net: wireless: rockchip_wlan: add rtl8723cs support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723cs / 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_SCAN_BACKOP
34 #define CONC_SCANNING_TIMEOUT_SINGLE_BAND 10000
35 #define CONC_SCANNING_TIMEOUT_DUAL_BAND 15000
36 #endif
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 /* Linked */
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 #define WIFI_UNDER_WPS                                  0x00000100
54 /*#define WIFI_UNDEFINED_STATE                  0x00000200*/
55 #define WIFI_STA_ALIVE_CHK_STATE                0x00000400
56 #define WIFI_SITE_MONITOR                               0x00000800 /* under site surveying */
57 #define WIFI_WDS                                                0x00001000
58 #define WIFI_WDS_RX_BEACON                              0x00002000 /* already rx WDS AP beacon */
59 #define WIFI_AUTOCONF                                   0x00004000
60 #define WIFI_AUTOCONF_IND                               0x00008000
61 #define WIFI_MP_STATE                                   0x00010000
62 #define WIFI_MP_CTX_BACKGROUND                  0x00020000 /* in continuous tx background */
63 #define WIFI_MP_CTX_ST                                  0x00040000 /* in continuous tx with single-tone */
64 #define WIFI_MP_CTX_BACKGROUND_PENDING  0x00080000 /* pending in continuous tx background due to out of skb */
65 #define WIFI_MP_CTX_CCK_HW                              0x00100000 /* in continuous tx */
66 #define WIFI_MP_CTX_CCK_CS                              0x00200000 /* in continuous tx with carrier suppression */
67 #define WIFI_MP_LPBK_STATE                              0x00400000
68 #define WIFI_OP_CH_SWITCHING                    0x00800000
69 /*#define WIFI_UNDEFINED_STATE                  0x01000000*/
70 /*#define WIFI_UNDEFINED_STATE                  0x02000000*/
71 /*#define WIFI_UNDEFINED_STATE                  0x04000000*/
72 /*#define WIFI_UNDEFINED_STATE                  0x08000000*/
73 /*#define WIFI_UNDEFINED_STATE                  0x10000000*/
74 /*#define WIFI_UNDEFINED_STATE                  0x20000000*/
75 /*#define WIFI_UNDEFINED_STATE                  0x40000000*/
76 #define WIFI_MONITOR_STATE                              0x80000000
77
78 #define MIRACAST_DISABLED       0
79 #define MIRACAST_SOURCE         BIT0
80 #define MIRACAST_SINK           BIT1
81
82 #define MIRACAST_MODE_REVERSE(mode) \
83         ((((mode) & MIRACAST_SOURCE) ? MIRACAST_SINK : 0) | (((mode) & MIRACAST_SINK) ? MIRACAST_SOURCE : 0))
84
85 bool is_miracast_enabled(_adapter *adapter);
86 bool rtw_chk_miracast_mode(_adapter *adapter, u8 mode);
87 const char *get_miracast_mode_str(int mode);
88 void rtw_wfd_st_switch(struct sta_info *sta, bool on);
89
90 #define MLME_STATE(adapter) get_fwstate(&((adapter)->mlmepriv))
91
92 #define MLME_IS_STA(adapter) (MLME_STATE((adapter)) & WIFI_STATION_STATE)
93 #define MLME_IS_AP(adapter) (MLME_STATE((adapter)) & WIFI_AP_STATE)
94 #define MLME_IS_ADHOC(adapter) (MLME_STATE((adapter)) & WIFI_ADHOC_STATE)
95 #define MLME_IS_ADHOC_MASTER(adapter) (MLME_STATE((adapter)) & WIFI_ADHOC_MASTER_STATE)
96 #define MLME_IS_MONITOR(adapter) (MLME_STATE((adapter)) & WIFI_MONITOR_STATE)
97 #define MLME_IS_MP(adapter) (MLME_STATE((adapter)) & WIFI_MP_STATE)
98 #ifdef CONFIG_P2P
99         #define MLME_IS_PD(adapter) rtw_p2p_chk_role(&(adapter)->wdinfo, P2P_ROLE_DEVICE)
100         #define MLME_IS_GC(adapter) rtw_p2p_chk_role(&(adapter)->wdinfo, P2P_ROLE_CLIENT)
101         #define MLME_IS_GO(adapter) rtw_p2p_chk_role(&(adapter)->wdinfo, P2P_ROLE_GO)
102 #else /* !CONFIG_P2P */
103         #define MLME_IS_PD(adapter) 0
104         #define MLME_IS_GC(adapter) 0
105         #define MLME_IS_GO(adapter) 0
106 #endif /* !CONFIG_P2P */
107
108 #if defined(CONFIG_IOCTL_CFG80211) && defined(CONFIG_P2P)
109 #define MLME_IS_ROCH(adapter) (rtw_cfg80211_get_is_roch(adapter) == _TRUE)
110 #else
111 #define MLME_IS_ROCH(adapter) 0
112 #endif
113
114 #define MLME_IS_MSRC(adapter) rtw_chk_miracast_mode((adapter), MIRACAST_SOURCE)
115 #define MLME_IS_MSINK(adapter) rtw_chk_miracast_mode((adapter), MIRACAST_SINK)
116
117 #ifdef CONFIG_IOCTL_CFG80211
118 #define MLME_IS_MGMT_TX(adapter) rtw_cfg80211_get_is_mgmt_tx(adapter)
119 #else
120 #define MLME_IS_MGMT_TX(adapter) 0
121 #endif
122
123 #define MLME_STATE_FMT "%s%s%s%s%s%s%s%s%s%s%s%s"
124 #define MLME_STATE_ARG(adapter) \
125         MLME_IS_STA((adapter)) ? (MLME_IS_GC((adapter)) ? " GC" : " STA") : \
126         MLME_IS_AP((adapter)) ? (MLME_IS_GO((adapter)) ? " GO" : " AP") : \
127         MLME_IS_ADHOC((adapter)) ? " ADHOC" : \
128         MLME_IS_ADHOC_MASTER((adapter)) ? " ADHOC_M" : \
129         MLME_IS_MONITOR((adapter)) ? " MONITOR" : \
130         MLME_IS_MP((adapter)) ? " MP" : "", \
131         MLME_IS_PD((adapter)) ? " PD" : "", \
132         MLME_IS_MSRC((adapter)) ? " MSRC" : "", \
133         MLME_IS_MSINK((adapter)) ? " MSINK" : "", \
134         (MLME_STATE((adapter)) & WIFI_SITE_MONITOR) ? " SCAN" : "", \
135         (MLME_STATE((adapter)) & WIFI_UNDER_LINKING) ? " LINKING" : "", \
136         (MLME_STATE((adapter)) & WIFI_ASOC_STATE) ? " ASOC" : "", \
137         (MLME_STATE((adapter)) & WIFI_OP_CH_SWITCHING) ? " OP_CH_SW" : "", \
138         (MLME_STATE((adapter)) & WIFI_UNDER_WPS) ? " WPS" : "", \
139         MLME_IS_ROCH((adapter)) ? " ROCH" : "", \
140         MLME_IS_MGMT_TX((adapter)) ? " MGMT_TX" : "", \
141         (MLME_STATE((adapter)) & WIFI_SLEEP_STATE) ? " SLEEP" : ""
142
143 #define _FW_UNDER_LINKING       WIFI_UNDER_LINKING
144 #define _FW_LINKED                      WIFI_ASOC_STATE
145 #define _FW_UNDER_SURVEY        WIFI_SITE_MONITOR
146
147
148 enum dot11AuthAlgrthmNum {
149         dot11AuthAlgrthm_Open = 0,
150         dot11AuthAlgrthm_Shared,
151         dot11AuthAlgrthm_8021X,
152         dot11AuthAlgrthm_Auto,
153         dot11AuthAlgrthm_WAPI,
154         dot11AuthAlgrthm_MaxNum
155 };
156
157 /* Scan type including active and passive scan. */
158 typedef enum _RT_SCAN_TYPE {
159         SCAN_PASSIVE,
160         SCAN_ACTIVE,
161         SCAN_MIX,
162 } RT_SCAN_TYPE, *PRT_SCAN_TYPE;
163
164 #define WIFI_FREQUENCY_BAND_AUTO 0
165 #define WIFI_FREQUENCY_BAND_5GHZ 1
166 #define WIFI_FREQUENCY_BAND_2GHZ 2
167
168 #define rtw_band_valid(band) ((band) <= WIFI_FREQUENCY_BAND_2GHZ)
169
170 enum DriverInterface {
171         DRIVER_WEXT =  1,
172         DRIVER_CFG80211 = 2
173 };
174
175 enum SCAN_RESULT_TYPE {
176         SCAN_RESULT_P2P_ONLY = 0,               /*      Will return all the P2P devices. */
177         SCAN_RESULT_ALL = 1,                    /*      Will return all the scanned device, include AP. */
178         SCAN_RESULT_WFD_TYPE = 2                /*      Will just return the correct WFD device. */
179                                                                         /*      If this device is Miracast sink device, it will just return all the Miracast source devices. */
180 };
181
182 /*
183
184 there are several "locks" in mlme_priv,
185 since mlme_priv is a shared resource between many threads,
186 like ISR/Call-Back functions, the OID handlers, and even timer functions.
187
188
189 Each _queue has its own locks, already.
190 Other items are protected by mlme_priv.lock.
191
192 To avoid possible dead lock, any thread trying to modifiying mlme_priv
193 SHALL not lock up more than one locks at a time!
194
195 */
196
197
198 #define traffic_threshold       10
199 #define traffic_scan_period     500
200
201 struct sitesurvey_ctrl {
202         u64     last_tx_pkts;
203         uint    last_rx_pkts;
204         sint    traffic_busy;
205         _timer  sitesurvey_ctrl_timer;
206 };
207
208 typedef struct _RT_LINK_DETECT_T {
209         u32                             NumTxOkInPeriod;
210         u32                             NumRxOkInPeriod;
211         u32                             NumRxUnicastOkInPeriod;
212         BOOLEAN                 bBusyTraffic;
213         BOOLEAN                 bTxBusyTraffic;
214         BOOLEAN                 bRxBusyTraffic;
215         BOOLEAN                 bHigherBusyTraffic; /* For interrupt migration purpose. */
216         BOOLEAN                 bHigherBusyRxTraffic; /* We may disable Tx interrupt according as Rx traffic. */
217         BOOLEAN                 bHigherBusyTxTraffic; /* We may disable Tx interrupt according as Tx traffic. */
218         /* u8 TrafficBusyState; */
219         u8 TrafficTransitionCount;
220         u32 LowPowerTransitionCount;
221 } RT_LINK_DETECT_T, *PRT_LINK_DETECT_T;
222
223 struct profile_info {
224         u8      ssidlen;
225         u8      ssid[WLAN_SSID_MAXLEN];
226         u8      peermac[ETH_ALEN];
227 };
228
229 struct tx_invite_req_info {
230         u8                                      token;
231         u8                                      benable;
232         u8                                      go_ssid[WLAN_SSID_MAXLEN];
233         u8                                      ssidlen;
234         u8                                      go_bssid[ETH_ALEN];
235         u8                                      peer_macaddr[ETH_ALEN];
236         u8                                      operating_ch;   /*      This information will be set by using the p2p_set op_ch=x */
237         u8                                      peer_ch;                /*      The listen channel for peer P2P device */
238
239 };
240
241 struct tx_invite_resp_info {
242         u8                                      token;  /*      Used to record the dialog token of p2p invitation request frame. */
243 };
244
245 #ifdef CONFIG_WFD
246
247 struct wifi_display_info {
248         u16                                                     wfd_enable;                     /*      Eanble/Disable the WFD function. */
249         u16                                                     init_rtsp_ctrlport;     /* init value of rtsp_ctrlport when WFD enable */
250         u16                                                     rtsp_ctrlport;          /* TCP port number at which the this WFD device listens for RTSP messages, 0 when WFD disable */
251         u16                                                     tdls_rtsp_ctrlport;     /* rtsp_ctrlport used by tdls, will sync when rtsp_ctrlport is changed by user */
252         u16                                                     peer_rtsp_ctrlport;     /*      TCP port number at which the peer WFD device listens for RTSP messages */
253                                                                                                         /*      This filed should be filled when receiving the gropu negotiation request */
254
255         u8                                                      peer_session_avail;     /*      WFD session is available or not for the peer wfd device. */
256                                                                                                         /*      This variable will be set when sending the provisioning discovery request to peer WFD device. */
257                                                                                                         /*      And this variable will be reset when it is read by using the iwpriv p2p_get wfd_sa command. */
258         u8                                                      ip_address[4];
259         u8                                                      peer_ip_address[4];
260         u8                                                      wfd_pc;                         /*      WFD preferred connection */
261                                                                                                         /*      0 -> Prefer to use the P2P for WFD connection on peer side. */
262                                                                                                         /*      1 -> Prefer to use the TDLS for WFD connection on peer side. */
263
264         u8                                                      wfd_device_type;        /*      WFD Device Type */
265                                                                                                         /*      0 -> WFD Source Device */
266                                                                                                         /*      1 -> WFD Primary Sink Device */
267         enum    SCAN_RESULT_TYPE        scan_result_type;       /*      Used when P2P is enable. This parameter will impact the scan result. */
268         u8 op_wfd_mode;
269         u8 stack_wfd_mode;
270 };
271 #endif /* CONFIG_WFD */
272
273 struct tx_provdisc_req_info {
274         u16                                     wps_config_method_request;      /*      Used when sending the provisioning request frame */
275         u16                                     peer_channel_num[2];            /*      The channel number which the receiver stands. */
276         NDIS_802_11_SSID        ssid;
277         u8                                      peerDevAddr[ETH_ALEN];          /*      Peer device address */
278         u8                                      peerIFAddr[ETH_ALEN];           /*      Peer interface address */
279         u8                                      benable;                                        /*      This provision discovery request frame is trigger to send or not */
280 };
281
282 struct rx_provdisc_req_info {   /* When peer device issue prov_disc_req first, we should store the following informations */
283         u8                                      peerDevAddr[ETH_ALEN];          /*      Peer device address */
284         u8                                      strconfig_method_desc_of_prov_disc_req[4];      /*      description for the config method located in the provisioning discovery request frame.   */
285                                                                                                                                         /*      The UI must know this information to know which config method the remote p2p device is requiring. */
286 };
287
288 struct tx_nego_req_info {
289         u16                                     peer_channel_num[2];            /*      The channel number which the receiver stands. */
290         u8                                      peerDevAddr[ETH_ALEN];          /*      Peer device address */
291         u8                                      benable;                                        /*      This negoitation request frame is trigger to send or not */
292         u8                                      peer_ch;                                        /*      The listen channel for peer P2P device */
293 };
294
295 struct group_id_info {
296         u8                                      go_device_addr[ETH_ALEN];       /*      The GO's device address of this P2P group */
297         u8                                      ssid[WLAN_SSID_MAXLEN];         /*      The SSID of this P2P group */
298 };
299
300 struct scan_limit_info {
301         u8                                      scan_op_ch_only;                        /*      When this flag is set, the driver should just scan the operation channel */
302 #ifndef CONFIG_P2P_OP_CHK_SOCIAL_CH
303         u8                                      operation_ch[2];                                /*      Store the operation channel of invitation request frame */
304 #else
305         u8                                      operation_ch[5];                                /*      Store additional channel 1,6,11  for Android 4.2 IOT & Nexus 4 */
306 #endif /* CONFIG_P2P_OP_CHK_SOCIAL_CH */
307 };
308
309 #ifdef CONFIG_IOCTL_CFG80211
310 struct cfg80211_wifidirect_info {
311         _timer                                  remain_on_ch_timer;
312         u8                                              restore_channel;
313         struct ieee80211_channel        remain_on_ch_channel;
314         enum nl80211_channel_type       remain_on_ch_type;
315         ATOMIC_T ro_ch_cookie_gen;
316         u64 remain_on_ch_cookie;
317         bool is_ro_ch;
318         struct wireless_dev *ro_ch_wdev;
319         u32 last_ro_ch_time; /* this will be updated at the beginning and end of ro_ch */
320 };
321 #endif /* CONFIG_IOCTL_CFG80211 */
322
323 #ifdef CONFIG_P2P_WOWLAN
324
325 enum P2P_WOWLAN_RECV_FRAME_TYPE {
326         P2P_WOWLAN_RECV_NEGO_REQ = 0,
327         P2P_WOWLAN_RECV_INVITE_REQ = 1,
328         P2P_WOWLAN_RECV_PROVISION_REQ = 2,
329 };
330
331 struct p2p_wowlan_info {
332
333         u8                                              is_trigger;
334         enum P2P_WOWLAN_RECV_FRAME_TYPE wowlan_recv_frame_type;
335         u8                                              wowlan_peer_addr[ETH_ALEN];
336         u16                                             wowlan_peer_wpsconfig;
337         u8                                              wowlan_peer_is_persistent;
338         u8                                              wowlan_peer_invitation_type;
339 };
340
341 #endif /* CONFIG_P2P_WOWLAN */
342
343 struct wifidirect_info {
344         _adapter                                *padapter;
345         _timer                                  find_phase_timer;
346         _timer                                  restore_p2p_state_timer;
347
348         /*      Used to do the scanning. After confirming the peer is availalble, the driver transmits the P2P frame to peer. */
349         _timer                                  pre_tx_scan_timer;
350         _timer                                  reset_ch_sitesurvey;
351         _timer                                  reset_ch_sitesurvey2;   /*      Just for resetting the scan limit function by using p2p nego */
352 #ifdef CONFIG_CONCURRENT_MODE
353         /*      Used to switch the channel between legacy AP and listen state. */
354         _timer                                  ap_p2p_switch_timer;
355 #endif
356         struct tx_provdisc_req_info     tx_prov_disc_info;
357         struct rx_provdisc_req_info rx_prov_disc_info;
358         struct tx_invite_req_info       invitereq_info;
359         struct profile_info                     profileinfo[P2P_MAX_PERSISTENT_GROUP_NUM];      /*      Store the profile information of persistent group */
360         struct tx_invite_resp_info      inviteresp_info;
361         struct tx_nego_req_info nego_req_info;
362         struct group_id_info            groupid_info;   /*      Store the group id information when doing the group negotiation handshake. */
363         struct scan_limit_info          rx_invitereq_info;      /*      Used for get the limit scan channel from the Invitation procedure */
364         struct scan_limit_info          p2p_info;               /*      Used for get the limit scan channel from the P2P negotiation handshake */
365 #ifdef CONFIG_WFD
366         struct wifi_display_info                *wfd_info;
367 #endif
368
369 #ifdef CONFIG_P2P_WOWLAN
370         struct p2p_wowlan_info          p2p_wow_info;
371 #endif /* CONFIG_P2P_WOWLAN */
372
373         enum P2P_ROLE                   role;
374         enum P2P_STATE                  pre_p2p_state;
375         enum P2P_STATE                  p2p_state;
376         u8                                              device_addr[ETH_ALEN];  /*      The device address should be the mac address of this device. */
377         u8                                              interface_addr[ETH_ALEN];
378         u8                                              social_chan[4];
379         u8                                              listen_channel;
380         u8                                              operating_channel;
381         u8                                              listen_dwell;           /*      This value should be between 1 and 3 */
382         u8                                              support_rate[8];
383         u8                                              p2p_wildcard_ssid[P2P_WILDCARD_SSID_LEN];
384         u8                                              intent;         /*      should only include the intent value. */
385         u8                                              p2p_peer_interface_addr[ETH_ALEN];
386         u8                                              p2p_peer_device_addr[ETH_ALEN];
387         u8                                              peer_intent;    /*      Included the intent value and tie breaker value. */
388         u8                                              device_name[WPS_MAX_DEVICE_NAME_LEN];   /*      Device name for displaying on searching device screen */
389         u8                                              device_name_len;
390         u8                                              profileindex;   /*      Used to point to the index of profileinfo array */
391         u8                                              peer_operating_ch;
392         u8                                              find_phase_state_exchange_cnt;
393         u16                                             device_password_id_for_nego;    /*      The device password ID for group negotation */
394         u8                                              negotiation_dialog_token;
395         u8                                              nego_ssid[WLAN_SSID_MAXLEN];    /*      SSID information for group negotitation */
396         u8                                              nego_ssidlen;
397         u8                                              p2p_group_ssid[WLAN_SSID_MAXLEN];
398         u8                                              p2p_group_ssid_len;
399         u8                                              persistent_supported;           /*      Flag to know the persistent function should be supported or not. */
400                                                                                                                 /*      In the Sigma test, the Sigma will provide this enable from the sta_set_p2p CAPI. */
401                                                                                                                 /*      0: disable */
402                                                                                                                 /*      1: enable */
403         u8                                              session_available;                      /*      Flag to set the WFD session available to enable or disable "by Sigma" */
404                                                                                                                 /*      In the Sigma test, the Sigma will disable the session available by using the sta_preset CAPI. */
405                                                                                                                 /*      0: disable */
406                                                                                                                 /*      1: enable */
407
408         u8                                              wfd_tdls_enable;                        /*      Flag to enable or disable the TDLS by WFD Sigma */
409                                                                                                                 /*      0: disable */
410                                                                                                                 /*      1: enable */
411         u8                                              wfd_tdls_weaksec;                       /*      Flag to enable or disable the weak security function for TDLS by WFD Sigma */
412                                                                                                                 /*      0: disable */
413                                                                                                                 /*      In this case, the driver can't issue the tdsl setup request frame. */
414                                                                                                                 /*      1: enable */
415                                                                                                                 /*      In this case, the driver can issue the tdls setup request frame */
416                                                                                                                 /*      even the current security is weak security. */
417
418         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. */
419         u16                                             supported_wps_cm;                       /*      This field describes the WPS config method which this driver supported. */
420                                                                                                                 /*      The value should be the combination of config method defined in page104 of WPS v2.0 spec.        */
421         u8                                              external_uuid;                          /* UUID flag */
422         u8                                              uuid[16];                                       /* UUID */
423         uint                                            channel_list_attr_len;  /*      This field will contain the length of body of P2P Channel List attribute of group negotitation response frame. */
424         u8                                              channel_list_attr[100];         /*      This field will contain the body of P2P Channel List attribute of group negotitation response frame. */
425                                                                                                                 /*      We will use the channel_cnt and channel_list fields when constructing the group negotitation confirm frame. */
426         u8                                              driver_interface;                       /*      Indicate DRIVER_WEXT or DRIVER_CFG80211 */
427
428 #ifdef CONFIG_CONCURRENT_MODE
429         u16                                             ext_listen_interval;    /*      The interval to be available with legacy AP (ms) */
430         u16                                             ext_listen_period;      /*      The time period to be available for P2P listen state (ms) */
431 #endif
432 #ifdef CONFIG_P2P_PS
433         enum P2P_PS_MODE                p2p_ps_mode; /* indicate p2p ps mode */
434         enum P2P_PS_STATE               p2p_ps_state; /* indicate p2p ps state */
435         u8                                              noa_index; /* Identifies and instance of Notice of Absence timing. */
436         u8                                              ctwindow; /* Client traffic window. A period of time in TU after TBTT. */
437         u8                                              opp_ps; /* opportunistic power save. */
438         u8                                              noa_num; /* number of NoA descriptor in P2P IE. */
439         u8                                              noa_count[P2P_MAX_NOA_NUM]; /* Count for owner, Type of client. */
440         u32                                             noa_duration[P2P_MAX_NOA_NUM]; /* Max duration for owner, preferred or min acceptable duration for client. */
441         u32                                             noa_interval[P2P_MAX_NOA_NUM]; /* Length of interval for owner, preferred or max acceptable interval of client. */
442         u32                                             noa_start_time[P2P_MAX_NOA_NUM]; /* schedule expressed in terms of the lower 4 bytes of the TSF timer. */
443 #endif /* CONFIG_P2P_PS */
444 };
445
446 struct tdls_ss_record { /* signal strength record */
447         u8              macaddr[ETH_ALEN];
448         u8              RxPWDBAll;
449         u8              is_tdls_sta;    /* _TRUE: direct link sta, _FALSE: else */
450 };
451
452 struct tdls_temp_mgmt {
453         u8      initiator;      /* 0: None, 1: we initiate, 2: peer initiate */
454         u8      peer_addr[ETH_ALEN];
455 };
456
457 #ifdef CONFIG_TDLS_CH_SW
458 struct tdls_ch_switch {
459         u32     ch_sw_state;
460         ATOMIC_T        chsw_on;
461         u8      addr[ETH_ALEN];
462         u8      off_ch_num;
463         u8      ch_offset;
464         u32     cur_time;
465         u8      delay_switch_back;
466         u8      dump_stack;
467         struct submit_ctx       chsw_sctx;
468 };
469 #endif
470
471 struct tdls_info {
472         u8                                      ap_prohibited;
473         u8                                      ch_switch_prohibited;
474         u8                                      link_established;
475         u8                                      sta_cnt;
476         u8                                      sta_maximum;    /* 1:tdls sta is equal (NUM_STA-1), reach max direct link number; 0: else; */
477         struct tdls_ss_record   ss_record;
478 #ifdef CONFIG_TDLS_CH_SW
479         struct tdls_ch_switch   chsw_info;
480 #endif
481
482         u8                                      ch_sensing;
483         u8                                      cur_channel;
484         u8                                      collect_pkt_num[MAX_CHANNEL_NUM];
485         _lock                           cmd_lock;
486         _lock                           hdl_lock;
487         u8                                      watchdog_count;
488         u8                                      dev_discovered;         /* WFD_TDLS: for sigma test */
489         u8                                      tdls_enable;
490
491         /* Let wpa_supplicant to setup*/
492         u8                                      driver_setup;
493 #ifdef CONFIG_WFD
494         struct wifi_display_info                *wfd_info;
495 #endif
496 };
497
498 struct tdls_txmgmt {
499         u8 peer[ETH_ALEN];
500         u8 action_code;
501         u8 dialog_token;
502         u16 status_code;
503         u8 *buf;
504         size_t len;
505 };
506
507 /* used for mlme_priv.roam_flags */
508 enum {
509         RTW_ROAM_ON_EXPIRED = BIT0,
510         RTW_ROAM_ON_RESUME = BIT1,
511         RTW_ROAM_ACTIVE = BIT2,
512 };
513
514 struct beacon_keys {
515         u8 ssid[IW_ESSID_MAX_SIZE];
516         u32 ssid_len;
517         u8 bcn_channel;
518         u16 ht_cap_info;
519         u8 ht_info_infos_0_sco; /* bit0 & bit1 in infos[0] is second channel offset */
520         int encryp_protocol;
521         int pairwise_cipher;
522         int group_cipher;
523         int is_8021x;
524 };
525 #ifdef CONFIG_RTW_80211R
526 #define FT_ACTION_REQ_LIMIT     4
527
528 typedef enum _RTW_WIFI_FT_STA_STATUS {
529         RTW_FT_UNASSOCIATED_STA = 0,
530         RTW_FT_AUTHENTICATING_STA,
531         RTW_FT_AUTHENTICATED_STA,
532         RTW_FT_ASSOCIATING_STA,
533         RTW_FT_ASSOCIATED_STA,
534         RTW_FT_REQUESTING_STA,
535         RTW_FT_REQUESTED_STA,
536         RTW_FT_CONFIRMED_STA,
537         RTW_FT_UNSPECIFIED_STA
538 } RTW_WIFI_FT_STA_STATUS;
539
540 #define rtw_chk_ft_status(adapter, status) ((adapter)->mlmepriv.ftpriv.ft_status == status)
541 #define rtw_set_ft_status(adapter, status) \
542         do { \
543                 ((adapter)->mlmepriv.ftpriv.ft_status = status); \
544         } while (0)
545
546 #define rtw_reset_ft_status(adapter) \
547         do { \
548                 ((adapter)->mlmepriv.ftpriv.ft_status = RTW_FT_UNASSOCIATED_STA); \
549         } while (0)
550
551 typedef enum _RTW_WIFI_FT_CAPABILITY {
552         RTW_FT_STA_SUPPORTED = BIT0,
553         RTW_FT_STA_OVER_DS_SUPPORTED = BIT1,
554         RTW_FT_SUPPORTED = BIT2,
555         RTW_FT_OVER_DS_SUPPORTED = BIT3,
556 } RTW_WIFI_FT_CAPABILITY;
557
558 #define rtw_chk_ft_flags(adapter, flags) ((adapter)->mlmepriv.ftpriv.ft_flags & (flags))
559 #define rtw_set_ft_flags(adapter, flags) \
560         do { \
561                 ((adapter)->mlmepriv.ftpriv.ft_flags |= (flags)); \
562         } while (0)
563
564 #define rtw_clr_ft_flags(adapter, flags) \
565         do { \
566                 ((adapter)->mlmepriv.ftpriv.ft_flags &= ~(flags)); \
567         } while (0)
568
569 #define RTW_MAX_FTIE_SZ 256
570 typedef struct _ft_priv {
571         u16     mdid;
572         u8      ft_cap; /*b0: FT over DS, b1: Resource Req Protocol Cap, b2~b7: Reserved*/
573         u8      updated_ft_ies[RTW_MAX_FTIE_SZ];
574         u16     updated_ft_ies_len;
575         u8      ft_action[RTW_MAX_FTIE_SZ];
576         u16     ft_action_len;
577         struct cfg80211_ft_event_params ft_event;
578         u8      ft_roam_on_expired;
579         u8      ft_flags;
580         u32 ft_status;
581         u32 ft_req_retry_cnt;
582 } ft_priv;
583 #endif
584
585 struct mlme_priv {
586
587         _lock   lock;
588         sint    fw_state;       /* shall we protect this variable? maybe not necessarily... */
589         u8 bScanInProcess;
590         u8      to_join; /* flag */
591 #ifdef CONFIG_LAYER2_ROAMING
592         u8 to_roam; /* roaming trying times */
593         struct wlan_network *roam_network; /* the target of active roam */
594         u8 roam_flags;
595         u8 roam_rssi_diff_th; /* rssi difference threshold for active scan candidate selection */
596         u32 roam_scan_int_ms; /* scan interval for active roam */
597         u32 roam_scanr_exp_ms; /* scan result expire time in ms  for roam */
598         u8 roam_tgt_addr[ETH_ALEN]; /* request to roam to speicific target without other consideration */
599         u8 roam_rssi_threshold;
600         bool need_to_roam;
601 #endif
602
603         u8      *nic_hdl;
604
605 #ifdef SUPPLICANT_RTK_VERSION_LOWER_THAN_JB42
606         u8      not_indic_disco;
607 #endif
608         _list           *pscanned;
609         _queue  free_bss_pool;
610         _queue  scanned_queue;
611         u8              *free_bss_buf;
612         u32     num_of_scanned;
613
614         NDIS_802_11_SSID        assoc_ssid;
615         u8      assoc_bssid[6];
616
617         struct wlan_network     cur_network;
618         struct wlan_network *cur_network_scanned;
619
620         /* bcn check info */
621         struct beacon_keys cur_beacon_keys; /* save current beacon keys */
622         struct beacon_keys new_beacon_keys; /* save new beacon keys */
623         u8 new_beacon_cnts; /* if new_beacon_cnts >= threshold, ap beacon is changed */
624
625 #ifdef CONFIG_ARP_KEEP_ALIVE
626         /* for arp offload keep alive */
627         u8 bGetGateway;
628         u8      GetGatewayTryCnt;
629         u8      gw_mac_addr[6];
630         u8      gw_ip[4];
631 #endif
632
633         /* uint wireless_mode; no used, remove it */
634
635         u32     auto_scan_int_ms;
636
637         _timer assoc_timer;
638
639         uint assoc_by_bssid;
640         uint assoc_by_rssi;
641
642         _timer scan_to_timer; /* driver itself handles scan_timeout status. */
643         u32 scan_start_time; /* used to evaluate the time spent in scanning */
644
645 #ifdef CONFIG_SET_SCAN_DENY_TIMER
646         _timer set_scan_deny_timer;
647         ATOMIC_T set_scan_deny; /* 0: allowed, 1: deny */
648 #endif
649
650         struct qos_priv qospriv;
651
652 #ifdef CONFIG_80211N_HT
653
654         /* Number of non-HT AP/stations */
655         int num_sta_no_ht;
656
657         /* Number of HT AP/stations 20 MHz */
658         /* int num_sta_ht_20mhz; */
659
660
661         int num_FortyMHzIntolerant;
662
663         struct ht_priv  htpriv;
664
665 #endif
666
667 #ifdef CONFIG_80211AC_VHT
668         struct vht_priv vhtpriv;
669 #endif
670 #ifdef CONFIG_BEAMFORMING
671 #ifndef RTW_BEAMFORMING_VERSION_2
672 #if (BEAMFORMING_SUPPORT == 0)/*for driver beamforming*/
673         struct beamforming_info beamforming_info;
674 #endif
675 #endif /* !RTW_BEAMFORMING_VERSION_2 */
676 #endif
677
678 #ifdef CONFIG_DFS
679         u8      handle_dfs;
680 #endif
681 #ifdef CONFIG_DFS_MASTER
682         /* TODO: move to rfctl */
683         _timer dfs_master_timer;
684 #endif
685 #ifdef CONFIG_RTW_80211R
686         ft_priv ftpriv;
687 #endif
688
689         RT_LINK_DETECT_T        LinkDetectInfo;
690
691         u8      acm_mask; /* for wmm acm mask */
692         const struct country_chplan *country_ent;
693         u8      ChannelPlan;
694         RT_SCAN_TYPE    scan_mode; /* active: 1, passive: 0 */
695
696         u8 *wps_probe_req_ie;
697         u32 wps_probe_req_ie_len;
698
699         u8 ext_capab_ie_data[8];/*currently for ap mode only*/
700         u8 ext_capab_ie_len;
701
702 #if defined(CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
703         /* Number of associated Non-ERP stations (i.e., stations using 802.11b
704          * in 802.11g BSS) */
705         int num_sta_non_erp;
706
707         /* Number of associated stations that do not support Short Slot Time */
708         int num_sta_no_short_slot_time;
709
710         /* Number of associated stations that do not support Short Preamble */
711         int num_sta_no_short_preamble;
712
713         ATOMIC_T olbc; /* Overlapping Legacy BSS Condition (Legacy b/g)*/
714
715         /* Number of HT associated stations that do not support greenfield */
716         int num_sta_ht_no_gf;
717
718         /* Number of associated non-HT stations */
719         /* int num_sta_no_ht; */
720
721         /* Number of HT associated stations 20 MHz */
722         int num_sta_ht_20mhz;
723
724         /* number of associated stations 40MHz intolerant */
725         int num_sta_40mhz_intolerant;
726
727         /* Overlapping BSS information */
728         ATOMIC_T olbc_ht;
729
730 #ifdef CONFIG_80211N_HT
731         int ht_20mhz_width_req;
732         int ht_intolerant_ch_reported;
733         u16 ht_op_mode;
734         u8 sw_to_20mhz; /*switch to 20Mhz BW*/
735 #endif /* CONFIG_80211N_HT */
736
737 #ifdef CONFIG_RTW_80211R
738         u8 *auth_rsp;
739         u32 auth_rsp_len;
740 #endif
741         u8 *assoc_req;
742         u32 assoc_req_len;
743
744         u8 *assoc_rsp;
745         u32 assoc_rsp_len;
746
747         /* u8 *wps_probe_req_ie; */
748         /* u32 wps_probe_req_ie_len; */
749
750         u8 *wps_beacon_ie;
751         u32 wps_beacon_ie_len;
752
753         u8 *wps_probe_resp_ie;
754         u32 wps_probe_resp_ie_len;
755
756         u8 *wps_assoc_resp_ie;
757         u32 wps_assoc_resp_ie_len;
758
759         u8 *p2p_beacon_ie;
760         u32 p2p_beacon_ie_len;
761
762         u8 *p2p_probe_req_ie;
763         u32 p2p_probe_req_ie_len;
764
765         u8 *p2p_probe_resp_ie;
766         u32 p2p_probe_resp_ie_len;
767
768         u8 *p2p_go_probe_resp_ie;               /* for GO */
769         u32 p2p_go_probe_resp_ie_len;   /* for GO */
770
771         u8 *p2p_assoc_req_ie;
772         u32 p2p_assoc_req_ie_len;
773
774         u8 *p2p_assoc_resp_ie;
775         u32 p2p_assoc_resp_ie_len;
776
777         _lock   bcn_update_lock;
778         u8              update_bcn;
779
780         u8 ori_ch;
781         u8 ori_bw;
782         u8 ori_offset;
783 #endif /* #if defined (CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME) */
784
785 #if defined(CONFIG_WFD) && defined(CONFIG_IOCTL_CFG80211)
786         u8 *wfd_beacon_ie;
787         u32 wfd_beacon_ie_len;
788
789         u8 *wfd_probe_req_ie;
790         u32 wfd_probe_req_ie_len;
791
792         u8 *wfd_probe_resp_ie;
793         u32 wfd_probe_resp_ie_len;
794
795         u8 *wfd_go_probe_resp_ie;               /* for GO */
796         u32 wfd_go_probe_resp_ie_len;   /* for GO */
797
798         u8 *wfd_assoc_req_ie;
799         u32 wfd_assoc_req_ie_len;
800
801         u8 *wfd_assoc_resp_ie;
802         u32 wfd_assoc_resp_ie_len;
803 #endif
804
805 #ifdef RTK_DMP_PLATFORM
806         /* DMP kobject_hotplug function  signal need in passive level */
807         _workitem       Linkup_workitem;
808         _workitem       Linkdown_workitem;
809 #endif
810
811 #ifdef CONFIG_INTEL_WIDI
812         int     widi_state;
813         int     listen_state;
814         _timer  listen_timer;
815         ATOMIC_T        rx_probe_rsp; /* 1:receive probe respone from RDS source. */
816         u8      *l2sdTaBuffer;
817         u8      channel_idx;
818         u8      group_cnt;      /* In WiDi 3.5, they specified another scan algo. for WFD/RDS co-existed */
819         u8      sa_ext[L2SDTA_SERVICE_VE_LEN];
820
821         u8      widi_enable;
822         /**
823          * For WiDi 4; upper layer would set
824          * p2p_primary_device_type_category_id
825          * p2p_primary_device_type_sub_category_id
826          * p2p_secondary_device_type_category_id
827          * p2p_secondary_device_type_sub_category_id
828          */
829         u16     p2p_pdt_cid;
830         u16     p2p_pdt_scid;
831         u8      num_p2p_sdt;
832         u16     p2p_sdt_cid[MAX_NUM_P2P_SDT];
833         u16     p2p_sdt_scid[MAX_NUM_P2P_SDT];
834         u8      p2p_reject_disable;     /* When starting NL80211 wpa_supplicant/hostapd, it will call netdev_close */
835                                                         /* such that it will cause p2p disabled. Use this flag to reject. */
836 #endif /* CONFIG_INTEL_WIDI */
837         u32 lastscantime;
838 #ifdef CONFIG_CONCURRENT_MODE
839         u8      scanning_via_buddy_intf;
840 #endif
841
842 #if 0
843         u8      NumOfBcnInfoChkFail;
844         u32     timeBcnInfoChkStart;
845 #endif
846
847 #ifdef CONFIG_APPEND_VENDOR_IE_ENABLE
848         u32 vendor_ie_mask[WLAN_MAX_VENDOR_IE_NUM];
849         u8 vendor_ie[WLAN_MAX_VENDOR_IE_NUM][WLAN_MAX_VENDOR_IE_LEN];
850         u32 vendor_ielen[WLAN_MAX_VENDOR_IE_NUM];
851 #endif
852 };
853
854 #define mlme_set_scan_to_timer(mlme, ms) \
855         do { \
856                 /* RTW_INFO("%s set_scan_to_timer(%p, %d)\n", __FUNCTION__, (mlme), (ms)); */ \
857                 _set_timer(&(mlme)->scan_to_timer, (ms)); \
858         } while (0)
859
860 #define rtw_mlme_set_auto_scan_int(adapter, ms) \
861         do { \
862                 adapter->mlmepriv.auto_scan_int_ms = ms; \
863         } while (0)
864
865 #define RTW_AUTO_SCAN_REASON_UNSPECIFIED        0
866 #define RTW_AUTO_SCAN_REASON_2040_BSS           BIT0
867 #define RTW_AUTO_SCAN_REASON_ACS                        BIT1
868 #define RTW_AUTO_SCAN_REASON_ROAM                       BIT2
869
870 void rtw_mlme_reset_auto_scan_int(_adapter *adapter, u8 *reason);
871
872 #ifdef CONFIG_AP_MODE
873
874 struct hostapd_priv {
875         _adapter *padapter;
876
877 #ifdef CONFIG_HOSTAPD_MLME
878         struct net_device *pmgnt_netdev;
879         struct usb_anchor anchored;
880 #endif
881
882 };
883
884 extern int hostapd_mode_init(_adapter *padapter);
885 extern void hostapd_mode_unload(_adapter *padapter);
886 #endif
887
888
889 extern void rtw_joinbss_event_prehandle(_adapter *adapter, u8 *pbuf);
890 extern void rtw_survey_event_callback(_adapter *adapter, u8 *pbuf);
891 extern void rtw_surveydone_event_callback(_adapter *adapter, u8 *pbuf);
892 extern void rtw_joinbss_event_callback(_adapter *adapter, u8 *pbuf);
893 extern void rtw_stassoc_event_callback(_adapter *adapter, u8 *pbuf);
894 extern void rtw_stadel_event_callback(_adapter *adapter, u8 *pbuf);
895 void rtw_sta_mstatus_report(_adapter *adapter);
896 extern void rtw_atimdone_event_callback(_adapter *adapter, u8 *pbuf);
897 extern void rtw_cpwm_event_callback(_adapter *adapter, u8 *pbuf);
898 extern void rtw_wmm_event_callback(PADAPTER padapter, u8 *pbuf);
899 #ifdef CONFIG_IEEE80211W
900 void rtw_sta_timeout_event_callback(_adapter *adapter, u8 *pbuf);
901 #endif /* CONFIG_IEEE80211W */
902 #ifdef CONFIG_RTW_80211R
903 void rtw_update_ft_stainfo(_adapter *padapter, WLAN_BSSID_EX *pnetwork);
904 void rtw_ft_reassoc_event_callback(_adapter *padapter, u8 *pbuf);
905 #endif
906 extern void rtw_join_timeout_handler(RTW_TIMER_HDL_ARGS);
907 extern void _rtw_scan_timeout_handler(RTW_TIMER_HDL_ARGS);
908
909 thread_return event_thread(thread_context context);
910
911 extern void rtw_free_network_queue(_adapter *adapter, u8 isfreeall);
912 extern int rtw_init_mlme_priv(_adapter *adapter);/* (struct mlme_priv *pmlmepriv); */
913
914 extern void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv);
915
916
917 extern sint rtw_select_and_join_from_scanned_queue(struct mlme_priv *pmlmepriv);
918 extern sint rtw_set_key(_adapter *adapter, struct security_priv *psecuritypriv, sint keyid, u8 set_tx, bool enqueue);
919 extern sint rtw_set_auth(_adapter *adapter, struct security_priv *psecuritypriv);
920
921 __inline static u8 *get_bssid(struct mlme_priv *pmlmepriv)
922 {
923         /* if sta_mode:pmlmepriv->cur_network.network.MacAddress=> bssid */
924         /* if adhoc_mode:pmlmepriv->cur_network.network.MacAddress=> ibss mac address */
925         return pmlmepriv->cur_network.network.MacAddress;
926 }
927
928 __inline static sint check_fwstate(struct mlme_priv *pmlmepriv, sint state)
929 {
930         if ((state == WIFI_NULL_STATE) &&
931                 (pmlmepriv->fw_state == WIFI_NULL_STATE))
932                 return _TRUE;
933
934         if (pmlmepriv->fw_state & state)
935                 return _TRUE;
936
937         return _FALSE;
938 }
939
940 __inline static sint get_fwstate(struct mlme_priv *pmlmepriv)
941 {
942         return pmlmepriv->fw_state;
943 }
944
945 /*
946  * No Limit on the calling context,
947  * therefore set it to be the critical section...
948  *
949  * ### NOTE:#### (!!!!)
950  * MUST TAKE CARE THAT BEFORE CALLING THIS FUNC, YOU SHOULD HAVE LOCKED pmlmepriv->lock
951  */
952 extern void rtw_mi_update_iface_status(struct mlme_priv *pmlmepriv, sint state);
953
954 static inline void set_fwstate(struct mlme_priv *pmlmepriv, sint state)
955 {
956         pmlmepriv->fw_state |= state;
957
958         /*bScanInProcess hook in phydm*/
959         if (_FW_UNDER_SURVEY == state)
960                 pmlmepriv->bScanInProcess = _TRUE;
961
962         rtw_mi_update_iface_status(pmlmepriv, state);
963 }
964 static inline void init_fwstate(struct mlme_priv *pmlmepriv, sint state)
965 {
966         pmlmepriv->fw_state = state;
967
968         /*bScanInProcess hook in phydm*/
969         if (_FW_UNDER_SURVEY == state)
970                 pmlmepriv->bScanInProcess = _TRUE;
971
972         rtw_mi_update_iface_status(pmlmepriv, state);
973 }
974
975 static inline void _clr_fwstate_(struct mlme_priv *pmlmepriv, sint state)
976 {
977         pmlmepriv->fw_state &= ~state;
978
979         /*bScanInProcess hook in phydm*/
980         if (_FW_UNDER_SURVEY == state)
981                 pmlmepriv->bScanInProcess = _FALSE;
982
983         rtw_mi_update_iface_status(pmlmepriv, state);
984 }
985
986 /*
987  * No Limit on the calling context,
988  * therefore set it to be the critical section...
989  */
990 static inline void clr_fwstate(struct mlme_priv *pmlmepriv, sint state)
991 {
992         _irqL irqL;
993
994         _enter_critical_bh(&pmlmepriv->lock, &irqL);
995         _clr_fwstate_(pmlmepriv, state);
996         _exit_critical_bh(&pmlmepriv->lock, &irqL);
997 }
998
999 static inline void up_scanned_network(struct mlme_priv *pmlmepriv)
1000 {
1001         _irqL irqL;
1002
1003         _enter_critical_bh(&pmlmepriv->lock, &irqL);
1004         pmlmepriv->num_of_scanned++;
1005         _exit_critical_bh(&pmlmepriv->lock, &irqL);
1006 }
1007 u8 rtw_is_adapter_up(_adapter *padapter);
1008
1009 __inline static void down_scanned_network(struct mlme_priv *pmlmepriv)
1010 {
1011         _irqL irqL;
1012
1013         _enter_critical_bh(&pmlmepriv->lock, &irqL);
1014         pmlmepriv->num_of_scanned--;
1015         _exit_critical_bh(&pmlmepriv->lock, &irqL);
1016 }
1017
1018 __inline static void set_scanned_network_val(struct mlme_priv *pmlmepriv, sint val)
1019 {
1020         _irqL irqL;
1021
1022         _enter_critical_bh(&pmlmepriv->lock, &irqL);
1023         pmlmepriv->num_of_scanned = val;
1024         _exit_critical_bh(&pmlmepriv->lock, &irqL);
1025 }
1026
1027 extern u16 rtw_get_capability(WLAN_BSSID_EX *bss);
1028 extern void rtw_update_scanned_network(_adapter *adapter, WLAN_BSSID_EX *target);
1029 extern void rtw_disconnect_hdl_under_linked(_adapter *adapter, struct sta_info *psta, u8 free_assoc);
1030 extern void rtw_generate_random_ibss(u8 *pibss);
1031 extern struct wlan_network *rtw_find_network(_queue *scanned_queue, u8 *addr);
1032 extern struct wlan_network *rtw_get_oldest_wlan_network(_queue *scanned_queue);
1033 struct wlan_network *_rtw_find_same_network(_queue *scanned_queue, struct wlan_network *network);
1034 struct wlan_network *rtw_find_same_network(_queue *scanned_queue, struct wlan_network *network);
1035
1036 extern void rtw_free_assoc_resources(_adapter *adapter, int lock_scanned_queue);
1037 extern void rtw_indicate_disconnect(_adapter *adapter, u16 reason, u8 locally_generated);
1038 extern void rtw_indicate_connect(_adapter *adapter);
1039 void rtw_indicate_scan_done(_adapter *padapter, bool aborted);
1040
1041 void rtw_drv_scan_by_self(_adapter *padapter, u8 reason);
1042 void rtw_scan_wait_completed(_adapter *adapter);
1043 u32 rtw_scan_abort_timeout(_adapter *adapter, u32 timeout_ms);
1044 void rtw_scan_abort_no_wait(_adapter *adapter);
1045 void rtw_scan_abort(_adapter *adapter);
1046
1047 extern int rtw_restruct_sec_ie(_adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_len);
1048 extern int rtw_restruct_wmm_ie(_adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_len, uint initial_out_len);
1049 extern void rtw_init_registrypriv_dev_network(_adapter *adapter);
1050
1051 extern void rtw_update_registrypriv_dev_network(_adapter *adapter);
1052
1053 extern void rtw_get_encrypt_decrypt_from_registrypriv(_adapter *adapter);
1054
1055 extern void _rtw_join_timeout_handler(_adapter *adapter);
1056 extern void rtw_scan_timeout_handler(_adapter *adapter);
1057
1058 extern void _dynamic_check_timer_handlder(void *FunctionContext);
1059 extern void rtw_dynamic_check_timer_handlder(_adapter *adapter);
1060 extern void rtw_iface_dynamic_check_timer_handlder(_adapter *adapter);
1061
1062 #ifdef CONFIG_SET_SCAN_DENY_TIMER
1063 bool rtw_is_scan_deny(_adapter *adapter);
1064 void rtw_clear_scan_deny(_adapter *adapter);
1065 void rtw_set_scan_deny_timer_hdl(_adapter *adapter);
1066 void rtw_set_scan_deny(_adapter *adapter, u32 ms);
1067 #else
1068 #define rtw_is_scan_deny(adapter) _FALSE
1069 #define rtw_clear_scan_deny(adapter) do {} while (0)
1070 #define rtw_set_scan_deny_timer_hdl(adapter) do {} while (0)
1071 #define rtw_set_scan_deny(adapter, ms) do {} while (0)
1072 #endif
1073
1074 void rtw_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv);
1075
1076 #define MLME_BEACON_IE                  0
1077 #define MLME_PROBE_REQ_IE               1
1078 #define MLME_PROBE_RESP_IE              2
1079 #define MLME_GO_PROBE_RESP_IE   3
1080 #define MLME_ASSOC_REQ_IE               4
1081 #define MLME_ASSOC_RESP_IE              5
1082
1083 #if defined(CONFIG_WFD) && defined(CONFIG_IOCTL_CFG80211)
1084 int rtw_mlme_update_wfd_ie_data(struct mlme_priv *mlme, u8 type, u8 *ie, u32 ie_len);
1085 #endif
1086
1087
1088 /* extern struct wlan_network* _rtw_dequeue_network(_queue *queue); */
1089
1090 extern struct wlan_network *_rtw_alloc_network(struct mlme_priv *pmlmepriv);
1091
1092
1093 extern void _rtw_free_network(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork, u8 isfreeall);
1094 extern void _rtw_free_network_nolock(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork);
1095
1096
1097 extern struct wlan_network *_rtw_find_network(_queue *scanned_queue, u8 *addr);
1098
1099 extern void _rtw_free_network_queue(_adapter *padapter, u8 isfreeall);
1100
1101 extern sint rtw_if_up(_adapter *padapter);
1102
1103 sint rtw_linked_check(_adapter *padapter);
1104
1105 u8 *rtw_get_capability_from_ie(u8 *ie);
1106 u8 *rtw_get_timestampe_from_ie(u8 *ie);
1107 u8 *rtw_get_beacon_interval_from_ie(u8 *ie);
1108
1109
1110 void rtw_joinbss_reset(_adapter *padapter);
1111
1112 #ifdef CONFIG_80211N_HT
1113 void    rtw_ht_use_default_setting(_adapter *padapter);
1114 void rtw_build_wmm_ie_ht(_adapter *padapter, u8 *out_ie, uint *pout_len);
1115 unsigned int rtw_restructure_ht_ie(_adapter *padapter, u8 *in_ie, u8 *out_ie, uint in_len, uint *pout_len, u8 channel);
1116 void rtw_update_ht_cap(_adapter *padapter, u8 *pie, uint ie_len, u8 channel);
1117 void rtw_issue_addbareq_cmd(_adapter *padapter, struct xmit_frame *pxmitframe);
1118 void rtw_append_exented_cap(_adapter *padapter, u8 *out_ie, uint *pout_len);
1119 #endif
1120
1121 int rtw_is_same_ibss(_adapter *adapter, struct wlan_network *pnetwork);
1122 int is_same_network(WLAN_BSSID_EX *src, WLAN_BSSID_EX *dst, u8 feature);
1123
1124 #ifdef CONFIG_LAYER2_ROAMING
1125 #define rtw_roam_flags(adapter) ((adapter)->mlmepriv.roam_flags)
1126 #define rtw_chk_roam_flags(adapter, flags) ((adapter)->mlmepriv.roam_flags & flags)
1127 #define rtw_clr_roam_flags(adapter, flags) \
1128         do { \
1129                 ((adapter)->mlmepriv.roam_flags &= ~flags); \
1130         } while (0)
1131
1132 #define rtw_set_roam_flags(adapter, flags) \
1133         do { \
1134                 ((adapter)->mlmepriv.roam_flags |= flags); \
1135         } while (0)
1136
1137 #define rtw_assign_roam_flags(adapter, flags) \
1138         do { \
1139                 ((adapter)->mlmepriv.roam_flags = flags); \
1140         } while (0)
1141
1142 void _rtw_roaming(_adapter *adapter, struct wlan_network *tgt_network);
1143 void rtw_roaming(_adapter *adapter, struct wlan_network *tgt_network);
1144 void rtw_set_to_roam(_adapter *adapter, u8 to_roam);
1145 u8 rtw_dec_to_roam(_adapter *adapter);
1146 u8 rtw_to_roam(_adapter *adapter);
1147 int rtw_select_roaming_candidate(struct mlme_priv *pmlmepriv);
1148 #else
1149 #define rtw_roam_flags(adapter) 0
1150 #define rtw_chk_roam_flags(adapter, flags) 0
1151 #define rtw_clr_roam_flags(adapter, flags) do {} while (0)
1152 #define rtw_set_roam_flags(adapter, flags) do {} while (0)
1153 #define rtw_assign_roam_flags(adapter, flags) do {} while (0)
1154 #define _rtw_roaming(adapter, tgt_network) do {} while (0)
1155 #define rtw_roaming(adapter, tgt_network) do {} while (0)
1156 #define rtw_set_to_roam(adapter, to_roam) do {} while (0)
1157 #define rtw_dec_to_roam(adapter) 0
1158 #define rtw_to_roam(adapter) 0
1159 #define rtw_select_roaming_candidate(mlme) _FAIL
1160 #endif /* CONFIG_LAYER2_ROAMING */
1161
1162 bool rtw_adjust_chbw(_adapter *adapter, u8 req_ch, u8 *req_bw, u8 *req_offset);
1163
1164 struct sta_media_status_rpt_cmd_parm {
1165         struct sta_info *sta;
1166         bool connected;
1167 };
1168
1169 void rtw_sta_media_status_rpt(_adapter *adapter, struct sta_info *sta, bool connected);
1170 u8 rtw_sta_media_status_rpt_cmd(_adapter *adapter, struct sta_info *sta, bool connected);
1171 void rtw_sta_media_status_rpt_cmd_hdl(_adapter *adapter, struct sta_media_status_rpt_cmd_parm *parm);
1172
1173 #ifdef CONFIG_INTEL_PROXIM
1174 void rtw_proxim_enable(_adapter *padapter);
1175 void rtw_proxim_disable(_adapter *padapter);
1176 void rtw_proxim_send_packet(_adapter *padapter, u8 *pbuf, u16 len, u8 m_rate);
1177 #endif /* CONFIG_INTEL_PROXIM */
1178
1179 #define IPV4_SRC(_iphdr)                        (((u8 *)(_iphdr)) + 12)
1180 #define IPV4_DST(_iphdr)                        (((u8 *)(_iphdr)) + 16)
1181 #define GET_IPV4_IHL(_iphdr)            BE_BITS_TO_1BYTE(((u8 *)(_iphdr)) + 0, 0, 4)
1182 #define GET_IPV4_PROTOCOL(_iphdr)       BE_BITS_TO_1BYTE(((u8 *)(_iphdr)) + 9, 0, 8)
1183 #define GET_IPV4_SRC(_iphdr)            BE_BITS_TO_4BYTE(((u8 *)(_iphdr)) + 12, 0, 32)
1184 #define GET_IPV4_DST(_iphdr)            BE_BITS_TO_4BYTE(((u8 *)(_iphdr)) + 16, 0, 32)
1185
1186 #define GET_UDP_SRC(_udphdr)                    BE_BITS_TO_2BYTE(((u8 *)(_udphdr)) + 0, 0, 16)
1187 #define GET_UDP_DST(_udphdr)                    BE_BITS_TO_2BYTE(((u8 *)(_udphdr)) + 2, 0, 16)
1188
1189 #define TCP_SRC(_tcphdr)                                (((u8 *)(_tcphdr)) + 0)
1190 #define TCP_DST(_tcphdr)                                (((u8 *)(_tcphdr)) + 2)
1191 #define GET_TCP_SRC(_tcphdr)                    BE_BITS_TO_2BYTE(((u8 *)(_tcphdr)) + 0, 0, 16)
1192 #define GET_TCP_DST(_tcphdr)                    BE_BITS_TO_2BYTE(((u8 *)(_tcphdr)) + 2, 0, 16)
1193 #define GET_TCP_SEQ(_tcphdr)                    BE_BITS_TO_4BYTE(((u8 *)(_tcphdr)) + 4, 0, 32)
1194 #define GET_TCP_ACK_SEQ(_tcphdr)                BE_BITS_TO_4BYTE(((u8 *)(_tcphdr)) + 8, 0, 32)
1195 #define GET_TCP_DOFF(_tcphdr)                   BE_BITS_TO_1BYTE(((u8 *)(_tcphdr)) + 12, 4, 4)
1196 #define GET_TCP_FIN(_tcphdr)                    BE_BITS_TO_1BYTE(((u8 *)(_tcphdr)) + 13, 0, 1)
1197 #define GET_TCP_SYN(_tcphdr)                    BE_BITS_TO_1BYTE(((u8 *)(_tcphdr)) + 13, 1, 1)
1198 #define GET_TCP_RST(_tcphdr)                    BE_BITS_TO_1BYTE(((u8 *)(_tcphdr)) + 13, 2, 1)
1199 #define GET_TCP_PSH(_tcphdr)                    BE_BITS_TO_1BYTE(((u8 *)(_tcphdr)) + 13, 3, 1)
1200 #define GET_TCP_ACK(_tcphdr)                    BE_BITS_TO_1BYTE(((u8 *)(_tcphdr)) + 13, 4, 1)
1201 #define GET_TCP_URG(_tcphdr)                    BE_BITS_TO_1BYTE(((u8 *)(_tcphdr)) + 13, 5, 1)
1202 #define GET_TCP_ECE(_tcphdr)                    BE_BITS_TO_1BYTE(((u8 *)(_tcphdr)) + 13, 6, 1)
1203 #define GET_TCP_CWR(_tcphdr)                    BE_BITS_TO_1BYTE(((u8 *)(_tcphdr)) + 13, 7, 1)
1204
1205 #endif /* __RTL871X_MLME_H_ */