Skip to content

Commit

Permalink
Merge pull request ARMmbed#1538 from ARMmbed/mergeMtoK
Browse files Browse the repository at this point in the history
Merge mto k
  • Loading branch information
Jarkko Paso authored Jan 22, 2018
2 parents 321f700 + 146d7c4 commit 2cef8ac
Show file tree
Hide file tree
Showing 26 changed files with 165 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2554,7 +2554,7 @@ void protocol_6lowpan_mac_scan_confirm(int8_t if_id, const mlme_scan_conf_t* con

void bootstrap_timer_handle(uint16_t ticks)
{
ticks;
(void)ticks;
ns_list_foreach(protocol_interface_info_entry_t, cur, &protocol_interface_info_list) {
if (cur->nwk_id == IF_6LoWPAN) {
if (cur->nwk_bootstrap_state == ER_ACTIVE_SCAN || cur->nwk_bootstrap_state == ER_WARM_ACTIVE_SCAN) {
Expand Down
28 changes: 14 additions & 14 deletions source/6LoWPAN/Thread/thread_bbr_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ static int thread_border_relay_to_leader_cb(int8_t service_id, uint8_t source_ad
return -1;
}

#ifdef HAVE_THREAD_BORDER_ROUTER
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)
{
bool i_host_this_prefix = false;
Expand Down Expand Up @@ -568,6 +569,7 @@ static void thread_bbr_network_data_remove(thread_bbr_t *this)
memset(this->bbr_prefix,0,8);
this->br_info_published = false;
}

static void thread_bbr_network_data_send(thread_bbr_t *this, uint8_t prefix[8], uint8_t eui64[8])
{
thread_border_router_info_t br_info = { 0 };
Expand All @@ -594,8 +596,8 @@ static void thread_bbr_network_data_send(thread_bbr_t *this, uint8_t prefix[8],
thread_border_router_prefix_add(this->interface_id, this->bbr_prefix, 64, &br_info);
thread_border_router_publish(this->interface_id);
this->br_info_published = true;

}

static void thread_bbr_routing_enable(thread_bbr_t *this)
{
if (this->routing_enabled) {
Expand Down Expand Up @@ -691,17 +693,18 @@ static void thread_bbr_status_check(thread_bbr_t *this, uint32_t seconds)
} else {
this->br_delete_timer = randLIB_get_random_in_range(5,10);
}
tr_info("br: too many BRs start remove jitter: %d", this->br_delete_timer);
tr_info("br: too many BRs start remove jitter:%"PRIu32, this->br_delete_timer);
return;
}
if (this->br_info_published && !bbr_prefix_ptr ) {
// Need to disable ND proxy will give a 20 second delay for it We could also disable routing immediately
this->br_delete_timer = 20;
tr_info("br: can not be border router need to remove after: %d", this->br_delete_timer);
tr_info("br: can not be border router need to remove after: %"PRIu32, this->br_delete_timer);
return;
}
}
}

static bool thread_bbr_activated(thread_bbr_t *this, uint32_t seconds)
{
protocol_interface_info_entry_t *cur;
Expand Down Expand Up @@ -740,7 +743,6 @@ static bool thread_bbr_activated(thread_bbr_t *this, uint32_t seconds)
return false;
}

#ifdef HAVE_THREAD_BORDER_ROUTER
bool thread_bbr_routing_enabled(protocol_interface_info_entry_t *cur)
{
thread_bbr_t *this = thread_bbr_find_by_interface(cur->thread_info->interface_id);
Expand All @@ -756,7 +758,7 @@ void thread_bbr_network_data_update_notify(protocol_interface_info_entry_t *cur)
(void) cur;
thread_mdns_network_data_update_notify();
}
#endif
#endif /* HAVE_THREAD_BORDER_ROUTER*/

static void thread_bbr_udp_proxy_service_stop(int8_t interface_id)
{
Expand All @@ -766,7 +768,6 @@ static void thread_bbr_udp_proxy_service_stop(int8_t interface_id)
tr_error("Failed to find BA instance");
return;
}
tr_debug("thread_border_router_udp_proxy_service_stop %d", interface_id);

socket_close(this->udp_proxy_socket);
this->udp_proxy_socket = -1;
Expand All @@ -787,19 +788,18 @@ int thread_bbr_commissioner_proxy_service_update(int8_t interface_id)
goto return_fail;
}

if (cur->thread_info->registered_commissioner.commissioner_valid) {
// relay is needed
if (!cur->thread_info->registered_commissioner.commissioner_valid) {
// commissioner not enabled
if (this->udp_proxy_socket != -1) {
// UDP service is already running
return 0;
thread_bbr_udp_proxy_service_stop(interface_id);
}
} else if (this->udp_proxy_socket != -1) {
// UDP service is running and need to delete
thread_bbr_udp_proxy_service_stop(interface_id);
return 0;
}
tr_debug("thread_border_router_udp_proxy_service_start %d", interface_id);

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

// Set source parameters, if commissioner is available
ret_val = thread_management_get_commissioner_address(this->interface_id, &ns_source_addr.address[0], 0);
Expand Down
14 changes: 11 additions & 3 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 Expand Up @@ -1419,9 +1427,9 @@ static void thread_bootstrap_generate_leader_and_link(protocol_interface_info_en
static int8_t thread_bootstrap_attempt_attach_with_pending_set(protocol_interface_info_entry_t *cur)
{
tr_debug("Attempting to attach with pending set");
uint32_t pending_timestamp = thread_joiner_application_pending_config_timeout_get(cur->id);
if (pending_timestamp > 0) {
tr_debug("We have a pending timestamp running");
uint32_t pending_delay_timer = thread_joiner_application_pending_config_timeout_get(cur->id);
if (pending_delay_timer > 0 && thread_joiner_application_pending_delay_timer_in_sync(cur->id)) {
tr_debug("We have a pending delay timer running");
//we already have a pending set that can be activated so return
return -1;
}
Expand Down
6 changes: 4 additions & 2 deletions source/6LoWPAN/Thread/thread_border_router_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,6 @@ static void thread_border_router_child_network_data_clean(uint8_t interface_id,

static void thread_border_router_lost_children_nwk_data_validate(protocol_interface_info_entry_t *cur, uint16_t router_short_addr)
{

tr_debug("thread_border_router_lost_children_nwk_data_validate() %x", router_short_addr);
if (!thread_is_router_addr(router_short_addr)) {
// not validating children nwk data
return;
Expand Down Expand Up @@ -432,6 +430,7 @@ static bool thread_border_router_local_srv_data_in_network_data_check(protocol_i
return true;
}

#ifdef HAVE_THREAD_BORDER_ROUTER
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)
{
thread_border_router_t *this = thread_border_router_find_by_interface(interface_id);
Expand All @@ -451,7 +450,9 @@ static int thread_border_router_recursive_dns_server_option_store(int8_t interfa
}
return 0;
}
#endif

#ifdef HAVE_THREAD_BORDER_ROUTER
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)
{
thread_border_router_t *this = thread_border_router_find_by_interface(interface_id);
Expand All @@ -470,6 +471,7 @@ static int thread_border_router_dns_search_list_option_store(int8_t interface_id
}
return 0;
}
#endif

int8_t thread_border_router_init(int8_t interface_id)
{
Expand Down
1 change: 0 additions & 1 deletion source/6LoWPAN/Thread/thread_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,6 @@ bool thread_pending_operational_dataset_process(protocol_interface_info_entry_t
tr_error("pending set creation failed");
return false;
}

tr_debug("updating pending dataset");
thread_joiner_application_pending_config_timestamp_set(cur->id,mle_pending_timestamp);
thread_joiner_application_pending_config_enable(cur->id,delay_timer);
Expand Down
1 change: 1 addition & 0 deletions source/6LoWPAN/Thread/thread_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ typedef struct thread_info_s {
bool networkDataRequested: 1;
bool end_device_link_synch: 1;
bool router_mc_addrs_registered: 1;
bool leader_synced:1; // flag used by leader after restart
} thread_info_t;

#ifdef HAVE_THREAD
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
11 changes: 8 additions & 3 deletions source/6LoWPAN/Thread/thread_extension_bbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@ static int thread_extension_bbr_mlr_cb(int8_t service_id, uint8_t source_address
(void)source_address;
(void)source_port;

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

thread_pbbr_t *this = thread_border_router_find_by_service(service_id);
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(this->interface_id);
sn_coap_msg_code_e response_code = COAP_MSG_CODE_RESPONSE_CHANGED;

if (!this) {
return -1;
}

cur = protocol_stack_interface_info_get_by_id(this->interface_id);
if (!cur) {
return -1;
}

ptr = payload;

// Set default value if not specified in message.
Expand Down
10 changes: 7 additions & 3 deletions source/6LoWPAN/Thread/thread_host_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ static void thread_child_synch_receive_cb(int8_t interface_id, mle_message_t *ml
tr_debug("End device synch Possible");

cur->thread_info->thread_attached_state = THREAD_STATE_CONNECTED;

// read network data, and leader data check. Send data request sent if pending set is not in sync
if (mle_tlv_read_tlv(MLE_TYPE_NETWORK_DATA, mle_msg->data_ptr, mle_msg->data_length, &networkDataTlv) &&
thread_leader_data_parse(mle_msg->data_ptr, mle_msg->data_length, &leaderData)) {
thread_leader_data_parse(mle_msg->data_ptr, mle_msg->data_length, &leaderData) && thread_joiner_application_pending_delay_timer_in_sync(cur->id)) {
thread_bootstrap_network_data_save(cur, &leaderData, networkDataTlv.dataPtr, networkDataTlv.tlvLen);
} else {
thread_bootstrap_parent_network_data_request(cur, true);
Expand Down 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
29 changes: 26 additions & 3 deletions source/6LoWPAN/Thread/thread_joiner_application.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ typedef struct {
int8_t interface_id;
int8_t coap_service_id;
int8_t secure_coap_service_id;
bool pending_set_in_sync:1;
ns_list_link_t link;
} thread_joiner_t;

Expand Down Expand Up @@ -988,6 +989,7 @@ static int thread_joiner_application_nvm_link_config_read(thread_joiner_t *this)
}
this->pending_configuration_ptr = pend_conf_ptr;
this->pending_configuration_ptr->timeout_in_ms = 0;
this->pending_set_in_sync = false;
}
else {
tr_info("Reading pending from NVM error:%d", pending_ret);
Expand Down Expand Up @@ -1031,6 +1033,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 Expand Up @@ -1112,7 +1124,8 @@ void thread_joiner_pending_config_activate(int8_t interface_id)

if (master_key_ptr && memcmp(master_key_ptr,link_configuration->master_key,16) != 0) {
this->configuration_ptr->key_sequence = 0;
thread_nvm_store_seq_counter_write(this->configuration_ptr->key_sequence);
// if write fails, keep going...
(void)thread_nvm_store_seq_counter_write(this->configuration_ptr->key_sequence);
}

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

uint64_t thread_joiner_application_pending_config_timestamp_get(int8_t interface_id)
bool thread_joiner_application_pending_delay_timer_in_sync(int8_t interface_id)
{
thread_joiner_t *this = thread_joiner_find(interface_id);
if (!this || !this->pending_configuration_ptr) {
return false;
}
return this->pending_set_in_sync;
}

uint64_t thread_joiner_application_pending_config_timestamp_get(int8_t interface_id)
{
thread_joiner_t *this = thread_joiner_find(interface_id);
if (!this || !this->pending_configuration_ptr || !this->pending_set_in_sync) {
return 0;
}
return this->pending_configuration_ptr->timestamp;
Expand All @@ -1217,6 +1239,7 @@ int thread_joiner_application_pending_config_enable(int8_t interface_id, uint32_
return -1;
}
this->pending_configuration_ptr->timeout_in_ms = timeout_in_ms;
this->pending_set_in_sync = true;

if(this->pending_configuration_ptr->timeout_in_ms > THREAD_MAX_DELAY_TIMER_SECONDS*1000) {
this->pending_configuration_ptr->timeout_in_ms = THREAD_MAX_DELAY_TIMER_SECONDS*1000;
Expand Down
Loading

0 comments on commit 2cef8ac

Please sign in to comment.