]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/net80211/ieee80211.h
zfs: merge openzfs/zfs@f795e90a1
[FreeBSD/FreeBSD.git] / sys / net80211 / ieee80211.h
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2001 Atsushi Onoe
5  * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 #ifndef _NET80211_IEEE80211_H_
29 #define _NET80211_IEEE80211_H_
30
31 /*
32  * 802.11 protocol definitions.
33  */
34
35 #define IEEE80211_ADDR_LEN      6               /* size of 802.11 address */
36 /* is 802.11 address multicast/broadcast? */
37 #define IEEE80211_IS_MULTICAST(_a)      (*(_a) & 0x01)
38
39 #ifdef _KERNEL
40 extern const uint8_t ieee80211broadcastaddr[];
41 #endif
42
43 typedef uint16_t ieee80211_seq;
44
45 /* IEEE 802.11 PLCP header */
46 struct ieee80211_plcp_hdr {
47         uint16_t        i_sfd;
48         uint8_t         i_signal;
49         uint8_t         i_service;
50         uint16_t        i_length;
51         uint16_t        i_crc;
52 } __packed;
53
54 #define IEEE80211_PLCP_SFD      0xF3A0 
55 #define IEEE80211_PLCP_SERVICE  0x00
56 #define IEEE80211_PLCP_SERVICE_LOCKED   0x04
57 #define IEEE80211_PLCL_SERVICE_PBCC     0x08
58 #define IEEE80211_PLCP_SERVICE_LENEXT5  0x20
59 #define IEEE80211_PLCP_SERVICE_LENEXT6  0x40
60 #define IEEE80211_PLCP_SERVICE_LENEXT7  0x80
61
62 /*
63  * generic definitions for IEEE 802.11 frames
64  */
65 struct ieee80211_frame {
66         uint8_t         i_fc[2];
67         uint8_t         i_dur[2];
68         uint8_t         i_addr1[IEEE80211_ADDR_LEN];
69         uint8_t         i_addr2[IEEE80211_ADDR_LEN];
70         uint8_t         i_addr3[IEEE80211_ADDR_LEN];
71         uint8_t         i_seq[2];
72         /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
73         /* see below */
74 } __packed;
75
76 struct ieee80211_qosframe {
77         uint8_t         i_fc[2];
78         uint8_t         i_dur[2];
79         uint8_t         i_addr1[IEEE80211_ADDR_LEN];
80         uint8_t         i_addr2[IEEE80211_ADDR_LEN];
81         uint8_t         i_addr3[IEEE80211_ADDR_LEN];
82         uint8_t         i_seq[2];
83         uint8_t         i_qos[2];
84         /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
85         /* see below */
86 } __packed;
87
88 struct ieee80211_qoscntl {
89         uint8_t         i_qos[2];
90 };
91
92 struct ieee80211_frame_addr4 {
93         uint8_t         i_fc[2];
94         uint8_t         i_dur[2];
95         uint8_t         i_addr1[IEEE80211_ADDR_LEN];
96         uint8_t         i_addr2[IEEE80211_ADDR_LEN];
97         uint8_t         i_addr3[IEEE80211_ADDR_LEN];
98         uint8_t         i_seq[2];
99         uint8_t         i_addr4[IEEE80211_ADDR_LEN];
100 } __packed;
101
102 struct ieee80211_qosframe_addr4 {
103         uint8_t         i_fc[2];
104         uint8_t         i_dur[2];
105         uint8_t         i_addr1[IEEE80211_ADDR_LEN];
106         uint8_t         i_addr2[IEEE80211_ADDR_LEN];
107         uint8_t         i_addr3[IEEE80211_ADDR_LEN];
108         uint8_t         i_seq[2];
109         uint8_t         i_addr4[IEEE80211_ADDR_LEN];
110         uint8_t         i_qos[2];
111 } __packed;
112
113 #define IEEE80211_FC0_VERSION_MASK              0x03
114 #define IEEE80211_FC0_VERSION_SHIFT             0
115 #define IEEE80211_FC0_VERSION_0                 0x00
116 #define IEEE80211_FC0_TYPE_MASK                 0x0c
117 #define IEEE80211_FC0_TYPE_SHIFT                2
118 #define IEEE80211_FC0_TYPE_MGT                  0x00    /* Management */
119 #define IEEE80211_FC0_TYPE_CTL                  0x04    /* Control */
120 #define IEEE80211_FC0_TYPE_DATA                 0x08    /* Data */
121 #define IEEE80211_FC0_TYPE_EXT                  0x0c    /* Extension */
122
123 #define IEEE80211_FC0_SUBTYPE_MASK              0xf0
124 #define IEEE80211_FC0_SUBTYPE_SHIFT             4
125 /* 802.11-2020 Table 9-1-Valid type and subtype combinations */
126 /* For type 00 Management (IEEE80211_FC0_TYPE_MGT) */
127 #define IEEE80211_FC0_SUBTYPE_ASSOC_REQ         0x00    /* Association Request */
128 #define IEEE80211_FC0_SUBTYPE_ASSOC_RESP        0x10    /* Association Response */
129 #define IEEE80211_FC0_SUBTYPE_REASSOC_REQ       0x20    /* Reassociation Request */
130 #define IEEE80211_FC0_SUBTYPE_REASSOC_RESP      0x30    /* Reassociation Response */
131 #define IEEE80211_FC0_SUBTYPE_PROBE_REQ         0x40    /* Probe Request */
132 #define IEEE80211_FC0_SUBTYPE_PROBE_RESP        0x50    /* Probe Response */
133 #define IEEE80211_FC0_SUBTYPE_TIMING_ADV        0x60    /* Timing Advertisement */
134 /* 0111 Reserved                                0x70 */
135 #define IEEE80211_FC0_SUBTYPE_BEACON            0x80    /* Beacon */
136 #define IEEE80211_FC0_SUBTYPE_ATIM              0x90    /* ATIM */
137 #define IEEE80211_FC0_SUBTYPE_DISASSOC          0xa0    /* Disassociation */
138 #define IEEE80211_FC0_SUBTYPE_AUTH              0xb0    /* Authentication */
139 #define IEEE80211_FC0_SUBTYPE_DEAUTH            0xc0    /* Deauthentication */
140 #define IEEE80211_FC0_SUBTYPE_ACTION            0xd0    /* Action */
141 #define IEEE80211_FC0_SUBTYPE_ACTION_NOACK      0xe0    /* Action No Ack */
142 /* 1111 Reserved                                0xf0 */
143 /* For type 01 Control (IEEE80211_FC0_TYPE_CTL) */
144 /* 0000-0001 Reserved                           0x00-0x10 */
145 #define IEEE80211_FC0_SUBTYPE_TRIGGER           0x20    /* Trigger, 80211ax-2021 */
146 #define IEEE80211_FC0_SUBTYPE_TACK              0x30    /* TACK */
147 #define IEEE80211_FC0_SUBTYPE_BF_REPORT_POLL    0x40    /* Beamforming Report Poll */
148 #define IEEE80211_FC0_SUBTYPE_VHT_HE_NDP        0x50    /* VHT/HE NDP Announcement, 80211ac/ax-2013/2021 */
149 #define IEEE80211_FC0_SUBTYPE_CTL_EXT           0x60    /* Control Frame Extension */
150 #define IEEE80211_FC0_SUBTYPE_CONTROL_WRAP      0x70    /* Control Wrapper */
151 #define IEEE80211_FC0_SUBTYPE_BAR               0x80    /* Block Ack Request (BlockAckReq) */
152 #define IEEE80211_FC0_SUBTYPE_BA                0x90    /* Block Ack (BlockAck) */
153 #define IEEE80211_FC0_SUBTYPE_PS_POLL           0xa0    /* PS-Poll */
154 #define IEEE80211_FC0_SUBTYPE_RTS               0xb0    /* RTS */
155 #define IEEE80211_FC0_SUBTYPE_CTS               0xc0    /* CTS */
156 #define IEEE80211_FC0_SUBTYPE_ACK               0xd0    /* Ack */
157 #define IEEE80211_FC0_SUBTYPE_CF_END            0xe0    /* CF-End */
158 #define IEEE80211_FC0_SUBTYPE_CF_END_ACK        0xf0    /* 1111 Reserved - what was CF_END_ACK? */
159 /* For type 10 Data (IEEE80211_FC0_TYPE_DATA) */
160 #define IEEE80211_FC0_SUBTYPE_DATA              0x00    /* Data */
161 /* 0001-0011 Reserved                           0x10-0x30 */    /* Were: CF_ACK, CF_POLL, CF_ACPL */
162 #define IEEE80211_FC0_SUBTYPE_NODATA            0x40    /* Null */
163 /* 0101-0111 Reserved                           0x50-0x70 */    /* Were: CFACK, CFPOLL, CF_ACK_CF_ACK */
164 #define IEEE80211_FC0_SUBTYPE_QOS_DATA          0x80    /* QoS Data */
165 #define IEEE80211_FC0_SUBTYPE_QOS_DATA_CFACK    0x90    /* QoS Data +CF-Ack */
166 #define IEEE80211_FC0_SUBTYPE_QOS_DATA_CFPOLL   0xa0    /* QoS Data +CF-Poll */
167 #define IEEE80211_FC0_SUBTYPE_QOS_DATA_CFACKPOLL 0xb0   /* QoS Data +CF-Ack +CF-Poll */
168 #define IEEE80211_FC0_SUBTYPE_QOS_NULL          0xc0    /* QoS Null */
169 /* 1101 Reserved                                0xd0 */
170 #define IEEE80211_FC0_SUBTYPE_QOS_CFPOLL        0xe0    /* QoS CF-Poll */
171 #define IEEE80211_FC0_SUBTYPE_QOS_CFACKPOLL     0xf0    /* QoS CF-Ack +CF-Poll */
172 /* For type 11 Extension (IEEE80211_FC0_TYPE_EXT) */
173 #define IEEE80211_FC0_SUBTYPE_DMG_BEACON        0x00    /* DMG Beacon */
174 #define IEEE80211_FC0_SUBTYPE_S1G_BEACON        0x10    /* S1G Beacon */
175 /* 0010-1111 Reserved                           0x20-0xff */
176
177 /* 802.11-2020 Table 9-2-Control Frame Extension */
178 /* Reusing B11..B8, part of FC1 */
179 #define IEEE80211_CTL_EXT_SECTOR_ACK            0x00    /* Sector Ack, 80211ay-2021 */
180 #define IEEE80211_CTL_EXT_BA_SCHED              0x01    /* Block Ack Schedule, 80211ay-2021 */
181 #define IEEE80211_CTL_EXT_POLL                  0x02    /* Poll */
182 #define IEEE80211_CTL_EXT_SPR                   0x03    /* SPR */
183 #define IEEE80211_CTL_EXT_GRANT                 0x04    /* Grant */
184 #define IEEE80211_CTL_EXT_DMG_CTS               0x05    /* DMG CTS */
185 #define IEEE80211_CTL_EXT_DMG_DTS               0x06    /* DMG DTS */
186 #define IEEE80211_CTL_EXT_GRANT_ACK             0x07    /* Grant Ack */
187 #define IEEE80211_CTL_EXT_SSW                   0x08    /* SSW */
188 #define IEEE80211_CTL_EXT_SSW_FBACK             0x09    /* SSW-Feedback */
189 #define IEEE80211_CTL_EXT_SSW_ACK               0x0a    /* SSW-Ack */
190 #define IEEE80211_CTL_EXT_TDD_BF                0x0b    /* TDD Beamforming, 80211ay-2021 */
191 /* 1100-1111 Reserved                           0xc-0xf */
192
193 #define IEEE80211_IS_MGMT(wh)                                   \
194         (!! (((wh)->i_fc[0] & IEEE80211_FC0_TYPE_MASK)          \
195             == IEEE80211_FC0_TYPE_MGT))
196 #define IEEE80211_IS_CTL(wh)                                    \
197         (!! (((wh)->i_fc[0] & IEEE80211_FC0_TYPE_MASK)          \
198             == IEEE80211_FC0_TYPE_CTL))
199 #define IEEE80211_IS_DATA(wh)                                   \
200         (!! (((wh)->i_fc[0] & IEEE80211_FC0_TYPE_MASK)          \
201             == IEEE80211_FC0_TYPE_DATA))
202 #define IEEE80211_IS_EXT(wh)                                    \
203         (!! (((wh)->i_fc[0] & IEEE80211_FC0_TYPE_MASK)          \
204             == IEEE80211_FC0_TYPE_EXT))
205
206 #define IEEE80211_FC0_QOSDATA \
207         (IEEE80211_FC0_TYPE_DATA|IEEE80211_FC0_SUBTYPE_QOS_DATA|IEEE80211_FC0_VERSION_0)
208
209 #define IEEE80211_IS_QOSDATA(wh) \
210         ((wh)->i_fc[0] == IEEE80211_FC0_QOSDATA)
211
212 #define IEEE80211_FC1_DIR_MASK                  0x03
213 #define IEEE80211_FC1_DIR_NODS                  0x00    /* STA->STA */
214 #define IEEE80211_FC1_DIR_TODS                  0x01    /* STA->AP  */
215 #define IEEE80211_FC1_DIR_FROMDS                0x02    /* AP ->STA */
216 #define IEEE80211_FC1_DIR_DSTODS                0x03    /* AP ->AP  */
217
218 #define IEEE80211_IS_DSTODS(wh) \
219         (((wh)->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS)
220
221 #define IEEE80211_FC1_MORE_FRAG                 0x04
222 #define IEEE80211_FC1_RETRY                     0x08
223 #define IEEE80211_FC1_PWR_MGT                   0x10
224 #define IEEE80211_FC1_MORE_DATA                 0x20
225 #define IEEE80211_FC1_PROTECTED                 0x40
226 #define IEEE80211_FC1_ORDER                     0x80
227
228 #define IEEE80211_IS_PROTECTED(wh) \
229         ((wh)->i_fc[1] & IEEE80211_FC1_PROTECTED)
230
231 #define IEEE80211_HAS_SEQ(type, subtype) \
232         ((type) != IEEE80211_FC0_TYPE_CTL && \
233         !((type) == IEEE80211_FC0_TYPE_DATA && \
234          ((subtype) & IEEE80211_FC0_SUBTYPE_QOS_NULL) == \
235                       IEEE80211_FC0_SUBTYPE_QOS_NULL))
236 #define IEEE80211_SEQ_FRAG_MASK                 0x000f
237 #define IEEE80211_SEQ_FRAG_SHIFT                0
238 #define IEEE80211_SEQ_SEQ_MASK                  0xfff0
239 #define IEEE80211_SEQ_SEQ_SHIFT                 4
240 #define IEEE80211_SEQ_RANGE                     4096
241
242 #define IEEE80211_SEQ_ADD(seq, incr) \
243         (((seq) + (incr)) & (IEEE80211_SEQ_RANGE-1))
244 #define IEEE80211_SEQ_INC(seq)  IEEE80211_SEQ_ADD(seq,1)
245 #define IEEE80211_SEQ_SUB(a, b) \
246         (((a) + IEEE80211_SEQ_RANGE - (b)) & (IEEE80211_SEQ_RANGE-1))
247
248 #define IEEE80211_SEQ_BA_RANGE                  2048    /* 2^11 */
249 #define IEEE80211_SEQ_BA_BEFORE(a, b) \
250         (IEEE80211_SEQ_SUB(b, a+1) < IEEE80211_SEQ_BA_RANGE-1)
251
252 #define IEEE80211_NWID_LEN                      32
253 #define IEEE80211_MESHID_LEN                    32
254
255 #define IEEE80211_QOS_CTL_LEN                   2
256
257 #define IEEE80211_QOS_TXOP                      0x00ff
258 /* bit 8 is reserved */
259 #define IEEE80211_QOS_AMSDU                     0x80
260 #define IEEE80211_QOS_AMSDU_S                   7
261 #define IEEE80211_QOS_ACKPOLICY                 0x60
262 #define IEEE80211_QOS_ACKPOLICY_S               5
263 #define IEEE80211_QOS_ACKPOLICY_NOACK           0x20    /* No ACK required */
264 #define IEEE80211_QOS_ACKPOLICY_BA              0x60    /* Block ACK */
265 #define IEEE80211_QOS_EOSP                      0x10    /* EndOfService Period*/
266 #define IEEE80211_QOS_EOSP_S                    4
267 #define IEEE80211_QOS_TID                       0x0f
268 /* qos[1] byte used for all frames sent by mesh STAs in a mesh BSS */
269 #define IEEE80211_QOS_MC                        0x01    /* Mesh control */
270 /* Mesh power save level*/
271 #define IEEE80211_QOS_MESH_PSL                  0x02
272 /* Mesh Receiver Service Period Initiated */
273 #define IEEE80211_QOS_RSPI                      0x04
274 /* bits 11 to 15 reserved */
275
276 /* does frame have QoS sequence control data */
277 #define IEEE80211_QOS_HAS_SEQ(wh) \
278         (((wh)->i_fc[0] & \
279           (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_QOS_DATA)) == \
280           (IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS_DATA))
281
282 /*
283  * WME/802.11e information element.
284  */
285 struct ieee80211_wme_info {
286         uint8_t         wme_id;         /* IEEE80211_ELEMID_VENDOR */
287         uint8_t         wme_len;        /* length in bytes */
288         uint8_t         wme_oui[3];     /* 0x00, 0x50, 0xf2 */
289         uint8_t         wme_type;       /* OUI type */
290         uint8_t         wme_subtype;    /* OUI subtype */
291         uint8_t         wme_version;    /* spec revision */
292         uint8_t         wme_info;       /* QoS info */
293 } __packed;
294
295 /*
296  * WME/802.11e Tspec Element
297  */
298 struct ieee80211_wme_tspec {
299         uint8_t         ts_id;
300         uint8_t         ts_len;
301         uint8_t         ts_oui[3];
302         uint8_t         ts_oui_type;
303         uint8_t         ts_oui_subtype;
304         uint8_t         ts_version;
305         uint8_t         ts_tsinfo[3];
306         uint8_t         ts_nom_msdu[2];
307         uint8_t         ts_max_msdu[2];
308         uint8_t         ts_min_svc[4];
309         uint8_t         ts_max_svc[4];
310         uint8_t         ts_inactv_intv[4];
311         uint8_t         ts_susp_intv[4];
312         uint8_t         ts_start_svc[4];
313         uint8_t         ts_min_rate[4];
314         uint8_t         ts_mean_rate[4];
315         uint8_t         ts_max_burst[4];
316         uint8_t         ts_min_phy[4];
317         uint8_t         ts_peak_rate[4];
318         uint8_t         ts_delay[4];
319         uint8_t         ts_surplus[2];
320         uint8_t         ts_medium_time[2];
321 } __packed;
322
323 /*
324  * WME AC parameter field
325  */
326 struct ieee80211_wme_acparams {
327         uint8_t         acp_aci_aifsn;
328         uint8_t         acp_logcwminmax;
329         uint16_t        acp_txop;
330 } __packed;
331
332 #define WME_NUM_AC              4       /* 4 AC categories */
333 #define WME_NUM_TID             16      /* 16 tids */
334
335 #define WME_PARAM_ACI           0x60    /* Mask for ACI field */
336 #define WME_PARAM_ACI_S         5       /* Shift for ACI field */
337 #define WME_PARAM_ACM           0x10    /* Mask for ACM bit */
338 #define WME_PARAM_ACM_S         4       /* Shift for ACM bit */
339 #define WME_PARAM_AIFSN         0x0f    /* Mask for aifsn field */
340 #define WME_PARAM_AIFSN_S       0       /* Shift for aifsn field */
341 #define WME_PARAM_LOGCWMIN      0x0f    /* Mask for CwMin field (in log) */
342 #define WME_PARAM_LOGCWMIN_S    0       /* Shift for CwMin field */
343 #define WME_PARAM_LOGCWMAX      0xf0    /* Mask for CwMax field (in log) */
344 #define WME_PARAM_LOGCWMAX_S    4       /* Shift for CwMax field */
345
346 #define WME_AC_TO_TID(_ac) (       \
347         ((_ac) == WME_AC_VO) ? 6 : \
348         ((_ac) == WME_AC_VI) ? 5 : \
349         ((_ac) == WME_AC_BK) ? 1 : \
350         0)
351
352 #define TID_TO_WME_AC(_tid) (      \
353         ((_tid) == 0 || (_tid) == 3) ? WME_AC_BE : \
354         ((_tid) < 3) ? WME_AC_BK : \
355         ((_tid) < 6) ? WME_AC_VI : \
356         WME_AC_VO)
357
358 /*
359  * WME Parameter Element
360  */
361 struct ieee80211_wme_param {
362         uint8_t         param_id;
363         uint8_t         param_len;
364         uint8_t         param_oui[3];
365         uint8_t         param_oui_type;
366         uint8_t         param_oui_subtype;
367         uint8_t         param_version;
368         uint8_t         param_qosInfo;
369 #define WME_QOSINFO_COUNT       0x0f    /* Mask for param count field */
370         uint8_t         param_reserved;
371         struct ieee80211_wme_acparams   params_acParams[WME_NUM_AC];
372 } __packed;
373
374 /*
375  * WME U-APSD qos info field defines
376  */
377 #define WME_CAPINFO_UAPSD_EN                    0x00000080
378 #define WME_CAPINFO_UAPSD_VO                    0x00000001
379 #define WME_CAPINFO_UAPSD_VI                    0x00000002
380 #define WME_CAPINFO_UAPSD_BK                    0x00000004
381 #define WME_CAPINFO_UAPSD_BE                    0x00000008
382 #define WME_CAPINFO_UAPSD_ACFLAGS_SHIFT         0
383 #define WME_CAPINFO_UAPSD_ACFLAGS_MASK          0xF
384 #define WME_CAPINFO_UAPSD_MAXSP_SHIFT           5
385 #define WME_CAPINFO_UAPSD_MAXSP_MASK            0x3
386 #define WME_CAPINFO_IE_OFFSET                   8
387 #define WME_UAPSD_MAXSP(_qosinfo)                               \
388             (((_qosinfo) >> WME_CAPINFO_UAPSD_MAXSP_SHIFT) &    \
389             WME_CAPINFO_UAPSD_MAXSP_MASK)
390 #define WME_UAPSD_AC_ENABLED(_ac, _qosinfo)                     \
391             ((1 << (3 - (_ac))) & (                             \
392             ((_qosinfo) >> WME_CAPINFO_UAPSD_ACFLAGS_SHIFT) &   \
393             WME_CAPINFO_UAPSD_ACFLAGS_MASK))
394
395 /*
396  * Management Notification Frame
397  */
398 struct ieee80211_mnf {
399         uint8_t         mnf_category;
400         uint8_t         mnf_action;
401         uint8_t         mnf_dialog;
402         uint8_t         mnf_status;
403 } __packed;
404 #define MNF_SETUP_REQ   0
405 #define MNF_SETUP_RESP  1
406 #define MNF_TEARDOWN    2
407
408 /* 
409  * 802.11n Management Action Frames 
410  */
411 /* generic frame format */
412 struct ieee80211_action {
413         uint8_t         ia_category;
414         uint8_t         ia_action;
415 } __packed;
416
417 /* 80211-2020 Table 9-51-Category values */
418 #define IEEE80211_ACTION_CAT_SM                 0       /* 9.6.2 Spectrum Management */
419 #define IEEE80211_ACTION_CAT_QOS                1       /* 9.6.3 QoS */
420 /* Reserved                                     2       was IEEE80211_ACTION_CAT_DLS */
421 #define IEEE80211_ACTION_CAT_BA                 3       /* 9.6.4 Block Ack */
422 #define IEEE80211_ACTION_CAT_PUBLIC             4       /* 9.6.7 Public */
423 #define IEEE80211_ACTION_CAT_RADIO_MEASUREMENT  5       /* 9.6.6 Radio Measurement */
424 #define IEEE80211_ACTION_CAT_FAST_BBS_TRANSITION 6      /* 9.6.8 Fast BSS Transition */
425 #define IEEE80211_ACTION_CAT_HT                 7       /* 9.6.11 HT */
426 #define IEEE80211_ACTION_CAT_SA_QUERY           8       /* 9.6.9 SA Query */
427 #define IEEE80211_ACTION_CAT_PROTECTED_DUAL_OF_PUBLIC_ACTION 9 /* 9.6.10 Protected Dual of Public Action */
428 #define IEEE80211_ACTION_CAT_WNM                10      /* 9.6.13 WNM */
429 #define IEEE80211_ACTION_CAT_UNPROTECTED_WNM    11      /* 9.6.14 Unprotected WNM */
430 #define IEEE80211_ACTION_CAT_TDLS               12      /* 9.6.12 TDLS */
431 #define IEEE80211_ACTION_CAT_MESH               13      /* 9.6.16 Mesh */
432 #define IEEE80211_ACTION_CAT_MULTIHOP           14      /* 9.6.17 Multihop */
433 #define IEEE80211_ACTION_CAT_SELF_PROT          15      /* 9.6.15 Self-protected */
434 #define IEEE80211_ACTION_CAT_DMG                16      /* 9.6.19 DMG */
435 /* Reserved                                     17      (R)Wi-Fi Alliance */
436 #define IEEE80211_ACTION_CAT_FAST_SESSION_TRANSFER 18   /* 9.6.20 Fast Session Transfer */
437 #define IEEE80211_ACTION_CAT_ROBUST_AV_STREAMING 19     /* 9.6.18 Robust AV Streaming */
438 #define IEEE80211_ACTION_CAT_UNPROTECTED_DMG    20      /* 9.6.21 Unprotected DMG */
439 #define IEEE80211_ACTION_CAT_VHT                21      /* 9.6.22 VHT */
440 #define IEEE80211_ACTION_CAT_UNPROTECTED_S1G    22      /* 9.6.24 Unprotected S1G */
441 #define IEEE80211_ACTION_CAT_S1G                23      /* 9.6.25 S1G */
442 #define IEEE80211_ACTION_CAT_FLOW_CONTROL       24      /* 9.6.26 Flow Control */
443 #define IEEE80211_ACTION_CAT_CTL_RESP_MCS_NEG   25      /* 9.6.27 Control Response MCS Negotiation */
444 #define IEEE80211_ACTION_CAT_FILS               26      /* 9.6.23 FILS */
445 #define IEEE80211_ACTION_CAT_CDMG               27      /* 9.6.28 CDMG */
446 #define IEEE80211_ACTION_CAT_CMMG               28      /* 9.6.29 CMMG */
447 #define IEEE80211_ACTION_CAT_GLK                29      /* 9.6.30 GLK */
448 #define IEEE80211_ACTION_CAT_HE                 30      /* 9.6.31 HE, 80211ax-2021 */
449 #define IEEE80211_ACTION_CAT_PROTECTED_HE       31      /* 9.6.32 Protected HE, 80211ax-2021 */
450 /* Reserved                                     32-125 */
451 #define IEEE80211_ACTION_CAT_VENDOR_SPECIFIC_PROTECTED 126 /* 9.6.5 Vendor-specific Protected */
452 #define IEEE80211_ACTION_CAT_VENDOR             127     /* 9.6.5 Vendor-specific */
453 /* Error                                        128-255 */
454
455
456 /* 80211-2020 Table 9-346-Spectrum Management Action field values */
457 enum ieee80211_action_sm {
458         IEEE80211_ACTION_SM_SMREQ               = 0,    /* Spectrum Measurement Request */
459         IEEE80211_ACTION_SM_SMREP               = 1,    /* Spectrum Measurement Report */
460         IEEE80211_ACTION_SM_TPCREQ              = 2,    /* TPC Request */
461         IEEE80211_ACTION_SM_TPCREP              = 3,    /* TPC Report */
462         IEEE80211_ACTION_SM_CSA                 = 4,    /* Channel Switch Announcement */
463         /* Reserved                             = 5-255 */
464 };
465
466 /* 80211-2020 Table 9-363-Radio Measurement Action field values */
467 enum ieee80211_action_radio_measurement {
468         IEEE80211_ACTION_RADIO_MEASUREMENT_RMREQ        = 0,    /* Radio Measurement Request */
469         IEEE80211_ACTION_RADIO_MEASUREMENT_RMREP        = 1,    /* Radio Measurement Report */
470         IEEE80211_ACTION_RADIO_MEASUREMENT_LMREQ        = 2,    /* Link Measurement Request */
471         IEEE80211_ACTION_RADIO_MEASUREMENT_LMREP        = 3,    /* Link Measurement Report */
472         IEEE80211_ACTION_RADIO_MEASUREMENT_NRREQ        = 4,    /* Neighbor Report Request */
473         IEEE80211_ACTION_RADIO_MEASUREMENT_NRRESP       = 5,    /* Neighbor Report Response */
474         /* Reserved                                     = 6-255 */
475 };
476
477 #define IEEE80211_ACTION_HT_TXCHWIDTH   0       /* recommended xmit chan width*/
478 #define IEEE80211_ACTION_HT_MIMOPWRSAVE 1       /* MIMO power save */
479
480 /* HT - recommended transmission channel width */
481 struct ieee80211_action_ht_txchwidth {
482         struct ieee80211_action at_header;
483         uint8_t         at_chwidth;     
484 } __packed;
485
486 #define IEEE80211_A_HT_TXCHWIDTH_20     0
487 #define IEEE80211_A_HT_TXCHWIDTH_2040   1
488
489 /* HT - MIMO Power Save (NB: D2.04) */
490 struct ieee80211_action_ht_mimopowersave {
491         struct ieee80211_action am_header;
492         uint8_t         am_control;
493 } __packed;
494
495 #define IEEE80211_A_HT_MIMOPWRSAVE_ENA          0x01    /* PS enabled */
496 #define IEEE80211_A_HT_MIMOPWRSAVE_MODE         0x02
497 #define IEEE80211_A_HT_MIMOPWRSAVE_MODE_S       1
498 #define IEEE80211_A_HT_MIMOPWRSAVE_DYNAMIC      0x02    /* Dynamic Mode */
499 #define IEEE80211_A_HT_MIMOPWRSAVE_STATIC       0x00    /* no SM packets */
500 /* bits 2-7 reserved */
501
502 /* Block Ack actions */
503 #define IEEE80211_ACTION_BA_ADDBA_REQUEST       0   /* ADDBA request */
504 #define IEEE80211_ACTION_BA_ADDBA_RESPONSE      1   /* ADDBA response */
505 #define IEEE80211_ACTION_BA_DELBA               2   /* DELBA */
506
507 /* Block Ack Parameter Set */
508 #define IEEE80211_BAPS_BUFSIZ   0xffc0          /* buffer size */
509 #define IEEE80211_BAPS_BUFSIZ_S 6
510 #define IEEE80211_BAPS_TID      0x003c          /* TID */
511 #define IEEE80211_BAPS_TID_S    2
512 #define IEEE80211_BAPS_POLICY   0x0002          /* block ack policy */
513 #define IEEE80211_BAPS_POLICY_S 1
514 #define IEEE80211_BAPS_AMSDU    0x0001          /* A-MSDU permitted */
515 #define IEEE80211_BAPS_AMSDU_S  0
516
517 #define IEEE80211_BAPS_POLICY_DELAYED   (0<<IEEE80211_BAPS_POLICY_S)
518 #define IEEE80211_BAPS_POLICY_IMMEDIATE (1<<IEEE80211_BAPS_POLICY_S)
519
520 /* Block Ack Sequence Control */
521 #define IEEE80211_BASEQ_START   0xfff0          /* starting seqnum */
522 #define IEEE80211_BASEQ_START_S 4
523 #define IEEE80211_BASEQ_FRAG    0x000f          /* fragment number */
524 #define IEEE80211_BASEQ_FRAG_S  0
525
526 /* Delayed Block Ack Parameter Set */
527 #define IEEE80211_DELBAPS_TID   0xf000          /* TID */
528 #define IEEE80211_DELBAPS_TID_S 12
529 #define IEEE80211_DELBAPS_INIT  0x0800          /* initiator */
530 #define IEEE80211_DELBAPS_INIT_S 11
531
532 /* BA - ADDBA request */
533 struct ieee80211_action_ba_addbarequest {
534         struct ieee80211_action rq_header;
535         uint8_t         rq_dialogtoken;
536         uint16_t        rq_baparamset;
537         uint16_t        rq_batimeout;           /* in TUs */
538         uint16_t        rq_baseqctl;
539 } __packed;
540
541 /* BA - ADDBA response */
542 struct ieee80211_action_ba_addbaresponse {
543         struct ieee80211_action rs_header;
544         uint8_t         rs_dialogtoken;
545         uint16_t        rs_statuscode;
546         uint16_t        rs_baparamset; 
547         uint16_t        rs_batimeout;           /* in TUs */
548 } __packed;
549
550 /* BA - DELBA */
551 struct ieee80211_action_ba_delba {
552         struct ieee80211_action dl_header;
553         uint16_t        dl_baparamset;
554         uint16_t        dl_reasoncode;
555 } __packed;
556
557 /* BAR Control */
558 #define IEEE80211_BAR_TID       0xf000          /* TID */
559 #define IEEE80211_BAR_TID_S     12
560 #define IEEE80211_BAR_COMP      0x0004          /* Compressed Bitmap */
561 #define IEEE80211_BAR_MTID      0x0002          /* Multi-TID */
562 #define IEEE80211_BAR_NOACK     0x0001          /* No-Ack policy */
563
564 /* BAR Starting Sequence Control */
565 #define IEEE80211_BAR_SEQ_START 0xfff0          /* starting seqnum */
566 #define IEEE80211_BAR_SEQ_START_S       4
567
568 struct ieee80211_ba_request {
569         uint16_t        rq_barctl;
570         uint16_t        rq_barseqctl;
571 } __packed;
572
573 /*
574  * Control frames.
575  */
576 struct ieee80211_frame_min {
577         uint8_t         i_fc[2];
578         uint8_t         i_dur[2];
579         uint8_t         i_addr1[IEEE80211_ADDR_LEN];
580         uint8_t         i_addr2[IEEE80211_ADDR_LEN];
581         /* FCS */
582 } __packed;
583
584 struct ieee80211_frame_rts {
585         uint8_t         i_fc[2];
586         uint8_t         i_dur[2];
587         uint8_t         i_ra[IEEE80211_ADDR_LEN];
588         uint8_t         i_ta[IEEE80211_ADDR_LEN];
589         /* FCS */
590 } __packed;
591
592 struct ieee80211_frame_cts {
593         uint8_t         i_fc[2];
594         uint8_t         i_dur[2];
595         uint8_t         i_ra[IEEE80211_ADDR_LEN];
596         /* FCS */
597 } __packed;
598
599 struct ieee80211_frame_ack {
600         uint8_t         i_fc[2];
601         uint8_t         i_dur[2];
602         uint8_t         i_ra[IEEE80211_ADDR_LEN];
603         /* FCS */
604 } __packed;
605
606 struct ieee80211_frame_pspoll {
607         uint8_t         i_fc[2];
608         uint8_t         i_aid[2];
609         uint8_t         i_bssid[IEEE80211_ADDR_LEN];
610         uint8_t         i_ta[IEEE80211_ADDR_LEN];
611         /* FCS */
612 } __packed;
613
614 struct ieee80211_frame_cfend {          /* NB: also CF-End+CF-Ack */
615         uint8_t         i_fc[2];
616         uint8_t         i_dur[2];       /* should be zero */
617         uint8_t         i_ra[IEEE80211_ADDR_LEN];
618         uint8_t         i_bssid[IEEE80211_ADDR_LEN];
619         /* FCS */
620 } __packed;
621
622 struct ieee80211_frame_bar {
623         uint8_t         i_fc[2];
624         uint8_t         i_dur[2];
625         uint8_t         i_ra[IEEE80211_ADDR_LEN];
626         uint8_t         i_ta[IEEE80211_ADDR_LEN];
627         uint16_t        i_ctl;
628         uint16_t        i_seq;
629         /* FCS */
630 } __packed;
631
632 /*
633  * BEACON management packets
634  *
635  *      octet timestamp[8]
636  *      octet beacon interval[2]
637  *      octet capability information[2]
638  *      information element
639  *              octet elemid
640  *              octet length
641  *              octet information[length]
642  */
643
644 #define IEEE80211_BEACON_INTERVAL(beacon) \
645         ((beacon)[8] | ((beacon)[9] << 8))
646 #define IEEE80211_BEACON_CAPABILITY(beacon) \
647         ((beacon)[10] | ((beacon)[11] << 8))
648
649 #define IEEE80211_CAPINFO_ESS                   0x0001
650 #define IEEE80211_CAPINFO_IBSS                  0x0002
651 #define IEEE80211_CAPINFO_CF_POLLABLE           0x0004
652 #define IEEE80211_CAPINFO_CF_POLLREQ            0x0008
653 #define IEEE80211_CAPINFO_PRIVACY               0x0010
654 #define IEEE80211_CAPINFO_SHORT_PREAMBLE        0x0020
655 #define IEEE80211_CAPINFO_PBCC                  0x0040
656 #define IEEE80211_CAPINFO_CHNL_AGILITY          0x0080
657 #define IEEE80211_CAPINFO_SPECTRUM_MGMT         0x0100
658 /* bit 9 is reserved */
659 #define IEEE80211_CAPINFO_SHORT_SLOTTIME        0x0400
660 #define IEEE80211_CAPINFO_RSN                   0x0800
661 /* bit 12 is reserved */
662 #define IEEE80211_CAPINFO_DSSSOFDM              0x2000
663 /* bits 14-15 are reserved */
664
665 #define IEEE80211_CAPINFO_BITS \
666         "\20\1ESS\2IBSS\3CF_POLLABLE\4CF_POLLREQ\5PRIVACY\6SHORT_PREAMBLE" \
667         "\7PBCC\10CHNL_AGILITY\11SPECTRUM_MGMT\13SHORT_SLOTTIME\14RSN" \
668         "\16DSSOFDM"
669
670 /*
671  * 802.11i/WPA information element (maximally sized).
672  */
673 struct ieee80211_ie_wpa {
674         uint8_t         wpa_id;         /* IEEE80211_ELEMID_VENDOR */
675         uint8_t         wpa_len;        /* length in bytes */
676         uint8_t         wpa_oui[3];     /* 0x00, 0x50, 0xf2 */
677         uint8_t         wpa_type;       /* OUI type */
678         uint16_t        wpa_version;    /* spec revision */
679         uint32_t        wpa_mcipher[1]; /* multicast/group key cipher */
680         uint16_t        wpa_uciphercnt; /* # pairwise key ciphers */
681         uint32_t        wpa_uciphers[8];/* ciphers */
682         uint16_t        wpa_authselcnt; /* authentication selector cnt*/
683         uint32_t        wpa_authsels[8];/* selectors */
684         uint16_t        wpa_caps;       /* 802.11i capabilities */
685         uint16_t        wpa_pmkidcnt;   /* 802.11i pmkid count */
686         uint16_t        wpa_pmkids[8];  /* 802.11i pmkids */
687 } __packed;
688
689 /*
690  * 802.11n HT Capability IE
691  * NB: these reflect D1.10 
692  */
693 struct ieee80211_ie_htcap {
694         uint8_t         hc_id;                  /* element ID */
695         uint8_t         hc_len;                 /* length in bytes */
696         uint16_t        hc_cap;                 /* HT caps (see below) */
697         uint8_t         hc_param;               /* HT params (see below) */
698         uint8_t         hc_mcsset[16];          /* supported MCS set */
699         uint16_t        hc_extcap;              /* extended HT capabilities */
700         uint32_t        hc_txbf;                /* txbf capabilities */
701         uint8_t         hc_antenna;             /* antenna capabilities */
702 } __packed;
703
704 /* HT capability flags (ht_cap) */
705 #define IEEE80211_HTCAP_LDPC            0x0001  /* LDPC rx supported */
706 #define IEEE80211_HTCAP_CHWIDTH40       0x0002  /* 20/40 supported */
707 #define IEEE80211_HTCAP_SMPS            0x000c  /* SM Power Save mode */
708 #define IEEE80211_HTCAP_SMPS_OFF        0x000c  /* disabled */
709 #define IEEE80211_HTCAP_SMPS_DYNAMIC    0x0004  /* send RTS first */
710 /* NB: SMPS value 2 is reserved */
711 #define IEEE80211_HTCAP_SMPS_ENA        0x0000  /* enabled (static mode) */
712 #define IEEE80211_HTCAP_GREENFIELD      0x0010  /* Greenfield supported */
713 #define IEEE80211_HTCAP_SHORTGI20       0x0020  /* Short GI in 20MHz */
714 #define IEEE80211_HTCAP_SHORTGI40       0x0040  /* Short GI in 40MHz */
715 #define IEEE80211_HTCAP_TXSTBC          0x0080  /* STBC tx ok */
716 #define IEEE80211_HTCAP_RXSTBC          0x0300  /* STBC rx support */
717 #define IEEE80211_HTCAP_RXSTBC_S        8
718 #define IEEE80211_HTCAP_RXSTBC_1STREAM  0x0100  /* 1 spatial stream */
719 #define IEEE80211_HTCAP_RXSTBC_2STREAM  0x0200  /* 1-2 spatial streams*/
720 #define IEEE80211_HTCAP_RXSTBC_3STREAM  0x0300  /* 1-3 spatial streams*/
721 #define IEEE80211_HTCAP_DELBA           0x0400  /* HT DELBA supported */
722 #define IEEE80211_HTCAP_MAXAMSDU        0x0800  /* max A-MSDU length */
723 #define IEEE80211_HTCAP_MAXAMSDU_7935   0x0800  /* 7935 octets */
724 #define IEEE80211_HTCAP_MAXAMSDU_3839   0x0000  /* 3839 octets */
725 #define IEEE80211_HTCAP_DSSSCCK40       0x1000  /* DSSS/CCK in 40MHz */
726 #define IEEE80211_HTCAP_PSMP            0x2000  /* PSMP supported */
727 #define IEEE80211_HTCAP_40INTOLERANT    0x4000  /* 40MHz intolerant */
728 #define IEEE80211_HTCAP_LSIGTXOPPROT    0x8000  /* L-SIG TXOP prot */
729
730 #define IEEE80211_HTCAP_BITS \
731         "\20\1LDPC\2CHWIDTH40\5GREENFIELD\6SHORTGI20\7SHORTGI40\10TXSTBC" \
732         "\13DELBA\14AMSDU(7935)\15DSSSCCK40\16PSMP\1740INTOLERANT" \
733         "\20LSIGTXOPPROT"
734
735 /* HT parameters (hc_param) */
736 #define IEEE80211_HTCAP_MAXRXAMPDU      0x03    /* max rx A-MPDU factor */
737 #define IEEE80211_HTCAP_MAXRXAMPDU_S    0
738 #define IEEE80211_HTCAP_MAXRXAMPDU_8K   0
739 #define IEEE80211_HTCAP_MAXRXAMPDU_16K  1
740 #define IEEE80211_HTCAP_MAXRXAMPDU_32K  2
741 #define IEEE80211_HTCAP_MAXRXAMPDU_64K  3
742 #define IEEE80211_HTCAP_MPDUDENSITY     0x1c    /* min MPDU start spacing */
743 #define IEEE80211_HTCAP_MPDUDENSITY_S   2
744 #define IEEE80211_HTCAP_MPDUDENSITY_NA  0       /* no time restriction */
745 #define IEEE80211_HTCAP_MPDUDENSITY_025 1       /* 1/4 us */
746 #define IEEE80211_HTCAP_MPDUDENSITY_05  2       /* 1/2 us */
747 #define IEEE80211_HTCAP_MPDUDENSITY_1   3       /* 1 us */
748 #define IEEE80211_HTCAP_MPDUDENSITY_2   4       /* 2 us */
749 #define IEEE80211_HTCAP_MPDUDENSITY_4   5       /* 4 us */
750 #define IEEE80211_HTCAP_MPDUDENSITY_8   6       /* 8 us */
751 #define IEEE80211_HTCAP_MPDUDENSITY_16  7       /* 16 us */
752
753 /* HT extended capabilities (hc_extcap) */
754 #define IEEE80211_HTCAP_PCO             0x0001  /* PCO capable */
755 #define IEEE80211_HTCAP_PCOTRANS        0x0006  /* PCO transition time */
756 #define IEEE80211_HTCAP_PCOTRANS_S      1
757 #define IEEE80211_HTCAP_PCOTRANS_04     0x0002  /* 400 us */
758 #define IEEE80211_HTCAP_PCOTRANS_15     0x0004  /* 1.5 ms */
759 #define IEEE80211_HTCAP_PCOTRANS_5      0x0006  /* 5 ms */
760 /* bits 3-7 reserved */
761 #define IEEE80211_HTCAP_MCSFBACK        0x0300  /* MCS feedback */
762 #define IEEE80211_HTCAP_MCSFBACK_S      8
763 #define IEEE80211_HTCAP_MCSFBACK_NONE   0x0000  /* nothing provided */
764 #define IEEE80211_HTCAP_MCSFBACK_UNSOL  0x0200  /* unsolicited feedback */
765 #define IEEE80211_HTCAP_MCSFBACK_MRQ    0x0300  /* " "+respond to MRQ */
766 #define IEEE80211_HTCAP_HTC             0x0400  /* +HTC support */
767 #define IEEE80211_HTCAP_RDR             0x0800  /* reverse direction responder*/
768 /* bits 12-15 reserved */
769
770 /*
771  * 802.11n HT Information IE
772  */
773 struct ieee80211_ie_htinfo {
774         uint8_t         hi_id;                  /* element ID */
775         uint8_t         hi_len;                 /* length in bytes */
776         uint8_t         hi_ctrlchannel;         /* primary channel */
777         uint8_t         hi_byte1;               /* ht ie byte 1 */
778         uint8_t         hi_byte2;               /* ht ie byte 2 */
779         uint8_t         hi_byte3;               /* ht ie byte 3 */
780         uint16_t        hi_byte45;              /* ht ie bytes 4+5 */
781         uint8_t         hi_basicmcsset[16];     /* basic MCS set */
782 } __packed;
783
784 /* byte1 */
785 #define IEEE80211_HTINFO_2NDCHAN        0x03    /* secondary/ext chan offset */
786 #define IEEE80211_HTINFO_2NDCHAN_S      0
787 #define IEEE80211_HTINFO_2NDCHAN_NONE   0x00    /* no secondary/ext channel */
788 #define IEEE80211_HTINFO_2NDCHAN_ABOVE  0x01    /* above private channel */
789 /* NB: 2 is reserved */
790 #define IEEE80211_HTINFO_2NDCHAN_BELOW  0x03    /* below primary channel */ 
791 #define IEEE80211_HTINFO_TXWIDTH        0x04    /* tx channel width */
792 #define IEEE80211_HTINFO_TXWIDTH_20     0x00    /* 20MHz width */
793 #define IEEE80211_HTINFO_TXWIDTH_2040   0x04    /* any supported width */
794 #define IEEE80211_HTINFO_RIFSMODE       0x08    /* Reduced IFS (RIFS) use */
795 #define IEEE80211_HTINFO_RIFSMODE_PROH  0x00    /* RIFS use prohibited */
796 #define IEEE80211_HTINFO_RIFSMODE_PERM  0x08    /* RIFS use permitted */
797 #define IEEE80211_HTINFO_PMSPONLY       0x10    /* PSMP required to associate */
798 #define IEEE80211_HTINFO_SIGRAN         0xe0    /* shortest Service Interval */
799 #define IEEE80211_HTINFO_SIGRAN_S       5
800 #define IEEE80211_HTINFO_SIGRAN_5       0x00    /* 5 ms */
801 /* XXX add rest */
802
803 /* bytes 2+3 */
804 #define IEEE80211_HTINFO_OPMODE         0x03    /* operating mode */
805 #define IEEE80211_HTINFO_OPMODE_S       0
806 #define IEEE80211_HTINFO_OPMODE_PURE    0x00    /* no protection */
807 #define IEEE80211_HTINFO_OPMODE_PROTOPT 0x01    /* protection optional */
808 #define IEEE80211_HTINFO_OPMODE_HT20PR  0x02    /* protection for HT20 sta's */
809 #define IEEE80211_HTINFO_OPMODE_MIXED   0x03    /* protection for legacy sta's*/
810 #define IEEE80211_HTINFO_NONGF_PRESENT  0x04    /* non-GF sta's present */
811 #define IEEE80211_HTINFO_TXBL           0x08    /* transmit burst limit */
812 #define IEEE80211_HTINFO_NONHT_PRESENT  0x10    /* non-HT sta's present */
813 /* bits 5-15 reserved */
814
815 /* bytes 4+5 */
816 #define IEEE80211_HTINFO_2NDARYBEACON   0x01
817 #define IEEE80211_HTINFO_LSIGTXOPPROT   0x02
818 #define IEEE80211_HTINFO_PCO_ACTIVE     0x04
819 #define IEEE80211_HTINFO_40MHZPHASE     0x08
820
821 /* byte5 */
822 #define IEEE80211_HTINFO_BASIC_STBCMCS  0x7f
823 #define IEEE80211_HTINFO_BASIC_STBCMCS_S 0
824 #define IEEE80211_HTINFO_DUALPROTECTED  0x80
825
826 /*
827  * 802.11ac definitions - 802.11ac-2013 .
828  */
829
830 /*
831  * Maximum length of A-MPDU that the STA can RX in VHT.
832  * Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
833  */
834 #define IEEE80211_VHTCAP_MAX_AMPDU_8K           0
835 #define IEEE80211_VHTCAP_MAX_AMPDU_16K          1
836 #define IEEE80211_VHTCAP_MAX_AMPDU_32K          2
837 #define IEEE80211_VHTCAP_MAX_AMPDU_64K          3
838 #define IEEE80211_VHTCAP_MAX_AMPDU_128K         4
839 #define IEEE80211_VHTCAP_MAX_AMPDU_256K         5
840 #define IEEE80211_VHTCAP_MAX_AMPDU_512K         6
841 #define IEEE80211_VHTCAP_MAX_AMPDU_1024K        7
842
843 /*
844  * VHT MCS information.
845  * + rx_highest/tx_highest: optional; maximum long GI VHT PPDU
846  *    data rate.  1Mbit/sec units.
847  * + rx_mcs_map/tx_mcs_map: bitmap of per-stream supported MCS;
848  *    2 bits each.
849  */
850
851 /* 802.11ac-2013, 8.4.2.160.3 Supported VHT-MCS and NSS Set field */
852 enum ieee80211_vht_mcs_support {
853         IEEE80211_VHT_MCS_SUPPORT_0_7           = 0,    /* MCS0-7 */
854         IEEE80211_VHT_MCS_SUPPORT_0_8           = 1,    /* MCS0-8 */
855         IEEE80211_VHT_MCS_SUPPORT_0_9           = 2,    /* MCS0-9 */
856         IEEE80211_VHT_MCS_NOT_SUPPORTED         = 3     /* not supported */
857 };
858
859 struct ieee80211_vht_mcs_info {
860         uint16_t rx_mcs_map;
861         uint16_t rx_highest;
862         uint16_t tx_mcs_map;
863         uint16_t tx_highest;
864 } __packed;
865
866 /* 802.11ac-2013, 8.4.2.160.1 VHT Capabilities element structure */
867 struct ieee80211_vht_cap {
868         uint32_t                        vht_cap_info;
869         struct ieee80211_vht_mcs_info   supp_mcs;
870 } __packed;
871
872 /* VHT capabilities element: 802.11ac-2013 8.4.2.160 */
873 struct ieee80211_ie_vhtcap {
874         uint8_t ie;
875         uint8_t len;
876         uint32_t vht_cap_info;
877         struct ieee80211_vht_mcs_info supp_mcs;
878 } __packed;
879
880 /* VHT operation mode subfields - 802.11ac-2013 Table 8.183x */
881 #define IEEE80211_VHT_CHANWIDTH_USE_HT          0       /* Use HT IE for chw */
882 #define IEEE80211_VHT_CHANWIDTH_80MHZ           1       /* 80MHz */
883 #define IEEE80211_VHT_CHANWIDTH_160MHZ          2       /* 160MHz */
884 #define IEEE80211_VHT_CHANWIDTH_80P80MHZ        3       /* 80+80MHz */
885
886 /* VHT operation IE - 802.11ac-2013 8.4.2.161 */
887 struct ieee80211_ie_vht_operation {
888         uint8_t ie;
889         uint8_t len;
890         uint8_t chan_width;
891         uint8_t center_freq_seg1_idx;
892         uint8_t center_freq_seg2_idx;
893         uint16_t basic_mcs_set;
894 } __packed;
895
896 /* 802.11ac VHT Capabilities */
897 #define IEEE80211_VHTCAP_MAX_MPDU_LENGTH_3895   0x00000000
898 #define IEEE80211_VHTCAP_MAX_MPDU_LENGTH_7991   0x00000001
899 #define IEEE80211_VHTCAP_MAX_MPDU_LENGTH_11454  0x00000002
900 #define IEEE80211_VHTCAP_MAX_MPDU_MASK          0x00000003
901 #define IEEE80211_VHTCAP_MAX_MPDU_MASK_S        0
902
903 #define IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_MASK   0x0000000C
904 #define IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_MASK_S 2
905 #define IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_NONE           0
906 #define IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_160MHZ         1
907 #define IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_160_80P80MHZ   2
908 #define IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_RESERVED       3
909
910 #define IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160MHZ(_vhtcaps)            \
911     (_IEEE80211_MASKSHIFT(_vhtcaps, IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_MASK) >= \
912             IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_160MHZ)
913 #define IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160_80P80MHZ(_vhtcaps)      \
914     (_IEEE80211_MASKSHIFT(_vhtcaps, IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_MASK) == \
915             IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_160_80P80MHZ)
916
917 #define IEEE80211_VHTCAP_RXLDPC         0x00000010
918 #define IEEE80211_VHTCAP_RXLDPC_S       4
919
920 #define IEEE80211_VHTCAP_SHORT_GI_80            0x00000020
921 #define IEEE80211_VHTCAP_SHORT_GI_80_S          5
922
923 #define IEEE80211_VHTCAP_SHORT_GI_160           0x00000040
924 #define IEEE80211_VHTCAP_SHORT_GI_160_S         6
925
926 #define IEEE80211_VHTCAP_TXSTBC         0x00000080
927 #define IEEE80211_VHTCAP_TXSTBC_S       7
928
929 #define IEEE80211_VHTCAP_RXSTBC_1               0x00000100
930 #define IEEE80211_VHTCAP_RXSTBC_2               0x00000200
931 #define IEEE80211_VHTCAP_RXSTBC_3               0x00000300
932 #define IEEE80211_VHTCAP_RXSTBC_4               0x00000400
933 #define IEEE80211_VHTCAP_RXSTBC_MASK            0x00000700
934 #define IEEE80211_VHTCAP_RXSTBC_MASK_S          8
935
936 #define IEEE80211_VHTCAP_SU_BEAMFORMER_CAPABLE  0x00000800
937 #define IEEE80211_VHTCAP_SU_BEAMFORMER_CAPABLE_S        11
938
939 #define IEEE80211_VHTCAP_SU_BEAMFORMEE_CAPABLE  0x00001000
940 #define IEEE80211_VHTCAP_SU_BEAMFORMEE_CAPABLE_S        12
941
942 #define IEEE80211_VHTCAP_BEAMFORMEE_STS_SHIFT   13
943 #define IEEE80211_VHTCAP_BEAMFORMEE_STS_MASK \
944             (7 << IEEE80211_VHTCAP_BEAMFORMEE_STS_SHIFT)
945 #define IEEE80211_VHTCAP_BEAMFORMEE_STS_MASK_S  13
946
947 #define IEEE80211_VHTCAP_SOUNDING_DIMENSIONS_SHIFT      16
948 #define IEEE80211_VHTCAP_SOUNDING_DIMENSIONS_MASK \
949             (7 << IEEE80211_VHTCAP_SOUNDING_DIMENSIONS_SHIFT)
950 #define IEEE80211_VHTCAP_SOUNDING_DIMENSIONS_MASK_S     16
951
952 #define IEEE80211_VHTCAP_MU_BEAMFORMER_CAPABLE  0x00080000
953 #define IEEE80211_VHTCAP_MU_BEAMFORMER_CAPABLE_S        19
954 #define IEEE80211_VHTCAP_MU_BEAMFORMEE_CAPABLE  0x00100000
955 #define IEEE80211_VHTCAP_MU_BEAMFORMEE_CAPABLE_S        20
956 #define IEEE80211_VHTCAP_VHT_TXOP_PS            0x00200000
957 #define IEEE80211_VHTCAP_VHT_TXOP_PS_S          21
958 #define IEEE80211_VHTCAP_HTC_VHT                0x00400000
959 #define IEEE80211_VHTCAP_HTC_VHT_S              22
960
961 #define IEEE80211_VHTCAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT       23
962 #define IEEE80211_VHTCAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK \
963             (7 << IEEE80211_VHTCAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT)
964 #define IEEE80211_VHTCAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK_S      23
965
966 #define IEEE80211_VHTCAP_VHT_LINK_ADAPTATION_VHT_MASK   0x0c000000
967 #define IEEE80211_VHTCAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB      0x08000000
968 #define IEEE80211_VHTCAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB        0x0c000000
969 #define IEEE80211_VHTCAP_VHT_LINK_ADAPTATION_VHT_MASK_S 26
970
971 #define IEEE80211_VHTCAP_RX_ANTENNA_PATTERN     0x10000000
972 #define IEEE80211_VHTCAP_RX_ANTENNA_PATTERN_S   28
973 #define IEEE80211_VHTCAP_TX_ANTENNA_PATTERN     0x20000000
974 #define IEEE80211_VHTCAP_TX_ANTENNA_PATTERN_S   29
975
976 /*
977  * XXX TODO: add the rest of the bits
978  */
979 #define IEEE80211_VHTCAP_BITS \
980         "\20\1MPDU7991\2MPDU11454\3CHAN160\4CHAN8080\5RXLDPC\6SHORTGI80" \
981         "\7SHORTGI160\10RXSTBC1\11RXSTBC2\12RXSTBC3\13RXSTBC4\14BFERCAP" \
982         "\15BFEECAP\27VHT\37RXANTPTN\40TXANTPTN"
983
984 /*
985  * VHT Transmit Power Envelope element - 802.11ac-2013 8.4.2.164
986  *
987  * This defines the maximum transmit power for various bandwidths.
988  */
989 /*
990  * Count is how many elements follow and what they're for:
991  *
992  * 0 - 20 MHz
993  * 1 - 20+40 MHz
994  * 2 - 20+40+80 MHz
995  * 3 - 20+40+80+(160, 80+80) MHz
996  */
997 #define IEEE80211_VHT_TXPWRENV_INFO_COUNT_SHIFT 0
998 #define IEEE80211_VHT_TXPWRENV_INFO_COUNT_MASK  0x07
999
1000 /*
1001  * Unit is the tx power representation.  It should be EIRP for now;
1002  * other values are reserved.
1003  */
1004 #define IEEE80211_VHT_TXPWRENV_UNIT_MASK        0x38
1005 #define IEEE80211_VHT_TXPWRENV_UNIT_SHIFT       3
1006
1007 /* This value is within the unit mask/shift above */
1008 #define IEEE80211_VHT_TXPWRENV_UNIT_EIRP        0
1009
1010 struct ieee80211_ie_vht_txpwrenv {
1011         uint8_t ie;
1012         uint8_t len;
1013         uint8_t tx_info;
1014         int8_t tx_elem[0];      /* TX power elements, 1/2 dB, signed */
1015 };
1016
1017 /* VHT action codes */
1018 #define WLAN_ACTION_VHT_COMPRESSED_BF           0
1019 #define WLAN_ACTION_VHT_GROUPID_MGMT            1
1020 #define WLAN_ACTION_VHT_OPMODE_NOTIF            2
1021
1022 /*
1023  * Management information element payloads.
1024  */
1025
1026 enum {
1027         IEEE80211_ELEMID_SSID           = 0,
1028         IEEE80211_ELEMID_RATES          = 1,
1029         IEEE80211_ELEMID_FHPARMS        = 2,
1030         IEEE80211_ELEMID_DSPARMS        = 3,
1031         IEEE80211_ELEMID_CFPARMS        = 4,
1032         IEEE80211_ELEMID_TIM            = 5,
1033         IEEE80211_ELEMID_IBSSPARMS      = 6,
1034         IEEE80211_ELEMID_COUNTRY        = 7,
1035         IEEE80211_ELEMID_BSSLOAD        = 11,
1036         IEEE80211_ELEMID_TSPEC          = 13,
1037         IEEE80211_ELEMID_TCLAS          = 14,
1038         IEEE80211_ELEMID_CHALLENGE      = 16,
1039         /* 17-31 reserved for challenge text extension */
1040         IEEE80211_ELEMID_PWRCNSTR       = 32,
1041         IEEE80211_ELEMID_PWRCAP         = 33,
1042         IEEE80211_ELEMID_TPCREQ         = 34,
1043         IEEE80211_ELEMID_TPCREP         = 35,
1044         IEEE80211_ELEMID_SUPPCHAN       = 36,
1045         IEEE80211_ELEMID_CSA            = 37,
1046         IEEE80211_ELEMID_MEASREQ        = 38,
1047         IEEE80211_ELEMID_MEASREP        = 39,
1048         IEEE80211_ELEMID_QUIET          = 40,
1049         IEEE80211_ELEMID_IBSSDFS        = 41,
1050         IEEE80211_ELEMID_ERP            = 42,
1051         IEEE80211_ELEMID_HTCAP          = 45,
1052         IEEE80211_ELEMID_QOS            = 46,
1053         IEEE80211_ELEMID_RESERVED_47    = 47,
1054         IEEE80211_ELEMID_RSN            = 48,
1055         IEEE80211_ELEMID_XRATES         = 50,
1056         IEEE80211_ELEMID_APCHANREP      = 51,
1057         IEEE80211_ELEMID_MOBILITY_DOMAIN        = 54,
1058         IEEE80211_ELEMID_HTINFO         = 61,
1059         IEEE80211_ELEMID_SECCHAN_OFFSET = 62,
1060         IEEE80211_ELEMID_RRM_ENACAPS    = 70,
1061         IEEE80211_ELEMID_MULTIBSSID     = 71,
1062         IEEE80211_ELEMID_COEX_2040      = 72,
1063         IEEE80211_ELEMID_INTOL_CHN_REPORT       = 73,
1064         IEEE80211_ELEMID_OVERLAP_BSS_SCAN_PARAM = 74,
1065         IEEE80211_ELEMID_TSF_REQ        = 91,
1066         IEEE80211_ELEMID_TSF_RESP       = 92,
1067         IEEE80211_ELEMID_WNM_SLEEP_MODE = 93,
1068         IEEE80211_ELEMID_TIM_BCAST_REQ  = 94,
1069         IEEE80211_ELEMID_TIM_BCAST_RESP = 95,
1070         IEEE80211_ELEMID_TPC            = 150,
1071         IEEE80211_ELEMID_CCKM           = 156,
1072         IEEE80211_ELEMID_VENDOR         = 221,  /* vendor private */
1073
1074         /*
1075          * 802.11s IEs
1076          * NB: On vanilla Linux still IEEE80211_ELEMID_MESHPEER = 55,
1077          * but they defined a new with id 117 called PEER_MGMT.
1078          * NB: complies with open80211
1079          */
1080         IEEE80211_ELEMID_MESHCONF       = 113,
1081         IEEE80211_ELEMID_MESHID         = 114,
1082         IEEE80211_ELEMID_MESHLINK       = 115,
1083         IEEE80211_ELEMID_MESHCNGST      = 116,
1084         IEEE80211_ELEMID_MESHPEER       = 117,
1085         IEEE80211_ELEMID_MESHCSA        = 118,
1086         IEEE80211_ELEMID_MESHTIM        = 39, /* XXX: remove */
1087         IEEE80211_ELEMID_MESHAWAKEW     = 119,
1088         IEEE80211_ELEMID_MESHBEACONT    = 120,
1089         /* 121-124 MMCAOP not implemented yet */
1090         IEEE80211_ELEMID_MESHGANN       = 125,
1091         IEEE80211_ELEMID_MESHRANN       = 126,
1092         /* 127 Extended Capabilities */
1093         IEEE80211_ELEMID_EXTCAP         = 127,
1094         /* 128-129 reserved */
1095         IEEE80211_ELEMID_MESHPREQ       = 130,
1096         IEEE80211_ELEMID_MESHPREP       = 131,
1097         IEEE80211_ELEMID_MESHPERR       = 132,
1098         /* 133-136 reserved */
1099         IEEE80211_ELEMID_MESHPXU        = 137,
1100         IEEE80211_ELEMID_MESHPXUC       = 138,
1101         IEEE80211_ELEMID_MESHAH         = 60, /* XXX: remove */
1102
1103         /* 802.11ac-2013, Table 8-54-Element IDs */
1104         IEEE80211_ELEMID_VHT_CAP        = 191,
1105         IEEE80211_ELEMID_VHT_OPMODE     = 192,
1106         IEEE80211_ELEMID_EXTENDED_BSS_LOAD = 193,
1107         IEEE80211_ELEMID_WIDE_BW_CHANNEL_SWITCH = 194,
1108         IEEE80211_ELEMID_VHT_PWR_ENV    = 195,
1109         IEEE80211_ELEMID_CHANNEL_SWITCH_WRAPPER = 196,
1110         IEEE80211_ELEMID_AID            = 197,
1111         IEEE80211_ELEMID_QUIET_CHANNEL  = 198,
1112         IEEE80211_ELEMID_OPMODE_NOTIF   = 199,
1113 };
1114
1115 struct ieee80211_tim_ie {
1116         uint8_t         tim_ie;                 /* IEEE80211_ELEMID_TIM */
1117         uint8_t         tim_len;
1118         uint8_t         tim_count;              /* DTIM count */
1119         uint8_t         tim_period;             /* DTIM period */
1120         uint8_t         tim_bitctl;             /* bitmap control */
1121         uint8_t         tim_bitmap[1];          /* variable-length bitmap */
1122 } __packed;
1123
1124 struct ieee80211_country_ie {
1125         uint8_t         ie;                     /* IEEE80211_ELEMID_COUNTRY */
1126         uint8_t         len;
1127         uint8_t         cc[3];                  /* ISO CC+(I)ndoor/(O)utdoor */
1128         struct {
1129                 uint8_t schan;                  /* starting channel */
1130                 uint8_t nchan;                  /* number channels */
1131                 uint8_t maxtxpwr;               /* tx power cap */
1132         } __packed band[1];                     /* sub bands (NB: var size) */
1133 } __packed;
1134
1135 #define IEEE80211_COUNTRY_MAX_BANDS     84      /* max possible bands */
1136 #define IEEE80211_COUNTRY_MAX_SIZE \
1137         (sizeof(struct ieee80211_country_ie) + 3*(IEEE80211_COUNTRY_MAX_BANDS-1))
1138
1139 struct ieee80211_bss_load_ie {
1140         uint8_t         ie;
1141         uint8_t         len;
1142         uint16_t        sta_count;      /* station count */
1143         uint8_t         chan_load;      /* channel utilization */
1144         uint8_t         aac;            /* available admission capacity */
1145 } __packed;
1146
1147 struct ieee80211_ap_chan_report_ie {
1148         uint8_t         ie;
1149         uint8_t         len;
1150         uint8_t         i_class; /* operating class */
1151         /* Annex E, E.1 Country information and operating classes */
1152         uint8_t         chan_list[0];
1153 } __packed;
1154
1155 #define IEEE80211_EXTCAP_CMS                    (1ULL <<  0) /* 20/40 BSS coexistence management support */
1156 #define IEEE80211_EXTCAP_RSVD_1                 (1ULL <<  1)
1157 #define IEEE80211_EXTCAP_ECS                    (1ULL <<  2) /* extended channel switching */
1158 #define IEEE80211_EXTCAP_RSVD_3                 (1ULL <<  3)
1159 #define IEEE80211_EXTCAP_PSMP_CAP               (1ULL <<  4) /* PSMP capability */
1160 #define IEEE80211_EXTCAP_RSVD_5                 (1ULL <<  5)
1161 #define IEEE80211_EXTCAP_S_PSMP_SUPP            (1ULL <<  6)
1162 #define IEEE80211_EXTCAP_EVENT                  (1ULL <<  7)
1163 #define IEEE80211_EXTCAP_DIAGNOSTICS            (1ULL <<  8)
1164 #define IEEE80211_EXTCAP_MCAST_DIAG             (1ULL <<  9)
1165 #define IEEE80211_EXTCAP_LOC_TRACKING           (1ULL << 10)
1166 #define IEEE80211_EXTCAP_FMS                    (1ULL << 11)
1167 #define IEEE80211_EXTCAP_PROXY_ARP              (1ULL << 12)
1168 #define IEEE80211_EXTCAP_CIR                    (1ULL << 13) /* collocated interference reporting */
1169 #define IEEE80211_EXTCAP_CIVIC_LOC              (1ULL << 14)
1170 #define IEEE80211_EXTCAP_GEOSPATIAL_LOC         (1ULL << 15)
1171 #define IEEE80211_EXTCAP_TFS                    (1ULL << 16)
1172 #define IEEE80211_EXTCAP_WNM_SLEEPMODE          (1ULL << 17)
1173 #define IEEE80211_EXTCAP_TIM_BROADCAST          (1ULL << 18)
1174 #define IEEE80211_EXTCAP_BSS_TRANSITION         (1ULL << 19)
1175 #define IEEE80211_EXTCAP_QOS_TRAF_CAP           (1ULL << 20)
1176 #define IEEE80211_EXTCAP_AC_STA_COUNT           (1ULL << 21)
1177 #define IEEE80211_EXTCAP_M_BSSID                (1ULL << 22) /* multiple BSSID field */
1178 #define IEEE80211_EXTCAP_TIMING_MEAS            (1ULL << 23)
1179 #define IEEE80211_EXTCAP_CHAN_USAGE             (1ULL << 24)
1180 #define IEEE80211_EXTCAP_SSID_LIST              (1ULL << 25)
1181 #define IEEE80211_EXTCAP_DMS                    (1ULL << 26)
1182 #define IEEE80211_EXTCAP_UTC_TSF_OFFSET         (1ULL << 27)
1183 #define IEEE80211_EXTCAP_TLDS_BUF_STA_SUPP      (1ULL << 28) /* TDLS peer U-APSP buffer STA support */
1184 #define IEEE80211_EXTCAP_TLDS_PPSM_SUPP         (1ULL << 29) /* TDLS peer PSM support */
1185 #define IEEE80211_EXTCAP_TLDS_CH_SW             (1ULL << 30) /* TDLS channel switching */
1186 #define IEEE80211_EXTCAP_INTERWORKING           (1ULL << 31)
1187 #define IEEE80211_EXTCAP_QOSMAP                 (1ULL << 32)
1188 #define IEEE80211_EXTCAP_EBR                    (1ULL << 33)
1189 #define IEEE80211_EXTCAP_SSPN_IF                (1ULL << 34)
1190 #define IEEE80211_EXTCAP_RSVD_35                (1ULL << 35)
1191 #define IEEE80211_EXTCAP_MSGCF_CAP              (1ULL << 36)
1192 #define IEEE80211_EXTCAP_TLDS_SUPP              (1ULL << 37)
1193 #define IEEE80211_EXTCAP_TLDS_PROHIB            (1ULL << 38)
1194 #define IEEE80211_EXTCAP_TLDS_CH_SW_PROHIB      (1ULL << 39) /* TDLS channel switching prohibited */
1195 #define IEEE80211_EXTCAP_RUF                    (1ULL << 40) /* reject unadmitted frame */
1196 /* service interval granularity */
1197 #define IEEE80211_EXTCAP_SIG \
1198                                 ((1ULL << 41) | (1ULL << 42) | (1ULL << 43))
1199 #define IEEE80211_EXTCAP_ID_LOC                 (1ULL << 44)
1200 #define IEEE80211_EXTCAP_U_APSD_COEX            (1ULL << 45)
1201 #define IEEE80211_EXTCAP_WNM_NOTIFICATION       (1ULL << 46)
1202 #define IEEE80211_EXTCAP_RSVD_47                (1ULL << 47)
1203 #define IEEE80211_EXTCAP_SSID                   (1ULL << 48) /* UTF-8 SSID */
1204 /* bits 49-n are reserved */
1205
1206 struct ieee80211_extcap_ie {
1207         uint8_t         ie;
1208         uint8_t         len;
1209 } __packed;
1210
1211 /*
1212  * 802.11h Quiet Time Element.
1213  */
1214 struct ieee80211_quiet_ie {
1215         uint8_t         quiet_ie;               /* IEEE80211_ELEMID_QUIET */
1216         uint8_t         len;
1217         uint8_t         tbttcount;              /* quiet start */
1218         uint8_t         period;                 /* beacon intervals between quiets */
1219         uint16_t        duration;               /* TUs of each quiet*/
1220         uint16_t        offset;                 /* TUs of from TBTT of quiet start */
1221 } __packed;
1222
1223 /*
1224  * 802.11h Channel Switch Announcement (CSA).
1225  */
1226 struct ieee80211_csa_ie {
1227         uint8_t         csa_ie;         /* IEEE80211_ELEMID_CHANSWITCHANN */
1228         uint8_t         csa_len;
1229         uint8_t         csa_mode;               /* Channel Switch Mode */
1230         uint8_t         csa_newchan;            /* New Channel Number */
1231         uint8_t         csa_count;              /* Channel Switch Count */
1232 } __packed;
1233
1234 /*
1235  * Note the min acceptable CSA count is used to guard against
1236  * malicious CSA injection in station mode.  Defining this value
1237  * as other than 0 violates the 11h spec.
1238  */
1239 #define IEEE80211_CSA_COUNT_MIN 2
1240 #define IEEE80211_CSA_COUNT_MAX 255
1241
1242 /* rate set entries are in .5 Mb/s units, and potentially marked as basic */
1243 #define IEEE80211_RATE_BASIC            0x80
1244 #define IEEE80211_RATE_VAL              0x7f
1245 #define IEEE80211_RV(v)                 ((v) & IEEE80211_RATE_VAL)
1246
1247 /* ERP information element flags */
1248 #define IEEE80211_ERP_NON_ERP_PRESENT   0x01
1249 #define IEEE80211_ERP_USE_PROTECTION    0x02
1250 #define IEEE80211_ERP_LONG_PREAMBLE     0x04
1251
1252 #define IEEE80211_ERP_BITS \
1253         "\20\1NON_ERP_PRESENT\2USE_PROTECTION\3LONG_PREAMBLE"
1254
1255 #define ATH_OUI                 0x7f0300        /* Atheros OUI */
1256 #define ATH_OUI_TYPE            0x01            /* Atheros protocol ie */
1257
1258 /* NB: Atheros allocated the OUI for this purpose ~2005 but beware ... */
1259 #define TDMA_OUI                ATH_OUI
1260 #define TDMA_OUI_TYPE           0x02            /* TDMA protocol ie */
1261
1262 #define BCM_OUI                 0x4c9000        /* Broadcom OUI */
1263 #define BCM_OUI_HTCAP           51              /* pre-draft HTCAP ie */
1264 #define BCM_OUI_HTINFO          52              /* pre-draft HTINFO ie */
1265
1266 #define WPA_OUI                 0xf25000
1267 #define WPA_OUI_TYPE            0x01
1268 #define WPA_VERSION             1               /* current supported version */
1269
1270 #define WPA_CSE_NULL            0x00
1271 #define WPA_CSE_WEP40           0x01
1272 #define WPA_CSE_TKIP            0x02
1273 #define WPA_CSE_CCMP            0x04
1274 #define WPA_CSE_WEP104          0x05
1275
1276 #define WPA_ASE_NONE            0x00
1277 #define WPA_ASE_8021X_UNSPEC    0x01
1278 #define WPA_ASE_8021X_PSK       0x02
1279
1280 #define WPS_OUI_TYPE            0x04
1281
1282 #define RSN_OUI                 0xac0f00
1283 #define RSN_VERSION             1               /* current supported version */
1284
1285 #define RSN_CSE_NULL            0x00
1286 #define RSN_CSE_WEP40           0x01
1287 #define RSN_CSE_TKIP            0x02
1288 #define RSN_CSE_WRAP            0x03
1289 #define RSN_CSE_CCMP            0x04
1290 #define RSN_CSE_WEP104          0x05
1291
1292 #define RSN_ASE_NONE            0x00
1293 #define RSN_ASE_8021X_UNSPEC    0x01
1294 #define RSN_ASE_8021X_PSK       0x02
1295
1296 #define RSN_CAP_PREAUTH         0x01
1297
1298 #define WME_OUI                 0xf25000
1299 #define WME_OUI_TYPE            0x02
1300 #define WME_INFO_OUI_SUBTYPE    0x00
1301 #define WME_PARAM_OUI_SUBTYPE   0x01
1302 #define WME_VERSION             1
1303
1304 /* WME stream classes */
1305 #define WME_AC_BE       0               /* best effort */
1306 #define WME_AC_BK       1               /* background */
1307 #define WME_AC_VI       2               /* video */
1308 #define WME_AC_VO       3               /* voice */
1309
1310 /*
1311  * AUTH management packets
1312  *
1313  *      octet algo[2]
1314  *      octet seq[2]
1315  *      octet status[2]
1316  *      octet chal.id
1317  *      octet chal.length
1318  *      octet chal.text[253]            NB: 1-253 bytes
1319  */
1320
1321 /* challenge length for shared key auth */
1322 #define IEEE80211_CHALLENGE_LEN         128
1323
1324 #define IEEE80211_AUTH_ALG_OPEN         0x0000
1325 #define IEEE80211_AUTH_ALG_SHARED       0x0001
1326 #define IEEE80211_AUTH_ALG_LEAP         0x0080
1327
1328 enum {
1329         IEEE80211_AUTH_OPEN_REQUEST             = 1,
1330         IEEE80211_AUTH_OPEN_RESPONSE            = 2,
1331 };
1332
1333 enum {
1334         IEEE80211_AUTH_SHARED_REQUEST           = 1,
1335         IEEE80211_AUTH_SHARED_CHALLENGE         = 2,
1336         IEEE80211_AUTH_SHARED_RESPONSE          = 3,
1337         IEEE80211_AUTH_SHARED_PASS              = 4,
1338 };
1339
1340 /*
1341  * Reason and status codes.
1342  *
1343  * Reason codes are used in management frames to indicate why an
1344  * action took place (e.g. on disassociation).  Status codes are
1345  * used in management frames to indicate the result of an operation.
1346  *
1347  * Unlisted codes are reserved
1348  */
1349
1350 enum {
1351         IEEE80211_REASON_UNSPECIFIED            = 1,
1352         IEEE80211_REASON_AUTH_EXPIRE            = 2,
1353         IEEE80211_REASON_AUTH_LEAVE             = 3,
1354         IEEE80211_REASON_ASSOC_EXPIRE           = 4,
1355         IEEE80211_REASON_ASSOC_TOOMANY          = 5,
1356         IEEE80211_REASON_NOT_AUTHED             = 6,
1357         IEEE80211_REASON_NOT_ASSOCED            = 7,
1358         IEEE80211_REASON_ASSOC_LEAVE            = 8,
1359         IEEE80211_REASON_ASSOC_NOT_AUTHED       = 9,
1360         IEEE80211_REASON_DISASSOC_PWRCAP_BAD    = 10,   /* 11h */
1361         IEEE80211_REASON_DISASSOC_SUPCHAN_BAD   = 11,   /* 11h */
1362         IEEE80211_REASON_IE_INVALID             = 13,   /* 11i */
1363         IEEE80211_REASON_MIC_FAILURE            = 14,   /* 11i */
1364         IEEE80211_REASON_4WAY_HANDSHAKE_TIMEOUT = 15,   /* 11i */
1365         IEEE80211_REASON_GROUP_KEY_UPDATE_TIMEOUT = 16, /* 11i */
1366         IEEE80211_REASON_IE_IN_4WAY_DIFFERS     = 17,   /* 11i */
1367         IEEE80211_REASON_GROUP_CIPHER_INVALID   = 18,   /* 11i */
1368         IEEE80211_REASON_PAIRWISE_CIPHER_INVALID= 19,   /* 11i */
1369         IEEE80211_REASON_AKMP_INVALID           = 20,   /* 11i */
1370         IEEE80211_REASON_UNSUPP_RSN_IE_VERSION  = 21,   /* 11i */
1371         IEEE80211_REASON_INVALID_RSN_IE_CAP     = 22,   /* 11i */
1372         IEEE80211_REASON_802_1X_AUTH_FAILED     = 23,   /* 11i */
1373         IEEE80211_REASON_CIPHER_SUITE_REJECTED  = 24,   /* 11i */
1374         IEEE80211_REASON_UNSPECIFIED_QOS        = 32,   /* 11e */
1375         IEEE80211_REASON_INSUFFICIENT_BW        = 33,   /* 11e */
1376         IEEE80211_REASON_TOOMANY_FRAMES         = 34,   /* 11e */
1377         IEEE80211_REASON_OUTSIDE_TXOP           = 35,   /* 11e */
1378         IEEE80211_REASON_LEAVING_QBSS           = 36,   /* 11e */
1379         IEEE80211_REASON_BAD_MECHANISM          = 37,   /* 11e */
1380         IEEE80211_REASON_SETUP_NEEDED           = 38,   /* 11e */
1381         IEEE80211_REASON_TIMEOUT                = 39,   /* 11e */
1382
1383         IEEE80211_REASON_PEER_LINK_CANCELED     = 52,   /* 11s */
1384         IEEE80211_REASON_MESH_MAX_PEERS         = 53,   /* 11s */
1385         IEEE80211_REASON_MESH_CPVIOLATION       = 54,   /* 11s */
1386         IEEE80211_REASON_MESH_CLOSE_RCVD        = 55,   /* 11s */
1387         IEEE80211_REASON_MESH_MAX_RETRIES       = 56,   /* 11s */
1388         IEEE80211_REASON_MESH_CONFIRM_TIMEOUT   = 57,   /* 11s */
1389         IEEE80211_REASON_MESH_INVALID_GTK       = 58,   /* 11s */
1390         IEEE80211_REASON_MESH_INCONS_PARAMS     = 59,   /* 11s */
1391         IEEE80211_REASON_MESH_INVALID_SECURITY  = 60,   /* 11s */
1392         IEEE80211_REASON_MESH_PERR_NO_PROXY     = 61,   /* 11s */
1393         IEEE80211_REASON_MESH_PERR_NO_FI        = 62,   /* 11s */
1394         IEEE80211_REASON_MESH_PERR_DEST_UNREACH = 63,   /* 11s */
1395         IEEE80211_REASON_MESH_MAC_ALRDY_EXISTS_MBSS = 64, /* 11s */
1396         IEEE80211_REASON_MESH_CHAN_SWITCH_REG   = 65,   /* 11s */
1397         IEEE80211_REASON_MESH_CHAN_SWITCH_UNSPEC = 66,  /* 11s */
1398
1399         IEEE80211_STATUS_SUCCESS                = 0,
1400         IEEE80211_STATUS_UNSPECIFIED            = 1,
1401         IEEE80211_STATUS_CAPINFO                = 10,
1402         IEEE80211_STATUS_NOT_ASSOCED            = 11,
1403         IEEE80211_STATUS_OTHER                  = 12,
1404         IEEE80211_STATUS_ALG                    = 13,
1405         IEEE80211_STATUS_SEQUENCE               = 14,
1406         IEEE80211_STATUS_CHALLENGE              = 15,
1407         IEEE80211_STATUS_TIMEOUT                = 16,
1408         IEEE80211_STATUS_TOOMANY                = 17,
1409         IEEE80211_STATUS_BASIC_RATE             = 18,
1410         IEEE80211_STATUS_SP_REQUIRED            = 19,   /* 11b */
1411         IEEE80211_STATUS_PBCC_REQUIRED          = 20,   /* 11b */
1412         IEEE80211_STATUS_CA_REQUIRED            = 21,   /* 11b */
1413         IEEE80211_STATUS_SPECMGMT_REQUIRED      = 22,   /* 11h */
1414         IEEE80211_STATUS_PWRCAP_REQUIRED        = 23,   /* 11h */
1415         IEEE80211_STATUS_SUPCHAN_REQUIRED       = 24,   /* 11h */
1416         IEEE80211_STATUS_SHORTSLOT_REQUIRED     = 25,   /* 11g */
1417         IEEE80211_STATUS_DSSSOFDM_REQUIRED      = 26,   /* 11g */
1418         IEEE80211_STATUS_MISSING_HT_CAPS        = 27,   /* 11n D3.0 */
1419         IEEE80211_STATUS_INVALID_IE             = 40,   /* 11i */
1420         IEEE80211_STATUS_GROUP_CIPHER_INVALID   = 41,   /* 11i */
1421         IEEE80211_STATUS_PAIRWISE_CIPHER_INVALID = 42,  /* 11i */
1422         IEEE80211_STATUS_AKMP_INVALID           = 43,   /* 11i */
1423         IEEE80211_STATUS_UNSUPP_RSN_IE_VERSION  = 44,   /* 11i */
1424         IEEE80211_STATUS_INVALID_RSN_IE_CAP     = 45,   /* 11i */
1425         IEEE80211_STATUS_CIPHER_SUITE_REJECTED  = 46,   /* 11i */
1426 };
1427
1428 #define IEEE80211_WEP_KEYLEN            5       /* 40bit */
1429 #define IEEE80211_WEP_IVLEN             3       /* 24bit */
1430 #define IEEE80211_WEP_KIDLEN            1       /* 1 octet */
1431 #define IEEE80211_WEP_CRCLEN            4       /* CRC-32 */
1432 #define IEEE80211_WEP_TOTLEN            (IEEE80211_WEP_IVLEN + \
1433                                          IEEE80211_WEP_KIDLEN + \
1434                                          IEEE80211_WEP_CRCLEN)
1435 #define IEEE80211_WEP_NKID              4       /* number of key ids */
1436
1437 /*
1438  * 802.11i defines an extended IV for use with non-WEP ciphers.
1439  * When the EXTIV bit is set in the key id byte an additional
1440  * 4 bytes immediately follow the IV for TKIP.  For CCMP the
1441  * EXTIV bit is likewise set but the 8 bytes represent the
1442  * CCMP header rather than IV+extended-IV.
1443  */
1444 #define IEEE80211_WEP_EXTIV             0x20
1445 #define IEEE80211_WEP_EXTIVLEN          4       /* extended IV length */
1446 #define IEEE80211_WEP_MICLEN            8       /* trailing MIC */
1447
1448 #define IEEE80211_CRC_LEN               4
1449
1450 /*
1451  * Maximum acceptable MTU is:
1452  *      IEEE80211_MAX_LEN - WEP overhead - CRC -
1453  *              QoS overhead - RSN/WPA overhead
1454  * Min is arbitrarily chosen > IEEE80211_MIN_LEN.  The default
1455  * mtu is Ethernet-compatible; it's set by ether_ifattach.
1456  */
1457 #define IEEE80211_MTU_MAX               2290
1458 #define IEEE80211_MTU_MIN               32
1459
1460 #define IEEE80211_MAX_LEN               (2300 + IEEE80211_CRC_LEN + \
1461     (IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN))
1462 #define IEEE80211_ACK_LEN \
1463         (sizeof(struct ieee80211_frame_ack) + IEEE80211_CRC_LEN)
1464 #define IEEE80211_MIN_LEN \
1465         (sizeof(struct ieee80211_frame_min) + IEEE80211_CRC_LEN)
1466
1467 /*
1468  * The 802.11 spec says at most 2007 stations may be
1469  * associated at once.  For most AP's this is way more
1470  * than is feasible so we use a default of IEEE80211_AID_DEF.
1471  * This number may be overridden by the driver and/or by
1472  * user configuration but may not be less than IEEE80211_AID_MIN
1473  * (see _ieee80211.h for implementation-specific settings).
1474  */
1475 #define IEEE80211_AID_MAX               2007
1476
1477 #define IEEE80211_AID(b)        ((b) &~ 0xc000)
1478
1479 /* 
1480  * RTS frame length parameters.  The default is specified in
1481  * the 802.11 spec as 512; we treat it as implementation-dependent
1482  * so it's defined in ieee80211_var.h.  The max may be wrong
1483  * for jumbo frames.
1484  */
1485 #define IEEE80211_RTS_MIN               1
1486 #define IEEE80211_RTS_MAX               2346
1487
1488 /* 
1489  * TX fragmentation parameters.  As above for RTS, we treat
1490  * default as implementation-dependent so define it elsewhere.
1491  */
1492 #define IEEE80211_FRAG_MIN              256
1493 #define IEEE80211_FRAG_MAX              2346
1494
1495 /*
1496  * Beacon interval (TU's).  Min+max come from WiFi requirements.
1497  * As above, we treat default as implementation-dependent so
1498  * define it elsewhere.
1499  */
1500 #define IEEE80211_BINTVAL_MAX   1000    /* max beacon interval (TU's) */
1501 #define IEEE80211_BINTVAL_MIN   25      /* min beacon interval (TU's) */
1502
1503 /*
1504  * DTIM period (beacons).  Min+max are not really defined
1505  * by the protocol but we want them publicly visible so
1506  * define them here.
1507  */
1508 #define IEEE80211_DTIM_MAX      15      /* max DTIM period */
1509 #define IEEE80211_DTIM_MIN      1       /* min DTIM period */
1510
1511 /*
1512  * Beacon miss threshold (beacons).  As for DTIM, we define
1513  * them here to be publicly visible.  Note the max may be
1514  * clamped depending on device capabilities.
1515  */
1516 #define IEEE80211_HWBMISS_MIN   1
1517 #define IEEE80211_HWBMISS_MAX   255
1518
1519 /*
1520  * 802.11 frame duration definitions.
1521  */
1522
1523 struct ieee80211_duration {
1524         uint16_t        d_rts_dur;
1525         uint16_t        d_data_dur;
1526         uint16_t        d_plcp_len;
1527         uint8_t         d_residue;      /* unused octets in time slot */
1528 };
1529
1530 /* One Time Unit (TU) is 1Kus = 1024 microseconds. */
1531 #define IEEE80211_DUR_TU                1024
1532
1533 /* IEEE 802.11b durations for DSSS PHY in microseconds */
1534 #define IEEE80211_DUR_DS_LONG_PREAMBLE  144
1535 #define IEEE80211_DUR_DS_SHORT_PREAMBLE 72
1536
1537 #define IEEE80211_DUR_DS_SLOW_PLCPHDR   48
1538 #define IEEE80211_DUR_DS_FAST_PLCPHDR   24
1539 #define IEEE80211_DUR_DS_SLOW_ACK       112
1540 #define IEEE80211_DUR_DS_FAST_ACK       56
1541 #define IEEE80211_DUR_DS_SLOW_CTS       112
1542 #define IEEE80211_DUR_DS_FAST_CTS       56
1543
1544 #define IEEE80211_DUR_DS_SLOT           20
1545 #define IEEE80211_DUR_DS_SIFS           10
1546 #define IEEE80211_DUR_DS_PIFS   (IEEE80211_DUR_DS_SIFS + IEEE80211_DUR_DS_SLOT)
1547 #define IEEE80211_DUR_DS_DIFS   (IEEE80211_DUR_DS_SIFS + \
1548                                  2 * IEEE80211_DUR_DS_SLOT)
1549 #define IEEE80211_DUR_DS_EIFS   (IEEE80211_DUR_DS_SIFS + \
1550                                  IEEE80211_DUR_DS_SLOW_ACK + \
1551                                  IEEE80211_DUR_DS_LONG_PREAMBLE + \
1552                                  IEEE80211_DUR_DS_SLOW_PLCPHDR + \
1553                                  IEEE80211_DUR_DIFS)
1554
1555 #endif /* _NET80211_IEEE80211_H_ */