Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016 ARM Limited. All rights reserved.
* Copyright (c) 2016-2019 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
Expand Down Expand Up @@ -132,9 +132,19 @@ class InterfaceNanostack : public virtual NetworkInterface {
*/
virtual nsapi_error_t set_blocking(bool blocking);

/** Set file system root path.
*
* Set file system root path that stack will use to write and read its data.
* Setting root_path to NULL will disable file system usage.
*
* @param root_path Address to NUL-terminated root-path string or NULL to disable file system usage.
* @return MESH_ERROR_NONE on success, MESH_ERROR_MEMORY in case of memory failure, MESH_ERROR_UNKNOWN in case of other error.
*/
virtual nsapi_error_t set_file_system_root_path(const char *root_path);

/** Get the interface ID
/return Interface identifier
*/
* @return Interface identifier
*/
int8_t get_interface_id() const
{
return _interface->get_interface_id();
Expand Down
95 changes: 94 additions & 1 deletion features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 ARM Limited. All rights reserved.
* Copyright (c) 2018-2019 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,6 +37,99 @@ class WisunInterface : public MeshInterfaceNanostack {
*/
WisunInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }

/**
* \brief Set Wi-SUN network name.
*
* Function stores new network name to mbed-mesh-api and uses it when connect() is called next time.
* If device is already connected to the Wi-SUN network then device will restart network discovery after
* changing the network name.
*
* Function overwrites network name defined by Mbed OS configuration.
*
* \param network_name Network name as NUL terminated string. Can't exceed 32 characters and can't be NULL.
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_UNKNOWN in case of failure.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All fails are Unknown?

* */
mesh_error_t set_network_name(char *network_name);

/**
* \brief Set Wi-SUN network regulatory domain, operating class and operating mode.
*
* Function stores new parameters to mbed-mesh-api and uses them when connect() is called next time.
* If device is already connected to the Wi-SUN network then device will restart network discovery after
* changing the regulatory_domain, operating_class or operating_mode.
*
* Function overwrites parameters defined by Mbed OS configuration.
*
* \param regulatory_domain Values defined in Wi-SUN PHY-specification. Use 0xff to use leave parameter unchanged.
* \param operating_class Values defined in Wi-SUN PHY-specification. Use 0xff to use leave parameter unchanged.
* \param operating_mode Values defined in Wi-SUN PHY-specification. Use 0xff to use leave parameter unchanged.
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_UNKNOWN in case of failure.
* */
mesh_error_t set_network_regulatory_domain(uint8_t regulatory_domain = 0xff, uint8_t operating_class = 0xff, uint8_t operating_mode = 0xff);

/**
* \brief Set own certificate and private key reference to the Wi-SUN network.
*
* Function can be called several times if intermediate certificates are used. Then each call to the function
* adds a certificate reference to own certificate chain. Certificates are in bottom up order i.e. the top certificate is given last.
*
* Function must be called before connecting the device i.e before call to connect() method.
* Function will not copy certificate or key, therefore addresses must remain valid.
*
* \param cert Certificate address.
* \param cert_len Certificate length in bytes.
* \param cert_key Certificate key address.
* \param cert_key_len Certificate key length in bytes.
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_STATE if method is called after calling connect().
* \return MESH_ERROR_MEMORY in case of memory allocation failure.
* */
mesh_error_t set_own_certificate(uint8_t *cert, uint16_t cert_len, uint8_t *cert_key = NULL, uint16_t cert_key_len = 0);

/**
* \brief Remove own certificates from the Wi-SUN network.
*
* Function must be called before connecting the device i.e before call to connect() method.
*
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_STATE if method is called after calling connect().
* */
mesh_error_t remove_own_certificates(void);

/**
* \brief Set trusted certificate reference to the Wi-SUN network.
*
* Function can be called several times. Certificates are in bottom up order i.e. the top certificate is given last.
*
* Function must be called before connecting the device i.e before call to connect() method.
* Function will not copy certificate, therefore addresses must remain valid.
*
* \param cert Certificate address.
* \param cert_len Certificate length in bytes.
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_STATE if method is called after calling connect().
* \return MESH_ERROR_MEMORY in case of memory allocation failure.
* */
mesh_error_t set_trusted_certificate(uint8_t *cert, uint16_t cert_len);

/**
* \brief Remove trusted certificates from the Wi-SUN network.
*
* Function must be called before connecting the device i.e before call to connect() method.
*
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_STATE if method is called after calling connect().
* */
mesh_error_t remove_trusted_certificates(void);

/**
* \brief Get router IP address
*
* \param address
* \param len
* */
bool getRouterIpAddress(char *address, int8_t len);
protected:
Nanostack::WisunInterface *get_interface() const;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016 ARM Limited. All rights reserved.
* Copyright (c) 2016-2019 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
Expand Down Expand Up @@ -217,6 +217,19 @@ nsapi_error_t InterfaceNanostack::set_blocking(bool blocking)
return NSAPI_ERROR_OK;
}

nsapi_error_t InterfaceNanostack::set_file_system_root_path(const char *root_path)
{
int status = mesh_system_set_file_system_root_path(root_path);

if (status == 0) {
return MESH_ERROR_NONE;
} else if (status == -2) {
return MESH_ERROR_MEMORY;
}

return MESH_ERROR_UNKNOWN;
}

#if !DEVICE_802_15_4_PHY
MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance()
{
Expand Down
78 changes: 77 additions & 1 deletion features/nanostack/mbed-mesh-api/source/WisunInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 ARM Limited. All rights reserved.
* Copyright (c) 2018-2019 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
Expand Down Expand Up @@ -171,6 +171,82 @@ bool WisunInterface::getRouterIpAddress(char *address, int8_t len)
return _interface->get_gateway(address, len);
}

mesh_error_t WisunInterface::set_network_name(char *network_name)
{
mesh_error_t ret_val = MESH_ERROR_NONE;

int status = wisun_tasklet_set_network_name(get_interface_id(), network_name);
if (status != 0) {
ret_val = MESH_ERROR_UNKNOWN;
}

return ret_val;
}

mesh_error_t WisunInterface::set_network_regulatory_domain(uint8_t regulatory_domain, uint8_t operating_class, uint8_t operating_mode)
{
mesh_error_t ret_val = MESH_ERROR_NONE;

int status = wisun_tasklet_set_regulatory_domain(get_interface_id(), regulatory_domain, operating_class, operating_mode);
if (status != 0) {
ret_val = MESH_ERROR_UNKNOWN;
}

return ret_val;
}

mesh_error_t WisunInterface::set_own_certificate(uint8_t *cert, uint16_t cert_len, uint8_t *cert_key, uint16_t cert_key_len)
{
mesh_error_t ret_val = MESH_ERROR_NONE;
int status = wisun_tasklet_set_own_certificate(cert, cert_len, cert_key, cert_key_len);
if (status == -1) {
ret_val = MESH_ERROR_MEMORY;
} else if (status == -2) {
ret_val = MESH_ERROR_STATE;
}

return ret_val;
}

mesh_error_t WisunInterface::remove_own_certificates(void)
{
mesh_error_t ret_val = MESH_ERROR_NONE;
int status = wisun_tasklet_remove_own_certificates();
if (status == -1) {
ret_val = MESH_ERROR_MEMORY;
} else if (status == -2) {
ret_val = MESH_ERROR_STATE;
}

return ret_val;
}

mesh_error_t WisunInterface::set_trusted_certificate(uint8_t *cert, uint16_t cert_len)
{
mesh_error_t ret_val = MESH_ERROR_NONE;
int status = wisun_tasklet_set_trusted_certificate(cert, cert_len);
if (status == -1) {
ret_val = MESH_ERROR_MEMORY;
} else if (status == -2) {
ret_val = MESH_ERROR_STATE;
}

return ret_val;
}

mesh_error_t WisunInterface::remove_trusted_certificates(void)
{
mesh_error_t ret_val = MESH_ERROR_NONE;
int status = wisun_tasklet_remove_trusted_certificates();
if (status == -1) {
ret_val = MESH_ERROR_MEMORY;
} else if (status == -2) {
ret_val = MESH_ERROR_STATE;
}

return ret_val;
}

#define WISUN 0x2345
#if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == WISUN && DEVICE_802_15_4_PHY
MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All rights reserved.
* Copyright (c) 2015-2019 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,6 +38,8 @@ enum {
*/
void mesh_system_send_connect_event(uint8_t receiver);

int mesh_system_set_file_system_root_path(const char *root_path);

/*
* \brief Initialize mesh system.
* Memory pool, timers, traces and support are initialized.
Expand Down
65 changes: 64 additions & 1 deletion features/nanostack/mbed-mesh-api/source/include/wisun_tasklet.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 ARM Limited
* Copyright (c) 2018-2019 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -64,6 +64,9 @@ void wisun_tasklet_init(void);
*
* \param device_id registered physical device
* \return interface ID that can be used to communication with this interface
* \return -1 in case of MAC initialization fails
* \return -2 in case of error in parameters
* \return -3 in case of memory allocation error
*/
int8_t wisun_tasklet_network_init(int8_t device_id);

Expand All @@ -76,6 +79,66 @@ int8_t wisun_tasklet_network_init(int8_t device_id);
*/
int8_t wisun_tasklet_disconnect(bool send_cb);

/*
* \brief Set Wi-SUN network name
*
* \param nwk_interface_id to use for networking
* \param network_name_ptr Address of the new network name. Can't be NULL.
* \return 0 if network name stored successfully
* \return < 0 in case of errors
*/
int wisun_tasklet_set_network_name(int8_t nwk_interface_id, char *network_name_ptr);

/*
* \brief Set Wi-SUN network regulatory domain
*
* \param nwk_interface_id to use for networking
* \param regulatory_domain
* \param operating_class
* \param operating_mode
* \return 0 if regulatory domain is set successfully.
* \return < 0 in case of errors
*/
int wisun_tasklet_set_regulatory_domain(int8_t nwk_interface_id, uint8_t regulatory_domain, uint8_t operating_class, uint8_t operating_mode);

/*
* \brief Set own certificate to Wi-SUN network
*
* \param cert to use for networking
* \param cert_len
* \param cert_key
* \param cert_key_len
* \return 0 if certificate stored successfully
* \return < 0 in case of errors
*/
int wisun_tasklet_set_own_certificate(uint8_t *cert, uint16_t cert_len, uint8_t *cert_key, uint16_t cert_key_len);

/*
* \brief Remove own certificate from Wi-SUN network
*
* \return 0 if certificates removed successfully
* \return < 0 in case of errors
*/
int wisun_tasklet_remove_own_certificates(void);

/*
* \brief Set trusted certificate to Wi-SUN network
*
* \param cert to use for networking
* \param cert_len
* \return 0 if certificate stored successfully
* \return < 0 in case of errors
*/
int wisun_tasklet_set_trusted_certificate(uint8_t *cert, uint16_t cert_len);

/*
* \brief Remove trusted certificate from Wi-SUN network
*
* \return 0 if certificates removed successfully
* \return < 0 in case of errors
*/
int wisun_tasklet_remove_trusted_certificates(void);

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 7 additions & 1 deletion features/nanostack/mbed-mesh-api/source/mesh_system.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 ARM Limited. All rights reserved.
* Copyright (c) 2015-2019 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
Expand All @@ -25,6 +25,7 @@
#include "include/mesh_system.h"
#include "mbed_assert.h"
#include "mbed_error.h"
#include "ns_file_system.h"
// For tracing we need to define flag, have include and define group
#define HAVE_DEBUG 1
#include "ns_trace.h"
Expand Down Expand Up @@ -77,3 +78,8 @@ void mesh_system_send_connect_event(uint8_t receiver)
};
eventOS_event_send(&event);
}

int mesh_system_set_file_system_root_path(const char *root_path)
{
return ns_file_system_set_root_path(root_path);
}
Loading