1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3 * rtl871x_ioctl_linux.c
5 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
6 * Linux device driver for RTL8192SU
8 * Modifications for inclusion into the Linux staging tree are
9 * Copyright(c) 2010 Larry Finger. All rights reserved.
11 * Contact information:
12 * WLAN FAE <wlanfae@realtek.com>
13 * Larry Finger <Larry.Finger@lwfinger.net>
15 ******************************************************************************/
17 #define _RTL871X_IOCTL_LINUX_C_
18 #define _RTL871X_MP_IOCTL_C_
20 #include "osdep_service.h"
21 #include "drv_types.h"
22 #include "wlan_bssdef.h"
23 #include "rtl871x_debug.h"
25 #include "rtl871x_mlme.h"
26 #include "rtl871x_ioctl.h"
27 #include "rtl871x_ioctl_set.h"
28 #include "rtl871x_mp_ioctl.h"
29 #include "mlme_osdep.h"
30 #include <linux/wireless.h>
31 #include <linux/module.h>
32 #include <linux/kernel.h>
34 #include <linux/semaphore.h>
35 #include <net/iw_handler.h>
36 #include <linux/if_arp.h>
37 #include <linux/etherdevice.h>
40 #define RTL_IOCTL_WPA_SUPPLICANT (SIOCIWFIRSTPRIV + 0x1E)
42 #define SCAN_ITEM_SIZE 768
43 #define MAX_CUSTOM_LEN 64
47 static const u32 rtl8180_rates[] = {1000000, 2000000, 5500000, 11000000,
48 6000000, 9000000, 12000000, 18000000,
49 24000000, 36000000, 48000000, 54000000};
51 static const long ieee80211_wlan_frequencies[] = {
52 2412, 2417, 2422, 2427,
53 2432, 2437, 2442, 2447,
54 2452, 2457, 2462, 2467,
58 void r8712_indicate_wx_assoc_event(struct _adapter *padapter)
60 union iwreq_data wrqu;
61 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
63 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
64 memcpy(wrqu.ap_addr.sa_data, pmlmepriv->cur_network.network.MacAddress,
66 wireless_send_event(padapter->pnetdev, SIOCGIWAP, &wrqu, NULL);
69 void r8712_indicate_wx_disassoc_event(struct _adapter *padapter)
71 union iwreq_data wrqu;
73 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
74 eth_zero_addr(wrqu.ap_addr.sa_data);
75 wireless_send_event(padapter->pnetdev, SIOCGIWAP, &wrqu, NULL);
78 static inline void handle_pairwise_key(struct sta_info *psta,
79 struct ieee_param *param,
80 struct _adapter *padapter)
83 memcpy(psta->x_UncstKey.skey, param->u.crypt.key,
84 (param->u.crypt. key_len > 16 ? 16 : param->u.crypt.key_len));
85 if (strcmp(param->u.crypt.alg, "TKIP") == 0) { /* set mic key */
86 memcpy(psta->tkiptxmickey. skey,
87 &(param->u.crypt.key[16]), 8);
88 memcpy(psta->tkiprxmickey. skey,
89 &(param->u.crypt.key[24]), 8);
90 padapter->securitypriv. busetkipkey = false;
91 mod_timer(&padapter->securitypriv.tkip_timer,
92 jiffies + msecs_to_jiffies(50));
94 r8712_setstakey_cmd(padapter, (unsigned char *)psta, true);
97 static inline void handle_group_key(struct ieee_param *param,
98 struct _adapter *padapter)
100 union Keytype *gk = padapter->securitypriv.XGrpKey;
101 union Keytype *gtk = padapter->securitypriv.XGrptxmickey;
102 union Keytype *grk = padapter->securitypriv.XGrprxmickey;
104 if (param->u.crypt.idx > 0 &&
105 param->u.crypt.idx < 3) {
106 /* group key idx is 1 or 2 */
107 memcpy(gk[param->u.crypt.idx - 1].skey,
109 (param->u.crypt.key_len > 16 ? 16 :
110 param->u.crypt.key_len));
111 memcpy(gtk[param->u.crypt.idx - 1].skey,
112 ¶m->u.crypt.key[16], 8);
113 memcpy(grk[param->u.crypt.idx - 1].skey,
114 ¶m->u.crypt.key[24], 8);
115 padapter->securitypriv.binstallGrpkey = true;
116 r8712_set_key(padapter, &padapter->securitypriv,
118 if (padapter->registrypriv.power_mgnt > PS_MODE_ACTIVE) {
119 if (padapter->registrypriv.power_mgnt !=
120 padapter->pwrctrlpriv.pwr_mode)
121 mod_timer(&padapter->mlmepriv.dhcp_timer,
122 jiffies + msecs_to_jiffies(60000));
127 static noinline_for_stack char *translate_scan_wpa(struct iw_request_info *info,
128 struct wlan_network *pnetwork,
129 struct iw_event *iwe,
130 char *start, char *stop)
132 /* parsing WPA/WPA2 IE */
133 u8 buf[MAX_WPA_IE_LEN];
134 u8 wpa_ie[255], rsn_ie[255];
135 u16 wpa_len = 0, rsn_len = 0;
138 r8712_get_sec_ie(pnetwork->network.IEs,
139 pnetwork->network.IELength, rsn_ie, &rsn_len,
142 memset(buf, 0, MAX_WPA_IE_LEN);
143 n = sprintf(buf, "wpa_ie=");
144 for (i = 0; i < wpa_len; i++) {
145 n += scnprintf(buf + n, MAX_WPA_IE_LEN - n,
147 if (n == MAX_WPA_IE_LEN-1)
150 memset(iwe, 0, sizeof(*iwe));
151 iwe->cmd = IWEVCUSTOM;
152 iwe->u.data.length = (u16)strlen(buf);
153 start = iwe_stream_add_point(info, start, stop,
155 memset(iwe, 0, sizeof(*iwe));
156 iwe->cmd = IWEVGENIE;
157 iwe->u.data.length = (u16)wpa_len;
158 start = iwe_stream_add_point(info, start, stop,
162 memset(buf, 0, MAX_WPA_IE_LEN);
163 n = sprintf(buf, "rsn_ie=");
164 for (i = 0; i < rsn_len; i++) {
165 n += scnprintf(buf + n, MAX_WPA_IE_LEN - n,
167 if (n == MAX_WPA_IE_LEN-1)
170 memset(iwe, 0, sizeof(*iwe));
171 iwe->cmd = IWEVCUSTOM;
172 iwe->u.data.length = strlen(buf);
173 start = iwe_stream_add_point(info, start, stop,
175 memset(iwe, 0, sizeof(*iwe));
176 iwe->cmd = IWEVGENIE;
177 iwe->u.data.length = rsn_len;
178 start = iwe_stream_add_point(info, start, stop, iwe,
185 static noinline_for_stack char *translate_scan_wps(struct iw_request_info *info,
186 struct wlan_network *pnetwork,
187 struct iw_event *iwe,
188 char *start, char *stop)
194 if (r8712_get_wps_ie(pnetwork->network.IEs,
195 pnetwork->network.IELength,
196 wps_ie, &wps_ielen)) {
198 iwe->cmd = IWEVGENIE;
199 iwe->u.data.length = (u16)wps_ielen;
200 start = iwe_stream_add_point(info, start, stop,
208 static char *translate_scan(struct _adapter *padapter,
209 struct iw_request_info *info,
210 struct wlan_network *pnetwork,
211 char *start, char *stop)
216 u32 i = 0, ht_ielen = 0;
217 u16 cap, ht_cap = false;
220 if ((pnetwork->network.Configuration.DSConfig < 1) ||
221 (pnetwork->network.Configuration.DSConfig > 14)) {
222 if (pnetwork->network.Configuration.DSConfig < 1)
223 pnetwork->network.Configuration.DSConfig = 1;
225 pnetwork->network.Configuration.DSConfig = 14;
229 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
230 ether_addr_copy(iwe.u.ap_addr.sa_data, pnetwork->network.MacAddress);
231 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_ADDR_LEN);
233 iwe.cmd = SIOCGIWESSID;
234 iwe.u.data.flags = 1;
235 iwe.u.data.length = min_t(u32, pnetwork->network.Ssid.SsidLength, 32);
236 start = iwe_stream_add_point(info, start, stop, &iwe,
237 pnetwork->network.Ssid.Ssid);
238 /* parsing HT_CAP_IE */
239 p = r8712_get_ie(&pnetwork->network.IEs[12], _HT_CAPABILITY_IE_,
240 &ht_ielen, pnetwork->network.IELength - 12);
241 if (p && ht_ielen > 0)
243 /* Add the protocol name */
244 iwe.cmd = SIOCGIWNAME;
245 if (r8712_is_cckratesonly_included(pnetwork->network.rates)) {
247 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bn");
249 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11b");
250 } else if (r8712_is_cckrates_included(pnetwork->network.rates)) {
252 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bgn");
254 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bg");
257 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11gn");
259 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11g");
261 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_CHAR_LEN);
263 iwe.cmd = SIOCGIWMODE;
264 memcpy((u8 *)&cap, r8712_get_capability_from_ie(pnetwork->network.IEs),
267 if (cap & (WLAN_CAPABILITY_IBSS | WLAN_CAPABILITY_ESS)) {
268 if (cap & WLAN_CAPABILITY_ESS)
269 iwe.u.mode = (u32)IW_MODE_MASTER;
271 iwe.u.mode = (u32)IW_MODE_ADHOC;
272 start = iwe_stream_add_event(info, start, stop, &iwe,
275 /* Add frequency/channel */
276 iwe.cmd = SIOCGIWFREQ;
278 /* check legal index */
279 u8 dsconfig = pnetwork->network.Configuration.DSConfig;
281 if (dsconfig >= 1 && dsconfig <= sizeof(
282 ieee80211_wlan_frequencies) / sizeof(long))
284 (s32)(ieee80211_wlan_frequencies
285 [dsconfig - 1] * 100000);
289 iwe.u.freq.e = (s16)1;
290 iwe.u.freq.i = (u8)pnetwork->network.Configuration.DSConfig;
291 start = iwe_stream_add_event(info, start, stop, &iwe,
293 /* Add encryption capability */
294 iwe.cmd = SIOCGIWENCODE;
295 if (cap & WLAN_CAPABILITY_PRIVACY)
296 iwe.u.data.flags = (u16)(IW_ENCODE_ENABLED |
299 iwe.u.data.flags = (u16)(IW_ENCODE_DISABLED);
300 iwe.u.data.length = (u16)0;
301 start = iwe_stream_add_point(info, start, stop, &iwe,
302 pnetwork->network.Ssid.Ssid);
303 /*Add basic and extended rates */
304 current_val = start + iwe_stream_lcp_len(info);
305 iwe.cmd = SIOCGIWRATE;
306 iwe.u.bitrate.fixed = 0;
307 iwe.u.bitrate.disabled = 0;
308 iwe.u.bitrate.value = 0;
310 while (pnetwork->network.rates[i] != 0) {
311 /* Bit rate given in 500 kb/s units */
312 iwe.u.bitrate.value = (pnetwork->network.rates[i++] &
314 current_val = iwe_stream_add_value(info, start, current_val,
315 stop, &iwe, IW_EV_PARAM_LEN);
317 /* Check if we added any event */
318 if ((current_val - start) > iwe_stream_lcp_len(info))
321 start = translate_scan_wpa(info, pnetwork, &iwe, start, stop);
323 start = translate_scan_wps(info, pnetwork, &iwe, start, stop);
325 /* Add quality statistics */
327 rssi = r8712_signal_scale_mapping(pnetwork->network.Rssi);
328 /* we only update signal_level (signal strength) that is rssi. */
329 iwe.u.qual.updated = (u8)(IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_UPDATED |
330 IW_QUAL_NOISE_INVALID);
331 iwe.u.qual.level = rssi; /* signal strength */
332 iwe.u.qual.qual = 0; /* signal quality */
333 iwe.u.qual.noise = 0; /* noise level */
334 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_QUAL_LEN);
335 /* how to translate rssi to ?% */
339 static int wpa_set_auth_algs(struct net_device *dev, u32 value)
341 struct _adapter *padapter = netdev_priv(dev);
344 if ((value & AUTH_ALG_SHARED_KEY) && (value & AUTH_ALG_OPEN_SYSTEM)) {
345 padapter->securitypriv.ndisencryptstatus =
346 Ndis802_11Encryption1Enabled;
347 padapter->securitypriv.ndisauthtype =
348 Ndis802_11AuthModeAutoSwitch;
349 padapter->securitypriv.AuthAlgrthm = 3;
350 } else if (value & AUTH_ALG_SHARED_KEY) {
351 padapter->securitypriv.ndisencryptstatus =
352 Ndis802_11Encryption1Enabled;
353 padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeShared;
354 padapter->securitypriv.AuthAlgrthm = 1;
355 } else if (value & AUTH_ALG_OPEN_SYSTEM) {
356 if (padapter->securitypriv.ndisauthtype <
357 Ndis802_11AuthModeWPAPSK) {
358 padapter->securitypriv.ndisauthtype =
359 Ndis802_11AuthModeOpen;
360 padapter->securitypriv.AuthAlgrthm = 0;
368 static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
372 u32 wep_key_idx, wep_key_len = 0;
373 struct NDIS_802_11_WEP *pwep = NULL;
374 struct _adapter *padapter = netdev_priv(dev);
375 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
376 struct security_priv *psecuritypriv = &padapter->securitypriv;
378 param->u.crypt.err = 0;
379 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
380 if (param_len != (u32)((u8 *) param->u.crypt.key - (u8 *)param) +
381 param->u.crypt.key_len)
383 if (!is_broadcast_ether_addr(param->sta_addr))
386 if (param->u.crypt.idx >= WEP_KEYS) {
387 /* for large key indices, set the default (0) */
388 param->u.crypt.idx = 0;
390 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
391 netdev_info(dev, "r8712u: %s: crypt.alg = WEP\n", __func__);
392 padapter->securitypriv.ndisencryptstatus =
393 Ndis802_11Encryption1Enabled;
394 padapter->securitypriv.PrivacyAlgrthm = _WEP40_;
395 padapter->securitypriv.XGrpPrivacy = _WEP40_;
396 wep_key_idx = param->u.crypt.idx;
397 wep_key_len = param->u.crypt.key_len;
398 if (wep_key_idx >= WEP_KEYS)
400 if (wep_key_len <= 0)
403 wep_key_len = wep_key_len <= 5 ? 5 : 13;
404 pwep = kzalloc(sizeof(*pwep), GFP_ATOMIC);
407 pwep->KeyLength = wep_key_len;
408 pwep->Length = wep_key_len +
409 offsetof(struct NDIS_802_11_WEP, KeyMaterial);
410 if (wep_key_len == 13) {
411 padapter->securitypriv.PrivacyAlgrthm = _WEP104_;
412 padapter->securitypriv.XGrpPrivacy = _WEP104_;
414 pwep->KeyIndex = wep_key_idx;
415 pwep->KeyIndex |= 0x80000000;
416 memcpy(pwep->KeyMaterial, param->u.crypt.key, pwep->KeyLength);
417 if (param->u.crypt.set_tx) {
418 if (r8712_set_802_11_add_wep(padapter, pwep))
421 /* don't update "psecuritypriv->PrivacyAlgrthm" and
422 * "psecuritypriv->PrivacyKeyIndex=keyid", but can
423 * r8712_set_key to fw/cam
425 if (wep_key_idx >= WEP_KEYS) {
429 memcpy(&psecuritypriv->DefKey[wep_key_idx].skey[0],
432 psecuritypriv->DefKeylen[wep_key_idx] =
434 r8712_set_key(padapter, psecuritypriv, wep_key_idx);
438 if (padapter->securitypriv.AuthAlgrthm == 2) { /* 802_1x */
439 struct sta_info *psta, *pbcmc_sta;
440 struct sta_priv *pstapriv = &padapter->stapriv;
441 struct security_priv *spriv = &padapter->securitypriv;
443 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE |
444 WIFI_MP_STATE)) { /* sta mode */
445 psta = r8712_get_stainfo(pstapriv,
446 get_bssid(pmlmepriv));
448 psta->ieee8021x_blocked = false;
449 if (spriv->ndisencryptstatus ==
450 Ndis802_11Encryption2Enabled ||
451 spriv->ndisencryptstatus ==
452 Ndis802_11Encryption3Enabled)
453 psta->XPrivacy = spriv->PrivacyAlgrthm;
454 if (param->u.crypt.set_tx == 1)
455 handle_pairwise_key(psta, param,
458 handle_group_key(param, padapter);
460 pbcmc_sta = r8712_get_bcmc_stainfo(padapter);
462 pbcmc_sta->ieee8021x_blocked = false;
463 if (spriv->ndisencryptstatus ==
464 Ndis802_11Encryption2Enabled ||
465 spriv->ndisencryptstatus ==
466 Ndis802_11Encryption3Enabled)
467 pbcmc_sta->XPrivacy =
468 spriv->PrivacyAlgrthm;
477 static int r871x_set_wpa_ie(struct _adapter *padapter, char *pie,
478 unsigned short ielen)
481 int group_cipher = 0, pairwise_cipher = 0;
484 if (ielen > MAX_WPA_IE_LEN || !pie)
487 buf = kmemdup(pie, ielen, GFP_ATOMIC);
490 if (ielen < RSN_HEADER_LEN) {
494 if (r8712_parse_wpa_ie(buf, ielen, &group_cipher,
495 &pairwise_cipher) == 0) {
496 padapter->securitypriv.AuthAlgrthm = 2;
497 padapter->securitypriv.ndisauthtype =
498 Ndis802_11AuthModeWPAPSK;
500 if (r8712_parse_wpa2_ie(buf, ielen, &group_cipher,
501 &pairwise_cipher) == 0) {
502 padapter->securitypriv.AuthAlgrthm = 2;
503 padapter->securitypriv.ndisauthtype =
504 Ndis802_11AuthModeWPA2PSK;
506 switch (group_cipher) {
507 case WPA_CIPHER_NONE:
508 padapter->securitypriv.XGrpPrivacy =
510 padapter->securitypriv.ndisencryptstatus =
511 Ndis802_11EncryptionDisabled;
513 case WPA_CIPHER_WEP40:
514 padapter->securitypriv.XGrpPrivacy = _WEP40_;
515 padapter->securitypriv.ndisencryptstatus =
516 Ndis802_11Encryption1Enabled;
518 case WPA_CIPHER_TKIP:
519 padapter->securitypriv.XGrpPrivacy = _TKIP_;
520 padapter->securitypriv.ndisencryptstatus =
521 Ndis802_11Encryption2Enabled;
523 case WPA_CIPHER_CCMP:
524 padapter->securitypriv.XGrpPrivacy = _AES_;
525 padapter->securitypriv.ndisencryptstatus =
526 Ndis802_11Encryption3Enabled;
528 case WPA_CIPHER_WEP104:
529 padapter->securitypriv.XGrpPrivacy = _WEP104_;
530 padapter->securitypriv.ndisencryptstatus =
531 Ndis802_11Encryption1Enabled;
534 switch (pairwise_cipher) {
535 case WPA_CIPHER_NONE:
536 padapter->securitypriv.PrivacyAlgrthm =
538 padapter->securitypriv.ndisencryptstatus =
539 Ndis802_11EncryptionDisabled;
541 case WPA_CIPHER_WEP40:
542 padapter->securitypriv.PrivacyAlgrthm = _WEP40_;
543 padapter->securitypriv.ndisencryptstatus =
544 Ndis802_11Encryption1Enabled;
546 case WPA_CIPHER_TKIP:
547 padapter->securitypriv.PrivacyAlgrthm = _TKIP_;
548 padapter->securitypriv.ndisencryptstatus =
549 Ndis802_11Encryption2Enabled;
551 case WPA_CIPHER_CCMP:
552 padapter->securitypriv.PrivacyAlgrthm = _AES_;
553 padapter->securitypriv.ndisencryptstatus =
554 Ndis802_11Encryption3Enabled;
556 case WPA_CIPHER_WEP104:
557 padapter->securitypriv.PrivacyAlgrthm = _WEP104_;
558 padapter->securitypriv.ndisencryptstatus =
559 Ndis802_11Encryption1Enabled;
562 padapter->securitypriv.wps_phase = false;
565 u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04};
567 while (cnt < ielen) {
570 if ((eid == _VENDOR_SPECIFIC_IE_) &&
571 (!memcmp(&buf[cnt + 2], wps_oui, 4))) {
572 netdev_info(padapter->pnetdev, "r8712u: SET WPS_IE\n");
573 padapter->securitypriv.wps_ie_len =
574 ((buf[cnt + 1] + 2) <
575 (MAX_WPA_IE_LEN << 2)) ?
577 (MAX_WPA_IE_LEN << 2);
578 memcpy(padapter->securitypriv.wps_ie,
580 padapter->securitypriv.wps_ie_len);
581 padapter->securitypriv.wps_phase =
583 netdev_info(padapter->pnetdev, "r8712u: SET WPS_IE, wps_phase==true\n");
584 cnt += buf[cnt + 1] + 2;
588 cnt += buf[cnt + 1] + 2;
597 static int r8711_wx_get_name(struct net_device *dev,
598 struct iw_request_info *info,
599 union iwreq_data *wrqu, char *extra)
601 struct _adapter *padapter = netdev_priv(dev);
605 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
606 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
609 if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE) ==
611 /* parsing HT_CAP_IE */
612 p = r8712_get_ie(&pcur_bss->IEs[12], _HT_CAPABILITY_IE_,
613 &ht_ielen, pcur_bss->IELength - 12);
614 if (p && ht_ielen > 0)
616 prates = pcur_bss->rates;
617 if (r8712_is_cckratesonly_included(prates)) {
619 snprintf(wrqu->name, IFNAMSIZ,
622 snprintf(wrqu->name, IFNAMSIZ,
624 } else if (r8712_is_cckrates_included(prates)) {
626 snprintf(wrqu->name, IFNAMSIZ,
629 snprintf(wrqu->name, IFNAMSIZ,
633 snprintf(wrqu->name, IFNAMSIZ,
636 snprintf(wrqu->name, IFNAMSIZ,
640 snprintf(wrqu->name, IFNAMSIZ, "unassociated");
645 static const long frequency_list[] = {
646 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462,
647 2467, 2472, 2484, 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
648 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210,
649 5220, 5230, 5240, 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560,
650 5580, 5600, 5620, 5640, 5660, 5680, 5700, 5745, 5765, 5785, 5805,
654 static int r8711_wx_set_freq(struct net_device *dev,
655 struct iw_request_info *info,
656 union iwreq_data *wrqu, char *extra)
658 struct _adapter *padapter = netdev_priv(dev);
659 struct iw_freq *fwrq = &wrqu->freq;
662 /* If setting by frequency, convert to a channel */
663 if ((fwrq->e == 1) &&
664 (fwrq->m >= (int) 2.412e8) &&
665 (fwrq->m <= (int) 2.487e8)) {
666 int f = fwrq->m / 100000;
669 while ((c < 14) && (f != frequency_list[c]))
674 /* Setting by channel number */
675 if ((fwrq->m > 14) || (fwrq->e > 0)) {
678 int channel = fwrq->m;
680 if ((channel < 1) || (channel > 14)) {
683 /* Yes ! We can set it !!! */
684 padapter->registrypriv.channel = channel;
690 static int r8711_wx_get_freq(struct net_device *dev,
691 struct iw_request_info *info,
692 union iwreq_data *wrqu, char *extra)
694 struct _adapter *padapter = netdev_priv(dev);
695 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
696 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
698 if (!check_fwstate(pmlmepriv, _FW_LINKED))
701 wrqu->freq.m = ieee80211_wlan_frequencies[
702 pcur_bss->Configuration.DSConfig - 1] * 100000;
704 wrqu->freq.i = pcur_bss->Configuration.DSConfig;
709 static int r8711_wx_set_mode(struct net_device *dev,
710 struct iw_request_info *a,
711 union iwreq_data *wrqu, char *b)
713 struct _adapter *padapter = netdev_priv(dev);
714 enum NDIS_802_11_NETWORK_INFRASTRUCTURE networkType;
716 switch (wrqu->mode) {
718 networkType = Ndis802_11AutoUnknown;
721 networkType = Ndis802_11IBSS;
724 networkType = Ndis802_11APMode;
727 networkType = Ndis802_11Infrastructure;
732 if (Ndis802_11APMode == networkType)
733 r8712_setopmode_cmd(padapter, networkType);
735 r8712_setopmode_cmd(padapter, Ndis802_11AutoUnknown);
737 r8712_set_802_11_infrastructure_mode(padapter, networkType);
741 static int r8711_wx_get_mode(struct net_device *dev, struct iw_request_info *a,
742 union iwreq_data *wrqu, char *b)
744 struct _adapter *padapter = netdev_priv(dev);
745 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
747 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
748 wrqu->mode = IW_MODE_INFRA;
749 else if (check_fwstate(pmlmepriv,
750 WIFI_ADHOC_MASTER_STATE | WIFI_ADHOC_STATE))
751 wrqu->mode = IW_MODE_ADHOC;
752 else if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
753 wrqu->mode = IW_MODE_MASTER;
755 wrqu->mode = IW_MODE_AUTO;
759 static int r871x_wx_set_pmkid(struct net_device *dev,
760 struct iw_request_info *a,
761 union iwreq_data *wrqu, char *extra)
763 struct _adapter *padapter = netdev_priv(dev);
764 struct security_priv *psecuritypriv = &padapter->securitypriv;
765 struct iw_pmksa *pPMK = (struct iw_pmksa *) extra;
766 struct RT_PMKID_LIST *pl = psecuritypriv->PMKIDList;
767 u8 strZeroMacAddress[ETH_ALEN] = {0x00};
768 u8 strIssueBssid[ETH_ALEN] = {0x00};
769 u8 j, blInserted = false;
770 int intReturn = false;
773 * There are the BSSID information in the bssid.sa_data array.
774 * If cmd is IW_PMKSA_FLUSH, it means the wpa_supplicant wants to clear
775 * all the PMKID information. If cmd is IW_PMKSA_ADD, it means the
776 * wpa_supplicant wants to add a PMKID/BSSID to driver.
777 * If cmd is IW_PMKSA_REMOVE, it means the wpa_supplicant wants to
778 * remove a PMKID/BSSID from driver.
782 memcpy(strIssueBssid, pPMK->bssid.sa_data, ETH_ALEN);
785 if (!memcmp(strIssueBssid, strZeroMacAddress, ETH_ALEN))
789 /* overwrite PMKID */
790 for (j = 0; j < NUM_PMKID_CACHE; j++) {
791 if (!memcmp(pl[j].Bssid, strIssueBssid, ETH_ALEN)) {
792 /* BSSID is matched, the same AP => rewrite
795 netdev_info(dev, "r8712u: %s: BSSID exists in the PMKList.\n",
797 memcpy(pl[j].PMKID, pPMK->pmkid, IW_PMKID_LEN);
799 psecuritypriv->PMKIDIndex = j + 1;
805 /* Find a new entry */
806 netdev_info(dev, "r8712u: %s: Use the new entry index = %d for this PMKID.\n",
807 __func__, psecuritypriv->PMKIDIndex);
808 memcpy(pl[psecuritypriv->PMKIDIndex].Bssid,
809 strIssueBssid, ETH_ALEN);
810 memcpy(pl[psecuritypriv->PMKIDIndex].PMKID,
811 pPMK->pmkid, IW_PMKID_LEN);
812 pl[psecuritypriv->PMKIDIndex].bUsed = true;
813 psecuritypriv->PMKIDIndex++;
814 if (psecuritypriv->PMKIDIndex == NUM_PMKID_CACHE)
815 psecuritypriv->PMKIDIndex = 0;
818 case IW_PMKSA_REMOVE:
820 for (j = 0; j < NUM_PMKID_CACHE; j++) {
821 if (!memcmp(pl[j].Bssid, strIssueBssid, ETH_ALEN)) {
822 /* BSSID is matched, the same AP => Remove
823 * this PMKID information and reset it.
825 eth_zero_addr(pl[j].Bssid);
832 memset(psecuritypriv->PMKIDList, 0,
833 sizeof(struct RT_PMKID_LIST) * NUM_PMKID_CACHE);
834 psecuritypriv->PMKIDIndex = 0;
838 netdev_info(dev, "r8712u: %s: unknown Command\n", __func__);
845 static int r8711_wx_get_sens(struct net_device *dev,
846 struct iw_request_info *info,
847 union iwreq_data *wrqu, char *extra)
849 wrqu->sens.value = 0;
850 wrqu->sens.fixed = 0; /* no auto select */
851 wrqu->sens.disabled = 1;
855 static int r8711_wx_get_range(struct net_device *dev,
856 struct iw_request_info *info,
857 union iwreq_data *wrqu, char *extra)
859 struct iw_range *range = (struct iw_range *)extra;
863 wrqu->data.length = sizeof(*range);
864 memset(range, 0, sizeof(*range));
865 /* Let's try to keep this struct in the same order as in
866 * linux/include/wireless.h
869 /* TODO: See what values we can set, and remove the ones we can't
870 * set, or fill them with some default data.
872 /* ~5 Mb/s real (802.11b) */
873 range->throughput = 5 * 1000 * 1000;
874 /* TODO: 8711 sensitivity ? */
875 /* signal level threshold range */
876 /* percent values between 0 and 100. */
877 range->max_qual.qual = 100;
878 range->max_qual.level = 100;
879 range->max_qual.noise = 100;
880 range->max_qual.updated = 7; /* Updated all three */
881 range->avg_qual.qual = 92; /* > 8% missed beacons is 'bad' */
882 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
883 range->avg_qual.level = 0x100 - 78;
884 range->avg_qual.noise = 0;
885 range->avg_qual.updated = 7; /* Updated all three */
886 range->num_bitrates = RATE_COUNT;
887 for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++)
888 range->bitrate[i] = rtl8180_rates[i];
889 range->min_frag = MIN_FRAG_THRESHOLD;
890 range->max_frag = MAX_FRAG_THRESHOLD;
892 range->we_version_compiled = WIRELESS_EXT;
893 range->we_version_source = 16;
894 range->num_channels = 14;
895 for (i = 0, val = 0; i < 14; i++) {
896 /* Include only legal frequencies for some countries */
897 range->freq[val].i = i + 1;
898 range->freq[val].m = ieee80211_wlan_frequencies[i] * 100000;
899 range->freq[val].e = 1;
901 if (val == IW_MAX_FREQUENCIES)
904 range->num_frequency = val;
905 range->enc_capa = IW_ENC_CAPA_WPA |
907 IW_ENC_CAPA_CIPHER_TKIP |
908 IW_ENC_CAPA_CIPHER_CCMP;
912 static int r8711_wx_get_rate(struct net_device *dev,
913 struct iw_request_info *info,
914 union iwreq_data *wrqu, char *extra);
916 static int r871x_wx_set_priv(struct net_device *dev,
917 struct iw_request_info *info,
918 union iwreq_data *awrq,
921 int ret = 0, len = 0;
923 struct _adapter *padapter = netdev_priv(dev);
924 struct iw_point *dwrq = (struct iw_point *)awrq;
927 ext = memdup_user(dwrq->pointer, len);
931 if (!strcasecmp(ext, "RSSI")) {
932 /*Return received signal strength indicator in -db for */
935 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
936 struct wlan_network *pcur_network = &pmlmepriv->cur_network;
938 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
939 sprintf(ext, "%s rssi %d",
940 pcur_network->network.Ssid.Ssid,
942 ((padapter->recvpriv.fw_rssi) >> 1) - 95
943 /*pcur_network->network.Rssi */
948 } else if (!strcasecmp(ext, "LINKSPEED")) {
949 /*Return link speed in MBPS */
951 union iwreq_data wrqd;
955 ret_inner = r8711_wx_get_rate(dev, info, &wrqd, extra);
959 mbps = wrqd.bitrate.value / 1000000;
960 sprintf(ext, "LINKSPEED %d", mbps);
961 } else if (!strcasecmp(ext, "MACADDR")) {
962 /*Return mac address of the station */
963 /* Macaddr = xx:xx:xx:xx:xx:xx */
964 sprintf(ext, "MACADDR = %pM", dev->dev_addr);
965 } else if (!strcasecmp(ext, "SCAN-ACTIVE")) {
966 /*Set scan type to active */
967 /*OK if successful */
968 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
970 pmlmepriv->passive_mode = 1;
972 } else if (!strcasecmp(ext, "SCAN-PASSIVE")) {
973 /*Set scan type to passive */
974 /*OK if successful */
975 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
977 pmlmepriv->passive_mode = 0;
979 } else if (!strncmp(ext, "DCE-E", 5)) {
980 /*Set scan type to passive */
981 /*OK if successful */
982 r8712_disconnectCtrlEx_cmd(padapter
983 , 1 /*u32 enableDrvCtrl */
984 , 5 /*u32 tryPktCnt */
985 , 100 /*u32 tryPktInterval */
986 , 5000 /*u32 firstStageTO */
989 } else if (!strncmp(ext, "DCE-D", 5)) {
990 /*Set scan type to passive */
992 r8712_disconnectCtrlEx_cmd(padapter
993 , 0 /*u32 enableDrvCtrl */
994 , 5 /*u32 tryPktCnt */
995 , 100 /*u32 tryPktInterval */
996 , 5000 /*u32 firstStageTO */
1000 netdev_info(dev, "r8712u: %s: unknown Command %s.\n",
1004 if (copy_to_user(dwrq->pointer, ext,
1005 min(dwrq->length, (__u16)(strlen(ext) + 1))))
1014 * s1. set_802_11_infrastructure_mode()
1015 * s2. set_802_11_authentication_mode()
1016 * s3. set_802_11_encryption_mode()
1017 * s4. set_802_11_bssid()
1019 * This function intends to handle the Set AP command, which specifies the
1020 * MAC# of a preferred Access Point.
1021 * Currently, the request comes via Wireless Extensions' SIOCSIWAP ioctl.
1023 * For this operation to succeed, there is no need for the interface to be up.
1026 static int r8711_wx_set_wap(struct net_device *dev,
1027 struct iw_request_info *info,
1028 union iwreq_data *awrq,
1031 int ret = -EINPROGRESS;
1032 struct _adapter *padapter = netdev_priv(dev);
1033 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1034 struct __queue *queue = &pmlmepriv->scanned_queue;
1035 struct sockaddr *temp = (struct sockaddr *)awrq;
1037 struct list_head *phead;
1039 struct wlan_network *pnetwork = NULL;
1040 enum NDIS_802_11_AUTHENTICATION_MODE authmode;
1042 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
1044 if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
1046 if (temp->sa_family != ARPHRD_ETHER)
1048 authmode = padapter->securitypriv.ndisauthtype;
1049 spin_lock_irqsave(&queue->lock, irqL);
1050 phead = &queue->queue;
1051 pmlmepriv->pscanned = phead->next;
1053 if (end_of_queue_search(phead, pmlmepriv->pscanned))
1055 pnetwork = container_of(pmlmepriv->pscanned,
1056 struct wlan_network, list);
1057 pmlmepriv->pscanned = pmlmepriv->pscanned->next;
1058 dst_bssid = pnetwork->network.MacAddress;
1059 if (!memcmp(dst_bssid, temp->sa_data, ETH_ALEN)) {
1060 r8712_set_802_11_infrastructure_mode(padapter,
1061 pnetwork->network.InfrastructureMode);
1065 spin_unlock_irqrestore(&queue->lock, irqL);
1067 if (!r8712_set_802_11_authentication_mode(padapter, authmode)) {
1070 if (!r8712_set_802_11_bssid(padapter, temp->sa_data))
1077 static int r8711_wx_get_wap(struct net_device *dev,
1078 struct iw_request_info *info,
1079 union iwreq_data *wrqu, char *extra)
1081 struct _adapter *padapter = netdev_priv(dev);
1082 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1083 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
1085 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1086 if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE |
1088 ether_addr_copy(wrqu->ap_addr.sa_data, pcur_bss->MacAddress);
1090 eth_zero_addr(wrqu->ap_addr.sa_data);
1094 static int r871x_wx_set_mlme(struct net_device *dev,
1095 struct iw_request_info *info,
1096 union iwreq_data *wrqu, char *extra)
1099 struct _adapter *padapter = netdev_priv(dev);
1100 struct iw_mlme *mlme = (struct iw_mlme *) extra;
1104 switch (mlme->cmd) {
1105 case IW_MLME_DEAUTH:
1106 if (!r8712_set_802_11_disassociate(padapter))
1109 case IW_MLME_DISASSOC:
1110 if (!r8712_set_802_11_disassociate(padapter))
1121 * This function intends to handle the Set Scan command.
1122 * Currently, the request comes via Wireless Extensions' SIOCSIWSCAN ioctl.
1124 * For this operation to succeed, the interface is brought Up beforehand.
1127 static int r8711_wx_set_scan(struct net_device *dev,
1128 struct iw_request_info *a,
1129 union iwreq_data *wrqu, char *extra)
1131 struct _adapter *padapter = netdev_priv(dev);
1132 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1135 if (padapter->driver_stopped) {
1136 netdev_info(dev, "In %s: driver_stopped=%d\n",
1137 __func__, padapter->driver_stopped);
1142 if (!padapter->hw_init_completed)
1144 if ((check_fwstate(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING)) ||
1145 (pmlmepriv->sitesurveyctrl.traffic_busy))
1147 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
1148 struct iw_scan_req *req = (struct iw_scan_req *)extra;
1150 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1151 struct ndis_802_11_ssid ssid;
1153 u32 len = min_t(u8, req->essid_len, IW_ESSID_MAX_SIZE);
1155 memset((unsigned char *)&ssid, 0,
1156 sizeof(struct ndis_802_11_ssid));
1157 memcpy(ssid.Ssid, req->essid, len);
1158 ssid.SsidLength = len;
1159 spin_lock_irqsave(&pmlmepriv->lock, irqL);
1160 if ((check_fwstate(pmlmepriv, _FW_UNDER_SURVEY |
1161 _FW_UNDER_LINKING)) ||
1162 (pmlmepriv->sitesurveyctrl.traffic_busy)) {
1163 if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
1166 status = r8712_sitesurvey_cmd(padapter, &ssid);
1168 spin_unlock_irqrestore(&pmlmepriv->lock, irqL);
1171 status = r8712_set_802_11_bssid_list_scan(padapter);
1178 static int r8711_wx_get_scan(struct net_device *dev,
1179 struct iw_request_info *a,
1180 union iwreq_data *wrqu, char *extra)
1182 struct _adapter *padapter = netdev_priv(dev);
1183 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1184 struct __queue *queue = &pmlmepriv->scanned_queue;
1185 struct wlan_network *pnetwork = NULL;
1187 struct list_head *plist, *phead;
1189 char *stop = ev + wrqu->data.length;
1190 u32 ret = 0, cnt = 0;
1192 if (padapter->driver_stopped)
1194 while (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY |
1195 _FW_UNDER_LINKING)) {
1201 spin_lock_irqsave(&queue->lock, irqL);
1202 phead = &queue->queue;
1203 plist = phead->next;
1205 if (end_of_queue_search(phead, plist))
1207 if ((stop - ev) < SCAN_ITEM_SIZE) {
1211 pnetwork = container_of(plist, struct wlan_network, list);
1212 ev = translate_scan(padapter, a, pnetwork, ev, stop);
1213 plist = plist->next;
1215 spin_unlock_irqrestore(&queue->lock, irqL);
1216 wrqu->data.length = ev - extra;
1217 wrqu->data.flags = 0;
1222 * s1. set_802_11_infrastructure_mode()
1223 * s2. set_802_11_authenticaion_mode()
1224 * s3. set_802_11_encryption_mode()
1225 * s4. set_802_11_ssid()
1227 * This function intends to handle the Set ESSID command.
1228 * Currently, the request comes via the Wireless Extensions' SIOCSIWESSID ioctl.
1230 * For this operation to succeed, there is no need for the interface to be Up.
1233 static int r8711_wx_set_essid(struct net_device *dev,
1234 struct iw_request_info *a,
1235 union iwreq_data *wrqu, char *extra)
1237 struct _adapter *padapter = netdev_priv(dev);
1238 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1239 struct __queue *queue = &pmlmepriv->scanned_queue;
1240 struct wlan_network *pnetwork = NULL;
1241 enum NDIS_802_11_AUTHENTICATION_MODE authmode;
1242 struct ndis_802_11_ssid ndis_ssid;
1243 u8 *dst_ssid, *src_ssid;
1244 struct list_head *phead;
1247 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
1249 if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
1251 if (wrqu->essid.length > IW_ESSID_MAX_SIZE)
1253 authmode = padapter->securitypriv.ndisauthtype;
1254 if (wrqu->essid.flags && wrqu->essid.length) {
1255 len = (wrqu->essid.length < IW_ESSID_MAX_SIZE) ?
1256 wrqu->essid.length : IW_ESSID_MAX_SIZE;
1257 memset(&ndis_ssid, 0, sizeof(struct ndis_802_11_ssid));
1258 ndis_ssid.SsidLength = len;
1259 memcpy(ndis_ssid.Ssid, extra, len);
1260 src_ssid = ndis_ssid.Ssid;
1261 phead = &queue->queue;
1262 pmlmepriv->pscanned = phead->next;
1264 if (end_of_queue_search(phead, pmlmepriv->pscanned))
1266 pnetwork = container_of(pmlmepriv->pscanned,
1267 struct wlan_network, list);
1268 pmlmepriv->pscanned = pmlmepriv->pscanned->next;
1269 dst_ssid = pnetwork->network.Ssid.Ssid;
1270 if ((!memcmp(dst_ssid, src_ssid, ndis_ssid.SsidLength))
1271 && (pnetwork->network.Ssid.SsidLength ==
1272 ndis_ssid.SsidLength)) {
1273 if (check_fwstate(pmlmepriv,
1274 WIFI_ADHOC_STATE)) {
1275 if (pnetwork->network.
1279 cur_network.network.
1284 r8712_set_802_11_infrastructure_mode(
1286 pnetwork->network.InfrastructureMode);
1290 r8712_set_802_11_authentication_mode(padapter, authmode);
1291 r8712_set_802_11_ssid(padapter, &ndis_ssid);
1293 return -EINPROGRESS;
1296 static int r8711_wx_get_essid(struct net_device *dev,
1297 struct iw_request_info *a,
1298 union iwreq_data *wrqu, char *extra)
1300 struct _adapter *padapter = netdev_priv(dev);
1301 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1302 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
1305 if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE)) {
1306 len = pcur_bss->Ssid.SsidLength;
1307 wrqu->essid.length = len;
1308 memcpy(extra, pcur_bss->Ssid.Ssid, len);
1309 wrqu->essid.flags = 1;
1316 static int r8711_wx_set_rate(struct net_device *dev,
1317 struct iw_request_info *a,
1318 union iwreq_data *wrqu, char *extra)
1320 struct _adapter *padapter = netdev_priv(dev);
1321 u32 target_rate = wrqu->bitrate.value;
1322 u32 fixed = wrqu->bitrate.fixed;
1324 u8 datarates[NumRates];
1325 u8 mpdatarate[NumRates] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0xff};
1328 if (target_rate == -1) {
1332 target_rate = target_rate / 100000;
1333 switch (target_rate) {
1375 for (i = 0; i < NumRates; i++) {
1376 if (ratevalue == mpdatarate[i]) {
1377 datarates[i] = mpdatarate[i];
1381 datarates[i] = 0xff;
1384 return r8712_setdatarate_cmd(padapter, datarates);
1387 static int r8711_wx_get_rate(struct net_device *dev,
1388 struct iw_request_info *info,
1389 union iwreq_data *wrqu, char *extra)
1391 struct _adapter *padapter = netdev_priv(dev);
1392 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1393 struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
1394 struct rtl_ieee80211_ht_cap *pht_capie;
1395 unsigned char rf_type = padapter->registrypriv.rf_config;
1398 u16 rate, max_rate = 0, ht_cap = false;
1400 u8 bw_40MHz = 0, short_GI = 0;
1404 if (!check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE))
1406 p = r8712_get_ie(&pcur_bss->IEs[12], _HT_CAPABILITY_IE_, &ht_ielen,
1407 pcur_bss->IELength - 12);
1408 if (p && ht_ielen > 0) {
1410 pht_capie = (struct rtl_ieee80211_ht_cap *)(p + 2);
1411 memcpy(&mcs_rate, pht_capie->supp_mcs_set, 2);
1412 bw_40MHz = (le16_to_cpu(pht_capie->cap_info) &
1413 IEEE80211_HT_CAP_SUP_WIDTH_20_40) ? 1 : 0;
1414 short_GI = (le16_to_cpu(pht_capie->cap_info) &
1415 (IEEE80211_HT_CAP_SGI_20 |
1416 IEEE80211_HT_CAP_SGI_40)) ? 1 : 0;
1418 while ((pcur_bss->rates[i] != 0) &&
1419 (pcur_bss->rates[i] != 0xFF)) {
1420 rate = pcur_bss->rates[i] & 0x7F;
1421 if (rate > max_rate)
1423 wrqu->bitrate.fixed = 0; /* no auto select */
1424 wrqu->bitrate.value = rate * 500000;
1428 if (mcs_rate & 0x8000 /* MCS15 */
1430 rf_type == RTL8712_RF_2T2R)
1431 max_rate = (bw_40MHz) ? ((short_GI) ? 300 : 270) :
1432 ((short_GI) ? 144 : 130);
1433 else /* default MCS7 */
1434 max_rate = (bw_40MHz) ? ((short_GI) ? 150 : 135) :
1435 ((short_GI) ? 72 : 65);
1436 max_rate *= 2; /* Mbps/2 */
1438 wrqu->bitrate.value = max_rate * 500000;
1442 static int r8711_wx_get_rts(struct net_device *dev,
1443 struct iw_request_info *info,
1444 union iwreq_data *wrqu, char *extra)
1446 struct _adapter *padapter = netdev_priv(dev);
1448 wrqu->rts.value = padapter->registrypriv.rts_thresh;
1449 wrqu->rts.fixed = 0; /* no auto select */
1453 static int r8711_wx_set_frag(struct net_device *dev,
1454 struct iw_request_info *info,
1455 union iwreq_data *wrqu, char *extra)
1457 struct _adapter *padapter = netdev_priv(dev);
1459 if (wrqu->frag.disabled) {
1460 padapter->xmitpriv.frag_len = MAX_FRAG_THRESHOLD;
1462 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
1463 wrqu->frag.value > MAX_FRAG_THRESHOLD)
1465 padapter->xmitpriv.frag_len = wrqu->frag.value & ~0x1;
1470 static int r8711_wx_get_frag(struct net_device *dev,
1471 struct iw_request_info *info,
1472 union iwreq_data *wrqu, char *extra)
1474 struct _adapter *padapter = netdev_priv(dev);
1476 wrqu->frag.value = padapter->xmitpriv.frag_len;
1477 wrqu->frag.fixed = 0; /* no auto select */
1481 static int r8711_wx_get_retry(struct net_device *dev,
1482 struct iw_request_info *info,
1483 union iwreq_data *wrqu, char *extra)
1485 wrqu->retry.value = 7;
1486 wrqu->retry.fixed = 0; /* no auto select */
1487 wrqu->retry.disabled = 1;
1491 static int r8711_wx_set_enc(struct net_device *dev,
1492 struct iw_request_info *info,
1493 union iwreq_data *wrqu, char *keybuf)
1496 u32 keyindex_provided;
1497 struct NDIS_802_11_WEP wep;
1498 enum NDIS_802_11_AUTHENTICATION_MODE authmode;
1499 struct iw_point *erq = &(wrqu->encoding);
1500 struct _adapter *padapter = netdev_priv(dev);
1502 key = erq->flags & IW_ENCODE_INDEX;
1503 memset(&wep, 0, sizeof(struct NDIS_802_11_WEP));
1504 if (erq->flags & IW_ENCODE_DISABLED) {
1505 netdev_info(dev, "r8712u: %s: EncryptionDisabled\n", __func__);
1506 padapter->securitypriv.ndisencryptstatus =
1507 Ndis802_11EncryptionDisabled;
1508 padapter->securitypriv.PrivacyAlgrthm = _NO_PRIVACY_;
1509 padapter->securitypriv.XGrpPrivacy = _NO_PRIVACY_;
1510 padapter->securitypriv.AuthAlgrthm = 0; /* open system */
1511 authmode = Ndis802_11AuthModeOpen;
1512 padapter->securitypriv.ndisauthtype = authmode;
1519 keyindex_provided = 1;
1521 keyindex_provided = 0;
1522 key = padapter->securitypriv.PrivacyKeyIndex;
1524 /* set authentication mode */
1525 if (erq->flags & IW_ENCODE_OPEN) {
1526 netdev_info(dev, "r8712u: %s: IW_ENCODE_OPEN\n", __func__);
1527 padapter->securitypriv.ndisencryptstatus =
1528 Ndis802_11Encryption1Enabled;
1529 padapter->securitypriv.AuthAlgrthm = 0; /* open system */
1530 padapter->securitypriv.PrivacyAlgrthm = _NO_PRIVACY_;
1531 padapter->securitypriv.XGrpPrivacy = _NO_PRIVACY_;
1532 authmode = Ndis802_11AuthModeOpen;
1533 padapter->securitypriv.ndisauthtype = authmode;
1534 } else if (erq->flags & IW_ENCODE_RESTRICTED) {
1536 "r8712u: %s: IW_ENCODE_RESTRICTED\n", __func__);
1537 padapter->securitypriv.ndisencryptstatus =
1538 Ndis802_11Encryption1Enabled;
1539 padapter->securitypriv.AuthAlgrthm = 1; /* shared system */
1540 padapter->securitypriv.PrivacyAlgrthm = _WEP40_;
1541 padapter->securitypriv.XGrpPrivacy = _WEP40_;
1542 authmode = Ndis802_11AuthModeShared;
1543 padapter->securitypriv.ndisauthtype = authmode;
1545 padapter->securitypriv.ndisencryptstatus =
1546 Ndis802_11Encryption1Enabled;
1547 padapter->securitypriv.AuthAlgrthm = 0; /* open system */
1548 padapter->securitypriv.PrivacyAlgrthm = _NO_PRIVACY_;
1549 padapter->securitypriv.XGrpPrivacy = _NO_PRIVACY_;
1550 authmode = Ndis802_11AuthModeOpen;
1551 padapter->securitypriv.ndisauthtype = authmode;
1554 if (erq->length > 0) {
1555 wep.KeyLength = erq->length <= 5 ? 5 : 13;
1556 wep.Length = wep.KeyLength +
1557 offsetof(struct NDIS_802_11_WEP, KeyMaterial);
1560 if (keyindex_provided == 1) { /* set key_id only, no given
1561 * KeyMaterial(erq->length==0).
1563 padapter->securitypriv.PrivacyKeyIndex = key;
1564 switch (padapter->securitypriv.DefKeylen[key]) {
1566 padapter->securitypriv.PrivacyAlgrthm =
1570 padapter->securitypriv.PrivacyAlgrthm =
1574 padapter->securitypriv.PrivacyAlgrthm =
1581 wep.KeyIndex |= 0x80000000; /* transmit key */
1582 memcpy(wep.KeyMaterial, keybuf, wep.KeyLength);
1583 if (r8712_set_802_11_add_wep(padapter, &wep))
1588 static int r8711_wx_get_enc(struct net_device *dev,
1589 struct iw_request_info *info,
1590 union iwreq_data *wrqu, char *keybuf)
1593 struct _adapter *padapter = netdev_priv(dev);
1594 struct iw_point *erq = &(wrqu->encoding);
1595 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1596 union Keytype *dk = padapter->securitypriv.DefKey;
1598 if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
1599 if (!check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
1601 erq->flags |= IW_ENCODE_DISABLED;
1605 key = erq->flags & IW_ENCODE_INDEX;
1611 key = padapter->securitypriv.PrivacyKeyIndex;
1613 erq->flags = key + 1;
1614 switch (padapter->securitypriv.ndisencryptstatus) {
1615 case Ndis802_11EncryptionNotSupported:
1616 case Ndis802_11EncryptionDisabled:
1618 erq->flags |= IW_ENCODE_DISABLED;
1620 case Ndis802_11Encryption1Enabled:
1621 erq->length = padapter->securitypriv.DefKeylen[key];
1623 memcpy(keybuf, dk[key].skey,
1624 padapter->securitypriv.DefKeylen[key]);
1625 erq->flags |= IW_ENCODE_ENABLED;
1626 if (padapter->securitypriv.ndisauthtype ==
1627 Ndis802_11AuthModeOpen)
1628 erq->flags |= IW_ENCODE_OPEN;
1629 else if (padapter->securitypriv.ndisauthtype ==
1630 Ndis802_11AuthModeShared)
1631 erq->flags |= IW_ENCODE_RESTRICTED;
1634 erq->flags |= IW_ENCODE_DISABLED;
1637 case Ndis802_11Encryption2Enabled:
1638 case Ndis802_11Encryption3Enabled:
1640 erq->flags |= (IW_ENCODE_ENABLED | IW_ENCODE_OPEN |
1645 erq->flags |= IW_ENCODE_DISABLED;
1651 static int r8711_wx_get_power(struct net_device *dev,
1652 struct iw_request_info *info,
1653 union iwreq_data *wrqu, char *extra)
1655 wrqu->power.value = 0;
1656 wrqu->power.fixed = 0; /* no auto select */
1657 wrqu->power.disabled = 1;
1661 static int r871x_wx_set_gen_ie(struct net_device *dev,
1662 struct iw_request_info *info,
1663 union iwreq_data *wrqu, char *extra)
1665 struct _adapter *padapter = netdev_priv(dev);
1667 return r871x_set_wpa_ie(padapter, extra, wrqu->data.length);
1670 static int r871x_wx_set_auth(struct net_device *dev,
1671 struct iw_request_info *info,
1672 union iwreq_data *wrqu, char *extra)
1674 struct _adapter *padapter = netdev_priv(dev);
1675 struct iw_param *param = (struct iw_param *)&(wrqu->param);
1680 paramid = param->flags & IW_AUTH_INDEX;
1681 paramval = param->value;
1683 case IW_AUTH_WPA_VERSION:
1685 case IW_AUTH_CIPHER_PAIRWISE:
1687 case IW_AUTH_CIPHER_GROUP:
1689 case IW_AUTH_KEY_MGMT:
1691 * ??? does not use these parameters
1694 case IW_AUTH_TKIP_COUNTERMEASURES:
1696 /* wpa_supplicant is enabling tkip countermeasure. */
1697 padapter->securitypriv.btkip_countermeasure = true;
1699 /* wpa_supplicant is disabling tkip countermeasure. */
1700 padapter->securitypriv.btkip_countermeasure = false;
1703 case IW_AUTH_DROP_UNENCRYPTED:
1706 * wpa_supplicant calls set_wpa_enabled when the driver
1707 * is loaded and unloaded, regardless of if WPA is being
1708 * used. No other calls are made which can be used to
1709 * determine if encryption will be used or not prior to
1710 * association being expected. If encryption is not being
1711 * used, drop_unencrypted is set to false, else true -- we
1712 * can use this to determine if the CAP_PRIVACY_ON bit should
1715 if (padapter->securitypriv.ndisencryptstatus ==
1716 Ndis802_11Encryption1Enabled) {
1717 /* it means init value, or using wep,
1718 * ndisencryptstatus =
1719 * Ndis802_11Encryption1Enabled,
1720 * then it needn't reset it;
1726 padapter->securitypriv.ndisencryptstatus =
1727 Ndis802_11EncryptionDisabled;
1728 padapter->securitypriv.PrivacyAlgrthm =
1730 padapter->securitypriv.XGrpPrivacy =
1732 padapter->securitypriv.AuthAlgrthm = 0;
1733 padapter->securitypriv.ndisauthtype =
1734 Ndis802_11AuthModeOpen;
1737 case IW_AUTH_80211_AUTH_ALG:
1738 ret = wpa_set_auth_algs(dev, (u32)paramval);
1740 case IW_AUTH_WPA_ENABLED:
1742 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1744 case IW_AUTH_PRIVACY_INVOKED:
1753 static int r871x_wx_set_enc_ext(struct net_device *dev,
1754 struct iw_request_info *info,
1755 union iwreq_data *wrqu, char *extra)
1757 struct iw_point *pencoding = &wrqu->encoding;
1758 struct iw_encode_ext *pext = (struct iw_encode_ext *)extra;
1759 struct ieee_param *param = NULL;
1764 switch (pext->alg) {
1765 case IW_ENCODE_ALG_NONE:
1768 case IW_ENCODE_ALG_WEP:
1771 case IW_ENCODE_ALG_TKIP:
1774 case IW_ENCODE_ALG_CCMP:
1781 param_len = sizeof(struct ieee_param) + pext->key_len;
1782 param = kzalloc(param_len, GFP_ATOMIC);
1785 param->cmd = IEEE_CMD_SET_ENCRYPTION;
1786 eth_broadcast_addr(param->sta_addr);
1787 strscpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN);
1788 if (pext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
1789 param->u.crypt.set_tx = 0;
1790 if (pext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
1791 param->u.crypt.set_tx = 1;
1792 param->u.crypt.idx = (pencoding->flags & 0x00FF) - 1;
1793 if (pext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
1794 memcpy(param->u.crypt.seq, pext->rx_seq, 8);
1795 if (pext->key_len) {
1796 param->u.crypt.key_len = pext->key_len;
1797 memcpy(param + 1, pext + 1, pext->key_len);
1799 ret = wpa_set_encryption(dev, param, param_len);
1804 static int r871x_wx_get_nick(struct net_device *dev,
1805 struct iw_request_info *info,
1806 union iwreq_data *wrqu, char *extra)
1809 wrqu->data.length = 8;
1810 wrqu->data.flags = 1;
1811 memcpy(extra, "rtl_wifi", 8);
1816 static int r8711_wx_read32(struct net_device *dev,
1817 struct iw_request_info *info,
1818 union iwreq_data *wrqu, char *keybuf)
1820 struct _adapter *padapter = netdev_priv(dev);
1824 get_user(addr, (u32 __user *)wrqu->data.pointer);
1825 data32 = r8712_read32(padapter, addr);
1826 put_user(data32, (u32 __user *)wrqu->data.pointer);
1827 wrqu->data.length = (data32 & 0xffff0000) >> 16;
1828 wrqu->data.flags = data32 & 0xffff;
1829 get_user(addr, (u32 __user *)wrqu->data.pointer);
1833 static int r8711_wx_write32(struct net_device *dev,
1834 struct iw_request_info *info,
1835 union iwreq_data *wrqu, char *keybuf)
1837 struct _adapter *padapter = netdev_priv(dev);
1841 get_user(addr, (u32 __user *)wrqu->data.pointer);
1842 data32 = ((u32)wrqu->data.length << 16) | (u32)wrqu->data.flags;
1843 r8712_write32(padapter, addr, data32);
1847 static int dummy(struct net_device *dev,
1848 struct iw_request_info *a,
1849 union iwreq_data *wrqu, char *b)
1854 static int r8711_drvext_hdl(struct net_device *dev,
1855 struct iw_request_info *info,
1856 union iwreq_data *wrqu, char *extra)
1861 static int r871x_mp_ioctl_hdl(struct net_device *dev,
1862 struct iw_request_info *info,
1863 union iwreq_data *wrqu, char *extra)
1865 struct _adapter *padapter = netdev_priv(dev);
1866 struct iw_point *p = &wrqu->data;
1867 struct oid_par_priv oid_par;
1868 struct mp_ioctl_handler *phandler;
1869 struct mp_ioctl_param *poidparam;
1870 unsigned long BytesRead, BytesWritten, BytesNeeded;
1876 if ((!p->length) || (!p->pointer))
1879 bset = (u8)(p->flags & 0xFFFF);
1881 pparmbuf = memdup_user(p->pointer, len);
1882 if (IS_ERR(pparmbuf))
1883 return PTR_ERR(pparmbuf);
1885 poidparam = (struct mp_ioctl_param *)pparmbuf;
1886 if (poidparam->subcode >= MAX_MP_IOCTL_SUBCODE) {
1888 goto _r871x_mp_ioctl_hdl_exit;
1890 phandler = mp_ioctl_hdl + poidparam->subcode;
1891 if ((phandler->paramsize != 0) &&
1892 (poidparam->len < phandler->paramsize)) {
1894 goto _r871x_mp_ioctl_hdl_exit;
1896 if (phandler->oid == 0 && phandler->handler) {
1897 status = phandler->handler(&oid_par);
1898 } else if (phandler->handler) {
1899 oid_par.adapter_context = padapter;
1900 oid_par.oid = phandler->oid;
1901 oid_par.information_buf = poidparam->data;
1902 oid_par.information_buf_len = poidparam->len;
1907 oid_par.bytes_rw = &BytesRead;
1908 oid_par.bytes_needed = &BytesNeeded;
1909 oid_par.type_of_oid = SET_OID;
1911 oid_par.bytes_rw = &BytesWritten;
1912 oid_par.bytes_needed = &BytesNeeded;
1913 oid_par.type_of_oid = QUERY_OID;
1915 status = phandler->handler(&oid_par);
1916 /* todo:check status, BytesNeeded, etc. */
1918 netdev_info(dev, "r8712u: %s: err!, subcode=%d, oid=%d, handler=%p\n",
1919 __func__, poidparam->subcode, phandler->oid,
1922 goto _r871x_mp_ioctl_hdl_exit;
1924 if (bset == 0x00) { /* query info */
1925 if (copy_to_user(p->pointer, pparmbuf, len))
1930 goto _r871x_mp_ioctl_hdl_exit;
1932 _r871x_mp_ioctl_hdl_exit:
1937 static int r871x_get_ap_info(struct net_device *dev,
1938 struct iw_request_info *info,
1939 union iwreq_data *wrqu, char *extra)
1941 struct _adapter *padapter = netdev_priv(dev);
1942 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1943 struct __queue *queue = &pmlmepriv->scanned_queue;
1944 struct iw_point *pdata = &wrqu->data;
1945 struct wlan_network *pnetwork = NULL;
1946 u32 cnt = 0, wpa_ielen;
1948 struct list_head *plist, *phead;
1949 unsigned char *pbuf;
1953 if (padapter->driver_stopped || !pdata)
1955 while (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY |
1956 _FW_UNDER_LINKING)) {
1963 if (pdata->length < 32)
1965 if (copy_from_user(data, pdata->pointer, 32))
1969 spin_lock_irqsave(&(pmlmepriv->scanned_queue.lock), irqL);
1970 phead = &queue->queue;
1971 plist = phead->next;
1973 if (end_of_queue_search(phead, plist))
1975 pnetwork = container_of(plist, struct wlan_network, list);
1976 if (!mac_pton(data, bssid)) {
1977 netdev_info(dev, "r8712u: Invalid BSSID '%s'.\n",
1979 spin_unlock_irqrestore(&(pmlmepriv->scanned_queue.lock),
1983 netdev_info(dev, "r8712u: BSSID:%pM\n", bssid);
1984 if (ether_addr_equal(bssid, pnetwork->network.MacAddress)) {
1985 /* BSSID match, then check if supporting wpa/wpa2 */
1986 pbuf = r8712_get_wpa_ie(&pnetwork->network.IEs[12],
1987 &wpa_ielen, pnetwork->network.IELength - 12);
1988 if (pbuf && (wpa_ielen > 0)) {
1992 pbuf = r8712_get_wpa2_ie(&pnetwork->network.IEs[12],
1993 &wpa_ielen, pnetwork->network.IELength - 12);
1994 if (pbuf && (wpa_ielen > 0)) {
1999 plist = plist->next;
2001 spin_unlock_irqrestore(&(pmlmepriv->scanned_queue.lock), irqL);
2002 if (pdata->length >= 34) {
2003 if (copy_to_user((u8 __user *)pdata->pointer + 32,
2004 (u8 *)&pdata->flags, 1))
2010 static int r871x_set_pid(struct net_device *dev,
2011 struct iw_request_info *info,
2012 union iwreq_data *wrqu, char *extra)
2014 struct _adapter *padapter = netdev_priv(dev);
2015 struct iw_point *pdata = &wrqu->data;
2017 if (padapter->driver_stopped || !pdata)
2019 if (copy_from_user(&padapter->pid, pdata->pointer, sizeof(int)))
2024 static int r871x_set_chplan(struct net_device *dev,
2025 struct iw_request_info *info,
2026 union iwreq_data *wrqu, char *extra)
2029 struct _adapter *padapter = netdev_priv(dev);
2030 struct iw_point *pdata = &wrqu->data;
2033 if (padapter->driver_stopped || !pdata) {
2037 ch_plan = (int)*extra;
2038 r8712_set_chplan_cmd(padapter, ch_plan);
2045 static int r871x_wps_start(struct net_device *dev,
2046 struct iw_request_info *info,
2047 union iwreq_data *wrqu, char *extra)
2049 struct _adapter *padapter = netdev_priv(dev);
2050 struct iw_point *pdata = &wrqu->data;
2051 u32 u32wps_start = 0;
2053 if (padapter->driver_stopped || !pdata)
2055 if (copy_from_user((void *)&u32wps_start, pdata->pointer, 4))
2057 if (u32wps_start == 0)
2058 u32wps_start = *extra;
2059 if (u32wps_start == 1) /* WPS Start */
2060 padapter->ledpriv.LedControlHandler(padapter,
2062 else if (u32wps_start == 2) /* WPS Stop because of wps success */
2063 padapter->ledpriv.LedControlHandler(padapter,
2065 else if (u32wps_start == 3) /* WPS Stop because of wps fail */
2066 padapter->ledpriv.LedControlHandler(padapter,
2067 LED_CTL_STOP_WPS_FAIL);
2071 static int wpa_set_param(struct net_device *dev, u8 name, u32 value)
2073 struct _adapter *padapter = netdev_priv(dev);
2076 case IEEE_PARAM_WPA_ENABLED:
2077 padapter->securitypriv.AuthAlgrthm = 2; /* 802.1x */
2078 switch ((value) & 0xff) {
2080 padapter->securitypriv.ndisauthtype =
2081 Ndis802_11AuthModeWPAPSK; /* WPA_PSK */
2082 padapter->securitypriv.ndisencryptstatus =
2083 Ndis802_11Encryption2Enabled;
2086 padapter->securitypriv.ndisauthtype =
2087 Ndis802_11AuthModeWPA2PSK; /* WPA2_PSK */
2088 padapter->securitypriv.ndisencryptstatus =
2089 Ndis802_11Encryption3Enabled;
2093 case IEEE_PARAM_TKIP_COUNTERMEASURES:
2095 case IEEE_PARAM_DROP_UNENCRYPTED:
2098 * wpa_supplicant calls set_wpa_enabled when the driver
2099 * is loaded and unloaded, regardless of if WPA is being
2100 * used. No other calls are made which can be used to
2101 * determine if encryption will be used or not prior to
2102 * association being expected. If encryption is not being
2103 * used, drop_unencrypted is set to false, else true -- we
2104 * can use this to determine if the CAP_PRIVACY_ON bit should
2108 case IEEE_PARAM_PRIVACY_INVOKED:
2110 case IEEE_PARAM_AUTH_ALGS:
2111 return wpa_set_auth_algs(dev, value);
2112 case IEEE_PARAM_IEEE_802_1X:
2114 case IEEE_PARAM_WPAX_SELECT:
2115 /* added for WPA2 mixed mode */
2123 static int wpa_mlme(struct net_device *dev, u32 command, u32 reason)
2125 struct _adapter *padapter = netdev_priv(dev);
2128 case IEEE_MLME_STA_DEAUTH:
2129 if (!r8712_set_802_11_disassociate(padapter))
2132 case IEEE_MLME_STA_DISASSOC:
2133 if (!r8712_set_802_11_disassociate(padapter))
2142 static int wpa_supplicant_ioctl(struct net_device *dev, struct iw_point *p)
2144 struct ieee_param *param;
2146 struct _adapter *padapter = netdev_priv(dev);
2148 if (p->length < sizeof(struct ieee_param) || !p->pointer)
2150 param = memdup_user(p->pointer, p->length);
2152 return PTR_ERR(param);
2153 switch (param->cmd) {
2154 case IEEE_CMD_SET_WPA_PARAM:
2155 ret = wpa_set_param(dev, param->u.wpa_param.name,
2156 param->u.wpa_param.value);
2158 case IEEE_CMD_SET_WPA_IE:
2159 ret = r871x_set_wpa_ie(padapter, (char *)param->u.wpa_ie.data,
2160 (u16)param->u.wpa_ie.len);
2162 case IEEE_CMD_SET_ENCRYPTION:
2163 ret = wpa_set_encryption(dev, param, p->length);
2166 ret = wpa_mlme(dev, param->u.mlme.command,
2167 param->u.mlme.reason_code);
2173 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
2179 /* based on "driver_ipw" and for hostapd */
2180 int r871x_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2182 struct iwreq *wrq = (struct iwreq *)rq;
2185 case RTL_IOCTL_WPA_SUPPLICANT:
2186 return wpa_supplicant_ioctl(dev, &wrq->u.data);
2193 static iw_handler r8711_handlers[] = {
2194 NULL, /* SIOCSIWCOMMIT */
2195 r8711_wx_get_name, /* SIOCGIWNAME */
2196 dummy, /* SIOCSIWNWID */
2197 dummy, /* SIOCGIWNWID */
2198 r8711_wx_set_freq, /* SIOCSIWFREQ */
2199 r8711_wx_get_freq, /* SIOCGIWFREQ */
2200 r8711_wx_set_mode, /* SIOCSIWMODE */
2201 r8711_wx_get_mode, /* SIOCGIWMODE */
2202 dummy, /* SIOCSIWSENS */
2203 r8711_wx_get_sens, /* SIOCGIWSENS */
2204 NULL, /* SIOCSIWRANGE */
2205 r8711_wx_get_range, /* SIOCGIWRANGE */
2206 r871x_wx_set_priv, /* SIOCSIWPRIV */
2207 NULL, /* SIOCGIWPRIV */
2208 NULL, /* SIOCSIWSTATS */
2209 NULL, /* SIOCGIWSTATS */
2210 dummy, /* SIOCSIWSPY */
2211 dummy, /* SIOCGIWSPY */
2212 NULL, /* SIOCGIWTHRSPY */
2213 NULL, /* SIOCWIWTHRSPY */
2214 r8711_wx_set_wap, /* SIOCSIWAP */
2215 r8711_wx_get_wap, /* SIOCGIWAP */
2216 r871x_wx_set_mlme, /* request MLME operation;
2217 * uses struct iw_mlme
2219 dummy, /* SIOCGIWAPLIST -- deprecated */
2220 r8711_wx_set_scan, /* SIOCSIWSCAN */
2221 r8711_wx_get_scan, /* SIOCGIWSCAN */
2222 r8711_wx_set_essid, /* SIOCSIWESSID */
2223 r8711_wx_get_essid, /* SIOCGIWESSID */
2224 dummy, /* SIOCSIWNICKN */
2225 r871x_wx_get_nick, /* SIOCGIWNICKN */
2226 NULL, /* -- hole -- */
2227 NULL, /* -- hole -- */
2228 r8711_wx_set_rate, /* SIOCSIWRATE */
2229 r8711_wx_get_rate, /* SIOCGIWRATE */
2230 dummy, /* SIOCSIWRTS */
2231 r8711_wx_get_rts, /* SIOCGIWRTS */
2232 r8711_wx_set_frag, /* SIOCSIWFRAG */
2233 r8711_wx_get_frag, /* SIOCGIWFRAG */
2234 dummy, /* SIOCSIWTXPOW */
2235 dummy, /* SIOCGIWTXPOW */
2236 dummy, /* SIOCSIWRETRY */
2237 r8711_wx_get_retry, /* SIOCGIWRETRY */
2238 r8711_wx_set_enc, /* SIOCSIWENCODE */
2239 r8711_wx_get_enc, /* SIOCGIWENCODE */
2240 dummy, /* SIOCSIWPOWER */
2241 r8711_wx_get_power, /* SIOCGIWPOWER */
2242 NULL, /*---hole---*/
2243 NULL, /*---hole---*/
2244 r871x_wx_set_gen_ie, /* SIOCSIWGENIE */
2245 NULL, /* SIOCGIWGENIE */
2246 r871x_wx_set_auth, /* SIOCSIWAUTH */
2247 NULL, /* SIOCGIWAUTH */
2248 r871x_wx_set_enc_ext, /* SIOCSIWENCODEEXT */
2249 NULL, /* SIOCGIWENCODEEXT */
2250 r871x_wx_set_pmkid, /* SIOCSIWPMKSA */
2251 NULL, /*---hole---*/
2254 static const struct iw_priv_args r8711_private_args[] = {
2256 SIOCIWFIRSTPRIV + 0x0,
2257 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "read32"
2260 SIOCIWFIRSTPRIV + 0x1,
2261 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "write32"
2264 SIOCIWFIRSTPRIV + 0x2, 0, 0, "driver_ext"
2267 SIOCIWFIRSTPRIV + 0x3, 0, 0, "mp_ioctl"
2270 SIOCIWFIRSTPRIV + 0x4,
2271 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "apinfo"
2274 SIOCIWFIRSTPRIV + 0x5,
2275 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "setpid"
2278 SIOCIWFIRSTPRIV + 0x6,
2279 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wps_start"
2282 SIOCIWFIRSTPRIV + 0x7,
2283 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "chplan"
2287 static iw_handler r8711_private_handler[] = {
2292 r871x_get_ap_info, /*for MM DTV platform*/
2298 static struct iw_statistics *r871x_get_wireless_stats(struct net_device *dev)
2300 struct _adapter *padapter = netdev_priv(dev);
2301 struct iw_statistics *piwstats = &padapter->iwstats;
2306 if (check_fwstate(&padapter->mlmepriv, _FW_LINKED) != true) {
2307 piwstats->qual.qual = 0;
2308 piwstats->qual.level = 0;
2309 piwstats->qual.noise = 0;
2311 /* show percentage, we need transfer dbm to original value. */
2312 tmp_level = padapter->recvpriv.fw_rssi;
2313 tmp_qual = padapter->recvpriv.signal;
2314 tmp_noise = padapter->recvpriv.noise;
2315 piwstats->qual.level = tmp_level;
2316 piwstats->qual.qual = tmp_qual;
2317 piwstats->qual.noise = tmp_noise;
2319 piwstats->qual.updated = IW_QUAL_ALL_UPDATED;
2320 return &padapter->iwstats;
2323 struct iw_handler_def r871x_handlers_def = {
2324 .standard = r8711_handlers,
2325 .num_standard = ARRAY_SIZE(r8711_handlers),
2326 .private = r8711_private_handler,
2327 .private_args = (struct iw_priv_args *)r8711_private_args,
2328 .num_private = ARRAY_SIZE(r8711_private_handler),
2329 .num_private_args = sizeof(r8711_private_args) /
2330 sizeof(struct iw_priv_args),
2331 .get_wireless_stats = r871x_get_wireless_stats