@@ -141,8 +141,8 @@ static int8_t ws_pae_controller_frame_counter_read(pae_controller_t *controller)
141141static void ws_pae_controller_frame_counter_reset (frame_counters_t * frame_counters );
142142static void ws_pae_controller_frame_counter_index_reset (frame_counters_t * frame_counters , uint8_t index );
143143static int8_t ws_pae_controller_nw_info_read (pae_controller_t * controller , sec_prot_gtk_keys_t * gtks );
144- static int8_t ws_pae_controller_nvm_nw_info_write (protocol_interface_info_entry_t * interface_ptr , uint16_t pan_id , char * network_name , sec_prot_gtk_keys_t * gtks );
145- static int8_t ws_pae_controller_nvm_nw_info_read (protocol_interface_info_entry_t * interface_ptr , uint16_t * pan_id , char * network_name , sec_prot_gtk_keys_t * gtks );
144+ static int8_t ws_pae_controller_nvm_nw_info_write (protocol_interface_info_entry_t * interface_ptr , uint16_t pan_id , char * network_name , uint8_t * gtk_eui64 , sec_prot_gtk_keys_t * gtks );
145+ static int8_t ws_pae_controller_nvm_nw_info_read (protocol_interface_info_entry_t * interface_ptr , uint16_t * pan_id , char * network_name , uint8_t * gtk_eui64 , sec_prot_gtk_keys_t * gtks );
146146
147147
148148static const char * FRAME_COUNTER_FILE = FRAME_COUNTER_FILE_NAME ;
@@ -371,7 +371,13 @@ static void ws_pae_controller_nw_info_updated_check(protocol_interface_info_entr
371371 }
372372
373373 if (controller -> sec_keys_nw_info .updated || sec_prot_keys_gtks_are_updated (controller -> sec_keys_nw_info .gtks )) {
374- ws_pae_controller_nvm_nw_info_write (interface_ptr , controller -> sec_keys_nw_info .key_pan_id , controller -> sec_keys_nw_info .network_name , controller -> sec_keys_nw_info .gtks );
374+ // Get own EUI-64
375+ uint8_t gtk_eui64 [8 ] = {0 };
376+ link_layer_address_s mac_params ;
377+ if (arm_nwk_mac_address_read (interface_ptr -> id , & mac_params ) >= 0 ) {
378+ memcpy (gtk_eui64 , mac_params .mac_long , 8 );
379+ }
380+ ws_pae_controller_nvm_nw_info_write (interface_ptr , controller -> sec_keys_nw_info .key_pan_id , controller -> sec_keys_nw_info .network_name , gtk_eui64 , controller -> sec_keys_nw_info .gtks );
375381 controller -> sec_keys_nw_info .updated = false;
376382 sec_prot_keys_gtks_updated_reset (controller -> sec_keys_nw_info .gtks );
377383 }
@@ -844,32 +850,46 @@ static void ws_pae_controller_frame_counter_index_reset(frame_counters_t *frame_
844850
845851static int8_t ws_pae_controller_nw_info_read (pae_controller_t * controller , sec_prot_gtk_keys_t * gtks )
846852{
847- if (ws_pae_controller_nvm_nw_info_read (controller -> interface_ptr , & controller -> sec_keys_nw_info .key_pan_id , controller -> sec_keys_nw_info .network_name , gtks ) < 0 ) {
853+ uint8_t nvm_gtk_eui64 [8 ];
854+ if (ws_pae_controller_nvm_nw_info_read (controller -> interface_ptr , & controller -> sec_keys_nw_info .key_pan_id , controller -> sec_keys_nw_info .network_name , nvm_gtk_eui64 , gtks ) < 0 ) {
848855 // If no stored GTKs and network info (pan_id and network name) exits
849856 return -1 ;
850857 }
851858
859+ /* Get own EUI-64 and compare to the one read from the NVM. In case of mismatch delete GTKs and make
860+ full authentication to update keys with new EUI-64 and in case of authenticator to update new
861+ authenticator EUI-64 to the network. */
862+ uint8_t gtk_eui64 [8 ] = {0 };
863+ link_layer_address_s mac_params ;
864+ if (arm_nwk_mac_address_read (controller -> interface_ptr -> id , & mac_params ) >= 0 ) {
865+ memcpy (gtk_eui64 , mac_params .mac_long , 8 );
866+ }
867+ if (memcmp (nvm_gtk_eui64 , gtk_eui64 , 8 ) != 0 ) {
868+ tr_warn ("NVM EUI-64 mismatch, current: %s stored: %s" , tr_array (gtk_eui64 , 8 ), tr_array (nvm_gtk_eui64 , 8 ));
869+ sec_prot_keys_gtks_clear (gtks );
870+ }
871+
852872 // Sets also new pan_id used for pan_id set by bootstrap
853873 controller -> sec_keys_nw_info .new_pan_id = controller -> sec_keys_nw_info .key_pan_id ;
854874
855875 return 0 ;
856876}
857877
858- static int8_t ws_pae_controller_nvm_nw_info_write (protocol_interface_info_entry_t * interface_ptr , uint16_t pan_id , char * network_name , sec_prot_gtk_keys_t * gtks )
878+ static int8_t ws_pae_controller_nvm_nw_info_write (protocol_interface_info_entry_t * interface_ptr , uint16_t pan_id , char * network_name , uint8_t * gtk_eui64 , sec_prot_gtk_keys_t * gtks )
859879{
860880 nw_info_nvm_tlv_t * tlv = (nw_info_nvm_tlv_t * ) ws_pae_controller_nvm_tlv_get (interface_ptr );
861881 if (!tlv ) {
862882 return -1 ;
863883 }
864884
865- ws_pae_nvm_store_nw_info_tlv_create (tlv , pan_id , network_name , gtks );
885+ ws_pae_nvm_store_nw_info_tlv_create (tlv , pan_id , network_name , gtk_eui64 , gtks );
866886
867887 ws_pae_nvm_store_tlv_file_write (NW_INFO_FILE , (nvm_tlv_t * ) tlv );
868888
869889 return 0 ;
870890}
871891
872- static int8_t ws_pae_controller_nvm_nw_info_read (protocol_interface_info_entry_t * interface_ptr , uint16_t * pan_id , char * network_name , sec_prot_gtk_keys_t * gtks )
892+ static int8_t ws_pae_controller_nvm_nw_info_read (protocol_interface_info_entry_t * interface_ptr , uint16_t * pan_id , char * network_name , uint8_t * gtk_eui64 , sec_prot_gtk_keys_t * gtks )
873893{
874894 nw_info_nvm_tlv_t * tlv_entry = (nw_info_nvm_tlv_t * ) ws_pae_controller_nvm_tlv_get (interface_ptr );
875895 if (!tlv_entry ) {
@@ -882,7 +902,7 @@ static int8_t ws_pae_controller_nvm_nw_info_read(protocol_interface_info_entry_t
882902 return -1 ;
883903 }
884904
885- if (ws_pae_nvm_store_nw_info_tlv_read (tlv_entry , pan_id , network_name , gtks ) < 0 ) {
905+ if (ws_pae_nvm_store_nw_info_tlv_read (tlv_entry , pan_id , network_name , gtk_eui64 , gtks ) < 0 ) {
886906 return -1 ;
887907 }
888908
@@ -964,7 +984,8 @@ int8_t ws_pae_controller_auth_init(protocol_interface_info_entry_t *interface_pt
964984 }
965985 if (!read_gtks_to || sec_prot_keys_gtk_count (read_gtks_to ) == 0 ) {
966986 // Key material invalid or GTKs are expired, delete GTKs from NVM
967- ws_pae_controller_nvm_nw_info_write (controller -> interface_ptr , controller -> sec_keys_nw_info .key_pan_id , controller -> sec_keys_nw_info .network_name , NULL );
987+ uint8_t gtk_eui64 [8 ] = {0 }; // Set GTK EUI-64 to zero
988+ ws_pae_controller_nvm_nw_info_write (controller -> interface_ptr , controller -> sec_keys_nw_info .key_pan_id , controller -> sec_keys_nw_info .network_name , gtk_eui64 , NULL );
968989 }
969990 }
970991
0 commit comments