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>
18 #include <linux/ieee80211.h>
20 #define WLAN_HDR_A3_LEN 24
21 #define WLAN_HDR_A3_QOS_LEN 26
23 #define P80211CAPTURE_VERSION 0x80211001
25 enum WIFI_FRAME_TYPE {
27 WIFI_CTRL_TYPE = (BIT(2)),
28 WIFI_DATA_TYPE = (BIT(3)),
29 WIFI_QOS_DATA_TYPE = (BIT(7) | BIT(3)), /*!< QoS Data */
32 enum WIFI_REG_DOMAIN {
46 #define SetToDs(pbuf) ({ \
47 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_TODS); \
50 #define GetToDs(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_TODS)) != 0)
52 #define ClearToDs(pbuf) ({ \
53 *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_TODS)); \
56 #define SetFrDs(pbuf) ({ \
57 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_FROMDS); \
60 #define GetFrDs(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_FROMDS)) != 0)
62 #define ClearFrDs(pbuf) ({ \
63 *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_FROMDS)); \
66 static inline unsigned char get_tofr_ds(unsigned char *pframe)
68 return ((GetToDs(pframe) << 1) | GetFrDs(pframe));
71 #define SetMFrag(pbuf) ({ \
72 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_MOREFRAGS); \
75 #define GetMFrag(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) != 0)
77 #define ClearMFrag(pbuf) ({ \
78 *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)); \
81 #define SetRetry(pbuf) ({ \
82 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_RETRY); \
85 #define GetRetry(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_RETRY)) != 0)
87 #define ClearRetry(pbuf) ({ \
88 *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_RETRY)); \
91 #define SetPwrMgt(pbuf) ({ \
92 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_PM); \
95 #define GetPwrMgt(pbuf) (((*(__le16 *)(pbuf)) & \
96 cpu_to_le16(IEEE80211_FCTL_PM)) != 0)
98 #define ClearPwrMgt(pbuf) ({ \
99 *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_PM)); \
102 #define SetMData(pbuf) ({ \
103 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_MOREDATA); \
106 #define GetMData(pbuf) (((*(__le16 *)(pbuf)) & \
107 cpu_to_le16(IEEE80211_FCTL_MOREDATA)) != 0)
109 #define ClearMData(pbuf) ({ \
110 *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_MOREDATA)); \
113 #define SetPrivacy(pbuf) ({ \
114 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); \
117 #define GetPrivacy(pbuf) (((*(__le16 *)(pbuf)) & \
118 cpu_to_le16(IEEE80211_FCTL_PROTECTED)) != 0)
120 #define GetOrder(pbuf) (((*(__le16 *)(pbuf)) & \
121 cpu_to_le16(IEEE80211_FCTL_ORDER)) != 0)
123 #define GetFrameType(pbuf) (le16_to_cpu(*(__le16 *)(pbuf)) & \
126 #define SetFrameType(pbuf, type) \
128 *(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(3) | \
130 *(__le16 *)(pbuf) |= cpu_to_le16(type); \
133 #define GetFrameSubType(pbuf) (le16_to_cpu(*(__le16 *)(pbuf)) & \
134 (BIT(7) | BIT(6) | BIT(5) | BIT(4) | BIT(3) | \
137 #define SetFrameSubType(pbuf, type) \
139 *(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(7) | BIT(6) | \
140 BIT(5) | BIT(4) | BIT(3) | BIT(2))); \
141 *(__le16 *)(pbuf) |= cpu_to_le16(type); \
144 #define GetSequence(pbuf) (le16_to_cpu(*(__le16 *)\
145 ((addr_t)(pbuf) + 22)) >> 4)
147 #define GetFragNum(pbuf) (le16_to_cpu(*(__le16 *)((addr_t)\
148 (pbuf) + 22)) & 0x0f)
150 #define SetSeqNum(pbuf, num) ({ \
151 *(__le16 *)((addr_t)(pbuf) + 22) = \
152 cpu_to_le16((le16_to_cpu(*(__le16 *)((addr_t)(pbuf) + 22)) & \
153 0x000f) | (0xfff0 & (num << 4))); \
156 #define SetPriority(pbuf, tid) ({ \
157 *(__le16 *)(pbuf) |= cpu_to_le16(tid & 0xf); \
160 #define GetPriority(pbuf) ((le16_to_cpu(*(__le16 *)(pbuf))) & 0xf)
162 #define SetAckpolicy(pbuf, ack) ({ \
163 *(__le16 *)(pbuf) |= cpu_to_le16((ack & 3) << 5); \
166 #define GetAckpolicy(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 5) & 0x3)
168 #define GetAMsdu(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 7) & 0x1)
170 #define GetAddr1Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 4))
172 #define GetAddr2Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 10))
174 #define GetAddr3Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 16))
176 #define GetAddr4Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 24))
178 static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
181 unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
184 case 0x00: /* ToDs=0, FromDs=0 */
185 sa = GetAddr3Ptr(pframe);
187 case 0x01: /* ToDs=0, FromDs=1 */
188 sa = GetAddr2Ptr(pframe);
190 case 0x02: /* ToDs=1, FromDs=0 */
191 sa = GetAddr1Ptr(pframe);
193 default: /* ToDs=1, FromDs=1 */
200 /*-----------------------------------------------------------------------------
201 * Below is for the security related definition
202 *-----------------------------------------------------------------------------
204 #define _ASOCREQ_IE_OFFSET_ 4 /* excluding wlan_hdr */
205 #define _ASOCRSP_IE_OFFSET_ 6
206 #define _REASOCREQ_IE_OFFSET_ 10
207 #define _REASOCRSP_IE_OFFSET_ 6
208 #define _PROBEREQ_IE_OFFSET_ 0
209 #define _PROBERSP_IE_OFFSET_ 12
210 #define _AUTH_IE_OFFSET_ 6
211 #define _DEAUTH_IE_OFFSET_ 0
212 #define _BEACON_IE_OFFSET_ 12
214 #define _FIXED_IE_LENGTH_ _BEACON_IE_OFFSET_
216 /* ---------------------------------------------------------------------------
217 * Below is the fixed elements...
218 * ---------------------------------------------------------------------------
220 #define _AUTH_ALGM_NUM_ 2
221 #define _AUTH_SEQ_NUM_ 2
222 #define _BEACON_ITERVAL_ 2
223 #define _CAPABILITY_ 2
224 #define _CURRENT_APADDR_ 6
225 #define _LISTEN_INTERVAL_ 2
226 #define _RSON_CODE_ 2
228 #define _STATUS_CODE_ 2
229 #define _TIMESTAMP_ 8
231 #define AUTH_ODD_TO 0
232 #define AUTH_EVEN_TO 1
234 /*-----------------------------------------------------------------------------
235 * Below is the definition for 802.11i / 802.1x
236 *------------------------------------------------------------------------------
238 #define _IEEE8021X_MGT_ 1 /*WPA */
239 #define _IEEE8021X_PSK_ 2 /* WPA with pre-shared key */
241 /*-----------------------------------------------------------------------------
242 * Below is the definition for WMM
243 *------------------------------------------------------------------------------
245 #define _WMM_IE_Length_ 7 /* for WMM STA */
247 #endif /* _WIFI_H_ */