19
19
#include " WisunBorderRouter.h"
20
20
#include " MeshInterfaceNanostack.h"
21
21
#include " net_interface.h"
22
+ #include " ip6string.h"
22
23
23
24
extern " C" {
24
25
#include " ws_bbr_api.h"
25
26
}
26
27
27
28
#define TRACE_GROUP " WSBR"
28
29
30
+
31
+ WisunBorderRouter::WisunBorderRouter ()
32
+ {
33
+ // Apply mbed configuration to Wi-SUN BBR
34
+ configure ();
35
+ }
36
+
29
37
mesh_error_t WisunBorderRouter::start (NetworkInterface *mesh_if, NetworkInterface *backbone_if)
30
38
{
31
39
if (mesh_if == NULL || backbone_if == NULL ) {
@@ -53,6 +61,8 @@ mesh_error_t WisunBorderRouter::start(NetworkInterface *mesh_if, NetworkInterfac
53
61
return MESH_ERROR_UNKNOWN;
54
62
}
55
63
64
+ apply_configuration (mesh_if_id);
65
+
56
66
int ret = ws_bbr_start (mesh_if_id, backbone_if_id);
57
67
if (ret < 0 ) {
58
68
return MESH_ERROR_UNKNOWN;
@@ -76,6 +86,8 @@ mesh_error_t WisunBorderRouter::start(NetworkInterface *mesh_if, OnboardNetworkS
76
86
return MESH_ERROR_UNKNOWN;
77
87
}
78
88
89
+ apply_configuration (mesh_if_id);
90
+
79
91
int ret = ws_bbr_start (mesh_if_id, backbone_if_id);
80
92
if (ret < 0 ) {
81
93
return MESH_ERROR_UNKNOWN;
@@ -95,6 +107,55 @@ void WisunBorderRouter::stop()
95
107
_mesh_if_id = -1 ;
96
108
}
97
109
110
+ mesh_error_t WisunBorderRouter::configure ()
111
+ {
112
+ #if defined(MBED_CONF_MBED_MESH_API_RADIUS_SHARED_SECRET) || defined(MBED_CONF_MBED_MESH_API_RADIUS_SERVER_IPV6_ADDRESS)
113
+ mesh_error_t status;
114
+ #endif
115
+
116
+ if (_configured) {
117
+ // Already configured
118
+ return MESH_ERROR_NONE;
119
+ }
120
+
121
+ _configured = true ;
122
+
123
+ #ifdef MBED_CONF_MBED_MESH_API_RADIUS_SHARED_SECRET
124
+ const char radius_shared_secret[] = {MBED_CONF_MBED_MESH_API_RADIUS_SHARED_SECRET};
125
+ #ifdef MBED_CONF_MBED_MESH_API_RADIUS_SHARED_SECRET_LEN
126
+ const uint16_t radius_shared_secret_len = MBED_CONF_MBED_MESH_API_RADIUS_SHARED_SECRET_LEN;
127
+ #else
128
+ uint16_t radius_shared_secret_len = strlen (radius_shared_secret);
129
+ #endif
130
+ status = set_radius_shared_secret (radius_shared_secret_len, (uint8_t *) radius_shared_secret);
131
+ if (status != MESH_ERROR_NONE) {
132
+ tr_error (" Failed to set RADIUS shared secret!" );
133
+ return status;
134
+ }
135
+ #endif
136
+
137
+ #ifdef MBED_CONF_MBED_MESH_API_RADIUS_SERVER_IPV6_ADDRESS
138
+ const char radius_server_ipv6_addr[] = {MBED_CONF_MBED_MESH_API_RADIUS_SERVER_IPV6_ADDRESS};
139
+ status = set_radius_server_ipv6_address (radius_server_ipv6_addr);
140
+ if (status != MESH_ERROR_NONE) {
141
+ tr_error (" Failed to set RADIUS server IPv6 address!" );
142
+ return status;
143
+ }
144
+ #endif
145
+
146
+ return MESH_ERROR_NONE;
147
+ }
148
+
149
+ mesh_error_t WisunBorderRouter::apply_configuration (int8_t mesh_if_id)
150
+ {
151
+ mesh_error_t status = set_bbr_radius_address ();
152
+ if (status != MESH_ERROR_NONE) {
153
+ tr_error (" Failed to apply RADIUS server IPv6 address!" );
154
+ return MESH_ERROR_PARAM;
155
+ }
156
+ return MESH_ERROR_NONE;
157
+ }
158
+
98
159
mesh_error_t WisunBorderRouter::set_rpl_parameters (uint8_t dio_interval_min, uint8_t dio_interval_doublings, uint8_t dio_redundancy_constant)
99
160
{
100
161
int status = ws_bbr_rpl_parameters_set (_mesh_if_id, dio_interval_min, dio_interval_doublings, dio_redundancy_constant);
@@ -188,3 +249,78 @@ int WisunBorderRouter::routing_table_get(ws_br_route_info_t *table_ptr, uint16_t
188
249
189
250
return ws_bbr_routing_table_get (_mesh_if_id, (bbr_route_info_t *)table_ptr, table_len);
190
251
}
252
+
253
+ mesh_error_t WisunBorderRouter::set_radius_server_ipv6_address (const char *address)
254
+ {
255
+ if (address) {
256
+ uint8_t ipv6_addr[16 ];
257
+ if (!stoip6 (address, strlen (address), ipv6_addr)) {
258
+ return MESH_ERROR_PARAM;
259
+ }
260
+ // Stored address (returned by get) is in the format given by user of the interface
261
+ strcpy (_radius_ipv6_addr, address);
262
+ _radius_ipv6_addr_set = true ;
263
+ } else {
264
+ _radius_ipv6_addr_set = false ;
265
+ }
266
+
267
+ return set_bbr_radius_address ();
268
+ }
269
+
270
+ mesh_error_t WisunBorderRouter::get_radius_server_ipv6_address (char *address)
271
+ {
272
+ if (!_radius_ipv6_addr_set) {
273
+ return MESH_ERROR_UNKNOWN;
274
+ }
275
+ strcpy (address, _radius_ipv6_addr);
276
+
277
+ return MESH_ERROR_NONE;
278
+ }
279
+
280
+ mesh_error_t WisunBorderRouter::set_bbr_radius_address (void )
281
+ {
282
+ int status;
283
+
284
+ if (_radius_ipv6_addr_set) {
285
+ uint8_t ipv6_addr[16 ];
286
+ if (!stoip6 (_radius_ipv6_addr, strlen (_radius_ipv6_addr), ipv6_addr)) {
287
+ return MESH_ERROR_PARAM;
288
+ }
289
+ status = ws_bbr_radius_address_set (_mesh_if_id, ipv6_addr);
290
+ } else {
291
+ status = ws_bbr_radius_address_set (_mesh_if_id, NULL );
292
+ }
293
+ if (status != 0 ) {
294
+ return MESH_ERROR_UNKNOWN;
295
+ }
296
+
297
+ return MESH_ERROR_NONE;
298
+ }
299
+
300
+ mesh_error_t WisunBorderRouter::set_radius_shared_secret (uint16_t shared_secret_len, const uint8_t *shared_secret)
301
+ {
302
+ if (shared_secret_len == 0 || !shared_secret) {
303
+ return MESH_ERROR_PARAM;
304
+ }
305
+
306
+ int status = ws_bbr_radius_shared_secret_set (_mesh_if_id, shared_secret_len, shared_secret);
307
+ if (status != 0 ) {
308
+ return MESH_ERROR_UNKNOWN;
309
+ }
310
+
311
+ return MESH_ERROR_NONE;
312
+ }
313
+
314
+ mesh_error_t WisunBorderRouter::get_radius_shared_secret (uint16_t *shared_secret_len, uint8_t *shared_secret)
315
+ {
316
+ if (shared_secret_len == NULL ) {
317
+ return MESH_ERROR_PARAM;
318
+ }
319
+
320
+ int status = ws_bbr_radius_shared_secret_get (_mesh_if_id, shared_secret_len, shared_secret);
321
+ if (status != 0 ) {
322
+ return MESH_ERROR_UNKNOWN;
323
+ }
324
+
325
+ return MESH_ERROR_NONE;
326
+ }
0 commit comments