Skip to content

Commit 24aa802

Browse files
Juha Heiskanenjuhhei01
authored andcommitted
Integrate Mac neighbour table to Thread and 6Lowpan code
Removed old MLE table and class functionality Integrated new MAC neighbour table and Thread neighbour table functionality. Fixed and simpilify specially link refresh operation at thread. Change-Id: Ie8167651e2c228d0451f66d1cf3c32f558db2fe4
1 parent 37c6342 commit 24aa802

File tree

75 files changed

+1085
-2835
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1085
-2835
lines changed

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

Lines changed: 60 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#include "6LoWPAN/lowpan_adaptation_interface.h"
7474
#include "6LoWPAN/Fragmentation/cipv6_fragmenter.h"
7575
#include "Service_Libs/etx/etx.h"
76+
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
7677

7778

7879
#define TRACE_GROUP_LOWPAN "6lo"
@@ -349,7 +350,6 @@ void protocol_6lowpan_host_init(protocol_interface_info_entry_t *cur, bool sleep
349350
}
350351
//Clear always INTERFACE_NWK_ROUTER_DEVICE, INTERFACE_NWK_CONF_MAC_RX_OFF_IDLE
351352
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);
353353
mac_helper_pib_boolean_set(cur, macRxOnWhenIdle, true);
354354
mac_data_poll_init(cur);
355355
arm_nwk_6lowpan_borderrouter_data_free(cur);
@@ -360,7 +360,6 @@ void protocol_6lowpan_router_init(protocol_interface_info_entry_t *cur)
360360
cur->bootsrap_mode = ARM_NWK_BOOTSRAP_MODE_6LoWPAN_ROUTER;
361361
cur->lowpan_info |= INTERFACE_NWK_ROUTER_DEVICE;
362362
cur->lowpan_info &= ~INTERFACE_NWK_CONF_MAC_RX_OFF_IDLE;
363-
mle_class_mode_set(cur->id, MLE_CLASS_ROUTER);
364363
mac_data_poll_init(cur);
365364
arm_nwk_6lowpan_borderrouter_data_free(cur);
366365
}
@@ -433,28 +432,27 @@ void protocol_6lowpan_release_long_link_address_from_neighcache(protocol_interfa
433432
}
434433
#ifdef HAVE_6LOWPAN_ND
435434

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)
437436
{
438437
uint8_t mac64[8];
439-
mle_neigh_table_entry_t *mle_entry;
440-
438+
mac_neighbor_table_entry_t *entry;
441439
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);
443441
} else {
444442

445443
memcpy(mac64, address, 8);
446444
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);
448446
}
449447

