Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 87cc2c9

Browse files
authored
Merge pull request ARMmbed#1763 from ARMmbed/mle_fixs
Fix broken MLE neigbor list write operation.
2 parents 833e740 + 944f9ca commit 87cc2c9

File tree

1 file changed

+54
-47
lines changed

1 file changed

+54
-47
lines changed

source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan_bootstrap.c

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -389,80 +389,87 @@ static uint8_t mle_link_quality_tlv_parse(uint8_t *mac64, uint16_t short_address
389389
return 0;
390390
}
391391

392+
static bool neighbor_list_short_address_available(mac_neighbor_table_t *table_class)
393+
{
394+
ns_list_foreach(mac_neighbor_table_entry_t, cur_entry, &table_class->neighbour_list) {
395+
if (cur_entry->connected_device && cur_entry->mac16 == 0xffff) {
396+
return false;
397+
}
398+
}
399+
return true;
400+
}
401+
402+
392403
static uint8_t *mle_table_set_neighbours(protocol_interface_info_entry_t *cur, uint8_t *ptr)
393404
{
394405
uint8_t *len_ptr = 0;
395-
uint8_t short_temp[2] = {0xff,0xff};
396406
uint8_t neigh_count = 0;
397407
uint8_t neigh_count_max = 0;
398408
uint8_t *link_flags_ptr;
399409
mac_neighbor_table_entry_t *first_entry_ptr = NULL;
400-
bool loop_list = false;
401410

402411
mac_neighbor_table_list_t * neigh_list = &cur->mac_parameters->mac_neighbor_table->neighbour_list;
403412

404413
*ptr++ = MLE_TYPE_LINK_QUALITY;
405414
len_ptr = ptr++;
406415
*len_ptr = 1;
407-
// defaults: complete, 2 bytes long link-layer address
416+
408417
link_flags_ptr = ptr++;
409-
*link_flags_ptr = 0x81;
410-
if (mac_neighbor_table_address_discover(mac_neighbor_info(cur), short_temp,ADDR_802_15_4_SHORT)) {
411-
*link_flags_ptr |= 0x07;
412-
neigh_count_max = mle_advert_neigh_cnt(cur, false);
418+
//*link_flags_ptr = 0x81;
419+
bool use_short_address_compression = neighbor_list_short_address_available(mac_neighbor_info(cur));
420+
if (use_short_address_compression) {
421+
//complete, 2 bytes long link-layer address
422+
*link_flags_ptr = 0x81;
413423
} else {
414-
neigh_count_max = mle_advert_neigh_cnt(cur, true);
424+
//complete, 8 bytes long link-layer address
425+
*link_flags_ptr = 0x87;
426+
415427
}
428+
neigh_count_max = mle_advert_neigh_cnt(cur, use_short_address_compression);
416429

417430
bool clean_entries = false;
418-
do {
419-
ns_list_foreach(mac_neighbor_table_entry_t, cur_entry, neigh_list)
420-
{
421-
422-
loop_list = false;
431+
ns_list_foreach(mac_neighbor_table_entry_t, cur_entry, neigh_list)
432+
{
423433

424-
if ((cur_entry->connected_device) && (cur_entry->advertisment == false) && (cur_entry->mac16 < 0xfffe)) {
434+
if ((cur_entry->connected_device) && (cur_entry->advertisment == false)) {
425435

426-
// If looping list, stops adding entries when at first sent entry again
427-
if (first_entry_ptr == cur_entry) {
428-
break;
429-
} else if (first_entry_ptr == NULL) {
430-
first_entry_ptr = cur_entry;
431-
}
436+
// If looping list, stops adding entries when at first sent entry again
437+
if (first_entry_ptr == cur_entry) {
438+
break;
439+
} else if (first_entry_ptr == NULL) {
440+
first_entry_ptr = cur_entry;
441+
}
432442

433-
// Limits the number of entries that are sent
434-
if (++neigh_count > neigh_count_max) {
435-
*link_flags_ptr &= 0x7f;
436-
break;
437-
}
443+
// Limits the number of entries that are sent
444+
if (++neigh_count > neigh_count_max) {
445+
*link_flags_ptr &= 0x7f;
446+
break;
447+
}
438448

439-
if (cur_entry->link_role == PRIORITY_PARENT_NEIGHBOUR) {
440-
*ptr++ = MLE_NEIGHBOR_PRIORITY_LINK | MLE_NEIGHBOR_INCOMING_LINK | MLE_NEIGHBOR_OUTGOING_LINK;
441-
} else {
442-
*ptr++ = MLE_NEIGHBOR_INCOMING_LINK | MLE_NEIGHBOR_OUTGOING_LINK;
443-
}
449+
if (cur_entry->link_role == PRIORITY_PARENT_NEIGHBOUR) {
450+
*ptr++ = MLE_NEIGHBOR_PRIORITY_LINK | MLE_NEIGHBOR_INCOMING_LINK | MLE_NEIGHBOR_OUTGOING_LINK;
451+
} else {
452+
*ptr++ = MLE_NEIGHBOR_INCOMING_LINK | MLE_NEIGHBOR_OUTGOING_LINK;
453+
}
444454

445-
*ptr++ = etx_local_incoming_idr_read(cur->id, cur_entry->index) >> 3;
455+
*ptr++ = etx_local_incoming_idr_read(cur->id, cur_entry->index) >> 3;
446456

447-
if ((*link_flags_ptr & 0x07) == 1) {
448-
ptr = common_write_16_bit(cur_entry->mac16, ptr);
449-
*len_ptr += 4;
450-
} else {
451-
memcpy(ptr, cur_entry->mac64, 8);
452-
ptr += 8;
453-
*len_ptr += 10;
454-
}
457+
if (use_short_address_compression) {
458+
ptr = common_write_16_bit(cur_entry->mac16, ptr);
459+
*len_ptr += 4;
460+
} else {
461+
memcpy(ptr, cur_entry->mac64, 8);
462+
ptr += 8;
463+
*len_ptr += 10;
464+
}
455465

456-
// If end of the neighbor list, start adding entries from start again
457-
if (cur_entry->link.next == 0) {
458-
loop_list = true;
459-
clean_entries = true;
460-
} else {
461-
cur_entry->advertisment = true;
462-
}
466+
// If end of the neighbor list, Mark a clean advertisment from the list
467+
if (cur_entry->link.next == 0) {
468+
clean_entries = true;
463469
}
470+
cur_entry->advertisment = true;
464471
}
465-
} while (loop_list);
472+
}
466473

467474
if (clean_entries) {
468475
ns_list_foreach(mac_neighbor_table_entry_t, temp, neigh_list) {

0 commit comments

Comments
 (0)