73
73
#include "6LoWPAN/lowpan_adaptation_interface.h"
74
74
#include "6LoWPAN/Fragmentation/cipv6_fragmenter.h"
75
75
#include "Service_Libs/etx/etx.h"
76
+ #include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
76
77
77
78
78
79
#define TRACE_GROUP_LOWPAN "6lo"
@@ -349,7 +350,6 @@ void protocol_6lowpan_host_init(protocol_interface_info_entry_t *cur, bool sleep
349
350
}
350
351
//Clear always INTERFACE_NWK_ROUTER_DEVICE, INTERFACE_NWK_CONF_MAC_RX_OFF_IDLE
351
352
cur -> lowpan_info &= ~(INTERFACE_NWK_ROUTER_DEVICE | INTERFACE_NWK_CONF_MAC_RX_OFF_IDLE );
352
- mle_class_mode_set (cur -> id , MLE_CLASS_END_DEVICE );
353
353
mac_helper_pib_boolean_set (cur , macRxOnWhenIdle , true);
354
354
mac_data_poll_init (cur );
355
355
arm_nwk_6lowpan_borderrouter_data_free (cur );
@@ -360,7 +360,6 @@ void protocol_6lowpan_router_init(protocol_interface_info_entry_t *cur)
360
360
cur -> bootsrap_mode = ARM_NWK_BOOTSRAP_MODE_6LoWPAN_ROUTER ;
361
361
cur -> lowpan_info |= INTERFACE_NWK_ROUTER_DEVICE ;
362
362
cur -> lowpan_info &= ~INTERFACE_NWK_CONF_MAC_RX_OFF_IDLE ;
363
- mle_class_mode_set (cur -> id , MLE_CLASS_ROUTER );
364
363
mac_data_poll_init (cur );
365
364
arm_nwk_6lowpan_borderrouter_data_free (cur );
366
365
}
@@ -433,28 +432,27 @@ void protocol_6lowpan_release_long_link_address_from_neighcache(protocol_interfa
433
432
}
434
433
#ifdef HAVE_6LOWPAN_ND
435
434
436
- static int8_t mle_set_link_priority (int8_t interface_id , const uint8_t * address , bool priority )
435
+ static int8_t mle_set_link_priority (protocol_interface_info_entry_t * cur , const uint8_t * address , bool priority )
437
436
{
438
437
uint8_t mac64 [8 ];
439
- mle_neigh_table_entry_t * mle_entry ;
440
-
438
+ mac_neighbor_table_entry_t * entry ;
441
439
if (!memcmp (address , ADDR_SHORT_ADR_SUFFIC , 6 )) {
442
- mle_entry = mle_class_get_by_link_address ( interface_id , address + 6 , ADDR_802_15_4_SHORT );
440
+ entry = mac_neighbor_table_address_discover ( cur -> mac_parameters -> mac_neighbor_table , address + 6 , ADDR_802_15_4_SHORT );
443
441
} else {
444
442
445
443
memcpy (mac64 , address , 8 );
446
444
mac64 [0 ] ^= 2 ;
447
- mle_entry = mle_class_get_by_link_address ( interface_id , mac64 , ADDR_802_15_4_LONG );
445
+ entry = mac_neighbor_table_address_discover ( cur -> mac_parameters -> mac_neighbor_table , mac64 , ADDR_802_15_4_LONG );
448
446
}
449
447
450
- if (!mle_entry ) {
448
+ if (!entry ) {
451
449
return -1 ;
452
450
}
453
451
454
452
if (priority ) {
455
- mle_entry -> priorityFlag = 1 ;
453
+ entry -> link_role = PRIORITY_PARENT_NEIGHBOUR ;
456
454
} else {
457
- mle_entry -> priorityFlag = 0 ;
455
+ entry -> link_role = NORMAL_NEIGHBOUR ;
458
456
}
459
457
return 0 ;
460
458
}
@@ -464,11 +462,11 @@ void protocol_6lowpan_neighbor_priority_update(protocol_interface_info_entry_t *
464
462
if (cur -> lowpan_info & INTERFACE_NWK_BOOTSRAP_MLE ) {
465
463
#ifndef NO_MLE
466
464
if (removed_priority ) {
467
- mle_set_link_priority (cur -> id ,removed_priority , false);
465
+ mle_set_link_priority (cur ,removed_priority , false);
468
466
}
469
467
470
468
if (updated_priority ) {
471
- mle_set_link_priority (cur -> id , updated_priority , true);
469
+ mle_set_link_priority (cur , updated_priority , true);
472
470
}
473
471
#endif
474
472
}
@@ -479,29 +477,27 @@ void protocol_6lowpan_neighbor_priority_update(protocol_interface_info_entry_t *
479
477
480
478
uint16_t protocol_6lowpan_neighbor_priority_set (int8_t interface_id , addrtype_t addr_type , const uint8_t * addr_ptr )
481
479
{
482
- mle_neigh_table_entry_t * neigh_table_ptr ;
480
+ protocol_interface_info_entry_t * cur = protocol_stack_interface_info_get_by_id ( interface_id ) ;
483
481
484
- if (!addr_ptr ) {
482
+ if (!cur || ! addr_ptr ) {
485
483
return 0 ;
486
484
}
487
485
488
- neigh_table_ptr = mle_class_get_by_link_address ( interface_id , addr_ptr + PAN_ID_LEN , addr_type );
486
+ mac_neighbor_table_entry_t * entry = mac_neighbor_table_address_discover ( cur -> mac_parameters -> mac_neighbor_table , addr_ptr + PAN_ID_LEN , addr_type );
489
487
490
- if (neigh_table_ptr ) {
491
- etx_storage_t * etx_entry = etx_storage_entry_get (interface_id , neigh_table_ptr -> attribute_index );
488
+ if (entry ) {
489
+ etx_storage_t * etx_entry = etx_storage_entry_get (interface_id , entry -> index );
492
490
// If primary parent has changed clears priority from previous parent
493
- if (! neigh_table_ptr -> priorityFlag ) {
491
+ if (entry -> link_role != PRIORITY_PARENT_NEIGHBOUR ) {
494
492
protocol_6lowpan_neighbor_priority_clear_all (interface_id , PRIORITY_1ST );
495
493
}
496
- neigh_table_ptr -> priorityFlag = 1 ;
497
-
498
- protocol_interface_info_entry_t * cur = protocol_stack_interface_info_get_by_id (interface_id );
499
- if (cur ) {
500
- uint8_t temp [2 ];
501
- common_write_16_bit (neigh_table_ptr -> short_adr , temp );
502
- mac_helper_coordinator_address_set (cur , ADDR_802_15_4_SHORT , temp );
503
- mac_helper_coordinator_address_set (cur , ADDR_802_15_4_LONG , neigh_table_ptr -> mac64 );
504
- }
494
+ entry -> link_role = PRIORITY_PARENT_NEIGHBOUR ;
495
+
496
+
497
+ uint8_t temp [2 ];
498
+ common_write_16_bit (entry -> mac16 , temp );
499
+ mac_helper_coordinator_address_set (cur , ADDR_802_15_4_SHORT , temp );
500
+ mac_helper_coordinator_address_set (cur , ADDR_802_15_4_LONG , entry -> mac64 );
505
501
if (etx_entry ) {
506
502
protocol_stats_update (STATS_ETX_1ST_PARENT , etx_entry -> etx >> 4 );
507
503
}
@@ -513,21 +509,23 @@ uint16_t protocol_6lowpan_neighbor_priority_set(int8_t interface_id, addrtype_t
513
509
514
510
uint16_t protocol_6lowpan_neighbor_second_priority_set (int8_t interface_id , addrtype_t addr_type , const uint8_t * addr_ptr )
515
511
{
516
- mle_neigh_table_entry_t * neigh_table_ptr ;
517
512
518
- if (!addr_ptr ) {
513
+ protocol_interface_info_entry_t * cur = protocol_stack_interface_info_get_by_id (interface_id );
514
+
515
+ if (!cur || !addr_ptr ) {
519
516
return 0 ;
520
517
}
521
518
522
- neigh_table_ptr = mle_class_get_by_link_address ( interface_id , addr_ptr + PAN_ID_LEN , addr_type );
519
+ mac_neighbor_table_entry_t * entry = mac_neighbor_table_address_discover ( cur -> mac_parameters -> mac_neighbor_table , addr_ptr + PAN_ID_LEN , addr_type );
523
520
524
- if (neigh_table_ptr ) {
525
- etx_storage_t * etx_entry = etx_storage_entry_get (interface_id , neigh_table_ptr -> attribute_index );
521
+ if (entry ) {
522
+ etx_storage_t * etx_entry = etx_storage_entry_get (interface_id , entry -> index );
526
523
// If secondary parent has changed clears priority from previous parent
527
- if (neigh_table_ptr -> second_priority_flag == 0 ) {
524
+ if (entry -> link_role != SECONDARY_PARENT_NEIGHBOUR ) {
528
525
protocol_6lowpan_neighbor_priority_clear_all (interface_id , PRIORITY_2ND );
529
526
}
530
- neigh_table_ptr -> second_priority_flag = 1 ;
527
+ entry -> link_role = SECONDARY_PARENT_NEIGHBOUR ;
528
+
531
529
if (etx_entry ) {
532
530
protocol_stats_update (STATS_ETX_2ND_PARENT , etx_entry -> etx >> 4 );
533
531
}
@@ -539,21 +537,22 @@ uint16_t protocol_6lowpan_neighbor_second_priority_set(int8_t interface_id, addr
539
537
540
538
void protocol_6lowpan_neighbor_priority_clear_all (int8_t interface_id , neighbor_priority priority )
541
539
{
542
- mle_neigh_table_list_t * mle_neigh_table ;
540
+ protocol_interface_info_entry_t * cur = protocol_stack_interface_info_get_by_id ( interface_id ) ;
543
541
544
- mle_neigh_table = mle_class_active_list_get (interface_id );
545
- if (!mle_neigh_table ) {
542
+ if (!cur ) {
546
543
return ;
547
544
}
545
+ mac_neighbor_table_list_t * mac_table_list = & cur -> mac_parameters -> mac_neighbor_table -> neighbour_list ;
548
546
549
- ns_list_foreach (mle_neigh_table_entry_t , entry , mle_neigh_table ) {
550
- if (priority == PRIORITY_1ST ) {
551
- entry -> priorityFlag = 0 ;
547
+ ns_list_foreach (mac_neighbor_table_entry_t , entry , mac_table_list ) {
548
+ if (priority == PRIORITY_1ST && entry -> link_role == PRIORITY_PARENT_NEIGHBOUR ) {
549
+ entry -> link_role = NORMAL_NEIGHBOUR ;
552
550
} else {
553
- if (entry -> second_priority_flag ) {
551
+ if (entry -> link_role == SECONDARY_PARENT_NEIGHBOUR ) {
554
552
protocol_stats_update (STATS_ETX_2ND_PARENT , 0 );
553
+ entry -> link_role = NORMAL_NEIGHBOUR ;
555
554
}
556
- entry -> second_priority_flag = 0 ;
555
+
557
556
}
558
557
}
559
558
}
@@ -566,43 +565,33 @@ void protocol_6lowpan_neighbor_priority_clear_all(int8_t interface_id, neighbor_
566
565
int8_t protocol_6lowpan_neighbor_address_state_synch (protocol_interface_info_entry_t * cur , const uint8_t eui64 [8 ], const uint8_t iid [8 ])
567
566
{
568
567
int8_t ret_val = -1 ;
569
- if (cur -> lowpan_info & INTERFACE_NWK_BOOTSRAP_MLE ) {
570
- #ifndef NO_MLE
571
- mle_neigh_table_entry_t * mle_entry = 0 ;
572
- mle_entry = mle_class_get_by_link_address (cur -> id , eui64 , ADDR_802_15_4_LONG );
573
- if (mle_entry ) {
574
- if (memcmp (iid , ADDR_SHORT_ADR_SUFFIC , 6 ) == 0 ) {
575
- iid += 6 ;
576
- //Set Short Address to MLE
577
- mle_entry -> short_adr = common_read_16_bit (iid );
578
- }
579
- if ((mle_entry -> mode & MLE_DEV_MASK ) == MLE_RFD_DEV ) {
580
- if (mle_entry -> connected_device ) {
581
- mle_entry_timeout_refresh (mle_entry );
582
- }
583
- ret_val = 1 ;
584
- } else {
585
- ret_val = 0 ;
568
+
569
+ mac_neighbor_table_entry_t * entry = mac_neighbor_table_address_discover (cur -> mac_parameters -> mac_neighbor_table , eui64 , ADDR_802_15_4_LONG );
570
+ if (entry ) {
571
+ if (memcmp (iid , ADDR_SHORT_ADR_SUFFIC , 6 ) == 0 ) {
572
+ iid += 6 ;
573
+ //Set Short Address to MLE
574
+ entry -> mac16 = common_read_16_bit (iid );
575
+ }
576
+ if (!entry -> ffd_device ) {
577
+ if (entry -> connected_device ) {
578
+ mac_neighbor_table_neighbor_refresh (cur -> mac_parameters -> mac_neighbor_table , entry , entry -> link_lifetime );
586
579
}
580
+ ret_val = 1 ;
581
+ } else {
582
+ ret_val = 0 ;
587
583
}
588
- #endif
589
- } else {
590
- ret_val = 0 ;
591
584
}
592
585
return ret_val ;
593
586
}
594
587
595
588
int8_t protocol_6lowpan_neighbor_remove (protocol_interface_info_entry_t * cur , uint8_t * address_ptr , addrtype_t type )
596
589
{
597
- int8_t ret_val = 0 ;
598
- if (cur -> lowpan_info & INTERFACE_NWK_BOOTSRAP_MLE ) {
599
- #ifndef NO_MLE
600
- mle_class_remove_neighbour (cur -> id , address_ptr , type );
601
- #endif
602
- } else {
603
- //REMOVE Something else
590
+ mac_neighbor_table_entry_t * entry = mac_neighbor_table_address_discover (cur -> mac_parameters -> mac_neighbor_table , address_ptr , type );
591
+ if (entry ) {
592
+ mac_neighbor_table_neighbor_remove (cur -> mac_parameters -> mac_neighbor_table , entry );
604
593
}
605
- return ret_val ;
594
+ return 0 ;
606
595
}
607
596
608
597
void protocol_6lowpan_allocate_mac16 (protocol_interface_info_entry_t * cur )
@@ -747,7 +736,7 @@ uint8_t protocol_6lowpan_beacon_join_priority_tx(int8_t interface_id)
747
736
mle_6lowpan_data_t * mle_6lowpan_data = protocol_6lowpan_mle_data_get ();
748
737
749
738
if (mle_6lowpan_data && mle_6lowpan_data -> nbr_of_neigh_max != 0 ) {
750
- uint16_t mle_neigh_cnt = mle_class_active_neigh_counter (interface_id );
739
+ uint16_t mle_neigh_cnt = mle_class_active_neigh_counter (cur );
751
740
752
741
if (mle_neigh_cnt > mle_6lowpan_data -> nbr_of_neigh_lower_threshold ) {
753
742
uint16_t mle_neigh_limit ;
0 commit comments