1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /* Copyright(c) 2007 - 2012 Realtek Corporation. */
3 
4 #ifndef _WIFI_H_
5 #define _WIFI_H_
6 
7 #include <linux/bits.h>
8 #include <linux/ieee80211.h>
9 
10 #define WLAN_ETHHDR_LEN		14
11 #define WLAN_HDR_A3_LEN		24
12 #define WLAN_HDR_A3_QOS_LEN	26
13 #define WLAN_SSID_MAXLEN	32
14 
15 enum WIFI_FRAME_SUBTYPE {
16 	/*  below is for mgt frame */
17 	WIFI_ASSOCREQ       = (0 | IEEE80211_FTYPE_MGMT),
18 	WIFI_ASSOCRSP       = (BIT(4) | IEEE80211_FTYPE_MGMT),
19 	WIFI_REASSOCREQ     = (BIT(5) | IEEE80211_FTYPE_MGMT),
20 	WIFI_REASSOCRSP     = (BIT(5) | BIT(4) | IEEE80211_FTYPE_MGMT),
21 	WIFI_PROBEREQ       = (BIT(6) | IEEE80211_FTYPE_MGMT),
22 	WIFI_PROBERSP       = (BIT(6) | BIT(4) | IEEE80211_FTYPE_MGMT),
23 	WIFI_BEACON         = (BIT(7) | IEEE80211_FTYPE_MGMT),
24 	WIFI_ATIM           = (BIT(7) | BIT(4) | IEEE80211_FTYPE_MGMT),
25 	WIFI_DISASSOC       = (BIT(7) | BIT(5) | IEEE80211_FTYPE_MGMT),
26 	WIFI_AUTH           = (BIT(7) | BIT(5) | BIT(4) | IEEE80211_FTYPE_MGMT),
27 	WIFI_DEAUTH         = (BIT(7) | BIT(6) | IEEE80211_FTYPE_MGMT),
28 	WIFI_ACTION         = (BIT(7) | BIT(6) | BIT(4) | IEEE80211_FTYPE_MGMT),
29 
30 	/*  below is for control frame */
31 	WIFI_PSPOLL         = (BIT(7) | BIT(5) | IEEE80211_FTYPE_CTL),
32 
33 	/*  below is for data frame */
34 	WIFI_DATA           = (0 | IEEE80211_FTYPE_DATA),
35 	WIFI_DATA_CFACK     = (BIT(4) | IEEE80211_FTYPE_DATA),
36 	WIFI_DATA_CFPOLL    = (BIT(5) | IEEE80211_FTYPE_DATA),
37 	WIFI_DATA_CFACKPOLL = (BIT(5) | BIT(4) | IEEE80211_FTYPE_DATA),
38 	WIFI_DATA_NULL      = (BIT(6) | IEEE80211_FTYPE_DATA),
39 	WIFI_QOS_DATA_NULL	= (BIT(6) | IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA),
40 };
41 
42 enum WIFI_REASON_CODE	{
43 	_RSON_RESERVED_			= 0,
44 	_RSON_UNSPECIFIED_		= 1,
45 	_RSON_AUTH_NO_LONGER_VALID_	= 2,
46 	_RSON_DEAUTH_STA_LEAVING_	= 3,
47 	_RSON_INACTIVITY_		= 4,
48 	_RSON_UNABLE_HANDLE_		= 5,
49 	_RSON_CLS2_			= 6,
50 	_RSON_CLS3_			= 7,
51 	_RSON_DISAOC_STA_LEAVING_	= 8,
52 	_RSON_ASOC_NOT_AUTH_		= 9,
53 
54 	/*  WPA reason */
55 	_RSON_INVALID_IE_		= 13,
56 	_RSON_MIC_FAILURE_		= 14,
57 	_RSON_4WAY_HNDSHK_TIMEOUT_	= 15,
58 	_RSON_GROUP_KEY_UPDATE_TIMEOUT_	= 16,
59 	_RSON_DIFF_IE_			= 17,
60 	_RSON_MLTCST_CIPHER_NOT_VALID_	= 18,
61 	_RSON_UNICST_CIPHER_NOT_VALID_	= 19,
62 	_RSON_AKMP_NOT_VALID_		= 20,
63 	_RSON_UNSUPPORT_RSNE_VER_	= 21,
64 	_RSON_INVALID_RSNE_CAP_		= 22,
65 	_RSON_IEEE_802DOT1X_AUTH_FAIL_	= 23,
66 
67 	/* belowing are Realtek definition */
68 	_RSON_PMK_NOT_AVAILABLE_	= 24,
69 	_RSON_TDLS_TEAR_TOOFAR_		= 25,
70 	_RSON_TDLS_TEAR_UN_RSN_		= 26,
71 };
72 
73 enum WIFI_STATUS_CODE {
74 	_STATS_SUCCESSFUL_		= 0,
75 	_STATS_FAILURE_			= 1,
76 	_STATS_CAP_FAIL_		= 10,
77 	_STATS_NO_ASOC_			= 11,
78 	_STATS_OTHER_			= 12,
79 	_STATS_NO_SUPP_ALG_		= 13,
80 	_STATS_OUT_OF_AUTH_SEQ_		= 14,
81 	_STATS_CHALLENGE_FAIL_		= 15,
82 	_STATS_AUTH_TIMEOUT_		= 16,
83 	_STATS_UNABLE_HANDLE_STA_	= 17,
84 	_STATS_RATE_FAIL_		= 18,
85 };
86 
87 /* entended */
88 /* IEEE 802.11b */
89 #define WLAN_STATUS_ASSOC_DENIED_NOSHORT 19
90 #define WLAN_STATUS_ASSOC_DENIED_NOPBCC 20
91 #define WLAN_STATUS_ASSOC_DENIED_NOAGILITY 21
92 /* IEEE 802.11h */
93 #define WLAN_STATUS_SPEC_MGMT_REQUIRED 22
94 #define WLAN_STATUS_PWR_CAPABILITY_NOT_VALID 23
95 #define WLAN_STATUS_SUPPORTED_CHANNEL_NOT_VALID 24
96 /* IEEE 802.11g */
97 #define WLAN_STATUS_ASSOC_DENIED_NO_SHORT_SLOT_TIME 25
98 #define WLAN_STATUS_ASSOC_DENIED_NO_ER_PBCC 26
99 #define WLAN_STATUS_ASSOC_DENIED_NO_DSSS_OFDM 27
100 /* IEEE 802.11w */
101 #define WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY 30
102 #define WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION 31
103 /* IEEE 802.11i */
104 #define WLAN_STATUS_INVALID_IE 40
105 #define WLAN_STATUS_GROUP_CIPHER_NOT_VALID 41
106 #define WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID 42
107 #define WLAN_STATUS_AKMP_NOT_VALID 43
108 #define WLAN_STATUS_UNSUPPORTED_RSN_IE_VERSION 44
109 #define WLAN_STATUS_INVALID_RSN_IE_CAPAB 45
110 #define WLAN_STATUS_CIPHER_REJECTED_PER_POLICY 46
111 #define WLAN_STATUS_TS_NOT_CREATED 47
112 #define WLAN_STATUS_DIRECT_LINK_NOT_ALLOWED 48
113 #define WLAN_STATUS_DEST_STA_NOT_PRESENT 49
114 #define WLAN_STATUS_DEST_STA_NOT_QOS_STA 50
115 #define WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE 51
116 /* IEEE 802.11r */
117 #define WLAN_STATUS_INVALID_FT_ACTION_FRAME_COUNT 52
118 #define WLAN_STATUS_INVALID_PMKID 53
119 #define WLAN_STATUS_INVALID_MDIE 54
120 #define WLAN_STATUS_INVALID_FTIE 55
121 
122 enum WIFI_REG_DOMAIN {
123 	DOMAIN_FCC	= 1,
124 	DOMAIN_IC	= 2,
125 	DOMAIN_ETSI	= 3,
126 	DOMAIN_SPA	= 4,
127 	DOMAIN_FRANCE	= 5,
128 	DOMAIN_MKK	= 6,
129 	DOMAIN_ISRAEL	= 7,
130 	DOMAIN_MKK1	= 8,
131 	DOMAIN_MKK2	= 9,
132 	DOMAIN_MKK3	= 10,
133 	DOMAIN_MAX
134 };
135 
136 #define _TO_DS_		BIT(8)
137 #define _FROM_DS_	BIT(9)
138 #define _MORE_FRAG_	BIT(10)
139 #define _RETRY_		BIT(11)
140 #define _PWRMGT_	BIT(12)
141 #define _MORE_DATA_	BIT(13)
142 #define _PRIVACY_	BIT(14)
143 #define _ORDER_		BIT(15)
144 
145 #define SetToDs(pbuf)	\
146 	*(__le16 *)(pbuf) |= cpu_to_le16(_TO_DS_)
147 
148 #define GetToDs(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_TO_DS_)) != 0)
149 
150 #define SetFrDs(pbuf)	\
151 	*(__le16 *)(pbuf) |= cpu_to_le16(_FROM_DS_)
152 
153 #define GetFrDs(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_FROM_DS_)) != 0)
154 
155 #define SetMFrag(pbuf)	\
156 	*(__le16 *)(pbuf) |= cpu_to_le16(_MORE_FRAG_)
157 
158 #define ClearMFrag(pbuf)	\
159 	*(__le16 *)(pbuf) &= (~cpu_to_le16(_MORE_FRAG_))
160 
161 #define GetRetry(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_RETRY_)) != 0)
162 
163 #define SetPwrMgt(pbuf)	\
164 	*(__le16 *)(pbuf) |= cpu_to_le16(_PWRMGT_)
165 
166 #define GetPwrMgt(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_PWRMGT_)) != 0)
167 
168 #define SetMData(pbuf)	\
169 	*(__le16 *)(pbuf) |= cpu_to_le16(_MORE_DATA_)
170 
171 #define SetPrivacy(pbuf)	\
172 	*(__le16 *)(pbuf) |= cpu_to_le16(_PRIVACY_)
173 
174 #define GetPrivacy(pbuf)					\
175 	(((*(__le16 *)(pbuf)) & cpu_to_le16(_PRIVACY_)) != 0)
176 
177 #define GetFrameType(pbuf)				\
178 	(le16_to_cpu(*(__le16 *)(pbuf)) & (BIT(3) | BIT(2)))
179 
180 #define GetFrameSubType(pbuf)	(le16_to_cpu(*(__le16 *)(pbuf)) & (BIT(7) |\
181 	 BIT(6) | BIT(5) | BIT(4) | BIT(3) | BIT(2)))
182 
183 #define SetFrameSubType(pbuf, type) \
184 	do {    \
185 		*(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(7) | BIT(6) |	\
186 		 BIT(5) | BIT(4) | BIT(3) | BIT(2))); \
187 		*(__le16 *)(pbuf) |= cpu_to_le16(type); \
188 	} while (0)
189 
190 #define GetTupleCache(pbuf)			\
191 	(cpu_to_le16(*(unsigned short *)((size_t)(pbuf) + 22)))
192 
193 #define SetFragNum(pbuf, num) \
194 	do {    \
195 		*(unsigned short *)((size_t)(pbuf) + 22) = \
196 			((*(unsigned short *)((size_t)(pbuf) + 22)) &	\
197 			le16_to_cpu(~(0x000f))) | \
198 			cpu_to_le16(0x0f & (num));     \
199 	} while (0)
200 
201 #define SetSeqNum(pbuf, num) \
202 	do {    \
203 		*(__le16 *)((size_t)(pbuf) + 22) = \
204 			((*(__le16 *)((size_t)(pbuf) + 22)) & cpu_to_le16((unsigned short)0x000f)) | \
205 			cpu_to_le16((unsigned short)(0xfff0 & (num << 4))); \
206 	} while (0)
207 
208 #define SetDuration(pbuf, dur) \
209 	*(__le16 *)((size_t)(pbuf) + 2) = cpu_to_le16(0xffff & (dur))
210 
211 #define SetPriority(pbuf, tid)	\
212 	*(__le16 *)(pbuf) |= cpu_to_le16(tid & 0xf)
213 
214 #define SetEOSP(pbuf, eosp)	\
215 		*(__le16 *)(pbuf) |= cpu_to_le16((eosp & 1) << 4)
216 
217 #define SetAckpolicy(pbuf, ack)	\
218 	*(__le16 *)(pbuf) |= cpu_to_le16((ack & 3) << 5)
219 
220 #define GetAckpolicy(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 5) & 0x3)
221 
222 #define GetAMsdu(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 7) & 0x1)
223 
224 #define SetAMsdu(pbuf, amsdu)	\
225 	*(__le16 *)(pbuf) |= cpu_to_le16((amsdu & 1) << 7)
226 
227 #define GetTid(pbuf)	(le16_to_cpu(*(__le16 *)((size_t)(pbuf) +	\
228 			(((GetToDs(pbuf)<<1) | GetFrDs(pbuf)) == 3 ?	\
229 			30 : 24))) & 0x000f)
230 
231 #define GetAddr1Ptr(pbuf)	((unsigned char *)((size_t)(pbuf) + 4))
232 
233 #define GetAddr2Ptr(pbuf)	((unsigned char *)((size_t)(pbuf) + 10))
234 
235 #define GetAddr3Ptr(pbuf)	((unsigned char *)((size_t)(pbuf) + 16))
236 
237 #define GetAddr4Ptr(pbuf)	((unsigned char *)((size_t)(pbuf) + 24))
238 
IS_MCAST(unsigned char * da)239 static inline bool IS_MCAST(unsigned char *da)
240 {
241 	return (*da) & 0x01;
242 }
243 
get_da(unsigned char * pframe)244 static inline unsigned char *get_da(unsigned char *pframe)
245 {
246 	unsigned char	*da;
247 	unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
248 
249 	switch (to_fr_ds) {
250 	case 0x00:	/*  ToDs=0, FromDs=0 */
251 		da = GetAddr1Ptr(pframe);
252 		break;
253 	case 0x01:	/*  ToDs=0, FromDs=1 */
254 		da = GetAddr1Ptr(pframe);
255 		break;
256 	case 0x02:	/*  ToDs=1, FromDs=0 */
257 		da = GetAddr3Ptr(pframe);
258 		break;
259 	default:	/*  ToDs=1, FromDs=1 */
260 		da = GetAddr3Ptr(pframe);
261 		break;
262 	}
263 	return da;
264 }
265 
get_sa(unsigned char * pframe)266 static inline unsigned char *get_sa(unsigned char *pframe)
267 {
268 	unsigned char	*sa;
269 	unsigned int	to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
270 
271 	switch (to_fr_ds) {
272 	case 0x00:	/*  ToDs=0, FromDs=0 */
273 		sa = GetAddr2Ptr(pframe);
274 		break;
275 	case 0x01:	/*  ToDs=0, FromDs=1 */
276 		sa = GetAddr3Ptr(pframe);
277 		break;
278 	case 0x02:	/*  ToDs=1, FromDs=0 */
279 		sa = GetAddr2Ptr(pframe);
280 		break;
281 	default:	/*  ToDs=1, FromDs=1 */
282 		sa = GetAddr4Ptr(pframe);
283 		break;
284 	}
285 	return sa;
286 }
287 
get_hdr_bssid(unsigned char * pframe)288 static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
289 {
290 	unsigned char	*sa;
291 	unsigned int	to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
292 
293 	switch (to_fr_ds) {
294 	case 0x00:	/*  ToDs=0, FromDs=0 */
295 		sa = GetAddr3Ptr(pframe);
296 		break;
297 	case 0x01:	/*  ToDs=0, FromDs=1 */
298 		sa = GetAddr2Ptr(pframe);
299 		break;
300 	case 0x02:	/*  ToDs=1, FromDs=0 */
301 		sa = GetAddr1Ptr(pframe);
302 		break;
303 	case 0x03:	/*  ToDs=1, FromDs=1 */
304 		sa = GetAddr1Ptr(pframe);
305 		break;
306 	default:
307 		sa = NULL; /*  */
308 		break;
309 	}
310 	return sa;
311 }
312 
313 /*-----------------------------------------------------------------------------
314 			Below is for the security related definition
315 ------------------------------------------------------------------------------*/
316 #define _RESERVED_FRAME_TYPE_		0
317 #define _SKB_FRAME_TYPE_		2
318 #define _PRE_ALLOCMEM_			1
319 #define _PRE_ALLOCHDR_			3
320 #define _PRE_ALLOCLLCHDR_		4
321 #define _PRE_ALLOCICVHDR_		5
322 #define _PRE_ALLOCMICHDR_		6
323 
324 #define _SIFSTIME_				\
325 	(priv->pmib->dot11BssType.net_work_type = 10)
326 #define _ACKCTSLNG_		14	/* 14 bytes long, including crclng */
327 #define _CRCLNG_		4
328 
329 #define _ASOCREQ_IE_OFFSET_	4	/*  excluding wlan_hdr */
330 #define	_ASOCRSP_IE_OFFSET_	6
331 #define _REASOCREQ_IE_OFFSET_	10
332 #define _REASOCRSP_IE_OFFSET_	6
333 #define _PROBEREQ_IE_OFFSET_	0
334 #define	_PROBERSP_IE_OFFSET_	12
335 #define _AUTH_IE_OFFSET_	6
336 #define _DEAUTH_IE_OFFSET_	0
337 #define _BEACON_IE_OFFSET_	12
338 #define _PUBLIC_ACTION_IE_OFFSET_	8
339 
340 #define _FIXED_IE_LENGTH_	_BEACON_IE_OFFSET_
341 
342 #define _SSID_IE_		0
343 #define _SUPPORTEDRATES_IE_	1
344 #define _DSSET_IE_		3
345 #define _TIM_IE_		5
346 #define _IBSS_PARA_IE_		6
347 #define _COUNTRY_IE_		7
348 #define _CHLGETXT_IE_		16
349 #define _SUPPORTED_CH_IE_	36
350 #define _CH_SWTICH_ANNOUNCE_	37	/* Secondary Channel Offset */
351 #define _RSN_IE_2_		48
352 #define _SSN_IE_1_		221
353 #define _ERPINFO_IE_		42
354 #define _EXT_SUPPORTEDRATES_IE_	50
355 
356 #define _HT_CAPABILITY_IE_	45
357 #define _FTIE_			55
358 #define _TIMEOUT_ITVL_IE_	56
359 #define _SRC_IE_		59
360 #define _HT_EXTRA_INFO_IE_	61
361 #define _HT_ADD_INFO_IE_	61 /* _HT_EXTRA_INFO_IE_ */
362 #define _WAPI_IE_		68
363 
364 #define	EID_BSSCoexistence	72 /*  20/40 BSS Coexistence */
365 #define	EID_BSSIntolerantChlReport	73
366 #define _RIC_Descriptor_IE_	75
367 
368 #define _LINK_ID_IE_		101
369 #define _CH_SWITCH_TIMING_	104
370 #define _PTI_BUFFER_STATUS_	106
371 #define _EXT_CAP_IE_		127
372 #define _VENDOR_SPECIFIC_IE_	221
373 
374 #define	_RESERVED47_		47
375 
376 /* ---------------------------------------------------------------------------
377 					Below is the fixed elements...
378 -----------------------------------------------------------------------------*/
379 #define _AUTH_ALGM_NUM_		2
380 #define _AUTH_SEQ_NUM_		2
381 #define _BEACON_ITERVAL_	2
382 #define _CAPABILITY_		2
383 #define _CURRENT_APADDR_	6
384 #define _LISTEN_INTERVAL_	2
385 #define _RSON_CODE_		2
386 #define _ASOC_ID_		2
387 #define _STATUS_CODE_		2
388 #define _TIMESTAMP_		8
389 
390 #define cap_ESS		BIT(0)
391 #define cap_IBSS	BIT(1)
392 #define cap_CFPollable	BIT(2)
393 #define cap_CFRequest	BIT(3)
394 #define cap_Privacy	BIT(4)
395 #define cap_ShortPremble BIT(5)
396 #define cap_PBCC	BIT(6)
397 #define cap_ChAgility	BIT(7)
398 #define cap_SpecMgmt	BIT(8)
399 #define cap_QoSi	BIT(9)
400 #define cap_ShortSlot	BIT(10)
401 
402 /*-----------------------------------------------------------------------------
403 				Below is the definition for 802.11i / 802.1x
404 ------------------------------------------------------------------------------*/
405 #define _IEEE8021X_MGT_			1	/*  WPA */
406 #define _IEEE8021X_PSK_			2	/*  WPA with pre-shared key */
407 
408 /*-----------------------------------------------------------------------------
409 				Below is the definition for WMM
410 ------------------------------------------------------------------------------*/
411 #define _WMM_IE_Length_				7  /*  for WMM STA */
412 #define _WMM_Para_Element_Length_		24
413 
414 /*-----------------------------------------------------------------------------
415 				Below is the definition for 802.11n
416 ------------------------------------------------------------------------------*/
417 
418 #define SetOrderBit(pbuf)	\
419 	do	{	\
420 		*(unsigned short *)(pbuf) |= cpu_to_le16(_ORDER_); \
421 	} while (0)
422 
423 #define GetOrderBit(pbuf)			\
424 	(((*(unsigned short *)(pbuf)) & le16_to_cpu(_ORDER_)) != 0)
425 
426 /**
427  * struct rtw_ieee80211_bar - HT Block Ack Request
428  *
429  * This structure refers to "HT BlockAckReq" as
430  * described in 802.11n draft section 7.2.1.7.1
431  */
432 struct rtw_ieee80211_bar {
433 	__le16 frame_control;
434 	__le16 duration;
435 	unsigned char ra[ETH_ALEN];
436 	unsigned char ta[ETH_ALEN];
437 	__le16 control;
438 	__le16 start_seq_num;
439 } __packed;
440 
441 /**
442  * struct ieee80211_ht_cap - HT additional information
443  *
444  * This structure refers to "HT information element" as
445  * described in 802.11n draft section 7.3.2.53
446  */
447 struct ieee80211_ht_addt_info {
448 	unsigned char	control_chan;
449 	unsigned char	ht_param;
450 	__le16	operation_mode;
451 	__le16	stbc_param;
452 	unsigned char	basic_set[16];
453 } __packed;
454 
455 struct HT_caps_element {
456 	union {
457 		struct {
458 			__le16	HT_caps_info;
459 			unsigned char	AMPDU_para;
460 			unsigned char	MCS_rate[16];
461 			__le16	HT_ext_caps;
462 			__le16	Beamforming_caps;
463 			unsigned char	ASEL_caps;
464 		} HT_cap_element;
465 		unsigned char HT_cap[26];
466 	} u;
467 } __packed;
468 
469 struct HT_info_element {
470 	unsigned char	primary_channel;
471 	unsigned char	infos[5];
472 	unsigned char	MCS_rate[16];
473 } __packed;
474 
475 struct AC_param {
476 	unsigned char		ACI_AIFSN;
477 	unsigned char		CW;
478 	__le16	TXOP_limit;
479 } __packed;
480 
481 struct WMM_para_element {
482 	unsigned char		QoS_info;
483 	unsigned char		reserved;
484 	struct AC_param	ac_param[4];
485 } __packed;
486 
487 struct ADDBA_request {
488 	unsigned char	action_code;
489 	unsigned char	dialog_token;
490 	__le16	BA_para_set;
491 	__le16	BA_timeout_value;
492 	__le16	BA_starting_seqctrl;
493 } __packed;
494 
495 #define MAX_AMPDU_FACTOR_64K	3
496 
497 /* Spatial Multiplexing Power Save Modes */
498 #define WLAN_HT_CAP_SM_PS_STATIC	0
499 #define WLAN_HT_CAP_SM_PS_DYNAMIC	1
500 #define WLAN_HT_CAP_SM_PS_INVALID	2
501 #define WLAN_HT_CAP_SM_PS_DISABLED	3
502 
503 #define OP_MODE_PURE                    0
504 #define OP_MODE_MAY_BE_LEGACY_STAS      1
505 #define OP_MODE_20MHZ_HT_STA_ASSOCED    2
506 #define OP_MODE_MIXED                   3
507 
508 #define HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK	((u8) BIT(0) | BIT(1))
509 #define HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE		((u8) BIT(0))
510 #define HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW		((u8) BIT(0) | BIT(1))
511 #define HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH		((u8) BIT(2))
512 #define HT_INFO_HT_PARAM_RIFS_MODE			((u8) BIT(3))
513 #define HT_INFO_HT_PARAM_CTRL_ACCESS_ONLY		((u8) BIT(4))
514 #define HT_INFO_HT_PARAM_SRV_INTERVAL_GRANULARITY	((u8) BIT(5))
515 
516 #define HT_INFO_OPERATION_MODE_OP_MODE_MASK	\
517 		((u16) (0x0001 | 0x0002))
518 #define HT_INFO_OPERATION_MODE_OP_MODE_OFFSET		0
519 #define HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT	((u8) BIT(2))
520 #define HT_INFO_OPERATION_MODE_TRANSMIT_BURST_LIMIT	((u8) BIT(3))
521 #define HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT	((u8) BIT(4))
522 
523 /*	===============WPS Section=============== */
524 /*	For WPSv1.0 */
525 #define WPSOUI					0x0050f204
526 /*	WPS attribute ID */
527 #define WPS_ATTR_VER1				0x104A
528 #define WPS_ATTR_SIMPLE_CONF_STATE		0x1044
529 #define WPS_ATTR_RESP_TYPE			0x103B
530 #define WPS_ATTR_UUID_E				0x1047
531 #define WPS_ATTR_MANUFACTURER			0x1021
532 #define WPS_ATTR_MODEL_NAME			0x1023
533 #define WPS_ATTR_MODEL_NUMBER			0x1024
534 #define WPS_ATTR_SERIAL_NUMBER			0x1042
535 #define WPS_ATTR_PRIMARY_DEV_TYPE		0x1054
536 #define WPS_ATTR_SEC_DEV_TYPE_LIST		0x1055
537 #define WPS_ATTR_DEVICE_NAME			0x1011
538 #define WPS_ATTR_CONF_METHOD			0x1008
539 #define WPS_ATTR_RF_BANDS			0x103C
540 #define WPS_ATTR_DEVICE_PWID			0x1012
541 #define WPS_ATTR_REQUEST_TYPE			0x103A
542 #define WPS_ATTR_ASSOCIATION_STATE		0x1002
543 #define WPS_ATTR_CONFIG_ERROR			0x1009
544 #define WPS_ATTR_VENDOR_EXT			0x1049
545 #define WPS_ATTR_SELECTED_REGISTRAR		0x1041
546 
547 /*	Value of WPS attribute "WPS_ATTR_DEVICE_NAME */
548 #define WPS_MAX_DEVICE_NAME_LEN			32
549 
550 /*	Value of WPS Request Type Attribute */
551 #define WPS_REQ_TYPE_ENROLLEE_INFO_ONLY		0x00
552 #define WPS_REQ_TYPE_ENROLLEE_OPEN_8021X	0x01
553 #define WPS_REQ_TYPE_REGISTRAR			0x02
554 #define WPS_REQ_TYPE_WLAN_MANAGER_REGISTRAR	0x03
555 
556 /*	Value of WPS Response Type Attribute */
557 #define WPS_RESPONSE_TYPE_INFO_ONLY	0x00
558 #define WPS_RESPONSE_TYPE_8021X		0x01
559 #define WPS_RESPONSE_TYPE_REGISTRAR	0x02
560 #define WPS_RESPONSE_TYPE_AP		0x03
561 
562 /*	Value of WPS WiFi Simple Configuration State Attribute */
563 #define WPS_WSC_STATE_NOT_CONFIG	0x01
564 #define WPS_WSC_STATE_CONFIG		0x02
565 
566 /*	Value of WPS Version Attribute */
567 #define WPS_VERSION_1			0x10
568 
569 /*	Value of WPS Configuration Method Attribute */
570 #define WPS_CONFIG_METHOD_FLASH		0x0001
571 #define WPS_CONFIG_METHOD_ETHERNET	0x0002
572 #define WPS_CONFIG_METHOD_LABEL		0x0004
573 #define WPS_CONFIG_METHOD_DISPLAY	0x0008
574 #define WPS_CONFIG_METHOD_E_NFC		0x0010
575 #define WPS_CONFIG_METHOD_I_NFC		0x0020
576 #define WPS_CONFIG_METHOD_NFC		0x0040
577 #define WPS_CONFIG_METHOD_PBC		0x0080
578 #define WPS_CONFIG_METHOD_KEYPAD	0x0100
579 #define WPS_CONFIG_METHOD_VPBC		0x0280
580 #define WPS_CONFIG_METHOD_PPBC		0x0480
581 #define WPS_CONFIG_METHOD_VDISPLAY	0x2008
582 #define WPS_CONFIG_METHOD_PDISPLAY	0x4008
583 
584 /*	Value of Category ID of WPS Primary Device Type Attribute */
585 #define WPS_PDT_CID_DISPLAYS		0x0007
586 #define WPS_PDT_CID_MULIT_MEDIA		0x0008
587 #define WPS_PDT_CID_RTK_WIDI		WPS_PDT_CID_MULIT_MEDIA
588 
589 /*	Value of Sub Category ID of WPS Primary Device Type Attribute */
590 #define WPS_PDT_SCID_MEDIA_SERVER	0x0005
591 #define WPS_PDT_SCID_RTK_DMP		WPS_PDT_SCID_MEDIA_SERVER
592 
593 /*	Value of Device Password ID */
594 #define WPS_DPID_P			0x0000
595 #define WPS_DPID_USER_SPEC		0x0001
596 #define WPS_DPID_MACHINE_SPEC		0x0002
597 #define WPS_DPID_REKEY			0x0003
598 #define WPS_DPID_PBC			0x0004
599 #define WPS_DPID_REGISTRAR_SPEC		0x0005
600 
601 /*	Value of WPS RF Bands Attribute */
602 #define WPS_RF_BANDS_2_4_GHZ		0x01
603 #define WPS_RF_BANDS_5_GHZ		0x02
604 
605 /*	Value of WPS Association State Attribute */
606 #define WPS_ASSOC_STATE_NOT_ASSOCIATED		0x00
607 #define WPS_ASSOC_STATE_CONNECTION_SUCCESS	0x01
608 #define WPS_ASSOC_STATE_CONFIGURATION_FAILURE	0x02
609 #define WPS_ASSOC_STATE_ASSOCIATION_FAILURE	0x03
610 #define WPS_ASSOC_STATE_IP_FAILURE		0x04
611 
612 /*	=====================P2P Section===================== */
613 /*	For P2P */
614 #define	P2POUI					0x506F9A09
615 
616 /*	P2P Attribute ID */
617 #define	P2P_ATTR_STATUS				0x00
618 #define	P2P_ATTR_MINOR_REASON_CODE		0x01
619 #define	P2P_ATTR_CAPABILITY			0x02
620 #define	P2P_ATTR_DEVICE_ID			0x03
621 #define	P2P_ATTR_GO_INTENT			0x04
622 #define	P2P_ATTR_CONF_TIMEOUT			0x05
623 #define	P2P_ATTR_LISTEN_CH			0x06
624 #define	P2P_ATTR_GROUP_BSSID			0x07
625 #define	P2P_ATTR_EX_LISTEN_TIMING		0x08
626 #define	P2P_ATTR_INTENTED_IF_ADDR		0x09
627 #define	P2P_ATTR_MANAGEABILITY			0x0A
628 #define	P2P_ATTR_CH_LIST			0x0B
629 #define	P2P_ATTR_NOA				0x0C
630 #define	P2P_ATTR_DEVICE_INFO			0x0D
631 #define	P2P_ATTR_GROUP_INFO			0x0E
632 #define	P2P_ATTR_GROUP_ID			0x0F
633 #define	P2P_ATTR_INTERFACE			0x10
634 #define	P2P_ATTR_OPERATING_CH			0x11
635 #define	P2P_ATTR_INVITATION_FLAGS		0x12
636 
637 /*	Value of Status Attribute */
638 #define	P2P_STATUS_SUCCESS				0x00
639 #define	P2P_STATUS_FAIL_INFO_UNAVAILABLE		0x01
640 #define	P2P_STATUS_FAIL_INCOMPATIBLE_PARAM		0x02
641 #define	P2P_STATUS_FAIL_LIMIT_REACHED			0x03
642 #define	P2P_STATUS_FAIL_INVALID_PARAM			0x04
643 #define	P2P_STATUS_FAIL_REQUEST_UNABLE			0x05
644 #define	P2P_STATUS_FAIL_PREVOUS_PROTO_ERR		0x06
645 #define	P2P_STATUS_FAIL_NO_COMMON_CH			0x07
646 #define	P2P_STATUS_FAIL_UNKNOWN_P2PGROUP		0x08
647 #define	P2P_STATUS_FAIL_BOTH_GOINTENT_15		0x09
648 #define	P2P_STATUS_FAIL_INCOMPATIBLE_PROVSION		0x0A
649 #define	P2P_STATUS_FAIL_USER_REJECT			0x0B
650 
651 /*	Value of Inviation Flags Attribute */
652 #define	P2P_INVITATION_FLAGS_PERSISTENT			BIT(0)
653 
654 #define	DMP_P2P_DEVCAP_SUPPORT	(P2P_DEVCAP_SERVICE_DISCOVERY | \
655 				P2P_DEVCAP_CLIENT_DISCOVERABILITY | \
656 				P2P_DEVCAP_CONCURRENT_OPERATION | \
657 				P2P_DEVCAP_INVITATION_PROC)
658 
659 #define	DMP_P2P_GRPCAP_SUPPORT	(P2P_GRPCAP_INTRABSS)
660 
661 /*	Value of Device Capability Bitmap */
662 #define	P2P_DEVCAP_SERVICE_DISCOVERY		BIT(0)
663 #define	P2P_DEVCAP_CLIENT_DISCOVERABILITY	BIT(1)
664 #define	P2P_DEVCAP_CONCURRENT_OPERATION		BIT(2)
665 #define	P2P_DEVCAP_INFRA_MANAGED		BIT(3)
666 #define	P2P_DEVCAP_DEVICE_LIMIT			BIT(4)
667 #define	P2P_DEVCAP_INVITATION_PROC		BIT(5)
668 
669 /*	Value of Group Capability Bitmap */
670 #define	P2P_GRPCAP_GO				BIT(0)
671 #define	P2P_GRPCAP_PERSISTENT_GROUP		BIT(1)
672 #define	P2P_GRPCAP_GROUP_LIMIT			BIT(2)
673 #define	P2P_GRPCAP_INTRABSS			BIT(3)
674 #define	P2P_GRPCAP_CROSS_CONN			BIT(4)
675 #define	P2P_GRPCAP_PERSISTENT_RECONN		BIT(5)
676 #define	P2P_GRPCAP_GROUP_FORMATION		BIT(6)
677 
678 /*	P2P Public Action Frame (Management Frame) */
679 #define	P2P_PUB_ACTION_ACTION			0x09
680 
681 /*	P2P Public Action Frame Type */
682 #define	P2P_GO_NEGO_REQ				0
683 #define	P2P_GO_NEGO_RESP			1
684 #define	P2P_GO_NEGO_CONF			2
685 #define	P2P_INVIT_REQ				3
686 #define	P2P_INVIT_RESP				4
687 #define	P2P_DEVDISC_REQ				5
688 #define	P2P_DEVDISC_RESP			6
689 #define	P2P_PROVISION_DISC_REQ			7
690 #define	P2P_PROVISION_DISC_RESP			8
691 
692 /*	P2P Action Frame Type */
693 #define	P2P_NOTICE_OF_ABSENCE			0
694 #define	P2P_PRESENCE_REQUEST			1
695 #define	P2P_PRESENCE_RESPONSE			2
696 #define	P2P_GO_DISC_REQUEST			3
697 
698 #define	P2P_MAX_PERSISTENT_GROUP_NUM		10
699 
700 #define	P2P_PROVISIONING_SCAN_CNT		3
701 
702 #define	P2P_WILDCARD_SSID_LEN			7
703 
704 /* default value, used when: (1)p2p disabed or (2)p2p enabled
705  * but only do 1 scan phase */
706 #define	P2P_FINDPHASE_EX_NONE		0
707 /*  used when p2p enabled and want to do 1 scan phase and
708  *  P2P_FINDPHASE_EX_MAX-1 find phase */
709 #define	P2P_FINDPHASE_EX_FULL		1
710 #define	P2P_FINDPHASE_EX_SOCIAL_FIRST	(P2P_FINDPHASE_EX_FULL+1)
711 #define	P2P_FINDPHASE_EX_MAX		4
712 #define	P2P_FINDPHASE_EX_SOCIAL_LAST	P2P_FINDPHASE_EX_MAX
713 
714 /* 5 seconds timeout for sending the provision discovery request */
715 #define	P2P_PROVISION_TIMEOUT		5000
716 /* 3 seconds timeout for sending the prov disc request concurrent mode */
717 #define	P2P_CONCURRENT_PROVISION_TIME	3000
718 /* 5 seconds timeout for receiving the group negotiation response */
719 #define	P2P_GO_NEGO_TIMEOUT		5000
720 /* 3 seconds timeout for sending the negotiation request under concurrent mode */
721 #define	P2P_CONCURRENT_GO_NEGO_TIME	3000
722 /* 100ms */
723 #define	P2P_TX_PRESCAN_TIMEOUT		100
724 /* 5 seconds timeout for sending the invitation request */
725 #define	P2P_INVITE_TIMEOUT		5000
726 /* 3 seconds timeout for sending the invitation request under concurrent mode */
727 #define	P2P_CONCURRENT_INVITE_TIME	3000
728 /* 25 seconds timeout to reset the scan channel (based on channel plan) */
729 #define	P2P_RESET_SCAN_CH		25000
730 #define	P2P_MAX_INTENT			15
731 
732 #define	P2P_MAX_NOA_NUM			2
733 
734 /*	WPS Configuration Method */
735 #define	WPS_CM_NONE			0x0000
736 #define	WPS_CM_LABEL			0x0004
737 #define	WPS_CM_DISPLYA			0x0008
738 #define	WPS_CM_EXTERNAL_NFC_TOKEN	0x0010
739 #define	WPS_CM_INTEGRATED_NFC_TOKEN	0x0020
740 #define	WPS_CM_NFC_INTERFACE		0x0040
741 #define	WPS_CM_PUSH_BUTTON		0x0080
742 #define	WPS_CM_KEYPAD			0x0100
743 #define	WPS_CM_SW_PUHS_BUTTON		0x0280
744 #define	WPS_CM_HW_PUHS_BUTTON		0x0480
745 #define	WPS_CM_SW_DISPLAY_P		0x2008
746 #define	WPS_CM_LCD_DISPLAY_P		0x4008
747 
748 enum P2P_ROLE {
749 	P2P_ROLE_DISABLE = 0,
750 	P2P_ROLE_DEVICE = 1,
751 	P2P_ROLE_CLIENT = 2,
752 	P2P_ROLE_GO = 3
753 };
754 
755 enum P2P_STATE {
756 	P2P_STATE_NONE = 0,			/* P2P disable */
757 	/* P2P had enabled and do nothing */
758 	P2P_STATE_IDLE = 1,
759 	P2P_STATE_LISTEN = 2,			/* In pure listen state */
760 	P2P_STATE_SCAN = 3,			/* In scan phase */
761 	/* In the listen state of find phase */
762 	P2P_STATE_FIND_PHASE_LISTEN = 4,
763 	/* In the search state of find phase */
764 	P2P_STATE_FIND_PHASE_SEARCH = 5,
765 	/* In P2P provisioning discovery */
766 	P2P_STATE_TX_PROVISION_DIS_REQ = 6,
767 	P2P_STATE_RX_PROVISION_DIS_RSP = 7,
768 	P2P_STATE_RX_PROVISION_DIS_REQ = 8,
769 	/* Doing the group owner negoitation handshake */
770 	P2P_STATE_GONEGO_ING = 9,
771 	/* finish the group negoitation handshake with success */
772 	P2P_STATE_GONEGO_OK = 10,
773 	/* finish the group negoitation handshake with failure */
774 	P2P_STATE_GONEGO_FAIL = 11,
775 	/* receiving the P2P Inviation request and match with the profile. */
776 	P2P_STATE_RECV_INVITE_REQ_MATCH = 12,
777 	/* Doing the P2P WPS */
778 	P2P_STATE_PROVISIONING_ING = 13,
779 	/* Finish the P2P WPS */
780 	P2P_STATE_PROVISIONING_DONE = 14,
781 	/* Transmit the P2P Invitation request */
782 	P2P_STATE_TX_INVITE_REQ = 15,
783 	/* Receiving the P2P Invitation response */
784 	P2P_STATE_RX_INVITE_RESP_OK = 16,
785 	/* receiving the P2P Inviation request and dismatch with the profile. */
786 	P2P_STATE_RECV_INVITE_REQ_DISMATCH = 17,
787 	/* receiving the P2P Inviation request and this wifi is GO. */
788 	P2P_STATE_RECV_INVITE_REQ_GO = 18,
789 	/* receiving the P2P Inviation request to join an existing P2P Group. */
790 	P2P_STATE_RECV_INVITE_REQ_JOIN = 19,
791 	/* recveing the P2P Inviation response with failure */
792 	P2P_STATE_RX_INVITE_RESP_FAIL = 20,
793 	/* receiving p2p negoitation response with information is not available */
794 	P2P_STATE_RX_INFOR_NOREADY = 21,
795 	/* sending p2p negoitation response with information is not available */
796 	P2P_STATE_TX_INFOR_NOREADY = 22,
797 };
798 
799 enum P2P_WPSINFO {
800 	P2P_NO_WPSINFO				= 0,
801 	P2P_GOT_WPSINFO_PEER_DISPLAY_PIN	= 1,
802 	P2P_GOT_WPSINFO_SELF_DISPLAY_PIN	= 2,
803 	P2P_GOT_WPSINFO_PBC			= 3,
804 };
805 
806 #define	P2P_PRIVATE_IOCTL_SET_LEN		64
807 
808 enum P2P_PROTO_WK_ID {
809 	P2P_FIND_PHASE_WK = 0,
810 	P2P_RESTORE_STATE_WK = 1,
811 	P2P_PRE_TX_PROVDISC_PROCESS_WK = 2,
812 	P2P_PRE_TX_NEGOREQ_PROCESS_WK = 3,
813 	P2P_PRE_TX_INVITEREQ_PROCESS_WK = 4,
814 	P2P_AP_P2P_CH_SWITCH_PROCESS_WK = 5,
815 	P2P_RO_CH_WK = 6,
816 };
817 
818 enum P2P_PS_STATE {
819 	P2P_PS_DISABLE = 0,
820 	P2P_PS_ENABLE = 1,
821 	P2P_PS_SCAN = 2,
822 	P2P_PS_SCAN_DONE = 3,
823 	P2P_PS_ALLSTASLEEP = 4, /*  for P2P GO */
824 };
825 
826 enum P2P_PS_MODE {
827 	P2P_PS_NONE = 0,
828 	P2P_PS_CTWINDOW = 1,
829 	P2P_PS_NOA	 = 2,
830 	P2P_PS_MIX = 3, /*  CTWindow and NoA */
831 };
832 
833 #define IP_MCAST_MAC(mac)				\
834 	((mac[0] == 0x01) && (mac[1] == 0x00) && (mac[2] == 0x5e))
835 #define ICMPV6_MCAST_MAC(mac)				\
836 	((mac[0] == 0x33) && (mac[1] == 0x33) && (mac[2] != 0xff))
837 
838 #endif /*  _WIFI_H_ */
839