• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2019 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 #define _IOCTL_LINUX_C_
16 
17 #include <drv_types.h>
18 #include <rtw_mp.h>
19 #include "../../hal/phydm/phydm_precomp.h"
20 #ifdef RTW_HALMAC
21 #include "../../hal/hal_halmac.h"
22 #endif
23 
24 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27))
25 #define  iwe_stream_add_event(a, b, c, d, e)  iwe_stream_add_event(b, c, d, e)
26 #define  iwe_stream_add_point(a, b, c, d, e)  iwe_stream_add_point(b, c, d, e)
27 #endif
28 
29 #ifdef CONFIG_80211N_HT
30 extern int rtw_ht_enable;
31 #endif
32 
33 
34 
35 #define RTL_IOCTL_WPA_SUPPLICANT	(SIOCIWFIRSTPRIV+30)
36 
37 #define SCAN_ITEM_SIZE 768
38 #define MAX_CUSTOM_LEN 64
39 #define RATE_COUNT 4
40 #define MAX_SCAN_BUFFER_LEN 65535
41 
42 #ifdef CONFIG_GLOBAL_UI_PID
43 extern int ui_pid[3];
44 #endif
45 
46 /* combo scan */
47 #define WEXT_CSCAN_AMOUNT 9
48 #define WEXT_CSCAN_BUF_LEN		360
49 #define WEXT_CSCAN_HEADER		"CSCAN S\x01\x00\x00S\x00"
50 #define WEXT_CSCAN_HEADER_SIZE		12
51 #define WEXT_CSCAN_SSID_SECTION		'S'
52 #define WEXT_CSCAN_CHANNEL_SECTION	'C'
53 #define WEXT_CSCAN_NPROBE_SECTION	'N'
54 #define WEXT_CSCAN_ACTV_DWELL_SECTION	'A'
55 #define WEXT_CSCAN_PASV_DWELL_SECTION	'P'
56 #define WEXT_CSCAN_HOME_DWELL_SECTION	'H'
57 #define WEXT_CSCAN_TYPE_SECTION		'T'
58 
59 
60 extern u8 key_2char2num(u8 hch, u8 lch);
61 extern u8 str_2char2num(u8 hch, u8 lch);
62 extern void macstr2num(u8 *dst, u8 *src);
63 extern u8 convert_ip_addr(u8 hch, u8 mch, u8 lch);
64 
65 u32 rtw_rates[] = {1000000, 2000000, 5500000, 11000000,
66 	6000000, 9000000, 12000000, 18000000, 24000000, 36000000, 48000000, 54000000};
67 
68 #ifdef CONFIG_RTW_ANDROID
indicate_wx_custom_event(_adapter * padapter,char * msg)69 static void indicate_wx_custom_event(_adapter *padapter, char *msg)
70 {
71 	u8 *buff;
72 	union iwreq_data wrqu;
73 
74 	if (strlen(msg) > IW_CUSTOM_MAX) {
75 		RTW_INFO("%s strlen(msg):%zu > IW_CUSTOM_MAX:%u\n", __FUNCTION__ , strlen(msg), IW_CUSTOM_MAX);
76 		return;
77 	}
78 
79 	buff = rtw_zmalloc(IW_CUSTOM_MAX + 1);
80 	if (!buff)
81 		return;
82 
83 	_rtw_memcpy(buff, msg, strlen(msg));
84 
85 	_rtw_memset(&wrqu, 0, sizeof(wrqu));
86 	wrqu.data.length = strlen(msg);
87 
88 	RTW_INFO("%s %s\n", __FUNCTION__, buff);
89 #ifndef CONFIG_IOCTL_CFG80211
90 	wireless_send_event(padapter->pnetdev, IWEVCUSTOM, &wrqu, buff);
91 #endif
92 
93 	rtw_mfree(buff, IW_CUSTOM_MAX + 1);
94 
95 }
96 #endif
97 
98 #if 0
99 static void request_wps_pbc_event(_adapter *padapter)
100 {
101 	u8 *buff, *p;
102 	union iwreq_data wrqu;
103 
104 
105 	buff = rtw_malloc(IW_CUSTOM_MAX);
106 	if (!buff)
107 		return;
108 
109 	_rtw_memset(buff, 0, IW_CUSTOM_MAX);
110 
111 	p = buff;
112 
113 	p += sprintf(p, "WPS_PBC_START.request=TRUE");
114 
115 	_rtw_memset(&wrqu, 0, sizeof(wrqu));
116 
117 	wrqu.data.length = p - buff;
118 
119 	wrqu.data.length = (wrqu.data.length < IW_CUSTOM_MAX) ? wrqu.data.length : IW_CUSTOM_MAX;
120 
121 	RTW_INFO("%s\n", __FUNCTION__);
122 
123 #ifndef CONFIG_IOCTL_CFG80211
124 	wireless_send_event(padapter->pnetdev, IWEVCUSTOM, &wrqu, buff);
125 #endif
126 
127 	if (buff)
128 		rtw_mfree(buff, IW_CUSTOM_MAX);
129 
130 }
131 #endif
132 
133 #ifdef CONFIG_SUPPORT_HW_WPS_PBC
rtw_request_wps_pbc_event(_adapter * padapter)134 void rtw_request_wps_pbc_event(_adapter *padapter)
135 {
136 #ifdef RTK_DMP_PLATFORM
137 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 12))
138 	kobject_uevent(&padapter->pnetdev->dev.kobj, KOBJ_NET_PBC);
139 #else
140 	kobject_hotplug(&padapter->pnetdev->class_dev.kobj, KOBJ_NET_PBC);
141 #endif
142 #else
143 
144 	if (padapter->pid[0] == 0) {
145 		/*	0 is the default value and it means the application monitors the HW PBC doesn't privde its pid to driver. */
146 		return;
147 	}
148 
149 	rtw_signal_process(padapter->pid[0], SIGUSR1);
150 
151 #endif
152 
153 	rtw_led_control(padapter, LED_CTL_START_WPS_BOTTON);
154 }
155 #endif/* #ifdef CONFIG_SUPPORT_HW_WPS_PBC */
156 
indicate_wx_scan_complete_event(_adapter * padapter)157 void indicate_wx_scan_complete_event(_adapter *padapter)
158 {
159 #ifdef CONFIG_RTL8822CS_WIFI_HDF
160 	RTW_INFO("+rtw_indicate_wx_scan_complete_event\n");
161 	HdfWifiEventScanDone(get_rtl_netdev(), WIFI_SCAN_SUCCESS);
162 #else
163 	union iwreq_data wrqu;
164 
165 	_rtw_memset(&wrqu, 0, sizeof(union iwreq_data));
166 
167 	/* RTW_INFO("+rtw_indicate_wx_scan_complete_event\n"); */
168 #ifndef CONFIG_IOCTL_CFG80211
169 	wireless_send_event(padapter->pnetdev, SIOCGIWSCAN, &wrqu, NULL);
170 #endif
171 #endif
172 }
173 
rtw_indicate_wx_assoc_event(_adapter * padapter)174 void rtw_indicate_wx_assoc_event(_adapter *padapter)
175 {
176 	union iwreq_data wrqu;
177 	struct	mlme_priv *pmlmepriv = &padapter->mlmepriv;
178 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
179 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
180 	WLAN_BSSID_EX		*pnetwork = (WLAN_BSSID_EX *)(&(pmlmeinfo->network));
181 
182 	_rtw_memset(&wrqu, 0, sizeof(union iwreq_data));
183 
184 	wrqu.ap_addr.sa_family = ARPHRD_ETHER;
185 
186 	if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE)
187 		_rtw_memcpy(wrqu.ap_addr.sa_data, pnetwork->MacAddress, ETH_ALEN);
188 	else
189 		_rtw_memcpy(wrqu.ap_addr.sa_data, pmlmepriv->cur_network.network.MacAddress, ETH_ALEN);
190 
191 	RTW_PRINT("assoc success\n");
192 #ifndef CONFIG_IOCTL_CFG80211
193 	wireless_send_event(padapter->pnetdev, SIOCGIWAP, &wrqu, NULL);
194 #endif
195 }
196 
rtw_indicate_wx_disassoc_event(_adapter * padapter)197 void rtw_indicate_wx_disassoc_event(_adapter *padapter)
198 {
199 	union iwreq_data wrqu;
200 
201 	_rtw_memset(&wrqu, 0, sizeof(union iwreq_data));
202 
203 	wrqu.ap_addr.sa_family = ARPHRD_ETHER;
204 	_rtw_memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
205 
206 #ifndef CONFIG_IOCTL_CFG80211
207 	RTW_PRINT("indicate disassoc\n");
208 	wireless_send_event(padapter->pnetdev, SIOCGIWAP, &wrqu, NULL);
209 #endif
210 }
211 
212 /*
213 uint	rtw_is_cckrates_included(u8 *rate)
214 {
215 		u32	i = 0;
216 
217 		while(rate[i]!=0)
218 		{
219 			if  (  (((rate[i]) & 0x7f) == 2)	|| (((rate[i]) & 0x7f) == 4) ||
220 			(((rate[i]) & 0x7f) == 11)  || (((rate[i]) & 0x7f) == 22) )
221 			return _TRUE;
222 			i++;
223 		}
224 
225 		return _FALSE;
226 }
227 
228 uint	rtw_is_cckratesonly_included(u8 *rate)
229 {
230 	u32 i = 0;
231 
232 	while(rate[i]!=0)
233 	{
234 			if  (  (((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
235 				(((rate[i]) & 0x7f) != 11)  && (((rate[i]) & 0x7f) != 22) )
236 			return _FALSE;
237 			i++;
238 	}
239 
240 	return _TRUE;
241 }
242 */
243 
244 #ifdef CONFIG_IOCTL_WEXT
search_p2p_wfd_ie(_adapter * padapter,struct iw_request_info * info,struct wlan_network * pnetwork,char * start,char * stop)245 static int search_p2p_wfd_ie(_adapter *padapter,
246 		struct iw_request_info *info, struct wlan_network *pnetwork,
247 		char *start, char *stop)
248 {
249 #ifdef CONFIG_P2P
250 	struct wifidirect_info	*pwdinfo = &padapter->wdinfo;
251 #ifdef CONFIG_WFD
252 	if (SCAN_RESULT_ALL == pwdinfo->wfd_info->scan_result_type) {
253 
254 	} else if ((SCAN_RESULT_P2P_ONLY == pwdinfo->wfd_info->scan_result_type) ||
255 		(SCAN_RESULT_WFD_TYPE == pwdinfo->wfd_info->scan_result_type))
256 #endif /* CONFIG_WFD */
257 	{
258 		if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
259 			u32	blnGotP2PIE = _FALSE;
260 
261 			/*	User is doing the P2P device discovery */
262 			/*	The prefix of SSID should be "DIRECT-" and the IE should contains the P2P IE. */
263 			/*	If not, the driver should ignore this AP and go to the next AP. */
264 
265 			/*	Verifying the SSID */
266 			if (_rtw_memcmp(pnetwork->network.Ssid.Ssid, pwdinfo->p2p_wildcard_ssid, P2P_WILDCARD_SSID_LEN)) {
267 				u32	p2pielen = 0;
268 
269 				/*	Verifying the P2P IE */
270 				if (rtw_bss_ex_get_p2p_ie(&pnetwork->network, NULL, &p2pielen))
271 					blnGotP2PIE = _TRUE;
272 			}
273 
274 			if (blnGotP2PIE == _FALSE)
275 				return _FALSE;
276 
277 		}
278 	}
279 
280 #ifdef CONFIG_WFD
281 	if (SCAN_RESULT_WFD_TYPE == pwdinfo->wfd_info->scan_result_type) {
282 		u32	blnGotWFD = _FALSE;
283 		u8 *wfd_ie;
284 		uint wfd_ielen = 0;
285 
286 		wfd_ie = rtw_bss_ex_get_wfd_ie(&pnetwork->network, NULL, &wfd_ielen);
287 		if (wfd_ie) {
288 			u8 *wfd_devinfo;
289 			uint wfd_devlen;
290 
291 			wfd_devinfo = rtw_get_wfd_attr_content(wfd_ie, wfd_ielen, WFD_ATTR_DEVICE_INFO, NULL, &wfd_devlen);
292 			if (wfd_devinfo) {
293 				if (pwdinfo->wfd_info->wfd_device_type == WFD_DEVINFO_PSINK) {
294 					/*	the first two bits will indicate the WFD device type */
295 					if ((wfd_devinfo[1] & 0x03) == WFD_DEVINFO_SOURCE) {
296 						/*	If this device is Miracast PSink device, the scan reuslt should just provide the Miracast source. */
297 						blnGotWFD = _TRUE;
298 					}
299 				} else if (pwdinfo->wfd_info->wfd_device_type == WFD_DEVINFO_SOURCE) {
300 					/*	the first two bits will indicate the WFD device type */
301 					if ((wfd_devinfo[1] & 0x03) == WFD_DEVINFO_PSINK) {
302 						/*	If this device is Miracast source device, the scan reuslt should just provide the Miracast PSink. */
303 						/*	Todo: How about the SSink?! */
304 						blnGotWFD = _TRUE;
305 					}
306 				}
307 			}
308 		}
309 
310 		if (blnGotWFD == _FALSE)
311 			return _FALSE;
312 	}
313 #endif /* CONFIG_WFD */
314 
315 #endif /* CONFIG_P2P */
316 	return _TRUE;
317 }
iwe_stream_mac_addr_proess(_adapter * padapter,struct iw_request_info * info,struct wlan_network * pnetwork,char * start,char * stop,struct iw_event * iwe)318 static inline char *iwe_stream_mac_addr_proess(_adapter *padapter,
319 		struct iw_request_info *info, struct wlan_network *pnetwork,
320 		char *start, char *stop, struct iw_event *iwe)
321 {
322 	/*  AP MAC address */
323 	iwe->cmd = SIOCGIWAP;
324 	iwe->u.ap_addr.sa_family = ARPHRD_ETHER;
325 
326 	_rtw_memcpy(iwe->u.ap_addr.sa_data, pnetwork->network.MacAddress, ETH_ALEN);
327 	start = iwe_stream_add_event(info, start, stop, iwe, IW_EV_ADDR_LEN);
328 	return start;
329 }
iwe_stream_essid_proess(_adapter * padapter,struct iw_request_info * info,struct wlan_network * pnetwork,char * start,char * stop,struct iw_event * iwe)330 static inline char *iwe_stream_essid_proess(_adapter *padapter,
331 		struct iw_request_info *info, struct wlan_network *pnetwork,
332 		char *start, char *stop, struct iw_event *iwe)
333 {
334 
335 	/* Add the ESSID */
336 	iwe->cmd = SIOCGIWESSID;
337 	iwe->u.data.flags = 1;
338 	iwe->u.data.length = min((u16)pnetwork->network.Ssid.SsidLength, (u16)32);
339 	start = iwe_stream_add_point(info, start, stop, iwe, pnetwork->network.Ssid.Ssid);
340 	return start;
341 }
342 
iwe_stream_chan_process(_adapter * padapter,struct iw_request_info * info,struct wlan_network * pnetwork,char * start,char * stop,struct iw_event * iwe)343 static inline char *iwe_stream_chan_process(_adapter *padapter,
344 		struct iw_request_info *info, struct wlan_network *pnetwork,
345 		char *start, char *stop, struct iw_event *iwe)
346 {
347 	if (pnetwork->network.Configuration.DSConfig < 1 /*|| pnetwork->network.Configuration.DSConfig>14*/)
348 		pnetwork->network.Configuration.DSConfig = 1;
349 
350 	/* Add frequency/channel */
351 	iwe->cmd = SIOCGIWFREQ;
352 	iwe->u.freq.m = rtw_ch2freq(pnetwork->network.Configuration.DSConfig) * 100000;
353 	iwe->u.freq.e = 1;
354 	iwe->u.freq.i = pnetwork->network.Configuration.DSConfig;
355 	start = iwe_stream_add_event(info, start, stop, iwe, IW_EV_FREQ_LEN);
356 	return start;
357 }
iwe_stream_mode_process(_adapter * padapter,struct iw_request_info * info,struct wlan_network * pnetwork,char * start,char * stop,struct iw_event * iwe,u16 cap)358 static inline char *iwe_stream_mode_process(_adapter *padapter,
359 		struct iw_request_info *info, struct wlan_network *pnetwork,
360 		char *start, char *stop, struct iw_event *iwe, u16 cap)
361 {
362 	/* Add mode */
363 	if (cap & (WLAN_CAPABILITY_IBSS | WLAN_CAPABILITY_BSS)) {
364 		iwe->cmd = SIOCGIWMODE;
365 		if (cap & WLAN_CAPABILITY_BSS)
366 			iwe->u.mode = IW_MODE_MASTER;
367 		else
368 			iwe->u.mode = IW_MODE_ADHOC;
369 
370 		start = iwe_stream_add_event(info, start, stop, iwe, IW_EV_UINT_LEN);
371 	}
372 	return start;
373 }
iwe_stream_encryption_process(_adapter * padapter,struct iw_request_info * info,struct wlan_network * pnetwork,char * start,char * stop,struct iw_event * iwe,u16 cap)374 static inline char *iwe_stream_encryption_process(_adapter *padapter,
375 		struct iw_request_info *info, struct wlan_network *pnetwork,
376 		char *start, char *stop, struct iw_event *iwe, u16 cap)
377 {
378 
379 	/* Add encryption capability */
380 	iwe->cmd = SIOCGIWENCODE;
381 	if (cap & WLAN_CAPABILITY_PRIVACY)
382 		iwe->u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
383 	else
384 		iwe->u.data.flags = IW_ENCODE_DISABLED;
385 	iwe->u.data.length = 0;
386 	start = iwe_stream_add_point(info, start, stop, iwe, pnetwork->network.Ssid.Ssid);
387 	return start;
388 
389 }
390 
iwe_stream_protocol_process(_adapter * padapter,struct iw_request_info * info,struct wlan_network * pnetwork,char * start,char * stop,struct iw_event * iwe)391 static inline char *iwe_stream_protocol_process(_adapter *padapter,
392 		struct iw_request_info *info, struct wlan_network *pnetwork,
393 		char *start, char *stop, struct iw_event *iwe)
394 {
395 	u16 ht_cap = _FALSE, vht_cap = _FALSE;
396 	u32 ht_ielen = 0, vht_ielen = 0;
397 	char *p;
398 	u8 ie_offset = (pnetwork->network.Reserved[0] == BSS_TYPE_PROB_REQ ? 0 : 12); /* Probe Request	 */
399 
400 #ifdef CONFIG_80211N_HT
401 	/* parsing HT_CAP_IE	 */
402 	if(padapter->registrypriv.ht_enable && is_supported_ht(padapter->registrypriv.wireless_mode)) {
403 		p = rtw_get_ie(&pnetwork->network.IEs[ie_offset], _HT_CAPABILITY_IE_, &ht_ielen, pnetwork->network.IELength - ie_offset);
404 		if (p && ht_ielen > 0)
405 			ht_cap = _TRUE;
406 	}
407 #endif
408 
409 #ifdef CONFIG_80211AC_VHT
410 	/* parsing VHT_CAP_IE */
411 	if(padapter->registrypriv.wireless_mode & WIRELESS_11AC) {
412 		p = rtw_get_ie(&pnetwork->network.IEs[ie_offset], EID_VHTCapability, &vht_ielen, pnetwork->network.IELength - ie_offset);
413 		if (p && vht_ielen > 0)
414 			vht_cap = _TRUE;
415 	}
416 #endif
417 	/* Add the protocol name */
418 	iwe->cmd = SIOCGIWNAME;
419 	if ((rtw_is_cckratesonly_included((u8 *)&pnetwork->network.SupportedRates)) == _TRUE) {
420 		if (ht_cap == _TRUE)
421 			snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11bn");
422 		else
423 			snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11b");
424 	} else if ((rtw_is_cckrates_included((u8 *)&pnetwork->network.SupportedRates)) == _TRUE) {
425 		if (ht_cap == _TRUE)
426 			snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11bgn");
427 		else
428 			snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11bg");
429 	} else {
430 		if (pnetwork->network.Configuration.DSConfig > 14) {
431 			#ifdef CONFIG_80211AC_VHT
432 			if (vht_cap == _TRUE)
433 				snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11AC");
434 			else
435 			#endif
436 			{
437 				if (ht_cap == _TRUE)
438 					snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11an");
439 				else
440 					snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11a");
441 			}
442 		} else {
443 			if (ht_cap == _TRUE)
444 				snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11gn");
445 			else
446 				snprintf(iwe->u.name, IFNAMSIZ, "IEEE 802.11g");
447 		}
448 	}
449 	start = iwe_stream_add_event(info, start, stop, iwe, IW_EV_CHAR_LEN);
450 	return start;
451 }
452 
iwe_stream_rate_process(_adapter * padapter,struct iw_request_info * info,struct wlan_network * pnetwork,char * start,char * stop,struct iw_event * iwe)453 static inline char *iwe_stream_rate_process(_adapter *padapter,
454 		struct iw_request_info *info, struct wlan_network *pnetwork,
455 		char *start, char *stop, struct iw_event *iwe)
456 {
457 	u32 ht_ielen = 0, vht_ielen = 0;
458 	char *p;
459 	u16 max_rate = 0, rate, ht_cap = _FALSE, vht_cap = _FALSE;
460 	u32 i = 0;
461 	u8 bw_40MHz = 0, short_GI = 0, bw_160MHz = 0, vht_highest_rate = 0;
462 	u16 mcs_rate = 0, vht_data_rate = 0;
463 	char custom[MAX_CUSTOM_LEN] = {0};
464 	u8 ie_offset = (pnetwork->network.Reserved[0] == BSS_TYPE_PROB_REQ ? 0 : 12); /* Probe Request	 */
465 
466 	/* parsing HT_CAP_IE	 */
467 	if(is_supported_ht(padapter->registrypriv.wireless_mode)) {
468 		p = rtw_get_ie(&pnetwork->network.IEs[ie_offset], _HT_CAPABILITY_IE_, &ht_ielen, pnetwork->network.IELength - ie_offset);
469 		if (p && ht_ielen > 0) {
470 			struct rtw_ieee80211_ht_cap *pht_capie;
471 			ht_cap = _TRUE;
472 			pht_capie = (struct rtw_ieee80211_ht_cap *)(p + 2);
473 			_rtw_memcpy(&mcs_rate , pht_capie->supp_mcs_set, 2);
474 			bw_40MHz = (pht_capie->cap_info & IEEE80211_HT_CAP_SUP_WIDTH) ? 1 : 0;
475 			short_GI = (pht_capie->cap_info & (IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40)) ? 1 : 0;
476 		}
477 	}
478 #ifdef CONFIG_80211AC_VHT
479 	/* parsing VHT_CAP_IE */
480 	if(padapter->registrypriv.wireless_mode & WIRELESS_11AC){
481 		p = rtw_get_ie(&pnetwork->network.IEs[ie_offset], EID_VHTCapability, &vht_ielen, pnetwork->network.IELength - ie_offset);
482 		if (p && vht_ielen > 0) {
483 			u8	mcs_map[2];
484 
485 			vht_cap = _TRUE;
486 			bw_160MHz = GET_VHT_CAPABILITY_ELE_CHL_WIDTH(p + 2);
487 			if (bw_160MHz)
488 				short_GI = GET_VHT_CAPABILITY_ELE_SHORT_GI160M(p + 2);
489 			else
490 				short_GI = GET_VHT_CAPABILITY_ELE_SHORT_GI80M(p + 2);
491 
492 			_rtw_memcpy(mcs_map, GET_VHT_CAPABILITY_ELE_TX_MCS(p + 2), 2);
493 
494 			vht_highest_rate = rtw_get_vht_highest_rate(mcs_map);
495 			vht_data_rate = rtw_vht_mcs_to_data_rate(CHANNEL_WIDTH_80, short_GI, vht_highest_rate);
496 		}
497 	}
498 #endif
499 
500 	/*Add basic and extended rates */
501 	p = custom;
502 	p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), " Rates (Mb/s): ");
503 	while (pnetwork->network.SupportedRates[i] != 0) {
504 		rate = pnetwork->network.SupportedRates[i] & 0x7F;
505 		if (rate > max_rate)
506 			max_rate = rate;
507 		p += snprintf(p, MAX_CUSTOM_LEN - (p - custom),
508 			      "%d%s ", rate >> 1, (rate & 1) ? ".5" : "");
509 		i++;
510 	}
511 #ifdef CONFIG_80211AC_VHT
512 	if (vht_cap == _TRUE)
513 		max_rate = vht_data_rate;
514 	else
515 #endif
516 		if (ht_cap == _TRUE) {
517 			if (mcs_rate & 0x8000) /* MCS15 */
518 				max_rate = (bw_40MHz) ? ((short_GI) ? 300 : 270) : ((short_GI) ? 144 : 130);
519 
520 			else if (mcs_rate & 0x0080) /* MCS7 */
521 				max_rate = (bw_40MHz) ? ((short_GI) ? 150 : 135) : ((short_GI) ? 72 : 65);
522 			else { /* default MCS7 */
523 				/* RTW_INFO("wx_get_scan, mcs_rate_bitmap=0x%x\n", mcs_rate); */
524 				max_rate = (bw_40MHz) ? ((short_GI) ? 150 : 135) : ((short_GI) ? 72 : 65);
525 			}
526 
527 			max_rate = max_rate * 2; /* Mbps/2;		 */
528 		}
529 
530 	iwe->cmd = SIOCGIWRATE;
531 	iwe->u.bitrate.fixed = iwe->u.bitrate.disabled = 0;
532 	iwe->u.bitrate.value = max_rate * 500000;
533 	start = iwe_stream_add_event(info, start, stop, iwe, IW_EV_PARAM_LEN);
534 	return start ;
535 }
536 
iwe_stream_wpa_wpa2_process(_adapter * padapter,struct iw_request_info * info,struct wlan_network * pnetwork,char * start,char * stop,struct iw_event * iwe)537 static inline char *iwe_stream_wpa_wpa2_process(_adapter *padapter,
538 		struct iw_request_info *info, struct wlan_network *pnetwork,
539 		char *start, char *stop, struct iw_event *iwe)
540 {
541 	int buf_size = MAX_WPA_IE_LEN * 2;
542 	/* u8 pbuf[buf_size]={0};	 */
543 	u8 *pbuf = rtw_zmalloc(buf_size);
544 
545 	u8 wpa_ie[255] = {0}, rsn_ie[255] = {0};
546 	u16 i, wpa_len = 0, rsn_len = 0;
547 	u8 *p;
548 	sint out_len = 0;
549 
550 
551 	if (pbuf) {
552 		p = pbuf;
553 
554 		/* parsing WPA/WPA2 IE */
555 		if (pnetwork->network.Reserved[0] != BSS_TYPE_PROB_REQ) { /* Probe Request */
556 			out_len = rtw_get_sec_ie(pnetwork->network.IEs , pnetwork->network.IELength, rsn_ie, &rsn_len, wpa_ie, &wpa_len);
557 
558 			if (wpa_len > 0) {
559 
560 				_rtw_memset(pbuf, 0, buf_size);
561 				p += sprintf(p, "wpa_ie=");
562 				for (i = 0; i < wpa_len; i++)
563 					p += sprintf(p, "%02x", wpa_ie[i]);
564 
565 				if (wpa_len > 100) {
566 					printk("-----------------Len %d----------------\n", wpa_len);
567 					for (i = 0; i < wpa_len; i++)
568 						printk("%02x ", wpa_ie[i]);
569 					printk("\n");
570 					printk("-----------------Len %d----------------\n", wpa_len);
571 				}
572 
573 				_rtw_memset(iwe, 0, sizeof(*iwe));
574 				iwe->cmd = IWEVCUSTOM;
575 				iwe->u.data.length = strlen(pbuf);
576 				start = iwe_stream_add_point(info, start, stop, iwe, pbuf);
577 
578 				_rtw_memset(iwe, 0, sizeof(*iwe));
579 				iwe->cmd = IWEVGENIE;
580 				iwe->u.data.length = wpa_len;
581 				start = iwe_stream_add_point(info, start, stop, iwe, wpa_ie);
582 			}
583 			if (rsn_len > 0) {
584 
585 				_rtw_memset(pbuf, 0, buf_size);
586 				p += sprintf(p, "rsn_ie=");
587 				for (i = 0; i < rsn_len; i++)
588 					p += sprintf(p, "%02x", rsn_ie[i]);
589 				_rtw_memset(iwe, 0, sizeof(*iwe));
590 				iwe->cmd = IWEVCUSTOM;
591 				iwe->u.data.length = strlen(pbuf);
592 				start = iwe_stream_add_point(info, start, stop, iwe, pbuf);
593 
594 				_rtw_memset(iwe, 0, sizeof(*iwe));
595 				iwe->cmd = IWEVGENIE;
596 				iwe->u.data.length = rsn_len;
597 				start = iwe_stream_add_point(info, start, stop, iwe, rsn_ie);
598 			}
599 		}
600 
601 		rtw_mfree(pbuf, buf_size);
602 	}
603 	return start;
604 }
605 
iwe_stream_wps_process(_adapter * padapter,struct iw_request_info * info,struct wlan_network * pnetwork,char * start,char * stop,struct iw_event * iwe)606 static inline char *iwe_stream_wps_process(_adapter *padapter,
607 		struct iw_request_info *info, struct wlan_network *pnetwork,
608 		char *start, char *stop, struct iw_event *iwe)
609 {
610 	/* parsing WPS IE */
611 	uint cnt = 0, total_ielen;
612 	u8 *wpsie_ptr = NULL;
613 	uint wps_ielen = 0;
614 	u8 ie_offset = (pnetwork->network.Reserved[0] == BSS_TYPE_PROB_REQ ? 0 : 12);
615 
616 	u8 *ie_ptr = pnetwork->network.IEs + ie_offset;
617 	total_ielen = pnetwork->network.IELength - ie_offset;
618 
619 	if (pnetwork->network.Reserved[0] == BSS_TYPE_PROB_REQ) { /* Probe Request */
620 		ie_ptr = pnetwork->network.IEs;
621 		total_ielen = pnetwork->network.IELength;
622 	} else { /* Beacon or Probe Respones */
623 		ie_ptr = pnetwork->network.IEs + _FIXED_IE_LENGTH_;
624 		total_ielen = pnetwork->network.IELength - _FIXED_IE_LENGTH_;
625 	}
626 	while (cnt < total_ielen) {
627 		if (rtw_is_wps_ie(&ie_ptr[cnt], &wps_ielen) && (wps_ielen > 2)) {
628 			wpsie_ptr = &ie_ptr[cnt];
629 			iwe->cmd = IWEVGENIE;
630 			iwe->u.data.length = (u16)wps_ielen;
631 			start = iwe_stream_add_point(info, start, stop, iwe, wpsie_ptr);
632 		}
633 		cnt += ie_ptr[cnt + 1] + 2; /* goto next */
634 	}
635 	return start;
636 }
637 
iwe_stream_wapi_process(_adapter * padapter,struct iw_request_info * info,struct wlan_network * pnetwork,char * start,char * stop,struct iw_event * iwe)638 static inline char *iwe_stream_wapi_process(_adapter *padapter,
639 		struct iw_request_info *info, struct wlan_network *pnetwork,
640 		char *start, char *stop, struct iw_event *iwe)
641 {
642 #ifdef CONFIG_WAPI_SUPPORT
643 	char *p;
644 
645 	if (pnetwork->network.Reserved[0] != BSS_TYPE_PROB_REQ) { /* Probe Request */
646 		sint out_len_wapi = 0;
647 		/* here use static for stack size */
648 		static u8 buf_wapi[MAX_WAPI_IE_LEN * 2] = {0};
649 		static u8 wapi_ie[MAX_WAPI_IE_LEN] = {0};
650 		u16 wapi_len = 0;
651 		u16  i;
652 
653 		out_len_wapi = rtw_get_wapi_ie(pnetwork->network.IEs , pnetwork->network.IELength, wapi_ie, &wapi_len);
654 
655 		RTW_INFO("rtw_wx_get_scan: %s ", pnetwork->network.Ssid.Ssid);
656 		RTW_INFO("rtw_wx_get_scan: ssid = %d ", wapi_len);
657 
658 
659 		if (wapi_len > 0) {
660 			p = buf_wapi;
661 			/* _rtw_memset(buf_wapi, 0, MAX_WAPI_IE_LEN*2); */
662 			p += sprintf(p, "wapi_ie=");
663 			for (i = 0; i < wapi_len; i++)
664 				p += sprintf(p, "%02x", wapi_ie[i]);
665 
666 			_rtw_memset(iwe, 0, sizeof(*iwe));
667 			iwe->cmd = IWEVCUSTOM;
668 			iwe->u.data.length = strlen(buf_wapi);
669 			start = iwe_stream_add_point(info, start, stop, iwe, buf_wapi);
670 
671 			_rtw_memset(iwe, 0, sizeof(*iwe));
672 			iwe->cmd = IWEVGENIE;
673 			iwe->u.data.length = wapi_len;
674 			start = iwe_stream_add_point(info, start, stop, iwe, wapi_ie);
675 		}
676 	}
677 #endif/* #ifdef CONFIG_WAPI_SUPPORT */
678 	return start;
679 }
680 
iwe_stream_rssi_process(_adapter * padapter,struct iw_request_info * info,struct wlan_network * pnetwork,char * start,char * stop,struct iw_event * iwe)681 static inline char   *iwe_stream_rssi_process(_adapter *padapter,
682 		struct iw_request_info *info, struct wlan_network *pnetwork,
683 		char *start, char *stop, struct iw_event *iwe)
684 {
685 	u8 ss, sq;
686 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
687 #ifdef CONFIG_BACKGROUND_NOISE_MONITOR
688 	s16 noise = 0;
689 #endif
690 
691 	/* Add quality statistics */
692 	iwe->cmd = IWEVQUAL;
693 	iwe->u.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED
694 #ifdef CONFIG_BACKGROUND_NOISE_MONITOR
695 			      | IW_QUAL_NOISE_UPDATED
696 #else
697 			      | IW_QUAL_NOISE_INVALID
698 #endif
699 #ifdef CONFIG_SIGNAL_DISPLAY_DBM
700 			      | IW_QUAL_DBM
701 #endif
702 			      ;
703 
704 	if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE &&
705 	    is_same_network(&pmlmepriv->cur_network.network, &pnetwork->network, 0)) {
706 		ss = padapter->recvpriv.signal_strength;
707 		sq = padapter->recvpriv.signal_qual;
708 	} else {
709 		ss = pnetwork->network.PhyInfo.SignalStrength;
710 		sq = pnetwork->network.PhyInfo.SignalQuality;
711 	}
712 
713 
714 #ifdef CONFIG_SIGNAL_DISPLAY_DBM
715 	iwe->u.qual.level = (u8) translate_percentage_to_dbm(ss); /* dbm */
716 #else
717 	iwe->u.qual.level = (u8)ss; /* % */
718 #endif
719 
720 	iwe->u.qual.qual = (u8)sq;   /* signal quality */
721 
722 #ifdef CONFIG_PLATFORM_ROCKCHIPS
723 	iwe->u.qual.noise = -100; /* noise level suggest by zhf@rockchips */
724 #else
725 #ifdef CONFIG_BACKGROUND_NOISE_MONITOR
726 	if (IS_NM_ENABLE(padapter)) {
727 		noise = rtw_noise_query_by_chan_num(padapter, pnetwork->network.Configuration.DSConfig);
728 		#ifndef CONFIG_SIGNAL_DISPLAY_DBM
729 		noise = translate_dbm_to_percentage(noise);/*percentage*/
730 		#endif
731 		iwe->u.qual.noise = noise;
732 	}
733 #else
734 	iwe->u.qual.noise = 0; /* noise level */
735 #endif
736 #endif /* CONFIG_PLATFORM_ROCKCHIPS */
737 
738 	/* RTW_INFO("iqual=%d, ilevel=%d, inoise=%d, iupdated=%d\n", iwe.u.qual.qual, iwe.u.qual.level , iwe.u.qual.noise, iwe.u.qual.updated); */
739 
740 	start = iwe_stream_add_event(info, start, stop, iwe, IW_EV_QUAL_LEN);
741 	return start;
742 }
743 
iwe_stream_net_rsv_process(_adapter * padapter,struct iw_request_info * info,struct wlan_network * pnetwork,char * start,char * stop,struct iw_event * iwe)744 static inline char   *iwe_stream_net_rsv_process(_adapter *padapter,
745 		struct iw_request_info *info, struct wlan_network *pnetwork,
746 		char *start, char *stop, struct iw_event *iwe)
747 {
748 	u8 buf[32] = {0};
749 	u8 *p, *pos;
750 	p = buf;
751 	pos = pnetwork->network.Reserved;
752 
753 	p += sprintf(p, "fm=%02X%02X", pos[1], pos[0]);
754 	_rtw_memset(iwe, 0, sizeof(*iwe));
755 	iwe->cmd = IWEVCUSTOM;
756 	iwe->u.data.length = strlen(buf);
757 	start = iwe_stream_add_point(info, start, stop, iwe, buf);
758 	return start;
759 }
760 
translate_scan(_adapter * padapter,struct iw_request_info * info,struct wlan_network * pnetwork,char * start,char * stop)761 static char *translate_scan(_adapter *padapter,
762 		struct iw_request_info *info, struct wlan_network *pnetwork,
763 		char *start, char *stop)
764 {
765 	struct iw_event iwe;
766 	u16 cap = 0;
767 	_rtw_memset(&iwe, 0, sizeof(iwe));
768 
769 	if (_FALSE == search_p2p_wfd_ie(padapter, info, pnetwork, start, stop))
770 		return start;
771 
772 	start = iwe_stream_mac_addr_proess(padapter, info, pnetwork, start, stop, &iwe);
773 	start = iwe_stream_essid_proess(padapter, info, pnetwork, start, stop, &iwe);
774 	start = iwe_stream_protocol_process(padapter, info, pnetwork, start, stop, &iwe);
775 	if (pnetwork->network.Reserved[0] == BSS_TYPE_PROB_REQ) /* Probe Request */
776 		cap = 0;
777 	else {
778 		_rtw_memcpy((u8 *)&cap, rtw_get_capability_from_ie(pnetwork->network.IEs), 2);
779 		cap = le16_to_cpu(cap);
780 	}
781 
782 	start = iwe_stream_mode_process(padapter, info, pnetwork, start, stop, &iwe, cap);
783 	start = iwe_stream_chan_process(padapter, info, pnetwork, start, stop, &iwe);
784 	start = iwe_stream_encryption_process(padapter, info, pnetwork, start, stop, &iwe, cap);
785 	start = iwe_stream_rate_process(padapter, info, pnetwork, start, stop, &iwe);
786 	start = iwe_stream_wpa_wpa2_process(padapter, info, pnetwork, start, stop, &iwe);
787 	start = iwe_stream_wps_process(padapter, info, pnetwork, start, stop, &iwe);
788 	start = iwe_stream_wapi_process(padapter, info, pnetwork, start, stop, &iwe);
789 	start = iwe_stream_rssi_process(padapter, info, pnetwork, start, stop, &iwe);
790 	start = iwe_stream_net_rsv_process(padapter, info, pnetwork, start, stop, &iwe);
791 
792 	return start;
793 }
794 
wpa_set_auth_algs(struct net_device * dev,u32 value)795 static int wpa_set_auth_algs(struct net_device *dev, u32 value)
796 {
797 	_adapter *padapter = (_adapter *) rtw_netdev_priv(dev);
798 	int ret = 0;
799 
800 	if ((value & AUTH_ALG_SHARED_KEY) && (value & AUTH_ALG_OPEN_SYSTEM)) {
801 		RTW_INFO("wpa_set_auth_algs, AUTH_ALG_SHARED_KEY and  AUTH_ALG_OPEN_SYSTEM [value:0x%x]\n", value);
802 		padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
803 		padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeAutoSwitch;
804 		padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
805 	} else if (value & AUTH_ALG_SHARED_KEY) {
806 		RTW_INFO("wpa_set_auth_algs, AUTH_ALG_SHARED_KEY  [value:0x%x]\n", value);
807 		padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
808 
809 #ifdef CONFIG_PLATFORM_MT53XX
810 		padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeAutoSwitch;
811 		padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
812 #else
813 		padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeShared;
814 		padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Shared;
815 #endif
816 	} else if (value & AUTH_ALG_OPEN_SYSTEM) {
817 		RTW_INFO("wpa_set_auth_algs, AUTH_ALG_OPEN_SYSTEM\n");
818 		/* padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled; */
819 		if (padapter->securitypriv.ndisauthtype < Ndis802_11AuthModeWPAPSK) {
820 #ifdef CONFIG_PLATFORM_MT53XX
821 			padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeAutoSwitch;
822 			padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
823 #else
824 			padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
825 			padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
826 #endif
827 		}
828 
829 	} else if (value & AUTH_ALG_LEAP)
830 		RTW_INFO("wpa_set_auth_algs, AUTH_ALG_LEAP\n");
831 	else {
832 		RTW_INFO("wpa_set_auth_algs, error!\n");
833 		ret = -EINVAL;
834 	}
835 
836 	return ret;
837 
838 }
839 
wpa_set_encryption(struct net_device * dev,struct ieee_param * param,u32 param_len)840 static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len)
841 {
842 	int ret = 0;
843 	u32 wep_key_idx, wep_key_len;
844 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
845 	struct mlme_priv	*pmlmepriv = &padapter->mlmepriv;
846 	struct security_priv *psecuritypriv = &padapter->securitypriv;
847 #ifdef CONFIG_P2P
848 	struct wifidirect_info *pwdinfo = &padapter->wdinfo;
849 #endif /* CONFIG_P2P */
850 
851 
852 	param->u.crypt.err = 0;
853 	param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
854 
855 	if (param_len < (u32)((u8 *) param->u.crypt.key - (u8 *) param) + param->u.crypt.key_len) {
856 		ret =  -EINVAL;
857 		goto exit;
858 	}
859 
860 	if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
861 	    param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
862 	    param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
863 
864 		if (param->u.crypt.idx >= WEP_KEYS
865 #ifdef CONFIG_IEEE80211W
866 		    && param->u.crypt.idx > BIP_MAX_KEYID
867 #endif /* CONFIG_IEEE80211W */
868 		   ) {
869 			ret = -EINVAL;
870 			goto exit;
871 		}
872 	} else {
873 #ifdef CONFIG_WAPI_SUPPORT
874 		if (strcmp(param->u.crypt.alg, "SMS4"))
875 #endif
876 		{
877 			ret = -EINVAL;
878 			goto exit;
879 		}
880 	}
881 
882 	if (strcmp(param->u.crypt.alg, "WEP") == 0) {
883 		RTW_INFO("wpa_set_encryption, crypt.alg = WEP\n");
884 
885 		wep_key_idx = param->u.crypt.idx;
886 		wep_key_len = param->u.crypt.key_len;
887 
888 		if ((wep_key_idx >= WEP_KEYS) || (wep_key_len <= 0)) {
889 			ret = -EINVAL;
890 			goto exit;
891 		}
892 
893 		if (psecuritypriv->bWepDefaultKeyIdxSet == 0) {
894 			/* wep default key has not been set, so use this key index as default key.*/
895 
896 			wep_key_len = wep_key_len <= 5 ? 5 : 13;
897 
898 			psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
899 			psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
900 			psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
901 
902 			if (wep_key_len == 13) {
903 				psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
904 				psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
905 			}
906 
907 			psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx;
908 		}
909 
910 		_rtw_memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), param->u.crypt.key, wep_key_len);
911 
912 		psecuritypriv->dot11DefKeylen[wep_key_idx] = wep_key_len;
913 
914 		psecuritypriv->key_mask |= BIT(wep_key_idx);
915 
916 		padapter->mlmeextpriv.mlmext_info.key_index = wep_key_idx;
917 		goto exit;
918 	}
919 
920 	if (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) { /* 802_1x */
921 		struct sta_info *psta, *pbcmc_sta;
922 		struct sta_priv *pstapriv = &padapter->stapriv;
923 
924 		if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_MP_STATE) == _TRUE) { /* sta mode */
925 			psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
926 			if (psta == NULL) {
927 				/* DEBUG_ERR( ("Set wpa_set_encryption: Obtain Sta_info fail\n")); */
928 			} else {
929 				/* Jeff: don't disable ieee8021x_blocked while clearing key */
930 				if (strcmp(param->u.crypt.alg, "none") != 0)
931 					psta->ieee8021x_blocked = _FALSE;
932 
933 				if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) ||
934 				    (padapter->securitypriv.ndisencryptstatus ==  Ndis802_11Encryption3Enabled))
935 					psta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
936 
937 				if (param->u.crypt.set_tx == 1) { /* pairwise key */
938 					RTW_INFO(FUNC_ADPT_FMT" set %s PTK idx:%u, len:%u\n"
939 						, FUNC_ADPT_ARG(padapter), param->u.crypt.alg, param->u.crypt.idx, param->u.crypt.key_len);
940 					_rtw_memcpy(psta->dot118021x_UncstKey.skey,  param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
941 					if (strcmp(param->u.crypt.alg, "TKIP") == 0) { /* set mic key */
942 						_rtw_memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8);
943 						_rtw_memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8);
944 						padapter->securitypriv.busetkipkey = _FALSE;
945 					}
946 					psta->dot11txpn.val = RTW_GET_LE64(param->u.crypt.seq);
947 					psta->dot11rxpn.val = RTW_GET_LE64(param->u.crypt.seq);
948 					psta->bpairwise_key_installed = _TRUE;
949 					rtw_setstakey_cmd(padapter, psta, UNICAST_KEY, _TRUE);
950 
951 				} else { /* group key */
952 					if (strcmp(param->u.crypt.alg, "TKIP") == 0 || strcmp(param->u.crypt.alg, "CCMP") == 0) {
953 						RTW_INFO(FUNC_ADPT_FMT" set %s GTK idx:%u, len:%u\n"
954 							, FUNC_ADPT_ARG(padapter), param->u.crypt.alg, param->u.crypt.idx, param->u.crypt.key_len);
955 						_rtw_memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey,  param->u.crypt.key,
956 							(param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
957 						/* only TKIP group key need to install this */
958 						if (param->u.crypt.key_len > 16) {
959 							_rtw_memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
960 							_rtw_memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8);
961 						}
962 						padapter->securitypriv.binstallGrpkey = _TRUE;
963 						if (param->u.crypt.idx < 4)
964 							_rtw_memcpy(padapter->securitypriv.iv_seq[param->u.crypt.idx], param->u.crypt.seq, 8);
965 						padapter->securitypriv.dot118021XGrpKeyid = param->u.crypt.idx;
966 						rtw_set_key(padapter, &padapter->securitypriv, param->u.crypt.idx, 1, _TRUE);
967 
968 					#ifdef CONFIG_IEEE80211W
969 					} else if (strcmp(param->u.crypt.alg, "BIP") == 0) {
970 						RTW_INFO(FUNC_ADPT_FMT" set IGTK idx:%u, len:%u\n"
971 							, FUNC_ADPT_ARG(padapter), param->u.crypt.idx, param->u.crypt.key_len);
972 						_rtw_memcpy(padapter->securitypriv.dot11wBIPKey[param->u.crypt.idx].skey,  param->u.crypt.key,
973 							(param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
974 						psecuritypriv->dot11wBIPKeyid = param->u.crypt.idx;
975 						psecuritypriv->dot11wBIPrxpn.val = RTW_GET_LE64(param->u.crypt.seq);
976 						psecuritypriv->binstallBIPkey = _TRUE;
977 					#endif /* CONFIG_IEEE80211W */
978 
979 					}
980 
981 #ifdef CONFIG_P2P
982 					if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_PROVISIONING_ING))
983 						rtw_p2p_set_state(pwdinfo, P2P_STATE_PROVISIONING_DONE);
984 #endif /* CONFIG_P2P */
985 
986 					/* WPA/WPA2 key-handshake has completed */
987 					clr_fwstate(pmlmepriv, WIFI_UNDER_KEY_HANDSHAKE);
988 				}
989 			}
990 
991 			pbcmc_sta = rtw_get_bcmc_stainfo(padapter);
992 			if (pbcmc_sta == NULL) {
993 				/* DEBUG_ERR( ("Set OID_802_11_ADD_KEY: bcmc stainfo is null\n")); */
994 			} else {
995 				/* Jeff: don't disable ieee8021x_blocked while clearing key */
996 				if (strcmp(param->u.crypt.alg, "none") != 0)
997 					pbcmc_sta->ieee8021x_blocked = _FALSE;
998 
999 				if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) ||
1000 				    (padapter->securitypriv.ndisencryptstatus ==  Ndis802_11Encryption3Enabled))
1001 					pbcmc_sta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
1002 			}
1003 		} else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) { /* adhoc mode */
1004 		}
1005 	}
1006 
1007 #ifdef CONFIG_WAPI_SUPPORT
1008 	if (strcmp(param->u.crypt.alg, "SMS4") == 0)
1009 		rtw_wapi_set_set_encryption(padapter, param);
1010 #endif
1011 
1012 exit:
1013 
1014 
1015 	return ret;
1016 }
1017 
rtw_set_wpa_ie(_adapter * padapter,char * pie,unsigned short ielen)1018 static int rtw_set_wpa_ie(_adapter *padapter, char *pie, unsigned short ielen)
1019 {
1020 	u8 *buf = NULL, *pos = NULL;
1021 	int group_cipher = 0, pairwise_cipher = 0;
1022 	u8 mfp_opt = MFP_NO;
1023 	int ret = 0;
1024 	u8 null_addr[] = {0, 0, 0, 0, 0, 0};
1025 #ifdef CONFIG_P2P
1026 	struct wifidirect_info *pwdinfo = &padapter->wdinfo;
1027 #endif /* CONFIG_P2P */
1028 
1029 	if ((ielen > MAX_WPA_IE_LEN) || (pie == NULL)) {
1030 		_clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
1031 		if (pie == NULL)
1032 			return ret;
1033 		else
1034 			return -EINVAL;
1035 	}
1036 
1037 	if (ielen) {
1038 		buf = rtw_zmalloc(ielen);
1039 		if (buf == NULL) {
1040 			ret =  -ENOMEM;
1041 			goto exit;
1042 		}
1043 
1044 		_rtw_memcpy(buf, pie , ielen);
1045 
1046 		/* dump */
1047 		{
1048 			int i;
1049 			RTW_INFO("\n wpa_ie(length:%d):\n", ielen);
1050 			for (i = 0; i < ielen; i = i + 8)
1051 				RTW_INFO("0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", buf[i], buf[i + 1], buf[i + 2], buf[i + 3], buf[i + 4], buf[i + 5], buf[i + 6], buf[i + 7]);
1052 		}
1053 
1054 		pos = buf;
1055 		if (ielen < RSN_HEADER_LEN) {
1056 			ret  = -1;
1057 			goto exit;
1058 		}
1059 
1060 		if (rtw_parse_wpa_ie(buf, ielen, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
1061 			padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
1062 			padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPAPSK;
1063 			_rtw_memcpy(padapter->securitypriv.supplicant_ie, &buf[0], ielen);
1064 		}
1065 
1066 		if (rtw_parse_wpa2_ie(buf, ielen, &group_cipher, &pairwise_cipher, NULL, NULL, &mfp_opt, NULL) == _SUCCESS) {
1067 			padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
1068 			padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPA2PSK;
1069 			_rtw_memcpy(padapter->securitypriv.supplicant_ie, &buf[0], ielen);
1070 		}
1071 
1072 		if (group_cipher == 0)
1073 			group_cipher = WPA_CIPHER_NONE;
1074 		if (pairwise_cipher == 0)
1075 			pairwise_cipher = WPA_CIPHER_NONE;
1076 
1077 		switch (group_cipher) {
1078 		case WPA_CIPHER_NONE:
1079 			padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
1080 			padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
1081 			break;
1082 		case WPA_CIPHER_WEP40:
1083 			padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_;
1084 			padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
1085 			break;
1086 		case WPA_CIPHER_TKIP:
1087 			padapter->securitypriv.dot118021XGrpPrivacy = _TKIP_;
1088 			padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
1089 			break;
1090 		case WPA_CIPHER_CCMP:
1091 			padapter->securitypriv.dot118021XGrpPrivacy = _AES_;
1092 			padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
1093 			break;
1094 		case WPA_CIPHER_WEP104:
1095 			padapter->securitypriv.dot118021XGrpPrivacy = _WEP104_;
1096 			padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
1097 			break;
1098 		}
1099 
1100 		switch (pairwise_cipher) {
1101 		case WPA_CIPHER_NONE:
1102 			padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
1103 			padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
1104 			break;
1105 		case WPA_CIPHER_WEP40:
1106 			padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
1107 			padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
1108 			break;
1109 		case WPA_CIPHER_TKIP:
1110 			padapter->securitypriv.dot11PrivacyAlgrthm = _TKIP_;
1111 			padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
1112 			break;
1113 		case WPA_CIPHER_CCMP:
1114 			padapter->securitypriv.dot11PrivacyAlgrthm = _AES_;
1115 			padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
1116 			break;
1117 		case WPA_CIPHER_WEP104:
1118 			padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_;
1119 			padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
1120 			break;
1121 		}
1122 
1123 		if (mfp_opt == MFP_INVALID) {
1124 			RTW_INFO(FUNC_ADPT_FMT" invalid MFP setting\n", FUNC_ADPT_ARG(padapter));
1125 			ret = -EINVAL;
1126 			goto exit;
1127 		}
1128 		padapter->securitypriv.mfp_opt = mfp_opt;
1129 
1130 		_clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
1131 		{/* set wps_ie	 */
1132 			u16 cnt = 0;
1133 			u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
1134 
1135 			while (cnt < ielen) {
1136 				eid = buf[cnt];
1137 
1138 				if ((eid == _VENDOR_SPECIFIC_IE_) && (_rtw_memcmp(&buf[cnt + 2], wps_oui, 4) == _TRUE)) {
1139 					RTW_INFO("SET WPS_IE\n");
1140 
1141 					padapter->securitypriv.wps_ie_len = ((buf[cnt + 1] + 2) < MAX_WPS_IE_LEN) ? (buf[cnt + 1] + 2) : MAX_WPS_IE_LEN;
1142 
1143 					_rtw_memcpy(padapter->securitypriv.wps_ie, &buf[cnt], padapter->securitypriv.wps_ie_len);
1144 
1145 					set_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS);
1146 
1147 #ifdef CONFIG_P2P
1148 					if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_OK))
1149 						rtw_p2p_set_state(pwdinfo, P2P_STATE_PROVISIONING_ING);
1150 #endif /* CONFIG_P2P */
1151 					cnt += buf[cnt + 1] + 2;
1152 
1153 					break;
1154 				} else {
1155 					cnt += buf[cnt + 1] + 2; /* goto next	 */
1156 				}
1157 			}
1158 		}
1159 
1160 		#ifdef CONFIG_RTW_MULTI_AP
1161 		padapter->multi_ap = rtw_get_multi_ap_ie_ext(buf, ielen) & MULTI_AP_BACKHAUL_STA;
1162 		if (padapter->multi_ap)
1163 			adapter_set_use_wds(padapter, 1);
1164 		#endif
1165 	}
1166 
1167 	/* TKIP and AES disallow multicast packets until installing group key */
1168 	if (padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_
1169 	    || padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_WTMIC_
1170 	    || padapter->securitypriv.dot11PrivacyAlgrthm == _AES_)
1171 		/* WPS open need to enable multicast
1172 		 * || check_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS) == _TRUE) */
1173 		rtw_hal_set_hwreg(padapter, HW_VAR_OFF_RCR_AM, null_addr);
1174 
1175 
1176 exit:
1177 
1178 	if (buf)
1179 		rtw_mfree(buf, ielen);
1180 
1181 	return ret;
1182 }
1183 
rtw_wx_get_name(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1184 static int rtw_wx_get_name(struct net_device *dev,
1185 			   struct iw_request_info *info,
1186 			   union iwreq_data *wrqu, char *extra)
1187 {
1188 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
1189 	u32 ht_ielen = 0;
1190 	char *p;
1191 	u8 ht_cap = _FALSE, vht_cap = _FALSE;
1192 	struct	mlme_priv	*pmlmepriv = &(padapter->mlmepriv);
1193 	WLAN_BSSID_EX  *pcur_bss = &pmlmepriv->cur_network.network;
1194 	NDIS_802_11_RATES_EX *prates = NULL;
1195 
1196 
1197 
1198 	if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE | WIFI_ADHOC_MASTER_STATE) == _TRUE) {
1199 		/* parsing HT_CAP_IE */
1200 		if( is_supported_ht(padapter->registrypriv.wireless_mode)&&(padapter->registrypriv.ht_enable)) {
1201 			p = rtw_get_ie(&pcur_bss->IEs[12], _HT_CAPABILITY_IE_, &ht_ielen, pcur_bss->IELength - 12);
1202 			if (p && ht_ielen > 0 )
1203 				ht_cap = _TRUE;
1204 		}
1205 #ifdef CONFIG_80211AC_VHT
1206 		if ((padapter->registrypriv.wireless_mode & WIRELESS_11AC) &&
1207 			(pmlmepriv->vhtpriv.vht_option == _TRUE))
1208 			vht_cap = _TRUE;
1209 #endif
1210 
1211 		prates = &pcur_bss->SupportedRates;
1212 		if (rtw_is_cckratesonly_included((u8 *)prates) == _TRUE) {
1213 			if (ht_cap == _TRUE)
1214 				snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11bn");
1215 			else
1216 				snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
1217 		} else if ((rtw_is_cckrates_included((u8 *)prates)) == _TRUE) {
1218 			if (ht_cap == _TRUE)
1219 				snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11bgn");
1220 			else {
1221 				if(padapter->registrypriv.wireless_mode & WIRELESS_11G)
1222 					snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11bg");
1223 				else
1224 					snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
1225 			}
1226 		} else {
1227 			if (pcur_bss->Configuration.DSConfig > 14) {
1228 #ifdef CONFIG_80211AC_VHT
1229 				if (vht_cap == _TRUE)
1230 					snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11AC");
1231 				else
1232 #endif
1233 				{
1234 					if (ht_cap == _TRUE)
1235 						snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11an");
1236 					else
1237 						snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11a");
1238 				}
1239 			} else {
1240 				if (ht_cap == _TRUE)
1241 					snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11gn");
1242 				else
1243 					snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11g");
1244 			}
1245 		}
1246 	} else {
1247 		/* prates = &padapter->registrypriv.dev_network.SupportedRates; */
1248 		/* snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11g"); */
1249 		snprintf(wrqu->name, IFNAMSIZ, "unassociated");
1250 	}
1251 
1252 
1253 	return 0;
1254 }
1255 
rtw_wx_set_freq(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1256 static int rtw_wx_set_freq(struct net_device *dev,
1257 			   struct iw_request_info *info,
1258 			   union iwreq_data *wrqu, char *extra)
1259 {
1260 
1261 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
1262 	int exp = 1, freq = 0, div = 0;
1263 
1264 	rtw_ps_deny(padapter, PS_DENY_IOCTL);
1265 	if (rtw_pwr_wakeup(padapter) == _FALSE)
1266 		goto exit;
1267 	if (wrqu->freq.m <= 1000) {
1268 		if (wrqu->freq.flags == IW_FREQ_AUTO) {
1269 			if (rtw_chset_search_ch(adapter_to_chset(padapter), wrqu->freq.m) > 0) {
1270 				padapter->mlmeextpriv.cur_channel = wrqu->freq.m;
1271 				RTW_INFO("%s: channel is auto, set to channel %d\n", __func__, wrqu->freq.m);
1272 			} else {
1273 				padapter->mlmeextpriv.cur_channel = 1;
1274 				RTW_INFO("%s: channel is auto, Channel Plan don't match just set to channel 1\n", __func__);
1275 			}
1276 		} else {
1277 			padapter->mlmeextpriv.cur_channel = wrqu->freq.m;
1278 			RTW_INFO("%s: set to channel %d\n", __func__, padapter->mlmeextpriv.cur_channel);
1279 		}
1280 	} else {
1281 		while (wrqu->freq.e) {
1282 			exp *= 10;
1283 			wrqu->freq.e--;
1284 		}
1285 
1286 		freq = wrqu->freq.m;
1287 
1288 		while (!(freq % 10)) {
1289 			freq /= 10;
1290 			exp *= 10;
1291 		}
1292 
1293 		/* freq unit is MHz here */
1294 		div = 1000000 / exp;
1295 
1296 		if (div)
1297 			freq /= div;
1298 		else {
1299 			div = exp / 1000000;
1300 			freq *= div;
1301 		}
1302 
1303 		/* If freq is invalid, rtw_freq2ch() will return channel 1 */
1304 		padapter->mlmeextpriv.cur_channel = rtw_freq2ch(freq);
1305 		RTW_INFO("%s: set to channel %d\n", __func__, padapter->mlmeextpriv.cur_channel);
1306 	}
1307 	set_channel_bwmode(padapter, padapter->mlmeextpriv.cur_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
1308 exit:
1309 	rtw_ps_deny_cancel(padapter, PS_DENY_IOCTL);
1310 
1311 	return 0;
1312 }
1313 
rtw_wx_get_freq(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1314 static int rtw_wx_get_freq(struct net_device *dev,
1315 			   struct iw_request_info *info,
1316 			   union iwreq_data *wrqu, char *extra)
1317 {
1318 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
1319 	struct	mlme_priv	*pmlmepriv = &(padapter->mlmepriv);
1320 	WLAN_BSSID_EX  *pcur_bss = &pmlmepriv->cur_network.network;
1321 
1322 	if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE && check_fwstate(pmlmepriv, WIFI_MONITOR_STATE) != _TRUE) {
1323 
1324 		wrqu->freq.m = rtw_ch2freq(pcur_bss->Configuration.DSConfig) * 100000;
1325 		wrqu->freq.e = 1;
1326 		wrqu->freq.i = pcur_bss->Configuration.DSConfig;
1327 
1328 	} else {
1329 		wrqu->freq.m = rtw_ch2freq(padapter->mlmeextpriv.cur_channel) * 100000;
1330 		wrqu->freq.e = 1;
1331 		wrqu->freq.i = padapter->mlmeextpriv.cur_channel;
1332 	}
1333 
1334 	return 0;
1335 }
1336 
rtw_wx_set_mode(struct net_device * dev,struct iw_request_info * a,union iwreq_data * wrqu,char * b)1337 static int rtw_wx_set_mode(struct net_device *dev, struct iw_request_info *a,
1338 			   union iwreq_data *wrqu, char *b)
1339 {
1340 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
1341 	struct	mlme_priv	*pmlmepriv = &(padapter->mlmepriv);
1342 	NDIS_802_11_NETWORK_INFRASTRUCTURE networkType ;
1343 	int ret = 0;
1344 
1345 
1346 	if (_FAIL == rtw_pwr_wakeup(padapter)) {
1347 		ret = -EPERM;
1348 		goto exit;
1349 	}
1350 
1351 	if (!rtw_is_hw_init_completed(padapter)) {
1352 		ret = -EPERM;
1353 		goto exit;
1354 	}
1355 
1356 	/* initial default type */
1357 	dev->type = ARPHRD_ETHER;
1358 
1359 	if (wrqu->mode != IW_MODE_MONITOR) {
1360 		rtw_ps_deny_cancel(padapter, PS_DENY_MONITOR_MODE);
1361 	}
1362 
1363 	switch (wrqu->mode) {
1364 #ifdef CONFIG_WIFI_MONITOR
1365 	case IW_MODE_MONITOR:
1366 		networkType = Ndis802_11Monitor;
1367 
1368 		rtw_ps_deny(padapter, PS_DENY_MONITOR_MODE);
1369 		LeaveAllPowerSaveMode(padapter);
1370 
1371 #if 0
1372 		dev->type = ARPHRD_IEEE80211; /* IEEE 802.11 : 801 */
1373 #endif
1374 
1375 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24))
1376 		dev->type = ARPHRD_IEEE80211_RADIOTAP; /* IEEE 802.11 + radiotap header : 803 */
1377 		RTW_INFO("set_mode = IW_MODE_MONITOR\n");
1378 #else
1379 		RTW_INFO("kernel version < 2.6.24 not support IW_MODE_MONITOR\n");
1380 #endif
1381 		break;
1382 #endif /* CONFIG_WIFI_MONITOR */
1383 	case IW_MODE_AUTO:
1384 		networkType = Ndis802_11AutoUnknown;
1385 		RTW_INFO("set_mode = IW_MODE_AUTO\n");
1386 		break;
1387 	case IW_MODE_ADHOC:
1388 		networkType = Ndis802_11IBSS;
1389 		RTW_INFO("set_mode = IW_MODE_ADHOC\n");
1390 		break;
1391 	case IW_MODE_MASTER:
1392 		networkType = Ndis802_11APMode;
1393 		RTW_INFO("set_mode = IW_MODE_MASTER\n");
1394 		break;
1395 	case IW_MODE_INFRA:
1396 		networkType = Ndis802_11Infrastructure;
1397 		RTW_INFO("set_mode = IW_MODE_INFRA\n");
1398 		break;
1399 
1400 	default:
1401 		ret = -EINVAL;;
1402 		goto exit;
1403 	}
1404 
1405 #ifdef CONFIG_AP_MODE
1406 	if (MLME_IS_AP(padapter) && networkType == Ndis802_11Infrastructure)
1407 		rtw_stop_ap_cmd(padapter, RTW_CMDF_WAIT_ACK);
1408 	else
1409 #endif
1410 	{
1411 		if (rtw_set_802_11_infrastructure_mode(padapter, networkType, 0) == _FALSE) {
1412 			ret = -EPERM;
1413 			goto exit;
1414 		}
1415 		rtw_setopmode_cmd(padapter, networkType, RTW_CMDF_WAIT_ACK);
1416 	}
1417 
1418 	if (check_fwstate(pmlmepriv, WIFI_MONITOR_STATE) == _TRUE)
1419 		rtw_indicate_connect(padapter);
1420 
1421 exit:
1422 
1423 
1424 	return ret;
1425 
1426 }
1427 
rtw_wx_get_mode(struct net_device * dev,struct iw_request_info * a,union iwreq_data * wrqu,char * b)1428 static int rtw_wx_get_mode(struct net_device *dev, struct iw_request_info *a,
1429 			   union iwreq_data *wrqu, char *b)
1430 {
1431 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
1432 	struct	mlme_priv	*pmlmepriv = &(padapter->mlmepriv);
1433 
1434 
1435 
1436 	if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == _TRUE)
1437 		wrqu->mode = IW_MODE_INFRA;
1438 	else if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) ||
1439 		 (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE))
1440 
1441 		wrqu->mode = IW_MODE_ADHOC;
1442 	else if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
1443 		wrqu->mode = IW_MODE_MASTER;
1444 	else if (check_fwstate(pmlmepriv, WIFI_MONITOR_STATE) == _TRUE)
1445 		wrqu->mode = IW_MODE_MONITOR;
1446 	else
1447 		wrqu->mode = IW_MODE_AUTO;
1448 
1449 
1450 	return 0;
1451 
1452 }
1453 
1454 
rtw_wx_set_pmkid(struct net_device * dev,struct iw_request_info * a,union iwreq_data * wrqu,char * extra)1455 static int rtw_wx_set_pmkid(struct net_device *dev,
1456 			    struct iw_request_info *a,
1457 			    union iwreq_data *wrqu, char *extra)
1458 {
1459 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
1460 	u8          j, blInserted = _FALSE;
1461 	int         intReturn = _FALSE;
1462 	struct security_priv *psecuritypriv = &padapter->securitypriv;
1463 	struct iw_pmksa  *pPMK = (struct iw_pmksa *) extra;
1464 	u8     strZeroMacAddress[ETH_ALEN] = { 0x00 };
1465 	u8     strIssueBssid[ETH_ALEN] = { 0x00 };
1466 
1467 #if 0
1468 	struct iw_pmksa {
1469 		__u32   cmd;
1470 		struct sockaddr bssid;
1471 		__u8    pmkid[IW_PMKID_LEN];   /* IW_PMKID_LEN=16 */
1472 	}
1473 	There are the BSSID information in the bssid.sa_data array.
1474 	If cmd is IW_PMKSA_FLUSH, it means the wpa_suppplicant wants to clear all the PMKID information.
1475 	If cmd is IW_PMKSA_ADD, it means the wpa_supplicant wants to add a PMKID / BSSID to driver.
1476 	If cmd is IW_PMKSA_REMOVE, it means the wpa_supplicant wants to remove a PMKID / BSSID from driver.
1477 #endif
1478 
1479 	_rtw_memcpy(strIssueBssid, pPMK->bssid.sa_data, ETH_ALEN);
1480 	if (pPMK->cmd == IW_PMKSA_ADD) {
1481 		RTW_INFO("[rtw_wx_set_pmkid] IW_PMKSA_ADD!\n");
1482 		if (_rtw_memcmp(strIssueBssid, strZeroMacAddress, ETH_ALEN) == _TRUE)
1483 			return intReturn ;
1484 		else
1485 			intReturn = _TRUE;
1486 		blInserted = _FALSE;
1487 
1488 		/* overwrite PMKID */
1489 		for (j = 0 ; j < NUM_PMKID_CACHE; j++) {
1490 			if (_rtw_memcmp(psecuritypriv->PMKIDList[j].Bssid, strIssueBssid, ETH_ALEN) == _TRUE) {
1491 				/* BSSID is matched, the same AP => rewrite with new PMKID. */
1492 
1493 				RTW_INFO("[rtw_wx_set_pmkid] BSSID exists in the PMKList.\n");
1494 
1495 				_rtw_memcpy(psecuritypriv->PMKIDList[j].PMKID, pPMK->pmkid, IW_PMKID_LEN);
1496 				psecuritypriv->PMKIDList[j].bUsed = _TRUE;
1497 				blInserted = _TRUE;
1498 				break;
1499 			}
1500 		}
1501 
1502 		if (!blInserted) {
1503 			/* Find a new entry */
1504 			RTW_INFO("[rtw_wx_set_pmkid] Use the new entry index = %d for this PMKID.\n",
1505 				 psecuritypriv->PMKIDIndex);
1506 
1507 			_rtw_memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].Bssid, strIssueBssid, ETH_ALEN);
1508 			_rtw_memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].PMKID, pPMK->pmkid, IW_PMKID_LEN);
1509 
1510 			psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].bUsed = _TRUE;
1511 			psecuritypriv->PMKIDIndex++ ;
1512 			if (psecuritypriv->PMKIDIndex == 16)
1513 				psecuritypriv->PMKIDIndex = 0;
1514 		}
1515 	} else if (pPMK->cmd == IW_PMKSA_REMOVE) {
1516 		RTW_INFO("[rtw_wx_set_pmkid] IW_PMKSA_REMOVE!\n");
1517 		intReturn = _TRUE;
1518 		for (j = 0 ; j < NUM_PMKID_CACHE; j++) {
1519 			if (_rtw_memcmp(psecuritypriv->PMKIDList[j].Bssid, strIssueBssid, ETH_ALEN) == _TRUE) {
1520 				/* BSSID is matched, the same AP => Remove this PMKID information and reset it. */
1521 				_rtw_memset(psecuritypriv->PMKIDList[j].Bssid, 0x00, ETH_ALEN);
1522 				psecuritypriv->PMKIDList[j].bUsed = _FALSE;
1523 				break;
1524 			}
1525 		}
1526 	} else if (pPMK->cmd == IW_PMKSA_FLUSH) {
1527 		RTW_INFO("[rtw_wx_set_pmkid] IW_PMKSA_FLUSH!\n");
1528 		_rtw_memset(&psecuritypriv->PMKIDList[0], 0x00, sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE);
1529 		psecuritypriv->PMKIDIndex = 0;
1530 		intReturn = _TRUE;
1531 	}
1532 	return intReturn ;
1533 }
1534 
rtw_wx_get_sens(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1535 static int rtw_wx_get_sens(struct net_device *dev,
1536 			   struct iw_request_info *info,
1537 			   union iwreq_data *wrqu, char *extra)
1538 {
1539 #ifdef CONFIG_PLATFORM_ROCKCHIPS
1540 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
1541 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1542 
1543 	/*
1544 	*  20110311 Commented by Jeff
1545 	*  For rockchip platform's wpa_driver_wext_get_rssi
1546 	*/
1547 	if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE) {
1548 		/* wrqu->sens.value=-padapter->recvpriv.signal_strength; */
1549 		wrqu->sens.value = -padapter->recvpriv.rssi;
1550 		/* RTW_INFO("%s: %d\n", __FUNCTION__, wrqu->sens.value); */
1551 		wrqu->sens.fixed = 0; /* no auto select */
1552 	} else
1553 #endif
1554 	{
1555 		wrqu->sens.value = 0;
1556 		wrqu->sens.fixed = 0;	/* no auto select */
1557 		wrqu->sens.disabled = 1;
1558 	}
1559 	return 0;
1560 }
1561 
rtw_wx_get_range(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1562 static int rtw_wx_get_range(struct net_device *dev,
1563 			    struct iw_request_info *info,
1564 			    union iwreq_data *wrqu, char *extra)
1565 {
1566 	struct iw_range *range = (struct iw_range *)extra;
1567 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
1568 	struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
1569 	u16 val;
1570 	int i;
1571 
1572 
1573 
1574 	wrqu->data.length = sizeof(*range);
1575 	_rtw_memset(range, 0, sizeof(*range));
1576 
1577 	/* Let's try to keep this struct in the same order as in
1578 	 * linux/include/wireless.h
1579 	 */
1580 
1581 	/* TODO: See what values we can set, and remove the ones we can't
1582 	 * set, or fill them with some default data.
1583 	 */
1584 
1585 	/* ~5 Mb/s real (802.11b) */
1586 	range->throughput = 5 * 1000 * 1000;
1587 
1588 	/* TODO: Not used in 802.11b?
1589 	*	range->min_nwid;	 Minimal NWID we are able to set  */
1590 	/* TODO: Not used in 802.11b?
1591 	*	range->max_nwid;	 Maximal NWID we are able to set  */
1592 
1593 	/* Old Frequency (backward compat - moved lower ) */
1594 	/*	range->old_num_channels;
1595 	 *	range->old_num_frequency;
1596 	 * 	range->old_freq[6];  Filler to keep "version" at the same offset  */
1597 
1598 	/* signal level threshold range */
1599 
1600 	/* Quality of link & SNR stuff */
1601 	/* Quality range (link, level, noise)
1602 	 * If the quality is absolute, it will be in the range [0 ; max_qual],
1603 	 * if the quality is dBm, it will be in the range [max_qual ; 0].
1604 	 * Don't forget that we use 8 bit arithmetics...
1605 	 *
1606 	 * If percentage range is 0~100
1607 	 * Signal strength dbm range logical is -100 ~ 0
1608 	 * but usually value is -90 ~ -20
1609 	 */
1610 	range->max_qual.qual = 100;
1611 #ifdef CONFIG_SIGNAL_DISPLAY_DBM
1612 	range->max_qual.level = (u8)-100;
1613 	range->max_qual.noise = (u8)-100;
1614 	range->max_qual.updated = IW_QUAL_ALL_UPDATED; /* Updated all three */
1615 	range->max_qual.updated |= IW_QUAL_DBM;
1616 #else /* !CONFIG_SIGNAL_DISPLAY_DBM */
1617 	/* percent values between 0 and 100. */
1618 	range->max_qual.level = 100;
1619 	range->max_qual.noise = 100;
1620 	range->max_qual.updated = IW_QUAL_ALL_UPDATED; /* Updated all three */
1621 #endif /* !CONFIG_SIGNAL_DISPLAY_DBM */
1622 
1623 	/* This should contain the average/typical values of the quality
1624 	 * indicator. This should be the threshold between a "good" and
1625 	 * a "bad" link (example : monitor going from green to orange).
1626 	 * Currently, user space apps like quality monitors don't have any
1627 	 * way to calibrate the measurement. With this, they can split
1628 	 * the range between 0 and max_qual in different quality level
1629 	 * (using a geometric subdivision centered on the average).
1630 	 * I expect that people doing the user space apps will feedback
1631 	 * us on which value we need to put in each driver... */
1632 	range->avg_qual.qual = 92; /* > 8% missed beacons is 'bad' */
1633 #ifdef CONFIG_SIGNAL_DISPLAY_DBM
1634 	/* TODO: Find real 'good' to 'bad' threshold value for RSSI */
1635 	range->avg_qual.level = (u8)-70;
1636 	range->avg_qual.noise = 0;
1637 	range->avg_qual.updated = IW_QUAL_ALL_UPDATED; /* Updated all three */
1638 	range->avg_qual.updated |= IW_QUAL_DBM;
1639 #else /* !CONFIG_SIGNAL_DISPLAY_DBM */
1640 	/* TODO: Find real 'good' to 'bad' threshol value for RSSI */
1641 	range->avg_qual.level = 30;
1642 	range->avg_qual.noise = 100;
1643 	range->avg_qual.updated = IW_QUAL_ALL_UPDATED; /* Updated all three */
1644 #endif /* !CONFIG_SIGNAL_DISPLAY_DBM */
1645 
1646 	range->num_bitrates = RATE_COUNT;
1647 
1648 	for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++)
1649 		range->bitrate[i] = rtw_rates[i];
1650 
1651 	range->min_frag = MIN_FRAG_THRESHOLD;
1652 	range->max_frag = MAX_FRAG_THRESHOLD;
1653 
1654 	range->pm_capa = 0;
1655 
1656 	range->we_version_compiled = WIRELESS_EXT;
1657 	range->we_version_source = 16;
1658 
1659 	/*	range->retry_capa;	 What retry options are supported
1660 	 *	range->retry_flags;	 How to decode max/min retry limit
1661 	 *	range->r_time_flags;	 How to decode max/min retry life
1662 	 *	range->min_retry;	 Minimal number of retries
1663 	 *	range->max_retry;	 Maximal number of retries
1664 	 *	range->min_r_time;	 Minimal retry lifetime
1665 	 *	range->max_r_time;	 Maximal retry lifetime  */
1666 
1667 	for (i = 0, val = 0; i < rfctl->max_chan_nums; i++) {
1668 
1669 		/* Include only legal frequencies for some countries */
1670 		if (rfctl->channel_set[i].ChannelNum != 0) {
1671 			range->freq[val].i = rfctl->channel_set[i].ChannelNum;
1672 			range->freq[val].m = rtw_ch2freq(rfctl->channel_set[i].ChannelNum) * 100000;
1673 			range->freq[val].e = 1;
1674 			val++;
1675 		}
1676 
1677 		if (val == IW_MAX_FREQUENCIES)
1678 			break;
1679 	}
1680 
1681 	range->num_channels = val;
1682 	range->num_frequency = val;
1683 
1684 	/* Commented by Albert 2009/10/13
1685 	 * The following code will proivde the security capability to network manager.
1686 	 * If the driver doesn't provide this capability to network manager,
1687 	 * the WPA/WPA2 routers can't be choosen in the network manager. */
1688 
1689 	/*
1690 	#define IW_SCAN_CAPA_NONE		0x00
1691 	#define IW_SCAN_CAPA_ESSID		0x01
1692 	#define IW_SCAN_CAPA_BSSID		0x02
1693 	#define IW_SCAN_CAPA_CHANNEL	0x04
1694 	#define IW_SCAN_CAPA_MODE		0x08
1695 	#define IW_SCAN_CAPA_RATE		0x10
1696 	#define IW_SCAN_CAPA_TYPE		0x20
1697 	#define IW_SCAN_CAPA_TIME		0x40
1698 	*/
1699 
1700 #if WIRELESS_EXT > 17
1701 	range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
1702 			  IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
1703 #endif
1704 
1705 #ifdef IW_SCAN_CAPA_ESSID /* WIRELESS_EXT > 21 */
1706 	range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE | IW_SCAN_CAPA_BSSID |
1707 		   IW_SCAN_CAPA_CHANNEL | IW_SCAN_CAPA_MODE | IW_SCAN_CAPA_RATE;
1708 #endif
1709 
1710 
1711 
1712 	return 0;
1713 
1714 }
1715 
1716 /* set bssid flow
1717  * s1. rtw_set_802_11_infrastructure_mode()
1718  * s2. rtw_set_802_11_authentication_mode()
1719  * s3. set_802_11_encryption_mode()
1720  * s4. rtw_set_802_11_bssid() */
rtw_wx_set_wap(struct net_device * dev,struct iw_request_info * info,union iwreq_data * awrq,char * extra)1721 static int rtw_wx_set_wap(struct net_device *dev,
1722 			  struct iw_request_info *info,
1723 			  union iwreq_data *awrq,
1724 			  char *extra)
1725 {
1726 	_irqL	irqL;
1727 	uint ret = 0;
1728 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
1729 	struct sockaddr *temp = (struct sockaddr *)awrq;
1730 	struct	mlme_priv	*pmlmepriv = &(padapter->mlmepriv);
1731 	_list	*phead;
1732 	u8 *dst_bssid, *src_bssid;
1733 	_queue	*queue	= &(pmlmepriv->scanned_queue);
1734 	struct	wlan_network	*pnetwork = NULL;
1735 	NDIS_802_11_AUTHENTICATION_MODE	authmode;
1736 
1737 	/*
1738 	#ifdef CONFIG_CONCURRENT_MODE
1739 		if(padapter->adapter_type > PRIMARY_IFACE)
1740 		{
1741 			ret = -EINVAL;
1742 			goto exit;
1743 		}
1744 	#endif
1745 	*/
1746 
1747 #ifdef CONFIG_CONCURRENT_MODE
1748 	if (rtw_mi_buddy_check_fwstate(padapter, WIFI_UNDER_SURVEY | WIFI_UNDER_LINKING) == _TRUE) {
1749 		RTW_INFO("set bssid, but buddy_intf is under scanning or linking\n");
1750 
1751 		ret = -EINVAL;
1752 
1753 		goto exit;
1754 	}
1755 #endif
1756 
1757 	rtw_ps_deny(padapter, PS_DENY_JOIN);
1758 	if (_FAIL == rtw_pwr_wakeup(padapter)) {
1759 		ret = -1;
1760 		goto cancel_ps_deny;
1761 	}
1762 
1763 	if (!padapter->bup) {
1764 		ret = -1;
1765 		goto cancel_ps_deny;
1766 	}
1767 
1768 
1769 	if (temp->sa_family != ARPHRD_ETHER) {
1770 		ret = -EINVAL;
1771 		goto cancel_ps_deny;
1772 	}
1773 
1774 	authmode = padapter->securitypriv.ndisauthtype;
1775 	_enter_critical_bh(&queue->lock, &irqL);
1776 	phead = get_list_head(queue);
1777 	pmlmepriv->pscanned = get_next(phead);
1778 
1779 	while (1) {
1780 
1781 		if ((rtw_end_of_queue_search(phead, pmlmepriv->pscanned)) == _TRUE) {
1782 #if 0
1783 			ret = -EINVAL;
1784 			goto cancel_ps_deny;
1785 
1786 			if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE) {
1787 				rtw_set_802_11_bssid(padapter, temp->sa_data);
1788 				goto cancel_ps_deny;
1789 			} else {
1790 				ret = -EINVAL;
1791 				goto cancel_ps_deny;
1792 			}
1793 #endif
1794 
1795 			break;
1796 		}
1797 
1798 		pnetwork = LIST_CONTAINOR(pmlmepriv->pscanned, struct wlan_network, list);
1799 
1800 		pmlmepriv->pscanned = get_next(pmlmepriv->pscanned);
1801 
1802 		dst_bssid = pnetwork->network.MacAddress;
1803 
1804 		src_bssid = temp->sa_data;
1805 
1806 		if ((_rtw_memcmp(dst_bssid, src_bssid, ETH_ALEN)) == _TRUE) {
1807 			if (!rtw_set_802_11_infrastructure_mode(padapter, pnetwork->network.InfrastructureMode, 0)) {
1808 				ret = -1;
1809 				_exit_critical_bh(&queue->lock, &irqL);
1810 				goto cancel_ps_deny;
1811 			}
1812 
1813 			break;
1814 		}
1815 
1816 	}
1817 	_exit_critical_bh(&queue->lock, &irqL);
1818 
1819 	rtw_set_802_11_authentication_mode(padapter, authmode);
1820 	/* set_802_11_encryption_mode(padapter, padapter->securitypriv.ndisencryptstatus); */
1821 	if (rtw_set_802_11_bssid(padapter, temp->sa_data) == _FALSE) {
1822 		ret = -1;
1823 		goto cancel_ps_deny;
1824 	}
1825 
1826 cancel_ps_deny:
1827 	rtw_ps_deny_cancel(padapter, PS_DENY_JOIN);
1828 
1829 #ifdef CONFIG_CONCURRENT_MODE
1830 exit:
1831 #endif
1832 	return ret;
1833 }
1834 
rtw_wx_get_wap(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1835 static int rtw_wx_get_wap(struct net_device *dev,
1836 			  struct iw_request_info *info,
1837 			  union iwreq_data *wrqu, char *extra)
1838 {
1839 
1840 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
1841 	struct	mlme_priv	*pmlmepriv = &(padapter->mlmepriv);
1842 	WLAN_BSSID_EX  *pcur_bss = &pmlmepriv->cur_network.network;
1843 
1844 	wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1845 
1846 	_rtw_memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
1847 
1848 
1849 
1850 	if (((check_fwstate(pmlmepriv, WIFI_ASOC_STATE)) == _TRUE) ||
1851 	    ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) == _TRUE) ||
1852 	    ((check_fwstate(pmlmepriv, WIFI_AP_STATE)) == _TRUE))
1853 
1854 		_rtw_memcpy(wrqu->ap_addr.sa_data, pcur_bss->MacAddress, ETH_ALEN);
1855 	else
1856 		_rtw_memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
1857 
1858 
1859 	return 0;
1860 
1861 }
1862 
rtw_wx_set_mlme(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1863 static int rtw_wx_set_mlme(struct net_device *dev,
1864 			   struct iw_request_info *info,
1865 			   union iwreq_data *wrqu, char *extra)
1866 {
1867 #if 0
1868 	/* SIOCSIWMLME data */
1869 	struct	iw_mlme {
1870 		__u16		cmd; /* IW_MLME_* */
1871 		__u16		reason_code;
1872 		struct sockaddr	addr;
1873 	};
1874 #endif
1875 
1876 	int ret = 0;
1877 	u16 reason;
1878 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
1879 	struct iw_mlme *mlme = (struct iw_mlme *) extra;
1880 
1881 
1882 	if (mlme == NULL)
1883 		return -1;
1884 
1885 	RTW_INFO("%s\n", __FUNCTION__);
1886 
1887 	reason = cpu_to_le16(mlme->reason_code);
1888 
1889 
1890 	RTW_INFO("%s, cmd=%d, reason=%d\n", __FUNCTION__, mlme->cmd, reason);
1891 
1892 
1893 	switch (mlme->cmd) {
1894 	case IW_MLME_DEAUTH:
1895 		if (!rtw_set_802_11_disassociate(padapter))
1896 			ret = -1;
1897 		break;
1898 
1899 	case IW_MLME_DISASSOC:
1900 		if (!rtw_set_802_11_disassociate(padapter))
1901 			ret = -1;
1902 
1903 		break;
1904 
1905 	default:
1906 		return -EOPNOTSUPP;
1907 	}
1908 #ifdef CONFIG_RTW_REPEATER_SON
1909 	rtw_rson_do_disconnect(padapter);
1910 #endif
1911 	return ret;
1912 }
1913 
1914 #ifndef CONFIG_RTL8822CS_WIFI_HDF
1915 static
1916 #endif
rtw_wx_set_scan(struct net_device * dev,struct iw_request_info * a,union iwreq_data * wrqu,char * extra)1917 int rtw_wx_set_scan(struct net_device *dev, struct iw_request_info *a,
1918 			   union iwreq_data *wrqu, char *extra)
1919 {
1920 	u8 _status = _FALSE;
1921 	int ret = 0;
1922 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
1923 	/*struct mlme_priv *pmlmepriv = &padapter->mlmepriv;*/
1924 	struct sitesurvey_parm parm;
1925 	u8 ssc_chk;
1926 #ifdef CONFIG_P2P
1927 	struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
1928 #endif /* CONFIG_P2P */
1929 
1930 #ifdef DBG_IOCTL
1931 	RTW_INFO("DBG_IOCTL %s:%d\n", __FUNCTION__, __LINE__);
1932 #endif
1933 
1934 	ssc_chk = rtw_sitesurvey_condition_check(padapter, _FALSE);
1935 
1936 	#ifdef CONFIG_DOSCAN_IN_BUSYTRAFFIC
1937 	if ((ssc_chk != SS_ALLOW) && (ssc_chk != SS_DENY_BUSY_TRAFFIC))
1938 	#else
1939 	/* When Busy Traffic, driver do not site survey. So driver return success. */
1940 	/* wpa_supplicant will not issue SIOCSIWSCAN cmd again after scan timeout. */
1941 	/* modify by thomas 2011-02-22. */
1942 	if (ssc_chk != SS_ALLOW)
1943 	#endif
1944 	{
1945 		if (ssc_chk == SS_DENY_MP_MODE)
1946 			ret = -EPERM;
1947 		#ifdef DBG_LA_MODE
1948 		else if (ssc_chk == SS_DENY_LA_MODE)
1949 			ret = -EPERM;
1950 		#endif
1951 		else
1952 			indicate_wx_scan_complete_event(padapter);
1953 
1954 		goto exit;
1955 	} else
1956 		RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
1957 
1958 	rtw_ps_deny(padapter, PS_DENY_SCAN);
1959 	if (_FAIL == rtw_pwr_wakeup(padapter)) {
1960 		ret = -1;
1961 		goto cancel_ps_deny;
1962 	}
1963 	if (!rtw_is_adapter_up(padapter)) {
1964 		ret = -1;
1965 		goto cancel_ps_deny;
1966 	}
1967 
1968 #ifdef CONFIG_P2P
1969 	if (pwdinfo->p2p_state != P2P_STATE_NONE) {
1970 		rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
1971 		rtw_p2p_set_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH);
1972 		rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_FULL);
1973 		rtw_free_network_queue(padapter, _TRUE);
1974 	}
1975 #endif /* CONFIG_P2P */
1976 
1977 #if WIRELESS_EXT >= 17
1978 	if (wrqu->data.length == sizeof(struct iw_scan_req)) {
1979 		struct iw_scan_req *req = (struct iw_scan_req *)extra;
1980 
1981 		if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1982 			int len = min((int)req->essid_len, IW_ESSID_MAX_SIZE);
1983 
1984 			rtw_init_sitesurvey_parm(padapter, &parm);
1985 			_rtw_memcpy(&parm.ssid[0].Ssid, &req->essid, len);
1986 			parm.ssid[0].SsidLength = len;
1987 			parm.ssid_num = 1;
1988 
1989 			RTW_INFO("IW_SCAN_THIS_ESSID, ssid=%s, len=%d\n", req->essid, req->essid_len);
1990 
1991 			_status = rtw_set_802_11_bssid_list_scan(padapter, &parm);
1992 
1993 		} else if (req->scan_type == IW_SCAN_TYPE_PASSIVE)
1994 			RTW_INFO("rtw_wx_set_scan, req->scan_type == IW_SCAN_TYPE_PASSIVE\n");
1995 
1996 	} else
1997 #endif
1998 
1999 		if (wrqu->data.length >= WEXT_CSCAN_HEADER_SIZE
2000 		    && _rtw_memcmp(extra, WEXT_CSCAN_HEADER, WEXT_CSCAN_HEADER_SIZE) == _TRUE
2001 		   ) {
2002 			int len = wrqu->data.length - WEXT_CSCAN_HEADER_SIZE;
2003 			char *pos = extra + WEXT_CSCAN_HEADER_SIZE;
2004 			char section;
2005 			char sec_len;
2006 			int ssid_index = 0;
2007 
2008 			/* RTW_INFO("%s COMBO_SCAN header is recognized\n", __FUNCTION__); */
2009 			rtw_init_sitesurvey_parm(padapter, &parm);
2010 
2011 			while (len >= 1) {
2012 				section = *(pos++);
2013 				len -= 1;
2014 
2015 				switch (section) {
2016 				case WEXT_CSCAN_SSID_SECTION:
2017 					/* RTW_INFO("WEXT_CSCAN_SSID_SECTION\n"); */
2018 					if (len < 1) {
2019 						len = 0;
2020 						break;
2021 					}
2022 
2023 					sec_len = *(pos++);
2024 					len -= 1;
2025 
2026 					if (sec_len > 0 && sec_len <= len) {
2027 
2028 						parm.ssid[ssid_index].SsidLength = sec_len;
2029 						_rtw_memcpy(&parm.ssid[ssid_index].Ssid, pos, sec_len);
2030 
2031 						/* RTW_INFO("%s COMBO_SCAN with specific parm.ssid:%s, %d\n", __FUNCTION__ */
2032 						/*	, parm.ssid[ssid_index].Ssid, parm.ssid[ssid_index].SsidLength); */
2033 						ssid_index++;
2034 					}
2035 
2036 					pos += sec_len;
2037 					len -= sec_len;
2038 					break;
2039 
2040 
2041 				case WEXT_CSCAN_CHANNEL_SECTION:
2042 					/* RTW_INFO("WEXT_CSCAN_CHANNEL_SECTION\n"); */
2043 					pos += 1;
2044 					len -= 1;
2045 					break;
2046 				case WEXT_CSCAN_ACTV_DWELL_SECTION:
2047 					/* RTW_INFO("WEXT_CSCAN_ACTV_DWELL_SECTION\n"); */
2048 					pos += 2;
2049 					len -= 2;
2050 					break;
2051 				case WEXT_CSCAN_PASV_DWELL_SECTION:
2052 					/* RTW_INFO("WEXT_CSCAN_PASV_DWELL_SECTION\n"); */
2053 					pos += 2;
2054 					len -= 2;
2055 					break;
2056 				case WEXT_CSCAN_HOME_DWELL_SECTION:
2057 					/* RTW_INFO("WEXT_CSCAN_HOME_DWELL_SECTION\n"); */
2058 					pos += 2;
2059 					len -= 2;
2060 					break;
2061 				case WEXT_CSCAN_TYPE_SECTION:
2062 					/* RTW_INFO("WEXT_CSCAN_TYPE_SECTION\n"); */
2063 					pos += 1;
2064 					len -= 1;
2065 					break;
2066 #if 0
2067 				case WEXT_CSCAN_NPROBE_SECTION:
2068 					RTW_INFO("WEXT_CSCAN_NPROBE_SECTION\n");
2069 					break;
2070 #endif
2071 
2072 				default:
2073 					/* RTW_INFO("Unknown CSCAN section %c\n", section); */
2074 					len = 0; /* stop parsing */
2075 				}
2076 				/* RTW_INFO("len:%d\n", len); */
2077 
2078 			}
2079 			parm.ssid_num = ssid_index;
2080 
2081 			/* jeff: it has still some scan paramater to parse, we only do this now... */
2082 			_status = rtw_set_802_11_bssid_list_scan(padapter, &parm);
2083 
2084 		} else
2085 
2086 			_status = rtw_set_802_11_bssid_list_scan(padapter, NULL);
2087 
2088 	if (_status == _FALSE)
2089 		ret = -1;
2090 
2091 cancel_ps_deny:
2092 	rtw_ps_deny_cancel(padapter, PS_DENY_SCAN);
2093 
2094 exit:
2095 #ifdef DBG_IOCTL
2096 	RTW_INFO("DBG_IOCTL %s:%d return %d\n", __FUNCTION__, __LINE__, ret);
2097 #endif
2098 
2099 	return ret;
2100 }
2101 
rtw_wx_get_scan(struct net_device * dev,struct iw_request_info * a,union iwreq_data * wrqu,char * extra)2102 static int rtw_wx_get_scan(struct net_device *dev, struct iw_request_info *a,
2103 			   union iwreq_data *wrqu, char *extra)
2104 {
2105 	_irqL	irqL;
2106 	_list					*plist, *phead;
2107 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
2108 	struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
2109 	RT_CHANNEL_INFO *chset = rfctl->channel_set;
2110 	struct	mlme_priv	*pmlmepriv = &(padapter->mlmepriv);
2111 	_queue				*queue	= &(pmlmepriv->scanned_queue);
2112 	struct	wlan_network	*pnetwork = NULL;
2113 	char *ev = extra;
2114 	char *stop = ev + wrqu->data.length;
2115 	u32 ret = 0;
2116 	u32 wait_for_surveydone;
2117 	sint wait_status;
2118 	u8 ch;
2119 
2120 #ifdef CONFIG_P2P
2121 	struct	wifidirect_info	*pwdinfo = &padapter->wdinfo;
2122 #endif /* CONFIG_P2P */
2123 
2124 
2125 #ifdef DBG_IOCTL
2126 	RTW_INFO("DBG_IOCTL %s:%d\n", __FUNCTION__, __LINE__);
2127 #endif
2128 
2129 	if (adapter_to_pwrctl(padapter)->brfoffbyhw && rtw_is_drv_stopped(padapter)) {
2130 		ret = -EINVAL;
2131 		goto exit;
2132 	}
2133 
2134 #ifdef CONFIG_P2P
2135 	if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
2136 		wait_for_surveydone = 200;
2137 	else {
2138 		/*	P2P is disabled */
2139 		wait_for_surveydone = 100;
2140 	}
2141 #else
2142 	{
2143 		wait_for_surveydone = 100;
2144 	}
2145 #endif /* CONFIG_P2P */
2146 
2147 #if 1 /* Wireless Extension use EAGAIN to try */
2148 	wait_status = WIFI_UNDER_SURVEY
2149 #ifndef CONFIG_RTW_ANDROID
2150 		      | WIFI_UNDER_LINKING
2151 #endif
2152 		      ;
2153 
2154 	while (check_fwstate(pmlmepriv, wait_status) == _TRUE)
2155 		return -EAGAIN;
2156 #else
2157 	wait_status = WIFI_UNDER_SURVEY
2158 #ifndef CONFIG_RTW_ANDROID
2159 		      | WIFI_UNDER_LINKING
2160 #endif
2161 		      ;
2162 
2163 	while (check_fwstate(pmlmepriv, wait_status) == _TRUE) {
2164 		rtw_msleep_os(30);
2165 		cnt++;
2166 		if (cnt > wait_for_surveydone)
2167 			break;
2168 	}
2169 #endif
2170 	_enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
2171 
2172 	phead = get_list_head(queue);
2173 	plist = get_next(phead);
2174 
2175 	while (1) {
2176 		if (rtw_end_of_queue_search(phead, plist) == _TRUE)
2177 			break;
2178 
2179 		if ((stop - ev) < SCAN_ITEM_SIZE) {
2180 			if(wrqu->data.length == MAX_SCAN_BUFFER_LEN){ /*max buffer len defined by iwlist*/
2181 				ret = 0;
2182 				RTW_INFO("%s: Scan results incomplete\n", __FUNCTION__);
2183 				break;
2184 			}
2185 			ret = -E2BIG;
2186 			break;
2187 		}
2188 
2189 		pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
2190 		ch = pnetwork->network.Configuration.DSConfig;
2191 
2192 		/* report network only if the current channel set contains the channel to which this network belongs */
2193 		if (rtw_chset_search_ch(chset, ch) >= 0
2194 			&& rtw_mlme_band_check(padapter, ch) == _TRUE
2195 			&& _TRUE == rtw_validate_ssid(&(pnetwork->network.Ssid))
2196 			&& (!IS_DFS_SLAVE_WITH_RD(rfctl)
2197 				|| rtw_rfctl_dfs_domain_unknown(rfctl)
2198 				|| !rtw_chset_is_ch_non_ocp(chset, ch))
2199 		)
2200 			ev = translate_scan(padapter, a, pnetwork, ev, stop);
2201 
2202 		plist = get_next(plist);
2203 
2204 	}
2205 
2206 	_exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
2207 
2208 	wrqu->data.length = ev - extra;
2209 	wrqu->data.flags = 0;
2210 
2211 exit:
2212 
2213 
2214 #ifdef DBG_IOCTL
2215 	RTW_INFO("DBG_IOCTL %s:%d return %d\n", __FUNCTION__, __LINE__, ret);
2216 #endif
2217 
2218 	return ret ;
2219 
2220 }
2221 
2222 /* set ssid flow
2223  * s1. rtw_set_802_11_infrastructure_mode()
2224  * s2. set_802_11_authenticaion_mode()
2225  * s3. set_802_11_encryption_mode()
2226  * s4. rtw_set_802_11_ssid() */
rtw_wx_set_essid(struct net_device * dev,struct iw_request_info * a,union iwreq_data * wrqu,char * extra)2227 static int rtw_wx_set_essid(struct net_device *dev,
2228 			    struct iw_request_info *a,
2229 			    union iwreq_data *wrqu, char *extra)
2230 {
2231 	_irqL irqL;
2232 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
2233 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2234 	_queue *queue = &pmlmepriv->scanned_queue;
2235 	_list *phead;
2236 	struct wlan_network *pnetwork = NULL;
2237 	NDIS_802_11_AUTHENTICATION_MODE authmode;
2238 	NDIS_802_11_SSID ndis_ssid;
2239 	u8 *dst_ssid, *src_ssid;
2240 
2241 	uint ret = 0, len;
2242 
2243 
2244 #ifdef DBG_IOCTL
2245 	RTW_INFO("DBG_IOCTL %s:%d\n", __FUNCTION__, __LINE__);
2246 #endif
2247 #ifdef CONFIG_WEXT_DONT_JOIN_BYSSID
2248 	RTW_INFO("%s: CONFIG_WEXT_DONT_JOIN_BYSSID be defined!! only allow bssid joining\n", __func__);
2249 	return -EPERM;
2250 #endif
2251 
2252 #if WIRELESS_EXT <= 20
2253 	if ((wrqu->essid.length - 1) > IW_ESSID_MAX_SIZE) {
2254 #else
2255 	if (wrqu->essid.length > IW_ESSID_MAX_SIZE) {
2256 #endif
2257 		ret = -E2BIG;
2258 		goto exit;
2259 	}
2260 
2261 
2262 
2263 	rtw_ps_deny(padapter, PS_DENY_JOIN);
2264 	if (_FAIL == rtw_pwr_wakeup(padapter)) {
2265 		ret = -1;
2266 		goto cancel_ps_deny;
2267 	}
2268 
2269 	if (!padapter->bup) {
2270 		ret = -1;
2271 		goto cancel_ps_deny;
2272 	}
2273 
2274 	if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
2275 		ret = -1;
2276 		goto cancel_ps_deny;
2277 	}
2278 
2279 #ifdef CONFIG_CONCURRENT_MODE
2280 	if (rtw_mi_buddy_check_fwstate(padapter, WIFI_UNDER_SURVEY | WIFI_UNDER_LINKING)) {
2281 		RTW_INFO("set ssid, but buddy_intf is under scanning or linking\n");
2282 		ret = -EINVAL;
2283 		goto cancel_ps_deny;
2284 	}
2285 #endif
2286 	authmode = padapter->securitypriv.ndisauthtype;
2287 	RTW_INFO("=>%s\n", __FUNCTION__);
2288 	if (wrqu->essid.flags && wrqu->essid.length) {
2289 		/* Commented by Albert 20100519 */
2290 		/* We got the codes in "set_info" function of iwconfig source code. */
2291 		/*	========================================= */
2292 		/*	wrq.u.essid.length = strlen(essid) + 1; */
2293 		/*	if(we_kernel_version > 20) */
2294 		/*		wrq.u.essid.length--; */
2295 		/*	========================================= */
2296 		/*	That means, if the WIRELESS_EXT less than or equal to 20, the correct ssid len should subtract 1. */
2297 #if WIRELESS_EXT <= 20
2298 		len = ((wrqu->essid.length - 1) < IW_ESSID_MAX_SIZE) ? (wrqu->essid.length - 1) : IW_ESSID_MAX_SIZE;
2299 #else
2300 		len = (wrqu->essid.length < IW_ESSID_MAX_SIZE) ? wrqu->essid.length : IW_ESSID_MAX_SIZE;
2301 #endif
2302 
2303 		if (wrqu->essid.length != 33)
2304 			RTW_INFO("ssid=%s, len=%d\n", extra, wrqu->essid.length);
2305 
2306 		_rtw_memset(&ndis_ssid, 0, sizeof(NDIS_802_11_SSID));
2307 		ndis_ssid.SsidLength = len;
2308 		_rtw_memcpy(ndis_ssid.Ssid, extra, len);
2309 		src_ssid = ndis_ssid.Ssid;
2310 
2311 		_enter_critical_bh(&queue->lock, &irqL);
2312 		phead = get_list_head(queue);
2313 		pmlmepriv->pscanned = get_next(phead);
2314 
2315 		while (1) {
2316 			if (rtw_end_of_queue_search(phead, pmlmepriv->pscanned) == _TRUE) {
2317 #if 0
2318 				if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE) {
2319 					rtw_set_802_11_ssid(padapter, &ndis_ssid);
2320 
2321 					goto cancel_ps_deny;
2322 				} else {
2323 					ret = -EINVAL;
2324 					goto cancel_ps_deny;
2325 				}
2326 #endif
2327 
2328 				break;
2329 			}
2330 
2331 			pnetwork = LIST_CONTAINOR(pmlmepriv->pscanned, struct wlan_network, list);
2332 
2333 			pmlmepriv->pscanned = get_next(pmlmepriv->pscanned);
2334 
2335 			dst_ssid = pnetwork->network.Ssid.Ssid;
2336 
2337 
2338 			if ((_rtw_memcmp(dst_ssid, src_ssid, ndis_ssid.SsidLength) == _TRUE) &&
2339 			    (pnetwork->network.Ssid.SsidLength == ndis_ssid.SsidLength)) {
2340 
2341 				if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE) {
2342 					if (pnetwork->network.InfrastructureMode != pmlmepriv->cur_network.network.InfrastructureMode)
2343 						continue;
2344 				}
2345 
2346 				if (rtw_set_802_11_infrastructure_mode(padapter, pnetwork->network.InfrastructureMode, 0) == _FALSE) {
2347 					ret = -1;
2348 					_exit_critical_bh(&queue->lock, &irqL);
2349 					goto cancel_ps_deny;
2350 				}
2351 
2352 				break;
2353 			}
2354 		}
2355 		_exit_critical_bh(&queue->lock, &irqL);
2356 		rtw_set_802_11_authentication_mode(padapter, authmode);
2357 		/* set_802_11_encryption_mode(padapter, padapter->securitypriv.ndisencryptstatus); */
2358 		if (rtw_set_802_11_ssid(padapter, &ndis_ssid) == _FALSE) {
2359 			ret = -1;
2360 			goto cancel_ps_deny;
2361 		}
2362 	}
2363 
2364 cancel_ps_deny:
2365 	rtw_ps_deny_cancel(padapter, PS_DENY_JOIN);
2366 
2367 exit:
2368 	RTW_INFO("<=%s, ret %d\n", __FUNCTION__, ret);
2369 
2370 #ifdef DBG_IOCTL
2371 	RTW_INFO("DBG_IOCTL %s:%d return %d\n", __FUNCTION__, __LINE__, ret);
2372 #endif
2373 
2374 
2375 	return ret;
2376 }
2377 
2378 static int rtw_wx_get_essid(struct net_device *dev,
2379 			    struct iw_request_info *a,
2380 			    union iwreq_data *wrqu, char *extra)
2381 {
2382 	u32 len, ret = 0;
2383 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
2384 	struct	mlme_priv	*pmlmepriv = &(padapter->mlmepriv);
2385 	WLAN_BSSID_EX  *pcur_bss = &pmlmepriv->cur_network.network;
2386 
2387 
2388 
2389 	if ((check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE) ||
2390 	    (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE)) {
2391 		len = pcur_bss->Ssid.SsidLength;
2392 
2393 		wrqu->essid.length = len;
2394 
2395 		_rtw_memcpy(extra, pcur_bss->Ssid.Ssid, len);
2396 
2397 		wrqu->essid.flags = 1;
2398 	} else {
2399 		ret = -1;
2400 		goto exit;
2401 	}
2402 
2403 exit:
2404 
2405 
2406 	return ret;
2407 
2408 }
2409 
2410 static int rtw_wx_set_rate(struct net_device *dev,
2411 			   struct iw_request_info *a,
2412 			   union iwreq_data *wrqu, char *extra)
2413 {
2414 	int ret = 0;
2415 #if 0
2416 	int i;
2417 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
2418 	u8	datarates[NumRates];
2419 	u32	target_rate = wrqu->bitrate.value;
2420 	u32	fixed = wrqu->bitrate.fixed;
2421 	u32	ratevalue = 0;
2422 	u8 mpdatarate[NumRates] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0xff};
2423 
2424 
2425 
2426 	if (target_rate == -1) {
2427 		ratevalue = 11;
2428 		goto set_rate;
2429 	}
2430 	target_rate = target_rate / 100000;
2431 
2432 	switch (target_rate) {
2433 	case 10:
2434 		ratevalue = 0;
2435 		break;
2436 	case 20:
2437 		ratevalue = 1;
2438 		break;
2439 	case 55:
2440 		ratevalue = 2;
2441 		break;
2442 	case 60:
2443 		ratevalue = 3;
2444 		break;
2445 	case 90:
2446 		ratevalue = 4;
2447 		break;
2448 	case 110:
2449 		ratevalue = 5;
2450 		break;
2451 	case 120:
2452 		ratevalue = 6;
2453 		break;
2454 	case 180:
2455 		ratevalue = 7;
2456 		break;
2457 	case 240:
2458 		ratevalue = 8;
2459 		break;
2460 	case 360:
2461 		ratevalue = 9;
2462 		break;
2463 	case 480:
2464 		ratevalue = 10;
2465 		break;
2466 	case 540:
2467 		ratevalue = 11;
2468 		break;
2469 	default:
2470 		ratevalue = 11;
2471 		break;
2472 	}
2473 
2474 set_rate:
2475 
2476 	for (i = 0; i < NumRates; i++) {
2477 		if (ratevalue == mpdatarate[i]) {
2478 			datarates[i] = mpdatarate[i];
2479 			if (fixed == 0)
2480 				break;
2481 		} else
2482 			datarates[i] = 0xff;
2483 
2484 	}
2485 
2486 	if (rtw_setdatarate_cmd(padapter, datarates) != _SUCCESS) {
2487 		ret = -1;
2488 	}
2489 
2490 #endif
2491 	return ret;
2492 }
2493 
2494 static int rtw_wx_get_rate(struct net_device *dev,
2495 			   struct iw_request_info *info,
2496 			   union iwreq_data *wrqu, char *extra)
2497 {
2498 	u16 max_rate = 0;
2499 
2500 	max_rate = rtw_get_cur_max_rate((_adapter *)rtw_netdev_priv(dev));
2501 
2502 	if (max_rate == 0)
2503 		return -EPERM;
2504 
2505 	wrqu->bitrate.fixed = 0;	/* no auto select */
2506 	wrqu->bitrate.value = max_rate * 100000;
2507 
2508 	return 0;
2509 }
2510 
2511 static int rtw_wx_set_rts(struct net_device *dev,
2512 			  struct iw_request_info *info,
2513 			  union iwreq_data *wrqu, char *extra)
2514 {
2515 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
2516 
2517 
2518 	if (wrqu->rts.disabled)
2519 		padapter->registrypriv.rts_thresh = 2347;
2520 	else {
2521 		if (wrqu->rts.value < 0 ||
2522 		    wrqu->rts.value > 2347)
2523 			return -EINVAL;
2524 
2525 		padapter->registrypriv.rts_thresh = wrqu->rts.value;
2526 	}
2527 
2528 	RTW_INFO("%s, rts_thresh=%d\n", __func__, padapter->registrypriv.rts_thresh);
2529 
2530 
2531 	return 0;
2532 
2533 }
2534 
2535 static int rtw_wx_get_rts(struct net_device *dev,
2536 			  struct iw_request_info *info,
2537 			  union iwreq_data *wrqu, char *extra)
2538 {
2539 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
2540 
2541 
2542 	RTW_INFO("%s, rts_thresh=%d\n", __func__, padapter->registrypriv.rts_thresh);
2543 
2544 	wrqu->rts.value = padapter->registrypriv.rts_thresh;
2545 	wrqu->rts.fixed = 0;	/* no auto select */
2546 	/* wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); */
2547 
2548 
2549 	return 0;
2550 }
2551 
2552 static int rtw_wx_set_frag(struct net_device *dev,
2553 			   struct iw_request_info *info,
2554 			   union iwreq_data *wrqu, char *extra)
2555 {
2556 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
2557 
2558 
2559 	if (wrqu->frag.disabled)
2560 		padapter->xmitpriv.frag_len = MAX_FRAG_THRESHOLD;
2561 	else {
2562 		if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
2563 		    wrqu->frag.value > MAX_FRAG_THRESHOLD)
2564 			return -EINVAL;
2565 
2566 		padapter->xmitpriv.frag_len = wrqu->frag.value & ~0x1;
2567 	}
2568 
2569 	RTW_INFO("%s, frag_len=%d\n", __func__, padapter->xmitpriv.frag_len);
2570 
2571 
2572 	return 0;
2573 
2574 }
2575 
2576 static int rtw_wx_get_frag(struct net_device *dev,
2577 			   struct iw_request_info *info,
2578 			   union iwreq_data *wrqu, char *extra)
2579 {
2580 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
2581 
2582 
2583 	RTW_INFO("%s, frag_len=%d\n", __func__, padapter->xmitpriv.frag_len);
2584 
2585 	wrqu->frag.value = padapter->xmitpriv.frag_len;
2586 	wrqu->frag.fixed = 0;	/* no auto select */
2587 	/* wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FRAG_THRESHOLD); */
2588 
2589 
2590 	return 0;
2591 }
2592 
2593 static int rtw_wx_get_retry(struct net_device *dev,
2594 			    struct iw_request_info *info,
2595 			    union iwreq_data *wrqu, char *extra)
2596 {
2597 	/* _adapter *padapter = (_adapter *)rtw_netdev_priv(dev); */
2598 
2599 
2600 	wrqu->retry.value = 7;
2601 	wrqu->retry.fixed = 0;	/* no auto select */
2602 	wrqu->retry.disabled = 1;
2603 
2604 	return 0;
2605 
2606 }
2607 
2608 #if 0
2609 	#define IW_ENCODE_INDEX		0x00FF	/* Token index (if needed) */
2610 	#define IW_ENCODE_FLAGS		0xFF00	/* Flags defined below */
2611 	#define IW_ENCODE_MODE		0xF000	/* Modes defined below */
2612 	#define IW_ENCODE_DISABLED	0x8000	/* Encoding disabled */
2613 	#define IW_ENCODE_ENABLED	0x0000	/* Encoding enabled */
2614 	#define IW_ENCODE_RESTRICTED	0x4000	/* Refuse non-encoded packets */
2615 	#define IW_ENCODE_OPEN		0x2000	/* Accept non-encoded packets */
2616 	#define IW_ENCODE_NOKEY		0x0800  /* Key is write only, so not present */
2617 	#define IW_ENCODE_TEMP		0x0400  /* Temporary key */
2618 	/*
2619 	iwconfig wlan0 key on->flags = 0x6001->maybe it means auto
2620 	iwconfig wlan0 key off->flags = 0x8800
2621 	iwconfig wlan0 key open->flags = 0x2800
2622 	iwconfig wlan0 key open 1234567890->flags = 0x2000
2623 	iwconfig wlan0 key restricted->flags = 0x4800
2624 	iwconfig wlan0 key open [3] 1234567890->flags = 0x2003
2625 	iwconfig wlan0 key restricted [2] 1234567890->flags = 0x4002
2626 	iwconfig wlan0 key open [3] -> flags = 0x2803
2627 	iwconfig wlan0 key restricted [2] -> flags = 0x4802
2628 	*/
2629 #endif
2630 
2631 static int rtw_wx_set_enc(struct net_device *dev,
2632 			  struct iw_request_info *info,
2633 			  union iwreq_data *wrqu, char *keybuf)
2634 {
2635 	u32 key, ret = 0;
2636 	u32 keyindex_provided;
2637 	NDIS_802_11_WEP	 wep;
2638 	NDIS_802_11_AUTHENTICATION_MODE authmode;
2639 
2640 	struct iw_point *erq = &(wrqu->encoding);
2641 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
2642 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
2643 	RTW_INFO("+rtw_wx_set_enc, flags=0x%x\n", erq->flags);
2644 
2645 	_rtw_memset(&wep, 0, sizeof(NDIS_802_11_WEP));
2646 
2647 	key = erq->flags & IW_ENCODE_INDEX;
2648 
2649 
2650 	if (erq->flags & IW_ENCODE_DISABLED) {
2651 		RTW_INFO("EncryptionDisabled\n");
2652 		padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
2653 		padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
2654 		padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
2655 		padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
2656 		authmode = Ndis802_11AuthModeOpen;
2657 		padapter->securitypriv.ndisauthtype = authmode;
2658 
2659 		goto exit;
2660 	}
2661 
2662 	if (key) {
2663 		if (key > WEP_KEYS)
2664 			return -EINVAL;
2665 		key--;
2666 		keyindex_provided = 1;
2667 	} else {
2668 		keyindex_provided = 0;
2669 		key = padapter->securitypriv.dot11PrivacyKeyIndex;
2670 		RTW_INFO("rtw_wx_set_enc, key=%d\n", key);
2671 	}
2672 
2673 	/* set authentication mode	 */
2674 	if (erq->flags & IW_ENCODE_OPEN) {
2675 		RTW_INFO("rtw_wx_set_enc():IW_ENCODE_OPEN\n");
2676 		padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;/* Ndis802_11EncryptionDisabled; */
2677 
2678 #ifdef CONFIG_PLATFORM_MT53XX
2679 		padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
2680 #else
2681 		padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
2682 #endif
2683 
2684 		padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
2685 		padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
2686 		authmode = Ndis802_11AuthModeOpen;
2687 		padapter->securitypriv.ndisauthtype = authmode;
2688 	} else if (erq->flags & IW_ENCODE_RESTRICTED) {
2689 		RTW_INFO("rtw_wx_set_enc():IW_ENCODE_RESTRICTED\n");
2690 		padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
2691 
2692 #ifdef CONFIG_PLATFORM_MT53XX
2693 		padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
2694 #else
2695 		padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Shared;
2696 #endif
2697 
2698 		padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
2699 		padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_;
2700 		authmode = Ndis802_11AuthModeShared;
2701 		padapter->securitypriv.ndisauthtype = authmode;
2702 	} else {
2703 		RTW_INFO("rtw_wx_set_enc():erq->flags=0x%x\n", erq->flags);
2704 
2705 		padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;/* Ndis802_11EncryptionDisabled; */
2706 		padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
2707 		padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
2708 		padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
2709 		authmode = Ndis802_11AuthModeOpen;
2710 		padapter->securitypriv.ndisauthtype = authmode;
2711 	}
2712 
2713 	wep.KeyIndex = key;
2714 	if (erq->length > 0) {
2715 		wep.KeyLength = erq->length <= 5 ? 5 : 13;
2716 
2717 		wep.Length = wep.KeyLength + FIELD_OFFSET(NDIS_802_11_WEP, KeyMaterial);
2718 	} else {
2719 		wep.KeyLength = 0 ;
2720 
2721 		if (keyindex_provided == 1) { /* set key_id only, no given KeyMaterial(erq->length==0). */
2722 			padapter->securitypriv.dot11PrivacyKeyIndex = key;
2723 
2724 			RTW_INFO("(keyindex_provided == 1), keyid=%d, key_len=%d\n", key, padapter->securitypriv.dot11DefKeylen[key]);
2725 
2726 			switch (padapter->securitypriv.dot11DefKeylen[key]) {
2727 			case 5:
2728 				padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
2729 				break;
2730 			case 13:
2731 				padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_;
2732 				break;
2733 			default:
2734 				padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
2735 				break;
2736 			}
2737 
2738 			goto exit;
2739 
2740 		}
2741 
2742 	}
2743 
2744 	wep.KeyIndex |= 0x80000000;
2745 
2746 	_rtw_memcpy(wep.KeyMaterial, keybuf, wep.KeyLength);
2747 
2748 	if (rtw_set_802_11_add_wep(padapter, &wep) == _FALSE) {
2749 		if (rf_on == pwrpriv->rf_pwrstate)
2750 			ret = -EOPNOTSUPP;
2751 		goto exit;
2752 	}
2753 
2754 exit:
2755 
2756 
2757 	return ret;
2758 
2759 }
2760 
2761 static int rtw_wx_get_enc(struct net_device *dev,
2762 			  struct iw_request_info *info,
2763 			  union iwreq_data *wrqu, char *keybuf)
2764 {
2765 	uint key, ret = 0;
2766 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
2767 	struct iw_point *erq = &(wrqu->encoding);
2768 	struct	mlme_priv	*pmlmepriv = &(padapter->mlmepriv);
2769 
2770 
2771 	if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) != _TRUE) {
2772 		if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) != _TRUE) {
2773 			erq->length = 0;
2774 			erq->flags |= IW_ENCODE_DISABLED;
2775 			return 0;
2776 		}
2777 	}
2778 
2779 
2780 	key = erq->flags & IW_ENCODE_INDEX;
2781 
2782 	if (key) {
2783 		if (key > WEP_KEYS)
2784 			return -EINVAL;
2785 		key--;
2786 	} else
2787 		key = padapter->securitypriv.dot11PrivacyKeyIndex;
2788 
2789 	erq->flags = key + 1;
2790 
2791 	/* if(padapter->securitypriv.ndisauthtype == Ndis802_11AuthModeOpen) */
2792 	/* { */
2793 	/* erq->flags |= IW_ENCODE_OPEN; */
2794 	/* }	  */
2795 
2796 	switch (padapter->securitypriv.ndisencryptstatus) {
2797 	case Ndis802_11EncryptionNotSupported:
2798 	case Ndis802_11EncryptionDisabled:
2799 
2800 		erq->length = 0;
2801 		erq->flags |= IW_ENCODE_DISABLED;
2802 
2803 		break;
2804 
2805 	case Ndis802_11Encryption1Enabled:
2806 
2807 		erq->length = padapter->securitypriv.dot11DefKeylen[key];
2808 
2809 		if (erq->length) {
2810 			_rtw_memcpy(keybuf, padapter->securitypriv.dot11DefKey[key].skey, padapter->securitypriv.dot11DefKeylen[key]);
2811 
2812 			erq->flags |= IW_ENCODE_ENABLED;
2813 
2814 			if (padapter->securitypriv.ndisauthtype == Ndis802_11AuthModeOpen)
2815 				erq->flags |= IW_ENCODE_OPEN;
2816 			else if (padapter->securitypriv.ndisauthtype == Ndis802_11AuthModeShared)
2817 				erq->flags |= IW_ENCODE_RESTRICTED;
2818 		} else {
2819 			erq->length = 0;
2820 			erq->flags |= IW_ENCODE_DISABLED;
2821 		}
2822 
2823 		break;
2824 
2825 	case Ndis802_11Encryption2Enabled:
2826 	case Ndis802_11Encryption3Enabled:
2827 
2828 		erq->length = 16;
2829 		erq->flags |= (IW_ENCODE_ENABLED | IW_ENCODE_OPEN | IW_ENCODE_NOKEY);
2830 
2831 		break;
2832 
2833 	default:
2834 		erq->length = 0;
2835 		erq->flags |= IW_ENCODE_DISABLED;
2836 
2837 		break;
2838 
2839 	}
2840 
2841 
2842 	return ret;
2843 
2844 }
2845 
2846 static int rtw_wx_get_power(struct net_device *dev,
2847 			    struct iw_request_info *info,
2848 			    union iwreq_data *wrqu, char *extra)
2849 {
2850 	/* _adapter *padapter = (_adapter *)rtw_netdev_priv(dev); */
2851 
2852 	wrqu->power.value = 0;
2853 	wrqu->power.fixed = 0;	/* no auto select */
2854 	wrqu->power.disabled = 1;
2855 
2856 	return 0;
2857 
2858 }
2859 
2860 static int rtw_wx_set_gen_ie(struct net_device *dev,
2861 			     struct iw_request_info *info,
2862 			     union iwreq_data *wrqu, char *extra)
2863 {
2864 	int ret;
2865 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
2866 
2867 	ret = rtw_set_wpa_ie(padapter, extra, wrqu->data.length);
2868 
2869 	return ret;
2870 }
2871 
2872 static int rtw_wx_set_auth(struct net_device *dev,
2873 			   struct iw_request_info *info,
2874 			   union iwreq_data *wrqu, char *extra)
2875 {
2876 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
2877 	struct iw_param *param = (struct iw_param *)&(wrqu->param);
2878 #ifdef CONFIG_WAPI_SUPPORT
2879 #ifndef CONFIG_IOCTL_CFG80211
2880 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
2881 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
2882 	struct security_priv *psecuritypriv = &padapter->securitypriv;
2883 	u32 value = param->value;
2884 #endif
2885 #endif
2886 	int ret = 0;
2887 
2888 	switch (param->flags & IW_AUTH_INDEX) {
2889 
2890 	case IW_AUTH_WPA_VERSION:
2891 #ifdef CONFIG_WAPI_SUPPORT
2892 #ifndef CONFIG_IOCTL_CFG80211
2893 		padapter->wapiInfo.bWapiEnable = false;
2894 		if (value == IW_AUTH_WAPI_VERSION_1) {
2895 			padapter->wapiInfo.bWapiEnable = true;
2896 			psecuritypriv->dot11PrivacyAlgrthm = _SMS4_;
2897 			psecuritypriv->dot118021XGrpPrivacy = _SMS4_;
2898 			psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_WAPI;
2899 			pmlmeinfo->auth_algo = psecuritypriv->dot11AuthAlgrthm;
2900 			padapter->wapiInfo.extra_prefix_len = WAPI_EXT_LEN;
2901 			padapter->wapiInfo.extra_postfix_len = SMS4_MIC_LEN;
2902 		}
2903 #endif
2904 #endif
2905 		break;
2906 	case IW_AUTH_CIPHER_PAIRWISE:
2907 
2908 		break;
2909 	case IW_AUTH_CIPHER_GROUP:
2910 
2911 		break;
2912 	case IW_AUTH_KEY_MGMT:
2913 #ifdef CONFIG_WAPI_SUPPORT
2914 #ifndef CONFIG_IOCTL_CFG80211
2915 		RTW_INFO("rtw_wx_set_auth: IW_AUTH_KEY_MGMT case\n");
2916 		if (value == IW_AUTH_KEY_MGMT_WAPI_PSK)
2917 			padapter->wapiInfo.bWapiPSK = true;
2918 		else
2919 			padapter->wapiInfo.bWapiPSK = false;
2920 		RTW_INFO("rtw_wx_set_auth: IW_AUTH_KEY_MGMT bwapipsk %d\n", padapter->wapiInfo.bWapiPSK);
2921 #endif
2922 #endif
2923 		/*
2924 		 *  ??? does not use these parameters
2925 		 */
2926 		break;
2927 
2928 	case IW_AUTH_TKIP_COUNTERMEASURES: {
2929 		if (param->value) {
2930 			/* wpa_supplicant is enabling the tkip countermeasure. */
2931 			padapter->securitypriv.btkip_countermeasure = _TRUE;
2932 		} else {
2933 			/* wpa_supplicant is disabling the tkip countermeasure. */
2934 			padapter->securitypriv.btkip_countermeasure = _FALSE;
2935 		}
2936 		break;
2937 	}
2938 	case IW_AUTH_DROP_UNENCRYPTED: {
2939 		/* HACK:
2940 		 *
2941 		 * wpa_supplicant calls set_wpa_enabled when the driver
2942 		 * is loaded and unloaded, regardless of if WPA is being
2943 		 * used.  No other calls are made which can be used to
2944 		 * determine if encryption will be used or not prior to
2945 		 * association being expected.  If encryption is not being
2946 		 * used, drop_unencrypted is set to false, else true -- we
2947 		 * can use this to determine if the CAP_PRIVACY_ON bit should
2948 		 * be set.
2949 		 */
2950 
2951 		if (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption1Enabled) {
2952 			break;/* it means init value, or using wep, ndisencryptstatus = Ndis802_11Encryption1Enabled, */
2953 			/* then it needn't reset it; */
2954 		}
2955 
2956 		if (param->value) {
2957 			padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
2958 			padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
2959 			padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
2960 			padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
2961 			padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
2962 		}
2963 
2964 		break;
2965 	}
2966 
2967 	case IW_AUTH_80211_AUTH_ALG:
2968 
2969 #if defined(CONFIG_RTW_ANDROID) || 1
2970 		/*
2971 		 *  It's the starting point of a link layer connection using wpa_supplicant
2972 		*/
2973 		if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE)) {
2974 			LeaveAllPowerSaveMode(padapter);
2975 			rtw_disassoc_cmd(padapter, 500, RTW_CMDF_WAIT_ACK);
2976 			RTW_INFO("%s...call rtw_indicate_disconnect\n ", __FUNCTION__);
2977 			rtw_indicate_disconnect(padapter, 0, _FALSE);
2978 			rtw_free_assoc_resources_cmd(padapter, _TRUE, RTW_CMDF_WAIT_ACK);
2979 		}
2980 #endif
2981 
2982 
2983 		ret = wpa_set_auth_algs(dev, (u32)param->value);
2984 
2985 		break;
2986 
2987 	case IW_AUTH_WPA_ENABLED:
2988 
2989 		/* if(param->value) */
2990 		/* padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; */ /* 802.1x */
2991 		/* else */
2992 		/* padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; */ /* open system */
2993 
2994 		/* _disassociate(priv); */
2995 
2996 		break;
2997 
2998 	case IW_AUTH_RX_UNENCRYPTED_EAPOL:
2999 		/* ieee->ieee802_1x = param->value; */
3000 		break;
3001 
3002 	case IW_AUTH_PRIVACY_INVOKED:
3003 		/* ieee->privacy_invoked = param->value; */
3004 		break;
3005 
3006 #ifdef CONFIG_WAPI_SUPPORT
3007 #ifndef CONFIG_IOCTL_CFG80211
3008 	case IW_AUTH_WAPI_ENABLED:
3009 		break;
3010 #endif
3011 #endif
3012 
3013 	default:
3014 		return -EOPNOTSUPP;
3015 
3016 	}
3017 
3018 	return ret;
3019 
3020 }
3021 
3022 static int rtw_wx_set_enc_ext(struct net_device *dev,
3023 			      struct iw_request_info *info,
3024 			      union iwreq_data *wrqu, char *extra)
3025 {
3026 	char *alg_name;
3027 	u32 param_len;
3028 	struct ieee_param *param = NULL;
3029 	struct iw_point *pencoding = &wrqu->encoding;
3030 	struct iw_encode_ext *pext = (struct iw_encode_ext *)extra;
3031 	int ret = 0;
3032 
3033 	param_len = sizeof(struct ieee_param) + pext->key_len;
3034 	param = (struct ieee_param *)rtw_malloc(param_len);
3035 	if (param == NULL)
3036 		return -1;
3037 
3038 	_rtw_memset(param, 0, param_len);
3039 
3040 	param->cmd = IEEE_CMD_SET_ENCRYPTION;
3041 	_rtw_memset(param->sta_addr, 0xff, ETH_ALEN);
3042 
3043 
3044 	switch (pext->alg) {
3045 	case IW_ENCODE_ALG_NONE:
3046 		/* todo: remove key */
3047 		/* remove = 1;	 */
3048 		alg_name = "none";
3049 		break;
3050 	case IW_ENCODE_ALG_WEP:
3051 		alg_name = "WEP";
3052 		break;
3053 	case IW_ENCODE_ALG_TKIP:
3054 		alg_name = "TKIP";
3055 		break;
3056 	case IW_ENCODE_ALG_CCMP:
3057 		alg_name = "CCMP";
3058 		break;
3059 #ifdef CONFIG_IEEE80211W
3060 	case IW_ENCODE_ALG_AES_CMAC:
3061 		alg_name = "BIP";
3062 		break;
3063 #endif /* CONFIG_IEEE80211W */
3064 #ifdef CONFIG_WAPI_SUPPORT
3065 #ifndef CONFIG_IOCTL_CFG80211
3066 	case IW_ENCODE_ALG_SM4:
3067 		alg_name = "SMS4";
3068 		_rtw_memcpy(param->sta_addr, pext->addr.sa_data, ETH_ALEN);
3069 		RTW_INFO("rtw_wx_set_enc_ext: SMS4 case\n");
3070 		break;
3071 #endif
3072 #endif
3073 	default:
3074 		ret = -1;
3075 		goto exit;
3076 	}
3077 
3078 	strncpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN);
3079 
3080 	if (pext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
3081 		param->u.crypt.set_tx = 1;
3082 
3083 	/* cliW: WEP does not have group key
3084 	 * just not checking GROUP key setting
3085 	 */
3086 	if ((pext->alg != IW_ENCODE_ALG_WEP) &&
3087 	    ((pext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
3088 #ifdef CONFIG_IEEE80211W
3089 	     || (pext->ext_flags & IW_ENCODE_ALG_AES_CMAC)
3090 #endif /* CONFIG_IEEE80211W */
3091 	    ))
3092 		param->u.crypt.set_tx = 0;
3093 
3094 	param->u.crypt.idx = (pencoding->flags & 0x00FF) - 1 ;
3095 
3096 	if (pext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
3097 #ifdef CONFIG_WAPI_SUPPORT
3098 #ifndef CONFIG_IOCTL_CFG80211
3099 		if (pext->alg == IW_ENCODE_ALG_SM4)
3100 			_rtw_memcpy(param->u.crypt.seq, pext->rx_seq, 16);
3101 		else
3102 #endif /* CONFIG_IOCTL_CFG80211 */
3103 #endif /* CONFIG_WAPI_SUPPORT */
3104 			_rtw_memcpy(param->u.crypt.seq, pext->rx_seq, 8);
3105 	}
3106 
3107 	if (pext->key_len) {
3108 		param->u.crypt.key_len = pext->key_len;
3109 		/* _rtw_memcpy(param + 1, pext + 1, pext->key_len); */
3110 		_rtw_memcpy(param->u.crypt.key, pext + 1, pext->key_len);
3111 	}
3112 
3113 	if (pencoding->flags & IW_ENCODE_DISABLED) {
3114 		/* todo: remove key */
3115 		/* remove = 1; */
3116 	}
3117 
3118 	ret =  wpa_set_encryption(dev, param, param_len);
3119 
3120 exit:
3121 	if (param)
3122 		rtw_mfree((u8 *)param, param_len);
3123 
3124 	return ret;
3125 }
3126 
3127 
3128 static int rtw_wx_get_nick(struct net_device *dev,
3129 			   struct iw_request_info *info,
3130 			   union iwreq_data *wrqu, char *extra)
3131 {
3132 	/* _adapter *padapter = (_adapter *)rtw_netdev_priv(dev); */
3133 	/* struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); */
3134 	/* struct security_priv *psecuritypriv = &padapter->securitypriv; */
3135 
3136 	if (extra) {
3137 		wrqu->data.length = 14;
3138 		wrqu->data.flags = 1;
3139 		_rtw_memcpy(extra, "<WIFI@REALTEK>", 14);
3140 	}
3141 
3142 	/* rtw_signal_process(pid, SIGUSR1); */ /* for test */
3143 
3144 	/* dump debug info here	 */
3145 #if 0
3146 	u32 dot11AuthAlgrthm;		/*  802.11 auth, could be open, shared, and 8021x */
3147 	u32 dot11PrivacyAlgrthm;	/*  This specify the privacy for shared auth. algorithm. */
3148 	u32 dot118021XGrpPrivacy;	/*  This specify the privacy algthm. used for Grp key */
3149 	u32 ndisauthtype;
3150 	u32 ndisencryptstatus;
3151 #endif
3152 
3153 	/* RTW_INFO("auth_alg=0x%x, enc_alg=0x%x, auth_type=0x%x, enc_type=0x%x\n",  */
3154 	/*		psecuritypriv->dot11AuthAlgrthm, psecuritypriv->dot11PrivacyAlgrthm, */
3155 	/*		psecuritypriv->ndisauthtype, psecuritypriv->ndisencryptstatus); */
3156 
3157 	/* RTW_INFO("enc_alg=0x%x\n", psecuritypriv->dot11PrivacyAlgrthm); */
3158 	/* RTW_INFO("auth_type=0x%x\n", psecuritypriv->ndisauthtype); */
3159 	/* RTW_INFO("enc_type=0x%x\n", psecuritypriv->ndisencryptstatus); */
3160 
3161 #if 0
3162 	RTW_INFO("dbg(0x210)=0x%x\n", rtw_read32(padapter, 0x210));
3163 	RTW_INFO("dbg(0x608)=0x%x\n", rtw_read32(padapter, 0x608));
3164 	RTW_INFO("dbg(0x280)=0x%x\n", rtw_read32(padapter, 0x280));
3165 	RTW_INFO("dbg(0x284)=0x%x\n", rtw_read32(padapter, 0x284));
3166 	RTW_INFO("dbg(0x288)=0x%x\n", rtw_read32(padapter, 0x288));
3167 
3168 	RTW_INFO("dbg(0x664)=0x%x\n", rtw_read32(padapter, 0x664));
3169 
3170 
3171 	RTW_INFO("\n");
3172 
3173 	RTW_INFO("dbg(0x430)=0x%x\n", rtw_read32(padapter, 0x430));
3174 	RTW_INFO("dbg(0x438)=0x%x\n", rtw_read32(padapter, 0x438));
3175 
3176 	RTW_INFO("dbg(0x440)=0x%x\n", rtw_read32(padapter, 0x440));
3177 
3178 	RTW_INFO("dbg(0x458)=0x%x\n", rtw_read32(padapter, 0x458));
3179 
3180 	RTW_INFO("dbg(0x484)=0x%x\n", rtw_read32(padapter, 0x484));
3181 	RTW_INFO("dbg(0x488)=0x%x\n", rtw_read32(padapter, 0x488));
3182 
3183 	RTW_INFO("dbg(0x444)=0x%x\n", rtw_read32(padapter, 0x444));
3184 	RTW_INFO("dbg(0x448)=0x%x\n", rtw_read32(padapter, 0x448));
3185 	RTW_INFO("dbg(0x44c)=0x%x\n", rtw_read32(padapter, 0x44c));
3186 	RTW_INFO("dbg(0x450)=0x%x\n", rtw_read32(padapter, 0x450));
3187 #endif
3188 
3189 	return 0;
3190 
3191 }
3192 #endif
3193 
3194 static int rtw_wx_read32(struct net_device *dev,
3195 			 struct iw_request_info *info,
3196 			 union iwreq_data *wrqu, char *extra)
3197 {
3198 	PADAPTER padapter;
3199 	struct iw_point *p;
3200 	u16 len;
3201 	u32 addr;
3202 	u32 data32;
3203 	u32 bytes;
3204 	u8 *ptmp;
3205 	int ret;
3206 
3207 
3208 	ret = 0;
3209 	padapter = (PADAPTER)rtw_netdev_priv(dev);
3210 	p = &wrqu->data;
3211 	len = p->length;
3212 	if (0 == len)
3213 		return -EINVAL;
3214 
3215 	ptmp = (u8 *)rtw_malloc(len);
3216 	if (NULL == ptmp)
3217 		return -ENOMEM;
3218 
3219 	if (copy_from_user(ptmp, p->pointer, len)) {
3220 		ret = -EFAULT;
3221 		goto exit;
3222 	}
3223 
3224 	bytes = 0;
3225 	addr = 0;
3226 	sscanf(ptmp, "%d,%x", &bytes, &addr);
3227 
3228 	switch (bytes) {
3229 	case 1:
3230 		data32 = rtw_read8(padapter, addr);
3231 		sprintf(extra, "0x%02X", data32);
3232 		break;
3233 	case 2:
3234 		data32 = rtw_read16(padapter, addr);
3235 		sprintf(extra, "0x%04X", data32);
3236 		break;
3237 	case 4:
3238 		data32 = rtw_read32(padapter, addr);
3239 		sprintf(extra, "0x%08X", data32);
3240 		break;
3241 
3242 	#if defined(CONFIG_SDIO_HCI) && defined(CONFIG_SDIO_INDIRECT_ACCESS) && defined(DBG_SDIO_INDIRECT_ACCESS)
3243 	case 11:
3244 		data32 = rtw_sd_iread8(padapter, addr);
3245 		sprintf(extra, "0x%02X", data32);
3246 		break;
3247 	case 12:
3248 		data32 = rtw_sd_iread16(padapter, addr);
3249 		sprintf(extra, "0x%04X", data32);
3250 		break;
3251 	case 14:
3252 		data32 = rtw_sd_iread32(padapter, addr);
3253 		sprintf(extra, "0x%08X", data32);
3254 		break;
3255 	#endif
3256 	default:
3257 		RTW_INFO("%s: usage> read [bytes],[address(hex)]\n", __func__);
3258 		ret = -EINVAL;
3259 		goto exit;
3260 	}
3261 	RTW_INFO("%s: addr=0x%08X data=%s\n", __func__, addr, extra);
3262 
3263 exit:
3264 	rtw_mfree(ptmp, len);
3265 
3266 	return 0;
3267 }
3268 
3269 static int rtw_wx_write32(struct net_device *dev,
3270 			  struct iw_request_info *info,
3271 			  union iwreq_data *wrqu, char *extra)
3272 {
3273 	PADAPTER padapter = (PADAPTER)rtw_netdev_priv(dev);
3274 
3275 	u32 addr;
3276 	u32 data32;
3277 	u32 bytes;
3278 
3279 
3280 	bytes = 0;
3281 	addr = 0;
3282 	data32 = 0;
3283 	sscanf(extra, "%d,%x,%x", &bytes, &addr, &data32);
3284 
3285 	switch (bytes) {
3286 	case 1:
3287 		rtw_write8(padapter, addr, (u8)data32);
3288 		RTW_INFO("%s: addr=0x%08X data=0x%02X\n", __func__, addr, (u8)data32);
3289 		break;
3290 	case 2:
3291 		rtw_write16(padapter, addr, (u16)data32);
3292 		RTW_INFO("%s: addr=0x%08X data=0x%04X\n", __func__, addr, (u16)data32);
3293 		break;
3294 	case 4:
3295 		rtw_write32(padapter, addr, data32);
3296 		RTW_INFO("%s: addr=0x%08X data=0x%08X\n", __func__, addr, data32);
3297 		break;
3298 	default:
3299 		RTW_INFO("%s: usage> write [bytes],[address(hex)],[data(hex)]\n", __func__);
3300 		return -EINVAL;
3301 	}
3302 
3303 	return 0;
3304 }
3305 
3306 static int rtw_wx_read_rf(struct net_device *dev,
3307 			  struct iw_request_info *info,
3308 			  union iwreq_data *wrqu, char *extra)
3309 {
3310 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
3311 	u32 path, addr, data32;
3312 
3313 
3314 	path = *(u32 *)extra;
3315 	addr = *((u32 *)extra + 1);
3316 	data32 = rtw_hal_read_rfreg(padapter, path, addr, 0xFFFFF);
3317 	/*	RTW_INFO("%s: path=%d addr=0x%02x data=0x%05x\n", __func__, path, addr, data32); */
3318 	/*
3319 	 * IMPORTANT!!
3320 	 * Only when wireless private ioctl is at odd order,
3321 	 * "extra" would be copied to user space.
3322 	 */
3323 	sprintf(extra, "0x%05x", data32);
3324 
3325 	return 0;
3326 }
3327 
3328 static int rtw_wx_write_rf(struct net_device *dev,
3329 			   struct iw_request_info *info,
3330 			   union iwreq_data *wrqu, char *extra)
3331 {
3332 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
3333 	u32 path, addr, data32;
3334 
3335 
3336 	path = *(u32 *)extra;
3337 	addr = *((u32 *)extra + 1);
3338 	data32 = *((u32 *)extra + 2);
3339 	/*	RTW_INFO("%s: path=%d addr=0x%02x data=0x%05x\n", __func__, path, addr, data32); */
3340 	rtw_hal_write_rfreg(padapter, path, addr, 0xFFFFF, data32);
3341 
3342 	return 0;
3343 }
3344 
3345 static int rtw_wx_priv_null(struct net_device *dev, struct iw_request_info *a,
3346 			    union iwreq_data *wrqu, char *b)
3347 {
3348 	return -1;
3349 }
3350 
3351 #ifdef CONFIG_RTW_80211K
3352 extern void rm_dbg_cmd(_adapter *padapter, char *s);
3353 static int rtw_wx_priv_rrm(struct net_device *dev, struct iw_request_info *a,
3354 			    union iwreq_data *wrqu, char *b)
3355 {
3356 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
3357 	u32 path, addr, data32;
3358 
3359 
3360 	rm_dbg_cmd(padapter, b);
3361 	wrqu->data.length = strlen(b);
3362 
3363 	return 0;
3364 }
3365 #endif
3366 
3367 #ifdef CONFIG_IOCTL_WEXT
3368 static int dummy(struct net_device *dev, struct iw_request_info *a,
3369 		 union iwreq_data *wrqu, char *b)
3370 {
3371 	/* _adapter *padapter = (_adapter *)rtw_netdev_priv(dev);	 */
3372 	/* struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); */
3373 
3374 	/* RTW_INFO("cmd_code=%x, fwstate=0x%x\n", a->cmd, get_fwstate(pmlmepriv)); */
3375 
3376 	return -1;
3377 
3378 }
3379 #endif
3380 
3381 static int rtw_wx_set_channel_plan(struct net_device *dev,
3382 				   struct iw_request_info *info,
3383 				   union iwreq_data *wrqu, char *extra)
3384 {
3385 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
3386 	u16 channel_plan_req = (u16)(*((int *)wrqu));
3387 
3388 	rtw_chplan_ioctl_input_mapping(&channel_plan_req, NULL);
3389 
3390 	if (_SUCCESS != rtw_set_channel_plan(padapter, channel_plan_req, RTW_CHPLAN_6G_UNSPECIFIED, RTW_REGD_SET_BY_USER))
3391 		return -EPERM;
3392 
3393 	return 0;
3394 }
3395 
3396 static int rtw_wx_set_mtk_wps_probe_ie(struct net_device *dev,
3397 				       struct iw_request_info *a,
3398 				       union iwreq_data *wrqu, char *b)
3399 {
3400 #ifdef CONFIG_PLATFORM_MT53XX
3401 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
3402 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
3403 
3404 #endif
3405 	return 0;
3406 }
3407 
3408 static int rtw_wx_get_sensitivity(struct net_device *dev,
3409 				  struct iw_request_info *info,
3410 				  union iwreq_data *wrqu, char *buf)
3411 {
3412 #ifdef CONFIG_PLATFORM_MT53XX
3413 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
3414 
3415 	/*	Modified by Albert 20110914 */
3416 	/*	This is in dbm format for MTK platform. */
3417 	wrqu->qual.level = padapter->recvpriv.rssi;
3418 	RTW_INFO(" level = %u\n",  wrqu->qual.level);
3419 #endif
3420 	return 0;
3421 }
3422 
3423 static int rtw_wx_set_mtk_wps_ie(struct net_device *dev,
3424 				 struct iw_request_info *info,
3425 				 union iwreq_data *wrqu, char *extra)
3426 {
3427 #ifdef CONFIG_PLATFORM_MT53XX
3428 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
3429 
3430 	return rtw_set_wpa_ie(padapter, wrqu->data.pointer, wrqu->data.length);
3431 #else
3432 	return 0;
3433 #endif
3434 }
3435 
3436 #ifdef MP_IOCTL_HDL
3437 static void rtw_dbg_mode_hdl(_adapter *padapter, u32 id, u8 *pdata, u32 len)
3438 {
3439 	pRW_Reg	RegRWStruct;
3440 	struct rf_reg_param *prfreg;
3441 	u8 path;
3442 	u8 offset;
3443 	u32 value;
3444 
3445 	RTW_INFO("%s\n", __FUNCTION__);
3446 
3447 	switch (id) {
3448 	case GEN_MP_IOCTL_SUBCODE(MP_START):
3449 		RTW_INFO("871x_driver is only for normal mode, can't enter mp mode\n");
3450 		break;
3451 	case GEN_MP_IOCTL_SUBCODE(READ_REG):
3452 		RegRWStruct = (pRW_Reg)pdata;
3453 		switch (RegRWStruct->width) {
3454 		case 1:
3455 			RegRWStruct->value = rtw_read8(padapter, RegRWStruct->offset);
3456 			break;
3457 		case 2:
3458 			RegRWStruct->value = rtw_read16(padapter, RegRWStruct->offset);
3459 			break;
3460 		case 4:
3461 			RegRWStruct->value = rtw_read32(padapter, RegRWStruct->offset);
3462 			break;
3463 		default:
3464 			break;
3465 		}
3466 
3467 		break;
3468 	case GEN_MP_IOCTL_SUBCODE(WRITE_REG):
3469 		RegRWStruct = (pRW_Reg)pdata;
3470 		switch (RegRWStruct->width) {
3471 		case 1:
3472 			rtw_write8(padapter, RegRWStruct->offset, (u8)RegRWStruct->value);
3473 			break;
3474 		case 2:
3475 			rtw_write16(padapter, RegRWStruct->offset, (u16)RegRWStruct->value);
3476 			break;
3477 		case 4:
3478 			rtw_write32(padapter, RegRWStruct->offset, (u32)RegRWStruct->value);
3479 			break;
3480 		default:
3481 			break;
3482 		}
3483 
3484 		break;
3485 	case GEN_MP_IOCTL_SUBCODE(READ_RF_REG):
3486 
3487 		prfreg = (struct rf_reg_param *)pdata;
3488 
3489 		path = (u8)prfreg->path;
3490 		offset = (u8)prfreg->offset;
3491 
3492 		value = rtw_hal_read_rfreg(padapter, path, offset, 0xffffffff);
3493 
3494 		prfreg->value = value;
3495 
3496 		break;
3497 	case GEN_MP_IOCTL_SUBCODE(WRITE_RF_REG):
3498 
3499 		prfreg = (struct rf_reg_param *)pdata;
3500 
3501 		path = (u8)prfreg->path;
3502 		offset = (u8)prfreg->offset;
3503 		value = prfreg->value;
3504 
3505 		rtw_hal_write_rfreg(padapter, path, offset, 0xffffffff, value);
3506 
3507 		break;
3508 	case GEN_MP_IOCTL_SUBCODE(TRIGGER_GPIO):
3509 		RTW_INFO("==> trigger gpio 0\n");
3510 		rtw_hal_set_hwreg(padapter, HW_VAR_TRIGGER_GPIO_0, 0);
3511 		break;
3512 #ifdef CONFIG_BT_COEXIST
3513 	case GEN_MP_IOCTL_SUBCODE(SET_DM_BT):
3514 		RTW_INFO("==> set dm_bt_coexist:%x\n", *(u8 *)pdata);
3515 		rtw_hal_set_hwreg(padapter, HW_VAR_BT_SET_COEXIST, pdata);
3516 		break;
3517 	case GEN_MP_IOCTL_SUBCODE(DEL_BA):
3518 		RTW_INFO("==> delete ba:%x\n", *(u8 *)pdata);
3519 		rtw_hal_set_hwreg(padapter, HW_VAR_BT_ISSUE_DELBA, pdata);
3520 		break;
3521 #endif
3522 #ifdef DBG_CONFIG_ERROR_DETECT
3523 	case GEN_MP_IOCTL_SUBCODE(GET_WIFI_STATUS):
3524 		*pdata = rtw_hal_sreset_get_wifi_status(padapter);
3525 		break;
3526 #endif
3527 
3528 	default:
3529 		break;
3530 	}
3531 
3532 }
3533 static int rtw_mp_ioctl_hdl(struct net_device *dev, struct iw_request_info *info,
3534 			    union iwreq_data *wrqu, char *extra)
3535 {
3536 	int ret = 0;
3537 	u32 BytesRead, BytesWritten, BytesNeeded;
3538 	struct oid_par_priv	oid_par;
3539 	struct mp_ioctl_handler	*phandler;
3540 	struct mp_ioctl_param	*poidparam;
3541 	uint status = 0;
3542 	u16 len;
3543 	u8 *pparmbuf = NULL, bset;
3544 	PADAPTER padapter = (PADAPTER)rtw_netdev_priv(dev);
3545 	struct iw_point *p = &wrqu->data;
3546 
3547 	/* RTW_INFO("+rtw_mp_ioctl_hdl\n"); */
3548 
3549 	/* mutex_lock(&ioctl_mutex); */
3550 
3551 	if ((!p->length) || (!p->pointer)) {
3552 		ret = -EINVAL;
3553 		goto _rtw_mp_ioctl_hdl_exit;
3554 	}
3555 
3556 	pparmbuf = NULL;
3557 	bset = (u8)(p->flags & 0xFFFF);
3558 	len = p->length;
3559 	pparmbuf = (u8 *)rtw_malloc(len);
3560 	if (pparmbuf == NULL) {
3561 		ret = -ENOMEM;
3562 		goto _rtw_mp_ioctl_hdl_exit;
3563 	}
3564 
3565 	if (copy_from_user(pparmbuf, p->pointer, len)) {
3566 		ret = -EFAULT;
3567 		goto _rtw_mp_ioctl_hdl_exit;
3568 	}
3569 
3570 	poidparam = (struct mp_ioctl_param *)pparmbuf;
3571 
3572 	if (poidparam->subcode >= MAX_MP_IOCTL_SUBCODE) {
3573 		ret = -EINVAL;
3574 		goto _rtw_mp_ioctl_hdl_exit;
3575 	}
3576 
3577 	/* RTW_INFO("%s: %d\n", __func__, poidparam->subcode); */
3578 #ifdef CONFIG_MP_INCLUDED
3579 	if (padapter->registrypriv.mp_mode == 1) {
3580 		phandler = mp_ioctl_hdl + poidparam->subcode;
3581 
3582 		if ((phandler->paramsize != 0) && (poidparam->len < phandler->paramsize)) {
3583 			ret = -EINVAL;
3584 			goto _rtw_mp_ioctl_hdl_exit;
3585 		}
3586 
3587 		if (phandler->handler) {
3588 			oid_par.adapter_context = padapter;
3589 			oid_par.oid = phandler->oid;
3590 			oid_par.information_buf = poidparam->data;
3591 			oid_par.information_buf_len = poidparam->len;
3592 			oid_par.dbg = 0;
3593 
3594 			BytesWritten = 0;
3595 			BytesNeeded = 0;
3596 
3597 			if (bset) {
3598 				oid_par.bytes_rw = &BytesRead;
3599 				oid_par.bytes_needed = &BytesNeeded;
3600 				oid_par.type_of_oid = SET_OID;
3601 			} else {
3602 				oid_par.bytes_rw = &BytesWritten;
3603 				oid_par.bytes_needed = &BytesNeeded;
3604 				oid_par.type_of_oid = QUERY_OID;
3605 			}
3606 
3607 			status = phandler->handler(&oid_par);
3608 
3609 			/* todo:check status, BytesNeeded, etc. */
3610 		} else {
3611 			RTW_INFO("rtw_mp_ioctl_hdl(): err!, subcode=%d, oid=%d, handler=%p\n",
3612 				poidparam->subcode, phandler->oid, phandler->handler);
3613 			ret = -EFAULT;
3614 			goto _rtw_mp_ioctl_hdl_exit;
3615 		}
3616 	} else
3617 #endif
3618 	{
3619 		rtw_dbg_mode_hdl(padapter, poidparam->subcode, poidparam->data, poidparam->len);
3620 	}
3621 
3622 	if (bset == 0x00) {/* query info */
3623 		if (copy_to_user(p->pointer, pparmbuf, len))
3624 			ret = -EFAULT;
3625 	}
3626 
3627 	if (status) {
3628 		ret = -EFAULT;
3629 		goto _rtw_mp_ioctl_hdl_exit;
3630 	}
3631 
3632 _rtw_mp_ioctl_hdl_exit:
3633 
3634 	if (pparmbuf)
3635 		rtw_mfree(pparmbuf, len);
3636 
3637 	/* mutex_unlock(&ioctl_mutex); */
3638 
3639 	return ret;
3640 }
3641 #endif /*MP_IOCTL_HDL*/
3642 static int rtw_get_ap_info(struct net_device *dev,
3643 			   struct iw_request_info *info,
3644 			   union iwreq_data *wrqu, char *extra)
3645 {
3646 	int ret = 0;
3647 	u32 cnt = 0, wpa_ielen;
3648 	_irqL	irqL;
3649 	_list	*plist, *phead;
3650 	unsigned char *pbuf;
3651 	u8 bssid[ETH_ALEN];
3652 	char data[32];
3653 	struct wlan_network *pnetwork = NULL;
3654 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
3655 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3656 	_queue *queue = &(pmlmepriv->scanned_queue);
3657 	struct iw_point *pdata = &wrqu->data;
3658 
3659 	RTW_INFO("+rtw_get_aplist_info\n");
3660 
3661 	if (rtw_is_drv_stopped(padapter) || (pdata == NULL)) {
3662 		ret = -EINVAL;
3663 		goto exit;
3664 	}
3665 
3666 	while ((check_fwstate(pmlmepriv, (WIFI_UNDER_SURVEY | WIFI_UNDER_LINKING))) == _TRUE) {
3667 		rtw_msleep_os(30);
3668 		cnt++;
3669 		if (cnt > 100)
3670 			break;
3671 	}
3672 
3673 
3674 	/* pdata->length = 0; */ /* ?	 */
3675 	pdata->flags = 0;
3676 	if (pdata->length >= 32) {
3677 		if (copy_from_user(data, pdata->pointer, 32)) {
3678 			ret = -EINVAL;
3679 			goto exit;
3680 		}
3681 	} else {
3682 		ret = -EINVAL;
3683 		goto exit;
3684 	}
3685 
3686 	_enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
3687 
3688 	phead = get_list_head(queue);
3689 	plist = get_next(phead);
3690 
3691 	while (1) {
3692 		if (rtw_end_of_queue_search(phead, plist) == _TRUE)
3693 			break;
3694 
3695 
3696 		pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
3697 
3698 		if (hwaddr_aton_i(data, bssid)) {
3699 			RTW_INFO("Invalid BSSID '%s'.\n", (u8 *)data);
3700 			_exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
3701 			return -EINVAL;
3702 		}
3703 
3704 
3705 		if (_rtw_memcmp(bssid, pnetwork->network.MacAddress, ETH_ALEN) == _TRUE) { /* BSSID match, then check if supporting wpa/wpa2 */
3706 			RTW_INFO("BSSID:" MAC_FMT "\n", MAC_ARG(bssid));
3707 
3708 			pbuf = rtw_get_wpa_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
3709 			if (pbuf && (wpa_ielen > 0)) {
3710 				pdata->flags = 1;
3711 				break;
3712 			}
3713 
3714 			pbuf = rtw_get_wpa2_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
3715 			if (pbuf && (wpa_ielen > 0)) {
3716 				pdata->flags = 2;
3717 				break;
3718 			}
3719 
3720 		}
3721 
3722 		plist = get_next(plist);
3723 
3724 	}
3725 
3726 	_exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
3727 
3728 	if (pdata->length >= 34) {
3729 		if (copy_to_user((u8 *)pdata->pointer + 32, (u8 *)&pdata->flags, 1)) {
3730 			ret = -EINVAL;
3731 			goto exit;
3732 		}
3733 	}
3734 
3735 exit:
3736 
3737 	return ret;
3738 
3739 }
3740 
3741 static int rtw_set_pid(struct net_device *dev,
3742 		       struct iw_request_info *info,
3743 		       union iwreq_data *wrqu, char *extra)
3744 {
3745 
3746 	int ret = 0;
3747 	_adapter *padapter = rtw_netdev_priv(dev);
3748 	int *pdata = (int *)wrqu;
3749 	int selector;
3750 
3751 	if (rtw_is_drv_stopped(padapter) || (pdata == NULL)) {
3752 		ret = -EINVAL;
3753 		goto exit;
3754 	}
3755 
3756 	selector = *pdata;
3757 	if (selector < 3 && selector >= 0) {
3758 		padapter->pid[selector] = *(pdata + 1);
3759 #ifdef CONFIG_GLOBAL_UI_PID
3760 		ui_pid[selector] = *(pdata + 1);
3761 #endif
3762 		RTW_INFO("%s set pid[%d]=%d\n", __FUNCTION__, selector , padapter->pid[selector]);
3763 	} else
3764 		RTW_INFO("%s selector %d error\n", __FUNCTION__, selector);
3765 
3766 exit:
3767 
3768 	return ret;
3769 
3770 }
3771 
3772 static int rtw_wps_start(struct net_device *dev,
3773 			 struct iw_request_info *info,
3774 			 union iwreq_data *wrqu, char *extra)
3775 {
3776 
3777 	int ret = 0;
3778 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
3779 	struct iw_point *pdata = &wrqu->data;
3780 	u32   u32wps_start = 0;
3781 	unsigned int uintRet = 0;
3782 
3783 	if (RTW_CANNOT_RUN(padapter) || (NULL == pdata)) {
3784 		ret = -EINVAL;
3785 		goto exit;
3786 	}
3787 
3788 	uintRet = copy_from_user((void *) &u32wps_start, pdata->pointer, 4);
3789 	if (u32wps_start == 0)
3790 		u32wps_start = *extra;
3791 
3792 	RTW_INFO("[%s] wps_start = %d\n", __FUNCTION__, u32wps_start);
3793 
3794 	if (u32wps_start == 1)   /* WPS Start */
3795 		rtw_led_control(padapter, LED_CTL_START_WPS);
3796 	else if (u32wps_start == 2)   /* WPS Stop because of wps success */
3797 		rtw_led_control(padapter, LED_CTL_STOP_WPS);
3798 	else if (u32wps_start == 3)   /* WPS Stop because of wps fail */
3799 		rtw_led_control(padapter, LED_CTL_STOP_WPS_FAIL);
3800 
3801 exit:
3802 
3803 	return ret;
3804 
3805 }
3806 
3807 #ifdef CONFIG_P2P
3808 static int rtw_wext_p2p_enable(struct net_device *dev,
3809 			       struct iw_request_info *info,
3810 			       union iwreq_data *wrqu, char *extra)
3811 {
3812 
3813 	int ret = 0;
3814 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
3815 	struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
3816 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
3817 	enum P2P_ROLE init_role = P2P_ROLE_DISABLE;
3818 #ifdef CONFIG_CONCURRENT_MODE
3819 	struct roch_info *prochinfo = &padapter->rochinfo;
3820 #endif
3821 
3822 	if (*extra == '0')
3823 		init_role = P2P_ROLE_DISABLE;
3824 	else if (*extra == '1')
3825 		init_role = P2P_ROLE_DEVICE;
3826 	else if (*extra == '2')
3827 		init_role = P2P_ROLE_CLIENT;
3828 	else if (*extra == '3')
3829 		init_role = P2P_ROLE_GO;
3830 
3831 	if (_FAIL == rtw_p2p_enable(padapter, init_role)) {
3832 		ret = -EFAULT;
3833 		goto exit;
3834 	}
3835 
3836 	/* set channel/bandwidth */
3837 	if (init_role != P2P_ROLE_DISABLE) {
3838 		u8 channel, ch_offset;
3839 		u16 bwmode;
3840 
3841 		if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_LISTEN)) {
3842 			/*	Stay at the listen state and wait for discovery. */
3843 			channel = pwdinfo->listen_channel;
3844 			pwdinfo->operating_channel = pwdinfo->listen_channel;
3845 			ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
3846 			bwmode = CHANNEL_WIDTH_20;
3847 		}
3848 #ifdef CONFIG_CONCURRENT_MODE
3849 		else if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE)) {
3850 
3851 			_set_timer(&prochinfo->ap_roch_ch_switch_timer, pwdinfo->ext_listen_interval);
3852 
3853 			channel = rtw_mi_get_union_chan(padapter);
3854 			ch_offset = rtw_mi_get_union_offset(padapter);
3855 			bwmode = rtw_mi_get_union_bw(padapter);
3856 
3857 			pwdinfo->operating_channel = channel;
3858 		}
3859 #endif
3860 		else {
3861 			pwdinfo->operating_channel = pmlmeext->cur_channel;
3862 
3863 			channel = pwdinfo->operating_channel;
3864 			ch_offset = pmlmeext->cur_ch_offset;
3865 			bwmode = pmlmeext->cur_bwmode;
3866 		}
3867 
3868 		set_channel_bwmode(padapter, channel, ch_offset, bwmode);
3869 	}
3870 
3871 exit:
3872 	return ret;
3873 
3874 }
3875 
3876 static int rtw_p2p_set_go_nego_ssid(struct net_device *dev,
3877 				    struct iw_request_info *info,
3878 				    union iwreq_data *wrqu, char *extra)
3879 {
3880 
3881 	int ret = 0;
3882 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
3883 	struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
3884 
3885 	RTW_INFO("[%s] ssid = %s, len = %zu\n", __FUNCTION__, extra, strlen(extra));
3886 	if( strlen(extra) > WPS_MAX_DEVICE_NAME_LEN){
3887 		RTW_ERR("Invalid strlen(extra): %zu\n", strlen(extra));
3888 		rtw_warn_on(1);
3889 		return -1;
3890 	}
3891 	_rtw_memcpy(pwdinfo->nego_ssid, extra, strlen(extra));
3892 	pwdinfo->nego_ssidlen = strlen(extra);
3893 
3894 	return ret;
3895 
3896 }
3897 
3898 
3899 static int rtw_p2p_set_intent(struct net_device *dev,
3900 			      struct iw_request_info *info,
3901 			      union iwreq_data *wrqu, char *extra)
3902 {
3903 	int							ret = 0;
3904 	_adapter						*padapter = (_adapter *)rtw_netdev_priv(dev);
3905 	struct wifidirect_info			*pwdinfo = &(padapter->wdinfo);
3906 	u8							intent = pwdinfo->intent;
3907 
3908 	extra[wrqu->data.length] = 0x00;
3909 
3910 	intent = rtw_atoi(extra);
3911 
3912 	if (intent <= 15)
3913 		pwdinfo->intent = intent;
3914 	else
3915 		ret = -1;
3916 
3917 	RTW_INFO("[%s] intent = %d\n", __FUNCTION__, intent);
3918 
3919 	return ret;
3920 
3921 }
3922 
3923 static int rtw_p2p_set_listen_ch(struct net_device *dev,
3924 				 struct iw_request_info *info,
3925 				 union iwreq_data *wrqu, char *extra)
3926 {
3927 
3928 	int ret = 0;
3929 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
3930 	struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
3931 	u8	listen_ch = pwdinfo->listen_channel;	/*	Listen channel number */
3932 
3933 	extra[wrqu->data.length] = 0x00;
3934 	listen_ch = rtw_atoi(extra);
3935 
3936 	if ((listen_ch == 1) || (listen_ch == 6) || (listen_ch == 11)) {
3937 		pwdinfo->listen_channel = listen_ch;
3938 		set_channel_bwmode(padapter, pwdinfo->listen_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
3939 	} else
3940 		ret = -1;
3941 
3942 	RTW_INFO("[%s] listen_ch = %d\n", __FUNCTION__, pwdinfo->listen_channel);
3943 
3944 	return ret;
3945 
3946 }
3947 
3948 static int rtw_p2p_set_op_ch(struct net_device *dev,
3949 			     struct iw_request_info *info,
3950 			     union iwreq_data *wrqu, char *extra)
3951 {
3952 	/*	Commented by Albert 20110524
3953 	 *	This function is used to set the operating channel if the driver will become the group owner */
3954 
3955 	int ret = 0;
3956 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
3957 	struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
3958 	u8	op_ch = pwdinfo->operating_channel;	/*	Operating channel number */
3959 
3960 	extra[wrqu->data.length] = 0x00;
3961 
3962 	op_ch = (u8) rtw_atoi(extra);
3963 	if (op_ch > 0)
3964 		pwdinfo->operating_channel = op_ch;
3965 	else
3966 		ret = -1;
3967 
3968 	RTW_INFO("[%s] op_ch = %d\n", __FUNCTION__, pwdinfo->operating_channel);
3969 
3970 	return ret;
3971 
3972 }
3973 
3974 
3975 static int rtw_p2p_profilefound(struct net_device *dev,
3976 				struct iw_request_info *info,
3977 				union iwreq_data *wrqu, char *extra)
3978 {
3979 
3980 	int ret = 0;
3981 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
3982 	struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
3983 
3984 	/*	Comment by Albert 2010/10/13 */
3985 	/*	Input data format: */
3986 	/*	Ex:  0 */
3987 	/*	Ex:  1XX:XX:XX:XX:XX:XXYYSSID */
3988 	/*	0 => Reflush the profile record list. */
3989 	/*	1 => Add the profile list */
3990 	/*	XX:XX:XX:XX:XX:XX => peer's MAC Address ( ex: 00:E0:4C:00:00:01 ) */
3991 	/*	YY => SSID Length */
3992 	/*	SSID => SSID for persistence group */
3993 
3994 	RTW_INFO("[%s] In value = %s, len = %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
3995 
3996 
3997 	/*	The upper application should pass the SSID to driver by using this rtw_p2p_profilefound function. */
3998 	if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
3999 		if (extra[0] == '0') {
4000 			/*	Remove all the profile information of wifidirect_info structure. */
4001 			_rtw_memset(&pwdinfo->profileinfo[0], 0x00, sizeof(struct profile_info) * P2P_MAX_PERSISTENT_GROUP_NUM);
4002 			pwdinfo->profileindex = 0;
4003 		} else {
4004 			if (pwdinfo->profileindex >= P2P_MAX_PERSISTENT_GROUP_NUM)
4005 				ret = -1;
4006 			else {
4007 				int jj, kk;
4008 
4009 				/*	Add this profile information into pwdinfo->profileinfo */
4010 				/*	Ex:  1XX:XX:XX:XX:XX:XXYYSSID */
4011 				for (jj = 0, kk = 1; jj < ETH_ALEN; jj++, kk += 3)
4012 					pwdinfo->profileinfo[pwdinfo->profileindex].peermac[jj] = key_2char2num(extra[kk], extra[kk + 1]);
4013 
4014 				/* pwdinfo->profileinfo[pwdinfo->profileindex].ssidlen = ( extra[18] - '0' ) * 10 + ( extra[19] - '0' ); */
4015 				/* _rtw_memcpy( pwdinfo->profileinfo[pwdinfo->profileindex].ssid, &extra[20], pwdinfo->profileinfo[pwdinfo->profileindex].ssidlen ); */
4016 				pwdinfo->profileindex++;
4017 			}
4018 		}
4019 	}
4020 
4021 	return ret;
4022 
4023 }
4024 
4025 static int rtw_p2p_setDN(struct net_device *dev,
4026 			 struct iw_request_info *info,
4027 			 union iwreq_data *wrqu, char *extra)
4028 {
4029 
4030 	int ret = 0;
4031 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
4032 	struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
4033 
4034 
4035 	RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
4036 	_rtw_memset(pwdinfo->device_name, 0x00, WPS_MAX_DEVICE_NAME_LEN);
4037 	if( wrqu->data.length - 1 > WPS_MAX_DEVICE_NAME_LEN){
4038 		RTW_ERR("Invalid wrqu->data.length:%d\n", wrqu->data.length - 1);
4039 		rtw_warn_on(1);
4040 		return -1;
4041 	}
4042 	_rtw_memcpy(pwdinfo->device_name, extra, wrqu->data.length - 1);
4043 	pwdinfo->device_name_len = wrqu->data.length - 1;
4044 
4045 	return ret;
4046 
4047 }
4048 
4049 
4050 static int rtw_p2p_get_status(struct net_device *dev,
4051 			      struct iw_request_info *info,
4052 			      union iwreq_data *wrqu, char *extra)
4053 {
4054 
4055 	int ret = 0;
4056 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
4057 	struct wifidirect_info	*pwdinfo = &(padapter->wdinfo);
4058 
4059 	if (padapter->bShowGetP2PState) {
4060 		RTW_INFO("[%s] Role = %d, Status = %d, peer addr = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", __FUNCTION__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo),
4061 			pwdinfo->p2p_peer_interface_addr[0], pwdinfo->p2p_peer_interface_addr[1], pwdinfo->p2p_peer_interface_addr[2],
4062 			pwdinfo->p2p_peer_interface_addr[3], pwdinfo->p2p_peer_interface_addr[4], pwdinfo->p2p_peer_interface_addr[5]);
4063 	}
4064 
4065 	/*	Commented by Albert 2010/10/12 */
4066 	/*	Because of the output size limitation, I had removed the "Role" information. */
4067 	/*	About the "Role" information, we will use the new private IOCTL to get the "Role" information. */
4068 	sprintf(extra, "\n\nStatus=%.2d\n", rtw_p2p_state(pwdinfo));
4069 	wrqu->data.length = strlen(extra);
4070 
4071 	return ret;
4072 
4073 }
4074 
4075 /*	Commented by Albert 20110520
4076  *	This function will return the config method description
4077  *	This config method description will show us which config method the remote P2P device is intented to use
4078  *	by sending the provisioning discovery request frame. */
4079 
4080 static int rtw_p2p_get_req_cm(struct net_device *dev,
4081 			      struct iw_request_info *info,
4082 			      union iwreq_data *wrqu, char *extra)
4083 {
4084 
4085 	int ret = 0;
4086 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
4087 	struct wifidirect_info	*pwdinfo = &(padapter->wdinfo);
4088 
4089 	sprintf(extra, "\n\nCM=%s\n", pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req);
4090 	wrqu->data.length = strlen(extra);
4091 	return ret;
4092 
4093 }
4094 
4095 
4096 static int rtw_p2p_get_role(struct net_device *dev,
4097 			    struct iw_request_info *info,
4098 			    union iwreq_data *wrqu, char *extra)
4099 {
4100 
4101 	int ret = 0;
4102 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
4103 	struct wifidirect_info	*pwdinfo = &(padapter->wdinfo);
4104 
4105 	RTW_INFO("[%s] Role = %d, Status = %d, peer addr = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", __FUNCTION__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo),
4106 		pwdinfo->p2p_peer_interface_addr[0], pwdinfo->p2p_peer_interface_addr[1], pwdinfo->p2p_peer_interface_addr[2],
4107 		pwdinfo->p2p_peer_interface_addr[3], pwdinfo->p2p_peer_interface_addr[4], pwdinfo->p2p_peer_interface_addr[5]);
4108 
4109 	sprintf(extra, "\n\nRole=%.2d\n", rtw_p2p_role(pwdinfo));
4110 	wrqu->data.length = strlen(extra);
4111 	return ret;
4112 
4113 }
4114 
4115 
4116 static int rtw_p2p_get_peer_ifaddr(struct net_device *dev,
4117 				   struct iw_request_info *info,
4118 				   union iwreq_data *wrqu, char *extra)
4119 {
4120 
4121 	int ret = 0;
4122 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
4123 	struct wifidirect_info	*pwdinfo = &(padapter->wdinfo);
4124 
4125 
4126 	RTW_INFO("[%s] Role = %d, Status = %d, peer addr = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", __FUNCTION__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo),
4127 		pwdinfo->p2p_peer_interface_addr[0], pwdinfo->p2p_peer_interface_addr[1], pwdinfo->p2p_peer_interface_addr[2],
4128 		pwdinfo->p2p_peer_interface_addr[3], pwdinfo->p2p_peer_interface_addr[4], pwdinfo->p2p_peer_interface_addr[5]);
4129 
4130 	sprintf(extra, "\nMAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
4131 		pwdinfo->p2p_peer_interface_addr[0], pwdinfo->p2p_peer_interface_addr[1], pwdinfo->p2p_peer_interface_addr[2],
4132 		pwdinfo->p2p_peer_interface_addr[3], pwdinfo->p2p_peer_interface_addr[4], pwdinfo->p2p_peer_interface_addr[5]);
4133 	wrqu->data.length = strlen(extra);
4134 	return ret;
4135 
4136 }
4137 
4138 static int rtw_p2p_get_peer_devaddr(struct net_device *dev,
4139 				    struct iw_request_info *info,
4140 				    union iwreq_data *wrqu, char *extra)
4141 
4142 {
4143 
4144 	int ret = 0;
4145 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
4146 	struct wifidirect_info	*pwdinfo = &(padapter->wdinfo);
4147 
4148 	RTW_INFO("[%s] Role = %d, Status = %d, peer addr = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", __FUNCTION__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo),
4149 		pwdinfo->rx_prov_disc_info.peerDevAddr[0], pwdinfo->rx_prov_disc_info.peerDevAddr[1],
4150 		pwdinfo->rx_prov_disc_info.peerDevAddr[2], pwdinfo->rx_prov_disc_info.peerDevAddr[3],
4151 		pwdinfo->rx_prov_disc_info.peerDevAddr[4], pwdinfo->rx_prov_disc_info.peerDevAddr[5]);
4152 	sprintf(extra, "\n%.2X%.2X%.2X%.2X%.2X%.2X",
4153 		pwdinfo->rx_prov_disc_info.peerDevAddr[0], pwdinfo->rx_prov_disc_info.peerDevAddr[1],
4154 		pwdinfo->rx_prov_disc_info.peerDevAddr[2], pwdinfo->rx_prov_disc_info.peerDevAddr[3],
4155 		pwdinfo->rx_prov_disc_info.peerDevAddr[4], pwdinfo->rx_prov_disc_info.peerDevAddr[5]);
4156 	wrqu->data.length = strlen(extra);
4157 	return ret;
4158 
4159 }
4160 
4161 static int rtw_p2p_get_peer_devaddr_by_invitation(struct net_device *dev,
4162 		struct iw_request_info *info,
4163 		union iwreq_data *wrqu, char *extra)
4164 
4165 {
4166 
4167 	int ret = 0;
4168 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
4169 	struct wifidirect_info	*pwdinfo = &(padapter->wdinfo);
4170 
4171 	RTW_INFO("[%s] Role = %d, Status = %d, peer addr = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", __FUNCTION__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo),
4172 		pwdinfo->p2p_peer_device_addr[0], pwdinfo->p2p_peer_device_addr[1],
4173 		pwdinfo->p2p_peer_device_addr[2], pwdinfo->p2p_peer_device_addr[3],
4174 		pwdinfo->p2p_peer_device_addr[4], pwdinfo->p2p_peer_device_addr[5]);
4175 	sprintf(extra, "\nMAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
4176 		pwdinfo->p2p_peer_device_addr[0], pwdinfo->p2p_peer_device_addr[1],
4177 		pwdinfo->p2p_peer_device_addr[2], pwdinfo->p2p_peer_device_addr[3],
4178 		pwdinfo->p2p_peer_device_addr[4], pwdinfo->p2p_peer_device_addr[5]);
4179 	wrqu->data.length = strlen(extra);
4180 	return ret;
4181 
4182 }
4183 
4184 static int rtw_p2p_get_groupid(struct net_device *dev,
4185 			       struct iw_request_info *info,
4186 			       union iwreq_data *wrqu, char *extra)
4187 
4188 {
4189 
4190 	int ret = 0;
4191 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
4192 	struct wifidirect_info	*pwdinfo = &(padapter->wdinfo);
4193 
4194 	sprintf(extra, "\n%.2X:%.2X:%.2X:%.2X:%.2X:%.2X %s",
4195 		pwdinfo->groupid_info.go_device_addr[0], pwdinfo->groupid_info.go_device_addr[1],
4196 		pwdinfo->groupid_info.go_device_addr[2], pwdinfo->groupid_info.go_device_addr[3],
4197 		pwdinfo->groupid_info.go_device_addr[4], pwdinfo->groupid_info.go_device_addr[5],
4198 		pwdinfo->groupid_info.ssid);
4199 	wrqu->data.length = strlen(extra);
4200 	return ret;
4201 
4202 }
4203 
4204 static int rtw_p2p_get_op_ch(struct net_device *dev,
4205 			     struct iw_request_info *info,
4206 			     union iwreq_data *wrqu, char *extra)
4207 
4208 {
4209 
4210 	int ret = 0;
4211 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
4212 	struct wifidirect_info	*pwdinfo = &(padapter->wdinfo);
4213 
4214 
4215 	RTW_INFO("[%s] Op_ch = %02x\n", __FUNCTION__, pwdinfo->operating_channel);
4216 
4217 	sprintf(extra, "\n\nOp_ch=%.2d\n", pwdinfo->operating_channel);
4218 	wrqu->data.length = strlen(extra);
4219 	return ret;
4220 
4221 }
4222 
4223 static int rtw_p2p_get_wps_configmethod(struct net_device *dev,
4224 					struct iw_request_info *info,
4225 			union iwreq_data *wrqu, char *extra, char *subcmd)
4226 {
4227 
4228 	int ret = 0;
4229 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
4230 	u8 peerMAC[ETH_ALEN] = { 0x00 };
4231 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
4232 	_irqL irqL;
4233 	_list *plist, *phead;
4234 	_queue *queue = &(pmlmepriv->scanned_queue);
4235 	struct wlan_network *pnetwork = NULL;
4236 	u8 blnMatch = 0;
4237 	u16	attr_content = 0;
4238 	uint attr_contentlen = 0;
4239 	u8	attr_content_str[P2P_PRIVATE_IOCTL_SET_LEN] = { 0x00 };
4240 
4241 	/*	Commented by Albert 20110727 */
4242 	/*	The input data is the MAC address which the application wants to know its WPS config method. */
4243 	/*	After knowing its WPS config method, the application can decide the config method for provisioning discovery. */
4244 	/*	Format: iwpriv wlanx p2p_get_wpsCM 00:E0:4C:00:00:05 */
4245 
4246 	RTW_INFO("[%s] data = %s\n", __FUNCTION__, subcmd);
4247 
4248 	macstr2num(peerMAC, subcmd);
4249 
4250 	_enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
4251 
4252 	phead = get_list_head(queue);
4253 	plist = get_next(phead);
4254 
4255 	while (1) {
4256 		if (rtw_end_of_queue_search(phead, plist) == _TRUE)
4257 			break;
4258 
4259 		pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
4260 		if (_rtw_memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
4261 			u8 *wpsie;
4262 			uint	wpsie_len = 0;
4263 
4264 			/*	The mac address is matched. */
4265 
4266 			wpsie = rtw_get_wps_ie_from_scan_queue(&pnetwork->network.IEs[0], pnetwork->network.IELength, NULL, &wpsie_len, pnetwork->network.Reserved[0]);
4267 			if (wpsie) {
4268 				attr_contentlen = sizeof(attr_content);
4269 				rtw_get_wps_attr_content(wpsie, wpsie_len, WPS_ATTR_CONF_METHOD, (u8 *)&attr_content, &attr_contentlen);
4270 				if (attr_contentlen) {
4271 					attr_content = be16_to_cpu(attr_content);
4272 					sprintf(attr_content_str, "\n\nM=%.4d", attr_content);
4273 					blnMatch = 1;
4274 				}
4275 			}
4276 
4277 			break;
4278 		}
4279 
4280 		plist = get_next(plist);
4281 
4282 	}
4283 
4284 	_exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
4285 
4286 	if (!blnMatch)
4287 		sprintf(attr_content_str, "\n\nM=0000");
4288 
4289 	wrqu->data.length = strlen(attr_content_str);
4290 	_rtw_memcpy(extra, attr_content_str, wrqu->data.length);
4291 
4292 	return ret;
4293 
4294 }
4295 
4296 #ifdef CONFIG_WFD
4297 static int rtw_p2p_get_peer_wfd_port(struct net_device *dev,
4298 				     struct iw_request_info *info,
4299 				     union iwreq_data *wrqu, char *extra)
4300 {
4301 
4302 	int ret = 0;
4303 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
4304 	struct wifidirect_info	*pwdinfo = &(padapter->wdinfo);
4305 
4306 	RTW_INFO("[%s] p2p_state = %d\n", __FUNCTION__, rtw_p2p_state(pwdinfo));
4307 
4308 	sprintf(extra, "\n\nPort=%d\n", pwdinfo->wfd_info->peer_rtsp_ctrlport);
4309 	RTW_INFO("[%s] remote port = %d\n", __FUNCTION__, pwdinfo->wfd_info->peer_rtsp_ctrlport);
4310 
4311 	wrqu->data.length = strlen(extra);
4312 	return ret;
4313 
4314 }
4315 
4316 static int rtw_p2p_get_peer_wfd_preferred_connection(struct net_device *dev,
4317 		struct iw_request_info *info,
4318 		union iwreq_data *wrqu, char *extra)
4319 {
4320 
4321 	int ret = 0;
4322 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
4323 	struct wifidirect_info	*pwdinfo = &(padapter->wdinfo);
4324 
4325 	sprintf(extra, "\n\nwfd_pc=%d\n", pwdinfo->wfd_info->wfd_pc);
4326 	RTW_INFO("[%s] wfd_pc = %d\n", __FUNCTION__, pwdinfo->wfd_info->wfd_pc);
4327 
4328 	wrqu->data.length = strlen(extra);
4329 	pwdinfo->wfd_info->wfd_pc = _FALSE;	/*	Reset the WFD preferred connection to P2P */
4330 	return ret;
4331 
4332 }
4333 
4334 static int rtw_p2p_get_peer_wfd_session_available(struct net_device *dev,
4335 		struct iw_request_info *info,
4336 		union iwreq_data *wrqu, char *extra)
4337 {
4338 
4339 	int ret = 0;
4340 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
4341 	struct wifidirect_info	*pwdinfo = &(padapter->wdinfo);
4342 
4343 	sprintf(extra, "\n\nwfd_sa=%d\n", pwdinfo->wfd_info->peer_session_avail);
4344 	RTW_INFO("[%s] wfd_sa = %d\n", __FUNCTION__, pwdinfo->wfd_info->peer_session_avail);
4345 
4346 	wrqu->data.length = strlen(extra);
4347 	pwdinfo->wfd_info->peer_session_avail = _TRUE;	/*	Reset the WFD session available */
4348 	return ret;
4349 
4350 }
4351 #endif /* CONFIG_WFD */
4352 
4353 static int rtw_p2p_get_go_device_address(struct net_device *dev,
4354 		struct iw_request_info *info,
4355 		union iwreq_data *wrqu, char *extra, char *subcmd)
4356 {
4357 
4358 	int ret = 0;
4359 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
4360 	u8 peerMAC[ETH_ALEN] = { 0x00 };
4361 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
4362 	_irqL irqL;
4363 	_list *plist, *phead;
4364 	_queue *queue	= &(pmlmepriv->scanned_queue);
4365 	struct wlan_network *pnetwork = NULL;
4366 	u8 blnMatch = 0;
4367 	u8 *p2pie;
4368 	uint p2pielen = 0, attr_contentlen = 0;
4369 	u8 attr_content[100] = { 0x00 };
4370 	u8 go_devadd_str[P2P_PRIVATE_IOCTL_SET_LEN] = { 0x00 };
4371 
4372 	/*	Commented by Albert 20121209 */
4373 	/*	The input data is the GO's interface address which the application wants to know its device address. */
4374 	/*	Format: iwpriv wlanx p2p_get2 go_devadd=00:E0:4C:00:00:05 */
4375 
4376 	RTW_INFO("[%s] data = %s\n", __FUNCTION__, subcmd);
4377 
4378 	macstr2num(peerMAC, subcmd);
4379 
4380 	_enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
4381 
4382 	phead = get_list_head(queue);
4383 	plist = get_next(phead);
4384 
4385 	while (1) {
4386 		if (rtw_end_of_queue_search(phead, plist) == _TRUE)
4387 			break;
4388 
4389 		pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
4390 		if (_rtw_memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
4391 			/*	Commented by Albert 2011/05/18 */
4392 			/*	Match the device address located in the P2P IE */
4393 			/*	This is for the case that the P2P device address is not the same as the P2P interface address. */
4394 
4395 			p2pie = rtw_bss_ex_get_p2p_ie(&pnetwork->network, NULL, &p2pielen);
4396 			if (p2pie) {
4397 				while (p2pie) {
4398 					/*	The P2P Device ID attribute is included in the Beacon frame. */
4399 					/*	The P2P Device Info attribute is included in the probe response frame. */
4400 
4401 					_rtw_memset(attr_content, 0x00, 100);
4402 					attr_contentlen = sizeof(attr_content);
4403 					if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_ID, attr_content, &attr_contentlen)) {
4404 						/*	Handle the P2P Device ID attribute of Beacon first */
4405 						blnMatch = 1;
4406 						break;
4407 
4408 					} else if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_INFO, attr_content, &attr_contentlen)) {
4409 						/*	Handle the P2P Device Info attribute of probe response */
4410 						blnMatch = 1;
4411 						break;
4412 					}
4413 
4414 					/* Get the next P2P IE */
4415 					p2pie = rtw_get_p2p_ie(p2pie + p2pielen, BSS_EX_TLV_IES_LEN(&pnetwork->network) - (p2pie + p2pielen - BSS_EX_TLV_IES(&pnetwork->network)), NULL, &p2pielen);
4416 				}
4417 			}
4418 		}
4419 
4420 		plist = get_next(plist);
4421 
4422 	}
4423 
4424 	_exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
4425 
4426 	if (!blnMatch)
4427 		sprintf(go_devadd_str, "\n\ndev_add=NULL");
4428 	else {
4429 		sprintf(go_devadd_str, "\n\ndev_add=%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
4430 			attr_content[0], attr_content[1], attr_content[2], attr_content[3], attr_content[4], attr_content[5]);
4431 	}
4432 
4433 	wrqu->data.length = strlen(go_devadd_str);
4434 	_rtw_memcpy(extra, go_devadd_str, wrqu->data.length);
4435 
4436 	return ret;
4437 
4438 }
4439 
4440 static int rtw_p2p_get_device_type(struct net_device *dev,
4441 				   struct iw_request_info *info,
4442 			   union iwreq_data *wrqu, char *extra, char *subcmd)
4443 {
4444 
4445 	int ret = 0;
4446 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
4447 	u8 peerMAC[ETH_ALEN] = { 0x00 };
4448 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
4449 	_irqL irqL;
4450 	_list *plist, *phead;
4451 	_queue *queue = &(pmlmepriv->scanned_queue);
4452 	struct wlan_network *pnetwork = NULL;
4453 	u8 blnMatch = 0;
4454 	u8 dev_type[8] = { 0x00 };
4455 	uint dev_type_len = 0;
4456 	u8 dev_type_str[P2P_PRIVATE_IOCTL_SET_LEN] = { 0x00 };    /* +9 is for the str "dev_type=", we have to clear it at wrqu->data.pointer */
4457 
4458 	/*	Commented by Albert 20121209 */
4459 	/*	The input data is the MAC address which the application wants to know its device type. */
4460 	/*	Such user interface could know the device type. */
4461 	/*	Format: iwpriv wlanx p2p_get2 dev_type=00:E0:4C:00:00:05 */
4462 
4463 	RTW_INFO("[%s] data = %s\n", __FUNCTION__, subcmd);
4464 
4465 	macstr2num(peerMAC, subcmd);
4466 
4467 	_enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
4468 
4469 	phead = get_list_head(queue);
4470 	plist = get_next(phead);
4471 
4472 	while (1) {
4473 		if (rtw_end_of_queue_search(phead, plist) == _TRUE)
4474 			break;
4475 
4476 		pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
4477 		if (_rtw_memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
4478 			u8 *wpsie;
4479 			uint	wpsie_len = 0;
4480 
4481 			/*	The mac address is matched. */
4482 
4483 			wpsie = rtw_get_wps_ie_from_scan_queue(&pnetwork->network.IEs[0], pnetwork->network.IELength, NULL, &wpsie_len, pnetwork->network.Reserved[0]);
4484 			if (wpsie) {
4485 				dev_type_len = sizeof(dev_type);
4486 				rtw_get_wps_attr_content(wpsie, wpsie_len, WPS_ATTR_PRIMARY_DEV_TYPE, dev_type, &dev_type_len);
4487 				if (dev_type_len) {
4488 					u16	type = 0;
4489 
4490 					_rtw_memcpy(&type, dev_type, 2);
4491 					type = be16_to_cpu(type);
4492 					sprintf(dev_type_str, "\n\nN=%.2d", type);
4493 					blnMatch = 1;
4494 				}
4495 			}
4496 			break;
4497 		}
4498 
4499 		plist = get_next(plist);
4500 
4501 	}
4502 
4503 	_exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
4504 
4505 	if (!blnMatch)
4506 		sprintf(dev_type_str, "\n\nN=00");
4507 
4508 	wrqu->data.length = strlen(dev_type_str);
4509 	_rtw_memcpy(extra, dev_type_str, wrqu->data.length);
4510 
4511 	return ret;
4512 
4513 }
4514 
4515 static int rtw_p2p_get_device_name(struct net_device *dev,
4516 				   struct iw_request_info *info,
4517 			   union iwreq_data *wrqu, char *extra, char *subcmd)
4518 {
4519 
4520 	int ret = 0;
4521 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
4522 	u8 peerMAC[ETH_ALEN] = { 0x00 };
4523 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
4524 	_irqL irqL;
4525 	_list *plist, *phead;
4526 	_queue *queue = &(pmlmepriv->scanned_queue);
4527 	struct wlan_network *pnetwork = NULL;
4528 	u8 blnMatch = 0;
4529 	u8 dev_name[WPS_MAX_DEVICE_NAME_LEN] = { 0x00 };
4530 	uint dev_len = 0;
4531 	u8 dev_name_str[P2P_PRIVATE_IOCTL_SET_LEN] = { 0x00 };
4532 
4533 	/*	Commented by Albert 20121225 */
4534 	/*	The input data is the MAC address which the application wants to know its device name. */
4535 	/*	Such user interface could show peer device's device name instead of ssid. */
4536 	/*	Format: iwpriv wlanx p2p_get2 devN=00:E0:4C:00:00:05 */
4537 
4538 	RTW_INFO("[%s] data = %s\n", __FUNCTION__, subcmd);
4539 
4540 	macstr2num(peerMAC, subcmd);
4541 
4542 	_enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
4543 
4544 	phead = get_list_head(queue);
4545 	plist = get_next(phead);
4546 
4547 	while (1) {
4548 		if (rtw_end_of_queue_search(phead, plist) == _TRUE)
4549 			break;
4550 
4551 		pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
4552 		if (_rtw_memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
4553 			u8 *wpsie;
4554 			uint	wpsie_len = 0;
4555 
4556 			/*	The mac address is matched. */
4557 
4558 			wpsie = rtw_get_wps_ie_from_scan_queue(&pnetwork->network.IEs[0], pnetwork->network.IELength, NULL, &wpsie_len, pnetwork->network.Reserved[0]);
4559 			if (wpsie) {
4560 				dev_len = sizeof(dev_name);
4561 				rtw_get_wps_attr_content(wpsie, wpsie_len, WPS_ATTR_DEVICE_NAME, dev_name, &dev_len);
4562 				if (dev_len) {
4563 					sprintf(dev_name_str, "\n\nN=%s", dev_name);
4564 					blnMatch = 1;
4565 				}
4566 			}
4567 			break;
4568 		}
4569 
4570 		plist = get_next(plist);
4571 
4572 	}
4573 
4574 	_exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
4575 
4576 	if (!blnMatch)
4577 		sprintf(dev_name_str, "\n\nN=0000");
4578 
4579 	wrqu->data.length = strlen(dev_name_str);
4580 	_rtw_memcpy(extra, dev_name_str, wrqu->data.length);
4581 
4582 	return ret;
4583 
4584 }
4585 
4586 static int rtw_p2p_get_invitation_procedure(struct net_device *dev,
4587 		struct iw_request_info *info,
4588 		union iwreq_data *wrqu, char *extra, char *subcmd)
4589 {
4590 
4591 	int ret = 0;
4592 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
4593 	u8 peerMAC[ETH_ALEN] = { 0x00 };
4594 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
4595 	_irqL irqL;
4596 	_list *plist, *phead;
4597 	_queue *queue	= &(pmlmepriv->scanned_queue);
4598 	struct wlan_network *pnetwork = NULL;
4599 	u8 blnMatch = 0;
4600 	u8 *p2pie;
4601 	uint p2pielen = 0, attr_contentlen = 2;
4602 	u8 attr_content[2] = { 0x00 };
4603 	u8 inv_proc_str[P2P_PRIVATE_IOCTL_SET_LEN] = { 0x00 };
4604 
4605 	/*	Commented by Ouden 20121226 */
4606 	/*	The application wants to know P2P initation procedure is support or not. */
4607 	/*	Format: iwpriv wlanx p2p_get2 InvProc=00:E0:4C:00:00:05 */
4608 
4609 	RTW_INFO("[%s] data = %s\n", __FUNCTION__, subcmd);
4610 
4611 	macstr2num(peerMAC, subcmd);
4612 
4613 	_enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
4614 
4615 	phead = get_list_head(queue);
4616 	plist = get_next(phead);
4617 
4618 	while (1) {
4619 		if (rtw_end_of_queue_search(phead, plist) == _TRUE)
4620 			break;
4621 
4622 		pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
4623 		if (_rtw_memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
4624 			/*	Commented by Albert 20121226 */
4625 			/*	Match the device address located in the P2P IE */
4626 			/*	This is for the case that the P2P device address is not the same as the P2P interface address. */
4627 
4628 			p2pie = rtw_bss_ex_get_p2p_ie(&pnetwork->network, NULL, &p2pielen);
4629 			if (p2pie) {
4630 				while (p2pie) {
4631 					/* _rtw_memset( attr_content, 0x00, 2); */
4632 					attr_contentlen = sizeof(attr_content);
4633 					if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_CAPABILITY, attr_content, &attr_contentlen)) {
4634 						/*	Handle the P2P capability attribute */
4635 						blnMatch = 1;
4636 						break;
4637 
4638 					}
4639 
4640 					/* Get the next P2P IE */
4641 					p2pie = rtw_get_p2p_ie(p2pie + p2pielen, BSS_EX_TLV_IES_LEN(&pnetwork->network) - (p2pie + p2pielen - BSS_EX_TLV_IES(&pnetwork->network)), NULL, &p2pielen);
4642 				}
4643 			}
4644 		}
4645 
4646 		plist = get_next(plist);
4647 
4648 	}
4649 
4650 	_exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
4651 
4652 	if (!blnMatch)
4653 		sprintf(inv_proc_str, "\nIP=-1");
4654 	else {
4655 		if ((attr_content[0] & 0x20) == 0x20)
4656 			sprintf(inv_proc_str, "\nIP=1");
4657 		else
4658 			sprintf(inv_proc_str, "\nIP=0");
4659 	}
4660 
4661 	wrqu->data.length = strlen(inv_proc_str);
4662 	_rtw_memcpy(extra, inv_proc_str, wrqu->data.length);
4663 
4664 	return ret;
4665 
4666 }
4667 
4668 static int rtw_p2p_connect(struct net_device *dev,
4669 			   struct iw_request_info *info,
4670 			   union iwreq_data *wrqu, char *extra)
4671 {
4672 
4673 	int ret = 0;
4674 	_adapter				*padapter = (_adapter *)rtw_netdev_priv(dev);
4675 	struct wifidirect_info	*pwdinfo = &(padapter->wdinfo);
4676 	u8					peerMAC[ETH_ALEN] = { 0x00 };
4677 	int					jj, kk;
4678 	struct mlme_priv		*pmlmepriv = &padapter->mlmepriv;
4679 	_irqL				irqL;
4680 	_list					*plist, *phead;
4681 	_queue				*queue	= &(pmlmepriv->scanned_queue);
4682 	struct	wlan_network	*pnetwork = NULL;
4683 	uint					uintPeerChannel = 0;
4684 #ifdef CONFIG_CONCURRENT_MODE
4685 	struct roch_info		*prochinfo = &padapter->rochinfo;
4686 #endif
4687 
4688 	/*	Commented by Albert 20110304 */
4689 	/*	The input data contains two informations. */
4690 	/*	1. First information is the MAC address which wants to formate with */
4691 	/*	2. Second information is the WPS PINCode or "pbc" string for push button method */
4692 	/*	Format: 00:E0:4C:00:00:05 */
4693 	/*	Format: 00:E0:4C:00:00:05 */
4694 
4695 	RTW_INFO("[%s] data = %s\n", __FUNCTION__, extra);
4696 
4697 	if (pwdinfo->p2p_state == P2P_STATE_NONE) {
4698 		RTW_INFO("[%s] WiFi Direct is disable!\n", __FUNCTION__);
4699 		return ret;
4700 	}
4701 
4702 	if (pwdinfo->ui_got_wps_info == P2P_NO_WPSINFO)
4703 		return -1;
4704 
4705 	for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
4706 		peerMAC[jj] = key_2char2num(extra[kk], extra[kk + 1]);
4707 
4708 	_enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
4709 
4710 	phead = get_list_head(queue);
4711 	plist = get_next(phead);
4712 
4713 	while (1) {
4714 		if (rtw_end_of_queue_search(phead, plist) == _TRUE)
4715 			break;
4716 
4717 		pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
4718 		if (_rtw_memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
4719 			if (pnetwork->network.Configuration.DSConfig != 0)
4720 				uintPeerChannel = pnetwork->network.Configuration.DSConfig;
4721 			else if (pwdinfo->nego_req_info.peer_ch != 0)
4722 				uintPeerChannel = pnetwork->network.Configuration.DSConfig = pwdinfo->nego_req_info.peer_ch;
4723 			else {
4724 				/* Unexpected case */
4725 				uintPeerChannel = 0;
4726 				RTW_INFO("%s  uintPeerChannel = 0\n", __func__);
4727 			}
4728 			break;
4729 		}
4730 
4731 		plist = get_next(plist);
4732 
4733 	}
4734 
4735 	_exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
4736 
4737 	if (uintPeerChannel) {
4738 #ifdef CONFIG_CONCURRENT_MODE
4739 		if (rtw_mi_check_status(padapter, MI_LINKED))
4740 			_cancel_timer_ex(&prochinfo->ap_roch_ch_switch_timer);
4741 #endif /* CONFIG_CONCURRENT_MODE */
4742 
4743 		_rtw_memset(&pwdinfo->nego_req_info, 0x00, sizeof(struct tx_nego_req_info));
4744 		_rtw_memset(&pwdinfo->groupid_info, 0x00, sizeof(struct group_id_info));
4745 
4746 		pwdinfo->nego_req_info.peer_channel_num[0] = uintPeerChannel;
4747 		_rtw_memcpy(pwdinfo->nego_req_info.peerDevAddr, pnetwork->network.MacAddress, ETH_ALEN);
4748 		pwdinfo->nego_req_info.benable = _TRUE;
4749 
4750 		_cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
4751 		if (rtw_p2p_state(pwdinfo) != P2P_STATE_GONEGO_OK) {
4752 			/*	Restore to the listen state if the current p2p state is not nego OK */
4753 			rtw_p2p_set_state(pwdinfo, P2P_STATE_LISTEN);
4754 		}
4755 
4756 		rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
4757 		rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_ING);
4758 
4759 #ifdef CONFIG_CONCURRENT_MODE
4760 		if (rtw_mi_check_status(padapter, MI_LINKED)) {
4761 			u8 union_ch = rtw_mi_get_union_chan(padapter);
4762 			u8 union_bw = rtw_mi_get_union_bw(padapter);
4763 			u8 union_offset = rtw_mi_get_union_offset(padapter);
4764 
4765 			set_channel_bwmode(padapter, union_ch, union_offset, union_bw);
4766 			rtw_leave_opch(padapter);
4767 		}
4768 #endif /* CONFIG_CONCURRENT_MODE */
4769 
4770 		RTW_INFO("[%s] Start PreTx Procedure!\n", __FUNCTION__);
4771 		_set_timer(&pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT);
4772 #ifdef CONFIG_CONCURRENT_MODE
4773 		if (rtw_mi_check_status(padapter, MI_LINKED))
4774 			_set_timer(&pwdinfo->restore_p2p_state_timer, P2P_CONCURRENT_GO_NEGO_TIMEOUT);
4775 		else
4776 			_set_timer(&pwdinfo->restore_p2p_state_timer, P2P_GO_NEGO_TIMEOUT);
4777 #else
4778 		_set_timer(&pwdinfo->restore_p2p_state_timer, P2P_GO_NEGO_TIMEOUT);
4779 #endif /* CONFIG_CONCURRENT_MODE		 */
4780 
4781 	} else {
4782 		RTW_INFO("[%s] Not Found in Scanning Queue~\n", __FUNCTION__);
4783 		ret = -1;
4784 	}
4785 
4786 	return ret;
4787 }
4788 
4789 static int rtw_p2p_invite_req(struct net_device *dev,
4790 			      struct iw_request_info *info,
4791 			      union iwreq_data *wrqu, char *extra)
4792 {
4793 
4794 	int ret = 0;
4795 	_adapter					*padapter = (_adapter *)rtw_netdev_priv(dev);
4796 	struct wifidirect_info		*pwdinfo = &(padapter->wdinfo);
4797 	int						jj, kk;
4798 	struct mlme_priv			*pmlmepriv = &padapter->mlmepriv;
4799 	_list						*plist, *phead;
4800 	_queue					*queue	= &(pmlmepriv->scanned_queue);
4801 	struct	wlan_network		*pnetwork = NULL;
4802 	uint						uintPeerChannel = 0;
4803 	u8						attr_content[50] = { 0x00 };
4804 	u8						*p2pie;
4805 	uint						p2pielen = 0, attr_contentlen = 50;
4806 	_irqL					irqL;
4807 	struct tx_invite_req_info	*pinvite_req_info = &pwdinfo->invitereq_info;
4808 #ifdef CONFIG_CONCURRENT_MODE
4809 	struct roch_info			*prochinfo = &padapter->rochinfo;
4810 #endif
4811 
4812 	/*	Commented by Albert 20120321 */
4813 	/*	The input data contains two informations. */
4814 	/*	1. First information is the P2P device address which you want to send to.	 */
4815 	/*	2. Second information is the group id which combines with GO's mac address, space and GO's ssid. */
4816 	/*	Command line sample: iwpriv wlan0 p2p_set invite="00:11:22:33:44:55 00:E0:4C:00:00:05 DIRECT-xy" */
4817 	/*	Format: 00:11:22:33:44:55 00:E0:4C:00:00:05 DIRECT-xy */
4818 
4819 	RTW_INFO("[%s] data = %s\n", __FUNCTION__, extra);
4820 
4821 	if (wrqu->data.length <=  37) {
4822 		RTW_INFO("[%s] Wrong format!\n", __FUNCTION__);
4823 		return ret;
4824 	}
4825 
4826 	if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
4827 		RTW_INFO("[%s] WiFi Direct is disable!\n", __FUNCTION__);
4828 		return ret;
4829 	} else {
4830 		/*	Reset the content of struct tx_invite_req_info */
4831 		pinvite_req_info->benable = _FALSE;
4832 		_rtw_memset(pinvite_req_info->go_bssid, 0x00, ETH_ALEN);
4833 		_rtw_memset(pinvite_req_info->go_ssid, 0x00, WLAN_SSID_MAXLEN);
4834 		pinvite_req_info->ssidlen = 0x00;
4835 		pinvite_req_info->operating_ch = pwdinfo->operating_channel;
4836 		_rtw_memset(pinvite_req_info->peer_macaddr, 0x00, ETH_ALEN);
4837 		pinvite_req_info->token = 3;
4838 	}
4839 
4840 	for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
4841 		pinvite_req_info->peer_macaddr[jj] = key_2char2num(extra[kk], extra[kk + 1]);
4842 
4843 	_enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
4844 
4845 	phead = get_list_head(queue);
4846 	plist = get_next(phead);
4847 
4848 	while (1) {
4849 		if (rtw_end_of_queue_search(phead, plist) == _TRUE)
4850 			break;
4851 
4852 		pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
4853 
4854 		/*	Commented by Albert 2011/05/18 */
4855 		/*	Match the device address located in the P2P IE */
4856 		/*	This is for the case that the P2P device address is not the same as the P2P interface address. */
4857 
4858 		p2pie = rtw_bss_ex_get_p2p_ie(&pnetwork->network, NULL, &p2pielen);
4859 		if (p2pie) {
4860 			/*	The P2P Device ID attribute is included in the Beacon frame. */
4861 			/*	The P2P Device Info attribute is included in the probe response frame. */
4862 
4863 			attr_contentlen = sizeof(attr_content);
4864 			if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_ID, attr_content, &attr_contentlen)) {
4865 				/*	Handle the P2P Device ID attribute of Beacon first */
4866 				if (_rtw_memcmp(attr_content, pinvite_req_info->peer_macaddr, ETH_ALEN)) {
4867 					uintPeerChannel = pnetwork->network.Configuration.DSConfig;
4868 					break;
4869 				}
4870 			} else if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_INFO, attr_content, &attr_contentlen)) {
4871 				/*	Handle the P2P Device Info attribute of probe response */
4872 				if (_rtw_memcmp(attr_content, pinvite_req_info->peer_macaddr, ETH_ALEN)) {
4873 					uintPeerChannel = pnetwork->network.Configuration.DSConfig;
4874 					break;
4875 				}
4876 			}
4877 
4878 		}
4879 
4880 		plist = get_next(plist);
4881 
4882 	}
4883 
4884 	_exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
4885 
4886 #ifdef CONFIG_WFD
4887 	if (hal_chk_wl_func(padapter, WL_FUNC_MIRACAST) && uintPeerChannel) {
4888 		struct wifi_display_info *pwfd_info = pwdinfo->wfd_info;
4889 		u8 *wfd_ie;
4890 		uint wfd_ielen = 0;
4891 
4892 		wfd_ie = rtw_bss_ex_get_wfd_ie(&pnetwork->network, NULL, &wfd_ielen);
4893 		if (wfd_ie) {
4894 			u8 *wfd_devinfo;
4895 			uint wfd_devlen;
4896 
4897 			RTW_INFO("[%s] Found WFD IE!\n", __FUNCTION__);
4898 			wfd_devinfo = rtw_get_wfd_attr_content(wfd_ie, wfd_ielen, WFD_ATTR_DEVICE_INFO, NULL, &wfd_devlen);
4899 			if (wfd_devinfo) {
4900 				u16	wfd_devinfo_field = 0;
4901 
4902 				/*	Commented by Albert 20120319 */
4903 				/*	The first two bytes are the WFD device information field of WFD device information subelement. */
4904 				/*	In big endian format. */
4905 				wfd_devinfo_field = RTW_GET_BE16(wfd_devinfo);
4906 				if (wfd_devinfo_field & WFD_DEVINFO_SESSION_AVAIL)
4907 					pwfd_info->peer_session_avail = _TRUE;
4908 				else
4909 					pwfd_info->peer_session_avail = _FALSE;
4910 			}
4911 		}
4912 
4913 		if (_FALSE == pwfd_info->peer_session_avail) {
4914 			RTW_INFO("[%s] WFD Session not avaiable!\n", __FUNCTION__);
4915 			goto exit;
4916 		}
4917 	}
4918 #endif /* CONFIG_WFD */
4919 
4920 	if (uintPeerChannel) {
4921 #ifdef CONFIG_CONCURRENT_MODE
4922 		if (rtw_mi_check_status(padapter, MI_LINKED))
4923 			_cancel_timer_ex(&prochinfo->ap_roch_ch_switch_timer);
4924 #endif /* CONFIG_CONCURRENT_MODE */
4925 
4926 		/*	Store the GO's bssid */
4927 		for (jj = 0, kk = 18; jj < ETH_ALEN; jj++, kk += 3)
4928 			pinvite_req_info->go_bssid[jj] = key_2char2num(extra[kk], extra[kk + 1]);
4929 
4930 		/*	Store the GO's ssid */
4931 		pinvite_req_info->ssidlen = wrqu->data.length - 36;
4932 		_rtw_memcpy(pinvite_req_info->go_ssid, &extra[36], (u32) pinvite_req_info->ssidlen);
4933 		pinvite_req_info->benable = _TRUE;
4934 		pinvite_req_info->peer_ch = uintPeerChannel;
4935 
4936 		rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
4937 		rtw_p2p_set_state(pwdinfo, P2P_STATE_TX_INVITE_REQ);
4938 
4939 #ifdef CONFIG_CONCURRENT_MODE
4940 		if (rtw_mi_check_status(padapter, MI_LINKED)) {
4941 			u8 union_ch = rtw_mi_get_union_chan(padapter);
4942 			u8 union_bw = rtw_mi_get_union_bw(padapter);
4943 			u8 union_offset = rtw_mi_get_union_offset(padapter);
4944 
4945 			set_channel_bwmode(padapter, union_ch, union_offset, union_bw);
4946 			rtw_leave_opch(padapter);
4947 
4948 		} else
4949 			set_channel_bwmode(padapter, uintPeerChannel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
4950 #else
4951 		set_channel_bwmode(padapter, uintPeerChannel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
4952 #endif/*CONFIG_CONCURRENT_MODE*/
4953 
4954 		_set_timer(&pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT);
4955 
4956 #ifdef CONFIG_CONCURRENT_MODE
4957 		if (rtw_mi_check_status(padapter, MI_LINKED))
4958 			_set_timer(&pwdinfo->restore_p2p_state_timer, P2P_CONCURRENT_INVITE_TIMEOUT);
4959 		else
4960 			_set_timer(&pwdinfo->restore_p2p_state_timer, P2P_INVITE_TIMEOUT);
4961 #else
4962 		_set_timer(&pwdinfo->restore_p2p_state_timer, P2P_INVITE_TIMEOUT);
4963 #endif /* CONFIG_CONCURRENT_MODE		 */
4964 
4965 
4966 	} else
4967 		RTW_INFO("[%s] NOT Found in the Scanning Queue!\n", __FUNCTION__);
4968 exit:
4969 
4970 	return ret;
4971 
4972 }
4973 
4974 static int rtw_p2p_set_persistent(struct net_device *dev,
4975 				  struct iw_request_info *info,
4976 				  union iwreq_data *wrqu, char *extra)
4977 {
4978 
4979 	int ret = 0;
4980 	_adapter					*padapter = (_adapter *)rtw_netdev_priv(dev);
4981 	struct wifidirect_info		*pwdinfo = &(padapter->wdinfo);
4982 
4983 	/*	Commented by Albert 20120328 */
4984 	/*	The input data is 0 or 1 */
4985 	/*	0: disable persistent group functionality */
4986 	/*	1: enable persistent group founctionality */
4987 
4988 	RTW_INFO("[%s] data = %s\n", __FUNCTION__, extra);
4989 
4990 	if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
4991 		RTW_INFO("[%s] WiFi Direct is disable!\n", __FUNCTION__);
4992 		return ret;
4993 	} else {
4994 		if (extra[0] == '0')	/*	Disable the persistent group function. */
4995 			pwdinfo->persistent_supported = _FALSE;
4996 		else if (extra[0] == '1')	/*	Enable the persistent group function. */
4997 			pwdinfo->persistent_supported = _TRUE;
4998 		else
4999 			pwdinfo->persistent_supported = _FALSE;
5000 	}
5001 	printk("[%s] persistent_supported = %d\n", __FUNCTION__, pwdinfo->persistent_supported);
5002 
5003 	return ret;
5004 
5005 }
5006 
5007 static int uuid_str2bin(const char *str, u8 *bin)
5008 {
5009 	const char *pos;
5010 	u8 *opos;
5011 
5012 	pos = str;
5013 	opos = bin;
5014 
5015 	if (hexstr2bin(pos, opos, 4))
5016 		return -1;
5017 	pos += 8;
5018 	opos += 4;
5019 
5020 	if (*pos++ != '-' || hexstr2bin(pos, opos, 2))
5021 		return -1;
5022 	pos += 4;
5023 	opos += 2;
5024 
5025 	if (*pos++ != '-' || hexstr2bin(pos, opos, 2))
5026 		return -1;
5027 	pos += 4;
5028 	opos += 2;
5029 
5030 	if (*pos++ != '-' || hexstr2bin(pos, opos, 2))
5031 		return -1;
5032 	pos += 4;
5033 	opos += 2;
5034 
5035 	if (*pos++ != '-' || hexstr2bin(pos, opos, 6))
5036 		return -1;
5037 
5038 	return 0;
5039 }
5040 
5041 static int rtw_p2p_set_wps_uuid(struct net_device *dev,
5042 				struct iw_request_info *info,
5043 				union iwreq_data *wrqu, char *extra)
5044 {
5045 
5046 	int ret = 0;
5047 	_adapter				*padapter = (_adapter *)rtw_netdev_priv(dev);
5048 	struct wifidirect_info			*pwdinfo = &(padapter->wdinfo);
5049 
5050 	RTW_INFO("[%s] data = %s\n", __FUNCTION__, extra);
5051 
5052 	if ((36 == strlen(extra)) && (uuid_str2bin(extra, pwdinfo->uuid) == 0))
5053 		pwdinfo->external_uuid = 1;
5054 	else {
5055 		pwdinfo->external_uuid = 0;
5056 		ret = -EINVAL;
5057 	}
5058 
5059 	return ret;
5060 
5061 }
5062 #ifdef CONFIG_WFD
5063 static int rtw_p2p_set_pc(struct net_device *dev,
5064 			  struct iw_request_info *info,
5065 			  union iwreq_data *wrqu, char *extra)
5066 {
5067 
5068 	int ret = 0;
5069 	_adapter				*padapter = (_adapter *)rtw_netdev_priv(dev);
5070 	struct wifidirect_info	*pwdinfo = &(padapter->wdinfo);
5071 	u8					peerMAC[ETH_ALEN] = { 0x00 };
5072 	int					jj, kk;
5073 	struct mlme_priv		*pmlmepriv = &padapter->mlmepriv;
5074 	_list					*plist, *phead;
5075 	_queue				*queue	= &(pmlmepriv->scanned_queue);
5076 	struct	wlan_network	*pnetwork = NULL;
5077 	u8					attr_content[50] = { 0x00 };
5078 	u8 *p2pie;
5079 	uint					p2pielen = 0, attr_contentlen = 50;
5080 	_irqL				irqL;
5081 	uint					uintPeerChannel = 0;
5082 
5083 	struct wifi_display_info	*pwfd_info = pwdinfo->wfd_info;
5084 
5085 	/*	Commented by Albert 20120512 */
5086 	/*	1. Input information is the MAC address which wants to know the Preferred Connection bit (PC bit) */
5087 	/*	Format: 00:E0:4C:00:00:05 */
5088 
5089 	RTW_INFO("[%s] data = %s\n", __FUNCTION__, extra);
5090 
5091 	if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
5092 		RTW_INFO("[%s] WiFi Direct is disable!\n", __FUNCTION__);
5093 		return ret;
5094 	}
5095 
5096 	for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
5097 		peerMAC[jj] = key_2char2num(extra[kk], extra[kk + 1]);
5098 
5099 	_enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
5100 
5101 	phead = get_list_head(queue);
5102 	plist = get_next(phead);
5103 
5104 	while (1) {
5105 		if (rtw_end_of_queue_search(phead, plist) == _TRUE)
5106 			break;
5107 
5108 		pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
5109 
5110 		/*	Commented by Albert 2011/05/18 */
5111 		/*	Match the device address located in the P2P IE */
5112 		/*	This is for the case that the P2P device address is not the same as the P2P interface address. */
5113 
5114 		p2pie = rtw_bss_ex_get_p2p_ie(&pnetwork->network, NULL, &p2pielen);
5115 		if (p2pie) {
5116 			/*	The P2P Device ID attribute is included in the Beacon frame. */
5117 			/*	The P2P Device Info attribute is included in the probe response frame. */
5118 			printk("[%s] Got P2P IE\n", __FUNCTION__);
5119 			attr_contentlen = sizeof(attr_content);
5120 			if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_ID, attr_content, &attr_contentlen)) {
5121 				/*	Handle the P2P Device ID attribute of Beacon first */
5122 				printk("[%s] P2P_ATTR_DEVICE_ID\n", __FUNCTION__);
5123 				if (_rtw_memcmp(attr_content, peerMAC, ETH_ALEN)) {
5124 					uintPeerChannel = pnetwork->network.Configuration.DSConfig;
5125 					break;
5126 				}
5127 			} else if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_INFO, attr_content, &attr_contentlen)) {
5128 				/*	Handle the P2P Device Info attribute of probe response */
5129 				printk("[%s] P2P_ATTR_DEVICE_INFO\n", __FUNCTION__);
5130 				if (_rtw_memcmp(attr_content, peerMAC, ETH_ALEN)) {
5131 					uintPeerChannel = pnetwork->network.Configuration.DSConfig;
5132 					break;
5133 				}
5134 			}
5135 
5136 		}
5137 
5138 		plist = get_next(plist);
5139 
5140 	}
5141 
5142 	_exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
5143 	printk("[%s] channel = %d\n", __FUNCTION__, uintPeerChannel);
5144 
5145 	if (uintPeerChannel) {
5146 		u8 *wfd_ie;
5147 		uint wfd_ielen = 0;
5148 
5149 		wfd_ie = rtw_bss_ex_get_wfd_ie(&pnetwork->network, NULL, &wfd_ielen);
5150 		if (wfd_ie) {
5151 			u8 *wfd_devinfo;
5152 			uint wfd_devlen;
5153 
5154 			RTW_INFO("[%s] Found WFD IE!\n", __FUNCTION__);
5155 			wfd_devinfo = rtw_get_wfd_attr_content(wfd_ie, wfd_ielen, WFD_ATTR_DEVICE_INFO, NULL, &wfd_devlen);
5156 			if (wfd_devinfo) {
5157 				u16	wfd_devinfo_field = 0;
5158 
5159 				/*	Commented by Albert 20120319 */
5160 				/*	The first two bytes are the WFD device information field of WFD device information subelement. */
5161 				/*	In big endian format. */
5162 				wfd_devinfo_field = RTW_GET_BE16(wfd_devinfo);
5163 				if (wfd_devinfo_field & WFD_DEVINFO_PC_TDLS)
5164 					pwfd_info->wfd_pc = _TRUE;
5165 				else
5166 					pwfd_info->wfd_pc = _FALSE;
5167 			}
5168 		}
5169 	} else
5170 		RTW_INFO("[%s] NOT Found in the Scanning Queue!\n", __FUNCTION__);
5171 
5172 	return ret;
5173 
5174 }
5175 
5176 static int rtw_p2p_set_wfd_device_type(struct net_device *dev,
5177 				       struct iw_request_info *info,
5178 				       union iwreq_data *wrqu, char *extra)
5179 {
5180 
5181 	int ret = 0;
5182 	_adapter					*padapter = (_adapter *)rtw_netdev_priv(dev);
5183 	struct wifidirect_info		*pwdinfo = &(padapter->wdinfo);
5184 	struct wifi_display_info		*pwfd_info = pwdinfo->wfd_info;
5185 
5186 	/*	Commented by Albert 20120328 */
5187 	/*	The input data is 0 or 1 */
5188 	/*	0: specify to Miracast source device */
5189 	/*	1 or others: specify to Miracast sink device (display device) */
5190 
5191 	RTW_INFO("[%s] data = %s\n", __FUNCTION__, extra);
5192 
5193 	if (extra[0] == '0')	/*	Set to Miracast source device. */
5194 		pwfd_info->wfd_device_type = WFD_DEVINFO_SOURCE;
5195 	else					/*	Set to Miracast sink device. */
5196 		pwfd_info->wfd_device_type = WFD_DEVINFO_PSINK;
5197 
5198 	return ret;
5199 
5200 }
5201 
5202 static int rtw_p2p_set_wfd_enable(struct net_device *dev,
5203 				  struct iw_request_info *info,
5204 				  union iwreq_data *wrqu, char *extra)
5205 {
5206 	/*	Commented by Kurt 20121206
5207 	 *	This function is used to set wfd enabled */
5208 
5209 	int ret = 0;
5210 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
5211 	struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
5212 
5213 	if (*extra == '0')
5214 		rtw_wfd_enable(padapter, 0);
5215 	else if (*extra == '1')
5216 		rtw_wfd_enable(padapter, 1);
5217 
5218 	RTW_INFO("[%s] wfd_enable = %d\n", __FUNCTION__, pwdinfo->wfd_info->wfd_enable);
5219 
5220 	return ret;
5221 
5222 }
5223 
5224 static int rtw_p2p_set_driver_iface(struct net_device *dev,
5225 				    struct iw_request_info *info,
5226 				    union iwreq_data *wrqu, char *extra)
5227 {
5228 	/*	Commented by Kurt 20121206
5229 	 *	This function is used to set driver iface is WEXT or CFG80211 */
5230 	int ret = 0;
5231 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
5232 	struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
5233 
5234 	if (*extra == '1') {
5235 		pwdinfo->driver_interface = DRIVER_WEXT;
5236 		RTW_INFO("[%s] driver_interface = WEXT\n", __FUNCTION__);
5237 	} else if (*extra == '2') {
5238 		pwdinfo->driver_interface = DRIVER_CFG80211;
5239 		RTW_INFO("[%s] driver_interface = CFG80211\n", __FUNCTION__);
5240 	}
5241 
5242 	return ret;
5243 
5244 }
5245 
5246 /*	To set the WFD session available to enable or disable */
5247 static int rtw_p2p_set_sa(struct net_device *dev,
5248 			  struct iw_request_info *info,
5249 			  union iwreq_data *wrqu, char *extra)
5250 {
5251 
5252 	int ret = 0;
5253 	_adapter					*padapter = (_adapter *)rtw_netdev_priv(dev);
5254 	struct wifidirect_info		*pwdinfo = &(padapter->wdinfo);
5255 
5256 	RTW_INFO("[%s] data = %s\n", __FUNCTION__, extra);
5257 
5258 	if (0) {
5259 		RTW_INFO("[%s] WiFi Direct is disable!\n", __FUNCTION__);
5260 		return ret;
5261 	} else {
5262 		if (extra[0] == '0')	/*	Disable the session available. */
5263 			pwdinfo->session_available = _FALSE;
5264 		else if (extra[0] == '1')	/*	Enable the session available. */
5265 			pwdinfo->session_available = _TRUE;
5266 		else
5267 			pwdinfo->session_available = _FALSE;
5268 	}
5269 	printk("[%s] session available = %d\n", __FUNCTION__, pwdinfo->session_available);
5270 
5271 	return ret;
5272 
5273 }
5274 #endif /* CONFIG_WFD */
5275 
5276 static int rtw_p2p_prov_disc(struct net_device *dev,
5277 			     struct iw_request_info *info,
5278 			     union iwreq_data *wrqu, char *extra)
5279 {
5280 	int ret = 0;
5281 	_adapter				*padapter = (_adapter *)rtw_netdev_priv(dev);
5282 	struct wifidirect_info	*pwdinfo = &(padapter->wdinfo);
5283 	u8					peerMAC[ETH_ALEN] = { 0x00 };
5284 	int					jj, kk;
5285 	struct mlme_priv		*pmlmepriv = &padapter->mlmepriv;
5286 	_list					*plist, *phead;
5287 	_queue				*queue	= &(pmlmepriv->scanned_queue);
5288 	struct	wlan_network	*pnetwork = NULL;
5289 	uint					uintPeerChannel = 0;
5290 	u8					attr_content[100] = { 0x00 };
5291 	u8 *p2pie;
5292 	uint					p2pielen = 0, attr_contentlen = 100;
5293 	_irqL				irqL;
5294 #ifdef CONFIG_CONCURRENT_MODE
5295 	struct roch_info 		*prochinfo = &padapter->rochinfo;
5296 #endif
5297 
5298 	/*	Commented by Albert 20110301 */
5299 	/*	The input data contains two informations. */
5300 	/*	1. First information is the MAC address which wants to issue the provisioning discovery request frame. */
5301 	/*	2. Second information is the WPS configuration method which wants to discovery */
5302 	/*	Format: 00:E0:4C:00:00:05_display */
5303 	/*	Format: 00:E0:4C:00:00:05_keypad */
5304 	/*	Format: 00:E0:4C:00:00:05_pbc */
5305 	/*	Format: 00:E0:4C:00:00:05_label */
5306 
5307 	RTW_INFO("[%s] data = %s\n", __FUNCTION__, extra);
5308 
5309 	if (pwdinfo->p2p_state == P2P_STATE_NONE) {
5310 		RTW_INFO("[%s] WiFi Direct is disable!\n", __FUNCTION__);
5311 		return ret;
5312 	} else {
5313 		/*	Reset the content of struct tx_provdisc_req_info excluded the wps_config_method_request. */
5314 		_rtw_memset(pwdinfo->tx_prov_disc_info.peerDevAddr, 0x00, ETH_ALEN);
5315 		_rtw_memset(pwdinfo->tx_prov_disc_info.peerIFAddr, 0x00, ETH_ALEN);
5316 		_rtw_memset(&pwdinfo->tx_prov_disc_info.ssid, 0x00, sizeof(NDIS_802_11_SSID));
5317 		pwdinfo->tx_prov_disc_info.peer_channel_num[0] = 0;
5318 		pwdinfo->tx_prov_disc_info.peer_channel_num[1] = 0;
5319 		pwdinfo->tx_prov_disc_info.benable = _FALSE;
5320 	}
5321 
5322 	for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
5323 		peerMAC[jj] = key_2char2num(extra[kk], extra[kk + 1]);
5324 
5325 	if (_rtw_memcmp(&extra[18], "display", 7))
5326 		pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_DISPLYA;
5327 	else if (_rtw_memcmp(&extra[18], "keypad", 7))
5328 		pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_KEYPAD;
5329 	else if (_rtw_memcmp(&extra[18], "pbc", 3))
5330 		pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_PUSH_BUTTON;
5331 	else if (_rtw_memcmp(&extra[18], "label", 5))
5332 		pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_LABEL;
5333 	else {
5334 		RTW_INFO("[%s] Unknown WPS config methodn", __FUNCTION__);
5335 		return ret ;
5336 	}
5337 
5338 	_enter_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
5339 
5340 	phead = get_list_head(queue);
5341 	plist = get_next(phead);
5342 
5343 	while (1) {
5344 		if (rtw_end_of_queue_search(phead, plist) == _TRUE)
5345 			break;
5346 
5347 		if (uintPeerChannel != 0)
5348 			break;
5349 
5350 		pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
5351 
5352 		/*	Commented by Albert 2011/05/18 */
5353 		/*	Match the device address located in the P2P IE */
5354 		/*	This is for the case that the P2P device address is not the same as the P2P interface address. */
5355 
5356 		p2pie = rtw_bss_ex_get_p2p_ie(&pnetwork->network, NULL, &p2pielen);
5357 		if (p2pie) {
5358 			while (p2pie) {
5359 				/*	The P2P Device ID attribute is included in the Beacon frame. */
5360 				/*	The P2P Device Info attribute is included in the probe response frame. */
5361 				attr_contentlen = sizeof(attr_content);
5362 				if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_ID, attr_content, &attr_contentlen)) {
5363 					/*	Handle the P2P Device ID attribute of Beacon first */
5364 					if (_rtw_memcmp(attr_content, peerMAC, ETH_ALEN)) {
5365 						uintPeerChannel = pnetwork->network.Configuration.DSConfig;
5366 						break;
5367 					}
5368 				} else if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_INFO, attr_content, &attr_contentlen)) {
5369 					/*	Handle the P2P Device Info attribute of probe response */
5370 					if (_rtw_memcmp(attr_content, peerMAC, ETH_ALEN)) {
5371 						uintPeerChannel = pnetwork->network.Configuration.DSConfig;
5372 						break;
5373 					}
5374 				}
5375 
5376 				/* Get the next P2P IE */
5377 				p2pie = rtw_get_p2p_ie(p2pie + p2pielen, BSS_EX_TLV_IES_LEN(&pnetwork->network) - (p2pie + p2pielen - BSS_EX_TLV_IES(&pnetwork->network)), NULL, &p2pielen);
5378 			}
5379 
5380 		}
5381 
5382 		plist = get_next(plist);
5383 
5384 	}
5385 
5386 	_exit_critical_bh(&(pmlmepriv->scanned_queue.lock), &irqL);
5387 
5388 	if (uintPeerChannel) {
5389 #ifdef CONFIG_WFD
5390 		if (hal_chk_wl_func(padapter, WL_FUNC_MIRACAST)) {
5391 			struct wifi_display_info *pwfd_info = pwdinfo->wfd_info;
5392 			u8 *wfd_ie;
5393 			uint wfd_ielen = 0;
5394 
5395 			wfd_ie = rtw_bss_ex_get_wfd_ie(&pnetwork->network, NULL, &wfd_ielen);
5396 			if (wfd_ie) {
5397 				u8 *wfd_devinfo;
5398 				uint wfd_devlen;
5399 
5400 				RTW_INFO("[%s] Found WFD IE!\n", __FUNCTION__);
5401 				wfd_devinfo = rtw_get_wfd_attr_content(wfd_ie, wfd_ielen, WFD_ATTR_DEVICE_INFO, NULL, &wfd_devlen);
5402 				if (wfd_devinfo) {
5403 					u16	wfd_devinfo_field = 0;
5404 
5405 					/*	Commented by Albert 20120319 */
5406 					/*	The first two bytes are the WFD device information field of WFD device information subelement. */
5407 					/*	In big endian format. */
5408 					wfd_devinfo_field = RTW_GET_BE16(wfd_devinfo);
5409 					if (wfd_devinfo_field & WFD_DEVINFO_SESSION_AVAIL)
5410 						pwfd_info->peer_session_avail = _TRUE;
5411 					else
5412 						pwfd_info->peer_session_avail = _FALSE;
5413 				}
5414 			}
5415 
5416 			if (_FALSE == pwfd_info->peer_session_avail) {
5417 				RTW_INFO("[%s] WFD Session not avaiable!\n", __FUNCTION__);
5418 				goto exit;
5419 			}
5420 		}
5421 #endif /* CONFIG_WFD */
5422 
5423 		RTW_INFO("[%s] peer channel: %d!\n", __FUNCTION__, uintPeerChannel);
5424 #ifdef CONFIG_CONCURRENT_MODE
5425 		if (rtw_mi_check_status(padapter, MI_LINKED))
5426 			_cancel_timer_ex(&prochinfo->ap_roch_ch_switch_timer);
5427 #endif /* CONFIG_CONCURRENT_MODE */
5428 		_rtw_memcpy(pwdinfo->tx_prov_disc_info.peerIFAddr, pnetwork->network.MacAddress, ETH_ALEN);
5429 		_rtw_memcpy(pwdinfo->tx_prov_disc_info.peerDevAddr, peerMAC, ETH_ALEN);
5430 		pwdinfo->tx_prov_disc_info.peer_channel_num[0] = (u16) uintPeerChannel;
5431 		pwdinfo->tx_prov_disc_info.benable = _TRUE;
5432 		rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
5433 		rtw_p2p_set_state(pwdinfo, P2P_STATE_TX_PROVISION_DIS_REQ);
5434 
5435 		if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT))
5436 			_rtw_memcpy(&pwdinfo->tx_prov_disc_info.ssid, &pnetwork->network.Ssid, sizeof(NDIS_802_11_SSID));
5437 		else if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_DEVICE) || rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
5438 			_rtw_memcpy(pwdinfo->tx_prov_disc_info.ssid.Ssid, pwdinfo->p2p_wildcard_ssid, P2P_WILDCARD_SSID_LEN);
5439 			pwdinfo->tx_prov_disc_info.ssid.SsidLength = P2P_WILDCARD_SSID_LEN;
5440 		}
5441 
5442 #ifdef CONFIG_CONCURRENT_MODE
5443 		if (rtw_mi_check_status(padapter, MI_LINKED)) {
5444 			u8 union_ch = rtw_mi_get_union_chan(padapter);
5445 			u8 union_bw = rtw_mi_get_union_bw(padapter);
5446 			u8 union_offset = rtw_mi_get_union_offset(padapter);
5447 
5448 			set_channel_bwmode(padapter, union_ch, union_offset, union_bw);
5449 			rtw_leave_opch(padapter);
5450 
5451 		} else
5452 			set_channel_bwmode(padapter, uintPeerChannel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
5453 #else
5454 		set_channel_bwmode(padapter, uintPeerChannel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20);
5455 #endif
5456 
5457 		_set_timer(&pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT);
5458 
5459 #ifdef CONFIG_CONCURRENT_MODE
5460 		if (rtw_mi_check_status(padapter, MI_LINKED))
5461 			_set_timer(&pwdinfo->restore_p2p_state_timer, P2P_CONCURRENT_PROVISION_TIMEOUT);
5462 		else
5463 			_set_timer(&pwdinfo->restore_p2p_state_timer, P2P_PROVISION_TIMEOUT);
5464 #else
5465 		_set_timer(&pwdinfo->restore_p2p_state_timer, P2P_PROVISION_TIMEOUT);
5466 #endif /* CONFIG_CONCURRENT_MODE		 */
5467 
5468 	} else {
5469 		RTW_INFO("[%s] NOT Found in the Scanning Queue!\n", __FUNCTION__);
5470 	}
5471 exit:
5472 
5473 	return ret;
5474 
5475 }
5476 
5477 /*	Added by Albert 20110328
5478  *	This function is used to inform the driver the user had specified the pin code value or pbc
5479  *	to application. */
5480 
5481 static int rtw_p2p_got_wpsinfo(struct net_device *dev,
5482 			       struct iw_request_info *info,
5483 			       union iwreq_data *wrqu, char *extra)
5484 {
5485 
5486 	int ret = 0;
5487 	_adapter				*padapter = (_adapter *)rtw_netdev_priv(dev);
5488 	struct wifidirect_info	*pwdinfo = &(padapter->wdinfo);
5489 
5490 
5491 	RTW_INFO("[%s] data = %s\n", __FUNCTION__, extra);
5492 	/*	Added by Albert 20110328 */
5493 	/*	if the input data is P2P_NO_WPSINFO -> reset the wpsinfo */
5494 	/*	if the input data is P2P_GOT_WPSINFO_PEER_DISPLAY_PIN -> the utility just input the PIN code got from the peer P2P device. */
5495 	/*	if the input data is P2P_GOT_WPSINFO_SELF_DISPLAY_PIN -> the utility just got the PIN code from itself. */
5496 	/*	if the input data is P2P_GOT_WPSINFO_PBC -> the utility just determine to use the PBC */
5497 
5498 	if (*extra == '0')
5499 		pwdinfo->ui_got_wps_info = P2P_NO_WPSINFO;
5500 	else if (*extra == '1')
5501 		pwdinfo->ui_got_wps_info = P2P_GOT_WPSINFO_PEER_DISPLAY_PIN;
5502 	else if (*extra == '2')
5503 		pwdinfo->ui_got_wps_info = P2P_GOT_WPSINFO_SELF_DISPLAY_PIN;
5504 	else if (*extra == '3')
5505 		pwdinfo->ui_got_wps_info = P2P_GOT_WPSINFO_PBC;
5506 	else
5507 		pwdinfo->ui_got_wps_info = P2P_NO_WPSINFO;
5508 
5509 	return ret;
5510 
5511 }
5512 
5513 #endif /* CONFIG_P2P */
5514 
5515 static int rtw_p2p_set(struct net_device *dev,
5516 		       struct iw_request_info *info,
5517 		       union iwreq_data *wrqu, char *extra)
5518 {
5519 	int ret = 0;
5520 #ifdef CONFIG_P2P
5521 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
5522 
5523 	RTW_INFO("[%s] extra = %s\n", __FUNCTION__, extra);
5524 
5525 	if (_rtw_memcmp(extra, "enable=", 7))
5526 		rtw_wext_p2p_enable(dev, info, wrqu, &extra[7]);
5527 	else if (_rtw_memcmp(extra, "setDN=", 6)) {
5528 		wrqu->data.length -= 6;
5529 		rtw_p2p_setDN(dev, info, wrqu, &extra[6]);
5530 	} else if (_rtw_memcmp(extra, "profilefound=", 13)) {
5531 		wrqu->data.length -= 13;
5532 		rtw_p2p_profilefound(dev, info, wrqu, &extra[13]);
5533 	} else if (_rtw_memcmp(extra, "prov_disc=", 10)) {
5534 		wrqu->data.length -= 10;
5535 		rtw_p2p_prov_disc(dev, info, wrqu, &extra[10]);
5536 	} else if (_rtw_memcmp(extra, "nego=", 5)) {
5537 		wrqu->data.length -= 5;
5538 		rtw_p2p_connect(dev, info, wrqu, &extra[5]);
5539 	} else if (_rtw_memcmp(extra, "intent=", 7)) {
5540 		/*	Commented by Albert 2011/03/23 */
5541 		/*	The wrqu->data.length will include the null character */
5542 		/*	So, we will decrease 7 + 1 */
5543 		wrqu->data.length -= 8;
5544 		rtw_p2p_set_intent(dev, info, wrqu, &extra[7]);
5545 	} else if (_rtw_memcmp(extra, "ssid=", 5)) {
5546 		wrqu->data.length -= 5;
5547 		rtw_p2p_set_go_nego_ssid(dev, info, wrqu, &extra[5]);
5548 	} else if (_rtw_memcmp(extra, "got_wpsinfo=", 12)) {
5549 		wrqu->data.length -= 12;
5550 		rtw_p2p_got_wpsinfo(dev, info, wrqu, &extra[12]);
5551 	} else if (_rtw_memcmp(extra, "listen_ch=", 10)) {
5552 		/*	Commented by Albert 2011/05/24 */
5553 		/*	The wrqu->data.length will include the null character */
5554 		/*	So, we will decrease (10 + 1)	 */
5555 		wrqu->data.length -= 11;
5556 		rtw_p2p_set_listen_ch(dev, info, wrqu, &extra[10]);
5557 	} else if (_rtw_memcmp(extra, "op_ch=", 6)) {
5558 		/*	Commented by Albert 2011/05/24 */
5559 		/*	The wrqu->data.length will include the null character */
5560 		/*	So, we will decrease (6 + 1)	 */
5561 		wrqu->data.length -= 7;
5562 		rtw_p2p_set_op_ch(dev, info, wrqu, &extra[6]);
5563 	} else if (_rtw_memcmp(extra, "invite=", 7)) {
5564 		wrqu->data.length -= 8;
5565 		rtw_p2p_invite_req(dev, info, wrqu, &extra[7]);
5566 	} else if (_rtw_memcmp(extra, "persistent=", 11)) {
5567 		wrqu->data.length -= 11;
5568 		rtw_p2p_set_persistent(dev, info, wrqu, &extra[11]);
5569 	} else if (_rtw_memcmp(extra, "uuid=", 5)) {
5570 		wrqu->data.length -= 5;
5571 		ret = rtw_p2p_set_wps_uuid(dev, info, wrqu, &extra[5]);
5572 	}
5573 
5574 #ifdef CONFIG_WFD
5575 	if (hal_chk_wl_func(padapter, WL_FUNC_MIRACAST)) {
5576 		if (_rtw_memcmp(extra, "sa=", 3)) {
5577 			/* sa: WFD Session Available information */
5578 			wrqu->data.length -= 3;
5579 			rtw_p2p_set_sa(dev, info, wrqu, &extra[3]);
5580 		} else if (_rtw_memcmp(extra, "pc=", 3)) {
5581 			/* pc: WFD Preferred Connection */
5582 			wrqu->data.length -= 3;
5583 			rtw_p2p_set_pc(dev, info, wrqu, &extra[3]);
5584 		} else if (_rtw_memcmp(extra, "wfd_type=", 9)) {
5585 			wrqu->data.length -= 9;
5586 			rtw_p2p_set_wfd_device_type(dev, info, wrqu, &extra[9]);
5587 		} else if (_rtw_memcmp(extra, "wfd_enable=", 11)) {
5588 			wrqu->data.length -= 11;
5589 			rtw_p2p_set_wfd_enable(dev, info, wrqu, &extra[11]);
5590 		} else if (_rtw_memcmp(extra, "driver_iface=", 13)) {
5591 			wrqu->data.length -= 13;
5592 			rtw_p2p_set_driver_iface(dev, info, wrqu, &extra[13]);
5593 		}
5594 	}
5595 #endif /* CONFIG_WFD */
5596 
5597 #endif /* CONFIG_P2P */
5598 
5599 	return ret;
5600 
5601 }
5602 
5603 static int rtw_p2p_get(struct net_device *dev,
5604 		       struct iw_request_info *info,
5605 		       union iwreq_data *wrqu, char *extra)
5606 {
5607 	int ret = 0;
5608 #ifdef CONFIG_P2P
5609 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
5610 
5611 	if (padapter->bShowGetP2PState)
5612 		RTW_INFO("[%s] extra = %s\n", __FUNCTION__, (char *) wrqu->data.pointer);
5613 
5614 	if (_rtw_memcmp(wrqu->data.pointer, "status", 6))
5615 		rtw_p2p_get_status(dev, info, wrqu, extra);
5616 	else if (_rtw_memcmp(wrqu->data.pointer, "role", 4))
5617 		rtw_p2p_get_role(dev, info, wrqu, extra);
5618 	else if (_rtw_memcmp(wrqu->data.pointer, "peer_ifa", 8))
5619 		rtw_p2p_get_peer_ifaddr(dev, info, wrqu, extra);
5620 	else if (_rtw_memcmp(wrqu->data.pointer, "req_cm", 6))
5621 		rtw_p2p_get_req_cm(dev, info, wrqu, extra);
5622 	else if (_rtw_memcmp(wrqu->data.pointer, "peer_deva", 9)) {
5623 		/*	Get the P2P device address when receiving the provision discovery request frame. */
5624 		rtw_p2p_get_peer_devaddr(dev, info, wrqu, extra);
5625 	} else if (_rtw_memcmp(wrqu->data.pointer, "group_id", 8))
5626 		rtw_p2p_get_groupid(dev, info, wrqu, extra);
5627 	else if (_rtw_memcmp(wrqu->data.pointer, "inv_peer_deva", 13)) {
5628 		/*	Get the P2P device address when receiving the P2P Invitation request frame. */
5629 		rtw_p2p_get_peer_devaddr_by_invitation(dev, info, wrqu, extra);
5630 	} else if (_rtw_memcmp(wrqu->data.pointer, "op_ch", 5))
5631 		rtw_p2p_get_op_ch(dev, info, wrqu, extra);
5632 
5633 #ifdef CONFIG_WFD
5634 	if (hal_chk_wl_func(padapter, WL_FUNC_MIRACAST)) {
5635 		if (_rtw_memcmp(wrqu->data.pointer, "peer_port", 9))
5636 			rtw_p2p_get_peer_wfd_port(dev, info, wrqu, extra);
5637 		else if (_rtw_memcmp(wrqu->data.pointer, "wfd_sa", 6))
5638 			rtw_p2p_get_peer_wfd_session_available(dev, info, wrqu, extra);
5639 		else if (_rtw_memcmp(wrqu->data.pointer, "wfd_pc", 6))
5640 			rtw_p2p_get_peer_wfd_preferred_connection(dev, info, wrqu, extra);
5641 	}
5642 #endif /* CONFIG_WFD */
5643 
5644 #endif /* CONFIG_P2P */
5645 
5646 	return ret;
5647 
5648 }
5649 
5650 static int rtw_p2p_get2(struct net_device *dev,
5651 			struct iw_request_info *info,
5652 			union iwreq_data *wrqu, char *extra)
5653 {
5654 
5655 	int ret = 0;
5656 
5657 #ifdef CONFIG_P2P
5658 
5659 	int length = wrqu->data.length;
5660 	char *buffer = (u8 *)rtw_malloc(length);
5661 
5662 	if (buffer == NULL) {
5663 		ret = -ENOMEM;
5664 		goto bad;
5665 	}
5666 
5667 	if (copy_from_user(buffer, wrqu->data.pointer, wrqu->data.length)) {
5668 		ret = -EFAULT;
5669 		goto bad;
5670 	}
5671 
5672 	RTW_INFO("[%s] buffer = %s\n", __FUNCTION__, buffer);
5673 
5674 	if (_rtw_memcmp(buffer, "wpsCM=", 6))
5675 		ret = rtw_p2p_get_wps_configmethod(dev, info, wrqu, extra, &buffer[6]);
5676 	else if (_rtw_memcmp(buffer, "devN=", 5))
5677 		ret = rtw_p2p_get_device_name(dev, info, wrqu, extra, &buffer[5]);
5678 	else if (_rtw_memcmp(buffer, "dev_type=", 9))
5679 		ret = rtw_p2p_get_device_type(dev, info, wrqu, extra, &buffer[9]);
5680 	else if (_rtw_memcmp(buffer, "go_devadd=", 10))
5681 		ret = rtw_p2p_get_go_device_address(dev, info, wrqu, extra, &buffer[10]);
5682 	else if (_rtw_memcmp(buffer, "InvProc=", 8))
5683 		ret = rtw_p2p_get_invitation_procedure(dev, info, wrqu, extra, &buffer[8]);
5684 	else {
5685 		snprintf(extra, sizeof("Command not found."), "Command not found.");
5686 		wrqu->data.length = strlen(extra);
5687 	}
5688 
5689 bad:
5690 	if (buffer)
5691 		rtw_mfree(buffer, length);
5692 
5693 #endif /* CONFIG_P2P */
5694 
5695 	return ret;
5696 
5697 }
5698 
5699 #ifdef CONFIG_MP_INCLUDED
5700 static int rtw_cta_test_start(struct net_device *dev,
5701 			      struct iw_request_info *info,
5702 			      union iwreq_data *wrqu, char *extra)
5703 {
5704 	int ret = 0;
5705 	_adapter	*padapter = (_adapter *)rtw_netdev_priv(dev);
5706 	HAL_DATA_TYPE *hal_data = GET_HAL_DATA(padapter);
5707 
5708 	RTW_INFO("%s %s\n", __func__, extra);
5709 	if (!strcmp(extra, "1"))
5710 		hal_data->in_cta_test = 1;
5711 	else
5712 		hal_data->in_cta_test = 0;
5713 
5714 	rtw_hal_rcr_set_chk_bssid(padapter, MLME_ACTION_NONE);
5715 
5716 	return ret;
5717 }
5718 #endif
5719 
5720 #ifdef CONFIG_IOL
5721 #include <rtw_iol.h>
5722 #endif
5723 #ifdef CONFIG_BACKGROUND_NOISE_MONITOR
5724 #include "../../hal/hal_dm_acs.h"
5725 #endif
5726 #ifdef DBG_CMD_QUEUE
5727 u8 dump_cmd_id = 0;
5728 #endif
5729 
5730 static int rtw_dbg_port(struct net_device *dev,
5731 			struct iw_request_info *info,
5732 			union iwreq_data *wrqu, char *extra)
5733 {
5734 	int ret = 0;
5735 #ifdef CONFIG_RTW_DEBUG
5736 	_irqL irqL;
5737 	u8 major_cmd, minor_cmd;
5738 	u16 arg;
5739 	u32 extra_arg, *pdata, val32;
5740 	struct sta_info *psta;
5741 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
5742 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
5743 	struct mlme_ext_priv	*pmlmeext = &padapter->mlmeextpriv;
5744 	struct mlme_ext_info	*pmlmeinfo = &(pmlmeext->mlmext_info);
5745 	struct security_priv *psecuritypriv = &padapter->securitypriv;
5746 	struct wlan_network *cur_network = &(pmlmepriv->cur_network);
5747 	struct sta_priv *pstapriv = &padapter->stapriv;
5748 
5749 
5750 	pdata = (u32 *)&wrqu->data;
5751 
5752 	val32 = *pdata;
5753 	arg = (u16)(val32 & 0x0000ffff);
5754 	major_cmd = (u8)(val32 >> 24);
5755 	minor_cmd = (u8)((val32 >> 16) & 0x00ff);
5756 
5757 	extra_arg = *(pdata + 1);
5758 
5759 	switch (major_cmd) {
5760 	case 0x70: /* read_reg */
5761 		switch (minor_cmd) {
5762 		case 1:
5763 			RTW_INFO("rtw_read8(0x%x)=0x%02x\n", arg, rtw_read8(padapter, arg));
5764 			break;
5765 		case 2:
5766 			RTW_INFO("rtw_read16(0x%x)=0x%04x\n", arg, rtw_read16(padapter, arg));
5767 			break;
5768 		case 4:
5769 			RTW_INFO("rtw_read32(0x%x)=0x%08x\n", arg, rtw_read32(padapter, arg));
5770 			break;
5771 		}
5772 		break;
5773 	case 0x71: /* write_reg */
5774 		switch (minor_cmd) {
5775 		case 1:
5776 			rtw_write8(padapter, arg, extra_arg);
5777 			RTW_INFO("rtw_write8(0x%x)=0x%02x\n", arg, rtw_read8(padapter, arg));
5778 			break;
5779 		case 2:
5780 			rtw_write16(padapter, arg, extra_arg);
5781 			RTW_INFO("rtw_write16(0x%x)=0x%04x\n", arg, rtw_read16(padapter, arg));
5782 			break;
5783 		case 4:
5784 			rtw_write32(padapter, arg, extra_arg);
5785 			RTW_INFO("rtw_write32(0x%x)=0x%08x\n", arg, rtw_read32(padapter, arg));
5786 			break;
5787 		}
5788 		break;
5789 	case 0x72: /* read_bb */
5790 		RTW_INFO("read_bbreg(0x%x)=0x%x\n", arg, rtw_hal_read_bbreg(padapter, arg, 0xffffffff));
5791 		break;
5792 	case 0x73: /* write_bb */
5793 		rtw_hal_write_bbreg(padapter, arg, 0xffffffff, extra_arg);
5794 		RTW_INFO("write_bbreg(0x%x)=0x%x\n", arg, rtw_hal_read_bbreg(padapter, arg, 0xffffffff));
5795 		break;
5796 	case 0x74: /* read_rf */
5797 		RTW_INFO("read RF_reg path(0x%02x),offset(0x%x),value(0x%08x)\n", minor_cmd, arg, rtw_hal_read_rfreg(padapter, minor_cmd, arg, 0xffffffff));
5798 		break;
5799 	case 0x75: /* write_rf */
5800 		rtw_hal_write_rfreg(padapter, minor_cmd, arg, 0xffffffff, extra_arg);
5801 		RTW_INFO("write RF_reg path(0x%02x),offset(0x%x),value(0x%08x)\n", minor_cmd, arg, rtw_hal_read_rfreg(padapter, minor_cmd, arg, 0xffffffff));
5802 		break;
5803 
5804 	case 0x76:
5805 		switch (minor_cmd) {
5806 		case 0x00: /* normal mode, */
5807 			padapter->recvpriv.is_signal_dbg = 0;
5808 			break;
5809 		case 0x01: /* dbg mode */
5810 			padapter->recvpriv.is_signal_dbg = 1;
5811 			extra_arg = extra_arg > 100 ? 100 : extra_arg;
5812 			padapter->recvpriv.signal_strength_dbg = extra_arg;
5813 			break;
5814 		}
5815 		break;
5816 	case 0x78: /* IOL test */
5817 		switch (minor_cmd) {
5818 		#ifdef CONFIG_IOL
5819 		case 0x04: { /* LLT table initialization test */
5820 			u8 page_boundary = 0xf9;
5821 			{
5822 				struct xmit_frame	*xmit_frame;
5823 
5824 				xmit_frame = rtw_IOL_accquire_xmit_frame(padapter);
5825 				if (xmit_frame == NULL) {
5826 					ret = -ENOMEM;
5827 					break;
5828 				}
5829 
5830 				rtw_IOL_append_LLT_cmd(xmit_frame, page_boundary);
5831 
5832 
5833 				if (_SUCCESS != rtw_IOL_exec_cmds_sync(padapter, xmit_frame, 500, 0))
5834 					ret = -EPERM;
5835 			}
5836 		}
5837 			break;
5838 		case 0x05: { /* blink LED test */
5839 			u16 reg = 0x4c;
5840 			u32 blink_num = 50;
5841 			u32 blink_delay_ms = 200;
5842 			int i;
5843 
5844 			{
5845 				struct xmit_frame	*xmit_frame;
5846 
5847 				xmit_frame = rtw_IOL_accquire_xmit_frame(padapter);
5848 				if (xmit_frame == NULL) {
5849 					ret = -ENOMEM;
5850 					break;
5851 				}
5852 
5853 				for (i = 0; i < blink_num; i++) {
5854 					#ifdef CONFIG_IOL_NEW_GENERATION
5855 					rtw_IOL_append_WB_cmd(xmit_frame, reg, 0x00, 0xff);
5856 					rtw_IOL_append_DELAY_MS_cmd(xmit_frame, blink_delay_ms);
5857 					rtw_IOL_append_WB_cmd(xmit_frame, reg, 0x08, 0xff);
5858 					rtw_IOL_append_DELAY_MS_cmd(xmit_frame, blink_delay_ms);
5859 					#else
5860 					rtw_IOL_append_WB_cmd(xmit_frame, reg, 0x00);
5861 					rtw_IOL_append_DELAY_MS_cmd(xmit_frame, blink_delay_ms);
5862 					rtw_IOL_append_WB_cmd(xmit_frame, reg, 0x08);
5863 					rtw_IOL_append_DELAY_MS_cmd(xmit_frame, blink_delay_ms);
5864 					#endif
5865 				}
5866 				if (_SUCCESS != rtw_IOL_exec_cmds_sync(padapter, xmit_frame, (blink_delay_ms * blink_num * 2) + 200, 0))
5867 					ret = -EPERM;
5868 			}
5869 		}
5870 			break;
5871 
5872 		case 0x06: { /* continuous wirte byte test */
5873 			u16 reg = arg;
5874 			u16 start_value = 0;
5875 			u32 write_num = extra_arg;
5876 			int i;
5877 			u8 final;
5878 
5879 			{
5880 				struct xmit_frame	*xmit_frame;
5881 
5882 				xmit_frame = rtw_IOL_accquire_xmit_frame(padapter);
5883 				if (xmit_frame == NULL) {
5884 					ret = -ENOMEM;
5885 					break;
5886 				}
5887 
5888 				for (i = 0; i < write_num; i++) {
5889 					#ifdef CONFIG_IOL_NEW_GENERATION
5890 					rtw_IOL_append_WB_cmd(xmit_frame, reg, i + start_value, 0xFF);
5891 					#else
5892 					rtw_IOL_append_WB_cmd(xmit_frame, reg, i + start_value);
5893 					#endif
5894 				}
5895 				if (_SUCCESS != rtw_IOL_exec_cmds_sync(padapter, xmit_frame, 5000, 0))
5896 					ret = -EPERM;
5897 			}
5898 
5899 			final = rtw_read8(padapter, reg);
5900 			if (start_value + write_num - 1 == final)
5901 				RTW_INFO("continuous IOL_CMD_WB_REG to 0x%x %u times Success, start:%u, final:%u\n", reg, write_num, start_value, final);
5902 			else
5903 				RTW_INFO("continuous IOL_CMD_WB_REG to 0x%x %u times Fail, start:%u, final:%u\n", reg, write_num, start_value, final);
5904 		}
5905 			break;
5906 
5907 		case 0x07: { /* continuous wirte word test */
5908 			u16 reg = arg;
5909 			u16 start_value = 200;
5910 			u32 write_num = extra_arg;
5911 
5912 			int i;
5913 			u16 final;
5914 
5915 			{
5916 				struct xmit_frame	*xmit_frame;
5917 
5918 				xmit_frame = rtw_IOL_accquire_xmit_frame(padapter);
5919 				if (xmit_frame == NULL) {
5920 					ret = -ENOMEM;
5921 					break;
5922 				}
5923 
5924 				for (i = 0; i < write_num; i++) {
5925 					#ifdef CONFIG_IOL_NEW_GENERATION
5926 					rtw_IOL_append_WW_cmd(xmit_frame, reg, i + start_value, 0xFFFF);
5927 					#else
5928 					rtw_IOL_append_WW_cmd(xmit_frame, reg, i + start_value);
5929 					#endif
5930 				}
5931 				if (_SUCCESS != rtw_IOL_exec_cmds_sync(padapter, xmit_frame, 5000, 0))
5932 					ret = -EPERM;
5933 			}
5934 
5935 			final = rtw_read16(padapter, reg);
5936 			if (start_value + write_num - 1 == final)
5937 				RTW_INFO("continuous IOL_CMD_WW_REG to 0x%x %u times Success, start:%u, final:%u\n", reg, write_num, start_value, final);
5938 			else
5939 				RTW_INFO("continuous IOL_CMD_WW_REG to 0x%x %u times Fail, start:%u, final:%u\n", reg, write_num, start_value, final);
5940 		}
5941 			break;
5942 
5943 		case 0x08: { /* continuous wirte dword test */
5944 			u16 reg = arg;
5945 			u32 start_value = 0x110000c7;
5946 			u32 write_num = extra_arg;
5947 
5948 			int i;
5949 			u32 final;
5950 
5951 			{
5952 				struct xmit_frame	*xmit_frame;
5953 
5954 				xmit_frame = rtw_IOL_accquire_xmit_frame(padapter);
5955 				if (xmit_frame == NULL) {
5956 					ret = -ENOMEM;
5957 					break;
5958 				}
5959 
5960 				for (i = 0; i < write_num; i++) {
5961 					#ifdef CONFIG_IOL_NEW_GENERATION
5962 					rtw_IOL_append_WD_cmd(xmit_frame, reg, i + start_value, 0xFFFFFFFF);
5963 					#else
5964 					rtw_IOL_append_WD_cmd(xmit_frame, reg, i + start_value);
5965 					#endif
5966 				}
5967 				if (_SUCCESS != rtw_IOL_exec_cmds_sync(padapter, xmit_frame, 5000, 0))
5968 					ret = -EPERM;
5969 
5970 			}
5971 
5972 			final = rtw_read32(padapter, reg);
5973 			if (start_value + write_num - 1 == final)
5974 				RTW_INFO("continuous IOL_CMD_WD_REG to 0x%x %u times Success, start:%u, final:%u\n", reg, write_num, start_value, final);
5975 			else
5976 				RTW_INFO("continuous IOL_CMD_WD_REG to 0x%x %u times Fail, start:%u, final:%u\n", reg, write_num, start_value, final);
5977 		}
5978 			break;
5979 		#endif /* CONFIG_IOL */
5980 		}
5981 		break;
5982 	case 0x79: {
5983 		/*
5984 		* dbg 0x79000000 [value], set RESP_TXAGC to + value, value:0~15
5985 		* dbg 0x79010000 [value], set RESP_TXAGC to - value, value:0~15
5986 		*/
5987 		u8 value =  extra_arg & 0x0f;
5988 		u8 sign = minor_cmd;
5989 		u16 write_value = 0;
5990 
5991 		RTW_INFO("%s set RESP_TXAGC to %s %u\n", __func__, sign ? "minus" : "plus", value);
5992 
5993 		if (sign)
5994 			value = value | 0x10;
5995 
5996 		write_value = value | (value << 5);
5997 		rtw_write16(padapter, 0x6d9, write_value);
5998 	}
5999 		break;
6000 	case 0x7a:
6001 		receive_disconnect(padapter, pmlmeinfo->network.MacAddress
6002 				   , WLAN_REASON_EXPIRATION_CHK, _FALSE);
6003 		break;
6004 	case 0x7F:
6005 		switch (minor_cmd) {
6006 		case 0x0:
6007 			RTW_INFO("fwstate=0x%x\n", get_fwstate(pmlmepriv));
6008 			break;
6009 		case 0x01:
6010 			RTW_INFO("auth_alg=0x%x, enc_alg=0x%x, auth_type=0x%x, enc_type=0x%x\n",
6011 				psecuritypriv->dot11AuthAlgrthm, psecuritypriv->dot11PrivacyAlgrthm,
6012 				psecuritypriv->ndisauthtype, psecuritypriv->ndisencryptstatus);
6013 			break;
6014 		case 0x03:
6015 			RTW_INFO("qos_option=%d\n", pmlmepriv->qospriv.qos_option);
6016 #ifdef CONFIG_80211N_HT
6017 			RTW_INFO("ht_option=%d\n", pmlmepriv->htpriv.ht_option);
6018 #endif /* CONFIG_80211N_HT */
6019 			break;
6020 		case 0x04:
6021 			RTW_INFO("cur_ch=%d\n", pmlmeext->cur_channel);
6022 			RTW_INFO("cur_bw=%d\n", pmlmeext->cur_bwmode);
6023 			RTW_INFO("cur_ch_off=%d\n", pmlmeext->cur_ch_offset);
6024 
6025 			RTW_INFO("oper_ch=%d\n", rtw_get_oper_ch(padapter));
6026 			RTW_INFO("oper_bw=%d\n", rtw_get_oper_bw(padapter));
6027 			RTW_INFO("oper_ch_offet=%d\n", rtw_get_oper_choffset(padapter));
6028 
6029 			break;
6030 		case 0x05:
6031 			psta = rtw_get_stainfo(pstapriv, cur_network->network.MacAddress);
6032 			if (psta) {
6033 				RTW_INFO("SSID=%s\n", cur_network->network.Ssid.Ssid);
6034 				RTW_INFO("sta's macaddr:" MAC_FMT "\n", MAC_ARG(psta->cmn.mac_addr));
6035 				RTW_INFO("cur_channel=%d, cur_bwmode=%d, cur_ch_offset=%d\n", pmlmeext->cur_channel, pmlmeext->cur_bwmode, pmlmeext->cur_ch_offset);
6036 				RTW_INFO("rtsen=%d, cts2slef=%d\n", psta->rtsen, psta->cts2self);
6037 				RTW_INFO("state=0x%x, aid=%d, macid=%d, raid=%d\n",
6038 					psta->state, psta->cmn.aid, psta->cmn.mac_id, psta->cmn.ra_info.rate_id);
6039 #ifdef CONFIG_80211N_HT
6040 				RTW_INFO("qos_en=%d, ht_en=%d, init_rate=%d\n", psta->qos_option, psta->htpriv.ht_option, psta->init_rate);
6041 				RTW_INFO("bwmode=%d, ch_offset=%d, sgi_20m=%d,sgi_40m=%d\n"
6042 					, psta->cmn.bw_mode, psta->htpriv.ch_offset, psta->htpriv.sgi_20m, psta->htpriv.sgi_40m);
6043 				RTW_INFO("ampdu_enable = %d\n", psta->htpriv.ampdu_enable);
6044 				RTW_INFO("agg_enable_bitmap=%x, candidate_tid_bitmap=%x\n", psta->htpriv.agg_enable_bitmap, psta->htpriv.candidate_tid_bitmap);
6045 #endif /* CONFIG_80211N_HT */
6046 
6047 				sta_rx_reorder_ctl_dump(RTW_DBGDUMP, psta);
6048 			} else
6049 				RTW_INFO("can't get sta's macaddr, cur_network's macaddr:" MAC_FMT "\n", MAC_ARG(cur_network->network.MacAddress));
6050 			break;
6051 		case 0x06: {
6052 				u64 tsf = 0;
6053 
6054 				tsf = rtw_hal_get_tsftr_by_port(padapter, extra_arg);
6055 				RTW_INFO(" PORT-%d TSF :%21lld\n", extra_arg, tsf);
6056 		}
6057 			break;
6058 		case 0x07:
6059 			RTW_INFO("bSurpriseRemoved=%s, bDriverStopped=%s\n"
6060 				, rtw_is_surprise_removed(padapter) ? "True" : "False"
6061 				, rtw_is_drv_stopped(padapter) ? "True" : "False");
6062 			break;
6063 		case 0x08: {
6064 			struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
6065 			struct recv_priv  *precvpriv = &padapter->recvpriv;
6066 
6067 			RTW_INFO("free_xmitbuf_cnt=%d, free_xmitframe_cnt=%d"
6068 				", free_xmit_extbuf_cnt=%d, free_xframe_ext_cnt=%d"
6069 				 ", free_recvframe_cnt=%d\n",
6070 				pxmitpriv->free_xmitbuf_cnt, pxmitpriv->free_xmitframe_cnt,
6071 				pxmitpriv->free_xmit_extbuf_cnt, pxmitpriv->free_xframe_ext_cnt,
6072 				 precvpriv->free_recvframe_cnt);
6073 #ifdef CONFIG_USB_HCI
6074 			RTW_INFO("rx_urb_pending_cn=%d\n", ATOMIC_READ(&(precvpriv->rx_pending_cnt)));
6075 #endif
6076 		}
6077 			break;
6078 		case 0x09: {
6079 			int i;
6080 			_list	*plist, *phead;
6081 
6082 #ifdef CONFIG_AP_MODE
6083 			RTW_INFO_DUMP("sta_dz_bitmap:", pstapriv->sta_dz_bitmap, pstapriv->aid_bmp_len);
6084 			RTW_INFO_DUMP("tim_bitmap:", pstapriv->tim_bitmap, pstapriv->aid_bmp_len);
6085 #endif
6086 			_enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
6087 
6088 			for (i = 0; i < NUM_STA; i++) {
6089 				phead = &(pstapriv->sta_hash[i]);
6090 				plist = get_next(phead);
6091 
6092 				while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
6093 					psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
6094 
6095 					plist = get_next(plist);
6096 
6097 					if (extra_arg == psta->cmn.aid) {
6098 						RTW_INFO("sta's macaddr:" MAC_FMT "\n", MAC_ARG(psta->cmn.mac_addr));
6099 						RTW_INFO("rtsen=%d, cts2slef=%d\n", psta->rtsen, psta->cts2self);
6100 						RTW_INFO("state=0x%x, aid=%d, macid=%d, raid=%d\n",
6101 							psta->state, psta->cmn.aid, psta->cmn.mac_id, psta->cmn.ra_info.rate_id);
6102 #ifdef CONFIG_80211N_HT
6103 						RTW_INFO("qos_en=%d, ht_en=%d, init_rate=%d\n", psta->qos_option, psta->htpriv.ht_option, psta->init_rate);
6104 						RTW_INFO("bwmode=%d, ch_offset=%d, sgi_20m=%d,sgi_40m=%d\n",
6105 							psta->cmn.bw_mode, psta->htpriv.ch_offset, psta->htpriv.sgi_20m,
6106 							psta->htpriv.sgi_40m);
6107 						RTW_INFO("ampdu_enable = %d\n", psta->htpriv.ampdu_enable);
6108 						RTW_INFO("agg_enable_bitmap=%x, candidate_tid_bitmap=%x\n", psta->htpriv.agg_enable_bitmap, psta->htpriv.candidate_tid_bitmap);
6109 #endif /* CONFIG_80211N_HT */
6110 
6111 #ifdef CONFIG_AP_MODE
6112 						RTW_INFO("capability=0x%x\n", psta->capability);
6113 						RTW_INFO("flags=0x%x\n", psta->flags);
6114 						RTW_INFO("wpa_psk=0x%x\n", psta->wpa_psk);
6115 						RTW_INFO("wpa2_group_cipher=0x%x\n", psta->wpa2_group_cipher);
6116 						RTW_INFO("wpa2_pairwise_cipher=0x%x\n", psta->wpa2_pairwise_cipher);
6117 						RTW_INFO("qos_info=0x%x\n", psta->qos_info);
6118 #endif
6119 						RTW_INFO("dot118021XPrivacy=0x%x\n", psta->dot118021XPrivacy);
6120 
6121 						sta_rx_reorder_ctl_dump(RTW_DBGDUMP, psta);
6122 					}
6123 
6124 				}
6125 			}
6126 
6127 			_exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
6128 
6129 		}
6130 			break;
6131 
6132 		case 0x0b: { /* Enable=1, Disable=0 driver control vrtl_carrier_sense. */
6133 			/* u8 driver_vcs_en; */ /* Enable=1, Disable=0 driver control vrtl_carrier_sense. */
6134 			/* u8 driver_vcs_type; */ /* force 0:disable VCS, 1:RTS-CTS, 2:CTS-to-self when vcs_en=1. */
6135 
6136 			if (arg == 0) {
6137 				RTW_INFO("disable driver ctrl vcs\n");
6138 				padapter->driver_vcs_en = 0;
6139 			} else if (arg == 1) {
6140 				RTW_INFO("enable driver ctrl vcs = %d\n", extra_arg);
6141 				padapter->driver_vcs_en = 1;
6142 
6143 				if (extra_arg > 2)
6144 					padapter->driver_vcs_type = 1;
6145 				else
6146 					padapter->driver_vcs_type = extra_arg;
6147 			}
6148 		}
6149 			break;
6150 		case 0x0c: { /* dump rx/tx packet */
6151 			if (arg == 0) {
6152 				RTW_INFO("dump rx packet (%d)\n", extra_arg);
6153 				/* pHalData->bDumpRxPkt =extra_arg;						 */
6154 				rtw_hal_set_def_var(padapter, HAL_DEF_DBG_DUMP_RXPKT, &(extra_arg));
6155 			} else if (arg == 1) {
6156 				RTW_INFO("dump tx packet (%d)\n", extra_arg);
6157 				rtw_hal_set_def_var(padapter, HAL_DEF_DBG_DUMP_TXPKT, &(extra_arg));
6158 			}
6159 		}
6160 			break;
6161 		case 0x0e: {
6162 			if (arg == 0) {
6163 				RTW_INFO("disable driver ctrl rx_ampdu_factor\n");
6164 				padapter->driver_rx_ampdu_factor = 0xFF;
6165 			} else if (arg == 1) {
6166 
6167 				RTW_INFO("enable driver ctrl rx_ampdu_factor = %d\n", extra_arg);
6168 
6169 				if (extra_arg > 0x03)
6170 					padapter->driver_rx_ampdu_factor = 0xFF;
6171 				else
6172 					padapter->driver_rx_ampdu_factor = extra_arg;
6173 			}
6174 		}
6175 			break;
6176 		#ifdef DBG_CONFIG_ERROR_DETECT
6177 		case 0x0f: {
6178 			if (extra_arg == 0) {
6179 				RTW_INFO("###### silent reset test.......#####\n");
6180 				rtw_hal_sreset_reset(padapter);
6181 			} else {
6182 				HAL_DATA_TYPE	*pHalData = GET_HAL_DATA(padapter);
6183 				struct sreset_priv *psrtpriv = &pHalData->srestpriv;
6184 				psrtpriv->dbg_trigger_point = extra_arg;
6185 			}
6186 
6187 		}
6188 			break;
6189 		case 0x15: {
6190 			struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
6191 			RTW_INFO("==>silent resete cnts:%d\n", pwrpriv->ips_enter_cnts);
6192 		}
6193 			break;
6194 
6195 		#endif
6196 
6197 		case 0x10: /* driver version display */
6198 			dump_drv_version(RTW_DBGDUMP);
6199 			break;
6200 		case 0x11: { /* dump linked status */
6201 			int pre_mode;
6202 			pre_mode = padapter->bLinkInfoDump;
6203 			/* linked_info_dump(padapter,extra_arg); */
6204 			if (extra_arg == 1 || (extra_arg == 0 && pre_mode == 1)) /* not consider pwr_saving 0: */
6205 				padapter->bLinkInfoDump = extra_arg;
6206 
6207 			else if ((extra_arg == 2) || (extra_arg == 0 && pre_mode == 2)) { /* consider power_saving */
6208 				/* RTW_INFO("linked_info_dump =%s\n", (padapter->bLinkInfoDump)?"enable":"disable") */
6209 				linked_info_dump(padapter, extra_arg);
6210 			}
6211 
6212 
6213 
6214 		}
6215 			break;
6216 #ifdef CONFIG_80211N_HT
6217 		case 0x12: { /* set rx_stbc */
6218 			struct registry_priv	*pregpriv = &padapter->registrypriv;
6219 			/* 0: disable, bit(0):enable 2.4g, bit(1):enable 5g, 0x3: enable both 2.4g and 5g */
6220 			/* default is set to enable 2.4GHZ for IOT issue with bufflao's AP at 5GHZ */
6221 			if (pregpriv && (extra_arg == 0 || extra_arg == 1 || extra_arg == 2 || extra_arg == 3)) {
6222 				pregpriv->rx_stbc = extra_arg;
6223 				RTW_INFO("set rx_stbc=%d\n", pregpriv->rx_stbc);
6224 			} else
6225 				RTW_INFO("get rx_stbc=%d\n", pregpriv->rx_stbc);
6226 
6227 		}
6228 			break;
6229 		case 0x13: { /* set ampdu_enable */
6230 			struct registry_priv	*pregpriv = &padapter->registrypriv;
6231 			/* 0: disable, 0x1:enable */
6232 			if (pregpriv && extra_arg < 2) {
6233 				pregpriv->ampdu_enable = extra_arg;
6234 				RTW_INFO("set ampdu_enable=%d\n", pregpriv->ampdu_enable);
6235 			} else
6236 				RTW_INFO("get ampdu_enable=%d\n", pregpriv->ampdu_enable);
6237 
6238 		}
6239 			break;
6240 #endif
6241 		case 0x14: { /* get wifi_spec */
6242 			struct registry_priv	*pregpriv = &padapter->registrypriv;
6243 			RTW_INFO("get wifi_spec=%d\n", pregpriv->wifi_spec);
6244 
6245 		}
6246 			break;
6247 
6248 #ifdef DBG_FIXED_CHAN
6249 		case 0x17: {
6250 			struct mlme_ext_priv	*pmlmeext = &(padapter->mlmeextpriv);
6251 			printk("===>  Fixed channel to %d\n", extra_arg);
6252 			pmlmeext->fixed_chan = extra_arg;
6253 
6254 		}
6255 			break;
6256 #endif
6257 #ifdef CONFIG_80211N_HT
6258 		case 0x19: {
6259 			struct registry_priv	*pregistrypriv = &padapter->registrypriv;
6260 			/* extra_arg : */
6261 			/* BIT0: Enable VHT LDPC Rx, BIT1: Enable VHT LDPC Tx, */
6262 			/* BIT4: Enable HT LDPC Rx, BIT5: Enable HT LDPC Tx */
6263 			if (arg == 0) {
6264 				RTW_INFO("driver disable LDPC\n");
6265 				pregistrypriv->ldpc_cap = 0x00;
6266 			} else if (arg == 1) {
6267 				RTW_INFO("driver set LDPC cap = 0x%x\n", extra_arg);
6268 				pregistrypriv->ldpc_cap = (u8)(extra_arg & 0x33);
6269 			}
6270 		}
6271 			break;
6272 		case 0x1a: {
6273 			struct registry_priv	*pregistrypriv = &padapter->registrypriv;
6274 			/* extra_arg : */
6275 			/* BIT0: Enable VHT STBC Rx, BIT1: Enable VHT STBC Tx, */
6276 			/* BIT4: Enable HT STBC Rx, BIT5: Enable HT STBC Tx */
6277 			if (arg == 0) {
6278 				RTW_INFO("driver disable STBC\n");
6279 				pregistrypriv->stbc_cap = 0x00;
6280 			} else if (arg == 1) {
6281 				RTW_INFO("driver set STBC cap = 0x%x\n", extra_arg);
6282 				pregistrypriv->stbc_cap = (u8)(extra_arg & 0x33);
6283 			}
6284 		}
6285 			break;
6286 #endif /* CONFIG_80211N_HT */
6287 		case 0x1b: {
6288 			struct registry_priv	*pregistrypriv = &padapter->registrypriv;
6289 
6290 			if (arg == 0) {
6291 				RTW_INFO("disable driver ctrl max_rx_rate, reset to default_rate_set\n");
6292 				init_mlme_default_rate_set(padapter);
6293 #ifdef CONFIG_80211N_HT
6294 				pregistrypriv->ht_enable = (u8)rtw_ht_enable;
6295 #endif /* CONFIG_80211N_HT */
6296 			} else if (arg == 1) {
6297 
6298 				int i;
6299 				u8 max_rx_rate;
6300 
6301 				RTW_INFO("enable driver ctrl max_rx_rate = 0x%x\n", extra_arg);
6302 
6303 				max_rx_rate = (u8)extra_arg;
6304 
6305 				if (max_rx_rate < 0xc) { /* max_rx_rate < MSC0->B or G -> disable HT */
6306 #ifdef CONFIG_80211N_HT
6307 					pregistrypriv->ht_enable = 0;
6308 #endif /* CONFIG_80211N_HT */
6309 					for (i = 0; i < NumRates; i++) {
6310 						if (pmlmeext->datarate[i] > max_rx_rate)
6311 							pmlmeext->datarate[i] = 0xff;
6312 					}
6313 
6314 				}
6315 #ifdef CONFIG_80211N_HT
6316 				else if (max_rx_rate < 0x1c) { /* mcs0~mcs15 */
6317 					u32 mcs_bitmap = 0x0;
6318 
6319 					for (i = 0; i < ((max_rx_rate + 1) - 0xc); i++)
6320 						mcs_bitmap |= BIT(i);
6321 
6322 					set_mcs_rate_by_mask(pmlmeext->default_supported_mcs_set, mcs_bitmap);
6323 				}
6324 #endif /* CONFIG_80211N_HT							 */
6325 			}
6326 		}
6327 			break;
6328 		case 0x1c: { /* enable/disable driver control AMPDU Density for peer sta's rx */
6329 			if (arg == 0) {
6330 				RTW_INFO("disable driver ctrl ampdu density\n");
6331 				padapter->driver_ampdu_spacing = 0xFF;
6332 			} else if (arg == 1) {
6333 
6334 				RTW_INFO("enable driver ctrl ampdu density = %d\n", extra_arg);
6335 
6336 				if (extra_arg > 0x07)
6337 					padapter->driver_ampdu_spacing = 0xFF;
6338 				else
6339 					padapter->driver_ampdu_spacing = extra_arg;
6340 			}
6341 		}
6342 			break;
6343 #ifdef CONFIG_BACKGROUND_NOISE_MONITOR
6344 		case 0x1e: {
6345 			RTW_INFO("===========================================\n");
6346 			rtw_noise_measure_curchan(padapter);
6347 			RTW_INFO("===========================================\n");
6348 		}
6349 			break;
6350 #endif
6351 
6352 
6353 #if defined(CONFIG_SDIO_HCI) && defined(CONFIG_SDIO_INDIRECT_ACCESS) && defined(DBG_SDIO_INDIRECT_ACCESS)
6354 		case 0x1f:
6355 			{
6356 				int i, j = 0, test_cnts = 0;
6357 				static u8 test_code = 0x5A;
6358 				static u32 data_misatch_cnt = 0, d_acc_err_cnt = 0;
6359 
6360 				u32 d_data, i_data;
6361 				u32 imr;
6362 
6363 				test_cnts = extra_arg;
6364 				for (i = 0; i < test_cnts; i++) {
6365 					if (RTW_CANNOT_IO(padapter))
6366 						break;
6367 
6368 					rtw_write8(padapter, 0x07, test_code);
6369 
6370 					d_data = rtw_read32(padapter, 0x04);
6371 					imr =  rtw_read32(padapter, 0x10250014);
6372 					rtw_write32(padapter, 0x10250014, 0);
6373 					rtw_msleep_os(50);
6374 
6375 					i_data = rtw_sd_iread32(padapter, 0x04);
6376 
6377 					rtw_write32(padapter, 0x10250014, imr);
6378 
6379 					if (d_data != i_data) {
6380 						data_misatch_cnt++;
6381 						RTW_ERR("d_data :0x%08x, i_data : 0x%08x\n", d_data, i_data);
6382 					}
6383 
6384 					if (test_code != (i_data >> 24)) {
6385 						d_acc_err_cnt++;
6386 						rtw_write8(padapter, 0x07, 0xAA);
6387 						RTW_ERR("test_code :0x%02x, i_data : 0x%08x\n", test_code, i_data);
6388 					}
6389 					if ((j++) == 100) {
6390 						rtw_msleep_os(2000);
6391 						RTW_INFO(" Indirect access testing..........%d/%d\n", i, test_cnts);
6392 						j = 0;
6393 					}
6394 
6395 					test_code = ~test_code;
6396 					rtw_msleep_os(50);
6397 				}
6398 				RTW_INFO("========Indirect access test=========\n");
6399 				RTW_INFO(" test_cnts = %d\n", test_cnts);
6400 				RTW_INFO(" direct & indirect read32 data missatch cnts = %d\n", data_misatch_cnt);
6401 				RTW_INFO(" indirect rdata is not equal to wdata cnts = %d\n", d_acc_err_cnt);
6402 				RTW_INFO("========Indirect access test=========\n\n");
6403 				data_misatch_cnt = d_acc_err_cnt = 0;
6404 
6405 			}
6406 			break;
6407 #endif
6408 		case 0x20:
6409 			{
6410 				if (arg == 0xAA) {
6411 					u8 page_offset, page_num;
6412 
6413 					page_offset = (u8)(extra_arg >> 16);
6414 					page_num = (u8)(extra_arg & 0xFF);
6415 					rtw_dump_rsvd_page(RTW_DBGDUMP, padapter, page_offset, page_num);
6416 				}
6417 #ifdef CONFIG_SUPPORT_FIFO_DUMP
6418 				else {
6419 					u8 fifo_sel;
6420 					u32 addr, size;
6421 
6422 					fifo_sel = (u8)(arg & 0x0F);
6423 					addr = (extra_arg >> 16) & 0xFFFF;
6424 					size = extra_arg & 0xFFFF;
6425 					rtw_dump_fifo(RTW_DBGDUMP, padapter, fifo_sel, addr, size);
6426 				}
6427 #endif
6428 			}
6429 			break;
6430 
6431 		case 0x23: {
6432 			RTW_INFO("turn %s the bNotifyChannelChange Variable\n", (extra_arg == 1) ? "on" : "off");
6433 			padapter->bNotifyChannelChange = extra_arg;
6434 			break;
6435 		}
6436 		case 0x24: {
6437 #ifdef CONFIG_P2P
6438 			RTW_INFO("turn %s the bShowGetP2PState Variable\n", (extra_arg == 1) ? "on" : "off");
6439 			padapter->bShowGetP2PState = extra_arg;
6440 #endif /* CONFIG_P2P */
6441 			break;
6442 		}
6443 #ifdef CONFIG_GPIO_API
6444 		case 0x25: { /* Get GPIO register */
6445 			/*
6446 			* dbg 0x7f250000 [gpio_num], Get gpio value, gpio_num:0~7
6447 			*/
6448 
6449 			u8 value;
6450 			RTW_INFO("Read GPIO Value  extra_arg = %d\n", extra_arg);
6451 			value = rtw_hal_get_gpio(padapter, extra_arg);
6452 			RTW_INFO("Read GPIO Value = %d\n", value);
6453 			break;
6454 		}
6455 		case 0x26: { /* Set GPIO direction */
6456 
6457 			/* dbg 0x7f26000x [y], Set gpio direction,
6458 			* x: gpio_num,4~7  y: indicate direction, 0~1
6459 			*/
6460 
6461 			int value;
6462 			RTW_INFO("Set GPIO Direction! arg = %d ,extra_arg=%d\n", arg , extra_arg);
6463 			value = rtw_hal_config_gpio(padapter, arg, extra_arg);
6464 			RTW_INFO("Set GPIO Direction %s\n", (value == -1) ? "Fail!!!" : "Success");
6465 			break;
6466 		}
6467 		case 0x27: { /* Set GPIO output direction value */
6468 			/*
6469 			* dbg 0x7f27000x [y], Set gpio output direction value,
6470 			* x: gpio_num,4~7  y: indicate direction, 0~1
6471 			*/
6472 
6473 			int value;
6474 			RTW_INFO("Set GPIO Value! arg = %d ,extra_arg=%d\n", arg , extra_arg);
6475 			value = rtw_hal_set_gpio_output_value(padapter, arg, extra_arg);
6476 			RTW_INFO("Set GPIO Value %s\n", (value == -1) ? "Fail!!!" : "Success");
6477 			break;
6478 		}
6479 #endif
6480 #ifdef DBG_CMD_QUEUE
6481 		case 0x28: {
6482 			dump_cmd_id = extra_arg;
6483 			RTW_INFO("dump_cmd_id:%d\n", dump_cmd_id);
6484 		}
6485 			break;
6486 #endif /* DBG_CMD_QUEUE */
6487 		case 0xaa: {
6488 			if ((extra_arg & 0x7F) > 0x3F)
6489 				extra_arg = 0xFF;
6490 			RTW_INFO("chang data rate to :0x%02x\n", extra_arg);
6491 			padapter->fix_rate = extra_arg;
6492 		}
6493 			break;
6494 		case 0xdd: { /* registers dump , 0 for mac reg,1 for bb reg, 2 for rf reg */
6495 			if (extra_arg == 0)
6496 				mac_reg_dump(RTW_DBGDUMP, padapter);
6497 			else if (extra_arg == 1)
6498 				bb_reg_dump(RTW_DBGDUMP, padapter);
6499 			else if (extra_arg == 2)
6500 				rf_reg_dump(RTW_DBGDUMP, padapter);
6501 			else if (extra_arg == 11)
6502 				bb_reg_dump_ex(RTW_DBGDUMP, padapter);
6503 		}
6504 			break;
6505 
6506 		case 0xee: {
6507 			RTW_INFO(" === please control /proc  to trun on/off PHYDM func ===\n");
6508 		}
6509 			break;
6510 
6511 		case 0xfd:
6512 			rtw_write8(padapter, 0xc50, arg);
6513 			RTW_INFO("wr(0xc50)=0x%x\n", rtw_read8(padapter, 0xc50));
6514 			rtw_write8(padapter, 0xc58, arg);
6515 			RTW_INFO("wr(0xc58)=0x%x\n", rtw_read8(padapter, 0xc58));
6516 			break;
6517 		case 0xfe:
6518 			RTW_INFO("rd(0xc50)=0x%x\n", rtw_read8(padapter, 0xc50));
6519 			RTW_INFO("rd(0xc58)=0x%x\n", rtw_read8(padapter, 0xc58));
6520 			break;
6521 		case 0xff: {
6522 			RTW_INFO("dbg(0x210)=0x%x\n", rtw_read32(padapter, 0x210));
6523 			RTW_INFO("dbg(0x608)=0x%x\n", rtw_read32(padapter, 0x608));
6524 			RTW_INFO("dbg(0x280)=0x%x\n", rtw_read32(padapter, 0x280));
6525 			RTW_INFO("dbg(0x284)=0x%x\n", rtw_read32(padapter, 0x284));
6526 			RTW_INFO("dbg(0x288)=0x%x\n", rtw_read32(padapter, 0x288));
6527 
6528 			RTW_INFO("dbg(0x664)=0x%x\n", rtw_read32(padapter, 0x664));
6529 
6530 
6531 			RTW_INFO("\n");
6532 
6533 			RTW_INFO("dbg(0x430)=0x%x\n", rtw_read32(padapter, 0x430));
6534 			RTW_INFO("dbg(0x438)=0x%x\n", rtw_read32(padapter, 0x438));
6535 
6536 			RTW_INFO("dbg(0x440)=0x%x\n", rtw_read32(padapter, 0x440));
6537 
6538 			RTW_INFO("dbg(0x458)=0x%x\n", rtw_read32(padapter, 0x458));
6539 
6540 			RTW_INFO("dbg(0x484)=0x%x\n", rtw_read32(padapter, 0x484));
6541 			RTW_INFO("dbg(0x488)=0x%x\n", rtw_read32(padapter, 0x488));
6542 
6543 			RTW_INFO("dbg(0x444)=0x%x\n", rtw_read32(padapter, 0x444));
6544 			RTW_INFO("dbg(0x448)=0x%x\n", rtw_read32(padapter, 0x448));
6545 			RTW_INFO("dbg(0x44c)=0x%x\n", rtw_read32(padapter, 0x44c));
6546 			RTW_INFO("dbg(0x450)=0x%x\n", rtw_read32(padapter, 0x450));
6547 		}
6548 			break;
6549 		}
6550 		break;
6551 	default:
6552 		RTW_INFO("error dbg cmd!\n");
6553 		break;
6554 	}
6555 
6556 #endif
6557 	return ret;
6558 
6559 }
6560 
6561 #ifdef CONFIG_IOCTL_WEXT
6562 static int wpa_set_param(struct net_device *dev, u8 name, u32 value)
6563 {
6564 	uint ret = 0;
6565 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
6566 
6567 	switch (name) {
6568 	case IEEE_PARAM_WPA_ENABLED:
6569 
6570 		padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; /* 802.1x */
6571 
6572 		/* ret = ieee80211_wpa_enable(ieee, value); */
6573 
6574 		switch ((value) & 0xff) {
6575 		case 1: /* WPA */
6576 			padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPAPSK; /* WPA_PSK */
6577 			padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
6578 			break;
6579 		case 2: /* WPA2 */
6580 			padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPA2PSK; /* WPA2_PSK */
6581 			padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
6582 			break;
6583 		}
6584 
6585 
6586 		break;
6587 
6588 	case IEEE_PARAM_TKIP_COUNTERMEASURES:
6589 		/* ieee->tkip_countermeasures=value; */
6590 		break;
6591 
6592 	case IEEE_PARAM_DROP_UNENCRYPTED: {
6593 		/* HACK:
6594 		 *
6595 		 * wpa_supplicant calls set_wpa_enabled when the driver
6596 		 * is loaded and unloaded, regardless of if WPA is being
6597 		 * used.  No other calls are made which can be used to
6598 		 * determine if encryption will be used or not prior to
6599 		 * association being expected.  If encryption is not being
6600 		 * used, drop_unencrypted is set to false, else true -- we
6601 		 * can use this to determine if the CAP_PRIVACY_ON bit should
6602 		 * be set.
6603 		 */
6604 
6605 #if 0
6606 		struct ieee80211_security sec = {
6607 			.flags = SEC_ENABLED,
6608 			.enabled = value,
6609 		};
6610 		ieee->drop_unencrypted = value;
6611 		/* We only change SEC_LEVEL for open mode. Others
6612 		 * are set by ipw_wpa_set_encryption.
6613 		 */
6614 		if (!value) {
6615 			sec.flags |= SEC_LEVEL;
6616 			sec.level = SEC_LEVEL_0;
6617 		} else {
6618 			sec.flags |= SEC_LEVEL;
6619 			sec.level = SEC_LEVEL_1;
6620 		}
6621 		if (ieee->set_security)
6622 			ieee->set_security(ieee->dev, &sec);
6623 #endif
6624 		break;
6625 
6626 	}
6627 	case IEEE_PARAM_PRIVACY_INVOKED:
6628 
6629 		/* ieee->privacy_invoked=value; */
6630 
6631 		break;
6632 
6633 	case IEEE_PARAM_AUTH_ALGS:
6634 
6635 		ret = wpa_set_auth_algs(dev, value);
6636 
6637 		break;
6638 
6639 	case IEEE_PARAM_IEEE_802_1X:
6640 
6641 		/* ieee->ieee802_1x=value;		 */
6642 
6643 		break;
6644 
6645 	case IEEE_PARAM_WPAX_SELECT:
6646 
6647 		/* added for WPA2 mixed mode */
6648 		/*RTW_WARN("------------------------>wpax value = %x\n", value);*/
6649 		/*
6650 		spin_lock_irqsave(&ieee->wpax_suitlist_lock,flags);
6651 		ieee->wpax_type_set = 1;
6652 		ieee->wpax_type_notify = value;
6653 		spin_unlock_irqrestore(&ieee->wpax_suitlist_lock,flags);
6654 		*/
6655 
6656 		break;
6657 
6658 	default:
6659 
6660 
6661 
6662 		ret = -EOPNOTSUPP;
6663 
6664 
6665 		break;
6666 
6667 	}
6668 
6669 	return ret;
6670 
6671 }
6672 
6673 static int wpa_mlme(struct net_device *dev, u32 command, u32 reason)
6674 {
6675 	int ret = 0;
6676 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
6677 
6678 	switch (command) {
6679 	case IEEE_MLME_STA_DEAUTH:
6680 
6681 		if (!rtw_set_802_11_disassociate(padapter))
6682 			ret = -1;
6683 
6684 		break;
6685 
6686 	case IEEE_MLME_STA_DISASSOC:
6687 
6688 		if (!rtw_set_802_11_disassociate(padapter))
6689 			ret = -1;
6690 
6691 		break;
6692 
6693 	default:
6694 		ret = -EOPNOTSUPP;
6695 		break;
6696 	}
6697 #ifdef CONFIG_RTW_REPEATER_SON
6698 	rtw_rson_do_disconnect(padapter);
6699 #endif
6700 	return ret;
6701 
6702 }
6703 
6704 static int wpa_supplicant_ioctl(struct net_device *dev, struct iw_point *p)
6705 {
6706 	struct ieee_param *param;
6707 	uint ret = 0;
6708 
6709 	/* down(&ieee->wx_sem);	 */
6710 
6711 	if (p->length < sizeof(struct ieee_param) || !p->pointer) {
6712 		ret = -EINVAL;
6713 		goto out;
6714 	}
6715 
6716 	param = (struct ieee_param *)rtw_malloc(p->length);
6717 	if (param == NULL) {
6718 		ret = -ENOMEM;
6719 		goto out;
6720 	}
6721 
6722 	if (copy_from_user(param, p->pointer, p->length)) {
6723 		rtw_mfree((u8 *)param, p->length);
6724 		ret = -EFAULT;
6725 		goto out;
6726 	}
6727 
6728 	switch (param->cmd) {
6729 
6730 	case IEEE_CMD_SET_WPA_PARAM:
6731 		ret = wpa_set_param(dev, param->u.wpa_param.name, param->u.wpa_param.value);
6732 		break;
6733 
6734 	case IEEE_CMD_SET_WPA_IE:
6735 		/* ret = wpa_set_wpa_ie(dev, param, p->length); */
6736 		ret =  rtw_set_wpa_ie((_adapter *)rtw_netdev_priv(dev), (char *)param->u.wpa_ie.data, (u16)param->u.wpa_ie.len);
6737 		break;
6738 
6739 	case IEEE_CMD_SET_ENCRYPTION:
6740 		ret = wpa_set_encryption(dev, param, p->length);
6741 		break;
6742 
6743 	case IEEE_CMD_MLME:
6744 		ret = wpa_mlme(dev, param->u.mlme.command, param->u.mlme.reason_code);
6745 		break;
6746 
6747 	default:
6748 		RTW_INFO("Unknown WPA supplicant request: %d\n", param->cmd);
6749 		ret = -EOPNOTSUPP;
6750 		break;
6751 
6752 	}
6753 
6754 	if (ret == 0 && copy_to_user(p->pointer, param, p->length))
6755 		ret = -EFAULT;
6756 
6757 	rtw_mfree((u8 *)param, p->length);
6758 
6759 out:
6760 
6761 	/* up(&ieee->wx_sem); */
6762 
6763 	return ret;
6764 
6765 }
6766 
6767 #ifdef CONFIG_AP_MODE
6768 static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len)
6769 {
6770 	int ret = 0;
6771 	u32 wep_key_idx, wep_key_len, wep_total_len;
6772 	NDIS_802_11_WEP	*pwep = NULL;
6773 	struct sta_info *psta = NULL, *pbcmc_sta = NULL;
6774 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
6775 	struct mlme_priv	*pmlmepriv = &padapter->mlmepriv;
6776 	struct security_priv *psecuritypriv = &(padapter->securitypriv);
6777 	struct sta_priv *pstapriv = &padapter->stapriv;
6778 
6779 	RTW_INFO("%s\n", __FUNCTION__);
6780 
6781 	param->u.crypt.err = 0;
6782 	param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
6783 
6784 	/* sizeof(struct ieee_param) = 64 bytes; */
6785 	/* if (param_len !=  (u32) ((u8 *) param->u.crypt.key - (u8 *) param) + param->u.crypt.key_len) */
6786 	if (param_len !=  sizeof(struct ieee_param) + param->u.crypt.key_len) {
6787 		ret =  -EINVAL;
6788 		goto exit;
6789 	}
6790 
6791 	if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
6792 	    param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
6793 	    param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
6794 		if (param->u.crypt.idx >= WEP_KEYS
6795 #ifdef CONFIG_IEEE80211W
6796 		    && param->u.crypt.idx > BIP_MAX_KEYID
6797 #endif /* CONFIG_IEEE80211W */
6798 		   ) {
6799 			ret = -EINVAL;
6800 			goto exit;
6801 		}
6802 	} else {
6803 		psta = rtw_get_stainfo(pstapriv, param->sta_addr);
6804 		if (!psta) {
6805 			/* ret = -EINVAL; */
6806 			RTW_INFO("rtw_set_encryption(), sta has already been removed or never been added\n");
6807 			goto exit;
6808 		}
6809 	}
6810 
6811 	if (strcmp(param->u.crypt.alg, "none") == 0 && (psta == NULL)) {
6812 		/* todo:clear default encryption keys */
6813 
6814 		psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
6815 		psecuritypriv->ndisencryptstatus = Ndis802_11EncryptionDisabled;
6816 		psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
6817 		psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
6818 
6819 		RTW_INFO("clear default encryption keys, keyid=%d\n", param->u.crypt.idx);
6820 
6821 		goto exit;
6822 	}
6823 
6824 
6825 	if (strcmp(param->u.crypt.alg, "WEP") == 0 && (psta == NULL)) {
6826 		RTW_INFO("r871x_set_encryption, crypt.alg = WEP\n");
6827 
6828 		wep_key_idx = param->u.crypt.idx;
6829 		wep_key_len = param->u.crypt.key_len;
6830 
6831 		RTW_INFO("r871x_set_encryption, wep_key_idx=%d, len=%d\n", wep_key_idx, wep_key_len);
6832 
6833 		if ((wep_key_idx >= WEP_KEYS) || (wep_key_len <= 0)) {
6834 			ret = -EINVAL;
6835 			goto exit;
6836 		}
6837 
6838 
6839 		if (wep_key_len > 0) {
6840 			wep_key_len = wep_key_len <= 5 ? 5 : 13;
6841 			wep_total_len = wep_key_len + FIELD_OFFSET(NDIS_802_11_WEP, KeyMaterial);
6842 			pwep = (NDIS_802_11_WEP *)rtw_malloc(wep_total_len);
6843 			if (pwep == NULL) {
6844 				RTW_INFO(" r871x_set_encryption: pwep allocate fail !!!\n");
6845 				goto exit;
6846 			}
6847 
6848 			_rtw_memset(pwep, 0, wep_total_len);
6849 
6850 			pwep->KeyLength = wep_key_len;
6851 			pwep->Length = wep_total_len;
6852 
6853 		}
6854 
6855 		pwep->KeyIndex = wep_key_idx;
6856 
6857 		_rtw_memcpy(pwep->KeyMaterial,  param->u.crypt.key, pwep->KeyLength);
6858 
6859 		if (param->u.crypt.set_tx) {
6860 			RTW_INFO("wep, set_tx=1\n");
6861 
6862 			psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
6863 			psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled;
6864 			psecuritypriv->dot11PrivacyAlgrthm = _WEP40_;
6865 			psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
6866 
6867 			if (pwep->KeyLength == 13) {
6868 				psecuritypriv->dot11PrivacyAlgrthm = _WEP104_;
6869 				psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
6870 			}
6871 
6872 
6873 			psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx;
6874 
6875 			_rtw_memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), pwep->KeyMaterial, pwep->KeyLength);
6876 
6877 			psecuritypriv->dot11DefKeylen[wep_key_idx] = pwep->KeyLength;
6878 
6879 			rtw_ap_set_wep_key(padapter, pwep->KeyMaterial, pwep->KeyLength, wep_key_idx, 1);
6880 		} else {
6881 			RTW_INFO("wep, set_tx=0\n");
6882 
6883 			/* don't update "psecuritypriv->dot11PrivacyAlgrthm" and  */
6884 			/* "psecuritypriv->dot11PrivacyKeyIndex=keyid", but can rtw_set_key to cam */
6885 
6886 			_rtw_memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), pwep->KeyMaterial, pwep->KeyLength);
6887 
6888 			psecuritypriv->dot11DefKeylen[wep_key_idx] = pwep->KeyLength;
6889 
6890 			rtw_ap_set_wep_key(padapter, pwep->KeyMaterial, pwep->KeyLength, wep_key_idx, 0);
6891 		}
6892 
6893 		goto exit;
6894 
6895 	}
6896 
6897 
6898 	if (!psta && check_fwstate(pmlmepriv, WIFI_AP_STATE)) /*  */ { /* group key */
6899 		if (param->u.crypt.set_tx == 1) {
6900 			if (strcmp(param->u.crypt.alg, "WEP") == 0) {
6901 				RTW_INFO(FUNC_ADPT_FMT" set WEP TX GTK idx:%u, len:%u\n"
6902 					, FUNC_ADPT_ARG(padapter), param->u.crypt.idx, param->u.crypt.key_len);
6903 				_rtw_memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey,  param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
6904 				psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
6905 				if (param->u.crypt.key_len == 13)
6906 					psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
6907 
6908 			} else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
6909 				RTW_INFO(FUNC_ADPT_FMT" set TKIP TX GTK idx:%u, len:%u\n"
6910 					, FUNC_ADPT_ARG(padapter), param->u.crypt.idx, param->u.crypt.key_len);
6911 				psecuritypriv->dot118021XGrpPrivacy = _TKIP_;
6912 				_rtw_memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey,  param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
6913 				/* set mic key */
6914 				_rtw_memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
6915 				_rtw_memcpy(psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8);
6916 				psecuritypriv->busetkipkey = _TRUE;
6917 
6918 			} else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
6919 				RTW_INFO(FUNC_ADPT_FMT" set CCMP TX GTK idx:%u, len:%u\n"
6920 					, FUNC_ADPT_ARG(padapter), param->u.crypt.idx, param->u.crypt.key_len);
6921 				psecuritypriv->dot118021XGrpPrivacy = _AES_;
6922 				_rtw_memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey,  param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
6923 
6924 			#ifdef CONFIG_IEEE80211W
6925 			} else if (strcmp(param->u.crypt.alg, "BIP") == 0) {
6926 				RTW_INFO(FUNC_ADPT_FMT" set TX IGTK idx:%u, len:%u\n"
6927 					, FUNC_ADPT_ARG(padapter), param->u.crypt.idx, param->u.crypt.key_len);
6928 				_rtw_memcpy(padapter->securitypriv.dot11wBIPKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
6929 				psecuritypriv->dot11wBIPKeyid = param->u.crypt.idx;
6930 				psecuritypriv->dot11wBIPtxpn.val = RTW_GET_LE64(param->u.crypt.seq);
6931 				psecuritypriv->binstallBIPkey = _TRUE;
6932 				goto exit;
6933 			#endif /* CONFIG_IEEE80211W */
6934 
6935 			} else if (strcmp(param->u.crypt.alg, "none") == 0) {
6936 				RTW_INFO(FUNC_ADPT_FMT" clear group key, idx:%u\n"
6937 					, FUNC_ADPT_ARG(padapter), param->u.crypt.idx);
6938 				psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
6939 			} else {
6940 				RTW_WARN(FUNC_ADPT_FMT" set group key, not support\n"
6941 					, FUNC_ADPT_ARG(padapter));
6942 				goto exit;
6943 			}
6944 
6945 			psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx;
6946 			pbcmc_sta = rtw_get_bcmc_stainfo(padapter);
6947 			if (pbcmc_sta) {
6948 				pbcmc_sta->dot11txpn.val = RTW_GET_LE64(param->u.crypt.seq);
6949 				pbcmc_sta->ieee8021x_blocked = _FALSE;
6950 				pbcmc_sta->dot118021XPrivacy = psecuritypriv->dot118021XGrpPrivacy; /* rx will use bmc_sta's dot118021XPrivacy			 */
6951 			}
6952 			psecuritypriv->binstallGrpkey = _TRUE;
6953 			psecuritypriv->dot11PrivacyAlgrthm = psecuritypriv->dot118021XGrpPrivacy;/* !!! */
6954 
6955 			rtw_ap_set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx);
6956 		}
6957 
6958 		goto exit;
6959 
6960 	}
6961 
6962 	if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X && psta) { /* psk/802_1x */
6963 		if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
6964 			if (param->u.crypt.set_tx == 1) {
6965 				_rtw_memcpy(psta->dot118021x_UncstKey.skey,  param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
6966 
6967 				if (strcmp(param->u.crypt.alg, "WEP") == 0) {
6968 					RTW_INFO(FUNC_ADPT_FMT" set WEP PTK of "MAC_FMT" idx:%u, len:%u\n"
6969 						, FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
6970 						, param->u.crypt.idx, param->u.crypt.key_len);
6971 					psta->dot118021XPrivacy = _WEP40_;
6972 					if (param->u.crypt.key_len == 13)
6973 						psta->dot118021XPrivacy = _WEP104_;
6974 
6975 				} else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
6976 					RTW_INFO(FUNC_ADPT_FMT" set TKIP PTK of "MAC_FMT" idx:%u, len:%u\n"
6977 						, FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
6978 						, param->u.crypt.idx, param->u.crypt.key_len);
6979 					psta->dot118021XPrivacy = _TKIP_;
6980 					/* set mic key */
6981 					_rtw_memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8);
6982 					_rtw_memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8);
6983 					psecuritypriv->busetkipkey = _TRUE;
6984 
6985 				} else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
6986 					RTW_INFO(FUNC_ADPT_FMT" set CCMP PTK of "MAC_FMT" idx:%u, len:%u\n"
6987 						, FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
6988 						, param->u.crypt.idx, param->u.crypt.key_len);
6989 					psta->dot118021XPrivacy = _AES_;
6990 
6991 				} else if (strcmp(param->u.crypt.alg, "none") == 0) {
6992 					RTW_INFO(FUNC_ADPT_FMT" clear pairwise key of "MAC_FMT" idx:%u\n"
6993 						, FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr)
6994 						, param->u.crypt.idx);
6995 					psta->dot118021XPrivacy = _NO_PRIVACY_;
6996 
6997 				} else {
6998 					RTW_WARN(FUNC_ADPT_FMT" set pairwise key of "MAC_FMT", not support\n"
6999 						, FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr));
7000 					goto exit;
7001 				}
7002 
7003 				psta->dot11txpn.val = RTW_GET_LE64(param->u.crypt.seq);
7004 				psta->dot11rxpn.val = RTW_GET_LE64(param->u.crypt.seq);
7005 				psta->ieee8021x_blocked = _FALSE;
7006 
7007 				if (psta->dot118021XPrivacy != _NO_PRIVACY_) {
7008 					psta->bpairwise_key_installed = _TRUE;
7009 
7010 					/* WPA2 key-handshake has completed */
7011 					if (psecuritypriv->ndisauthtype == Ndis802_11AuthModeWPA2PSK)
7012 						psta->state &= (~WIFI_UNDER_KEY_HANDSHAKE);
7013 				}
7014 
7015 				rtw_ap_set_pairwise_key(padapter, psta);
7016 			} else {
7017 				RTW_WARN(FUNC_ADPT_FMT" set group key of "MAC_FMT", not support\n"
7018 					, FUNC_ADPT_ARG(padapter), MAC_ARG(psta->cmn.mac_addr));
7019 				goto exit;
7020 			}
7021 
7022 		}
7023 
7024 	}
7025 
7026 exit:
7027 
7028 	if (pwep)
7029 		rtw_mfree((u8 *)pwep, wep_total_len);
7030 
7031 	return ret;
7032 
7033 }
7034 
7035 static int rtw_set_beacon(struct net_device *dev, struct ieee_param *param, int len)
7036 {
7037 	int ret = 0;
7038 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
7039 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
7040 	struct sta_priv *pstapriv = &padapter->stapriv;
7041 	unsigned char *pbuf = param->u.bcn_ie.buf;
7042 
7043 
7044 	RTW_INFO("%s, len=%d\n", __FUNCTION__, len);
7045 
7046 	if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
7047 		return -EINVAL;
7048 
7049 	_rtw_memcpy(&pstapriv->max_num_sta, param->u.bcn_ie.reserved, 2);
7050 
7051 	if ((pstapriv->max_num_sta > NUM_STA) || (pstapriv->max_num_sta <= 0))
7052 		pstapriv->max_num_sta = NUM_STA;
7053 
7054 
7055 	if (rtw_check_beacon_data(padapter, pbuf, (len - 12 - 2)) == _SUCCESS) /* 12 = param header, 2:no packed */
7056 		ret = 0;
7057 	else
7058 		ret = -EINVAL;
7059 
7060 
7061 	return ret;
7062 
7063 }
7064 
7065 static int rtw_hostapd_sta_flush(struct net_device *dev)
7066 {
7067 	/* _irqL irqL; */
7068 	/* _list	*phead, *plist; */
7069 	int ret = 0;
7070 	/* struct sta_info *psta = NULL; */
7071 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
7072 	/* struct sta_priv *pstapriv = &padapter->stapriv; */
7073 
7074 	RTW_INFO("%s\n", __FUNCTION__);
7075 
7076 	flush_all_cam_entry(padapter);	/* clear CAM */
7077 #ifdef CONFIG_AP_MODE
7078 	ret = rtw_sta_flush(padapter, _TRUE);
7079 #endif
7080 	return ret;
7081 
7082 }
7083 
7084 static int rtw_add_sta(struct net_device *dev, struct ieee_param *param)
7085 {
7086 	int ret = 0;
7087 	struct sta_info *psta = NULL;
7088 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
7089 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
7090 	struct sta_priv *pstapriv = &padapter->stapriv;
7091 
7092 	RTW_INFO("rtw_add_sta(aid=%d)=" MAC_FMT "\n", param->u.add_sta.aid, MAC_ARG(param->sta_addr));
7093 
7094 	if (check_fwstate(pmlmepriv, (WIFI_ASOC_STATE | WIFI_AP_STATE)) != _TRUE)
7095 		return -EINVAL;
7096 
7097 	if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
7098 	    param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
7099 	    param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
7100 		return -EINVAL;
7101 
7102 #if 0
7103 	psta = rtw_get_stainfo(pstapriv, param->sta_addr);
7104 	if (psta) {
7105 		RTW_INFO("rtw_add_sta(), free has been added psta=%p\n", psta);
7106 		/* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);		 */
7107 		rtw_free_stainfo(padapter,  psta);
7108 		/* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL); */
7109 
7110 		psta = NULL;
7111 	}
7112 #endif
7113 	/* psta = rtw_alloc_stainfo(pstapriv, param->sta_addr); */
7114 	psta = rtw_get_stainfo(pstapriv, param->sta_addr);
7115 	if (psta) {
7116 		int flags = param->u.add_sta.flags;
7117 
7118 		/* RTW_INFO("rtw_add_sta(), init sta's variables, psta=%p\n", psta); */
7119 
7120 		psta->cmn.aid = param->u.add_sta.aid;/* aid=1~2007 */
7121 
7122 		_rtw_memcpy(psta->bssrateset, param->u.add_sta.tx_supp_rates, 16);
7123 
7124 
7125 		/* check wmm cap. */
7126 		if (WLAN_STA_WME & flags)
7127 			psta->qos_option = 1;
7128 		else
7129 			psta->qos_option = 0;
7130 
7131 		if (pmlmepriv->qospriv.qos_option == 0)
7132 			psta->qos_option = 0;
7133 
7134 
7135 #ifdef CONFIG_80211N_HT
7136 		/* chec 802.11n ht cap. */
7137 		if (padapter->registrypriv.ht_enable &&
7138 			is_supported_ht(padapter->registrypriv.wireless_mode) &&
7139 			(WLAN_STA_HT & flags)) {
7140 			psta->htpriv.ht_option = _TRUE;
7141 			psta->qos_option = 1;
7142 			_rtw_memcpy((void *)&psta->htpriv.ht_cap, (void *)&param->u.add_sta.ht_cap, sizeof(struct rtw_ieee80211_ht_cap));
7143 		} else
7144 			psta->htpriv.ht_option = _FALSE;
7145 
7146 		if (pmlmepriv->htpriv.ht_option == _FALSE)
7147 			psta->htpriv.ht_option = _FALSE;
7148 
7149 #endif
7150 
7151 
7152 		update_sta_info_apmode(padapter, psta);
7153 
7154 
7155 	} else
7156 		ret = -ENOMEM;
7157 
7158 	return ret;
7159 
7160 }
7161 
7162 static int rtw_del_sta(struct net_device *dev, struct ieee_param *param)
7163 {
7164 	_irqL irqL;
7165 	int ret = 0;
7166 	struct sta_info *psta = NULL;
7167 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
7168 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
7169 	struct sta_priv *pstapriv = &padapter->stapriv;
7170 
7171 	RTW_INFO("rtw_del_sta=" MAC_FMT "\n", MAC_ARG(param->sta_addr));
7172 
7173 	if (check_fwstate(pmlmepriv, (WIFI_ASOC_STATE | WIFI_AP_STATE)) != _TRUE)
7174 		return -EINVAL;
7175 
7176 	if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
7177 	    param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
7178 	    param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
7179 		return -EINVAL;
7180 
7181 	psta = rtw_get_stainfo(pstapriv, param->sta_addr);
7182 	if (psta) {
7183 		u8 updated = _FALSE;
7184 
7185 		/* RTW_INFO("free psta=%p, aid=%d\n", psta, psta->cmn.aid); */
7186 
7187 		_enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
7188 		if (rtw_is_list_empty(&psta->asoc_list) == _FALSE) {
7189 			rtw_list_delete(&psta->asoc_list);
7190 			pstapriv->asoc_list_cnt--;
7191 			#ifdef CONFIG_RTW_TOKEN_BASED_XMIT
7192 			if (psta->tbtx_enable)
7193 				pstapriv->tbtx_asoc_list_cnt--;
7194 			#endif
7195 			updated = ap_free_sta(padapter, psta, _TRUE, WLAN_REASON_DEAUTH_LEAVING, _TRUE);
7196 
7197 		}
7198 		_exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
7199 
7200 		associated_clients_update(padapter, updated, STA_INFO_UPDATE_ALL);
7201 
7202 		psta = NULL;
7203 
7204 	} else {
7205 		RTW_INFO("rtw_del_sta(), sta has already been removed or never been added\n");
7206 
7207 		/* ret = -1; */
7208 	}
7209 
7210 
7211 	return ret;
7212 
7213 }
7214 
7215 static int rtw_ioctl_get_sta_data(struct net_device *dev, struct ieee_param *param, int len)
7216 {
7217 	int ret = 0;
7218 	struct sta_info *psta = NULL;
7219 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
7220 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
7221 	struct sta_priv *pstapriv = &padapter->stapriv;
7222 	struct ieee_param_ex *param_ex = (struct ieee_param_ex *)param;
7223 	struct sta_data *psta_data = (struct sta_data *)param_ex->data;
7224 
7225 	RTW_INFO("rtw_ioctl_get_sta_info, sta_addr: " MAC_FMT "\n", MAC_ARG(param_ex->sta_addr));
7226 
7227 	if (check_fwstate(pmlmepriv, (WIFI_ASOC_STATE | WIFI_AP_STATE)) != _TRUE)
7228 		return -EINVAL;
7229 
7230 	if (param_ex->sta_addr[0] == 0xff && param_ex->sta_addr[1] == 0xff &&
7231 	    param_ex->sta_addr[2] == 0xff && param_ex->sta_addr[3] == 0xff &&
7232 	    param_ex->sta_addr[4] == 0xff && param_ex->sta_addr[5] == 0xff)
7233 		return -EINVAL;
7234 
7235 	psta = rtw_get_stainfo(pstapriv, param_ex->sta_addr);
7236 	if (psta) {
7237 #if 0
7238 		struct {
7239 			u16 aid;
7240 			u16 capability;
7241 			int flags;
7242 			u32 sta_set;
7243 			u8 tx_supp_rates[16];
7244 			u32 tx_supp_rates_len;
7245 			struct rtw_ieee80211_ht_cap ht_cap;
7246 			u64	rx_pkts;
7247 			u64	rx_bytes;
7248 			u64	rx_drops;
7249 			u64	tx_pkts;
7250 			u64	tx_bytes;
7251 			u64	tx_drops;
7252 		} get_sta;
7253 #endif
7254 		psta_data->aid = (u16)psta->cmn.aid;
7255 		psta_data->capability = psta->capability;
7256 		psta_data->flags = psta->flags;
7257 
7258 		/*
7259 				nonerp_set : BIT(0)
7260 				no_short_slot_time_set : BIT(1)
7261 				no_short_preamble_set : BIT(2)
7262 				no_ht_gf_set : BIT(3)
7263 				no_ht_set : BIT(4)
7264 				ht_20mhz_set : BIT(5)
7265 		*/
7266 
7267 		psta_data->sta_set = ((psta->nonerp_set) |
7268 				      (psta->no_short_slot_time_set << 1) |
7269 				      (psta->no_short_preamble_set << 2) |
7270 				      (psta->no_ht_gf_set << 3) |
7271 				      (psta->no_ht_set << 4) |
7272 				      (psta->ht_20mhz_set << 5));
7273 
7274 		psta_data->tx_supp_rates_len =  psta->bssratelen;
7275 		_rtw_memcpy(psta_data->tx_supp_rates, psta->bssrateset, psta->bssratelen);
7276 #ifdef CONFIG_80211N_HT
7277 		if(padapter->registrypriv.ht_enable && is_supported_ht(padapter->registrypriv.wireless_mode))
7278 			_rtw_memcpy(&psta_data->ht_cap, &psta->htpriv.ht_cap, sizeof(struct rtw_ieee80211_ht_cap));
7279 #endif /* CONFIG_80211N_HT */
7280 		psta_data->rx_pkts = psta->sta_stats.rx_data_pkts;
7281 		psta_data->rx_bytes = psta->sta_stats.rx_bytes;
7282 		psta_data->rx_drops = psta->sta_stats.rx_drops;
7283 
7284 		psta_data->tx_pkts = psta->sta_stats.tx_pkts;
7285 		psta_data->tx_bytes = psta->sta_stats.tx_bytes;
7286 		psta_data->tx_drops = psta->sta_stats.tx_drops;
7287 
7288 
7289 	} else
7290 		ret = -1;
7291 
7292 	return ret;
7293 
7294 }
7295 
7296 static int rtw_get_sta_wpaie(struct net_device *dev, struct ieee_param *param)
7297 {
7298 	int ret = 0;
7299 	struct sta_info *psta = NULL;
7300 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
7301 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
7302 	struct sta_priv *pstapriv = &padapter->stapriv;
7303 
7304 	RTW_INFO("rtw_get_sta_wpaie, sta_addr: " MAC_FMT "\n", MAC_ARG(param->sta_addr));
7305 
7306 	if (check_fwstate(pmlmepriv, (WIFI_ASOC_STATE | WIFI_AP_STATE)) != _TRUE)
7307 		return -EINVAL;
7308 
7309 	if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
7310 	    param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
7311 	    param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
7312 		return -EINVAL;
7313 
7314 	psta = rtw_get_stainfo(pstapriv, param->sta_addr);
7315 	if (psta) {
7316 		if ((psta->wpa_ie[0] == WLAN_EID_RSN) || (psta->wpa_ie[0] == WLAN_EID_GENERIC)) {
7317 			int wpa_ie_len;
7318 			int copy_len;
7319 
7320 			wpa_ie_len = psta->wpa_ie[1];
7321 
7322 			copy_len = ((wpa_ie_len + 2) > sizeof(psta->wpa_ie)) ? (sizeof(psta->wpa_ie)) : (wpa_ie_len + 2);
7323 
7324 			param->u.wpa_ie.len = copy_len;
7325 
7326 			_rtw_memcpy(param->u.wpa_ie.reserved, psta->wpa_ie, copy_len);
7327 		} else {
7328 			/* ret = -1; */
7329 			RTW_INFO("sta's wpa_ie is NONE\n");
7330 		}
7331 	} else
7332 		ret = -1;
7333 
7334 	return ret;
7335 
7336 }
7337 
7338 static int rtw_set_wps_beacon(struct net_device *dev, struct ieee_param *param, int len)
7339 {
7340 	int ret = 0;
7341 	unsigned char wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
7342 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
7343 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
7344 	struct mlme_ext_priv	*pmlmeext = &(padapter->mlmeextpriv);
7345 	int ie_len;
7346 
7347 	RTW_INFO("%s, len=%d\n", __FUNCTION__, len);
7348 
7349 	if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
7350 		return -EINVAL;
7351 
7352 	ie_len = len - 12 - 2; /* 12 = param header, 2:no packed */
7353 
7354 
7355 	if (pmlmepriv->wps_beacon_ie) {
7356 		rtw_mfree(pmlmepriv->wps_beacon_ie, pmlmepriv->wps_beacon_ie_len);
7357 		pmlmepriv->wps_beacon_ie = NULL;
7358 	}
7359 
7360 	if (ie_len > 0) {
7361 		pmlmepriv->wps_beacon_ie = rtw_malloc(ie_len);
7362 		pmlmepriv->wps_beacon_ie_len = ie_len;
7363 		if (pmlmepriv->wps_beacon_ie == NULL) {
7364 			RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
7365 			return -EINVAL;
7366 		}
7367 
7368 		_rtw_memcpy(pmlmepriv->wps_beacon_ie, param->u.bcn_ie.buf, ie_len);
7369 
7370 		update_beacon(padapter, _VENDOR_SPECIFIC_IE_, wps_oui, _TRUE, 0);
7371 
7372 		pmlmeext->bstart_bss = _TRUE;
7373 
7374 	}
7375 
7376 
7377 	return ret;
7378 
7379 }
7380 
7381 static int rtw_set_wps_probe_resp(struct net_device *dev, struct ieee_param *param, int len)
7382 {
7383 	int ret = 0;
7384 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
7385 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
7386 	int ie_len;
7387 
7388 	RTW_INFO("%s, len=%d\n", __FUNCTION__, len);
7389 
7390 	if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
7391 		return -EINVAL;
7392 
7393 	ie_len = len - 12 - 2; /* 12 = param header, 2:no packed */
7394 
7395 
7396 	if (pmlmepriv->wps_probe_resp_ie) {
7397 		rtw_mfree(pmlmepriv->wps_probe_resp_ie, pmlmepriv->wps_probe_resp_ie_len);
7398 		pmlmepriv->wps_probe_resp_ie = NULL;
7399 	}
7400 
7401 	if (ie_len > 0) {
7402 		pmlmepriv->wps_probe_resp_ie = rtw_malloc(ie_len);
7403 		pmlmepriv->wps_probe_resp_ie_len = ie_len;
7404 		if (pmlmepriv->wps_probe_resp_ie == NULL) {
7405 			RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
7406 			return -EINVAL;
7407 		}
7408 		_rtw_memcpy(pmlmepriv->wps_probe_resp_ie, param->u.bcn_ie.buf, ie_len);
7409 	}
7410 
7411 
7412 	return ret;
7413 
7414 }
7415 
7416 static int rtw_set_wps_assoc_resp(struct net_device *dev, struct ieee_param *param, int len)
7417 {
7418 	int ret = 0;
7419 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
7420 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
7421 	int ie_len;
7422 
7423 	RTW_INFO("%s, len=%d\n", __FUNCTION__, len);
7424 
7425 	if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
7426 		return -EINVAL;
7427 
7428 	ie_len = len - 12 - 2; /* 12 = param header, 2:no packed */
7429 
7430 
7431 	if (pmlmepriv->wps_assoc_resp_ie) {
7432 		rtw_mfree(pmlmepriv->wps_assoc_resp_ie, pmlmepriv->wps_assoc_resp_ie_len);
7433 		pmlmepriv->wps_assoc_resp_ie = NULL;
7434 	}
7435 
7436 	if (ie_len > 0) {
7437 		pmlmepriv->wps_assoc_resp_ie = rtw_malloc(ie_len);
7438 		pmlmepriv->wps_assoc_resp_ie_len = ie_len;
7439 		if (pmlmepriv->wps_assoc_resp_ie == NULL) {
7440 			RTW_INFO("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
7441 			return -EINVAL;
7442 		}
7443 
7444 		_rtw_memcpy(pmlmepriv->wps_assoc_resp_ie, param->u.bcn_ie.buf, ie_len);
7445 	}
7446 
7447 
7448 	return ret;
7449 
7450 }
7451 
7452 static int rtw_set_hidden_ssid(struct net_device *dev, struct ieee_param *param, int len)
7453 {
7454 	int ret = 0;
7455 	_adapter *adapter = (_adapter *)rtw_netdev_priv(dev);
7456 	struct mlme_priv *mlmepriv = &(adapter->mlmepriv);
7457 	struct mlme_ext_priv	*mlmeext = &(adapter->mlmeextpriv);
7458 	struct mlme_ext_info	*mlmeinfo = &(mlmeext->mlmext_info);
7459 	int ie_len;
7460 	u8 *ssid_ie;
7461 	char ssid[NDIS_802_11_LENGTH_SSID + 1];
7462 	sint ssid_len = 0;
7463 	u8 ignore_broadcast_ssid;
7464 
7465 	if (check_fwstate(mlmepriv, WIFI_AP_STATE) != _TRUE)
7466 		return -EPERM;
7467 
7468 	if (param->u.bcn_ie.reserved[0] != 0xea)
7469 		return -EINVAL;
7470 
7471 	mlmeinfo->hidden_ssid_mode = ignore_broadcast_ssid = param->u.bcn_ie.reserved[1];
7472 
7473 	ie_len = len - 12 - 2; /* 12 = param header, 2:no packed */
7474 	ssid_ie = rtw_get_ie(param->u.bcn_ie.buf,  WLAN_EID_SSID, &ssid_len, ie_len);
7475 
7476 	if (ssid_ie && ssid_len > 0 && ssid_len <= NDIS_802_11_LENGTH_SSID) {
7477 		WLAN_BSSID_EX *pbss_network = &mlmepriv->cur_network.network;
7478 		WLAN_BSSID_EX *pbss_network_ext = &mlmeinfo->network;
7479 
7480 		_rtw_memcpy(ssid, ssid_ie + 2, ssid_len);
7481 		ssid[ssid_len] = 0x0;
7482 
7483 		if (0)
7484 			RTW_INFO(FUNC_ADPT_FMT" ssid:(%s,%d), from ie:(%s,%d), (%s,%d)\n", FUNC_ADPT_ARG(adapter),
7485 				ssid, ssid_len,
7486 				pbss_network->Ssid.Ssid, pbss_network->Ssid.SsidLength,
7487 				pbss_network_ext->Ssid.Ssid, pbss_network_ext->Ssid.SsidLength);
7488 
7489 		_rtw_memcpy(pbss_network->Ssid.Ssid, (void *)ssid, ssid_len);
7490 		pbss_network->Ssid.SsidLength = ssid_len;
7491 		_rtw_memcpy(pbss_network_ext->Ssid.Ssid, (void *)ssid, ssid_len);
7492 		pbss_network_ext->Ssid.SsidLength = ssid_len;
7493 
7494 		if (0)
7495 			RTW_INFO(FUNC_ADPT_FMT" after ssid:(%s,%d), (%s,%d)\n", FUNC_ADPT_ARG(adapter),
7496 				pbss_network->Ssid.Ssid, pbss_network->Ssid.SsidLength,
7497 				pbss_network_ext->Ssid.Ssid, pbss_network_ext->Ssid.SsidLength);
7498 	}
7499 
7500 	RTW_INFO(FUNC_ADPT_FMT" ignore_broadcast_ssid:%d, %s,%d\n", FUNC_ADPT_ARG(adapter),
7501 		ignore_broadcast_ssid, ssid, ssid_len);
7502 
7503 	return ret;
7504 }
7505 
7506 #if CONFIG_RTW_MACADDR_ACL
7507 static int rtw_ioctl_acl_remove_sta(struct net_device *dev, struct ieee_param *param, int len)
7508 {
7509 	int ret = 0;
7510 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
7511 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
7512 
7513 	if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
7514 		return -EINVAL;
7515 
7516 	if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
7517 	    param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
7518 	    param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
7519 		return -EINVAL;
7520 
7521 	ret = rtw_acl_remove_sta(padapter, RTW_ACL_PERIOD_BSS, param->sta_addr);
7522 
7523 	return ret;
7524 
7525 }
7526 
7527 static int rtw_ioctl_acl_add_sta(struct net_device *dev, struct ieee_param *param, int len)
7528 {
7529 	int ret = 0;
7530 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
7531 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
7532 
7533 	if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
7534 		return -EINVAL;
7535 
7536 	if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
7537 	    param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
7538 	    param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff)
7539 		return -EINVAL;
7540 
7541 	ret = rtw_acl_add_sta(padapter, RTW_ACL_PERIOD_BSS, param->sta_addr);
7542 
7543 	return ret;
7544 
7545 }
7546 
7547 static int rtw_ioctl_set_macaddr_acl(struct net_device *dev, struct ieee_param *param, int len)
7548 {
7549 	int ret = 0;
7550 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
7551 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
7552 
7553 	if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != _TRUE)
7554 		return -EINVAL;
7555 
7556 	rtw_set_macaddr_acl(padapter, RTW_ACL_PERIOD_BSS, param->u.mlme.command);
7557 
7558 	return ret;
7559 }
7560 #endif /* CONFIG_RTW_MACADDR_ACL */
7561 
7562 static int rtw_hostapd_ioctl(struct net_device *dev, struct iw_point *p)
7563 {
7564 	struct ieee_param *param;
7565 	int ret = 0;
7566 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
7567 
7568 	/* RTW_INFO("%s\n", __FUNCTION__); */
7569 
7570 	/*
7571 	* this function is expect to call in master mode, which allows no power saving
7572 	* so, we just check hw_init_completed
7573 	*/
7574 
7575 	if (!rtw_is_hw_init_completed(padapter)) {
7576 		ret = -EPERM;
7577 		goto out;
7578 	}
7579 
7580 
7581 	/* if (p->length < sizeof(struct ieee_param) || !p->pointer){ */
7582 	if (!p->pointer) {
7583 		ret = -EINVAL;
7584 		goto out;
7585 	}
7586 
7587 	param = (struct ieee_param *)rtw_malloc(p->length);
7588 	if (param == NULL) {
7589 		ret = -ENOMEM;
7590 		goto out;
7591 	}
7592 
7593 	if (copy_from_user(param, p->pointer, p->length)) {
7594 		rtw_mfree((u8 *)param, p->length);
7595 		ret = -EFAULT;
7596 		goto out;
7597 	}
7598 
7599 	/* RTW_INFO("%s, cmd=%d\n", __FUNCTION__, param->cmd); */
7600 
7601 	switch (param->cmd) {
7602 	case RTL871X_HOSTAPD_FLUSH:
7603 
7604 		ret = rtw_hostapd_sta_flush(dev);
7605 
7606 		break;
7607 
7608 	case RTL871X_HOSTAPD_ADD_STA:
7609 
7610 		ret = rtw_add_sta(dev, param);
7611 
7612 		break;
7613 
7614 	case RTL871X_HOSTAPD_REMOVE_STA:
7615 
7616 		ret = rtw_del_sta(dev, param);
7617 
7618 		break;
7619 
7620 	case RTL871X_HOSTAPD_SET_BEACON:
7621 
7622 		ret = rtw_set_beacon(dev, param, p->length);
7623 
7624 		break;
7625 
7626 	case RTL871X_SET_ENCRYPTION:
7627 
7628 		ret = rtw_set_encryption(dev, param, p->length);
7629 
7630 		break;
7631 
7632 	case RTL871X_HOSTAPD_GET_WPAIE_STA:
7633 
7634 		ret = rtw_get_sta_wpaie(dev, param);
7635 
7636 		break;
7637 
7638 	case RTL871X_HOSTAPD_SET_WPS_BEACON:
7639 
7640 		ret = rtw_set_wps_beacon(dev, param, p->length);
7641 
7642 		break;
7643 
7644 	case RTL871X_HOSTAPD_SET_WPS_PROBE_RESP:
7645 
7646 		ret = rtw_set_wps_probe_resp(dev, param, p->length);
7647 
7648 		break;
7649 
7650 	case RTL871X_HOSTAPD_SET_WPS_ASSOC_RESP:
7651 
7652 		ret = rtw_set_wps_assoc_resp(dev, param, p->length);
7653 
7654 		break;
7655 
7656 	case RTL871X_HOSTAPD_SET_HIDDEN_SSID:
7657 
7658 		ret = rtw_set_hidden_ssid(dev, param, p->length);
7659 
7660 		break;
7661 
7662 	case RTL871X_HOSTAPD_GET_INFO_STA:
7663 
7664 		ret = rtw_ioctl_get_sta_data(dev, param, p->length);
7665 
7666 		break;
7667 
7668 #if CONFIG_RTW_MACADDR_ACL
7669 	case RTL871X_HOSTAPD_SET_MACADDR_ACL:
7670 		ret = rtw_ioctl_set_macaddr_acl(dev, param, p->length);
7671 		break;
7672 	case RTL871X_HOSTAPD_ACL_ADD_STA:
7673 		ret = rtw_ioctl_acl_add_sta(dev, param, p->length);
7674 		break;
7675 	case RTL871X_HOSTAPD_ACL_REMOVE_STA:
7676 		ret = rtw_ioctl_acl_remove_sta(dev, param, p->length);
7677 		break;
7678 #endif /* CONFIG_RTW_MACADDR_ACL */
7679 
7680 	default:
7681 		RTW_INFO("Unknown hostapd request: %d\n", param->cmd);
7682 		ret = -EOPNOTSUPP;
7683 		break;
7684 
7685 	}
7686 
7687 	if (ret == 0 && copy_to_user(p->pointer, param, p->length))
7688 		ret = -EFAULT;
7689 
7690 
7691 	rtw_mfree((u8 *)param, p->length);
7692 
7693 out:
7694 
7695 	return ret;
7696 
7697 }
7698 #endif	/*	CONFIG_AP_MODE	*/
7699 
7700 static int rtw_wx_set_priv(struct net_device *dev,
7701 			   struct iw_request_info *info,
7702 			   union iwreq_data *awrq,
7703 			   char *extra)
7704 {
7705 
7706 #ifdef CONFIG_DEBUG_RTW_WX_SET_PRIV
7707 	char *ext_dbg;
7708 #endif
7709 
7710 	int ret = 0;
7711 	int len = 0;
7712 	char *ext;
7713 #ifdef CONFIG_RTW_ANDROID
7714 	int i;
7715 #endif
7716 
7717 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
7718 	struct iw_point *dwrq = (struct iw_point *)awrq;
7719 
7720 	if (dwrq->length == 0)
7721 		return -EFAULT;
7722 
7723 	len = dwrq->length;
7724 	ext = rtw_vmalloc(len);
7725 	if (!ext)
7726 		return -ENOMEM;
7727 
7728 	if (copy_from_user(ext, dwrq->pointer, len)) {
7729 		rtw_vmfree(ext, len);
7730 		return -EFAULT;
7731 	}
7732 
7733 
7734 
7735 #ifdef CONFIG_DEBUG_RTW_WX_SET_PRIV
7736 	ext_dbg = rtw_vmalloc(len);
7737 	if (!ext_dbg) {
7738 		rtw_vmfree(ext, len);
7739 		return -ENOMEM;
7740 	}
7741 
7742 	_rtw_memcpy(ext_dbg, ext, len);
7743 #endif
7744 
7745 	/* added for wps2.0 @20110524 */
7746 	if (dwrq->flags == 0x8766 && len > 8) {
7747 		u32 cp_sz;
7748 		struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
7749 		u8 *probereq_wpsie = ext;
7750 		int probereq_wpsie_len = len;
7751 		u8 wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
7752 
7753 		if ((_VENDOR_SPECIFIC_IE_ == probereq_wpsie[0]) &&
7754 		    (_rtw_memcmp(&probereq_wpsie[2], wps_oui, 4) == _TRUE)) {
7755 			cp_sz = probereq_wpsie_len > MAX_WPS_IE_LEN ? MAX_WPS_IE_LEN : probereq_wpsie_len;
7756 
7757 			if (pmlmepriv->wps_probe_req_ie) {
7758 				u32 free_len = pmlmepriv->wps_probe_req_ie_len;
7759 				pmlmepriv->wps_probe_req_ie_len = 0;
7760 				rtw_mfree(pmlmepriv->wps_probe_req_ie, free_len);
7761 				pmlmepriv->wps_probe_req_ie = NULL;
7762 			}
7763 
7764 			pmlmepriv->wps_probe_req_ie = rtw_malloc(cp_sz);
7765 			if (pmlmepriv->wps_probe_req_ie == NULL) {
7766 				printk("%s()-%d: rtw_malloc() ERROR!\n", __FUNCTION__, __LINE__);
7767 				ret =  -EINVAL;
7768 				goto FREE_EXT;
7769 
7770 			}
7771 
7772 			_rtw_memcpy(pmlmepriv->wps_probe_req_ie, probereq_wpsie, cp_sz);
7773 			pmlmepriv->wps_probe_req_ie_len = cp_sz;
7774 
7775 		}
7776 
7777 		goto FREE_EXT;
7778 
7779 	}
7780 
7781 	if (len >= WEXT_CSCAN_HEADER_SIZE
7782 		&& _rtw_memcmp(ext, WEXT_CSCAN_HEADER, WEXT_CSCAN_HEADER_SIZE) == _TRUE
7783 	) {
7784 		ret = rtw_wx_set_scan(dev, info, awrq, ext);
7785 		goto FREE_EXT;
7786 	}
7787 
7788 #ifdef CONFIG_RTW_ANDROID
7789 	/* RTW_INFO("rtw_wx_set_priv: %s req=%s\n", dev->name, ext); */
7790 
7791 	i = rtw_android_cmdstr_to_num(ext);
7792 
7793 	switch (i) {
7794 	case ANDROID_WIFI_CMD_START:
7795 		indicate_wx_custom_event(padapter, "START");
7796 		break;
7797 	case ANDROID_WIFI_CMD_STOP:
7798 		indicate_wx_custom_event(padapter, "STOP");
7799 		break;
7800 	case ANDROID_WIFI_CMD_RSSI: {
7801 		struct	mlme_priv	*pmlmepriv = &(padapter->mlmepriv);
7802 		struct	wlan_network	*pcur_network = &pmlmepriv->cur_network;
7803 
7804 		if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)
7805 			sprintf(ext, "%s rssi %d", pcur_network->network.Ssid.Ssid, padapter->recvpriv.rssi);
7806 		else
7807 			sprintf(ext, "OK");
7808 	}
7809 		break;
7810 	case ANDROID_WIFI_CMD_LINKSPEED: {
7811 		u16 mbps = rtw_get_cur_max_rate(padapter) / 10;
7812 		sprintf(ext, "LINKSPEED %d", mbps);
7813 	}
7814 		break;
7815 	case ANDROID_WIFI_CMD_MACADDR:
7816 		sprintf(ext, "MACADDR = " MAC_FMT, MAC_ARG(dev->dev_addr));
7817 		break;
7818 	case ANDROID_WIFI_CMD_SCAN_ACTIVE: {
7819 		/* rtw_set_scan_mode(padapter, SCAN_ACTIVE); */
7820 		sprintf(ext, "OK");
7821 	}
7822 		break;
7823 	case ANDROID_WIFI_CMD_SCAN_PASSIVE: {
7824 		/* rtw_set_scan_mode(padapter, SCAN_PASSIVE); */
7825 		sprintf(ext, "OK");
7826 	}
7827 		break;
7828 
7829 	case ANDROID_WIFI_CMD_COUNTRY: {
7830 		char country_code[10];
7831 		sscanf(ext, "%*s %s", country_code);
7832 		rtw_set_country(padapter, country_code, RTW_REGD_SET_BY_USER);
7833 		sprintf(ext, "OK");
7834 	}
7835 		break;
7836 	default:
7837 		#ifdef CONFIG_DEBUG_RTW_WX_SET_PRIV
7838 		RTW_INFO("%s: %s unknowned req=%s\n", __FUNCTION__,
7839 			dev->name, ext_dbg);
7840 		#endif
7841 
7842 		sprintf(ext, "OK");
7843 
7844 	}
7845 
7846 	if (copy_to_user(dwrq->pointer, ext, min(dwrq->length, (u16)(strlen(ext) + 1))))
7847 		ret = -EFAULT;
7848 
7849 #ifdef CONFIG_DEBUG_RTW_WX_SET_PRIV
7850 	RTW_INFO("%s: %s req=%s rep=%s dwrq->length=%d, strlen(ext)+1=%d\n", __FUNCTION__,
7851 		dev->name, ext_dbg , ext, dwrq->length, (u16)(strlen(ext) + 1));
7852 #endif
7853 #endif /* end of CONFIG_ANDROID */
7854 
7855 
7856 FREE_EXT:
7857 
7858 	rtw_vmfree(ext, len);
7859 	#ifdef CONFIG_DEBUG_RTW_WX_SET_PRIV
7860 	rtw_vmfree(ext_dbg, len);
7861 	#endif
7862 
7863 	/* RTW_INFO("rtw_wx_set_priv: (SIOCSIWPRIV) %s ret=%d\n",  */
7864 	/*		dev->name, ret); */
7865 
7866 	return ret;
7867 
7868 }
7869 #endif	/*CONFIG_IOCTL_WEXT*/
7870 
7871 #ifdef CONFIG_WOWLAN
7872 static int rtw_wowlan_ctrl(struct net_device *dev,
7873 			   struct iw_request_info *info,
7874 			   union iwreq_data *wrqu, char *extra)
7875 {
7876 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
7877 	struct wowlan_ioctl_param poidparam;
7878 	struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
7879 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
7880 	int ret = 0;
7881 	systime start_time = rtw_get_current_time();
7882 	poidparam.subcode = 0;
7883 
7884 	RTW_INFO("+rtw_wowlan_ctrl: %s\n", extra);
7885 
7886 	if (!check_fwstate(pmlmepriv, WIFI_ASOC_STATE) &&
7887 		check_fwstate(pmlmepriv, WIFI_STATION_STATE) &&
7888 		!WOWLAN_IS_STA_MIX_MODE(padapter)) {
7889 #ifdef CONFIG_PNO_SUPPORT
7890 		pwrctrlpriv->wowlan_pno_enable = _TRUE;
7891 #else
7892 		RTW_INFO("[%s] WARNING: Please Connect With AP First!!\n", __func__);
7893 		goto _rtw_wowlan_ctrl_exit_free;
7894 #endif /* CONFIG_PNO_SUPPORT */
7895 	}
7896 
7897 	if (check_fwstate(pmlmepriv, WIFI_UNDER_SURVEY))
7898 		rtw_scan_abort(padapter);
7899 
7900 	if (_rtw_memcmp(extra, "enable", 6))
7901 
7902 
7903 		rtw_suspend_common(padapter);
7904 
7905 	else if (_rtw_memcmp(extra, "disable", 7)) {
7906 #ifdef CONFIG_USB_HCI
7907 		RTW_ENABLE_FUNC(padapter, DF_RX_BIT);
7908 		RTW_ENABLE_FUNC(padapter, DF_TX_BIT);
7909 #endif
7910 		rtw_resume_common(padapter);
7911 
7912 #ifdef CONFIG_PNO_SUPPORT
7913 		pwrctrlpriv->wowlan_pno_enable = _FALSE;
7914 #endif /* CONFIG_PNO_SUPPORT */
7915 
7916 	} else {
7917 		RTW_INFO("[%s] Invalid Parameter.\n", __func__);
7918 		goto _rtw_wowlan_ctrl_exit_free;
7919 	}
7920 	/* mutex_lock(&ioctl_mutex); */
7921 _rtw_wowlan_ctrl_exit_free:
7922 	RTW_INFO("-rtw_wowlan_ctrl( subcode = %d)\n", poidparam.subcode);
7923 	RTW_PRINT("%s in %d ms\n", __func__,
7924 		  rtw_get_passing_time_ms(start_time));
7925 	return ret;
7926 }
7927 
7928 /*
7929  * IP filter This pattern if for a frame containing a ip packet:
7930  * AA:AA:AA:AA:AA:AA:BB:BB:BB:BB:BB:BB:CC:CC:DD:-:-:-:-:-:-:-:-:EE:-:-:FF:FF:FF:FF:GG:GG:GG:GG:HH:HH:II:II
7931  *
7932  * A: Ethernet destination address
7933  * B: Ethernet source address
7934  * C: Ethernet protocol type
7935  * D: IP header VER+Hlen, use: 0x45 (4 is for ver 4, 5 is for len 20)
7936  * E: IP protocol
7937  * F: IP source address ( 192.168.0.4: C0:A8:00:2C )
7938  * G: IP destination address ( 192.168.0.4: C0:A8:00:2C )
7939  * H: Source port (1024: 04:00)
7940  * I: Destination port (1024: 04:00)
7941  */
7942 
7943 static int rtw_wowlan_set_pattern(struct net_device *dev,
7944 				  struct iw_request_info *info,
7945 				  union iwreq_data *wrqu, char *extra)
7946 {
7947 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
7948 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
7949 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
7950 	struct wowlan_ioctl_param poidparam;
7951 	int ret = 0;
7952 	u8 input[MAX_IN_PATTERN_SIZE];
7953 	u8 index = 0;
7954 
7955 	poidparam.subcode = 0;
7956 
7957 	if (!check_fwstate(pmlmepriv, WIFI_ASOC_STATE) &&
7958 	    check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
7959 		ret = -EFAULT;
7960 		RTW_INFO("Please Connect With AP First!!\n");
7961 		goto _rtw_wowlan_set_pattern_exit;
7962 	}
7963 
7964 	if ((wrqu->data.length <= 0) || (wrqu->data.length > MAX_IN_PATTERN_SIZE)) {
7965 		ret = -EFAULT;
7966 		RTW_INFO("ERROR: parameter length error, len=%d\n", wrqu->data.length);
7967 		goto _rtw_wowlan_set_pattern_exit;
7968 	} else {
7969 		/* set pattern */
7970 		if (copy_from_user(input,
7971 				   wrqu->data.pointer, wrqu->data.length))
7972 			return -EFAULT;
7973 		/* leave PS first */
7974 		rtw_ps_deny(padapter, PS_DENY_IOCTL);
7975 		LeaveAllPowerSaveModeDirect(padapter);
7976 		if ((strncmp(input, "pattern=", 8) == 0) ||(strncmp(input, "ack_pattern=", 12) == 0)) {
7977 			if (pwrpriv->wowlan_pattern_idx >= MAX_WKFM_CAM_NUM) {
7978 				RTW_INFO("WARNING: priv-pattern is full(idx: %d)\n",
7979 					 pwrpriv->wowlan_pattern_idx);
7980 				RTW_INFO("WARNING: please clean priv-pattern first\n");
7981 				ret = -EINVAL;
7982 				goto _rtw_wowlan_set_pattern_exit;
7983 			} else {
7984 				index = pwrpriv->wowlan_pattern_idx;
7985 				ret = rtw_wowlan_parser_pattern_cmd(input,
7986 					    pwrpriv->patterns[index].content,
7987 					    &pwrpriv->patterns[index].len,
7988 					    pwrpriv->patterns[index].mask);
7989 
7990 				if (ret == _TRUE) {
7991 					#ifdef CONFIG_WOW_KEEP_ALIVE_PATTERN
7992 					if(strncmp(input, "ack_pattern=", 12) == 0)
7993 						pwrpriv->wowlan_keep_alive_ack_index = index;
7994 					else
7995 						pwrpriv->wowlan_wake_pattern_index = index;
7996 					RTW_INFO("pwrpriv->wowlan_keep_alive_ack_index =%d\n",pwrpriv->wowlan_keep_alive_ack_index);
7997 					RTW_INFO("pwrpriv->wowlan_wake_pattern_index =%d\n",pwrpriv->wowlan_wake_pattern_index);
7998 					#endif /*CONFIG_WOW_KEEP_ALIVE_PATTERN*/
7999 					pwrpriv->wowlan_pattern_idx++;
8000 				}
8001 			}
8002 		} else if (strncmp(input, "clean", 5) == 0) {
8003 			poidparam.subcode = WOWLAN_PATTERN_CLEAN;
8004 			#ifdef CONFIG_WOW_KEEP_ALIVE_PATTERN
8005 			pwrpriv->wowlan_wake_pattern_index = 0xFF;
8006 			pwrpriv->wowlan_keep_alive_ack_index = 0xFF;
8007 			#endif /*CONFIG_WOW_KEEP_ALIVE_PATTERN*/
8008 
8009 			rtw_hal_set_hwreg(padapter,
8010 					  HW_VAR_WOWLAN, (u8 *)&poidparam);
8011 		} else if (strncmp(input, "show", 4) == 0) {
8012 			rtw_wow_pattern_cam_dump(padapter);
8013 			rtw_wow_pattern_sw_dump(padapter);
8014 		} else {
8015 			RTW_INFO("ERROR: incorrect parameter!\n");
8016 			ret = -EINVAL;
8017 		}
8018 		rtw_ps_deny_cancel(padapter, PS_DENY_IOCTL);
8019 	}
8020 _rtw_wowlan_set_pattern_exit:
8021 	return ret;
8022 }
8023 
8024 #ifdef CONFIG_WOW_KEEP_ALIVE_PATTERN
8025 static int rtw_wowlan_set_keep_alive_pattern(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
8026 {
8027 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
8028 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
8029 
8030 	int ret = 0,totoal_len=0,i=0,len=0;
8031 	char *cp = NULL;
8032 	u32	mode = 0xFF;  /*para1*/
8033 	u16 period = 15*10; /* para2;units:100ms,default 15s*/
8034 	char tx_pattern[512];	   /*para3*/
8035 	u32   retry_intervel = 2*10; /* para4;units:100ms,default 2s*/
8036 	u32	retry_limit_count = 5; /*para5*/
8037 
8038 	ret = sscanf(extra, "%d %hu %s %d %d", &mode , &period, tx_pattern, &retry_intervel, &retry_limit_count);
8039 	pwrpriv->wowlan_keep_alive_mode = mode;
8040 
8041 	RTW_INFO("[%s] ret =%d \n", __func__ ,ret);
8042 	totoal_len = strlen(tx_pattern);
8043 	RTW_INFO("[%s] totoal_len=%d \n", __func__ ,totoal_len);
8044 
8045 	 if (mode && (ret < 3))
8046                 return  -EINVAL;
8047 
8048 	 if (((mode ==2) ||(mode ==3)) && ((retry_intervel*retry_limit_count) > period)) {
8049 		RTW_INFO("[%s]  retry_intervel*retry_limit_count need smaller than period\n", __func__ );
8050 		return  -EINVAL;
8051 	 }
8052 
8053 	switch(mode){
8054 		case wow_keep_alive_pattern_disable:
8055 			/*disable this feature*/
8056 			pwrpriv->keep_alive_pattern_loc = 0;
8057 			pwrpriv->keep_alive_pattern_len = 0;
8058 			pwrpriv->wowlan_keep_alive_period = 0;
8059 			pwrpriv->wowlan_keep_alive_ack_index = 0xFF;
8060 			pwrpriv->wowlan_wake_pattern_index = 0xFF;
8061 			pwrpriv->wowlan_keep_alive_retry_interval = 0;
8062 			pwrpriv->wowlan_keep_alive_retry_counter = 0;
8063 			_rtw_memset(pwrpriv->keep_alive_pattern,0,WLAN_MAX_KEEP_ALIVE_IE_LEN);
8064 			RTW_INFO("[%s] clear pattern \n", __func__ );
8065 			ret = _SUCCESS;
8066 			break;
8067 		case wow_keep_alive_pattern_tx:
8068 			/*only tx udp packet*/
8069 			pwrpriv->wowlan_keep_alive_period = period;
8070 			pwrpriv->wowlan_keep_alive_retry_interval = 0;
8071 			pwrpriv->wowlan_keep_alive_retry_counter = 0;
8072 			RTW_INFO("[%s] wow_keep_alive_pattern_tx \n", __func__ );
8073 			break;
8074 		case wow_keep_alive_pattern_trx:
8075 			/*trx+no need wakeup*/
8076 			pwrpriv->wowlan_keep_alive_period = period;
8077 			pwrpriv->wowlan_keep_alive_retry_interval = retry_intervel;
8078 			pwrpriv->wowlan_keep_alive_retry_counter = retry_limit_count;
8079 			RTW_INFO("[%s] wow_keep_alive_pattern_trx \n", __func__ );
8080 			break;
8081 		case wow_keep_alive_pattern_trx_with_ack:
8082 			/*trx+need wakeup*/
8083 			pwrpriv->wowlan_keep_alive_period = period;
8084 			pwrpriv->wowlan_keep_alive_retry_interval = retry_intervel;
8085 			pwrpriv->wowlan_keep_alive_retry_counter = retry_limit_count;
8086 			RTW_INFO("[%s] wow_keep_alive_pattern_trx_with_ack \n", __func__ );
8087 			break;
8088 		default:
8089 			RTW_INFO("[%s] please setting valid mode \n", __func__ );
8090 			ret = -EINVAL;
8091 			break;
8092 
8093 	}
8094 
8095 	if((mode == 0) || (mode > 4))
8096 		return ret;
8097 
8098 	totoal_len = strlen(tx_pattern);
8099 	RTW_INFO("[%s] totoal_len=%d \n", __func__ ,totoal_len);
8100 	if (totoal_len > WLAN_MAX_KEEP_ALIVE_IE_LEN*2) {
8101 		RTW_INFO("[%s] Fail , not support ie length extend %d\n", __func__ , WLAN_MAX_KEEP_ALIVE_IE_LEN);
8102 		return -EFAULT;
8103 	}
8104 	RTW_INFO("[%s] period = %hu ,ie = %s , len = %d\n", __func__ , period , tx_pattern  , totoal_len);
8105 
8106 
8107 	if (totoal_len > 0) {
8108 		RTW_INFO("[%s] pwrpriv->keep_alive_pattern==========> \n", __func__ );
8109 		for (i = 0  ; i <totoal_len ; i += 2) {
8110 			pwrpriv->keep_alive_pattern[len] = key_2char2num(tx_pattern[i], tx_pattern[i + 1]);
8111 			RTW_INFO("[0x%x] ",pwrpriv->keep_alive_pattern[len]);
8112 			len++;
8113 		}
8114 		RTW_INFO(" \n" );
8115 		pwrpriv->keep_alive_pattern_len = len;
8116 	}
8117 
8118 	return ret;
8119 }
8120 #endif /*CONFIG_WOW_KEEP_ALIVE_PATTERN*/
8121 
8122 #endif /* CONFIG_WOWLAN */
8123 
8124 #ifdef CONFIG_AP_WOWLAN
8125 static int rtw_ap_wowlan_ctrl(struct net_device *dev,
8126 			      struct iw_request_info *info,
8127 			      union iwreq_data *wrqu, char *extra)
8128 {
8129 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
8130 	struct wowlan_ioctl_param poidparam;
8131 	struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
8132 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
8133 	struct sta_info	*psta = NULL;
8134 	int ret = 0;
8135 	systime start_time = rtw_get_current_time();
8136 	poidparam.subcode = 0;
8137 
8138 	RTW_INFO("+rtw_ap_wowlan_ctrl: %s\n", extra);
8139 
8140 	if (!check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
8141 		RTW_INFO("[%s] It is not AP mode!!\n", __func__);
8142 		goto _rtw_ap_wowlan_ctrl_exit_free;
8143 	}
8144 
8145 	if (_rtw_memcmp(extra, "enable", 6)) {
8146 
8147 		pwrctrlpriv->wowlan_ap_mode = _TRUE;
8148 
8149 		rtw_suspend_common(padapter);
8150 	} else if (_rtw_memcmp(extra, "disable", 7)) {
8151 #ifdef CONFIG_USB_HCI
8152 		RTW_ENABLE_FUNC(padapter, DF_RX_BIT);
8153 		RTW_ENABLE_FUNC(padapter, DF_TX_BIT);
8154 #endif
8155 		rtw_resume_common(padapter);
8156 	} else {
8157 		RTW_INFO("[%s] Invalid Parameter.\n", __func__);
8158 		goto _rtw_ap_wowlan_ctrl_exit_free;
8159 	}
8160 	/* mutex_lock(&ioctl_mutex); */
8161 _rtw_ap_wowlan_ctrl_exit_free:
8162 	RTW_INFO("-rtw_ap_wowlan_ctrl( subcode = %d)\n", poidparam.subcode);
8163 	RTW_PRINT("%s in %d ms\n", __func__,
8164 		  rtw_get_passing_time_ms(start_time));
8165 _rtw_ap_wowlan_ctrl_exit:
8166 	return ret;
8167 }
8168 #endif /* CONFIG_AP_WOWLAN */
8169 
8170 static int rtw_pm_set(struct net_device *dev,
8171 		      struct iw_request_info *info,
8172 		      union iwreq_data *wrqu, char *extra)
8173 {
8174 	int ret = 0;
8175 	unsigned	mode = 0;
8176 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
8177 
8178 	RTW_INFO("[%s] extra = %s\n", __FUNCTION__, extra);
8179 
8180 	if (_rtw_memcmp(extra, "lps=", 4)) {
8181 		sscanf(extra + 4, "%u", &mode);
8182 		ret = rtw_pm_set_lps(padapter, mode);
8183 	} else if (_rtw_memcmp(extra, "ips=", 4)) {
8184 		sscanf(extra + 4, "%u", &mode);
8185 		ret = rtw_pm_set_ips(padapter, mode);
8186 	} else if (_rtw_memcmp(extra, "lps_level=", 10)) {
8187 		if (sscanf(extra + 10, "%u", &mode) > 0)
8188 			ret = rtw_pm_set_lps_level(padapter, mode);
8189 #ifdef CONFIG_LPS_1T1R
8190 	} else if (_rtw_memcmp(extra, "lps_1t1r=", 9)) {
8191 		if (sscanf(extra + 9, "%u", &mode) > 0)
8192 			ret = rtw_pm_set_lps_1t1r(padapter, mode);
8193 #endif
8194 	}
8195 #ifdef CONFIG_WOWLAN
8196 	else if (_rtw_memcmp(extra, "wow_lps=", 8)) {
8197 		sscanf(extra + 8, "%u", &mode);
8198 		ret = rtw_pm_set_wow_lps(padapter, mode);
8199 	} else if (_rtw_memcmp(extra, "wow_lps_level=", 14)) {
8200 		if (sscanf(extra + 14, "%u", &mode) > 0)
8201 			ret = rtw_pm_set_wow_lps_level(padapter, mode);
8202 	#ifdef CONFIG_LPS_1T1R
8203 	} else if (_rtw_memcmp(extra, "wow_lps_1t1r=", 13)) {
8204 		if (sscanf(extra + 13, "%u", &mode) > 0)
8205 			ret = rtw_pm_set_wow_lps_1t1r(padapter, mode);
8206 	#endif
8207 	}
8208 #endif /* CONFIG_WOWLAN */
8209 	else
8210 		ret = -EINVAL;
8211 
8212 	return ret;
8213 }
8214 #ifdef CONFIG_APPEND_VENDOR_IE_ENABLE
8215 
8216 int rtw_vendor_ie_get_raw_data(struct net_device *dev, u32 vendor_ie_num,
8217 							   char *extra, u32 length)
8218 {
8219 	int j;
8220 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
8221 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
8222 	u32 vendor_ie_mask = 0;
8223 	char *pstring;
8224 
8225 	if (vendor_ie_num >= WLAN_MAX_VENDOR_IE_NUM) {
8226 		RTW_INFO("[%s] only support %d vendor ie\n", __func__ ,
8227 				 WLAN_MAX_VENDOR_IE_NUM);
8228 		return -EFAULT;
8229 	}
8230 
8231 	if (pmlmepriv->vendor_ielen[vendor_ie_num] == 0) {
8232 		RTW_INFO("[%s]  Fail, vendor_ie_num: %d is not set\n", __func__,
8233 				 vendor_ie_num);
8234 		return -EFAULT;
8235 	}
8236 
8237 	if (length < 2 * pmlmepriv->vendor_ielen[vendor_ie_num] + 5) {
8238 		RTW_INFO("[%s]  Fail, buffer size is too small\n", __func__);
8239 		return -EFAULT;
8240 	}
8241 
8242 	vendor_ie_mask = pmlmepriv->vendor_ie_mask[vendor_ie_num];
8243 	_rtw_memset(extra, 0, length);
8244 
8245 	pstring = extra;
8246 	pstring += sprintf(pstring, "%d,%x,", vendor_ie_num, vendor_ie_mask);
8247 
8248 	for (j = 0; j < pmlmepriv->vendor_ielen[vendor_ie_num]; j++)
8249 		pstring += sprintf(pstring, "%02x", pmlmepriv->vendor_ie[vendor_ie_num][j]);
8250 
8251 	length = pstring - extra;
8252 	return length;
8253 }
8254 
8255 int rtw_vendor_ie_get_data(struct net_device *dev, int vendor_ie_num, char *extra)
8256 {
8257 	int j;
8258 	char *pstring;
8259 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
8260 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
8261 	u32 vendor_ie_mask = 0;
8262 	__u16 length = 0;
8263 
8264 	vendor_ie_mask = pmlmepriv->vendor_ie_mask[vendor_ie_num];
8265 	pstring = extra;
8266 	pstring += sprintf(pstring , "\nVendor IE num %d , Mask:%x " , vendor_ie_num , vendor_ie_mask);
8267 
8268 	if (vendor_ie_mask & WIFI_BEACON_VENDOR_IE_BIT)
8269 		pstring += sprintf(pstring , "[Beacon]");
8270 	if (vendor_ie_mask & WIFI_PROBEREQ_VENDOR_IE_BIT)
8271 		pstring += sprintf(pstring , "[Probe Req]");
8272 	if (vendor_ie_mask & WIFI_PROBERESP_VENDOR_IE_BIT)
8273 		pstring += sprintf(pstring , "[Probe Resp]");
8274 	if (vendor_ie_mask & WIFI_ASSOCREQ_VENDOR_IE_BIT)
8275 		pstring += sprintf(pstring , "[Assoc Req]");
8276 	if (vendor_ie_mask & WIFI_ASSOCRESP_VENDOR_IE_BIT)
8277 		pstring += sprintf(pstring , "[Assoc Resp]");
8278 #ifdef CONFIG_P2P
8279 	if (vendor_ie_mask & WIFI_P2P_PROBEREQ_VENDOR_IE_BIT)
8280 		pstring += sprintf(pstring , "[P2P_Probe Req]");
8281 	if (vendor_ie_mask & WIFI_P2P_PROBERESP_VENDOR_IE_BIT)
8282 		pstring += sprintf(pstring , "[P2P_Probe Resp]");
8283 #endif
8284 
8285 	pstring += sprintf(pstring , "\nVendor IE:\n");
8286 	for (j = 0 ; j < pmlmepriv->vendor_ielen[vendor_ie_num]  ; j++)
8287 		pstring += sprintf(pstring , "%02x" , pmlmepriv->vendor_ie[vendor_ie_num][j]);
8288 
8289 	length = pstring - extra;
8290 	return length;
8291 
8292 }
8293 
8294 int rtw_vendor_ie_get(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
8295 {
8296 	int ret = 0, vendor_ie_num = 0, cmdlen;
8297 	struct iw_point *p;
8298 	u8 *ptmp;
8299 
8300 	p = &wrqu->data;
8301 	cmdlen = p->length;
8302 	if (0 == cmdlen)
8303 		return -EINVAL;
8304 
8305 	ptmp = (u8 *)rtw_malloc(cmdlen);
8306 	if (NULL == ptmp)
8307 		return -ENOMEM;
8308 
8309 	if (copy_from_user(ptmp, p->pointer, cmdlen)) {
8310 		ret = -EFAULT;
8311 		goto exit;
8312 	}
8313 	ret = sscanf(ptmp , "%d", &vendor_ie_num);
8314 	if (vendor_ie_num > WLAN_MAX_VENDOR_IE_NUM - 1) {
8315 		ret = -EFAULT;
8316 		goto exit;
8317 	}
8318 
8319 	wrqu->data.length = rtw_vendor_ie_get_data(dev, vendor_ie_num, extra);
8320 
8321 exit:
8322 	rtw_mfree(ptmp, cmdlen);
8323 
8324 	return 0;
8325 }
8326 
8327 int rtw_vendor_ie_set(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
8328 {
8329 	int ret = 0, i , len = 0 , totoal_ie_len = 0 , total_ie_len_byte = 0;
8330 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
8331 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
8332 	u32 vendor_ie_mask = 0;
8333 	u32 vendor_ie_num = 0;
8334 	u32 vendor_ie_mask_max = BIT(WLAN_MAX_VENDOR_IE_MASK_MAX) - 1;
8335 	u32 id, elen;
8336 
8337 	ret = sscanf(extra, "%d,%x,%*s", &vendor_ie_num , &vendor_ie_mask);
8338 	if (strrchr(extra , ','))
8339 		extra = strrchr(extra , ',') + 1;
8340 	else
8341 		return -EINVAL;
8342 	totoal_ie_len = strlen(extra);
8343 	RTW_INFO("[%s] vendor_ie_num = %d , vendor_ie_mask = 0x%x , vendor_ie = %s , len = %d\n", __func__ , vendor_ie_num , vendor_ie_mask , extra  , totoal_ie_len);
8344 
8345 	if (vendor_ie_num  > WLAN_MAX_VENDOR_IE_NUM - 1) {
8346 		RTW_INFO("[%s] Fail, only support %d vendor ie\n", __func__ , WLAN_MAX_VENDOR_IE_NUM);
8347 		return -EFAULT;
8348 	}
8349 
8350 	if (totoal_ie_len > WLAN_MAX_VENDOR_IE_LEN) {
8351 		RTW_INFO("[%s] Fail , not support ie length extend %d\n", __func__ , WLAN_MAX_VENDOR_IE_LEN);
8352 		return -EFAULT;
8353 	}
8354 
8355 	if (vendor_ie_mask > vendor_ie_mask_max) {
8356 		RTW_INFO("[%s] Fail, not support vendor_ie_mask more than 0x%x\n", __func__ , vendor_ie_mask_max);
8357 		return -EFAULT;
8358 	}
8359 
8360 	if (vendor_ie_mask == 0) {
8361 		RTW_INFO("[%s] Clear vendor_ie_num %d group\n", __func__ , vendor_ie_num);
8362 		goto _clear_path;
8363 	}
8364 
8365 	if (totoal_ie_len % 2 != 0) {
8366 		RTW_INFO("[%s]  Fail , IE length = %zu is odd\n" , __func__ , strlen(extra));
8367 		return -EFAULT;
8368 	}
8369 
8370 	if (totoal_ie_len > 0) {
8371 		for (i = 0  ; i < strlen(extra) ; i += 2) {
8372 			pmlmepriv->vendor_ie[vendor_ie_num][len] = key_2char2num(extra[i] , extra[i + 1]);
8373 			if (len == 0) {
8374 				id = pmlmepriv->vendor_ie[vendor_ie_num][len];
8375 				if (id != WLAN_EID_VENDOR_SPECIFIC) {
8376 					RTW_INFO("[%s] Fail , VENDOR SPECIFIC IE ID \"%x\" was not correct\n", __func__ , id);
8377 					goto _clear_path;
8378 				}
8379 			} else if (len == 1) {
8380 				total_ie_len_byte = (totoal_ie_len / 2) - 2;
8381 				elen = pmlmepriv->vendor_ie[vendor_ie_num][len];
8382 				if (elen != total_ie_len_byte) {
8383 					RTW_INFO("[%s] Fail , Input IE length = \"%d\"(hex:%x) bytes , not match input total IE context length \"%d\" bytes\n", __func__ , elen , elen ,
8384 						 total_ie_len_byte);
8385 					goto _clear_path;
8386 				}
8387 			}
8388 			len++;
8389 		}
8390 		pmlmepriv->vendor_ielen[vendor_ie_num] = len;
8391 	} else
8392 		pmlmepriv->vendor_ielen[vendor_ie_num] = 0;
8393 
8394 
8395 
8396 	if (vendor_ie_mask & WIFI_BEACON_VENDOR_IE_BIT)
8397 		RTW_INFO("[%s] Beacon append vendor ie\n", __func__);
8398 	if (vendor_ie_mask & WIFI_PROBEREQ_VENDOR_IE_BIT)
8399 		RTW_INFO("[%s] Probe Req append vendor ie\n", __func__);
8400 	if (vendor_ie_mask & WIFI_PROBERESP_VENDOR_IE_BIT)
8401 		RTW_INFO("[%s] Probe Resp append vendor ie\n", __func__);
8402 	if (vendor_ie_mask & WIFI_ASSOCREQ_VENDOR_IE_BIT)
8403 		RTW_INFO("[%s] Assoc Req append vendor ie\n", __func__);
8404 	if (vendor_ie_mask & WIFI_ASSOCRESP_VENDOR_IE_BIT)
8405 		RTW_INFO("[%s] Assoc Resp append vendor ie\n", __func__);
8406 #ifdef CONFIG_P2P
8407 	if (vendor_ie_mask & WIFI_P2P_PROBEREQ_VENDOR_IE_BIT)
8408 		RTW_INFO("[%s] P2P Probe Req append vendor ie\n", __func__);
8409 	if (vendor_ie_mask & WIFI_P2P_PROBERESP_VENDOR_IE_BIT)
8410 		RTW_INFO("[%s] P2P Probe Resp append vendor ie\n", __func__);
8411 #endif
8412 
8413 	pmlmepriv->vendor_ie_mask[vendor_ie_num] = vendor_ie_mask;
8414 
8415 	return ret;
8416 
8417 _clear_path:
8418 	_rtw_memset(pmlmepriv->vendor_ie[vendor_ie_num] , 0 , sizeof(u32) * WLAN_MAX_VENDOR_IE_LEN);
8419 	pmlmepriv->vendor_ielen[vendor_ie_num] = 0;
8420 	pmlmepriv->vendor_ie_mask[vendor_ie_num] = 0;
8421 	return -EFAULT;
8422 }
8423 #endif
8424 
8425 static int rtw_get_ic_type(struct net_device *dev,
8426 				struct iw_request_info *info,
8427 				union iwreq_data *wrqu, char *extra)
8428 {
8429 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
8430 	struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
8431 	char *pstring = extra;
8432 	u8 regdata;
8433 
8434 	_rtw_memset(pstring, 0, wrqu->data.length);
8435 
8436 	regdata = (rtw_read32(padapter, 0xF0) & 0xf000) >> 12;
8437 	RTW_INFO("%s: f0[15:12]= 0x%x\n", __FUNCTION__, regdata);
8438 
8439 	if (regdata == 0x04)
8440 		pstring += sprintf(pstring , ":%s\n" ,"rtl8822c-vbs");
8441 	else
8442 		pstring += sprintf(pstring , ":%s\n" ,"rtl8822c-vs");
8443 
8444 	wrqu->data.length = strlen(extra);
8445 
8446 	return 0;
8447 }
8448 
8449 static int rtw_mp_efuse_get(struct net_device *dev,
8450 			    struct iw_request_info *info,
8451 			    union iwreq_data *wdata, char *extra)
8452 {
8453 	PADAPTER padapter = rtw_netdev_priv(dev);
8454 	HAL_DATA_TYPE	*pHalData = GET_HAL_DATA(padapter);
8455 
8456 	PEFUSE_HAL pEfuseHal;
8457 	struct iw_point *wrqu;
8458 
8459 	u8 ips_mode = IPS_NUM; /* init invalid value */
8460 	u8 lps_mode = PS_MODE_NUM; /* init invalid value */
8461 	struct pwrctrl_priv *pwrctrlpriv ;
8462 	u8 *data = NULL;
8463 	u8 *rawdata = NULL;
8464 	char *pch, *ptmp, *token, *tmp[3] = {0x00, 0x00, 0x00};
8465 	u16 i = 0, j = 0, mapLen = 0, addr = 0, cnts = 0;
8466 	u16 max_available_len = 0, raw_cursize = 0, raw_maxsize = 0;
8467 	u16 mask_len;
8468 	u8 mask_buf[64] = "";
8469 	int err;
8470 	char *pextra = NULL;
8471 #ifdef CONFIG_IOL
8472 	u8 org_fw_iol = padapter->registrypriv.fw_iol;/* 0:Disable, 1:enable, 2:by usb speed */
8473 #endif
8474 
8475 	wrqu = (struct iw_point *)wdata;
8476 	pwrctrlpriv = adapter_to_pwrctl(padapter);
8477 	pEfuseHal = &pHalData->EfuseHal;
8478 
8479 	err = 0;
8480 	data = rtw_zmalloc(EFUSE_BT_MAX_MAP_LEN);
8481 	if (data == NULL) {
8482 		err = -ENOMEM;
8483 		goto exit;
8484 	}
8485 	rawdata = rtw_zmalloc(EFUSE_BT_MAX_MAP_LEN);
8486 	if (rawdata == NULL) {
8487 		err = -ENOMEM;
8488 		goto exit;
8489 	}
8490 
8491 	if (copy_from_user(extra, wrqu->pointer, wrqu->length)) {
8492 		err = -EFAULT;
8493 		goto exit;
8494 	}
8495 
8496 	*(extra + wrqu->length) = '\0';
8497 
8498 #ifdef CONFIG_LPS
8499 	lps_mode = pwrctrlpriv->power_mgnt;/* keep org value */
8500 	rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);
8501 #endif
8502 
8503 #ifdef CONFIG_IPS
8504 	ips_mode = pwrctrlpriv->ips_mode;/* keep org value */
8505 	rtw_pm_set_ips(padapter, IPS_NONE);
8506 #endif
8507 
8508 	pch = extra;
8509 	RTW_INFO("%s: in=%s\n", __FUNCTION__, extra);
8510 
8511 	i = 0;
8512 	/* mac 16 "00e04c871200" rmap,00,2 */
8513 	while ((token = strsep(&pch, ",")) != NULL) {
8514 		if (i > 2)
8515 			break;
8516 		tmp[i] = token;
8517 		i++;
8518 	}
8519 #ifdef CONFIG_IOL
8520 	padapter->registrypriv.fw_iol = 0;/* 0:Disable, 1:enable, 2:by usb speed */
8521 #endif
8522 
8523 	if (strcmp(tmp[0], "status") == 0) {
8524 		sprintf(extra, "Load File efuse=%s,Load File MAC=%s"
8525 			, pHalData->efuse_file_status == EFUSE_FILE_FAILED ? "FAIL" : "OK"
8526 			, pHalData->macaddr_file_status == MACADDR_FILE_FAILED ? "FAIL" : "OK"
8527 		       );
8528 		goto exit;
8529 	} else if (strcmp(tmp[0], "drvmap") == 0) {
8530 		static u8 drvmaporder = 0;
8531 		u8 *efuse;
8532 		u32 shift, cnt;
8533 		u32 blksz = 0x200; /* The size of one time show, default 512 */
8534 		EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&mapLen, _FALSE);
8535 
8536 		efuse = pHalData->efuse_eeprom_data;
8537 
8538 		shift = blksz * drvmaporder;
8539 		efuse += shift;
8540 		cnt = mapLen - shift;
8541 
8542 		if (cnt > blksz) {
8543 			cnt = blksz;
8544 			drvmaporder++;
8545 		} else
8546 			drvmaporder = 0;
8547 
8548 		sprintf(extra, "\n");
8549 		for (i = 0; i < cnt; i += 16) {
8550 			pextra = extra + strlen(extra);
8551 			pextra += sprintf(pextra, "0x%02x\t", shift + i);
8552 			for (j = 0; j < 8; j++)
8553 				pextra += sprintf(pextra, "%02X ", efuse[i + j]);
8554 			pextra += sprintf(pextra, "\t");
8555 			for (; j < 16; j++)
8556 				pextra += sprintf(pextra, "%02X ", efuse[i + j]);
8557 			pextra += sprintf(pextra, "\n");
8558 		}
8559 		if ((shift + cnt) < mapLen)
8560 			pextra += sprintf(pextra, "\t...more (left:%d/%d)\n", mapLen-(shift + cnt), mapLen);
8561 
8562 	} else if (strcmp(tmp[0], "realmap") == 0) {
8563 		static u8 order = 0;
8564 		u8 *efuse;
8565 		u32 shift, cnt;
8566 		u32 blksz = 0x200; /* The size of one time show, default 512 */
8567 
8568 		EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN , (void *)&mapLen, _FALSE);
8569 		efuse = pEfuseHal->fakeEfuseInitMap;
8570 		if (rtw_efuse_mask_map_read(padapter, 0, mapLen, efuse) == _FAIL) {
8571 			RTW_INFO("%s: read realmap Fail!!\n", __FUNCTION__);
8572 			err = -EFAULT;
8573 			goto exit;
8574 		}
8575 
8576 #if 0
8577 		RTW_INFO("OFFSET\tVALUE(hex)\n");
8578 		for (i = 0; i < mapLen; i += 16) {
8579 			RTW_INFO("0x%02x\t", i);
8580 			for (j = 0; j < 8; j++)
8581 				RTW_INFO("%02X ", efuse[i + j]);
8582 			RTW_INFO("\t");
8583 			for (; j < 16; j++)
8584 				RTW_INFO("%02X ", efuse[i + j]);
8585 			RTW_INFO("\n");
8586 		}
8587 		RTW_INFO("\n");
8588 #endif
8589 
8590 		shift = blksz * order;
8591 		efuse += shift;
8592 		cnt = mapLen - shift;
8593 		if (cnt > blksz) {
8594 			cnt = blksz;
8595 			order++;
8596 		} else
8597 			order = 0;
8598 
8599 		sprintf(extra, "\n");
8600 		for (i = 0; i < cnt; i += 16) {
8601 			pextra = extra + strlen(extra);
8602 			pextra += sprintf(pextra, "0x%02x\t", shift + i);
8603 			for (j = 0; j < 8; j++)
8604 				pextra += sprintf(pextra, "%02X ", efuse[i + j]);
8605 			pextra += sprintf(pextra, "\t");
8606 			for (; j < 16; j++)
8607 				pextra += sprintf(pextra, "%02X ", efuse[i + j]);
8608 			pextra += sprintf(pextra, "\n");
8609 		}
8610 		if ((shift + cnt) < mapLen)
8611 			pextra += sprintf(pextra, "\t...more (left:%d/%d)\n", mapLen-(shift + cnt), mapLen);
8612 	} else if (strcmp(tmp[0], "rmap") == 0) {
8613 		if ((tmp[1] == NULL) || (tmp[2] == NULL)) {
8614 			RTW_INFO("%s: rmap Fail!! Parameters error!\n", __FUNCTION__);
8615 			err = -EINVAL;
8616 			goto exit;
8617 		}
8618 
8619 		/* rmap addr cnts */
8620 		addr = simple_strtoul(tmp[1], &ptmp, 16);
8621 		RTW_INFO("%s: addr=%x\n", __FUNCTION__, addr);
8622 
8623 		cnts = simple_strtoul(tmp[2], &ptmp, 10);
8624 		if (cnts == 0) {
8625 			RTW_INFO("%s: rmap Fail!! cnts error!\n", __FUNCTION__);
8626 			err = -EINVAL;
8627 			goto exit;
8628 		}
8629 		RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
8630 
8631 		EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN , (void *)&max_available_len, _FALSE);
8632 		if ((addr + cnts) > max_available_len) {
8633 			RTW_INFO("%s: addr(0x%X)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
8634 			err = -EINVAL;
8635 			goto exit;
8636 		}
8637 
8638 		if (rtw_efuse_mask_map_read(padapter, addr, cnts, data) == _FAIL) {
8639 			RTW_INFO("%s: rtw_efuse_mask_map_read error!\n", __func__);
8640 			err = -EFAULT;
8641 			goto exit;
8642 		}
8643 
8644 		/*		RTW_INFO("%s: data={", __FUNCTION__); */
8645 		*extra = 0;
8646 		pextra = extra;
8647 		for (i = 0; i < cnts; i++) {
8648 			/*			RTW_INFO("0x%02x ", data[i]); */
8649 			pextra += sprintf(pextra, "0x%02X ", data[i]);
8650 		}
8651 		/*		RTW_INFO("}\n"); */
8652 	} else if (strcmp(tmp[0], "realraw") == 0) {
8653 		static u8 raw_order = 0;
8654 		u32 shift, cnt;
8655 		u32 blksz = 0x200; /* The size of one time show, default 512 */
8656 
8657 		addr = 0;
8658 		EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_REAL_CONTENT_LEN , (void *)&mapLen, _FALSE);
8659 		RTW_INFO("Real content len = %d\n",mapLen );
8660 
8661 		if (rtw_efuse_access(padapter, _FALSE, addr, mapLen, rawdata) == _FAIL) {
8662 			RTW_INFO("%s: rtw_efuse_access Fail!!\n", __func__);
8663 			err = -EFAULT;
8664 			goto exit;
8665 		}
8666 
8667 		_rtw_memset(extra, '\0', strlen(extra));
8668 
8669 		shift = blksz * raw_order;
8670 		rawdata += shift;
8671 		cnt = mapLen - shift;
8672 		if (cnt > blksz) {
8673 			cnt = blksz;
8674 			raw_order++;
8675 		} else
8676 			raw_order = 0;
8677 
8678 		sprintf(extra, "\n");
8679 		for (i = 0; i < cnt; i += 16) {
8680 			pextra = extra + strlen(extra);
8681 			pextra += sprintf(pextra, "0x%02x\t", shift + i);
8682 			for (j = 0; j < 8; j++)
8683 				pextra += sprintf(pextra, "%02X ", rawdata[i + j]);
8684 			pextra += sprintf(pextra, "\t");
8685 			for (; j < 16; j++)
8686 				pextra += sprintf(pextra, "%02X ", rawdata[i + j]);
8687 			pextra += sprintf(pextra, "\n");
8688 		}
8689 		if ((shift + cnt) < mapLen)
8690 			pextra += sprintf(pextra, "\t...more (left:%d/%d)\n", mapLen-(shift + cnt), mapLen);
8691 
8692 	} else if (strcmp(tmp[0], "btrealraw") == 0) {
8693 		static u8 bt_raw_order = 0;
8694 		u32 shift, cnt;
8695 		u32 blksz = 0x200; /* The size of one time show, default 512 */
8696 
8697 		addr = 0;
8698 		EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_EFUSE_REAL_CONTENT_LEN, (void *)&mapLen, _FALSE);
8699 		RTW_INFO("Real content len = %d\n", mapLen);
8700 #ifdef RTW_HALMAC
8701 		if (rtw_efuse_bt_access(padapter, _FALSE, 0, mapLen, rawdata) == _FAIL) {
8702 			RTW_INFO("%s: rtw_efuse_access Fail!!\n", __func__);
8703 			err = -EFAULT;
8704 			goto exit;
8705 		}
8706 #else
8707 		rtw_write8(padapter, 0x35, 0x1);
8708 
8709 		if (rtw_efuse_access(padapter, _FALSE, addr, mapLen, rawdata) == _FAIL) {
8710 			RTW_INFO("%s: rtw_efuse_access Fail!!\n", __func__);
8711 			err = -EFAULT;
8712 			goto exit;
8713 		}
8714 #endif
8715 		_rtw_memset(extra, '\0', strlen(extra));
8716 
8717 		shift = blksz * bt_raw_order;
8718 		rawdata += shift;
8719 		cnt = mapLen - shift;
8720 		if (cnt > blksz) {
8721 			cnt = blksz;
8722 			bt_raw_order++;
8723 		} else
8724 			bt_raw_order = 0;
8725 
8726 		sprintf(extra, "\n");
8727 		for (i = 0; i < cnt; i += 16) {
8728 			pextra = extra + strlen(extra);
8729 			pextra += sprintf(pextra, "0x%02x\t", shift + i);
8730 			for (j = 0; j < 8; j++)
8731 				pextra += sprintf(pextra, "%02X ", rawdata[i + j]);
8732 			pextra += sprintf(pextra, "\t");
8733 			for (; j < 16; j++)
8734 				pextra += sprintf(pextra, "%02X ", rawdata[i + j]);
8735 			pextra += sprintf(pextra, "\n");
8736 		}
8737 		if ((shift + cnt) < mapLen)
8738 			pextra += sprintf(pextra, "\t...more (left:%d/%d)\n", mapLen-(shift + cnt), mapLen);
8739 
8740 	} else if (strcmp(tmp[0], "mac") == 0) {
8741 		if (hal_efuse_macaddr_offset(padapter) == -1) {
8742 			err = -EFAULT;
8743 			goto exit;
8744 		}
8745 
8746 		addr = hal_efuse_macaddr_offset(padapter);
8747 		cnts = 6;
8748 
8749 		EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&max_available_len, _FALSE);
8750 		if ((addr + cnts) > max_available_len) {
8751 			RTW_INFO("%s: addr(0x%02x)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
8752 			err = -EFAULT;
8753 			goto exit;
8754 		}
8755 
8756 		if (rtw_efuse_mask_map_read(padapter, addr, cnts, data) == _FAIL) {
8757 			RTW_INFO("%s: rtw_efuse_mask_map_read error!\n", __func__);
8758 			err = -EFAULT;
8759 			goto exit;
8760 		}
8761 
8762 		/*		RTW_INFO("%s: MAC address={", __FUNCTION__); */
8763 		*extra = 0;
8764 		pextra = extra;
8765 		for (i = 0; i < cnts; i++) {
8766 			/*			RTW_INFO("%02X", data[i]); */
8767 			pextra += sprintf(pextra, "%02X", data[i]);
8768 			if (i != (cnts - 1)) {
8769 				/*				RTW_INFO(":"); */
8770 				pextra += sprintf(pextra, ":");
8771 			}
8772 		}
8773 		/*		RTW_INFO("}\n"); */
8774 	} else if (strcmp(tmp[0], "vidpid") == 0) {
8775 #ifdef CONFIG_RTL8188E
8776 #ifdef CONFIG_USB_HCI
8777 		addr = EEPROM_VID_88EU;
8778 #endif
8779 #ifdef CONFIG_PCI_HCI
8780 		addr = EEPROM_VID_88EE;
8781 #endif
8782 #endif /* CONFIG_RTL8188E */
8783 
8784 #ifdef CONFIG_RTL8192E
8785 #ifdef CONFIG_USB_HCI
8786 		addr = EEPROM_VID_8192EU;
8787 #endif
8788 #ifdef CONFIG_PCI_HCI
8789 		addr = EEPROM_VID_8192EE;
8790 #endif
8791 #endif /* CONFIG_RTL8192E */
8792 #ifdef CONFIG_RTL8723B
8793 		addr = EEPROM_VID_8723BU;
8794 #endif /* CONFIG_RTL8192E */
8795 
8796 #ifdef CONFIG_RTL8188F
8797 		addr = EEPROM_VID_8188FU;
8798 #endif /* CONFIG_RTL8188F */
8799 
8800 #ifdef CONFIG_RTL8188GTV
8801 		addr = EEPROM_VID_8188GTVU;
8802 #endif
8803 
8804 #ifdef CONFIG_RTL8703B
8805 #ifdef CONFIG_USB_HCI
8806 		addr = EEPROM_VID_8703BU;
8807 #endif
8808 #endif /* CONFIG_RTL8703B */
8809 
8810 #ifdef CONFIG_RTL8723D
8811 #ifdef CONFIG_USB_HCI
8812 		addr = EEPROM_VID_8723DU;
8813 #endif /* CONFIG_USB_HCI */
8814 #endif /* CONFIG_RTL8723D */
8815 
8816 		cnts = 4;
8817 
8818 		EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&max_available_len, _FALSE);
8819 		if ((addr + cnts) > max_available_len) {
8820 			RTW_INFO("%s: addr(0x%02x)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
8821 			err = -EFAULT;
8822 			goto exit;
8823 		}
8824 		if (rtw_efuse_mask_map_read(padapter, addr, cnts, data) == _FAIL) {
8825 			RTW_INFO("%s: rtw_efuse_access error!!\n", __FUNCTION__);
8826 			err = -EFAULT;
8827 			goto exit;
8828 		}
8829 
8830 		/*		RTW_INFO("%s: {VID,PID}={", __FUNCTION__); */
8831 		*extra = 0;
8832 		pextra = extra;
8833 		for (i = 0; i < cnts; i++) {
8834 			/*			RTW_INFO("0x%02x", data[i]); */
8835 			pextra += sprintf(pextra, "0x%02X", data[i]);
8836 			if (i != (cnts - 1)) {
8837 				/*				RTW_INFO(","); */
8838 				pextra += sprintf(pextra, ",");
8839 			}
8840 		}
8841 		/*		RTW_INFO("}\n"); */
8842 	} else if (strcmp(tmp[0], "ableraw") == 0) {
8843 #ifdef RTW_HALMAC
8844 		raw_maxsize = efuse_GetavailableSize(padapter);
8845 #else
8846 		efuse_GetCurrentSize(padapter, &raw_cursize);
8847 		raw_maxsize = efuse_GetMaxSize(padapter);
8848 #endif
8849 		sprintf(extra, "[available raw size]= %d bytes\n", raw_maxsize - raw_cursize);
8850 	} else if (strcmp(tmp[0], "btableraw") == 0) {
8851 		efuse_bt_GetCurrentSize(padapter, &raw_cursize);
8852 		raw_maxsize = efuse_bt_GetMaxSize(padapter);
8853 		sprintf(extra, "[available raw size]= %d bytes\n", raw_maxsize - raw_cursize);
8854 	} else if (strcmp(tmp[0], "btfmap") == 0) {
8855 
8856 		BTEfuse_PowerSwitch(padapter, 1, _TRUE);
8857 
8858 		mapLen = EFUSE_BT_MAX_MAP_LEN;
8859 		if (rtw_BT_efuse_map_read(padapter, 0, mapLen, pEfuseHal->BTEfuseInitMap) == _FAIL) {
8860 			RTW_INFO("%s: rtw_BT_efuse_map_read Fail!!\n", __FUNCTION__);
8861 			err = -EFAULT;
8862 			goto exit;
8863 		}
8864 
8865 		/*		RTW_INFO("OFFSET\tVALUE(hex)\n"); */
8866 		sprintf(extra, "\n");
8867 		for (i = 0; i < 512; i += 16) { /* set 512 because the iwpriv's extra size have limit 0x7FF */
8868 			/*			RTW_INFO("0x%03x\t", i); */
8869 			pextra = extra + strlen(extra);
8870 			pextra += sprintf(pextra, "0x%03x\t", i);
8871 			for (j = 0; j < 8; j++) {
8872 				/*				RTW_INFO("%02X ", pEfuseHal->BTEfuseInitMap[i+j]); */
8873 				pextra += sprintf(pextra, "%02X ", pEfuseHal->BTEfuseInitMap[i+j]);
8874 			}
8875 			/*			RTW_INFO("\t"); */
8876 			pextra += sprintf(pextra, "\t");
8877 			for (; j < 16; j++) {
8878 				/*				RTW_INFO("%02X ", pEfuseHal->BTEfuseInitMap[i+j]); */
8879 				pextra += sprintf(pextra, "%02X ", pEfuseHal->BTEfuseInitMap[i+j]);
8880 			}
8881 			/*			RTW_INFO("\n"); */
8882 			pextra += sprintf(pextra, "\n");
8883 		}
8884 		/*		RTW_INFO("\n"); */
8885 	} else if (strcmp(tmp[0], "btbmap") == 0) {
8886 		BTEfuse_PowerSwitch(padapter, 1, _TRUE);
8887 
8888 		mapLen = EFUSE_BT_MAX_MAP_LEN;
8889 		if (rtw_BT_efuse_map_read(padapter, 0, mapLen, pEfuseHal->BTEfuseInitMap) == _FAIL) {
8890 			RTW_INFO("%s: rtw_BT_efuse_map_read Fail!!\n", __FUNCTION__);
8891 			err = -EFAULT;
8892 			goto exit;
8893 		}
8894 
8895 		/*		RTW_INFO("OFFSET\tVALUE(hex)\n"); */
8896 		sprintf(extra, "\n");
8897 		for (i = 512; i < 1024 ; i += 16) {
8898 			/*			RTW_INFO("0x%03x\t", i); */
8899 			pextra = extra + strlen(extra);
8900 			pextra += sprintf(pextra, "0x%03x\t", i);
8901 			for (j = 0; j < 8; j++) {
8902 				/*				RTW_INFO("%02X ", data[i+j]); */
8903 				pextra += sprintf(pextra, "%02X ", pEfuseHal->BTEfuseInitMap[i+j]);
8904 			}
8905 			/*			RTW_INFO("\t"); */
8906 			pextra += sprintf(pextra, "\t");
8907 			for (; j < 16; j++) {
8908 				/*				RTW_INFO("%02X ", data[i+j]); */
8909 				pextra += sprintf(pextra, "%02X ", pEfuseHal->BTEfuseInitMap[i+j]);
8910 			}
8911 			/*			RTW_INFO("\n"); */
8912 			pextra += sprintf(pextra, "\n");
8913 		}
8914 		/*		RTW_INFO("\n"); */
8915 	} else if (strcmp(tmp[0], "btrmap") == 0) {
8916 		u8 BTStatus;
8917 
8918 		rtw_write8(padapter, 0xa3, 0x05); /* For 8723AB ,8821S ? */
8919 		BTStatus = rtw_read8(padapter, 0xa0);
8920 
8921 		RTW_INFO("%s: Check 0xa0 BT Status =0x%x\n", __FUNCTION__, BTStatus);
8922 		if (BTStatus != 0x04) {
8923 			sprintf(extra, "BT Status not Active ,can't to read BT eFuse\n");
8924 			goto exit;
8925 		}
8926 
8927 		if ((tmp[1] == NULL) || (tmp[2] == NULL)) {
8928 			err = -EINVAL;
8929 			goto exit;
8930 		}
8931 
8932 		BTEfuse_PowerSwitch(padapter, 1, _TRUE);
8933 
8934 		/* rmap addr cnts */
8935 		addr = simple_strtoul(tmp[1], &ptmp, 16);
8936 		RTW_INFO("%s: addr=0x%X\n", __FUNCTION__, addr);
8937 
8938 		cnts = simple_strtoul(tmp[2], &ptmp, 10);
8939 		if (cnts == 0) {
8940 			RTW_INFO("%s: btrmap Fail!! cnts error!\n", __FUNCTION__);
8941 			err = -EINVAL;
8942 			goto exit;
8943 		}
8944 		RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
8945 #ifndef RTW_HALMAC
8946 		EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_EFUSE_MAP_LEN, (void *)&max_available_len, _FALSE);
8947 		if ((addr + cnts) > max_available_len) {
8948 			RTW_INFO("%s: addr(0x%X)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
8949 			err = -EFAULT;
8950 			goto exit;
8951 		}
8952 #endif
8953 		if (rtw_BT_efuse_map_read(padapter, addr, cnts, data) == _FAIL) {
8954 			RTW_INFO("%s: rtw_BT_efuse_map_read error!!\n", __FUNCTION__);
8955 			err = -EFAULT;
8956 			goto exit;
8957 		}
8958 
8959 		*extra = 0;
8960 		pextra = extra;
8961 		/*		RTW_INFO("%s: bt efuse data={", __FUNCTION__); */
8962 		for (i = 0; i < cnts; i++) {
8963 			/*			RTW_INFO("0x%02x ", data[i]); */
8964 			pextra += sprintf(pextra, " 0x%02X ", data[i]);
8965 		}
8966 		/*		RTW_INFO("}\n"); */
8967 		RTW_INFO(FUNC_ADPT_FMT ": BT MAC=[%s]\n", FUNC_ADPT_ARG(padapter), extra);
8968 	} else if (strcmp(tmp[0], "btffake") == 0) {
8969 		/*		RTW_INFO("OFFSET\tVALUE(hex)\n"); */
8970 		sprintf(extra, "\n");
8971 		for (i = 0; i < 512; i += 16) {
8972 			/*			RTW_INFO("0x%03x\t", i); */
8973 			pextra = extra + strlen(extra);
8974 			pextra += sprintf(pextra, "0x%03x\t", i);
8975 			for (j = 0; j < 8; j++) {
8976 				/*				RTW_INFO("%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i+j]); */
8977 				pextra += sprintf(pextra, "%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i+j]);
8978 			}
8979 			/*			RTW_INFO("\t"); */
8980 			pextra += sprintf(pextra, "\t");
8981 			for (; j < 16; j++) {
8982 				/*				RTW_INFO("%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i+j]); */
8983 				pextra += sprintf(pextra, "%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i+j]);
8984 			}
8985 			/*			RTW_INFO("\n"); */
8986 			pextra += sprintf(pextra, "\n");
8987 		}
8988 		/*		RTW_INFO("\n"); */
8989 	} else if (strcmp(tmp[0], "btbfake") == 0) {
8990 		/*		RTW_INFO("OFFSET\tVALUE(hex)\n"); */
8991 		sprintf(extra, "\n");
8992 		for (i = 512; i < 1024; i += 16) {
8993 			/*			RTW_INFO("0x%03x\t", i); */
8994 			pextra = extra + strlen(extra);
8995 			pextra += sprintf(pextra, "0x%03x\t", i);
8996 			for (j = 0; j < 8; j++) {
8997 				/*				RTW_INFO("%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i+j]); */
8998 				pextra += sprintf(pextra, "%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i+j]);
8999 			}
9000 			/*			RTW_INFO("\t"); */
9001 			pextra += sprintf(pextra, "\t");
9002 			for (; j < 16; j++) {
9003 				/*				RTW_INFO("%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i+j]); */
9004 				pextra += sprintf(pextra, "%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i+j]);
9005 			}
9006 			/*			RTW_INFO("\n"); */
9007 			pextra += sprintf(pextra, "\n");
9008 		}
9009 		/*		RTW_INFO("\n"); */
9010 	} else if (strcmp(tmp[0], "wlrfkmap") == 0) {
9011 		static u8 fk_order = 0;
9012 		u8 *efuse;
9013 		u32 shift, cnt;
9014 		u32 blksz = 0x200; /* The size of one time show, default 512 */
9015 
9016 		EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN , (void *)&mapLen, _FALSE);
9017 		efuse = pEfuseHal->fakeEfuseModifiedMap;
9018 
9019 		shift = blksz * fk_order;
9020 		efuse += shift;
9021 		cnt = mapLen - shift;
9022 		if (cnt > blksz) {
9023 			cnt = blksz;
9024 			fk_order++;
9025 		} else
9026 			fk_order = 0;
9027 
9028 		sprintf(extra, "\n");
9029 		for (i = 0; i < cnt; i += 16) {
9030 			pextra = extra + strlen(extra);
9031 			pextra += sprintf(pextra, "0x%02x\t", shift + i);
9032 			for (j = 0; j < 8; j++)
9033 				pextra += sprintf(pextra, "%02X ", efuse[i + j]);
9034 			pextra += sprintf(pextra, "\t");
9035 			for (; j < 16; j++)
9036 				pextra += sprintf(pextra, "%02X ", efuse[i + j]);
9037 			pextra += sprintf(pextra, "\n");
9038 		}
9039 		if ((shift + cnt) < mapLen)
9040 			pextra += sprintf(pextra, "\t...more\n");
9041 
9042 	} else if (strcmp(tmp[0], "wlrfkrmap") == 0) {
9043 		if ((tmp[1] == NULL) || (tmp[2] == NULL)) {
9044 			RTW_INFO("%s: rmap Fail!! Parameters error!\n", __FUNCTION__);
9045 			err = -EINVAL;
9046 			goto exit;
9047 		}
9048 		/* rmap addr cnts */
9049 		addr = simple_strtoul(tmp[1], &ptmp, 16);
9050 		RTW_INFO("%s: addr=%x\n", __FUNCTION__, addr);
9051 
9052 		cnts = simple_strtoul(tmp[2], &ptmp, 10);
9053 		if (cnts == 0) {
9054 			RTW_INFO("%s: rmap Fail!! cnts error!\n", __FUNCTION__);
9055 			err = -EINVAL;
9056 			goto exit;
9057 		}
9058 		RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
9059 
9060 		/*		RTW_INFO("%s: data={", __FUNCTION__); */
9061 		*extra = 0;
9062 		pextra = extra;
9063 		for (i = 0; i < cnts; i++) {
9064 			RTW_INFO("wlrfkrmap = 0x%02x\n", pEfuseHal->fakeEfuseModifiedMap[addr + i]);
9065 			pextra += sprintf(pextra, "0x%02X ", pEfuseHal->fakeEfuseModifiedMap[addr+i]);
9066 		}
9067 	} else if (strcmp(tmp[0], "btrfkrmap") == 0) {
9068 		if ((tmp[1] == NULL) || (tmp[2] == NULL)) {
9069 			RTW_INFO("%s: rmap Fail!! Parameters error!\n", __FUNCTION__);
9070 			err = -EINVAL;
9071 			goto exit;
9072 		}
9073 		/* rmap addr cnts */
9074 		addr = simple_strtoul(tmp[1], &ptmp, 16);
9075 		RTW_INFO("%s: addr=%x\n", __FUNCTION__, addr);
9076 
9077 		cnts = simple_strtoul(tmp[2], &ptmp, 10);
9078 		if (cnts == 0) {
9079 			RTW_INFO("%s: rmap Fail!! cnts error!\n", __FUNCTION__);
9080 			err = -EINVAL;
9081 			goto exit;
9082 		}
9083 		RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
9084 
9085 		/*		RTW_INFO("%s: data={", __FUNCTION__); */
9086 		*extra = 0;
9087 		pextra = extra;
9088 		for (i = 0; i < cnts; i++) {
9089 			RTW_INFO("wlrfkrmap = 0x%02x\n", pEfuseHal->fakeBTEfuseModifiedMap[addr + i]);
9090 			pextra += sprintf(pextra, "0x%02X ", pEfuseHal->fakeBTEfuseModifiedMap[addr+i]);
9091 		}
9092 	} else if (strcmp(tmp[0], "mask") == 0) {
9093 		*extra = 0;
9094 		mask_len = sizeof(u8) * rtw_get_efuse_mask_arraylen(padapter);
9095 		rtw_efuse_mask_array(padapter, mask_buf);
9096 
9097 		if (padapter->registrypriv.bFileMaskEfuse == _TRUE)
9098 			_rtw_memcpy(mask_buf, maskfileBuffer, mask_len);
9099 
9100 		sprintf(extra, "\n");
9101 		pextra = extra + strlen(extra);
9102 		for (i = 0; i < mask_len; i++)
9103 			pextra += sprintf(pextra, "0x%02X\n", mask_buf[i]);
9104 
9105 	} else if (strcmp(tmp[0], "btmask") == 0) {
9106 		*extra = 0;
9107 		mask_len = sizeof(u8) * rtw_get_bt_efuse_mask_arraylen(padapter);
9108 		rtw_bt_efuse_mask_array(padapter, mask_buf);
9109 
9110 		if (padapter->registrypriv.bBTFileMaskEfuse == _TRUE)
9111 			_rtw_memcpy(mask_buf, btmaskfileBuffer, mask_len);
9112 
9113 		sprintf(extra, "\n");
9114 		pextra = extra + strlen(extra);
9115 		for (i = 0; i < mask_len; i++)
9116 			pextra += sprintf(pextra, "0x%02X\n", mask_buf[i]);
9117 
9118 	} else
9119 		sprintf(extra, "Command not found!");
9120 
9121 exit:
9122 	if (data)
9123 		rtw_mfree(data, EFUSE_BT_MAX_MAP_LEN);
9124 	if (rawdata)
9125 		rtw_mfree(rawdata, EFUSE_BT_MAX_MAP_LEN);
9126 	if (!err)
9127 		wrqu->length = strlen(extra);
9128 
9129 	if (padapter->registrypriv.mp_mode == 0) {
9130 #ifdef CONFIG_IPS
9131 		rtw_pm_set_ips(padapter, ips_mode);
9132 #endif /* CONFIG_IPS */
9133 
9134 #ifdef CONFIG_LPS
9135 		rtw_pm_set_lps(padapter, lps_mode);
9136 #endif /* CONFIG_LPS */
9137 	}
9138 
9139 #ifdef CONFIG_IOL
9140 	padapter->registrypriv.fw_iol = org_fw_iol;/* 0:Disable, 1:enable, 2:by usb speed */
9141 #endif
9142 	return err;
9143 }
9144 
9145 
9146 #ifdef CONFIG_MP_INCLUDED
9147 static int rtw_mp_efuse_set(struct net_device *dev,
9148 			    struct iw_request_info *info,
9149 			    union iwreq_data *wdata, char *extra)
9150 {
9151 	struct iw_point *wrqu;
9152 	PADAPTER padapter;
9153 	struct pwrctrl_priv *pwrctrlpriv ;
9154 	PHAL_DATA_TYPE pHalData;
9155 	PEFUSE_HAL pEfuseHal;
9156 	struct hal_ops *pHalFunc;
9157 	struct mp_priv *pmp_priv;
9158 
9159 	u8 ips_mode = IPS_NUM; /* init invalid value */
9160 	u8 lps_mode = PS_MODE_NUM; /* init invalid value */
9161 	u32 i = 0, j = 0, jj, kk;
9162 	u8 *setdata = NULL;
9163 	u8 *ShadowMapBT = NULL;
9164 	u8 *ShadowMapWiFi = NULL;
9165 	u8 *setrawdata = NULL;
9166 	char *pch, *ptmp, *token, *tmp[3] = {0x00, 0x00, 0x00};
9167 	u16 addr = 0xFF, cnts = 0, BTStatus = 0 , max_available_len = 0;
9168 	u16 wifimaplen;
9169 	int err;
9170 	boolean bcmpchk = _TRUE;
9171 
9172 
9173 	wrqu = (struct iw_point *)wdata;
9174 	padapter = rtw_netdev_priv(dev);
9175 	pwrctrlpriv = adapter_to_pwrctl(padapter);
9176 	pHalData = GET_HAL_DATA(padapter);
9177 	pEfuseHal = &pHalData->EfuseHal;
9178 	pHalFunc = &padapter->hal_func;
9179 	pmp_priv = &padapter->mppriv;
9180 
9181 	err = 0;
9182 
9183 	if (copy_from_user(extra, wrqu->pointer, wrqu->length))
9184 		return -EFAULT;
9185 #ifdef CONFIG_RTL8822C
9186 	rtw_pre_bt_efuse(padapter);
9187 #endif
9188 	*(extra + wrqu->length) = '\0';
9189 
9190 	EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN , (void *)&wifimaplen, _FALSE);
9191 
9192 	setdata = rtw_zmalloc(1024);
9193 	if (setdata == NULL) {
9194 		err = -ENOMEM;
9195 		goto exit;
9196 	}
9197 	ShadowMapBT = rtw_malloc(EFUSE_BT_MAX_MAP_LEN);
9198 	if (ShadowMapBT == NULL) {
9199 		err = -ENOMEM;
9200 		goto exit;
9201 	}
9202 	ShadowMapWiFi = rtw_malloc(wifimaplen);
9203 	if (ShadowMapWiFi == NULL) {
9204 		err = -ENOMEM;
9205 		goto exit;
9206 	}
9207 	setrawdata = rtw_malloc(EFUSE_MAX_SIZE);
9208 	if (setrawdata == NULL) {
9209 		err = -ENOMEM;
9210 		goto exit;
9211 	}
9212 
9213 #ifdef CONFIG_LPS
9214 	lps_mode = pwrctrlpriv->power_mgnt;/* keep org value */
9215 	rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);
9216 #endif
9217 
9218 #ifdef CONFIG_IPS
9219 	ips_mode = pwrctrlpriv->ips_mode;/* keep org value */
9220 	rtw_pm_set_ips(padapter, IPS_NONE);
9221 #endif
9222 
9223 	pch = extra;
9224 	RTW_INFO("%s: in=%s\n", __FUNCTION__, extra);
9225 
9226 	i = 0;
9227 	while ((token = strsep(&pch, ",")) != NULL) {
9228 		if (i > 2)
9229 			break;
9230 		tmp[i] = token;
9231 		i++;
9232 	}
9233 
9234 	/* tmp[0],[1],[2] */
9235 	/* wmap,addr,00e04c871200 */
9236 	if (strcmp(tmp[0], "wmap") == 0) {
9237 		if ((tmp[1] == NULL) || (tmp[2] == NULL)) {
9238 			err = -EINVAL;
9239 			goto exit;
9240 		}
9241 
9242 #ifndef RTW_HALMAC
9243 		/* unknown bug workaround, need to fix later */
9244 		addr = 0x1ff;
9245 		rtw_write8(padapter, EFUSE_CTRL + 1, (addr & 0xff));
9246 		rtw_msleep_os(10);
9247 		rtw_write8(padapter, EFUSE_CTRL + 2, ((addr >> 8) & 0x03));
9248 		rtw_msleep_os(10);
9249 		rtw_write8(padapter, EFUSE_CTRL + 3, 0x72);
9250 		rtw_msleep_os(10);
9251 		rtw_read8(padapter, EFUSE_CTRL);
9252 #endif /* RTW_HALMAC */
9253 
9254 		addr = simple_strtoul(tmp[1], &ptmp, 16);
9255 		addr &= 0xFFF;
9256 
9257 		cnts = strlen(tmp[2]);
9258 		if (cnts % 2) {
9259 			err = -EINVAL;
9260 			goto exit;
9261 		}
9262 		cnts /= 2;
9263 		if (cnts == 0) {
9264 			err = -EINVAL;
9265 			goto exit;
9266 		}
9267 
9268 		RTW_INFO("%s: addr=0x%X\n", __FUNCTION__, addr);
9269 		RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
9270 		RTW_INFO("%s: map data=%s\n", __FUNCTION__, tmp[2]);
9271 
9272 		for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
9273 			setdata[jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
9274 
9275 		EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&max_available_len, _FALSE);
9276 
9277 		if ((addr + cnts) > max_available_len) {
9278 			RTW_INFO("%s: addr(0x%X)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
9279 			err = -EFAULT;
9280 			goto exit;
9281 		}
9282 
9283 		if (rtw_efuse_map_write(padapter, addr, cnts, setdata) == _FAIL) {
9284 			RTW_INFO("%s: rtw_efuse_map_write error!!\n", __FUNCTION__);
9285 			err = -EFAULT;
9286 			goto exit;
9287 		}
9288 		*extra = 0;
9289 		RTW_INFO("%s: after rtw_efuse_map_write to _rtw_memcmp\n", __func__);
9290 		if (rtw_efuse_mask_map_read(padapter, addr, cnts, ShadowMapWiFi) == _SUCCESS) {
9291 			if (_rtw_memcmp((void *)ShadowMapWiFi , (void *)setdata, cnts)) {
9292 				RTW_INFO("%s: WiFi write map afterf compare success\n", __FUNCTION__);
9293 				sprintf(extra, "WiFi write map compare OK\n");
9294 				err = 0;
9295 				goto exit;
9296 			} else {
9297 				sprintf(extra, "WiFi write map compare FAIL\n");
9298 				RTW_INFO("%s: WiFi write map compare Fail\n", __FUNCTION__);
9299 				err = 0;
9300 				goto exit;
9301 			}
9302 		}
9303 	} else if (strcmp(tmp[0], "wraw") == 0) {
9304 		if ((tmp[1] == NULL) || (tmp[2] == NULL)) {
9305 			err = -EINVAL;
9306 			goto exit;
9307 		}
9308 
9309 		addr = simple_strtoul(tmp[1], &ptmp, 16);
9310 		addr &= 0xFFF;
9311 
9312 		cnts = strlen(tmp[2]);
9313 		if (cnts % 2) {
9314 			err = -EINVAL;
9315 			goto exit;
9316 		}
9317 		cnts /= 2;
9318 		if (cnts == 0) {
9319 			err = -EINVAL;
9320 			goto exit;
9321 		}
9322 
9323 		RTW_INFO("%s: addr=0x%X\n", __FUNCTION__, addr);
9324 		RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
9325 		RTW_INFO("%s: raw data=%s\n", __FUNCTION__, tmp[2]);
9326 
9327 		for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
9328 			setrawdata[jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
9329 
9330 		if (rtw_efuse_access(padapter, _TRUE, addr, cnts, setrawdata) == _FAIL) {
9331 			RTW_INFO("%s: rtw_efuse_access error!!\n", __FUNCTION__);
9332 			err = -EFAULT;
9333 			goto exit;
9334 		}
9335 	} else if (strcmp(tmp[0], "btwraw") == 0) {
9336 		if ((tmp[1] == NULL) || (tmp[2] == NULL)) {
9337 			err = -EINVAL;
9338 			goto exit;
9339 		}
9340 
9341 		addr = simple_strtoul(tmp[1], &ptmp, 16);
9342 		addr &= 0xFFF;
9343 
9344 		cnts = strlen(tmp[2]);
9345 		if (cnts % 2) {
9346 			err = -EINVAL;
9347 			goto exit;
9348 		}
9349 		cnts /= 2;
9350 		if (cnts == 0) {
9351 			err = -EINVAL;
9352 			goto exit;
9353 		}
9354 
9355 		RTW_INFO("%s: addr=0x%X\n", __FUNCTION__, addr);
9356 		RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
9357 		RTW_INFO("%s: raw data=%s\n", __FUNCTION__, tmp[2]);
9358 
9359 		for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
9360 			setrawdata[jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
9361 #ifdef RTW_HALMAC
9362 		if (rtw_efuse_bt_access(padapter, _TRUE, addr, cnts, setrawdata) == _FAIL) {
9363 			RTW_INFO("%s: rtw_efuse_access error!!\n", __FUNCTION__);
9364 			err = -EFAULT;
9365 			goto exit;
9366 		}
9367 #else
9368 		rtw_write8(padapter, 0x35, 1); /* switch bank 1 (BT)*/
9369 		if (rtw_efuse_access(padapter, _TRUE, addr, cnts, setrawdata) == _FAIL) {
9370 			RTW_INFO("%s: rtw_efuse_access error!!\n", __FUNCTION__);
9371 			rtw_write8(padapter, 0x35, 0); /* switch bank 0 (WiFi)*/
9372 			err = -EFAULT;
9373 			goto exit;
9374 		}
9375 		rtw_write8(padapter, 0x35, 0); /* switch bank 0 (WiFi)*/
9376 #endif
9377 	} else if (strcmp(tmp[0], "mac") == 0) {
9378 		if (tmp[1] == NULL) {
9379 			err = -EINVAL;
9380 			goto exit;
9381 		}
9382 
9383 		/* mac,00e04c871200 */
9384 
9385 		if (hal_efuse_macaddr_offset(padapter) == -1) {
9386 			err = -EFAULT;
9387 			goto exit;
9388 		}
9389 
9390 		addr = hal_efuse_macaddr_offset(padapter);
9391 		cnts = strlen(tmp[1]);
9392 		if (cnts % 2) {
9393 			err = -EINVAL;
9394 			goto exit;
9395 		}
9396 		cnts /= 2;
9397 		if (cnts == 0) {
9398 			err = -EINVAL;
9399 			goto exit;
9400 		}
9401 		if (cnts > 6) {
9402 			RTW_INFO("%s: error data for mac addr=\"%s\"\n", __FUNCTION__, tmp[1]);
9403 			err = -EFAULT;
9404 			goto exit;
9405 		}
9406 
9407 		RTW_INFO("%s: addr=0x%X\n", __FUNCTION__, addr);
9408 		RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
9409 		RTW_INFO("%s: MAC address=%s\n", __FUNCTION__, tmp[1]);
9410 
9411 		for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
9412 			setdata[jj] = key_2char2num(tmp[1][kk], tmp[1][kk + 1]);
9413 
9414 		EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&max_available_len, _FALSE);
9415 
9416 		if ((addr + cnts) > max_available_len) {
9417 			RTW_INFO("%s: addr(0x%X)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
9418 			err = -EFAULT;
9419 			goto exit;
9420 		}
9421 
9422 		if (rtw_efuse_map_write(padapter, addr, cnts, setdata) == _FAIL) {
9423 			RTW_INFO("%s: rtw_efuse_map_write error!!\n", __FUNCTION__);
9424 			err = -EFAULT;
9425 			goto exit;
9426 		}
9427 	} else if (strcmp(tmp[0], "vidpid") == 0) {
9428 		if (tmp[1] == NULL) {
9429 			err = -EINVAL;
9430 			goto exit;
9431 		}
9432 
9433 		/* pidvid,da0b7881		 */
9434 #ifdef CONFIG_RTL8188E
9435 #ifdef CONFIG_USB_HCI
9436 		addr = EEPROM_VID_88EU;
9437 #endif
9438 #ifdef CONFIG_PCI_HCI
9439 		addr = EEPROM_VID_88EE;
9440 #endif
9441 #endif /* CONFIG_RTL8188E */
9442 
9443 #ifdef CONFIG_RTL8192E
9444 #ifdef CONFIG_USB_HCI
9445 		addr = EEPROM_VID_8192EU;
9446 #endif
9447 #ifdef CONFIG_PCI_HCI
9448 		addr = EEPROM_VID_8192EE;
9449 #endif
9450 #endif /* CONFIG_RTL8188E */
9451 
9452 #ifdef CONFIG_RTL8723B
9453 		addr = EEPROM_VID_8723BU;
9454 #endif
9455 
9456 #ifdef CONFIG_RTL8188F
9457 		addr = EEPROM_VID_8188FU;
9458 #endif
9459 
9460 #ifdef CONFIG_RTL8188GTV
9461 		addr = EEPROM_VID_8188GTVU;
9462 #endif
9463 
9464 #ifdef CONFIG_RTL8703B
9465 #ifdef CONFIG_USB_HCI
9466 		addr = EEPROM_VID_8703BU;
9467 #endif /* CONFIG_USB_HCI */
9468 #endif /* CONFIG_RTL8703B */
9469 
9470 #ifdef CONFIG_RTL8723D
9471 #ifdef CONFIG_USB_HCI
9472 		addr = EEPROM_VID_8723DU;
9473 #endif /* CONFIG_USB_HCI */
9474 #endif /* CONFIG_RTL8723D */
9475 
9476 		cnts = strlen(tmp[1]);
9477 		if (cnts % 2) {
9478 			err = -EINVAL;
9479 			goto exit;
9480 		}
9481 		cnts /= 2;
9482 		if (cnts == 0) {
9483 			err = -EINVAL;
9484 			goto exit;
9485 		}
9486 
9487 		RTW_INFO("%s: addr=0x%X\n", __FUNCTION__, addr);
9488 		RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
9489 		RTW_INFO("%s: VID/PID=%s\n", __FUNCTION__, tmp[1]);
9490 
9491 		for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
9492 			setdata[jj] = key_2char2num(tmp[1][kk], tmp[1][kk + 1]);
9493 
9494 		EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&max_available_len, _FALSE);
9495 		if ((addr + cnts) > max_available_len) {
9496 			RTW_INFO("%s: addr(0x%X)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
9497 			err = -EFAULT;
9498 			goto exit;
9499 		}
9500 
9501 		if (rtw_efuse_map_write(padapter, addr, cnts, setdata) == _FAIL) {
9502 			RTW_INFO("%s: rtw_efuse_map_write error!!\n", __FUNCTION__);
9503 			err = -EFAULT;
9504 			goto exit;
9505 		}
9506 	} else if (strcmp(tmp[0], "wldumpfake") == 0) {
9507 		if (wifimaplen > EFUSE_MAX_MAP_LEN)
9508 			cnts = EFUSE_MAX_MAP_LEN;
9509 		else
9510 			cnts = wifimaplen;
9511 		if (rtw_efuse_mask_map_read(padapter, 0, cnts, pEfuseHal->fakeEfuseModifiedMap) == _SUCCESS)
9512 			RTW_INFO("%s: WiFi hw efuse dump to Fake map success\n", __func__);
9513 		else {
9514 			RTW_INFO("%s: WiFi hw efuse dump to Fake map Fail\n", __func__);
9515 			err = -EFAULT;
9516 		}
9517 	} else if (strcmp(tmp[0], "btwmap") == 0) {
9518 		rtw_write8(padapter, 0xa3, 0x05); /* For 8723AB ,8821S ? */
9519 		BTStatus = rtw_read8(padapter, 0xa0);
9520 		RTW_INFO("%s: btwmap before read 0xa0 BT Status =0x%x\n", __FUNCTION__, BTStatus);
9521 		if (BTStatus != 0x04) {
9522 			sprintf(extra, "BT Status not Active ,can't do Write\n");
9523 			goto exit;
9524 		}
9525 
9526 		if ((tmp[1] == NULL) || (tmp[2] == NULL)) {
9527 			err = -EINVAL;
9528 			goto exit;
9529 		}
9530 
9531 #ifndef RTW_HALMAC
9532 		BTEfuse_PowerSwitch(padapter, 1, _TRUE);
9533 		addr = 0x1ff;
9534 		rtw_write8(padapter, EFUSE_CTRL + 1, (addr & 0xff));
9535 		rtw_msleep_os(10);
9536 		rtw_write8(padapter, EFUSE_CTRL + 2, ((addr >> 8) & 0x03));
9537 		rtw_msleep_os(10);
9538 		rtw_write8(padapter, EFUSE_CTRL + 3, 0x72);
9539 		rtw_msleep_os(10);
9540 		rtw_read8(padapter, EFUSE_CTRL);
9541 		BTEfuse_PowerSwitch(padapter, 1, _FALSE);
9542 #endif /* RTW_HALMAC */
9543 
9544 		addr = simple_strtoul(tmp[1], &ptmp, 16);
9545 		addr &= 0xFFF;
9546 
9547 		cnts = strlen(tmp[2]);
9548 		if (cnts % 2) {
9549 			err = -EINVAL;
9550 			goto exit;
9551 		}
9552 		cnts /= 2;
9553 		if (cnts == 0) {
9554 			err = -EINVAL;
9555 			goto exit;
9556 		}
9557 
9558 		RTW_INFO("%s: addr=0x%X\n", __FUNCTION__, addr);
9559 		RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
9560 		RTW_INFO("%s: BT data=%s\n", __FUNCTION__, tmp[2]);
9561 
9562 		for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
9563 			setdata[jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
9564 #ifndef RTW_HALMAC
9565 		EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_EFUSE_MAP_LEN, (void *)&max_available_len, _FALSE);
9566 		if ((addr + cnts) > max_available_len) {
9567 			RTW_INFO("%s: addr(0x%X)+cnts(%d) parameter error!\n", __FUNCTION__, addr, cnts);
9568 			err = -EFAULT;
9569 			goto exit;
9570 		}
9571 #endif
9572 		if (rtw_BT_efuse_map_write(padapter, addr, cnts, setdata) == _FAIL) {
9573 			RTW_INFO("%s: rtw_BT_efuse_map_write error!!\n", __FUNCTION__);
9574 			sprintf(extra, "BT write FAIL !!!\n");
9575 			err = -EFAULT;
9576 			goto exit;
9577 		}
9578 		*extra = 0;
9579 		RTW_INFO("%s: after rtw_BT_efuse_map_write to _rtw_memcmp\n", __FUNCTION__);
9580 		if ((rtw_BT_efuse_map_read(padapter, addr, cnts, ShadowMapBT) == _SUCCESS)) {
9581 			if (_rtw_memcmp((void *)ShadowMapBT , (void *)setdata, cnts)) {
9582 				RTW_INFO("%s: BT write map compare OK BTStatus=0x%x\n", __FUNCTION__, BTStatus);
9583 				sprintf(extra, "BT write map compare OK");
9584 				err = 0;
9585 				goto exit;
9586 			} else {
9587 				sprintf(extra, "BT write map compare FAIL");
9588 				RTW_INFO("%s: BT write map compare FAIL BTStatus=0x%x\n", __FUNCTION__, BTStatus);
9589 				err = 0;
9590 				goto exit;
9591 			}
9592 		}
9593 	} else if (strcmp(tmp[0], "btwfake") == 0) {
9594 		if ((tmp[1] == NULL) || (tmp[2] == NULL)) {
9595 			err = -EINVAL;
9596 			goto exit;
9597 		}
9598 		if (pmp_priv->bprocess_mp_mode != _TRUE) {
9599 			RTW_INFO("%s: btwfake not to be exec, please first to mp_start\n", __FUNCTION__);
9600 			sprintf(extra, "Error, btwfake cant to be exec, please first to mp_start !!!!\n");
9601 			err = 0;
9602 			goto exit;
9603 		}
9604 		addr = simple_strtoul(tmp[1], &ptmp, 16);
9605 		addr &= 0xFFF;
9606 
9607 		cnts = strlen(tmp[2]);
9608 		if (cnts % 2) {
9609 			err = -EINVAL;
9610 			goto exit;
9611 		}
9612 		cnts /= 2;
9613 		if (cnts == 0) {
9614 			err = -EINVAL;
9615 			goto exit;
9616 		}
9617 
9618 		RTW_INFO("%s: addr=0x%X\n", __FUNCTION__, addr);
9619 		RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
9620 		RTW_INFO("%s: BT tmp data=%s\n", __FUNCTION__, tmp[2]);
9621 
9622 		for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
9623 			pEfuseHal->fakeBTEfuseModifiedMap[addr + jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
9624 	} else if (strcmp(tmp[0], "btdumpfake") == 0) {
9625 		if (rtw_BT_efuse_map_read(padapter, 0, EFUSE_BT_MAX_MAP_LEN, pEfuseHal->fakeBTEfuseModifiedMap) == _SUCCESS)
9626 			RTW_INFO("%s: BT read all map success\n", __FUNCTION__);
9627 		else {
9628 			RTW_INFO("%s: BT read all map Fail!\n", __FUNCTION__);
9629 			err = -EFAULT;
9630 		}
9631 	} else if (strcmp(tmp[0], "btfk2map") == 0) {
9632 #ifdef CONFIG_BT_EFUSE_MASK
9633 		if (padapter->registrypriv.bBTFileMaskEfuse != _TRUE && pmp_priv->bloadBTefusemap == _TRUE) {
9634 			RTW_INFO("%s: File BT eFuse mask file not to be loaded\n", __FUNCTION__);
9635 			sprintf(extra, "Not load BT eFuse mask file yet, Please advance to use [ efuse_bt_mask ], now remove the Adapter.!!!!\n");
9636 			rtw_set_surprise_removed(padapter);
9637 			err = 0;
9638 			goto exit;
9639 		}
9640 #endif
9641 		rtw_write8(padapter, 0xa3, 0x05);
9642 		BTStatus = rtw_read8(padapter, 0xa0);
9643 		RTW_INFO("%s: btwmap before read 0xa0 BT Status =0x%x\n", __FUNCTION__, BTStatus);
9644 		if (BTStatus != 0x04) {
9645 			sprintf(extra, "BT Status not Active Write FAIL\n");
9646 			goto exit;
9647 		}
9648 		if (pmp_priv->bprocess_mp_mode != _TRUE) {
9649 			RTW_INFO("%s: btfk2map not to be exec, please first to mp_start\n", __FUNCTION__);
9650 			sprintf(extra, "Error, btfk2map cant to be exec, please first to mp_start !!!!\n");
9651 			err = 0;
9652 			goto exit;
9653 		}
9654 #ifndef RTW_HALMAC
9655 		BTEfuse_PowerSwitch(padapter, 1, _TRUE);
9656 		addr = 0x1ff;
9657 		rtw_write8(padapter, EFUSE_CTRL + 1, (addr & 0xff));
9658 		rtw_msleep_os(10);
9659 		rtw_write8(padapter, EFUSE_CTRL + 2, ((addr >> 8) & 0x03));
9660 		rtw_msleep_os(10);
9661 		rtw_write8(padapter, EFUSE_CTRL + 3, 0x72);
9662 		rtw_msleep_os(10);
9663 		rtw_read8(padapter, EFUSE_CTRL);
9664 		BTEfuse_PowerSwitch(padapter, 1, _FALSE);
9665 #endif /* RTW_HALMAC */
9666 
9667 		if (rtw_BT_efuse_map_write(padapter, 0x00, EFUSE_BT_MAX_MAP_LEN, pEfuseHal->fakeBTEfuseModifiedMap) == _FAIL) {
9668 			RTW_INFO("%s: rtw_BT_efuse_map_write error!\n", __FUNCTION__);
9669 			sprintf(extra, "BT write FAIL !!!\n");
9670 			err = -EFAULT;
9671 			goto exit;
9672 		}
9673 
9674 		RTW_INFO("pEfuseHal->fakeBTEfuseModifiedMap OFFSET\tVALUE(hex)\n");
9675 		for (i = 0; i < EFUSE_BT_MAX_MAP_LEN; i += 16) {
9676 			printk("0x%02x\t", i);
9677 			for (j = 0; j < 8; j++)
9678 				printk("%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i + j]);
9679 			printk("\t");
9680 
9681 			for (; j < 16; j++)
9682 				printk("%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i + j]);
9683 			printk("\n");
9684 		}
9685 		printk("\n");
9686 #if 1
9687 		err = -EFAULT;
9688 		RTW_INFO("%s: rtw_BT_efuse_map_read _rtw_memcmp\n", __FUNCTION__);
9689 		if ((rtw_BT_efuse_map_read(padapter, 0x00, EFUSE_BT_MAX_MAP_LEN, pEfuseHal->fakeBTEfuseInitMap) == _SUCCESS)) {
9690 			if (_rtw_memcmp((void *)pEfuseHal->fakeBTEfuseModifiedMap, (void *)pEfuseHal->fakeBTEfuseInitMap, EFUSE_BT_MAX_MAP_LEN)) {
9691 				sprintf(extra, "BT write map compare OK");
9692 				RTW_INFO("%s: BT write map afterf compare success BTStatus=0x%x\n", __FUNCTION__, BTStatus);
9693 				err = 0;
9694 				goto exit;
9695 			} else {
9696 				sprintf(extra, "BT write map compare FAIL");
9697 				if (rtw_BT_efuse_map_write(padapter, 0x00, EFUSE_BT_MAX_MAP_LEN, pEfuseHal->fakeBTEfuseModifiedMap) == _FAIL)
9698 					RTW_INFO("%s: rtw_BT_efuse_map_write compare error,retry = %d!\n", __FUNCTION__, i);
9699 
9700 				if (rtw_BT_efuse_map_read(padapter, EFUSE_BT, EFUSE_BT_MAX_MAP_LEN, pEfuseHal->fakeBTEfuseInitMap) == _SUCCESS) {
9701 					RTW_INFO("pEfuseHal->fakeBTEfuseInitMap OFFSET\tVALUE(hex)\n");
9702 
9703 					for (i = 0; i < EFUSE_BT_MAX_MAP_LEN; i += 16) {
9704 						printk("0x%02x\t", i);
9705 						for (j = 0; j < 8; j++)
9706 							printk("%02X ", pEfuseHal->fakeBTEfuseInitMap[i + j]);
9707 						printk("\t");
9708 						for (; j < 16; j++)
9709 							printk("%02X ", pEfuseHal->fakeBTEfuseInitMap[i + j]);
9710 						printk("\n");
9711 					}
9712 					printk("\n");
9713 				}
9714 				RTW_INFO("%s: BT write map afterf compare not match to write efuse try write Map again , BTStatus=0x%x\n", __FUNCTION__, BTStatus);
9715 				goto exit;
9716 			}
9717 		}
9718 #endif
9719 
9720 	} else if (strcmp(tmp[0], "wlfk2map") == 0) {
9721 		*extra = 0;
9722 
9723 		if (padapter->registrypriv.bFileMaskEfuse != _TRUE && pmp_priv->bloadefusemap == _TRUE) {
9724 			RTW_INFO("%s: File eFuse mask file not to be loaded\n", __FUNCTION__);
9725 			sprintf(extra, "Not load eFuse mask file yet, Please use the efuse_mask CMD, now remove the interface !!!!\n");
9726 			rtw_set_surprise_removed(padapter);
9727 			err = 0;
9728 			goto exit;
9729 		}
9730 
9731 		if (pmp_priv->bprocess_mp_mode != _TRUE) {
9732 			RTW_INFO("%s: wlfk2map not to be exec, please first to mp_start\n", __FUNCTION__);
9733 			sprintf(extra, "Error, wlfk2map cant to be exec, please first to mp_start !!!!\n");
9734 			err = 0;
9735 			goto exit;
9736 		}
9737 		if (wifimaplen > EFUSE_MAX_MAP_LEN)
9738 			cnts = EFUSE_MAX_MAP_LEN;
9739 		else
9740 			cnts = wifimaplen;
9741 		if (rtw_efuse_map_write(padapter, 0x00, cnts, pEfuseHal->fakeEfuseModifiedMap) == _FAIL) {
9742 			RTW_INFO("%s: rtw_efuse_map_write fakeEfuseModifiedMap error!\n", __FUNCTION__);
9743 			err = -EFAULT;
9744 			goto exit;
9745 		}
9746 
9747 		if (rtw_efuse_mask_map_read(padapter, 0x00, wifimaplen, ShadowMapWiFi) == _SUCCESS) {
9748 			addr = 0x00;
9749 			err = _TRUE;
9750 
9751 			for (i = 0; i < cnts; i++) {
9752 				if (padapter->registrypriv.boffefusemask == 0) {
9753 					if (padapter->registrypriv.bFileMaskEfuse == _TRUE) {
9754 						if (rtw_file_efuse_IsMasked(padapter, addr + i, maskfileBuffer) == _TRUE)	/*use file efuse mask. */
9755 							bcmpchk = _FALSE;
9756 					} else {
9757 						if (efuse_IsMasked(padapter, addr + i) == _TRUE)
9758 							bcmpchk = _FALSE;
9759 					}
9760 				}
9761 
9762 				if (bcmpchk == _TRUE) {
9763 					RTW_INFO("compare readMapWiFi[0x%02x] = %x, ModifiedMap = %x\n", addr + i, ShadowMapWiFi[ addr + i], pEfuseHal->fakeEfuseModifiedMap[addr + i]);
9764 					if (_rtw_memcmp((void *) &ShadowMapWiFi[addr + i], (void *)&pEfuseHal->fakeEfuseModifiedMap[addr + i], 1) == _FALSE){
9765 						err = _FALSE;
9766 						break;
9767 					}
9768 				}
9769 				bcmpchk = _TRUE;
9770 			}
9771 		}
9772 
9773 		if (err) {
9774 			RTW_INFO("%s: WiFi write map afterf compare OK\n", __FUNCTION__);
9775 			sprintf(extra, "WiFi write map compare OK\n");
9776 			err = 0;
9777 			goto exit;
9778 		} else {
9779 			sprintf(extra, "WiFi write map compare FAIL\n");
9780 			RTW_INFO("%s: WiFi write map compare Fail\n", __FUNCTION__);
9781 			err = 0;
9782 			goto exit;
9783 		}
9784 	} else if (strcmp(tmp[0], "wlwfake") == 0) {
9785 		if ((tmp[1] == NULL) || (tmp[2] == NULL)) {
9786 			err = -EINVAL;
9787 			goto exit;
9788 		}
9789 		if (pmp_priv->bprocess_mp_mode != _TRUE) {
9790 			RTW_INFO("%s: wlwfake not to be exec, please first to mp_start\n", __FUNCTION__);
9791 			sprintf(extra, "Error, wlwfake cant to be exec, please first to mp_start !!!!\n");
9792 			err = 0;
9793 			goto exit;
9794 		}
9795 		addr = simple_strtoul(tmp[1], &ptmp, 16);
9796 		addr &= 0xFFF;
9797 
9798 		cnts = strlen(tmp[2]);
9799 		if (cnts % 2) {
9800 			err = -EINVAL;
9801 			goto exit;
9802 		}
9803 		cnts /= 2;
9804 		if (cnts == 0) {
9805 			err = -EINVAL;
9806 			goto exit;
9807 		}
9808 
9809 		RTW_INFO("%s: addr=0x%X\n", __FUNCTION__, addr);
9810 		RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
9811 		RTW_INFO("%s: map tmp data=%s\n", __FUNCTION__, tmp[2]);
9812 
9813 		for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
9814 			pEfuseHal->fakeEfuseModifiedMap[addr + jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
9815 		_rtw_memset(extra, '\0', strlen(extra));
9816 		sprintf(extra, "wlwfake OK\n");
9817 
9818 	}
9819 	else if (strcmp(tmp[0], "wfakemac") == 0) {
9820 		if (tmp[1] == NULL) {
9821 			err = -EINVAL;
9822 			goto exit;
9823 		}
9824 		if (pmp_priv->bprocess_mp_mode != _TRUE) {
9825 			RTW_INFO("%s: wfakemac not to be exec, please first to mp_start\n", __FUNCTION__);
9826 			sprintf(extra, "Error, wfakemac cant to be exec, please first to mp_start !!!!\n");
9827 			err = 0;
9828 			goto exit;
9829 		}
9830 		/* wfakemac,00e04c871200 */
9831 		if (hal_efuse_macaddr_offset(padapter) == -1) {
9832 			err = -EFAULT;
9833 			goto exit;
9834 		}
9835 
9836 		addr = hal_efuse_macaddr_offset(padapter);
9837 		cnts = strlen(tmp[1]);
9838 		if (cnts % 2) {
9839 			err = -EINVAL;
9840 			goto exit;
9841 		}
9842 		cnts /= 2;
9843 		if (cnts == 0) {
9844 			err = -EINVAL;
9845 			goto exit;
9846 		}
9847 		if (cnts > 6) {
9848 			RTW_INFO("%s: error data for mac addr=\"%s\"\n", __FUNCTION__, tmp[1]);
9849 			err = -EFAULT;
9850 			goto exit;
9851 		}
9852 
9853 		RTW_INFO("%s: addr=0x%X\n", __FUNCTION__, addr);
9854 		RTW_INFO("%s: cnts=%d\n", __FUNCTION__, cnts);
9855 		RTW_INFO("%s: MAC address=%s\n", __FUNCTION__, tmp[1]);
9856 
9857 		for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
9858 			if ((addr + jj) < EFUSE_MAX_MAP_LEN)
9859 				pEfuseHal->fakeEfuseModifiedMap[addr + jj] = key_2char2num(tmp[1][kk], tmp[1][kk + 1]);
9860 
9861 		_rtw_memset(extra, '\0', strlen(extra));
9862 		sprintf(extra, "write mac addr to fake map OK\n");
9863 	} else if(strcmp(tmp[0], "update") == 0) {
9864 		RTW_INFO("To Use new eFuse map ver3\n");
9865 
9866 		if (tmp[1] != 0x00) {
9867 			if (strcmp(tmp[1], "fake") == 0) {
9868 				pmp_priv->efuse_update_on = _TRUE;
9869 				RTW_INFO("Set efuse update without file\n");
9870 			} else if (strcmp(tmp[1], "phy") == 0) {
9871 				pmp_priv->efuse_update_file = _FALSE;
9872 				pmp_priv->efuse_update_on = _FALSE;
9873 				RTW_INFO("Set efuse update with phy\n");
9874 			} else {
9875 				pmp_priv->efuse_update_file = _TRUE;
9876 				strcpy(pmp_priv->efuse_file_path , tmp[1]);
9877 				RTW_INFO("Got file path %s\n", pmp_priv->efuse_file_path);
9878 			}
9879 		}
9880 		/*step read efuse/eeprom data and get mac_addr*/
9881 		if (padapter->hal_func.read_adapter_info(padapter)) {
9882 			_rtw_memset(extra, '\0', strlen(extra));
9883 			#ifdef CONFIG_TXPWR_PG_WITH_PWR_IDX
9884 			if (pHalData->txpwr_pg_mode == TXPWR_PG_WITH_PWR_IDX)
9885 				hal_load_txpwr_info(padapter);
9886 			#endif
9887 			phy_load_tx_power_ext_info(padapter, 1);
9888 			sprintf(extra, "eFuse Update OK\n");
9889 			RTW_INFO("eFuse Update OK\n");
9890 		} else {
9891 			_rtw_memset(extra, '\0', strlen(extra));
9892 			sprintf(extra, "eFuse Update FAIL\n");
9893 			RTW_INFO("eFuse Update FAIL\n");
9894 		}
9895 
9896 		RTW_INFO("To Use new eFuse map ver3 done\n");
9897 	} else if (strcmp(tmp[0], "analyze") == 0) {
9898 
9899 		rtw_efuse_analyze(padapter, EFUSE_WIFI, 0);
9900 		_rtw_memset(extra, '\0', strlen(extra));
9901 		sprintf(extra, "eFuse Analyze OK,please to check kernel log\n");
9902 	}
9903 exit:
9904 	if (setdata)
9905 		rtw_mfree(setdata, 1024);
9906 	if (ShadowMapBT)
9907 		rtw_mfree(ShadowMapBT, EFUSE_BT_MAX_MAP_LEN);
9908 	if (ShadowMapWiFi)
9909 		rtw_mfree(ShadowMapWiFi, wifimaplen);
9910 	if (setrawdata)
9911 		rtw_mfree(setrawdata, EFUSE_MAX_SIZE);
9912 
9913 	wrqu->length = strlen(extra);
9914 
9915 	if (padapter->registrypriv.mp_mode == 0) {
9916 #ifdef CONFIG_IPS
9917 		rtw_pm_set_ips(padapter, ips_mode);
9918 #endif /* CONFIG_IPS */
9919 
9920 #ifdef CONFIG_LPS
9921 		rtw_pm_set_lps(padapter, lps_mode);
9922 #endif /* CONFIG_LPS */
9923 	}
9924 
9925 	return err;
9926 }
9927 
9928 #ifdef CONFIG_RTW_CUSTOMER_STR
9929 static int rtw_mp_customer_str(
9930 	struct net_device *dev,
9931 	struct iw_request_info *info,
9932 	union iwreq_data *wrqu, char *extra)
9933 {
9934 	_adapter *adapter = rtw_netdev_priv(dev);
9935 	u32 len;
9936 	u8 *pbuf = NULL, *pch;
9937 	char *ptmp;
9938 	u8 param[RTW_CUSTOMER_STR_LEN];
9939 	u8 count = 0;
9940 	u8 tmp;
9941 	u8 i;
9942 	u32 pos;
9943 	u8 ret;
9944 	u8 read = 0;
9945 
9946 	if (adapter->registrypriv.mp_mode != 1
9947 		|| !adapter->registrypriv.mp_customer_str)
9948 		return -EFAULT;
9949 
9950 	len = wrqu->data.length + 1;
9951 
9952 	pbuf = (u8 *)rtw_zmalloc(len);
9953 	if (pbuf == NULL) {
9954 		RTW_WARN("%s: no memory!\n", __func__);
9955 		return -ENOMEM;
9956 	}
9957 
9958 	if (copy_from_user(pbuf, wrqu->data.pointer, wrqu->data.length)) {
9959 		rtw_mfree(pbuf, len);
9960 		RTW_WARN("%s: copy from user fail!\n", __func__);
9961 		return -EFAULT;
9962 	}
9963 	RTW_INFO("%s: string=\"%s\"\n", __func__, pbuf);
9964 
9965 	ptmp = (char *)pbuf;
9966 	pch = strsep(&ptmp, ",");
9967 	if ((pch == NULL) || (strlen(pch) == 0)) {
9968 		rtw_mfree(pbuf, len);
9969 		RTW_INFO("%s: parameter error(no cmd)!\n", __func__);
9970 		return -EFAULT;
9971 	}
9972 
9973 	_rtw_memset(param, 0xFF, RTW_CUSTOMER_STR_LEN);
9974 
9975 	if (strcmp(pch, "read") == 0) {
9976 		read = 1;
9977 		ret = rtw_hal_customer_str_read(adapter, param);
9978 
9979 	} else if (strcmp(pch, "write") == 0) {
9980 		do {
9981 			pch = strsep(&ptmp, ":");
9982 			if ((pch == NULL) || (strlen(pch) == 0))
9983 				break;
9984 			if (strlen(pch) != 2
9985 				|| IsHexDigit(*pch) == _FALSE
9986 				|| IsHexDigit(*(pch + 1)) == _FALSE
9987 				|| sscanf(pch, "%hhx", &tmp) != 1
9988 			) {
9989 				RTW_WARN("%s: invalid 8-bit hex!\n", __func__);
9990 				rtw_mfree(pbuf, len);
9991 				return -EFAULT;
9992 			}
9993 
9994 			param[count++] = tmp;
9995 
9996 		} while (count < RTW_CUSTOMER_STR_LEN);
9997 
9998 		if (count == 0) {
9999 			rtw_mfree(pbuf, len);
10000 			RTW_WARN("%s: no input!\n", __func__);
10001 			return -EFAULT;
10002 		}
10003 		ret = rtw_hal_customer_str_write(adapter, param);
10004 	} else {
10005 		rtw_mfree(pbuf, len);
10006 		RTW_INFO("%s: parameter error(unknown cmd)!\n", __func__);
10007 		return -EFAULT;
10008 	}
10009 
10010 	pos = sprintf(extra, "%s: ", read ? "read" : "write");
10011 	if (read == 0 || ret == _SUCCESS) {
10012 		for (i = 0; i < RTW_CUSTOMER_STR_LEN; i++)
10013 			pos += sprintf(extra + pos, "%02x:", param[i]);
10014 		extra[pos] = 0;
10015 		pos--;
10016 	}
10017 	pos += sprintf(extra + pos, " %s", ret == _SUCCESS ? "OK" : "FAIL");
10018 
10019 	wrqu->data.length = strlen(extra) + 1;
10020 
10021 	rtw_mfree(pbuf, len);
10022 	return 0;
10023 }
10024 #endif /* CONFIG_RTW_CUSTOMER_STR */
10025 
10026 static int rtw_priv_mp_set(struct net_device *dev,
10027 			   struct iw_request_info *info,
10028 			   union iwreq_data *wdata, char *extra)
10029 {
10030 
10031 	struct iw_point *wrqu = (struct iw_point *)wdata;
10032 	u32 subcmd = wrqu->flags;
10033 	PADAPTER padapter = rtw_netdev_priv(dev);
10034 	int status = 0;
10035 
10036 #ifdef CONFIG_CONCURRENT_MODE
10037 	if (!is_primary_adapter(padapter)) {
10038 		RTW_INFO("MP mode only primary Adapter support\n");
10039 		return -EIO;
10040 	}
10041 #endif
10042 
10043 	RTW_INFO("%s mutx in %d\n", __func__, subcmd);
10044 	_enter_critical_mutex(&(adapter_to_dvobj(padapter)->ioctrl_mutex), NULL);
10045 	switch (subcmd) {
10046 	case CTA_TEST:
10047 		RTW_INFO("set CTA_TEST\n");
10048 		status = rtw_cta_test_start(dev, info, wdata, extra);
10049 		break;
10050 	case MP_DISABLE_BT_COEXIST:
10051 		RTW_INFO("set case MP_DISABLE_BT_COEXIST\n");
10052 		status = rtw_mp_disable_bt_coexist(dev, info, wdata, extra);
10053 		break;
10054 	case MP_IQK:
10055 		RTW_INFO("set MP_IQK\n");
10056 		status = rtw_mp_iqk(dev, info, wrqu, extra);
10057 		break;
10058 	case MP_LCK:
10059 		RTW_INFO("set MP_LCK\n");
10060 		status = rtw_mp_lck(dev, info, wrqu, extra);
10061 	break;
10062 
10063 	default:
10064 		status = -EIO;
10065 	}
10066 	_exit_critical_mutex(&(adapter_to_dvobj(padapter)->ioctrl_mutex), NULL);
10067 	RTW_INFO("%s mutx done %d\n", __func__, subcmd);
10068 
10069 	return status;
10070 }
10071 
10072 static int rtw_priv_mp_get(struct net_device *dev,
10073 			   struct iw_request_info *info,
10074 			   union iwreq_data *wdata, char *extra)
10075 {
10076 
10077 	struct iw_point *wrqu = (struct iw_point *)wdata;
10078 	u32 subcmd = wrqu->flags;
10079 	PADAPTER padapter = rtw_netdev_priv(dev);
10080 	int status = 0;
10081 
10082 #ifdef CONFIG_CONCURRENT_MODE
10083 	if (!is_primary_adapter(padapter)) {
10084 		RTW_INFO("MP mode only primary Adapter support\n");
10085 		return -EIO;
10086 	}
10087 #endif
10088 
10089 	RTW_INFO("%s mutx in %d\n", __func__, subcmd);
10090 	_enter_critical_mutex(&(adapter_to_dvobj(padapter)->ioctrl_mutex), NULL);
10091 
10092 	switch (subcmd) {
10093 	case MP_START:
10094 		RTW_INFO("set case mp_start\n");
10095 		status = rtw_mp_start(dev, info, wrqu, extra);
10096 		break;
10097 	case MP_STOP:
10098 		RTW_INFO("set case mp_stop\n");
10099 		status = rtw_mp_stop(dev, info, wrqu, extra);
10100 		break;
10101 	case MP_BANDWIDTH:
10102 		RTW_INFO("set case mp_bandwidth\n");
10103 		status = rtw_mp_bandwidth(dev, info, wrqu, extra);
10104 		break;
10105 	case MP_RESET_STATS:
10106 		RTW_INFO("set case MP_RESET_STATS\n");
10107 		status = rtw_mp_reset_stats(dev, info, wrqu, extra);
10108 		break;
10109 	case MP_SetRFPathSwh:
10110 		RTW_INFO("set MP_SetRFPathSwitch\n");
10111 		status = rtw_mp_SetRFPath(dev, info, wrqu, extra);
10112 		break;
10113 	case WRITE_REG:
10114 		status = rtw_mp_write_reg(dev, info, wrqu, extra);
10115 		break;
10116 	case WRITE_RF:
10117 		status = rtw_mp_write_rf(dev, info, wrqu, extra);
10118 		break;
10119 	case MP_PHYPARA:
10120 		RTW_INFO("mp_get  MP_PHYPARA\n");
10121 		status = rtw_mp_phypara(dev, info, wrqu, extra);
10122 		break;
10123 	case MP_CHANNEL:
10124 		RTW_INFO("set case mp_channel\n");
10125 		status = rtw_mp_channel(dev , info, wrqu, extra);
10126 		break;
10127 	case  MP_CHL_OFFSET:
10128 		RTW_INFO("set case mp_ch_offset\n");
10129 		status = rtw_mp_ch_offset(dev , info, wrqu, extra);
10130 		break;
10131 	case READ_REG:
10132 		RTW_INFO("mp_get  READ_REG\n");
10133 		status = rtw_mp_read_reg(dev, info, wrqu, extra);
10134 		break;
10135 	case READ_RF:
10136 		RTW_INFO("mp_get  READ_RF\n");
10137 		status = rtw_mp_read_rf(dev, info, wrqu, extra);
10138 		break;
10139 	case MP_RATE:
10140 		RTW_INFO("set case mp_rate\n");
10141 		status = rtw_mp_rate(dev, info, wrqu, extra);
10142 		break;
10143 	case MP_TXPOWER:
10144 		RTW_INFO("set case MP_TXPOWER\n");
10145 		status = rtw_mp_txpower(dev, info, wrqu, extra);
10146 		break;
10147 	case MP_ANT_TX:
10148 		RTW_INFO("set case MP_ANT_TX\n");
10149 		status = rtw_mp_ant_tx(dev, info, wrqu, extra);
10150 		break;
10151 	case MP_ANT_RX:
10152 		RTW_INFO("set case MP_ANT_RX\n");
10153 		status = rtw_mp_ant_rx(dev, info, wrqu, extra);
10154 		break;
10155 	case MP_QUERY:
10156 		status = rtw_mp_trx_query(dev, info, wrqu, extra);
10157 		break;
10158 	case MP_CTX:
10159 		RTW_INFO("set case MP_CTX\n");
10160 		status = rtw_mp_ctx(dev, info, wrqu, extra);
10161 		break;
10162 	case MP_ARX:
10163 		RTW_INFO("set case MP_ARX\n");
10164 		status = rtw_mp_arx(dev, info, wrqu, extra);
10165 		break;
10166 	case MP_DUMP:
10167 		RTW_INFO("set case MP_DUMP\n");
10168 		status = rtw_mp_dump(dev, info, wrqu, extra);
10169 		break;
10170 	case MP_PSD:
10171 		RTW_INFO("set case MP_PSD\n");
10172 		status = rtw_mp_psd(dev, info, wrqu, extra);
10173 		break;
10174 	case MP_THER:
10175 		RTW_INFO("set case MP_THER\n");
10176 		status = rtw_mp_thermal(dev, info, wrqu, extra);
10177 		break;
10178 	case MP_PwrCtlDM:
10179 		RTW_INFO("set MP_PwrCtlDM\n");
10180 		status = rtw_mp_PwrCtlDM(dev, info, wrqu, extra);
10181 		break;
10182 	case MP_QueryDrvStats:
10183 		RTW_INFO("mp_get MP_QueryDrvStats\n");
10184 		status = rtw_mp_QueryDrv(dev, info, wdata, extra);
10185 		break;
10186 	case MP_PWRTRK:
10187 		RTW_INFO("set case MP_PWRTRK\n");
10188 		status = rtw_mp_pwrtrk(dev, info, wrqu, extra);
10189 		break;
10190 	case MP_SET_TSSIDE:
10191 		RTW_INFO("set case MP_TSSI_DE\n");
10192 		status = rtw_mp_set_tsside(dev, info, wrqu, extra);
10193 		break;
10194 #ifdef CONFIG_MP_INCLUDED
10195 	case EFUSE_SET:
10196 		RTW_INFO("set case efuse set\n");
10197 		status = rtw_mp_efuse_set(dev, info, wdata, extra);
10198 		break;
10199 #endif
10200 	case EFUSE_GET:
10201 		RTW_INFO("efuse get EFUSE_GET\n");
10202 		status = rtw_mp_efuse_get(dev, info, wdata, extra);
10203 		break;
10204 	case MP_GET_TXPOWER_INX:
10205 		RTW_INFO("mp_get MP_GET_TXPOWER_INX\n");
10206 		status = rtw_mp_txpower_index(dev, info, wrqu, extra);
10207 		break;
10208 	case MP_GETVER:
10209 		RTW_INFO("mp_get MP_GETVER\n");
10210 		status = rtw_mp_getver(dev, info, wdata, extra);
10211 		break;
10212 	case MP_MON:
10213 		RTW_INFO("mp_get MP_MON\n");
10214 		status = rtw_mp_mon(dev, info, wdata, extra);
10215 		break;
10216 	case EFUSE_BT_MASK:
10217 		RTW_INFO("mp_get EFUSE_BT_MASK\n");
10218 		status = rtw_bt_efuse_mask_file(dev, info, wdata, extra);
10219 		break;
10220 	case EFUSE_MASK:
10221 		RTW_INFO("mp_get EFUSE_MASK\n");
10222 		status = rtw_efuse_mask_file(dev, info, wdata, extra);
10223 		break;
10224 	case EFUSE_FILE:
10225 		RTW_INFO("mp_get EFUSE_FILE\n");
10226 		status = rtw_efuse_file_map(dev, info, wdata, extra);
10227 		break;
10228 	case EFUSE_FILE_STORE:
10229 #if !defined(CONFIG_RTW_ANDROID_GKI)
10230 		RTW_INFO("mp_get EFUSE_FILE_STORE\n");
10231 		status = rtw_efuse_file_map_store(dev, info, wdata, extra);
10232 #else
10233 		RTW_ERR("Android GKI doesn't support: mp_get EFUSE_FILE_STORE\n");
10234 #endif /* !defined(CONFIG_RTW_ANDROID_GKI) */
10235 		break;
10236 	case MP_TX:
10237 		RTW_INFO("mp_get MP_TX\n");
10238 		status = rtw_mp_tx(dev, info, wdata, extra);
10239 		break;
10240 	case MP_RX:
10241 		RTW_INFO("mp_get MP_RX\n");
10242 		status = rtw_mp_rx(dev, info, wdata, extra);
10243 		break;
10244 	case MP_HW_TX_MODE:
10245 		RTW_INFO("mp_get MP_HW_TX_MODE\n");
10246 		status = rtw_mp_hwtx(dev, info, wdata, extra);
10247 		break;
10248 	case MP_GET_TSSIDE:
10249 		RTW_INFO("mp_get TSSI_DE\n");
10250 		status = rtw_mp_get_tsside(dev, info, wrqu, extra);
10251 		break;
10252 #ifdef CONFIG_RTW_CUSTOMER_STR
10253 	case MP_CUSTOMER_STR:
10254 		RTW_INFO("customer str\n");
10255 		status = rtw_mp_customer_str(dev, info, wdata, extra);
10256 		break;
10257 #endif
10258 	case MP_PWRLMT:
10259 		RTW_INFO("mp_get MP_SETPWRLMT\n");
10260 		status = rtw_mp_pwrlmt(dev, info, wdata, extra);
10261 		break;
10262 	case MP_PWRBYRATE:
10263 		RTW_INFO("mp_get MP_SETPWRBYRATE\n");
10264 		status = rtw_mp_pwrbyrate(dev, info, wdata, extra);
10265 		break;
10266 	case  BT_EFUSE_FILE:
10267 		RTW_INFO("mp_get BT EFUSE_FILE\n");
10268 		status = rtw_bt_efuse_file_map(dev, info, wdata, extra);
10269 		break;
10270 	case MP_SWRFPath:
10271 		RTW_INFO("mp_get MP_SWRFPath\n");
10272 		status = rtw_mp_switch_rf_path(dev, info, wrqu, extra);
10273 		break;
10274 	case MP_LINK:
10275 		RTW_INFO("mp_get MP_LINK\n");
10276 		status = rtw_mp_link(dev, info, wrqu, extra);
10277 		break;
10278 	case MP_DPK_TRK:
10279 		RTW_INFO("mp_get MP_DPK_TRK\n");
10280 		status = rtw_mp_dpk_track(dev, info, wdata, extra);
10281 		break;
10282 	case MP_DPK:
10283 		RTW_INFO("set MP_DPK\n");
10284 		status = rtw_mp_dpk(dev, info, wdata, extra);
10285 		break;
10286 	default:
10287 		status = -EIO;
10288 	}
10289 
10290 	_exit_critical_mutex(&(adapter_to_dvobj(padapter)->ioctrl_mutex), NULL);
10291 	RTW_INFO("%s mutx done_%d\n", __func__, subcmd);
10292 
10293 	return status;
10294 }
10295 #endif /*#if defined(CONFIG_MP_INCLUDED)*/
10296 
10297 
10298 #ifdef CONFIG_SDIO_INDIRECT_ACCESS
10299 #define DBG_MP_SDIO_INDIRECT_ACCESS 1
10300 static int rtw_mp_sd_iread(struct net_device *dev
10301 			   , struct iw_request_info *info
10302 			   , struct iw_point *wrqu
10303 			   , char *extra)
10304 {
10305 	char input[16];
10306 	u8 width;
10307 	unsigned long addr;
10308 	u32 ret = 0;
10309 	PADAPTER padapter = rtw_netdev_priv(dev);
10310 
10311 	if (wrqu->length > 16) {
10312 		RTW_INFO(FUNC_ADPT_FMT" wrqu->length:%d\n", FUNC_ADPT_ARG(padapter), wrqu->length);
10313 		ret = -EINVAL;
10314 		goto exit;
10315 	}
10316 
10317 	if (copy_from_user(input, wrqu->pointer, wrqu->length)) {
10318 		RTW_INFO(FUNC_ADPT_FMT" copy_from_user fail\n", FUNC_ADPT_ARG(padapter));
10319 		ret = -EFAULT;
10320 		goto exit;
10321 	}
10322 
10323 	_rtw_memset(extra, 0, wrqu->length);
10324 
10325 	if (sscanf(input, "%hhu,%lx", &width, &addr) != 2) {
10326 		RTW_INFO(FUNC_ADPT_FMT" sscanf fail\n", FUNC_ADPT_ARG(padapter));
10327 		ret = -EINVAL;
10328 		goto exit;
10329 	}
10330 
10331 	if (addr > 0x3FFF) {
10332 		RTW_INFO(FUNC_ADPT_FMT" addr:0x%lx\n", FUNC_ADPT_ARG(padapter), addr);
10333 		ret = -EINVAL;
10334 		goto exit;
10335 	}
10336 
10337 	if (DBG_MP_SDIO_INDIRECT_ACCESS)
10338 		RTW_INFO(FUNC_ADPT_FMT" width:%u, addr:0x%lx\n", FUNC_ADPT_ARG(padapter), width, addr);
10339 
10340 	switch (width) {
10341 	case 1:
10342 		sprintf(extra, "0x%02x", rtw_sd_iread8(padapter, addr));
10343 		wrqu->length = strlen(extra);
10344 		break;
10345 	case 2:
10346 		sprintf(extra, "0x%04x", rtw_sd_iread16(padapter, addr));
10347 		wrqu->length = strlen(extra);
10348 		break;
10349 	case 4:
10350 		sprintf(extra, "0x%08x", rtw_sd_iread32(padapter, addr));
10351 		wrqu->length = strlen(extra);
10352 		break;
10353 	default:
10354 		wrqu->length = 0;
10355 		ret = -EINVAL;
10356 		break;
10357 	}
10358 
10359 exit:
10360 	return ret;
10361 }
10362 
10363 static int rtw_mp_sd_iwrite(struct net_device *dev
10364 			    , struct iw_request_info *info
10365 			    , struct iw_point *wrqu
10366 			    , char *extra)
10367 {
10368 	char width;
10369 	unsigned long addr, data;
10370 	int ret = 0;
10371 	PADAPTER padapter = rtw_netdev_priv(dev);
10372 	char input[32];
10373 
10374 	if (wrqu->length > 32) {
10375 		RTW_INFO(FUNC_ADPT_FMT" wrqu->length:%d\n", FUNC_ADPT_ARG(padapter), wrqu->length);
10376 		ret = -EINVAL;
10377 		goto exit;
10378 	}
10379 
10380 	if (copy_from_user(input, wrqu->pointer, wrqu->length)) {
10381 		RTW_INFO(FUNC_ADPT_FMT" copy_from_user fail\n", FUNC_ADPT_ARG(padapter));
10382 		ret = -EFAULT;
10383 		goto exit;
10384 	}
10385 
10386 	_rtw_memset(extra, 0, wrqu->length);
10387 
10388 	if (sscanf(input, "%hhu,%lx,%lx", &width, &addr, &data) != 3) {
10389 		RTW_INFO(FUNC_ADPT_FMT" sscanf fail\n", FUNC_ADPT_ARG(padapter));
10390 		ret = -EINVAL;
10391 		goto exit;
10392 	}
10393 
10394 	if (addr > 0x3FFF) {
10395 		RTW_INFO(FUNC_ADPT_FMT" addr:0x%lx\n", FUNC_ADPT_ARG(padapter), addr);
10396 		ret = -EINVAL;
10397 		goto exit;
10398 	}
10399 
10400 	if (DBG_MP_SDIO_INDIRECT_ACCESS)
10401 		RTW_INFO(FUNC_ADPT_FMT" width:%u, addr:0x%lx, data:0x%lx\n", FUNC_ADPT_ARG(padapter), width, addr, data);
10402 
10403 	switch (width) {
10404 	case 1:
10405 		if (data > 0xFF) {
10406 			ret = -EINVAL;
10407 			break;
10408 		}
10409 		rtw_sd_iwrite8(padapter, addr, data);
10410 		break;
10411 	case 2:
10412 		if (data > 0xFFFF) {
10413 			ret = -EINVAL;
10414 			break;
10415 		}
10416 		rtw_sd_iwrite16(padapter, addr, data);
10417 		break;
10418 	case 4:
10419 		rtw_sd_iwrite32(padapter, addr, data);
10420 		break;
10421 	default:
10422 		wrqu->length = 0;
10423 		ret = -EINVAL;
10424 		break;
10425 	}
10426 
10427 exit:
10428 	return ret;
10429 }
10430 #endif /* CONFIG_SDIO_INDIRECT_ACCESS */
10431 
10432 static int rtw_priv_set(struct net_device *dev,
10433 			struct iw_request_info *info,
10434 			union iwreq_data *wdata, char *extra)
10435 {
10436 	struct iw_point *wrqu = (struct iw_point *)wdata;
10437 	u32 subcmd = wrqu->flags;
10438 	PADAPTER padapter = rtw_netdev_priv(dev);
10439 
10440 	if (padapter == NULL)
10441 		return -ENETDOWN;
10442 
10443 	if (padapter->bup == _FALSE) {
10444 		RTW_INFO(" %s fail =>(padapter->bup == _FALSE )\n", __FUNCTION__);
10445 		return -ENETDOWN;
10446 	}
10447 
10448 	if (RTW_CANNOT_RUN(padapter)) {
10449 		RTW_INFO("%s fail =>(bSurpriseRemoved == _TRUE) || ( bDriverStopped == _TRUE)\n", __func__);
10450 		return -ENETDOWN;
10451 	}
10452 
10453 	if (extra == NULL) {
10454 		wrqu->length = 0;
10455 		return -EIO;
10456 	}
10457 
10458 	if (subcmd < MP_NULL) {
10459 #ifdef CONFIG_MP_INCLUDED
10460 		rtw_priv_mp_set(dev, info, wdata, extra);
10461 #endif
10462 		return 0;
10463 	}
10464 
10465 	switch (subcmd) {
10466 #ifdef CONFIG_WOWLAN
10467 	case MP_WOW_ENABLE:
10468 		RTW_INFO("set case MP_WOW_ENABLE: %s\n", extra);
10469 
10470 		rtw_wowlan_ctrl(dev, info, wdata, extra);
10471 		break;
10472 	case MP_WOW_SET_PATTERN:
10473 		RTW_INFO("set case MP_WOW_SET_PATTERN: %s\n", extra);
10474 		rtw_wowlan_set_pattern(dev, info, wdata, extra);
10475 		break;
10476 	#ifdef CONFIG_WOW_KEEP_ALIVE_PATTERN
10477 	case MP_WOW_SET_KEEP_ALIVE_PATTERN:
10478 		RTW_INFO("set case MP_WOW_SET_KEEP_ALIVE_PATTERN: %s\n", extra);
10479 		rtw_wowlan_set_keep_alive_pattern(dev, info, wdata, extra);
10480 		break;
10481 	#endif /*CONFIG_WOW_KEEP_ALIVE_PATTERN*/
10482 
10483 #endif
10484 #ifdef CONFIG_AP_WOWLAN
10485 	case MP_AP_WOW_ENABLE:
10486 		RTW_INFO("set case MP_AP_WOW_ENABLE: %s\n", extra);
10487 		rtw_ap_wowlan_ctrl(dev, info, wdata, extra);
10488 		break;
10489 #endif
10490 #ifdef CONFIG_APPEND_VENDOR_IE_ENABLE
10491 	case VENDOR_IE_SET:
10492 		RTW_INFO("set case VENDOR_IE_SET\n");
10493 		rtw_vendor_ie_set(dev , info , wdata , extra);
10494 		break;
10495 #endif
10496 	default:
10497 		return -EIO;
10498 	}
10499 
10500 	return 0;
10501 }
10502 
10503 
10504 static int rtw_priv_get(struct net_device *dev,
10505 			struct iw_request_info *info,
10506 			union iwreq_data *wdata, char *extra)
10507 {
10508 	struct iw_point *wrqu = (struct iw_point *)wdata;
10509 	u32 subcmd = wrqu->flags;
10510 	PADAPTER padapter = rtw_netdev_priv(dev);
10511 	HAL_DATA_TYPE	*pHalData = GET_HAL_DATA(padapter);
10512 	struct dm_struct	*p_dm = &pHalData->odmpriv;
10513 	struct dm_rf_calibration_struct	*p_rf_calibrate_info = &(p_dm->rf_calibrate_info);
10514 	struct dm_iqk_info	*p_iqk_info = &p_dm->IQK_info;
10515 	u32 i = 100;
10516 
10517 
10518 	if (padapter->bup == _FALSE) {
10519 		RTW_INFO(" %s fail =>(padapter->bup == _FALSE )\n", __FUNCTION__);
10520 		return -ENETDOWN;
10521 	}
10522 
10523 	if (RTW_CANNOT_RUN(padapter)) {
10524 		RTW_INFO("%s fail =>(padapter->bSurpriseRemoved == _TRUE) || ( padapter->bDriverStopped == _TRUE)\n", __func__);
10525 		return -ENETDOWN;
10526 	}
10527 
10528 	if (extra == NULL) {
10529 		wrqu->length = 0;
10530 		return -EIO;
10531 	}
10532 
10533 	if (subcmd < MP_NULL) {
10534 #ifdef CONFIG_MP_INCLUDED
10535 		while (i > 1) {
10536 			if (p_rf_calibrate_info->is_iqk_in_progress) {
10537 				rtw_msleep_os(10);
10538 			} else {
10539 				p_iqk_info->rfk_forbidden = _TRUE;
10540 				break;
10541 			}
10542 			i--;
10543 		}
10544 		if (subcmd == MP_CHANNEL || subcmd == MP_BANDWIDTH || subcmd == MP_START || subcmd == MP_DPK)
10545 			p_iqk_info->rfk_forbidden = _FALSE;
10546 		rtw_priv_mp_get(dev, info, wdata, extra);
10547 		rtw_msleep_os(10); /* delay 5ms for sending pkt before exit adb shell operation */
10548 		p_iqk_info->rfk_forbidden = _FALSE;
10549 #endif
10550 	} else {
10551 			switch (subcmd) {
10552 #if defined(CONFIG_RTL8723B)
10553 			case MP_SetBT:
10554 				RTW_INFO("set MP_SetBT\n");
10555 				rtw_mp_SetBT(dev, info, wdata, extra);
10556 				break;
10557 #endif
10558 #ifdef CONFIG_SDIO_INDIRECT_ACCESS
10559 			case MP_SD_IREAD:
10560 				rtw_mp_sd_iread(dev, info, wrqu, extra);
10561 				break;
10562 			case MP_SD_IWRITE:
10563 				rtw_mp_sd_iwrite(dev, info, wrqu, extra);
10564 				break;
10565 #endif
10566 #ifdef CONFIG_APPEND_VENDOR_IE_ENABLE
10567 			case VENDOR_IE_GET:
10568 				RTW_INFO("get case VENDOR_IE_GET\n");
10569 				rtw_vendor_ie_get(dev , info , wdata , extra);
10570 				break;
10571 #endif
10572 			case GET_IC_TYPE:
10573 				RTW_INFO("get IC Type\n");
10574 				rtw_get_ic_type(dev , info , wdata , extra);
10575 				break;
10576 			default:
10577 				return -EIO;
10578 			}
10579 		}
10580 
10581 	return 0;
10582 }
10583 
10584 
10585 #ifdef CONFIG_TDLS
10586 static int rtw_wx_tdls_wfd_enable(struct net_device *dev,
10587 				  struct iw_request_info *info,
10588 				  union iwreq_data *wrqu, char *extra)
10589 {
10590 	int ret = 0;
10591 
10592 #ifdef CONFIG_WFD
10593 
10594 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
10595 
10596 	RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
10597 
10598 	if (extra[0] == '0')
10599 		rtw_tdls_wfd_enable(padapter, 0);
10600 	else
10601 		rtw_tdls_wfd_enable(padapter, 1);
10602 
10603 #endif /* CONFIG_WFD */
10604 
10605 	return ret;
10606 }
10607 
10608 static int rtw_tdls_weaksec(struct net_device *dev,
10609 			    struct iw_request_info *info,
10610 			    union iwreq_data *wrqu, char *extra)
10611 {
10612 	int ret = 0;
10613 
10614 #ifdef CONFIG_TDLS
10615 
10616 	u8 i, j;
10617 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
10618 
10619 	RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
10620 
10621 	if (extra[0] == '0')
10622 		padapter->wdinfo.wfd_tdls_weaksec = 0;
10623 	else
10624 		padapter->wdinfo.wfd_tdls_weaksec = 1;
10625 
10626 #endif /* CONFIG_TDLS */
10627 
10628 	return ret;
10629 }
10630 
10631 
10632 static int rtw_tdls_enable(struct net_device *dev,
10633 			   struct iw_request_info *info,
10634 			   union iwreq_data *wrqu, char *extra)
10635 {
10636 	int ret = 0;
10637 
10638 #ifdef CONFIG_TDLS
10639 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
10640 
10641 	RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
10642 
10643 	if (extra[0] == '0')
10644 		rtw_disable_tdls_func(padapter, _TRUE);
10645 	else if (extra[0] == '1')
10646 		rtw_enable_tdls_func(padapter);
10647 #endif /* CONFIG_TDLS */
10648 
10649 	return ret;
10650 }
10651 
10652 static int rtw_tdls_setup(struct net_device *dev,
10653 			  struct iw_request_info *info,
10654 			  union iwreq_data *wrqu, char *extra)
10655 {
10656 	int ret = 0;
10657 #ifdef CONFIG_TDLS
10658 	u8 i, j;
10659 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
10660 	struct tdls_txmgmt txmgmt;
10661 #ifdef CONFIG_WFD
10662 	struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
10663 #endif /* CONFIG_WFD */
10664 
10665 	RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
10666 
10667 	if (wrqu->data.length - 1 != 17) {
10668 		RTW_INFO("[%s] length:%d != 17\n", __FUNCTION__, (wrqu->data.length - 1));
10669 		return ret;
10670 	}
10671 
10672 	_rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
10673 	for (i = 0, j = 0 ; i < ETH_ALEN; i++, j += 3)
10674 		txmgmt.peer[i] = key_2char2num(*(extra + j), *(extra + j + 1));
10675 
10676 #ifdef CONFIG_WFD
10677 	if (_AES_ != padapter->securitypriv.dot11PrivacyAlgrthm) {
10678 		/* Weak Security situation with AP. */
10679 		if (0 == pwdinfo->wfd_tdls_weaksec)	{
10680 			/* Can't send the tdls setup request out!! */
10681 			RTW_INFO("[%s] Current link is not AES, "
10682 				"SKIP sending the tdls setup request!!\n", __FUNCTION__);
10683 		} else
10684 			issue_tdls_setup_req(padapter, &txmgmt, _TRUE);
10685 	} else
10686 #endif /* CONFIG_WFD */
10687 	{
10688 		issue_tdls_setup_req(padapter, &txmgmt, _TRUE);
10689 	}
10690 #endif /* CONFIG_TDLS */
10691 
10692 	return ret;
10693 }
10694 
10695 static int rtw_tdls_teardown(struct net_device *dev,
10696 			     struct iw_request_info *info,
10697 			     union iwreq_data *wrqu, char *extra)
10698 {
10699 	int ret = 0;
10700 
10701 #ifdef CONFIG_TDLS
10702 
10703 	u8 i, j;
10704 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
10705 	struct sta_info *ptdls_sta = NULL;
10706 	struct tdls_txmgmt txmgmt;
10707 
10708 	RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
10709 
10710 	if (wrqu->data.length - 1 != 17 && wrqu->data.length - 1 != 19) {
10711 		RTW_INFO("[%s] length:%d != 17 or 19\n",
10712 			 __FUNCTION__, (wrqu->data.length - 1));
10713 		return ret;
10714 	}
10715 
10716 	_rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
10717 	for (i = 0, j = 0; i < ETH_ALEN; i++, j += 3)
10718 		txmgmt.peer[i] = key_2char2num(*(extra + j), *(extra + j + 1));
10719 
10720 	ptdls_sta = rtw_get_stainfo(&(padapter->stapriv), txmgmt.peer);
10721 
10722 	if (ptdls_sta != NULL) {
10723 		txmgmt.status_code = _RSON_TDLS_TEAR_UN_RSN_;
10724 		if (wrqu->data.length - 1 == 19)
10725 			issue_tdls_teardown(padapter, &txmgmt, _FALSE);
10726 		else
10727 			issue_tdls_teardown(padapter, &txmgmt, _TRUE);
10728 	} else
10729 		RTW_INFO("TDLS peer not found\n");
10730 #endif /* CONFIG_TDLS */
10731 
10732 	return ret;
10733 }
10734 
10735 static int rtw_tdls_discovery(struct net_device *dev,
10736 			      struct iw_request_info *info,
10737 			      union iwreq_data *wrqu, char *extra)
10738 {
10739 	int ret = 0;
10740 
10741 #ifdef CONFIG_TDLS
10742 
10743 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
10744 	struct tdls_txmgmt	txmgmt;
10745 	int i = 0, j = 0;
10746 
10747 	RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
10748 
10749 	_rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
10750 	for (i = 0, j = 0 ; i < ETH_ALEN; i++, j += 3)
10751 		txmgmt.peer[i] = key_2char2num(*(extra + j), *(extra + j + 1));
10752 
10753 	issue_tdls_dis_req(padapter, &txmgmt);
10754 
10755 #endif /* CONFIG_TDLS */
10756 
10757 	return ret;
10758 }
10759 
10760 static int rtw_tdls_ch_switch(struct net_device *dev,
10761 			      struct iw_request_info *info,
10762 			      union iwreq_data *wrqu, char *extra)
10763 {
10764 	int ret = 0;
10765 
10766 #ifdef CONFIG_TDLS
10767 #ifdef CONFIG_TDLS_CH_SW
10768 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
10769 	struct tdls_ch_switch *pchsw_info = &padapter->tdlsinfo.chsw_info;
10770 	u8 i, j;
10771 	struct sta_info *ptdls_sta = NULL;
10772 	u8 take_care_iqk;
10773 
10774 	RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
10775 
10776 	if (rtw_tdls_is_chsw_allowed(padapter) == _FALSE) {
10777 		RTW_INFO("TDLS channel switch is not allowed\n");
10778 		return ret;
10779 	}
10780 
10781 	for (i = 0, j = 0 ; i < ETH_ALEN; i++, j += 3)
10782 		pchsw_info->addr[i] = key_2char2num(*(extra + j), *(extra + j + 1));
10783 
10784 	ptdls_sta = rtw_get_stainfo(&padapter->stapriv, pchsw_info->addr);
10785 	if (ptdls_sta == NULL)
10786 		return ret;
10787 
10788 	pchsw_info->ch_sw_state |= TDLS_CH_SW_INITIATOR_STATE;
10789 
10790 	if (ptdls_sta != NULL) {
10791 		if (pchsw_info->off_ch_num == 0)
10792 			pchsw_info->off_ch_num = 11;
10793 	} else
10794 		RTW_INFO("TDLS peer not found\n");
10795 
10796 	rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);
10797 
10798 	rtw_hal_get_hwreg(padapter, HW_VAR_CH_SW_NEED_TO_TAKE_CARE_IQK_INFO, &take_care_iqk);
10799 	if (take_care_iqk == _TRUE) {
10800 #ifdef CONFIG_TDLS_CH_SW_V2
10801 		rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_PREPARE);
10802 #else
10803 		u8 central_chnl;
10804 		u8 bw_mode;
10805 
10806 		bw_mode = (pchsw_info->ch_offset) ? CHANNEL_WIDTH_40 : CHANNEL_WIDTH_20;
10807 		central_chnl = rtw_get_center_ch(pchsw_info->off_ch_num, bw_mode, pchsw_info->ch_offset);
10808 		if (rtw_hal_ch_sw_iqk_info_search(padapter, central_chnl, bw_mode) >= 0)
10809 			rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_START);
10810 		else
10811 			rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_PREPARE);
10812 #endif
10813 	} else
10814 		rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_START);
10815 
10816 	/* issue_tdls_ch_switch_req(padapter, ptdls_sta); */
10817 	/* RTW_INFO("issue tdls ch switch req\n"); */
10818 
10819 #endif /* CONFIG_TDLS_CH_SW */
10820 #endif /* CONFIG_TDLS */
10821 
10822 	return ret;
10823 }
10824 
10825 static int rtw_tdls_ch_switch_off(struct net_device *dev,
10826 				  struct iw_request_info *info,
10827 				  union iwreq_data *wrqu, char *extra)
10828 {
10829 	int ret = 0;
10830 
10831 #ifdef CONFIG_TDLS
10832 #ifdef CONFIG_TDLS_CH_SW
10833 
10834 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
10835 	struct tdls_ch_switch *pchsw_info = &padapter->tdlsinfo.chsw_info;
10836 	u8 i, j, mac_addr[ETH_ALEN];
10837 	struct sta_info *ptdls_sta = NULL;
10838 	struct tdls_txmgmt txmgmt;
10839 
10840 	_rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
10841 
10842 	RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
10843 
10844 	if (rtw_tdls_is_chsw_allowed(padapter) == _FALSE) {
10845 		RTW_INFO("TDLS channel switch is not allowed\n");
10846 		return ret;
10847 	}
10848 
10849 	if (wrqu->data.length >= 17) {
10850 		for (i = 0, j = 0 ; i < ETH_ALEN; i++, j += 3)
10851 			mac_addr[i] = key_2char2num(*(extra + j), *(extra + j + 1));
10852 		ptdls_sta = rtw_get_stainfo(&padapter->stapriv, mac_addr);
10853 	}
10854 
10855 	if (ptdls_sta == NULL)
10856 		return ret;
10857 
10858 	rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_END_TO_BASE_CHNL);
10859 
10860 	pchsw_info->ch_sw_state &= ~(TDLS_CH_SW_INITIATOR_STATE |
10861 				     TDLS_CH_SWITCH_ON_STATE |
10862 				     TDLS_PEER_AT_OFF_STATE);
10863 	_rtw_memset(pchsw_info->addr, 0x00, ETH_ALEN);
10864 
10865 	ptdls_sta->ch_switch_time = 0;
10866 	ptdls_sta->ch_switch_timeout = 0;
10867 	_cancel_timer_ex(&ptdls_sta->ch_sw_timer);
10868 	_cancel_timer_ex(&ptdls_sta->delay_timer);
10869 	_cancel_timer_ex(&ptdls_sta->stay_on_base_chnl_timer);
10870 	_cancel_timer_ex(&ptdls_sta->ch_sw_monitor_timer);
10871 
10872 	rtw_pm_set_lps(padapter, PS_MODE_MAX);
10873 #endif /* CONFIG_TDLS_CH_SW */
10874 #endif /* CONFIG_TDLS */
10875 
10876 	return ret;
10877 }
10878 
10879 static int rtw_tdls_dump_ch(struct net_device *dev,
10880 			    struct iw_request_info *info,
10881 			    union iwreq_data *wrqu, char *extra)
10882 {
10883 	int ret = 0;
10884 
10885 #ifdef CONFIG_TDLS
10886 #ifdef CONFIG_TDLS_CH_SW
10887 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
10888 	struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
10889 
10890 	RTW_INFO("[%s] dump_stack:%s\n", __FUNCTION__, extra);
10891 
10892 	extra[wrqu->data.length] = 0x00;
10893 	ptdlsinfo->chsw_info.dump_stack = rtw_atoi(extra);
10894 
10895 	return ret;
10896 
10897 #endif
10898 #endif /* CONFIG_TDLS */
10899 
10900 	return ret;
10901 }
10902 
10903 static int rtw_tdls_off_ch_num(struct net_device *dev,
10904 			       struct iw_request_info *info,
10905 			       union iwreq_data *wrqu, char *extra)
10906 {
10907 	int ret = 0;
10908 
10909 #ifdef CONFIG_TDLS
10910 #ifdef CONFIG_TDLS_CH_SW
10911 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
10912 	struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
10913 
10914 	RTW_INFO("[%s] off_ch_num:%s\n", __FUNCTION__, extra);
10915 
10916 	extra[wrqu->data.length] = 0x00;
10917 	ptdlsinfo->chsw_info.off_ch_num = rtw_atoi(extra);
10918 
10919 	return ret;
10920 
10921 #endif
10922 #endif /* CONFIG_TDLS */
10923 
10924 	return ret;
10925 }
10926 
10927 static int rtw_tdls_ch_offset(struct net_device *dev,
10928 			      struct iw_request_info *info,
10929 			      union iwreq_data *wrqu, char *extra)
10930 {
10931 	int ret = 0;
10932 
10933 #ifdef CONFIG_TDLS
10934 #ifdef CONFIG_TDLS_CH_SW
10935 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
10936 	struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
10937 
10938 	RTW_INFO("[%s] ch_offset:%s\n", __FUNCTION__, extra);
10939 
10940 	extra[wrqu->data.length] = 0x00;
10941 	switch (rtw_atoi(extra)) {
10942 	case SCA:
10943 		ptdlsinfo->chsw_info.ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
10944 		break;
10945 
10946 	case SCB:
10947 		ptdlsinfo->chsw_info.ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
10948 		break;
10949 
10950 	default:
10951 		ptdlsinfo->chsw_info.ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
10952 		break;
10953 	}
10954 
10955 	return ret;
10956 
10957 #endif
10958 #endif /* CONFIG_TDLS */
10959 
10960 	return ret;
10961 }
10962 
10963 static int rtw_tdls_pson(struct net_device *dev,
10964 			 struct iw_request_info *info,
10965 			 union iwreq_data *wrqu, char *extra)
10966 {
10967 	int ret = 0;
10968 
10969 #ifdef CONFIG_TDLS
10970 
10971 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
10972 	u8 i, j, mac_addr[ETH_ALEN];
10973 	struct sta_info *ptdls_sta = NULL;
10974 
10975 	RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
10976 
10977 	for (i = 0, j = 0; i < ETH_ALEN; i++, j += 3)
10978 		mac_addr[i] = key_2char2num(*(extra + j), *(extra + j + 1));
10979 
10980 	ptdls_sta = rtw_get_stainfo(&padapter->stapriv, mac_addr);
10981 
10982 	issue_nulldata_to_TDLS_peer_STA(padapter, ptdls_sta->cmn.mac_addr, 1, 3, 500);
10983 
10984 #endif /* CONFIG_TDLS */
10985 
10986 	return ret;
10987 }
10988 
10989 static int rtw_tdls_psoff(struct net_device *dev,
10990 			  struct iw_request_info *info,
10991 			  union iwreq_data *wrqu, char *extra)
10992 {
10993 	int ret = 0;
10994 
10995 #ifdef CONFIG_TDLS
10996 
10997 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
10998 	u8 i, j, mac_addr[ETH_ALEN];
10999 	struct sta_info *ptdls_sta = NULL;
11000 
11001 	RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
11002 
11003 	for (i = 0, j = 0; i < ETH_ALEN; i++, j += 3)
11004 		mac_addr[i] = key_2char2num(*(extra + j), *(extra + j + 1));
11005 
11006 	ptdls_sta = rtw_get_stainfo(&padapter->stapriv, mac_addr);
11007 
11008 	if (ptdls_sta)
11009 		issue_nulldata_to_TDLS_peer_STA(padapter, ptdls_sta->cmn.mac_addr, 0, 3, 500);
11010 
11011 #endif /* CONFIG_TDLS */
11012 
11013 	return ret;
11014 }
11015 
11016 static int rtw_tdls_setip(struct net_device *dev,
11017 			  struct iw_request_info *info,
11018 			  union iwreq_data *wrqu, char *extra)
11019 {
11020 	int ret = 0;
11021 
11022 #ifdef CONFIG_TDLS
11023 #ifdef CONFIG_WFD
11024 
11025 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
11026 	struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
11027 	struct wifi_display_info *pwfd_info = ptdlsinfo->wfd_info;
11028 	u8 i = 0, j = 0, k = 0, tag = 0;
11029 
11030 	RTW_INFO("[%s] %s %d\n", __FUNCTION__, extra, wrqu->data.length - 1);
11031 
11032 	while (i < 4) {
11033 		for (j = 0; j < 4; j++) {
11034 			if (*(extra + j + tag) == '.' || *(extra + j + tag) == '\0') {
11035 				if (j == 1)
11036 					pwfd_info->ip_address[i] = convert_ip_addr('0', '0', *(extra + (j - 1) + tag));
11037 				if (j == 2)
11038 					pwfd_info->ip_address[i] = convert_ip_addr('0', *(extra + (j - 2) + tag), *(extra + (j - 1) + tag));
11039 				if (j == 3)
11040 					pwfd_info->ip_address[i] = convert_ip_addr(*(extra + (j - 3) + tag), *(extra + (j - 2) + tag), *(extra + (j - 1) + tag));
11041 
11042 				tag += j + 1;
11043 				break;
11044 			}
11045 		}
11046 		i++;
11047 	}
11048 
11049 	RTW_INFO("[%s] Set IP = %u.%u.%u.%u\n", __FUNCTION__,
11050 		 ptdlsinfo->wfd_info->ip_address[0],
11051 		 ptdlsinfo->wfd_info->ip_address[1],
11052 		 ptdlsinfo->wfd_info->ip_address[2],
11053 		 ptdlsinfo->wfd_info->ip_address[3]);
11054 
11055 #endif /* CONFIG_WFD */
11056 #endif /* CONFIG_TDLS */
11057 
11058 	return ret;
11059 }
11060 
11061 static int rtw_tdls_getip(struct net_device *dev,
11062 			  struct iw_request_info *info,
11063 			  union iwreq_data *wrqu, char *extra)
11064 {
11065 	int ret = 0;
11066 
11067 #ifdef CONFIG_TDLS
11068 #ifdef CONFIG_WFD
11069 
11070 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
11071 	struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
11072 	struct wifi_display_info *pwfd_info = ptdlsinfo->wfd_info;
11073 
11074 	RTW_INFO("[%s]\n", __FUNCTION__);
11075 
11076 	sprintf(extra, "\n\n%u.%u.%u.%u\n",
11077 		pwfd_info->peer_ip_address[0], pwfd_info->peer_ip_address[1],
11078 		pwfd_info->peer_ip_address[2], pwfd_info->peer_ip_address[3]);
11079 
11080 	RTW_INFO("[%s] IP=%u.%u.%u.%u\n", __FUNCTION__,
11081 		 pwfd_info->peer_ip_address[0], pwfd_info->peer_ip_address[1],
11082 		 pwfd_info->peer_ip_address[2], pwfd_info->peer_ip_address[3]);
11083 
11084 	wrqu->data.length = strlen(extra);
11085 
11086 #endif /* CONFIG_WFD */
11087 #endif /* CONFIG_TDLS */
11088 
11089 	return ret;
11090 }
11091 
11092 static int rtw_tdls_getport(struct net_device *dev,
11093 			    struct iw_request_info *info,
11094 			    union iwreq_data *wrqu, char *extra)
11095 {
11096 
11097 	int ret = 0;
11098 
11099 #ifdef CONFIG_TDLS
11100 #ifdef CONFIG_WFD
11101 
11102 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
11103 	struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
11104 	struct wifi_display_info *pwfd_info = ptdlsinfo->wfd_info;
11105 
11106 	RTW_INFO("[%s]\n", __FUNCTION__);
11107 
11108 	sprintf(extra, "\n\n%d\n", pwfd_info->peer_rtsp_ctrlport);
11109 	RTW_INFO("[%s] remote port = %d\n",
11110 		 __FUNCTION__, pwfd_info->peer_rtsp_ctrlport);
11111 
11112 	wrqu->data.length = strlen(extra);
11113 
11114 #endif /* CONFIG_WFD */
11115 #endif /* CONFIG_TDLS */
11116 
11117 	return ret;
11118 
11119 }
11120 
11121 /* WFDTDLS, for sigma test */
11122 static int rtw_tdls_dis_result(struct net_device *dev,
11123 			       struct iw_request_info *info,
11124 			       union iwreq_data *wrqu, char *extra)
11125 {
11126 
11127 	int ret = 0;
11128 
11129 #ifdef CONFIG_TDLS
11130 #ifdef CONFIG_WFD
11131 
11132 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
11133 	struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
11134 
11135 	RTW_INFO("[%s]\n", __FUNCTION__);
11136 
11137 	if (ptdlsinfo->dev_discovered == _TRUE) {
11138 		sprintf(extra, "\n\nDis=1\n");
11139 		ptdlsinfo->dev_discovered = _FALSE;
11140 	}
11141 
11142 	wrqu->data.length = strlen(extra);
11143 
11144 #endif /* CONFIG_WFD */
11145 #endif /* CONFIG_TDLS */
11146 
11147 	return ret;
11148 
11149 }
11150 
11151 /* WFDTDLS, for sigma test */
11152 static int rtw_wfd_tdls_status(struct net_device *dev,
11153 			       struct iw_request_info *info,
11154 			       union iwreq_data *wrqu, char *extra)
11155 {
11156 
11157 	int ret = 0;
11158 
11159 #ifdef CONFIG_TDLS
11160 
11161 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
11162 	struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
11163 
11164 	RTW_INFO("[%s]\n", __FUNCTION__);
11165 
11166 	sprintf(extra, "\nlink_established:%d\n"
11167 		"sta_cnt:%d\n"
11168 		"sta_maximum:%d\n"
11169 		"cur_channel:%d\n"
11170 		"tdls_enable:%d"
11171 #ifdef CONFIG_TDLS_CH_SW
11172 		"ch_sw_state:%08x\n"
11173 		"chsw_on:%d\n"
11174 		"off_ch_num:%d\n"
11175 		"cur_time:%d\n"
11176 		"ch_offset:%d\n"
11177 		"delay_swtich_back:%d"
11178 #endif
11179 		,
11180 		ptdlsinfo->link_established, ptdlsinfo->sta_cnt,
11181 		ptdlsinfo->sta_maximum, ptdlsinfo->cur_channel,
11182 		rtw_is_tdls_enabled(padapter)
11183 #ifdef CONFIG_TDLS_CH_SW
11184 		,
11185 		ptdlsinfo->chsw_info.ch_sw_state,
11186 		ATOMIC_READ(&padapter->tdlsinfo.chsw_info.chsw_on),
11187 		ptdlsinfo->chsw_info.off_ch_num,
11188 		ptdlsinfo->chsw_info.cur_time,
11189 		ptdlsinfo->chsw_info.ch_offset,
11190 		ptdlsinfo->chsw_info.delay_switch_back
11191 #endif
11192 	       );
11193 
11194 	wrqu->data.length = strlen(extra);
11195 
11196 #endif /* CONFIG_TDLS */
11197 
11198 	return ret;
11199 
11200 }
11201 
11202 static int rtw_tdls_getsta(struct net_device *dev,
11203 			   struct iw_request_info *info,
11204 			   union iwreq_data *wrqu, char *extra)
11205 {
11206 
11207 	int ret = 0;
11208 #ifdef CONFIG_TDLS
11209 	u8 i, j;
11210 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
11211 	u8 addr[ETH_ALEN] = {0};
11212 	char charmac[17];
11213 	struct sta_info *ptdls_sta = NULL;
11214 
11215 	RTW_INFO("[%s] %s %d\n", __FUNCTION__,
11216 		 (char *)wrqu->data.pointer, wrqu->data.length - 1);
11217 
11218 	if (copy_from_user(charmac, wrqu->data.pointer + 9, 17)) {
11219 		ret = -EFAULT;
11220 		goto exit;
11221 	}
11222 
11223 	RTW_INFO("[%s] %d, charmac:%s\n", __FUNCTION__, __LINE__, charmac);
11224 	for (i = 0, j = 0 ; i < ETH_ALEN; i++, j += 3)
11225 		addr[i] = key_2char2num(*(charmac + j), *(charmac + j + 1));
11226 
11227 	RTW_INFO("[%s] %d, charmac:%s, addr:"MAC_FMT"\n",
11228 		 __FUNCTION__, __LINE__, charmac, MAC_ARG(addr));
11229 	ptdls_sta = rtw_get_stainfo(&padapter->stapriv, addr);
11230 	if (ptdls_sta) {
11231 		sprintf(extra, "\n\ntdls_sta_state=0x%08x\n", ptdls_sta->tdls_sta_state);
11232 		RTW_INFO("\n\ntdls_sta_state=%d\n", ptdls_sta->tdls_sta_state);
11233 	} else {
11234 		sprintf(extra, "\n\nNot found this sta\n");
11235 		RTW_INFO("\n\nNot found this sta\n");
11236 	}
11237 	wrqu->data.length = strlen(extra);
11238 
11239 exit:
11240 #endif /* CONFIG_TDLS */
11241 	return ret;
11242 
11243 }
11244 
11245 static int rtw_tdls_get_best_ch(struct net_device *dev,
11246 				struct iw_request_info *info,
11247 				union iwreq_data *wrqu, char *extra)
11248 {
11249 #ifdef CONFIG_FIND_BEST_CHANNEL
11250 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
11251 	struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
11252 	u32 i, best_channel_24G = 1, best_channel_5G = 36, index_24G = 0, index_5G = 0;
11253 
11254 	for (i = 0; i < rfctl->max_chan_nums && rfctl->channel_set[i].ChannelNum != 0; i++) {
11255 		if (rfctl->channel_set[i].ChannelNum == 1)
11256 			index_24G = i;
11257 		if (rfctl->channel_set[i].ChannelNum == 36)
11258 			index_5G = i;
11259 	}
11260 
11261 	for (i = 0; i < rfctl->max_chan_nums && rfctl->channel_set[i].ChannelNum != 0; i++) {
11262 		/* 2.4G */
11263 		if (rfctl->channel_set[i].ChannelNum == 6 || rfctl->channel_set[i].ChannelNum == 11) {
11264 			if (rfctl->channel_set[i].rx_count < rfctl->channel_set[index_24G].rx_count) {
11265 				index_24G = i;
11266 				best_channel_24G = rfctl->channel_set[i].ChannelNum;
11267 			}
11268 		}
11269 
11270 		/* 5G */
11271 		if (rfctl->channel_set[i].ChannelNum >= 36
11272 		    && rfctl->channel_set[i].ChannelNum < 140) {
11273 			/* Find primary channel */
11274 			if (((rfctl->channel_set[i].ChannelNum - 36) % 8 == 0)
11275 			    && (rfctl->channel_set[i].rx_count < rfctl->channel_set[index_5G].rx_count)) {
11276 				index_5G = i;
11277 				best_channel_5G = rfctl->channel_set[i].ChannelNum;
11278 			}
11279 		}
11280 
11281 		if (rfctl->channel_set[i].ChannelNum >= 149
11282 		    && rfctl->channel_set[i].ChannelNum < 165) {
11283 			/* Find primary channel */
11284 			if (((rfctl->channel_set[i].ChannelNum - 149) % 8 == 0)
11285 			    && (rfctl->channel_set[i].rx_count < rfctl->channel_set[index_5G].rx_count)) {
11286 				index_5G = i;
11287 				best_channel_5G = rfctl->channel_set[i].ChannelNum;
11288 			}
11289 		}
11290 #if 1 /* debug */
11291 		RTW_INFO("The rx cnt of channel %3d = %d\n",
11292 			 rfctl->channel_set[i].ChannelNum,
11293 			 rfctl->channel_set[i].rx_count);
11294 #endif
11295 	}
11296 
11297 	sprintf(extra, "\nbest_channel_24G = %d\n", best_channel_24G);
11298 	RTW_INFO("best_channel_24G = %d\n", best_channel_24G);
11299 
11300 	if (index_5G != 0) {
11301 		sprintf(extra, "best_channel_5G = %d\n", best_channel_5G);
11302 		RTW_INFO("best_channel_5G = %d\n", best_channel_5G);
11303 	}
11304 
11305 	wrqu->data.length = strlen(extra);
11306 
11307 #endif
11308 
11309 	return 0;
11310 
11311 }
11312 #endif /*#ifdef CONFIG_TDLS*/
11313 static int rtw_tdls(struct net_device *dev,
11314 		    struct iw_request_info *info,
11315 		    union iwreq_data *wrqu, char *extra)
11316 {
11317 	int ret = 0;
11318 
11319 #ifdef CONFIG_TDLS
11320 
11321 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
11322 
11323 	RTW_INFO("[%s] extra = %s\n", __FUNCTION__, extra);
11324 
11325 	if (hal_chk_wl_func(padapter, WL_FUNC_TDLS) == _FALSE) {
11326 		RTW_INFO("Discard tdls oper since hal doesn't support tdls\n");
11327 		return 0;
11328 	}
11329 
11330 	if (rtw_is_tdls_enabled(padapter) == _FALSE) {
11331 		RTW_INFO("TDLS is not enabled\n");
11332 		return 0;
11333 	}
11334 
11335 	/* WFD Sigma will use the tdls enable command to let the driver know we want to test the tdls now! */
11336 
11337 	if (hal_chk_wl_func(padapter, WL_FUNC_MIRACAST)) {
11338 		if (_rtw_memcmp(extra, "wfdenable=", 10)) {
11339 			wrqu->data.length -= 10;
11340 			rtw_wx_tdls_wfd_enable(dev, info, wrqu, &extra[10]);
11341 			return ret;
11342 		}
11343 	}
11344 
11345 	if (_rtw_memcmp(extra, "weaksec=", 8)) {
11346 		wrqu->data.length -= 8;
11347 		rtw_tdls_weaksec(dev, info, wrqu, &extra[8]);
11348 		return ret;
11349 	} else if (_rtw_memcmp(extra, "tdlsenable=", 11)) {
11350 		wrqu->data.length -= 11;
11351 		rtw_tdls_enable(dev, info, wrqu, &extra[11]);
11352 		return ret;
11353 	}
11354 
11355 	if (_rtw_memcmp(extra, "setup=", 6)) {
11356 		wrqu->data.length -= 6;
11357 		rtw_tdls_setup(dev, info, wrqu, &extra[6]);
11358 	} else if (_rtw_memcmp(extra, "tear=", 5)) {
11359 		wrqu->data.length -= 5;
11360 		rtw_tdls_teardown(dev, info, wrqu, &extra[5]);
11361 	} else if (_rtw_memcmp(extra, "dis=", 4)) {
11362 		wrqu->data.length -= 4;
11363 		rtw_tdls_discovery(dev, info, wrqu, &extra[4]);
11364 	} else if (_rtw_memcmp(extra, "swoff=", 6)) {
11365 		wrqu->data.length -= 6;
11366 		rtw_tdls_ch_switch_off(dev, info, wrqu, &extra[6]);
11367 	} else if (_rtw_memcmp(extra, "sw=", 3)) {
11368 		wrqu->data.length -= 3;
11369 		rtw_tdls_ch_switch(dev, info, wrqu, &extra[3]);
11370 	} else if (_rtw_memcmp(extra, "dumpstack=", 10)) {
11371 		wrqu->data.length -= 10;
11372 		rtw_tdls_dump_ch(dev, info, wrqu, &extra[10]);
11373 	} else if (_rtw_memcmp(extra, "offchnum=", 9)) {
11374 		wrqu->data.length -= 9;
11375 		rtw_tdls_off_ch_num(dev, info, wrqu, &extra[9]);
11376 	} else if (_rtw_memcmp(extra, "choffset=", 9)) {
11377 		wrqu->data.length -= 9;
11378 		rtw_tdls_ch_offset(dev, info, wrqu, &extra[9]);
11379 	} else if (_rtw_memcmp(extra, "pson=", 5)) {
11380 		wrqu->data.length -= 5;
11381 		rtw_tdls_pson(dev, info, wrqu, &extra[5]);
11382 	} else if (_rtw_memcmp(extra, "psoff=", 6)) {
11383 		wrqu->data.length -= 6;
11384 		rtw_tdls_psoff(dev, info, wrqu, &extra[6]);
11385 	}
11386 
11387 #ifdef CONFIG_WFD
11388 	if (hal_chk_wl_func(padapter, WL_FUNC_MIRACAST)) {
11389 		if (_rtw_memcmp(extra, "setip=", 6)) {
11390 			wrqu->data.length -= 6;
11391 			rtw_tdls_setip(dev, info, wrqu, &extra[6]);
11392 		} else if (_rtw_memcmp(extra, "tprobe=", 6))
11393 			issue_tunneled_probe_req((_adapter *)rtw_netdev_priv(dev));
11394 	}
11395 #endif /* CONFIG_WFD */
11396 
11397 #endif /* CONFIG_TDLS */
11398 
11399 	return ret;
11400 }
11401 
11402 
11403 static int rtw_tdls_get(struct net_device *dev,
11404 			struct iw_request_info *info,
11405 			union iwreq_data *wrqu, char *extra)
11406 {
11407 	int ret = 0;
11408 
11409 #ifdef CONFIG_TDLS
11410 
11411 	RTW_INFO("[%s] extra = %s\n", __FUNCTION__, (char *) wrqu->data.pointer);
11412 
11413 	if (_rtw_memcmp(wrqu->data.pointer, "ip", 2))
11414 		rtw_tdls_getip(dev, info, wrqu, extra);
11415 	else if (_rtw_memcmp(wrqu->data.pointer, "port", 4))
11416 		rtw_tdls_getport(dev, info, wrqu, extra);
11417 	/* WFDTDLS, for sigma test */
11418 	else if (_rtw_memcmp(wrqu->data.pointer, "dis", 3))
11419 		rtw_tdls_dis_result(dev, info, wrqu, extra);
11420 	else if (_rtw_memcmp(wrqu->data.pointer, "status", 6))
11421 		rtw_wfd_tdls_status(dev, info, wrqu, extra);
11422 	else if (_rtw_memcmp(wrqu->data.pointer, "tdls_sta=", 9))
11423 		rtw_tdls_getsta(dev, info, wrqu, extra);
11424 	else if (_rtw_memcmp(wrqu->data.pointer, "best_ch", 7))
11425 		rtw_tdls_get_best_ch(dev, info, wrqu, extra);
11426 #endif /* CONFIG_TDLS */
11427 
11428 	return ret;
11429 }
11430 
11431 #ifdef CONFIG_MAC_LOOPBACK_DRIVER
11432 
11433 #if defined(CONFIG_RTL8188E)
11434 #include <rtl8188e_hal.h>
11435 extern void rtl8188e_cal_txdesc_chksum(struct tx_desc *ptxdesc);
11436 #define cal_txdesc_chksum(padapter, desc) rtl8188e_cal_txdesc_chksum(desc)
11437 #ifdef CONFIG_SDIO_HCI || defined(CONFIG_GSPI_HCI)
11438 extern void rtl8188es_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf);
11439 #define fill_default_txdesc rtl8188es_fill_default_txdesc
11440 #endif /* CONFIG_SDIO_HCI */
11441 #endif /* CONFIG_RTL8188E */
11442 #if defined(CONFIG_RTL8723B)
11443 extern void rtl8723b_cal_txdesc_chksum(struct tx_desc *ptxdesc);
11444 #define cal_txdesc_chksum(padapter, desc) rtl8723b_cal_txdesc_chksum(desc)
11445 extern void rtl8723b_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf);
11446 #define fill_default_txdesc rtl8723b_fill_default_txdesc
11447 #endif /* CONFIG_RTL8723B */
11448 
11449 #if defined(CONFIG_RTL8703B)
11450 /* extern void rtl8703b_cal_txdesc_chksum(struct tx_desc *ptxdesc); */
11451 #define cal_txdesc_chksum(padapter, desc) rtl8703b_cal_txdesc_chksum(desc)
11452 /* extern void rtl8703b_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf); */
11453 #define fill_default_txdesc rtl8703b_fill_default_txdesc
11454 #endif /* CONFIG_RTL8703B */
11455 
11456 #if defined(CONFIG_RTL8723D)
11457 /* extern void rtl8723d_cal_txdesc_chksum(struct tx_desc *ptxdesc); */
11458 #define cal_txdesc_chksum(padapter, desc) rtl8723d_cal_txdesc_chksum(desc)
11459 /* extern void rtl8723d_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf); */
11460 #define fill_default_txdesc rtl8723d_fill_default_txdesc
11461 #endif /* CONFIG_RTL8723D */
11462 
11463 #if defined(CONFIG_RTL8710B)
11464 #define cal_txdesc_chksum(padapter, desc) rtl8710b_cal_txdesc_chksum(desc)
11465 #define fill_default_txdesc rtl8710b_fill_default_txdesc
11466 #endif /* CONFIG_RTL8710B */
11467 
11468 #if defined(CONFIG_RTL8192E)
11469 extern void rtl8192e_cal_txdesc_chksum(struct tx_desc *ptxdesc);
11470 #define cal_txdesc_chksum(padapter, desc) rtl8192e_cal_txdesc_chksum(desc)
11471 #ifdef CONFIG_SDIO_HCI || defined(CONFIG_GSPI_HCI)
11472 extern void rtl8192es_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf);
11473 #define fill_default_txdesc rtl8192es_fill_default_txdesc
11474 #endif /* CONFIG_SDIO_HCI */
11475 #endif /* CONFIG_RTL8192E */
11476 
11477 #if defined(CONFIG_RTL8192F)
11478 /* extern void rtl8192f_cal_txdesc_chksum(struct tx_desc *ptxdesc); */
11479 #define cal_txdesc_chksum(padapter, desc) rtl8192f_cal_txdesc_chksum(desc)
11480 /* extern void rtl8192f_fill_default_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf); */
11481 #define fill_default_txdesc rtl8192f_fill_default_txdesc
11482 #endif /* CONFIG_RTL8192F */
11483 
11484 #ifdef CONFIG_RTL8723F
11485 #include <../../hal/rtl8723f/rtl8723f.h>
11486 
11487 #define REG_LOOPBACK_ENABLE 0x0103
11488 #define LOOKBACK_ENABLE_VALUE 0x0b
11489 #define cal_txdesc_chksum(padapter, desc) rtl8723f_cal_txdesc_chksum(padapter, desc)
11490 #define dump_txdesc_data(padapter, desc) rtl8723f_dbg_dump_tx_desc(padapter, DATA_FRAMETAG, desc);
11491 #define get_rx_desc(rx_desc, rxbuf) rtl8723f_rxdesc2attribute(rx_desc, rxbuf)
11492 #define hal_init rtl8723f_hal_init
11493 #endif /* CONFIG_RTL8723F */
11494 
11495 void dbg_dump_pkt(char *s, u8 *buf, u8 len)
11496 {
11497 	u8 i, j = 1;
11498 
11499 	RTW_INFO("%s size = %u\n", s, len);
11500 
11501 	for (i = 0; (i + 4) < len; i += 4) {
11502 		if (j % 4 == 1)
11503 			RTW_PRINT("idx:%u:", i);
11504 		_RTW_PRINT(" 0x%02x 0x%02x 0x%02x 0x%02x", buf[i], buf[i+1], buf[i+2], buf[i+3]);
11505 		if ((j++) % 4 == 0)
11506 			_RTW_PRINT("\n");
11507 	}
11508 
11509 	for (; i < len ; i++) {
11510 		_RTW_PRINT(" 0x%02x", buf[i]);
11511 	}
11512 	_RTW_PRINT("\n ================================\n");
11513 }
11514 
11515 static s32 initLoopback(PADAPTER padapter)
11516 {
11517 	PLOOPBACKDATA ploopback;
11518 
11519 	if (padapter->ploopback == NULL) {
11520 		ploopback = (PLOOPBACKDATA)rtw_zmalloc(sizeof(LOOPBACKDATA));
11521 		if (ploopback == NULL)
11522 			return -ENOMEM;
11523 
11524 		_rtw_init_sema(&ploopback->sema, 0);
11525 		ploopback->bstop = _TRUE;
11526 		ploopback->cnt = 0;
11527 		ploopback->size = 300;
11528 		_rtw_memset(ploopback->msg, 0, sizeof(ploopback->msg));
11529 
11530 		padapter->ploopback = ploopback;
11531 	}
11532 
11533 	return 0;
11534 }
11535 
11536 static void freeLoopback(PADAPTER padapter)
11537 {
11538 	PLOOPBACKDATA ploopback;
11539 
11540 	ploopback = padapter->ploopback;
11541 	if (ploopback) {
11542 		rtw_mfree((u8 *)ploopback, sizeof(LOOPBACKDATA));
11543 		padapter->ploopback = NULL;
11544 	}
11545 }
11546 
11547 static s32 initpseudoadhoc(PADAPTER padapter)
11548 {
11549 	NDIS_802_11_NETWORK_INFRASTRUCTURE networkType;
11550 	s32 err;
11551 
11552 	networkType = Ndis802_11IBSS;
11553 	err = rtw_set_802_11_infrastructure_mode(padapter, networkType, 0);
11554 	if (err == _FALSE)
11555 		return _FAIL;
11556 
11557 	err = rtw_setopmode_cmd(padapter, networkType, RTW_CMDF_WAIT_ACK);
11558 	if (err == _FAIL)
11559 		return _FAIL;
11560 
11561 	return _SUCCESS;
11562 }
11563 
11564 static s32 createpseudoadhoc(PADAPTER padapter)
11565 {
11566 	NDIS_802_11_AUTHENTICATION_MODE authmode;
11567 	struct mlme_priv *pmlmepriv;
11568 	NDIS_802_11_SSID *passoc_ssid;
11569 	WLAN_BSSID_EX *pdev_network;
11570 	u8 *pibss;
11571 	u8 ssid[] = "pseduo_ad-hoc";
11572 	s32 err;
11573 	_irqL irqL;
11574 
11575 	pmlmepriv = &padapter->mlmepriv;
11576 
11577 	authmode = Ndis802_11AuthModeOpen;
11578 	err = rtw_set_802_11_authentication_mode(padapter, authmode);
11579 	if (err == _FALSE)
11580 		return _FAIL;
11581 
11582 	passoc_ssid = &pmlmepriv->assoc_ssid;
11583 	_rtw_memset(passoc_ssid, 0, sizeof(NDIS_802_11_SSID));
11584 	passoc_ssid->SsidLength = sizeof(ssid) - 1;
11585 	_rtw_memcpy(passoc_ssid->Ssid, ssid, passoc_ssid->SsidLength);
11586 
11587 	pdev_network = &padapter->registrypriv.dev_network;
11588 	pibss = padapter->registrypriv.dev_network.MacAddress;
11589 	_rtw_memcpy(&pdev_network->Ssid, passoc_ssid, sizeof(NDIS_802_11_SSID));
11590 
11591 	rtw_update_registrypriv_dev_network(padapter);
11592 	rtw_generate_random_ibss(pibss);
11593 
11594 	_enter_critical_bh(&pmlmepriv->lock, &irqL);
11595 	/*pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE;*/
11596 	init_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE);
11597 
11598 	_exit_critical_bh(&pmlmepriv->lock, &irqL);
11599 
11600 #if 0
11601 	err = rtw_create_ibss_cmd(padapter, 0);
11602 	if (err == _FAIL)
11603 		return _FAIL;
11604 #else
11605 	{
11606 		struct wlan_network *pcur_network;
11607 		struct sta_info *psta;
11608 
11609 		/* 3  create a new psta */
11610 		pcur_network = &pmlmepriv->cur_network;
11611 
11612 		/* clear psta in the cur_network, if any */
11613 		psta = rtw_get_stainfo(&padapter->stapriv, pcur_network->network.MacAddress);
11614 		if (psta)
11615 			rtw_free_stainfo(padapter, psta);
11616 
11617 		psta = rtw_alloc_stainfo(&padapter->stapriv, pibss);
11618 		if (psta == NULL)
11619 			return _FAIL;
11620 
11621 		/* 3  join psudo AdHoc */
11622 		pcur_network->join_res = 1;
11623 		pcur_network->aid = psta->cmn.aid = 1;
11624 		_rtw_memcpy(&pcur_network->network, pdev_network, get_WLAN_BSSID_EX_sz(pdev_network));
11625 
11626 		/* set msr to WIFI_FW_ADHOC_STATE */
11627 		padapter->hw_port = HW_PORT0;
11628 		Set_MSR(padapter, WIFI_FW_ADHOC_STATE);
11629 
11630 	}
11631 #endif
11632 
11633 	return _SUCCESS;
11634 }
11635 
11636 static struct xmit_frame *createloopbackpkt(PADAPTER padapter, u32 size)
11637 {
11638 	struct xmit_priv *pxmitpriv;
11639 	struct xmit_frame *pframe;
11640 	struct xmit_buf *pxmitbuf;
11641 	struct pkt_attrib *pattrib;
11642 	struct tx_desc *desc;
11643 	u8 *pkt_start, *pkt_end, *ptr;
11644 	struct rtw_ieee80211_hdr *hdr;
11645 	s32 bmcast;
11646 	_irqL irqL;
11647 
11648 
11649 	if ((TXDESC_SIZE + WLANHDR_OFFSET + size) > MAX_XMITBUF_SZ)
11650 		return NULL;
11651 
11652 	pxmitpriv = &padapter->xmitpriv;
11653 	pframe = NULL;
11654 
11655 	/* 2 1. allocate xmit frame */
11656 	pframe = rtw_alloc_xmitframe(pxmitpriv, 0);
11657 	if (pframe == NULL)
11658 		return NULL;
11659 	pframe->padapter = padapter;
11660 
11661 	/* 2 2. allocate xmit buffer */
11662 	_enter_critical_bh(&pxmitpriv->lock, &irqL);
11663 	pxmitbuf = rtw_alloc_xmitbuf(pxmitpriv);
11664 	_exit_critical_bh(&pxmitpriv->lock, &irqL);
11665 	if (pxmitbuf == NULL) {
11666 		rtw_free_xmitframe(pxmitpriv, pframe);
11667 		return NULL;
11668 	}
11669 
11670 	pframe->pxmitbuf = pxmitbuf;
11671 	pframe->buf_addr = pxmitbuf->pbuf;
11672 	pxmitbuf->priv_data = pframe;
11673 
11674 	/* 2 3. update_attrib() */
11675 	pattrib = &pframe->attrib;
11676 
11677 	/* init xmitframe attribute */
11678 	_rtw_memset(pattrib, 0, sizeof(struct pkt_attrib));
11679 
11680 	pattrib->ether_type = 0x8723;
11681 	_rtw_memcpy(pattrib->src, adapter_mac_addr(padapter), ETH_ALEN);
11682 	_rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
11683 	_rtw_memset(pattrib->dst, 0xFF, ETH_ALEN);
11684 	_rtw_memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
11685 
11686 	/*	pattrib->dhcp_pkt = 0;
11687 	 *	pattrib->pktlen = 0; */
11688 	pattrib->ack_policy = 0;
11689 	/*	pattrib->pkt_hdrlen = ETH_HLEN; */
11690 	pattrib->hdrlen = WLAN_HDR_A3_LEN;
11691 	pattrib->subtype = WIFI_DATA;
11692 	pattrib->priority = 0;
11693 	pattrib->qsel = pattrib->priority;
11694 	/*	do_queue_select(padapter, pattrib); */
11695 	pattrib->nr_frags = 1;
11696 	pattrib->encrypt = 0;
11697 	pattrib->bswenc = _FALSE;
11698 	pattrib->qos_en = _FALSE;
11699 
11700 	bmcast = IS_MCAST(pattrib->ra);
11701 	if (bmcast)
11702 		pattrib->psta = rtw_get_bcmc_stainfo(padapter);
11703 	else
11704 		pattrib->psta = rtw_get_stainfo(&padapter->stapriv, get_bssid(&padapter->mlmepriv));
11705 
11706 	pattrib->mac_id = pattrib->psta->cmn.mac_id;
11707 	pattrib->pktlen = size;
11708 	pattrib->last_txcmdsz = pattrib->hdrlen + pattrib->pktlen;
11709 
11710 	/* 2 4. fill TX descriptor */
11711 	desc = (struct tx_desc *)pframe->buf_addr;
11712 	_rtw_memset(desc, 0, TXDESC_SIZE);
11713 
11714 	fill_default_txdesc(pframe, (u8 *)desc);
11715 
11716 #if 0
11717 	/* Hw set sequence number */
11718 	((PTXDESC)desc)->hwseq_en = 0; /* HWSEQ_EN, 0:disable, 1:enable
11719  * ((PTXDESC)desc)->hwseq_sel = 0;  */ /* HWSEQ_SEL */
11720 
11721 	((PTXDESC)desc)->disdatafb = 1;
11722 
11723 	/* convert to little endian */
11724 	desc->txdw0 = cpu_to_le32(desc->txdw0);
11725 	desc->txdw1 = cpu_to_le32(desc->txdw1);
11726 	desc->txdw2 = cpu_to_le32(desc->txdw2);
11727 	desc->txdw3 = cpu_to_le32(desc->txdw3);
11728 	desc->txdw4 = cpu_to_le32(desc->txdw4);
11729 	desc->txdw5 = cpu_to_le32(desc->txdw5);
11730 	desc->txdw6 = cpu_to_le32(desc->txdw6);
11731 	desc->txdw7 = cpu_to_le32(desc->txdw7);
11732 #ifdef CONFIG_PCI_HCI
11733 	desc->txdw8 = cpu_to_le32(desc->txdw8);
11734 	desc->txdw9 = cpu_to_le32(desc->txdw9);
11735 	desc->txdw10 = cpu_to_le32(desc->txdw10);
11736 	desc->txdw11 = cpu_to_le32(desc->txdw11);
11737 	desc->txdw12 = cpu_to_le32(desc->txdw12);
11738 	desc->txdw13 = cpu_to_le32(desc->txdw13);
11739 	desc->txdw14 = cpu_to_le32(desc->txdw14);
11740 	desc->txdw15 = cpu_to_le32(desc->txdw15);
11741 #endif
11742 #endif
11743 
11744 	cal_txdesc_chksum(padapter, (u8*)desc);
11745 	/* dump_txdesc_data(padapter, (u8*)desc); */
11746 
11747 	/* 2 5. coalesce */
11748 	pkt_start = pframe->buf_addr + TXDESC_SIZE;
11749 	pkt_end = pkt_start + pattrib->last_txcmdsz;
11750 
11751 	/* 3 5.1. make wlan header, make_wlanhdr() */
11752 	hdr = (struct rtw_ieee80211_hdr *)pkt_start;
11753 	set_frame_sub_type(&hdr->frame_ctl, pattrib->subtype);
11754 	_rtw_memcpy(hdr->addr1, pattrib->dst, ETH_ALEN); /* DA */
11755 	_rtw_memcpy(hdr->addr2, pattrib->src, ETH_ALEN); /* SA */
11756 	_rtw_memcpy(hdr->addr3, get_bssid(&padapter->mlmepriv), ETH_ALEN); /* RA, BSSID */
11757 
11758 	/* 3 5.2. make payload */
11759 	ptr = pkt_start + pattrib->hdrlen;
11760 	get_random_bytes(ptr, pkt_end - ptr);
11761 
11762 	pxmitbuf->len = TXDESC_SIZE + pattrib->last_txcmdsz;
11763 #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
11764 	pxmitbuf->ptail += pxmitbuf->len;
11765 #endif
11766 
11767 	dbg_dump_pkt("TX packet", pxmitbuf->pbuf, pxmitbuf->len);
11768 
11769 	return pframe;
11770 }
11771 
11772 static void freeloopbackpkt(PADAPTER padapter, struct xmit_frame *pframe)
11773 {
11774 	struct xmit_priv *pxmitpriv;
11775 	struct xmit_buf *pxmitbuf;
11776 
11777 	pxmitpriv = &padapter->xmitpriv;
11778 	pxmitbuf = pframe->pxmitbuf;
11779 
11780 	rtw_free_xmitframe(pxmitpriv, pframe);
11781 	rtw_free_xmitbuf(pxmitpriv, pxmitbuf);
11782 }
11783 
11784 static void printdata(u8 *pbuf, u32 len)
11785 {
11786 	u32 i, val;
11787 
11788 	for (i = 0; (i + 4) <= len; i += 4) {
11789 		printk("%08X", *(u32 *)(pbuf + i));
11790 		if ((i + 4) & 0x1F)
11791 			printk(" ");
11792 		else
11793 			printk("\n");
11794 	}
11795 
11796 	if (i < len) {
11797 #ifdef CONFIG_BIG_ENDIAN
11798 		for (; i < len, i++)
11799 			printk("%02X", pbuf + i);
11800 #else /* CONFIG_LITTLE_ENDIAN */
11801 #if 0
11802 		val = 0;
11803 		_rtw_memcpy(&val, pbuf + i, len - i);
11804 		printk("%8X", val);
11805 #else
11806 		u8 str[9];
11807 		u8 n;
11808 		val = 0;
11809 		n = len - i;
11810 		_rtw_memcpy(&val, pbuf + i, n);
11811 		sprintf(str, "%08X", val);
11812 		n = (4 - n) * 2;
11813 		printk("%8s", str + n);
11814 #endif
11815 #endif /* CONFIG_LITTLE_ENDIAN */
11816 	}
11817 	printk("\n");
11818 }
11819 
11820 static u8 pktcmp(PADAPTER padapter, u8 *txbuf, u32 txsz, u8 *rxbuf, u32 rxsz)
11821 {
11822 	struct rx_pkt_attrib rx_desc;
11823 #if 0
11824 	struct recv_stat *prxstat;
11825 	struct recv_stat report;
11826 	PRXREPORT prxreport;
11827 #endif
11828 	u32 rxpktsize;
11829 	u8 drvinfosize;
11830 	u8 shiftsize;
11831 	u8 ret = _FALSE;
11832 	u8 skip_len = 4; /* Don't compare the frame control and duration field */
11833 	get_rx_desc(&rx_desc, rxbuf);
11834 	rxpktsize = rx_desc.pkt_len;
11835 	drvinfosize = rx_desc.drvinfo_sz;
11836 	shiftsize = rx_desc.shift_sz;
11837 
11838 #if 0
11839 	prxstat = (struct recv_stat *)rxbuf;
11840 	report.rxdw0 = le32_to_cpu(prxstat->rxdw0);
11841 	report.rxdw1 = le32_to_cpu(prxstat->rxdw1);
11842 	report.rxdw2 = le32_to_cpu(prxstat->rxdw2);
11843 	report.rxdw3 = le32_to_cpu(prxstat->rxdw3);
11844 	report.rxdw4 = le32_to_cpu(prxstat->rxdw4);
11845 	report.rxdw5 = le32_to_cpu(prxstat->rxdw5);
11846 
11847 	prxreport = (PRXREPORT)&report;
11848 	drvinfosize = prxreport->drvinfosize << 3;
11849 	rxpktsize = prxreport->pktlen;
11850 #endif
11851 
11852 	if (rtw_hal_rcr_check(padapter, RCR_APPFCS))
11853 		rxpktsize -= IEEE80211_FCS_LEN;
11854 
11855 	if ((txsz - TXDESC_SIZE) != rxpktsize) {
11856 		RTW_INFO("%s: ERROR! size not match tx/rx=%d/%d !\n",
11857 			 __func__, txsz - TXDESC_SIZE, rxpktsize);
11858 		ret = _FALSE;
11859 	} else {
11860 		ret = _rtw_memcmp(txbuf + TXDESC_SIZE + skip_len, \
11861 				  rxbuf + RXDESC_SIZE + skip_len + drvinfosize, \
11862 				  txsz - TXDESC_SIZE - skip_len);
11863 		if (ret == _FALSE)
11864 			RTW_INFO("%s: ERROR! pkt content mismatch!\n", __func__);
11865 	}
11866 
11867 	if (ret == _FALSE) {
11868 		RTW_INFO("\n%s: TX PKT total=%d, desc=%d, content=%d\n",
11869 			 __func__, txsz, TXDESC_SIZE, txsz - TXDESC_SIZE);
11870 		dbg_dump_pkt("TX DESC", txbuf, TXDESC_SIZE);
11871 		dbg_dump_pkt("TX content", txbuf + TXDESC_SIZE, txsz - TXDESC_SIZE);
11872 
11873 		RTW_INFO("\n%s: RX PKT read=%d offset=%d(%d,%d) content=%d\n",
11874 			__func__, rxsz, RXDESC_SIZE + drvinfosize, RXDESC_SIZE, drvinfosize, rxpktsize);
11875 		if (rxpktsize != 0) {
11876 			dbg_dump_pkt("RX DESC", rxbuf, RXDESC_SIZE);
11877 			dbg_dump_pkt("RX drvinfo", rxbuf + RXDESC_SIZE, drvinfosize);
11878 			dbg_dump_pkt("RX packet content", rxbuf + RXDESC_SIZE + drvinfosize, rxpktsize);
11879 		} else {
11880 			RTW_INFO("%s: RX data size=%d\n", __func__, rxsz);
11881 		}
11882 	}
11883 
11884 	return ret;
11885 }
11886 
11887 thread_return lbk_thread(thread_context context)
11888 {
11889 	s32 err;
11890 	PADAPTER padapter;
11891 	PLOOPBACKDATA ploopback;
11892 	struct xmit_frame *pxmitframe;
11893 	u32 cnt, ok, fail, headerlen;
11894 	u32 pktsize;
11895 	u32 ff_hwaddr;
11896 
11897 	padapter = (PADAPTER)context;
11898 	ploopback = padapter->ploopback;
11899 	if (ploopback == NULL)
11900 		return -1;
11901 	cnt = 0;
11902 	ok = 0;
11903 	fail = 0;
11904 
11905 	thread_enter("RTW_LBK_THREAD");
11906 	/* daemonize("%s", "RTW_LBK_THREAD"); */
11907 	allow_signal(SIGTERM);
11908 
11909 	do {
11910 		if (ploopback->size == 0) {
11911 			get_random_bytes(&pktsize, 4);
11912 			pktsize = (pktsize % 1535) + 1; /* 1~1535 */
11913 		} else
11914 			pktsize = ploopback->size;
11915 
11916 		pxmitframe = createloopbackpkt(padapter, pktsize);
11917 		if (pxmitframe == NULL) {
11918 			sprintf(ploopback->msg, "loopback FAIL! 3. create Packet FAIL!");
11919 			break;
11920 		}
11921 
11922 		ploopback->txsize = TXDESC_SIZE + pxmitframe->attrib.last_txcmdsz;
11923 		_rtw_memcpy(ploopback->txbuf, pxmitframe->buf_addr, ploopback->txsize);
11924 		ff_hwaddr = rtw_get_ff_hwaddr(pxmitframe);
11925 		cnt++;
11926 		RTW_INFO("%s: wirte port cnt=%d size=%d\n", __func__, cnt, ploopback->txsize);
11927 #if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
11928 		pxmitframe->pxmitbuf->pdata = ploopback->txbuf;
11929 #endif
11930 		rtw_write_port(padapter, ff_hwaddr, ploopback->txsize, (u8 *)pxmitframe->pxmitbuf);
11931 
11932 		/* wait for rx pkt */
11933 		RTW_INFO("%s: wait for rx packet\n", __func__);
11934 		_rtw_down_sema(&ploopback->sema);
11935 
11936 		err = pktcmp(padapter, ploopback->txbuf, ploopback->txsize, ploopback->rxbuf, ploopback->rxsize);
11937 		if (err == _TRUE)
11938 			ok++;
11939 		else
11940 			fail++;
11941 
11942 		ploopback->txsize = 0;
11943 		_rtw_memset(ploopback->txbuf, 0, 0x8000);
11944 		ploopback->rxsize = 0;
11945 		_rtw_memset(ploopback->rxbuf, 0, 0x8000);
11946 
11947 		freeloopbackpkt(padapter, pxmitframe);
11948 		pxmitframe = NULL;
11949 
11950 		flush_signals_thread();
11951 
11952 		if ((ploopback->bstop == _TRUE) ||
11953 		    ((ploopback->cnt != 0) && (ploopback->cnt == cnt))) {
11954 			u32 ok_rate, fail_rate, all;
11955 			all = cnt;
11956 			ok_rate = (ok * 100) / all;
11957 			fail_rate = (fail * 100) / all;
11958 			sprintf(ploopback->msg, \
11959 				"loopback result: ok=%d%%(%d/%d),error=%d%%(%d/%d)", \
11960 				ok_rate, ok, all, fail_rate, fail, all);
11961 			break;
11962 		}
11963 	} while (1);
11964 
11965 	ploopback->bstop = _TRUE;
11966 
11967 	thread_exit(NULL);
11968 	return 0;
11969 }
11970 
11971 static void loopbackTest(PADAPTER padapter, u32 cnt, u32 size, u8 *pmsg)
11972 {
11973 	PLOOPBACKDATA ploopback;
11974 	u32 len;
11975 	s32 err;
11976 
11977 	ploopback = padapter->ploopback;
11978 
11979 	if (ploopback) {
11980 		if (ploopback->bstop == _FALSE) {
11981 			ploopback->bstop = _TRUE;
11982 			_rtw_up_sema(&ploopback->sema);
11983 		}
11984 		len = 0;
11985 		do {
11986 			len = strlen(ploopback->msg);
11987 			if (len)
11988 				break;
11989 			rtw_msleep_os(1);
11990 		} while (1);
11991 		RTW_INFO("Free loopback, end the test.\n");
11992 		_rtw_memcpy(pmsg, ploopback->msg, len + 1);
11993 		freeLoopback(padapter);
11994 
11995 		return;
11996 	}
11997 
11998 	/* disable dynamic algorithm	 */
11999 #ifndef CONFIG_NO_PHYDM
12000 	rtw_phydm_ability_backup(padapter);
12001 	rtw_phydm_func_disable_all(padapter);
12002 #endif
12003 
12004 	/* create pseudo ad-hoc connection */
12005 	err = initpseudoadhoc(padapter);
12006 	if (err == _FAIL) {
12007 		sprintf(pmsg, "loopback FAIL! 1.1 init ad-hoc FAIL!");
12008 		return;
12009 	}
12010 
12011 	err = createpseudoadhoc(padapter);
12012 	if (err == _FAIL) {
12013 		sprintf(pmsg, "loopback FAIL! 1.2 create ad-hoc master FAIL!");
12014 		return;
12015 	}
12016 
12017 	err = initLoopback(padapter);
12018 	if (err) {
12019 		sprintf(pmsg, "loopback FAIL! 2. init FAIL! error code=%d", err);
12020 		return;
12021 	}
12022 
12023 	ploopback = padapter->ploopback;
12024 
12025 	ploopback->bstop = _FALSE;
12026 	ploopback->cnt = cnt;
12027 	ploopback->size = size;
12028 	ploopback->lbkthread = kthread_run(lbk_thread, padapter, "RTW_LBK_THREAD");
12029 	if (IS_ERR(ploopback->lbkthread)) {
12030 		freeLoopback(padapter);
12031 		ploopback->lbkthread = NULL;
12032 		sprintf(pmsg, "loopback start FAIL! cnt=%d", cnt);
12033 		return;
12034 	}
12035 
12036 	sprintf(pmsg, "loopback start! cnt=%d", cnt);
12037 }
12038 #endif /* CONFIG_MAC_LOOPBACK_DRIVER */
12039 
12040 static int rtw_test(
12041 	struct net_device *dev,
12042 	struct iw_request_info *info,
12043 	union iwreq_data *wrqu, char *extra)
12044 {
12045 	u32 len;
12046 	u8 *pbuf, *pch;
12047 	char *ptmp;
12048 	u8 *delim = ",";
12049 	PADAPTER padapter = rtw_netdev_priv(dev);
12050 
12051 
12052 	RTW_INFO("+%s\n", __func__);
12053 	len = wrqu->data.length;
12054 
12055 	pbuf = (u8 *)rtw_zmalloc(len + 1);
12056 	if (pbuf == NULL) {
12057 		RTW_INFO("%s: no memory!\n", __func__);
12058 		return -ENOMEM;
12059 	}
12060 
12061 	if (copy_from_user(pbuf, wrqu->data.pointer, len)) {
12062 		rtw_mfree(pbuf, len + 1);
12063 		RTW_INFO("%s: copy from user fail!\n", __func__);
12064 		return -EFAULT;
12065 	}
12066 
12067 	pbuf[len] = '\0';
12068 
12069 	RTW_INFO("%s: string=\"%s\"\n", __func__, pbuf);
12070 
12071 	ptmp = (char *)pbuf;
12072 	pch = strsep(&ptmp, delim);
12073 	if ((pch == NULL) || (strlen(pch) == 0)) {
12074 		rtw_mfree(pbuf, len);
12075 		RTW_INFO("%s: parameter error(level 1)!\n", __func__);
12076 		return -EFAULT;
12077 	}
12078 
12079 #ifdef CONFIG_MAC_LOOPBACK_DRIVER
12080 	if (strcmp(pch, "init") == 0) {
12081 		u8 status;
12082 
12083 		rtw_clr_drv_stopped(padapter); /* should clear drv_stopped, otherwise driver can't trx */
12084 
12085 		status = hal_init(padapter);
12086 		RTW_INFO("HAL_INIT %s\n", status ? "SUCCESS" : "FAIL");
12087 
12088 		rtw_write8(padapter, REG_LOOPBACK_ENABLE, LOOKBACK_ENABLE_VALUE);
12089 		RTW_INFO("Write 0x%03x to 0x%02x, enable loopback\n",
12090 			REG_LOOPBACK_ENABLE, LOOKBACK_ENABLE_VALUE);
12091 
12092 	} else if (strcmp(pch, "loopback") == 0) {
12093 		s32 cnt = 0;
12094 		u32 size = 64;
12095 
12096 		pch = strsep(&ptmp, delim);
12097 		if ((pch == NULL) || (strlen(pch) == 0)) {
12098 			rtw_mfree(pbuf, len);
12099 			RTW_INFO("%s: parameter error(level 2)!\n", __func__);
12100 			return -EFAULT;
12101 		}
12102 
12103 		sscanf(pch, "%d", &cnt);
12104 		RTW_INFO("%s: loopback cnt=%d\n", __func__, cnt);
12105 
12106 		pch = strsep(&ptmp, delim);
12107 		if ((pch == NULL) || (strlen(pch) == 0)) {
12108 			rtw_mfree(pbuf, len);
12109 			RTW_INFO("%s: parameter error(level 2)!\n", __func__);
12110 			return -EFAULT;
12111 		}
12112 
12113 		sscanf(pch, "%d", &size);
12114 		RTW_INFO("%s: loopback size=%d\n", __func__, size);
12115 
12116 		loopbackTest(padapter, cnt, size, extra);
12117 		wrqu->data.length = strlen(extra) + 1;
12118 
12119 		goto free_buf;
12120 	}
12121 #endif
12122 
12123 
12124 #ifdef CONFIG_BT_COEXIST
12125 	if (strcmp(pch, "bton") == 0) {
12126 		rtw_btcoex_SetManualControl(padapter, _FALSE);
12127 		goto free_buf;
12128 	} else if (strcmp(pch, "btoff") == 0) {
12129 		rtw_btcoex_SetManualControl(padapter, _TRUE);
12130 		goto free_buf;
12131 	} else if (strcmp(pch, "coex_auto") == 0) {
12132 		rtw_btcoex_set_policy_control(padapter, BTCOEX_POLICY_CONTROL_AUTO);
12133 		goto free_buf;
12134 	} else if (strcmp(pch, "coex_force_freerun") == 0) {
12135 		rtw_btcoex_set_policy_control(padapter, BTCOEX_POLICY_CONTROL_FORCE_FREERUN);
12136 		goto free_buf;
12137 	} else if (strcmp(pch, "coex_force_tdma") == 0) {
12138 		rtw_btcoex_set_policy_control(padapter, BTCOEX_POLICY_CONTROL_FORCE_TDMA);
12139 		goto free_buf;
12140 	}
12141 #endif
12142 
12143 	if (strcmp(pch, "h2c") == 0) {
12144 		u8 param[8];
12145 		u8 count = 0;
12146 		u32 tmp;
12147 		u8 i;
12148 		u32 pos;
12149 		u8 ret;
12150 
12151 		do {
12152 			pch = strsep(&ptmp, delim);
12153 			if ((pch == NULL) || (strlen(pch) == 0))
12154 				break;
12155 
12156 			sscanf(pch, "%x", &tmp);
12157 			param[count++] = (u8)tmp;
12158 		} while (count < 8);
12159 
12160 		if (count == 0) {
12161 			rtw_mfree(pbuf, len);
12162 			RTW_INFO("%s: parameter error(level 2)!\n", __func__);
12163 			return -EFAULT;
12164 		}
12165 
12166 		ret = rtw_test_h2c_cmd(padapter, param, count);
12167 
12168 		pos = sprintf(extra, "H2C ID=0x%02x content=", param[0]);
12169 		for (i = 1; i < count; i++)
12170 			pos += sprintf(extra + pos, "%02x,", param[i]);
12171 		extra[pos] = 0;
12172 		pos--;
12173 		pos += sprintf(extra + pos, " %s", ret == _FAIL ? "FAIL" : "OK");
12174 
12175 		wrqu->data.length = strlen(extra) + 1;
12176 
12177 		goto free_buf;
12178 	}
12179 
12180 	if (strcmp(pch, "dump_mac_reg") == 0) {
12181 		mac_reg_dump(RTW_DBGDUMP, padapter);
12182 		goto free_buf;
12183 	}
12184 
12185 free_buf:
12186 	rtw_mfree(pbuf, len);
12187 	return 0;
12188 }
12189 
12190 static iw_handler rtw_handlers[] = {
12191 #ifdef CONFIG_IOCTL_WEXT
12192 	NULL,					/* SIOCSIWCOMMIT */
12193 	rtw_wx_get_name,		/* SIOCGIWNAME */
12194 	dummy,					/* SIOCSIWNWID */
12195 	dummy,					/* SIOCGIWNWID */
12196 	rtw_wx_set_freq,		/* SIOCSIWFREQ */
12197 	rtw_wx_get_freq,		/* SIOCGIWFREQ */
12198 	rtw_wx_set_mode,		/* SIOCSIWMODE */
12199 	rtw_wx_get_mode,		/* SIOCGIWMODE */
12200 	dummy,					/* SIOCSIWSENS */
12201 	rtw_wx_get_sens,		/* SIOCGIWSENS */
12202 	NULL,					/* SIOCSIWRANGE */
12203 	rtw_wx_get_range,		/* SIOCGIWRANGE */
12204 	rtw_wx_set_priv,		/* SIOCSIWPRIV */
12205 	NULL,					/* SIOCGIWPRIV */
12206 	NULL,					/* SIOCSIWSTATS */
12207 	NULL,					/* SIOCGIWSTATS */
12208 	dummy,					/* SIOCSIWSPY */
12209 	dummy,					/* SIOCGIWSPY */
12210 	NULL,					/* SIOCGIWTHRSPY */
12211 	NULL,					/* SIOCWIWTHRSPY */
12212 	rtw_wx_set_wap,		/* SIOCSIWAP */
12213 	rtw_wx_get_wap,		/* SIOCGIWAP */
12214 	rtw_wx_set_mlme,		/* request MLME operation; uses struct iw_mlme */
12215 	dummy,					/* SIOCGIWAPLIST -- depricated */
12216 	rtw_wx_set_scan,		/* SIOCSIWSCAN */
12217 	rtw_wx_get_scan,		/* SIOCGIWSCAN */
12218 	rtw_wx_set_essid,		/* SIOCSIWESSID */
12219 	rtw_wx_get_essid,		/* SIOCGIWESSID */
12220 	dummy,					/* SIOCSIWNICKN */
12221 	rtw_wx_get_nick,		/* SIOCGIWNICKN */
12222 	NULL,					/* -- hole -- */
12223 	NULL,					/* -- hole -- */
12224 	rtw_wx_set_rate,		/* SIOCSIWRATE */
12225 	rtw_wx_get_rate,		/* SIOCGIWRATE */
12226 	rtw_wx_set_rts,			/* SIOCSIWRTS */
12227 	rtw_wx_get_rts,			/* SIOCGIWRTS */
12228 	rtw_wx_set_frag,		/* SIOCSIWFRAG */
12229 	rtw_wx_get_frag,		/* SIOCGIWFRAG */
12230 	dummy,					/* SIOCSIWTXPOW */
12231 	dummy,					/* SIOCGIWTXPOW */
12232 	dummy,					/* SIOCSIWRETRY */
12233 	rtw_wx_get_retry,		/* SIOCGIWRETRY */
12234 	rtw_wx_set_enc,			/* SIOCSIWENCODE */
12235 	rtw_wx_get_enc,			/* SIOCGIWENCODE */
12236 	dummy,					/* SIOCSIWPOWER */
12237 	rtw_wx_get_power,		/* SIOCGIWPOWER */
12238 	NULL,					/*---hole---*/
12239 	NULL,					/*---hole---*/
12240 	rtw_wx_set_gen_ie,		/* SIOCSIWGENIE */
12241 	NULL,					/* SIOCGWGENIE */
12242 	rtw_wx_set_auth,		/* SIOCSIWAUTH */
12243 	NULL,					/* SIOCGIWAUTH */
12244 	rtw_wx_set_enc_ext,		/* SIOCSIWENCODEEXT */
12245 	NULL,					/* SIOCGIWENCODEEXT */
12246 	rtw_wx_set_pmkid,		/* SIOCSIWPMKSA */
12247 	NULL,					/*---hole---*/
12248 #endif
12249 };
12250 
12251 
12252 static const struct iw_priv_args rtw_private_args[] = {
12253 	{
12254 		SIOCIWFIRSTPRIV + 0x0,
12255 		IW_PRIV_TYPE_CHAR | 0x7FF, 0, "write"
12256 	},
12257 	{
12258 		SIOCIWFIRSTPRIV + 0x1,
12259 		IW_PRIV_TYPE_CHAR | 0x7FF,
12260 		IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "read"
12261 	},
12262 	{
12263 		SIOCIWFIRSTPRIV + 0x2, 0, 0, "driver_ext"
12264 	},
12265 	{
12266 		SIOCIWFIRSTPRIV + 0x3, 0, 0, "mp_ioctl"
12267 	},
12268 	{
12269 		SIOCIWFIRSTPRIV + 0x4,
12270 		IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "apinfo"
12271 	},
12272 	{
12273 		SIOCIWFIRSTPRIV + 0x5,
12274 		IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "setpid"
12275 	},
12276 	{
12277 		SIOCIWFIRSTPRIV + 0x6,
12278 		IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wps_start"
12279 	},
12280 	/* for PLATFORM_MT53XX	 */
12281 	{
12282 		SIOCIWFIRSTPRIV + 0x7,
12283 		IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "get_sensitivity"
12284 	},
12285 	{
12286 		SIOCIWFIRSTPRIV + 0x8,
12287 		IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wps_prob_req_ie"
12288 	},
12289 	{
12290 		SIOCIWFIRSTPRIV + 0x9,
12291 		IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wps_assoc_req_ie"
12292 	},
12293 
12294 	/* for RTK_DMP_PLATFORM	 */
12295 	{
12296 		SIOCIWFIRSTPRIV + 0xA,
12297 		IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "channel_plan"
12298 	},
12299 
12300 	{
12301 		SIOCIWFIRSTPRIV + 0xB,
12302 		IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "dbg"
12303 	},
12304 	{
12305 		SIOCIWFIRSTPRIV + 0xC,
12306 		IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 3, 0, "rfw"
12307 	},
12308 	{
12309 		SIOCIWFIRSTPRIV + 0xD,
12310 		IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "rfr"
12311 	},
12312 #if 0
12313 	{
12314 		SIOCIWFIRSTPRIV + 0xE, 0, 0, "wowlan_ctrl"
12315 	},
12316 #endif
12317 	{
12318 		SIOCIWFIRSTPRIV + 0x10,
12319 		IW_PRIV_TYPE_CHAR | 1024, 0, "p2p_set"
12320 	},
12321 	{
12322 		SIOCIWFIRSTPRIV + 0x11,
12323 		IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK , "p2p_get"
12324 	},
12325 	{
12326 		SIOCIWFIRSTPRIV + 0x12, 0, 0, "NULL"
12327 	},
12328 	{
12329 		SIOCIWFIRSTPRIV + 0x13,
12330 		IW_PRIV_TYPE_CHAR | 64, IW_PRIV_TYPE_CHAR | 64 , "p2p_get2"
12331 	},
12332 	{
12333 		SIOCIWFIRSTPRIV + 0x14,
12334 		IW_PRIV_TYPE_CHAR  | 64, 0, "tdls"
12335 	},
12336 	{
12337 		SIOCIWFIRSTPRIV + 0x15,
12338 		IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024 , "tdls_get"
12339 	},
12340 	{
12341 		SIOCIWFIRSTPRIV + 0x16,
12342 		IW_PRIV_TYPE_CHAR | 64, 0, "pm_set"
12343 	},
12344 #ifdef CONFIG_RTW_80211K
12345 	{
12346 		SIOCIWFIRSTPRIV + 0x17,
12347 		IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024 , "rrm"
12348 	},
12349 #else
12350 	{SIOCIWFIRSTPRIV + 0x17, IW_PRIV_TYPE_CHAR | 1024 , 0 , "NULL"},
12351 #endif
12352 
12353 #ifdef CONFIG_PLATFORM_CMAP_INTFS
12354 	{SIOCIWFIRSTPRIV + 0x18, IW_PRIV_TYPE_CHAR | 1024 , 0 , "cmap_intfs"},
12355 #else
12356 	{SIOCIWFIRSTPRIV + 0x18, 0, 0, "NULL"},
12357 #endif
12358 
12359 #ifdef CONFIG_MP_INCLUDED
12360 	{SIOCIWFIRSTPRIV + 0x1A, IW_PRIV_TYPE_CHAR | 1024, 0,  "NULL"},
12361 	{SIOCIWFIRSTPRIV + 0x1B, IW_PRIV_TYPE_CHAR | 128, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "NULL"},
12362 #else
12363 	{SIOCIWFIRSTPRIV + 0x1A, IW_PRIV_TYPE_CHAR | 1024, 0,  "NULL"},
12364 	{SIOCIWFIRSTPRIV + 0x1B, IW_PRIV_TYPE_CHAR | 128, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_get"},
12365 #endif
12366 	{
12367 		SIOCIWFIRSTPRIV + 0x1D,
12368 		IW_PRIV_TYPE_CHAR | 40, IW_PRIV_TYPE_CHAR | 0x7FF, "test"
12369 	},
12370 
12371 	{ SIOCIWFIRSTPRIV + 0x0E, IW_PRIV_TYPE_CHAR | 1024, 0 , ""},  /* set  */
12372 	{ SIOCIWFIRSTPRIV + 0x0F, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK , ""},/* get
12373  * --- sub-ioctls definitions --- */
12374 
12375 #ifdef CONFIG_APPEND_VENDOR_IE_ENABLE
12376 	{ VENDOR_IE_SET, IW_PRIV_TYPE_CHAR | 1024 , 0 , "vendor_ie_set" },
12377 	{ VENDOR_IE_GET, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "vendor_ie_get" },
12378 #endif
12379 #if defined(CONFIG_RTL8723B)
12380 	{ MP_SetBT, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_setbt" },
12381 	{ MP_DISABLE_BT_COEXIST, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_disa_btcoex"},
12382 #endif
12383 #ifdef CONFIG_WOWLAN
12384 	{ MP_WOW_ENABLE , IW_PRIV_TYPE_CHAR | 1024, 0, "wow_mode" },
12385 	{ MP_WOW_SET_PATTERN , IW_PRIV_TYPE_CHAR | 1024, 0, "wow_set_pattern" },
12386 #ifdef CONFIG_WOW_KEEP_ALIVE_PATTERN
12387 	{ MP_WOW_SET_KEEP_ALIVE_PATTERN ,IW_PRIV_TYPE_CHAR | 1024 , 0 , "wow_keep_alive"},
12388 #endif /* defined (CONFIG_KEEP_ALIVE_PATTERN)*/
12389 #endif
12390 
12391 #ifdef CONFIG_AP_WOWLAN
12392 	{ MP_AP_WOW_ENABLE , IW_PRIV_TYPE_CHAR | 1024, 0, "ap_wow_mode" }, /* set  */
12393 #endif
12394 #ifdef CONFIG_SDIO_INDIRECT_ACCESS
12395 	{ MP_SD_IREAD, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "sd_iread" },
12396 	{ MP_SD_IWRITE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "sd_iwrite" },
12397 #endif
12398 	{ GET_IC_TYPE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "ic_type" },
12399 };
12400 
12401 
12402 static const struct iw_priv_args rtw_mp_private_args[] = {
12403 	/* --- sub-ioctls definitions --- */
12404 #ifdef CONFIG_MP_INCLUDED
12405 	{ MP_START , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_start" },
12406 	{ MP_PHYPARA, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_phypara" },
12407 	{ MP_STOP , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_stop" },
12408 	{ MP_CHANNEL , IW_PRIV_TYPE_CHAR | 1024 , IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_channel" },
12409 	{ MP_CHL_OFFSET , IW_PRIV_TYPE_CHAR | 1024 , IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ch_offset" },
12410 	{ MP_BANDWIDTH , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_bandwidth"},
12411 	{ MP_RATE , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_rate" },
12412 	{ MP_RESET_STATS , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_reset_stats"},
12413 	{ MP_QUERY , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK , "mp_query"},
12414 	{ READ_REG , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "read_reg" },
12415 	{ MP_RATE , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_rate" },
12416 	{ READ_RF , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "read_rf" },
12417 	{ MP_PSD , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_psd"},
12418 	{ MP_DUMP, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_dump" },
12419 	{ MP_TXPOWER , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_txpower"},
12420 	{ MP_ANT_TX , IW_PRIV_TYPE_CHAR | 1024,  IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ant_tx"},
12421 	{ MP_ANT_RX , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ant_rx"},
12422 	{ WRITE_REG , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "write_reg" },
12423 	{ WRITE_RF , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "write_rf" },
12424 	{ MP_CTX , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ctx"},
12425 	{ MP_ARX , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_arx"},
12426 	{ MP_THER , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ther"},
12427 	{ EFUSE_SET, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_set" },
12428 	{ EFUSE_GET, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_get" },
12429 	{ MP_PWRTRK , IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_pwrtrk"},
12430 	{ MP_QueryDrvStats, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_drvquery" },
12431 	{ MP_IOCTL, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_ioctl"},
12432 	{ MP_SetRFPathSwh, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_setrfpath" },
12433 	{ MP_PwrCtlDM, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_pwrctldm" },
12434 	{ MP_GET_TXPOWER_INX, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_get_txpower" },
12435 	{ MP_GETVER, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_priv_ver" },
12436 	{ MP_MON, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_mon" },
12437 	{ EFUSE_BT_MASK, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_bt_mask" },
12438 	{ EFUSE_MASK, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_mask" },
12439 	{ EFUSE_FILE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_file" },
12440 	{ EFUSE_FILE_STORE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_store" },
12441 	{ MP_TX, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_tx" },
12442 	{ MP_RX, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_rx" },
12443 	{ MP_HW_TX_MODE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_hxtx" },
12444 	{ MP_PWRLMT, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_pwrlmt" },
12445 	{ MP_PWRBYRATE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_pwrbyrate" },
12446 	{ CTA_TEST, IW_PRIV_TYPE_CHAR | 1024, 0, "cta_test"},
12447 	{ MP_IQK, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_iqk"},
12448 	{ MP_LCK, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_lck"},
12449 	{ BT_EFUSE_FILE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "bt_efuse_file" },
12450 	{ MP_SWRFPath, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_swrfpath" },
12451 	{ MP_LINK, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_link" },
12452 	{ MP_DPK, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_dpk"},
12453 	{ MP_DPK_TRK, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_dpk_trk" },
12454 	{ MP_GET_TSSIDE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_get_tsside" },
12455 	{ MP_SET_TSSIDE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_set_tsside" },
12456 #ifdef CONFIG_RTW_CUSTOMER_STR
12457 	{ MP_CUSTOMER_STR, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "customer_str" },
12458 #endif
12459 
12460 #endif /* CONFIG_MP_INCLUDED */
12461 };
12462 
12463 static iw_handler rtw_private_handler[] = {
12464 	rtw_wx_write32,					/* 0x00 */
12465 	rtw_wx_read32,					/* 0x01 */
12466 	NULL,					/* 0x02 */
12467 #ifdef MP_IOCTL_HDL
12468 	rtw_mp_ioctl_hdl,				/* 0x03 */
12469 #else
12470 	rtw_wx_priv_null,
12471 #endif
12472 	/* for MM DTV platform */
12473 	rtw_get_ap_info,					/* 0x04 */
12474 
12475 	rtw_set_pid,						/* 0x05 */
12476 	rtw_wps_start,					/* 0x06 */
12477 
12478 	/* for PLATFORM_MT53XX */
12479 	rtw_wx_get_sensitivity,			/* 0x07 */
12480 	rtw_wx_set_mtk_wps_probe_ie,	/* 0x08 */
12481 	rtw_wx_set_mtk_wps_ie,			/* 0x09 */
12482 
12483 	/* for RTK_DMP_PLATFORM
12484 	 * Set Channel depend on the country code */
12485 	rtw_wx_set_channel_plan,		/* 0x0A */
12486 
12487 	rtw_dbg_port,					/* 0x0B */
12488 	rtw_wx_write_rf,					/* 0x0C */
12489 	rtw_wx_read_rf,					/* 0x0D */
12490 
12491 	rtw_priv_set,					/*0x0E*/
12492 	rtw_priv_get,					/*0x0F*/
12493 
12494 	rtw_p2p_set,					/* 0x10 */
12495 	rtw_p2p_get,					/* 0x11 */
12496 	NULL,							/* 0x12 */
12497 	rtw_p2p_get2,					/* 0x13 */
12498 
12499 	rtw_tdls,						/* 0x14 */
12500 	rtw_tdls_get,					/* 0x15 */
12501 
12502 	rtw_pm_set,						/* 0x16 */
12503 #ifdef CONFIG_RTW_80211K
12504 	rtw_wx_priv_rrm,				/* 0x17 */
12505 #else
12506 	rtw_wx_priv_null,				/* 0x17 */
12507 #endif
12508 #ifdef CONFIG_PLATFORM_CMAP_INTFS
12509 	cmap_intfs_ioctl,				/* 0x18 */
12510 #else
12511 	NULL,							/* 0x18 */
12512 #endif
12513 	rtw_wx_priv_null,				/* 0x19 */
12514 #ifdef CONFIG_MP_INCLUDED
12515 	rtw_wx_priv_null,				/* 0x1A */
12516 	rtw_wx_priv_null,				/* 0x1B */
12517 #else
12518 	rtw_wx_priv_null,				/* 0x1A */
12519 	rtw_mp_efuse_get,				/* 0x1B */
12520 #endif
12521 	NULL,							/* 0x1C is reserved for hostapd */
12522 	rtw_test,						/* 0x1D */
12523 };
12524 
12525 #ifdef CONFIG_WIRELESS_EXT
12526 #if WIRELESS_EXT >= 17
12527 static struct iw_statistics *rtw_get_wireless_stats(struct net_device *dev)
12528 {
12529 	_adapter *padapter = (_adapter *)rtw_netdev_priv(dev);
12530 	struct iw_statistics *piwstats = &padapter->iwstats;
12531 	int tmp_level = 0;
12532 	int tmp_qual = 0;
12533 	int tmp_noise = 0;
12534 
12535 	if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) != _TRUE) {
12536 		piwstats->qual.qual = 0;
12537 		piwstats->qual.level = 0;
12538 		piwstats->qual.noise = 0;
12539 		/* RTW_INFO("No link  level:%d, qual:%d, noise:%d\n", tmp_level, tmp_qual, tmp_noise); */
12540 	} else {
12541 #ifdef CONFIG_SIGNAL_DISPLAY_DBM
12542 		tmp_level = translate_percentage_to_dbm(padapter->recvpriv.signal_strength);
12543 #else
12544 		tmp_level = padapter->recvpriv.signal_strength;
12545 #endif
12546 
12547 		tmp_qual = padapter->recvpriv.signal_qual;
12548 		#ifdef CONFIG_BACKGROUND_NOISE_MONITOR
12549 		if (IS_NM_ENABLE(padapter)) {
12550 			tmp_noise = rtw_noise_measure_curchan(padapter);
12551 			#ifndef CONFIG_SIGNAL_DISPLAY_DBM
12552 			tmp_noise = translate_dbm_to_percentage(tmp_noise);/*percentage*/
12553 			#endif
12554 		}
12555 		#endif
12556 		/* RTW_INFO("level:%d, qual:%d, noise:%d, rssi (%d)\n", tmp_level, tmp_qual, tmp_noise,padapter->recvpriv.rssi); */
12557 
12558 		piwstats->qual.level = tmp_level;
12559 		piwstats->qual.qual = tmp_qual;
12560 		piwstats->qual.noise = tmp_noise;
12561 	}
12562 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14))
12563 	piwstats->qual.updated = IW_QUAL_ALL_UPDATED ;/* |IW_QUAL_DBM; */
12564 #else
12565 #ifdef RTK_DMP_PLATFORM
12566 	/* IW_QUAL_DBM= 0x8, if driver use this flag, wireless extension will show value of dbm. */
12567 	/* remove this flag for show percentage 0~100 */
12568 	piwstats->qual.updated = 0x07;
12569 #else
12570 	piwstats->qual.updated = 0x0f;
12571 #endif
12572 #endif
12573 
12574 #ifdef CONFIG_SIGNAL_DISPLAY_DBM
12575 	piwstats->qual.updated = piwstats->qual.updated | IW_QUAL_DBM;
12576 #endif
12577 
12578 	return &padapter->iwstats;
12579 }
12580 #endif
12581 
12582 struct iw_handler_def rtw_handlers_def = {
12583 	.standard = rtw_handlers,
12584 	.num_standard = sizeof(rtw_handlers) / sizeof(iw_handler),
12585 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33)) || defined(CONFIG_WEXT_PRIV)
12586 	.private = rtw_private_handler,
12587 	.private_args = (struct iw_priv_args *)rtw_private_args,
12588 	.num_private = sizeof(rtw_private_handler) / sizeof(iw_handler),
12589 	.num_private_args = sizeof(rtw_private_args) / sizeof(struct iw_priv_args),
12590 #endif
12591 #if WIRELESS_EXT >= 17
12592 	.get_wireless_stats = rtw_get_wireless_stats,
12593 #endif
12594 };
12595 #endif
12596 
12597 /* copy from net/wireless/wext.c start
12598  * ----------------------------------------------------------------
12599  *
12600  * Calculate size of private arguments
12601  */
12602 static const char iw_priv_type_size[] = {
12603 	0,                              /* IW_PRIV_TYPE_NONE */
12604 	1,                              /* IW_PRIV_TYPE_BYTE */
12605 	1,                              /* IW_PRIV_TYPE_CHAR */
12606 	0,                              /* Not defined */
12607 	sizeof(__u32),                  /* IW_PRIV_TYPE_INT */
12608 	sizeof(struct iw_freq),         /* IW_PRIV_TYPE_FLOAT */
12609 	sizeof(struct sockaddr),        /* IW_PRIV_TYPE_ADDR */
12610 	0,                              /* Not defined */
12611 };
12612 
12613 static int get_priv_size(__u16 args)
12614 {
12615 	int num = args & IW_PRIV_SIZE_MASK;
12616 	int type = (args & IW_PRIV_TYPE_MASK) >> 12;
12617 
12618 	return num * iw_priv_type_size[type];
12619 }
12620 /* copy from net/wireless/wext.c end */
12621 
12622 
12623 static int _rtw_ioctl_wext_private(struct net_device *dev, union iwreq_data *wrq_data)
12624 {
12625 	int err = 0;
12626 	u8 *input = NULL;
12627 	u32 input_len = 0;
12628 	const char delim[] = " ";
12629 	u8 *output = NULL;
12630 	u32 output_len = 0;
12631 	u32 count = 0;
12632 	u8 *buffer = NULL;
12633 	u32 buffer_len = 0;
12634 	char *ptr = NULL;
12635 	u8 cmdname[17] = {0}; /* IFNAMSIZ+1 */
12636 	u32 cmdlen;
12637 	s32 len;
12638 	u8 *extra = NULL;
12639 	u32 extra_size = 0;
12640 
12641 	s32 k;
12642 	const iw_handler *priv;		/* Private ioctl */
12643 	const struct iw_priv_args *priv_args;	/* Private ioctl description */
12644 	const struct iw_priv_args *mp_priv_args;	/*MP Private ioctl description */
12645 	const struct iw_priv_args *sel_priv_args;	/*Selected Private ioctl description */
12646 	u32 num_priv;				/* Number of ioctl */
12647 	u32 num_priv_args;			/* Number of descriptions */
12648 	u32 num_mp_priv_args;			/*Number of MP descriptions */
12649 	u32 num_sel_priv_args;			/*Number of Selected descriptions */
12650 	iw_handler handler;
12651 	int temp;
12652 	int subcmd = 0;				/* sub-ioctl index */
12653 	int offset = 0;				/* Space for sub-ioctl index */
12654 
12655 	union iwreq_data wdata;
12656 
12657 	_rtw_memcpy(&wdata, wrq_data, sizeof(wdata));
12658 
12659 	input_len = wdata.data.length;
12660 	if (!input_len)
12661 		return -EINVAL;
12662 	input = rtw_zmalloc(input_len);
12663 
12664 	if (input == NULL) {
12665 		err = -EOPNOTSUPP;
12666 		goto exit;
12667 	}
12668 
12669 	if (copy_from_user(input, wdata.data.pointer, input_len)) {
12670 		err = -EFAULT;
12671 		goto exit;
12672 	}
12673 	input[input_len - 1] = '\0';
12674 	ptr = input;
12675 	len = input_len;
12676 
12677 	sscanf(ptr, "%16s", cmdname);
12678 	cmdlen = strlen(cmdname);
12679 	RTW_DBG("%s: cmd=%s\n", __func__, cmdname);
12680 
12681 	/* skip command string */
12682 	if (cmdlen > 0)
12683 		cmdlen += 1; /* skip one space */
12684 	ptr += cmdlen;
12685 	len -= cmdlen;
12686 	RTW_DBG("%s: parameters=%s\n", __func__, ptr);
12687 
12688 	priv = rtw_private_handler;
12689 	priv_args = rtw_private_args;
12690 	mp_priv_args = rtw_mp_private_args;
12691 	num_priv = sizeof(rtw_private_handler) / sizeof(iw_handler);
12692 	num_priv_args = sizeof(rtw_private_args) / sizeof(struct iw_priv_args);
12693 	num_mp_priv_args = sizeof(rtw_mp_private_args) / sizeof(struct iw_priv_args);
12694 
12695 	if (num_priv_args == 0) {
12696 		err = -EOPNOTSUPP;
12697 		goto exit;
12698 	}
12699 
12700 	/* Search the correct ioctl */
12701 	k = -1;
12702 	sel_priv_args = priv_args;
12703 	num_sel_priv_args = num_priv_args;
12704 	while
12705 	((++k < num_sel_priv_args) && strcmp(sel_priv_args[k].name, cmdname))
12706 		;
12707 
12708 	/* If not found... */
12709 	if (k == num_sel_priv_args) {
12710 		k = -1;
12711 		sel_priv_args = mp_priv_args;
12712 		num_sel_priv_args = num_mp_priv_args;
12713 		while
12714 		((++k < num_sel_priv_args) && strcmp(sel_priv_args[k].name, cmdname))
12715 			;
12716 
12717 		if (k == num_sel_priv_args) {
12718 			err = -EOPNOTSUPP;
12719 			goto exit;
12720 		}
12721 	}
12722 
12723 	/* Watch out for sub-ioctls ! */
12724 	if (sel_priv_args[k].cmd < SIOCDEVPRIVATE) {
12725 		int j = -1;
12726 
12727 		/* Find the matching *real* ioctl */
12728 		while ((++j < num_priv_args) && ((priv_args[j].name[0] != '\0') ||
12729 			 (priv_args[j].set_args != sel_priv_args[k].set_args) ||
12730 			 (priv_args[j].get_args != sel_priv_args[k].get_args)))
12731 			;
12732 
12733 		/* If not found... */
12734 		if (j == num_priv_args) {
12735 			err = -EINVAL;
12736 			goto exit;
12737 		}
12738 
12739 		/* Save sub-ioctl number */
12740 		subcmd = sel_priv_args[k].cmd;
12741 		/* Reserve one int (simplify alignment issues) */
12742 		offset = sizeof(__u32);
12743 		/* Use real ioctl definition from now on */
12744 		k = j;
12745 	}
12746 
12747 	buffer = rtw_zmalloc(4096);
12748 	if (NULL == buffer) {
12749 		err = -ENOMEM;
12750 		goto exit;
12751 	}
12752 
12753 	if (k >= num_priv_args) {
12754 		err = -EINVAL;
12755 		goto exit;
12756 	}
12757 
12758 	/* If we have to set some data */
12759 	if ((priv_args[k].set_args & IW_PRIV_TYPE_MASK) &&
12760 	    (priv_args[k].set_args & IW_PRIV_SIZE_MASK)) {
12761 		u8 *str;
12762 
12763 		switch (priv_args[k].set_args & IW_PRIV_TYPE_MASK) {
12764 		case IW_PRIV_TYPE_BYTE:
12765 			/* Fetch args */
12766 			count = 0;
12767 			do {
12768 				str = strsep(&ptr, delim);
12769 				if (NULL == str || count >= 4096)
12770 					break;
12771 				sscanf(str, "%i", &temp);
12772 				buffer[count++] = (u8)temp;
12773 			} while (1);
12774 			buffer_len = count;
12775 
12776 			/* Number of args to fetch */
12777 			wdata.data.length = count;
12778 			if (wdata.data.length > (priv_args[k].set_args & IW_PRIV_SIZE_MASK))
12779 				wdata.data.length = priv_args[k].set_args & IW_PRIV_SIZE_MASK;
12780 
12781 			break;
12782 
12783 		case IW_PRIV_TYPE_INT:
12784 			/* Fetch args */
12785 			count = 0;
12786 			do {
12787 				str = strsep(&ptr, delim);
12788 				if (NULL == str || count >= 1024)
12789 					break;
12790 				sscanf(str, "%i", &temp);
12791 				((s32 *)buffer)[count++] = (s32)temp;
12792 			} while (1);
12793 			buffer_len = count * sizeof(s32);
12794 
12795 			/* Number of args to fetch */
12796 			wdata.data.length = count;
12797 			if (wdata.data.length > (priv_args[k].set_args & IW_PRIV_SIZE_MASK))
12798 				wdata.data.length = priv_args[k].set_args & IW_PRIV_SIZE_MASK;
12799 
12800 			break;
12801 
12802 		case IW_PRIV_TYPE_CHAR:
12803 			if (len > 0) {
12804 				/* Size of the string to fetch */
12805 				wdata.data.length = len;
12806 				if (wdata.data.length > (priv_args[k].set_args & IW_PRIV_SIZE_MASK))
12807 					wdata.data.length = priv_args[k].set_args & IW_PRIV_SIZE_MASK;
12808 
12809 				/* Fetch string */
12810 				_rtw_memcpy(buffer, ptr, wdata.data.length);
12811 			} else {
12812 				wdata.data.length = 1;
12813 				buffer[0] = '\0';
12814 			}
12815 			buffer_len = wdata.data.length;
12816 			break;
12817 
12818 		default:
12819 			RTW_INFO("%s: Not yet implemented...\n", __func__);
12820 			err = -1;
12821 			goto exit;
12822 		}
12823 
12824 		if ((priv_args[k].set_args & IW_PRIV_SIZE_FIXED) &&
12825 		    (wdata.data.length != (priv_args[k].set_args & IW_PRIV_SIZE_MASK))) {
12826 			RTW_INFO("%s: The command %s needs exactly %d argument(s)...\n",
12827 				__func__, cmdname, priv_args[k].set_args & IW_PRIV_SIZE_MASK);
12828 			err = -EINVAL;
12829 			goto exit;
12830 		}
12831 	}   /* if args to set */
12832 	else
12833 		wdata.data.length = 0L;
12834 
12835 	/* Those two tests are important. They define how the driver
12836 	* will have to handle the data */
12837 	if ((priv_args[k].set_args & IW_PRIV_SIZE_FIXED) &&
12838 	    ((get_priv_size(priv_args[k].set_args) + offset) <= IFNAMSIZ)) {
12839 		/* First case : all SET args fit within wrq */
12840 		if (offset)
12841 			wdata.mode = subcmd;
12842 		_rtw_memcpy(wdata.name + offset, buffer, IFNAMSIZ - offset);
12843 	} else {
12844 		if ((priv_args[k].set_args == 0) &&
12845 		    (priv_args[k].get_args & IW_PRIV_SIZE_FIXED) &&
12846 		    (get_priv_size(priv_args[k].get_args) <= IFNAMSIZ)) {
12847 			/* Second case : no SET args, GET args fit within wrq */
12848 			if (offset)
12849 				wdata.mode = subcmd;
12850 		} else {
12851 			/* Third case : args won't fit in wrq, or variable number of args */
12852 			if (copy_to_user(wdata.data.pointer, buffer, buffer_len)) {
12853 				err = -EFAULT;
12854 				goto exit;
12855 			}
12856 			wdata.data.flags = subcmd;
12857 		}
12858 	}
12859 
12860 	rtw_mfree(input, input_len);
12861 	input = NULL;
12862 
12863 	extra_size = 0;
12864 	if (IW_IS_SET(priv_args[k].cmd)) {
12865 		/* Size of set arguments */
12866 		extra_size = get_priv_size(priv_args[k].set_args);
12867 
12868 		/* Does it fits in iwr ? */
12869 		if ((priv_args[k].set_args & IW_PRIV_SIZE_FIXED) &&
12870 		    ((extra_size + offset) <= IFNAMSIZ))
12871 			extra_size = 0;
12872 	} else {
12873 		/* Size of get arguments */
12874 		extra_size = get_priv_size(priv_args[k].get_args);
12875 
12876 		/* Does it fits in iwr ? */
12877 		if ((priv_args[k].get_args & IW_PRIV_SIZE_FIXED) &&
12878 		    (extra_size <= IFNAMSIZ))
12879 			extra_size = 0;
12880 	}
12881 
12882 	if (extra_size == 0) {
12883 		extra = (u8 *)&wdata;
12884 		rtw_mfree(buffer, 4096);
12885 		buffer = NULL;
12886 	} else
12887 		extra = buffer;
12888 
12889 	handler = priv[priv_args[k].cmd - SIOCIWFIRSTPRIV];
12890 	err = handler(dev, NULL, &wdata, extra);
12891 
12892 	/* If we have to get some data */
12893 	if ((priv_args[k].get_args & IW_PRIV_TYPE_MASK) &&
12894 	    (priv_args[k].get_args & IW_PRIV_SIZE_MASK)) {
12895 		int j;
12896 		int n = 0;	/* number of args */
12897 		u8 str[20] = {0};
12898 
12899 		/* Check where is the returned data */
12900 		if ((priv_args[k].get_args & IW_PRIV_SIZE_FIXED) &&
12901 		    (get_priv_size(priv_args[k].get_args) <= IFNAMSIZ))
12902 			n = priv_args[k].get_args & IW_PRIV_SIZE_MASK;
12903 		else
12904 			n = wdata.data.length;
12905 
12906 		output = rtw_zmalloc(4096);
12907 		if (NULL == output) {
12908 			err =  -ENOMEM;
12909 			goto exit;
12910 		}
12911 
12912 		switch (priv_args[k].get_args & IW_PRIV_TYPE_MASK) {
12913 		case IW_PRIV_TYPE_BYTE:
12914 			/* Display args */
12915 			for (j = 0; j < n; j++) {
12916 				sprintf(str, "%d  ", extra[j]);
12917 				len = strlen(str);
12918 				output_len = strlen(output);
12919 				if ((output_len + len + 1) > 4096) {
12920 					err = -E2BIG;
12921 					goto exit;
12922 				}
12923 				_rtw_memcpy(output + output_len, str, len);
12924 			}
12925 			break;
12926 
12927 		case IW_PRIV_TYPE_INT:
12928 			/* Display args */
12929 			for (j = 0; j < n; j++) {
12930 				sprintf(str, "%d  ", ((__s32 *)extra)[j]);
12931 				len = strlen(str);
12932 				output_len = strlen(output);
12933 				if ((output_len + len + 1) > 4096) {
12934 					err = -E2BIG;
12935 					goto exit;
12936 				}
12937 				_rtw_memcpy(output + output_len, str, len);
12938 			}
12939 			break;
12940 
12941 		case IW_PRIV_TYPE_CHAR:
12942 			/* Display args */
12943 			_rtw_memcpy(output, extra, n);
12944 			break;
12945 
12946 		default:
12947 			RTW_INFO("%s: Not yet implemented...\n", __func__);
12948 			err = -1;
12949 			goto exit;
12950 		}
12951 
12952 		output_len = strlen(output) + 1;
12953 		wrq_data->data.length = output_len;
12954 		if (copy_to_user(wrq_data->data.pointer, output, output_len)) {
12955 			err = -EFAULT;
12956 			goto exit;
12957 		}
12958 	}   /* if args to set */
12959 	else
12960 		wrq_data->data.length = 0;
12961 
12962 exit:
12963 	if (input)
12964 		rtw_mfree(input, input_len);
12965 	if (buffer)
12966 		rtw_mfree(buffer, 4096);
12967 	if (output)
12968 		rtw_mfree(output, 4096);
12969 
12970 	return err;
12971 }
12972 
12973 #ifdef CONFIG_COMPAT
12974 static int rtw_ioctl_compat_wext_private(struct net_device *dev, struct ifreq *rq)
12975 {
12976 	struct compat_iw_point iwp_compat;
12977 	union iwreq_data wrq_data;
12978 	int err = 0;
12979 	RTW_DBG("%s:...\n", __func__);
12980 	if (copy_from_user(&iwp_compat, rq->ifr_ifru.ifru_data, sizeof(struct compat_iw_point)))
12981 		return -EFAULT;
12982 
12983 	wrq_data.data.pointer = compat_ptr(iwp_compat.pointer);
12984 	wrq_data.data.length = iwp_compat.length;
12985 	wrq_data.data.flags = iwp_compat.flags;
12986 
12987 	err = _rtw_ioctl_wext_private(dev, &wrq_data);
12988 
12989 	iwp_compat.pointer = ptr_to_compat(wrq_data.data.pointer);
12990 	iwp_compat.length = wrq_data.data.length;
12991 	iwp_compat.flags = wrq_data.data.flags;
12992 	if (copy_to_user(rq->ifr_ifru.ifru_data, &iwp_compat, sizeof(struct compat_iw_point)))
12993 		return -EFAULT;
12994 
12995 	return err;
12996 }
12997 #endif /* CONFIG_COMPAT */
12998 
12999 static int rtw_ioctl_standard_wext_private(struct net_device *dev, struct ifreq *rq)
13000 {
13001 	struct iw_point *iwp;
13002 	union iwreq_data wrq_data;
13003 	int err = 0;
13004 	iwp = &wrq_data.data;
13005 	RTW_DBG("%s:...\n", __func__);
13006 	if (copy_from_user(iwp, rq->ifr_ifru.ifru_data, sizeof(struct iw_point)))
13007 		return -EFAULT;
13008 
13009 	err = _rtw_ioctl_wext_private(dev, &wrq_data);
13010 
13011 	if (copy_to_user(rq->ifr_ifru.ifru_data, iwp, sizeof(struct iw_point)))
13012 		return -EFAULT;
13013 
13014 	return err;
13015 }
13016 
13017 static int rtw_ioctl_wext_private(struct net_device *dev, struct ifreq *rq)
13018 {
13019 #ifdef CONFIG_COMPAT
13020 #if (KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE)
13021 	if (is_compat_task())
13022 #else
13023 	if (in_compat_syscall())
13024 #endif
13025 		return rtw_ioctl_compat_wext_private(dev, rq);
13026 	else
13027 #endif /* CONFIG_COMPAT */
13028 		return rtw_ioctl_standard_wext_private(dev, rq);
13029 }
13030 
13031 int rtw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
13032 {
13033 	struct iwreq *wrq = (struct iwreq *)rq;
13034 	int ret = 0;
13035 
13036 	switch (cmd) {
13037 #ifdef CONFIG_IOCTL_WEXT
13038 	case RTL_IOCTL_WPA_SUPPLICANT:
13039 		ret = wpa_supplicant_ioctl(dev, &wrq->u.data);
13040 		break;
13041 #ifdef CONFIG_AP_MODE
13042 	case RTL_IOCTL_HOSTAPD:
13043 		ret = rtw_hostapd_ioctl(dev, &wrq->u.data);
13044 		break;
13045 #ifdef CONFIG_WIRELESS_EXT
13046 	case SIOCSIWMODE:
13047 		ret = rtw_wx_set_mode(dev, NULL, &wrq->u, NULL);
13048 		break;
13049 #endif
13050 #endif /* CONFIG_AP_MODE */
13051 #endif /* CONFIG_IOCTL_WEXT */
13052 	case SIOCDEVPRIVATE:
13053 		ret = rtw_ioctl_wext_private(dev, rq);
13054 		break;
13055 	case (SIOCDEVPRIVATE+1):
13056 		ret = rtw_android_priv_cmd(dev, rq, cmd);
13057 		break;
13058 	default:
13059 		ret = -EOPNOTSUPP;
13060 		break;
13061 	}
13062 
13063 	return ret;
13064 }
13065