11#include "esp_assert.h"
12#include "esp_ieee802154.h"
15#define IEEE802154_FCF_SIZE 2
16#define IEEE802154_MAX_ADDR_LEN 8
17#define IEEE802154_PAN_ID_LEN 2
18#define IEEE802154_RSSI_LQI_SIZE 1
20#define MAX_FRAME_LEN 128
104 static_assert(N == 2 || N == 8,
"Address must be 2 or 8 bytes");
105 if constexpr (N == 2) {
108 }
else if constexpr (N == 8) {
138 static const char*
to_str(
const uint8_t* addr,
int len) {
141 snprintf(str,
sizeof(str),
"%02X:%02X", addr[0], addr[1]);
142 }
else if (len == 8) {
143 snprintf(str,
sizeof(str),
"%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
144 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], addr[6],
147 snprintf(str,
sizeof(str),
"Invalid");
197 bool parse(
const uint8_t* data,
bool verbose);
203 const char*
to_str(uint8_t frameType);
223 if (
buffer.size() < len) {
251 "ieee802154_fcf_t must be 2 bytes");
#define IEEE802154_FCF_SIZE
Definition Frame.h:15
#define MAX_FRAME_LEN
Definition Frame.h:20
IEEE 802.15.4 Address abstraction.
Definition Frame.h:77
Address(const uint8_t *addr, addr_mode_t mode)
Construct an Address from a pointer and mode.
Definition Frame.h:88
Address(const uint8_t(&addr)[N])
Template constructor to deduce address length and mode at compile time.
Definition Frame.h:103
addr_mode_t mode()
Get the address mode (NONE, SHORT, EXTENDED).
Definition Frame.h:124
addr_mode_t local_addr_mode
Local address mode (NONE, SHORT, EXTENDED).
Definition Frame.h:175
Address()=default
Default constructor. Initializes address mode to NONE.
static const char * to_str(const uint8_t *addr, int len)
Get a human-readable string for a raw address and length.
Definition Frame.h:138
uint8_t * data()
Get a pointer to the address bytes.
Definition Frame.h:118
static const char * to_str(const uint8_t *addr, addr_mode_t mode)
Get a human-readable string for a raw address and mode.
Definition Frame.h:158
uint8_t local_address[8]
Local address bytes (0, 2, or 8 bytes used).
Definition Frame.h:179
const char * to_str() const
Get a human-readable string representation of the address.
Definition Frame.h:130
Definition ESP32TransceiverIEEE802_15_4.cpp:15
frame_version_t
IEEE 802.15.4 frame version enumerations.
Definition Frame.h:42
addr_mode_t
IEEE 802.15.4 address mode enumerations.
Definition Frame.h:34
ESP_STATIC_ASSERT(sizeof(FrameControlField)==IEEE802154_FCF_SIZE, "ieee802154_fcf_t must be 2 bytes")
Frameype_t
IEEE 802.15.4 FCF field value enumerations.
Definition Frame.h:25
IEEE 802.15.4 Frame Control Field (FCF) structure Bit fields are ordered LSB to MSB to match IEEE 802...
Definition Frame.h:53
uint8_t informationElementsPresent
Definition Frame.h:63
uint8_t frameType
Definition Frame.h:54
uint8_t destAddrMode
Definition Frame.h:64
uint8_t framePending
Definition Frame.h:56
uint8_t frameVersion
Definition Frame.h:66
uint8_t panIdCompression
Definition Frame.h:58
uint8_t srcAddrMode
Definition Frame.h:67
uint8_t reserved
Definition Frame.h:59
uint8_t securityEnabled
Definition Frame.h:55
uint8_t sequenceNumberSuppression
Definition Frame.h:61
uint8_t ackRequest
Definition Frame.h:57
IEEE 802.15.4 MAC frame structure.
Definition Frame.h:183
void setDestinationAddress(Address address)
Set the destination address for the frame.
Definition Frame.h:214
uint8_t rssi_lqi
Definition Frame.h:194
uint16_t srcPanId
Definition Frame.h:188
uint8_t sequenceNumber
Definition Frame.h:185
uint8_t srcAddrLen
Definition Frame.h:191
uint8_t srcAddress[8]
Definition Frame.h:189
uint8_t * payload
Definition Frame.h:193
FrameControlField fcf
Definition Frame.h:184
void setPayload(const uint8_t *data, size_t len)
Set the payload for the frame.
Definition Frame.h:222
size_t build(uint8_t *buffer, bool verbose) const
Build IEEE 802.15.4 frame array with length byte at start and 0x00 at end.
Definition Frame.cpp:284
size_t payloadLen
Definition Frame.h:192
uint8_t destAddrLen
Definition Frame.h:190
const char * to_str(uint8_t frameType)
Get a human-readable string representation of the frame.
Definition Frame.cpp:378
uint16_t destPanId
Definition Frame.h:186
void setPAN(uint16_t panId)
Defines the Personal Area Network Identifier (PAN ID) for the frame.
Definition Frame.h:232
uint8_t destAddress[8]
Definition Frame.h:187
bool parse(const uint8_t *data, bool verbose)
parse frame from raw data
Definition Frame.cpp:127
std::vector< uint8_t > buffer
Definition Frame.h:239
void setSourceAddress(Address address)
Set the source address for the frame.
Definition Frame.h:206
Structure to hold frame data and frame info.
Definition Frame.h:243
esp_ieee802154_frame_info_t frame_info
Definition Frame.h:245
uint8_t frame[MAX_FRAME_LEN]
Definition Frame.h:244