Loading...
Searching...
No Matches
submac.h
1/*
2 * SPDX-FileCopyrightText: 2020 HAW Hamburg
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
123
124#include "mutex.h"
125#ifdef __cplusplus
126extern "C" {
127#endif
128
129#include <stdint.h>
130#include <stdio.h>
131#include <string.h>
132#include "assert.h"
133
134#include "net/ieee802154.h"
135#include "net/ieee802154/radio.h"
136
141
145typedef struct {
159 void (*rx_done)(ieee802154_submac_t *submac);
172 void (*tx_done)(ieee802154_submac_t *submac, int status,
175
191
200
206
214
223#if IS_USED(MODULE_IEEE802154_SUBMAC_SOFT_CSMA_CA)
225 uint16_t csma_backoff_us;
226 uint8_t csma_retries;
227 uint8_t backoff_mask;
228 uint8_t csma_retries_nb;
229#endif
230#if IS_USED(MODULE_IEEE802154_SUBMAC_SOFT_FRAME_RETRANS)
231 uint8_t retrans;
232 bool wait_for_ack;
233#endif
234 uint16_t ack_timeout_us;
235 uint16_t panid;
236 uint16_t channel_num;
237 int8_t tx_pow;
241 const iolist_t *psdu;
242 uint8_t tx_ftype;
243};
244
261
272 const network_uint16_t *short_addr)
273{
274 int res = ieee802154_radio_config_addr_filter(&submac->dev,
276 short_addr);
277
278 if (res >= 0) {
279 memcpy(&submac->short_addr, short_addr, IEEE802154_SHORT_ADDRESS_LEN);
280 }
281
282 return res;
283}
284
295 const eui64_t *ext_addr)
296{
297 int res = ieee802154_radio_config_addr_filter(&submac->dev,
299 ext_addr);
300
301 if (res >= 0) {
302 memcpy(&submac->ext_addr, ext_addr, IEEE802154_LONG_ADDRESS_LEN);
303 }
304 return res;
305}
306
317 const uint16_t *panid)
318{
319 int res = ieee802154_radio_config_addr_filter(&submac->dev,
321 panid);
322
323 if (res >= 0) {
324 submac->panid = *panid;
325 }
326
327 return res;
328}
329
338 ieee802154_submac_t *submac)
339{
340 return submac->phy_mode;
341}
342
357
374 uint16_t channel_num)
375{
376 const ieee802154_phy_conf_t conf = {
377 .phy_mode = IEEE802154_PHY_NO_OP,
378 .channel = channel_num,
379 .pow = submac->tx_pow,
380 };
381
382 return ieee802154_set_phy_conf(submac, &conf);
383}
384
401 int8_t tx_pow)
402{
403 const ieee802154_phy_conf_t conf = {
404 .phy_mode = IEEE802154_PHY_NO_OP,
405 .channel = submac->channel_num,
406 .pow = tx_pow,
407 };
408
409 return ieee802154_set_phy_conf(submac, &conf);
410}
411
423{
424 return ieee802154_radio_len(&submac->dev);
425}
426
443static inline int ieee802154_read_frame(ieee802154_submac_t *submac, void *buf,
444 size_t len, ieee802154_rx_info_t *info)
445{
446 return ieee802154_radio_read(&submac->dev, buf, len, info);
447}
448
458
468
482 const eui64_t *ext_addr);
483
492
501
515
531
541
551
561
579
596
597#ifdef __cplusplus
598}
599#endif
600
POSIX.1-2008 compliant version of the assert macro.
be_uint16_t network_uint16_t
A 16 bit integer in network byte order.
Definition byteorder.h:92
static int ieee802154_radio_read(ieee802154_dev_t *dev, void *buf, size_t size, ieee802154_rx_info_t *info)
Shortcut to ieee802154_radio_ops::read.
Definition radio.h:1038
struct ieee802154_dev ieee802154_dev_t
Forward declaration of the IEEE802.15.4 device descriptor.
Definition radio.h:415
static int ieee802154_radio_len(ieee802154_dev_t *dev)
Shortcut to ieee802154_radio_ops::len.
Definition radio.h:1022
static int ieee802154_radio_config_addr_filter(ieee802154_dev_t *dev, ieee802154_af_cmd_t cmd, const void *value)
Shortcut to ieee802154_radio_ops::config_addr_filter.
Definition radio.h:1153
@ IEEE802154_AF_EXT_ADDR
Set extended IEEE 802.15.4 address (eui64_t)
Definition radio.h:346
@ IEEE802154_AF_SHORT_ADDR
Set short IEEE 802.15.4 address (network_uint16_t)
Definition radio.h:345
@ IEEE802154_AF_PANID
Set PAN ID (uint16_t)
Definition radio.h:347
#define IEEE802154_SHORT_ADDRESS_LEN
IEEE 802.15.4 address lengths.
Definition ieee802154.h:41
ieee802154_phy_mode_t
802.15.4 PHY modes
Definition ieee802154.h:192
#define IEEE802154_LONG_ADDRESS_LEN
long address (EUI-64)
Definition ieee802154.h:42
@ IEEE802154_PHY_NO_OP
don't change PHY configuration
Definition ieee802154.h:201
static int ieee802154_set_idle(ieee802154_submac_t *submac)
Set the SubMAC to IDLE state.
Definition submac.h:575
bool ieee802154_submac_state_is_rx(ieee802154_submac_t *submac)
Check whether the SubMAC is in RX state.
static int ieee802154_get_frame_length(ieee802154_submac_t *submac)
Get the received frame length.
Definition submac.h:422
void ieee802154_submac_ack_timer_cancel(ieee802154_submac_t *submac)
Cancel the ACK timeout timer.
struct ieee802154_submac ieee802154_submac_t
IEEE 802.15.4 SubMAC forward declaration.
Definition submac.h:140
int ieee802154_send(ieee802154_submac_t *submac, const iolist_t *iolist)
Transmit an IEEE 802.15.4 PSDU.
ieee802154_submac_fsm_return_t(* ieee802154_fsm_state_cb_t)(ieee802154_submac_t *submac, ieee802154_fsm_ev_t ev)
Internal SubMAC FSM state.
Definition submac.h:204
static void ieee802154_submac_tx_done_cb(ieee802154_submac_t *submac)
Indicate the SubMAC that the device finished the transmission procedure.
Definition submac.h:557
void ieee802154_submac_ack_timer_set(ieee802154_submac_t *submac)
Set the ACK timeout timer.
bool ieee802154_submac_state_is_idle(ieee802154_submac_t *submac)
Check whether the SubMAC is in IDLE state.
static int ieee802154_set_short_addr(ieee802154_submac_t *submac, const network_uint16_t *short_addr)
Set the IEEE 802.15.4 short address.
Definition submac.h:271
int ieee802154_submac_init(ieee802154_submac_t *submac, const network_uint16_t *short_addr, const eui64_t *ext_addr)
Init the IEEE 802.15.4 SubMAC.
static int ieee802154_set_ext_addr(ieee802154_submac_t *submac, const eui64_t *ext_addr)
Set the IEEE 802.15.4 extended address.
Definition submac.h:294
static int ieee802154_set_channel_number(ieee802154_submac_t *submac, uint16_t channel_num)
Set IEEE 802.15.4 channel number.
Definition submac.h:373
int ieee802154_set_phy_conf(ieee802154_submac_t *submac, const ieee802154_phy_conf_t *conf)
Set IEEE 802.15.4 PHY configuration (channel, TX power)
ieee802154_fsm_ev_t
Internal SubMAC FSM state machine events.
Definition submac.h:179
int ieee802154_submac_process_ev(ieee802154_submac_t *submac, ieee802154_fsm_ev_t ev)
Process an FSM event.
static ieee802154_phy_mode_t ieee802154_get_phy_mode(ieee802154_submac_t *submac)
Get IEEE 802.15.4 PHY mode.
Definition submac.h:337
static int ieee802154_set_rx(ieee802154_submac_t *submac)
Set the SubMAC to RX state.
Definition submac.h:592
static int ieee802154_set_tx_power(ieee802154_submac_t *submac, int8_t tx_pow)
Set IEEE 802.15.4 transmission power.
Definition submac.h:400
static int ieee802154_read_frame(ieee802154_submac_t *submac, void *buf, size_t len, ieee802154_rx_info_t *info)
Read the received frame.
Definition submac.h:443
ieee802154_submac_fsm_return_t
Internal SubMAC FSM process Event return status.
Definition submac.h:195
static void ieee802154_submac_ack_timeout_fired(ieee802154_submac_t *submac)
Indicate the SubMAC that the ACK timeout fired.
Definition submac.h:527
static int ieee802154_set_panid(ieee802154_submac_t *submac, const uint16_t *panid)
Set the IEEE 802.15.4 PAN ID.
Definition submac.h:316
static void ieee802154_submac_rx_done_cb(ieee802154_submac_t *submac)
Indicate the SubMAC that the device received a frame.
Definition submac.h:537
static void ieee802154_submac_crc_error_cb(ieee802154_submac_t *submac)
Indicate the SubMAC that a frame with invalid CRC was received.
Definition submac.h:547
@ IEEE802154_FSM_EV_ACK_TIMEOUT
ACK timer fired.
Definition submac.h:185
@ IEEE802154_FSM_EV_CRC_ERROR
Radio reports frame was received but CRC failed.
Definition submac.h:184
@ IEEE802154_FSM_EV_REQUEST_TX
The upper layer requested to transmit a frame.
Definition submac.h:186
@ IEEE802154_FSM_EV_EXIT
FSM calls exit function of a state.
Definition submac.h:181
@ IEEE802154_FSM_EV_TX_DONE
Radio reports frame was sent.
Definition submac.h:182
@ IEEE802154_FSM_EV_REQUEST_SET_IDLE
The upper layer requested to go to IDLE.
Definition submac.h:188
@ IEEE802154_FSM_EV_NUMOF
Number of SubMAC FSM events.
Definition submac.h:189
@ IEEE802154_FSM_EV_RX_DONE
Radio reports frame was received.
Definition submac.h:183
@ IEEE802154_FSM_EV_ENTRY
FSM calls entry function of a state.
Definition submac.h:180
@ IEEE802154_FSM_EV_REQUEST_SET_RX_ON
The upper layer requested to go to RX.
Definition submac.h:187
@ IEEE802154_SUBMAC_FSM_RETURN_HANDLED
Event was handled.
Definition submac.h:196
@ IEEE802154_SUBMAC_FSM_RETURN_IGNORED
Event was ignored, no action was performed.
Definition submac.h:198
@ IEEE802154_SUBMAC_FSM_RETURN_TRANSITION
Event has caused a transition.
Definition submac.h:197
struct iolist iolist_t
iolist forward declaration
Definition iolist.h:30
Mutex for thread synchronization.
CSMA-CA exponential backoff parameters.
Definition radio.h:384
Internal SubMAC FSM.
Definition submac.h:210
mutex_t lock
Access lock to the FSM.
Definition submac.h:212
ieee802154_fsm_state_cb_t fsm_state_cb
Current state of the SubMAC FSM.
Definition submac.h:211
Holder of the PHY configuration.
Definition radio.h:469
RX information associated to a frame.
Definition radio.h:392
IEEE 802.15.4 SubMAC callbacks.
Definition submac.h:145
void(* tx_done)(ieee802154_submac_t *submac, int status, ieee802154_tx_info_t *info)
TX done event.
Definition submac.h:172
void(* rx_done)(ieee802154_submac_t *submac)
RX done event.
Definition submac.h:159
IEEE 802.15.4 SubMAC descriptor.
Definition submac.h:218
const ieee802154_submac_cb_t * cb
pointer to the SubMAC callbacks
Definition submac.h:222
eui64_t ext_addr
IEEE 802.15.4 extended address.
Definition submac.h:220
const iolist_t * psdu
stores the current PSDU
Definition submac.h:241
int8_t tx_pow
Transmission power (in dBm)
Definition submac.h:237
network_uint16_t short_addr
IEEE 802.15.4 short address.
Definition submac.h:221
uint8_t tx_ftype
frame type of the current TX frame
Definition submac.h:242
ieee802154_fsm_t fsm
FSM of the SubMAC.
Definition submac.h:238
uint16_t channel_num
IEEE 802.15.4 channel number.
Definition submac.h:236
uint16_t ack_timeout_us
ACK timeout in µs.
Definition submac.h:234
ieee802154_phy_mode_t phy_mode
IEEE 802.15.4 PHY mode.
Definition submac.h:240
ieee802154_dev_t dev
802.15.4 HAL descriptor
Definition submac.h:219
int32_t fsm_context_res
Result of the proceeded fsm action.
Definition submac.h:239
uint16_t panid
IEEE 802.15.4 PAN ID.
Definition submac.h:235
TX information of the last transmitted frame.
Definition radio.h:407
iolist structure definition
Definition iolist.h:35
Mutex structure.
Definition mutex.h:36
IEEE 802.15.4 header definitions.
Data type to represent an EUI-64.
Definition eui64.h:52