@@ -86,8 +86,10 @@ typedef struct thread_extension_info {
86
86
87
87
#ifdef HAVE_THREAD_ROUTER
88
88
static int thread_extension_joiner_router_init (protocol_interface_info_entry_t * cur );
89
+ static bool thread_extension_is_domain_prefix (protocol_interface_info_entry_t * interface , const uint8_t * addr );
89
90
#else
90
91
#define thread_extension_joiner_router_init (cur )
92
+ #define thread_extension_is_domain_prefix (interface , addr ) false
91
93
#endif
92
94
93
95
static int thread_extension_dua_registration_cb (int8_t service_id , uint8_t source_address [static 16 ], uint16_t source_port , sn_coap_hdr_s * response_ptr )
@@ -131,7 +133,7 @@ static int thread_extension_dua_registration_cb(int8_t service_id, uint8_t sourc
131
133
if_address_entry_t * addr_entry = addr_get_entry (cur , addr_data_ptr );
132
134
if (addr_entry ) {
133
135
cur -> dad_failures ++ ;
134
- thread_extension_address_generate (cur );
136
+ thread_extension_dua_address_generate (cur , addr_data_ptr , 64 );
135
137
return 0 ;
136
138
}
137
139
@@ -192,7 +194,7 @@ static int thread_extension_mtd_dua_ntf_cb(int8_t service_id, uint8_t source_add
192
194
}
193
195
// generate new dua address
194
196
cur -> dad_failures ++ ;
195
- thread_extension_address_generate (cur );
197
+ thread_extension_dua_address_generate (cur , addr_data_ptr , 64 );
196
198
197
199
return 0 ;
198
200
}
@@ -322,15 +324,12 @@ void thread_extension_addr_ntf_send(struct protocol_interface_info_entry *cur, u
322
324
{
323
325
uint8_t payload [16 + 1 ]; // Target eid + Status
324
326
uint8_t * ptr ;
325
- uint8_t domain_prefix [16 ];
326
- uint8_t domain_prefix_len ;
327
327
uint8_t br_ml_addr [16 ];
328
328
uint8_t seq ;
329
329
uint32_t delay_timer ;
330
330
331
- if (0 != thread_extension_network_prefix_get (cur -> id , NULL , domain_prefix , & domain_prefix_len ) ||
332
- !bitsequal (addr_data_ptr , domain_prefix , domain_prefix_len )) {
333
- //Not in commercial Mode
331
+
332
+ if (!thread_extension_is_domain_prefix (cur , addr_data_ptr )) {
334
333
return ;
335
334
}
336
335
@@ -351,38 +350,6 @@ void thread_extension_addr_ntf_send(struct protocol_interface_info_entry *cur, u
351
350
return ;
352
351
}
353
352
354
- int thread_extension_network_prefix_get (int8_t interface_id , uint8_t * options_ptr , uint8_t * domain_prefix_ptr , uint8_t * domain_prefix_len )
355
- {
356
- uint8_t * ptr ;
357
- uint16_t tlv_len ;
358
- uint8_t * configuration_ptr ;
359
- uint16_t configuration_len ;
360
- configuration_ptr = thread_joiner_application_active_config_params_get (interface_id , & configuration_len );
361
- if (!configuration_ptr || !configuration_len ) {
362
- return -1 ;
363
- }
364
- tlv_len = thread_meshcop_tlv_find (configuration_ptr ,configuration_len , MESHCOP_TLV_DOMAIN_PREFIX , & ptr );
365
- if (tlv_len == 0 ) {
366
- return -2 ;
367
- }
368
- if (tlv_len < 9 ) {
369
- tr_error ("domain prefix corrupted len:%d" , tlv_len );
370
- return -3 ;
371
- }
372
-
373
- if (domain_prefix_len ) {
374
- * domain_prefix_len = 64 ;
375
- }
376
- if (options_ptr ) {
377
- * options_ptr = ptr [0 ];
378
- }
379
- if (domain_prefix_ptr ) {
380
- bitcopy (domain_prefix_ptr , & ptr [1 ], 64 );
381
- }
382
-
383
- return 0 ;
384
- }
385
-
386
353
static void thread_extension_primary_bbr_update_done (struct protocol_interface_info_entry * cur )
387
354
{
388
355
// Check if network data changed or bbr info and send proactive an if needed
@@ -407,8 +374,6 @@ void thread_extension_network_data_process(struct protocol_interface_info_entry
407
374
{
408
375
// Check if network data changed or bbr info and send proactive an if needed
409
376
uint8_t addr [16 ];
410
- uint8_t domain_prefix [16 ];
411
- uint8_t domain_prefix_len ;
412
377
uint8_t sequence_number ;
413
378
uint32_t delay_timer ;
414
379
uint32_t mlr_timeout ;
@@ -420,17 +385,8 @@ void thread_extension_network_data_process(struct protocol_interface_info_entry
420
385
if (1 == thread_extension_primary_bbr_update_needed (cur ,common_read_16_bit (& addr [14 ]), sequence_number )) {
421
386
thread_address_registration_timer_set (cur , 1 + randLIB_get_random_in_range (0 , delay_timer /1000 ), randLIB_get_random_in_range (1 ,5 ));
422
387
}
423
- // Check if we are the BBR if we are make default route to backend
424
- if (0 == thread_extension_network_prefix_get (cur -> id , NULL , domain_prefix , & domain_prefix_len )) {
425
- // Routers and FEDs create on-mesh prefix for domain prefix
426
- if (cur -> thread_info -> thread_device_mode == THREAD_DEVICE_MODE_ROUTER ||
427
- cur -> thread_info -> thread_device_mode == THREAD_DEVICE_MODE_FULL_END_DEVICE ){
428
- if (ipv6_route_add (domain_prefix , domain_prefix_len , cur -> id , NULL , ROUTE_THREAD , 0xffffffff , 0 ) == NULL ) {
429
- tr_error ("fail to add domain prefix route" );
430
- }
431
- }
432
- }
433
388
}
389
+
434
390
static uint8_t * thread_server_tlv_list_get (uint8_t * service_tlv_ptr , uint16_t service_tlv_len , uint16_t * server_tlv_list_len )
435
391
{
436
392
uint16_t tlv_length = 0 ;
@@ -576,19 +532,14 @@ static int thread_extension_mlr_req_send(protocol_interface_info_entry_t *cur, c
576
532
return 0 ;
577
533
}
578
534
579
-
580
535
void thread_extension_address_registration (struct protocol_interface_info_entry * interface , const uint8_t * addr , const uint8_t * child_mac64 , bool refresh_child_entry , bool duplicate_child_detected )
581
536
{
582
537
uint8_t * ml_eid ;
583
538
uint8_t br_ml_addr [16 ];
584
539
uint8_t seq ;
585
540
uint32_t delay_timer ;
586
- uint8_t domain_prefix [16 ];
587
- uint8_t domain_prefix_len ;
588
541
589
- if (0 != thread_extension_network_prefix_get (interface -> id , NULL , domain_prefix , & domain_prefix_len ) ||
590
- !bitsequal (addr , domain_prefix , domain_prefix_len )) {
591
- //Not in commercial Mode
542
+ if (!thread_extension_is_domain_prefix (interface , addr )) {
592
543
return ;
593
544
}
594
545
tr_debug ("domain prefix address" );
@@ -671,22 +622,13 @@ void thread_extension_address_registration(struct protocol_interface_info_entry
671
622
}
672
623
#endif
673
624
}
674
- void thread_extension_address_generate (protocol_interface_info_entry_t * cur )
625
+
626
+ void thread_extension_dua_address_generate (protocol_interface_info_entry_t * cur , uint8_t * domain_prefix , uint8_t domain_prefix_len )
675
627
{
676
628
if_address_entry_t * def_address = NULL ;
677
- uint8_t options ;
678
- uint8_t domain_prefix_len ;
679
- uint8_t domain_address [16 ];
680
629
addr_delete_matching (cur , NULL , 0 , ADDR_SOURCE_THREAD_DOMAIN );
681
-
682
- if (thread_extension_network_prefix_get (cur -> id , & options , domain_address , & domain_prefix_len )) {
683
- return ;
684
- }
685
- if (!(options & 0x80 )) {
686
- tr_debug ("domain prefix does not allow SLAAC address, prefix %s options:%u" ,trace_ipv6_prefix (domain_address ,domain_prefix_len ),options );
687
- return ;
688
- }
689
-
630
+ uint8_t domain_address [16 ];
631
+ memcpy (domain_address , domain_prefix , 8 );
690
632
def_address = icmpv6_slaac_address_add (cur , domain_address , domain_prefix_len , 0xffffffff , 0xffffffff , true, SLAAC_IID_DEFAULT );
691
633
if (def_address ) {
692
634
tr_info ("Generated domain address 64: %s" , trace_ipv6 (def_address -> address ));
@@ -814,43 +756,6 @@ void thread_extension_address_registration_trigger(protocol_interface_info_entry
814
756
}
815
757
}
816
758
817
- void thread_extension_route_set (protocol_interface_info_entry_t * cur )
818
- {
819
- uint8_t domain_prefix [16 ];
820
- uint8_t domain_prefix_len ;
821
- if (0 == thread_extension_network_prefix_get (cur -> id , NULL , domain_prefix , & domain_prefix_len )) {
822
- tr_info ("domain prefix route handling" );
823
- // If we are Primary BBR we dont do this, but we dont know when we become it so We must remove this if selected as pBBR
824
- if (ipv6_route_add (domain_prefix , domain_prefix_len , cur -> id , NULL , ROUTE_THREAD , 0xffffffff , 0 ) == NULL ) {
825
- tr_error ("fail to add domain prefix route" );
826
- }
827
- }
828
- }
829
- void thread_extension_activate (protocol_interface_info_entry_t * cur )
830
- {
831
- uint8_t domain_prefix [16 ];
832
- uint8_t domain_prefix_len ;
833
- if (0 == thread_extension_network_prefix_get (cur -> id , NULL , domain_prefix , & domain_prefix_len )) {
834
- // Domain prefix available create DUA address.
835
- // Domain prefix is allways context id 1
836
- tr_info ("domain prefix Context created" );
837
- lowpan_context_update (& cur -> lowpan_contexts , LOWPAN_CONTEXT_C | 1 , 0xFFFF , domain_prefix , domain_prefix_len , true);
838
-
839
- }
840
- }
841
-
842
- bool thread_extension_context_can_delete (int8_t id , uint8_t servicesPrefix [16 ], uint8_t context_prefix_length )
843
- {
844
- uint8_t domain_prefix [16 ];
845
- uint8_t domain_prefix_len ;
846
- if (0 == thread_extension_network_prefix_get (id , NULL ,domain_prefix , & domain_prefix_len )) {
847
- if (context_prefix_length == domain_prefix_len && memcmp (domain_prefix , servicesPrefix , context_prefix_length /8 ) == 0 ) {
848
- return false;
849
- }
850
- }
851
- return true;
852
- }
853
-
854
759
bool thread_extension_enabled (protocol_interface_info_entry_t * cur )
855
760
{
856
761
if (thread_info (cur )-> version <= THREAD_PROTOCOL_VERSION ) {
@@ -966,6 +871,29 @@ static int thread_extension_relay_tx_cb(int8_t service_id, uint8_t source_addres
966
871
return -1 ; // OK no response sent
967
872
}
968
873
874
+ static bool thread_extension_is_domain_prefix (protocol_interface_info_entry_t * interface , const uint8_t * addr )
875
+ {
876
+ uint8_t address [16 ];
877
+ memcpy (address , addr , 16 );
878
+ thread_prefix_tlv_t prefixTlv ;
879
+ prefixTlv .domainId = 0 ;
880
+ prefixTlv .Prefix = address ;
881
+ prefixTlv .PrefixLen = 64 ;
882
+ thread_network_data_prefix_cache_entry_t * prefix_entry = NULL ;
883
+ thread_network_data_cache_entry_t * networkDataCache = & interface -> thread_info -> networkDataStorage ;
884
+ prefix_entry = thread_prefix_entry_find (& networkDataCache -> localPrefixList , & prefixTlv );
885
+ if (!prefix_entry ) {
886
+ return false;
887
+ }
888
+ ns_list_foreach (thread_network_server_data_entry_t , brEntry , & prefix_entry -> borderRouterList ) {
889
+ if (brEntry -> P_res1 ) {
890
+ return true;
891
+ }
892
+ }
893
+ return false;
894
+
895
+ }
896
+
969
897
static void thread_extension_relay_socket_cb (void * cb_res )
970
898
{
971
899
socket_callback_t * sckt_data = 0 ;
0 commit comments