Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 14 | ******************************************************************************/ |
| 15 | #define _IOCTL_LINUX_C_ |
| 16 | |
Paul Gortmaker | 04fbf97 | 2015-04-27 01:25:34 -0400 | [diff] [blame] | 17 | #include <linux/ieee80211.h> |
| 18 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 19 | #include <osdep_service.h> |
| 20 | #include <drv_types.h> |
| 21 | #include <wlan_bssdef.h> |
| 22 | #include <rtw_debug.h> |
| 23 | #include <wifi.h> |
| 24 | #include <rtw_mlme.h> |
| 25 | #include <rtw_mlme_ext.h> |
| 26 | #include <rtw_ioctl.h> |
| 27 | #include <rtw_ioctl_set.h> |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 28 | #include <rtl8188e_hal.h> |
| 29 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 30 | #include <rtw_iol.h> |
Larry Finger | d249db9e5 | 2014-02-07 18:38:50 -0600 | [diff] [blame] | 31 | #include <linux/vmalloc.h> |
Aya Mahfouz | 8e5d943 | 2015-03-04 08:56:45 +0200 | [diff] [blame] | 32 | #include <linux/etherdevice.h> |
| 33 | |
Jeff Oczek | 45c2fc8 | 2014-07-24 20:19:43 -0400 | [diff] [blame] | 34 | #include "osdep_intf.h" |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 35 | |
| 36 | #define RTL_IOCTL_WPA_SUPPLICANT (SIOCIWFIRSTPRIV + 30) |
| 37 | |
| 38 | #define SCAN_ITEM_SIZE 768 |
| 39 | #define MAX_CUSTOM_LEN 64 |
| 40 | #define RATE_COUNT 4 |
| 41 | |
| 42 | /* combo scan */ |
| 43 | #define WEXT_CSCAN_AMOUNT 9 |
| 44 | #define WEXT_CSCAN_BUF_LEN 360 |
| 45 | #define WEXT_CSCAN_HEADER "CSCAN S\x01\x00\x00S\x00" |
| 46 | #define WEXT_CSCAN_HEADER_SIZE 12 |
| 47 | #define WEXT_CSCAN_SSID_SECTION 'S' |
| 48 | #define WEXT_CSCAN_CHANNEL_SECTION 'C' |
| 49 | #define WEXT_CSCAN_NPROBE_SECTION 'N' |
| 50 | #define WEXT_CSCAN_ACTV_DWELL_SECTION 'A' |
| 51 | #define WEXT_CSCAN_PASV_DWELL_SECTION 'P' |
| 52 | #define WEXT_CSCAN_HOME_DWELL_SECTION 'H' |
| 53 | #define WEXT_CSCAN_TYPE_SECTION 'T' |
| 54 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 55 | static u32 rtw_rates[] = {1000000, 2000000, 5500000, 11000000, |
| 56 | 6000000, 9000000, 12000000, 18000000, 24000000, 36000000, |
| 57 | 48000000, 54000000}; |
| 58 | |
| 59 | static const char * const iw_operation_mode[] = { |
| 60 | "Auto", "Ad-Hoc", "Managed", "Master", "Repeater", |
| 61 | "Secondary", "Monitor" |
| 62 | }; |
| 63 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 64 | void indicate_wx_scan_complete_event(struct adapter *padapter) |
| 65 | { |
| 66 | union iwreq_data wrqu; |
| 67 | |
navin patidar | 1ce3984 | 2014-06-22 13:49:28 +0530 | [diff] [blame] | 68 | memset(&wrqu, 0, sizeof(union iwreq_data)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 69 | wireless_send_event(padapter->pnetdev, SIOCGIWSCAN, &wrqu, NULL); |
| 70 | } |
| 71 | |
| 72 | void rtw_indicate_wx_assoc_event(struct adapter *padapter) |
| 73 | { |
| 74 | union iwreq_data wrqu; |
| 75 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
| 76 | |
navin patidar | 1ce3984 | 2014-06-22 13:49:28 +0530 | [diff] [blame] | 77 | memset(&wrqu, 0, sizeof(union iwreq_data)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 78 | |
| 79 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 80 | |
| 81 | memcpy(wrqu.ap_addr.sa_data, pmlmepriv->cur_network.network.MacAddress, ETH_ALEN); |
| 82 | |
| 83 | DBG_88E_LEVEL(_drv_always_, "assoc success\n"); |
| 84 | wireless_send_event(padapter->pnetdev, SIOCGIWAP, &wrqu, NULL); |
| 85 | } |
| 86 | |
| 87 | void rtw_indicate_wx_disassoc_event(struct adapter *padapter) |
| 88 | { |
| 89 | union iwreq_data wrqu; |
| 90 | |
navin patidar | 1ce3984 | 2014-06-22 13:49:28 +0530 | [diff] [blame] | 91 | memset(&wrqu, 0, sizeof(union iwreq_data)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 92 | |
| 93 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
Aya Mahfouz | 8e5d943 | 2015-03-04 08:56:45 +0200 | [diff] [blame] | 94 | eth_zero_addr(wrqu.ap_addr.sa_data); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 95 | |
| 96 | DBG_88E_LEVEL(_drv_always_, "indicate disassoc\n"); |
| 97 | wireless_send_event(padapter->pnetdev, SIOCGIWAP, &wrqu, NULL); |
| 98 | } |
| 99 | |
| 100 | static char *translate_scan(struct adapter *padapter, |
| 101 | struct iw_request_info *info, |
| 102 | struct wlan_network *pnetwork, |
| 103 | char *start, char *stop) |
| 104 | { |
| 105 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 106 | struct iw_event iwe; |
| 107 | u16 cap; |
| 108 | __le16 le_tmp; |
| 109 | u32 ht_ielen = 0; |
| 110 | char custom[MAX_CUSTOM_LEN]; |
| 111 | char *p; |
| 112 | u16 max_rate = 0, rate, ht_cap = false; |
| 113 | u32 i = 0; |
| 114 | u8 bw_40MHz = 0, short_GI = 0; |
| 115 | u16 mcs_rate = 0; |
| 116 | u8 ss, sq; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 117 | |
| 118 | /* AP MAC address */ |
| 119 | iwe.cmd = SIOCGIWAP; |
| 120 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; |
| 121 | |
| 122 | memcpy(iwe.u.ap_addr.sa_data, pnetwork->network.MacAddress, ETH_ALEN); |
| 123 | start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_ADDR_LEN); |
| 124 | |
| 125 | /* Add the ESSID */ |
| 126 | iwe.cmd = SIOCGIWESSID; |
| 127 | iwe.u.data.flags = 1; |
| 128 | iwe.u.data.length = min_t(u16, pnetwork->network.Ssid.SsidLength, 32); |
| 129 | start = iwe_stream_add_point(info, start, stop, &iwe, pnetwork->network.Ssid.Ssid); |
| 130 | |
| 131 | /* parsing HT_CAP_IE */ |
| 132 | p = rtw_get_ie(&pnetwork->network.IEs[12], _HT_CAPABILITY_IE_, &ht_ielen, pnetwork->network.IELength-12); |
| 133 | |
| 134 | if (p && ht_ielen > 0) { |
Ivan Safonov | da9090a | 2016-08-24 15:21:14 +0700 | [diff] [blame] | 135 | struct ieee80211_ht_cap *pht_capie; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 136 | ht_cap = true; |
Ivan Safonov | da9090a | 2016-08-24 15:21:14 +0700 | [diff] [blame] | 137 | pht_capie = (struct ieee80211_ht_cap *)(p + 2); |
| 138 | memcpy(&mcs_rate, pht_capie->mcs.rx_mask, 2); |
| 139 | bw_40MHz = !!(le16_to_cpu(pht_capie->cap_info) & |
| 140 | IEEE80211_HT_CAP_SUP_WIDTH); |
| 141 | short_GI = !!(le16_to_cpu(pht_capie->cap_info) & |
| 142 | (IEEE80211_HT_CAP_SGI_20 | |
| 143 | IEEE80211_HT_CAP_SGI_40)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /* Add the protocol name */ |
| 147 | iwe.cmd = SIOCGIWNAME; |
| 148 | if ((rtw_is_cckratesonly_included((u8 *)&pnetwork->network.SupportedRates))) { |
| 149 | if (ht_cap) |
| 150 | snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bn"); |
| 151 | else |
| 152 | snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11b"); |
| 153 | } else if ((rtw_is_cckrates_included((u8 *)&pnetwork->network.SupportedRates))) { |
| 154 | if (ht_cap) |
| 155 | snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bgn"); |
| 156 | else |
| 157 | snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bg"); |
| 158 | } else { |
| 159 | if (pnetwork->network.Configuration.DSConfig > 14) { |
| 160 | if (ht_cap) |
| 161 | snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11an"); |
| 162 | else |
| 163 | snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11a"); |
| 164 | } else { |
| 165 | if (ht_cap) |
| 166 | snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11gn"); |
| 167 | else |
| 168 | snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11g"); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_CHAR_LEN); |
| 173 | |
| 174 | /* Add mode */ |
| 175 | iwe.cmd = SIOCGIWMODE; |
| 176 | memcpy(&le_tmp, rtw_get_capability_from_ie(pnetwork->network.IEs), 2); |
| 177 | |
| 178 | cap = le16_to_cpu(le_tmp); |
| 179 | |
Jakub Sitnicki | 027d3ef | 2015-06-26 07:50:34 +0200 | [diff] [blame] | 180 | if (!WLAN_CAPABILITY_IS_STA_BSS(cap)) { |
| 181 | if (cap & WLAN_CAPABILITY_ESS) |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 182 | iwe.u.mode = IW_MODE_MASTER; |
| 183 | else |
| 184 | iwe.u.mode = IW_MODE_ADHOC; |
| 185 | |
| 186 | start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_UINT_LEN); |
| 187 | } |
| 188 | |
| 189 | if (pnetwork->network.Configuration.DSConfig < 1) |
| 190 | pnetwork->network.Configuration.DSConfig = 1; |
| 191 | |
| 192 | /* Add frequency/channel */ |
| 193 | iwe.cmd = SIOCGIWFREQ; |
| 194 | iwe.u.freq.m = rtw_ch2freq(pnetwork->network.Configuration.DSConfig) * 100000; |
| 195 | iwe.u.freq.e = 1; |
| 196 | iwe.u.freq.i = pnetwork->network.Configuration.DSConfig; |
| 197 | start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_FREQ_LEN); |
| 198 | |
| 199 | /* Add encryption capability */ |
| 200 | iwe.cmd = SIOCGIWENCODE; |
| 201 | if (cap & WLAN_CAPABILITY_PRIVACY) |
| 202 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; |
| 203 | else |
| 204 | iwe.u.data.flags = IW_ENCODE_DISABLED; |
| 205 | iwe.u.data.length = 0; |
| 206 | start = iwe_stream_add_point(info, start, stop, &iwe, pnetwork->network.Ssid.Ssid); |
| 207 | |
| 208 | /*Add basic and extended rates */ |
| 209 | max_rate = 0; |
| 210 | p = custom; |
| 211 | p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), " Rates (Mb/s): "); |
| 212 | while (pnetwork->network.SupportedRates[i] != 0) { |
| 213 | rate = pnetwork->network.SupportedRates[i]&0x7F; |
| 214 | if (rate > max_rate) |
| 215 | max_rate = rate; |
| 216 | p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), |
| 217 | "%d%s ", rate >> 1, (rate & 1) ? ".5" : ""); |
| 218 | i++; |
| 219 | } |
| 220 | |
| 221 | if (ht_cap) { |
| 222 | if (mcs_rate&0x8000)/* MCS15 */ |
| 223 | max_rate = (bw_40MHz) ? ((short_GI) ? 300 : 270) : ((short_GI) ? 144 : 130); |
| 224 | else if (mcs_rate&0x0080)/* MCS7 */ |
| 225 | ; |
| 226 | else/* default MCS7 */ |
| 227 | max_rate = (bw_40MHz) ? ((short_GI) ? 150 : 135) : ((short_GI) ? 72 : 65); |
| 228 | |
| 229 | max_rate = max_rate*2;/* Mbps/2; */ |
| 230 | } |
| 231 | |
| 232 | iwe.cmd = SIOCGIWRATE; |
| 233 | iwe.u.bitrate.fixed = 0; |
| 234 | iwe.u.bitrate.disabled = 0; |
| 235 | iwe.u.bitrate.value = max_rate * 500000; |
| 236 | start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_PARAM_LEN); |
| 237 | |
| 238 | /* parsing WPA/WPA2 IE */ |
| 239 | { |
| 240 | u8 buf[MAX_WPA_IE_LEN]; |
| 241 | u8 wpa_ie[255], rsn_ie[255]; |
| 242 | u16 wpa_len = 0, rsn_len = 0; |
| 243 | u8 *p; |
| 244 | |
| 245 | rtw_get_sec_ie(pnetwork->network.IEs, pnetwork->network.IELength, rsn_ie, &rsn_len, wpa_ie, &wpa_len); |
| 246 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_wx_get_scan: ssid =%s\n", pnetwork->network.Ssid.Ssid)); |
| 247 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_wx_get_scan: wpa_len =%d rsn_len =%d\n", wpa_len, rsn_len)); |
| 248 | |
| 249 | if (wpa_len > 0) { |
| 250 | p = buf; |
navin patidar | 1ce3984 | 2014-06-22 13:49:28 +0530 | [diff] [blame] | 251 | memset(buf, 0, MAX_WPA_IE_LEN); |
Wilfried Klaebe | ec03ab7 | 2014-03-25 17:59:39 +0000 | [diff] [blame] | 252 | p += sprintf(p, "wpa_ie="); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 253 | for (i = 0; i < wpa_len; i++) |
| 254 | p += sprintf(p, "%02x", wpa_ie[i]); |
| 255 | |
navin patidar | 1ce3984 | 2014-06-22 13:49:28 +0530 | [diff] [blame] | 256 | memset(&iwe, 0, sizeof(iwe)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 257 | iwe.cmd = IWEVCUSTOM; |
| 258 | iwe.u.data.length = strlen(buf); |
| 259 | start = iwe_stream_add_point(info, start, stop, &iwe, buf); |
| 260 | |
navin patidar | 1ce3984 | 2014-06-22 13:49:28 +0530 | [diff] [blame] | 261 | memset(&iwe, 0, sizeof(iwe)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 262 | iwe.cmd = IWEVGENIE; |
| 263 | iwe.u.data.length = wpa_len; |
| 264 | start = iwe_stream_add_point(info, start, stop, &iwe, wpa_ie); |
| 265 | } |
| 266 | if (rsn_len > 0) { |
| 267 | p = buf; |
navin patidar | 1ce3984 | 2014-06-22 13:49:28 +0530 | [diff] [blame] | 268 | memset(buf, 0, MAX_WPA_IE_LEN); |
Wilfried Klaebe | ec03ab7 | 2014-03-25 17:59:39 +0000 | [diff] [blame] | 269 | p += sprintf(p, "rsn_ie="); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 270 | for (i = 0; i < rsn_len; i++) |
| 271 | p += sprintf(p, "%02x", rsn_ie[i]); |
navin patidar | 1ce3984 | 2014-06-22 13:49:28 +0530 | [diff] [blame] | 272 | memset(&iwe, 0, sizeof(iwe)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 273 | iwe.cmd = IWEVCUSTOM; |
| 274 | iwe.u.data.length = strlen(buf); |
| 275 | start = iwe_stream_add_point(info, start, stop, &iwe, buf); |
| 276 | |
navin patidar | 1ce3984 | 2014-06-22 13:49:28 +0530 | [diff] [blame] | 277 | memset(&iwe, 0, sizeof(iwe)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 278 | iwe.cmd = IWEVGENIE; |
| 279 | iwe.u.data.length = rsn_len; |
| 280 | start = iwe_stream_add_point(info, start, stop, &iwe, rsn_ie); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | {/* parsing WPS IE */ |
| 285 | uint cnt = 0, total_ielen; |
| 286 | u8 *wpsie_ptr = NULL; |
| 287 | uint wps_ielen = 0; |
| 288 | |
| 289 | u8 *ie_ptr = pnetwork->network.IEs + _FIXED_IE_LENGTH_; |
| 290 | total_ielen = pnetwork->network.IELength - _FIXED_IE_LENGTH_; |
| 291 | |
| 292 | while (cnt < total_ielen) { |
| 293 | if (rtw_is_wps_ie(&ie_ptr[cnt], &wps_ielen) && (wps_ielen > 2)) { |
| 294 | wpsie_ptr = &ie_ptr[cnt]; |
| 295 | iwe.cmd = IWEVGENIE; |
| 296 | iwe.u.data.length = (u16)wps_ielen; |
| 297 | start = iwe_stream_add_point(info, start, stop, &iwe, wpsie_ptr); |
| 298 | } |
| 299 | cnt += ie_ptr[cnt+1]+2; /* goto next */ |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | /* Add quality statistics */ |
| 304 | iwe.cmd = IWEVQUAL; |
| 305 | iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_INVALID; |
| 306 | |
| 307 | if (check_fwstate(pmlmepriv, _FW_LINKED) == true && |
| 308 | is_same_network(&pmlmepriv->cur_network.network, &pnetwork->network)) { |
| 309 | ss = padapter->recvpriv.signal_strength; |
| 310 | sq = padapter->recvpriv.signal_qual; |
| 311 | } else { |
| 312 | ss = pnetwork->network.PhyInfo.SignalStrength; |
| 313 | sq = pnetwork->network.PhyInfo.SignalQuality; |
| 314 | } |
| 315 | |
| 316 | iwe.u.qual.level = (u8)ss; |
| 317 | iwe.u.qual.qual = (u8)sq; /* signal quality */ |
| 318 | iwe.u.qual.noise = 0; /* noise level */ |
| 319 | start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_QUAL_LEN); |
| 320 | return start; |
| 321 | } |
| 322 | |
| 323 | static int wpa_set_auth_algs(struct net_device *dev, u32 value) |
| 324 | { |
| 325 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 326 | int ret = 0; |
| 327 | |
| 328 | if ((value & AUTH_ALG_SHARED_KEY) && (value & AUTH_ALG_OPEN_SYSTEM)) { |
| 329 | DBG_88E("wpa_set_auth_algs, AUTH_ALG_SHARED_KEY and AUTH_ALG_OPEN_SYSTEM [value:0x%x]\n", value); |
| 330 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; |
| 331 | padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeAutoSwitch; |
| 332 | padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Auto; |
| 333 | } else if (value & AUTH_ALG_SHARED_KEY) { |
| 334 | DBG_88E("wpa_set_auth_algs, AUTH_ALG_SHARED_KEY [value:0x%x]\n", value); |
| 335 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; |
| 336 | |
| 337 | padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeShared; |
| 338 | padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Shared; |
| 339 | } else if (value & AUTH_ALG_OPEN_SYSTEM) { |
| 340 | DBG_88E("wpa_set_auth_algs, AUTH_ALG_OPEN_SYSTEM\n"); |
| 341 | if (padapter->securitypriv.ndisauthtype < Ndis802_11AuthModeWPAPSK) { |
| 342 | padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen; |
| 343 | padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; |
| 344 | } |
| 345 | } else if (value & AUTH_ALG_LEAP) { |
| 346 | DBG_88E("wpa_set_auth_algs, AUTH_ALG_LEAP\n"); |
| 347 | } else { |
| 348 | DBG_88E("wpa_set_auth_algs, error!\n"); |
| 349 | ret = -EINVAL; |
| 350 | } |
| 351 | return ret; |
| 352 | } |
| 353 | |
| 354 | static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len) |
| 355 | { |
| 356 | int ret = 0; |
| 357 | u32 wep_key_idx, wep_key_len, wep_total_len; |
| 358 | struct ndis_802_11_wep *pwep = NULL; |
| 359 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 360 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
| 361 | struct security_priv *psecuritypriv = &padapter->securitypriv; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 362 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 363 | param->u.crypt.err = 0; |
| 364 | param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0'; |
| 365 | |
Jia He | 7be921a2 | 2014-11-04 09:39:58 +0800 | [diff] [blame] | 366 | if (param_len < (u32)((u8 *)param->u.crypt.key - (u8 *)param) + param->u.crypt.key_len) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 367 | ret = -EINVAL; |
| 368 | goto exit; |
| 369 | } |
| 370 | |
| 371 | if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff && |
| 372 | param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff && |
| 373 | param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) { |
| 374 | if (param->u.crypt.idx >= WEP_KEYS) { |
| 375 | ret = -EINVAL; |
| 376 | goto exit; |
| 377 | } |
| 378 | } else { |
| 379 | ret = -EINVAL; |
| 380 | goto exit; |
| 381 | } |
| 382 | |
| 383 | if (strcmp(param->u.crypt.alg, "WEP") == 0) { |
| 384 | RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_, ("wpa_set_encryption, crypt.alg = WEP\n")); |
| 385 | DBG_88E("wpa_set_encryption, crypt.alg = WEP\n"); |
| 386 | |
| 387 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; |
| 388 | padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_; |
| 389 | padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_; |
| 390 | |
| 391 | wep_key_idx = param->u.crypt.idx; |
| 392 | wep_key_len = param->u.crypt.key_len; |
| 393 | |
| 394 | RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, ("(1)wep_key_idx =%d\n", wep_key_idx)); |
| 395 | DBG_88E("(1)wep_key_idx =%d\n", wep_key_idx); |
| 396 | |
| 397 | if (wep_key_idx > WEP_KEYS) |
| 398 | return -EINVAL; |
| 399 | |
| 400 | RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, ("(2)wep_key_idx =%d\n", wep_key_idx)); |
| 401 | |
| 402 | if (wep_key_len > 0) { |
| 403 | wep_key_len = wep_key_len <= 5 ? 5 : 13; |
Ivan Safonov | 5e3027b | 2016-03-02 14:59:01 +0700 | [diff] [blame] | 404 | wep_total_len = wep_key_len + offsetof(struct ndis_802_11_wep, KeyMaterial); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 405 | pwep = (struct ndis_802_11_wep *)rtw_malloc(wep_total_len); |
Amit Ghadge | 4fe514d | 2016-09-04 22:53:35 +0530 | [diff] [blame] | 406 | if (!pwep) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 407 | RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_, (" wpa_set_encryption: pwep allocate fail !!!\n")); |
| 408 | goto exit; |
| 409 | } |
navin patidar | 1ce3984 | 2014-06-22 13:49:28 +0530 | [diff] [blame] | 410 | memset(pwep, 0, wep_total_len); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 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_; |
| 416 | } |
| 417 | } else { |
| 418 | ret = -EINVAL; |
| 419 | goto exit; |
| 420 | } |
| 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 | DBG_88E("wep, set_tx = 1\n"); |
| 426 | if (rtw_set_802_11_add_wep(padapter, pwep) == (u8)_FAIL) |
| 427 | ret = -EOPNOTSUPP; |
| 428 | } else { |
| 429 | DBG_88E("wep, set_tx = 0\n"); |
| 430 | if (wep_key_idx >= WEP_KEYS) { |
| 431 | ret = -EOPNOTSUPP; |
| 432 | goto exit; |
| 433 | } |
| 434 | memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), pwep->KeyMaterial, pwep->KeyLength); |
| 435 | psecuritypriv->dot11DefKeylen[wep_key_idx] = pwep->KeyLength; |
| 436 | rtw_set_key(padapter, psecuritypriv, wep_key_idx, 0); |
| 437 | } |
| 438 | goto exit; |
| 439 | } |
| 440 | |
| 441 | if (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) { /* 802_1x */ |
| 442 | struct sta_info *psta, *pbcmc_sta; |
| 443 | struct sta_priv *pstapriv = &padapter->stapriv; |
| 444 | |
| 445 | if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_MP_STATE)) { /* sta mode */ |
| 446 | psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv)); |
Amit Ghadge | 4fe514d | 2016-09-04 22:53:35 +0530 | [diff] [blame] | 447 | if (!psta) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 448 | ; |
| 449 | } else { |
| 450 | if (strcmp(param->u.crypt.alg, "none") != 0) |
| 451 | psta->ieee8021x_blocked = false; |
| 452 | |
| 453 | if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) || |
| 454 | (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled)) |
| 455 | psta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm; |
| 456 | |
| 457 | if (param->u.crypt.set_tx == 1) { /* pairwise key */ |
Ivan Safonov | ad8d8cd | 2015-10-27 22:18:10 +0700 | [diff] [blame] | 458 | memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 459 | |
| 460 | if (strcmp(param->u.crypt.alg, "TKIP") == 0) { /* set mic key */ |
| 461 | memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8); |
| 462 | memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8); |
| 463 | padapter->securitypriv.busetkipkey = false; |
| 464 | } |
| 465 | |
| 466 | DBG_88E(" ~~~~set sta key:unicastkey\n"); |
| 467 | |
| 468 | rtw_setstakey_cmd(padapter, (unsigned char *)psta, true); |
| 469 | } else { /* group key */ |
Ivan Safonov | ad8d8cd | 2015-10-27 22:18:10 +0700 | [diff] [blame] | 470 | memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16 )); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 471 | memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8); |
| 472 | memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8); |
| 473 | padapter->securitypriv.binstallGrpkey = true; |
| 474 | DBG_88E(" ~~~~set sta key:groupkey\n"); |
| 475 | |
| 476 | padapter->securitypriv.dot118021XGrpKeyid = param->u.crypt.idx; |
| 477 | |
| 478 | rtw_set_key(padapter, &padapter->securitypriv, param->u.crypt.idx, 1); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 479 | } |
| 480 | } |
| 481 | pbcmc_sta = rtw_get_bcmc_stainfo(padapter); |
Amit Ghadge | 4fe514d | 2016-09-04 22:53:35 +0530 | [diff] [blame] | 482 | if (!pbcmc_sta) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 483 | ; |
| 484 | } else { |
| 485 | /* Jeff: don't disable ieee8021x_blocked while clearing key */ |
| 486 | if (strcmp(param->u.crypt.alg, "none") != 0) |
| 487 | pbcmc_sta->ieee8021x_blocked = false; |
| 488 | |
| 489 | if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) || |
| 490 | (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled)) |
| 491 | pbcmc_sta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm; |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | exit: |
| 497 | |
| 498 | kfree(pwep); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 499 | return ret; |
| 500 | } |
| 501 | |
| 502 | static int rtw_set_wpa_ie(struct adapter *padapter, char *pie, unsigned short ielen) |
| 503 | { |
| 504 | u8 *buf = NULL; |
| 505 | int group_cipher = 0, pairwise_cipher = 0; |
| 506 | int ret = 0; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 507 | |
Amit Ghadge | 4fe514d | 2016-09-04 22:53:35 +0530 | [diff] [blame] | 508 | if ((ielen > MAX_WPA_IE_LEN) || (!pie)) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 509 | _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS); |
Amit Ghadge | 4fe514d | 2016-09-04 22:53:35 +0530 | [diff] [blame] | 510 | if (!pie) |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 511 | return ret; |
| 512 | else |
| 513 | return -EINVAL; |
| 514 | } |
| 515 | |
| 516 | if (ielen) { |
Tapasweni Pathak | 705515c | 2014-10-21 09:48:20 +0530 | [diff] [blame] | 517 | buf = kmemdup(pie, ielen, GFP_KERNEL); |
Amit Ghadge | 4fe514d | 2016-09-04 22:53:35 +0530 | [diff] [blame] | 518 | if (!buf) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 519 | ret = -ENOMEM; |
| 520 | goto exit; |
| 521 | } |
| 522 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 523 | /* dump */ |
| 524 | { |
| 525 | int i; |
| 526 | DBG_88E("\n wpa_ie(length:%d):\n", ielen); |
| 527 | for (i = 0; i < ielen; i += 8) |
| 528 | DBG_88E("0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", buf[i], buf[i+1], buf[i+2], buf[i+3], buf[i+4], buf[i+5], buf[i+6], buf[i+7]); |
| 529 | } |
| 530 | |
| 531 | if (ielen < RSN_HEADER_LEN) { |
| 532 | RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_, ("Ie len too short %d\n", ielen)); |
| 533 | ret = -1; |
| 534 | goto exit; |
| 535 | } |
| 536 | |
| 537 | if (rtw_parse_wpa_ie(buf, ielen, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) { |
| 538 | padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; |
| 539 | padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPAPSK; |
| 540 | memcpy(padapter->securitypriv.supplicant_ie, &buf[0], ielen); |
| 541 | } |
| 542 | |
| 543 | if (rtw_parse_wpa2_ie(buf, ielen, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) { |
| 544 | padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; |
| 545 | padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPA2PSK; |
| 546 | memcpy(padapter->securitypriv.supplicant_ie, &buf[0], ielen); |
| 547 | } |
| 548 | |
| 549 | switch (group_cipher) { |
| 550 | case WPA_CIPHER_NONE: |
| 551 | padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_; |
| 552 | padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled; |
| 553 | break; |
| 554 | case WPA_CIPHER_WEP40: |
| 555 | padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_; |
| 556 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; |
| 557 | break; |
| 558 | case WPA_CIPHER_TKIP: |
| 559 | padapter->securitypriv.dot118021XGrpPrivacy = _TKIP_; |
| 560 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled; |
| 561 | break; |
| 562 | case WPA_CIPHER_CCMP: |
| 563 | padapter->securitypriv.dot118021XGrpPrivacy = _AES_; |
| 564 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled; |
| 565 | break; |
| 566 | case WPA_CIPHER_WEP104: |
| 567 | padapter->securitypriv.dot118021XGrpPrivacy = _WEP104_; |
| 568 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; |
| 569 | break; |
| 570 | } |
| 571 | |
| 572 | switch (pairwise_cipher) { |
| 573 | case WPA_CIPHER_NONE: |
| 574 | padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_; |
| 575 | padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled; |
| 576 | break; |
| 577 | case WPA_CIPHER_WEP40: |
| 578 | padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_; |
| 579 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; |
| 580 | break; |
| 581 | case WPA_CIPHER_TKIP: |
| 582 | padapter->securitypriv.dot11PrivacyAlgrthm = _TKIP_; |
| 583 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled; |
| 584 | break; |
| 585 | case WPA_CIPHER_CCMP: |
| 586 | padapter->securitypriv.dot11PrivacyAlgrthm = _AES_; |
| 587 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled; |
| 588 | break; |
| 589 | case WPA_CIPHER_WEP104: |
| 590 | padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_; |
| 591 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; |
| 592 | break; |
| 593 | } |
| 594 | |
| 595 | _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS); |
| 596 | {/* set wps_ie */ |
| 597 | u16 cnt = 0; |
| 598 | u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04}; |
| 599 | |
| 600 | while (cnt < ielen) { |
| 601 | eid = buf[cnt]; |
| 602 | if ((eid == _VENDOR_SPECIFIC_IE_) && (!memcmp(&buf[cnt+2], wps_oui, 4))) { |
| 603 | DBG_88E("SET WPS_IE\n"); |
| 604 | |
Ivan Safonov | 20e7653 | 2015-10-27 22:16:25 +0700 | [diff] [blame] | 605 | padapter->securitypriv.wps_ie_len = min(buf[cnt + 1] + 2, MAX_WPA_IE_LEN << 2); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 606 | |
| 607 | memcpy(padapter->securitypriv.wps_ie, &buf[cnt], padapter->securitypriv.wps_ie_len); |
| 608 | |
| 609 | set_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 610 | cnt += buf[cnt+1]+2; |
| 611 | break; |
| 612 | } else { |
| 613 | cnt += buf[cnt+1]+2; /* goto next */ |
| 614 | } |
| 615 | } |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, |
| 620 | ("rtw_set_wpa_ie: pairwise_cipher = 0x%08x padapter->securitypriv.ndisencryptstatus =%d padapter->securitypriv.ndisauthtype =%d\n", |
| 621 | pairwise_cipher, padapter->securitypriv.ndisencryptstatus, padapter->securitypriv.ndisauthtype)); |
| 622 | exit: |
| 623 | kfree(buf); |
| 624 | return ret; |
| 625 | } |
| 626 | |
| 627 | typedef unsigned char NDIS_802_11_RATES_EX[NDIS_802_11_LENGTH_RATES_EX]; |
| 628 | |
| 629 | static int rtw_wx_get_name(struct net_device *dev, |
| 630 | struct iw_request_info *info, |
| 631 | union iwreq_data *wrqu, char *extra) |
| 632 | { |
| 633 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 634 | u32 ht_ielen = 0; |
| 635 | char *p; |
| 636 | u8 ht_cap = false; |
| 637 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 638 | struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network; |
| 639 | NDIS_802_11_RATES_EX *prates = NULL; |
| 640 | |
| 641 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("cmd_code =%x\n", info->cmd)); |
| 642 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 643 | if (check_fwstate(pmlmepriv, _FW_LINKED|WIFI_ADHOC_MASTER_STATE) == true) { |
| 644 | /* parsing HT_CAP_IE */ |
| 645 | p = rtw_get_ie(&pcur_bss->IEs[12], _HT_CAPABILITY_IE_, &ht_ielen, pcur_bss->IELength-12); |
| 646 | if (p && ht_ielen > 0) |
| 647 | ht_cap = true; |
| 648 | |
| 649 | prates = &pcur_bss->SupportedRates; |
| 650 | |
| 651 | if (rtw_is_cckratesonly_included((u8 *)prates) == true) { |
| 652 | if (ht_cap) |
| 653 | snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11bn"); |
| 654 | else |
| 655 | snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b"); |
| 656 | } else if ((rtw_is_cckrates_included((u8 *)prates)) == true) { |
| 657 | if (ht_cap) |
| 658 | snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11bgn"); |
| 659 | else |
| 660 | snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11bg"); |
| 661 | } else { |
| 662 | if (pcur_bss->Configuration.DSConfig > 14) { |
| 663 | if (ht_cap) |
| 664 | snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11an"); |
| 665 | else |
| 666 | snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11a"); |
| 667 | } else { |
| 668 | if (ht_cap) |
| 669 | snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11gn"); |
| 670 | else |
| 671 | snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11g"); |
| 672 | } |
| 673 | } |
| 674 | } else { |
| 675 | snprintf(wrqu->name, IFNAMSIZ, "unassociated"); |
| 676 | } |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 677 | return 0; |
| 678 | } |
| 679 | |
| 680 | static int rtw_wx_set_freq(struct net_device *dev, |
| 681 | struct iw_request_info *info, |
| 682 | union iwreq_data *wrqu, char *extra) |
| 683 | { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 684 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_, ("+rtw_wx_set_freq\n")); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 685 | return 0; |
| 686 | } |
| 687 | |
| 688 | static int rtw_wx_get_freq(struct net_device *dev, |
| 689 | struct iw_request_info *info, |
| 690 | union iwreq_data *wrqu, char *extra) |
| 691 | { |
| 692 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 693 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 694 | struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network; |
| 695 | |
| 696 | if (check_fwstate(pmlmepriv, _FW_LINKED)) { |
| 697 | /* wrqu->freq.m = ieee80211_wlan_frequencies[pcur_bss->Configuration.DSConfig-1] * 100000; */ |
| 698 | wrqu->freq.m = rtw_ch2freq(pcur_bss->Configuration.DSConfig) * 100000; |
| 699 | wrqu->freq.e = 1; |
| 700 | wrqu->freq.i = pcur_bss->Configuration.DSConfig; |
| 701 | } else { |
| 702 | wrqu->freq.m = rtw_ch2freq(padapter->mlmeextpriv.cur_channel) * 100000; |
| 703 | wrqu->freq.e = 1; |
| 704 | wrqu->freq.i = padapter->mlmeextpriv.cur_channel; |
| 705 | } |
| 706 | |
| 707 | return 0; |
| 708 | } |
| 709 | |
| 710 | static int rtw_wx_set_mode(struct net_device *dev, struct iw_request_info *a, |
| 711 | union iwreq_data *wrqu, char *b) |
| 712 | { |
| 713 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 714 | enum ndis_802_11_network_infra networkType; |
| 715 | int ret = 0; |
| 716 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 717 | if (_FAIL == rtw_pwr_wakeup(padapter)) { |
| 718 | ret = -EPERM; |
| 719 | goto exit; |
| 720 | } |
| 721 | |
| 722 | if (!padapter->hw_init_completed) { |
| 723 | ret = -EPERM; |
| 724 | goto exit; |
| 725 | } |
| 726 | |
| 727 | switch (wrqu->mode) { |
| 728 | case IW_MODE_AUTO: |
| 729 | networkType = Ndis802_11AutoUnknown; |
| 730 | DBG_88E("set_mode = IW_MODE_AUTO\n"); |
| 731 | break; |
| 732 | case IW_MODE_ADHOC: |
| 733 | networkType = Ndis802_11IBSS; |
| 734 | DBG_88E("set_mode = IW_MODE_ADHOC\n"); |
| 735 | break; |
| 736 | case IW_MODE_MASTER: |
| 737 | networkType = Ndis802_11APMode; |
| 738 | DBG_88E("set_mode = IW_MODE_MASTER\n"); |
| 739 | break; |
| 740 | case IW_MODE_INFRA: |
| 741 | networkType = Ndis802_11Infrastructure; |
| 742 | DBG_88E("set_mode = IW_MODE_INFRA\n"); |
| 743 | break; |
| 744 | default: |
| 745 | ret = -EINVAL; |
| 746 | RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_, ("\n Mode: %s is not supported\n", iw_operation_mode[wrqu->mode])); |
| 747 | goto exit; |
| 748 | } |
| 749 | if (rtw_set_802_11_infrastructure_mode(padapter, networkType) == false) { |
| 750 | ret = -EPERM; |
| 751 | goto exit; |
| 752 | } |
| 753 | rtw_setopmode_cmd(padapter, networkType); |
| 754 | exit: |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 755 | return ret; |
| 756 | } |
| 757 | |
| 758 | static int rtw_wx_get_mode(struct net_device *dev, struct iw_request_info *a, |
| 759 | union iwreq_data *wrqu, char *b) |
| 760 | { |
| 761 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 762 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 763 | |
| 764 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, (" rtw_wx_get_mode\n")); |
| 765 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 766 | if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) |
| 767 | wrqu->mode = IW_MODE_INFRA; |
| 768 | else if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) || |
| 769 | (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE))) |
| 770 | wrqu->mode = IW_MODE_ADHOC; |
| 771 | else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) |
| 772 | wrqu->mode = IW_MODE_MASTER; |
| 773 | else |
| 774 | wrqu->mode = IW_MODE_AUTO; |
| 775 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 776 | return 0; |
| 777 | } |
| 778 | |
| 779 | static int rtw_wx_set_pmkid(struct net_device *dev, |
| 780 | struct iw_request_info *a, |
| 781 | union iwreq_data *wrqu, char *extra) |
| 782 | { |
| 783 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 784 | u8 j, blInserted = false; |
| 785 | int ret = false; |
| 786 | struct security_priv *psecuritypriv = &padapter->securitypriv; |
| 787 | struct iw_pmksa *pPMK = (struct iw_pmksa *)extra; |
| 788 | u8 strZeroMacAddress[ETH_ALEN] = {0x00}; |
| 789 | u8 strIssueBssid[ETH_ALEN] = {0x00}; |
| 790 | |
| 791 | memcpy(strIssueBssid, pPMK->bssid.sa_data, ETH_ALEN); |
| 792 | if (pPMK->cmd == IW_PMKSA_ADD) { |
| 793 | DBG_88E("[rtw_wx_set_pmkid] IW_PMKSA_ADD!\n"); |
Larry Finger | dc14a62 | 2013-09-04 15:56:02 -0500 | [diff] [blame] | 794 | if (!memcmp(strIssueBssid, strZeroMacAddress, ETH_ALEN)) |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 795 | return ret; |
| 796 | else |
| 797 | ret = true; |
| 798 | blInserted = false; |
| 799 | |
| 800 | /* overwrite PMKID */ |
| 801 | for (j = 0; j < NUM_PMKID_CACHE; j++) { |
| 802 | if (!memcmp(psecuritypriv->PMKIDList[j].Bssid, strIssueBssid, ETH_ALEN)) { |
| 803 | /* BSSID is matched, the same AP => rewrite with new PMKID. */ |
| 804 | DBG_88E("[rtw_wx_set_pmkid] BSSID exists in the PMKList.\n"); |
| 805 | memcpy(psecuritypriv->PMKIDList[j].PMKID, pPMK->pmkid, IW_PMKID_LEN); |
| 806 | psecuritypriv->PMKIDList[j].bUsed = true; |
| 807 | psecuritypriv->PMKIDIndex = j+1; |
| 808 | blInserted = true; |
| 809 | break; |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | if (!blInserted) { |
| 814 | /* Find a new entry */ |
| 815 | DBG_88E("[rtw_wx_set_pmkid] Use the new entry index = %d for this PMKID.\n", |
| 816 | psecuritypriv->PMKIDIndex); |
| 817 | |
| 818 | memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].Bssid, strIssueBssid, ETH_ALEN); |
| 819 | memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].PMKID, pPMK->pmkid, IW_PMKID_LEN); |
| 820 | |
| 821 | psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].bUsed = true; |
| 822 | psecuritypriv->PMKIDIndex++; |
| 823 | if (psecuritypriv->PMKIDIndex == 16) |
| 824 | psecuritypriv->PMKIDIndex = 0; |
| 825 | } |
| 826 | } else if (pPMK->cmd == IW_PMKSA_REMOVE) { |
| 827 | DBG_88E("[rtw_wx_set_pmkid] IW_PMKSA_REMOVE!\n"); |
| 828 | ret = true; |
| 829 | for (j = 0; j < NUM_PMKID_CACHE; j++) { |
| 830 | if (!memcmp(psecuritypriv->PMKIDList[j].Bssid, strIssueBssid, ETH_ALEN)) { |
| 831 | /* BSSID is matched, the same AP => Remove this PMKID information and reset it. */ |
Aya Mahfouz | 8e5d943 | 2015-03-04 08:56:45 +0200 | [diff] [blame] | 832 | eth_zero_addr(psecuritypriv->PMKIDList[j].Bssid); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 833 | psecuritypriv->PMKIDList[j].bUsed = false; |
| 834 | break; |
| 835 | } |
| 836 | } |
| 837 | } else if (pPMK->cmd == IW_PMKSA_FLUSH) { |
| 838 | DBG_88E("[rtw_wx_set_pmkid] IW_PMKSA_FLUSH!\n"); |
navin patidar | 1ce3984 | 2014-06-22 13:49:28 +0530 | [diff] [blame] | 839 | memset(&psecuritypriv->PMKIDList[0], 0x00, sizeof(struct rt_pmkid_list) * NUM_PMKID_CACHE); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 840 | psecuritypriv->PMKIDIndex = 0; |
| 841 | ret = true; |
| 842 | } |
| 843 | return ret; |
| 844 | } |
| 845 | |
| 846 | static int rtw_wx_get_sens(struct net_device *dev, |
| 847 | struct iw_request_info *info, |
| 848 | union iwreq_data *wrqu, char *extra) |
| 849 | { |
| 850 | wrqu->sens.value = 0; |
| 851 | wrqu->sens.fixed = 0; /* no auto select */ |
| 852 | wrqu->sens.disabled = 1; |
| 853 | return 0; |
| 854 | } |
| 855 | |
| 856 | static int rtw_wx_get_range(struct net_device *dev, |
| 857 | struct iw_request_info *info, |
| 858 | union iwreq_data *wrqu, char *extra) |
| 859 | { |
| 860 | struct iw_range *range = (struct iw_range *)extra; |
| 861 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 862 | struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; |
| 863 | |
| 864 | u16 val; |
| 865 | int i; |
| 866 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 867 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_wx_get_range. cmd_code =%x\n", info->cmd)); |
| 868 | |
| 869 | wrqu->data.length = sizeof(*range); |
navin patidar | 1ce3984 | 2014-06-22 13:49:28 +0530 | [diff] [blame] | 870 | memset(range, 0, sizeof(*range)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 871 | |
| 872 | /* Let's try to keep this struct in the same order as in |
| 873 | * linux/include/wireless.h |
| 874 | */ |
| 875 | |
| 876 | /* TODO: See what values we can set, and remove the ones we can't |
| 877 | * set, or fill them with some default data. |
| 878 | */ |
| 879 | |
| 880 | /* ~5 Mb/s real (802.11b) */ |
| 881 | range->throughput = 5 * 1000 * 1000; |
| 882 | |
| 883 | /* signal level threshold range */ |
| 884 | |
| 885 | /* percent values between 0 and 100. */ |
| 886 | range->max_qual.qual = 100; |
| 887 | range->max_qual.level = 100; |
| 888 | range->max_qual.noise = 100; |
| 889 | range->max_qual.updated = 7; /* Updated all three */ |
| 890 | |
| 891 | range->avg_qual.qual = 92; /* > 8% missed beacons is 'bad' */ |
| 892 | /* TODO: Find real 'good' to 'bad' threshol value for RSSI */ |
Larry Finger | dc14a62 | 2013-09-04 15:56:02 -0500 | [diff] [blame] | 893 | range->avg_qual.level = 178; /* -78 dBm */ |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 894 | range->avg_qual.noise = 0; |
| 895 | range->avg_qual.updated = 7; /* Updated all three */ |
| 896 | |
| 897 | range->num_bitrates = RATE_COUNT; |
| 898 | |
| 899 | for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) |
| 900 | range->bitrate[i] = rtw_rates[i]; |
| 901 | |
| 902 | range->min_frag = MIN_FRAG_THRESHOLD; |
| 903 | range->max_frag = MAX_FRAG_THRESHOLD; |
| 904 | |
| 905 | range->pm_capa = 0; |
| 906 | |
| 907 | range->we_version_compiled = WIRELESS_EXT; |
| 908 | range->we_version_source = 16; |
| 909 | |
| 910 | for (i = 0, val = 0; i < MAX_CHANNEL_NUM; i++) { |
| 911 | /* Include only legal frequencies for some countries */ |
| 912 | if (pmlmeext->channel_set[i].ChannelNum != 0) { |
| 913 | range->freq[val].i = pmlmeext->channel_set[i].ChannelNum; |
| 914 | range->freq[val].m = rtw_ch2freq(pmlmeext->channel_set[i].ChannelNum) * 100000; |
| 915 | range->freq[val].e = 1; |
| 916 | val++; |
| 917 | } |
| 918 | |
| 919 | if (val == IW_MAX_FREQUENCIES) |
| 920 | break; |
| 921 | } |
| 922 | |
| 923 | range->num_channels = val; |
| 924 | range->num_frequency = val; |
| 925 | |
| 926 | /* The following code will proivde the security capability to network manager. */ |
| 927 | /* If the driver doesn't provide this capability to network manager, */ |
Masanari Iida | 7efc02c | 2013-09-27 00:11:46 +0900 | [diff] [blame] | 928 | /* the WPA/WPA2 routers can't be chosen in the network manager. */ |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 929 | |
| 930 | /* |
| 931 | #define IW_SCAN_CAPA_NONE 0x00 |
| 932 | #define IW_SCAN_CAPA_ESSID 0x01 |
| 933 | #define IW_SCAN_CAPA_BSSID 0x02 |
| 934 | #define IW_SCAN_CAPA_CHANNEL 0x04 |
| 935 | #define IW_SCAN_CAPA_MODE 0x08 |
| 936 | #define IW_SCAN_CAPA_RATE 0x10 |
| 937 | #define IW_SCAN_CAPA_TYPE 0x20 |
| 938 | #define IW_SCAN_CAPA_TIME 0x40 |
| 939 | */ |
| 940 | |
| 941 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | |
| 942 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; |
| 943 | |
| 944 | range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE | |
| 945 | IW_SCAN_CAPA_BSSID | IW_SCAN_CAPA_CHANNEL | |
| 946 | IW_SCAN_CAPA_MODE | IW_SCAN_CAPA_RATE; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 947 | return 0; |
| 948 | } |
| 949 | |
| 950 | /* set bssid flow */ |
| 951 | /* s1. rtw_set_802_11_infrastructure_mode() */ |
| 952 | /* s2. rtw_set_802_11_authentication_mode() */ |
| 953 | /* s3. set_802_11_encryption_mode() */ |
| 954 | /* s4. rtw_set_802_11_bssid() */ |
| 955 | static int rtw_wx_set_wap(struct net_device *dev, |
| 956 | struct iw_request_info *info, |
| 957 | union iwreq_data *awrq, |
| 958 | char *extra) |
| 959 | { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 960 | uint ret = 0; |
| 961 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 962 | struct sockaddr *temp = (struct sockaddr *)awrq; |
| 963 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 964 | struct list_head *phead; |
| 965 | u8 *dst_bssid, *src_bssid; |
| 966 | struct __queue *queue = &(pmlmepriv->scanned_queue); |
| 967 | struct wlan_network *pnetwork = NULL; |
| 968 | enum ndis_802_11_auth_mode authmode; |
| 969 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 970 | if (_FAIL == rtw_pwr_wakeup(padapter)) { |
| 971 | ret = -1; |
| 972 | goto exit; |
| 973 | } |
| 974 | |
| 975 | if (!padapter->bup) { |
| 976 | ret = -1; |
| 977 | goto exit; |
| 978 | } |
| 979 | |
| 980 | if (temp->sa_family != ARPHRD_ETHER) { |
| 981 | ret = -EINVAL; |
| 982 | goto exit; |
| 983 | } |
| 984 | |
| 985 | authmode = padapter->securitypriv.ndisauthtype; |
Larry Finger | 7057dcb | 2013-12-19 22:38:34 -0600 | [diff] [blame] | 986 | spin_lock_bh(&queue->lock); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 987 | phead = get_list_head(queue); |
Larry Finger | c44e5e3 | 2014-02-09 15:15:58 -0600 | [diff] [blame] | 988 | pmlmepriv->pscanned = phead->next; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 989 | |
navin patidar | 8466070 | 2014-06-22 13:49:32 +0530 | [diff] [blame] | 990 | while (phead != pmlmepriv->pscanned) { |
Larry Finger | bea8810 | 2014-02-09 15:15:57 -0600 | [diff] [blame] | 991 | pnetwork = container_of(pmlmepriv->pscanned, struct wlan_network, list); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 992 | |
Larry Finger | c44e5e3 | 2014-02-09 15:15:58 -0600 | [diff] [blame] | 993 | pmlmepriv->pscanned = pmlmepriv->pscanned->next; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 994 | |
| 995 | dst_bssid = pnetwork->network.MacAddress; |
| 996 | |
| 997 | src_bssid = temp->sa_data; |
| 998 | |
| 999 | if ((!memcmp(dst_bssid, src_bssid, ETH_ALEN))) { |
| 1000 | if (!rtw_set_802_11_infrastructure_mode(padapter, pnetwork->network.InfrastructureMode)) { |
| 1001 | ret = -1; |
Larry Finger | e02bcf6 | 2013-12-19 22:38:35 -0600 | [diff] [blame] | 1002 | spin_unlock_bh(&queue->lock); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1003 | goto exit; |
| 1004 | } |
| 1005 | |
| 1006 | break; |
| 1007 | } |
| 1008 | } |
Larry Finger | e02bcf6 | 2013-12-19 22:38:35 -0600 | [diff] [blame] | 1009 | spin_unlock_bh(&queue->lock); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1010 | |
| 1011 | rtw_set_802_11_authentication_mode(padapter, authmode); |
| 1012 | /* set_802_11_encryption_mode(padapter, padapter->securitypriv.ndisencryptstatus); */ |
| 1013 | if (rtw_set_802_11_bssid(padapter, temp->sa_data) == false) { |
| 1014 | ret = -1; |
| 1015 | goto exit; |
| 1016 | } |
| 1017 | |
| 1018 | exit: |
| 1019 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1020 | return ret; |
| 1021 | } |
| 1022 | |
| 1023 | static int rtw_wx_get_wap(struct net_device *dev, |
| 1024 | struct iw_request_info *info, |
| 1025 | union iwreq_data *wrqu, char *extra) |
| 1026 | { |
| 1027 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 1028 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 1029 | struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network; |
| 1030 | |
| 1031 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; |
| 1032 | |
Aya Mahfouz | 8e5d943 | 2015-03-04 08:56:45 +0200 | [diff] [blame] | 1033 | eth_zero_addr(wrqu->ap_addr.sa_data); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1034 | |
| 1035 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_wx_get_wap\n")); |
| 1036 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1037 | if (((check_fwstate(pmlmepriv, _FW_LINKED)) == true) || |
| 1038 | ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) == true) || |
| 1039 | ((check_fwstate(pmlmepriv, WIFI_AP_STATE)) == true)) |
| 1040 | memcpy(wrqu->ap_addr.sa_data, pcur_bss->MacAddress, ETH_ALEN); |
| 1041 | else |
Aya Mahfouz | 8e5d943 | 2015-03-04 08:56:45 +0200 | [diff] [blame] | 1042 | eth_zero_addr(wrqu->ap_addr.sa_data); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1043 | return 0; |
| 1044 | } |
| 1045 | |
| 1046 | static int rtw_wx_set_mlme(struct net_device *dev, |
| 1047 | struct iw_request_info *info, |
| 1048 | union iwreq_data *wrqu, char *extra) |
| 1049 | { |
| 1050 | int ret = 0; |
| 1051 | u16 reason; |
| 1052 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 1053 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
| 1054 | |
Amit Ghadge | 4fe514d | 2016-09-04 22:53:35 +0530 | [diff] [blame] | 1055 | if (!mlme) |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1056 | return -1; |
| 1057 | |
| 1058 | DBG_88E("%s\n", __func__); |
| 1059 | |
| 1060 | reason = mlme->reason_code; |
| 1061 | |
| 1062 | DBG_88E("%s, cmd =%d, reason =%d\n", __func__, mlme->cmd, reason); |
| 1063 | |
| 1064 | switch (mlme->cmd) { |
| 1065 | case IW_MLME_DEAUTH: |
| 1066 | if (!rtw_set_802_11_disassociate(padapter)) |
| 1067 | ret = -1; |
| 1068 | break; |
| 1069 | case IW_MLME_DISASSOC: |
| 1070 | if (!rtw_set_802_11_disassociate(padapter)) |
| 1071 | ret = -1; |
| 1072 | break; |
| 1073 | default: |
| 1074 | return -EOPNOTSUPP; |
| 1075 | } |
| 1076 | return ret; |
| 1077 | } |
| 1078 | |
| 1079 | static int rtw_wx_set_scan(struct net_device *dev, struct iw_request_info *a, |
| 1080 | union iwreq_data *wrqu, char *extra) |
| 1081 | { |
| 1082 | u8 _status = false; |
| 1083 | int ret = 0; |
| 1084 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 1085 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
| 1086 | struct ndis_802_11_ssid ssid[RTW_SSID_SCAN_AMOUNT]; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1087 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_wx_set_scan\n")); |
| 1088 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1089 | if (padapter->registrypriv.mp_mode == 1) { |
| 1090 | if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) { |
| 1091 | ret = -1; |
| 1092 | goto exit; |
| 1093 | } |
| 1094 | } |
| 1095 | if (_FAIL == rtw_pwr_wakeup(padapter)) { |
| 1096 | ret = -1; |
| 1097 | goto exit; |
| 1098 | } |
| 1099 | |
| 1100 | if (padapter->bDriverStopped) { |
| 1101 | DBG_88E("bDriverStopped =%d\n", padapter->bDriverStopped); |
| 1102 | ret = -1; |
| 1103 | goto exit; |
| 1104 | } |
| 1105 | |
| 1106 | if (!padapter->bup) { |
| 1107 | ret = -1; |
| 1108 | goto exit; |
| 1109 | } |
| 1110 | |
| 1111 | if (!padapter->hw_init_completed) { |
| 1112 | ret = -1; |
| 1113 | goto exit; |
| 1114 | } |
| 1115 | |
| 1116 | /* When Busy Traffic, driver do not site survey. So driver return success. */ |
| 1117 | /* wpa_supplicant will not issue SIOCSIWSCAN cmd again after scan timeout. */ |
| 1118 | /* modify by thomas 2011-02-22. */ |
| 1119 | if (pmlmepriv->LinkDetectInfo.bBusyTraffic) { |
| 1120 | indicate_wx_scan_complete_event(padapter); |
| 1121 | goto exit; |
| 1122 | } |
| 1123 | |
| 1124 | if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING)) { |
| 1125 | indicate_wx_scan_complete_event(padapter); |
| 1126 | goto exit; |
| 1127 | } |
| 1128 | |
| 1129 | /* For the DMP WiFi Display project, the driver won't to scan because */ |
| 1130 | /* the pmlmepriv->scan_interval is always equal to 3. */ |
| 1131 | /* So, the wpa_supplicant won't find out the WPS SoftAP. */ |
| 1132 | |
navin patidar | 1ce3984 | 2014-06-22 13:49:28 +0530 | [diff] [blame] | 1133 | memset(ssid, 0, sizeof(struct ndis_802_11_ssid)*RTW_SSID_SCAN_AMOUNT); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1134 | |
| 1135 | if (wrqu->data.length == sizeof(struct iw_scan_req)) { |
| 1136 | struct iw_scan_req *req = (struct iw_scan_req *)extra; |
| 1137 | |
| 1138 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { |
Gulsah Kose | 3fd511d | 2014-10-30 03:03:46 +0200 | [diff] [blame] | 1139 | int len = min_t(int, req->essid_len, |
| 1140 | IW_ESSID_MAX_SIZE); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1141 | |
| 1142 | memcpy(ssid[0].Ssid, req->essid, len); |
| 1143 | ssid[0].SsidLength = len; |
| 1144 | |
| 1145 | DBG_88E("IW_SCAN_THIS_ESSID, ssid =%s, len =%d\n", req->essid, req->essid_len); |
| 1146 | |
Larry Finger | 7057dcb | 2013-12-19 22:38:34 -0600 | [diff] [blame] | 1147 | spin_lock_bh(&pmlmepriv->lock); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1148 | |
| 1149 | _status = rtw_sitesurvey_cmd(padapter, ssid, 1, NULL, 0); |
| 1150 | |
Larry Finger | e02bcf6 | 2013-12-19 22:38:35 -0600 | [diff] [blame] | 1151 | spin_unlock_bh(&pmlmepriv->lock); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1152 | } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) { |
| 1153 | DBG_88E("rtw_wx_set_scan, req->scan_type == IW_SCAN_TYPE_PASSIVE\n"); |
| 1154 | } |
| 1155 | } else { |
| 1156 | if (wrqu->data.length >= WEXT_CSCAN_HEADER_SIZE && |
| 1157 | !memcmp(extra, WEXT_CSCAN_HEADER, WEXT_CSCAN_HEADER_SIZE)) { |
| 1158 | int len = wrqu->data.length - WEXT_CSCAN_HEADER_SIZE; |
| 1159 | char *pos = extra+WEXT_CSCAN_HEADER_SIZE; |
| 1160 | char section; |
| 1161 | char sec_len; |
| 1162 | int ssid_index = 0; |
| 1163 | |
| 1164 | while (len >= 1) { |
| 1165 | section = *(pos++); |
| 1166 | len -= 1; |
| 1167 | |
| 1168 | switch (section) { |
| 1169 | case WEXT_CSCAN_SSID_SECTION: |
| 1170 | if (len < 1) { |
| 1171 | len = 0; |
| 1172 | break; |
| 1173 | } |
| 1174 | sec_len = *(pos++); len -= 1; |
| 1175 | if (sec_len > 0 && sec_len <= len) { |
| 1176 | ssid[ssid_index].SsidLength = sec_len; |
| 1177 | memcpy(ssid[ssid_index].Ssid, pos, ssid[ssid_index].SsidLength); |
| 1178 | ssid_index++; |
| 1179 | } |
| 1180 | pos += sec_len; |
| 1181 | len -= sec_len; |
| 1182 | break; |
| 1183 | case WEXT_CSCAN_TYPE_SECTION: |
| 1184 | case WEXT_CSCAN_CHANNEL_SECTION: |
| 1185 | pos += 1; |
| 1186 | len -= 1; |
| 1187 | break; |
| 1188 | case WEXT_CSCAN_PASV_DWELL_SECTION: |
| 1189 | case WEXT_CSCAN_HOME_DWELL_SECTION: |
| 1190 | case WEXT_CSCAN_ACTV_DWELL_SECTION: |
| 1191 | pos += 2; |
| 1192 | len -= 2; |
| 1193 | break; |
| 1194 | default: |
| 1195 | len = 0; /* stop parsing */ |
| 1196 | } |
| 1197 | } |
| 1198 | |
Masanari Iida | 7efc02c | 2013-09-27 00:11:46 +0900 | [diff] [blame] | 1199 | /* it has still some scan parameter to parse, we only do this now... */ |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1200 | _status = rtw_set_802_11_bssid_list_scan(padapter, ssid, RTW_SSID_SCAN_AMOUNT); |
| 1201 | } else { |
| 1202 | _status = rtw_set_802_11_bssid_list_scan(padapter, NULL, 0); |
| 1203 | } |
| 1204 | } |
| 1205 | |
| 1206 | if (!_status) |
| 1207 | ret = -1; |
| 1208 | |
| 1209 | exit: |
| 1210 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1211 | return ret; |
| 1212 | } |
| 1213 | |
| 1214 | static int rtw_wx_get_scan(struct net_device *dev, struct iw_request_info *a, |
| 1215 | union iwreq_data *wrqu, char *extra) |
| 1216 | { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1217 | struct list_head *plist, *phead; |
| 1218 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 1219 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 1220 | struct __queue *queue = &(pmlmepriv->scanned_queue); |
| 1221 | struct wlan_network *pnetwork = NULL; |
| 1222 | char *ev = extra; |
| 1223 | char *stop = ev + wrqu->data.length; |
| 1224 | u32 ret = 0; |
| 1225 | u32 cnt = 0; |
| 1226 | u32 wait_for_surveydone; |
| 1227 | int wait_status; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1228 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_wx_get_scan\n")); |
| 1229 | RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, (" Start of Query SIOCGIWSCAN .\n")); |
| 1230 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1231 | if (padapter->pwrctrlpriv.brfoffbyhw && padapter->bDriverStopped) { |
| 1232 | ret = -EINVAL; |
| 1233 | goto exit; |
| 1234 | } |
| 1235 | |
navin patidar | 2454e79 | 2014-07-10 09:11:27 +0530 | [diff] [blame] | 1236 | wait_for_surveydone = 100; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1237 | |
| 1238 | wait_status = _FW_UNDER_SURVEY | _FW_UNDER_LINKING; |
| 1239 | |
| 1240 | while (check_fwstate(pmlmepriv, wait_status)) { |
Larry Finger | 0da46e6 | 2013-12-19 22:38:41 -0600 | [diff] [blame] | 1241 | msleep(30); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1242 | cnt++; |
| 1243 | if (cnt > wait_for_surveydone) |
| 1244 | break; |
| 1245 | } |
| 1246 | |
Larry Finger | 7057dcb | 2013-12-19 22:38:34 -0600 | [diff] [blame] | 1247 | spin_lock_bh(&(pmlmepriv->scanned_queue.lock)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1248 | |
| 1249 | phead = get_list_head(queue); |
Larry Finger | c44e5e3 | 2014-02-09 15:15:58 -0600 | [diff] [blame] | 1250 | plist = phead->next; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1251 | |
navin patidar | 8466070 | 2014-06-22 13:49:32 +0530 | [diff] [blame] | 1252 | while (phead != plist) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1253 | if ((stop - ev) < SCAN_ITEM_SIZE) { |
| 1254 | ret = -E2BIG; |
| 1255 | break; |
| 1256 | } |
| 1257 | |
Larry Finger | bea8810 | 2014-02-09 15:15:57 -0600 | [diff] [blame] | 1258 | pnetwork = container_of(plist, struct wlan_network, list); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1259 | |
| 1260 | /* report network only if the current channel set contains the channel to which this network belongs */ |
| 1261 | if (rtw_ch_set_search_ch(padapter->mlmeextpriv.channel_set, pnetwork->network.Configuration.DSConfig) >= 0) |
| 1262 | ev = translate_scan(padapter, a, pnetwork, ev, stop); |
| 1263 | |
Larry Finger | c44e5e3 | 2014-02-09 15:15:58 -0600 | [diff] [blame] | 1264 | plist = plist->next; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1265 | } |
| 1266 | |
Larry Finger | e02bcf6 | 2013-12-19 22:38:35 -0600 | [diff] [blame] | 1267 | spin_unlock_bh(&pmlmepriv->scanned_queue.lock); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1268 | |
| 1269 | wrqu->data.length = ev-extra; |
| 1270 | wrqu->data.flags = 0; |
| 1271 | |
| 1272 | exit: |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1273 | return ret; |
| 1274 | } |
| 1275 | |
| 1276 | /* set ssid flow */ |
| 1277 | /* s1. rtw_set_802_11_infrastructure_mode() */ |
| 1278 | /* s2. set_802_11_authenticaion_mode() */ |
| 1279 | /* s3. set_802_11_encryption_mode() */ |
| 1280 | /* s4. rtw_set_802_11_ssid() */ |
| 1281 | static int rtw_wx_set_essid(struct net_device *dev, |
| 1282 | struct iw_request_info *a, |
| 1283 | union iwreq_data *wrqu, char *extra) |
| 1284 | { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1285 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 1286 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
| 1287 | struct __queue *queue = &pmlmepriv->scanned_queue; |
| 1288 | struct list_head *phead; |
| 1289 | struct wlan_network *pnetwork = NULL; |
| 1290 | enum ndis_802_11_auth_mode authmode; |
| 1291 | struct ndis_802_11_ssid ndis_ssid; |
| 1292 | u8 *dst_ssid, *src_ssid; |
| 1293 | |
| 1294 | uint ret = 0, len; |
| 1295 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1296 | |
| 1297 | RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, |
| 1298 | ("+rtw_wx_set_essid: fw_state = 0x%08x\n", get_fwstate(pmlmepriv))); |
| 1299 | if (_FAIL == rtw_pwr_wakeup(padapter)) { |
| 1300 | ret = -1; |
| 1301 | goto exit; |
| 1302 | } |
| 1303 | |
| 1304 | if (!padapter->bup) { |
| 1305 | ret = -1; |
| 1306 | goto exit; |
| 1307 | } |
| 1308 | |
| 1309 | if (wrqu->essid.length > IW_ESSID_MAX_SIZE) { |
| 1310 | ret = -E2BIG; |
| 1311 | goto exit; |
| 1312 | } |
| 1313 | |
| 1314 | if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { |
| 1315 | ret = -1; |
| 1316 | goto exit; |
| 1317 | } |
| 1318 | |
| 1319 | authmode = padapter->securitypriv.ndisauthtype; |
| 1320 | DBG_88E("=>%s\n", __func__); |
| 1321 | if (wrqu->essid.flags && wrqu->essid.length) { |
Ivan Safonov | ad8d8cd | 2015-10-27 22:18:10 +0700 | [diff] [blame] | 1322 | len = min_t(uint, wrqu->essid.length, IW_ESSID_MAX_SIZE); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1323 | |
| 1324 | if (wrqu->essid.length != 33) |
| 1325 | DBG_88E("ssid =%s, len =%d\n", extra, wrqu->essid.length); |
| 1326 | |
navin patidar | 1ce3984 | 2014-06-22 13:49:28 +0530 | [diff] [blame] | 1327 | memset(&ndis_ssid, 0, sizeof(struct ndis_802_11_ssid)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1328 | ndis_ssid.SsidLength = len; |
| 1329 | memcpy(ndis_ssid.Ssid, extra, len); |
| 1330 | src_ssid = ndis_ssid.Ssid; |
| 1331 | |
| 1332 | RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, ("rtw_wx_set_essid: ssid =[%s]\n", src_ssid)); |
Larry Finger | 7057dcb | 2013-12-19 22:38:34 -0600 | [diff] [blame] | 1333 | spin_lock_bh(&queue->lock); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1334 | phead = get_list_head(queue); |
Larry Finger | c44e5e3 | 2014-02-09 15:15:58 -0600 | [diff] [blame] | 1335 | pmlmepriv->pscanned = phead->next; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1336 | |
navin patidar | 8466070 | 2014-06-22 13:49:32 +0530 | [diff] [blame] | 1337 | while (phead != pmlmepriv->pscanned) { |
Larry Finger | bea8810 | 2014-02-09 15:15:57 -0600 | [diff] [blame] | 1338 | pnetwork = container_of(pmlmepriv->pscanned, struct wlan_network, list); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1339 | |
Larry Finger | c44e5e3 | 2014-02-09 15:15:58 -0600 | [diff] [blame] | 1340 | pmlmepriv->pscanned = pmlmepriv->pscanned->next; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1341 | |
| 1342 | dst_ssid = pnetwork->network.Ssid.Ssid; |
| 1343 | |
| 1344 | RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, |
| 1345 | ("rtw_wx_set_essid: dst_ssid =%s\n", |
| 1346 | pnetwork->network.Ssid.Ssid)); |
| 1347 | |
| 1348 | if ((!memcmp(dst_ssid, src_ssid, ndis_ssid.SsidLength)) && |
| 1349 | (pnetwork->network.Ssid.SsidLength == ndis_ssid.SsidLength)) { |
| 1350 | RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, |
| 1351 | ("rtw_wx_set_essid: find match, set infra mode\n")); |
| 1352 | |
| 1353 | if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) { |
| 1354 | if (pnetwork->network.InfrastructureMode != pmlmepriv->cur_network.network.InfrastructureMode) |
| 1355 | continue; |
| 1356 | } |
| 1357 | |
| 1358 | if (!rtw_set_802_11_infrastructure_mode(padapter, pnetwork->network.InfrastructureMode)) { |
| 1359 | ret = -1; |
Larry Finger | e02bcf6 | 2013-12-19 22:38:35 -0600 | [diff] [blame] | 1360 | spin_unlock_bh(&queue->lock); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1361 | goto exit; |
| 1362 | } |
| 1363 | |
| 1364 | break; |
| 1365 | } |
| 1366 | } |
Larry Finger | e02bcf6 | 2013-12-19 22:38:35 -0600 | [diff] [blame] | 1367 | spin_unlock_bh(&queue->lock); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1368 | RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, |
| 1369 | ("set ssid: set_802_11_auth. mode =%d\n", authmode)); |
| 1370 | rtw_set_802_11_authentication_mode(padapter, authmode); |
| 1371 | if (rtw_set_802_11_ssid(padapter, &ndis_ssid) == false) { |
| 1372 | ret = -1; |
| 1373 | goto exit; |
| 1374 | } |
| 1375 | } |
| 1376 | |
| 1377 | exit: |
| 1378 | |
| 1379 | DBG_88E("<=%s, ret %d\n", __func__, ret); |
| 1380 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1381 | |
| 1382 | return ret; |
| 1383 | } |
| 1384 | |
| 1385 | static int rtw_wx_get_essid(struct net_device *dev, |
| 1386 | struct iw_request_info *a, |
| 1387 | union iwreq_data *wrqu, char *extra) |
| 1388 | { |
| 1389 | u32 len, ret = 0; |
| 1390 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 1391 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 1392 | struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network; |
| 1393 | |
| 1394 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_wx_get_essid\n")); |
| 1395 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1396 | |
| 1397 | if ((check_fwstate(pmlmepriv, _FW_LINKED)) || |
| 1398 | (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE))) { |
| 1399 | len = pcur_bss->Ssid.SsidLength; |
| 1400 | |
| 1401 | wrqu->essid.length = len; |
| 1402 | |
| 1403 | memcpy(extra, pcur_bss->Ssid.Ssid, len); |
| 1404 | |
| 1405 | wrqu->essid.flags = 1; |
| 1406 | } else { |
| 1407 | ret = -1; |
| 1408 | goto exit; |
| 1409 | } |
| 1410 | |
| 1411 | exit: |
| 1412 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1413 | |
| 1414 | return ret; |
| 1415 | } |
| 1416 | |
| 1417 | static int rtw_wx_set_rate(struct net_device *dev, |
| 1418 | struct iw_request_info *a, |
| 1419 | union iwreq_data *wrqu, char *extra) |
| 1420 | { |
Sudip Mukherjee | c78a964 | 2014-11-07 16:50:45 +0530 | [diff] [blame] | 1421 | int i; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1422 | u8 datarates[NumRates]; |
| 1423 | u32 target_rate = wrqu->bitrate.value; |
| 1424 | u32 fixed = wrqu->bitrate.fixed; |
| 1425 | u32 ratevalue = 0; |
| 1426 | u8 mpdatarate[NumRates] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0xff}; |
| 1427 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1428 | |
| 1429 | RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, (" rtw_wx_set_rate\n")); |
| 1430 | RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, ("target_rate = %d, fixed = %d\n", target_rate, fixed)); |
| 1431 | |
| 1432 | if (target_rate == -1) { |
| 1433 | ratevalue = 11; |
| 1434 | goto set_rate; |
| 1435 | } |
| 1436 | target_rate = target_rate/100000; |
| 1437 | |
| 1438 | switch (target_rate) { |
| 1439 | case 10: |
| 1440 | ratevalue = 0; |
| 1441 | break; |
| 1442 | case 20: |
| 1443 | ratevalue = 1; |
| 1444 | break; |
| 1445 | case 55: |
| 1446 | ratevalue = 2; |
| 1447 | break; |
| 1448 | case 60: |
| 1449 | ratevalue = 3; |
| 1450 | break; |
| 1451 | case 90: |
| 1452 | ratevalue = 4; |
| 1453 | break; |
| 1454 | case 110: |
| 1455 | ratevalue = 5; |
| 1456 | break; |
| 1457 | case 120: |
| 1458 | ratevalue = 6; |
| 1459 | break; |
| 1460 | case 180: |
| 1461 | ratevalue = 7; |
| 1462 | break; |
| 1463 | case 240: |
| 1464 | ratevalue = 8; |
| 1465 | break; |
| 1466 | case 360: |
| 1467 | ratevalue = 9; |
| 1468 | break; |
| 1469 | case 480: |
| 1470 | ratevalue = 10; |
| 1471 | break; |
| 1472 | case 540: |
| 1473 | ratevalue = 11; |
| 1474 | break; |
| 1475 | default: |
| 1476 | ratevalue = 11; |
| 1477 | break; |
| 1478 | } |
| 1479 | |
| 1480 | set_rate: |
| 1481 | |
| 1482 | for (i = 0; i < NumRates; i++) { |
| 1483 | if (ratevalue == mpdatarate[i]) { |
| 1484 | datarates[i] = mpdatarate[i]; |
| 1485 | if (fixed == 0) |
| 1486 | break; |
| 1487 | } else { |
| 1488 | datarates[i] = 0xff; |
| 1489 | } |
| 1490 | |
| 1491 | RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, ("datarate_inx =%d\n", datarates[i])); |
| 1492 | } |
| 1493 | |
Sudip Mukherjee | c78a964 | 2014-11-07 16:50:45 +0530 | [diff] [blame] | 1494 | return 0; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | static int rtw_wx_get_rate(struct net_device *dev, |
| 1498 | struct iw_request_info *info, |
| 1499 | union iwreq_data *wrqu, char *extra) |
| 1500 | { |
| 1501 | u16 max_rate = 0; |
| 1502 | |
| 1503 | max_rate = rtw_get_cur_max_rate((struct adapter *)rtw_netdev_priv(dev)); |
| 1504 | |
| 1505 | if (max_rate == 0) |
| 1506 | return -EPERM; |
| 1507 | |
| 1508 | wrqu->bitrate.fixed = 0; /* no auto select */ |
| 1509 | wrqu->bitrate.value = max_rate * 100000; |
| 1510 | |
| 1511 | return 0; |
| 1512 | } |
| 1513 | |
| 1514 | static int rtw_wx_set_rts(struct net_device *dev, |
| 1515 | struct iw_request_info *info, |
| 1516 | union iwreq_data *wrqu, char *extra) |
| 1517 | { |
| 1518 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 1519 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1520 | |
| 1521 | if (wrqu->rts.disabled) { |
| 1522 | padapter->registrypriv.rts_thresh = 2347; |
| 1523 | } else { |
| 1524 | if (wrqu->rts.value < 0 || |
| 1525 | wrqu->rts.value > 2347) |
| 1526 | return -EINVAL; |
| 1527 | |
| 1528 | padapter->registrypriv.rts_thresh = wrqu->rts.value; |
| 1529 | } |
| 1530 | |
| 1531 | DBG_88E("%s, rts_thresh =%d\n", __func__, padapter->registrypriv.rts_thresh); |
| 1532 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1533 | |
| 1534 | return 0; |
| 1535 | } |
| 1536 | |
| 1537 | static int rtw_wx_get_rts(struct net_device *dev, |
| 1538 | struct iw_request_info *info, |
| 1539 | union iwreq_data *wrqu, char *extra) |
| 1540 | { |
| 1541 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 1542 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1543 | |
| 1544 | DBG_88E("%s, rts_thresh =%d\n", __func__, padapter->registrypriv.rts_thresh); |
| 1545 | |
| 1546 | wrqu->rts.value = padapter->registrypriv.rts_thresh; |
| 1547 | wrqu->rts.fixed = 0; /* no auto select */ |
| 1548 | /* wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); */ |
| 1549 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1550 | |
| 1551 | return 0; |
| 1552 | } |
| 1553 | |
| 1554 | static int rtw_wx_set_frag(struct net_device *dev, |
| 1555 | struct iw_request_info *info, |
| 1556 | union iwreq_data *wrqu, char *extra) |
| 1557 | { |
| 1558 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 1559 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1560 | |
| 1561 | if (wrqu->frag.disabled) { |
| 1562 | padapter->xmitpriv.frag_len = MAX_FRAG_THRESHOLD; |
| 1563 | } else { |
| 1564 | if (wrqu->frag.value < MIN_FRAG_THRESHOLD || |
| 1565 | wrqu->frag.value > MAX_FRAG_THRESHOLD) |
| 1566 | return -EINVAL; |
| 1567 | |
| 1568 | padapter->xmitpriv.frag_len = wrqu->frag.value & ~0x1; |
| 1569 | } |
| 1570 | |
| 1571 | DBG_88E("%s, frag_len =%d\n", __func__, padapter->xmitpriv.frag_len); |
| 1572 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1573 | |
| 1574 | return 0; |
| 1575 | } |
| 1576 | |
| 1577 | static int rtw_wx_get_frag(struct net_device *dev, |
| 1578 | struct iw_request_info *info, |
| 1579 | union iwreq_data *wrqu, char *extra) |
| 1580 | { |
| 1581 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 1582 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1583 | |
| 1584 | DBG_88E("%s, frag_len =%d\n", __func__, padapter->xmitpriv.frag_len); |
| 1585 | |
| 1586 | wrqu->frag.value = padapter->xmitpriv.frag_len; |
| 1587 | wrqu->frag.fixed = 0; /* no auto select */ |
| 1588 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1589 | |
| 1590 | return 0; |
| 1591 | } |
| 1592 | |
| 1593 | static int rtw_wx_get_retry(struct net_device *dev, |
| 1594 | struct iw_request_info *info, |
| 1595 | union iwreq_data *wrqu, char *extra) |
| 1596 | { |
| 1597 | wrqu->retry.value = 7; |
| 1598 | wrqu->retry.fixed = 0; /* no auto select */ |
| 1599 | wrqu->retry.disabled = 1; |
| 1600 | |
| 1601 | return 0; |
| 1602 | } |
| 1603 | |
| 1604 | static int rtw_wx_set_enc(struct net_device *dev, |
| 1605 | struct iw_request_info *info, |
| 1606 | union iwreq_data *wrqu, char *keybuf) |
| 1607 | { |
| 1608 | u32 key, ret = 0; |
| 1609 | u32 keyindex_provided; |
| 1610 | struct ndis_802_11_wep wep; |
| 1611 | enum ndis_802_11_auth_mode authmode; |
| 1612 | |
| 1613 | struct iw_point *erq = &(wrqu->encoding); |
| 1614 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 1615 | struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv; |
| 1616 | DBG_88E("+rtw_wx_set_enc, flags = 0x%x\n", erq->flags); |
| 1617 | |
navin patidar | 1ce3984 | 2014-06-22 13:49:28 +0530 | [diff] [blame] | 1618 | memset(&wep, 0, sizeof(struct ndis_802_11_wep)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1619 | |
| 1620 | key = erq->flags & IW_ENCODE_INDEX; |
| 1621 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1622 | |
| 1623 | if (erq->flags & IW_ENCODE_DISABLED) { |
| 1624 | DBG_88E("EncryptionDisabled\n"); |
| 1625 | padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled; |
| 1626 | padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_; |
| 1627 | padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_; |
Luca Ceresoli | 2ff4e79 | 2015-04-16 23:28:03 +0200 | [diff] [blame] | 1628 | padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1629 | authmode = Ndis802_11AuthModeOpen; |
| 1630 | padapter->securitypriv.ndisauthtype = authmode; |
| 1631 | |
| 1632 | goto exit; |
| 1633 | } |
| 1634 | |
| 1635 | if (key) { |
| 1636 | if (key > WEP_KEYS) |
| 1637 | return -EINVAL; |
| 1638 | key--; |
| 1639 | keyindex_provided = 1; |
| 1640 | } else { |
| 1641 | keyindex_provided = 0; |
| 1642 | key = padapter->securitypriv.dot11PrivacyKeyIndex; |
| 1643 | DBG_88E("rtw_wx_set_enc, key =%d\n", key); |
| 1644 | } |
| 1645 | |
| 1646 | /* set authentication mode */ |
| 1647 | if (erq->flags & IW_ENCODE_OPEN) { |
| 1648 | DBG_88E("rtw_wx_set_enc():IW_ENCODE_OPEN\n"); |
| 1649 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;/* Ndis802_11EncryptionDisabled; */ |
| 1650 | padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; |
| 1651 | padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_; |
| 1652 | padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_; |
| 1653 | authmode = Ndis802_11AuthModeOpen; |
| 1654 | padapter->securitypriv.ndisauthtype = authmode; |
| 1655 | } else if (erq->flags & IW_ENCODE_RESTRICTED) { |
| 1656 | DBG_88E("rtw_wx_set_enc():IW_ENCODE_RESTRICTED\n"); |
| 1657 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; |
| 1658 | padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Shared; |
| 1659 | padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_; |
| 1660 | padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_; |
| 1661 | authmode = Ndis802_11AuthModeShared; |
| 1662 | padapter->securitypriv.ndisauthtype = authmode; |
| 1663 | } else { |
| 1664 | DBG_88E("rtw_wx_set_enc():erq->flags = 0x%x\n", erq->flags); |
| 1665 | |
| 1666 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled;/* Ndis802_11EncryptionDisabled; */ |
Luca Ceresoli | 2ff4e79 | 2015-04-16 23:28:03 +0200 | [diff] [blame] | 1667 | padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1668 | padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_; |
| 1669 | padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_; |
| 1670 | authmode = Ndis802_11AuthModeOpen; |
| 1671 | padapter->securitypriv.ndisauthtype = authmode; |
| 1672 | } |
| 1673 | |
| 1674 | wep.KeyIndex = key; |
| 1675 | if (erq->length > 0) { |
| 1676 | wep.KeyLength = erq->length <= 5 ? 5 : 13; |
| 1677 | |
Ivan Safonov | 5e3027b | 2016-03-02 14:59:01 +0700 | [diff] [blame] | 1678 | wep.Length = wep.KeyLength + offsetof(struct ndis_802_11_wep, KeyMaterial); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1679 | } else { |
| 1680 | wep.KeyLength = 0; |
| 1681 | |
| 1682 | if (keyindex_provided == 1) { |
| 1683 | /* set key_id only, no given KeyMaterial(erq->length == 0). */ |
| 1684 | padapter->securitypriv.dot11PrivacyKeyIndex = key; |
| 1685 | |
| 1686 | DBG_88E("(keyindex_provided == 1), keyid =%d, key_len =%d\n", key, padapter->securitypriv.dot11DefKeylen[key]); |
| 1687 | |
| 1688 | switch (padapter->securitypriv.dot11DefKeylen[key]) { |
| 1689 | case 5: |
| 1690 | padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_; |
| 1691 | break; |
| 1692 | case 13: |
| 1693 | padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_; |
| 1694 | break; |
| 1695 | default: |
| 1696 | padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_; |
| 1697 | break; |
| 1698 | } |
| 1699 | |
| 1700 | goto exit; |
| 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | wep.KeyIndex |= 0x80000000; |
| 1705 | |
| 1706 | memcpy(wep.KeyMaterial, keybuf, wep.KeyLength); |
| 1707 | |
| 1708 | if (rtw_set_802_11_add_wep(padapter, &wep) == false) { |
| 1709 | if (rf_on == pwrpriv->rf_pwrstate) |
| 1710 | ret = -EOPNOTSUPP; |
| 1711 | goto exit; |
| 1712 | } |
| 1713 | |
| 1714 | exit: |
| 1715 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1716 | |
| 1717 | return ret; |
| 1718 | } |
| 1719 | |
| 1720 | static int rtw_wx_get_enc(struct net_device *dev, |
| 1721 | struct iw_request_info *info, |
| 1722 | union iwreq_data *wrqu, char *keybuf) |
| 1723 | { |
| 1724 | uint key, ret = 0; |
| 1725 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 1726 | struct iw_point *erq = &(wrqu->encoding); |
| 1727 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 1728 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1729 | |
| 1730 | if (check_fwstate(pmlmepriv, _FW_LINKED) != true) { |
| 1731 | if (!check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) { |
| 1732 | erq->length = 0; |
| 1733 | erq->flags |= IW_ENCODE_DISABLED; |
| 1734 | return 0; |
| 1735 | } |
| 1736 | } |
| 1737 | |
| 1738 | key = erq->flags & IW_ENCODE_INDEX; |
| 1739 | |
| 1740 | if (key) { |
| 1741 | if (key > WEP_KEYS) |
| 1742 | return -EINVAL; |
| 1743 | key--; |
| 1744 | } else { |
| 1745 | key = padapter->securitypriv.dot11PrivacyKeyIndex; |
| 1746 | } |
| 1747 | |
| 1748 | erq->flags = key + 1; |
| 1749 | |
| 1750 | switch (padapter->securitypriv.ndisencryptstatus) { |
| 1751 | case Ndis802_11EncryptionNotSupported: |
| 1752 | case Ndis802_11EncryptionDisabled: |
| 1753 | erq->length = 0; |
| 1754 | erq->flags |= IW_ENCODE_DISABLED; |
| 1755 | break; |
| 1756 | case Ndis802_11Encryption1Enabled: |
| 1757 | erq->length = padapter->securitypriv.dot11DefKeylen[key]; |
| 1758 | if (erq->length) { |
| 1759 | memcpy(keybuf, padapter->securitypriv.dot11DefKey[key].skey, padapter->securitypriv.dot11DefKeylen[key]); |
| 1760 | |
| 1761 | erq->flags |= IW_ENCODE_ENABLED; |
| 1762 | |
| 1763 | if (padapter->securitypriv.ndisauthtype == Ndis802_11AuthModeOpen) |
| 1764 | erq->flags |= IW_ENCODE_OPEN; |
| 1765 | else if (padapter->securitypriv.ndisauthtype == Ndis802_11AuthModeShared) |
| 1766 | erq->flags |= IW_ENCODE_RESTRICTED; |
| 1767 | } else { |
| 1768 | erq->length = 0; |
| 1769 | erq->flags |= IW_ENCODE_DISABLED; |
| 1770 | } |
| 1771 | break; |
| 1772 | case Ndis802_11Encryption2Enabled: |
| 1773 | case Ndis802_11Encryption3Enabled: |
| 1774 | erq->length = 16; |
| 1775 | erq->flags |= (IW_ENCODE_ENABLED | IW_ENCODE_OPEN | IW_ENCODE_NOKEY); |
| 1776 | break; |
| 1777 | default: |
| 1778 | erq->length = 0; |
| 1779 | erq->flags |= IW_ENCODE_DISABLED; |
| 1780 | break; |
| 1781 | } |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1782 | |
| 1783 | return ret; |
| 1784 | } |
| 1785 | |
| 1786 | static int rtw_wx_get_power(struct net_device *dev, |
| 1787 | struct iw_request_info *info, |
| 1788 | union iwreq_data *wrqu, char *extra) |
| 1789 | { |
| 1790 | wrqu->power.value = 0; |
| 1791 | wrqu->power.fixed = 0; /* no auto select */ |
| 1792 | wrqu->power.disabled = 1; |
| 1793 | |
| 1794 | return 0; |
| 1795 | } |
| 1796 | |
| 1797 | static int rtw_wx_set_gen_ie(struct net_device *dev, |
| 1798 | struct iw_request_info *info, |
| 1799 | union iwreq_data *wrqu, char *extra) |
| 1800 | { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1801 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 1802 | |
Aya Mahfouz | 5f70306 | 2015-02-27 14:54:23 +0200 | [diff] [blame] | 1803 | return rtw_set_wpa_ie(padapter, extra, wrqu->data.length); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1804 | } |
| 1805 | |
| 1806 | static int rtw_wx_set_auth(struct net_device *dev, |
| 1807 | struct iw_request_info *info, |
| 1808 | union iwreq_data *wrqu, char *extra) |
| 1809 | { |
| 1810 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 1811 | struct iw_param *param = (struct iw_param *)&(wrqu->param); |
| 1812 | int ret = 0; |
| 1813 | |
| 1814 | switch (param->flags & IW_AUTH_INDEX) { |
| 1815 | case IW_AUTH_WPA_VERSION: |
| 1816 | break; |
| 1817 | case IW_AUTH_CIPHER_PAIRWISE: |
| 1818 | |
| 1819 | break; |
| 1820 | case IW_AUTH_CIPHER_GROUP: |
| 1821 | |
| 1822 | break; |
| 1823 | case IW_AUTH_KEY_MGMT: |
| 1824 | /* |
| 1825 | * ??? does not use these parameters |
| 1826 | */ |
| 1827 | break; |
| 1828 | case IW_AUTH_TKIP_COUNTERMEASURES: |
| 1829 | if (param->value) { |
| 1830 | /* wpa_supplicant is enabling the tkip countermeasure. */ |
| 1831 | padapter->securitypriv.btkip_countermeasure = true; |
| 1832 | } else { |
| 1833 | /* wpa_supplicant is disabling the tkip countermeasure. */ |
| 1834 | padapter->securitypriv.btkip_countermeasure = false; |
| 1835 | } |
| 1836 | break; |
| 1837 | case IW_AUTH_DROP_UNENCRYPTED: |
| 1838 | /* HACK: |
| 1839 | * |
| 1840 | * wpa_supplicant calls set_wpa_enabled when the driver |
| 1841 | * is loaded and unloaded, regardless of if WPA is being |
| 1842 | * used. No other calls are made which can be used to |
| 1843 | * determine if encryption will be used or not prior to |
| 1844 | * association being expected. If encryption is not being |
| 1845 | * used, drop_unencrypted is set to false, else true -- we |
| 1846 | * can use this to determine if the CAP_PRIVACY_ON bit should |
| 1847 | * be set. |
| 1848 | */ |
| 1849 | |
| 1850 | if (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption1Enabled) |
| 1851 | break;/* it means init value, or using wep, ndisencryptstatus = Ndis802_11Encryption1Enabled, */ |
| 1852 | /* then it needn't reset it; */ |
| 1853 | |
| 1854 | if (param->value) { |
| 1855 | padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled; |
| 1856 | padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_; |
| 1857 | padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_; |
Luca Ceresoli | 2ff4e79 | 2015-04-16 23:28:03 +0200 | [diff] [blame] | 1858 | padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1859 | padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen; |
| 1860 | } |
| 1861 | |
| 1862 | break; |
| 1863 | case IW_AUTH_80211_AUTH_ALG: |
| 1864 | /* |
| 1865 | * It's the starting point of a link layer connection using wpa_supplicant |
| 1866 | */ |
| 1867 | if (check_fwstate(&padapter->mlmepriv, _FW_LINKED)) { |
| 1868 | LeaveAllPowerSaveMode(padapter); |
| 1869 | rtw_disassoc_cmd(padapter, 500, false); |
| 1870 | DBG_88E("%s...call rtw_indicate_disconnect\n ", __func__); |
| 1871 | rtw_indicate_disconnect(padapter); |
Buţiu Alexandru Octavian | b4ba3b5 | 2015-07-24 00:13:27 +0300 | [diff] [blame] | 1872 | rtw_free_assoc_resources(padapter); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1873 | } |
| 1874 | ret = wpa_set_auth_algs(dev, (u32)param->value); |
| 1875 | break; |
| 1876 | case IW_AUTH_WPA_ENABLED: |
| 1877 | break; |
| 1878 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 1879 | break; |
| 1880 | case IW_AUTH_PRIVACY_INVOKED: |
| 1881 | break; |
| 1882 | default: |
| 1883 | return -EOPNOTSUPP; |
| 1884 | } |
| 1885 | |
| 1886 | return ret; |
| 1887 | } |
| 1888 | |
| 1889 | static int rtw_wx_set_enc_ext(struct net_device *dev, |
| 1890 | struct iw_request_info *info, |
| 1891 | union iwreq_data *wrqu, char *extra) |
| 1892 | { |
| 1893 | char *alg_name; |
| 1894 | u32 param_len; |
| 1895 | struct ieee_param *param = NULL; |
| 1896 | struct iw_point *pencoding = &wrqu->encoding; |
| 1897 | struct iw_encode_ext *pext = (struct iw_encode_ext *)extra; |
| 1898 | int ret = 0; |
| 1899 | |
| 1900 | param_len = sizeof(struct ieee_param) + pext->key_len; |
| 1901 | param = (struct ieee_param *)rtw_malloc(param_len); |
Amit Ghadge | 4fe514d | 2016-09-04 22:53:35 +0530 | [diff] [blame] | 1902 | if (!param) |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1903 | return -1; |
| 1904 | |
navin patidar | 1ce3984 | 2014-06-22 13:49:28 +0530 | [diff] [blame] | 1905 | memset(param, 0, param_len); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1906 | |
| 1907 | param->cmd = IEEE_CMD_SET_ENCRYPTION; |
Hari Prasath Gujulan Elango | a3124e7 | 2016-01-20 12:52:58 +0000 | [diff] [blame] | 1908 | eth_broadcast_addr(param->sta_addr); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1909 | |
| 1910 | switch (pext->alg) { |
| 1911 | case IW_ENCODE_ALG_NONE: |
| 1912 | /* todo: remove key */ |
| 1913 | /* remove = 1; */ |
| 1914 | alg_name = "none"; |
| 1915 | break; |
| 1916 | case IW_ENCODE_ALG_WEP: |
| 1917 | alg_name = "WEP"; |
| 1918 | break; |
| 1919 | case IW_ENCODE_ALG_TKIP: |
| 1920 | alg_name = "TKIP"; |
| 1921 | break; |
| 1922 | case IW_ENCODE_ALG_CCMP: |
| 1923 | alg_name = "CCMP"; |
| 1924 | break; |
| 1925 | default: |
Christian Engelmayer | 5d57f1e | 2014-05-07 21:31:20 +0200 | [diff] [blame] | 1926 | ret = -1; |
| 1927 | goto exit; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | strncpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN); |
| 1931 | |
| 1932 | if (pext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) |
| 1933 | param->u.crypt.set_tx = 1; |
| 1934 | |
| 1935 | /* cliW: WEP does not have group key |
| 1936 | * just not checking GROUP key setting |
| 1937 | */ |
| 1938 | if ((pext->alg != IW_ENCODE_ALG_WEP) && |
| 1939 | (pext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)) |
| 1940 | param->u.crypt.set_tx = 0; |
| 1941 | |
| 1942 | param->u.crypt.idx = (pencoding->flags&0x00FF) - 1; |
| 1943 | |
| 1944 | if (pext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) |
| 1945 | memcpy(param->u.crypt.seq, pext->rx_seq, 8); |
| 1946 | |
| 1947 | if (pext->key_len) { |
| 1948 | param->u.crypt.key_len = pext->key_len; |
| 1949 | memcpy(param->u.crypt.key, pext + 1, pext->key_len); |
| 1950 | } |
| 1951 | |
| 1952 | ret = wpa_set_encryption(dev, param, param_len); |
| 1953 | |
Christian Engelmayer | 5d57f1e | 2014-05-07 21:31:20 +0200 | [diff] [blame] | 1954 | exit: |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1955 | kfree(param); |
| 1956 | return ret; |
| 1957 | } |
| 1958 | |
| 1959 | static int rtw_wx_get_nick(struct net_device *dev, |
| 1960 | struct iw_request_info *info, |
| 1961 | union iwreq_data *wrqu, char *extra) |
| 1962 | { |
| 1963 | if (extra) { |
| 1964 | wrqu->data.length = 14; |
| 1965 | wrqu->data.flags = 1; |
| 1966 | memcpy(extra, "<WIFI@REALTEK>", 14); |
| 1967 | } |
| 1968 | |
| 1969 | /* dump debug info here */ |
| 1970 | return 0; |
| 1971 | } |
| 1972 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1973 | static int dummy(struct net_device *dev, struct iw_request_info *a, |
| 1974 | union iwreq_data *wrqu, char *b) |
| 1975 | { |
| 1976 | return -1; |
| 1977 | } |
| 1978 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 1979 | static int wpa_set_param(struct net_device *dev, u8 name, u32 value) |
| 1980 | { |
| 1981 | uint ret = 0; |
| 1982 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 1983 | |
| 1984 | switch (name) { |
| 1985 | case IEEE_PARAM_WPA_ENABLED: |
| 1986 | padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; /* 802.1x */ |
| 1987 | switch ((value)&0xff) { |
| 1988 | case 1: /* WPA */ |
| 1989 | padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPAPSK; /* WPA_PSK */ |
| 1990 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled; |
| 1991 | break; |
| 1992 | case 2: /* WPA2 */ |
| 1993 | padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPA2PSK; /* WPA2_PSK */ |
| 1994 | padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled; |
| 1995 | break; |
| 1996 | } |
| 1997 | RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, |
| 1998 | ("wpa_set_param:padapter->securitypriv.ndisauthtype =%d\n", padapter->securitypriv.ndisauthtype)); |
| 1999 | break; |
| 2000 | case IEEE_PARAM_TKIP_COUNTERMEASURES: |
| 2001 | break; |
| 2002 | case IEEE_PARAM_DROP_UNENCRYPTED: { |
| 2003 | /* HACK: |
| 2004 | * |
| 2005 | * wpa_supplicant calls set_wpa_enabled when the driver |
| 2006 | * is loaded and unloaded, regardless of if WPA is being |
| 2007 | * used. No other calls are made which can be used to |
| 2008 | * determine if encryption will be used or not prior to |
| 2009 | * association being expected. If encryption is not being |
| 2010 | * used, drop_unencrypted is set to false, else true -- we |
| 2011 | * can use this to determine if the CAP_PRIVACY_ON bit should |
| 2012 | * be set. |
| 2013 | */ |
| 2014 | |
| 2015 | break; |
| 2016 | } |
| 2017 | case IEEE_PARAM_PRIVACY_INVOKED: |
| 2018 | break; |
| 2019 | |
| 2020 | case IEEE_PARAM_AUTH_ALGS: |
| 2021 | ret = wpa_set_auth_algs(dev, value); |
| 2022 | break; |
| 2023 | case IEEE_PARAM_IEEE_802_1X: |
| 2024 | break; |
| 2025 | case IEEE_PARAM_WPAX_SELECT: |
| 2026 | break; |
| 2027 | default: |
| 2028 | ret = -EOPNOTSUPP; |
| 2029 | break; |
| 2030 | } |
| 2031 | return ret; |
| 2032 | } |
| 2033 | |
| 2034 | static int wpa_mlme(struct net_device *dev, u32 command, u32 reason) |
| 2035 | { |
| 2036 | int ret = 0; |
| 2037 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 2038 | |
| 2039 | switch (command) { |
| 2040 | case IEEE_MLME_STA_DEAUTH: |
| 2041 | if (!rtw_set_802_11_disassociate(padapter)) |
| 2042 | ret = -1; |
| 2043 | break; |
| 2044 | case IEEE_MLME_STA_DISASSOC: |
| 2045 | if (!rtw_set_802_11_disassociate(padapter)) |
| 2046 | ret = -1; |
| 2047 | break; |
| 2048 | default: |
| 2049 | ret = -EOPNOTSUPP; |
| 2050 | break; |
| 2051 | } |
| 2052 | |
| 2053 | return ret; |
| 2054 | } |
| 2055 | |
| 2056 | static int wpa_supplicant_ioctl(struct net_device *dev, struct iw_point *p) |
| 2057 | { |
| 2058 | struct ieee_param *param; |
| 2059 | uint ret = 0; |
| 2060 | |
| 2061 | if (p->length < sizeof(struct ieee_param) || !p->pointer) { |
| 2062 | ret = -EINVAL; |
| 2063 | goto out; |
| 2064 | } |
| 2065 | |
| 2066 | param = (struct ieee_param *)rtw_malloc(p->length); |
Amit Ghadge | 4fe514d | 2016-09-04 22:53:35 +0530 | [diff] [blame] | 2067 | if (!param) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2068 | ret = -ENOMEM; |
| 2069 | goto out; |
| 2070 | } |
| 2071 | |
| 2072 | if (copy_from_user(param, p->pointer, p->length)) { |
| 2073 | kfree(param); |
| 2074 | ret = -EFAULT; |
| 2075 | goto out; |
| 2076 | } |
| 2077 | |
| 2078 | switch (param->cmd) { |
| 2079 | case IEEE_CMD_SET_WPA_PARAM: |
| 2080 | ret = wpa_set_param(dev, param->u.wpa_param.name, param->u.wpa_param.value); |
| 2081 | break; |
| 2082 | |
| 2083 | case IEEE_CMD_SET_WPA_IE: |
| 2084 | ret = rtw_set_wpa_ie((struct adapter *)rtw_netdev_priv(dev), |
| 2085 | (char *)param->u.wpa_ie.data, (u16)param->u.wpa_ie.len); |
| 2086 | break; |
| 2087 | |
| 2088 | case IEEE_CMD_SET_ENCRYPTION: |
| 2089 | ret = wpa_set_encryption(dev, param, p->length); |
| 2090 | break; |
| 2091 | |
| 2092 | case IEEE_CMD_MLME: |
| 2093 | ret = wpa_mlme(dev, param->u.mlme.command, param->u.mlme.reason_code); |
| 2094 | break; |
| 2095 | |
| 2096 | default: |
| 2097 | DBG_88E("Unknown WPA supplicant request: %d\n", param->cmd); |
| 2098 | ret = -EOPNOTSUPP; |
| 2099 | break; |
| 2100 | } |
| 2101 | |
| 2102 | if (ret == 0 && copy_to_user(p->pointer, param, p->length)) |
| 2103 | ret = -EFAULT; |
| 2104 | |
| 2105 | kfree(param); |
| 2106 | |
| 2107 | out: |
| 2108 | |
| 2109 | return ret; |
| 2110 | } |
| 2111 | |
| 2112 | #ifdef CONFIG_88EU_AP_MODE |
| 2113 | static u8 set_pairwise_key(struct adapter *padapter, struct sta_info *psta) |
| 2114 | { |
| 2115 | struct cmd_obj *ph2c; |
| 2116 | struct set_stakey_parm *psetstakey_para; |
| 2117 | struct cmd_priv *pcmdpriv = &padapter->cmdpriv; |
| 2118 | u8 res = _SUCCESS; |
| 2119 | |
navin patidar | fadbe0c | 2014-06-22 14:06:23 +0530 | [diff] [blame] | 2120 | ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); |
Bhaktipriya Shridhar | 4ada295 | 2016-03-22 20:19:49 +0530 | [diff] [blame] | 2121 | if (!ph2c) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2122 | res = _FAIL; |
| 2123 | goto exit; |
| 2124 | } |
| 2125 | |
navin patidar | fadbe0c | 2014-06-22 14:06:23 +0530 | [diff] [blame] | 2126 | psetstakey_para = kzalloc(sizeof(struct set_stakey_parm), GFP_KERNEL); |
Bhaktipriya Shridhar | 4ada295 | 2016-03-22 20:19:49 +0530 | [diff] [blame] | 2127 | if (!psetstakey_para) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2128 | kfree(ph2c); |
| 2129 | res = _FAIL; |
| 2130 | goto exit; |
| 2131 | } |
| 2132 | |
| 2133 | init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_); |
| 2134 | |
| 2135 | psetstakey_para->algorithm = (u8)psta->dot118021XPrivacy; |
| 2136 | |
| 2137 | memcpy(psetstakey_para->addr, psta->hwaddr, ETH_ALEN); |
| 2138 | |
| 2139 | memcpy(psetstakey_para->key, &psta->dot118021x_UncstKey, 16); |
| 2140 | |
| 2141 | res = rtw_enqueue_cmd(pcmdpriv, ph2c); |
| 2142 | |
| 2143 | exit: |
| 2144 | |
| 2145 | return res; |
| 2146 | } |
| 2147 | |
| 2148 | static int set_group_key(struct adapter *padapter, u8 *key, u8 alg, int keyid) |
| 2149 | { |
| 2150 | u8 keylen; |
| 2151 | struct cmd_obj *pcmd; |
| 2152 | struct setkey_parm *psetkeyparm; |
| 2153 | struct cmd_priv *pcmdpriv = &(padapter->cmdpriv); |
| 2154 | int res = _SUCCESS; |
| 2155 | |
| 2156 | DBG_88E("%s\n", __func__); |
| 2157 | |
navin patidar | fadbe0c | 2014-06-22 14:06:23 +0530 | [diff] [blame] | 2158 | pcmd = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); |
Bhaktipriya Shridhar | 4ada295 | 2016-03-22 20:19:49 +0530 | [diff] [blame] | 2159 | if (!pcmd) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2160 | res = _FAIL; |
| 2161 | goto exit; |
| 2162 | } |
navin patidar | fadbe0c | 2014-06-22 14:06:23 +0530 | [diff] [blame] | 2163 | psetkeyparm = kzalloc(sizeof(struct setkey_parm), GFP_KERNEL); |
Bhaktipriya Shridhar | 4ada295 | 2016-03-22 20:19:49 +0530 | [diff] [blame] | 2164 | if (!psetkeyparm) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2165 | kfree(pcmd); |
| 2166 | res = _FAIL; |
| 2167 | goto exit; |
| 2168 | } |
| 2169 | |
navin patidar | 1ce3984 | 2014-06-22 13:49:28 +0530 | [diff] [blame] | 2170 | memset(psetkeyparm, 0, sizeof(struct setkey_parm)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2171 | |
| 2172 | psetkeyparm->keyid = (u8)keyid; |
| 2173 | |
| 2174 | psetkeyparm->algorithm = alg; |
| 2175 | |
| 2176 | psetkeyparm->set_tx = 1; |
| 2177 | |
| 2178 | switch (alg) { |
| 2179 | case _WEP40_: |
| 2180 | keylen = 5; |
| 2181 | break; |
| 2182 | case _WEP104_: |
| 2183 | keylen = 13; |
| 2184 | break; |
| 2185 | case _TKIP_: |
| 2186 | case _TKIP_WTMIC_: |
| 2187 | case _AES_: |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2188 | default: |
| 2189 | keylen = 16; |
| 2190 | } |
| 2191 | |
| 2192 | memcpy(&(psetkeyparm->key[0]), key, keylen); |
| 2193 | |
| 2194 | pcmd->cmdcode = _SetKey_CMD_; |
| 2195 | pcmd->parmbuf = (u8 *)psetkeyparm; |
| 2196 | pcmd->cmdsz = (sizeof(struct setkey_parm)); |
| 2197 | pcmd->rsp = NULL; |
| 2198 | pcmd->rspsz = 0; |
| 2199 | |
navin patidar | aa3f5cc | 2014-06-22 13:49:34 +0530 | [diff] [blame] | 2200 | INIT_LIST_HEAD(&pcmd->list); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2201 | |
| 2202 | res = rtw_enqueue_cmd(pcmdpriv, pcmd); |
| 2203 | |
| 2204 | exit: |
| 2205 | |
| 2206 | return res; |
| 2207 | } |
| 2208 | |
| 2209 | static int set_wep_key(struct adapter *padapter, u8 *key, u8 keylen, int keyid) |
| 2210 | { |
| 2211 | u8 alg; |
| 2212 | |
| 2213 | switch (keylen) { |
| 2214 | case 5: |
| 2215 | alg = _WEP40_; |
| 2216 | break; |
| 2217 | case 13: |
| 2218 | alg = _WEP104_; |
| 2219 | break; |
| 2220 | default: |
| 2221 | alg = _NO_PRIVACY_; |
| 2222 | } |
| 2223 | |
| 2224 | return set_group_key(padapter, key, alg, keyid); |
| 2225 | } |
| 2226 | |
| 2227 | static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len) |
| 2228 | { |
| 2229 | int ret = 0; |
| 2230 | u32 wep_key_idx, wep_key_len, wep_total_len; |
| 2231 | struct ndis_802_11_wep *pwep = NULL; |
| 2232 | struct sta_info *psta = NULL, *pbcmc_sta = NULL; |
| 2233 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 2234 | struct mlme_priv *pmlmepriv = &padapter->mlmepriv; |
| 2235 | struct security_priv *psecuritypriv = &(padapter->securitypriv); |
| 2236 | struct sta_priv *pstapriv = &padapter->stapriv; |
| 2237 | |
| 2238 | DBG_88E("%s\n", __func__); |
| 2239 | param->u.crypt.err = 0; |
| 2240 | param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0'; |
| 2241 | if (param_len != sizeof(struct ieee_param) + param->u.crypt.key_len) { |
| 2242 | ret = -EINVAL; |
| 2243 | goto exit; |
| 2244 | } |
| 2245 | if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff && |
| 2246 | param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff && |
| 2247 | param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) { |
| 2248 | if (param->u.crypt.idx >= WEP_KEYS) { |
| 2249 | ret = -EINVAL; |
| 2250 | goto exit; |
| 2251 | } |
| 2252 | } else { |
| 2253 | psta = rtw_get_stainfo(pstapriv, param->sta_addr); |
| 2254 | if (!psta) { |
| 2255 | DBG_88E("rtw_set_encryption(), sta has already been removed or never been added\n"); |
| 2256 | goto exit; |
| 2257 | } |
| 2258 | } |
| 2259 | |
Amit Ghadge | 4fe514d | 2016-09-04 22:53:35 +0530 | [diff] [blame] | 2260 | if (strcmp(param->u.crypt.alg, "none") == 0 && (!psta)) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2261 | /* todo:clear default encryption keys */ |
| 2262 | |
| 2263 | DBG_88E("clear default encryption keys, keyid =%d\n", param->u.crypt.idx); |
| 2264 | goto exit; |
| 2265 | } |
Amit Ghadge | 4fe514d | 2016-09-04 22:53:35 +0530 | [diff] [blame] | 2266 | if (strcmp(param->u.crypt.alg, "WEP") == 0 && (!psta)) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2267 | DBG_88E("r871x_set_encryption, crypt.alg = WEP\n"); |
| 2268 | wep_key_idx = param->u.crypt.idx; |
| 2269 | wep_key_len = param->u.crypt.key_len; |
| 2270 | DBG_88E("r871x_set_encryption, wep_key_idx=%d, len=%d\n", wep_key_idx, wep_key_len); |
| 2271 | if ((wep_key_idx >= WEP_KEYS) || (wep_key_len <= 0)) { |
| 2272 | ret = -EINVAL; |
| 2273 | goto exit; |
| 2274 | } |
| 2275 | |
| 2276 | if (wep_key_len > 0) { |
| 2277 | wep_key_len = wep_key_len <= 5 ? 5 : 13; |
Ivan Safonov | 5e3027b | 2016-03-02 14:59:01 +0700 | [diff] [blame] | 2278 | wep_total_len = wep_key_len + offsetof(struct ndis_802_11_wep, KeyMaterial); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2279 | pwep = (struct ndis_802_11_wep *)rtw_malloc(wep_total_len); |
Amit Ghadge | 4fe514d | 2016-09-04 22:53:35 +0530 | [diff] [blame] | 2280 | if (!pwep) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2281 | DBG_88E(" r871x_set_encryption: pwep allocate fail !!!\n"); |
| 2282 | goto exit; |
| 2283 | } |
| 2284 | |
navin patidar | 1ce3984 | 2014-06-22 13:49:28 +0530 | [diff] [blame] | 2285 | memset(pwep, 0, wep_total_len); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2286 | |
| 2287 | pwep->KeyLength = wep_key_len; |
| 2288 | pwep->Length = wep_total_len; |
| 2289 | } |
| 2290 | |
| 2291 | pwep->KeyIndex = wep_key_idx; |
| 2292 | |
| 2293 | memcpy(pwep->KeyMaterial, param->u.crypt.key, pwep->KeyLength); |
| 2294 | |
| 2295 | if (param->u.crypt.set_tx) { |
| 2296 | DBG_88E("wep, set_tx = 1\n"); |
| 2297 | |
| 2298 | psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled; |
| 2299 | psecuritypriv->dot11PrivacyAlgrthm = _WEP40_; |
| 2300 | psecuritypriv->dot118021XGrpPrivacy = _WEP40_; |
| 2301 | |
| 2302 | if (pwep->KeyLength == 13) { |
| 2303 | psecuritypriv->dot11PrivacyAlgrthm = _WEP104_; |
| 2304 | psecuritypriv->dot118021XGrpPrivacy = _WEP104_; |
| 2305 | } |
| 2306 | |
| 2307 | psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx; |
| 2308 | |
| 2309 | memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), pwep->KeyMaterial, pwep->KeyLength); |
| 2310 | |
| 2311 | psecuritypriv->dot11DefKeylen[wep_key_idx] = pwep->KeyLength; |
| 2312 | |
| 2313 | set_wep_key(padapter, pwep->KeyMaterial, pwep->KeyLength, wep_key_idx); |
| 2314 | } else { |
| 2315 | DBG_88E("wep, set_tx = 0\n"); |
| 2316 | |
| 2317 | /* don't update "psecuritypriv->dot11PrivacyAlgrthm" and */ |
| 2318 | /* psecuritypriv->dot11PrivacyKeyIndex = keyid", but can rtw_set_key to cam */ |
| 2319 | |
| 2320 | memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), pwep->KeyMaterial, pwep->KeyLength); |
| 2321 | |
| 2322 | psecuritypriv->dot11DefKeylen[wep_key_idx] = pwep->KeyLength; |
| 2323 | |
| 2324 | set_wep_key(padapter, pwep->KeyMaterial, pwep->KeyLength, wep_key_idx); |
| 2325 | } |
| 2326 | |
| 2327 | goto exit; |
| 2328 | } |
| 2329 | |
| 2330 | if (!psta && check_fwstate(pmlmepriv, WIFI_AP_STATE)) { /* group key */ |
| 2331 | if (param->u.crypt.set_tx == 1) { |
| 2332 | if (strcmp(param->u.crypt.alg, "WEP") == 0) { |
| 2333 | DBG_88E("%s, set group_key, WEP\n", __func__); |
| 2334 | |
| 2335 | memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, |
Ivan Safonov | ad8d8cd | 2015-10-27 22:18:10 +0700 | [diff] [blame] | 2336 | param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2337 | |
| 2338 | psecuritypriv->dot118021XGrpPrivacy = _WEP40_; |
| 2339 | if (param->u.crypt.key_len == 13) |
| 2340 | psecuritypriv->dot118021XGrpPrivacy = _WEP104_; |
| 2341 | } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) { |
| 2342 | DBG_88E("%s, set group_key, TKIP\n", __func__); |
| 2343 | psecuritypriv->dot118021XGrpPrivacy = _TKIP_; |
| 2344 | memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, |
Ivan Safonov | ad8d8cd | 2015-10-27 22:18:10 +0700 | [diff] [blame] | 2345 | param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2346 | /* set mic key */ |
| 2347 | memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8); |
| 2348 | memcpy(psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8); |
| 2349 | |
| 2350 | psecuritypriv->busetkipkey = true; |
| 2351 | } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) { |
| 2352 | DBG_88E("%s, set group_key, CCMP\n", __func__); |
| 2353 | psecuritypriv->dot118021XGrpPrivacy = _AES_; |
| 2354 | memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, |
Ivan Safonov | ad8d8cd | 2015-10-27 22:18:10 +0700 | [diff] [blame] | 2355 | param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2356 | } else { |
| 2357 | DBG_88E("%s, set group_key, none\n", __func__); |
| 2358 | psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_; |
| 2359 | } |
| 2360 | psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx; |
| 2361 | psecuritypriv->binstallGrpkey = true; |
| 2362 | psecuritypriv->dot11PrivacyAlgrthm = psecuritypriv->dot118021XGrpPrivacy;/* */ |
| 2363 | set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx); |
| 2364 | pbcmc_sta = rtw_get_bcmc_stainfo(padapter); |
| 2365 | if (pbcmc_sta) { |
| 2366 | pbcmc_sta->ieee8021x_blocked = false; |
| 2367 | pbcmc_sta->dot118021XPrivacy = psecuritypriv->dot118021XGrpPrivacy;/* rx will use bmc_sta's dot118021XPrivacy */ |
| 2368 | } |
| 2369 | } |
| 2370 | goto exit; |
| 2371 | } |
| 2372 | |
| 2373 | if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X && psta) { /* psk/802_1x */ |
| 2374 | if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { |
| 2375 | if (param->u.crypt.set_tx == 1) { |
Ivan Safonov | ad8d8cd | 2015-10-27 22:18:10 +0700 | [diff] [blame] | 2376 | memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2377 | |
| 2378 | if (strcmp(param->u.crypt.alg, "WEP") == 0) { |
| 2379 | DBG_88E("%s, set pairwise key, WEP\n", __func__); |
| 2380 | |
| 2381 | psta->dot118021XPrivacy = _WEP40_; |
| 2382 | if (param->u.crypt.key_len == 13) |
| 2383 | psta->dot118021XPrivacy = _WEP104_; |
| 2384 | } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) { |
| 2385 | DBG_88E("%s, set pairwise key, TKIP\n", __func__); |
| 2386 | |
| 2387 | psta->dot118021XPrivacy = _TKIP_; |
| 2388 | |
| 2389 | /* set mic key */ |
| 2390 | memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8); |
| 2391 | memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8); |
| 2392 | |
| 2393 | psecuritypriv->busetkipkey = true; |
| 2394 | } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) { |
| 2395 | DBG_88E("%s, set pairwise key, CCMP\n", __func__); |
| 2396 | |
| 2397 | psta->dot118021XPrivacy = _AES_; |
| 2398 | } else { |
| 2399 | DBG_88E("%s, set pairwise key, none\n", __func__); |
| 2400 | |
| 2401 | psta->dot118021XPrivacy = _NO_PRIVACY_; |
| 2402 | } |
| 2403 | |
| 2404 | set_pairwise_key(padapter, psta); |
| 2405 | |
| 2406 | psta->ieee8021x_blocked = false; |
| 2407 | } else { /* group key??? */ |
| 2408 | if (strcmp(param->u.crypt.alg, "WEP") == 0) { |
| 2409 | memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, |
Ivan Safonov | ad8d8cd | 2015-10-27 22:18:10 +0700 | [diff] [blame] | 2410 | param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2411 | psecuritypriv->dot118021XGrpPrivacy = _WEP40_; |
| 2412 | if (param->u.crypt.key_len == 13) |
| 2413 | psecuritypriv->dot118021XGrpPrivacy = _WEP104_; |
| 2414 | } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) { |
| 2415 | psecuritypriv->dot118021XGrpPrivacy = _TKIP_; |
| 2416 | |
| 2417 | memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, |
Ivan Safonov | ad8d8cd | 2015-10-27 22:18:10 +0700 | [diff] [blame] | 2418 | param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2419 | |
| 2420 | /* set mic key */ |
| 2421 | memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8); |
| 2422 | memcpy(psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8); |
| 2423 | |
| 2424 | psecuritypriv->busetkipkey = true; |
| 2425 | } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) { |
| 2426 | psecuritypriv->dot118021XGrpPrivacy = _AES_; |
| 2427 | |
| 2428 | memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, |
Ivan Safonov | ad8d8cd | 2015-10-27 22:18:10 +0700 | [diff] [blame] | 2429 | param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2430 | } else { |
| 2431 | psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_; |
| 2432 | } |
| 2433 | |
| 2434 | psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx; |
| 2435 | |
| 2436 | psecuritypriv->binstallGrpkey = true; |
| 2437 | |
| 2438 | psecuritypriv->dot11PrivacyAlgrthm = psecuritypriv->dot118021XGrpPrivacy;/* */ |
| 2439 | |
| 2440 | set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx); |
| 2441 | |
| 2442 | pbcmc_sta = rtw_get_bcmc_stainfo(padapter); |
| 2443 | if (pbcmc_sta) { |
| 2444 | pbcmc_sta->ieee8021x_blocked = false; |
| 2445 | pbcmc_sta->dot118021XPrivacy = psecuritypriv->dot118021XGrpPrivacy;/* rx will use bmc_sta's dot118021XPrivacy */ |
| 2446 | } |
| 2447 | } |
| 2448 | } |
| 2449 | } |
| 2450 | |
| 2451 | exit: |
| 2452 | |
| 2453 | kfree(pwep); |
| 2454 | |
| 2455 | return ret; |
| 2456 | } |
| 2457 | |
| 2458 | static int rtw_set_beacon(struct net_device *dev, struct ieee_param *param, int len) |
| 2459 | { |
| 2460 | int ret = 0; |
| 2461 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 2462 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 2463 | struct sta_priv *pstapriv = &padapter->stapriv; |
| 2464 | unsigned char *pbuf = param->u.bcn_ie.buf; |
| 2465 | |
| 2466 | DBG_88E("%s, len =%d\n", __func__, len); |
| 2467 | |
| 2468 | if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != true) |
| 2469 | return -EINVAL; |
| 2470 | |
| 2471 | memcpy(&pstapriv->max_num_sta, param->u.bcn_ie.reserved, 2); |
| 2472 | |
| 2473 | if ((pstapriv->max_num_sta > NUM_STA) || (pstapriv->max_num_sta <= 0)) |
| 2474 | pstapriv->max_num_sta = NUM_STA; |
| 2475 | |
| 2476 | if (rtw_check_beacon_data(padapter, pbuf, (len-12-2)) == _SUCCESS)/* 12 = param header, 2:no packed */ |
| 2477 | ret = 0; |
| 2478 | else |
| 2479 | ret = -EINVAL; |
| 2480 | |
| 2481 | return ret; |
| 2482 | } |
| 2483 | |
| 2484 | static int rtw_hostapd_sta_flush(struct net_device *dev) |
| 2485 | { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2486 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 2487 | |
| 2488 | DBG_88E("%s\n", __func__); |
| 2489 | |
| 2490 | flush_all_cam_entry(padapter); /* clear CAM */ |
| 2491 | |
Shraddha Barke | f523c7d | 2015-07-27 19:07:57 +0530 | [diff] [blame] | 2492 | return rtw_sta_flush(padapter); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | static int rtw_add_sta(struct net_device *dev, struct ieee_param *param) |
| 2496 | { |
| 2497 | int ret = 0; |
| 2498 | struct sta_info *psta = NULL; |
| 2499 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 2500 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 2501 | struct sta_priv *pstapriv = &padapter->stapriv; |
| 2502 | |
| 2503 | DBG_88E("rtw_add_sta(aid =%d) =%pM\n", param->u.add_sta.aid, (param->sta_addr)); |
| 2504 | |
| 2505 | if (!check_fwstate(pmlmepriv, (_FW_LINKED|WIFI_AP_STATE))) |
| 2506 | return -EINVAL; |
| 2507 | |
| 2508 | if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff && |
| 2509 | param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff && |
| 2510 | param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) |
| 2511 | return -EINVAL; |
| 2512 | |
| 2513 | psta = rtw_get_stainfo(pstapriv, param->sta_addr); |
| 2514 | if (psta) { |
| 2515 | int flags = param->u.add_sta.flags; |
| 2516 | |
| 2517 | psta->aid = param->u.add_sta.aid;/* aid = 1~2007 */ |
| 2518 | |
| 2519 | memcpy(psta->bssrateset, param->u.add_sta.tx_supp_rates, 16); |
| 2520 | |
| 2521 | /* check wmm cap. */ |
| 2522 | if (WLAN_STA_WME&flags) |
| 2523 | psta->qos_option = 1; |
| 2524 | else |
| 2525 | psta->qos_option = 0; |
| 2526 | |
| 2527 | if (pmlmepriv->qospriv.qos_option == 0) |
| 2528 | psta->qos_option = 0; |
| 2529 | |
| 2530 | /* chec 802.11n ht cap. */ |
| 2531 | if (WLAN_STA_HT&flags) { |
| 2532 | psta->htpriv.ht_option = true; |
| 2533 | psta->qos_option = 1; |
Ivan Safonov | 81a2b8e | 2016-08-24 15:21:18 +0700 | [diff] [blame] | 2534 | memcpy(&psta->htpriv.ht_cap, ¶m->u.add_sta.ht_cap, |
| 2535 | sizeof(struct ieee80211_ht_cap)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2536 | } else { |
| 2537 | psta->htpriv.ht_option = false; |
| 2538 | } |
| 2539 | |
| 2540 | if (pmlmepriv->htpriv.ht_option == false) |
| 2541 | psta->htpriv.ht_option = false; |
| 2542 | |
| 2543 | update_sta_info_apmode(padapter, psta); |
| 2544 | } else { |
| 2545 | ret = -ENOMEM; |
| 2546 | } |
| 2547 | |
| 2548 | return ret; |
| 2549 | } |
| 2550 | |
| 2551 | static int rtw_del_sta(struct net_device *dev, struct ieee_param *param) |
| 2552 | { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2553 | int ret = 0; |
| 2554 | struct sta_info *psta = NULL; |
| 2555 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 2556 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 2557 | struct sta_priv *pstapriv = &padapter->stapriv; |
| 2558 | int updated = 0; |
| 2559 | |
| 2560 | DBG_88E("rtw_del_sta =%pM\n", (param->sta_addr)); |
| 2561 | |
| 2562 | if (check_fwstate(pmlmepriv, (_FW_LINKED|WIFI_AP_STATE)) != true) |
| 2563 | return -EINVAL; |
| 2564 | |
| 2565 | if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff && |
| 2566 | param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff && |
| 2567 | param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) |
| 2568 | return -EINVAL; |
| 2569 | |
| 2570 | psta = rtw_get_stainfo(pstapriv, param->sta_addr); |
| 2571 | if (psta) { |
Larry Finger | 7057dcb | 2013-12-19 22:38:34 -0600 | [diff] [blame] | 2572 | spin_lock_bh(&pstapriv->asoc_list_lock); |
navin patidar | 9c4b0e7 | 2014-06-22 13:49:33 +0530 | [diff] [blame] | 2573 | if (!list_empty(&psta->asoc_list)) { |
navin patidar | 8d5bdec | 2014-06-22 14:06:27 +0530 | [diff] [blame] | 2574 | list_del_init(&psta->asoc_list); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2575 | pstapriv->asoc_list_cnt--; |
| 2576 | updated = ap_free_sta(padapter, psta, true, WLAN_REASON_DEAUTH_LEAVING); |
| 2577 | } |
Larry Finger | e02bcf6 | 2013-12-19 22:38:35 -0600 | [diff] [blame] | 2578 | spin_unlock_bh(&pstapriv->asoc_list_lock); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2579 | associated_clients_update(padapter, updated); |
| 2580 | psta = NULL; |
| 2581 | } else { |
| 2582 | DBG_88E("rtw_del_sta(), sta has already been removed or never been added\n"); |
| 2583 | } |
| 2584 | |
| 2585 | return ret; |
| 2586 | } |
| 2587 | |
| 2588 | static int rtw_ioctl_get_sta_data(struct net_device *dev, struct ieee_param *param, int len) |
| 2589 | { |
| 2590 | int ret = 0; |
| 2591 | struct sta_info *psta = NULL; |
| 2592 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 2593 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 2594 | struct sta_priv *pstapriv = &padapter->stapriv; |
| 2595 | struct ieee_param_ex *param_ex = (struct ieee_param_ex *)param; |
| 2596 | struct sta_data *psta_data = (struct sta_data *)param_ex->data; |
| 2597 | |
| 2598 | DBG_88E("rtw_ioctl_get_sta_info, sta_addr: %pM\n", (param_ex->sta_addr)); |
| 2599 | |
| 2600 | if (check_fwstate(pmlmepriv, (_FW_LINKED|WIFI_AP_STATE)) != true) |
| 2601 | return -EINVAL; |
| 2602 | |
| 2603 | if (param_ex->sta_addr[0] == 0xff && param_ex->sta_addr[1] == 0xff && |
| 2604 | param_ex->sta_addr[2] == 0xff && param_ex->sta_addr[3] == 0xff && |
| 2605 | param_ex->sta_addr[4] == 0xff && param_ex->sta_addr[5] == 0xff) |
| 2606 | return -EINVAL; |
| 2607 | |
| 2608 | psta = rtw_get_stainfo(pstapriv, param_ex->sta_addr); |
| 2609 | if (psta) { |
| 2610 | psta_data->aid = (u16)psta->aid; |
| 2611 | psta_data->capability = psta->capability; |
| 2612 | psta_data->flags = psta->flags; |
| 2613 | |
| 2614 | /* |
| 2615 | nonerp_set : BIT(0) |
| 2616 | no_short_slot_time_set : BIT(1) |
| 2617 | no_short_preamble_set : BIT(2) |
| 2618 | no_ht_gf_set : BIT(3) |
| 2619 | no_ht_set : BIT(4) |
| 2620 | ht_20mhz_set : BIT(5) |
| 2621 | */ |
| 2622 | |
| 2623 | psta_data->sta_set = ((psta->nonerp_set) | |
| 2624 | (psta->no_short_slot_time_set << 1) | |
| 2625 | (psta->no_short_preamble_set << 2) | |
| 2626 | (psta->no_ht_gf_set << 3) | |
| 2627 | (psta->no_ht_set << 4) | |
| 2628 | (psta->ht_20mhz_set << 5)); |
| 2629 | psta_data->tx_supp_rates_len = psta->bssratelen; |
| 2630 | memcpy(psta_data->tx_supp_rates, psta->bssrateset, psta->bssratelen); |
Ivan Safonov | 81a2b8e | 2016-08-24 15:21:18 +0700 | [diff] [blame] | 2631 | memcpy(&psta_data->ht_cap, |
| 2632 | &psta->htpriv.ht_cap, sizeof(struct ieee80211_ht_cap)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2633 | psta_data->rx_pkts = psta->sta_stats.rx_data_pkts; |
| 2634 | psta_data->rx_bytes = psta->sta_stats.rx_bytes; |
| 2635 | psta_data->rx_drops = psta->sta_stats.rx_drops; |
| 2636 | psta_data->tx_pkts = psta->sta_stats.tx_pkts; |
| 2637 | psta_data->tx_bytes = psta->sta_stats.tx_bytes; |
| 2638 | psta_data->tx_drops = psta->sta_stats.tx_drops; |
| 2639 | } else { |
| 2640 | ret = -1; |
| 2641 | } |
| 2642 | |
| 2643 | return ret; |
| 2644 | } |
| 2645 | |
| 2646 | static int rtw_get_sta_wpaie(struct net_device *dev, struct ieee_param *param) |
| 2647 | { |
| 2648 | int ret = 0; |
| 2649 | struct sta_info *psta = NULL; |
| 2650 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 2651 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 2652 | struct sta_priv *pstapriv = &padapter->stapriv; |
| 2653 | |
| 2654 | DBG_88E("rtw_get_sta_wpaie, sta_addr: %pM\n", (param->sta_addr)); |
| 2655 | |
| 2656 | if (check_fwstate(pmlmepriv, (_FW_LINKED|WIFI_AP_STATE)) != true) |
| 2657 | return -EINVAL; |
| 2658 | |
| 2659 | if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff && |
| 2660 | param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff && |
| 2661 | param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) |
| 2662 | return -EINVAL; |
| 2663 | |
| 2664 | psta = rtw_get_stainfo(pstapriv, param->sta_addr); |
| 2665 | if (psta) { |
Jakub Sitnicki | 63d6c96 | 2015-07-29 10:15:16 +0200 | [diff] [blame] | 2666 | if (psta->wpa_ie[0] == WLAN_EID_RSN || |
| 2667 | psta->wpa_ie[0] == WLAN_EID_VENDOR_SPECIFIC) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2668 | int wpa_ie_len; |
| 2669 | int copy_len; |
| 2670 | |
| 2671 | wpa_ie_len = psta->wpa_ie[1]; |
Ivan Safonov | 530c9b1 | 2015-10-27 22:19:50 +0700 | [diff] [blame] | 2672 | copy_len = min_t(int, wpa_ie_len + 2, sizeof(psta->wpa_ie)); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2673 | param->u.wpa_ie.len = copy_len; |
| 2674 | memcpy(param->u.wpa_ie.reserved, psta->wpa_ie, copy_len); |
| 2675 | } else { |
| 2676 | DBG_88E("sta's wpa_ie is NONE\n"); |
| 2677 | } |
| 2678 | } else { |
| 2679 | ret = -1; |
| 2680 | } |
| 2681 | |
| 2682 | return ret; |
| 2683 | } |
| 2684 | |
| 2685 | static int rtw_set_wps_beacon(struct net_device *dev, struct ieee_param *param, int len) |
| 2686 | { |
| 2687 | int ret = 0; |
| 2688 | unsigned char wps_oui[4] = {0x0, 0x50, 0xf2, 0x04}; |
| 2689 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 2690 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 2691 | struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); |
| 2692 | int ie_len; |
| 2693 | |
| 2694 | DBG_88E("%s, len =%d\n", __func__, len); |
| 2695 | |
| 2696 | if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != true) |
| 2697 | return -EINVAL; |
| 2698 | |
| 2699 | ie_len = len-12-2;/* 12 = param header, 2:no packed */ |
| 2700 | |
Tapasweni Pathak | 157b8e5 | 2014-10-24 21:45:11 +0530 | [diff] [blame] | 2701 | kfree(pmlmepriv->wps_beacon_ie); |
| 2702 | pmlmepriv->wps_beacon_ie = NULL; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2703 | |
| 2704 | if (ie_len > 0) { |
| 2705 | pmlmepriv->wps_beacon_ie = rtw_malloc(ie_len); |
| 2706 | pmlmepriv->wps_beacon_ie_len = ie_len; |
Amit Ghadge | 4fe514d | 2016-09-04 22:53:35 +0530 | [diff] [blame] | 2707 | if (!pmlmepriv->wps_beacon_ie) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2708 | DBG_88E("%s()-%d: rtw_malloc() ERROR!\n", __func__, __LINE__); |
| 2709 | return -EINVAL; |
| 2710 | } |
| 2711 | |
| 2712 | memcpy(pmlmepriv->wps_beacon_ie, param->u.bcn_ie.buf, ie_len); |
| 2713 | |
| 2714 | update_beacon(padapter, _VENDOR_SPECIFIC_IE_, wps_oui, true); |
| 2715 | |
| 2716 | pmlmeext->bstart_bss = true; |
| 2717 | } |
| 2718 | |
| 2719 | return ret; |
| 2720 | } |
| 2721 | |
| 2722 | static int rtw_set_wps_probe_resp(struct net_device *dev, struct ieee_param *param, int len) |
| 2723 | { |
| 2724 | int ret = 0; |
| 2725 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 2726 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 2727 | int ie_len; |
| 2728 | |
| 2729 | DBG_88E("%s, len =%d\n", __func__, len); |
| 2730 | |
| 2731 | if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != true) |
| 2732 | return -EINVAL; |
| 2733 | |
| 2734 | ie_len = len-12-2;/* 12 = param header, 2:no packed */ |
| 2735 | |
Tapasweni Pathak | 157b8e5 | 2014-10-24 21:45:11 +0530 | [diff] [blame] | 2736 | kfree(pmlmepriv->wps_probe_resp_ie); |
| 2737 | pmlmepriv->wps_probe_resp_ie = NULL; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2738 | |
| 2739 | if (ie_len > 0) { |
| 2740 | pmlmepriv->wps_probe_resp_ie = rtw_malloc(ie_len); |
| 2741 | pmlmepriv->wps_probe_resp_ie_len = ie_len; |
Amit Ghadge | 4fe514d | 2016-09-04 22:53:35 +0530 | [diff] [blame] | 2742 | if (!pmlmepriv->wps_probe_resp_ie) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2743 | DBG_88E("%s()-%d: rtw_malloc() ERROR!\n", __func__, __LINE__); |
| 2744 | return -EINVAL; |
| 2745 | } |
| 2746 | memcpy(pmlmepriv->wps_probe_resp_ie, param->u.bcn_ie.buf, ie_len); |
| 2747 | } |
| 2748 | |
| 2749 | return ret; |
| 2750 | } |
| 2751 | |
| 2752 | static int rtw_set_wps_assoc_resp(struct net_device *dev, struct ieee_param *param, int len) |
| 2753 | { |
| 2754 | int ret = 0; |
| 2755 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 2756 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 2757 | int ie_len; |
| 2758 | |
| 2759 | DBG_88E("%s, len =%d\n", __func__, len); |
| 2760 | |
| 2761 | if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != true) |
| 2762 | return -EINVAL; |
| 2763 | |
| 2764 | ie_len = len-12-2;/* 12 = param header, 2:no packed */ |
| 2765 | |
Tapasweni Pathak | 157b8e5 | 2014-10-24 21:45:11 +0530 | [diff] [blame] | 2766 | kfree(pmlmepriv->wps_assoc_resp_ie); |
| 2767 | pmlmepriv->wps_assoc_resp_ie = NULL; |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2768 | |
| 2769 | if (ie_len > 0) { |
| 2770 | pmlmepriv->wps_assoc_resp_ie = rtw_malloc(ie_len); |
| 2771 | pmlmepriv->wps_assoc_resp_ie_len = ie_len; |
Amit Ghadge | 4fe514d | 2016-09-04 22:53:35 +0530 | [diff] [blame] | 2772 | if (!pmlmepriv->wps_assoc_resp_ie) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2773 | DBG_88E("%s()-%d: rtw_malloc() ERROR!\n", __func__, __LINE__); |
| 2774 | return -EINVAL; |
| 2775 | } |
| 2776 | |
| 2777 | memcpy(pmlmepriv->wps_assoc_resp_ie, param->u.bcn_ie.buf, ie_len); |
| 2778 | } |
| 2779 | |
| 2780 | return ret; |
| 2781 | } |
| 2782 | |
| 2783 | static int rtw_set_hidden_ssid(struct net_device *dev, struct ieee_param *param, int len) |
| 2784 | { |
| 2785 | int ret = 0; |
| 2786 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 2787 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 2788 | struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); |
| 2789 | struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); |
| 2790 | |
| 2791 | u8 value; |
| 2792 | |
| 2793 | if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != true) |
| 2794 | return -EINVAL; |
| 2795 | |
| 2796 | if (param->u.wpa_param.name != 0) /* dummy test... */ |
| 2797 | DBG_88E("%s name(%u) != 0\n", __func__, param->u.wpa_param.name); |
| 2798 | value = param->u.wpa_param.value; |
| 2799 | |
| 2800 | /* use the same definition of hostapd's ignore_broadcast_ssid */ |
| 2801 | if (value != 1 && value != 2) |
| 2802 | value = 0; |
| 2803 | DBG_88E("%s value(%u)\n", __func__, value); |
| 2804 | pmlmeinfo->hidden_ssid_mode = value; |
| 2805 | return ret; |
| 2806 | } |
| 2807 | |
| 2808 | static int rtw_ioctl_acl_remove_sta(struct net_device *dev, struct ieee_param *param, int len) |
| 2809 | { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2810 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 2811 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 2812 | |
| 2813 | if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != true) |
| 2814 | return -EINVAL; |
| 2815 | |
| 2816 | if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff && |
| 2817 | param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff && |
| 2818 | param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) |
| 2819 | return -EINVAL; |
Shraddha Barke | f523c7d | 2015-07-27 19:07:57 +0530 | [diff] [blame] | 2820 | return rtw_acl_remove_sta(padapter, param->sta_addr); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2821 | } |
| 2822 | |
| 2823 | static int rtw_ioctl_acl_add_sta(struct net_device *dev, struct ieee_param *param, int len) |
| 2824 | { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2825 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 2826 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 2827 | |
| 2828 | if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != true) |
| 2829 | return -EINVAL; |
| 2830 | |
| 2831 | if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff && |
| 2832 | param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff && |
| 2833 | param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) |
| 2834 | return -EINVAL; |
Shraddha Barke | f523c7d | 2015-07-27 19:07:57 +0530 | [diff] [blame] | 2835 | return rtw_acl_add_sta(padapter, param->sta_addr); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | static int rtw_ioctl_set_macaddr_acl(struct net_device *dev, struct ieee_param *param, int len) |
| 2839 | { |
| 2840 | int ret = 0; |
| 2841 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 2842 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 2843 | |
| 2844 | if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != true) |
| 2845 | return -EINVAL; |
| 2846 | |
| 2847 | rtw_set_macaddr_acl(padapter, param->u.mlme.command); |
| 2848 | |
| 2849 | return ret; |
| 2850 | } |
| 2851 | |
| 2852 | static int rtw_hostapd_ioctl(struct net_device *dev, struct iw_point *p) |
| 2853 | { |
| 2854 | struct ieee_param *param; |
| 2855 | int ret = 0; |
| 2856 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 2857 | |
| 2858 | /* |
| 2859 | * this function is expect to call in master mode, which allows no power saving |
| 2860 | * so, we just check hw_init_completed |
| 2861 | */ |
| 2862 | |
| 2863 | if (!padapter->hw_init_completed) { |
| 2864 | ret = -EPERM; |
| 2865 | goto out; |
| 2866 | } |
| 2867 | |
| 2868 | if (!p->pointer) { |
| 2869 | ret = -EINVAL; |
| 2870 | goto out; |
| 2871 | } |
| 2872 | |
| 2873 | param = (struct ieee_param *)rtw_malloc(p->length); |
Amit Ghadge | 4fe514d | 2016-09-04 22:53:35 +0530 | [diff] [blame] | 2874 | if (!param) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2875 | ret = -ENOMEM; |
| 2876 | goto out; |
| 2877 | } |
| 2878 | |
| 2879 | if (copy_from_user(param, p->pointer, p->length)) { |
| 2880 | kfree(param); |
| 2881 | ret = -EFAULT; |
| 2882 | goto out; |
| 2883 | } |
| 2884 | |
| 2885 | switch (param->cmd) { |
| 2886 | case RTL871X_HOSTAPD_FLUSH: |
| 2887 | ret = rtw_hostapd_sta_flush(dev); |
| 2888 | break; |
| 2889 | case RTL871X_HOSTAPD_ADD_STA: |
| 2890 | ret = rtw_add_sta(dev, param); |
| 2891 | break; |
| 2892 | case RTL871X_HOSTAPD_REMOVE_STA: |
| 2893 | ret = rtw_del_sta(dev, param); |
| 2894 | break; |
| 2895 | case RTL871X_HOSTAPD_SET_BEACON: |
| 2896 | ret = rtw_set_beacon(dev, param, p->length); |
| 2897 | break; |
| 2898 | case RTL871X_SET_ENCRYPTION: |
| 2899 | ret = rtw_set_encryption(dev, param, p->length); |
| 2900 | break; |
| 2901 | case RTL871X_HOSTAPD_GET_WPAIE_STA: |
| 2902 | ret = rtw_get_sta_wpaie(dev, param); |
| 2903 | break; |
| 2904 | case RTL871X_HOSTAPD_SET_WPS_BEACON: |
| 2905 | ret = rtw_set_wps_beacon(dev, param, p->length); |
| 2906 | break; |
| 2907 | case RTL871X_HOSTAPD_SET_WPS_PROBE_RESP: |
| 2908 | ret = rtw_set_wps_probe_resp(dev, param, p->length); |
| 2909 | break; |
| 2910 | case RTL871X_HOSTAPD_SET_WPS_ASSOC_RESP: |
| 2911 | ret = rtw_set_wps_assoc_resp(dev, param, p->length); |
| 2912 | break; |
| 2913 | case RTL871X_HOSTAPD_SET_HIDDEN_SSID: |
| 2914 | ret = rtw_set_hidden_ssid(dev, param, p->length); |
| 2915 | break; |
| 2916 | case RTL871X_HOSTAPD_GET_INFO_STA: |
| 2917 | ret = rtw_ioctl_get_sta_data(dev, param, p->length); |
| 2918 | break; |
| 2919 | case RTL871X_HOSTAPD_SET_MACADDR_ACL: |
| 2920 | ret = rtw_ioctl_set_macaddr_acl(dev, param, p->length); |
| 2921 | break; |
| 2922 | case RTL871X_HOSTAPD_ACL_ADD_STA: |
| 2923 | ret = rtw_ioctl_acl_add_sta(dev, param, p->length); |
| 2924 | break; |
| 2925 | case RTL871X_HOSTAPD_ACL_REMOVE_STA: |
| 2926 | ret = rtw_ioctl_acl_remove_sta(dev, param, p->length); |
| 2927 | break; |
| 2928 | default: |
| 2929 | DBG_88E("Unknown hostapd request: %d\n", param->cmd); |
| 2930 | ret = -EOPNOTSUPP; |
| 2931 | break; |
| 2932 | } |
| 2933 | |
| 2934 | if (ret == 0 && copy_to_user(p->pointer, param, p->length)) |
| 2935 | ret = -EFAULT; |
| 2936 | kfree(param); |
| 2937 | out: |
| 2938 | return ret; |
| 2939 | } |
| 2940 | #endif |
| 2941 | |
| 2942 | #include <rtw_android.h> |
| 2943 | static int rtw_wx_set_priv(struct net_device *dev, |
| 2944 | struct iw_request_info *info, |
| 2945 | union iwreq_data *awrq, |
| 2946 | char *extra) |
| 2947 | { |
| 2948 | int ret = 0; |
| 2949 | int len = 0; |
| 2950 | char *ext; |
| 2951 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 2952 | struct iw_point *dwrq = (struct iw_point *)awrq; |
| 2953 | |
| 2954 | if (dwrq->length == 0) |
| 2955 | return -EFAULT; |
| 2956 | |
| 2957 | len = dwrq->length; |
Larry Finger | 2397c6e | 2014-02-06 20:45:42 -0600 | [diff] [blame] | 2958 | ext = vmalloc(len); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2959 | if (!ext) |
| 2960 | return -ENOMEM; |
| 2961 | |
| 2962 | if (copy_from_user(ext, dwrq->pointer, len)) { |
Larry Finger | 03bd6ae | 2014-02-06 20:45:43 -0600 | [diff] [blame] | 2963 | vfree(ext); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2964 | return -EFAULT; |
| 2965 | } |
| 2966 | |
| 2967 | /* added for wps2.0 @20110524 */ |
| 2968 | if (dwrq->flags == 0x8766 && len > 8) { |
| 2969 | u32 cp_sz; |
| 2970 | struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); |
| 2971 | u8 *probereq_wpsie = ext; |
| 2972 | int probereq_wpsie_len = len; |
| 2973 | u8 wps_oui[4] = {0x0, 0x50, 0xf2, 0x04}; |
| 2974 | |
| 2975 | if ((_VENDOR_SPECIFIC_IE_ == probereq_wpsie[0]) && |
| 2976 | (!memcmp(&probereq_wpsie[2], wps_oui, 4))) { |
Ivan Safonov | 20e7653 | 2015-10-27 22:16:25 +0700 | [diff] [blame] | 2977 | cp_sz = min(probereq_wpsie_len, MAX_WPS_IE_LEN); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2978 | |
| 2979 | pmlmepriv->wps_probe_req_ie_len = 0; |
| 2980 | kfree(pmlmepriv->wps_probe_req_ie); |
| 2981 | pmlmepriv->wps_probe_req_ie = NULL; |
| 2982 | |
| 2983 | pmlmepriv->wps_probe_req_ie = rtw_malloc(cp_sz); |
Amit Ghadge | 4fe514d | 2016-09-04 22:53:35 +0530 | [diff] [blame] | 2984 | if (!pmlmepriv->wps_probe_req_ie) { |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 2985 | pr_info("%s()-%d: rtw_malloc() ERROR!\n", __func__, __LINE__); |
| 2986 | ret = -EINVAL; |
| 2987 | goto FREE_EXT; |
| 2988 | } |
| 2989 | memcpy(pmlmepriv->wps_probe_req_ie, probereq_wpsie, cp_sz); |
| 2990 | pmlmepriv->wps_probe_req_ie_len = cp_sz; |
| 2991 | } |
| 2992 | goto FREE_EXT; |
| 2993 | } |
| 2994 | |
| 2995 | if (len >= WEXT_CSCAN_HEADER_SIZE && |
| 2996 | !memcmp(ext, WEXT_CSCAN_HEADER, WEXT_CSCAN_HEADER_SIZE)) { |
| 2997 | ret = rtw_wx_set_scan(dev, info, awrq, ext); |
| 2998 | goto FREE_EXT; |
| 2999 | } |
| 3000 | |
| 3001 | FREE_EXT: |
| 3002 | |
Larry Finger | 03bd6ae | 2014-02-06 20:45:43 -0600 | [diff] [blame] | 3003 | vfree(ext); |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 3004 | |
| 3005 | return ret; |
| 3006 | } |
| 3007 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 3008 | static iw_handler rtw_handlers[] = { |
| 3009 | NULL, /* SIOCSIWCOMMIT */ |
| 3010 | rtw_wx_get_name, /* SIOCGIWNAME */ |
| 3011 | dummy, /* SIOCSIWNWID */ |
| 3012 | dummy, /* SIOCGIWNWID */ |
| 3013 | rtw_wx_set_freq, /* SIOCSIWFREQ */ |
| 3014 | rtw_wx_get_freq, /* SIOCGIWFREQ */ |
| 3015 | rtw_wx_set_mode, /* SIOCSIWMODE */ |
| 3016 | rtw_wx_get_mode, /* SIOCGIWMODE */ |
| 3017 | dummy, /* SIOCSIWSENS */ |
| 3018 | rtw_wx_get_sens, /* SIOCGIWSENS */ |
| 3019 | NULL, /* SIOCSIWRANGE */ |
| 3020 | rtw_wx_get_range, /* SIOCGIWRANGE */ |
| 3021 | rtw_wx_set_priv, /* SIOCSIWPRIV */ |
| 3022 | NULL, /* SIOCGIWPRIV */ |
| 3023 | NULL, /* SIOCSIWSTATS */ |
| 3024 | NULL, /* SIOCGIWSTATS */ |
| 3025 | dummy, /* SIOCSIWSPY */ |
| 3026 | dummy, /* SIOCGIWSPY */ |
| 3027 | NULL, /* SIOCGIWTHRSPY */ |
| 3028 | NULL, /* SIOCWIWTHRSPY */ |
| 3029 | rtw_wx_set_wap, /* SIOCSIWAP */ |
| 3030 | rtw_wx_get_wap, /* SIOCGIWAP */ |
| 3031 | rtw_wx_set_mlme, /* request MLME operation; uses struct iw_mlme */ |
| 3032 | dummy, /* SIOCGIWAPLIST -- depricated */ |
| 3033 | rtw_wx_set_scan, /* SIOCSIWSCAN */ |
| 3034 | rtw_wx_get_scan, /* SIOCGIWSCAN */ |
| 3035 | rtw_wx_set_essid, /* SIOCSIWESSID */ |
| 3036 | rtw_wx_get_essid, /* SIOCGIWESSID */ |
| 3037 | dummy, /* SIOCSIWNICKN */ |
| 3038 | rtw_wx_get_nick, /* SIOCGIWNICKN */ |
| 3039 | NULL, /* -- hole -- */ |
| 3040 | NULL, /* -- hole -- */ |
| 3041 | rtw_wx_set_rate, /* SIOCSIWRATE */ |
| 3042 | rtw_wx_get_rate, /* SIOCGIWRATE */ |
| 3043 | rtw_wx_set_rts, /* SIOCSIWRTS */ |
| 3044 | rtw_wx_get_rts, /* SIOCGIWRTS */ |
| 3045 | rtw_wx_set_frag, /* SIOCSIWFRAG */ |
| 3046 | rtw_wx_get_frag, /* SIOCGIWFRAG */ |
| 3047 | dummy, /* SIOCSIWTXPOW */ |
| 3048 | dummy, /* SIOCGIWTXPOW */ |
| 3049 | dummy, /* SIOCSIWRETRY */ |
| 3050 | rtw_wx_get_retry, /* SIOCGIWRETRY */ |
| 3051 | rtw_wx_set_enc, /* SIOCSIWENCODE */ |
| 3052 | rtw_wx_get_enc, /* SIOCGIWENCODE */ |
| 3053 | dummy, /* SIOCSIWPOWER */ |
| 3054 | rtw_wx_get_power, /* SIOCGIWPOWER */ |
| 3055 | NULL, /*---hole---*/ |
| 3056 | NULL, /*---hole---*/ |
| 3057 | rtw_wx_set_gen_ie, /* SIOCSIWGENIE */ |
| 3058 | NULL, /* SIOCGWGENIE */ |
| 3059 | rtw_wx_set_auth, /* SIOCSIWAUTH */ |
| 3060 | NULL, /* SIOCGIWAUTH */ |
| 3061 | rtw_wx_set_enc_ext, /* SIOCSIWENCODEEXT */ |
| 3062 | NULL, /* SIOCGIWENCODEEXT */ |
| 3063 | rtw_wx_set_pmkid, /* SIOCSIWPMKSA */ |
| 3064 | NULL, /*---hole---*/ |
| 3065 | }; |
| 3066 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 3067 | static struct iw_statistics *rtw_get_wireless_stats(struct net_device *dev) |
| 3068 | { |
| 3069 | struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); |
| 3070 | struct iw_statistics *piwstats = &padapter->iwstats; |
| 3071 | int tmp_level = 0; |
| 3072 | int tmp_qual = 0; |
| 3073 | int tmp_noise = 0; |
| 3074 | |
| 3075 | if (!check_fwstate(&padapter->mlmepriv, _FW_LINKED)) { |
| 3076 | piwstats->qual.qual = 0; |
| 3077 | piwstats->qual.level = 0; |
| 3078 | piwstats->qual.noise = 0; |
| 3079 | } else { |
| 3080 | tmp_level = padapter->recvpriv.signal_strength; |
| 3081 | tmp_qual = padapter->recvpriv.signal_qual; |
| 3082 | tmp_noise = padapter->recvpriv.noise; |
| 3083 | |
| 3084 | piwstats->qual.level = tmp_level; |
| 3085 | piwstats->qual.qual = tmp_qual; |
| 3086 | piwstats->qual.noise = tmp_noise; |
| 3087 | } |
| 3088 | piwstats->qual.updated = IW_QUAL_ALL_UPDATED;/* IW_QUAL_DBM; */ |
| 3089 | return &padapter->iwstats; |
| 3090 | } |
| 3091 | |
| 3092 | struct iw_handler_def rtw_handlers_def = { |
| 3093 | .standard = rtw_handlers, |
Ivan Safonov | bbef472 | 2015-10-27 22:13:57 +0700 | [diff] [blame] | 3094 | .num_standard = ARRAY_SIZE(rtw_handlers), |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 3095 | .get_wireless_stats = rtw_get_wireless_stats, |
| 3096 | }; |
| 3097 | |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 3098 | int rtw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 3099 | { |
| 3100 | struct iwreq *wrq = (struct iwreq *)rq; |
| 3101 | int ret = 0; |
| 3102 | |
| 3103 | switch (cmd) { |
| 3104 | case RTL_IOCTL_WPA_SUPPLICANT: |
| 3105 | ret = wpa_supplicant_ioctl(dev, &wrq->u.data); |
| 3106 | break; |
| 3107 | #ifdef CONFIG_88EU_AP_MODE |
| 3108 | case RTL_IOCTL_HOSTAPD: |
| 3109 | ret = rtw_hostapd_ioctl(dev, &wrq->u.data); |
| 3110 | break; |
| 3111 | #endif /* CONFIG_88EU_AP_MODE */ |
Larry Finger | a2c60d4 | 2013-08-21 22:33:58 -0500 | [diff] [blame] | 3112 | case (SIOCDEVPRIVATE+1): |
| 3113 | ret = rtw_android_priv_cmd(dev, rq, cmd); |
| 3114 | break; |
| 3115 | default: |
| 3116 | ret = -EOPNOTSUPP; |
| 3117 | break; |
| 3118 | } |
| 3119 | return ret; |
| 3120 | } |