450-
if (!mle_entry) {
448+
if (!entry) {
451449
return -1;
452450
}
453451

454452
if (priority) {
455-
mle_entry->priorityFlag = 1;
453+
entry->link_role = PRIORITY_PARENT_NEIGHBOUR;
456454
} else {
457-
mle_entry->priorityFlag = 0;
455+
entry->link_role = NORMAL_NEIGHBOUR;
458456
}
459457
return 0;
460458
}
@@ -464,11 +462,11 @@ void protocol_6lowpan_neighbor_priority_update(protocol_interface_info_entry_t *
464462
if (cur->lowpan_info & INTERFACE_NWK_BOOTSRAP_MLE) {
465463
#ifndef NO_MLE
466464
if (removed_priority) {
467-
mle_set_link_priority(cur->id,removed_priority, false);
465+
mle_set_link_priority(cur,removed_priority, false);
468466
}
469467

470468
if (updated_priority) {
471-
mle_set_link_priority(cur->id, updated_priority, true);
469+
mle_set_link_priority(cur, updated_priority, true);
472470
}
473471
#endif
474472
}
@@ -479,29 +477,27 @@ void protocol_6lowpan_neighbor_priority_update(protocol_interface_info_entry_t *
479477

480478
uint16_t protocol_6lowpan_neighbor_priority_set(int8_t interface_id, addrtype_t addr_type, const uint8_t *addr_ptr)
481479
{
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);
483481

484-
if (!addr_ptr) {
482+
if (!cur || !addr_ptr) {
485483
return 0;
486484
}
487485

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);
489487

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);
492490
// If primary parent has changed clears priority from previous parent
493-
if (!neigh_table_ptr->priorityFlag) {
491+
if (entry->link_role != PRIORITY_PARENT_NEIGHBOUR) {
494492
protocol_6lowpan_neighbor_priority_clear_all(interface_id, PRIORITY_1ST);
495493
}
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);
505501
if (etx_entry) {
506502
protocol_stats_update(STATS_ETX_1ST_PARENT, etx_entry->etx >> 4);
507503
}
@@ -513,21 +509,23 @@ uint16_t protocol_6lowpan_neighbor_priority_set(int8_t interface_id, addrtype_t
513509

514510
uint16_t protocol_6lowpan_neighbor_second_priority_set(int8_t interface_id, addrtype_t addr_type, const uint8_t *addr_ptr)
515511
{
516-
mle_neigh_table_entry_t *neigh_table_ptr;
517512

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) {
519516
return 0;
520517
}
521518

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);
523520

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);
526523
// 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) {
528525
protocol_6lowpan_neighbor_priority_clear_all(interface_id, PRIORITY_2ND);
529526
}
530-
neigh_table_ptr->second_priority_flag = 1;
527+
entry->link_role = SECONDARY_PARENT_NEIGHBOUR;
528+
531529
if (etx_entry) {
532530
protocol_stats_update(STATS_ETX_2ND_PARENT, etx_entry->etx >> 4);
533531
}
@@ -539,21 +537,22 @@ uint16_t protocol_6lowpan_neighbor_second_priority_set(int8_t interface_id, addr
539537

540538
void protocol_6lowpan_neighbor_priority_clear_all(int8_t interface_id, neighbor_priority priority)
541539
{
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);
543541

544-
mle_neigh_table = mle_class_active_list_get(interface_id);
545-
if (!mle_neigh_table) {
542+
if (!cur) {
546543
return;
547544
}
545+
mac_neighbor_table_list_t *mac_table_list = &cur->mac_parameters->mac_neighbor_table->neighbour_list;
548546

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;
552550
} else {
553-
if (entry->second_priority_flag) {
551+
if (entry->link_role == SECONDARY_PARENT_NEIGHBOUR) {
554552
protocol_stats_update(STATS_ETX_2ND_PARENT, 0);
553+
entry->link_role = NORMAL_NEIGHBOUR;
555554
}
556-
entry->second_priority_flag = 0;
555+
557556
}
558557
}
559558
}
@@ -566,43 +565,33 @@ void protocol_6lowpan_neighbor_priority_clear_all(int8_t interface_id, neighbor_
566565
int8_t protocol_6lowpan_neighbor_address_state_synch(protocol_interface_info_entry_t *cur, const uint8_t eui64[8], const uint8_t iid[8])
567566
{
568567
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);
586579
}
580+
ret_val = 1;
581+
} else {
582+
ret_val = 0;
587583
}
588-
#endif
589-
} else {
590-
ret_val = 0;
591584
}
592585
return ret_val;
593586
}
594587

595588
int8_t protocol_6lowpan_neighbor_remove(protocol_interface_info_entry_t *cur, uint8_t *address_ptr, addrtype_t type)
596589
{
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);
604593
}
605-
return ret_val;
594+
return 0;
606595
}
607596

608597
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)
747736
mle_6lowpan_data_t *mle_6lowpan_data = protocol_6lowpan_mle_data_get();
748737

749738
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);
751740

752741
if (mle_neigh_cnt > mle_6lowpan_data->nbr_of_neigh_lower_threshold) {
753742
uint16_t mle_neigh_limit;

0 commit comments

Comments
 (0)