Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mesh API: Get and validate functions for PHY mode and channel plan IDs #14251

Merged
merged 1 commit into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,46 @@ class WisunInterface : 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.
Expand Down
29 changes: 23 additions & 6 deletions features/nanostack/mbed-mesh-api/source/WisunInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -315,13 +316,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;
Copy link
Contributor

Choose a reason for hiding this comment

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

we not have a better error than unknot available?

Copy link
Author

Choose a reason for hiding this comment

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

Actually we have these error types in mesh API:
MESH_ERROR_NONE
MESH_ERROR_UNKNOWN
MESH_ERROR_MEMORY
MESH_ERROR_STATE
MESH_ERROR_PARAM

But Nanostack API documentation (Doxygen) doesn't tell the reason for error. It only says: "return <0 Fail" for every WS management function.

We should probably first check that error values are correctly set and documented in Nanostack API.

Copy link
Contributor

Choose a reason for hiding this comment

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

MESH_ERROR_PARAM may be good select for indicate proper information

}
Expand Down