1 #ifndef __RTL871X_MLME_H_
2 #define __RTL871X_MLME_H_
3 
4 #include "osdep_service.h"
5 #include "drv_types.h"
6 #include "wlan_bssdef.h"
7 
8 #define	MAX_BSS_CNT	64
9 #define   MAX_JOIN_TIMEOUT	6000
10 
11 #define		SCANNING_TIMEOUT	4500
12 
13 #define	SCANQUEUE_LIFETIME 20 /* unit:sec */
14 
15 #define		WIFI_NULL_STATE	0x00000000
16 #define	WIFI_ASOC_STATE		0x00000001	/* Under Linked state...*/
17 #define		WIFI_REASOC_STATE 0x00000002
18 #define	WIFI_SLEEP_STATE	0x00000004
19 #define	WIFI_STATION_STATE	0x00000008
20 #define	WIFI_AP_STATE		0x00000010
21 #define	WIFI_ADHOC_STATE	0x00000020
22 #define   WIFI_ADHOC_MASTER_STATE 0x00000040
23 #define   WIFI_UNDER_LINKING	0x00000080
24 #define WIFI_SITE_MONITOR	0x00000800	/* to indicate the station
25 						 * is under site surveying*/
26 #define	WIFI_MP_STATE		0x00010000
27 #define	WIFI_MP_CTX_BACKGROUND	0x00020000	/* in cont. tx background*/
28 #define	WIFI_MP_CTX_ST		0x00040000	/* in cont. tx with
29 						 *  single-tone*/
30 #define	WIFI_MP_CTX_BACKGROUND_PENDING	0x00080000 /* pending in cont, tx
31 					* background due to out of skb*/
32 #define	WIFI_MP_CTX_CCK_HW	0x00100000	/* in continuous tx*/
33 #define	WIFI_MP_CTX_CCK_CS	0x00200000	/* in cont, tx with carrier
34 						 * suppression*/
35 #define   WIFI_MP_LPBK_STATE	0x00400000
36 
37 #define _FW_UNDER_LINKING	WIFI_UNDER_LINKING
38 #define _FW_LINKED		WIFI_ASOC_STATE
39 #define _FW_UNDER_SURVEY	WIFI_SITE_MONITOR
40 
41 /*
42 there are several "locks" in mlme_priv,
43 since mlme_priv is a shared resource between many threads,
44 like ISR/Call-Back functions, the OID handlers, and even timer functions.
45 Each _queue has its own locks, already.
46 Other items are protected by mlme_priv.lock.
47 To avoid possible dead lock, any thread trying to modifiying mlme_priv
48 SHALL not lock up more than one locks at a time!
49 */
50 
51 #define traffic_threshold	10
52 #define	traffic_scan_period	500
53 
54 struct sitesurvey_ctrl {
55 	u64	last_tx_pkts;
56 	uint	last_rx_pkts;
57 	sint	traffic_busy;
58 	struct timer_list sitesurvey_ctrl_timer;
59 };
60 
61 struct mlme_priv {
62 
63 	spinlock_t lock;
64 	spinlock_t lock2;
65 	sint	fw_state;	/*shall we protect this variable? */
66 	u8 to_join; /*flag*/
67 	u8 *nic_hdl;
68 	struct list_head *pscanned;
69 	struct  __queue free_bss_pool;
70 	struct  __queue scanned_queue;
71 	u8 *free_bss_buf;
72 	unsigned long num_of_scanned;
73 	struct ndis_802_11_ssid	assoc_ssid;
74 	u8 assoc_bssid[6];
75 	struct wlan_network cur_network;
76 	struct sitesurvey_ctrl sitesurveyctrl;
77 	struct timer_list assoc_timer;
78 	uint assoc_by_bssid;
79 	uint assoc_by_rssi;
80 	struct timer_list scan_to_timer; /* driver handles scan_timeout.*/
81 	struct timer_list dhcp_timer; /* set dhcp to if driver in ps mode.*/
82 	struct qos_priv qospriv;
83 	struct ht_priv	htpriv;
84 	struct timer_list wdg_timer; /*watchdog periodic timer*/
85 };
86 
get_bssid(struct mlme_priv * pmlmepriv)87 static inline u8 *get_bssid(struct mlme_priv *pmlmepriv)
88 {
89 	return pmlmepriv->cur_network.network.MacAddress;
90 }
91 
check_fwstate(struct mlme_priv * pmlmepriv,sint state)92 static inline u8 check_fwstate(struct mlme_priv *pmlmepriv, sint state)
93 {
94 	if (pmlmepriv->fw_state & state)
95 		return true;
96 	return false;
97 }
98 
get_fwstate(struct mlme_priv * pmlmepriv)99 static inline sint get_fwstate(struct mlme_priv *pmlmepriv)
100 {
101 	return pmlmepriv->fw_state;
102 }
103 
104 /*
105  * No Limit on the calling context,
106  * therefore set it to be the critical section...
107  *
108  * ### NOTE:#### (!!!!)
109  * TAKE CARE THAT BEFORE CALLING THIS FUNC, LOCK pmlmepriv->lock
110  */
set_fwstate(struct mlme_priv * pmlmepriv,sint state)111 static inline void set_fwstate(struct mlme_priv *pmlmepriv, sint state)
112 {
113 	pmlmepriv->fw_state |= state;
114 }
115 
_clr_fwstate_(struct mlme_priv * pmlmepriv,sint state)116 static inline void _clr_fwstate_(struct mlme_priv *pmlmepriv, sint state)
117 {
118 	pmlmepriv->fw_state &= ~state;
119 }
120 
121 /*
122  * No Limit on the calling context,
123  * therefore set it to be the critical section...
124  */
clr_fwstate(struct mlme_priv * pmlmepriv,sint state)125 static inline void clr_fwstate(struct mlme_priv *pmlmepriv, sint state)
126 {
127 	unsigned long irqL;
128 
129 	spin_lock_irqsave(&pmlmepriv->lock, irqL);
130 	if (check_fwstate(pmlmepriv, state) == true)
131 		pmlmepriv->fw_state ^= state;
132 	spin_unlock_irqrestore(&pmlmepriv->lock, irqL);
133 }
134 
up_scanned_network(struct mlme_priv * pmlmepriv)135 static inline void up_scanned_network(struct mlme_priv *pmlmepriv)
136 {
137 	unsigned long irqL;
138 
139 	spin_lock_irqsave(&pmlmepriv->lock, irqL);
140 	pmlmepriv->num_of_scanned++;
141 	spin_unlock_irqrestore(&pmlmepriv->lock, irqL);
142 }
143 
down_scanned_network(struct mlme_priv * pmlmepriv)144 static inline void down_scanned_network(struct mlme_priv *pmlmepriv)
145 {
146 	unsigned long irqL;
147 
148 	spin_lock_irqsave(&pmlmepriv->lock, irqL);
149 	pmlmepriv->num_of_scanned--;
150 	spin_unlock_irqrestore(&pmlmepriv->lock, irqL);
151 }
152 
set_scanned_network_val(struct mlme_priv * pmlmepriv,sint val)153 static inline void set_scanned_network_val(struct mlme_priv *pmlmepriv,
154 					     sint val)
155 {
156 	unsigned long irqL;
157 
158 	spin_lock_irqsave(&pmlmepriv->lock, irqL);
159 	pmlmepriv->num_of_scanned = val;
160 	spin_unlock_irqrestore(&pmlmepriv->lock, irqL);
161 }
162 
163 void r8712_survey_event_callback(struct _adapter *adapter, u8 *pbuf);
164 void r8712_surveydone_event_callback(struct _adapter *adapter, u8 *pbuf);
165 void r8712_joinbss_event_callback(struct _adapter *adapter, u8 *pbuf);
166 void r8712_stassoc_event_callback(struct _adapter *adapter, u8 *pbuf);
167 void r8712_stadel_event_callback(struct _adapter *adapter, u8 *pbuf);
168 void r8712_atimdone_event_callback(struct _adapter *adapter, u8 *pbuf);
169 void r8712_cpwm_event_callback(struct _adapter *adapter, u8 *pbuf);
170 void r8712_wpspbc_event_callback(struct _adapter *adapter, u8 *pbuf);
171 void r8712_free_network_queue(struct _adapter *adapter);
172 int r8712_init_mlme_priv(struct _adapter *adapter);
173 void r8712_free_mlme_priv(struct mlme_priv *pmlmepriv);
174 sint r8712_select_and_join_from_scan(struct mlme_priv *pmlmepriv);
175 sint r8712_set_key(struct _adapter *adapter,
176 		   struct security_priv *psecuritypriv, sint keyid);
177 sint r8712_set_auth(struct _adapter *adapter,
178 		    struct security_priv *psecuritypriv);
179 uint r8712_get_ndis_wlan_bssid_ex_sz(struct ndis_wlan_bssid_ex *bss);
180 void r8712_generate_random_ibss(u8 *pibss);
181 u8 *r8712_get_capability_from_ie(u8 *ie);
182 struct wlan_network *r8712_get_oldest_wlan_network(
183 				struct  __queue *scanned_queue);
184 void r8712_free_assoc_resources(struct _adapter *adapter);
185 void r8712_ind_disconnect(struct _adapter *adapter);
186 void r8712_indicate_connect(struct _adapter *adapter);
187 int r8712_restruct_sec_ie(struct _adapter *adapter, u8 *in_ie,
188 			  u8 *out_ie, uint in_len);
189 int r8712_restruct_wmm_ie(struct _adapter *adapter, u8 *in_ie,
190 			  u8 *out_ie, uint in_len, uint initial_out_len);
191 void r8712_init_registrypriv_dev_network(struct _adapter *adapter);
192 void r8712_update_registrypriv_dev_network(struct _adapter *adapter);
193 void _r8712_sitesurvey_ctrl_handler(struct _adapter *adapter);
194 void _r8712_join_timeout_handler(struct _adapter *adapter);
195 void r8712_scan_timeout_handler(struct _adapter *adapter);
196 void _r8712_dhcp_timeout_handler(struct _adapter *adapter);
197 void _r8712_wdg_timeout_handler(struct _adapter *adapter);
198 struct wlan_network *_r8712_alloc_network(struct mlme_priv *pmlmepriv);
199 sint r8712_if_up(struct _adapter *padapter);
200 void r8712_joinbss_reset(struct _adapter *padapter);
201 unsigned int r8712_restructure_ht_ie(struct _adapter *padapter, u8 *in_ie,
202 				     u8 *out_ie, uint in_len, uint *pout_len);
203 void r8712_issue_addbareq_cmd(struct _adapter *padapter, int priority);
204 unsigned int r8712_add_ht_addt_info(struct _adapter *padapter, u8 *in_ie,
205 				    u8 *out_ie, uint in_len, uint *pout_len);
206 int r8712_is_same_ibss(struct _adapter *adapter, struct wlan_network *pnetwork);
207 
208 #endif /*__RTL871X_MLME_H_*/
209