Skip to content

Commit 397240a

Browse files
author
Jarkko Paso
committed
MAC: Implemented CCA threshold and TX power setting
1 parent 888a0fb commit 397240a

File tree

5 files changed

+75
-2
lines changed

5 files changed

+75
-2
lines changed

nanostack/mlme.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ typedef enum {
264264
macAutoRequestKeyIndex = 0x7b, /*<The index of the key used for automatic data*/
265265
macDefaultKeySource = 0x7c, /*<Default key source*/
266266
//NON standard extension
267+
macTXPower = 0xf8, /*<TX output power*/
268+
macCCAThreshold = 0xf9, /*<CCA threshold*/
267269
macMultiCSMAParameters = 0xfa, /*<Multi CSMA parameters*/
268270
macRfConfiguration = 0xfb, /*<RF channel configuration parameters*/
269271
macAcceptByPassUnknowDevice = 0xfc, /*< Accept data trough MAC if packet is data can be authenticated by group key nad MIC. Security enforsment point must be handled carefully these packets */

nanostack/net_interface.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,34 @@ extern void net_get_version_information(uint8_t *ptr);
10601060

10611061
extern int arm_nwk_sleepy_device_parent_buffer_size_set(int8_t interface_id, uint16_t big_packet_threshold, uint16_t small_packets_per_child_count, uint16_t big_packets_total_count);
10621062

1063+
/**
1064+
* \brief Set CCA threshold.
1065+
*
1066+
* This function can be used to set CCA threshold to PHY layer. Threshold is given as percentage of maximum threshold.
1067+
* 0 is the lowest(strictest) possible threshold and 100 is the highest possible threshold.
1068+
*
1069+
* Note! Software MAC must be created and registered before using this function.
1070+
*
1071+
* \param interface_id Network interface ID.
1072+
* \param cca_threshold CCA threshold (%).
1073+
* \return 0 on success, <0 on errors.
1074+
*/
1075+
extern int8_t arm_nwk_set_cca_threshold(int8_t interface_id, uint8_t cca_threshold);
1076+
1077+
/**
1078+
* \brief Set TX output power.
1079+
*
1080+
* This function can be used to set TX output power to PHY layer. TX power is given as percentage of maximum output power.
1081+
* 0 is the lowest possible TX power and 100 is the highest possible TX power.
1082+
*
1083+
* Note! Software MAC must be created and registered before using this function.
1084+
*
1085+
* \param interface_id Network interface ID.
1086+
* \param tx_power TX output power (%).
1087+
* \return 0 on success, <0 on errors.
1088+
*/
1089+
extern int8_t arm_nwk_set_tx_output_power(int8_t interface_id, uint8_t tx_power);
1090+
10631091

10641092
#ifdef __cplusplus
10651093
}

nanostack/platform/arm_hal_phy.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ typedef enum {
7777
PHY_EXTENSION_SET_CSMA_PARAMETERS, /**< CSMA parameter's are given by phy_csma_params_t structure remember type cast uint8_t pointer to structure type*/
7878
PHY_EXTENSION_GET_SYMBOLS_PER_SECOND, /**< Read Symbols per seconds which will help to convert symbol time to real time */
7979
PHY_EXTENSION_SET_RF_CONFIGURATION, /**< Set RF configuration using phy_rf_channel_parameters_s structure */
80-
PHY_EXTENSION_FILTERING_SUPPORT /**< Return filtering modes that can be supported by the PHY driver. See phy_link_filters_e */
80+
PHY_EXTENSION_FILTERING_SUPPORT, /**< Return filtering modes that can be supported by the PHY driver. See phy_link_filters_e */
81+
PHY_EXTENSION_SET_TX_POWER, /**< Set TX output power which is given as percentage of maximum. 0 is the lowest possible TX power and 100 is the highest possible TX power */
82+
PHY_EXTENSION_SET_CCA_THRESHOLD /**< Set CCA threshold which is given as percentage of maximum threshold. 0 is the lowest(strictest) possible threshold and 100 is the highest possible threshold */
8183
} phy_extension_type_e;
8284

8385
/** Address types */

source/MAC/IEEE802_15_4/mac_mlme.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ int8_t mac_mlme_set_req(protocol_interface_rf_mac_setup_s *rf_mac_setup, const m
738738
if (!set_req || !rf_mac_setup || !rf_mac_setup->dev_driver || !rf_mac_setup->dev_driver->phy_driver) {
739739
return -1;
740740
}
741-
741+
uint8_t *pu8 = NULL;
742742
switch (set_req->attr) {
743743
case macAckWaitDuration:
744744
return mac_mlme_set_ack_wait_duration(rf_mac_setup, set_req);
@@ -758,6 +758,16 @@ int8_t mac_mlme_set_req(protocol_interface_rf_mac_setup_s *rf_mac_setup, const m
758758
memcpy(rf_mac_setup->coord_long_address, set_req->value_pointer, 8);
759759
}
760760
return 0;
761+
case macTXPower:
762+
pu8 = (uint8_t *) set_req->value_pointer;
763+
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_SET_TX_POWER, pu8);
764+
tr_debug("Set TX output power to %u%%", *pu8);
765+
return 0;
766+
case macCCAThreshold:
767+
pu8 = (uint8_t *) set_req->value_pointer;
768+
rf_mac_setup->dev_driver->phy_driver->extension(PHY_EXTENSION_SET_CCA_THRESHOLD, pu8);
769+
tr_debug("Set CCA threshold to %u%%", *pu8);
770+
return 0;
761771
case macMultiCSMAParameters:
762772
return mac_mlme_set_multi_csma_parameters(rf_mac_setup, set_req);
763773
case macRfConfiguration:

source/libNET/src/ns_net.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,3 +1481,34 @@ int arm_nwk_sleepy_device_parent_buffer_size_set(int8_t interface_id, uint16_t b
14811481
return -1;
14821482
}
14831483

1484+
int8_t arm_nwk_set_cca_threshold(int8_t interface_id, uint8_t cca_threshold)
1485+
{
1486+
protocol_interface_info_entry_t *cur;
1487+
cur = protocol_stack_interface_info_get_by_id(interface_id);
1488+
if (!cur || !cur->mac_api || (cca_threshold > 100)) {
1489+
return -1;
1490+
}
1491+
mlme_set_t set_req;
1492+
set_req.attr = macCCAThreshold;
1493+
set_req.attr_index = 0;
1494+
set_req.value_pointer = &cca_threshold;
1495+
set_req.value_size = sizeof(cca_threshold);
1496+
cur->mac_api->mlme_req(cur->mac_api, MLME_SET, &set_req);
1497+
return 0;
1498+
}
1499+
1500+
int8_t arm_nwk_set_tx_output_power(int8_t interface_id, uint8_t tx_power)
1501+
{
1502+
protocol_interface_info_entry_t *cur;
1503+
cur = protocol_stack_interface_info_get_by_id(interface_id);
1504+
if (!cur || !cur->mac_api || (tx_power > 100)) {
1505+
return -1;
1506+
}
1507+
mlme_set_t set_req;
1508+
set_req.attr = macTXPower;
1509+
set_req.attr_index = 0;
1510+
set_req.value_pointer = &tx_power;
1511+
set_req.value_size = sizeof(tx_power);
1512+
cur->mac_api->mlme_req(cur->mac_api, MLME_SET, &set_req);
1513+
return 0;
1514+
}

0 commit comments

Comments
 (0)