46
46
#include "6LoWPAN/Thread/thread_extension_bootstrap.h"
47
47
#include "6LoWPAN/Thread/thread_extension_constants.h"
48
48
#include "6LoWPAN/Thread/thread_management_server.h"
49
+ #include "6LoWPAN/Thread/thread_nvm_store.h"
49
50
50
51
51
52
/*
@@ -71,12 +72,14 @@ typedef struct thread_extension_credentials {
71
72
72
73
int8_t coap_service_secure_session_id ;
73
74
int8_t interface_id ;
75
+ bool reattach_ongoing ;
74
76
75
77
ns_list_link_t link ;
76
78
} thread_ccm_credentials_t ;
77
79
78
80
#ifdef HAVE_THREAD_V2
79
81
82
+ #if 1
80
83
/* Hardcoded CSR request */
81
84
static const unsigned char csr_request [215 ] = {
82
85
0x30 , 0x81 , 0xd4 , 0x30 , 0x7c , 0x02 , 0x01 , 0x00 , 0x30 , 0x1a , 0x31 , 0x18 , 0x30 , 0x16 , 0x06 , 0x03 ,
@@ -94,6 +97,25 @@ static const unsigned char csr_request[215] = {
94
97
0x63 , 0xea , 0xe3 , 0xd2 , 0xf1 , 0x50 , 0x48 , 0x56 , 0xdf , 0x6b , 0xcf , 0xc4 , 0x31 , 0xc4 , 0xcf , 0xbc ,
95
98
0x26 , 0xe3 , 0x5a , 0x74 , 0x62 , 0x0f , 0x70
96
99
};
100
+ #else
101
+ /* CSR request with CBOR header*/
102
+ static const unsigned char csr_request [244 ] = {
103
+ 0x58 , 0xf2 , 0x30 , 0x81 , 0xef , 0x30 , 0x81 , 0x95 , 0x02 , 0x01 , 0x01 , 0x30 , 0x33 , 0x31 , 0x1c , 0x30 , 0x1a , 0x06 ,
104
+ 0x03 , 0x55 , 0x04 , 0x03 , 0x0c , 0x13 , 0x4c , 0x69 , 0x67 , 0x68 , 0x74 , 0x69 , 0x66 , 0x79 , 0x20 , 0x50 , 0x72 , 0x6f ,
105
+ 0x20 , 0x4d , 0x6f , 0x64 , 0x75 , 0x6c , 0x65 , 0x31 , 0x13 , 0x30 , 0x11 , 0x06 , 0x03 , 0x55 , 0x04 , 0x0a , 0x0c , 0x0a ,
106
+ 0x4f , 0x53 , 0x52 , 0x41 , 0x4d , 0x20 , 0x47 , 0x6d , 0x62 , 0x48 , 0x30 , 0x59 , 0x30 , 0x13 , 0x06 , 0x07 , 0x2a , 0x86 ,
107
+ 0x48 , 0xce , 0x3d , 0x02 , 0x01 , 0x06 , 0x08 , 0x2a , 0x86 , 0x48 , 0xce , 0x3d , 0x03 , 0x01 , 0x07 , 0x03 , 0x42 , 0x00 ,
108
+ 0x04 , 0xd8 , 0x19 , 0x64 , 0x07 , 0xca , 0x38 , 0x01 , 0x62 , 0xfd , 0x7e , 0xe7 , 0x07 , 0x8d , 0x21 , 0x50 , 0x0b , 0x9f ,
109
+ 0x00 , 0x71 , 0x26 , 0xaa , 0x55 , 0x2a , 0x44 , 0x9b , 0xe8 , 0xfd , 0xfb , 0x0e , 0x8d , 0x41 , 0x01 , 0xf2 , 0x7b , 0x2e ,
110
+ 0x7b , 0xe4 , 0x4f , 0x35 , 0x00 , 0x0b , 0x1f , 0xbc , 0x86 , 0x57 , 0xa1 , 0x69 , 0x32 , 0x49 , 0xcf , 0xd7 , 0x2f , 0x0b ,
111
+ 0xfa , 0x22 , 0x44 , 0x0b , 0x6f , 0xf4 , 0xb5 , 0xbd , 0x0f , 0x20 , 0xab , 0xa0 , 0x00 , 0x30 , 0x0a , 0x06 , 0x08 , 0x2a ,
112
+ 0x86 , 0x48 , 0xce , 0x3d , 0x04 , 0x03 , 0x02 , 0x03 , 0x49 , 0x00 , 0x30 , 0x46 , 0x02 , 0x21 , 0x00 , 0xb5 , 0xa2 , 0x8b ,
113
+ 0xf9 , 0xbf , 0x7d , 0x2c , 0x72 , 0x3e , 0xf0 , 0xad , 0x1e , 0x38 , 0x28 , 0xc0 , 0xa3 , 0xe8 , 0xd6 , 0x70 , 0x9a , 0x2a ,
114
+ 0xf8 , 0x1d , 0x33 , 0x9d , 0xbb , 0x6c , 0x4f , 0x7c , 0x81 , 0xb6 , 0x71 , 0x02 , 0x21 , 0x00 , 0xba , 0x74 , 0x50 , 0xad ,
115
+ 0x27 , 0x2e , 0x00 , 0x71 , 0x68 , 0x7f , 0xe0 , 0x2c , 0x8c , 0x1b , 0x6f , 0x95 , 0x8c , 0x58 , 0x1e , 0xe7 , 0xe3 , 0xa5 ,
116
+ 0x50 , 0xca , 0x12 , 0x0a , 0x60 , 0x56 , 0xd2 , 0x3a , 0xe2 , 0xeb
117
+ }
118
+ #endif
97
119
98
120
/*
99
121
* Private key for certificate m_device_nxp_sn_and_8021ar.cert.pem -> test registrar will return this as default
@@ -155,19 +177,29 @@ static void thread_extension_bootstrap_attach_cb(void *arg)
155
177
if (!this ) {
156
178
return ;
157
179
}
158
- // Cleaning up the joining information
159
- if (this -> ccm_done_cb ) {// This is successfull
160
- this -> ccm_done_cb (this -> interface_id );
180
+ if (this -> reattach_ongoing ) {
181
+ this -> reattach_ongoing = false;
182
+ thread_nvm_store_mleid_rloc_map_remove ();
183
+ thread_nvm_store_link_info_clear ();
184
+ thread_joiner_application_link_configuration_delete (this -> interface_id );
185
+ thread_bootstrap_connection_error (this -> interface_id , CON_ERROR_NETWORK_KICK , NULL );
186
+ } else {
187
+ // Cleaning up the joining information
188
+ if (this -> ccm_done_cb ) {// This is successfull
189
+ this -> ccm_done_cb (this -> interface_id );
190
+ }
161
191
}
162
192
}
163
193
164
- int8_t thread_extension_bootstrap_network_reattach (int8_t interface_id , uint16_t timeout )
194
+ int8_t thread_extension_bootstrap_network_reattach (int8_t service_id , uint16_t timeout , bool clear_data )
165
195
{
166
- thread_ccm_credentials_t * this = thread_extension_bootstrap_find_by_service (interface_id );
196
+ thread_ccm_credentials_t * this = thread_extension_bootstrap_find_by_service (service_id );
167
197
if (!this ) {
168
198
return -1 ;
169
199
}
170
200
201
+ this -> reattach_ongoing = clear_data ;
202
+
171
203
// re-attach in any case and close the secure connection
172
204
this -> attach_timeout = eventOS_timeout_ms (thread_extension_bootstrap_attach_cb , timeout , this );
173
205
@@ -185,26 +217,14 @@ static int commercial_bootstrap_security_start_cb(int8_t service_id, uint8_t add
185
217
186
218
return 0 ;
187
219
}
188
- static int thread_joiner_application_simple_enroll_response_cb (int8_t service_id , uint8_t source_address [static 16 ], uint16_t source_port , sn_coap_hdr_s * response_ptr )
220
+
221
+ static int thread_extension_bootstrap_enroll_parse (protocol_interface_info_entry_t * cur , uint8_t * payload_ptr , uint16_t payload_len )
189
222
{
190
- (void ) source_address ;
191
- (void ) source_port ;
192
223
uint8_t * ptr ;
193
224
uint16_t len , flen ;
194
225
195
- // re-attach in any case and close the secure connection
196
- thread_extension_bootstrap_network_reattach (service_id , 1000 );
197
- coap_service_close_secure_connection (service_id , source_address , source_port );
198
-
199
- protocol_interface_info_entry_t * cur = protocol_stack_interface_info_get_by_id (thread_extension_bootstrap_find_id_by_service (service_id ));
200
-
201
- tr_debug ("Simple enrollment received len:%d - %s" , response_ptr -> payload_len , trace_array (response_ptr -> payload_ptr , response_ptr -> payload_len ));
202
-
203
- if (!cur || !cur -> thread_info || !response_ptr ) {
204
- return -1 ;
205
- }
206
- ptr = response_ptr -> payload_ptr ;
207
- len = response_ptr -> payload_len ;
226
+ ptr = payload_ptr ;
227
+ len = payload_len ;
208
228
// CBOR format check
209
229
if (* ptr == 0x58 ) {
210
230
flen = * (ptr + 1 );
@@ -224,6 +244,27 @@ static int thread_joiner_application_simple_enroll_response_cb(int8_t service_id
224
244
tr_warn ("ae response parse failed, len %d != %d" , len , flen );
225
245
}
226
246
247
+ return 0 ;
248
+ }
249
+
250
+ static int thread_joiner_application_simple_enroll_response_cb (int8_t service_id , uint8_t source_address [static 16 ], uint16_t source_port , sn_coap_hdr_s * response_ptr )
251
+ {
252
+ (void ) source_address ;
253
+ (void ) source_port ;
254
+
255
+ // re-attach in any case and close the secure connection
256
+ thread_extension_bootstrap_network_reattach (service_id , 1000 , false);
257
+ coap_service_close_secure_connection (service_id , source_address , source_port );
258
+
259
+ protocol_interface_info_entry_t * cur = protocol_stack_interface_info_get_by_id (thread_extension_bootstrap_find_id_by_service (service_id ));
260
+
261
+ tr_debug ("Simple enrollment received len:%d - %s" ,response_ptr -> payload_len ,trace_array (response_ptr -> payload_ptr , response_ptr -> payload_len ));
262
+
263
+ if (!cur || !cur -> thread_info || !response_ptr ) {
264
+ return -1 ;
265
+ }
266
+
267
+ thread_extension_bootstrap_enroll_parse (cur , response_ptr -> payload_ptr , response_ptr -> payload_len );
227
268
228
269
return 0 ;
229
270
}
@@ -398,7 +439,7 @@ static int thread_joiner_application_nmkp_response_cb(int8_t service_id, uint8_t
398
439
tr_debug ("nmkp provisioning done" );
399
440
400
441
// re-attach in any case and close the secure connection
401
- thread_extension_bootstrap_network_reattach (service_id , 1000 );
442
+ thread_extension_bootstrap_network_reattach (service_id , 1000 , false );
402
443
coap_service_close_secure_connection (service_id , source_address , source_port );
403
444
404
445
// CoAP message failed - try to reattach
@@ -682,18 +723,24 @@ static int thread_extension_reenroll_resp_cb(int8_t service_id, uint8_t source_a
682
723
(void ) service_id ;
683
724
(void ) source_address ;
684
725
(void ) source_port ;
726
+ protocol_interface_info_entry_t * cur = protocol_stack_interface_info_get_by_id (thread_extension_bootstrap_find_id_by_service (service_id ));
685
727
686
- if (!response_ptr ) {
687
- tr_debug ("No response to re-enroll req" );
728
+ // Close secure connection
729
+ coap_service_close_secure_connection (service_id , source_address , source_port );
730
+
731
+ if (!response_ptr || !cur ) {
732
+ tr_debug ("re-enroll failed" );
688
733
return -1 ;
689
734
}
690
735
691
736
tr_debug ("re-enroll resp len %d" , response_ptr -> payload_len );
692
737
693
- // todo:check & update new certificate
694
-
695
- // Close secure connection
696
- coap_service_close_secure_connection (service_id , source_address , source_port );
738
+ // todo:check new certificate
739
+ // Update certificate
740
+ if (0 == thread_extension_bootstrap_enroll_parse (cur , response_ptr -> payload_ptr , response_ptr -> payload_len )) {
741
+ // start NMKP with new certificates
742
+ thread_extension_bootstrap_network_reattach (service_id , 5000 , true);
743
+ }
697
744
698
745
return 0 ;
699
746
}
0 commit comments