Skip to content

Commit 0eea30d

Browse files
delay Join_ent.ntf sending by 50 ms (ARMmbed#1860)
1 parent dac1d99 commit 0eea30d

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

source/6LoWPAN/Thread/thread_constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
#define THREAD_DEFAULT_KEY_SWITCH_GUARD_TIME 624 // Hours
146146
#define THREAD_DEFAULT_KEY_ROTATION 672 // Hours
147147
#define THREAD_COMMISSIONER_KEEP_ALIVE_INTERVAL 50000 // Default thread commissioner keep-alive message interval (milliseconds)
148+
#define THREAD_DELAY_JOIN_ENT 50 // Minimum delay for Joiner router before sending joiner entrust (milliseconds)
148149

149150
#define THREAD_FAILED_CHILD_TRANSMISSIONS 4
150151
#define THREAD_FAILED_ROUTER_TRANSMISSIONS 4

source/6LoWPAN/Thread/thread_management_server.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ typedef struct announce {
100100
typedef struct thread_management_server {
101101
scan_query_t *scan_ptr;
102102
announce_t *announce_ptr;
103+
timeout_t *join_ent_timer;
104+
uint8_t destination_address[16];
105+
uint8_t one_time_key[16];
103106
uint16_t relay_port_joiner;
104107
uint16_t external_commissioner_port;
105108
int8_t interface_id;
@@ -994,7 +997,6 @@ static int thread_management_server_energy_scan_cb(int8_t service_id, uint8_t so
994997
return -1;
995998
}
996999

997-
9981000
static void thread_announce_timeout_cb(void* arg)
9991001
{
10001002
link_configuration_s *linkConfiguration;
@@ -1132,6 +1134,9 @@ int thread_management_server_init(int8_t interface_id)
11321134
this->relay_port_joiner = 0;
11331135
this->scan_ptr = NULL;
11341136
this->announce_ptr = NULL;
1137+
this->join_ent_timer = NULL;
1138+
memset(this->destination_address,0,16);
1139+
memset(this->one_time_key,0,16);
11351140
this->external_commissioner_port = THREAD_COMMISSIONING_PORT;
11361141

11371142
#ifdef HAVE_THREAD_ROUTER
@@ -1312,6 +1317,19 @@ static int thread_management_server_entrust_send(thread_management_server_t *thi
13121317
ns_dyn_mem_free(response_ptr);
13131318
return 0;
13141319
}
1320+
1321+
static void thread_join_ent_timeout_cb(void *arg)
1322+
{
1323+
thread_management_server_t *this = arg;
1324+
if(!this || !this->join_ent_timer) {
1325+
return;
1326+
}
1327+
1328+
this->join_ent_timer = NULL;
1329+
thread_management_server_entrust_send(this, this->destination_address, this->one_time_key);
1330+
return;
1331+
}
1332+
13151333
void joiner_router_recv_commission_msg(void *cb_res)
13161334
{
13171335
socket_callback_t *sckt_data = 0;
@@ -1412,7 +1430,13 @@ static int thread_management_server_relay_tx_cb(int8_t service_id, uint8_t sourc
14121430
if (0 < thread_meshcop_tlv_find(request_ptr->payload_ptr, request_ptr->payload_len, MESHCOP_TLV_JOINER_ROUTER_KEK, &kek_ptr)) {
14131431
// KEK present in relay set pairwise key and send entrust
14141432
tr_debug("Kek received");
1415-
thread_management_server_entrust_send(this, destination_address.address, kek_ptr);
1433+
if (this->join_ent_timer) {
1434+
eventOS_timeout_cancel(this->join_ent_timer);
1435+
thread_management_server_entrust_send(this, this->destination_address, this->one_time_key);
1436+
}
1437+
memcpy(this->destination_address, destination_address.address, 16);
1438+
memcpy(this->one_time_key, kek_ptr, 16);
1439+
this->join_ent_timer = eventOS_timeout_ms(thread_join_ent_timeout_cb, THREAD_DELAY_JOIN_ENT, this);
14161440
}
14171441
tr_debug("Relay TX sendto addr:%s port:%d, length:%d", trace_ipv6(destination_address.address), port, udp_data_len);
14181442
thci_trace("joinerrouterJoinerDataRelayedOutbound");

0 commit comments

Comments
 (0)