1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /* Copyright(c) 2007 - 2011 Realtek Corporation. */
3 
4 #ifndef __RTW_MLME_EXT_H_
5 #define __RTW_MLME_EXT_H_
6 
7 #include "osdep_service.h"
8 #include "drv_types.h"
9 #include "wlan_bssdef.h"
10 
11 /*	Commented by Albert 20101105 */
12 /*	Increase the SURVEY_TO value from 100 to 150  ( 100ms to 150ms ) */
13 /*	The Realtek 8188CE SoftAP will spend around 100ms to send the probe response after receiving the probe request. */
14 /*	So, this driver tried to extend the dwell time for each scanning channel. */
15 /*	This will increase the chance to receive the probe response from SoftAP. */
16 
17 #define SURVEY_TO		(100)
18 #define REAUTH_TO		(300) /* 50) */
19 #define REASSOC_TO		(300) /* 50) */
20 /* define DISCONNECT_TO	(3000) */
21 #define ADDBA_TO			(2000)
22 
23 #define LINKED_TO (1) /* unit:2 sec, 1x2=2 sec */
24 
25 #define REAUTH_LIMIT	(4)
26 #define REASSOC_LIMIT	(4)
27 
28 #define	DYNAMIC_FUNC_DISABLE			(0x0)
29 
30 /*  ====== ODM_ABILITY_E ======== */
31 /*  BB ODM section BIT 0-15 */
32 #define	DYNAMIC_BB_DIG				BIT(0)
33 
34 #define		DYNAMIC_ALL_FUNC_ENABLE		0xFFFFFFF
35 
36 #define _HW_STATE_NOLINK_		0x00
37 #define _HW_STATE_ADHOC_		0x01
38 #define _HW_STATE_STATION_	0x02
39 #define _HW_STATE_AP_			0x03
40 
41 #define		_1M_RATE_	0
42 #define		_2M_RATE_	1
43 #define		_5M_RATE_	2
44 #define		_11M_RATE_	3
45 #define		_6M_RATE_	4
46 #define		_9M_RATE_	5
47 #define		_12M_RATE_	6
48 #define		_18M_RATE_	7
49 #define		_24M_RATE_	8
50 #define		_36M_RATE_	9
51 #define		_48M_RATE_	10
52 #define		_54M_RATE_	11
53 
54 extern unsigned char RTW_WPA_OUI[];
55 extern unsigned char WMM_OUI[];
56 extern unsigned char WPS_OUI[];
57 extern unsigned char WFD_OUI[];
58 extern unsigned char P2P_OUI[];
59 
60 extern unsigned char WMM_INFO_OUI[];
61 extern unsigned char WMM_PARA_OUI[];
62 
63 /*  Channel Plan Type. */
64 /*  Note: */
65 /*	We just add new channel plan when the new channel plan is different
66  *      from any of the following channel plan. */
67 /*	If you just want to customize the actions(scan period or join actions)
68  *      about one of the channel plan, */
69 /*	customize them in struct rt_channel_info in the RT_CHANNEL_LIST. */
70 enum RT_CHANNEL_DOMAIN {
71 	/*  old channel plan mapping =====  */
72 	RT_CHANNEL_DOMAIN_FCC = 0x00,
73 	RT_CHANNEL_DOMAIN_IC = 0x01,
74 	RT_CHANNEL_DOMAIN_ETSI = 0x02,
75 	RT_CHANNEL_DOMAIN_SPAIN = 0x03,
76 	RT_CHANNEL_DOMAIN_FRANCE = 0x04,
77 	RT_CHANNEL_DOMAIN_MKK = 0x05,
78 	RT_CHANNEL_DOMAIN_MKK1 = 0x06,
79 	RT_CHANNEL_DOMAIN_ISRAEL = 0x07,
80 	RT_CHANNEL_DOMAIN_TELEC = 0x08,
81 	RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN = 0x09,
82 	RT_CHANNEL_DOMAIN_WORLD_WIDE_13 = 0x0A,
83 	RT_CHANNEL_DOMAIN_TAIWAN = 0x0B,
84 	RT_CHANNEL_DOMAIN_CHINA = 0x0C,
85 	RT_CHANNEL_DOMAIN_SINGAPORE_INDIA_MEXICO = 0x0D,
86 	RT_CHANNEL_DOMAIN_KOREA = 0x0E,
87 	RT_CHANNEL_DOMAIN_TURKEY = 0x0F,
88 	RT_CHANNEL_DOMAIN_JAPAN = 0x10,
89 	RT_CHANNEL_DOMAIN_FCC_NO_DFS = 0x11,
90 	RT_CHANNEL_DOMAIN_JAPAN_NO_DFS = 0x12,
91 	RT_CHANNEL_DOMAIN_TAIWAN_NO_DFS = 0x14,
92 
93 	/*  new channel plan mapping, (2GDOMAIN_5GDOMAIN) ===== */
94 	RT_CHANNEL_DOMAIN_WORLD_NULL = 0x20,
95 	RT_CHANNEL_DOMAIN_ETSI1_NULL = 0x21,
96 	RT_CHANNEL_DOMAIN_FCC1_NULL = 0x22,
97 	RT_CHANNEL_DOMAIN_MKK1_NULL = 0x23,
98 	RT_CHANNEL_DOMAIN_ETSI2_NULL = 0x24,
99 	RT_CHANNEL_DOMAIN_FCC1_FCC1 = 0x25,
100 	RT_CHANNEL_DOMAIN_WORLD_ETSI1 = 0x26,
101 	RT_CHANNEL_DOMAIN_MKK1_MKK1 = 0x27,
102 	RT_CHANNEL_DOMAIN_WORLD_KCC1 = 0x28,
103 	RT_CHANNEL_DOMAIN_WORLD_FCC2 = 0x29,
104 	RT_CHANNEL_DOMAIN_WORLD_FCC3 = 0x30,
105 	RT_CHANNEL_DOMAIN_WORLD_FCC4 = 0x31,
106 	RT_CHANNEL_DOMAIN_WORLD_FCC5 = 0x32,
107 	RT_CHANNEL_DOMAIN_WORLD_FCC6 = 0x33,
108 	RT_CHANNEL_DOMAIN_FCC1_FCC7 = 0x34,
109 	RT_CHANNEL_DOMAIN_WORLD_ETSI2 = 0x35,
110 	RT_CHANNEL_DOMAIN_WORLD_ETSI3 = 0x36,
111 	RT_CHANNEL_DOMAIN_MKK1_MKK2 = 0x37,
112 	RT_CHANNEL_DOMAIN_MKK1_MKK3 = 0x38,
113 	RT_CHANNEL_DOMAIN_FCC1_NCC1 = 0x39,
114 	RT_CHANNEL_DOMAIN_FCC1_NCC2 = 0x40,
115 	RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN_2G = 0x41,
116 	/*  Add new channel plan above this line=============== */
117 	RT_CHANNEL_DOMAIN_MAX,
118 	RT_CHANNEL_DOMAIN_REALTEK_DEFINE = 0x7F,
119 };
120 
121 enum RT_CHANNEL_DOMAIN_2G {
122 	RT_CHANNEL_DOMAIN_2G_WORLD = 0x00,		/* Worldwide 13 */
123 	RT_CHANNEL_DOMAIN_2G_ETSI1 = 0x01,		/* Europe */
124 	RT_CHANNEL_DOMAIN_2G_FCC1 = 0x02,		/* US */
125 	RT_CHANNEL_DOMAIN_2G_MKK1 = 0x03,		/* Japan */
126 	RT_CHANNEL_DOMAIN_2G_ETSI2 = 0x04,		/* France */
127 	RT_CHANNEL_DOMAIN_2G_NULL = 0x05,
128 	/*  Add new channel plan above this line=============== */
129 	RT_CHANNEL_DOMAIN_2G_MAX,
130 };
131 
132 #define rtw_is_channel_plan_valid(chplan)			\
133 	(chplan < RT_CHANNEL_DOMAIN_MAX ||			\
134 	 chplan == RT_CHANNEL_DOMAIN_REALTEK_DEFINE)
135 
136 struct rt_channel_plan {
137 	unsigned char	Channel[MAX_CHANNEL_NUM];
138 	unsigned char	Len;
139 };
140 
141 struct rt_channel_plan_map {
142 	unsigned char	Index2G;
143 };
144 
145 enum Associated_AP {
146 	atherosAP	= 0,
147 	broadcomAP	= 1,
148 	ciscoAP		= 2,
149 	marvellAP	= 3,
150 	ralinkAP	= 4,
151 	realtekAP	= 5,
152 	airgocapAP	= 6,
153 	unknownAP	= 7,
154 	maxAP,
155 };
156 
157 enum HT_IOT_PEER {
158 	HT_IOT_PEER_UNKNOWN		= 0,
159 	HT_IOT_PEER_REALTEK		= 1,
160 	HT_IOT_PEER_REALTEK_92SE	= 2,
161 	HT_IOT_PEER_BROADCOM		= 3,
162 	HT_IOT_PEER_RALINK		= 4,
163 	HT_IOT_PEER_ATHEROS		= 5,
164 	HT_IOT_PEER_CISCO		= 6,
165 	HT_IOT_PEER_MERU		= 7,
166 	HT_IOT_PEER_MARVELL		= 8,
167 	HT_IOT_PEER_REALTEK_SOFTAP	= 9,/*  peer is RealTek SOFT_AP */
168 	HT_IOT_PEER_SELF_SOFTAP		= 10, /*  Self is SoftAP */
169 	HT_IOT_PEER_AIRGO		= 11,
170 	HT_IOT_PEER_INTEL		= 12,
171 	HT_IOT_PEER_RTK_APCLIENT	= 13,
172 	HT_IOT_PEER_REALTEK_81XX	= 14,
173 	HT_IOT_PEER_REALTEK_WOW		= 15,
174 	HT_IOT_PEER_TENDA		= 16,
175 	HT_IOT_PEER_MAX			= 17
176 };
177 
178 enum SCAN_STATE {
179 	SCAN_DISABLE = 0,
180 	SCAN_START = 1,
181 	SCAN_TXNULL = 2,
182 	SCAN_PROCESS = 3,
183 	SCAN_COMPLETE = 4,
184 	SCAN_STATE_MAX,
185 };
186 
187 typedef unsigned int (*mlme_handler)(struct adapter *adapt, struct recv_frame *frame);
188 
189 struct	ss_res {
190 	int	state;
191 	int	bss_cnt;
192 	int	channel_idx;
193 	int	scan_mode;
194 	u8 ssid_num;
195 	u8 ch_num;
196 	struct ndis_802_11_ssid ssid[RTW_SSID_SCAN_AMOUNT];
197 	struct rtw_ieee80211_channel ch[RTW_CHANNEL_SCAN_AMOUNT];
198 };
199 
200 /* define AP_MODE				0x0C */
201 /* define STATION_MODE	0x08 */
202 /* define AD_HOC_MODE		0x04 */
203 /* define NO_LINK_MODE	0x00 */
204 
205 #define WIFI_FW_NULL_STATE		_HW_STATE_NOLINK_
206 #define	WIFI_FW_STATION_STATE		_HW_STATE_STATION_
207 #define	WIFI_FW_AP_STATE		_HW_STATE_AP_
208 #define	WIFI_FW_ADHOC_STATE		_HW_STATE_ADHOC_
209 
210 #define	WIFI_FW_AUTH_NULL		0x00000100
211 #define	WIFI_FW_AUTH_STATE		0x00000200
212 #define	WIFI_FW_AUTH_SUCCESS		0x00000400
213 
214 #define	WIFI_FW_ASSOC_STATE		0x00002000
215 #define	WIFI_FW_ASSOC_SUCCESS		0x00004000
216 
217 #define	WIFI_FW_LINKING_STATE		(WIFI_FW_AUTH_NULL |		\
218 					WIFI_FW_AUTH_STATE |		\
219 					WIFI_FW_AUTH_SUCCESS |		\
220 					WIFI_FW_ASSOC_STATE)
221 
222 struct FW_Sta_Info {
223 	struct sta_info	*psta;
224 	u32	status;
225 	u32	rx_pkt;
226 	u32	retry;
227 	unsigned char SupportedRates[NDIS_802_11_LENGTH_RATES_EX];
228 };
229 
230 /*
231  * Usage:
232  * When one iface acted as AP mode and the other iface is STA mode and scanning,
233  * it should switch back to AP's operating channel periodically.
234  * Parameters info:
235  * When the driver scanned RTW_SCAN_NUM_OF_CH channels, it would switch back to
236  * AP's operating channel for
237  * RTW_STAY_AP_CH_MILLISECOND * SURVEY_TO milliseconds.
238  * Example:
239  * For chip supports 2.4G + 5GHz and AP mode is operating in channel 1,
240  * RTW_SCAN_NUM_OF_CH is 8, RTW_STAY_AP_CH_MS is 3 and SURVEY_TO is 100.
241  * When it's STA mode gets set_scan command,
242  * it would
243  * 1. Doing the scan on channel 1.2.3.4.5.6.7.8
244  * 2. Back to channel 1 for 300 milliseconds
245  * 3. Go through doing site survey on channel 9.10.11.36.40.44.48.52
246  * 4. Back to channel 1 for 300 milliseconds
247  * 5. ... and so on, till survey done.
248  */
249 
250 struct mlme_ext_info {
251 	u32	state;
252 	u32	reauth_count;
253 	u32	reassoc_count;
254 	u32	link_count;
255 	u32	auth_seq;
256 	u32	auth_algo;	/*  802.11 auth, could be open, shared, auto */
257 	u32	authModeToggle;
258 	u32	enc_algo;/* encrypt algorithm; */
259 	u32	key_index;	/*  this is only valid for legacy wep,
260 				 *  0~3 for key id. */
261 	u32	iv;
262 	u8	chg_txt[128];
263 	u16	aid;
264 	u16	bcn_interval;
265 	u16	capability;
266 	u8	assoc_AP_vendor;
267 	u8	slotTime;
268 	u8	preamble_mode;
269 	u8	WMM_enable;
270 	u8	ERP_enable;
271 	u8	ERP_IE;
272 	u8	HT_enable;
273 	u8	HT_caps_enable;
274 	u8	HT_info_enable;
275 	u8	HT_protection;
276 	u8	turboMode_cts2self;
277 	u8	turboMode_rtsen;
278 	u8	SM_PS;
279 	u8	agg_enable_bitmap;
280 	u8	ADDBA_retry_count;
281 	u8	candidate_tid_bitmap;
282 	u8	dialogToken;
283 	/*  Accept ADDBA Request */
284 	bool bAcceptAddbaReq;
285 	u8	bwmode_updated;
286 	u8	hidden_ssid_mode;
287 
288 	struct ADDBA_request	ADDBA_req;
289 	struct WMM_para_element	WMM_param;
290 	struct HT_caps_element	HT_caps;
291 	struct HT_info_element	HT_info;
292 	struct wlan_bssid_ex	network;/* join network or bss_network,
293 					 * if in ap mode, it is the same
294 					 * as cur_network.network */
295 	struct FW_Sta_Info	FW_sta_info[NUM_STA];
296 };
297 
298 /*  The channel information about this channel including joining,
299  *  scanning, and power constraints. */
300 struct rt_channel_info {
301 	u8	ChannelNum;	/*  The channel number. */
302 	enum rt_scan_type ScanType;	/*  Scan type such as passive
303 					 *  or active scan. */
304 	u32	rx_count;
305 };
306 
307 int rtw_ch_set_search_ch(struct rt_channel_info *ch_set, const u32 ch);
308 
309 /*  P2P_MAX_REG_CLASSES - Maximum number of regulatory classes */
310 #define P2P_MAX_REG_CLASSES 10
311 
312 /*  P2P_MAX_REG_CLASS_CHANNELS - Maximum number of chan per regulatory class */
313 #define P2P_MAX_REG_CLASS_CHANNELS 20
314 
315 /*   struct p2p_channels - List of supported channels */
316 struct p2p_channels {
317 	/*  struct p2p_reg_class - Supported regulatory class */
318 	struct p2p_reg_class {
319 		/*  reg_class - Regulatory class (IEEE 802.11-2007, Annex J) */
320 		u8 reg_class;
321 
322 		/*  channel - Supported channels */
323 		u8 channel[P2P_MAX_REG_CLASS_CHANNELS];
324 
325 		/*  channels - Number of channel entries in use */
326 		size_t channels;
327 	} reg_class[P2P_MAX_REG_CLASSES];
328 
329 	/*  reg_classes - Number of reg_class entries in use */
330 	size_t reg_classes;
331 };
332 
333 struct p2p_oper_class_map {
334 	enum hw_mode {IEEE80211G} mode;
335 	u8 op_class;
336 	u8 min_chan;
337 	u8 max_chan;
338 	u8 inc;
339 	enum {BW20, BW40PLUS, BW40MINUS} bw;
340 };
341 
342 struct mlme_ext_priv {
343 	struct adapter	*padapter;
344 	u8	mlmeext_init;
345 	atomic_t event_seq;
346 	u16	mgnt_seq;
347 
348 	unsigned char	cur_channel;
349 	unsigned char	cur_bwmode;
350 	unsigned char	cur_ch_offset;/* PRIME_CHNL_OFFSET */
351 	unsigned char	cur_wireless_mode;	/*  NETWORK_TYPE */
352 
353 	unsigned char	oper_channel; /* saved chan info when call
354 				       * set_channel_bw */
355 	unsigned char	oper_bwmode;
356 	unsigned char	oper_ch_offset;/* PRIME_CHNL_OFFSET */
357 
358 	unsigned char	max_chan_nums;
359 	struct rt_channel_info channel_set[MAX_CHANNEL_NUM];
360 	struct p2p_channels channel_list;
361 	unsigned char	basicrate[NumRates];
362 	unsigned char	datarate[NumRates];
363 
364 	struct ss_res		sitesurvey_res;
365 	struct mlme_ext_info	mlmext_info;/* for sta/adhoc mode, including
366 					     * current scan/connecting/connected
367 					     * related info. For ap mode,
368 					     * network includes ap's cap_info*/
369 	struct timer_list survey_timer;
370 	struct timer_list link_timer;
371 	u16	chan_scan_time;
372 
373 	u8	scan_abort;
374 	u8	tx_rate; /*  TXRATE when USERATE is set. */
375 
376 	u32	retry; /* retry for issue probereq */
377 
378 	u64 TSFValue;
379 
380 	unsigned char bstart_bss;
381 	u8 update_channel_plan_by_ap_done;
382 	/* recv_decache check for Action_public frame */
383 	u8 action_public_dialog_token;
384 	u16	 action_public_rxseq;
385 	u8 active_keep_alive_check;
386 };
387 
388 void init_mlme_ext_priv(struct adapter *adapter);
389 int init_hw_mlme_ext(struct adapter *padapter);
390 void free_mlme_ext_priv (struct mlme_ext_priv *pmlmeext);
391 extern void init_mlme_ext_timer(struct adapter *padapter);
392 extern void init_addba_retry_timer(struct adapter *adapt, struct sta_info *sta);
393 extern struct xmit_frame *alloc_mgtxmitframe(struct xmit_priv *pxmitpriv);
394 
395 unsigned char networktype_to_raid(unsigned char network_type);
396 u8 judge_network_type(struct adapter *padapter, unsigned char *rate, int len);
397 void get_rate_set(struct adapter *padapter, unsigned char *pbssrate, int *len);
398 void UpdateBrateTbl(struct adapter *padapter, u8 *mBratesOS);
399 void UpdateBrateTblForSoftAP(u8 *bssrateset, u32 bssratelen);
400 
401 void Save_DM_Func_Flag(struct adapter *padapter);
402 void Restore_DM_Func_Flag(struct adapter *padapter);
403 
404 void Set_MSR(struct adapter *padapter, u8 type);
405 
406 u8 rtw_get_oper_ch(struct adapter *adapter);
407 void rtw_set_oper_ch(struct adapter *adapter, u8 ch);
408 void rtw_set_oper_bw(struct adapter *adapter, u8 bw);
409 void rtw_set_oper_choffset(struct adapter *adapter, u8 offset);
410 
411 void set_channel_bwmode(struct adapter *padapter, unsigned char channel,
412 			unsigned char channel_offset, unsigned short bwmode);
413 void SelectChannel(struct adapter *padapter, unsigned char channel);
414 void SetBWMode(struct adapter *padapter, unsigned short bwmode,
415 	       unsigned char channel_offset);
416 
417 unsigned int decide_wait_for_beacon_timeout(unsigned int bcn_interval);
418 
419 void write_cam(struct adapter *padapter, u8 entry, u16 ctrl, u8 *mac, u8 *key);
420 void clear_cam_entry(struct adapter *padapter, u8 entry);
421 
422 void invalidate_cam_all(struct adapter *padapter);
423 
424 int allocate_fw_sta_entry(struct adapter *padapter);
425 void flush_all_cam_entry(struct adapter *padapter);
426 
427 void site_survey(struct adapter *padapter);
428 u8 collect_bss_info(struct adapter *padapter, struct recv_frame *precv_frame,
429 		    struct wlan_bssid_ex *bssid);
430 void update_network(struct wlan_bssid_ex *dst, struct wlan_bssid_ex *src,
431 		    struct adapter *adapter, bool update_ie);
432 
433 u8 *get_my_bssid(struct wlan_bssid_ex *pnetwork);
434 u16 get_beacon_interval(struct wlan_bssid_ex *bss);
435 
436 int is_client_associated_to_ap(struct adapter *padapter);
437 int is_client_associated_to_ibss(struct adapter *padapter);
438 int is_IBSS_empty(struct adapter *padapter);
439 
440 unsigned char check_assoc_AP(u8 *pframe, uint len);
441 
442 int WMM_param_handler(struct adapter *padapter, struct ndis_802_11_var_ie *pIE);
443 void WMMOnAssocRsp(struct adapter *padapter);
444 
445 void HT_caps_handler(struct adapter *padapter, struct ndis_802_11_var_ie *pIE);
446 void HT_info_handler(struct adapter *padapter, struct ndis_802_11_var_ie *pIE);
447 void HTOnAssocRsp(struct adapter *padapter);
448 
449 void ERP_IE_handler(struct adapter *padapter, struct ndis_802_11_var_ie *pIE);
450 void VCS_update(struct adapter *padapter, struct sta_info *psta);
451 
452 void update_beacon_info(struct adapter *padapter, u8 *pframe, uint len,
453 		        struct sta_info *psta);
454 int rtw_check_bcn_info(struct adapter  *Adapter, u8 *pframe, u32 packet_len);
455 void update_IOT_info(struct adapter *padapter);
456 void update_capinfo(struct adapter *adapter, u16 updatecap);
457 void update_wireless_mode(struct adapter *padapter);
458 void update_tx_basic_rate(struct adapter *padapter, u8 modulation);
459 void update_bmc_sta_support_rate(struct adapter *padapter, u32 mac_id);
460 int update_sta_support_rate(struct adapter *padapter, u8 *pvar_ie,
461 			    uint var_ie_len, int cam_idx);
462 
463 /* for sta/adhoc mode */
464 void update_sta_info(struct adapter *padapter, struct sta_info *psta);
465 unsigned int update_basic_rate(unsigned char *ptn, unsigned int ptn_sz);
466 unsigned int update_supported_rate(unsigned char *ptn, unsigned int ptn_sz);
467 unsigned int update_MSC_rate(struct HT_caps_element *pHT_caps);
468 void Update_RA_Entry(struct adapter *padapter, u32 mac_id);
469 void set_sta_rate(struct adapter *padapter, struct sta_info *psta);
470 
471 unsigned int receive_disconnect(struct adapter *padapter,
472 				unsigned char *macaddr, unsigned short reason);
473 
474 unsigned char get_highest_rate_idx(u32 mask);
475 int support_short_GI(struct adapter *padapter, struct HT_caps_element *caps);
476 bool is_ap_in_tkip(struct adapter *padapter);
477 
478 void report_join_res(struct adapter *padapter, int res);
479 void report_survey_event(struct adapter *padapter, struct recv_frame *precv_frame);
480 void report_surveydone_event(struct adapter *padapter);
481 void report_del_sta_event(struct adapter *padapter,
482 			  unsigned char *addr, unsigned short reason);
483 void report_add_sta_event(struct adapter *padapter, unsigned char* addr,
484 			  int cam_idx);
485 
486 void beacon_timing_control(struct adapter *padapter);
487 extern u8 set_tx_beacon_cmd(struct adapter*padapter);
488 unsigned int setup_beacon_frame(struct adapter *padapter,
489 				unsigned char *beacon_frame);
490 void update_mgnt_tx_rate(struct adapter *padapter, u8 rate);
491 void update_mgntframe_attrib(struct adapter *padapter,
492 			     struct pkt_attrib *pattrib);
493 void dump_mgntframe(struct adapter *padapter, struct xmit_frame *pmgntframe);
494 s32 dump_mgntframe_and_wait(struct adapter *padapter,
495 			    struct xmit_frame *pmgntframe, int timeout_ms);
496 s32 dump_mgntframe_and_wait_ack(struct adapter *padapter,
497 				struct xmit_frame *pmgntframe);
498 
499 void issue_probersp_p2p(struct adapter *padapter, unsigned char *da);
500 void issue_p2p_provision_request(struct adapter *padapter, u8 *pssid,
501 				 u8 ussidlen, u8 *pdev_raddr);
502 void issue_p2p_GO_request(struct adapter *padapter, u8 *raddr);
503 void issue_probereq_p2p(struct adapter *padapter, u8 *da);
504 void issue_p2p_invitation_response(struct adapter *padapter, u8 *raddr,
505 				   u8 dialogToken, u8 success);
506 void issue_p2p_invitation_request(struct adapter *padapter, u8* raddr);
507 void issue_beacon(struct adapter *padapter, int timeout_ms);
508 void issue_probersp(struct adapter *padapter, unsigned char *da,
509 		    u8 is_valid_p2p_probereq);
510 void issue_assocreq(struct adapter *padapter);
511 void issue_asocrsp(struct adapter *padapter, unsigned short status,
512 		   struct sta_info *pstat, int pkt_type);
513 void issue_auth(struct adapter *padapter, struct sta_info *psta,
514 		unsigned short status);
515 void issue_probereq(struct adapter *padapter, struct ndis_802_11_ssid *pssid,
516 		    u8 *da);
517 s32 issue_probereq_ex(struct adapter *adapter, struct ndis_802_11_ssid *pssid,
518 		      u8* da, int try_cnt, int wait_ms);
519 int issue_nulldata(struct adapter *padapter, unsigned char *da,
520 		   unsigned int power_mode, int try_cnt, int wait_ms);
521 int issue_qos_nulldata(struct adapter *padapter, unsigned char *da,
522 		       u16 tid, int try_cnt, int wait_ms);
523 int issue_deauth(struct adapter *padapter, unsigned char *da,
524 		 unsigned short reason);
525 int issue_deauth_ex(struct adapter *padapter, u8 *da, unsigned short reason,
526 		    int try_cnt, int wait_ms);
527 void issue_action_BA(struct adapter *padapter, unsigned char *raddr,
528 		     unsigned char action, unsigned short status);
529 unsigned int send_delba(struct adapter *padapter, u8 initiator, u8 *addr);
530 unsigned int send_beacon(struct adapter *padapter);
531 bool get_beacon_valid_bit(struct adapter *adapter);
532 void clear_beacon_valid_bit(struct adapter *adapter);
533 
534 void start_clnt_assoc(struct adapter *padapter);
535 void start_clnt_auth(struct adapter *padapter);
536 void start_clnt_join(struct adapter *padapter);
537 void start_create_ibss(struct adapter *padapter);
538 
539 unsigned int OnAssocReq(struct adapter *padapter,
540 			struct recv_frame *precv_frame);
541 unsigned int OnAssocRsp(struct adapter *padapter,
542 			struct recv_frame *precv_frame);
543 unsigned int OnProbeReq(struct adapter *padapter,
544 			struct recv_frame *precv_frame);
545 unsigned int OnProbeRsp(struct adapter *padapter,
546 			struct recv_frame *precv_frame);
547 unsigned int DoReserved(struct adapter *padapter,
548 			struct recv_frame *precv_frame);
549 unsigned int OnBeacon(struct adapter *padapter,
550 		      struct recv_frame *precv_frame);
551 unsigned int OnAtim(struct adapter *padapter,
552 		    struct recv_frame *precv_frame);
553 unsigned int OnDisassoc(struct adapter *padapter,
554 			struct recv_frame *precv_frame);
555 unsigned int OnAuth(struct adapter *padapter,
556 		    struct recv_frame *precv_frame);
557 unsigned int OnAuthClient(struct adapter *padapter,
558 			  struct recv_frame *precv_frame);
559 unsigned int OnDeAuth(struct adapter *padapter,
560 		      struct recv_frame *precv_frame);
561 unsigned int OnAction(struct adapter *padapter,
562 		      struct recv_frame *precv_frame);
563 
564 unsigned int OnAction_back(struct adapter *padapter,
565 			   struct recv_frame *precv_frame);
566 unsigned int on_action_public(struct adapter *padapter,
567 			      struct recv_frame *precv_frame);
568 unsigned int OnAction_p2p(struct adapter *padapter,
569 			  struct recv_frame *precv_frame);
570 
571 void mlmeext_joinbss_event_callback(struct adapter *padapter, int join_res);
572 void mlmeext_sta_del_event_callback(struct adapter *padapter);
573 void mlmeext_sta_add_event_callback(struct adapter *padapter,
574 				    struct sta_info *psta);
575 
576 void linked_status_chk(struct adapter *padapter);
577 
578 void survey_timer_hdl (struct adapter *padapter);
579 void link_timer_hdl (struct adapter *padapter);
580 void addba_timer_hdl(struct sta_info *psta);
581 
582 #define set_survey_timer(mlmeext, ms) \
583 	do { \
584 		_set_timer(&(mlmeext)->survey_timer, (ms)); \
585 	} while (0)
586 
587 #define set_link_timer(mlmeext, ms) \
588 	do { \
589 		_set_timer(&(mlmeext)->link_timer, (ms)); \
590 	} while (0)
591 
592 bool cckrates_included(unsigned char *rate, int ratelen);
593 bool cckratesonly_included(unsigned char *rate, int ratelen);
594 
595 void update_TSF(struct mlme_ext_priv *pmlmeext, u8 *pframe, uint len);
596 void correct_TSF(struct adapter *padapter, struct mlme_ext_priv *pmlmeext);
597 
598 struct cmd_hdl {
599 	uint	parmsize;
600 	u8 (*h2cfuns)(struct adapter  *padapter, u8 *pbuf);
601 };
602 
603 u8 read_macreg_hdl(struct adapter *padapter, u8 *pbuf);
604 u8 write_macreg_hdl(struct adapter *padapter, u8 *pbuf);
605 u8 read_bbreg_hdl(struct adapter *padapter, u8 *pbuf);
606 u8 write_bbreg_hdl(struct adapter *padapter, u8 *pbuf);
607 u8 read_rfreg_hdl(struct adapter *padapter, u8 *pbuf);
608 u8 write_rfreg_hdl(struct adapter *padapter, u8 *pbuf);
609 u8 NULL_hdl(struct adapter *padapter, u8 *pbuf);
610 u8 join_cmd_hdl(struct adapter *padapter, u8 *pbuf);
611 u8 disconnect_hdl(struct adapter *padapter, u8 *pbuf);
612 u8 createbss_hdl(struct adapter *padapter, u8 *pbuf);
613 u8 setopmode_hdl(struct adapter *padapter, u8 *pbuf);
614 u8 sitesurvey_cmd_hdl(struct adapter *padapter, u8 *pbuf);
615 u8 setauth_hdl(struct adapter *padapter, u8 *pbuf);
616 u8 setkey_hdl(struct adapter *padapter, u8 *pbuf);
617 u8 set_stakey_hdl(struct adapter *padapter, u8 *pbuf);
618 u8 set_assocsta_hdl(struct adapter *padapter, u8 *pbuf);
619 u8 del_assocsta_hdl(struct adapter *padapter, u8 *pbuf);
620 u8 add_ba_hdl(struct adapter *padapter, unsigned char *pbuf);
621 
622 u8 mlme_evt_hdl(struct adapter *padapter, unsigned char *pbuf);
623 u8 h2c_msg_hdl(struct adapter *padapter, unsigned char *pbuf);
624 u8 tx_beacon_hdl(struct adapter *padapter, unsigned char *pbuf);
625 u8 set_ch_hdl(struct adapter *padapter, u8 *pbuf);
626 u8 set_chplan_hdl(struct adapter *padapter, unsigned char *pbuf);
627 u8 led_blink_hdl(struct adapter *padapter, unsigned char *pbuf);
628 /* Handling DFS channel switch announcement ie. */
629 u8 set_csa_hdl(struct adapter *padapter, unsigned char *pbuf);
630 u8 tdls_hdl(struct adapter *padapter, unsigned char *pbuf);
631 
632 #define GEN_DRV_CMD_HANDLER(size, cmd)	{size, &cmd ## _hdl},
633 #define GEN_MLME_EXT_HANDLER(size, cmd)	{size, cmd},
634 
635 #ifdef _RTW_CMD_C_
636 
637 static struct cmd_hdl wlancmds[] = {
638 	GEN_DRV_CMD_HANDLER(0, NULL) /*0*/
639 	GEN_DRV_CMD_HANDLER(0, NULL)
640 	GEN_DRV_CMD_HANDLER(0, NULL)
641 	GEN_DRV_CMD_HANDLER(0, NULL)
642 	GEN_DRV_CMD_HANDLER(0, NULL)
643 	GEN_DRV_CMD_HANDLER(0, NULL)
644 	GEN_MLME_EXT_HANDLER(0, NULL)
645 	GEN_MLME_EXT_HANDLER(0, NULL)
646 	GEN_MLME_EXT_HANDLER(0, NULL)
647 	GEN_MLME_EXT_HANDLER(0, NULL)
648 	GEN_MLME_EXT_HANDLER(0, NULL) /*10*/
649 	GEN_MLME_EXT_HANDLER(0, NULL)
650 	GEN_MLME_EXT_HANDLER(0, NULL)
651 	GEN_MLME_EXT_HANDLER(0, NULL)
652 	GEN_MLME_EXT_HANDLER(sizeof (struct joinbss_parm), join_cmd_hdl) /*14*/
653 	GEN_MLME_EXT_HANDLER(sizeof (struct disconnect_parm), disconnect_hdl)
654 	GEN_MLME_EXT_HANDLER(sizeof (struct createbss_parm), createbss_hdl)
655 	GEN_MLME_EXT_HANDLER(sizeof (struct setopmode_parm), setopmode_hdl)
656 	GEN_MLME_EXT_HANDLER(sizeof (struct sitesurvey_parm),
657 			     sitesurvey_cmd_hdl) /*18*/
658 	GEN_MLME_EXT_HANDLER(sizeof (struct setauth_parm), setauth_hdl)
659 	GEN_MLME_EXT_HANDLER(sizeof (struct setkey_parm), setkey_hdl) /*20*/
660 	GEN_MLME_EXT_HANDLER(sizeof (struct set_stakey_parm), set_stakey_hdl)
661 	GEN_MLME_EXT_HANDLER(sizeof (struct set_assocsta_parm), NULL)
662 	GEN_MLME_EXT_HANDLER(sizeof (struct del_assocsta_parm), NULL)
663 	GEN_MLME_EXT_HANDLER(sizeof (struct setstapwrstate_parm), NULL)
664 	GEN_MLME_EXT_HANDLER(sizeof (struct setbasicrate_parm), NULL)
665 	GEN_MLME_EXT_HANDLER(sizeof (struct getbasicrate_parm), NULL)
666 	GEN_MLME_EXT_HANDLER(sizeof (struct setdatarate_parm), NULL)
667 	GEN_MLME_EXT_HANDLER(sizeof (struct getdatarate_parm), NULL)
668 	GEN_MLME_EXT_HANDLER(sizeof (struct setphyinfo_parm), NULL)
669 	GEN_MLME_EXT_HANDLER(sizeof (struct getphyinfo_parm), NULL)  /*30*/
670 	GEN_MLME_EXT_HANDLER(sizeof (struct setphy_parm), NULL)
671 	GEN_MLME_EXT_HANDLER(sizeof (struct getphy_parm), NULL)
672 	GEN_MLME_EXT_HANDLER(0, NULL)
673 	GEN_MLME_EXT_HANDLER(0, NULL)
674 	GEN_MLME_EXT_HANDLER(0, NULL)
675 	GEN_MLME_EXT_HANDLER(0, NULL)
676 	GEN_MLME_EXT_HANDLER(0, NULL)
677 	GEN_MLME_EXT_HANDLER(0, NULL)
678 	GEN_MLME_EXT_HANDLER(0, NULL)
679 	GEN_MLME_EXT_HANDLER(0, NULL)	/*40*/
680 	GEN_MLME_EXT_HANDLER(0, NULL)
681 	GEN_MLME_EXT_HANDLER(0, NULL)
682 	GEN_MLME_EXT_HANDLER(0, NULL)
683 	GEN_MLME_EXT_HANDLER(0, NULL)
684 	GEN_MLME_EXT_HANDLER(sizeof(struct addBaReq_parm), add_ba_hdl)
685 	GEN_MLME_EXT_HANDLER(sizeof(struct set_ch_parm), set_ch_hdl) /* 46 */
686 	GEN_MLME_EXT_HANDLER(0, NULL)
687 	GEN_MLME_EXT_HANDLER(0, NULL)
688 	GEN_MLME_EXT_HANDLER(0, NULL)
689 	GEN_MLME_EXT_HANDLER(0, NULL) /*50*/
690 	GEN_MLME_EXT_HANDLER(0, NULL)
691 	GEN_MLME_EXT_HANDLER(0, NULL)
692 	GEN_MLME_EXT_HANDLER(0, NULL)
693 	GEN_MLME_EXT_HANDLER(0, NULL)
694 	GEN_MLME_EXT_HANDLER(sizeof(struct Tx_Beacon_param),
695 			     tx_beacon_hdl) /*55*/
696 
697 	GEN_MLME_EXT_HANDLER(0, mlme_evt_hdl) /*56*/
698 	GEN_MLME_EXT_HANDLER(0, rtw_drvextra_cmd_hdl) /*57*/
699 
700 	GEN_MLME_EXT_HANDLER(0, h2c_msg_hdl) /*58*/
701 	GEN_MLME_EXT_HANDLER(sizeof(struct SetChannelPlan_param),
702 			     set_chplan_hdl) /*59*/
703 	GEN_MLME_EXT_HANDLER(sizeof(struct LedBlink_param),
704 			     led_blink_hdl) /*60*/
705 
706 	GEN_MLME_EXT_HANDLER(sizeof(struct SetChannelSwitch_param),
707 			     set_csa_hdl) /*61*/
708 	GEN_MLME_EXT_HANDLER(sizeof(struct TDLSoption_param),
709 			     tdls_hdl) /*62*/
710 };
711 
712 #endif
713 
714 struct C2HEvent_Header {
715 #ifdef __LITTLE_ENDIAN
716 	unsigned int len:16;
717 	unsigned int ID:8;
718 	unsigned int seq:8;
719 #elif defined(__BIG_ENDIAN)
720 	unsigned int seq:8;
721 	unsigned int ID:8;
722 	unsigned int len:16;
723 #endif
724 	unsigned int rsvd;
725 };
726 
727 enum rtw_c2h_event {
728 	GEN_EVT_CODE(_Read_MACREG) = 0, /*0*/
729 	GEN_EVT_CODE(_Read_BBREG),
730 	GEN_EVT_CODE(_Read_RFREG),
731 	GEN_EVT_CODE(_Read_EEPROM),
732 	GEN_EVT_CODE(_Read_EFUSE),
733 	GEN_EVT_CODE(_Read_CAM),	/*5*/
734 	GEN_EVT_CODE(_Get_BasicRate),
735 	GEN_EVT_CODE(_Get_DataRate),
736 	GEN_EVT_CODE(_Survey),	 /*8*/
737 	GEN_EVT_CODE(_SurveyDone),	 /*9*/
738 
739 	GEN_EVT_CODE(_JoinBss) , /*10*/
740 	GEN_EVT_CODE(_AddSTA),
741 	GEN_EVT_CODE(_DelSTA),
742 	GEN_EVT_CODE(_AtimDone),
743 	GEN_EVT_CODE(_TX_Report),
744 	GEN_EVT_CODE(_CCX_Report),		/*15*/
745 	GEN_EVT_CODE(_DTM_Report),
746 	GEN_EVT_CODE(_TX_Rate_Statistics),
747 	GEN_EVT_CODE(_C2HLBK),
748 	GEN_EVT_CODE(_FWDBG),
749 	GEN_EVT_CODE(_C2HFEEDBACK),             /*20*/
750 	GEN_EVT_CODE(_ADDBA),
751 	GEN_EVT_CODE(_C2HBCN),
752 	GEN_EVT_CODE(_ReportPwrState),	/* filen: only for PCIE, USB */
753 	GEN_EVT_CODE(_CloseRF),		/* filen: only for PCIE,
754 					 * work around ASPM */
755 	MAX_C2HEVT
756 };
757 
758 #ifdef _RTW_MLME_EXT_C_
759 
760 static struct fwevent wlanevents[] = {
761 	{0, NULL},	/*0*/
762 	{0, NULL},
763 	{0, NULL},
764 	{0, NULL},
765 	{0, NULL},
766 	{0, NULL},
767 	{0, NULL},
768 	{0, NULL},
769 	{0, &rtw_survey_event_callback},		/*8*/
770 	{sizeof (struct surveydone_event), &rtw_surveydone_event_callback},/*9*/
771 	{0, &rtw_joinbss_event_callback},		/*10*/
772 	{sizeof(struct stassoc_event), &rtw_stassoc_event_callback},
773 	{sizeof(struct stadel_event), &rtw_stadel_event_callback},
774 	{0, NULL},
775 	{0, NULL},
776 	{0, NULL},	/*15*/
777 	{0, NULL},
778 	{0, NULL},
779 	{0, NULL},
780 	{0, NULL},
781 	{0, NULL},	 /*20*/
782 	{0, NULL},
783 	{0, NULL},
784 	{0, NULL},
785 	{0, NULL},
786 };
787 
788 #endif/* _RTL_MLME_EXT_C_ */
789 
790 #endif /* __RTW_MLME_EXT_H_ */
791