Skip to content

Commit

Permalink
Merge branch 'master' into koli
Browse files Browse the repository at this point in the history
* master: (22 commits)
  Allow MLE entry forced saving to MAC (ARMmbed#1600)
  Update router id sequence number in router sync (ARMmbed#1594)
  Read the short addr as 16-bit value before calling mac api (ARMmbed#1585)
  purge old partition data when child id response is received (ARMmbed#1588)
  Remove unnecessary call to mac (ARMmbed#1583)
  Fix uninitialised memory defect found by valgrind (ARMmbed#1582)
  Update Thread publishing during address change (ARMmbed#1581)
  Send new a/sd immediately after address change (ARMmbed#1576)
  added check for parent info before processing child update (ARMmbed#1577)
  implemented Sleepy End Device child update requests. (ARMmbed#1570)
  Flag check updated. (ARMmbed#1572)
  Update socket_api_test.cpp
  Update socket_api_test.cpp
  ML-EID is now added to address registration tlv. (ARMmbed#1565)
  unittest fix for newer release of cpputest
  Add new function to unit tests
  Review correction
  Move indirect queue size public API to net_interface
  Review corrections
  Increase Thread SED buffer size for big packets
  ...
  • Loading branch information
Jarkko Paso committed Mar 8, 2018
2 parents 8166585 + b69ba04 commit d119df9
Show file tree
Hide file tree
Showing 35 changed files with 609 additions and 311 deletions.
17 changes: 17 additions & 0 deletions nanostack/net_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,23 @@ void arm_print_protocols2(void (*print_fn)(const char *fmt, ...), char sep);
*
*/
extern void net_get_version_information(uint8_t *ptr);

/**
* \brief Set buffer size for sleepy device parent.
*
* This function can be used to set sleepy device parent buffer size and packet threshold.
*
* Note! In Thread mode parent buffer size is automatically set during Thread initialization.
*
* \param big_packet_threshold Indicate how long packets are considered big. For Thread, must be 106 bytes.
* \param small_packets_per_child_count Number of small packets stored for each sleepy children. For Thread, must be at least 1.
* \param big_packets_total_count Total number of big packets parent can store for all sleepy children. For Thread, must be at least 1.
* \return 0 on success, <0 on errors.
*/

extern int arm_nwk_sleepy_device_parent_buffer_size_set(int8_t interface_id, uint16_t big_packet_threshold, uint16_t small_packets_per_child_count, uint16_t big_packets_total_count);


#ifdef __cplusplus
}
#endif
Expand Down
14 changes: 14 additions & 0 deletions nanostack/thread_management_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,20 @@ int thread_management_network_certificate_set(int8_t interface_id, const unsigne
*/
int thread_management_partition_weighting_set(int8_t interface_id, uint8_t partition_weighting);

/**
* Set Thread Sleepy End Device parent packet buffer size.
*
* This function can be used to adjust count of packets SED parent is storing.
*
* \param interface_id Network interface ID.
* \param small_packets_per_child_count Number of small packets parent is storing for each SED.
* \param big_packets_total_count Number of big packets parent can store for all SEDs.
*
* \return 0, OK.
* \return <0 fail.
*/
int thread_management_sed_parent_buffer_size_set(int8_t interface_id, uint16_t small_packets_per_child_count, uint16_t big_packets_total_count);

#ifdef __cplusplus
}
#endif
Expand Down
12 changes: 6 additions & 6 deletions source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ static int mle_router_accept_request_build(protocol_interface_info_entry_t *cur,

static void protocol_6lowpan_link_reject_handler(protocol_interface_info_entry_t *cur, uint8_t *ll64)
{
mle_neigh_table_entry_t *entry_temp = mle_class_get_entry_by_ll64(cur->id, 0, ll64, false);
mle_neigh_table_entry_t *entry_temp = mle_class_get_entry_by_ll64(cur->id, 0, ll64, false, NULL);
tr_debug("MLE link reject");
if (entry_temp) {
mle_class_remove_entry(cur->id, entry_temp);
Expand Down Expand Up @@ -1081,7 +1081,7 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
mle_6lowpan_data->link_req_token_bucket--;
} else {
//Update only old information based on link request
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, false);
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, false, NULL);
if (entry_temp) {
mle_neigh_time_and_mode_update(entry_temp,mle_msg->data_ptr, mle_msg->data_length);
mle_neigh_entry_update_by_mle_tlv_list(interface_id, entry_temp, mle_msg->data_ptr, mle_msg->data_length, cur->mac, own_mac16);
Expand Down Expand Up @@ -1118,12 +1118,12 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml

tr_debug("Accept & Request");

entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, false);
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, false, NULL);

if (!entry_temp) {
// If there is space for neighbors try to allocate new entry
if (mle_6lowpan_neighbor_limit_check(interface_id, mle_msg, true)) {
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, true);
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, true, NULL);
}
}

Expand Down Expand Up @@ -1185,7 +1185,7 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
mode = *t_ptr;
}

entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, false);
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, false, NULL);
if (!entry_temp) {
if ((mode & MLE_DEV_MASK) == MLE_FFD_DEV) {
// If there is space for neighbors synchronizes to new router
Expand Down Expand Up @@ -2787,7 +2787,7 @@ bool lowpan_neighbour_data_clean(int8_t interface_id, const uint8_t *link_local_
{
bool return_value = false;
#ifndef NO_MLE
mle_neigh_table_entry_t * neigh_entry = mle_class_get_entry_by_ll64(interface_id, 0, link_local_address, false);
mle_neigh_table_entry_t * neigh_entry = mle_class_get_entry_by_ll64(interface_id, 0, link_local_address, false, NULL);
if (neigh_entry) {
//Remove entry
if (neigh_entry->priorityFlag) {
Expand Down
8 changes: 5 additions & 3 deletions source/6LoWPAN/MAC/mac_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,9 @@ void mac_helper_coordinator_address_set(protocol_interface_info_entry_t *interfa
if (adr_type == ADDR_802_15_4_SHORT) {
memcpy(interface->mac_parameters->mac_cordinator_info.mac_mlme_coord_address, adr_ptr, 2);
interface->mac_parameters->mac_cordinator_info.cord_adr_mode = MAC_ADDR_MODE_16_BIT;
uint16_t short_addr = common_read_16_bit(interface->mac_parameters->mac_cordinator_info.mac_mlme_coord_address);
set_req.attr = macCoordShortAddress;
set_req.value_pointer = &interface->mac_parameters->mac_cordinator_info.mac_mlme_coord_address;
set_req.value_pointer = &short_addr;
set_req.value_size = 2;
} else if (adr_type == ADDR_802_15_4_LONG) {
memcpy(interface->mac_parameters->mac_cordinator_info.mac_mlme_coord_address, adr_ptr, 8);
Expand Down Expand Up @@ -838,13 +839,14 @@ void mac_helper_device_description_write(protocol_interface_info_entry_t *cur, m
device_desc->FrameCounter = frame_counter;
}

void mac_helper_devicetable_set(const mlme_device_descriptor_t *device_desc, protocol_interface_info_entry_t *cur, uint8_t attribute_index, uint8_t keyID)
void mac_helper_devicetable_set(const mlme_device_descriptor_t *device_desc, protocol_interface_info_entry_t *cur, uint8_t attribute_index, uint8_t keyID, bool force_set)

{
if (!cur->mac_api) {
return;
}

if (cur->mac_parameters->SecurityEnabled && cur->mac_parameters->mac_default_key_index != keyID) {
if (!force_set && cur->mac_parameters->SecurityEnabled && cur->mac_parameters->mac_default_key_index != keyID) {
tr_debug("Do not set counter by index %u != %u", cur->mac_parameters->mac_default_key_index, keyID);
return;
}
Expand Down
3 changes: 1 addition & 2 deletions source/6LoWPAN/MAC/mac_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ void mac_helper_devicetable_remove(struct mac_api_s *mac_api, uint8_t attribute_

void mac_helper_device_description_write(struct protocol_interface_info_entry *cur, mlme_device_descriptor_t *device_desc, uint8_t *mac64, uint16_t mac16, uint32_t frame_counter, bool exempt);

void mac_helper_devicetable_set(const mlme_device_descriptor_t *device_dec, struct protocol_interface_info_entry *cur, uint8_t attribute_index, uint8_t keyID);

void mac_helper_devicetable_set(const mlme_device_descriptor_t *device_dec, struct protocol_interface_info_entry *cur, uint8_t attribute_index, uint8_t keyID, bool force_set);
int8_t mac_helper_mac_mlme_max_retry_set(int8_t interface_id, uint8_t mac_retry_set);

#endif // MAC_HELPER_H
8 changes: 5 additions & 3 deletions source/6LoWPAN/MAC/mac_pairwise_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ int mac_pairwise_key_interface_unregister(int8_t interface_id)
int mac_pairwise_key_add(int8_t interface_id, uint32_t valid_life_time, const uint8_t eui64[static 8], const uint8_t key[static 16])
{
protocol_interface_info_entry_t *interface = protocol_stack_interface_info_get_by_id(interface_id);
bool new_entry_created;

if (!interface || !interface->mac_api) {
return -1;
}
Expand All @@ -264,7 +266,7 @@ int mac_pairwise_key_add(int8_t interface_id, uint32_t valid_life_time, const ui
}

//Allocate mle entry
mle_neigh_table_entry_t *mle_entry = mle_class_get_entry_by_mac64(interface_id, 0, eui64, true);
mle_neigh_table_entry_t *mle_entry = mle_class_get_entry_by_mac64(interface_id, 0, eui64, true, &new_entry_created);
if (!mle_entry) {
return -1;
}
Expand All @@ -283,7 +285,7 @@ int mac_pairwise_key_add(int8_t interface_id, uint32_t valid_life_time, const ui

mlme_device_descriptor_t device_desc;
mac_helper_device_description_write(interface, &device_desc, mle_entry->mac64, mle_entry->short_adr,0, false);
mac_helper_devicetable_set(&device_desc, interface,mle_entry->attribute_index, interface->mac_parameters->mac_default_key_index);
mac_helper_devicetable_set(&device_desc, interface,mle_entry->attribute_index, interface->mac_parameters->mac_default_key_index, new_entry_created);

//set key descriptor
if (mac_helper_security_pairwisekey_set(interface, key, eui64, key_desc->key_decriptor_attribute) != 0) {
Expand All @@ -309,7 +311,7 @@ int mac_pairwise_key_del(int8_t interface_id, const uint8_t eui64[static 8])
return -1;
}
//Get from mle
mle_neigh_table_entry_t *mle_entry = mle_class_get_entry_by_mac64(interface_id, 0, eui64, true);
mle_neigh_table_entry_t *mle_entry = mle_class_get_entry_by_mac64(interface_id, 0, eui64, true, NULL);
if (!mle_entry) {
return -1;
}
Expand Down
117 changes: 6 additions & 111 deletions source/6LoWPAN/Thread/thread_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ static void thread_bootsrap_network_discovery_failure(int8_t interface_id);

static void thread_neighbor_remove(int8_t interface_id, mle_neigh_table_entry_t *cur);
static void thread_bootsrap_network_join_start(struct protocol_interface_info_entry *cur_interface, discovery_response_list_t *nwk_info);
static int8_t thread_child_keep_alive(int8_t interface_id, const uint8_t *mac64);



Expand All @@ -134,37 +133,6 @@ static void thread_neighbor_remove(int8_t interface_id, mle_neigh_table_entry_t
thread_reset_neighbour_info(cur_interface, cur);
}


static bool thread_child_keep_alive_callback(int8_t interface_id, uint16_t msgId, bool usedAllRetries)
{
uint8_t mac64[8];
uint8_t *ll64_ptr = mle_service_get_msg_destination_address_pointer(msgId);

memcpy(mac64, ll64_ptr + 8, 8);
mac64[0] ^= 2;

mle_neigh_table_entry_t *neig_info = mle_class_get_by_link_address(interface_id, mac64, ADDR_802_15_4_LONG);

if (!neig_info) {
return false;//Why entry is removed before timeout??
}


if (neig_info->ttl > MLE_TABLE_CHALLENGE_TIMER) {
return false;
}


if (usedAllRetries) {

//GET entry
mle_class_remove_entry(interface_id, neig_info);
return false;
}

return true;
}

int8_t thread_mle_class_init(int8_t interface_id)
{
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
Expand All @@ -182,7 +150,7 @@ int8_t thread_mle_class_init(int8_t interface_id)
return -1;
}

if (mle_class_init(interface_id, buffer.device_decription_table_size - 1, &thread_neighbor_remove, &thread_child_keep_alive, &thread_interface_is_active) != 0) {
if (mle_class_init(interface_id, buffer.device_decription_table_size - 1, &thread_neighbor_remove, &thread_host_bootstrap_child_update, &thread_interface_is_active) != 0) {
return -1;
}

Expand Down Expand Up @@ -231,68 +199,6 @@ uint8_t thread_mode_get_by_interface_ptr(protocol_interface_info_entry_t *cur)
return mle_mode;
}

static int8_t thread_child_keep_alive(int8_t interface_id, const uint8_t *mac64)
{
mle_message_timeout_params_t timeout;
uint8_t ll64[16];
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
uint32_t keySequence;
uint16_t bufId;
uint8_t mode;
if (!cur) {
return -1;
}

if (!thread_info(cur)) {
return -1;
}

//routers do not send keep alive
if (thread_i_am_router(cur)){
return -1;
}

tr_debug("Child Keep Alive");
bufId = mle_service_msg_allocate(cur->id, 150 + 3 + 6 + 10, false,MLE_COMMAND_CHILD_UPDATE_REQUEST);
if (bufId == 0) {
return -1;
}

thread_management_get_current_keysequence(cur->id, &keySequence);
mle_service_msg_update_security_params(bufId, 5, 2, keySequence);
mode = thread_mode_get_by_interface_ptr(cur);

uint8_t *ptr = mle_service_get_data_pointer(bufId);
ptr = mle_general_write_source_address(ptr, cur);
ptr = mle_tlv_write_mode(ptr, mode);

ptr = thread_leader_data_tlv_write(ptr, cur);

//Set Addresss TLV
if ((mode & MLE_FFD_DEV) == 0) {
ptr = thread_address_registration_tlv_write(ptr, cur);
}

memcpy(ll64, ADDR_LINK_LOCAL_PREFIX, 8);
memcpy(&ll64[8], mac64, 8);
ll64[8] ^= 2;
if (mle_service_update_length_by_ptr(bufId,ptr)!= 0) {
tr_debug("Buffer overflow at message write");
}
timeout.retrans_max = 3;
timeout.timeout_init = 1;
timeout.timeout_max = 4;
timeout.delay = MLE_NO_DELAY;

//SET Destination address
mle_service_set_msg_destination_address(bufId, ll64);
//Set Callback
mle_service_set_packet_callback(bufId, thread_child_keep_alive_callback);
mle_service_set_msg_timeout_parameters(bufId, &timeout);
mle_service_send_message(bufId);
return 0;
}

/**
* Return lower (worse) of the two margins.
*/
Expand Down Expand Up @@ -1014,6 +920,7 @@ static void thread_interface_bootsrap_mode_init(protocol_interface_info_entry_t
cur->thread_info->thread_device_mode = THREAD_DEVICE_MODE_SLEEPY_END_DEVICE;
//SET Sleepy Host To RX on Idle mode for bootsrap
nwk_thread_host_control(cur, NET_HOST_RX_ON_IDLE, 0);
cur->thread_info->childUpdateReqTimer = 0.8 * cur->thread_info->host_link_timeout;
} else {
tr_debug("Set End node Mode");
cur->thread_info->thread_device_mode = THREAD_DEVICE_MODE_END_DEVICE;
Expand Down Expand Up @@ -1134,7 +1041,9 @@ void thread_tasklet(arm_event_s *event)

case THREAD_CHILD_UPDATE:
tr_debug_extra("Thread SM THREAD_CHILD_UPDATE");
thread_bootstrap_child_update(cur);
if (thread_info(cur)->thread_endnode_parent) {
thread_host_bootstrap_child_update(cur->id, cur->thread_info->thread_endnode_parent->mac64);
}
break;
case THREAD_ANNOUNCE_ACTIVE: {
tr_debug_extra("Thread SM THREAD_ANNOUNCE_ACTIVE");
Expand Down Expand Up @@ -2333,21 +2242,7 @@ void thread_bootstrap_stop(protocol_interface_info_entry_t *cur)

void thread_bootstrap_child_update_trig(protocol_interface_info_entry_t *cur)
{
if (cur->thread_info->thread_attached_state == THREAD_STATE_CONNECTED) {
if (cur->thread_info->thread_endnode_parent == NULL) {
return;
}

if (cur->thread_info->thread_endnode_parent->childUpdateProcessActive) {
//Set Pending if earlier proces is already started
cur->thread_info->thread_endnode_parent->childUpdatePending = true;
return;
}
//Trig event
cur->thread_info->thread_endnode_parent->childUpdatePending = false;
cur->thread_info->thread_endnode_parent->childUpdateProcessActive = true;
cur->thread_info->thread_endnode_parent->childUpdateProcessStatus = false;

if (cur->thread_info->thread_attached_state == THREAD_STATE_CONNECTED && cur->thread_info->thread_endnode_parent) {
thread_bootsrap_event_trig(THREAD_CHILD_UPDATE, cur->bootStrapId, ARM_LIB_HIGH_PRIORITY_EVENT);
}
}
Expand Down
17 changes: 14 additions & 3 deletions source/6LoWPAN/Thread/thread_border_router_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -884,9 +884,20 @@ int thread_border_router_publish(int8_t interface_id)
tr_debug("Border router old: %x, new: %x", cur->thread_info->localServerDataBase.registered_rloc16, rloc16);

if (cur->thread_info->localServerDataBase.publish_active) {
cur->thread_info->localServerDataBase.publish_pending = true;
tr_debug("Activate pending status for publish");
return 0;
if (rloc16 != cur->thread_info->localServerDataBase.registered_rloc16) {
/*
* Device short address has changed, cancel previous a/sd and a/as requests
* and start resubmit timer
* */
tr_debug("address changed, kill pending reuqests");
thread_management_client_pending_coap_request_kill(cur->id);
thread_border_router_resubmit_timer_set(interface_id, 5);
return 0;
} else {
cur->thread_info->localServerDataBase.publish_pending = true;
tr_debug("Activate pending status for publish");
return 0;
}
}

//Allocate Memory for Data
Expand Down
6 changes: 3 additions & 3 deletions source/6LoWPAN/Thread/thread_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ void thread_child_id_request_info_init(thread_pending_child_id_req_t *child_info
thread_pending_child_id_req_t *thread_child_id_request_allocate(void)
{
thread_pending_child_id_req_t *req = ns_dyn_mem_alloc(sizeof(thread_pending_child_id_req_t));
memset(req->eiid, 0 , 8);
thread_child_id_request_info_init(req);
return req;
}
Expand Down Expand Up @@ -880,7 +881,6 @@ static void thread_child_update_req_timer(protocol_interface_info_entry_t *cur,
if (cur->thread_info->childUpdateReqTimer == -1) {
return;
}

if (cur->thread_info->childUpdateReqTimer > seconds) {
cur->thread_info->childUpdateReqTimer -= seconds;
} else {
Expand Down Expand Up @@ -1712,7 +1712,8 @@ uint8_t *thread_address_registration_tlv_write(uint8_t *ptr, protocol_interface_
// Maximum length of address registrations
continue;
}
if (addr_ipv6_scope(e->address, cur) == IPV6_SCOPE_GLOBAL) {
if (addr_ipv6_scope(e->address, cur) == IPV6_SCOPE_GLOBAL || (addr_ipv6_scope(e->address, cur) == IPV6_SCOPE_REALM_LOCAL
&& !thread_addr_is_mesh_local_16(e->address, cur))) {
ctx = lowpan_context_get_by_address(&cur->lowpan_contexts, e->address);
if (ctx) {
//Write TLV to list
Expand All @@ -1725,7 +1726,6 @@ uint8_t *thread_address_registration_tlv_write(uint8_t *ptr, protocol_interface_
memcpy(ptr, e->address, 16);
ptr += 16;
*address_len_ptr += 17;

}
}
}
Expand Down
Loading

0 comments on commit d119df9

Please sign in to comment.