1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
3 *
4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5 *
6 ******************************************************************************/
7 #ifndef __RTW_MLME_H_
8 #define __RTW_MLME_H_
9
10
11 #define MAX_BSS_CNT 128
12 /* define MAX_JOIN_TIMEOUT 2000 */
13 /* define MAX_JOIN_TIMEOUT 2500 */
14 #define MAX_JOIN_TIMEOUT 6500
15
16 /* Commented by Albert 20101105 */
17 /* Increase the scanning timeout because of increasing the SURVEY_TO value. */
18
19 #define SCANNING_TIMEOUT 8000
20
21 #ifdef PALTFORM_OS_WINCE
22 #define SCANQUEUE_LIFETIME 12000000 /* unit:us */
23 #else
24 #define SCANQUEUE_LIFETIME 20000 /* 20sec, unit:msec */
25 #endif
26
27 #define WIFI_NULL_STATE 0x00000000
28 #define WIFI_ASOC_STATE 0x00000001 /* Under Linked state... */
29 #define WIFI_SLEEP_STATE 0x00000004
30 #define WIFI_STATION_STATE 0x00000008
31 #define WIFI_AP_STATE 0x00000010
32 #define WIFI_ADHOC_STATE 0x00000020
33 #define WIFI_ADHOC_MASTER_STATE 0x00000040
34 #define WIFI_UNDER_LINKING 0x00000080
35
36 #define WIFI_UNDER_WPS 0x00000100
37 #define WIFI_STA_ALIVE_CHK_STATE 0x00000400
38 #define WIFI_SITE_MONITOR 0x00000800 /* to indicate the station is under site surveying */
39
40 /* ifdef UNDER_MPTEST */
41 #define WIFI_MP_STATE 0x00010000
42 /* endif */
43
44 /* define _FW_UNDER_CMD WIFI_UNDER_CMD */
45 #define _FW_UNDER_LINKING WIFI_UNDER_LINKING
46 #define _FW_LINKED WIFI_ASOC_STATE
47 #define _FW_UNDER_SURVEY WIFI_SITE_MONITOR
48
49
50 enum {
51 dot11AuthAlgrthm_Open = 0,
52 dot11AuthAlgrthm_Shared,
53 dot11AuthAlgrthm_8021X,
54 dot11AuthAlgrthm_Auto,
55 dot11AuthAlgrthm_WAPI,
56 dot11AuthAlgrthm_MaxNum
57 };
58
59 /* Scan type including active and passive scan. */
60 enum rt_scan_type {
61 SCAN_PASSIVE,
62 SCAN_ACTIVE,
63 SCAN_MIX,
64 };
65
66 enum {
67 GHZ24_50 = 0,
68 GHZ_50,
69 GHZ_24,
70 GHZ_MAX,
71 };
72
73 /*
74
75 there are several "locks" in mlme_priv,
76 since mlme_priv is a shared resource between many threads,
77 like ISR/Call-Back functions, the OID handlers, and even timer functions.
78
79 Each struct __queue has its own locks, already.
80 Other items in mlme_priv are protected by mlme_priv.lock, while items in
81 xmit_priv are protected by xmit_priv.lock.
82
83 To avoid possible dead lock, any thread trying to modifiying mlme_priv
84 SHALL not lock up more than one locks at a time!
85
86 The only exception is that queue functions which take the __queue.lock
87 may be called with the xmit_priv.lock held. In this case the order
88 MUST always be first lock xmit_priv.lock and then call any queue functions
89 which take __queue.lock.
90 */
91
92 struct sitesurvey_ctrl {
93 u64 last_tx_pkts;
94 uint last_rx_pkts;
95 signed int traffic_busy;
96 struct timer_list sitesurvey_ctrl_timer;
97 };
98
99 struct rt_link_detect_t {
100 u32 NumTxOkInPeriod;
101 u32 NumRxOkInPeriod;
102 u32 NumRxUnicastOkInPeriod;
103 bool bBusyTraffic;
104 bool bTxBusyTraffic;
105 bool bRxBusyTraffic;
106 bool bHigherBusyTraffic; /* For interrupt migration purpose. */
107 bool bHigherBusyRxTraffic; /* We may disable Tx interrupt according as Rx traffic. */
108 bool bHigherBusyTxTraffic; /* We may disable Tx interrupt according as Tx traffic. */
109 /* u8 TrafficBusyState; */
110 u8 TrafficTransitionCount;
111 u32 LowPowerTransitionCount;
112 };
113
114 /* used for mlme_priv.roam_flags */
115 enum {
116 RTW_ROAM_ON_EXPIRED = BIT0,
117 RTW_ROAM_ON_RESUME = BIT1,
118 RTW_ROAM_ACTIVE = BIT2,
119 };
120
121 struct mlme_priv {
122
123 spinlock_t lock;
124 signed int fw_state; /* shall we protect this variable? maybe not necessarily... */
125 u8 bScanInProcess;
126 u8 to_join; /* flag */
127
128 u8 to_roam; /* roaming trying times */
129 struct wlan_network *roam_network; /* the target of active roam */
130 u8 roam_flags;
131 u8 roam_rssi_diff_th; /* rssi difference threshold for active scan candidate selection */
132 u32 roam_scan_int_ms; /* scan interval for active roam */
133 u32 roam_scanr_exp_ms; /* scan result expire time in ms for roam */
134 u8 roam_tgt_addr[ETH_ALEN]; /* request to roam to specific target without other consideration */
135
136 u8 *nic_hdl;
137
138 u8 not_indic_disco;
139 struct list_head *pscanned;
140 struct __queue free_bss_pool;
141 struct __queue scanned_queue;
142 u8 *free_bss_buf;
143
144 struct ndis_802_11_ssid assoc_ssid;
145 u8 assoc_bssid[6];
146
147 struct wlan_network cur_network;
148 struct wlan_network *cur_network_scanned;
149
150 /* uint wireless_mode; no used, remove it */
151
152 u32 auto_scan_int_ms;
153
154 struct timer_list assoc_timer;
155
156 uint assoc_by_bssid;
157 uint assoc_by_rssi;
158
159 struct timer_list scan_to_timer; /* driver itself handles scan_timeout status. */
160 unsigned long scan_start_time; /* used to evaluate the time spent in scanning */
161
162 struct timer_list set_scan_deny_timer;
163 atomic_t set_scan_deny; /* 0: allowed, 1: deny */
164
165 struct qos_priv qospriv;
166
167 /* Number of non-HT AP/stations */
168 int num_sta_no_ht;
169
170 /* Number of HT AP/stations 20 MHz */
171 /* int num_sta_ht_20mhz; */
172
173
174 int num_FortyMHzIntolerant;
175
176 struct ht_priv htpriv;
177
178 struct rt_link_detect_t LinkDetectInfo;
179 struct timer_list dynamic_chk_timer; /* dynamic/periodic check timer */
180
181 u8 acm_mask; /* for wmm acm mask */
182 u8 ChannelPlan;
183 enum rt_scan_type scan_mode; /* active: 1, passive: 0 */
184
185 u8 *wps_probe_req_ie;
186 u32 wps_probe_req_ie_len;
187
188 /* Number of associated Non-ERP stations (i.e., stations using 802.11b
189 * in 802.11g BSS) */
190 int num_sta_non_erp;
191
192 /* Number of associated stations that do not support Short Slot Time */
193 int num_sta_no_short_slot_time;
194
195 /* Number of associated stations that do not support Short Preamble */
196 int num_sta_no_short_preamble;
197
198 int olbc; /* Overlapping Legacy BSS Condition */
199
200 /* Number of HT associated stations that do not support greenfield */
201 int num_sta_ht_no_gf;
202
203 /* Number of associated non-HT stations */
204 /* int num_sta_no_ht; */
205
206 /* Number of HT associated stations 20 MHz */
207 int num_sta_ht_20mhz;
208
209 /* Overlapping BSS information */
210 int olbc_ht;
211
212 u16 ht_op_mode;
213
214 u8 *assoc_req;
215 u32 assoc_req_len;
216 u8 *assoc_rsp;
217 u32 assoc_rsp_len;
218
219 u8 *wps_beacon_ie;
220 /* u8 *wps_probe_req_ie; */
221 u8 *wps_probe_resp_ie;
222 u8 *wps_assoc_resp_ie; /* for CONFIG_IOCTL_CFG80211, this IE could include p2p ie / wfd ie */
223
224 u32 wps_beacon_ie_len;
225 /* u32 wps_probe_req_ie_len; */
226 u32 wps_probe_resp_ie_len;
227 u32 wps_assoc_resp_ie_len; /* for CONFIG_IOCTL_CFG80211, this IE len could include p2p ie / wfd ie */
228
229 u8 *p2p_beacon_ie;
230 u8 *p2p_probe_req_ie;
231 u8 *p2p_probe_resp_ie;
232 u8 *p2p_go_probe_resp_ie; /* for GO */
233 u8 *p2p_assoc_req_ie;
234
235 u32 p2p_beacon_ie_len;
236 u32 p2p_probe_req_ie_len;
237 u32 p2p_probe_resp_ie_len;
238 u32 p2p_go_probe_resp_ie_len; /* for GO */
239 u32 p2p_assoc_req_ie_len;
240
241 spinlock_t bcn_update_lock;
242 u8 update_bcn;
243
244 u8 NumOfBcnInfoChkFail;
245 unsigned long timeBcnInfoChkStart;
246 };
247
248 void rtw_mlme_reset_auto_scan_int(struct adapter *adapter);
249
250 struct hostapd_priv {
251 struct adapter *padapter;
252 };
253
254 extern int hostapd_mode_init(struct adapter *padapter);
255 extern void hostapd_mode_unload(struct adapter *padapter);
256
257 extern void rtw_joinbss_event_prehandle(struct adapter *adapter, u8 *pbuf);
258 extern void rtw_survey_event_callback(struct adapter *adapter, u8 *pbuf);
259 extern void rtw_surveydone_event_callback(struct adapter *adapter, u8 *pbuf);
260 extern void rtw_joinbss_event_callback(struct adapter *adapter, u8 *pbuf);
261 extern void rtw_stassoc_event_callback(struct adapter *adapter, u8 *pbuf);
262 extern void rtw_stadel_event_callback(struct adapter *adapter, u8 *pbuf);
263 extern void rtw_atimdone_event_callback(struct adapter *adapter, u8 *pbuf);
264 extern void rtw_cpwm_event_callback(struct adapter *adapter, u8 *pbuf);
265 extern void rtw_wmm_event_callback(struct adapter *padapter, u8 *pbuf);
266
267 extern void rtw_join_timeout_handler(struct timer_list *t);
268 extern void _rtw_scan_timeout_handler(struct timer_list *t);
269
270 int event_thread(void *context);
271
272 extern void rtw_free_network_queue(struct adapter *adapter, u8 isfreeall);
273 extern int rtw_init_mlme_priv(struct adapter *adapter);/* (struct mlme_priv *pmlmepriv); */
274
275 extern void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv);
276
277
278 extern signed int rtw_select_and_join_from_scanned_queue(struct mlme_priv *pmlmepriv);
279 extern signed int rtw_set_key(struct adapter *adapter, struct security_priv *psecuritypriv, signed int keyid, u8 set_tx, bool enqueue);
280 extern signed int rtw_set_auth(struct adapter *adapter, struct security_priv *psecuritypriv);
281
get_bssid(struct mlme_priv * pmlmepriv)282 static inline u8 *get_bssid(struct mlme_priv *pmlmepriv)
283 { /* if sta_mode:pmlmepriv->cur_network.network.mac_address => bssid */
284 /* if adhoc_mode:pmlmepriv->cur_network.network.mac_address => ibss mac address */
285 return pmlmepriv->cur_network.network.mac_address;
286 }
287
check_fwstate(struct mlme_priv * pmlmepriv,signed int state)288 static inline signed int check_fwstate(struct mlme_priv *pmlmepriv, signed int state)
289 {
290 if (pmlmepriv->fw_state & state)
291 return true;
292
293 return false;
294 }
295
get_fwstate(struct mlme_priv * pmlmepriv)296 static inline signed int get_fwstate(struct mlme_priv *pmlmepriv)
297 {
298 return pmlmepriv->fw_state;
299 }
300
301 /*
302 * No Limit on the calling context,
303 * therefore set it to be the critical section...
304 *
305 * ### NOTE:#### (!!!!)
306 * MUST TAKE CARE THAT BEFORE CALLING THIS FUNC, YOU SHOULD HAVE LOCKED pmlmepriv->lock
307 */
set_fwstate(struct mlme_priv * pmlmepriv,signed int state)308 static inline void set_fwstate(struct mlme_priv *pmlmepriv, signed int state)
309 {
310 pmlmepriv->fw_state |= state;
311 /* FOR HW integration */
312 if (state == _FW_UNDER_SURVEY)
313 pmlmepriv->bScanInProcess = true;
314 }
315
_clr_fwstate_(struct mlme_priv * pmlmepriv,signed int state)316 static inline void _clr_fwstate_(struct mlme_priv *pmlmepriv, signed int state)
317 {
318 pmlmepriv->fw_state &= ~state;
319 /* FOR HW integration */
320 if (state == _FW_UNDER_SURVEY)
321 pmlmepriv->bScanInProcess = false;
322 }
323
324 extern u16 rtw_get_capability(struct wlan_bssid_ex *bss);
325 extern void rtw_update_scanned_network(struct adapter *adapter, struct wlan_bssid_ex *target);
326 extern void rtw_disconnect_hdl_under_linked(struct adapter *adapter, struct sta_info *psta, u8 free_assoc);
327 extern void rtw_generate_random_ibss(u8 *pibss);
328 extern struct wlan_network *rtw_find_network(struct __queue *scanned_queue, u8 *addr);
329 extern struct wlan_network *rtw_get_oldest_wlan_network(struct __queue *scanned_queue);
330 struct wlan_network *_rtw_find_same_network(struct __queue *scanned_queue, struct wlan_network *network);
331
332 extern void rtw_free_assoc_resources(struct adapter *adapter, int lock_scanned_queue);
333 extern void rtw_indicate_disconnect(struct adapter *adapter);
334 extern void rtw_indicate_connect(struct adapter *adapter);
335 void rtw_indicate_scan_done(struct adapter *padapter, bool aborted);
336 void rtw_scan_abort(struct adapter *adapter);
337
338 extern int rtw_restruct_sec_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_len);
339 extern int rtw_restruct_wmm_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_len, uint initial_out_len);
340 extern void rtw_init_registrypriv_dev_network(struct adapter *adapter);
341
342 extern void rtw_update_registrypriv_dev_network(struct adapter *adapter);
343
344 extern void rtw_get_encrypt_decrypt_from_registrypriv(struct adapter *adapter);
345
346 extern void _rtw_join_timeout_handler(struct timer_list *t);
347 extern void rtw_scan_timeout_handler(struct timer_list *t);
348
349 extern void rtw_dynamic_check_timer_handler(struct adapter *adapter);
350 bool rtw_is_scan_deny(struct adapter *adapter);
351 void rtw_clear_scan_deny(struct adapter *adapter);
352 void rtw_set_scan_deny(struct adapter *adapter, u32 ms);
353
354 void rtw_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv);
355
356 extern void _rtw_free_mlme_priv(struct mlme_priv *pmlmepriv);
357
358 /* extern struct wlan_network* _rtw_dequeue_network(struct __queue *queue); */
359
360 extern struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv);
361
362
363 extern void _rtw_free_network(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork, u8 isfreeall);
364 extern void _rtw_free_network_nolock(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork);
365
366
367 extern struct wlan_network *_rtw_find_network(struct __queue *scanned_queue, u8 *addr);
368
369 extern signed int rtw_if_up(struct adapter *padapter);
370
371 signed int rtw_linked_check(struct adapter *padapter);
372
373 u8 *rtw_get_capability_from_ie(u8 *ie);
374 u8 *rtw_get_beacon_interval_from_ie(u8 *ie);
375
376
377 void rtw_joinbss_reset(struct adapter *padapter);
378
379 void rtw_ht_use_default_setting(struct adapter *padapter);
380 void rtw_build_wmm_ie_ht(struct adapter *padapter, u8 *out_ie, uint *pout_len);
381 unsigned int rtw_restructure_ht_ie(struct adapter *padapter, u8 *in_ie, u8 *out_ie, uint in_len, uint *pout_len, u8 channel);
382 void rtw_update_ht_cap(struct adapter *padapter, u8 *pie, uint ie_len, u8 channel);
383 void rtw_issue_addbareq_cmd(struct adapter *padapter, struct xmit_frame *pxmitframe);
384 void rtw_append_exented_cap(struct adapter *padapter, u8 *out_ie, uint *pout_len);
385
386 int rtw_is_same_ibss(struct adapter *adapter, struct wlan_network *pnetwork);
387 int is_same_network(struct wlan_bssid_ex *src, struct wlan_bssid_ex *dst, u8 feature);
388
389 #define rtw_roam_flags(adapter) ((adapter)->mlmepriv.roam_flags)
390 #define rtw_chk_roam_flags(adapter, flags) ((adapter)->mlmepriv.roam_flags & flags)
391
392 void _rtw_roaming(struct adapter *adapter, struct wlan_network *tgt_network);
393 void rtw_roaming(struct adapter *adapter, struct wlan_network *tgt_network);
394 void rtw_set_to_roam(struct adapter *adapter, u8 to_roam);
395 u8 rtw_dec_to_roam(struct adapter *adapter);
396 u8 rtw_to_roam(struct adapter *adapter);
397 int rtw_select_roaming_candidate(struct mlme_priv *pmlmepriv);
398
399 void rtw_sta_media_status_rpt(struct adapter *adapter, struct sta_info *psta, u32 mstatus);
400
401 #endif /* __RTL871X_MLME_H_ */
402