1 /******************************************************************************
3 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 * Modifications for inclusion into the Linux staging tree are
19 * Copyright(c) 2010 Larry Finger. All rights reserved.
21 * Contact information:
22 * WLAN FAE <wlanfae@realtek.com>
23 * Larry Finger <Larry.Finger@lwfinger.net>
25 ******************************************************************************/
29 #include <linux/compiler.h>
31 #define WLAN_IEEE_OUI_LEN 3
32 #define WLAN_CRC_LEN 4
33 #define WLAN_BSSID_LEN 6
34 #define WLAN_BSS_TS_LEN 8
35 #define WLAN_HDR_A3_LEN 24
36 #define WLAN_HDR_A4_LEN 30
37 #define WLAN_HDR_A3_QOS_LEN 26
38 #define WLAN_HDR_A4_QOS_LEN 32
39 #define WLAN_SSID_MAXLEN 32
40 #define WLAN_DATA_MAXLEN 2312
42 #define WLAN_A3_PN_OFFSET 24
43 #define WLAN_A4_PN_OFFSET 30
45 #define WLAN_MIN_ETHFRM_LEN 60
46 #define WLAN_MAX_ETHFRM_LEN 1514
48 #define P80211CAPTURE_VERSION 0x80211001
50 enum WIFI_FRAME_TYPE {
52 WIFI_CTRL_TYPE = (BIT(2)),
53 WIFI_DATA_TYPE = (BIT(3)),
54 WIFI_QOS_DATA_TYPE = (BIT(7)|BIT(3)), /*!< QoS Data */
57 enum WIFI_FRAME_SUBTYPE {
58 /* below is for mgt frame */
59 WIFI_ASSOCREQ = (0 | WIFI_MGT_TYPE),
60 WIFI_ASSOCRSP = (BIT(4) | WIFI_MGT_TYPE),
61 WIFI_REASSOCREQ = (BIT(5) | WIFI_MGT_TYPE),
62 WIFI_REASSOCRSP = (BIT(5) | BIT(4) | WIFI_MGT_TYPE),
63 WIFI_PROBEREQ = (BIT(6) | WIFI_MGT_TYPE),
64 WIFI_PROBERSP = (BIT(6) | BIT(4) | WIFI_MGT_TYPE),
65 WIFI_BEACON = (BIT(7) | WIFI_MGT_TYPE),
66 WIFI_ATIM = (BIT(7) | BIT(4) | WIFI_MGT_TYPE),
67 WIFI_DISASSOC = (BIT(7) | BIT(5) | WIFI_MGT_TYPE),
68 WIFI_AUTH = (BIT(7) | BIT(5) | BIT(4) | WIFI_MGT_TYPE),
69 WIFI_DEAUTH = (BIT(7) | BIT(6) | WIFI_MGT_TYPE),
70 WIFI_ACTION = (BIT(7) | BIT(6) | BIT(4) | WIFI_MGT_TYPE),
71 /* below is for control frame */
72 WIFI_PSPOLL = (BIT(7) | BIT(5) | WIFI_CTRL_TYPE),
73 WIFI_RTS = (BIT(7) | BIT(5) | BIT(4) | WIFI_CTRL_TYPE),
74 WIFI_CTS = (BIT(7) | BIT(6) | WIFI_CTRL_TYPE),
75 WIFI_ACK = (BIT(7) | BIT(6) | BIT(4) | WIFI_CTRL_TYPE),
76 WIFI_CFEND = (BIT(7) | BIT(6) | BIT(5) | WIFI_CTRL_TYPE),
77 WIFI_CFEND_CFACK = (BIT(7) | BIT(6) | BIT(5) | BIT(4) | WIFI_CTRL_TYPE),
78 /* below is for data frame */
79 WIFI_DATA = (0 | WIFI_DATA_TYPE),
80 WIFI_DATA_CFACK = (BIT(4) | WIFI_DATA_TYPE),
81 WIFI_DATA_CFPOLL = (BIT(5) | WIFI_DATA_TYPE),
82 WIFI_DATA_CFACKPOLL = (BIT(5) | BIT(4) | WIFI_DATA_TYPE),
83 WIFI_DATA_NULL = (BIT(6) | WIFI_DATA_TYPE),
84 WIFI_CF_ACK = (BIT(6) | BIT(4) | WIFI_DATA_TYPE),
85 WIFI_CF_POLL = (BIT(6) | BIT(5) | WIFI_DATA_TYPE),
86 WIFI_CF_ACKPOLL = (BIT(6) | BIT(5) | BIT(4) | WIFI_DATA_TYPE),
89 enum WIFI_REASON_CODE {
91 _RSON_UNSPECIFIED_ = 1,
92 _RSON_AUTH_NO_LONGER_VALID_ = 2,
93 _RSON_DEAUTH_STA_LEAVING_ = 3,
94 _RSON_INACTIVITY_ = 4,
95 _RSON_UNABLE_HANDLE_ = 5,
98 _RSON_DISAOC_STA_LEAVING_ = 8,
99 _RSON_ASOC_NOT_AUTH_ = 9,
101 _RSON_INVALID_IE_ = 13,
102 _RSON_MIC_FAILURE_ = 14,
103 _RSON_4WAY_HNDSHK_TIMEOUT_ = 15,
104 _RSON_GROUP_KEY_UPDATE_TIMEOUT_ = 16,
106 _RSON_MLTCST_CIPHER_NOT_VALID_ = 18,
107 _RSON_UNICST_CIPHER_NOT_VALID_ = 19,
108 _RSON_AKMP_NOT_VALID_ = 20,
109 _RSON_UNSUPPORT_RSNE_VER_ = 21,
110 _RSON_INVALID_RSNE_CAP_ = 22,
111 _RSON_IEEE_802DOT1X_AUTH_FAIL_ = 23,
112 /* below are Realtek definitions */
113 _RSON_PMK_NOT_AVAILABLE_ = 24,
116 enum WIFI_STATUS_CODE {
117 _STATS_SUCCESSFUL_ = 0,
119 _STATS_CAP_FAIL_ = 10,
120 _STATS_NO_ASOC_ = 11,
122 _STATS_NO_SUPP_ALG_ = 13,
123 _STATS_OUT_OF_AUTH_SEQ_ = 14,
124 _STATS_CHALLENGE_FAIL_ = 15,
125 _STATS_AUTH_TIMEOUT_ = 16,
126 _STATS_UNABLE_HANDLE_STA_ = 17,
127 _STATS_RATE_FAIL_ = 18,
130 enum WIFI_REG_DOMAIN {
144 #define _TO_DS_ BIT(8)
145 #define _FROM_DS_ BIT(9)
146 #define _MORE_FRAG_ BIT(10)
147 #define _RETRY_ BIT(11)
148 #define _PWRMGT_ BIT(12)
149 #define _MORE_DATA_ BIT(13)
150 #define _PRIVACY_ BIT(14)
151 #define _ORDER_ BIT(15)
153 #define SetToDs(pbuf) ({ \
154 *(__le16 *)(pbuf) |= cpu_to_le16(_TO_DS_); \
157 #define GetToDs(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_TO_DS_)) != 0)
159 #define ClearToDs(pbuf) ({ \
160 *(__le16 *)(pbuf) &= (~cpu_to_le16(_TO_DS_)); \
163 #define SetFrDs(pbuf) ({ \
164 *(__le16 *)(pbuf) |= cpu_to_le16(_FROM_DS_); \
167 #define GetFrDs(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_FROM_DS_)) != 0)
169 #define ClearFrDs(pbuf) ({ \
170 *(__le16 *)(pbuf) &= (~cpu_to_le16(_FROM_DS_)); \
173 #define get_tofr_ds(pframe) ((GetToDs(pframe) << 1) | GetFrDs(pframe))
176 #define SetMFrag(pbuf) ({ \
177 *(__le16 *)(pbuf) |= cpu_to_le16(_MORE_FRAG_); \
180 #define GetMFrag(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_MORE_FRAG_)) != 0)
182 #define ClearMFrag(pbuf) ({ \
183 *(__le16 *)(pbuf) &= (~cpu_to_le16(_MORE_FRAG_)); \
186 #define SetRetry(pbuf) ({ \
187 *(__le16 *)(pbuf) |= cpu_to_le16(_RETRY_); \
190 #define GetRetry(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_RETRY_)) != 0)
192 #define ClearRetry(pbuf) ({ \
193 *(__le16 *)(pbuf) &= (~cpu_to_le16(_RETRY_)); \
196 #define SetPwrMgt(pbuf) ({ \
197 *(__le16 *)(pbuf) |= cpu_to_le16(_PWRMGT_); \
200 #define GetPwrMgt(pbuf) (((*(__le16 *)(pbuf)) & \
201 cpu_to_le16(_PWRMGT_)) != 0)
203 #define ClearPwrMgt(pbuf) ({ \
204 *(__le16 *)(pbuf) &= (~cpu_to_le16(_PWRMGT_)); \
207 #define SetMData(pbuf) ({ \
208 *(__le16 *)(pbuf) |= cpu_to_le16(_MORE_DATA_); \
211 #define GetMData(pbuf) (((*(__le16 *)(pbuf)) & \
212 cpu_to_le16(_MORE_DATA_)) != 0)
214 #define ClearMData(pbuf) ({ \
215 *(__le16 *)(pbuf) &= (~cpu_to_le16(_MORE_DATA_)); \
218 #define SetPrivacy(pbuf) ({ \
219 *(__le16 *)(pbuf) |= cpu_to_le16(_PRIVACY_); \
222 #define GetPrivacy(pbuf) (((*(__le16 *)(pbuf)) & \
223 cpu_to_le16(_PRIVACY_)) != 0)
225 #define GetOrder(pbuf) (((*(__le16 *)(pbuf)) & \
226 cpu_to_le16(_ORDER_)) != 0)
228 #define GetFrameType(pbuf) (le16_to_cpu(*(__le16 *)(pbuf)) & \
231 #define SetFrameType(pbuf, type) \
233 *(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(3) | \
235 *(__le16 *)(pbuf) |= cpu_to_le16(type); \
238 #define GetFrameSubType(pbuf) (le16_to_cpu(*(__le16 *)(pbuf)) & \
239 (BIT(7) | BIT(6) | BIT(5) | BIT(4) | BIT(3) | \
242 #define SetFrameSubType(pbuf, type) \
244 *(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(7) | BIT(6) | \
245 BIT(5) | BIT(4) | BIT(3) | BIT(2))); \
246 *(__le16 *)(pbuf) |= cpu_to_le16(type); \
249 #define GetSequence(pbuf) (le16_to_cpu(*(__le16 *)\
250 ((addr_t)(pbuf) + 22)) >> 4)
252 #define GetFragNum(pbuf) (le16_to_cpu(*(__le16 *)((addr_t)\
253 (pbuf) + 22)) & 0x0f)
255 #define SetSeqNum(pbuf, num) ({ \
256 *(__le16 *)((addr_t)(pbuf) + 22) = \
257 cpu_to_le16((le16_to_cpu(*(__le16 *)((addr_t)(pbuf) + 22)) & \
258 0x000f) | (0xfff0 & (num << 4))); \
261 #define SetDuration(pbuf, dur) ({ \
262 *(__le16 *)((addr_t)(pbuf) + 2) |= \
263 cpu_to_le16(0xffff & (dur)); \
266 #define SetPriority(pbuf, tid) ({ \
267 *(__le16 *)(pbuf) |= cpu_to_le16(tid & 0xf); \
270 #define GetPriority(pbuf) ((le16_to_cpu(*(__le16 *)(pbuf))) & 0xf)
272 #define SetAckpolicy(pbuf, ack) ({ \
273 *(__le16 *)(pbuf) |= cpu_to_le16((ack & 3) << 5); \
276 #define GetAckpolicy(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 5) & 0x3)
278 #define GetAMsdu(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 7) & 0x1)
280 #define GetAid(pbuf) (cpu_to_le16(*(__le16 *)((addr_t)(pbuf) + 2)) \
283 #define GetAddr1Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 4))
285 #define GetAddr2Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 10))
287 #define GetAddr3Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 16))
289 #define GetAddr4Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 24))
293 static inline int IS_MCAST(unsigned char *da)
302 static inline unsigned char *get_da(unsigned char *pframe)
305 unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
308 case 0x00: /* ToDs=0, FromDs=0 */
309 da = GetAddr1Ptr(pframe);
311 case 0x01: /* ToDs=0, FromDs=1 */
312 da = GetAddr1Ptr(pframe);
314 case 0x02: /* ToDs=1, FromDs=0 */
315 da = GetAddr3Ptr(pframe);
317 default: /* ToDs=1, FromDs=1 */
318 da = GetAddr3Ptr(pframe);
325 static inline unsigned char *get_sa(unsigned char *pframe)
328 unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
331 case 0x00: /* ToDs=0, FromDs=0 */
332 sa = GetAddr2Ptr(pframe);
334 case 0x01: /* ToDs=0, FromDs=1 */
335 sa = GetAddr3Ptr(pframe);
337 case 0x02: /* ToDs=1, FromDs=0 */
338 sa = GetAddr2Ptr(pframe);
340 default: /* ToDs=1, FromDs=1 */
341 sa = GetAddr4Ptr(pframe);
348 static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
351 unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
354 case 0x00: /* ToDs=0, FromDs=0 */
355 sa = GetAddr3Ptr(pframe);
357 case 0x01: /* ToDs=0, FromDs=1 */
358 sa = GetAddr2Ptr(pframe);
360 case 0x02: /* ToDs=1, FromDs=0 */
361 sa = GetAddr1Ptr(pframe);
363 default: /* ToDs=1, FromDs=1 */
372 /*-----------------------------------------------------------------------------
373 Below is for the security related definition
374 *-----------------------------------------------------------------------------
376 #define _RESERVED_FRAME_TYPE_ 0
377 #define _SKB_FRAME_TYPE_ 2
378 #define _PRE_ALLOCMEM_ 1
379 #define _PRE_ALLOCHDR_ 3
380 #define _PRE_ALLOCLLCHDR_ 4
381 #define _PRE_ALLOCICVHDR_ 5
382 #define _PRE_ALLOCMICHDR_ 6
384 #define _SIFSTIME_ ((priv->pmib->BssType.net_work_type & \
385 WIRELESS_11A) ? 16 : 10)
386 #define _ACKCTSLNG_ 14 /*14 bytes long, including crclng */
389 #define _ASOCREQ_IE_OFFSET_ 4 /* excluding wlan_hdr */
390 #define _ASOCRSP_IE_OFFSET_ 6
391 #define _REASOCREQ_IE_OFFSET_ 10
392 #define _REASOCRSP_IE_OFFSET_ 6
393 #define _PROBEREQ_IE_OFFSET_ 0
394 #define _PROBERSP_IE_OFFSET_ 12
395 #define _AUTH_IE_OFFSET_ 6
396 #define _DEAUTH_IE_OFFSET_ 0
397 #define _BEACON_IE_OFFSET_ 12
399 #define _FIXED_IE_LENGTH_ _BEACON_IE_OFFSET_
402 #define _SUPPORTEDRATES_IE_ 1
404 #define _IBSS_PARA_IE_ 6
405 #define _ERPINFO_IE_ 42
406 #define _EXT_SUPPORTEDRATES_IE_ 50
408 #define _HT_CAPABILITY_IE_ 45
409 #define _HT_EXTRA_INFO_IE_ 61
410 #define _HT_ADD_INFO_IE_ 61 /* _HT_EXTRA_INFO_IE_ */
412 #define _VENDOR_SPECIFIC_IE_ 221
414 #define _RESERVED47_ 47
417 /* ---------------------------------------------------------------------------
418 Below is the fixed elements...
419 * ---------------------------------------------------------------------------
421 #define _AUTH_ALGM_NUM_ 2
422 #define _AUTH_SEQ_NUM_ 2
423 #define _BEACON_ITERVAL_ 2
424 #define _CAPABILITY_ 2
425 #define _CURRENT_APADDR_ 6
426 #define _LISTEN_INTERVAL_ 2
427 #define _RSON_CODE_ 2
429 #define _STATUS_CODE_ 2
430 #define _TIMESTAMP_ 8
432 #define AUTH_ODD_TO 0
433 #define AUTH_EVEN_TO 1
435 #define WLAN_ETHCONV_ENCAP 1
436 #define WLAN_ETHCONV_RFC1042 2
437 #define WLAN_ETHCONV_8021h 3
439 #define cap_ESS BIT(0)
440 #define cap_IBSS BIT(1)
441 #define cap_CFPollable BIT(2)
442 #define cap_CFRequest BIT(3)
443 #define cap_Privacy BIT(4)
444 #define cap_ShortPremble BIT(5)
446 /*-----------------------------------------------------------------------------
447 Below is the definition for 802.11i / 802.1x
448 *------------------------------------------------------------------------------
450 #define _IEEE8021X_MGT_ 1 /*WPA */
451 #define _IEEE8021X_PSK_ 2 /* WPA with pre-shared key */
453 /*-----------------------------------------------------------------------------
454 Below is the definition for WMM
455 *------------------------------------------------------------------------------
457 #define _WMM_IE_Length_ 7 /* for WMM STA */
458 #define _WMM_Para_Element_Length_ 24
461 /*-----------------------------------------------------------------------------
462 Below is the definition for 802.11n
463 *------------------------------------------------------------------------------
466 /* block-ack parameters */
467 #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
468 #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
469 #define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
470 #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
471 #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
473 #define SetOrderBit(pbuf) ({ \
474 *(__le16 *)(pbuf) |= cpu_to_le16(_ORDER_); \
477 #define GetOrderBit(pbuf) (((*(__le16 *)(pbuf)) & \
478 le16_to_cpu(_ORDER_)) != 0)
482 * struct ieee80211_bar - HT Block Ack Request
484 * This structure refers to "HT BlockAckReq" as
485 * described in 802.11n draft section 7.2.1.7.1
487 struct ieee80211_bar {
488 __le16 frame_control;
493 __le16 start_seq_num;
496 /* 802.11 BAR control masks */
497 #define IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL 0x0000
498 #define IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA 0x0004
502 * struct ieee80211_ht_cap - HT capabilities
504 * This structure refers to "HT capabilities element" as
505 * described in 802.11n draft section 7.3.2.52
508 struct ieee80211_ht_cap {
510 unsigned char ampdu_params_info;
511 unsigned char supp_mcs_set[16];
512 __le16 extended_ht_cap_info;
513 __le32 tx_BF_cap_info;
514 unsigned char antenna_selection_info;
518 * struct ieee80211_ht_cap - HT additional information
520 * This structure refers to "HT information element" as
521 * described in 802.11n draft section 7.3.2.53
523 struct ieee80211_ht_addt_info {
524 unsigned char control_chan;
525 unsigned char ht_param;
526 __le16 operation_mode;
528 unsigned char basic_set[16];
531 /* 802.11n HT capabilities masks */
532 #define IEEE80211_HT_CAP_SUP_WIDTH 0x0002
533 #define IEEE80211_HT_CAP_SM_PS 0x000C
534 #define IEEE80211_HT_CAP_GRN_FLD 0x0010
535 #define IEEE80211_HT_CAP_SGI_20 0x0020
536 #define IEEE80211_HT_CAP_SGI_40 0x0040
537 #define IEEE80211_HT_CAP_TX_STBC 0x0080
538 #define IEEE80211_HT_CAP_DELAY_BA 0x0400
539 #define IEEE80211_HT_CAP_MAX_AMSDU 0x0800
540 #define IEEE80211_HT_CAP_DSSSCCK40 0x1000
541 /* 802.11n HT capability AMPDU settings */
542 #define IEEE80211_HT_CAP_AMPDU_FACTOR 0x03
543 #define IEEE80211_HT_CAP_AMPDU_DENSITY 0x1C
544 /* 802.11n HT capability MSC set */
545 #define IEEE80211_SUPP_MCS_SET_UEQM 4
546 #define IEEE80211_HT_CAP_MAX_STREAMS 4
547 #define IEEE80211_SUPP_MCS_SET_LEN 10
548 /* maximum streams the spec allows */
549 #define IEEE80211_HT_CAP_MCS_TX_DEFINED 0x01
550 #define IEEE80211_HT_CAP_MCS_TX_RX_DIFF 0x02
551 #define IEEE80211_HT_CAP_MCS_TX_STREAMS 0x0C
552 #define IEEE80211_HT_CAP_MCS_TX_UEQM 0x10
553 /* 802.11n HT IE masks */
554 #define IEEE80211_HT_IE_CHA_SEC_OFFSET 0x03
555 #define IEEE80211_HT_IE_CHA_SEC_NONE 0x00
556 #define IEEE80211_HT_IE_CHA_SEC_ABOVE 0x01
557 #define IEEE80211_HT_IE_CHA_SEC_BELOW 0x03
558 #define IEEE80211_HT_IE_CHA_WIDTH 0x04
559 #define IEEE80211_HT_IE_HT_PROTECTION 0x0003
560 #define IEEE80211_HT_IE_NON_GF_STA_PRSNT 0x0004
561 #define IEEE80211_HT_IE_NON_HT_STA_PRSNT 0x0010
563 /* block-ack parameters */
564 #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
565 #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
566 #define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0
567 #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
568 #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
571 * A-PMDU buffer sizes
572 * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2)
574 #define IEEE80211_MIN_AMPDU_BUF 0x8
575 #define IEEE80211_MAX_AMPDU_BUF 0x40
578 /* Spatial Multiplexing Power Save Modes */
579 #define WLAN_HT_CAP_SM_PS_STATIC 0
580 #define WLAN_HT_CAP_SM_PS_DYNAMIC 1
581 #define WLAN_HT_CAP_SM_PS_INVALID 2
582 #define WLAN_HT_CAP_SM_PS_DISABLED 3
584 #endif /* _WIFI_H_ */