Skip to content

Commit f96db0c

Browse files
author
Jarkko Paso
authored
Merge pull request ARMmbed#1607 from ARMmbed/merge_MtoK
Merge mto k
2 parents 8166585 + 72bb71f commit f96db0c

36 files changed

+610
-312
lines changed

nanostack/net_interface.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,23 @@ void arm_print_protocols2(void (*print_fn)(const char *fmt, ...), char sep);
988988
*
989989
*/
990990
extern void net_get_version_information(uint8_t *ptr);
991+
992+
/**
993+
* \brief Set buffer size for sleepy device parent.
994+
*
995+
* This function can be used to set sleepy device parent buffer size and packet threshold.
996+
*
997+
* Note! In Thread mode parent buffer size is automatically set during Thread initialization.
998+
*
999+
* \param big_packet_threshold Indicate how long packets are considered big. For Thread, must be 106 bytes.
1000+
* \param small_packets_per_child_count Number of small packets stored for each sleepy children. For Thread, must be at least 1.
1001+
* \param big_packets_total_count Total number of big packets parent can store for all sleepy children. For Thread, must be at least 1.
1002+
* \return 0 on success, <0 on errors.
1003+
*/
1004+
1005+
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);
1006+
1007+
9911008
#ifdef __cplusplus
9921009
}
9931010
#endif

