• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20 #ifndef _WIFI_H_
21 #define _WIFI_H_
22 
23 
24 #ifdef BIT
25 /* error	"BIT define occurred earlier elsewhere!\n" */
26 #undef BIT
27 #endif
28 #define BIT(x)	(1 << (x))
29 
30 
31 #define WLAN_ETHHDR_LEN		14
32 #define WLAN_ETHADDR_LEN	6
33 #define WLAN_IEEE_OUI_LEN	3
34 #define WLAN_ADDR_LEN		6
35 #define WLAN_CRC_LEN		4
36 #define WLAN_BSSID_LEN		6
37 #define WLAN_BSS_TS_LEN		8
38 #define WLAN_HDR_A3_LEN		24
39 #define WLAN_HDR_A4_LEN		30
40 #define WLAN_HDR_A3_QOS_LEN	26
41 #define WLAN_HDR_A4_QOS_LEN	32
42 #define WLAN_SSID_MAXLEN	32
43 #define WLAN_DATA_MAXLEN	2312
44 
45 #define WLAN_A3_PN_OFFSET	24
46 #define WLAN_A4_PN_OFFSET	30
47 
48 #define WLAN_MIN_ETHFRM_LEN	60
49 #define WLAN_MAX_ETHFRM_LEN	1514
50 #define WLAN_ETHHDR_LEN		14
51 
52 #define P80211CAPTURE_VERSION	0x80211001
53 
54 /*  This value is tested by WiFi 11n Test Plan 5.2.3. */
55 /*  This test verifies the WLAN NIC can update the NAV through sending
56  *  the CTS with large duration. */
57 #define	WiFiNavUpperUs				30000	/*  30 ms */
58 
59 enum WIFI_FRAME_TYPE {
60 	WIFI_MGT_TYPE  =	(0),
61 	WIFI_CTRL_TYPE =	(BIT(2)),
62 	WIFI_DATA_TYPE =	(BIT(3)),
63 	WIFI_QOS_DATA_TYPE	= (BIT(7)|BIT(3)),	/*  QoS Data */
64 };
65 
66 enum WIFI_FRAME_SUBTYPE {
67 	/*  below is for mgt frame */
68 	WIFI_ASSOCREQ       = (0 | WIFI_MGT_TYPE),
69 	WIFI_ASSOCRSP       = (BIT(4) | WIFI_MGT_TYPE),
70 	WIFI_REASSOCREQ     = (BIT(5) | WIFI_MGT_TYPE),
71 	WIFI_REASSOCRSP     = (BIT(5) | BIT(4) | WIFI_MGT_TYPE),
72 	WIFI_PROBEREQ       = (BIT(6) | WIFI_MGT_TYPE),
73 	WIFI_PROBERSP       = (BIT(6) | BIT(4) | WIFI_MGT_TYPE),
74 	WIFI_BEACON         = (BIT(7) | WIFI_MGT_TYPE),
75 	WIFI_ATIM           = (BIT(7) | BIT(4) | WIFI_MGT_TYPE),
76 	WIFI_DISASSOC       = (BIT(7) | BIT(5) | WIFI_MGT_TYPE),
77 	WIFI_AUTH           = (BIT(7) | BIT(5) | BIT(4) | WIFI_MGT_TYPE),
78 	WIFI_DEAUTH         = (BIT(7) | BIT(6) | WIFI_MGT_TYPE),
79 	WIFI_ACTION         = (BIT(7) | BIT(6) | BIT(4) | WIFI_MGT_TYPE),
80 
81 	/*  below is for control frame */
82 	WIFI_PSPOLL         = (BIT(7) | BIT(5) | WIFI_CTRL_TYPE),
83 	WIFI_RTS            = (BIT(7) | BIT(5) | BIT(4) | WIFI_CTRL_TYPE),
84 	WIFI_CTS            = (BIT(7) | BIT(6) | WIFI_CTRL_TYPE),
85 	WIFI_ACK            = (BIT(7) | BIT(6) | BIT(4) | WIFI_CTRL_TYPE),
86 	WIFI_CFEND          = (BIT(7) | BIT(6) | BIT(5) | WIFI_CTRL_TYPE),
87 	WIFI_CFEND_CFACK    = (BIT(7) | BIT(6) | BIT(5) | BIT(4) |
88 	WIFI_CTRL_TYPE),
89 
90 	/*  below is for data frame */
91 	WIFI_DATA           = (0 | WIFI_DATA_TYPE),
92 	WIFI_DATA_CFACK     = (BIT(4) | WIFI_DATA_TYPE),
93 	WIFI_DATA_CFPOLL    = (BIT(5) | WIFI_DATA_TYPE),
94 	WIFI_DATA_CFACKPOLL = (BIT(5) | BIT(4) | WIFI_DATA_TYPE),
95 	WIFI_DATA_NULL      = (BIT(6) | WIFI_DATA_TYPE),
96 	WIFI_CF_ACK         = (BIT(6) | BIT(4) | WIFI_DATA_TYPE),
97 	WIFI_CF_POLL        = (BIT(6) | BIT(5) | WIFI_DATA_TYPE),
98 	WIFI_CF_ACKPOLL     = (BIT(6) | BIT(5) | BIT(4) | WIFI_DATA_TYPE),
99 	WIFI_QOS_DATA_NULL	= (BIT(6) | WIFI_QOS_DATA_TYPE),
100 };
101 
102 enum WIFI_REASON_CODE	{
103 	_RSON_RESERVED_			= 0,
104 	_RSON_UNSPECIFIED_		= 1,
105 	_RSON_AUTH_NO_LONGER_VALID_	= 2,
106 	_RSON_DEAUTH_STA_LEAVING_	= 3,
107 	_RSON_INACTIVITY_		= 4,
108 	_RSON_UNABLE_HANDLE_		= 5,
109 	_RSON_CLS2_			= 6,
110 	_RSON_CLS3_			= 7,
111 	_RSON_DISAOC_STA_LEAVING_	= 8,
112 	_RSON_ASOC_NOT_AUTH_		= 9,
113 
114 	/*  WPA reason */
115 	_RSON_INVALID_IE_		= 13,
116 	_RSON_MIC_FAILURE_		= 14,
117 	_RSON_4WAY_HNDSHK_TIMEOUT_	= 15,
118 	_RSON_GROUP_KEY_UPDATE_TIMEOUT_	= 16,
119 	_RSON_DIFF_IE_			= 17,
120 	_RSON_MLTCST_CIPHER_NOT_VALID_	= 18,
121 	_RSON_UNICST_CIPHER_NOT_VALID_	= 19,
122 	_RSON_AKMP_NOT_VALID_		= 20,
123 	_RSON_UNSUPPORT_RSNE_VER_	= 21,
124 	_RSON_INVALID_RSNE_CAP_		= 22,
125 	_RSON_IEEE_802DOT1X_AUTH_FAIL_	= 23,
126 
127 	/* belowing are Realtek definition */
128 	_RSON_PMK_NOT_AVAILABLE_	= 24,
129 	_RSON_TDLS_TEAR_TOOFAR_		= 25,
130 	_RSON_TDLS_TEAR_UN_RSN_		= 26,
131 };
132 
133 /* Reason codes (IEEE 802.11-2007, 7.3.1.7, Table 7-22)
134 
135 #define WLAN_REASON_UNSPECIFIED 1
136 #define WLAN_REASON_PREV_AUTH_NOT_VALID 2
137 #define WLAN_REASON_DEAUTH_LEAVING 3
138 #define WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY 4
139 #define WLAN_REASON_DISASSOC_AP_BUSY 5
140 #define WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA 6
141 #define WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA 7
142 #define WLAN_REASON_DISASSOC_STA_HAS_LEFT 8
143 #define WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH 9 */
144 /* IEEE 802.11h */
145 #define WLAN_REASON_PWR_CAPABILITY_NOT_VALID 10
146 #define WLAN_REASON_SUPPORTED_CHANNEL_NOT_VALID 11
147 
148 /* IEEE 802.11i
149 #define WLAN_REASON_INVALID_IE 13
150 #define WLAN_REASON_MICHAEL_MIC_FAILURE 14
151 #define WLAN_REASON_4WAY_HANDSHAKE_TIMEOUT 15
152 #define WLAN_REASON_GROUP_KEY_UPDATE_TIMEOUT 16
153 #define WLAN_REASON_IE_IN_4WAY_DIFFERS 17
154 #define WLAN_REASON_GROUP_CIPHER_NOT_VALID 18
155 #define WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID 19
156 #define WLAN_REASON_AKMP_NOT_VALID 20
157 #define WLAN_REASON_UNSUPPORTED_RSN_IE_VERSION 21
158 #define WLAN_REASON_INVALID_RSN_IE_CAPAB 22
159 #define WLAN_REASON_IEEE_802_1X_AUTH_FAILED 23
160 #define WLAN_REASON_CIPHER_SUITE_REJECTED 24 */
161 
162 enum WIFI_STATUS_CODE {
163 	_STATS_SUCCESSFUL_		= 0,
164 	_STATS_FAILURE_			= 1,
165 	_STATS_CAP_FAIL_		= 10,
166 	_STATS_NO_ASOC_			= 11,
167 	_STATS_OTHER_			= 12,
168 	_STATS_NO_SUPP_ALG_		= 13,
169 	_STATS_OUT_OF_AUTH_SEQ_		= 14,
170 	_STATS_CHALLENGE_FAIL_		= 15,
171 	_STATS_AUTH_TIMEOUT_		= 16,
172 	_STATS_UNABLE_HANDLE_STA_	= 17,
173 	_STATS_RATE_FAIL_		= 18,
174 };
175 
176 /* Status codes (IEEE 802.11-2007, 7.3.1.9, Table 7-23)
177 #define WLAN_STATUS_SUCCESS 0
178 #define WLAN_STATUS_UNSPECIFIED_FAILURE 1
179 #define WLAN_STATUS_CAPS_UNSUPPORTED 10
180 #define WLAN_STATUS_REASSOC_NO_ASSOC 11
181 #define WLAN_STATUS_ASSOC_DENIED_UNSPEC 12
182 #define WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG 13
183 #define WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION 14
184 #define WLAN_STATUS_CHALLENGE_FAIL 15
185 #define WLAN_STATUS_AUTH_TIMEOUT 16
186 #define WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA 17
187 #define WLAN_STATUS_ASSOC_DENIED_RATES 18 */
188 
189 /* entended */
190 /* IEEE 802.11b */
191 #define WLAN_STATUS_ASSOC_DENIED_NOSHORT 19
192 #define WLAN_STATUS_ASSOC_DENIED_NOPBCC 20
193 #define WLAN_STATUS_ASSOC_DENIED_NOAGILITY 21
194 /* IEEE 802.11h */
195 #define WLAN_STATUS_SPEC_MGMT_REQUIRED 22
196 #define WLAN_STATUS_PWR_CAPABILITY_NOT_VALID 23
197 #define WLAN_STATUS_SUPPORTED_CHANNEL_NOT_VALID 24
198 /* IEEE 802.11g */
199 #define WLAN_STATUS_ASSOC_DENIED_NO_SHORT_SLOT_TIME 25
200 #define WLAN_STATUS_ASSOC_DENIED_NO_ER_PBCC 26
201 #define WLAN_STATUS_ASSOC_DENIED_NO_DSSS_OFDM 27
202 /* IEEE 802.11w */
203 #define WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY 30
204 #define WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION 31
205 /* IEEE 802.11i */
206 #define WLAN_STATUS_INVALID_IE 40
207 #define WLAN_STATUS_GROUP_CIPHER_NOT_VALID 41
208 #define WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID 42
209 #define WLAN_STATUS_AKMP_NOT_VALID 43
210 #define WLAN_STATUS_UNSUPPORTED_RSN_IE_VERSION 44
211 #define WLAN_STATUS_INVALID_RSN_IE_CAPAB 45
212 #define WLAN_STATUS_CIPHER_REJECTED_PER_POLICY 46
213 #define WLAN_STATUS_TS_NOT_CREATED 47
214 #define WLAN_STATUS_DIRECT_LINK_NOT_ALLOWED 48
215 #define WLAN_STATUS_DEST_STA_NOT_PRESENT 49
216 #define WLAN_STATUS_DEST_STA_NOT_QOS_STA 50
217 #define WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE 51
218 /* IEEE 802.11r */
219 #define WLAN_STATUS_INVALID_FT_ACTION_FRAME_COUNT 52
220 #define WLAN_STATUS_INVALID_PMKID 53
221 #define WLAN_STATUS_INVALID_MDIE 54
222 #define WLAN_STATUS_INVALID_FTIE 55
223 
224 enum WIFI_REG_DOMAIN {
225 	DOMAIN_FCC	= 1,
226 	DOMAIN_IC	= 2,
227 	DOMAIN_ETSI	= 3,
228 	DOMAIN_SPA	= 4,
229 	DOMAIN_FRANCE	= 5,
230 	DOMAIN_MKK	= 6,
231 	DOMAIN_ISRAEL	= 7,
232 	DOMAIN_MKK1	= 8,
233 	DOMAIN_MKK2	= 9,
234 	DOMAIN_MKK3	= 10,
235 	DOMAIN_MAX
236 };
237 
238 #define _TO_DS_		BIT(8)
239 #define _FROM_DS_	BIT(9)
240 #define _MORE_FRAG_	BIT(10)
241 #define _RETRY_		BIT(11)
242 #define _PWRMGT_	BIT(12)
243 #define _MORE_DATA_	BIT(13)
244 #define _PRIVACY_	BIT(14)
245 #define _ORDER_		BIT(15)
246 
247 #define SetToDs(pbuf)	\
248 	*(__le16 *)(pbuf) |= cpu_to_le16(_TO_DS_)
249 
250 #define GetToDs(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_TO_DS_)) != 0)
251 
252 #define ClearToDs(pbuf)	\
253 	*(__le16 *)(pbuf) &= (~cpu_to_le16(_TO_DS_))
254 
255 #define SetFrDs(pbuf)	\
256 	*(__le16 *)(pbuf) |= cpu_to_le16(_FROM_DS_)
257 
258 #define GetFrDs(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_FROM_DS_)) != 0)
259 
260 #define ClearFrDs(pbuf)	\
261 	*(__le16 *)(pbuf) &= (~cpu_to_le16(_FROM_DS_))
262 
263 #define get_tofr_ds(pframe)	((GetToDs(pframe) << 1) | GetFrDs(pframe))
264 
265 
266 #define SetMFrag(pbuf)	\
267 	*(__le16 *)(pbuf) |= cpu_to_le16(_MORE_FRAG_)
268 
269 #define GetMFrag(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_MORE_FRAG_)) != 0)
270 
271 #define ClearMFrag(pbuf)	\
272 	*(__le16 *)(pbuf) &= (~cpu_to_le16(_MORE_FRAG_))
273 
274 #define SetRetry(pbuf)	\
275 	*(__le16 *)(pbuf) |= cpu_to_le16(_RETRY_)
276 
277 #define GetRetry(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_RETRY_)) != 0)
278 
279 #define ClearRetry(pbuf)	\
280 	*(__le16 *)(pbuf) &= (~cpu_to_le16(_RETRY_))
281 
282 #define SetPwrMgt(pbuf)	\
283 	*(__le16 *)(pbuf) |= cpu_to_le16(_PWRMGT_)
284 
285 #define GetPwrMgt(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_PWRMGT_)) != 0)
286 
287 #define ClearPwrMgt(pbuf)	\
288 	*(__le16 *)(pbuf) &= (~cpu_to_le16(_PWRMGT_))
289 
290 #define SetMData(pbuf)	\
291 	*(__le16 *)(pbuf) |= cpu_to_le16(_MORE_DATA_)
292 
293 #define GetMData(pbuf)	(((*(__le16 *)(pbuf)) & cpu_to_le16(_MORE_DATA_)) != 0)
294 
295 #define ClearMData(pbuf)	\
296 	*(__le16 *)(pbuf) &= (~cpu_to_le16(_MORE_DATA_))
297 
298 #define SetPrivacy(pbuf)	\
299 	*(__le16 *)(pbuf) |= cpu_to_le16(_PRIVACY_)
300 
301 #define GetPrivacy(pbuf)					\
302 	(((*(__le16 *)(pbuf)) & cpu_to_le16(_PRIVACY_)) != 0)
303 
304 #define ClearPrivacy(pbuf)	\
305 	*(__le16 *)(pbuf) &= (~cpu_to_le16(_PRIVACY_))
306 
307 
308 #define GetOrder(pbuf)					\
309 	(((*(__le16 *)(pbuf)) & cpu_to_le16(_ORDER_)) != 0)
310 
311 #define GetFrameType(pbuf)				\
312 	(le16_to_cpu(*(__le16 *)(pbuf)) & (BIT(3) | BIT(2)))
313 
314 #define SetFrameType(pbuf, type)	\
315 	do {	\
316 		*(unsigned short *)(pbuf) &= __constant_cpu_to_le16(~(BIT(3) | BIT(2))); \
317 		*(unsigned short *)(pbuf) |= __constant_cpu_to_le16(type); \
318 	} while (0)
319 
320 #define GetFrameSubType(pbuf)	(le16_to_cpu(*(__le16 *)(pbuf)) & (BIT(7) |\
321 	 BIT(6) | BIT(5) | BIT(4) | BIT(3) | BIT(2)))
322 
323 #define SetFrameSubType(pbuf, type) \
324 	do {    \
325 		*(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(7) | BIT(6) |	\
326 		 BIT(5) | BIT(4) | BIT(3) | BIT(2))); \
327 		*(__le16 *)(pbuf) |= cpu_to_le16(type); \
328 	} while (0)
329 
330 #define GetSequence(pbuf)			\
331 	(le16_to_cpu(*(__le16 *)((size_t)(pbuf) + 22)) >> 4)
332 
333 #define GetFragNum(pbuf)			\
334 	(le16_to_cpu(*(__le16 *)((size_t)(pbuf) + 22)) & 0x0f)
335 
336 #define GetTupleCache(pbuf)			\
337 	(cpu_to_le16(*(unsigned short *)((size_t)(pbuf) + 22)))
338 
339 #define SetFragNum(pbuf, num) \
340 	do {    \
341 		*(unsigned short *)((size_t)(pbuf) + 22) = \
342 			((*(unsigned short *)((size_t)(pbuf) + 22)) &	\
343 			le16_to_cpu(~(0x000f))) | \
344 			cpu_to_le16(0x0f & (num));     \
345 	} while (0)
346 
347 #define SetSeqNum(pbuf, num) \
348 	do {    \
349 		*(__le16 *)((size_t)(pbuf) + 22) = \
350 			((*(__le16 *)((size_t)(pbuf) + 22)) & cpu_to_le16((unsigned short)0x000f)) | \
351 			cpu_to_le16((unsigned short)(0xfff0 & (num << 4))); \
352 	} while (0)
353 
354 #define SetDuration(pbuf, dur) \
355 	*(__le16 *)((size_t)(pbuf) + 2) = cpu_to_le16(0xffff & (dur))
356 
357 
358 #define SetPriority(pbuf, tid)	\
359 	*(__le16 *)(pbuf) |= cpu_to_le16(tid & 0xf)
360 
361 #define GetPriority(pbuf)	((le16_to_cpu(*(__le16 *)(pbuf))) & 0xf)
362 
363 #define SetEOSP(pbuf, eosp)	\
364 		*(__le16 *)(pbuf) |= cpu_to_le16((eosp & 1) << 4)
365 
366 #define SetAckpolicy(pbuf, ack)	\
367 	*(__le16 *)(pbuf) |= cpu_to_le16((ack & 3) << 5)
368 
369 #define GetAckpolicy(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 5) & 0x3)
370 
371 #define GetAMsdu(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 7) & 0x1)
372 
373 #define SetAMsdu(pbuf, amsdu)	\
374 	*(__le16 *)(pbuf) |= cpu_to_le16((amsdu & 1) << 7)
375 
376 #define GetAid(pbuf)	(le16_to_cpu(*(__le16 *)((size_t)(pbuf) + 2)) & 0x3fff)
377 
378 #define GetTid(pbuf)	(le16_to_cpu(*(__le16 *)((size_t)(pbuf) +	\
379 			(((GetToDs(pbuf)<<1) | GetFrDs(pbuf)) == 3 ?	\
380 			30 : 24))) & 0x000f)
381 
382 #define GetAddr1Ptr(pbuf)	((unsigned char *)((size_t)(pbuf) + 4))
383 
384 #define GetAddr2Ptr(pbuf)	((unsigned char *)((size_t)(pbuf) + 10))
385 
386 #define GetAddr3Ptr(pbuf)	((unsigned char *)((size_t)(pbuf) + 16))
387 
388 #define GetAddr4Ptr(pbuf)	((unsigned char *)((size_t)(pbuf) + 24))
389 
390 #define MacAddr_isBcst(addr) \
391 	( \
392 	((addr[0] == 0xff) && (addr[1] == 0xff) && \
393 	(addr[2] == 0xff) && (addr[3] == 0xff) && \
394 	(addr[4] == 0xff) && (addr[5] == 0xff))  ? true : false \
395 )
396 
IS_MCAST(unsigned char * da)397 static inline int IS_MCAST(unsigned char *da)
398 {
399 	if ((*da) & 0x01)
400 		return true;
401 	else
402 		return false;
403 }
404 
get_da(unsigned char * pframe)405 static inline unsigned char *get_da(unsigned char *pframe)
406 {
407 	unsigned char	*da;
408 	unsigned int to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
409 
410 	switch (to_fr_ds) {
411 	case 0x00:	/*  ToDs=0, FromDs=0 */
412 		da = GetAddr1Ptr(pframe);
413 		break;
414 	case 0x01:	/*  ToDs=0, FromDs=1 */
415 		da = GetAddr1Ptr(pframe);
416 		break;
417 	case 0x02:	/*  ToDs=1, FromDs=0 */
418 		da = GetAddr3Ptr(pframe);
419 		break;
420 	default:	/*  ToDs=1, FromDs=1 */
421 		da = GetAddr3Ptr(pframe);
422 		break;
423 	}
424 	return da;
425 }
426 
get_sa(unsigned char * pframe)427 static inline unsigned char *get_sa(unsigned char *pframe)
428 {
429 	unsigned char	*sa;
430 	unsigned int	to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
431 
432 	switch (to_fr_ds) {
433 	case 0x00:	/*  ToDs=0, FromDs=0 */
434 		sa = GetAddr2Ptr(pframe);
435 		break;
436 	case 0x01:	/*  ToDs=0, FromDs=1 */
437 		sa = GetAddr3Ptr(pframe);
438 		break;
439 	case 0x02:	/*  ToDs=1, FromDs=0 */
440 		sa = GetAddr2Ptr(pframe);
441 		break;
442 	default:	/*  ToDs=1, FromDs=1 */
443 		sa = GetAddr4Ptr(pframe);
444 		break;
445 	}
446 	return sa;
447 }
448 
get_hdr_bssid(unsigned char * pframe)449 static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
450 {
451 	unsigned char	*sa;
452 	unsigned int	to_fr_ds = (GetToDs(pframe) << 1) | GetFrDs(pframe);
453 
454 	switch (to_fr_ds) {
455 	case 0x00:	/*  ToDs=0, FromDs=0 */
456 		sa = GetAddr3Ptr(pframe);
457 		break;
458 	case 0x01:	/*  ToDs=0, FromDs=1 */
459 		sa = GetAddr2Ptr(pframe);
460 		break;
461 	case 0x02:	/*  ToDs=1, FromDs=0 */
462 		sa = GetAddr1Ptr(pframe);
463 		break;
464 	case 0x03:	/*  ToDs=1, FromDs=1 */
465 		sa = GetAddr1Ptr(pframe);
466 		break;
467 	default:
468 		sa = NULL; /*  */
469 		break;
470 	}
471 	return sa;
472 }
473 
IsFrameTypeCtrl(unsigned char * pframe)474 static inline int IsFrameTypeCtrl(unsigned char *pframe)
475 {
476 	if (WIFI_CTRL_TYPE == GetFrameType(pframe))
477 		return true;
478 	else
479 		return false;
480 }
481 /*-----------------------------------------------------------------------------
482 			Below is for the security related definition
483 ------------------------------------------------------------------------------*/
484 #define _RESERVED_FRAME_TYPE_		0
485 #define _SKB_FRAME_TYPE_		2
486 #define _PRE_ALLOCMEM_			1
487 #define _PRE_ALLOCHDR_			3
488 #define _PRE_ALLOCLLCHDR_		4
489 #define _PRE_ALLOCICVHDR_		5
490 #define _PRE_ALLOCMICHDR_		6
491 
492 #define _SIFSTIME_				\
493 	((priv->pmib->dot11BssType.net_work_type & WIRELESS_11A) ? 16 : 10)
494 #define _ACKCTSLNG_		14	/* 14 bytes long, including crclng */
495 #define _CRCLNG_		4
496 
497 #define _ASOCREQ_IE_OFFSET_	4	/*  excluding wlan_hdr */
498 #define	_ASOCRSP_IE_OFFSET_	6
499 #define _REASOCREQ_IE_OFFSET_	10
500 #define _REASOCRSP_IE_OFFSET_	6
501 #define _PROBEREQ_IE_OFFSET_	0
502 #define	_PROBERSP_IE_OFFSET_	12
503 #define _AUTH_IE_OFFSET_	6
504 #define _DEAUTH_IE_OFFSET_	0
505 #define _BEACON_IE_OFFSET_	12
506 #define _PUBLIC_ACTION_IE_OFFSET_	8
507 
508 #define _FIXED_IE_LENGTH_	_BEACON_IE_OFFSET_
509 
510 #define _SSID_IE_		0
511 #define _SUPPORTEDRATES_IE_	1
512 #define _DSSET_IE_		3
513 #define _TIM_IE_		5
514 #define _IBSS_PARA_IE_		6
515 #define _COUNTRY_IE_		7
516 #define _CHLGETXT_IE_		16
517 #define _SUPPORTED_CH_IE_	36
518 #define _CH_SWTICH_ANNOUNCE_	37	/* Secondary Channel Offset */
519 #define _RSN_IE_2_		48
520 #define _SSN_IE_1_		221
521 #define _ERPINFO_IE_		42
522 #define _EXT_SUPPORTEDRATES_IE_	50
523 
524 #define _HT_CAPABILITY_IE_	45
525 #define _FTIE_			55
526 #define _TIMEOUT_ITVL_IE_	56
527 #define _SRC_IE_		59
528 #define _HT_EXTRA_INFO_IE_	61
529 #define _HT_ADD_INFO_IE_	61 /* _HT_EXTRA_INFO_IE_ */
530 #define _WAPI_IE_		68
531 
532 
533 #define	EID_BSSCoexistence	72 /*  20/40 BSS Coexistence */
534 #define	EID_BSSIntolerantChlReport	73
535 #define _RIC_Descriptor_IE_	75
536 
537 #define _LINK_ID_IE_		101
538 #define _CH_SWITCH_TIMING_	104
539 #define _PTI_BUFFER_STATUS_	106
540 #define _EXT_CAP_IE_		127
541 #define _VENDOR_SPECIFIC_IE_	221
542 
543 #define	_RESERVED47_		47
544 
545 /* ---------------------------------------------------------------------------
546 					Below is the fixed elements...
547 -----------------------------------------------------------------------------*/
548 #define _AUTH_ALGM_NUM_		2
549 #define _AUTH_SEQ_NUM_		2
550 #define _BEACON_ITERVAL_	2
551 #define _CAPABILITY_		2
552 #define _CURRENT_APADDR_	6
553 #define _LISTEN_INTERVAL_	2
554 #define _RSON_CODE_		2
555 #define _ASOC_ID_		2
556 #define _STATUS_CODE_		2
557 #define _TIMESTAMP_		8
558 
559 #define AUTH_ODD_TO		0
560 #define AUTH_EVEN_TO		1
561 
562 #define WLAN_ETHCONV_ENCAP	1
563 #define WLAN_ETHCONV_RFC1042	2
564 #define WLAN_ETHCONV_8021h	3
565 
566 #define cap_ESS		BIT(0)
567 #define cap_IBSS	BIT(1)
568 #define cap_CFPollable	BIT(2)
569 #define cap_CFRequest	BIT(3)
570 #define cap_Privacy	BIT(4)
571 #define cap_ShortPremble BIT(5)
572 #define cap_PBCC	BIT(6)
573 #define cap_ChAgility	BIT(7)
574 #define cap_SpecMgmt	BIT(8)
575 #define cap_QoSi	BIT(9)
576 #define cap_ShortSlot	BIT(10)
577 
578 /*-----------------------------------------------------------------------------
579 				Below is the definition for 802.11i / 802.1x
580 ------------------------------------------------------------------------------*/
581 #define _IEEE8021X_MGT_			1	/*  WPA */
582 #define _IEEE8021X_PSK_			2	/*  WPA with pre-shared key */
583 
584 /*
585 #define _NO_PRIVACY_			0
586 #define _WEP_40_PRIVACY_		1
587 #define _TKIP_PRIVACY_			2
588 #define _WRAP_PRIVACY_			3
589 #define _CCMP_PRIVACY_			4
590 #define _WEP_104_PRIVACY_		5
591 #define _WEP_WPA_MIXED_PRIVACY_ 6	WEP + WPA
592 */
593 
594 /*-----------------------------------------------------------------------------
595 				Below is the definition for WMM
596 ------------------------------------------------------------------------------*/
597 #define _WMM_IE_Length_				7  /*  for WMM STA */
598 #define _WMM_Para_Element_Length_		24
599 
600 
601 /*-----------------------------------------------------------------------------
602 				Below is the definition for 802.11n
603 ------------------------------------------------------------------------------*/
604 
605 #define SetOrderBit(pbuf)	\
606 	do	{	\
607 		*(unsigned short *)(pbuf) |= cpu_to_le16(_ORDER_); \
608 	} while (0)
609 
610 #define GetOrderBit(pbuf)			\
611 	(((*(unsigned short *)(pbuf)) & le16_to_cpu(_ORDER_)) != 0)
612 
613 
614 /**
615  * struct rtw_ieee80211_bar - HT Block Ack Request
616  *
617  * This structure refers to "HT BlockAckReq" as
618  * described in 802.11n draft section 7.2.1.7.1
619  */
620 struct rtw_ieee80211_bar {
621 	unsigned short frame_control;
622 	unsigned short duration;
623 	unsigned char ra[6];
624 	unsigned char ta[6];
625 	unsigned short control;
626 	unsigned short start_seq_num;
627 } __packed;
628 
629 /* 802.11 BAR control masks */
630 #define IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL     0x0000
631 #define IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA  0x0004
632 
633  /**
634  * struct rtw_ieee80211_ht_cap - HT capabilities
635  *
636  * This structure refers to "HT capabilities element" as
637  * described in 802.11n draft section 7.3.2.52
638  */
639 
640 struct rtw_ieee80211_ht_cap {
641 	unsigned short	cap_info;
642 	unsigned char	ampdu_params_info;
643 	unsigned char	supp_mcs_set[16];
644 	unsigned short	extended_ht_cap_info;
645 	unsigned int	tx_BF_cap_info;
646 	unsigned char   antenna_selection_info;
647 } __packed;
648 
649 /**
650  * struct rtw_ieee80211_ht_cap - HT additional information
651  *
652  * This structure refers to "HT information element" as
653  * described in 802.11n draft section 7.3.2.53
654  */
655 struct ieee80211_ht_addt_info {
656 	unsigned char	control_chan;
657 	unsigned char	ht_param;
658 	unsigned short	operation_mode;
659 	unsigned short	stbc_param;
660 	unsigned char	basic_set[16];
661 } __packed;
662 
663 struct HT_caps_element {
664 	union {
665 		struct {
666 			__le16	HT_caps_info;
667 			unsigned char	AMPDU_para;
668 			unsigned char	MCS_rate[16];
669 			unsigned short	HT_ext_caps;
670 			unsigned int	Beamforming_caps;
671 			unsigned char	ASEL_caps;
672 		} HT_cap_element;
673 		unsigned char HT_cap[26];
674 	} u;
675 } __packed;
676 
677 struct HT_info_element {
678 	unsigned char	primary_channel;
679 	unsigned char	infos[5];
680 	unsigned char	MCS_rate[16];
681 } __packed;
682 
683 struct AC_param {
684 	unsigned char		ACI_AIFSN;
685 	unsigned char		CW;
686 	__le16	TXOP_limit;
687 } __packed;
688 
689 struct WMM_para_element {
690 	unsigned char		QoS_info;
691 	unsigned char		reserved;
692 	struct AC_param	ac_param[4];
693 } __packed;
694 
695 struct ADDBA_request {
696 	unsigned char	dialog_token;
697 	__le16		BA_para_set;
698 	unsigned short	BA_timeout_value;
699 	unsigned short	BA_starting_seqctrl;
700 } __packed;
701 
702 enum ht_cap_ampdu_factor {
703 	MAX_AMPDU_FACTOR_8K	= 0,
704 	MAX_AMPDU_FACTOR_16K	= 1,
705 	MAX_AMPDU_FACTOR_32K	= 2,
706 	MAX_AMPDU_FACTOR_64K	= 3,
707 };
708 
709 /* 802.11n HT capabilities masks */
710 #define IEEE80211_HT_CAP_SUP_WIDTH		0x0002
711 #define IEEE80211_HT_CAP_SM_PS			0x000C
712 #define IEEE80211_HT_CAP_GRN_FLD		0x0010
713 #define IEEE80211_HT_CAP_SGI_20			0x0020
714 #define IEEE80211_HT_CAP_SGI_40			0x0040
715 #define IEEE80211_HT_CAP_TX_STBC		0x0080
716 #define IEEE80211_HT_CAP_RX_STBC		0x0300
717 #define IEEE80211_HT_CAP_DELAY_BA		0x0400
718 #define IEEE80211_HT_CAP_MAX_AMSDU		0x0800
719 #define IEEE80211_HT_CAP_DSSSCCK40		0x1000
720 /* 802.11n HT capability AMPDU settings */
721 #define IEEE80211_HT_CAP_AMPDU_FACTOR		0x03
722 #define IEEE80211_HT_CAP_AMPDU_DENSITY		0x1C
723 /* 802.11n HT capability MSC set */
724 #define IEEE80211_SUPP_MCS_SET_UEQM		4
725 #define IEEE80211_HT_CAP_MAX_STREAMS		4
726 #define IEEE80211_SUPP_MCS_SET_LEN		10
727 /* maximum streams the spec allows */
728 #define IEEE80211_HT_CAP_MCS_TX_DEFINED		0x01
729 #define IEEE80211_HT_CAP_MCS_TX_RX_DIFF		0x02
730 #define IEEE80211_HT_CAP_MCS_TX_STREAMS		0x0C
731 #define IEEE80211_HT_CAP_MCS_TX_UEQM		0x10
732 /* 802.11n HT IE masks */
733 #define IEEE80211_HT_IE_CHA_SEC_OFFSET		0x03
734 #define IEEE80211_HT_IE_CHA_SEC_NONE		0x00
735 #define IEEE80211_HT_IE_CHA_SEC_ABOVE		0x01
736 #define IEEE80211_HT_IE_CHA_SEC_BELOW		0x03
737 #define IEEE80211_HT_IE_CHA_WIDTH		0x04
738 #define IEEE80211_HT_IE_HT_PROTECTION		0x0003
739 #define IEEE80211_HT_IE_NON_GF_STA_PRSNT	0x0004
740 #define IEEE80211_HT_IE_NON_HT_STA_PRSNT	0x0010
741 
742 /* block-ack parameters */
743 #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002
744 #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C
745 #define RTW_IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFC0
746 #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
747 #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
748 
749 /*
750  * A-PMDU buffer sizes
751  * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2)
752  */
753 #define IEEE80211_MIN_AMPDU_BUF 0x8
754 #define IEEE80211_MAX_AMPDU_BUF 0x40
755 
756 
757 /* Spatial Multiplexing Power Save Modes */
758 #define WLAN_HT_CAP_SM_PS_STATIC	0
759 #define WLAN_HT_CAP_SM_PS_DYNAMIC	1
760 #define WLAN_HT_CAP_SM_PS_INVALID	2
761 #define WLAN_HT_CAP_SM_PS_DISABLED	3
762 
763 
764 #define OP_MODE_PURE                    0
765 #define OP_MODE_MAY_BE_LEGACY_STAS      1
766 #define OP_MODE_20MHZ_HT_STA_ASSOCED    2
767 #define OP_MODE_MIXED                   3
768 
769 #define HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK	((u8) BIT(0) | BIT(1))
770 #define HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE		((u8) BIT(0))
771 #define HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW		((u8) BIT(0) | BIT(1))
772 #define HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH		((u8) BIT(2))
773 #define HT_INFO_HT_PARAM_RIFS_MODE			((u8) BIT(3))
774 #define HT_INFO_HT_PARAM_CTRL_ACCESS_ONLY		((u8) BIT(4))
775 #define HT_INFO_HT_PARAM_SRV_INTERVAL_GRANULARITY	((u8) BIT(5))
776 
777 #define HT_INFO_OPERATION_MODE_OP_MODE_MASK	\
778 		((u16) (0x0001 | 0x0002))
779 #define HT_INFO_OPERATION_MODE_OP_MODE_OFFSET		0
780 #define HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT	((u8) BIT(2))
781 #define HT_INFO_OPERATION_MODE_TRANSMIT_BURST_LIMIT	((u8) BIT(3))
782 #define HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT	((u8) BIT(4))
783 
784 #define HT_INFO_STBC_PARAM_DUAL_BEACON		((u16) BIT(6))
785 #define HT_INFO_STBC_PARAM_DUAL_STBC_PROTECT	((u16) BIT(7))
786 #define HT_INFO_STBC_PARAM_SECONDARY_BC		((u16) BIT(8))
787 #define HT_INFO_STBC_PARAM_LSIG_TXOP_PROTECT_ALLOWED	((u16) BIT(9))
788 #define HT_INFO_STBC_PARAM_PCO_ACTIVE		((u16) BIT(10))
789 #define HT_INFO_STBC_PARAM_PCO_PHASE		((u16) BIT(11))
790 
791 /*	===============WPS Section=============== */
792 /*	For WPSv1.0 */
793 #define WPSOUI					0x0050f204
794 /*	WPS attribute ID */
795 #define WPS_ATTR_VER1				0x104A
796 #define WPS_ATTR_SIMPLE_CONF_STATE		0x1044
797 #define WPS_ATTR_RESP_TYPE			0x103B
798 #define WPS_ATTR_UUID_E				0x1047
799 #define WPS_ATTR_MANUFACTURER			0x1021
800 #define WPS_ATTR_MODEL_NAME			0x1023
801 #define WPS_ATTR_MODEL_NUMBER			0x1024
802 #define WPS_ATTR_SERIAL_NUMBER			0x1042
803 #define WPS_ATTR_PRIMARY_DEV_TYPE		0x1054
804 #define WPS_ATTR_SEC_DEV_TYPE_LIST		0x1055
805 #define WPS_ATTR_DEVICE_NAME			0x1011
806 #define WPS_ATTR_CONF_METHOD			0x1008
807 #define WPS_ATTR_RF_BANDS			0x103C
808 #define WPS_ATTR_DEVICE_PWID			0x1012
809 #define WPS_ATTR_REQUEST_TYPE			0x103A
810 #define WPS_ATTR_ASSOCIATION_STATE		0x1002
811 #define WPS_ATTR_CONFIG_ERROR			0x1009
812 #define WPS_ATTR_VENDOR_EXT			0x1049
813 #define WPS_ATTR_SELECTED_REGISTRAR		0x1041
814 
815 /*	Value of WPS attribute "WPS_ATTR_DEVICE_NAME */
816 #define WPS_MAX_DEVICE_NAME_LEN			32
817 
818 /*	Value of WPS Request Type Attribute */
819 #define WPS_REQ_TYPE_ENROLLEE_INFO_ONLY		0x00
820 #define WPS_REQ_TYPE_ENROLLEE_OPEN_8021X	0x01
821 #define WPS_REQ_TYPE_REGISTRAR			0x02
822 #define WPS_REQ_TYPE_WLAN_MANAGER_REGISTRAR	0x03
823 
824 /*	Value of WPS Response Type Attribute */
825 #define WPS_RESPONSE_TYPE_INFO_ONLY	0x00
826 #define WPS_RESPONSE_TYPE_8021X		0x01
827 #define WPS_RESPONSE_TYPE_REGISTRAR	0x02
828 #define WPS_RESPONSE_TYPE_AP		0x03
829 
830 /*	Value of WPS WiFi Simple Configuration State Attribute */
831 #define WPS_WSC_STATE_NOT_CONFIG	0x01
832 #define WPS_WSC_STATE_CONFIG		0x02
833 
834 /*	Value of WPS Version Attribute */
835 #define WPS_VERSION_1			0x10
836 
837 /*	Value of WPS Configuration Method Attribute */
838 #define WPS_CONFIG_METHOD_FLASH		0x0001
839 #define WPS_CONFIG_METHOD_ETHERNET	0x0002
840 #define WPS_CONFIG_METHOD_LABEL		0x0004
841 #define WPS_CONFIG_METHOD_DISPLAY	0x0008
842 #define WPS_CONFIG_METHOD_E_NFC		0x0010
843 #define WPS_CONFIG_METHOD_I_NFC		0x0020
844 #define WPS_CONFIG_METHOD_NFC		0x0040
845 #define WPS_CONFIG_METHOD_PBC		0x0080
846 #define WPS_CONFIG_METHOD_KEYPAD	0x0100
847 #define WPS_CONFIG_METHOD_VPBC		0x0280
848 #define WPS_CONFIG_METHOD_PPBC		0x0480
849 #define WPS_CONFIG_METHOD_VDISPLAY	0x2008
850 #define WPS_CONFIG_METHOD_PDISPLAY	0x4008
851 
852 /*	Value of Category ID of WPS Primary Device Type Attribute */
853 #define WPS_PDT_CID_DISPLAYS		0x0007
854 #define WPS_PDT_CID_MULIT_MEDIA		0x0008
855 #define WPS_PDT_CID_RTK_WIDI		WPS_PDT_CID_MULIT_MEDIA
856 
857 /*	Value of Sub Category ID of WPS Primary Device Type Attribute */
858 #define WPS_PDT_SCID_MEDIA_SERVER	0x0005
859 #define WPS_PDT_SCID_RTK_DMP		WPS_PDT_SCID_MEDIA_SERVER
860 
861 /*	Value of Device Password ID */
862 #define WPS_DPID_P			0x0000
863 #define WPS_DPID_USER_SPEC		0x0001
864 #define WPS_DPID_MACHINE_SPEC		0x0002
865 #define WPS_DPID_REKEY			0x0003
866 #define WPS_DPID_PBC			0x0004
867 #define WPS_DPID_REGISTRAR_SPEC		0x0005
868 
869 /*	Value of WPS RF Bands Attribute */
870 #define WPS_RF_BANDS_2_4_GHZ		0x01
871 #define WPS_RF_BANDS_5_GHZ		0x02
872 
873 /*	Value of WPS Association State Attribute */
874 #define WPS_ASSOC_STATE_NOT_ASSOCIATED		0x00
875 #define WPS_ASSOC_STATE_CONNECTION_SUCCESS	0x01
876 #define WPS_ASSOC_STATE_CONFIGURATION_FAILURE	0x02
877 #define WPS_ASSOC_STATE_ASSOCIATION_FAILURE	0x03
878 #define WPS_ASSOC_STATE_IP_FAILURE		0x04
879 
880 /*	=====================P2P Section===================== */
881 /*	For P2P */
882 #define	P2POUI					0x506F9A09
883 
884 /*	P2P Attribute ID */
885 #define	P2P_ATTR_STATUS				0x00
886 #define	P2P_ATTR_MINOR_REASON_CODE		0x01
887 #define	P2P_ATTR_CAPABILITY			0x02
888 #define	P2P_ATTR_DEVICE_ID			0x03
889 #define	P2P_ATTR_GO_INTENT			0x04
890 #define	P2P_ATTR_CONF_TIMEOUT			0x05
891 #define	P2P_ATTR_LISTEN_CH			0x06
892 #define	P2P_ATTR_GROUP_BSSID			0x07
893 #define	P2P_ATTR_EX_LISTEN_TIMING		0x08
894 #define	P2P_ATTR_INTENTED_IF_ADDR		0x09
895 #define	P2P_ATTR_MANAGEABILITY			0x0A
896 #define	P2P_ATTR_CH_LIST			0x0B
897 #define	P2P_ATTR_NOA				0x0C
898 #define	P2P_ATTR_DEVICE_INFO			0x0D
899 #define	P2P_ATTR_GROUP_INFO			0x0E
900 #define	P2P_ATTR_GROUP_ID			0x0F
901 #define	P2P_ATTR_INTERFACE			0x10
902 #define	P2P_ATTR_OPERATING_CH			0x11
903 #define	P2P_ATTR_INVITATION_FLAGS		0x12
904 
905 /*	Value of Status Attribute */
906 #define	P2P_STATUS_SUCCESS				0x00
907 #define	P2P_STATUS_FAIL_INFO_UNAVAILABLE		0x01
908 #define	P2P_STATUS_FAIL_INCOMPATIBLE_PARAM		0x02
909 #define	P2P_STATUS_FAIL_LIMIT_REACHED			0x03
910 #define	P2P_STATUS_FAIL_INVALID_PARAM			0x04
911 #define	P2P_STATUS_FAIL_REQUEST_UNABLE			0x05
912 #define	P2P_STATUS_FAIL_PREVOUS_PROTO_ERR		0x06
913 #define	P2P_STATUS_FAIL_NO_COMMON_CH			0x07
914 #define	P2P_STATUS_FAIL_UNKNOWN_P2PGROUP		0x08
915 #define	P2P_STATUS_FAIL_BOTH_GOINTENT_15		0x09
916 #define	P2P_STATUS_FAIL_INCOMPATIBLE_PROVSION		0x0A
917 #define	P2P_STATUS_FAIL_USER_REJECT			0x0B
918 
919 /*	Value of Inviation Flags Attribute */
920 #define	P2P_INVITATION_FLAGS_PERSISTENT			BIT(0)
921 
922 #define	DMP_P2P_DEVCAP_SUPPORT	(P2P_DEVCAP_SERVICE_DISCOVERY | \
923 				P2P_DEVCAP_CLIENT_DISCOVERABILITY | \
924 				P2P_DEVCAP_CONCURRENT_OPERATION | \
925 				P2P_DEVCAP_INVITATION_PROC)
926 
927 #define	DMP_P2P_GRPCAP_SUPPORT	(P2P_GRPCAP_INTRABSS)
928 
929 /*	Value of Device Capability Bitmap */
930 #define	P2P_DEVCAP_SERVICE_DISCOVERY		BIT(0)
931 #define	P2P_DEVCAP_CLIENT_DISCOVERABILITY	BIT(1)
932 #define	P2P_DEVCAP_CONCURRENT_OPERATION		BIT(2)
933 #define	P2P_DEVCAP_INFRA_MANAGED		BIT(3)
934 #define	P2P_DEVCAP_DEVICE_LIMIT			BIT(4)
935 #define	P2P_DEVCAP_INVITATION_PROC		BIT(5)
936 
937 /*	Value of Group Capability Bitmap */
938 #define	P2P_GRPCAP_GO				BIT(0)
939 #define	P2P_GRPCAP_PERSISTENT_GROUP		BIT(1)
940 #define	P2P_GRPCAP_GROUP_LIMIT			BIT(2)
941 #define	P2P_GRPCAP_INTRABSS			BIT(3)
942 #define	P2P_GRPCAP_CROSS_CONN			BIT(4)
943 #define	P2P_GRPCAP_PERSISTENT_RECONN		BIT(5)
944 #define	P2P_GRPCAP_GROUP_FORMATION		BIT(6)
945 
946 /*	P2P Public Action Frame (Management Frame) */
947 #define	P2P_PUB_ACTION_ACTION			0x09
948 
949 /*	P2P Public Action Frame Type */
950 #define	P2P_GO_NEGO_REQ				0
951 #define	P2P_GO_NEGO_RESP			1
952 #define	P2P_GO_NEGO_CONF			2
953 #define	P2P_INVIT_REQ				3
954 #define	P2P_INVIT_RESP				4
955 #define	P2P_DEVDISC_REQ				5
956 #define	P2P_DEVDISC_RESP			6
957 #define	P2P_PROVISION_DISC_REQ			7
958 #define	P2P_PROVISION_DISC_RESP			8
959 
960 /*	P2P Action Frame Type */
961 #define	P2P_NOTICE_OF_ABSENCE			0
962 #define	P2P_PRESENCE_REQUEST			1
963 #define	P2P_PRESENCE_RESPONSE			2
964 #define	P2P_GO_DISC_REQUEST			3
965 
966 
967 #define	P2P_MAX_PERSISTENT_GROUP_NUM		10
968 
969 #define	P2P_PROVISIONING_SCAN_CNT		3
970 
971 #define	P2P_WILDCARD_SSID_LEN			7
972 
973 /* default value, used when: (1)p2p disabed or (2)p2p enabled
974  * but only do 1 scan phase */
975 #define	P2P_FINDPHASE_EX_NONE		0
976 /*  used when p2p enabled and want to do 1 scan phase and
977  *  P2P_FINDPHASE_EX_MAX-1 find phase */
978 #define	P2P_FINDPHASE_EX_FULL		1
979 #define	P2P_FINDPHASE_EX_SOCIAL_FIRST	(P2P_FINDPHASE_EX_FULL+1)
980 #define	P2P_FINDPHASE_EX_MAX		4
981 #define	P2P_FINDPHASE_EX_SOCIAL_LAST	P2P_FINDPHASE_EX_MAX
982 
983 /* 5 seconds timeout for sending the provision discovery request */
984 #define	P2P_PROVISION_TIMEOUT		5000
985 /* 3 seconds timeout for sending the prov disc request concurrent mode */
986 #define	P2P_CONCURRENT_PROVISION_TIME	3000
987 /* 5 seconds timeout for receiving the group negotiation response */
988 #define	P2P_GO_NEGO_TIMEOUT		5000
989 /* 3 seconds timeout for sending the negotiation request under concurrent mode */
990 #define	P2P_CONCURRENT_GO_NEGO_TIME	3000
991 /* 100ms */
992 #define	P2P_TX_PRESCAN_TIMEOUT		100
993 /* 5 seconds timeout for sending the invitation request */
994 #define	P2P_INVITE_TIMEOUT		5000
995 /* 3 seconds timeout for sending the invitation request under concurrent mode */
996 #define	P2P_CONCURRENT_INVITE_TIME	3000
997 /* 25 seconds timeout to reset the scan channel (based on channel plan) */
998 #define	P2P_RESET_SCAN_CH		25000
999 #define	P2P_MAX_INTENT			15
1000 
1001 #define	P2P_MAX_NOA_NUM			2
1002 
1003 /*	WPS Configuration Method */
1004 #define	WPS_CM_NONE			0x0000
1005 #define	WPS_CM_LABEL			0x0004
1006 #define	WPS_CM_DISPLYA			0x0008
1007 #define	WPS_CM_EXTERNAL_NFC_TOKEN	0x0010
1008 #define	WPS_CM_INTEGRATED_NFC_TOKEN	0x0020
1009 #define	WPS_CM_NFC_INTERFACE		0x0040
1010 #define	WPS_CM_PUSH_BUTTON		0x0080
1011 #define	WPS_CM_KEYPAD			0x0100
1012 #define	WPS_CM_SW_PUHS_BUTTON		0x0280
1013 #define	WPS_CM_HW_PUHS_BUTTON		0x0480
1014 #define	WPS_CM_SW_DISPLAY_P		0x2008
1015 #define	WPS_CM_LCD_DISPLAY_P		0x4008
1016 
1017 enum P2P_ROLE {
1018 	P2P_ROLE_DISABLE = 0,
1019 	P2P_ROLE_DEVICE = 1,
1020 	P2P_ROLE_CLIENT = 2,
1021 	P2P_ROLE_GO = 3
1022 };
1023 
1024 enum P2P_STATE {
1025 	P2P_STATE_NONE = 0,			/* P2P disable */
1026 	/* P2P had enabled and do nothing */
1027 	P2P_STATE_IDLE = 1,
1028 	P2P_STATE_LISTEN = 2,			/* In pure listen state */
1029 	P2P_STATE_SCAN = 3,			/* In scan phase */
1030 	/* In the listen state of find phase */
1031 	P2P_STATE_FIND_PHASE_LISTEN = 4,
1032 	/* In the search state of find phase */
1033 	P2P_STATE_FIND_PHASE_SEARCH = 5,
1034 	/* In P2P provisioning discovery */
1035 	P2P_STATE_TX_PROVISION_DIS_REQ = 6,
1036 	P2P_STATE_RX_PROVISION_DIS_RSP = 7,
1037 	P2P_STATE_RX_PROVISION_DIS_REQ = 8,
1038 	/* Doing the group owner negoitation handshake */
1039 	P2P_STATE_GONEGO_ING = 9,
1040 	/* finish the group negoitation handshake with success */
1041 	P2P_STATE_GONEGO_OK = 10,
1042 	/* finish the group negoitation handshake with failure */
1043 	P2P_STATE_GONEGO_FAIL = 11,
1044 	/* receiving the P2P Inviation request and match with the profile. */
1045 	P2P_STATE_RECV_INVITE_REQ_MATCH = 12,
1046 	/* Doing the P2P WPS */
1047 	P2P_STATE_PROVISIONING_ING = 13,
1048 	/* Finish the P2P WPS */
1049 	P2P_STATE_PROVISIONING_DONE = 14,
1050 	/* Transmit the P2P Invitation request */
1051 	P2P_STATE_TX_INVITE_REQ = 15,
1052 	/* Receiving the P2P Invitation response */
1053 	P2P_STATE_RX_INVITE_RESP_OK = 16,
1054 	/* receiving the P2P Inviation request and dismatch with the profile. */
1055 	P2P_STATE_RECV_INVITE_REQ_DISMATCH = 17,
1056 	/* receiving the P2P Inviation request and this wifi is GO. */
1057 	P2P_STATE_RECV_INVITE_REQ_GO = 18,
1058 	/* receiving the P2P Inviation request to join an existing P2P Group. */
1059 	P2P_STATE_RECV_INVITE_REQ_JOIN = 19,
1060 	/* recveing the P2P Inviation response with failure */
1061 	P2P_STATE_RX_INVITE_RESP_FAIL = 20,
1062 	/* receiving p2p negoitation response with information is not available */
1063 	P2P_STATE_RX_INFOR_NOREADY = 21,
1064 	/* sending p2p negoitation response with information is not available */
1065 	P2P_STATE_TX_INFOR_NOREADY = 22,
1066 };
1067 
1068 enum P2P_WPSINFO {
1069 	P2P_NO_WPSINFO				= 0,
1070 	P2P_GOT_WPSINFO_PEER_DISPLAY_PIN	= 1,
1071 	P2P_GOT_WPSINFO_SELF_DISPLAY_PIN	= 2,
1072 	P2P_GOT_WPSINFO_PBC			= 3,
1073 };
1074 
1075 #define	P2P_PRIVATE_IOCTL_SET_LEN		64
1076 
1077 enum P2P_PROTO_WK_ID {
1078 	P2P_FIND_PHASE_WK = 0,
1079 	P2P_RESTORE_STATE_WK = 1,
1080 	P2P_PRE_TX_PROVDISC_PROCESS_WK = 2,
1081 	P2P_PRE_TX_NEGOREQ_PROCESS_WK = 3,
1082 	P2P_PRE_TX_INVITEREQ_PROCESS_WK = 4,
1083 	P2P_AP_P2P_CH_SWITCH_PROCESS_WK = 5,
1084 	P2P_RO_CH_WK = 6,
1085 };
1086 
1087 enum P2P_PS_STATE {
1088 	P2P_PS_DISABLE = 0,
1089 	P2P_PS_ENABLE = 1,
1090 	P2P_PS_SCAN = 2,
1091 	P2P_PS_SCAN_DONE = 3,
1092 	P2P_PS_ALLSTASLEEP = 4, /*  for P2P GO */
1093 };
1094 
1095 enum P2P_PS_MODE {
1096 	P2P_PS_NONE = 0,
1097 	P2P_PS_CTWINDOW = 1,
1098 	P2P_PS_NOA	 = 2,
1099 	P2P_PS_MIX = 3, /*  CTWindow and NoA */
1100 };
1101 
1102 /*	=====================WFD Section===================== */
1103 /*	For Wi-Fi Display */
1104 #define	WFD_ATTR_DEVICE_INFO		0x00
1105 #define	WFD_ATTR_ASSOC_BSSID		0x01
1106 #define	WFD_ATTR_COUPLED_SINK_INFO	0x06
1107 #define	WFD_ATTR_LOCAL_IP_ADDR		0x08
1108 #define	WFD_ATTR_SESSION_INFO		0x09
1109 #define	WFD_ATTR_ALTER_MAC		0x0a
1110 
1111 /*	For WFD Device Information Attribute */
1112 #define	WFD_DEVINFO_SOURCE			0x0000
1113 #define	WFD_DEVINFO_PSINK			0x0001
1114 #define	WFD_DEVINFO_SSINK			0x0002
1115 #define	WFD_DEVINFO_DUAL			0x0003
1116 
1117 #define	WFD_DEVINFO_SESSION_AVAIL		0x0010
1118 #define	WFD_DEVINFO_WSD				0x0040
1119 #define	WFD_DEVINFO_PC_TDLS			0x0080
1120 #define	WFD_DEVINFO_HDCP_SUPPORT		0x0100
1121 
1122 #define IP_MCAST_MAC(mac)				\
1123 	((mac[0] == 0x01) && (mac[1] == 0x00) && (mac[2] == 0x5e))
1124 #define ICMPV6_MCAST_MAC(mac)				\
1125 	((mac[0] == 0x33) && (mac[1] == 0x33) && (mac[2] != 0xff))
1126 
1127 #endif /*  _WIFI_H_ */
1128