@@ -154,33 +154,37 @@ uint8_t *thread_management_key_request_with_sequence(int8_t interface_id, uint8_
154
154
if (!linkConfiguration ) {
155
155
return NULL ;
156
156
}
157
+ //tr_debug("MLE key request by sequence id %"PRIu8" seq %"PRIu32, keyId, keySequnce);
157
158
158
159
cur = protocol_stack_interface_info_get_by_id (interface_id );
159
- if (cur && cur -> thread_info ) {
160
- if (cur -> thread_info -> masterSecretMaterial .valid_Info ) {
161
- if (keySequnce == linkConfiguration -> key_sequence ) {
162
- if (mle_service_security_default_key_id_get (interface_id ) == keyId ) {
163
- keyPtr = mle_service_security_default_key_get (interface_id );
164
- }
165
- } else if (keySequnce == (linkConfiguration -> key_sequence + 1 )) {
166
- if (mle_service_security_next_key_id_get (interface_id ) == keyId ) {
167
- keyPtr = mle_service_security_next_key_get (interface_id );
168
- }
169
- }
170
-
171
- if (!keyPtr ) {
172
- tr_debug ("Gen temporary key id %" PRIu8 " seq %" PRIu32 , keyId , keySequnce );
173
- thread_key_get (linkConfiguration -> master_key , cur -> thread_info -> masterSecretMaterial .historyKey , keySequnce );
174
- cur -> thread_info -> masterSecretMaterial .historyKeyId = keyId ;
175
- cur -> thread_info -> masterSecretMaterial .historyKeyValid = false;
176
- keyPtr = cur -> thread_info -> masterSecretMaterial .historyKey ;
177
- }
160
+ if (!cur || !cur -> thread_info ) {
161
+ return NULL ;
162
+ }
163
+ if (!cur -> thread_info -> masterSecretMaterial .valid_Info ) {
164
+ return NULL ;
165
+ }
166
+ if (keySequnce == linkConfiguration -> key_sequence ) {
167
+ if (mle_service_security_default_key_id_get (interface_id ) == keyId ) {
168
+ keyPtr = mle_service_security_default_key_get (interface_id );
169
+ }
170
+ } else if (keySequnce == (linkConfiguration -> key_sequence + 1 )) {
171
+ if (mle_service_security_next_key_id_get (interface_id ) == keyId ) {
172
+ keyPtr = mle_service_security_next_key_get (interface_id );
178
173
}
179
174
}
175
+
176
+ if (!keyPtr ) {
177
+ tr_debug ("Gen temporary key id %" PRIu8 " seq %" PRIu32 , keyId , keySequnce );
178
+ thread_key_get (linkConfiguration -> master_key , cur -> thread_info -> masterSecretMaterial .historyKey , keySequnce );
179
+ cur -> thread_info -> masterSecretMaterial .historyKeyId = keyId ;
180
+ cur -> thread_info -> masterSecretMaterial .historyKeyValid = false;
181
+ keyPtr = cur -> thread_info -> masterSecretMaterial .historyKey ;
182
+ }
180
183
return keyPtr ;
181
184
}
182
185
uint8_t * thread_mle_service_security_notify_cb (int8_t interface_id , mle_security_event_t event , uint8_t keyId )
183
186
{
187
+ (void )keyId ;
184
188
protocol_interface_info_entry_t * interface = protocol_stack_interface_info_get_by_id (interface_id );
185
189
if (!interface ) {
186
190
return NULL ;
@@ -199,7 +203,7 @@ uint8_t * thread_mle_service_security_notify_cb(int8_t interface_id, mle_securit
199
203
break ;
200
204
201
205
case MLE_SEC_UNKNOWN_KEY :
202
- return thread_management_key_request ( interface_id , keyId ) ;
206
+ return NULL ;
203
207
}
204
208
return NULL ;
205
209
}
@@ -362,17 +366,22 @@ bool thread_connectivity_tlv_parse(uint8_t *ptr, uint16_t dataLength, thread_con
362
366
return false;
363
367
}
364
368
365
- void thread_calculate_key_guard_timer (protocol_interface_info_entry_t * cur , link_configuration_s * linkConfiguration , bool is_init )
369
+ void thread_key_guard_timer_calculate (protocol_interface_info_entry_t * cur , link_configuration_s * linkConfiguration , bool is_init )
366
370
{
367
371
uint32_t key_rotation = linkConfiguration ? linkConfiguration -> key_rotation : 0 ;
368
372
369
- if (is_init && key_rotation < 3600 ) {
373
+ if (is_init && key_rotation < 1 ) {
370
374
tr_warn ("Attempted to set key rotation time smaller than 1 hour." );
371
- key_rotation = 3600 ;
375
+ key_rotation = 1 ;
372
376
}
373
377
374
- cur -> thread_info -> masterSecretMaterial .keyRotation = key_rotation ;
375
- cur -> thread_info -> masterSecretMaterial .keySwitchGuardTimer = is_init ? 0 : (key_rotation * 0.93 );
378
+ cur -> thread_info -> masterSecretMaterial .keyRotation = key_rotation * 3600 ; // setting value is hours converting to seconds
379
+ cur -> thread_info -> masterSecretMaterial .keySwitchGuardTimer = is_init ? 0 : (key_rotation * 3600 * 0.93 );
380
+ }
381
+
382
+ void thread_key_guard_timer_reset (protocol_interface_info_entry_t * cur )
383
+ {
384
+ cur -> thread_info -> masterSecretMaterial .keySwitchGuardTimer = 0 ;
376
385
}
377
386
378
387
thread_leader_data_t * thread_leader_data_generate (void )
@@ -932,7 +941,7 @@ static void thread_key_switch_timer(protocol_interface_info_entry_t *cur, uint16
932
941
933
942
tr_debug ("thrKeyRotation == 0: sync key material by %" PRIu32 , linkConfiguration -> key_sequence + 1 );
934
943
thread_management_key_sets_calc (cur , linkConfiguration , linkConfiguration -> key_sequence + 1 );
935
- thread_calculate_key_guard_timer (cur , linkConfiguration , false);
944
+ thread_key_guard_timer_calculate (cur , linkConfiguration , false);
936
945
}
937
946
}
938
947
0 commit comments