8723BU: Update 8723BU wifi driver to version v4.3.16_14189.20150519_BTCOEX2015119...
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bu / include / rtw_mlme.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_H_
21 #define __RTW_MLME_H_
22
23
24 #define MAX_BSS_CNT     128
25 //#define   MAX_JOIN_TIMEOUT    2000
26 //#define   MAX_JOIN_TIMEOUT    2500
27 #define   MAX_JOIN_TIMEOUT      6500
28
29 //      Commented by Albert 20101105
30 //      Increase the scanning timeout because of increasing the SURVEY_TO value.
31
32 #define         SCANNING_TIMEOUT        8000
33 #ifdef CONFIG_STA_MODE_SCAN_UNDER_AP_MODE
34 #define         CONC_SCANNING_TIMEOUT_SINGLE_BAND 10000
35 #define         CONC_SCANNING_TIMEOUT_DUAL_BAND 15000
36 #endif //CONFIG_STA_MODE_SCAN_UNDER_AP_MODE
37
38 #ifdef PALTFORM_OS_WINCE
39 #define SCANQUEUE_LIFETIME 12000000 // unit:us
40 #else
41 #define SCANQUEUE_LIFETIME 20000 // 20sec, unit:msec
42 #endif
43
44 #define WIFI_NULL_STATE         0x00000000
45 #define WIFI_ASOC_STATE         0x00000001              // Under Linked state...
46 #define WIFI_REASOC_STATE       0x00000002
47 #define WIFI_SLEEP_STATE        0x00000004
48 #define WIFI_STATION_STATE      0x00000008
49 #define WIFI_AP_STATE                   0x00000010
50 #define WIFI_ADHOC_STATE                0x00000020
51 #define WIFI_ADHOC_MASTER_STATE 0x00000040
52 #define WIFI_UNDER_LINKING      0x00000080
53
54 #define WIFI_UNDER_WPS                  0x00000100
55 //#define       WIFI_UNDER_CMD                  0x00000200
56 //#define       WIFI_UNDER_P2P                  0x00000400
57 #define WIFI_STA_ALIVE_CHK_STATE        0x00000400
58 #define WIFI_SITE_MONITOR                       0x00000800              //to indicate the station is under site surveying
59 #ifdef WDS
60 #define WIFI_WDS                                0x00001000
61 #define WIFI_WDS_RX_BEACON      0x00002000              // already rx WDS AP beacon
62 #endif
63 #ifdef AUTO_CONFIG
64 #define WIFI_AUTOCONF                   0x00004000
65 #define WIFI_AUTOCONF_IND       0x00008000
66 #endif
67 #define WIFI_MONITOR_STATE 0x80000000
68
69 /*
70 // ========== P2P Section Start ===============
71 #define WIFI_P2P_LISTEN_STATE           0x00010000
72 #define WIFI_P2P_GROUP_FORMATION_STATE          0x00020000
73 // ========== P2P Section End ===============
74 */
75
76 //#ifdef UNDER_MPTEST
77 #define WIFI_MP_STATE                                                   0x00010000
78 #define WIFI_MP_CTX_BACKGROUND                          0x00020000      // in continous tx background
79 #define WIFI_MP_CTX_ST                                          0x00040000      // in continous tx with single-tone
80 #define WIFI_MP_CTX_BACKGROUND_PENDING  0x00080000      // pending in continous tx background due to out of skb
81 #define WIFI_MP_CTX_CCK_HW                                      0x00100000      // in continous tx
82 #define WIFI_MP_CTX_CCK_CS                                      0x00200000      // in continous tx with carrier suppression
83 #define   WIFI_MP_LPBK_STATE                                    0x00400000
84 //#endif
85
86 //#define _FW_UNDER_CMD         WIFI_UNDER_CMD
87 #define _FW_UNDER_LINKING       WIFI_UNDER_LINKING
88 #define _FW_LINKED                      WIFI_ASOC_STATE
89 #define _FW_UNDER_SURVEY        WIFI_SITE_MONITOR
90
91
92 enum dot11AuthAlgrthmNum {
93  dot11AuthAlgrthm_Open = 0,
94  dot11AuthAlgrthm_Shared,
95  dot11AuthAlgrthm_8021X,
96  dot11AuthAlgrthm_Auto,
97  dot11AuthAlgrthm_WAPI,
98  dot11AuthAlgrthm_MaxNum
99 };
100
101 // Scan type including active and passive scan.
102 typedef enum _RT_SCAN_TYPE
103 {
104         SCAN_PASSIVE,
105         SCAN_ACTIVE,
106         SCAN_MIX,
107 }RT_SCAN_TYPE, *PRT_SCAN_TYPE;
108
109 #define WIFI_FREQUENCY_BAND_AUTO 0
110 #define WIFI_FREQUENCY_BAND_5GHZ 1
111 #define WIFI_FREQUENCY_BAND_2GHZ 2
112
113 #define rtw_band_valid(band) ((band) <= WIFI_FREQUENCY_BAND_2GHZ)
114
115 enum DriverInterface {
116         DRIVER_WEXT =  1,
117         DRIVER_CFG80211 = 2
118 };
119
120 enum SCAN_RESULT_TYPE
121 {
122         SCAN_RESULT_P2P_ONLY = 0,               //      Will return all the P2P devices.
123         SCAN_RESULT_ALL = 1,                    //      Will return all the scanned device, include AP.
124         SCAN_RESULT_WFD_TYPE = 2                //      Will just return the correct WFD device.
125                                                                         //      If this device is Miracast sink device, it will just return all the Miracast source devices.
126 };
127
128 /*
129
130 there are several "locks" in mlme_priv,
131 since mlme_priv is a shared resource between many threads,
132 like ISR/Call-Back functions, the OID handlers, and even timer functions.
133
134
135 Each _queue has its own locks, already.
136 Other items are protected by mlme_priv.lock.
137
138 To avoid possible dead lock, any thread trying to modifiying mlme_priv
139 SHALL not lock up more than one locks at a time!
140
141 */
142
143
144 #define traffic_threshold       10
145 #define traffic_scan_period     500
146
147 struct sitesurvey_ctrl {
148         u64     last_tx_pkts;
149         uint    last_rx_pkts;
150         sint    traffic_busy;
151         _timer  sitesurvey_ctrl_timer;
152 };
153
154 typedef struct _RT_LINK_DETECT_T{
155         u32                             NumTxOkInPeriod;
156         u32                             NumRxOkInPeriod;
157         u32                             NumRxUnicastOkInPeriod;
158         BOOLEAN                 bBusyTraffic;
159         BOOLEAN                 bTxBusyTraffic;
160         BOOLEAN                 bRxBusyTraffic;
161         BOOLEAN                 bHigherBusyTraffic; // For interrupt migration purpose.
162         BOOLEAN                 bHigherBusyRxTraffic; // We may disable Tx interrupt according as Rx traffic.
163         BOOLEAN                 bHigherBusyTxTraffic; // We may disable Tx interrupt according as Tx traffic.
164         //u8 TrafficBusyState;
165         u8 TrafficTransitionCount;
166         u32 LowPowerTransitionCount;
167 }RT_LINK_DETECT_T, *PRT_LINK_DETECT_T;
168
169 struct profile_info {
170         u8      ssidlen;
171         u8      ssid[ WLAN_SSID_MAXLEN ];
172         u8      peermac[ ETH_ALEN ];
173 };
174
175 struct tx_invite_req_info{
176         u8                                      token;
177         u8                                      benable;
178         u8                                      go_ssid[ WLAN_SSID_MAXLEN ];
179         u8                                      ssidlen;
180         u8                                      go_bssid[ ETH_ALEN ];
181         u8                                      peer_macaddr[ ETH_ALEN ];
182         u8                                      operating_ch;   //      This information will be set by using the p2p_set op_ch=x
183         u8                                      peer_ch;                //      The listen channel for peer P2P device
184
185 };
186
187 struct tx_invite_resp_info{
188         u8                                      token;  //      Used to record the dialog token of p2p invitation request frame.
189 };
190
191 #define MIRACAST_DISABLED 0
192 #define MIRACAST_SOURCE 1
193 #define MIRACAST_SINK 2
194 #define MIRACAST_INVALID 3
195
196 #define is_miracast_enabled(mode) \
197         (mode == MIRACAST_SOURCE || mode == MIRACAST_SINK)
198
199 const char *get_miracast_mode_str(int mode);
200
201 #ifdef CONFIG_WFD
202
203 struct wifi_display_info{
204         u16                                                     wfd_enable;                     //      Eanble/Disable the WFD function.
205         u16                                                     rtsp_ctrlport;          //      TCP port number at which the this WFD device listens for RTSP messages
206         u16                                                     peer_rtsp_ctrlport;     //      TCP port number at which the peer WFD device listens for RTSP messages
207                                                                                                         //      This filed should be filled when receiving the gropu negotiation request
208
209         u8                                                      peer_session_avail;     //      WFD session is available or not for the peer wfd device.
210                                                                                                         //      This variable will be set when sending the provisioning discovery request to peer WFD device.
211                                                                                                         //      And this variable will be reset when it is read by using the iwpriv p2p_get wfd_sa command.
212         u8                                                      ip_address[4];
213         u8                                                      peer_ip_address[4];
214         u8                                                      wfd_pc;                         //      WFD preferred connection
215                                                                                                         //      0 -> Prefer to use the P2P for WFD connection on peer side.
216                                                                                                         //      1 -> Prefer to use the TDLS for WFD connection on peer side.
217                                                                                         
218         u8                                                      wfd_device_type;        //      WFD Device Type
219                                                                                                         //      0 -> WFD Source Device
220                                                                                                         //      1 -> WFD Primary Sink Device
221         enum    SCAN_RESULT_TYPE        scan_result_type;       //      Used when P2P is enable. This parameter will impact the scan result.
222         u8 stack_wfd_mode;
223 };
224 #endif //CONFIG_WFD
225
226 struct tx_provdisc_req_info{
227         u16                                     wps_config_method_request;      //      Used when sending the provisioning request frame
228         u16                                     peer_channel_num[2];            //      The channel number which the receiver stands.
229         NDIS_802_11_SSID        ssid;
230         u8                                      peerDevAddr[ ETH_ALEN ];                //      Peer device address
231         u8                                      peerIFAddr[ ETH_ALEN ];         //      Peer interface address
232         u8                                      benable;                                        //      This provision discovery request frame is trigger to send or not
233 };
234
235 struct rx_provdisc_req_info{    //When peer device issue prov_disc_req first, we should store the following informations
236         u8                                      peerDevAddr[ ETH_ALEN ];                //      Peer device address
237         u8                                      strconfig_method_desc_of_prov_disc_req[4];      //      description for the config method located in the provisioning discovery request frame.  
238                                                                                                                                         //      The UI must know this information to know which config method the remote p2p device is requiring.
239 };
240
241 struct tx_nego_req_info{
242         u16                                     peer_channel_num[2];            //      The channel number which the receiver stands.
243         u8                                      peerDevAddr[ ETH_ALEN ];                //      Peer device address
244         u8                                      benable;                                        //      This negoitation request frame is trigger to send or not
245 };
246
247 struct group_id_info{
248         u8                                      go_device_addr[ ETH_ALEN ];     //      The GO's device address of this P2P group
249         u8                                      ssid[ WLAN_SSID_MAXLEN ];       //      The SSID of this P2P group
250 };
251
252 struct scan_limit_info{
253         u8                                      scan_op_ch_only;                        //      When this flag is set, the driver should just scan the operation channel
254 #ifndef CONFIG_P2P_OP_CHK_SOCIAL_CH
255         u8                                      operation_ch[2];                                //      Store the operation channel of invitation request frame
256 #else
257         u8                                      operation_ch[5];                                //      Store additional channel 1,6,11  for Android 4.2 IOT & Nexus 4
258 #endif //CONFIG_P2P_OP_CHK_SOCIAL_CH
259 };
260
261 #ifdef CONFIG_IOCTL_CFG80211
262 struct cfg80211_wifidirect_info{
263         _timer                                  remain_on_ch_timer;
264         u8                                              restore_channel;
265         struct ieee80211_channel        remain_on_ch_channel;
266         enum nl80211_channel_type       remain_on_ch_type;
267         ATOMIC_T ro_ch_cookie_gen;
268         u64 remain_on_ch_cookie;
269         bool is_ro_ch;
270         u32 last_ro_ch_time; /* this will be updated at the beginning and end of ro_ch */
271 };
272 #endif //CONFIG_IOCTL_CFG80211
273
274 #ifdef CONFIG_P2P_WOWLAN
275
276 enum P2P_WOWLAN_RECV_FRAME_TYPE
277 {
278         P2P_WOWLAN_RECV_NEGO_REQ = 0,
279         P2P_WOWLAN_RECV_INVITE_REQ = 1,
280         P2P_WOWLAN_RECV_PROVISION_REQ = 2,
281 };
282
283 struct p2p_wowlan_info{
284
285         u8                                              is_trigger;
286         enum P2P_WOWLAN_RECV_FRAME_TYPE wowlan_recv_frame_type;
287         u8                                              wowlan_peer_addr[ETH_ALEN];
288         u16                                             wowlan_peer_wpsconfig;
289         u8                                              wowlan_peer_is_persistent;
290         u8                                              wowlan_peer_invitation_type;
291 };
292
293 #endif //CONFIG_P2P_WOWLAN
294
295 struct wifidirect_info{
296         _adapter*                               padapter;
297         _timer                                  find_phase_timer;
298         _timer                                  restore_p2p_state_timer;
299         
300         //      Used to do the scanning. After confirming the peer is availalble, the driver transmits the P2P frame to peer.
301         _timer                                  pre_tx_scan_timer;
302         _timer                                  reset_ch_sitesurvey;
303         _timer                                  reset_ch_sitesurvey2;   //      Just for resetting the scan limit function by using p2p nego
304 #ifdef CONFIG_CONCURRENT_MODE
305         //      Used to switch the channel between legacy AP and listen state.
306         _timer                                  ap_p2p_switch_timer;
307 #endif
308         struct tx_provdisc_req_info     tx_prov_disc_info;
309         struct rx_provdisc_req_info rx_prov_disc_info;
310         struct tx_invite_req_info       invitereq_info;
311         struct profile_info                     profileinfo[ P2P_MAX_PERSISTENT_GROUP_NUM ];    //      Store the profile information of persistent group
312         struct tx_invite_resp_info      inviteresp_info;
313         struct tx_nego_req_info nego_req_info;
314         struct group_id_info            groupid_info;   //      Store the group id information when doing the group negotiation handshake.
315         struct scan_limit_info          rx_invitereq_info;      //      Used for get the limit scan channel from the Invitation procedure
316         struct scan_limit_info          p2p_info;               //      Used for get the limit scan channel from the P2P negotiation handshake
317 #ifdef CONFIG_WFD
318         struct wifi_display_info                *wfd_info;
319 #endif  
320
321 #ifdef CONFIG_P2P_WOWLAN
322         struct p2p_wowlan_info          p2p_wow_info;
323 #endif //CONFIG_P2P_WOWLAN
324
325         enum P2P_ROLE                   role;
326         enum P2P_STATE                  pre_p2p_state;
327         enum P2P_STATE                  p2p_state;
328         u8                                              device_addr[ETH_ALEN];  //      The device address should be the mac address of this device.
329         u8                                              interface_addr[ETH_ALEN];
330         u8                                              social_chan[4];
331         u8                                              listen_channel;
332         u8                                              operating_channel;
333         u8                                              listen_dwell;           //      This value should be between 1 and 3
334         u8                                              support_rate[8];
335         u8                                              p2p_wildcard_ssid[P2P_WILDCARD_SSID_LEN];
336         u8                                              intent;         //      should only include the intent value.
337         u8                                              p2p_peer_interface_addr[ ETH_ALEN ];
338         u8                                              p2p_peer_device_addr[ ETH_ALEN ];
339         u8                                              peer_intent;    //      Included the intent value and tie breaker value.
340         u8                                              device_name[ WPS_MAX_DEVICE_NAME_LEN ]; //      Device name for displaying on searching device screen
341         u8                                              device_name_len;
342         u8                                              profileindex;   //      Used to point to the index of profileinfo array
343         u8                                              peer_operating_ch;
344         u8                                              find_phase_state_exchange_cnt;
345         u16                                             device_password_id_for_nego;    //      The device password ID for group negotation
346         u8                                              negotiation_dialog_token;
347         u8                                              nego_ssid[ WLAN_SSID_MAXLEN ];  //      SSID information for group negotitation
348         u8                                              nego_ssidlen;
349         u8                                              p2p_group_ssid[WLAN_SSID_MAXLEN];
350         u8                                              p2p_group_ssid_len;
351         u8                                              persistent_supported;           //      Flag to know the persistent function should be supported or not.
352                                                                                                                 //      In the Sigma test, the Sigma will provide this enable from the sta_set_p2p CAPI.
353                                                                                                                 //      0: disable
354                                                                                                                 //      1: enable
355         u8                                              session_available;                      //      Flag to set the WFD session available to enable or disable "by Sigma"
356                                                                                                                 //      In the Sigma test, the Sigma will disable the session available by using the sta_preset CAPI.
357                                                                                                                 //      0: disable
358                                                                                                                 //      1: enable
359
360         u8                                              wfd_tdls_enable;                        //      Flag to enable or disable the TDLS by WFD Sigma
361                                                                                                                 //      0: disable
362                                                                                                                 //      1: enable
363         u8                                              wfd_tdls_weaksec;                       //      Flag to enable or disable the weak security function for TDLS by WFD Sigma
364                                                                                                                 //      0: disable
365                                                                                                                 //      In this case, the driver can't issue the tdsl setup request frame.
366                                                                                                                 //      1: enable
367                                                                                                                 //      In this case, the driver can issue the tdls setup request frame
368                                                                                                                 //      even the current security is weak security.
369
370         enum    P2P_WPSINFO             ui_got_wps_info;                        //      This field will store the WPS value (PIN value or PBC) that UI had got from the user.
371         u16                                             supported_wps_cm;                       //      This field describes the WPS config method which this driver supported.
372                                                                                                                 //      The value should be the combination of config method defined in page104 of WPS v2.0 spec.       
373         u8                                              external_uuid;                          // UUID flag
374         u8                                              uuid[16];                                       // UUID
375         uint                                            channel_list_attr_len;          //      This field will contain the length of body of P2P Channel List attribute of group negotitation response frame.
376         u8                                              channel_list_attr[100];         //      This field will contain the body of P2P Channel List attribute of group negotitation response frame.
377                                                                                                                 //      We will use the channel_cnt and channel_list fields when constructing the group negotitation confirm frame.
378         u8                                              driver_interface;                       //      Indicate DRIVER_WEXT or DRIVER_CFG80211
379
380 #ifdef CONFIG_CONCURRENT_MODE
381         u16                                             ext_listen_interval;    //      The interval to be available with legacy AP (ms)
382         u16                                             ext_listen_period;      //      The time period to be available for P2P listen state (ms)
383 #endif
384 #ifdef CONFIG_P2P_PS
385         enum P2P_PS_MODE                p2p_ps_mode; // indicate p2p ps mode
386         enum P2P_PS_STATE               p2p_ps_state; // indicate p2p ps state
387         u8                                              noa_index; // Identifies and instance of Notice of Absence timing.
388         u8                                              ctwindow; // Client traffic window. A period of time in TU after TBTT.
389         u8                                              opp_ps; // opportunistic power save.
390         u8                                              noa_num; // number of NoA descriptor in P2P IE.
391         u8                                              noa_count[P2P_MAX_NOA_NUM]; // Count for owner, Type of client.
392         u32                                             noa_duration[P2P_MAX_NOA_NUM]; // Max duration for owner, preferred or min acceptable duration for client.
393         u32                                             noa_interval[P2P_MAX_NOA_NUM]; // Length of interval for owner, preferred or max acceptable interval of client.
394         u32                                             noa_start_time[P2P_MAX_NOA_NUM]; // schedule expressed in terms of the lower 4 bytes of the TSF timer.
395 #endif // CONFIG_P2P_PS
396 };
397
398 struct tdls_ss_record{  //signal strength record
399         u8              macaddr[ETH_ALEN];
400         u8              RxPWDBAll;
401         u8              is_tdls_sta;    // _TRUE: direct link sta, _FALSE: else
402 };
403
404 struct tdls_temp_mgmt{
405         u8      initiator;      // 0: None, 1: we initiate, 2: peer initiate
406         u8      peer_addr[ETH_ALEN];
407 };
408
409 #ifdef CONFIG_TDLS_CH_SW
410 struct tdls_ch_switch{
411         u32     ch_sw_state;
412         ATOMIC_T        chsw_on;
413         u8      addr[ETH_ALEN];
414         u8      off_ch_num;
415         u8      ch_offset;
416         u32     cur_time;
417         u8      delay_switch_back;
418         u8      dump_stack;
419 };
420 #endif
421
422 struct tdls_info{
423         u8                                      ap_prohibited;
424         u8                                      ch_switch_prohibited;
425         u8                                      link_established;
426         u8                                      sta_cnt;
427         u8                                      sta_maximum;    /* 1:tdls sta is equal (NUM_STA-1), reach max direct link number; 0: else; */
428         struct tdls_ss_record   ss_record;
429 #ifdef CONFIG_TDLS_CH_SW        
430         struct tdls_ch_switch   chsw_info;
431 #endif
432
433         u8                                      ch_sensing;
434         u8                                      cur_channel;
435         u8                                      collect_pkt_num[MAX_CHANNEL_NUM];
436         _lock                           cmd_lock;
437         _lock                           hdl_lock;
438         u8                                      watchdog_count;
439         u8                                      dev_discovered;         /* WFD_TDLS: for sigma test */
440         u8                                      tdls_enable;
441
442         /* Let wpa_supplicant to setup*/
443         u8                                      driver_setup;
444 #ifdef CONFIG_WFD
445         struct wifi_display_info                *wfd_info;
446 #endif          
447 };
448
449 struct tdls_txmgmt {
450         u8 peer[ETH_ALEN];
451         u8 action_code;
452         u8 dialog_token;
453         u16 status_code;
454         u8 *buf;
455         size_t len;
456 };
457
458 /* used for mlme_priv.roam_flags */
459 enum {
460         RTW_ROAM_ON_EXPIRED = BIT0,
461         RTW_ROAM_ON_RESUME = BIT1,
462         RTW_ROAM_ACTIVE = BIT2,
463 };
464
465 struct beacon_keys {
466         u8 ssid[IW_ESSID_MAX_SIZE];
467         u32 ssid_len;
468         u8 bcn_channel;
469         u16 ht_cap_info;
470         u8 ht_info_infos_0_sco; // bit0 & bit1 in infos[0] is second channel offset
471         int encryp_protocol;
472         int pairwise_cipher;
473         int group_cipher;
474         int is_8021x;
475 };
476
477 struct mlme_priv {
478
479         _lock   lock;
480         sint    fw_state;       //shall we protect this variable? maybe not necessarily...
481         u8 bScanInProcess;
482         u8      to_join; //flag
483         #ifdef CONFIG_LAYER2_ROAMING
484         u8 to_roam; /* roaming trying times */
485         struct wlan_network *roam_network; /* the target of active roam */
486         u8 roam_flags;
487         u8 roam_rssi_diff_th; /* rssi difference threshold for active scan candidate selection */
488         u32 roam_scan_int_ms; /* scan interval for active roam */
489         u32 roam_scanr_exp_ms; /* scan result expire time in ms  for roam */
490         u8 roam_tgt_addr[ETH_ALEN]; /* request to roam to speicific target without other consideration */
491         #endif
492
493         u8      *nic_hdl;
494
495         u8      not_indic_disco;
496         _list           *pscanned;
497         _queue  free_bss_pool;
498         _queue  scanned_queue;
499         u8              *free_bss_buf;
500         u32     num_of_scanned;
501
502         NDIS_802_11_SSID        assoc_ssid;
503         u8      assoc_bssid[6];
504
505         struct wlan_network     cur_network;
506         struct wlan_network *cur_network_scanned;
507
508         // bcn check info
509         struct beacon_keys cur_beacon_keys; // save current beacon keys
510         struct beacon_keys new_beacon_keys; // save new beacon keys
511         u8 new_beacon_cnts; // if new_beacon_cnts >= threshold, ap beacon is changed
512
513 #ifdef CONFIG_ARP_KEEP_ALIVE
514         // for arp offload keep alive
515         u8      gw_mac_addr[6];
516         u8      gw_ip[4];
517 #endif
518
519         //uint wireless_mode; no used, remove it
520
521         u32     auto_scan_int_ms;
522
523         _timer assoc_timer;
524
525         uint assoc_by_bssid;
526         uint assoc_by_rssi;
527
528         _timer scan_to_timer; // driver itself handles scan_timeout status.
529         u32 scan_start_time; // used to evaluate the time spent in scanning
530
531         #ifdef CONFIG_SET_SCAN_DENY_TIMER
532         _timer set_scan_deny_timer;
533         ATOMIC_T set_scan_deny; //0: allowed, 1: deny
534         #endif
535
536         struct qos_priv qospriv;
537
538 #ifdef CONFIG_80211N_HT
539
540         /* Number of non-HT AP/stations */
541         int num_sta_no_ht;
542
543         /* Number of HT AP/stations 20 MHz */
544         //int num_sta_ht_20mhz; 
545
546
547         int num_FortyMHzIntolerant;
548
549         struct ht_priv  htpriv;
550
551 #endif
552
553 #ifdef CONFIG_80211AC_VHT
554         struct vht_priv vhtpriv;
555 #endif
556 #ifdef CONFIG_BEAMFORMING
557         struct beamforming_info beamforming_info;
558 #endif
559
560 #ifdef CONFIG_DFS
561         u8      handle_dfs;
562 #endif //CONFIG_DFS
563
564         RT_LINK_DETECT_T        LinkDetectInfo;
565         _timer  dynamic_chk_timer; //dynamic/periodic check timer
566
567         u8      acm_mask; // for wmm acm mask
568         u8      ChannelPlan;
569         RT_SCAN_TYPE    scan_mode; // active: 1, passive: 0
570
571         u8 *wps_probe_req_ie;
572         u32 wps_probe_req_ie_len;
573
574 #if defined (CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
575         /* Number of associated Non-ERP stations (i.e., stations using 802.11b
576          * in 802.11g BSS) */
577         int num_sta_non_erp;
578
579         /* Number of associated stations that do not support Short Slot Time */
580         int num_sta_no_short_slot_time;
581
582         /* Number of associated stations that do not support Short Preamble */
583         int num_sta_no_short_preamble;
584
585         int olbc; /* Overlapping Legacy BSS Condition */
586
587         /* Number of HT associated stations that do not support greenfield */
588         int num_sta_ht_no_gf;
589
590         /* Number of associated non-HT stations */
591         //int num_sta_no_ht;
592
593         /* Number of HT associated stations 20 MHz */
594         int num_sta_ht_20mhz;
595
596         /* Overlapping BSS information */
597         int olbc_ht;
598         
599 #ifdef CONFIG_80211N_HT
600         u16 ht_op_mode;
601 #endif /* CONFIG_80211N_HT */   
602
603         u8 *assoc_req;
604         u32 assoc_req_len;
605         u8 *assoc_rsp;
606         u32 assoc_rsp_len;
607
608         u8 *wps_beacon_ie;      
609         //u8 *wps_probe_req_ie;
610         u8 *wps_probe_resp_ie;
611         u8 *wps_assoc_resp_ie; // for CONFIG_IOCTL_CFG80211, this IE could include p2p ie / wfd ie
612
613         u32 wps_beacon_ie_len;
614         //u32 wps_probe_req_ie_len;
615         u32 wps_probe_resp_ie_len;
616         u32 wps_assoc_resp_ie_len; // for CONFIG_IOCTL_CFG80211, this IE len could include p2p ie / wfd ie
617         
618         u8 *p2p_beacon_ie;
619         u8 *p2p_probe_req_ie;
620         u8 *p2p_probe_resp_ie;  
621         u8 *p2p_go_probe_resp_ie; //for GO      
622         u8 *p2p_assoc_req_ie;
623
624         u32 p2p_beacon_ie_len;
625         u32 p2p_probe_req_ie_len;
626         u32 p2p_probe_resp_ie_len;
627         u32 p2p_go_probe_resp_ie_len; //for GO
628         u32 p2p_assoc_req_ie_len;
629 /*
630 #if defined(CONFIG_P2P) && defined(CONFIG_IOCTL_CFG80211)
631         //u8 *wps_p2p_beacon_ie;
632         u8 *p2p_beacon_ie;
633         u8 *wps_p2p_probe_resp_ie;
634         u8 *wps_p2p_assoc_resp_ie;
635         //u32 wps_p2p_beacon_ie_len;
636         u32 p2p_beacon_ie_len;
637         u32 wps_p2p_probe_resp_ie_len;
638         u32 wps_p2p_assoc_resp_ie_len;
639 #endif
640 */
641         
642         _lock   bcn_update_lock;
643         u8              update_bcn;
644         
645         
646 #endif //#if defined (CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
647
648 #if defined(CONFIG_WFD) && defined(CONFIG_IOCTL_CFG80211)
649         
650         u8 *wfd_beacon_ie;
651         u8 *wfd_probe_req_ie;
652         u8 *wfd_probe_resp_ie;  
653         u8 *wfd_go_probe_resp_ie; //for GO      
654         u8 *wfd_assoc_req_ie;
655
656         u32 wfd_beacon_ie_len;
657         u32 wfd_probe_req_ie_len;
658         u32 wfd_probe_resp_ie_len;
659         u32 wfd_go_probe_resp_ie_len; //for GO
660         u32 wfd_assoc_req_ie_len;
661
662 #endif
663
664 #ifdef RTK_DMP_PLATFORM
665         // DMP kobject_hotplug function  signal need in passive level
666         _workitem       Linkup_workitem;
667         _workitem       Linkdown_workitem;
668 #endif
669
670 #ifdef CONFIG_INTEL_WIDI
671         int     widi_state;
672         int     listen_state;
673         _timer  listen_timer;
674         ATOMIC_T        rx_probe_rsp; // 1:receive probe respone from RDS source.
675         u8      *l2sdTaBuffer;
676         u8      channel_idx;
677         u8      group_cnt;      //In WiDi 3.5, they specified another scan algo. for WFD/RDS co-existed
678         u8      sa_ext[L2SDTA_SERVICE_VE_LEN];
679
680         u8      widi_enable;
681         /**
682          * For WiDi 4; upper layer would set
683          * p2p_primary_device_type_category_id
684          * p2p_primary_device_type_sub_category_id
685          * p2p_secondary_device_type_category_id
686          * p2p_secondary_device_type_sub_category_id
687          */
688         u16     p2p_pdt_cid;
689         u16     p2p_pdt_scid;
690         u8      num_p2p_sdt;
691         u16     p2p_sdt_cid[MAX_NUM_P2P_SDT];
692         u16     p2p_sdt_scid[MAX_NUM_P2P_SDT];
693         u8      p2p_reject_disable;     //When starting NL80211 wpa_supplicant/hostapd, it will call netdev_close
694                                                         //such that it will cause p2p disabled. Use this flag to reject.
695 #endif // CONFIG_INTEL_WIDI
696
697 #ifdef CONFIG_CONCURRENT_MODE
698         u8      scanning_via_buddy_intf;
699 #endif
700
701 //      u8      NumOfBcnInfoChkFail;
702 //      u32     timeBcnInfoChkStart;
703 };
704
705 #define mlme_set_scan_to_timer(mlme, ms) \
706         do { \
707                 /* DBG_871X("%s set_scan_to_timer(%p, %d)\n", __FUNCTION__, (mlme), (ms)); */ \
708                 _set_timer(&(mlme)->scan_to_timer, (ms)); \
709         } while(0)
710
711 #define rtw_mlme_set_auto_scan_int(adapter, ms) \
712         do { \
713                 adapter->mlmepriv.auto_scan_int_ms = ms; \
714         while (0)
715
716 void rtw_mlme_reset_auto_scan_int(_adapter *adapter);
717
718 #ifdef CONFIG_AP_MODE
719
720 struct hostapd_priv
721 {
722         _adapter *padapter;
723
724 #ifdef CONFIG_HOSTAPD_MLME
725         struct net_device *pmgnt_netdev;
726         struct usb_anchor anchored;
727 #endif  
728         
729 };
730
731 extern int hostapd_mode_init(_adapter *padapter);
732 extern void hostapd_mode_unload(_adapter *padapter);
733 #endif
734
735
736 extern void rtw_joinbss_event_prehandle(_adapter *adapter, u8 *pbuf);
737 extern void rtw_survey_event_callback(_adapter *adapter, u8 *pbuf);
738 extern void rtw_surveydone_event_callback(_adapter *adapter, u8 *pbuf);
739 extern void rtw_joinbss_event_callback(_adapter *adapter, u8 *pbuf);
740 extern void rtw_stassoc_event_callback(_adapter *adapter, u8 *pbuf);
741 extern void rtw_stadel_event_callback(_adapter *adapter, u8 *pbuf);
742 extern void rtw_atimdone_event_callback(_adapter *adapter, u8 *pbuf);
743 extern void rtw_cpwm_event_callback(_adapter *adapter, u8 *pbuf);
744 extern void rtw_wmm_event_callback(PADAPTER padapter, u8 *pbuf);
745
746 extern void rtw_join_timeout_handler(RTW_TIMER_HDL_ARGS);
747 extern void _rtw_scan_timeout_handler(RTW_TIMER_HDL_ARGS);
748
749 thread_return event_thread(thread_context context);
750
751 extern void rtw_free_network_queue(_adapter *adapter,u8 isfreeall);
752 extern int rtw_init_mlme_priv(_adapter *adapter);// (struct mlme_priv *pmlmepriv);
753
754 extern void rtw_free_mlme_priv (struct mlme_priv *pmlmepriv);
755
756
757 extern sint rtw_select_and_join_from_scanned_queue(struct mlme_priv *pmlmepriv);
758 extern sint rtw_set_key(_adapter *adapter,struct security_priv *psecuritypriv,sint keyid, u8 set_tx, bool enqueue);
759 extern sint rtw_set_auth(_adapter *adapter,struct security_priv *psecuritypriv);
760
761 __inline static u8 *get_bssid(struct mlme_priv *pmlmepriv)
762 {       //if sta_mode:pmlmepriv->cur_network.network.MacAddress=> bssid
763         // if adhoc_mode:pmlmepriv->cur_network.network.MacAddress=> ibss mac address
764         return pmlmepriv->cur_network.network.MacAddress;
765 }
766
767 __inline static sint check_fwstate(struct mlme_priv *pmlmepriv, sint state)
768 {
769         if (pmlmepriv->fw_state & state)
770                 return _TRUE;
771
772         return _FALSE;
773 }
774
775 __inline static sint get_fwstate(struct mlme_priv *pmlmepriv)
776 {
777         return pmlmepriv->fw_state;
778 }
779
780 /*
781  * No Limit on the calling context,
782  * therefore set it to be the critical section...
783  *
784  * ### NOTE:#### (!!!!)
785  * MUST TAKE CARE THAT BEFORE CALLING THIS FUNC, YOU SHOULD HAVE LOCKED pmlmepriv->lock
786  */
787 __inline static void set_fwstate(struct mlme_priv *pmlmepriv, sint state)
788 {
789         pmlmepriv->fw_state |= state;
790         //FOR HW integration
791         if(_FW_UNDER_SURVEY==state){
792                 pmlmepriv->bScanInProcess = _TRUE;
793         }
794 }
795
796 __inline static void _clr_fwstate_(struct mlme_priv *pmlmepriv, sint state)
797 {
798         pmlmepriv->fw_state &= ~state;
799         //FOR HW integration
800         if(_FW_UNDER_SURVEY==state){
801                 pmlmepriv->bScanInProcess = _FALSE;
802         }
803 }
804
805 /*
806  * No Limit on the calling context,
807  * therefore set it to be the critical section...
808  */
809 __inline static void clr_fwstate(struct mlme_priv *pmlmepriv, sint state)
810 {
811         _irqL irqL;
812
813         _enter_critical_bh(&pmlmepriv->lock, &irqL);
814         if (check_fwstate(pmlmepriv, state) == _TRUE)
815                 pmlmepriv->fw_state ^= state;
816         _exit_critical_bh(&pmlmepriv->lock, &irqL);
817 }
818
819 __inline static void clr_fwstate_ex(struct mlme_priv *pmlmepriv, sint state)
820 {
821         _irqL irqL;
822
823         _enter_critical_bh(&pmlmepriv->lock, &irqL);
824         _clr_fwstate_(pmlmepriv, state);
825         _exit_critical_bh(&pmlmepriv->lock, &irqL);
826 }
827
828 __inline static void up_scanned_network(struct mlme_priv *pmlmepriv)
829 {
830         _irqL irqL;
831
832         _enter_critical_bh(&pmlmepriv->lock, &irqL);
833         pmlmepriv->num_of_scanned++;
834         _exit_critical_bh(&pmlmepriv->lock, &irqL);
835 }
836
837 #ifdef CONFIG_CONCURRENT_MODE
838 sint rtw_buddy_adapter_up(_adapter *padapter);
839 sint check_buddy_fwstate(_adapter *padapter, sint state);
840 u8 rtw_get_buddy_bBusyTraffic(_adapter *padapter);
841 #endif //CONFIG_CONCURRENT_MODE
842
843 __inline static void down_scanned_network(struct mlme_priv *pmlmepriv)
844 {
845         _irqL irqL;
846
847         _enter_critical_bh(&pmlmepriv->lock, &irqL);
848         pmlmepriv->num_of_scanned--;
849         _exit_critical_bh(&pmlmepriv->lock, &irqL);
850 }
851
852 __inline static void set_scanned_network_val(struct mlme_priv *pmlmepriv, sint val)
853 {
854         _irqL irqL;
855
856         _enter_critical_bh(&pmlmepriv->lock, &irqL);
857         pmlmepriv->num_of_scanned = val;
858         _exit_critical_bh(&pmlmepriv->lock, &irqL);
859 }
860
861 extern u16 rtw_get_capability(WLAN_BSSID_EX *bss);
862 extern void rtw_update_scanned_network(_adapter *adapter, WLAN_BSSID_EX *target);
863 extern void rtw_disconnect_hdl_under_linked(_adapter* adapter, struct sta_info *psta, u8 free_assoc);
864 extern void rtw_generate_random_ibss(u8 *pibss);
865 extern struct wlan_network* rtw_find_network(_queue *scanned_queue, u8 *addr);
866 extern struct wlan_network* rtw_get_oldest_wlan_network(_queue *scanned_queue);
867 struct wlan_network *_rtw_find_same_network(_queue *scanned_queue, struct wlan_network *network);
868 struct wlan_network *rtw_find_same_network(_queue *scanned_queue, struct wlan_network *network);
869
870 extern void rtw_free_assoc_resources(_adapter* adapter, int lock_scanned_queue);
871 extern void rtw_indicate_disconnect(_adapter* adapter);
872 extern void rtw_indicate_connect(_adapter* adapter);
873 void rtw_indicate_scan_done( _adapter *padapter, bool aborted);
874
875 u32 rtw_scan_abort_timeout(_adapter *adapter, u32 timeout_ms);
876 void rtw_scan_abort_no_wait(_adapter *adapter);
877 void rtw_scan_abort(_adapter *adapter);
878
879 extern int rtw_restruct_sec_ie(_adapter *adapter,u8 *in_ie,u8 *out_ie,uint in_len);
880 extern int rtw_restruct_wmm_ie(_adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_len, uint initial_out_len);
881 extern void rtw_init_registrypriv_dev_network(_adapter *adapter);
882
883 extern void rtw_update_registrypriv_dev_network(_adapter *adapter);
884
885 extern void rtw_get_encrypt_decrypt_from_registrypriv(_adapter *adapter);
886
887 extern void _rtw_join_timeout_handler(_adapter *adapter);
888 extern void rtw_scan_timeout_handler(_adapter *adapter);
889
890 extern void rtw_dynamic_check_timer_handlder(_adapter *adapter);
891 #ifdef CONFIG_SET_SCAN_DENY_TIMER
892 bool rtw_is_scan_deny(_adapter *adapter);
893 void rtw_clear_scan_deny(_adapter *adapter);
894 void rtw_set_scan_deny_timer_hdl(_adapter *adapter);
895 void rtw_set_scan_deny(_adapter *adapter, u32 ms);
896 #else
897 #define rtw_is_scan_deny(adapter) _FALSE
898 #define rtw_clear_scan_deny(adapter) do {} while (0)
899 #define rtw_set_scan_deny_timer_hdl(adapter) do {} while (0)
900 #define rtw_set_scan_deny(adapter, ms) do {} while (0)
901 #endif
902
903
904 extern int _rtw_init_mlme_priv(_adapter *padapter);
905
906 void rtw_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv);
907
908 extern void _rtw_free_mlme_priv(struct mlme_priv *pmlmepriv);
909
910 extern int _rtw_enqueue_network(_queue *queue, struct wlan_network *pnetwork);
911
912 //extern struct wlan_network* _rtw_dequeue_network(_queue *queue);
913
914 extern struct wlan_network* _rtw_alloc_network(struct mlme_priv *pmlmepriv);
915
916
917 extern void _rtw_free_network(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork, u8 isfreeall);
918 extern void _rtw_free_network_nolock(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork);
919
920
921 extern struct wlan_network* _rtw_find_network(_queue *scanned_queue, u8 *addr);
922
923 extern void _rtw_free_network_queue(_adapter* padapter, u8 isfreeall);
924
925 extern sint rtw_if_up(_adapter *padapter);
926
927 sint rtw_linked_check(_adapter *padapter);
928
929 u8 *rtw_get_capability_from_ie(u8 *ie);
930 u8 *rtw_get_timestampe_from_ie(u8 *ie);
931 u8 *rtw_get_beacon_interval_from_ie(u8 *ie);
932
933
934 void rtw_joinbss_reset(_adapter *padapter);
935
936 #ifdef CONFIG_80211N_HT
937 void    rtw_ht_use_default_setting(_adapter *padapter);
938 void rtw_build_wmm_ie_ht(_adapter *padapter, u8 *out_ie, uint *pout_len);
939 unsigned int rtw_restructure_ht_ie(_adapter *padapter, u8 *in_ie, u8 *out_ie, uint in_len, uint *pout_len, u8 channel);
940 void rtw_update_ht_cap(_adapter *padapter, u8 *pie, uint ie_len, u8 channel);
941 void rtw_issue_addbareq_cmd(_adapter *padapter, struct xmit_frame *pxmitframe);
942 void rtw_append_exented_cap(_adapter *padapter, u8 *out_ie, uint *pout_len);
943 #endif
944
945 int rtw_is_same_ibss(_adapter *adapter, struct wlan_network *pnetwork);
946 int is_same_network(WLAN_BSSID_EX *src, WLAN_BSSID_EX *dst, u8 feature);
947
948 #ifdef CONFIG_LAYER2_ROAMING
949 #define rtw_roam_flags(adapter) ((adapter)->mlmepriv.roam_flags)
950 #define rtw_chk_roam_flags(adapter, flags) ((adapter)->mlmepriv.roam_flags & flags)
951 #define rtw_clr_roam_flags(adapter, flags) \
952         do { \
953                 ((adapter)->mlmepriv.roam_flags &= ~flags); \
954         } while (0)
955
956 #define rtw_set_roam_flags(adapter, flags) \
957         do { \
958                 ((adapter)->mlmepriv.roam_flags |= flags); \
959         } while (0)
960
961 #define rtw_assign_roam_flags(adapter, flags) \
962         do { \
963                 ((adapter)->mlmepriv.roam_flags = flags); \
964         } while (0)
965
966 void _rtw_roaming(_adapter *adapter, struct wlan_network *tgt_network);
967 void rtw_roaming(_adapter *adapter, struct wlan_network *tgt_network);
968 void rtw_set_to_roam(_adapter *adapter, u8 to_roam);
969 u8 rtw_dec_to_roam(_adapter *adapter);
970 u8 rtw_to_roam(_adapter *adapter);
971 int rtw_select_roaming_candidate(struct mlme_priv *pmlmepriv);
972 #else
973 #define rtw_roam_flags(adapter) 0
974 #define rtw_chk_roam_flags(adapter, flags) 0
975 #define rtw_clr_roam_flags(adapter, flags) do {} while (0)
976 #define rtw_set_roam_flags(adapter, flags) do {} while (0)
977 #define rtw_assign_roam_flags(adapter, flags) do {} while (0)
978 #define _rtw_roaming(adapter, tgt_network) do {} while(0)
979 #define rtw_roaming(adapter, tgt_network) do {} while(0)
980 #define rtw_set_to_roam(adapter, to_roam) do {} while(0)
981 #define rtw_dec_to_roam(adapter) 0
982 #define rtw_to_roam(adapter) 0
983 #define rtw_select_roaming_candidate(mlme) _FAIL
984 #endif /* CONFIG_LAYER2_ROAMING */
985
986 void rtw_sta_media_status_rpt(_adapter *adapter,struct sta_info *psta, u32 mstatus);
987
988 #ifdef CONFIG_INTEL_PROXIM
989 void rtw_proxim_enable(_adapter *padapter);
990 void rtw_proxim_disable(_adapter *padapter);
991 void rtw_proxim_send_packet(_adapter *padapter,u8 *pbuf,u16 len,u8 hw_rate);
992 #endif //CONFIG_INTEL_PROXIM
993 #endif //__RTL871X_MLME_H_
994