diff --git a/features/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h b/features/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h index 9a782bff898..51d4ca14310 100644 --- a/features/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h +++ b/features/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h @@ -82,6 +82,8 @@ class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed }; class Nanostack::MeshInterface : public Nanostack::Interface { +public: + char *get_interface_name(char *buf); protected: MeshInterface(NanostackRfPhy &phy) : Interface(phy) { } NanostackRfPhy &get_phy() const @@ -172,6 +174,7 @@ class InterfaceNanostack : public virtual NetworkInterface { char mac_addr_str[24]; mbed::Callback _connection_status_cb; bool _blocking; + bool _configured = false; }; class MeshInterfaceNanostack : public InterfaceNanostack, public MeshInterface, private mbed::NonCopyable { diff --git a/features/nanostack/mbed-mesh-api/mbed-mesh-api/NanostackEthernetInterface.h b/features/nanostack/mbed-mesh-api/mbed-mesh-api/NanostackEthernetInterface.h index f58b5393ad7..da2c9d48819 100644 --- a/features/nanostack/mbed-mesh-api/mbed-mesh-api/NanostackEthernetInterface.h +++ b/features/nanostack/mbed-mesh-api/mbed-mesh-api/NanostackEthernetInterface.h @@ -29,6 +29,7 @@ class Nanostack::EthernetInterface : public Nanostack::Interface { bool blocking = true); virtual nsapi_error_t bringdown(); + char *get_interface_name(char *buf); private: friend class Nanostack; friend class NanostackEthernetInterface; diff --git a/features/nanostack/mbed-mesh-api/mbed-mesh-api/NanostackPPPInterface.h b/features/nanostack/mbed-mesh-api/mbed-mesh-api/NanostackPPPInterface.h index f60f45ae3cf..735ef52d14a 100644 --- a/features/nanostack/mbed-mesh-api/mbed-mesh-api/NanostackPPPInterface.h +++ b/features/nanostack/mbed-mesh-api/mbed-mesh-api/NanostackPPPInterface.h @@ -32,6 +32,7 @@ class Nanostack::PPPInterface : public Nanostack::Interface { typedef mbed::Callback link_state_cb_t; virtual void set_link_state_changed_callback(link_state_cb_t link_state_cb); + char *get_interface_name(char *buf); private: friend class Nanostack; PPPInterface(NanostackPhy &phy) : Interface(phy), link_state_up(false), enet_tasklet_connected(false) {} diff --git a/features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunBorderRouter.h b/features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunBorderRouter.h new file mode 100644 index 00000000000..600e8d8d98d --- /dev/null +++ b/features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunBorderRouter.h @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2020 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WISUNBORDERROUTER_H +#define WISUNBORDERROUTER_H + +/** Wi-SUN Border Router class + * + * Class can be used to start, stop and configure Wi-SUN Border Router. + */ +class WisunBorderRouter { +public: + + /** Create WisunBorderRouter + * + * */ + WisunBorderRouter() { } + + /** + * \brief Start Wi-SUN Border Router + * + * Starts Wi-SUN Border Router and routing between the mesh and backbone interfaces. Network interfaces + * must be initialized and connected before calling the start. Backbone interface can be either Ethernet + * (EMAC) or Cellular. + * + * \param mesh_if Wi-SUN mesh network interface + * \param backbone_if Backbone network interface + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t start(NetworkInterface *mesh_if, NetworkInterface *backbone_if); + + /** + * \brief Start Wi-SUN Border Router + * + * Starts Wi-SUN Border Router and routing between the mesh and backbone interfaces. Mesh network interface + * must be initialized and connected before calling the start. Backbone OnboardNetworkStack::Interface must + * be brought up before calling the start. Backbone interface can be either Ethernet (EMAC) or Cellular (PPP). + * + * \param mesh_if Wi-SUN mesh network interface + * \param backbone_if Backbone OnboardNetworkStack::Interface interface + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t start(NetworkInterface *mesh_if, OnboardNetworkStack::Interface *backbone_if); + + /** + * \brief Stop Wi-SUN Border Router + * + * Stops Wi-SUN Border Router. + * + * */ + void stop(); + + /** + * \brief Set Wi-SUN RPL DIO trickle parameters. + * + * Function stores new parameters to Border Router and uses them when mesh interface connect() is called + * next time. If device is already connected to the Wi-SUN network then device will restart Wi-SUN network after + * changing the RPL DIO trickle parameters. Mesh interface must be initialized before calling this + * function. + * + * \param dio_interval_min DIO trickle timer Imin parameter. Use 0x00 to use leave parameter unchanged. + * \param dio_interval_doublings DIO trickle timer Imax parameter as doublings of Imin. Use 0x00 to use leave parameter unchanged. + * \param dio_redundancy_constant DIO trickle timer redundancy constant. 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_rpl_parameters(uint8_t dio_interval_min, uint8_t dio_interval_doublings, uint8_t dio_redundancy_constant); + + /** + * \brief Get Wi-SUN RPL DIO trickle parameters. + * + * Function reads DIO trickle timer Imin, DIO trickle timer Imax and DIO trickle timer redundancy + * constant from Border Router. Mesh interface must be initialized before calling this function. + * + * \param dio_interval_min DIO trickle timer Imin parameter. + * \param dio_interval_doublings DIO trickle timer Imax parameter as doublings of Imin. + * \param dio_redundancy_constant DIO trickle timer redundancy constant. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t get_rpl_parameters(uint8_t *dio_interval_min, uint8_t *dio_interval_doublings, uint8_t *dio_redundancy_constant); + + /** + * \brief Validate Wi-SUN RPL DIO trickle parameters. + * + * Function validates DIO trickle timer Imin, DIO trickle timer Imax and DIO trickle timer redundancy + * constant. Function can be used to test that values that will be used on set function are valid. + * Mesh interface must be initialized before the calling this function. + * + * \param dio_interval_min DIO trickle timer Imin parameter. + * \param dio_interval_doublings DIO trickle timer Imax parameter as doublings of Imin. + * \param dio_redundancy_constant DIO trickle timer redundancy constant. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t validate_rpl_parameters(uint8_t dio_interval_min, uint8_t dio_interval_doublings, uint8_t dio_redundancy_constant); + + /** + * \brief Set Wi-SUN PAN configuration parameters. + * + * Function stores new parameters to Border Router and uses them when mesh interface connect() is called + * next time. If device is already connected to the Wi-SUN network then device will restart Wi-SUN network after + * changing the PAN configuration parameters. Mesh interface must be initialized before calling this + * function. + * + * \param pan_id PAN ID. 0xffff will generate the PAN ID on the mesh interface connect() call if not already generated. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t set_pan_configuration(uint16_t pan_id); + + /** + * \brief Get Wi-SUN PAN configuration parameters. + * + * Function reads PAN ID from Border Router. Mesh interface must be initialized before calling this function. + * + * \param pan_id PAN ID. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t get_pan_configuration(uint16_t *pan_id); + + /** + * \brief Validate Wi-SUN PAN configuration parameters. + * + * Function validates PAN ID. Function can be used to test that values that will be used on set function are valid. + * Mesh interface must be initialized before calling this function. + * + * \param pan_id PAN ID. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t validate_pan_configuration(uint16_t pan_id); + +private: + int8_t _mesh_if_id = -1; + +}; + +#endif diff --git a/features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h b/features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h index e80657c3e3d..7fd06c1f49a 100644 --- a/features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h +++ b/features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h @@ -52,6 +52,28 @@ class WisunInterface : public MeshInterfaceNanostack { * */ mesh_error_t set_network_name(char *network_name); + /** + * \brief Get Wi-SUN network name. + * + * Function reads network name from mbed-mesh-api. + * + * \param network_name Network name as NUL terminated string. Must have space for 33 characters (string and null terminator). + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t get_network_name(char *network_name); + + /** + * \brief Validate Wi-SUN network name. + * + * Function validates network name. Function can be used to test that values that will be used on set function are valid. + * + * \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. + * */ + mesh_error_t validate_network_name(char *network_name); + /** * \brief Set Wi-SUN network regulatory domain, operating class and operating mode. * @@ -69,6 +91,252 @@ class WisunInterface : public MeshInterfaceNanostack { * */ mesh_error_t set_network_regulatory_domain(uint8_t regulatory_domain = 0xff, uint8_t operating_class = 0xff, uint8_t operating_mode = 0xff); + /** + * \brief Get Wi-SUN network regulatory domain, operating class and operating mode. + * + * Function reads regulatory_domain, operating_class and operating_mode from mbed-mesh-api. + * + * \param regulatory_domain Values defined in Wi-SUN PHY-specification. + * \param operating_class Values defined in Wi-SUN PHY-specification. + * \param operating_mode Values defined in Wi-SUN PHY-specification. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t get_network_regulatory_domain(uint8_t *regulatory_domain, uint8_t *operating_class, uint8_t *operating_mode); + + /** + * \brief Validate Wi-SUN network regulatory domain, operating class and operating mode. + * + * Function validates regulatory_domain, operating_class and operating_mode. Function can be used to test that values that will + * be used on set function are valid. + * + * \param regulatory_domain Values defined in Wi-SUN PHY-specification. + * \param operating_class Values defined in Wi-SUN PHY-specification. + * \param operating_mode Values defined in Wi-SUN PHY-specification. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t validate_network_regulatory_domain(uint8_t regulatory_domain, uint8_t operating_class, uint8_t operating_mode); + + /** + * \brief Set Wi-SUN network size. + * + * 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 network size. + * + * Default value: medium + * Small network size: less than hundred devices + * Medium network size: hundreds of devices + * Large network size: thousands of devices + * Certificate: used on testing + * + * When network size is changed, it will override all or some of the following configuration values: + * - Timing settings set by set_timing_parameters() of the Wi-SUN interface. + * - RPL settings set by rpl_parameters_set() of the Border Router interface. + * + * When network size is changed, and if timing or RPL values should be other than defaults set by stack for the network size, + * they need to set again using above function calls. + * + * \param network_size Network size in hundreds of devices (e.g. 1200 devices is 12), 0x00 for network size certificate. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t set_network_size(uint8_t network_size); + + /** + * \brief Get Wi-SUN network size. + * + * Function reads network size from mbed-mesh-api. + * + * \param network_size Network size in hundreds of devices, 0x00 for network size certificate. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t get_network_size(uint8_t *network_size); + + /** + * \brief Validate Wi-SUN network size. + * + * Function validates network size from mbed-mesh-api. Function can be used to test that values that will + * be used on set function are valid. + * + * \param network_size Network size in hundreds of devices, 0x00 for network size certificate. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t validate_network_size(uint8_t network_size); + + /** + * \brief Set Wi-SUN FHSS channel mask + * + * 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 settings take effect right away. + * + * \param channel_mask Values defined in Wi-SUN management API. Channel mask bit field. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t set_channel_mask(uint32_t channel_mask[8]); + + /** + * \brief Get Wi-SUN FHSS channel mask + * + * Function reads FHSS channel mask from mbed-mesh-api. + * + * \param channel_mask Values defined in Wi-SUN management API. Channel mask bit field. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t get_channel_mask(uint32_t *channel_mask); + + /** + * \brief Validate Wi-SUN FHSS channel mask + * + * Function validates FHSS channel mask. Function can be used to test that values that will + * be used on set function are valid. + * + * \param channel_mask Values defined in Wi-SUN management API. Channel mask bit field. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t validate_channel_mask(uint32_t channel_mask[8]); + + /** + * \brief Set Wi-SUN FHSS unicast channel function parameters + * + * 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 channel function, fixed channel or dwell interval. + * + * Function overwrites parameters defined by Mbed OS configuration. + * + * \param channel_function Channel function. Fixed, TR51CF, DH1CF or vendor defined. + * \param fixed_channel Used channel when channel function is fixed channel. Use 0xffff when fixed channel function not on use. + * \param dwell_interval Used dwell interval when channel function is TR51 or DH1. Use 0x00 to use leave parameter unchanged. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t set_unicast_channel_function(mesh_channel_function_t channel_function, uint16_t fixed_channel = 0xffff, uint8_t dwell_interval = 0x00); + + /** + * \brief Get Wi-SUN FHSS unicast channel function parameters + * + * Function reads FHSS unicast channel function parameters from mbed-mesh-api. + * + * \param channel_function Channel function. Fixed, TR51CF, DH1CF or vendor defined. + * \param fixed_channel Used channel when channel function is fixed channel. + * \param dwell_interval Used dwell interval when channel function is TR51 or DH1. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t get_unicast_channel_function(mesh_channel_function_t *channel_function, uint16_t *fixed_channel, uint8_t *dwell_interval); + + /** + * \brief Validate Wi-SUN FHSS unicast channel function parameters + * + * Function validates FHSS unicast channel function parameters. Function can be used to test that values that will + * be used on set function are valid. + * + * \param channel_function Channel function. Fixed, TR51CF, DH1CF or vendor defined. + * \param fixed_channel Used channel when channel function is fixed channel. + * \param dwell_interval Used dwell interval when channel function is TR51 or DH1. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t validate_unicast_channel_function(mesh_channel_function_t channel_function, uint16_t fixed_channel, uint8_t dwell_interval); + + /** + * \brief Set Wi-SUN FHSS broadcast channel function parameters + * + * 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 channel function, fixed channel, dwell interval or broadcast_interval. + * + * Function overwrites parameters defined by Mbed OS configuration. + * + * \param channel_function Channel function. Fixed, TR51CF, DH1CF or vendor defined. + * \param fixed_channel Used channel when channel function is fixed channel. Use 0xffff when fixed channel function not on use. + * \param dwell_interval Used dwell interval when channel function is TR51 or DH1. Use 0x00 to use leave parameter unchanged. + * \param broadcast_interval Used broadcast interval. Use 0x00 to use leave parameter unchanged. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + 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); + + /** + * \brief Get Wi-SUN FHSS broadcast channel function parameters + * + * Function reads FHSS broadcast channel function parameters from mbed-mesh-api. + * + * \param channel_function Channel function. Fixed, TR51CF, DH1CF or vendor defined. + * \param fixed_channel Used channel when channel function is fixed channel. + * \param dwell_interval Used dwell interval when channel function is TR51 or DH1. + * \param broadcast_interval Used broadcast interval. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + 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); + + /** + * \brief Validate Wi-SUN FHSS broadcast channel function parameters + * + * Function validates FHSS broadcast channel function parameters from mbed-mesh-api. Function can be used to test that values that will + * be used on set function are valid. + * + * \param channel_function Channel function. Fixed, TR51CF, DH1CF or vendor defined. + * \param fixed_channel Used channel when channel function is fixed channel. + * \param dwell_interval Used dwell interval when channel function is TR51 or DH1. + * \param broadcast_interval Used broadcast interval. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + 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); + + /** + * \brief Set Wi-SUN timing parameters + * + * 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 settings take effect right away. + * + * \param disc_trickle_imin Discovery trickle Imin. Range 1-255 seconds. Use 0x00 to use leave parameter unchanged. + * \param disc_trickle_imax Discovery trickle Imax. Range (2-2^8)*Imin. Use 0x00 to use leave parameter unchanged. + * \param disc_trickle_k Discovery trickle k. Use 0x00 to use leave parameter unchanged. + * \param pan_timeout PAN timeout; seconds; Range 60-15300 seconds. Use 0x00 to use leave parameter unchanged. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + 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); + + /** + * \brief Get Wi-SUN timing parameters + * + * Function reads timing parameters from mbed-mesh-api. + * + * \param disc_trickle_imin Discovery trickle Imin. Range 1-255 seconds. + * \param disc_trickle_imax Discovery trickle Imax. Range (2-2^8)*Imin. + * \param disc_trickle_k Discovery trickle k. + * \param pan_timeout PAN timeout; seconds; Range 60-15300 seconds. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + 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); + + /** + * \brief Validates Wi-SUN timing parameters + * + * Function validates timing parameters. Function can be used to test that values that will be used on set + * function are valid. + * + * \param disc_trickle_imin Discovery trickle Imin. Range 1-255 seconds. + * \param disc_trickle_imax Discovery trickle Imax. Range (2-2^8)*Imin. + * \param disc_trickle_k Discovery trickle k. + * \param pan_timeout PAN timeout; seconds; Range 60-15300 seconds. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + 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); + /** * \brief Set own certificate and private key reference to the Wi-SUN network. * @@ -134,6 +402,7 @@ class WisunInterface : public MeshInterfaceNanostack { protected: Nanostack::WisunInterface *get_interface() const; virtual nsapi_error_t do_initialize(); + virtual nsapi_error_t configure(); }; #endif diff --git a/features/nanostack/mbed-mesh-api/mbed-mesh-api/mesh_interface_types.h b/features/nanostack/mbed-mesh-api/mbed-mesh-api/mesh_interface_types.h index 7a6846955d5..b63c25713b5 100644 --- a/features/nanostack/mbed-mesh-api/mbed-mesh-api/mesh_interface_types.h +++ b/features/nanostack/mbed-mesh-api/mbed-mesh-api/mesh_interface_types.h @@ -62,6 +62,43 @@ typedef enum { MESH_DEVICE_TYPE_THREAD_MINIMAL_END_DEVICE /*bringdown(); } +char *Nanostack::MeshInterface::get_interface_name(char *buf) +{ + if (interface_id < 0) { + return NULL; + } + sprintf(buf, "MES%d", interface_id); + return buf; +}; + nsapi_error_t MeshInterfaceNanostack::initialize(NanostackRfPhy *phy) { if (_phy && phy && _phy != phy) { diff --git a/features/nanostack/mbed-mesh-api/source/NanostackEthernetInterface.cpp b/features/nanostack/mbed-mesh-api/source/NanostackEthernetInterface.cpp index 83c5af5d0d3..3ad3e3fa39c 100644 --- a/features/nanostack/mbed-mesh-api/source/NanostackEthernetInterface.cpp +++ b/features/nanostack/mbed-mesh-api/source/NanostackEthernetInterface.cpp @@ -120,3 +120,12 @@ nsapi_error_t Nanostack::EthernetInterface::bringdown() } return NSAPI_ERROR_OK; } + +char *Nanostack::EthernetInterface::get_interface_name(char *buf) +{ + if (interface_id < 0) { + return NULL; + } + sprintf(buf, "ETH%d", interface_id); + return buf; +}; diff --git a/features/nanostack/mbed-mesh-api/source/NanostackPPPInterface.cpp b/features/nanostack/mbed-mesh-api/source/NanostackPPPInterface.cpp index 85c2b3a3f9a..8a19090cd86 100644 --- a/features/nanostack/mbed-mesh-api/source/NanostackPPPInterface.cpp +++ b/features/nanostack/mbed-mesh-api/source/NanostackPPPInterface.cpp @@ -181,6 +181,15 @@ void Nanostack::PPPInterface::set_link_state_changed_callback(link_state_cb_t ne link_state_cb = new_link_state_cb; } +char *Nanostack::PPPInterface::get_interface_name(char *buf) +{ + if (interface_id < 0) { + return NULL; + } + sprintf(buf, "PPP%d", interface_id); + return buf; +}; + // GAH! no handles on the callback. Force a single interface static PPPPhy *single_phy; diff --git a/features/nanostack/mbed-mesh-api/source/WisunBorderRouter.cpp b/features/nanostack/mbed-mesh-api/source/WisunBorderRouter.cpp new file mode 100644 index 00000000000..d5fcf624ea8 --- /dev/null +++ b/features/nanostack/mbed-mesh-api/source/WisunBorderRouter.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2020 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "WisunInterface.h" +#include "ns_trace.h" +#include "WisunBorderRouter.h" +#include "MeshInterfaceNanostack.h" + +extern "C" { +#include "ws_bbr_api.h" +} + +#define TRACE_GROUP "WSBR" + +mesh_error_t WisunBorderRouter::start(NetworkInterface *mesh_if, NetworkInterface *backbone_if) +{ + if (mesh_if == NULL || backbone_if == NULL) { + return MESH_ERROR_PARAM; + } + + InterfaceNanostack *nano_mesh_if = reinterpret_cast(mesh_if); + int8_t mesh_if_id = nano_mesh_if->get_interface_id(); + if (mesh_if_id < 0) { + return MESH_ERROR_UNKNOWN; + } + _mesh_if_id = mesh_if_id; + + char backbone_if_name[7] = {0}; + if (backbone_if->get_interface_name(backbone_if_name) == NULL) { + return MESH_ERROR_UNKNOWN; + } + + if (strlen((char *) &backbone_if_name) < 4) { + return MESH_ERROR_UNKNOWN; + } + + int backbone_if_id = atoi(&backbone_if_name[3]); + if (backbone_if_id < 0) { + return MESH_ERROR_UNKNOWN; + } + + int ret = ws_bbr_start(mesh_if_id, backbone_if_id); + if (ret < 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunBorderRouter::start(NetworkInterface *mesh_if, OnboardNetworkStack::Interface *backbone_if) +{ + InterfaceNanostack *nano_mesh_if = reinterpret_cast(mesh_if); + int8_t mesh_if_id = nano_mesh_if->get_interface_id(); + if (mesh_if_id < 0) { + return MESH_ERROR_UNKNOWN; + } + _mesh_if_id = mesh_if_id; + + Nanostack::Interface *nano_backbone_if = static_cast(backbone_if); + int8_t backbone_if_id = nano_backbone_if->get_interface_id(); + if (backbone_if_id < 0) { + return MESH_ERROR_UNKNOWN; + } + + int ret = ws_bbr_start(mesh_if_id, backbone_if_id); + if (ret < 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +void WisunBorderRouter::stop() +{ + if (_mesh_if_id < 0) { + return; + } + + ws_bbr_stop(_mesh_if_id); + + _mesh_if_id = -1; +} + +mesh_error_t WisunBorderRouter::set_rpl_parameters(uint8_t dio_interval_min, uint8_t dio_interval_doublings, uint8_t dio_redundancy_constant) +{ + int status = ws_bbr_rpl_parameters_set(_mesh_if_id, dio_interval_min, dio_interval_doublings, dio_redundancy_constant); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunBorderRouter::get_rpl_parameters(uint8_t *dio_interval_min, uint8_t *dio_interval_doublings, uint8_t *dio_redundancy_constant) +{ + int status = ws_bbr_rpl_parameters_get(_mesh_if_id, dio_interval_min, dio_interval_doublings, dio_redundancy_constant); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunBorderRouter::validate_rpl_parameters(uint8_t dio_interval_min, uint8_t dio_interval_doublings, uint8_t dio_redundancy_constant) +{ + int status = ws_bbr_rpl_parameters_validate(_mesh_if_id, dio_interval_min, dio_interval_doublings, dio_redundancy_constant); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunBorderRouter::set_pan_configuration(uint16_t pan_id) +{ + int status = ws_bbr_pan_configuration_set(_mesh_if_id, pan_id); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunBorderRouter::get_pan_configuration(uint16_t *pan_id) +{ + int status = ws_bbr_pan_configuration_get(_mesh_if_id, pan_id); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunBorderRouter::validate_pan_configuration(uint16_t pan_id) +{ + int status = ws_bbr_pan_configuration_validate(_mesh_if_id, pan_id); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} diff --git a/features/nanostack/mbed-mesh-api/source/WisunInterface.cpp b/features/nanostack/mbed-mesh-api/source/WisunInterface.cpp index b363c7d578c..4cc2e703da8 100644 --- a/features/nanostack/mbed-mesh-api/source/WisunInterface.cpp +++ b/features/nanostack/mbed-mesh-api/source/WisunInterface.cpp @@ -21,6 +21,9 @@ #include "NanostackLockGuard.h" #include "mesh_system.h" #include "randLIB.h" +#include "fhss_api.h" +#include "fhss_config.h" +#include "ws_management_api.h" #include "ns_trace.h" #define TRACE_GROUP "WSIn" @@ -57,6 +60,63 @@ nsapi_error_t WisunInterface::do_initialize() } _interface->attach(_connection_status_cb); } + + // Apply mbed configuration to Wi-SUN + configure(); + + return NSAPI_ERROR_OK; +} + +nsapi_error_t WisunInterface::configure() +{ + int status; + + if (_configured) { + // Already configured + return NSAPI_ERROR_OK; + } + + _configured = true; +#ifdef MBED_CONF_MBED_MESH_API_WISUN_NETWORK_NAME + char network_name[] = {MBED_CONF_MBED_MESH_API_WISUN_NETWORK_NAME}; + status = set_network_name((char *) &network_name); + if (status < 0) { + tr_error("Failed to set network name!"); + return NSAPI_ERROR_PARAMETER; + } +#endif + +#if (MBED_CONF_MBED_MESH_API_WISUN_REGULATORY_DOMAIN != 255) || (MBED_CONF_MBED_MESH_API_WISUN_OPERATING_CLASS != 255) || (MBED_CONF_MBED_MESH_API_WISUN_OPERATING_MODE != 255) + status = set_network_regulatory_domain(MBED_CONF_MBED_MESH_API_WISUN_REGULATORY_DOMAIN, + MBED_CONF_MBED_MESH_API_WISUN_OPERATING_CLASS, + MBED_CONF_MBED_MESH_API_WISUN_OPERATING_MODE); + if (status < 0) { + tr_error("Failed to set regulatory domain!"); + return NSAPI_ERROR_PARAMETER; + } +#endif + +#if (MBED_CONF_MBED_MESH_API_WISUN_UC_CHANNEL_FUNCTION != 255) + status = set_unicast_channel_function(static_cast(MBED_CONF_MBED_MESH_API_WISUN_UC_CHANNEL_FUNCTION), + MBED_CONF_MBED_MESH_API_WISUN_UC_FIXED_CHANNEL, + MBED_CONF_MBED_MESH_API_WISUN_UC_DWELL_INTERVAL); + if (status < 0) { + tr_error("Failed to set unicast channel function configuration"); + return NSAPI_ERROR_PARAMETER; + } +#endif + +#if (MBED_CONF_MBED_MESH_API_WISUN_BC_CHANNEL_FUNCTION != 255) || (MBED_CONF_MBED_MESH_API_WISUN_BC_DWELL_INTERVAL != 0) || (MBED_CONF_MBED_MESH_API_WISUN_BC_INTERVAL != 0) + status = set_broadcast_channel_function(static_cast(MBED_CONF_MBED_MESH_API_WISUN_BC_CHANNEL_FUNCTION), + MBED_CONF_MBED_MESH_API_WISUN_BC_FIXED_CHANNEL, + MBED_CONF_MBED_MESH_API_WISUN_BC_DWELL_INTERVAL, + MBED_CONF_MBED_MESH_API_WISUN_BC_INTERVAL); + if (status < 0) { + tr_error("Failed to set broadcast channel function configuration"); + return NSAPI_ERROR_PARAMETER; + } +#endif + return NSAPI_ERROR_OK; } @@ -178,26 +238,226 @@ bool WisunInterface::getRouterIpAddress(char *address, int8_t len) mesh_error_t WisunInterface::set_network_name(char *network_name) { - mesh_error_t ret_val = MESH_ERROR_NONE; + int status = ws_management_network_name_set(get_interface_id(), network_name); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} - int status = wisun_tasklet_set_network_name(get_interface_id(), network_name); +mesh_error_t WisunInterface::get_network_name(char *network_name) +{ + int status = ws_management_network_name_get(get_interface_id(), network_name); if (status != 0) { - ret_val = MESH_ERROR_UNKNOWN; + return MESH_ERROR_UNKNOWN; } - return ret_val; + return MESH_ERROR_NONE; +} + +mesh_error_t WisunInterface::validate_network_name(char *network_name) +{ + int status = ws_management_network_name_validate(get_interface_id(), network_name); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; } 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 = ws_management_regulatory_domain_set(get_interface_id(), regulatory_domain, operating_class, operating_mode); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} - int status = wisun_tasklet_set_regulatory_domain(get_interface_id(), regulatory_domain, operating_class, operating_mode); +mesh_error_t WisunInterface::get_network_regulatory_domain(uint8_t *regulatory_domain, uint8_t *operating_class, uint8_t *operating_mode) +{ + int status = ws_management_regulatory_domain_get(get_interface_id(), regulatory_domain, operating_class, operating_mode); if (status != 0) { - ret_val = MESH_ERROR_UNKNOWN; + return MESH_ERROR_UNKNOWN; } - return ret_val; + return MESH_ERROR_NONE; +} + +mesh_error_t WisunInterface::validate_network_regulatory_domain(uint8_t regulatory_domain, uint8_t operating_class, uint8_t operating_mode) +{ + int status = ws_management_regulatory_domain_validate(get_interface_id(), regulatory_domain, operating_class, operating_mode); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunInterface::set_network_size(uint8_t network_size) +{ + if (network_size == 0xff) { + // Size 0xff is internal API + network_size = 0xfe; + } + + int status = ws_management_network_size_set(get_interface_id(), network_size); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunInterface::get_network_size(uint8_t *network_size) +{ + int status = ws_management_network_size_get(get_interface_id(), network_size); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunInterface::validate_network_size(uint8_t network_size) +{ + if (network_size == 0xff) { + // Size 0xff is internal API + network_size = 0xfe; + } + + int status = ws_management_network_size_validate(get_interface_id(), network_size); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunInterface::set_channel_mask(uint32_t channel_mask[8]) +{ + int status = ws_management_channel_mask_set(get_interface_id(), channel_mask); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunInterface::get_channel_mask(uint32_t *channel_mask) +{ + int status = ws_management_channel_mask_get(get_interface_id(), channel_mask); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunInterface::validate_channel_mask(uint32_t channel_mask[8]) +{ + int status = ws_management_channel_mask_validate(get_interface_id(), channel_mask); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunInterface::set_unicast_channel_function(mesh_channel_function_t channel_function, uint16_t fixed_channel, uint8_t dwell_interval) +{ + int status = ws_management_fhss_unicast_channel_function_configure(get_interface_id(), channel_function, fixed_channel, dwell_interval); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunInterface::get_unicast_channel_function(mesh_channel_function_t *channel_function, uint16_t *fixed_channel, uint8_t *dwell_interval) +{ + uint8_t ch_function; + int status = ws_management_fhss_unicast_channel_function_get(get_interface_id(), &ch_function, fixed_channel, dwell_interval); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + *channel_function = static_cast(ch_function); + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunInterface::validate_unicast_channel_function(mesh_channel_function_t channel_function, uint16_t fixed_channel, uint8_t dwell_interval) +{ + int status = ws_management_fhss_unicast_channel_function_validate(get_interface_id(), channel_function, fixed_channel, dwell_interval); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunInterface::set_broadcast_channel_function(mesh_channel_function_t channel_function, uint16_t fixed_channel, uint8_t dwell_interval, uint32_t broadcast_interval) +{ + int status = ws_management_fhss_broadcast_channel_function_configure(get_interface_id(), channel_function, fixed_channel, dwell_interval, broadcast_interval); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunInterface::get_broadcast_channel_function(mesh_channel_function_t *channel_function, uint16_t *fixed_channel, uint8_t *dwell_interval, uint32_t *broadcast_interval) +{ + uint8_t ch_function; + int status = ws_management_fhss_broadcast_channel_function_get(get_interface_id(), &ch_function, fixed_channel, dwell_interval, broadcast_interval); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + *channel_function = static_cast(ch_function); + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunInterface::validate_broadcast_channel_function(mesh_channel_function_t channel_function, uint16_t fixed_channel, uint8_t dwell_interval, uint32_t broadcast_interval) +{ + int status = ws_management_fhss_broadcast_channel_function_validate(get_interface_id(), channel_function, fixed_channel, dwell_interval, broadcast_interval); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunInterface::set_timing_parameters(uint16_t disc_trickle_imin, uint16_t disc_trickle_imax, uint8_t disc_trickle_k, uint16_t pan_timeout) +{ + int status = ws_management_timing_parameters_set(get_interface_id(), disc_trickle_imin, disc_trickle_imax, disc_trickle_k, pan_timeout); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunInterface::get_timing_parameters(uint16_t *disc_trickle_imin, uint16_t *disc_trickle_imax, uint8_t *disc_trickle_k, uint16_t *pan_timeout) +{ + int status = ws_management_timing_parameters_get(get_interface_id(), disc_trickle_imin, disc_trickle_imax, disc_trickle_k, pan_timeout); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunInterface::validate_timing_parameters(uint16_t disc_trickle_imin, uint16_t disc_trickle_imax, uint8_t disc_trickle_k, uint16_t pan_timeout) +{ + int status = ws_management_timing_parameters_validate(get_interface_id(), disc_trickle_imin, disc_trickle_imax, disc_trickle_k, pan_timeout); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; } mesh_error_t WisunInterface::set_own_certificate(uint8_t *cert, uint16_t cert_len, uint8_t *cert_key, uint16_t cert_key_len) diff --git a/features/nanostack/mbed-mesh-api/source/include/wisun_tasklet.h b/features/nanostack/mbed-mesh-api/source/include/wisun_tasklet.h index d4ff836f929..0294e4e915e 100644 --- a/features/nanostack/mbed-mesh-api/source/include/wisun_tasklet.h +++ b/features/nanostack/mbed-mesh-api/source/include/wisun_tasklet.h @@ -79,28 +79,6 @@ 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 * diff --git a/features/nanostack/mbed-mesh-api/source/wisun_tasklet.c b/features/nanostack/mbed-mesh-api/source/wisun_tasklet.c index f822ab823d3..96b35683539 100644 --- a/features/nanostack/mbed-mesh-api/source/wisun_tasklet.c +++ b/features/nanostack/mbed-mesh-api/source/wisun_tasklet.c @@ -70,20 +70,6 @@ typedef struct { int8_t network_interface_id; } wisun_tasklet_data_str_t; -typedef struct { - char *network_name; - uint8_t regulatory_domain; - uint8_t rd_operating_class; - uint8_t rd_operating_mode; - uint8_t uc_channel_function; - uint8_t bc_channel_function; - uint8_t uc_dwell_interval; - uint32_t bc_interval; - uint8_t bc_dwell_interval; - uint16_t uc_fixed_channel; - uint16_t bc_fixed_channel; -} wisun_network_settings_t; - typedef struct { arm_certificate_entry_s arm_cert_entry; ns_list_link_t link; /*!< List link entry */ @@ -97,25 +83,9 @@ typedef struct { bool remove_trusted_certificates: 1; } wisun_certificates_t; -#define WS_NA 0xff // Not applicable value -#define WS_DEFAULT 0x00 // Use default value - /* Tasklet data */ static wisun_tasklet_data_str_t *wisun_tasklet_data_ptr = NULL; static wisun_certificates_t *wisun_certificates_ptr = NULL; -static wisun_network_settings_t wisun_settings_str = { - .network_name = NULL, - .regulatory_domain = MBED_CONF_MBED_MESH_API_WISUN_REGULATORY_DOMAIN, - .rd_operating_class = MBED_CONF_MBED_MESH_API_WISUN_OPERATING_CLASS, - .rd_operating_mode = MBED_CONF_MBED_MESH_API_WISUN_OPERATING_MODE, - .uc_channel_function = MBED_CONF_MBED_MESH_API_WISUN_UC_CHANNEL_FUNCTION, - .bc_channel_function = MBED_CONF_MBED_MESH_API_WISUN_BC_CHANNEL_FUNCTION, - .uc_dwell_interval = MBED_CONF_MBED_MESH_API_WISUN_UC_DWELL_INTERVAL, - .bc_interval = MBED_CONF_MBED_MESH_API_WISUN_BC_INTERVAL, - .bc_dwell_interval = MBED_CONF_MBED_MESH_API_WISUN_BC_DWELL_INTERVAL, - .uc_fixed_channel = MBED_CONF_MBED_MESH_API_WISUN_UC_FIXED_CHANNEL, - .bc_fixed_channel = MBED_CONF_MBED_MESH_API_WISUN_BC_FIXED_CHANNEL -}; static mac_api_t *mac_api = NULL; extern fhss_timer_t fhss_functions; @@ -265,70 +235,32 @@ static void wisun_tasklet_configure_and_connect_to_network(void) return; } + char network_name[33]; + status = ws_management_network_name_get(wisun_tasklet_data_ptr->network_interface_id, (char *) &network_name); + if (status < 0) { + tr_error("Failed to read network name"); + return; + } + uint8_t regulatory_domain; + uint8_t operating_class; + uint8_t operating_mode; + status = ws_management_regulatory_domain_get(wisun_tasklet_data_ptr->network_interface_id, + ®ulatory_domain, + &operating_class, + &operating_mode); + if (status < 0) { + tr_error("Failed to read regulatory domain"); + return; + } status = ws_management_node_init(wisun_tasklet_data_ptr->network_interface_id, - MBED_CONF_MBED_MESH_API_WISUN_REGULATORY_DOMAIN, - wisun_settings_str.network_name, + regulatory_domain, + (char *) network_name, fhss_timer_ptr); if (status < 0) { tr_error("Failed to initialize WS"); return; } - if (wisun_settings_str.uc_channel_function != WS_NA) { - status = ws_management_fhss_unicast_channel_function_configure(wisun_tasklet_data_ptr->network_interface_id, - wisun_settings_str.uc_channel_function, - wisun_settings_str.uc_fixed_channel, - wisun_settings_str.uc_dwell_interval); - - if (status < 0) { - tr_error("Failed to set unicast channel function configuration"); - return; - } - } - - if (wisun_settings_str.bc_channel_function != WS_NA || - wisun_settings_str.bc_dwell_interval != WS_DEFAULT || - wisun_settings_str.bc_interval != WS_DEFAULT) { - status = ws_management_fhss_broadcast_channel_function_configure(wisun_tasklet_data_ptr->network_interface_id, - wisun_settings_str.bc_channel_function, - wisun_settings_str.bc_fixed_channel, - wisun_settings_str.bc_dwell_interval, - wisun_settings_str.bc_interval); - - if (status < 0) { - tr_error("Failed to set broadcast channel function configuration"); - return; - } - } - - if (wisun_settings_str.uc_dwell_interval != WS_DEFAULT || - wisun_settings_str.bc_dwell_interval != WS_DEFAULT || - wisun_settings_str.bc_interval != WS_DEFAULT) { - status = ws_management_fhss_timing_configure(wisun_tasklet_data_ptr->network_interface_id, - wisun_settings_str.uc_dwell_interval, - wisun_settings_str.bc_interval, - wisun_settings_str.bc_dwell_interval); - - if (status < 0) { - tr_error("Failed to set fhss configuration"); - return; - } - } - - if (wisun_settings_str.regulatory_domain != WS_NA || - wisun_settings_str.rd_operating_class != WS_NA || - wisun_settings_str.rd_operating_mode != WS_NA) { - status = ws_management_regulatory_domain_set(wisun_tasklet_data_ptr->network_interface_id, - wisun_settings_str.regulatory_domain, - wisun_settings_str.rd_operating_class, - wisun_settings_str.rd_operating_mode); - - if (status < 0) { - tr_error("Failed to set regulatory domain!"); - return; - } - } - #if defined(MBED_CONF_MBED_MESH_API_CERTIFICATE_HEADER) arm_certificate_entry_s trusted_cert = { .cert = MBED_CONF_MBED_MESH_API_ROOT_CERTIFICATE, @@ -583,57 +515,9 @@ int8_t wisun_tasklet_network_init(int8_t device_id) mac_api = ns_sw_mac_create(device_id, &storage_sizes); } - if (!wisun_settings_str.network_name) { - // No network name set by API, use network name from configuration - int wisun_network_name_len = sizeof(MBED_CONF_MBED_MESH_API_WISUN_NETWORK_NAME); - wisun_settings_str.network_name = (char *)ns_dyn_mem_alloc(wisun_network_name_len); - if (!wisun_settings_str.network_name) { - return -3; - } - strncpy(wisun_settings_str.network_name, MBED_CONF_MBED_MESH_API_WISUN_NETWORK_NAME, wisun_network_name_len); - } - return arm_nwk_interface_lowpan_init(mac_api, INTERFACE_NAME); } -int wisun_tasklet_set_network_name(int8_t nwk_interface_id, char *network_name_ptr) -{ - if (!network_name_ptr || strlen(network_name_ptr) > 32) { - return -1; - } - - // save the network name to have support for disconnect/connect - ns_dyn_mem_free(wisun_settings_str.network_name); - wisun_settings_str.network_name = (char *)ns_dyn_mem_alloc(strlen(network_name_ptr) + 1); - if (!wisun_settings_str.network_name) { - return -2; - } - - strcpy(wisun_settings_str.network_name, network_name_ptr); - - if (wisun_tasklet_data_ptr && wisun_tasklet_data_ptr->tasklet_state == TASKLET_STATE_BOOTSTRAP_READY) { - // interface is up, try to change name dynamically - return ws_management_network_name_set(nwk_interface_id, wisun_settings_str.network_name); - } - - return 0; -} - -int wisun_tasklet_set_regulatory_domain(int8_t nwk_interface_id, uint8_t regulatory_domain, uint8_t operating_class, uint8_t operating_mode) -{ - int status = 0; - - wisun_settings_str.regulatory_domain = regulatory_domain; - wisun_settings_str.rd_operating_class = operating_class; - wisun_settings_str.rd_operating_mode = operating_mode; - - if (wisun_tasklet_data_ptr && wisun_tasklet_data_ptr->tasklet_state == TASKLET_STATE_BOOTSTRAP_READY) { - status = ws_management_regulatory_domain_set(nwk_interface_id, regulatory_domain, operating_class, operating_mode); - } - - return status; -} - int wisun_tasklet_set_own_certificate(uint8_t *cert, uint16_t cert_len, uint8_t *cert_key, uint16_t cert_key_len) { if (wisun_tasklet_data_ptr) {