GNU Linux-libre 4.14.290-gnu1
[releases.git] / drivers / staging / rtl8188eu / 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  ******************************************************************************/
15 #ifndef __RTW_MLME_H_
16 #define __RTW_MLME_H_
17
18 #include <osdep_service.h>
19 #include <mlme_osdep.h>
20 #include <drv_types.h>
21 #include <wlan_bssdef.h>
22
23 #define MAX_BSS_CNT     128
24 #define   MAX_JOIN_TIMEOUT      6500
25
26 /* Increase the scanning timeout because of increasing the SURVEY_TO value. */
27
28 #define         SCANNING_TIMEOUT        8000
29
30 #define SCAN_INTERVAL   (30) /*  unit:2sec, 30*2=60sec */
31
32 #define SCANQUEUE_LIFETIME 20 /*  unit:sec */
33
34 #define WIFI_NULL_STATE                 0x00000000
35
36 #define WIFI_ASOC_STATE                 0x00000001      /* Under Linked state */
37 #define WIFI_REASOC_STATE               0x00000002
38 #define WIFI_SLEEP_STATE                0x00000004
39 #define WIFI_STATION_STATE              0x00000008
40
41 #define WIFI_AP_STATE                   0x00000010
42 #define WIFI_ADHOC_STATE                0x00000020
43 #define WIFI_ADHOC_MASTER_STATE         0x00000040
44 #define WIFI_UNDER_LINKING              0x00000080
45
46 #define WIFI_UNDER_WPS                  0x00000100
47 #define WIFI_STA_ALIVE_CHK_STATE        0x00000400
48 #define WIFI_SITE_MONITOR               0x00000800      /* to indicate the station is under site surveying */
49
50 #define _FW_UNDER_LINKING       WIFI_UNDER_LINKING
51 #define _FW_LINKED                      WIFI_ASOC_STATE
52 #define _FW_UNDER_SURVEY        WIFI_SITE_MONITOR
53
54 enum dot11AuthAlgrthmNum {
55         dot11AuthAlgrthm_Open = 0, /* open system */
56         dot11AuthAlgrthm_Shared,
57         dot11AuthAlgrthm_8021X,
58         dot11AuthAlgrthm_Auto,
59         dot11AuthAlgrthm_WAPI,
60         dot11AuthAlgrthm_MaxNum
61 };
62
63 /*  Scan type including active and passive scan. */
64 enum rt_scan_type {
65         SCAN_PASSIVE,
66         SCAN_ACTIVE,
67         SCAN_MIX,
68 };
69
70 enum SCAN_RESULT_TYPE {
71         SCAN_RESULT_P2P_ONLY = 0,       /* Will return all the P2P devices. */
72         SCAN_RESULT_ALL = 1,            /* Will return all the scanned device,
73                                          * include AP. */
74         SCAN_RESULT_WFD_TYPE = 2        /* Will just return the correct WFD
75                                          * device. */
76                                         /* If this device is Miracast sink
77                                          * device, it will just return all the
78                                          * Miracast source devices. */
79 };
80
81 /*
82 there are several "locks" in mlme_priv,
83 since mlme_priv is a shared resource between many threads,
84 like ISR/Call-Back functions, the OID handlers, and even timer functions.
85
86 Each _queue has its own locks, already.
87 Other items are protected by mlme_priv.lock.
88
89 To avoid possible dead lock, any thread trying to modifiying mlme_priv
90 SHALL not lock up more than one lock at a time!
91 */
92
93 #define traffic_threshold       10
94 #define traffic_scan_period     500
95
96 struct rt_link_detect {
97         u32     NumTxOkInPeriod;
98         u32     NumRxOkInPeriod;
99         u32     NumRxUnicastOkInPeriod;
100         bool    bBusyTraffic;
101         bool    bTxBusyTraffic;
102         bool    bRxBusyTraffic;
103         bool    bHigherBusyTraffic; /*  For interrupt migration purpose. */
104         bool    bHigherBusyRxTraffic; /* We may disable Tx interrupt according
105                                        * to Rx traffic. */
106         bool    bHigherBusyTxTraffic; /* We may disable Tx interrupt according
107                                        * to Tx traffic. */
108 };
109
110 struct mlme_priv {
111         spinlock_t lock;
112         int fw_state;   /* shall we protect this variable? maybe not necessarily... */
113         u8 bScanInProcess;
114         u8 to_join; /* flag */
115         u8 to_roaming; /*  roaming trying times */
116
117         u8 *nic_hdl;
118
119         struct list_head *pscanned;
120         struct __queue free_bss_pool;
121         struct __queue scanned_queue;
122         u8 *free_bss_buf;
123
124         struct ndis_802_11_ssid assoc_ssid;
125         u8      assoc_bssid[6];
126
127         struct wlan_network     cur_network;
128
129         u32     scan_interval;
130
131         struct timer_list assoc_timer;
132
133         uint assoc_by_bssid;
134
135         struct timer_list scan_to_timer; /*  driver itself handles scan_timeout status. */
136
137         struct qos_priv qospriv;
138
139         /* Number of non-HT AP/stations */
140         int num_sta_no_ht;
141
142         /* Number of HT AP/stations 20 MHz */
143         /* int num_sta_ht_20mhz; */
144
145         int num_FortyMHzIntolerant;
146         struct ht_priv  htpriv;
147         struct rt_link_detect LinkDetectInfo;
148         struct timer_list dynamic_chk_timer; /* dynamic/periodic check timer */
149
150         u8      key_mask; /* use for ips to set wep key after ips_leave */
151         u8      acm_mask; /*  for wmm acm mask */
152         u8      ChannelPlan;
153         enum rt_scan_type scan_mode; /*  active: 1, passive: 0 */
154
155         /* u8 probereq_wpsie[MAX_WPS_IE_LEN];added in probe req */
156         /* int probereq_wpsie_len; */
157         u8 *wps_probe_req_ie;
158         u32 wps_probe_req_ie_len;
159
160         u8 *assoc_req;
161         u32 assoc_req_len;
162         u8 *assoc_rsp;
163         u32 assoc_rsp_len;
164
165 #if defined(CONFIG_88EU_AP_MODE)
166         /* Number of associated Non-ERP stations (i.e., stations using 802.11b
167          * in 802.11g BSS) */
168         int num_sta_non_erp;
169
170         /* Number of associated stations that do not support Short Slot Time */
171         int num_sta_no_short_slot_time;
172
173         /* Number of associated stations that do not support Short Preamble */
174         int num_sta_no_short_preamble;
175
176         int olbc; /* Overlapping Legacy BSS Condition */
177
178         /* Number of HT assoc sta that do not support greenfield */
179         int num_sta_ht_no_gf;
180
181         /* Number of associated non-HT stations */
182         /* int num_sta_no_ht; */
183
184         /* Number of HT associated stations 20 MHz */
185         int num_sta_ht_20mhz;
186
187         /* Overlapping BSS information */
188         int olbc_ht;
189
190         u16 ht_op_mode;
191
192         u8 *wps_beacon_ie;
193         /* u8 *wps_probe_req_ie; */
194         u8 *wps_probe_resp_ie;
195         u8 *wps_assoc_resp_ie;
196
197         u32 wps_beacon_ie_len;
198         u32 wps_probe_resp_ie_len;
199         u32 wps_assoc_resp_ie_len;
200
201         spinlock_t bcn_update_lock;
202         u8              update_bcn;
203 #endif /* if defined (CONFIG_88EU_AP_MODE) */
204 };
205
206 #ifdef CONFIG_88EU_AP_MODE
207
208 struct hostapd_priv {
209         struct adapter *padapter;
210 };
211
212 int hostapd_mode_init(struct adapter *padapter);
213 void hostapd_mode_unload(struct adapter *padapter);
214 #endif
215
216 extern unsigned char WPA_TKIP_CIPHER[4];
217 extern unsigned char RSN_TKIP_CIPHER[4];
218 extern unsigned char REALTEK_96B_IE[];
219 extern unsigned char    MCS_rate_1R[16];
220
221 void rtw_joinbss_event_prehandle(struct adapter *adapter, u8 *pbuf);
222 void rtw_survey_event_callback(struct adapter *adapter, u8 *pbuf);
223 void rtw_surveydone_event_callback(struct adapter *adapter, u8 *pbuf);
224 void rtw_joinbss_event_callback(struct adapter *adapter, u8 *pbuf);
225 void rtw_stassoc_event_callback(struct adapter *adapter, u8 *pbuf);
226 void rtw_stadel_event_callback(struct adapter *adapter, u8 *pbuf);
227 void rtw_atimdone_event_callback(struct adapter *adapter, u8 *pbuf);
228 void rtw_cpwm_event_callback(struct adapter *adapter, u8 *pbuf);
229 void indicate_wx_scan_complete_event(struct adapter *padapter);
230 void rtw_indicate_wx_assoc_event(struct adapter *padapter);
231 void rtw_indicate_wx_disassoc_event(struct adapter *padapter);
232 int event_thread(void *context);
233 void rtw_free_network_queue(struct adapter *adapter, u8 isfreeall);
234 int rtw_init_mlme_priv(struct adapter *adapter);
235 void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv);
236 int rtw_select_and_join_from_scanned_queue(struct mlme_priv *pmlmepriv);
237 int rtw_set_key(struct adapter *adapter, struct security_priv *psecuritypriv,
238                 int keyid, u8 set_tx);
239 int rtw_set_auth(struct adapter *adapter, struct security_priv *psecuritypriv);
240
241 static inline u8 *get_bssid(struct mlme_priv *pmlmepriv)
242 {       /* if sta_mode:pmlmepriv->cur_network.network.MacAddress=> bssid */
243         /*  if adhoc_mode:pmlmepriv->cur_network.network.MacAddress=> ibss mac address */
244         return pmlmepriv->cur_network.network.MacAddress;
245 }
246
247 static inline int check_fwstate(struct mlme_priv *pmlmepriv, int state)
248 {
249         if (pmlmepriv->fw_state & state)
250                 return true;
251
252         return false;
253 }
254
255 static inline int get_fwstate(struct mlme_priv *pmlmepriv)
256 {
257         return pmlmepriv->fw_state;
258 }
259
260 /*
261  * No Limit on the calling context,
262  * therefore set it to be the critical section...
263  *
264  * ### NOTE:#### (!!!!)
265  * MUST TAKE CARE THAT BEFORE CALLING THIS FUNC, YOU SHOULD HAVE LOCKED pmlmepriv->lock
266  */
267 static inline void set_fwstate(struct mlme_priv *pmlmepriv, int state)
268 {
269         pmlmepriv->fw_state |= state;
270         /* FOR HW integration */
271         if (_FW_UNDER_SURVEY == state)
272                 pmlmepriv->bScanInProcess = true;
273 }
274
275 static inline void _clr_fwstate_(struct mlme_priv *pmlmepriv, int state)
276 {
277         pmlmepriv->fw_state &= ~state;
278         /* FOR HW integration */
279         if (_FW_UNDER_SURVEY == state)
280                 pmlmepriv->bScanInProcess = false;
281 }
282
283 /*
284  * No Limit on the calling context,
285  * therefore set it to be the critical section...
286  */
287 static inline void clr_fwstate(struct mlme_priv *pmlmepriv, int state)
288 {
289         spin_lock_bh(&pmlmepriv->lock);
290         if (check_fwstate(pmlmepriv, state) == true)
291                 pmlmepriv->fw_state ^= state;
292         spin_unlock_bh(&pmlmepriv->lock);
293 }
294
295 static inline void clr_fwstate_ex(struct mlme_priv *pmlmepriv, int state)
296 {
297         spin_lock_bh(&pmlmepriv->lock);
298         _clr_fwstate_(pmlmepriv, state);
299         spin_unlock_bh(&pmlmepriv->lock);
300 }
301
302 u16 rtw_get_capability(struct wlan_bssid_ex *bss);
303 void rtw_update_scanned_network(struct adapter *adapter,
304                                 struct wlan_bssid_ex *target);
305 void rtw_disconnect_hdl_under_linked(struct adapter *adapter,
306                                      struct sta_info *psta, u8 free_assoc);
307 void rtw_generate_random_ibss(u8 *pibss);
308 struct wlan_network *rtw_find_network(struct __queue *scanned_queue, u8 *addr);
309 struct wlan_network *rtw_get_oldest_wlan_network(struct __queue *scanned_queue);
310
311 void rtw_free_assoc_resources(struct adapter *adapter);
312 void rtw_free_assoc_resources_locked(struct adapter *adapter);
313 void rtw_indicate_disconnect(struct adapter *adapter);
314 void rtw_indicate_connect(struct adapter *adapter);
315 void rtw_indicate_scan_done(struct adapter *padapter, bool aborted);
316 void rtw_scan_abort(struct adapter *adapter);
317
318 int rtw_restruct_sec_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie,
319                         uint in_len);
320 int rtw_restruct_wmm_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie,
321                         uint in_len, uint initial_out_len);
322 void rtw_init_registrypriv_dev_network(struct adapter *adapter);
323
324 void rtw_update_registrypriv_dev_network(struct adapter *adapter);
325
326 void rtw_get_encrypt_decrypt_from_registrypriv(struct adapter *adapter);
327
328 void _rtw_join_timeout_handler(unsigned long data);
329 void rtw_scan_timeout_handler(unsigned long data);
330
331 void rtw_dynamic_check_timer_handlder(unsigned long data);
332 #define rtw_is_scan_deny(adapter) false
333 #define rtw_clear_scan_deny(adapter) do {} while (0)
334 #define rtw_set_scan_deny_timer_hdl(adapter) do {} while (0)
335 #define rtw_set_scan_deny(adapter, ms) do {} while (0)
336
337 void rtw_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv);
338
339 struct wlan_network *_rtw_alloc_network(struct mlme_priv *pmlmepriv);
340
341 void _rtw_free_network_nolock(struct mlme_priv *pmlmepriv,
342                               struct wlan_network *pnetwork);
343
344 int rtw_if_up(struct adapter *padapter);
345
346 u8 *rtw_get_capability_from_ie(u8 *ie);
347 u8 *rtw_get_beacon_interval_from_ie(u8 *ie);
348
349 void rtw_joinbss_reset(struct adapter *padapter);
350
351 unsigned int rtw_restructure_ht_ie(struct adapter *padapter, u8 *in_ie,
352                                    u8 *out_ie, uint in_len, uint *pout_len);
353 void rtw_update_ht_cap(struct adapter *padapter, u8 *pie, uint ie_len);
354 void rtw_issue_addbareq_cmd(struct adapter *padapter,
355                             struct xmit_frame *pxmitframe);
356
357 int rtw_is_same_ibss(struct adapter *adapter, struct wlan_network *pnetwork);
358 int is_same_network(struct wlan_bssid_ex *src, struct wlan_bssid_ex *dst);
359
360 void rtw_roaming(struct adapter *padapter, struct wlan_network *tgt_network);
361 void _rtw_roaming(struct adapter *padapter, struct wlan_network *tgt_network);
362
363 void rtw_stassoc_hw_rpt(struct adapter *adapter, struct sta_info *psta);
364
365 #endif /* __RTL871X_MLME_H_ */