cfg80211.c revision 3450334f392bca1fccbf04a90020161ec4404a1e
1/* 2 * Copyright (c) 2004-2011 Atheros Communications Inc. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17#include "core.h" 18#include "cfg80211.h" 19#include "debug.h" 20#include "hif-ops.h" 21#include "testmode.h" 22 23static unsigned int ath6kl_p2p; 24 25module_param(ath6kl_p2p, uint, 0644); 26 27#define RATETAB_ENT(_rate, _rateid, _flags) { \ 28 .bitrate = (_rate), \ 29 .flags = (_flags), \ 30 .hw_value = (_rateid), \ 31} 32 33#define CHAN2G(_channel, _freq, _flags) { \ 34 .band = IEEE80211_BAND_2GHZ, \ 35 .hw_value = (_channel), \ 36 .center_freq = (_freq), \ 37 .flags = (_flags), \ 38 .max_antenna_gain = 0, \ 39 .max_power = 30, \ 40} 41 42#define CHAN5G(_channel, _flags) { \ 43 .band = IEEE80211_BAND_5GHZ, \ 44 .hw_value = (_channel), \ 45 .center_freq = 5000 + (5 * (_channel)), \ 46 .flags = (_flags), \ 47 .max_antenna_gain = 0, \ 48 .max_power = 30, \ 49} 50 51static struct ieee80211_rate ath6kl_rates[] = { 52 RATETAB_ENT(10, 0x1, 0), 53 RATETAB_ENT(20, 0x2, 0), 54 RATETAB_ENT(55, 0x4, 0), 55 RATETAB_ENT(110, 0x8, 0), 56 RATETAB_ENT(60, 0x10, 0), 57 RATETAB_ENT(90, 0x20, 0), 58 RATETAB_ENT(120, 0x40, 0), 59 RATETAB_ENT(180, 0x80, 0), 60 RATETAB_ENT(240, 0x100, 0), 61 RATETAB_ENT(360, 0x200, 0), 62 RATETAB_ENT(480, 0x400, 0), 63 RATETAB_ENT(540, 0x800, 0), 64}; 65 66#define ath6kl_a_rates (ath6kl_rates + 4) 67#define ath6kl_a_rates_size 8 68#define ath6kl_g_rates (ath6kl_rates + 0) 69#define ath6kl_g_rates_size 12 70 71static struct ieee80211_channel ath6kl_2ghz_channels[] = { 72 CHAN2G(1, 2412, 0), 73 CHAN2G(2, 2417, 0), 74 CHAN2G(3, 2422, 0), 75 CHAN2G(4, 2427, 0), 76 CHAN2G(5, 2432, 0), 77 CHAN2G(6, 2437, 0), 78 CHAN2G(7, 2442, 0), 79 CHAN2G(8, 2447, 0), 80 CHAN2G(9, 2452, 0), 81 CHAN2G(10, 2457, 0), 82 CHAN2G(11, 2462, 0), 83 CHAN2G(12, 2467, 0), 84 CHAN2G(13, 2472, 0), 85 CHAN2G(14, 2484, 0), 86}; 87 88static struct ieee80211_channel ath6kl_5ghz_a_channels[] = { 89 CHAN5G(34, 0), CHAN5G(36, 0), 90 CHAN5G(38, 0), CHAN5G(40, 0), 91 CHAN5G(42, 0), CHAN5G(44, 0), 92 CHAN5G(46, 0), CHAN5G(48, 0), 93 CHAN5G(52, 0), CHAN5G(56, 0), 94 CHAN5G(60, 0), CHAN5G(64, 0), 95 CHAN5G(100, 0), CHAN5G(104, 0), 96 CHAN5G(108, 0), CHAN5G(112, 0), 97 CHAN5G(116, 0), CHAN5G(120, 0), 98 CHAN5G(124, 0), CHAN5G(128, 0), 99 CHAN5G(132, 0), CHAN5G(136, 0), 100 CHAN5G(140, 0), CHAN5G(149, 0), 101 CHAN5G(153, 0), CHAN5G(157, 0), 102 CHAN5G(161, 0), CHAN5G(165, 0), 103 CHAN5G(184, 0), CHAN5G(188, 0), 104 CHAN5G(192, 0), CHAN5G(196, 0), 105 CHAN5G(200, 0), CHAN5G(204, 0), 106 CHAN5G(208, 0), CHAN5G(212, 0), 107 CHAN5G(216, 0), 108}; 109 110static struct ieee80211_supported_band ath6kl_band_2ghz = { 111 .n_channels = ARRAY_SIZE(ath6kl_2ghz_channels), 112 .channels = ath6kl_2ghz_channels, 113 .n_bitrates = ath6kl_g_rates_size, 114 .bitrates = ath6kl_g_rates, 115}; 116 117static struct ieee80211_supported_band ath6kl_band_5ghz = { 118 .n_channels = ARRAY_SIZE(ath6kl_5ghz_a_channels), 119 .channels = ath6kl_5ghz_a_channels, 120 .n_bitrates = ath6kl_a_rates_size, 121 .bitrates = ath6kl_a_rates, 122}; 123 124#define CCKM_KRK_CIPHER_SUITE 0x004096ff /* use for KRK */ 125 126static int ath6kl_set_wpa_version(struct ath6kl *ar, 127 enum nl80211_wpa_versions wpa_version) 128{ 129 /* TODO: Findout vif */ 130 struct ath6kl_vif *vif = ar->vif; 131 132 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: %u\n", __func__, wpa_version); 133 134 if (!wpa_version) { 135 vif->auth_mode = NONE_AUTH; 136 } else if (wpa_version & NL80211_WPA_VERSION_2) { 137 vif->auth_mode = WPA2_AUTH; 138 } else if (wpa_version & NL80211_WPA_VERSION_1) { 139 vif->auth_mode = WPA_AUTH; 140 } else { 141 ath6kl_err("%s: %u not supported\n", __func__, wpa_version); 142 return -ENOTSUPP; 143 } 144 145 return 0; 146} 147 148static int ath6kl_set_auth_type(struct ath6kl *ar, 149 enum nl80211_auth_type auth_type) 150{ 151 /* TODO: Findout vif */ 152 struct ath6kl_vif *vif = ar->vif; 153 154 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, auth_type); 155 156 switch (auth_type) { 157 case NL80211_AUTHTYPE_OPEN_SYSTEM: 158 vif->dot11_auth_mode = OPEN_AUTH; 159 break; 160 case NL80211_AUTHTYPE_SHARED_KEY: 161 vif->dot11_auth_mode = SHARED_AUTH; 162 break; 163 case NL80211_AUTHTYPE_NETWORK_EAP: 164 vif->dot11_auth_mode = LEAP_AUTH; 165 break; 166 167 case NL80211_AUTHTYPE_AUTOMATIC: 168 vif->dot11_auth_mode = OPEN_AUTH | SHARED_AUTH; 169 break; 170 171 default: 172 ath6kl_err("%s: 0x%x not spported\n", __func__, auth_type); 173 return -ENOTSUPP; 174 } 175 176 return 0; 177} 178 179static int ath6kl_set_cipher(struct ath6kl *ar, u32 cipher, bool ucast) 180{ 181 /* TODO: Findout vif */ 182 struct ath6kl_vif *vif = ar->vif; 183 184 u8 *ar_cipher = ucast ? &vif->prwise_crypto : &vif->grp_crypto; 185 u8 *ar_cipher_len = ucast ? &vif->prwise_crypto_len : 186 &vif->grp_crypto_len; 187 188 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: cipher 0x%x, ucast %u\n", 189 __func__, cipher, ucast); 190 191 switch (cipher) { 192 case 0: 193 /* our own hack to use value 0 as no crypto used */ 194 *ar_cipher = NONE_CRYPT; 195 *ar_cipher_len = 0; 196 break; 197 case WLAN_CIPHER_SUITE_WEP40: 198 *ar_cipher = WEP_CRYPT; 199 *ar_cipher_len = 5; 200 break; 201 case WLAN_CIPHER_SUITE_WEP104: 202 *ar_cipher = WEP_CRYPT; 203 *ar_cipher_len = 13; 204 break; 205 case WLAN_CIPHER_SUITE_TKIP: 206 *ar_cipher = TKIP_CRYPT; 207 *ar_cipher_len = 0; 208 break; 209 case WLAN_CIPHER_SUITE_CCMP: 210 *ar_cipher = AES_CRYPT; 211 *ar_cipher_len = 0; 212 break; 213 default: 214 ath6kl_err("cipher 0x%x not supported\n", cipher); 215 return -ENOTSUPP; 216 } 217 218 return 0; 219} 220 221static void ath6kl_set_key_mgmt(struct ath6kl *ar, u32 key_mgmt) 222{ 223 /* TODO: Findout vif */ 224 struct ath6kl_vif *vif = ar->vif; 225 226 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: 0x%x\n", __func__, key_mgmt); 227 228 if (key_mgmt == WLAN_AKM_SUITE_PSK) { 229 if (vif->auth_mode == WPA_AUTH) 230 vif->auth_mode = WPA_PSK_AUTH; 231 else if (vif->auth_mode == WPA2_AUTH) 232 vif->auth_mode = WPA2_PSK_AUTH; 233 } else if (key_mgmt == 0x00409600) { 234 if (vif->auth_mode == WPA_AUTH) 235 vif->auth_mode = WPA_AUTH_CCKM; 236 else if (vif->auth_mode == WPA2_AUTH) 237 vif->auth_mode = WPA2_AUTH_CCKM; 238 } else if (key_mgmt != WLAN_AKM_SUITE_8021X) { 239 vif->auth_mode = NONE_AUTH; 240 } 241} 242 243static bool ath6kl_cfg80211_ready(struct ath6kl *ar) 244{ 245 struct ath6kl_vif *vif = ar->vif; 246 247 if (!test_bit(WMI_READY, &ar->flag)) { 248 ath6kl_err("wmi is not ready\n"); 249 return false; 250 } 251 252 if (!test_bit(WLAN_ENABLED, &vif->flags)) { 253 ath6kl_err("wlan disabled\n"); 254 return false; 255 } 256 257 return true; 258} 259 260static bool ath6kl_is_wpa_ie(const u8 *pos) 261{ 262 return pos[0] == WLAN_EID_WPA && pos[1] >= 4 && 263 pos[2] == 0x00 && pos[3] == 0x50 && 264 pos[4] == 0xf2 && pos[5] == 0x01; 265} 266 267static bool ath6kl_is_rsn_ie(const u8 *pos) 268{ 269 return pos[0] == WLAN_EID_RSN; 270} 271 272static int ath6kl_set_assoc_req_ies(struct ath6kl *ar, const u8 *ies, 273 size_t ies_len) 274{ 275 const u8 *pos; 276 u8 *buf = NULL; 277 size_t len = 0; 278 int ret; 279 280 /* 281 * Filter out RSN/WPA IE(s) 282 */ 283 284 if (ies && ies_len) { 285 buf = kmalloc(ies_len, GFP_KERNEL); 286 if (buf == NULL) 287 return -ENOMEM; 288 pos = ies; 289 290 while (pos + 1 < ies + ies_len) { 291 if (pos + 2 + pos[1] > ies + ies_len) 292 break; 293 if (!(ath6kl_is_wpa_ie(pos) || ath6kl_is_rsn_ie(pos))) { 294 memcpy(buf + len, pos, 2 + pos[1]); 295 len += 2 + pos[1]; 296 } 297 pos += 2 + pos[1]; 298 } 299 } 300 301 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_ASSOC_REQ, 302 buf, len); 303 kfree(buf); 304 return ret; 305} 306 307static int ath6kl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev, 308 struct cfg80211_connect_params *sme) 309{ 310 struct ath6kl *ar = ath6kl_priv(dev); 311 struct ath6kl_vif *vif = netdev_priv(dev); 312 int status; 313 314 ar->sme_state = SME_CONNECTING; 315 316 if (!ath6kl_cfg80211_ready(ar)) 317 return -EIO; 318 319 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) { 320 ath6kl_err("destroy in progress\n"); 321 return -EBUSY; 322 } 323 324 if (test_bit(SKIP_SCAN, &ar->flag) && 325 ((sme->channel && sme->channel->center_freq == 0) || 326 (sme->bssid && is_zero_ether_addr(sme->bssid)))) { 327 ath6kl_err("SkipScan: channel or bssid invalid\n"); 328 return -EINVAL; 329 } 330 331 if (down_interruptible(&ar->sem)) { 332 ath6kl_err("busy, couldn't get access\n"); 333 return -ERESTARTSYS; 334 } 335 336 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) { 337 ath6kl_err("busy, destroy in progress\n"); 338 up(&ar->sem); 339 return -EBUSY; 340 } 341 342 if (ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)]) { 343 /* 344 * sleep until the command queue drains 345 */ 346 wait_event_interruptible_timeout(ar->event_wq, 347 ar->tx_pending[ath6kl_wmi_get_control_ep(ar->wmi)] == 0, 348 WMI_TIMEOUT); 349 if (signal_pending(current)) { 350 ath6kl_err("cmd queue drain timeout\n"); 351 up(&ar->sem); 352 return -EINTR; 353 } 354 } 355 356 if (sme->ie && (sme->ie_len > 0)) { 357 status = ath6kl_set_assoc_req_ies(ar, sme->ie, sme->ie_len); 358 if (status) 359 return status; 360 } 361 362 if (test_bit(CONNECTED, &vif->flags) && 363 vif->ssid_len == sme->ssid_len && 364 !memcmp(vif->ssid, sme->ssid, vif->ssid_len)) { 365 ar->reconnect_flag = true; 366 status = ath6kl_wmi_reconnect_cmd(ar->wmi, ar->req_bssid, 367 ar->ch_hint); 368 369 up(&ar->sem); 370 if (status) { 371 ath6kl_err("wmi_reconnect_cmd failed\n"); 372 return -EIO; 373 } 374 return 0; 375 } else if (vif->ssid_len == sme->ssid_len && 376 !memcmp(vif->ssid, sme->ssid, vif->ssid_len)) { 377 ath6kl_disconnect(ar); 378 } 379 380 memset(vif->ssid, 0, sizeof(vif->ssid)); 381 vif->ssid_len = sme->ssid_len; 382 memcpy(vif->ssid, sme->ssid, sme->ssid_len); 383 384 if (sme->channel) 385 ar->ch_hint = sme->channel->center_freq; 386 387 memset(ar->req_bssid, 0, sizeof(ar->req_bssid)); 388 if (sme->bssid && !is_broadcast_ether_addr(sme->bssid)) 389 memcpy(ar->req_bssid, sme->bssid, sizeof(ar->req_bssid)); 390 391 ath6kl_set_wpa_version(ar, sme->crypto.wpa_versions); 392 393 status = ath6kl_set_auth_type(ar, sme->auth_type); 394 if (status) { 395 up(&ar->sem); 396 return status; 397 } 398 399 if (sme->crypto.n_ciphers_pairwise) 400 ath6kl_set_cipher(ar, sme->crypto.ciphers_pairwise[0], true); 401 else 402 ath6kl_set_cipher(ar, 0, true); 403 404 ath6kl_set_cipher(ar, sme->crypto.cipher_group, false); 405 406 if (sme->crypto.n_akm_suites) 407 ath6kl_set_key_mgmt(ar, sme->crypto.akm_suites[0]); 408 409 if ((sme->key_len) && 410 (vif->auth_mode == NONE_AUTH) && 411 (vif->prwise_crypto == WEP_CRYPT)) { 412 struct ath6kl_key *key = NULL; 413 414 if (sme->key_idx < WMI_MIN_KEY_INDEX || 415 sme->key_idx > WMI_MAX_KEY_INDEX) { 416 ath6kl_err("key index %d out of bounds\n", 417 sme->key_idx); 418 up(&ar->sem); 419 return -ENOENT; 420 } 421 422 key = &ar->keys[sme->key_idx]; 423 key->key_len = sme->key_len; 424 memcpy(key->key, sme->key, key->key_len); 425 key->cipher = vif->prwise_crypto; 426 vif->def_txkey_index = sme->key_idx; 427 428 ath6kl_wmi_addkey_cmd(ar->wmi, sme->key_idx, 429 vif->prwise_crypto, 430 GROUP_USAGE | TX_USAGE, 431 key->key_len, 432 NULL, 433 key->key, KEY_OP_INIT_VAL, NULL, 434 NO_SYNC_WMIFLAG); 435 } 436 437 if (!ar->usr_bss_filter) { 438 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags); 439 if (ath6kl_wmi_bssfilter_cmd(ar->wmi, ALL_BSS_FILTER, 0) != 0) { 440 ath6kl_err("couldn't set bss filtering\n"); 441 up(&ar->sem); 442 return -EIO; 443 } 444 } 445 446 ar->nw_type = ar->next_mode; 447 448 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, 449 "%s: connect called with authmode %d dot11 auth %d" 450 " PW crypto %d PW crypto len %d GRP crypto %d" 451 " GRP crypto len %d channel hint %u\n", 452 __func__, 453 vif->auth_mode, vif->dot11_auth_mode, vif->prwise_crypto, 454 vif->prwise_crypto_len, vif->grp_crypto, 455 vif->grp_crypto_len, ar->ch_hint); 456 457 ar->reconnect_flag = 0; 458 status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type, 459 vif->dot11_auth_mode, vif->auth_mode, 460 vif->prwise_crypto, 461 vif->prwise_crypto_len, 462 vif->grp_crypto, vif->grp_crypto_len, 463 vif->ssid_len, vif->ssid, 464 ar->req_bssid, ar->ch_hint, 465 ar->connect_ctrl_flags); 466 467 up(&ar->sem); 468 469 if (status == -EINVAL) { 470 memset(vif->ssid, 0, sizeof(vif->ssid)); 471 vif->ssid_len = 0; 472 ath6kl_err("invalid request\n"); 473 return -ENOENT; 474 } else if (status) { 475 ath6kl_err("ath6kl_wmi_connect_cmd failed\n"); 476 return -EIO; 477 } 478 479 if ((!(ar->connect_ctrl_flags & CONNECT_DO_WPA_OFFLOAD)) && 480 ((vif->auth_mode == WPA_PSK_AUTH) 481 || (vif->auth_mode == WPA2_PSK_AUTH))) { 482 mod_timer(&ar->disconnect_timer, 483 jiffies + msecs_to_jiffies(DISCON_TIMER_INTVAL)); 484 } 485 486 ar->connect_ctrl_flags &= ~CONNECT_DO_WPA_OFFLOAD; 487 set_bit(CONNECT_PEND, &vif->flags); 488 489 return 0; 490} 491 492static int ath6kl_add_bss_if_needed(struct ath6kl *ar, const u8 *bssid, 493 struct ieee80211_channel *chan, 494 const u8 *beacon_ie, size_t beacon_ie_len) 495{ 496 /* TODO: Findout vif */ 497 struct ath6kl_vif *vif = ar->vif; 498 struct cfg80211_bss *bss; 499 u8 *ie; 500 501 bss = cfg80211_get_bss(ar->wiphy, chan, bssid, 502 vif->ssid, vif->ssid_len, WLAN_CAPABILITY_ESS, 503 WLAN_CAPABILITY_ESS); 504 if (bss == NULL) { 505 /* 506 * Since cfg80211 may not yet know about the BSS, 507 * generate a partial entry until the first BSS info 508 * event becomes available. 509 * 510 * Prepend SSID element since it is not included in the Beacon 511 * IEs from the target. 512 */ 513 ie = kmalloc(2 + vif->ssid_len + beacon_ie_len, GFP_KERNEL); 514 if (ie == NULL) 515 return -ENOMEM; 516 ie[0] = WLAN_EID_SSID; 517 ie[1] = vif->ssid_len; 518 memcpy(ie + 2, vif->ssid, vif->ssid_len); 519 memcpy(ie + 2 + vif->ssid_len, beacon_ie, beacon_ie_len); 520 bss = cfg80211_inform_bss(ar->wiphy, chan, 521 bssid, 0, WLAN_CAPABILITY_ESS, 100, 522 ie, 2 + vif->ssid_len + beacon_ie_len, 523 0, GFP_KERNEL); 524 if (bss) 525 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "added dummy bss for " 526 "%pM prior to indicating connect/roamed " 527 "event\n", bssid); 528 kfree(ie); 529 } else 530 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "cfg80211 already has a bss " 531 "entry\n"); 532 533 if (bss == NULL) 534 return -ENOMEM; 535 536 cfg80211_put_bss(bss); 537 538 return 0; 539} 540 541void ath6kl_cfg80211_connect_event(struct ath6kl *ar, u16 channel, 542 u8 *bssid, u16 listen_intvl, 543 u16 beacon_intvl, 544 enum network_type nw_type, 545 u8 beacon_ie_len, u8 assoc_req_len, 546 u8 assoc_resp_len, u8 *assoc_info) 547{ 548 struct ieee80211_channel *chan; 549 /* TODO: Findout vif */ 550 struct ath6kl_vif *vif = ar->vif; 551 552 /* capinfo + listen interval */ 553 u8 assoc_req_ie_offset = sizeof(u16) + sizeof(u16); 554 555 /* capinfo + status code + associd */ 556 u8 assoc_resp_ie_offset = sizeof(u16) + sizeof(u16) + sizeof(u16); 557 558 u8 *assoc_req_ie = assoc_info + beacon_ie_len + assoc_req_ie_offset; 559 u8 *assoc_resp_ie = assoc_info + beacon_ie_len + assoc_req_len + 560 assoc_resp_ie_offset; 561 562 assoc_req_len -= assoc_req_ie_offset; 563 assoc_resp_len -= assoc_resp_ie_offset; 564 565 /* 566 * Store Beacon interval here; DTIM period will be available only once 567 * a Beacon frame from the AP is seen. 568 */ 569 ar->assoc_bss_beacon_int = beacon_intvl; 570 clear_bit(DTIM_PERIOD_AVAIL, &vif->flags); 571 572 if (nw_type & ADHOC_NETWORK) { 573 if (ar->wdev->iftype != NL80211_IFTYPE_ADHOC) { 574 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, 575 "%s: ath6k not in ibss mode\n", __func__); 576 return; 577 } 578 } 579 580 if (nw_type & INFRA_NETWORK) { 581 if (ar->wdev->iftype != NL80211_IFTYPE_STATION && 582 ar->wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) { 583 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, 584 "%s: ath6k not in station mode\n", __func__); 585 return; 586 } 587 } 588 589 chan = ieee80211_get_channel(ar->wiphy, (int) channel); 590 591 592 if (nw_type & ADHOC_NETWORK) { 593 cfg80211_ibss_joined(ar->net_dev, bssid, GFP_KERNEL); 594 return; 595 } 596 597 if (ath6kl_add_bss_if_needed(ar, bssid, chan, assoc_info, 598 beacon_ie_len) < 0) { 599 ath6kl_err("could not add cfg80211 bss entry for " 600 "connect/roamed notification\n"); 601 return; 602 } 603 604 if (ar->sme_state == SME_CONNECTING) { 605 /* inform connect result to cfg80211 */ 606 ar->sme_state = SME_CONNECTED; 607 cfg80211_connect_result(ar->net_dev, bssid, 608 assoc_req_ie, assoc_req_len, 609 assoc_resp_ie, assoc_resp_len, 610 WLAN_STATUS_SUCCESS, GFP_KERNEL); 611 } else if (ar->sme_state == SME_CONNECTED) { 612 /* inform roam event to cfg80211 */ 613 cfg80211_roamed(ar->net_dev, chan, bssid, 614 assoc_req_ie, assoc_req_len, 615 assoc_resp_ie, assoc_resp_len, GFP_KERNEL); 616 } 617} 618 619static int ath6kl_cfg80211_disconnect(struct wiphy *wiphy, 620 struct net_device *dev, u16 reason_code) 621{ 622 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev); 623 struct ath6kl_vif *vif = netdev_priv(dev); 624 625 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: reason=%u\n", __func__, 626 reason_code); 627 628 if (!ath6kl_cfg80211_ready(ar)) 629 return -EIO; 630 631 if (test_bit(DESTROY_IN_PROGRESS, &ar->flag)) { 632 ath6kl_err("busy, destroy in progress\n"); 633 return -EBUSY; 634 } 635 636 if (down_interruptible(&ar->sem)) { 637 ath6kl_err("busy, couldn't get access\n"); 638 return -ERESTARTSYS; 639 } 640 641 ar->reconnect_flag = 0; 642 ath6kl_disconnect(ar); 643 memset(vif->ssid, 0, sizeof(vif->ssid)); 644 vif->ssid_len = 0; 645 646 if (!test_bit(SKIP_SCAN, &ar->flag)) 647 memset(ar->req_bssid, 0, sizeof(ar->req_bssid)); 648 649 up(&ar->sem); 650 651 ar->sme_state = SME_DISCONNECTED; 652 653 return 0; 654} 655 656void ath6kl_cfg80211_disconnect_event(struct ath6kl *ar, u8 reason, 657 u8 *bssid, u8 assoc_resp_len, 658 u8 *assoc_info, u16 proto_reason) 659{ 660 /* TODO: Findout vif */ 661 struct ath6kl_vif *vif = ar->vif; 662 663 if (ar->scan_req) { 664 cfg80211_scan_done(ar->scan_req, true); 665 ar->scan_req = NULL; 666 } 667 668 if (ar->nw_type & ADHOC_NETWORK) { 669 if (ar->wdev->iftype != NL80211_IFTYPE_ADHOC) { 670 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, 671 "%s: ath6k not in ibss mode\n", __func__); 672 return; 673 } 674 memset(bssid, 0, ETH_ALEN); 675 cfg80211_ibss_joined(ar->net_dev, bssid, GFP_KERNEL); 676 return; 677 } 678 679 if (ar->nw_type & INFRA_NETWORK) { 680 if (ar->wdev->iftype != NL80211_IFTYPE_STATION && 681 ar->wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) { 682 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, 683 "%s: ath6k not in station mode\n", __func__); 684 return; 685 } 686 } 687 688 /* 689 * Send a disconnect command to target when a disconnect event is 690 * received with reason code other than 3 (DISCONNECT_CMD - disconnect 691 * request from host) to make the firmware stop trying to connect even 692 * after giving disconnect event. There will be one more disconnect 693 * event for this disconnect command with reason code DISCONNECT_CMD 694 * which will be notified to cfg80211. 695 */ 696 697 if (reason != DISCONNECT_CMD) { 698 ath6kl_wmi_disconnect_cmd(ar->wmi); 699 return; 700 } 701 702 clear_bit(CONNECT_PEND, &vif->flags); 703 704 if (ar->sme_state == SME_CONNECTING) { 705 cfg80211_connect_result(ar->net_dev, 706 bssid, NULL, 0, 707 NULL, 0, 708 WLAN_STATUS_UNSPECIFIED_FAILURE, 709 GFP_KERNEL); 710 } else if (ar->sme_state == SME_CONNECTED) { 711 cfg80211_disconnected(ar->net_dev, reason, 712 NULL, 0, GFP_KERNEL); 713 } 714 715 ar->sme_state = SME_DISCONNECTED; 716} 717 718static int ath6kl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev, 719 struct cfg80211_scan_request *request) 720{ 721 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev); 722 struct ath6kl_vif *vif = netdev_priv(ndev); 723 s8 n_channels = 0; 724 u16 *channels = NULL; 725 int ret = 0; 726 u32 force_fg_scan = 0; 727 728 if (!ath6kl_cfg80211_ready(ar)) 729 return -EIO; 730 731 if (!ar->usr_bss_filter) { 732 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags); 733 ret = ath6kl_wmi_bssfilter_cmd( 734 ar->wmi, 735 (test_bit(CONNECTED, &vif->flags) ? 736 ALL_BUT_BSS_FILTER : ALL_BSS_FILTER), 0); 737 if (ret) { 738 ath6kl_err("couldn't set bss filtering\n"); 739 return ret; 740 } 741 } 742 743 if (request->n_ssids && request->ssids[0].ssid_len) { 744 u8 i; 745 746 if (request->n_ssids > (MAX_PROBED_SSID_INDEX - 1)) 747 request->n_ssids = MAX_PROBED_SSID_INDEX - 1; 748 749 for (i = 0; i < request->n_ssids; i++) 750 ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1, 751 SPECIFIC_SSID_FLAG, 752 request->ssids[i].ssid_len, 753 request->ssids[i].ssid); 754 } 755 756 if (request->ie) { 757 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_PROBE_REQ, 758 request->ie, request->ie_len); 759 if (ret) { 760 ath6kl_err("failed to set Probe Request appie for " 761 "scan"); 762 return ret; 763 } 764 } 765 766 /* 767 * Scan only the requested channels if the request specifies a set of 768 * channels. If the list is longer than the target supports, do not 769 * configure the list and instead, scan all available channels. 770 */ 771 if (request->n_channels > 0 && 772 request->n_channels <= WMI_MAX_CHANNELS) { 773 u8 i; 774 775 n_channels = request->n_channels; 776 777 channels = kzalloc(n_channels * sizeof(u16), GFP_KERNEL); 778 if (channels == NULL) { 779 ath6kl_warn("failed to set scan channels, " 780 "scan all channels"); 781 n_channels = 0; 782 } 783 784 for (i = 0; i < n_channels; i++) 785 channels[i] = request->channels[i]->center_freq; 786 } 787 788 if (test_bit(CONNECTED, &vif->flags)) 789 force_fg_scan = 1; 790 791 ret = ath6kl_wmi_startscan_cmd(ar->wmi, WMI_LONG_SCAN, force_fg_scan, 792 false, 0, 0, n_channels, channels); 793 if (ret) 794 ath6kl_err("wmi_startscan_cmd failed\n"); 795 else 796 ar->scan_req = request; 797 798 kfree(channels); 799 800 return ret; 801} 802 803void ath6kl_cfg80211_scan_complete_event(struct ath6kl *ar, int status) 804{ 805 int i; 806 807 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: status %d\n", __func__, status); 808 809 if (!ar->scan_req) 810 return; 811 812 if ((status == -ECANCELED) || (status == -EBUSY)) { 813 cfg80211_scan_done(ar->scan_req, true); 814 goto out; 815 } 816 817 cfg80211_scan_done(ar->scan_req, false); 818 819 if (ar->scan_req->n_ssids && ar->scan_req->ssids[0].ssid_len) { 820 for (i = 0; i < ar->scan_req->n_ssids; i++) { 821 ath6kl_wmi_probedssid_cmd(ar->wmi, i + 1, 822 DISABLE_SSID_FLAG, 823 0, NULL); 824 } 825 } 826 827out: 828 ar->scan_req = NULL; 829} 830 831static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev, 832 u8 key_index, bool pairwise, 833 const u8 *mac_addr, 834 struct key_params *params) 835{ 836 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev); 837 struct ath6kl_vif *vif = netdev_priv(ndev); 838 struct ath6kl_key *key = NULL; 839 u8 key_usage; 840 u8 key_type; 841 int status = 0; 842 843 if (!ath6kl_cfg80211_ready(ar)) 844 return -EIO; 845 846 if (params->cipher == CCKM_KRK_CIPHER_SUITE) { 847 if (params->key_len != WMI_KRK_LEN) 848 return -EINVAL; 849 return ath6kl_wmi_add_krk_cmd(ar->wmi, params->key); 850 } 851 852 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) { 853 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, 854 "%s: key index %d out of bounds\n", __func__, 855 key_index); 856 return -ENOENT; 857 } 858 859 key = &ar->keys[key_index]; 860 memset(key, 0, sizeof(struct ath6kl_key)); 861 862 if (pairwise) 863 key_usage = PAIRWISE_USAGE; 864 else 865 key_usage = GROUP_USAGE; 866 867 if (params) { 868 if (params->key_len > WLAN_MAX_KEY_LEN || 869 params->seq_len > sizeof(key->seq)) 870 return -EINVAL; 871 872 key->key_len = params->key_len; 873 memcpy(key->key, params->key, key->key_len); 874 key->seq_len = params->seq_len; 875 memcpy(key->seq, params->seq, key->seq_len); 876 key->cipher = params->cipher; 877 } 878 879 switch (key->cipher) { 880 case WLAN_CIPHER_SUITE_WEP40: 881 case WLAN_CIPHER_SUITE_WEP104: 882 key_type = WEP_CRYPT; 883 break; 884 885 case WLAN_CIPHER_SUITE_TKIP: 886 key_type = TKIP_CRYPT; 887 break; 888 889 case WLAN_CIPHER_SUITE_CCMP: 890 key_type = AES_CRYPT; 891 break; 892 893 default: 894 return -ENOTSUPP; 895 } 896 897 if (((vif->auth_mode == WPA_PSK_AUTH) 898 || (vif->auth_mode == WPA2_PSK_AUTH)) 899 && (key_usage & GROUP_USAGE)) 900 del_timer(&ar->disconnect_timer); 901 902 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, 903 "%s: index %d, key_len %d, key_type 0x%x, key_usage 0x%x, seq_len %d\n", 904 __func__, key_index, key->key_len, key_type, 905 key_usage, key->seq_len); 906 907 vif->def_txkey_index = key_index; 908 909 if (ar->nw_type == AP_NETWORK && !pairwise && 910 (key_type == TKIP_CRYPT || key_type == AES_CRYPT) && params) { 911 ar->ap_mode_bkey.valid = true; 912 ar->ap_mode_bkey.key_index = key_index; 913 ar->ap_mode_bkey.key_type = key_type; 914 ar->ap_mode_bkey.key_len = key->key_len; 915 memcpy(ar->ap_mode_bkey.key, key->key, key->key_len); 916 if (!test_bit(CONNECTED, &vif->flags)) { 917 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay initial group " 918 "key configuration until AP mode has been " 919 "started\n"); 920 /* 921 * The key will be set in ath6kl_connect_ap_mode() once 922 * the connected event is received from the target. 923 */ 924 return 0; 925 } 926 } 927 928 if (ar->next_mode == AP_NETWORK && key_type == WEP_CRYPT && 929 !test_bit(CONNECTED, &vif->flags)) { 930 /* 931 * Store the key locally so that it can be re-configured after 932 * the AP mode has properly started 933 * (ath6kl_install_statioc_wep_keys). 934 */ 935 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "Delay WEP key configuration " 936 "until AP mode has been started\n"); 937 ar->wep_key_list[key_index].key_len = key->key_len; 938 memcpy(ar->wep_key_list[key_index].key, key->key, key->key_len); 939 return 0; 940 } 941 942 status = ath6kl_wmi_addkey_cmd(ar->wmi, vif->def_txkey_index, 943 key_type, key_usage, key->key_len, 944 key->seq, key->key, KEY_OP_INIT_VAL, 945 (u8 *) mac_addr, SYNC_BOTH_WMIFLAG); 946 947 if (status) 948 return -EIO; 949 950 return 0; 951} 952 953static int ath6kl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev, 954 u8 key_index, bool pairwise, 955 const u8 *mac_addr) 956{ 957 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev); 958 959 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index); 960 961 if (!ath6kl_cfg80211_ready(ar)) 962 return -EIO; 963 964 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) { 965 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, 966 "%s: key index %d out of bounds\n", __func__, 967 key_index); 968 return -ENOENT; 969 } 970 971 if (!ar->keys[key_index].key_len) { 972 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, 973 "%s: index %d is empty\n", __func__, key_index); 974 return 0; 975 } 976 977 ar->keys[key_index].key_len = 0; 978 979 return ath6kl_wmi_deletekey_cmd(ar->wmi, key_index); 980} 981 982static int ath6kl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev, 983 u8 key_index, bool pairwise, 984 const u8 *mac_addr, void *cookie, 985 void (*callback) (void *cookie, 986 struct key_params *)) 987{ 988 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev); 989 struct ath6kl_key *key = NULL; 990 struct key_params params; 991 992 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index); 993 994 if (!ath6kl_cfg80211_ready(ar)) 995 return -EIO; 996 997 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) { 998 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, 999 "%s: key index %d out of bounds\n", __func__, 1000 key_index); 1001 return -ENOENT; 1002 } 1003 1004 key = &ar->keys[key_index]; 1005 memset(¶ms, 0, sizeof(params)); 1006 params.cipher = key->cipher; 1007 params.key_len = key->key_len; 1008 params.seq_len = key->seq_len; 1009 params.seq = key->seq; 1010 params.key = key->key; 1011 1012 callback(cookie, ¶ms); 1013 1014 return key->key_len ? 0 : -ENOENT; 1015} 1016 1017static int ath6kl_cfg80211_set_default_key(struct wiphy *wiphy, 1018 struct net_device *ndev, 1019 u8 key_index, bool unicast, 1020 bool multicast) 1021{ 1022 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(ndev); 1023 struct ath6kl_vif *vif = netdev_priv(ndev); 1024 struct ath6kl_key *key = NULL; 1025 int status = 0; 1026 u8 key_usage; 1027 enum crypto_type key_type = NONE_CRYPT; 1028 1029 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: index %d\n", __func__, key_index); 1030 1031 if (!ath6kl_cfg80211_ready(ar)) 1032 return -EIO; 1033 1034 if (key_index < WMI_MIN_KEY_INDEX || key_index > WMI_MAX_KEY_INDEX) { 1035 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, 1036 "%s: key index %d out of bounds\n", 1037 __func__, key_index); 1038 return -ENOENT; 1039 } 1040 1041 if (!ar->keys[key_index].key_len) { 1042 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: invalid key index %d\n", 1043 __func__, key_index); 1044 return -EINVAL; 1045 } 1046 1047 vif->def_txkey_index = key_index; 1048 key = &ar->keys[vif->def_txkey_index]; 1049 key_usage = GROUP_USAGE; 1050 if (vif->prwise_crypto == WEP_CRYPT) 1051 key_usage |= TX_USAGE; 1052 if (unicast) 1053 key_type = vif->prwise_crypto; 1054 if (multicast) 1055 key_type = vif->grp_crypto; 1056 1057 if (ar->next_mode == AP_NETWORK && !test_bit(CONNECTED, &vif->flags)) 1058 return 0; /* Delay until AP mode has been started */ 1059 1060 status = ath6kl_wmi_addkey_cmd(ar->wmi, vif->def_txkey_index, 1061 key_type, key_usage, 1062 key->key_len, key->seq, key->key, 1063 KEY_OP_INIT_VAL, NULL, 1064 SYNC_BOTH_WMIFLAG); 1065 if (status) 1066 return -EIO; 1067 1068 return 0; 1069} 1070 1071void ath6kl_cfg80211_tkip_micerr_event(struct ath6kl *ar, u8 keyid, 1072 bool ismcast) 1073{ 1074 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, 1075 "%s: keyid %d, ismcast %d\n", __func__, keyid, ismcast); 1076 1077 cfg80211_michael_mic_failure(ar->net_dev, ar->bssid, 1078 (ismcast ? NL80211_KEYTYPE_GROUP : 1079 NL80211_KEYTYPE_PAIRWISE), keyid, NULL, 1080 GFP_KERNEL); 1081} 1082 1083static int ath6kl_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) 1084{ 1085 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy); 1086 int ret; 1087 1088 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: changed 0x%x\n", __func__, 1089 changed); 1090 1091 if (!ath6kl_cfg80211_ready(ar)) 1092 return -EIO; 1093 1094 if (changed & WIPHY_PARAM_RTS_THRESHOLD) { 1095 ret = ath6kl_wmi_set_rts_cmd(ar->wmi, wiphy->rts_threshold); 1096 if (ret != 0) { 1097 ath6kl_err("ath6kl_wmi_set_rts_cmd failed\n"); 1098 return -EIO; 1099 } 1100 } 1101 1102 return 0; 1103} 1104 1105/* 1106 * The type nl80211_tx_power_setting replaces the following 1107 * data type from 2.6.36 onwards 1108*/ 1109static int ath6kl_cfg80211_set_txpower(struct wiphy *wiphy, 1110 enum nl80211_tx_power_setting type, 1111 int dbm) 1112{ 1113 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy); 1114 u8 ath6kl_dbm; 1115 1116 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x, dbm %d\n", __func__, 1117 type, dbm); 1118 1119 if (!ath6kl_cfg80211_ready(ar)) 1120 return -EIO; 1121 1122 switch (type) { 1123 case NL80211_TX_POWER_AUTOMATIC: 1124 return 0; 1125 case NL80211_TX_POWER_LIMITED: 1126 ar->tx_pwr = ath6kl_dbm = dbm; 1127 break; 1128 default: 1129 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type 0x%x not supported\n", 1130 __func__, type); 1131 return -EOPNOTSUPP; 1132 } 1133 1134 ath6kl_wmi_set_tx_pwr_cmd(ar->wmi, ath6kl_dbm); 1135 1136 return 0; 1137} 1138 1139static int ath6kl_cfg80211_get_txpower(struct wiphy *wiphy, int *dbm) 1140{ 1141 struct ath6kl *ar = (struct ath6kl *)wiphy_priv(wiphy); 1142 struct ath6kl_vif *vif = ar->vif; 1143 1144 if (!ath6kl_cfg80211_ready(ar)) 1145 return -EIO; 1146 1147 if (test_bit(CONNECTED, &vif->flags)) { 1148 ar->tx_pwr = 0; 1149 1150 if (ath6kl_wmi_get_tx_pwr_cmd(ar->wmi) != 0) { 1151 ath6kl_err("ath6kl_wmi_get_tx_pwr_cmd failed\n"); 1152 return -EIO; 1153 } 1154 1155 wait_event_interruptible_timeout(ar->event_wq, ar->tx_pwr != 0, 1156 5 * HZ); 1157 1158 if (signal_pending(current)) { 1159 ath6kl_err("target did not respond\n"); 1160 return -EINTR; 1161 } 1162 } 1163 1164 *dbm = ar->tx_pwr; 1165 return 0; 1166} 1167 1168static int ath6kl_cfg80211_set_power_mgmt(struct wiphy *wiphy, 1169 struct net_device *dev, 1170 bool pmgmt, int timeout) 1171{ 1172 struct ath6kl *ar = ath6kl_priv(dev); 1173 struct wmi_power_mode_cmd mode; 1174 1175 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: pmgmt %d, timeout %d\n", 1176 __func__, pmgmt, timeout); 1177 1178 if (!ath6kl_cfg80211_ready(ar)) 1179 return -EIO; 1180 1181 if (pmgmt) { 1182 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: max perf\n", __func__); 1183 mode.pwr_mode = REC_POWER; 1184 } else { 1185 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: rec power\n", __func__); 1186 mode.pwr_mode = MAX_PERF_POWER; 1187 } 1188 1189 if (ath6kl_wmi_powermode_cmd(ar->wmi, mode.pwr_mode) != 0) { 1190 ath6kl_err("wmi_powermode_cmd failed\n"); 1191 return -EIO; 1192 } 1193 1194 return 0; 1195} 1196 1197static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy, 1198 struct net_device *ndev, 1199 enum nl80211_iftype type, u32 *flags, 1200 struct vif_params *params) 1201{ 1202 struct ath6kl *ar = ath6kl_priv(ndev); 1203 struct wireless_dev *wdev = ar->wdev; 1204 1205 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type); 1206 1207 if (!ath6kl_cfg80211_ready(ar)) 1208 return -EIO; 1209 1210 switch (type) { 1211 case NL80211_IFTYPE_STATION: 1212 ar->next_mode = INFRA_NETWORK; 1213 break; 1214 case NL80211_IFTYPE_ADHOC: 1215 ar->next_mode = ADHOC_NETWORK; 1216 break; 1217 case NL80211_IFTYPE_AP: 1218 ar->next_mode = AP_NETWORK; 1219 break; 1220 case NL80211_IFTYPE_P2P_CLIENT: 1221 ar->next_mode = INFRA_NETWORK; 1222 break; 1223 case NL80211_IFTYPE_P2P_GO: 1224 ar->next_mode = AP_NETWORK; 1225 break; 1226 default: 1227 ath6kl_err("invalid interface type %u\n", type); 1228 return -EOPNOTSUPP; 1229 } 1230 1231 wdev->iftype = type; 1232 1233 return 0; 1234} 1235 1236static int ath6kl_cfg80211_join_ibss(struct wiphy *wiphy, 1237 struct net_device *dev, 1238 struct cfg80211_ibss_params *ibss_param) 1239{ 1240 struct ath6kl *ar = ath6kl_priv(dev); 1241 struct ath6kl_vif *vif = netdev_priv(dev); 1242 int status; 1243 1244 if (!ath6kl_cfg80211_ready(ar)) 1245 return -EIO; 1246 1247 vif->ssid_len = ibss_param->ssid_len; 1248 memcpy(vif->ssid, ibss_param->ssid, vif->ssid_len); 1249 1250 if (ibss_param->channel) 1251 ar->ch_hint = ibss_param->channel->center_freq; 1252 1253 if (ibss_param->channel_fixed) { 1254 /* 1255 * TODO: channel_fixed: The channel should be fixed, do not 1256 * search for IBSSs to join on other channels. Target 1257 * firmware does not support this feature, needs to be 1258 * updated. 1259 */ 1260 return -EOPNOTSUPP; 1261 } 1262 1263 memset(ar->req_bssid, 0, sizeof(ar->req_bssid)); 1264 if (ibss_param->bssid && !is_broadcast_ether_addr(ibss_param->bssid)) 1265 memcpy(ar->req_bssid, ibss_param->bssid, sizeof(ar->req_bssid)); 1266 1267 ath6kl_set_wpa_version(ar, 0); 1268 1269 status = ath6kl_set_auth_type(ar, NL80211_AUTHTYPE_OPEN_SYSTEM); 1270 if (status) 1271 return status; 1272 1273 if (ibss_param->privacy) { 1274 ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, true); 1275 ath6kl_set_cipher(ar, WLAN_CIPHER_SUITE_WEP40, false); 1276 } else { 1277 ath6kl_set_cipher(ar, 0, true); 1278 ath6kl_set_cipher(ar, 0, false); 1279 } 1280 1281 ar->nw_type = ar->next_mode; 1282 1283 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, 1284 "%s: connect called with authmode %d dot11 auth %d" 1285 " PW crypto %d PW crypto len %d GRP crypto %d" 1286 " GRP crypto len %d channel hint %u\n", 1287 __func__, 1288 vif->auth_mode, vif->dot11_auth_mode, vif->prwise_crypto, 1289 vif->prwise_crypto_len, vif->grp_crypto, 1290 vif->grp_crypto_len, ar->ch_hint); 1291 1292 status = ath6kl_wmi_connect_cmd(ar->wmi, ar->nw_type, 1293 vif->dot11_auth_mode, vif->auth_mode, 1294 vif->prwise_crypto, 1295 vif->prwise_crypto_len, 1296 vif->grp_crypto, vif->grp_crypto_len, 1297 vif->ssid_len, vif->ssid, 1298 ar->req_bssid, ar->ch_hint, 1299 ar->connect_ctrl_flags); 1300 set_bit(CONNECT_PEND, &vif->flags); 1301 1302 return 0; 1303} 1304 1305static int ath6kl_cfg80211_leave_ibss(struct wiphy *wiphy, 1306 struct net_device *dev) 1307{ 1308 struct ath6kl *ar = (struct ath6kl *)ath6kl_priv(dev); 1309 struct ath6kl_vif *vif = netdev_priv(dev); 1310 1311 if (!ath6kl_cfg80211_ready(ar)) 1312 return -EIO; 1313 1314 ath6kl_disconnect(ar); 1315 memset(vif->ssid, 0, sizeof(vif->ssid)); 1316 vif->ssid_len = 0; 1317 1318 return 0; 1319} 1320 1321static const u32 cipher_suites[] = { 1322 WLAN_CIPHER_SUITE_WEP40, 1323 WLAN_CIPHER_SUITE_WEP104, 1324 WLAN_CIPHER_SUITE_TKIP, 1325 WLAN_CIPHER_SUITE_CCMP, 1326 CCKM_KRK_CIPHER_SUITE, 1327}; 1328 1329static bool is_rate_legacy(s32 rate) 1330{ 1331 static const s32 legacy[] = { 1000, 2000, 5500, 11000, 1332 6000, 9000, 12000, 18000, 24000, 1333 36000, 48000, 54000 1334 }; 1335 u8 i; 1336 1337 for (i = 0; i < ARRAY_SIZE(legacy); i++) 1338 if (rate == legacy[i]) 1339 return true; 1340 1341 return false; 1342} 1343 1344static bool is_rate_ht20(s32 rate, u8 *mcs, bool *sgi) 1345{ 1346 static const s32 ht20[] = { 6500, 13000, 19500, 26000, 39000, 1347 52000, 58500, 65000, 72200 1348 }; 1349 u8 i; 1350 1351 for (i = 0; i < ARRAY_SIZE(ht20); i++) { 1352 if (rate == ht20[i]) { 1353 if (i == ARRAY_SIZE(ht20) - 1) 1354 /* last rate uses sgi */ 1355 *sgi = true; 1356 else 1357 *sgi = false; 1358 1359 *mcs = i; 1360 return true; 1361 } 1362 } 1363 return false; 1364} 1365 1366static bool is_rate_ht40(s32 rate, u8 *mcs, bool *sgi) 1367{ 1368 static const s32 ht40[] = { 13500, 27000, 40500, 54000, 1369 81000, 108000, 121500, 135000, 1370 150000 1371 }; 1372 u8 i; 1373 1374 for (i = 0; i < ARRAY_SIZE(ht40); i++) { 1375 if (rate == ht40[i]) { 1376 if (i == ARRAY_SIZE(ht40) - 1) 1377 /* last rate uses sgi */ 1378 *sgi = true; 1379 else 1380 *sgi = false; 1381 1382 *mcs = i; 1383 return true; 1384 } 1385 } 1386 1387 return false; 1388} 1389 1390static int ath6kl_get_station(struct wiphy *wiphy, struct net_device *dev, 1391 u8 *mac, struct station_info *sinfo) 1392{ 1393 struct ath6kl *ar = ath6kl_priv(dev); 1394 struct ath6kl_vif *vif = netdev_priv(dev); 1395 long left; 1396 bool sgi; 1397 s32 rate; 1398 int ret; 1399 u8 mcs; 1400 1401 if (memcmp(mac, ar->bssid, ETH_ALEN) != 0) 1402 return -ENOENT; 1403 1404 if (down_interruptible(&ar->sem)) 1405 return -EBUSY; 1406 1407 set_bit(STATS_UPDATE_PEND, &ar->flag); 1408 1409 ret = ath6kl_wmi_get_stats_cmd(ar->wmi); 1410 1411 if (ret != 0) { 1412 up(&ar->sem); 1413 return -EIO; 1414 } 1415 1416 left = wait_event_interruptible_timeout(ar->event_wq, 1417 !test_bit(STATS_UPDATE_PEND, 1418 &ar->flag), 1419 WMI_TIMEOUT); 1420 1421 up(&ar->sem); 1422 1423 if (left == 0) 1424 return -ETIMEDOUT; 1425 else if (left < 0) 1426 return left; 1427 1428 if (ar->target_stats.rx_byte) { 1429 sinfo->rx_bytes = ar->target_stats.rx_byte; 1430 sinfo->filled |= STATION_INFO_RX_BYTES; 1431 sinfo->rx_packets = ar->target_stats.rx_pkt; 1432 sinfo->filled |= STATION_INFO_RX_PACKETS; 1433 } 1434 1435 if (ar->target_stats.tx_byte) { 1436 sinfo->tx_bytes = ar->target_stats.tx_byte; 1437 sinfo->filled |= STATION_INFO_TX_BYTES; 1438 sinfo->tx_packets = ar->target_stats.tx_pkt; 1439 sinfo->filled |= STATION_INFO_TX_PACKETS; 1440 } 1441 1442 sinfo->signal = ar->target_stats.cs_rssi; 1443 sinfo->filled |= STATION_INFO_SIGNAL; 1444 1445 rate = ar->target_stats.tx_ucast_rate; 1446 1447 if (is_rate_legacy(rate)) { 1448 sinfo->txrate.legacy = rate / 100; 1449 } else if (is_rate_ht20(rate, &mcs, &sgi)) { 1450 if (sgi) { 1451 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI; 1452 sinfo->txrate.mcs = mcs - 1; 1453 } else { 1454 sinfo->txrate.mcs = mcs; 1455 } 1456 1457 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS; 1458 } else if (is_rate_ht40(rate, &mcs, &sgi)) { 1459 if (sgi) { 1460 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI; 1461 sinfo->txrate.mcs = mcs - 1; 1462 } else { 1463 sinfo->txrate.mcs = mcs; 1464 } 1465 1466 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH; 1467 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS; 1468 } else { 1469 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, 1470 "invalid rate from stats: %d\n", rate); 1471 ath6kl_debug_war(ar, ATH6KL_WAR_INVALID_RATE); 1472 return 0; 1473 } 1474 1475 sinfo->filled |= STATION_INFO_TX_BITRATE; 1476 1477 if (test_bit(CONNECTED, &vif->flags) && 1478 test_bit(DTIM_PERIOD_AVAIL, &vif->flags) && 1479 ar->nw_type == INFRA_NETWORK) { 1480 sinfo->filled |= STATION_INFO_BSS_PARAM; 1481 sinfo->bss_param.flags = 0; 1482 sinfo->bss_param.dtim_period = ar->assoc_bss_dtim_period; 1483 sinfo->bss_param.beacon_interval = ar->assoc_bss_beacon_int; 1484 } 1485 1486 return 0; 1487} 1488 1489static int ath6kl_set_pmksa(struct wiphy *wiphy, struct net_device *netdev, 1490 struct cfg80211_pmksa *pmksa) 1491{ 1492 struct ath6kl *ar = ath6kl_priv(netdev); 1493 return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid, 1494 pmksa->pmkid, true); 1495} 1496 1497static int ath6kl_del_pmksa(struct wiphy *wiphy, struct net_device *netdev, 1498 struct cfg80211_pmksa *pmksa) 1499{ 1500 struct ath6kl *ar = ath6kl_priv(netdev); 1501 return ath6kl_wmi_setpmkid_cmd(ar->wmi, pmksa->bssid, 1502 pmksa->pmkid, false); 1503} 1504 1505static int ath6kl_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev) 1506{ 1507 struct ath6kl *ar = ath6kl_priv(netdev); 1508 struct ath6kl_vif *vif = netdev_priv(netdev); 1509 1510 if (test_bit(CONNECTED, &vif->flags)) 1511 return ath6kl_wmi_setpmkid_cmd(ar->wmi, ar->bssid, NULL, false); 1512 return 0; 1513} 1514 1515#ifdef CONFIG_PM 1516static int ar6k_cfg80211_suspend(struct wiphy *wiphy, 1517 struct cfg80211_wowlan *wow) 1518{ 1519 struct ath6kl *ar = wiphy_priv(wiphy); 1520 1521 return ath6kl_hif_suspend(ar); 1522} 1523 1524static int ar6k_cfg80211_resume(struct wiphy *wiphy) 1525{ 1526 struct ath6kl *ar = wiphy_priv(wiphy); 1527 1528 return ath6kl_hif_resume(ar); 1529} 1530#endif 1531 1532static int ath6kl_set_channel(struct wiphy *wiphy, struct net_device *dev, 1533 struct ieee80211_channel *chan, 1534 enum nl80211_channel_type channel_type) 1535{ 1536 struct ath6kl *ar = ath6kl_priv(dev); 1537 1538 if (!ath6kl_cfg80211_ready(ar)) 1539 return -EIO; 1540 1541 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: center_freq=%u hw_value=%u\n", 1542 __func__, chan->center_freq, chan->hw_value); 1543 ar->next_chan = chan->center_freq; 1544 1545 return 0; 1546} 1547 1548static bool ath6kl_is_p2p_ie(const u8 *pos) 1549{ 1550 return pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 && 1551 pos[2] == 0x50 && pos[3] == 0x6f && 1552 pos[4] == 0x9a && pos[5] == 0x09; 1553} 1554 1555static int ath6kl_set_ap_probe_resp_ies(struct ath6kl *ar, const u8 *ies, 1556 size_t ies_len) 1557{ 1558 const u8 *pos; 1559 u8 *buf = NULL; 1560 size_t len = 0; 1561 int ret; 1562 1563 /* 1564 * Filter out P2P IE(s) since they will be included depending on 1565 * the Probe Request frame in ath6kl_send_go_probe_resp(). 1566 */ 1567 1568 if (ies && ies_len) { 1569 buf = kmalloc(ies_len, GFP_KERNEL); 1570 if (buf == NULL) 1571 return -ENOMEM; 1572 pos = ies; 1573 while (pos + 1 < ies + ies_len) { 1574 if (pos + 2 + pos[1] > ies + ies_len) 1575 break; 1576 if (!ath6kl_is_p2p_ie(pos)) { 1577 memcpy(buf + len, pos, 2 + pos[1]); 1578 len += 2 + pos[1]; 1579 } 1580 pos += 2 + pos[1]; 1581 } 1582 } 1583 1584 ret = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_PROBE_RESP, 1585 buf, len); 1586 kfree(buf); 1587 return ret; 1588} 1589 1590static int ath6kl_ap_beacon(struct wiphy *wiphy, struct net_device *dev, 1591 struct beacon_parameters *info, bool add) 1592{ 1593 struct ath6kl *ar = ath6kl_priv(dev); 1594 struct ath6kl_vif *vif = netdev_priv(dev); 1595 struct ieee80211_mgmt *mgmt; 1596 u8 *ies; 1597 int ies_len; 1598 struct wmi_connect_cmd p; 1599 int res; 1600 int i; 1601 1602 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: add=%d\n", __func__, add); 1603 1604 if (!ath6kl_cfg80211_ready(ar)) 1605 return -EIO; 1606 1607 if (ar->next_mode != AP_NETWORK) 1608 return -EOPNOTSUPP; 1609 1610 if (info->beacon_ies) { 1611 res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_BEACON, 1612 info->beacon_ies, 1613 info->beacon_ies_len); 1614 if (res) 1615 return res; 1616 } 1617 if (info->proberesp_ies) { 1618 res = ath6kl_set_ap_probe_resp_ies(ar, info->proberesp_ies, 1619 info->proberesp_ies_len); 1620 if (res) 1621 return res; 1622 } 1623 if (info->assocresp_ies) { 1624 res = ath6kl_wmi_set_appie_cmd(ar->wmi, WMI_FRAME_ASSOC_RESP, 1625 info->assocresp_ies, 1626 info->assocresp_ies_len); 1627 if (res) 1628 return res; 1629 } 1630 1631 if (!add) 1632 return 0; 1633 1634 ar->ap_mode_bkey.valid = false; 1635 1636 /* TODO: 1637 * info->interval 1638 * info->dtim_period 1639 */ 1640 1641 if (info->head == NULL) 1642 return -EINVAL; 1643 mgmt = (struct ieee80211_mgmt *) info->head; 1644 ies = mgmt->u.beacon.variable; 1645 if (ies > info->head + info->head_len) 1646 return -EINVAL; 1647 ies_len = info->head + info->head_len - ies; 1648 1649 if (info->ssid == NULL) 1650 return -EINVAL; 1651 memcpy(vif->ssid, info->ssid, info->ssid_len); 1652 vif->ssid_len = info->ssid_len; 1653 if (info->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE) 1654 return -EOPNOTSUPP; /* TODO */ 1655 1656 vif->dot11_auth_mode = OPEN_AUTH; 1657 1658 memset(&p, 0, sizeof(p)); 1659 1660 for (i = 0; i < info->crypto.n_akm_suites; i++) { 1661 switch (info->crypto.akm_suites[i]) { 1662 case WLAN_AKM_SUITE_8021X: 1663 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1) 1664 p.auth_mode |= WPA_AUTH; 1665 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2) 1666 p.auth_mode |= WPA2_AUTH; 1667 break; 1668 case WLAN_AKM_SUITE_PSK: 1669 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_1) 1670 p.auth_mode |= WPA_PSK_AUTH; 1671 if (info->crypto.wpa_versions & NL80211_WPA_VERSION_2) 1672 p.auth_mode |= WPA2_PSK_AUTH; 1673 break; 1674 } 1675 } 1676 if (p.auth_mode == 0) 1677 p.auth_mode = NONE_AUTH; 1678 vif->auth_mode = p.auth_mode; 1679 1680 for (i = 0; i < info->crypto.n_ciphers_pairwise; i++) { 1681 switch (info->crypto.ciphers_pairwise[i]) { 1682 case WLAN_CIPHER_SUITE_WEP40: 1683 case WLAN_CIPHER_SUITE_WEP104: 1684 p.prwise_crypto_type |= WEP_CRYPT; 1685 break; 1686 case WLAN_CIPHER_SUITE_TKIP: 1687 p.prwise_crypto_type |= TKIP_CRYPT; 1688 break; 1689 case WLAN_CIPHER_SUITE_CCMP: 1690 p.prwise_crypto_type |= AES_CRYPT; 1691 break; 1692 } 1693 } 1694 if (p.prwise_crypto_type == 0) { 1695 p.prwise_crypto_type = NONE_CRYPT; 1696 ath6kl_set_cipher(ar, 0, true); 1697 } else if (info->crypto.n_ciphers_pairwise == 1) 1698 ath6kl_set_cipher(ar, info->crypto.ciphers_pairwise[0], true); 1699 1700 switch (info->crypto.cipher_group) { 1701 case WLAN_CIPHER_SUITE_WEP40: 1702 case WLAN_CIPHER_SUITE_WEP104: 1703 p.grp_crypto_type = WEP_CRYPT; 1704 break; 1705 case WLAN_CIPHER_SUITE_TKIP: 1706 p.grp_crypto_type = TKIP_CRYPT; 1707 break; 1708 case WLAN_CIPHER_SUITE_CCMP: 1709 p.grp_crypto_type = AES_CRYPT; 1710 break; 1711 default: 1712 p.grp_crypto_type = NONE_CRYPT; 1713 break; 1714 } 1715 ath6kl_set_cipher(ar, info->crypto.cipher_group, false); 1716 1717 p.nw_type = AP_NETWORK; 1718 ar->nw_type = ar->next_mode; 1719 1720 p.ssid_len = vif->ssid_len; 1721 memcpy(p.ssid, vif->ssid, vif->ssid_len); 1722 p.dot11_auth_mode = vif->dot11_auth_mode; 1723 p.ch = cpu_to_le16(ar->next_chan); 1724 1725 res = ath6kl_wmi_ap_profile_commit(ar->wmi, &p); 1726 if (res < 0) 1727 return res; 1728 1729 return 0; 1730} 1731 1732static int ath6kl_add_beacon(struct wiphy *wiphy, struct net_device *dev, 1733 struct beacon_parameters *info) 1734{ 1735 return ath6kl_ap_beacon(wiphy, dev, info, true); 1736} 1737 1738static int ath6kl_set_beacon(struct wiphy *wiphy, struct net_device *dev, 1739 struct beacon_parameters *info) 1740{ 1741 return ath6kl_ap_beacon(wiphy, dev, info, false); 1742} 1743 1744static int ath6kl_del_beacon(struct wiphy *wiphy, struct net_device *dev) 1745{ 1746 struct ath6kl *ar = ath6kl_priv(dev); 1747 struct ath6kl_vif *vif = netdev_priv(dev); 1748 1749 if (ar->nw_type != AP_NETWORK) 1750 return -EOPNOTSUPP; 1751 if (!test_bit(CONNECTED, &vif->flags)) 1752 return -ENOTCONN; 1753 1754 ath6kl_wmi_disconnect_cmd(ar->wmi); 1755 clear_bit(CONNECTED, &vif->flags); 1756 1757 return 0; 1758} 1759 1760static int ath6kl_change_station(struct wiphy *wiphy, struct net_device *dev, 1761 u8 *mac, struct station_parameters *params) 1762{ 1763 struct ath6kl *ar = ath6kl_priv(dev); 1764 1765 if (ar->nw_type != AP_NETWORK) 1766 return -EOPNOTSUPP; 1767 1768 /* Use this only for authorizing/unauthorizing a station */ 1769 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) 1770 return -EOPNOTSUPP; 1771 1772 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED)) 1773 return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_AUTHORIZE, 1774 mac, 0); 1775 return ath6kl_wmi_ap_set_mlme(ar->wmi, WMI_AP_MLME_UNAUTHORIZE, mac, 1776 0); 1777} 1778 1779static int ath6kl_remain_on_channel(struct wiphy *wiphy, 1780 struct net_device *dev, 1781 struct ieee80211_channel *chan, 1782 enum nl80211_channel_type channel_type, 1783 unsigned int duration, 1784 u64 *cookie) 1785{ 1786 struct ath6kl *ar = ath6kl_priv(dev); 1787 1788 /* TODO: if already pending or ongoing remain-on-channel, 1789 * return -EBUSY */ 1790 *cookie = 1; /* only a single pending request is supported */ 1791 1792 return ath6kl_wmi_remain_on_chnl_cmd(ar->wmi, chan->center_freq, 1793 duration); 1794} 1795 1796static int ath6kl_cancel_remain_on_channel(struct wiphy *wiphy, 1797 struct net_device *dev, 1798 u64 cookie) 1799{ 1800 struct ath6kl *ar = ath6kl_priv(dev); 1801 1802 if (cookie != 1) 1803 return -ENOENT; 1804 1805 return ath6kl_wmi_cancel_remain_on_chnl_cmd(ar->wmi); 1806} 1807 1808static int ath6kl_send_go_probe_resp(struct ath6kl *ar, const u8 *buf, 1809 size_t len, unsigned int freq) 1810{ 1811 const u8 *pos; 1812 u8 *p2p; 1813 int p2p_len; 1814 int ret; 1815 const struct ieee80211_mgmt *mgmt; 1816 1817 mgmt = (const struct ieee80211_mgmt *) buf; 1818 1819 /* Include P2P IE(s) from the frame generated in user space. */ 1820 1821 p2p = kmalloc(len, GFP_KERNEL); 1822 if (p2p == NULL) 1823 return -ENOMEM; 1824 p2p_len = 0; 1825 1826 pos = mgmt->u.probe_resp.variable; 1827 while (pos + 1 < buf + len) { 1828 if (pos + 2 + pos[1] > buf + len) 1829 break; 1830 if (ath6kl_is_p2p_ie(pos)) { 1831 memcpy(p2p + p2p_len, pos, 2 + pos[1]); 1832 p2p_len += 2 + pos[1]; 1833 } 1834 pos += 2 + pos[1]; 1835 } 1836 1837 ret = ath6kl_wmi_send_probe_response_cmd(ar->wmi, freq, mgmt->da, 1838 p2p, p2p_len); 1839 kfree(p2p); 1840 return ret; 1841} 1842 1843static int ath6kl_mgmt_tx(struct wiphy *wiphy, struct net_device *dev, 1844 struct ieee80211_channel *chan, bool offchan, 1845 enum nl80211_channel_type channel_type, 1846 bool channel_type_valid, unsigned int wait, 1847 const u8 *buf, size_t len, bool no_cck, 1848 bool dont_wait_for_ack, u64 *cookie) 1849{ 1850 struct ath6kl *ar = ath6kl_priv(dev); 1851 struct ath6kl_vif *vif = netdev_priv(dev); 1852 u32 id; 1853 const struct ieee80211_mgmt *mgmt; 1854 1855 mgmt = (const struct ieee80211_mgmt *) buf; 1856 if (buf + len >= mgmt->u.probe_resp.variable && 1857 ar->nw_type == AP_NETWORK && test_bit(CONNECTED, &vif->flags) && 1858 ieee80211_is_probe_resp(mgmt->frame_control)) { 1859 /* 1860 * Send Probe Response frame in AP mode using a separate WMI 1861 * command to allow the target to fill in the generic IEs. 1862 */ 1863 *cookie = 0; /* TX status not supported */ 1864 return ath6kl_send_go_probe_resp(ar, buf, len, 1865 chan->center_freq); 1866 } 1867 1868 id = ar->send_action_id++; 1869 if (id == 0) { 1870 /* 1871 * 0 is a reserved value in the WMI command and shall not be 1872 * used for the command. 1873 */ 1874 id = ar->send_action_id++; 1875 } 1876 1877 *cookie = id; 1878 return ath6kl_wmi_send_action_cmd(ar->wmi, id, chan->center_freq, wait, 1879 buf, len); 1880} 1881 1882static void ath6kl_mgmt_frame_register(struct wiphy *wiphy, 1883 struct net_device *dev, 1884 u16 frame_type, bool reg) 1885{ 1886 struct ath6kl *ar = ath6kl_priv(dev); 1887 1888 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: frame_type=0x%x reg=%d\n", 1889 __func__, frame_type, reg); 1890 if (frame_type == IEEE80211_STYPE_PROBE_REQ) { 1891 /* 1892 * Note: This notification callback is not allowed to sleep, so 1893 * we cannot send WMI_PROBE_REQ_REPORT_CMD here. Instead, we 1894 * hardcode target to report Probe Request frames all the time. 1895 */ 1896 ar->probe_req_report = reg; 1897 } 1898} 1899 1900static const struct ieee80211_txrx_stypes 1901ath6kl_mgmt_stypes[NUM_NL80211_IFTYPES] = { 1902 [NL80211_IFTYPE_STATION] = { 1903 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | 1904 BIT(IEEE80211_STYPE_PROBE_RESP >> 4), 1905 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | 1906 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) 1907 }, 1908 [NL80211_IFTYPE_P2P_CLIENT] = { 1909 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | 1910 BIT(IEEE80211_STYPE_PROBE_RESP >> 4), 1911 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | 1912 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) 1913 }, 1914 [NL80211_IFTYPE_P2P_GO] = { 1915 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | 1916 BIT(IEEE80211_STYPE_PROBE_RESP >> 4), 1917 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | 1918 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) 1919 }, 1920}; 1921 1922static struct cfg80211_ops ath6kl_cfg80211_ops = { 1923 .change_virtual_intf = ath6kl_cfg80211_change_iface, 1924 .scan = ath6kl_cfg80211_scan, 1925 .connect = ath6kl_cfg80211_connect, 1926 .disconnect = ath6kl_cfg80211_disconnect, 1927 .add_key = ath6kl_cfg80211_add_key, 1928 .get_key = ath6kl_cfg80211_get_key, 1929 .del_key = ath6kl_cfg80211_del_key, 1930 .set_default_key = ath6kl_cfg80211_set_default_key, 1931 .set_wiphy_params = ath6kl_cfg80211_set_wiphy_params, 1932 .set_tx_power = ath6kl_cfg80211_set_txpower, 1933 .get_tx_power = ath6kl_cfg80211_get_txpower, 1934 .set_power_mgmt = ath6kl_cfg80211_set_power_mgmt, 1935 .join_ibss = ath6kl_cfg80211_join_ibss, 1936 .leave_ibss = ath6kl_cfg80211_leave_ibss, 1937 .get_station = ath6kl_get_station, 1938 .set_pmksa = ath6kl_set_pmksa, 1939 .del_pmksa = ath6kl_del_pmksa, 1940 .flush_pmksa = ath6kl_flush_pmksa, 1941 CFG80211_TESTMODE_CMD(ath6kl_tm_cmd) 1942#ifdef CONFIG_PM 1943 .suspend = ar6k_cfg80211_suspend, 1944 .resume = ar6k_cfg80211_resume, 1945#endif 1946 .set_channel = ath6kl_set_channel, 1947 .add_beacon = ath6kl_add_beacon, 1948 .set_beacon = ath6kl_set_beacon, 1949 .del_beacon = ath6kl_del_beacon, 1950 .change_station = ath6kl_change_station, 1951 .remain_on_channel = ath6kl_remain_on_channel, 1952 .cancel_remain_on_channel = ath6kl_cancel_remain_on_channel, 1953 .mgmt_tx = ath6kl_mgmt_tx, 1954 .mgmt_frame_register = ath6kl_mgmt_frame_register, 1955}; 1956 1957struct ath6kl *ath6kl_core_alloc(struct device *dev) 1958{ 1959 struct ath6kl *ar; 1960 struct wiphy *wiphy; 1961 u8 ctr; 1962 1963 /* create a new wiphy for use with cfg80211 */ 1964 wiphy = wiphy_new(&ath6kl_cfg80211_ops, sizeof(struct ath6kl)); 1965 1966 if (!wiphy) { 1967 ath6kl_err("couldn't allocate wiphy device\n"); 1968 return NULL; 1969 } 1970 1971 ar = wiphy_priv(wiphy); 1972 ar->p2p = !!ath6kl_p2p; 1973 ar->wiphy = wiphy; 1974 ar->dev = dev; 1975 1976 spin_lock_init(&ar->lock); 1977 spin_lock_init(&ar->mcastpsq_lock); 1978 1979 init_waitqueue_head(&ar->event_wq); 1980 sema_init(&ar->sem, 1); 1981 1982 INIT_LIST_HEAD(&ar->amsdu_rx_buffer_queue); 1983 1984 clear_bit(WMI_ENABLED, &ar->flag); 1985 clear_bit(SKIP_SCAN, &ar->flag); 1986 clear_bit(DESTROY_IN_PROGRESS, &ar->flag); 1987 1988 ar->listen_intvl_t = A_DEFAULT_LISTEN_INTERVAL; 1989 ar->listen_intvl_b = 0; 1990 ar->tx_pwr = 0; 1991 1992 ar->intra_bss = 1; 1993 memset(&ar->sc_params, 0, sizeof(ar->sc_params)); 1994 ar->sc_params.short_scan_ratio = WMI_SHORTSCANRATIO_DEFAULT; 1995 ar->sc_params.scan_ctrl_flags = DEFAULT_SCAN_CTRL_FLAGS; 1996 ar->lrssi_roam_threshold = DEF_LRSSI_ROAM_THRESHOLD; 1997 1998 memset((u8 *)ar->sta_list, 0, 1999 AP_MAX_NUM_STA * sizeof(struct ath6kl_sta)); 2000 2001 /* Init the PS queues */ 2002 for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) { 2003 spin_lock_init(&ar->sta_list[ctr].psq_lock); 2004 skb_queue_head_init(&ar->sta_list[ctr].psq); 2005 } 2006 2007 skb_queue_head_init(&ar->mcastpsq); 2008 2009 memcpy(ar->ap_country_code, DEF_AP_COUNTRY_CODE, 3); 2010 2011 return ar; 2012} 2013 2014int ath6kl_register_ieee80211_hw(struct ath6kl *ar) 2015{ 2016 struct wiphy *wiphy = ar->wiphy; 2017 int ret; 2018 2019 wiphy->mgmt_stypes = ath6kl_mgmt_stypes; 2020 2021 wiphy->max_remain_on_channel_duration = 5000; 2022 2023 /* set device pointer for wiphy */ 2024 set_wiphy_dev(wiphy, ar->dev); 2025 2026 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | 2027 BIT(NL80211_IFTYPE_ADHOC) | 2028 BIT(NL80211_IFTYPE_AP); 2029 if (ar->p2p) { 2030 wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_GO) | 2031 BIT(NL80211_IFTYPE_P2P_CLIENT); 2032 } 2033 2034 /* max num of ssids that can be probed during scanning */ 2035 wiphy->max_scan_ssids = MAX_PROBED_SSID_INDEX; 2036 wiphy->max_scan_ie_len = 1000; /* FIX: what is correct limit? */ 2037 wiphy->bands[IEEE80211_BAND_2GHZ] = &ath6kl_band_2ghz; 2038 wiphy->bands[IEEE80211_BAND_5GHZ] = &ath6kl_band_5ghz; 2039 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; 2040 2041 wiphy->cipher_suites = cipher_suites; 2042 wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); 2043 2044 ret = wiphy_register(wiphy); 2045 if (ret < 0) { 2046 ath6kl_err("couldn't register wiphy device\n"); 2047 return ret; 2048 } 2049 2050 return 0; 2051} 2052 2053static int ath6kl_init_if_data(struct ath6kl_vif *vif) 2054{ 2055 struct ath6kl *ar = vif->ar; 2056 2057 ar->aggr_cntxt = aggr_init(vif->ndev); 2058 if (!ar->aggr_cntxt) { 2059 ath6kl_err("failed to initialize aggr\n"); 2060 return -ENOMEM; 2061 } 2062 2063 setup_timer(&ar->disconnect_timer, disconnect_timer_handler, 2064 (unsigned long) vif->ndev); 2065 2066 return 0; 2067} 2068 2069void ath6kl_deinit_if_data(struct ath6kl_vif *vif) 2070{ 2071 struct ath6kl *ar = vif->ar; 2072 2073 aggr_module_destroy(ar->aggr_cntxt); 2074 2075 ar->aggr_cntxt = NULL; 2076 2077 if (test_bit(NETDEV_REGISTERED, &vif->flags)) { 2078 unregister_netdev(vif->ndev); 2079 clear_bit(NETDEV_REGISTERED, &vif->flags); 2080 } 2081 2082 free_netdev(vif->ndev); 2083} 2084 2085struct net_device *ath6kl_interface_add(struct ath6kl *ar, char *name, 2086 enum nl80211_iftype type) 2087{ 2088 struct net_device *ndev; 2089 struct ath6kl_vif *vif; 2090 2091 ndev = alloc_netdev(sizeof(*vif), "wlan%d", ether_setup); 2092 if (!ndev) 2093 return NULL; 2094 2095 vif = netdev_priv(ndev); 2096 ndev->ieee80211_ptr = &vif->wdev; 2097 vif->wdev.wiphy = ar->wiphy; 2098 vif->ar = ar; 2099 ar->vif = vif; 2100 vif->ndev = ndev; 2101 SET_NETDEV_DEV(ndev, wiphy_dev(vif->wdev.wiphy)); 2102 vif->wdev.netdev = ndev; 2103 vif->wdev.iftype = type; 2104 ar->wdev = &vif->wdev; 2105 ar->net_dev = ndev; 2106 2107 init_netdev(ndev); 2108 2109 ath6kl_init_control_info(ar); 2110 2111 /* TODO: Pass interface specific pointer instead of ar */ 2112 if (ath6kl_init_if_data(vif)) 2113 goto err; 2114 2115 if (register_netdev(ndev)) 2116 goto err; 2117 2118 ar->sme_state = SME_DISCONNECTED; 2119 set_bit(WLAN_ENABLED, &vif->flags); 2120 ar->wlan_pwr_state = WLAN_POWER_STATE_ON; 2121 set_bit(NETDEV_REGISTERED, &vif->flags); 2122 2123 return ndev; 2124 2125err: 2126 ath6kl_deinit_if_data(vif); 2127 2128 return NULL; 2129} 2130 2131void ath6kl_deinit_ieee80211_hw(struct ath6kl *ar) 2132{ 2133 if (ar->scan_req) { 2134 cfg80211_scan_done(ar->scan_req, true); 2135 ar->scan_req = NULL; 2136 } 2137 2138 wiphy_unregister(ar->wiphy); 2139 wiphy_free(ar->wiphy); 2140} 2141