Skip to content

Commit 2cef8ac

Browse files
author
Jarkko Paso
authored
Merge pull request ARMmbed#1538 from ARMmbed/mergeMtoK
Merge mto k
2 parents 321f700 + 146d7c4 commit 2cef8ac

26 files changed

+165
-91
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2554,7 +2554,7 @@ void protocol_6lowpan_mac_scan_confirm(int8_t if_id, const mlme_scan_conf_t* con
25542554

25552555
void bootstrap_timer_handle(uint16_t ticks)
25562556
{
2557-
ticks;
2557+
(void)ticks;
25582558
ns_list_foreach(protocol_interface_info_entry_t, cur, &protocol_interface_info_list) {
25592559
if (cur->nwk_id == IF_6LoWPAN) {
25602560
if (cur->nwk_bootstrap_state == ER_ACTIVE_SCAN || cur->nwk_bootstrap_state == ER_WARM_ACTIVE_SCAN) {

source/6LoWPAN/Thread/thread_bbr_api.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ static int thread_border_relay_to_leader_cb(int8_t service_id, uint8_t source_ad
512512
return -1;
513513
}
514514

515+
#ifdef HAVE_THREAD_BORDER_ROUTER
515516
static bool thread_bbr_i_host_prefix(struct protocol_interface_info_entry *cur, uint8_t prefix_ptr[8], uint8_t *br_count, bool *i_am_lowest)
516517
{
517518
bool i_host_this_prefix = false;
@@ -568,6 +569,7 @@ static void thread_bbr_network_data_remove(thread_bbr_t *this)
568569
memset(this->bbr_prefix,0,8);
569570
this->br_info_published = false;
570571
}
572+
571573
static void thread_bbr_network_data_send(thread_bbr_t *this, uint8_t prefix[8], uint8_t eui64[8])
572574
{
573575
thread_border_router_info_t br_info = { 0 };
@@ -594,8 +596,8 @@ static void thread_bbr_network_data_send(thread_bbr_t *this, uint8_t prefix[8],
594596
thread_border_router_prefix_add(this->interface_id, this->bbr_prefix, 64, &br_info);
595597
thread_border_router_publish(this->interface_id);
596598
this->br_info_published = true;
597-
598599
}
600+
599601
static void thread_bbr_routing_enable(thread_bbr_t *this)
600602
{
601603
if (this->routing_enabled) {
@@ -691,17 +693,18 @@ static void thread_bbr_status_check(thread_bbr_t *this, uint32_t seconds)
691693
} else {
692694
this->br_delete_timer = randLIB_get_random_in_range(5,10);
693695
}
694-
tr_info("br: too many BRs start remove jitter: %d", this->br_delete_timer);
696+
tr_info("br: too many BRs start remove jitter:%"PRIu32, this->br_delete_timer);
695697
return;
696698
}
697699
if (this->br_info_published && !bbr_prefix_ptr ) {
698700
// Need to disable ND proxy will give a 20 second delay for it We could also disable routing immediately
699701
this->br_delete_timer = 20;
700-
tr_info("br: can not be border router need to remove after: %d", this->br_delete_timer);
702+
tr_info("br: can not be border router need to remove after: %"PRIu32, this->br_delete_timer);
701703
return;
702704
}
703705
}
704706
}
707+
705708
static bool thread_bbr_activated(thread_bbr_t *this, uint32_t seconds)
706709
{
707710
protocol_interface_info_entry_t *cur;
@@ -740,7 +743,6 @@ static bool thread_bbr_activated(thread_bbr_t *this, uint32_t seconds)
740743
return false;
741744
}
742745

743-
#ifdef HAVE_THREAD_BORDER_ROUTER
744746
bool thread_bbr_routing_enabled(protocol_interface_info_entry_t *cur)
745747
{
746748
thread_bbr_t *this = thread_bbr_find_by_interface(cur->thread_info->interface_id);
@@ -756,7 +758,7 @@ void thread_bbr_network_data_update_notify(protocol_interface_info_entry_t *cur)
756758
(void) cur;
757759
thread_mdns_network_data_update_notify();
758760
}
759-
#endif
761+
#endif /* HAVE_THREAD_BORDER_ROUTER*/
760762

761763
static void thread_bbr_udp_proxy_service_stop(int8_t interface_id)
762764
{
@@ -766,7 +768,6 @@ static void thread_bbr_udp_proxy_service_stop(int8_t interface_id)
766768
tr_error("Failed to find BA instance");
767769
return;
768770
}
769-
tr_debug("thread_border_router_udp_proxy_service_stop %d", interface_id);
770771

771772
socket_close(this->udp_proxy_socket);
772773
this->udp_proxy_socket = -1;
@@ -787,19 +788,18 @@ int thread_bbr_commissioner_proxy_service_update(int8_t interface_id)
787788
goto return_fail;
788789
}
789790

790-
if (cur->thread_info->registered_commissioner.commissioner_valid) {
791-
// relay is needed
791+
if (!cur->thread_info->registered_commissioner.commissioner_valid) {
792+
// commissioner not enabled
792793
if (this->udp_proxy_socket != -1) {
793-
// UDP service is already running
794-
return 0;
794+
thread_bbr_udp_proxy_service_stop(interface_id);
795795
}
796-
} else if (this->udp_proxy_socket != -1) {
797-
// UDP service is running and need to delete
798-
thread_bbr_udp_proxy_service_stop(interface_id);
799796
return 0;
800797
}
801-
tr_debug("thread_border_router_udp_proxy_service_start %d", interface_id);
802798

799+
if (this->udp_proxy_socket != -1) {
800+
// commissioner is valid and UDP service is already running
801+
return 0;
802+
}
803803

804804
// Set source parameters, if commissioner is available
805805
ret_val = thread_management_get_commissioner_address(this->interface_id, &ns_source_addr.address[0], 0);

source/6LoWPAN/Thread/thread_bootstrap.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,14 @@ int thread_bootstrap_partition_process(protocol_interface_info_entry_t *cur, uin
489489
tr_debug("Heard a REED and I am a singleton - merge");
490490
return 2;
491491
}
492+
/*Rule 0: If we are going to form Higher partition than heard we dont try to attach to lower ones
493+
*/
494+
if (thread_extension_enabled(cur) &&
495+
thread_info(cur)->thread_device_mode == THREAD_DEVICE_MODE_ROUTER &&
496+
heard_partition_leader_data->weighting < thread_info(cur)->partition_weighting) {
497+
return -2;
498+
}
499+
492500
//Rule 1: A non-singleton Thread Network Partition always has higher priority than a singleton Thread Network Partition
493501
if (heard_partition_routers > 1 && active_routers == 1) {
494502
tr_debug("Heard a nonsingleton and i am a singleton");
@@ -1419,9 +1427,9 @@ static void thread_bootstrap_generate_leader_and_link(protocol_interface_info_en
14191427
static int8_t thread_bootstrap_attempt_attach_with_pending_set(protocol_interface_info_entry_t *cur)
14201428
{
14211429
tr_debug("Attempting to attach with pending set");
1422-
uint32_t pending_timestamp = thread_joiner_application_pending_config_timeout_get(cur->id);
1423-
if (pending_timestamp > 0) {
1424-
tr_debug("We have a pending timestamp running");
1430+
uint32_t pending_delay_timer = thread_joiner_application_pending_config_timeout_get(cur->id);
1431+
if (pending_delay_timer > 0 && thread_joiner_application_pending_delay_timer_in_sync(cur->id)) {
1432+
tr_debug("We have a pending delay timer running");
14251433
//we already have a pending set that can be activated so return
14261434
return -1;
14271435
}

source/6LoWPAN/Thread/thread_border_router_api.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,6 @@ static void thread_border_router_child_network_data_clean(uint8_t interface_id,
314314

315315
static void thread_border_router_lost_children_nwk_data_validate(protocol_interface_info_entry_t *cur, uint16_t router_short_addr)
316316
{
317-
318-
tr_debug("thread_border_router_lost_children_nwk_data_validate() %x", router_short_addr);
319317
if (!thread_is_router_addr(router_short_addr)) {
320318
// not validating children nwk data
321319
return;
@@ -432,6 +430,7 @@ static bool thread_border_router_local_srv_data_in_network_data_check(protocol_i
432430
return true;
433431
}
434432

433+
#ifdef HAVE_THREAD_BORDER_ROUTER
435434
static int thread_border_router_recursive_dns_server_option_store(int8_t interface_id, uint8_t *recursive_dns_server_option, uint16_t recursive_dns_server_option_len)
436435
{
437436
thread_border_router_t *this = thread_border_router_find_by_interface(interface_id);
@@ -451,7 +450,9 @@ static int thread_border_router_recursive_dns_server_option_store(int8_t interfa
451450
}
452451
return 0;
453452
}
453+
#endif
454454

455+
#ifdef HAVE_THREAD_BORDER_ROUTER
455456
static int thread_border_router_dns_search_list_option_store(int8_t interface_id, uint8_t *dns_search_list_option, uint16_t search_list_option_len)
456457
{
457458
thread_border_router_t *this = thread_border_router_find_by_interface(interface_id);
@@ -470,6 +471,7 @@ static int thread_border_router_dns_search_list_option_store(int8_t interface_id
470471
}
471472
return 0;
472473
}
474+
#endif
473475

474476
int8_t thread_border_router_init(int8_t interface_id)
475477
{

source/6LoWPAN/Thread/thread_common.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,6 @@ bool thread_pending_operational_dataset_process(protocol_interface_info_entry_t
16601660
tr_error("pending set creation failed");
16611661
return false;
16621662
}
1663-
16641663
tr_debug("updating pending dataset");
16651664
thread_joiner_application_pending_config_timestamp_set(cur->id,mle_pending_timestamp);
16661665
thread_joiner_application_pending_config_enable(cur->id,delay_timer);

source/6LoWPAN/Thread/thread_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ typedef struct thread_info_s {
304304
bool networkDataRequested: 1;
305305
bool end_device_link_synch: 1;
306306
bool router_mc_addrs_registered: 1;
307+
bool leader_synced:1; // flag used by leader after restart
307308
} thread_info_t;
308309

309310
#ifdef HAVE_THREAD

source/6LoWPAN/Thread/thread_discovery.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ static int thread_discovery_response_send(thread_discovery_class_t *class, threa
559559
*ptr++ = message_length;
560560
uint16_t discover_response_tlv = thread_discover_tlv_get(class->version, (linkConfiguration->securityPolicy & SECURITY_POLICY_NATIVE_COMMISSIONING_ALLOWED));
561561

562-
discover_response_tlv = thread_extension_discover_response_tlv_write(discover_response_tlv, class->version, thread_extension_security_policy_enabled(linkConfiguration->securityPolicy));
562+
thread_extension_discover_response_tlv_write(&discover_response_tlv, class->version, linkConfiguration->securityPolicy);
563563

564564
ptr = thread_meshcop_tlv_data_write_uint16(ptr, MESHCOP_TLV_DISCOVERY_RESPONSE, discover_response_tlv);
565565
ptr = thread_meshcop_tlv_data_write(ptr, MESHCOP_TLV_XPANID, 8, linkConfiguration->extented_pan_id);

source/6LoWPAN/Thread/thread_extension.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,14 @@ void thread_extension_activate(protocol_interface_info_entry_t *cur)
568568
}
569569
}
570570

571-
bool thread_extension_security_policy_enabled(uint8_t securityPolicy)
571+
bool thread_extension_enabled(protocol_interface_info_entry_t *cur)
572572
{
573+
if (thread_info(cur)->version <= THREAD_PROTOCOL_VERSION) {
574+
// Thread 1.1 version devices dont check the extension
575+
return false;
576+
}
577+
uint16_t securityPolicy = thread_joiner_application_security_policy_get(cur->id);
578+
573579
if (securityPolicy & SECURITY_POLICY_CCM_ENABLED) {
574580
return true;
575581
}
@@ -607,12 +613,13 @@ void thread_extension_discover_response_read(discovery_response_list_t *nwk_info
607613
discovery_add_info->ccm_supported = (discover_response_tlv >> 10) & 1;
608614
}
609615

610-
uint16_t thread_extension_discover_response_tlv_write(uint16_t data, uint8_t version, bool extension_bit)
616+
void thread_extension_discover_response_tlv_write(uint16_t *data, uint8_t version, uint16_t securityPolicy)
611617
{
612-
if (version == 3 && extension_bit) {
613-
data |= (uint16_t) (1 << 10);
618+
619+
if (version == 3 && securityPolicy & SECURITY_POLICY_CCM_ENABLED) {
620+
*data |= (uint16_t) (1 << 10);
614621
}
615-
return data;
622+
return;
616623
}
617624

618625
#ifdef HAVE_THREAD_ROUTER

source/6LoWPAN/Thread/thread_extension.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ void thread_extension_mcast_subscrition_change(protocol_interface_info_entry_t *
5656
void thread_extension_address_registration_trigger(protocol_interface_info_entry_t *interface);
5757
void thread_extension_route_set(protocol_interface_info_entry_t *cur);
5858
void thread_extension_activate(protocol_interface_info_entry_t *cur);
59-
bool thread_extension_security_policy_enabled(uint8_t securityPolicy);
59+
bool thread_extension_enabled(protocol_interface_info_entry_t *cur);
6060
bool thread_extension_version_check(uint8_t version);
6161
void thread_extension_discover_response_read(struct discovery_response_list *nwk_info, uint16_t discover_response_tlv, uint8_t *data_ptr, uint16_t data_len);
62-
uint16_t thread_extension_discover_response_tlv_write(uint16_t data, uint8_t version, bool extension_bit);
62+
void thread_extension_discover_response_tlv_write(uint16_t *data, uint8_t version, uint16_t securityPolicy);
6363
#ifdef HAVE_THREAD_ROUTER
6464
int thread_extension_joiner_router_init(int8_t interface_id);
6565
bool thread_extension_joining_enabled(int8_t interface_id);
@@ -87,7 +87,7 @@ uint8_t *thread_extension_discover_response_write(protocol_interface_info_entry_
8787
#define thread_extension_mcast_subscrition_change(interface, group, added)
8888
#define thread_extension_route_set(cur)
8989
#define thread_extension_activate(cur)
90-
#define thread_extension_security_policy_enabled(securityPolicy) (false)
90+
#define thread_extension_enabled(cur) (false)
9191
#define thread_extension_version_check(version) (false)
9292
#define thread_extension_discover_response_read(nwk_info, discover_response_tlv, data_ptr, data_len)
9393
#define thread_extension_discover_response_tlv_write(data, version, extension_bit) (data)

source/6LoWPAN/Thread/thread_extension_bbr.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ static int thread_extension_bbr_mlr_cb(int8_t service_id, uint8_t source_address
571571
(void)source_address;
572572
(void)source_port;
573573

574+
protocol_interface_info_entry_t *cur;
575+
sn_coap_msg_code_e response_code = COAP_MSG_CODE_RESPONSE_CHANGED;
574576
uint16_t addr_len;
575577
uint16_t session_id;
576578
uint8_t *addr_data_ptr;
@@ -583,12 +585,15 @@ static int thread_extension_bbr_mlr_cb(int8_t service_id, uint8_t source_address
583585
tr_info("Thread BBR MLR.ntf receive");
584586

585587
thread_pbbr_t *this = thread_border_router_find_by_service(service_id);
586-
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(this->interface_id);
587-
sn_coap_msg_code_e response_code = COAP_MSG_CODE_RESPONSE_CHANGED;
588-
589588
if (!this) {
590589
return -1;
591590
}
591+
592+
cur = protocol_stack_interface_info_get_by_id(this->interface_id);
593+
if (!cur) {
594+
return -1;
595+
}
596+
592597
ptr = payload;
593598

594599
// Set default value if not specified in message.

source/6LoWPAN/Thread/thread_host_bootstrap.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,9 @@ static void thread_child_synch_receive_cb(int8_t interface_id, mle_message_t *ml
407407
tr_debug("End device synch Possible");
408408

409409
cur->thread_info->thread_attached_state = THREAD_STATE_CONNECTED;
410-
410+
// read network data, and leader data check. Send data request sent if pending set is not in sync
411411
if (mle_tlv_read_tlv(MLE_TYPE_NETWORK_DATA, mle_msg->data_ptr, mle_msg->data_length, &networkDataTlv) &&
412-
thread_leader_data_parse(mle_msg->data_ptr, mle_msg->data_length, &leaderData)) {
412+
thread_leader_data_parse(mle_msg->data_ptr, mle_msg->data_length, &leaderData) && thread_joiner_application_pending_delay_timer_in_sync(cur->id)) {
413413
thread_bootstrap_network_data_save(cur, &leaderData, networkDataTlv.dataPtr, networkDataTlv.tlvLen);
414414
} else {
415415
thread_bootstrap_parent_network_data_request(cur, true);
@@ -588,7 +588,10 @@ void thread_mle_parent_discover_receive_cb(int8_t interface_id, mle_message_t *m
588588
}
589589
}
590590

591-
if (leaderData.weighting < thread_info(cur)->partition_weighting) {
591+
if (thread_extension_enabled(cur) &&
592+
thread_info(cur)->thread_device_mode == THREAD_DEVICE_MODE_ROUTER &&
593+
leaderData.weighting < thread_info(cur)->partition_weighting) {
594+
// Only applies to extensions and only routers that can form new partitions can ignore lower weight
592595
tr_debug("Drop parent due weighting %d<%d", leaderData.weighting, thread_info(cur)->partition_weighting);
593596
return;
594597
}
@@ -612,6 +615,7 @@ void thread_mle_parent_discover_receive_cb(int8_t interface_id, mle_message_t *m
612615
(leaderData.weighting != currentWeighting)) {
613616
int retVal = thread_bootstrap_partition_process(cur, connectivityTlv.activeRouters, &leaderData,NULL);
614617
if (retVal > 0) {
618+
// New partition is Higher
615619
scan_result = thread_info(cur)->thread_attach_scanned_parent;
616620
}
617621
}

source/6LoWPAN/Thread/thread_joiner_application.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ typedef struct {
218218
int8_t interface_id;
219219
int8_t coap_service_id;
220220
int8_t secure_coap_service_id;
221+
bool pending_set_in_sync:1;
221222
ns_list_link_t link;
222223
} thread_joiner_t;
223224

@@ -988,6 +989,7 @@ static int thread_joiner_application_nvm_link_config_read(thread_joiner_t *this)
988989
}
989990
this->pending_configuration_ptr = pend_conf_ptr;
990991
this->pending_configuration_ptr->timeout_in_ms = 0;
992+
this->pending_set_in_sync = false;
991993
}
992994
else {
993995
tr_info("Reading pending from NVM error:%d", pending_ret);
@@ -1031,6 +1033,16 @@ uint64_t thread_joiner_application_active_timestamp_get(int8_t interface_id)
10311033
return this->configuration_ptr->timestamp;
10321034
}
10331035

1036+
uint8_t thread_joiner_application_security_policy_get(int8_t interface_id)
1037+
{
1038+
thread_joiner_t *this = thread_joiner_find(interface_id);
1039+
if (!this) {
1040+
return 0;
1041+
}
1042+
1043+
return this->configuration_ptr->securityPolicy;
1044+
}
1045+
10341046
uint8_t *thread_joiner_application_random_mac_get(int8_t interface_id)
10351047
{
10361048
thread_joiner_t *this = thread_joiner_find(interface_id);
@@ -1112,7 +1124,8 @@ void thread_joiner_pending_config_activate(int8_t interface_id)
11121124

11131125
if (master_key_ptr && memcmp(master_key_ptr,link_configuration->master_key,16) != 0) {
11141126
this->configuration_ptr->key_sequence = 0;
1115-
thread_nvm_store_seq_counter_write(this->configuration_ptr->key_sequence);
1127+
// if write fails, keep going...
1128+
(void)thread_nvm_store_seq_counter_write(this->configuration_ptr->key_sequence);
11161129
}
11171130

11181131
tr_info("*** Activating pending configuration.");
@@ -1123,7 +1136,7 @@ void thread_joiner_pending_config_activate(int8_t interface_id)
11231136
this->active_configuration_ptr->timestamp = pending_active_timestamp;
11241137
// All information is copied from old configuration so if configuration is corrupt we dont change anything.
11251138
this->pending_configuration_ptr = NULL;
1126-
thread_nvm_store_pending_configuration_remove();
1139+
(void)thread_nvm_store_pending_configuration_remove();
11271140
configuration_set_copy_mandatory(this->active_configuration_ptr, this->old_active_configuration_ptr);
11281141
link_configuration_update(this->configuration_ptr,this->active_configuration_ptr->data, this->active_configuration_ptr->length);
11291142
link_configuration_trace(this->configuration_ptr);
@@ -1190,10 +1203,19 @@ bool thread_joiner_application_pending_config_exists(int8_t interface_id)
11901203
return true;
11911204
}
11921205

1193-
uint64_t thread_joiner_application_pending_config_timestamp_get(int8_t interface_id)
1206+
bool thread_joiner_application_pending_delay_timer_in_sync(int8_t interface_id)
11941207
{
11951208
thread_joiner_t *this = thread_joiner_find(interface_id);
11961209
if (!this || !this->pending_configuration_ptr) {
1210+
return false;
1211+
}
1212+
return this->pending_set_in_sync;
1213+
}
1214+
1215+
uint64_t thread_joiner_application_pending_config_timestamp_get(int8_t interface_id)
1216+
{
1217+
thread_joiner_t *this = thread_joiner_find(interface_id);
1218+
if (!this || !this->pending_configuration_ptr || !this->pending_set_in_sync) {
11971219
return 0;
11981220
}
11991221
return this->pending_configuration_ptr->timestamp;
@@ -1217,6 +1239,7 @@ int thread_joiner_application_pending_config_enable(int8_t interface_id, uint32_
12171239
return -1;
12181240
}
12191241
this->pending_configuration_ptr->timeout_in_ms = timeout_in_ms;
1242+
this->pending_set_in_sync = true;
12201243

12211244
if(this->pending_configuration_ptr->timeout_in_ms > THREAD_MAX_DELAY_TIMER_SECONDS*1000) {
12221245
this->pending_configuration_ptr->timeout_in_ms = THREAD_MAX_DELAY_TIMER_SECONDS*1000;

0 commit comments

Comments
 (0)