Mbed OS Reference
Loading...
Searching...
No Matches
WisunBorderRouter.h
1/*
2 * Copyright (c) 2020 ARM Limited. All rights reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 * Licensed under the Apache License, Version 2.0 (the License); you may
5 * not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef WISUNBORDERROUTER_H
18#define WISUNBORDERROUTER_H
19
20/**
21 * \brief Struct br_information Border router dynamic information.
22 */
23typedef struct ws_br_info {
24 /** Address prefix given to devices in network set to 0 if not available*/
25 uint8_t ipv6_prefix[8];
26 /** IID of Border router */
27 uint8_t ipv6_iid[8];
28 /** Border router dodag id */
29 uint8_t rpl_dodag_id[16];
30 /** Border router instance identifier defined in RPL */
31 uint8_t instance_id;
32 /** RPL version number */
33 uint8_t version;
34 /** Timestamp of the the device. Can be used as version number*/
36 /** Amount of devices in the network. */
37 uint16_t device_count;
38 /** Gateway Local Address */
39 uint8_t gateway_addr[16];
41
42/**
43 * \brief Struct br_route_info is parent child relation structure.
44 */
45typedef struct ws_br_route_info {
46 /** IID of target device
47 * Public IPv6 address can be formed by combining prefix + IID*/
48 uint8_t target[8];
49 /** IID of parent*/
50 uint8_t parent[8];
52
53/**
54 * \brief Struct ws_br_radius_timing_t is RADIUS timing configuration structure.
55 */
56typedef struct ws_br_radius_timing {
57 /** RADIUS retry trickle timer Imin; in 100ms units; range 1-1200; default 20 (2 seconds) */
59 /** RADIUS retry trickle timer Imax; in 100ms units; range 1-1200; default 30 (3 seconds) */
61 /** RADIUS retry trickle count; default 3 */
64
65/** Wi-SUN Border Router class
66 *
67 * Class can be used to start, stop and configure Wi-SUN Border Router.
68 */
70public:
71
72 /** Create WisunBorderRouter
73 *
74 * */
76
77 /**
78 * \brief Start Wi-SUN Border Router
79 *
80 * Starts Wi-SUN Border Router and routing between the mesh and backbone interfaces. Network interfaces
81 * must be initialized and connected before calling the start. Backbone interface can be either Ethernet
82 * (EMAC) or Cellular.
83 *
84 * \param mesh_if Wi-SUN mesh network interface
85 * \param backbone_if Backbone network interface
86 * \return MESH_ERROR_NONE on success.
87 * \return MESH_ERROR_UNKNOWN in case of failure.
88 * */
89 mesh_error_t start(WisunInterface *mesh_if, NetworkInterface *backbone_if);
90
91 /**
92 * \brief Start Wi-SUN Border Router
93 *
94 * Starts Wi-SUN Border Router and routing between the mesh and backbone interfaces. Network interfaces
95 * must be initialized and connected before calling the start. Backbone interface can be either Ethernet
96 * (EMAC) or Cellular.
97 *
98 * \param mesh_if Wi-SUN mesh network interface
99 * \param backbone_if Backbone network interface
100 * \return MESH_ERROR_NONE on success.
101 * \return MESH_ERROR_UNKNOWN in case of failure.
102 * */
103 MBED_DEPRECATED_SINCE("mbed-os-6.10.0", "Using NetworkInterface type for mesh_if is deprecated, use WisunInterface instead")
104 mesh_error_t start(NetworkInterface *mesh_if, NetworkInterface *backbone_if);
105
106 /**
107 * \brief Start Wi-SUN Border Router
108 *
109 * Starts Wi-SUN Border Router and routing between the mesh and backbone interfaces. Mesh network interface
110 * must be initialized and connected before calling the start. Backbone OnboardNetworkStack::Interface must
111 * be brought up before calling the start. Backbone interface can be either Ethernet (EMAC) or Cellular (PPP).
112 *
113 * \param mesh_if Wi-SUN mesh network interface
114 * \param backbone_if Backbone OnboardNetworkStack::Interface interface
115 * \return MESH_ERROR_NONE on success.
116 * \return MESH_ERROR_UNKNOWN in case of failure.
117 * */
118 mesh_error_t start(WisunInterface *mesh_if, OnboardNetworkStack::Interface *backbone_if);
119
120 /**
121 * \brief Start Wi-SUN Border Router
122 *
123 * Starts Wi-SUN Border Router and routing between the mesh and backbone interfaces. Mesh network interface
124 * must be initialized and connected before calling the start. Backbone OnboardNetworkStack::Interface must
125 * be brought up before calling the start. Backbone interface can be either Ethernet (EMAC) or Cellular (PPP).
126 *
127 * \param mesh_if Wi-SUN mesh network interface
128 * \param backbone_if Backbone OnboardNetworkStack::Interface interface
129 * \return MESH_ERROR_NONE on success.
130 * \return MESH_ERROR_UNKNOWN in case of failure.
131 * */
132 MBED_DEPRECATED_SINCE("mbed-os-6.10.0", "Using NetworkInterface type for mesh_if is deprecated, use WisunInterface instead")
133 mesh_error_t start(NetworkInterface *mesh_if, OnboardNetworkStack::Interface *backbone_if);
134
135 /**
136 * \brief Stop Wi-SUN Border Router
137 *
138 * Stops Wi-SUN Border Router.
139 *
140 * */
141 void stop();
142
143 /**
144 * \brief Set Wi-SUN RPL DIO trickle parameters.
145 *
146 * Function stores new parameters to Border Router and uses them when mesh interface connect() is called
147 * next time. If device is already connected to the Wi-SUN network then device will restart Wi-SUN network after
148 * changing the RPL DIO trickle parameters. Mesh interface must be initialized before calling this
149 * function.
150 *
151 * \param dio_interval_min DIO trickle timer Imin parameter. Use 0x00 to use leave parameter unchanged.
152 * \param dio_interval_doublings DIO trickle timer Imax parameter as doublings of Imin. Use 0x00 to use leave parameter unchanged.
153 * \param dio_redundancy_constant DIO trickle timer redundancy constant. Use 0xff to use leave parameter unchanged.
154 * \return MESH_ERROR_NONE on success.
155 * \return MESH_ERROR_UNKNOWN in case of failure.
156 * */
157 mesh_error_t set_rpl_parameters(uint8_t dio_interval_min, uint8_t dio_interval_doublings, uint8_t dio_redundancy_constant);
158
159 /**
160 * \brief Get Wi-SUN RPL DIO trickle parameters.
161 *
162 * Function reads DIO trickle timer Imin, DIO trickle timer Imax and DIO trickle timer redundancy
163 * constant from Border Router. Mesh interface must be initialized before calling this function.
164 *
165 * \param dio_interval_min DIO trickle timer Imin parameter.
166 * \param dio_interval_doublings DIO trickle timer Imax parameter as doublings of Imin.
167 * \param dio_redundancy_constant DIO trickle timer redundancy constant.
168 * \return MESH_ERROR_NONE on success.
169 * \return MESH_ERROR_UNKNOWN in case of failure.
170 * */
171 mesh_error_t get_rpl_parameters(uint8_t *dio_interval_min, uint8_t *dio_interval_doublings, uint8_t *dio_redundancy_constant);
172
173 /**
174 * \brief Validate Wi-SUN RPL DIO trickle parameters.
175 *
176 * Function validates DIO trickle timer Imin, DIO trickle timer Imax and DIO trickle timer redundancy
177 * constant. Function can be used to test that values that will be used on set function are valid.
178 * Mesh interface must be initialized before the calling this function.
179 *
180 * \param dio_interval_min DIO trickle timer Imin parameter.
181 * \param dio_interval_doublings DIO trickle timer Imax parameter as doublings of Imin.
182 * \param dio_redundancy_constant DIO trickle timer redundancy constant.
183 * \return MESH_ERROR_NONE on success.
184 * \return MESH_ERROR_UNKNOWN in case of failure.
185 * */
186 mesh_error_t validate_rpl_parameters(uint8_t dio_interval_min, uint8_t dio_interval_doublings, uint8_t dio_redundancy_constant);
187
188 /**
189 * \brief Set Wi-SUN PAN configuration parameters.
190 *
191 * Function stores new parameters to Border Router and uses them when mesh interface connect() is called
192 * next time. If device is already connected to the Wi-SUN network then device will restart Wi-SUN network after
193 * changing the PAN configuration parameters. Mesh interface must be initialized before calling this
194 * function.
195 *
196 * \param pan_id PAN ID. 0xffff will generate the PAN ID on the mesh interface connect() call if not already generated.
197 * \return MESH_ERROR_NONE on success.
198 * \return MESH_ERROR_UNKNOWN in case of failure.
199 * */
200 mesh_error_t set_pan_configuration(uint16_t pan_id);
201
202 /**
203 * \brief Get Wi-SUN PAN configuration parameters.
204 *
205 * Function reads PAN ID from Border Router. Mesh interface must be initialized before calling this function.
206 *
207 * \param pan_id PAN ID.
208 * \return MESH_ERROR_NONE on success.
209 * \return MESH_ERROR_UNKNOWN in case of failure.
210 * */
211 mesh_error_t get_pan_configuration(uint16_t *pan_id);
212
213 /**
214 * \brief Validate Wi-SUN PAN configuration parameters.
215 *
216 * Function validates PAN ID. Function can be used to test that values that will be used on set function are valid.
217 * Mesh interface must be initialized before calling this function.
218 *
219 * \param pan_id PAN ID.
220 * \return MESH_ERROR_NONE on success.
221 * \return MESH_ERROR_UNKNOWN in case of failure.
222 * */
223 mesh_error_t validate_pan_configuration(uint16_t pan_id);
224
225 /**
226 * \brief Get Wi-SUN Border Router information.
227 *
228 * Function reads RPL information from Border Router.
229 * Mesh interface must be initialized before calling this function.
230 *
231 * \param info_ptr Structure given to stack where information will be stored
232 *
233 * \return MESH_ERROR_NONE on success.
234 * \return MESH_ERROR_UNKNOWN in case of failure.
235 * */
236 mesh_error_t info_get(ws_br_info_t *info_ptr);
237
238 /**
239 * \brief Get Wi-SUN neighbor table information.
240 *
241 * Function reads Routing Table information from Border Router.
242 * Table is Parent child relation using the Global address IID of the devices.
243 * To get the full IPv6 address of the device, IPv6 = Global Prefix + IID.
244 * Mesh interface must be initialized before calling this function.
245 *
246 * \param table_ptr Application allocated memory block where routing table is written.
247 * \param table_len Length of the table allocated by application given as amount of entries.
248 *
249 * \returns 0 - x on success indicates number of entries written to the table_ptr.
250 * \return <0 in case of errors.
251 * */
252 int routing_table_get(ws_br_route_info_t *table_ptr, uint16_t table_len);
253
254 /**
255 * \brief Set Wi-SUN RADIUS server IPv6 address.
256 *
257 * Function sets external RADIUS server IPv6 address to Border Router. Setting the address enables
258 * external RADIUS server interface on Border Router. To disable external RADIUS server interface,
259 * call the function with address set to NULL. The RADIUS shared secret must be set before address
260 * is set using set_radius_shared_secret() call.
261 *
262 * \param address Pointer to IPv6 address string or NULL to disable RADIUS. Address string format is e.g. 2001:1234::1 and it is NUL terminated.
263 * \return MESH_ERROR_NONE on success.
264 * \return MESH_ERROR_UNKNOWN in case of failure.
265 * */
266 mesh_error_t set_radius_server_ipv6_address(const char *address);
267
268 /**
269 * \brief Get Wi-SUN RADIUS server IPv6 address.
270 *
271 * Function gets external RADIUS server IPv6 address from Border Router.
272 *
273 * \param address Pointer to buffer where to write IPv6 address string. Must have space at least for 39 characters and NUL terminator.
274 * \return MESH_ERROR_NONE on success.
275 * \return error value in case of failure, e.g. if address has not been set to Border Router.
276 * */
277 mesh_error_t get_radius_server_ipv6_address(char *address);
278
279 /**
280 * \brief Set Wi-SUN RADIUS shared secret.
281 *
282 * Function sets RADIUS shared secret to Border Router. Shared secret may be an ASCII string. Check
283 * the format and length constraints for the shared secret from the documentation of RADIUS server you
284 * are connecting to.
285 *
286 * \param shared_secret_len The length of the shared secret in bytes.
287 * \param shared_secret Pointer to shared secret. Can be 8-bit ASCII string or byte array. Is not NUL terminated.
288 * \return MESH_ERROR_NONE on success.
289 * \return error value in case of failure.
290 * */
291 mesh_error_t set_radius_shared_secret(uint16_t shared_secret_len, const uint8_t *shared_secret);
292
293 /**
294 * \brief Get Wi-SUN RADIUS shared secret.
295 *
296 * Function gets RADIUS shared secret from Border Router.
297 *
298 * \param shared_secret_len On function call, is the size of the shared secret write buffer in bytes, on return is the shared secret length in bytes.
299 * \param shared_secret Pointer to buffer where to write shared secret or NULL. At maximum, bytes set by the length parameter are written. If NULL only buffer length is returned.
300 * \return MESH_ERROR_NONE on success.
301 * \return error value in case of failure.
302 * */
303 mesh_error_t get_radius_shared_secret(uint16_t *shared_secret_len, uint8_t *shared_secret);
304
305 /**
306 * \brief Set Wi-SUN RADIUS timing parameters.
307 *
308 * Function sets RADIUS timing parameters to Border Router. For RADIUS retry trickle timer default
309 * settings are that the first retry is done between 1 to 3 seconds after the initial attempt and
310 * all retries are done in maximum in 9 seconds.
311 *
312 * \param timing Timing parameters.
313 * \return MESH_ERROR_NONE on success.
314 * \return error value in case of failure.
315 * */
317
318 /**
319 * \brief Get Wi-SUN RADIUS timing parameters.
320 *
321 * Function gets RADIUS timing parameters from Border Router.
322 *
323 * \param timing Timing parameters.
324 * \return MESH_ERROR_NONE on success.
325 * \return error value in case of failure.
326 * */
328
329 /**
330 * \brief Validate Wi-SUN RADIUS timing parameters.
331 *
332 * Function validates RADIUS timing parameters on Border Router.
333 *
334 * \param timing Timing parameters.
335 * \return MESH_ERROR_NONE on success.
336 * \return error value in case of failure.
337 * */
339
340 /**
341 * \brief Set DNS query result to Nanostack cache.
342 *
343 * Function sets DNS query result to Nanostack cache to get distributed to the devices in the Wi-SUN network.
344 * Function must be called for a running Wi-SUN Border Router instance.
345 *
346 * \param address resolved address of domain_name.
347 * \param domain_name name of the domain. Must be non-NULL.
348 * \return MESH_ERROR_NONE on success.
349 * \return error value in case of failure.
350 * */
351 mesh_error_t set_dns_query_result(SocketAddress *address, char *domain_name);
352
353private:
354 mesh_error_t configure();
355 mesh_error_t apply_configuration(int8_t mesh_if_id);
356 mesh_error_t set_bbr_radius_address(void);
357 mesh_error_t set_bbr_radius_shared_secret(void);
358 mesh_error_t set_bbr_radius_timing(void);
359 char _radius_ipv6_addr[40];
360 ws_br_radius_timing_t _radius_timing = {
362 .radius_retry_imax = 0,
363 .radius_retry_count = 0
364 };
365 char *_shared_secret = NULL;
366 uint16_t _shared_secret_len = 0;
367 int8_t _mesh_if_id = -1;
368 bool _radius_ipv6_addr_set = false;
369 bool _configured = false;
370 bool _radius_timing_set = false;
371};
372
373#endif
Common interface that is shared between network devices.
mbed OS API for onboard IP stack abstraction
SocketAddress class.
Definition: SocketAddress.h:37
Wi-SUN Border Router class.
mesh_error_t get_rpl_parameters(uint8_t *dio_interval_min, uint8_t *dio_interval_doublings, uint8_t *dio_redundancy_constant)
Get Wi-SUN RPL DIO trickle parameters.
mesh_error_t set_rpl_parameters(uint8_t dio_interval_min, uint8_t dio_interval_doublings, uint8_t dio_redundancy_constant)
Set Wi-SUN RPL DIO trickle parameters.
mesh_error_t set_radius_shared_secret(uint16_t shared_secret_len, const uint8_t *shared_secret)
Set Wi-SUN RADIUS shared secret.
mesh_error_t set_radius_timing(ws_br_radius_timing_t *timing)
Set Wi-SUN RADIUS timing parameters.
mesh_error_t validate_pan_configuration(uint16_t pan_id)
Validate Wi-SUN PAN configuration parameters.
mesh_error_t info_get(ws_br_info_t *info_ptr)
Get Wi-SUN Border Router information.
int routing_table_get(ws_br_route_info_t *table_ptr, uint16_t table_len)
Get Wi-SUN neighbor table information.
mesh_error_t set_pan_configuration(uint16_t pan_id)
Set Wi-SUN PAN configuration parameters.
mesh_error_t set_radius_server_ipv6_address(const char *address)
Set Wi-SUN RADIUS server IPv6 address.
void stop()
Stop Wi-SUN Border Router.
mesh_error_t get_radius_shared_secret(uint16_t *shared_secret_len, uint8_t *shared_secret)
Get Wi-SUN RADIUS shared secret.
mesh_error_t start(WisunInterface *mesh_if, NetworkInterface *backbone_if)
Start Wi-SUN Border Router.
mesh_error_t get_pan_configuration(uint16_t *pan_id)
Get Wi-SUN PAN configuration parameters.
mesh_error_t get_radius_server_ipv6_address(char *address)
Get Wi-SUN RADIUS server IPv6 address.
mesh_error_t validate_radius_timing(ws_br_radius_timing_t *timing)
Validate Wi-SUN RADIUS timing parameters.
WisunBorderRouter()
Create WisunBorderRouter.
mesh_error_t validate_rpl_parameters(uint8_t dio_interval_min, uint8_t dio_interval_doublings, uint8_t dio_redundancy_constant)
Validate Wi-SUN RPL DIO trickle parameters.
mesh_error_t get_radius_timing(ws_br_radius_timing_t *timing)
Get Wi-SUN RADIUS timing parameters.
mesh_error_t set_dns_query_result(SocketAddress *address, char *domain_name)
Set DNS query result to Nanostack cache.
Wi-SUN mesh network interface class.
#define MBED_DEPRECATED_SINCE(D, M)
MBED_DEPRECATED("message string") Mark a function declaration as deprecated, if it used then a warnin...
Struct br_information Border router dynamic information.
uint8_t rpl_dodag_id[16]
Border router dodag id.
uint8_t ipv6_iid[8]
IID of Border router.
uint8_t ipv6_prefix[8]
Address prefix given to devices in network set to 0 if not available.
uint8_t version
RPL version number.
uint8_t instance_id
Border router instance identifier defined in RPL.
uint64_t host_timestamp
Timestamp of the the device.
uint8_t gateway_addr[16]
Gateway Local Address.
uint16_t device_count
Amount of devices in the network.
Struct ws_br_radius_timing_t is RADIUS timing configuration structure.
uint16_t radius_retry_imax
RADIUS retry trickle timer Imax; in 100ms units; range 1-1200; default 30 (3 seconds)
uint16_t radius_retry_imin
RADIUS retry trickle timer Imin; in 100ms units; range 1-1200; default 20 (2 seconds)
uint8_t radius_retry_count
RADIUS retry trickle count; default 3.
Struct br_route_info is parent child relation structure.
uint8_t target[8]
IID of target device Public IPv6 address can be formed by combining prefix + IID.
uint8_t parent[8]
IID of parent.