Skip to content

Commit d6304e3

Browse files
authored
Merge pull request #11181 from artokin/mbed_wisun_api_update
mbed-mesh-api: Add new API for Wi-SUN configuration
2 parents a6372e5 + f8289ec commit d6304e3

File tree

8 files changed

+537
-18
lines changed

8 files changed

+537
-18
lines changed

features/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016 ARM Limited. All rights reserved.
2+
* Copyright (c) 2016-2019 ARM Limited. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
* Licensed under the Apache License, Version 2.0 (the License); you may
55
* not use this file except in compliance with the License.
@@ -132,9 +132,19 @@ class InterfaceNanostack : public virtual NetworkInterface {
132132
*/
133133
virtual nsapi_error_t set_blocking(bool blocking);
134134

135+
/** Set file system root path.
136+
*
137+
* Set file system root path that stack will use to write and read its data.
138+
* Setting root_path to NULL will disable file system usage.
139+
*
140+
* @param root_path Address to NUL-terminated root-path string or NULL to disable file system usage.
141+
* @return MESH_ERROR_NONE on success, MESH_ERROR_MEMORY in case of memory failure, MESH_ERROR_UNKNOWN in case of other error.
142+
*/
143+
virtual nsapi_error_t set_file_system_root_path(const char *root_path);
144+
135145
/** Get the interface ID
136-
/return Interface identifier
137-
*/
146+
* @return Interface identifier
147+
*/
138148
int8_t get_interface_id() const
139149
{
140150
return _interface->get_interface_id();

features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018 ARM Limited. All rights reserved.
2+
* Copyright (c) 2018-2019 ARM Limited. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
* Licensed under the Apache License, Version 2.0 (the License); you may
55
* not use this file except in compliance with the License.
@@ -37,6 +37,99 @@ class WisunInterface : public MeshInterfaceNanostack {
3737
*/
3838
WisunInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
3939

40+
/**
41+
* \brief Set Wi-SUN network name.
42+
*
43+
* Function stores new network name to mbed-mesh-api and uses it when connect() is called next time.
44+
* If device is already connected to the Wi-SUN network then device will restart network discovery after
45+
* changing the network name.
46+
*
47+
* Function overwrites network name defined by Mbed OS configuration.
48+
*
49+
* \param network_name Network name as NUL terminated string. Can't exceed 32 characters and can't be NULL.
50+
* \return MESH_ERROR_NONE on success.
51+
* \return MESH_ERROR_UNKNOWN in case of failure.
52+
* */
53+
mesh_error_t set_network_name(char *network_name);
54+
55+
/**
56+
* \brief Set Wi-SUN network regulatory domain, operating class and operating mode.
57+
*
58+
* Function stores new parameters to mbed-mesh-api and uses them when connect() is called next time.
59+
* If device is already connected to the Wi-SUN network then device will restart network discovery after
60+
* changing the regulatory_domain, operating_class or operating_mode.
61+
*
62+
* Function overwrites parameters defined by Mbed OS configuration.
63+
*
64+
* \param regulatory_domain Values defined in Wi-SUN PHY-specification. Use 0xff to use leave parameter unchanged.
65+
* \param operating_class Values defined in Wi-SUN PHY-specification. Use 0xff to use leave parameter unchanged.
66+
* \param operating_mode Values defined in Wi-SUN PHY-specification. Use 0xff to use leave parameter unchanged.
67+
* \return MESH_ERROR_NONE on success.
68+
* \return MESH_ERROR_UNKNOWN in case of failure.
69+
* */
70+
mesh_error_t set_network_regulatory_domain(uint8_t regulatory_domain = 0xff, uint8_t operating_class = 0xff, uint8_t operating_mode = 0xff);
71+
72+
/**
73+
* \brief Set own certificate and private key reference to the Wi-SUN network.
74+
*
75+
* Function can be called several times if intermediate certificates are used. Then each call to the function
76+
* adds a certificate reference to own certificate chain. Certificates are in bottom up order i.e. the top certificate is given last.
77+
*
78+
* Function must be called before connecting the device i.e before call to connect() method.
79+
* Function will not copy certificate or key, therefore addresses must remain valid.
80+
*
81+
* \param cert Certificate address.
82+
* \param cert_len Certificate length in bytes.
83+
* \param cert_key Certificate key address.
84+
* \param cert_key_len Certificate key length in bytes.
85+
* \return MESH_ERROR_NONE on success.
86+
* \return MESH_ERROR_STATE if method is called after calling connect().
87+
* \return MESH_ERROR_MEMORY in case of memory allocation failure.
88+
* */
89+
mesh_error_t set_own_certificate(uint8_t *cert, uint16_t cert_len, uint8_t *cert_key = NULL, uint16_t cert_key_len = 0);
90+
91+
/**
92+
* \brief Remove own certificates from the Wi-SUN network.
93+
*
94+
* Function must be called before connecting the device i.e before call to connect() method.
95+
*
96+
* \return MESH_ERROR_NONE on success.
97+
* \return MESH_ERROR_STATE if method is called after calling connect().
98+
* */
99+
mesh_error_t remove_own_certificates(void);
100+
101+
/**
102+
* \brief Set trusted certificate reference to the Wi-SUN network.
103+
*
104+
* Function can be called several times. Certificates are in bottom up order i.e. the top certificate is given last.
105+
*
106+
* Function must be called before connecting the device i.e before call to connect() method.
107+
* Function will not copy certificate, therefore addresses must remain valid.
108+
*
109+
* \param cert Certificate address.
110+
* \param cert_len Certificate length in bytes.
111+
* \return MESH_ERROR_NONE on success.
112+
* \return MESH_ERROR_STATE if method is called after calling connect().
113+
* \return MESH_ERROR_MEMORY in case of memory allocation failure.
114+
* */
115+
mesh_error_t set_trusted_certificate(uint8_t *cert, uint16_t cert_len);
116+
117+
/**
118+
* \brief Remove trusted certificates from the Wi-SUN network.
119+
*
120+
* Function must be called before connecting the device i.e before call to connect() method.
121+
*
122+
* \return MESH_ERROR_NONE on success.
123+
* \return MESH_ERROR_STATE if method is called after calling connect().
124+
* */
125+
mesh_error_t remove_trusted_certificates(void);
126+
127+
/**
128+
* \brief Get router IP address
129+
*
130+
* \param address
131+
* \param len
132+
* */
40133
bool getRouterIpAddress(char *address, int8_t len);
41134
protected:
42135
Nanostack::WisunInterface *get_interface() const;

features/nanostack/mbed-mesh-api/source/MeshInterfaceNanostack.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016 ARM Limited. All rights reserved.
2+
* Copyright (c) 2016-2019 ARM Limited. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
* Licensed under the Apache License, Version 2.0 (the License); you may
55
* not use this file except in compliance with the License.
@@ -217,6 +217,19 @@ nsapi_error_t InterfaceNanostack::set_blocking(bool blocking)
217217
return NSAPI_ERROR_OK;
218218
}
219219

220+
nsapi_error_t InterfaceNanostack::set_file_system_root_path(const char *root_path)
221+
{
222+
int status = mesh_system_set_file_system_root_path(root_path);
223+
224+
if (status == 0) {
225+
return MESH_ERROR_NONE;
226+
} else if (status == -2) {
227+
return MESH_ERROR_MEMORY;
228+
}
229+
230+
return MESH_ERROR_UNKNOWN;
231+
}
232+
220233
#if !DEVICE_802_15_4_PHY
221234
MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance()
222235
{

features/nanostack/mbed-mesh-api/source/WisunInterface.cpp

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018 ARM Limited. All rights reserved.
2+
* Copyright (c) 2018-2019 ARM Limited. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
* Licensed under the Apache License, Version 2.0 (the License); you may
55
* not use this file except in compliance with the License.
@@ -171,6 +171,82 @@ bool WisunInterface::getRouterIpAddress(char *address, int8_t len)
171171
return _interface->get_gateway(address, len);
172172
}
173173

174+
mesh_error_t WisunInterface::set_network_name(char *network_name)
175+
{
176+
mesh_error_t ret_val = MESH_ERROR_NONE;
177+
178+
int status = wisun_tasklet_set_network_name(get_interface_id(), network_name);
179+
if (status != 0) {
180+
ret_val = MESH_ERROR_UNKNOWN;
181+
}
182+
183+
return ret_val;
184+
}
185+
186+
mesh_error_t WisunInterface::set_network_regulatory_domain(uint8_t regulatory_domain, uint8_t operating_class, uint8_t operating_mode)
187+
{
188+
mesh_error_t ret_val = MESH_ERROR_NONE;
189+
190+
int status = wisun_tasklet_set_regulatory_domain(get_interface_id(), regulatory_domain, operating_class, operating_mode);
191+
if (status != 0) {
192+
ret_val = MESH_ERROR_UNKNOWN;
193+
}
194+
195+
return ret_val;
196+
}
197+
198+
mesh_error_t WisunInterface::set_own_certificate(uint8_t *cert, uint16_t cert_len, uint8_t *cert_key, uint16_t cert_key_len)
199+
{
200+
mesh_error_t ret_val = MESH_ERROR_NONE;
201+
int status = wisun_tasklet_set_own_certificate(cert, cert_len, cert_key, cert_key_len);
202+
if (status == -1) {
203+
ret_val = MESH_ERROR_MEMORY;
204+
} else if (status == -2) {
205+
ret_val = MESH_ERROR_STATE;
206+
}
207+
208+
return ret_val;
209+
}
210+
211+
mesh_error_t WisunInterface::remove_own_certificates(void)
212+
{
213+
mesh_error_t ret_val = MESH_ERROR_NONE;
214+
int status = wisun_tasklet_remove_own_certificates();
215+
if (status == -1) {
216+
ret_val = MESH_ERROR_MEMORY;
217+
} else if (status == -2) {
218+
ret_val = MESH_ERROR_STATE;
219+
}
220+
221+
return ret_val;
222+
}
223+
224+
mesh_error_t WisunInterface::set_trusted_certificate(uint8_t *cert, uint16_t cert_len)
225+
{
226+
mesh_error_t ret_val = MESH_ERROR_NONE;
227+
int status = wisun_tasklet_set_trusted_certificate(cert, cert_len);
228+
if (status == -1) {
229+
ret_val = MESH_ERROR_MEMORY;
230+
} else if (status == -2) {
231+
ret_val = MESH_ERROR_STATE;
232+
}
233+
234+
return ret_val;
235+
}
236+
237+
mesh_error_t WisunInterface::remove_trusted_certificates(void)
238+
{
239+
mesh_error_t ret_val = MESH_ERROR_NONE;
240+
int status = wisun_tasklet_remove_trusted_certificates();
241+
if (status == -1) {
242+
ret_val = MESH_ERROR_MEMORY;
243+
} else if (status == -2) {
244+
ret_val = MESH_ERROR_STATE;
245+
}
246+
247+
return ret_val;
248+
}
249+
174250
#define WISUN 0x2345
175251
#if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == WISUN && DEVICE_802_15_4_PHY
176252
MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance()

features/nanostack/mbed-mesh-api/source/include/mesh_system.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015 ARM Limited. All rights reserved.
2+
* Copyright (c) 2015-2019 ARM Limited. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
* Licensed under the Apache License, Version 2.0 (the License); you may
55
* not use this file except in compliance with the License.
@@ -38,6 +38,8 @@ enum {
3838
*/
3939
void mesh_system_send_connect_event(uint8_t receiver);
4040

41+
int mesh_system_set_file_system_root_path(const char *root_path);
42+
4143
/*
4244
* \brief Initialize mesh system.
4345
* Memory pool, timers, traces and support are initialized.

features/nanostack/mbed-mesh-api/source/include/wisun_tasklet.h

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018 ARM Limited
2+
* Copyright (c) 2018-2019 ARM Limited
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -64,6 +64,9 @@ void wisun_tasklet_init(void);
6464
*
6565
* \param device_id registered physical device
6666
* \return interface ID that can be used to communication with this interface
67+
* \return -1 in case of MAC initialization fails
68+
* \return -2 in case of error in parameters
69+
* \return -3 in case of memory allocation error
6770
*/
6871
int8_t wisun_tasklet_network_init(int8_t device_id);
6972

@@ -76,6 +79,66 @@ int8_t wisun_tasklet_network_init(int8_t device_id);
7679
*/
7780
int8_t wisun_tasklet_disconnect(bool send_cb);
7881

82+
/*
83+
* \brief Set Wi-SUN network name
84+
*
85+
* \param nwk_interface_id to use for networking
86+
* \param network_name_ptr Address of the new network name. Can't be NULL.
87+
* \return 0 if network name stored successfully
88+
* \return < 0 in case of errors
89+
*/
90+
int wisun_tasklet_set_network_name(int8_t nwk_interface_id, char *network_name_ptr);
91+
92+
/*
93+
* \brief Set Wi-SUN network regulatory domain
94+
*
95+
* \param nwk_interface_id to use for networking
96+
* \param regulatory_domain
97+
* \param operating_class
98+
* \param operating_mode
99+
* \return 0 if regulatory domain is set successfully.
100+
* \return < 0 in case of errors
101+
*/
102+
int wisun_tasklet_set_regulatory_domain(int8_t nwk_interface_id, uint8_t regulatory_domain, uint8_t operating_class, uint8_t operating_mode);
103+
104+
/*
105+
* \brief Set own certificate to Wi-SUN network
106+
*
107+
* \param cert to use for networking
108+
* \param cert_len
109+
* \param cert_key
110+
* \param cert_key_len
111+
* \return 0 if certificate stored successfully
112+
* \return < 0 in case of errors
113+
*/
114+
int wisun_tasklet_set_own_certificate(uint8_t *cert, uint16_t cert_len, uint8_t *cert_key, uint16_t cert_key_len);
115+
116+
/*
117+
* \brief Remove own certificate from Wi-SUN network
118+
*
119+
* \return 0 if certificates removed successfully
120+
* \return < 0 in case of errors
121+
*/
122+
int wisun_tasklet_remove_own_certificates(void);
123+
124+
/*
125+
* \brief Set trusted certificate to Wi-SUN network
126+
*
127+
* \param cert to use for networking
128+
* \param cert_len
129+
* \return 0 if certificate stored successfully
130+
* \return < 0 in case of errors
131+
*/
132+
int wisun_tasklet_set_trusted_certificate(uint8_t *cert, uint16_t cert_len);
133+
134+
/*
135+
* \brief Remove trusted certificate from Wi-SUN network
136+
*
137+
* \return 0 if certificates removed successfully
138+
* \return < 0 in case of errors
139+
*/
140+
int wisun_tasklet_remove_trusted_certificates(void);
141+
79142
#ifdef __cplusplus
80143
}
81144
#endif

features/nanostack/mbed-mesh-api/source/mesh_system.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015 ARM Limited. All rights reserved.
2+
* Copyright (c) 2015-2019 ARM Limited. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
* Licensed under the Apache License, Version 2.0 (the License); you may
55
* not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
2525
#include "include/mesh_system.h"
2626
#include "mbed_assert.h"
2727
#include "mbed_error.h"
28+
#include "ns_file_system.h"
2829
// For tracing we need to define flag, have include and define group
2930
#define HAVE_DEBUG 1
3031
#include "ns_trace.h"
@@ -77,3 +78,8 @@ void mesh_system_send_connect_event(uint8_t receiver)
7778
};
7879
eventOS_event_send(&event);
7980
}
81+
82+
int mesh_system_set_file_system_root_path(const char *root_path)
83+
{
84+
return ns_file_system_set_root_path(root_path);
85+
}

0 commit comments

Comments
 (0)