1 // SPDX-License-Identifier: GPL-2.0 2 /****************************************************************************** 3 * 4 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. 5 * 6 ******************************************************************************/ 7 #define _IOCTL_CFG80211_C_ 8 9 #include <linux/etherdevice.h> 10 #include <drv_types.h> 11 #include <rtw_debug.h> 12 #include <linux/jiffies.h> 13 14 #include <rtw_wifi_regd.h> 15 16 #define RTW_MAX_MGMT_TX_CNT (8) 17 18 #define RTW_SCAN_IE_LEN_MAX 2304 19 #define RTW_MAX_REMAIN_ON_CHANNEL_DURATION 5000 /* ms */ 20 #define RTW_MAX_NUM_PMKIDS 4 21 22 #define RTW_CH_MAX_2G_CHANNEL 14 /* Max channel in 2G band */ 23 24 static const u32 rtw_cipher_suites[] = { 25 WLAN_CIPHER_SUITE_WEP40, 26 WLAN_CIPHER_SUITE_WEP104, 27 WLAN_CIPHER_SUITE_TKIP, 28 WLAN_CIPHER_SUITE_CCMP, 29 WLAN_CIPHER_SUITE_AES_CMAC, 30 }; 31 32 #define RATETAB_ENT(_rate, _rateid, _flags) \ 33 { \ 34 .bitrate = (_rate), \ 35 .hw_value = (_rateid), \ 36 .flags = (_flags), \ 37 } 38 39 #define CHAN2G(_channel, _freq, _flags) { \ 40 .band = NL80211_BAND_2GHZ, \ 41 .center_freq = (_freq), \ 42 .hw_value = (_channel), \ 43 .flags = (_flags), \ 44 .max_antenna_gain = 0, \ 45 .max_power = 30, \ 46 } 47 48 /* if wowlan is not supported, kernel generate a disconnect at each suspend 49 * cf: /net/wireless/sysfs.c, so register a stub wowlan. 50 * Moreover wowlan has to be enabled via a the nl80211_set_wowlan callback. 51 * (from user space, e.g. iw phy0 wowlan enable) 52 */ 53 static const struct wiphy_wowlan_support wowlan_stub = { 54 .flags = WIPHY_WOWLAN_ANY, 55 .n_patterns = 0, 56 .pattern_max_len = 0, 57 .pattern_min_len = 0, 58 .max_pkt_offset = 0, 59 }; 60 61 static struct ieee80211_rate rtw_rates[] = { 62 RATETAB_ENT(10, 0x1, 0), 63 RATETAB_ENT(20, 0x2, 0), 64 RATETAB_ENT(55, 0x4, 0), 65 RATETAB_ENT(110, 0x8, 0), 66 RATETAB_ENT(60, 0x10, 0), 67 RATETAB_ENT(90, 0x20, 0), 68 RATETAB_ENT(120, 0x40, 0), 69 RATETAB_ENT(180, 0x80, 0), 70 RATETAB_ENT(240, 0x100, 0), 71 RATETAB_ENT(360, 0x200, 0), 72 RATETAB_ENT(480, 0x400, 0), 73 RATETAB_ENT(540, 0x800, 0), 74 }; 75 76 #define rtw_a_rates (rtw_rates + 4) 77 #define RTW_A_RATES_NUM 8 78 #define rtw_g_rates (rtw_rates + 0) 79 #define RTW_G_RATES_NUM 12 80 81 #define RTW_2G_CHANNELS_NUM 14 82 #define RTW_5G_CHANNELS_NUM 37 83 84 static struct ieee80211_channel rtw_2ghz_channels[] = { 85 CHAN2G(1, 2412, 0), 86 CHAN2G(2, 2417, 0), 87 CHAN2G(3, 2422, 0), 88 CHAN2G(4, 2427, 0), 89 CHAN2G(5, 2432, 0), 90 CHAN2G(6, 2437, 0), 91 CHAN2G(7, 2442, 0), 92 CHAN2G(8, 2447, 0), 93 CHAN2G(9, 2452, 0), 94 CHAN2G(10, 2457, 0), 95 CHAN2G(11, 2462, 0), 96 CHAN2G(12, 2467, 0), 97 CHAN2G(13, 2472, 0), 98 CHAN2G(14, 2484, 0), 99 }; 100 101 static void rtw_2g_channels_init(struct ieee80211_channel *channels) 102 { 103 memcpy((void*)channels, (void*)rtw_2ghz_channels, 104 sizeof(struct ieee80211_channel)*RTW_2G_CHANNELS_NUM 105 ); 106 } 107 108 static void rtw_2g_rates_init(struct ieee80211_rate *rates) 109 { 110 memcpy(rates, rtw_g_rates, 111 sizeof(struct ieee80211_rate)*RTW_G_RATES_NUM 112 ); 113 } 114 115 static struct ieee80211_supported_band *rtw_spt_band_alloc( 116 enum nl80211_band band 117 ) 118 { 119 struct ieee80211_supported_band *spt_band = NULL; 120 int n_channels, n_bitrates; 121 122 if (band == NL80211_BAND_2GHZ) 123 { 124 n_channels = RTW_2G_CHANNELS_NUM; 125 n_bitrates = RTW_G_RATES_NUM; 126 } 127 else 128 { 129 goto exit; 130 } 131 132 spt_band = rtw_zmalloc(sizeof(struct ieee80211_supported_band) + 133 sizeof(struct ieee80211_channel) * n_channels + 134 sizeof(struct ieee80211_rate) * n_bitrates); 135 if (!spt_band) 136 goto exit; 137 138 spt_band->channels = (struct ieee80211_channel*)(((u8 *)spt_band)+sizeof(struct ieee80211_supported_band)); 139 spt_band->bitrates = (struct ieee80211_rate*)(((u8 *)spt_band->channels)+sizeof(struct ieee80211_channel)*n_channels); 140 spt_band->band = band; 141 spt_band->n_channels = n_channels; 142 spt_band->n_bitrates = n_bitrates; 143 144 if (band == NL80211_BAND_2GHZ) 145 { 146 rtw_2g_channels_init(spt_band->channels); 147 rtw_2g_rates_init(spt_band->bitrates); 148 } 149 150 /* spt_band.ht_cap */ 151 152 exit: 153 154 return spt_band; 155 } 156 157 static void rtw_spt_band_free(struct ieee80211_supported_band *spt_band) 158 { 159 u32 size = 0; 160 161 if (!spt_band) 162 return; 163 164 if (spt_band->band == NL80211_BAND_2GHZ) 165 { 166 size = sizeof(struct ieee80211_supported_band) 167 + sizeof(struct ieee80211_channel)*RTW_2G_CHANNELS_NUM 168 + sizeof(struct ieee80211_rate)*RTW_G_RATES_NUM; 169 } 170 kfree((u8 *)spt_band); 171 } 172 173 static const struct ieee80211_txrx_stypes 174 rtw_cfg80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = { 175 [NL80211_IFTYPE_ADHOC] = { 176 .tx = 0xffff, 177 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) 178 }, 179 [NL80211_IFTYPE_STATION] = { 180 .tx = 0xffff, 181 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | 182 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) 183 }, 184 [NL80211_IFTYPE_AP] = { 185 .tx = 0xffff, 186 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | 187 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | 188 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | 189 BIT(IEEE80211_STYPE_DISASSOC >> 4) | 190 BIT(IEEE80211_STYPE_AUTH >> 4) | 191 BIT(IEEE80211_STYPE_DEAUTH >> 4) | 192 BIT(IEEE80211_STYPE_ACTION >> 4) 193 }, 194 [NL80211_IFTYPE_AP_VLAN] = { 195 /* copy AP */ 196 .tx = 0xffff, 197 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | 198 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | 199 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | 200 BIT(IEEE80211_STYPE_DISASSOC >> 4) | 201 BIT(IEEE80211_STYPE_AUTH >> 4) | 202 BIT(IEEE80211_STYPE_DEAUTH >> 4) | 203 BIT(IEEE80211_STYPE_ACTION >> 4) 204 }, 205 [NL80211_IFTYPE_P2P_CLIENT] = { 206 .tx = 0xffff, 207 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | 208 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) 209 }, 210 [NL80211_IFTYPE_P2P_GO] = { 211 .tx = 0xffff, 212 .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | 213 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | 214 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | 215 BIT(IEEE80211_STYPE_DISASSOC >> 4) | 216 BIT(IEEE80211_STYPE_AUTH >> 4) | 217 BIT(IEEE80211_STYPE_DEAUTH >> 4) | 218 BIT(IEEE80211_STYPE_ACTION >> 4) 219 }, 220 }; 221 222 static int rtw_ieee80211_channel_to_frequency(int chan, int band) 223 { 224 /* see 802.11 17.3.8.3.2 and Annex J 225 * there are overlapping channel numbers in 5GHz and 2GHz bands */ 226 if (band == NL80211_BAND_2GHZ) { 227 if (chan == 14) 228 return 2484; 229 else if (chan < 14) 230 return 2407 + chan * 5; 231 } 232 233 return 0; /* not supported */ 234 } 235 236 static u64 rtw_get_systime_us(void) 237 { 238 struct timespec ts; 239 get_monotonic_boottime(&ts); 240 return ((u64)ts.tv_sec*1000000) + ts.tv_nsec / 1000; 241 } 242 243 #define MAX_BSSINFO_LEN 1000 244 struct cfg80211_bss *rtw_cfg80211_inform_bss(struct adapter *padapter, struct wlan_network *pnetwork) 245 { 246 struct ieee80211_channel *notify_channel; 247 struct cfg80211_bss *bss = NULL; 248 /* struct ieee80211_supported_band *band; */ 249 u16 channel; 250 u32 freq; 251 u64 notify_timestamp; 252 u16 notify_capability; 253 u16 notify_interval; 254 u8 *notify_ie; 255 size_t notify_ielen; 256 s32 notify_signal; 257 u8 *buf = NULL, *pbuf; 258 size_t len, bssinf_len = 0; 259 struct ieee80211_hdr *pwlanhdr; 260 __le16 *fctrl; 261 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 262 263 struct wireless_dev *wdev = padapter->rtw_wdev; 264 struct wiphy *wiphy = wdev->wiphy; 265 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 266 267 268 /* DBG_8192C("%s\n", __func__); */ 269 270 bssinf_len = pnetwork->network.IELength+sizeof (struct ieee80211_hdr_3addr); 271 if (bssinf_len > MAX_BSSINFO_LEN) { 272 DBG_871X("%s IE Length too long > %d byte\n", __func__, MAX_BSSINFO_LEN); 273 goto exit; 274 } 275 276 { 277 u16 wapi_len = 0; 278 279 if (rtw_get_wapi_ie(pnetwork->network.IEs, pnetwork->network.IELength, NULL, &wapi_len)>0) 280 { 281 if (wapi_len > 0) 282 { 283 DBG_871X("%s, no support wapi!\n", __func__); 284 goto exit; 285 } 286 } 287 } 288 289 /* To reduce PBC Overlap rate */ 290 /* spin_lock_bh(&pwdev_priv->scan_req_lock); */ 291 if (adapter_wdev_data(padapter)->scan_request != NULL) 292 { 293 u8 *psr = NULL, sr = 0; 294 struct ndis_802_11_ssid *pssid = &pnetwork->network.Ssid; 295 struct cfg80211_scan_request *request = adapter_wdev_data(padapter)->scan_request; 296 struct cfg80211_ssid *ssids = request->ssids; 297 u32 wpsielen = 0; 298 u8 *wpsie = NULL; 299 300 wpsie = rtw_get_wps_ie(pnetwork->network.IEs+_FIXED_IE_LENGTH_, pnetwork->network.IELength-_FIXED_IE_LENGTH_, NULL, &wpsielen); 301 302 if (wpsie && wpsielen>0) 303 psr = rtw_get_wps_attr_content(wpsie, wpsielen, WPS_ATTR_SELECTED_REGISTRAR, (u8 *)(&sr), NULL); 304 305 if (sr != 0) 306 { 307 if (request->n_ssids == 1 && request->n_channels == 1) /* it means under processing WPS */ 308 { 309 DBG_8192C("ssid =%s, len =%d\n", pssid->Ssid, pssid->SsidLength); 310 311 if (ssids[0].ssid_len == 0) { 312 } 313 else if (pssid->SsidLength == ssids[0].ssid_len && 314 !memcmp(pssid->Ssid, ssids[0].ssid, ssids[0].ssid_len)) 315 { 316 DBG_871X("%s, got sr and ssid match!\n", __func__); 317 } 318 else 319 { 320 if (psr != NULL) 321 *psr = 0; /* clear sr */ 322 } 323 } 324 } 325 } 326 /* spin_unlock_bh(&pwdev_priv->scan_req_lock); */ 327 328 329 channel = pnetwork->network.Configuration.DSConfig; 330 freq = rtw_ieee80211_channel_to_frequency(channel, NL80211_BAND_2GHZ); 331 332 notify_channel = ieee80211_get_channel(wiphy, freq); 333 334 notify_timestamp = rtw_get_systime_us(); 335 336 notify_interval = le16_to_cpu(*(__le16 *)rtw_get_beacon_interval_from_ie(pnetwork->network.IEs)); 337 notify_capability = le16_to_cpu(*(__le16 *)rtw_get_capability_from_ie(pnetwork->network.IEs)); 338 339 notify_ie = pnetwork->network.IEs+_FIXED_IE_LENGTH_; 340 notify_ielen = pnetwork->network.IELength-_FIXED_IE_LENGTH_; 341 342 /* We've set wiphy's signal_type as CFG80211_SIGNAL_TYPE_MBM: signal strength in mBm (100*dBm) */ 343 if (check_fwstate(pmlmepriv, _FW_LINKED) == true && 344 is_same_network(&pmlmepriv->cur_network.network, &pnetwork->network, 0)) { 345 notify_signal = 100*translate_percentage_to_dbm(padapter->recvpriv.signal_strength);/* dbm */ 346 } else { 347 notify_signal = 100*translate_percentage_to_dbm(pnetwork->network.PhyInfo.SignalStrength);/* dbm */ 348 } 349 350 buf = kzalloc(MAX_BSSINFO_LEN, GFP_ATOMIC); 351 if (!buf) 352 goto exit; 353 pbuf = buf; 354 355 pwlanhdr = (struct ieee80211_hdr *)pbuf; 356 fctrl = &(pwlanhdr->frame_control); 357 *(fctrl) = 0; 358 359 SetSeqNum(pwlanhdr, 0/*pmlmeext->mgnt_seq*/); 360 /* pmlmeext->mgnt_seq++; */ 361 362 if (pnetwork->network.Reserved[0] == 1) { /* WIFI_BEACON */ 363 memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN); 364 SetFrameSubType(pbuf, WIFI_BEACON); 365 } else { 366 memcpy(pwlanhdr->addr1, myid(&(padapter->eeprompriv)), ETH_ALEN); 367 SetFrameSubType(pbuf, WIFI_PROBERSP); 368 } 369 370 memcpy(pwlanhdr->addr2, pnetwork->network.MacAddress, ETH_ALEN); 371 memcpy(pwlanhdr->addr3, pnetwork->network.MacAddress, ETH_ALEN); 372 373 374 pbuf += sizeof(struct ieee80211_hdr_3addr); 375 len = sizeof (struct ieee80211_hdr_3addr); 376 377 memcpy(pbuf, pnetwork->network.IEs, pnetwork->network.IELength); 378 len += pnetwork->network.IELength; 379 380 *((__le64*)pbuf) = cpu_to_le64(notify_timestamp); 381 382 bss = cfg80211_inform_bss_frame(wiphy, notify_channel, (struct ieee80211_mgmt *)buf, 383 len, notify_signal, GFP_ATOMIC); 384 385 if (unlikely(!bss)) { 386 DBG_8192C(FUNC_ADPT_FMT" bss NULL\n", FUNC_ADPT_ARG(padapter)); 387 goto exit; 388 } 389 390 cfg80211_put_bss(wiphy, bss); 391 kfree(buf); 392 393 exit: 394 return bss; 395 396 } 397 398 /* 399 Check the given bss is valid by kernel API cfg80211_get_bss() 400 @padapter : the given adapter 401 402 return true if bss is valid, false for not found. 403 */ 404 int rtw_cfg80211_check_bss(struct adapter *padapter) 405 { 406 struct wlan_bssid_ex *pnetwork = &(padapter->mlmeextpriv.mlmext_info.network); 407 struct cfg80211_bss *bss = NULL; 408 struct ieee80211_channel *notify_channel = NULL; 409 u32 freq; 410 411 if (!(pnetwork) || !(padapter->rtw_wdev)) 412 return false; 413 414 freq = rtw_ieee80211_channel_to_frequency(pnetwork->Configuration.DSConfig, NL80211_BAND_2GHZ); 415 416 notify_channel = ieee80211_get_channel(padapter->rtw_wdev->wiphy, freq); 417 bss = cfg80211_get_bss(padapter->rtw_wdev->wiphy, notify_channel, 418 pnetwork->MacAddress, pnetwork->Ssid.Ssid, 419 pnetwork->Ssid.SsidLength, 420 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); 421 422 cfg80211_put_bss(padapter->rtw_wdev->wiphy, bss); 423 424 return (bss!= NULL); 425 } 426 427 void rtw_cfg80211_ibss_indicate_connect(struct adapter *padapter) 428 { 429 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 430 struct wlan_network *cur_network = &(pmlmepriv->cur_network); 431 struct wireless_dev *pwdev = padapter->rtw_wdev; 432 struct wiphy *wiphy = pwdev->wiphy; 433 int freq = (int)cur_network->network.Configuration.DSConfig; 434 struct ieee80211_channel *chan; 435 436 DBG_871X(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter)); 437 if (pwdev->iftype != NL80211_IFTYPE_ADHOC) 438 { 439 return; 440 } 441 442 if (!rtw_cfg80211_check_bss(padapter)) { 443 struct wlan_bssid_ex *pnetwork = &(padapter->mlmeextpriv.mlmext_info.network); 444 struct wlan_network *scanned = pmlmepriv->cur_network_scanned; 445 446 if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) ==true) 447 { 448 449 memcpy(&cur_network->network, pnetwork, sizeof(struct wlan_bssid_ex)); 450 if (!rtw_cfg80211_inform_bss(padapter, cur_network)) 451 DBG_871X(FUNC_ADPT_FMT" inform fail !!\n", FUNC_ADPT_ARG(padapter)); 452 else 453 DBG_871X(FUNC_ADPT_FMT" inform success !!\n", FUNC_ADPT_ARG(padapter)); 454 } 455 else 456 { 457 if (scanned == NULL) { 458 rtw_warn_on(1); 459 return; 460 } 461 if (!memcmp(&(scanned->network.Ssid), &(pnetwork->Ssid), sizeof(struct ndis_802_11_ssid)) 462 && !memcmp(scanned->network.MacAddress, pnetwork->MacAddress, sizeof(NDIS_802_11_MAC_ADDRESS)) 463 ) { 464 if (!rtw_cfg80211_inform_bss(padapter, scanned)) { 465 DBG_871X(FUNC_ADPT_FMT" inform fail !!\n", FUNC_ADPT_ARG(padapter)); 466 } else { 467 /* DBG_871X(FUNC_ADPT_FMT" inform success !!\n", FUNC_ADPT_ARG(padapter)); */ 468 } 469 } else { 470 DBG_871X("scanned & pnetwork compare fail\n"); 471 rtw_warn_on(1); 472 } 473 } 474 475 if (!rtw_cfg80211_check_bss(padapter)) 476 DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT" BSS not found !!\n", FUNC_ADPT_ARG(padapter)); 477 } 478 /* notify cfg80211 that device joined an IBSS */ 479 chan = ieee80211_get_channel(wiphy, freq); 480 cfg80211_ibss_joined(padapter->pnetdev, cur_network->network.MacAddress, chan, GFP_ATOMIC); 481 } 482 483 void rtw_cfg80211_indicate_connect(struct adapter *padapter) 484 { 485 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 486 struct wlan_network *cur_network = &(pmlmepriv->cur_network); 487 struct wireless_dev *pwdev = padapter->rtw_wdev; 488 489 DBG_871X(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter)); 490 if (pwdev->iftype != NL80211_IFTYPE_STATION 491 && pwdev->iftype != NL80211_IFTYPE_P2P_CLIENT 492 ) { 493 return; 494 } 495 496 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) 497 return; 498 499 { 500 struct wlan_bssid_ex *pnetwork = &(padapter->mlmeextpriv.mlmext_info.network); 501 struct wlan_network *scanned = pmlmepriv->cur_network_scanned; 502 503 /* DBG_871X(FUNC_ADPT_FMT" BSS not found\n", FUNC_ADPT_ARG(padapter)); */ 504 505 if (scanned == NULL) { 506 rtw_warn_on(1); 507 goto check_bss; 508 } 509 510 if (!memcmp(scanned->network.MacAddress, pnetwork->MacAddress, sizeof(NDIS_802_11_MAC_ADDRESS)) 511 && !memcmp(&(scanned->network.Ssid), &(pnetwork->Ssid), sizeof(struct ndis_802_11_ssid)) 512 ) { 513 if (!rtw_cfg80211_inform_bss(padapter, scanned)) { 514 DBG_871X(FUNC_ADPT_FMT" inform fail !!\n", FUNC_ADPT_ARG(padapter)); 515 } else { 516 /* DBG_871X(FUNC_ADPT_FMT" inform success !!\n", FUNC_ADPT_ARG(padapter)); */ 517 } 518 } else { 519 DBG_871X("scanned: %s("MAC_FMT"), cur: %s("MAC_FMT")\n", 520 scanned->network.Ssid.Ssid, MAC_ARG(scanned->network.MacAddress), 521 pnetwork->Ssid.Ssid, MAC_ARG(pnetwork->MacAddress) 522 ); 523 rtw_warn_on(1); 524 } 525 } 526 527 check_bss: 528 if (!rtw_cfg80211_check_bss(padapter)) 529 DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT" BSS not found !!\n", FUNC_ADPT_ARG(padapter)); 530 531 if (rtw_to_roam(padapter) > 0) { 532 struct wiphy *wiphy = pwdev->wiphy; 533 struct ieee80211_channel *notify_channel; 534 u32 freq; 535 u16 channel = cur_network->network.Configuration.DSConfig; 536 struct cfg80211_roam_info roam_info = {}; 537 538 freq = rtw_ieee80211_channel_to_frequency(channel, NL80211_BAND_2GHZ); 539 540 notify_channel = ieee80211_get_channel(wiphy, freq); 541 542 DBG_871X(FUNC_ADPT_FMT" call cfg80211_roamed\n", FUNC_ADPT_ARG(padapter)); 543 roam_info.channel = notify_channel; 544 roam_info.bssid = cur_network->network.MacAddress; 545 roam_info.req_ie = 546 pmlmepriv->assoc_req+sizeof(struct ieee80211_hdr_3addr)+2; 547 roam_info.req_ie_len = 548 pmlmepriv->assoc_req_len-sizeof(struct ieee80211_hdr_3addr)-2; 549 roam_info.resp_ie = 550 pmlmepriv->assoc_rsp+sizeof(struct ieee80211_hdr_3addr)+6; 551 roam_info.resp_ie_len = 552 pmlmepriv->assoc_rsp_len-sizeof(struct ieee80211_hdr_3addr)-6; 553 cfg80211_roamed(padapter->pnetdev, &roam_info, GFP_ATOMIC); 554 } 555 else 556 { 557 cfg80211_connect_result(padapter->pnetdev, cur_network->network.MacAddress 558 , pmlmepriv->assoc_req+sizeof(struct ieee80211_hdr_3addr)+2 559 , pmlmepriv->assoc_req_len-sizeof(struct ieee80211_hdr_3addr)-2 560 , pmlmepriv->assoc_rsp+sizeof(struct ieee80211_hdr_3addr)+6 561 , pmlmepriv->assoc_rsp_len-sizeof(struct ieee80211_hdr_3addr)-6 562 , WLAN_STATUS_SUCCESS, GFP_ATOMIC); 563 } 564 } 565 566 void rtw_cfg80211_indicate_disconnect(struct adapter *padapter) 567 { 568 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 569 struct wireless_dev *pwdev = padapter->rtw_wdev; 570 571 DBG_871X(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter)); 572 573 if (pwdev->iftype != NL80211_IFTYPE_STATION 574 && pwdev->iftype != NL80211_IFTYPE_P2P_CLIENT 575 ) { 576 return; 577 } 578 579 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) 580 return; 581 582 if (!padapter->mlmepriv.not_indic_disco) { 583 if (check_fwstate(&padapter->mlmepriv, _FW_LINKED)) { 584 cfg80211_disconnected(padapter->pnetdev, 0, 585 NULL, 0, true, GFP_ATOMIC); 586 } else { 587 cfg80211_connect_result(padapter->pnetdev, NULL, NULL, 0, NULL, 0, 588 WLAN_STATUS_UNSPECIFIED_FAILURE, GFP_ATOMIC/*GFP_KERNEL*/); 589 } 590 } 591 } 592 593 594 static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len) 595 { 596 int ret = 0; 597 u32 wep_key_idx, wep_key_len; 598 struct sta_info *psta = NULL, *pbcmc_sta = NULL; 599 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); 600 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 601 struct security_priv* psecuritypriv =&(padapter->securitypriv); 602 struct sta_priv *pstapriv = &padapter->stapriv; 603 604 DBG_8192C("%s\n", __func__); 605 606 param->u.crypt.err = 0; 607 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0'; 608 609 if (param_len != sizeof(struct ieee_param) + param->u.crypt.key_len) 610 { 611 ret = -EINVAL; 612 goto exit; 613 } 614 615 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff && 616 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff && 617 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) 618 { 619 if (param->u.crypt.idx >= WEP_KEYS) 620 { 621 ret = -EINVAL; 622 goto exit; 623 } 624 } 625 else 626 { 627 psta = rtw_get_stainfo(pstapriv, param->sta_addr); 628 if (!psta) 629 { 630 /* ret = -EINVAL; */ 631 DBG_8192C("rtw_set_encryption(), sta has already been removed or never been added\n"); 632 goto exit; 633 } 634 } 635 636 if (strcmp(param->u.crypt.alg, "none") == 0 && (psta == NULL)) 637 { 638 /* todo:clear default encryption keys */ 639 640 DBG_8192C("clear default encryption keys, keyid =%d\n", param->u.crypt.idx); 641 642 goto exit; 643 } 644 645 646 if (strcmp(param->u.crypt.alg, "WEP") == 0 && (psta == NULL)) 647 { 648 DBG_8192C("r871x_set_encryption, crypt.alg = WEP\n"); 649 650 wep_key_idx = param->u.crypt.idx; 651 wep_key_len = param->u.crypt.key_len; 652 653 DBG_8192C("r871x_set_encryption, wep_key_idx =%d, len =%d\n", wep_key_idx, wep_key_len); 654 655 if ((wep_key_idx >= WEP_KEYS) || (wep_key_len<= 0)) 656 { 657 ret = -EINVAL; 658 goto exit; 659 } 660 661 if (wep_key_len > 0) 662 { 663 wep_key_len = wep_key_len <= 5 ? 5 : 13; 664 } 665 666 if (psecuritypriv->bWepDefaultKeyIdxSet == 0) 667 { 668 /* wep default key has not been set, so use this key index as default key. */ 669 670 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Auto; 671 psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled; 672 psecuritypriv->dot11PrivacyAlgrthm = _WEP40_; 673 psecuritypriv->dot118021XGrpPrivacy = _WEP40_; 674 675 if (wep_key_len == 13) 676 { 677 psecuritypriv->dot11PrivacyAlgrthm = _WEP104_; 678 psecuritypriv->dot118021XGrpPrivacy = _WEP104_; 679 } 680 681 psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx; 682 } 683 684 memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), param->u.crypt.key, wep_key_len); 685 686 psecuritypriv->dot11DefKeylen[wep_key_idx] = wep_key_len; 687 688 rtw_ap_set_wep_key(padapter, param->u.crypt.key, wep_key_len, wep_key_idx, 1); 689 690 goto exit; 691 692 } 693 694 695 if (!psta && check_fwstate(pmlmepriv, WIFI_AP_STATE)) /* group key */ 696 { 697 if (param->u.crypt.set_tx == 0) /* group key */ 698 { 699 if (strcmp(param->u.crypt.alg, "WEP") == 0) 700 { 701 DBG_8192C("%s, set group_key, WEP\n", __func__); 702 703 memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); 704 705 psecuritypriv->dot118021XGrpPrivacy = _WEP40_; 706 if (param->u.crypt.key_len == 13) 707 { 708 psecuritypriv->dot118021XGrpPrivacy = _WEP104_; 709 } 710 711 } 712 else if (strcmp(param->u.crypt.alg, "TKIP") == 0) 713 { 714 DBG_8192C("%s, set group_key, TKIP\n", __func__); 715 716 psecuritypriv->dot118021XGrpPrivacy = _TKIP_; 717 718 memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); 719 720 /* DEBUG_ERR("set key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len); */ 721 /* set mic key */ 722 memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8); 723 memcpy(psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8); 724 725 psecuritypriv->busetkipkey = true; 726 727 } 728 else if (strcmp(param->u.crypt.alg, "CCMP") == 0) 729 { 730 DBG_8192C("%s, set group_key, CCMP\n", __func__); 731 732 psecuritypriv->dot118021XGrpPrivacy = _AES_; 733 734 memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); 735 } 736 else 737 { 738 DBG_8192C("%s, set group_key, none\n", __func__); 739 740 psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_; 741 } 742 743 psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx; 744 745 psecuritypriv->binstallGrpkey = true; 746 747 psecuritypriv->dot11PrivacyAlgrthm = psecuritypriv->dot118021XGrpPrivacy;/* */ 748 749 rtw_ap_set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx); 750 751 pbcmc_sta =rtw_get_bcmc_stainfo(padapter); 752 if (pbcmc_sta) 753 { 754 pbcmc_sta->ieee8021x_blocked = false; 755 pbcmc_sta->dot118021XPrivacy = psecuritypriv->dot118021XGrpPrivacy;/* rx will use bmc_sta's dot118021XPrivacy */ 756 } 757 758 } 759 760 goto exit; 761 762 } 763 764 if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X && psta) /* psk/802_1x */ 765 { 766 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) 767 { 768 if (param->u.crypt.set_tx == 1) /* pairwise key */ 769 { 770 memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); 771 772 if (strcmp(param->u.crypt.alg, "WEP") == 0) 773 { 774 DBG_8192C("%s, set pairwise key, WEP\n", __func__); 775 776 psta->dot118021XPrivacy = _WEP40_; 777 if (param->u.crypt.key_len == 13) 778 { 779 psta->dot118021XPrivacy = _WEP104_; 780 } 781 } 782 else if (strcmp(param->u.crypt.alg, "TKIP") == 0) 783 { 784 DBG_8192C("%s, set pairwise key, TKIP\n", __func__); 785 786 psta->dot118021XPrivacy = _TKIP_; 787 788 /* DEBUG_ERR("set key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len); */ 789 /* set mic key */ 790 memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8); 791 memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8); 792 793 psecuritypriv->busetkipkey = true; 794 795 } 796 else if (strcmp(param->u.crypt.alg, "CCMP") == 0) 797 { 798 799 DBG_8192C("%s, set pairwise key, CCMP\n", __func__); 800 801 psta->dot118021XPrivacy = _AES_; 802 } 803 else 804 { 805 DBG_8192C("%s, set pairwise key, none\n", __func__); 806 807 psta->dot118021XPrivacy = _NO_PRIVACY_; 808 } 809 810 rtw_ap_set_pairwise_key(padapter, psta); 811 812 psta->ieee8021x_blocked = false; 813 814 psta->bpairwise_key_installed = true; 815 816 } 817 else/* group key??? */ 818 { 819 if (strcmp(param->u.crypt.alg, "WEP") == 0) 820 { 821 memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); 822 823 psecuritypriv->dot118021XGrpPrivacy = _WEP40_; 824 if (param->u.crypt.key_len == 13) 825 { 826 psecuritypriv->dot118021XGrpPrivacy = _WEP104_; 827 } 828 } 829 else if (strcmp(param->u.crypt.alg, "TKIP") == 0) 830 { 831 psecuritypriv->dot118021XGrpPrivacy = _TKIP_; 832 833 memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); 834 835 /* DEBUG_ERR("set key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len); */ 836 /* set mic key */ 837 memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8); 838 memcpy(psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8); 839 840 psecuritypriv->busetkipkey = true; 841 842 } 843 else if (strcmp(param->u.crypt.alg, "CCMP") == 0) 844 { 845 psecuritypriv->dot118021XGrpPrivacy = _AES_; 846 847 memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); 848 } 849 else 850 { 851 psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_; 852 } 853 854 psecuritypriv->dot118021XGrpKeyid = param->u.crypt.idx; 855 856 psecuritypriv->binstallGrpkey = true; 857 858 psecuritypriv->dot11PrivacyAlgrthm = psecuritypriv->dot118021XGrpPrivacy;/* */ 859 860 rtw_ap_set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx); 861 862 pbcmc_sta =rtw_get_bcmc_stainfo(padapter); 863 if (pbcmc_sta) 864 { 865 pbcmc_sta->ieee8021x_blocked = false; 866 pbcmc_sta->dot118021XPrivacy = psecuritypriv->dot118021XGrpPrivacy;/* rx will use bmc_sta's dot118021XPrivacy */ 867 } 868 869 } 870 871 } 872 873 } 874 875 exit: 876 877 return ret; 878 879 } 880 881 static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_param *param, u32 param_len) 882 { 883 int ret = 0; 884 u32 wep_key_idx, wep_key_len; 885 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); 886 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 887 struct security_priv *psecuritypriv = &padapter->securitypriv; 888 889 DBG_8192C("%s\n", __func__); 890 891 param->u.crypt.err = 0; 892 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0'; 893 894 if (param_len < (u32) ((u8 *) param->u.crypt.key - (u8 *) param) + param->u.crypt.key_len) 895 { 896 ret = -EINVAL; 897 goto exit; 898 } 899 900 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff && 901 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff && 902 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) 903 { 904 if (param->u.crypt.idx >= WEP_KEYS 905 || param->u.crypt.idx >= BIP_MAX_KEYID 906 ) 907 { 908 ret = -EINVAL; 909 goto exit; 910 } 911 } else { 912 { 913 ret = -EINVAL; 914 goto exit; 915 } 916 } 917 918 if (strcmp(param->u.crypt.alg, "WEP") == 0) 919 { 920 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_, ("wpa_set_encryption, crypt.alg = WEP\n")); 921 DBG_8192C("wpa_set_encryption, crypt.alg = WEP\n"); 922 923 wep_key_idx = param->u.crypt.idx; 924 wep_key_len = param->u.crypt.key_len; 925 926 if ((wep_key_idx >= WEP_KEYS) || (wep_key_len <= 0)) 927 { 928 ret = -EINVAL; 929 goto exit; 930 } 931 932 if (psecuritypriv->bWepDefaultKeyIdxSet == 0) 933 { 934 /* wep default key has not been set, so use this key index as default key. */ 935 936 wep_key_len = wep_key_len <= 5 ? 5 : 13; 937 938 psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled; 939 psecuritypriv->dot11PrivacyAlgrthm = _WEP40_; 940 psecuritypriv->dot118021XGrpPrivacy = _WEP40_; 941 942 if (wep_key_len == 13) 943 { 944 psecuritypriv->dot11PrivacyAlgrthm = _WEP104_; 945 psecuritypriv->dot118021XGrpPrivacy = _WEP104_; 946 } 947 948 psecuritypriv->dot11PrivacyKeyIndex = wep_key_idx; 949 } 950 951 memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), param->u.crypt.key, wep_key_len); 952 953 psecuritypriv->dot11DefKeylen[wep_key_idx] = wep_key_len; 954 955 rtw_set_key(padapter, psecuritypriv, wep_key_idx, 0, true); 956 957 goto exit; 958 } 959 960 if (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) /* 802_1x */ 961 { 962 struct sta_info * psta,*pbcmc_sta; 963 struct sta_priv * pstapriv = &padapter->stapriv; 964 965 /* DBG_8192C("%s, : dot11AuthAlgrthm == dot11AuthAlgrthm_8021X\n", __func__); */ 966 967 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_MP_STATE) == true) /* sta mode */ 968 { 969 psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv)); 970 if (psta == NULL) { 971 /* DEBUG_ERR(("Set wpa_set_encryption: Obtain Sta_info fail\n")); */ 972 DBG_8192C("%s, : Obtain Sta_info fail\n", __func__); 973 } 974 else 975 { 976 /* Jeff: don't disable ieee8021x_blocked while clearing key */ 977 if (strcmp(param->u.crypt.alg, "none") != 0) 978 psta->ieee8021x_blocked = false; 979 980 981 if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled)|| 982 (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled)) 983 { 984 psta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm; 985 } 986 987 if (param->u.crypt.set_tx == 1)/* pairwise key */ 988 { 989 990 DBG_8192C("%s, : param->u.crypt.set_tx == 1\n", __func__); 991 992 memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); 993 994 if (strcmp(param->u.crypt.alg, "TKIP") == 0)/* set mic key */ 995 { 996 /* DEBUG_ERR(("\nset key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len)); */ 997 memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8); 998 memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8); 999 1000 padapter->securitypriv.busetkipkey =false; 1001 /* _set_timer(&padapter->securitypriv.tkip_timer, 50); */ 1002 } 1003 1004 /* DEBUG_ERR((" param->u.crypt.key_len =%d\n", param->u.crypt.key_len)); */ 1005 DBG_871X(" ~~~~set sta key:unicastkey\n"); 1006 1007 rtw_setstakey_cmd(padapter, psta, true, true); 1008 } 1009 else/* group key */ 1010 { 1011 if (strcmp(param->u.crypt.alg, "TKIP") == 0 || strcmp(param->u.crypt.alg, "CCMP") == 0) 1012 { 1013 memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); 1014 memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey,&(param->u.crypt.key[16]), 8); 1015 memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey,&(param->u.crypt.key[24]), 8); 1016 padapter->securitypriv.binstallGrpkey = true; 1017 /* DEBUG_ERR((" param->u.crypt.key_len =%d\n", param->u.crypt.key_len)); */ 1018 DBG_871X(" ~~~~set sta key:groupkey\n"); 1019 1020 padapter->securitypriv.dot118021XGrpKeyid = param->u.crypt.idx; 1021 rtw_set_key(padapter,&padapter->securitypriv, param->u.crypt.idx, 1, true); 1022 } 1023 else if (strcmp(param->u.crypt.alg, "BIP") == 0) 1024 { 1025 /* DBG_871X("BIP key_len =%d , index =%d @@@@@@@@@@@@@@@@@@\n", param->u.crypt.key_len, param->u.crypt.idx); */ 1026 /* save the IGTK key, length 16 bytes */ 1027 memcpy(padapter->securitypriv.dot11wBIPKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); 1028 /*DBG_871X("IGTK key below:\n"); 1029 for (no = 0;no<16;no++) 1030 printk(" %02x ", padapter->securitypriv.dot11wBIPKey[param->u.crypt.idx].skey[no]); 1031 DBG_871X("\n");*/ 1032 padapter->securitypriv.dot11wBIPKeyid = param->u.crypt.idx; 1033 padapter->securitypriv.binstallBIPkey = true; 1034 DBG_871X(" ~~~~set sta key:IGKT\n"); 1035 } 1036 } 1037 } 1038 1039 pbcmc_sta =rtw_get_bcmc_stainfo(padapter); 1040 if (pbcmc_sta == NULL) 1041 { 1042 /* DEBUG_ERR(("Set OID_802_11_ADD_KEY: bcmc stainfo is null\n")); */ 1043 } 1044 else 1045 { 1046 /* Jeff: don't disable ieee8021x_blocked while clearing key */ 1047 if (strcmp(param->u.crypt.alg, "none") != 0) 1048 pbcmc_sta->ieee8021x_blocked = false; 1049 1050 if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled)|| 1051 (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled)) 1052 { 1053 pbcmc_sta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm; 1054 } 1055 } 1056 } 1057 else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) /* adhoc mode */ 1058 { 1059 } 1060 } 1061 1062 exit: 1063 1064 DBG_8192C("%s, ret =%d\n", __func__, ret); 1065 1066 return ret; 1067 } 1068 1069 static int cfg80211_rtw_add_key(struct wiphy *wiphy, struct net_device *ndev, 1070 u8 key_index, bool pairwise, const u8 *mac_addr, 1071 struct key_params *params) 1072 { 1073 char *alg_name; 1074 u32 param_len; 1075 struct ieee_param *param = NULL; 1076 int ret = 0; 1077 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(ndev); 1078 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 1079 1080 DBG_871X(FUNC_NDEV_FMT" adding key for %pM\n", FUNC_NDEV_ARG(ndev), mac_addr); 1081 DBG_871X("cipher = 0x%x\n", params->cipher); 1082 DBG_871X("key_len = 0x%x\n", params->key_len); 1083 DBG_871X("seq_len = 0x%x\n", params->seq_len); 1084 DBG_871X("key_index =%d\n", key_index); 1085 DBG_871X("pairwise =%d\n", pairwise); 1086 1087 param_len = sizeof(struct ieee_param) + params->key_len; 1088 param = rtw_malloc(param_len); 1089 if (param == NULL) 1090 return -1; 1091 1092 memset(param, 0, param_len); 1093 1094 param->cmd = IEEE_CMD_SET_ENCRYPTION; 1095 memset(param->sta_addr, 0xff, ETH_ALEN); 1096 1097 switch (params->cipher) { 1098 case IW_AUTH_CIPHER_NONE: 1099 /* todo: remove key */ 1100 /* remove = 1; */ 1101 alg_name = "none"; 1102 break; 1103 case WLAN_CIPHER_SUITE_WEP40: 1104 case WLAN_CIPHER_SUITE_WEP104: 1105 alg_name = "WEP"; 1106 break; 1107 case WLAN_CIPHER_SUITE_TKIP: 1108 alg_name = "TKIP"; 1109 break; 1110 case WLAN_CIPHER_SUITE_CCMP: 1111 alg_name = "CCMP"; 1112 break; 1113 case WLAN_CIPHER_SUITE_AES_CMAC: 1114 alg_name = "BIP"; 1115 break; 1116 default: 1117 ret = -ENOTSUPP; 1118 goto addkey_end; 1119 } 1120 1121 strncpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN); 1122 1123 1124 if (!mac_addr || is_broadcast_ether_addr(mac_addr)) 1125 { 1126 param->u.crypt.set_tx = 0; /* for wpa/wpa2 group key */ 1127 } else { 1128 param->u.crypt.set_tx = 1; /* for wpa/wpa2 pairwise key */ 1129 } 1130 1131 param->u.crypt.idx = key_index; 1132 1133 if (params->seq_len && params->seq) 1134 { 1135 memcpy(param->u.crypt.seq, (u8 *)params->seq, params->seq_len); 1136 } 1137 1138 if (params->key_len && params->key) 1139 { 1140 param->u.crypt.key_len = params->key_len; 1141 memcpy(param->u.crypt.key, (u8 *)params->key, params->key_len); 1142 } 1143 1144 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) 1145 { 1146 ret = rtw_cfg80211_set_encryption(ndev, param, param_len); 1147 } 1148 else if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) 1149 { 1150 if (mac_addr) 1151 memcpy(param->sta_addr, (void*)mac_addr, ETH_ALEN); 1152 1153 ret = rtw_cfg80211_ap_set_encryption(ndev, param, param_len); 1154 } 1155 else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true 1156 || check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true) 1157 { 1158 /* DBG_8192C("@@@@@@@@@@ fw_state = 0x%x, iftype =%d\n", pmlmepriv->fw_state, rtw_wdev->iftype); */ 1159 ret = rtw_cfg80211_set_encryption(ndev, param, param_len); 1160 } 1161 else 1162 { 1163 DBG_8192C("error!\n"); 1164 1165 } 1166 1167 addkey_end: 1168 kfree((u8 *)param); 1169 1170 return ret; 1171 1172 } 1173 1174 static int cfg80211_rtw_get_key(struct wiphy *wiphy, struct net_device *ndev, 1175 u8 key_index, bool pairwise, const u8 *mac_addr, 1176 void *cookie, 1177 void (*callback)(void *cookie, 1178 struct key_params*)) 1179 { 1180 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); 1181 return 0; 1182 } 1183 1184 static int cfg80211_rtw_del_key(struct wiphy *wiphy, struct net_device *ndev, 1185 u8 key_index, bool pairwise, const u8 *mac_addr) 1186 { 1187 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(ndev); 1188 struct security_priv *psecuritypriv = &padapter->securitypriv; 1189 1190 DBG_871X(FUNC_NDEV_FMT" key_index =%d\n", FUNC_NDEV_ARG(ndev), key_index); 1191 1192 if (key_index == psecuritypriv->dot11PrivacyKeyIndex) 1193 { 1194 /* clear the flag of wep default key set. */ 1195 psecuritypriv->bWepDefaultKeyIdxSet = 0; 1196 } 1197 1198 return 0; 1199 } 1200 1201 static int cfg80211_rtw_set_default_key(struct wiphy *wiphy, 1202 struct net_device *ndev, u8 key_index 1203 , bool unicast, bool multicast 1204 ) 1205 { 1206 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(ndev); 1207 struct security_priv *psecuritypriv = &padapter->securitypriv; 1208 1209 DBG_871X(FUNC_NDEV_FMT" key_index =%d, unicast =%d, multicast =%d\n", 1210 FUNC_NDEV_ARG(ndev), key_index, unicast, multicast); 1211 1212 if ((key_index < WEP_KEYS) && ((psecuritypriv->dot11PrivacyAlgrthm == _WEP40_) || (psecuritypriv->dot11PrivacyAlgrthm == _WEP104_))) /* set wep default key */ 1213 { 1214 psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled; 1215 1216 psecuritypriv->dot11PrivacyKeyIndex = key_index; 1217 1218 psecuritypriv->dot11PrivacyAlgrthm = _WEP40_; 1219 psecuritypriv->dot118021XGrpPrivacy = _WEP40_; 1220 if (psecuritypriv->dot11DefKeylen[key_index] == 13) 1221 { 1222 psecuritypriv->dot11PrivacyAlgrthm = _WEP104_; 1223 psecuritypriv->dot118021XGrpPrivacy = _WEP104_; 1224 } 1225 1226 psecuritypriv->bWepDefaultKeyIdxSet = 1; /* set the flag to represent that wep default key has been set */ 1227 } 1228 1229 return 0; 1230 1231 } 1232 1233 static int cfg80211_rtw_get_station(struct wiphy *wiphy, 1234 struct net_device *ndev, 1235 const u8 *mac, 1236 struct station_info *sinfo) 1237 { 1238 int ret = 0; 1239 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(ndev); 1240 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 1241 struct sta_info *psta = NULL; 1242 struct sta_priv *pstapriv = &padapter->stapriv; 1243 1244 sinfo->filled = 0; 1245 1246 if (!mac) { 1247 DBG_871X(FUNC_NDEV_FMT" mac ==%p\n", FUNC_NDEV_ARG(ndev), mac); 1248 ret = -ENOENT; 1249 goto exit; 1250 } 1251 1252 psta = rtw_get_stainfo(pstapriv, (u8 *)mac); 1253 if (psta == NULL) { 1254 DBG_8192C("%s, sta_info is null\n", __func__); 1255 ret = -ENOENT; 1256 goto exit; 1257 } 1258 1259 #ifdef DEBUG_CFG80211 1260 DBG_871X(FUNC_NDEV_FMT" mac ="MAC_FMT"\n", FUNC_NDEV_ARG(ndev), MAC_ARG(mac)); 1261 #endif 1262 1263 /* for infra./P2PClient mode */ 1264 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) 1265 && check_fwstate(pmlmepriv, _FW_LINKED) 1266 ) 1267 { 1268 struct wlan_network *cur_network = &(pmlmepriv->cur_network); 1269 1270 if (memcmp((u8 *)mac, cur_network->network.MacAddress, ETH_ALEN)) { 1271 DBG_871X("%s, mismatch bssid ="MAC_FMT"\n", __func__, MAC_ARG(cur_network->network.MacAddress)); 1272 ret = -ENOENT; 1273 goto exit; 1274 } 1275 1276 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL); 1277 sinfo->signal = translate_percentage_to_dbm(padapter->recvpriv.signal_strength); 1278 1279 sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE); 1280 sinfo->txrate.legacy = rtw_get_cur_max_rate(padapter); 1281 1282 sinfo->filled |= BIT(NL80211_STA_INFO_RX_PACKETS); 1283 sinfo->rx_packets = sta_rx_data_pkts(psta); 1284 1285 sinfo->filled |= BIT(NL80211_STA_INFO_TX_PACKETS); 1286 sinfo->tx_packets = psta->sta_stats.tx_pkts; 1287 1288 } 1289 1290 /* for Ad-Hoc/AP mode */ 1291 if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) 1292 ||check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) 1293 ||check_fwstate(pmlmepriv, WIFI_AP_STATE)) 1294 && check_fwstate(pmlmepriv, _FW_LINKED) 1295 ) 1296 { 1297 /* TODO: should acquire station info... */ 1298 } 1299 1300 exit: 1301 return ret; 1302 } 1303 1304 extern int netdev_open(struct net_device *pnetdev); 1305 1306 static int cfg80211_rtw_change_iface(struct wiphy *wiphy, 1307 struct net_device *ndev, 1308 enum nl80211_iftype type, 1309 struct vif_params *params) 1310 { 1311 enum nl80211_iftype old_type; 1312 enum NDIS_802_11_NETWORK_INFRASTRUCTURE networkType; 1313 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(ndev); 1314 struct wireless_dev *rtw_wdev = padapter->rtw_wdev; 1315 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); 1316 int ret = 0; 1317 u8 change = false; 1318 1319 DBG_871X(FUNC_NDEV_FMT" type =%d\n", FUNC_NDEV_ARG(ndev), type); 1320 1321 if (adapter_to_dvobj(padapter)->processing_dev_remove == true) 1322 { 1323 ret = -EPERM; 1324 goto exit; 1325 } 1326 1327 { 1328 DBG_871X(FUNC_NDEV_FMT" call netdev_open\n", FUNC_NDEV_ARG(ndev)); 1329 if (netdev_open(ndev) != 0) { 1330 DBG_871X(FUNC_NDEV_FMT" call netdev_open fail\n", FUNC_NDEV_ARG(ndev)); 1331 ret = -EPERM; 1332 goto exit; 1333 } 1334 } 1335 1336 if (_FAIL == rtw_pwr_wakeup(padapter)) { 1337 DBG_871X(FUNC_NDEV_FMT" call rtw_pwr_wakeup fail\n", FUNC_NDEV_ARG(ndev)); 1338 ret = -EPERM; 1339 goto exit; 1340 } 1341 1342 old_type = rtw_wdev->iftype; 1343 DBG_871X(FUNC_NDEV_FMT" old_iftype =%d, new_iftype =%d\n", 1344 FUNC_NDEV_ARG(ndev), old_type, type); 1345 1346 if (old_type != type) 1347 { 1348 change = true; 1349 pmlmeext->action_public_rxseq = 0xffff; 1350 pmlmeext->action_public_dialog_token = 0xff; 1351 } 1352 1353 switch (type) { 1354 case NL80211_IFTYPE_ADHOC: 1355 networkType = Ndis802_11IBSS; 1356 break; 1357 case NL80211_IFTYPE_STATION: 1358 networkType = Ndis802_11Infrastructure; 1359 break; 1360 case NL80211_IFTYPE_AP: 1361 networkType = Ndis802_11APMode; 1362 break; 1363 default: 1364 ret = -EOPNOTSUPP; 1365 goto exit; 1366 } 1367 1368 rtw_wdev->iftype = type; 1369 1370 if (rtw_set_802_11_infrastructure_mode(padapter, networkType) ==false) 1371 { 1372 rtw_wdev->iftype = old_type; 1373 ret = -EPERM; 1374 goto exit; 1375 } 1376 1377 rtw_setopmode_cmd(padapter, networkType, true); 1378 1379 exit: 1380 1381 DBG_871X(FUNC_NDEV_FMT" ret:%d\n", FUNC_NDEV_ARG(ndev), ret); 1382 return ret; 1383 } 1384 1385 void rtw_cfg80211_indicate_scan_done(struct adapter *adapter, bool aborted) 1386 { 1387 struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(adapter); 1388 struct cfg80211_scan_info info = { 1389 .aborted = aborted 1390 }; 1391 1392 spin_lock_bh(&pwdev_priv->scan_req_lock); 1393 if (pwdev_priv->scan_request != NULL) { 1394 #ifdef DEBUG_CFG80211 1395 DBG_871X("%s with scan req\n", __func__); 1396 #endif 1397 1398 /* avoid WARN_ON(request != wiphy_to_dev(request->wiphy)->scan_req); */ 1399 if (pwdev_priv->scan_request->wiphy != pwdev_priv->rtw_wdev->wiphy) 1400 { 1401 DBG_8192C("error wiphy compare\n"); 1402 } 1403 else 1404 { 1405 cfg80211_scan_done(pwdev_priv->scan_request, &info); 1406 } 1407 1408 pwdev_priv->scan_request = NULL; 1409 } else { 1410 #ifdef DEBUG_CFG80211 1411 DBG_871X("%s without scan req\n", __func__); 1412 #endif 1413 } 1414 spin_unlock_bh(&pwdev_priv->scan_req_lock); 1415 } 1416 1417 void rtw_cfg80211_unlink_bss(struct adapter *padapter, struct wlan_network *pnetwork) 1418 { 1419 struct wireless_dev *pwdev = padapter->rtw_wdev; 1420 struct wiphy *wiphy = pwdev->wiphy; 1421 struct cfg80211_bss *bss = NULL; 1422 struct wlan_bssid_ex select_network = pnetwork->network; 1423 1424 bss = cfg80211_get_bss(wiphy, NULL/*notify_channel*/, 1425 select_network.MacAddress, select_network.Ssid.Ssid, 1426 select_network.Ssid.SsidLength, 0/*WLAN_CAPABILITY_ESS*/, 1427 0/*WLAN_CAPABILITY_ESS*/); 1428 1429 if (bss) { 1430 cfg80211_unlink_bss(wiphy, bss); 1431 DBG_8192C("%s(): cfg80211_unlink %s!! () ", __func__, select_network.Ssid.Ssid); 1432 cfg80211_put_bss(padapter->rtw_wdev->wiphy, bss); 1433 } 1434 return; 1435 } 1436 1437 void rtw_cfg80211_surveydone_event_callback(struct adapter *padapter) 1438 { 1439 struct list_head *plist, *phead; 1440 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 1441 struct __queue *queue = &(pmlmepriv->scanned_queue); 1442 struct wlan_network *pnetwork = NULL; 1443 1444 #ifdef DEBUG_CFG80211 1445 DBG_8192C("%s\n", __func__); 1446 #endif 1447 1448 spin_lock_bh(&(pmlmepriv->scanned_queue.lock)); 1449 1450 phead = get_list_head(queue); 1451 plist = get_next(phead); 1452 1453 while (1) 1454 { 1455 if (phead == plist) 1456 break; 1457 1458 pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list); 1459 1460 /* report network only if the current channel set contains the channel to which this network belongs */ 1461 if (rtw_ch_set_search_ch(padapter->mlmeextpriv.channel_set, pnetwork->network.Configuration.DSConfig) >= 0 1462 && rtw_mlme_band_check(padapter, pnetwork->network.Configuration.DSConfig) == true 1463 && true == rtw_validate_ssid(&(pnetwork->network.Ssid)) 1464 ) 1465 { 1466 /* ev =translate_scan(padapter, a, pnetwork, ev, stop); */ 1467 rtw_cfg80211_inform_bss(padapter, pnetwork); 1468 } 1469 1470 plist = get_next(plist); 1471 1472 } 1473 1474 spin_unlock_bh(&(pmlmepriv->scanned_queue.lock)); 1475 } 1476 1477 static int rtw_cfg80211_set_probe_req_wpsp2pie(struct adapter *padapter, char *buf, int len) 1478 { 1479 int ret = 0; 1480 uint wps_ielen = 0; 1481 u8 *wps_ie; 1482 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 1483 1484 #ifdef DEBUG_CFG80211 1485 DBG_8192C("%s, ielen =%d\n", __func__, len); 1486 #endif 1487 1488 if (len>0) 1489 { 1490 if ((wps_ie = rtw_get_wps_ie(buf, len, NULL, &wps_ielen))) 1491 { 1492 #ifdef DEBUG_CFG80211 1493 DBG_8192C("probe_req_wps_ielen =%d\n", wps_ielen); 1494 #endif 1495 1496 if (pmlmepriv->wps_probe_req_ie) 1497 { 1498 pmlmepriv->wps_probe_req_ie_len = 0; 1499 kfree(pmlmepriv->wps_probe_req_ie); 1500 pmlmepriv->wps_probe_req_ie = NULL; 1501 } 1502 1503 pmlmepriv->wps_probe_req_ie = rtw_malloc(wps_ielen); 1504 if (pmlmepriv->wps_probe_req_ie == NULL) { 1505 DBG_8192C("%s()-%d: rtw_malloc() ERROR!\n", __func__, __LINE__); 1506 return -EINVAL; 1507 1508 } 1509 memcpy(pmlmepriv->wps_probe_req_ie, wps_ie, wps_ielen); 1510 pmlmepriv->wps_probe_req_ie_len = wps_ielen; 1511 } 1512 } 1513 1514 return ret; 1515 1516 } 1517 1518 static int cfg80211_rtw_scan(struct wiphy *wiphy 1519 , struct cfg80211_scan_request *request) 1520 { 1521 struct net_device *ndev = wdev_to_ndev(request->wdev); 1522 int i; 1523 u8 _status = false; 1524 int ret = 0; 1525 struct ndis_802_11_ssid ssid[RTW_SSID_SCAN_AMOUNT]; 1526 struct rtw_ieee80211_channel ch[RTW_CHANNEL_SCAN_AMOUNT]; 1527 u8 survey_times =3; 1528 u8 survey_times_for_one_ch =6; 1529 struct cfg80211_ssid *ssids = request->ssids; 1530 int j = 0; 1531 bool need_indicate_scan_done = false; 1532 1533 struct adapter *padapter; 1534 struct rtw_wdev_priv *pwdev_priv; 1535 struct mlme_priv *pmlmepriv; 1536 1537 if (ndev == NULL) { 1538 ret = -EINVAL; 1539 goto exit; 1540 } 1541 1542 padapter = (struct adapter *)rtw_netdev_priv(ndev); 1543 pwdev_priv = adapter_wdev_data(padapter); 1544 pmlmepriv = &padapter->mlmepriv; 1545 1546 /* ifdef DEBUG_CFG80211 */ 1547 DBG_871X(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter)); 1548 /* endif */ 1549 1550 spin_lock_bh(&pwdev_priv->scan_req_lock); 1551 pwdev_priv->scan_request = request; 1552 spin_unlock_bh(&pwdev_priv->scan_req_lock); 1553 1554 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) 1555 { 1556 #ifdef DEBUG_CFG80211 1557 DBG_871X("%s under WIFI_AP_STATE\n", __func__); 1558 #endif 1559 1560 if (check_fwstate(pmlmepriv, WIFI_UNDER_WPS|_FW_UNDER_SURVEY|_FW_UNDER_LINKING) == true) 1561 { 1562 DBG_8192C("%s, fwstate = 0x%x\n", __func__, pmlmepriv->fw_state); 1563 1564 if (check_fwstate(pmlmepriv, WIFI_UNDER_WPS)) 1565 { 1566 DBG_8192C("AP mode process WPS\n"); 1567 } 1568 1569 need_indicate_scan_done = true; 1570 goto check_need_indicate_scan_done; 1571 } 1572 } 1573 1574 rtw_ps_deny(padapter, PS_DENY_SCAN); 1575 if (_FAIL == rtw_pwr_wakeup(padapter)) { 1576 need_indicate_scan_done = true; 1577 goto check_need_indicate_scan_done; 1578 } 1579 1580 if (request->ie && request->ie_len>0) 1581 { 1582 rtw_cfg80211_set_probe_req_wpsp2pie(padapter, (u8 *)request->ie, request->ie_len); 1583 } 1584 1585 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == true) { 1586 DBG_8192C("%s, fwstate = 0x%x\n", __func__, pmlmepriv->fw_state); 1587 need_indicate_scan_done = true; 1588 goto check_need_indicate_scan_done; 1589 } else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == true) { 1590 DBG_8192C("%s, fwstate = 0x%x\n", __func__, pmlmepriv->fw_state); 1591 ret = -EBUSY; 1592 goto check_need_indicate_scan_done; 1593 } 1594 1595 if (pmlmepriv->LinkDetectInfo.bBusyTraffic == true) 1596 { 1597 static unsigned long lastscantime = 0; 1598 unsigned long passtime; 1599 1600 passtime = jiffies_to_msecs(jiffies - lastscantime); 1601 lastscantime = jiffies; 1602 if (passtime > 12000) 1603 { 1604 DBG_871X("%s: bBusyTraffic == true\n", __func__); 1605 need_indicate_scan_done = true; 1606 goto check_need_indicate_scan_done; 1607 } 1608 } 1609 1610 if (rtw_is_scan_deny(padapter)) { 1611 DBG_871X(FUNC_ADPT_FMT ": scan deny\n", FUNC_ADPT_ARG(padapter)); 1612 need_indicate_scan_done = true; 1613 goto check_need_indicate_scan_done; 1614 } 1615 1616 memset(ssid, 0, sizeof(struct ndis_802_11_ssid)*RTW_SSID_SCAN_AMOUNT); 1617 /* parsing request ssids, n_ssids */ 1618 for (i = 0; i < request->n_ssids && i < RTW_SSID_SCAN_AMOUNT; i++) { 1619 #ifdef DEBUG_CFG80211 1620 DBG_8192C("ssid =%s, len =%d\n", ssids[i].ssid, ssids[i].ssid_len); 1621 #endif 1622 memcpy(ssid[i].Ssid, ssids[i].ssid, ssids[i].ssid_len); 1623 ssid[i].SsidLength = ssids[i].ssid_len; 1624 } 1625 1626 /* parsing channels, n_channels */ 1627 memset(ch, 0, sizeof(struct rtw_ieee80211_channel)*RTW_CHANNEL_SCAN_AMOUNT); 1628 for (i = 0;i<request->n_channels && i<RTW_CHANNEL_SCAN_AMOUNT;i++) { 1629 #ifdef DEBUG_CFG80211 1630 DBG_871X(FUNC_ADPT_FMT CHAN_FMT"\n", FUNC_ADPT_ARG(padapter), CHAN_ARG(request->channels[i])); 1631 #endif 1632 ch[i].hw_value = request->channels[i]->hw_value; 1633 ch[i].flags = request->channels[i]->flags; 1634 } 1635 1636 spin_lock_bh(&pmlmepriv->lock); 1637 if (request->n_channels == 1) { 1638 for (i = 1;i<survey_times_for_one_ch;i++) 1639 memcpy(&ch[i], &ch[0], sizeof(struct rtw_ieee80211_channel)); 1640 _status = rtw_sitesurvey_cmd(padapter, ssid, RTW_SSID_SCAN_AMOUNT, ch, survey_times_for_one_ch); 1641 } else if (request->n_channels <= 4) { 1642 for (j =request->n_channels-1;j>= 0;j--) 1643 for (i = 0;i<survey_times;i++) 1644 { 1645 memcpy(&ch[j*survey_times+i], &ch[j], sizeof(struct rtw_ieee80211_channel)); 1646 } 1647 _status = rtw_sitesurvey_cmd(padapter, ssid, RTW_SSID_SCAN_AMOUNT, ch, survey_times * request->n_channels); 1648 } else { 1649 _status = rtw_sitesurvey_cmd(padapter, ssid, RTW_SSID_SCAN_AMOUNT, NULL, 0); 1650 } 1651 spin_unlock_bh(&pmlmepriv->lock); 1652 1653 1654 if (_status == false) 1655 { 1656 ret = -1; 1657 } 1658 1659 check_need_indicate_scan_done: 1660 if (true == need_indicate_scan_done) 1661 { 1662 rtw_cfg80211_surveydone_event_callback(padapter); 1663 rtw_cfg80211_indicate_scan_done(padapter, false); 1664 } 1665 1666 rtw_ps_deny_cancel(padapter, PS_DENY_SCAN); 1667 1668 exit: 1669 return ret; 1670 1671 } 1672 1673 static int cfg80211_rtw_set_wiphy_params(struct wiphy *wiphy, u32 changed) 1674 { 1675 DBG_8192C("%s\n", __func__); 1676 return 0; 1677 } 1678 1679 1680 1681 static int rtw_cfg80211_set_wpa_version(struct security_priv *psecuritypriv, u32 wpa_version) 1682 { 1683 DBG_8192C("%s, wpa_version =%d\n", __func__, wpa_version); 1684 1685 if (!wpa_version) { 1686 psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen; 1687 return 0; 1688 } 1689 1690 1691 if (wpa_version & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2)) 1692 { 1693 psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPAPSK; 1694 } 1695 1696 return 0; 1697 1698 } 1699 1700 static int rtw_cfg80211_set_auth_type(struct security_priv *psecuritypriv, 1701 enum nl80211_auth_type sme_auth_type) 1702 { 1703 DBG_8192C("%s, nl80211_auth_type =%d\n", __func__, sme_auth_type); 1704 1705 1706 switch (sme_auth_type) { 1707 case NL80211_AUTHTYPE_AUTOMATIC: 1708 1709 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Auto; 1710 1711 break; 1712 case NL80211_AUTHTYPE_OPEN_SYSTEM: 1713 1714 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; 1715 1716 if (psecuritypriv->ndisauthtype>Ndis802_11AuthModeWPA) 1717 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; 1718 1719 break; 1720 case NL80211_AUTHTYPE_SHARED_KEY: 1721 1722 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Shared; 1723 1724 psecuritypriv->ndisencryptstatus = Ndis802_11Encryption1Enabled; 1725 1726 1727 break; 1728 default: 1729 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; 1730 /* return -ENOTSUPP; */ 1731 } 1732 1733 return 0; 1734 1735 } 1736 1737 static int rtw_cfg80211_set_cipher(struct security_priv *psecuritypriv, u32 cipher, bool ucast) 1738 { 1739 u32 ndisencryptstatus = Ndis802_11EncryptionDisabled; 1740 1741 u32 *profile_cipher = ucast ? &psecuritypriv->dot11PrivacyAlgrthm : 1742 &psecuritypriv->dot118021XGrpPrivacy; 1743 1744 DBG_8192C("%s, ucast =%d, cipher = 0x%x\n", __func__, ucast, cipher); 1745 1746 1747 if (!cipher) { 1748 *profile_cipher = _NO_PRIVACY_; 1749 psecuritypriv->ndisencryptstatus = ndisencryptstatus; 1750 return 0; 1751 } 1752 1753 switch (cipher) { 1754 case IW_AUTH_CIPHER_NONE: 1755 *profile_cipher = _NO_PRIVACY_; 1756 ndisencryptstatus = Ndis802_11EncryptionDisabled; 1757 break; 1758 case WLAN_CIPHER_SUITE_WEP40: 1759 *profile_cipher = _WEP40_; 1760 ndisencryptstatus = Ndis802_11Encryption1Enabled; 1761 break; 1762 case WLAN_CIPHER_SUITE_WEP104: 1763 *profile_cipher = _WEP104_; 1764 ndisencryptstatus = Ndis802_11Encryption1Enabled; 1765 break; 1766 case WLAN_CIPHER_SUITE_TKIP: 1767 *profile_cipher = _TKIP_; 1768 ndisencryptstatus = Ndis802_11Encryption2Enabled; 1769 break; 1770 case WLAN_CIPHER_SUITE_CCMP: 1771 *profile_cipher = _AES_; 1772 ndisencryptstatus = Ndis802_11Encryption3Enabled; 1773 break; 1774 default: 1775 DBG_8192C("Unsupported cipher: 0x%x\n", cipher); 1776 return -ENOTSUPP; 1777 } 1778 1779 if (ucast) 1780 { 1781 psecuritypriv->ndisencryptstatus = ndisencryptstatus; 1782 1783 /* if (psecuritypriv->dot11PrivacyAlgrthm >= _AES_) */ 1784 /* psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPA2PSK; */ 1785 } 1786 1787 return 0; 1788 } 1789 1790 static int rtw_cfg80211_set_key_mgt(struct security_priv *psecuritypriv, u32 key_mgt) 1791 { 1792 DBG_8192C("%s, key_mgt = 0x%x\n", __func__, key_mgt); 1793 1794 if (key_mgt == WLAN_AKM_SUITE_8021X) 1795 /* auth_type = UMAC_AUTH_TYPE_8021X; */ 1796 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; 1797 else if (key_mgt == WLAN_AKM_SUITE_PSK) { 1798 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; 1799 } 1800 else { 1801 DBG_8192C("Invalid key mgt: 0x%x\n", key_mgt); 1802 /* return -EINVAL; */ 1803 } 1804 1805 return 0; 1806 } 1807 1808 static int rtw_cfg80211_set_wpa_ie(struct adapter *padapter, u8 *pie, size_t ielen) 1809 { 1810 u8 *buf = NULL, *pos = NULL; 1811 int group_cipher = 0, pairwise_cipher = 0; 1812 int ret = 0; 1813 int wpa_ielen = 0; 1814 int wpa2_ielen = 0; 1815 u8 *pwpa, *pwpa2; 1816 u8 null_addr[]= {0, 0, 0, 0, 0, 0}; 1817 1818 if (pie == NULL || !ielen) { 1819 /* Treat this as normal case, but need to clear WIFI_UNDER_WPS */ 1820 _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS); 1821 goto exit; 1822 } 1823 1824 if (ielen > MAX_WPA_IE_LEN+MAX_WPS_IE_LEN+MAX_P2P_IE_LEN) { 1825 ret = -EINVAL; 1826 goto exit; 1827 } 1828 1829 buf = rtw_zmalloc(ielen); 1830 if (buf == NULL) { 1831 ret = -ENOMEM; 1832 goto exit; 1833 } 1834 1835 memcpy(buf, pie , ielen); 1836 1837 /* dump */ 1838 { 1839 int i; 1840 DBG_8192C("set wpa_ie(length:%zu):\n", ielen); 1841 for (i = 0;i<ielen;i =i+8) 1842 DBG_8192C("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]); 1843 } 1844 1845 pos = buf; 1846 if (ielen < RSN_HEADER_LEN) { 1847 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_, ("Ie len too short %d\n", ielen)); 1848 ret = -1; 1849 goto exit; 1850 } 1851 1852 pwpa = rtw_get_wpa_ie(buf, &wpa_ielen, ielen); 1853 if (pwpa && wpa_ielen>0) 1854 { 1855 if (rtw_parse_wpa_ie(pwpa, wpa_ielen+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) 1856 { 1857 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; 1858 padapter->securitypriv.ndisauthtype =Ndis802_11AuthModeWPAPSK; 1859 memcpy(padapter->securitypriv.supplicant_ie, &pwpa[0], wpa_ielen+2); 1860 1861 DBG_8192C("got wpa_ie, wpa_ielen:%u\n", wpa_ielen); 1862 } 1863 } 1864 1865 pwpa2 = rtw_get_wpa2_ie(buf, &wpa2_ielen, ielen); 1866 if (pwpa2 && wpa2_ielen>0) 1867 { 1868 if (rtw_parse_wpa2_ie(pwpa2, wpa2_ielen+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) 1869 { 1870 padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; 1871 padapter->securitypriv.ndisauthtype =Ndis802_11AuthModeWPA2PSK; 1872 memcpy(padapter->securitypriv.supplicant_ie, &pwpa2[0], wpa2_ielen+2); 1873 1874 DBG_8192C("got wpa2_ie, wpa2_ielen:%u\n", wpa2_ielen); 1875 } 1876 } 1877 1878 if (group_cipher == 0) 1879 { 1880 group_cipher = WPA_CIPHER_NONE; 1881 } 1882 if (pairwise_cipher == 0) 1883 { 1884 pairwise_cipher = WPA_CIPHER_NONE; 1885 } 1886 1887 switch (group_cipher) 1888 { 1889 case WPA_CIPHER_NONE: 1890 padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_; 1891 padapter->securitypriv.ndisencryptstatus =Ndis802_11EncryptionDisabled; 1892 break; 1893 case WPA_CIPHER_WEP40: 1894 padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_; 1895 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; 1896 break; 1897 case WPA_CIPHER_TKIP: 1898 padapter->securitypriv.dot118021XGrpPrivacy = _TKIP_; 1899 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled; 1900 break; 1901 case WPA_CIPHER_CCMP: 1902 padapter->securitypriv.dot118021XGrpPrivacy = _AES_; 1903 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled; 1904 break; 1905 case WPA_CIPHER_WEP104: 1906 padapter->securitypriv.dot118021XGrpPrivacy = _WEP104_; 1907 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; 1908 break; 1909 } 1910 1911 switch (pairwise_cipher) 1912 { 1913 case WPA_CIPHER_NONE: 1914 padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_; 1915 padapter->securitypriv.ndisencryptstatus =Ndis802_11EncryptionDisabled; 1916 break; 1917 case WPA_CIPHER_WEP40: 1918 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_; 1919 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; 1920 break; 1921 case WPA_CIPHER_TKIP: 1922 padapter->securitypriv.dot11PrivacyAlgrthm = _TKIP_; 1923 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled; 1924 break; 1925 case WPA_CIPHER_CCMP: 1926 padapter->securitypriv.dot11PrivacyAlgrthm = _AES_; 1927 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption3Enabled; 1928 break; 1929 case WPA_CIPHER_WEP104: 1930 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_; 1931 padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; 1932 break; 1933 } 1934 1935 {/* handle wps_ie */ 1936 uint wps_ielen; 1937 u8 *wps_ie; 1938 1939 wps_ie = rtw_get_wps_ie(buf, ielen, NULL, &wps_ielen); 1940 if (wps_ie && wps_ielen > 0) { 1941 DBG_8192C("got wps_ie, wps_ielen:%u\n", wps_ielen); 1942 padapter->securitypriv.wps_ie_len = wps_ielen<MAX_WPS_IE_LEN?wps_ielen:MAX_WPS_IE_LEN; 1943 memcpy(padapter->securitypriv.wps_ie, wps_ie, padapter->securitypriv.wps_ie_len); 1944 set_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS); 1945 } else { 1946 _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS); 1947 } 1948 } 1949 1950 /* TKIP and AES disallow multicast packets until installing group key */ 1951 if (padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_ 1952 || padapter->securitypriv.dot11PrivacyAlgrthm == _TKIP_WTMIC_ 1953 || padapter->securitypriv.dot11PrivacyAlgrthm == _AES_) 1954 /* WPS open need to enable multicast */ 1955 /* check_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS) == true) */ 1956 rtw_hal_set_hwreg(padapter, HW_VAR_OFF_RCR_AM, null_addr); 1957 1958 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, 1959 ("rtw_set_wpa_ie: pairwise_cipher = 0x%08x padapter->securitypriv.ndisencryptstatus =%d padapter->securitypriv.ndisauthtype =%d\n", 1960 pairwise_cipher, padapter->securitypriv.ndisencryptstatus, padapter->securitypriv.ndisauthtype)); 1961 1962 exit: 1963 kfree(buf); 1964 if (ret) 1965 _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS); 1966 return ret; 1967 } 1968 1969 static int cfg80211_rtw_join_ibss(struct wiphy *wiphy, struct net_device *ndev, 1970 struct cfg80211_ibss_params *params) 1971 { 1972 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(ndev); 1973 struct ndis_802_11_ssid ndis_ssid; 1974 struct security_priv *psecuritypriv = &padapter->securitypriv; 1975 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 1976 int ret = 0; 1977 1978 if (_FAIL == rtw_pwr_wakeup(padapter)) { 1979 ret = -EPERM; 1980 goto exit; 1981 } 1982 1983 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { 1984 ret = -EPERM; 1985 goto exit; 1986 } 1987 1988 if (!params->ssid || !params->ssid_len) 1989 { 1990 ret = -EINVAL; 1991 goto exit; 1992 } 1993 1994 if (params->ssid_len > IW_ESSID_MAX_SIZE) { 1995 1996 ret = -E2BIG; 1997 goto exit; 1998 } 1999 2000 memset(&ndis_ssid, 0, sizeof(struct ndis_802_11_ssid)); 2001 ndis_ssid.SsidLength = params->ssid_len; 2002 memcpy(ndis_ssid.Ssid, (u8 *)params->ssid, params->ssid_len); 2003 2004 /* DBG_8192C("ssid =%s, len =%zu\n", ndis_ssid.Ssid, params->ssid_len); */ 2005 2006 psecuritypriv->ndisencryptstatus = Ndis802_11EncryptionDisabled; 2007 psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_; 2008 psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_; 2009 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */ 2010 psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen; 2011 2012 ret = rtw_cfg80211_set_auth_type(psecuritypriv, NL80211_AUTHTYPE_OPEN_SYSTEM); 2013 rtw_set_802_11_authentication_mode(padapter, psecuritypriv->ndisauthtype); 2014 2015 if (rtw_set_802_11_ssid(padapter, &ndis_ssid) == false) 2016 { 2017 ret = -1; 2018 goto exit; 2019 } 2020 2021 exit: 2022 return ret; 2023 } 2024 2025 static int cfg80211_rtw_leave_ibss(struct wiphy *wiphy, struct net_device *ndev) 2026 { 2027 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(ndev); 2028 struct wireless_dev *rtw_wdev = padapter->rtw_wdev; 2029 enum nl80211_iftype old_type; 2030 int ret = 0; 2031 2032 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); 2033 2034 padapter->mlmepriv.not_indic_disco = true; 2035 2036 old_type = rtw_wdev->iftype; 2037 2038 rtw_set_to_roam(padapter, 0); 2039 2040 if (check_fwstate(&padapter->mlmepriv, _FW_LINKED)) 2041 { 2042 rtw_scan_abort(padapter); 2043 LeaveAllPowerSaveMode(padapter); 2044 2045 rtw_wdev->iftype = NL80211_IFTYPE_STATION; 2046 2047 if (rtw_set_802_11_infrastructure_mode(padapter, Ndis802_11Infrastructure) ==false) 2048 { 2049 rtw_wdev->iftype = old_type; 2050 ret = -EPERM; 2051 goto leave_ibss; 2052 } 2053 rtw_setopmode_cmd(padapter, Ndis802_11Infrastructure, true); 2054 } 2055 2056 leave_ibss: 2057 padapter->mlmepriv.not_indic_disco = false; 2058 2059 return 0; 2060 } 2061 2062 static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev, 2063 struct cfg80211_connect_params *sme) 2064 { 2065 int ret = 0; 2066 enum NDIS_802_11_AUTHENTICATION_MODE authmode; 2067 struct ndis_802_11_ssid ndis_ssid; 2068 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(ndev); 2069 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 2070 struct security_priv *psecuritypriv = &padapter->securitypriv; 2071 2072 padapter->mlmepriv.not_indic_disco = true; 2073 2074 DBG_871X("=>"FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); 2075 DBG_871X("privacy =%d, key =%p, key_len =%d, key_idx =%d\n", 2076 sme->privacy, sme->key, sme->key_len, sme->key_idx); 2077 2078 2079 if (adapter_wdev_data(padapter)->block == true) 2080 { 2081 ret = -EBUSY; 2082 DBG_871X("%s wdev_priv.block is set\n", __func__); 2083 goto exit; 2084 } 2085 2086 rtw_ps_deny(padapter, PS_DENY_JOIN); 2087 if (_FAIL == rtw_pwr_wakeup(padapter)) { 2088 ret = -EPERM; 2089 goto exit; 2090 } 2091 2092 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { 2093 ret = -EPERM; 2094 goto exit; 2095 } 2096 2097 if (!sme->ssid || !sme->ssid_len) 2098 { 2099 ret = -EINVAL; 2100 goto exit; 2101 } 2102 2103 if (sme->ssid_len > IW_ESSID_MAX_SIZE) { 2104 2105 ret = -E2BIG; 2106 goto exit; 2107 } 2108 2109 memset(&ndis_ssid, 0, sizeof(struct ndis_802_11_ssid)); 2110 ndis_ssid.SsidLength = sme->ssid_len; 2111 memcpy(ndis_ssid.Ssid, (u8 *)sme->ssid, sme->ssid_len); 2112 2113 DBG_8192C("ssid =%s, len =%zu\n", ndis_ssid.Ssid, sme->ssid_len); 2114 2115 2116 if (sme->bssid) 2117 DBG_8192C("bssid ="MAC_FMT"\n", MAC_ARG(sme->bssid)); 2118 2119 2120 if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == true) { 2121 ret = -EBUSY; 2122 DBG_8192C("%s, fw_state = 0x%x, goto exit\n", __func__, pmlmepriv->fw_state); 2123 goto exit; 2124 } 2125 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == true) { 2126 rtw_scan_abort(padapter); 2127 } 2128 2129 psecuritypriv->ndisencryptstatus = Ndis802_11EncryptionDisabled; 2130 psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_; 2131 psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_; 2132 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */ 2133 psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen; 2134 2135 ret = rtw_cfg80211_set_wpa_version(psecuritypriv, sme->crypto.wpa_versions); 2136 if (ret < 0) 2137 goto exit; 2138 2139 ret = rtw_cfg80211_set_auth_type(psecuritypriv, sme->auth_type); 2140 2141 if (ret < 0) 2142 goto exit; 2143 2144 DBG_8192C("%s, ie_len =%zu\n", __func__, sme->ie_len); 2145 2146 ret = rtw_cfg80211_set_wpa_ie(padapter, (u8 *)sme->ie, sme->ie_len); 2147 if (ret < 0) 2148 goto exit; 2149 2150 if (sme->crypto.n_ciphers_pairwise) { 2151 ret = rtw_cfg80211_set_cipher(psecuritypriv, sme->crypto.ciphers_pairwise[0], true); 2152 if (ret < 0) 2153 goto exit; 2154 } 2155 2156 /* For WEP Shared auth */ 2157 if ((psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_Shared 2158 || psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_Auto) && sme->key 2159 ) 2160 { 2161 u32 wep_key_idx, wep_key_len, wep_total_len; 2162 struct ndis_802_11_wep *pwep = NULL; 2163 DBG_871X("%s(): Shared/Auto WEP\n", __func__); 2164 2165 wep_key_idx = sme->key_idx; 2166 wep_key_len = sme->key_len; 2167 2168 if (sme->key_idx > WEP_KEYS) { 2169 ret = -EINVAL; 2170 goto exit; 2171 } 2172 2173 if (wep_key_len > 0) 2174 { 2175 wep_key_len = wep_key_len <= 5 ? 5 : 13; 2176 wep_total_len = wep_key_len + FIELD_OFFSET(struct ndis_802_11_wep, KeyMaterial); 2177 pwep = rtw_malloc(wep_total_len); 2178 if (pwep == NULL) { 2179 DBG_871X(" wpa_set_encryption: pwep allocate fail !!!\n"); 2180 ret = -ENOMEM; 2181 goto exit; 2182 } 2183 2184 memset(pwep, 0, wep_total_len); 2185 2186 pwep->KeyLength = wep_key_len; 2187 pwep->Length = wep_total_len; 2188 2189 if (wep_key_len == 13) 2190 { 2191 padapter->securitypriv.dot11PrivacyAlgrthm = _WEP104_; 2192 padapter->securitypriv.dot118021XGrpPrivacy = _WEP104_; 2193 } 2194 } 2195 else { 2196 ret = -EINVAL; 2197 goto exit; 2198 } 2199 2200 pwep->KeyIndex = wep_key_idx; 2201 pwep->KeyIndex |= 0x80000000; 2202 2203 memcpy(pwep->KeyMaterial, (void *)sme->key, pwep->KeyLength); 2204 2205 if (rtw_set_802_11_add_wep(padapter, pwep) == (u8)_FAIL) 2206 { 2207 ret = -EOPNOTSUPP ; 2208 } 2209 2210 kfree((u8 *)pwep); 2211 2212 if (ret < 0) 2213 goto exit; 2214 } 2215 2216 ret = rtw_cfg80211_set_cipher(psecuritypriv, sme->crypto.cipher_group, false); 2217 if (ret < 0) 2218 return ret; 2219 2220 if (sme->crypto.n_akm_suites) { 2221 ret = rtw_cfg80211_set_key_mgt(psecuritypriv, sme->crypto.akm_suites[0]); 2222 if (ret < 0) 2223 goto exit; 2224 } 2225 2226 authmode = psecuritypriv->ndisauthtype; 2227 rtw_set_802_11_authentication_mode(padapter, authmode); 2228 2229 /* rtw_set_802_11_encryption_mode(padapter, padapter->securitypriv.ndisencryptstatus); */ 2230 2231 if (rtw_set_802_11_connect(padapter, (u8 *)sme->bssid, &ndis_ssid) == false) { 2232 ret = -1; 2233 goto exit; 2234 } 2235 2236 DBG_8192C("set ssid:dot11AuthAlgrthm =%d, dot11PrivacyAlgrthm =%d, dot118021XGrpPrivacy =%d\n", psecuritypriv->dot11AuthAlgrthm, psecuritypriv->dot11PrivacyAlgrthm, psecuritypriv->dot118021XGrpPrivacy); 2237 2238 exit: 2239 2240 rtw_ps_deny_cancel(padapter, PS_DENY_JOIN); 2241 2242 DBG_8192C("<=%s, ret %d\n", __func__, ret); 2243 2244 padapter->mlmepriv.not_indic_disco = false; 2245 2246 return ret; 2247 } 2248 2249 static int cfg80211_rtw_disconnect(struct wiphy *wiphy, struct net_device *ndev, 2250 u16 reason_code) 2251 { 2252 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(ndev); 2253 2254 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); 2255 2256 padapter->mlmepriv.not_indic_disco = true; 2257 2258 rtw_set_to_roam(padapter, 0); 2259 2260 rtw_scan_abort(padapter); 2261 LeaveAllPowerSaveMode(padapter); 2262 rtw_disassoc_cmd(padapter, 500, false); 2263 2264 DBG_871X("%s...call rtw_indicate_disconnect\n", __func__); 2265 2266 rtw_indicate_disconnect(padapter); 2267 2268 rtw_free_assoc_resources(padapter, 1); 2269 rtw_pwr_wakeup(padapter); 2270 2271 padapter->mlmepriv.not_indic_disco = false; 2272 2273 DBG_871X(FUNC_NDEV_FMT" return 0\n", FUNC_NDEV_ARG(ndev)); 2274 return 0; 2275 } 2276 2277 static int cfg80211_rtw_set_txpower(struct wiphy *wiphy, 2278 struct wireless_dev *wdev, 2279 enum nl80211_tx_power_setting type, int mbm) 2280 { 2281 DBG_8192C("%s\n", __func__); 2282 return 0; 2283 } 2284 2285 static int cfg80211_rtw_get_txpower(struct wiphy *wiphy, 2286 struct wireless_dev *wdev, 2287 int *dbm) 2288 { 2289 DBG_8192C("%s\n", __func__); 2290 2291 *dbm = (12); 2292 2293 return 0; 2294 } 2295 2296 inline bool rtw_cfg80211_pwr_mgmt(struct adapter *adapter) 2297 { 2298 struct rtw_wdev_priv *rtw_wdev_priv = adapter_wdev_data(adapter); 2299 return rtw_wdev_priv->power_mgmt; 2300 } 2301 2302 static int cfg80211_rtw_set_power_mgmt(struct wiphy *wiphy, 2303 struct net_device *ndev, 2304 bool enabled, int timeout) 2305 { 2306 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(ndev); 2307 struct rtw_wdev_priv *rtw_wdev_priv = adapter_wdev_data(padapter); 2308 2309 DBG_871X(FUNC_NDEV_FMT" enabled:%u, timeout:%d\n", FUNC_NDEV_ARG(ndev), 2310 enabled, timeout); 2311 2312 rtw_wdev_priv->power_mgmt = enabled; 2313 2314 if (!enabled) 2315 LPS_Leave(padapter, "CFG80211_PWRMGMT"); 2316 2317 return 0; 2318 } 2319 2320 static int cfg80211_rtw_set_pmksa(struct wiphy *wiphy, 2321 struct net_device *ndev, 2322 struct cfg80211_pmksa *pmksa) 2323 { 2324 u8 index, blInserted = false; 2325 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(ndev); 2326 struct security_priv *psecuritypriv = &padapter->securitypriv; 2327 u8 strZeroMacAddress[ ETH_ALEN ] = { 0x00 }; 2328 2329 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); 2330 2331 if (!memcmp((u8 *)pmksa->bssid, strZeroMacAddress, ETH_ALEN)) 2332 { 2333 return -EINVAL; 2334 } 2335 2336 blInserted = false; 2337 2338 /* overwrite PMKID */ 2339 for (index = 0 ; index<NUM_PMKID_CACHE; index++) 2340 { 2341 if (!memcmp(psecuritypriv->PMKIDList[index].Bssid, (u8 *)pmksa->bssid, ETH_ALEN)) 2342 { /* BSSID is matched, the same AP => rewrite with new PMKID. */ 2343 DBG_871X(FUNC_NDEV_FMT" BSSID exists in the PMKList.\n", FUNC_NDEV_ARG(ndev)); 2344 2345 memcpy(psecuritypriv->PMKIDList[index].PMKID, (u8 *)pmksa->pmkid, WLAN_PMKID_LEN); 2346 psecuritypriv->PMKIDList[index].bUsed = true; 2347 psecuritypriv->PMKIDIndex = index+1; 2348 blInserted = true; 2349 break; 2350 } 2351 } 2352 2353 if (!blInserted) 2354 { 2355 /* Find a new entry */ 2356 DBG_871X(FUNC_NDEV_FMT" Use the new entry index = %d for this PMKID.\n", 2357 FUNC_NDEV_ARG(ndev), psecuritypriv->PMKIDIndex); 2358 2359 memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].Bssid, (u8 *)pmksa->bssid, ETH_ALEN); 2360 memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].PMKID, (u8 *)pmksa->pmkid, WLAN_PMKID_LEN); 2361 2362 psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].bUsed = true; 2363 psecuritypriv->PMKIDIndex++ ; 2364 if (psecuritypriv->PMKIDIndex == 16) 2365 { 2366 psecuritypriv->PMKIDIndex = 0; 2367 } 2368 } 2369 2370 return 0; 2371 } 2372 2373 static int cfg80211_rtw_del_pmksa(struct wiphy *wiphy, 2374 struct net_device *ndev, 2375 struct cfg80211_pmksa *pmksa) 2376 { 2377 u8 index, bMatched = false; 2378 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(ndev); 2379 struct security_priv *psecuritypriv = &padapter->securitypriv; 2380 2381 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); 2382 2383 for (index = 0 ; index<NUM_PMKID_CACHE; index++) 2384 { 2385 if (!memcmp(psecuritypriv->PMKIDList[index].Bssid, (u8 *)pmksa->bssid, ETH_ALEN)) 2386 { /* BSSID is matched, the same AP => Remove this PMKID information and reset it. */ 2387 eth_zero_addr(psecuritypriv->PMKIDList[index].Bssid); 2388 memset(psecuritypriv->PMKIDList[index].PMKID, 0x00, WLAN_PMKID_LEN); 2389 psecuritypriv->PMKIDList[index].bUsed = false; 2390 bMatched = true; 2391 break; 2392 } 2393 } 2394 2395 if (false == bMatched) 2396 { 2397 DBG_871X(FUNC_NDEV_FMT" do not have matched BSSID\n" 2398 , FUNC_NDEV_ARG(ndev)); 2399 return -EINVAL; 2400 } 2401 2402 return 0; 2403 } 2404 2405 static int cfg80211_rtw_flush_pmksa(struct wiphy *wiphy, 2406 struct net_device *ndev) 2407 { 2408 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(ndev); 2409 struct security_priv *psecuritypriv = &padapter->securitypriv; 2410 2411 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); 2412 2413 memset(&psecuritypriv->PMKIDList[ 0 ], 0x00, sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE); 2414 psecuritypriv->PMKIDIndex = 0; 2415 2416 return 0; 2417 } 2418 2419 void rtw_cfg80211_indicate_sta_assoc(struct adapter *padapter, u8 *pmgmt_frame, uint frame_len) 2420 { 2421 struct net_device *ndev = padapter->pnetdev; 2422 2423 DBG_871X(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter)); 2424 2425 { 2426 struct station_info sinfo; 2427 u8 ie_offset; 2428 if (GetFrameSubType(pmgmt_frame) == WIFI_ASSOCREQ) 2429 ie_offset = _ASOCREQ_IE_OFFSET_; 2430 else /* WIFI_REASSOCREQ */ 2431 ie_offset = _REASOCREQ_IE_OFFSET_; 2432 2433 sinfo.filled = 0; 2434 sinfo.assoc_req_ies = pmgmt_frame + WLAN_HDR_A3_LEN + ie_offset; 2435 sinfo.assoc_req_ies_len = frame_len - WLAN_HDR_A3_LEN - ie_offset; 2436 cfg80211_new_sta(ndev, GetAddr2Ptr(pmgmt_frame), &sinfo, GFP_ATOMIC); 2437 } 2438 } 2439 2440 void rtw_cfg80211_indicate_sta_disassoc(struct adapter *padapter, unsigned char *da, unsigned short reason) 2441 { 2442 struct net_device *ndev = padapter->pnetdev; 2443 2444 DBG_871X(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter)); 2445 2446 cfg80211_del_sta(ndev, da, GFP_ATOMIC); 2447 } 2448 2449 static int rtw_cfg80211_monitor_if_open(struct net_device *ndev) 2450 { 2451 int ret = 0; 2452 2453 DBG_8192C("%s\n", __func__); 2454 2455 return ret; 2456 } 2457 2458 static int rtw_cfg80211_monitor_if_close(struct net_device *ndev) 2459 { 2460 int ret = 0; 2461 2462 DBG_8192C("%s\n", __func__); 2463 2464 return ret; 2465 } 2466 2467 static netdev_tx_t rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb, struct net_device *ndev) 2468 { 2469 int ret = 0; 2470 int rtap_len; 2471 int qos_len = 0; 2472 int dot11_hdr_len = 24; 2473 int snap_len = 6; 2474 unsigned char *pdata; 2475 u16 frame_control; 2476 unsigned char src_mac_addr[6]; 2477 unsigned char dst_mac_addr[6]; 2478 struct ieee80211_hdr *dot11_hdr; 2479 struct ieee80211_radiotap_header *rtap_hdr; 2480 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(ndev); 2481 2482 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); 2483 2484 if (!skb) 2485 goto fail; 2486 2487 rtw_mstat_update(MSTAT_TYPE_SKB, MSTAT_ALLOC_SUCCESS, skb->truesize); 2488 2489 if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header))) 2490 goto fail; 2491 2492 rtap_hdr = (struct ieee80211_radiotap_header *)skb->data; 2493 if (unlikely(rtap_hdr->it_version)) 2494 goto fail; 2495 2496 rtap_len = ieee80211_get_radiotap_len(skb->data); 2497 if (unlikely(skb->len < rtap_len)) 2498 goto fail; 2499 2500 if (rtap_len != 14) 2501 { 2502 DBG_8192C("radiotap len (should be 14): %d\n", rtap_len); 2503 goto fail; 2504 } 2505 2506 /* Skip the ratio tap header */ 2507 skb_pull(skb, rtap_len); 2508 2509 dot11_hdr = (struct ieee80211_hdr *)skb->data; 2510 frame_control = le16_to_cpu(dot11_hdr->frame_control); 2511 /* Check if the QoS bit is set */ 2512 if ((frame_control & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) { 2513 /* Check if this ia a Wireless Distribution System (WDS) frame 2514 * which has 4 MAC addresses 2515 */ 2516 if (frame_control & 0x0080) 2517 qos_len = 2; 2518 if ((frame_control & 0x0300) == 0x0300) 2519 dot11_hdr_len += 6; 2520 2521 memcpy(dst_mac_addr, dot11_hdr->addr1, sizeof(dst_mac_addr)); 2522 memcpy(src_mac_addr, dot11_hdr->addr2, sizeof(src_mac_addr)); 2523 2524 /* Skip the 802.11 header, QoS (if any) and SNAP, but leave spaces for 2525 * for two MAC addresses 2526 */ 2527 skb_pull(skb, dot11_hdr_len + qos_len + snap_len - sizeof(src_mac_addr) * 2); 2528 pdata = (unsigned char*)skb->data; 2529 memcpy(pdata, dst_mac_addr, sizeof(dst_mac_addr)); 2530 memcpy(pdata + sizeof(dst_mac_addr), src_mac_addr, sizeof(src_mac_addr)); 2531 2532 DBG_8192C("should be eapol packet\n"); 2533 2534 /* Use the real net device to transmit the packet */ 2535 ret = _rtw_xmit_entry(skb, padapter->pnetdev); 2536 2537 return ret; 2538 2539 } 2540 else if ((frame_control & (IEEE80211_FCTL_FTYPE|IEEE80211_FCTL_STYPE)) 2541 == (IEEE80211_FTYPE_MGMT|IEEE80211_STYPE_ACTION) 2542 ) 2543 { 2544 /* only for action frames */ 2545 struct xmit_frame *pmgntframe; 2546 struct pkt_attrib *pattrib; 2547 unsigned char *pframe; 2548 /* u8 category, action, OUI_Subtype, dialogToken = 0; */ 2549 /* unsigned char *frame_body; */ 2550 struct ieee80211_hdr *pwlanhdr; 2551 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); 2552 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); 2553 u8 *buf = skb->data; 2554 u32 len = skb->len; 2555 u8 category, action; 2556 2557 if (rtw_action_frame_parse(buf, len, &category, &action) == false) { 2558 DBG_8192C(FUNC_NDEV_FMT" frame_control:0x%x\n", FUNC_NDEV_ARG(ndev), 2559 le16_to_cpu(((struct ieee80211_hdr_3addr *)buf)->frame_control)); 2560 goto fail; 2561 } 2562 2563 DBG_8192C("RTW_Tx:da ="MAC_FMT" via "FUNC_NDEV_FMT"\n", 2564 MAC_ARG(GetAddr1Ptr(buf)), FUNC_NDEV_ARG(ndev)); 2565 if (category == RTW_WLAN_CATEGORY_PUBLIC) 2566 DBG_871X("RTW_Tx:%s\n", action_public_str(action)); 2567 else 2568 DBG_871X("RTW_Tx:category(%u), action(%u)\n", category, action); 2569 2570 /* starting alloc mgmt frame to dump it */ 2571 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL) 2572 { 2573 goto fail; 2574 } 2575 2576 /* update attribute */ 2577 pattrib = &pmgntframe->attrib; 2578 update_mgntframe_attrib(padapter, pattrib); 2579 pattrib->retry_ctrl = false; 2580 2581 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET); 2582 2583 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; 2584 2585 memcpy(pframe, (void*)buf, len); 2586 pattrib->pktlen = len; 2587 2588 pwlanhdr = (struct ieee80211_hdr *)pframe; 2589 /* update seq number */ 2590 pmlmeext->mgnt_seq = GetSequence(pwlanhdr); 2591 pattrib->seqnum = pmlmeext->mgnt_seq; 2592 pmlmeext->mgnt_seq++; 2593 2594 2595 pattrib->last_txcmdsz = pattrib->pktlen; 2596 2597 dump_mgntframe(padapter, pmgntframe); 2598 2599 } 2600 else 2601 { 2602 DBG_8192C("frame_control = 0x%x\n", frame_control & (IEEE80211_FCTL_FTYPE|IEEE80211_FCTL_STYPE)); 2603 } 2604 2605 2606 fail: 2607 2608 dev_kfree_skb_any(skb); 2609 2610 return 0; 2611 2612 } 2613 2614 static int rtw_cfg80211_monitor_if_set_mac_address(struct net_device *ndev, void *addr) 2615 { 2616 int ret = 0; 2617 2618 DBG_8192C("%s\n", __func__); 2619 2620 return ret; 2621 } 2622 2623 static const struct net_device_ops rtw_cfg80211_monitor_if_ops = { 2624 .ndo_open = rtw_cfg80211_monitor_if_open, 2625 .ndo_stop = rtw_cfg80211_monitor_if_close, 2626 .ndo_start_xmit = rtw_cfg80211_monitor_if_xmit_entry, 2627 .ndo_set_mac_address = rtw_cfg80211_monitor_if_set_mac_address, 2628 }; 2629 2630 static int rtw_cfg80211_add_monitor_if (struct adapter *padapter, char *name, struct net_device **ndev) 2631 { 2632 int ret = 0; 2633 struct net_device* mon_ndev = NULL; 2634 struct wireless_dev* mon_wdev = NULL; 2635 struct rtw_netdev_priv_indicator *pnpi; 2636 struct rtw_wdev_priv *pwdev_priv = adapter_wdev_data(padapter); 2637 2638 if (!name) { 2639 DBG_871X(FUNC_ADPT_FMT" without specific name\n", FUNC_ADPT_ARG(padapter)); 2640 ret = -EINVAL; 2641 goto out; 2642 } 2643 2644 if (pwdev_priv->pmon_ndev) { 2645 DBG_871X(FUNC_ADPT_FMT" monitor interface exist: "NDEV_FMT"\n", 2646 FUNC_ADPT_ARG(padapter), NDEV_ARG(pwdev_priv->pmon_ndev)); 2647 ret = -EBUSY; 2648 goto out; 2649 } 2650 2651 mon_ndev = alloc_etherdev(sizeof(struct rtw_netdev_priv_indicator)); 2652 if (!mon_ndev) { 2653 DBG_871X(FUNC_ADPT_FMT" allocate ndev fail\n", FUNC_ADPT_ARG(padapter)); 2654 ret = -ENOMEM; 2655 goto out; 2656 } 2657 2658 mon_ndev->type = ARPHRD_IEEE80211_RADIOTAP; 2659 strncpy(mon_ndev->name, name, IFNAMSIZ); 2660 mon_ndev->name[IFNAMSIZ - 1] = 0; 2661 mon_ndev->needs_free_netdev = true; 2662 mon_ndev->priv_destructor = rtw_ndev_destructor; 2663 2664 mon_ndev->netdev_ops = &rtw_cfg80211_monitor_if_ops; 2665 2666 pnpi = netdev_priv(mon_ndev); 2667 pnpi->priv = padapter; 2668 pnpi->sizeof_priv = sizeof(struct adapter); 2669 2670 /* wdev */ 2671 mon_wdev = rtw_zmalloc(sizeof(struct wireless_dev)); 2672 if (!mon_wdev) { 2673 DBG_871X(FUNC_ADPT_FMT" allocate mon_wdev fail\n", FUNC_ADPT_ARG(padapter)); 2674 ret = -ENOMEM; 2675 goto out; 2676 } 2677 2678 mon_wdev->wiphy = padapter->rtw_wdev->wiphy; 2679 mon_wdev->netdev = mon_ndev; 2680 mon_wdev->iftype = NL80211_IFTYPE_MONITOR; 2681 mon_ndev->ieee80211_ptr = mon_wdev; 2682 2683 ret = register_netdevice(mon_ndev); 2684 if (ret) { 2685 goto out; 2686 } 2687 2688 *ndev = pwdev_priv->pmon_ndev = mon_ndev; 2689 memcpy(pwdev_priv->ifname_mon, name, IFNAMSIZ+1); 2690 2691 out: 2692 if (ret && mon_wdev) { 2693 kfree((u8 *)mon_wdev); 2694 mon_wdev = NULL; 2695 } 2696 2697 if (ret && mon_ndev) { 2698 free_netdev(mon_ndev); 2699 *ndev = mon_ndev = NULL; 2700 } 2701 2702 return ret; 2703 } 2704 2705 static struct wireless_dev * 2706 cfg80211_rtw_add_virtual_intf( 2707 struct wiphy *wiphy, 2708 const char *name, 2709 unsigned char name_assign_type, 2710 enum nl80211_iftype type, struct vif_params *params) 2711 { 2712 int ret = 0; 2713 struct net_device* ndev = NULL; 2714 struct adapter *padapter = wiphy_to_adapter(wiphy); 2715 2716 DBG_871X(FUNC_ADPT_FMT " wiphy:%s, name:%s, type:%d\n", 2717 FUNC_ADPT_ARG(padapter), wiphy_name(wiphy), name, type); 2718 2719 switch (type) { 2720 case NL80211_IFTYPE_ADHOC: 2721 case NL80211_IFTYPE_AP_VLAN: 2722 case NL80211_IFTYPE_WDS: 2723 case NL80211_IFTYPE_MESH_POINT: 2724 ret = -ENODEV; 2725 break; 2726 case NL80211_IFTYPE_MONITOR: 2727 ret = rtw_cfg80211_add_monitor_if(padapter, (char *)name, &ndev); 2728 break; 2729 case NL80211_IFTYPE_P2P_CLIENT: 2730 case NL80211_IFTYPE_STATION: 2731 ret = -ENODEV; 2732 break; 2733 case NL80211_IFTYPE_P2P_GO: 2734 case NL80211_IFTYPE_AP: 2735 ret = -ENODEV; 2736 break; 2737 default: 2738 ret = -ENODEV; 2739 DBG_871X("Unsupported interface type\n"); 2740 break; 2741 } 2742 2743 DBG_871X(FUNC_ADPT_FMT" ndev:%p, ret:%d\n", FUNC_ADPT_ARG(padapter), ndev, ret); 2744 2745 return ndev ? ndev->ieee80211_ptr : ERR_PTR(ret); 2746 } 2747 2748 static int cfg80211_rtw_del_virtual_intf(struct wiphy *wiphy, 2749 struct wireless_dev *wdev 2750 ) 2751 { 2752 struct net_device *ndev = wdev_to_ndev(wdev); 2753 int ret = 0; 2754 struct adapter *adapter; 2755 struct rtw_wdev_priv *pwdev_priv; 2756 2757 if (!ndev) { 2758 ret = -EINVAL; 2759 goto exit; 2760 } 2761 2762 adapter = (struct adapter *)rtw_netdev_priv(ndev); 2763 pwdev_priv = adapter_wdev_data(adapter); 2764 2765 unregister_netdevice(ndev); 2766 2767 if (ndev == pwdev_priv->pmon_ndev) { 2768 pwdev_priv->pmon_ndev = NULL; 2769 pwdev_priv->ifname_mon[0] = '\0'; 2770 DBG_871X(FUNC_NDEV_FMT" remove monitor interface\n", FUNC_NDEV_ARG(ndev)); 2771 } 2772 2773 exit: 2774 return ret; 2775 } 2776 2777 static int rtw_add_beacon(struct adapter *adapter, const u8 *head, size_t head_len, const u8 *tail, size_t tail_len) 2778 { 2779 int ret = 0; 2780 u8 *pbuf = NULL; 2781 uint len, wps_ielen = 0; 2782 struct mlme_priv *pmlmepriv = &(adapter->mlmepriv); 2783 2784 DBG_8192C("%s beacon_head_len =%zu, beacon_tail_len =%zu\n", __func__, head_len, tail_len); 2785 2786 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != true) 2787 return -EINVAL; 2788 2789 if (head_len<24) 2790 return -EINVAL; 2791 2792 pbuf = rtw_zmalloc(head_len+tail_len); 2793 if (!pbuf) 2794 return -ENOMEM; 2795 2796 memcpy(pbuf, (void *)head+24, head_len-24);/* 24 =beacon header len. */ 2797 memcpy(pbuf+head_len-24, (void *)tail, tail_len); 2798 2799 len = head_len+tail_len-24; 2800 2801 /* check wps ie if inclued */ 2802 if (rtw_get_wps_ie(pbuf+_FIXED_IE_LENGTH_, len-_FIXED_IE_LENGTH_, NULL, &wps_ielen)) 2803 DBG_8192C("add bcn, wps_ielen =%d\n", wps_ielen); 2804 2805 /* pbss_network->IEs will not include p2p_ie, wfd ie */ 2806 rtw_ies_remove_ie(pbuf, &len, _BEACON_IE_OFFSET_, _VENDOR_SPECIFIC_IE_, P2P_OUI, 4); 2807 rtw_ies_remove_ie(pbuf, &len, _BEACON_IE_OFFSET_, _VENDOR_SPECIFIC_IE_, WFD_OUI, 4); 2808 2809 if (rtw_check_beacon_data(adapter, pbuf, len) == _SUCCESS) 2810 { 2811 ret = 0; 2812 } 2813 else 2814 { 2815 ret = -EINVAL; 2816 } 2817 2818 2819 kfree(pbuf); 2820 2821 return ret; 2822 } 2823 2824 static int cfg80211_rtw_start_ap(struct wiphy *wiphy, struct net_device *ndev, 2825 struct cfg80211_ap_settings *settings) 2826 { 2827 int ret = 0; 2828 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(ndev); 2829 2830 DBG_871X(FUNC_NDEV_FMT" hidden_ssid:%d, auth_type:%d\n", FUNC_NDEV_ARG(ndev), 2831 settings->hidden_ssid, settings->auth_type); 2832 2833 ret = rtw_add_beacon(adapter, settings->beacon.head, settings->beacon.head_len, 2834 settings->beacon.tail, settings->beacon.tail_len); 2835 2836 adapter->mlmeextpriv.mlmext_info.hidden_ssid_mode = settings->hidden_ssid; 2837 2838 if (settings->ssid && settings->ssid_len) { 2839 struct wlan_bssid_ex *pbss_network = &adapter->mlmepriv.cur_network.network; 2840 struct wlan_bssid_ex *pbss_network_ext = &adapter->mlmeextpriv.mlmext_info.network; 2841 2842 memcpy(pbss_network->Ssid.Ssid, (void *)settings->ssid, settings->ssid_len); 2843 pbss_network->Ssid.SsidLength = settings->ssid_len; 2844 memcpy(pbss_network_ext->Ssid.Ssid, (void *)settings->ssid, settings->ssid_len); 2845 pbss_network_ext->Ssid.SsidLength = settings->ssid_len; 2846 } 2847 2848 return ret; 2849 } 2850 2851 static int cfg80211_rtw_change_beacon(struct wiphy *wiphy, struct net_device *ndev, 2852 struct cfg80211_beacon_data *info) 2853 { 2854 int ret = 0; 2855 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(ndev); 2856 2857 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); 2858 2859 ret = rtw_add_beacon(adapter, info->head, info->head_len, info->tail, info->tail_len); 2860 2861 return ret; 2862 } 2863 2864 static int cfg80211_rtw_stop_ap(struct wiphy *wiphy, struct net_device *ndev) 2865 { 2866 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); 2867 return 0; 2868 } 2869 2870 static int cfg80211_rtw_add_station(struct wiphy *wiphy, struct net_device *ndev, 2871 const u8 *mac, 2872 struct station_parameters *params) 2873 { 2874 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); 2875 2876 return 0; 2877 } 2878 2879 static int cfg80211_rtw_del_station(struct wiphy *wiphy, struct net_device *ndev, 2880 struct station_del_parameters *params) 2881 { 2882 int ret = 0; 2883 struct list_head *phead, *plist; 2884 u8 updated = false; 2885 struct sta_info *psta = NULL; 2886 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(ndev); 2887 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 2888 struct sta_priv *pstapriv = &padapter->stapriv; 2889 const u8 *mac = params->mac; 2890 2891 DBG_871X("+"FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); 2892 2893 if (check_fwstate(pmlmepriv, (_FW_LINKED|WIFI_AP_STATE)) != true) 2894 { 2895 DBG_8192C("%s, fw_state != FW_LINKED|WIFI_AP_STATE\n", __func__); 2896 return -EINVAL; 2897 } 2898 2899 2900 if (!mac) 2901 { 2902 DBG_8192C("flush all sta, and cam_entry\n"); 2903 2904 flush_all_cam_entry(padapter); /* clear CAM */ 2905 2906 ret = rtw_sta_flush(padapter); 2907 2908 return ret; 2909 } 2910 2911 2912 DBG_8192C("free sta macaddr =" MAC_FMT "\n", MAC_ARG(mac)); 2913 2914 if (mac[0] == 0xff && mac[1] == 0xff && 2915 mac[2] == 0xff && mac[3] == 0xff && 2916 mac[4] == 0xff && mac[5] == 0xff) 2917 { 2918 return -EINVAL; 2919 } 2920 2921 2922 spin_lock_bh(&pstapriv->asoc_list_lock); 2923 2924 phead = &pstapriv->asoc_list; 2925 plist = get_next(phead); 2926 2927 /* check asoc_queue */ 2928 while (phead != plist) 2929 { 2930 psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list); 2931 2932 plist = get_next(plist); 2933 2934 if (!memcmp((u8 *)mac, psta->hwaddr, ETH_ALEN)) 2935 { 2936 if (psta->dot8021xalg == 1 && psta->bpairwise_key_installed == false) 2937 { 2938 DBG_8192C("%s, sta's dot8021xalg = 1 and key_installed = false\n", __func__); 2939 } 2940 else 2941 { 2942 DBG_8192C("free psta =%p, aid =%d\n", psta, psta->aid); 2943 2944 list_del_init(&psta->asoc_list); 2945 pstapriv->asoc_list_cnt--; 2946 2947 updated = ap_free_sta(padapter, psta, true, WLAN_REASON_DEAUTH_LEAVING); 2948 2949 psta = NULL; 2950 2951 break; 2952 } 2953 2954 } 2955 2956 } 2957 2958 spin_unlock_bh(&pstapriv->asoc_list_lock); 2959 2960 associated_clients_update(padapter, updated); 2961 2962 DBG_871X("-"FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); 2963 2964 return ret; 2965 2966 } 2967 2968 static int cfg80211_rtw_change_station(struct wiphy *wiphy, struct net_device *ndev, 2969 const u8 *mac, struct station_parameters *params) 2970 { 2971 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); 2972 2973 return 0; 2974 } 2975 2976 static struct sta_info *rtw_sta_info_get_by_idx(const int idx, struct sta_priv *pstapriv) 2977 2978 { 2979 struct list_head *phead, *plist; 2980 struct sta_info *psta = NULL; 2981 int i = 0; 2982 2983 phead = &pstapriv->asoc_list; 2984 plist = get_next(phead); 2985 2986 /* check asoc_queue */ 2987 while (phead != plist) 2988 { 2989 if (idx == i) psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list); 2990 plist = get_next(plist); 2991 i++; 2992 } 2993 return psta; 2994 } 2995 2996 static int cfg80211_rtw_dump_station(struct wiphy *wiphy, struct net_device *ndev, 2997 int idx, u8 *mac, struct station_info *sinfo) 2998 { 2999 3000 int ret = 0; 3001 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(ndev); 3002 struct sta_info *psta = NULL; 3003 struct sta_priv *pstapriv = &padapter->stapriv; 3004 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); 3005 3006 spin_lock_bh(&pstapriv->asoc_list_lock); 3007 psta = rtw_sta_info_get_by_idx(idx, pstapriv); 3008 spin_unlock_bh(&pstapriv->asoc_list_lock); 3009 if (NULL == psta) 3010 { 3011 DBG_871X("Station is not found\n"); 3012 ret = -ENOENT; 3013 goto exit; 3014 } 3015 memcpy(mac, psta->hwaddr, ETH_ALEN); 3016 sinfo->filled = BIT(NL80211_STA_INFO_SIGNAL); 3017 sinfo->signal = psta->rssi; 3018 3019 exit: 3020 return ret; 3021 } 3022 3023 static int cfg80211_rtw_change_bss(struct wiphy *wiphy, struct net_device *ndev, 3024 struct bss_parameters *params) 3025 { 3026 DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); 3027 return 0; 3028 } 3029 3030 void rtw_cfg80211_rx_action(struct adapter *adapter, u8 *frame, uint frame_len, const char*msg) 3031 { 3032 s32 freq; 3033 int channel; 3034 u8 category, action; 3035 3036 channel = rtw_get_oper_ch(adapter); 3037 3038 rtw_action_frame_parse(frame, frame_len, &category, &action); 3039 3040 DBG_8192C("RTW_Rx:cur_ch =%d\n", channel); 3041 if (msg) 3042 DBG_871X("RTW_Rx:%s\n", msg); 3043 else 3044 DBG_871X("RTW_Rx:category(%u), action(%u)\n", category, action); 3045 3046 freq = rtw_ieee80211_channel_to_frequency(channel, NL80211_BAND_2GHZ); 3047 3048 rtw_cfg80211_rx_mgmt(adapter, freq, 0, frame, frame_len, GFP_ATOMIC); 3049 } 3050 3051 static int _cfg80211_rtw_mgmt_tx(struct adapter *padapter, u8 tx_ch, const u8 *buf, size_t len) 3052 { 3053 struct xmit_frame *pmgntframe; 3054 struct pkt_attrib *pattrib; 3055 unsigned char *pframe; 3056 int ret = _FAIL; 3057 bool ack = true; 3058 struct ieee80211_hdr *pwlanhdr; 3059 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); 3060 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); 3061 3062 rtw_set_scan_deny(padapter, 1000); 3063 3064 rtw_scan_abort(padapter); 3065 if (tx_ch != rtw_get_oper_ch(padapter)) { 3066 if (!check_fwstate(&padapter->mlmepriv, _FW_LINKED)) 3067 pmlmeext->cur_channel = tx_ch; 3068 set_channel_bwmode(padapter, tx_ch, HAL_PRIME_CHNL_OFFSET_DONT_CARE, CHANNEL_WIDTH_20); 3069 } 3070 3071 /* starting alloc mgmt frame to dump it */ 3072 if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL) 3073 { 3074 /* ret = -ENOMEM; */ 3075 ret = _FAIL; 3076 goto exit; 3077 } 3078 3079 /* update attribute */ 3080 pattrib = &pmgntframe->attrib; 3081 update_mgntframe_attrib(padapter, pattrib); 3082 pattrib->retry_ctrl = false; 3083 3084 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET); 3085 3086 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET; 3087 3088 memcpy(pframe, (void*)buf, len); 3089 pattrib->pktlen = len; 3090 3091 pwlanhdr = (struct ieee80211_hdr *)pframe; 3092 /* update seq number */ 3093 pmlmeext->mgnt_seq = GetSequence(pwlanhdr); 3094 pattrib->seqnum = pmlmeext->mgnt_seq; 3095 pmlmeext->mgnt_seq++; 3096 3097 pattrib->last_txcmdsz = pattrib->pktlen; 3098 3099 if (dump_mgntframe_and_wait_ack(padapter, pmgntframe) != _SUCCESS) 3100 { 3101 ack = false; 3102 ret = _FAIL; 3103 3104 #ifdef DEBUG_CFG80211 3105 DBG_8192C("%s, ack == _FAIL\n", __func__); 3106 #endif 3107 } 3108 else 3109 { 3110 3111 msleep(50); 3112 3113 #ifdef DEBUG_CFG80211 3114 DBG_8192C("%s, ack =%d, ok!\n", __func__, ack); 3115 #endif 3116 ret = _SUCCESS; 3117 } 3118 3119 exit: 3120 3121 #ifdef DEBUG_CFG80211 3122 DBG_8192C("%s, ret =%d\n", __func__, ret); 3123 #endif 3124 3125 return ret; 3126 3127 } 3128 3129 static int cfg80211_rtw_mgmt_tx(struct wiphy *wiphy, 3130 struct wireless_dev *wdev, 3131 struct cfg80211_mgmt_tx_params *params, 3132 u64 *cookie) 3133 { 3134 struct net_device *ndev = wdev_to_ndev(wdev); 3135 struct ieee80211_channel *chan = params->chan; 3136 const u8 *buf = params->buf; 3137 size_t len = params->len; 3138 int ret = 0; 3139 int tx_ret; 3140 u32 dump_limit = RTW_MAX_MGMT_TX_CNT; 3141 u32 dump_cnt = 0; 3142 bool ack = true; 3143 u8 tx_ch = (u8)ieee80211_frequency_to_channel(chan->center_freq); 3144 u8 category, action; 3145 int type = (-1); 3146 struct adapter *padapter; 3147 struct rtw_wdev_priv *pwdev_priv; 3148 3149 if (ndev == NULL) { 3150 ret = -EINVAL; 3151 goto exit; 3152 } 3153 3154 padapter = (struct adapter *)rtw_netdev_priv(ndev); 3155 pwdev_priv = adapter_wdev_data(padapter); 3156 3157 /* cookie generation */ 3158 *cookie = (unsigned long) buf; 3159 3160 #ifdef DEBUG_CFG80211 3161 DBG_871X(FUNC_ADPT_FMT" len =%zu, ch =%d" 3162 "\n", FUNC_ADPT_ARG(padapter), 3163 len, tx_ch 3164 ); 3165 #endif /* DEBUG_CFG80211 */ 3166 3167 /* indicate ack before issue frame to avoid racing with rsp frame */ 3168 rtw_cfg80211_mgmt_tx_status(padapter, *cookie, buf, len, ack, GFP_KERNEL); 3169 3170 if (rtw_action_frame_parse(buf, len, &category, &action) == false) { 3171 DBG_8192C(FUNC_ADPT_FMT" frame_control:0x%x\n", FUNC_ADPT_ARG(padapter), 3172 le16_to_cpu(((struct ieee80211_hdr_3addr *)buf)->frame_control)); 3173 goto exit; 3174 } 3175 3176 DBG_8192C("RTW_Tx:tx_ch =%d, da ="MAC_FMT"\n", tx_ch, MAC_ARG(GetAddr1Ptr(buf))); 3177 if (category == RTW_WLAN_CATEGORY_PUBLIC) 3178 DBG_871X("RTW_Tx:%s\n", action_public_str(action)); 3179 else 3180 DBG_871X("RTW_Tx:category(%u), action(%u)\n", category, action); 3181 3182 rtw_ps_deny(padapter, PS_DENY_MGNT_TX); 3183 if (_FAIL == rtw_pwr_wakeup(padapter)) { 3184 ret = -EFAULT; 3185 goto cancel_ps_deny; 3186 } 3187 3188 do { 3189 dump_cnt++; 3190 tx_ret = _cfg80211_rtw_mgmt_tx(padapter, tx_ch, buf, len); 3191 } while (dump_cnt < dump_limit && tx_ret != _SUCCESS); 3192 3193 if (tx_ret != _SUCCESS || dump_cnt > 1) { 3194 DBG_871X(FUNC_ADPT_FMT" %s (%d/%d)\n", FUNC_ADPT_ARG(padapter), 3195 tx_ret == _SUCCESS?"OK":"FAIL", dump_cnt, dump_limit); 3196 } 3197 3198 switch (type) { 3199 case P2P_GO_NEGO_CONF: 3200 rtw_clear_scan_deny(padapter); 3201 break; 3202 case P2P_INVIT_RESP: 3203 if (pwdev_priv->invit_info.flags & BIT(0) 3204 && pwdev_priv->invit_info.status == 0) 3205 { 3206 DBG_871X(FUNC_ADPT_FMT" agree with invitation of persistent group\n", 3207 FUNC_ADPT_ARG(padapter)); 3208 rtw_set_scan_deny(padapter, 5000); 3209 rtw_pwr_wakeup_ex(padapter, 5000); 3210 rtw_clear_scan_deny(padapter); 3211 } 3212 break; 3213 } 3214 3215 cancel_ps_deny: 3216 rtw_ps_deny_cancel(padapter, PS_DENY_MGNT_TX); 3217 exit: 3218 return ret; 3219 } 3220 3221 static void cfg80211_rtw_mgmt_frame_register(struct wiphy *wiphy, 3222 struct wireless_dev *wdev, 3223 u16 frame_type, bool reg) 3224 { 3225 struct net_device *ndev = wdev_to_ndev(wdev); 3226 struct adapter *adapter; 3227 3228 if (ndev == NULL) 3229 goto exit; 3230 3231 adapter = (struct adapter *)rtw_netdev_priv(ndev); 3232 3233 #ifdef DEBUG_CFG80211 3234 DBG_871X(FUNC_ADPT_FMT" frame_type:%x, reg:%d\n", FUNC_ADPT_ARG(adapter), 3235 frame_type, reg); 3236 #endif 3237 3238 if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ)) 3239 return; 3240 exit: 3241 return; 3242 } 3243 3244 #if defined(CONFIG_PNO_SUPPORT) 3245 static int cfg80211_rtw_sched_scan_start(struct wiphy *wiphy, 3246 struct net_device *dev, 3247 struct cfg80211_sched_scan_request *request) { 3248 3249 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); 3250 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 3251 int ret; 3252 3253 if (padapter->bup == false) { 3254 DBG_871X("%s: net device is down.\n", __func__); 3255 return -EIO; 3256 } 3257 3258 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == true || 3259 check_fwstate(pmlmepriv, _FW_LINKED) == true || 3260 check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == true) { 3261 DBG_871X("%s: device is busy.\n", __func__); 3262 rtw_scan_abort(padapter); 3263 } 3264 3265 if (request == NULL) { 3266 DBG_871X("%s: invalid cfg80211_requests parameters.\n", __func__); 3267 return -EINVAL; 3268 } 3269 3270 ret = rtw_android_cfg80211_pno_setup(dev, request->ssids, 3271 request->n_ssids, request->interval); 3272 3273 if (ret < 0) { 3274 DBG_871X("%s ret: %d\n", __func__, ret); 3275 goto exit; 3276 } 3277 3278 ret = rtw_android_pno_enable(dev, true); 3279 if (ret < 0) { 3280 DBG_871X("%s ret: %d\n", __func__, ret); 3281 goto exit; 3282 } 3283 exit: 3284 return ret; 3285 } 3286 3287 static int cfg80211_rtw_sched_scan_stop(struct wiphy *wiphy, 3288 struct net_device *dev) { 3289 return rtw_android_pno_enable(dev, false); 3290 } 3291 #endif /* CONFIG_PNO_SUPPORT */ 3292 3293 static void rtw_cfg80211_init_ht_capab(struct ieee80211_sta_ht_cap *ht_cap, enum nl80211_band band, u8 rf_type) 3294 { 3295 3296 #define MAX_BIT_RATE_40MHZ_MCS15 300 /* Mbps */ 3297 #define MAX_BIT_RATE_40MHZ_MCS7 150 /* Mbps */ 3298 3299 ht_cap->ht_supported = true; 3300 3301 ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 | 3302 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20 | 3303 IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU; 3304 3305 /* 3306 *Maximum length of AMPDU that the STA can receive. 3307 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets) 3308 */ 3309 ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; 3310 3311 /*Minimum MPDU start spacing , */ 3312 ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16; 3313 3314 ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; 3315 3316 /* 3317 *hw->wiphy->bands[NL80211_BAND_2GHZ] 3318 *base on ant_num 3319 *rx_mask: RX mask 3320 *if rx_ant = 1 rx_mask[0]= 0xff;==>MCS0-MCS7 3321 *if rx_ant =2 rx_mask[1]= 0xff;==>MCS8-MCS15 3322 *if rx_ant >=3 rx_mask[2]= 0xff; 3323 *if BW_40 rx_mask[4]= 0x01; 3324 *highest supported RX rate 3325 */ 3326 if (rf_type == RF_1T1R) 3327 { 3328 ht_cap->mcs.rx_mask[0] = 0xFF; 3329 ht_cap->mcs.rx_mask[1] = 0x00; 3330 ht_cap->mcs.rx_mask[4] = 0x01; 3331 3332 ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7); 3333 } 3334 else if ((rf_type == RF_1T2R) || (rf_type ==RF_2T2R)) 3335 { 3336 ht_cap->mcs.rx_mask[0] = 0xFF; 3337 ht_cap->mcs.rx_mask[1] = 0xFF; 3338 ht_cap->mcs.rx_mask[4] = 0x01; 3339 3340 ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15); 3341 } 3342 else 3343 { 3344 DBG_8192C("%s, error rf_type =%d\n", __func__, rf_type); 3345 } 3346 3347 } 3348 3349 void rtw_cfg80211_init_wiphy(struct adapter *padapter) 3350 { 3351 u8 rf_type; 3352 struct ieee80211_supported_band *bands; 3353 struct wireless_dev *pwdev = padapter->rtw_wdev; 3354 struct wiphy *wiphy = pwdev->wiphy; 3355 3356 rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type)); 3357 3358 DBG_8192C("%s:rf_type =%d\n", __func__, rf_type); 3359 3360 { 3361 bands = wiphy->bands[NL80211_BAND_2GHZ]; 3362 if (bands) 3363 rtw_cfg80211_init_ht_capab(&bands->ht_cap, NL80211_BAND_2GHZ, rf_type); 3364 } 3365 3366 /* init regulary domain */ 3367 rtw_regd_init(padapter, rtw_reg_notifier); 3368 3369 /* copy mac_addr to wiphy */ 3370 memcpy(wiphy->perm_addr, padapter->eeprompriv.mac_addr, ETH_ALEN); 3371 3372 } 3373 3374 static void rtw_cfg80211_preinit_wiphy(struct adapter *padapter, struct wiphy *wiphy) 3375 { 3376 3377 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; 3378 3379 wiphy->max_scan_ssids = RTW_SSID_SCAN_AMOUNT; 3380 wiphy->max_scan_ie_len = RTW_SCAN_IE_LEN_MAX; 3381 wiphy->max_num_pmkids = RTW_MAX_NUM_PMKIDS; 3382 3383 wiphy->max_remain_on_channel_duration = RTW_MAX_REMAIN_ON_CHANNEL_DURATION; 3384 3385 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) 3386 | BIT(NL80211_IFTYPE_ADHOC) 3387 | BIT(NL80211_IFTYPE_AP) 3388 | BIT(NL80211_IFTYPE_MONITOR) 3389 ; 3390 3391 wiphy->mgmt_stypes = rtw_cfg80211_default_mgmt_stypes; 3392 3393 wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR); 3394 3395 wiphy->cipher_suites = rtw_cipher_suites; 3396 wiphy->n_cipher_suites = ARRAY_SIZE(rtw_cipher_suites); 3397 3398 /* if (padapter->registrypriv.wireless_mode & WIRELESS_11G) */ 3399 wiphy->bands[NL80211_BAND_2GHZ] = rtw_spt_band_alloc(NL80211_BAND_2GHZ); 3400 3401 wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; 3402 wiphy->flags |= WIPHY_FLAG_OFFCHAN_TX | WIPHY_FLAG_HAVE_AP_SME; 3403 3404 #if defined(CONFIG_PM) 3405 wiphy->max_sched_scan_reqs = 1; 3406 #ifdef CONFIG_PNO_SUPPORT 3407 wiphy->max_sched_scan_ssids = MAX_PNO_LIST_COUNT; 3408 #endif 3409 #endif 3410 3411 #if defined(CONFIG_PM) 3412 wiphy->wowlan = &wowlan_stub; 3413 #endif 3414 3415 if (padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE) 3416 wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; 3417 else 3418 wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; 3419 } 3420 3421 static struct cfg80211_ops rtw_cfg80211_ops = { 3422 .change_virtual_intf = cfg80211_rtw_change_iface, 3423 .add_key = cfg80211_rtw_add_key, 3424 .get_key = cfg80211_rtw_get_key, 3425 .del_key = cfg80211_rtw_del_key, 3426 .set_default_key = cfg80211_rtw_set_default_key, 3427 .get_station = cfg80211_rtw_get_station, 3428 .scan = cfg80211_rtw_scan, 3429 .set_wiphy_params = cfg80211_rtw_set_wiphy_params, 3430 .connect = cfg80211_rtw_connect, 3431 .disconnect = cfg80211_rtw_disconnect, 3432 .join_ibss = cfg80211_rtw_join_ibss, 3433 .leave_ibss = cfg80211_rtw_leave_ibss, 3434 .set_tx_power = cfg80211_rtw_set_txpower, 3435 .get_tx_power = cfg80211_rtw_get_txpower, 3436 .set_power_mgmt = cfg80211_rtw_set_power_mgmt, 3437 .set_pmksa = cfg80211_rtw_set_pmksa, 3438 .del_pmksa = cfg80211_rtw_del_pmksa, 3439 .flush_pmksa = cfg80211_rtw_flush_pmksa, 3440 3441 .add_virtual_intf = cfg80211_rtw_add_virtual_intf, 3442 .del_virtual_intf = cfg80211_rtw_del_virtual_intf, 3443 3444 .start_ap = cfg80211_rtw_start_ap, 3445 .change_beacon = cfg80211_rtw_change_beacon, 3446 .stop_ap = cfg80211_rtw_stop_ap, 3447 3448 .add_station = cfg80211_rtw_add_station, 3449 .del_station = cfg80211_rtw_del_station, 3450 .change_station = cfg80211_rtw_change_station, 3451 .dump_station = cfg80211_rtw_dump_station, 3452 .change_bss = cfg80211_rtw_change_bss, 3453 3454 .mgmt_tx = cfg80211_rtw_mgmt_tx, 3455 .mgmt_frame_register = cfg80211_rtw_mgmt_frame_register, 3456 3457 #if defined(CONFIG_PNO_SUPPORT) 3458 .sched_scan_start = cfg80211_rtw_sched_scan_start, 3459 .sched_scan_stop = cfg80211_rtw_sched_scan_stop, 3460 #endif /* CONFIG_PNO_SUPPORT */ 3461 }; 3462 3463 int rtw_wdev_alloc(struct adapter *padapter, struct device *dev) 3464 { 3465 int ret = 0; 3466 struct wiphy *wiphy; 3467 struct wireless_dev *wdev; 3468 struct rtw_wdev_priv *pwdev_priv; 3469 struct net_device *pnetdev = padapter->pnetdev; 3470 3471 DBG_8192C("%s(padapter =%p)\n", __func__, padapter); 3472 3473 /* wiphy */ 3474 wiphy = wiphy_new(&rtw_cfg80211_ops, sizeof(struct adapter *)); 3475 if (!wiphy) { 3476 DBG_8192C("Couldn't allocate wiphy device\n"); 3477 ret = -ENOMEM; 3478 goto exit; 3479 } 3480 set_wiphy_dev(wiphy, dev); 3481 *((struct adapter **)wiphy_priv(wiphy)) = padapter; 3482 rtw_cfg80211_preinit_wiphy(padapter, wiphy); 3483 3484 ret = wiphy_register(wiphy); 3485 if (ret < 0) { 3486 DBG_8192C("Couldn't register wiphy device\n"); 3487 goto free_wiphy; 3488 } 3489 3490 /* wdev */ 3491 wdev = rtw_zmalloc(sizeof(struct wireless_dev)); 3492 if (!wdev) { 3493 DBG_8192C("Couldn't allocate wireless device\n"); 3494 ret = -ENOMEM; 3495 goto unregister_wiphy; 3496 } 3497 wdev->wiphy = wiphy; 3498 wdev->netdev = pnetdev; 3499 3500 wdev->iftype = NL80211_IFTYPE_STATION; /* will be init in rtw_hal_init() */ 3501 /* Must sync with _rtw_init_mlme_priv() */ 3502 /* pmlmepriv->fw_state = WIFI_STATION_STATE */ 3503 padapter->rtw_wdev = wdev; 3504 pnetdev->ieee80211_ptr = wdev; 3505 3506 /* init pwdev_priv */ 3507 pwdev_priv = adapter_wdev_data(padapter); 3508 pwdev_priv->rtw_wdev = wdev; 3509 pwdev_priv->pmon_ndev = NULL; 3510 pwdev_priv->ifname_mon[0] = '\0'; 3511 pwdev_priv->padapter = padapter; 3512 pwdev_priv->scan_request = NULL; 3513 spin_lock_init(&pwdev_priv->scan_req_lock); 3514 3515 pwdev_priv->p2p_enabled = false; 3516 pwdev_priv->provdisc_req_issued = false; 3517 rtw_wdev_invit_info_init(&pwdev_priv->invit_info); 3518 rtw_wdev_nego_info_init(&pwdev_priv->nego_info); 3519 3520 pwdev_priv->bandroid_scan = false; 3521 3522 if (padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE) 3523 pwdev_priv->power_mgmt = true; 3524 else 3525 pwdev_priv->power_mgmt = false; 3526 3527 return ret; 3528 3529 unregister_wiphy: 3530 wiphy_unregister(wiphy); 3531 free_wiphy: 3532 wiphy_free(wiphy); 3533 exit: 3534 return ret; 3535 3536 } 3537 3538 void rtw_wdev_free(struct wireless_dev *wdev) 3539 { 3540 DBG_8192C("%s(wdev =%p)\n", __func__, wdev); 3541 3542 if (!wdev) 3543 return; 3544 3545 rtw_spt_band_free(wdev->wiphy->bands[NL80211_BAND_2GHZ]); 3546 3547 wiphy_free(wdev->wiphy); 3548 3549 kfree((u8 *)wdev); 3550 } 3551 3552 void rtw_wdev_unregister(struct wireless_dev *wdev) 3553 { 3554 struct net_device *ndev; 3555 struct adapter *adapter; 3556 struct rtw_wdev_priv *pwdev_priv; 3557 3558 DBG_8192C("%s(wdev =%p)\n", __func__, wdev); 3559 3560 if (!wdev) 3561 return; 3562 3563 if (!(ndev = wdev_to_ndev(wdev))) 3564 return; 3565 3566 adapter = (struct adapter *)rtw_netdev_priv(ndev); 3567 pwdev_priv = adapter_wdev_data(adapter); 3568 3569 rtw_cfg80211_indicate_scan_done(adapter, true); 3570 3571 if (pwdev_priv->pmon_ndev) { 3572 DBG_8192C("%s, unregister monitor interface\n", __func__); 3573 unregister_netdev(pwdev_priv->pmon_ndev); 3574 } 3575 3576 wiphy_unregister(wdev->wiphy); 3577 } 3578