diff --git a/nanostack/mac_api.h b/nanostack/mac_api.h index f9e59b40587..fea75801299 100644 --- a/nanostack/mac_api.h +++ b/nanostack/mac_api.h @@ -32,6 +32,8 @@ extern "C" { #endif +struct channel_list_s; + typedef struct mac_api_s mac_api_t; /** @@ -125,8 +127,11 @@ typedef void mcps_data_request(const mac_api_t* api, const mcps_data_req_t *data * @param api API to handle the request * @param data MCPS-DATA.request specific values * @param ie_ext Information element list to MCPS-DATA.request + * @param asynch_channel_list Optional channel list to asynch data request. Give NULL when normal data request. + * + * Asynch data request is mac standard extension. asynch_channel_list include channel mask which channel message is requested to send. */ -typedef void mcps_data_request_ext(const mac_api_t* api, const mcps_data_req_t *data, const mcps_data_req_ie_list_t *ie_ext); +typedef void mcps_data_request_ext(const mac_api_t* api, const mcps_data_req_t *data, const mcps_data_req_ie_list_t *ie_ext, const struct channel_list_s *asynch_channel_list); /** * @brief mcps_purge_request MCPS_PURGE request call diff --git a/source/MAC/IEEE802_15_4/mac_defines.h b/source/MAC/IEEE802_15_4/mac_defines.h index 74d0e73597c..74c34628e72 100644 --- a/source/MAC/IEEE802_15_4/mac_defines.h +++ b/source/MAC/IEEE802_15_4/mac_defines.h @@ -139,6 +139,7 @@ typedef struct protocol_interface_rf_mac_setup { bool macUpState; bool shortAdressValid: 1; //Define Dynamic src address to mac16 when it is true bool beaconSrcAddressModeLong: 1; //This force beacon src to mac64 otherwise shortAdressValid will define type + bool mac_extension_enabled:1; uint16_t mac_short_address; uint16_t pan_id; uint8_t mac64[8]; diff --git a/source/MAC/IEEE802_15_4/mac_mcps_sap.c b/source/MAC/IEEE802_15_4/mac_mcps_sap.c index e4f25413d06..d2dc7ad936b 100644 --- a/source/MAC/IEEE802_15_4/mac_mcps_sap.c +++ b/source/MAC/IEEE802_15_4/mac_mcps_sap.c @@ -95,14 +95,17 @@ void mcps_sap_data_req_handler(protocol_interface_rf_mac_setup_s *rf_mac_setup , { mcps_data_req_ie_list_t ie_list; memset(&ie_list, 0 , sizeof(mcps_data_req_ie_list_t)); - mcps_sap_data_req_handler_ext(rf_mac_setup, data_req, &ie_list); + mcps_sap_data_req_handler_ext(rf_mac_setup, data_req, &ie_list, NULL); } -void mcps_sap_data_req_handler_ext(protocol_interface_rf_mac_setup_s *rf_mac_setup , const mcps_data_req_t *data_req , const mcps_data_req_ie_list_t *ie_list) { +void mcps_sap_data_req_handler_ext(protocol_interface_rf_mac_setup_s *rf_mac_setup , const mcps_data_req_t *data_req , const mcps_data_req_ie_list_t *ie_list, const channel_list_s *asynch_channel_list) { uint8_t status = MLME_SUCCESS; mac_pre_build_frame_t *buffer = NULL; + //Asynch Data request will be enabled seperately lare API is defined + + if (!rf_mac_setup->mac_security_enabled) { if (data_req->Key.SecurityLevel) { status = MLME_UNSUPPORTED_SECURITY; @@ -123,6 +126,12 @@ void mcps_sap_data_req_handler_ext(protocol_interface_rf_mac_setup_s *rf_mac_set goto verify_status; } + if ((ie_header_length || ie_payload_length || asynch_channel_list) && !rf_mac_setup->mac_extension_enabled ) { + //Report error when feature is not enaled yet + status = MLME_INVALID_PARAMETER; + goto verify_status; + } + if ((data_req->msduLength + ie_header_length + ie_payload_length) > rf_mac_setup->dev_driver->phy_driver->phy_MTU - MAC_DATA_PACKET_MIN_HEADER_LENGTH) { tr_debug("packet %u, %u",data_req->msduLength, rf_mac_setup->dev_driver->phy_driver->phy_MTU); status = MLME_FRAME_TOO_LONG; @@ -142,6 +151,13 @@ void mcps_sap_data_req_handler_ext(protocol_interface_rf_mac_setup_s *rf_mac_set tr_debug("Drop MAC tx packet when mac disabled"); goto verify_status; } + + if (asynch_channel_list ) { + //Copy Asynch data list + buffer->asynch_channel_list = *asynch_channel_list; + buffer->asynch_request = true; + } + buffer->upper_layer_request = true; buffer->fcf_dsn.frametype = FC_DATA_FRAME; buffer->fcf_dsn.ackRequested = data_req->TxAckReq; diff --git a/source/MAC/IEEE802_15_4/mac_mcps_sap.h b/source/MAC/IEEE802_15_4/mac_mcps_sap.h index dd628f73b86..9b721479eca 100644 --- a/source/MAC/IEEE802_15_4/mac_mcps_sap.h +++ b/source/MAC/IEEE802_15_4/mac_mcps_sap.h @@ -34,6 +34,7 @@ struct arm_phy_sap_msg_s; struct mcps_purge_s; struct mcps_data_ie_list; struct mcps_data_req_ie_list; +struct channel_list_s; /** Address types */ typedef enum { @@ -120,10 +121,12 @@ typedef struct mac_pre_build_frame{ uint8_t msduHandle; uint16_t buffer_ttl; struct mcps_data_req_ie_list ie_elements; + struct channel_list_s asynch_channel_list; uint8_t *mac_payload; uint8_t status; bool upper_layer_request; bool mac_allocated_payload_ptr:1; + bool asynch_request:1; unsigned security_mic_len:5; //Max possible lengths 0, 4, 8, 16 bytes unsigned priority:2; struct mac_pre_build_frame *next; //Pointer for queue purpose @@ -179,7 +182,7 @@ int8_t mac_virtual_sap_data_cb(void *identifier, struct arm_phy_sap_msg_s *messa void mcps_sap_data_req_handler(struct protocol_interface_rf_mac_setup *rf_mac_setup , const struct mcps_data_req_s *data_req ); -void mcps_sap_data_req_handler_ext(struct protocol_interface_rf_mac_setup *rf_mac_setup , const struct mcps_data_req_s *data_req , const struct mcps_data_req_ie_list *ie_list); +void mcps_sap_data_req_handler_ext(struct protocol_interface_rf_mac_setup *rf_mac_setup , const struct mcps_data_req_s *data_req , const struct mcps_data_req_ie_list *ie_list, const channel_list_s *asynch_channel_list); void mac_mcps_trig_buffer_from_queue(struct protocol_interface_rf_mac_setup *rf_mac_setup); diff --git a/source/MAC/IEEE802_15_4/sw_mac.c b/source/MAC/IEEE802_15_4/sw_mac.c index d2d4d616a44..21091342d1c 100644 --- a/source/MAC/IEEE802_15_4/sw_mac.c +++ b/source/MAC/IEEE802_15_4/sw_mac.c @@ -53,7 +53,7 @@ static int8_t ns_sw_mac_api_enable_mcps_ext(mac_api_t *api, mcps_data_indication static void mlme_req(const mac_api_t* api, mlme_primitive id, const void *data); static void mcps_req(const mac_api_t* api, const mcps_data_req_t *data); -static void mcps_req_ext(const mac_api_t* api, const mcps_data_req_t *data, const const mcps_data_req_ie_list_t *ie_ext); +static void mcps_req_ext(const mac_api_t* api, const mcps_data_req_t *data, const const mcps_data_req_ie_list_t *ie_ext, const channel_list_s *asynch_channel_list); static void purge_req(const mac_api_t* api, const mcps_purge_t *data); static int8_t macext_mac64_address_set( const mac_api_t* api, const uint8_t *mac64); static int8_t macext_mac64_address_get( const mac_api_t* api, mac_extended_address_type type, uint8_t *mac64_buf); @@ -227,6 +227,7 @@ static int8_t ns_sw_mac_api_enable_mcps_ext(mac_api_t *api, mcps_data_indication cur->data_conf_ext_cb = data_cnf_cb; cur->data_ind_ext_cb = data_ind_cb; + mac_store.setup->mac_extension_enabled = true; return 0; } @@ -468,15 +469,15 @@ void mcps_req(const mac_api_t* api, const mcps_data_req_t *data) /* Call direct new API but without IE extensions */ mcps_data_req_ie_list_t ie_list; memset(&ie_list, 0 , sizeof(mcps_data_req_ie_list_t)); - mcps_sap_data_req_handler_ext(mac_store.setup , data , &ie_list); + mcps_sap_data_req_handler_ext(mac_store.setup , data , &ie_list, NULL); } } -void mcps_req_ext(const mac_api_t* api, const mcps_data_req_t *data, const mcps_data_req_ie_list_t *ie_ext) +void mcps_req_ext(const mac_api_t* api, const mcps_data_req_t *data, const mcps_data_req_ie_list_t *ie_ext, const channel_list_s *asynch_channel_list) { //TODO: Populate linked list when present if (mac_store.mac_api == api) { - mcps_sap_data_req_handler_ext(mac_store.setup , data , ie_ext); + mcps_sap_data_req_handler_ext(mac_store.setup , data , ie_ext, asynch_channel_list); } } diff --git a/test/nanostack/unittest/stub/mac_mcps_sap_stub.c b/test/nanostack/unittest/stub/mac_mcps_sap_stub.c index ef37db34292..7aa28d1ca54 100644 --- a/test/nanostack/unittest/stub/mac_mcps_sap_stub.c +++ b/test/nanostack/unittest/stub/mac_mcps_sap_stub.c @@ -55,7 +55,7 @@ mac_mcps_sap_stub_def mac_mcps_sap_stub; void mcps_sap_data_req_handler(protocol_interface_rf_mac_setup_s *rf_mac_setup , const mcps_data_req_t *data_req ) { } -void mcps_sap_data_req_handler_ext(struct protocol_interface_rf_mac_setup *rf_mac_setup , const struct mcps_data_req_s *data_req , const struct mcps_data_req_ie_list *ie_list) +void mcps_sap_data_req_handler_ext(struct protocol_interface_rf_mac_setup *rf_mac_setup , const struct mcps_data_req_s *data_req , const struct mcps_data_req_ie_list *ie_list, const channel_list_s *asynch_channel_list) { }