Skip to content

Commit

Permalink
MAC functional updates and fix's:
Browse files Browse the repository at this point in the history
Fixed possible null pointer use when mac extension is not enabled and
handled frame version 2 packet.

Enabled MCPS confirmation extension use when extension is enabled.

Accept to send and receive MAC packet where is no Destination address.

Enabled sequence number suppression when send MAC packet without
destination address.

Improved unit test coverage and tested MAC packet with no destinaton
address.
  • Loading branch information
Juha Heiskanen authored and juhhei01 committed Jan 22, 2018
1 parent 2cef8ac commit b9f7bf4
Show file tree
Hide file tree
Showing 13 changed files with 346 additions and 92 deletions.
32 changes: 0 additions & 32 deletions source/MAC/IEEE802_15_4/mac_header_helper_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,38 +683,6 @@ void mac_header_information_elements_preparation(mac_pre_build_frame_t *buffer)
}
}

bool mac_ie_vector_length_validate(ns_ie_iovec_t *ie_vector, uint16_t iov_length, uint16_t *length_out)
{
*length_out = 0;
if (!iov_length) {
return true;
}

if (iov_length != 0 && !ie_vector) {
return false;
}

uint16_t msg_length = 0;
ns_ie_iovec_t *msg_iov = ie_vector;
for (uint_fast16_t i = 0; i < iov_length; i++) {
if (msg_iov->iovLen != 0 && !msg_iov->ieBase) {
return false;
}
msg_length += msg_iov->iovLen;
if (msg_length < msg_iov->iovLen) {
return false;
}
msg_iov++;
}

if (length_out) {
*length_out = msg_length;
}

return true;

}

