Skip to content

Commit 0ca78d6

Browse files
author
Juha Heiskanen
authored
Merge pull request ARMmbed#1784 from ARMmbed/iotthd-2533
Iotthd 2533
2 parents 6bc9e00 + 9b37c24 commit 0ca78d6

File tree

9 files changed

+84
-41
lines changed

9 files changed

+84
-41
lines changed

source/6LoWPAN/ws/ws_llc_data_service.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,13 @@ static void ws_llc_mpx_data_request(const mpx_api_t *api, const struct mcps_data
657657
data_req.msduLength = 0;
658658
data_req.msduHandle = message->msg_handle;
659659

660+
if (!data->TxAckReq) {
661+
data_req.PanIdSuppressed = false;
662+
data_req.DstAddrMode = MAC_ADDR_MODE_NONE;
663+
} else {
664+
data_req.PanIdSuppressed = true;
665+
}
666+
660667
uint8_t *ptr = ws_message_buffer_ptr_get(message);
661668
if (user_id == MPX_LOWPAN_ENC_USER_ID) {
662669
message->messsage_type = WS_FT_DATA;

source/MAC/IEEE802_15_4/mac_header_helper_functions.c

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -337,32 +337,59 @@ void mac_header_security_components_read(mac_pre_parsed_frame_t *buffer, mlme_se
337337

338338
}
339339

340-
uint16_t mac_header_get_src_panid(const mac_fcf_sequence_t *header, const uint8_t *ptr)
340+
static bool mac_header_pan_full_compressed(const mac_fcf_sequence_t *header)
341341
{
342-
343-
if (!header->SrcPanPresents) {
344-
if (!header->DstPanPresents) {
345-
return 0xffff;
346-
}
347-
return mac_header_get_dst_panid(header, ptr);
342+
if (header->frameVersion == MAC_FRAME_VERSION_2015 && (!header->DstPanPresents && !header->SrcPanPresents) && header->intraPan) {
343+
return true;
348344
}
345+
return false;
346+
}
349347

348+
static uint16_t mac_header_read_src_pan(const mac_fcf_sequence_t *header, const uint8_t *ptr)
349+
{
350350
ptr += mac_fcf_lenght(header);//Skip FCF + DSN
351351

352352
ptr += mac_dst_address_length_with_panid(header); //Skip Dst panID & Address
353353

354354
return common_read_16_bit_inverse(ptr);
355355
}
356356

357-
uint16_t mac_header_get_dst_panid(const mac_fcf_sequence_t *header, const uint8_t *ptr)
357+
static uint16_t mac_header_read_dst_pan(const mac_fcf_sequence_t *header, const uint8_t *ptr)
358+
{
359+
ptr += mac_fcf_lenght(header);//Skip FCF + DSN
360+
361+
return common_read_16_bit_inverse(ptr);
362+
}
363+
364+
uint16_t mac_header_get_src_panid(const mac_fcf_sequence_t *header, const uint8_t *ptr, uint16_t configured_pan_id)
365+
{
366+
if (mac_header_pan_full_compressed(header)) {
367+
return configured_pan_id;
368+
}
369+
370+
if (!header->SrcPanPresents) {
371+
if (!header->DstPanPresents) {
372+
return 0xffff;
373+
}
374+
return mac_header_read_dst_pan(header, ptr);
375+
}
376+
377+
return mac_header_read_src_pan(header, ptr);
378+
}
379+
380+
uint16_t mac_header_get_dst_panid(const mac_fcf_sequence_t *header, const uint8_t *ptr, uint16_t configured_pan_id)
358381
{
382+
if (mac_header_pan_full_compressed(header)) {
383+
return configured_pan_id;
384+
}
359385
if (!header->DstPanPresents) {
386+
if (header->SrcPanPresents && header->frameVersion == MAC_FRAME_VERSION_2015 && header->DstAddrMode == MAC_ADDR_MODE_NONE) {
387+
return mac_header_read_src_pan(header, ptr);
388+
}
360389
return 0xffff;
361390
}
362391

363-
ptr += mac_fcf_lenght(header);//Skip FCF + DSN
364-
365-
return common_read_16_bit_inverse(ptr);
392+
return mac_header_read_dst_pan(header, ptr);
366393
}
367394

368395
void mac_header_get_src_address(const mac_fcf_sequence_t *header, const uint8_t *ptr, uint8_t *address_ptr)

source/MAC/IEEE802_15_4/mac_header_helper_functions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ uint16_t mac_buffer_total_payload_length(struct mac_pre_build_frame *buffer);
5959
/**
6060
* Next function should only call when address mode is not MAC_ADDR_MODE_NONE and parsed proper header!
6161
*/
62-
uint16_t mac_header_get_src_panid(const struct mac_fcf_sequence_s *header, const uint8_t *ptr);
63-
uint16_t mac_header_get_dst_panid(const struct mac_fcf_sequence_s *header, const uint8_t *ptr);
62+
uint16_t mac_header_get_src_panid(const struct mac_fcf_sequence_s *header, const uint8_t *ptr, uint16_t configured_pan_id);
63+
uint16_t mac_header_get_dst_panid(const struct mac_fcf_sequence_s *header, const uint8_t *ptr, uint16_t configured_pan_id);
6464
void mac_header_get_src_address(const struct mac_fcf_sequence_s *header, const uint8_t *ptr, uint8_t *address_ptr);
6565
void mac_header_get_dst_address(const struct mac_fcf_sequence_s *header, const uint8_t *ptr, uint8_t *address_ptr);
6666
uint8_t mac_address_length(uint8_t address_mode);

source/MAC/IEEE802_15_4/mac_indirect_data.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ uint8_t mac_indirect_data_req_handle(mac_pre_parsed_frame_t *buf, protocol_inter
134134

135135
comm_status.status = MLME_DATA_POLL_NOTIFICATION;
136136
//Call com status
137-
comm_status.PANId = mac_header_get_dst_panid(&buf->fcf_dsn, mac_header_message_start_pointer(buf));
137+
comm_status.PANId = mac_header_get_dst_panid(&buf->fcf_dsn, mac_header_message_start_pointer(buf), mac_ptr->pan_id);
138138
comm_status.DstAddrMode = buf->fcf_dsn.DstAddrMode;;
139139
mac_header_get_dst_address(&buf->fcf_dsn, mac_header_message_start_pointer(buf), comm_status.DstAddr);
140140
comm_status.SrcAddrMode = buf->fcf_dsn.SrcAddrMode;

source/MAC/IEEE802_15_4/mac_mcps_sap.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ static uint8_t mac_data_interface_decrypt_packet(mac_pre_parsed_frame_t *b, mlme
568568

569569
//READ SRC Address
570570

571-
uint16_t SrcPANId = mac_header_get_src_panid(&b->fcf_dsn, mac_header_message_start_pointer(b));
571+
uint16_t SrcPANId = mac_header_get_src_panid(&b->fcf_dsn, mac_header_message_start_pointer(b), rf_mac_setup->pan_id);
572572
mac_header_get_src_address(&b->fcf_dsn, mac_header_message_start_pointer(b), neighbour_validation.address);
573573
neighbour_validation.addr_type = b->fcf_dsn.SrcAddrMode;
574574
neighbour_validation.keyId = security_params->KeyIndex;
@@ -670,10 +670,11 @@ static uint8_t mac_data_interface_decrypt_packet(mac_pre_parsed_frame_t *b, mlme
670670
static void mcps_comm_status_indication_generate(uint8_t status, mac_pre_parsed_frame_t *buf, mac_api_t * mac)
671671
{
672672
mlme_comm_status_t comm_status;
673+
protocol_interface_rf_mac_setup_s *rf_ptr = buf->mac_class_ptr;
673674
memset(&comm_status,0 ,sizeof(mlme_comm_status_t) );
674675
comm_status.status = status;
675676
//Call com status
676-
comm_status.PANId = mac_header_get_dst_panid(&buf->fcf_dsn, mac_header_message_start_pointer(buf));
677+
comm_status.PANId = mac_header_get_dst_panid(&buf->fcf_dsn, mac_header_message_start_pointer(buf), rf_ptr->pan_id);
677678
comm_status.DstAddrMode = buf->fcf_dsn.DstAddrMode;;
678679
mac_header_get_dst_address(&buf->fcf_dsn, mac_header_message_start_pointer(buf), comm_status.DstAddr);
679680
comm_status.SrcAddrMode = buf->fcf_dsn.SrcAddrMode;
@@ -723,12 +724,14 @@ static int8_t mac_data_sap_rx_handler(mac_pre_parsed_frame_t *buf, protocol_inte
723724
//Parse data
724725
data_ind->DSN = buf->fcf_dsn.DSN;
725726
data_ind->DstAddrMode = buf->fcf_dsn.DstAddrMode;
726-
data_ind->DstPANId = mac_header_get_dst_panid(&buf->fcf_dsn, mac_header_message_start_pointer(buf));
727727
mac_header_get_dst_address(&buf->fcf_dsn, mac_header_message_start_pointer(buf), data_ind->DstAddr);
728728
data_ind->SrcAddrMode = buf->fcf_dsn.SrcAddrMode;
729-
data_ind->SrcPANId = mac_header_get_src_panid(&buf->fcf_dsn, mac_header_message_start_pointer(buf));
729+
730730
mac_header_get_src_address(&buf->fcf_dsn, mac_header_message_start_pointer(buf), data_ind->SrcAddr);
731731

732+
data_ind->SrcPANId = mac_header_get_src_panid(&buf->fcf_dsn, mac_header_message_start_pointer(buf), rf_mac_setup->pan_id);
733+
data_ind->DstPANId = mac_header_get_dst_panid(&buf->fcf_dsn, mac_header_message_start_pointer(buf), rf_mac_setup->pan_id);
734+
732735
data_ind->mpduLinkQuality = buf->LQI;
733736
data_ind->signal_dbm = buf->dbm;
734737
data_ind->timestamp = buf->timestamp;
@@ -772,6 +775,12 @@ static int8_t mac_data_sap_rx_handler(mac_pre_parsed_frame_t *buf, protocol_inte
772775
ie_list.payloadIeListLength = buf->payloadsIeLength;
773776
ie_list.headerIeList = buf->headerIePtr;
774777
ie_list.headerIeListLength = buf->headerIeLength;
778+
//Swap compressed address to broadcast when dst Address is elided
779+
if (buf->fcf_dsn.DstAddrMode == MAC_ADDR_MODE_NONE) {
780+
data_ind->DstAddrMode = MAC_ADDR_MODE_16_BIT;
781+
data_ind->DstAddr[0] = 0xff;
782+
data_ind->DstAddr[1] = 0xff;
783+
}
775784
mac->data_ind_ext_cb(mac, data_ind, &ie_list);
776785

777786
} else {
@@ -796,7 +805,7 @@ static void mac_lib_res_no_data_to_req(mac_pre_parsed_frame_t *buffer, protocol_
796805
buf->fcf_dsn.SrcAddrMode = buffer->fcf_dsn.DstAddrMode;
797806
buf->fcf_dsn.DstAddrMode = buffer->fcf_dsn.SrcAddrMode;
798807
//SET PANID
799-
buf->SrcPANId = mac_header_get_dst_panid(&buffer->fcf_dsn, mac_header_message_start_pointer(buffer));
808+
buf->SrcPANId = mac_header_get_dst_panid(&buffer->fcf_dsn, mac_header_message_start_pointer(buffer), rf_mac_setup->pan_id);
800809
buf->DstPANId = buf->SrcPANId;
801810

802811
mac_header_get_dst_address(&buffer->fcf_dsn, mac_header_message_start_pointer(buffer), buf->SrcAddr);
@@ -910,7 +919,7 @@ static void mac_data_interface_parse_beacon(mac_pre_parsed_frame_t *buf, protoco
910919
uint8_t *pending_address_list = NULL;
911920
uint8_t SuperframeSpec[2];
912921

913-
uint16_t src_pan_id = mac_header_get_src_panid(&buf->fcf_dsn, mac_header_message_start_pointer(buf));
922+
uint16_t src_pan_id = mac_header_get_src_panid(&buf->fcf_dsn, mac_header_message_start_pointer(buf), rf_mac_setup->pan_id);
914923

915924
//validate beacon pan-id and filter other network out
916925
if (rf_mac_setup->pan_id < 0xffff && (rf_mac_setup->pan_id != src_pan_id && !rf_mac_setup->macAcceptAnyBeacon)) {
@@ -1615,6 +1624,7 @@ int8_t mcps_generic_ack_build(protocol_interface_rf_mac_setup_s *rf_ptr, const m
16151624
buffer->fcf_dsn.frameVersion = fcf->frameVersion;
16161625
buffer->fcf_dsn.framePending = rf_ptr->mac_frame_pending;
16171626
buffer->fcf_dsn.DSN = fcf->DSN;
1627+
buffer->fcf_dsn.intraPan = fcf->intraPan;
16181628
buffer->fcf_dsn.sequenceNumberSuppress = fcf->sequenceNumberSuppress;
16191629
buffer->fcf_dsn.DstPanPresents = fcf->DstPanPresents;
16201630
buffer->fcf_dsn.SrcAddrMode = fcf->DstAddrMode;
@@ -1628,9 +1638,8 @@ int8_t mcps_generic_ack_build(protocol_interface_rf_mac_setup_s *rf_ptr, const m
16281638

16291639
buffer->mac_header_length_with_security += mac_header_address_length(&buffer->fcf_dsn);
16301640

1631-
buffer->DstPANId = mac_header_get_src_panid(fcf, data_ptr);
1632-
buffer->SrcPANId = mac_header_get_dst_panid(fcf, data_ptr);
1633-
1641+
buffer->DstPANId = mac_header_get_src_panid(fcf, data_ptr, rf_ptr->pan_id);
1642+
buffer->SrcPANId = mac_header_get_dst_panid(fcf, data_ptr, rf_ptr->pan_id);
16341643
mac_header_get_src_address(fcf, data_ptr, buffer->DstAddr);
16351644
mac_header_get_dst_address(fcf, data_ptr, buffer->SrcAddr);
16361645

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,21 +268,21 @@ bool test_mac_header_get_src_panid()
268268
seq.SrcPanPresents = false;
269269

270270

271-
if( 0xffff != mac_header_get_src_panid(&seq, &ptr) ){
271+
if( 0xffff != mac_header_get_src_panid(&seq, &ptr, 0xffff) ){
272272
return false;
273273
}
274274
seq.SrcPanPresents = false;
275275
seq.DstPanPresents = true;
276276

277-
mac_header_get_src_panid(&seq, &ptr);
277+
mac_header_get_src_panid(&seq, &ptr, 0xffff);
278278
if (memcmp(common_functions_stub.argument_table, &ptr[3], 2)) {
279279
return false;
280280
}
281281

282282
seq.DstPanPresents = false;
283283
seq.SrcPanPresents = true;
284284

285-
mac_header_get_src_panid(&seq, &ptr);
285+
mac_header_get_src_panid(&seq, &ptr, 0xffff);
286286
if (memcmp(common_functions_stub.argument_table, &ptr[3], 2)) {
287287
return false;
288288
}
@@ -291,15 +291,15 @@ bool test_mac_header_get_src_panid()
291291
ptr[8] = 0;
292292
seq.DstPanPresents = true;
293293
seq.DstAddrMode = MAC_ADDR_MODE_16_BIT;
294-
mac_header_get_src_panid(&seq, &ptr);
294+
mac_header_get_src_panid(&seq, &ptr, 0xffff);
295295
if (memcmp(common_functions_stub.argument_table, &ptr[7], 2)) {
296296
return false;
297297
}
298298

299299
ptr[13] = 5;
300300
ptr[14] = 0;
301301
seq.DstAddrMode = MAC_ADDR_MODE_64_BIT;
302-
mac_header_get_src_panid(&seq, &ptr);
302+
mac_header_get_src_panid(&seq, &ptr, 0xffff);
303303
if (memcmp(common_functions_stub.argument_table, &ptr[13], 2)) {
304304
return false;
305305
}
@@ -316,12 +316,12 @@ bool test_mac_header_get_dst_panid()
316316
ptr[3] = 3;
317317
ptr[4] = 0;
318318
seq.DstPanPresents = false;
319-
uint16_t ret = mac_header_get_dst_panid(&seq, &ptr);
319+
uint16_t ret = mac_header_get_dst_panid(&seq, &ptr, 0xffff);
320320
if( 0xffff != ret ){
321321
return false;
322322
}
323323
seq.DstPanPresents = true;
324-
mac_header_get_dst_panid(&seq, &ptr);
324+
mac_header_get_dst_panid(&seq, &ptr,0xffff);
325325
if (memcmp(common_functions_stub.argument_table, &ptr[3], 2)) {
326326
return false;
327327
}

test/nanostack/unittest/mac/mac_mcps_sap/test_mac_mcps_sap.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -649,23 +649,16 @@ bool test_mac_mcps_data_confirmation()
649649
event_stub.int8_value = 0;
650650
int8_t mac_tasklet_id = mac_mcps_sap_tasklet_init();
651651
mcps_data_req_t data_req;
652+
memset(&data_req, 0, sizeof(mcps_data_req_t));
652653

653654
ccm_globals_t ccm_ptr;
654655
mac_api_t mac_api;
655-
mlme_key_descriptor_t key_description;
656-
mlme_device_descriptor_t device_description;
657-
mac_aux_security_header_t secuirity_params;
658-
mlme_key_device_descriptor_t key_device_description;
659-
memset(&data_req, 0, sizeof(mcps_data_req_t));
656+
memset(&mac_api, 0, sizeof(mac_api_t));
660657

661658
uint8_t tx_buf[127];
662-
uint8_t tx_temp[200];
663659
protocol_interface_rf_mac_setup_s *rf_mac_setup = test_mac_rf_mac_class_allocate();
664660
memset(tx_buf, 1, 127);
665661

666-
memset(&key_description, 0, sizeof(mlme_key_descriptor_t));
667-
memset(&device_description, 0, sizeof(mlme_device_descriptor_t));
668-
669662
mac_api.data_conf_cb = &test_mcps_data_confirm;
670663
mac_api.mlme_conf_cb = &test_mlme_confirm;
671664
mac_api.data_ind_cb = &test_mcps_data_indication;
@@ -675,6 +668,8 @@ bool test_mac_mcps_data_confirmation()
675668

676669
rf_mac_setup->macUpState = true;
677670
sw_mac_stub.mac_api_ptr = &mac_api;
671+
mac_header_helper_functions_stub.uint8_value = 0;
672+
memset(&mac_header_helper_functions_stub.security_header, 0, sizeof(mac_header_helper_functions_stub.security_header));
678673

679674
data_req.msdu = tx_buf;
680675
data_req.msduLength = 10;
@@ -2287,6 +2282,7 @@ bool test_mcps_sap_data_req_ext_handler()
22872282
memset(&secuirity_params, 0, sizeof(mac_aux_security_header_t));
22882283
mcps_data_req_t data_req;
22892284
memset(&data_req, 0, sizeof(mcps_data_req_t));
2285+
memset(&mac_header_helper_functions_stub.security_header, 0, sizeof(mac_header_helper_functions_stub.security_header));
22902286

22912287
uint8_t tx_buf[127];
22922288
uint8_t tx_buf_driver[127];
@@ -2364,6 +2360,7 @@ bool test_mcps_sap_data_req_handler()
23642360
memset(&secuirity_params, 0, sizeof(mac_aux_security_header_t));
23652361
mcps_data_req_t data_req;
23662362
memset(&data_req, 0, sizeof(mcps_data_req_t));
2363+
memset(&mac_header_helper_functions_stub.security_header, 0, sizeof(mac_header_helper_functions_stub.security_header));
23672364

23682365
uint8_t tx_buf[127];
23692366
uint8_t msdu_handle = 0;
@@ -3003,6 +3000,7 @@ bool test_mcps_sap_data_req_handler_ext()
30033000
memset(&ie_list, 0, sizeof(mcps_data_req_ie_list_t));
30043001
channel_list_s asynch_channel_list;
30053002
memset(&asynch_channel_list, 0, sizeof(channel_list_s));
3003+
memset(&mac_header_helper_functions_stub.security_header, 0, sizeof(mac_header_helper_functions_stub.security_header));
30063004

30073005
ns_ie_iovec_t vector_list[3];
30083006

test/nanostack/unittest/mac/mac_pd_sap/test_mac_pd_sap.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,8 @@ bool test_mac_pd_sap_data_cb()
549549

550550
// FHSS TESTS START
551551
mac_pre_build_frame_t temp_buf;
552+
553+
memset(&temp_buf, 0, sizeof(mac_pre_build_frame_t));
552554
rf_ptr.active_pd_data_request = &temp_buf;
553555
mac_mcps_sap_stub.int8_value = 0;
554556
nsdynmemlib_stub.returnCounter = 1;

test/nanostack/unittest/stub/mac_header_helper_functions_stub.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ uint16_t mac_header_off_set_to_aux_header(const mac_fcf_sequence_t *fcf)
8484
return 0;
8585
}
8686

87-
uint16_t mac_header_get_src_panid(const mac_fcf_sequence_t *header, const uint8_t *ptr)
87+
uint16_t mac_header_get_src_panid(const mac_fcf_sequence_t *header, const uint8_t *ptr, uint16_t configured_pan_id)
8888
{
8989
return mac_header_helper_functions_stub.pan_src;
9090
}
9191

92-
uint16_t mac_header_get_dst_panid(const mac_fcf_sequence_t *header, const uint8_t *ptr)
92+
uint16_t mac_header_get_dst_panid(const mac_fcf_sequence_t *header, const uint8_t *ptr, uint16_t configured_pan_id)
9393
{
9494
return mac_header_helper_functions_stub.uint16_value;
9595
}

0 commit comments

Comments
 (0)