Skip to content

Commit 774162d

Browse files
author
Arto Kinnunen
committed
mbed-mesh-api: Add new Wi-SUN certificate API
Add new API for setting Wi-SUN: -Setting own/trusted certificates -Removing own/trusted certificates
1 parent c0f3cb7 commit 774162d

File tree

4 files changed

+340
-13
lines changed

4 files changed

+340
-13
lines changed

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

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class WisunInterface : public MeshInterfaceNanostack {
5050
* \return MESH_ERROR_NONE on success.
5151
* \return MESH_ERROR_UNKNOWN in case of failure.
5252
* */
53-
mesh_error_t network_name_set(char *network_name);
53+
mesh_error_t set_network_name(char *network_name);
5454

5555
/**
5656
* \brief Set Wi-SUN network regulatory domain, operating class and operating mode.
@@ -61,13 +61,68 @@ class WisunInterface : public MeshInterfaceNanostack {
6161
*
6262
* Function overwrites parameters defined by Mbed OS configuration.
6363
*
64-
* \param regulatory_domain Values defined in Wi-SUN PHY-specification
65-
* \param operating_class Values defined in Wi-SUN PHY-specification
66-
* \param operating_mode Values defined in Wi-SUN PHY-specification
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.
6767
* \return MESH_ERROR_NONE on success.
6868
* \return MESH_ERROR_UNKNOWN in case of failure.
6969
* */
70-
mesh_error_t network_regulatory_domain_set(uint8_t regulatory_domain = 0xff, uint8_t operating_class = 0xff, uint8_t operating_mode = 0xff);
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 first 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 first 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 first 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 first 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);
71126

72127
/**
73128
* \brief Get router IP address

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

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,30 +171,82 @@ bool WisunInterface::getRouterIpAddress(char *address, int8_t len)
171171
return _interface->get_gateway(address, len);
172172
}
173173

174-
mesh_error_t WisunInterface::network_name_set(char *network_name)
174+
mesh_error_t WisunInterface::set_network_name(char *network_name)
175175
{
176176
mesh_error_t ret_val = MESH_ERROR_NONE;
177177

178-
int status = wisun_tasklet_network_name_set(get_interface_id(), network_name);
178+
int status = wisun_tasklet_set_network_name(get_interface_id(), network_name);
179179
if (status != 0) {
180180
ret_val = MESH_ERROR_UNKNOWN;
181181
}
182182

183183
return ret_val;
184184
}
185185

186-
mesh_error_t WisunInterface::network_regulatory_domain_set(uint8_t regulatory_domain, uint8_t operating_class, uint8_t operating_mode)
186+
mesh_error_t WisunInterface::set_network_regulatory_domain(uint8_t regulatory_domain, uint8_t operating_class, uint8_t operating_mode)
187187
{
188188
mesh_error_t ret_val = MESH_ERROR_NONE;
189189

190-
int status = wisun_tasklet_regulatory_domain_set(get_interface_id(), regulatory_domain, operating_class, operating_mode);
190+
int status = wisun_tasklet_set_regulatory_domain(get_interface_id(), regulatory_domain, operating_class, operating_mode);
191191
if (status != 0) {
192192
ret_val = MESH_ERROR_UNKNOWN;
193193
}
194194

195195
return ret_val;
196196
}
197197

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+
198250
#define WISUN 0x2345
199251
#if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == WISUN && DEVICE_802_15_4_PHY
200252
MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance()

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

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -84,7 +87,7 @@ int8_t wisun_tasklet_disconnect(bool send_cb);
8487
* \return 0 if network name stored successfully
8588
* \return < 0 in case of errors
8689
*/
87-
int wisun_tasklet_network_name_set(int8_t nwk_interface_id, char *network_name_ptr);
90+
int wisun_tasklet_set_network_name(int8_t nwk_interface_id, char *network_name_ptr);
8891

8992
/*
9093
* \brief Set Wi-SUN network regulatory domain
@@ -96,7 +99,45 @@ int wisun_tasklet_network_name_set(int8_t nwk_interface_id, char *network_name_p
9699
* \return 0 if regulatory domain is set successfully.
97100
* \return < 0 in case of errors
98101
*/
99-
int wisun_tasklet_regulatory_domain_set(int8_t nwk_interface_id, uint8_t regulatory_domain, uint8_t operating_class, uint8_t operating_mode);
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);
100141

101142
#ifdef __cplusplus
102143
}

0 commit comments

Comments
 (0)