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 9a782bff89..972810fa6a 100644 --- a/features/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h +++ b/features/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h @@ -172,6 +172,7 @@ protected: 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/WisunInterface.h b/features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h index eee67d5fad..d23efc6bfb 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 @@ public: * */ 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 @@ public: * */ 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. * @@ -168,6 +436,7 @@ public: 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 c3f5ad7c0d..5fd4902846 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 @@ -64,6 +64,16 @@ typedef enum { MESH_DEVICE_TYPE_WISUN_BORDER_ROUTER /*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 = wisun_tasklet_set_network_name(get_interface_id(), network_name); + int status = ws_management_network_name_set(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::get_network_name(char *network_name) +{ + int status = ws_management_network_name_get(get_interface_id(), network_name); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + 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 = wisun_tasklet_set_regulatory_domain(get_interface_id(), regulatory_domain, operating_class, operating_mode); + int status = ws_management_regulatory_domain_set(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::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) { + return MESH_ERROR_UNKNOWN; + } + + 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 5d6e5cbec4..5156293633 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 822d62fab2..5a052372da 100644 --- a/features/nanostack/mbed-mesh-api/source/wisun_tasklet.c +++ b/features/nanostack/mbed-mesh-api/source/wisun_tasklet.c @@ -71,20 +71,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 */ @@ -98,25 +84,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; typedef struct { @@ -280,70 +250,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, @@ -602,57 +534,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) {