net: wireless: rockchip_wlan: add rtl8723bs support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bs / include / rtw_mlme_ext.h
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2011 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 __RTW_MLME_EXT_H_
21 #define __RTW_MLME_EXT_H_
22
23
24 //      Commented by Albert 20101105
25 //      Increase the SURVEY_TO value from 100 to 150  ( 100ms to 150ms )
26 //      The Realtek 8188CE SoftAP will spend around 100ms to send the probe response after receiving the probe request.
27 //      So, this driver tried to extend the dwell time for each scanning channel.
28 //      This will increase the chance to receive the probe response from SoftAP.
29
30 #define SURVEY_TO               (100)
31 #define REAUTH_TO               (300) //(50)
32 #define REASSOC_TO              (300) //(50)
33 //#define DISCONNECT_TO (3000)
34 #define ADDBA_TO                        (2000)
35
36 #define LINKED_TO (1) //unit:2 sec, 1x2=2 sec
37
38 #define REAUTH_LIMIT    (4)
39 #define REASSOC_LIMIT   (4)
40 #define READDBA_LIMIT   (2)
41
42 #ifdef CONFIG_GSPI_HCI
43         #define ROAMING_LIMIT   5
44 #else
45         #define ROAMING_LIMIT   8
46 #endif
47 //#define       IOCMD_REG0              0x10250370                      
48 //#define       IOCMD_REG1              0x10250374
49 //#define       IOCMD_REG2              0x10250378
50
51 //#define       FW_DYNAMIC_FUN_SWITCH   0x10250364
52
53 //#define       WRITE_BB_CMD            0xF0000001
54 //#define       SET_CHANNEL_CMD 0xF3000000
55 //#define       UPDATE_RA_CMD   0xFD0000A2
56
57 #define _HW_STATE_NOLINK_               0x00
58 #define _HW_STATE_ADHOC_                0x01
59 #define _HW_STATE_STATION_      0x02
60 #define _HW_STATE_AP_                   0x03
61 #define _HW_STATE_MONITOR_ 0x04
62
63
64 #define         _1M_RATE_       0
65 #define         _2M_RATE_       1
66 #define         _5M_RATE_       2
67 #define         _11M_RATE_      3
68 #define         _6M_RATE_       4
69 #define         _9M_RATE_       5
70 #define         _12M_RATE_      6
71 #define         _18M_RATE_      7
72 #define         _24M_RATE_      8
73 #define         _36M_RATE_      9
74 #define         _48M_RATE_      10
75 #define         _54M_RATE_      11
76
77 /********************************************************
78 MCS rate definitions
79 *********************************************************/
80 #define MCS_RATE_1R     (0x000000ff)
81 #define MCS_RATE_2R     (0x0000ffff)
82 #define MCS_RATE_3R     (0x00ffffff)
83 #define MCS_RATE_4R     (0xffffffff)
84 #define MCS_RATE_2R_13TO15_OFF  (0x00001fff)
85
86
87 extern unsigned char RTW_WPA_OUI[];
88 extern unsigned char WMM_OUI[];
89 extern unsigned char WPS_OUI[];
90 extern unsigned char WFD_OUI[];
91 extern unsigned char P2P_OUI[];
92
93 extern unsigned char WMM_INFO_OUI[];
94 extern unsigned char WMM_PARA_OUI[];
95
96 typedef enum _RT_CHANNEL_DOMAIN
97 {
98         /* ===== 0x00 ~ 0x1F, legacy channel plan ===== */
99         RTW_CHPLAN_FCC = 0x00,
100         RTW_CHPLAN_IC = 0x01,
101         RTW_CHPLAN_ETSI = 0x02,
102         RTW_CHPLAN_SPAIN = 0x03,
103         RTW_CHPLAN_FRANCE = 0x04,
104         RTW_CHPLAN_MKK = 0x05,
105         RTW_CHPLAN_MKK1 = 0x06,
106         RTW_CHPLAN_ISRAEL = 0x07,
107         RTW_CHPLAN_TELEC = 0x08,
108         RTW_CHPLAN_GLOBAL_DOAMIN = 0x09,
109         RTW_CHPLAN_WORLD_WIDE_13 = 0x0A,
110         RTW_CHPLAN_TAIWAN = 0x0B,
111         RTW_CHPLAN_CHINA = 0x0C,
112         RTW_CHPLAN_SINGAPORE_INDIA_MEXICO = 0x0D,
113         RTW_CHPLAN_KOREA = 0x0E,
114         RTW_CHPLAN_TURKEY = 0x0F,
115         RTW_CHPLAN_JAPAN = 0x10,
116         RTW_CHPLAN_FCC_NO_DFS = 0x11,
117         RTW_CHPLAN_JAPAN_NO_DFS = 0x12,
118         RTW_CHPLAN_WORLD_WIDE_5G = 0x13,
119         RTW_CHPLAN_TAIWAN_NO_DFS = 0x14,
120
121         /* ===== 0x20 ~ 0x7F, new channel plan ===== */
122         RTW_CHPLAN_WORLD_NULL = 0x20,
123         RTW_CHPLAN_ETSI1_NULL = 0x21,
124         RTW_CHPLAN_FCC1_NULL = 0x22,
125         RTW_CHPLAN_MKK1_NULL = 0x23,
126         RTW_CHPLAN_ETSI2_NULL = 0x24,
127         RTW_CHPLAN_FCC1_FCC1 = 0x25,
128         RTW_CHPLAN_WORLD_ETSI1 = 0x26,
129         RTW_CHPLAN_MKK1_MKK1 = 0x27,
130         RTW_CHPLAN_WORLD_KCC1 = 0x28,
131         RTW_CHPLAN_WORLD_FCC2 = 0x29,
132         RTW_CHPLAN_FCC2_NULL = 0x2A,
133         RTW_CHPLAN_WORLD_FCC3 = 0x30,
134         RTW_CHPLAN_WORLD_FCC4 = 0x31,
135         RTW_CHPLAN_WORLD_FCC5 = 0x32,
136         RTW_CHPLAN_WORLD_FCC6 = 0x33,
137         RTW_CHPLAN_FCC1_FCC7 = 0x34,
138         RTW_CHPLAN_WORLD_ETSI2 = 0x35,
139         RTW_CHPLAN_WORLD_ETSI3 = 0x36,
140         RTW_CHPLAN_MKK1_MKK2 = 0x37,
141         RTW_CHPLAN_MKK1_MKK3 = 0x38,
142         RTW_CHPLAN_FCC1_NCC1 = 0x39,
143         RTW_CHPLAN_FCC1_NCC2 = 0x40,
144         RTW_CHPLAN_GLOBAL_NULL = 0x41,
145         RTW_CHPLAN_ETSI1_ETSI4 = 0x42,
146         RTW_CHPLAN_FCC1_FCC2 = 0x43,
147         RTW_CHPLAN_FCC1_NCC3 = 0x44,
148         RTW_CHPLAN_WORLD_ETSI5 = 0x45,
149         RTW_CHPLAN_FCC1_FCC8 = 0x46,
150         RTW_CHPLAN_WORLD_ETSI6 = 0x47,
151         RTW_CHPLAN_WORLD_ETSI7 = 0x48,
152         RTW_CHPLAN_WORLD_ETSI8 = 0x49,
153         RTW_CHPLAN_WORLD_ETSI9 = 0x50,
154         RTW_CHPLAN_WORLD_ETSI10 = 0x51,
155         RTW_CHPLAN_WORLD_ETSI11 = 0x52,
156         RTW_CHPLAN_FCC1_NCC4 = 0x53,
157         RTW_CHPLAN_WORLD_ETSI12 = 0x54,
158         RTW_CHPLAN_FCC1_FCC9 = 0x55,
159         RTW_CHPLAN_WORLD_ETSI13 = 0x56,
160         RTW_CHPLAN_FCC1_FCC10 = 0x57,
161         RTW_CHPLAN_MKK2_MKK4 = 0x58,
162         RTW_CHPLAN_WORLD_ETSI14 = 0x59,
163         RTW_CHPLAN_FCC1_FCC5 = 0x60,
164
165         RTW_CHPLAN_MAX,
166         RTW_CHPLAN_REALTEK_DEFINE = 0x7F,
167 }RT_CHANNEL_DOMAIN, *PRT_CHANNEL_DOMAIN;
168
169 typedef enum _RT_CHANNEL_DOMAIN_2G
170 {
171         RTW_RD_2G_NULL = 0,
172         RTW_RD_2G_WORLD = 1,    /* Worldwird 13 */
173         RTW_RD_2G_ETSI1 = 2,    /* Europe */
174         RTW_RD_2G_FCC1 = 3,             /* US */
175         RTW_RD_2G_MKK1 = 4,             /* Japan */
176         RTW_RD_2G_ETSI2 = 5,    /* France */
177         RTW_RD_2G_GLOBAL = 6,   /* Global domain */
178         RTW_RD_2G_MKK2 = 7,             /* Japan */
179         RTW_RD_2G_FCC2 = 8,             /* US */
180
181         RTW_RD_2G_MAX,
182 }RT_CHANNEL_DOMAIN_2G, *PRT_CHANNEL_DOMAIN_2G;
183
184 typedef enum _RT_CHANNEL_DOMAIN_5G
185 {
186         RTW_RD_5G_NULL = 0,             /*      */
187         RTW_RD_5G_ETSI1 = 1,    /* Europe */
188         RTW_RD_5G_ETSI2 = 2,    /* Australia, New Zealand */
189         RTW_RD_5G_ETSI3 = 3,    /* Russia */
190         RTW_RD_5G_FCC1 = 4,             /* US */
191         RTW_RD_5G_FCC2 = 5,             /* FCC w/o DFS Channels */
192         RTW_RD_5G_FCC3 = 6,             /* Bolivia, Chile, El Salvador, Venezuela */
193         RTW_RD_5G_FCC4 = 7,             /* Venezuela */
194         RTW_RD_5G_FCC5 = 8,             /* China */
195         RTW_RD_5G_FCC6 = 9,             /*      */
196         RTW_RD_5G_FCC7 = 10,    /* US Canada(w/o Weather radar) */
197         RTW_RD_5G_KCC1 = 11,    /* Korea */
198         RTW_RD_5G_MKK1 = 12,    /* Japan */
199         RTW_RD_5G_MKK2 = 13,    /* Japan (W52, W53) */
200         RTW_RD_5G_MKK3 = 14,    /* Japan (W56) */
201         RTW_RD_5G_NCC1 = 15,    /* Taiwan, (w/o Weather radar) */
202         RTW_RD_5G_NCC2 = 16,    /* Taiwan, Band2, Band4 */
203         RTW_RD_5G_NCC3 = 17,    /* Taiwan w/o DFS, Band4 only */
204         RTW_RD_5G_ETSI4 = 18,   /* Europe w/o DFS, Band1 only */
205         RTW_RD_5G_ETSI5 = 19,   /* Australia, New Zealand(w/o Weather radar) */
206         RTW_RD_5G_FCC8 = 20,    /* Latin America */
207         RTW_RD_5G_ETSI6 = 21,   /* Israel, Bahrain, Egypt, India, China, Malaysia */
208         RTW_RD_5G_ETSI7 = 22,   /* China */
209         RTW_RD_5G_ETSI8 = 23,   /* Jordan */
210         RTW_RD_5G_ETSI9 = 24,   /* Lebanon */
211         RTW_RD_5G_ETSI10 = 25,  /* Qatar */
212         RTW_RD_5G_ETSI11 = 26,  /* Russia */
213         RTW_RD_5G_NCC4 = 27,    /* Taiwan, (w/o Weather radar) */
214         RTW_RD_5G_ETSI12 = 28,  /* Indonesia */
215         RTW_RD_5G_FCC9 = 29,    /* (w/o Weather radar) */
216         RTW_RD_5G_ETSI13 = 30,  /* (w/o Weather radar) */
217         RTW_RD_5G_FCC10 = 31,   /* Argentina(w/o Weather radar) */
218         RTW_RD_5G_MKK4 = 32,    /* Japan (W52) */
219         RTW_RD_5G_ETSI14 = 33,  /* Russia */
220
221         /* === Below are driver defined for legacy channel plan compatible, DON'T assign index ==== */
222         RTW_RD_5G_OLD_FCC1,
223         RTW_RD_5G_OLD_NCC1,
224         RTW_RD_5G_OLD_KCC1,
225
226         RTW_RD_5G_MAX,
227 }RT_CHANNEL_DOMAIN_5G, *PRT_CHANNEL_DOMAIN_5G;
228
229 bool rtw_chplan_is_empty(u8 id);
230 #define rtw_is_channel_plan_valid(chplan) (((chplan) < RTW_CHPLAN_MAX || (chplan) == RTW_CHPLAN_REALTEK_DEFINE) && !rtw_chplan_is_empty(chplan))
231 #define rtw_is_legacy_channel_plan(chplan) ((chplan) < 0x20)
232
233 typedef struct _RT_CHANNEL_PLAN
234 {
235         unsigned char   Channel[MAX_CHANNEL_NUM];
236         unsigned char   Len;
237 }RT_CHANNEL_PLAN, *PRT_CHANNEL_PLAN;
238
239 typedef struct _RT_CHANNEL_PLAN_2G
240 {
241         unsigned char   Channel[MAX_CHANNEL_NUM_2G];
242         unsigned char   Len;
243 }RT_CHANNEL_PLAN_2G, *PRT_CHANNEL_PLAN_2G;
244
245 typedef struct _RT_CHANNEL_PLAN_5G
246 {
247         unsigned char   Channel[MAX_CHANNEL_NUM_5G];
248         unsigned char   Len;
249 }RT_CHANNEL_PLAN_5G, *PRT_CHANNEL_PLAN_5G;
250
251 typedef struct _RT_CHANNEL_PLAN_MAP
252 {
253         u8 Index2G;
254         u8 Index5G;
255         u8 regd; /* value of REGULATION_TXPWR_LMT */
256 }RT_CHANNEL_PLAN_MAP, *PRT_CHANNEL_PLAN_MAP;
257
258 enum Associated_AP
259 {
260         atherosAP       = 0,
261         broadcomAP      = 1,
262         ciscoAP         = 2,
263         marvellAP       = 3,
264         ralinkAP        = 4,
265         realtekAP       = 5,
266         airgocapAP      = 6,
267         unknownAP       = 7,
268         maxAP,
269 };
270
271 typedef enum _HT_IOT_PEER
272 {
273         HT_IOT_PEER_UNKNOWN                     = 0,
274         HT_IOT_PEER_REALTEK                     = 1,
275         HT_IOT_PEER_REALTEK_92SE                = 2,
276         HT_IOT_PEER_BROADCOM            = 3,
277         HT_IOT_PEER_RALINK                      = 4,
278         HT_IOT_PEER_ATHEROS                     = 5,
279         HT_IOT_PEER_CISCO                               = 6,
280         HT_IOT_PEER_MERU                                = 7,    
281         HT_IOT_PEER_MARVELL                     = 8,
282         HT_IOT_PEER_REALTEK_SOFTAP      = 9,// peer is RealTek SOFT_AP, by Bohn, 2009.12.17
283         HT_IOT_PEER_SELF_SOFTAP                 = 10, // Self is SoftAP
284         HT_IOT_PEER_AIRGO                               = 11,
285         HT_IOT_PEER_INTEL                               = 12, 
286         HT_IOT_PEER_RTK_APCLIENT                = 13, 
287         HT_IOT_PEER_REALTEK_81XX                = 14,   
288         HT_IOT_PEER_REALTEK_WOW                 = 15,
289         HT_IOT_PEER_REALTEK_JAGUAR_BCUTAP = 16,
290         HT_IOT_PEER_REALTEK_JAGUAR_CCUTAP = 17,
291         HT_IOT_PEER_MAX                                 = 18
292 }HT_IOT_PEER_E, *PHTIOT_PEER_E;
293
294 struct mlme_handler {
295         unsigned int   num;
296         char* str;
297         unsigned int (*func)(_adapter *padapter, union recv_frame *precv_frame);
298 };
299
300 struct action_handler {
301         unsigned int   num;
302         char* str;
303         unsigned int (*func)(_adapter *padapter, union recv_frame *precv_frame);
304 };
305
306 enum SCAN_STATE
307 {
308         SCAN_DISABLE = 0,
309         SCAN_START = 1,
310         SCAN_PS_ANNC_WAIT = 2,
311         SCAN_ENTER = 3,
312         SCAN_PROCESS = 4,
313
314         /* backop */
315         SCAN_BACKING_OP = 5,
316         SCAN_BACK_OP = 6,
317         SCAN_LEAVING_OP = 7,
318         SCAN_LEAVE_OP = 8,
319
320         /* SW antenna diversity (before linked) */
321         SCAN_SW_ANTDIV_BL = 9,
322
323         /* legacy p2p */
324         SCAN_TO_P2P_LISTEN = 10, 
325         SCAN_P2P_LISTEN = 11,
326
327         SCAN_COMPLETE = 12,
328         SCAN_STATE_MAX,
329 };
330
331 const char *scan_state_str(u8 state);
332
333 enum ss_backop_flag {
334         SS_BACKOP_EN = BIT0, /* backop when linked */
335         SS_BACKOP_EN_NL = BIT1, /* backop even when no linked */
336
337         SS_BACKOP_PS_ANNC = BIT4,
338         SS_BACKOP_TX_RESUME = BIT5,
339 };
340
341 struct ss_res {
342         u8 state;
343         u8 next_state; /* will set to state on next cmd hdl */
344         int     bss_cnt;
345         int     channel_idx;
346         int     scan_mode;
347         u16 scan_ch_ms;
348         u8 rx_ampdu_accept;
349         u8 rx_ampdu_size;
350 #ifdef CONFIG_SCAN_BACKOP
351         u8 backop_flags_sta; /* policy for station mode*/
352         u8 backop_flags_ap; /* policy for ap mode */
353         u8 backop_flags; /* per backop runtime decision */
354         u8 scan_cnt;
355         u8 scan_cnt_max;
356         u32 backop_time; /* the start time of backop */
357         u16 backop_ms;
358 #endif
359 #if defined(CONFIG_ANTENNA_DIVERSITY) || defined(DBG_SCAN_SW_ANTDIV_BL)
360         u8 is_sw_antdiv_bl_scan;
361 #endif
362         u8 ssid_num;
363         u8 ch_num;
364         NDIS_802_11_SSID ssid[RTW_SSID_SCAN_AMOUNT];
365         struct rtw_ieee80211_channel ch[RTW_CHANNEL_SCAN_AMOUNT];
366 };
367
368 //#define AP_MODE                               0x0C
369 //#define STATION_MODE  0x08
370 //#define AD_HOC_MODE           0x04
371 //#define NO_LINK_MODE  0x00
372
373 #define         WIFI_FW_NULL_STATE                      _HW_STATE_NOLINK_
374 #define WIFI_FW_STATION_STATE           _HW_STATE_STATION_
375 #define WIFI_FW_AP_STATE                                _HW_STATE_AP_
376 #define WIFI_FW_ADHOC_STATE                     _HW_STATE_ADHOC_
377
378 #define WIFI_FW_AUTH_NULL                       0x00000100
379 #define WIFI_FW_AUTH_STATE                      0x00000200
380 #define WIFI_FW_AUTH_SUCCESS                    0x00000400
381
382 #define WIFI_FW_ASSOC_STATE                     0x00002000
383 #define WIFI_FW_ASSOC_SUCCESS           0x00004000
384
385 #define WIFI_FW_LINKING_STATE           (WIFI_FW_AUTH_NULL | WIFI_FW_AUTH_STATE | WIFI_FW_AUTH_SUCCESS |WIFI_FW_ASSOC_STATE)
386
387 #ifdef CONFIG_TDLS
388 enum TDLS_option
389 {
390         TDLS_ESTABLISHED = 1,
391         TDLS_ISSUE_PTI,
392         TDLS_CH_SW_RESP,
393         TDLS_CH_SW_PREPARE,
394         TDLS_CH_SW_START,
395         TDLS_CH_SW_TO_OFF_CHNL,
396         TDLS_CH_SW_TO_BASE_CHNL_UNSOLICITED,
397         TDLS_CH_SW_TO_BASE_CHNL,
398         TDLS_CH_SW_END_TO_BASE_CHNL,
399         TDLS_CH_SW_END,
400         TDLS_RS_RCR,
401         TDLS_TEARDOWN_STA,
402         TDLS_TEARDOWN_STA_LOCALLY,
403         maxTDLS,
404 };
405
406 #endif //CONFIG_TDLS
407
408 /*
409  * Usage:
410  * When one iface acted as AP mode and the other iface is STA mode and scanning, 
411  * it should switch back to AP's operating channel periodically.
412  * Parameters info:
413  * When the driver scanned RTW_SCAN_NUM_OF_CH channels, it would switch back to AP's operating channel for
414  * RTW_BACK_OP_CH_MS milliseconds.
415  * Example:
416  * For chip supports 2.4G + 5GHz and AP mode is operating in channel 1, 
417  * RTW_SCAN_NUM_OF_CH is 8, RTW_BACK_OP_CH_MS is 300
418  * When it's STA mode gets set_scan command, 
419  * it would 
420  * 1. Doing the scan on channel 1.2.3.4.5.6.7.8 
421  * 2. Back to channel 1 for 300 milliseconds
422  * 3. Go through doing site survey on channel 9.10.11.36.40.44.48.52
423  * 4. Back to channel 1 for 300 milliseconds
424  * 5. ... and so on, till survey done.
425  */
426 #if defined(CONFIG_ATMEL_RC_PATCH)
427 #define RTW_SCAN_NUM_OF_CH 2
428 #define RTW_BACK_OP_CH_MS 200
429 #else
430 #define RTW_SCAN_NUM_OF_CH 3
431 #define RTW_BACK_OP_CH_MS 400
432 #endif
433
434 struct mlme_ext_info
435 {
436         u32     state;
437         u32     reauth_count;
438         u32     reassoc_count;
439         u32     link_count;
440         u32     auth_seq;
441         u32     auth_algo;      // 802.11 auth, could be open, shared, auto
442         u32     authModeToggle;
443         u32     enc_algo;//encrypt algorithm;
444         u32     key_index;      // this is only valid for legendary wep, 0~3 for key id.
445         u32     iv;
446         u8      chg_txt[128];
447         u16     aid;
448         u16     bcn_interval;
449         u16     capability;
450         u8      assoc_AP_vendor;
451         u8      slotTime;
452         u8      preamble_mode;
453         u8      WMM_enable;
454         u8      ERP_enable;
455         u8      ERP_IE;
456         u8      HT_enable;
457         u8      HT_caps_enable; 
458         u8      HT_info_enable;
459         u8      HT_protection;
460         u8      turboMode_cts2self;
461         u8      turboMode_rtsen;
462         u8      SM_PS;
463         u8      agg_enable_bitmap;
464         u8      ADDBA_retry_count;
465         u8      candidate_tid_bitmap;
466         u8      dialogToken;
467         // Accept ADDBA Request
468         BOOLEAN bAcceptAddbaReq;
469         u8      bwmode_updated;
470         u8      hidden_ssid_mode;
471         u8      VHT_enable;
472
473         struct ADDBA_request            ADDBA_req;
474         struct WMM_para_element WMM_param;
475         struct HT_caps_element  HT_caps;
476         struct HT_info_element          HT_info;
477         WLAN_BSSID_EX                   network;//join network or bss_network, if in ap mode, it is the same to cur_network.network
478 };
479
480 // The channel information about this channel including joining, scanning, and power constraints.
481 typedef struct _RT_CHANNEL_INFO
482 {
483         u8                              ChannelNum;             // The channel number.
484         RT_SCAN_TYPE    ScanType;               // Scan type such as passive or active scan.
485         //u16                           ScanPeriod;             // Listen time in millisecond in this channel.
486         //s32                           MaxTxPwrDbm;    // Max allowed tx power.
487         //u32                           ExInfo;                 // Extended Information for this channel.
488 #ifdef CONFIG_FIND_BEST_CHANNEL
489         u32                             rx_count;
490 #endif
491 #ifdef CONFIG_DFS_MASTER
492         u32 non_ocp_end_time;
493 #endif
494 }RT_CHANNEL_INFO, *PRT_CHANNEL_INFO;
495
496 #define DFS_MASTER_TIMER_MS 100
497 #define CAC_TIME_MS (60*1000)
498 #define CAC_TIME_CE_MS (10*60*1000)
499 #define NON_OCP_TIME_MS (30*60*1000)
500
501 #ifdef CONFIG_DFS_MASTER
502 struct rf_ctl_t;
503 #define CH_IS_NON_OCP(rt_ch_info) (time_after((unsigned long)(rt_ch_info)->non_ocp_end_time, (unsigned long)rtw_get_current_time()))
504 void rtw_rfctl_reset_cac(struct rf_ctl_t *rfctl);
505 bool rtw_is_cac_reset_needed(_adapter *adapter);
506 bool _rtw_rfctl_overlap_radar_detect_ch(struct rf_ctl_t *rfctl, u8 ch, u8 bw, u8 offset);
507 bool rtw_rfctl_overlap_radar_detect_ch(struct rf_ctl_t *rfctl);
508 bool rtw_rfctl_is_tx_blocked_by_cac(struct rf_ctl_t *rfctl);
509 bool rtw_chset_is_ch_non_ocp(RT_CHANNEL_INFO *ch_set, u8 ch, u8 bw, u8 offset);
510 void rtw_chset_update_non_ocp(RT_CHANNEL_INFO *ch_set, u8 ch, u8 bw, u8 offset);
511 void rtw_chset_update_non_ocp_ms(RT_CHANNEL_INFO *ch_set, u8 ch, u8 bw, u8 offset, int ms);
512 #else
513 #define CH_IS_NON_OCP(rt_ch_info) 0
514 #define rtw_chset_is_ch_non_ocp(ch_set, ch, bw, offset) _FALSE
515 #define rtw_rfctl_is_tx_blocked_by_cac(rfctl) _FALSE
516 #endif
517
518 enum {
519         RTW_CHF_2G = BIT0,
520         RTW_CHF_5G = BIT1,
521         RTW_CHF_DFS = BIT2,
522         RTW_CHF_LONG_CAC = BIT3,
523         RTW_CHF_NON_DFS = BIT4,
524         RTW_CHF_NON_LONG_CAC = BIT5,
525 };
526 bool rtw_choose_available_chbw(_adapter *adapter, u8 req_bw, u8 *dec_ch, u8 *dec_bw, u8 *dec_offset, u8 d_flags);
527 void dump_country_chplan(void *sel, const struct country_chplan *ent);
528 void dump_country_chplan_map(void *sel);
529 void dump_chplan_id_list(void *sel);
530 void dump_chplan_test(void *sel);
531 void dump_chset(void *sel, RT_CHANNEL_INFO *ch_set);
532 void dump_cur_chset(void *sel, _adapter *adapter);
533
534 int rtw_ch_set_search_ch(RT_CHANNEL_INFO *ch_set, const u32 ch);
535 bool rtw_mlme_band_check(_adapter *adapter, const u32 ch);
536
537 // P2P_MAX_REG_CLASSES - Maximum number of regulatory classes
538 #define P2P_MAX_REG_CLASSES 10
539
540 // P2P_MAX_REG_CLASS_CHANNELS - Maximum number of channels per regulatory class
541 #define P2P_MAX_REG_CLASS_CHANNELS 20
542
543 //  struct p2p_channels - List of supported channels
544 struct p2p_channels {
545         // struct p2p_reg_class - Supported regulatory class
546         struct p2p_reg_class {
547                 // reg_class - Regulatory class (IEEE 802.11-2007, Annex J)
548                 u8 reg_class;
549
550                 // channel - Supported channels
551                 u8 channel[P2P_MAX_REG_CLASS_CHANNELS];
552
553                 // channels - Number of channel entries in use
554                 size_t channels;
555         } reg_class[P2P_MAX_REG_CLASSES];
556
557         // reg_classes - Number of reg_class entries in use
558         size_t reg_classes;
559 };
560
561 struct p2p_oper_class_map {
562         enum hw_mode {IEEE80211G,IEEE80211A} mode;
563         u8 op_class;
564         u8 min_chan;
565         u8 max_chan;
566         u8 inc;
567         enum { BW20, BW40PLUS, BW40MINUS } bw;
568 };
569
570 struct mlme_ext_priv
571 {
572         _adapter        *padapter;
573         u8      mlmeext_init;
574         ATOMIC_T                event_seq;
575         u16     mgnt_seq;
576 #ifdef CONFIG_IEEE80211W
577         u16     sa_query_seq;
578         u64 mgnt_80211w_IPN;
579         u64 mgnt_80211w_IPN_rx;
580 #endif //CONFIG_IEEE80211W
581         //struct fw_priv        fwpriv;
582         
583         unsigned char   cur_channel;
584         unsigned char   cur_bwmode;
585         unsigned char   cur_ch_offset;//PRIME_CHNL_OFFSET
586         unsigned char   cur_wireless_mode;      // NETWORK_TYPE
587         
588         unsigned char   max_chan_nums;
589         RT_CHANNEL_INFO         channel_set[MAX_CHANNEL_NUM];
590         struct p2p_channels channel_list;
591         unsigned char   basicrate[NumRates];
592         unsigned char   datarate[NumRates];
593 #ifdef CONFIG_80211N_HT
594         unsigned char default_supported_mcs_set[16];
595 #endif
596         
597         struct ss_res           sitesurvey_res;         
598         struct mlme_ext_info    mlmext_info;//for sta/adhoc mode, including current scanning/connecting/connected related info.
599                                                      //for ap mode, network includes ap's cap_info
600         _timer          survey_timer;
601         _timer          link_timer;
602
603         //_timer                ADDBA_timer;
604         u32 last_scan_time;
605         u8      scan_abort;
606         u8      tx_rate; // TXRATE when USERATE is set.
607
608         u32     retry; //retry for issue probereq
609         
610         u64 TSFValue;
611
612         //for LPS-32K to adaptive bcn early and timeout
613         u8 adaptive_tsf_done;
614         u32 bcn_delay_cnt[9];
615         u32 bcn_delay_ratio[9];
616         u32 bcn_cnt;
617         u8 DrvBcnEarly;
618         u8 DrvBcnTimeOut;
619
620 #ifdef CONFIG_AP_MODE   
621         unsigned char bstart_bss;
622 #endif
623
624 #ifdef CONFIG_80211D
625         u8 update_channel_plan_by_ap_done;
626 #endif
627         //recv_decache check for Action_public frame 
628         u8 action_public_dialog_token;
629         u16      action_public_rxseq;
630
631 //#ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
632         u8 active_keep_alive_check;
633 //#endif
634 #ifdef DBG_FIXED_CHAN
635         u8 fixed_chan;
636 #endif
637         /* set hw sync bcn tsf register or not */
638         u8 en_hw_update_tsf;
639 };
640
641 #define mlmeext_msr(mlmeext) ((mlmeext)->mlmext_info.state & 0x03)
642 #define mlmeext_scan_state(mlmeext) ((mlmeext)->sitesurvey_res.state)
643 #define mlmeext_scan_state_str(mlmeext) scan_state_str((mlmeext)->sitesurvey_res.state)
644 #define mlmeext_chk_scan_state(mlmeext, _state) ((mlmeext)->sitesurvey_res.state == (_state))
645 #define mlmeext_set_scan_state(mlmeext, _state) \
646         do { \
647                 ((mlmeext)->sitesurvey_res.state = (_state)); \
648                 ((mlmeext)->sitesurvey_res.next_state = (_state)); \
649                 /* DBG_871X("set_scan_state:%s\n", scan_state_str(_state)); */ \
650         } while (0)
651
652 #define mlmeext_scan_next_state(mlmeext) ((mlmeext)->sitesurvey_res.next_state)
653 #define mlmeext_set_scan_next_state(mlmeext, _state) \
654         do { \
655                 ((mlmeext)->sitesurvey_res.next_state = (_state)); \
656                 /* DBG_871X("set_scan_next_state:%s\n", scan_state_str(_state)); */ \
657         } while (0)
658
659 #ifdef CONFIG_SCAN_BACKOP
660 #define mlmeext_scan_backop_flags(mlmeext) ((mlmeext)->sitesurvey_res.backop_flags)
661 #define mlmeext_chk_scan_backop_flags(mlmeext, flags) ((mlmeext)->sitesurvey_res.backop_flags & (flags))
662 #define mlmeext_assign_scan_backop_flags(mlmeext, flags) \
663                 do { \
664                         ((mlmeext)->sitesurvey_res.backop_flags = (flags)); \
665                         DBG_871X("assign_scan_backop_flags:0x%02x\n", (mlmeext)->sitesurvey_res.backop_flags); \
666                 } while (0)
667
668 #define mlmeext_scan_backop_flags_sta(mlmeext) ((mlmeext)->sitesurvey_res.backop_flags_sta)
669 #define mlmeext_chk_scan_backop_flags_sta(mlmeext, flags) ((mlmeext)->sitesurvey_res.backop_flags_sta & (flags))
670 #define mlmeext_assign_scan_backop_flags_sta(mlmeext, flags) \
671         do { \
672                 ((mlmeext)->sitesurvey_res.backop_flags_sta = (flags)); \
673         } while (0)
674
675 #define mlmeext_scan_backop_flags_ap(mlmeext) ((mlmeext)->sitesurvey_res.backop_flags_ap)
676 #define mlmeext_chk_scan_backop_flags_ap(mlmeext, flags) ((mlmeext)->sitesurvey_res.backop_flags_ap & (flags))
677 #define mlmeext_assign_scan_backop_flags_ap(mlmeext, flags) \
678         do { \
679                 ((mlmeext)->sitesurvey_res.backop_flags_ap = (flags)); \
680         } while (0)
681 #else
682 #define mlmeext_scan_backop_flags(mlmeext) (0)
683 #define mlmeext_chk_scan_backop_flags(mlmeext, flags) (0)
684 #define mlmeext_assign_scan_backop_flags(mlmeext, flags) do {} while (0)
685
686 #define mlmeext_scan_backop_flags_sta(mlmeext) (0)
687 #define mlmeext_chk_scan_backop_flags_sta(mlmeext, flags) (0)
688 #define mlmeext_assign_scan_backop_flags_sta(mlmeext, flags) do {} while (0)
689
690 #define mlmeext_scan_backop_flags_ap(mlmeext) (0)
691 #define mlmeext_chk_scan_backop_flags_ap(mlmeext, flags) (0)
692 #define mlmeext_assign_scan_backop_flags_ap(mlmeext, flags) do {} while (0)
693 #endif
694
695 void init_mlme_default_rate_set(_adapter* padapter);
696 int init_mlme_ext_priv(_adapter* padapter);
697 int init_hw_mlme_ext(_adapter *padapter);
698 void free_mlme_ext_priv (struct mlme_ext_priv *pmlmeext);
699 extern void init_mlme_ext_timer(_adapter *padapter);
700 extern void init_addba_retry_timer(_adapter *padapter, struct sta_info *psta);
701 extern struct xmit_frame *alloc_mgtxmitframe(struct xmit_priv *pxmitpriv);
702 struct xmit_frame *alloc_mgtxmitframe_once(struct xmit_priv *pxmitpriv);
703
704 //void fill_fwpriv(_adapter * padapter, struct fw_priv *pfwpriv);
705
706 unsigned char networktype_to_raid(_adapter *adapter,struct sta_info *psta);
707 unsigned char networktype_to_raid_ex(_adapter *adapter, struct sta_info *psta);
708
709 u8 judge_network_type(_adapter *padapter, unsigned char *rate, int ratelen);
710 void get_rate_set(_adapter *padapter, unsigned char *pbssrate, int *bssrate_len);
711 void set_mcs_rate_by_mask(u8 *mcs_set, u32 mask);
712 void UpdateBrateTbl(_adapter *padapter,u8 *mBratesOS);
713 void UpdateBrateTblForSoftAP(u8 *bssrateset, u32 bssratelen);
714 void change_band_update_ie(_adapter *padapter, WLAN_BSSID_EX *pnetwork, u8 ch);
715
716 //void Set_NETYPE1_MSR(_adapter *padapter, u8 type);
717 //void Set_NETYPE0_MSR(_adapter *padapter, u8 type);
718 void Set_MSR(_adapter *padapter, u8 type);
719
720 u8 rtw_get_oper_ch(_adapter *adapter);
721 void rtw_set_oper_ch(_adapter *adapter, u8 ch);
722 u8 rtw_get_oper_bw(_adapter *adapter);
723 void rtw_set_oper_bw(_adapter *adapter, u8 bw);
724 u8 rtw_get_oper_choffset(_adapter *adapter);
725 void rtw_set_oper_choffset(_adapter *adapter, u8 offset);
726 u8      rtw_get_center_ch(u8 channel, u8 chnl_bw, u8 chnl_offset);
727 u32 rtw_get_on_oper_ch_time(_adapter *adapter);
728 u32 rtw_get_on_cur_ch_time(_adapter *adapter);
729
730 u8 rtw_get_offset_by_ch(u8 channel);
731
732 void set_channel_bwmode(_adapter *padapter, unsigned char channel, unsigned char channel_offset, unsigned short bwmode);
733 void SelectChannel(_adapter *padapter, unsigned char channel);
734 void SetBWMode(_adapter *padapter, unsigned short bwmode, unsigned char channel_offset);
735
736 unsigned int decide_wait_for_beacon_timeout(unsigned int bcn_interval);
737
738 void _clear_cam_entry(_adapter *padapter, u8 entry);
739 void write_cam_from_cache(_adapter *adapter, u8 id);
740
741 /* modify both HW and cache */
742 void write_cam(_adapter *padapter, u8 id, u16 ctrl, u8 *mac, u8 *key);
743 void clear_cam_entry(_adapter *padapter, u8 id);
744
745 /* modify cache only */
746 void write_cam_cache(_adapter *adapter, u8 id, u16 ctrl, u8 *mac, u8 *key);
747 void clear_cam_cache(_adapter *adapter, u8 id);
748
749 void invalidate_cam_all(_adapter *padapter);
750 void CAM_empty_entry(PADAPTER Adapter, u8 ucIndex);
751
752 void flush_all_cam_entry(_adapter *padapter);
753
754 BOOLEAN IsLegal5GChannel(PADAPTER Adapter, u8 channel);
755
756 void site_survey(_adapter *padapter, u8 survey_channel, RT_SCAN_TYPE ScanType);
757 u8 collect_bss_info(_adapter *padapter, union recv_frame *precv_frame, WLAN_BSSID_EX *bssid);
758 void update_network(WLAN_BSSID_EX *dst, WLAN_BSSID_EX *src, _adapter * padapter, bool update_ie);
759
760 int get_bsstype(unsigned short capability);
761 u8* get_my_bssid(WLAN_BSSID_EX *pnetwork);
762 u16 get_beacon_interval(WLAN_BSSID_EX *bss);
763
764 int is_client_associated_to_ap(_adapter *padapter);
765 int is_client_associated_to_ibss(_adapter *padapter);
766 int is_IBSS_empty(_adapter *padapter);
767
768 unsigned char check_assoc_AP(u8 *pframe, uint len);
769
770 int WMM_param_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs     pIE);
771 #ifdef CONFIG_WFD
772 void rtw_process_wfd_ie(_adapter *adapter, u8 *ie, u8 ie_len, const char *tag);
773 void rtw_process_wfd_ies(_adapter *adapter, u8 *ies, u8 ies_len, const char *tag);
774 #endif
775 void WMMOnAssocRsp(_adapter *padapter);
776
777 void HT_caps_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE);
778 void HT_info_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE);
779 void HTOnAssocRsp(_adapter *padapter);
780
781 void ERP_IE_handler(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE);
782 void VCS_update(_adapter *padapter, struct sta_info *psta);
783 void    update_ldpc_stbc_cap(struct sta_info *psta);
784
785 int rtw_get_bcn_keys(ADAPTER *Adapter, u8 *pframe, u32 packet_len,
786                 struct beacon_keys *recv_beacon);
787 void rtw_dump_bcn_keys(struct beacon_keys *recv_beacon);
788 int rtw_check_bcn_info(ADAPTER *Adapter, u8 *pframe, u32 packet_len);
789 void update_beacon_info(_adapter *padapter, u8 *pframe, uint len, struct sta_info *psta);
790 #ifdef CONFIG_DFS
791 void process_csa_ie(_adapter *padapter, u8 *pframe, uint len);
792 #endif //CONFIG_DFS
793 void update_capinfo(PADAPTER Adapter, u16 updateCap);
794 void update_wireless_mode(_adapter * padapter);
795 void update_tx_basic_rate(_adapter *padapter, u8 modulation);
796 void update_sta_basic_rate(struct sta_info *psta, u8 wireless_mode);
797 int rtw_ies_get_supported_rate(u8 *ies, uint ies_len, u8 *rate_set, u8 *rate_num);
798
799 //for sta/adhoc mode
800 void update_sta_info(_adapter *padapter, struct sta_info *psta);
801 unsigned int update_basic_rate(unsigned char *ptn, unsigned int ptn_sz);
802 unsigned int update_supported_rate(unsigned char *ptn, unsigned int ptn_sz);
803 unsigned int update_MCS_rate(struct HT_caps_element *pHT_caps);
804 void Update_RA_Entry(_adapter *padapter, struct sta_info *psta);
805 void set_sta_rate(_adapter *padapter, struct sta_info *psta);
806
807 unsigned int receive_disconnect(_adapter *padapter, unsigned char *MacAddr, unsigned short reason, u8 locally_generated);
808
809 unsigned char get_highest_rate_idx(u32 mask);
810 int support_short_GI(_adapter *padapter, struct HT_caps_element *pHT_caps, u8 bwmode);
811 unsigned int is_ap_in_tkip(_adapter *padapter);
812 unsigned int is_ap_in_wep(_adapter *padapter);
813 unsigned int should_forbid_n_rate(_adapter * padapter);
814
815 s16 rtw_get_camid(_adapter *adapter, struct sta_info* sta, s16 kid);
816 bool _rtw_camctl_chk_cap(_adapter *adapter, u8 cap);
817 void _rtw_camctl_set_flags(_adapter *adapter, u32 flags);
818 void rtw_camctl_set_flags(_adapter *adapter, u32 flags);
819 void _rtw_camctl_clr_flags(_adapter *adapter, u32 flags);
820 void rtw_camctl_clr_flags(_adapter *adapter, u32 flags);
821 bool _rtw_camctl_chk_flags(_adapter *adapter, u32 flags);
822
823 struct sec_cam_bmp;
824 void dump_sec_cam_map(void *sel, struct sec_cam_bmp *map, u8 max_num);
825 void rtw_sec_cam_map_clr_all(struct sec_cam_bmp *map);
826
827 bool _rtw_camid_is_gk(_adapter *adapter, u8 cam_id);
828 bool rtw_camid_is_gk(_adapter *adapter, u8 cam_id);
829 s16 rtw_camid_search(_adapter *adapter, u8 *addr, s16 kid, s8 gk);
830 s16 rtw_camid_alloc(_adapter *adapter, struct sta_info *sta, u8 kid, bool *used);
831 void rtw_camid_free(_adapter *adapter, u8 cam_id);
832
833 struct macid_bmp;
834 struct macid_ctl_t;
835 void dump_macid_map(void *sel, struct macid_bmp *map, u8 max_num);
836 bool rtw_macid_is_set(struct macid_bmp *map, u8 id);
837 bool rtw_macid_is_used(struct macid_ctl_t *macid_ctl, u8 id);
838 bool rtw_macid_is_bmc(struct macid_ctl_t *macid_ctl, u8 id);
839 s8 rtw_macid_get_if_g(struct macid_ctl_t *macid_ctl, u8 id);
840 s8 rtw_macid_get_ch_g(struct macid_ctl_t *macid_ctl, u8 id);
841 void rtw_alloc_macid(_adapter *padapter, struct sta_info *psta);
842 void rtw_release_macid(_adapter *padapter, struct sta_info *psta);
843 u8 rtw_search_max_mac_id(_adapter *padapter);
844 void rtw_macid_ctl_set_h2c_msr(struct macid_ctl_t *macid_ctl, u8 id, u8 h2c_msr);
845 void rtw_macid_ctl_init(struct macid_ctl_t *macid_ctl);
846 void rtw_macid_ctl_deinit(struct macid_ctl_t *macid_ctl);
847
848 void report_join_res(_adapter *padapter, int res);
849 void report_survey_event(_adapter *padapter, union recv_frame *precv_frame);
850 void report_surveydone_event(_adapter *padapter);
851 void report_del_sta_event(_adapter *padapter, unsigned char *MacAddr, unsigned short reason, bool enqueue, u8 locally_generated);
852 void report_add_sta_event(_adapter *padapter, unsigned char *MacAddr);
853 bool rtw_port_switch_chk(_adapter *adapter);
854 void report_wmm_edca_update(_adapter *padapter);
855
856 void beacon_timing_control(_adapter *padapter);
857 u8 chk_bmc_sleepq_cmd(_adapter* padapter);
858 extern u8 set_tx_beacon_cmd(_adapter*padapter);
859 unsigned int setup_beacon_frame(_adapter *padapter, unsigned char *beacon_frame);
860 void update_mgnt_tx_rate(_adapter *padapter, u8 rate);
861 void update_monitor_frame_attrib(_adapter *padapter, struct pkt_attrib *pattrib);
862 void update_mgntframe_attrib(_adapter *padapter, struct pkt_attrib *pattrib);
863 void update_mgntframe_attrib_addr(_adapter *padapter, struct xmit_frame *pmgntframe);
864 void dump_mgntframe(_adapter *padapter, struct xmit_frame *pmgntframe);
865 s32 dump_mgntframe_and_wait(_adapter *padapter, struct xmit_frame *pmgntframe, int timeout_ms);
866 s32 dump_mgntframe_and_wait_ack(_adapter *padapter, struct xmit_frame *pmgntframe);
867 s32 dump_mgntframe_and_wait_ack_timeout(_adapter *padapter, struct xmit_frame *pmgntframe, int timeout_ms);
868
869 #ifdef CONFIG_P2P
870 void issue_probersp_p2p(_adapter *padapter, unsigned char *da);
871 void issue_p2p_provision_request( _adapter *padapter, u8* pssid, u8 ussidlen, u8* pdev_raddr);
872 void issue_p2p_GO_request(_adapter *padapter, u8* raddr);
873 void issue_probereq_p2p(_adapter *padapter, u8 *da);
874 int issue_probereq_p2p_ex(_adapter *adapter, u8 *da, int try_cnt, int wait_ms);
875 void issue_p2p_invitation_response(_adapter *padapter, u8* raddr, u8 dialogToken, u8 success);
876 void issue_p2p_invitation_request(_adapter *padapter, u8* raddr );
877 #endif //CONFIG_P2P
878 void issue_beacon(_adapter *padapter, int timeout_ms);
879 void issue_probersp(_adapter *padapter, unsigned char *da, u8 is_valid_p2p_probereq);
880 void issue_assocreq(_adapter *padapter);
881 void issue_asocrsp(_adapter *padapter, unsigned short status, struct sta_info *pstat, int pkt_type);
882 void issue_auth(_adapter *padapter, struct sta_info *psta, unsigned short status);
883 void issue_probereq(_adapter *padapter, NDIS_802_11_SSID *pssid, u8 *da);
884 s32 issue_probereq_ex(_adapter *padapter, NDIS_802_11_SSID *pssid, u8* da, u8 ch, bool append_wps, int try_cnt, int wait_ms);
885 int issue_nulldata(_adapter *padapter, unsigned char *da, unsigned int power_mode, int try_cnt, int wait_ms);
886 s32 issue_nulldata_in_interrupt(PADAPTER padapter, u8 *da, unsigned int power_mode);
887 int issue_qos_nulldata(_adapter *padapter, unsigned char *da, u16 tid, int try_cnt, int wait_ms);
888 int issue_deauth(_adapter *padapter, unsigned char *da, unsigned short reason);
889 int issue_deauth_ex(_adapter *padapter, u8 *da, unsigned short reason, int try_cnt, int wait_ms);
890 void issue_action_spct_ch_switch(_adapter *padapter, u8 *ra, u8 new_ch, u8 ch_offset);
891 void issue_addba_req(_adapter *adapter, unsigned char *ra, u8 tid);
892 void issue_addba_rsp(_adapter *adapter, unsigned char *ra, u8 tid, u16 status, u8 size);
893 u8 issue_addba_rsp_wait_ack(_adapter *adapter, unsigned char *ra, u8 tid, u16 status, u8 size, int try_cnt, int wait_ms);
894 void issue_del_ba(_adapter *adapter, unsigned char *ra, u8 tid, u16 reason, u8 initiator);
895 int issue_del_ba_ex(_adapter *adapter, unsigned char *ra, u8 tid, u16 reason, u8 initiator, int try_cnt, int wait_ms);
896
897 #ifdef CONFIG_IEEE80211W
898 void issue_action_SA_Query(_adapter *padapter, unsigned char *raddr, unsigned char action, unsigned short tid, u8 key_type);
899 int issue_deauth_11w(_adapter *padapter, unsigned char *da, unsigned short reason, u8 key_type);
900 extern void init_dot11w_expire_timer(_adapter *padapter, struct sta_info *psta);
901 #endif //CONFIG_IEEE80211W
902 int issue_action_SM_PS(_adapter *padapter ,  unsigned char *raddr , u8 NewMimoPsMode);
903 int issue_action_SM_PS_wait_ack(_adapter *padapter, unsigned char *raddr, u8 NewMimoPsMode, int try_cnt, int wait_ms);
904
905 unsigned int send_delba_sta_tid(_adapter *adapter, u8 initiator, struct sta_info *sta, u8 tid, u8 force);
906 unsigned int send_delba_sta_tid_wait_ack(_adapter *adapter, u8 initiator, struct sta_info *sta, u8 tid, u8 force);
907
908 unsigned int send_delba(_adapter *padapter, u8 initiator, u8 *addr);
909 unsigned int send_beacon(_adapter *padapter);
910
911 void start_clnt_assoc(_adapter *padapter);
912 void start_clnt_auth(_adapter* padapter);
913 void start_clnt_join(_adapter* padapter);
914 void start_create_ibss(_adapter* padapter);
915
916 unsigned int OnAssocReq(_adapter *padapter, union recv_frame *precv_frame);
917 unsigned int OnAssocRsp(_adapter *padapter, union recv_frame *precv_frame);
918 unsigned int OnProbeReq(_adapter *padapter, union recv_frame *precv_frame);
919 unsigned int OnProbeRsp(_adapter *padapter, union recv_frame *precv_frame);
920 unsigned int DoReserved(_adapter *padapter, union recv_frame *precv_frame);
921 unsigned int OnBeacon(_adapter *padapter, union recv_frame *precv_frame);
922 unsigned int OnAtim(_adapter *padapter, union recv_frame *precv_frame);
923 unsigned int OnDisassoc(_adapter *padapter, union recv_frame *precv_frame);
924 unsigned int OnAuth(_adapter *padapter, union recv_frame *precv_frame);
925 unsigned int OnAuthClient(_adapter *padapter, union recv_frame *precv_frame);
926 unsigned int OnDeAuth(_adapter *padapter, union recv_frame *precv_frame);
927 unsigned int OnAction(_adapter *padapter, union recv_frame *precv_frame);
928
929 unsigned int on_action_spct(_adapter *padapter, union recv_frame *precv_frame);
930 unsigned int OnAction_qos(_adapter *padapter, union recv_frame *precv_frame);
931 unsigned int OnAction_dls(_adapter *padapter, union recv_frame *precv_frame);
932
933 #define RX_AMPDU_ACCEPT_INVALID 0xFF
934 #define RX_AMPDU_SIZE_INVALID 0xFF
935
936 enum rx_ampdu_reason {
937         RX_AMPDU_DRV_FIXED = 1,
938         RX_AMPDU_BTCOEX = 2, /* not used, because BTCOEX has its own variable management */
939         RX_AMPDU_DRV_SCAN = 3,
940 };
941 u8 rtw_rx_ampdu_size(_adapter *adapter);
942 bool rtw_rx_ampdu_is_accept(_adapter *adapter);
943 bool rtw_rx_ampdu_set_size(_adapter *adapter, u8 size, u8 reason);
944 bool rtw_rx_ampdu_set_accept(_adapter *adapter, u8 accept, u8 reason);
945 u8 rx_ampdu_apply_sta_tid(_adapter *adapter, struct sta_info *sta, u8 tid, u8 accept, u8 size);
946 u8 rx_ampdu_apply_sta(_adapter *adapter, struct sta_info *sta, u8 accept, u8 size);
947 u16 rtw_rx_ampdu_apply(_adapter *adapter);
948
949 unsigned int OnAction_back(_adapter *padapter, union recv_frame *precv_frame);
950 unsigned int on_action_public(_adapter *padapter, union recv_frame *precv_frame);
951 unsigned int OnAction_ht(_adapter *padapter, union recv_frame *precv_frame);
952 #ifdef CONFIG_IEEE80211W
953 unsigned int OnAction_sa_query(_adapter *padapter, union recv_frame *precv_frame);
954 #endif //CONFIG_IEEE80211W
955 unsigned int OnAction_wmm(_adapter *padapter, union recv_frame *precv_frame);
956 unsigned int OnAction_vht(_adapter *padapter, union recv_frame *precv_frame);
957 unsigned int OnAction_p2p(_adapter *padapter, union recv_frame *precv_frame);
958
959
960 void mlmeext_joinbss_event_callback(_adapter *padapter, int join_res);
961 void mlmeext_sta_del_event_callback(_adapter *padapter);
962 void mlmeext_sta_add_event_callback(_adapter *padapter, struct sta_info *psta);
963
964 void linked_status_chk(_adapter *padapter, u8 from_timer);
965
966 void _linked_info_dump(_adapter *padapter);
967
968 void survey_timer_hdl (_adapter *padapter);
969 void link_timer_hdl (_adapter *padapter);
970 void addba_timer_hdl(struct sta_info *psta);
971 #ifdef CONFIG_IEEE80211W
972 void sa_query_timer_hdl(struct sta_info *psta);
973 #endif //CONFIG_IEEE80211W
974 //void reauth_timer_hdl(_adapter *padapter);
975 //void reassoc_timer_hdl(_adapter *padapter);
976
977 #define set_survey_timer(mlmeext, ms) \
978         do { \
979                 /*DBG_871X("%s set_survey_timer(%p, %d)\n", __FUNCTION__, (mlmeext), (ms));*/ \
980                 _set_timer(&(mlmeext)->survey_timer, (ms)); \
981         } while(0)
982
983 #define set_link_timer(mlmeext, ms) \
984         do { \
985                 /*DBG_871X("%s set_link_timer(%p, %d)\n", __FUNCTION__, (mlmeext), (ms));*/ \
986                 _set_timer(&(mlmeext)->link_timer, (ms)); \
987         } while(0)
988
989 extern int cckrates_included(unsigned char *rate, int ratelen);
990 extern int cckratesonly_included(unsigned char *rate, int ratelen);
991
992 extern void process_addba_req(_adapter *padapter, u8 *paddba_req, u8 *addr);
993
994 extern void update_TSF(struct mlme_ext_priv *pmlmeext, u8 *pframe, uint len);
995 extern void correct_TSF(_adapter *padapter, struct mlme_ext_priv *pmlmeext);
996 extern void adaptive_early_32k(struct mlme_ext_priv *pmlmeext, u8 *pframe, uint len);
997 extern u8 traffic_status_watchdog(_adapter *padapter, u8 from_timer);
998
999
1000 #ifdef CONFIG_CONCURRENT_MODE
1001 sint check_buddy_mlmeinfo_state(_adapter *padapter, u32 state);
1002 #endif
1003
1004 void rtw_join_done_chk_ch(_adapter *padapter, int join_res);
1005
1006 int rtw_chk_start_clnt_join(_adapter *padapter, u8 *ch, u8 *bw, u8 *offset);
1007 int rtw_get_ch_setting_union(_adapter *adapter, u8 *ch, u8 *bw, u8 *offset);
1008 int rtw_get_ch_setting_union_no_self(_adapter *adapter, u8 *ch, u8 *bw, u8 *offset);
1009
1010 void rtw_dev_iface_status(_adapter *adapter, u8 *sta_num, u8 *ld_sta_num, u8 *lg_sta_num
1011         , u8 *ap_num, u8 *ld_ap_num);
1012 void rtw_dev_iface_status_no_self(_adapter *adapter, u8 *sta_num, u8 *ld_sta_num, u8 *lg_sta_num
1013         , u8 *ap_num, u8 *ld_ap_num);
1014
1015 struct cmd_hdl {
1016         uint    parmsize;
1017         u8 (*h2cfuns)(struct _ADAPTER *padapter, u8 *pbuf);     
1018 };
1019
1020
1021 u8 read_macreg_hdl(_adapter *padapter, u8 *pbuf);
1022 u8 write_macreg_hdl(_adapter *padapter, u8 *pbuf);
1023 u8 read_bbreg_hdl(_adapter *padapter, u8 *pbuf);
1024 u8 write_bbreg_hdl(_adapter *padapter, u8 *pbuf);
1025 u8 read_rfreg_hdl(_adapter *padapter, u8 *pbuf);
1026 u8 write_rfreg_hdl(_adapter *padapter, u8 *pbuf);
1027
1028
1029 u8 NULL_hdl(_adapter *padapter, u8 *pbuf);
1030 u8 join_cmd_hdl(_adapter *padapter, u8 *pbuf);
1031 u8 disconnect_hdl(_adapter *padapter, u8 *pbuf);
1032 u8 createbss_hdl(_adapter *padapter, u8 *pbuf);
1033 u8 setopmode_hdl(_adapter *padapter, u8 *pbuf);
1034 u8 sitesurvey_cmd_hdl(_adapter *padapter, u8 *pbuf);    
1035 u8 setauth_hdl(_adapter *padapter, u8 *pbuf);
1036 u8 setkey_hdl(_adapter *padapter, u8 *pbuf);
1037 u8 set_stakey_hdl(_adapter *padapter, u8 *pbuf);
1038 u8 set_assocsta_hdl(_adapter *padapter, u8 *pbuf);
1039 u8 del_assocsta_hdl(_adapter *padapter, u8 *pbuf);
1040 u8 add_ba_hdl(_adapter *padapter, unsigned char *pbuf);
1041 u8 add_ba_rsp_hdl(_adapter *padapter, unsigned char *pbuf);
1042
1043 u8 mlme_evt_hdl(_adapter *padapter, unsigned char *pbuf);
1044 u8 h2c_msg_hdl(_adapter *padapter, unsigned char *pbuf);
1045 u8 chk_bmc_sleepq_hdl(_adapter *padapter, unsigned char *pbuf);
1046 u8 tx_beacon_hdl(_adapter *padapter, unsigned char *pbuf);
1047 u8 set_ch_hdl(_adapter *padapter, u8 *pbuf);
1048 u8 set_chplan_hdl(_adapter *padapter, unsigned char *pbuf);
1049 u8 led_blink_hdl(_adapter *padapter, unsigned char *pbuf);
1050 u8 set_csa_hdl(_adapter *padapter, unsigned char *pbuf);        //Kurt: Handling DFS channel switch announcement ie.
1051 u8 tdls_hdl(_adapter *padapter, unsigned char *pbuf);
1052 u8 run_in_thread_hdl(_adapter *padapter, u8 *pbuf);
1053 u8 rtw_getmacreg_hdl(_adapter *padapter, u8 *pbuf);
1054
1055 #define GEN_DRV_CMD_HANDLER(size, cmd)  {size, &cmd ## _hdl},
1056 #define GEN_MLME_EXT_HANDLER(size, cmd) {size, cmd},
1057
1058 #ifdef _RTW_CMD_C_
1059
1060 struct cmd_hdl wlancmds[] = 
1061 {
1062         GEN_DRV_CMD_HANDLER(sizeof(struct readMAC_parm), rtw_getmacreg) /*0*/
1063         GEN_DRV_CMD_HANDLER(0, NULL)
1064         GEN_DRV_CMD_HANDLER(0, NULL)
1065         GEN_DRV_CMD_HANDLER(0, NULL)
1066         GEN_DRV_CMD_HANDLER(0, NULL)
1067         GEN_DRV_CMD_HANDLER(0, NULL)
1068         GEN_MLME_EXT_HANDLER(0, NULL)
1069         GEN_MLME_EXT_HANDLER(0, NULL)
1070         GEN_MLME_EXT_HANDLER(0, NULL)
1071         GEN_MLME_EXT_HANDLER(0, NULL)
1072         GEN_MLME_EXT_HANDLER(0, NULL) /*10*/
1073         GEN_MLME_EXT_HANDLER(0, NULL)
1074         GEN_MLME_EXT_HANDLER(0, NULL)
1075         GEN_MLME_EXT_HANDLER(0, NULL)           
1076         GEN_MLME_EXT_HANDLER(sizeof (struct joinbss_parm), join_cmd_hdl) /*14*/
1077         GEN_MLME_EXT_HANDLER(sizeof (struct disconnect_parm), disconnect_hdl)
1078         GEN_MLME_EXT_HANDLER(sizeof (struct createbss_parm), createbss_hdl)
1079         GEN_MLME_EXT_HANDLER(sizeof (struct setopmode_parm), setopmode_hdl)
1080         GEN_MLME_EXT_HANDLER(sizeof (struct sitesurvey_parm), sitesurvey_cmd_hdl) /*18*/
1081         GEN_MLME_EXT_HANDLER(sizeof (struct setauth_parm), setauth_hdl)
1082         GEN_MLME_EXT_HANDLER(sizeof (struct setkey_parm), setkey_hdl) /*20*/
1083         GEN_MLME_EXT_HANDLER(sizeof (struct set_stakey_parm), set_stakey_hdl)
1084         GEN_MLME_EXT_HANDLER(sizeof (struct set_assocsta_parm), NULL)
1085         GEN_MLME_EXT_HANDLER(sizeof (struct del_assocsta_parm), NULL)
1086         GEN_MLME_EXT_HANDLER(sizeof (struct setstapwrstate_parm), NULL)
1087         GEN_MLME_EXT_HANDLER(sizeof (struct setbasicrate_parm), NULL)
1088         GEN_MLME_EXT_HANDLER(sizeof (struct getbasicrate_parm), NULL)
1089         GEN_MLME_EXT_HANDLER(sizeof (struct setdatarate_parm), NULL)
1090         GEN_MLME_EXT_HANDLER(sizeof (struct getdatarate_parm), NULL)
1091         GEN_MLME_EXT_HANDLER(sizeof (struct setphyinfo_parm), NULL)
1092         GEN_MLME_EXT_HANDLER(sizeof (struct getphyinfo_parm), NULL)  /*30*/
1093         GEN_MLME_EXT_HANDLER(sizeof (struct setphy_parm), NULL)
1094         GEN_MLME_EXT_HANDLER(sizeof (struct getphy_parm), NULL)
1095         GEN_MLME_EXT_HANDLER(0, NULL)
1096         GEN_MLME_EXT_HANDLER(0, NULL)
1097         GEN_MLME_EXT_HANDLER(0, NULL)
1098         GEN_MLME_EXT_HANDLER(0, NULL)
1099         GEN_MLME_EXT_HANDLER(0, NULL)
1100         GEN_MLME_EXT_HANDLER(0, NULL)
1101         GEN_MLME_EXT_HANDLER(0, NULL)
1102         GEN_MLME_EXT_HANDLER(0, NULL)   /*40*/
1103         GEN_MLME_EXT_HANDLER(0, NULL)
1104         GEN_MLME_EXT_HANDLER(0, NULL)
1105         GEN_MLME_EXT_HANDLER(0, NULL)
1106         GEN_MLME_EXT_HANDLER(0, NULL)
1107         GEN_MLME_EXT_HANDLER(sizeof(struct addBaReq_parm), add_ba_hdl)  
1108         GEN_MLME_EXT_HANDLER(sizeof(struct set_ch_parm), set_ch_hdl) /* 46 */
1109         GEN_MLME_EXT_HANDLER(0, NULL)
1110         GEN_MLME_EXT_HANDLER(0, NULL)
1111         GEN_MLME_EXT_HANDLER(0, NULL)
1112         GEN_MLME_EXT_HANDLER(0, NULL) /*50*/
1113         GEN_MLME_EXT_HANDLER(0, NULL)
1114         GEN_MLME_EXT_HANDLER(0, NULL)
1115         GEN_MLME_EXT_HANDLER(0, NULL)
1116         GEN_MLME_EXT_HANDLER(0, NULL) 
1117         GEN_MLME_EXT_HANDLER(sizeof(struct Tx_Beacon_param), tx_beacon_hdl) /*55*/
1118
1119         GEN_MLME_EXT_HANDLER(0, mlme_evt_hdl) /*56*/
1120         GEN_MLME_EXT_HANDLER(0, rtw_drvextra_cmd_hdl) /*57*/
1121
1122         GEN_MLME_EXT_HANDLER(0, h2c_msg_hdl) /*58*/
1123         GEN_MLME_EXT_HANDLER(sizeof(struct SetChannelPlan_param), set_chplan_hdl) /*59*/
1124         GEN_MLME_EXT_HANDLER(sizeof(struct LedBlink_param), led_blink_hdl) /*60*/
1125
1126         GEN_MLME_EXT_HANDLER(sizeof(struct SetChannelSwitch_param), set_csa_hdl) /*61*/
1127         GEN_MLME_EXT_HANDLER(sizeof(struct TDLSoption_param), tdls_hdl) /*62*/
1128         GEN_MLME_EXT_HANDLER(0, chk_bmc_sleepq_hdl) /*63*/
1129         GEN_MLME_EXT_HANDLER(sizeof(struct RunInThread_param), run_in_thread_hdl) /*64*/
1130         GEN_MLME_EXT_HANDLER(sizeof(struct addBaRsp_parm), add_ba_rsp_hdl) /* 65 */
1131 };
1132
1133 #endif
1134
1135 struct C2HEvent_Header
1136 {
1137
1138 #ifdef CONFIG_LITTLE_ENDIAN
1139
1140         unsigned int len:16;
1141         unsigned int ID:8;
1142         unsigned int seq:8;
1143         
1144 #elif defined(CONFIG_BIG_ENDIAN)
1145
1146         unsigned int seq:8;
1147         unsigned int ID:8;
1148         unsigned int len:16;
1149         
1150 #else
1151
1152 #  error "Must be LITTLE or BIG Endian"
1153
1154 #endif
1155
1156         unsigned int rsvd;
1157
1158 };
1159
1160 void rtw_dummy_event_callback(_adapter *adapter , u8 *pbuf);
1161 void rtw_fwdbg_event_callback(_adapter *adapter , u8 *pbuf);
1162
1163 enum rtw_c2h_event
1164 {
1165         GEN_EVT_CODE(_Read_MACREG)=0, /*0*/
1166         GEN_EVT_CODE(_Read_BBREG),
1167         GEN_EVT_CODE(_Read_RFREG),
1168         GEN_EVT_CODE(_Read_EEPROM),
1169         GEN_EVT_CODE(_Read_EFUSE),
1170         GEN_EVT_CODE(_Read_CAM),                        /*5*/
1171         GEN_EVT_CODE(_Get_BasicRate),  
1172         GEN_EVT_CODE(_Get_DataRate),   
1173         GEN_EVT_CODE(_Survey),   /*8*/
1174         GEN_EVT_CODE(_SurveyDone),       /*9*/
1175         
1176         GEN_EVT_CODE(_JoinBss) , /*10*/
1177         GEN_EVT_CODE(_AddSTA),
1178         GEN_EVT_CODE(_DelSTA),
1179         GEN_EVT_CODE(_AtimDone) ,
1180         GEN_EVT_CODE(_TX_Report),  
1181         GEN_EVT_CODE(_CCX_Report),                      /*15*/
1182         GEN_EVT_CODE(_DTM_Report),
1183         GEN_EVT_CODE(_TX_Rate_Statistics),
1184         GEN_EVT_CODE(_C2HLBK), 
1185         GEN_EVT_CODE(_FWDBG),
1186         GEN_EVT_CODE(_C2HFEEDBACK),               /*20*/
1187         GEN_EVT_CODE(_ADDBA),
1188         GEN_EVT_CODE(_C2HBCN),
1189         GEN_EVT_CODE(_ReportPwrState),          //filen: only for PCIE, USB     
1190         GEN_EVT_CODE(_CloseRF),                         //filen: only for PCIE, work around ASPM
1191         GEN_EVT_CODE(_WMM),                                     /*25*/
1192 #ifdef CONFIG_IEEE80211W
1193         GEN_EVT_CODE(_TimeoutSTA),
1194 #endif /* CONFIG_IEEE80211W */
1195         MAX_C2HEVT
1196 };
1197
1198
1199 #ifdef _RTW_MLME_EXT_C_         
1200
1201 static struct fwevent wlanevents[] = 
1202 {
1203         {0, rtw_dummy_event_callback},  /*0*/
1204         {0, NULL},
1205         {0, NULL},
1206         {0, NULL},
1207         {0, NULL},
1208         {0, NULL},
1209         {0, NULL},
1210         {0, NULL},
1211         {0, &rtw_survey_event_callback},                /*8*/
1212         {sizeof (struct surveydone_event), &rtw_surveydone_event_callback},     /*9*/
1213                 
1214         {0, &rtw_joinbss_event_callback},               /*10*/
1215         {sizeof(struct stassoc_event), &rtw_stassoc_event_callback},
1216         {sizeof(struct stadel_event), &rtw_stadel_event_callback},      
1217         {0, &rtw_atimdone_event_callback},
1218         {0, rtw_dummy_event_callback},
1219         {0, NULL},      /*15*/
1220         {0, NULL},
1221         {0, NULL},
1222         {0, NULL},
1223         {0, rtw_fwdbg_event_callback},
1224         {0, NULL},       /*20*/
1225         {0, NULL},
1226         {0, NULL},
1227         {0, &rtw_cpwm_event_callback},
1228         {0, NULL},
1229         {0, &rtw_wmm_event_callback}, /*25*/
1230 #ifdef CONFIG_IEEE80211W
1231         {sizeof(struct stadel_event), &rtw_sta_timeout_event_callback},
1232 #endif /* CONFIG_IEEE80211W */
1233
1234 };
1235
1236 #endif//_RTW_MLME_EXT_C_
1237
1238 #endif
1239