@@ -335,14 +335,14 @@ static void link_configuration_copy(link_configuration_s *this, link_configurati
335
335
if (!this || !configuration_ptr ) {
336
336
return ;
337
337
}
338
- //@TODO Totaly wrong place
338
+
339
+ memcpy (this -> extended_random_mac , configuration_ptr -> extended_random_mac , 8 );
340
+ memcpy (this -> mesh_local_eid , configuration_ptr -> mesh_local_eid ,5 );
339
341
memcpy (this -> name , configuration_ptr -> name , 16 );
340
342
memcpy (this -> PSKc , configuration_ptr -> PSKc , 16 );
341
343
memcpy (this -> master_key , configuration_ptr -> master_key , 16 );
342
344
memcpy (this -> mesh_local_ula_prefix , configuration_ptr -> mesh_local_ula_prefix , 8 );
343
- memcpy (this -> mesh_local_eid , configuration_ptr -> mesh_local_eid , 8 );
344
345
memcpy (this -> extented_pan_id , configuration_ptr -> extented_pan_id , 8 );
345
- memcpy (this -> extended_random_mac , configuration_ptr -> extended_random_mac , 8 );
346
346
memcpy (this -> channel_mask , configuration_ptr -> channel_mask ,5 );
347
347
this -> key_rotation = configuration_ptr -> key_rotation ;
348
348
this -> key_sequence = configuration_ptr -> key_sequence ;
@@ -416,8 +416,6 @@ static void link_configuration_trace(link_configuration_s *this)
416
416
}
417
417
tr_debug ("NwkName: %s" , trace_array (this -> name , 16 ));
418
418
tr_debug ("Mesh ula: %s" , trace_array (this -> mesh_local_ula_prefix , 8 ));
419
- tr_debug ("ML-EID: %s" , trace_array (this -> mesh_local_eid , 8 ));
420
- tr_debug ("Random MAC: %s" , trace_array (this -> extended_random_mac , 8 ));
421
419
tr_debug ("Extendend PanId: %s" , trace_array (this -> extented_pan_id , 8 ));
422
420
tr_debug ("panid: %" PRIu16 ", Channel:%" PRIu16 ", keyRot:%" PRIu16 ", keySeq:%" PRIu32 , this -> panId , this -> rfChannel , this -> key_rotation , this -> key_sequence );
423
421
return ;
@@ -432,6 +430,7 @@ static device_configuration_s *device_configuration_create(void)
432
430
memset (this , 0 , sizeof (device_configuration_s ));
433
431
return this ;
434
432
}
433
+
435
434
static void device_configuration_delete (device_configuration_s * this )
436
435
{
437
436
if (!this ) {
@@ -787,12 +786,13 @@ void thread_joiner_application_lc_nvm_read_callback(int status, void *context)
787
786
fast_data .mle_frame_counter += MLE_FRAME_COUNTER_LIMIT ;
788
787
thread_nvm_store_fast_data_store (& fast_data );
789
788
790
- thread_dynamic_storage_device_configuration_read (this -> interface_id ,this -> configuration_ptr -> extended_random_mac ,this -> configuration_ptr -> mesh_local_eid );
789
+ thread_dynamic_storage_device_configuration_read (this -> interface_id ,this -> device_configuration_ptr -> extended_random_mac ,this -> device_configuration_ptr -> mesh_local_eid );
791
790
thread_nvm_store_link_info_file_read ();
792
791
thread_joiner_application_validate_settings (this );// Generate all random information
793
792
this -> configuration_valid = true;
794
793
link_configuration_trace (this -> configuration_ptr );
795
-
794
+ tr_debug ("ML-EID: %s" , trace_array (this -> device_configuration_ptr -> mesh_local_eid , 8 ));
795
+ tr_debug ("Random MAC: %s" , trace_array (this -> device_configuration_ptr -> extended_random_mac , 8 ));
796
796
//Add Security to MLE service
797
797
uint8_t key_material [32 ];
798
798
uint8_t key_index ;
@@ -867,26 +867,32 @@ void thread_joiner_application_nvm_delete_callback(int status, void *context)
867
867
868
868
static void thread_joiner_application_validate_settings (thread_joiner_t * this )
869
869
{
870
-
871
- if (memcmp (this -> configuration_ptr -> extended_random_mac ,ADDR_UNSPECIFIED , 8 ) == 0 ) {
872
- randLIB_get_n_bytes_random (this -> configuration_ptr -> extended_random_mac , 8 );
873
-
874
- this -> configuration_ptr -> extended_random_mac [0 ] |= 2 ; //Set Local Bit
875
- this -> configuration_ptr -> extended_random_mac [0 ] &= ~1 ; //Clear multicast bit
870
+ if (memcmp (this -> device_configuration_ptr -> extended_random_mac ,ADDR_UNSPECIFIED , 8 ) == 0 ) {
871
+ memcpy (this -> device_configuration_ptr -> extended_random_mac ,this -> configuration_ptr -> extended_random_mac ,8 );
872
+ }
873
+ if (memcmp (this -> device_configuration_ptr -> extended_random_mac ,ADDR_UNSPECIFIED , 8 ) == 0 ) {
874
+ randLIB_get_n_bytes_random (this -> device_configuration_ptr -> extended_random_mac , 8 );
875
+ this -> device_configuration_ptr -> extended_random_mac [0 ] |= 2 ; //Set Local Bit
876
+ this -> device_configuration_ptr -> extended_random_mac [0 ] &= ~1 ; //Clear multicast bit
876
877
tr_info ("Generating Random MAC" );
878
+ memcpy (this -> configuration_ptr -> extended_random_mac ,this -> device_configuration_ptr -> extended_random_mac ,8 );
879
+ }
880
+ if (memcmp (this -> device_configuration_ptr -> mesh_local_eid ,ADDR_UNSPECIFIED ,8 )== 0 ){
881
+ memcpy (this -> device_configuration_ptr -> mesh_local_eid ,this -> configuration_ptr -> mesh_local_eid ,8 );
877
882
}
878
- while (addr_iid_reserved (this -> configuration_ptr -> mesh_local_eid ) ||
879
- memcmp (this -> configuration_ptr -> mesh_local_eid , ADDR_SHORT_ADR_SUFFIC ,6 ) == 0 ) {
883
+ while (addr_iid_reserved (this -> device_configuration_ptr -> mesh_local_eid ) ||
884
+ memcmp (this -> device_configuration_ptr -> mesh_local_eid , ADDR_SHORT_ADR_SUFFIC ,6 ) == 0 ) {
880
885
// addr_iid_reserved checks the all zeroes case.
881
- randLIB_get_n_bytes_random (this -> configuration_ptr -> mesh_local_eid , 8 );
886
+ randLIB_get_n_bytes_random (this -> device_configuration_ptr -> mesh_local_eid , 8 );
882
887
tr_info ("Generating Random ML-EID" );
888
+ memcpy (this -> configuration_ptr -> mesh_local_eid ,this -> device_configuration_ptr -> mesh_local_eid ,8 );
883
889
}
884
-
885
890
if (this -> configuration_ptr -> key_rotation < 3600 ) {
886
891
this -> configuration_ptr -> key_rotation = 3600 ;
887
892
}
888
893
}
889
894
895
+
890
896
int thread_joiner_application_init (int8_t interface_id , device_configuration_s * device_configuration_ptr , link_configuration_s * default_configuration_ptr )
891
897
{
892
898
thread_joiner_t * this ;
@@ -1132,6 +1138,25 @@ uint64_t thread_joiner_application_active_timestamp_get(int8_t interface_id)
1132
1138
return this -> configuration_ptr -> timestamp ;
1133
1139
}
1134
1140
1141
+ uint8_t * thread_joiner_application_random_mac_get (int8_t interface_id )
1142
+ {
1143
+ thread_joiner_t * this = thread_joiner_find (interface_id );
1144
+ if (!this || !this -> device_configuration_ptr ) {
1145
+ tr_error ("thread_joiner_application_random_mac_get NULL parameter " );
1146
+ return (uint8_t * )ADDR_UNSPECIFIED ;
1147
+ }
1148
+ return this -> device_configuration_ptr -> extended_random_mac ;
1149
+ }
1150
+ uint8_t * thread_joiner_application_ml_eid_get (int8_t interface_id )
1151
+ {
1152
+ tr_info ("thread_joiner_application_ml_eid_get" );
1153
+ thread_joiner_t * this = thread_joiner_find (interface_id );
1154
+ if (!this || !this -> device_configuration_ptr ) {
1155
+ tr_error ("thread_joiner_application_ml_eid_get parameter NULL" );
1156
+ return (uint8_t * )ADDR_UNSPECIFIED ;
1157
+ }
1158
+ return this -> device_configuration_ptr -> mesh_local_eid ;
1159
+ }
1135
1160
void thread_joiner_application_active_timestamp_set (int8_t interface_id , uint64_t timestamp )
1136
1161
{
1137
1162
thread_joiner_t * this = thread_joiner_find (interface_id );
@@ -1944,13 +1969,12 @@ int thread_joiner_application_pskd_commission_start(int8_t interface_id, uint8_t
1944
1969
1945
1970
int thread_joiner_application_configuration_nvm_save (int8_t interface_id )
1946
1971
{
1947
-
1972
+ tr_info ( "thread_joiner_application_configuration_nvm_save" );
1948
1973
thread_joiner_t * this = thread_joiner_find (interface_id );
1949
1974
if (!this ) {
1950
1975
return -1 ;
1951
1976
}
1952
-
1953
- thread_dynamic_storage_device_configuration_store (interface_id ,this -> configuration_ptr -> extended_random_mac ,this -> configuration_ptr -> mesh_local_eid );
1977
+ thread_dynamic_storage_device_configuration_store (interface_id ,this -> device_configuration_ptr -> extended_random_mac ,this -> device_configuration_ptr -> mesh_local_eid );
1954
1978
thread_dynamic_storage_pending_configuration_store (interface_id ,this -> pending_configuration_ptr , sizeof (configuration_set_t ));
1955
1979
thread_nvm_store_seq_counter_store (this -> configuration_ptr -> key_sequence );
1956
1980
thread_joiner_application_nvm_link_config_write (this , this -> active_configuration_ptr );
0 commit comments