@@ -224,8 +224,6 @@ static bool thread_router_leader_data_process(protocol_interface_info_entry_t *c
224
224
// Request network data if we have a 2-way link
225
225
tr_debug ("Request New Network Data from %s" , trace_ipv6 (src_address ));
226
226
thread_network_data_request_send (cur , src_address , true);
227
- } else {
228
-
229
227
}
230
228
} else if (leaderDataUpdate == 2 ) {
231
229
tr_debug ("Start Merge" );
@@ -323,14 +321,31 @@ static void thread_update_mle_entry(protocol_interface_info_entry_t *cur, mle_me
323
321
return ;
324
322
}
325
323
324
+ static bool thread_parse_advertisement_from_parent (protocol_interface_info_entry_t * cur , thread_leader_data_t * leader_data , uint16_t short_address )
325
+ {
326
+ if ((thread_info (cur )-> thread_leader_data -> partitionId != leader_data -> partitionId ) ||
327
+ (thread_info (cur )-> thread_leader_data -> weighting != leader_data -> weighting )) {
328
+ //parent changed partition/weight - reset own routing information
329
+ thread_old_partition_data_purge (cur );
330
+ }
331
+ //check if network data needs to be requested
332
+ if (!thread_bootstrap_request_network_data (cur , leader_data , short_address )) {
333
+ tr_debug ("Parent short address changed - re-attach" );
334
+ thread_bootstrap_connection_error (cur -> id , CON_PARENT_CONNECT_DOWN , NULL );
335
+ return false;
336
+ }
337
+
338
+ return true;
339
+ }
340
+
326
341
static void thread_parse_advertisement (protocol_interface_info_entry_t * cur , mle_message_t * mle_msg , mle_security_header_t * security_headers , uint8_t linkMargin )
327
342
{
328
343
mle_tlv_info_t routeTlv ;
329
344
thread_leader_data_t leaderData ;
330
345
mle_neigh_table_entry_t * entry_temp ;
331
346
uint16_t shortAddress ;
332
- bool my_parent ;
333
347
bool adv_from_my_partition ;
348
+ bool my_parent ;
334
349
335
350
// Check device mode & bootstrap state
336
351
if ((thread_info (cur )-> thread_device_mode == THREAD_DEVICE_MODE_SLEEPY_END_DEVICE ) ||
@@ -348,7 +363,9 @@ static void thread_parse_advertisement(protocol_interface_info_entry_t *cur, mle
348
363
// Get MLE entry
349
364
entry_temp = mle_class_get_entry_by_ll64 (cur -> id , linkMargin , mle_msg -> packet_src_address , false, NULL );
350
365
366
+ // Check if this is from my parent
351
367
my_parent = thread_check_is_this_my_parent (cur , entry_temp );
368
+
352
369
adv_from_my_partition = thread_instance_id_matches (cur , & leaderData );
353
370
354
371
if ((security_headers -> KeyIdMode == MAC_KEY_ID_MODE_SRC4_IDX ) && adv_from_my_partition ) {
@@ -361,22 +378,10 @@ static void thread_parse_advertisement(protocol_interface_info_entry_t *cur, mle
361
378
entry_temp = NULL ;
362
379
}
363
380
364
- // Check parent status
365
- if (!thread_attach_active_router (cur )) {
366
- //processing for non routers
367
- if (my_parent ) {
368
- //advertisement from parent
369
- if ((thread_info (cur )-> thread_leader_data -> partitionId != leaderData .partitionId ) ||
370
- (thread_info (cur )-> thread_leader_data -> weighting != leaderData .weighting )) {
371
- //parent changed partition/weight - reset own routing information
372
- thread_old_partition_data_purge (cur );
373
- }
374
- //check if network data needs to be requested
375
- if (!thread_bootstrap_request_network_data (cur , & leaderData , shortAddress )) {
376
- tr_debug ("Parent short address changed - re-attach" );
377
- thread_bootstrap_connection_error (cur -> id , CON_PARENT_CONNECT_DOWN , NULL );
378
- return ;
379
- }
381
+ /* Check parent status */
382
+ if (!thread_attach_active_router (cur ) && my_parent ) {
383
+ if (!thread_parse_advertisement_from_parent (cur , & leaderData , shortAddress )) {
384
+ return ;
380
385
}
381
386
}
382
387
@@ -385,30 +390,28 @@ static void thread_parse_advertisement(protocol_interface_info_entry_t *cur, mle
385
390
386
391
// Process advertisement
387
392
if (thread_info (cur )-> thread_device_mode != THREAD_DEVICE_MODE_END_DEVICE ) {
393
+ /* REED and FED */
388
394
if (!thread_attach_active_router (cur )) {
389
- // REED and FED
390
- if (!entry_temp && thread_bootstrap_link_create_check (cur , shortAddress ) && thread_bootstrap_link_create_allowed (cur , shortAddress , mle_msg -> packet_src_address )) {
391
- if ((thread_info (cur )-> thread_leader_data -> partitionId == leaderData .partitionId ) &&
392
- (thread_info (cur )-> thread_leader_data -> weighting == leaderData .weighting )) {
395
+ /* Check if advertisement is from same partition */
396
+ if (thread_info (cur )-> thread_leader_data -> weighting == leaderData .weighting && thread_info (cur )-> thread_leader_data -> partitionId == leaderData .partitionId ) {
397
+ if (!entry_temp && thread_bootstrap_link_create_check (cur , shortAddress ) && thread_bootstrap_link_create_allowed (cur , shortAddress , mle_msg -> packet_src_address )) {
393
398
// Create link to new neighbor no other processing allowed
394
399
thread_link_request_start (cur , mle_msg -> packet_src_address );
395
400
return ;
396
401
}
397
- if (!thread_router_leader_data_process (cur , mle_msg -> packet_src_address , & leaderData , & routeTlv , entry_temp )) {
398
- // better partition found or new network data learn started
402
+ /* Advertisement from higher / lower partition */
403
+ } else {
404
+ // process REED advertisement from higher partition
405
+ if (thread_reed_partitions_merge (cur , shortAddress , leaderData )) {
399
406
return ;
400
407
}
408
+ // REED advertisement to lower partition to help merge faster
409
+ if (thread_heard_lower_partition (cur ,leaderData )) {
410
+ thread_router_bootstrap_reed_merge_advertisement (cur );
411
+ }
401
412
}
402
- // process REED advertisement from higher partition
403
- if (thread_reed_partitions_merge (cur , shortAddress , leaderData )) {
404
- return ;
405
- }
406
- // REED advertisement to lower partition to help merge faster
407
- if (thread_heard_lower_partition (cur ,leaderData )) {
408
- thread_router_bootstrap_reed_merge_advertisement (cur );
409
- }
413
+ /* ROUTER */
410
414
} else {
411
- //Router
412
415
if (!thread_router_leader_data_process (cur , mle_msg -> packet_src_address , & leaderData , & routeTlv , entry_temp ) ) {
413
416
return ;
414
417
}
0 commit comments