37
37
#include "6LoWPAN/ws/ws_bbr_api_internal.h"
38
38
#include "DHCPv6_Server/DHCPv6_server_service.h"
39
39
40
+ #include "ws_bbr_api.h"
41
+
40
42
#define TRACE_GROUP "wsbs"
41
43
42
44
#define RPL_INSTANCE_ID 1
49
51
*
50
52
*/
51
53
static int8_t backbone_interface_id = -1 ; // BBR backbone information
54
+ static uint16_t configuration = BBR_ULA_C | BBR_GUA_C | BBR_GUA_ROUTE ;
52
55
53
56
static uint8_t static_dodag_prefix [8 ] = {0xfd , 0x00 , 0x61 , 0x72 , 0x6d };
54
57
static uint8_t static_ula_address [16 ] = {0 };
@@ -109,15 +112,10 @@ static void ws_bbr_rpl_root_start(uint8_t *dodag_id)
109
112
tr_err ("RPL dodag init failed" );
110
113
return ;
111
114
}
112
- memcpy (static_dodag_id , dodag_id , 16 );
113
-
114
115
// RPL memory limits set larger for Border router
115
116
rpl_control_set_memory_limits (64 * 1024 , 0 );
116
-
117
- uint8_t t_flags = PIO_A ;
118
-
119
- rpl_control_update_dodag_prefix (protocol_6lowpan_rpl_root_dodag , dodag_id , 64 , t_flags , 7200 , 7200 , false);
120
- rpl_control_update_dodag_route (protocol_6lowpan_rpl_root_dodag , dodag_id , 64 , 0x18 , 7200 , false);
117
+ // Save configured static id to check for changes later
118
+ memcpy (static_dodag_id , dodag_id , 16 );
121
119
}
122
120
123
121
static void ws_bbr_rpl_root_stop (void )
@@ -130,6 +128,17 @@ static void ws_bbr_rpl_root_stop(void)
130
128
memset (global_dodag_id , 0 , 16 );
131
129
}
132
130
131
+ static void ws_bbr_ula_prefix_enable (uint8_t * dodag_id )
132
+ {
133
+ tr_info ("RPL ula prefix start" );
134
+
135
+ uint8_t t_flags = PIO_A ;
136
+
137
+ rpl_control_update_dodag_prefix (protocol_6lowpan_rpl_root_dodag , dodag_id , 64 , t_flags , 7200 , 7200 , false);
138
+ rpl_control_update_dodag_route (protocol_6lowpan_rpl_root_dodag , dodag_id , 64 , 0x18 , 7200 , false);
139
+ }
140
+
141
+
133
142
static int ws_border_router_proxy_validate (int8_t interface_id , uint8_t * address )
134
143
{
135
144
@@ -267,6 +276,35 @@ static bool wisun_dhcp_address_add_cb(int8_t interfaceId, dhcp_address_cache_upd
267
276
return true;
268
277
}
269
278
279
+ static void ws_bbr_dhcp_server_start (protocol_interface_info_entry_t * cur , uint8_t * global_id )
280
+ {
281
+ uint8_t ll [16 ];
282
+ memcpy (ll , ADDR_LINK_LOCAL_PREFIX , 8 );
283
+ memcpy (& ll [8 ], cur -> mac , 8 );
284
+ ll [8 ] ^= 2 ;
285
+
286
+ tr_debug ("DHCP server activate %s" , trace_ipv6 (global_id ));
287
+
288
+ if (DHCPv6_server_service_init (cur -> id , global_id , cur -> mac , DHCPV6_DUID_HARDWARE_IEEE_802_NETWORKS_TYPE ) != 0 ) {
289
+ tr_error ("DHCPv6 Server create fail" );
290
+ return ;
291
+ }
292
+ DHCPv6_server_service_callback_set (cur -> id , global_id , NULL , wisun_dhcp_address_add_cb );
293
+
294
+ DHCPv6_server_service_set_address_autonous_flag (cur -> id , global_id , true);
295
+ DHCPv6_server_service_set_address_validlifetime (cur -> id , global_id , 7200 );
296
+
297
+ ws_dhcp_client_address_request (cur , global_id , ll );
298
+ }
299
+ static void ws_bbr_dhcp_server_stop (protocol_interface_info_entry_t * cur , uint8_t * global_id )
300
+ {
301
+ tr_debug ("DHCP server deactivate %s" , trace_ipv6 (global_id ));
302
+ DHCPv6_server_service_delete (cur -> id , global_id , false);
303
+
304
+ // Set old addresses to deferred and timeout
305
+ ws_dhcp_client_address_delete (cur , global_id );
306
+
307
+ }
270
308
271
309
static void ws_bbr_rpl_status_check (protocol_interface_info_entry_t * cur )
272
310
{
@@ -278,56 +316,64 @@ static void ws_bbr_rpl_status_check(protocol_interface_info_entry_t *cur)
278
316
279
317
ws_bbr_dodag_get (cur , static_id , global_id );
280
318
319
+ // Check if we need to wait for Global ID
320
+ if (configuration & BBR_GUA_WAIT ) {
321
+ if (memcmp (global_dodag_id , ADDR_UNSPECIFIED , 16 ) == 0 &&
322
+ memcmp (global_id , ADDR_UNSPECIFIED , 16 ) == 0 ) {
323
+ // We need to wait for Global connectivity to start anything
324
+ return ;
325
+ }
326
+ }
327
+
281
328
if (memcmp (static_dodag_id , static_id , 16 ) != 0 ) {
282
329
// Static id updated or first setup
283
330
ws_bbr_rpl_root_start (static_id );
331
+ if (configuration & BBR_ULA_C ) {
332
+ // Start static ULA prefix and routing always
333
+ ws_bbr_ula_prefix_enable (static_id );
334
+ }
284
335
}
336
+
285
337
if (memcmp (global_dodag_id , global_id , 16 ) != 0 ) {
286
338
// Global prefix changed
287
339
if (memcmp (global_dodag_id , ADDR_UNSPECIFIED , 16 ) != 0 ) {
288
340
// TODO remove old global prefix
289
341
tr_info ("RPL GUA deactivate %s" , trace_ipv6 (global_dodag_id ));
290
342
291
- rpl_control_update_dodag_prefix (protocol_6lowpan_rpl_root_dodag , static_dodag_id , 64 , PIO_A , 7200 , 7200 , false);
292
- rpl_control_update_dodag_route (protocol_6lowpan_rpl_root_dodag , static_dodag_id , 64 , 0x18 , 7200 , false);
293
-
294
343
// Old backbone information is deleted after 120 seconds
295
344
rpl_control_update_dodag_route (protocol_6lowpan_rpl_root_dodag , NULL , 0 , 0 , 120 , true);
296
345
rpl_control_update_dodag_prefix (protocol_6lowpan_rpl_root_dodag , global_dodag_id , 64 , 0 , 120 , 0 , true);
297
346
rpl_control_update_dodag_route (protocol_6lowpan_rpl_root_dodag , global_dodag_id , 64 , 0 , 120 , true);
298
347
ipv6_route_add_with_info (global_dodag_id , 64 , backbone_interface_id , NULL , ROUTE_THREAD_BBR , NULL , 0 , 120 , 0 );
299
- DHCPv6_server_service_delete (cur -> id , global_dodag_id , false);
300
348
301
- // Set old addresses to deferred and timeout
302
- ws_dhcp_client_address_delete (cur , global_dodag_id );
349
+ ws_bbr_dhcp_server_stop (cur , global_dodag_id );
303
350
}
304
351
// TODO add global prefix
305
352
if (memcmp (global_id , ADDR_UNSPECIFIED , 16 ) != 0 ) {
306
- //DHCPv6 Server set here
307
- //Interface LL64 address
308
- uint8_t ll [16 ];
309
- memcpy (ll , ADDR_LINK_LOCAL_PREFIX , 8 );
310
- memcpy (& ll [8 ], cur -> mac , 8 );
311
- ll [8 ] ^= 2 ;
312
-
313
- if (DHCPv6_server_service_init (cur -> id , global_id , cur -> mac , DHCPV6_DUID_HARDWARE_IEEE_802_NETWORKS_TYPE ) != 0 ) {
314
- tr_error ("DHCPv6 Server create fail" );
315
- return ;
316
- }
317
- DHCPv6_server_service_callback_set (cur -> id , global_id , NULL , wisun_dhcp_address_add_cb );
318
-
319
- DHCPv6_server_service_set_address_autonous_flag (cur -> id , global_id , true);
320
- DHCPv6_server_service_set_address_validlifetime (cur -> id , global_id , 7200 );
321
-
322
- tr_info ("RPL GUA activate %s" , trace_ipv6 (global_id ));
323
- ws_dhcp_client_address_request (cur , global_id , ll );
353
+ //DHCPv6 Server flags set 0 by default
354
+ uint8_t t_flags = 0 ;
324
355
356
+ // Add default route to RPL
325
357
rpl_control_update_dodag_route (protocol_6lowpan_rpl_root_dodag , NULL , 0 , 0 , 7200 , false);
326
- rpl_control_update_dodag_prefix (protocol_6lowpan_rpl_root_dodag , static_dodag_id , 64 , PIO_A , 7200 , 7200 , false);
327
- rpl_control_update_dodag_route (protocol_6lowpan_rpl_root_dodag , static_dodag_id , 64 , 0x18 , 7200 , false);
328
- rpl_control_update_dodag_prefix (protocol_6lowpan_rpl_root_dodag , global_id , 64 , 0 , 7200 , 7200 , false);
329
- rpl_control_update_dodag_route (protocol_6lowpan_rpl_root_dodag , global_id , 64 , 0 , 7200 , false);
358
+ // Enable default routing to backbone
330
359
ipv6_route_add_with_info (global_id , 64 , backbone_interface_id , NULL , ROUTE_THREAD_BBR , NULL , 0 , 0xffffffff , 0 );
360
+
361
+ if (configuration & BBR_GUA_SLAAC ) {
362
+ // GUA prefix is using SLAAC so no DHCP started and set correct flags for prefix
363
+ t_flags = PIO_A ;
364
+ } else {
365
+ ws_bbr_dhcp_server_start (cur , global_id );
366
+ }
367
+
368
+ if (configuration & BBR_GUA_C ) {
369
+ // Add also global prefix and route to RPL
370
+ rpl_control_update_dodag_prefix (protocol_6lowpan_rpl_root_dodag , global_id , 64 , t_flags , 7200 , 7200 , false);
371
+ }
372
+ if (configuration & BBR_GUA_ROUTE ) {
373
+ // Add also global prefix and route to RPL
374
+ rpl_control_update_dodag_route (protocol_6lowpan_rpl_root_dodag , global_id , 64 , 0 , 7200 , false);
375
+ }
376
+
331
377
}
332
378
memcpy (global_dodag_id , global_id , 16 );
333
379
rpl_control_increment_dodag_version (protocol_6lowpan_rpl_root_dodag );
@@ -426,7 +472,29 @@ uint16_t ws_bbr_pan_size(protocol_interface_info_entry_t *cur)
426
472
return result ;
427
473
}
428
474
475
+ bool ws_bbr_ready_to_start (protocol_interface_info_entry_t * cur )
476
+ {
429
477
478
+ (void )cur ;
479
+ uint8_t global_address [16 ];
480
+
481
+ if (backbone_interface_id < 0 ) {
482
+ // No need to wait for backbone
483
+ return true;
484
+ }
485
+
486
+ if ((configuration & BBR_BB_WAIT ) != BBR_BB_WAIT ) {
487
+ // No need to wait for backbone
488
+ return true;
489
+ }
490
+
491
+ if (arm_net_address_get (backbone_interface_id , ADDR_IPV6_GP , global_address ) != 0 ) {
492
+ // No global prefix available
493
+ return false;
494
+ }
495
+
496
+ return true;
497
+ }
430
498
#endif //HAVE_WS_BORDER_ROUTER
431
499
432
500
/* Public APIs
@@ -472,6 +540,24 @@ void ws_bbr_stop(int8_t interface_id)
472
540
(void )interface_id ;
473
541
#endif
474
542
}
543
+ int ws_bbr_configure (int8_t interface_id , uint16_t options )
544
+ {
545
+ #ifdef HAVE_WS_BORDER_ROUTER
546
+
547
+ (void )interface_id ;
548
+ if (protocol_6lowpan_rpl_root_dodag &&
549
+ options != configuration ) {
550
+ //Configuration changed delete previus setup
551
+ ws_bbr_rpl_root_stop ();
552
+ }
553
+ configuration = options ;
554
+ return 0 ;
555
+ #else
556
+ (void )interface_id ;
557
+ (void )options ;
558
+ return -1 ;
559
+ #endif
560
+ }
475
561
476
562
int ws_bbr_node_keys_remove (int8_t interface_id , uint8_t * eui64 )
477
563
{
0 commit comments