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 {
26 WIFI_QOS_DATA_TYPE = (BIT(7) | BIT(3)), /*!< QoS Data */
29 enum WIFI_REG_DOMAIN {
43 #define SetToDs(pbuf) ({ \
44 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_TODS); \
47 #define GetToDs(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_TODS)) != 0)
49 #define ClearToDs(pbuf) ({ \
50 *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_TODS)); \
53 #define SetFrDs(pbuf) ({ \
54 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_FROMDS); \
57 #define GetFrDs(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_FROMDS)) != 0)
59 #define ClearFrDs(pbuf) ({ \
60 *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_FROMDS)); \
63 static inline unsigned char get_tofr_ds(unsigned char *pframe)
65 return ((GetToDs(pframe) << 1) | GetFrDs(pframe));
68 #define SetMFrag(pbuf) ({ \
69 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_MOREFRAGS); \
72 #define GetMFrag(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) != 0)
74 #define ClearMFrag(pbuf) ({ \
75 *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)); \
78 #define SetRetry(pbuf) ({ \
79 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_RETRY); \
82 #define GetRetry(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_RETRY)) != 0)
84 #define ClearRetry(pbuf) ({ \
85 *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_RETRY)); \
88 #define SetPwrMgt(pbuf) ({ \
89 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_PM); \
92 #define GetPwrMgt(pbuf) (((*(__le16 *)(pbuf)) & \
93 cpu_to_le16(IEEE80211_FCTL_PM)) != 0)
95 #define ClearPwrMgt(pbuf) ({ \
96 *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_PM)); \
99 #define SetMData(pbuf) ({ \
100 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_MOREDATA); \
103 #define GetMData(pbuf) (((*(__le16 *)(pbuf)) & \
104 cpu_to_le16(IEEE80211_FCTL_MOREDATA)) != 0)
106 #define ClearMData(pbuf) ({ \
107 *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_MOREDATA)); \
110 #define SetPrivacy(pbuf) ({ \
111 *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); \
114 #define GetPrivacy(pbuf) (((*(__le16 *)(pbuf)) & \
115 cpu_to_le16(IEEE80211_FCTL_PROTECTED)) != 0)
117 #define GetOrder(pbuf) (((*(__le16 *)(pbuf)) & \
118 cpu_to_le16(IEEE80211_FCTL_ORDER)) != 0)
120 #define GetFrameType(pbuf) (le16_to_cpu(*(__le16 *)(pbuf)) & \
123 #define SetFrameType(pbuf, type) \
125 *(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(3) | \
127 *(__le16 *)(pbuf) |= cpu_to_le16(type); \
130 #define GetFrameSubType(pbuf) (le16_to_cpu(*(__le16 *)(pbuf)) & \
131 (BIT(7) | BIT(6) | BIT(5) | BIT(4) | BIT(3) | \
134 #define SetFrameSubType(pbuf, type) \
136 *(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(7) | BIT(6) | \
137 BIT(5) | BIT(4) | BIT(3) | BIT(2))); \
138 *(__le16 *)(pbuf) |= cpu_to_le16(type); \
141 #define GetSequence(pbuf) (le16_to_cpu(*(__le16 *)\
142 ((addr_t)(pbuf) + 22)) >> 4)
144 #define GetFragNum(pbuf) (le16_to_cpu(*(__le16 *)((addr_t)\
145 (pbuf) + 22)) & 0x0f)
147 #define SetSeqNum(pbuf, num) ({ \
148 *(__le16 *)((addr_t)(pbuf) + 22) = \
149 cpu_to_le16((le16_to_cpu(*(__le16 *)((addr_t)(pbuf) + 22)) & \
150 0x000f) | (0xfff0 & (num << 4))); \
153 #define SetPriority(pbuf, tid) ({ \
154 *(__le16 *)(pbuf) |= cpu_to_le16(tid & 0xf); \
157 #define GetPriority(pbuf) ((le16_to_cpu(*(__le16 *)(pbuf))) & 0xf)
159 #define SetAckpolicy(pbuf, ack) ({ \
160 *(__le16 *)(pbuf) |= cpu_to_le16((ack & 3) << 5); \
163 #define GetAckpolicy(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 5) & 0x3)
165 #define GetAMsdu(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 7) & 0x1)
167 #define GetAddr1Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 4))
169 #define GetAddr2Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 10))
171 #define GetAddr3Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 16))
173 #define GetAddr4Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 24))
175 static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
178 unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
181 case 0x00: /* ToDs=0, FromDs=0 */
182 sa = GetAddr3Ptr(pframe);
184 case 0x01: /* ToDs=0, FromDs=1 */
185 sa = GetAddr2Ptr(pframe);
187 case 0x02: /* ToDs=1, FromDs=0 */
188 sa = GetAddr1Ptr(pframe);
190 default: /* ToDs=1, FromDs=1 */
197 /*-----------------------------------------------------------------------------
198 * Below is for the security related definition
199 *-----------------------------------------------------------------------------
201 #define _ASOCREQ_IE_OFFSET_ 4 /* excluding wlan_hdr */
202 #define _ASOCRSP_IE_OFFSET_ 6
203 #define _REASOCREQ_IE_OFFSET_ 10
204 #define _REASOCRSP_IE_OFFSET_ 6
205 #define _PROBEREQ_IE_OFFSET_ 0
206 #define _PROBERSP_IE_OFFSET_ 12
207 #define _AUTH_IE_OFFSET_ 6
208 #define _DEAUTH_IE_OFFSET_ 0
209 #define _BEACON_IE_OFFSET_ 12
211 #define _FIXED_IE_LENGTH_ _BEACON_IE_OFFSET_
213 /* ---------------------------------------------------------------------------
214 * Below is the fixed elements...
215 * ---------------------------------------------------------------------------
217 #define _AUTH_ALGM_NUM_ 2
218 #define _AUTH_SEQ_NUM_ 2
219 #define _BEACON_ITERVAL_ 2
220 #define _CAPABILITY_ 2
221 #define _CURRENT_APADDR_ 6
222 #define _LISTEN_INTERVAL_ 2
223 #define _RSON_CODE_ 2
225 #define _STATUS_CODE_ 2
226 #define _TIMESTAMP_ 8
228 #define AUTH_ODD_TO 0
229 #define AUTH_EVEN_TO 1
231 /*-----------------------------------------------------------------------------
232 * Below is the definition for 802.11i / 802.1x
233 *------------------------------------------------------------------------------
235 #define _IEEE8021X_MGT_ 1 /*WPA */
236 #define _IEEE8021X_PSK_ 2 /* WPA with pre-shared key */
238 /*-----------------------------------------------------------------------------
239 * Below is the definition for WMM
240 *------------------------------------------------------------------------------
242 #define _WMM_IE_Length_ 7 /* for WMM STA */
244 #endif /* _WIFI_H_ */