Skip to content

Commit

Permalink
MAC data req: API to support mode switch (ARMmbed#2674)
Browse files Browse the repository at this point in the history
* MAC data req: API to support mode switch

* Updated MAC unit tests
  • Loading branch information
Jarkko Paso authored Sep 1, 2021
1 parent cad5122 commit a3f3412
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 29 deletions.
6 changes: 4 additions & 2 deletions nanostack/mac_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ typedef void mcps_data_request(const mac_api_t *api, const mcps_data_req_t *data
* @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.
* @param priority Data request priority level
* @param phy_mode_id Use mode switch if given phy_mode_id > 0
*
* 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, const struct channel_list_s *asynch_channel_list, mac_data_priority_t priority);
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, mac_data_priority_t priority, uint8_t phy_mode_id);

/**
* @brief mcps_purge_request MCPS_PURGE request call
Expand Down Expand Up @@ -286,10 +287,11 @@ typedef int8_t mac_api_enable_mcps_edfe_ext(mac_api_t *api,
* @brief mac_api_mode_switch_resolver_ext Initialises mode switch resolver callback. Upper layer must configure function when mode switch is used.
* @param api mac_api_t pointer, which is created by application.
* @param mode_resolver_cb Upper layer function to resolve received PHY mode ID
* @param base_phy_mode Base PHY mode, device returns to this mode after mode switch transmission or reception
* @return -1 if error, 0 otherwise
*/
typedef int8_t mac_api_mode_switch_resolver_ext(mac_api_t *api,
mode_switch_resolver *mode_resolver_cb);
mode_switch_resolver *mode_resolver_cb, uint8_t base_phy_mode);

/**
* \brief Struct mac_api_s defines functions for two-way communications between external MAC and Upper layer.
Expand Down
2 changes: 1 addition & 1 deletion source/6LoWPAN/adaptation_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ static void lowpan_data_request_to_mac(protocol_interface_info_entry_t *cur, buf
} else {
mcps_data_req_ie_list_t ie_list;
memset(&ie_list, 0, sizeof(mcps_data_req_ie_list_t));
cur->mac_api->mcps_data_req_ext(cur->mac_api, &dataReq, &ie_list, NULL, data_priority);
cur->mac_api->mcps_data_req_ext(cur->mac_api, &dataReq, &ie_list, NULL, data_priority, 0);
}
}

Expand Down
6 changes: 3 additions & 3 deletions source/6LoWPAN/ws/ws_llc_data_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ static void ws_llc_lowpan_mpx_data_request(llc_data_base_t *base, mpx_user_t *us
message->ie_ext.payloadIovLength = 0; //Set Back 2 at response handler
}

base->interface_ptr->mac_api->mcps_data_req_ext(base->interface_ptr->mac_api, &data_req, &message->ie_ext, NULL, message->priority);
base->interface_ptr->mac_api->mcps_data_req_ext(base->interface_ptr->mac_api, &data_req, &message->ie_ext, NULL, message->priority, 0);
}

static void ws_llc_eapol_data_req_init(mcps_data_req_t *data_req, llc_message_t *message)
Expand Down Expand Up @@ -1199,7 +1199,7 @@ static void ws_llc_mpx_eapol_send(llc_data_base_t *base, llc_message_t *message)
ns_list_add_to_end(&base->llc_message_list, message);
ws_llc_eapol_data_req_init(&data_req, message);
base->temp_entries->active_eapol_session = true;
base->interface_ptr->mac_api->mcps_data_req_ext(base->interface_ptr->mac_api, &data_req, &message->ie_ext, NULL, message->priority);
base->interface_ptr->mac_api->mcps_data_req_ext(base->interface_ptr->mac_api, &data_req, &message->ie_ext, NULL, message->priority, 0);
}


Expand Down Expand Up @@ -1916,7 +1916,7 @@ int8_t ws_llc_asynch_request(struct protocol_interface_info_entry *interface, as

}

base->interface_ptr->mac_api->mcps_data_req_ext(base->interface_ptr->mac_api, &data_req, &message->ie_ext, &request->channel_list, message->priority);
base->interface_ptr->mac_api->mcps_data_req_ext(base->interface_ptr->mac_api, &data_req, &message->ie_ext, &request->channel_list, message->priority, 0);

return 0;
}
Expand Down
1 change: 1 addition & 0 deletions source/MAC/IEEE802_15_4/mac_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ typedef struct protocol_interface_rf_mac_setup {

uint8_t mac_channel;
uint8_t mac_tx_start_channel;
uint8_t base_phy_mode;
//uint8_t cca_failure;

/* MAC TX Queue */
Expand Down
5 changes: 3 additions & 2 deletions source/MAC/IEEE802_15_4/mac_mcps_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ 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, NULL, MAC_DATA_NORMAL_PRIORITY);
mcps_sap_data_req_handler_ext(rf_mac_setup, data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY, 0);
}

