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

mbed-os-5.15: Add APIs for Device min sense and CCA threshold table #13758

Merged
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
59 changes: 59 additions & 0 deletions features/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,20 @@ typedef struct ws_stack_state {
uint8_t join_state;
/** Network PAN ID */
uint16_t pan_id;
/** Device RF minimum sensitivity configuration. lowest level of radio signal strength packet heard. Range of -174 (0) to +80 (254) dBm*/
uint8_t device_min_sens;
} ws_stack_state_t;

/**
* \brief Struct ws_cca_threshold_table Wi-SUN CCA threshold table information.
*/
typedef struct ws_cca_threshold_table {
/** Number of channels */
uint8_t number_of_channels;
/** CCA threshold table */
const int8_t *cca_threshold_table;
} ws_cca_threshold_table_t;

/** Wi-SUN mesh network interface class
*
* Configure Nanostack to use Wi-SUN protocol.
Expand Down Expand Up @@ -373,6 +385,41 @@ class WisunInterface : public MeshInterfaceNanostack {
* */
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 Wi-SUN device minimum sensitivity
*
* 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 device_min_sens Device minimum sensitivity. Range 0(-174 dB) to 254(+80 dB).
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_UNKNOWN in case of failure.
* */
mesh_error_t set_device_min_sens(uint8_t device_min_sens);

/**
* \brief Get Wi-SUN device minimum sensitivity.
*
* Function reads device minimum sensitivity from mbed-mesh-api.
*
* \param device_min_sens Device minimum sensitivity. Range 0-254.
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_UNKNOWN in case of failure.
* */
mesh_error_t get_device_min_sens(uint8_t *device_min_sens);

/**
* \brief Validates Device minimum sensitivity.
*
* Function validates device minimum sensitivity. Function can be used to test that values that will be used on set
* function are valid.
*
* \param device_min_sens Device minimum sensitivity. Range 0-254.
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_UNKNOWN in case of failure.
* */
mesh_error_t validate_device_min_sens(uint8_t device_min_sens);

/**
* \brief Set own certificate and private key reference to the Wi-SUN network.
*
Expand Down Expand Up @@ -495,6 +542,18 @@ class WisunInterface : public MeshInterfaceNanostack {
* */
mesh_error_t stack_info_get(ws_stack_state_t *stack_info_ptr);

/**
* \brief Get Wi-SUN CCA threshold table information.
*
* Function reads CCA threshold table from nanostack.
*
** \param ws_cca_threshold_table_t Structure given to stack where information will be stored
**
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_UNKNOWN in case of failure.
* */
mesh_error_t cca_threshold_table_get(ws_cca_threshold_table_t *table);

protected:
Nanostack::WisunInterface *get_interface() const;
virtual nsapi_error_t do_initialize();
Expand Down
50 changes: 50 additions & 0 deletions features/nanostack/mbed-mesh-api/source/WisunInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,37 @@ mesh_error_t WisunInterface::validate_timing_parameters(uint16_t disc_trickle_im
return MESH_ERROR_NONE;
}

mesh_error_t WisunInterface::set_device_min_sens(uint8_t device_min_sens)
{
int status = ws_device_min_sens_set(get_interface_id(), device_min_sens);
if (status != 0) {
return MESH_ERROR_UNKNOWN;
}

return MESH_ERROR_NONE;
}

mesh_error_t WisunInterface::get_device_min_sens(uint8_t *device_min_sens)
{
if (device_min_sens == NULL) {
return MESH_ERROR_PARAM;
}

/* To-Do :: Update this when device_min_sense get API is available */
*device_min_sens = 0;

return MESH_ERROR_NONE;
}

mesh_error_t WisunInterface::validate_device_min_sens(uint8_t device_min_sens)
{
if (device_min_sens == 0xFF) {
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)
{
mesh_error_t ret_val = MESH_ERROR_NONE;
Expand Down Expand Up @@ -627,13 +658,32 @@ mesh_error_t WisunInterface::stack_info_get(ws_stack_state_t *stack_info_ptr)
stack_info_ptr->pan_id = stack_info.pan_id;
stack_info_ptr->rsl_in = stack_info.rsl_in;
stack_info_ptr->rsl_out = stack_info.rsl_out;
stack_info_ptr->device_min_sens = stack_info.device_min_sens;
memcpy(stack_info_ptr->parent_addr, stack_info.parent, 16);
memcpy(stack_info_ptr->global_addr, global_address, 16);
memcpy(stack_info_ptr->link_local_addr, link_local_address, 16);

return MESH_ERROR_NONE;
}

mesh_error_t WisunInterface::cca_threshold_table_get(ws_cca_threshold_table_t *table)
{
if (table == NULL) {
return MESH_ERROR_PARAM;
}

const cca_threshold_table_s *cca_table = arm_nwk_get_cca_threshold_table(get_interface_id());

if (cca_table != NULL) {
table->number_of_channels = cca_table->number_of_channels;
table->cca_threshold_table = cca_table->cca_threshold_table;
} else {
return MESH_ERROR_UNKNOWN;
}

return MESH_ERROR_NONE;
}

#define WISUN 0x2345
#if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == WISUN && DEVICE_802_15_4_PHY
MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance()
Expand Down