1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
6 ******************************************************************************/
10 #include <osdep_service.h>
11 #include <mlme_osdep.h>
12 #include <drv_types.h>
13 #include <wlan_bssdef.h>
15 #define MAX_BSS_CNT 128
16 #define MAX_JOIN_TIMEOUT 6500
18 /* Increase the scanning timeout because of increasing the SURVEY_TO value. */
20 #define SCANNING_TIMEOUT 8000
22 #define SCAN_INTERVAL (30) /* unit:2sec, 30*2=60sec */
24 #define SCANQUEUE_LIFETIME 20 /* unit:sec */
26 #define WIFI_NULL_STATE 0x00000000
28 #define WIFI_ASOC_STATE 0x00000001 /* Under Linked state */
29 #define WIFI_REASOC_STATE 0x00000002
30 #define WIFI_SLEEP_STATE 0x00000004
31 #define WIFI_STATION_STATE 0x00000008
33 #define WIFI_AP_STATE 0x00000010
34 #define WIFI_ADHOC_STATE 0x00000020
35 #define WIFI_ADHOC_MASTER_STATE 0x00000040
36 #define WIFI_UNDER_LINKING 0x00000080
38 #define WIFI_UNDER_WPS 0x00000100
39 #define WIFI_STA_ALIVE_CHK_STATE 0x00000400
40 #define WIFI_SITE_MONITOR 0x00000800 /* to indicate the station is under site surveying */
42 #define _FW_UNDER_LINKING WIFI_UNDER_LINKING
43 #define _FW_LINKED WIFI_ASOC_STATE
44 #define _FW_UNDER_SURVEY WIFI_SITE_MONITOR
46 enum dot11AuthAlgrthmNum {
47 dot11AuthAlgrthm_Open = 0, /* open system */
48 dot11AuthAlgrthm_Shared,
49 dot11AuthAlgrthm_8021X,
50 dot11AuthAlgrthm_Auto,
51 dot11AuthAlgrthm_WAPI,
52 dot11AuthAlgrthm_MaxNum
55 /* Scan type including active and passive scan. */
62 enum SCAN_RESULT_TYPE {
63 SCAN_RESULT_P2P_ONLY = 0, /* Will return all the P2P devices. */
64 SCAN_RESULT_ALL = 1, /* Will return all the scanned device,
67 SCAN_RESULT_WFD_TYPE = 2 /* Will just return the correct WFD
70 /* If this device is Miracast sink
71 * device, it will just return all the
72 * Miracast source devices.
77 * there are several "locks" in mlme_priv,
78 * since mlme_priv is a shared resource between many threads,
79 * like ISR/Call-Back functions, the OID handlers, and even timer functions.
81 * Each _queue has its own locks, already.
82 * Other items are protected by mlme_priv.lock.
84 * To avoid possible dead lock, any thread trying to modifiying mlme_priv
85 * SHALL not lock up more than one lock at a time!
88 #define traffic_threshold 10
89 #define traffic_scan_period 500
91 struct rt_link_detect {
94 u32 NumRxUnicastOkInPeriod;
98 bool bHigherBusyTraffic; /* For interrupt migration purpose. */
99 bool bHigherBusyRxTraffic; /* We may disable Tx interrupt according
102 bool bHigherBusyTxTraffic; /* We may disable Tx interrupt according
109 int fw_state; /* shall we protect this variable? maybe not necessarily... */
111 u8 to_join; /* flag */
112 u8 to_roaming; /* roaming trying times */
116 struct list_head *pscanned;
117 struct __queue free_bss_pool;
118 struct __queue scanned_queue;
121 struct ndis_802_11_ssid assoc_ssid;
124 struct wlan_network cur_network;
128 struct timer_list assoc_timer;
132 struct timer_list scan_to_timer; /* driver itself handles scan_timeout status. */
134 struct qos_priv qospriv;
136 /* Number of non-HT AP/stations */
139 /* Number of HT AP/stations 20 MHz */
140 /* int num_sta_ht_20mhz; */
142 int num_FortyMHzIntolerant;
143 struct ht_priv htpriv;
144 struct rt_link_detect LinkDetectInfo;
145 struct timer_list dynamic_chk_timer; /* dynamic/periodic check timer */
147 u8 key_mask; /* use for ips to set wep key after ips_leave */
148 u8 acm_mask; /* for wmm acm mask */
150 enum rt_scan_type scan_mode; /* active: 1, passive: 0 */
152 /* u8 probereq_wpsie[MAX_WPS_IE_LEN];added in probe req */
153 /* int probereq_wpsie_len; */
154 u8 *wps_probe_req_ie;
155 u32 wps_probe_req_ie_len;
162 #if defined(CONFIG_88EU_AP_MODE)
163 /* Number of associated Non-ERP stations (i.e., stations using 802.11b
168 /* Number of associated stations that do not support Short Slot Time */
169 int num_sta_no_short_slot_time;
171 /* Number of associated stations that do not support Short Preamble */
172 int num_sta_no_short_preamble;
174 int olbc; /* Overlapping Legacy BSS Condition */
176 /* Number of HT assoc sta that do not support greenfield */
177 int num_sta_ht_no_gf;
179 /* Number of associated non-HT stations */
180 /* int num_sta_no_ht; */
182 /* Number of HT associated stations 20 MHz */
183 int num_sta_ht_20mhz;
185 /* Overlapping BSS information */
191 /* u8 *wps_probe_req_ie; */
192 u8 *wps_probe_resp_ie;
193 u8 *wps_assoc_resp_ie;
195 u32 wps_beacon_ie_len;
196 u32 wps_probe_resp_ie_len;
197 u32 wps_assoc_resp_ie_len;
199 spinlock_t bcn_update_lock;
201 #endif /* if defined (CONFIG_88EU_AP_MODE) */
204 #ifdef CONFIG_88EU_AP_MODE
206 struct hostapd_priv {
207 struct adapter *padapter;
210 int hostapd_mode_init(struct adapter *padapter);
211 void hostapd_mode_unload(struct adapter *padapter);
214 extern unsigned char WPA_TKIP_CIPHER[4];
215 extern unsigned char RSN_TKIP_CIPHER[4];
216 extern unsigned char REALTEK_96B_IE[];
217 extern unsigned char MCS_rate_1R[16];
219 void rtw_joinbss_event_prehandle(struct adapter *adapter, u8 *pbuf);
220 void rtw_survey_event_callback(struct adapter *adapter, u8 *pbuf);
221 void rtw_surveydone_event_callback(struct adapter *adapter, u8 *pbuf);
222 void rtw_joinbss_event_callback(struct adapter *adapter, u8 *pbuf);
223 void rtw_stassoc_event_callback(struct adapter *adapter, u8 *pbuf);
224 void rtw_stadel_event_callback(struct adapter *adapter, u8 *pbuf);
225 void rtw_atimdone_event_callback(struct adapter *adapter, u8 *pbuf);
226 void rtw_cpwm_event_callback(struct adapter *adapter, u8 *pbuf);
227 void indicate_wx_scan_complete_event(struct adapter *padapter);
228 void rtw_indicate_wx_assoc_event(struct adapter *padapter);
229 void rtw_indicate_wx_disassoc_event(struct adapter *padapter);
230 int event_thread(void *context);
231 void rtw_free_network_queue(struct adapter *adapter, u8 isfreeall);
232 int rtw_init_mlme_priv(struct adapter *adapter);
233 void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv);
234 int rtw_select_and_join_from_scanned_queue(struct mlme_priv *pmlmepriv);
235 int rtw_set_key(struct adapter *adapter, struct security_priv *psecuritypriv,
236 int keyid, u8 set_tx);
237 int rtw_set_auth(struct adapter *adapter, struct security_priv *psecuritypriv);
239 static inline u8 *get_bssid(struct mlme_priv *pmlmepriv)
240 { /* if sta_mode:pmlmepriv->cur_network.network.MacAddress=> bssid */
241 /* if adhoc_mode:pmlmepriv->cur_network.network.MacAddress=> ibss mac address */
242 return pmlmepriv->cur_network.network.MacAddress;
245 static inline int check_fwstate(struct mlme_priv *pmlmepriv, int state)
247 if (pmlmepriv->fw_state & state)
253 static inline int get_fwstate(struct mlme_priv *pmlmepriv)
255 return pmlmepriv->fw_state;
259 * No Limit on the calling context,
260 * therefore set it to be the critical section...
262 * ### NOTE:#### (!!!!)
263 * MUST TAKE CARE THAT BEFORE CALLING THIS FUNC, YOU SHOULD HAVE LOCKED pmlmepriv->lock
265 static inline void set_fwstate(struct mlme_priv *pmlmepriv, int state)
267 pmlmepriv->fw_state |= state;
268 /* FOR HW integration */
269 if (_FW_UNDER_SURVEY == state)
270 pmlmepriv->bScanInProcess = true;
273 static inline void _clr_fwstate_(struct mlme_priv *pmlmepriv, int state)
275 pmlmepriv->fw_state &= ~state;
276 /* FOR HW integration */
277 if (_FW_UNDER_SURVEY == state)
278 pmlmepriv->bScanInProcess = false;
282 * No Limit on the calling context,
283 * therefore set it to be the critical section...
285 static inline void clr_fwstate(struct mlme_priv *pmlmepriv, int state)
287 spin_lock_bh(&pmlmepriv->lock);
288 if (check_fwstate(pmlmepriv, state) == true)
289 pmlmepriv->fw_state ^= state;
290 spin_unlock_bh(&pmlmepriv->lock);
293 static inline void clr_fwstate_ex(struct mlme_priv *pmlmepriv, int state)
295 spin_lock_bh(&pmlmepriv->lock);
296 _clr_fwstate_(pmlmepriv, state);
297 spin_unlock_bh(&pmlmepriv->lock);
300 u16 rtw_get_capability(struct wlan_bssid_ex *bss);
301 void rtw_update_scanned_network(struct adapter *adapter,
302 struct wlan_bssid_ex *target);
303 void rtw_disconnect_hdl_under_linked(struct adapter *adapter,
304 struct sta_info *psta, u8 free_assoc);
305 void rtw_generate_random_ibss(u8 *pibss);
306 struct wlan_network *rtw_find_network(struct __queue *scanned_queue, u8 *addr);
307 struct wlan_network *rtw_get_oldest_wlan_network(struct __queue *scanned_queue);
309 void rtw_free_assoc_resources(struct adapter *adapter);
310 void rtw_free_assoc_resources_locked(struct adapter *adapter);
311 void rtw_indicate_disconnect(struct adapter *adapter);
312 void rtw_indicate_connect(struct adapter *adapter);
313 void rtw_indicate_scan_done(struct adapter *padapter, bool aborted);
314 void rtw_scan_abort(struct adapter *adapter);
316 int rtw_restruct_sec_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie,
318 int rtw_restruct_wmm_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie,
319 uint in_len, uint initial_out_len);
320 void rtw_init_registrypriv_dev_network(struct adapter *adapter);
322 void rtw_update_registrypriv_dev_network(struct adapter *adapter);
324 void rtw_get_encrypt_decrypt_from_registrypriv(struct adapter *adapter);
326 void _rtw_join_timeout_handler(struct timer_list *t);
327 void rtw_scan_timeout_handler(struct timer_list *t);
329 void rtw_dynamic_check_timer_handlder(struct timer_list *t);
330 #define rtw_is_scan_deny(adapter) false
331 #define rtw_clear_scan_deny(adapter) do {} while (0)
332 #define rtw_set_scan_deny_timer_hdl(adapter) do {} while (0)
333 #define rtw_set_scan_deny(adapter, ms) do {} while (0)
335 void rtw_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv);
337 struct wlan_network *_rtw_alloc_network(struct mlme_priv *pmlmepriv);
339 void _rtw_free_network_nolock(struct mlme_priv *pmlmepriv,
340 struct wlan_network *pnetwork);
342 int rtw_if_up(struct adapter *padapter);
344 u8 *rtw_get_capability_from_ie(u8 *ie);
345 u8 *rtw_get_beacon_interval_from_ie(u8 *ie);
347 void rtw_joinbss_reset(struct adapter *padapter);
349 unsigned int rtw_restructure_ht_ie(struct adapter *padapter, u8 *in_ie,
350 u8 *out_ie, uint in_len, uint *pout_len);
351 void rtw_update_ht_cap(struct adapter *padapter, u8 *pie, uint ie_len);
352 void rtw_issue_addbareq_cmd(struct adapter *padapter,
353 struct xmit_frame *pxmitframe);
355 int rtw_is_same_ibss(struct adapter *adapter, struct wlan_network *pnetwork);
356 int is_same_network(struct wlan_bssid_ex *src, struct wlan_bssid_ex *dst);
358 void rtw_roaming(struct adapter *padapter, struct wlan_network *tgt_network);
359 void _rtw_roaming(struct adapter *padapter, struct wlan_network *tgt_network);
361 void rtw_stassoc_hw_rpt(struct adapter *adapter, struct sta_info *psta);
363 #endif /* __RTL871X_MLME_H_ */