nanostack/thread_management_if.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,20 @@ int thread_management_network_certificate_set(int8_t interface_id, const unsigne
426426
*/
427427
int thread_management_partition_weighting_set(int8_t interface_id, uint8_t partition_weighting);
428428

429+
/**
430+
* Set Thread Sleepy End Device parent packet buffer size.
431+
*
432+
* This function can be used to adjust count of packets SED parent is storing.
433+
*
434+
* \param interface_id Network interface ID.
435+
* \param small_packets_per_child_count Number of small packets parent is storing for each SED.
436+
* \param big_packets_total_count Number of big packets parent can store for all SEDs.
437+
*
438+
* \return 0, OK.
439+
* \return <0 fail.
440+
*/
441+
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);
442+
429443
#ifdef __cplusplus
430444
}
431445
#endif

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ static int mle_router_accept_request_build(protocol_interface_info_entry_t *cur,
758758

759759
static void protocol_6lowpan_link_reject_handler(protocol_interface_info_entry_t *cur, uint8_t *ll64)
760760
{
761-
mle_neigh_table_entry_t *entry_temp = mle_class_get_entry_by_ll64(cur->id, 0, ll64, false);
761+
mle_neigh_table_entry_t *entry_temp = mle_class_get_entry_by_ll64(cur->id, 0, ll64, false, NULL);
762762
tr_debug("MLE link reject");
763763
if (entry_temp) {
764764
mle_class_remove_entry(cur->id, entry_temp);
@@ -1081,7 +1081,7 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
10811081
mle_6lowpan_data->link_req_token_bucket--;
10821082
} else {
10831083
//Update only old information based on link request
1084-
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, false);
1084+
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, false, NULL);
10851085
if (entry_temp) {
10861086
mle_neigh_time_and_mode_update(entry_temp,mle_msg->data_ptr, mle_msg->data_length);
10871087
mle_neigh_entry_update_by_mle_tlv_list(interface_id, entry_temp, mle_msg->data_ptr, mle_msg->data_length, cur->mac, own_mac16);
@@ -1118,12 +1118,12 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
11181118

11191119
tr_debug("Accept & Request");
11201120

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

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

@@ -1185,7 +1185,7 @@ void mle_6lowpan_message_handler(int8_t interface_id, mle_message_t *mle_msg, ml
11851185
mode = *t_ptr;
11861186
}
11871187

1188-
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, false);
1188+
entry_temp = mle_class_get_entry_by_ll64(interface_id, linkMargin, mle_msg->packet_src_address, false, NULL);
11891189
if (!entry_temp) {
11901190
if ((mode & MLE_DEV_MASK) == MLE_FFD_DEV) {
11911191
// If there is space for neighbors synchronizes to new router
@@ -2787,7 +2787,7 @@ bool lowpan_neighbour_data_clean(int8_t interface_id, const uint8_t *link_local_
27872787
{
27882788
bool return_value = false;
27892789
#ifndef NO_MLE
2790-
mle_neigh_table_entry_t * neigh_entry = mle_class_get_entry_by_ll64(interface_id, 0, link_local_address, false);
2790+
mle_neigh_table_entry_t * neigh_entry = mle_class_get_entry_by_ll64(interface_id, 0, link_local_address, false, NULL);
27912791
if (neigh_entry) {
27922792
//Remove entry
27932793
if (neigh_entry->priorityFlag) {

source/6LoWPAN/MAC/mac_helper.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,9 @@ void mac_helper_coordinator_address_set(protocol_interface_info_entry_t *interfa
432432
if (adr_type == ADDR_802_15_4_SHORT) {
433433
memcpy(interface->mac_parameters->mac_cordinator_info.mac_mlme_coord_address, adr_ptr, 2);
434434
interface->mac_parameters->mac_cordinator_info.cord_adr_mode = MAC_ADDR_MODE_16_BIT;
435+
uint16_t short_addr = common_read_16_bit(interface->mac_parameters->mac_cordinator_info.mac_mlme_coord_address);
435436
set_req.attr = macCoordShortAddress;
436-
set_req.value_pointer = &interface->mac_parameters->mac_cordinator_info.mac_mlme_coord_address;
437+
set_req.value_pointer = &short_addr;
437438
set_req.value_size = 2;
438439
} else if (adr_type == ADDR_802_15_4_LONG) {
439440
memcpy(interface->mac_parameters->mac_cordinator_info.mac_mlme_coord_address, adr_ptr, 8);
@@ -838,13 +839,14 @@ void mac_helper_device_description_write(protocol_interface_info_entry_t *cur, m
838839
device_desc->FrameCounter = frame_counter;
839840
}
840841

841-
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)
842+
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)
843+
842844
{
843845
if (!cur->mac_api) {
844846
return;
845847
}
846848

847-
if (cur->mac_parameters->SecurityEnabled && cur->mac_parameters->mac_default_key_index != keyID) {
849+
if (!force_set && cur->mac_parameters->SecurityEnabled && cur->mac_parameters->mac_default_key_index != keyID) {
848850
tr_debug("Do not set counter by index %u != %u", cur->mac_parameters->mac_default_key_index, keyID);
849851
return;
850852
}

source/6LoWPAN/MAC/mac_helper.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ void mac_helper_devicetable_remove(struct mac_api_s *mac_api, uint8_t attribute_
111111

112112
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);
113113

114-
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);
115-
114+
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);
116115
int8_t mac_helper_mac_mlme_max_retry_set(int8_t interface_id, uint8_t mac_retry_set);
117116

118117
#endif // MAC_HELPER_H

source/6LoWPAN/MAC/mac_pairwise_key.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ int mac_pairwise_key_interface_unregister(int8_t interface_id)
252252
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])
253253
{
254254
protocol_interface_info_entry_t *interface = protocol_stack_interface_info_get_by_id(interface_id);
255+
bool new_entry_created;
256+
255257
if (!interface || !interface->mac_api) {
256258
return -1;
257259
}
@@ -264,7 +266,7 @@ int mac_pairwise_key_add(int8_t interface_id, uint32_t valid_life_time, const ui
264266
}
265267

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

284286
mlme_device_descriptor_t device_desc;
285287
mac_helper_device_description_write(interface, &device_desc, mle_entry->mac64, mle_entry->short_adr,0, false);
286-
mac_helper_devicetable_set(&device_desc, interface,mle_entry->attribute_index, interface->mac_parameters->mac_default_key_index);
288+
mac_helper_devicetable_set(&device_desc, interface,mle_entry->attribute_index, interface->mac_parameters->mac_default_key_index, new_entry_created);
287289

288290
//set key descriptor
289291
if (mac_helper_security_pairwisekey_set(interface, key, eui64, key_desc->key_decriptor_attribute) != 0) {
@@ -309,7 +311,7 @@ int mac_pairwise_key_del(int8_t interface_id, const uint8_t eui64[static 8])
309311
return -1;
310312
}
311313
//Get from mle
312-
mle_neigh_table_entry_t *mle_entry = mle_class_get_entry_by_mac64(interface_id, 0, eui64, true);
314+
mle_neigh_table_entry_t *mle_entry = mle_class_get_entry_by_mac64(interface_id, 0, eui64, true, NULL);
313315
if (!mle_entry) {
314316
return -1;
315317
}

source/6LoWPAN/Thread/thread_bootstrap.c

Lines changed: 6 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ static void thread_bootsrap_network_discovery_failure(int8_t interface_id);
112112

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

117116

118117

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

137-
138-
static bool thread_child_keep_alive_callback(int8_t interface_id, uint16_t msgId, bool usedAllRetries)
139-
{
140-
uint8_t mac64[8];
141-
uint8_t *ll64_ptr = mle_service_get_msg_destination_address_pointer(msgId);
142-
143-
memcpy(mac64, ll64_ptr + 8, 8);
144-
mac64[0] ^= 2;
145-
146-
mle_neigh_table_entry_t *neig_info = mle_class_get_by_link_address(interface_id, mac64, ADDR_802_15_4_LONG);
147-
148-
if (!neig_info) {
149-
return false;//Why entry is removed before timeout??
150-
}
151-
152-
153-
if (neig_info->ttl > MLE_TABLE_CHALLENGE_TIMER) {
154-
return false;
155-
}
156-
157-
158-
if (usedAllRetries) {
159-
160-
//GET entry
161-
mle_class_remove_entry(interface_id, neig_info);
162-
return false;
163-
}
164-
165-
return true;
166-
}
167-
168136
int8_t thread_mle_class_init(int8_t interface_id)
169137
{
170138
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
@@ -182,7 +150,7 @@ int8_t thread_mle_class_init(int8_t interface_id)
182150
return -1;
183151
}
184152

185-
if (mle_class_init(interface_id, buffer.device_decription_table_size - 1, &thread_neighbor_remove, &thread_child_keep_alive, &thread_interface_is_active) != 0) {
153+
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) {
186154
return -1;
187155
}
188156

@@ -231,68 +199,6 @@ uint8_t thread_mode_get_by_interface_ptr(protocol_interface_info_entry_t *cur)
231199
return mle_mode;
232200
}
233201

234-
static int8_t thread_child_keep_alive(int8_t interface_id, const uint8_t *mac64)
235-
{
236-
mle_message_timeout_params_t timeout;
237-
uint8_t ll64[16];
238-
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
239-
uint32_t keySequence;
240-
uint16_t bufId;
241-
uint8_t mode;
242-
if (!cur) {
243-
return -1;
244-
}
245-
246-
if (!thread_info(cur)) {
247-
return -1;
248-
}
249-
250-
//routers do not send keep alive
251-
if (thread_i_am_router(cur)){
252-
return -1;
253-
}
254-
255-
tr_debug("Child Keep Alive");
256-
bufId = mle_service_msg_allocate(cur->id, 150 + 3 + 6 + 10, false,MLE_COMMAND_CHILD_UPDATE_REQUEST);
257-
if (bufId == 0) {
258-
return -1;
259-
}
260-
261-
thread_management_get_current_keysequence(cur->id, &keySequence);
262-
mle_service_msg_update_security_params(bufId, 5, 2, keySequence);
263-
mode = thread_mode_get_by_interface_ptr(cur);
264-
265-
uint8_t *ptr = mle_service_get_data_pointer(bufId);
266-
ptr = mle_general_write_source_address(ptr, cur);
267-
ptr = mle_tlv_write_mode(ptr, mode);
268-
269-
ptr = thread_leader_data_tlv_write(ptr, cur);
270-
271-
//Set Addresss TLV
272-
if ((mode & MLE_FFD_DEV) == 0) {
273-
ptr = thread_address_registration_tlv_write(ptr, cur);
274-
}
275-
276-
memcpy(ll64, ADDR_LINK_LOCAL_PREFIX, 8);
277-
memcpy(&ll64[8], mac64, 8);
278-
ll64[8] ^= 2;
279-
if (mle_service_update_length_by_ptr(bufId,ptr)!= 0) {
280-
tr_debug("Buffer overflow at message write");
281-
}
282-
timeout.retrans_max = 3;
283-
timeout.timeout_init = 1;
284-
timeout.timeout_max = 4;
285-
timeout.delay = MLE_NO_DELAY;
286-
287-
//SET Destination address
288-
mle_service_set_msg_destination_address(bufId, ll64);
289-
//Set Callback
290-
mle_service_set_packet_callback(bufId, thread_child_keep_alive_callback);
291-
mle_service_set_msg_timeout_parameters(bufId, &timeout);
292-
mle_service_send_message(bufId);
293-
return 0;
294-
}
295-
296202
/**
297203
* Return lower (worse) of the two margins.
298204
*/
@@ -1014,6 +920,7 @@ static void thread_interface_bootsrap_mode_init(protocol_interface_info_entry_t
1014920
cur->thread_info->thread_device_mode = THREAD_DEVICE_MODE_SLEEPY_END_DEVICE;
1015921
//SET Sleepy Host To RX on Idle mode for bootsrap
1016922
nwk_thread_host_control(cur, NET_HOST_RX_ON_IDLE, 0);
923+
cur->thread_info->childUpdateReqTimer = 0.8 * cur->thread_info->host_link_timeout;
1017924
} else {
1018925
tr_debug("Set End node Mode");
1019926
cur->thread_info->thread_device_mode = THREAD_DEVICE_MODE_END_DEVICE;
@@ -1134,7 +1041,9 @@ void thread_tasklet(arm_event_s *event)
11341041

11351042
case THREAD_CHILD_UPDATE:
11361043
tr_debug_extra("Thread SM THREAD_CHILD_UPDATE");
1137-
thread_bootstrap_child_update(cur);
1044+
if (thread_info(cur)->thread_endnode_parent) {
1045+
thread_host_bootstrap_child_update(cur->id, cur->thread_info->thread_endnode_parent->mac64);
1046+
}
11381047
break;
11391048
case THREAD_ANNOUNCE_ACTIVE: {
11401049
tr_debug_extra("Thread SM THREAD_ANNOUNCE_ACTIVE");
@@ -2333,21 +2242,7 @@ void thread_bootstrap_stop(protocol_interface_info_entry_t *cur)
23332242

23342243
void thread_bootstrap_child_update_trig(protocol_interface_info_entry_t *cur)
23352244
{
2336-
if (cur->thread_info->thread_attached_state == THREAD_STATE_CONNECTED) {
2337-
if (cur->thread_info->thread_endnode_parent == NULL) {
2338-
return;
2339-
}
2340-
2341-
if (cur->thread_info->thread_endnode_parent->childUpdateProcessActive) {
2342-
//Set Pending if earlier proces is already started
2343-
cur->thread_info->thread_endnode_parent->childUpdatePending = true;
2344-
return;
2345-
}
2346-
//Trig event
2347-
cur->thread_info->thread_endnode_parent->childUpdatePending = false;
2348-
cur->thread_info->thread_endnode_parent->childUpdateProcessActive = true;
2349-
cur->thread_info->thread_endnode_parent->childUpdateProcessStatus = false;
2350-
2245+
if (cur->thread_info->thread_attached_state == THREAD_STATE_CONNECTED && cur->thread_info->thread_endnode_parent) {
23512246
thread_bootsrap_event_trig(THREAD_CHILD_UPDATE, cur->bootStrapId, ARM_LIB_HIGH_PRIORITY_EVENT);
23522247
}
23532248
}

source/6LoWPAN/Thread/thread_border_router_api.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -884,9 +884,20 @@ int thread_border_router_publish(int8_t interface_id)
884884
tr_debug("Border router old: %x, new: %x", cur->thread_info->localServerDataBase.registered_rloc16, rloc16);
885885

886886
if (cur->thread_info->localServerDataBase.publish_active) {
887-
cur->thread_info->localServerDataBase.publish_pending = true;
888-
tr_debug("Activate pending status for publish");
889-
return 0;
887+
if (rloc16 != cur->thread_info->localServerDataBase.registered_rloc16) {
888+
/*
889+
* Device short address has changed, cancel previous a/sd and a/as requests
890+
* and start resubmit timer
891+
* */
892+
tr_debug("address changed, kill pending reuqests");
893+
thread_management_client_pending_coap_request_kill(cur->id);
894+
thread_border_router_resubmit_timer_set(interface_id, 5);
895+
return 0;
896+
} else {
897+
cur->thread_info->localServerDataBase.publish_pending = true;
898+
tr_debug("Activate pending status for publish");
899+
return 0;
900+
}
890901
}
891902

892903
//Allocate Memory for Data

source/6LoWPAN/Thread/thread_common.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ void thread_child_id_request_info_init(thread_pending_child_id_req_t *child_info
717717
thread_pending_child_id_req_t *thread_child_id_request_allocate(void)
718718
{
719719
thread_pending_child_id_req_t *req = ns_dyn_mem_alloc(sizeof(thread_pending_child_id_req_t));
720+
memset(req->eiid, 0 , 8);
720721
thread_child_id_request_info_init(req);
721722
return req;
722723
}
@@ -880,7 +881,6 @@ static void thread_child_update_req_timer(protocol_interface_info_entry_t *cur,
880881
if (cur->thread_info->childUpdateReqTimer == -1) {
881882
return;
882883
}
883-
884884
if (cur->thread_info->childUpdateReqTimer > seconds) {
885885
cur->thread_info->childUpdateReqTimer -= seconds;
886886
} else {
@@ -1712,7 +1712,8 @@ uint8_t *thread_address_registration_tlv_write(uint8_t *ptr, protocol_interface_
17121712
// Maximum length of address registrations
17131713
continue;
17141714
}
1715-
if (addr_ipv6_scope(e->address, cur) == IPV6_SCOPE_GLOBAL) {
1715+
if (addr_ipv6_scope(e->address, cur) == IPV6_SCOPE_GLOBAL || (addr_ipv6_scope(e->address, cur) == IPV6_SCOPE_REALM_LOCAL
1716+
&& !thread_addr_is_mesh_local_16(e->address, cur))) {
17161717
ctx = lowpan_context_get_by_address(&cur->lowpan_contexts, e->address);
17171718
if (ctx) {
17181719
//Write TLV to list
@@ -1725,7 +1726,6 @@ uint8_t *thread_address_registration_tlv_write(uint8_t *ptr, protocol_interface_
17251726
memcpy(ptr, e->address, 16);
17261727
ptr += 16;
17271728
*address_len_ptr += 17;
1728-
17291729
}
17301730
}
17311731
}

0 commit comments

Comments
 (0)