blob: 6dd8fb4765532ab3285a8895d2cd2cc983d69866 [file] [log] [blame]
Larry Finger364e30e2014-03-28 21:37:41 -05001/******************************************************************************
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 ******************************************************************************/
16#ifndef __RTW_MLME_H_
17#define __RTW_MLME_H_
18
19#include <osdep_service.h>
20#include <mlme_osdep.h>
21#include <drv_types.h>
22#include <wlan_bssdef.h>
23
24#define MAX_BSS_CNT 128
25#define MAX_JOIN_TIMEOUT 6500
26
27/* Increase the scanning timeout because of increasing the SURVEY_TO value. */
28
29#define SCANNING_TIMEOUT 8000
30
31#define SCAN_INTERVAL (30) /* unit:2sec, 30*2 = 60sec */
32
33#define SCANQUEUE_LIFETIME 20 /* unit:sec */
34
35#define WIFI_NULL_STATE 0x00000000
36
37#define WIFI_ASOC_STATE 0x00000001 /* Under Linked state.*/
38#define WIFI_REASOC_STATE 0x00000002
39#define WIFI_SLEEP_STATE 0x00000004
40#define WIFI_STATION_STATE 0x00000008
41
42#define WIFI_AP_STATE 0x00000010
43#define WIFI_ADHOC_STATE 0x00000020
44#define WIFI_ADHOC_MASTER_STATE 0x00000040
45#define WIFI_UNDER_LINKING 0x00000080
46
47#define WIFI_UNDER_WPS 0x00000100
48#define WIFI_STA_ALIVE_CHK_STATE 0x00000400
49/* to indicate the station is under site surveying */
50#define WIFI_SITE_MONITOR 0x00000800
51
52#define WIFI_MP_STATE 0x00010000
53#define WIFI_MP_CTX_BACKGROUND 0x00020000 /* in continous tx background */
54#define WIFI_MP_CTX_ST 0x00040000 /* in continous tx with single-tone */
55#define WIFI_MP_CTX_BACKGROUND_PENDING 0x00080000 /* pending in continous tx background due to out of skb */
56#define WIFI_MP_CTX_CCK_HW 0x00100000 /* in continous tx */
57#define WIFI_MP_CTX_CCK_CS 0x00200000 /* in continous tx with carrier suppression */
58#define WIFI_MP_LPBK_STATE 0x00400000
59
60#define _FW_UNDER_LINKING WIFI_UNDER_LINKING
61#define _FW_LINKED WIFI_ASOC_STATE
62#define _FW_UNDER_SURVEY WIFI_SITE_MONITOR
63
64
65enum dot11AuthAlgrthmNum {
66 dot11AuthAlgrthm_Open = 0,
67 dot11AuthAlgrthm_Shared,
68 dot11AuthAlgrthm_8021X,
69 dot11AuthAlgrthm_Auto,
70 dot11AuthAlgrthm_MaxNum
71};
72
73/* Scan type including active and passive scan. */
74enum rt_scan_type {
75 SCAN_PASSIVE,
76 SCAN_ACTIVE,
77 SCAN_MIX,
78};
79
80enum {
81 GHZ24_50 = 0,
82 GHZ_50,
83 GHZ_24,
84};
85
86enum SCAN_RESULT_TYPE {
87 SCAN_RESULT_P2P_ONLY = 0, /* Will return all the P2P devices. */
88 SCAN_RESULT_ALL = 1, /* Will return all the scanned device, include AP. */
89 SCAN_RESULT_WFD_TYPE = 2 /* Will just return the correct WFD device. */
90 /* If this device is Miracast sink device, it will just return all the Miracast source devices. */
91};
92
93/*
94
95there are several "locks" in mlme_priv,
96since mlme_priv is a shared resource between many threads,
97like ISR/Call-Back functions, the OID handlers, and even timer functions.
98
99
100Each _queue has its own locks, already.
101Other items are protected by mlme_priv.lock.
102
103To avoid possible dead lock, any thread trying to modifiying mlme_priv
104SHALL not lock up more than one locks at a time!
105*/
106
107#define traffic_threshold 10
108#define traffic_scan_period 500
109
110struct sitesurvey_ctrl {
111 u64 last_tx_pkts;
112 uint last_rx_pkts;
113 int traffic_busy;
114 struct timer_list sitesurvey_ctrl_timer;
115};
116
117struct rt_link_detect {
118 u32 NumTxOkInPeriod;
119 u32 NumRxOkInPeriod;
120 u32 NumRxUnicastOkInPeriod;
121 bool bBusyTraffic;
122 bool bTxBusyTraffic;
123 bool bRxBusyTraffic;
124 bool bHigherBusyTraffic; /* For interrupt migration purpose. */
125 bool bHigherBusyRxTraffic; /* We may disable Tx interrupt according as Rx traffic. */
126 bool bHigherBusyTxTraffic; /* We may disable Tx interrupt according as Tx traffic. */
127};
128
129struct profile_info {
130 u8 ssidlen;
131 u8 ssid[IEEE80211_MAX_SSID_LEN];
132 u8 peermac[ETH_ALEN];
133};
134
135struct tx_invite_req_info {
136 u8 token;
137 u8 benable;
138 u8 go_ssid[IEEE80211_MAX_SSID_LEN];
139 u8 ssidlen;
140 u8 go_bssid[ETH_ALEN];
141 u8 peer_macaddr[ETH_ALEN];
142 u8 operating_ch; /* This information will be set by using the p2p_set op_ch = x */
143 u8 peer_ch; /* The listen channel for peer P2P device */
144
145};
146
147struct tx_invite_resp_info {
148 u8 token; /* Used to record the dialog token of p2p invitation request frame. */
149};
150
Larry Finger364e30e2014-03-28 21:37:41 -0500151struct tx_provdisc_req_info {
152 u16 wps_config_method_request; /* Used when sending the provisioning request frame */
153 u16 peer_channel_num[2]; /* The channel number which the receiver stands. */
154 struct cfg80211_ssid ssid;
155 u8 peerDevAddr[ETH_ALEN]; /* Peer device address */
156 u8 peerIFAddr[ETH_ALEN]; /* Peer interface address */
157 u8 benable; /* This provision discovery request frame is trigger to send or not */
158};
159
160struct rx_provdisc_req_info { /* When peer device issue prov_disc_req first, we should store the following informations */
161 u8 peerDevAddr[ETH_ALEN]; /* Peer device address */
162 u8 strconfig_method_desc_of_prov_disc_req[4]; /* description for the config method located in the provisioning discovery request frame. */
163 /* The UI must know this information to know which config method the remote p2p device is requiring. */
164};
165
166struct tx_nego_req_info {
167 u16 peer_channel_num[2]; /* The channel number which the receiver stands. */
168 u8 peerDevAddr[ETH_ALEN];/* Peer device address */
169 u8 benable; /* This negoitation request frame is trigger to send or not */
170};
171
172struct group_id_info {
173 u8 go_device_addr[ETH_ALEN]; /*The GO's device address of P2P group */
174 u8 ssid[IEEE80211_MAX_SSID_LEN]; /* The SSID of this P2P group */
175};
176
177struct scan_limit_info {
178 u8 scan_op_ch_only; /* When this flag is set, the driver should just scan the operation channel */
179 u8 operation_ch[2]; /* Store the operation channel of invitation request frame */
180};
181
Larry Finger364e30e2014-03-28 21:37:41 -0500182struct tdls_ss_record { /* signal strength record */
183 u8 macaddr[ETH_ALEN];
184 u8 RxPWDBAll;
185 u8 is_tdls_sta; /* true: direct link sta, false: else */
186};
187
188struct tdls_info {
189 u8 ap_prohibited;
190 uint setup_state;
191 u8 sta_cnt;
192 /* 1:tdls sta == (NUM_STA-1), reach max direct link no; 0: else; */
193 u8 sta_maximum;
194 struct tdls_ss_record ss_record;
195 u8 macid_index; /* macid entry that is ready to write */
196 /* cam entry that is trying to clear, using it in direct link teardown*/
197 u8 clear_cam;
198 u8 ch_sensing;
199 u8 cur_channel;
200 u8 candidate_ch;
201 u8 collect_pkt_num[MAX_CHANNEL_NUM];
202 spinlock_t cmd_lock;
203 spinlock_t hdl_lock;
204 u8 watchdog_count;
205 u8 dev_discovered; /* WFD_TDLS: for sigma test */
206 u8 enable;
Larry Finger364e30e2014-03-28 21:37:41 -0500207};
208
209struct mlme_priv {
210 spinlock_t lock;
211 int fw_state;
212 u8 bScanInProcess;
213 u8 to_join; /* flag */
214 u8 to_roaming; /* roaming trying times */
215
216 struct rtw_adapter *nic_hdl;
217
218 u8 not_indic_disco;
219 struct rtw_queue scanned_queue;
220
221 struct cfg80211_ssid assoc_ssid;
222 u8 assoc_bssid[6];
223
224 struct wlan_network cur_network;
225
226 /* uint wireless_mode; no used, remove it */
227
228 u32 scan_interval;
229
230 struct timer_list assoc_timer;
231
232 uint assoc_by_bssid;
233 uint assoc_by_rssi;
234
235 struct timer_list scan_to_timer;
236
237 struct timer_list set_scan_deny_timer;
238 atomic_t set_scan_deny; /* 0: allowed, 1: deny */
239
Jes Sorensenbd8ad4a2014-05-09 15:03:21 +0200240 unsigned int qos_option;
Larry Finger364e30e2014-03-28 21:37:41 -0500241
242 /* Number of non-HT AP/stations */
243 int num_sta_no_ht;
244
245 int num_FortyMHzIntolerant;
246
247 struct ht_priv htpriv;
248
249 struct rt_link_detect LinkDetectInfo;
250 struct timer_list dynamic_chk_timer; /* dynamic/periodic check timer */
251
252 u8 key_mask; /* use for ips to set wep key after ips_leave23a */
253 u8 acm_mask; /* for wmm acm mask */
254 u8 ChannelPlan;
255 enum rt_scan_type scan_mode; /* active: 1, passive: 0 */
256
257 u8 *wps_probe_req_ie;
258 u32 wps_probe_req_ie_len;
Larry Fingerc17416e2014-03-28 21:37:42 -0500259 u8 *assoc_req;
260 u32 assoc_req_len;
261 u32 assoc_rsp_len;
262 u8 *assoc_rsp;
263 u32 wps_assoc_resp_ie_len;
264 u8 *wps_assoc_resp_ie;
265 u8 *wps_probe_resp_ie;
266 u32 wps_probe_resp_ie_len;
267 u8 *wps_beacon_ie;
268 u32 wps_beacon_ie_len;
269 u32 p2p_go_probe_resp_ie_len; /* for GO */
270 u32 p2p_assoc_req_ie_len;
271 u8 *p2p_beacon_ie;
272 u8 *p2p_probe_req_ie;
273 u8 *p2p_probe_resp_ie;
274 u8 *p2p_go_probe_resp_ie; /* for GO */
275 u8 *p2p_assoc_req_ie;
276 u32 p2p_beacon_ie_len;
277 u32 p2p_probe_req_ie_len;
278 u32 p2p_probe_resp_ie_len;
279 u8 *wfd_assoc_req_ie;
280 u32 wfd_assoc_req_ie_len;
Larry Finger364e30e2014-03-28 21:37:41 -0500281
282#ifdef CONFIG_8723AU_AP_MODE
283 /* Number of associated Non-ERP stations (i.e., stations using 802.11b
284 * in 802.11g BSS) */
285 int num_sta_non_erp;
286
287 /* Number of associated stations that do not support Short Slot Time */
288 int num_sta_no_short_slot_time;
289
290 /* Number of associated stations that do not support Short Preamble */
291 int num_sta_no_short_preamble;
292
293 int olbc; /* Overlapping Legacy BSS Condition */
294
295 /* Number of HT associated stations that do not support greenfield */
296 int num_sta_ht_no_gf;
297
298 /* Number of associated non-HT stations */
299 /* int num_sta_no_ht; */
300
301 /* Number of HT associated stations 20 MHz */
302 int num_sta_ht_20mhz;
303
304 /* Overlapping BSS information */
305 int olbc_ht;
306
307 u16 ht_op_mode;
308
Larry Finger364e30e2014-03-28 21:37:41 -0500309 spinlock_t bcn_update_lock;
310 u8 update_bcn;
311
312#endif /* ifdef CONFIG_8723AU_AP_MODE */
313
Larry Finger364e30e2014-03-28 21:37:41 -0500314 u8 *wfd_beacon_ie;
315 u8 *wfd_probe_req_ie;
316 u8 *wfd_probe_resp_ie;
317 u8 *wfd_go_probe_resp_ie; /* for GO */
Larry Finger364e30e2014-03-28 21:37:41 -0500318
319 u32 wfd_beacon_ie_len;
320 u32 wfd_probe_req_ie_len;
321 u32 wfd_probe_resp_ie_len;
322 u32 wfd_go_probe_resp_ie_len; /* for GO */
Larry Finger364e30e2014-03-28 21:37:41 -0500323};
324
325#ifdef CONFIG_8723AU_AP_MODE
326
327struct hostapd_priv {
328 struct rtw_adapter *padapter;
329};
330
331int hostapd_mode_init(struct rtw_adapter *padapter);
332void hostapd_mode_unload(struct rtw_adapter *padapter);
333#endif
334
335void rtw_joinbss_event_prehandle23a(struct rtw_adapter *adapter, u8 *pbuf);
Jes Sorensene2601962014-05-09 15:03:19 +0200336void rtw_survey_event_cb23a(struct rtw_adapter *adapter, const u8 *pbuf);
337void rtw_surveydone_event_callback23a(struct rtw_adapter *adapter, const u8 *pbuf);
338void rtw23a_joinbss_event_cb(struct rtw_adapter *adapter, const u8 *pbuf);
339void rtw_stassoc_event_callback23a(struct rtw_adapter *adapter, const u8 *pbuf);
340void rtw_stadel_event_callback23a(struct rtw_adapter *adapter, const u8 *pbuf);
341void rtw_atimdone_event_callback23a(struct rtw_adapter *adapter, const u8 *pbuf);
342void rtw_cpwm_event_callback23a(struct rtw_adapter *adapter, const u8 *pbuf);
Larry Finger364e30e2014-03-28 21:37:41 -0500343
344
345int event_thread(void *context);
346void rtw23a_join_to_handler(unsigned long);
347
Jes Sorensen528e5c12014-04-26 18:55:51 +0200348void rtw_free_network_queue23a(struct rtw_adapter *adapter);
Larry Finger364e30e2014-03-28 21:37:41 -0500349int rtw_init_mlme_priv23a(struct rtw_adapter *adapter);
350
351void rtw_free_mlme_priv23a(struct mlme_priv *pmlmepriv);
352
353int rtw_select_and_join_from_scanned_queue23a(struct mlme_priv *pmlmepriv);
354int rtw_set_key23a(struct rtw_adapter *adapter,
355 struct security_priv *psecuritypriv, int keyid, u8 set_tx);
356int rtw_set_auth23a(struct rtw_adapter *adapter,
357 struct security_priv *psecuritypriv);
358
359static inline u8 *get_bssid(struct mlme_priv *pmlmepriv)
360{ /* if sta_mode:pmlmepriv->cur_network.network.MacAddress => bssid */
361 /* if adhoc_mode:pmlmepriv->cur_network.network.MacAddress => ibss mac address */
362 return pmlmepriv->cur_network.network.MacAddress;
363}
364
365static inline int check_fwstate(struct mlme_priv *pmlmepriv, int state)
366{
367 if (pmlmepriv->fw_state & state)
368 return true;
369
370 return false;
371}
372
373static inline int get_fwstate(struct mlme_priv *pmlmepriv)
374{
375 return pmlmepriv->fw_state;
376}
377
378/*
379 * No Limit on the calling context,
380 * therefore set it to be the critical section...
381 *
382 * ### NOTE:#### (!!!!)
383 * MUST TAKE CARE THAT BEFORE CALLING THIS FUNC, YOU SHOULD HAVE LOCKED pmlmepriv->lock
384 */
385static inline void set_fwstate(struct mlme_priv *pmlmepriv, int state)
386{
387 pmlmepriv->fw_state |= state;
388 /* FOR HW integration */
389 if (_FW_UNDER_SURVEY == state)
390 pmlmepriv->bScanInProcess = true;
391}
392
393static inline void _clr_fwstate_(struct mlme_priv *pmlmepriv, int state)
394{
395 pmlmepriv->fw_state &= ~state;
396 /* FOR HW integration */
397 if (_FW_UNDER_SURVEY == state)
398 pmlmepriv->bScanInProcess = false;
399}
400
401/*
402 * No Limit on the calling context,
403 * therefore set it to be the critical section...
404 */
405static inline void clr_fwstate(struct mlme_priv *pmlmepriv, int state)
406{
407 spin_lock_bh(&pmlmepriv->lock);
408 if (check_fwstate(pmlmepriv, state) == true)
409 pmlmepriv->fw_state ^= state;
410 spin_unlock_bh(&pmlmepriv->lock);
411}
412
413static inline void clr_fwstate_ex(struct mlme_priv *pmlmepriv, int state)
414{
415 spin_lock_bh(&pmlmepriv->lock);
416 _clr_fwstate_(pmlmepriv, state);
417 spin_unlock_bh(&pmlmepriv->lock);
418}
419
420u16 rtw_get_capability23a(struct wlan_bssid_ex *bss);
421void rtw_update_scanned_network23a(struct rtw_adapter *adapter,
422 struct wlan_bssid_ex *target);
423void rtw_disconnect_hdl23a_under_linked(struct rtw_adapter *adapter,
424 struct sta_info *psta, u8 free_assoc);
425void rtw_generate_random_ibss23a(u8 *pibss);
426struct wlan_network *rtw_find_network23a(struct rtw_queue *scanned_queue, u8 *addr);
427struct wlan_network *rtw_get_oldest_wlan_network23a(struct rtw_queue *scanned_queue);
428
429void rtw_free_assoc_resources23a(struct rtw_adapter *adapter,
430 int lock_scanned_queue);
431void rtw_indicate_disconnect23a(struct rtw_adapter *adapter);
432void rtw_indicate_connect23a(struct rtw_adapter *adapter);
Larry Finger364e30e2014-03-28 21:37:41 -0500433void rtw_scan_abort23a(struct rtw_adapter *adapter);
434
435int rtw_restruct_sec_ie23a(struct rtw_adapter *adapter, u8 *in_ie, u8 *out_ie,
436 uint in_len);
437int rtw_restruct_wmm_ie23a(struct rtw_adapter *adapter, u8 *in_ie, u8 *out_ie,
438 uint in_len, uint initial_out_len);
439void rtw_init_registrypriv_dev_network23a(struct rtw_adapter *adapter);
440
441void rtw_update_registrypriv_dev_network23a(struct rtw_adapter *adapter);
442
443void rtw_get_encrypt_decrypt_from_registrypriv23a(struct rtw_adapter *adapter);
444
445void rtw_scan_timeout_handler23a(unsigned long data);
446
447void rtw_dynamic_check_timer_handler(unsigned long data);
448bool rtw_is_scan_deny(struct rtw_adapter *adapter);
449void rtw_clear_scan_deny(struct rtw_adapter *adapter);
450void rtw_set_scan_deny_timer_hdl(unsigned long data);
451void rtw_set_scan_deny(struct rtw_adapter *adapter, u32 ms);
452
Larry Finger364e30e2014-03-28 21:37:41 -0500453void rtw23a_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv);
454
455void _rtw_free_mlme_priv23a(struct mlme_priv *pmlmepriv);
456
457struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv);
458
Larry Finger364e30e2014-03-28 21:37:41 -0500459int rtw_if_up23a(struct rtw_adapter *padapter);
460
461int rtw_linked_check(struct rtw_adapter *padapter);
462
Jes Sorensen6a235442014-04-26 18:55:41 +0200463__le16 *rtw_get_capability23a_from_ie(u8 *ie);
Jes Sorensend7cfe7c2014-04-26 18:55:43 +0200464__le16 *rtw_get_beacon_interval23a_from_ie(u8 *ie);
Larry Finger364e30e2014-03-28 21:37:41 -0500465
466
467void rtw_joinbss_reset23a(struct rtw_adapter *padapter);
468
469unsigned int rtw_restructure_ht_ie23a(struct rtw_adapter *padapter, u8 *in_ie,
470 u8 *out_ie, uint in_len, uint *pout_len);
471void rtw_update_ht_cap23a(struct rtw_adapter *padapter,
472 u8 *pie, uint ie_len);
473void rtw_issue_addbareq_cmd23a(struct rtw_adapter *padapter,
474 struct xmit_frame *pxmitframe);
475
476int rtw_is_same_ibss23a(struct rtw_adapter *adapter,
477 struct wlan_network *pnetwork);
478int is_same_network23a(struct wlan_bssid_ex *src, struct wlan_bssid_ex *dst);
479
Larry Finger364e30e2014-03-28 21:37:41 -0500480void rtw23a_roaming(struct rtw_adapter *adapter,
481 struct wlan_network *tgt_network);
482void rtw_set_roaming(struct rtw_adapter *adapter, u8 to_roaming);
Larry Finger364e30e2014-03-28 21:37:41 -0500483
484#endif /* __RTL871X_MLME_H_ */