@@ -79,7 +79,8 @@ const char *KEYS_FILE = "pae_keys";
79
79
typedef struct {
80
80
char network_name [33 ]; /**< Network name for keys */
81
81
sec_prot_gtk_keys_t * gtks ; /**< Link to GTKs */
82
- uint16_t pan_id ; /**< PAN ID for keys */
82
+ uint16_t new_pan_id ; /**< new PAN ID indicated by bootstrap */
83
+ uint16_t key_pan_id ; /**< PAN ID for keys */
83
84
bool updated : 1 ; /**< Network info has been updated */
84
85
} sec_prot_keys_nw_info_t ;
85
86
@@ -159,13 +160,6 @@ int8_t ws_pae_supp_authenticate(protocol_interface_info_entry_t *interface_ptr,
159
160
return -1 ;
160
161
}
161
162
162
- if (!dest_eui_64 ) {
163
- pae_supp -> sec_keys_nw_info .pan_id = dest_pan_id ;
164
- if (pae_supp -> nw_keys_used_cnt > 1 ) {
165
- pae_supp -> nw_keys_used_cnt = 1 ;
166
- }
167
- }
168
-
169
163
if (ws_pae_supp_nw_keys_valid_check (pae_supp , dest_pan_id ) >= 0 ) {
170
164
pae_supp -> auth_completed (interface_ptr , true);
171
165
return 0 ;
@@ -174,6 +168,16 @@ int8_t ws_pae_supp_authenticate(protocol_interface_info_entry_t *interface_ptr,
174
168
// Delete GTKs
175
169
sec_prot_keys_gtks_init (pae_supp -> sec_keys_nw_info .gtks );
176
170
171
+ /* PAN ID has changed, delete key data associated with border router
172
+ i.e PMK, PTK, EA-IE data (border router EUI-64) */
173
+ if (pae_supp -> sec_keys_nw_info .key_pan_id != 0xFFFF && pae_supp -> sec_keys_nw_info .key_pan_id != dest_pan_id ) {
174
+ sec_prot_keys_pmk_delete (& pae_supp -> entry .sec_keys );
175
+ sec_prot_keys_ptk_delete (& pae_supp -> entry .sec_keys );
176
+ sec_prot_keys_ptk_eui_64_delete (& pae_supp -> entry .sec_keys );
177
+ }
178
+
179
+ pae_supp -> sec_keys_nw_info .key_pan_id = dest_pan_id ;
180
+
177
181
// Prepare to receive new border router address
178
182
pae_supp -> new_br_eui_64_set = false;
179
183
@@ -203,8 +207,8 @@ int8_t ws_pae_supp_nw_info_set(protocol_interface_info_entry_t *interface_ptr, u
203
207
}
204
208
205
209
// PAN ID has been modified
206
- if (pan_id != 0xffff && pan_id != pae_supp -> sec_keys_nw_info .pan_id ) {
207
- pae_supp -> sec_keys_nw_info .pan_id = pan_id ;
210
+ if (pan_id != 0xffff && pan_id != pae_supp -> sec_keys_nw_info .new_pan_id ) {
211
+ pae_supp -> sec_keys_nw_info .new_pan_id = pan_id ;
208
212
pae_supp -> sec_keys_nw_info .updated = true;
209
213
}
210
214
@@ -350,7 +354,7 @@ static int8_t ws_pae_supp_nvm_nw_info_write(pae_supp_t *pae_supp)
350
354
nvm_tlv_list_t tlv_list ;
351
355
ns_list_init (& tlv_list );
352
356
353
- nvm_tlv_entry_t * tlv_entry = ws_pae_nvm_store_nw_info_tlv_create (pae_supp -> sec_keys_nw_info .pan_id ,
357
+ nvm_tlv_entry_t * tlv_entry = ws_pae_nvm_store_nw_info_tlv_create (pae_supp -> sec_keys_nw_info .key_pan_id ,
354
358
pae_supp -> sec_keys_nw_info .network_name ,
355
359
& pae_supp -> gtks );
356
360
ns_list_add_to_end (& tlv_list , tlv_entry );
@@ -370,7 +374,7 @@ static int8_t ws_pae_supp_nvm_nw_info_read(pae_supp_t *pae_supp)
370
374
ws_pae_nvm_store_tlv_file_read (NW_INFO_FILE , & tlv_list );
371
375
372
376
ns_list_foreach_safe (nvm_tlv_entry_t , entry , & tlv_list ) {
373
- ws_pae_nvm_store_nw_info_tlv_read (entry , & pae_supp -> sec_keys_nw_info .pan_id ,
377
+ ws_pae_nvm_store_nw_info_tlv_read (entry , & pae_supp -> sec_keys_nw_info .key_pan_id ,
374
378
pae_supp -> sec_keys_nw_info .network_name ,
375
379
& pae_supp -> gtks );
376
380
ns_list_remove (& tlv_list , entry );
@@ -465,21 +469,18 @@ static int8_t ws_pae_supp_nw_keys_valid_check(pae_supp_t *pae_supp, uint16_t pan
465
469
return -1 ;
466
470
}
467
471
468
- // First attempt to authenticate, checks if keys exists
469
- if (pae_supp -> nw_keys_used_cnt == 0 && pan_id == pae_supp -> sec_keys_nw_info .pan_id ) {
472
+ /* Checks if keys matches to PAN ID, and call inserts function that will update the
473
+ network keys as needed */
474
+ if (pan_id == pae_supp -> sec_keys_nw_info .key_pan_id ) {
475
+ tr_debug ("Existing keys used, counter %i" , pae_supp -> nw_keys_used_cnt );
470
476
if (pae_supp -> nw_key_insert (pae_supp -> interface_ptr , pae_supp -> sec_keys_nw_info .gtks ) >= 0 ) {
471
477
tr_debug ("Keys inserted" );
472
- pae_supp -> nw_keys_used_cnt ++ ;
473
- return 0 ;
474
478
}
475
- }
476
-
477
- if (pae_supp -> nw_keys_used_cnt == 0 ) {
478
- return -1 ;
479
- } else {
480
- tr_debug ("Existing keys used, counter %i" , pae_supp -> nw_keys_used_cnt );
481
479
pae_supp -> nw_keys_used_cnt ++ ;
482
480
return 0 ;
481
+ } else {
482
+ pae_supp -> nw_keys_used_cnt = 0 ;
483
+ return -1 ;
483
484
}
484
485
}
485
486
@@ -492,6 +493,8 @@ static void ws_pae_supp_keys_nw_info_init(sec_prot_keys_nw_info_t *sec_keys_nw_i
492
493
memset (sec_keys_nw_info , 0 , sizeof (sec_prot_keys_nw_info_t ));
493
494
494
495
sec_keys_nw_info -> gtks = gtks ;
496
+ sec_keys_nw_info -> new_pan_id = 0xFFFF ;
497
+ sec_keys_nw_info -> key_pan_id = 0xFFFF ;
495
498
sec_keys_nw_info -> updated = false;
496
499
}
497
500
0 commit comments