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