Skip to content

Commit d8e7d40

Browse files
author
Jarkko Paso
authored
Iotthd 4239 (ARMmbed#2414)
* Api to read CCA threshold table * Use existing cca threshold attribute when requesting threshold table * Some documentation to CCA threshold read API
1 parent b46f3c6 commit d8e7d40

File tree

11 files changed

+103
-7
lines changed

11 files changed

+103
-7
lines changed

nanostack/net_interface.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ typedef struct {
286286
uint8_t *beacon_payload_tlv_ptr; /**< Optional steering parameters. */
287287
} network_driver_setup_s;
288288

289+
/** CCA threshold table */
290+
typedef struct {
291+
uint8_t number_of_channels; /**< Number of channels */
292+
const int8_t *cca_threshold_table; /**< CCA threshold table */
293+
} cca_threshold_table_s;
294+
289295
/**
290296
* Init 6LoWPAN library
291297
*
@@ -1135,6 +1141,20 @@ extern int8_t arm_nwk_set_cca_threshold(int8_t interface_id, uint8_t cca_thresho
11351141
*/
11361142
extern int8_t arm_nwk_set_tx_output_power(int8_t interface_id, uint8_t tx_power);
11371143

1144+
/**
1145+
* \brief Get CCA threshold table.
1146+
*
1147+
* This function can be used to read CCA threshold table.
1148+
* CCA threshold table structure contains number of channels and an array indicating the currently used CCA threshold value of each channel. CCA threshold values are updated by library continuously.
1149+
* If channels are reconfigured, number of channels and table length are changed automatically. User should check the table length (number of channels) before reading the table.
1150+
* Automatic CCA threshold feature may not be enabled before interface is up, causing function to return NULL.
1151+
* Returned pointer to cca_threshold_table_s structure is valid until interface is destroyed. Re-reading the pointer with this function is allowed any time.
1152+
*
1153+
* \param interface_id Network interface ID.
1154+
* \return NULL if automatic CCA threshold feature is not enabled, otherwise pointer to CCA threshold structure.
1155+
*/
1156+
extern const cca_threshold_table_s *arm_nwk_get_cca_threshold_table(int8_t interface_id);
1157+
11381158

11391159
#ifdef __cplusplus
11401160
}

source/6LoWPAN/MAC/mac_helper.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,3 +995,23 @@ int8_t mac_helper_mac_device_description_pan_id_update(int8_t interface_id, uint
995995
cur->mac_api->mlme_req(cur->mac_api, MLME_SET, &set_req);
996996
return 0;
997997
}
998+
999+
int8_t mac_helper_start_auto_cca_threshold(int8_t interface_id, uint8_t number_of_channels, int8_t default_dbm, int8_t high_limit, int8_t low_limit)
1000+
{
1001+
protocol_interface_info_entry_t *cur;
1002+
cur = protocol_stack_interface_info_get_by_id(interface_id);
1003+
if (!cur || !cur->mac_api) {
1004+
return -1;
1005+
}
1006+
uint8_t start_cca_thr[4] = {number_of_channels, default_dbm, high_limit, low_limit};
1007+
mlme_set_t set_req;
1008+
set_req.attr = macCCAThresholdStart;
1009+
set_req.value_pointer = &start_cca_thr;
1010+
set_req.value_size = sizeof(start_cca_thr);
1011+
cur->mac_api->mlme_req(cur->mac_api, MLME_SET, &set_req);
1012+
/* Get CCA threshold table. Table is stored to interface structure */
1013+
mlme_get_t get_req;
1014+
get_req.attr = macCCAThreshold;
1015+
cur->mac_api->mlme_req(cur->mac_api, MLME_GET, &get_req);
1016+
return 0;
1017+
}

