Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
frame802154.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2008, Swedish Institute of Computer Science
3
* All rights reserved.
4
*
5
* Additional fixes for AVR contributed by:
6
* Colin O'Flynn coflynn@newae.com
7
* Eric Gnoske egnoske@gmail.com
8
* Blake Leverett bleverett@gmail.com
9
* Mike Vidales mavida404@gmail.com
10
* Kevin Brown kbrown3@uccs.edu
11
* Nate Bohlmann nate@elfwerks.com
12
*
13
* Additional fixes for MSP430 contributed by:
14
* Joakim Eriksson
15
* Niclas Finne
16
* Nicolas Tsiftes
17
*
18
* All rights reserved.
19
*
20
* Redistribution and use in source and binary forms, with or without
21
* modification, are permitted provided that the following conditions are met:
22
*
23
* * Redistributions of source code must retain the above copyright
24
* notice, this list of conditions and the following disclaimer.
25
* * Redistributions in binary form must reproduce the above copyright
26
* notice, this list of conditions and the following disclaimer in
27
* the documentation and/or other materials provided with the
28
* distribution.
29
* * Neither the name of the copyright holders nor the names of
30
* contributors may be used to endorse or promote products derived
31
* from this software without specific prior written permission.
32
*
33
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
34
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
37
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
40
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
41
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43
* POSSIBILITY OF SUCH DAMAGE.
44
*/
45
46
/**
47
* \addtogroup link-layer
48
* @{
49
*/
50
51
/**
52
* \defgroup frame802154 802.15.4 frame creation and parsing
53
* @{
54
*/
55
/**
56
* \file
57
* \brief 802.15.4 frame creation and parsing functions
58
*
59
* This file converts to and from a structure to a packed 802.15.4
60
* frame.
61
*
62
*/
63
64
/* Includes */
65
#ifndef FRAME_802154_H
66
#define FRAME_802154_H
67
68
#include "contiki.h"
69
#include "
net/linkaddr.h
"
70
#include <stdbool.h>
71
72
#ifdef IEEE802154_CONF_PANID
73
#define IEEE802154_PANID IEEE802154_CONF_PANID
74
#else
/* IEEE802154_CONF_PANID */
75
#define IEEE802154_PANID 0xABCD
76
#endif
/* IEEE802154_CONF_PANID */
77
78
#ifdef FRAME802154_CONF_VERSION
79
#define FRAME802154_VERSION FRAME802154_CONF_VERSION
80
#else
/* FRAME802154_CONF_VERSION */
81
/* Use frame v2 if TSCH is used, otherwise stick to v1 (more
82
frame-filtering-friendly on some platforms) */
83
#if MAC_CONF_WITH_TSCH
84
#define FRAME802154_VERSION FRAME802154_IEEE802154_2015
85
#else
/* MAC_CONF_WITH_TSCH */
86
#define FRAME802154_VERSION FRAME802154_IEEE802154_2006
87
#endif
/* MAC_CONF_WITH_TSCH */
88
#endif
/* FRAME802154_CONF_VERSION */
89
90
#ifdef FRAME802154_CONF_SUPPR_SEQNO
91
#define FRAME802154_SUPPR_SEQNO FRAME802154_CONF_SUPPR_SEQNO
92
#else
/* FRAME802154_CONF_SUPPR_SEQNO */
93
#define FRAME802154_SUPPR_SEQNO 0
94
#endif
/* FRAME802154_CONF_SUPPR_SEQNO */
95
96
/* Macros & Defines */
97
98
/** \brief These are some definitions of values used in the FCF. See the 802.15.4 spec for details.
99
* \name FCF element values definitions
100
* @{
101
*/
102
#define FRAME802154_BEACONFRAME (0x00)
103
#define FRAME802154_DATAFRAME (0x01)
104
#define FRAME802154_ACKFRAME (0x02)
105
#define FRAME802154_CMDFRAME (0x03)
106
107
#define FRAME802154_BEACONREQ (0x07)
108
109
#define FRAME802154_IEEERESERVED (0x00)
110
#define FRAME802154_NOADDR (0x00)
/**< Only valid for ACK or Beacon frames. */
111
#define FRAME802154_SHORTADDRMODE (0x02)
112
#define FRAME802154_LONGADDRMODE (0x03)
113
114
#define FRAME802154_NOBEACONS (0x0F)
115
116
#define FRAME802154_BROADCASTADDR (0xFFFF)
117
#define FRAME802154_BROADCASTPANDID (0xFFFF)
118
119
#define FRAME802154_IEEE802154_2003 (0x00)
120
#define FRAME802154_IEEE802154_2006 (0x01)
121
#define FRAME802154_IEEE802154_2015 (0x02)
122
123
#define FRAME802154_SECURITY_LEVEL_NONE (0)
124
#define FRAME802154_SECURITY_LEVEL_MIC_32 (1)
125
#define FRAME802154_SECURITY_LEVEL_MIC_64 (2)
126
#define FRAME802154_SECURITY_LEVEL_MIC_128 (3)
127
#define FRAME802154_SECURITY_LEVEL_ENC (4)
128
#define FRAME802154_SECURITY_LEVEL_ENC_MIC_32 (5)
129
#define FRAME802154_SECURITY_LEVEL_ENC_MIC_64 (6)
130
#define FRAME802154_SECURITY_LEVEL_ENC_MIC_128 (7)
131
132
#define FRAME802154_IMPLICIT_KEY (0)
133
#define FRAME802154_1_BYTE_KEY_ID_MODE (1)
134
#define FRAME802154_5_BYTE_KEY_ID_MODE (2)
135
#define FRAME802154_9_BYTE_KEY_ID_MODE (3)
136
137
/**
138
* @brief The IEEE 802.15.4 frame has a number of constant/fixed fields that
139
* can be counted to make frame construction and max payload
140
* calculations easier.
141
*
142
* These include:
143
* 1. FCF - 2 bytes - Fixed
144
* 2. Sequence number - 1 byte - Fixed
145
* 3. Addressing fields - 4 - 20 bytes - Variable
146
* 4. Aux security header - 0 - 14 bytes - Variable
147
* 5. CRC - 2 bytes - Fixed
148
*/
149
150
/**
151
* \brief Defines the bitfields of the frame control field (FCF).
152
*/
153
typedef
struct
{
154
uint8_t
frame_type
;
/**< 3 bit. Frame type field, see 802.15.4 */
155
uint8_t
security_enabled
;
/**< 1 bit. True if security is used in this frame */
156
uint8_t
frame_pending
;
/**< 1 bit. True if sender has more data to send */
157
uint8_t
ack_required
;
/**< 1 bit. Is an ack frame required? */
158
uint8_t
panid_compression
;
/**< 1 bit. Is this a compressed header? */
159
/* uint8_t reserved; */
/**< 1 bit. Unused bit */
160
uint8_t
sequence_number_suppression
;
/**< 1 bit. Does the header omit sequence number?, see 802.15.4e */
161
uint8_t
ie_list_present
;
/**< 1 bit. Does the header contain Information Elements?, see 802.15.4e */
162
uint8_t
dest_addr_mode
;
/**< 2 bit. Destination address mode, see 802.15.4 */
163
uint8_t
frame_version
;
/**< 2 bit. 802.15.4 frame version */
164
uint8_t
src_addr_mode
;
/**< 2 bit. Source address mode, see 802.15.4 */
165
}
frame802154_fcf_t
;
166
167
/** \brief 802.15.4 security control bitfield. See section 7.6.2.2.1 in 802.15.4 specification */
168
typedef
struct
{
169
uint8_t
security_level
;
/**< 3 bit. security level */
170
uint8_t
key_id_mode
;
/**< 2 bit. Key identifier mode */
171
uint8_t
frame_counter_suppression
;
/**< 1 bit. Frame counter suppression */
172
uint8_t
frame_counter_size
;
/**< 1 bit. Frame counter size (0: 4 bytes, 1: 5 bytes) */
173
uint8_t
reserved
;
/**< 3 bit. Reserved bits */
174
}
frame802154_scf_t
;
175
176
typedef
union
{
177
uint32_t u32;
178
uint16_t u16[2];
179
uint8_t u8[4];
180
} frame802154_frame_counter_t;
181
182
typedef
union
{
183
uint16_t u16[4];
184
uint8_t u8[8];
185
} frame802154_key_source_t;
186
187
/** \brief 802.15.4 Aux security header */
188
typedef
struct
{
189
frame802154_scf_t
security_control
;
/**< Security control bitfield */
190
frame802154_frame_counter_t
frame_counter
;
/**< Frame counter, used for security */
191
frame802154_key_source_t
key_source
;
/**< Key Source subfield */
192
uint8_t
key_index
;
/**< Key Index subfield */
193
}
frame802154_aux_hdr_t
;
194
195
/** \brief Parameters used by the frame802154_create() function. These
196
* parameters are used in the 802.15.4 frame header. See the 802.15.4
197
* specification for details.
198
*/
199
typedef
struct
{
200
/* The fields dest_addr and src_addr must come first to ensure they are aligned to the
201
* CPU word size. Needed as they are accessed directly as linkaddr_t*. Note we cannot use
202
* the type linkaddr_t directly here, as we always need 8 bytes, not LINKADDR_SIZE bytes. */
203
uint8_t
dest_addr
[8];
/**< Destination address */
204
uint8_t
src_addr
[8];
/**< Source address */
205
frame802154_fcf_t
fcf
;
/**< Frame control field */
206
uint8_t
seq
;
/**< Sequence number */
207
uint16_t
dest_pid
;
/**< Destination PAN ID */
208
uint16_t
src_pid
;
/**< Source PAN ID */
209
frame802154_aux_hdr_t
aux_hdr
;
/**< Aux security header */
210
uint8_t *
payload
;
/**< Pointer to 802.15.4 payload */
211
int
payload_len
;
/**< Length of payload field */
212
}
frame802154_t
;
213
214
/* Prototypes */
215
216
int
frame802154_hdrlen
(
frame802154_t
*p);
217
void
frame802154_create_fcf(
frame802154_fcf_t
*fcf, uint8_t *buf);
218
int
frame802154_create
(
frame802154_t
*p, uint8_t *buf);
219
int
frame802154_parse
(uint8_t *data,
int
length,
frame802154_t
*pf);
220
void
frame802154_parse_fcf(
const
uint8_t *data,
frame802154_fcf_t
*pfcf);
221
222
/* Get current PAN ID */
223
uint16_t frame802154_get_pan_id(
void
);
224
/* Set current PAN ID */
225
void
frame802154_set_pan_id(uint16_t pan_id);
226
/* Tells whether a given Frame Control Field indicates a frame with
227
* source PANID and/or destination PANID */
228
void
frame802154_has_panid(
frame802154_fcf_t
*fcf,
int
*has_src_pan_id,
int
*has_dest_pan_id);
229
/* Check if the destination PAN ID, if any, matches ours */
230
int
frame802154_check_dest_panid(
frame802154_t
*frame);
231
/* Check is the address is a broadcast address, whatever its size */
232
bool
frame802154_is_broadcast_addr(uint8_t mode,
const
uint8_t *
addr
);
233
/* Check and extract source and destination linkaddr from frame */
234
int
frame802154_extract_linkaddr(
frame802154_t
*frame, linkaddr_t *source_address, linkaddr_t *dest_address);
235
236
/** @} */
237
#endif
/* FRAME_802154_H */
238
/** @} */
239
/** @} */
frame802154_parse
int frame802154_parse(uint8_t *data, int len, frame802154_t *pf)
Parses an input frame.
Definition
frame802154.c:494
frame802154_create
int frame802154_create(frame802154_t *p, uint8_t *buf)
Creates a frame for transmission over the air.
Definition
frame802154.c:387
frame802154_hdrlen
int frame802154_hdrlen(frame802154_t *p)
Calculates the length of the frame header.
Definition
frame802154.c:353
linkaddr.h
Header file for the link-layer address representation.
frame802154_aux_hdr_t
802.15.4 Aux security header
Definition
frame802154.h:188
frame802154_aux_hdr_t::security_control
frame802154_scf_t security_control
Security control bitfield.
Definition
frame802154.h:189
frame802154_aux_hdr_t::frame_counter
frame802154_frame_counter_t frame_counter
Frame counter, used for security.
Definition
frame802154.h:190
frame802154_aux_hdr_t::key_index
uint8_t key_index
Key Index subfield.
Definition
frame802154.h:192
frame802154_aux_hdr_t::key_source
frame802154_key_source_t key_source
Key Source subfield.
Definition
frame802154.h:191
frame802154_fcf_t
The IEEE 802.15.4 frame has a number of constant/fixed fields that can be counted to make frame const...
Definition
frame802154.h:153
frame802154_fcf_t::frame_type
uint8_t frame_type
3 bit.
Definition
frame802154.h:154
frame802154_fcf_t::frame_version
uint8_t frame_version
2 bit.
Definition
frame802154.h:163
frame802154_fcf_t::ie_list_present
uint8_t ie_list_present
1 bit.
Definition
frame802154.h:161
frame802154_fcf_t::security_enabled
uint8_t security_enabled
1 bit.
Definition
frame802154.h:155
frame802154_fcf_t::sequence_number_suppression
uint8_t sequence_number_suppression
< 1 bit.
Definition
frame802154.h:160
frame802154_fcf_t::src_addr_mode
uint8_t src_addr_mode
2 bit.
Definition
frame802154.h:164
frame802154_fcf_t::panid_compression
uint8_t panid_compression
1 bit.
Definition
frame802154.h:158
frame802154_fcf_t::ack_required
uint8_t ack_required
1 bit.
Definition
frame802154.h:157
frame802154_fcf_t::dest_addr_mode
uint8_t dest_addr_mode
2 bit.
Definition
frame802154.h:162
frame802154_fcf_t::frame_pending
uint8_t frame_pending
1 bit.
Definition
frame802154.h:156
frame802154_scf_t
802.15.4 security control bitfield.
Definition
frame802154.h:168
frame802154_scf_t::key_id_mode
uint8_t key_id_mode
2 bit.
Definition
frame802154.h:170
frame802154_scf_t::frame_counter_size
uint8_t frame_counter_size
1 bit.
Definition
frame802154.h:172
frame802154_scf_t::reserved
uint8_t reserved
3 bit.
Definition
frame802154.h:173
frame802154_scf_t::frame_counter_suppression
uint8_t frame_counter_suppression
1 bit.
Definition
frame802154.h:171
frame802154_scf_t::security_level
uint8_t security_level
3 bit.
Definition
frame802154.h:169
frame802154_t
Parameters used by the frame802154_create() function.
Definition
frame802154.h:199
frame802154_t::seq
uint8_t seq
Sequence number.
Definition
frame802154.h:206
frame802154_t::dest_addr
uint8_t dest_addr[8]
Destination address.
Definition
frame802154.h:203
frame802154_t::aux_hdr
frame802154_aux_hdr_t aux_hdr
Aux security header.
Definition
frame802154.h:209
frame802154_t::payload
uint8_t * payload
Pointer to 802.15.4 payload.
Definition
frame802154.h:210
frame802154_t::src_addr
uint8_t src_addr[8]
Source address.
Definition
frame802154.h:204
frame802154_t::src_pid
uint16_t src_pid
Source PAN ID.
Definition
frame802154.h:208
frame802154_t::fcf
frame802154_fcf_t fcf
Frame control field.
Definition
frame802154.h:205
frame802154_t::dest_pid
uint16_t dest_pid
Destination PAN ID.
Definition
frame802154.h:207
frame802154_t::payload_len
int payload_len
Length of payload field.
Definition
frame802154.h:211
addr
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Definition
uip-nd6.c:107
os
net
mac
framer
frame802154.h
Generated on
for Contiki-NG by
1.17.0