Skip to content

Commit bdb6bd5

Browse files
authored
Merge pull request #13757 from artokin/add-min-sens-wisun-param-master
wisun: Add APIs for Device min sense and CCA threshold table.
2 parents b7551c2 + 986f9dd commit bdb6bd5

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,20 @@ typedef struct ws_stack_state {
5353
uint8_t join_state;
5454
/** Network PAN ID */
5555
uint16_t pan_id;
56+
/** Device RF minimum sensitivity configuration. lowest level of radio signal strength packet heard. Range of -174 (0) to +80 (254) dBm*/
57+
uint8_t device_min_sens;
5658
} ws_stack_state_t;
5759

60+
/**
61+
* \brief Struct ws_cca_threshold_table Wi-SUN CCA threshold table information.
62+
*/
63+
typedef struct ws_cca_threshold_table {
64+
/** Number of channels */
65+
uint8_t number_of_channels;
66+
/** CCA threshold table */
67+
const int8_t *cca_threshold_table;
68+
} ws_cca_threshold_table_t;
69+
5870
/** Wi-SUN mesh network interface class
5971
*
6072
* Configure Nanostack to use Wi-SUN protocol.
@@ -364,6 +376,41 @@ class WisunInterface final : public MeshInterfaceNanostack {
364376
* */
365377
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);
366378

379+
/**
380+
* \brief Set Wi-SUN device minimum sensitivity
381+
*
382+
* Function stores new parameters to mbed-mesh-api and uses them when connect() is called next time.
383+
* If device is already connected to the Wi-SUN network then settings take effect right away.
384+
*
385+
* \param device_min_sens Device minimum sensitivity. Range 0(-174 dB) to 254(+80 dB).
386+
* \return MESH_ERROR_NONE on success.
387+
* \return MESH_ERROR_UNKNOWN in case of failure.
388+
* */
389+
mesh_error_t set_device_min_sens(uint8_t device_min_sens);
390+
391+
/**
392+
* \brief Get Wi-SUN device minimum sensitivity.
393+
*
394+
* Function reads device minimum sensitivity from mbed-mesh-api.
395+
*
396+
* \param device_min_sens Device minimum sensitivity. Range 0-254.
397+
* \return MESH_ERROR_NONE on success.
398+
* \return MESH_ERROR_UNKNOWN in case of failure.
399+
* */
400+
mesh_error_t get_device_min_sens(uint8_t *device_min_sens);
401+
402+
/**
403+
* \brief Validates Device minimum sensitivity.
404+
*
405+
* Function validates device minimum sensitivity. Function can be used to test that values that will be used on set
406+
* function are valid.
407+
*
408+
* \param device_min_sens Device minimum sensitivity. Range 0-254.
409+
* \return MESH_ERROR_NONE on success.
410+
* \return MESH_ERROR_UNKNOWN in case of failure.
411+
* */
412+
mesh_error_t validate_device_min_sens(uint8_t device_min_sens);
413+
367414
/**
368415
* \brief Set own certificate and private key reference to the Wi-SUN network.
369416
*
@@ -486,6 +533,18 @@ class WisunInterface final : public MeshInterfaceNanostack {
486533
* */
487534
mesh_error_t stack_info_get(ws_stack_state_t *stack_info_ptr);
488535

536+
/**
537+
* \brief Get Wi-SUN CCA threshold table information.
538+
*
539+
* Function reads CCA threshold table from nanostack.
540+
*
541+
** \param ws_cca_threshold_table_t Structure given to stack where information will be stored
542+
**
543+
* \return MESH_ERROR_NONE on success.
544+
* \return MESH_ERROR_UNKNOWN in case of failure.
545+
* */
546+
mesh_error_t cca_threshold_table_get(ws_cca_threshold_table_t *table);
547+
489548
protected:
490549
Nanostack::WisunInterface *get_interface() const;
491550
nsapi_error_t do_initialize() override;

connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,37 @@ mesh_error_t WisunInterface::validate_timing_parameters(uint16_t disc_trickle_im
472472
return MESH_ERROR_NONE;
473473
}
474474

475+
mesh_error_t WisunInterface::set_device_min_sens(uint8_t device_min_sens)
476+
{
477+
int status = ws_device_min_sens_set(get_interface_id(), device_min_sens);
478+
if (status != 0) {
479+
return MESH_ERROR_UNKNOWN;
480+
}
481+
482+
return MESH_ERROR_NONE;
483+
}
484+
485+
mesh_error_t WisunInterface::get_device_min_sens(uint8_t *device_min_sens)
486+
{
487+
if (device_min_sens == NULL) {
488+
return MESH_ERROR_PARAM;
489+
}
490+
491+
/* To-Do :: Update this when device_min_sense get API is available */
492+
*device_min_sens = 0;
493+
494+
return MESH_ERROR_NONE;
495+
}
496+
497+
mesh_error_t WisunInterface::validate_device_min_sens(uint8_t device_min_sens)
498+
{
499+
if (device_min_sens == 0xFF) {
500+
return MESH_ERROR_UNKNOWN;
501+
}
502+
503+
return MESH_ERROR_NONE;
504+
}
505+
475506
mesh_error_t WisunInterface::set_own_certificate(uint8_t *cert, uint16_t cert_len, uint8_t *cert_key, uint16_t cert_key_len)
476507
{
477508
mesh_error_t ret_val = MESH_ERROR_NONE;
@@ -629,13 +660,32 @@ mesh_error_t WisunInterface::stack_info_get(ws_stack_state_t *stack_info_ptr)
629660
stack_info_ptr->pan_id = stack_info.pan_id;
630661
stack_info_ptr->rsl_in = stack_info.rsl_in;
631662
stack_info_ptr->rsl_out = stack_info.rsl_out;
663+
stack_info_ptr->device_min_sens = stack_info.device_min_sens;
632664
memcpy(stack_info_ptr->parent_addr, stack_info.parent, 16);
633665
memcpy(stack_info_ptr->global_addr, global_address, 16);
634666
memcpy(stack_info_ptr->link_local_addr, link_local_address, 16);
635667

636668
return MESH_ERROR_NONE;
637669
}
638670

671+
mesh_error_t WisunInterface::cca_threshold_table_get(ws_cca_threshold_table_t *table)
672+
{
673+
if (table == NULL) {
674+
return MESH_ERROR_PARAM;
675+
}
676+
677+
const cca_threshold_table_s *cca_table = arm_nwk_get_cca_threshold_table(get_interface_id());
678+
679+
if (cca_table != NULL) {
680+
table->number_of_channels = cca_table->number_of_channels;
681+
table->cca_threshold_table = cca_table->cca_threshold_table;
682+
} else {
683+
return MESH_ERROR_UNKNOWN;
684+
}
685+
686+
return MESH_ERROR_NONE;
687+
}
688+
639689
#define WISUN 0x2345
640690
#if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == WISUN && DEVICE_802_15_4_PHY
641691
MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance()

0 commit comments

Comments
 (0)