From 2f4b3426cbf502db9bdb1427ee21c8ebc9789241 Mon Sep 17 00:00:00 2001 From: Jarkko Paso Date: Fri, 15 Jan 2021 12:43:24 +0200 Subject: [PATCH 1/3] Mesh api: Added PHY mode and channel plan IDs --- .../mbed-mesh-api/WisunInterface.h | 16 +++++++++++++ .../nanostack/mbed-mesh-api/mbed_lib.json | 8 +++++++ .../mbed-mesh-api/source/WisunInterface.cpp | 23 +++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h b/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h index 0c0407c60df..57ad766f62c 100644 --- a/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h +++ b/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h @@ -157,6 +157,22 @@ class WisunInterface final : public MeshInterfaceNanostack { * */ mesh_error_t validate_network_regulatory_domain(uint8_t regulatory_domain, uint8_t operating_class, uint8_t operating_mode); + /** + * \brief Set Wi-SUN network PHY mode and channel plan IDs. + * + * 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 phy_mode_id or channel_plan_id. + * + * Function overwrites parameters defined by Mbed OS configuration. + * + * \param phy_mode_id Values defined in Wi-SUN PHY-specification. Use 0xff to leave parameter unchanged. + * \param channel_plan_id Values defined in Wi-SUN PHY-specification. Use 0xff to leave parameter unchanged. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t set_network_phy_mode_and_channel_plan_id(uint8_t phy_mode_id, uint8_t channel_plan_id); + /** * \brief Set Wi-SUN network size. * diff --git a/connectivity/nanostack/mbed-mesh-api/mbed_lib.json b/connectivity/nanostack/mbed-mesh-api/mbed_lib.json index 949c87acc43..f71df5fe18c 100644 --- a/connectivity/nanostack/mbed-mesh-api/mbed_lib.json +++ b/connectivity/nanostack/mbed-mesh-api/mbed_lib.json @@ -136,6 +136,14 @@ "help": "Operating mode as specified in the Wi-SUN PHY Specification. Wi-SUN stack uses operating-mode suitable for EU-region if value 255 is used.", "value": "255" }, + "wisun-phy-mode-id": { + "help": "PHY mode ID as specified in the Wi-SUN PHY Specification. With default value 255, parameter is not used.", + "value": "255" + }, + "wisun-channel-plan-id": { + "help": "Channel plan ID as specified in the Wi-SUN PHY Specification. With default value 255, parameter is not used.", + "value": "255" + }, "wisun-uc-channel-function": { "help": "Unicast channel function as specified in the Wi-SUN FAN specification. Wi-SUN stack will select channel function if value 255 is used.", "value": 255 diff --git a/connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp b/connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp index cde1e3e3371..6a142e0e7da 100644 --- a/connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp +++ b/connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp @@ -98,6 +98,15 @@ nsapi_error_t WisunInterface::configure() } #endif +#if (MBED_CONF_MBED_MESH_API_WISUN_PHY_MODE_ID != 255) || (MBED_CONF_MBED_MESH_API_WISUN_CHANNEL_PLAN_ID != 255) + status = set_network_phy_mode_and_channel_plan_id(MBED_CONF_MBED_MESH_API_WISUN_PHY_MODE_ID, + MBED_CONF_MBED_MESH_API_WISUN_CHANNEL_PLAN_ID); + if (status != MESH_ERROR_NONE) { + tr_error("Failed to set PHY mode and channel plan ID!"); + 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, @@ -308,6 +317,20 @@ mesh_error_t WisunInterface::validate_network_regulatory_domain(uint8_t regulato return MESH_ERROR_NONE; } +mesh_error_t WisunInterface::set_network_phy_mode_and_channel_plan_id(uint8_t phy_mode_id, uint8_t channel_plan_id) +{ + int status = ws_management_phy_mode_id_set(get_interface_id(), phy_mode_id); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + status = ws_management_channel_plan_id_set(get_interface_id(), channel_plan_id); + 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) { From 6c7789e31e66f2d5b2d505dcfd3f21495a596a22 Mon Sep 17 00:00:00 2001 From: Jarkko Paso Date: Mon, 18 Jan 2021 16:10:26 +0200 Subject: [PATCH 2/3] Fixed astyle issue --- connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp b/connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp index 6a142e0e7da..e040b7c8d19 100644 --- a/connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp +++ b/connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp @@ -100,7 +100,7 @@ nsapi_error_t WisunInterface::configure() #if (MBED_CONF_MBED_MESH_API_WISUN_PHY_MODE_ID != 255) || (MBED_CONF_MBED_MESH_API_WISUN_CHANNEL_PLAN_ID != 255) status = set_network_phy_mode_and_channel_plan_id(MBED_CONF_MBED_MESH_API_WISUN_PHY_MODE_ID, - MBED_CONF_MBED_MESH_API_WISUN_CHANNEL_PLAN_ID); + MBED_CONF_MBED_MESH_API_WISUN_CHANNEL_PLAN_ID); if (status != MESH_ERROR_NONE) { tr_error("Failed to set PHY mode and channel plan ID!"); return NSAPI_ERROR_PARAMETER; From 37e42fb1b75c1dbf7a82a4ce2fa3810879d30228 Mon Sep 17 00:00:00 2001 From: Jarkko Paso Date: Tue, 9 Feb 2021 10:10:20 +0200 Subject: [PATCH 3/3] Mesh API: Functions to set/get/validate FAN v1.1 domain configuration. --- .../mbed-mesh-api/WisunInterface.h | 38 ++++++++++++++++--- .../mbed-mesh-api/source/WisunInterface.cpp | 29 +++++++++++--- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h b/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h index 57ad766f62c..712ad54c61f 100644 --- a/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h +++ b/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h @@ -158,20 +158,46 @@ class WisunInterface final : public MeshInterfaceNanostack { mesh_error_t validate_network_regulatory_domain(uint8_t regulatory_domain, uint8_t operating_class, uint8_t operating_mode); /** - * \brief Set Wi-SUN network PHY mode and channel plan IDs. + * \brief Set Wi-SUN network regulatory domain, PHY mode ID and channel plan ID. * * 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 phy_mode_id or channel_plan_id. + * changing the regulatory_domain, phy_mode_id or channel_plan_id. * - * Function overwrites parameters defined by Mbed OS configuration. + * \param regulatory_domain Values defined in Wi-SUN PHY-specification. Use 0 to leave parameter unchanged or 0xff to use default value. + * \param phy_mode_id Values defined in Wi-SUN PHY-specification. Use 0 to leave parameter unchanged or 0xff to use default value. + * \param channel_plan_id Values defined in Wi-SUN PHY-specification. Use 0 to leave parameter unchanged or 0xff to use default value. + * \return MESH_ERROR_NONE on success. + * \return MESH_ERROR_UNKNOWN in case of failure. + * */ + mesh_error_t set_network_domain_configuration(uint8_t regulatory_domain, uint8_t phy_mode_id, uint8_t channel_plan_id); + + /** + * \brief Get Wi-SUN network regulatory domain, PHY mode ID and channel plan ID. + * + * Function reads regulatory_domain, phy_mode_id and channel_plan_id from mbed-mesh-api. * - * \param phy_mode_id Values defined in Wi-SUN PHY-specification. Use 0xff to leave parameter unchanged. - * \param channel_plan_id Values defined in Wi-SUN PHY-specification. Use 0xff to leave parameter unchanged. + * \param regulatory_domain Values defined in Wi-SUN PHY-specification. + * \param phy_mode_id Values defined in Wi-SUN PHY-specification. + * \param channel_plan_id 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_domain_configuration(uint8_t *regulatory_domain, uint8_t *phy_mode_id, uint8_t *channel_plan_id); + + /** + * \brief Validate Wi-SUN network regulatory domain, PHY mode ID and channel plan ID. + * + * Function validates regulatory_domain, phy_mode_id and channel_plan_id. 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 phy_mode_id Values defined in Wi-SUN PHY-specification. + * \param channel_plan_id Values defined in Wi-SUN PHY-specification. * \return MESH_ERROR_NONE on success. * \return MESH_ERROR_UNKNOWN in case of failure. * */ - mesh_error_t set_network_phy_mode_and_channel_plan_id(uint8_t phy_mode_id, uint8_t channel_plan_id); + mesh_error_t validate_network_domain_configuration(uint8_t regulatory_domain, uint8_t phy_mode_id, uint8_t channel_plan_id); /** * \brief Set Wi-SUN network size. diff --git a/connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp b/connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp index e040b7c8d19..4555c4ec66e 100644 --- a/connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp +++ b/connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp @@ -99,10 +99,11 @@ nsapi_error_t WisunInterface::configure() #endif #if (MBED_CONF_MBED_MESH_API_WISUN_PHY_MODE_ID != 255) || (MBED_CONF_MBED_MESH_API_WISUN_CHANNEL_PLAN_ID != 255) - status = set_network_phy_mode_and_channel_plan_id(MBED_CONF_MBED_MESH_API_WISUN_PHY_MODE_ID, - MBED_CONF_MBED_MESH_API_WISUN_CHANNEL_PLAN_ID); + status = set_network_domain_configuration(MBED_CONF_MBED_MESH_API_WISUN_REGULATORY_DOMAIN, + MBED_CONF_MBED_MESH_API_WISUN_PHY_MODE_ID, + MBED_CONF_MBED_MESH_API_WISUN_CHANNEL_PLAN_ID); if (status != MESH_ERROR_NONE) { - tr_error("Failed to set PHY mode and channel plan ID!"); + tr_error("Failed to set domain configuration!"); return NSAPI_ERROR_PARAMETER; } #endif @@ -317,13 +318,29 @@ mesh_error_t WisunInterface::validate_network_regulatory_domain(uint8_t regulato return MESH_ERROR_NONE; } -mesh_error_t WisunInterface::set_network_phy_mode_and_channel_plan_id(uint8_t phy_mode_id, uint8_t channel_plan_id) +mesh_error_t WisunInterface::set_network_domain_configuration(uint8_t regulatory_domain, uint8_t phy_mode_id, uint8_t channel_plan_id) { - int status = ws_management_phy_mode_id_set(get_interface_id(), phy_mode_id); + int status = ws_management_domain_configuration_set(get_interface_id(), regulatory_domain, phy_mode_id, channel_plan_id); if (status != 0) { return MESH_ERROR_UNKNOWN; } - status = ws_management_channel_plan_id_set(get_interface_id(), channel_plan_id); + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunInterface::get_network_domain_configuration(uint8_t *regulatory_domain, uint8_t *phy_mode_id, uint8_t *channel_plan_id) +{ + int status = ws_management_domain_configuration_get(get_interface_id(), regulatory_domain, phy_mode_id, channel_plan_id); + if (status != 0) { + return MESH_ERROR_UNKNOWN; + } + + return MESH_ERROR_NONE; +} + +mesh_error_t WisunInterface::validate_network_domain_configuration(uint8_t regulatory_domain, uint8_t phy_mode_id, uint8_t channel_plan_id) +{ + int status = ws_management_domain_configuration_validate(get_interface_id(), regulatory_domain, phy_mode_id, channel_plan_id); if (status != 0) { return MESH_ERROR_UNKNOWN; }