1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #15468 from jia200x/pr/rh/rev.13.11

ieee802154/hal: adapt frame filter and source address matching changes
This commit is contained in:
Martine Lenders 2021-06-17 16:18:57 +02:00 committed by GitHub
commit 7cad799afe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 357 additions and 222 deletions

View File

@ -107,7 +107,10 @@ extern "C" {
#define CC2538_RSSI_OFFSET (-73) /**< Signal strength offset value */
#define CC2538_RF_SENSITIVITY (-97) /**< dBm typical, normal conditions */
#define CC2538_ACCEPT_FT_0_BEACON (1 << 3) /**< enable or disable the BEACON filter */
#define CC2538_ACCEPT_FT_1_DATA (1 << 4) /**< enable or disable the DATA filter */
#define CC2538_ACCEPT_FT_2_ACK (1 << 5) /**< enable or disable the ACK filter */
#define CC2538_ACCEPT_FT_3_CMD (1 << 6) /**< enable or disable the CMD filter */
#define CC2538_STATE_SFD_WAIT_RANGE_MIN (0x03U) /**< min range value of SFD wait state */
#define CC2538_STATE_SFD_WAIT_RANGE_MAX (0x06U) /**< max range value of SFD wait state */
#define CC2538_FRMCTRL1_PENDING_OR_MASK (0x04) /**< mask for enabling or disabling the

View File

@ -174,6 +174,9 @@ void cc2538_init(void)
/* setup mac timer */
_cc2538_setup_mac_timer();
/* Enable Auto ACK */
RFCORE->XREG_FRMCTRL0bits.AUTOACK = !IS_ACTIVE(CONFIG_IEEE802154_AUTO_ACK_DISABLE);
/* Flush the receive and transmit FIFOs */
RFCORE_SFR_RFST = ISFLUSHTX;
RFCORE_SFR_RFST = ISFLUSHRX;

View File

@ -352,7 +352,7 @@ void cc2538_irq_handler(void)
/* Disable RX while the frame has not been processed */
RFCORE_XREG_RXMASKCLR = 0xFF;
/* If AUTOACK is enabled and the ACK request bit is set */
if (RFCORE->XREG_FRMCTRL0bits.AUTOACK &&
if (!IS_ACTIVE(CONFIG_IEEE802154_AUTO_ACK_DISABLE) &&
(rfcore_peek_rx_fifo(1) & IEEE802154_FCF_ACK_REQ)) {
/* The next SFD will be the ACK's, ignore it */
cc2538_sfd_listen = false;
@ -400,31 +400,51 @@ static int _off(ieee802154_dev_t *dev)
return -ENOTSUP;
}
static int _set_hw_addr_filter(ieee802154_dev_t *dev, const network_uint16_t *short_addr,
const eui64_t *ext_addr, const uint16_t *pan_id)
static int _config_addr_filter(ieee802154_dev_t *dev, ieee802154_af_cmd_t cmd, const void *value)
{
(void) dev;
if (short_addr) {
RFCORE_FFSM_SHORT_ADDR0 = short_addr->u8[1];
RFCORE_FFSM_SHORT_ADDR1 = short_addr->u8[0];
const network_uint16_t *short_addr = value;
const eui64_t *ext_addr = value;
const uint16_t *pan_id = value;
switch(cmd) {
case IEEE802154_AF_SHORT_ADDR:
RFCORE_FFSM_SHORT_ADDR0 = short_addr->u8[1];
RFCORE_FFSM_SHORT_ADDR1 = short_addr->u8[0];
break;
case IEEE802154_AF_EXT_ADDR:
RFCORE_FFSM_EXT_ADDR0 = ext_addr->uint8[7];
RFCORE_FFSM_EXT_ADDR1 = ext_addr->uint8[6];
RFCORE_FFSM_EXT_ADDR2 = ext_addr->uint8[5];
RFCORE_FFSM_EXT_ADDR3 = ext_addr->uint8[4];
RFCORE_FFSM_EXT_ADDR4 = ext_addr->uint8[3];
RFCORE_FFSM_EXT_ADDR5 = ext_addr->uint8[2];
RFCORE_FFSM_EXT_ADDR6 = ext_addr->uint8[1];
RFCORE_FFSM_EXT_ADDR7 = ext_addr->uint8[0];
break;
case IEEE802154_AF_PANID:
RFCORE_FFSM_PAN_ID0 = *pan_id;
RFCORE_FFSM_PAN_ID1 = (*pan_id) >> 8;
break;
case IEEE802154_AF_PAN_COORD:
return -ENOTSUP;
}
if (ext_addr) {
RFCORE_FFSM_EXT_ADDR0 = ext_addr->uint8[7];
RFCORE_FFSM_EXT_ADDR1 = ext_addr->uint8[6];
RFCORE_FFSM_EXT_ADDR2 = ext_addr->uint8[5];
RFCORE_FFSM_EXT_ADDR3 = ext_addr->uint8[4];
RFCORE_FFSM_EXT_ADDR4 = ext_addr->uint8[3];
RFCORE_FFSM_EXT_ADDR5 = ext_addr->uint8[2];
RFCORE_FFSM_EXT_ADDR6 = ext_addr->uint8[1];
RFCORE_FFSM_EXT_ADDR7 = ext_addr->uint8[0];
}
return 0;
}
if (pan_id) {
RFCORE_FFSM_PAN_ID0 = *pan_id;
RFCORE_FFSM_PAN_ID1 = (*pan_id) >> 8;
static int _config_src_addr_match(ieee802154_dev_t *dev, ieee802154_src_match_t cmd, const void *value)
{
(void) dev;
switch(cmd) {
case IEEE802154_SRC_MATCH_EN:
RFCORE_XREG_FRMCTRL1 &= ~CC2538_FRMCTRL1_PENDING_OR_MASK;
if (*((const bool*) value) == true) {
RFCORE_XREG_FRMCTRL1 |= CC2538_FRMCTRL1_PENDING_OR_MASK;
}
break;
default:
return -ENOTSUP;
}
return 0;
}
@ -468,43 +488,6 @@ static int _set_cca_mode(ieee802154_dev_t *dev, ieee802154_cca_mode_t mode)
return 0;
}
static int _set_rx_mode(ieee802154_dev_t *dev, ieee802154_rx_mode_t mode)
{
(void) dev;
bool promisc = false;
bool ack_filter = true;
switch (mode) {
case IEEE802154_RX_AACK_DISABLED:
RFCORE->XREG_FRMCTRL0bits.AUTOACK = 0;
break;
case IEEE802154_RX_AACK_ENABLED:
RFCORE->XREG_FRMCTRL0bits.AUTOACK = 1;
RFCORE_XREG_FRMCTRL1 &= ~CC2538_FRMCTRL1_PENDING_OR_MASK;
break;
case IEEE802154_RX_AACK_FRAME_PENDING:
RFCORE->XREG_FRMCTRL0bits.AUTOACK = 1;
RFCORE_XREG_FRMCTRL1 |= CC2538_FRMCTRL1_PENDING_OR_MASK;
break;
case IEEE802154_RX_PROMISC:
promisc = true;
break;
case IEEE802154_RX_WAIT_FOR_ACK:
ack_filter = false;
break;
}
if (ack_filter) {
RFCORE_XREG_FRMFILT1 &= ~CC2538_ACCEPT_FT_2_ACK;
}
else {
RFCORE_XREG_FRMFILT1 |= CC2538_ACCEPT_FT_2_ACK;
}
cc2538_set_monitor(promisc);
return 0;
}
static int _set_csma_params(ieee802154_dev_t *dev, const ieee802154_csma_be_t *bd, int8_t retries)
{
(void) dev;
@ -518,6 +501,34 @@ static int _set_csma_params(ieee802154_dev_t *dev, const ieee802154_csma_be_t *b
return 0;
}
static int _set_frame_filter_mode(ieee802154_dev_t *dev, ieee802154_filter_mode_t mode)
{
(void) dev;
uint8_t flags = 0;
bool promisc = false;
switch (mode) {
case IEEE802154_FILTER_ACCEPT:
flags = CC2538_ACCEPT_FT_0_BEACON
| CC2538_ACCEPT_FT_1_DATA
| CC2538_ACCEPT_FT_3_CMD;
break;
case IEEE802154_FILTER_PROMISC:
promisc = true;
break;
case IEEE802154_FILTER_ACK_ONLY:
flags = CC2538_ACCEPT_FT_2_ACK;
break;
default:
return -ENOTSUP;
}
RFCORE_XREG_FRMFILT1 |= flags;
cc2538_set_monitor(promisc);
return 0;
}
static const ieee802154_radio_ops_t cc2538_rf_ops = {
.caps = IEEE802154_CAP_24_GHZ
| IEEE802154_CAP_AUTO_CSMA
@ -543,7 +554,8 @@ static const ieee802154_radio_ops_t cc2538_rf_ops = {
.set_cca_threshold = _set_cca_threshold,
.set_cca_mode = _set_cca_mode,
.config_phy = _config_phy,
.set_hw_addr_filter = _set_hw_addr_filter,
.config_addr_filter = _config_addr_filter,
.config_src_addr_match = _config_src_addr_match,
.set_csma_params = _set_csma_params,
.set_rx_mode = _set_rx_mode,
.set_frame_filter_mode = _set_frame_filter_mode,
};

View File

@ -91,6 +91,7 @@ static struct {
bool cca_send : 1; /**< whether the next transmission uses CCA or not */
bool ack_filter : 1; /**< whether the ACK filter is activated or not */
bool promisc : 1; /**< whether the device is in promiscuous mode or not */
bool pending : 1; /**< whether there pending bit should be set in the ACK frame or not */
} cfg = {
.cca_send = true,
.ack_filter = true,
@ -431,6 +432,11 @@ static void _timer_cb(void *arg, int chan)
if (chan == MAC_TIMER_CHAN_ACK) {
/* Copy sqn */
ack[1] = IEEE802154_FCF_TYPE_ACK;
if (cfg.pending) {
ack[1] |= IEEE802154_FCF_FRAME_PEND;
}
ack[3] = rxbuf[3];
NRF_RADIO->PACKETPTR = (uint32_t) &ack;
@ -517,7 +523,7 @@ void isr_radio(void)
case STATE_RX:
if (NRF_RADIO->CRCSTATUS) {
bool l2filter_passed = _l2filter(rxbuf+1);
bool is_auto_ack_en = ack[1];
bool is_auto_ack_en = !IS_ACTIVE(CONFIG_IEEE802154_AUTO_ACK_DISABLE);
bool is_ack = rxbuf[1] & IEEE802154_FCF_TYPE_ACK;
bool ack_req = rxbuf[1] & IEEE802154_FCF_ACK_REQ;
@ -699,26 +705,41 @@ int _set_cca_mode(ieee802154_dev_t *dev, ieee802154_cca_mode_t mode)
return 0;
}
static int _set_hw_addr_filter(ieee802154_dev_t *dev, const network_uint16_t *short_addr,
const eui64_t *ext_addr, const uint16_t *pan_id)
static int _config_addr_filter(ieee802154_dev_t *dev, ieee802154_af_cmd_t cmd, const void *value)
{
(void) dev;
if (short_addr) {
memcpy(nrf802154_short_addr, short_addr, IEEE802154_SHORT_ADDRESS_LEN);
}
if (ext_addr) {
memcpy(nrf802154_long_addr, ext_addr, IEEE802154_LONG_ADDRESS_LEN);
}
if (pan_id) {
nrf802154_pan_id = *pan_id;
const uint16_t *pan_id = value;
switch(cmd) {
case IEEE802154_AF_SHORT_ADDR:
memcpy(nrf802154_short_addr, value, IEEE802154_SHORT_ADDRESS_LEN);
break;
case IEEE802154_AF_EXT_ADDR:
memcpy(nrf802154_long_addr, value, IEEE802154_LONG_ADDRESS_LEN);
break;
case IEEE802154_AF_PANID:
nrf802154_pan_id = *pan_id;
break;
case IEEE802154_AF_PAN_COORD:
return -ENOTSUP;
}
return 0;
}
static int _set_rx_mode(ieee802154_dev_t *dev, ieee802154_rx_mode_t mode)
static int _config_src_addr_match(ieee802154_dev_t *dev, ieee802154_src_match_t cmd, const void *value)
{
(void) dev;
switch(cmd) {
case IEEE802154_SRC_MATCH_EN:
cfg.pending = *((const bool*) value);
break;
default:
return -ENOTSUP;
}
return 0;
}
static int _set_frame_filter_mode(ieee802154_dev_t *dev, ieee802154_filter_mode_t mode)
{
(void) dev;
@ -726,21 +747,16 @@ static int _set_rx_mode(ieee802154_dev_t *dev, ieee802154_rx_mode_t mode)
bool _promisc = false;
switch (mode) {
case IEEE802154_RX_AACK_DISABLED:
ack[1] = 0;
break;
case IEEE802154_RX_AACK_ENABLED:
ack[1] = IEEE802154_FCF_TYPE_ACK;
break;
case IEEE802154_RX_AACK_FRAME_PENDING:
ack[1] = IEEE802154_FCF_TYPE_ACK | IEEE802154_FCF_FRAME_PEND;
break;
case IEEE802154_RX_PROMISC:
_promisc = true;
break;
case IEEE802154_RX_WAIT_FOR_ACK:
ackf = false;
break;
case IEEE802154_FILTER_ACCEPT:
break;
case IEEE802154_FILTER_PROMISC:
_promisc = true;
break;
case IEEE802154_FILTER_ACK_ONLY:
ackf = false;
break;
default:
return -ENOTSUP;
}
cfg.ack_filter = ackf;
@ -800,7 +816,8 @@ static const ieee802154_radio_ops_t nrf802154_ops = {
.set_cca_threshold = set_cca_threshold,
.set_cca_mode = _set_cca_mode,
.config_phy = _config_phy,
.set_hw_addr_filter = _set_hw_addr_filter,
.set_csma_params = _set_csma_params,
.set_rx_mode = _set_rx_mode,
.config_addr_filter = _config_addr_filter,
.config_src_addr_match = _config_src_addr_match,
.set_frame_filter_mode = _set_frame_filter_mode,
};

View File

@ -72,5 +72,10 @@ ifneq (,$(filter at86rf2xx,$(USEMODULE)))
CFLAGS += -DAT86RF2XX_BASIC_MODE
endif
# Auto ACK should be disabled in order to run OpenWSN
ifndef CONFIG_KCONFIG_USEMODULE_IEEE802154
CFLAGS += -DCONFIG_IEEE802154_AUTO_ACK_DISABLE
endif
# LLVM ARM shows issues with missing definitions for stdatomic
TOOLCHAINS_BLACKLIST += llvm

View File

@ -71,9 +71,12 @@ void _idmanager_addr_override(void)
/* Set all IEEE addresses */
uint16_t panid = OPENWSN_PANID;
ieee802154_radio_set_hw_addr_filter(openwsn_radio.dev, &short_addr,
&eui64, &panid);
ieee802154_radio_config_addr_filter(openwsn_radio.dev, IEEE802154_AF_SHORT_ADDR,
&short_addr);
ieee802154_radio_config_addr_filter(openwsn_radio.dev, IEEE802154_AF_EXT_ADDR,
&eui64);
ieee802154_radio_config_addr_filter(openwsn_radio.dev, IEEE802154_AF_PANID,
&panid);
}
static void _hal_radio_cb(ieee802154_dev_t *dev, ieee802154_trx_ev_t status)
@ -137,8 +140,8 @@ int openwsn_radio_init(void *radio_dev)
/* If the radio is still not in TRX_OFF state, spin */
while (ieee802154_radio_confirm_on(dev) == -EAGAIN) {}
/* Enable basic mode, no AUTOACK. no CSMA */
ieee802154_radio_set_rx_mode(dev, IEEE802154_RX_AACK_DISABLED);
/* Enable basic mode (no AUTOACK. no CSMA-CA).
* Auto ACK is disabled via CONFIG_IEEE802154_AUTO_ACK_DISABLE. */
/* MAC layer retransmissions are disabled by _set_csma_params() */
ieee802154_radio_set_csma_params(dev, NULL, -1);
@ -147,7 +150,7 @@ int openwsn_radio_init(void *radio_dev)
where the destination-address mode is 0 (no destination address).
per rfc8180 4.5.1 the destination address must be set, which means
the destination-address mode can't be 0 */
ieee802154_radio_set_rx_mode(dev, IEEE802154_RX_PROMISC);
ieee802154_radio_set_frame_filter_mode(dev, IEEE802154_FILTER_PROMISC);
}
/* Configure PHY settings (channel, TX power) */

View File

@ -301,6 +301,13 @@ extern const uint8_t ieee802154_addr_bcast[IEEE802154_ADDR_BCAST_LEN];
#define CONFIG_IEEE802154_CCA_THRESH_DEFAULT (-70)
#endif
/**
* @brief Disable Auto ACK support
*/
#ifdef DOXYGEN
#define CONFIG_IEEE802154_AUTO_ACK_DISABLE 0
#endif
/**
* @brief Initializes an IEEE 802.15.4 MAC frame header in @p buf.
*

View File

@ -148,6 +148,15 @@ typedef enum {
* @brief Multi-Rate Frequency Shift Keying PHY mode
*/
IEEE802154_CAP_PHY_MR_FSK = BIT17,
/**
* @brief the device supports source address match table.
*
* A Source Address Match table contains source addresses with pending
* data. When a coordinator device receives an IEEE 802.15.4 Data
* Request command from a child node, the Frame Pending bit of the ACK is
* set if the source address matches one from the table.
*/
IEEE802154_CAP_SRC_ADDR_MATCH = BIT18,
} ieee802154_rf_caps_t;
/**
@ -288,6 +297,87 @@ typedef enum {
IEEE802154_RADIO_CONFIRM_CCA,
} ieee802154_trx_ev_t;
/**
* @brief Source Address Match commands.
*/
typedef enum {
/**
* @brief Enable or disable source address match.
*
* Enabling it sets the frame pending to all ACK frames in
* response to a Data Request command (if the radio doesn't
* support Source Address Matching) or to a specific address
* in the Source Address Matching table
*/
IEEE802154_SRC_MATCH_EN,
/**
* @brief Add a short address to entry.
*
* This command should only be implemented if @ref IEEE802154_CAP_SRC_ADDR_MATCH
* is available.
*/
IEEE802154_SRC_MATCH_SHORT_ADD,
/**
* @brief Clear short address from entry.
* This command should only be implemented if @ref IEEE802154_CAP_SRC_ADDR_MATCH
* is available.
*/
IEEE802154_SRC_MATCH_SHORT_CLEAR,
/**
* @brief Add a extended address to entry.
* This command should only be implemented if @ref IEEE802154_CAP_SRC_ADDR_MATCH
* is available.
*/
IEEE802154_SRC_MATCH_EXT_ADD,
/**
* @brief Clear extended address from entry.
*
* This command should only be implemented if @ref IEEE802154_CAP_SRC_ADDR_MATCH
* is available.
*/
IEEE802154_SRC_MATCH_EXT_CLEAR,
} ieee802154_src_match_t;
/**
* @brief Address filter command
*/
typedef enum {
IEEE802154_AF_SHORT_ADDR, /**< Set short IEEE 802.15.4 address (network_uint16_t) */
IEEE802154_AF_EXT_ADDR, /**< Set extended IEEE 802.15.4 address (eui64_t) */
IEEE802154_AF_PANID, /**< Set PAN ID (uint16_t) */
IEEE802154_AF_PAN_COORD, /**< Set device as PAN coordinator (bool) */
} ieee802154_af_cmd_t;
/**
* @brief Frame Filter mode
*/
typedef enum {
/**
* @brief accept all valid frames that match address filter configuration
*/
IEEE802154_FILTER_ACCEPT,
/**
* @brief accept only ACK frames
*
* @note This mode should only be implemented if the transceiver doesn't
* handle ACK frame reception (when @ref IEEE802154_CAP_FRAME_RETRANS and
* @ref IEEE802154_CAP_IRQ_ACK_TIMEOUT are not present).
*/
IEEE802154_FILTER_ACK_ONLY,
/**
* @brief accept all valid frames
*
* @note This mode is optional
*/
IEEE802154_FILTER_PROMISC,
/**
* @brief accept all frames, regardless of FCS
*
* @note This mode is optional
*/
IEEE802154_FILTER_SNIFFER,
} ieee802154_filter_mode_t;
/**
* @brief CSMA-CA exponential backoff parameters.
*/
@ -372,40 +462,6 @@ typedef enum {
IEEE802154_CCA_MODE_ED_THRESH_OR_CS,
} ieee802154_cca_mode_t;
/**
* @brief RX mode configuration
*/
typedef enum {
/**
* @brief Auto ACK is disabled
*/
IEEE802154_RX_AACK_DISABLED,
/**
* @brief Auto ACK is enabled
*/
IEEE802154_RX_AACK_ENABLED,
/**
* @brief Auto ACK is enabled and frame pending bit set in the next ACK frame
*/
IEEE802154_RX_AACK_FRAME_PENDING,
/**
* @brief Radio is in promiscuous mode
*/
IEEE802154_RX_PROMISC,
/**
* @brief Radio is ready to receive ACK frames
*
* This mode is optional. If a radio decides to implement it, the radio
* should allow ACK frames (and block ACK frames in all other RX modes).
* Note that this mode cannot guarantee that only ACK frames will be
* received.
*
* Expected to be implemented when either @ref IEEE802154_CAP_FRAME_RETRANS
* or @ref IEEE802154_CAP_IRQ_ACK_TIMEOUT is not there.
*/
IEEE802154_RX_WAIT_FOR_ACK,
} ieee802154_rx_mode_t;
/**
* @brief Holder of the PHY configuration
*/
@ -565,9 +621,10 @@ struct ieee802154_radio_ops {
* - @ref set_cca_threshold
* - @ref set_cca_mode
* - @ref config_phy
* - @ref config_addr_filter
* - @ref set_csma_params
* - @ref set_rx_mode
* - @ref set_hw_addr_filter
* - @ref set_frame_filter_mode
* - @ref config_src_addr_match
* - @ref set_frame_retrans (if available)
*
* @param[in] dev IEEE802.15.4 device descriptor
@ -698,26 +755,6 @@ struct ieee802154_radio_ops {
*/
int (*config_phy)(ieee802154_dev_t *dev, const ieee802154_phy_conf_t *conf);
/**
* @brief Set IEEE802.15.4 addresses in hardware address filter
*
* @pre the device is on
*
* @param[in] dev IEEE802.15.4 device descriptor
* @param[in] short_addr the IEEE802.15.4 short address. If NULL, the short
* address is not altered..
* @param[in] ext_addr the IEEE802.15.4 extended address (Network Byte Order).
* If NULL, the extended address is not altered.
* @param[in] pan_id the IEEE802.15.4 PAN ID. If NULL, the PAN ID is not altered.
*
* @return 0 on success
* @return negative errno on error
*/
int (*set_hw_addr_filter)(ieee802154_dev_t *dev,
const network_uint16_t *short_addr,
const eui64_t *ext_addr,
const uint16_t *pan_id);
/**
* @brief Set number of frame retransmissions
*
@ -756,15 +793,55 @@ struct ieee802154_radio_ops {
int8_t retries);
/**
* @brief Set the RX mode.
* @brief Set the frame filter moder.
*
* @pre the device is on
*
* @param[in] dev IEEE802.15.4 device descriptor
* @param[in] mode RX mode
* @param[in] mode address filter mode
*
* @return 0 on success
* @return negative errno on error
*/
int (*set_rx_mode)(ieee802154_dev_t *dev, ieee802154_rx_mode_t mode);
int (*set_frame_filter_mode)(ieee802154_dev_t *dev, ieee802154_filter_mode_t mode);
/**
* @brief Configure the address filter.
*
* This functions is used for configuring the address filter parameters
* required by the IEEE 802.15.4 standard.
*
* @pre the device is on
*
* @param[in] dev IEEE802.15.4 device descriptor
* @param[in] cmd command for the address filter
* @param[in] value value for @p cmd.
*
* @return 0 on success
* @return negative errno on error
*/
int (*config_addr_filter)(ieee802154_dev_t *dev, ieee802154_af_cmd_t cmd, const void *value);
/**
* @brief Set the source address match configuration.
*
* This function configures the source address match filter in order to set
* the Frame Pending bit in ACK frames accordingly.
* In case the radio doesn't support @ref IEEE802154_CAP_SRC_ADDR_MATCH,
* this functions is used to activate the Frame Pending bit for all ACK
* frames (in order to be compliant with the IEEE 802.15.4 standard).
*
* @pre the device is on
*
* @param[in] dev IEEE802.15.4 device descriptor
* @param[in] cmd command for the source address match configuration
* @param[in] value value associated to @p cmd.
*
* @return 0 on success
* @return negative errno on error
*/
int (*config_src_addr_match)(ieee802154_dev_t *dev, ieee802154_src_match_t cmd,
const void *value);
};
/**
@ -881,6 +958,24 @@ static inline int ieee802154_radio_config_phy(ieee802154_dev_t *dev,
return dev->driver->config_phy(dev, conf);
}
/**
* @brief Shortcut to @ref ieee802154_radio_ops::config_src_addr_match
*
* @pre the device is on
*
* @param[in] dev IEEE802.15.4 device descriptor
* @param[in] cmd command for the source address match configuration
* @param[in] value value associated to @p cmd.
*
* @return result of @ref ieee802154_radio_ops::config_src_addr_match
*/
static inline int ieee802154_radio_config_src_address_match(ieee802154_dev_t *dev,
ieee802154_src_match_t cmd,
const void *value)
{
return dev->driver->config_src_addr_match(dev, cmd, value);
}
/**
* @brief Shortcut to @ref ieee802154_radio_ops::off
*
@ -896,25 +991,37 @@ static inline int ieee802154_radio_off(ieee802154_dev_t *dev)
}
/**
* @brief Shortcut to @ref ieee802154_radio_ops::set_hw_addr_filter
* @brief Shortcut to @ref ieee802154_radio_ops::config_addr_filter
*
* @pre the device is on
*
* @param[in] dev IEEE802.15.4 device descriptor
* @param[in] short_addr the IEEE802.15.4 short address. If NULL, the short
* address is not altered..
* @param[in] ext_addr the IEEE802.15.4 extended address (Network Byte Order).
* If NULL, the extended address is not altered.
* @param[in] pan_id the IEEE802.15.4 PAN ID. If NULL, the PAN ID is not altered.
* @param[in] cmd command for the address filter
* @param[in] value value for @p cmd.
*
* @return result of @ref ieee802154_radio_ops::set_hw_addr_filter
* @return result of @ref ieee802154_radio_ops::config_addr_filter
*/
static inline int ieee802154_radio_set_hw_addr_filter(ieee802154_dev_t *dev,
const network_uint16_t *short_addr,
const eui64_t *ext_addr,
const uint16_t *pan_id)
static inline int ieee802154_radio_config_addr_filter(ieee802154_dev_t *dev,
ieee802154_af_cmd_t cmd,
const void* value)
{
return dev->driver->set_hw_addr_filter(dev, short_addr, ext_addr, pan_id);
return dev->driver->config_addr_filter(dev, cmd, value);
}
/**
* @brief Shortcut to @ref ieee802154_radio_ops::set_frame_filter_mode
*
* @pre the device is on
*
* @param[in] dev IEEE802.15.4 device descriptor
* @param[in] mode frame filter mode
*
* @return result of @ref ieee802154_radio_ops::set_frame_filter_mode
*/
static inline int ieee802154_radio_set_frame_filter_mode(ieee802154_dev_t *dev,
ieee802154_filter_mode_t mode)
{
return dev->driver->set_frame_filter_mode(dev, mode);
}
/**
@ -1303,20 +1410,6 @@ static inline uint32_t ieee802154_radio_get_phy_modes(ieee802154_dev_t *dev)
return (dev->driver->caps & IEEE802154_RF_CAPS_PHY_MASK);
}
/**
* @brief Shortcut to @ref ieee802154_radio_ops::set_rx_mode
*
* @param[in] dev IEEE802.15.4 device descriptor
* @param[in] mode RX mode
*
* @return result of @ref ieee802154_radio_ops::set_rx_mode
*/
static inline int ieee802154_radio_set_rx_mode(ieee802154_dev_t *dev,
ieee802154_rx_mode_t mode)
{
return dev->driver->set_rx_mode(dev, mode);
}
/**
* @brief Convert a @ref ieee802154_phy_mode_t to a @ref ieee802154_rf_caps_t
* value.

View File

@ -173,8 +173,8 @@ int ieee802154_send(ieee802154_submac_t *submac, const iolist_t *iolist);
static inline int ieee802154_set_short_addr(ieee802154_submac_t *submac,
const network_uint16_t *short_addr)
{
int res = ieee802154_radio_set_hw_addr_filter(submac->dev, short_addr, NULL,
NULL);
int res = ieee802154_radio_config_addr_filter(submac->dev, IEEE802154_AF_SHORT_ADDR, short_addr);
if (res >= 0) {
memcpy(&submac->short_addr, short_addr, IEEE802154_SHORT_ADDRESS_LEN);
@ -195,8 +195,7 @@ static inline int ieee802154_set_short_addr(ieee802154_submac_t *submac,
static inline int ieee802154_set_ext_addr(ieee802154_submac_t *submac,
const eui64_t *ext_addr)
{
int res = ieee802154_radio_set_hw_addr_filter(submac->dev, NULL, ext_addr,
NULL);
int res = ieee802154_radio_config_addr_filter(submac->dev, IEEE802154_AF_EXT_ADDR, ext_addr);
if (res >= 0) {
memcpy(&submac->ext_addr, ext_addr, IEEE802154_LONG_ADDRESS_LEN);
@ -216,8 +215,7 @@ static inline int ieee802154_set_ext_addr(ieee802154_submac_t *submac,
static inline int ieee802154_set_panid(ieee802154_submac_t *submac,
const uint16_t *panid)
{
int res = ieee802154_radio_set_hw_addr_filter(submac->dev, NULL, NULL,
panid);
int res = ieee802154_radio_config_addr_filter(submac->dev, IEEE802154_AF_PANID, panid);
if (res >= 0) {
submac->panid = *panid;

View File

@ -82,6 +82,9 @@ if KCONFIG_USEMODULE_IEEE802154
config IEEE802154_DEFAULT_CSMA_CA_MAX
int "IEEE802.15.4 default CSMA-CA maximum backoff exponent"
default 5
config IEEE802154_AUTO_ACK_DISABLE
bool "Disable Auto ACK support" if !USEPKG_OPENWSN
default y if USEPKG_OPENWSN
menuconfig KCONFIG_USEMODULE_IEEE802154_SECURITY
bool "Configure IEEE802.15.4 Security"

View File

@ -76,7 +76,7 @@ static int _perform_csma_ca(ieee802154_submac_t *submac)
submac->csma_retries_nb++;
}
else {
ieee802154_radio_set_rx_mode(dev, IEEE802154_RX_AACK_ENABLED);
ieee802154_radio_set_frame_filter_mode(dev, IEEE802154_FILTER_ACCEPT);
_tx_end(submac, TX_STATUS_MEDIUM_BUSY, NULL);
}
@ -134,7 +134,7 @@ static void _perform_retrans(ieee802154_submac_t *submac)
ieee802154_csma_ca_transmit(submac);
}
else {
ieee802154_radio_set_rx_mode(dev, IEEE802154_RX_AACK_ENABLED);
ieee802154_radio_set_frame_filter_mode(dev, IEEE802154_FILTER_ACCEPT);
_tx_end(submac, TX_STATUS_NO_ACK, NULL);
}
}
@ -169,8 +169,7 @@ void ieee802154_submac_rx_done_cb(ieee802154_submac_t *submac)
ieee802154_tx_info_t tx_info;
tx_info.retrans = submac->retrans;
bool fp = (ack[0] & IEEE802154_FCF_FRAME_PEND);
ieee802154_radio_set_rx_mode(submac->dev,
IEEE802154_RX_AACK_ENABLED);
ieee802154_radio_set_frame_filter_mode(submac->dev, IEEE802154_FILTER_ACCEPT);
_tx_end(submac, fp ? TX_STATUS_FRAME_PENDING : TX_STATUS_SUCCESS,
&tx_info);
}
@ -216,7 +215,7 @@ static void _handle_tx_success(ieee802154_submac_t *submac,
_tx_end(submac, info->status, info);
}
else {
ieee802154_radio_set_rx_mode(dev, IEEE802154_RX_WAIT_FOR_ACK);
ieee802154_radio_set_frame_filter_mode(dev, IEEE802154_FILTER_ACK_ONLY);
/* Handle ACK reception */
ieee802154_submac_ack_timer_set(submac, ACK_TIMEOUT_US);
@ -363,12 +362,10 @@ int ieee802154_submac_init(ieee802154_submac_t *submac, const network_uint16_t *
/* If the radio is still not in TRX_OFF state, spin */
while (ieee802154_radio_confirm_on(dev) == -EAGAIN) {}
/* Enable Auto ACK */
ieee802154_radio_set_rx_mode(dev, IEEE802154_RX_AACK_ENABLED);
/* Configure address filter */
ieee802154_radio_set_hw_addr_filter(dev, &submac->short_addr,
&submac->ext_addr, &submac->panid);
ieee802154_radio_config_addr_filter(dev, IEEE802154_AF_SHORT_ADDR, &submac->short_addr);
ieee802154_radio_config_addr_filter(dev, IEEE802154_AF_EXT_ADDR, &submac->ext_addr);
ieee802154_radio_config_addr_filter(dev, IEEE802154_AF_PANID, &submac->panid);
/* Configure PHY settings (mode, channel, TX power) */
ieee802154_phy_conf_t conf =

View File

@ -48,7 +48,6 @@ static xtimer_t timer_ack;
static mutex_t lock;
static const char *str_states[3]= {"TRX_OFF", "RX", "TX"};
static ieee802154_rx_mode_t current_rx_mode;
static eui64_t ext_addr;
static network_uint16_t short_addr;
static uint8_t seq;
@ -86,7 +85,7 @@ static void _ack_timeout(event_t *event)
(void) event;
ieee802154_dev_t *dev = ieee802154_hal_test_get_dev(RADIO_DEFAULT_ID);
ieee802154_radio_set_rx_mode(dev, current_rx_mode);
ieee802154_radio_set_frame_filter_mode(dev, IEEE802154_FILTER_ACCEPT);
}
static event_t _ack_timeout_ev = {
@ -217,8 +216,8 @@ static void _send(iolist_t *pkt)
while(ieee802154_radio_confirm_set_trx_state(ieee802154_hal_test_get_dev(RADIO_DEFAULT_ID)) == -EAGAIN);
/* Trigger the transmit and wait for the mutex unlock (TX_DONE event) */
ieee802154_radio_set_frame_filter_mode(ieee802154_hal_test_get_dev(RADIO_DEFAULT_ID), IEEE802154_FILTER_ACK_ONLY);
ieee802154_radio_request_transmit(ieee802154_hal_test_get_dev(RADIO_DEFAULT_ID));
ieee802154_radio_set_rx_mode(ieee802154_hal_test_get_dev(RADIO_DEFAULT_ID), IEEE802154_RX_WAIT_FOR_ACK);
mutex_lock(&lock);
event_post(EVENT_PRIO_HIGHEST, &_tx_finish_ev);
@ -241,12 +240,16 @@ static int _init(void)
ieee802154_radio_request_on(ieee802154_hal_test_get_dev(RADIO_DEFAULT_ID));
while(ieee802154_radio_confirm_on(ieee802154_hal_test_get_dev(RADIO_DEFAULT_ID)) == -EAGAIN) {}
current_rx_mode = IEEE802154_RX_AACK_ENABLED;
ieee802154_radio_set_rx_mode(ieee802154_hal_test_get_dev(RADIO_DEFAULT_ID), current_rx_mode);
ieee802154_radio_set_frame_filter_mode(ieee802154_hal_test_get_dev(RADIO_DEFAULT_ID), IEEE802154_FILTER_ACCEPT);
uint16_t panid = CONFIG_IEEE802154_DEFAULT_PANID;
/* Set all IEEE addresses */
ieee802154_radio_set_hw_addr_filter(ieee802154_hal_test_get_dev(RADIO_DEFAULT_ID), &short_addr, &ext_addr, &panid);
ieee802154_radio_config_addr_filter(ieee802154_hal_test_get_dev(RADIO_DEFAULT_ID),
IEEE802154_AF_SHORT_ADDR, &short_addr);
ieee802154_radio_config_addr_filter(ieee802154_hal_test_get_dev(RADIO_DEFAULT_ID),
IEEE802154_AF_EXT_ADDR, &ext_addr);
ieee802154_radio_config_addr_filter(ieee802154_hal_test_get_dev(RADIO_DEFAULT_ID),
IEEE802154_AF_PANID, &panid);
/* Set PHY configuration */
ieee802154_phy_conf_t conf = {.channel=CONFIG_IEEE802154_DEFAULT_CHANNEL, .page=CONFIG_IEEE802154_DEFAULT_SUBGHZ_PAGE, .pow=CONFIG_IEEE802154_DEFAULT_TXPOWER};
@ -457,33 +460,24 @@ int txtsnd(int argc, char **argv)
return send(addr, res, len);
}
static int rx_mode_cmd(int argc, char **argv)
static int promisc(int argc, char **argv)
{
ieee802154_rx_mode_t conf;
ieee802154_filter_mode_t conf;
if (argc < 2) {
printf("Usage: %s <on|off|pend|promisc>", argv[0]);
printf("Usage: %s <on|off>", argv[0]);
return 1;
}
if (strcmp(argv[1], "pend") == 0) {
conf = IEEE802154_RX_AACK_FRAME_PENDING;
puts("ACK enabled with Frame Pending");
}
else if (strcmp(argv[1], "off") == 0) {
conf = IEEE802154_RX_AACK_DISABLED;
puts("ACK disabled");
}
else if (strcmp(argv[1], "promisc") == 0) {
conf = IEEE802154_RX_PROMISC;
puts("Promiscuous mode enabled");
if (strcmp(argv[1], "on") == 0) {
conf = IEEE802154_FILTER_PROMISC;
puts("Enabled promiscuos mode");
}
else {
conf = IEEE802154_RX_AACK_ENABLED;
puts("ACK enabled");
conf = IEEE802154_FILTER_ACCEPT;
puts("Disabled promiscuos mode");
}
current_rx_mode = conf;
ieee802154_radio_set_rx_mode(ieee802154_hal_test_get_dev(RADIO_DEFAULT_ID), conf);
ieee802154_radio_set_frame_filter_mode(ieee802154_hal_test_get_dev(RADIO_DEFAULT_ID), conf);
return 0;
}
@ -729,7 +723,7 @@ static const shell_command_t shell_commands[] = {
{ "test_states", "Test state changes", _test_states },
{ "cca", "Perform CCA", _cca },
{ "config_cca", "Config CCA parameters", _config_cca_cmd },
{ "rx_mode", "Enable/Disable AACK or set Frame Pending bit or set promiscuos mode", rx_mode_cmd },
{ "promisc", "Set promiscuos mode", promisc },
{ "tx_mode", "Enable CSMA-CA, CCA or direct transmission", txmode_cmd },
{ "caps", "Get a list of caps supported by the device", _caps_cmd },
{ NULL, NULL, NULL }