All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
ieee802154.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015-2019 Freie Universität Berlin
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
21#ifndef NET_IEEE802154_H
22#define NET_IEEE802154_H
23
24#include <stdint.h>
25#include <stdlib.h>
26
27#include "byteorder.h"
28#include "modules.h"
29#include "net/eui64.h"
30#include "time_units.h"
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
39#define IEEE802154_SFD (0xa7)
40
45#define IEEE802154_SHORT_ADDRESS_LEN (2U)
46#define IEEE802154_LONG_ADDRESS_LEN (8U)
55#define IEEE802154_MAX_HDR_LEN (23U)
56#define IEEE802154_MIN_FRAME_LEN (IEEE802154_FCF_LEN + sizeof(uint8_t))
57
58#define IEEE802154_FCF_LEN (2U)
59#define IEEE802154_FCS_LEN (2U)
60
61#define IEEE802154_FCF_TYPE_MASK (0x07)
62#define IEEE802154_FCF_TYPE_BEACON (0x00)
63#define IEEE802154_FCF_TYPE_DATA (0x01)
64#define IEEE802154_FCF_TYPE_ACK (0x02)
65#define IEEE802154_FCF_TYPE_MACCMD (0x03)
66
67#define IEEE802154_FCF_SECURITY_EN (0x08)
68#define IEEE802154_FCF_FRAME_PEND (0x10)
69#define IEEE802154_FCF_ACK_REQ (0x20)
70#define IEEE802154_FCF_PAN_COMP (0x40)
72#define IEEE802154_FCF_DST_ADDR_MASK (0x0c)
73#define IEEE802154_FCF_DST_ADDR_VOID (0x00)
74#define IEEE802154_FCF_DST_ADDR_RESV (0x04)
75#define IEEE802154_FCF_DST_ADDR_SHORT (0x08)
76#define IEEE802154_FCF_DST_ADDR_LONG (0x0c)
78#define IEEE802154_FCF_VERS_MASK (0x30)
79#define IEEE802154_FCF_VERS_V0 (0x00)
80#define IEEE802154_FCF_VERS_V1 (0x10)
81
82#define IEEE802154_FCF_SRC_ADDR_MASK (0xc0)
83#define IEEE802154_FCF_SRC_ADDR_VOID (0x00)
84#define IEEE802154_FCF_SRC_ADDR_RESV (0x40)
85#define IEEE802154_FCF_SRC_ADDR_SHORT (0x80)
86#define IEEE802154_FCF_SRC_ADDR_LONG (0xc0)
93#define IEEE802154_CHANNEL_MIN_SUBGHZ (0U)
94#define IEEE802154_CHANNEL_MAX_SUBGHZ (10U)
95#define IEEE802154_CHANNEL_MIN (11U)
96#define IEEE802154_CHANNEL_MAX (26U)
99#define IEEE802154_FRAME_LEN_MAX (127U)
100#define IEEE802154G_FRAME_LEN_MAX (2047U)
101#define IEEE802154_ACK_FRAME_LEN (5U)
106#define IEEE802154_LIFS_SYMS (40U)
107
111#define IEEE802154_SIFS_SYMS (12U)
112
116#define IEEE802154_SIFS_MAX_FRAME_SIZE (18U)
117
121#define IEEE802154_ACK_TIMEOUT_SYMS (54)
122
126#define IEEE802154_MR_OFDM_SYMBOL_TIME_US (120)
127
133#define IEEE802154_MR_FSK_SYMBOL_TIME_US (20)
134
140#define IEEE802154_RADIO_RSSI_OFFSET (-174)
141
142#define IEEE802154_PHY_MR_FSK_PHR_LEN (2)
143#define IEEE802154_PHY_MR_FSK_2FSK_SFD_LEN (2)
153#define IEEE802154_PHY_MR_FSK_2FSK_CODED_SFD_0 (0x6F4E)
154#define IEEE802154_PHY_MR_FSK_2FSK_CODED_SFD_1 (0x632D)
155#define IEEE802154_PHY_MR_FSK_2FSK_UNCODED_SFD_0 (0x90E4)
156#define IEEE802154_PHY_MR_FSK_2FSK_UNCODED_SFD_1 (0x7A0E)
165#define IEEE802154G_ATURNAROUNDTIME_US (1 * US_PER_MS)
166
171#define IEEE802154_ATURNAROUNDTIME_IN_SYMBOLS (12)
172
182#define IEEE802154_SYMBOL_TIME_US (16)
183
191#define IEEE802154_CCA_DURATION_IN_SYMBOLS (8)
192
207
216
228
238
248{
249 switch (srate) {
251 return 2;
253 return 3;
257 return 8;
259 return 10;
260 }
261
262 return 0;
263}
264
272#define IEEE802154_ADDR_BCAST { 0xff, 0xff }
273
277#define IEEE802154_ADDR_BCAST_LEN (IEEE802154_SHORT_ADDRESS_LEN)
278
294#if IS_ACTIVE(CONFIG_IEEE802154_DEFAULT_PHY_BPSK)
295#define CONFIG_IEEE802154_DEFAULT_PHY_MODE IEEE802154_PHY_BPSK
296#elif IS_ACTIVE(CONFIG_IEEE802154_DEFAULT_PHY_ASK)
297#define CONFIG_IEEE802154_DEFAULT_PHY_MODE IEEE802154_PHY_ASK
298#elif IS_ACTIVE(CONFIG_IEEE802154_DEFAULT_PHY_OQPSK)
299#define CONFIG_IEEE802154_DEFAULT_PHY_MODE IEEE802154_PHY_OQPSK
300#elif IS_ACTIVE(CONFIG_IEEE802154_DEFAULT_PHY_MR_OQPSK)
301#define CONFIG_IEEE802154_DEFAULT_PHY_MODE IEEE802154_PHY_MR_OQPSK
302#elif IS_ACTIVE(CONFIG_IEEE802154_DEFAULT_PHY_MR_OFDM)
303#define CONFIG_IEEE802154_DEFAULT_PHY_MODE IEEE802154_PHY_MR_OFDM
304#elif IS_ACTIVE(CONFIG_IEEE802154_DEFAULT_PHY_MR_FSK)
305#define CONFIG_IEEE802154_DEFAULT_PHY_MODE IEEE802154_PHY_MR_FSK
306#endif
307
308#ifndef CONFIG_IEEE802154_DEFAULT_PHY_MODE
309#define CONFIG_IEEE802154_DEFAULT_PHY_MODE IEEE802154_PHY_OQPSK
310#endif
315#ifndef CONFIG_IEEE802154_DEFAULT_SUBGHZ_CHANNEL
316#define CONFIG_IEEE802154_DEFAULT_SUBGHZ_CHANNEL (5U)
317#endif
318
322#ifndef CONFIG_IEEE802154_DEFAULT_CHANNEL
323#define CONFIG_IEEE802154_DEFAULT_CHANNEL (26U)
324#endif
325
329#ifndef CONFIG_IEEE802154_DEFAULT_SUBGHZ_PAGE
330#define CONFIG_IEEE802154_DEFAULT_SUBGHZ_PAGE (2U)
331#endif
332
336#ifndef CONFIG_IEEE802154_MR_OQPSK_DEFAULT_CHIPS
337#define CONFIG_IEEE802154_MR_OQPSK_DEFAULT_CHIPS IEEE802154_MR_OQPSK_CHIPS_1000
338#endif
339
343#ifndef CONFIG_IEEE802154_MR_OQPSK_DEFAULT_RATE
344#define CONFIG_IEEE802154_MR_OQPSK_DEFAULT_RATE (2U)
345#endif
346
350#ifndef CONFIG_IEEE802154_MR_OFDM_DEFAULT_OPTION
351#define CONFIG_IEEE802154_MR_OFDM_DEFAULT_OPTION (2U)
352#endif
353
357#ifndef CONFIG_IEEE802154_MR_OFDM_DEFAULT_SCHEME
358#define CONFIG_IEEE802154_MR_OFDM_DEFAULT_SCHEME (2U)
359#endif
360
364#ifndef CONFIG_IEEE802154_MR_FSK_DEFAULT_SRATE
365#define CONFIG_IEEE802154_MR_FSK_DEFAULT_SRATE IEEE802154_MR_FSK_SRATE_200K
366#endif
367
371#ifndef CONFIG_IEEE802154_MR_FSK_DEFAULT_MOD_IDX
372#define CONFIG_IEEE802154_MR_FSK_DEFAULT_MOD_IDX (64U)
373#endif
374
378#ifndef CONFIG_IEEE802154_MR_FSK_DEFAULT_MOD_ORD
379#define CONFIG_IEEE802154_MR_FSK_DEFAULT_MOD_ORD (2U)
380#endif
381
385#ifndef CONFIG_IEEE802154_MR_FSK_DEFAULT_FEC
386#define CONFIG_IEEE802154_MR_FSK_DEFAULT_FEC IEEE802154_FEC_NONE
387#endif
388
392#ifndef CONFIG_IEEE802154_DEFAULT_PANID
393#define CONFIG_IEEE802154_DEFAULT_PANID (0x0023U)
394#endif
395
399#ifndef IEEE802154_PANID_BCAST
400#define IEEE802154_PANID_BCAST { 0xff, 0xff }
401#endif
402
406#ifndef CONFIG_IEEE802154_DEFAULT_TXPOWER
407#define CONFIG_IEEE802154_DEFAULT_TXPOWER (0)
408#endif
414#ifndef CONFIG_IEEE802154_DEFAULT_CSMA_CA_MIN_BE
415#define CONFIG_IEEE802154_DEFAULT_CSMA_CA_MIN_BE (3U)
416#endif
417
421#ifndef CONFIG_IEEE802154_DEFAULT_CSMA_CA_RETRIES
422#define CONFIG_IEEE802154_DEFAULT_CSMA_CA_RETRIES (4U)
423#endif
424
428#ifndef CONFIG_IEEE802154_DEFAULT_CSMA_CA_MAX_BE
429#define CONFIG_IEEE802154_DEFAULT_CSMA_CA_MAX_BE (5U)
430#endif
431
435#ifndef CONFIG_IEEE802154_CCA_THRESH_DEFAULT
436#define CONFIG_IEEE802154_CCA_THRESH_DEFAULT (-70)
437#endif
438
442#ifndef CONFIG_IEEE802154_DEFAULT_MAX_FRAME_RETRANS
443#define CONFIG_IEEE802154_DEFAULT_MAX_FRAME_RETRANS (4U)
444#endif
445
449#ifdef DOXYGEN
450#define CONFIG_IEEE802154_AUTO_ACK_DISABLE 0
451#endif
452
456#ifndef CONFIG_IEEE802154_DEFAULT_ACK_REQ
457#define CONFIG_IEEE802154_DEFAULT_ACK_REQ 1
458#endif
459
465#ifndef CONFIG_IEEE802154_DSME_CAP_REDUCTION
466#define CONFIG_IEEE802154_DSME_CAP_REDUCTION 0
467#endif
468
478#ifndef CONFIG_IEEE802154_DSME_MAC_RESPONSE_WAIT_TIME
479#define CONFIG_IEEE802154_DSME_MAC_RESPONSE_WAIT_TIME (244U)
480#endif
481
490#ifndef CONFIG_IEEE802154_DSME_SCAN_DURATION
491#define CONFIG_IEEE802154_DSME_SCAN_DURATION (4U)
492#endif
493
505#ifndef CONFIG_IEEE802154_DSME_SUPERFRAME_ORDER
506#define CONFIG_IEEE802154_DSME_SUPERFRAME_ORDER (3U)
507#endif
508
518#ifndef CONFIG_IEEE802154_DSME_MULTISUPERFRAME_ORDER
519#define CONFIG_IEEE802154_DSME_MULTISUPERFRAME_ORDER (3U)
520#endif
521
531#ifndef CONFIG_IEEE802154_DSME_BEACON_ORDER
532#define CONFIG_IEEE802154_DSME_BEACON_ORDER (3U)
533#endif
534
545#ifdef DOXYGEN
546#define CONFIG_IEEE802154_DSME_STATIC_GTS 0
547#endif
548
557#ifndef CONFIG_IEEE802154_DSME_GTS_EXPIRATION
558#define CONFIG_IEEE802154_DSME_GTS_EXPIRATION (16U)
559#endif
560
566#ifndef CONFIG_IEEE802154_DSME_MIN_COORD_LQI
567#define CONFIG_IEEE802154_DSME_MIN_COORD_LQI (100U)
568#endif
569
613size_t ieee802154_set_frame_hdr(uint8_t *buf, const uint8_t *src, size_t src_len,
614 const uint8_t *dst, size_t dst_len,
615 le_uint16_t src_pan, le_uint16_t dst_pan,
616 uint8_t flags, uint8_t seq);
617
628size_t ieee802154_get_frame_hdr_len(const uint8_t *mhr);
629
642int ieee802154_get_src(const uint8_t *mhr, uint8_t *src, le_uint16_t *src_pan);
643
656int ieee802154_get_dst(const uint8_t *mhr, uint8_t *dst, le_uint16_t *dst_pan);
657
674int ieee802154_dst_filter(const uint8_t *mhr, uint16_t pan,
675 network_uint16_t short_addr, const eui64_t *ext_addr);
676
686static inline uint8_t ieee802154_get_seq(const uint8_t *mhr)
687{
688 return mhr[2];
689}
690
710static inline eui64_t *ieee802154_get_iid(eui64_t *eui64, const uint8_t *addr,
711 size_t addr_len)
712{
713 int i = 0;
714
715 eui64->uint8[0] = eui64->uint8[1] = 0;
716
717 switch (addr_len) {
718 case 8:
719 eui64->uint8[0] = addr[i++] ^ 0x02;
720 eui64->uint8[1] = addr[i++];
721 eui64->uint8[2] = addr[i++];
722 eui64->uint8[3] = addr[i++];
723 eui64->uint8[4] = addr[i++];
724 eui64->uint8[5] = addr[i++];
725 eui64->uint8[6] = addr[i++];
726 eui64->uint8[7] = addr[i++];
727 break;
728
729 case 4:
730 eui64->uint8[0] = addr[i++] ^ 0x02;
731 eui64->uint8[1] = addr[i++];
732
733 /* Falls through. */
734 case 2:
735 eui64->uint8[2] = 0;
736 eui64->uint8[3] = 0xff;
737 eui64->uint8[4] = 0xfe;
738 eui64->uint8[5] = 0;
739 eui64->uint8[6] = addr[i++];
740 eui64->uint8[7] = addr[i++];
741 break;
742
743 default:
744 return NULL;
745 }
746
747 return eui64;
748}
749
766static inline int16_t ieee802154_rssi_to_dbm(uint8_t rssi)
767{
768 return rssi + IEEE802154_RADIO_RSSI_OFFSET;
769}
770
784static inline uint8_t ieee802154_dbm_to_rssi(int16_t dbm)
785{
786 const int min = IEEE802154_RADIO_RSSI_OFFSET;
787 const int max = min + (UINT8_MAX - 1);
788
789 int val = dbm <= min ? min : (dbm >= max ? max : dbm);
790 return val - IEEE802154_RADIO_RSSI_OFFSET;
791}
792
793#ifdef __cplusplus
794}
795#endif
796
797#endif /* NET_IEEE802154_H */
Functions to work with different byte orders.
EUI-64 data type definition.
ieee802154_mr_oqpsk_chips_t
802.15.4 MR-OQPSK chip rates
Definition ieee802154.h:232
#define IEEE802154_ADDR_BCAST_LEN
Length in byte of IEEE802154_ADDR_BCAST.
Definition ieee802154.h:277
int ieee802154_get_src(const uint8_t *mhr, uint8_t *src, le_uint16_t *src_pan)
Gets source address from MAC header.
size_t ieee802154_get_frame_hdr_len(const uint8_t *mhr)
Get length of MAC header.
int ieee802154_get_dst(const uint8_t *mhr, uint8_t *dst, le_uint16_t *dst_pan)
Gets destination address from MAC header.
static uint8_t ieee802154_mr_fsk_plen(ieee802154_mr_fsk_srate_t srate)
Get the minimum preamble length for a given symbol rate.
Definition ieee802154.h:247
int ieee802154_dst_filter(const uint8_t *mhr, uint16_t pan, network_uint16_t short_addr, const eui64_t *ext_addr)
Check whether a frame pass the IEEE 802.15.4 frame filter.
ieee802154_mr_fsk_srate_t
802.15.4 MR-FSK symbol rates
Definition ieee802154.h:220
size_t ieee802154_set_frame_hdr(uint8_t *buf, const uint8_t *src, size_t src_len, const uint8_t *dst, size_t dst_len, le_uint16_t src_pan, le_uint16_t dst_pan, uint8_t flags, uint8_t seq)
Initializes an IEEE 802.15.4 MAC frame header in buf.
static uint8_t ieee802154_dbm_to_rssi(int16_t dbm)
Convert from dBm scale to RSSI.
Definition ieee802154.h:784
const uint8_t ieee802154_addr_bcast[IEEE802154_ADDR_BCAST_LEN]
Broadcast address.
static uint8_t ieee802154_get_seq(const uint8_t *mhr)
Gets sequence number from MAC header.
Definition ieee802154.h:686
static eui64_t * ieee802154_get_iid(eui64_t *eui64, const uint8_t *addr, size_t addr_len)
Generates an IPv6 interface identifier from an IEEE 802.15.4 address.
Definition ieee802154.h:710
ieee802154_phy_mode_t
802.15.4 PHY modes
Definition ieee802154.h:196
static int16_t ieee802154_rssi_to_dbm(uint8_t rssi)
Convert from RSSI scale to dBm.
Definition ieee802154.h:766
#define IEEE802154_RADIO_RSSI_OFFSET
value of measured power when RSSI is zero.
Definition ieee802154.h:140
ieee802154_mr_fsk_fec_t
802.15.4 forward error correction schemes
Definition ieee802154.h:211
@ IEEE802154_MR_OQPSK_CHIPS_100
100 kChip/s
Definition ieee802154.h:233
@ IEEE802154_MR_OQPSK_CHIPS_200
200 kChip/s
Definition ieee802154.h:234
@ IEEE802154_MR_OQPSK_CHIPS_2000
2000 kChip/s
Definition ieee802154.h:236
@ IEEE802154_MR_OQPSK_CHIPS_1000
1000 kChip/s
Definition ieee802154.h:235
@ IEEE802154_MR_FSK_SRATE_50K
50k Symbols/s
Definition ieee802154.h:221
@ IEEE802154_MR_FSK_SRATE_100K
100k Symbols/s
Definition ieee802154.h:222
@ IEEE802154_MR_FSK_SRATE_400K
400k Symbols/s
Definition ieee802154.h:226
@ IEEE802154_MR_FSK_SRATE_150K
150k Symbols/s
Definition ieee802154.h:223
@ IEEE802154_MR_FSK_SRATE_200K
200k Symbols/s
Definition ieee802154.h:224
@ IEEE802154_MR_FSK_SRATE_300K
300k Symbols/s
Definition ieee802154.h:225
@ IEEE802154_PHY_BPSK
Binary Phase Shift Keying.
Definition ieee802154.h:198
@ IEEE802154_PHY_MR_OFDM
Multi-Rate Orthogonal Frequency-Division Multiplexing.
Definition ieee802154.h:202
@ IEEE802154_PHY_OQPSK
Offset Quadrature Phase-Shift Keying.
Definition ieee802154.h:200
@ IEEE802154_PHY_ASK
Amplitude-Shift Keying.
Definition ieee802154.h:199
@ IEEE802154_PHY_MR_FSK
Multi-Rate Frequency Shift Keying.
Definition ieee802154.h:203
@ IEEE802154_PHY_DISABLED
PHY disabled, no mode selected.
Definition ieee802154.h:197
@ IEEE802154_PHY_MR_OQPSK
Multi-Rate Offset Quadrature Phase-Shift Keying.
Definition ieee802154.h:201
@ IEEE802154_PHY_NO_OP
don't change PHY configuration
Definition ieee802154.h:205
@ IEEE802154_FEC_RSC
recursive and systematic code
Definition ieee802154.h:214
@ IEEE802154_FEC_NRNSC
non-recursive and non-systematic code
Definition ieee802154.h:213
@ IEEE802154_FEC_NONE
no forward error correction
Definition ieee802154.h:212
Common macros and compiler attributes/pragmas configuration.
Utility header providing time unit defines.
A 16 bit integer in big endian aka network byte order.
Definition byteorder.h:74
Data type to represent an EUI-64.
Definition eui64.h:55
uint8_t uint8[8]
split into 8 8-bit words.
Definition eui64.h:57
A 16 bit integer in little endian.
Definition byteorder.h:38