1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
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.
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
14 ******************************************************************************/
18 #include <osdep_service.h>
19 #include <mlme_osdep.h>
20 #include <drv_types.h>
21 #include <wlan_bssdef.h>
23 #define MAX_BSS_CNT 128
24 #define MAX_JOIN_TIMEOUT 6500
26 /* Increase the scanning timeout because of increasing the SURVEY_TO value. */
28 #define SCANNING_TIMEOUT 8000
30 #define SCAN_INTERVAL (30) /* unit:2sec, 30*2=60sec */
32 #define SCANQUEUE_LIFETIME 20 /* unit:sec */
34 #define WIFI_NULL_STATE 0x00000000
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
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
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 */
50 #define _FW_UNDER_LINKING WIFI_UNDER_LINKING
51 #define _FW_LINKED WIFI_ASOC_STATE
52 #define _FW_UNDER_SURVEY WIFI_SITE_MONITOR
54 enum dot11AuthAlgrthmNum {
55 dot11AuthAlgrthm_Open = 0, /* open system */
56 dot11AuthAlgrthm_Shared,
57 dot11AuthAlgrthm_8021X,
58 dot11AuthAlgrthm_Auto,
59 dot11AuthAlgrthm_WAPI,
60 dot11AuthAlgrthm_MaxNum
63 /* Scan type including active and passive scan. */
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,
74 SCAN_RESULT_WFD_TYPE = 2 /* Will just return the correct WFD
76 /* If this device is Miracast sink
77 * device, it will just return all the
78 * Miracast source devices. */
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.
86 Each _queue has its own locks, already.
87 Other items are protected by mlme_priv.lock.
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!
93 #define traffic_threshold 10
94 #define traffic_scan_period 500
96 struct rt_link_detect {
99 u32 NumRxUnicastOkInPeriod;
103 bool bHigherBusyTraffic; /* For interrupt migration purpose. */
104 bool bHigherBusyRxTraffic; /* We may disable Tx interrupt according
106 bool bHigherBusyTxTraffic; /* We may disable Tx interrupt according
112 int fw_state; /* shall we protect this variable? maybe not necessarily... */
114 u8 to_join; /* flag */
115 u8 to_roaming; /* roaming trying times */
119 struct list_head *pscanned;
120 struct __queue free_bss_pool;
121 struct __queue scanned_queue;
124 struct ndis_802_11_ssid assoc_ssid;
127 struct wlan_network cur_network;
131 struct timer_list assoc_timer;
135 struct timer_list scan_to_timer; /* driver itself handles scan_timeout status. */
137 struct qos_priv qospriv;
139 /* Number of non-HT AP/stations */
142 /* Number of HT AP/stations 20 MHz */
143 /* int num_sta_ht_20mhz; */
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 */
150 u8 key_mask; /* use for ips to set wep key after ips_leave */
151 u8 acm_mask; /* for wmm acm mask */
153 enum rt_scan_type scan_mode; /* active: 1, passive: 0 */
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;
165 #if defined(CONFIG_88EU_AP_MODE)
166 /* Number of associated Non-ERP stations (i.e., stations using 802.11b
170 /* Number of associated stations that do not support Short Slot Time */
171 int num_sta_no_short_slot_time;
173 /* Number of associated stations that do not support Short Preamble */
174 int num_sta_no_short_preamble;
176 int olbc; /* Overlapping Legacy BSS Condition */
178 /* Number of HT assoc sta that do not support greenfield */
179 int num_sta_ht_no_gf;
181 /* Number of associated non-HT stations */
182 /* int num_sta_no_ht; */
184 /* Number of HT associated stations 20 MHz */
185 int num_sta_ht_20mhz;
187 /* Overlapping BSS information */
193 /* u8 *wps_probe_req_ie; */
194 u8 *wps_probe_resp_ie;
195 u8 *wps_assoc_resp_ie;
197 u32 wps_beacon_ie_len;
198 u32 wps_probe_resp_ie_len;
199 u32 wps_assoc_resp_ie_len;
201 spinlock_t bcn_update_lock;
203 #endif /* if defined (CONFIG_88EU_AP_MODE) */
206 #ifdef CONFIG_88EU_AP_MODE
208 struct hostapd_priv {
209 struct adapter *padapter;
212 int hostapd_mode_init(struct adapter *padapter);
213 void hostapd_mode_unload(struct adapter *padapter);
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];
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);
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;
247 static inline int check_fwstate(struct mlme_priv *pmlmepriv, int state)
249 if (pmlmepriv->fw_state & state)
255 static inline int get_fwstate(struct mlme_priv *pmlmepriv)
257 return pmlmepriv->fw_state;
261 * No Limit on the calling context,
262 * therefore set it to be the critical section...
264 * ### NOTE:#### (!!!!)
265 * MUST TAKE CARE THAT BEFORE CALLING THIS FUNC, YOU SHOULD HAVE LOCKED pmlmepriv->lock
267 static inline void set_fwstate(struct mlme_priv *pmlmepriv, int state)
269 pmlmepriv->fw_state |= state;
270 /* FOR HW integration */
271 if (_FW_UNDER_SURVEY == state)
272 pmlmepriv->bScanInProcess = true;
275 static inline void _clr_fwstate_(struct mlme_priv *pmlmepriv, int state)
277 pmlmepriv->fw_state &= ~state;
278 /* FOR HW integration */
279 if (_FW_UNDER_SURVEY == state)
280 pmlmepriv->bScanInProcess = false;
284 * No Limit on the calling context,
285 * therefore set it to be the critical section...
287 static inline void clr_fwstate(struct mlme_priv *pmlmepriv, int state)
289 spin_lock_bh(&pmlmepriv->lock);
290 if (check_fwstate(pmlmepriv, state) == true)
291 pmlmepriv->fw_state ^= state;
292 spin_unlock_bh(&pmlmepriv->lock);
295 static inline void clr_fwstate_ex(struct mlme_priv *pmlmepriv, int state)
297 spin_lock_bh(&pmlmepriv->lock);
298 _clr_fwstate_(pmlmepriv, state);
299 spin_unlock_bh(&pmlmepriv->lock);
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);
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);
318 int rtw_restruct_sec_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie,
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);
324 void rtw_update_registrypriv_dev_network(struct adapter *adapter);
326 void rtw_get_encrypt_decrypt_from_registrypriv(struct adapter *adapter);
328 void _rtw_join_timeout_handler(unsigned long data);
329 void rtw_scan_timeout_handler(unsigned long data);
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)
337 void rtw_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv);
339 struct wlan_network *_rtw_alloc_network(struct mlme_priv *pmlmepriv);
341 void _rtw_free_network_nolock(struct mlme_priv *pmlmepriv,
342 struct wlan_network *pnetwork);
344 int rtw_if_up(struct adapter *padapter);
346 u8 *rtw_get_capability_from_ie(u8 *ie);
347 u8 *rtw_get_beacon_interval_from_ie(u8 *ie);
349 void rtw_joinbss_reset(struct adapter *padapter);
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);
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);
360 void rtw_roaming(struct adapter *padapter, struct wlan_network *tgt_network);
361 void _rtw_roaming(struct adapter *padapter, struct wlan_network *tgt_network);
363 void rtw_stassoc_hw_rpt(struct adapter *adapter, struct sta_info *psta);
365 #endif /* __RTL871X_MLME_H_ */