blob: a907fe59b1d12f6712a51b2f96e9eab1bc67919f [file] [log] [blame]
Sergey Lapin9ec76712009-06-08 12:18:48 +00001/*
2 * IEEE802.15.4-2003 specification
3 *
4 * Copyright (C) 2007, 2008 Siemens AG
5 *
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.
9 *
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.
14 *
Sergey Lapin9ec76712009-06-08 12:18:48 +000015 * 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>
alex.bluesman.smirnov@gmail.com719269a2011-11-10 07:38:38 +000020 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
Sergey Lapin9ec76712009-06-08 12:18:48 +000021 */
22
Alexander Aring4ca24ac2014-10-25 09:41:04 +020023#ifndef LINUX_IEEE802154_H
24#define LINUX_IEEE802154_H
Sergey Lapin9ec76712009-06-08 12:18:48 +000025
Alexander Aringfa491002014-10-27 17:13:40 +010026#include <linux/types.h>
Alexander Aringc28bee82014-11-02 21:43:02 +010027#include <asm/byteorder.h>
Alexander Aringfa491002014-10-27 17:13:40 +010028
alex.bluesman.smirnov@gmail.com719269a2011-11-10 07:38:38 +000029#define IEEE802154_MTU 127
Alexander Aringfa491002014-10-27 17:13:40 +010030#define IEEE802154_MIN_PSDU_LEN 5
alex.bluesman.smirnov@gmail.com719269a2011-11-10 07:38:38 +000031
Alexander Aring1906bbb2014-11-05 20:51:21 +010032#define IEEE802154_EXTENDED_ADDR_LEN 8
33
Sergey Lapin9ec76712009-06-08 12:18:48 +000034#define IEEE802154_FC_TYPE_BEACON 0x0 /* Frame is beacon */
35#define IEEE802154_FC_TYPE_DATA 0x1 /* Frame is data */
36#define IEEE802154_FC_TYPE_ACK 0x2 /* Frame is acknowledgment */
37#define IEEE802154_FC_TYPE_MAC_CMD 0x3 /* Frame is MAC command */
38
39#define IEEE802154_FC_TYPE_SHIFT 0
40#define IEEE802154_FC_TYPE_MASK ((1 << 3) - 1)
41#define IEEE802154_FC_TYPE(x) ((x & IEEE802154_FC_TYPE_MASK) >> IEEE802154_FC_TYPE_SHIFT)
42#define IEEE802154_FC_SET_TYPE(v, x) do { \
43 v = (((v) & ~IEEE802154_FC_TYPE_MASK) | \
44 (((x) << IEEE802154_FC_TYPE_SHIFT) & IEEE802154_FC_TYPE_MASK)); \
45 } while (0)
46
Phoebe Buckheister94b4f6c2014-03-14 21:24:00 +010047#define IEEE802154_FC_SECEN_SHIFT 3
48#define IEEE802154_FC_SECEN (1 << IEEE802154_FC_SECEN_SHIFT)
49#define IEEE802154_FC_FRPEND_SHIFT 4
50#define IEEE802154_FC_FRPEND (1 << IEEE802154_FC_FRPEND_SHIFT)
51#define IEEE802154_FC_ACK_REQ_SHIFT 5
52#define IEEE802154_FC_ACK_REQ (1 << IEEE802154_FC_ACK_REQ_SHIFT)
53#define IEEE802154_FC_INTRA_PAN_SHIFT 6
54#define IEEE802154_FC_INTRA_PAN (1 << IEEE802154_FC_INTRA_PAN_SHIFT)
Sergey Lapin9ec76712009-06-08 12:18:48 +000055
56#define IEEE802154_FC_SAMODE_SHIFT 14
57#define IEEE802154_FC_SAMODE_MASK (3 << IEEE802154_FC_SAMODE_SHIFT)
58#define IEEE802154_FC_DAMODE_SHIFT 10
59#define IEEE802154_FC_DAMODE_MASK (3 << IEEE802154_FC_DAMODE_SHIFT)
60
Phoebe Buckheister94b4f6c2014-03-14 21:24:00 +010061#define IEEE802154_FC_VERSION_SHIFT 12
62#define IEEE802154_FC_VERSION_MASK (3 << IEEE802154_FC_VERSION_SHIFT)
63#define IEEE802154_FC_VERSION(x) ((x & IEEE802154_FC_VERSION_MASK) >> IEEE802154_FC_VERSION_SHIFT)
64
Sergey Lapin9ec76712009-06-08 12:18:48 +000065#define IEEE802154_FC_SAMODE(x) \
66 (((x) & IEEE802154_FC_SAMODE_MASK) >> IEEE802154_FC_SAMODE_SHIFT)
67
68#define IEEE802154_FC_DAMODE(x) \
69 (((x) & IEEE802154_FC_DAMODE_MASK) >> IEEE802154_FC_DAMODE_SHIFT)
70
Phoebe Buckheister94b4f6c2014-03-14 21:24:00 +010071#define IEEE802154_SCF_SECLEVEL_MASK 7
72#define IEEE802154_SCF_SECLEVEL_SHIFT 0
73#define IEEE802154_SCF_SECLEVEL(x) (x & IEEE802154_SCF_SECLEVEL_MASK)
74#define IEEE802154_SCF_KEY_ID_MODE_SHIFT 3
75#define IEEE802154_SCF_KEY_ID_MODE_MASK (3 << IEEE802154_SCF_KEY_ID_MODE_SHIFT)
76#define IEEE802154_SCF_KEY_ID_MODE(x) \
77 ((x & IEEE802154_SCF_KEY_ID_MODE_MASK) >> IEEE802154_SCF_KEY_ID_MODE_SHIFT)
78
79#define IEEE802154_SCF_KEY_IMPLICIT 0
80#define IEEE802154_SCF_KEY_INDEX 1
81#define IEEE802154_SCF_KEY_SHORT_INDEX 2
82#define IEEE802154_SCF_KEY_HW_INDEX 3
Sergey Lapin9ec76712009-06-08 12:18:48 +000083
Phoebe Buckheisterc3a61142014-05-14 17:43:06 +020084#define IEEE802154_SCF_SECLEVEL_NONE 0
85#define IEEE802154_SCF_SECLEVEL_MIC32 1
86#define IEEE802154_SCF_SECLEVEL_MIC64 2
87#define IEEE802154_SCF_SECLEVEL_MIC128 3
88#define IEEE802154_SCF_SECLEVEL_ENC 4
89#define IEEE802154_SCF_SECLEVEL_ENC_MIC32 5
90#define IEEE802154_SCF_SECLEVEL_ENC_MIC64 6
91#define IEEE802154_SCF_SECLEVEL_ENC_MIC128 7
92
alex.bluesman.smirnov@gmail.com719269a2011-11-10 07:38:38 +000093/* MAC footer size */
94#define IEEE802154_MFR_SIZE 2 /* 2 octets */
95
Sergey Lapin9ec76712009-06-08 12:18:48 +000096/* MAC's Command Frames Identifiers */
97#define IEEE802154_CMD_ASSOCIATION_REQ 0x01
98#define IEEE802154_CMD_ASSOCIATION_RESP 0x02
99#define IEEE802154_CMD_DISASSOCIATION_NOTIFY 0x03
100#define IEEE802154_CMD_DATA_REQ 0x04
101#define IEEE802154_CMD_PANID_CONFLICT_NOTIFY 0x05
102#define IEEE802154_CMD_ORPHAN_NOTIFY 0x06
103#define IEEE802154_CMD_BEACON_REQ 0x07
104#define IEEE802154_CMD_COORD_REALIGN_NOTIFY 0x08
105#define IEEE802154_CMD_GTS_REQ 0x09
106
107/*
108 * The return values of MAC operations
109 */
110enum {
111 /*
112 * The requested operation was completed successfully.
113 * For a transmission request, this value indicates
114 * a successful transmission.
115 */
116 IEEE802154_SUCCESS = 0x0,
117
118 /* The beacon was lost following a synchronization request. */
119 IEEE802154_BEACON_LOSS = 0xe0,
120 /*
121 * A transmission could not take place due to activity on the
122 * channel, i.e., the CSMA-CA mechanism has failed.
123 */
124 IEEE802154_CHNL_ACCESS_FAIL = 0xe1,
125 /* The GTS request has been denied by the PAN coordinator. */
126 IEEE802154_DENINED = 0xe2,
127 /* The attempt to disable the transceiver has failed. */
128 IEEE802154_DISABLE_TRX_FAIL = 0xe3,
129 /*
130 * The received frame induces a failed security check according to
131 * the security suite.
132 */
133 IEEE802154_FAILED_SECURITY_CHECK = 0xe4,
134 /*
135 * The frame resulting from secure processing has a length that is
136 * greater than aMACMaxFrameSize.
137 */
138 IEEE802154_FRAME_TOO_LONG = 0xe5,
139 /*
140 * The requested GTS transmission failed because the specified GTS
141 * either did not have a transmit GTS direction or was not defined.
142 */
143 IEEE802154_INVALID_GTS = 0xe6,
144 /*
145 * A request to purge an MSDU from the transaction queue was made using
146 * an MSDU handle that was not found in the transaction table.
147 */
148 IEEE802154_INVALID_HANDLE = 0xe7,
149 /* A parameter in the primitive is out of the valid range.*/
150 IEEE802154_INVALID_PARAMETER = 0xe8,
151 /* No acknowledgment was received after aMaxFrameRetries. */
152 IEEE802154_NO_ACK = 0xe9,
153 /* A scan operation failed to find any network beacons.*/
154 IEEE802154_NO_BEACON = 0xea,
155 /* No response data were available following a request. */
156 IEEE802154_NO_DATA = 0xeb,
157 /* The operation failed because a short address was not allocated. */
158 IEEE802154_NO_SHORT_ADDRESS = 0xec,
159 /*
160 * A receiver enable request was unsuccessful because it could not be
161 * completed within the CAP.
162 */
163 IEEE802154_OUT_OF_CAP = 0xed,
164 /*
165 * A PAN identifier conflict has been detected and communicated to the
166 * PAN coordinator.
167 */
168 IEEE802154_PANID_CONFLICT = 0xee,
169 /* A coordinator realignment command has been received. */
170 IEEE802154_REALIGMENT = 0xef,
171 /* The transaction has expired and its information discarded. */
172 IEEE802154_TRANSACTION_EXPIRED = 0xf0,
173 /* There is no capacity to store the transaction. */
174 IEEE802154_TRANSACTION_OVERFLOW = 0xf1,
175 /*
176 * The transceiver was in the transmitter enabled state when the
177 * receiver was requested to be enabled.
178 */
179 IEEE802154_TX_ACTIVE = 0xf2,
180 /* The appropriate key is not available in the ACL. */
181 IEEE802154_UNAVAILABLE_KEY = 0xf3,
182 /*
183 * A SET/GET request was issued with the identifier of a PIB attribute
184 * that is not supported.
185 */
186 IEEE802154_UNSUPPORTED_ATTR = 0xf4,
187 /*
188 * A request to perform a scan operation failed because the MLME was
189 * in the process of performing a previously initiated scan operation.
190 */
191 IEEE802154_SCAN_IN_PROGRESS = 0xfc,
192};
193
Alexander Aringfa491002014-10-27 17:13:40 +0100194/**
195 * ieee802154_is_valid_psdu_len - check if psdu len is valid
196 * @len: psdu len with (MHR + payload + MFR)
197 */
198static inline bool ieee802154_is_valid_psdu_len(const u8 len)
199{
200 return (len >= IEEE802154_MIN_PSDU_LEN && len <= IEEE802154_MTU);
201}
Sergey Lapin9ec76712009-06-08 12:18:48 +0000202
Alexander Aringcb904b02014-11-02 04:18:45 +0100203/**
204 * ieee802154_is_valid_psdu_len - check if extended addr is valid
205 * @addr: extended addr to check
206 */
207static inline bool ieee802154_is_valid_extended_addr(const __le64 addr)
208{
209 /* These EUI-64 addresses are reserved by IEEE. 0xffffffffffffffff
210 * is used internally as extended to short address broadcast mapping.
211 * This is currently a workaround because neighbor discovery can't
212 * deal with short addresses types right now.
213 */
Dan Carpenter0d8a52f2014-11-04 11:55:09 +0300214 return ((addr != cpu_to_le64(0x0000000000000000ULL)) &&
Alexander Aringc28bee82014-11-02 21:43:02 +0100215 (addr != cpu_to_le64(0xffffffffffffffffULL)));
Alexander Aringcb904b02014-11-02 04:18:45 +0100216}
217
Alexander Aring4ca24ac2014-10-25 09:41:04 +0200218#endif /* LINUX_IEEE802154_H */