xref: /linux/drivers/staging/rtl8723bs/include/wifi.h (revision 3fb7c93716d36395ffec52d4c2d50f85fd5b451c)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
3  *
4  * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5  *
6  ******************************************************************************/
7 #ifndef _WIFI_H_
8 #define _WIFI_H_
9 
10 #define WLAN_HDR_A3_LEN		24
11 #define WLAN_HDR_A3_QOS_LEN	26
12 
13 #define WLAN_WMM_LEN		24
14 
15 /*  This value is tested by WiFi 11n Test Plan 5.2.3. */
16 /*  This test verifies the WLAN NIC can update the NAV through sending the CTS with large duration. */
17 #define	WiFiNavUpperUs				30000	/*  30 ms */
18 
19 enum {
20 	WIFI_MGT_TYPE  =	(0),
21 	WIFI_CTRL_TYPE =	(BIT(2)),
22 	WIFI_DATA_TYPE =	(BIT(3)),
23 	WIFI_QOS_DATA_TYPE	= (BIT(7)|BIT(3)),	/*  QoS Data */
24 };
25 
26 enum {
27 
28     /*  below is for mgt frame */
29     WIFI_ASSOCREQ       = (0 | WIFI_MGT_TYPE),
30     WIFI_ASSOCRSP       = (BIT(4) | WIFI_MGT_TYPE),
31     WIFI_REASSOCREQ     = (BIT(5) | WIFI_MGT_TYPE),
32     WIFI_REASSOCRSP     = (BIT(5) | BIT(4) | WIFI_MGT_TYPE),
33     WIFI_PROBEREQ       = (BIT(6) | WIFI_MGT_TYPE),
34     WIFI_PROBERSP       = (BIT(6) | BIT(4) | WIFI_MGT_TYPE),
35     WIFI_BEACON         = (BIT(7) | WIFI_MGT_TYPE),
36     WIFI_ATIM           = (BIT(7) | BIT(4) | WIFI_MGT_TYPE),
37     WIFI_DISASSOC       = (BIT(7) | BIT(5) | WIFI_MGT_TYPE),
38     WIFI_AUTH           = (BIT(7) | BIT(5) | BIT(4) | WIFI_MGT_TYPE),
39     WIFI_DEAUTH         = (BIT(7) | BIT(6) | WIFI_MGT_TYPE),
40     WIFI_ACTION         = (BIT(7) | BIT(6) | BIT(4) | WIFI_MGT_TYPE),
41     WIFI_ACTION_NOACK = (BIT(7) | BIT(6) | BIT(5) | WIFI_MGT_TYPE),
42 
43     /*  below is for control frame */
44     WIFI_NDPA         = (BIT(6) | BIT(4) | WIFI_CTRL_TYPE),
45     WIFI_PSPOLL         = (BIT(7) | BIT(5) | WIFI_CTRL_TYPE),
46     WIFI_RTS            = (BIT(7) | BIT(5) | BIT(4) | WIFI_CTRL_TYPE),
47     WIFI_CTS            = (BIT(7) | BIT(6) | WIFI_CTRL_TYPE),
48     WIFI_ACK            = (BIT(7) | BIT(6) | BIT(4) | WIFI_CTRL_TYPE),
49     WIFI_CFEND          = (BIT(7) | BIT(6) | BIT(5) | WIFI_CTRL_TYPE),
50     WIFI_CFEND_CFACK    = (BIT(7) | BIT(6) | BIT(5) | BIT(4) | WIFI_CTRL_TYPE),
51 
52     /*  below is for data frame */
53     WIFI_DATA           = (0 | WIFI_DATA_TYPE),
54     WIFI_DATA_CFACK     = (BIT(4) | WIFI_DATA_TYPE),
55     WIFI_DATA_CFPOLL    = (BIT(5) | WIFI_DATA_TYPE),
56     WIFI_DATA_CFACKPOLL = (BIT(5) | BIT(4) | WIFI_DATA_TYPE),
57     WIFI_DATA_NULL      = (BIT(6) | WIFI_DATA_TYPE),
58     WIFI_CF_ACK         = (BIT(6) | BIT(4) | WIFI_DATA_TYPE),
59     WIFI_CF_POLL        = (BIT(6) | BIT(5) | WIFI_DATA_TYPE),
60     WIFI_CF_ACKPOLL     = (BIT(6) | BIT(5) | BIT(4) | WIFI_DATA_TYPE),
61     WIFI_QOS_DATA_NULL	= (BIT(6) | WIFI_QOS_DATA_TYPE),
62 };
63 
64 #define _TO_DS_		BIT(8)
65 #define _FROM_DS_	BIT(9)
66 #define _MORE_FRAG_	BIT(10)
67 #define _RETRY_		BIT(11)
68 #define _PWRMGT_	BIT(12)
69 #define _MORE_DATA_	BIT(13)
70 #define _PRIVACY_	BIT(14)
71 #define _ORDER_			BIT(15)
72 
73 #define SetToDs(pbuf)	\
74 	(*(__le16 *)(pbuf) |= cpu_to_le16(_TO_DS_))
75 
76 #define GetToDs(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_TO_DS_)) != 0)
77 
78 #define SetFrDs(pbuf)	\
79 	(*(__le16 *)(pbuf) |= cpu_to_le16(_FROM_DS_))
80 
81 #define GetFrDs(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_FROM_DS_)) != 0)
82 
83 #define get_tofr_ds(pframe)	((GetToDs(pframe) << 1) | GetFrDs(pframe))
84 
85 #define SetMFrag(pbuf)	\
86 	(*(__le16 *)(pbuf) |= cpu_to_le16(_MORE_FRAG_))
87 
88 #define GetMFrag(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_MORE_FRAG_)) != 0)
89 
90 #define ClearMFrag(pbuf)	\
91 	(*(__le16 *)(pbuf) &= (~cpu_to_le16(_MORE_FRAG_)))
92 
93 #define GetRetry(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_RETRY_)) != 0)
94 
95 #define ClearRetry(pbuf)	\
96 	(*(__le16 *)(pbuf) &= (~cpu_to_le16(_RETRY_)))
97 
98 #define SetPwrMgt(pbuf)	\
99 	(*(__le16 *)(pbuf) |= cpu_to_le16(_PWRMGT_))
100 
101 #define GetPwrMgt(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_PWRMGT_)) != 0)
102 
103 #define ClearPwrMgt(pbuf)	\
104 	(*(__le16 *)(pbuf) &= (~cpu_to_le16(_PWRMGT_)))
105 
106 #define SetMData(pbuf)	\
107 	(*(__le16 *)(pbuf) |= cpu_to_le16(_MORE_DATA_))
108 
109 #define GetMData(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_MORE_DATA_)) != 0)
110 
111 #define ClearMData(pbuf)	\
112 	(*(__le16 *)(pbuf) &= (~cpu_to_le16(_MORE_DATA_)))
113 
114 #define SetPrivacy(pbuf)	\
115 	(*(__le16 *)(pbuf) |= cpu_to_le16(_PRIVACY_))
116 
117 #define GetPrivacy(pbuf)					\
118 	(((*(__le16 *)(pbuf)) & cpu_to_le16(_PRIVACY_)) != 0)
119 
120 #define GetOrder(pbuf)					\
121 	(((*(__le16 *)(pbuf)) & cpu_to_le16(_ORDER_)) != 0)
122 
123 #define GetFrameType(pbuf)				\
124 	(le16_to_cpu(*(__le16 *)(pbuf)) & (BIT(3) | BIT(2)))
125 
126 #define SetFrameType(pbuf, type)	\
127 	do {	\
128 		*(unsigned short *)(pbuf) &= cpu_to_le16(~(BIT(3) | BIT(2))); \
129 		*(unsigned short *)(pbuf) |= cpu_to_le16(type); \
130 	} while (0)
131 
132 #define GetFrameSubType(pbuf)	(le16_to_cpu(*(__le16 *)(pbuf)) & (BIT(7) |\
133 	 BIT(6) | BIT(5) | BIT(4) | BIT(3) | BIT(2)))
134 
135 #define SetFrameSubType(pbuf, type) \
136 	do {    \
137 		*(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(7) | BIT(6) |	\
138 		 BIT(5) | BIT(4) | BIT(3) | BIT(2))); \
139 		*(__le16 *)(pbuf) |= cpu_to_le16(type); \
140 	} while (0)
141 
142 #define GetSequence(pbuf)			\
143 	(le16_to_cpu(*(__le16 *)((size_t)(pbuf) + 22)) >> 4)
144 
145 #define GetFragNum(pbuf)			\
146 	(le16_to_cpu(*(__le16 *)((size_t)(pbuf) + 22)) & 0x0f)
147 
148 #define SetFragNum(pbuf, num) \
149 	do {    \
150 		*(unsigned short *)((size_t)(pbuf) + 22) = \
151 			((*(unsigned short *)((size_t)(pbuf) + 22)) &	\
152 			le16_to_cpu(~(0x000f))) | \
153 			cpu_to_le16(0x0f & (num));     \
154 	} while (0)
155 
156 #define SetSeqNum(pbuf, num) \
157 	do {    \
158 		*(__le16 *)((size_t)(pbuf) + 22) = \
159 			((*(__le16 *)((size_t)(pbuf) + 22)) & cpu_to_le16((unsigned short)0x000f)) | \
160 			cpu_to_le16((unsigned short)(0xfff0 & (num << 4))); \
161 	} while (0)
162 
163 #define SetDuration(pbuf, dur) \
164 	(*(__le16 *)((size_t)(pbuf) + 2) = cpu_to_le16(0xffff & (dur)))
165 
166 
167 #define SetPriority(pbuf, tid)	\
168 	(*(__le16 *)(pbuf) |= cpu_to_le16(tid & 0xf))
169 
170 #define GetPriority(pbuf)	((le16_to_cpu(*(__le16 *)(pbuf))) & 0xf)
171 
172 #define SetEOSP(pbuf, eosp)	\
173 		(*(__le16 *)(pbuf) |= cpu_to_le16((eosp & 1) << 4))
174 
175 #define SetAckpolicy(pbuf, ack)	\
176 	(*(__le16 *)(pbuf) |= cpu_to_le16((ack & 3) << 5))
177 
178 #define GetAckpolicy(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 5) & 0x3)
179 
180 #define GetAMsdu(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 7) & 0x1)
181 
182 #define GetAid(pbuf)	(le16_to_cpu(*(__le16 *)((size_t)(pbuf) + 2)) & 0x3fff)
183 
184 #define GetAddr1Ptr(pbuf)	((unsigned char *)((size_t)(pbuf) + 4))
185 
186 #define GetAddr2Ptr(pbuf)	((unsigned char *)((size_t)(pbuf) + 10))
187 
188 #define GetAddr3Ptr(pbuf)	((unsigned char *)((size_t)(pbuf) + 16))
189 
190 #define GetAddr4Ptr(pbuf)	((unsigned char *)((size_t)(pbuf) + 24))
191 
192 static inline unsigned char *rtl8723bs_get_ra(unsigned char *pframe)
193 {
194 	unsigned char *ra;
195 	ra = GetAddr1Ptr(pframe);
196 	return ra;
197 }
198 static inline unsigned char *get_ta(unsigned char *pframe)
199 {
200 	unsigned char *ta;
201 	ta = GetAddr2Ptr(pframe);
202 	return ta;
203 }
204 
205 static inline unsigned char *get_da(unsigned char *pframe)
206 {
207 	unsigned char *da;
208 	unsigned int	to_fr_ds	= (GetToDs(pframe) << 1) | GetFrDs(pframe);
209 
210 	switch (to_fr_ds) {
211 	case 0x00:	/*  ToDs = 0, FromDs = 0 */
212 		da = GetAddr1Ptr(pframe);
213 		break;
214 	case 0x01:	/*  ToDs = 0, FromDs = 1 */
215 		da = GetAddr1Ptr(pframe);
216 		break;
217 	case 0x02:	/*  ToDs = 1, FromDs = 0 */
218 		da = GetAddr3Ptr(pframe);
219 		break;
220 	default:	/*  ToDs = 1, FromDs = 1 */
221 		da = GetAddr3Ptr(pframe);
222 		break;
223 	}
224 
225 	return da;
226 }
227 
228 
229 static inline unsigned char *get_sa(unsigned char *pframe)
230 {
231 	unsigned char *sa;
232 	unsigned int	to_fr_ds	= (GetToDs(pframe) << 1) | GetFrDs(pframe);
233 
234 	switch (to_fr_ds) {
235 	case 0x00:	/*  ToDs = 0, FromDs = 0 */
236 		sa = GetAddr2Ptr(pframe);
237 		break;
238 	case 0x01:	/*  ToDs = 0, FromDs = 1 */
239 		sa = GetAddr3Ptr(pframe);
240 		break;
241 	case 0x02:	/*  ToDs = 1, FromDs = 0 */
242 		sa = GetAddr2Ptr(pframe);
243 		break;
244 	default:	/*  ToDs = 1, FromDs = 1 */
245 		sa = GetAddr4Ptr(pframe);
246 		break;
247 	}
248 
249 	return sa;
250 }
251 
252 static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
253 {
254 	unsigned char *sa = NULL;
255 	unsigned int	to_fr_ds	= (GetToDs(pframe) << 1) | GetFrDs(pframe);
256 
257 	switch (to_fr_ds) {
258 	case 0x00:	/*  ToDs = 0, FromDs = 0 */
259 		sa = GetAddr3Ptr(pframe);
260 		break;
261 	case 0x01:	/*  ToDs = 0, FromDs = 1 */
262 		sa = GetAddr2Ptr(pframe);
263 		break;
264 	case 0x02:	/*  ToDs = 1, FromDs = 0 */
265 		sa = GetAddr1Ptr(pframe);
266 		break;
267 	case 0x03:	/*  ToDs = 1, FromDs = 1 */
268 		sa = GetAddr1Ptr(pframe);
269 		break;
270 	}
271 
272 	return sa;
273 }
274 
275 
276 static inline int IsFrameTypeCtrl(unsigned char *pframe)
277 {
278 	return GetFrameType(pframe) == WIFI_CTRL_TYPE;
279 }
280 /*-----------------------------------------------------------------------------
281 			Below is for the security related definition
282 ------------------------------------------------------------------------------*/
283 
284 #define _ASOCREQ_IE_OFFSET_		4	/*  excluding wlan_hdr */
285 #define _REASOCREQ_IE_OFFSET_	10
286 #define _PROBEREQ_IE_OFFSET_	0
287 #define	_PROBERSP_IE_OFFSET_	12
288 #define _AUTH_IE_OFFSET_		6
289 #define _BEACON_IE_OFFSET_		12
290 
291 #define _FIXED_IE_LENGTH_			_BEACON_IE_OFFSET_
292 
293 /* ---------------------------------------------------------------------------
294 					Below is the fixed elements...
295 -----------------------------------------------------------------------------*/
296 #define _AUTH_ALGM_NUM_			2
297 #define _AUTH_SEQ_NUM_			2
298 #define _BEACON_ITERVAL_		2
299 #define _CAPABILITY_			2
300 #define _RSON_CODE_				2
301 #define _ASOC_ID_				2
302 #define _STATUS_CODE_			2
303 #define _TIMESTAMP_				8
304 
305 /*-----------------------------------------------------------------------------
306 				Below is the definition for 802.11i / 802.1x
307 ------------------------------------------------------------------------------*/
308 #define _IEEE8021X_MGT_			1		/*  WPA */
309 #define _IEEE8021X_PSK_			2		/*  WPA with pre-shared key */
310 
311 #define _MME_IE_LENGTH_  18
312 /*-----------------------------------------------------------------------------
313 				Below is the definition for WMM
314 ------------------------------------------------------------------------------*/
315 #define _WMM_IE_Length_				7  /*  for WMM STA */
316 
317 /*-----------------------------------------------------------------------------
318 				Below is the definition for 802.11n
319 ------------------------------------------------------------------------------*/
320 #define GetOrderBit(pbuf)	(((*(unsigned short *)(pbuf)) & cpu_to_le16(_ORDER_)) != 0)
321 
322 #define ACT_CAT_VENDOR				0x7F/* 127 */
323 
324 /**
325  * struct rtw_ieee80211_ht_cap - HT additional information
326  *
327  * This structure refers to "HT information element" as
328  * described in 802.11n draft section 7.3.2.53
329  */
330 struct ieee80211_ht_addt_info {
331 	unsigned char control_chan;
332 	unsigned char 	ht_param;
333 	__le16	operation_mode;
334 	__le16	stbc_param;
335 	unsigned char 	basic_set[16];
336 } __packed;
337 
338 
339 struct HT_caps_element {
340 	union {
341 		struct {
342 			__le16	HT_caps_info;
343 			unsigned char AMPDU_para;
344 			unsigned char MCS_rate[16];
345 			__le16	HT_ext_caps;
346 			__le16	Beamforming_caps;
347 			unsigned char ASEL_caps;
348 		} HT_cap_element;
349 		unsigned char HT_cap[26];
350 	} u;
351 } __packed;
352 
353 struct HT_info_element {
354 	unsigned char primary_channel;
355 	unsigned char infos[5];
356 	unsigned char MCS_rate[16];
357 } __packed;
358 
359 struct AC_param {
360 	unsigned char 	ACI_AIFSN;
361 	unsigned char 	CW;
362 	__le16	TXOP_limit;
363 } __packed;
364 
365 struct WMM_para_element {
366 	unsigned char 	QoS_info;
367 	unsigned char 	reserved;
368 	struct AC_param	ac_param[4];
369 } __packed;
370 
371 struct ADDBA_request {
372 	unsigned char 	dialog_token;
373 	__le16	BA_para_set;
374 	__le16	BA_timeout_value;
375 	__le16	BA_starting_seqctrl;
376 } __packed;
377 
378 /* 802.11n HT capabilities masks */
379 #define IEEE80211_HT_CAP_LDPC_CODING		0x0001
380 #define IEEE80211_HT_CAP_SUP_WIDTH		0x0002
381 #define IEEE80211_HT_CAP_SM_PS			0x000C
382 #define IEEE80211_HT_CAP_GRN_FLD		0x0010
383 #define IEEE80211_HT_CAP_SGI_20			0x0020
384 #define IEEE80211_HT_CAP_SGI_40			0x0040
385 #define IEEE80211_HT_CAP_TX_STBC			0x0080
386 #define IEEE80211_HT_CAP_RX_STBC_1R		0x0100
387 #define IEEE80211_HT_CAP_RX_STBC_3R		0x0300
388 #define IEEE80211_HT_CAP_MAX_AMSDU		0x0800
389 #define IEEE80211_HT_CAP_DSSSCCK40		0x1000
390 /* 802.11n HT capability AMPDU settings */
391 #define IEEE80211_HT_CAP_AMPDU_FACTOR		0x03
392 #define IEEE80211_HT_CAP_AMPDU_DENSITY		0x1C
393 
394 /* endif */
395 
396 /* 	===============WPS Section =============== */
397 /* 	WPS attribute ID */
398 #define WPS_ATTR_SELECTED_REGISTRAR	0x1041
399 
400 /* 	=====================P2P Section ===================== */
401 enum p2p_role {
402 	P2P_ROLE_DISABLE = 0,
403 	P2P_ROLE_DEVICE = 1,
404 	P2P_ROLE_CLIENT = 2,
405 	P2P_ROLE_GO = 3
406 };
407 
408 enum p2p_state {
409 	P2P_STATE_NONE = 0,							/* 	P2P disable */
410 	P2P_STATE_IDLE = 1,								/* 	P2P had enabled and do nothing */
411 	P2P_STATE_LISTEN = 2,							/* 	In pure listen state */
412 	P2P_STATE_SCAN = 3,							/* 	In scan phase */
413 	P2P_STATE_FIND_PHASE_LISTEN = 4,				/* 	In the listen state of find phase */
414 	P2P_STATE_FIND_PHASE_SEARCH = 5,				/* 	In the search state of find phase */
415 	P2P_STATE_TX_PROVISION_DIS_REQ = 6,			/* 	In P2P provisioning discovery */
416 	P2P_STATE_RX_PROVISION_DIS_RSP = 7,
417 	P2P_STATE_RX_PROVISION_DIS_REQ = 8,
418 	P2P_STATE_GONEGO_ING = 9,						/* 	Doing the group owner negotiation handshake */
419 	P2P_STATE_GONEGO_OK = 10,						/* 	finish the group negotiation handshake with success */
420 	P2P_STATE_GONEGO_FAIL = 11,					/* 	finish the group negotiation handshake with failure */
421 	P2P_STATE_RECV_INVITE_REQ_MATCH = 12,		/* 	receiving the P2P Invitation request and match with the profile. */
422 	P2P_STATE_PROVISIONING_ING = 13,				/* 	Doing the P2P WPS */
423 	P2P_STATE_PROVISIONING_DONE = 14,			/* 	Finish the P2P WPS */
424 	P2P_STATE_TX_INVITE_REQ = 15,					/* 	Transmit the P2P Invitation request */
425 	P2P_STATE_RX_INVITE_RESP_OK = 16,				/* 	Receiving the P2P Invitation response */
426 	P2P_STATE_RECV_INVITE_REQ_DISMATCH = 17,	/* 	receiving the P2P Invitation request and mismatch with the profile. */
427 	P2P_STATE_RECV_INVITE_REQ_GO = 18,			/* 	receiving the P2P Invitation request and this wifi is GO. */
428 	P2P_STATE_RECV_INVITE_REQ_JOIN = 19,			/* 	receiving the P2P Invitation request to join an existing P2P Group. */
429 	P2P_STATE_RX_INVITE_RESP_FAIL = 20,			/* 	recveing the P2P Invitation response with failure */
430 	P2P_STATE_RX_INFOR_NOREADY = 21,			/*  receiving p2p negotiation response with information is not available */
431 	P2P_STATE_TX_INFOR_NOREADY = 22,			/*  sending p2p negotiation response with information is not available */
432 };
433 
434 enum p2p_wpsinfo {
435 	P2P_NO_WPSINFO						= 0,
436 	P2P_GOT_WPSINFO_PEER_DISPLAY_PIN	= 1,
437 	P2P_GOT_WPSINFO_SELF_DISPLAY_PIN	= 2,
438 	P2P_GOT_WPSINFO_PBC					= 3,
439 };
440 
441 #define IP_MCAST_MAC(mac)		((mac[0] == 0x01) && (mac[1] == 0x00) && (mac[2] == 0x5e))
442 #define ICMPV6_MCAST_MAC(mac)	((mac[0] == 0x33) && (mac[1] == 0x33) && (mac[2] != 0xff))
443 
444 /* Regulatroy Domain */
445 struct regd_pair_mapping {
446 	u16 reg_dmnenum;
447 	u16 reg_2ghz_ctl;
448 };
449 
450 #endif /*  _WIFI_H_ */
451