Skip to content

Commit b9f7bf4

Browse files
Juha Heiskanenjuhhei01
authored andcommitted
MAC functional updates and fix's:
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.
1 parent 2cef8ac commit b9f7bf4

13 files changed

+346
-92
lines changed

source/MAC/IEEE802_15_4/mac_header_helper_functions.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -683,38 +683,6 @@ void mac_header_information_elements_preparation(mac_pre_build_frame_t *buffer)
683683
}
684684
}
685685

686-
bool mac_ie_vector_length_validate(ns_ie_iovec_t *ie_vector, uint16_t iov_length, uint16_t *length_out)
687-
{
688-
*length_out = 0;
689-
if (!iov_length) {
690-
return true;
691-
}
692-
693-
if (iov_length != 0 && !ie_vector) {
694-
return false;
695-
}
696-
697-
uint16_t msg_length = 0;
698-
ns_ie_iovec_t *msg_iov = ie_vector;
699-
for (uint_fast16_t i = 0; i < iov_length; i++) {
700-
if (msg_iov->iovLen != 0 && !msg_iov->ieBase) {
701-
return false;
702-
}
703-
msg_length += msg_iov->iovLen;
704-
if (msg_length < msg_iov->iovLen) {
705-
return false;
706-
}
707-
msg_iov++;
708-
}
709-
710-
if (length_out) {
711-
*length_out = msg_length;
712-
}
713-
714-
return true;
715-
716-
}
717-
718686
uint16_t mac_buffer_total_payload_length(mac_pre_build_frame_t *buffer)
719687
{
720688
return mac_payload_length_calc_with_ie(buffer->mac_payload_length, buffer->payloadsIeLength);

source/MAC/IEEE802_15_4/mac_header_helper_functions.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ void mac_header_information_elements_preparation(struct mac_pre_build_frame *buf
5151

5252
uint16_t mac_buffer_total_payload_length(struct mac_pre_build_frame *buffer);
5353

54-
bool mac_ie_vector_length_validate(struct ns_ie_iovec *ie_vector, uint16_t iov_length, uint16_t *length_out);
55-
5654
/**
5755
* Next function should only call when address mode is not MAC_ADDR_MODE_NONE and parsed proper header!
5856
*/

source/MAC/IEEE802_15_4/mac_indirect_data.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,13 @@ void mac_indirect_data_ttl_handle(protocol_interface_rf_mac_setup_s *cur, uint16
9393
confirm.status = MLME_TRANSACTION_EXPIRED;
9494

9595
mcps_sap_prebuild_frame_buffer_free(buf_temp);
96-
if( api->data_conf_cb ) {
96+
97+
if (cur->mac_extension_enabled) {
98+
mcps_data_conf_payload_t data_conf;
99+
memset(&data_conf, 0, sizeof(mcps_data_conf_payload_t));
100+
//Check Payload Here
101+
api->data_conf_ext_cb(api, &confirm, &data_conf);
102+
} else {
97103
api->data_conf_cb(api, &confirm);
98104
}
99105
}

source/MAC/IEEE802_15_4/mac_mcps_sap.c

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,14 @@ static void mcps_data_confirm_cb(protocol_interface_rf_mac_setup_s *rf_mac_setup
8787
mac_data_poll_radio_disable_check(rf_mac_setup);
8888

8989
if( get_sw_mac_api(rf_mac_setup) ) {
90-
get_sw_mac_api(rf_mac_setup)->data_conf_cb(get_sw_mac_api(rf_mac_setup), confirm);
90+
if (rf_mac_setup->mac_extension_enabled) {
91+
mcps_data_conf_payload_t data_conf;
92+
memset(&data_conf, 0, sizeof(mcps_data_conf_payload_t));
93+
//Check Payload Here
94+
get_sw_mac_api(rf_mac_setup)->data_conf_ext_cb(get_sw_mac_api(rf_mac_setup), confirm, &data_conf);
95+
} else {
96+
get_sw_mac_api(rf_mac_setup)->data_conf_cb(get_sw_mac_api(rf_mac_setup), confirm);
97+
}
9198
}
9299
}
93100

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

108+
static bool mac_ie_vector_length_validate(ns_ie_iovec_t *ie_vector, uint16_t iov_length, uint16_t *length_out)
109+
{
110+
*length_out = 0;
111+
if (!iov_length) {
112+
return true;
113+
}
114+
115+
if (iov_length != 0 && !ie_vector) {
116+
return false;
117+
}
118+
119+
uint16_t msg_length = 0;
120+
ns_ie_iovec_t *msg_iov = ie_vector;
121+
for (uint_fast16_t i = 0; i < iov_length; i++) {
122+
if (msg_iov->iovLen != 0 && !msg_iov->ieBase) {
123+
return false;
124+
}
125+
msg_length += msg_iov->iovLen;
126+
if (msg_length < msg_iov->iovLen) {
127+
return false;
128+
}
129+
msg_iov++;
130+
}
131+
132+
if (length_out) {
133+
*length_out = msg_length;
134+
}
135+
136+
return true;
137+
138+
}
139+
101140

102141
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) {
103142
uint8_t status = MLME_SUCCESS;
104143
mac_pre_build_frame_t *buffer = NULL;
105144

106-
//Asynch Data request will be enabled seperately lare API is defined
107-
108145

109146
if (!rf_mac_setup->mac_security_enabled) {
110147
if (data_req->Key.SecurityLevel) {
@@ -206,7 +243,7 @@ void mcps_sap_data_req_handler_ext(protocol_interface_rf_mac_setup_s *rf_mac_set
206243
buffer->fcf_dsn.informationElementsPresets = true;
207244
}
208245

209-
if (buffer->DstPANId == buffer->SrcPANId) {
246+
if (buffer->fcf_dsn.DstAddrMode && buffer->DstPANId == buffer->SrcPANId) {
210247
if (buffer->fcf_dsn.frameVersion == MAC_FRAME_VERSION_2015) {
211248

212249
if (buffer->fcf_dsn.DstAddrMode && buffer->fcf_dsn.SrcAddrMode) {
@@ -218,6 +255,10 @@ void mcps_sap_data_req_handler_ext(protocol_interface_rf_mac_setup_s *rf_mac_set
218255
} else {
219256
buffer->fcf_dsn.intraPan = true;
220257
}
258+
} else if (buffer->fcf_dsn.DstAddrMode == MAC_ADDR_MODE_NONE && buffer->fcf_dsn.frameVersion == MAC_FRAME_VERSION_2015) {
259+
//Suppress sequence number
260+
buffer->fcf_dsn.sequenceNumberSuppress = true;
261+
buffer->mac_header_length_with_security--;
221262
}
222263

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

627668
if (buf->fcf_dsn.frameVersion == MAC_FRAME_VERSION_2015) {
628-
if (!mac->data_ind_ext_cb) {
669+
if (!rf_mac_setup->mac_extension_enabled) {
629670
tr_debug("No Ext reg");
630671
goto DROP_PACKET;
631672
}

source/MAC/IEEE802_15_4/mac_pd_sap.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,9 @@ int8_t mac_pd_sap_data_cb(void *identifier, arm_phy_sap_msg_t *message)
460460

461461
switch (buffer->fcf_dsn.frametype) {
462462
case FC_DATA_FRAME:
463-
if (buffer->fcf_dsn.SrcAddrMode == MAC_ADDR_MODE_NONE || buffer->fcf_dsn.DstAddrMode == MAC_ADDR_MODE_NONE) {
463+
if (buffer->fcf_dsn.SrcAddrMode == MAC_ADDR_MODE_NONE) {
464+
goto ERROR_HANDLER;
465+
} else if (buffer->fcf_dsn.DstAddrMode == MAC_ADDR_MODE_NONE && buffer->fcf_dsn.frameVersion != MAC_FRAME_VERSION_2015) {
464466
goto ERROR_HANDLER;
465467
}
466468
break;

test/nanostack/unittest/mac/mac_header_helper_functions/mac_header_helper_functionstest.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,6 @@ TEST(mac_header_helper_functions, test_mac_header_information_elements_preparati
134134
CHECK(test_mac_header_information_elements_preparation());
135135
}
136136

137-
138-
TEST(mac_header_helper_functions, test_mac_ie_vector_length_validate)
139-
{
140-
CHECK(test_mac_ie_vector_length_validate());
141-
}
142-
143137
TEST(mac_header_helper_functions, test_mac_buffer_total_payload_length)
144138
{
145139
CHECK(test_mac_buffer_total_payload_length());

test/nanostack/unittest/mac/mac_header_helper_functions/test_mac_header_helper_functions.c

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -920,44 +920,44 @@ bool test_mac_header_information_elements_preparation()
920920
return true;
921921
}
922922

923-
bool test_mac_ie_vector_length_validate()
924-
{
925-
uint16_t length;
926-
if (!mac_ie_vector_length_validate(NULL, 0, &length) || length) {
927-
return false;
928-
}
929-
930-
if (mac_ie_vector_length_validate(NULL, 2, &length) || length) {
931-
return false;
932-
}
933-
934-
uint8_t temp[8];
935-
ns_ie_iovec_t vector_list[3];
936-
ns_ie_iovec_t *vector = vector_list;
937-
vector->ieBase = NULL;
938-
vector->iovLen = 100;
939-
if (mac_ie_vector_length_validate(vector_list, 3, &length)) {
940-
return false;
941-
}
942-
943-
vector->ieBase = temp;
944-
vector++;
945-
vector->ieBase = temp;
946-
vector->iovLen = 0xfffe;
947-
if (mac_ie_vector_length_validate(vector_list, 3, &length)) {
948-
return false;
949-
}
950-
vector->iovLen = 100;
951-
952-
vector++;
953-
vector->ieBase = temp;
954-
vector->iovLen = 200;
955-
956-
if (!mac_ie_vector_length_validate(vector_list, 3, &length) || length != 400) {
957-
return false;
958-
}
959-
return true;
960-
}
923+
//bool test_mac_ie_vector_length_validate()
924+
//{
925+
// uint16_t length;
926+
// if (!mac_ie_vector_length_validate(NULL, 0, &length) || length) {
927+
// return false;
928+
// }
929+
//
930+
// if (mac_ie_vector_length_validate(NULL, 2, &length) || length) {
931+
// return false;
932+
// }
933+
//
934+
// uint8_t temp[8];
935+
// ns_ie_iovec_t vector_list[3];
936+
// ns_ie_iovec_t *vector = vector_list;
937+
// vector->ieBase = NULL;
938+
// vector->iovLen = 100;
939+
// if (mac_ie_vector_length_validate(vector_list, 3, &length)) {
940+
// return false;
941+
// }
942+
//
943+
// vector->ieBase = temp;
944+
// vector++;
945+
// vector->ieBase = temp;
946+
// vector->iovLen = 0xfffe;
947+
// if (mac_ie_vector_length_validate(vector_list, 3, &length)) {
948+
// return false;
949+
// }
950+
// vector->iovLen = 100;
951+
//
952+
// vector++;
953+
// vector->ieBase = temp;
954+
// vector->iovLen = 200;
955+
//
956+
// if (!mac_ie_vector_length_validate(vector_list, 3, &length) || length != 400) {
957+
// return false;
958+
// }
959+
// return true;
960+
//}
961961

962962
bool test_mac_buffer_total_payload_length()
963963
{

test/nanostack/unittest/mac/mac_header_helper_functions/test_mac_header_helper_functions.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ bool test_mac_payload_information_elements_parse();
6565

6666
bool test_mac_header_information_elements_preparation();
6767

68-
bool test_mac_ie_vector_length_validate();
69-
7068
bool test_mac_buffer_total_payload_length();
7169

7270
#ifdef __cplusplus

test/nanostack/unittest/mac/mac_mcps_sap/mac_mcps_saptest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,9 @@ TEST(mac_mcps_sap, test_mac_mcps_buffer_queue_free)
113113
{
114114
CHECK(test_mac_mcps_buffer_queue_free());
115115
}
116+
117+
TEST(mac_mcps_sap, test_mcps_sap_data_req_handler_ext)
118+
{
119+
CHECK(test_mcps_sap_data_req_handler_ext());
120+
}
121+

0 commit comments

Comments
 (0)