1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2007 - 2012 Realtek Corporation. */
4 #include "../include/osdep_service.h"
5 #include "../include/drv_types.h"
6 #include "../include/wlan_bssdef.h"
7 #include "../include/wifi.h"
8 #include "../include/rtw_mlme.h"
9 #include "../include/rtw_mlme_ext.h"
10 #include "../include/rtw_ioctl.h"
11 #include "../include/rtw_ioctl_set.h"
12 #include "../include/usb_ops.h"
13 #include "../include/rtl8188e_hal.h"
14 #include "../include/rtw_led.h"
16 #include "../include/rtw_iol.h"
18 #define RTL_IOCTL_WPA_SUPPLICANT (SIOCIWFIRSTPRIV + 30)
20 #define SCAN_ITEM_SIZE 768
21 #define MAX_CUSTOM_LEN 64
25 #define WEXT_CSCAN_AMOUNT 9
26 #define WEXT_CSCAN_BUF_LEN 360
27 #define WEXT_CSCAN_HEADER "CSCAN S\x01\x00\x00S\x00"
28 #define WEXT_CSCAN_HEADER_SIZE 12
29 #define WEXT_CSCAN_SSID_SECTION 'S'
30 #define WEXT_CSCAN_CHANNEL_SECTION 'C'
31 #define WEXT_CSCAN_NPROBE_SECTION 'N'
32 #define WEXT_CSCAN_ACTV_DWELL_SECTION 'A'
33 #define WEXT_CSCAN_PASV_DWELL_SECTION 'P'
34 #define WEXT_CSCAN_HOME_DWELL_SECTION 'H'
35 #define WEXT_CSCAN_TYPE_SECTION 'T'
37 static u32 rtw_rates[] = {1000000, 2000000, 5500000, 11000000,
38 6000000, 9000000, 12000000, 18000000, 24000000, 36000000,
41 void indicate_wx_scan_complete_event(struct adapter *padapter)
43 union iwreq_data wrqu;
45 memset(&wrqu, 0, sizeof(union iwreq_data));
46 wireless_send_event(padapter->pnetdev, SIOCGIWSCAN, &wrqu, NULL);
49 void rtw_indicate_wx_assoc_event(struct adapter *padapter)
51 union iwreq_data wrqu;
52 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
54 memset(&wrqu, 0, sizeof(union iwreq_data));
56 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
58 memcpy(wrqu.ap_addr.sa_data, pmlmepriv->cur_network.network.MacAddress, ETH_ALEN);
60 wireless_send_event(padapter->pnetdev, SIOCGIWAP, &wrqu, NULL);
63 void rtw_indicate_wx_disassoc_event(struct adapter *padapter)
65 union iwreq_data wrqu;
67 memset(&wrqu, 0, sizeof(union iwreq_data));
69 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
70 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
72 wireless_send_event(padapter->pnetdev, SIOCGIWAP, &wrqu, NULL);
75 static char *translate_scan(struct adapter *padapter,
76 struct iw_request_info *info,
77 struct wlan_network *pnetwork,
78 char *start, char *stop)
80 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
87 u16 max_rate = 0, rate, ht_cap = false;
89 u8 bw_40MHz = 0, short_GI = 0;
92 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
94 if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
95 u32 blnGotP2PIE = false;
97 /* User is doing the P2P device discovery */
98 /* The prefix of SSID should be "DIRECT-" and the IE should contains the P2P IE. */
99 /* If not, the driver should ignore this AP and go to the next AP. */
101 /* Verifying the SSID */
102 if (!memcmp(pnetwork->network.Ssid.Ssid, pwdinfo->p2p_wildcard_ssid, P2P_WILDCARD_SSID_LEN)) {
105 if (pnetwork->network.Reserved[0] == 2) {/* Probe Request */
106 /* Verifying the P2P IE */
107 if (rtw_get_p2p_ie(pnetwork->network.IEs, pnetwork->network.IELength, NULL, &p2pielen))
109 } else {/* Beacon or Probe Respones */
110 /* Verifying the P2P IE */
111 if (rtw_get_p2p_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &p2pielen))
122 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
124 memcpy(iwe.u.ap_addr.sa_data, pnetwork->network.MacAddress, ETH_ALEN);
125 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_ADDR_LEN);
128 iwe.cmd = SIOCGIWESSID;
129 iwe.u.data.flags = 1;
130 iwe.u.data.length = min_t(u16, pnetwork->network.Ssid.SsidLength, 32);
131 start = iwe_stream_add_point(info, start, stop, &iwe, pnetwork->network.Ssid.Ssid);
133 /* parsing HT_CAP_IE */
134 p = rtw_get_ie(&pnetwork->network.IEs[12], _HT_CAPABILITY_IE_, &ht_ielen, pnetwork->network.IELength - 12);
136 if (p && ht_ielen > 0) {
137 struct ieee80211_ht_cap *pht_capie;
140 pht_capie = (struct ieee80211_ht_cap *)(p + 2);
141 memcpy(&mcs_rate, pht_capie->mcs.rx_mask, 2);
142 bw_40MHz = (le16_to_cpu(pht_capie->cap_info) &
143 IEEE80211_HT_CAP_SUP_WIDTH_20_40) ? 1 : 0;
144 short_GI = (le16_to_cpu(pht_capie->cap_info) &
145 (IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40)) ? 1 : 0;
148 /* Add the protocol name */
149 iwe.cmd = SIOCGIWNAME;
150 if ((rtw_is_cckratesonly_included((u8 *)&pnetwork->network.SupportedRates))) {
152 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bn");
154 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11b");
155 } else if ((rtw_is_cckrates_included((u8 *)&pnetwork->network.SupportedRates))) {
157 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bgn");
159 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bg");
162 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11gn");
164 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11g");
167 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_CHAR_LEN);
170 iwe.cmd = SIOCGIWMODE;
171 memcpy(&le_tmp, rtw_get_capability_from_ie(pnetwork->network.IEs), 2);
173 cap = le16_to_cpu(le_tmp);
175 if (cap & (WLAN_CAPABILITY_IBSS | WLAN_CAPABILITY_BSS)) {
176 if (cap & WLAN_CAPABILITY_BSS)
177 iwe.u.mode = IW_MODE_MASTER;
179 iwe.u.mode = IW_MODE_ADHOC;
181 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_UINT_LEN);
184 if (pnetwork->network.Configuration.DSConfig < 1)
185 pnetwork->network.Configuration.DSConfig = 1;
187 /* Add frequency/channel */
188 iwe.cmd = SIOCGIWFREQ;
189 iwe.u.freq.m = rtw_ch2freq(pnetwork->network.Configuration.DSConfig) * 100000;
191 iwe.u.freq.i = pnetwork->network.Configuration.DSConfig;
192 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_FREQ_LEN);
194 /* Add encryption capability */
195 iwe.cmd = SIOCGIWENCODE;
196 if (cap & WLAN_CAPABILITY_PRIVACY)
197 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
199 iwe.u.data.flags = IW_ENCODE_DISABLED;
200 iwe.u.data.length = 0;
201 start = iwe_stream_add_point(info, start, stop, &iwe, pnetwork->network.Ssid.Ssid);
203 /*Add basic and extended rates */
205 custom = kzalloc(MAX_CUSTOM_LEN, GFP_ATOMIC);
209 p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), " Rates (Mb/s): ");
210 while (pnetwork->network.SupportedRates[i] != 0) {
211 rate = pnetwork->network.SupportedRates[i] & 0x7F;
214 p += snprintf(p, MAX_CUSTOM_LEN - (p - custom),
215 "%d%s ", rate >> 1, (rate & 1) ? ".5" : "");
220 if (mcs_rate & 0x8000)/* MCS15 */
221 max_rate = (bw_40MHz) ? ((short_GI) ? 300 : 270) : ((short_GI) ? 144 : 130);
222 else if (mcs_rate & 0x0080)/* MCS7 */
224 else/* default MCS7 */
225 max_rate = (bw_40MHz) ? ((short_GI) ? 150 : 135) : ((short_GI) ? 72 : 65);
227 max_rate = max_rate * 2;/* Mbps/2; */
230 iwe.cmd = SIOCGIWRATE;
231 iwe.u.bitrate.fixed = 0;
232 iwe.u.bitrate.disabled = 0;
233 iwe.u.bitrate.value = max_rate * 500000;
234 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_PARAM_LEN);
236 /* parsing WPA/WPA2 IE */
240 u16 wpa_len = 0, rsn_len = 0;
243 buf = kzalloc(MAX_WPA_IE_LEN, GFP_ATOMIC);
246 wpa_ie = kzalloc(255, GFP_ATOMIC);
251 rsn_ie = kzalloc(255, GFP_ATOMIC);
257 rtw_get_sec_ie(pnetwork->network.IEs, pnetwork->network.IELength, rsn_ie, &rsn_len, wpa_ie, &wpa_len);
261 memset(buf, 0, MAX_WPA_IE_LEN);
262 p += sprintf(p, "wpa_ie =");
263 for (i = 0; i < wpa_len; i++)
264 p += sprintf(p, "%02x", wpa_ie[i]);
266 memset(&iwe, 0, sizeof(iwe));
267 iwe.cmd = IWEVCUSTOM;
268 iwe.u.data.length = strlen(buf);
269 start = iwe_stream_add_point(info, start, stop, &iwe, buf);
271 memset(&iwe, 0, sizeof(iwe));
273 iwe.u.data.length = wpa_len;
274 start = iwe_stream_add_point(info, start, stop, &iwe, wpa_ie);
278 memset(buf, 0, MAX_WPA_IE_LEN);
279 p += sprintf(p, "rsn_ie =");
280 for (i = 0; i < rsn_len; i++)
281 p += sprintf(p, "%02x", rsn_ie[i]);
282 memset(&iwe, 0, sizeof(iwe));
283 iwe.cmd = IWEVCUSTOM;
284 iwe.u.data.length = strlen(buf);
285 start = iwe_stream_add_point(info, start, stop, &iwe, buf);
287 memset(&iwe, 0, sizeof(iwe));
289 iwe.u.data.length = rsn_len;
290 start = iwe_stream_add_point(info, start, stop, &iwe, rsn_ie);
297 {/* parsing WPS IE */
298 uint cnt = 0, total_ielen;
299 u8 *wpsie_ptr = NULL;
302 u8 *ie_ptr = pnetwork->network.IEs + _FIXED_IE_LENGTH_;
303 total_ielen = pnetwork->network.IELength - _FIXED_IE_LENGTH_;
305 while (cnt < total_ielen) {
306 if (rtw_is_wps_ie(&ie_ptr[cnt], &wps_ielen) && (wps_ielen > 2)) {
307 wpsie_ptr = &ie_ptr[cnt];
309 iwe.u.data.length = (u16)wps_ielen;
310 start = iwe_stream_add_point(info, start, stop, &iwe, wpsie_ptr);
312 cnt += ie_ptr[cnt + 1] + 2; /* goto next */
316 /* Add quality statistics */
318 iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_INVALID;
320 if (check_fwstate(pmlmepriv, _FW_LINKED) &&
321 is_same_network(&pmlmepriv->cur_network.network, &pnetwork->network)) {
322 ss = padapter->recvpriv.signal_strength;
323 sq = padapter->recvpriv.signal_qual;
325 ss = pnetwork->network.PhyInfo.SignalStrength;
326 sq = pnetwork->network.PhyInfo.SignalQuality;
329 iwe.u.qual.level = (u8)ss;
330 iwe.u.qual.qual = (u8)sq; /* signal quality */
331 iwe.u.qual.noise = 0; /* noise level */
332 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_QUAL_LEN);
338 static int wpa_set_auth_algs(struct net_device *dev, u32 value)
340 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
343 if ((value & AUTH_ALG_SHARED_KEY) && (value & AUTH_ALG_OPEN_SYSTEM)) {
344 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
345 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeAutoSwitch;
346 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto;
347 } else if (value & AUTH_ALG_SHARED_KEY) {
348 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
350 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeShared;
351 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Shared;
352 } else if (value & AUTH_ALG_OPEN_SYSTEM) {
353 if (padapter->securitypriv.ndisauthtype < Ndis802_11AuthModeWPAPSK) {
354 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
355 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
357 } else if (!(value & AUTH_ALG_LEAP)) {
363 static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len)
366 u32 wep_key_idx, wep_key_len, wep_total_len;
367 struct ndis_802_11_wep *pwep = NULL;
368 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
369 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
370 struct security_priv *psecuritypriv = &padapter->securitypriv;
371 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
373 param->u.crypt.err = 0;
374 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
376 if (param_len < (u32)((u8 *)param->u.crypt.key - (u8 *)param) + param->u.crypt.key_len) {
381 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
382 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
383 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
384 if (param->u.crypt.idx >= WEP_KEYS) {
393 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
394 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
395 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
396 padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_;
398 wep_key_idx = param->u.crypt.idx;
399 wep_key_len = param->u.crypt.key_len;
401 if (wep_key_idx > WEP_KEYS)
404 if (wep_key_len > 0) {
405 wep_key_len = wep_key_len <= 5 ? 5 : 13;
406 wep_total_len = wep_key_len + sizeof(*pwep);
407 pwep = kzalloc(wep_total_len, GFP_KERNEL);
411 pwep->KeyLength = wep_key_len;
412 pwep->Length = wep_total_len;
413 if (wep_key_len == 13) {
414 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_;
415 padapter->securitypriv.dot118021XGrpPrivacy = _WEP104_;
421 pwep->KeyIndex = wep_key_idx;
422 pwep->KeyIndex |= 0x80000000;
423 memcpy(pwep->KeyMaterial, param->u.crypt.key, pwep->KeyLength);
424 if (param->u.crypt.set_tx) {
425 if (rtw_set_802_11_add_wep(padapter, pwep) == (u8)_FAIL)
428 if (wep_key_idx >= WEP_KEYS) {
432 memcpy(&psecuritypriv->dot11DefKey[wep_key_idx].skey[0], pwep->KeyMaterial, pwep->KeyLength);
433 psecuritypriv->dot11DefKeylen[wep_key_idx] = pwep->KeyLength;
434 rtw_set_key(padapter, psecuritypriv, wep_key_idx, 0);
439 if (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) { /* 802_1x */
440 struct sta_info *psta, *pbcmc_sta;
441 struct sta_priv *pstapriv = &padapter->stapriv;
443 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_MP_STATE)) { /* sta mode */
444 psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
448 if (strcmp(param->u.crypt.alg, "none") != 0)
449 psta->ieee8021x_blocked = false;
451 if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) ||
452 (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled))
453 psta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
455 if (param->u.crypt.set_tx == 1) { /* pairwise key */
456 memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
458 if (strcmp(param->u.crypt.alg, "TKIP") == 0) { /* set mic key */
459 memcpy(psta->dot11tkiptxmickey.skey, ¶m->u.crypt.key[16], 8);
460 memcpy(psta->dot11tkiprxmickey.skey, ¶m->u.crypt.key[24], 8);
461 padapter->securitypriv.busetkipkey = false;
464 rtw_setstakey_cmd(padapter, (unsigned char *)psta, true);
465 } else { /* group key */
466 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));
467 memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey, ¶m->u.crypt.key[16], 8);
468 memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey, ¶m->u.crypt.key[24], 8);
469 padapter->securitypriv.binstallGrpkey = true;
471 padapter->securitypriv.dot118021XGrpKeyid = param->u.crypt.idx;
473 rtw_set_key(padapter, &padapter->securitypriv, param->u.crypt.idx, 1);
474 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_PROVISIONING_ING))
475 rtw_p2p_set_state(pwdinfo, P2P_STATE_PROVISIONING_DONE);
478 pbcmc_sta = rtw_get_bcmc_stainfo(padapter);
482 /* Jeff: don't disable ieee8021x_blocked while clearing key */
483 if (strcmp(param->u.crypt.alg, "none") != 0)
484 pbcmc_sta->ieee8021x_blocked = false;
486 if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) ||
487 (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled))
488 pbcmc_sta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
500 static int rtw_set_wpa_ie(struct adapter *padapter, char *pie, unsigned short ielen)
503 int group_cipher = 0, pairwise_cipher = 0;
505 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
507 if (ielen > MAX_WPA_IE_LEN || !pie) {
508 _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
516 buf = kmemdup(pie, ielen, GFP_KERNEL);
522 if (ielen < RSN_HEADER_LEN) {
527 if (rtw_parse_wpa_ie(buf, ielen, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
528 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
529 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPAPSK;
530 memcpy(padapter->securitypriv.supplicant_ie, &buf[0], ielen);
533 if (rtw_parse_wpa2_ie(buf, ielen, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
534 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
535 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPA2PSK;
536 memcpy(padapter->securitypriv.supplicant_ie, &buf[0], ielen);
539 switch (group_cipher) {
540 case WPA_CIPHER_NONE:
541 padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
542 padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
544 case WPA_CIPHER_WEP40:
545 padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_;
546 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
548 case WPA_CIPHER_TKIP:
549 padapter->securitypriv.dot118021XGrpPrivacy = _TKIP_;
550 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
552 case WPA_CIPHER_CCMP:
553 padapter->securitypriv.dot118021XGrpPrivacy = _AES_;
554 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
556 case WPA_CIPHER_WEP104:
557 padapter->securitypriv.dot118021XGrpPrivacy = _WEP104_;
558 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
562 switch (pairwise_cipher) {
563 case WPA_CIPHER_NONE:
564 padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
565 padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
567 case WPA_CIPHER_WEP40:
568 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
569 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
571 case WPA_CIPHER_TKIP:
572 padapter->securitypriv.dot11PrivacyAlgrthm = _TKIP_;
573 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled;
575 case WPA_CIPHER_CCMP:
576 padapter->securitypriv.dot11PrivacyAlgrthm = _AES_;
577 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled;
579 case WPA_CIPHER_WEP104:
580 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_;
581 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
585 _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS);
588 u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
590 while (cnt < ielen) {
592 if ((eid == _VENDOR_SPECIFIC_IE_) && (!memcmp(&buf[cnt + 2], wps_oui, 4))) {
593 padapter->securitypriv.wps_ie_len = ((buf[cnt + 1] + 2) < (MAX_WPA_IE_LEN << 2)) ? (buf[cnt + 1] + 2) : (MAX_WPA_IE_LEN << 2);
595 memcpy(padapter->securitypriv.wps_ie, &buf[cnt], padapter->securitypriv.wps_ie_len);
597 set_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS);
598 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_OK))
599 rtw_p2p_set_state(pwdinfo, P2P_STATE_PROVISIONING_ING);
600 cnt += buf[cnt + 1] + 2;
603 cnt += buf[cnt + 1] + 2; /* goto next */
614 typedef unsigned char NDIS_802_11_RATES_EX[NDIS_802_11_LENGTH_RATES_EX];
616 static int rtw_wx_get_name(struct net_device *dev,
617 struct iw_request_info *info,
618 union iwreq_data *wrqu, char *extra)
620 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
624 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
625 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
626 NDIS_802_11_RATES_EX *prates = NULL;
628 if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE)) {
629 /* parsing HT_CAP_IE */
630 p = rtw_get_ie(&pcur_bss->IEs[12], _HT_CAPABILITY_IE_, &ht_ielen, pcur_bss->IELength - 12);
631 if (p && ht_ielen > 0)
634 prates = &pcur_bss->SupportedRates;
636 if (rtw_is_cckratesonly_included((u8 *)prates)) {
638 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11bn");
640 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
641 } else if (rtw_is_cckrates_included((u8 *)prates)) {
643 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11bgn");
645 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11bg");
648 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11gn");
650 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11g");
653 snprintf(wrqu->name, IFNAMSIZ, "unassociated");
661 static int rtw_wx_get_freq(struct net_device *dev,
662 struct iw_request_info *info,
663 union iwreq_data *wrqu, char *extra)
665 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
666 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
667 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
669 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
670 /* wrqu->freq.m = ieee80211_wlan_frequencies[pcur_bss->Configuration.DSConfig-1] * 100000; */
671 wrqu->freq.m = rtw_ch2freq(pcur_bss->Configuration.DSConfig) * 100000;
673 wrqu->freq.i = pcur_bss->Configuration.DSConfig;
675 wrqu->freq.m = rtw_ch2freq(padapter->mlmeextpriv.cur_channel) * 100000;
677 wrqu->freq.i = padapter->mlmeextpriv.cur_channel;
683 static int rtw_wx_set_mode(struct net_device *dev, struct iw_request_info *a,
684 union iwreq_data *wrqu, char *b)
686 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
687 enum ndis_802_11_network_infra networkType;
692 if (_FAIL == rtw_pwr_wakeup(padapter)) {
697 if (!padapter->hw_init_completed) {
702 switch (wrqu->mode) {
704 networkType = Ndis802_11AutoUnknown;
707 networkType = Ndis802_11IBSS;
710 networkType = Ndis802_11APMode;
713 networkType = Ndis802_11Infrastructure;
719 if (!rtw_set_802_11_infrastructure_mode(padapter, networkType)) {
723 rtw_setopmode_cmd(padapter, networkType);
729 static int rtw_wx_get_mode(struct net_device *dev, struct iw_request_info *a,
730 union iwreq_data *wrqu, char *b)
732 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
733 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
735 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
736 wrqu->mode = IW_MODE_INFRA;
737 else if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) ||
738 (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)))
739 wrqu->mode = IW_MODE_ADHOC;
740 else if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
741 wrqu->mode = IW_MODE_MASTER;
743 wrqu->mode = IW_MODE_AUTO;
750 static int rtw_wx_set_pmkid(struct net_device *dev,
751 struct iw_request_info *a,
752 union iwreq_data *wrqu, char *extra)
754 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
755 u8 j, blInserted = false;
757 struct security_priv *psecuritypriv = &padapter->securitypriv;
758 struct iw_pmksa *pPMK = (struct iw_pmksa *)extra;
759 u8 strZeroMacAddress[ETH_ALEN] = {0x00};
760 u8 strIssueBssid[ETH_ALEN] = {0x00};
762 memcpy(strIssueBssid, pPMK->bssid.sa_data, ETH_ALEN);
763 if (pPMK->cmd == IW_PMKSA_ADD) {
764 if (!memcmp(strIssueBssid, strZeroMacAddress, ETH_ALEN))
770 /* overwrite PMKID */
771 for (j = 0; j < NUM_PMKID_CACHE; j++) {
772 if (!memcmp(psecuritypriv->PMKIDList[j].Bssid, strIssueBssid, ETH_ALEN)) {
773 /* BSSID is matched, the same AP => rewrite with new PMKID. */
774 memcpy(psecuritypriv->PMKIDList[j].PMKID, pPMK->pmkid, IW_PMKID_LEN);
775 psecuritypriv->PMKIDList[j].bUsed = true;
776 psecuritypriv->PMKIDIndex = j + 1;
783 /* Find a new entry */
784 memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].Bssid, strIssueBssid, ETH_ALEN);
785 memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].PMKID, pPMK->pmkid, IW_PMKID_LEN);
787 psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].bUsed = true;
788 psecuritypriv->PMKIDIndex++;
789 if (psecuritypriv->PMKIDIndex == 16)
790 psecuritypriv->PMKIDIndex = 0;
792 } else if (pPMK->cmd == IW_PMKSA_REMOVE) {
794 for (j = 0; j < NUM_PMKID_CACHE; j++) {
795 if (!memcmp(psecuritypriv->PMKIDList[j].Bssid, strIssueBssid, ETH_ALEN)) {
796 /* BSSID is matched, the same AP => Remove this PMKID information and reset it. */
797 memset(psecuritypriv->PMKIDList[j].Bssid, 0x00, ETH_ALEN);
798 psecuritypriv->PMKIDList[j].bUsed = false;
802 } else if (pPMK->cmd == IW_PMKSA_FLUSH) {
803 memset(&psecuritypriv->PMKIDList[0], 0x00, sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE);
804 psecuritypriv->PMKIDIndex = 0;
810 static int rtw_wx_get_sens(struct net_device *dev,
811 struct iw_request_info *info,
812 union iwreq_data *wrqu, char *extra)
814 wrqu->sens.value = 0;
815 wrqu->sens.fixed = 0; /* no auto select */
816 wrqu->sens.disabled = 1;
820 static int rtw_wx_get_range(struct net_device *dev,
821 struct iw_request_info *info,
822 union iwreq_data *wrqu, char *extra)
824 struct iw_range *range = (struct iw_range *)extra;
825 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
826 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
831 wrqu->data.length = sizeof(*range);
832 memset(range, 0, sizeof(*range));
834 /* Let's try to keep this struct in the same order as in
835 * linux/include/wireless.h
838 /* TODO: See what values we can set, and remove the ones we can't
839 * set, or fill them with some default data.
842 /* ~5 Mb/s real (802.11b) */
843 range->throughput = 5 * 1000 * 1000;
845 /* signal level threshold range */
847 /* percent values between 0 and 100. */
848 range->max_qual.qual = 100;
849 range->max_qual.level = 100;
850 range->max_qual.noise = 100;
851 range->max_qual.updated = 7; /* Updated all three */
853 range->avg_qual.qual = 92; /* > 8% missed beacons is 'bad' */
854 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
855 range->avg_qual.level = 178; /* -78 dBm */
856 range->avg_qual.noise = 0;
857 range->avg_qual.updated = 7; /* Updated all three */
859 range->num_bitrates = RATE_COUNT;
861 for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++)
862 range->bitrate[i] = rtw_rates[i];
864 range->min_frag = MIN_FRAG_THRESHOLD;
865 range->max_frag = MAX_FRAG_THRESHOLD;
869 range->we_version_compiled = WIRELESS_EXT;
870 range->we_version_source = 16;
872 for (i = 0, val = 0; i < MAX_CHANNEL_NUM; i++) {
873 /* Include only legal frequencies for some countries */
874 if (pmlmeext->channel_set[i].ChannelNum != 0) {
875 range->freq[val].i = pmlmeext->channel_set[i].ChannelNum;
876 range->freq[val].m = rtw_ch2freq(pmlmeext->channel_set[i].ChannelNum) * 100000;
877 range->freq[val].e = 1;
881 if (val == IW_MAX_FREQUENCIES)
885 range->num_channels = val;
886 range->num_frequency = val;
888 /* The following code will proivde the security capability to network manager. */
889 /* If the driver doesn't provide this capability to network manager, */
890 /* the WPA/WPA2 routers can't be chosen in the network manager. */
893 #define IW_SCAN_CAPA_NONE 0x00
894 #define IW_SCAN_CAPA_ESSID 0x01
895 #define IW_SCAN_CAPA_BSSID 0x02
896 #define IW_SCAN_CAPA_CHANNEL 0x04
897 #define IW_SCAN_CAPA_MODE 0x08
898 #define IW_SCAN_CAPA_RATE 0x10
899 #define IW_SCAN_CAPA_TYPE 0x20
900 #define IW_SCAN_CAPA_TIME 0x40
903 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
904 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
906 range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE |
907 IW_SCAN_CAPA_BSSID | IW_SCAN_CAPA_CHANNEL |
908 IW_SCAN_CAPA_MODE | IW_SCAN_CAPA_RATE;
915 /* s1. rtw_set_802_11_infrastructure_mode() */
916 /* s2. rtw_set_802_11_authentication_mode() */
917 /* s3. set_802_11_encryption_mode() */
918 /* s4. rtw_set_802_11_bssid() */
919 static int rtw_wx_set_wap(struct net_device *dev,
920 struct iw_request_info *info,
921 union iwreq_data *awrq,
925 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
926 struct sockaddr *temp = (struct sockaddr *)awrq;
927 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
928 struct list_head *phead;
929 u8 *dst_bssid, *src_bssid;
930 struct __queue *queue = &pmlmepriv->scanned_queue;
931 struct wlan_network *pnetwork = NULL;
932 enum ndis_802_11_auth_mode authmode;
936 if (_FAIL == rtw_pwr_wakeup(padapter)) {
941 if (!padapter->bup) {
946 if (temp->sa_family != ARPHRD_ETHER) {
951 authmode = padapter->securitypriv.ndisauthtype;
952 spin_lock_bh(&queue->lock);
953 phead = get_list_head(queue);
954 pmlmepriv->pscanned = phead->next;
956 while (phead != pmlmepriv->pscanned) {
958 pnetwork = container_of(pmlmepriv->pscanned, struct wlan_network, list);
960 pmlmepriv->pscanned = pmlmepriv->pscanned->next;
962 dst_bssid = pnetwork->network.MacAddress;
964 src_bssid = temp->sa_data;
966 if ((!memcmp(dst_bssid, src_bssid, ETH_ALEN))) {
967 if (!rtw_set_802_11_infrastructure_mode(padapter, pnetwork->network.InfrastructureMode)) {
969 spin_unlock_bh(&queue->lock);
976 spin_unlock_bh(&queue->lock);
978 rtw_set_802_11_authentication_mode(padapter, authmode);
979 /* set_802_11_encryption_mode(padapter, padapter->securitypriv.ndisencryptstatus); */
980 if (!rtw_set_802_11_bssid(padapter, temp->sa_data)) {
992 static int rtw_wx_get_wap(struct net_device *dev,
993 struct iw_request_info *info,
994 union iwreq_data *wrqu, char *extra)
996 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
997 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
998 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
1000 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1002 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
1004 if (check_fwstate(pmlmepriv, _FW_LINKED) ||
1005 check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) ||
1006 check_fwstate(pmlmepriv, WIFI_AP_STATE))
1007 memcpy(wrqu->ap_addr.sa_data, pcur_bss->MacAddress, ETH_ALEN);
1009 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
1016 static int rtw_wx_set_mlme(struct net_device *dev,
1017 struct iw_request_info *info,
1018 union iwreq_data *wrqu, char *extra)
1021 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1022 struct iw_mlme *mlme = (struct iw_mlme *)extra;
1027 switch (mlme->cmd) {
1028 case IW_MLME_DEAUTH:
1029 if (!rtw_set_802_11_disassociate(padapter))
1032 case IW_MLME_DISASSOC:
1033 if (!rtw_set_802_11_disassociate(padapter))
1042 static int rtw_wx_set_scan(struct net_device *dev, struct iw_request_info *a,
1043 union iwreq_data *wrqu, char *extra)
1047 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1048 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1049 struct ndis_802_11_ssid ssid[RTW_SSID_SCAN_AMOUNT];
1050 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
1052 if (_FAIL == rtw_pwr_wakeup(padapter)) {
1057 if (padapter->bDriverStopped) {
1062 if (!padapter->bup) {
1067 if (!padapter->hw_init_completed) {
1072 /* When Busy Traffic, driver do not site survey. So driver return success. */
1073 /* wpa_supplicant will not issue SIOCSIWSCAN cmd again after scan timeout. */
1074 /* modify by thomas 2011-02-22. */
1075 if (pmlmepriv->LinkDetectInfo.bBusyTraffic) {
1076 indicate_wx_scan_complete_event(padapter);
1080 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING)) {
1081 indicate_wx_scan_complete_event(padapter);
1085 /* For the DMP WiFi Display project, the driver won't to scan because */
1086 /* the pmlmepriv->scan_interval is always equal to 3. */
1087 /* So, the wpa_supplicant won't find out the WPS SoftAP. */
1089 if (pwdinfo->p2p_state != P2P_STATE_NONE) {
1090 rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
1091 rtw_p2p_set_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH);
1092 rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_FULL);
1093 rtw_free_network_queue(padapter, true);
1096 memset(ssid, 0, sizeof(struct ndis_802_11_ssid) * RTW_SSID_SCAN_AMOUNT);
1098 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
1099 struct iw_scan_req *req = (struct iw_scan_req *)extra;
1101 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1102 int len = min((int)req->essid_len, IW_ESSID_MAX_SIZE);
1104 memcpy(ssid[0].Ssid, req->essid, len);
1105 ssid[0].SsidLength = len;
1107 spin_lock_bh(&pmlmepriv->lock);
1109 _status = rtw_sitesurvey_cmd(padapter, ssid, 1, NULL, 0);
1111 spin_unlock_bh(&pmlmepriv->lock);
1114 if (wrqu->data.length >= WEXT_CSCAN_HEADER_SIZE &&
1115 !memcmp(extra, WEXT_CSCAN_HEADER, WEXT_CSCAN_HEADER_SIZE)) {
1116 int len = wrqu->data.length - WEXT_CSCAN_HEADER_SIZE;
1117 char *pos = extra + WEXT_CSCAN_HEADER_SIZE;
1127 case WEXT_CSCAN_SSID_SECTION:
1132 sec_len = *(pos++); len -= 1;
1136 ssid[ssid_index].SsidLength = sec_len;
1137 memcpy(ssid[ssid_index].Ssid, pos, sec_len);
1143 case WEXT_CSCAN_TYPE_SECTION:
1144 case WEXT_CSCAN_CHANNEL_SECTION:
1148 case WEXT_CSCAN_PASV_DWELL_SECTION:
1149 case WEXT_CSCAN_HOME_DWELL_SECTION:
1150 case WEXT_CSCAN_ACTV_DWELL_SECTION:
1155 len = 0; /* stop parsing */
1159 /* it has still some scan parameter to parse, we only do this now... */
1160 _status = rtw_set_802_11_bssid_list_scan(padapter, ssid, RTW_SSID_SCAN_AMOUNT);
1162 _status = rtw_set_802_11_bssid_list_scan(padapter, NULL, 0);
1174 static int rtw_wx_get_scan(struct net_device *dev, struct iw_request_info *a,
1175 union iwreq_data *wrqu, char *extra)
1177 struct list_head *plist, *phead;
1178 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1179 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1180 struct __queue *queue = &pmlmepriv->scanned_queue;
1181 struct wlan_network *pnetwork = NULL;
1183 char *stop = ev + wrqu->data.length;
1186 u32 wait_for_surveydone;
1188 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
1190 if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
1191 /* P2P is enabled */
1192 wait_for_surveydone = 200;
1194 /* P2P is disabled */
1195 wait_for_surveydone = 100;
1198 wait_status = _FW_UNDER_SURVEY | _FW_UNDER_LINKING;
1200 while (check_fwstate(pmlmepriv, wait_status)) {
1203 if (cnt > wait_for_surveydone)
1207 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
1209 phead = get_list_head(queue);
1210 plist = phead->next;
1212 while (phead != plist) {
1213 if ((stop - ev) < SCAN_ITEM_SIZE) {
1218 pnetwork = container_of(plist, struct wlan_network, list);
1220 /* report network only if the current channel set contains the channel to which this network belongs */
1221 if (rtw_ch_set_search_ch(padapter->mlmeextpriv.channel_set, pnetwork->network.Configuration.DSConfig) >= 0)
1222 ev = translate_scan(padapter, a, pnetwork, ev, stop);
1224 plist = plist->next;
1227 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
1229 wrqu->data.length = ev - extra;
1230 wrqu->data.flags = 0;
1236 /* s1. rtw_set_802_11_infrastructure_mode() */
1237 /* s2. set_802_11_authenticaion_mode() */
1238 /* s3. set_802_11_encryption_mode() */
1239 /* s4. rtw_set_802_11_ssid() */
1240 static int rtw_wx_set_essid(struct net_device *dev,
1241 struct iw_request_info *a,
1242 union iwreq_data *wrqu, char *extra)
1244 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1245 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1246 struct __queue *queue = &pmlmepriv->scanned_queue;
1247 struct list_head *phead;
1248 struct wlan_network *pnetwork = NULL;
1249 enum ndis_802_11_auth_mode authmode;
1250 struct ndis_802_11_ssid ndis_ssid;
1251 u8 *dst_ssid, *src_ssid;
1255 if (_FAIL == rtw_pwr_wakeup(padapter)) {
1260 if (!padapter->bup) {
1265 if (wrqu->essid.length > IW_ESSID_MAX_SIZE) {
1270 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1275 authmode = padapter->securitypriv.ndisauthtype;
1276 if (wrqu->essid.flags && wrqu->essid.length) {
1277 len = (wrqu->essid.length < IW_ESSID_MAX_SIZE) ? wrqu->essid.length : IW_ESSID_MAX_SIZE;
1279 memset(&ndis_ssid, 0, sizeof(struct ndis_802_11_ssid));
1280 ndis_ssid.SsidLength = len;
1281 memcpy(ndis_ssid.Ssid, extra, len);
1282 src_ssid = ndis_ssid.Ssid;
1284 spin_lock_bh(&queue->lock);
1285 phead = get_list_head(queue);
1286 pmlmepriv->pscanned = phead->next;
1288 while (phead != pmlmepriv->pscanned) {
1289 pnetwork = container_of(pmlmepriv->pscanned, struct wlan_network, list);
1291 pmlmepriv->pscanned = pmlmepriv->pscanned->next;
1293 dst_ssid = pnetwork->network.Ssid.Ssid;
1295 if ((!memcmp(dst_ssid, src_ssid, ndis_ssid.SsidLength)) &&
1296 (pnetwork->network.Ssid.SsidLength == ndis_ssid.SsidLength)) {
1298 if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) {
1299 if (pnetwork->network.InfrastructureMode != pmlmepriv->cur_network.network.InfrastructureMode)
1303 if (!rtw_set_802_11_infrastructure_mode(padapter, pnetwork->network.InfrastructureMode)) {
1305 spin_unlock_bh(&queue->lock);
1312 spin_unlock_bh(&queue->lock);
1313 rtw_set_802_11_authentication_mode(padapter, authmode);
1314 if (!rtw_set_802_11_ssid(padapter, &ndis_ssid)) {
1324 static int rtw_wx_get_essid(struct net_device *dev,
1325 struct iw_request_info *a,
1326 union iwreq_data *wrqu, char *extra)
1329 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1330 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1331 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
1333 if ((check_fwstate(pmlmepriv, _FW_LINKED)) ||
1334 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE))) {
1335 len = pcur_bss->Ssid.SsidLength;
1336 memcpy(extra, pcur_bss->Ssid.Ssid, len);
1341 wrqu->essid.length = len;
1342 wrqu->essid.flags = 1;
1347 static int rtw_wx_set_rate(struct net_device *dev,
1348 struct iw_request_info *a,
1349 union iwreq_data *wrqu, char *extra)
1352 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1353 u8 datarates[NumRates];
1354 u32 target_rate = wrqu->bitrate.value;
1355 u32 fixed = wrqu->bitrate.fixed;
1357 u8 mpdatarate[NumRates] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0xff};
1359 if (target_rate == -1) {
1363 target_rate = target_rate / 100000;
1365 switch (target_rate) {
1409 for (i = 0; i < NumRates; i++) {
1410 if (ratevalue == mpdatarate[i]) {
1411 datarates[i] = mpdatarate[i];
1415 datarates[i] = 0xff;
1419 if (rtw_setdatarate_cmd(padapter, datarates) != _SUCCESS)
1425 static int rtw_wx_get_rate(struct net_device *dev,
1426 struct iw_request_info *info,
1427 union iwreq_data *wrqu, char *extra)
1431 max_rate = rtw_get_cur_max_rate((struct adapter *)rtw_netdev_priv(dev));
1436 wrqu->bitrate.fixed = 0; /* no auto select */
1437 wrqu->bitrate.value = max_rate * 100000;
1442 static int rtw_wx_set_rts(struct net_device *dev,
1443 struct iw_request_info *info,
1444 union iwreq_data *wrqu, char *extra)
1446 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1450 if (wrqu->rts.disabled) {
1451 padapter->registrypriv.rts_thresh = 2347;
1453 if (wrqu->rts.value < 0 ||
1454 wrqu->rts.value > 2347)
1457 padapter->registrypriv.rts_thresh = wrqu->rts.value;
1463 static int rtw_wx_get_rts(struct net_device *dev,
1464 struct iw_request_info *info,
1465 union iwreq_data *wrqu, char *extra)
1467 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1471 wrqu->rts.value = padapter->registrypriv.rts_thresh;
1472 wrqu->rts.fixed = 0; /* no auto select */
1473 /* wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); */
1480 static int rtw_wx_set_frag(struct net_device *dev,
1481 struct iw_request_info *info,
1482 union iwreq_data *wrqu, char *extra)
1484 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1488 if (wrqu->frag.disabled) {
1489 padapter->xmitpriv.frag_len = MAX_FRAG_THRESHOLD;
1491 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
1492 wrqu->frag.value > MAX_FRAG_THRESHOLD)
1495 padapter->xmitpriv.frag_len = wrqu->frag.value & ~0x1;
1501 static int rtw_wx_get_frag(struct net_device *dev,
1502 struct iw_request_info *info,
1503 union iwreq_data *wrqu, char *extra)
1505 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1509 wrqu->frag.value = padapter->xmitpriv.frag_len;
1510 wrqu->frag.fixed = 0; /* no auto select */
1517 static int rtw_wx_get_retry(struct net_device *dev,
1518 struct iw_request_info *info,
1519 union iwreq_data *wrqu, char *extra)
1521 wrqu->retry.value = 7;
1522 wrqu->retry.fixed = 0; /* no auto select */
1523 wrqu->retry.disabled = 1;
1528 static int rtw_wx_set_enc(struct net_device *dev,
1529 struct iw_request_info *info,
1530 union iwreq_data *wrqu, char *keybuf)
1533 u32 keyindex_provided;
1534 struct ndis_802_11_wep wep;
1535 enum ndis_802_11_auth_mode authmode;
1537 struct iw_point *erq = &wrqu->encoding;
1538 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1539 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
1541 memset(&wep, 0, sizeof(struct ndis_802_11_wep));
1543 key = erq->flags & IW_ENCODE_INDEX;
1547 if (erq->flags & IW_ENCODE_DISABLED) {
1548 padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
1549 padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
1550 padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
1551 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
1552 authmode = Ndis802_11AuthModeOpen;
1553 padapter->securitypriv.ndisauthtype = authmode;
1562 keyindex_provided = 1;
1564 keyindex_provided = 0;
1565 key = padapter->securitypriv.dot11PrivacyKeyIndex;
1568 /* set authentication mode */
1569 if (erq->flags & IW_ENCODE_OPEN) {
1570 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;/* Ndis802_11EncryptionDisabled; */
1571 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
1572 padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
1573 padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
1574 authmode = Ndis802_11AuthModeOpen;
1575 padapter->securitypriv.ndisauthtype = authmode;
1576 } else if (erq->flags & IW_ENCODE_RESTRICTED) {
1577 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;
1578 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Shared;
1579 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
1580 padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_;
1581 authmode = Ndis802_11AuthModeShared;
1582 padapter->securitypriv.ndisauthtype = authmode;
1584 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;/* Ndis802_11EncryptionDisabled; */
1585 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
1586 padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
1587 padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
1588 authmode = Ndis802_11AuthModeOpen;
1589 padapter->securitypriv.ndisauthtype = authmode;
1593 if (erq->length > 0) {
1594 wep.KeyLength = erq->length <= 5 ? 5 : 13;
1596 wep.Length = wep.KeyLength + FIELD_OFFSET(struct ndis_802_11_wep, KeyMaterial);
1600 if (keyindex_provided == 1) {
1601 /* set key_id only, no given KeyMaterial(erq->length == 0). */
1602 padapter->securitypriv.dot11PrivacyKeyIndex = key;
1604 switch (padapter->securitypriv.dot11DefKeylen[key]) {
1606 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_;
1609 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_;
1612 padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
1620 wep.KeyIndex |= 0x80000000;
1622 memcpy(wep.KeyMaterial, keybuf, wep.KeyLength);
1624 if (!rtw_set_802_11_add_wep(padapter, &wep)) {
1625 if (rf_on == pwrpriv->rf_pwrstate)
1637 static int rtw_wx_get_enc(struct net_device *dev,
1638 struct iw_request_info *info,
1639 union iwreq_data *wrqu, char *keybuf)
1642 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1643 struct iw_point *erq = &wrqu->encoding;
1644 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1648 if (check_fwstate(pmlmepriv, _FW_LINKED) != true) {
1649 if (!check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
1651 erq->flags |= IW_ENCODE_DISABLED;
1656 key = erq->flags & IW_ENCODE_INDEX;
1663 key = padapter->securitypriv.dot11PrivacyKeyIndex;
1666 erq->flags = key + 1;
1668 switch (padapter->securitypriv.ndisencryptstatus) {
1669 case Ndis802_11EncryptionNotSupported:
1670 case Ndis802_11EncryptionDisabled:
1672 erq->flags |= IW_ENCODE_DISABLED;
1674 case Ndis802_11Encryption1Enabled:
1675 erq->length = padapter->securitypriv.dot11DefKeylen[key];
1677 memcpy(keybuf, padapter->securitypriv.dot11DefKey[key].skey, padapter->securitypriv.dot11DefKeylen[key]);
1679 erq->flags |= IW_ENCODE_ENABLED;
1681 if (padapter->securitypriv.ndisauthtype == Ndis802_11AuthModeOpen)
1682 erq->flags |= IW_ENCODE_OPEN;
1683 else if (padapter->securitypriv.ndisauthtype == Ndis802_11AuthModeShared)
1684 erq->flags |= IW_ENCODE_RESTRICTED;
1687 erq->flags |= IW_ENCODE_DISABLED;
1690 case Ndis802_11Encryption2Enabled:
1691 case Ndis802_11Encryption3Enabled:
1693 erq->flags |= (IW_ENCODE_ENABLED | IW_ENCODE_OPEN | IW_ENCODE_NOKEY);
1697 erq->flags |= IW_ENCODE_DISABLED;
1705 static int rtw_wx_get_power(struct net_device *dev,
1706 struct iw_request_info *info,
1707 union iwreq_data *wrqu, char *extra)
1709 wrqu->power.value = 0;
1710 wrqu->power.fixed = 0; /* no auto select */
1711 wrqu->power.disabled = 1;
1716 static int rtw_wx_set_gen_ie(struct net_device *dev,
1717 struct iw_request_info *info,
1718 union iwreq_data *wrqu, char *extra)
1721 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1723 ret = rtw_set_wpa_ie(padapter, extra, wrqu->data.length);
1727 static int rtw_wx_set_auth(struct net_device *dev,
1728 struct iw_request_info *info,
1729 union iwreq_data *wrqu, char *extra)
1731 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1732 struct iw_param *param = (struct iw_param *)&wrqu->param;
1735 switch (param->flags & IW_AUTH_INDEX) {
1736 case IW_AUTH_WPA_VERSION:
1738 case IW_AUTH_CIPHER_PAIRWISE:
1741 case IW_AUTH_CIPHER_GROUP:
1744 case IW_AUTH_KEY_MGMT:
1746 * ??? does not use these parameters
1749 case IW_AUTH_TKIP_COUNTERMEASURES:
1751 /* wpa_supplicant is enabling the tkip countermeasure. */
1752 padapter->securitypriv.btkip_countermeasure = true;
1754 /* wpa_supplicant is disabling the tkip countermeasure. */
1755 padapter->securitypriv.btkip_countermeasure = false;
1758 case IW_AUTH_DROP_UNENCRYPTED:
1761 * wpa_supplicant calls set_wpa_enabled when the driver
1762 * is loaded and unloaded, regardless of if WPA is being
1763 * used. No other calls are made which can be used to
1764 * determine if encryption will be used or not prior to
1765 * association being expected. If encryption is not being
1766 * used, drop_unencrypted is set to false, else true -- we
1767 * can use this to determine if the CAP_PRIVACY_ON bit should
1771 if (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption1Enabled)
1772 break;/* it means init value, or using wep, ndisencryptstatus = Ndis802_11Encryption1Enabled, */
1773 /* then it needn't reset it; */
1776 padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled;
1777 padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_;
1778 padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_;
1779 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
1780 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
1784 case IW_AUTH_80211_AUTH_ALG:
1786 * It's the starting point of a link layer connection using wpa_supplicant
1788 if (check_fwstate(&padapter->mlmepriv, _FW_LINKED)) {
1789 LeaveAllPowerSaveMode(padapter);
1790 rtw_disassoc_cmd(padapter, 500, false);
1791 rtw_indicate_disconnect(padapter);
1792 rtw_free_assoc_resources(padapter, 1);
1794 ret = wpa_set_auth_algs(dev, (u32)param->value);
1796 case IW_AUTH_WPA_ENABLED:
1798 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1800 case IW_AUTH_PRIVACY_INVOKED:
1809 static int rtw_wx_set_enc_ext(struct net_device *dev,
1810 struct iw_request_info *info,
1811 union iwreq_data *wrqu, char *extra)
1815 struct ieee_param *param = NULL;
1816 struct iw_point *pencoding = &wrqu->encoding;
1817 struct iw_encode_ext *pext = (struct iw_encode_ext *)extra;
1820 param_len = sizeof(struct ieee_param) + pext->key_len;
1821 param = kzalloc(param_len, GFP_KERNEL);
1825 param->cmd = IEEE_CMD_SET_ENCRYPTION;
1826 memset(param->sta_addr, 0xff, ETH_ALEN);
1828 switch (pext->alg) {
1829 case IW_ENCODE_ALG_NONE:
1830 /* todo: remove key */
1834 case IW_ENCODE_ALG_WEP:
1837 case IW_ENCODE_ALG_TKIP:
1840 case IW_ENCODE_ALG_CCMP:
1847 strlcpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN);
1849 if (pext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
1850 param->u.crypt.set_tx = 1;
1852 /* cliW: WEP does not have group key
1853 * just not checking GROUP key setting
1855 if ((pext->alg != IW_ENCODE_ALG_WEP) &&
1856 (pext->ext_flags & IW_ENCODE_EXT_GROUP_KEY))
1857 param->u.crypt.set_tx = 0;
1859 param->u.crypt.idx = (pencoding->flags & 0x00FF) - 1;
1861 if (pext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
1862 memcpy(param->u.crypt.seq, pext->rx_seq, 8);
1864 if (pext->key_len) {
1865 param->u.crypt.key_len = pext->key_len;
1866 memcpy(param->u.crypt.key, pext + 1, pext->key_len);
1869 ret = wpa_set_encryption(dev, param, param_len);
1876 static int rtw_wx_get_nick(struct net_device *dev,
1877 struct iw_request_info *info,
1878 union iwreq_data *wrqu, char *extra)
1881 wrqu->data.length = 14;
1882 wrqu->data.flags = 1;
1883 memcpy(extra, "<WIFI@REALTEK>", 14);
1886 /* dump debug info here */
1890 static int rtw_wx_read_rf(struct net_device *dev,
1891 struct iw_request_info *info,
1892 union iwreq_data *wrqu, char *extra)
1894 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1895 u32 path, addr, data32;
1897 path = *(u32 *)extra;
1898 if (path != RF_PATH_A)
1901 addr = *((u32 *)extra + 1);
1902 data32 = rtl8188e_PHY_QueryRFReg(padapter, addr, 0xFFFFF);
1905 * Only when wireless private ioctl is at odd order,
1906 * "extra" would be copied to user space.
1908 sprintf(extra, "0x%05x", data32);
1913 static int rtw_wx_write_rf(struct net_device *dev,
1914 struct iw_request_info *info,
1915 union iwreq_data *wrqu, char *extra)
1917 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1918 u32 path, addr, data32;
1920 path = *(u32 *)extra;
1921 if (path != RF_PATH_A)
1924 addr = *((u32 *)extra + 1);
1925 data32 = *((u32 *)extra + 2);
1926 rtl8188e_PHY_SetRFReg(padapter, addr, 0xFFFFF, data32);
1931 static int rtw_wx_set_channel_plan(struct net_device *dev,
1932 struct iw_request_info *info,
1933 union iwreq_data *wrqu, char *extra)
1935 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1936 u8 channel_plan_req = (u8)(*((int *)wrqu));
1938 if (rtw_set_chplan_cmd(padapter, channel_plan_req) != _SUCCESS)
1944 static int rtw_get_ap_info(struct net_device *dev,
1945 struct iw_request_info *info,
1946 union iwreq_data *wrqu, char *extra)
1949 u32 cnt = 0, wpa_ielen;
1950 struct list_head *plist, *phead;
1951 unsigned char *pbuf;
1954 struct wlan_network *pnetwork = NULL;
1955 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1956 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1957 struct __queue *queue = &pmlmepriv->scanned_queue;
1958 struct iw_point *pdata = &wrqu->data;
1960 if (padapter->bDriverStopped || !pdata) {
1965 while ((check_fwstate(pmlmepriv, (_FW_UNDER_SURVEY | _FW_UNDER_LINKING)))) {
1972 if (pdata->length >= 32) {
1973 if (copy_from_user(data, pdata->pointer, 32)) {
1982 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
1984 phead = get_list_head(queue);
1985 plist = phead->next;
1987 while (phead != plist) {
1988 pnetwork = container_of(plist, struct wlan_network, list);
1990 if (!mac_pton(data, bssid)) {
1991 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
1995 if (!memcmp(bssid, pnetwork->network.MacAddress, ETH_ALEN)) {
1996 /* BSSID match, then check if supporting wpa/wpa2 */
1997 pbuf = rtw_get_wpa_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
1998 if (pbuf && (wpa_ielen > 0)) {
2003 pbuf = rtw_get_wpa2_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
2004 if (pbuf && (wpa_ielen > 0)) {
2010 plist = plist->next;
2013 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
2015 if (pdata->length >= 34) {
2016 if (copy_to_user(pdata->pointer + 32, (u8 *)&pdata->flags, 1)) {
2027 static int rtw_set_pid(struct net_device *dev,
2028 struct iw_request_info *info,
2029 union iwreq_data *wrqu, char *extra)
2032 struct adapter *padapter = rtw_netdev_priv(dev);
2033 int *pdata = (int *)wrqu;
2036 if (padapter->bDriverStopped || !pdata) {
2042 if (selector < 3 && selector >= 0) {
2043 padapter->pid[selector] = *(pdata + 1);
2044 ui_pid[selector] = *(pdata + 1);
2050 static int rtw_wps_start(struct net_device *dev,
2051 struct iw_request_info *info,
2052 union iwreq_data *wrqu, char *extra)
2055 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2056 struct iw_point *pdata = &wrqu->data;
2057 u32 u32wps_start = 0;
2061 ret = copy_from_user((void *)&u32wps_start, pdata->pointer, 4);
2067 if (padapter->bDriverStopped) {
2072 if (u32wps_start == 0)
2073 u32wps_start = *extra;
2075 if (u32wps_start == 1) /* WPS Start */
2076 rtw_led_control(padapter, LED_CTL_START_WPS);
2077 else if (u32wps_start == 2) /* WPS Stop because of wps success */
2078 rtw_led_control(padapter, LED_CTL_STOP_WPS);
2079 else if (u32wps_start == 3) /* WPS Stop because of wps fail */
2080 rtw_led_control(padapter, LED_CTL_STOP_WPS_FAIL);
2086 static int rtw_wext_p2p_enable(struct net_device *dev,
2087 struct iw_request_info *info,
2088 union iwreq_data *wrqu, char *extra)
2091 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2092 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2093 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2094 enum P2P_ROLE init_role = P2P_ROLE_DISABLE;
2097 init_role = P2P_ROLE_DISABLE;
2098 else if (*extra == '1')
2099 init_role = P2P_ROLE_DEVICE;
2100 else if (*extra == '2')
2101 init_role = P2P_ROLE_CLIENT;
2102 else if (*extra == '3')
2103 init_role = P2P_ROLE_GO;
2105 if (_FAIL == rtw_p2p_enable(padapter, init_role)) {
2110 /* set channel/bandwidth */
2111 if (init_role != P2P_ROLE_DISABLE) {
2112 u8 channel, ch_offset;
2115 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_LISTEN)) {
2116 /* Stay at the listen state and wait for discovery. */
2117 channel = pwdinfo->listen_channel;
2118 pwdinfo->operating_channel = pwdinfo->listen_channel;
2119 ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
2120 bwmode = HT_CHANNEL_WIDTH_20;
2122 pwdinfo->operating_channel = pmlmeext->cur_channel;
2124 channel = pwdinfo->operating_channel;
2125 ch_offset = pmlmeext->cur_ch_offset;
2126 bwmode = pmlmeext->cur_bwmode;
2129 set_channel_bwmode(padapter, channel, ch_offset, bwmode);
2136 static void rtw_p2p_set_go_nego_ssid(struct net_device *dev,
2137 struct iw_request_info *info,
2138 union iwreq_data *wrqu, char *extra)
2140 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2141 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2143 memcpy(pwdinfo->nego_ssid, extra, strlen(extra));
2144 pwdinfo->nego_ssidlen = strlen(extra);
2147 static int rtw_p2p_set_intent(struct net_device *dev,
2148 struct iw_request_info *info,
2149 union iwreq_data *wrqu, char *extra)
2152 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2153 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2154 u8 intent = pwdinfo->intent;
2156 switch (wrqu->data.length) {
2158 intent = extra[0] - '0';
2161 intent = str_2char2num(extra[0], extra[1]);
2165 pwdinfo->intent = intent;
2171 static int rtw_p2p_set_listen_ch(struct net_device *dev,
2172 struct iw_request_info *info,
2173 union iwreq_data *wrqu, char *extra)
2176 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2177 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2178 u8 listen_ch = pwdinfo->listen_channel; /* Listen channel number */
2180 switch (wrqu->data.length) {
2182 listen_ch = extra[0] - '0';
2185 listen_ch = str_2char2num(extra[0], extra[1]);
2189 if ((listen_ch == 1) || (listen_ch == 6) || (listen_ch == 11)) {
2190 pwdinfo->listen_channel = listen_ch;
2191 set_channel_bwmode(padapter, pwdinfo->listen_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
2199 static int rtw_p2p_set_op_ch(struct net_device *dev,
2200 struct iw_request_info *info,
2201 union iwreq_data *wrqu, char *extra)
2203 /* Commented by Albert 20110524 */
2204 /* This function is used to set the operating channel if the driver will become the group owner */
2207 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2208 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2209 u8 op_ch = pwdinfo->operating_channel; /* Operating channel number */
2211 switch (wrqu->data.length) {
2213 op_ch = extra[0] - '0';
2216 op_ch = str_2char2num(extra[0], extra[1]);
2221 pwdinfo->operating_channel = op_ch;
2228 static int rtw_p2p_profilefound(struct net_device *dev,
2229 struct iw_request_info *info,
2230 union iwreq_data *wrqu, char *extra)
2233 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2234 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2236 /* Comment by Albert 2010/10/13 */
2237 /* Input data format: */
2239 /* Ex: 1XX:XX:XX:XX:XX:XXYYSSID */
2240 /* 0 => Reflush the profile record list. */
2241 /* 1 => Add the profile list */
2242 /* XX:XX:XX:XX:XX:XX => peer's MAC Address (ex: 00:E0:4C:00:00:01) */
2243 /* YY => SSID Length */
2244 /* SSID => SSID for persistence group */
2246 /* The upper application should pass the SSID to driver by using this rtw_p2p_profilefound function. */
2247 if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
2248 if (extra[0] == '0') {
2249 /* Remove all the profile information of wifidirect_info structure. */
2250 memset(&pwdinfo->profileinfo[0], 0x00, sizeof(struct profile_info) * P2P_MAX_PERSISTENT_GROUP_NUM);
2251 pwdinfo->profileindex = 0;
2253 if (pwdinfo->profileindex >= P2P_MAX_PERSISTENT_GROUP_NUM) {
2258 /* Add this profile information into pwdinfo->profileinfo */
2259 /* Ex: 1XX:XX:XX:XX:XX:XXYYSSID */
2260 for (jj = 0, kk = 1; jj < ETH_ALEN; jj++, kk += 3)
2261 pwdinfo->profileinfo[pwdinfo->profileindex].peermac[jj] = key_2char2num(extra[kk], extra[kk + 1]);
2263 pwdinfo->profileinfo[pwdinfo->profileindex].ssidlen = (extra[18] - '0') * 10 + (extra[19] - '0');
2264 memcpy(pwdinfo->profileinfo[pwdinfo->profileindex].ssid, &extra[20], pwdinfo->profileinfo[pwdinfo->profileindex].ssidlen);
2265 pwdinfo->profileindex++;
2273 static void rtw_p2p_setDN(struct net_device *dev,
2274 struct iw_request_info *info,
2275 union iwreq_data *wrqu, char *extra)
2277 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2278 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2280 memset(pwdinfo->device_name, 0x00, WPS_MAX_DEVICE_NAME_LEN);
2281 memcpy(pwdinfo->device_name, extra, wrqu->data.length - 1);
2282 pwdinfo->device_name_len = wrqu->data.length - 1;
2285 static int rtw_p2p_get_wps_configmethod(struct net_device *dev,
2286 struct iw_request_info *info,
2287 union iwreq_data *wrqu, char *extra)
2289 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2290 u8 peerMAC[ETH_ALEN] = {0x00};
2292 u8 peerMACStr[17] = {0x00};
2293 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2294 struct list_head *plist, *phead;
2295 struct __queue *queue = &pmlmepriv->scanned_queue;
2296 struct wlan_network *pnetwork = NULL;
2298 u16 attr_content = 0;
2299 uint attr_contentlen = 0;
2300 /* 6 is the string "wpsCM =", 17 is the MAC addr, we have to clear it at wrqu->data.pointer */
2301 u8 attr_content_str[6 + 17] = {0x00};
2303 /* Commented by Albert 20110727 */
2304 /* The input data is the MAC address which the application wants to know its WPS config method. */
2305 /* After knowing its WPS config method, the application can decide the config method for provisioning discovery. */
2306 /* Format: iwpriv wlanx p2p_get_wpsCM 00:E0:4C:00:00:05 */
2308 if (copy_from_user(peerMACStr, wrqu->data.pointer + 6, 17))
2311 for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
2312 peerMAC[jj] = key_2char2num(peerMACStr[kk], peerMACStr[kk + 1]);
2314 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
2316 phead = get_list_head(queue);
2317 plist = phead->next;
2319 while (phead != plist) {
2320 pnetwork = container_of(plist, struct wlan_network, list);
2321 if (!memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
2326 /* The mac address is matched. */
2327 wpsie = rtw_get_wps_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &wpsie_len);
2329 rtw_get_wps_attr_content(wpsie, wpsie_len, WPS_ATTR_CONF_METHOD, (u8 *)&be_tmp, &attr_contentlen);
2330 if (attr_contentlen) {
2331 attr_content = be16_to_cpu(be_tmp);
2332 sprintf(attr_content_str, "\n\nM =%.4d", attr_content);
2338 plist = plist->next;
2341 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
2344 sprintf(attr_content_str, "\n\nM = 0000");
2346 if (copy_to_user(wrqu->data.pointer, attr_content_str, 6 + 17))
2351 static int rtw_p2p_get_go_device_address(struct net_device *dev,
2352 struct iw_request_info *info,
2353 union iwreq_data *wrqu, char *extra)
2355 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2356 u8 peerMAC[ETH_ALEN] = {0x00};
2358 u8 peerMACStr[17] = {0x00};
2359 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2360 struct list_head *plist, *phead;
2361 struct __queue *queue = &pmlmepriv->scanned_queue;
2362 struct wlan_network *pnetwork = NULL;
2365 uint p2pielen = 0, attr_contentlen = 0;
2366 u8 attr_content[100] = {0x00};
2368 u8 go_devadd_str[100 + 10] = {0x00};
2369 /* +10 is for the str "go_devadd =", we have to clear it at wrqu->data.pointer */
2371 /* Commented by Albert 20121209 */
2372 /* The input data is the GO's interface address which the application wants to know its device address. */
2373 /* Format: iwpriv wlanx p2p_get2 go_devadd = 00:E0:4C:00:00:05 */
2375 if (copy_from_user(peerMACStr, wrqu->data.pointer + 10, 17))
2378 for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
2379 peerMAC[jj] = key_2char2num(peerMACStr[kk], peerMACStr[kk + 1]);
2381 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
2383 phead = get_list_head(queue);
2384 plist = phead->next;
2386 while (phead != plist) {
2387 pnetwork = container_of(plist, struct wlan_network, list);
2388 if (!memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
2389 /* Commented by Albert 2011/05/18 */
2390 /* Match the device address located in the P2P IE */
2391 /* This is for the case that the P2P device address is not the same as the P2P interface address. */
2393 p2pie = rtw_get_p2p_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &p2pielen);
2396 /* The P2P Device ID attribute is included in the Beacon frame. */
2397 /* The P2P Device Info attribute is included in the probe response frame. */
2399 memset(attr_content, 0x00, 100);
2400 if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_ID, attr_content, &attr_contentlen)) {
2401 /* Handle the P2P Device ID attribute of Beacon first */
2404 } else if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_INFO, attr_content, &attr_contentlen)) {
2405 /* Handle the P2P Device Info attribute of probe response */
2410 /* Get the next P2P IE */
2411 p2pie = rtw_get_p2p_ie(p2pie + p2pielen, pnetwork->network.IELength - 12 - (p2pie - &pnetwork->network.IEs[12] + p2pielen), NULL, &p2pielen);
2416 plist = plist->next;
2419 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
2422 sprintf(go_devadd_str, "\n\ndev_add = NULL");
2424 sprintf(go_devadd_str, "\ndev_add =%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
2425 attr_content[0], attr_content[1], attr_content[2], attr_content[3], attr_content[4], attr_content[5]);
2427 if (copy_to_user(wrqu->data.pointer, go_devadd_str, 10 + 17))
2432 static int rtw_p2p_get_device_type(struct net_device *dev,
2433 struct iw_request_info *info,
2434 union iwreq_data *wrqu, char *extra)
2436 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2437 u8 peerMAC[ETH_ALEN] = {0x00};
2439 u8 peerMACStr[17] = {0x00};
2440 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2441 struct list_head *plist, *phead;
2442 struct __queue *queue = &pmlmepriv->scanned_queue;
2443 struct wlan_network *pnetwork = NULL;
2445 u8 dev_type[8] = {0x00};
2446 uint dev_type_len = 0;
2447 u8 dev_type_str[17 + 9] = {0x00}; /* +9 is for the str "dev_type =", we have to clear it at wrqu->data.pointer */
2449 /* Commented by Albert 20121209 */
2450 /* The input data is the MAC address which the application wants to know its device type. */
2451 /* Such user interface could know the device type. */
2452 /* Format: iwpriv wlanx p2p_get2 dev_type = 00:E0:4C:00:00:05 */
2454 if (copy_from_user(peerMACStr, wrqu->data.pointer + 9, 17))
2457 for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
2458 peerMAC[jj] = key_2char2num(peerMACStr[kk], peerMACStr[kk + 1]);
2460 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
2462 phead = get_list_head(queue);
2463 plist = phead->next;
2465 while (phead != plist) {
2466 pnetwork = container_of(plist, struct wlan_network, list);
2467 if (!memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
2471 /* The mac address is matched. */
2473 wpsie = rtw_get_wps_ie(&pnetwork->network.IEs[12],
2474 pnetwork->network.IELength - 12,
2477 rtw_get_wps_attr_content(wpsie, wpsie_len, WPS_ATTR_PRIMARY_DEV_TYPE, dev_type, &dev_type_len);
2482 memcpy(&be_tmp, dev_type, 2);
2483 type = be16_to_cpu(be_tmp);
2484 sprintf(dev_type_str, "\n\nN =%.2d", type);
2491 plist = plist->next;
2494 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
2497 sprintf(dev_type_str, "\n\nN = 00");
2499 if (copy_to_user(wrqu->data.pointer, dev_type_str, 9 + 17)) {
2506 static int rtw_p2p_get_device_name(struct net_device *dev,
2507 struct iw_request_info *info,
2508 union iwreq_data *wrqu, char *extra)
2510 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2511 u8 peerMAC[ETH_ALEN] = {0x00};
2513 u8 peerMACStr[17] = {0x00};
2514 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2515 struct list_head *plist, *phead;
2516 struct __queue *queue = &pmlmepriv->scanned_queue;
2517 struct wlan_network *pnetwork = NULL;
2519 u8 dev_name[WPS_MAX_DEVICE_NAME_LEN] = {0x00};
2521 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 */
2523 /* Commented by Albert 20121225 */
2524 /* The input data is the MAC address which the application wants to know its device name. */
2525 /* Such user interface could show peer device's device name instead of ssid. */
2526 /* Format: iwpriv wlanx p2p_get2 devN = 00:E0:4C:00:00:05 */
2528 if (copy_from_user(peerMACStr, wrqu->data.pointer + 5, 17))
2531 for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
2532 peerMAC[jj] = key_2char2num(peerMACStr[kk], peerMACStr[kk + 1]);
2534 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
2536 phead = get_list_head(queue);
2537 plist = phead->next;
2539 while (phead != plist) {
2540 pnetwork = container_of(plist, struct wlan_network, list);
2541 if (!memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
2545 /* The mac address is matched. */
2546 wpsie = rtw_get_wps_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &wpsie_len);
2548 rtw_get_wps_attr_content(wpsie, wpsie_len, WPS_ATTR_DEVICE_NAME, dev_name, &dev_len);
2550 sprintf(dev_name_str, "\n\nN =%s", dev_name);
2557 plist = plist->next;
2560 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
2563 sprintf(dev_name_str, "\n\nN = 0000");
2565 if (copy_to_user(wrqu->data.pointer, dev_name_str, 5 + ((dev_len > 17) ? dev_len : 17)))
2570 static int rtw_p2p_get_invitation_procedure(struct net_device *dev,
2571 struct iw_request_info *info,
2572 union iwreq_data *wrqu, char *extra)
2574 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2575 u8 peerMAC[ETH_ALEN] = {0x00};
2577 u8 peerMACStr[17] = {0x00};
2578 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2579 struct list_head *plist, *phead;
2580 struct __queue *queue = &pmlmepriv->scanned_queue;
2581 struct wlan_network *pnetwork = NULL;
2584 uint p2pielen = 0, attr_contentlen = 0;
2585 u8 attr_content[2] = {0x00};
2587 u8 inv_proc_str[17 + 8] = {0x00};
2588 /* +8 is for the str "InvProc =", we have to clear it at wrqu->data.pointer */
2590 /* Commented by Ouden 20121226 */
2591 /* The application wants to know P2P initiation procedure is supported or not. */
2592 /* Format: iwpriv wlanx p2p_get2 InvProc = 00:E0:4C:00:00:05 */
2594 if (copy_from_user(peerMACStr, wrqu->data.pointer + 8, 17))
2597 for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
2598 peerMAC[jj] = key_2char2num(peerMACStr[kk], peerMACStr[kk + 1]);
2600 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
2602 phead = get_list_head(queue);
2603 plist = phead->next;
2605 while (phead != plist) {
2606 pnetwork = container_of(plist, struct wlan_network, list);
2607 if (!memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
2608 /* Commented by Albert 20121226 */
2609 /* Match the device address located in the P2P IE */
2610 /* This is for the case that the P2P device address is not the same as the P2P interface address. */
2612 p2pie = rtw_get_p2p_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &p2pielen);
2615 if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_CAPABILITY, attr_content, &attr_contentlen)) {
2616 /* Handle the P2P capability attribute */
2621 /* Get the next P2P IE */
2622 p2pie = rtw_get_p2p_ie(p2pie + p2pielen, pnetwork->network.IELength - 12 - (p2pie - &pnetwork->network.IEs[12] + p2pielen), NULL, &p2pielen);
2626 plist = plist->next;
2629 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
2632 sprintf(inv_proc_str, "\nIP =-1");
2634 if (attr_content[0] & 0x20)
2635 sprintf(inv_proc_str, "\nIP = 1");
2637 sprintf(inv_proc_str, "\nIP = 0");
2639 if (copy_to_user(wrqu->data.pointer, inv_proc_str, 8 + 17))
2644 static int rtw_p2p_connect(struct net_device *dev,
2645 struct iw_request_info *info,
2646 union iwreq_data *wrqu, char *extra)
2649 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2650 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2651 u8 peerMAC[ETH_ALEN] = {0x00};
2653 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2654 struct list_head *plist, *phead;
2655 struct __queue *queue = &pmlmepriv->scanned_queue;
2656 struct wlan_network *pnetwork = NULL;
2657 u32 peer_channel = 0;
2659 /* Commented by Albert 20110304 */
2660 /* The input data contains two informations. */
2661 /* 1. First information is the MAC address which wants to formate with */
2662 /* 2. Second information is the WPS PINCode or "pbc" string for push button method */
2663 /* Format: 00:E0:4C:00:00:05 */
2664 /* Format: 00:E0:4C:00:00:05 */
2666 if (pwdinfo->p2p_state == P2P_STATE_NONE)
2669 if (pwdinfo->ui_got_wps_info == P2P_NO_WPSINFO)
2672 for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
2673 peerMAC[jj] = key_2char2num(extra[kk], extra[kk + 1]);
2675 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
2677 phead = get_list_head(queue);
2678 plist = phead->next;
2680 while (phead != plist) {
2681 pnetwork = container_of(plist, struct wlan_network, list);
2682 if (!memcmp(pnetwork->network.MacAddress, peerMAC, ETH_ALEN)) {
2683 peer_channel = pnetwork->network.Configuration.DSConfig;
2687 plist = plist->next;
2690 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
2693 memset(&pwdinfo->nego_req_info, 0x00, sizeof(struct tx_nego_req_info));
2694 memset(&pwdinfo->groupid_info, 0x00, sizeof(struct group_id_info));
2696 pwdinfo->nego_req_info.peer_channel_num[0] = peer_channel;
2697 memcpy(pwdinfo->nego_req_info.peerDevAddr, pnetwork->network.MacAddress, ETH_ALEN);
2698 pwdinfo->nego_req_info.benable = true;
2700 _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
2701 if (rtw_p2p_state(pwdinfo) != P2P_STATE_GONEGO_OK) {
2702 /* Restore to the listen state if the current p2p state is not nego OK */
2703 rtw_p2p_set_state(pwdinfo, P2P_STATE_LISTEN);
2706 rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
2707 rtw_p2p_set_state(pwdinfo, P2P_STATE_GONEGO_ING);
2709 _set_timer(&pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT);
2710 _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_GO_NEGO_TIMEOUT);
2717 static void rtw_p2p_invite_req(struct net_device *dev,
2718 struct iw_request_info *info,
2719 union iwreq_data *wrqu, char *extra)
2721 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2722 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2724 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2725 struct list_head *plist, *phead;
2726 struct __queue *queue = &pmlmepriv->scanned_queue;
2727 struct wlan_network *pnetwork = NULL;
2728 uint peer_channel = 0;
2729 u8 attr_content[50] = {0x00};
2731 uint p2pielen = 0, attr_contentlen = 0;
2732 struct tx_invite_req_info *pinvite_req_info = &pwdinfo->invitereq_info;
2734 /* The input data contains two informations. */
2735 /* 1. First information is the P2P device address which you want to send to. */
2736 /* 2. Second information is the group id which combines with GO's mac address, space and GO's ssid. */
2737 /* Command line sample: iwpriv wlan0 p2p_set invite ="00:11:22:33:44:55 00:E0:4C:00:00:05 DIRECT-xy" */
2738 /* Format: 00:11:22:33:44:55 00:E0:4C:00:00:05 DIRECT-xy */
2740 if (wrqu->data.length <= 37)
2743 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
2746 /* Reset the content of struct tx_invite_req_info */
2747 pinvite_req_info->benable = false;
2748 memset(pinvite_req_info->go_bssid, 0x00, ETH_ALEN);
2749 memset(pinvite_req_info->go_ssid, 0x00, WLAN_SSID_MAXLEN);
2750 pinvite_req_info->ssidlen = 0x00;
2751 pinvite_req_info->operating_ch = pwdinfo->operating_channel;
2752 memset(pinvite_req_info->peer_macaddr, 0x00, ETH_ALEN);
2753 pinvite_req_info->token = 3;
2756 for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
2757 pinvite_req_info->peer_macaddr[jj] = key_2char2num(extra[kk], extra[kk + 1]);
2759 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
2761 phead = get_list_head(queue);
2762 plist = phead->next;
2764 while (phead != plist) {
2765 pnetwork = container_of(plist, struct wlan_network, list);
2767 /* Commented by Albert 2011/05/18 */
2768 /* Match the device address located in the P2P IE */
2769 /* This is for the case that the P2P device address is not the same as the P2P interface address. */
2771 p2pie = rtw_get_p2p_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &p2pielen);
2773 /* The P2P Device ID attribute is included in the Beacon frame. */
2774 /* The P2P Device Info attribute is included in the probe response frame. */
2776 if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_ID, attr_content, &attr_contentlen)) {
2777 /* Handle the P2P Device ID attribute of Beacon first */
2778 if (!memcmp(attr_content, pinvite_req_info->peer_macaddr, ETH_ALEN)) {
2779 peer_channel = pnetwork->network.Configuration.DSConfig;
2782 } else if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_INFO, attr_content, &attr_contentlen)) {
2783 /* Handle the P2P Device Info attribute of probe response */
2784 if (!memcmp(attr_content, pinvite_req_info->peer_macaddr, ETH_ALEN)) {
2785 peer_channel = pnetwork->network.Configuration.DSConfig;
2790 plist = plist->next;
2793 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
2796 /* Store the GO's bssid */
2797 for (jj = 0, kk = 18; jj < ETH_ALEN; jj++, kk += 3)
2798 pinvite_req_info->go_bssid[jj] = key_2char2num(extra[kk], extra[kk + 1]);
2800 /* Store the GO's ssid */
2801 pinvite_req_info->ssidlen = wrqu->data.length - 36;
2802 memcpy(pinvite_req_info->go_ssid, &extra[36], (u32)pinvite_req_info->ssidlen);
2803 pinvite_req_info->benable = true;
2804 pinvite_req_info->peer_ch = peer_channel;
2806 rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
2807 rtw_p2p_set_state(pwdinfo, P2P_STATE_TX_INVITE_REQ);
2809 set_channel_bwmode(padapter, peer_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
2811 _set_timer(&pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT);
2813 _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_INVITE_TIMEOUT);
2817 static void rtw_p2p_set_persistent(struct net_device *dev,
2818 struct iw_request_info *info,
2819 union iwreq_data *wrqu, char *extra)
2821 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2822 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2824 /* The input data is 0 or 1 */
2825 /* 0: disable persistent group functionality */
2826 /* 1: enable persistent group founctionality */
2828 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
2831 if (extra[0] == '0') /* Disable the persistent group function. */
2832 pwdinfo->persistent_supported = false;
2833 else if (extra[0] == '1') /* Enable the persistent group function. */
2834 pwdinfo->persistent_supported = true;
2836 pwdinfo->persistent_supported = false;
2838 pr_info("[%s] persistent_supported = %d\n", __func__, pwdinfo->persistent_supported);
2841 static void rtw_p2p_prov_disc(struct net_device *dev,
2842 struct iw_request_info *info,
2843 union iwreq_data *wrqu, char *extra)
2845 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2846 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2847 u8 peerMAC[ETH_ALEN] = {0x00};
2849 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2850 struct list_head *plist, *phead;
2851 struct __queue *queue = &pmlmepriv->scanned_queue;
2852 struct wlan_network *pnetwork = NULL;
2853 uint peer_channel = 0;
2854 u8 attr_content[100] = {0x00};
2856 uint p2pielen = 0, attr_contentlen = 0;
2858 /* The input data contains two informations. */
2859 /* 1. First information is the MAC address which wants to issue the provisioning discovery request frame. */
2860 /* 2. Second information is the WPS configuration method which wants to discovery */
2861 /* Format: 00:E0:4C:00:00:05_display */
2862 /* Format: 00:E0:4C:00:00:05_keypad */
2863 /* Format: 00:E0:4C:00:00:05_pbc */
2864 /* Format: 00:E0:4C:00:00:05_label */
2866 if (pwdinfo->p2p_state == P2P_STATE_NONE) {
2869 /* Reset the content of struct tx_provdisc_req_info excluded the wps_config_method_request. */
2870 memset(pwdinfo->tx_prov_disc_info.peerDevAddr, 0x00, ETH_ALEN);
2871 memset(pwdinfo->tx_prov_disc_info.peerIFAddr, 0x00, ETH_ALEN);
2872 memset(&pwdinfo->tx_prov_disc_info.ssid, 0x00, sizeof(struct ndis_802_11_ssid));
2873 pwdinfo->tx_prov_disc_info.peer_channel_num[0] = 0;
2874 pwdinfo->tx_prov_disc_info.peer_channel_num[1] = 0;
2875 pwdinfo->tx_prov_disc_info.benable = false;
2878 for (jj = 0, kk = 0; jj < ETH_ALEN; jj++, kk += 3)
2879 peerMAC[jj] = key_2char2num(extra[kk], extra[kk + 1]);
2881 if (!memcmp(&extra[18], "display", 7))
2882 pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_DISPLYA;
2883 else if (!memcmp(&extra[18], "keypad", 7))
2884 pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_KEYPAD;
2885 else if (!memcmp(&extra[18], "pbc", 3))
2886 pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_PUSH_BUTTON;
2887 else if (!memcmp(&extra[18], "label", 5))
2888 pwdinfo->tx_prov_disc_info.wps_config_method_request = WPS_CM_LABEL;
2892 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
2894 phead = get_list_head(queue);
2895 plist = phead->next;
2897 while (phead != plist) {
2898 if (peer_channel != 0)
2901 pnetwork = container_of(plist, struct wlan_network, list);
2903 /* Commented by Albert 2011/05/18 */
2904 /* Match the device address located in the P2P IE */
2905 /* This is for the case that the P2P device address is not the same as the P2P interface address. */
2907 p2pie = rtw_get_p2p_ie(&pnetwork->network.IEs[12], pnetwork->network.IELength - 12, NULL, &p2pielen);
2910 /* The P2P Device ID attribute is included in the Beacon frame. */
2911 /* The P2P Device Info attribute is included in the probe response frame. */
2913 if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_ID, attr_content, &attr_contentlen)) {
2914 /* Handle the P2P Device ID attribute of Beacon first */
2915 if (!memcmp(attr_content, peerMAC, ETH_ALEN)) {
2916 peer_channel = pnetwork->network.Configuration.DSConfig;
2919 } else if (rtw_get_p2p_attr_content(p2pie, p2pielen, P2P_ATTR_DEVICE_INFO, attr_content, &attr_contentlen)) {
2920 /* Handle the P2P Device Info attribute of probe response */
2921 if (!memcmp(attr_content, peerMAC, ETH_ALEN)) {
2922 peer_channel = pnetwork->network.Configuration.DSConfig;
2927 /* Get the next P2P IE */
2928 p2pie = rtw_get_p2p_ie(p2pie + p2pielen, pnetwork->network.IELength - 12 - (p2pie - &pnetwork->network.IEs[12] + p2pielen), NULL, &p2pielen);
2932 plist = plist->next;
2935 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
2938 memcpy(pwdinfo->tx_prov_disc_info.peerIFAddr, pnetwork->network.MacAddress, ETH_ALEN);
2939 memcpy(pwdinfo->tx_prov_disc_info.peerDevAddr, peerMAC, ETH_ALEN);
2940 pwdinfo->tx_prov_disc_info.peer_channel_num[0] = (u16)peer_channel;
2941 pwdinfo->tx_prov_disc_info.benable = true;
2942 rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
2943 rtw_p2p_set_state(pwdinfo, P2P_STATE_TX_PROVISION_DIS_REQ);
2945 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT)) {
2946 memcpy(&pwdinfo->tx_prov_disc_info.ssid, &pnetwork->network.Ssid, sizeof(struct ndis_802_11_ssid));
2947 } else if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_DEVICE) || rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
2948 memcpy(pwdinfo->tx_prov_disc_info.ssid.Ssid, pwdinfo->p2p_wildcard_ssid, P2P_WILDCARD_SSID_LEN);
2949 pwdinfo->tx_prov_disc_info.ssid.SsidLength = P2P_WILDCARD_SSID_LEN;
2952 set_channel_bwmode(padapter, peer_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
2954 _set_timer(&pwdinfo->pre_tx_scan_timer, P2P_TX_PRESCAN_TIMEOUT);
2956 _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_PROVISION_TIMEOUT);
2960 /* This function is used to inform the driver the user had specified the pin code value or pbc */
2961 /* to application. */
2963 static void rtw_p2p_got_wpsinfo(struct net_device *dev,
2964 struct iw_request_info *info,
2965 union iwreq_data *wrqu, char *extra)
2967 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
2968 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
2970 /* Added by Albert 20110328 */
2971 /* if the input data is P2P_NO_WPSINFO -> reset the wpsinfo */
2972 /* if the input data is P2P_GOT_WPSINFO_PEER_DISPLAY_PIN -> the utility just input the PIN code got from the peer P2P device. */
2973 /* if the input data is P2P_GOT_WPSINFO_SELF_DISPLAY_PIN -> the utility just got the PIN code from itself. */
2974 /* if the input data is P2P_GOT_WPSINFO_PBC -> the utility just determine to use the PBC */
2977 pwdinfo->ui_got_wps_info = P2P_NO_WPSINFO;
2978 else if (*extra == '1')
2979 pwdinfo->ui_got_wps_info = P2P_GOT_WPSINFO_PEER_DISPLAY_PIN;
2980 else if (*extra == '2')
2981 pwdinfo->ui_got_wps_info = P2P_GOT_WPSINFO_SELF_DISPLAY_PIN;
2982 else if (*extra == '3')
2983 pwdinfo->ui_got_wps_info = P2P_GOT_WPSINFO_PBC;
2985 pwdinfo->ui_got_wps_info = P2P_NO_WPSINFO;
2988 static int rtw_p2p_set(struct net_device *dev,
2989 struct iw_request_info *info,
2990 union iwreq_data *wrqu, char *extra)
2994 if (!memcmp(extra, "enable =", 7)) {
2995 rtw_wext_p2p_enable(dev, info, wrqu, &extra[7]);
2996 } else if (!memcmp(extra, "setDN =", 6)) {
2997 wrqu->data.length -= 6;
2998 rtw_p2p_setDN(dev, info, wrqu, &extra[6]);
2999 } else if (!memcmp(extra, "profilefound =", 13)) {
3000 wrqu->data.length -= 13;
3001 rtw_p2p_profilefound(dev, info, wrqu, &extra[13]);
3002 } else if (!memcmp(extra, "prov_disc =", 10)) {
3003 wrqu->data.length -= 10;
3004 rtw_p2p_prov_disc(dev, info, wrqu, &extra[10]);
3005 } else if (!memcmp(extra, "nego =", 5)) {
3006 wrqu->data.length -= 5;
3007 rtw_p2p_connect(dev, info, wrqu, &extra[5]);
3008 } else if (!memcmp(extra, "intent =", 7)) {
3009 /* Commented by Albert 2011/03/23 */
3010 /* The wrqu->data.length will include the null character */
3011 /* So, we will decrease 7 + 1 */
3012 wrqu->data.length -= 8;
3013 rtw_p2p_set_intent(dev, info, wrqu, &extra[7]);
3014 } else if (!memcmp(extra, "ssid =", 5)) {
3015 wrqu->data.length -= 5;
3016 rtw_p2p_set_go_nego_ssid(dev, info, wrqu, &extra[5]);
3017 } else if (!memcmp(extra, "got_wpsinfo =", 12)) {
3018 wrqu->data.length -= 12;
3019 rtw_p2p_got_wpsinfo(dev, info, wrqu, &extra[12]);
3020 } else if (!memcmp(extra, "listen_ch =", 10)) {
3021 /* Commented by Albert 2011/05/24 */
3022 /* The wrqu->data.length will include the null character */
3023 /* So, we will decrease (10 + 1) */
3024 wrqu->data.length -= 11;
3025 rtw_p2p_set_listen_ch(dev, info, wrqu, &extra[10]);
3026 } else if (!memcmp(extra, "op_ch =", 6)) {
3027 /* Commented by Albert 2011/05/24 */
3028 /* The wrqu->data.length will include the null character */
3029 /* So, we will decrease (6 + 1) */
3030 wrqu->data.length -= 7;
3031 rtw_p2p_set_op_ch(dev, info, wrqu, &extra[6]);
3032 } else if (!memcmp(extra, "invite =", 7)) {
3033 wrqu->data.length -= 8;
3034 rtw_p2p_invite_req(dev, info, wrqu, &extra[7]);
3035 } else if (!memcmp(extra, "persistent =", 11)) {
3036 wrqu->data.length -= 11;
3037 rtw_p2p_set_persistent(dev, info, wrqu, &extra[11]);
3043 static int rtw_p2p_get2(struct net_device *dev,
3044 struct iw_request_info *info,
3045 union iwreq_data *wrqu, char *extra)
3049 if (!memcmp(extra, "wpsCM =", 6)) {
3050 wrqu->data.length -= 6;
3051 ret = rtw_p2p_get_wps_configmethod(dev, info, wrqu, &extra[6]);
3052 } else if (!memcmp(extra, "devN =", 5)) {
3053 wrqu->data.length -= 5;
3054 ret = rtw_p2p_get_device_name(dev, info, wrqu, &extra[5]);
3055 } else if (!memcmp(extra, "dev_type =", 9)) {
3056 wrqu->data.length -= 9;
3057 ret = rtw_p2p_get_device_type(dev, info, wrqu, &extra[9]);
3058 } else if (!memcmp(extra, "go_devadd =", 10)) {
3059 wrqu->data.length -= 10;
3060 ret = rtw_p2p_get_go_device_address(dev, info, wrqu, &extra[10]);
3061 } else if (!memcmp(extra, "InvProc =", 8)) {
3062 wrqu->data.length -= 8;
3063 ret = rtw_p2p_get_invitation_procedure(dev, info, wrqu, &extra[8]);
3069 static int rtw_rereg_nd_name(struct net_device *dev,
3070 struct iw_request_info *info,
3071 union iwreq_data *wrqu, char *extra)
3074 struct adapter *padapter = rtw_netdev_priv(dev);
3075 struct rereg_nd_name_data *rereg_priv = &padapter->rereg_nd_name_priv;
3076 char new_ifname[IFNAMSIZ];
3078 if (rereg_priv->old_ifname[0] == 0) {
3080 reg_ifname = padapter->registrypriv.if2name;
3082 strncpy(rereg_priv->old_ifname, reg_ifname, IFNAMSIZ);
3083 rereg_priv->old_ifname[IFNAMSIZ - 1] = 0;
3086 if (wrqu->data.length > IFNAMSIZ)
3089 if (copy_from_user(new_ifname, wrqu->data.pointer, IFNAMSIZ))
3092 if (0 == strcmp(rereg_priv->old_ifname, new_ifname))
3095 ret = rtw_change_ifname(padapter, new_ifname);
3099 if (!memcmp(rereg_priv->old_ifname, "disable%d", 9)) {
3100 padapter->ledpriv.bRegUseLed = rereg_priv->old_bRegUseLed;
3101 rtl8188eu_InitSwLeds(padapter);
3102 rtw_ips_mode_req(&padapter->pwrctrlpriv, rereg_priv->old_ips_mode);
3105 strncpy(rereg_priv->old_ifname, new_ifname, IFNAMSIZ);
3106 rereg_priv->old_ifname[IFNAMSIZ - 1] = 0;
3108 if (!memcmp(new_ifname, "disable%d", 9)) {
3109 /* free network queue for Android's timming issue */
3110 rtw_free_network_queue(padapter, true);
3113 rtw_led_control(padapter, LED_CTL_POWER_OFF);
3114 rereg_priv->old_bRegUseLed = padapter->ledpriv.bRegUseLed;
3115 padapter->ledpriv.bRegUseLed = false;
3116 rtl8188eu_DeInitSwLeds(padapter);
3118 /* the interface is being "disabled", we can do deeper IPS */
3119 rereg_priv->old_ips_mode = rtw_get_ips_mode_req(&padapter->pwrctrlpriv);
3120 rtw_ips_mode_req(&padapter->pwrctrlpriv, IPS_NORMAL);
3126 static void mac_reg_dump(struct adapter *padapter)
3129 pr_info("\n ======= MAC REG =======\n");
3130 for (i = 0x0; i < 0x300; i += 4) {
3132 pr_info("0x%02x", i);
3133 pr_info(" 0x%08x ", rtw_read32(padapter, i));
3137 for (i = 0x400; i < 0x800; i += 4) {
3139 pr_info("0x%02x", i);
3140 pr_info(" 0x%08x ", rtw_read32(padapter, i));
3146 static void bb_reg_dump(struct adapter *padapter)
3149 pr_info("\n ======= BB REG =======\n");
3150 for (i = 0x800; i < 0x1000; i += 4) {
3152 pr_info("0x%02x", i);
3154 pr_info(" 0x%08x ", rtw_read32(padapter, i));
3160 static void rf_reg_dump(struct adapter *padapter)
3165 pr_info("\n ======= RF REG =======\n");
3166 pr_info("\nRF_Path(%x)\n", RF_PATH_A);
3167 for (i = 0; i < 0x100; i++) {
3168 value = rtl8188e_PHY_QueryRFReg(padapter, i, 0xffffffff);
3170 pr_info("0x%02x ", i);
3171 pr_info(" 0x%08x ", value);
3177 static void rtw_set_dynamic_functions(struct adapter *adapter, u8 dm_func)
3179 struct hal_data_8188e *haldata = &adapter->haldata;
3180 struct odm_dm_struct *odmpriv = &haldata->odmpriv;
3184 /* disable all dynamic func */
3185 odmpriv->SupportAbility = DYNAMIC_FUNC_DISABLE;
3189 odmpriv->SupportAbility &= (~DYNAMIC_BB_DIG);
3192 /* turn on all dynamic func */
3193 if (!(odmpriv->SupportAbility & DYNAMIC_BB_DIG)) {
3194 struct rtw_dig *digtable = &odmpriv->DM_DigTable;
3196 digtable->CurIGValue = rtw_read8(adapter, 0xc50);
3198 odmpriv->SupportAbility = DYNAMIC_ALL_FUNC_ENABLE;
3205 static int rtw_dbg_port(struct net_device *dev,
3206 struct iw_request_info *info,
3207 union iwreq_data *wrqu, char *extra)
3210 u8 major_cmd, minor_cmd;
3214 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
3215 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
3216 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3217 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
3218 struct wlan_network *cur_network = &pmlmepriv->cur_network;
3219 struct sta_priv *pstapriv = &padapter->stapriv;
3221 pdata = (u32 *)&wrqu->data;
3224 arg = (u16)(val32 & 0x0000ffff);
3225 major_cmd = (u8)(val32 >> 24);
3226 minor_cmd = (u8)((val32 >> 16) & 0x00ff);
3228 extra_arg = *(pdata + 1);
3230 switch (major_cmd) {
3231 case 0x70:/* read_reg */
3232 switch (minor_cmd) {
3241 case 0x71:/* write_reg */
3242 switch (minor_cmd) {
3244 rtw_write8(padapter, arg, extra_arg);
3247 rtw_write16(padapter, arg, extra_arg);
3250 rtw_write32(padapter, arg, extra_arg);
3254 case 0x72:/* read_bb */
3256 case 0x73:/* write_bb */
3257 rtl8188e_PHY_SetBBReg(padapter, arg, 0xffffffff, extra_arg);
3259 case 0x74:/* read_rf */
3260 if (minor_cmd != RF_PATH_A) {
3265 case 0x75:/* write_rf */
3266 if (minor_cmd != RF_PATH_A) {
3270 rtl8188e_PHY_SetRFReg(padapter, arg, 0xffffffff, extra_arg);
3274 switch (minor_cmd) {
3275 case 0x00: /* normal mode, */
3276 padapter->recvpriv.is_signal_dbg = 0;
3278 case 0x01: /* dbg mode */
3279 padapter->recvpriv.is_signal_dbg = 1;
3280 extra_arg = extra_arg > 100 ? 100 : extra_arg;
3281 extra_arg = extra_arg < 0 ? 0 : extra_arg;
3282 padapter->recvpriv.signal_strength_dbg = extra_arg;
3286 case 0x78: /* IOL test */
3287 switch (minor_cmd) {
3288 case 0x04: /* LLT table initialization test */
3290 struct xmit_frame *xmit_frame;
3292 xmit_frame = rtw_IOL_accquire_xmit_frame(padapter);
3298 if (rtl8188e_IOL_exec_cmds_sync(padapter, xmit_frame, 500, 0) != _SUCCESS)
3302 case 0x05: /* blink LED test */
3306 u32 blink_delay_ms = 200;
3308 struct xmit_frame *xmit_frame;
3310 xmit_frame = rtw_IOL_accquire_xmit_frame(padapter);
3316 for (i = 0; i < blink_num; i++) {
3317 rtw_IOL_append_WB_cmd(xmit_frame, reg, 0x00, 0xff);
3318 rtw_IOL_append_DELAY_MS_cmd(xmit_frame, blink_delay_ms);
3319 rtw_IOL_append_WB_cmd(xmit_frame, reg, 0x08, 0xff);
3320 rtw_IOL_append_DELAY_MS_cmd(xmit_frame, blink_delay_ms);
3322 if (rtl8188e_IOL_exec_cmds_sync(padapter, xmit_frame, (blink_delay_ms * blink_num * 2) + 200, 0) != _SUCCESS)
3327 case 0x06: /* continuous write byte test */
3330 u16 start_value = 0;
3331 u32 write_num = extra_arg;
3333 struct xmit_frame *xmit_frame;
3335 xmit_frame = rtw_IOL_accquire_xmit_frame(padapter);
3341 for (i = 0; i < write_num; i++)
3342 rtw_IOL_append_WB_cmd(xmit_frame, reg, i + start_value, 0xFF);
3343 if (rtl8188e_IOL_exec_cmds_sync(padapter, xmit_frame, 5000, 0) != _SUCCESS)
3346 rtw_read8(padapter, reg);
3350 case 0x07: /* continuous write word test */
3353 u16 start_value = 200;
3354 u32 write_num = extra_arg;
3357 struct xmit_frame *xmit_frame;
3359 xmit_frame = rtw_IOL_accquire_xmit_frame(padapter);
3365 for (i = 0; i < write_num; i++)
3366 rtw_IOL_append_WW_cmd(xmit_frame, reg, i + start_value, 0xFFFF);
3367 if (rtl8188e_IOL_exec_cmds_sync(padapter, xmit_frame, 5000, 0) != _SUCCESS)
3370 rtw_read16(padapter, reg);
3373 case 0x08: /* continuous write dword test */
3376 u32 start_value = 0x110000c7;
3377 u32 write_num = extra_arg;
3380 struct xmit_frame *xmit_frame;
3382 xmit_frame = rtw_IOL_accquire_xmit_frame(padapter);
3388 for (i = 0; i < write_num; i++)
3389 rtw_IOL_append_WD_cmd(xmit_frame, reg, i + start_value, 0xFFFFFFFF);
3390 if (rtl8188e_IOL_exec_cmds_sync(padapter, xmit_frame, 5000, 0) != _SUCCESS)
3393 rtw_read32(padapter, reg);
3401 * dbg 0x79000000 [value], set RESP_TXAGC to + value, value:0~15
3402 * dbg 0x79010000 [value], set RESP_TXAGC to - value, value:0~15
3404 u8 value = extra_arg & 0x0f;
3405 u8 sign = minor_cmd;
3406 u16 write_value = 0;
3409 value = value | 0x10;
3411 write_value = value | (value << 5);
3412 rtw_write16(padapter, 0x6d9, write_value);
3416 receive_disconnect(padapter, pmlmeinfo->network.MacAddress
3417 , WLAN_REASON_EXPIRATION_CHK);
3420 switch (minor_cmd) {
3432 rtw_get_stainfo(pstapriv, cur_network->network.MacAddress);
3436 u32 ODMFlag = (u32)(0x0f & arg);
3437 SetHwReg8188EU(padapter, HW_VAR_DM_FLAG, (u8 *)(&ODMFlag));
3448 case 0x10:/* driver version display */
3451 padapter->bRxRSSIDisplay = extra_arg;
3453 case 0x12: /* set rx_stbc */
3455 struct registry_priv *pregpriv = &padapter->registrypriv;
3456 /* 0: disable, bit(0):enable 2.4g, bit(1):enable 5g, 0x3: enable both 2.4g and 5g */
3457 /* default is set to enable 2.4GHZ for IOT issue with bufflao's AP at 5GHZ */
3458 if (extra_arg == 0 ||
3462 pregpriv->rx_stbc = extra_arg;
3465 case 0x13: /* set ampdu_enable */
3467 struct registry_priv *pregpriv = &padapter->registrypriv;
3468 /* 0: disable, 0x1:enable (but wifi_spec should be 0), 0x2: force enable (don't care wifi_spec) */
3469 if (extra_arg >= 0 && extra_arg < 3)
3470 pregpriv->ampdu_enable = extra_arg;
3473 case 0x14: /* get wifi_spec */
3476 padapter->bNotifyChannelChange = extra_arg;
3479 padapter->bShowGetP2PState = extra_arg;
3481 case 0xdd:/* registers dump, 0 for mac reg, 1 for bb reg, 2 for rf reg */
3483 mac_reg_dump(padapter);
3484 else if (extra_arg == 1)
3485 bb_reg_dump(padapter);
3486 else if (extra_arg == 2)
3487 rf_reg_dump(padapter);
3489 case 0xee:/* turn on/off dynamic funcs */
3490 if (extra_arg != 0xf) {
3491 /* extra_arg = 0 - disable all dynamic func
3492 * extra_arg = 1 - disable DIG
3493 * extra_arg = 6 - turn on all dynamic func
3495 rtw_set_dynamic_functions(padapter, extra_arg);
3499 rtw_write8(padapter, 0xc50, arg);
3500 rtw_write8(padapter, 0xc58, arg);
3514 static int rtw_wx_set_priv(struct net_device *dev,
3515 struct iw_request_info *info,
3516 union iwreq_data *awrq,
3522 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
3523 struct iw_point *dwrq = (struct iw_point *)awrq;
3525 if (dwrq->length == 0)
3533 if (copy_from_user(ext, dwrq->pointer, len)) {
3538 /* added for wps2.0 @20110524 */
3539 if (dwrq->flags == 0x8766 && len > 8) {
3541 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
3542 u8 *probereq_wpsie = ext;
3543 int probereq_wpsie_len = len;
3544 u8 wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
3546 if ((_VENDOR_SPECIFIC_IE_ == probereq_wpsie[0]) &&
3547 (!memcmp(&probereq_wpsie[2], wps_oui, 4))) {
3548 cp_sz = probereq_wpsie_len > MAX_WPS_IE_LEN ? MAX_WPS_IE_LEN : probereq_wpsie_len;
3550 pmlmepriv->wps_probe_req_ie_len = 0;
3551 kfree(pmlmepriv->wps_probe_req_ie);
3552 pmlmepriv->wps_probe_req_ie = NULL;
3554 pmlmepriv->wps_probe_req_ie = kmemdup(probereq_wpsie, cp_sz, GFP_KERNEL);
3555 if (!pmlmepriv->wps_probe_req_ie) {
3559 pmlmepriv->wps_probe_req_ie_len = cp_sz;
3564 if (len >= WEXT_CSCAN_HEADER_SIZE &&
3565 !memcmp(ext, WEXT_CSCAN_HEADER, WEXT_CSCAN_HEADER_SIZE)) {
3566 ret = rtw_wx_set_scan(dev, info, awrq, ext);
3577 static int rtw_pm_set(struct net_device *dev,
3578 struct iw_request_info *info,
3579 union iwreq_data *wrqu, char *extra)
3583 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
3585 if (!memcmp(extra, "lps =", 4)) {
3586 sscanf(extra + 4, "%u", &mode);
3587 ret = rtw_pm_set_lps(padapter, mode);
3588 } else if (!memcmp(extra, "ips =", 4)) {
3589 sscanf(extra + 4, "%u", &mode);
3590 ret = rtw_pm_set_ips(padapter, mode);
3598 static iw_handler rtw_handlers[] = {
3599 IW_HANDLER(SIOCGIWNAME, rtw_wx_get_name),
3600 IW_HANDLER(SIOCGIWFREQ, rtw_wx_get_freq),
3601 IW_HANDLER(SIOCSIWMODE, rtw_wx_set_mode),
3602 IW_HANDLER(SIOCGIWMODE, rtw_wx_get_mode),
3603 IW_HANDLER(SIOCGIWSENS, rtw_wx_get_sens),
3604 IW_HANDLER(SIOCGIWRANGE, rtw_wx_get_range),
3605 IW_HANDLER(SIOCSIWPRIV, rtw_wx_set_priv),
3606 IW_HANDLER(SIOCSIWAP, rtw_wx_set_wap),
3607 IW_HANDLER(SIOCGIWAP, rtw_wx_get_wap),
3608 IW_HANDLER(SIOCSIWMLME, rtw_wx_set_mlme),
3609 IW_HANDLER(SIOCSIWSCAN, rtw_wx_set_scan),
3610 IW_HANDLER(SIOCGIWSCAN, rtw_wx_get_scan),
3611 IW_HANDLER(SIOCSIWESSID, rtw_wx_set_essid),
3612 IW_HANDLER(SIOCGIWESSID, rtw_wx_get_essid),
3613 IW_HANDLER(SIOCGIWNICKN, rtw_wx_get_nick),
3614 IW_HANDLER(SIOCSIWRATE, rtw_wx_set_rate),
3615 IW_HANDLER(SIOCGIWRATE, rtw_wx_get_rate),
3616 IW_HANDLER(SIOCSIWRTS, rtw_wx_set_rts),
3617 IW_HANDLER(SIOCGIWRTS, rtw_wx_get_rts),
3618 IW_HANDLER(SIOCSIWFRAG, rtw_wx_set_frag),
3619 IW_HANDLER(SIOCGIWFRAG, rtw_wx_get_frag),
3620 IW_HANDLER(SIOCGIWRETRY, rtw_wx_get_retry),
3621 IW_HANDLER(SIOCSIWENCODE, rtw_wx_set_enc),
3622 IW_HANDLER(SIOCGIWENCODE, rtw_wx_get_enc),
3623 IW_HANDLER(SIOCGIWPOWER, rtw_wx_get_power),
3624 IW_HANDLER(SIOCSIWGENIE, rtw_wx_set_gen_ie),
3625 IW_HANDLER(SIOCSIWAUTH, rtw_wx_set_auth),
3626 IW_HANDLER(SIOCSIWENCODEEXT, rtw_wx_set_enc_ext),
3627 IW_HANDLER(SIOCSIWPMKSA, rtw_wx_set_pmkid),
3630 static const struct iw_priv_args rtw_private_args[] = {
3632 SIOCIWFIRSTPRIV + 0x0,
3633 IW_PRIV_TYPE_CHAR | 0x7FF, 0, "write"
3636 SIOCIWFIRSTPRIV + 0x1,
3637 IW_PRIV_TYPE_CHAR | 0x7FF,
3638 IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "read"
3641 SIOCIWFIRSTPRIV + 0x2, 0, 0, "driver_ext"
3644 SIOCIWFIRSTPRIV + 0x4,
3645 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "apinfo"
3648 SIOCIWFIRSTPRIV + 0x5,
3649 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "setpid"
3652 SIOCIWFIRSTPRIV + 0x6,
3653 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wps_start"
3656 SIOCIWFIRSTPRIV + 0xA,
3657 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "channel_plan"
3661 SIOCIWFIRSTPRIV + 0xB,
3662 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "dbg"
3665 SIOCIWFIRSTPRIV + 0xC,
3666 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 3, 0, "rfw"
3669 SIOCIWFIRSTPRIV + 0xD,
3670 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "rfr"
3673 SIOCIWFIRSTPRIV + 0x10,
3674 IW_PRIV_TYPE_CHAR | P2P_PRIVATE_IOCTL_SET_LEN, 0, "p2p_set"
3677 SIOCIWFIRSTPRIV + 0x11,
3678 IW_PRIV_TYPE_CHAR | P2P_PRIVATE_IOCTL_SET_LEN, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | P2P_PRIVATE_IOCTL_SET_LEN, "p2p_get"
3681 SIOCIWFIRSTPRIV + 0x12,
3682 IW_PRIV_TYPE_CHAR | P2P_PRIVATE_IOCTL_SET_LEN, IW_PRIV_TYPE_CHAR | IFNAMSIZ, "p2p_get2"
3685 SIOCIWFIRSTPRIV + 0x16,
3686 IW_PRIV_TYPE_CHAR | 64, 0, "pm_set"
3689 {SIOCIWFIRSTPRIV + 0x18, IW_PRIV_TYPE_CHAR | IFNAMSIZ, 0, "rereg_nd_name"},
3692 static iw_handler rtw_private_handler[] = {
3697 /* for MM DTV platform */
3698 rtw_get_ap_info, /* 0x04 */
3700 rtw_set_pid, /* 0x05 */
3701 rtw_wps_start, /* 0x06 */
3707 /* Set Channel depend on the country code */
3708 rtw_wx_set_channel_plan, /* 0x0A */
3710 rtw_dbg_port, /* 0x0B */
3711 rtw_wx_write_rf, /* 0x0C */
3712 rtw_wx_read_rf, /* 0x0D */
3716 rtw_p2p_set, /* 0x10 */
3718 rtw_p2p_get2, /* 0x12 */
3724 rtw_pm_set, /* 0x16 */
3726 rtw_rereg_nd_name, /* 0x18 */
3729 static struct iw_statistics *rtw_get_wireless_stats(struct net_device *dev)
3731 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
3732 struct iw_statistics *piwstats = &padapter->iwstats;
3736 if (!check_fwstate(&padapter->mlmepriv, _FW_LINKED)) {
3737 piwstats->qual.qual = 0;
3738 piwstats->qual.level = 0;
3739 piwstats->qual.noise = 0;
3741 tmp_noise = padapter->recvpriv.noise;
3743 piwstats->qual.level = padapter->signal_strength;
3744 tmp = 219 + 3 * padapter->signal_strength;
3745 tmp = min(100, tmp);
3747 piwstats->qual.qual = tmp;
3748 piwstats->qual.noise = tmp_noise;
3750 piwstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
3751 return &padapter->iwstats;
3754 struct iw_handler_def rtw_handlers_def = {
3755 .standard = rtw_handlers,
3756 .num_standard = ARRAY_SIZE(rtw_handlers),
3757 .private = rtw_private_handler,
3758 .private_args = (struct iw_priv_args *)rtw_private_args,
3759 .num_private = ARRAY_SIZE(rtw_private_handler),
3760 .num_private_args = ARRAY_SIZE(rtw_private_args),
3761 .get_wireless_stats = rtw_get_wireless_stats,