1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
6 * Modifications for inclusion into the Linux staging tree are
7 * Copyright(c) 2010 Larry Finger. All rights reserved.
10 * WLAN FAE <wlanfae@realtek.com>
11 * Larry Finger <Larry.Finger@lwfinger.net>
13 ******************************************************************************/
17 #include <linux/compiler.h>
19 #define WLAN_IEEE_OUI_LEN 3
20 #define WLAN_CRC_LEN 4
21 #define WLAN_BSSID_LEN 6
22 #define WLAN_BSS_TS_LEN 8
23 #define WLAN_HDR_A3_LEN 24
24 #define WLAN_HDR_A4_LEN 30
25 #define WLAN_HDR_A3_QOS_LEN 26
26 #define WLAN_HDR_A4_QOS_LEN 32
27 #define WLAN_SSID_MAXLEN 32
28 #define WLAN_DATA_MAXLEN 2312
30 #define WLAN_A3_PN_OFFSET 24
31 #define WLAN_A4_PN_OFFSET 30
33 #define WLAN_MIN_ETHFRM_LEN 60
34 #define WLAN_MAX_ETHFRM_LEN 1514
36 #define P80211CAPTURE_VERSION 0x80211001
38 enum WIFI_FRAME_TYPE {
40 WIFI_CTRL_TYPE = (BIT(2)),
41 WIFI_DATA_TYPE = (BIT(3)),
42 WIFI_QOS_DATA_TYPE = (BIT(7)|BIT(3)), /*!< QoS Data */
45 enum WIFI_FRAME_SUBTYPE {
46 /* below is for mgt frame */
47 WIFI_ASSOCREQ = (0 | WIFI_MGT_TYPE),
48 WIFI_ASSOCRSP = (BIT(4) | WIFI_MGT_TYPE),
49 WIFI_REASSOCREQ = (BIT(5) | WIFI_MGT_TYPE),
50 WIFI_REASSOCRSP = (BIT(5) | BIT(4) | WIFI_MGT_TYPE),
51 WIFI_PROBEREQ = (BIT(6) | WIFI_MGT_TYPE),
52 WIFI_PROBERSP = (BIT(6) | BIT(4) | WIFI_MGT_TYPE),
53 WIFI_BEACON = (BIT(7) | WIFI_MGT_TYPE),
54 WIFI_ATIM = (BIT(7) | BIT(4) | WIFI_MGT_TYPE),
55 WIFI_DISASSOC = (BIT(7) | BIT(5) | WIFI_MGT_TYPE),
56 WIFI_AUTH = (BIT(7) | BIT(5) | BIT(4) | WIFI_MGT_TYPE),
57 WIFI_DEAUTH = (BIT(7) | BIT(6) | WIFI_MGT_TYPE),
58 WIFI_ACTION = (BIT(7) | BIT(6) | BIT(4) | WIFI_MGT_TYPE),
59 /* below is for control frame */
60 WIFI_PSPOLL = (BIT(7) | BIT(5) | WIFI_CTRL_TYPE),
61 WIFI_RTS = (BIT(7) | BIT(5) | BIT(4) | WIFI_CTRL_TYPE),
62 WIFI_CTS = (BIT(7) | BIT(6) | WIFI_CTRL_TYPE),
63 WIFI_ACK = (BIT(7) | BIT(6) | BIT(4) | WIFI_CTRL_TYPE),
64 WIFI_CFEND = (BIT(7) | BIT(6) | BIT(5) | WIFI_CTRL_TYPE),
65 WIFI_CFEND_CFACK = (BIT(7) | BIT(6) | BIT(5) | BIT(4) | WIFI_CTRL_TYPE),
66 /* below is for data frame */
67 WIFI_DATA = (0 | WIFI_DATA_TYPE),
68 WIFI_DATA_CFACK = (BIT(4) | WIFI_DATA_TYPE),
69 WIFI_DATA_CFPOLL = (BIT(5) | WIFI_DATA_TYPE),
70 WIFI_DATA_CFACKPOLL = (BIT(5) | BIT(4) | WIFI_DATA_TYPE),
71 WIFI_DATA_NULL = (BIT(6) | WIFI_DATA_TYPE),
72 WIFI_CF_ACK = (BIT(6) | BIT(4) | WIFI_DATA_TYPE),
73 WIFI_CF_POLL = (BIT(6) | BIT(5) | WIFI_DATA_TYPE),
74 WIFI_CF_ACKPOLL = (BIT(6) | BIT(5) | BIT(4) | WIFI_DATA_TYPE),
77 enum WIFI_REASON_CODE {
79 _RSON_UNSPECIFIED_ = 1,
80 _RSON_AUTH_NO_LONGER_VALID_ = 2,
81 _RSON_DEAUTH_STA_LEAVING_ = 3,
82 _RSON_INACTIVITY_ = 4,
83 _RSON_UNABLE_HANDLE_ = 5,
86 _RSON_DISAOC_STA_LEAVING_ = 8,
87 _RSON_ASOC_NOT_AUTH_ = 9,
89 _RSON_INVALID_IE_ = 13,
90 _RSON_MIC_FAILURE_ = 14,
91 _RSON_4WAY_HNDSHK_TIMEOUT_ = 15,
92 _RSON_GROUP_KEY_UPDATE_TIMEOUT_ = 16,
94 _RSON_MLTCST_CIPHER_NOT_VALID_ = 18,
95 _RSON_UNICST_CIPHER_NOT_VALID_ = 19,
96 _RSON_AKMP_NOT_VALID_ = 20,
97 _RSON_UNSUPPORT_RSNE_VER_ = 21,
98 _RSON_INVALID_RSNE_CAP_ = 22,
99 _RSON_IEEE_802DOT1X_AUTH_FAIL_ = 23,
100 /* below are Realtek definitions */
101 _RSON_PMK_NOT_AVAILABLE_ = 24,
104 enum WIFI_REG_DOMAIN {
118 #define _TO_DS_ BIT(8)
119 #define _FROM_DS_ BIT(9)
120 #define _MORE_FRAG_ BIT(10)
121 #define _RETRY_ BIT(11)
122 #define _PWRMGT_ BIT(12)
123 #define _MORE_DATA_ BIT(13)
124 #define _PRIVACY_ BIT(14)
125 #define _ORDER_ BIT(15)
127 #define SetToDs(pbuf) ({ \
128 *(__le16 *)(pbuf) |= cpu_to_le16(_TO_DS_); \
131 #define GetToDs(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_TO_DS_)) != 0)
133 #define ClearToDs(pbuf) ({ \
134 *(__le16 *)(pbuf) &= (~cpu_to_le16(_TO_DS_)); \
137 #define SetFrDs(pbuf) ({ \
138 *(__le16 *)(pbuf) |= cpu_to_le16(_FROM_DS_); \
141 #define GetFrDs(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_FROM_DS_)) != 0)
143 #define ClearFrDs(pbuf) ({ \
144 *(__le16 *)(pbuf) &= (~cpu_to_le16(_FROM_DS_)); \
147 static inline unsigned char get_tofr_ds(unsigned char *pframe)
149 return ((GetToDs(pframe) << 1) | GetFrDs(pframe));
152 #define SetMFrag(pbuf) ({ \
153 *(__le16 *)(pbuf) |= cpu_to_le16(_MORE_FRAG_); \
156 #define GetMFrag(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_MORE_FRAG_)) != 0)
158 #define ClearMFrag(pbuf) ({ \
159 *(__le16 *)(pbuf) &= (~cpu_to_le16(_MORE_FRAG_)); \
162 #define SetRetry(pbuf) ({ \
163 *(__le16 *)(pbuf) |= cpu_to_le16(_RETRY_); \
166 #define GetRetry(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_RETRY_)) != 0)
168 #define ClearRetry(pbuf) ({ \
169 *(__le16 *)(pbuf) &= (~cpu_to_le16(_RETRY_)); \
172 #define SetPwrMgt(pbuf) ({ \
173 *(__le16 *)(pbuf) |= cpu_to_le16(_PWRMGT_); \
176 #define GetPwrMgt(pbuf) (((*(__le16 *)(pbuf)) & \
177 cpu_to_le16(_PWRMGT_)) != 0)
179 #define ClearPwrMgt(pbuf) ({ \
180 *(__le16 *)(pbuf) &= (~cpu_to_le16(_PWRMGT_)); \
183 #define SetMData(pbuf) ({ \
184 *(__le16 *)(pbuf) |= cpu_to_le16(_MORE_DATA_); \
187 #define GetMData(pbuf) (((*(__le16 *)(pbuf)) & \
188 cpu_to_le16(_MORE_DATA_)) != 0)
190 #define ClearMData(pbuf) ({ \
191 *(__le16 *)(pbuf) &= (~cpu_to_le16(_MORE_DATA_)); \
194 #define SetPrivacy(pbuf) ({ \
195 *(__le16 *)(pbuf) |= cpu_to_le16(_PRIVACY_); \
198 #define GetPrivacy(pbuf) (((*(__le16 *)(pbuf)) & \
199 cpu_to_le16(_PRIVACY_)) != 0)
201 #define GetOrder(pbuf) (((*(__le16 *)(pbuf)) & \
202 cpu_to_le16(_ORDER_)) != 0)
204 #define GetFrameType(pbuf) (le16_to_cpu(*(__le16 *)(pbuf)) & \
207 #define SetFrameType(pbuf, type) \
209 *(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(3) | \
211 *(__le16 *)(pbuf) |= cpu_to_le16(type); \
214 #define GetFrameSubType(pbuf) (le16_to_cpu(*(__le16 *)(pbuf)) & \
215 (BIT(7) | BIT(6) | BIT(5) | BIT(4) | BIT(3) | \
218 #define SetFrameSubType(pbuf, type) \
220 *(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(7) | BIT(6) | \
221 BIT(5) | BIT(4) | BIT(3) | BIT(2))); \
222 *(__le16 *)(pbuf) |= cpu_to_le16(type); \
225 #define GetSequence(pbuf) (le16_to_cpu(*(__le16 *)\
226 ((addr_t)(pbuf) + 22)) >> 4)
228 #define GetFragNum(pbuf) (le16_to_cpu(*(__le16 *)((addr_t)\
229 (pbuf) + 22)) & 0x0f)
231 #define SetSeqNum(pbuf, num) ({ \
232 *(__le16 *)((addr_t)(pbuf) + 22) = \
233 cpu_to_le16((le16_to_cpu(*(__le16 *)((addr_t)(pbuf) + 22)) & \
234 0x000f) | (0xfff0 & (num << 4))); \
237 #define SetDuration(pbuf, dur) ({ \
238 *(__le16 *)((addr_t)(pbuf) + 2) |= \
239 cpu_to_le16(0xffff & (dur)); \
242 #define SetPriority(pbuf, tid) ({ \
243 *(__le16 *)(pbuf) |= cpu_to_le16(tid & 0xf); \
246 #define GetPriority(pbuf) ((le16_to_cpu(*(__le16 *)(pbuf))) & 0xf)
248 #define SetAckpolicy(pbuf, ack) ({ \
249 *(__le16 *)(pbuf) |= cpu_to_le16((ack & 3) << 5); \
252 #define GetAckpolicy(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 5) & 0x3)
254 #define GetAMsdu(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 7) & 0x1)
256 #define GetAid(pbuf) (cpu_to_le16(*(__le16 *)((addr_t)(pbuf) + 2)) \
259 #define GetAddr1Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 4))
261 #define GetAddr2Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 10))
263 #define GetAddr3Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 16))
265 #define GetAddr4Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 24))
267 static inline unsigned char *get_da(unsigned char *pframe)
270 unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
273 case 0x00: /* ToDs=0, FromDs=0 */
274 da = GetAddr1Ptr(pframe);
276 case 0x01: /* ToDs=0, FromDs=1 */
277 da = GetAddr1Ptr(pframe);
279 case 0x02: /* ToDs=1, FromDs=0 */
280 da = GetAddr3Ptr(pframe);
282 default: /* ToDs=1, FromDs=1 */
283 da = GetAddr3Ptr(pframe);
289 static inline unsigned char *get_sa(unsigned char *pframe)
292 unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
295 case 0x00: /* ToDs=0, FromDs=0 */
296 sa = GetAddr2Ptr(pframe);
298 case 0x01: /* ToDs=0, FromDs=1 */
299 sa = GetAddr3Ptr(pframe);
301 case 0x02: /* ToDs=1, FromDs=0 */
302 sa = GetAddr2Ptr(pframe);
304 default: /* ToDs=1, FromDs=1 */
305 sa = GetAddr4Ptr(pframe);
312 static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
315 unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
318 case 0x00: /* ToDs=0, FromDs=0 */
319 sa = GetAddr3Ptr(pframe);
321 case 0x01: /* ToDs=0, FromDs=1 */
322 sa = GetAddr2Ptr(pframe);
324 case 0x02: /* ToDs=1, FromDs=0 */
325 sa = GetAddr1Ptr(pframe);
327 default: /* ToDs=1, FromDs=1 */
334 /*-----------------------------------------------------------------------------
335 * Below is for the security related definition
336 *-----------------------------------------------------------------------------
338 #define _RESERVED_FRAME_TYPE_ 0
339 #define _SKB_FRAME_TYPE_ 2
340 #define _PRE_ALLOCMEM_ 1
341 #define _PRE_ALLOCHDR_ 3
342 #define _PRE_ALLOCLLCHDR_ 4
343 #define _PRE_ALLOCICVHDR_ 5
344 #define _PRE_ALLOCMICHDR_ 6
346 #define _SIFSTIME_ ((priv->pmib->BssType.net_work_type & \
347 WIRELESS_11A) ? 16 : 10)
348 #define _ACKCTSLNG_ 14 /*14 bytes long, including crclng */
351 #define _ASOCREQ_IE_OFFSET_ 4 /* excluding wlan_hdr */
352 #define _ASOCRSP_IE_OFFSET_ 6
353 #define _REASOCREQ_IE_OFFSET_ 10
354 #define _REASOCRSP_IE_OFFSET_ 6
355 #define _PROBEREQ_IE_OFFSET_ 0
356 #define _PROBERSP_IE_OFFSET_ 12
357 #define _AUTH_IE_OFFSET_ 6
358 #define _DEAUTH_IE_OFFSET_ 0
359 #define _BEACON_IE_OFFSET_ 12
361 #define _FIXED_IE_LENGTH_ _BEACON_IE_OFFSET_
364 #define _SUPPORTEDRATES_IE_ 1
366 #define _IBSS_PARA_IE_ 6
367 #define _ERPINFO_IE_ 42
368 #define _EXT_SUPPORTEDRATES_IE_ 50
370 #define _HT_CAPABILITY_IE_ 45
371 #define _HT_EXTRA_INFO_IE_ 61
372 #define _HT_ADD_INFO_IE_ 61 /* _HT_EXTRA_INFO_IE_ */
374 #define _VENDOR_SPECIFIC_IE_ 221
376 #define _RESERVED47_ 47
378 /* ---------------------------------------------------------------------------
379 * Below is the fixed elements...
380 * ---------------------------------------------------------------------------
382 #define _AUTH_ALGM_NUM_ 2
383 #define _AUTH_SEQ_NUM_ 2
384 #define _BEACON_ITERVAL_ 2
385 #define _CAPABILITY_ 2
386 #define _CURRENT_APADDR_ 6
387 #define _LISTEN_INTERVAL_ 2
388 #define _RSON_CODE_ 2
390 #define _STATUS_CODE_ 2
391 #define _TIMESTAMP_ 8
393 #define AUTH_ODD_TO 0
394 #define AUTH_EVEN_TO 1
396 #define WLAN_ETHCONV_ENCAP 1
397 #define WLAN_ETHCONV_RFC1042 2
398 #define WLAN_ETHCONV_8021h 3
400 #define cap_ESS BIT(0)
401 #define cap_IBSS BIT(1)
402 #define cap_CFPollable BIT(2)
403 #define cap_CFRequest BIT(3)
404 #define cap_Privacy BIT(4)
405 #define cap_ShortPremble BIT(5)
407 /*-----------------------------------------------------------------------------
408 * Below is the definition for 802.11i / 802.1x
409 *------------------------------------------------------------------------------
411 #define _IEEE8021X_MGT_ 1 /*WPA */
412 #define _IEEE8021X_PSK_ 2 /* WPA with pre-shared key */
414 /*-----------------------------------------------------------------------------
415 * Below is the definition for WMM
416 *------------------------------------------------------------------------------
418 #define _WMM_IE_Length_ 7 /* for WMM STA */
419 #define _WMM_Para_Element_Length_ 24
421 /*-----------------------------------------------------------------------------
422 * Below is the definition for 802.11n
423 *------------------------------------------------------------------------------
426 #define SetOrderBit(pbuf) ({ \
427 *(__le16 *)(pbuf) |= cpu_to_le16(_ORDER_); \
430 #define GetOrderBit(pbuf) (((*(__le16 *)(pbuf)) & \
431 le16_to_cpu(_ORDER_)) != 0)
434 * struct rtl_ieee80211_ht_cap - HT capabilities
436 * This structure refers to "HT capabilities element" as
437 * described in 802.11n draft section 7.3.2.52
440 struct rtl_ieee80211_ht_cap {
442 unsigned char ampdu_params_info;
443 unsigned char supp_mcs_set[16];
444 __le16 extended_ht_cap_info;
445 __le32 tx_BF_cap_info;
446 unsigned char antenna_selection_info;
450 * struct ieee80211_ht_addt_info - HT additional information
452 * This structure refers to "HT information element" as
453 * described in 802.11n draft section 7.3.2.53
455 struct ieee80211_ht_addt_info {
456 unsigned char control_chan;
457 unsigned char ht_param;
458 __le16 operation_mode;
460 unsigned char basic_set[16];
463 #endif /* _WIFI_H_ */