58
58
#include "thread_network_synch.h"
59
59
#include "thread_network_data_lib.h"
60
60
#include "thread_joiner_application.h"
61
+ #include "thread_extension.h"
61
62
#include "6LoWPAN/Thread/thread_extension_bootstrap.h"
62
63
#include "mac_api.h"
63
64
#include "6LoWPAN/MAC/mac_helper.h"
@@ -318,6 +319,7 @@ static link_configuration_s *link_configuration_create(void)
318
319
}
319
320
memset (this , 0 , sizeof (link_configuration_s ));
320
321
this -> securityPolicy = SECURITY_POLICY_ALL_SECURITY ; // Set all default values ('1') for security policy flags
322
+ this -> securityPolicyExt = SECURITY_POLICY_ALL_SECURITY ; // Set all default values
321
323
return this ;
322
324
}
323
325
@@ -345,6 +347,7 @@ static void link_configuration_copy(link_configuration_s *this, link_configurati
345
347
this -> panId = configuration_ptr -> panId ;
346
348
this -> rfChannel = configuration_ptr -> rfChannel ;
347
349
this -> securityPolicy = configuration_ptr -> securityPolicy ;
350
+ this -> securityPolicyExt = configuration_ptr -> securityPolicyExt ;
348
351
this -> timestamp = configuration_ptr -> timestamp ;
349
352
return ;
350
353
}
@@ -398,8 +401,12 @@ static int link_configuration_update(link_configuration_s *link_configuration, u
398
401
}
399
402
400
403
if (thread_meshcop_tlv_find (msg_ptr , msg_len , MESHCOP_TLV_SECURITY_POLICY , & ptr ) >= 3 ) {
404
+ link_configuration -> securityPolicyExt = SECURITY_POLICY_ALL_SECURITY ;
401
405
link_configuration -> securityPolicy = ptr [2 ];
402
406
link_configuration -> key_rotation = common_read_16_bit (ptr );
407
+ if (msg_len > 3 ) {
408
+ link_configuration -> securityPolicyExt = ptr [3 ];
409
+ }
403
410
}
404
411
405
412
return 0 ;
@@ -710,7 +717,7 @@ static void configuration_set_copy_mandatory(configuration_set_t *destination_pt
710
717
tr_debug ("mandatory TLVs needed: %s" , trace_array (tlv_list , tlv_list_len ));
711
718
configuration_set_add_fields (destination_ptr , source_ptr -> data , source_ptr -> length , tlv_list , tlv_list_len );
712
719
}
713
- static void configuration_set_generate (configuration_set_t * destination_ptr , link_configuration_s * configuration_ptr )
720
+ static void configuration_set_generate (int8_t interface_id , configuration_set_t * destination_ptr , link_configuration_s * configuration_ptr )
714
721
{
715
722
uint8_t * response_ptr ;
716
723
@@ -733,11 +740,18 @@ static void configuration_set_generate(configuration_set_t *destination_ptr, lin
733
740
response_ptr = thread_tmfcop_tlv_data_write (response_ptr , MESHCOP_TLV_PSKC , 16 , configuration_ptr -> PSKc );
734
741
response_ptr = thread_tmfcop_tlv_data_write (response_ptr , MESHCOP_TLV_NETWORK_NAME , stringlen ((char * )& configuration_ptr -> name , 16 ), configuration_ptr -> name );
735
742
* response_ptr ++ = MESHCOP_TLV_SECURITY_POLICY ; // type
736
- * response_ptr ++ = 3 ; // length
737
- response_ptr = common_write_16_bit (configuration_ptr -> key_rotation , response_ptr );
738
- * response_ptr ++ = configuration_ptr -> securityPolicy ;
743
+ protocol_interface_info_entry_t * cur = protocol_stack_interface_info_get_by_id (interface_id );
744
+ if (thread_extension_version_check (thread_info (cur )-> version )) {
745
+ * response_ptr ++ = 4 ; // length
746
+ response_ptr = common_write_16_bit (configuration_ptr -> key_rotation , response_ptr );
747
+ * response_ptr ++ = configuration_ptr -> securityPolicy ;
748
+ * response_ptr ++ = configuration_ptr -> securityPolicyExt ;
749
+ } else {
750
+ * response_ptr ++ = 3 ; // length
751
+ response_ptr = common_write_16_bit (configuration_ptr -> key_rotation , response_ptr );
752
+ * response_ptr ++ = configuration_ptr -> securityPolicy ;
753
+ }
739
754
response_ptr = thread_tmfcop_tlv_data_write_uint64 (response_ptr , MESHCOP_TLV_ACTIVE_TIME_STAMP , configuration_ptr -> timestamp );
740
-
741
755
destination_ptr -> length = response_ptr - destination_ptr -> data ;
742
756
}
743
757
@@ -859,7 +873,7 @@ int thread_joiner_application_init(int8_t interface_id, device_configuration_s *
859
873
//If no master key or PSKc set we assume not valid configuration for thread network others may be possible to be 0
860
874
//This allows some configurations to be set statically for testing purposes
861
875
this -> configuration_valid = true;
862
- configuration_set_generate (this -> active_configuration_ptr , this -> configuration_ptr );
876
+ configuration_set_generate (this -> interface_id , this -> active_configuration_ptr , this -> configuration_ptr );
863
877
}
864
878
}
865
879
// Always load link configuration from bootstrap state machine. NVM overrides Static configuration
@@ -1533,7 +1547,7 @@ int thread_joiner_application_link_configuration_store(int8_t interface_id, link
1533
1547
}
1534
1548
1535
1549
thread_joiner_application_validate_settings (this );// Generate all random information
1536
- configuration_set_generate (this -> active_configuration_ptr , link_config );
1550
+ configuration_set_generate (this -> interface_id , this -> active_configuration_ptr , link_config );
1537
1551
link_configuration_update (this -> configuration_ptr , this -> active_configuration_ptr -> data , this -> active_configuration_ptr -> length );
1538
1552
this -> configuration_ptr -> key_sequence = link_config -> key_sequence ;
1539
1553
this -> configuration_valid = true;
0 commit comments