2016-06-16 16:00:11 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation.
|
|
|
|
*
|
2017-01-19 02:01:01 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-06-16 16:00:11 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief IEEE 802.15.4 Frame API header
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __IEEE802154_FRAME_H__
|
|
|
|
#define __IEEE802154_FRAME_H__
|
|
|
|
|
2016-11-09 21:07:51 +01:00
|
|
|
#include <kernel.h>
|
2017-04-03 17:14:35 +02:00
|
|
|
#include <net/net_pkt.h>
|
2017-12-07 10:13:56 +01:00
|
|
|
#include <net/ieee802154.h>
|
2019-09-09 14:45:22 +02:00
|
|
|
#include <toolchain.h>
|
2017-12-07 10:13:56 +01:00
|
|
|
|
2016-06-16 16:00:11 +02:00
|
|
|
#define IEEE802154_MTU 127
|
2017-03-22 14:37:25 +01:00
|
|
|
#define IEEE802154_MIN_LENGTH 3
|
2016-06-16 16:00:11 +02:00
|
|
|
/* See Section 5.2.1.4 */
|
|
|
|
#define IEEE802154_BROADCAST_ADDRESS 0xFFFF
|
2016-10-10 14:55:53 +02:00
|
|
|
#define IEEE802154_BROADCAST_PAN_ID 0xFFFF
|
2016-06-16 16:00:11 +02:00
|
|
|
/* ACK packet size is the minimum size, see Section 5.2.2.3 */
|
|
|
|
#define IEEE802154_ACK_PKT_LENGTH IEEE802154_MIN_LENGTH
|
|
|
|
#define IEEE802154_MFR_LENGTH 2
|
|
|
|
|
2020-04-30 10:22:25 +02:00
|
|
|
#define IEEE802154_FCF_SEQ_LENGTH 3
|
2016-06-16 16:00:11 +02:00
|
|
|
#define IEEE802154_EXT_ADDR_LENGTH 8
|
|
|
|
#define IEEE802154_SHORT_ADDR_LENGTH 2
|
2016-08-17 15:05:47 +02:00
|
|
|
#define IEEE802154_SIMPLE_ADDR_LENGTH 1
|
2016-06-16 16:00:11 +02:00
|
|
|
#define IEEE802154_PAN_ID_LENGTH 2
|
|
|
|
|
2016-08-30 11:23:22 +02:00
|
|
|
#define IEEE802154_BEACON_MIN_SIZE 4
|
|
|
|
#define IEEE802154_BEACON_SF_SIZE 2
|
|
|
|
#define IEEE802154_BEACON_GTS_SPEC_SIZE 1
|
|
|
|
#define IEEE802154_BEACON_GTS_IF_MIN_SIZE IEEE802154_BEACON_GTS_SPEC_SIZE
|
|
|
|
#define IEEE802154_BEACON_PAS_SPEC_SIZE 1
|
|
|
|
#define IEEE802154_BEACON_PAS_IF_MIN_SIZE IEEE802154_BEACON_PAS_SPEC_SIZE
|
|
|
|
#define IEEE802154_BEACON_GTS_DIR_SIZE 1
|
|
|
|
#define IEEE802154_BEACON_GTS_SIZE 3
|
|
|
|
#define IEEE802154_BEACON_GTS_RX 1
|
|
|
|
#define IEEE802154_BEACON_GTS_TX 0
|
|
|
|
|
2016-06-16 16:00:11 +02:00
|
|
|
/* See Section 5.2.1.1.1 */
|
|
|
|
enum ieee802154_frame_type {
|
|
|
|
IEEE802154_FRAME_TYPE_BEACON = 0x0,
|
|
|
|
IEEE802154_FRAME_TYPE_DATA = 0x1,
|
|
|
|
IEEE802154_FRAME_TYPE_ACK = 0x2,
|
|
|
|
IEEE802154_FRAME_TYPE_MAC_COMMAND = 0x3,
|
2016-08-17 15:05:47 +02:00
|
|
|
IEEE802154_FRAME_TYPE_LLDN = 0x4,
|
|
|
|
IEEE802154_FRAME_TYPE_MULTIPURPOSE = 0x5,
|
|
|
|
IEEE802154_FRAME_TYPE_RESERVED = 0x6,
|
2016-06-16 16:00:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* See Section 5.2.1.1.6 */
|
|
|
|
enum ieee802154_addressing_mode {
|
|
|
|
IEEE802154_ADDR_MODE_NONE = 0x0,
|
2016-08-17 15:05:47 +02:00
|
|
|
IEEE802154_ADDR_MODE_SIMPLE = 0x1,
|
2016-06-16 16:00:11 +02:00
|
|
|
IEEE802154_ADDR_MODE_SHORT = 0x2,
|
|
|
|
IEEE802154_ADDR_MODE_EXTENDED = 0x3,
|
|
|
|
};
|
|
|
|
|
2016-08-17 15:05:47 +02:00
|
|
|
/** Versions 2003/2006 do no support simple addressing mode */
|
|
|
|
#define IEEE802154_ADDR_MODE_RESERVED IEEE802154_ADDR_MODE_SIMPLE
|
|
|
|
|
2016-06-16 16:00:11 +02:00
|
|
|
/* See Section 5.2.1.1.7 */
|
|
|
|
enum ieee802154_version {
|
|
|
|
IEEE802154_VERSION_802154_2003 = 0x0,
|
2016-08-17 15:05:47 +02:00
|
|
|
IEEE802154_VERSION_802154_2006 = 0x1,
|
|
|
|
IEEE802154_VERSION_802154 = 0x2,
|
|
|
|
IEEE802154_VERSION_RESERVED = 0x3,
|
2016-06-16 16:00:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Frame Control Field and sequence number
|
|
|
|
* See Section 5.2.1.1
|
|
|
|
*/
|
|
|
|
struct ieee802154_fcf_seq {
|
|
|
|
struct {
|
2016-11-21 16:16:26 +01:00
|
|
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t frame_type :3;
|
|
|
|
uint16_t security_enabled :1;
|
|
|
|
uint16_t frame_pending :1;
|
|
|
|
uint16_t ar :1;
|
|
|
|
uint16_t pan_id_comp :1;
|
|
|
|
uint16_t reserved :1;
|
|
|
|
uint16_t seq_num_suppr :1;
|
|
|
|
uint16_t ie_list :1;
|
|
|
|
uint16_t dst_addr_mode :2;
|
|
|
|
uint16_t frame_version :2;
|
|
|
|
uint16_t src_addr_mode :2;
|
2016-11-21 16:16:26 +01:00
|
|
|
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t reserved :1;
|
|
|
|
uint16_t pan_id_comp :1;
|
|
|
|
uint16_t ar :1;
|
|
|
|
uint16_t frame_pending :1;
|
|
|
|
uint16_t security_enabled :1;
|
|
|
|
uint16_t frame_type :3;
|
|
|
|
uint16_t src_addr_mode :2;
|
|
|
|
uint16_t frame_version :2;
|
|
|
|
uint16_t dst_addr_mode :2;
|
|
|
|
uint16_t ie_list :1;
|
|
|
|
uint16_t seq_num_suppr :1;
|
2016-11-21 16:16:26 +01:00
|
|
|
#endif
|
2016-06-16 16:00:11 +02:00
|
|
|
} fc __packed;
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t sequence;
|
2016-06-16 16:00:11 +02:00
|
|
|
} __packed;
|
|
|
|
|
|
|
|
struct ieee802154_address {
|
|
|
|
union {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t simple_addr;
|
|
|
|
uint16_t short_addr;
|
|
|
|
uint8_t ext_addr[0];
|
2016-06-16 16:00:11 +02:00
|
|
|
};
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
struct ieee802154_address_field_comp {
|
|
|
|
struct ieee802154_address addr;
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
struct ieee802154_address_field_plain {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t pan_id;
|
2016-06-16 16:00:11 +02:00
|
|
|
struct ieee802154_address addr;
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
struct ieee802154_address_field {
|
|
|
|
union {
|
|
|
|
struct ieee802154_address_field_plain plain;
|
|
|
|
struct ieee802154_address_field_comp comp;
|
|
|
|
};
|
|
|
|
} __packed;
|
|
|
|
|
2017-01-17 10:12:38 +01:00
|
|
|
/* See Section 7.4.1.1 */
|
|
|
|
enum ieee802154_security_level {
|
|
|
|
IEEE802154_SECURITY_LEVEL_NONE = 0x0,
|
|
|
|
IEEE802154_SECURITY_LEVEL_MIC_32 = 0x1,
|
|
|
|
IEEE802154_SECURITY_LEVEL_MIC_64 = 0x2,
|
|
|
|
IEEE802154_SECURITY_LEVEL_MIC_128 = 0x3,
|
|
|
|
IEEE802154_SECURITY_LEVEL_ENC = 0x4,
|
|
|
|
IEEE802154_SECURITY_LEVEL_ENC_MIC_32 = 0x5,
|
|
|
|
IEEE802154_SECURITY_LEVEL_ENC_MIC_64 = 0x6,
|
|
|
|
IEEE802154_SECURITY_LEVEL_ENC_MIC_128 = 0x7,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* This will match above *_MIC_<32/64/128> */
|
|
|
|
#define IEEE8021254_AUTH_TAG_LENGTH_32 4
|
|
|
|
#define IEEE8021254_AUTH_TAG_LENGTH_64 8
|
|
|
|
#define IEEE8021254_AUTH_TAG_LENGTH_128 16
|
|
|
|
|
|
|
|
/* See Section 7.4.1.2 */
|
|
|
|
enum ieee802154_key_id_mode {
|
|
|
|
IEEE802154_KEY_ID_MODE_IMPLICIT = 0x0,
|
|
|
|
IEEE802154_KEY_ID_MODE_INDEX = 0x1,
|
|
|
|
IEEE802154_KEY_ID_MODE_SRC_4_INDEX = 0x2,
|
|
|
|
IEEE802154_KEY_ID_MODE_SRC_8_INDEX = 0x3,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define IEEE8021254_KEY_ID_FIELD_INDEX_LENGTH 1
|
|
|
|
#define IEEE8021254_KEY_ID_FIELD_SRC_4_INDEX_LENGTH 5
|
|
|
|
#define IEEE8021254_KEY_ID_FIELD_SRC_8_INDEX_LENGTH 9
|
|
|
|
|
|
|
|
#define IEEE802154_KEY_MAX_LEN 16
|
|
|
|
|
|
|
|
/* See Section 7.4.1 */
|
|
|
|
struct ieee802154_security_control_field {
|
|
|
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t security_level :3;
|
|
|
|
uint8_t key_id_mode :2;
|
|
|
|
uint8_t reserved :3;
|
2017-01-17 10:12:38 +01:00
|
|
|
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t reserved :3;
|
|
|
|
uint8_t key_id_mode :2;
|
|
|
|
uint8_t security_level :3;
|
2017-01-17 10:12:38 +01:00
|
|
|
#endif
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
#define IEEE802154_SECURITY_CF_LENGTH 1
|
|
|
|
|
|
|
|
/* See Section 7.4.3 */
|
|
|
|
struct ieee802154_key_identifier_field {
|
|
|
|
union {
|
|
|
|
/* mode_0 being implicit, it holds no info here */
|
|
|
|
struct {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t key_index;
|
2017-01-17 10:12:38 +01:00
|
|
|
} mode_1;
|
|
|
|
|
|
|
|
struct {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t key_src[4];
|
|
|
|
uint8_t key_index;
|
2017-01-17 10:12:38 +01:00
|
|
|
} mode_2;
|
|
|
|
|
|
|
|
struct {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t key_src[8];
|
|
|
|
uint8_t key_index;
|
2017-01-17 10:12:38 +01:00
|
|
|
} mode_3;
|
|
|
|
};
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Auxiliary Security Header
|
|
|
|
* See Section 7.4
|
|
|
|
*/
|
|
|
|
struct ieee802154_aux_security_hdr {
|
|
|
|
struct ieee802154_security_control_field control;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t frame_counter;
|
2017-01-17 10:12:38 +01:00
|
|
|
struct ieee802154_key_identifier_field kif;
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
#define IEEE802154_SECURITY_FRAME_COUNTER_LENGTH 4
|
|
|
|
|
2016-06-16 16:00:11 +02:00
|
|
|
/** MAC header */
|
|
|
|
struct ieee802154_mhr {
|
|
|
|
struct ieee802154_fcf_seq *fs;
|
|
|
|
struct ieee802154_address_field *dst_addr;
|
|
|
|
struct ieee802154_address_field *src_addr;
|
2017-01-17 11:31:12 +01:00
|
|
|
#ifdef CONFIG_NET_L2_IEEE802154_SECURITY
|
2017-01-17 10:12:38 +01:00
|
|
|
struct ieee802154_aux_security_hdr *aux_sec;
|
2017-01-17 11:31:12 +01:00
|
|
|
#endif
|
2016-06-16 16:00:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ieee802154_mfr {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t fcs;
|
2016-06-16 16:00:11 +02:00
|
|
|
};
|
|
|
|
|
2016-08-30 11:23:22 +02:00
|
|
|
struct ieee802154_gts_dir {
|
2016-11-21 16:16:26 +01:00
|
|
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t mask : 7;
|
|
|
|
uint8_t reserved : 1;
|
2016-11-21 16:16:26 +01:00
|
|
|
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t reserved : 1;
|
|
|
|
uint8_t mask : 7;
|
2016-11-21 16:16:26 +01:00
|
|
|
#endif
|
2016-08-30 11:23:22 +02:00
|
|
|
} __packed;
|
|
|
|
|
|
|
|
struct ieee802154_gts {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t short_address;
|
2016-11-21 16:16:26 +01:00
|
|
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t starting_slot : 4;
|
|
|
|
uint8_t length : 4;
|
2016-11-21 16:16:26 +01:00
|
|
|
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t length : 4;
|
|
|
|
uint8_t starting_slot : 4;
|
2016-11-21 16:16:26 +01:00
|
|
|
#endif
|
2016-08-30 11:23:22 +02:00
|
|
|
} __packed;
|
|
|
|
|
|
|
|
struct ieee802154_gts_spec {
|
2016-11-21 16:16:26 +01:00
|
|
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
2016-08-30 11:23:22 +02:00
|
|
|
/* Descriptor Count */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t desc_count : 3;
|
|
|
|
uint8_t reserved : 4;
|
2016-08-30 11:23:22 +02:00
|
|
|
/* GTS Permit */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t permit : 1;
|
2016-11-21 16:16:26 +01:00
|
|
|
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
|
|
|
/* GTS Permit */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t permit : 1;
|
|
|
|
uint8_t reserved : 4;
|
2016-11-21 16:16:26 +01:00
|
|
|
/* Descriptor Count */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t desc_count : 3;
|
2016-11-21 16:16:26 +01:00
|
|
|
#endif
|
2016-08-30 11:23:22 +02:00
|
|
|
} __packed;
|
|
|
|
|
|
|
|
struct ieee802154_pas_spec {
|
2016-11-21 16:16:26 +01:00
|
|
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
2016-08-30 11:23:22 +02:00
|
|
|
/* Number of Short Addresses Pending */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t nb_sap : 3;
|
|
|
|
uint8_t reserved_1 : 1;
|
2016-08-30 11:23:22 +02:00
|
|
|
/* Number of Extended Addresses Pending */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t nb_eap : 3;
|
|
|
|
uint8_t reserved_2 : 1;
|
2016-11-21 16:16:26 +01:00
|
|
|
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t reserved_1 : 1;
|
2016-11-21 16:16:26 +01:00
|
|
|
/* Number of Extended Addresses Pending */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t nb_eap : 3;
|
|
|
|
uint8_t reserved_2 : 1;
|
2016-11-21 16:16:26 +01:00
|
|
|
/* Number of Short Addresses Pending */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t nb_sap : 3;
|
2016-11-21 16:16:26 +01:00
|
|
|
#endif
|
2016-08-30 11:23:22 +02:00
|
|
|
} __packed;
|
|
|
|
|
|
|
|
struct ieee802154_beacon_sf {
|
2016-11-21 16:16:26 +01:00
|
|
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
2016-08-30 11:23:22 +02:00
|
|
|
/* Beacon Order*/
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t bc_order : 4;
|
2016-08-30 11:23:22 +02:00
|
|
|
/* Superframe Order*/
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t sf_order : 4;
|
2016-08-30 11:23:22 +02:00
|
|
|
/* Final CAP Slot */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t cap_slot : 4;
|
2016-08-30 11:23:22 +02:00
|
|
|
/* Battery Life Extension */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t ble : 1;
|
|
|
|
uint16_t reserved : 1;
|
2016-08-30 11:23:22 +02:00
|
|
|
/* PAN Coordinator */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t coordinator : 1;
|
2016-08-30 11:23:22 +02:00
|
|
|
/* Association Permit */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t association : 1;
|
2016-11-21 16:16:26 +01:00
|
|
|
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
|
|
|
/* Superframe Order*/
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t sf_order : 4;
|
2016-11-21 16:16:26 +01:00
|
|
|
/* Beacon Order*/
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t bc_order : 4;
|
2016-11-21 16:16:26 +01:00
|
|
|
/* Association Permit */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t association : 1;
|
2016-11-21 16:16:26 +01:00
|
|
|
/* PAN Coordinator */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t coordinator : 1;
|
|
|
|
uint16_t reserved : 1;
|
2016-11-21 16:16:26 +01:00
|
|
|
/* Battery Life Extension */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t ble : 1;
|
2016-11-21 16:16:26 +01:00
|
|
|
/* Final CAP Slot */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t cap_slot : 4;
|
2016-11-21 16:16:26 +01:00
|
|
|
#endif
|
2016-08-30 11:23:22 +02:00
|
|
|
} __packed;
|
|
|
|
|
|
|
|
struct ieee802154_beacon {
|
|
|
|
struct ieee802154_beacon_sf sf;
|
|
|
|
|
|
|
|
/* GTS Fields - Spec is always there */
|
|
|
|
struct ieee802154_gts_spec gts;
|
|
|
|
} __packed;
|
|
|
|
|
2016-10-10 13:00:58 +02:00
|
|
|
/* See Section 5.3.1 */
|
|
|
|
struct ieee802154_cmd_assoc_req {
|
|
|
|
struct {
|
2016-11-21 16:16:26 +01:00
|
|
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t reserved_1 : 1;
|
|
|
|
uint8_t dev_type : 1;
|
|
|
|
uint8_t power_src : 1;
|
|
|
|
uint8_t rx_on : 1;
|
|
|
|
uint8_t reserved_2 : 2;
|
|
|
|
uint8_t sec_capability : 1;
|
|
|
|
uint8_t alloc_addr : 1;
|
2016-11-21 16:16:26 +01:00
|
|
|
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t alloc_addr : 1;
|
|
|
|
uint8_t sec_capability : 1;
|
|
|
|
uint8_t reserved_2 : 2;
|
|
|
|
uint8_t rx_on : 1;
|
|
|
|
uint8_t power_src : 1;
|
|
|
|
uint8_t dev_type : 1;
|
|
|
|
uint8_t reserved_1 : 1;
|
2016-11-21 16:16:26 +01:00
|
|
|
#endif
|
2016-10-10 13:00:58 +02:00
|
|
|
} ci;
|
|
|
|
} __packed;
|
|
|
|
|
2020-04-30 10:22:25 +02:00
|
|
|
#define IEEE802154_CMD_ASSOC_REQ_LENGTH 1
|
|
|
|
|
2016-10-10 13:00:58 +02:00
|
|
|
/* See Section 5.3.2 */
|
|
|
|
enum ieee802154_association_status_field {
|
|
|
|
IEEE802154_ASF_SUCCESSFUL = 0x00,
|
|
|
|
IEEE802154_ASF_PAN_AT_CAPACITY = 0x01,
|
|
|
|
IEEE802154_ASF_PAN_ACCESS_DENIED = 0x02,
|
|
|
|
IEEE802154_ASF_RESERVED = 0x03,
|
|
|
|
IEEE802154_ASF_RESERVED_PRIMITIVES = 0x80,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ieee802154_cmd_assoc_res {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t short_addr;
|
|
|
|
uint8_t status;
|
2016-10-10 13:00:58 +02:00
|
|
|
} __packed;
|
|
|
|
|
2020-04-30 10:22:25 +02:00
|
|
|
#define IEEE802154_CMD_ASSOC_RES_LENGTH 3
|
|
|
|
|
2016-10-10 13:00:58 +02:00
|
|
|
/* See Section 5.3.3 */
|
|
|
|
enum ieee802154_disassociation_reason_field {
|
|
|
|
IEEE802154_DRF_RESERVED_1 = 0x00,
|
|
|
|
IEEE802154_DRF_COORDINATOR_WISH = 0x01,
|
|
|
|
IEEE802154_DRF_DEVICE_WISH = 0x02,
|
|
|
|
IEEE802154_DRF_RESERVED_2 = 0x03,
|
|
|
|
IEEE802154_DRF_RESERVED_PRIMITIVES = 0x80,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ieee802154_cmd_disassoc_note {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t reason;
|
2016-10-10 13:00:58 +02:00
|
|
|
} __packed;
|
|
|
|
|
2020-04-30 10:22:25 +02:00
|
|
|
#define IEEE802154_CMD_DISASSOC_NOTE_LENGTH 1
|
|
|
|
|
2016-10-10 13:00:58 +02:00
|
|
|
/* See Section 5.3.8 */
|
|
|
|
struct ieee802154_cmd_coord_realign {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t pan_id;
|
|
|
|
uint16_t coordinator_short_addr;
|
|
|
|
uint8_t channel;
|
|
|
|
uint16_t short_addr;
|
|
|
|
uint8_t channel_page; /* Optional */
|
2016-10-10 13:00:58 +02:00
|
|
|
} __packed;
|
|
|
|
|
2020-04-30 10:22:25 +02:00
|
|
|
#define IEEE802154_CMD_COORD_REALIGN_LENGTH 3
|
|
|
|
|
2016-10-10 13:00:58 +02:00
|
|
|
/* See Section 5.3.9 */
|
|
|
|
struct ieee802154_gts_request {
|
|
|
|
struct {
|
2016-11-21 16:16:26 +01:00
|
|
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t length : 4;
|
|
|
|
uint8_t direction : 1;
|
|
|
|
uint8_t type : 1;
|
|
|
|
uint8_t reserved : 2;
|
2016-11-21 16:16:26 +01:00
|
|
|
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t reserved : 2;
|
|
|
|
uint8_t type : 1;
|
|
|
|
uint8_t direction : 1;
|
|
|
|
uint8_t length : 4;
|
2016-11-21 16:16:26 +01:00
|
|
|
#endif
|
2016-10-10 13:00:58 +02:00
|
|
|
} gts;
|
|
|
|
} __packed;
|
|
|
|
|
2020-04-30 10:22:25 +02:00
|
|
|
#define IEEE802154_GTS_REQUEST_LENGTH 1
|
|
|
|
|
2016-10-10 13:00:58 +02:00
|
|
|
/* See Section 5.3 */
|
|
|
|
enum ieee802154_cfi {
|
|
|
|
IEEE802154_CFI_UNKNOWN = 0x00,
|
|
|
|
IEEE802154_CFI_ASSOCIATION_REQUEST = 0x01,
|
|
|
|
IEEE802154_CFI_ASSOCIATION_RESPONSE = 0x02,
|
|
|
|
IEEE802154_CFI_DISASSOCIATION_NOTIFICATION = 0x03,
|
|
|
|
IEEE802154_CFI_DATA_REQUEST = 0x04,
|
|
|
|
IEEE802154_CFI_PAN_ID_CONLICT_NOTIFICATION = 0x05,
|
|
|
|
IEEE802154_CFI_ORPHAN_NOTIFICATION = 0x06,
|
|
|
|
IEEE802154_CFI_BEACON_REQUEST = 0x07,
|
|
|
|
IEEE802154_CFI_COORDINATOR_REALIGNEMENT = 0x08,
|
|
|
|
IEEE802154_CFI_GTS_REQUEST = 0x09,
|
|
|
|
IEEE802154_CFI_RESERVED = 0x0a,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ieee802154_command {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t cfi;
|
2016-10-10 13:00:58 +02:00
|
|
|
union {
|
|
|
|
struct ieee802154_cmd_assoc_req assoc_req;
|
|
|
|
struct ieee802154_cmd_assoc_res assoc_res;
|
|
|
|
struct ieee802154_cmd_disassoc_note disassoc_note;
|
|
|
|
struct ieee802154_cmd_coord_realign coord_realign;
|
|
|
|
struct ieee802154_gts_request gts_request;
|
|
|
|
/* Data request, PAN ID conflict, Orphan notification
|
|
|
|
* or Beacon request do not provide more than the CIF.
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
} __packed;
|
|
|
|
|
2020-04-30 10:22:25 +02:00
|
|
|
#define IEEE802154_CMD_CFI_LENGTH 1
|
|
|
|
|
2016-06-16 16:00:11 +02:00
|
|
|
/** Frame */
|
|
|
|
struct ieee802154_mpdu {
|
|
|
|
struct ieee802154_mhr mhr;
|
2016-08-30 11:23:22 +02:00
|
|
|
union {
|
|
|
|
void *payload;
|
|
|
|
struct ieee802154_beacon *beacon;
|
2016-10-10 13:00:58 +02:00
|
|
|
struct ieee802154_command *command;
|
2016-08-30 11:23:22 +02:00
|
|
|
};
|
2016-06-16 16:00:11 +02:00
|
|
|
struct ieee802154_mfr *mfr;
|
|
|
|
} __packed;
|
|
|
|
|
2016-10-18 10:00:57 +02:00
|
|
|
/** Frame build parameters */
|
|
|
|
struct ieee802154_frame_params {
|
|
|
|
struct {
|
|
|
|
union {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t *ext_addr;
|
|
|
|
uint16_t short_addr;
|
2016-10-18 10:00:57 +02:00
|
|
|
};
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t len;
|
|
|
|
uint16_t pan_id;
|
2016-10-18 10:00:57 +02:00
|
|
|
} dst;
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t short_addr;
|
|
|
|
uint16_t pan_id;
|
2016-10-18 10:00:57 +02:00
|
|
|
} __packed;
|
|
|
|
|
2017-03-10 14:43:37 +01:00
|
|
|
#ifdef CONFIG_NET_L2_IEEE802154_SECURITY
|
|
|
|
struct ieee802154_aux_security_hdr *
|
2020-05-27 18:26:57 +02:00
|
|
|
ieee802154_validate_aux_security_hdr(uint8_t *buf, uint8_t **p_buf, uint8_t *length);
|
2017-03-10 14:43:37 +01:00
|
|
|
#endif
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
struct ieee802154_fcf_seq *ieee802154_validate_fc_seq(uint8_t *buf, uint8_t **p_buf,
|
|
|
|
uint8_t *length);
|
2017-06-16 09:22:47 +02:00
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
bool ieee802154_validate_frame(uint8_t *buf, uint8_t length,
|
2016-06-16 16:00:11 +02:00
|
|
|
struct ieee802154_mpdu *mpdu);
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t ieee802154_compute_header_size(struct net_if *iface,
|
2018-10-24 15:08:50 +02:00
|
|
|
struct in6_addr *dst);
|
2016-06-16 16:00:11 +02:00
|
|
|
|
2017-03-28 08:33:43 +02:00
|
|
|
bool ieee802154_create_data_frame(struct ieee802154_context *ctx,
|
2017-03-09 11:48:26 +01:00
|
|
|
struct net_linkaddr *dst,
|
2017-01-18 14:18:05 +01:00
|
|
|
struct net_buf *frag,
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t hdr_size);
|
2016-06-16 16:00:11 +02:00
|
|
|
|
2017-04-05 08:37:44 +02:00
|
|
|
struct net_pkt *
|
2019-02-20 13:43:24 +01:00
|
|
|
ieee802154_create_mac_cmd_frame(struct net_if *iface,
|
2016-10-18 16:06:19 +02:00
|
|
|
enum ieee802154_cfi type,
|
|
|
|
struct ieee802154_frame_params *params);
|
|
|
|
|
2018-10-24 15:08:50 +02:00
|
|
|
void ieee802154_mac_cmd_finalize(struct net_pkt *pkt,
|
|
|
|
enum ieee802154_cfi type);
|
|
|
|
|
2016-10-18 16:06:19 +02:00
|
|
|
static inline
|
2017-04-05 08:37:44 +02:00
|
|
|
struct ieee802154_command *ieee802154_get_mac_command(struct net_pkt *pkt)
|
2016-10-18 16:06:19 +02:00
|
|
|
{
|
2018-10-24 15:08:50 +02:00
|
|
|
return (struct ieee802154_command *)(pkt->frags->data +
|
|
|
|
pkt->frags->len);
|
2016-10-18 16:06:19 +02:00
|
|
|
}
|
|
|
|
|
2016-06-28 15:05:07 +02:00
|
|
|
#ifdef CONFIG_NET_L2_IEEE802154_ACK_REPLY
|
|
|
|
bool ieee802154_create_ack_frame(struct net_if *iface,
|
2020-05-27 18:26:57 +02:00
|
|
|
struct net_pkt *pkt, uint8_t seq);
|
2016-06-28 15:05:07 +02:00
|
|
|
#endif
|
|
|
|
|
2017-01-26 15:00:17 +01:00
|
|
|
#ifdef CONFIG_NET_L2_IEEE802154_SECURITY
|
2017-04-05 08:37:44 +02:00
|
|
|
bool ieee802154_decipher_data_frame(struct net_if *iface, struct net_pkt *pkt,
|
2017-01-26 15:00:17 +01:00
|
|
|
struct ieee802154_mpdu *mpdu);
|
|
|
|
#else
|
|
|
|
#define ieee802154_decipher_data_frame(...) true
|
|
|
|
#endif /* CONFIG_NET_L2_IEEE802154_SECURITY */
|
|
|
|
|
2016-06-16 16:00:11 +02:00
|
|
|
#endif /* __IEEE802154_FRAME_H__ */
|