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

Commit 1fc81fc

Browse files
author
Arto Kinnunen
authored
Thread device learns weighting from advertisement (ARMmbed#1696)
- Save weighting value from received advertisement. - Check weighting value together with partition id - Update network data version saving
1 parent 7c7568d commit 1fc81fc

File tree

9 files changed

+59
-58
lines changed

9 files changed

+59
-58
lines changed

source/6LoWPAN/Thread/thread_bootstrap.c

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -245,45 +245,31 @@ bool thread_check_is_this_my_parent(protocol_interface_info_entry_t *cur, mle_ne
245245
bool thread_bootstrap_request_network_data(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData, uint16_t short_address)
246246
{
247247
bool requestNetworkdata = false;
248-
thread_leader_data_t *leadeInfo = thread_info(cur)->thread_leader_data;
248+
thread_leader_data_t *leaderInfo = thread_info(cur)->thread_leader_data;
249249

250250
if (thread_info(cur)->thread_endnode_parent->shortAddress != short_address) {
251251
return false;
252252
}
253253

254-
if (thread_info(cur)->thread_leader_data->partitionId != leaderData->partitionId) {
254+
if (!thread_partition_match(cur, leaderData)) {
255255
tr_debug("Learn new Network Data");
256256
requestNetworkdata = true;
257-
thread_info(cur)->thread_leader_data->dataVersion = leaderData->dataVersion - 1;
258-
thread_info(cur)->thread_leader_data->stableDataVersion = leaderData->stableDataVersion - 1;
257+
thread_partition_info_update(cur, leaderData);
259258
}
260-
else if (common_serial_number_greater_8(leaderData->dataVersion, leadeInfo->dataVersion)) {
259+
else if (common_serial_number_greater_8(leaderData->dataVersion, leaderInfo->dataVersion)) {
261260
requestNetworkdata = true;
262261

263-
} else if (common_serial_number_greater_8(leaderData->stableDataVersion, leadeInfo->stableDataVersion)) {
262+
} else if (common_serial_number_greater_8(leaderData->stableDataVersion, leaderInfo->stableDataVersion)) {
264263
requestNetworkdata = true;
265264

266265
}
267266

268-
// Version number is updated when new network data is learned to avoid synchronization problems
269-
thread_info(cur)->thread_leader_data->leaderRouterId = leaderData->leaderRouterId;
270-
thread_info(cur)->thread_leader_data->partitionId = leaderData->partitionId;
271267
if (requestNetworkdata) {
272268
thread_bootstrap_parent_network_data_request(cur, true);
273269
}
274270
return true;
275271
}
276272

277-
bool thread_instance_id_matches(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData)
278-
{
279-
if (thread_info(cur)->thread_leader_data) {
280-
if (thread_info(cur)->thread_leader_data->partitionId == leaderData->partitionId) {
281-
return true;
282-
}
283-
}
284-
return false;
285-
}
286-
287273
static int thread_router_check_previous_partition_info(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData, mle_tlv_info_t *routeTlv)
288274
{
289275
if (!routeTlv || !routeTlv->dataPtr || !routeTlv->tlvLen || !leaderData) {
@@ -386,8 +372,7 @@ int thread_leader_data_validation(protocol_interface_info_entry_t *cur, thread_l
386372
if (!thread_info(cur)->thread_leader_data) {
387373
return -1;
388374
}
389-
if ((thread_info(cur)->thread_leader_data->partitionId != leaderData->partitionId) ||
390-
(thread_info(cur)->thread_leader_data->weighting != leaderData->weighting)) {
375+
if (!thread_partition_match(cur, leaderData)) {
391376
uint8_t routers_in_route_tlv = thread_get_router_count_from_route_tlv(routeTlv);
392377
//partition checks
393378
return thread_bootstrap_partition_process(cur,routers_in_route_tlv,leaderData, routeTlv);

source/6LoWPAN/Thread/thread_bootstrap.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ int thread_parent_discover_start(int8_t interface_id, uint8_t *mac64 );
126126

127127
bool thread_device_synch_timeout(int8_t interface_id, uint16_t msgId, bool usedAllRetries);
128128
bool thread_link_request_timeout(int8_t interface_id, uint16_t msgId, bool usedAllRetries);
129-
bool thread_instance_id_matches(struct protocol_interface_info_entry *cur, struct thread_leader_data_s *leaderData);
130129
int thread_leader_data_validation(struct protocol_interface_info_entry *cur, struct thread_leader_data_s *leaderData, struct mle_tlv_info_s *routeTlv);
131130
uint8_t thread_calculate_link_margin(int8_t dbm, uint8_t compLinkMarginFromParent);
132131
uint8_t thread_compute_link_margin(int8_t rssi);

source/6LoWPAN/Thread/thread_common.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1922,7 +1922,7 @@ void thread_mcast_group_change(struct protocol_interface_info_entry *interface,
19221922
}
19231923
}
19241924

1925-
void thread_old_partition_data_purge(protocol_interface_info_entry_t *cur)
1925+
void thread_partition_data_purge(protocol_interface_info_entry_t *cur)
19261926
{
19271927
/* Partition has been changed. Wipe out data related to old partition */
19281928
thread_management_client_pending_coap_request_kill(cur->id);
@@ -1935,5 +1935,28 @@ void thread_old_partition_data_purge(protocol_interface_info_entry_t *cur)
19351935

19361936
}
19371937

1938+
bool thread_partition_match(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData)
1939+
{
1940+
if (thread_info(cur)->thread_leader_data) {
1941+
if ((thread_info(cur)->thread_leader_data->partitionId == leaderData->partitionId) &&
1942+
(thread_info(cur)->thread_leader_data->weighting == leaderData->weighting)) {
1943+
return true;
1944+
}
1945+
}
1946+
return false;
1947+
}
1948+
1949+
void thread_partition_info_update(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData)
1950+
{
1951+
/* Force network data update later when processing network data TLV */
1952+
thread_info(cur)->thread_leader_data->dataVersion = leaderData->dataVersion - 1;
1953+
thread_info(cur)->thread_leader_data->stableDataVersion = leaderData->stableDataVersion - 1;
1954+
thread_info(cur)->thread_leader_data->leaderRouterId = leaderData->leaderRouterId;
1955+
thread_info(cur)->thread_leader_data->partitionId = leaderData->partitionId;
1956+
thread_info(cur)->thread_leader_data->weighting = leaderData->weighting;
1957+
/* New network data learned, get rid of old partition data */
1958+
thread_partition_data_purge(cur);
1959+
}
1960+
19381961
#endif
19391962

source/6LoWPAN/Thread/thread_common.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,9 @@ uint8_t thread_pending_timestamp_tlv_size(protocol_interface_info_entry_t *cur);
416416
void thread_calculate_key_guard_timer(protocol_interface_info_entry_t *cur, link_configuration_s *linkConfiguration, bool is_init);
417417
void thread_set_link_local_address(protocol_interface_info_entry_t *cur);
418418
void thread_mcast_group_change(struct protocol_interface_info_entry *interface, struct if_group_entry *group, bool group_added);
419-
void thread_old_partition_data_purge(protocol_interface_info_entry_t *cur);
419+
void thread_partition_data_purge(protocol_interface_info_entry_t *cur);
420+
bool thread_partition_match(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData);
421+
void thread_partition_info_update(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData);
420422

421423
#else // HAVE_THREAD
422424

source/6LoWPAN/Thread/thread_host_bootstrap.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static void thread_merge_prepare(protocol_interface_info_entry_t *cur)
122122
thread_clean_old_16_bit_address_based_addresses(cur);
123123
mpl_clear_realm_scope_seeds(cur);
124124
ipv6_route_table_remove_info(cur->id, ROUTE_THREAD_PROXIED_HOST, NULL);
125-
thread_old_partition_data_purge(cur);
125+
thread_partition_data_purge(cur);
126126
thread_network_data_clean(cur);
127127
cur->nwk_mode = ARM_NWK_GP_IP_MODE;
128128
}
@@ -538,8 +538,7 @@ void thread_mle_parent_discover_receive_cb(int8_t interface_id, mle_message_t *m
538538
if (thread_info(cur)->thread_attached_state == THREAD_STATE_REATTACH || thread_info(cur)->thread_attached_state == THREAD_STATE_REATTACH_RETRY) {
539539
tr_debug("Reattach");
540540
if (thread_info(cur)->thread_leader_data) {
541-
if ((thread_info(cur)->thread_leader_data->partitionId != leaderData.partitionId) ||
542-
(thread_info(cur)->thread_leader_data->weighting != leaderData.weighting)) {
541+
if (!thread_partition_match(cur, &leaderData)) {
543542
//accept only same ID at reattach phase
544543
return;
545544
}
@@ -557,8 +556,7 @@ void thread_mle_parent_discover_receive_cb(int8_t interface_id, mle_message_t *m
557556
thread_info(cur)->thread_attached_state == THREAD_STATE_CONNECTED ||
558557
thread_info(cur)->thread_attached_state == THREAD_STATE_CONNECTED_ROUTER) {
559558
if (thread_info(cur)->thread_leader_data) {
560-
if ((thread_info(cur)->thread_leader_data->partitionId == leaderData.partitionId) &&
561-
(thread_info(cur)->thread_leader_data->weighting == leaderData.weighting)) {
559+
if (thread_partition_match(cur, &leaderData)) {
562560
//accept only different ID at anyattach phase
563561
tr_debug("Drop old partition");
564562
return;
@@ -1017,7 +1015,8 @@ static bool thread_child_id_req_timeout(int8_t interface_id, uint16_t msgId, boo
10171015
tr_debug("Back to old partition");
10181016

10191017
/* If scanned parent is from other partition, delete from MLE table */
1020-
if (scanned_parent->leader_data.partitionId != thread_info(cur)->thread_leader_data->partitionId) {
1018+
if ((scanned_parent->leader_data.partitionId != thread_info(cur)->thread_leader_data->partitionId) ||
1019+
(scanned_parent->leader_data.weighting != thread_info(cur)->thread_leader_data->weighting)) {
10211020
memcpy(ll64, ADDR_LINK_LOCAL_PREFIX , 8);
10221021
memcpy(&ll64[8], scanned_parent->mac64 , 8);
10231022
ll64[8] ^= 2;

source/6LoWPAN/Thread/thread_leader_service.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ static void thread_leader_service_interface_setup_activate(protocol_interface_in
13461346
thread_leader_service_private_routemask_init(private);
13471347
//SET Router ID
13481348
thread_leader_allocate_router_id_by_allocated_id(private, routerId, cur->mac);
1349-
thread_old_partition_data_purge(cur);
1349+
thread_partition_data_purge(cur);
13501350
// remove any existing rloc mapping in nvm
13511351
thread_nvm_store_mleid_rloc_map_remove();
13521352
cur->lowpan_address_mode = NET_6LOWPAN_GP16_ADDRESS;

source/6LoWPAN/Thread/thread_mle_message_handler.c

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,11 @@ static void thread_save_leader_data(protocol_interface_info_entry_t *cur, thread
159159
requestNetworkdata = true;
160160
}
161161

162-
if (thread_info(cur)->thread_leader_data->partitionId != leaderData->partitionId) {
162+
if (!thread_partition_match(cur, leaderData)) {
163163
requestNetworkdata = true;
164-
thread_info(cur)->thread_leader_data->stableDataVersion = leaderData->stableDataVersion - 1;
165-
thread_info(cur)->thread_leader_data->dataVersion = leaderData->dataVersion - 1;
164+
thread_partition_info_update(cur, leaderData);
166165
}
167166

168-
thread_info(cur)->thread_leader_data->partitionId = leaderData->partitionId;
169-
thread_info(cur)->thread_leader_data->leaderRouterId = leaderData->leaderRouterId;
170-
thread_info(cur)->thread_leader_data->weighting = leaderData->weighting;
171-
172167
if (requestNetworkdata) {
173168
thread_bootstrap_parent_network_data_request(cur, false);
174169
} else {
@@ -304,11 +299,6 @@ static void thread_update_mle_entry(protocol_interface_info_entry_t *cur, mle_me
304299

305300
static bool thread_parse_advertisement_from_parent(protocol_interface_info_entry_t *cur, thread_leader_data_t *leader_data, uint16_t short_address)
306301
{
307-
if ((thread_info(cur)->thread_leader_data->partitionId != leader_data->partitionId) ||
308-
(thread_info(cur)->thread_leader_data->weighting != leader_data->weighting)) {
309-
//parent changed partition/weight - reset own routing information
310-
thread_old_partition_data_purge(cur);
311-
}
312302
//check if network data needs to be requested
313303
if (!thread_bootstrap_request_network_data(cur, leader_data, short_address)) {
314304
tr_debug("Parent short address changed - re-attach");
@@ -347,7 +337,7 @@ static void thread_parse_advertisement(protocol_interface_info_entry_t *cur, mle
347337
// Check if this is from my parent
348338
my_parent = thread_check_is_this_my_parent(cur, entry_temp);
349339

350-
adv_from_my_partition = thread_instance_id_matches(cur, &leaderData);
340+
adv_from_my_partition = thread_partition_match(cur, &leaderData);
351341

352342
if ((security_headers->KeyIdMode == MAC_KEY_ID_MODE_SRC4_IDX) && adv_from_my_partition) {
353343
thread_management_key_synch_req(cur->id, common_read_32_bit(security_headers->Keysource));
@@ -374,7 +364,7 @@ static void thread_parse_advertisement(protocol_interface_info_entry_t *cur, mle
374364
/* REED and FED */
375365
if (!thread_attach_active_router(cur)) {
376366
/* Check if advertisement is from same partition */
377-
if (thread_info(cur)->thread_leader_data->weighting == leaderData.weighting && thread_info(cur)->thread_leader_data->partitionId == leaderData.partitionId ) {
367+
if (thread_partition_match(cur, &leaderData)) {
378368
if (!entry_temp && thread_bootstrap_link_create_check(cur, shortAddress) && thread_bootstrap_link_create_allowed(cur, shortAddress, mle_msg->packet_src_address)) {
379369
// Create link to new neighbor no other processing allowed
380370
thread_link_request_start(cur, mle_msg->packet_src_address);
@@ -404,8 +394,7 @@ static void thread_parse_advertisement(protocol_interface_info_entry_t *cur, mle
404394
}
405395

406396
// Process route TLV
407-
if ((entry_temp && routeTlv.dataPtr && routeTlv.tlvLen) &&
408-
(thread_info(cur)->thread_leader_data->partitionId == leaderData.partitionId)){
397+
if ((entry_temp && routeTlv.dataPtr && routeTlv.tlvLen) && thread_partition_match(cur, &leaderData)){
409398
tr_debug("Update Route TLV %x", entry_temp->short_adr);
410399
thread_router_bootstrap_route_tlv_push(cur, routeTlv.dataPtr, routeTlv.tlvLen , linkMargin, entry_temp);
411400
}
@@ -570,7 +559,7 @@ static void thread_parse_data_response(protocol_interface_info_entry_t *cur, mle
570559
return;
571560
}
572561
} else {
573-
if (thread_info(cur)->thread_leader_data->partitionId != leaderData.partitionId) {
562+
if (!thread_partition_match(cur, &leaderData)) {
574563
// if receiving data response from different partition it is dropped
575564
return;
576565
}
@@ -583,10 +572,8 @@ static void thread_parse_data_response(protocol_interface_info_entry_t *cur, mle
583572
}
584573
}
585574

586-
if (thread_info(cur)->thread_leader_data->partitionId != leaderData.partitionId) {
587-
thread_info(cur)->thread_leader_data->leaderRouterId = leaderData.leaderRouterId;
588-
thread_info(cur)->thread_leader_data->partitionId = leaderData.partitionId;
589-
thread_old_partition_data_purge(cur);
575+
if (!thread_partition_match(cur, &leaderData)) {
576+
thread_partition_info_update(cur, &leaderData);
590577
accept_new_data = true;
591578
}
592579

@@ -722,10 +709,8 @@ static void thread_host_child_update_request_process(protocol_interface_info_ent
722709
mle_tlv_read_tlv(MLE_TYPE_TLV_REQUEST, mle_msg->data_ptr, mle_msg->data_length, &tlv_req);
723710

724711
// Check if partition changed
725-
if (thread_info(cur)->thread_leader_data->partitionId != leaderData.partitionId) {
726-
thread_info(cur)->thread_leader_data->leaderRouterId = leaderData.leaderRouterId;
727-
thread_info(cur)->thread_leader_data->partitionId = leaderData.partitionId;
728-
thread_old_partition_data_purge(cur);
712+
if (!thread_partition_match(cur, &leaderData)) {
713+
thread_partition_info_update(cur, &leaderData);
729714
}
730715
//Check Network Data TLV
731716
if (mle_tlv_read_tlv(MLE_TYPE_NETWORK_DATA, mle_msg->data_ptr, mle_msg->data_length, &networkDataTlv)) {

source/6LoWPAN/Thread/thread_router_bootstrap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,7 +1714,7 @@ void thread_router_bootstrap_mle_receive_cb(int8_t interface_id, mle_message_t *
17141714
if (mle_tlv_read_16_bit_tlv(MLE_TYPE_SRC_ADDRESS, mle_msg->data_ptr, mle_msg->data_length, &shortAddress)) {
17151715
//Correct TLV's lets response
17161716
if (!thread_is_router_addr(shortAddress)) {
1717-
if (leaderDataReceived && thread_info(cur)->thread_leader_data->partitionId == leaderData.partitionId) {
1717+
if (leaderDataReceived && thread_partition_match(cur, &leaderData)) {
17181718
//REED or end device send response
17191719
thread_router_accept_to_endevice(cur, mle_msg, challengeTlv.dataPtr, challengeTlv.tlvLen);
17201720
} else {
@@ -1759,7 +1759,7 @@ void thread_router_bootstrap_mle_receive_cb(int8_t interface_id, mle_message_t *
17591759
}
17601760

17611761
//validate partition id
1762-
if (thread_info(cur)->thread_leader_data->partitionId != leaderData.partitionId) {
1762+
if (!thread_partition_match(cur, &leaderData)) {
17631763
tr_debug("Drop link request from wrong partition");
17641764
return;
17651765
}

test/nanostack/unittest/stub/thread_common_stub.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,11 @@ int thread_address_registration_primary_bbr_get(struct protocol_interface_info_e
396396
void thread_reset_neighbour_info(protocol_interface_info_entry_t *cur, mle_neigh_table_entry_t *neighbour)
397397
{
398398
}
399+
bool thread_partition_match(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData)
400+
{
401+
return false;
402+
}
403+
void thread_partition_info_update(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData)
404+
{
405+
}
406+

0 commit comments

Comments
 (0)