Merge branch 'stable/for-linus-5.15' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-microblaze.git] / drivers / staging / rtl8712 / wifi.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
3  *
4  * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5  *
6  * Modifications for inclusion into the Linux staging tree are
7  * Copyright(c) 2010 Larry Finger. All rights reserved.
8  *
9  * Contact information:
10  * WLAN FAE <wlanfae@realtek.com>
11  * Larry Finger <Larry.Finger@lwfinger.net>
12  *
13  ******************************************************************************/
14 #ifndef _WIFI_H_
15 #define _WIFI_H_
16
17 #include <linux/compiler.h>
18 #include <linux/ieee80211.h>
19
20 #define WLAN_HDR_A3_LEN         24
21 #define WLAN_HDR_A3_QOS_LEN     26
22
23 #define P80211CAPTURE_VERSION   0x80211001
24
25 enum WIFI_FRAME_TYPE {
26         WIFI_QOS_DATA_TYPE      = (BIT(7) | BIT(3)),    /*!< QoS Data */
27 };
28
29 enum WIFI_REG_DOMAIN {
30         DOMAIN_FCC      = 1,
31         DOMAIN_IC       = 2,
32         DOMAIN_ETSI     = 3,
33         DOMAIN_SPAIN    = 4,
34         DOMAIN_FRANCE   = 5,
35         DOMAIN_MKK      = 6,
36         DOMAIN_ISRAEL   = 7,
37         DOMAIN_MKK1     = 8,
38         DOMAIN_MKK2     = 9,
39         DOMAIN_MKK3     = 10,
40         DOMAIN_MAX
41 };
42
43 #define SetToDs(pbuf) ({ \
44         *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_TODS); \
45 })
46
47 #define GetToDs(pbuf)   (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_TODS)) != 0)
48
49 #define ClearToDs(pbuf) ({ \
50         *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_TODS)); \
51 })
52
53 #define SetFrDs(pbuf) ({ \
54         *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_FROMDS); \
55 })
56
57 #define GetFrDs(pbuf)   (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_FROMDS)) != 0)
58
59 #define ClearFrDs(pbuf) ({ \
60         *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_FROMDS)); \
61 })
62
63 static inline unsigned char get_tofr_ds(unsigned char *pframe)
64 {
65         return ((GetToDs(pframe) << 1) | GetFrDs(pframe));
66 }
67
68 #define SetMFrag(pbuf) ({ \
69         *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_MOREFRAGS); \
70 })
71
72 #define GetMFrag(pbuf)  (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) != 0)
73
74 #define ClearMFrag(pbuf) ({ \
75         *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)); \
76 })
77
78 #define SetRetry(pbuf) ({ \
79         *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_RETRY); \
80 })
81
82 #define GetRetry(pbuf)  (((*(__le16 *)(pbuf)) & cpu_to_le16(IEEE80211_FCTL_RETRY)) != 0)
83
84 #define ClearRetry(pbuf) ({ \
85         *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_RETRY)); \
86 })
87
88 #define SetPwrMgt(pbuf) ({ \
89         *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_PM); \
90 })
91
92 #define GetPwrMgt(pbuf) (((*(__le16 *)(pbuf)) & \
93                         cpu_to_le16(IEEE80211_FCTL_PM)) != 0)
94
95 #define ClearPwrMgt(pbuf) ({ \
96         *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_PM)); \
97 })
98
99 #define SetMData(pbuf) ({ \
100         *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_MOREDATA); \
101 })
102
103 #define GetMData(pbuf)  (((*(__le16 *)(pbuf)) & \
104                         cpu_to_le16(IEEE80211_FCTL_MOREDATA)) != 0)
105
106 #define ClearMData(pbuf) ({ \
107         *(__le16 *)(pbuf) &= (~cpu_to_le16(IEEE80211_FCTL_MOREDATA)); \
108 })
109
110 #define SetPrivacy(pbuf) ({ \
111         *(__le16 *)(pbuf) |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); \
112 })
113
114 #define GetPrivacy(pbuf)        (((*(__le16 *)(pbuf)) & \
115                                 cpu_to_le16(IEEE80211_FCTL_PROTECTED)) != 0)
116
117 #define GetOrder(pbuf)  (((*(__le16 *)(pbuf)) & \
118                         cpu_to_le16(IEEE80211_FCTL_ORDER)) != 0)
119
120 #define GetFrameType(pbuf)      (le16_to_cpu(*(__le16 *)(pbuf)) & \
121                                 (BIT(3) | BIT(2)))
122
123 #define SetFrameType(pbuf, type)        \
124         do {    \
125                 *(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(3) | \
126                 BIT(2))); \
127                 *(__le16 *)(pbuf) |= cpu_to_le16(type); \
128         } while (0)
129
130 #define GetFrameSubType(pbuf)   (le16_to_cpu(*(__le16 *)(pbuf)) & \
131                                 (BIT(7) | BIT(6) | BIT(5) | BIT(4) | BIT(3) | \
132                                 BIT(2)))
133
134 #define SetFrameSubType(pbuf, type) \
135         do {    \
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); \
139         } while (0)
140
141 #define GetSequence(pbuf)       (le16_to_cpu(*(__le16 *)\
142                                 ((addr_t)(pbuf) + 22)) >> 4)
143
144 #define GetFragNum(pbuf)        (le16_to_cpu(*(__le16 *)((addr_t)\
145                                 (pbuf) + 22)) & 0x0f)
146
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))); \
151 })
152
153 #define SetPriority(pbuf, tid) ({ \
154         *(__le16 *)(pbuf) |= cpu_to_le16(tid & 0xf); \
155 })
156
157 #define GetPriority(pbuf)       ((le16_to_cpu(*(__le16 *)(pbuf))) & 0xf)
158
159 #define SetAckpolicy(pbuf, ack) ({ \
160         *(__le16 *)(pbuf) |= cpu_to_le16((ack & 3) << 5); \
161 })
162
163 #define GetAckpolicy(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 5) & 0x3)
164
165 #define GetAMsdu(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 7) & 0x1)
166
167 #define GetAddr1Ptr(pbuf)       ((unsigned char *)((addr_t)(pbuf) + 4))
168
169 #define GetAddr2Ptr(pbuf)       ((unsigned char *)((addr_t)(pbuf) + 10))
170
171 #define GetAddr3Ptr(pbuf)       ((unsigned char *)((addr_t)(pbuf) + 16))
172
173 #define GetAddr4Ptr(pbuf)       ((unsigned char *)((addr_t)(pbuf) + 24))
174
175 static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
176 {
177         unsigned char   *sa;
178         unsigned int    to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
179
180         switch (to_fr_ds) {
181         case 0x00:      /* ToDs=0, FromDs=0 */
182                 sa = GetAddr3Ptr(pframe);
183                 break;
184         case 0x01:      /* ToDs=0, FromDs=1 */
185                 sa = GetAddr2Ptr(pframe);
186                 break;
187         case 0x02:      /* ToDs=1, FromDs=0 */
188                 sa = GetAddr1Ptr(pframe);
189                 break;
190         default:        /* ToDs=1, FromDs=1 */
191                 sa = NULL;
192                 break;
193         }
194         return sa;
195 }
196
197 /*-----------------------------------------------------------------------------
198  *              Below is for the security related definition
199  *-----------------------------------------------------------------------------
200  */
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
210
211 #define _FIXED_IE_LENGTH_       _BEACON_IE_OFFSET_
212
213 /* ---------------------------------------------------------------------------
214  *                      Below is the fixed elements...
215  * ---------------------------------------------------------------------------
216  */
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
224 #define _ASOC_ID_                               2
225 #define _STATUS_CODE_                   2
226 #define _TIMESTAMP_                             8
227
228 #define AUTH_ODD_TO                             0
229 #define AUTH_EVEN_TO                    1
230
231 /*-----------------------------------------------------------------------------
232  *                      Below is the definition for 802.11i / 802.1x
233  *------------------------------------------------------------------------------
234  */
235 #define _IEEE8021X_MGT_                 1       /*WPA */
236 #define _IEEE8021X_PSK_                 2       /* WPA with pre-shared key */
237
238 /*-----------------------------------------------------------------------------
239  *                      Below is the definition for WMM
240  *------------------------------------------------------------------------------
241  */
242 #define _WMM_IE_Length_                         7  /* for WMM STA */
243
244 #endif /* _WIFI_H_ */
245