Mistake on this page?
Report an issue in GitHub or email us
WisunInterface.h
1 /*
2  * Copyright (c) 2018-2019 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 WISUNINTERFACE_H
18 #define WISUNINTERFACE_H
19 
20 #include "MeshInterfaceNanostack.h"
21 
22 /**
23  * \brief Struct ws_rpl_info Wi-SUN router RPL information.
24  */
25 typedef struct ws_rpl_info {
26  /** Router dodag id */
27  uint8_t rpl_dodag_id[16];
28  /** Router instance identifier */
29  uint8_t instance_id;
30  /** RPL version number */
31  uint8_t version;
32  /** RPL DODAG node current Rank */
33  uint16_t current_rank;
34  /** RPL Primary Parent Rank */
37 
38 /**
39  * \brief Struct ws_stack_state Wi-SUN stack information.
40  */
41 typedef struct ws_stack_state {
42  /** Mesh Interface Global IPv6 Address */
43  uint8_t global_addr[16];
44  /** Mesh Interface Link Local IPv6 Address */
45  uint8_t link_local_addr[16];
46  /** Parent link local address */
47  uint8_t parent_addr[16];
48  /** parent RSSI Out measured RSSI value calculated using EWMA specified by Wi-SUN from range of -174 (0) to +80 (254) dBm.*/
49  uint8_t rsl_out;
50  /** parent RSSI in measured RSSI value calculated using EWMA specified by Wi-SUN from range of -174 (0) to +80 (254) dBm.*/
51  uint8_t rsl_in;
52  /** Wi-SUN join state defined by Wi-SUN specification 1-5 */
53  uint8_t join_state;
54  /** Network PAN ID */
55  uint16_t pan_id;
57 
58 /** Wi-SUN mesh network interface class
59  *
60  * Configure Nanostack to use Wi-SUN protocol.
61  */
62 class WisunInterface final : public MeshInterfaceNanostack {
63 public:
64  /** Inherit MeshInterfaceNanostack constructors */
65  using MeshInterfaceNanostack::MeshInterfaceNanostack;
66 
67  /**
68  * \brief Set Wi-SUN network name.
69  *
70  * Function stores new network name to mbed-mesh-api and uses it when connect() is called next time.
71  * If device is already connected to the Wi-SUN network then device will restart network discovery after
72  * changing the network name.
73  *
74  * Function overwrites network name defined by Mbed OS configuration.
75  *
76  * \param network_name Network name as NUL terminated string. Can't exceed 32 characters and can't be NULL.
77  * \return MESH_ERROR_NONE on success.
78  * \return MESH_ERROR_UNKNOWN in case of failure.
79  * */
80  mesh_error_t set_network_name(char *network_name);
81 
82  /**
83  * \brief Get Wi-SUN network name.
84  *
85  * Function reads network name from mbed-mesh-api.
86  *
87  * \param network_name Network name as NUL terminated string. Must have space for 33 characters (string and null terminator).
88  * \return MESH_ERROR_NONE on success.
89  * \return MESH_ERROR_UNKNOWN in case of failure.
90  * */
91  mesh_error_t get_network_name(char *network_name);
92 
93  /**
94  * \brief Validate Wi-SUN network name.
95  *
96  * Function validates network name. Function can be used to test that values that will be used on set function are valid.
97  *
98  * \param network_name Network name as NUL terminated string. Can't exceed 32 characters and can't be NULL.
99  * \return MESH_ERROR_NONE on success.
100  * \return MESH_ERROR_UNKNOWN in case of failure.
101  * */
102  mesh_error_t validate_network_name(char *network_name);
103 
104  /**
105  * \brief Set Wi-SUN network regulatory domain, operating class and operating mode.
106  *
107  * Function stores new parameters to mbed-mesh-api and uses them when connect() is called next time.
108  * If device is already connected to the Wi-SUN network then device will restart network discovery after
109  * changing the regulatory_domain, operating_class or operating_mode.
110  *
111  * Function overwrites parameters defined by Mbed OS configuration.
112  *
113  * \param regulatory_domain Values defined in Wi-SUN PHY-specification. Use 0xff to use leave parameter unchanged.
114  * \param operating_class Values defined in Wi-SUN PHY-specification. Use 0xff to use leave parameter unchanged.
115  * \param operating_mode Values defined in Wi-SUN PHY-specification. Use 0xff to use leave parameter unchanged.
116  * \return MESH_ERROR_NONE on success.
117  * \return MESH_ERROR_UNKNOWN in case of failure.
118  * */
119  mesh_error_t set_network_regulatory_domain(uint8_t regulatory_domain = 0xff, uint8_t operating_class = 0xff, uint8_t operating_mode = 0xff);
120 
121  /**
122  * \brief Get Wi-SUN network regulatory domain, operating class and operating mode.
123  *
124  * Function reads regulatory_domain, operating_class and operating_mode from mbed-mesh-api.
125  *
126  * \param regulatory_domain Values defined in Wi-SUN PHY-specification.
127  * \param operating_class Values defined in Wi-SUN PHY-specification.
128  * \param operating_mode Values defined in Wi-SUN PHY-specification.
129  * \return MESH_ERROR_NONE on success.
130  * \return MESH_ERROR_UNKNOWN in case of failure.
131  * */
132  mesh_error_t get_network_regulatory_domain(uint8_t *regulatory_domain, uint8_t *operating_class, uint8_t *operating_mode);
133 
134  /**
135  * \brief Validate Wi-SUN network regulatory domain, operating class and operating mode.
136  *
137  * Function validates regulatory_domain, operating_class and operating_mode. Function can be used to test that values that will
138  * be used on set function are valid.
139  *
140  * \param regulatory_domain Values defined in Wi-SUN PHY-specification.
141  * \param operating_class Values defined in Wi-SUN PHY-specification.
142  * \param operating_mode Values defined in Wi-SUN PHY-specification.
143  * \return MESH_ERROR_NONE on success.
144  * \return MESH_ERROR_UNKNOWN in case of failure.
145  * */
146  mesh_error_t validate_network_regulatory_domain(uint8_t regulatory_domain, uint8_t operating_class, uint8_t operating_mode);
147 
148  /**
149  * \brief Set Wi-SUN network size.
150  *
151  * Function stores new parameters to mbed-mesh-api and uses them when connect() is called next time.
152  * If device is already connected to the Wi-SUN network then device will restart network discovery after
153  * changing the network size.
154  *
155  * Default value: medium
156  * Small network size: less than hundred devices
157  * Medium network size: hundreds of devices
158  * Large network size: thousands of devices
159  * Certificate: used on testing
160  *
161  * When network size is changed, it will override all or some of the following configuration values:
162  * - Timing settings set by set_timing_parameters() of the Wi-SUN interface.
163  * - RPL settings set by rpl_parameters_set() of the Border Router interface.
164  *
165  * When network size is changed, and if timing or RPL values should be other than defaults set by stack for the network size,
166  * they need to set again using above function calls.
167  *
168  * \param network_size Network size in hundreds of devices (e.g. 1200 devices is 12), 0x00 for network size certificate.
169  * \return MESH_ERROR_NONE on success.
170  * \return MESH_ERROR_UNKNOWN in case of failure.
171  * */
172  mesh_error_t set_network_size(uint8_t network_size);
173 
174  /**
175  * \brief Get Wi-SUN network size.
176  *
177  * Function reads network size from mbed-mesh-api.
178  *
179  * \param network_size Network size in hundreds of devices, 0x00 for network size certificate.
180  * \return MESH_ERROR_NONE on success.
181  * \return MESH_ERROR_UNKNOWN in case of failure.
182  * */
183  mesh_error_t get_network_size(uint8_t *network_size);
184 
185  /**
186  * \brief Validate Wi-SUN network size.
187  *
188  * Function validates network size from mbed-mesh-api. Function can be used to test that values that will
189  * be used on set function are valid.
190  *
191  * \param network_size Network size in hundreds of devices, 0x00 for network size certificate.
192  * \return MESH_ERROR_NONE on success.
193  * \return MESH_ERROR_UNKNOWN in case of failure.
194  * */
195  mesh_error_t validate_network_size(uint8_t network_size);
196 
197  /**
198  * \brief Set Wi-SUN FHSS channel mask
199  *
200  * Function stores new parameters to mbed-mesh-api and uses them when connect() is called next time.
201  * If device is already connected to the Wi-SUN network then settings take effect right away.
202  *
203  * \param channel_mask Values defined in Wi-SUN management API. Channel mask bit field.
204  * \return MESH_ERROR_NONE on success.
205  * \return MESH_ERROR_UNKNOWN in case of failure.
206  * */
207  mesh_error_t set_channel_mask(uint32_t channel_mask[8]);
208 
209  /**
210  * \brief Get Wi-SUN FHSS channel mask
211  *
212  * Function reads FHSS channel mask from mbed-mesh-api.
213  *
214  * \param channel_mask Values defined in Wi-SUN management API. Channel mask bit field.
215  * \return MESH_ERROR_NONE on success.
216  * \return MESH_ERROR_UNKNOWN in case of failure.
217  * */
218  mesh_error_t get_channel_mask(uint32_t *channel_mask);
219 
220  /**
221  * \brief Validate Wi-SUN FHSS channel mask
222  *
223  * Function validates FHSS channel mask. Function can be used to test that values that will
224  * be used on set function are valid.
225  *
226  * \param channel_mask Values defined in Wi-SUN management API. Channel mask bit field.
227  * \return MESH_ERROR_NONE on success.
228  * \return MESH_ERROR_UNKNOWN in case of failure.
229  * */
230  mesh_error_t validate_channel_mask(uint32_t channel_mask[8]);
231 
232  /**
233  * \brief Set Wi-SUN FHSS unicast channel function parameters
234  *
235  * Function stores new parameters to mbed-mesh-api and uses them when connect() is called next time.
236  * If device is already connected to the Wi-SUN network then device will restart network discovery after
237  * changing the channel function, fixed channel or dwell interval.
238  *
239  * Function overwrites parameters defined by Mbed OS configuration.
240  *
241  * \param channel_function Channel function. Fixed, TR51CF, DH1CF or vendor defined.
242  * \param fixed_channel Used channel when channel function is fixed channel. Use 0xffff when fixed channel function not on use.
243  * \param dwell_interval Used dwell interval when channel function is TR51 or DH1. Use 0x00 to use leave parameter unchanged.
244  * \return MESH_ERROR_NONE on success.
245  * \return MESH_ERROR_UNKNOWN in case of failure.
246  * */
247  mesh_error_t set_unicast_channel_function(mesh_channel_function_t channel_function, uint16_t fixed_channel = 0xffff, uint8_t dwell_interval = 0x00);
248 
249  /**
250  * \brief Get Wi-SUN FHSS unicast channel function parameters
251  *
252  * Function reads FHSS unicast channel function parameters from mbed-mesh-api.
253  *
254  * \param channel_function Channel function. Fixed, TR51CF, DH1CF or vendor defined.
255  * \param fixed_channel Used channel when channel function is fixed channel.
256  * \param dwell_interval Used dwell interval when channel function is TR51 or DH1.
257  * \return MESH_ERROR_NONE on success.
258  * \return MESH_ERROR_UNKNOWN in case of failure.
259  * */
260  mesh_error_t get_unicast_channel_function(mesh_channel_function_t *channel_function, uint16_t *fixed_channel, uint8_t *dwell_interval);
261 
262  /**
263  * \brief Validate Wi-SUN FHSS unicast channel function parameters
264  *
265  * Function validates FHSS unicast channel function parameters. Function can be used to test that values that will
266  * be used on set function are valid.
267  *
268  * \param channel_function Channel function. Fixed, TR51CF, DH1CF or vendor defined.
269  * \param fixed_channel Used channel when channel function is fixed channel.
270  * \param dwell_interval Used dwell interval when channel function is TR51 or DH1.
271  * \return MESH_ERROR_NONE on success.
272  * \return MESH_ERROR_UNKNOWN in case of failure.
273  * */
274  mesh_error_t validate_unicast_channel_function(mesh_channel_function_t channel_function, uint16_t fixed_channel, uint8_t dwell_interval);
275 
276  /**
277  * \brief Set Wi-SUN FHSS broadcast channel function parameters
278  *
279  * Function stores new parameters to mbed-mesh-api and uses them when connect() is called next time.
280  * If device is already connected to the Wi-SUN network then device will restart network discovery after
281  * changing the channel function, fixed channel, dwell interval or broadcast_interval.
282  *
283  * Function overwrites parameters defined by Mbed OS configuration.
284  *
285  * \param channel_function Channel function. Fixed, TR51CF, DH1CF or vendor defined.
286  * \param fixed_channel Used channel when channel function is fixed channel. Use 0xffff when fixed channel function not on use.
287  * \param dwell_interval Used dwell interval when channel function is TR51 or DH1. Use 0x00 to use leave parameter unchanged.
288  * \param broadcast_interval Used broadcast interval. Use 0x00 to use leave parameter unchanged.
289  * \return MESH_ERROR_NONE on success.
290  * \return MESH_ERROR_UNKNOWN in case of failure.
291  * */
292  mesh_error_t set_broadcast_channel_function(mesh_channel_function_t channel_function, uint16_t fixed_channel = 0xffff, uint8_t dwell_interval = 0x00, uint32_t broadcast_interval = 0x00);
293 
294  /**
295  * \brief Get Wi-SUN FHSS broadcast channel function parameters
296  *
297  * Function reads FHSS broadcast channel function parameters from mbed-mesh-api.
298  *
299  * \param channel_function Channel function. Fixed, TR51CF, DH1CF or vendor defined.
300  * \param fixed_channel Used channel when channel function is fixed channel.
301  * \param dwell_interval Used dwell interval when channel function is TR51 or DH1.
302  * \param broadcast_interval Used broadcast interval.
303  * \return MESH_ERROR_NONE on success.
304  * \return MESH_ERROR_UNKNOWN in case of failure.
305  * */
306  mesh_error_t get_broadcast_channel_function(mesh_channel_function_t *channel_function, uint16_t *fixed_channel, uint8_t *dwell_interval, uint32_t *broadcast_interval);
307 
308  /**
309  * \brief Validate Wi-SUN FHSS broadcast channel function parameters
310  *
311  * Function validates FHSS broadcast channel function parameters from mbed-mesh-api. Function can be used to test that values that will
312  * be used on set function are valid.
313  *
314  * \param channel_function Channel function. Fixed, TR51CF, DH1CF or vendor defined.
315  * \param fixed_channel Used channel when channel function is fixed channel.
316  * \param dwell_interval Used dwell interval when channel function is TR51 or DH1.
317  * \param broadcast_interval Used broadcast interval.
318  * \return MESH_ERROR_NONE on success.
319  * \return MESH_ERROR_UNKNOWN in case of failure.
320  * */
321  mesh_error_t validate_broadcast_channel_function(mesh_channel_function_t channel_function, uint16_t fixed_channel, uint8_t dwell_interval, uint32_t broadcast_interval);
322 
323  /**
324  * \brief Set Wi-SUN timing parameters
325  *
326  * Function stores new parameters to mbed-mesh-api and uses them when connect() is called next time.
327  * If device is already connected to the Wi-SUN network then settings take effect right away.
328  *
329  * \param disc_trickle_imin Discovery trickle Imin. Range 1-255 seconds. Use 0x00 to use leave parameter unchanged.
330  * \param disc_trickle_imax Discovery trickle Imax. Range (2-2^8)*Imin. Use 0x00 to use leave parameter unchanged.
331  * \param disc_trickle_k Discovery trickle k. Use 0x00 to use leave parameter unchanged.
332  * \param pan_timeout PAN timeout; seconds; Range 60-15300 seconds. Use 0x00 to use leave parameter unchanged.
333  * \return MESH_ERROR_NONE on success.
334  * \return MESH_ERROR_UNKNOWN in case of failure.
335  * */
336  mesh_error_t set_timing_parameters(uint16_t disc_trickle_imin = 0x00, uint16_t disc_trickle_imax = 0x00, uint8_t disc_trickle_k = 0x00, uint16_t pan_timeout = 0x00);
337 
338  /**
339  * \brief Get Wi-SUN timing parameters
340  *
341  * Function reads timing parameters from mbed-mesh-api.
342  *
343  * \param disc_trickle_imin Discovery trickle Imin. Range 1-255 seconds.
344  * \param disc_trickle_imax Discovery trickle Imax. Range (2-2^8)*Imin.
345  * \param disc_trickle_k Discovery trickle k.
346  * \param pan_timeout PAN timeout; seconds; Range 60-15300 seconds.
347  * \return MESH_ERROR_NONE on success.
348  * \return MESH_ERROR_UNKNOWN in case of failure.
349  * */
350  mesh_error_t get_timing_parameters(uint16_t *disc_trickle_imin, uint16_t *disc_trickle_imax, uint8_t *disc_trickle_k, uint16_t *pan_timeout);
351 
352  /**
353  * \brief Validates Wi-SUN timing parameters
354  *
355  * Function validates timing parameters. Function can be used to test that values that will be used on set
356  * function are valid.
357  *
358  * \param disc_trickle_imin Discovery trickle Imin. Range 1-255 seconds.
359  * \param disc_trickle_imax Discovery trickle Imax. Range (2-2^8)*Imin.
360  * \param disc_trickle_k Discovery trickle k.
361  * \param pan_timeout PAN timeout; seconds; Range 60-15300 seconds.
362  * \return MESH_ERROR_NONE on success.
363  * \return MESH_ERROR_UNKNOWN in case of failure.
364  * */
365  mesh_error_t validate_timing_parameters(uint16_t disc_trickle_imin, uint16_t disc_trickle_imax, uint8_t disc_trickle_k, uint16_t pan_timeout);
366 
367  /**
368  * \brief Set own certificate and private key reference to the Wi-SUN network.
369  *
370  * Function can be called several times if intermediate certificates are used. Then each call to the function
371  * adds a certificate reference to own certificate chain. Certificates are in bottom up order i.e. the top certificate is given last.
372  *
373  * Function must be called before connecting the device i.e before call to connect() method.
374  * Function will not copy certificate or key, therefore addresses must remain valid.
375  *
376  * \param cert Certificate address.
377  * \param cert_len Certificate length in bytes.
378  * \param cert_key Certificate key address.
379  * \param cert_key_len Certificate key length in bytes.
380  * \return MESH_ERROR_NONE on success.
381  * \return MESH_ERROR_STATE if method is called after calling connect().
382  * \return MESH_ERROR_MEMORY in case of memory allocation failure.
383  * */
384  mesh_error_t set_own_certificate(uint8_t *cert, uint16_t cert_len, uint8_t *cert_key = NULL, uint16_t cert_key_len = 0);
385 
386  /**
387  * \brief Remove own certificates from the Wi-SUN network.
388  *
389  * Function must be called before connecting the device i.e before call to connect() method.
390  *
391  * \return MESH_ERROR_NONE on success.
392  * \return MESH_ERROR_STATE if method is called after calling connect().
393  * */
394  mesh_error_t remove_own_certificates(void);
395 
396  /**
397  * \brief Set trusted certificate reference to the Wi-SUN network.
398  *
399  * Function can be called several times. Certificates are in bottom up order i.e. the top certificate is given last.
400  *
401  * Function must be called before connecting the device i.e before call to connect() method.
402  * Function will not copy certificate, therefore addresses must remain valid.
403  *
404  * \param cert Certificate address.
405  * \param cert_len Certificate length in bytes.
406  * \return MESH_ERROR_NONE on success.
407  * \return MESH_ERROR_STATE if method is called after calling connect().
408  * \return MESH_ERROR_MEMORY in case of memory allocation failure.
409  * */
410  mesh_error_t set_trusted_certificate(uint8_t *cert, uint16_t cert_len);
411 
412  /**
413  * \brief Remove trusted certificates from the Wi-SUN network.
414  *
415  * Function must be called before connecting the device i.e before call to connect() method.
416  *
417  * \return MESH_ERROR_NONE on success.
418  * \return MESH_ERROR_STATE if method is called after calling connect().
419  * */
420  mesh_error_t remove_trusted_certificates(void);
421 
422  /**
423  * \brief Get router IP address
424  *
425  * \param address
426  * \param len
427  * */
428  bool getRouterIpAddress(char *address, int8_t len);
429 
430  /**
431  * \brief Enable Wi-SUN statistics
432  *
433  * After enabling statistics those can be read using the network, physical layer,
434  * MAC and FHSS and Wi-SUN statistics read functions.
435  *
436  * \return MESH_ERROR_NONE on success.
437  * \return MESH_ERROR_UNKNOWN on error
438  * */
439  mesh_error_t enable_statistics(void);
440 
441  /**
442  * \brief Reads Wi-SUN network statistics
443  *
444  * Reads network statistics.
445  *
446  * \param statistics Network statistics.
447  * \return MESH_ERROR_NONE on success.
448  * \return MESH_ERROR_UNKNOWN on error
449  * */
450  mesh_error_t read_nw_statistics(mesh_nw_statistics_t *statistics);
451 
452  /**
453  * \brief Reads Wi-SUN MAC statistics
454  *
455  * Reads MAC statistics.
456  *
457  * \param statistics MAC statistics.
458  * \return MESH_ERROR_NONE on success.
459  * \return MESH_ERROR_UNKNOWN on error
460  * */
461  mesh_error_t read_mac_statistics(mesh_mac_statistics_t *statistics);
462 
463  /**
464  * \brief Get Wi-SUN Router information.
465  *
466  * Function reads RPL information from nanostack.
467  * Mesh interface must be initialized before calling this function.
468  *
469  * \param info_ptr Structure given to stack where information will be stored
470  *
471  * \return MESH_ERROR_NONE on success.
472  * \return MESH_ERROR_UNKNOWN in case of failure.
473  * */
474  mesh_error_t info_get(ws_rpl_info_t *info_ptr);
475 
476  /**
477  * \brief Get Wi-SUN Stack information.
478  *
479  * Function reads Stack information from nanostack.
480  * Mesh interface must be initialized before calling this function.
481  *
482  * \param stack_info_ptr Structure given to stack where information will be stored
483  *
484  * \return MESH_ERROR_NONE on success.
485  * \return MESH_ERROR_UNKNOWN in case of failure.
486  * */
487  mesh_error_t stack_info_get(ws_stack_state_t *stack_info_ptr);
488 
489 protected:
490  Nanostack::WisunInterface *get_interface() const;
491  nsapi_error_t do_initialize() override;
492  virtual nsapi_error_t configure();
493 };
494 
495 #endif
uint8_t join_state
Wi-SUN join state defined by Wi-SUN specification 1-5.
Wi-SUN mesh network interface class.
uint8_t version
RPL version number.
signed int nsapi_error_t
Type used to represent error codes.
Definition: nsapi_types.h:95
uint16_t primary_parent_rank
RPL Primary Parent Rank.
Mesh physical layer statistics.
Mesh network statistics.
Struct ws_stack_state Wi-SUN stack information.
uint8_t instance_id
Router instance identifier.
uint8_t rsl_out
parent RSSI Out measured RSSI value calculated using EWMA specified by Wi-SUN from range of -174 (0) ...
uint8_t rsl_in
parent RSSI in measured RSSI value calculated using EWMA specified by Wi-SUN from range of -174 (0) t...
uint8_t rpl_dodag_id[16]
Router dodag id.
Struct ws_rpl_info Wi-SUN router RPL information.
uint16_t current_rank
RPL DODAG node current Rank.
uint16_t pan_id
Network PAN ID.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.