1 /*
2 * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef WM_IEEE80211_H
17 #define WM_IEEE80211_H
18 /*
19 * DS bit usage
20 *
21 * TA = transmitter address
22 * RA = receiver address
23 * DA = destination address
24 * SA = source address
25 *
26 * ToDS FromDS A1(RA) A2(TA) A3 A4 Use
27 * -----------------------------------------------------------------
28 * 0 0 DA SA BSSID - IBSS/DLS
29 * 0 1 DA BSSID SA - AP -> STA
30 * 1 0 BSSID SA DA - AP <- STA
31 * 1 1 RA TA DA SA unspecified (WDS)
32 */
33
34 #define FCS_LEN 4
35
36 #define IEEE80211_FCTL_VERS 0x0003
37 #define IEEE80211_FCTL_FTYPE 0x000c
38 #define IEEE80211_FCTL_STYPE 0x00f0
39 #define IEEE80211_FCTL_TODS 0x0100
40 #define IEEE80211_FCTL_FROMDS 0x0200
41 #define IEEE80211_FCTL_MOREFRAGS 0x0400
42 #define IEEE80211_FCTL_RETRY 0x0800
43 #define IEEE80211_FCTL_PM 0x1000
44 #define IEEE80211_FCTL_MOREDATA 0x2000
45 #define IEEE80211_FCTL_PROTECTED 0x4000
46 #define IEEE80211_FCTL_ORDER 0x8000
47
48 #define IEEE80211_SCTL_FRAG 0x000F
49 #define IEEE80211_SCTL_SEQ 0xFFF0
50
51 #define IEEE80211_FTYPE_MGMT 0x0000
52 #define IEEE80211_FTYPE_CTL 0x0004
53 #define IEEE80211_FTYPE_DATA 0x0008
54
55 /* management */
56 #define IEEE80211_STYPE_ASSOC_REQ 0x0000
57 #define IEEE80211_STYPE_ASSOC_RESP 0x0010
58 #define IEEE80211_STYPE_REASSOC_REQ 0x0020
59 #define IEEE80211_STYPE_REASSOC_RESP 0x0030
60 #define IEEE80211_STYPE_PROBE_REQ 0x0040
61 #define IEEE80211_STYPE_PROBE_RESP 0x0050
62 #define IEEE80211_STYPE_BEACON 0x0080
63 #define IEEE80211_STYPE_ATIM 0x0090
64 #define IEEE80211_STYPE_DISASSOC 0x00A0
65 #define IEEE80211_STYPE_AUTH 0x00B0
66 #define IEEE80211_STYPE_DEAUTH 0x00C0
67 #define IEEE80211_STYPE_ACTION 0x00D0
68
69 /* control */
70 #define IEEE80211_STYPE_BACK_REQ 0x0080
71 #define IEEE80211_STYPE_BACK 0x0090
72 #define IEEE80211_STYPE_PSPOLL 0x00A0
73 #define IEEE80211_STYPE_RTS 0x00B0
74 #define IEEE80211_STYPE_CTS 0x00C0
75 #define IEEE80211_STYPE_ACK 0x00D0
76 #define IEEE80211_STYPE_CFEND 0x00E0
77 #define IEEE80211_STYPE_CFENDACK 0x00F0
78
79 /* data */
80 #define IEEE80211_STYPE_DATA 0x0000
81 #define IEEE80211_STYPE_DATA_CFACK 0x0010
82 #define IEEE80211_STYPE_DATA_CFPOLL 0x0020
83 #define IEEE80211_STYPE_DATA_CFACKPOLL 0x0030
84 #define IEEE80211_STYPE_NULLFUNC 0x0040
85 #define IEEE80211_STYPE_CFACK 0x0050
86 #define IEEE80211_STYPE_CFPOLL 0x0060
87 #define IEEE80211_STYPE_CFACKPOLL 0x0070
88 #define IEEE80211_STYPE_QOS_DATA 0x0080
89 #define IEEE80211_STYPE_QOS_DATA_CFACK 0x0090
90 #define IEEE80211_STYPE_QOS_DATA_CFPOLL 0x00A0
91 #define IEEE80211_STYPE_QOS_DATA_CFACKPOLL 0x00B0
92 #define IEEE80211_STYPE_QOS_NULLFUNC 0x00C0
93 #define IEEE80211_STYPE_QOS_CFACK 0x00D0
94 #define IEEE80211_STYPE_QOS_CFPOLL 0x00E0
95 #define IEEE80211_STYPE_QOS_CFACKPOLL 0x00F0
96
97 #define IEEE80211_STA_DEFAULT_LISTEN_INTERVAL 10
98 #define IEEE80211_STA_MIN_LISTEN_INTERVAL 1
99
100 /* miscellaneous IEEE 802.11 constants */
101 #define IEEE80211_MAX_FRAG_THRESHOLD 2352
102 #define IEEE80211_MAX_RTS_THRESHOLD 2353
103 #define IEEE80211_MAX_AID 2007
104 #define IEEE80211_MAX_TIM_LEN 251
105 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
106 6.2.1.1.2.
107
108 802.11e clarifies the figure in section 7.1.2. The frame body is
109 up to 2304 octets long (maximum MSDU size) plus any crypt overhead. */
110 #define IEEE80211_MAX_DATA_LEN 2304
111 /* 30 byte 4 addr hdr, 2 byte QoS, 2304 byte MSDU, 12 byte crypt, 4 byte FCS */
112 #define IEEE80211_MAX_FRAME_LEN 2352
113
114 #define IEEE80211_MAX_SSID_LEN 32
115
116 #define IEEE80211_MAX_MESH_ID_LEN 32
117
118 #define IEEE80211_QOS_CTL_LEN 2
119 #define IEEE80211_QOS_CTL_TID_MASK 0x000F
120 #define IEEE80211_QOS_CTL_TAG1D_MASK 0x0007
121
122 #define IEEE80211_HT_CTL_LEN 4
123
124 /* U-APSD queue for WMM IEs sent by AP */
125 #define IEEE80211_WMM_IE_AP_QOSINFO_UAPSD (1<<7)
126
127 /* U-APSD queues for WMM IEs sent by STA */
128 #define IEEE80211_WMM_IE_STA_QOSINFO_AC_VO (1<<0)
129 #define IEEE80211_WMM_IE_STA_QOSINFO_AC_VI (1<<1)
130 #define IEEE80211_WMM_IE_STA_QOSINFO_AC_BK (1<<2)
131 #define IEEE80211_WMM_IE_STA_QOSINFO_AC_BE (1<<3)
132 #define IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK 0x0f
133
134 /* U-APSD max SP length for WMM IEs sent by STA */
135 #define IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL 0x00
136 #define IEEE80211_WMM_IE_STA_QOSINFO_SP_2 0x01
137 #define IEEE80211_WMM_IE_STA_QOSINFO_SP_4 0x02
138 #define IEEE80211_WMM_IE_STA_QOSINFO_SP_6 0x03
139 #define IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK 0x03
140 #define IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT 5
141
142 /* Parsed Information Elements */
143 struct ieee802_11_elems {
144 u8 *ie_start;
145 size_t total_len;
146
147 /* pointers to IEs */
148 u8 *ssid;
149 u8 *supp_rates;
150 u8 *fh_params;
151 u8 *ds_params;
152 u8 *cf_params;
153 u8 *tim;
154 u8 *ibss_params;
155 u8 *country_elem;
156 u8 *challenge;
157 u8 *erp_info;
158 u8 *ext_supp_rates;
159 u8 *wpa_ie;
160 u8 *rsn_ie;
161 u8 *wmm; /* WMM Information or Parameter Element */
162 u8 *wmm_param;
163 struct ieee80211_ht_cap *ht_cap_elem;
164 struct ieee80211_ht_info *ht_info_elem;
165 u8 *wmm_tspec;
166 u8 *wps_ie;
167 u8 *power_cap;
168 u8 *supp_channels;
169 u8 *mdie;
170 u8 *ftie;
171 u8 *timeout_int;
172 u8 *ch_switch_elem;
173 u8 *ht_capabilities;
174 u8 *ht_operation;
175 u8 *vendor_ht_cap;
176 u8 *p2p;
177 u8 *link_id;
178 u8 *pwr_constr_elem;
179 u8 *interworking;
180
181 u8 ssid_len;
182 u8 supp_rates_len;
183 u8 fh_params_len;
184 u8 ds_params_len;
185 u8 cf_params_len;
186 u8 tim_len;
187 u8 ibss_params_len;
188 u8 challenge_len;
189 u8 erp_info_len;
190 u8 ext_supp_rates_len;
191 u8 ch_switch_elem_len;
192 u8 wpa_ie_len;
193 u8 rsn_ie_len;
194 u8 wmm_len; /* 7 = WMM Information; 24 = WMM Parameter */
195 u8 wmm_param_len;
196 u8 wmm_tspec_len;
197 u8 wps_ie_len;
198 u8 power_cap_len;
199 u8 supp_channels_len;
200 u8 mdie_len;
201 u8 ftie_len;
202 u8 timeout_int_len;
203 u8 ht_capabilities_len;
204 u8 pwr_constr_elem_len;
205 u8 country_elem_len;
206 u8 ht_operation_len;
207 u8 vendor_ht_cap_len;
208 u8 p2p_len;
209 u8 interworking_len;
210 };
211
212 struct ieee80211_hdr {
213 u16 frame_control;
214 u16 duration_id;
215 u8 addr1[6];
216 u8 addr2[6];
217 u8 addr3[6];
218 u16 seq_ctrl;
219 u8 addr4[6];
220 }__attribute__((packed));
221
222 struct ieee80211_hdr_3addr {
223 u16 frame_control;
224 u16 duration_id;
225 u8 addr1[6];
226 u8 addr2[6];
227 u8 addr3[6];
228 u16 seq_ctrl;
229 }__attribute__((packed));
230
231 struct ieee80211_qos_hdr {
232 u16 frame_control;
233 u16 duration_id;
234 u8 addr1[6];
235 u8 addr2[6];
236 u8 addr3[6];
237 u16 seq_ctrl;
238 u16 qos_ctrl;
239 }__attribute__((packed));
240 typedef enum _phy_type {
241 phy_80211_b,
242 phy_80211_bg,
243 phy_80211_bgn,
244 phy_80211_n,
245 phy_80211_max
246 }phy_type;
247
248 #define IEEE80211_HDRLEN (sizeof(struct ieee80211_hdr_3addr))
249
250 /**
251 * ieee80211_has_tods - check if IEEE80211_FCTL_TODS is set
252 * @fc: frame control bytes in little-endian byteorder
253 */
ieee80211_has_tods(u16 fc)254 static __inline int ieee80211_has_tods(u16 fc)
255 {
256 return (fc & IEEE80211_FCTL_TODS) != 0;
257 }
258
259 /**
260 * ieee80211_has_fromds - check if IEEE80211_FCTL_FROMDS is set
261 * @fc: frame control bytes in little-endian byteorder
262 */
ieee80211_has_fromds(u16 fc)263 static __inline int ieee80211_has_fromds(u16 fc)
264 {
265 return (fc & IEEE80211_FCTL_FROMDS) != 0;
266 }
267
268 /**
269 * ieee80211_has_a4 - check if IEEE80211_FCTL_TODS and IEEE80211_FCTL_FROMDS are set
270 * @fc: frame control bytes in little-endian byteorder
271 */
ieee80211_has_a4(u16 fc)272 static __inline int ieee80211_has_a4(u16 fc)
273 {
274 u16 tmp = IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS;
275 return (fc & tmp) == tmp;
276 }
277
278 /**
279 * ieee80211_has_morefrags - check if IEEE80211_FCTL_MOREFRAGS is set
280 * @fc: frame control bytes in little-endian byteorder
281 */
ieee80211_has_morefrags(u16 fc)282 static __inline int ieee80211_has_morefrags(u16 fc)
283 {
284 return (fc & IEEE80211_FCTL_MOREFRAGS) != 0;
285 }
286
287 /**
288 * ieee80211_has_retry - check if IEEE80211_FCTL_RETRY is set
289 * @fc: frame control bytes in little-endian byteorder
290 */
ieee80211_has_retry(u16 fc)291 static __inline int ieee80211_has_retry(u16 fc)
292 {
293 return (fc & IEEE80211_FCTL_RETRY) != 0;
294 }
295
296 /**
297 * ieee80211_has_pm - check if IEEE80211_FCTL_PM is set
298 * @fc: frame control bytes in little-endian byteorder
299 */
ieee80211_has_pm(u16 fc)300 static __inline int ieee80211_has_pm(u16 fc)
301 {
302 return (fc & IEEE80211_FCTL_PM) != 0;
303 }
304
305 /**
306 * ieee80211_has_moredata - check if IEEE80211_FCTL_MOREDATA is set
307 * @fc: frame control bytes in little-endian byteorder
308 */
ieee80211_has_moredata(u16 fc)309 static __inline int ieee80211_has_moredata(u16 fc)
310 {
311 return (fc & IEEE80211_FCTL_MOREDATA) != 0;
312 }
313
314 /**
315 * ieee80211_has_protected - check if IEEE80211_FCTL_PROTECTED is set
316 * @fc: frame control bytes in little-endian byteorder
317 */
ieee80211_has_protected(u16 fc)318 static __inline int ieee80211_has_protected(u16 fc)
319 {
320 return (fc & IEEE80211_FCTL_PROTECTED) != 0;
321 }
322
323 /**
324 * ieee80211_has_order - check if IEEE80211_FCTL_ORDER is set
325 * @fc: frame control bytes in little-endian byteorder
326 */
ieee80211_has_order(u16 fc)327 static __inline int ieee80211_has_order(u16 fc)
328 {
329 return (fc & IEEE80211_FCTL_ORDER) != 0;
330 }
331
332 /**
333 * ieee80211_is_mgmt - check if type is IEEE80211_FTYPE_MGMT
334 * @fc: frame control bytes in little-endian byteorder
335 */
ieee80211_is_mgmt(u16 fc)336 static __inline int ieee80211_is_mgmt(u16 fc)
337 {
338 return (fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT;
339 }
340
341 /**
342 * ieee80211_is_ctl - check if type is IEEE80211_FTYPE_CTL
343 * @fc: frame control bytes in little-endian byteorder
344 */
ieee80211_is_ctl(u16 fc)345 static __inline int ieee80211_is_ctl(u16 fc)
346 {
347 return (fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL;
348 }
349
350 /**
351 * ieee80211_is_data - check if type is IEEE80211_FTYPE_DATA
352 * @fc: frame control bytes in little-endian byteorder
353 */
ieee80211_is_data(u16 fc)354 static __inline int ieee80211_is_data(u16 fc)
355 {
356 return (fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA;
357 }
358
359 /**
360 * ieee80211_is_data_qos - check if type is IEEE80211_FTYPE_DATA and IEEE80211_STYPE_QOS_DATA is set
361 * @fc: frame control bytes in little-endian byteorder
362 */
ieee80211_is_data_qos(u16 fc)363 static __inline int ieee80211_is_data_qos(u16 fc)
364 {
365 /*
366 * mask with QOS_DATA rather than IEEE80211_FCTL_STYPE as we just need
367 * to check the one bit
368 */
369 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_STYPE_QOS_DATA)) ==
370 (IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_DATA);
371 }
372
373 /**
374 * ieee80211_is_data_present - check if type is IEEE80211_FTYPE_DATA and has data
375 * @fc: frame control bytes in little-endian byteorder
376 */
ieee80211_is_data_present(u16 fc)377 static __inline int ieee80211_is_data_present(u16 fc)
378 {
379 /*
380 * mask with 0x40 and test that that bit is clear to only return TRUE
381 * for the data-containing substypes.
382 */
383 return (fc & (IEEE80211_FCTL_FTYPE | 0x40)) == (IEEE80211_FTYPE_DATA);
384 }
385
386 /**
387 * ieee80211_is_assoc_req - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ASSOC_REQ
388 * @fc: frame control bytes in little-endian byteorder
389 */
ieee80211_is_assoc_req(u16 fc)390 static __inline int ieee80211_is_assoc_req(u16 fc)
391 {
392 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
393 (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ASSOC_REQ);
394 }
395
396 /**
397 * ieee80211_is_assoc_resp - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ASSOC_RESP
398 * @fc: frame control bytes in little-endian byteorder
399 */
ieee80211_is_assoc_resp(u16 fc)400 static __inline int ieee80211_is_assoc_resp(u16 fc)
401 {
402 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
403 (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ASSOC_RESP);
404 }
405
406 /**
407 * ieee80211_is_reassoc_req - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_REASSOC_REQ
408 * @fc: frame control bytes in little-endian byteorder
409 */
ieee80211_is_reassoc_req(u16 fc)410 static __inline int ieee80211_is_reassoc_req(u16 fc)
411 {
412 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
413 (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_REASSOC_REQ);
414 }
415
416 /**
417 * ieee80211_is_reassoc_resp - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_REASSOC_RESP
418 * @fc: frame control bytes in little-endian byteorder
419 */
ieee80211_is_reassoc_resp(u16 fc)420 static __inline int ieee80211_is_reassoc_resp(u16 fc)
421 {
422 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
423 (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_REASSOC_RESP);
424 }
425
426 /**
427 * ieee80211_is_probe_req - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_PROBE_REQ
428 * @fc: frame control bytes in little-endian byteorder
429 */
ieee80211_is_probe_req(u16 fc)430 static __inline int ieee80211_is_probe_req(u16 fc)
431 {
432 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
433 (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ);
434 }
435
436 /**
437 * ieee80211_is_probe_resp - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_PROBE_RESP
438 * @fc: frame control bytes in little-endian byteorder
439 */
ieee80211_is_probe_resp(u16 fc)440 static __inline int ieee80211_is_probe_resp(u16 fc)
441 {
442 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
443 (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
444 }
445
446 /**
447 * ieee80211_is_beacon - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_BEACON
448 * @fc: frame control bytes in little-endian byteorder
449 */
ieee80211_is_beacon(u16 fc)450 static __inline int ieee80211_is_beacon(u16 fc)
451 {
452 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
453 (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
454 }
455
456 /**
457 * ieee80211_is_atim - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ATIM
458 * @fc: frame control bytes in little-endian byteorder
459 */
ieee80211_is_atim(u16 fc)460 static __inline int ieee80211_is_atim(u16 fc)
461 {
462 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
463 (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ATIM);
464 }
465
466 /**
467 * ieee80211_is_disassoc - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_DISASSOC
468 * @fc: frame control bytes in little-endian byteorder
469 */
ieee80211_is_disassoc(u16 fc)470 static __inline int ieee80211_is_disassoc(u16 fc)
471 {
472 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
473 (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DISASSOC);
474 }
475
476 /**
477 * ieee80211_is_auth - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_AUTH
478 * @fc: frame control bytes in little-endian byteorder
479 */
ieee80211_is_auth(u16 fc)480 static __inline int ieee80211_is_auth(u16 fc)
481 {
482 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
483 (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH);
484 }
485
486 /**
487 * ieee80211_is_deauth - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_DEAUTH
488 * @fc: frame control bytes in little-endian byteorder
489 */
ieee80211_is_deauth(u16 fc)490 static __inline int ieee80211_is_deauth(u16 fc)
491 {
492 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
493 (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_DEAUTH);
494 }
495
496 /**
497 * ieee80211_is_action - check if IEEE80211_FTYPE_MGMT && IEEE80211_STYPE_ACTION
498 * @fc: frame control bytes in little-endian byteorder
499 */
ieee80211_is_action(u16 fc)500 static __inline int ieee80211_is_action(u16 fc)
501 {
502 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
503 (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION);
504 }
505
506 /**
507 * ieee80211_is_back_req - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_BACK_REQ
508 * @fc: frame control bytes in little-endian byteorder
509 */
ieee80211_is_back_req(u16 fc)510 static __inline int ieee80211_is_back_req(u16 fc)
511 {
512 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
513 (IEEE80211_FTYPE_CTL | IEEE80211_STYPE_BACK_REQ);
514 }
515
516 /**
517 * ieee80211_is_back - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_BACK
518 * @fc: frame control bytes in little-endian byteorder
519 */
ieee80211_is_back(u16 fc)520 static __inline int ieee80211_is_back(u16 fc)
521 {
522 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
523 (IEEE80211_FTYPE_CTL | IEEE80211_STYPE_BACK);
524 }
525
526 /**
527 * ieee80211_is_pspoll - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_PSPOLL
528 * @fc: frame control bytes in little-endian byteorder
529 */
ieee80211_is_pspoll(u16 fc)530 static __inline int ieee80211_is_pspoll(u16 fc)
531 {
532 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
533 (IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
534 }
535
536 /**
537 * ieee80211_is_rts - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_RTS
538 * @fc: frame control bytes in little-endian byteorder
539 */
ieee80211_is_rts(u16 fc)540 static __inline int ieee80211_is_rts(u16 fc)
541 {
542 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
543 (IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
544 }
545
546 /**
547 * ieee80211_is_cts - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_CTS
548 * @fc: frame control bytes in little-endian byteorder
549 */
ieee80211_is_cts(u16 fc)550 static __inline int ieee80211_is_cts(u16 fc)
551 {
552 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
553 (IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
554 }
555
556 /**
557 * ieee80211_is_ack - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_ACK
558 * @fc: frame control bytes in little-endian byteorder
559 */
ieee80211_is_ack(u16 fc)560 static __inline int ieee80211_is_ack(u16 fc)
561 {
562 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
563 (IEEE80211_FTYPE_CTL | IEEE80211_STYPE_ACK);
564 }
565
566 /**
567 * ieee80211_is_cfend - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_CFEND
568 * @fc: frame control bytes in little-endian byteorder
569 */
ieee80211_is_cfend(u16 fc)570 static __inline int ieee80211_is_cfend(u16 fc)
571 {
572 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
573 (IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CFEND);
574 }
575
576 /**
577 * ieee80211_is_cfendack - check if IEEE80211_FTYPE_CTL && IEEE80211_STYPE_CFENDACK
578 * @fc: frame control bytes in little-endian byteorder
579 */
ieee80211_is_cfendack(u16 fc)580 static __inline int ieee80211_is_cfendack(u16 fc)
581 {
582 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
583 (IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CFENDACK);
584 }
585
586 /**
587 * ieee80211_is_nullfunc - check if frame is a regular (non-QoS) nullfunc frame
588 * @fc: frame control bytes in little-endian byteorder
589 */
ieee80211_is_nullfunc(u16 fc)590 static __inline int ieee80211_is_nullfunc(u16 fc)
591 {
592 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
593 (IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC);
594 }
595
596 /**
597 * ieee80211_is_qos_nullfunc - check if frame is a QoS nullfunc frame
598 * @fc: frame control bytes in little-endian byteorder
599 */
ieee80211_is_qos_nullfunc(u16 fc)600 static __inline int ieee80211_is_qos_nullfunc(u16 fc)
601 {
602 return (fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
603 (IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_NULLFUNC);
604 }
605
606 /**
607 * struct ieee80211_quiet_ie
608 *
609 * This structure refers to "Quiet information element"
610 */
611 struct ieee80211_quiet_ie {
612 u8 count;
613 u8 period;
614 u16 duration;
615 u16 offset;
616 }__attribute__((packed));
617
618 /**
619 * struct ieee80211_msrment_ie
620 *
621 * This structure refers to "Measurement Request/Report information element"
622 */
623 struct ieee80211_msrment_ie {
624 u8 token;
625 u8 mode;
626 u8 type;
627 u8 request[1];
628 }__attribute__((packed));
629
630 /**
631 * struct ieee80211_channel_sw_ie
632 *
633 * This structure refers to "Channel Switch Announcement information element"
634 */
635 struct ieee80211_channel_sw_ie {
636 u8 mode;
637 u8 new_ch_num;
638 u8 count;
639 }__attribute__((packed));
640
641 /**
642 * struct ieee80211_tim
643 *
644 * This structure refers to "Traffic Indication Map information element"
645 */
646 struct ieee80211_tim_ie {
647 u8 dtim_count;
648 u8 dtim_period;
649 u8 bitmap_ctrl;
650 /* variable size: 1 - 251 bytes */
651 u8 virtual_map[1];
652 }__attribute__((packed));
653
654 /**
655 * struct ieee80211_rann_ie
656 *
657 * This structure refers to "Root Announcement information element"
658 */
659 struct ieee80211_rann_ie {
660 u8 rann_flags;
661 u8 rann_hopcount;
662 u8 rann_ttl;
663 u8 rann_addr[6];
664 u32 rann_seq;
665 u32 rann_metric;
666 }__attribute__((packed));
667
668 #define WLAN_SA_QUERY_TR_ID_LEN 2
669
670 struct ieee80211_mgmt {
671 u16 frame_control;
672 u16 duration;
673 u8 da[6];
674 u8 sa[6];
675 u8 bssid[6];
676 u16 seq_ctrl;
677 union {
678 struct {
679 u16 auth_alg;
680 u16 auth_transaction;
681 u16 status_code;
682 /* possibly followed by Challenge text */
683 u8 variable[0];
684 } __attribute__ ((packed)) auth;
685 struct {
686 u16 reason_code;
687 } __attribute__ ((packed)) deauth;
688 struct {
689 u16 capab_info;
690 u16 listen_interval;
691 /* followed by SSID and Supported rates */
692 u8 variable[0];
693 } assoc_req;
694 struct {
695 u16 capab_info;
696 u16 status_code;
697 u16 aid;
698 /* followed by Supported rates */
699 u8 variable[0];
700 } __attribute__ ((packed)) assoc_resp, reassoc_resp;
701 struct {
702 u16 capab_info;
703 u16 listen_interval;
704 u8 current_ap[6];
705 /* followed by SSID and Supported rates */
706 u8 variable[0];
707 } __attribute__ ((packed)) reassoc_req;
708 struct {
709 u16 reason_code;
710 } __attribute__ ((packed)) disassoc;
711 struct {
712 u64 timestamp;
713 u16 beacon_int;
714 u16 capab_info;
715 /* followed by some of SSID, Supported rates,
716 * FH Params, DS Params, CF Params, IBSS Params, TIM */
717 u8 variable[0];
718 } __attribute__ ((packed)) beacon;
719 struct {
720 /* only variable items: SSID, Supported rates */
721 u8 variable[0];
722 } __attribute__ ((packed)) probe_req;
723 struct {
724 u64 timestamp;
725 u16 beacon_int;
726 u16 capab_info;
727 /* followed by some of SSID, Supported rates,
728 * FH Params, DS Params, CF Params, IBSS Params */
729 u8 variable[0];
730 } __attribute__ ((packed)) probe_resp;
731 struct {
732 u8 category;
733 union {
734 struct {
735 u8 action_code;
736 u8 dialog_token;
737 u8 status_code;
738 u8 variable[0];
739 } __attribute__ ((packed)) wme_action;
740 struct {
741 u8 action_code;
742 u8 element_id;
743 u8 length;
744 struct ieee80211_channel_sw_ie sw_elem;
745 } __attribute__ ((packed)) chan_switch;
746 struct {
747 u8 action_code;
748 u8 channel_width;
749 } __attribute__ ((packed)) chan_width;
750 struct {
751 u8 action_code;
752 u8 dialog_token;
753 u8 element_id;
754 u8 length;
755 struct ieee80211_msrment_ie msr_elem;
756 } __attribute__ ((packed)) measurement;
757 struct {
758 u8 action_code;
759 u8 dialog_token;
760 u16 capab;
761 u16 timeout;
762 u16 start_seq_num;
763 } __attribute__ ((packed)) addba_req;
764 struct {
765 u8 action_code;
766 u8 dialog_token;
767 u16 status;
768 u16 capab;
769 u16 timeout;
770 } __attribute__ ((packed)) addba_resp;
771 struct {
772 u8 action_code;
773 u16 params;
774 u16 reason_code;
775 } __attribute__ ((packed)) delba;
776 struct {
777 u8 action_code;
778 /* capab_info for open and confirm,
779 * reason for close
780 */
781 u16 aux;
782 /* Followed in plink_confirm by status
783 * code, AID and supported rates,
784 * and directly by supported rates in
785 * plink_open and plink_close
786 */
787 u8 variable[0];
788 } __attribute__ ((packed)) plink_action;
789 struct {
790 u8 action_code;
791 u8 variable[0];
792 } __attribute__ ((packed)) mesh_action;
793 struct {
794 u8 action;
795 u8 trans_id[WLAN_SA_QUERY_TR_ID_LEN];
796 } __attribute__ ((packed)) sa_query;
797 struct {
798 u8 action;
799 u8 smps_control;
800 } __attribute__ ((packed)) ht_smps;
801 } u;
802 } __attribute__ ((packed)) action;
803 } u;
804 } __attribute__ ((packed));
805
806 #if TLS_CONFIG_11N
807 /* mgmt header + 1 byte category code */
808 #define IEEE80211_MIN_ACTION_SIZE offsetof(struct ieee80211_mgmt, u.action.u)
809
810 #endif
811
812 /* Management MIC information element (IEEE 802.11w) */
813 struct ieee80211_mmie {
814 u8 element_id;
815 u8 length;
816 u16 key_id;
817 u8 sequence_number[6];
818 u8 mic[8];
819 }__attribute__ ((packed)) ;
820
821 /* Control frames */
822 struct ieee80211_rts {
823 u16 frame_control;
824 u16 duration;
825 u8 ra[6];
826 u8 ta[6];
827 }__attribute__ ((packed)) ;
828
829 struct ieee80211_cts {
830 u16 frame_control;
831 u16 duration;
832 u8 ra[6];
833 }__attribute__ ((packed)) ;
834
835 struct ieee80211_pspoll {
836 u16 frame_control;
837 u16 aid;
838 u8 bssid[6];
839 u8 ta[6];
840 }__attribute__ ((packed)) ;
841
842 /**
843 * struct ieee80211_bar - HT Block Ack Request
844 *
845 * This structure refers to "HT BlockAckReq" as
846 * described in 802.11n draft section 7.2.1.7.1
847 */
848 struct ieee80211_bar {
849 u16 frame_control;
850 u16 duration;
851 u8 ra[6];
852 u8 ta[6];
853 u16 control;
854 u16 start_seq_num;
855 }__attribute__ ((packed)) ;
856
857 /* 802.11 BAR control masks */
858 #define IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL 0x0000
859 #define IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA 0x0004
860
861 #define IEEE80211_HT_MCS_MASK_LEN 10
862
863 /**
864 * struct ieee80211_mcs_info - MCS information
865 * @rx_mask: RX mask
866 * @rx_highest: highest supported RX rate. If set represents
867 * the highest supported RX data rate in units of 1 Mbps.
868 * If this field is 0 this value should not be used to
869 * consider the highest RX data rate supported.
870 * @tx_params: TX parameters
871 */
872 struct ieee80211_mcs_info {
873 u8 rx_mask[IEEE80211_HT_MCS_MASK_LEN];
874 u16 rx_highest;
875 u8 tx_params;
876 u8 reserved[3];
877 }__attribute__ ((packed)) ;
878
879 /* 802.11n HT capability MSC set */
880 #define IEEE80211_HT_MCS_RX_HIGHEST_MASK 0x3ff
881 #define IEEE80211_HT_MCS_TX_DEFINED 0x01
882 #define IEEE80211_HT_MCS_TX_RX_DIFF 0x02
883 /* value 0 == 1 stream etc */
884 #define IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK 0x0C
885 #define IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT 2
886 #define IEEE80211_HT_MCS_TX_MAX_STREAMS 4
887 #define IEEE80211_HT_MCS_TX_UNEQUAL_MODULATION 0x10
888
889 /*
890 * 802.11n D5.0 20.3.5 / 20.6 says:
891 * - indices 0 to 7 and 32 are single spatial stream
892 * - 8 to 31 are multiple spatial streams using equal modulation
893 * [8..15 for two streams, 16..23 for three and 24..31 for four]
894 * - remainder are multiple spatial streams using unequal modulation
895 */
896 #define IEEE80211_HT_MCS_UNEQUAL_MODULATION_START 33
897 #define IEEE80211_HT_MCS_UNEQUAL_MODULATION_START_BYTE \
898 (IEEE80211_HT_MCS_UNEQUAL_MODULATION_START / 8)
899
900 /**
901 * struct ieee80211_ht_cap - HT capabilities
902 *
903 * This structure is the "HT capabilities element" as
904 * described in 802.11n D5.0 7.3.2.56
905 */
906 struct ieee80211_ht_cap {
907 u16 cap_info;
908 u8 ampdu_params_info;
909
910 /* 16 bytes MCS information */
911 struct ieee80211_mcs_info mcs;
912
913 u16 extended_ht_cap_info;
914 u32 tx_BF_cap_info;
915 u8 antenna_selection_info;
916 }__attribute__ ((packed)) ;
917
918 /* 802.11n HT capabilities masks (for cap_info) */
919 #define IEEE80211_HT_CAP_LDPC_CODING 0x0001
920 #define IEEE80211_HT_CAP_SUP_WIDTH_20_40 0x0002
921 #define IEEE80211_HT_CAP_SM_PS 0x000C
922 #define IEEE80211_HT_CAP_SM_PS_SHIFT 2
923 /* Spatial Multiplexing Power Save Modes (for capability) */
924 #define IEEE80211_HT_CAP_SM_PS_STATIC 0
925 #define IEEE80211_HT_CAP_SM_PS_DYNAMIC 1
926 #define IEEE80211_HT_CAP_SM_PS_INVALID 2
927 #define IEEE80211_HT_CAP_SM_PS_DISABLED 3
928
929 #define IEEE80211_HT_CAP_GRN_FLD 0x0010
930 #define IEEE80211_HT_CAP_SGI_20 0x0020
931 #define IEEE80211_HT_CAP_SGI_40 0x0040
932 #define IEEE80211_HT_CAP_TX_STBC 0x0080
933 #define IEEE80211_HT_CAP_RX_STBC 0x0300
934 #define IEEE80211_HT_CAP_RX_STBC_SHIFT 8
935 #define IEEE80211_HT_CAP_RX_STBC_DISABLE 0
936 #define IEEE80211_HT_CAP_RX_STBC_1 1
937 #define IEEE80211_HT_CAP_RX_STBC_2 2
938 #define IEEE80211_HT_CAP_RX_STBC_3 3
939
940 #define IEEE80211_HT_CAP_DELAY_BA 0x0400
941 #define IEEE80211_HT_CAP_MAX_AMSDU 0x0800
942 #define IEEE80211_HT_CAP_DSSSCCK40 0x1000
943 #define IEEE80211_HT_CAP_RESERVED 0x2000
944 #define IEEE80211_HT_CAP_40MHZ_INTOLERANT 0x4000
945 #define IEEE80211_HT_CAP_LSIG_TXOP_PROT 0x8000
946
947 /* 802.11n HT capability AMPDU settings (for ampdu_params_info) */
948 #define IEEE80211_HT_AMPDU_PARM_FACTOR 0x03
949 #define IEEE80211_HT_AMPDU_PARM_DENSITY 0x1C
950 #define IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT 2
951
952 /*
953 * Maximum length of AMPDU that the STA can receive.
954 * Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
955 */
956 enum ieee80211_max_ampdu_length_exp {
957 IEEE80211_HT_MAX_AMPDU_8K = 0,
958 IEEE80211_HT_MAX_AMPDU_16K = 1,
959 IEEE80211_HT_MAX_AMPDU_32K = 2,
960 IEEE80211_HT_MAX_AMPDU_64K = 3
961 };
962
963 /* 802.11n HT extended capability */
964 #define IEEE80211_HT_EXT_CAP_HTC 0x0400
965 #define IEEE80211_HT_EXT_CAP_RD 0x0800
966
967 #define IEEE80211_HT_MAX_AMPDU_FACTOR 13
968
969 /* Minimum MPDU start spacing */
970 enum ieee80211_min_mpdu_spacing {
971 IEEE80211_HT_MPDU_DENSITY_NONE = 0, /* No restriction */
972 IEEE80211_HT_MPDU_DENSITY_0_25 = 1, /* 1/4 usec */
973 IEEE80211_HT_MPDU_DENSITY_0_5 = 2, /* 1/2 usec */
974 IEEE80211_HT_MPDU_DENSITY_1 = 3, /* 1 usec */
975 IEEE80211_HT_MPDU_DENSITY_2 = 4, /* 2 usec */
976 IEEE80211_HT_MPDU_DENSITY_4 = 5, /* 4 usec */
977 IEEE80211_HT_MPDU_DENSITY_8 = 6, /* 8 usec */
978 IEEE80211_HT_MPDU_DENSITY_16 = 7 /* 16 usec */
979 };
980
981 #define IEEE80211_HT_MPDU_DENSITY_SHIFT 2
982 /**
983 * struct ieee80211_ht_info - HT information
984 *
985 * This structure is the "HT information element" as
986 * described in 802.11n D5.0 7.3.2.58
987 */
988 /* ELEMENTID = 61, HT Operation element in 11n7.3.5.57
989 */
990 struct ieee80211_ht_info {
991 u8 control_chan;
992 u8 ht_param;
993 u16 operation_mode;
994 u16 stbc_param;
995 u8 basic_set[16];
996 }__attribute__((packed));
997
998 /* for ht_param */
999 #define IEEE80211_HT_PARAM_CHA_SEC_OFFSET 0x03
1000 #define IEEE80211_HT_PARAM_CHA_SEC_NONE 0x00
1001 #define IEEE80211_HT_PARAM_CHA_SEC_ABOVE 0x01
1002 #define IEEE80211_HT_PARAM_CHA_SEC_BELOW 0x03
1003 #define IEEE80211_HT_PARAM_CHAN_WIDTH_ANY 0x04
1004 #define IEEE80211_HT_PARAM_RIFS_MODE 0x08
1005 #define IEEE80211_HT_PARAM_SPSMP_SUPPORT 0x10
1006 #define IEEE80211_HT_PARAM_SERV_INTERVAL_GRAN 0xE0
1007
1008 /* for operation_mode */
1009 #define IEEE80211_HT_OP_MODE_PROTECTION 0x0003
1010 #define IEEE80211_HT_OP_MODE_PROTECTION_NONE 0
1011 #define IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER 1
1012 #define IEEE80211_HT_OP_MODE_PROTECTION_20MHZ 2
1013 #define IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED 3
1014 #define IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT 0x0004
1015 #define IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT 0x0010
1016
1017 /* for stbc_param */
1018 #define IEEE80211_HT_STBC_PARAM_DUAL_BEACON 0x0040
1019 #define IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT 0x0080
1020 #define IEEE80211_HT_STBC_PARAM_STBC_BEACON 0x0100
1021 #define IEEE80211_HT_STBC_PARAM_LSIG_TXOP_FULLPROT 0x0200
1022 #define IEEE80211_HT_STBC_PARAM_PCO_ACTIVE 0x0400
1023 #define IEEE80211_HT_STBC_PARAM_PCO_PHASE 0x0800
1024
1025 /* block-ack parameters */
1026 #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
1027 #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
1028 #define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
1029 #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
1030 #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
1031
1032 /*
1033 * A-PMDU buffer sizes
1034 * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2)
1035 */
1036 #define IEEE80211_MIN_AMPDU_BUF 0x8
1037 #define IEEE80211_MAX_AMPDU_BUF 0x40
1038
1039 /* Spatial Multiplexing Power Save Modes (for capability) */
1040 #define WLAN_HT_CAP_SM_PS_STATIC 0
1041 #define WLAN_HT_CAP_SM_PS_DYNAMIC 1
1042 #define WLAN_HT_CAP_SM_PS_INVALID 2
1043 #define WLAN_HT_CAP_SM_PS_DISABLED 3
1044
1045 /* for SM power control field lower two bits */
1046 #define WLAN_HT_SMPS_CONTROL_DISABLED 0
1047 #define WLAN_HT_SMPS_CONTROL_STATIC 1
1048 #define WLAN_HT_SMPS_CONTROL_DYNAMIC 3
1049
1050 /* Authentication algorithms */
1051 #define WLAN_AUTH_OPEN 0
1052 #define WLAN_AUTH_SHARED_KEY 1
1053 #define WLAN_AUTH_FT 2
1054 #define WLAN_AUTH_LEAP 128
1055
1056 #define WLAN_AUTH_CHALLENGE_LEN 128
1057
1058 #define WLAN_CAPABILITY_ESS (1<<0)
1059 #define WLAN_CAPABILITY_IBSS (1<<1)
1060 #define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
1061 #define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
1062 #define WLAN_CAPABILITY_PRIVACY (1<<4)
1063 #define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
1064 #define WLAN_CAPABILITY_PBCC (1<<6)
1065 #define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
1066
1067 /* 802.11h */
1068 #define WLAN_CAPABILITY_SPECTRUM_MGMT (1<<8)
1069 #define WLAN_CAPABILITY_QOS (1<<9)
1070 #define WLAN_CAPABILITY_SHORT_SLOT_TIME (1<<10)
1071 #define WLAN_CAPABILITY_DSSS_OFDM (1<<13)
1072 /* measurement */
1073 #define IEEE80211_SPCT_MSR_RPRT_MODE_LATE (1<<0)
1074 #define IEEE80211_SPCT_MSR_RPRT_MODE_INCAPABLE (1<<1)
1075 #define IEEE80211_SPCT_MSR_RPRT_MODE_REFUSED (1<<2)
1076
1077 #define IEEE80211_SPCT_MSR_RPRT_TYPE_BASIC 0
1078 #define IEEE80211_SPCT_MSR_RPRT_TYPE_CCA 1
1079 #define IEEE80211_SPCT_MSR_RPRT_TYPE_RPI 2
1080
1081 /* 802.11g ERP information element */
1082 #define WLAN_ERP_NON_ERP_PRESENT (1<<0)
1083 #define WLAN_ERP_USE_PROTECTION (1<<1)
1084 #define WLAN_ERP_BARKER_PREAMBLE (1<<2)
1085
1086 /* WLAN_ERP_BARKER_PREAMBLE values */
1087 enum {
1088 WLAN_ERP_PREAMBLE_SHORT = 0,
1089 WLAN_ERP_PREAMBLE_LONG = 1,
1090 };
1091
1092 /* Status codes */
1093 enum ieee80211_statuscode {
1094 WLAN_STATUS_SUCCESS = 0,
1095 WLAN_STATUS_UNSPECIFIED_FAILURE = 1,
1096 WLAN_STATUS_CAPS_UNSUPPORTED = 10,
1097 WLAN_STATUS_REASSOC_NO_ASSOC = 11,
1098 WLAN_STATUS_ASSOC_DENIED_UNSPEC = 12,
1099 WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG = 13,
1100 WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION = 14,
1101 WLAN_STATUS_CHALLENGE_FAIL = 15,
1102 WLAN_STATUS_AUTH_TIMEOUT = 16,
1103 WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA = 17,
1104 WLAN_STATUS_ASSOC_DENIED_RATES = 18,
1105 /* 802.11b */
1106 WLAN_STATUS_ASSOC_DENIED_NOSHORTPREAMBLE = 19,
1107 WLAN_STATUS_ASSOC_DENIED_NOPBCC = 20,
1108 WLAN_STATUS_ASSOC_DENIED_NOAGILITY = 21,
1109 /* 802.11h */
1110 WLAN_STATUS_ASSOC_DENIED_NOSPECTRUM = 22,
1111 WLAN_STATUS_ASSOC_REJECTED_BAD_POWER = 23,
1112 WLAN_STATUS_ASSOC_REJECTED_BAD_SUPP_CHAN = 24,
1113 /* 802.11g */
1114 WLAN_STATUS_ASSOC_DENIED_NOSHORTTIME = 25,
1115 WLAN_STATUS_ASSOC_DENIED_NODSSSOFDM = 26,
1116 /* 802.11w */
1117 WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY = 30,
1118 WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION = 31,
1119 /* 802.11i */
1120 WLAN_STATUS_INVALID_IE = 40,
1121 WLAN_STATUS_INVALID_GROUP_CIPHER = 41,
1122 WLAN_STATUS_INVALID_PAIRWISE_CIPHER = 42,
1123 WLAN_STATUS_INVALID_AKMP = 43,
1124 WLAN_STATUS_UNSUPP_RSN_VERSION = 44,
1125 WLAN_STATUS_INVALID_RSN_IE_CAP = 45,
1126 WLAN_STATUS_CIPHER_SUITE_REJECTED = 46,
1127 /* 802.11e */
1128 WLAN_STATUS_UNSPECIFIED_QOS = 32,
1129 WLAN_STATUS_ASSOC_DENIED_NOBANDWIDTH = 33,
1130 WLAN_STATUS_ASSOC_DENIED_LOWACK = 34,
1131 WLAN_STATUS_ASSOC_DENIED_UNSUPP_QOS = 35,
1132 WLAN_STATUS_REQUEST_DECLINED = 37,
1133 WLAN_STATUS_INVALID_QOS_PARAM = 38,
1134 WLAN_STATUS_CHANGE_TSPEC = 39,
1135 WLAN_STATUS_WAIT_TS_DELAY = 47,
1136 WLAN_STATUS_NO_DIRECT_LINK = 48,
1137 WLAN_STATUS_STA_NOT_PRESENT = 49,
1138 WLAN_STATUS_STA_NOT_QSTA = 50,
1139 WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE = 51,
1140 };
1141
1142 /* Reason codes */
1143 enum ieee80211_reasoncode {
1144 WLAN_REASON_UNSPECIFIED = 1,
1145 WLAN_REASON_PREV_AUTH_NOT_VALID = 2,
1146 WLAN_REASON_DEAUTH_LEAVING = 3,
1147 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY = 4,
1148 WLAN_REASON_DISASSOC_AP_BUSY = 5,
1149 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA = 6,
1150 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA = 7,
1151 WLAN_REASON_DISASSOC_STA_HAS_LEFT = 8,
1152 WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH = 9,
1153 /* 802.11h */
1154 WLAN_REASON_DISASSOC_BAD_POWER = 10,
1155 WLAN_REASON_DISASSOC_BAD_SUPP_CHAN = 11,
1156 /* 802.11i */
1157 WLAN_REASON_INVALID_IE = 13,
1158 WLAN_REASON_MIC_FAILURE = 14,
1159 WLAN_REASON_4WAY_HANDSHAKE_TIMEOUT = 15,
1160 WLAN_REASON_GROUP_KEY_HANDSHAKE_TIMEOUT = 16,
1161 WLAN_REASON_IE_DIFFERENT = 17,
1162 WLAN_REASON_INVALID_GROUP_CIPHER = 18,
1163 WLAN_REASON_INVALID_PAIRWISE_CIPHER = 19,
1164 WLAN_REASON_INVALID_AKMP = 20,
1165 WLAN_REASON_UNSUPP_RSN_VERSION = 21,
1166 WLAN_REASON_INVALID_RSN_IE_CAP = 22,
1167 WLAN_REASON_IEEE8021X_FAILED = 23,
1168 WLAN_REASON_CIPHER_SUITE_REJECTED = 24,
1169 /* 802.11e */
1170 WLAN_REASON_DISASSOC_UNSPECIFIED_QOS = 32,
1171 WLAN_REASON_DISASSOC_QAP_NO_BANDWIDTH = 33,
1172 WLAN_REASON_DISASSOC_LOW_ACK = 34,
1173 WLAN_REASON_DISASSOC_QAP_EXCEED_TXOP = 35,
1174 WLAN_REASON_QSTA_LEAVE_QBSS = 36,
1175 WLAN_REASON_QSTA_NOT_USE = 37,
1176 WLAN_REASON_QSTA_REQUIRE_SETUP = 38,
1177 WLAN_REASON_QSTA_TIMEOUT = 39,
1178 WLAN_REASON_QSTA_CIPHER_NOT_SUPP = 45,
1179 };
1180
1181 /* Information Element IDs */
1182 enum ieee80211_eid {
1183 WLAN_EID_SSID = 0,
1184 WLAN_EID_SUPP_RATES = 1,
1185 WLAN_EID_FH_PARAMS = 2,
1186 WLAN_EID_DS_PARAMS = 3,
1187 WLAN_EID_CF_PARAMS = 4,
1188 WLAN_EID_TIM = 5,
1189 WLAN_EID_IBSS_PARAMS = 6,
1190 WLAN_EID_CHALLENGE = 16,
1191
1192 WLAN_EID_COUNTRY = 7,
1193 WLAN_EID_HP_PARAMS = 8,
1194 WLAN_EID_HP_TABLE = 9,
1195 WLAN_EID_REQUEST = 10,
1196
1197 WLAN_EID_QBSS_LOAD = 11,
1198 WLAN_EID_EDCA_PARAM_SET = 12,
1199 WLAN_EID_TSPEC = 13,
1200 WLAN_EID_TCLAS = 14,
1201 WLAN_EID_SCHEDULE = 15,
1202 WLAN_EID_TS_DELAY = 43,
1203 WLAN_EID_TCLAS_PROCESSING = 44,
1204 WLAN_EID_QOS_CAPA = 46,
1205 /* 802.11s */
1206 WLAN_EID_MESH_CONFIG = 113,
1207 WLAN_EID_MESH_ID = 114,
1208 WLAN_EID_LINK_METRIC_REPORT = 115,
1209 WLAN_EID_CONGESTION_NOTIFICATION = 116,
1210 /* Note that the Peer Link IE has been replaced with the similar
1211 * Peer Management IE. We will keep the former definition until mesh
1212 * code is changed to comply with latest 802.11s drafts.
1213 */
1214 WLAN_EID_PEER_LINK = 55, /* no longer in 802.11s drafts */
1215 WLAN_EID_PEER_MGMT = 117,
1216 WLAN_EID_CHAN_SWITCH_PARAM = 118,
1217 WLAN_EID_MESH_AWAKE_WINDOW = 119,
1218 WLAN_EID_BEACON_TIMING = 120,
1219 WLAN_EID_MCCAOP_SETUP_REQ = 121,
1220 WLAN_EID_MCCAOP_SETUP_RESP = 122,
1221 WLAN_EID_MCCAOP_ADVERT = 123,
1222 WLAN_EID_MCCAOP_TEARDOWN = 124,
1223 WLAN_EID_GANN = 125,
1224 WLAN_EID_RANN = 126,
1225 WLAN_EID_PREQ = 130,
1226 WLAN_EID_PREP = 131,
1227 WLAN_EID_PERR = 132,
1228 WLAN_EID_PXU = 137,
1229 WLAN_EID_PXUC = 138,
1230 WLAN_EID_AUTH_MESH_PEER_EXCH = 139,
1231 WLAN_EID_MIC = 140,
1232
1233 WLAN_EID_PWR_CONSTRAINT = 32,
1234 WLAN_EID_PWR_CAPABILITY = 33,
1235 WLAN_EID_TPC_REQUEST = 34,
1236 WLAN_EID_TPC_REPORT = 35,
1237 WLAN_EID_SUPPORTED_CHANNELS = 36,
1238 WLAN_EID_CHANNEL_SWITCH = 37,
1239 WLAN_EID_MEASURE_REQUEST = 38,
1240 WLAN_EID_MEASURE_REPORT = 39,
1241 WLAN_EID_QUIET = 40,
1242 WLAN_EID_IBSS_DFS = 41,
1243
1244 WLAN_EID_ERP_INFO = 42,
1245 WLAN_EID_EXT_SUPP_RATES = 50,
1246
1247 WLAN_EID_HT_CAPABILITY = 45,
1248 WLAN_EID_HT_INFORMATION = 61,
1249
1250 WLAN_EID_RSN = 48,
1251 WLAN_EID_MMIE = 76,
1252 WLAN_EID_WPA = 221,
1253 WLAN_EID_GENERIC = 221,
1254 WLAN_EID_VENDOR_SPECIFIC = 221,
1255 WLAN_EID_QOS_PARAMETER = 222,
1256
1257 WLAN_EID_AP_CHAN_REPORT = 51,
1258 WLAN_EID_NEIGHBOR_REPORT = 52,
1259 WLAN_EID_RCPI = 53,
1260 WLAN_EID_BSS_AVG_ACCESS_DELAY = 63,
1261 WLAN_EID_ANTENNA_INFO = 64,
1262 WLAN_EID_RSNI = 65,
1263 WLAN_EID_MEASUREMENT_PILOT_TX_INFO = 66,
1264 WLAN_EID_BSS_AVAILABLE_CAPACITY = 67,
1265 WLAN_EID_BSS_AC_ACCESS_DELAY = 68,
1266 WLAN_EID_RRM_ENABLED_CAPABILITIES = 70,
1267 WLAN_EID_MULTIPLE_BSSID = 71,
1268 WLAN_EID_BSS_COEX_2040 = 72,
1269 WLAN_EID_OVERLAP_BSS_SCAN_PARAM = 74,
1270 WLAN_EID_EXT_CAPABILITY = 127,
1271
1272 WLAN_EID_MOBILITY_DOMAIN = 54,
1273 WLAN_EID_FAST_BSS_TRANSITION = 55,
1274 WLAN_EID_TIMEOUT_INTERVAL = 56,
1275 WLAN_EID_RIC_DATA = 57,
1276 WLAN_EID_RIC_DESCRIPTOR = 75,
1277
1278 WLAN_EID_DSE_REGISTERED_LOCATION = 58,
1279 WLAN_EID_SUPPORTED_REGULATORY_CLASSES = 59,
1280 WLAN_EID_EXT_CHANSWITCH_ANN = 60,
1281
1282 WLAN_EID_TIME_ZONE = 98,
1283 WLAN_EID_LINK_ID = 101,
1284 WLAN_EID_INTERWORKING = 107,
1285 WLAN_EID_ADV_PROTO = 108,
1286 WLAN_EID_ROAMING_CONSORTIUM = 111,
1287 WLAN_EID_EXT_CAPAB = 127,
1288 };
1289
1290 /* Action category code */
1291 enum ieee80211_category {
1292 WLAN_CATEGORY_SPECTRUM_MGMT = 0,
1293 WLAN_CATEGORY_QOS = 1,
1294 WLAN_CATEGORY_DLS = 2,
1295 WLAN_CATEGORY_BACK = 3,
1296 WLAN_CATEGORY_PUBLIC = 4,
1297 WLAN_CATEGORY_HT = 7,
1298 WLAN_CATEGORY_SA_QUERY = 8,
1299 WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION = 9,
1300 WLAN_CATEGORY_WMM = 17,
1301 WLAN_CATEGORY_VENDOR_SPECIFIC_PROTECTED = 126,
1302 WLAN_CATEGORY_VENDOR_SPECIFIC = 127,
1303 };
1304
1305 /* SPECTRUM_MGMT action code */
1306 enum ieee80211_spectrum_mgmt_actioncode {
1307 WLAN_ACTION_SPCT_MSR_REQ = 0,
1308 WLAN_ACTION_SPCT_MSR_RPRT = 1,
1309 WLAN_ACTION_SPCT_TPC_REQ = 2,
1310 WLAN_ACTION_SPCT_TPC_RPRT = 3,
1311 WLAN_ACTION_SPCT_CHL_SWITCH = 4,
1312 };
1313
1314 /* HT action codes */
1315 enum ieee80211_ht_actioncode {
1316 WLAN_HT_ACTION_NOTIFY_CHANWIDTH = 0,
1317 WLAN_HT_ACTION_SMPS = 1,
1318 WLAN_HT_ACTION_PSMP = 2,
1319 WLAN_HT_ACTION_PCO_PHASE = 3,
1320 WLAN_HT_ACTION_CSI = 4,
1321 WLAN_HT_ACTION_NONCOMPRESSED_BF = 5,
1322 WLAN_HT_ACTION_COMPRESSED_BF = 6,
1323 WLAN_HT_ACTION_ASEL_IDX_FEEDBACK = 7,
1324 };
1325
1326 /* Security key length */
1327 enum ieee80211_key_len {
1328 WLAN_KEY_LEN_WEP40 = 5,
1329 WLAN_KEY_LEN_WEP104 = 13,
1330 WLAN_KEY_LEN_CCMP = 16,
1331 WLAN_KEY_LEN_TKIP = 32,
1332 WLAN_KEY_LEN_AES_CMAC = 16,
1333 };
1334
1335 /*
1336 * IEEE 802.11-2007 7.3.2.9 Country information element
1337 *
1338 * Minimum length is 8 octets, ie len must be evenly
1339 * divisible by 2
1340 */
1341
1342 /* Although the spec says 8 I'm seeing 6 in practice */
1343 #define IEEE80211_COUNTRY_IE_MIN_LEN 6
1344
1345 /*
1346 * For regulatory extension stuff see IEEE 802.11-2007
1347 * Annex I (page 1141) and Annex J (page 1147). Also
1348 * review 7.3.2.9.
1349 *
1350 * When dot11RegulatoryClassesRequired is TRUE and the
1351 * first_channel/reg_extension_id is >= 201 then the IE
1352 * compromises of the 'ext' struct represented below:
1353 *
1354 * - Regulatory extension ID - when generating IE this just needs
1355 * to be monotonically increasing for each triplet passed in
1356 * the IE
1357 * - Regulatory class - index into set of rules
1358 * - Coverage class - index into air propagation time (Table 7-27),
1359 * in microseconds, you can compute the air propagation time from
1360 * the index by multiplying by 3, so index 10 yields a propagation
1361 * of 10 us. Valid values are 0-31, values 32-255 are not defined
1362 * yet. A value of 0 inicates air propagation of <= 1 us.
1363 *
1364 * See also Table I.2 for Emission limit sets and table
1365 * I.3 for Behavior limit sets. Table J.1 indicates how to map
1366 * a reg_class to an emission limit set and behavior limit set.
1367 */
1368 #define IEEE80211_COUNTRY_EXTENSION_ID 201
1369
1370 /*
1371 * Channels numbers in the IE must be monotonically increasing
1372 * if dot11RegulatoryClassesRequired is not TRUE.
1373 *
1374 * If dot11RegulatoryClassesRequired is TRUE consecutive
1375 * subband triplets following a regulatory triplet shall
1376 * have monotonically increasing first_channel number fields.
1377 *
1378 * Channel numbers shall not overlap.
1379 *
1380 * Note that max_power is signed.
1381 */
1382 struct ieee80211_country_ie_triplet {
1383 union {
1384 struct {
1385 u8 first_channel;
1386 u8 num_channels;
1387 s8 max_power;
1388 }__attribute__((packed))chans;
1389 struct {
1390 u8 reg_extension_id;
1391 u8 reg_class;
1392 u8 coverage_class;
1393 }__attribute__((packed))ext;
1394 }__attribute__((packed))u;
1395 }__attribute__((packed));
1396
1397 enum ieee80211_timeout_interval_type {
1398 WLAN_TIMEOUT_REASSOC_DEADLINE = 1 /* 802.11r */,
1399 WLAN_TIMEOUT_KEY_LIFETIME = 2 /* 802.11r */,
1400 WLAN_TIMEOUT_ASSOC_COMEBACK = 3 /* 802.11w */,
1401 };
1402
1403 /* BACK action code */
1404 enum ieee80211_back_actioncode {
1405 WLAN_ACTION_ADDBA_REQ = 0,
1406 WLAN_ACTION_ADDBA_RESP = 1,
1407 WLAN_ACTION_DELBA = 2,
1408 };
1409
1410 /* BACK (block-ack) parties */
1411 enum ieee80211_back_parties {
1412 WLAN_BACK_RECIPIENT = 0,
1413 WLAN_BACK_INITIATOR = 1,
1414 WLAN_BACK_TIMER = 2,
1415 };
1416
1417 /* SA Query action */
1418 enum ieee80211_sa_query_action {
1419 WLAN_ACTION_SA_QUERY_REQUEST = 0,
1420 WLAN_ACTION_SA_QUERY_RESPONSE = 1,
1421 };
1422
1423 /* A-MSDU 802.11n */
1424 #define IEEE80211_QOS_CONTROL_A_MSDU_PRESENT 0x0080
1425
1426 /* cipher suite selectors */
1427 #define WLAN_CIPHER_SUITE_USE_GROUP 0x000FAC00
1428 #define WLAN_CIPHER_SUITE_WEP40 0x000FAC01
1429 #define WLAN_CIPHER_SUITE_TKIP 0x000FAC02
1430 /* reserved: 0x000FAC03 */
1431 #define WLAN_CIPHER_SUITE_CCMP 0x000FAC04
1432 #define WLAN_CIPHER_SUITE_WEP104 0x000FAC05
1433 #define WLAN_CIPHER_SUITE_AES_CMAC 0x000FAC06
1434
1435 /* AKM suite selectors */
1436 #define WLAN_AKM_SUITE_8021X 0x000FAC01
1437 #define WLAN_AKM_SUITE_PSK 0x000FAC02
1438
1439 #define WLAN_MAX_KEY_LEN 32
1440
1441 #define WLAN_PMKID_LEN 16
1442
1443 /**
1444 * ieee80211_get_qos_ctl - get pointer to qos control bytes
1445 * @hdr: the frame
1446 *
1447 * The qos ctrl bytes come after the frame_control, duration, seq_num
1448 * and 3 or 4 addresses of length ETH_ALEN.
1449 * 3 addr: 2 + 2 + 2 + 3*6 = 24
1450 * 4 addr: 2 + 2 + 2 + 4*6 = 30
1451 */
ieee80211_get_qos_ctl(struct ieee80211_hdr * hdr)1452 static __inline u8 *ieee80211_get_qos_ctl(struct ieee80211_hdr *hdr)
1453 {
1454 if (ieee80211_has_a4(hdr->frame_control)) {
1455 return (u8 *)hdr + 30;
1456 } else {
1457 return (u8 *)hdr + 24;
1458 }
1459 }
1460
1461 /**
1462 * ieee80211_get_SA - get pointer to SA
1463 * @hdr: the frame
1464 *
1465 * Given an 802.11 frame, this function returns the offset
1466 * to the source address (SA). It does not verify that the
1467 * header is long enough to contain the address, and the
1468 * header must be long enough to contain the frame control
1469 * field.
1470 */
ieee80211_get_SA(struct ieee80211_hdr * hdr)1471 static __inline u8 *ieee80211_get_SA(struct ieee80211_hdr *hdr)
1472 {
1473 if (ieee80211_has_a4(hdr->frame_control)) {
1474 return hdr->addr4;
1475 }
1476 if (ieee80211_has_fromds(hdr->frame_control)) {
1477 return hdr->addr3;
1478 }
1479 return hdr->addr2;
1480 }
1481
1482 /**
1483 * ieee80211_get_DA - get pointer to DA
1484 * @hdr: the frame
1485 *
1486 * Given an 802.11 frame, this function returns the offset
1487 * to the destination address (DA). It does not verify that
1488 * the header is long enough to contain the address, and the
1489 * header must be long enough to contain the frame control
1490 * field.
1491 */
ieee80211_get_DA(struct ieee80211_hdr * hdr)1492 static __inline u8 *ieee80211_get_DA(struct ieee80211_hdr *hdr)
1493 {
1494 if (ieee80211_has_tods(hdr->frame_control)) {
1495 return hdr->addr3;
1496 } else {
1497 return hdr->addr1;
1498 }
1499 }
1500
1501 /**
1502 * ieee80211_is_robust_mgmt_frame - check if frame is a robust management frame
1503 * @hdr: the frame (buffer must include at least the first octet of payload)
1504 */
ieee80211_is_robust_mgmt_frame(struct ieee80211_hdr * hdr)1505 static __inline bool ieee80211_is_robust_mgmt_frame(struct ieee80211_hdr *hdr)
1506 {
1507 if (ieee80211_is_disassoc(hdr->frame_control) ||
1508 ieee80211_is_deauth(hdr->frame_control)) {
1509 return TRUE;
1510 }
1511
1512 if (ieee80211_is_action(hdr->frame_control)) {
1513 u8 *category;
1514
1515 /*
1516 * Action frames, excluding Public Action frames, are Robust
1517 * Management Frames. However, if we are looking at a Protected
1518 * frame, skip the check since the data may be encrypted and
1519 * the frame has already been found to be a Robust Management
1520 * Frame (by the other end).
1521 */
1522 if (ieee80211_has_protected(hdr->frame_control)) {
1523 return TRUE;
1524 }
1525 category = ((u8 *) hdr) + 24;
1526 return *category != WLAN_CATEGORY_PUBLIC &&
1527 *category != WLAN_CATEGORY_HT &&
1528 *category != WLAN_CATEGORY_VENDOR_SPECIFIC;
1529 }
1530
1531 return FALSE;
1532 }
1533
1534 /**
1535 * ieee80211_fhss_chan_to_freq - get channel frequency
1536 * @channel: the FHSS channel
1537 *
1538 * Convert IEEE802.11 FHSS channel to frequency (MHz)
1539 * Ref IEEE 802.11-2007 section 14.6
1540 */
ieee80211_fhss_chan_to_freq(int channel)1541 static __inline int ieee80211_fhss_chan_to_freq(int channel)
1542 {
1543 if ((channel > 1) && (channel < 96)) { // 96:byte alignment
1544 return channel + 2400; // 2400:byte alignment
1545 } else {
1546 return -1;
1547 }
1548 }
1549
1550 /**
1551 * ieee80211_freq_to_fhss_chan - get channel
1552 * @freq: the channels frequency
1553 *
1554 * Convert frequency (MHz) to IEEE802.11 FHSS channel
1555 * Ref IEEE 802.11-2007 section 14.6
1556 */
ieee80211_freq_to_fhss_chan(int freq)1557 static __inline int ieee80211_freq_to_fhss_chan(int freq)
1558 {
1559 if ((freq > 2401) && (freq < 2496)) { // 2401:byte alignment, 2496:byte alignment
1560 return freq - 2400; // 2400:byte alignment
1561 } else {
1562 return -1;
1563 }
1564 }
1565
1566 /**
1567 * ieee80211_dsss_chan_to_freq - get channel center frequency
1568 * @channel: the DSSS channel
1569 *
1570 * Convert IEEE802.11 DSSS channel to the center frequency (MHz).
1571 * Ref IEEE 802.11-2007 section 15.6
1572 */
ieee80211_dsss_chan_to_freq(int channel)1573 static __inline int ieee80211_dsss_chan_to_freq(int channel)
1574 {
1575 if ((channel > 0) && (channel < 14)) { // 14:byte alignment
1576 return 2407 + (channel * 5); // 2407:byte alignment, 5:byte alignment
1577 } else if (channel == 14) { // 14:byte alignment
1578 return 2484; // 2484:byte alignment
1579 } else {
1580 return -1;
1581 }
1582 }
1583
1584 /**
1585 * ieee80211_freq_to_dsss_chan - get channel
1586 * @freq: the frequency
1587 *
1588 * Convert frequency (MHz) to IEEE802.11 DSSS channel
1589 * Ref IEEE 802.11-2007 section 15.6
1590 *
1591 * This routine selects the channel with the closest center frequency.
1592 */
ieee80211_freq_to_dsss_chan(int freq)1593 static __inline int ieee80211_freq_to_dsss_chan(int freq)
1594 {
1595 if ((freq >= 2410) && (freq < 2475)) { // 2410:byte alignment, 2475:byte alignment
1596 return (freq - 2405) / 5; // 2405:byte alignment, 5:byte alignment
1597 } else if ((freq >= 2482) && (freq < 2487)) { // 2482:byte alignment, 2487:byte alignment
1598 return 14; // 14:byte alignment
1599 } else {
1600 return -1;
1601 }
1602 }
1603
1604 /* Convert IEEE802.11 HR DSSS channel to frequency (MHz) and back
1605 * Ref IEEE 802.11-2007 section 18.4.6.2
1606 *
1607 * The channels and frequencies are the same as those defined for DSSS
1608 */
1609 #define ieee80211_hr_chan_to_freq(chan) ieee80211_dsss_chan_to_freq(chan)
1610 #define ieee80211_freq_to_hr_chan(freq) ieee80211_freq_to_dsss_chan(freq)
1611
1612 /* Convert IEEE802.11 ERP channel to frequency (MHz) and back
1613 * Ref IEEE 802.11-2007 section 19.4.2
1614 */
1615 #define ieee80211_erp_chan_to_freq(chan) ieee80211_hr_chan_to_freq(chan)
1616 #define ieee80211_freq_to_erp_chan(freq) ieee80211_freq_to_hr_chan(freq)
1617
1618 /**
1619 * ieee80211_ofdm_chan_to_freq - get channel center frequency
1620 * @s_freq: starting frequency == (dotChannelStartingFactor/2) MHz
1621 * @channel: the OFDM channel
1622 *
1623 * Convert IEEE802.11 OFDM channel to center frequency (MHz)
1624 * Ref IEEE 802.11-2007 section 17.3.8.3.2
1625 */
ieee80211_ofdm_chan_to_freq(int s_freq,int channel)1626 static __inline int ieee80211_ofdm_chan_to_freq(int s_freq, int channel)
1627 {
1628 if ((channel > 0) && (channel <= 200) && // 200:byte alignment
1629 (s_freq >= 4000)) { // 4000:byte alignment
1630 return s_freq + (channel * 5); // 5:byte alignment
1631 } else {
1632 return -1;
1633 }
1634 }
1635
1636 /**
1637 * ieee80211_freq_to_ofdm_channel - get channel
1638 * @s_freq: starting frequency == (dotChannelStartingFactor/2) MHz
1639 * @freq: the frequency
1640 *
1641 * Convert frequency (MHz) to IEEE802.11 OFDM channel
1642 * Ref IEEE 802.11-2007 section 17.3.8.3.2
1643 *
1644 * This routine selects the channel with the closest center frequency.
1645 */
ieee80211_freq_to_ofdm_chan(int s_freq,int freq)1646 static __inline int ieee80211_freq_to_ofdm_chan(int s_freq, int freq)
1647 {
1648 if ((freq > (s_freq + 2)) && (freq <= (s_freq + 1202)) && // 2:byte alignment, 1202:byte alignment
1649 (s_freq >= 4000)) { // 4000:byte alignment
1650 return (freq + 2 - s_freq) / 5; // 5:byte alignment
1651 } else {
1652 return -1;
1653 }
1654 }
1655
1656 /**
1657 * ieee80211_tu_to_usec - convert time units (TU) to microseconds
1658 * @tu: the TUs
1659 */
ieee80211_tu_to_usec(unsigned long tu)1660 static __inline unsigned long ieee80211_tu_to_usec(unsigned long tu)
1661 {
1662 return 1024 * tu;
1663 }
1664
1665 /**
1666 * ieee80211_check_tim - check if AID bit is set in TIM
1667 * @tim: the TIM IE
1668 * @tim_len: length of the TIM IE
1669 * @aid: the AID to look for
1670 */
ieee80211_check_tim(struct ieee80211_tim_ie * tim,u8 tim_len,u16 aid)1671 static __inline bool ieee80211_check_tim(struct ieee80211_tim_ie *tim,
1672 u8 tim_len, u16 aid)
1673 {
1674 u8 mask;
1675 u8 index, indexn1, indexn2;
1676
1677 if (!tim || tim_len < sizeof(*tim))
1678 return FALSE;
1679
1680 aid &= 0x3fff;
1681 index = aid / 8;
1682 mask = 1 << (aid & 7);
1683
1684 indexn1 = tim->bitmap_ctrl & 0xfe;
1685 indexn2 = tim_len + indexn1 - 4;
1686
1687 if (index < indexn1 || index > indexn2)
1688 return FALSE;
1689
1690 index -= indexn1;
1691
1692 return !!(tim->virtual_map[index] & mask);
1693 }
1694
1695 #endif /* end of TLS_IEEE80211_H */