Linux 4.13.16
[linux/fpc-iii.git] / include / linux / ieee802154.h
blobddb890174a0e92e8d897bc61cc51e11cbd276067
1 /*
2 * IEEE802.15.4-2003 specification
4 * Copyright (C) 2007, 2008 Siemens AG
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * Written by:
16 * Pavel Smolenskiy <pavel.smolenskiy@gmail.com>
17 * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
18 * Maxim Osipov <maxim.osipov@siemens.com>
19 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
20 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
23 #ifndef LINUX_IEEE802154_H
24 #define LINUX_IEEE802154_H
26 #include <linux/types.h>
27 #include <linux/random.h>
29 #define IEEE802154_MTU 127
30 #define IEEE802154_ACK_PSDU_LEN 5
31 #define IEEE802154_MIN_PSDU_LEN 9
32 #define IEEE802154_FCS_LEN 2
33 #define IEEE802154_MAX_AUTH_TAG_LEN 16
34 #define IEEE802154_FC_LEN 2
35 #define IEEE802154_SEQ_LEN 1
37 /* General MAC frame format:
38 * 2 bytes: Frame Control
39 * 1 byte: Sequence Number
40 * 20 bytes: Addressing fields
41 * 14 bytes: Auxiliary Security Header
43 #define IEEE802154_MAX_HEADER_LEN (2 + 1 + 20 + 14)
44 #define IEEE802154_MIN_HEADER_LEN (IEEE802154_ACK_PSDU_LEN - \
45 IEEE802154_FCS_LEN)
47 #define IEEE802154_PAN_ID_BROADCAST 0xffff
48 #define IEEE802154_ADDR_SHORT_BROADCAST 0xffff
49 #define IEEE802154_ADDR_SHORT_UNSPEC 0xfffe
51 #define IEEE802154_EXTENDED_ADDR_LEN 8
52 #define IEEE802154_SHORT_ADDR_LEN 2
53 #define IEEE802154_PAN_ID_LEN 2
55 #define IEEE802154_LIFS_PERIOD 40
56 #define IEEE802154_SIFS_PERIOD 12
57 #define IEEE802154_MAX_SIFS_FRAME_SIZE 18
59 #define IEEE802154_MAX_CHANNEL 26
60 #define IEEE802154_MAX_PAGE 31
62 #define IEEE802154_FC_TYPE_BEACON 0x0 /* Frame is beacon */
63 #define IEEE802154_FC_TYPE_DATA 0x1 /* Frame is data */
64 #define IEEE802154_FC_TYPE_ACK 0x2 /* Frame is acknowledgment */
65 #define IEEE802154_FC_TYPE_MAC_CMD 0x3 /* Frame is MAC command */
67 #define IEEE802154_FC_TYPE_SHIFT 0
68 #define IEEE802154_FC_TYPE_MASK ((1 << 3) - 1)
69 #define IEEE802154_FC_TYPE(x) ((x & IEEE802154_FC_TYPE_MASK) >> IEEE802154_FC_TYPE_SHIFT)
70 #define IEEE802154_FC_SET_TYPE(v, x) do { \
71 v = (((v) & ~IEEE802154_FC_TYPE_MASK) | \
72 (((x) << IEEE802154_FC_TYPE_SHIFT) & IEEE802154_FC_TYPE_MASK)); \
73 } while (0)
75 #define IEEE802154_FC_SECEN_SHIFT 3
76 #define IEEE802154_FC_SECEN (1 << IEEE802154_FC_SECEN_SHIFT)
77 #define IEEE802154_FC_FRPEND_SHIFT 4
78 #define IEEE802154_FC_FRPEND (1 << IEEE802154_FC_FRPEND_SHIFT)
79 #define IEEE802154_FC_ACK_REQ_SHIFT 5
80 #define IEEE802154_FC_ACK_REQ (1 << IEEE802154_FC_ACK_REQ_SHIFT)
81 #define IEEE802154_FC_INTRA_PAN_SHIFT 6
82 #define IEEE802154_FC_INTRA_PAN (1 << IEEE802154_FC_INTRA_PAN_SHIFT)
84 #define IEEE802154_FC_SAMODE_SHIFT 14
85 #define IEEE802154_FC_SAMODE_MASK (3 << IEEE802154_FC_SAMODE_SHIFT)
86 #define IEEE802154_FC_DAMODE_SHIFT 10
87 #define IEEE802154_FC_DAMODE_MASK (3 << IEEE802154_FC_DAMODE_SHIFT)
89 #define IEEE802154_FC_VERSION_SHIFT 12
90 #define IEEE802154_FC_VERSION_MASK (3 << IEEE802154_FC_VERSION_SHIFT)
91 #define IEEE802154_FC_VERSION(x) ((x & IEEE802154_FC_VERSION_MASK) >> IEEE802154_FC_VERSION_SHIFT)
93 #define IEEE802154_FC_SAMODE(x) \
94 (((x) & IEEE802154_FC_SAMODE_MASK) >> IEEE802154_FC_SAMODE_SHIFT)
96 #define IEEE802154_FC_DAMODE(x) \
97 (((x) & IEEE802154_FC_DAMODE_MASK) >> IEEE802154_FC_DAMODE_SHIFT)
99 #define IEEE802154_SCF_SECLEVEL_MASK 7
100 #define IEEE802154_SCF_SECLEVEL_SHIFT 0
101 #define IEEE802154_SCF_SECLEVEL(x) (x & IEEE802154_SCF_SECLEVEL_MASK)
102 #define IEEE802154_SCF_KEY_ID_MODE_SHIFT 3
103 #define IEEE802154_SCF_KEY_ID_MODE_MASK (3 << IEEE802154_SCF_KEY_ID_MODE_SHIFT)
104 #define IEEE802154_SCF_KEY_ID_MODE(x) \
105 ((x & IEEE802154_SCF_KEY_ID_MODE_MASK) >> IEEE802154_SCF_KEY_ID_MODE_SHIFT)
107 #define IEEE802154_SCF_KEY_IMPLICIT 0
108 #define IEEE802154_SCF_KEY_INDEX 1
109 #define IEEE802154_SCF_KEY_SHORT_INDEX 2
110 #define IEEE802154_SCF_KEY_HW_INDEX 3
112 #define IEEE802154_SCF_SECLEVEL_NONE 0
113 #define IEEE802154_SCF_SECLEVEL_MIC32 1
114 #define IEEE802154_SCF_SECLEVEL_MIC64 2
115 #define IEEE802154_SCF_SECLEVEL_MIC128 3
116 #define IEEE802154_SCF_SECLEVEL_ENC 4
117 #define IEEE802154_SCF_SECLEVEL_ENC_MIC32 5
118 #define IEEE802154_SCF_SECLEVEL_ENC_MIC64 6
119 #define IEEE802154_SCF_SECLEVEL_ENC_MIC128 7
121 /* MAC footer size */
122 #define IEEE802154_MFR_SIZE 2 /* 2 octets */
124 /* MAC's Command Frames Identifiers */
125 #define IEEE802154_CMD_ASSOCIATION_REQ 0x01
126 #define IEEE802154_CMD_ASSOCIATION_RESP 0x02
127 #define IEEE802154_CMD_DISASSOCIATION_NOTIFY 0x03
128 #define IEEE802154_CMD_DATA_REQ 0x04
129 #define IEEE802154_CMD_PANID_CONFLICT_NOTIFY 0x05
130 #define IEEE802154_CMD_ORPHAN_NOTIFY 0x06
131 #define IEEE802154_CMD_BEACON_REQ 0x07
132 #define IEEE802154_CMD_COORD_REALIGN_NOTIFY 0x08
133 #define IEEE802154_CMD_GTS_REQ 0x09
136 * The return values of MAC operations
138 enum {
140 * The requested operation was completed successfully.
141 * For a transmission request, this value indicates
142 * a successful transmission.
144 IEEE802154_SUCCESS = 0x0,
146 /* The beacon was lost following a synchronization request. */
147 IEEE802154_BEACON_LOSS = 0xe0,
149 * A transmission could not take place due to activity on the
150 * channel, i.e., the CSMA-CA mechanism has failed.
152 IEEE802154_CHNL_ACCESS_FAIL = 0xe1,
153 /* The GTS request has been denied by the PAN coordinator. */
154 IEEE802154_DENINED = 0xe2,
155 /* The attempt to disable the transceiver has failed. */
156 IEEE802154_DISABLE_TRX_FAIL = 0xe3,
158 * The received frame induces a failed security check according to
159 * the security suite.
161 IEEE802154_FAILED_SECURITY_CHECK = 0xe4,
163 * The frame resulting from secure processing has a length that is
164 * greater than aMACMaxFrameSize.
166 IEEE802154_FRAME_TOO_LONG = 0xe5,
168 * The requested GTS transmission failed because the specified GTS
169 * either did not have a transmit GTS direction or was not defined.
171 IEEE802154_INVALID_GTS = 0xe6,
173 * A request to purge an MSDU from the transaction queue was made using
174 * an MSDU handle that was not found in the transaction table.
176 IEEE802154_INVALID_HANDLE = 0xe7,
177 /* A parameter in the primitive is out of the valid range.*/
178 IEEE802154_INVALID_PARAMETER = 0xe8,
179 /* No acknowledgment was received after aMaxFrameRetries. */
180 IEEE802154_NO_ACK = 0xe9,
181 /* A scan operation failed to find any network beacons.*/
182 IEEE802154_NO_BEACON = 0xea,
183 /* No response data were available following a request. */
184 IEEE802154_NO_DATA = 0xeb,
185 /* The operation failed because a short address was not allocated. */
186 IEEE802154_NO_SHORT_ADDRESS = 0xec,
188 * A receiver enable request was unsuccessful because it could not be
189 * completed within the CAP.
191 IEEE802154_OUT_OF_CAP = 0xed,
193 * A PAN identifier conflict has been detected and communicated to the
194 * PAN coordinator.
196 IEEE802154_PANID_CONFLICT = 0xee,
197 /* A coordinator realignment command has been received. */
198 IEEE802154_REALIGMENT = 0xef,
199 /* The transaction has expired and its information discarded. */
200 IEEE802154_TRANSACTION_EXPIRED = 0xf0,
201 /* There is no capacity to store the transaction. */
202 IEEE802154_TRANSACTION_OVERFLOW = 0xf1,
204 * The transceiver was in the transmitter enabled state when the
205 * receiver was requested to be enabled.
207 IEEE802154_TX_ACTIVE = 0xf2,
208 /* The appropriate key is not available in the ACL. */
209 IEEE802154_UNAVAILABLE_KEY = 0xf3,
211 * A SET/GET request was issued with the identifier of a PIB attribute
212 * that is not supported.
214 IEEE802154_UNSUPPORTED_ATTR = 0xf4,
216 * A request to perform a scan operation failed because the MLME was
217 * in the process of performing a previously initiated scan operation.
219 IEEE802154_SCAN_IN_PROGRESS = 0xfc,
222 /* frame control handling */
223 #define IEEE802154_FCTL_FTYPE 0x0003
224 #define IEEE802154_FCTL_ACKREQ 0x0020
225 #define IEEE802154_FCTL_SECEN 0x0004
226 #define IEEE802154_FCTL_INTRA_PAN 0x0040
227 #define IEEE802154_FCTL_DADDR 0x0c00
228 #define IEEE802154_FCTL_SADDR 0xc000
230 #define IEEE802154_FTYPE_DATA 0x0001
232 #define IEEE802154_FCTL_ADDR_NONE 0x0000
233 #define IEEE802154_FCTL_DADDR_SHORT 0x0800
234 #define IEEE802154_FCTL_DADDR_EXTENDED 0x0c00
235 #define IEEE802154_FCTL_SADDR_SHORT 0x8000
236 #define IEEE802154_FCTL_SADDR_EXTENDED 0xc000
239 * ieee802154_is_data - check if type is IEEE802154_FTYPE_DATA
240 * @fc: frame control bytes in little-endian byteorder
242 static inline int ieee802154_is_data(__le16 fc)
244 return (fc & cpu_to_le16(IEEE802154_FCTL_FTYPE)) ==
245 cpu_to_le16(IEEE802154_FTYPE_DATA);
249 * ieee802154_is_secen - check if Security bit is set
250 * @fc: frame control bytes in little-endian byteorder
252 static inline bool ieee802154_is_secen(__le16 fc)
254 return fc & cpu_to_le16(IEEE802154_FCTL_SECEN);
258 * ieee802154_is_ackreq - check if acknowledgment request bit is set
259 * @fc: frame control bytes in little-endian byteorder
261 static inline bool ieee802154_is_ackreq(__le16 fc)
263 return fc & cpu_to_le16(IEEE802154_FCTL_ACKREQ);
267 * ieee802154_is_intra_pan - check if intra pan id communication
268 * @fc: frame control bytes in little-endian byteorder
270 static inline bool ieee802154_is_intra_pan(__le16 fc)
272 return fc & cpu_to_le16(IEEE802154_FCTL_INTRA_PAN);
276 * ieee802154_daddr_mode - get daddr mode from fc
277 * @fc: frame control bytes in little-endian byteorder
279 static inline __le16 ieee802154_daddr_mode(__le16 fc)
281 return fc & cpu_to_le16(IEEE802154_FCTL_DADDR);
285 * ieee802154_saddr_mode - get saddr mode from fc
286 * @fc: frame control bytes in little-endian byteorder
288 static inline __le16 ieee802154_saddr_mode(__le16 fc)
290 return fc & cpu_to_le16(IEEE802154_FCTL_SADDR);
294 * ieee802154_is_valid_psdu_len - check if psdu len is valid
295 * available lengths:
296 * 0-4 Reserved
297 * 5 MPDU (Acknowledgment)
298 * 6-8 Reserved
299 * 9-127 MPDU
301 * @len: psdu len with (MHR + payload + MFR)
303 static inline bool ieee802154_is_valid_psdu_len(u8 len)
305 return (len == IEEE802154_ACK_PSDU_LEN ||
306 (len >= IEEE802154_MIN_PSDU_LEN && len <= IEEE802154_MTU));
310 * ieee802154_is_valid_extended_unicast_addr - check if extended addr is valid
311 * @addr: extended addr to check
313 static inline bool ieee802154_is_valid_extended_unicast_addr(__le64 addr)
315 /* Bail out if the address is all zero, or if the group
316 * address bit is set.
318 return ((addr != cpu_to_le64(0x0000000000000000ULL)) &&
319 !(addr & cpu_to_le64(0x0100000000000000ULL)));
323 * ieee802154_is_broadcast_short_addr - check if short addr is broadcast
324 * @addr: short addr to check
326 static inline bool ieee802154_is_broadcast_short_addr(__le16 addr)
328 return (addr == cpu_to_le16(IEEE802154_ADDR_SHORT_BROADCAST));
332 * ieee802154_is_unspec_short_addr - check if short addr is unspecified
333 * @addr: short addr to check
335 static inline bool ieee802154_is_unspec_short_addr(__le16 addr)
337 return (addr == cpu_to_le16(IEEE802154_ADDR_SHORT_UNSPEC));
341 * ieee802154_is_valid_src_short_addr - check if source short address is valid
342 * @addr: short addr to check
344 static inline bool ieee802154_is_valid_src_short_addr(__le16 addr)
346 return !(ieee802154_is_broadcast_short_addr(addr) ||
347 ieee802154_is_unspec_short_addr(addr));
351 * ieee802154_random_extended_addr - generates a random extended address
352 * @addr: extended addr pointer to place the random address
354 static inline void ieee802154_random_extended_addr(__le64 *addr)
356 get_random_bytes(addr, IEEE802154_EXTENDED_ADDR_LEN);
358 /* clear the group bit, and set the locally administered bit */
359 ((u8 *)addr)[IEEE802154_EXTENDED_ADDR_LEN - 1] &= ~0x01;
360 ((u8 *)addr)[IEEE802154_EXTENDED_ADDR_LEN - 1] |= 0x02;
363 #endif /* LINUX_IEEE802154_H */