xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852bs/include/rtw_mlme.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2021 Realtek Corporation.
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 #ifndef __RTW_MLME_H_
16 #define __RTW_MLME_H_
17 
18 
19 #define	MAX_BSS_CNT	128
20 /* #define   MAX_JOIN_TIMEOUT	2000 */
21 /* #define   MAX_JOIN_TIMEOUT	2500 */
22 #define   MAX_JOIN_TIMEOUT	6500
23 
24 /*	Commented by Albert 20101105
25  *	Increase the scanning timeout because of increasing the SURVEY_TO value. */
26 #define	SCANQUEUE_LIFETIME 20000 /* 20sec, unit:msec */
27 
28 #define MAX_UNASSOC_STA_CNT 128
29 #define UNASSOC_STA_LIFETIME_MS 60000
30 
31 /*pmlmepriv->fw_state*/
32 #define WIFI_NULL_STATE			0x00000000
33 #define WIFI_ASOC_STATE			0x00000001 /* Linked */
34 #define WIFI_REASOC_STATE			0x00000002
35 #define WIFI_SLEEP_STATE			0x00000004
36 #define WIFI_STATION_STATE			0x00000008
37 #define WIFI_AP_STATE				0x00000010
38 #define WIFI_ADHOC_STATE			0x00000020
39 #define WIFI_ADHOC_MASTER_STATE		0x00000040
40 #define WIFI_UNDER_LINKING			0x00000080
41 #define WIFI_UNDER_WPS				0x00000100
42 #define WIFI_MESH_STATE			0x00000200
43 #define WIFI_STA_ALIVE_CHK_STATE		0x00000400
44 #define WIFI_UNDER_SURVEY			0x00000800 /* under site surveying */
45 /*#define WIFI_UNDEFINED_STATE			0x00001000*/
46 /*#define WIFI_UNDEFINED_STATE			0x00002000*/
47 /*#define WIFI_UNDEFINED_STATE			0x00004000*/
48 /*#define WIFI_UNDEFINED_STATE			0x00008000*/
49 #define WIFI_MP_STATE				0x00010000
50 /*#define WIFI_UNDEFINED_STATE			0x00020000*/
51 /*#define WIFI_UNDEFINED_STATE			0x00040000*/
52 /*#define WIFI_UNDEFINED_STATE			0x00080000*/
53 /*#define WIFI_UNDEFINED_STATE			0x00100000*/
54 /*#define WIFI_UNDEFINED_STATE			0x00200000*/
55 /*#define WIFI_UNDEFINED_STATE			0x00400000*/
56 #define WIFI_OP_CH_SWITCHING			0x00800000
57 #define WIFI_UNDER_KEY_HANDSHAKE		0x01000000
58 /*#define WIFI_UNDEFINED_STATE			0x02000000*/
59 /*#define WIFI_UNDEFINED_STATE			0x04000000*/
60 /*#define WIFI_UNDEFINED_STATE			0x08000000*/
61 /*#define WIFI_UNDEFINED_STATE			0x10000000*/
62 /*#define WIFI_UNDEFINED_STATE			0x20000000*/
63 #define WIFI_CSA_UPDATE_BEACON			0x40000000
64 #define WIFI_MONITOR_STATE			0x80000000
65 
66 
67 #define MIRACAST_DISABLED	0
68 #define MIRACAST_SOURCE		BIT0
69 #define MIRACAST_SINK		BIT1
70 
71 #define MIRACAST_MODE_REVERSE(mode) \
72 	((((mode) & MIRACAST_SOURCE) ? MIRACAST_SINK : 0) | (((mode) & MIRACAST_SINK) ? MIRACAST_SOURCE : 0))
73 
74 bool is_miracast_enabled(_adapter *adapter);
75 bool rtw_chk_miracast_mode(_adapter *adapter, u8 mode);
76 const char *get_miracast_mode_str(int mode);
77 void rtw_wfd_st_switch(struct sta_info *sta, bool on);
78 
79 #define MLME_STATE(adapter) get_fwstate(&((adapter)->mlmepriv))
80 #define CHK_MLME_STATE(adapter, state) check_fwstate(&((adapter)->mlmepriv), (state))
81 
82 #define MLME_IS_NULL(adapter) CHK_MLME_STATE(adapter, WIFI_NULL_STATE)
83 #define MLME_IS_STA(adapter) CHK_MLME_STATE(adapter, WIFI_STATION_STATE)
84 #define MLME_IS_AP(adapter) CHK_MLME_STATE(adapter, WIFI_AP_STATE)
85 #define MLME_IS_ADHOC(adapter) CHK_MLME_STATE(adapter, WIFI_ADHOC_STATE)
86 #define MLME_IS_ADHOC_MASTER(adapter) CHK_MLME_STATE(adapter, WIFI_ADHOC_MASTER_STATE)
87 #define MLME_IS_MESH(adapter) CHK_MLME_STATE(adapter, WIFI_MESH_STATE)
88 #define MLME_IS_MONITOR(adapter) CHK_MLME_STATE(adapter, WIFI_MONITOR_STATE)
89 #define MLME_IS_MP(adapter) CHK_MLME_STATE(adapter, WIFI_MP_STATE)
90 #ifdef CONFIG_P2P
91 	#define MLME_IS_PD(adapter) rtw_p2p_chk_role(&(adapter)->wdinfo, P2P_ROLE_DEVICE)
92 	#define MLME_IS_GC(adapter) rtw_p2p_chk_role(&(adapter)->wdinfo, P2P_ROLE_CLIENT)
93 	#define MLME_IS_GO(adapter) rtw_p2p_chk_role(&(adapter)->wdinfo, P2P_ROLE_GO)
94 #else /* !CONFIG_P2P */
95 	#define MLME_IS_PD(adapter) 0
96 	#define MLME_IS_GC(adapter) 0
97 	#define MLME_IS_GO(adapter) 0
98 #endif /* !CONFIG_P2P */
99 
100 #define MLME_IS_MSRC(adapter) rtw_chk_miracast_mode((adapter), MIRACAST_SOURCE)
101 #define MLME_IS_MSINK(adapter) rtw_chk_miracast_mode((adapter), MIRACAST_SINK)
102 
103 #define MLME_IS_SCAN(adapter) CHK_MLME_STATE(adapter, WIFI_UNDER_SURVEY)
104 #define MLME_IS_LINKING(adapter) CHK_MLME_STATE(adapter, WIFI_UNDER_LINKING)
105 #define MLME_IS_ASOC(adapter) CHK_MLME_STATE(adapter, WIFI_ASOC_STATE)
106 #define MLME_IS_OPCH_SW(adapter) CHK_MLME_STATE(adapter, WIFI_OP_CH_SWITCHING)
107 #define MLME_IS_WPS(adapter) CHK_MLME_STATE(adapter, WIFI_UNDER_WPS)
108 
109 #if defined(CONFIG_IOCTL_CFG80211) && defined(CONFIG_P2P)
110 #define MLME_IS_ROCH(adapter) (rtw_cfg80211_get_is_roch(adapter) == _TRUE)
111 #else
112 #define MLME_IS_ROCH(adapter) 0
113 #endif
114 
115 #ifdef CONFIG_IOCTL_CFG80211
116 #define MLME_IS_MGMT_TX(adapter) rtw_cfg80211_get_is_mgmt_tx(adapter)
117 #else
118 #define MLME_IS_MGMT_TX(adapter) 0
119 #endif
120 
121 #define MLME_STATE_FMT "%s%s%s%s%s%s%s%s%s%s%s%s"
122 #define MLME_STATE_ARG(adapter) \
123 	MLME_IS_STA((adapter)) ? (MLME_IS_GC((adapter)) ? " GC" : " STA") : \
124 	MLME_IS_AP((adapter)) ? (MLME_IS_GO((adapter)) ? " GO" : " AP") : \
125 	MLME_IS_ADHOC((adapter)) ? " ADHOC" : \
126 	MLME_IS_ADHOC_MASTER((adapter)) ? " ADHOC_M" : \
127 	MLME_IS_MESH((adapter)) ? " MESH" : \
128 	MLME_IS_MONITOR((adapter)) ? " MONITOR" : \
129 	MLME_IS_MP((adapter)) ? " MP" : "", \
130 	MLME_IS_PD((adapter)) ? " PD" : "", \
131 	MLME_IS_MSRC((adapter)) ? " MSRC" : "", \
132 	MLME_IS_MSINK((adapter)) ? " MSINK" : "", \
133 	MLME_IS_SCAN((adapter)) ? " SCAN" : "", \
134 	MLME_IS_LINKING((adapter)) ? " LINKING" : "", \
135 	MLME_IS_ASOC((adapter)) ? " ASOC" : "", \
136 	MLME_IS_OPCH_SW((adapter)) ? " OPCH_SW" : "", \
137 	MLME_IS_WPS((adapter)) ? " WPS" : "", \
138 	MLME_IS_ROCH((adapter)) ? " ROCH" : "", \
139 	MLME_IS_MGMT_TX((adapter)) ? " MGMT_TX" : "", \
140 	(MLME_STATE((adapter)) & WIFI_SLEEP_STATE) ? " SLEEP" : ""
141 
142 enum {
143 	MLME_ACTION_UNKNOWN,
144 	MLME_ACTION_NONE,
145 	MLME_SCAN_ENABLE, /* WIFI_UNDER_SURVEY */
146 	MLME_SCAN_ENTER, /* WIFI_UNDER_SURVEY && !SCAN_DISABLE && !SCAN_BACK_OP */
147 	MLME_SCAN_DONE, /*  WIFI_UNDER_SURVEY && (SCAN_DISABLE || SCAN_BACK_OP) */
148 	MLME_SCAN_DISABLE, /* WIFI_UNDER_SURVEY is going to be cleared */
149 	MLME_STA_CONNECTING,
150 	MLME_STA_CONNECTED,
151 	MLME_STA_DISCONNECTED,
152 	MLME_TDLS_LINKED,
153 	MLME_TDLS_NOLINK,
154 	MLME_AP_STARTED,
155 	MLME_AP_STOPPED,
156 	MLME_ADHOC_STARTED,
157 	MLME_ADHOC_STOPPED,
158 	MLME_MESH_STARTED,
159 	MLME_MESH_STOPPED,
160 	MLME_OPCH_SWITCH,
161 };
162 
163 enum dot11AuthAlgrthmNum {
164 	dot11AuthAlgrthm_Open = 0,
165 	dot11AuthAlgrthm_Shared,
166 	dot11AuthAlgrthm_8021X,
167 	dot11AuthAlgrthm_Auto,
168 	dot11AuthAlgrthm_WAPI,
169 	dot11AuthAlgrthm_MaxNum
170 };
171 
172 /**
173  * enum mlme_auth_type - AuthenticationType
174  *
175  * @MLME_AUTHTYPE_OPEN_SYSTEM: Open System authentication
176  * @MLME_AUTHTYPE_SHARED_KEY: Shared Key authentication (WEP only)
177  * @MLME_AUTHTYPE_FT: Fast BSS Transition (IEEE 802.11r)
178  * @MLME_AUTHTYPE_NETWORK_EAP: Network EAP (some Cisco APs and mainly LEAP)
179  * @MLME_AUTHTYPE_SAE: Simultaneous authentication of equals
180  * @MLME_AUTHTYPE_FILS_SK: Fast Initial Link Setup shared key
181  * @MLME_AUTHTYPE_FILS_SK_PFS: Fast Initial Link Setup shared key with PFS
182  * @MLME_AUTHTYPE_FILS_PK: Fast Initial Link Setup public key
183  * @__MLME_AUTHTYPE_NUM: internal
184  * @MLME_AUTHTYPE_MAX: maximum valid auth algorithm
185  * @MLME_AUTHTYPE_AUTOMATIC: determine automatically (if necessary by trying
186  *      multiple times); this is invalid in netlink -- leave out the attribute
187  *      for this on CONNECT commands.
188  */
189 enum mlme_auth_type {
190 	MLME_AUTHTYPE_OPEN_SYSTEM,
191 	MLME_AUTHTYPE_SHARED_KEY,
192 	MLME_AUTHTYPE_FT,
193 	MLME_AUTHTYPE_NETWORK_EAP,
194 	MLME_AUTHTYPE_SAE,
195 	MLME_AUTHTYPE_FILS_SK,
196 	MLME_AUTHTYPE_FILS_SK_PFS,
197 	MLME_AUTHTYPE_FILS_PK,
198 
199 	/* keep last */
200 	__MLME_AUTHTYPE_NUM,
201 	MLME_AUTHTYPE_MAX = __MLME_AUTHTYPE_NUM - 1,
202 	MLME_AUTHTYPE_AUTOMATIC
203 };
204 
205 
206 #define WIFI_FREQUENCY_BAND_AUTO 0
207 #define WIFI_FREQUENCY_BAND_5GHZ 1
208 #define WIFI_FREQUENCY_BAND_2GHZ 2
209 
210 #define rtw_band_valid(band) ((band) <= WIFI_FREQUENCY_BAND_2GHZ)
211 
212 enum SCAN_RESULT_TYPE {
213 	SCAN_RESULT_P2P_ONLY = 0,		/*	Will return all the P2P devices. */
214 	SCAN_RESULT_ALL = 1,			/*	Will return all the scanned device, include AP. */
215 	SCAN_RESULT_WFD_TYPE = 2		/*	Will just return the correct WFD device. */
216 									/*	If this device is Miracast sink device, it will just return all the Miracast source devices. */
217 };
218 
219 /*
220 
221 there are several "locks" in mlme_priv,
222 since mlme_priv is a shared resource between many threads,
223 like ISR/Call-Back functions, the OID handlers, and even timer functions.
224 
225 
226 Each _queue has its own locks, already.
227 Other items are protected by mlme_priv.lock.
228 
229 To avoid possible dead lock, any thread trying to modifiying mlme_priv
230 SHALL not lock up more than one locks at a time!
231 
232 */
233 
234 
235 #define traffic_threshold	10
236 #define	traffic_scan_period	500
237 
238 typedef struct _RT_LINK_DETECT_T {
239 	u32				NumTxOkInPeriod;
240 	u32				NumRxOkInPeriod;
241 	u32				NumRxUnicastOkInPeriod;
242 	BOOLEAN			bBusyTraffic;
243 	BOOLEAN			bTxBusyTraffic;
244 	BOOLEAN			bRxBusyTraffic;
245 	BOOLEAN			bHigherBusyTraffic; /* For interrupt migration purpose. */
246 	BOOLEAN			bHigherBusyRxTraffic; /* We may disable Tx interrupt according as Rx traffic. */
247 	BOOLEAN			bHigherBusyTxTraffic; /* We may disable Tx interrupt according as Tx traffic. */
248 	/* u8 TrafficBusyState; */
249 	u8 TrafficTransitionCount;
250 	u32 LowPowerTransitionCount;
251 } RT_LINK_DETECT_T, *PRT_LINK_DETECT_T;
252 
253 #ifdef CONFIG_WFD
254 
255 struct wifi_display_info {
256 	u16							wfd_enable;			/*	Eanble/Disable the WFD function. */
257 	u16							init_rtsp_ctrlport;	/* init value of rtsp_ctrlport when WFD enable */
258 	u16							rtsp_ctrlport;		/* TCP port number at which the this WFD device listens for RTSP messages, 0 when WFD disable */
259 	u16							tdls_rtsp_ctrlport;	/* rtsp_ctrlport used by tdls, will sync when rtsp_ctrlport is changed by user */
260 	u16							peer_rtsp_ctrlport;	/*	TCP port number at which the peer WFD device listens for RTSP messages */
261 													/*	This filed should be filled when receiving the gropu negotiation request */
262 
263 	u8							peer_session_avail;	/*	WFD session is available or not for the peer wfd device. */
264 													/*	This variable will be set when sending the provisioning discovery request to peer WFD device. */
265 													/*	And this variable will be reset when it is read by using the iwpriv p2p_get wfd_sa command. */
266 	u8							ip_address[4];
267 	u8							peer_ip_address[4];
268 	u8							wfd_pc;				/*	WFD preferred connection */
269 													/*	0 -> Prefer to use the P2P for WFD connection on peer side. */
270 													/*	1 -> Prefer to use the TDLS for WFD connection on peer side. */
271 
272 	u8							wfd_device_type;	/*	WFD Device Type */
273 													/*	0 -> WFD Source Device */
274 													/*	1 -> WFD Primary Sink Device */
275 	enum	SCAN_RESULT_TYPE	scan_result_type;	/*	Used when P2P is enable. This parameter will impact the scan result. */
276 	u8 op_wfd_mode;
277 	u8 stack_wfd_mode;
278 };
279 #endif /* CONFIG_WFD */
280 
281 #ifdef CONFIG_IOCTL_CFG80211
282 struct cfg80211_roch_info {
283 	u8						restore_channel;
284 	struct ieee80211_channel	remain_on_ch_channel;
285 	enum nl80211_channel_type	remain_on_ch_type;
286 	unsigned int duration;
287 	ATOMIC_T ro_ch_cookie_gen;
288 	u64 remain_on_ch_cookie;
289 	bool is_ro_ch;
290 	struct wireless_dev *ro_ch_wdev;
291 	systime last_ro_ch_time; /* this will be updated at the beginning and end of ro_ch */
292 };
293 #endif /* CONFIG_IOCTL_CFG80211 */
294 
295 #ifdef CONFIG_P2P_WOWLAN
296 
297 enum P2P_WOWLAN_RECV_FRAME_TYPE {
298 	P2P_WOWLAN_RECV_NEGO_REQ = 0,
299 	P2P_WOWLAN_RECV_INVITE_REQ = 1,
300 	P2P_WOWLAN_RECV_PROVISION_REQ = 2,
301 };
302 
303 struct p2p_wowlan_info {
304 
305 	u8						is_trigger;
306 	enum P2P_WOWLAN_RECV_FRAME_TYPE	wowlan_recv_frame_type;
307 	u8						wowlan_peer_addr[ETH_ALEN];
308 	u16						wowlan_peer_wpsconfig;
309 	u8						wowlan_peer_is_persistent;
310 	u8						wowlan_peer_invitation_type;
311 };
312 
313 #endif /* CONFIG_P2P_WOWLAN */
314 
315 struct wifidirect_info {
316 	_adapter				*padapter;
317 
318 #ifdef CONFIG_WFD
319 	struct wifi_display_info		*wfd_info;
320 #endif
321 
322 #ifdef CONFIG_P2P_WOWLAN
323 	struct p2p_wowlan_info		p2p_wow_info;
324 #endif /* CONFIG_P2P_WOWLAN */
325 
326 	enum P2P_ROLE			role;
327 	u8						listen_channel;
328 	u8						support_rate[8];
329 	u8						p2p_wildcard_ssid[P2P_WILDCARD_SSID_LEN];
330 	u8						wfd_tdls_enable;			/*	Flag to enable or disable the TDLS by WFD Sigma */
331 														/*	0: disable */
332 														/*	1: enable */
333 	u8						wfd_tdls_weaksec;			/*	Flag to enable or disable the weak security function for TDLS by WFD Sigma */
334 														/*	0: disable */
335 														/*	In this case, the driver can't issue the tdsl setup request frame. */
336 														/*	1: enable */
337 														/*	In this case, the driver can issue the tdls setup request frame */
338 														/*	even the current security is weak security. */
339 
340 #ifdef CONFIG_P2P_PS
341 	enum P2P_PS_MODE		p2p_ps_mode; /* indicate p2p ps mode */
342 	enum P2P_PS_STATE		p2p_ps_state; /* indicate p2p ps state */
343 	u8						noa_index; /* Identifies and instance of Notice of Absence timing. */
344 	u8						ctwindow; /* Client traffic window. A period of time in TU after TBTT. */
345 	u8						opp_ps; /* opportunistic power save. */
346 	u8						noa_num; /* number of NoA descriptor in P2P IE. */
347 	u8						noa_count[P2P_MAX_NOA_NUM]; /* Count for owner, Type of client. */
348 	u32						noa_duration[P2P_MAX_NOA_NUM]; /* Max duration for owner, preferred or min acceptable duration for client. */
349 	u32						noa_interval[P2P_MAX_NOA_NUM]; /* Length of interval for owner, preferred or max acceptable interval of client. */
350 	u32						noa_start_time[P2P_MAX_NOA_NUM]; /* schedule expressed in terms of the lower 4 bytes of the TSF timer. */
351 #endif /* CONFIG_P2P_PS */
352 #ifdef ROKU_PRIVATE
353 	u8						remote_mac_address[48]; /* For Roku find remote function */
354 	u32						num_of_remote;
355 #endif
356 };
357 
358 struct tdls_ss_record {	/* signal strength record */
359 	u8		macaddr[ETH_ALEN];
360 	u8		RxPWDBAll;
361 	u8		is_tdls_sta;	/* _TRUE: direct link sta, _FALSE: else */
362 };
363 
364 struct tdls_temp_mgmt {
365 	u8	initiator;	/* 0: None, 1: we initiate, 2: peer initiate */
366 	u8	peer_addr[ETH_ALEN];
367 };
368 
369 #ifdef CONFIG_TDLS_CH_SW
370 struct tdls_ch_switch {
371 	u32	ch_sw_state;
372 	ATOMIC_T	chsw_on;
373 	u8	addr[ETH_ALEN];
374 	u8	off_ch_num;
375 	u8	ch_offset;
376 	u32	cur_time;
377 	u8	delay_switch_back;
378 	u8	dump_stack;
379 	struct submit_ctx	chsw_sctx;
380 };
381 #endif
382 
383 struct tdls_info {
384 	u8					ap_prohibited;
385 	u8					ch_switch_prohibited;
386 	u8					link_established;
387 	u8					sta_cnt;
388 	u8					sta_maximum;	/* 1:tdls sta is equal (NUM_STA-1), reach max direct link number; 0: else; */
389 	struct tdls_ss_record	ss_record;
390 #ifdef CONFIG_TDLS_CH_SW
391 	struct tdls_ch_switch	chsw_info;
392 #endif
393 
394 	u8					ch_sensing;
395 	u8					cur_channel;
396 	u8					collect_pkt_num[MAX_CHANNEL_NUM];
397 	_lock				cmd_lock;
398 	_lock				hdl_lock;
399 	u8					watchdog_count;
400 	u8					dev_discovered;		/* WFD_TDLS: for sigma test */
401 
402 	/* Let wpa_supplicant to setup*/
403 	u8					driver_setup;
404 #ifdef CONFIG_WFD
405 	struct wifi_display_info		*wfd_info;
406 #endif
407 
408 	struct submit_ctx	*tdls_sctx;
409 };
410 
411 struct tdls_txmgmt {
412 	u8 peer[ETH_ALEN];
413 	u8 action_code;
414 	u8 dialog_token;
415 	u16 status_code;
416 	u8 *buf;
417 	size_t len;
418 };
419 
420 /* used for mlme_priv.roam_flags */
421 enum {
422 	RTW_ROAM_ON_EXPIRED = BIT0,
423 	RTW_ROAM_ON_RESUME = BIT1,
424 	RTW_ROAM_ACTIVE = BIT2,
425 };
426 
427 struct beacon_keys {
428 	u8 ssid[IW_ESSID_MAX_SIZE];
429 	u32 ssid_len;
430 	u8 ch;
431 	u8 bw;
432 	u8 offset;
433 	u8 proto_cap; /* PROTO_CAP_XXX */
434 	u8 rate_set[12];
435 	u8 rate_num;
436 	int encryp_protocol;
437 	int pairwise_cipher;
438 	int group_cipher;
439 	u32 akm;
440 };
441 
442 
443 #define UNASOC_STA_SRC_RX_BMC		0
444 #define UNASOC_STA_SRC_RX_NMY_UC	1
445 #define UNASOC_STA_SRC_NUM			2
446 
447 #define UNASOC_STA_MODE_DISABLED	0
448 #define UNASOC_STA_MODE_INTERESTED	1
449 #define UNASOC_STA_MODE_ALL			2
450 #define UNASOC_STA_MODE_NUM			3
451 
452 #define UNASOC_STA_DEL_CHK_SKIP		0
453 #define UNASOC_STA_DEL_CHK_ALIVE	1
454 #define UNASOC_STA_DEL_CHK_DELETED	2
455 
456 #ifdef CONFIG_RTW_MULTI_AP
457 struct unassoc_sta_info {
458 	_list list;
459 	u8 addr[ETH_ALEN];
460 	u8 interested;
461 	s8 recv_signal_power;
462 	systime time;
463 };
464 #endif
465 
466 #ifdef ROKU_PRIVATE
467 #define MAX_VENDOR_IE_NUM 10
468 #define MAX_VENDOR_IE_LEN 255
469 #define MAX_VENDOR_IE_PARAM_LEN MAX_VENDOR_IE_LEN + 2	/* vendor ie filter index + content maximum length */
470 #endif
471 struct mlme_priv {
472 
473 	_lock	lock;
474 	sint	fw_state;	/* shall we protect this variable? maybe not necessarily... */
475 	u8	to_join; /* flag */
476 	u16 join_status;
477 #ifdef CONFIG_LAYER2_ROAMING
478 	u8 to_roam; /* roaming trying times */
479 	struct wlan_network *roam_network; /* the target of active roam */
480 	u8 roam_flags;
481 	u8 roam_rssi_diff_th; /* rssi difference threshold for active scan candidate selection */
482 	u32 roam_scan_int; 		/* scan interval for active roam (Unit:2 second)*/
483 	u32 roam_scanr_exp_ms; /* scan result expire time in ms  for roam */
484 	u8 roam_tgt_addr[ETH_ALEN]; /* request to roam to speicific target without other consideration */
485 	u8 roam_rssi_threshold;
486 	systime last_roaming;
487 	bool need_to_roam;
488 #endif
489 
490 	u32 defs_lmt_sta;
491 	u32 defs_lmt_time;
492 
493 	u8	*nic_hdl;
494 	u32	max_bss_cnt;		/*	The size of scan queue	*/
495 	_list		*pscanned;
496 	_queue	free_bss_pool;
497 	_queue	scanned_queue;
498 	u8		*free_bss_buf;
499 	u32	num_of_scanned;
500 
501 	NDIS_802_11_SSID	assoc_ssid;
502 	u8	assoc_bssid[6];
503 	u16	assoc_ch;		/* 0 reserved for no specific channel */
504 
505 	struct wlan_network	cur_network;
506 	struct wlan_network *cur_network_scanned;
507 
508 	/* bcn check info */
509 	struct beacon_keys cur_beacon_keys; /* save current beacon keys */
510 #if CONFIG_DFS
511 	u8 bcn_cnts_after_csa;
512 #endif
513 
514 #ifdef CONFIG_ARP_KEEP_ALIVE
515 	/* for arp offload keep alive */
516 	u8 bGetGateway;
517 	u8	GetGatewayTryCnt;
518 	u8	gw_mac_addr[ETH_ALEN];
519 	u8	gw_ip[4];
520 #endif
521 
522 	/* uint wireless_mode; no used, remove it */
523 
524 	u32	auto_scan_int_ms;
525 
526 	_timer assoc_timer;
527 
528 	uint assoc_by_bssid;
529 	uint assoc_by_rssi;
530 
531 	_timer scan_to_timer; /* driver itself handles scan_timeout status. */
532 	systime scan_start_time; /* used to evaluate the time spent in scanning */
533 
534 #ifdef CONFIG_SET_SCAN_DENY_TIMER
535 	_timer set_scan_deny_timer;
536 	ATOMIC_T set_scan_deny; /* 0: allowed, 1: deny */
537 #endif
538 	u8 wpa_phase;/*wpa_phase after wps finished*/
539 
540 	struct qos_priv qospriv;
541 
542 #ifdef CONFIG_80211D
543 	u8 *recv_country_ie;
544 	u32 recv_country_ie_len;
545 #endif
546 
547 #ifdef CONFIG_80211N_HT
548 
549 	/* Number of non-HT AP/stations */
550 	int num_sta_no_ht;
551 
552 	/* Number of HT AP/stations 20 MHz */
553 	/* int num_sta_ht_20mhz; */
554 
555 
556 	int num_FortyMHzIntolerant;
557 
558 	struct ht_priv	htpriv;
559 
560 #endif
561 
562 #ifdef CONFIG_80211AC_VHT
563 	struct vht_priv	vhtpriv;
564 #ifdef ROKU_PRIVATE
565 	/*infra mode, used to store AP's info*/
566 	struct vht_priv_infra_ap vhtpriv_infra_ap;
567 #endif /* ROKU_PRIVATE */
568 #endif
569 
570 #ifdef CONFIG_80211AX_HE
571 	struct he_priv hepriv;
572 #endif
573 
574 #ifdef CONFIG_RTW_MBO
575 	struct mbo_priv mbopriv;
576 #endif
577 
578 #ifdef ROKU_PRIVATE
579 	struct ht_priv_infra_ap htpriv_infra_ap;
580 #endif /* ROKU_PRIVATE */
581 
582 #ifdef CONFIG_RTW_80211R
583 	struct ft_roam_info ft_roam;
584 #endif
585 #if defined(CONFIG_RTW_WNM) || defined(CONFIG_RTW_80211K)
586 	struct roam_nb_info nb_info;
587 	u8 ch_cnt;
588 #endif
589 
590 	RT_LINK_DETECT_T	LinkDetectInfo;
591 
592 	u8	acm_mask; /* for wmm acm mask */
593 	enum rtw_phl_scan_type scan_mode; /* active: 1, passive: 0 */
594 
595 	u8 *wps_probe_req_ie;
596 	u32 wps_probe_req_ie_len;
597 
598 	u8 ext_capab_ie_data[WLAN_EID_EXT_CAP_MAX_LEN];/*currently for ap mode only*/
599 	u8 ext_capab_ie_len;
600 
601 #if defined(CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME)
602 	/* Number of associated Non-ERP stations (i.e., stations using 802.11b
603 	 * in 802.11g BSS) */
604 	int num_sta_non_erp;
605 
606 	/* Number of associated stations that do not support Short Slot Time */
607 	int num_sta_no_short_slot_time;
608 
609 	/* Number of associated stations that do not support Short Preamble */
610 	int num_sta_no_short_preamble;
611 
612 	ATOMIC_T olbc; /* Overlapping Legacy BSS Condition (Legacy b/g)*/
613 
614 	/* Number of HT associated stations that do not support greenfield */
615 	int num_sta_ht_no_gf;
616 
617 	/* Number of associated non-HT stations */
618 	/* int num_sta_no_ht; */
619 
620 	/* Number of HT associated stations 20 MHz */
621 	int num_sta_ht_20mhz;
622 
623 	/* number of associated stations 40MHz intolerant */
624 	int num_sta_40mhz_intolerant;
625 
626 	/* Overlapping BSS information */
627 	ATOMIC_T olbc_ht;
628 
629 #ifdef CONFIG_80211N_HT
630 	int ht_20mhz_width_req;
631 	int ht_intolerant_ch_reported;
632 	u16 ht_op_mode;
633 	u8 sw_to_20mhz; /*switch to 20Mhz BW*/
634 #endif /* CONFIG_80211N_HT */
635 
636 #ifdef CONFIG_RTW_80211R
637 	u8 *auth_rsp;
638 	u32 auth_rsp_len;
639 #endif
640 	u8 *assoc_req;
641 	u32 assoc_req_len;
642 
643 	u8 *assoc_rsp;
644 	u32 assoc_rsp_len;
645 
646 	/* u8 *wps_probe_req_ie; */
647 	/* u32 wps_probe_req_ie_len; */
648 
649 	u8 *wps_beacon_ie;
650 	u32 wps_beacon_ie_len;
651 
652 	u8 *wps_probe_resp_ie;
653 	u32 wps_probe_resp_ie_len;
654 
655 	u8 *wps_assoc_resp_ie;
656 	u32 wps_assoc_resp_ie_len;
657 
658 	u8 *p2p_beacon_ie;
659 	u32 p2p_beacon_ie_len;
660 
661 	u8 *p2p_probe_req_ie;
662 	u32 p2p_probe_req_ie_len;
663 
664 	u8 *p2p_probe_resp_ie;
665 	u32 p2p_probe_resp_ie_len;
666 
667 	u8 *p2p_go_probe_resp_ie;		/* for GO */
668 	u32 p2p_go_probe_resp_ie_len;	/* for GO */
669 
670 	u8 *p2p_assoc_req_ie;
671 	u32 p2p_assoc_req_ie_len;
672 
673 	u8 *p2p_assoc_resp_ie;
674 	u32 p2p_assoc_resp_ie_len;
675 
676 	_lock	bcn_update_lock;
677 	u8 update_bcn;
678 
679 	struct rtw_chan_def ori_chandef;
680 	#ifdef CONFIG_80211AC_VHT
681 	u8 ori_vht_en;
682 	#endif
683 #endif /* #if defined (CONFIG_AP_MODE) && defined (CONFIG_NATIVEAP_MLME) */
684 
685 #if defined(CONFIG_WFD) && defined(CONFIG_IOCTL_CFG80211)
686 	u8 *wfd_beacon_ie;
687 	u32 wfd_beacon_ie_len;
688 
689 	u8 *wfd_probe_req_ie;
690 	u32 wfd_probe_req_ie_len;
691 
692 	u8 *wfd_probe_resp_ie;
693 	u32 wfd_probe_resp_ie_len;
694 
695 	u8 *wfd_go_probe_resp_ie;		/* for GO */
696 	u32 wfd_go_probe_resp_ie_len;	/* for GO */
697 
698 	u8 *wfd_assoc_req_ie;
699 	u32 wfd_assoc_req_ie_len;
700 
701 	u8 *wfd_assoc_resp_ie;
702 	u32 wfd_assoc_resp_ie_len;
703 #endif
704 
705 #ifdef CONFIG_RTW_MBO
706 	u8 *pcell_data_cap_ie;
707 	u32 cell_data_cap_len;
708 	struct mbo_attr_info mbo_attr;
709 #endif
710 
711 #ifdef RTK_DMP_PLATFORM
712 	/* DMP kobject_hotplug function  signal need in passive level */
713 	_workitem	Linkup_workitem;
714 	_workitem	Linkdown_workitem;
715 #endif
716 
717 #ifdef RTW_BUSY_DENY_SCAN
718 	systime lastscantime;
719 #endif
720 
721 #ifdef CONFIG_CONCURRENT_MODE
722 	u8	scanning_via_buddy_intf;
723 #endif
724 
725 #ifdef CONFIG_APPEND_VENDOR_IE_ENABLE
726 	u32 vendor_ie_mask[WLAN_MAX_VENDOR_IE_NUM];
727 	u8 vendor_ie[WLAN_MAX_VENDOR_IE_NUM][WLAN_MAX_VENDOR_IE_LEN];
728 	u32 vendor_ielen[WLAN_MAX_VENDOR_IE_NUM];
729 #endif
730 #ifdef CONFIG_RTW_MULTI_AP
731 	u8 unassoc_sta_mode_of_stype[UNASOC_STA_SRC_NUM];
732 	_queue unassoc_sta_queue;
733 	_queue free_unassoc_sta_queue;
734 	u8 *free_unassoc_sta_buf;
735 	u32 interested_unassoc_sta_cnt;
736 	u32 max_unassoc_sta_cnt;
737 #endif
738 #ifdef ROKU_PRIVATE
739 	u8 vendor_ie_filter[MAX_VENDOR_IE_NUM][MAX_VENDOR_IE_LEN];
740 	u8 vendor_ie_len[MAX_VENDOR_IE_NUM];
741 	u8 vendor_ie_filter_enable;
742 #endif
743 };
744 
745 #define mlme_set_scan_to_timer(mlme, ms) \
746 	do { \
747 		/* RTW_INFO("%s set_scan_to_timer(%p, %d)\n", __FUNCTION__, (mlme), (ms)); */ \
748 		_set_timer(&(mlme)->scan_to_timer, (ms)); \
749 	} while (0)
750 
751 #define rtw_mlme_set_auto_scan_int(adapter, ms) \
752 	do { \
753 		adapter->mlmepriv.auto_scan_int_ms = ms; \
754 	} while (0)
755 
756 #define set_assoc_timer(mlme, ms) \
757 	do { \
758 		/*RTW_INFO("%s set_assoc_timer(%p, %d)\n", __FUNCTION__, (mlme), (ms));*/ \
759 		_set_timer(&(mlme)->assoc_timer, (ms)); \
760 	} while (0)
761 #define cancel_assoc_timer(mlme) \
762 	do { \
763 		/*RTW_INFO("%s cancel_assoc_timer(%p)\n", __FUNCTION__, (mlme));*/ \
764 		_cancel_timer_ex(&(mlme)->assoc_timer); \
765 	} while (0)
766 
767 #define RTW_AUTO_SCAN_REASON_UNSPECIFIED		0
768 #define RTW_AUTO_SCAN_REASON_2040_BSS			BIT0
769 #define RTW_AUTO_SCAN_REASON_ACS				BIT1
770 #define RTW_AUTO_SCAN_REASON_ROAM				BIT2
771 #define RTW_AUTO_SCAN_REASON_ROAM_ACTIVE			BIT3
772 #define RTW_AUTO_SCAN_REASON_MESH_OFFCH_CAND		BIT4
773 
774 void rtw_mlme_reset_auto_scan_int(_adapter *adapter, u8 *reason);
775 
776 #ifdef CONFIG_AP_MODE
777 
778 struct hostapd_priv {
779 	_adapter *padapter;
780 
781 #ifdef CONFIG_HOSTAPD_MLME
782 	struct net_device *pmgnt_netdev;
783 	struct usb_anchor anchored;
784 #endif
785 
786 };
787 
788 extern int hostapd_mode_init(_adapter *padapter);
789 extern void hostapd_mode_unload(_adapter *padapter);
790 #endif
791 
792 
793 extern void rtw_joinbss_event_prehandle(_adapter *adapter, u8 *pbuf, u16 status);
794 extern void rtw_joinbss_event_callback(_adapter *adapter, u8 *pbuf);
795 extern void rtw_stassoc_event_callback(_adapter *adapter, u8 *pbuf);
796 extern void rtw_stadel_event_callback(_adapter *adapter, u8 *pbuf);
797 extern void rtw_wmm_event_callback(_adapter *padapter, u8 *pbuf);
798 #ifdef CONFIG_IEEE80211W
799 void rtw_sta_timeout_event_callback(_adapter *adapter, u8 *pbuf);
800 #endif /* CONFIG_IEEE80211W */
801 
802 extern void rtw_free_network_queue(_adapter *adapter, u8 isfreeall);
803 extern int rtw_init_mlme_priv(_adapter *adapter);/* (struct mlme_priv *pmlmepriv); */
804 
805 extern void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv);
806 
807 
808 extern sint rtw_select_and_join_from_scanned_queue(struct mlme_priv *pmlmepriv);
809 extern sint rtw_set_key(_adapter *adapter, struct security_priv *psecuritypriv, sint keyid, u8 set_tx, bool enqueue);
810 extern sint rtw_set_auth(_adapter *adapter, struct security_priv *psecuritypriv);
811 
get_bssid(struct mlme_priv * pmlmepriv)812 __inline static u8 *get_bssid(struct mlme_priv *pmlmepriv)
813 {
814 	/* if sta_mode:pmlmepriv->cur_network.network.MacAddress=> bssid */
815 	/* if adhoc_mode:pmlmepriv->cur_network.network.MacAddress=> ibss mac address */
816 	return pmlmepriv->cur_network.network.MacAddress;
817 }
818 
check_fwstate(struct mlme_priv * pmlmepriv,sint state)819 __inline static sint check_fwstate(struct mlme_priv *pmlmepriv, sint state)
820 {
821 	if ((state == WIFI_NULL_STATE) &&
822 		(pmlmepriv->fw_state == WIFI_NULL_STATE))
823 		return _TRUE;
824 
825 	if (pmlmepriv->fw_state & state)
826 		return _TRUE;
827 
828 	return _FALSE;
829 }
830 
get_fwstate(struct mlme_priv * pmlmepriv)831 __inline static sint get_fwstate(struct mlme_priv *pmlmepriv)
832 {
833 	return pmlmepriv->fw_state;
834 }
835 
836 /*
837  * No Limit on the calling context,
838  * therefore set it to be the critical section...
839  *
840  * ### NOTE:#### (!!!!)
841  * MUST TAKE CARE THAT BEFORE CALLING THIS FUNC, YOU SHOULD HAVE LOCKED pmlmepriv->lock
842  */
843 extern void rtw_mi_update_iface_status(struct mlme_priv *pmlmepriv, sint state);
844 
set_fwstate(struct mlme_priv * pmlmepriv,sint state)845 static inline void set_fwstate(struct mlme_priv *pmlmepriv, sint state)
846 {
847 	pmlmepriv->fw_state |= state;
848 	rtw_mi_update_iface_status(pmlmepriv, state);
849 }
init_fwstate(struct mlme_priv * pmlmepriv,sint state)850 static inline void init_fwstate(struct mlme_priv *pmlmepriv, sint state)
851 {
852 	pmlmepriv->fw_state = state;
853 	rtw_mi_update_iface_status(pmlmepriv, state);
854 }
855 
_clr_fwstate_(struct mlme_priv * pmlmepriv,sint state)856 static inline void _clr_fwstate_(struct mlme_priv *pmlmepriv, sint state)
857 {
858 	pmlmepriv->fw_state &= ~state;
859 	rtw_mi_update_iface_status(pmlmepriv, state);
860 }
861 
862 /*
863  * No Limit on the calling context,
864  * therefore set it to be the critical section...
865  */
clr_fwstate(struct mlme_priv * pmlmepriv,sint state)866 static inline void clr_fwstate(struct mlme_priv *pmlmepriv, sint state)
867 {
868 	_rtw_spinlock_bh(&pmlmepriv->lock);
869 	_clr_fwstate_(pmlmepriv, state);
870 	_rtw_spinunlock_bh(&pmlmepriv->lock);
871 }
872 
up_scanned_network(struct mlme_priv * pmlmepriv)873 static inline void up_scanned_network(struct mlme_priv *pmlmepriv)
874 {
875 	_rtw_spinlock_bh(&pmlmepriv->lock);
876 	pmlmepriv->num_of_scanned++;
877 	_rtw_spinunlock_bh(&pmlmepriv->lock);
878 }
879 u8 rtw_is_adapter_up(_adapter *padapter);
880 
down_scanned_network(struct mlme_priv * pmlmepriv)881 __inline static void down_scanned_network(struct mlme_priv *pmlmepriv)
882 {
883 	_rtw_spinlock_bh(&pmlmepriv->lock);
884 	pmlmepriv->num_of_scanned--;
885 	_rtw_spinunlock_bh(&pmlmepriv->lock);
886 }
887 
set_scanned_network_val(struct mlme_priv * pmlmepriv,sint val)888 __inline static void set_scanned_network_val(struct mlme_priv *pmlmepriv, sint val)
889 {
890 	_rtw_spinlock_bh(&pmlmepriv->lock);
891 	pmlmepriv->num_of_scanned = val;
892 	_rtw_spinunlock_bh(&pmlmepriv->lock);
893 }
894 
895 extern u16 rtw_get_capability(WLAN_BSSID_EX *bss);
896 extern void rtw_disconnect_hdl_under_linked(_adapter *adapter, struct sta_info *psta, u8 free_assoc);
897 extern void rtw_generate_random_ibss(u8 *pibss);
898 struct wlan_network *_rtw_find_network(_queue *scanned_queue, const u8 *addr);
899 struct wlan_network *rtw_find_network(_queue *scanned_queue, const u8 *addr);
900 extern struct wlan_network *rtw_get_oldest_wlan_network(_queue *scanned_queue);
901 struct wlan_network *_rtw_find_same_network(_queue *scanned_queue, struct wlan_network *network);
902 struct wlan_network *rtw_find_same_network(_queue *scanned_queue, struct wlan_network *network);
903 
904 extern void rtw_free_assoc_resources(_adapter *adapter, u8 lock_scanned_queue);
905 extern void rtw_indicate_disconnect(_adapter *adapter, u16 reason, u8 locally_generated);
906 extern void rtw_indicate_connect(_adapter *adapter);
907 void rtw_indicate_scan_done(_adapter *padapter, bool aborted);
908 
909 u32 rtw_join_abort_timeout(_adapter *adapter, u32 timeout_ms);
910 
911 int rtw_cached_pmkid(_adapter *adapter, u8 *bssid);
912 int rtw_rsn_sync_pmkid(_adapter *adapter, u8 *ie, uint ie_len, int i_ent);
913 
914 extern int rtw_restruct_sec_ie(_adapter *adapter, u8 *out_ie);
915 #ifdef CONFIG_WMMPS_STA
916 void rtw_uapsd_use_default_setting(_adapter *padapter);
917 bool rtw_is_wmmps_mode(_adapter *padapter);
918 #endif /* CONFIG_WMMPS_STA */
919 extern int rtw_restruct_wmm_ie(_adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_len, uint initial_out_len);
920 extern void rtw_init_registrypriv_dev_network(_adapter *adapter);
921 
922 extern void rtw_update_registrypriv_dev_network(_adapter *adapter);
923 
924 extern void rtw_get_encrypt_decrypt_from_registrypriv(_adapter *adapter);
925 
926 extern void rtw_join_timeout_handler(void *ctx);
927 
928 extern void rtw_iface_dynamic_check_handlder(struct _ADAPTER *a);
929 #ifdef CONFIG_CMD_GENERAL
930 void rtw_core_watchdog_sw_hdlr(void *drv_priv);
931 void rtw_core_watchdog_hw_hdlr(void *drv_priv);
932 #else
933 extern int rtw_dynamic_check_handlder(void *ctx, void* param, bool discard);
934 #endif
935 #if 0 /*#ifdef CONFIG_CORE_DM_CHK_TIMER*/
936 extern void rtw_dynamic_check_timer_handlder(void *ctx);
937 extern void rtw_iface_dynamic_check_timer_handlder(_adapter *adapter);
938 #endif
939 
940 
941 void rtw_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv);
942 
943 #define MLME_BEACON_IE			0
944 #define MLME_PROBE_REQ_IE		1
945 #define MLME_PROBE_RESP_IE		2
946 #define MLME_GO_PROBE_RESP_IE	3
947 #define MLME_ASSOC_REQ_IE		4
948 #define MLME_ASSOC_RESP_IE		5
949 
950 #if defined(CONFIG_WFD) && defined(CONFIG_IOCTL_CFG80211)
951 int rtw_mlme_update_wfd_ie_data(struct mlme_priv *mlme, u8 type, u8 *ie, u32 ie_len);
952 #endif
953 
954 
955 /* extern struct wlan_network* _rtw_dequeue_network(_queue *queue); */
956 
957 extern struct wlan_network *_rtw_alloc_network(struct mlme_priv *pmlmepriv);
958 
959 
960 extern void _rtw_free_network(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork, u8 isfreeall);
961 extern void _rtw_free_network_nolock(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork);
962 
963 extern void _rtw_free_network_queue(_adapter *padapter, u8 isfreeall);
964 
965 extern sint rtw_if_up(_adapter *padapter);
966 
967 sint rtw_linked_check(_adapter *padapter);
968 
969 u8 *rtw_get_capability_from_ie(u8 *ie);
970 u8 *rtw_get_timestampe_from_ie(u8 *ie);
971 u8 *rtw_get_beacon_interval_from_ie(u8 *ie);
972 
973 
974 void rtw_joinbss_reset(_adapter *padapter);
975 
976 #ifdef CONFIG_80211N_HT
977 void rtw_ht_get_dft_setting(_adapter *padapter,
978 				struct protocol_cap_t *dft_proto_cap, struct role_cap_t *dft_cap);
979 void	rtw_ht_use_default_setting(_adapter *padapter);
980 void rtw_build_wmm_ie_ht(_adapter *padapter, u8 *out_ie, uint *pout_len);
981 unsigned int rtw_restructure_ht_ie(_adapter *padapter, u8 *in_ie, u8 *out_ie, uint in_len, uint *pout_len, u8 channel, struct country_chplan *req_chplan);
982 void rtw_update_ht_cap(_adapter *padapter, u8 *pie, uint ie_len, u8 channel);
983 void rtw_issue_addbareq_cmd(_adapter *padapter, struct xmit_frame *pxmitframe, u8 issue_when_busy);
984 #endif
985 
986 void rtw_append_extended_cap(_adapter *padapter, u8 *out_ie, uint *pout_len);
987 
988 int rtw_is_same_ibss(_adapter *adapter, struct wlan_network *pnetwork);
989 int is_same_network(WLAN_BSSID_EX *src, WLAN_BSSID_EX *dst);
990 
991 #ifdef CONFIG_LAYER2_ROAMING
992 #define rtw_roam_flags(adapter) ((adapter)->mlmepriv.roam_flags)
993 #define rtw_chk_roam_flags(adapter, flags) ((adapter)->mlmepriv.roam_flags & flags)
994 #define rtw_clr_roam_flags(adapter, flags) \
995 	do { \
996 		((adapter)->mlmepriv.roam_flags &= ~flags); \
997 	} while (0)
998 
999 #define rtw_set_roam_flags(adapter, flags) \
1000 	do { \
1001 		((adapter)->mlmepriv.roam_flags |= flags); \
1002 	} while (0)
1003 
1004 #define rtw_assign_roam_flags(adapter, flags) \
1005 	do { \
1006 		((adapter)->mlmepriv.roam_flags = flags); \
1007 	} while (0)
1008 
1009 void _rtw_roaming(_adapter *adapter, struct wlan_network *tgt_network);
1010 void rtw_roaming(_adapter *adapter, struct wlan_network *tgt_network);
1011 void rtw_set_to_roam(_adapter *adapter, u8 to_roam);
1012 u8 rtw_dec_to_roam(_adapter *adapter);
1013 u8 rtw_to_roam(_adapter *adapter);
1014 int rtw_select_roaming_candidate(struct mlme_priv *pmlmepriv);
1015 #else
1016 #define rtw_roam_flags(adapter) 0
1017 #define rtw_chk_roam_flags(adapter, flags) 0
1018 #define rtw_clr_roam_flags(adapter, flags) do {} while (0)
1019 #define rtw_set_roam_flags(adapter, flags) do {} while (0)
1020 #define rtw_assign_roam_flags(adapter, flags) do {} while (0)
1021 #define _rtw_roaming(adapter, tgt_network) do {} while (0)
1022 #define rtw_roaming(adapter, tgt_network) do {} while (0)
1023 #define rtw_set_to_roam(adapter, to_roam) do {} while (0)
1024 #define rtw_dec_to_roam(adapter) 0
1025 #define rtw_to_roam(adapter) 0
1026 #define rtw_select_roaming_candidate(mlme) _FAIL
1027 #endif /* CONFIG_LAYER2_ROAMING */
1028 
1029 bool rtw_adjust_chbw(_adapter *adapter, u8 req_ch, u8 *req_bw, u8 *req_offset);
1030 
1031 struct sta_media_status_rpt_cmd_parm {
1032 	struct sta_info *sta;
1033 	bool connected;
1034 };
1035 
1036 #ifdef CONFIG_RTW_MULTI_AP
1037 void rtw_map_config_monitor_act_non(_adapter *adapter);
1038 void rtw_map_config_monitor(_adapter *adapter, u8 self_act);
1039 void rtw_unassoc_sta_set_mode(_adapter *adapter, u8 stype, u8 mode);
1040 bool rtw_unassoc_sta_src_chk(_adapter *adapter, u8 stype);
1041 void dump_unassoc_sta(void *sel, _adapter *adapter);
1042 void rtw_del_unassoc_sta_queue(_adapter *adapter);
1043 void rtw_del_unassoc_sta(_adapter *adapter, u8 *addr);
1044 void rtw_rx_add_unassoc_sta(_adapter *adapter, u8 stype, u8 *addr, s8 recv_signal_power);
1045 void rtw_add_interested_unassoc_sta(_adapter *adapter, u8 *addr);
1046 void rtw_undo_interested_unassoc_sta(_adapter *adapter, u8 *addr);
1047 void rtw_undo_all_interested_unassoc_sta(_adapter *adapter);
1048 u8 rtw_search_unassoc_sta(_adapter *adapter, u8 *addr, struct unassoc_sta_info *ret_sta);
1049 #endif
1050 
1051 void rtw_sta_media_status_rpt(_adapter *adapter, struct sta_info *sta, bool connected);
1052 u8 rtw_sta_media_status_rpt_cmd(_adapter *adapter, struct sta_info *sta, bool connected);
1053 void rtw_sta_media_status_rpt_cmd_hdl(_adapter *adapter, struct sta_media_status_rpt_cmd_parm *parm);
1054 void rtw_sta_traffic_info(void *sel, _adapter *adapter);
1055 
1056 #define GET_ARP_HTYPE(_arp)	BE_BITS_TO_2BYTE(((u8 *)(_arp)) + 0, 0, 16)
1057 #define GET_ARP_PTYPE(_arp)	BE_BITS_TO_2BYTE(((u8 *)(_arp)) + 2, 0, 16)
1058 #define GET_ARP_HLEN(_arp)	BE_BITS_TO_1BYTE(((u8 *)(_arp)) + 4, 0, 8)
1059 #define GET_ARP_PLEN(_arp)	BE_BITS_TO_1BYTE(((u8 *)(_arp)) + 5, 0, 8)
1060 #define GET_ARP_OPER(_arp)	BE_BITS_TO_2BYTE(((u8 *)(_arp)) + 6, 0, 16)
1061 
1062 #define SET_ARP_HTYPE(_arp, _val)	SET_BITS_TO_BE_2BYTE(((u8 *)(_arp)) + 0, 0, 16, _val)
1063 #define SET_ARP_PTYPE(_arp, _val)	SET_BITS_TO_BE_2BYTE(((u8 *)(_arp)) + 2, 0, 16, _val)
1064 #define SET_ARP_HLEN(_arp, _val)	SET_BITS_TO_BE_1BYTE(((u8 *)(_arp)) + 4, 0, 8, _val)
1065 #define SET_ARP_PLEN(_arp, _val)	SET_BITS_TO_BE_1BYTE(((u8 *)(_arp)) + 5, 0, 8, _val)
1066 #define SET_ARP_OPER(_arp, _val)	SET_BITS_TO_BE_2BYTE(((u8 *)(_arp)) + 6, 0, 16, _val)
1067 
1068 #define ARP_SHA(_arp, _hlen, _plen)	(((u8 *)(_arp)) + 8)
1069 #define ARP_SPA(_arp, _hlen, _plen)	(((u8 *)(_arp)) + 8 + (_hlen))
1070 #define ARP_THA(_arp, _hlen, _plen)	(((u8 *)(_arp)) + 8 + (_hlen) + (_plen))
1071 #define ARP_TPA(_arp, _hlen, _plen)	(((u8 *)(_arp)) + 8 + 2 * (_hlen) + (_plen))
1072 
1073 #define ARP_SENDER_MAC_ADDR(_arp)	ARP_SHA(_arp, ETH_ALEN, RTW_IP_ADDR_LEN)
1074 #define ARP_SENDER_IP_ADDR(_arp)	ARP_SPA(_arp, ETH_ALEN, RTW_IP_ADDR_LEN)
1075 #define ARP_TARGET_MAC_ADDR(_arp)	ARP_THA(_arp, ETH_ALEN, RTW_IP_ADDR_LEN)
1076 #define ARP_TARGET_IP_ADDR(_arp)	ARP_TPA(_arp, ETH_ALEN, RTW_IP_ADDR_LEN)
1077 
1078 #define GET_ARP_SENDER_MAC_ADDR(_arp, _val)	_rtw_memcpy(_val, ARP_SENDER_MAC_ADDR(_arp), ETH_ALEN)
1079 #define GET_ARP_SENDER_IP_ADDR(_arp, _val)	_rtw_memcpy(_val, ARP_SENDER_IP_ADDR(_arp), RTW_IP_ADDR_LEN)
1080 #define GET_ARP_TARGET_MAC_ADDR(_arp, _val)	_rtw_memcpy(_val, ARP_TARGET_MAC_ADDR(_arp), ETH_ALEN)
1081 #define GET_ARP_TARGET_IP_ADDR(_arp, _val)	_rtw_memcpy(_val, ARP_TARGET_IP_ADDR(_arp), RTW_IP_ADDR_LEN)
1082 
1083 #define SET_ARP_SENDER_MAC_ADDR(_arp, _val)	_rtw_memcpy(ARP_SENDER_MAC_ADDR(_arp), _val, ETH_ALEN)
1084 #define SET_ARP_SENDER_IP_ADDR(_arp, _val)	_rtw_memcpy(ARP_SENDER_IP_ADDR(_arp), _val, RTW_IP_ADDR_LEN)
1085 #define SET_ARP_TARGET_MAC_ADDR(_arp, _val)	_rtw_memcpy(ARP_TARGET_MAC_ADDR(_arp), _val, ETH_ALEN)
1086 #define SET_ARP_TARGET_IP_ADDR(_arp, _val)	_rtw_memcpy(ARP_TARGET_IP_ADDR(_arp), _val, RTW_IP_ADDR_LEN)
1087 
1088 void dump_arp_pkt(void *sel, u8 *da, u8 *sa, u8 *arp, bool tx);
1089 
1090 #define IPV4_SRC(_iphdr)			(((u8 *)(_iphdr)) + 12)
1091 #define IPV4_DST(_iphdr)			(((u8 *)(_iphdr)) + 16)
1092 #define GET_IPV4_IHL(_iphdr)		BE_BITS_TO_1BYTE(((u8 *)(_iphdr)) + 0, 0, 4)
1093 #define GET_IPV4_PROTOCOL(_iphdr)	BE_BITS_TO_1BYTE(((u8 *)(_iphdr)) + 9, 0, 8)
1094 #define GET_IPV4_SRC(_iphdr)		BE_BITS_TO_4BYTE(((u8 *)(_iphdr)) + 12, 0, 32)
1095 #define GET_IPV4_DST(_iphdr)		BE_BITS_TO_4BYTE(((u8 *)(_iphdr)) + 16, 0, 32)
1096 
1097 #define GET_UDP_SRC(_udphdr)			BE_BITS_TO_2BYTE(((u8 *)(_udphdr)) + 0, 0, 16)
1098 #define GET_UDP_DST(_udphdr)			BE_BITS_TO_2BYTE(((u8 *)(_udphdr)) + 2, 0, 16)
1099 #define GET_UDP_SIG1(_udphdr)			BE_BITS_TO_1BYTE(((u8 *)(_udphdr)) + 8, 0, 8)
1100 #define GET_UDP_SIG2(_udphdr)			BE_BITS_TO_1BYTE(((u8 *)(_udphdr)) + 23, 0, 8)
1101 
1102 #define TCP_SRC(_tcphdr)				(((u8 *)(_tcphdr)) + 0)
1103 #define TCP_DST(_tcphdr)				(((u8 *)(_tcphdr)) + 2)
1104 #define GET_TCP_SRC(_tcphdr)			BE_BITS_TO_2BYTE(((u8 *)(_tcphdr)) + 0, 0, 16)
1105 #define GET_TCP_DST(_tcphdr)			BE_BITS_TO_2BYTE(((u8 *)(_tcphdr)) + 2, 0, 16)
1106 #define GET_TCP_SEQ(_tcphdr)			BE_BITS_TO_4BYTE(((u8 *)(_tcphdr)) + 4, 0, 32)
1107 #define GET_TCP_ACK_SEQ(_tcphdr)		BE_BITS_TO_4BYTE(((u8 *)(_tcphdr)) + 8, 0, 32)
1108 #define GET_TCP_DOFF(_tcphdr)			BE_BITS_TO_1BYTE(((u8 *)(_tcphdr)) + 12, 4, 4)
1109 #define GET_TCP_FIN(_tcphdr)			BE_BITS_TO_1BYTE(((u8 *)(_tcphdr)) + 13, 0, 1)
1110 #define GET_TCP_SYN(_tcphdr)			BE_BITS_TO_1BYTE(((u8 *)(_tcphdr)) + 13, 1, 1)
1111 #define GET_TCP_RST(_tcphdr)			BE_BITS_TO_1BYTE(((u8 *)(_tcphdr)) + 13, 2, 1)
1112 #define GET_TCP_PSH(_tcphdr)			BE_BITS_TO_1BYTE(((u8 *)(_tcphdr)) + 13, 3, 1)
1113 #define GET_TCP_ACK(_tcphdr)			BE_BITS_TO_1BYTE(((u8 *)(_tcphdr)) + 13, 4, 1)
1114 #define GET_TCP_URG(_tcphdr)			BE_BITS_TO_1BYTE(((u8 *)(_tcphdr)) + 13, 5, 1)
1115 #define GET_TCP_ECE(_tcphdr)			BE_BITS_TO_1BYTE(((u8 *)(_tcphdr)) + 13, 6, 1)
1116 #define GET_TCP_CWR(_tcphdr)			BE_BITS_TO_1BYTE(((u8 *)(_tcphdr)) + 13, 7, 1)
1117 
1118 #ifdef CONFIG_STA_CMD_DISPR
1119 enum rtw_phl_status rtw_connect_cmd(struct _ADAPTER *a,
1120 				    struct _WLAN_BSSID_EX *network);
1121 void rtw_connect_abort(struct _ADAPTER *a);
1122 int rtw_connect_abort_wait(struct _ADAPTER *a);
1123 void rtw_connect_req_free(struct _ADAPTER *a);
1124 void rtw_connect_req_init(struct _ADAPTER *a);
1125 enum rtw_phl_status rtw_connect_disconnect_prepare(struct _ADAPTER *a);
1126 
1127 enum rtw_phl_status rtw_disconnect_cmd(struct _ADAPTER *a,
1128 				       struct cmd_obj *pcmd);
1129 int rtw_disconnect_abort_wait(struct _ADAPTER *a);
1130 void rtw_disconnect_req_free(struct _ADAPTER *a);
1131 void rtw_disconnect_req_init(struct _ADAPTER *a);
1132 #endif /* CONFIG_STA_CMD_DISPR */
1133 #endif /* __RTL871X_MLME_H_ */
1134