The MAC Core Layer (MCL) abstracts and implements IEEE 802.15.4-2006 compliant behavior for non-beacon enabled and beacon-enabled network support.
Macros | |
#define | MAKE_MAC_BUSY() |
This macro sets the MAC to busy. More... | |
#define | MAKE_MAC_NOT_BUSY() |
This macro sets the MAC to not busy. More... | |
Functions | |
void | dispatch_event (uint8_t *event) |
Obtains the message type from the buffer and calls the respective handler. More... | |
void | mac_build_and_tx_beacon (bool beacon_enabled, buffer_t *beacon_buffer_header) |
Builds and transmits the beacon frame. More... | |
void | mac_coord_realignment_command_tx_success (uint8_t tx_status, buffer_t *buf_ptr) |
Continues handling of MLME_START.request (Coordinator realignment) command. More... | |
void | mac_gen_mcps_data_conf (buffer_t *buf_ptr, uint8_t status, uint8_t handle) |
void | mac_idle_trans (void) |
Resets the MAC helper variables and transition to idle state. More... | |
void | mac_process_beacon_frame (buffer_t *msg) |
Processes received beacon frame. More... | |
void | mac_process_beacon_request (buffer_t *buf_ptr) |
Processes a beacon request. More... | |
void | mac_process_data_frame (buffer_t *buf_ptr) |
Processes data frames. More... | |
void | mac_process_tal_data_ind (uint8_t *msg) |
Depending on received frame the appropriate function is called. More... | |
void | mac_scan_send_complete (retval_t status) |
Continue scanning after the completion of frame transmission. More... | |
void | mac_sleep_trans (void) |
Puts the radio to sleep if this is allowed. More... | |
void | mac_trx_init_sleep (void) |
MAC function to put the radio to sleep mode. More... | |
void | mac_trx_wakeup (void) |
MAC function to wake-up the radio from sleep state. More... | |
bool | mac_tx_coord_realignment_command (frame_msgtype_t cmd_type, buffer_t *buf_ptr, uint16_t new_panid, uint8_t new_channel, uint8_t new_page) |
Sends a coordinator realignment command frame. More... | |
retval_t | set_tal_pib_internal (uint8_t attribute, pib_value_t *attribute_value) |
Wakes-up the radio and sets the corresponding TAL PIB attribute. More... | |
#define MAKE_MAC_BUSY | ( | ) |
This macro sets the MAC to busy.
Referenced by mac_build_and_tx_beacon(), mac_process_tal_tx_status(), mac_tx_coord_realignment_command(), mcps_data_request(), scan_set_complete(), and send_scan_cmd().
#define MAKE_MAC_NOT_BUSY | ( | ) |
This macro sets the MAC to not busy.
Referenced by tal_ed_end_cb(), and tal_tx_frame_done_cb().
void dispatch_event | ( | uint8_t * | event | ) |
Obtains the message type from the buffer and calls the respective handler.
This function decodes all events/messages and calls the appropriate handler.
event | Pointer to the buffer header whose body part holds the message type and message elemnets |
References Assert, bmm_buffer_free(), BMM_BUFFER_POINTER, CMD_ID_OCTET, LAST_MESSAGE, and PGM_READ_WORD.
Referenced by mac_task().
Builds and transmits the beacon frame.
This function is called to build a beacon frame. For beaconless network this function also transmits the generated beacon frame.
beacon_enabled | Flag indicating the mode of beacon transmission |
beacon_buffer_header | For build without beacon support only: Pointer to buffer of beacon frame to be transmitted in nonbeacon network. |
References ASSOC_PERMIT_BIT_POS, BATT_LIFE_EXT_BIT_POS, BEACON_MESSAGE, BEACON_PAYLOAD_LEN, BMM_BUFFER_POINTER, frame_info_tag::buffer_header, CCPU_ENDIAN_TO_LE16, convert_16_bit_to_byte_array(), convert_64_bit_to_byte_array(), convert_spec_16_bit_to_byte_array(), CSMA_UNSLOTTED, mcps_data_req_tag::DstPANId, FCF_FRAME_PENDING, FCF_FRAME_VERSION_2006, FCF_FRAMETYPE_BEACON, FCF_LONG_ADDR, FCF_SECURITY_ENABLED, FCF_SET_FRAMETYPE, FCF_SET_SOURCE_ADDR_MODE, FCF_SHORT_ADDR, FINAL_CAP_SLOT_DEFAULT, mac_beacon_payload, mac_pib_tag::mac_BeaconPayloadLength, mac_pib_tag::mac_BSN, MAC_COORDINATOR, MAC_NO_SHORT_ADDR_VALUE, MAC_PAN_COORD_STARTED, mac_pib, mac_state, MAC_SUCCESS, MAKE_MAC_BUSY, frame_info_tag::mpdu, mcps_data_req_tag::msduLength, frame_info_tag::msg_type, NON_BEACON_NWK, PAN_COORD_BIT_POS, mcps_data_req_tag::SrcAddrMode, tal_pib, and tal_tx_frame().
Referenced by mac_process_beacon_request().
void mac_coord_realignment_command_tx_success | ( | uint8_t | tx_status, |
buffer_t * | buf_ptr | ||
) |
Continues handling of MLME_START.request (Coordinator realignment) command.
This function is called once the coordinator realignment command is sent out to continue the handling of the MLME_START.request command.
tx_status | Status of the coordinator realignment command transmission |
buf_ptr | Buffer for start confirmation |
References Assert, mlme_start_req_tag::BeaconOrder, mlme_start_req_tag::ChannelPage, gen_mlme_start_conf(), mlme_start_req_tag::LogicalChannel, MAC_INVALID_PARAMETER, mac_sleep_trans(), MAC_SUCCESS, macBattLifeExt, macBeaconOrder, macPANId, macSuperframeOrder, NON_BEACON_NWK, mlme_start_req_tag::PANId, phyCurrentChannel, phyCurrentPage, set_tal_pib_internal(), mlme_start_req_tag::SuperframeOrder, and tal_pib.
Referenced by mac_process_tal_tx_status().
void mac_gen_mcps_data_conf | ( | buffer_t * | buf_ptr, |
uint8_t | status, | ||
uint8_t | handle | ||
) |
References BMM_BUFFER_POINTER, mcps_data_conf_tag::cmdcode, mac_nhle_q, MCPS_DATA_CONFIRM, mcps_data_conf_tag::msduHandle, qmm_queue_append(), and mcps_data_conf_tag::status.
Referenced by mac_process_tal_tx_status(), and mcps_data_request().
void mac_idle_trans | ( | void | ) |
Resets the MAC helper variables and transition to idle state.
This function sets the MAC to idle state and resets MAC helper variables
References Assert, mac_sleep_trans(), mac_soft_reset(), MAC_SUCCESS, mac_trx_wakeup(), macPANId, macPANId_def, macShortAddress, macShortAddress_def, and set_tal_pib_internal().
Referenced by mac_process_tal_data_ind(), mac_process_tal_tx_status(), and process_data_ind_not_transient().
void mac_process_beacon_frame | ( | buffer_t * | beacon | ) |
Processes received beacon frame.
This function processes a received beacon frame. When the system is scanning it records PAN descriptor information contained in the beacon. These PAN descriptors will be reported to the next higher layer via MLME_SCAN.confirm. Also this routine constructs the MLME_BEACON_NOTIFY.indication. Additionally when a device is synced with the coordinator, it tracks beacon frames, checks whether the coordinator does have pending data and will initiate the transmission of a data request frame. The routine uses global "parse_data" structure. The PAN descriptors are stored in the mlme_scan_conf_t structure.
beacon | Pointer to the buffer in which the beacon was received |
References wpan_addr_spec_tag::Addr, ADDR_COPY_DST_SRC_16, ADDR_COPY_DST_SRC_64, mlme_beacon_notify_ind_tag::AddrList, wpan_addr_spec_tag::AddrMode, aMaxSIFSFrameSize, Assert, aUnitBackoffPeriod, frame_payload_t::beacon_data, mac_beacon_payload_tag::beacon_payload_len, bmm_buffer_free(), BMM_BUFFER_POINTER, mlme_beacon_notify_ind_tag::BSN, wpan_pandescriptor_tag::ChannelPage, mlme_beacon_notify_ind_tag::cmdcode, convert_byte_array_to_16_bit(), convert_byte_array_to_64_bit(), wpan_pandescriptor_tag::CoordAddrSpec, parse_tag::fcf, FCF_FRAME_PENDING, FCF_SHORT_ADDR, FUNC_PTR, GET_BEACON_ORDER, GET_FINAL_CAP, GET_GTS_PERMIT, GET_SUPERFRAME_ORDER, mac_beacon_payload_tag::gts_spec, wpan_pandescriptor_tag::GTSPermit, wpan_pandescriptor_tag::LinkQuality, wpan_pandescriptor_tag::LogicalChannel, address_field_t::long_address, mac_pib_tag::mac_AutoRequest, mac_pib_tag::mac_BattLifeExtPeriods, mac_conf_buf_ptr, mac_nhle_q, MAC_NO_DATA, MAC_PAN_COORD_STARTED, mac_parse_data, parse_tag::mac_payload_data, mac_pib, MAC_POLL_IDLE, mac_poll_state, MAC_SCAN_ACTIVE, MAC_SCAN_IDLE, MAC_SCAN_PASSIVE, mac_scan_state, mac_state, MAC_SUCCESS, MAC_SYNC_NEVER, mac_sync_state, macBeaconOrder, macMinLIFSPeriod_def, macMinSIFSPeriod_def, macSuperframeOrder, MAX_PANDESCRIPTORS, MLME_BEACON_NOTIFY_INDICATION, parse_tag::mpdu_length, NON_BEACON_NWK, NUM_LONG_PEND_ADDR, NUM_SHORT_PEND_ADDR, pal_timer_start(), mlme_beacon_notify_ind_tag::PANDescriptor, wpan_addr_spec_tag::PANId, mlme_beacon_notify_ind_tag::PendAddrSpec, mac_beacon_payload_tag::pending_addr_list, mac_beacon_payload_tag::pending_addr_spec, PHY_OVERHEAD, parse_tag::ppdu_link_quality, qmm_queue_append(), mlme_scan_conf_tag::ResultListSize, mlme_scan_conf_tag::scan_result_list, mlme_beacon_notify_ind_tag::sdu, mlme_beacon_notify_ind_tag::sduLength, parse_tag::sequence_number, set_tal_pib_internal(), address_field_t::short_address, parse_tag::src_addr, parse_tag::src_addr_mode, parse_tag::src_panid, mac_beacon_payload_tag::superframe_spec, wpan_pandescriptor_tag::SuperframeSpec, SYMBOLS_PER_OCTET, TAL_CONVERT_SYMBOLS_TO_US, tal_pib, TIMEOUT_RELATIVE, and WPAN_ADDRMODE_SHORT.
Referenced by process_data_ind_not_transient(), and process_data_ind_scanning().
void mac_process_beacon_request | ( | buffer_t * | msg | ) |
Processes a beacon request.
This function is called in case a beacon request frame has been received by a coordinator. In a nonbeacon-enabled PAN the generation of a beacon frame using CSMA-CA is initiated. In a beacon-enabled PAN no extra beacon frame will be transmitted apart from the standard beacon frames.
msg | Pointer to the buffer in which the beaocn request was received |
References bmm_buffer_free(), mac_build_and_tx_beacon(), NON_BEACON_NWK, and tal_pib.
Referenced by mac_process_tal_data_ind(), and process_data_ind_not_transient().
void mac_process_data_frame | ( | buffer_t * | buf_ptr | ) |
Processes data frames.
This function processes the data frames received and sends mcps_data_indication to the NHLE.
buf_ptr | Pointer to receive buffer of the data frame |
References ADDR_COPY_DST_SRC_16, ADDR_COPY_DST_SRC_64, bmm_buffer_free(), BMM_BUFFER_POINTER, frame_payload_t::data, parse_tag::dest_addr, parse_tag::dest_addr_mode, parse_tag::dest_panid, parse_tag::fcf, FCF_FRAME_PENDING, FCF_LONG_ADDR, FCF_SHORT_ADDR, address_field_t::long_address, mac_last_dsn, mac_last_src_addr, mac_nhle_q, MAC_PAN_COORD_STARTED, mac_parse_data, parse_tag::mac_payload_data, parse_tag::mac_payload_length, mac_sleep_trans(), mac_state, MCPS_DATA_INDICATION, mac_data_payload_tag::payload, parse_tag::ppdu_link_quality, qmm_queue_append(), parse_tag::sequence_number, address_field_t::short_address, parse_tag::src_addr, parse_tag::src_addr_mode, and parse_tag::src_panid.
Referenced by mac_process_tal_data_ind(), and process_data_ind_not_transient().
void mac_process_tal_data_ind | ( | uint8_t * | msg | ) |
Depending on received frame the appropriate function is called.
msg | Pointer to the buffer header. |
References Assert, ASSOCIATIONREQUEST, ASSOCIATIONRESPONSE, BEACONREQUEST, bmm_buffer_free(), BMM_BUFFER_POINTER, COORDINATORREALIGNMENT, DATAREQUEST, DISASSOCIATIONNOTIFICATION, FCF_FRAMETYPE_DATA, FCF_FRAMETYPE_MAC_CMD, parse_tag::frame_type, LQI_LEN, MAC_AWAIT_ASSOC_RESPONSE, mac_busy, parse_tag::mac_command, MAC_COORDINATOR, mac_idle_trans(), mac_parse_data, MAC_POLL_EXPLICIT, MAC_POLL_IDLE, MAC_POLL_IMPLICIT, mac_poll_state, mac_process_beacon_request(), mac_process_data_frame(), MAC_SCAN_IDLE, mac_scan_state, mac_state, frame_info_tag::mpdu, parse_tag::mpdu_length, ORPHANNOTIFICATION, pal_is_timer_running(), pal_timer_stop(), PANIDCONFLICTNOTIFICAION, parse_mpdu(), parse_tag::ppdu_link_quality, process_data_ind_not_transient(), process_data_ind_scanning(), qmm_queue_append(), tal_mac_q, and tal_pib.
void mac_scan_send_complete | ( | retval_t | status | ) |
Continue scanning after the completion of frame transmission.
This functions continues the corresponding scaning depending on status from the transmission of a beacon request or orphan notification frame.
status | Status of transmission |
References Assert, FUNC_PTR, MAC_CALCULATE_SYMBOL_TIME_SCANDURATION, mac_conf_buf_ptr, mac_pib_tag::mac_DSN, mac_pib, mac_pib_tag::mac_ResponseWaitTime, MAC_SCAN_ACTIVE, mac_scan_state, MAC_SUCCESS, mac_t_scan_duration_cb(), pal_timer_start(), scan_curr_channel, scan_duration, scan_proceed(), scan_type, T_Scan_Duration, TAL_CONVERT_SYMBOLS_TO_US, and TIMEOUT_RELATIVE.
Referenced by tal_tx_frame_done_cb().
void mac_sleep_trans | ( | void | ) |
Puts the radio to sleep if this is allowed.
References MAC_INACTIVE, mac_pib, mac_rx_enabled, mac_pib_tag::mac_RxOnWhenIdle, MAC_SYNC_NEVER, mac_sync_state, mac_trx_init_sleep(), NON_BEACON_NWK, pal_is_timer_running(), and tal_pib.
Referenced by mac_awake_scan(), mac_coord_realignment_command_tx_success(), mac_idle_trans(), mac_init(), mac_process_data_frame(), mac_process_tal_tx_status(), mac_t_rx_off_cb(), mcps_data_request(), mlme_reset_request(), mlme_set(), mlme_start_request(), process_data_ind_not_transient(), scan_clean_up(), scan_proceed(), and set_tal_pib_internal().
void mac_trx_init_sleep | ( | void | ) |
MAC function to put the radio to sleep mode.
References mac_radio_sleep_state, MAC_SUCCESS, pal_timer_source_select(), RADIO_AWAKE, RADIO_SLEEPING, SLEEP_MODE_1, tal_trx_sleep(), TMR_CLK_SRC_DURING_TRX_AWAKE, and TMR_CLK_SRC_DURING_TRX_SLEEP.
Referenced by mac_sleep_trans().
void mac_trx_wakeup | ( | void | ) |
MAC function to wake-up the radio from sleep state.
References FAILURE, mac_radio_sleep_state, pal_timer_source_select(), RADIO_AWAKE, RADIO_SLEEPING, tal_trx_wakeup(), and TMR_CLK_SRC_DURING_TRX_AWAKE.
Referenced by mac_idle_trans(), mac_rx_enable(), mcps_data_request(), mlme_reset_request(), mlme_scan_request(), mlme_set(), mlme_start_request(), process_data_ind_not_transient(), and set_tal_pib_internal().
bool mac_tx_coord_realignment_command | ( | frame_msgtype_t | cmd_type, |
buffer_t * | buf_ptr, | ||
uint16_t | new_panid, | ||
uint8_t | new_channel, | ||
uint8_t | new_page | ||
) |
Sends a coordinator realignment command frame.
This function is called either in response to the reception of an orphan notification command from a device (cmd_type = ORPHANREALIGNMENT), or gratuitously whenever the PAN parameters are about to be changed (cmd_type = COORDINATORREALIGNMENT). In the first case, the paramater mor contains a pointer to the respective MLME_ORPHAN.response message, while in the latter case this parameter is unused, and can be passed as NULL.
cmd_type | Determines directed or broadcast mode |
buf_ptr | Pointer to the buffer, using which coord_realignment_command to be sent |
new_panid | Contains the new PAN-ID in case there is a network realignment |
new_channel | Contains the new channel in case there is a network realignment |
new_page | Contains the new channel page in case there is a network realignment |
References BMM_BUFFER_POINTER, BROADCAST, frame_info_tag::buffer_header, convert_16_bit_to_byte_array(), convert_64_bit_to_byte_array(), convert_spec_16_bit_to_byte_array(), COORD_REALIGN_PAYLOAD_LEN, COORDINATORREALIGNMENT, CSMA_SLOTTED, CSMA_UNSLOTTED, FCF_ACK_REQUEST, FCF_FRAME_VERSION_2006, FCF_FRAMETYPE_MAC_CMD, FCF_LONG_ADDR, FCF_SET_DEST_ADDR_MODE, FCF_SET_FRAMETYPE, FCF_SET_SOURCE_ADDR_MODE, FCF_SHORT_ADDR, mac_pib_tag::mac_DSN, mac_pib, MAC_SUCCESS, MAKE_MAC_BUSY, frame_info_tag::mpdu, frame_info_tag::msg_type, NON_BEACON_NWK, mlme_orphan_resp_tag::OrphanAddress, ORPHANREALIGNMENT, qmm_queue_append(), QUEUE_FULL, mlme_orphan_resp_tag::ShortAddress, tal_pib, and tal_tx_frame().
Referenced by mlme_start_request().
retval_t set_tal_pib_internal | ( | uint8_t | attribute, |
pib_value_t * | attribute_value | ||
) |
Wakes-up the radio and sets the corresponding TAL PIB attribute.
attribute | PIB attribute to be set |
attribute_value | Attribute value to be set |
References mac_radio_sleep_state, mac_sleep_trans(), mac_trx_wakeup(), RADIO_SLEEPING, and tal_pib_set().
Referenced by mac_awake_scan(), mac_coord_realignment_command_tx_success(), mac_idle_trans(), mac_process_beacon_frame(), mlme_start_request(), process_data_ind_not_transient(), scan_clean_up(), and scan_proceed().