source/6LoWPAN/MAC/mac_helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,6 @@ int8_t mac_helper_mac_mlme_max_retry_set(int8_t interface_id, uint8_t mac_retry_
134134

135135
int8_t mac_helper_mac_device_description_pan_id_update(int8_t interface_id, uint16_t pan_id);
136136

137+
int8_t mac_helper_start_auto_cca_threshold(int8_t interface_id, uint8_t number_of_channels, int8_t default_dbm, int8_t high_limit, int8_t low_limit);
138+
137139
#endif // MAC_HELPER_H

source/6LoWPAN/MAC/mac_response_handler.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ static void mac_mlme_frame_counter_confirmation_handle(protocol_interface_info_e
8181
info_entry->mac_parameters->security_frame_counter = *temp_ptr;
8282
}
8383

84+
static void mac_mlme_cca_threshold_confirmation_handle(protocol_interface_info_entry_t *info_entry, mlme_get_conf_t *confirmation)
85+
{
86+
if (confirmation->value_size < 1) {
87+
return;
88+
}
89+
info_entry->mac_parameters->cca_thr_table.number_of_channels = confirmation->value_size;
90+
info_entry->mac_parameters->cca_thr_table.cca_threshold_table = (int8_t *)confirmation->value_pointer;
91+
}
92+
8493
static void mac_mlme_get_confirmation_handler(protocol_interface_info_entry_t *info_entry, mlme_get_conf_t *confirmation)
8594
{
8695

@@ -96,6 +105,10 @@ static void mac_mlme_get_confirmation_handler(protocol_interface_info_entry_t *i
96105
mac_mlme_frame_counter_confirmation_handle(info_entry, confirmation);
97106
break;
98107

108+
case macCCAThreshold:
109+
mac_mlme_cca_threshold_confirmation_handle(info_entry, confirmation);
110+
break;
111+
99112
default:
100113

101114
break;

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,11 +2135,7 @@ int ws_bootstrap_set_rf_config(protocol_interface_info_entry_t *cur, phy_rf_chan
21352135
set_request.value_size = sizeof(mlme_multi_csma_ca_param_t);
21362136
cur->mac_api->mlme_req(cur->mac_api, MLME_SET, &set_request);
21372137
// Start automatic CCA threshold
2138-
uint8_t start_cca_thr[4] = {cur->ws_info->hopping_schdule.number_of_channels, CCA_DEFAULT_DBM, CCA_HIGH_LIMIT, CCA_LOW_LIMIT};
2139-
set_request.attr = macCCAThresholdStart;
2140-
set_request.value_pointer = &start_cca_thr;
2141-
set_request.value_size = sizeof(start_cca_thr);
2142-
cur->mac_api->mlme_req(cur->mac_api, MLME_SET, &set_request);
2138+
mac_helper_start_auto_cca_threshold(cur->id, cur->ws_info->hopping_schdule.number_of_channels, CCA_DEFAULT_DBM, CCA_HIGH_LIMIT, CCA_LOW_LIMIT);
21432139
return 0;
21442140
}
21452141

source/MAC/IEEE802_15_4/mac_cca_threshold.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,11 @@ int8_t mac_cca_threshold_update(protocol_interface_rf_mac_setup_s *rf_ptr, uint8
140140
tr_debug("Channel %u CCA threshold to %i", channel, rf_ptr->cca_threshold->ch_thresholds[channel]);
141141
return 0;
142142
}
143+
144+
mac_cca_threshold_s *mac_get_cca_threshold_table(protocol_interface_rf_mac_setup_s *rf_ptr)
145+
{
146+
if (!rf_ptr->cca_threshold) {
147+
return NULL;
148+
}
149+
return rf_ptr->cca_threshold;
150+
}

source/MAC/IEEE802_15_4/mac_cca_threshold.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,26 @@ int8_t mac_cca_thr_deinit(protocol_interface_rf_mac_setup_s *rf_ptr);
4949

5050
/**
5151
* @brief Read CCA threshold of specific channel.
52+
* @param rf_ptr Pointer to MAC instance.
5253
* @param channel Channel.
5354
* @return CCA threshold (dBm), CCA_FAILED_DBM Feature not enabled.
5455
*/
5556
int8_t mac_cca_thr_get_dbm(protocol_interface_rf_mac_setup_s *rf_ptr, uint8_t channel);
5657

5758
/**
5859
* @brief Update CCA threshold of specific channel.
60+
* @param rf_ptr Pointer to MAC instance.
5961
* @param channel Channel.
6062
* @param dbm CCA threshold (dBm).
6163
* @return 0 Updated, negative Already using this value.
6264
*/
6365
int8_t mac_cca_threshold_update(protocol_interface_rf_mac_setup_s *rf_ptr, uint8_t channel, int8_t dbm);
6466

67+
/**
68+
* @brief Get pointer to CCA threshold table.
69+
* @param rf_ptr Pointer to MAC instance.
70+
* @return CCA threshold table.
71+
*/
72+
mac_cca_threshold_s *mac_get_cca_threshold_table(protocol_interface_rf_mac_setup_s *rf_ptr);
73+
6574
#endif /* MAC_CCA_THRESHOLD_H_ */

source/MAC/IEEE802_15_4/mac_mlme.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ int8_t mac_mlme_get_req(struct protocol_interface_rf_mac_setup *rf_mac_setup, ml
878878
if (!get_req || !rf_mac_setup) {
879879
return -1;
880880
}
881-
881+
mac_cca_threshold_s *cca_thr_table = NULL;
882882
switch (get_req->attr) {
883883
case macDeviceTable:
884884
get_req->value_pointer = mac_sec_mib_device_description_get_attribute_index(rf_mac_setup, get_req->attr_index);
@@ -908,6 +908,12 @@ int8_t mac_mlme_get_req(struct protocol_interface_rf_mac_setup *rf_mac_setup, ml
908908
get_req->value_size = 4;
909909
break;
910910

911+
case macCCAThreshold:
912+
cca_thr_table = mac_get_cca_threshold_table(rf_mac_setup);
913+
get_req->value_size = cca_thr_table->number_of_channels;
914+
get_req->value_pointer = cca_thr_table->ch_thresholds;
915+
break;
916+
911917
default:
912918
get_req->status = MLME_UNSUPPORTED_ATTRIBUTE;
913919
break;

source/NWK_INTERFACE/Include/protocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ typedef struct arm_15_4_mac_parameters_t {
238238
uint16_t pan_id;
239239
uint16_t mac_short_address;
240240
mac_cordinator_s mac_cordinator_info;
241+
cca_threshold_table_s cca_thr_table;
241242
uint8_t number_of_fhss_channel_retries;
242243
/* MAC Beacon info */
243244
uint8_t *mac_beacon_payload;

source/libNET/src/ns_net.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,3 +1570,18 @@ int8_t arm_nwk_set_tx_output_power(int8_t interface_id, uint8_t tx_power)
15701570
cur->mac_api->mlme_req(cur->mac_api, MLME_SET, &set_req);
15711571
return 0;
15721572
}
1573+
1574+
const cca_threshold_table_s *arm_nwk_get_cca_threshold_table(int8_t interface_id)
1575+
{
1576+
protocol_interface_info_entry_t *cur;
1577+
cur = protocol_stack_interface_info_get_by_id(interface_id);
1578+
// Interface or MAC parameters not initialized
1579+
if (!cur || !cur->mac_parameters) {
1580+
return NULL;
1581+
}
1582+
// Automatic CCA threshold not initialized
1583+
if (!cur->mac_parameters->cca_thr_table.cca_threshold_table || !cur->mac_parameters->cca_thr_table.number_of_channels) {
1584+
return NULL;
1585+
}
1586+
return &cur->mac_parameters->cca_thr_table;
1587+
}

test/nanostack/unittest/stub/mac_cca_threshold_stub.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
#include "ns_list.h"
2222
#include "ns_trace.h"
2323
#include "mac_defines.h"
24+
#include "mac_cca_threshold.h"
2425

25-
int8_t mac_cca_threshold_update(protocol_interface_rf_mac_setup_s *rf_ptr, uint16_t event_data)
26+
int8_t mac_cca_threshold_update(protocol_interface_rf_mac_setup_s *rf_ptr, uint8_t channel, int8_t dbm)
2627
{
2728
return 0;
2829
}
@@ -41,3 +42,8 @@ int8_t mac_cca_thr_get_dbm(protocol_interface_rf_mac_setup_s *rf_ptr, uint8_t ch
4142
{
4243
return 0;
4344
}
45+
46+
mac_cca_threshold_s *mac_get_cca_threshold_table(protocol_interface_rf_mac_setup_s *rf_ptr)
47+
{
48+
return NULL;
49+
}

0 commit comments

Comments
 (0)