Skip to content

Commit 389fab0

Browse files
author
Tero Heinonen
authored
MLE parent request timeout fixes (#1676)
- More exact timeout values for parent request timeouts - Added delay for parent request send
1 parent feb1784 commit 389fab0

File tree

4 files changed

+56
-12
lines changed

4 files changed

+56
-12
lines changed

source/6LoWPAN/Thread/thread_config.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,15 @@
307307
*/
308308
#define THREAD_PROACTIVE_AN_SEND_DELAY 2
309309

310+
/*
311+
* Parent response wait time (in 100ms) when "R" bit is set in scan mask TLV (rounded up from 0.75 seconds)
312+
*/
313+
#define THREAD_PARENT_REQ_SCANMASK_R_TIMEOUT 9
314+
315+
/*
316+
* Parent response wait time (in 100ms) when both "R" and "E" bit is set in scan mask TLV (rounded up from 1.25 seconds)
317+
*/
318+
#define THREAD_PARENT_REQ_SCANMASK_RE_TIMEOUT 15
310319
/**
311320
* Build time flag to enable THCI special traces for test harness purposes
312321
*/

source/6LoWPAN/Thread/thread_host_bootstrap.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,20 @@ static int thread_parent_request_build(protocol_interface_info_entry_t *cur)
227227
return -1;
228228
}
229229

230+
timeout.retrans_max = THREAD_PARENT_REQUEST_MAX_RETRY_CNT;
231+
timeout.timeout_init = THREAD_PARENT_REQ_SCANMASK_R_TIMEOUT;
232+
timeout.timeout_max = THREAD_PARENT_REQ_SCANMASK_RE_TIMEOUT;
233+
timeout.delay = MLE_STANDARD_RESPONSE_DELAY;
234+
230235
if (cur->thread_info->thread_attached_state == THREAD_STATE_REATTACH ||
231236
cur->thread_info->thread_attached_state == THREAD_STATE_REATTACH_RETRY ||
232237
cur->thread_info->thread_attached_state == THREAD_STATE_CONNECTED ||
233238
cur->thread_info->thread_attached_state == THREAD_STATE_CONNECTED_ROUTER) {
234239
// When doing re-attach End devices are immediately accepted as parents
235240
scanMask |= 0x40;
241+
timeout.timeout_init = THREAD_PARENT_REQ_SCANMASK_RE_TIMEOUT;
236242
}
243+
237244
thread_management_get_current_keysequence(cur->id, &keySequence);
238245
mle_service_msg_update_security_params(buf_id, 5, 2, keySequence);
239246

@@ -256,19 +263,17 @@ static int thread_parent_request_build(protocol_interface_info_entry_t *cur)
256263
if (mle_service_update_length_by_ptr(buf_id,ptr)!= 0) {
257264
tr_debug("Buffer overflow at message write");
258265
}
259-
timeout.retrans_max = THREAD_PARENT_REQUEST_MAX_RETRY_CNT;
260-
timeout.timeout_init = 1;
261-
timeout.timeout_max = 2;
262-
timeout.delay = MLE_NO_DELAY;
266+
263267
cur->nwk_nd_re_scan_count = 1;
268+
264269
mle_service_set_packet_callback(buf_id, thread_parent_discover_timeout_cb);
265270
if (cur->thread_info->thread_attached_state == THREAD_STATE_NETWORK_DISCOVER) {
266271
mle_service_interface_receiver_handler_update(cur->id, thread_mle_parent_discover_receive_cb);
267272
} else {
268273
mle_service_interface_receiver_handler_update(cur->id, thread_general_mle_receive_cb);
269274
}
270275

271-
mle_service_set_msg_timeout_parameters(buf_id, &timeout);
276+
mle_service_set_msg_timeout_parameters_fast(buf_id, &timeout);
272277
mle_service_send_message(buf_id);
273278
return 0;
274279
}

source/Service_Libs/mle_service/mle_service.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,22 +1210,41 @@ int mle_service_message_tail_get(uint16_t msgId, uint16_t tail_length)
12101210
return mle_service_buffer_tail_get(msgId,tail_length);
12111211
}
12121212

