Skip to content

Commit 9e7e9e0

Browse files
author
Tero Heinonen
authored
REED parser refactoring for MLE advertisement (#1654)
Refactored REED parser logic for MLE advertisement to make function more simpler, and some unneeded code removed.
1 parent 4fda90e commit 9e7e9e0

File tree

1 file changed

+37
-34
lines changed

1 file changed

+37
-34
lines changed

source/6LoWPAN/Thread/thread_mle_message_handler.c

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,6 @@ static bool thread_router_leader_data_process(protocol_interface_info_entry_t *c
224224
// Request network data if we have a 2-way link
225225
tr_debug("Request New Network Data from %s", trace_ipv6(src_address));
226226
thread_network_data_request_send(cur, src_address, true);
227-
} else {
228-
229227
}
230228
} else if (leaderDataUpdate == 2) {
231229
tr_debug("Start Merge");
@@ -323,14 +321,31 @@ static void thread_update_mle_entry(protocol_interface_info_entry_t *cur, mle_me
323321
return;
324322
}
325323

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+
326341
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)
327342
{
328343
mle_tlv_info_t routeTlv;
329344
thread_leader_data_t leaderData;
330345
mle_neigh_table_entry_t *entry_temp;
331346
uint16_t shortAddress;
332-
bool my_parent;
333347
bool adv_from_my_partition;
348+
bool my_parent;
334349

335350
// Check device mode & bootstrap state
336351
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
348363
// Get MLE entry
349364
entry_temp = mle_class_get_entry_by_ll64(cur->id, linkMargin, mle_msg->packet_src_address, false, NULL);
350365

366+
// Check if this is from my parent
351367
my_parent = thread_check_is_this_my_parent(cur, entry_temp);
368+
352369
adv_from_my_partition = thread_instance_id_matches(cur, &leaderData);
353370

354371
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
361378
entry_temp = NULL;
362379
}
363380

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;
380385
}
381386
}
382387

@@ -385,30 +390,28 @@ static void thread_parse_advertisement(protocol_interface_info_entry_t *cur, mle
385390

386391
// Process advertisement
387392
if (thread_info(cur)->thread_device_mode != THREAD_DEVICE_MODE_END_DEVICE) {
393+
/* REED and FED */
388394
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)) {
393398
// Create link to new neighbor no other processing allowed
394399
thread_link_request_start(cur, mle_msg->packet_src_address);
395400
return;
396401
}
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)) {
399406
return;
400407
}
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+
}
401412
}
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 */
410414
} else {
411-
//Router
412415
if (!thread_router_leader_data_process(cur, mle_msg->packet_src_address, &leaderData, &routeTlv, entry_temp) ) {
413416
return;
414417
}

0 commit comments

Comments
 (0)