@@ -389,80 +389,87 @@ static uint8_t mle_link_quality_tlv_parse(uint8_t *mac64, uint16_t short_address
389
389
return 0 ;
390
390
}
391
391
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
+
392
403
static uint8_t * mle_table_set_neighbours (protocol_interface_info_entry_t * cur , uint8_t * ptr )
393
404
{
394
405
uint8_t * len_ptr = 0 ;
395
- uint8_t short_temp [2 ] = {0xff ,0xff };
396
406
uint8_t neigh_count = 0 ;
397
407
uint8_t neigh_count_max = 0 ;
398
408
uint8_t * link_flags_ptr ;
399
409
mac_neighbor_table_entry_t * first_entry_ptr = NULL ;
400
- bool loop_list = false;
401
410
402
411
mac_neighbor_table_list_t * neigh_list = & cur -> mac_parameters -> mac_neighbor_table -> neighbour_list ;
403
412
404
413
* ptr ++ = MLE_TYPE_LINK_QUALITY ;
405
414
len_ptr = ptr ++ ;
406
415
* len_ptr = 1 ;
407
- // defaults: complete, 2 bytes long link-layer address
416
+
408
417
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 ;
413
423
} 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
+
415
427
}
428
+ neigh_count_max = mle_advert_neigh_cnt (cur , use_short_address_compression );
416
429
417
430
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
+ {
423
433
424
- if ((cur_entry -> connected_device ) && (cur_entry -> advertisment == false) && ( cur_entry -> mac16 < 0xfffe )) {
434
+ if ((cur_entry -> connected_device ) && (cur_entry -> advertisment == false)) {
425
435
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
+ }
432
442
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
+ }
438
448
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
+ }
444
454
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 ;
446
456
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
+ }
455
465
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;
463
469
}
470
+ cur_entry -> advertisment = true;
464
471
}
465
- } while ( loop_list );
472
+ }
466
473
467
474
if (clean_entries ) {
468
475
ns_list_foreach (mac_neighbor_table_entry_t , temp , neigh_list ) {
0 commit comments