Skip to content

Commit 13b3b05

Browse files
Juha Heiskanenjuhhei01
authored andcommitted
Thread Neighbor and MLE API update
Thread neighbour table base API generated Mle entry table API removed link margin parameter Integrate new neighbor class and remove duplicate parameters from mle table entry Change-Id: Ieaa002d191786d299b75602ee950f5fa98087a43
1 parent 49ccb9d commit 13b3b05

28 files changed

+524
-108
lines changed

nanostack/platform/arm_hal_aes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*/
3636

3737
#include "ns_types.h"
38-
#include "nsconfig.h"
38+
3939

4040
#ifdef __cplusplus
4141
extern "C" {

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

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -550,15 +550,6 @@ static int protocol_6lowpan_mle_neigh_advertise(protocol_interface_info_entry_t
550550
}
551551
#endif
552552

553-
static uint8_t compute_link_margin(int8_t rssi)
554-
{
555-
if (rssi < -94) {
556-
return 0;
557-
}
558-
559-
return (rssi + 94);
560-
}
561-
562553
static int mle_validate_6lowpan_link_request_message(uint8_t *ptr, uint16_t data_len, mle_tlv_info_t *tlv_info)
563554
{
564555
/**
@@ -759,7 +750,7 @@ static int mle_router_accept_request_build(protocol_interface_info_entry_t *cur,
759750

760751
static void protocol_6lowpan_link_reject_handler(protocol_interface_info_entry_t *cur, uint8_t *ll64)
761752
{
762-
mle_neigh_table_entry_t *entry_temp = mle_class_get_entry_by_ll64(cur->id, 0, ll64, false, NULL);
753+
mle_neigh_table_entry_t *entry_temp = mle_class_get_entry_by_ll64(cur->id, ll64, false, NULL);
763754
tr_debug("MLE link reject");
764755
if (entry_temp) {
765756
mle_class_remove_entry(cur->id, entry_temp);
@@ -1052,16 +1043,13 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
10521043
mle_tlv_info_t mle_tlv_info;
10531044
mle_tlv_info_t mle_challenge;
10541045
mle_neigh_table_entry_t *entry_temp;
1055-
uint8_t linkMargin;
10561046
uint8_t incoming_idr;
10571047
uint16_t responseId, own_mac16;
10581048
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
10591049
if (!cur) {
10601050
return;
10611051
}
10621052

1063-
//Calculate link margin
1064-
linkMargin = compute_link_margin(mle_msg->dbm);
10651053

10661054
own_mac16 = mac_helper_mac16_address_get(cur);
10671055

@@ -1084,7 +1072,7 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
10841072
mle_6lowpan_data->link_req_token_bucket--;
10851073
} else {
10861074
//Update only old information based on link request
1087-
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, false, NULL);
1075+
entry_temp = mle_class_get_entry_by_ll64(interface_id, mle_msg->packet_src_address, false, NULL);
10881076
if (entry_temp) {
10891077
mle_neigh_time_and_mode_update(entry_temp,mle_msg->data_ptr, mle_msg->data_length);
10901078
mle_neigh_entry_update_by_mle_tlv_list(interface_id, entry_temp, mle_msg->data_ptr, mle_msg->data_length, cur->mac, own_mac16);
@@ -1121,12 +1109,12 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
11211109

11221110
tr_debug("Accept & Request");
11231111

1124-
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, false, NULL);
1112+
entry_temp = mle_class_get_entry_by_ll64(interface_id, mle_msg->packet_src_address, false, NULL);
11251113

11261114
if (!entry_temp) {
11271115
// If there is space for neighbors try to allocate new entry
11281116
if (mle_6lowpan_neighbor_limit_check(interface_id, mle_msg, true)) {
1129-
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, true, NULL);
1117+
entry_temp = mle_class_get_entry_by_ll64(interface_id, mle_msg->packet_src_address, true, NULL);
11301118
}
11311119
}
11321120

@@ -1186,7 +1174,7 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
11861174
mode = *t_ptr;
11871175
}
11881176

1189-
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, false, NULL);
1177+
entry_temp = mle_class_get_entry_by_ll64(interface_id, mle_msg->packet_src_address, false, NULL);
11901178
if (!entry_temp) {
11911179
if ((mode & MLE_DEV_MASK) == MLE_FFD_DEV) {
11921180
// If there is space for neighbors synchronizes to new router
@@ -2793,6 +2781,7 @@ static void lowpan_comm_status_indication_cb(int8_t if_id, const mlme_comm_statu
27932781
break;
27942782
case MLME_DATA_POLL_NOTIFICATION:
27952783
mle_refresh_entry_timeout(if_id, status->SrcAddr, (addrtype_t)status->SrcAddrMode, false);
2784+
//TIMEOUT REFRESH missing
27962785
break;
27972786
default:
27982787
break;
@@ -2804,7 +2793,7 @@ bool lowpan_neighbour_data_clean(int8_t interface_id, const uint8_t *link_local_
28042793
{
28052794
bool return_value = false;
28062795
#ifndef NO_MLE
2807-
mle_neigh_table_entry_t * neigh_entry = mle_class_get_entry_by_ll64(interface_id, 0, link_local_address, false, NULL);
2796+
mle_neigh_table_entry_t * neigh_entry = mle_class_get_entry_by_ll64(interface_id, link_local_address, false, NULL);
28082797
if (neigh_entry) {
28092798
//Remove entry
28102799
if (neigh_entry->priorityFlag) {

source/6LoWPAN/MAC/mac_data_poll.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,20 +295,21 @@ void mac_mlme_poll_confirm(protocol_interface_info_entry_t *cur, const mlme_poll
295295
}
296296

297297
rf_ptr->pollActive = false;
298+
mle_neigh_table_entry_t *entry = NULL;
298299

299300
switch (confirm->status) {
300301
case MLME_SUCCESS:
301302
//tr_debug("Poll Confirm: Data with Data");
302303
rf_ptr->nwk_parent_poll_fail = 0;
303304
//Trig new Data Poll immediately
304-
mle_refresh_entry_timeout(cur->id, rf_ptr->poll_req.CoordAddress, (addrtype_t)rf_ptr->poll_req.CoordAddrMode, true);
305+
entry = mle_refresh_entry_timeout(cur->id, rf_ptr->poll_req.CoordAddress, (addrtype_t)rf_ptr->poll_req.CoordAddrMode, true);
305306
poll_time = 1;
306307
break;
307308

308309
case MLME_NO_DATA:
309310
//Start next case timer
310311
rf_ptr->nwk_parent_poll_fail = 0;
311-
mle_refresh_entry_timeout(cur->id, rf_ptr->poll_req.CoordAddress, (addrtype_t)rf_ptr->poll_req.CoordAddrMode, true);
312+
entry = mle_refresh_entry_timeout(cur->id, rf_ptr->poll_req.CoordAddress, (addrtype_t)rf_ptr->poll_req.CoordAddrMode, true);
312313
//tr_debug("Poll Confirm: No Data");
313314

314315
if (rf_ptr->protocol_poll == 0) {
@@ -333,6 +334,9 @@ void mac_mlme_poll_confirm(protocol_interface_info_entry_t *cur, const mlme_poll
333334
}
334335
break;
335336
}
337+
if (thread_info(cur) && entry) {
338+
thread_neighbor_commucation_update(cur, entry->attribute_index);
339+
}
336340

337341
mac_poll_timer_trig(poll_time, cur);
338342

source/6LoWPAN/MAC/mac_pairwise_key.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,11 @@ int mac_pairwise_key_add(int8_t interface_id, uint32_t valid_life_time, const ui
266266
}
267267

268268
//Allocate mle entry
269-
mle_neigh_table_entry_t *mle_entry = mle_class_get_entry_by_mac64(interface_id, 0, eui64, true, &new_entry_created);
269+
mle_neigh_table_entry_t *mle_entry = mle_class_get_entry_by_mac64(interface_id, eui64, true, &new_entry_created);
270270
if (!mle_entry) {
271271
return -1;
272272
}
273+
273274
mle_entry->thread_commission = true;
274275
mle_entry->short_adr = 0xffff;
275276
mle_entry->ttl = 20;
@@ -311,7 +312,7 @@ int mac_pairwise_key_del(int8_t interface_id, const uint8_t eui64[static 8])
311312
return -1;
312313
}
313314
//Get from mle
314-
mle_neigh_table_entry_t *mle_entry = mle_class_get_entry_by_mac64(interface_id, 0, eui64, true, NULL);
315+
mle_neigh_table_entry_t *mle_entry = mle_class_get_entry_by_mac64(interface_id, eui64, true, NULL);
315316
if (!mle_entry) {
316317
return -1;
317318
}

source/6LoWPAN/Thread/thread_bootstrap.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "6LoWPAN/Thread/thread_router_bootstrap.h"
6060
#include "6LoWPAN/Thread/thread_management_internal.h"
6161
#include "6LoWPAN/Thread/thread_management_server.h"
62+
#include "6LoWPAN/Thread/thread_neighbor_class.h"
6263
#include "6LoWPAN/Thread/thread_network_data_lib.h"
6364
#include "6LoWPAN/Thread/thread_network_synch.h"
6465
#include "6LoWPAN/Thread/thread_joiner_application.h"
@@ -153,6 +154,12 @@ int8_t thread_mle_class_init(int8_t interface_id)
153154
return -1;
154155
}
155156

157+
thread_neighbor_class_delete(&cur->thread_info->neighbor_class);
158+
159+
if (!thread_neighbor_class_create(&cur->thread_info->neighbor_class, buffer.device_decription_table_size - 1)) {
160+
return -1;
161+
}
162+
156163
if (mle_class_init(interface_id, buffer.device_decription_table_size - 1, &thread_neighbor_remove, &thread_host_bootstrap_child_update, &thread_interface_is_active) != 0) {
157164
return -1;
158165
}

source/6LoWPAN/Thread/thread_common.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#include "6LoWPAN/Thread/thread_address_registration_client.h"
6565
#include "6LoWPAN/Thread/thread_resolution_client.h"
6666
#include <6LoWPAN/Thread/thread_extension_bootstrap.h>
67+
#include "6LoWPAN/Thread/thread_neighbor_class.h"
6768
#include "MLE/mle.h"
6869
#include "Service_Libs/mle_service/mle_service_security.h"
6970
#include "Service_Libs/blacklist/blacklist.h"
@@ -1121,14 +1122,20 @@ uint8_t thread_beacon_indication(uint8_t *ptr, uint8_t len, protocol_interface_i
11211122

11221123
static uint8_t *thread_linkquality_write(int8_t interface_id, uint8_t *buffer)
11231124
{
1125+
protocol_interface_info_entry_t *interface_ptr = protocol_stack_interface_info_get_by_id(interface_id);
1126+
if (!interface_ptr && !interface_ptr->thread_info) {
1127+
return buffer;
1128+
}
1129+
11241130
uint8_t lqi1 = 0, lqi2 = 0, lqi3 = 0;
11251131
thread_link_quality_e thread_link_quality;
11261132
mle_neigh_table_list_t *neigh_list = mle_class_active_list_get(interface_id);
11271133

11281134
ns_list_foreach(mle_neigh_table_entry_t, cur, neigh_list) {
11291135
if (thread_is_router_addr(cur->short_adr)) {
11301136
// Only count routers to link quality
1131-
thread_link_quality = thread_link_margin_to_quality(cur->link_margin);
1137+
uint16_t link_margin = thread_neighbor_class_linkmargin_get(&interface_ptr->thread_info->neighbor_class, cur->attribute_index);
1138+
thread_link_quality = thread_link_margin_to_quality(link_margin);
11321139
switch (thread_link_quality) {
11331140
case QUALITY_20dB:
11341141
lqi3++;
@@ -1865,6 +1872,7 @@ void thread_reset_neighbour_info(protocol_interface_info_entry_t *cur, mle_neigh
18651872
thread_router_bootstrap_reset_child_info(cur, neighbour);
18661873
protocol_6lowpan_release_long_link_address_from_neighcache(cur, neighbour->mac64);
18671874
mac_helper_devicetable_remove(cur->mac_api, neighbour->attribute_index);
1875+
thread_neighbor_class_table_remove(&cur->thread_info->neighbor_class, neighbour->attribute_index);
18681876
}
18691877

18701878
uint8_t thread_get_router_count_from_route_tlv(mle_tlv_info_t *routeTlv)
@@ -1940,5 +1948,10 @@ void thread_old_partition_data_purge(protocol_interface_info_entry_t *cur)
19401948

19411949
}
19421950

1951+
void thread_neighbor_commucation_update(protocol_interface_info_entry_t *cur, uint8_t neighbor_attribute_index)
1952+
{
1953+
thread_neighbor_last_communincation_time_update(&cur->thread_info->neighbor_class, neighbor_attribute_index);
1954+
}
1955+
19431956
#endif
19441957

source/6LoWPAN/Thread/thread_common.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,20 @@ typedef enum {
9292
THREAD_COMMISSIONER_REGISTERED
9393
} thread_commissioner_register_status_e;
9494

95+
typedef struct thread_neigh_table_entry_s {
96+
uint8_t mlEid[8];
97+
uint32_t last_contact_time; /*!< monotonic time - hard to define "contact"; used for Thread Leasequery replies */
98+
uint16_t link_margin;
99+
} thread_neigh_table_entry_t ;
100+
101+
/**
102+
* Neighbor info data base
103+
*/
104+
typedef struct thread_neighbor_class_s {
105+
thread_neigh_table_entry_t *neigh_info_list; /*!< Allocated Neighbour info array*/
106+
uint8_t list_size; /*!< List size*/
107+
} thread_neighbor_class_t;
108+
95109
typedef struct thread_mcast_child {
96110
uint8_t mac64[8];
97111
ns_list_link_t link;
@@ -261,6 +275,7 @@ typedef struct thread_previous_partition_info_s {
261275

262276
typedef struct thread_info_s {
263277
thread_routing_info_t routing;
278+
thread_neighbor_class_t neighbor_class;
264279
thread_master_secret_material_t masterSecretMaterial;
265280
thread_network_data_cache_entry_t networkDataStorage;
266281
thread_network_local_data_cache_entry_t localServerDataBase;
@@ -417,6 +432,7 @@ void thread_calculate_key_guard_timer(protocol_interface_info_entry_t *cur, link
417432
void thread_set_link_local_address(protocol_interface_info_entry_t *cur);
418433
void thread_mcast_group_change(struct protocol_interface_info_entry *interface, struct if_group_entry *group, bool group_added);
419434
void thread_old_partition_data_purge(protocol_interface_info_entry_t *cur);
435+
void thread_neighbor_commucation_update(protocol_interface_info_entry_t *cur, uint8_t neighbor_attribute_index);
420436

421437
#else // HAVE_THREAD
422438

@@ -438,6 +454,7 @@ NS_DUMMY_DEFINITIONS_OK
438454
#define thread_link_reject_send(interface, ll64) 0
439455
#define thread_addr_is_mesh_local_16(addr, cur) false
440456
#define thread_mcast_group_change(interface, group, group_added) ((void)0)
457+
#define thread_neighbor_commucation_update(cur, neighbor_attribute_index) ((void)0)
441458
#endif // HAVE_THREAD
442459

443460
#endif /* LOWPAN_THREAD_H_ */

source/6LoWPAN/Thread/thread_extension.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "6LoWPAN/Thread/thread_discovery.h"
5353
#include "6LoWPAN/Thread/thread_extension_bootstrap.h"
5454
#include "6LoWPAN/Thread/thread_extension_constants.h"
55+
#include "6LoWPAN/Thread/thread_neighbor_class.h"
5556
#include "6LoWPAN/MAC/mac_helper.h"
5657
#include "NWK_INTERFACE/Include/protocol.h"
5758
#include "Common_Protocols/ipv6.h"
@@ -381,7 +382,11 @@ void thread_extension_address_registration(struct protocol_interface_info_entry
381382
return;
382383
}
383384

384-
ml_eid = entry->mlEid;
385+
ml_eid = thread_neighbor_class_get_mleid(&interface->thread_info->neighbor_class, entry->attribute_index);
386+
if (!ml_eid) {
387+
tr_error("No Thread neighbor.");
388+
return;
389+
}
385390
} else {
386391
link_configuration_s *link_config = thread_joiner_application_get_config(interface->id);
387392

source/6LoWPAN/Thread/thread_host_bootstrap.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "6LoWPAN/Thread/thread_management_client.h"
6464
#include "6LoWPAN/Thread/thread_network_data_lib.h"
6565
#include "6LoWPAN/Thread/thread_tmfcop_lib.h"
66+
#include "6LoWPAN/Thread/thread_neighbor_class.h"
6667
#include "thread_management_if.h"
6768
#include "Common_Protocols/ipv6.h"
6869
#include "MPL/mpl.h"
@@ -157,10 +158,13 @@ static bool thread_parent_discover_timeout_cb(int8_t interface_id, uint16_t msgI
157158
memcpy(&ll64[8], parent->mac64 , 8);
158159
ll64[8] ^= 2;
159160

160-
entry_temp = mle_class_get_entry_by_ll64(interface_id, parent->linkMarginToParent,ll64, true, &new_entry_created);
161+
entry_temp = mle_class_get_entry_by_ll64(interface_id,ll64, true, &new_entry_created);
161162
if (entry_temp == NULL) {
162163
return false;
163164
}
165+
thread_neighbor_class_update_link(&cur->thread_info->neighbor_class, entry_temp->attribute_index, parent->linkMarginToParent, new_entry_created);
166+
thread_neighbor_last_communincation_time_update(&cur->thread_info->neighbor_class, entry_temp->attribute_index);
167+
164168
entry_temp->short_adr = parent->shortAddress;
165169
entry_temp->priorityFlag = true;
166170

@@ -325,12 +329,14 @@ static int thread_end_device_synch_response_validate(protocol_interface_info_ent
325329
}
326330

327331
//Update parent link information
328-
entry_temp = mle_class_get_entry_by_ll64(cur->id, linkMargin, src_address, true, &new_entry_created);
332+
entry_temp = mle_class_get_entry_by_ll64(cur->id, src_address, true, &new_entry_created);
329333

330334
if (!entry_temp) {
331335
tr_debug("Neighbor allocate fail");
332336
return -2;
333337
}
338+
thread_neighbor_class_update_link(&cur->thread_info->neighbor_class, entry_temp->attribute_index, linkMargin, new_entry_created);
339+
thread_neighbor_last_communincation_time_update(&cur->thread_info->neighbor_class, entry_temp->attribute_index);
334340
/*
335341
336342
*/
@@ -787,11 +793,13 @@ static void thread_mle_child_request_receive_cb(int8_t interface_id, mle_message
787793
thread_merge_prepare(cur);
788794

789795
// Create entry for new parent
790-
entry_temp = mle_class_get_entry_by_ll64(cur->id, thread_compute_link_margin(mle_msg->dbm), mle_msg->packet_src_address, true, &new_entry_created);
796+
entry_temp = mle_class_get_entry_by_ll64(cur->id, mle_msg->packet_src_address, true, &new_entry_created);
791797
if (entry_temp == NULL) {
792798
// todo: what to do here?
793799
return;
794800
}
801+
thread_neighbor_class_update_link(&cur->thread_info->neighbor_class, entry_temp->attribute_index, thread_compute_link_margin(mle_msg->dbm), new_entry_created);
802+
thread_neighbor_last_communincation_time_update(&cur->thread_info->neighbor_class, entry_temp->attribute_index);
795803

796804
//Parse mandatory TLV's
797805
if (!thread_leader_data_parse(mle_msg->data_ptr, mle_msg->data_length, &leaderData)) {
@@ -948,9 +956,13 @@ void thread_endevice_synch_start(protocol_interface_info_entry_t *cur)
948956
bool new_entry_created;
949957

950958
// Add the parent to the MLE neighbor table
951-
entry_temp = mle_class_get_entry_by_mac64(cur->id, 64, cur->thread_info->thread_endnode_parent->mac64, true, &new_entry_created);
959+
entry_temp = mle_class_get_entry_by_mac64(cur->id, cur->thread_info->thread_endnode_parent->mac64, true, &new_entry_created);
952960

953961
if (entry_temp) {
962+
//Add link margin 64
963+
thread_neighbor_class_update_link(&cur->thread_info->neighbor_class, entry_temp->attribute_index,64, new_entry_created);
964+
thread_neighbor_last_communincation_time_update(&cur->thread_info->neighbor_class, entry_temp->attribute_index);
965+
954966
entry_temp->short_adr = cur->thread_info->thread_endnode_parent->shortAddress;
955967
entry_temp->handshakeReady = 1;
956968

@@ -1019,7 +1031,7 @@ static bool thread_child_id_req_timeout(int8_t interface_id, uint16_t msgId, boo
10191031
memcpy(&ll64[8], scanned_parent->mac64 , 8);
10201032
ll64[8] ^= 2;
10211033

1022-
entry_temp = mle_class_get_entry_by_ll64(cur->id, scanned_parent->linkMarginToParent, ll64, false, NULL);
1034+
entry_temp = mle_class_get_entry_by_ll64(cur->id, ll64, false, NULL);
10231035
if (entry_temp) {
10241036
mle_class_remove_entry(cur->id, entry_temp);
10251037
}

source/6LoWPAN/Thread/thread_management_if.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ void thread_comm_status_indication_cb(int8_t if_id, const mlme_comm_status_t* st
797797
if (!cur) {
798798
return;
799799
}
800+
mle_neigh_table_entry_t *entry;
800801

801802
switch (status->status) {
802803

@@ -809,7 +810,10 @@ void thread_comm_status_indication_cb(int8_t if_id, const mlme_comm_status_t* st
809810
break;
810811

811812
case MLME_DATA_POLL_NOTIFICATION:
812-
mle_refresh_entry_timeout(if_id, status->SrcAddr, (addrtype_t)status->SrcAddrMode, false);
813+
entry = mle_refresh_entry_timeout(if_id, status->SrcAddr, (addrtype_t)status->SrcAddrMode, false);
814+
if (entry) {
815+
thread_neighbor_commucation_update(cur, entry->attribute_index);
816+
}
813817
break;
814818
default:
815819
break;

0 commit comments

Comments
 (0)