Skip to content

Commit

Permalink
Add extension check for partition weight drop in parent selection (AR…
Browse files Browse the repository at this point in the history
…Mmbed#1521)

Only drop partitions if security policy demands
  • Loading branch information
Mika Tervonen authored Jan 9, 2018
1 parent d8dea28 commit c288227
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 10 deletions.
8 changes: 8 additions & 0 deletions source/6LoWPAN/Thread/thread_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,14 @@ int thread_bootstrap_partition_process(protocol_interface_info_entry_t *cur, uin
tr_debug("Heard a REED and I am a singleton - merge");
return 2;
}
/*Rule 0: If we are going to form Higher partition than heard we dont try to attach to lower ones
*/
if (thread_extension_enabled(cur) &&
thread_info(cur)->thread_device_mode == THREAD_DEVICE_MODE_ROUTER &&
heard_partition_leader_data->weighting < thread_info(cur)->partition_weighting) {
return -2;
}

//Rule 1: A non-singleton Thread Network Partition always has higher priority than a singleton Thread Network Partition
if (heard_partition_routers > 1 && active_routers == 1) {
tr_debug("Heard a nonsingleton and i am a singleton");
Expand Down
2 changes: 1 addition & 1 deletion source/6LoWPAN/Thread/thread_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ static int thread_discovery_response_send(thread_discovery_class_t *class, threa
*ptr++ = message_length;
uint16_t discover_response_tlv = thread_discover_tlv_get(class->version, (linkConfiguration->securityPolicy & SECURITY_POLICY_NATIVE_COMMISSIONING_ALLOWED));

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

ptr = thread_meshcop_tlv_data_write_uint16(ptr, MESHCOP_TLV_DISCOVERY_RESPONSE, discover_response_tlv);
ptr = thread_meshcop_tlv_data_write(ptr, MESHCOP_TLV_XPANID, 8, linkConfiguration->extented_pan_id);
Expand Down
17 changes: 12 additions & 5 deletions source/6LoWPAN/Thread/thread_extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,14 @@ void thread_extension_activate(protocol_interface_info_entry_t *cur)
}
}

bool thread_extension_security_policy_enabled(uint8_t securityPolicy)
bool thread_extension_enabled(protocol_interface_info_entry_t *cur)
{
if (thread_info(cur)->version <= THREAD_PROTOCOL_VERSION) {
// Thread 1.1 version devices dont check the extension
return false;
}
uint16_t securityPolicy = thread_joiner_application_security_policy_get(cur->id);

if (securityPolicy & SECURITY_POLICY_CCM_ENABLED) {
return true;
}
Expand Down Expand Up @@ -607,12 +613,13 @@ void thread_extension_discover_response_read(discovery_response_list_t *nwk_info
discovery_add_info->ccm_supported = (discover_response_tlv >> 10) & 1;
}

uint16_t thread_extension_discover_response_tlv_write(uint16_t data, uint8_t version, bool extension_bit)
void thread_extension_discover_response_tlv_write(uint16_t *data, uint8_t version, uint16_t securityPolicy)
{
if (version == 3 && extension_bit) {
data |= (uint16_t) (1 << 10);

if (version == 3 && securityPolicy & SECURITY_POLICY_CCM_ENABLED) {
*data |= (uint16_t) (1 << 10);
}
return data;
return;
}

#ifdef HAVE_THREAD_ROUTER
Expand Down
6 changes: 3 additions & 3 deletions source/6LoWPAN/Thread/thread_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ void thread_extension_mcast_subscrition_change(protocol_interface_info_entry_t *
void thread_extension_address_registration_trigger(protocol_interface_info_entry_t *interface);
void thread_extension_route_set(protocol_interface_info_entry_t *cur);
void thread_extension_activate(protocol_interface_info_entry_t *cur);
bool thread_extension_security_policy_enabled(uint8_t securityPolicy);
bool thread_extension_enabled(protocol_interface_info_entry_t *cur);
bool thread_extension_version_check(uint8_t version);
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);
uint16_t thread_extension_discover_response_tlv_write(uint16_t data, uint8_t version, bool extension_bit);
void thread_extension_discover_response_tlv_write(uint16_t *data, uint8_t version, uint16_t securityPolicy);
#ifdef HAVE_THREAD_ROUTER
int thread_extension_joiner_router_init(int8_t interface_id);
bool thread_extension_joining_enabled(int8_t interface_id);
Expand Down Expand Up @@ -87,7 +87,7 @@ uint8_t *thread_extension_discover_response_write(protocol_interface_info_entry_
#define thread_extension_mcast_subscrition_change(interface, group, added)
#define thread_extension_route_set(cur)
#define thread_extension_activate(cur)
#define thread_extension_security_policy_enabled(securityPolicy) (false)
#define thread_extension_enabled(cur) (false)
#define thread_extension_version_check(version) (false)
#define thread_extension_discover_response_read(nwk_info, discover_response_tlv, data_ptr, data_len)
#define thread_extension_discover_response_tlv_write(data, version, extension_bit) (data)
Expand Down
6 changes: 5 additions & 1 deletion source/6LoWPAN/Thread/thread_host_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,10 @@ void thread_mle_parent_discover_receive_cb(int8_t interface_id, mle_message_t *m
}
}

if (leaderData.weighting < thread_info(cur)->partition_weighting) {
if (thread_extension_enabled(cur) &&
thread_info(cur)->thread_device_mode == THREAD_DEVICE_MODE_ROUTER &&
leaderData.weighting < thread_info(cur)->partition_weighting) {
// Only applies to extensions and only routers that can form new partitions can ignore lower weight
tr_debug("Drop parent due weighting %d<%d", leaderData.weighting, thread_info(cur)->partition_weighting);
return;
}
Expand All @@ -612,6 +615,7 @@ void thread_mle_parent_discover_receive_cb(int8_t interface_id, mle_message_t *m
(leaderData.weighting != currentWeighting)) {
int retVal = thread_bootstrap_partition_process(cur, connectivityTlv.activeRouters, &leaderData,NULL);
if (retVal > 0) {
// New partition is Higher
scan_result = thread_info(cur)->thread_attach_scanned_parent;
}
}
Expand Down
10 changes: 10 additions & 0 deletions source/6LoWPAN/Thread/thread_joiner_application.c
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,16 @@ uint64_t thread_joiner_application_active_timestamp_get(int8_t interface_id)
return this->configuration_ptr->timestamp;
}

uint8_t thread_joiner_application_security_policy_get(int8_t interface_id)
{
thread_joiner_t *this = thread_joiner_find(interface_id);
if (!this) {
return 0;
}

return this->configuration_ptr->securityPolicy;
}

uint8_t *thread_joiner_application_random_mac_get(int8_t interface_id)
{
thread_joiner_t *this = thread_joiner_find(interface_id);
Expand Down
1 change: 1 addition & 0 deletions source/6LoWPAN/Thread/thread_joiner_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void thread_joiner_application_deinit(int8_t interface_id);
struct link_configuration *thread_joiner_application_get_config(int8_t interface_id);

uint64_t thread_joiner_application_active_timestamp_get(int8_t interface_id);
uint8_t thread_joiner_application_security_policy_get(int8_t interface_id);
void thread_joiner_application_active_timestamp_set(int8_t interface_id, uint64_t timestamp);
uint8_t *thread_joiner_application_active_config_tlv_list_get(uint8_t interface_id, uint16_t *length);

Expand Down
6 changes: 6 additions & 0 deletions test/nanostack/unittest/stub/thread_extension_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ void thread_extension_activate(protocol_interface_info_entry_t *cur)
{
(void)cur;
}
bool thread_extension_enabled(protocol_interface_info_entry_t *cur)
{
(void)cur;
return false;
}

void thread_extension_route_set(protocol_interface_info_entry_t *cur)
{
(void)cur;
Expand Down
5 changes: 5 additions & 0 deletions test/nanostack/unittest/stub/thread_joiner_application_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ uint64_t thread_joiner_application_active_timestamp_get(int8_t interface_id)
{
return 0;
}
uint8_t thread_joiner_application_security_policy_get(int8_t interface_id)
{
return 0;
}

int thread_joiner_application_domain_prefix_get(int8_t interface_id, uint8_t *options_ptr, uint8_t *domain_prefix_ptr, uint8_t *domain_prefix_len)
{
return 0;
Expand Down

0 comments on commit c288227

Please sign in to comment.