blob: 6e50a2a1d4851f77163b0dacf4623b17909363bd [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>
27
alex.bluesman.smirnov@gmail.com719269a2011-11-10 07:38:38 +000028#define IEEE802154_MTU 127
Alexander Aringfa491002014-10-27 17:13:40 +010029#define IEEE802154_MIN_PSDU_LEN 5
alex.bluesman.smirnov@gmail.com719269a2011-11-10 07:38:38 +000030
Sergey Lapin9ec76712009-06-08 12:18:48 +000031#define IEEE802154_FC_TYPE_BEACON 0x0 /* Frame is beacon */
32#define IEEE802154_FC_TYPE_DATA 0x1 /* Frame is data */
33#define IEEE802154_FC_TYPE_ACK 0x2 /* Frame is acknowledgment */
34#define IEEE802154_FC_TYPE_MAC_CMD 0x3 /* Frame is MAC command */
35
36#define IEEE802154_FC_TYPE_SHIFT 0
37#define IEEE802154_FC_TYPE_MASK ((1 << 3) - 1)
38#define IEEE802154_FC_TYPE(x) ((x & IEEE802154_FC_TYPE_MASK) >> IEEE802154_FC_TYPE_SHIFT)
39#define IEEE802154_FC_SET_TYPE(v, x) do { \
40 v = (((v) & ~IEEE802154_FC_TYPE_MASK) | \
41 (((x) << IEEE802154_FC_TYPE_SHIFT) & IEEE802154_FC_TYPE_MASK)); \
42 } while (0)
43
Phoebe Buckheister94b4f6c2014-03-14 21:24:00 +010044#define IEEE802154_FC_SECEN_SHIFT 3
45#define IEEE802154_FC_SECEN (1 << IEEE802154_FC_SECEN_SHIFT)
46#define IEEE802154_FC_FRPEND_SHIFT 4
47#define IEEE802154_FC_FRPEND (1 << IEEE802154_FC_FRPEND_SHIFT)
48#define IEEE802154_FC_ACK_REQ_SHIFT 5
49#define IEEE802154_FC_ACK_REQ (1 << IEEE802154_FC_ACK_REQ_SHIFT)
50#define IEEE802154_FC_INTRA_PAN_SHIFT 6
51#define IEEE802154_FC_INTRA_PAN (1 << IEEE802154_FC_INTRA_PAN_SHIFT)
Sergey Lapin9ec76712009-06-08 12:18:48 +000052
53#define IEEE802154_FC_SAMODE_SHIFT 14
54#define IEEE802154_FC_SAMODE_MASK (3 << IEEE802154_FC_SAMODE_SHIFT)
55#define IEEE802154_FC_DAMODE_SHIFT 10
56#define IEEE802154_FC_DAMODE_MASK (3 << IEEE802154_FC_DAMODE_SHIFT)
57
Phoebe Buckheister94b4f6c2014-03-14 21:24:00 +010058#define IEEE802154_FC_VERSION_SHIFT 12
59#define IEEE802154_FC_VERSION_MASK (3 << IEEE802154_FC_VERSION_SHIFT)
60#define IEEE802154_FC_VERSION(x) ((x & IEEE802154_FC_VERSION_MASK) >> IEEE802154_FC_VERSION_SHIFT)
61
Sergey Lapin9ec76712009-06-08 12:18:48 +000062#define IEEE802154_FC_SAMODE(x) \
63 (((x) & IEEE802154_FC_SAMODE_MASK) >> IEEE802154_FC_SAMODE_SHIFT)
64
65#define IEEE802154_FC_DAMODE(x) \
66 (((x) & IEEE802154_FC_DAMODE_MASK) >> IEEE802154_FC_DAMODE_SHIFT)
67
Phoebe Buckheister94b4f6c2014-03-14 21:24:00 +010068#define IEEE802154_SCF_SECLEVEL_MASK 7
69#define IEEE802154_SCF_SECLEVEL_SHIFT 0
70#define IEEE802154_SCF_SECLEVEL(x) (x & IEEE802154_SCF_SECLEVEL_MASK)
71#define IEEE802154_SCF_KEY_ID_MODE_SHIFT 3
72#define IEEE802154_SCF_KEY_ID_MODE_MASK (3 << IEEE802154_SCF_KEY_ID_MODE_SHIFT)
73#define IEEE802154_SCF_KEY_ID_MODE(x) \
74 ((x & IEEE802154_SCF_KEY_ID_MODE_MASK) >> IEEE802154_SCF_KEY_ID_MODE_SHIFT)
75
76#define IEEE802154_SCF_KEY_IMPLICIT 0
77#define IEEE802154_SCF_KEY_INDEX 1
78#define IEEE802154_SCF_KEY_SHORT_INDEX 2
79#define IEEE802154_SCF_KEY_HW_INDEX 3
Sergey Lapin9ec76712009-06-08 12:18:48 +000080
Phoebe Buckheisterc3a61142014-05-14 17:43:06 +020081#define IEEE802154_SCF_SECLEVEL_NONE 0
82#define IEEE802154_SCF_SECLEVEL_MIC32 1
83#define IEEE802154_SCF_SECLEVEL_MIC64 2
84#define IEEE802154_SCF_SECLEVEL_MIC128 3
85#define IEEE802154_SCF_SECLEVEL_ENC 4
86#define IEEE802154_SCF_SECLEVEL_ENC_MIC32 5
87#define IEEE802154_SCF_SECLEVEL_ENC_MIC64 6
88#define IEEE802154_SCF_SECLEVEL_ENC_MIC128 7
89
alex.bluesman.smirnov@gmail.com719269a2011-11-10 07:38:38 +000090/* MAC footer size */
91#define IEEE802154_MFR_SIZE 2 /* 2 octets */
92
Sergey Lapin9ec76712009-06-08 12:18:48 +000093/* MAC's Command Frames Identifiers */
94#define IEEE802154_CMD_ASSOCIATION_REQ 0x01
95#define IEEE802154_CMD_ASSOCIATION_RESP 0x02
96#define IEEE802154_CMD_DISASSOCIATION_NOTIFY 0x03
97#define IEEE802154_CMD_DATA_REQ 0x04
98#define IEEE802154_CMD_PANID_CONFLICT_NOTIFY 0x05
99#define IEEE802154_CMD_ORPHAN_NOTIFY 0x06
100#define IEEE802154_CMD_BEACON_REQ 0x07
101#define IEEE802154_CMD_COORD_REALIGN_NOTIFY 0x08
102#define IEEE802154_CMD_GTS_REQ 0x09
103
104/*
105 * The return values of MAC operations
106 */
107enum {
108 /*
109 * The requested operation was completed successfully.
110 * For a transmission request, this value indicates
111 * a successful transmission.
112 */
113 IEEE802154_SUCCESS = 0x0,
114
115 /* The beacon was lost following a synchronization request. */
116 IEEE802154_BEACON_LOSS = 0xe0,
117 /*
118 * A transmission could not take place due to activity on the
119 * channel, i.e., the CSMA-CA mechanism has failed.
120 */
121 IEEE802154_CHNL_ACCESS_FAIL = 0xe1,
122 /* The GTS request has been denied by the PAN coordinator. */
123 IEEE802154_DENINED = 0xe2,
124 /* The attempt to disable the transceiver has failed. */
125 IEEE802154_DISABLE_TRX_FAIL = 0xe3,
126 /*
127 * The received frame induces a failed security check according to
128 * the security suite.
129 */
130 IEEE802154_FAILED_SECURITY_CHECK = 0xe4,
131 /*
132 * The frame resulting from secure processing has a length that is
133 * greater than aMACMaxFrameSize.
134 */
135 IEEE802154_FRAME_TOO_LONG = 0xe5,
136 /*
137 * The requested GTS transmission failed because the specified GTS
138 * either did not have a transmit GTS direction or was not defined.
139 */
140 IEEE802154_INVALID_GTS = 0xe6,
141 /*
142 * A request to purge an MSDU from the transaction queue was made using
143 * an MSDU handle that was not found in the transaction table.
144 */
145 IEEE802154_INVALID_HANDLE = 0xe7,
146 /* A parameter in the primitive is out of the valid range.*/
147 IEEE802154_INVALID_PARAMETER = 0xe8,
148 /* No acknowledgment was received after aMaxFrameRetries. */
149 IEEE802154_NO_ACK = 0xe9,
150 /* A scan operation failed to find any network beacons.*/
151 IEEE802154_NO_BEACON = 0xea,
152 /* No response data were available following a request. */
153 IEEE802154_NO_DATA = 0xeb,
154 /* The operation failed because a short address was not allocated. */
155 IEEE802154_NO_SHORT_ADDRESS = 0xec,
156 /*
157 * A receiver enable request was unsuccessful because it could not be
158 * completed within the CAP.
159 */
160 IEEE802154_OUT_OF_CAP = 0xed,
161 /*
162 * A PAN identifier conflict has been detected and communicated to the
163 * PAN coordinator.
164 */
165 IEEE802154_PANID_CONFLICT = 0xee,
166 /* A coordinator realignment command has been received. */
167 IEEE802154_REALIGMENT = 0xef,
168 /* The transaction has expired and its information discarded. */
169 IEEE802154_TRANSACTION_EXPIRED = 0xf0,
170 /* There is no capacity to store the transaction. */
171 IEEE802154_TRANSACTION_OVERFLOW = 0xf1,
172 /*
173 * The transceiver was in the transmitter enabled state when the
174 * receiver was requested to be enabled.
175 */
176 IEEE802154_TX_ACTIVE = 0xf2,
177 /* The appropriate key is not available in the ACL. */
178 IEEE802154_UNAVAILABLE_KEY = 0xf3,
179 /*
180 * A SET/GET request was issued with the identifier of a PIB attribute
181 * that is not supported.
182 */
183 IEEE802154_UNSUPPORTED_ATTR = 0xf4,
184 /*
185 * A request to perform a scan operation failed because the MLME was
186 * in the process of performing a previously initiated scan operation.
187 */
188 IEEE802154_SCAN_IN_PROGRESS = 0xfc,
189};
190
Alexander Aringfa491002014-10-27 17:13:40 +0100191/**
192 * ieee802154_is_valid_psdu_len - check if psdu len is valid
193 * @len: psdu len with (MHR + payload + MFR)
194 */
195static inline bool ieee802154_is_valid_psdu_len(const u8 len)
196{
197 return (len >= IEEE802154_MIN_PSDU_LEN && len <= IEEE802154_MTU);
198}
Sergey Lapin9ec76712009-06-08 12:18:48 +0000199
Alexander Aring4ca24ac2014-10-25 09:41:04 +0200200#endif /* LINUX_IEEE802154_H */