blob: dbd3a5f5c52333f4b22c13013834f9cd486fdde8 [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
Carlos E. Garcia69e98df2015-04-24 09:40:42 -040053#define WIFI_MP_CTX_BACKGROUND 0x00020000 /* in continuous tx background */
54#define WIFI_MP_CTX_ST 0x00040000 /* in continuous tx with single-tone */
55#define WIFI_MP_CTX_BACKGROUND_PENDING 0x00080000 /* pending in continuous tx background due to out of skb */
56#define WIFI_MP_CTX_CCK_HW 0x00100000 /* in continuous tx */
57#define WIFI_MP_CTX_CCK_CS 0x00200000 /* in continuous tx with carrier suppression */
Larry Finger364e30e2014-03-28 21:37:41 -050058#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
Larry Finger364e30e2014-03-28 21:37:41 -050086/*
87
88there are several "locks" in mlme_priv,
89since mlme_priv is a shared resource between many threads,
90like ISR/Call-Back functions, the OID handlers, and even timer functions.
91
92
93Each _queue has its own locks, already.
94Other items are protected by mlme_priv.lock.
95
96To avoid possible dead lock, any thread trying to modifiying mlme_priv
97SHALL not lock up more than one locks at a time!
98*/
99
Larry Finger364e30e2014-03-28 21:37:41 -0500100struct rt_link_detect {
101 u32 NumTxOkInPeriod;
102 u32 NumRxOkInPeriod;
103 u32 NumRxUnicastOkInPeriod;
104 bool bBusyTraffic;
105 bool bTxBusyTraffic;
106 bool bRxBusyTraffic;
107 bool bHigherBusyTraffic; /* For interrupt migration purpose. */
108 bool bHigherBusyRxTraffic; /* We may disable Tx interrupt according as Rx traffic. */
109 bool bHigherBusyTxTraffic; /* We may disable Tx interrupt according as Tx traffic. */
110};
111
Larry Finger364e30e2014-03-28 21:37:41 -0500112struct mlme_priv {
113 spinlock_t lock;
114 int fw_state;
115 u8 bScanInProcess;
116 u8 to_join; /* flag */
117 u8 to_roaming; /* roaming trying times */
118
119 struct rtw_adapter *nic_hdl;
120
121 u8 not_indic_disco;
122 struct rtw_queue scanned_queue;
123
124 struct cfg80211_ssid assoc_ssid;
125 u8 assoc_bssid[6];
126
127 struct wlan_network cur_network;
128
129 /* uint wireless_mode; no used, remove it */
130
131 u32 scan_interval;
132
133 struct timer_list assoc_timer;
134
135 uint assoc_by_bssid;
136 uint assoc_by_rssi;
137
138 struct timer_list scan_to_timer;
139
140 struct timer_list set_scan_deny_timer;
141 atomic_t set_scan_deny; /* 0: allowed, 1: deny */
142
Jes Sorensenbd8ad4a2014-05-09 15:03:21 +0200143 unsigned int qos_option;
Larry Finger364e30e2014-03-28 21:37:41 -0500144
145 /* Number of non-HT AP/stations */
146 int num_sta_no_ht;
147
148 int num_FortyMHzIntolerant;
149
150 struct ht_priv htpriv;
151
152 struct rt_link_detect LinkDetectInfo;
153 struct timer_list dynamic_chk_timer; /* dynamic/periodic check timer */
154
155 u8 key_mask; /* use for ips to set wep key after ips_leave23a */
156 u8 acm_mask; /* for wmm acm mask */
157 u8 ChannelPlan;
158 enum rt_scan_type scan_mode; /* active: 1, passive: 0 */
159
160 u8 *wps_probe_req_ie;
161 u32 wps_probe_req_ie_len;
Larry Fingerc17416e2014-03-28 21:37:42 -0500162 u8 *assoc_req;
163 u32 assoc_req_len;
164 u32 assoc_rsp_len;
165 u8 *assoc_rsp;
Larry Finger364e30e2014-03-28 21:37:41 -0500166
167#ifdef CONFIG_8723AU_AP_MODE
168 /* Number of associated Non-ERP stations (i.e., stations using 802.11b
169 * in 802.11g BSS) */
170 int num_sta_non_erp;
171
172 /* Number of associated stations that do not support Short Slot Time */
173 int num_sta_no_short_slot_time;
174
175 /* Number of associated stations that do not support Short Preamble */
176 int num_sta_no_short_preamble;
177
178 int olbc; /* Overlapping Legacy BSS Condition */
179
180 /* Number of HT associated stations that do not support greenfield */
181 int num_sta_ht_no_gf;
182
183 /* Number of associated non-HT stations */
184 /* int num_sta_no_ht; */
185
186 /* Number of HT associated stations 20 MHz */
187 int num_sta_ht_20mhz;
188
189 /* Overlapping BSS information */
190 int olbc_ht;
191
192 u16 ht_op_mode;
193
Larry Finger364e30e2014-03-28 21:37:41 -0500194 spinlock_t bcn_update_lock;
195 u8 update_bcn;
196
197#endif /* ifdef CONFIG_8723AU_AP_MODE */
Larry Finger364e30e2014-03-28 21:37:41 -0500198};
199
Larry Finger364e30e2014-03-28 21:37:41 -0500200void rtw_joinbss_event_prehandle23a(struct rtw_adapter *adapter, u8 *pbuf);
Jes Sorensene2601962014-05-09 15:03:19 +0200201void rtw_survey_event_cb23a(struct rtw_adapter *adapter, const u8 *pbuf);
202void rtw_surveydone_event_callback23a(struct rtw_adapter *adapter, const u8 *pbuf);
203void rtw23a_joinbss_event_cb(struct rtw_adapter *adapter, const u8 *pbuf);
204void rtw_stassoc_event_callback23a(struct rtw_adapter *adapter, const u8 *pbuf);
205void rtw_stadel_event_callback23a(struct rtw_adapter *adapter, const u8 *pbuf);
Larry Finger364e30e2014-03-28 21:37:41 -0500206
207int event_thread(void *context);
208void rtw23a_join_to_handler(unsigned long);
209
Jes Sorensen528e5c12014-04-26 18:55:51 +0200210void rtw_free_network_queue23a(struct rtw_adapter *adapter);
Larry Finger364e30e2014-03-28 21:37:41 -0500211int rtw_init_mlme_priv23a(struct rtw_adapter *adapter);
212
213void rtw_free_mlme_priv23a(struct mlme_priv *pmlmepriv);
214
Jes Sorensenfcc60202014-06-09 15:16:53 +0200215int rtw_do_join_adhoc(struct rtw_adapter *adapter);
Jes Sorensenb66dad22014-06-09 15:16:50 +0200216int rtw_do_join_network(struct rtw_adapter *adapter,
217 struct wlan_network *candidate);
Larry Finger364e30e2014-03-28 21:37:41 -0500218int rtw_select_and_join_from_scanned_queue23a(struct mlme_priv *pmlmepriv);
219int rtw_set_key23a(struct rtw_adapter *adapter,
220 struct security_priv *psecuritypriv, int keyid, u8 set_tx);
221int rtw_set_auth23a(struct rtw_adapter *adapter,
222 struct security_priv *psecuritypriv);
223
224static inline u8 *get_bssid(struct mlme_priv *pmlmepriv)
225{ /* if sta_mode:pmlmepriv->cur_network.network.MacAddress => bssid */
226 /* if adhoc_mode:pmlmepriv->cur_network.network.MacAddress => ibss mac address */
227 return pmlmepriv->cur_network.network.MacAddress;
228}
229
Jes Sorensena6ab7522014-05-25 22:43:05 +0200230static inline bool check_fwstate(struct mlme_priv *pmlmepriv, int state)
Larry Finger364e30e2014-03-28 21:37:41 -0500231{
232 if (pmlmepriv->fw_state & state)
233 return true;
234
235 return false;
236}
237
238static inline int get_fwstate(struct mlme_priv *pmlmepriv)
239{
240 return pmlmepriv->fw_state;
241}
242
243/*
244 * No Limit on the calling context,
245 * therefore set it to be the critical section...
246 *
247 * ### NOTE:#### (!!!!)
248 * MUST TAKE CARE THAT BEFORE CALLING THIS FUNC, YOU SHOULD HAVE LOCKED pmlmepriv->lock
249 */
250static inline void set_fwstate(struct mlme_priv *pmlmepriv, int state)
251{
252 pmlmepriv->fw_state |= state;
253 /* FOR HW integration */
254 if (_FW_UNDER_SURVEY == state)
255 pmlmepriv->bScanInProcess = true;
256}
257
258static inline void _clr_fwstate_(struct mlme_priv *pmlmepriv, int state)
259{
260 pmlmepriv->fw_state &= ~state;
261 /* FOR HW integration */
262 if (_FW_UNDER_SURVEY == state)
263 pmlmepriv->bScanInProcess = false;
264}
265
266/*
267 * No Limit on the calling context,
268 * therefore set it to be the critical section...
269 */
270static inline void clr_fwstate(struct mlme_priv *pmlmepriv, int state)
271{
272 spin_lock_bh(&pmlmepriv->lock);
Roberta Dobrescu08551cb2014-10-26 23:30:05 +0200273 if (check_fwstate(pmlmepriv, state))
Larry Finger364e30e2014-03-28 21:37:41 -0500274 pmlmepriv->fw_state ^= state;
275 spin_unlock_bh(&pmlmepriv->lock);
276}
277
278static inline void clr_fwstate_ex(struct mlme_priv *pmlmepriv, int state)
279{
280 spin_lock_bh(&pmlmepriv->lock);
281 _clr_fwstate_(pmlmepriv, state);
282 spin_unlock_bh(&pmlmepriv->lock);
283}
284
Larry Finger364e30e2014-03-28 21:37:41 -0500285void rtw_disconnect_hdl23a_under_linked(struct rtw_adapter *adapter,
286 struct sta_info *psta, u8 free_assoc);
287void rtw_generate_random_ibss23a(u8 *pibss);
288struct wlan_network *rtw_find_network23a(struct rtw_queue *scanned_queue, u8 *addr);
289struct wlan_network *rtw_get_oldest_wlan_network23a(struct rtw_queue *scanned_queue);
290
291void rtw_free_assoc_resources23a(struct rtw_adapter *adapter,
292 int lock_scanned_queue);
293void rtw_indicate_disconnect23a(struct rtw_adapter *adapter);
294void rtw_indicate_connect23a(struct rtw_adapter *adapter);
Larry Finger364e30e2014-03-28 21:37:41 -0500295void rtw_scan_abort23a(struct rtw_adapter *adapter);
296
297int rtw_restruct_sec_ie23a(struct rtw_adapter *adapter, u8 *in_ie, u8 *out_ie,
298 uint in_len);
299int rtw_restruct_wmm_ie23a(struct rtw_adapter *adapter, u8 *in_ie, u8 *out_ie,
300 uint in_len, uint initial_out_len);
301void rtw_init_registrypriv_dev_network23a(struct rtw_adapter *adapter);
302
303void rtw_update_registrypriv_dev_network23a(struct rtw_adapter *adapter);
304
Larry Finger364e30e2014-03-28 21:37:41 -0500305void rtw_scan_timeout_handler23a(unsigned long data);
306
307void rtw_dynamic_check_timer_handler(unsigned long data);
308bool rtw_is_scan_deny(struct rtw_adapter *adapter);
309void rtw_clear_scan_deny(struct rtw_adapter *adapter);
310void rtw_set_scan_deny_timer_hdl(unsigned long data);
311void rtw_set_scan_deny(struct rtw_adapter *adapter, u32 ms);
312
Larry Finger364e30e2014-03-28 21:37:41 -0500313void rtw23a_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv);
314
315void _rtw_free_mlme_priv23a(struct mlme_priv *pmlmepriv);
316
Clément Calmels809d2082014-06-26 10:20:46 +0200317struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv, gfp_t gfp);
Larry Finger364e30e2014-03-28 21:37:41 -0500318
Larry Finger364e30e2014-03-28 21:37:41 -0500319int rtw_if_up23a(struct rtw_adapter *padapter);
320
321int rtw_linked_check(struct rtw_adapter *padapter);
322
Larry Finger364e30e2014-03-28 21:37:41 -0500323void rtw_joinbss_reset23a(struct rtw_adapter *padapter);
324
Jes Sorensen6f765c22014-06-09 15:16:06 +0200325bool rtw_restructure_ht_ie23a(struct rtw_adapter *padapter, u8 *in_ie,
326 u8 *out_ie, uint in_len, uint *pout_len);
Larry Finger364e30e2014-03-28 21:37:41 -0500327void rtw_update_ht_cap23a(struct rtw_adapter *padapter,
328 u8 *pie, uint ie_len);
329void rtw_issue_addbareq_cmd23a(struct rtw_adapter *padapter,
330 struct xmit_frame *pxmitframe);
331
Jes Sorensenec36ce22014-06-09 15:16:36 +0200332bool rtw_is_same_ibss23a(struct rtw_adapter *adapter,
333 struct wlan_network *pnetwork);
Larry Finger364e30e2014-03-28 21:37:41 -0500334int is_same_network23a(struct wlan_bssid_ex *src, struct wlan_bssid_ex *dst);
335
Larry Finger364e30e2014-03-28 21:37:41 -0500336void rtw23a_roaming(struct rtw_adapter *adapter,
337 struct wlan_network *tgt_network);
338void rtw_set_roaming(struct rtw_adapter *adapter, u8 to_roaming);
Larry Finger364e30e2014-03-28 21:37:41 -0500339
340#endif /* __RTL871X_MLME_H_ */