uint16_t mac_buffer_total_payload_length(mac_pre_build_frame_t *buffer)
{
return mac_payload_length_calc_with_ie(buffer->mac_payload_length, buffer->payloadsIeLength);
Expand Down
2 changes: 0 additions & 2 deletions source/MAC/IEEE802_15_4/mac_header_helper_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ void mac_header_information_elements_preparation(struct mac_pre_build_frame *buf

uint16_t mac_buffer_total_payload_length(struct mac_pre_build_frame *buffer);

bool mac_ie_vector_length_validate(struct ns_ie_iovec *ie_vector, uint16_t iov_length, uint16_t *length_out);

/**
* Next function should only call when address mode is not MAC_ADDR_MODE_NONE and parsed proper header!
*/
Expand Down
8 changes: 7 additions & 1 deletion source/MAC/IEEE802_15_4/mac_indirect_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ void mac_indirect_data_ttl_handle(protocol_interface_rf_mac_setup_s *cur, uint16
confirm.status = MLME_TRANSACTION_EXPIRED;

mcps_sap_prebuild_frame_buffer_free(buf_temp);
if( api->data_conf_cb ) {

if (cur->mac_extension_enabled) {
mcps_data_conf_payload_t data_conf;
memset(&data_conf, 0, sizeof(mcps_data_conf_payload_t));
//Check Payload Here
api->data_conf_ext_cb(api, &confirm, &data_conf);
} else {
api->data_conf_cb(api, &confirm);
}
}
Expand Down
51 changes: 46 additions & 5 deletions source/MAC/IEEE802_15_4/mac_mcps_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ static void mcps_data_confirm_cb(protocol_interface_rf_mac_setup_s *rf_mac_setup
mac_data_poll_radio_disable_check(rf_mac_setup);

if( get_sw_mac_api(rf_mac_setup) ) {
get_sw_mac_api(rf_mac_setup)->data_conf_cb(get_sw_mac_api(rf_mac_setup), confirm);
if (rf_mac_setup->mac_extension_enabled) {
mcps_data_conf_payload_t data_conf;
memset(&data_conf, 0, sizeof(mcps_data_conf_payload_t));
//Check Payload Here
get_sw_mac_api(rf_mac_setup)->data_conf_ext_cb(get_sw_mac_api(rf_mac_setup), confirm, &data_conf);
} else {
get_sw_mac_api(rf_mac_setup)->data_conf_cb(get_sw_mac_api(rf_mac_setup), confirm);
}
}
}

Expand All @@ -98,13 +105,43 @@ void mcps_sap_data_req_handler(protocol_interface_rf_mac_setup_s *rf_mac_setup ,
mcps_sap_data_req_handler_ext(rf_mac_setup, data_req, &ie_list, NULL);
}

static bool mac_ie_vector_length_validate(ns_ie_iovec_t *ie_vector, uint16_t iov_length, uint16_t *length_out)
{
*length_out = 0;
if (!iov_length) {
return true;
}

if (iov_length != 0 && !ie_vector) {
return false;
}

uint16_t msg_length = 0;
ns_ie_iovec_t *msg_iov = ie_vector;
for (uint_fast16_t i = 0; i < iov_length; i++) {
if (msg_iov->iovLen != 0 && !msg_iov->ieBase) {
return false;
}
msg_length += msg_iov->iovLen;
if (msg_length < msg_iov->iovLen) {
return false;
}
msg_iov++;
}

if (length_out) {
*length_out = msg_length;
}

return true;

}


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) {
Expand Down Expand Up @@ -206,7 +243,7 @@ void mcps_sap_data_req_handler_ext(protocol_interface_rf_mac_setup_s *rf_mac_set
buffer->fcf_dsn.informationElementsPresets = true;
}

if (buffer->DstPANId == buffer->SrcPANId) {
if (buffer->fcf_dsn.DstAddrMode && buffer->DstPANId == buffer->SrcPANId) {
if (buffer->fcf_dsn.frameVersion == MAC_FRAME_VERSION_2015) {

if (buffer->fcf_dsn.DstAddrMode && buffer->fcf_dsn.SrcAddrMode) {
Expand All @@ -218,6 +255,10 @@ void mcps_sap_data_req_handler_ext(protocol_interface_rf_mac_setup_s *rf_mac_set
} else {
buffer->fcf_dsn.intraPan = true;
}
} else if (buffer->fcf_dsn.DstAddrMode == MAC_ADDR_MODE_NONE && buffer->fcf_dsn.frameVersion == MAC_FRAME_VERSION_2015) {
//Suppress sequence number
buffer->fcf_dsn.sequenceNumberSuppress = true;
buffer->mac_header_length_with_security--;
}

//Check PanID presents at header
Expand Down Expand Up @@ -625,7 +666,7 @@ static int8_t mac_data_sap_rx_handler(mac_pre_parsed_frame_t *buf, protocol_inte
if (mac) {

if (buf->fcf_dsn.frameVersion == MAC_FRAME_VERSION_2015) {
if (!mac->data_ind_ext_cb) {
if (!rf_mac_setup->mac_extension_enabled) {
tr_debug("No Ext reg");
goto DROP_PACKET;
}
Expand Down
4 changes: 3 additions & 1 deletion source/MAC/IEEE802_15_4/mac_pd_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,9 @@ int8_t mac_pd_sap_data_cb(void *identifier, arm_phy_sap_msg_t *message)

switch (buffer->fcf_dsn.frametype) {
case FC_DATA_FRAME:
if (buffer->fcf_dsn.SrcAddrMode == MAC_ADDR_MODE_NONE || buffer->fcf_dsn.DstAddrMode == MAC_ADDR_MODE_NONE) {
if (buffer->fcf_dsn.SrcAddrMode == MAC_ADDR_MODE_NONE) {
goto ERROR_HANDLER;
} else if (buffer->fcf_dsn.DstAddrMode == MAC_ADDR_MODE_NONE && buffer->fcf_dsn.frameVersion != MAC_FRAME_VERSION_2015) {
goto ERROR_HANDLER;
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,6 @@ TEST(mac_header_helper_functions, test_mac_header_information_elements_preparati
CHECK(test_mac_header_information_elements_preparation());
}


TEST(mac_header_helper_functions, test_mac_ie_vector_length_validate)
{
CHECK(test_mac_ie_vector_length_validate());
}

TEST(mac_header_helper_functions, test_mac_buffer_total_payload_length)
{
CHECK(test_mac_buffer_total_payload_length());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -920,44 +920,44 @@ bool test_mac_header_information_elements_preparation()
return true;
}

bool test_mac_ie_vector_length_validate()
{
uint16_t length;
if (!mac_ie_vector_length_validate(NULL, 0, &length) || length) {
return false;
}

if (mac_ie_vector_length_validate(NULL, 2, &length) || length) {
return false;
}

uint8_t temp[8];
ns_ie_iovec_t vector_list[3];
ns_ie_iovec_t *vector = vector_list;
vector->ieBase = NULL;
vector->iovLen = 100;
if (mac_ie_vector_length_validate(vector_list, 3, &length)) {
return false;
}

vector->ieBase = temp;
vector++;
vector->ieBase = temp;
vector->iovLen = 0xfffe;
if (mac_ie_vector_length_validate(vector_list, 3, &length)) {
return false;
}
vector->iovLen = 100;

vector++;
vector->ieBase = temp;
vector->iovLen = 200;

if (!mac_ie_vector_length_validate(vector_list, 3, &length) || length != 400) {
return false;
}
return true;
}
//bool test_mac_ie_vector_length_validate()
//{
// uint16_t length;
// if (!mac_ie_vector_length_validate(NULL, 0, &length) || length) {
// return false;
// }
//
// if (mac_ie_vector_length_validate(NULL, 2, &length) || length) {
// return false;
// }
//
// uint8_t temp[8];
// ns_ie_iovec_t vector_list[3];
// ns_ie_iovec_t *vector = vector_list;
// vector->ieBase = NULL;
// vector->iovLen = 100;
// if (mac_ie_vector_length_validate(vector_list, 3, &length)) {
// return false;
// }
//
// vector->ieBase = temp;
// vector++;
// vector->ieBase = temp;
// vector->iovLen = 0xfffe;
// if (mac_ie_vector_length_validate(vector_list, 3, &length)) {
// return false;
// }
// vector->iovLen = 100;
//
// vector++;
// vector->ieBase = temp;
// vector->iovLen = 200;
//
// if (!mac_ie_vector_length_validate(vector_list, 3, &length) || length != 400) {
// return false;
// }
// return true;
//}

bool test_mac_buffer_total_payload_length()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ bool test_mac_payload_information_elements_parse();

bool test_mac_header_information_elements_preparation();

bool test_mac_ie_vector_length_validate();

bool test_mac_buffer_total_payload_length();

#ifdef __cplusplus
Expand Down
6 changes: 6 additions & 0 deletions test/nanostack/unittest/mac/mac_mcps_sap/mac_mcps_saptest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,9 @@ TEST(mac_mcps_sap, test_mac_mcps_buffer_queue_free)
{
CHECK(test_mac_mcps_buffer_queue_free());
}

TEST(mac_mcps_sap, test_mcps_sap_data_req_handler_ext)
{
CHECK(test_mcps_sap_data_req_handler_ext());
}

Loading

0 comments on commit b9f7bf4

Please sign in to comment.