1213-
int mle_service_set_msg_timeout_parameters(uint16_t msgId, mle_message_timeout_params_t *timeout_params)
1213+
static int mle_service_timeout_fill(uint16_t msgId, mle_message_timeout_params_t *timeout_params, bool timeout_in_seconds)
12141214
{
12151215
mle_service_msg_buf_t *buffer = mle_service_buffer_find(msgId);
12161216

12171217
if (!buffer) {
12181218
return -1;
12191219
}
12201220

1221-
buffer->timeout_init = randLIB_randomise_base(timeout_params->timeout_init * 10, MLE_RAND_LOW, MLE_RAND_HIGH);
1222-
buffer->timeout = buffer->timeout_init;
1223-
buffer->timeout_max = timeout_params->timeout_max * 10;
1221+
buffer->timeout_max = timeout_params->timeout_max;
12241222
buffer->retrans_max = timeout_params->retrans_max;
12251223
buffer->delayed_response = timeout_params->delay;
1224+
buffer->timeout_init = timeout_params->timeout_init;
1225+
1226+
if (timeout_in_seconds) {
1227+
buffer->timeout_max = buffer->timeout_max * 10;
1228+
buffer->timeout_init = buffer->timeout_init * 10;
1229+
}
1230+
1231+
buffer->timeout_init = randLIB_randomise_base(buffer->timeout_init, MLE_RAND_LOW, MLE_RAND_HIGH);
1232+
1233+
buffer->timeout = buffer->timeout_init;
1234+
12261235
return 0;
12271236
}
12281237

1238+
int mle_service_set_msg_timeout_parameters(uint16_t msgId, mle_message_timeout_params_t *timeout_params)
1239+
{
1240+
return mle_service_timeout_fill(msgId, timeout_params, true);
1241+
}
1242+
1243+
int mle_service_set_msg_timeout_parameters_fast(uint16_t msgId, mle_message_timeout_params_t *timeout_params)
1244+
{
1245+
return mle_service_timeout_fill(msgId, timeout_params, false);
1246+
}
1247+
12291248
int mle_service_set_msg_token_bucket_priority(uint16_t msgId)
12301249
{
12311250
mle_service_msg_buf_t *buffer = mle_service_buffer_find(msgId);

source/Service_Libs/mle_service/mle_service_api.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ typedef struct {
126126
*
127127
*/
128128
typedef struct {
129-
uint16_t timeout_init; /*!< Define start timeout in seconds */
130-
uint16_t timeout_max; /*!< Define max timeout time in seconds */
129+
uint16_t timeout_init; /*!< Define start timeout */
130+
uint16_t timeout_max; /*!< Define max timeout time */
131131
uint8_t retrans_max; /*!< Define max packet TX count */
132132
uint8_t delay; /*!< 100ms Ticks for random delay */
133133
} mle_message_timeout_params_t;
@@ -583,14 +583,25 @@ int mle_service_set_msg_panid(uint16_t msgId, uint16_t panid);
583583
/**
584584
* Set messages timeout parameters.
585585
*
586-
* Messages timeout parameters define messages TX count and init timeout and max timeout values is messages delayed.
586+
* Struct timeout_params defines messages retransmission times in seconds, retransmission count and sending delay.
587587
* Delayed message will affect random time between 100-900ms
588588
*
589589
* \param msgId Message Id.
590590
* \param timeout_params messages transmission parameters
591591
*/
592592
int mle_service_set_msg_timeout_parameters(uint16_t msgId, mle_message_timeout_params_t *timeout_params);
593593

594+
/**
595+
* Set messages timeout parameters.
596+
*
597+
* Struct timeout_params defines messages retransmission times in 100ms, retransmission count and sending delay.
598+
* Delayed message will affect random time between 100-900ms
599+
*
600+
* \param msgId Message Id.
601+
* \param timeout_params messages transmission parameters
602+
*/
603+
int mle_service_set_msg_timeout_parameters_fast(uint16_t msgId, mle_message_timeout_params_t *timeout_params);
604+
594605
int mle_service_set_msg_rf_channel(uint16_t msgId, uint8_t channel);
595606

596607
int mle_service_set_msg_link_layer_security_mode(uint16_t msgId, bool use_key_id_mode_2);

0 commit comments

Comments
 (0)