From 6c84032a330ec308cff44431cc701d2e149d4188 Mon Sep 17 00:00:00 2001 From: Debdeep Saha Date: Tue, 1 Sep 2020 20:05:00 +0530 Subject: [PATCH 1/2] Added APIs for Device min sense and CCA threshold table. -Added get, set and validate API for device min sens. -Added get API for CCA threshold table. --- .../mbed-mesh-api/WisunInterface.h | 57 +++++++++++++++++++ .../mbed-mesh-api/source/WisunInterface.cpp | 44 ++++++++++++++ 2 files changed, 101 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 19e808b85c2..5806b6d1577 100644 --- a/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h +++ b/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h @@ -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. @@ -364,6 +376,41 @@ class WisunInterface final : 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. * @@ -486,6 +533,16 @@ class WisunInterface final : 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. + * + * \return pointer to ws_cca_threshold_table_t structure on success. + * \return NULL in case of failure. + * */ + const ws_cca_threshold_table_t *cca_threshold_table_get(void); + protected: Nanostack::WisunInterface *get_interface() const; nsapi_error_t do_initialize() override; diff --git a/connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp b/connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp index ed6e72a1795..6a54f29e9a5 100644 --- a/connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp +++ b/connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp @@ -472,6 +472,42 @@ 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; + } + + ws_stack_info_t stack_info = {0}; + + if (ws_stack_info_get(get_interface_id(), &stack_info)) { + return MESH_ERROR_UNKNOWN; + } + + *device_min_sens = stack_info.device_min_sens; + + 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; @@ -629,6 +665,7 @@ 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); @@ -636,6 +673,13 @@ mesh_error_t WisunInterface::stack_info_get(ws_stack_state_t *stack_info_ptr) return MESH_ERROR_NONE; } +const ws_cca_threshold_table_t *WisunInterface::cca_threshold_table_get(void) +{ + const cca_threshold_table_s *cca_threshold_table = arm_nwk_get_cca_threshold_table(get_interface_id()); + + return (const ws_cca_threshold_table_t *)cca_threshold_table; +} + #define WISUN 0x2345 #if MBED_CONF_NSAPI_DEFAULT_MESH_TYPE == WISUN && DEVICE_802_15_4_PHY MBED_WEAK MeshInterface *MeshInterface::get_target_default_instance() From 986f9dd9463d768f41ed65682c6bec20741f3b14 Mon Sep 17 00:00:00 2001 From: Debdeep Saha Date: Thu, 3 Sep 2020 21:24:26 +0530 Subject: [PATCH 2/2] Resolved comments. --- .../mbed-mesh-api/WisunInterface.h | 8 +++--- .../mbed-mesh-api/source/WisunInterface.cpp | 26 ++++++++++++------- 2 files changed, 21 insertions(+), 13 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 5806b6d1577..23272faef55 100644 --- a/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h +++ b/connectivity/nanostack/mbed-mesh-api/mbed-mesh-api/WisunInterface.h @@ -538,10 +538,12 @@ class WisunInterface final : public MeshInterfaceNanostack { * * Function reads CCA threshold table from nanostack. * - * \return pointer to ws_cca_threshold_table_t structure on success. - * \return NULL in case of failure. + ** \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. * */ - const ws_cca_threshold_table_t *cca_threshold_table_get(void); + mesh_error_t cca_threshold_table_get(ws_cca_threshold_table_t *table); protected: Nanostack::WisunInterface *get_interface() const; diff --git a/connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp b/connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp index 6a54f29e9a5..896a6f7c7a0 100644 --- a/connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp +++ b/connectivity/nanostack/mbed-mesh-api/source/WisunInterface.cpp @@ -488,13 +488,8 @@ mesh_error_t WisunInterface::get_device_min_sens(uint8_t *device_min_sens) return MESH_ERROR_PARAM; } - ws_stack_info_t stack_info = {0}; - - if (ws_stack_info_get(get_interface_id(), &stack_info)) { - return MESH_ERROR_UNKNOWN; - } - - *device_min_sens = stack_info.device_min_sens; + /* To-Do :: Update this when device_min_sense get API is available */ + *device_min_sens = 0; return MESH_ERROR_NONE; } @@ -673,11 +668,22 @@ mesh_error_t WisunInterface::stack_info_get(ws_stack_state_t *stack_info_ptr) return MESH_ERROR_NONE; } -const ws_cca_threshold_table_t *WisunInterface::cca_threshold_table_get(void) +mesh_error_t WisunInterface::cca_threshold_table_get(ws_cca_threshold_table_t *table) { - const cca_threshold_table_s *cca_threshold_table = arm_nwk_get_cca_threshold_table(get_interface_id()); + if (table == NULL) { + return MESH_ERROR_PARAM; + } + + const cca_threshold_table_s *cca_table = arm_nwk_get_cca_threshold_table(get_interface_id()); - return (const ws_cca_threshold_table_t *)cca_threshold_table; + 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