1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2007 - 2012 Realtek Corporation. */
4 #define _IOCTL_LINUX_C_
6 #include "../include/osdep_service.h"
7 #include "../include/drv_types.h"
8 #include "../include/wlan_bssdef.h"
9 #include "../include/rtw_debug.h"
10 #include "../include/wifi.h"
11 #include "../include/rtw_mlme.h"
12 #include "../include/rtw_mlme_ext.h"
13 #include "../include/rtw_ioctl.h"
14 #include "../include/rtw_ioctl_set.h"
15 #include "../include/rtw_mp_ioctl.h"
16 #include "../include/usb_ops.h"
17 #include "../include/rtl8188e_hal.h"
19 #include "../include/rtw_mp.h"
20 #include "../include/rtw_iol.h"
22 #define RTL_IOCTL_WPA_SUPPLICANT (SIOCIWFIRSTPRIV + 30)
24 #define SCAN_ITEM_SIZE 768
25 #define MAX_CUSTOM_LEN 64
29 #define WEXT_CSCAN_AMOUNT 9
30 #define WEXT_CSCAN_BUF_LEN 360
31 #define WEXT_CSCAN_HEADER "CSCAN S\x01\x00\x00S\x00"
32 #define WEXT_CSCAN_HEADER_SIZE 12
33 #define WEXT_CSCAN_SSID_SECTION 'S'
34 #define WEXT_CSCAN_CHANNEL_SECTION 'C'
35 #define WEXT_CSCAN_NPROBE_SECTION 'N'
36 #define WEXT_CSCAN_ACTV_DWELL_SECTION 'A'
37 #define WEXT_CSCAN_PASV_DWELL_SECTION 'P'
38 #define WEXT_CSCAN_HOME_DWELL_SECTION 'H'
39 #define WEXT_CSCAN_TYPE_SECTION 'T'
41 static struct mp_ioctl_handler mp_ioctl_hdl[] = {
42 /*0*/ GEN_HANDLER(sizeof(u32), rtl8188eu_oid_rt_pro_start_test_hdl, OID_RT_PRO_START_TEST)
43 GEN_HANDLER(sizeof(u32), rtl8188eu_oid_rt_pro_stop_test_hdl, OID_RT_PRO_STOP_TEST)
45 GEN_HANDLER(sizeof(struct rwreg_param), rtl8188eu_oid_rt_pro_read_register_hdl, OID_RT_PRO_READ_REGISTER)
46 GEN_HANDLER(sizeof(struct rwreg_param), rtl8188eu_oid_rt_pro_write_register_hdl, OID_RT_PRO_WRITE_REGISTER)
47 GEN_HANDLER(sizeof(struct bb_reg_param), rtl8188eu_oid_rt_pro_read_bb_reg_hdl, OID_RT_PRO_READ_BB_REG)
48 /*5*/ GEN_HANDLER(sizeof(struct bb_reg_param), rtl8188eu_oid_rt_pro_write_bb_reg_hdl, OID_RT_PRO_WRITE_BB_REG)
49 GEN_HANDLER(sizeof(struct rf_reg_param), rtl8188eu_oid_rt_pro_read_rf_reg_hdl, OID_RT_PRO_RF_READ_REGISTRY)
50 GEN_HANDLER(sizeof(struct rf_reg_param), rtl8188eu_oid_rt_pro_write_rf_reg_hdl, OID_RT_PRO_RF_WRITE_REGISTRY)
52 GEN_HANDLER(sizeof(u32), rtl8188eu_oid_rt_pro_set_channel_direct_call_hdl, OID_RT_PRO_SET_CHANNEL_DIRECT_CALL)
53 GEN_HANDLER(sizeof(struct txpower_param), rtl8188eu_oid_rt_pro_set_tx_power_control_hdl, OID_RT_PRO_SET_TX_POWER_CONTROL)
54 /*10*/ GEN_HANDLER(sizeof(u32), rtl8188eu_oid_rt_pro_set_data_rate_hdl, OID_RT_PRO_SET_DATA_RATE)
55 GEN_HANDLER(sizeof(u32), rtl8188eu_oid_rt_set_bandwidth_hdl, OID_RT_SET_BANDWIDTH)
56 GEN_HANDLER(sizeof(u32), rtl8188eu_oid_rt_pro_set_antenna_bb_hdl, OID_RT_PRO_SET_ANTENNA_BB)
58 GEN_HANDLER(sizeof(u32), rtl8188eu_oid_rt_pro_set_continuous_tx_hdl, OID_RT_PRO_SET_CONTINUOUS_TX)
59 GEN_HANDLER(sizeof(u32), rtl8188eu_oid_rt_pro_set_single_carrier_tx_hdl, OID_RT_PRO_SET_SINGLE_CARRIER_TX)
60 /*15*/ GEN_HANDLER(sizeof(u32), rtl8188eu_oid_rt_pro_set_carrier_suppression_tx_hdl, OID_RT_PRO_SET_CARRIER_SUPPRESSION_TX)
61 GEN_HANDLER(sizeof(u32), rtl8188eu_oid_rt_pro_set_single_tone_tx_hdl, OID_RT_PRO_SET_SINGLE_TONE_TX)
63 EXT_MP_IOCTL_HANDLER(0, xmit_packet, 0)
65 GEN_HANDLER(sizeof(u32), rtl8188eu_oid_rt_set_rx_packet_type_hdl, OID_RT_SET_RX_PACKET_TYPE)
66 GEN_HANDLER(0, rtl8188eu_oid_rt_reset_phy_rx_packet_count_hdl, OID_RT_RESET_PHY_RX_PACKET_COUNT)
67 /*20*/ GEN_HANDLER(sizeof(u32), rtl8188eu_oid_rt_get_phy_rx_packet_received_hdl, OID_RT_GET_PHY_RX_PACKET_RECEIVED)
68 GEN_HANDLER(sizeof(u32), rtl8188eu_oid_rt_get_phy_rx_packet_crc32_error_hdl, OID_RT_GET_PHY_RX_PACKET_CRC32_ERROR)
70 GEN_HANDLER(sizeof(struct eeprom_rw_param), NULL, 0)
71 GEN_HANDLER(sizeof(struct eeprom_rw_param), NULL, 0)
72 GEN_HANDLER(sizeof(struct efuse_access_struct), rtl8188eu_oid_rt_pro_efuse_hdl, OID_RT_PRO_EFUSE)
73 /*25*/ GEN_HANDLER(0, rtl8188eu_oid_rt_pro_efuse_map_hdl, OID_RT_PRO_EFUSE_MAP)
74 GEN_HANDLER(sizeof(u32), rtl8188eu_oid_rt_get_efuse_max_size_hdl, OID_RT_GET_EFUSE_MAX_SIZE)
75 GEN_HANDLER(sizeof(u32), rtl8188eu_oid_rt_get_efuse_current_size_hdl, OID_RT_GET_EFUSE_CURRENT_SIZE)
77 GEN_HANDLER(sizeof(u32), rtl8188eu_oid_rt_get_thermal_meter_hdl, OID_RT_PRO_GET_THERMAL_METER)
78 GEN_HANDLER(sizeof(u8), rtl8188eu_oid_rt_pro_set_power_tracking_hdl, OID_RT_PRO_SET_POWER_TRACKING)
79 /*30*/ GEN_HANDLER(sizeof(u8), rtl8188eu_oid_rt_set_power_down_hdl, OID_RT_SET_POWER_DOWN)
80 /*31*/ GEN_HANDLER(0, rtl8188eu_oid_rt_pro_trigger_gpio_hdl, 0)
83 static u32 rtw_rates[] = {1000000, 2000000, 5500000, 11000000,
84 6000000, 9000000, 12000000, 18000000, 24000000, 36000000,
87 void indicate_wx_scan_complete_event(struct adapter *padapter)
89 union iwreq_data wrqu;
91 memset(&wrqu, 0, sizeof(union iwreq_data));
92 wireless_send_event(padapter->pnetdev, SIOCGIWSCAN, &wrqu, NULL);
95 void rtw_indicate_wx_assoc_event(struct adapter *padapter)
97 union iwreq_data wrqu;
98 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
100 memset(&wrqu, 0, sizeof(union iwreq_data));
102 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
104 memcpy(wrqu.ap_addr.sa_data, pmlmepriv->cur_network.network.MacAddress, ETH_ALEN);
106 DBG_88E_LEVEL(_drv_always_, "assoc success\n");
107 wireless_send_event(padapter->pnetdev, SIOCGIWAP, &wrqu, NULL);
110 void rtw_indicate_wx_disassoc_event(struct adapter *padapter)
112 union iwreq_data wrqu;
114 memset(&wrqu, 0, sizeof(union iwreq_data));
116 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
117 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
119 DBG_88E_LEVEL(_drv_always_, "indicate disassoc\n");
120 wireless_send_event(padapter->pnetdev, SIOCGIWAP, &wrqu, NULL);
123 static char *translate_scan(struct adapter *padapter,
124 struct iw_request_info *info,
125 struct wlan_network *pnetwork,
126 char *start, char *stop)
128 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
135 u16 max_rate = 0, rate, ht_cap = false;
137 u8 bw_40MHz = 0, short_GI = 0;
140 #ifdef CONFIG_88EU_P2P
141 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
143 if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
144 u32 blnGotP2PIE = false;
146 /* User is doing the P2P device discovery */
147 /* The prefix of SSID should be "DIRECT-" and the IE should contains the P2P IE. */
148 /* If not, the driver should ignore this AP and go to the next AP. */
150 /* Verifying the SSID */
151 if (!memcmp(pnetwork->network.Ssid.Ssid, pwdinfo->p2p_wildcard_ssid, P2P_WILDCARD_SSID_LEN)) {
154 if (pnetwork->network.Reserved[0] == 2) {/* Probe Request */
155 /* Verifying the P2P IE */
156 if (rtw_get_p2p_ie(pnetwork->network.IEs, pnetwork->network.IELength, NULL, &p2pielen))
158 } else {/* Beacon or Probe Respones */
159 /* Verifying the P2P IE */
160 if (rtw_get_p2p_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &p2pielen))
168 #endif /* CONFIG_88EU_P2P */
172 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
174 memcpy(iwe.u.ap_addr.sa_data, pnetwork->network.MacAddress, ETH_ALEN);
175 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_ADDR_LEN);
178 iwe.cmd = SIOCGIWESSID;
179 iwe.u.data.flags = 1;
180 iwe.u.data.length = min_t(u16, pnetwork->network.Ssid.SsidLength, 32);
181 start = iwe_stream_add_point(info, start, stop, &iwe, pnetwork->network.Ssid.Ssid);
183 /* parsing HT_CAP_IE */
184 p = rtw_get_ie(&pnetwork->network.IEs[12], _HT_CAPABILITY_IE_, &ht_ielen, pnetwork->network.IELength - 12);
186 if (p && ht_ielen > 0) {
187 struct ieee80211_ht_cap *pht_capie;
190 pht_capie = (struct ieee80211_ht_cap *)(p + 2);
191 memcpy(&mcs_rate, pht_capie->mcs.rx_mask, 2);
192 bw_40MHz = (le16_to_cpu(pht_capie->cap_info) &
193 IEEE80211_HT_CAP_SUP_WIDTH_20_40) ? 1 : 0;
194 short_GI = (le16_to_cpu(pht_capie->cap_info) &
195 (IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40)) ? 1 : 0;
198 /* Add the protocol name */
199 iwe.cmd = SIOCGIWNAME;
200 if ((rtw_is_cckratesonly_included((u8 *)&pnetwork->network.SupportedRates))) {
202 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bn");
204 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11b");
205 } else if ((rtw_is_cckrates_included((u8 *)&pnetwork->network.SupportedRates))) {
207 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bgn");
209 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bg");
212 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11gn");
214 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11g");
217 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_CHAR_LEN);
220 iwe.cmd = SIOCGIWMODE;
221 memcpy(&le_tmp, rtw_get_capability_from_ie(pnetwork->network.IEs), 2);
223 cap = le16_to_cpu(le_tmp);
225 if (cap & (WLAN_CAPABILITY_IBSS | WLAN_CAPABILITY_BSS)) {
226 if (cap & WLAN_CAPABILITY_BSS)
227 iwe.u.mode = IW_MODE_MASTER;
229 iwe.u.mode = IW_MODE_ADHOC;
231 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_UINT_LEN);
234 if (pnetwork->network.Configuration.DSConfig < 1)
235 pnetwork->network.Configuration.DSConfig = 1;
237 /* Add frequency/channel */
238 iwe.cmd = SIOCGIWFREQ;
239 iwe.u.freq.m = rtw_ch2freq(pnetwork->network.Configuration.DSConfig) * 100000;
241 iwe.u.freq.i = pnetwork->network.Configuration.DSConfig;
242 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_FREQ_LEN);
244 /* Add encryption capability */
245 iwe.cmd = SIOCGIWENCODE;
246 if (cap & WLAN_CAPABILITY_PRIVACY)
247 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
249 iwe.u.data.flags = IW_ENCODE_DISABLED;
250 iwe.u.data.length = 0;
251 start = iwe_stream_add_point(info, start, stop, &iwe, pnetwork->network.Ssid.Ssid);
253 /*Add basic and extended rates */
255 custom = kzalloc(MAX_CUSTOM_LEN, GFP_ATOMIC);
259 p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), " Rates (Mb/s): ");
260 while (pnetwork->network.SupportedRates[i] != 0) {
261 rate = pnetwork->network.SupportedRates[i] & 0x7F;
264 p += snprintf(p, MAX_CUSTOM_LEN - (p - custom),
265 "%d%s ", rate >> 1, (rate & 1) ? ".5" : "");
270 if (mcs_rate & 0x8000)/* MCS15 */
271 max_rate = (bw_40MHz) ? ((short_GI) ? 300 : 270) : ((short_GI) ? 144 : 130);
272 else if (mcs_rate & 0x0080)/* MCS7 */
274 else/* default MCS7 */
275 max_rate = (bw_40MHz) ? ((short_GI) ? 150 : 135) : ((short_GI) ? 72 : 65);
277 max_rate = max_rate * 2;/* Mbps/2; */
280 iwe.cmd = SIOCGIWRATE;
281 iwe.u.bitrate.fixed = 0;
282 iwe.u.bitrate.disabled = 0;
283 iwe.u.bitrate.value = max_rate * 500000;
284 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_PARAM_LEN);
286 /* parsing WPA/WPA2 IE */
290 u16 wpa_len = 0, rsn_len = 0;
293 buf = kzalloc(MAX_WPA_IE_LEN, GFP_ATOMIC);
296 wpa_ie = kzalloc(255, GFP_ATOMIC);
301 rsn_ie = kzalloc(255, GFP_ATOMIC);
307 rtw_get_sec_ie(pnetwork->network.IEs, pnetwork->network.IELength, rsn_ie, &rsn_len, wpa_ie, &wpa_len);
311 memset(buf, 0, MAX_WPA_IE_LEN);
312 p += sprintf(p, "wpa_ie =");
313 for (i = 0; i < wpa_len; i++)
314 p += sprintf(p, "%02x", wpa_ie[i]);
316 memset(&iwe, 0, sizeof(iwe));
317 iwe.cmd = IWEVCUSTOM;
318 iwe.u.data.length = strlen(buf);
319 start = iwe_stream_add_point(info, start, stop, &iwe, buf);
321 memset(&iwe, 0, sizeof(iwe));
323 iwe.u.data.length = wpa_len;
324 start = iwe_stream_add_point(info, start, stop, &iwe, wpa_ie);
328 memset(buf, 0, MAX_WPA_IE_LEN);
329 p += sprintf(p, "rsn_ie =");
330 for (i = 0; i < rsn_len; i++)
331 p += sprintf(p, "%02x", rsn_ie[i]);
332 memset(&iwe, 0, sizeof(iwe));
333 iwe.cmd = IWEVCUSTOM;
334 iwe.u.data.length = strlen(buf);
335 start = iwe_stream_add_point(info, start, stop, &iwe, buf);
337 memset(&iwe, 0, sizeof(iwe));
339 iwe.u.data.length = rsn_len;
340 start = iwe_stream_add_point(info, start, stop, &iwe, rsn_ie);
347 {/* parsing WPS IE */
348 uint cnt = 0, total_ielen;
349 u8 *wpsie_ptr = NULL;
352 u8 *ie_ptr = pnetwork->network.IEs + _FIXED_IE_LENGTH_;
353 total_ielen = pnetwork->network.IELength - _FIXED_IE_LENGTH_;
355 while (cnt < total_ielen) {
356 if (rtw_is_wps_ie(&ie_ptr[cnt], &wps_ielen) && (wps_ielen > 2)) {
357 wpsie_ptr = &ie_ptr[cnt];
359 iwe.u.data.length = (u16)wps_ielen;
360 start = iwe_stream_add_point(info, start, stop, &iwe, wpsie_ptr);
362 cnt += ie_ptr[cnt + 1] + 2; /* goto next */
366 /* Add quality statistics */
368 iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_INVALID;
370 if (check_fwstate(pmlmepriv, _FW_LINKED) &&
371 is_same_network(&pmlmepriv->cur_network.network, &pnetwork->network)) {
372 ss = padapter->recvpriv.signal_strength;
373 sq = padapter->recvpriv.signal_qual;
375 ss = pnetwork->network.PhyInfo.SignalStrength;
376 sq = pnetwork->network.PhyInfo.SignalQuality;
379 iwe.u.qual.level = (u8)ss;
380 iwe.u.qual.qual = (u8)sq; /* signal quality */
381 iwe.u.qual.noise = 0; /* noise level */
382 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_QUAL_LEN);
388 static int wpa_set_auth_algs(struct net_device *dev, u32 value)
390 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
393 if ((value & AUTH_ALG_SHARED_KEY) && (value & AUTH_ALG_OPEN_SYSTEM)) {
394 DBG_88E("wpa_set_auth_algs, AUTH_ALG_SHARED_KEY and AUTH_ALG_OPEN_SYSTEM [value:0x%x]\n", value);
395 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
396 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeAutoSwitch;
397 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
398 } else if (value & AUTH_ALG_SHARED_KEY) {
399 DBG_88E("wpa_set_auth_algs, AUTH_ALG_SHARED_KEY [value:0x%x]\n", value);
400 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
402 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeShared;
403 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Shared;
404 } else if (value & AUTH_ALG_OPEN_SYSTEM) {
405 DBG_88E("wpa_set_auth_algs, AUTH_ALG_OPEN_SYSTEM\n");
406 if (padapter->securitypriv.ndisauthtype < Ndis802_11AuthModeWPAPSK) {
407 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
408 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
410 } else if (value & AUTH_ALG_LEAP) {
411 DBG_88E("wpa_set_auth_algs, AUTH_ALG_LEAP\n");
413 DBG_88E("wpa_set_auth_algs, error!\n");
419 static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len)
422 u32 wep_key_idx, wep_key_len, wep_total_len;
423 struct ndis_802_11_wep *pwep = NULL;
424 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
425 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
426 struct security_priv *psecuritypriv = &padapter->securitypriv;
427 #ifdef CONFIG_88EU_P2P
428 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
429 #endif /* CONFIG_88EU_P2P */
431 param->u.crypt.err = 0;
432 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
434 if (param_len < (u32)((u8 *)param->u.crypt.key - (u8 *)param) + param->u.crypt.key_len) {
439 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
440 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
441 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
442 if (param->u.crypt.idx >= WEP_KEYS) {
451 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
452 DBG_88E("wpa_set_encryption, crypt.alg = WEP\n");
454 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
455 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
456 padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_;
458 wep_key_idx = param->u.crypt.idx;
459 wep_key_len = param->u.crypt.key_len;
461 DBG_88E("(1)wep_key_idx =%d\n", wep_key_idx);
463 if (wep_key_idx > WEP_KEYS)
466 if (wep_key_len > 0) {
467 wep_key_len = wep_key_len <= 5 ? 5 : 13;
468 wep_total_len = wep_key_len + FIELD_OFFSET(struct ndis_802_11_wep, KeyMaterial);
469 pwep = kmalloc(wep_total_len, GFP_KERNEL);
473 memset(pwep, 0, wep_total_len);
474 pwep->KeyLength = wep_key_len;
475 pwep->Length = wep_total_len;
476 if (wep_key_len == 13) {
477 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_;
478 padapter->securitypriv.dot118021XGrpPrivacy = _WEP104_;
484 pwep->KeyIndex = wep_key_idx;
485 pwep->KeyIndex |= 0x80000000;
486 memcpy(pwep->KeyMaterial, param->u.crypt.key, pwep->KeyLength);
487 if (param->u.crypt.set_tx) {
488 DBG_88E("wep, set_tx = 1\n");
489 if (rtw_set_802_11_add_wep(padapter, pwep) == (u8)_FAIL)
492 DBG_88E("wep, set_tx = 0\n");
493 if (wep_key_idx >= WEP_KEYS) {
497 memcpy(&psecuritypriv->dot11DefKey[wep_key_idx].skey[0], pwep->KeyMaterial, pwep->KeyLength);
498 psecuritypriv->dot11DefKeylen[wep_key_idx] = pwep->KeyLength;
499 rtw_set_key(padapter, psecuritypriv, wep_key_idx, 0);
504 if (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) { /* 802_1x */
505 struct sta_info *psta, *pbcmc_sta;
506 struct sta_priv *pstapriv = &padapter->stapriv;
508 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_MP_STATE)) { /* sta mode */
509 psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
513 if (strcmp(param->u.crypt.alg, "none") != 0)
514 psta->ieee8021x_blocked = false;
516 if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) ||
517 (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled))
518 psta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
520 if (param->u.crypt.set_tx == 1) { /* pairwise key */
521 memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
523 if (strcmp(param->u.crypt.alg, "TKIP") == 0) { /* set mic key */
524 memcpy(psta->dot11tkiptxmickey.skey, ¶m->u.crypt.key[16], 8);
525 memcpy(psta->dot11tkiprxmickey.skey, ¶m->u.crypt.key[24], 8);
526 padapter->securitypriv.busetkipkey = false;
529 DBG_88E(" ~~~~set sta key:unicastkey\n");
531 rtw_setstakey_cmd(padapter, (unsigned char *)psta, true);
532 } else { /* group key */
533 memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
534 memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey, ¶m->u.crypt.key[16], 8);
535 memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey, ¶m->u.crypt.key[24], 8);
536 padapter->securitypriv.binstallGrpkey = true;
537 DBG_88E(" ~~~~set sta key:groupkey\n");
539 padapter->securitypriv.dot118021XGrpKeyid = param->u.crypt.idx;
541 rtw_set_key(padapter, &padapter->securitypriv, param->u.crypt.idx, 1);
542 #ifdef CONFIG_88EU_P2P
543 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_PROVISIONING_ING))
544 rtw_p2p_set_state(pwdinfo, P2P_STATE_PROVISIONING_DONE);
545 #endif /* CONFIG_88EU_P2P */
548 pbcmc_sta = rtw_get_bcmc_stainfo(padapter);
552 /* Jeff: don't disable ieee8021x_blocked while clearing key */
553 if (strcmp(param->u.crypt.alg, "none") != 0)
554 pbcmc_sta->ieee8021x_blocked = false;
556 if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) ||
557 (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled))
558 pbcmc_sta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
570 static int rtw_set_wpa_ie(struct adapter *padapter, char *pie, unsigned short ielen)
573 int group_cipher = 0, pairwise_cipher = 0;
575 #ifdef CONFIG_88EU_P2P
576 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
577 #endif /* CONFIG_88EU_P2P */
579 if (ielen > MAX_WPA_IE_LEN || !pie) {
580 _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
588 buf = kzalloc(ielen, GFP_KERNEL);
594 memcpy(buf, pie, ielen);
599 DBG_88E("\n wpa_ie(length:%d):\n", ielen);
600 for (i = 0; i < ielen; i += 8)
601 DBG_88E("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]);
604 if (ielen < RSN_HEADER_LEN) {
609 if (rtw_parse_wpa_ie(buf, ielen, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
610 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
611 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPAPSK;
612 memcpy(padapter->securitypriv.supplicant_ie, &buf[0], ielen);
615 if (rtw_parse_wpa2_ie(buf, ielen, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
616 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
617 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPA2PSK;
618 memcpy(padapter->securitypriv.supplicant_ie, &buf[0], ielen);
621 switch (group_cipher) {
622 case WPA_CIPHER_NONE:
623 padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
624 padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
626 case WPA_CIPHER_WEP40:
627 padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_;
628 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
630 case WPA_CIPHER_TKIP:
631 padapter->securitypriv.dot118021XGrpPrivacy = _TKIP_;
632 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
634 case WPA_CIPHER_CCMP:
635 padapter->securitypriv.dot118021XGrpPrivacy = _AES_;
636 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
638 case WPA_CIPHER_WEP104:
639 padapter->securitypriv.dot118021XGrpPrivacy = _WEP104_;
640 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
644 switch (pairwise_cipher) {
645 case WPA_CIPHER_NONE:
646 padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
647 padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
649 case WPA_CIPHER_WEP40:
650 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
651 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
653 case WPA_CIPHER_TKIP:
654 padapter->securitypriv.dot11PrivacyAlgrthm = _TKIP_;
655 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
657 case WPA_CIPHER_CCMP:
658 padapter->securitypriv.dot11PrivacyAlgrthm = _AES_;
659 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
661 case WPA_CIPHER_WEP104:
662 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_;
663 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
667 _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
670 u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
672 while (cnt < ielen) {
674 if ((eid == _VENDOR_SPECIFIC_IE_) && (!memcmp(&buf[cnt + 2], wps_oui, 4))) {
675 DBG_88E("SET WPS_IE\n");
677 padapter->securitypriv.wps_ie_len = ((buf[cnt + 1] + 2) < (MAX_WPA_IE_LEN << 2)) ? (buf[cnt + 1] + 2) : (MAX_WPA_IE_LEN << 2);
679 memcpy(padapter->securitypriv.wps_ie, &buf[cnt], padapter->securitypriv.wps_ie_len);
681 set_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS);
682 #ifdef CONFIG_88EU_P2P
683 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_OK))
684 rtw_p2p_set_state(pwdinfo, P2P_STATE_PROVISIONING_ING);
685 #endif /* CONFIG_88EU_P2P */
686 cnt += buf[cnt + 1] + 2;
689 cnt += buf[cnt + 1] + 2; /* goto next */
700 typedef unsigned char NDIS_802_11_RATES_EX[NDIS_802_11_LENGTH_RATES_EX];
702 static int rtw_wx_get_name(struct net_device *dev,
703 struct iw_request_info *info,
704 union iwreq_data *wrqu, char *extra)
706 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
710 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
711 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
712 NDIS_802_11_RATES_EX *prates = NULL;
714 if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE)) {
715 /* parsing HT_CAP_IE */
716 p = rtw_get_ie(&pcur_bss->IEs[12], _HT_CAPABILITY_IE_, &ht_ielen, pcur_bss->IELength - 12);
717 if (p && ht_ielen > 0)
720 prates = &pcur_bss->SupportedRates;
722 if (rtw_is_cckratesonly_included((u8 *)prates)) {
724 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11bn");
726 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
727 } else if (rtw_is_cckrates_included((u8 *)prates)) {
729 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11bgn");
731 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11bg");
734 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11gn");
736 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11g");
739 snprintf(wrqu->name, IFNAMSIZ, "unassociated");
747 static int rtw_wx_get_freq(struct net_device *dev,
748 struct iw_request_info *info,
749 union iwreq_data *wrqu, char *extra)
751 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
752 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
753 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
755 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
756 /* wrqu->freq.m = ieee80211_wlan_frequencies[pcur_bss->Configuration.DSConfig-1] * 100000; */
757 wrqu->freq.m = rtw_ch2freq(pcur_bss->Configuration.DSConfig) * 100000;
759 wrqu->freq.i = pcur_bss->Configuration.DSConfig;
761 wrqu->freq.m = rtw_ch2freq(padapter->mlmeextpriv.cur_channel) * 100000;
763 wrqu->freq.i = padapter->mlmeextpriv.cur_channel;
769 static int rtw_wx_set_mode(struct net_device *dev, struct iw_request_info *a,
770 union iwreq_data *wrqu, char *b)
772 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
773 enum ndis_802_11_network_infra networkType;
778 if (_FAIL == rtw_pwr_wakeup(padapter)) {
783 if (!padapter->hw_init_completed) {
788 switch (wrqu->mode) {
790 networkType = Ndis802_11AutoUnknown;
791 DBG_88E("set_mode = IW_MODE_AUTO\n");
794 networkType = Ndis802_11IBSS;
795 DBG_88E("set_mode = IW_MODE_ADHOC\n");
798 networkType = Ndis802_11APMode;
799 DBG_88E("set_mode = IW_MODE_MASTER\n");
802 networkType = Ndis802_11Infrastructure;
803 DBG_88E("set_mode = IW_MODE_INFRA\n");
809 if (!rtw_set_802_11_infrastructure_mode(padapter, networkType)) {
813 rtw_setopmode_cmd(padapter, networkType);
819 static int rtw_wx_get_mode(struct net_device *dev, struct iw_request_info *a,
820 union iwreq_data *wrqu, char *b)
822 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
823 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
825 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
826 wrqu->mode = IW_MODE_INFRA;
827 else if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) ||
828 (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)))
829 wrqu->mode = IW_MODE_ADHOC;
830 else if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
831 wrqu->mode = IW_MODE_MASTER;
833 wrqu->mode = IW_MODE_AUTO;
840 static int rtw_wx_set_pmkid(struct net_device *dev,
841 struct iw_request_info *a,
842 union iwreq_data *wrqu, char *extra)
844 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
845 u8 j, blInserted = false;
847 struct security_priv *psecuritypriv = &padapter->securitypriv;
848 struct iw_pmksa *pPMK = (struct iw_pmksa *)extra;
849 u8 strZeroMacAddress[ETH_ALEN] = {0x00};
850 u8 strIssueBssid[ETH_ALEN] = {0x00};
852 memcpy(strIssueBssid, pPMK->bssid.sa_data, ETH_ALEN);
853 if (pPMK->cmd == IW_PMKSA_ADD) {
854 DBG_88E("[rtw_wx_set_pmkid] IW_PMKSA_ADD!\n");
855 if (!memcmp(strIssueBssid, strZeroMacAddress, ETH_ALEN))
861 /* overwrite PMKID */
862 for (j = 0; j < NUM_PMKID_CACHE; j++) {
863 if (!memcmp(psecuritypriv->PMKIDList[j].Bssid, strIssueBssid, ETH_ALEN)) {
864 /* BSSID is matched, the same AP => rewrite with new PMKID. */
865 DBG_88E("[rtw_wx_set_pmkid] BSSID exists in the PMKList.\n");
866 memcpy(psecuritypriv->PMKIDList[j].PMKID, pPMK->pmkid, IW_PMKID_LEN);
867 psecuritypriv->PMKIDList[j].bUsed = true;
868 psecuritypriv->PMKIDIndex = j + 1;
875 /* Find a new entry */
876 DBG_88E("[rtw_wx_set_pmkid] Use the new entry index = %d for this PMKID.\n",
877 psecuritypriv->PMKIDIndex);
879 memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].Bssid, strIssueBssid, ETH_ALEN);
880 memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].PMKID, pPMK->pmkid, IW_PMKID_LEN);
882 psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].bUsed = true;
883 psecuritypriv->PMKIDIndex++;
884 if (psecuritypriv->PMKIDIndex == 16)
885 psecuritypriv->PMKIDIndex = 0;
887 } else if (pPMK->cmd == IW_PMKSA_REMOVE) {
888 DBG_88E("[rtw_wx_set_pmkid] IW_PMKSA_REMOVE!\n");
890 for (j = 0; j < NUM_PMKID_CACHE; j++) {
891 if (!memcmp(psecuritypriv->PMKIDList[j].Bssid, strIssueBssid, ETH_ALEN)) {
892 /* BSSID is matched, the same AP => Remove this PMKID information and reset it. */
893 memset(psecuritypriv->PMKIDList[j].Bssid, 0x00, ETH_ALEN);
894 psecuritypriv->PMKIDList[j].bUsed = false;
898 } else if (pPMK->cmd == IW_PMKSA_FLUSH) {
899 DBG_88E("[rtw_wx_set_pmkid] IW_PMKSA_FLUSH!\n");
900 memset(&psecuritypriv->PMKIDList[0], 0x00, sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE);
901 psecuritypriv->PMKIDIndex = 0;
907 static int rtw_wx_get_sens(struct net_device *dev,
908 struct iw_request_info *info,
909 union iwreq_data *wrqu, char *extra)
911 wrqu->sens.value = 0;
912 wrqu->sens.fixed = 0; /* no auto select */
913 wrqu->sens.disabled = 1;
917 static int rtw_wx_get_range(struct net_device *dev,
918 struct iw_request_info *info,
919 union iwreq_data *wrqu, char *extra)
921 struct iw_range *range = (struct iw_range *)extra;
922 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
923 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
928 wrqu->data.length = sizeof(*range);
929 memset(range, 0, sizeof(*range));
931 /* Let's try to keep this struct in the same order as in
932 * linux/include/wireless.h
935 /* TODO: See what values we can set, and remove the ones we can't
936 * set, or fill them with some default data.
939 /* ~5 Mb/s real (802.11b) */
940 range->throughput = 5 * 1000 * 1000;
942 /* signal level threshold range */
944 /* percent values between 0 and 100. */
945 range->max_qual.qual = 100;
946 range->max_qual.level = 100;
947 range->max_qual.noise = 100;
948 range->max_qual.updated = 7; /* Updated all three */
950 range->avg_qual.qual = 92; /* > 8% missed beacons is 'bad' */
951 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
952 range->avg_qual.level = 178; /* -78 dBm */
953 range->avg_qual.noise = 0;
954 range->avg_qual.updated = 7; /* Updated all three */
956 range->num_bitrates = RATE_COUNT;
958 for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++)
959 range->bitrate[i] = rtw_rates[i];
961 range->min_frag = MIN_FRAG_THRESHOLD;
962 range->max_frag = MAX_FRAG_THRESHOLD;
966 range->we_version_compiled = WIRELESS_EXT;
967 range->we_version_source = 16;
969 for (i = 0, val = 0; i < MAX_CHANNEL_NUM; i++) {
970 /* Include only legal frequencies for some countries */
971 if (pmlmeext->channel_set[i].ChannelNum != 0) {
972 range->freq[val].i = pmlmeext->channel_set[i].ChannelNum;
973 range->freq[val].m = rtw_ch2freq(pmlmeext->channel_set[i].ChannelNum) * 100000;
974 range->freq[val].e = 1;
978 if (val == IW_MAX_FREQUENCIES)
982 range->num_channels = val;
983 range->num_frequency = val;
985 /* The following code will proivde the security capability to network manager. */
986 /* If the driver doesn't provide this capability to network manager, */
987 /* the WPA/WPA2 routers can't be chosen in the network manager. */
990 #define IW_SCAN_CAPA_NONE 0x00
991 #define IW_SCAN_CAPA_ESSID 0x01
992 #define IW_SCAN_CAPA_BSSID 0x02
993 #define IW_SCAN_CAPA_CHANNEL 0x04
994 #define IW_SCAN_CAPA_MODE 0x08
995 #define IW_SCAN_CAPA_RATE 0x10
996 #define IW_SCAN_CAPA_TYPE 0x20
997 #define IW_SCAN_CAPA_TIME 0x40
1000 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
1001 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
1003 range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE |
1004 IW_SCAN_CAPA_BSSID | IW_SCAN_CAPA_CHANNEL |
1005 IW_SCAN_CAPA_MODE | IW_SCAN_CAPA_RATE;
1011 /* set bssid flow */
1012 /* s1. rtw_set_802_11_infrastructure_mode() */
1013 /* s2. rtw_set_802_11_authentication_mode() */
1014 /* s3. set_802_11_encryption_mode() */
1015 /* s4. rtw_set_802_11_bssid() */
1016 static int rtw_wx_set_wap(struct net_device *dev,
1017 struct iw_request_info *info,
1018 union iwreq_data *awrq,
1022 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1023 struct sockaddr *temp = (struct sockaddr *)awrq;
1024 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1025 struct list_head *phead;
1026 u8 *dst_bssid, *src_bssid;
1027 struct __queue *queue = &pmlmepriv->scanned_queue;
1028 struct wlan_network *pnetwork = NULL;
1029 enum ndis_802_11_auth_mode authmode;
1033 if (_FAIL == rtw_pwr_wakeup(padapter)) {
1038 if (!padapter->bup) {
1043 if (temp->sa_family != ARPHRD_ETHER) {
1048 authmode = padapter->securitypriv.ndisauthtype;
1049 spin_lock_bh(&queue->lock);
1050 phead = get_list_head(queue);
1051 pmlmepriv->pscanned = phead->next;
1053 while (phead != pmlmepriv->pscanned) {
1055 pnetwork = container_of(pmlmepriv->pscanned, struct wlan_network, list);
1057 pmlmepriv->pscanned = pmlmepriv->pscanned->next;
1059 dst_bssid = pnetwork->network.MacAddress;
1061 src_bssid = temp->sa_data;
1063 if ((!memcmp(dst_bssid, src_bssid, ETH_ALEN))) {
1064 if (!rtw_set_802_11_infrastructure_mode(padapter, pnetwork->network.InfrastructureMode)) {
1066 spin_unlock_bh(&queue->lock);
1073 spin_unlock_bh(&queue->lock);
1075 rtw_set_802_11_authentication_mode(padapter, authmode);
1076 /* set_802_11_encryption_mode(padapter, padapter->securitypriv.ndisencryptstatus); */
1077 if (!rtw_set_802_11_bssid(padapter, temp->sa_data)) {
1089 static int rtw_wx_get_wap(struct net_device *dev,
1090 struct iw_request_info *info,
1091 union iwreq_data *wrqu, char *extra)
1093 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1094 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1095 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
1097 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1099 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
1101 if (check_fwstate(pmlmepriv, _FW_LINKED) ||
1102 check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) ||
1103 check_fwstate(pmlmepriv, WIFI_AP_STATE))
1104 memcpy(wrqu->ap_addr.sa_data, pcur_bss->MacAddress, ETH_ALEN);
1106 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
1113 static int rtw_wx_set_mlme(struct net_device *dev,
1114 struct iw_request_info *info,
1115 union iwreq_data *wrqu, char *extra)
1119 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1120 struct iw_mlme *mlme = (struct iw_mlme *)extra;
1125 DBG_88E("%s\n", __func__);
1127 reason = mlme->reason_code;
1129 DBG_88E("%s, cmd =%d, reason =%d\n", __func__, mlme->cmd, reason);
1131 switch (mlme->cmd) {
1132 case IW_MLME_DEAUTH:
1133 if (!rtw_set_802_11_disassociate(padapter))
1136 case IW_MLME_DISASSOC:
1137 if (!rtw_set_802_11_disassociate(padapter))
1146 static int rtw_wx_set_scan(struct net_device *dev, struct iw_request_info *a,
1147 union iwreq_data *wrqu, char *extra)
1151 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1152 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1153 struct ndis_802_11_ssid ssid[RTW_SSID_SCAN_AMOUNT];
1154 #ifdef CONFIG_88EU_P2P
1155 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
1156 #endif /* CONFIG_88EU_P2P */
1158 if (padapter->registrypriv.mp_mode == 1) {
1159 if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
1164 if (_FAIL == rtw_pwr_wakeup(padapter)) {
1169 if (padapter->bDriverStopped) {
1170 DBG_88E("bDriverStopped =%d\n", padapter->bDriverStopped);
1175 if (!padapter->bup) {
1180 if (!padapter->hw_init_completed) {
1185 /* When Busy Traffic, driver do not site survey. So driver return success. */
1186 /* wpa_supplicant will not issue SIOCSIWSCAN cmd again after scan timeout. */
1187 /* modify by thomas 2011-02-22. */
1188 if (pmlmepriv->LinkDetectInfo.bBusyTraffic) {
1189 indicate_wx_scan_complete_event(padapter);
1193 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING)) {
1194 indicate_wx_scan_complete_event(padapter);
1198 /* For the DMP WiFi Display project, the driver won't to scan because */
1199 /* the pmlmepriv->scan_interval is always equal to 3. */
1200 /* So, the wpa_supplicant won't find out the WPS SoftAP. */
1202 #ifdef CONFIG_88EU_P2P
1203 if (pwdinfo->p2p_state != P2P_STATE_NONE) {
1204 rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
1205 rtw_p2p_set_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH);
1206 rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_FULL);
1207 rtw_free_network_queue(padapter, true);
1209 #endif /* CONFIG_88EU_P2P */
1211 memset(ssid, 0, sizeof(struct ndis_802_11_ssid) * RTW_SSID_SCAN_AMOUNT);
1213 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
1214 struct iw_scan_req *req = (struct iw_scan_req *)extra;
1216 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1217 int len = min((int)req->essid_len, IW_ESSID_MAX_SIZE);
1219 memcpy(ssid[0].Ssid, req->essid, len);
1220 ssid[0].SsidLength = len;
1222 DBG_88E("IW_SCAN_THIS_ESSID, ssid =%s, len =%d\n", req->essid, req->essid_len);
1224 spin_lock_bh(&pmlmepriv->lock);
1226 _status = rtw_sitesurvey_cmd(padapter, ssid, 1, NULL, 0);
1228 spin_unlock_bh(&pmlmepriv->lock);
1229 } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) {
1230 DBG_88E("rtw_wx_set_scan, req->scan_type == IW_SCAN_TYPE_PASSIVE\n");
1233 if (wrqu->data.length >= WEXT_CSCAN_HEADER_SIZE &&
1234 !memcmp(extra, WEXT_CSCAN_HEADER, WEXT_CSCAN_HEADER_SIZE)) {
1235 int len = wrqu->data.length - WEXT_CSCAN_HEADER_SIZE;
1236 char *pos = extra + WEXT_CSCAN_HEADER_SIZE;
1246 case WEXT_CSCAN_SSID_SECTION:
1251 sec_len = *(pos++); len -= 1;
1252 if (sec_len > 0 && sec_len <= len) {
1253 ssid[ssid_index].SsidLength = sec_len;
1254 memcpy(ssid[ssid_index].Ssid, pos, ssid[ssid_index].SsidLength);
1260 case WEXT_CSCAN_TYPE_SECTION:
1261 case WEXT_CSCAN_CHANNEL_SECTION:
1265 case WEXT_CSCAN_PASV_DWELL_SECTION:
1266 case WEXT_CSCAN_HOME_DWELL_SECTION:
1267 case WEXT_CSCAN_ACTV_DWELL_SECTION:
1272 len = 0; /* stop parsing */
1276 /* it has still some scan parameter to parse, we only do this now... */
1277 _status = rtw_set_802_11_bssid_list_scan(padapter, ssid, RTW_SSID_SCAN_AMOUNT);
1279 _status = rtw_set_802_11_bssid_list_scan(padapter, NULL, 0);
1291 static int rtw_wx_get_scan(struct net_device *dev, struct iw_request_info *a,
1292 union iwreq_data *wrqu, char *extra)
1294 struct list_head *plist, *phead;
1295 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1296 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1297 struct __queue *queue = &pmlmepriv->scanned_queue;
1298 struct wlan_network *pnetwork = NULL;
1300 char *stop = ev + wrqu->data.length;
1303 u32 wait_for_surveydone;
1305 #ifdef CONFIG_88EU_P2P
1306 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
1307 #endif /* CONFIG_88EU_P2P */
1309 if (padapter->pwrctrlpriv.brfoffbyhw && padapter->bDriverStopped) {
1314 #ifdef CONFIG_88EU_P2P
1315 if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
1316 /* P2P is enabled */
1317 wait_for_surveydone = 200;
1319 /* P2P is disabled */
1320 wait_for_surveydone = 100;
1324 wait_for_surveydone = 100;
1326 #endif /* CONFIG_88EU_P2P */
1328 wait_status = _FW_UNDER_SURVEY | _FW_UNDER_LINKING;
1330 while (check_fwstate(pmlmepriv, wait_status)) {
1333 if (cnt > wait_for_surveydone)
1337 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
1339 phead = get_list_head(queue);
1340 plist = phead->next;
1342 while (phead != plist) {
1343 if ((stop - ev) < SCAN_ITEM_SIZE) {
1348 pnetwork = container_of(plist, struct wlan_network, list);
1350 /* report network only if the current channel set contains the channel to which this network belongs */
1351 if (rtw_ch_set_search_ch(padapter->mlmeextpriv.channel_set, pnetwork->network.Configuration.DSConfig) >= 0)
1352 ev = translate_scan(padapter, a, pnetwork, ev, stop);
1354 plist = plist->next;
1357 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
1359 wrqu->data.length = ev - extra;
1360 wrqu->data.flags = 0;
1368 /* s1. rtw_set_802_11_infrastructure_mode() */
1369 /* s2. set_802_11_authenticaion_mode() */
1370 /* s3. set_802_11_encryption_mode() */
1371 /* s4. rtw_set_802_11_ssid() */
1372 static int rtw_wx_set_essid(struct net_device *dev,
1373 struct iw_request_info *a,
1374 union iwreq_data *wrqu, char *extra)
1376 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1377 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1378 struct __queue *queue = &pmlmepriv->scanned_queue;
1379 struct list_head *phead;
1380 struct wlan_network *pnetwork = NULL;
1381 enum ndis_802_11_auth_mode authmode;
1382 struct ndis_802_11_ssid ndis_ssid;
1383 u8 *dst_ssid, *src_ssid;
1387 if (_FAIL == rtw_pwr_wakeup(padapter)) {
1392 if (!padapter->bup) {
1397 if (wrqu->essid.length > IW_ESSID_MAX_SIZE) {
1402 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1407 authmode = padapter->securitypriv.ndisauthtype;
1408 DBG_88E("=>%s\n", __func__);
1409 if (wrqu->essid.flags && wrqu->essid.length) {
1410 len = (wrqu->essid.length < IW_ESSID_MAX_SIZE) ? wrqu->essid.length : IW_ESSID_MAX_SIZE;
1412 if (wrqu->essid.length != 33)
1413 DBG_88E("ssid =%s, len =%d\n", extra, wrqu->essid.length);
1415 memset(&ndis_ssid, 0, sizeof(struct ndis_802_11_ssid));
1416 ndis_ssid.SsidLength = len;
1417 memcpy(ndis_ssid.Ssid, extra, len);
1418 src_ssid = ndis_ssid.Ssid;
1420 spin_lock_bh(&queue->lock);
1421 phead = get_list_head(queue);
1422 pmlmepriv->pscanned = phead->next;
1424 while (phead != pmlmepriv->pscanned) {
1425 pnetwork = container_of(pmlmepriv->pscanned, struct wlan_network, list);
1427 pmlmepriv->pscanned = pmlmepriv->pscanned->next;
1429 dst_ssid = pnetwork->network.Ssid.Ssid;
1431 if ((!memcmp(dst_ssid, src_ssid, ndis_ssid.SsidLength)) &&
1432 (pnetwork->network.Ssid.SsidLength == ndis_ssid.SsidLength)) {
1434 if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) {
1435 if (pnetwork->network.InfrastructureMode != pmlmepriv->cur_network.network.InfrastructureMode)
1439 if (!rtw_set_802_11_infrastructure_mode(padapter, pnetwork->network.InfrastructureMode)) {
1441 spin_unlock_bh(&queue->lock);
1448 spin_unlock_bh(&queue->lock);
1449 rtw_set_802_11_authentication_mode(padapter, authmode);
1450 if (!rtw_set_802_11_ssid(padapter, &ndis_ssid)) {
1458 DBG_88E("<=%s, ret %d\n", __func__, ret);
1465 static int rtw_wx_get_essid(struct net_device *dev,
1466 struct iw_request_info *a,
1467 union iwreq_data *wrqu, char *extra)
1470 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1471 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1472 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
1474 if ((check_fwstate(pmlmepriv, _FW_LINKED)) ||
1475 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE))) {
1476 len = pcur_bss->Ssid.SsidLength;
1477 memcpy(extra, pcur_bss->Ssid.Ssid, len);
1482 wrqu->essid.length = len;
1483 wrqu->essid.flags = 1;
1488 static int rtw_wx_set_rate(struct net_device *dev,
1489 struct iw_request_info *a,
1490 union iwreq_data *wrqu, char *extra)
1493 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1494 u8 datarates[NumRates];
1495 u32 target_rate = wrqu->bitrate.value;
1496 u32 fixed = wrqu->bitrate.fixed;
1498 u8 mpdatarate[NumRates] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0xff};
1500 if (target_rate == -1) {
1504 target_rate = target_rate / 100000;
1506 switch (target_rate) {
1550 for (i = 0; i < NumRates; i++) {
1551 if (ratevalue == mpdatarate[i]) {
1552 datarates[i] = mpdatarate[i];
1556 datarates[i] = 0xff;
1560 if (rtw_setdatarate_cmd(padapter, datarates) != _SUCCESS)
1566 static int rtw_wx_get_rate(struct net_device *dev,
1567 struct iw_request_info *info,
1568 union iwreq_data *wrqu, char *extra)
1572 max_rate = rtw_get_cur_max_rate((struct adapter *)rtw_netdev_priv(dev));
1577 wrqu->bitrate.fixed = 0; /* no auto select */
1578 wrqu->bitrate.value = max_rate * 100000;
1583 static int rtw_wx_set_rts(struct net_device *dev,
1584 struct iw_request_info *info,
1585 union iwreq_data *wrqu, char *extra)
1587 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1591 if (wrqu->rts.disabled) {
1592 padapter->registrypriv.rts_thresh = 2347;
1594 if (wrqu->rts.value < 0 ||
1595 wrqu->rts.value > 2347)
1598 padapter->registrypriv.rts_thresh = wrqu->rts.value;
1601 DBG_88E("%s, rts_thresh =%d\n", __func__, padapter->registrypriv.rts_thresh);
1608 static int rtw_wx_get_rts(struct net_device *dev,
1609 struct iw_request_info *info,
1610 union iwreq_data *wrqu, char *extra)
1612 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1616 DBG_88E("%s, rts_thresh =%d\n", __func__, padapter->registrypriv.rts_thresh);
1618 wrqu->rts.value = padapter->registrypriv.rts_thresh;
1619 wrqu->rts.fixed = 0; /* no auto select */
1620 /* wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); */
1627 static int rtw_wx_set_frag(struct net_device *dev,
1628 struct iw_request_info *info,
1629 union iwreq_data *wrqu, char *extra)
1631 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1635 if (wrqu->frag.disabled) {
1636 padapter->xmitpriv.frag_len = MAX_FRAG_THRESHOLD;
1638 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
1639 wrqu->frag.value > MAX_FRAG_THRESHOLD)
1642 padapter->xmitpriv.frag_len = wrqu->frag.value & ~0x1;
1645 DBG_88E("%s, frag_len =%d\n", __func__, padapter->xmitpriv.frag_len);
1652 static int rtw_wx_get_frag(struct net_device *dev,
1653 struct iw_request_info *info,
1654 union iwreq_data *wrqu, char *extra)
1656 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1660 DBG_88E("%s, frag_len =%d\n", __func__, padapter->xmitpriv.frag_len);
1662 wrqu->frag.value = padapter->xmitpriv.frag_len;
1663 wrqu->frag.fixed = 0; /* no auto select */
1670 static int rtw_wx_get_retry(struct net_device *dev,
1671 struct iw_request_info *info,
1672 union iwreq_data *wrqu, char *extra)
1674 wrqu->retry.value = 7;
1675 wrqu->retry.fixed = 0; /* no auto select */
1676 wrqu->retry.disabled = 1;
1681 static int rtw_wx_set_enc(struct net_device *dev,
1682 struct iw_request_info *info,
1683 union iwreq_data *wrqu, char *keybuf)
1686 u32 keyindex_provided;
1687 struct ndis_802_11_wep wep;
1688 enum ndis_802_11_auth_mode authmode;
1690 struct iw_point *erq = &wrqu->encoding;
1691 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1692 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
1693 DBG_88E("+rtw_wx_set_enc, flags = 0x%x\n", erq->flags);
1695 memset(&wep, 0, sizeof(struct ndis_802_11_wep));
1697 key = erq->flags & IW_ENCODE_INDEX;
1701 if (erq->flags & IW_ENCODE_DISABLED) {
1702 DBG_88E("EncryptionDisabled\n");
1703 padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
1704 padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
1705 padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
1706 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
1707 authmode = Ndis802_11AuthModeOpen;
1708 padapter->securitypriv.ndisauthtype = authmode;
1717 keyindex_provided = 1;
1719 keyindex_provided = 0;
1720 key = padapter->securitypriv.dot11PrivacyKeyIndex;
1721 DBG_88E("rtw_wx_set_enc, key =%d\n", key);
1724 /* set authentication mode */
1725 if (erq->flags & IW_ENCODE_OPEN) {
1726 DBG_88E("rtw_wx_set_enc():IW_ENCODE_OPEN\n");
1727 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;/* Ndis802_11EncryptionDisabled; */
1728 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
1729 padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
1730 padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
1731 authmode = Ndis802_11AuthModeOpen;
1732 padapter->securitypriv.ndisauthtype = authmode;
1733 } else if (erq->flags & IW_ENCODE_RESTRICTED) {
1734 DBG_88E("rtw_wx_set_enc():IW_ENCODE_RESTRICTED\n");
1735 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
1736 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Shared;
1737 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
1738 padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_;
1739 authmode = Ndis802_11AuthModeShared;
1740 padapter->securitypriv.ndisauthtype = authmode;
1742 DBG_88E("rtw_wx_set_enc():erq->flags = 0x%x\n", erq->flags);
1744 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;/* Ndis802_11EncryptionDisabled; */
1745 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
1746 padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
1747 padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
1748 authmode = Ndis802_11AuthModeOpen;
1749 padapter->securitypriv.ndisauthtype = authmode;
1753 if (erq->length > 0) {
1754 wep.KeyLength = erq->length <= 5 ? 5 : 13;
1756 wep.Length = wep.KeyLength + FIELD_OFFSET(struct ndis_802_11_wep, KeyMaterial);
1760 if (keyindex_provided == 1) {
1761 /* set key_id only, no given KeyMaterial(erq->length == 0). */
1762 padapter->securitypriv.dot11PrivacyKeyIndex = key;
1764 DBG_88E("(keyindex_provided == 1), keyid =%d, key_len =%d\n", key, padapter->securitypriv.dot11DefKeylen[key]);
1766 switch (padapter->securitypriv.dot11DefKeylen[key]) {
1768 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
1771 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_;
1774 padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
1782 wep.KeyIndex |= 0x80000000;
1784 memcpy(wep.KeyMaterial, keybuf, wep.KeyLength);
1786 if (!rtw_set_802_11_add_wep(padapter, &wep)) {
1787 if (rf_on == pwrpriv->rf_pwrstate)
1799 static int rtw_wx_get_enc(struct net_device *dev,
1800 struct iw_request_info *info,
1801 union iwreq_data *wrqu, char *keybuf)
1804 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1805 struct iw_point *erq = &wrqu->encoding;
1806 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1810 if (check_fwstate(pmlmepriv, _FW_LINKED) != true) {
1811 if (!check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
1813 erq->flags |= IW_ENCODE_DISABLED;
1818 key = erq->flags & IW_ENCODE_INDEX;
1825 key = padapter->securitypriv.dot11PrivacyKeyIndex;
1828 erq->flags = key + 1;
1830 switch (padapter->securitypriv.ndisencryptstatus) {
1831 case Ndis802_11EncryptionNotSupported:
1832 case Ndis802_11EncryptionDisabled:
1834 erq->flags |= IW_ENCODE_DISABLED;
1836 case Ndis802_11Encryption1Enabled:
1837 erq->length = padapter->securitypriv.dot11DefKeylen[key];
1839 memcpy(keybuf, padapter->securitypriv.dot11DefKey[key].skey, padapter->securitypriv.dot11DefKeylen[key]);
1841 erq->flags |= IW_ENCODE_ENABLED;
1843 if (padapter->securitypriv.ndisauthtype == Ndis802_11AuthModeOpen)
1844 erq->flags |= IW_ENCODE_OPEN;
1845 else if (padapter->securitypriv.ndisauthtype == Ndis802_11AuthModeShared)
1846 erq->flags |= IW_ENCODE_RESTRICTED;
1849 erq->flags |= IW_ENCODE_DISABLED;
1852 case Ndis802_11Encryption2Enabled:
1853 case Ndis802_11Encryption3Enabled:
1855 erq->flags |= (IW_ENCODE_ENABLED | IW_ENCODE_OPEN | IW_ENCODE_NOKEY);
1859 erq->flags |= IW_ENCODE_DISABLED;
1867 static int rtw_wx_get_power(struct net_device *dev,
1868 struct iw_request_info *info,
1869 union iwreq_data *wrqu, char *extra)
1871 wrqu->power.value = 0;
1872 wrqu->power.fixed = 0; /* no auto select */
1873 wrqu->power.disabled = 1;
1878 static int rtw_wx_set_gen_ie(struct net_device *dev,
1879 struct iw_request_info *info,
1880 union iwreq_data *wrqu, char *extra)
1883 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1885 ret = rtw_set_wpa_ie(padapter, extra, wrqu->data.length);
1889 static int rtw_wx_set_auth(struct net_device *dev,
1890 struct iw_request_info *info,
1891 union iwreq_data *wrqu, char *extra)
1893 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1894 struct iw_param *param = (struct iw_param *)&wrqu->param;
1897 switch (param->flags & IW_AUTH_INDEX) {
1898 case IW_AUTH_WPA_VERSION:
1900 case IW_AUTH_CIPHER_PAIRWISE:
1903 case IW_AUTH_CIPHER_GROUP:
1906 case IW_AUTH_KEY_MGMT:
1908 * ??? does not use these parameters
1911 case IW_AUTH_TKIP_COUNTERMEASURES:
1913 /* wpa_supplicant is enabling the tkip countermeasure. */
1914 padapter->securitypriv.btkip_countermeasure = true;
1916 /* wpa_supplicant is disabling the tkip countermeasure. */
1917 padapter->securitypriv.btkip_countermeasure = false;
1920 case IW_AUTH_DROP_UNENCRYPTED:
1923 * wpa_supplicant calls set_wpa_enabled when the driver
1924 * is loaded and unloaded, regardless of if WPA is being
1925 * used. No other calls are made which can be used to
1926 * determine if encryption will be used or not prior to
1927 * association being expected. If encryption is not being
1928 * used, drop_unencrypted is set to false, else true -- we
1929 * can use this to determine if the CAP_PRIVACY_ON bit should
1933 if (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption1Enabled)
1934 break;/* it means init value, or using wep, ndisencryptstatus = Ndis802_11Encryption1Enabled, */
1935 /* then it needn't reset it; */
1938 padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
1939 padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
1940 padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
1941 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
1942 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
1946 case IW_AUTH_80211_AUTH_ALG:
1948 * It's the starting point of a link layer connection using wpa_supplicant
1950 if (check_fwstate(&padapter->mlmepriv, _FW_LINKED)) {
1951 LeaveAllPowerSaveMode(padapter);
1952 rtw_disassoc_cmd(padapter, 500, false);
1953 DBG_88E("%s...call rtw_indicate_disconnect\n ", __func__);
1954 rtw_indicate_disconnect(padapter);
1955 rtw_free_assoc_resources(padapter, 1);
1957 ret = wpa_set_auth_algs(dev, (u32)param->value);
1959 case IW_AUTH_WPA_ENABLED:
1961 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1963 case IW_AUTH_PRIVACY_INVOKED:
1972 static int rtw_wx_set_enc_ext(struct net_device *dev,
1973 struct iw_request_info *info,
1974 union iwreq_data *wrqu, char *extra)
1978 struct ieee_param *param = NULL;
1979 struct iw_point *pencoding = &wrqu->encoding;
1980 struct iw_encode_ext *pext = (struct iw_encode_ext *)extra;
1983 param_len = sizeof(struct ieee_param) + pext->key_len;
1984 param = kzalloc(param_len, GFP_KERNEL);
1988 param->cmd = IEEE_CMD_SET_ENCRYPTION;
1989 memset(param->sta_addr, 0xff, ETH_ALEN);
1991 switch (pext->alg) {
1992 case IW_ENCODE_ALG_NONE:
1993 /* todo: remove key */
1997 case IW_ENCODE_ALG_WEP:
2000 case IW_ENCODE_ALG_TKIP:
2003 case IW_ENCODE_ALG_CCMP:
2010 strncpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN);
2012 if (pext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2013 param->u.crypt.set_tx = 1;
2015 /* cliW: WEP does not have group key
2016 * just not checking GROUP key setting
2018 if ((pext->alg != IW_ENCODE_ALG_WEP) &&
2019 (pext->ext_flags & IW_ENCODE_EXT_GROUP_KEY))
2020 param->u.crypt.set_tx = 0;
2022 param->u.crypt.idx = (pencoding->flags & 0x00FF) - 1;
2024 if (pext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
2025 memcpy(param->u.crypt.seq, pext->rx_seq, 8);
2027 if (pext->key_len) {
2028 param->u.crypt.key_len = pext->key_len;
2029 memcpy(param->u.crypt.key, pext + 1, pext->key_len);
2032 ret = wpa_set_encryption(dev, param, param_len);
2038 static int rtw_wx_get_nick(struct net_device *dev,
2039 struct iw_request_info *info,
2040 union iwreq_data *wrqu, char *extra)
2043 wrqu->data.length = 14;
2044 wrqu->data.flags = 1;
2045 memcpy(extra, "<WIFI@REALTEK>", 14);
2048 /* dump debug info here */
2052 static int rtw_wx_read32(struct net_device *dev,
2053 struct iw_request_info *info,
2054 union iwreq_data *wrqu, char *extra)
2056 struct adapter *padapter;
2064 padapter = (struct adapter *)rtw_netdev_priv(dev);
2067 ptmp = kmalloc(len, GFP_KERNEL);
2071 if (copy_from_user(ptmp, p->pointer, len)) {
2078 sscanf(ptmp, "%d,%x", &bytes, &addr);
2082 data32 = rtw_read8(padapter, addr);
2083 sprintf(extra, "0x%02X", data32);
2086 data32 = rtw_read16(padapter, addr);
2087 sprintf(extra, "0x%04X", data32);
2090 data32 = rtw_read32(padapter, addr);
2091 sprintf(extra, "0x%08X", data32);
2094 DBG_88E(KERN_INFO "%s: usage> read [bytes],[address(hex)]\n", __func__);
2097 DBG_88E(KERN_INFO "%s: addr = 0x%08X data =%s\n", __func__, addr, extra);
2103 static int rtw_wx_write32(struct net_device *dev,
2104 struct iw_request_info *info,
2105 union iwreq_data *wrqu, char *extra)
2107 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2116 sscanf(extra, "%d,%x,%x", &bytes, &addr, &data32);
2120 rtw_write8(padapter, addr, (u8)data32);
2121 DBG_88E(KERN_INFO "%s: addr = 0x%08X data = 0x%02X\n", __func__, addr, (u8)data32);
2124 rtw_write16(padapter, addr, (u16)data32);
2125 DBG_88E(KERN_INFO "%s: addr = 0x%08X data = 0x%04X\n", __func__, addr, (u16)data32);
2128 rtw_write32(padapter, addr, data32);
2129 DBG_88E(KERN_INFO "%s: addr = 0x%08X data = 0x%08X\n", __func__, addr, data32);
2132 DBG_88E(KERN_INFO "%s: usage> write [bytes],[address(hex)],[data(hex)]\n", __func__);
2139 static int rtw_wx_read_rf(struct net_device *dev,
2140 struct iw_request_info *info,
2141 union iwreq_data *wrqu, char *extra)
2143 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2144 u32 path, addr, data32;
2146 path = *(u32 *)extra;
2147 addr = *((u32 *)extra + 1);
2148 data32 = rtw_hal_read_rfreg(padapter, path, addr, 0xFFFFF);
2151 * Only when wireless private ioctl is at odd order,
2152 * "extra" would be copied to user space.
2154 sprintf(extra, "0x%05x", data32);
2159 static int rtw_wx_write_rf(struct net_device *dev,
2160 struct iw_request_info *info,
2161 union iwreq_data *wrqu, char *extra)
2163 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2164 u32 path, addr, data32;
2166 path = *(u32 *)extra;
2167 addr = *((u32 *)extra + 1);
2168 data32 = *((u32 *)extra + 2);
2169 rtw_hal_write_rfreg(padapter, path, addr, 0xFFFFF, data32);
2174 static int rtw_wx_priv_null(struct net_device *dev, struct iw_request_info *a,
2175 union iwreq_data *wrqu, char *b)
2180 static int dummy(struct net_device *dev, struct iw_request_info *a,
2181 union iwreq_data *wrqu, char *b)
2186 static int rtw_wx_set_channel_plan(struct net_device *dev,
2187 struct iw_request_info *info,
2188 union iwreq_data *wrqu, char *extra)
2190 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2191 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2192 u8 channel_plan_req = (u8)(*((int *)wrqu));
2194 if (_SUCCESS == rtw_set_chplan_cmd(padapter, channel_plan_req, 1))
2195 DBG_88E("%s set channel_plan = 0x%02X\n", __func__, pmlmepriv->ChannelPlan);
2202 static int rtw_wx_set_mtk_wps_probe_ie(struct net_device *dev,
2203 struct iw_request_info *a,
2204 union iwreq_data *wrqu, char *b)
2209 static int rtw_wx_get_sensitivity(struct net_device *dev,
2210 struct iw_request_info *info,
2211 union iwreq_data *wrqu, char *buf)
2216 static int rtw_wx_set_mtk_wps_ie(struct net_device *dev,
2217 struct iw_request_info *info,
2218 union iwreq_data *wrqu, char *extra)
2224 * For all data larger than 16 octets, we need to use a
2225 * pointer to memory allocated in user space.
2227 static int rtw_drvext_hdl(struct net_device *dev, struct iw_request_info *info,
2228 union iwreq_data *wrqu, char *extra)
2233 static void rtw_dbg_mode_hdl(struct adapter *padapter, u32 id, u8 *pdata, u32 len)
2235 struct mp_rw_reg *RegRWStruct;
2236 struct rf_reg_param *prfreg;
2241 DBG_88E("%s\n", __func__);
2244 case GEN_MP_IOCTL_SUBCODE(MP_START):
2245 DBG_88E("871x_driver is only for normal mode, can't enter mp mode\n");
2247 case GEN_MP_IOCTL_SUBCODE(READ_REG):
2248 RegRWStruct = (struct mp_rw_reg *)pdata;
2249 switch (RegRWStruct->width) {
2251 RegRWStruct->value = rtw_read8(padapter, RegRWStruct->offset);
2254 RegRWStruct->value = rtw_read16(padapter, RegRWStruct->offset);
2257 RegRWStruct->value = rtw_read32(padapter, RegRWStruct->offset);
2264 case GEN_MP_IOCTL_SUBCODE(WRITE_REG):
2265 RegRWStruct = (struct mp_rw_reg *)pdata;
2266 switch (RegRWStruct->width) {
2268 rtw_write8(padapter, RegRWStruct->offset, (u8)RegRWStruct->value);
2271 rtw_write16(padapter, RegRWStruct->offset, (u16)RegRWStruct->value);
2274 rtw_write32(padapter, RegRWStruct->offset, (u32)RegRWStruct->value);
2281 case GEN_MP_IOCTL_SUBCODE(READ_RF_REG):
2283 prfreg = (struct rf_reg_param *)pdata;
2285 path = (u8)prfreg->path;
2286 offset = (u8)prfreg->offset;
2288 value = rtw_hal_read_rfreg(padapter, path, offset, 0xffffffff);
2290 prfreg->value = value;
2293 case GEN_MP_IOCTL_SUBCODE(WRITE_RF_REG):
2295 prfreg = (struct rf_reg_param *)pdata;
2297 path = (u8)prfreg->path;
2298 offset = (u8)prfreg->offset;
2299 value = prfreg->value;
2301 rtw_hal_write_rfreg(padapter, path, offset, 0xffffffff, value);
2304 case GEN_MP_IOCTL_SUBCODE(TRIGGER_GPIO):
2305 DBG_88E("==> trigger gpio 0\n");
2306 rtw_hal_set_hwreg(padapter, HW_VAR_TRIGGER_GPIO_0, NULL);
2308 case GEN_MP_IOCTL_SUBCODE(GET_WIFI_STATUS):
2309 *pdata = rtw_hal_sreset_get_wifi_status(padapter);
2316 static int rtw_mp_ioctl_hdl(struct net_device *dev, struct iw_request_info *info,
2317 union iwreq_data *wrqu, char *extra)
2320 u32 BytesRead, BytesWritten, BytesNeeded;
2321 struct oid_par_priv oid_par;
2322 struct mp_ioctl_handler *phandler;
2323 struct mp_ioctl_param *poidparam;
2326 u8 *pparmbuf = NULL, bset;
2327 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2328 struct iw_point *p = &wrqu->data;
2330 if ((!p->length) || (!p->pointer)) {
2332 goto _rtw_mp_ioctl_hdl_exit;
2335 bset = (u8)(p->flags & 0xFFFF);
2337 pparmbuf = kmalloc(len, GFP_KERNEL);
2340 goto _rtw_mp_ioctl_hdl_exit;
2343 if (copy_from_user(pparmbuf, p->pointer, len)) {
2345 goto _rtw_mp_ioctl_hdl_exit;
2348 poidparam = (struct mp_ioctl_param *)pparmbuf;
2350 if (poidparam->subcode >= MAX_MP_IOCTL_SUBCODE) {
2352 goto _rtw_mp_ioctl_hdl_exit;
2355 if (padapter->registrypriv.mp_mode == 1) {
2356 phandler = mp_ioctl_hdl + poidparam->subcode;
2358 if ((phandler->paramsize != 0) && (poidparam->len < phandler->paramsize)) {
2360 goto _rtw_mp_ioctl_hdl_exit;
2363 if (phandler->handler) {
2364 oid_par.adapter_context = padapter;
2365 oid_par.oid = phandler->oid;
2366 oid_par.information_buf = poidparam->data;
2367 oid_par.information_buf_len = poidparam->len;
2374 oid_par.bytes_rw = &BytesRead;
2375 oid_par.bytes_needed = &BytesNeeded;
2376 oid_par.type_of_oid = SET_OID;
2378 oid_par.bytes_rw = &BytesWritten;
2379 oid_par.bytes_needed = &BytesNeeded;
2380 oid_par.type_of_oid = QUERY_OID;
2383 status = phandler->handler(&oid_par);
2385 DBG_88E("rtw_mp_ioctl_hdl(): err!, subcode =%d, oid =%d, handler =%p\n",
2386 poidparam->subcode, phandler->oid, phandler->handler);
2388 goto _rtw_mp_ioctl_hdl_exit;
2391 rtw_dbg_mode_hdl(padapter, poidparam->subcode, poidparam->data, poidparam->len);
2394 if (bset == 0x00) {/* query info */
2395 if (copy_to_user(p->pointer, pparmbuf, len))
2401 goto _rtw_mp_ioctl_hdl_exit;
2404 _rtw_mp_ioctl_hdl_exit:
2410 static int rtw_get_ap_info(struct net_device *dev,
2411 struct iw_request_info *info,
2412 union iwreq_data *wrqu, char *extra)
2415 u32 cnt = 0, wpa_ielen;
2416 struct list_head *plist, *phead;
2417 unsigned char *pbuf;
2420 struct wlan_network *pnetwork = NULL;
2421 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2422 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2423 struct __queue *queue = &pmlmepriv->scanned_queue;
2424 struct iw_point *pdata = &wrqu->data;
2426 DBG_88E("+rtw_get_aplist_info\n");
2428 if (padapter->bDriverStopped || !pdata) {
2433 while ((check_fwstate(pmlmepriv, (_FW_UNDER_SURVEY | _FW_UNDER_LINKING)))) {
2440 if (pdata->length >= 32) {
2441 if (copy_from_user(data, pdata->pointer, 32)) {
2450 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
2452 phead = get_list_head(queue);
2453 plist = phead->next;
2455 while (phead != plist) {
2456 pnetwork = container_of(plist, struct wlan_network, list);
2458 if (!mac_pton(data, bssid)) {
2459 DBG_88E("Invalid BSSID '%s'.\n", (u8 *)data);
2460 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
2464 if (!memcmp(bssid, pnetwork->network.MacAddress, ETH_ALEN)) {
2465 /* BSSID match, then check if supporting wpa/wpa2 */
2466 DBG_88E("BSSID:%pM\n", (bssid));
2468 pbuf = rtw_get_wpa_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
2469 if (pbuf && (wpa_ielen > 0)) {
2474 pbuf = rtw_get_wpa2_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
2475 if (pbuf && (wpa_ielen > 0)) {
2481 plist = plist->next;
2484 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
2486 if (pdata->length >= 34) {
2487 if (copy_to_user(pdata->pointer + 32, (u8 *)&pdata->flags, 1)) {
2498 static int rtw_set_pid(struct net_device *dev,
2499 struct iw_request_info *info,
2500 union iwreq_data *wrqu, char *extra)
2503 struct adapter *padapter = rtw_netdev_priv(dev);
2504 int *pdata = (int *)wrqu;
2507 if (padapter->bDriverStopped || !pdata) {
2513 if (selector < 3 && selector >= 0) {
2514 padapter->pid[selector] = *(pdata + 1);
2515 ui_pid[selector] = *(pdata + 1);
2516 DBG_88E("%s set pid[%d] =%d\n", __func__, selector, padapter->pid[selector]);
2518 DBG_88E("%s selector %d error\n", __func__, selector);
2524 static int rtw_wps_start(struct net_device *dev,
2525 struct iw_request_info *info,
2526 union iwreq_data *wrqu, char *extra)
2529 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2530 struct iw_point *pdata = &wrqu->data;
2531 u32 u32wps_start = 0;
2535 ret = copy_from_user((void *)&u32wps_start, pdata->pointer, 4);
2541 if (padapter->bDriverStopped) {
2546 if (u32wps_start == 0)
2547 u32wps_start = *extra;
2549 DBG_88E("[%s] wps_start = %d\n", __func__, u32wps_start);
2551 if (u32wps_start == 1) /* WPS Start */
2552 rtw_led_control(padapter, LED_CTL_START_WPS);
2553 else if (u32wps_start == 2) /* WPS Stop because of wps success */
2554 rtw_led_control(padapter, LED_CTL_STOP_WPS);
2555 else if (u32wps_start == 3) /* WPS Stop because of wps fail */
2556 rtw_led_control(padapter, LED_CTL_STOP_WPS_FAIL);
2562 #ifdef CONFIG_88EU_P2P
2563 static int rtw_wext_p2p_enable(struct net_device *dev,
2564 struct iw_request_info *info,
2565 union iwreq_data *wrqu, char *extra)
2568 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2569 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2570 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2571 enum P2P_ROLE init_role = P2P_ROLE_DISABLE;
2574 init_role = P2P_ROLE_DISABLE;
2575 else if (*extra == '1')
2576 init_role = P2P_ROLE_DEVICE;
2577 else if (*extra == '2')
2578 init_role = P2P_ROLE_CLIENT;
2579 else if (*extra == '3')
2580 init_role = P2P_ROLE_GO;
2582 if (_FAIL == rtw_p2p_enable(padapter, init_role)) {
2587 /* set channel/bandwidth */
2588 if (init_role != P2P_ROLE_DISABLE) {
2589 u8 channel, ch_offset;
2592 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_LISTEN)) {
2593 /* Stay at the listen state and wait for discovery. */
2594 channel = pwdinfo->listen_channel;
2595 pwdinfo->operating_channel = pwdinfo->listen_channel;
2596 ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
2597 bwmode = HT_CHANNEL_WIDTH_20;
2599 pwdinfo->operating_channel = pmlmeext->cur_channel;
2601 channel = pwdinfo->operating_channel;
2602 ch_offset = pmlmeext->cur_ch_offset;
2603 bwmode = pmlmeext->cur_bwmode;
2606 set_channel_bwmode(padapter, channel, ch_offset, bwmode);
2613 static int rtw_p2p_set_go_nego_ssid(struct net_device *dev,
2614 struct iw_request_info *info,
2615 union iwreq_data *wrqu, char *extra)
2618 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2619 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2621 DBG_88E("[%s] ssid = %s, len = %zu\n", __func__, extra, strlen(extra));
2622 memcpy(pwdinfo->nego_ssid, extra, strlen(extra));
2623 pwdinfo->nego_ssidlen = strlen(extra);
2628 static int rtw_p2p_set_intent(struct net_device *dev,
2629 struct iw_request_info *info,
2630 union iwreq_data *wrqu, char *extra)
2633 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2634 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2635 u8 intent = pwdinfo->intent;
2637 switch (wrqu->data.length) {
2639 intent = extra[0] - '0';
2642 intent = str_2char2num(extra[0], extra[1]);
2646 pwdinfo->intent = intent;
2649 DBG_88E("[%s] intent = %d\n", __func__, intent);
2653 static int rtw_p2p_set_listen_ch(struct net_device *dev,
2654 struct iw_request_info *info,
2655 union iwreq_data *wrqu, char *extra)
2658 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2659 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2660 u8 listen_ch = pwdinfo->listen_channel; /* Listen channel number */
2662 switch (wrqu->data.length) {
2664 listen_ch = extra[0] - '0';
2667 listen_ch = str_2char2num(extra[0], extra[1]);
2671 if ((listen_ch == 1) || (listen_ch == 6) || (listen_ch == 11)) {
2672 pwdinfo->listen_channel = listen_ch;
2673 set_channel_bwmode(padapter, pwdinfo->listen_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
2678 DBG_88E("[%s] listen_ch = %d\n", __func__, pwdinfo->listen_channel);
2683 static int rtw_p2p_set_op_ch(struct net_device *dev,
2684 struct iw_request_info *info,
2685 union iwreq_data *wrqu, char *extra)
2687 /* Commented by Albert 20110524 */
2688 /* This function is used to set the operating channel if the driver will become the group owner */
2691 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2692 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2693 u8 op_ch = pwdinfo->operating_channel; /* Operating channel number */
2695 switch (wrqu->data.length) {
2697 op_ch = extra[0] - '0';
2700 op_ch = str_2char2num(extra[0], extra[1]);
2705 pwdinfo->operating_channel = op_ch;
2709 DBG_88E("[%s] op_ch = %d\n", __func__, pwdinfo->operating_channel);
2714 static int rtw_p2p_profilefound(struct net_device *dev,
2715 struct iw_request_info *info,
2716 union iwreq_data *wrqu, char *extra)
2719 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2720 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2722 /* Comment by Albert 2010/10/13 */
2723 /* Input data format: */
2725 /* Ex: 1XX:XX:XX:XX:XX:XXYYSSID */
2726 /* 0 => Reflush the profile record list. */
2727 /* 1 => Add the profile list */
2728 /* XX:XX:XX:XX:XX:XX => peer's MAC Address (ex: 00:E0:4C:00:00:01) */
2729 /* YY => SSID Length */
2730 /* SSID => SSID for persistence group */
2732 DBG_88E("[%s] In value = %s, len = %d\n", __func__, extra, wrqu->data.length - 1);
2734 /* The upper application should pass the SSID to driver by using this rtw_p2p_profilefound function. */
2735 if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
2736 if (extra[0] == '0') {
2737 /* Remove all the profile information of wifidirect_info structure. */
2738 memset(&pwdinfo->profileinfo[0], 0x00, sizeof(struct profile_info) * P2P_MAX_PERSISTENT_GROUP_NUM);
2739 pwdinfo->profileindex = 0;
2741 if (pwdinfo->profileindex >= P2P_MAX_PERSISTENT_GROUP_NUM) {
2746 /* Add this profile information into pwdinfo->profileinfo */
2747 /* Ex: 1XX:XX:XX:XX:XX:XXYYSSID */
2748 for (jj = 0, kk = 1; jj < ETH_ALEN; jj++, kk += 3)
2749 pwdinfo->profileinfo[pwdinfo->profileindex].peermac[jj] = key_2char2num(extra[kk], extra[kk + 1]);
2751 pwdinfo->profileinfo[pwdinfo->profileindex].ssidlen = (extra[18] - '0') * 10 + (extra[19] - '0');
2752 memcpy(pwdinfo->profileinfo[pwdinfo->profileindex].ssid, &extra[20], pwdinfo->profileinfo[pwdinfo->profileindex].ssidlen);
2753 pwdinfo->profileindex++;
2761 static int rtw_p2p_setDN(struct net_device *dev,
2762 struct iw_request_info *info,
2763 union iwreq_data *wrqu, char *extra)
2766 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2767 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2769 DBG_88E("[%s] %s %d\n", __func__, extra, wrqu->data.length - 1);
2770 memset(pwdinfo->device_name, 0x00, WPS_MAX_DEVICE_NAME_LEN);
2771 memcpy(pwdinfo->device_name, extra, wrqu->data.length - 1);
2772 pwdinfo->device_name_len = wrqu->data.length - 1;
2777 static int rtw_p2p_get_status(struct net_device *dev,
2778 struct iw_request_info *info,
2779 union iwreq_data *wrqu, char *extra)
2782 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2783 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2785 if (padapter->bShowGetP2PState)
2786 DBG_88E("[%s] Role = %d, Status = %d, peer addr = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo),
2787 pwdinfo->p2p_peer_interface_addr[0], pwdinfo->p2p_peer_interface_addr[1], pwdinfo->p2p_peer_interface_addr[2],
2788 pwdinfo->p2p_peer_interface_addr[3], pwdinfo->p2p_peer_interface_addr[4], pwdinfo->p2p_peer_interface_addr[5]);
2790 /* Commented by Albert 2010/10/12 */
2791 /* Because of the output size limitation, I had removed the "Role" information. */
2792 /* About the "Role" information, we will use the new private IOCTL to get the "Role" information. */
2793 sprintf(extra, "\n\nStatus =%.2d\n", rtw_p2p_state(pwdinfo));
2794 wrqu->data.length = strlen(extra);
2799 /* Commented by Albert 20110520 */
2800 /* This function will return the config method description */
2801 /* This config method description will show us which config method the remote P2P device is intended to use */
2802 /* by sending the provisioning discovery request frame. */
2804 static int rtw_p2p_get_req_cm(struct net_device *dev,
2805 struct iw_request_info *info,
2806 union iwreq_data *wrqu, char *extra)
2809 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2810 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2812 sprintf(extra, "\n\nCM =%s\n", pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req);
2813 wrqu->data.length = strlen(extra);
2817 static int rtw_p2p_get_role(struct net_device *dev,
2818 struct iw_request_info *info,
2819 union iwreq_data *wrqu, char *extra)
2822 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2823 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2825 DBG_88E("[%s] Role = %d, Status = %d, peer addr = %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo),
2826 pwdinfo->p2p_peer_interface_addr[0], pwdinfo->p2p_peer_interface_addr[1], pwdinfo->p2p_peer_interface_addr[2],
2827 pwdinfo->p2p_peer_interface_addr[3], pwdinfo->p2p_peer_interface_addr[4], pwdinfo->p2p_peer_interface_addr[5]);
2829 sprintf(extra, "\n\nRole =%.2d\n", rtw_p2p_role(pwdinfo));
2830 wrqu->data.length = strlen(extra);
2834 static int rtw_p2p_get_peer_ifaddr(struct net_device *dev,
2835 struct iw_request_info *info,
2836 union iwreq_data *wrqu, char *extra)
2839 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2840 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2842 DBG_88E("[%s] Role = %d, Status = %d, peer addr = %pM\n", __func__,
2843 rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo),
2844 pwdinfo->p2p_peer_interface_addr);
2845 sprintf(extra, "\nMAC %pM",
2846 pwdinfo->p2p_peer_interface_addr);
2847 wrqu->data.length = strlen(extra);
2851 static int rtw_p2p_get_peer_devaddr(struct net_device *dev,
2852 struct iw_request_info *info,
2853 union iwreq_data *wrqu, char *extra)
2857 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2858 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2860 DBG_88E("[%s] Role = %d, Status = %d, peer addr = %pM\n", __func__,
2861 rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo),
2862 pwdinfo->rx_prov_disc_info.peerDevAddr);
2863 sprintf(extra, "\n%pM",
2864 pwdinfo->rx_prov_disc_info.peerDevAddr);
2865 wrqu->data.length = strlen(extra);
2869 static int rtw_p2p_get_peer_devaddr_by_invitation(struct net_device *dev,
2870 struct iw_request_info *info,
2871 union iwreq_data *wrqu, char *extra)
2875 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2876 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2878 DBG_88E("[%s] Role = %d, Status = %d, peer addr = %pM\n",
2879 __func__, rtw_p2p_role(pwdinfo), rtw_p2p_state(pwdinfo),
2880 pwdinfo->p2p_peer_device_addr);
2881 sprintf(extra, "\nMAC %pM",
2882 pwdinfo->p2p_peer_device_addr);
2883 wrqu->data.length = strlen(extra);
2887 static int rtw_p2p_get_groupid(struct net_device *dev,
2888 struct iw_request_info *info,
2889 union iwreq_data *wrqu, char *extra)
2893 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2894 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2896 sprintf(extra, "\n%.2X:%.2X:%.2X:%.2X:%.2X:%.2X %s",
2897 pwdinfo->groupid_info.go_device_addr[0], pwdinfo->groupid_info.go_device_addr[1],
2898 pwdinfo->groupid_info.go_device_addr[2], pwdinfo->groupid_info.go_device_addr[3],
2899 pwdinfo->groupid_info.go_device_addr[4], pwdinfo->groupid_info.go_device_addr[5],
2900 pwdinfo->groupid_info.ssid);
2901 wrqu->data.length = strlen(extra);
2905 static int rtw_p2p_get_op_ch(struct net_device *dev,
2906 struct iw_request_info *info,
2907 union iwreq_data *wrqu, char *extra)
2911 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2912 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2914 DBG_88E("[%s] Op_ch = %02x\n", __func__, pwdinfo->operating_channel);
2916 sprintf(extra, "\n\nOp_ch =%.2d\n", pwdinfo->operating_channel);
2917 wrqu->data.length = strlen(extra);
2921 static int rtw_p2p_get_wps_configmethod(struct net_device *dev,
2922 struct iw_request_info *info,
2923 union iwreq_data *wrqu, char *extra)
2926 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2927 u8 peerMAC[ETH_ALEN] = {0x00};
2929 u8 peerMACStr[17] = {0x00};
2930 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2931 struct list_head *plist, *phead;
2932 struct __queue *queue = &pmlmepriv->scanned_queue;
2933 struct wlan_network *pnetwork = NULL;
2935 u16 attr_content = 0;
2936 uint attr_contentlen = 0;
2937 /* 6 is the string "wpsCM =", 17 is the MAC addr, we have to clear it at wrqu->data.pointer */
2938 u8 attr_content_str[6 + 17] = {0x00};
2940 /* Commented by Albert 20110727 */
2941 /* The input data is the MAC address which the application wants to know its WPS config method. */
2942 /* After knowing its WPS config method, the application can decide the config method for provisioning discovery. */
2943 /* Format: iwpriv wlanx p2p_get_wpsCM 00:E0:4C:00:00:05 */
2945 DBG_88E("[%s] data = %s\n", __func__, (char *)extra);
2946 if (copy_from_user(peerMACStr, wrqu->data.pointer + 6, 17))
2949 for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
2950 peerMAC[jj] = key_2char2num(peerMACStr[kk], peerMACStr[kk + 1]);
2952 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
2954 phead = get_list_head(queue);
2955 plist = phead->next;
2957 while (phead != plist) {
2958 pnetwork = container_of(plist, struct wlan_network, list);
2959 if (!memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
2964 /* The mac address is matched. */
2965 wpsie = rtw_get_wps_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &wpsie_len);
2967 rtw_get_wps_attr_content(wpsie, wpsie_len, WPS_ATTR_CONF_METHOD, (u8 *)&be_tmp, &attr_contentlen);
2968 if (attr_contentlen) {
2969 attr_content = be16_to_cpu(be_tmp);
2970 sprintf(attr_content_str, "\n\nM =%.4d", attr_content);
2976 plist = plist->next;
2979 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
2982 sprintf(attr_content_str, "\n\nM = 0000");
2984 if (copy_to_user(wrqu->data.pointer, attr_content_str, 6 + 17))
2989 static int rtw_p2p_get_go_device_address(struct net_device *dev,
2990 struct iw_request_info *info,
2991 union iwreq_data *wrqu, char *extra)
2994 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2995 u8 peerMAC[ETH_ALEN] = {0x00};
2997 u8 peerMACStr[17] = {0x00};
2998 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2999 struct list_head *plist, *phead;
3000 struct __queue *queue = &pmlmepriv->scanned_queue;
3001 struct wlan_network *pnetwork = NULL;
3004 uint p2pielen = 0, attr_contentlen = 0;
3005 u8 attr_content[100] = {0x00};
3007 u8 go_devadd_str[100 + 10] = {0x00};
3008 /* +10 is for the str "go_devadd =", we have to clear it at wrqu->data.pointer */
3010 /* Commented by Albert 20121209 */
3011 /* The input data is the GO's interface address which the application wants to know its device address. */
3012 /* Format: iwpriv wlanx p2p_get2 go_devadd = 00:E0:4C:00:00:05 */
3014 DBG_88E("[%s] data = %s\n", __func__, (char *)extra);
3015 if (copy_from_user(peerMACStr, wrqu->data.pointer + 10, 17))
3018 for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
3019 peerMAC[jj] = key_2char2num(peerMACStr[kk], peerMACStr[kk + 1]);
3021 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
3023 phead = get_list_head(queue);
3024 plist = phead->next;
3026 while (phead != plist) {
3027 pnetwork = container_of(plist, struct wlan_network, list);
3028 if (!memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
3029 /* Commented by Albert 2011/05/18 */
3030 /* Match the device address located in the P2P IE */
3031 /* This is for the case that the P2P device address is not the same as the P2P interface address. */
3033 p2pie = rtw_get_p2p_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &p2pielen);
3036 /* The P2P Device ID attribute is included in the Beacon frame. */
3037 /* The P2P Device Info attribute is included in the probe response frame. */
3039 memset(attr_content, 0x00, 100);
3040 if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_ID, attr_content, &attr_contentlen)) {
3041 /* Handle the P2P Device ID attribute of Beacon first */
3044 } else if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_INFO, attr_content, &attr_contentlen)) {
3045 /* Handle the P2P Device Info attribute of probe response */
3050 /* Get the next P2P IE */
3051 p2pie = rtw_get_p2p_ie(p2pie + p2pielen, pnetwork->network.IELength - 12 - (p2pie - &pnetwork->network.IEs[12] + p2pielen), NULL, &p2pielen);
3056 plist = plist->next;
3059 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
3062 sprintf(go_devadd_str, "\n\ndev_add = NULL");
3064 sprintf(go_devadd_str, "\ndev_add =%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
3065 attr_content[0], attr_content[1], attr_content[2], attr_content[3], attr_content[4], attr_content[5]);
3067 if (copy_to_user(wrqu->data.pointer, go_devadd_str, 10 + 17))
3072 static int rtw_p2p_get_device_type(struct net_device *dev,
3073 struct iw_request_info *info,
3074 union iwreq_data *wrqu, char *extra)
3077 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
3078 u8 peerMAC[ETH_ALEN] = {0x00};
3080 u8 peerMACStr[17] = {0x00};
3081 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
3082 struct list_head *plist, *phead;
3083 struct __queue *queue = &pmlmepriv->scanned_queue;
3084 struct wlan_network *pnetwork = NULL;
3086 u8 dev_type[8] = {0x00};
3087 uint dev_type_len = 0;
3088 u8 dev_type_str[17 + 9] = {0x00}; /* +9 is for the str "dev_type =", we have to clear it at wrqu->data.pointer */
3090 /* Commented by Albert 20121209 */
3091 /* The input data is the MAC address which the application wants to know its device type. */
3092 /* Such user interface could know the device type. */
3093 /* Format: iwpriv wlanx p2p_get2 dev_type = 00:E0:4C:00:00:05 */
3095 DBG_88E("[%s] data = %s\n", __func__, (char *)extra);
3096 if (copy_from_user(peerMACStr, wrqu->data.pointer + 9, 17))
3099 for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
3100 peerMAC[jj] = key_2char2num(peerMACStr[kk], peerMACStr[kk + 1]);
3102 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
3104 phead = get_list_head(queue);
3105 plist = phead->next;
3107 while (phead != plist) {
3108 pnetwork = container_of(plist, struct wlan_network, list);
3109 if (!memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
3113 /* The mac address is matched. */
3115 wpsie = rtw_get_wps_ie(&pnetwork->network.IEs[12],
3116 pnetwork->network.IELength - 12,
3119 rtw_get_wps_attr_content(wpsie, wpsie_len, WPS_ATTR_PRIMARY_DEV_TYPE, dev_type, &dev_type_len);
3124 memcpy(&be_tmp, dev_type, 2);
3125 type = be16_to_cpu(be_tmp);
3126 sprintf(dev_type_str, "\n\nN =%.2d", type);
3133 plist = plist->next;
3136 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
3139 sprintf(dev_type_str, "\n\nN = 00");
3141 if (copy_to_user(wrqu->data.pointer, dev_type_str, 9 + 17)) {
3148 static int rtw_p2p_get_device_name(struct net_device *dev,
3149 struct iw_request_info *info,
3150 union iwreq_data *wrqu, char *extra)
3153 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
3154 u8 peerMAC[ETH_ALEN] = {0x00};
3156 u8 peerMACStr[17] = {0x00};
3157 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
3158 struct list_head *plist, *phead;
3159 struct __queue *queue = &pmlmepriv->scanned_queue;
3160 struct wlan_network *pnetwork = NULL;
3162 u8 dev_name[WPS_MAX_DEVICE_NAME_LEN] = {0x00};
3164 u8 dev_name_str[WPS_MAX_DEVICE_NAME_LEN + 5] = {0x00}; /* +5 is for the str "devN =", we have to clear it at wrqu->data.pointer */
3166 /* Commented by Albert 20121225 */
3167 /* The input data is the MAC address which the application wants to know its device name. */
3168 /* Such user interface could show peer device's device name instead of ssid. */
3169 /* Format: iwpriv wlanx p2p_get2 devN = 00:E0:4C:00:00:05 */
3171 DBG_88E("[%s] data = %s\n", __func__, (char *)extra);
3172 if (copy_from_user(peerMACStr, wrqu->data.pointer + 5, 17))
3175 for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
3176 peerMAC[jj] = key_2char2num(peerMACStr[kk], peerMACStr[kk + 1]);
3178 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
3180 phead = get_list_head(queue);
3181 plist = phead->next;
3183 while (phead != plist) {
3184 pnetwork = container_of(plist, struct wlan_network, list);
3185 if (!memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
3189 /* The mac address is matched. */
3190 wpsie = rtw_get_wps_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &wpsie_len);
3192 rtw_get_wps_attr_content(wpsie, wpsie_len, WPS_ATTR_DEVICE_NAME, dev_name, &dev_len);
3194 sprintf(dev_name_str, "\n\nN =%s", dev_name);
3201 plist = plist->next;
3204 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
3207 sprintf(dev_name_str, "\n\nN = 0000");
3209 if (copy_to_user(wrqu->data.pointer, dev_name_str, 5 + ((dev_len > 17) ? dev_len : 17)))
3214 static int rtw_p2p_get_invitation_procedure(struct net_device *dev,
3215 struct iw_request_info *info,
3216 union iwreq_data *wrqu, char *extra)
3219 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
3220 u8 peerMAC[ETH_ALEN] = {0x00};
3222 u8 peerMACStr[17] = {0x00};
3223 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
3224 struct list_head *plist, *phead;
3225 struct __queue *queue = &pmlmepriv->scanned_queue;
3226 struct wlan_network *pnetwork = NULL;
3229 uint p2pielen = 0, attr_contentlen = 0;
3230 u8 attr_content[2] = {0x00};
3232 u8 inv_proc_str[17 + 8] = {0x00};
3233 /* +8 is for the str "InvProc =", we have to clear it at wrqu->data.pointer */
3235 /* Commented by Ouden 20121226 */
3236 /* The application wants to know P2P initiation procedure is supported or not. */
3237 /* Format: iwpriv wlanx p2p_get2 InvProc = 00:E0:4C:00:00:05 */
3239 DBG_88E("[%s] data = %s\n", __func__, (char *)extra);
3240 if (copy_from_user(peerMACStr, wrqu->data.pointer + 8, 17))
3243 for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
3244 peerMAC[jj] = key_2char2num(peerMACStr[kk], peerMACStr[kk + 1]);
3246 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
3248 phead = get_list_head(queue);
3249 plist = phead->next;
3251 while (phead != plist) {
3252 pnetwork = container_of(plist, struct wlan_network, list);
3253 if (!memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
3254 /* Commented by Albert 20121226 */
3255 /* Match the device address located in the P2P IE */
3256 /* This is for the case that the P2P device address is not the same as the P2P interface address. */
3258 p2pie = rtw_get_p2p_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &p2pielen);
3261 if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_CAPABILITY, attr_content, &attr_contentlen)) {
3262 /* Handle the P2P capability attribute */
3267 /* Get the next P2P IE */
3268 p2pie = rtw_get_p2p_ie(p2pie + p2pielen, pnetwork->network.IELength - 12 - (p2pie - &pnetwork->network.IEs[12] + p2pielen), NULL, &p2pielen);
3272 plist = plist->next;
3275 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
3278 sprintf(inv_proc_str, "\nIP =-1");
3280 if (attr_content[0] & 0x20)
3281 sprintf(inv_proc_str, "\nIP = 1");
3283 sprintf(inv_proc_str, "\nIP = 0");
3285 if (copy_to_user(wrqu->data.pointer, inv_proc_str, 8 + 17))
3290 static int rtw_p2p_connect(struct net_device *dev,
3291 struct iw_request_info *info,
3292 union iwreq_data *wrqu, char *extra)
3295 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
3296 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
3297 u8 peerMAC[ETH_ALEN] = {0x00};
3299 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
3300 struct list_head *plist, *phead;
3301 struct __queue *queue = &pmlmepriv->scanned_queue;
3302 struct wlan_network *pnetwork = NULL;
3303 uint uintPeerChannel = 0;
3305 /* Commented by Albert 20110304 */
3306 /* The input data contains two informations. */
3307 /* 1. First information is the MAC address which wants to formate with */
3308 /* 2. Second information is the WPS PINCode or "pbc" string for push button method */
3309 /* Format: 00:E0:4C:00:00:05 */
3310 /* Format: 00:E0:4C:00:00:05 */
3312 DBG_88E("[%s] data = %s\n", __func__, extra);
3314 if (pwdinfo->p2p_state == P2P_STATE_NONE) {
3315 DBG_88E("[%s] WiFi Direct is disable!\n", __func__);
3319 if (pwdinfo->ui_got_wps_info == P2P_NO_WPSINFO)
3322 for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
3323 peerMAC[jj] = key_2char2num(extra[kk], extra[kk + 1]);
3325 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
3327 phead = get_list_head(queue);
3328 plist = phead->next;
3330 while (phead != plist) {
3331 pnetwork = container_of(plist, struct wlan_network, list);
3332 if (!memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
3333 uintPeerChannel = pnetwork->network.Configuration.DSConfig;
3337 plist = plist->next;
3340 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
3342 if (uintPeerChannel) {
3343 memset(&pwdinfo->nego_req_info, 0x00, sizeof(struct tx_nego_req_info));
3344 memset(&pwdinfo->groupid_info, 0x00, sizeof(struct group_id_info));
3346 pwdinfo->nego_req_info.peer_channel_num[0] = uintPeerChannel;
3347 memcpy(pwdinfo->nego_req_info.peerDevAddr, pnetwork->network.MacAddress, ETH_ALEN);
3348 pwdinfo->nego_req_info.benable = true;
3350 _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
3351 if (rtw_p2p_state(pwdinfo) != P2P_STATE_GONEGO_OK) {
3352 /* Restore to the listen state if the current p2p state is not nego OK */
3353 rtw_p2p_set_state(pwdinfo, P2P_STATE_LISTEN);
3356 rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
3357 rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_ING);
3359 DBG_88E("[%s] Start PreTx Procedure!\n", __func__);
3360 _set_timer(&pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT);
3361 _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_GO_NEGO_TIMEOUT);
3363 DBG_88E("[%s] Not Found in Scanning Queue~\n", __func__);
3369 static int rtw_p2p_invite_req(struct net_device *dev,
3370 struct iw_request_info *info,
3371 union iwreq_data *wrqu, char *extra)
3374 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
3375 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
3377 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
3378 struct list_head *plist, *phead;
3379 struct __queue *queue = &pmlmepriv->scanned_queue;
3380 struct wlan_network *pnetwork = NULL;
3381 uint uintPeerChannel = 0;
3382 u8 attr_content[50] = {0x00};
3384 uint p2pielen = 0, attr_contentlen = 0;
3385 struct tx_invite_req_info *pinvite_req_info = &pwdinfo->invitereq_info;
3387 /* The input data contains two informations. */
3388 /* 1. First information is the P2P device address which you want to send to. */
3389 /* 2. Second information is the group id which combines with GO's mac address, space and GO's ssid. */
3390 /* Command line sample: iwpriv wlan0 p2p_set invite ="00:11:22:33:44:55 00:E0:4C:00:00:05 DIRECT-xy" */
3391 /* Format: 00:11:22:33:44:55 00:E0:4C:00:00:05 DIRECT-xy */
3393 DBG_88E("[%s] data = %s\n", __func__, extra);
3395 if (wrqu->data.length <= 37) {
3396 DBG_88E("[%s] Wrong format!\n", __func__);
3400 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
3401 DBG_88E("[%s] WiFi Direct is disable!\n", __func__);
3404 /* Reset the content of struct tx_invite_req_info */
3405 pinvite_req_info->benable = false;
3406 memset(pinvite_req_info->go_bssid, 0x00, ETH_ALEN);
3407 memset(pinvite_req_info->go_ssid, 0x00, WLAN_SSID_MAXLEN);
3408 pinvite_req_info->ssidlen = 0x00;
3409 pinvite_req_info->operating_ch = pwdinfo->operating_channel;
3410 memset(pinvite_req_info->peer_macaddr, 0x00, ETH_ALEN);
3411 pinvite_req_info->token = 3;
3414 for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
3415 pinvite_req_info->peer_macaddr[jj] = key_2char2num(extra[kk], extra[kk + 1]);
3417 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
3419 phead = get_list_head(queue);
3420 plist = phead->next;
3422 while (phead != plist) {
3423 pnetwork = container_of(plist, struct wlan_network, list);
3425 /* Commented by Albert 2011/05/18 */
3426 /* Match the device address located in the P2P IE */
3427 /* This is for the case that the P2P device address is not the same as the P2P interface address. */
3429 p2pie = rtw_get_p2p_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &p2pielen);
3431 /* The P2P Device ID attribute is included in the Beacon frame. */
3432 /* The P2P Device Info attribute is included in the probe response frame. */
3434 if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_ID, attr_content, &attr_contentlen)) {
3435 /* Handle the P2P Device ID attribute of Beacon first */
3436 if (!memcmp(attr_content, pinvite_req_info->peer_macaddr, ETH_ALEN)) {
3437 uintPeerChannel = pnetwork->network.Configuration.DSConfig;
3440 } else if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_INFO, attr_content, &attr_contentlen)) {
3441 /* Handle the P2P Device Info attribute of probe response */
3442 if (!memcmp(attr_content, pinvite_req_info->peer_macaddr, ETH_ALEN)) {
3443 uintPeerChannel = pnetwork->network.Configuration.DSConfig;
3448 plist = plist->next;
3451 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
3453 if (uintPeerChannel) {
3454 /* Store the GO's bssid */
3455 for (jj = 0, kk = 18; jj < ETH_ALEN; jj++, kk += 3)
3456 pinvite_req_info->go_bssid[jj] = key_2char2num(extra[kk], extra[kk + 1]);
3458 /* Store the GO's ssid */
3459 pinvite_req_info->ssidlen = wrqu->data.length - 36;
3460 memcpy(pinvite_req_info->go_ssid, &extra[36], (u32)pinvite_req_info->ssidlen);
3461 pinvite_req_info->benable = true;
3462 pinvite_req_info->peer_ch = uintPeerChannel;
3464 rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
3465 rtw_p2p_set_state(pwdinfo, P2P_STATE_TX_INVITE_REQ);
3467 set_channel_bwmode(padapter, uintPeerChannel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
3469 _set_timer(&pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT);
3471 _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_INVITE_TIMEOUT);
3473 DBG_88E("[%s] NOT Found in the Scanning Queue!\n", __func__);
3478 static int rtw_p2p_set_persistent(struct net_device *dev,
3479 struct iw_request_info *info,
3480 union iwreq_data *wrqu, char *extra)
3483 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
3484 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
3486 /* The input data is 0 or 1 */
3487 /* 0: disable persistent group functionality */
3488 /* 1: enable persistent group founctionality */
3490 DBG_88E("[%s] data = %s\n", __func__, extra);
3492 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
3493 DBG_88E("[%s] WiFi Direct is disable!\n", __func__);
3496 if (extra[0] == '0') /* Disable the persistent group function. */
3497 pwdinfo->persistent_supported = false;
3498 else if (extra[0] == '1') /* Enable the persistent group function. */
3499 pwdinfo->persistent_supported = true;
3501 pwdinfo->persistent_supported = false;
3503 pr_info("[%s] persistent_supported = %d\n", __func__, pwdinfo->persistent_supported);
3507 static int rtw_p2p_prov_disc(struct net_device *dev,
3508 struct iw_request_info *info,
3509 union iwreq_data *wrqu, char *extra)
3512 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
3513 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
3514 u8 peerMAC[ETH_ALEN] = {0x00};
3516 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
3517 struct list_head *plist, *phead;
3518 struct __queue *queue = &pmlmepriv->scanned_queue;
3519 struct wlan_network *pnetwork = NULL;
3520 uint uintPeerChannel = 0;
3521 u8 attr_content[100] = {0x00};
3523 uint p2pielen = 0, attr_contentlen = 0;
3525 /* The input data contains two informations. */
3526 /* 1. First information is the MAC address which wants to issue the provisioning discovery request frame. */
3527 /* 2. Second information is the WPS configuration method which wants to discovery */
3528 /* Format: 00:E0:4C:00:00:05_display */
3529 /* Format: 00:E0:4C:00:00:05_keypad */
3530 /* Format: 00:E0:4C:00:00:05_pbc */
3531 /* Format: 00:E0:4C:00:00:05_label */
3533 DBG_88E("[%s] data = %s\n", __func__, extra);
3535 if (pwdinfo->p2p_state == P2P_STATE_NONE) {
3536 DBG_88E("[%s] WiFi Direct is disable!\n", __func__);
3539 /* Reset the content of struct tx_provdisc_req_info excluded the wps_config_method_request. */
3540 memset(pwdinfo->tx_prov_disc_info.peerDevAddr, 0x00, ETH_ALEN);
3541 memset(pwdinfo->tx_prov_disc_info.peerIFAddr, 0x00, ETH_ALEN);
3542 memset(&pwdinfo->tx_prov_disc_info.ssid, 0x00, sizeof(struct ndis_802_11_ssid));
3543 pwdinfo->tx_prov_disc_info.peer_channel_num[0] = 0;
3544 pwdinfo->tx_prov_disc_info.peer_channel_num[1] = 0;
3545 pwdinfo->tx_prov_disc_info.benable = false;
3548 for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
3549 peerMAC[jj] = key_2char2num(extra[kk], extra[kk + 1]);
3551 if (!memcmp(&extra[18], "display", 7)) {
3552 pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_DISPLYA;
3553 } else if (!memcmp(&extra[18], "keypad", 7)) {
3554 pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_KEYPAD;
3555 } else if (!memcmp(&extra[18], "pbc", 3)) {
3556 pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_PUSH_BUTTON;
3557 } else if (!memcmp(&extra[18], "label", 5)) {
3558 pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_LABEL;
3560 DBG_88E("[%s] Unknown WPS config methodn", __func__);
3564 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
3566 phead = get_list_head(queue);
3567 plist = phead->next;
3569 while (phead != plist) {
3570 if (uintPeerChannel != 0)
3573 pnetwork = container_of(plist, struct wlan_network, list);
3575 /* Commented by Albert 2011/05/18 */
3576 /* Match the device address located in the P2P IE */
3577 /* This is for the case that the P2P device address is not the same as the P2P interface address. */
3579 p2pie = rtw_get_p2p_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &p2pielen);
3582 /* The P2P Device ID attribute is included in the Beacon frame. */
3583 /* The P2P Device Info attribute is included in the probe response frame. */
3585 if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_ID, attr_content, &attr_contentlen)) {
3586 /* Handle the P2P Device ID attribute of Beacon first */
3587 if (!memcmp(attr_content, peerMAC, ETH_ALEN)) {
3588 uintPeerChannel = pnetwork->network.Configuration.DSConfig;
3591 } else if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_INFO, attr_content, &attr_contentlen)) {
3592 /* Handle the P2P Device Info attribute of probe response */
3593 if (!memcmp(attr_content, peerMAC, ETH_ALEN)) {
3594 uintPeerChannel = pnetwork->network.Configuration.DSConfig;
3599 /* Get the next P2P IE */
3600 p2pie = rtw_get_p2p_ie(p2pie + p2pielen, pnetwork->network.IELength - 12 - (p2pie - &pnetwork->network.IEs[12] + p2pielen), NULL, &p2pielen);
3604 plist = plist->next;
3607 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
3609 if (uintPeerChannel) {
3610 DBG_88E("[%s] peer channel: %d!\n", __func__, uintPeerChannel);
3611 memcpy(pwdinfo->tx_prov_disc_info.peerIFAddr, pnetwork->network.MacAddress, ETH_ALEN);
3612 memcpy(pwdinfo->tx_prov_disc_info.peerDevAddr, peerMAC, ETH_ALEN);
3613 pwdinfo->tx_prov_disc_info.peer_channel_num[0] = (u16)uintPeerChannel;
3614 pwdinfo->tx_prov_disc_info.benable = true;
3615 rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
3616 rtw_p2p_set_state(pwdinfo, P2P_STATE_TX_PROVISION_DIS_REQ);
3618 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT)) {
3619 memcpy(&pwdinfo->tx_prov_disc_info.ssid, &pnetwork->network.Ssid, sizeof(struct ndis_802_11_ssid));
3620 } else if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_DEVICE) || rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
3621 memcpy(pwdinfo->tx_prov_disc_info.ssid.Ssid, pwdinfo->p2p_wildcard_ssid, P2P_WILDCARD_SSID_LEN);
3622 pwdinfo->tx_prov_disc_info.ssid.SsidLength = P2P_WILDCARD_SSID_LEN;
3625 set_channel_bwmode(padapter, uintPeerChannel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
3627 _set_timer(&pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT);
3629 _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_PROVISION_TIMEOUT);
3631 DBG_88E("[%s] NOT Found in the Scanning Queue!\n", __func__);
3636 /* This function is used to inform the driver the user had specified the pin code value or pbc */
3637 /* to application. */
3639 static int rtw_p2p_got_wpsinfo(struct net_device *dev,
3640 struct iw_request_info *info,
3641 union iwreq_data *wrqu, char *extra)
3644 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
3645 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
3647 DBG_88E("[%s] data = %s\n", __func__, extra);
3648 /* Added by Albert 20110328 */
3649 /* if the input data is P2P_NO_WPSINFO -> reset the wpsinfo */
3650 /* if the input data is P2P_GOT_WPSINFO_PEER_DISPLAY_PIN -> the utility just input the PIN code got from the peer P2P device. */
3651 /* if the input data is P2P_GOT_WPSINFO_SELF_DISPLAY_PIN -> the utility just got the PIN code from itself. */
3652 /* if the input data is P2P_GOT_WPSINFO_PBC -> the utility just determine to use the PBC */
3655 pwdinfo->ui_got_wps_info = P2P_NO_WPSINFO;
3656 else if (*extra == '1')
3657 pwdinfo->ui_got_wps_info = P2P_GOT_WPSINFO_PEER_DISPLAY_PIN;
3658 else if (*extra == '2')
3659 pwdinfo->ui_got_wps_info = P2P_GOT_WPSINFO_SELF_DISPLAY_PIN;
3660 else if (*extra == '3')
3661 pwdinfo->ui_got_wps_info = P2P_GOT_WPSINFO_PBC;
3663 pwdinfo->ui_got_wps_info = P2P_NO_WPSINFO;
3667 #endif /* CONFIG_88EU_P2P */
3669 static int rtw_p2p_set(struct net_device *dev,
3670 struct iw_request_info *info,
3671 union iwreq_data *wrqu, char *extra)
3675 #ifdef CONFIG_88EU_P2P
3676 DBG_88E("[%s] extra = %s\n", __func__, extra);
3677 if (!memcmp(extra, "enable =", 7)) {
3678 rtw_wext_p2p_enable(dev, info, wrqu, &extra[7]);
3679 } else if (!memcmp(extra, "setDN =", 6)) {
3680 wrqu->data.length -= 6;
3681 rtw_p2p_setDN(dev, info, wrqu, &extra[6]);
3682 } else if (!memcmp(extra, "profilefound =", 13)) {
3683 wrqu->data.length -= 13;
3684 rtw_p2p_profilefound(dev, info, wrqu, &extra[13]);
3685 } else if (!memcmp(extra, "prov_disc =", 10)) {
3686 wrqu->data.length -= 10;
3687 rtw_p2p_prov_disc(dev, info, wrqu, &extra[10]);
3688 } else if (!memcmp(extra, "nego =", 5)) {
3689 wrqu->data.length -= 5;
3690 rtw_p2p_connect(dev, info, wrqu, &extra[5]);
3691 } else if (!memcmp(extra, "intent =", 7)) {
3692 /* Commented by Albert 2011/03/23 */
3693 /* The wrqu->data.length will include the null character */
3694 /* So, we will decrease 7 + 1 */
3695 wrqu->data.length -= 8;
3696 rtw_p2p_set_intent(dev, info, wrqu, &extra[7]);
3697 } else if (!memcmp(extra, "ssid =", 5)) {
3698 wrqu->data.length -= 5;
3699 rtw_p2p_set_go_nego_ssid(dev, info, wrqu, &extra[5]);
3700 } else if (!memcmp(extra, "got_wpsinfo =", 12)) {
3701 wrqu->data.length -= 12;
3702 rtw_p2p_got_wpsinfo(dev, info, wrqu, &extra[12]);
3703 } else if (!memcmp(extra, "listen_ch =", 10)) {
3704 /* Commented by Albert 2011/05/24 */
3705 /* The wrqu->data.length will include the null character */
3706 /* So, we will decrease (10 + 1) */
3707 wrqu->data.length -= 11;
3708 rtw_p2p_set_listen_ch(dev, info, wrqu, &extra[10]);
3709 } else if (!memcmp(extra, "op_ch =", 6)) {
3710 /* Commented by Albert 2011/05/24 */
3711 /* The wrqu->data.length will include the null character */
3712 /* So, we will decrease (6 + 1) */
3713 wrqu->data.length -= 7;
3714 rtw_p2p_set_op_ch(dev, info, wrqu, &extra[6]);
3715 } else if (!memcmp(extra, "invite =", 7)) {
3716 wrqu->data.length -= 8;
3717 rtw_p2p_invite_req(dev, info, wrqu, &extra[7]);
3718 } else if (!memcmp(extra, "persistent =", 11)) {
3719 wrqu->data.length -= 11;
3720 rtw_p2p_set_persistent(dev, info, wrqu, &extra[11]);
3722 #endif /* CONFIG_88EU_P2P */
3727 static int rtw_p2p_get(struct net_device *dev,
3728 struct iw_request_info *info,
3729 union iwreq_data *wrqu, char *extra)
3733 #ifdef CONFIG_88EU_P2P
3734 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
3736 if (padapter->bShowGetP2PState)
3737 DBG_88E("[%s] extra = %s\n", __func__, (char *)wrqu->data.pointer);
3738 if (!memcmp(wrqu->data.pointer, "status", 6)) {
3739 rtw_p2p_get_status(dev, info, wrqu, extra);
3740 } else if (!memcmp(wrqu->data.pointer, "role", 4)) {
3741 rtw_p2p_get_role(dev, info, wrqu, extra);
3742 } else if (!memcmp(wrqu->data.pointer, "peer_ifa", 8)) {
3743 rtw_p2p_get_peer_ifaddr(dev, info, wrqu, extra);
3744 } else if (!memcmp(wrqu->data.pointer, "req_cm", 6)) {
3745 rtw_p2p_get_req_cm(dev, info, wrqu, extra);
3746 } else if (!memcmp(wrqu->data.pointer, "peer_deva", 9)) {
3747 /* Get the P2P device address when receiving the provision discovery request frame. */
3748 rtw_p2p_get_peer_devaddr(dev, info, wrqu, extra);
3749 } else if (!memcmp(wrqu->data.pointer, "group_id", 8)) {
3750 rtw_p2p_get_groupid(dev, info, wrqu, extra);
3751 } else if (!memcmp(wrqu->data.pointer, "peer_deva_inv", 9)) {
3752 /* Get the P2P device address when receiving the P2P Invitation request frame. */
3753 rtw_p2p_get_peer_devaddr_by_invitation(dev, info, wrqu, extra);
3754 } else if (!memcmp(wrqu->data.pointer, "op_ch", 5)) {
3755 rtw_p2p_get_op_ch(dev, info, wrqu, extra);
3757 #endif /* CONFIG_88EU_P2P */
3761 static int rtw_p2p_get2(struct net_device *dev,
3762 struct iw_request_info *info,
3763 union iwreq_data *wrqu, char *extra)
3767 #ifdef CONFIG_88EU_P2P
3768 DBG_88E("[%s] extra = %s\n", __func__, (char *)wrqu->data.pointer);
3769 if (!memcmp(extra, "wpsCM =", 6)) {
3770 wrqu->data.length -= 6;
3771 rtw_p2p_get_wps_configmethod(dev, info, wrqu, &extra[6]);
3772 } else if (!memcmp(extra, "devN =", 5)) {
3773 wrqu->data.length -= 5;
3774 rtw_p2p_get_device_name(dev, info, wrqu, &extra[5]);
3775 } else if (!memcmp(extra, "dev_type =", 9)) {
3776 wrqu->data.length -= 9;
3777 rtw_p2p_get_device_type(dev, info, wrqu, &extra[9]);
3778 } else if (!memcmp(extra, "go_devadd =", 10)) {
3779 wrqu->data.length -= 10;
3780 rtw_p2p_get_go_device_address(dev, info, wrqu, &extra[10]);
3781 } else if (!memcmp(extra, "InvProc =", 8)) {
3782 wrqu->data.length -= 8;
3783 rtw_p2p_get_invitation_procedure(dev, info, wrqu, &extra[8]);
3786 #endif /* CONFIG_88EU_P2P */
3791 static int rtw_cta_test_start(struct net_device *dev,
3792 struct iw_request_info *info,
3793 union iwreq_data *wrqu, char *extra)
3796 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
3797 DBG_88E("%s %s\n", __func__, extra);
3798 if (!strcmp(extra, "1"))
3799 padapter->in_cta_test = 1;
3801 padapter->in_cta_test = 0;
3803 if (padapter->in_cta_test) {
3804 u32 v = rtw_read32(padapter, REG_RCR);
3805 v &= ~(RCR_CBSSID_DATA | RCR_CBSSID_BCN);/* RCR_ADF */
3806 rtw_write32(padapter, REG_RCR, v);
3807 DBG_88E("enable RCR_ADF\n");
3809 u32 v = rtw_read32(padapter, REG_RCR);
3810 v |= RCR_CBSSID_DATA | RCR_CBSSID_BCN;/* RCR_ADF */
3811 rtw_write32(padapter, REG_RCR, v);
3812 DBG_88E("disable RCR_ADF\n");
3817 static int rtw_rereg_nd_name(struct net_device *dev,
3818 struct iw_request_info *info,
3819 union iwreq_data *wrqu, char *extra)
3822 struct adapter *padapter = rtw_netdev_priv(dev);
3823 struct rereg_nd_name_data *rereg_priv = &padapter->rereg_nd_name_priv;
3824 char new_ifname[IFNAMSIZ];
3826 if (rereg_priv->old_ifname[0] == 0) {
3828 reg_ifname = padapter->registrypriv.if2name;
3830 strncpy(rereg_priv->old_ifname, reg_ifname, IFNAMSIZ);
3831 rereg_priv->old_ifname[IFNAMSIZ - 1] = 0;
3834 if (wrqu->data.length > IFNAMSIZ)
3837 if (copy_from_user(new_ifname, wrqu->data.pointer, IFNAMSIZ))
3840 if (0 == strcmp(rereg_priv->old_ifname, new_ifname))
3843 DBG_88E("%s new_ifname:%s\n", __func__, new_ifname);
3844 ret = rtw_change_ifname(padapter, new_ifname);
3848 if (!memcmp(rereg_priv->old_ifname, "disable%d", 9)) {
3849 padapter->ledpriv.bRegUseLed = rereg_priv->old_bRegUseLed;
3850 rtw_hal_sw_led_init(padapter);
3851 rtw_ips_mode_req(&padapter->pwrctrlpriv, rereg_priv->old_ips_mode);
3854 strncpy(rereg_priv->old_ifname, new_ifname, IFNAMSIZ);
3855 rereg_priv->old_ifname[IFNAMSIZ - 1] = 0;
3857 if (!memcmp(new_ifname, "disable%d", 9)) {
3858 DBG_88E("%s disable\n", __func__);
3859 /* free network queue for Android's timming issue */
3860 rtw_free_network_queue(padapter, true);
3863 rtw_led_control(padapter, LED_CTL_POWER_OFF);
3864 rereg_priv->old_bRegUseLed = padapter->ledpriv.bRegUseLed;
3865 padapter->ledpriv.bRegUseLed = false;
3866 rtw_hal_sw_led_deinit(padapter);
3868 /* the interface is being "disabled", we can do deeper IPS */
3869 rereg_priv->old_ips_mode = rtw_get_ips_mode_req(&padapter->pwrctrlpriv);
3870 rtw_ips_mode_req(&padapter->pwrctrlpriv, IPS_NORMAL);
3876 static void mac_reg_dump(struct adapter *padapter)
3879 pr_info("\n ======= MAC REG =======\n");
3880 for (i = 0x0; i < 0x300; i += 4) {
3882 pr_info("0x%02x", i);
3883 pr_info(" 0x%08x ", rtw_read32(padapter, i));
3887 for (i = 0x400; i < 0x800; i += 4) {
3889 pr_info("0x%02x", i);
3890 pr_info(" 0x%08x ", rtw_read32(padapter, i));
3896 static void bb_reg_dump(struct adapter *padapter)
3899 pr_info("\n ======= BB REG =======\n");
3900 for (i = 0x800; i < 0x1000; i += 4) {
3902 pr_info("0x%02x", i);
3904 pr_info(" 0x%08x ", rtw_read32(padapter, i));
3910 static void rf_reg_dump(struct adapter *padapter)
3914 u8 rf_type, path_nums = 0;
3915 rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
3917 pr_info("\n ======= RF REG =======\n");
3918 if ((RF_1T2R == rf_type) || (RF_1T1R == rf_type))
3923 for (path = 0; path < path_nums; path++) {
3924 pr_info("\nRF_Path(%x)\n", path);
3925 for (i = 0; i < 0x100; i++) {
3926 value = rtw_hal_read_rfreg(padapter, path, i, 0xffffffff);
3928 pr_info("0x%02x ", i);
3929 pr_info(" 0x%08x ", value);
3936 static int rtw_dbg_port(struct net_device *dev,
3937 struct iw_request_info *info,
3938 union iwreq_data *wrqu, char *extra)
3941 u8 major_cmd, minor_cmd;
3945 struct sta_info *psta;
3946 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
3947 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
3948 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3949 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
3950 struct security_priv *psecuritypriv = &padapter->securitypriv;
3951 struct wlan_network *cur_network = &pmlmepriv->cur_network;
3952 struct sta_priv *pstapriv = &padapter->stapriv;
3954 pdata = (u32 *)&wrqu->data;
3957 arg = (u16)(val32 & 0x0000ffff);
3958 major_cmd = (u8)(val32 >> 24);
3959 minor_cmd = (u8)((val32 >> 16) & 0x00ff);
3961 extra_arg = *(pdata + 1);
3963 switch (major_cmd) {
3964 case 0x70:/* read_reg */
3965 switch (minor_cmd) {
3967 DBG_88E("rtw_read8(0x%x) = 0x%02x\n", arg, rtw_read8(padapter, arg));
3970 DBG_88E("rtw_read16(0x%x) = 0x%04x\n", arg, rtw_read16(padapter, arg));
3973 DBG_88E("rtw_read32(0x%x) = 0x%08x\n", arg, rtw_read32(padapter, arg));
3977 case 0x71:/* write_reg */
3978 switch (minor_cmd) {
3980 rtw_write8(padapter, arg, extra_arg);
3981 DBG_88E("rtw_write8(0x%x) = 0x%02x\n", arg, rtw_read8(padapter, arg));
3984 rtw_write16(padapter, arg, extra_arg);
3985 DBG_88E("rtw_write16(0x%x) = 0x%04x\n", arg, rtw_read16(padapter, arg));
3988 rtw_write32(padapter, arg, extra_arg);
3989 DBG_88E("rtw_write32(0x%x) = 0x%08x\n", arg, rtw_read32(padapter, arg));
3993 case 0x72:/* read_bb */
3994 DBG_88E("read_bbreg(0x%x) = 0x%x\n", arg, rtw_hal_read_bbreg(padapter, arg, 0xffffffff));
3996 case 0x73:/* write_bb */
3997 rtw_hal_write_bbreg(padapter, arg, 0xffffffff, extra_arg);
3998 DBG_88E("write_bbreg(0x%x) = 0x%x\n", arg, rtw_hal_read_bbreg(padapter, arg, 0xffffffff));
4000 case 0x74:/* read_rf */
4001 DBG_88E("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));
4003 case 0x75:/* write_rf */
4004 rtw_hal_write_rfreg(padapter, minor_cmd, arg, 0xffffffff, extra_arg);
4005 DBG_88E("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));
4009 switch (minor_cmd) {
4010 case 0x00: /* normal mode, */
4011 padapter->recvpriv.is_signal_dbg = 0;
4013 case 0x01: /* dbg mode */
4014 padapter->recvpriv.is_signal_dbg = 1;
4015 extra_arg = extra_arg > 100 ? 100 : extra_arg;
4016 extra_arg = extra_arg < 0 ? 0 : extra_arg;
4017 padapter->recvpriv.signal_strength_dbg = extra_arg;
4021 case 0x78: /* IOL test */
4022 switch (minor_cmd) {
4023 case 0x04: /* LLT table initialization test */
4025 u8 page_boundary = 0xf9;
4026 struct xmit_frame *xmit_frame;
4028 xmit_frame = rtw_IOL_accquire_xmit_frame(padapter);
4034 rtw_IOL_append_LLT_cmd(xmit_frame, page_boundary);
4036 if (_SUCCESS != rtw_IOL_exec_cmds_sync(padapter, xmit_frame, 500, 0))
4040 case 0x05: /* blink LED test */
4044 u32 blink_delay_ms = 200;
4046 struct xmit_frame *xmit_frame;
4048 xmit_frame = rtw_IOL_accquire_xmit_frame(padapter);
4054 for (i = 0; i < blink_num; i++) {
4055 rtw_IOL_append_WB_cmd(xmit_frame, reg, 0x00, 0xff);
4056 rtw_IOL_append_DELAY_MS_cmd(xmit_frame, blink_delay_ms);
4057 rtw_IOL_append_WB_cmd(xmit_frame, reg, 0x08, 0xff);
4058 rtw_IOL_append_DELAY_MS_cmd(xmit_frame, blink_delay_ms);
4060 if (_SUCCESS != rtw_IOL_exec_cmds_sync(padapter, xmit_frame, (blink_delay_ms * blink_num * 2) + 200, 0))
4065 case 0x06: /* continuous write byte test */
4068 u16 start_value = 0;
4069 u32 write_num = extra_arg;
4072 struct xmit_frame *xmit_frame;
4074 xmit_frame = rtw_IOL_accquire_xmit_frame(padapter);
4080 for (i = 0; i < write_num; i++)
4081 rtw_IOL_append_WB_cmd(xmit_frame, reg, i + start_value, 0xFF);
4082 if (_SUCCESS != rtw_IOL_exec_cmds_sync(padapter, xmit_frame, 5000, 0))
4085 final = rtw_read8(padapter, reg);
4086 if (start_value + write_num - 1 == final)
4087 DBG_88E("continuous IOL_CMD_WB_REG to 0x%x %u times Success, start:%u, final:%u\n", reg, write_num, start_value, final);
4089 DBG_88E("continuous IOL_CMD_WB_REG to 0x%x %u times Fail, start:%u, final:%u\n", reg, write_num, start_value, final);
4093 case 0x07: /* continuous write word test */
4096 u16 start_value = 200;
4097 u32 write_num = extra_arg;
4101 struct xmit_frame *xmit_frame;
4103 xmit_frame = rtw_IOL_accquire_xmit_frame(padapter);
4109 for (i = 0; i < write_num; i++)
4110 rtw_IOL_append_WW_cmd(xmit_frame, reg, i + start_value, 0xFFFF);
4111 if (_SUCCESS != rtw_IOL_exec_cmds_sync(padapter, xmit_frame, 5000, 0))
4114 final = rtw_read16(padapter, reg);
4115 if (start_value + write_num - 1 == final)
4116 DBG_88E("continuous IOL_CMD_WW_REG to 0x%x %u times Success, start:%u, final:%u\n", reg, write_num, start_value, final);
4118 DBG_88E("continuous IOL_CMD_WW_REG to 0x%x %u times Fail, start:%u, final:%u\n", reg, write_num, start_value, final);
4121 case 0x08: /* continuous write dword test */
4124 u32 start_value = 0x110000c7;
4125 u32 write_num = extra_arg;
4129 struct xmit_frame *xmit_frame;
4131 xmit_frame = rtw_IOL_accquire_xmit_frame(padapter);
4137 for (i = 0; i < write_num; i++)
4138 rtw_IOL_append_WD_cmd(xmit_frame, reg, i + start_value, 0xFFFFFFFF);
4139 if (_SUCCESS != rtw_IOL_exec_cmds_sync(padapter, xmit_frame, 5000, 0))
4142 final = rtw_read32(padapter, reg);
4143 if (start_value + write_num - 1 == final)
4144 DBG_88E("continuous IOL_CMD_WD_REG to 0x%x %u times Success, start:%u, final:%u\n",
4145 reg, write_num, start_value, final);
4147 DBG_88E("continuous IOL_CMD_WD_REG to 0x%x %u times Fail, start:%u, final:%u\n",
4148 reg, write_num, start_value, final);
4156 * dbg 0x79000000 [value], set RESP_TXAGC to + value, value:0~15
4157 * dbg 0x79010000 [value], set RESP_TXAGC to - value, value:0~15
4159 u8 value = extra_arg & 0x0f;
4160 u8 sign = minor_cmd;
4161 u16 write_value = 0;
4163 DBG_88E("%s set RESP_TXAGC to %s %u\n", __func__, sign ? "minus" : "plus", value);
4166 value = value | 0x10;
4168 write_value = value | (value << 5);
4169 rtw_write16(padapter, 0x6d9, write_value);
4173 receive_disconnect(padapter, pmlmeinfo->network.MacAddress
4174 , WLAN_REASON_EXPIRATION_CHK);
4177 switch (minor_cmd) {
4179 DBG_88E("fwstate = 0x%x\n", get_fwstate(pmlmepriv));
4182 DBG_88E("auth_alg = 0x%x, enc_alg = 0x%x, auth_type = 0x%x, enc_type = 0x%x\n",
4183 psecuritypriv->dot11AuthAlgrthm, psecuritypriv->dot11PrivacyAlgrthm,
4184 psecuritypriv->ndisauthtype, psecuritypriv->ndisencryptstatus);
4187 DBG_88E("pmlmeinfo->state = 0x%x\n", pmlmeinfo->state);
4190 DBG_88E("qos_option =%d\n", pmlmepriv->qospriv.qos_option);
4191 DBG_88E("ht_option =%d\n", pmlmepriv->htpriv.ht_option);
4194 DBG_88E("cur_ch =%d\n", pmlmeext->cur_channel);
4195 DBG_88E("cur_bw =%d\n", pmlmeext->cur_bwmode);
4196 DBG_88E("cur_ch_off =%d\n", pmlmeext->cur_ch_offset);
4199 psta = rtw_get_stainfo(pstapriv, cur_network->network.MacAddress);
4202 struct recv_reorder_ctrl *preorder_ctrl;
4204 DBG_88E("SSID =%s\n", cur_network->network.Ssid.Ssid);
4205 DBG_88E("sta's macaddr: %pM\n", psta->hwaddr);
4206 DBG_88E("cur_channel =%d, cur_bwmode =%d, cur_ch_offset =%d\n", pmlmeext->cur_channel, pmlmeext->cur_bwmode, pmlmeext->cur_ch_offset);
4207 DBG_88E("rtsen =%d, cts2slef =%d\n", psta->rtsen, psta->cts2self);
4208 DBG_88E("state = 0x%x, aid =%d, macid =%d, raid =%d\n", psta->state, psta->aid, psta->mac_id, psta->raid);
4209 DBG_88E("qos_en =%d, ht_en =%d, init_rate =%d\n", psta->qos_option, psta->htpriv.ht_option, psta->init_rate);
4210 DBG_88E("bwmode =%d, ch_offset =%d, sgi =%d\n", psta->htpriv.bwmode, psta->htpriv.ch_offset, psta->htpriv.sgi);
4211 DBG_88E("ampdu_enable = %d\n", psta->htpriv.ampdu_enable);
4212 DBG_88E("agg_enable_bitmap =%x, candidate_tid_bitmap =%x\n", psta->htpriv.agg_enable_bitmap, psta->htpriv.candidate_tid_bitmap);
4213 for (i = 0; i < 16; i++) {
4214 preorder_ctrl = &psta->recvreorder_ctrl[i];
4215 if (preorder_ctrl->enable)
4216 DBG_88E("tid =%d, indicate_seq =%d\n", i, preorder_ctrl->indicate_seq);
4219 DBG_88E("can't get sta's macaddr, cur_network's macaddr:%pM\n", (cur_network->network.MacAddress));
4225 rtw_hal_get_hwreg(padapter, HW_VAR_DM_FLAG, (u8 *)(&ODMFlag));
4226 DBG_88E("(B)DMFlag = 0x%x, arg = 0x%x\n", ODMFlag, arg);
4227 ODMFlag = (u32)(0x0f & arg);
4228 DBG_88E("(A)DMFlag = 0x%x\n", ODMFlag);
4229 rtw_hal_set_hwreg(padapter, HW_VAR_DM_FLAG, (u8 *)(&ODMFlag));
4233 DBG_88E("bSurpriseRemoved =%d, bDriverStopped =%d\n",
4234 padapter->bSurpriseRemoved, padapter->bDriverStopped);
4238 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
4239 struct recv_priv *precvpriv = &padapter->recvpriv;
4241 DBG_88E("free_xmitbuf_cnt =%d, free_xmitframe_cnt =%d, free_xmit_extbuf_cnt =%d\n",
4242 pxmitpriv->free_xmitbuf_cnt, pxmitpriv->free_xmitframe_cnt, pxmitpriv->free_xmit_extbuf_cnt);
4243 DBG_88E("rx_urb_pending_cn =%d\n", precvpriv->rx_pending_cnt);
4249 struct list_head *plist, *phead;
4250 struct recv_reorder_ctrl *preorder_ctrl;
4252 #ifdef CONFIG_88EU_AP_MODE
4253 DBG_88E("sta_dz_bitmap = 0x%x, tim_bitmap = 0x%x\n", pstapriv->sta_dz_bitmap, pstapriv->tim_bitmap);
4255 spin_lock_bh(&pstapriv->sta_hash_lock);
4257 for (i = 0; i < NUM_STA; i++) {
4258 phead = &pstapriv->sta_hash[i];
4259 plist = phead->next;
4261 while (phead != plist) {
4262 psta = container_of(plist, struct sta_info, hash_list);
4264 plist = plist->next;
4266 if (extra_arg == psta->aid) {
4267 DBG_88E("sta's macaddr:%pM\n", (psta->hwaddr));
4268 DBG_88E("rtsen =%d, cts2slef =%d\n", psta->rtsen, psta->cts2self);
4269 DBG_88E("state = 0x%x, aid =%d, macid =%d, raid =%d\n", psta->state, psta->aid, psta->mac_id, psta->raid);
4270 DBG_88E("qos_en =%d, ht_en =%d, init_rate =%d\n", psta->qos_option, psta->htpriv.ht_option, psta->init_rate);
4271 DBG_88E("bwmode =%d, ch_offset =%d, sgi =%d\n", psta->htpriv.bwmode, psta->htpriv.ch_offset, psta->htpriv.sgi);
4272 DBG_88E("ampdu_enable = %d\n", psta->htpriv.ampdu_enable);
4273 DBG_88E("agg_enable_bitmap =%x, candidate_tid_bitmap =%x\n", psta->htpriv.agg_enable_bitmap, psta->htpriv.candidate_tid_bitmap);
4275 #ifdef CONFIG_88EU_AP_MODE
4276 DBG_88E("capability = 0x%x\n", psta->capability);
4277 DBG_88E("flags = 0x%x\n", psta->flags);
4278 DBG_88E("wpa_psk = 0x%x\n", psta->wpa_psk);
4279 DBG_88E("wpa2_group_cipher = 0x%x\n", psta->wpa2_group_cipher);
4280 DBG_88E("wpa2_pairwise_cipher = 0x%x\n", psta->wpa2_pairwise_cipher);
4281 DBG_88E("qos_info = 0x%x\n", psta->qos_info);
4283 DBG_88E("dot118021XPrivacy = 0x%x\n", psta->dot118021XPrivacy);
4285 for (j = 0; j < 16; j++) {
4286 preorder_ctrl = &psta->recvreorder_ctrl[j];
4287 if (preorder_ctrl->enable)
4288 DBG_88E("tid =%d, indicate_seq =%d\n", j, preorder_ctrl->indicate_seq);
4293 spin_unlock_bh(&pstapriv->sta_hash_lock);
4296 case 0x0c:/* dump rx/tx packet */
4298 DBG_88E("dump rx packet (%d)\n", extra_arg);
4299 rtw_hal_set_def_var(padapter, HAL_DEF_DBG_DUMP_RXPKT, &(extra_arg));
4300 } else if (arg == 1) {
4301 DBG_88E("dump tx packet (%d)\n", extra_arg);
4302 rtw_hal_set_def_var(padapter, HAL_DEF_DBG_DUMP_TXPKT, &(extra_arg));
4306 if (extra_arg == 0) {
4307 DBG_88E("###### silent reset test.......#####\n");
4308 rtw_hal_sreset_reset(padapter);
4313 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
4314 DBG_88E("==>silent resete cnts:%d\n", pwrpriv->ips_enter_cnts);
4317 case 0x10:/* driver version display */
4318 DBG_88E("rtw driver version =%s\n", DRIVERVERSION);
4321 DBG_88E("turn %s Rx RSSI display function\n", (extra_arg == 1) ? "on" : "off");
4322 padapter->bRxRSSIDisplay = extra_arg;
4324 case 0x12: /* set rx_stbc */
4326 struct registry_priv *pregpriv = &padapter->registrypriv;
4327 /* 0: disable, bit(0):enable 2.4g, bit(1):enable 5g, 0x3: enable both 2.4g and 5g */
4328 /* default is set to enable 2.4GHZ for IOT issue with bufflao's AP at 5GHZ */
4334 pregpriv->rx_stbc = extra_arg;
4335 DBG_88E("set rx_stbc =%d\n", pregpriv->rx_stbc);
4337 DBG_88E("get rx_stbc =%d\n", pregpriv->rx_stbc);
4341 case 0x13: /* set ampdu_enable */
4343 struct registry_priv *pregpriv = &padapter->registrypriv;
4344 /* 0: disable, 0x1:enable (but wifi_spec should be 0), 0x2: force enable (don't care wifi_spec) */
4345 if (pregpriv && extra_arg >= 0 && extra_arg < 3) {
4346 pregpriv->ampdu_enable = extra_arg;
4347 DBG_88E("set ampdu_enable =%d\n", pregpriv->ampdu_enable);
4349 DBG_88E("get ampdu_enable =%d\n", pregpriv->ampdu_enable);
4353 case 0x14: /* get wifi_spec */
4355 struct registry_priv *pregpriv = &padapter->registrypriv;
4356 DBG_88E("get wifi_spec =%d\n", pregpriv->wifi_spec);
4360 DBG_88E("turn %s the bNotifyChannelChange Variable\n", (extra_arg == 1) ? "on" : "off");
4361 padapter->bNotifyChannelChange = extra_arg;
4364 #ifdef CONFIG_88EU_P2P
4365 DBG_88E("turn %s the bShowGetP2PState Variable\n", (extra_arg == 1) ? "on" : "off");
4366 padapter->bShowGetP2PState = extra_arg;
4367 #endif /* CONFIG_88EU_P2P */
4370 if (extra_arg > 0x13)
4372 DBG_88E("chang data rate to :0x%02x\n", extra_arg);
4373 padapter->fix_rate = extra_arg;
4375 case 0xdd:/* registers dump, 0 for mac reg, 1 for bb reg, 2 for rf reg */
4377 mac_reg_dump(padapter);
4378 else if (extra_arg == 1)
4379 bb_reg_dump(padapter);
4380 else if (extra_arg == 2)
4381 rf_reg_dump(padapter);
4383 case 0xee:/* turn on/off dynamic funcs */
4387 if (0xf == extra_arg) {
4388 rtw_hal_get_def_var(padapter, HAL_DEF_DBG_DM_FUNC, &odm_flag);
4389 DBG_88E(" === DMFlag(0x%08x) ===\n", odm_flag);
4390 DBG_88E("extra_arg = 0 - disable all dynamic func\n");
4391 DBG_88E("extra_arg = 1 - disable DIG- BIT(0)\n");
4392 DBG_88E("extra_arg = 2 - disable High power - BIT(1)\n");
4393 DBG_88E("extra_arg = 3 - disable tx power tracking - BIT(2)\n");
4394 DBG_88E("extra_arg = 4 - disable BT coexistence - BIT(3)\n");
4395 DBG_88E("extra_arg = 5 - disable antenna diversity - BIT(4)\n");
4396 DBG_88E("extra_arg = 6 - enable all dynamic func\n");
4398 /* extra_arg = 0 - disable all dynamic func
4399 extra_arg = 1 - disable DIG
4400 extra_arg = 2 - disable tx power tracking
4401 extra_arg = 3 - turn on all dynamic func
4403 rtw_hal_set_def_var(padapter, HAL_DEF_DBG_DM_FUNC, &(extra_arg));
4404 rtw_hal_get_def_var(padapter, HAL_DEF_DBG_DM_FUNC, &odm_flag);
4405 DBG_88E(" === DMFlag(0x%08x) ===\n", odm_flag);
4411 rtw_write8(padapter, 0xc50, arg);
4412 DBG_88E("wr(0xc50) = 0x%x\n", rtw_read8(padapter, 0xc50));
4413 rtw_write8(padapter, 0xc58, arg);
4414 DBG_88E("wr(0xc58) = 0x%x\n", rtw_read8(padapter, 0xc58));
4417 DBG_88E("rd(0xc50) = 0x%x\n", rtw_read8(padapter, 0xc50));
4418 DBG_88E("rd(0xc58) = 0x%x\n", rtw_read8(padapter, 0xc58));
4421 DBG_88E("dbg(0x210) = 0x%x\n", rtw_read32(padapter, 0x210));
4422 DBG_88E("dbg(0x608) = 0x%x\n", rtw_read32(padapter, 0x608));
4423 DBG_88E("dbg(0x280) = 0x%x\n", rtw_read32(padapter, 0x280));
4424 DBG_88E("dbg(0x284) = 0x%x\n", rtw_read32(padapter, 0x284));
4425 DBG_88E("dbg(0x288) = 0x%x\n", rtw_read32(padapter, 0x288));
4427 DBG_88E("dbg(0x664) = 0x%x\n", rtw_read32(padapter, 0x664));
4431 DBG_88E("dbg(0x430) = 0x%x\n", rtw_read32(padapter, 0x430));
4432 DBG_88E("dbg(0x438) = 0x%x\n", rtw_read32(padapter, 0x438));
4434 DBG_88E("dbg(0x440) = 0x%x\n", rtw_read32(padapter, 0x440));
4436 DBG_88E("dbg(0x458) = 0x%x\n", rtw_read32(padapter, 0x458));
4438 DBG_88E("dbg(0x484) = 0x%x\n", rtw_read32(padapter, 0x484));
4439 DBG_88E("dbg(0x488) = 0x%x\n", rtw_read32(padapter, 0x488));
4441 DBG_88E("dbg(0x444) = 0x%x\n", rtw_read32(padapter, 0x444));
4442 DBG_88E("dbg(0x448) = 0x%x\n", rtw_read32(padapter, 0x448));
4443 DBG_88E("dbg(0x44c) = 0x%x\n", rtw_read32(padapter, 0x44c));
4444 DBG_88E("dbg(0x450) = 0x%x\n", rtw_read32(padapter, 0x450));
4449 DBG_88E("error dbg cmd!\n");
4455 static int rtw_wx_set_priv(struct net_device *dev,
4456 struct iw_request_info *info,
4457 union iwreq_data *awrq,
4463 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
4464 struct iw_point *dwrq = (struct iw_point *)awrq;
4466 if (dwrq->length == 0)
4474 if (copy_from_user(ext, dwrq->pointer, len)) {
4479 /* added for wps2.0 @20110524 */
4480 if (dwrq->flags == 0x8766 && len > 8) {
4482 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
4483 u8 *probereq_wpsie = ext;
4484 int probereq_wpsie_len = len;
4485 u8 wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
4487 if ((_VENDOR_SPECIFIC_IE_ == probereq_wpsie[0]) &&
4488 (!memcmp(&probereq_wpsie[2], wps_oui, 4))) {
4489 cp_sz = probereq_wpsie_len > MAX_WPS_IE_LEN ? MAX_WPS_IE_LEN : probereq_wpsie_len;
4491 pmlmepriv->wps_probe_req_ie_len = 0;
4492 kfree(pmlmepriv->wps_probe_req_ie);
4493 pmlmepriv->wps_probe_req_ie = NULL;
4495 pmlmepriv->wps_probe_req_ie = kmalloc(cp_sz, GFP_KERNEL);
4496 if (!pmlmepriv->wps_probe_req_ie) {
4500 memcpy(pmlmepriv->wps_probe_req_ie, probereq_wpsie, cp_sz);
4501 pmlmepriv->wps_probe_req_ie_len = cp_sz;
4506 if (len >= WEXT_CSCAN_HEADER_SIZE &&
4507 !memcmp(ext, WEXT_CSCAN_HEADER, WEXT_CSCAN_HEADER_SIZE)) {
4508 ret = rtw_wx_set_scan(dev, info, awrq, ext);
4519 static int rtw_pm_set(struct net_device *dev,
4520 struct iw_request_info *info,
4521 union iwreq_data *wrqu, char *extra)
4525 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
4527 DBG_88E("[%s] extra = %s\n", __func__, extra);
4529 if (!memcmp(extra, "lps =", 4)) {
4530 sscanf(extra + 4, "%u", &mode);
4531 ret = rtw_pm_set_lps(padapter, mode);
4532 } else if (!memcmp(extra, "ips =", 4)) {
4533 sscanf(extra + 4, "%u", &mode);
4534 ret = rtw_pm_set_ips(padapter, mode);
4542 static int rtw_mp_efuse_get(struct net_device *dev,
4543 struct iw_request_info *info,
4544 union iwreq_data *wdata, char *extra)
4546 struct adapter *padapter = rtw_netdev_priv(dev);
4547 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
4548 struct hal_data_8188e *haldata = GET_HAL_DATA(padapter);
4549 struct efuse_hal *pEfuseHal;
4550 struct iw_point *wrqu;
4552 u8 *PROMContent = pEEPROM->efuse_eeprom_data;
4553 u8 ips_mode = 0, lps_mode = 0;
4554 struct pwrctrl_priv *pwrctrlpriv;
4557 char *pch, *ptmp, *token, *tmp[3] = {NULL, NULL, NULL};
4558 u16 i = 0, j = 0, mapLen = 0, addr = 0, cnts = 0;
4559 u16 max_available_size = 0, raw_cursize = 0, raw_maxsize = 0;
4561 u8 org_fw_iol = padapter->registrypriv.fw_iol;/* 0:Disable, 1:enable, 2:by usb speed */
4563 wrqu = (struct iw_point *)wdata;
4564 pwrctrlpriv = &padapter->pwrctrlpriv;
4565 pEfuseHal = &haldata->EfuseHal;
4568 data = kzalloc(EFUSE_BT_MAX_MAP_LEN, GFP_KERNEL);
4573 rawdata = kzalloc(EFUSE_BT_MAX_MAP_LEN, GFP_KERNEL);
4579 if (copy_from_user(extra, wrqu->pointer, wrqu->length)) {
4583 lps_mode = pwrctrlpriv->power_mgnt;/* keep org value */
4584 rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);
4586 ips_mode = pwrctrlpriv->ips_mode;/* keep org value */
4587 rtw_pm_set_ips(padapter, IPS_NONE);
4590 DBG_88E("%s: in =%s\n", __func__, extra);
4593 /* mac 16 "00e04c871200" rmap, 00, 2 */
4594 while ((token = strsep(&pch, ",")) != NULL) {
4600 padapter->registrypriv.fw_iol = 0;/* 0:Disable, 1:enable, 2:by usb speed */
4602 if (strcmp(tmp[0], "status") == 0) {
4603 sprintf(extra, "Load File efuse =%s, Load File MAC =%s", (pEEPROM->bloadfile_fail_flag ? "FAIL" : "OK"), (pEEPROM->bloadmac_fail_flag ? "FAIL" : "OK"));
4606 } else if (strcmp(tmp[0], "filemap") == 0) {
4607 mapLen = EFUSE_MAP_SIZE;
4609 sprintf(extra, "\n");
4610 for (i = 0; i < EFUSE_MAP_SIZE; i += 16) {
4611 sprintf(extra + strlen(extra), "0x%02x\t", i);
4612 for (j = 0; j < 8; j++)
4613 sprintf(extra + strlen(extra), "%02X ", PROMContent[i + j]);
4614 sprintf(extra + strlen(extra), "\t");
4616 sprintf(extra + strlen(extra), "%02X ", PROMContent[i + j]);
4617 sprintf(extra + strlen(extra), "\n");
4619 } else if (strcmp(tmp[0], "realmap") == 0) {
4620 mapLen = EFUSE_MAP_SIZE;
4621 if (rtw_efuse_map_read(padapter, 0, mapLen, pEfuseHal->fakeEfuseInitMap) == _FAIL) {
4622 DBG_88E("%s: read realmap Fail!!\n", __func__);
4627 sprintf(extra, "\n");
4628 for (i = 0; i < EFUSE_MAP_SIZE; i += 16) {
4629 sprintf(extra + strlen(extra), "0x%02x\t", i);
4630 for (j = 0; j < 8; j++)
4631 sprintf(extra + strlen(extra), "%02X ", pEfuseHal->fakeEfuseInitMap[i + j]);
4632 sprintf(extra + strlen(extra), "\t");
4634 sprintf(extra + strlen(extra), "%02X ", pEfuseHal->fakeEfuseInitMap[i + j]);
4635 sprintf(extra + strlen(extra), "\n");
4637 } else if (strcmp(tmp[0], "rmap") == 0) {
4638 if (!tmp[1] || !tmp[2]) {
4639 DBG_88E("%s: rmap Fail!! Parameters error!\n", __func__);
4644 /* rmap addr cnts */
4645 addr = simple_strtoul(tmp[1], &ptmp, 16);
4646 DBG_88E("%s: addr =%x\n", __func__, addr);
4648 cnts = simple_strtoul(tmp[2], &ptmp, 10);
4650 DBG_88E("%s: rmap Fail!! cnts error!\n", __func__);
4654 DBG_88E("%s: cnts =%d\n", __func__, cnts);
4656 EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (void *)&max_available_size, false);
4657 if ((addr + cnts) > max_available_size) {
4658 DBG_88E("%s: addr(0x%X)+cnts(%d) parameter error!\n", __func__, addr, cnts);
4663 if (rtw_efuse_map_read(padapter, addr, cnts, data) == _FAIL) {
4664 DBG_88E("%s: rtw_efuse_map_read error!\n", __func__);
4670 for (i = 0; i < cnts; i++)
4671 sprintf(extra + strlen(extra), "0x%02X ", data[i]);
4672 } else if (strcmp(tmp[0], "realraw") == 0) {
4674 mapLen = EFUSE_MAX_SIZE;
4675 if (rtw_efuse_access(padapter, false, addr, mapLen, rawdata) == _FAIL) {
4676 DBG_88E("%s: rtw_efuse_access Fail!!\n", __func__);
4681 sprintf(extra, "\n");
4682 for (i = 0; i < mapLen; i++) {
4683 sprintf(extra + strlen(extra), "%02X", rawdata[i]);
4685 if ((i & 0xF) == 0xF)
4686 sprintf(extra + strlen(extra), "\n");
4687 else if ((i & 0x7) == 0x7)
4688 sprintf(extra + strlen(extra), "\t");
4690 sprintf(extra + strlen(extra), " ");
4692 } else if (strcmp(tmp[0], "mac") == 0) {
4695 EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (void *)&max_available_size, false);
4696 if ((addr + cnts) > max_available_size) {
4697 DBG_88E("%s: addr(0x%02x)+cnts(%d) parameter error!\n", __func__, addr, cnts);
4702 if (rtw_efuse_map_read(padapter, addr, cnts, data) == _FAIL) {
4703 DBG_88E("%s: rtw_efuse_map_read error!\n", __func__);
4709 for (i = 0; i < cnts; i++) {
4710 sprintf(extra + strlen(extra), "%02X", data[i]);
4711 if (i != (cnts - 1))
4712 sprintf(extra + strlen(extra), ":");
4714 } else if (strcmp(tmp[0], "vidpid") == 0) {
4717 EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (void *)&max_available_size, false);
4718 if ((addr + cnts) > max_available_size) {
4719 DBG_88E("%s: addr(0x%02x)+cnts(%d) parameter error!\n", __func__, addr, cnts);
4723 if (rtw_efuse_map_read(padapter, addr, cnts, data) == _FAIL) {
4724 DBG_88E("%s: rtw_efuse_access error!!\n", __func__);
4730 for (i = 0; i < cnts; i++) {
4731 sprintf(extra + strlen(extra), "0x%02X", data[i]);
4732 if (i != (cnts - 1))
4733 sprintf(extra + strlen(extra), ",");
4735 } else if (strcmp(tmp[0], "ableraw") == 0) {
4736 efuse_GetCurrentSize(padapter, &raw_cursize);
4737 raw_maxsize = efuse_GetMaxSize(padapter);
4738 sprintf(extra, "[available raw size] = %d bytes", raw_maxsize - raw_cursize);
4739 } else if (strcmp(tmp[0], "btfmap") == 0) {
4740 mapLen = EFUSE_BT_MAX_MAP_LEN;
4741 if (rtw_BT_efuse_map_read(padapter, 0, mapLen, pEfuseHal->BTEfuseInitMap) == _FAIL) {
4742 DBG_88E("%s: rtw_BT_efuse_map_read Fail!!\n", __func__);
4747 sprintf(extra, "\n");
4748 for (i = 0; i < 512; i += 16) {
4749 /* set 512 because the iwpriv's extra size have limit 0x7FF */
4750 sprintf(extra + strlen(extra), "0x%03x\t", i);
4751 for (j = 0; j < 8; j++)
4752 sprintf(extra + strlen(extra), "%02X ", pEfuseHal->BTEfuseInitMap[i + j]);
4753 sprintf(extra + strlen(extra), "\t");
4755 sprintf(extra + strlen(extra), "%02X ", pEfuseHal->BTEfuseInitMap[i + j]);
4756 sprintf(extra + strlen(extra), "\n");
4758 } else if (strcmp(tmp[0], "btbmap") == 0) {
4759 mapLen = EFUSE_BT_MAX_MAP_LEN;
4760 if (rtw_BT_efuse_map_read(padapter, 0, mapLen, pEfuseHal->BTEfuseInitMap) == _FAIL) {
4761 DBG_88E("%s: rtw_BT_efuse_map_read Fail!!\n", __func__);
4766 sprintf(extra, "\n");
4767 for (i = 512; i < 1024; i += 16) {
4768 sprintf(extra + strlen(extra), "0x%03x\t", i);
4769 for (j = 0; j < 8; j++)
4770 sprintf(extra + strlen(extra), "%02X ", pEfuseHal->BTEfuseInitMap[i + j]);
4771 sprintf(extra + strlen(extra), "\t");
4773 sprintf(extra + strlen(extra), "%02X ", pEfuseHal->BTEfuseInitMap[i + j]);
4774 sprintf(extra + strlen(extra), "\n");
4776 } else if (strcmp(tmp[0], "btrmap") == 0) {
4777 if (!tmp[1] || !tmp[2]) {
4782 /* rmap addr cnts */
4783 addr = simple_strtoul(tmp[1], &ptmp, 16);
4784 DBG_88E("%s: addr = 0x%X\n", __func__, addr);
4786 cnts = simple_strtoul(tmp[2], &ptmp, 10);
4788 DBG_88E("%s: btrmap Fail!! cnts error!\n", __func__);
4792 DBG_88E("%s: cnts =%d\n", __func__, cnts);
4794 EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (void *)&max_available_size, false);
4795 if ((addr + cnts) > max_available_size) {
4796 DBG_88E("%s: addr(0x%X)+cnts(%d) parameter error!\n", __func__, addr, cnts);
4801 if (rtw_BT_efuse_map_read(padapter, addr, cnts, data) == _FAIL) {
4802 DBG_88E("%s: rtw_BT_efuse_map_read error!!\n", __func__);
4808 for (i = 0; i < cnts; i++)
4809 sprintf(extra + strlen(extra), " 0x%02X ", data[i]);
4810 } else if (strcmp(tmp[0], "btffake") == 0) {
4811 sprintf(extra, "\n");
4812 for (i = 0; i < 512; i += 16) {
4813 sprintf(extra + strlen(extra), "0x%03x\t", i);
4814 for (j = 0; j < 8; j++)
4815 sprintf(extra + strlen(extra), "%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i + j]);
4816 sprintf(extra + strlen(extra), "\t");
4818 sprintf(extra + strlen(extra), "%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i + j]);
4819 sprintf(extra + strlen(extra), "\n");
4821 } else if (strcmp(tmp[0], "btbfake") == 0) {
4822 sprintf(extra, "\n");
4823 for (i = 512; i < 1024; i += 16) {
4824 sprintf(extra + strlen(extra), "0x%03x\t", i);
4825 for (j = 0; j < 8; j++)
4826 sprintf(extra + strlen(extra), "%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i + j]);
4827 sprintf(extra + strlen(extra), "\t");
4829 sprintf(extra + strlen(extra), "%02X ", pEfuseHal->fakeBTEfuseModifiedMap[i + j]);
4830 sprintf(extra + strlen(extra), "\n");
4832 } else if (strcmp(tmp[0], "wlrfkmap") == 0) {
4833 sprintf(extra, "\n");
4834 for (i = 0; i < EFUSE_MAP_SIZE; i += 16) {
4835 sprintf(extra + strlen(extra), "0x%02x\t", i);
4836 for (j = 0; j < 8; j++)
4837 sprintf(extra + strlen(extra), "%02X ", pEfuseHal->fakeEfuseModifiedMap[i + j]);
4838 sprintf(extra + strlen(extra), "\t");
4840 sprintf(extra + strlen(extra), " %02X", pEfuseHal->fakeEfuseModifiedMap[i + j]);
4841 sprintf(extra + strlen(extra), "\n");
4844 sprintf(extra, "Command not found!");
4851 wrqu->length = strlen(extra);
4853 rtw_pm_set_ips(padapter, ips_mode);
4854 rtw_pm_set_lps(padapter, lps_mode);
4855 padapter->registrypriv.fw_iol = org_fw_iol;/* 0:Disable, 1:enable, 2:by usb speed */
4859 static int rtw_mp_efuse_set(struct net_device *dev,
4860 struct iw_request_info *info,
4861 union iwreq_data *wdata, char *extra)
4863 struct adapter *padapter;
4864 struct pwrctrl_priv *pwrctrlpriv;
4865 struct hal_data_8188e *haldata;
4866 struct efuse_hal *pEfuseHal;
4868 u8 ips_mode = 0, lps_mode = 0;
4871 u8 *ShadowMapBT = NULL;
4872 u8 *ShadowMapWiFi = NULL;
4873 u8 *setrawdata = NULL;
4874 char *pch, *ptmp, *token, *tmp[3] = {NULL, NULL, NULL};
4875 u16 addr = 0, cnts = 0, max_available_size = 0;
4878 padapter = rtw_netdev_priv(dev);
4879 pwrctrlpriv = &padapter->pwrctrlpriv;
4880 haldata = GET_HAL_DATA(padapter);
4881 pEfuseHal = &haldata->EfuseHal;
4883 setdata = kzalloc(1024, GFP_KERNEL);
4888 ShadowMapBT = kmalloc(EFUSE_BT_MAX_MAP_LEN, GFP_KERNEL);
4893 ShadowMapWiFi = kmalloc(EFUSE_MAP_SIZE, GFP_KERNEL);
4894 if (!ShadowMapWiFi) {
4898 setrawdata = kmalloc(EFUSE_MAX_SIZE, GFP_KERNEL);
4904 lps_mode = pwrctrlpriv->power_mgnt;/* keep org value */
4905 rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);
4907 ips_mode = pwrctrlpriv->ips_mode;/* keep org value */
4908 rtw_pm_set_ips(padapter, IPS_NONE);
4911 DBG_88E("%s: in =%s\n", __func__, extra);
4914 while ((token = strsep(&pch, ",")) != NULL) {
4921 /* tmp[0],[1],[2] */
4922 /* wmap, addr, 00e04c871200 */
4923 if (strcmp(tmp[0], "wmap") == 0) {
4924 if (!tmp[1] || !tmp[2]) {
4929 addr = simple_strtoul(tmp[1], &ptmp, 16);
4932 cnts = strlen(tmp[2]);
4943 DBG_88E("%s: addr = 0x%X\n", __func__, addr);
4944 DBG_88E("%s: cnts =%d\n", __func__, cnts);
4945 DBG_88E("%s: map data =%s\n", __func__, tmp[2]);
4947 for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
4948 setdata[jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
4949 /* Change to check TYPE_EFUSE_MAP_LEN, because 8188E raw 256, logic map over 256. */
4950 EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&max_available_size, false);
4951 if ((addr + cnts) > max_available_size) {
4952 DBG_88E("%s: addr(0x%X)+cnts(%d) parameter error!\n", __func__, addr, cnts);
4957 if (rtw_efuse_map_write(padapter, addr, cnts, setdata) == _FAIL) {
4958 DBG_88E("%s: rtw_efuse_map_write error!!\n", __func__);
4962 } else if (strcmp(tmp[0], "wraw") == 0) {
4963 if (!tmp[1] || !tmp[2]) {
4968 addr = simple_strtoul(tmp[1], &ptmp, 16);
4971 cnts = strlen(tmp[2]);
4982 DBG_88E("%s: addr = 0x%X\n", __func__, addr);
4983 DBG_88E("%s: cnts =%d\n", __func__, cnts);
4984 DBG_88E("%s: raw data =%s\n", __func__, tmp[2]);
4986 for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
4987 setrawdata[jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
4989 if (rtw_efuse_access(padapter, true, addr, cnts, setrawdata) == _FAIL) {
4990 DBG_88E("%s: rtw_efuse_access error!!\n", __func__);
4994 } else if (strcmp(tmp[0], "mac") == 0) {
5000 /* mac, 00e04c871200 */
5001 addr = EEPROM_MAC_ADDR_88EU;
5002 cnts = strlen(tmp[1]);
5013 DBG_88E("%s: error data for mac addr =\"%s\"\n", __func__, tmp[1]);
5018 DBG_88E("%s: addr = 0x%X\n", __func__, addr);
5019 DBG_88E("%s: cnts =%d\n", __func__, cnts);
5020 DBG_88E("%s: MAC address =%s\n", __func__, tmp[1]);
5022 for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
5023 setdata[jj] = key_2char2num(tmp[1][kk], tmp[1][kk + 1]);
5024 /* Change to check TYPE_EFUSE_MAP_LEN, because 8188E raw 256, logic map over 256. */
5025 EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (void *)&max_available_size, false);
5026 if ((addr + cnts) > max_available_size) {
5027 DBG_88E("%s: addr(0x%X)+cnts(%d) parameter error!\n", __func__, addr, cnts);
5032 if (rtw_efuse_map_write(padapter, addr, cnts, setdata) == _FAIL) {
5033 DBG_88E("%s: rtw_efuse_map_write error!!\n", __func__);
5037 } else if (strcmp(tmp[0], "vidpid") == 0) {
5043 /* pidvid, da0b7881 */
5044 addr = EEPROM_VID_88EE;
5045 cnts = strlen(tmp[1]);
5056 DBG_88E("%s: addr = 0x%X\n", __func__, addr);
5057 DBG_88E("%s: cnts =%d\n", __func__, cnts);
5058 DBG_88E("%s: VID/PID =%s\n", __func__, tmp[1]);
5060 for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
5061 setdata[jj] = key_2char2num(tmp[1][kk], tmp[1][kk + 1]);
5063 EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (void *)&max_available_size, false);
5064 if ((addr + cnts) > max_available_size) {
5065 DBG_88E("%s: addr(0x%X)+cnts(%d) parameter error!\n", __func__, addr, cnts);
5070 if (rtw_efuse_map_write(padapter, addr, cnts, setdata) == _FAIL) {
5071 DBG_88E("%s: rtw_efuse_map_write error!!\n", __func__);
5075 } else if (strcmp(tmp[0], "btwmap") == 0) {
5076 if (!tmp[1] || !tmp[2]) {
5081 addr = simple_strtoul(tmp[1], &ptmp, 16);
5084 cnts = strlen(tmp[2]);
5095 DBG_88E("%s: addr = 0x%X\n", __func__, addr);
5096 DBG_88E("%s: cnts =%d\n", __func__, cnts);
5097 DBG_88E("%s: BT data =%s\n", __func__, tmp[2]);
5099 for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
5100 setdata[jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
5102 EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (void *)&max_available_size, false);
5103 if ((addr + cnts) > max_available_size) {
5104 DBG_88E("%s: addr(0x%X)+cnts(%d) parameter error!\n", __func__, addr, cnts);
5109 if (rtw_BT_efuse_map_write(padapter, addr, cnts, setdata) == _FAIL) {
5110 DBG_88E("%s: rtw_BT_efuse_map_write error!!\n", __func__);
5114 } else if (strcmp(tmp[0], "btwfake") == 0) {
5115 if (!tmp[1] || !tmp[2]) {
5120 addr = simple_strtoul(tmp[1], &ptmp, 16);
5123 cnts = strlen(tmp[2]);
5134 DBG_88E("%s: addr = 0x%X\n", __func__, addr);
5135 DBG_88E("%s: cnts =%d\n", __func__, cnts);
5136 DBG_88E("%s: BT tmp data =%s\n", __func__, tmp[2]);
5138 for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
5139 pEfuseHal->fakeBTEfuseModifiedMap[addr + jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
5140 } else if (strcmp(tmp[0], "btdumpfake") == 0) {
5141 if (rtw_BT_efuse_map_read(padapter, 0, EFUSE_BT_MAX_MAP_LEN, pEfuseHal->fakeBTEfuseModifiedMap) == _SUCCESS) {
5142 DBG_88E("%s: BT read all map success\n", __func__);
5144 DBG_88E("%s: BT read all map Fail!\n", __func__);
5147 } else if (strcmp(tmp[0], "wldumpfake") == 0) {
5148 if (rtw_efuse_map_read(padapter, 0, EFUSE_BT_MAX_MAP_LEN, pEfuseHal->fakeEfuseModifiedMap) == _SUCCESS) {
5149 DBG_88E("%s: BT read all map success\n", __func__);
5151 DBG_88E("%s: BT read all map Fail\n", __func__);
5154 } else if (strcmp(tmp[0], "btfk2map") == 0) {
5155 memcpy(pEfuseHal->BTEfuseModifiedMap, pEfuseHal->fakeBTEfuseModifiedMap, EFUSE_BT_MAX_MAP_LEN);
5157 EFUSE_GetEfuseDefinition(padapter, EFUSE_BT, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (void *)&max_available_size, false);
5158 if (max_available_size < 1) {
5163 if (rtw_BT_efuse_map_write(padapter, 0x00, EFUSE_BT_MAX_MAP_LEN, pEfuseHal->fakeBTEfuseModifiedMap) == _FAIL) {
5164 DBG_88E("%s: rtw_BT_efuse_map_write error!\n", __func__);
5168 } else if (strcmp(tmp[0], "wlfk2map") == 0) {
5169 EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (void *)&max_available_size, false);
5170 if (max_available_size < 1) {
5175 if (rtw_efuse_map_write(padapter, 0x00, EFUSE_MAX_MAP_LEN, pEfuseHal->fakeEfuseModifiedMap) == _FAIL) {
5176 DBG_88E("%s: rtw_efuse_map_write error!\n", __func__);
5180 } else if (strcmp(tmp[0], "wlwfake") == 0) {
5181 if (!tmp[1] || !tmp[2]) {
5186 addr = simple_strtoul(tmp[1], &ptmp, 16);
5189 cnts = strlen(tmp[2]);
5200 DBG_88E("%s: addr = 0x%X\n", __func__, addr);
5201 DBG_88E("%s: cnts =%d\n", __func__, cnts);
5202 DBG_88E("%s: map tmp data =%s\n", __func__, tmp[2]);
5204 for (jj = 0, kk = 0; jj < cnts; jj++, kk += 2)
5205 pEfuseHal->fakeEfuseModifiedMap[addr + jj] = key_2char2num(tmp[2][kk], tmp[2][kk + 1]);
5211 kfree(ShadowMapWiFi);
5214 rtw_pm_set_ips(padapter, ips_mode);
5215 rtw_pm_set_lps(padapter, lps_mode);
5221 * Input Format: %s,%d,%d
5222 * %s is width, could be
5224 * "w" for WORD (2 bytes)
5225 * "dw" for DWORD (4 bytes)
5226 * 1st %d is address(offset)
5227 * 2st %d is data to write
5229 static int rtw_mp_write_reg(struct net_device *dev,
5230 struct iw_request_info *info,
5231 struct iw_point *wrqu, char *extra)
5233 char *pch, *pnext, *ptmp;
5238 struct adapter *padapter = rtw_netdev_priv(dev);
5241 pnext = strpbrk(pch, ",.-");
5248 pnext = strpbrk(pch, ",.-");
5252 addr = simple_strtoul(pch, &ptmp, 16);
5257 if ((pch - extra) >= wrqu->length)
5259 data = simple_strtoul(pch, &ptmp, 16);
5262 width = width_str[0];
5270 rtw_write8(padapter, addr, data);
5274 if (data > 0xFFFF) {
5278 rtw_write16(padapter, addr, data);
5282 rtw_write32(padapter, addr, data);
5293 * Input Format: %s,%d
5294 * %s is width, could be
5296 * "w" for WORD (2 bytes)
5297 * "dw" for DWORD (4 bytes)
5298 * %d is address(offset)
5301 * %d for data readed
5303 static int rtw_mp_read_reg(struct net_device *dev,
5304 struct iw_request_info *info,
5305 struct iw_point *wrqu, char *extra)
5307 struct adapter *padapter = rtw_netdev_priv(dev);
5308 char *input = kmalloc(wrqu->length, GFP_KERNEL);
5309 char *pch, *pnext, *ptmp;
5312 char data[20], tmp[20];
5314 u32 ret, i = 0, j = 0, strtout = 0;
5318 if (copy_from_user(input, wrqu->pointer, wrqu->length)) {
5322 memset(data, 0, 20);
5324 memset(extra, 0, wrqu->length);
5327 pnext = strpbrk(pch, ",.-");
5336 if ((pch - input) >= wrqu->length) {
5341 addr = simple_strtoul(pch, &ptmp, 16);
5346 width = width_str[0];
5350 sprintf(extra, "%d\n", rtw_read8(padapter, addr));
5351 wrqu->length = strlen(extra);
5355 sprintf(data, "%04x\n", rtw_read16(padapter, addr));
5356 for (i = 0; i <= strlen(data); i++) {
5361 if (data[i] != '\0')
5366 DBG_88E("pch =%s", pch);
5368 while (*pch != '\0') {
5369 pnext = strpbrk(pch, " ");
5374 if (*pnext != '\0') {
5375 strtout = simple_strtoul(pnext, &ptmp, 16);
5376 sprintf(extra + strlen(extra), " %d", strtout);
5386 sprintf(data, "%08x", rtw_read32(padapter, addr));
5387 /* add read data format blank */
5388 for (i = 0; i <= strlen(data); i++) {
5393 if (data[i] != '\0')
5399 DBG_88E("pch =%s", pch);
5401 while (*pch != '\0') {
5402 pnext = strpbrk(pch, " ");
5406 if (*pnext != '\0') {
5407 strtout = simple_strtoul(pnext, &ptmp, 16);
5408 sprintf(extra + strlen(extra), " %d", strtout);
5414 wrqu->length = strlen(extra);
5426 * Input Format: %d,%x,%x
5427 * %d is RF path, should be smaller than RF_PATH_MAX
5428 * 1st %x is address(offset)
5429 * 2st %x is data to write
5431 static int rtw_mp_write_rf(struct net_device *dev,
5432 struct iw_request_info *info,
5433 struct iw_point *wrqu, char *extra)
5435 u32 path, addr, data;
5437 struct adapter *padapter = rtw_netdev_priv(dev);
5439 ret = sscanf(extra, "%d,%x,%x", &path, &addr, &data);
5443 if (path >= RF_PATH_MAX)
5450 memset(extra, 0, wrqu->length);
5452 write_rfreg(padapter, path, addr, data);
5454 sprintf(extra, "write_rf completed\n");
5455 wrqu->length = strlen(extra);
5461 * Input Format: %d,%x
5462 * %d is RF path, should be smaller than RF_PATH_MAX
5463 * %x is address(offset)
5466 * %d for data readed
5468 static int rtw_mp_read_rf(struct net_device *dev,
5469 struct iw_request_info *info,
5470 struct iw_point *wrqu, char *extra)
5472 char *input = kmalloc(wrqu->length, GFP_KERNEL);
5473 char *pch, *pnext, *ptmp;
5474 char data[20], tmp[20];
5476 u32 ret, i = 0, j = 0, strtou = 0;
5477 struct adapter *padapter = rtw_netdev_priv(dev);
5481 if (copy_from_user(input, wrqu->pointer, wrqu->length)) {
5485 ret = sscanf(input, "%d,%x", &path, &addr);
5490 if (path >= RF_PATH_MAX)
5495 memset(extra, 0, wrqu->length);
5497 sprintf(data, "%08x", read_rfreg(padapter, path, addr));
5498 /* add read data format blank */
5499 for (i = 0; i <= strlen(data); i++) {
5508 DBG_88E("pch =%s", pch);
5510 while (*pch != '\0') {
5511 pnext = strpbrk(pch, " ");
5513 if (*pnext != '\0') {
5514 strtou = simple_strtoul(pnext, &ptmp, 16);
5515 sprintf(extra + strlen(extra), " %d", strtou);
5521 wrqu->length = strlen(extra);
5525 static int rtw_mp_start(struct net_device *dev,
5526 struct iw_request_info *info,
5527 struct iw_point *wrqu, char *extra)
5529 struct adapter *padapter = rtw_netdev_priv(dev);
5531 if (padapter->registrypriv.mp_mode == 0) {
5532 padapter->registrypriv.mp_mode = 1;
5534 rtw_pm_set_ips(padapter, IPS_NONE);
5535 LeaveAllPowerSaveMode(padapter);
5537 MPT_InitializeAdapter(padapter, 1);
5539 if (padapter->registrypriv.mp_mode == 0)
5541 if (padapter->mppriv.mode == MP_OFF) {
5542 if (mp_start_test(padapter) == _FAIL)
5544 padapter->mppriv.mode = MP_ON;
5549 static int rtw_mp_stop(struct net_device *dev,
5550 struct iw_request_info *info,
5551 struct iw_point *wrqu, char *extra)
5553 struct adapter *padapter = rtw_netdev_priv(dev);
5555 if (padapter->registrypriv.mp_mode == 1) {
5556 MPT_DeInitAdapter(padapter);
5557 padapter->registrypriv.mp_mode = 0;
5560 if (padapter->mppriv.mode != MP_OFF) {
5561 mp_stop_test(padapter);
5562 padapter->mppriv.mode = MP_OFF;
5568 extern int wifirate2_ratetbl_inx(unsigned char rate);
5570 static int rtw_mp_rate(struct net_device *dev,
5571 struct iw_request_info *info,
5572 struct iw_point *wrqu, char *extra)
5574 u32 rate = MPT_RATE_1M;
5575 char *input = kmalloc(wrqu->length, GFP_KERNEL);
5576 struct adapter *padapter = rtw_netdev_priv(dev);
5580 if (copy_from_user(input, wrqu->pointer, wrqu->length)) {
5584 rate = rtw_atoi(input);
5585 sprintf(extra, "Set data rate to %d", rate);
5588 rate = wifirate2_ratetbl_inx((u8)rate);
5590 rate = (rate - 0x80 + MPT_RATE_MCS0);
5592 if (rate >= MPT_RATE_LAST)
5595 padapter->mppriv.rateidx = rate;
5596 Hal_SetDataRate(padapter);
5598 wrqu->length = strlen(extra) + 1;
5602 static int rtw_mp_channel(struct net_device *dev,
5603 struct iw_request_info *info,
5604 struct iw_point *wrqu, char *extra)
5606 struct adapter *padapter = rtw_netdev_priv(dev);
5607 char *input = kmalloc(wrqu->length, GFP_KERNEL);
5612 if (copy_from_user(input, wrqu->pointer, wrqu->length)) {
5616 channel = rtw_atoi(input);
5617 sprintf(extra, "Change channel %d to channel %d", padapter->mppriv.channel, channel);
5619 padapter->mppriv.channel = channel;
5620 Hal_SetChannel(padapter);
5622 wrqu->length = strlen(extra) + 1;
5627 static int rtw_mp_bandwidth(struct net_device *dev,
5628 struct iw_request_info *info,
5629 struct iw_point *wrqu, char *extra)
5631 u32 bandwidth = 0, sg = 0;
5632 struct adapter *padapter = rtw_netdev_priv(dev);
5634 sscanf(extra, "40M =%d, shortGI =%d", &bandwidth, &sg);
5636 if (bandwidth != HT_CHANNEL_WIDTH_40)
5637 bandwidth = HT_CHANNEL_WIDTH_20;
5639 padapter->mppriv.bandwidth = (u8)bandwidth;
5640 padapter->mppriv.preamble = sg;
5642 SetBandwidth(padapter);
5647 static int rtw_mp_txpower(struct net_device *dev,
5648 struct iw_request_info *info,
5649 struct iw_point *wrqu, char *extra)
5651 u32 idx_a = 0, idx_b = 0;
5652 char *input = kmalloc(wrqu->length, GFP_KERNEL);
5653 struct adapter *padapter = rtw_netdev_priv(dev);
5657 if (copy_from_user(input, wrqu->pointer, wrqu->length)) {
5661 sscanf(input, "patha =%d, pathb =%d", &idx_a, &idx_b);
5663 sprintf(extra, "Set power level path_A:%d path_B:%d", idx_a, idx_b);
5664 padapter->mppriv.txpoweridx = (u8)idx_a;
5665 padapter->mppriv.txpoweridx_b = (u8)idx_b;
5666 padapter->mppriv.bSetTxPower = 1;
5667 Hal_SetAntennaPathPower(padapter);
5669 wrqu->length = strlen(extra) + 1;
5674 static int rtw_mp_ant_tx(struct net_device *dev,
5675 struct iw_request_info *info,
5676 struct iw_point *wrqu, char *extra)
5679 char *input = kmalloc(wrqu->length, GFP_KERNEL);
5681 struct adapter *padapter = rtw_netdev_priv(dev);
5685 if (copy_from_user(input, wrqu->pointer, wrqu->length)) {
5690 sprintf(extra, "switch Tx antenna to %s", input);
5692 for (i = 0; i < strlen(input); i++) {
5695 antenna |= ANTENNA_A;
5698 antenna |= ANTENNA_B;
5702 padapter->mppriv.antenna_tx = antenna;
5704 Hal_SetAntenna(padapter);
5706 wrqu->length = strlen(extra) + 1;
5711 static int rtw_mp_ant_rx(struct net_device *dev,
5712 struct iw_request_info *info,
5713 struct iw_point *wrqu, char *extra)
5717 char *input = kmalloc(wrqu->length, GFP_KERNEL);
5718 struct adapter *padapter = rtw_netdev_priv(dev);
5722 if (copy_from_user(input, wrqu->pointer, wrqu->length)) {
5726 memset(extra, 0, wrqu->length);
5728 sprintf(extra, "switch Rx antenna to %s", input);
5730 for (i = 0; i < strlen(input); i++) {
5733 antenna |= ANTENNA_A;
5736 antenna |= ANTENNA_B;
5741 padapter->mppriv.antenna_rx = antenna;
5742 Hal_SetAntenna(padapter);
5743 wrqu->length = strlen(extra);
5748 static int rtw_mp_ctx(struct net_device *dev,
5749 struct iw_request_info *info,
5750 struct iw_point *wrqu, char *extra)
5752 u32 pkTx = 1, countPkTx = 1, cotuTx = 1, CarrSprTx = 1, scTx = 1, sgleTx = 1, stop = 1;
5755 struct mp_priv *pmp_priv;
5756 struct pkt_attrib *pattrib;
5758 struct adapter *padapter = rtw_netdev_priv(dev);
5760 pmp_priv = &padapter->mppriv;
5762 if (copy_from_user(extra, wrqu->pointer, wrqu->length))
5765 DBG_88E("%s: in =%s\n", __func__, extra);
5767 countPkTx = strncmp(extra, "count =", 5); /* strncmp true is 0 */
5768 cotuTx = strncmp(extra, "background", 20);
5769 CarrSprTx = strncmp(extra, "background, cs", 20);
5770 scTx = strncmp(extra, "background, sc", 20);
5771 sgleTx = strncmp(extra, "background, stone", 20);
5772 pkTx = strncmp(extra, "background, pkt", 20);
5773 stop = strncmp(extra, "stop", 4);
5774 sscanf(extra, "count =%d, pkt", &count);
5776 memset(extra, '\0', sizeof(*extra));
5779 bStartTest = 0; /* To set Stop */
5780 pmp_priv->tx.stop = 1;
5781 sprintf(extra, "Stop continuous Tx");
5784 if (pmp_priv->mode != MP_ON) {
5785 if (pmp_priv->tx.stop != 1) {
5786 DBG_88E("%s: MP_MODE != ON %d\n", __func__, pmp_priv->mode);
5792 if (pkTx == 0 || countPkTx == 0)
5793 pmp_priv->mode = MP_PACKET_TX;
5795 pmp_priv->mode = MP_SINGLE_TONE_TX;
5797 pmp_priv->mode = MP_CONTINUOUS_TX;
5799 pmp_priv->mode = MP_CARRIER_SUPPRISSION_TX;
5801 pmp_priv->mode = MP_SINGLE_CARRIER_TX;
5803 switch (pmp_priv->mode) {
5805 if (bStartTest == 0) {
5806 pmp_priv->tx.stop = 1;
5807 pmp_priv->mode = MP_ON;
5808 sprintf(extra, "Stop continuous Tx");
5809 } else if (pmp_priv->tx.stop == 1) {
5810 sprintf(extra, "Start continuous DA = ffffffffffff len = 1500 count =%u,\n", count);
5811 pmp_priv->tx.stop = 0;
5812 pmp_priv->tx.count = count;
5813 pmp_priv->tx.payload = 2;
5814 pattrib = &pmp_priv->tx.attrib;
5815 pattrib->pktlen = 1500;
5816 memset(pattrib->dst, 0xFF, ETH_ALEN);
5817 SetPacketTx(padapter);
5821 wrqu->length = strlen(extra);
5823 case MP_SINGLE_TONE_TX:
5824 if (bStartTest != 0)
5825 sprintf(extra, "Start continuous DA = ffffffffffff len = 1500\n infinite = yes.");
5826 Hal_SetSingleToneTx(padapter, (u8)bStartTest);
5828 case MP_CONTINUOUS_TX:
5829 if (bStartTest != 0)
5830 sprintf(extra, "Start continuous DA = ffffffffffff len = 1500\n infinite = yes.");
5831 Hal_SetContinuousTx(padapter, (u8)bStartTest);
5833 case MP_CARRIER_SUPPRISSION_TX:
5834 if (bStartTest != 0) {
5835 if (pmp_priv->rateidx <= MPT_RATE_11M) {
5836 sprintf(extra, "Start continuous DA = ffffffffffff len = 1500\n infinite = yes.");
5837 Hal_SetCarrierSuppressionTx(padapter, (u8)bStartTest);
5839 sprintf(extra, "Specify carrier suppression but not CCK rate");
5843 case MP_SINGLE_CARRIER_TX:
5844 if (bStartTest != 0)
5845 sprintf(extra, "Start continuous DA = ffffffffffff len = 1500\n infinite = yes.");
5846 Hal_SetSingleCarrierTx(padapter, (u8)bStartTest);
5849 sprintf(extra, "Error! Continuous-Tx is not on-going.");
5853 if (bStartTest == 1 && pmp_priv->mode != MP_ON) {
5854 struct mp_priv *pmp_priv = &padapter->mppriv;
5855 if (pmp_priv->tx.stop == 0) {
5856 pmp_priv->tx.stop = 1;
5859 pmp_priv->tx.stop = 0;
5860 pmp_priv->tx.count = 1;
5861 SetPacketTx(padapter);
5863 pmp_priv->mode = MP_ON;
5866 wrqu->length = strlen(extra);
5870 static int rtw_mp_arx(struct net_device *dev,
5871 struct iw_request_info *info,
5872 struct iw_point *wrqu, char *extra)
5874 u8 bStartRx = 0, bStopRx = 0, bQueryPhy;
5875 u32 cckok = 0, cckcrc = 0, ofdmok = 0, ofdmcrc = 0, htok = 0, htcrc = 0, OFDM_FA = 0, CCK_FA = 0;
5876 char *input = kmalloc(wrqu->length, GFP_KERNEL);
5877 struct adapter *padapter = rtw_netdev_priv(dev);
5882 if (copy_from_user(input, wrqu->pointer, wrqu->length)) {
5886 DBG_88E("%s: %s\n", __func__, input);
5888 bStartRx = (strncmp(input, "start", 5) == 0) ? 1 : 0; /* strncmp true is 0 */
5889 bStopRx = (strncmp(input, "stop", 5) == 0) ? 1 : 0; /* strncmp true is 0 */
5890 bQueryPhy = (strncmp(input, "phy", 3) == 0) ? 1 : 0; /* strncmp true is 0 */
5893 sprintf(extra, "start");
5894 SetPacketRx(padapter, bStartRx);
5895 } else if (bStopRx) {
5896 SetPacketRx(padapter, 0);
5897 sprintf(extra, "Received packet OK:%d CRC error:%d", padapter->mppriv.rx_pktcount, padapter->mppriv.rx_crcerrpktcount);
5898 } else if (bQueryPhy) {
5908 (RegA5B<<8) | RegA5C
5910 cckok = read_bbreg(padapter, 0xf88, 0xffffffff);
5911 cckcrc = read_bbreg(padapter, 0xf84, 0xffffffff);
5912 ofdmok = read_bbreg(padapter, 0xf94, 0x0000FFFF);
5913 ofdmcrc = read_bbreg(padapter, 0xf94, 0xFFFF0000);
5914 htok = read_bbreg(padapter, 0xf90, 0x0000FFFF);
5915 htcrc = read_bbreg(padapter, 0xf90, 0xFFFF0000);
5917 OFDM_FA = read_bbreg(padapter, 0xcf0, 0x0000FFFF);
5918 OFDM_FA = read_bbreg(padapter, 0xcf2, 0xFFFF0000);
5919 OFDM_FA = read_bbreg(padapter, 0xda0, 0xFFFF0000);
5920 OFDM_FA = read_bbreg(padapter, 0xda4, 0x0000FFFF);
5921 OFDM_FA = read_bbreg(padapter, 0xda4, 0xFFFF0000);
5922 OFDM_FA = read_bbreg(padapter, 0xda8, 0x0000FFFF);
5923 CCK_FA = (rtw_read8(padapter, 0xa5b) << 8) | (rtw_read8(padapter, 0xa5c));
5925 sprintf(extra, "Phy Received packet OK:%d CRC error:%d FA Counter: %d", cckok + ofdmok + htok, cckcrc + ofdmcrc + htcrc, OFDM_FA + CCK_FA);
5927 wrqu->length = strlen(extra) + 1;
5932 static int rtw_mp_trx_query(struct net_device *dev,
5933 struct iw_request_info *info,
5934 struct iw_point *wrqu, char *extra)
5936 u32 txok, txfail, rxok, rxfail;
5937 struct adapter *padapter = rtw_netdev_priv(dev);
5939 txok = padapter->mppriv.tx.sended;
5941 rxok = padapter->mppriv.rx_pktcount;
5942 rxfail = padapter->mppriv.rx_crcerrpktcount;
5944 memset(extra, '\0', 128);
5946 sprintf(extra, "Tx OK:%d, Tx Fail:%d, Rx OK:%d, CRC error:%d ", txok, txfail, rxok, rxfail);
5948 wrqu->length = strlen(extra) + 1;
5953 static int rtw_mp_pwrtrk(struct net_device *dev,
5954 struct iw_request_info *info,
5955 struct iw_point *wrqu, char *extra)
5960 struct adapter *padapter = rtw_netdev_priv(dev);
5961 char *input = kmalloc(wrqu->length, GFP_KERNEL);
5965 if (copy_from_user(input, wrqu->pointer, wrqu->length)) {
5969 memset(extra, 0, wrqu->length);
5972 if (wrqu->length > 1) {/* not empty string */
5973 if (strncmp(input, "stop", 4) == 0) {
5975 sprintf(extra, "mp tx power tracking stop");
5976 } else if (sscanf(input, "ther =%d", &thermal)) {
5977 ret = Hal_SetThermalMeter(padapter, (u8)thermal);
5980 sprintf(extra, "mp tx power tracking start, target value =%d ok ", thermal);
5988 ret = Hal_SetPowerTracking(padapter, enable);
5992 wrqu->length = strlen(extra);
5996 static int rtw_mp_psd(struct net_device *dev,
5997 struct iw_request_info *info,
5998 struct iw_point *wrqu, char *extra)
6000 struct adapter *padapter = rtw_netdev_priv(dev);
6001 char *input = kmalloc(wrqu->length, GFP_KERNEL);
6005 if (copy_from_user(input, wrqu->pointer, wrqu->length)) {
6010 strcpy(extra, input);
6012 wrqu->length = mp_query_psd(padapter, extra);
6017 static int rtw_mp_thermal(struct net_device *dev,
6018 struct iw_request_info *info,
6019 struct iw_point *wrqu, char *extra)
6023 u16 addr = EEPROM_THERMAL_METER_88E;
6026 u16 max_available_size = 0;
6027 struct adapter *padapter = rtw_netdev_priv(dev);
6029 if (copy_from_user(extra, wrqu->pointer, wrqu->length))
6032 bwrite = strncmp(extra, "write", 6); /* strncmp true is 0 */
6034 Hal_GetThermalMeter(padapter, &val);
6037 EFUSE_GetEfuseDefinition(padapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (void *)&max_available_size, false);
6038 if (2 > max_available_size) {
6039 DBG_88E("no available efuse!\n");
6042 if (rtw_efuse_map_write(padapter, addr, cnt, &val) == _FAIL) {
6043 DBG_88E("rtw_efuse_map_write error\n");
6046 sprintf(extra, " efuse write ok :%d", val);
6049 sprintf(extra, "%d", val);
6051 wrqu->length = strlen(extra);
6056 static int rtw_mp_reset_stats(struct net_device *dev,
6057 struct iw_request_info *info,
6058 struct iw_point *wrqu, char *extra)
6060 struct mp_priv *pmp_priv;
6061 struct adapter *padapter = rtw_netdev_priv(dev);
6063 pmp_priv = &padapter->mppriv;
6065 pmp_priv->tx.sended = 0;
6066 pmp_priv->tx_pktcount = 0;
6067 pmp_priv->rx_pktcount = 0;
6068 pmp_priv->rx_crcerrpktcount = 0;
6070 /* reset phy counter */
6071 write_bbreg(padapter, 0xf14, BIT(16), 0x1);
6073 write_bbreg(padapter, 0xf14, BIT(16), 0x0);
6078 static int rtw_mp_dump(struct net_device *dev,
6079 struct iw_request_info *info,
6080 struct iw_point *wrqu, char *extra)
6083 u8 rf_type, path_nums = 0;
6085 struct adapter *padapter = rtw_netdev_priv(dev);
6087 if (strncmp(extra, "all", 4) == 0) {
6088 DBG_88E("\n ======= MAC REG =======\n");
6089 for (i = 0x0; i < 0x300; i += 4) {
6091 DBG_88E("0x%02x", i);
6092 DBG_88E(" 0x%08x ", rtw_read32(padapter, i));
6096 for (i = 0x400; i < 0x1000; i += 4) {
6098 DBG_88E("0x%02x", i);
6099 DBG_88E(" 0x%08x ", rtw_read32(padapter, i));
6105 rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
6107 DBG_88E("\n ======= RF REG =======\n");
6108 if ((RF_1T2R == rf_type) || (RF_1T1R == rf_type))
6113 for (path = 0; path < path_nums; path++) {
6114 for (i = 0; i < 0x34; i++) {
6115 value = rtw_hal_read_rfreg(padapter, path, i, 0xffffffff);
6117 DBG_88E("0x%02x ", i);
6118 DBG_88E(" 0x%08x ", value);
6127 static int rtw_mp_phypara(struct net_device *dev,
6128 struct iw_request_info *info,
6129 struct iw_point *wrqu, char *extra)
6131 char *input = kmalloc(wrqu->length, GFP_KERNEL);
6136 if (copy_from_user(input, wrqu->pointer, wrqu->length)) {
6141 DBG_88E("%s:iwpriv in =%s\n", __func__, input);
6143 sscanf(input, "xcap =%d", &valxcap);
6149 static int rtw_mp_SetRFPath(struct net_device *dev,
6150 struct iw_request_info *info,
6151 union iwreq_data *wrqu, char *extra)
6153 struct adapter *padapter = rtw_netdev_priv(dev);
6154 char *input = kmalloc(wrqu->data.length, GFP_KERNEL);
6155 u8 bMain = 1, bTurnoff = 1;
6159 if (copy_from_user(input, wrqu->data.pointer, wrqu->data.length))
6161 DBG_88E("%s:iwpriv in =%s\n", __func__, input);
6163 bMain = strncmp(input, "1", 2); /* strncmp true is 0 */
6164 bTurnoff = strncmp(input, "0", 3); /* strncmp true is 0 */
6167 MP_PHY_SetRFPathSwitch(padapter, true);
6168 DBG_88E("%s:PHY_SetRFPathSwitch = true\n", __func__);
6169 } else if (bTurnoff == 0) {
6170 MP_PHY_SetRFPathSwitch(padapter, false);
6171 DBG_88E("%s:PHY_SetRFPathSwitch = false\n", __func__);
6177 static int rtw_mp_QueryDrv(struct net_device *dev,
6178 struct iw_request_info *info,
6179 union iwreq_data *wrqu, char *extra)
6181 struct adapter *padapter = rtw_netdev_priv(dev);
6182 char *input = kmalloc(wrqu->data.length, GFP_KERNEL);
6184 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
6189 if (copy_from_user(input, wrqu->data.pointer, wrqu->data.length))
6191 DBG_88E("%s:iwpriv in =%s\n", __func__, input);
6193 qAutoLoad = strncmp(input, "autoload", 8); /* strncmp true is 0 */
6195 if (qAutoLoad == 0) {
6196 DBG_88E("%s:qAutoLoad\n", __func__);
6198 if (pEEPROM->bautoload_fail_flag)
6199 sprintf(extra, "fail");
6201 sprintf(extra, "ok");
6203 wrqu->data.length = strlen(extra) + 1;
6208 static int rtw_mp_set(struct net_device *dev,
6209 struct iw_request_info *info,
6210 union iwreq_data *wdata, char *extra)
6212 struct iw_point *wrqu = (struct iw_point *)wdata;
6213 u32 subcmd = wrqu->flags;
6214 struct adapter *padapter = rtw_netdev_priv(dev);
6226 DBG_88E("set case mp_start\n");
6227 rtw_mp_start(dev, info, wrqu, extra);
6230 DBG_88E("set case mp_stop\n");
6231 rtw_mp_stop(dev, info, wrqu, extra);
6234 DBG_88E("set case mp_bandwidth\n");
6235 rtw_mp_bandwidth(dev, info, wrqu, extra);
6237 case MP_RESET_STATS:
6238 DBG_88E("set case MP_RESET_STATS\n");
6239 rtw_mp_reset_stats(dev, info, wrqu, extra);
6241 case MP_SetRFPathSwh:
6242 DBG_88E("set MP_SetRFPathSwitch\n");
6243 rtw_mp_SetRFPath(dev, info, wdata, extra);
6246 DBG_88E("set CTA_TEST\n");
6247 rtw_cta_test_start(dev, info, wdata, extra);
6254 static int rtw_mp_get(struct net_device *dev,
6255 struct iw_request_info *info,
6256 union iwreq_data *wdata, char *extra)
6258 struct iw_point *wrqu = (struct iw_point *)wdata;
6259 u32 subcmd = wrqu->flags;
6260 struct adapter *padapter = rtw_netdev_priv(dev);
6271 rtw_mp_write_reg(dev, info, wrqu, extra);
6274 rtw_mp_write_rf(dev, info, wrqu, extra);
6277 DBG_88E("mp_get MP_PHYPARA\n");
6278 rtw_mp_phypara(dev, info, wrqu, extra);
6281 DBG_88E("set case mp_channel\n");
6282 rtw_mp_channel(dev, info, wrqu, extra);
6285 DBG_88E("mp_get READ_REG\n");
6286 rtw_mp_read_reg(dev, info, wrqu, extra);
6289 DBG_88E("mp_get READ_RF\n");
6290 rtw_mp_read_rf(dev, info, wrqu, extra);
6293 DBG_88E("set case mp_rate\n");
6294 rtw_mp_rate(dev, info, wrqu, extra);
6297 DBG_88E("set case MP_TXPOWER\n");
6298 rtw_mp_txpower(dev, info, wrqu, extra);
6301 DBG_88E("set case MP_ANT_TX\n");
6302 rtw_mp_ant_tx(dev, info, wrqu, extra);
6305 DBG_88E("set case MP_ANT_RX\n");
6306 rtw_mp_ant_rx(dev, info, wrqu, extra);
6309 rtw_mp_trx_query(dev, info, wrqu, extra);
6312 DBG_88E("set case MP_CTX\n");
6313 rtw_mp_ctx(dev, info, wrqu, extra);
6316 DBG_88E("set case MP_ARX\n");
6317 rtw_mp_arx(dev, info, wrqu, extra);
6320 DBG_88E("efuse get EFUSE_GET\n");
6321 rtw_mp_efuse_get(dev, info, wdata, extra);
6324 DBG_88E("set case MP_DUMP\n");
6325 rtw_mp_dump(dev, info, wrqu, extra);
6328 DBG_88E("set case MP_PSD\n");
6329 rtw_mp_psd(dev, info, wrqu, extra);
6332 DBG_88E("set case MP_THER\n");
6333 rtw_mp_thermal(dev, info, wrqu, extra);
6335 case MP_QueryDrvStats:
6336 DBG_88E("mp_get MP_QueryDrvStats\n");
6337 rtw_mp_QueryDrv(dev, info, wdata, extra);
6340 DBG_88E("set case MP_PWRTRK\n");
6341 rtw_mp_pwrtrk(dev, info, wrqu, extra);
6344 DBG_88E("set case efuse set\n");
6345 rtw_mp_efuse_set(dev, info, wdata, extra);
6349 msleep(10); /* delay 5ms for sending pkt before exit adb shell operation */
6353 static int rtw_tdls(struct net_device *dev,
6354 struct iw_request_info *info,
6355 union iwreq_data *wrqu, char *extra)
6360 static int rtw_tdls_get(struct net_device *dev,
6361 struct iw_request_info *info,
6362 union iwreq_data *wrqu, char *extra)
6367 static int rtw_test(
6368 struct net_device *dev,
6369 struct iw_request_info *info,
6370 union iwreq_data *wrqu, char *extra)
6377 DBG_88E("+%s\n", __func__);
6378 len = wrqu->data.length;
6380 pbuf = kzalloc(len, GFP_KERNEL);
6382 DBG_88E("%s: no memory!\n", __func__);
6386 if (copy_from_user(pbuf, wrqu->data.pointer, len)) {
6388 DBG_88E("%s: copy from user fail!\n", __func__);
6391 DBG_88E("%s: string =\"%s\"\n", __func__, pbuf);
6393 ptmp = (char *)pbuf;
6394 pch = strsep(&ptmp, delim);
6395 if (!pch || strlen(pch) == 0) {
6397 DBG_88E("%s: parameter error(level 1)!\n", __func__);
6404 static iw_handler rtw_handlers[] = {
6405 IW_HANDLER(SIOCGIWNAME, rtw_wx_get_name),
6406 IW_HANDLER(SIOCSIWNWID, dummy),
6407 IW_HANDLER(SIOCGIWNWID, dummy),
6408 IW_HANDLER(SIOCGIWFREQ, rtw_wx_get_freq),
6409 IW_HANDLER(SIOCSIWMODE, rtw_wx_set_mode),
6410 IW_HANDLER(SIOCGIWMODE, rtw_wx_get_mode),
6411 IW_HANDLER(SIOCSIWSENS, dummy),
6412 IW_HANDLER(SIOCGIWSENS, rtw_wx_get_sens),
6413 IW_HANDLER(SIOCGIWRANGE, rtw_wx_get_range),
6414 IW_HANDLER(SIOCSIWPRIV, rtw_wx_set_priv),
6415 IW_HANDLER(SIOCSIWSPY, dummy),
6416 IW_HANDLER(SIOCGIWSPY, dummy),
6417 IW_HANDLER(SIOCSIWAP, rtw_wx_set_wap),
6418 IW_HANDLER(SIOCGIWAP, rtw_wx_get_wap),
6419 IW_HANDLER(SIOCSIWMLME, rtw_wx_set_mlme),
6420 IW_HANDLER(SIOCGIWAPLIST, dummy),
6421 IW_HANDLER(SIOCSIWSCAN, rtw_wx_set_scan),
6422 IW_HANDLER(SIOCGIWSCAN, rtw_wx_get_scan),
6423 IW_HANDLER(SIOCSIWESSID, rtw_wx_set_essid),
6424 IW_HANDLER(SIOCGIWESSID, rtw_wx_get_essid),
6425 IW_HANDLER(SIOCSIWNICKN, dummy),
6426 IW_HANDLER(SIOCGIWNICKN, rtw_wx_get_nick),
6427 IW_HANDLER(SIOCSIWRATE, rtw_wx_set_rate),
6428 IW_HANDLER(SIOCGIWRATE, rtw_wx_get_rate),
6429 IW_HANDLER(SIOCSIWRTS, rtw_wx_set_rts),
6430 IW_HANDLER(SIOCGIWRTS, rtw_wx_get_rts),
6431 IW_HANDLER(SIOCSIWFRAG, rtw_wx_set_frag),
6432 IW_HANDLER(SIOCGIWFRAG, rtw_wx_get_frag),
6433 IW_HANDLER(SIOCSIWTXPOW, dummy),
6434 IW_HANDLER(SIOCGIWTXPOW, dummy),
6435 IW_HANDLER(SIOCSIWRETRY, dummy),
6436 IW_HANDLER(SIOCGIWRETRY, rtw_wx_get_retry),
6437 IW_HANDLER(SIOCSIWENCODE, rtw_wx_set_enc),
6438 IW_HANDLER(SIOCGIWENCODE, rtw_wx_get_enc),
6439 IW_HANDLER(SIOCSIWPOWER, dummy),
6440 IW_HANDLER(SIOCGIWPOWER, rtw_wx_get_power),
6441 IW_HANDLER(SIOCSIWGENIE, rtw_wx_set_gen_ie),
6442 IW_HANDLER(SIOCSIWAUTH, rtw_wx_set_auth),
6443 IW_HANDLER(SIOCSIWENCODEEXT, rtw_wx_set_enc_ext),
6444 IW_HANDLER(SIOCSIWPMKSA, rtw_wx_set_pmkid),
6447 static const struct iw_priv_args rtw_private_args[] = {
6449 SIOCIWFIRSTPRIV + 0x0,
6450 IW_PRIV_TYPE_CHAR | 0x7FF, 0, "write"
6453 SIOCIWFIRSTPRIV + 0x1,
6454 IW_PRIV_TYPE_CHAR | 0x7FF,
6455 IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "read"
6458 SIOCIWFIRSTPRIV + 0x2, 0, 0, "driver_ext"
6461 SIOCIWFIRSTPRIV + 0x3, 0, 0, "mp_ioctl"
6464 SIOCIWFIRSTPRIV + 0x4,
6465 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "apinfo"
6468 SIOCIWFIRSTPRIV + 0x5,
6469 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "setpid"
6472 SIOCIWFIRSTPRIV + 0x6,
6473 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wps_start"
6476 SIOCIWFIRSTPRIV + 0x7,
6477 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "get_sensitivity"
6480 SIOCIWFIRSTPRIV + 0x8,
6481 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wps_prob_req_ie"
6484 SIOCIWFIRSTPRIV + 0x9,
6485 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wps_assoc_req_ie"
6489 SIOCIWFIRSTPRIV + 0xA,
6490 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "channel_plan"
6494 SIOCIWFIRSTPRIV + 0xB,
6495 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "dbg"
6498 SIOCIWFIRSTPRIV + 0xC,
6499 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 3, 0, "rfw"
6502 SIOCIWFIRSTPRIV + 0xD,
6503 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "rfr"
6506 SIOCIWFIRSTPRIV + 0x10,
6507 IW_PRIV_TYPE_CHAR | P2P_PRIVATE_IOCTL_SET_LEN, 0, "p2p_set"
6510 SIOCIWFIRSTPRIV + 0x11,
6511 IW_PRIV_TYPE_CHAR | P2P_PRIVATE_IOCTL_SET_LEN, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | P2P_PRIVATE_IOCTL_SET_LEN, "p2p_get"
6514 SIOCIWFIRSTPRIV + 0x12,
6515 IW_PRIV_TYPE_CHAR | P2P_PRIVATE_IOCTL_SET_LEN, IW_PRIV_TYPE_CHAR | IFNAMSIZ, "p2p_get2"
6517 {SIOCIWFIRSTPRIV + 0x13, IW_PRIV_TYPE_CHAR | 128, 0, "NULL"},
6519 SIOCIWFIRSTPRIV + 0x14,
6520 IW_PRIV_TYPE_CHAR | 64, 0, "tdls"
6523 SIOCIWFIRSTPRIV + 0x15,
6524 IW_PRIV_TYPE_CHAR | P2P_PRIVATE_IOCTL_SET_LEN, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | P2P_PRIVATE_IOCTL_SET_LEN, "tdls_get"
6527 SIOCIWFIRSTPRIV + 0x16,
6528 IW_PRIV_TYPE_CHAR | 64, 0, "pm_set"
6531 {SIOCIWFIRSTPRIV + 0x18, IW_PRIV_TYPE_CHAR | IFNAMSIZ, 0, "rereg_nd_name"},
6533 {SIOCIWFIRSTPRIV + 0x1A, IW_PRIV_TYPE_CHAR | 1024, 0, "efuse_set"},
6534 {SIOCIWFIRSTPRIV + 0x1B, IW_PRIV_TYPE_CHAR | 128, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_get"},
6535 {SIOCIWFIRSTPRIV + 0x1D, IW_PRIV_TYPE_CHAR | 40, IW_PRIV_TYPE_CHAR | 0x7FF, "test"
6538 {SIOCIWFIRSTPRIV + 0x0E, IW_PRIV_TYPE_CHAR | 1024, 0, ""}, /* set */
6539 {SIOCIWFIRSTPRIV + 0x0F, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, ""},/* get */
6540 /* --- sub-ioctls definitions --- */
6542 {MP_START, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_start"}, /* set */
6543 {MP_PHYPARA, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_phypara"},/* get */
6544 {MP_STOP, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_stop"}, /* set */
6545 {MP_CHANNEL, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_channel"},/* get */
6546 {MP_BANDWIDTH, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_bandwidth"}, /* set */
6547 {MP_RATE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_rate"},/* get */
6548 {MP_RESET_STATS, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_reset_stats"},
6549 {MP_QUERY, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_query"}, /* get */
6550 {READ_REG, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "read_reg"},
6551 {MP_RATE, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_rate"},
6552 {READ_RF, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "read_rf"},
6553 {MP_PSD, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_psd"},
6554 {MP_DUMP, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_dump"},
6555 {MP_TXPOWER, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_txpower"},
6556 {MP_ANT_TX, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ant_tx"},
6557 {MP_ANT_RX, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ant_rx"},
6558 {WRITE_REG, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "write_reg"},
6559 {WRITE_RF, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "write_rf"},
6560 {MP_CTX, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ctx"},
6561 {MP_ARX, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_arx"},
6562 {MP_THER, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_ther"},
6563 {EFUSE_SET, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_set"},
6564 {EFUSE_GET, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_get"},
6565 {MP_PWRTRK, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_pwrtrk"},
6566 {MP_QueryDrvStats, IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "mp_drvquery"},
6567 {MP_IOCTL, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_ioctl"}, /* mp_ioctl */
6568 {MP_SetRFPathSwh, IW_PRIV_TYPE_CHAR | 1024, 0, "mp_setrfpath"},
6569 {CTA_TEST, IW_PRIV_TYPE_CHAR | 1024, 0, "cta_test"},
6572 static iw_handler rtw_private_handler[] = {
6573 rtw_wx_write32, /* 0x00 */
6574 rtw_wx_read32, /* 0x01 */
6575 rtw_drvext_hdl, /* 0x02 */
6576 rtw_mp_ioctl_hdl, /* 0x03 */
6578 /* for MM DTV platform */
6579 rtw_get_ap_info, /* 0x04 */
6581 rtw_set_pid, /* 0x05 */
6582 rtw_wps_start, /* 0x06 */
6584 rtw_wx_get_sensitivity, /* 0x07 */
6585 rtw_wx_set_mtk_wps_probe_ie, /* 0x08 */
6586 rtw_wx_set_mtk_wps_ie, /* 0x09 */
6588 /* Set Channel depend on the country code */
6589 rtw_wx_set_channel_plan, /* 0x0A */
6591 rtw_dbg_port, /* 0x0B */
6592 rtw_wx_write_rf, /* 0x0C */
6593 rtw_wx_read_rf, /* 0x0D */
6595 rtw_mp_set, /* 0x0E */
6596 rtw_mp_get, /* 0x0F */
6597 rtw_p2p_set, /* 0x10 */
6598 rtw_p2p_get, /* 0x11 */
6599 rtw_p2p_get2, /* 0x12 */
6602 rtw_tdls, /* 0x14 */
6603 rtw_tdls_get, /* 0x15 */
6605 rtw_pm_set, /* 0x16 */
6606 rtw_wx_priv_null, /* 0x17 */
6607 rtw_rereg_nd_name, /* 0x18 */
6608 rtw_wx_priv_null, /* 0x19 */
6610 rtw_mp_efuse_set, /* 0x1A */
6611 rtw_mp_efuse_get, /* 0x1B */
6612 NULL, /* 0x1C is reserved for hostapd */
6613 rtw_test, /* 0x1D */
6616 static struct iw_statistics *rtw_get_wireless_stats(struct net_device *dev)
6618 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
6619 struct iw_statistics *piwstats = &padapter->iwstats;
6623 if (!check_fwstate(&padapter->mlmepriv, _FW_LINKED)) {
6624 piwstats->qual.qual = 0;
6625 piwstats->qual.level = 0;
6626 piwstats->qual.noise = 0;
6628 tmp_noise = padapter->recvpriv.noise;
6630 piwstats->qual.level = padapter->signal_strength;
6631 tmp = 219 + 3 * padapter->signal_strength;
6632 tmp = min(100, tmp);
6634 piwstats->qual.qual = tmp;
6635 piwstats->qual.noise = tmp_noise;
6637 piwstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
6638 return &padapter->iwstats;
6641 struct iw_handler_def rtw_handlers_def = {
6642 .standard = rtw_handlers,
6643 .num_standard = sizeof(rtw_handlers) / sizeof(iw_handler),
6644 .private = rtw_private_handler,
6645 .private_args = (struct iw_priv_args *)rtw_private_args,
6646 .num_private = sizeof(rtw_private_handler) / sizeof(iw_handler),
6647 .num_private_args = sizeof(rtw_private_args) / sizeof(struct iw_priv_args),
6648 .get_wireless_stats = rtw_get_wireless_stats,