static bool mac_ie_vector_length_validate(ns_ie_iovec_t *ie_vector, uint16_t iov_length, uint16_t *length_out)
Expand Down Expand Up @@ -195,8 +195,9 @@ static bool mac_ie_vector_length_validate(ns_ie_iovec_t *ie_vector, uint16_t iov
}


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, mac_data_priority_t priority)
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, mac_data_priority_t priority, uint8_t phy_mode_id)
{
(void) phy_mode_id;
uint8_t status = MLME_SUCCESS;
mac_pre_build_frame_t *buffer = NULL;

Expand Down
2 changes: 1 addition & 1 deletion source/MAC/IEEE802_15_4/mac_mcps_sap.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,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, const channel_list_s *asynch_channel_list, mac_data_priority_t priority);
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, mac_data_priority_t priority, uint8_t phy_mode_id);

void mac_mcps_trig_buffer_from_queue(struct protocol_interface_rf_mac_setup *rf_mac_setup);

Expand Down
13 changes: 7 additions & 6 deletions source/MAC/IEEE802_15_4/sw_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ static int8_t ns_sw_mac_initialize(mac_api_t *api, mcps_data_confirm *mcps_data_
mlme_confirm *mlme_conf_callback, mlme_indication *mlme_ind_callback, int8_t parent_id);
static int8_t ns_sw_mac_api_enable_mcps_ext(mac_api_t *api, mcps_data_indication_ext *data_ind_cb, mcps_data_confirm_ext *data_cnf_cb, mcps_ack_data_req_ext *ack_data_req_cb);
static int8_t ns_sw_mac_api_enable_edfe_ext(mac_api_t *api, mcps_edfe_handler *edfe_ind_cb);
static int8_t ns_sw_mac_api_mode_switch_resolver_set(mac_api_t *api, mode_switch_resolver *mode_resolver_cb);
static int8_t ns_sw_mac_api_mode_switch_resolver_set(mac_api_t *api, mode_switch_resolver *mode_resolver_cb, uint8_t base_phy_mode);

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 mcps_data_req_ie_list_t *ie_ext, const channel_list_s *asynch_channel_list, mac_data_priority_t priority);
static 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, mac_data_priority_t priority, uint8_t phy_mode_id);
static uint8_t 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);
Expand Down Expand Up @@ -346,14 +346,15 @@ static int8_t ns_sw_mac_api_enable_edfe_ext(mac_api_t *api, mcps_edfe_handler *e
return 0;
}

static int8_t ns_sw_mac_api_mode_switch_resolver_set(mac_api_t *api, mode_switch_resolver *mode_resolver_cb)
static int8_t ns_sw_mac_api_mode_switch_resolver_set(mac_api_t *api, mode_switch_resolver *mode_resolver_cb, uint8_t base_phy_mode)
{
if (api != mac_store.mac_api) {
return -1;
}
if (!mac_store.setup->mac_extension_enabled) {
return -1;
}
mac_store.setup->base_phy_mode = base_phy_mode;
mac_store.mac_api->mode_resolver_cb = mode_resolver_cb;
return 0;
}
Expand Down Expand Up @@ -596,15 +597,15 @@ static 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, NULL, MAC_DATA_NORMAL_PRIORITY);
mcps_sap_data_req_handler_ext(mac_store.setup, data, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY, 0);
}
}

static 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, mac_data_priority_t priority)
static 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, mac_data_priority_t priority, uint8_t phy_mode_id)
{
//TODO: Populate linked list when present
if (mac_store.mac_api == api) {
mcps_sap_data_req_handler_ext(mac_store.setup, data, ie_ext, asynch_channel_list, priority);
mcps_sap_data_req_handler_ext(mac_store.setup, data, ie_ext, asynch_channel_list, priority, phy_mode_id);
}
}

Expand Down
26 changes: 13 additions & 13 deletions test/nanostack/unittest/mac/mac_mcps_sap/test_mac_mcps_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ bool test_mac_mcps_data_confirmation()
channel_list.channel_mask[0] = 0x07FFF800;
rf_mac_setup->mac_channel = 20;
mac_mlme_stub.uint16_value = 11;
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, &channel_list, MAC_DATA_NORMAL_PRIORITY);
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, &channel_list, MAC_DATA_NORMAL_PRIORITY, 0);
if (!rf_mac_setup->active_pd_data_request) {
return false;
}
Expand Down Expand Up @@ -3165,7 +3165,7 @@ bool test_mcps_sap_data_req_handler_ext()
ie_list.headerIovLength = 1;
//NULL Pointer

mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY);
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY, 0);
if (rf_mac_setup->active_pd_data_request || !data_confirm_valid) {
return false;
}
Expand All @@ -3178,7 +3178,7 @@ bool test_mcps_sap_data_req_handler_ext()
vector->ieBase = NULL;
vector->iovLen = 15;
ie_list.headerIeVectorList = vector;
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY);
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY, 0);
if (rf_mac_setup->active_pd_data_request || !data_confirm_valid) {
return false;
}
Expand All @@ -3192,7 +3192,7 @@ bool test_mcps_sap_data_req_handler_ext()
expect_data_confirmation_status = MLME_INVALID_PARAMETER;
data_confirm_valid = false;

mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY);
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY, 0);
if (rf_mac_setup->active_pd_data_request || !data_confirm_valid) {
return false;
}
Expand All @@ -3203,7 +3203,7 @@ bool test_mcps_sap_data_req_handler_ext()
expect_data_confirmation_status = MLME_INVALID_PARAMETER;
data_confirm_valid = false;

mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY);
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY, 0);
if (rf_mac_setup->active_pd_data_request || !data_confirm_valid) {
return false;
}
Expand All @@ -3214,7 +3214,7 @@ bool test_mcps_sap_data_req_handler_ext()
expect_data_confirmation_status = MLME_INVALID_PARAMETER;
data_confirm_valid = false;

mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY);
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY, 0);



Expand All @@ -3234,7 +3234,7 @@ bool test_mcps_sap_data_req_handler_ext()
nsdynmemlib_stub.returnCounter = 10;
nsdynmemlib_stub.returnCounter = 0;
//TEST new confirmation call
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY);
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY, 0);
if (rf_mac_setup->active_pd_data_request || !data_confirm_valid) {
return false;
}
Expand All @@ -3243,7 +3243,7 @@ bool test_mcps_sap_data_req_handler_ext()
data_req.DstAddrMode = MAC_ADDR_MODE_16_BIT;
data_req.SrcAddrMode = MAC_ADDR_MODE_16_BIT;
nsdynmemlib_stub.returnCounter = 1;
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY);
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY, 0);
if (!rf_mac_setup->active_pd_data_request) {
return false;
}
Expand All @@ -3253,7 +3253,7 @@ bool test_mcps_sap_data_req_handler_ext()
data_req.DstAddrMode = MAC_ADDR_MODE_NONE;
data_req.SeqNumSuppressed = true;
nsdynmemlib_stub.returnCounter = 1;
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY);
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY, 0);
if (!rf_mac_setup->active_pd_data_request || !rf_mac_setup->active_pd_data_request->fcf_dsn.sequenceNumberSuppress) {
return false;
}
Expand All @@ -3265,7 +3265,7 @@ bool test_mcps_sap_data_req_handler_ext()
data_req.SeqNumSuppressed = false;
data_req.PanIdSuppressed = true;
nsdynmemlib_stub.returnCounter = 1;
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY);
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY, 0);
if (!rf_mac_setup->active_pd_data_request || rf_mac_setup->active_pd_data_request->fcf_dsn.intraPan == data_req.PanIdSuppressed) {
return false;
}
Expand All @@ -3277,7 +3277,7 @@ bool test_mcps_sap_data_req_handler_ext()
data_req.SrcAddrMode = MAC_ADDR_MODE_NONE;
data_req.PanIdSuppressed = false;
nsdynmemlib_stub.returnCounter = 1;
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY);
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, NULL, MAC_DATA_NORMAL_PRIORITY, 0);
if (!rf_mac_setup->active_pd_data_request || rf_mac_setup->active_pd_data_request->fcf_dsn.intraPan != data_req.PanIdSuppressed) {
return false;
}
Expand All @@ -3302,12 +3302,12 @@ bool test_mcps_sap_data_req_handler_ext()
expect_data_confirmation_status = MLME_INVALID_PARAMETER;
data_confirm_valid = false;

mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, &channel_list, MAC_DATA_NORMAL_PRIORITY);
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, &channel_list, MAC_DATA_NORMAL_PRIORITY, 0);
if (rf_mac_setup->active_pd_data_request || !data_confirm_valid) {
return false;
}
data_req.TxAckReq = false;
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, &channel_list, MAC_DATA_NORMAL_PRIORITY);
mcps_sap_data_req_handler_ext(rf_mac_setup, &data_req, &ie_list, &channel_list, MAC_DATA_NORMAL_PRIORITY, 0);
if (!rf_mac_setup->active_pd_data_request) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion test/nanostack/unittest/stub/mac_mcps_sap_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(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, mac_data_priority_t priority)
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, mac_data_priority_t priority, uint8_t phy_mode_id)
{

}
Expand Down

0 comments on commit a3f3412

Please sign in to comment.