1 /* 2 * Marvell Wireless LAN device driver: CFG80211 3 * 4 * Copyright (C) 2011-2014, Marvell International Ltd. 5 * 6 * This software file (the "File") is distributed by Marvell International 7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991 8 * (the "License"). You may use, redistribute and/or modify this File in 9 * accordance with the terms and conditions of the License, a copy of which 10 * is available by writing to the Free Software Foundation, Inc., 11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the 12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 13 * 14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE 16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about 17 * this warranty disclaimer. 18 */ 19 20 #include "cfg80211.h" 21 #include "main.h" 22 #include "11n.h" 23 #include "wmm.h" 24 25 static char *reg_alpha2; 26 module_param(reg_alpha2, charp, 0); 27 28 static const struct ieee80211_iface_limit mwifiex_ap_sta_limits[] = { 29 { 30 .max = 3, .types = BIT(NL80211_IFTYPE_STATION) | 31 BIT(NL80211_IFTYPE_P2P_GO) | 32 BIT(NL80211_IFTYPE_P2P_CLIENT) | 33 BIT(NL80211_IFTYPE_AP), 34 }, 35 }; 36 37 static const struct ieee80211_iface_combination 38 mwifiex_iface_comb_ap_sta = { 39 .limits = mwifiex_ap_sta_limits, 40 .num_different_channels = 1, 41 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits), 42 .max_interfaces = MWIFIEX_MAX_BSS_NUM, 43 .beacon_int_infra_match = true, 44 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | 45 BIT(NL80211_CHAN_WIDTH_20) | 46 BIT(NL80211_CHAN_WIDTH_40), 47 }; 48 49 static const struct ieee80211_iface_combination 50 mwifiex_iface_comb_ap_sta_vht = { 51 .limits = mwifiex_ap_sta_limits, 52 .num_different_channels = 1, 53 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits), 54 .max_interfaces = MWIFIEX_MAX_BSS_NUM, 55 .beacon_int_infra_match = true, 56 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | 57 BIT(NL80211_CHAN_WIDTH_20) | 58 BIT(NL80211_CHAN_WIDTH_40) | 59 BIT(NL80211_CHAN_WIDTH_80), 60 }; 61 62 static const struct 63 ieee80211_iface_combination mwifiex_iface_comb_ap_sta_drcs = { 64 .limits = mwifiex_ap_sta_limits, 65 .num_different_channels = 2, 66 .n_limits = ARRAY_SIZE(mwifiex_ap_sta_limits), 67 .max_interfaces = MWIFIEX_MAX_BSS_NUM, 68 .beacon_int_infra_match = true, 69 }; 70 71 /* 72 * This function maps the nl802.11 channel type into driver channel type. 73 * 74 * The mapping is as follows - 75 * NL80211_CHAN_NO_HT -> IEEE80211_HT_PARAM_CHA_SEC_NONE 76 * NL80211_CHAN_HT20 -> IEEE80211_HT_PARAM_CHA_SEC_NONE 77 * NL80211_CHAN_HT40PLUS -> IEEE80211_HT_PARAM_CHA_SEC_ABOVE 78 * NL80211_CHAN_HT40MINUS -> IEEE80211_HT_PARAM_CHA_SEC_BELOW 79 * Others -> IEEE80211_HT_PARAM_CHA_SEC_NONE 80 */ 81 u8 mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type) 82 { 83 switch (chan_type) { 84 case NL80211_CHAN_NO_HT: 85 case NL80211_CHAN_HT20: 86 return IEEE80211_HT_PARAM_CHA_SEC_NONE; 87 case NL80211_CHAN_HT40PLUS: 88 return IEEE80211_HT_PARAM_CHA_SEC_ABOVE; 89 case NL80211_CHAN_HT40MINUS: 90 return IEEE80211_HT_PARAM_CHA_SEC_BELOW; 91 default: 92 return IEEE80211_HT_PARAM_CHA_SEC_NONE; 93 } 94 } 95 96 /* This function maps IEEE HT secondary channel type to NL80211 channel type 97 */ 98 u8 mwifiex_get_chan_type(struct mwifiex_private *priv) 99 { 100 struct mwifiex_channel_band channel_band; 101 int ret; 102 103 ret = mwifiex_get_chan_info(priv, &channel_band); 104 105 if (!ret) { 106 switch (channel_band.band_config.chan_width) { 107 case CHAN_BW_20MHZ: 108 if (IS_11N_ENABLED(priv)) 109 return NL80211_CHAN_HT20; 110 else 111 return NL80211_CHAN_NO_HT; 112 case CHAN_BW_40MHZ: 113 if (channel_band.band_config.chan2_offset == 114 SEC_CHAN_ABOVE) 115 return NL80211_CHAN_HT40PLUS; 116 else 117 return NL80211_CHAN_HT40MINUS; 118 default: 119 return NL80211_CHAN_HT20; 120 } 121 } 122 123 return NL80211_CHAN_HT20; 124 } 125 126 /* 127 * This function checks whether WEP is set. 128 */ 129 static int 130 mwifiex_is_alg_wep(u32 cipher) 131 { 132 switch (cipher) { 133 case WLAN_CIPHER_SUITE_WEP40: 134 case WLAN_CIPHER_SUITE_WEP104: 135 return 1; 136 default: 137 break; 138 } 139 140 return 0; 141 } 142 143 /* 144 * This function retrieves the private structure from kernel wiphy structure. 145 */ 146 static void *mwifiex_cfg80211_get_adapter(struct wiphy *wiphy) 147 { 148 return (void *) (*(unsigned long *) wiphy_priv(wiphy)); 149 } 150 151 /* 152 * CFG802.11 operation handler to delete a network key. 153 */ 154 static int 155 mwifiex_cfg80211_del_key(struct wiphy *wiphy, struct net_device *netdev, 156 u8 key_index, bool pairwise, const u8 *mac_addr) 157 { 158 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev); 159 static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 160 const u8 *peer_mac = pairwise ? mac_addr : bc_mac; 161 162 if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, peer_mac, 1)) { 163 mwifiex_dbg(priv->adapter, ERROR, "deleting the crypto keys\n"); 164 return -EFAULT; 165 } 166 167 mwifiex_dbg(priv->adapter, INFO, "info: crypto keys deleted\n"); 168 return 0; 169 } 170 171 /* 172 * This function forms an skb for management frame. 173 */ 174 static int 175 mwifiex_form_mgmt_frame(struct sk_buff *skb, const u8 *buf, size_t len) 176 { 177 u8 addr[ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; 178 u16 pkt_len; 179 u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT; 180 181 pkt_len = len + ETH_ALEN; 182 183 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN + 184 MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len)); 185 memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len)); 186 187 memcpy(skb_push(skb, sizeof(tx_control)), 188 &tx_control, sizeof(tx_control)); 189 190 memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type)); 191 192 /* Add packet data and address4 */ 193 skb_put_data(skb, buf, sizeof(struct ieee80211_hdr_3addr)); 194 skb_put_data(skb, addr, ETH_ALEN); 195 skb_put_data(skb, buf + sizeof(struct ieee80211_hdr_3addr), 196 len - sizeof(struct ieee80211_hdr_3addr)); 197 198 skb->priority = LOW_PRIO_TID; 199 __net_timestamp(skb); 200 201 return 0; 202 } 203 204 /* 205 * CFG802.11 operation handler to transmit a management frame. 206 */ 207 static int 208 mwifiex_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, 209 struct cfg80211_mgmt_tx_params *params, u64 *cookie) 210 { 211 const u8 *buf = params->buf; 212 size_t len = params->len; 213 struct sk_buff *skb; 214 u16 pkt_len; 215 const struct ieee80211_mgmt *mgmt; 216 struct mwifiex_txinfo *tx_info; 217 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev); 218 219 if (!buf || !len) { 220 mwifiex_dbg(priv->adapter, ERROR, "invalid buffer and length\n"); 221 return -EFAULT; 222 } 223 224 mgmt = (const struct ieee80211_mgmt *)buf; 225 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA && 226 ieee80211_is_probe_resp(mgmt->frame_control)) { 227 /* Since we support offload probe resp, we need to skip probe 228 * resp in AP or GO mode */ 229 mwifiex_dbg(priv->adapter, INFO, 230 "info: skip to send probe resp in AP or GO mode\n"); 231 return 0; 232 } 233 234 pkt_len = len + ETH_ALEN; 235 skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN + 236 MWIFIEX_MGMT_FRAME_HEADER_SIZE + 237 pkt_len + sizeof(pkt_len)); 238 239 if (!skb) { 240 mwifiex_dbg(priv->adapter, ERROR, 241 "allocate skb failed for management frame\n"); 242 return -ENOMEM; 243 } 244 245 tx_info = MWIFIEX_SKB_TXCB(skb); 246 memset(tx_info, 0, sizeof(*tx_info)); 247 tx_info->bss_num = priv->bss_num; 248 tx_info->bss_type = priv->bss_type; 249 tx_info->pkt_len = pkt_len; 250 251 mwifiex_form_mgmt_frame(skb, buf, len); 252 *cookie = prandom_u32() | 1; 253 254 if (ieee80211_is_action(mgmt->frame_control)) 255 skb = mwifiex_clone_skb_for_tx_status(priv, 256 skb, 257 MWIFIEX_BUF_FLAG_ACTION_TX_STATUS, cookie); 258 else 259 cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true, 260 GFP_ATOMIC); 261 262 mwifiex_queue_tx_pkt(priv, skb); 263 264 mwifiex_dbg(priv->adapter, INFO, "info: management frame transmitted\n"); 265 return 0; 266 } 267 268 /* 269 * CFG802.11 operation handler to register a mgmt frame. 270 */ 271 static void 272 mwifiex_cfg80211_mgmt_frame_register(struct wiphy *wiphy, 273 struct wireless_dev *wdev, 274 u16 frame_type, bool reg) 275 { 276 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev); 277 u32 mask; 278 279 if (reg) 280 mask = priv->mgmt_frame_mask | BIT(frame_type >> 4); 281 else 282 mask = priv->mgmt_frame_mask & ~BIT(frame_type >> 4); 283 284 if (mask != priv->mgmt_frame_mask) { 285 priv->mgmt_frame_mask = mask; 286 mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG, 287 HostCmd_ACT_GEN_SET, 0, 288 &priv->mgmt_frame_mask, false); 289 mwifiex_dbg(priv->adapter, INFO, "info: mgmt frame registered\n"); 290 } 291 } 292 293 /* 294 * CFG802.11 operation handler to remain on channel. 295 */ 296 static int 297 mwifiex_cfg80211_remain_on_channel(struct wiphy *wiphy, 298 struct wireless_dev *wdev, 299 struct ieee80211_channel *chan, 300 unsigned int duration, u64 *cookie) 301 { 302 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev); 303 int ret; 304 305 if (!chan || !cookie) { 306 mwifiex_dbg(priv->adapter, ERROR, "Invalid parameter for ROC\n"); 307 return -EINVAL; 308 } 309 310 if (priv->roc_cfg.cookie) { 311 mwifiex_dbg(priv->adapter, INFO, 312 "info: ongoing ROC, cookie = 0x%llx\n", 313 priv->roc_cfg.cookie); 314 return -EBUSY; 315 } 316 317 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_SET, chan, 318 duration); 319 320 if (!ret) { 321 *cookie = prandom_u32() | 1; 322 priv->roc_cfg.cookie = *cookie; 323 priv->roc_cfg.chan = *chan; 324 325 cfg80211_ready_on_channel(wdev, *cookie, chan, 326 duration, GFP_ATOMIC); 327 328 mwifiex_dbg(priv->adapter, INFO, 329 "info: ROC, cookie = 0x%llx\n", *cookie); 330 } 331 332 return ret; 333 } 334 335 /* 336 * CFG802.11 operation handler to cancel remain on channel. 337 */ 338 static int 339 mwifiex_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy, 340 struct wireless_dev *wdev, u64 cookie) 341 { 342 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev); 343 int ret; 344 345 if (cookie != priv->roc_cfg.cookie) 346 return -ENOENT; 347 348 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_REMOVE, 349 &priv->roc_cfg.chan, 0); 350 351 if (!ret) { 352 cfg80211_remain_on_channel_expired(wdev, cookie, 353 &priv->roc_cfg.chan, 354 GFP_ATOMIC); 355 356 memset(&priv->roc_cfg, 0, sizeof(struct mwifiex_roc_cfg)); 357 358 mwifiex_dbg(priv->adapter, INFO, 359 "info: cancel ROC, cookie = 0x%llx\n", cookie); 360 } 361 362 return ret; 363 } 364 365 /* 366 * CFG802.11 operation handler to set Tx power. 367 */ 368 static int 369 mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy, 370 struct wireless_dev *wdev, 371 enum nl80211_tx_power_setting type, 372 int mbm) 373 { 374 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy); 375 struct mwifiex_private *priv; 376 struct mwifiex_power_cfg power_cfg; 377 int dbm = MBM_TO_DBM(mbm); 378 379 if (type == NL80211_TX_POWER_FIXED) { 380 power_cfg.is_power_auto = 0; 381 power_cfg.power_level = dbm; 382 } else { 383 power_cfg.is_power_auto = 1; 384 } 385 386 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); 387 388 return mwifiex_set_tx_power(priv, &power_cfg); 389 } 390 391 /* 392 * CFG802.11 operation handler to get Tx power. 393 */ 394 static int 395 mwifiex_cfg80211_get_tx_power(struct wiphy *wiphy, 396 struct wireless_dev *wdev, 397 int *dbm) 398 { 399 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy); 400 struct mwifiex_private *priv = mwifiex_get_priv(adapter, 401 MWIFIEX_BSS_ROLE_ANY); 402 int ret = mwifiex_send_cmd(priv, HostCmd_CMD_RF_TX_PWR, 403 HostCmd_ACT_GEN_GET, 0, NULL, true); 404 405 if (ret < 0) 406 return ret; 407 408 /* tx_power_level is set in HostCmd_CMD_RF_TX_PWR command handler */ 409 *dbm = priv->tx_power_level; 410 411 return 0; 412 } 413 414 /* 415 * CFG802.11 operation handler to set Power Save option. 416 * 417 * The timeout value, if provided, is currently ignored. 418 */ 419 static int 420 mwifiex_cfg80211_set_power_mgmt(struct wiphy *wiphy, 421 struct net_device *dev, 422 bool enabled, int timeout) 423 { 424 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 425 u32 ps_mode; 426 427 if (timeout) 428 mwifiex_dbg(priv->adapter, INFO, 429 "info: ignore timeout value for IEEE Power Save\n"); 430 431 ps_mode = enabled; 432 433 return mwifiex_drv_set_power(priv, &ps_mode); 434 } 435 436 /* 437 * CFG802.11 operation handler to set the default network key. 438 */ 439 static int 440 mwifiex_cfg80211_set_default_key(struct wiphy *wiphy, struct net_device *netdev, 441 u8 key_index, bool unicast, 442 bool multicast) 443 { 444 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev); 445 446 /* Return if WEP key not configured */ 447 if (!priv->sec_info.wep_enabled) 448 return 0; 449 450 if (priv->bss_type == MWIFIEX_BSS_TYPE_UAP) { 451 priv->wep_key_curr_index = key_index; 452 } else if (mwifiex_set_encode(priv, NULL, NULL, 0, key_index, 453 NULL, 0)) { 454 mwifiex_dbg(priv->adapter, ERROR, "set default Tx key index\n"); 455 return -EFAULT; 456 } 457 458 return 0; 459 } 460 461 /* 462 * CFG802.11 operation handler to add a network key. 463 */ 464 static int 465 mwifiex_cfg80211_add_key(struct wiphy *wiphy, struct net_device *netdev, 466 u8 key_index, bool pairwise, const u8 *mac_addr, 467 struct key_params *params) 468 { 469 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev); 470 struct mwifiex_wep_key *wep_key; 471 static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 472 const u8 *peer_mac = pairwise ? mac_addr : bc_mac; 473 474 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP && 475 (params->cipher == WLAN_CIPHER_SUITE_WEP40 || 476 params->cipher == WLAN_CIPHER_SUITE_WEP104)) { 477 if (params->key && params->key_len) { 478 wep_key = &priv->wep_key[key_index]; 479 memset(wep_key, 0, sizeof(struct mwifiex_wep_key)); 480 memcpy(wep_key->key_material, params->key, 481 params->key_len); 482 wep_key->key_index = key_index; 483 wep_key->key_length = params->key_len; 484 priv->sec_info.wep_enabled = 1; 485 } 486 return 0; 487 } 488 489 if (mwifiex_set_encode(priv, params, params->key, params->key_len, 490 key_index, peer_mac, 0)) { 491 mwifiex_dbg(priv->adapter, ERROR, "crypto keys added\n"); 492 return -EFAULT; 493 } 494 495 return 0; 496 } 497 498 /* 499 * CFG802.11 operation handler to set default mgmt key. 500 */ 501 static int 502 mwifiex_cfg80211_set_default_mgmt_key(struct wiphy *wiphy, 503 struct net_device *netdev, 504 u8 key_index) 505 { 506 struct mwifiex_private *priv = mwifiex_netdev_get_priv(netdev); 507 struct mwifiex_ds_encrypt_key encrypt_key; 508 509 wiphy_dbg(wiphy, "set default mgmt key, key index=%d\n", key_index); 510 511 memset(&encrypt_key, 0, sizeof(struct mwifiex_ds_encrypt_key)); 512 encrypt_key.key_len = WLAN_KEY_LEN_CCMP; 513 encrypt_key.key_index = key_index; 514 encrypt_key.is_igtk_def_key = true; 515 eth_broadcast_addr(encrypt_key.mac_addr); 516 517 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_KEY_MATERIAL, 518 HostCmd_ACT_GEN_SET, true, &encrypt_key, true); 519 } 520 521 /* 522 * This function sends domain information to the firmware. 523 * 524 * The following information are passed to the firmware - 525 * - Country codes 526 * - Sub bands (first channel, number of channels, maximum Tx power) 527 */ 528 int mwifiex_send_domain_info_cmd_fw(struct wiphy *wiphy) 529 { 530 u8 no_of_triplet = 0; 531 struct ieee80211_country_ie_triplet *t; 532 u8 no_of_parsed_chan = 0; 533 u8 first_chan = 0, next_chan = 0, max_pwr = 0; 534 u8 i, flag = 0; 535 enum nl80211_band band; 536 struct ieee80211_supported_band *sband; 537 struct ieee80211_channel *ch; 538 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy); 539 struct mwifiex_private *priv; 540 struct mwifiex_802_11d_domain_reg *domain_info = &adapter->domain_reg; 541 542 /* Set country code */ 543 domain_info->country_code[0] = adapter->country_code[0]; 544 domain_info->country_code[1] = adapter->country_code[1]; 545 domain_info->country_code[2] = ' '; 546 547 band = mwifiex_band_to_radio_type(adapter->config_bands); 548 if (!wiphy->bands[band]) { 549 mwifiex_dbg(adapter, ERROR, 550 "11D: setting domain info in FW\n"); 551 return -1; 552 } 553 554 sband = wiphy->bands[band]; 555 556 for (i = 0; i < sband->n_channels ; i++) { 557 ch = &sband->channels[i]; 558 if (ch->flags & IEEE80211_CHAN_DISABLED) 559 continue; 560 561 if (!flag) { 562 flag = 1; 563 first_chan = (u32) ch->hw_value; 564 next_chan = first_chan; 565 max_pwr = ch->max_power; 566 no_of_parsed_chan = 1; 567 continue; 568 } 569 570 if (ch->hw_value == next_chan + 1 && 571 ch->max_power == max_pwr) { 572 next_chan++; 573 no_of_parsed_chan++; 574 } else { 575 t = &domain_info->triplet[no_of_triplet]; 576 t->chans.first_channel = first_chan; 577 t->chans.num_channels = no_of_parsed_chan; 578 t->chans.max_power = max_pwr; 579 no_of_triplet++; 580 first_chan = (u32) ch->hw_value; 581 next_chan = first_chan; 582 max_pwr = ch->max_power; 583 no_of_parsed_chan = 1; 584 } 585 } 586 587 if (flag) { 588 t = &domain_info->triplet[no_of_triplet]; 589 t->chans.first_channel = first_chan; 590 t->chans.num_channels = no_of_parsed_chan; 591 t->chans.max_power = max_pwr; 592 no_of_triplet++; 593 } 594 595 domain_info->no_of_triplet = no_of_triplet; 596 597 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); 598 599 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11D_DOMAIN_INFO, 600 HostCmd_ACT_GEN_SET, 0, NULL, false)) { 601 mwifiex_dbg(adapter, INFO, 602 "11D: setting domain info in FW\n"); 603 return -1; 604 } 605 606 return 0; 607 } 608 609 static void mwifiex_reg_apply_radar_flags(struct wiphy *wiphy) 610 { 611 struct ieee80211_supported_band *sband; 612 struct ieee80211_channel *chan; 613 unsigned int i; 614 615 if (!wiphy->bands[NL80211_BAND_5GHZ]) 616 return; 617 sband = wiphy->bands[NL80211_BAND_5GHZ]; 618 619 for (i = 0; i < sband->n_channels; i++) { 620 chan = &sband->channels[i]; 621 if ((!(chan->flags & IEEE80211_CHAN_DISABLED)) && 622 (chan->flags & IEEE80211_CHAN_RADAR)) 623 chan->flags |= IEEE80211_CHAN_NO_IR; 624 } 625 } 626 627 /* 628 * CFG802.11 regulatory domain callback function. 629 * 630 * This function is called when the regulatory domain is changed due to the 631 * following reasons - 632 * - Set by driver 633 * - Set by system core 634 * - Set by user 635 * - Set bt Country IE 636 */ 637 static void mwifiex_reg_notifier(struct wiphy *wiphy, 638 struct regulatory_request *request) 639 { 640 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy); 641 struct mwifiex_private *priv = mwifiex_get_priv(adapter, 642 MWIFIEX_BSS_ROLE_ANY); 643 mwifiex_dbg(adapter, INFO, 644 "info: cfg80211 regulatory domain callback for %c%c\n", 645 request->alpha2[0], request->alpha2[1]); 646 mwifiex_reg_apply_radar_flags(wiphy); 647 648 switch (request->initiator) { 649 case NL80211_REGDOM_SET_BY_DRIVER: 650 case NL80211_REGDOM_SET_BY_CORE: 651 case NL80211_REGDOM_SET_BY_USER: 652 case NL80211_REGDOM_SET_BY_COUNTRY_IE: 653 break; 654 default: 655 mwifiex_dbg(adapter, ERROR, 656 "unknown regdom initiator: %d\n", 657 request->initiator); 658 return; 659 } 660 661 /* Don't send world or same regdom info to firmware */ 662 if (strncmp(request->alpha2, "00", 2) && 663 strncmp(request->alpha2, adapter->country_code, 664 sizeof(request->alpha2))) { 665 memcpy(adapter->country_code, request->alpha2, 666 sizeof(request->alpha2)); 667 mwifiex_send_domain_info_cmd_fw(wiphy); 668 mwifiex_dnld_txpwr_table(priv); 669 } 670 } 671 672 /* 673 * This function sets the fragmentation threshold. 674 * 675 * The fragmentation threshold value must lie between MWIFIEX_FRAG_MIN_VALUE 676 * and MWIFIEX_FRAG_MAX_VALUE. 677 */ 678 static int 679 mwifiex_set_frag(struct mwifiex_private *priv, u32 frag_thr) 680 { 681 if (frag_thr < MWIFIEX_FRAG_MIN_VALUE || 682 frag_thr > MWIFIEX_FRAG_MAX_VALUE) 683 frag_thr = MWIFIEX_FRAG_MAX_VALUE; 684 685 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB, 686 HostCmd_ACT_GEN_SET, FRAG_THRESH_I, 687 &frag_thr, true); 688 } 689 690 /* 691 * This function sets the RTS threshold. 692 693 * The rts value must lie between MWIFIEX_RTS_MIN_VALUE 694 * and MWIFIEX_RTS_MAX_VALUE. 695 */ 696 static int 697 mwifiex_set_rts(struct mwifiex_private *priv, u32 rts_thr) 698 { 699 if (rts_thr < MWIFIEX_RTS_MIN_VALUE || rts_thr > MWIFIEX_RTS_MAX_VALUE) 700 rts_thr = MWIFIEX_RTS_MAX_VALUE; 701 702 return mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB, 703 HostCmd_ACT_GEN_SET, RTS_THRESH_I, 704 &rts_thr, true); 705 } 706 707 /* 708 * CFG802.11 operation handler to set wiphy parameters. 709 * 710 * This function can be used to set the RTS threshold and the 711 * Fragmentation threshold of the driver. 712 */ 713 static int 714 mwifiex_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) 715 { 716 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy); 717 struct mwifiex_private *priv; 718 struct mwifiex_uap_bss_param *bss_cfg; 719 int ret; 720 721 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY); 722 723 switch (priv->bss_role) { 724 case MWIFIEX_BSS_ROLE_UAP: 725 if (priv->bss_started) { 726 mwifiex_dbg(adapter, ERROR, 727 "cannot change wiphy params when bss started"); 728 return -EINVAL; 729 } 730 731 bss_cfg = kzalloc(sizeof(*bss_cfg), GFP_KERNEL); 732 if (!bss_cfg) 733 return -ENOMEM; 734 735 mwifiex_set_sys_config_invalid_data(bss_cfg); 736 737 if (changed & WIPHY_PARAM_RTS_THRESHOLD) 738 bss_cfg->rts_threshold = wiphy->rts_threshold; 739 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) 740 bss_cfg->frag_threshold = wiphy->frag_threshold; 741 if (changed & WIPHY_PARAM_RETRY_LONG) 742 bss_cfg->retry_limit = wiphy->retry_long; 743 744 ret = mwifiex_send_cmd(priv, HostCmd_CMD_UAP_SYS_CONFIG, 745 HostCmd_ACT_GEN_SET, 746 UAP_BSS_PARAMS_I, bss_cfg, 747 false); 748 749 kfree(bss_cfg); 750 if (ret) { 751 mwifiex_dbg(adapter, ERROR, 752 "Failed to set wiphy phy params\n"); 753 return ret; 754 } 755 break; 756 757 case MWIFIEX_BSS_ROLE_STA: 758 if (priv->media_connected) { 759 mwifiex_dbg(adapter, ERROR, 760 "cannot change wiphy params when connected"); 761 return -EINVAL; 762 } 763 if (changed & WIPHY_PARAM_RTS_THRESHOLD) { 764 ret = mwifiex_set_rts(priv, 765 wiphy->rts_threshold); 766 if (ret) 767 return ret; 768 } 769 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) { 770 ret = mwifiex_set_frag(priv, 771 wiphy->frag_threshold); 772 if (ret) 773 return ret; 774 } 775 break; 776 } 777 778 return 0; 779 } 780 781 static int 782 mwifiex_cfg80211_deinit_p2p(struct mwifiex_private *priv) 783 { 784 u16 mode = P2P_MODE_DISABLE; 785 786 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG, 787 HostCmd_ACT_GEN_SET, 0, &mode, true)) 788 return -1; 789 790 return 0; 791 } 792 793 /* 794 * This function initializes the functionalities for P2P client. 795 * The P2P client initialization sequence is: 796 * disable -> device -> client 797 */ 798 static int 799 mwifiex_cfg80211_init_p2p_client(struct mwifiex_private *priv) 800 { 801 u16 mode; 802 803 if (mwifiex_cfg80211_deinit_p2p(priv)) 804 return -1; 805 806 mode = P2P_MODE_DEVICE; 807 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG, 808 HostCmd_ACT_GEN_SET, 0, &mode, true)) 809 return -1; 810 811 mode = P2P_MODE_CLIENT; 812 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG, 813 HostCmd_ACT_GEN_SET, 0, &mode, true)) 814 return -1; 815 816 return 0; 817 } 818 819 /* 820 * This function initializes the functionalities for P2P GO. 821 * The P2P GO initialization sequence is: 822 * disable -> device -> GO 823 */ 824 static int 825 mwifiex_cfg80211_init_p2p_go(struct mwifiex_private *priv) 826 { 827 u16 mode; 828 829 if (mwifiex_cfg80211_deinit_p2p(priv)) 830 return -1; 831 832 mode = P2P_MODE_DEVICE; 833 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG, 834 HostCmd_ACT_GEN_SET, 0, &mode, true)) 835 return -1; 836 837 mode = P2P_MODE_GO; 838 if (mwifiex_send_cmd(priv, HostCmd_CMD_P2P_MODE_CFG, 839 HostCmd_ACT_GEN_SET, 0, &mode, true)) 840 return -1; 841 842 return 0; 843 } 844 845 static int mwifiex_deinit_priv_params(struct mwifiex_private *priv) 846 { 847 struct mwifiex_adapter *adapter = priv->adapter; 848 unsigned long flags; 849 850 priv->mgmt_frame_mask = 0; 851 if (mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG, 852 HostCmd_ACT_GEN_SET, 0, 853 &priv->mgmt_frame_mask, false)) { 854 mwifiex_dbg(adapter, ERROR, 855 "could not unregister mgmt frame rx\n"); 856 return -1; 857 } 858 859 mwifiex_deauthenticate(priv, NULL); 860 861 spin_lock_irqsave(&adapter->main_proc_lock, flags); 862 adapter->main_locked = true; 863 if (adapter->mwifiex_processing) { 864 spin_unlock_irqrestore(&adapter->main_proc_lock, flags); 865 flush_workqueue(adapter->workqueue); 866 } else { 867 spin_unlock_irqrestore(&adapter->main_proc_lock, flags); 868 } 869 870 spin_lock_irqsave(&adapter->rx_proc_lock, flags); 871 adapter->rx_locked = true; 872 if (adapter->rx_processing) { 873 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags); 874 flush_workqueue(adapter->rx_workqueue); 875 } else { 876 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags); 877 } 878 879 mwifiex_free_priv(priv); 880 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED; 881 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED; 882 priv->sec_info.authentication_mode = NL80211_AUTHTYPE_OPEN_SYSTEM; 883 884 return 0; 885 } 886 887 static int 888 mwifiex_init_new_priv_params(struct mwifiex_private *priv, 889 struct net_device *dev, 890 enum nl80211_iftype type) 891 { 892 struct mwifiex_adapter *adapter = priv->adapter; 893 unsigned long flags; 894 895 mwifiex_init_priv(priv); 896 897 priv->bss_mode = type; 898 priv->wdev.iftype = type; 899 900 mwifiex_init_priv_params(priv, priv->netdev); 901 priv->bss_started = 0; 902 903 switch (type) { 904 case NL80211_IFTYPE_STATION: 905 case NL80211_IFTYPE_ADHOC: 906 priv->bss_role = MWIFIEX_BSS_ROLE_STA; 907 break; 908 case NL80211_IFTYPE_P2P_CLIENT: 909 priv->bss_role = MWIFIEX_BSS_ROLE_STA; 910 break; 911 case NL80211_IFTYPE_P2P_GO: 912 priv->bss_role = MWIFIEX_BSS_ROLE_UAP; 913 break; 914 case NL80211_IFTYPE_AP: 915 priv->bss_role = MWIFIEX_BSS_ROLE_UAP; 916 break; 917 default: 918 mwifiex_dbg(adapter, ERROR, 919 "%s: changing to %d not supported\n", 920 dev->name, type); 921 return -EOPNOTSUPP; 922 } 923 924 spin_lock_irqsave(&adapter->main_proc_lock, flags); 925 adapter->main_locked = false; 926 spin_unlock_irqrestore(&adapter->main_proc_lock, flags); 927 928 spin_lock_irqsave(&adapter->rx_proc_lock, flags); 929 adapter->rx_locked = false; 930 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags); 931 932 mwifiex_set_mac_address(priv, dev, false, NULL); 933 934 return 0; 935 } 936 937 static int 938 mwifiex_change_vif_to_p2p(struct net_device *dev, 939 enum nl80211_iftype curr_iftype, 940 enum nl80211_iftype type, 941 struct vif_params *params) 942 { 943 struct mwifiex_private *priv; 944 struct mwifiex_adapter *adapter; 945 946 priv = mwifiex_netdev_get_priv(dev); 947 948 if (!priv) 949 return -1; 950 951 adapter = priv->adapter; 952 953 if (adapter->curr_iface_comb.p2p_intf == 954 adapter->iface_limit.p2p_intf) { 955 mwifiex_dbg(adapter, ERROR, 956 "cannot create multiple P2P ifaces\n"); 957 return -1; 958 } 959 960 mwifiex_dbg(adapter, INFO, 961 "%s: changing role to p2p\n", dev->name); 962 963 if (mwifiex_deinit_priv_params(priv)) 964 return -1; 965 if (mwifiex_init_new_priv_params(priv, dev, type)) 966 return -1; 967 968 switch (type) { 969 case NL80211_IFTYPE_P2P_CLIENT: 970 if (mwifiex_cfg80211_init_p2p_client(priv)) 971 return -EFAULT; 972 break; 973 case NL80211_IFTYPE_P2P_GO: 974 if (mwifiex_cfg80211_init_p2p_go(priv)) 975 return -EFAULT; 976 break; 977 default: 978 mwifiex_dbg(adapter, ERROR, 979 "%s: changing to %d not supported\n", 980 dev->name, type); 981 return -EOPNOTSUPP; 982 } 983 984 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE, 985 HostCmd_ACT_GEN_SET, 0, NULL, true)) 986 return -1; 987 988 if (mwifiex_sta_init_cmd(priv, false, false)) 989 return -1; 990 991 switch (curr_iftype) { 992 case NL80211_IFTYPE_STATION: 993 case NL80211_IFTYPE_ADHOC: 994 adapter->curr_iface_comb.sta_intf--; 995 break; 996 case NL80211_IFTYPE_AP: 997 adapter->curr_iface_comb.uap_intf--; 998 break; 999 default: 1000 break; 1001 } 1002 1003 adapter->curr_iface_comb.p2p_intf++; 1004 dev->ieee80211_ptr->iftype = type; 1005 1006 return 0; 1007 } 1008 1009 static int 1010 mwifiex_change_vif_to_sta_adhoc(struct net_device *dev, 1011 enum nl80211_iftype curr_iftype, 1012 enum nl80211_iftype type, 1013 struct vif_params *params) 1014 { 1015 struct mwifiex_private *priv; 1016 struct mwifiex_adapter *adapter; 1017 1018 priv = mwifiex_netdev_get_priv(dev); 1019 1020 if (!priv) 1021 return -1; 1022 1023 adapter = priv->adapter; 1024 1025 if ((curr_iftype != NL80211_IFTYPE_P2P_CLIENT && 1026 curr_iftype != NL80211_IFTYPE_P2P_GO) && 1027 (adapter->curr_iface_comb.sta_intf == 1028 adapter->iface_limit.sta_intf)) { 1029 mwifiex_dbg(adapter, ERROR, 1030 "cannot create multiple station/adhoc ifaces\n"); 1031 return -1; 1032 } 1033 1034 if (type == NL80211_IFTYPE_STATION) 1035 mwifiex_dbg(adapter, INFO, 1036 "%s: changing role to station\n", dev->name); 1037 else 1038 mwifiex_dbg(adapter, INFO, 1039 "%s: changing role to adhoc\n", dev->name); 1040 1041 if (mwifiex_deinit_priv_params(priv)) 1042 return -1; 1043 if (mwifiex_init_new_priv_params(priv, dev, type)) 1044 return -1; 1045 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE, 1046 HostCmd_ACT_GEN_SET, 0, NULL, true)) 1047 return -1; 1048 if (mwifiex_sta_init_cmd(priv, false, false)) 1049 return -1; 1050 1051 switch (curr_iftype) { 1052 case NL80211_IFTYPE_P2P_CLIENT: 1053 case NL80211_IFTYPE_P2P_GO: 1054 adapter->curr_iface_comb.p2p_intf--; 1055 break; 1056 case NL80211_IFTYPE_AP: 1057 adapter->curr_iface_comb.uap_intf--; 1058 break; 1059 default: 1060 break; 1061 } 1062 1063 adapter->curr_iface_comb.sta_intf++; 1064 dev->ieee80211_ptr->iftype = type; 1065 return 0; 1066 } 1067 1068 static int 1069 mwifiex_change_vif_to_ap(struct net_device *dev, 1070 enum nl80211_iftype curr_iftype, 1071 enum nl80211_iftype type, 1072 struct vif_params *params) 1073 { 1074 struct mwifiex_private *priv; 1075 struct mwifiex_adapter *adapter; 1076 1077 priv = mwifiex_netdev_get_priv(dev); 1078 1079 if (!priv) 1080 return -1; 1081 1082 adapter = priv->adapter; 1083 1084 if (adapter->curr_iface_comb.uap_intf == 1085 adapter->iface_limit.uap_intf) { 1086 mwifiex_dbg(adapter, ERROR, 1087 "cannot create multiple AP ifaces\n"); 1088 return -1; 1089 } 1090 1091 mwifiex_dbg(adapter, INFO, 1092 "%s: changing role to AP\n", dev->name); 1093 1094 if (mwifiex_deinit_priv_params(priv)) 1095 return -1; 1096 if (mwifiex_init_new_priv_params(priv, dev, type)) 1097 return -1; 1098 if (mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE, 1099 HostCmd_ACT_GEN_SET, 0, NULL, true)) 1100 return -1; 1101 if (mwifiex_sta_init_cmd(priv, false, false)) 1102 return -1; 1103 1104 switch (curr_iftype) { 1105 case NL80211_IFTYPE_P2P_CLIENT: 1106 case NL80211_IFTYPE_P2P_GO: 1107 adapter->curr_iface_comb.p2p_intf--; 1108 break; 1109 case NL80211_IFTYPE_STATION: 1110 case NL80211_IFTYPE_ADHOC: 1111 adapter->curr_iface_comb.sta_intf--; 1112 break; 1113 default: 1114 break; 1115 } 1116 1117 adapter->curr_iface_comb.uap_intf++; 1118 dev->ieee80211_ptr->iftype = type; 1119 return 0; 1120 } 1121 /* 1122 * CFG802.11 operation handler to change interface type. 1123 */ 1124 static int 1125 mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy, 1126 struct net_device *dev, 1127 enum nl80211_iftype type, 1128 struct vif_params *params) 1129 { 1130 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 1131 enum nl80211_iftype curr_iftype = dev->ieee80211_ptr->iftype; 1132 1133 if (priv->scan_request) { 1134 mwifiex_dbg(priv->adapter, ERROR, 1135 "change virtual interface: scan in process\n"); 1136 return -EBUSY; 1137 } 1138 1139 switch (curr_iftype) { 1140 case NL80211_IFTYPE_ADHOC: 1141 switch (type) { 1142 case NL80211_IFTYPE_STATION: 1143 priv->bss_mode = type; 1144 priv->sec_info.authentication_mode = 1145 NL80211_AUTHTYPE_OPEN_SYSTEM; 1146 dev->ieee80211_ptr->iftype = type; 1147 mwifiex_deauthenticate(priv, NULL); 1148 return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE, 1149 HostCmd_ACT_GEN_SET, 0, NULL, 1150 true); 1151 case NL80211_IFTYPE_P2P_CLIENT: 1152 case NL80211_IFTYPE_P2P_GO: 1153 return mwifiex_change_vif_to_p2p(dev, curr_iftype, 1154 type, params); 1155 case NL80211_IFTYPE_AP: 1156 return mwifiex_change_vif_to_ap(dev, curr_iftype, type, 1157 params); 1158 case NL80211_IFTYPE_UNSPECIFIED: 1159 mwifiex_dbg(priv->adapter, INFO, 1160 "%s: kept type as IBSS\n", dev->name); 1161 /* fall through */ 1162 case NL80211_IFTYPE_ADHOC: /* This shouldn't happen */ 1163 return 0; 1164 default: 1165 mwifiex_dbg(priv->adapter, ERROR, 1166 "%s: changing to %d not supported\n", 1167 dev->name, type); 1168 return -EOPNOTSUPP; 1169 } 1170 break; 1171 case NL80211_IFTYPE_STATION: 1172 switch (type) { 1173 case NL80211_IFTYPE_ADHOC: 1174 priv->bss_mode = type; 1175 priv->sec_info.authentication_mode = 1176 NL80211_AUTHTYPE_OPEN_SYSTEM; 1177 dev->ieee80211_ptr->iftype = type; 1178 mwifiex_deauthenticate(priv, NULL); 1179 return mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE, 1180 HostCmd_ACT_GEN_SET, 0, NULL, 1181 true); 1182 case NL80211_IFTYPE_P2P_CLIENT: 1183 case NL80211_IFTYPE_P2P_GO: 1184 return mwifiex_change_vif_to_p2p(dev, curr_iftype, 1185 type, params); 1186 case NL80211_IFTYPE_AP: 1187 return mwifiex_change_vif_to_ap(dev, curr_iftype, type, 1188 params); 1189 case NL80211_IFTYPE_UNSPECIFIED: 1190 mwifiex_dbg(priv->adapter, INFO, 1191 "%s: kept type as STA\n", dev->name); 1192 /* fall through */ 1193 case NL80211_IFTYPE_STATION: /* This shouldn't happen */ 1194 return 0; 1195 default: 1196 mwifiex_dbg(priv->adapter, ERROR, 1197 "%s: changing to %d not supported\n", 1198 dev->name, type); 1199 return -EOPNOTSUPP; 1200 } 1201 break; 1202 case NL80211_IFTYPE_AP: 1203 switch (type) { 1204 case NL80211_IFTYPE_ADHOC: 1205 return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype, 1206 type, params); 1207 break; 1208 case NL80211_IFTYPE_P2P_CLIENT: 1209 case NL80211_IFTYPE_P2P_GO: 1210 return mwifiex_change_vif_to_p2p(dev, curr_iftype, 1211 type, params); 1212 case NL80211_IFTYPE_UNSPECIFIED: 1213 mwifiex_dbg(priv->adapter, INFO, 1214 "%s: kept type as AP\n", dev->name); 1215 /* fall through */ 1216 case NL80211_IFTYPE_AP: /* This shouldn't happen */ 1217 return 0; 1218 default: 1219 mwifiex_dbg(priv->adapter, ERROR, 1220 "%s: changing to %d not supported\n", 1221 dev->name, type); 1222 return -EOPNOTSUPP; 1223 } 1224 break; 1225 case NL80211_IFTYPE_P2P_CLIENT: 1226 case NL80211_IFTYPE_P2P_GO: 1227 switch (type) { 1228 case NL80211_IFTYPE_STATION: 1229 if (mwifiex_cfg80211_deinit_p2p(priv)) 1230 return -EFAULT; 1231 priv->adapter->curr_iface_comb.p2p_intf--; 1232 priv->adapter->curr_iface_comb.sta_intf++; 1233 dev->ieee80211_ptr->iftype = type; 1234 if (mwifiex_deinit_priv_params(priv)) 1235 return -1; 1236 if (mwifiex_init_new_priv_params(priv, dev, type)) 1237 return -1; 1238 if (mwifiex_sta_init_cmd(priv, false, false)) 1239 return -1; 1240 break; 1241 case NL80211_IFTYPE_ADHOC: 1242 if (mwifiex_cfg80211_deinit_p2p(priv)) 1243 return -EFAULT; 1244 return mwifiex_change_vif_to_sta_adhoc(dev, curr_iftype, 1245 type, params); 1246 break; 1247 case NL80211_IFTYPE_AP: 1248 if (mwifiex_cfg80211_deinit_p2p(priv)) 1249 return -EFAULT; 1250 return mwifiex_change_vif_to_ap(dev, curr_iftype, type, 1251 params); 1252 case NL80211_IFTYPE_UNSPECIFIED: 1253 mwifiex_dbg(priv->adapter, INFO, 1254 "%s: kept type as P2P\n", dev->name); 1255 /* fall through */ 1256 case NL80211_IFTYPE_P2P_CLIENT: 1257 case NL80211_IFTYPE_P2P_GO: 1258 return 0; 1259 default: 1260 mwifiex_dbg(priv->adapter, ERROR, 1261 "%s: changing to %d not supported\n", 1262 dev->name, type); 1263 return -EOPNOTSUPP; 1264 } 1265 break; 1266 default: 1267 mwifiex_dbg(priv->adapter, ERROR, 1268 "%s: unknown iftype: %d\n", 1269 dev->name, dev->ieee80211_ptr->iftype); 1270 return -EOPNOTSUPP; 1271 } 1272 1273 1274 return 0; 1275 } 1276 1277 static void 1278 mwifiex_parse_htinfo(struct mwifiex_private *priv, u8 rateinfo, u8 htinfo, 1279 struct rate_info *rate) 1280 { 1281 struct mwifiex_adapter *adapter = priv->adapter; 1282 1283 if (adapter->is_hw_11ac_capable) { 1284 /* bit[1-0]: 00=LG 01=HT 10=VHT */ 1285 if (htinfo & BIT(0)) { 1286 /* HT */ 1287 rate->mcs = rateinfo; 1288 rate->flags |= RATE_INFO_FLAGS_MCS; 1289 } 1290 if (htinfo & BIT(1)) { 1291 /* VHT */ 1292 rate->mcs = rateinfo & 0x0F; 1293 rate->flags |= RATE_INFO_FLAGS_VHT_MCS; 1294 } 1295 1296 if (htinfo & (BIT(1) | BIT(0))) { 1297 /* HT or VHT */ 1298 switch (htinfo & (BIT(3) | BIT(2))) { 1299 case 0: 1300 rate->bw = RATE_INFO_BW_20; 1301 break; 1302 case (BIT(2)): 1303 rate->bw = RATE_INFO_BW_40; 1304 break; 1305 case (BIT(3)): 1306 rate->bw = RATE_INFO_BW_80; 1307 break; 1308 case (BIT(3) | BIT(2)): 1309 rate->bw = RATE_INFO_BW_160; 1310 break; 1311 } 1312 1313 if (htinfo & BIT(4)) 1314 rate->flags |= RATE_INFO_FLAGS_SHORT_GI; 1315 1316 if ((rateinfo >> 4) == 1) 1317 rate->nss = 2; 1318 else 1319 rate->nss = 1; 1320 } 1321 } else { 1322 /* 1323 * Bit 0 in htinfo indicates that current rate is 11n. Valid 1324 * MCS index values for us are 0 to 15. 1325 */ 1326 if ((htinfo & BIT(0)) && (rateinfo < 16)) { 1327 rate->mcs = rateinfo; 1328 rate->flags |= RATE_INFO_FLAGS_MCS; 1329 rate->bw = RATE_INFO_BW_20; 1330 if (htinfo & BIT(1)) 1331 rate->bw = RATE_INFO_BW_40; 1332 if (htinfo & BIT(2)) 1333 rate->flags |= RATE_INFO_FLAGS_SHORT_GI; 1334 } 1335 } 1336 1337 /* Decode legacy rates for non-HT. */ 1338 if (!(htinfo & (BIT(0) | BIT(1)))) { 1339 /* Bitrates in multiples of 100kb/s. */ 1340 static const int legacy_rates[] = { 1341 [0] = 10, 1342 [1] = 20, 1343 [2] = 55, 1344 [3] = 110, 1345 [4] = 60, /* MWIFIEX_RATE_INDEX_OFDM0 */ 1346 [5] = 60, 1347 [6] = 90, 1348 [7] = 120, 1349 [8] = 180, 1350 [9] = 240, 1351 [10] = 360, 1352 [11] = 480, 1353 [12] = 540, 1354 }; 1355 if (rateinfo < ARRAY_SIZE(legacy_rates)) 1356 rate->legacy = legacy_rates[rateinfo]; 1357 } 1358 } 1359 1360 /* 1361 * This function dumps the station information on a buffer. 1362 * 1363 * The following information are shown - 1364 * - Total bytes transmitted 1365 * - Total bytes received 1366 * - Total packets transmitted 1367 * - Total packets received 1368 * - Signal quality level 1369 * - Transmission rate 1370 */ 1371 static int 1372 mwifiex_dump_station_info(struct mwifiex_private *priv, 1373 struct mwifiex_sta_node *node, 1374 struct station_info *sinfo) 1375 { 1376 u32 rate; 1377 1378 sinfo->filled = BIT_ULL(NL80211_STA_INFO_RX_BYTES) | BIT_ULL(NL80211_STA_INFO_TX_BYTES) | 1379 BIT_ULL(NL80211_STA_INFO_RX_PACKETS) | BIT_ULL(NL80211_STA_INFO_TX_PACKETS) | 1380 BIT_ULL(NL80211_STA_INFO_TX_BITRATE) | 1381 BIT_ULL(NL80211_STA_INFO_SIGNAL) | BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG); 1382 1383 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) { 1384 if (!node) 1385 return -ENOENT; 1386 1387 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME) | 1388 BIT_ULL(NL80211_STA_INFO_TX_FAILED); 1389 sinfo->inactive_time = 1390 jiffies_to_msecs(jiffies - node->stats.last_rx); 1391 1392 sinfo->signal = node->stats.rssi; 1393 sinfo->signal_avg = node->stats.rssi; 1394 sinfo->rx_bytes = node->stats.rx_bytes; 1395 sinfo->tx_bytes = node->stats.tx_bytes; 1396 sinfo->rx_packets = node->stats.rx_packets; 1397 sinfo->tx_packets = node->stats.tx_packets; 1398 sinfo->tx_failed = node->stats.tx_failed; 1399 1400 mwifiex_parse_htinfo(priv, priv->tx_rate, 1401 node->stats.last_tx_htinfo, 1402 &sinfo->txrate); 1403 sinfo->txrate.legacy = node->stats.last_tx_rate * 5; 1404 1405 return 0; 1406 } 1407 1408 /* Get signal information from the firmware */ 1409 if (mwifiex_send_cmd(priv, HostCmd_CMD_RSSI_INFO, 1410 HostCmd_ACT_GEN_GET, 0, NULL, true)) { 1411 mwifiex_dbg(priv->adapter, ERROR, 1412 "failed to get signal information\n"); 1413 return -EFAULT; 1414 } 1415 1416 if (mwifiex_drv_get_data_rate(priv, &rate)) { 1417 mwifiex_dbg(priv->adapter, ERROR, 1418 "getting data rate error\n"); 1419 return -EFAULT; 1420 } 1421 1422 /* Get DTIM period information from firmware */ 1423 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB, 1424 HostCmd_ACT_GEN_GET, DTIM_PERIOD_I, 1425 &priv->dtim_period, true); 1426 1427 mwifiex_parse_htinfo(priv, priv->tx_rate, priv->tx_htinfo, 1428 &sinfo->txrate); 1429 1430 sinfo->signal_avg = priv->bcn_rssi_avg; 1431 sinfo->rx_bytes = priv->stats.rx_bytes; 1432 sinfo->tx_bytes = priv->stats.tx_bytes; 1433 sinfo->rx_packets = priv->stats.rx_packets; 1434 sinfo->tx_packets = priv->stats.tx_packets; 1435 sinfo->signal = priv->bcn_rssi_avg; 1436 /* bit rate is in 500 kb/s units. Convert it to 100kb/s units */ 1437 sinfo->txrate.legacy = rate * 5; 1438 1439 sinfo->filled |= BIT(NL80211_STA_INFO_RX_BITRATE); 1440 mwifiex_parse_htinfo(priv, priv->rxpd_rate, priv->rxpd_htinfo, 1441 &sinfo->rxrate); 1442 1443 if (priv->bss_mode == NL80211_IFTYPE_STATION) { 1444 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BSS_PARAM); 1445 sinfo->bss_param.flags = 0; 1446 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap & 1447 WLAN_CAPABILITY_SHORT_PREAMBLE) 1448 sinfo->bss_param.flags |= 1449 BSS_PARAM_FLAGS_SHORT_PREAMBLE; 1450 if (priv->curr_bss_params.bss_descriptor.cap_info_bitmap & 1451 WLAN_CAPABILITY_SHORT_SLOT_TIME) 1452 sinfo->bss_param.flags |= 1453 BSS_PARAM_FLAGS_SHORT_SLOT_TIME; 1454 sinfo->bss_param.dtim_period = priv->dtim_period; 1455 sinfo->bss_param.beacon_interval = 1456 priv->curr_bss_params.bss_descriptor.beacon_period; 1457 } 1458 1459 return 0; 1460 } 1461 1462 /* 1463 * CFG802.11 operation handler to get station information. 1464 * 1465 * This function only works in connected mode, and dumps the 1466 * requested station information, if available. 1467 */ 1468 static int 1469 mwifiex_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev, 1470 const u8 *mac, struct station_info *sinfo) 1471 { 1472 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 1473 1474 if (!priv->media_connected) 1475 return -ENOENT; 1476 if (memcmp(mac, priv->cfg_bssid, ETH_ALEN)) 1477 return -ENOENT; 1478 1479 return mwifiex_dump_station_info(priv, NULL, sinfo); 1480 } 1481 1482 /* 1483 * CFG802.11 operation handler to dump station information. 1484 */ 1485 static int 1486 mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev, 1487 int idx, u8 *mac, struct station_info *sinfo) 1488 { 1489 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 1490 static struct mwifiex_sta_node *node; 1491 1492 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) && 1493 priv->media_connected && idx == 0) { 1494 ether_addr_copy(mac, priv->cfg_bssid); 1495 return mwifiex_dump_station_info(priv, NULL, sinfo); 1496 } else if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) { 1497 mwifiex_send_cmd(priv, HOST_CMD_APCMD_STA_LIST, 1498 HostCmd_ACT_GEN_GET, 0, NULL, true); 1499 1500 if (node && (&node->list == &priv->sta_list)) { 1501 node = NULL; 1502 return -ENOENT; 1503 } 1504 1505 node = list_prepare_entry(node, &priv->sta_list, list); 1506 list_for_each_entry_continue(node, &priv->sta_list, list) { 1507 ether_addr_copy(mac, node->mac_addr); 1508 return mwifiex_dump_station_info(priv, node, sinfo); 1509 } 1510 } 1511 1512 return -ENOENT; 1513 } 1514 1515 static int 1516 mwifiex_cfg80211_dump_survey(struct wiphy *wiphy, struct net_device *dev, 1517 int idx, struct survey_info *survey) 1518 { 1519 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 1520 struct mwifiex_chan_stats *pchan_stats = priv->adapter->chan_stats; 1521 enum nl80211_band band; 1522 1523 mwifiex_dbg(priv->adapter, DUMP, "dump_survey idx=%d\n", idx); 1524 1525 memset(survey, 0, sizeof(struct survey_info)); 1526 1527 if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) && 1528 priv->media_connected && idx == 0) { 1529 u8 curr_bss_band = priv->curr_bss_params.band; 1530 u32 chan = priv->curr_bss_params.bss_descriptor.channel; 1531 1532 band = mwifiex_band_to_radio_type(curr_bss_band); 1533 survey->channel = ieee80211_get_channel(wiphy, 1534 ieee80211_channel_to_frequency(chan, band)); 1535 1536 if (priv->bcn_nf_last) { 1537 survey->filled = SURVEY_INFO_NOISE_DBM; 1538 survey->noise = priv->bcn_nf_last; 1539 } 1540 return 0; 1541 } 1542 1543 if (idx >= priv->adapter->num_in_chan_stats) 1544 return -ENOENT; 1545 1546 if (!pchan_stats[idx].cca_scan_dur) 1547 return 0; 1548 1549 band = pchan_stats[idx].bandcfg; 1550 survey->channel = ieee80211_get_channel(wiphy, 1551 ieee80211_channel_to_frequency(pchan_stats[idx].chan_num, band)); 1552 survey->filled = SURVEY_INFO_NOISE_DBM | 1553 SURVEY_INFO_TIME | 1554 SURVEY_INFO_TIME_BUSY; 1555 survey->noise = pchan_stats[idx].noise; 1556 survey->time = pchan_stats[idx].cca_scan_dur; 1557 survey->time_busy = pchan_stats[idx].cca_busy_dur; 1558 1559 return 0; 1560 } 1561 1562 /* Supported rates to be advertised to the cfg80211 */ 1563 static struct ieee80211_rate mwifiex_rates[] = { 1564 {.bitrate = 10, .hw_value = 2, }, 1565 {.bitrate = 20, .hw_value = 4, }, 1566 {.bitrate = 55, .hw_value = 11, }, 1567 {.bitrate = 110, .hw_value = 22, }, 1568 {.bitrate = 60, .hw_value = 12, }, 1569 {.bitrate = 90, .hw_value = 18, }, 1570 {.bitrate = 120, .hw_value = 24, }, 1571 {.bitrate = 180, .hw_value = 36, }, 1572 {.bitrate = 240, .hw_value = 48, }, 1573 {.bitrate = 360, .hw_value = 72, }, 1574 {.bitrate = 480, .hw_value = 96, }, 1575 {.bitrate = 540, .hw_value = 108, }, 1576 }; 1577 1578 /* Channel definitions to be advertised to cfg80211 */ 1579 static struct ieee80211_channel mwifiex_channels_2ghz[] = { 1580 {.center_freq = 2412, .hw_value = 1, }, 1581 {.center_freq = 2417, .hw_value = 2, }, 1582 {.center_freq = 2422, .hw_value = 3, }, 1583 {.center_freq = 2427, .hw_value = 4, }, 1584 {.center_freq = 2432, .hw_value = 5, }, 1585 {.center_freq = 2437, .hw_value = 6, }, 1586 {.center_freq = 2442, .hw_value = 7, }, 1587 {.center_freq = 2447, .hw_value = 8, }, 1588 {.center_freq = 2452, .hw_value = 9, }, 1589 {.center_freq = 2457, .hw_value = 10, }, 1590 {.center_freq = 2462, .hw_value = 11, }, 1591 {.center_freq = 2467, .hw_value = 12, }, 1592 {.center_freq = 2472, .hw_value = 13, }, 1593 {.center_freq = 2484, .hw_value = 14, }, 1594 }; 1595 1596 static struct ieee80211_supported_band mwifiex_band_2ghz = { 1597 .channels = mwifiex_channels_2ghz, 1598 .n_channels = ARRAY_SIZE(mwifiex_channels_2ghz), 1599 .bitrates = mwifiex_rates, 1600 .n_bitrates = ARRAY_SIZE(mwifiex_rates), 1601 }; 1602 1603 static struct ieee80211_channel mwifiex_channels_5ghz[] = { 1604 {.center_freq = 5040, .hw_value = 8, }, 1605 {.center_freq = 5060, .hw_value = 12, }, 1606 {.center_freq = 5080, .hw_value = 16, }, 1607 {.center_freq = 5170, .hw_value = 34, }, 1608 {.center_freq = 5190, .hw_value = 38, }, 1609 {.center_freq = 5210, .hw_value = 42, }, 1610 {.center_freq = 5230, .hw_value = 46, }, 1611 {.center_freq = 5180, .hw_value = 36, }, 1612 {.center_freq = 5200, .hw_value = 40, }, 1613 {.center_freq = 5220, .hw_value = 44, }, 1614 {.center_freq = 5240, .hw_value = 48, }, 1615 {.center_freq = 5260, .hw_value = 52, }, 1616 {.center_freq = 5280, .hw_value = 56, }, 1617 {.center_freq = 5300, .hw_value = 60, }, 1618 {.center_freq = 5320, .hw_value = 64, }, 1619 {.center_freq = 5500, .hw_value = 100, }, 1620 {.center_freq = 5520, .hw_value = 104, }, 1621 {.center_freq = 5540, .hw_value = 108, }, 1622 {.center_freq = 5560, .hw_value = 112, }, 1623 {.center_freq = 5580, .hw_value = 116, }, 1624 {.center_freq = 5600, .hw_value = 120, }, 1625 {.center_freq = 5620, .hw_value = 124, }, 1626 {.center_freq = 5640, .hw_value = 128, }, 1627 {.center_freq = 5660, .hw_value = 132, }, 1628 {.center_freq = 5680, .hw_value = 136, }, 1629 {.center_freq = 5700, .hw_value = 140, }, 1630 {.center_freq = 5745, .hw_value = 149, }, 1631 {.center_freq = 5765, .hw_value = 153, }, 1632 {.center_freq = 5785, .hw_value = 157, }, 1633 {.center_freq = 5805, .hw_value = 161, }, 1634 {.center_freq = 5825, .hw_value = 165, }, 1635 }; 1636 1637 static struct ieee80211_supported_band mwifiex_band_5ghz = { 1638 .channels = mwifiex_channels_5ghz, 1639 .n_channels = ARRAY_SIZE(mwifiex_channels_5ghz), 1640 .bitrates = mwifiex_rates + 4, 1641 .n_bitrates = ARRAY_SIZE(mwifiex_rates) - 4, 1642 }; 1643 1644 1645 /* Supported crypto cipher suits to be advertised to cfg80211 */ 1646 static const u32 mwifiex_cipher_suites[] = { 1647 WLAN_CIPHER_SUITE_WEP40, 1648 WLAN_CIPHER_SUITE_WEP104, 1649 WLAN_CIPHER_SUITE_TKIP, 1650 WLAN_CIPHER_SUITE_CCMP, 1651 WLAN_CIPHER_SUITE_SMS4, 1652 WLAN_CIPHER_SUITE_AES_CMAC, 1653 }; 1654 1655 /* Supported mgmt frame types to be advertised to cfg80211 */ 1656 static const struct ieee80211_txrx_stypes 1657 mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES] = { 1658 [NL80211_IFTYPE_STATION] = { 1659 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | 1660 BIT(IEEE80211_STYPE_PROBE_RESP >> 4), 1661 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | 1662 BIT(IEEE80211_STYPE_PROBE_REQ >> 4), 1663 }, 1664 [NL80211_IFTYPE_AP] = { 1665 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | 1666 BIT(IEEE80211_STYPE_PROBE_RESP >> 4), 1667 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | 1668 BIT(IEEE80211_STYPE_PROBE_REQ >> 4), 1669 }, 1670 [NL80211_IFTYPE_P2P_CLIENT] = { 1671 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | 1672 BIT(IEEE80211_STYPE_PROBE_RESP >> 4), 1673 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | 1674 BIT(IEEE80211_STYPE_PROBE_REQ >> 4), 1675 }, 1676 [NL80211_IFTYPE_P2P_GO] = { 1677 .tx = BIT(IEEE80211_STYPE_ACTION >> 4) | 1678 BIT(IEEE80211_STYPE_PROBE_RESP >> 4), 1679 .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | 1680 BIT(IEEE80211_STYPE_PROBE_REQ >> 4), 1681 }, 1682 }; 1683 1684 /* 1685 * CFG802.11 operation handler for setting bit rates. 1686 * 1687 * Function configures data rates to firmware using bitrate mask 1688 * provided by cfg80211. 1689 */ 1690 static int mwifiex_cfg80211_set_bitrate_mask(struct wiphy *wiphy, 1691 struct net_device *dev, 1692 const u8 *peer, 1693 const struct cfg80211_bitrate_mask *mask) 1694 { 1695 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 1696 u16 bitmap_rates[MAX_BITMAP_RATES_SIZE]; 1697 enum nl80211_band band; 1698 struct mwifiex_adapter *adapter = priv->adapter; 1699 1700 if (!priv->media_connected) { 1701 mwifiex_dbg(adapter, ERROR, 1702 "Can not set Tx data rate in disconnected state\n"); 1703 return -EINVAL; 1704 } 1705 1706 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band); 1707 1708 memset(bitmap_rates, 0, sizeof(bitmap_rates)); 1709 1710 /* Fill HR/DSSS rates. */ 1711 if (band == NL80211_BAND_2GHZ) 1712 bitmap_rates[0] = mask->control[band].legacy & 0x000f; 1713 1714 /* Fill OFDM rates */ 1715 if (band == NL80211_BAND_2GHZ) 1716 bitmap_rates[1] = (mask->control[band].legacy & 0x0ff0) >> 4; 1717 else 1718 bitmap_rates[1] = mask->control[band].legacy; 1719 1720 /* Fill HT MCS rates */ 1721 bitmap_rates[2] = mask->control[band].ht_mcs[0]; 1722 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2) 1723 bitmap_rates[2] |= mask->control[band].ht_mcs[1] << 8; 1724 1725 /* Fill VHT MCS rates */ 1726 if (adapter->fw_api_ver == MWIFIEX_FW_V15) { 1727 bitmap_rates[10] = mask->control[band].vht_mcs[0]; 1728 if (adapter->hw_dev_mcs_support == HT_STREAM_2X2) 1729 bitmap_rates[11] = mask->control[band].vht_mcs[1]; 1730 } 1731 1732 return mwifiex_send_cmd(priv, HostCmd_CMD_TX_RATE_CFG, 1733 HostCmd_ACT_GEN_SET, 0, bitmap_rates, true); 1734 } 1735 1736 /* 1737 * CFG802.11 operation handler for connection quality monitoring. 1738 * 1739 * This function subscribes/unsubscribes HIGH_RSSI and LOW_RSSI 1740 * events to FW. 1741 */ 1742 static int mwifiex_cfg80211_set_cqm_rssi_config(struct wiphy *wiphy, 1743 struct net_device *dev, 1744 s32 rssi_thold, u32 rssi_hyst) 1745 { 1746 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 1747 struct mwifiex_ds_misc_subsc_evt subsc_evt; 1748 1749 priv->cqm_rssi_thold = rssi_thold; 1750 priv->cqm_rssi_hyst = rssi_hyst; 1751 1752 memset(&subsc_evt, 0x00, sizeof(struct mwifiex_ds_misc_subsc_evt)); 1753 subsc_evt.events = BITMASK_BCN_RSSI_LOW | BITMASK_BCN_RSSI_HIGH; 1754 1755 /* Subscribe/unsubscribe low and high rssi events */ 1756 if (rssi_thold && rssi_hyst) { 1757 subsc_evt.action = HostCmd_ACT_BITWISE_SET; 1758 subsc_evt.bcn_l_rssi_cfg.abs_value = abs(rssi_thold); 1759 subsc_evt.bcn_h_rssi_cfg.abs_value = abs(rssi_thold); 1760 subsc_evt.bcn_l_rssi_cfg.evt_freq = 1; 1761 subsc_evt.bcn_h_rssi_cfg.evt_freq = 1; 1762 return mwifiex_send_cmd(priv, 1763 HostCmd_CMD_802_11_SUBSCRIBE_EVENT, 1764 0, 0, &subsc_evt, true); 1765 } else { 1766 subsc_evt.action = HostCmd_ACT_BITWISE_CLR; 1767 return mwifiex_send_cmd(priv, 1768 HostCmd_CMD_802_11_SUBSCRIBE_EVENT, 1769 0, 0, &subsc_evt, true); 1770 } 1771 1772 return 0; 1773 } 1774 1775 /* cfg80211 operation handler for change_beacon. 1776 * Function retrieves and sets modified management IEs to FW. 1777 */ 1778 static int mwifiex_cfg80211_change_beacon(struct wiphy *wiphy, 1779 struct net_device *dev, 1780 struct cfg80211_beacon_data *data) 1781 { 1782 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 1783 struct mwifiex_adapter *adapter = priv->adapter; 1784 1785 mwifiex_cancel_scan(adapter); 1786 1787 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP) { 1788 mwifiex_dbg(priv->adapter, ERROR, 1789 "%s: bss_type mismatched\n", __func__); 1790 return -EINVAL; 1791 } 1792 1793 if (!priv->bss_started) { 1794 mwifiex_dbg(priv->adapter, ERROR, 1795 "%s: bss not started\n", __func__); 1796 return -EINVAL; 1797 } 1798 1799 if (mwifiex_set_mgmt_ies(priv, data)) { 1800 mwifiex_dbg(priv->adapter, ERROR, 1801 "%s: setting mgmt ies failed\n", __func__); 1802 return -EFAULT; 1803 } 1804 1805 return 0; 1806 } 1807 1808 /* cfg80211 operation handler for del_station. 1809 * Function deauthenticates station which value is provided in mac parameter. 1810 * If mac is NULL/broadcast, all stations in associated station list are 1811 * deauthenticated. If bss is not started or there are no stations in 1812 * associated stations list, no action is taken. 1813 */ 1814 static int 1815 mwifiex_cfg80211_del_station(struct wiphy *wiphy, struct net_device *dev, 1816 struct station_del_parameters *params) 1817 { 1818 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 1819 struct mwifiex_sta_node *sta_node; 1820 u8 deauth_mac[ETH_ALEN]; 1821 unsigned long flags; 1822 1823 if (!priv->bss_started && priv->wdev.cac_started) { 1824 mwifiex_dbg(priv->adapter, INFO, "%s: abort CAC!\n", __func__); 1825 mwifiex_abort_cac(priv); 1826 } 1827 1828 if (list_empty(&priv->sta_list) || !priv->bss_started) 1829 return 0; 1830 1831 if (!params->mac || is_broadcast_ether_addr(params->mac)) 1832 return 0; 1833 1834 mwifiex_dbg(priv->adapter, INFO, "%s: mac address %pM\n", 1835 __func__, params->mac); 1836 1837 eth_zero_addr(deauth_mac); 1838 1839 spin_lock_irqsave(&priv->sta_list_spinlock, flags); 1840 sta_node = mwifiex_get_sta_entry(priv, params->mac); 1841 if (sta_node) 1842 ether_addr_copy(deauth_mac, params->mac); 1843 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags); 1844 1845 if (is_valid_ether_addr(deauth_mac)) { 1846 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_STA_DEAUTH, 1847 HostCmd_ACT_GEN_SET, 0, 1848 deauth_mac, true)) 1849 return -1; 1850 } 1851 1852 return 0; 1853 } 1854 1855 static int 1856 mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant) 1857 { 1858 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy); 1859 struct mwifiex_private *priv = mwifiex_get_priv(adapter, 1860 MWIFIEX_BSS_ROLE_ANY); 1861 struct mwifiex_ds_ant_cfg ant_cfg; 1862 1863 if (!tx_ant || !rx_ant) 1864 return -EOPNOTSUPP; 1865 1866 if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) { 1867 /* Not a MIMO chip. User should provide specific antenna number 1868 * for Tx/Rx path or enable all antennas for diversity 1869 */ 1870 if (tx_ant != rx_ant) 1871 return -EOPNOTSUPP; 1872 1873 if ((tx_ant & (tx_ant - 1)) && 1874 (tx_ant != BIT(adapter->number_of_antenna) - 1)) 1875 return -EOPNOTSUPP; 1876 1877 if ((tx_ant == BIT(adapter->number_of_antenna) - 1) && 1878 (priv->adapter->number_of_antenna > 1)) { 1879 tx_ant = RF_ANTENNA_AUTO; 1880 rx_ant = RF_ANTENNA_AUTO; 1881 } 1882 } else { 1883 struct ieee80211_sta_ht_cap *ht_info; 1884 int rx_mcs_supp; 1885 enum nl80211_band band; 1886 1887 if ((tx_ant == 0x1 && rx_ant == 0x1)) { 1888 adapter->user_dev_mcs_support = HT_STREAM_1X1; 1889 if (adapter->is_hw_11ac_capable) 1890 adapter->usr_dot_11ac_mcs_support = 1891 MWIFIEX_11AC_MCS_MAP_1X1; 1892 } else { 1893 adapter->user_dev_mcs_support = HT_STREAM_2X2; 1894 if (adapter->is_hw_11ac_capable) 1895 adapter->usr_dot_11ac_mcs_support = 1896 MWIFIEX_11AC_MCS_MAP_2X2; 1897 } 1898 1899 for (band = 0; band < NUM_NL80211_BANDS; band++) { 1900 if (!adapter->wiphy->bands[band]) 1901 continue; 1902 1903 ht_info = &adapter->wiphy->bands[band]->ht_cap; 1904 rx_mcs_supp = 1905 GET_RXMCSSUPP(adapter->user_dev_mcs_support); 1906 memset(&ht_info->mcs, 0, adapter->number_of_antenna); 1907 memset(&ht_info->mcs, 0xff, rx_mcs_supp); 1908 } 1909 } 1910 1911 ant_cfg.tx_ant = tx_ant; 1912 ant_cfg.rx_ant = rx_ant; 1913 1914 return mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA, 1915 HostCmd_ACT_GEN_SET, 0, &ant_cfg, true); 1916 } 1917 1918 static int 1919 mwifiex_cfg80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant) 1920 { 1921 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy); 1922 struct mwifiex_private *priv = mwifiex_get_priv(adapter, 1923 MWIFIEX_BSS_ROLE_ANY); 1924 mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA, 1925 HostCmd_ACT_GEN_GET, 0, NULL, true); 1926 1927 *tx_ant = priv->tx_ant; 1928 *rx_ant = priv->rx_ant; 1929 1930 return 0; 1931 } 1932 1933 /* cfg80211 operation handler for stop ap. 1934 * Function stops BSS running at uAP interface. 1935 */ 1936 static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev) 1937 { 1938 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 1939 1940 mwifiex_abort_cac(priv); 1941 1942 if (mwifiex_del_mgmt_ies(priv)) 1943 mwifiex_dbg(priv->adapter, ERROR, 1944 "Failed to delete mgmt IEs!\n"); 1945 1946 priv->ap_11n_enabled = 0; 1947 memset(&priv->bss_cfg, 0, sizeof(priv->bss_cfg)); 1948 1949 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_STOP, 1950 HostCmd_ACT_GEN_SET, 0, NULL, true)) { 1951 mwifiex_dbg(priv->adapter, ERROR, 1952 "Failed to stop the BSS\n"); 1953 return -1; 1954 } 1955 1956 if (mwifiex_send_cmd(priv, HOST_CMD_APCMD_SYS_RESET, 1957 HostCmd_ACT_GEN_SET, 0, NULL, true)) { 1958 mwifiex_dbg(priv->adapter, ERROR, 1959 "Failed to reset BSS\n"); 1960 return -1; 1961 } 1962 1963 if (netif_carrier_ok(priv->netdev)) 1964 netif_carrier_off(priv->netdev); 1965 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter); 1966 1967 return 0; 1968 } 1969 1970 /* cfg80211 operation handler for start_ap. 1971 * Function sets beacon period, DTIM period, SSID and security into 1972 * AP config structure. 1973 * AP is configured with these settings and BSS is started. 1974 */ 1975 static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy, 1976 struct net_device *dev, 1977 struct cfg80211_ap_settings *params) 1978 { 1979 struct mwifiex_uap_bss_param *bss_cfg; 1980 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 1981 1982 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP) 1983 return -1; 1984 1985 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL); 1986 if (!bss_cfg) 1987 return -ENOMEM; 1988 1989 mwifiex_set_sys_config_invalid_data(bss_cfg); 1990 1991 if (params->beacon_interval) 1992 bss_cfg->beacon_period = params->beacon_interval; 1993 if (params->dtim_period) 1994 bss_cfg->dtim_period = params->dtim_period; 1995 1996 if (params->ssid && params->ssid_len) { 1997 memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len); 1998 bss_cfg->ssid.ssid_len = params->ssid_len; 1999 } 2000 if (params->inactivity_timeout > 0) { 2001 /* sta_ao_timer/ps_sta_ao_timer is in unit of 100ms */ 2002 bss_cfg->sta_ao_timer = 10 * params->inactivity_timeout; 2003 bss_cfg->ps_sta_ao_timer = 10 * params->inactivity_timeout; 2004 } 2005 2006 switch (params->hidden_ssid) { 2007 case NL80211_HIDDEN_SSID_NOT_IN_USE: 2008 bss_cfg->bcast_ssid_ctl = 1; 2009 break; 2010 case NL80211_HIDDEN_SSID_ZERO_LEN: 2011 bss_cfg->bcast_ssid_ctl = 0; 2012 break; 2013 case NL80211_HIDDEN_SSID_ZERO_CONTENTS: 2014 bss_cfg->bcast_ssid_ctl = 2; 2015 break; 2016 default: 2017 kfree(bss_cfg); 2018 return -EINVAL; 2019 } 2020 2021 mwifiex_uap_set_channel(priv, bss_cfg, params->chandef); 2022 mwifiex_set_uap_rates(bss_cfg, params); 2023 2024 if (mwifiex_set_secure_params(priv, bss_cfg, params)) { 2025 mwifiex_dbg(priv->adapter, ERROR, 2026 "Failed to parse security parameters!\n"); 2027 goto out; 2028 } 2029 2030 mwifiex_set_ht_params(priv, bss_cfg, params); 2031 2032 if (priv->adapter->is_hw_11ac_capable) { 2033 mwifiex_set_vht_params(priv, bss_cfg, params); 2034 mwifiex_set_vht_width(priv, params->chandef.width, 2035 priv->ap_11ac_enabled); 2036 } 2037 2038 if (priv->ap_11ac_enabled) 2039 mwifiex_set_11ac_ba_params(priv); 2040 else 2041 mwifiex_set_ba_params(priv); 2042 2043 mwifiex_set_wmm_params(priv, bss_cfg, params); 2044 2045 if (mwifiex_is_11h_active(priv)) 2046 mwifiex_set_tpc_params(priv, bss_cfg, params); 2047 2048 if (mwifiex_is_11h_active(priv) && 2049 !cfg80211_chandef_dfs_required(wiphy, ¶ms->chandef, 2050 priv->bss_mode)) { 2051 mwifiex_dbg(priv->adapter, INFO, 2052 "Disable 11h extensions in FW\n"); 2053 if (mwifiex_11h_activate(priv, false)) { 2054 mwifiex_dbg(priv->adapter, ERROR, 2055 "Failed to disable 11h extensions!!"); 2056 goto out; 2057 } 2058 priv->state_11h.is_11h_active = false; 2059 } 2060 2061 mwifiex_config_uap_11d(priv, ¶ms->beacon); 2062 2063 if (mwifiex_config_start_uap(priv, bss_cfg)) { 2064 mwifiex_dbg(priv->adapter, ERROR, 2065 "Failed to start AP\n"); 2066 goto out; 2067 } 2068 2069 if (mwifiex_set_mgmt_ies(priv, ¶ms->beacon)) 2070 goto out; 2071 2072 if (!netif_carrier_ok(priv->netdev)) 2073 netif_carrier_on(priv->netdev); 2074 mwifiex_wake_up_net_dev_queue(priv->netdev, priv->adapter); 2075 2076 memcpy(&priv->bss_cfg, bss_cfg, sizeof(priv->bss_cfg)); 2077 kfree(bss_cfg); 2078 return 0; 2079 2080 out: 2081 kfree(bss_cfg); 2082 return -1; 2083 } 2084 2085 /* 2086 * CFG802.11 operation handler for disconnection request. 2087 * 2088 * This function does not work when there is already a disconnection 2089 * procedure going on. 2090 */ 2091 static int 2092 mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev, 2093 u16 reason_code) 2094 { 2095 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 2096 2097 if (!mwifiex_stop_bg_scan(priv)) 2098 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy, 0); 2099 2100 if (mwifiex_deauthenticate(priv, NULL)) 2101 return -EFAULT; 2102 2103 eth_zero_addr(priv->cfg_bssid); 2104 priv->hs2_enabled = false; 2105 2106 return 0; 2107 } 2108 2109 /* 2110 * This function informs the CFG802.11 subsystem of a new IBSS. 2111 * 2112 * The following information are sent to the CFG802.11 subsystem 2113 * to register the new IBSS. If we do not register the new IBSS, 2114 * a kernel panic will result. 2115 * - SSID 2116 * - SSID length 2117 * - BSSID 2118 * - Channel 2119 */ 2120 static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv) 2121 { 2122 struct ieee80211_channel *chan; 2123 struct mwifiex_bss_info bss_info; 2124 struct cfg80211_bss *bss; 2125 int ie_len; 2126 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)]; 2127 enum nl80211_band band; 2128 2129 if (mwifiex_get_bss_info(priv, &bss_info)) 2130 return -1; 2131 2132 ie_buf[0] = WLAN_EID_SSID; 2133 ie_buf[1] = bss_info.ssid.ssid_len; 2134 2135 memcpy(&ie_buf[sizeof(struct ieee_types_header)], 2136 &bss_info.ssid.ssid, bss_info.ssid.ssid_len); 2137 ie_len = ie_buf[1] + sizeof(struct ieee_types_header); 2138 2139 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band); 2140 chan = ieee80211_get_channel(priv->wdev.wiphy, 2141 ieee80211_channel_to_frequency(bss_info.bss_chan, 2142 band)); 2143 2144 bss = cfg80211_inform_bss(priv->wdev.wiphy, chan, 2145 CFG80211_BSS_FTYPE_UNKNOWN, 2146 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS, 2147 0, ie_buf, ie_len, 0, GFP_KERNEL); 2148 if (bss) { 2149 cfg80211_put_bss(priv->wdev.wiphy, bss); 2150 ether_addr_copy(priv->cfg_bssid, bss_info.bssid); 2151 } 2152 2153 return 0; 2154 } 2155 2156 /* 2157 * This function connects with a BSS. 2158 * 2159 * This function handles both Infra and Ad-Hoc modes. It also performs 2160 * validity checking on the provided parameters, disconnects from the 2161 * current BSS (if any), sets up the association/scan parameters, 2162 * including security settings, and performs specific SSID scan before 2163 * trying to connect. 2164 * 2165 * For Infra mode, the function returns failure if the specified SSID 2166 * is not found in scan table. However, for Ad-Hoc mode, it can create 2167 * the IBSS if it does not exist. On successful completion in either case, 2168 * the function notifies the CFG802.11 subsystem of the new BSS connection. 2169 */ 2170 static int 2171 mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len, 2172 const u8 *ssid, const u8 *bssid, int mode, 2173 struct ieee80211_channel *channel, 2174 struct cfg80211_connect_params *sme, bool privacy) 2175 { 2176 struct cfg80211_ssid req_ssid; 2177 int ret, auth_type = 0; 2178 struct cfg80211_bss *bss = NULL; 2179 u8 is_scanning_required = 0; 2180 2181 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid)); 2182 2183 req_ssid.ssid_len = ssid_len; 2184 if (ssid_len > IEEE80211_MAX_SSID_LEN) { 2185 mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n"); 2186 return -EINVAL; 2187 } 2188 2189 memcpy(req_ssid.ssid, ssid, ssid_len); 2190 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) { 2191 mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n"); 2192 return -EINVAL; 2193 } 2194 2195 /* As this is new association, clear locally stored 2196 * keys and security related flags */ 2197 priv->sec_info.wpa_enabled = false; 2198 priv->sec_info.wpa2_enabled = false; 2199 priv->wep_key_curr_index = 0; 2200 priv->sec_info.encryption_mode = 0; 2201 priv->sec_info.is_authtype_auto = 0; 2202 ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1); 2203 2204 if (mode == NL80211_IFTYPE_ADHOC) { 2205 u16 enable = true; 2206 2207 /* set ibss coalescing_status */ 2208 ret = mwifiex_send_cmd( 2209 priv, 2210 HostCmd_CMD_802_11_IBSS_COALESCING_STATUS, 2211 HostCmd_ACT_GEN_SET, 0, &enable, true); 2212 if (ret) 2213 return ret; 2214 2215 /* "privacy" is set only for ad-hoc mode */ 2216 if (privacy) { 2217 /* 2218 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that 2219 * the firmware can find a matching network from the 2220 * scan. The cfg80211 does not give us the encryption 2221 * mode at this stage so just setting it to WEP here. 2222 */ 2223 priv->sec_info.encryption_mode = 2224 WLAN_CIPHER_SUITE_WEP104; 2225 priv->sec_info.authentication_mode = 2226 NL80211_AUTHTYPE_OPEN_SYSTEM; 2227 } 2228 2229 goto done; 2230 } 2231 2232 /* Now handle infra mode. "sme" is valid for infra mode only */ 2233 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) { 2234 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM; 2235 priv->sec_info.is_authtype_auto = 1; 2236 } else { 2237 auth_type = sme->auth_type; 2238 } 2239 2240 if (sme->crypto.n_ciphers_pairwise) { 2241 priv->sec_info.encryption_mode = 2242 sme->crypto.ciphers_pairwise[0]; 2243 priv->sec_info.authentication_mode = auth_type; 2244 } 2245 2246 if (sme->crypto.cipher_group) { 2247 priv->sec_info.encryption_mode = sme->crypto.cipher_group; 2248 priv->sec_info.authentication_mode = auth_type; 2249 } 2250 if (sme->ie) 2251 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len); 2252 2253 if (sme->key) { 2254 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) { 2255 mwifiex_dbg(priv->adapter, INFO, 2256 "info: setting wep encryption\t" 2257 "with key len %d\n", sme->key_len); 2258 priv->wep_key_curr_index = sme->key_idx; 2259 ret = mwifiex_set_encode(priv, NULL, sme->key, 2260 sme->key_len, sme->key_idx, 2261 NULL, 0); 2262 } 2263 } 2264 done: 2265 /* 2266 * Scan entries are valid for some time (15 sec). So we can save one 2267 * active scan time if we just try cfg80211_get_bss first. If it fails 2268 * then request scan and cfg80211_get_bss() again for final output. 2269 */ 2270 while (1) { 2271 if (is_scanning_required) { 2272 /* Do specific SSID scanning */ 2273 if (mwifiex_request_scan(priv, &req_ssid)) { 2274 mwifiex_dbg(priv->adapter, ERROR, "scan error\n"); 2275 return -EFAULT; 2276 } 2277 } 2278 2279 /* Find the BSS we want using available scan results */ 2280 if (mode == NL80211_IFTYPE_ADHOC) 2281 bss = cfg80211_get_bss(priv->wdev.wiphy, channel, 2282 bssid, ssid, ssid_len, 2283 IEEE80211_BSS_TYPE_IBSS, 2284 IEEE80211_PRIVACY_ANY); 2285 else 2286 bss = cfg80211_get_bss(priv->wdev.wiphy, channel, 2287 bssid, ssid, ssid_len, 2288 IEEE80211_BSS_TYPE_ESS, 2289 IEEE80211_PRIVACY_ANY); 2290 2291 if (!bss) { 2292 if (is_scanning_required) { 2293 mwifiex_dbg(priv->adapter, MSG, 2294 "assoc: requested bss not found in scan results\n"); 2295 break; 2296 } 2297 is_scanning_required = 1; 2298 } else { 2299 mwifiex_dbg(priv->adapter, MSG, 2300 "info: trying to associate to '%.*s' bssid %pM\n", 2301 req_ssid.ssid_len, (char *)req_ssid.ssid, 2302 bss->bssid); 2303 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN); 2304 break; 2305 } 2306 } 2307 2308 ret = mwifiex_bss_start(priv, bss, &req_ssid); 2309 if (ret) 2310 return ret; 2311 2312 if (mode == NL80211_IFTYPE_ADHOC) { 2313 /* Inform the BSS information to kernel, otherwise 2314 * kernel will give a panic after successful assoc */ 2315 if (mwifiex_cfg80211_inform_ibss_bss(priv)) 2316 return -EFAULT; 2317 } 2318 2319 return ret; 2320 } 2321 2322 /* 2323 * CFG802.11 operation handler for association request. 2324 * 2325 * This function does not work when the current mode is set to Ad-Hoc, or 2326 * when there is already an association procedure going on. The given BSS 2327 * information is used to associate. 2328 */ 2329 static int 2330 mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev, 2331 struct cfg80211_connect_params *sme) 2332 { 2333 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 2334 struct mwifiex_adapter *adapter = priv->adapter; 2335 int ret; 2336 2337 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA) { 2338 mwifiex_dbg(adapter, ERROR, 2339 "%s: reject infra assoc request in non-STA role\n", 2340 dev->name); 2341 return -EINVAL; 2342 } 2343 2344 if (priv->wdev.current_bss) { 2345 mwifiex_dbg(adapter, ERROR, 2346 "%s: already connected\n", dev->name); 2347 return -EALREADY; 2348 } 2349 2350 if (priv->scan_block) 2351 priv->scan_block = false; 2352 2353 if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags) || 2354 test_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags)) { 2355 mwifiex_dbg(adapter, ERROR, 2356 "%s: Ignore connection.\t" 2357 "Card removed or FW in bad state\n", 2358 dev->name); 2359 return -EFAULT; 2360 } 2361 2362 mwifiex_dbg(adapter, INFO, 2363 "info: Trying to associate to %.*s and bssid %pM\n", 2364 (int)sme->ssid_len, (char *)sme->ssid, sme->bssid); 2365 2366 if (!mwifiex_stop_bg_scan(priv)) 2367 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy, 0); 2368 2369 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid, 2370 priv->bss_mode, sme->channel, sme, 0); 2371 if (!ret) { 2372 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, NULL, 0, 2373 NULL, 0, WLAN_STATUS_SUCCESS, 2374 GFP_KERNEL); 2375 mwifiex_dbg(priv->adapter, MSG, 2376 "info: associated to bssid %pM successfully\n", 2377 priv->cfg_bssid); 2378 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) && 2379 priv->adapter->auto_tdls && 2380 priv->bss_type == MWIFIEX_BSS_TYPE_STA) 2381 mwifiex_setup_auto_tdls_timer(priv); 2382 } else { 2383 mwifiex_dbg(priv->adapter, ERROR, 2384 "info: association to bssid %pM failed\n", 2385 priv->cfg_bssid); 2386 eth_zero_addr(priv->cfg_bssid); 2387 2388 if (ret > 0) 2389 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, 2390 NULL, 0, NULL, 0, ret, 2391 GFP_KERNEL); 2392 else 2393 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, 2394 NULL, 0, NULL, 0, 2395 WLAN_STATUS_UNSPECIFIED_FAILURE, 2396 GFP_KERNEL); 2397 } 2398 2399 return 0; 2400 } 2401 2402 /* 2403 * This function sets following parameters for ibss network. 2404 * - channel 2405 * - start band 2406 * - 11n flag 2407 * - secondary channel offset 2408 */ 2409 static int mwifiex_set_ibss_params(struct mwifiex_private *priv, 2410 struct cfg80211_ibss_params *params) 2411 { 2412 struct mwifiex_adapter *adapter = priv->adapter; 2413 int index = 0, i; 2414 u8 config_bands = 0; 2415 2416 if (params->chandef.chan->band == NL80211_BAND_2GHZ) { 2417 if (!params->basic_rates) { 2418 config_bands = BAND_B | BAND_G; 2419 } else { 2420 for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) { 2421 /* 2422 * Rates below 6 Mbps in the table are CCK 2423 * rates; 802.11b and from 6 they are OFDM; 2424 * 802.11G 2425 */ 2426 if (mwifiex_rates[i].bitrate == 60) { 2427 index = 1 << i; 2428 break; 2429 } 2430 } 2431 2432 if (params->basic_rates < index) { 2433 config_bands = BAND_B; 2434 } else { 2435 config_bands = BAND_G; 2436 if (params->basic_rates % index) 2437 config_bands |= BAND_B; 2438 } 2439 } 2440 2441 if (cfg80211_get_chandef_type(¶ms->chandef) != 2442 NL80211_CHAN_NO_HT) 2443 config_bands |= BAND_G | BAND_GN; 2444 } else { 2445 if (cfg80211_get_chandef_type(¶ms->chandef) == 2446 NL80211_CHAN_NO_HT) 2447 config_bands = BAND_A; 2448 else 2449 config_bands = BAND_AN | BAND_A; 2450 } 2451 2452 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) { 2453 adapter->config_bands = config_bands; 2454 adapter->adhoc_start_band = config_bands; 2455 2456 if ((config_bands & BAND_GN) || (config_bands & BAND_AN)) 2457 adapter->adhoc_11n_enabled = true; 2458 else 2459 adapter->adhoc_11n_enabled = false; 2460 } 2461 2462 adapter->sec_chan_offset = 2463 mwifiex_chan_type_to_sec_chan_offset( 2464 cfg80211_get_chandef_type(¶ms->chandef)); 2465 priv->adhoc_channel = ieee80211_frequency_to_channel( 2466 params->chandef.chan->center_freq); 2467 2468 mwifiex_dbg(adapter, INFO, 2469 "info: set ibss band %d, chan %d, chan offset %d\n", 2470 config_bands, priv->adhoc_channel, 2471 adapter->sec_chan_offset); 2472 2473 return 0; 2474 } 2475 2476 /* 2477 * CFG802.11 operation handler to join an IBSS. 2478 * 2479 * This function does not work in any mode other than Ad-Hoc, or if 2480 * a join operation is already in progress. 2481 */ 2482 static int 2483 mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev, 2484 struct cfg80211_ibss_params *params) 2485 { 2486 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 2487 int ret = 0; 2488 2489 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) { 2490 mwifiex_dbg(priv->adapter, ERROR, 2491 "request to join ibss received\t" 2492 "when station is not in ibss mode\n"); 2493 goto done; 2494 } 2495 2496 mwifiex_dbg(priv->adapter, MSG, 2497 "info: trying to join to %.*s and bssid %pM\n", 2498 params->ssid_len, (char *)params->ssid, params->bssid); 2499 2500 mwifiex_set_ibss_params(priv, params); 2501 2502 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid, 2503 params->bssid, priv->bss_mode, 2504 params->chandef.chan, NULL, 2505 params->privacy); 2506 done: 2507 if (!ret) { 2508 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid, 2509 params->chandef.chan, GFP_KERNEL); 2510 mwifiex_dbg(priv->adapter, MSG, 2511 "info: joined/created adhoc network with bssid\t" 2512 "%pM successfully\n", priv->cfg_bssid); 2513 } else { 2514 mwifiex_dbg(priv->adapter, ERROR, 2515 "info: failed creating/joining adhoc network\n"); 2516 } 2517 2518 return ret; 2519 } 2520 2521 /* 2522 * CFG802.11 operation handler to leave an IBSS. 2523 * 2524 * This function does not work if a leave operation is 2525 * already in progress. 2526 */ 2527 static int 2528 mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev) 2529 { 2530 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 2531 2532 mwifiex_dbg(priv->adapter, MSG, "info: disconnecting from essid %pM\n", 2533 priv->cfg_bssid); 2534 if (mwifiex_deauthenticate(priv, NULL)) 2535 return -EFAULT; 2536 2537 eth_zero_addr(priv->cfg_bssid); 2538 2539 return 0; 2540 } 2541 2542 /* 2543 * CFG802.11 operation handler for scan request. 2544 * 2545 * This function issues a scan request to the firmware based upon 2546 * the user specified scan configuration. On successful completion, 2547 * it also informs the results. 2548 */ 2549 static int 2550 mwifiex_cfg80211_scan(struct wiphy *wiphy, 2551 struct cfg80211_scan_request *request) 2552 { 2553 struct net_device *dev = request->wdev->netdev; 2554 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 2555 int i, offset, ret; 2556 struct ieee80211_channel *chan; 2557 struct ieee_types_header *ie; 2558 struct mwifiex_user_scan_cfg *user_scan_cfg; 2559 u8 mac_addr[ETH_ALEN]; 2560 2561 mwifiex_dbg(priv->adapter, CMD, 2562 "info: received scan request on %s\n", dev->name); 2563 2564 /* Block scan request if scan operation or scan cleanup when interface 2565 * is disabled is in process 2566 */ 2567 if (priv->scan_request || priv->scan_aborting) { 2568 mwifiex_dbg(priv->adapter, WARN, 2569 "cmd: Scan already in process..\n"); 2570 return -EBUSY; 2571 } 2572 2573 if (!priv->wdev.current_bss && priv->scan_block) 2574 priv->scan_block = false; 2575 2576 if (!mwifiex_stop_bg_scan(priv)) 2577 cfg80211_sched_scan_stopped_rtnl(priv->wdev.wiphy, 0); 2578 2579 user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL); 2580 if (!user_scan_cfg) 2581 return -ENOMEM; 2582 2583 priv->scan_request = request; 2584 2585 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { 2586 get_random_mask_addr(mac_addr, request->mac_addr, 2587 request->mac_addr_mask); 2588 ether_addr_copy(request->mac_addr, mac_addr); 2589 ether_addr_copy(user_scan_cfg->random_mac, mac_addr); 2590 } 2591 2592 user_scan_cfg->num_ssids = request->n_ssids; 2593 user_scan_cfg->ssid_list = request->ssids; 2594 2595 if (request->ie && request->ie_len) { 2596 offset = 0; 2597 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) { 2598 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR) 2599 continue; 2600 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN; 2601 ie = (struct ieee_types_header *)(request->ie + offset); 2602 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len); 2603 offset += sizeof(*ie) + ie->len; 2604 2605 if (offset >= request->ie_len) 2606 break; 2607 } 2608 } 2609 2610 for (i = 0; i < min_t(u32, request->n_channels, 2611 MWIFIEX_USER_SCAN_CHAN_MAX); i++) { 2612 chan = request->channels[i]; 2613 user_scan_cfg->chan_list[i].chan_number = chan->hw_value; 2614 user_scan_cfg->chan_list[i].radio_type = chan->band; 2615 2616 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids) 2617 user_scan_cfg->chan_list[i].scan_type = 2618 MWIFIEX_SCAN_TYPE_PASSIVE; 2619 else 2620 user_scan_cfg->chan_list[i].scan_type = 2621 MWIFIEX_SCAN_TYPE_ACTIVE; 2622 2623 user_scan_cfg->chan_list[i].scan_time = 0; 2624 } 2625 2626 if (priv->adapter->scan_chan_gap_enabled && 2627 mwifiex_is_any_intf_active(priv)) 2628 user_scan_cfg->scan_chan_gap = 2629 priv->adapter->scan_chan_gap_time; 2630 2631 ret = mwifiex_scan_networks(priv, user_scan_cfg); 2632 kfree(user_scan_cfg); 2633 if (ret) { 2634 mwifiex_dbg(priv->adapter, ERROR, 2635 "scan failed: %d\n", ret); 2636 priv->scan_aborting = false; 2637 priv->scan_request = NULL; 2638 return ret; 2639 } 2640 2641 if (request->ie && request->ie_len) { 2642 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) { 2643 if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) { 2644 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR; 2645 memset(&priv->vs_ie[i].ie, 0, 2646 MWIFIEX_MAX_VSIE_LEN); 2647 } 2648 } 2649 } 2650 return 0; 2651 } 2652 2653 /* CFG802.11 operation handler for sched_scan_start. 2654 * 2655 * This function issues a bgscan config request to the firmware based upon 2656 * the user specified sched_scan configuration. On successful completion, 2657 * firmware will generate BGSCAN_REPORT event, driver should issue bgscan 2658 * query command to get sched_scan results from firmware. 2659 */ 2660 static int 2661 mwifiex_cfg80211_sched_scan_start(struct wiphy *wiphy, 2662 struct net_device *dev, 2663 struct cfg80211_sched_scan_request *request) 2664 { 2665 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 2666 int i, offset; 2667 struct ieee80211_channel *chan; 2668 struct mwifiex_bg_scan_cfg *bgscan_cfg; 2669 struct ieee_types_header *ie; 2670 2671 if (!request || (!request->n_ssids && !request->n_match_sets)) { 2672 wiphy_err(wiphy, "%s : Invalid Sched_scan parameters", 2673 __func__); 2674 return -EINVAL; 2675 } 2676 2677 wiphy_info(wiphy, "sched_scan start : n_ssids=%d n_match_sets=%d ", 2678 request->n_ssids, request->n_match_sets); 2679 wiphy_info(wiphy, "n_channels=%d interval=%d ie_len=%d\n", 2680 request->n_channels, request->scan_plans->interval, 2681 (int)request->ie_len); 2682 2683 bgscan_cfg = kzalloc(sizeof(*bgscan_cfg), GFP_KERNEL); 2684 if (!bgscan_cfg) 2685 return -ENOMEM; 2686 2687 if (priv->scan_request || priv->scan_aborting) 2688 bgscan_cfg->start_later = true; 2689 2690 bgscan_cfg->num_ssids = request->n_match_sets; 2691 bgscan_cfg->ssid_list = request->match_sets; 2692 2693 if (request->ie && request->ie_len) { 2694 offset = 0; 2695 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) { 2696 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR) 2697 continue; 2698 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_BGSCAN; 2699 ie = (struct ieee_types_header *)(request->ie + offset); 2700 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len); 2701 offset += sizeof(*ie) + ie->len; 2702 2703 if (offset >= request->ie_len) 2704 break; 2705 } 2706 } 2707 2708 for (i = 0; i < min_t(u32, request->n_channels, 2709 MWIFIEX_BG_SCAN_CHAN_MAX); i++) { 2710 chan = request->channels[i]; 2711 bgscan_cfg->chan_list[i].chan_number = chan->hw_value; 2712 bgscan_cfg->chan_list[i].radio_type = chan->band; 2713 2714 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids) 2715 bgscan_cfg->chan_list[i].scan_type = 2716 MWIFIEX_SCAN_TYPE_PASSIVE; 2717 else 2718 bgscan_cfg->chan_list[i].scan_type = 2719 MWIFIEX_SCAN_TYPE_ACTIVE; 2720 2721 bgscan_cfg->chan_list[i].scan_time = 0; 2722 } 2723 2724 bgscan_cfg->chan_per_scan = min_t(u32, request->n_channels, 2725 MWIFIEX_BG_SCAN_CHAN_MAX); 2726 2727 /* Use at least 15 second for per scan cycle */ 2728 bgscan_cfg->scan_interval = (request->scan_plans->interval > 2729 MWIFIEX_BGSCAN_INTERVAL) ? 2730 request->scan_plans->interval : 2731 MWIFIEX_BGSCAN_INTERVAL; 2732 2733 bgscan_cfg->repeat_count = MWIFIEX_BGSCAN_REPEAT_COUNT; 2734 bgscan_cfg->report_condition = MWIFIEX_BGSCAN_SSID_MATCH | 2735 MWIFIEX_BGSCAN_WAIT_ALL_CHAN_DONE; 2736 bgscan_cfg->bss_type = MWIFIEX_BSS_MODE_INFRA; 2737 bgscan_cfg->action = MWIFIEX_BGSCAN_ACT_SET; 2738 bgscan_cfg->enable = true; 2739 if (request->min_rssi_thold != NL80211_SCAN_RSSI_THOLD_OFF) { 2740 bgscan_cfg->report_condition |= MWIFIEX_BGSCAN_SSID_RSSI_MATCH; 2741 bgscan_cfg->rssi_threshold = request->min_rssi_thold; 2742 } 2743 2744 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_CONFIG, 2745 HostCmd_ACT_GEN_SET, 0, bgscan_cfg, true)) { 2746 kfree(bgscan_cfg); 2747 return -EFAULT; 2748 } 2749 2750 priv->sched_scanning = true; 2751 2752 kfree(bgscan_cfg); 2753 return 0; 2754 } 2755 2756 /* CFG802.11 operation handler for sched_scan_stop. 2757 * 2758 * This function issues a bgscan config command to disable 2759 * previous bgscan configuration in the firmware 2760 */ 2761 static int mwifiex_cfg80211_sched_scan_stop(struct wiphy *wiphy, 2762 struct net_device *dev, u64 reqid) 2763 { 2764 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 2765 2766 wiphy_info(wiphy, "sched scan stop!"); 2767 mwifiex_stop_bg_scan(priv); 2768 2769 return 0; 2770 } 2771 2772 static void mwifiex_setup_vht_caps(struct ieee80211_sta_vht_cap *vht_info, 2773 struct mwifiex_private *priv) 2774 { 2775 struct mwifiex_adapter *adapter = priv->adapter; 2776 2777 vht_info->vht_supported = true; 2778 2779 vht_info->cap = adapter->hw_dot_11ac_dev_cap; 2780 /* Update MCS support for VHT */ 2781 vht_info->vht_mcs.rx_mcs_map = cpu_to_le16( 2782 adapter->hw_dot_11ac_mcs_support & 0xFFFF); 2783 vht_info->vht_mcs.rx_highest = 0; 2784 vht_info->vht_mcs.tx_mcs_map = cpu_to_le16( 2785 adapter->hw_dot_11ac_mcs_support >> 16); 2786 vht_info->vht_mcs.tx_highest = 0; 2787 } 2788 2789 /* 2790 * This function sets up the CFG802.11 specific HT capability fields 2791 * with default values. 2792 * 2793 * The following default values are set - 2794 * - HT Supported = True 2795 * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K 2796 * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE 2797 * - HT Capabilities supported by firmware 2798 * - MCS information, Rx mask = 0xff 2799 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01) 2800 */ 2801 static void 2802 mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info, 2803 struct mwifiex_private *priv) 2804 { 2805 int rx_mcs_supp; 2806 struct ieee80211_mcs_info mcs_set; 2807 u8 *mcs = (u8 *)&mcs_set; 2808 struct mwifiex_adapter *adapter = priv->adapter; 2809 2810 ht_info->ht_supported = true; 2811 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; 2812 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE; 2813 2814 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs)); 2815 2816 /* Fill HT capability information */ 2817 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap)) 2818 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; 2819 else 2820 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; 2821 2822 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap)) 2823 ht_info->cap |= IEEE80211_HT_CAP_SGI_20; 2824 else 2825 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20; 2826 2827 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap)) 2828 ht_info->cap |= IEEE80211_HT_CAP_SGI_40; 2829 else 2830 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40; 2831 2832 if (adapter->user_dev_mcs_support == HT_STREAM_2X2) 2833 ht_info->cap |= 2 << IEEE80211_HT_CAP_RX_STBC_SHIFT; 2834 else 2835 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT; 2836 2837 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap)) 2838 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC; 2839 else 2840 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC; 2841 2842 if (ISSUPP_GREENFIELD(adapter->hw_dot_11n_dev_cap)) 2843 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD; 2844 else 2845 ht_info->cap &= ~IEEE80211_HT_CAP_GRN_FLD; 2846 2847 if (ISENABLED_40MHZ_INTOLERANT(adapter->hw_dot_11n_dev_cap)) 2848 ht_info->cap |= IEEE80211_HT_CAP_40MHZ_INTOLERANT; 2849 else 2850 ht_info->cap &= ~IEEE80211_HT_CAP_40MHZ_INTOLERANT; 2851 2852 if (ISSUPP_RXLDPC(adapter->hw_dot_11n_dev_cap)) 2853 ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING; 2854 else 2855 ht_info->cap &= ~IEEE80211_HT_CAP_LDPC_CODING; 2856 2857 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU; 2858 ht_info->cap |= IEEE80211_HT_CAP_SM_PS; 2859 2860 rx_mcs_supp = GET_RXMCSSUPP(adapter->user_dev_mcs_support); 2861 /* Set MCS for 1x1/2x2 */ 2862 memset(mcs, 0xff, rx_mcs_supp); 2863 /* Clear all the other values */ 2864 memset(&mcs[rx_mcs_supp], 0, 2865 sizeof(struct ieee80211_mcs_info) - rx_mcs_supp); 2866 if (priv->bss_mode == NL80211_IFTYPE_STATION || 2867 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap)) 2868 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */ 2869 SETHT_MCS32(mcs_set.rx_mask); 2870 2871 memcpy((u8 *) &ht_info->mcs, mcs, sizeof(struct ieee80211_mcs_info)); 2872 2873 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; 2874 } 2875 2876 /* 2877 * create a new virtual interface with the given name and name assign type 2878 */ 2879 struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy, 2880 const char *name, 2881 unsigned char name_assign_type, 2882 enum nl80211_iftype type, 2883 struct vif_params *params) 2884 { 2885 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy); 2886 struct mwifiex_private *priv; 2887 struct net_device *dev; 2888 void *mdev_priv; 2889 int ret; 2890 2891 if (!adapter) 2892 return ERR_PTR(-EFAULT); 2893 2894 switch (type) { 2895 case NL80211_IFTYPE_UNSPECIFIED: 2896 case NL80211_IFTYPE_STATION: 2897 case NL80211_IFTYPE_ADHOC: 2898 if (adapter->curr_iface_comb.sta_intf == 2899 adapter->iface_limit.sta_intf) { 2900 mwifiex_dbg(adapter, ERROR, 2901 "cannot create multiple sta/adhoc ifaces\n"); 2902 return ERR_PTR(-EINVAL); 2903 } 2904 2905 priv = mwifiex_get_unused_priv_by_bss_type( 2906 adapter, MWIFIEX_BSS_TYPE_STA); 2907 if (!priv) { 2908 mwifiex_dbg(adapter, ERROR, 2909 "could not get free private struct\n"); 2910 return ERR_PTR(-EFAULT); 2911 } 2912 2913 priv->wdev.wiphy = wiphy; 2914 priv->wdev.iftype = NL80211_IFTYPE_STATION; 2915 2916 if (type == NL80211_IFTYPE_UNSPECIFIED) 2917 priv->bss_mode = NL80211_IFTYPE_STATION; 2918 else 2919 priv->bss_mode = type; 2920 2921 priv->bss_type = MWIFIEX_BSS_TYPE_STA; 2922 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II; 2923 priv->bss_priority = 0; 2924 priv->bss_role = MWIFIEX_BSS_ROLE_STA; 2925 2926 break; 2927 case NL80211_IFTYPE_AP: 2928 if (adapter->curr_iface_comb.uap_intf == 2929 adapter->iface_limit.uap_intf) { 2930 mwifiex_dbg(adapter, ERROR, 2931 "cannot create multiple AP ifaces\n"); 2932 return ERR_PTR(-EINVAL); 2933 } 2934 2935 priv = mwifiex_get_unused_priv_by_bss_type( 2936 adapter, MWIFIEX_BSS_TYPE_UAP); 2937 if (!priv) { 2938 mwifiex_dbg(adapter, ERROR, 2939 "could not get free private struct\n"); 2940 return ERR_PTR(-EFAULT); 2941 } 2942 2943 priv->wdev.wiphy = wiphy; 2944 priv->wdev.iftype = NL80211_IFTYPE_AP; 2945 2946 priv->bss_type = MWIFIEX_BSS_TYPE_UAP; 2947 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II; 2948 priv->bss_priority = 0; 2949 priv->bss_role = MWIFIEX_BSS_ROLE_UAP; 2950 priv->bss_started = 0; 2951 priv->bss_mode = type; 2952 2953 break; 2954 case NL80211_IFTYPE_P2P_CLIENT: 2955 if (adapter->curr_iface_comb.p2p_intf == 2956 adapter->iface_limit.p2p_intf) { 2957 mwifiex_dbg(adapter, ERROR, 2958 "cannot create multiple P2P ifaces\n"); 2959 return ERR_PTR(-EINVAL); 2960 } 2961 2962 priv = mwifiex_get_unused_priv_by_bss_type( 2963 adapter, MWIFIEX_BSS_TYPE_P2P); 2964 if (!priv) { 2965 mwifiex_dbg(adapter, ERROR, 2966 "could not get free private struct\n"); 2967 return ERR_PTR(-EFAULT); 2968 } 2969 2970 priv->wdev.wiphy = wiphy; 2971 /* At start-up, wpa_supplicant tries to change the interface 2972 * to NL80211_IFTYPE_STATION if it is not managed mode. 2973 */ 2974 priv->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT; 2975 priv->bss_mode = NL80211_IFTYPE_P2P_CLIENT; 2976 2977 /* Setting bss_type to P2P tells firmware that this interface 2978 * is receiving P2P peers found during find phase and doing 2979 * action frame handshake. 2980 */ 2981 priv->bss_type = MWIFIEX_BSS_TYPE_P2P; 2982 2983 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II; 2984 priv->bss_priority = MWIFIEX_BSS_ROLE_STA; 2985 priv->bss_role = MWIFIEX_BSS_ROLE_STA; 2986 priv->bss_started = 0; 2987 2988 if (mwifiex_cfg80211_init_p2p_client(priv)) { 2989 memset(&priv->wdev, 0, sizeof(priv->wdev)); 2990 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED; 2991 return ERR_PTR(-EFAULT); 2992 } 2993 2994 break; 2995 default: 2996 mwifiex_dbg(adapter, ERROR, "type not supported\n"); 2997 return ERR_PTR(-EINVAL); 2998 } 2999 3000 dev = alloc_netdev_mqs(sizeof(struct mwifiex_private *), name, 3001 name_assign_type, ether_setup, 3002 IEEE80211_NUM_ACS, 1); 3003 if (!dev) { 3004 mwifiex_dbg(adapter, ERROR, 3005 "no memory available for netdevice\n"); 3006 ret = -ENOMEM; 3007 goto err_alloc_netdev; 3008 } 3009 3010 mwifiex_init_priv_params(priv, dev); 3011 3012 priv->netdev = dev; 3013 3014 if (!adapter->mfg_mode) { 3015 mwifiex_set_mac_address(priv, dev, false, NULL); 3016 3017 ret = mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE, 3018 HostCmd_ACT_GEN_SET, 0, NULL, true); 3019 if (ret) 3020 goto err_set_bss_mode; 3021 3022 ret = mwifiex_sta_init_cmd(priv, false, false); 3023 if (ret) 3024 goto err_sta_init; 3025 } 3026 3027 mwifiex_setup_ht_caps(&wiphy->bands[NL80211_BAND_2GHZ]->ht_cap, priv); 3028 if (adapter->is_hw_11ac_capable) 3029 mwifiex_setup_vht_caps( 3030 &wiphy->bands[NL80211_BAND_2GHZ]->vht_cap, priv); 3031 3032 if (adapter->config_bands & BAND_A) 3033 mwifiex_setup_ht_caps( 3034 &wiphy->bands[NL80211_BAND_5GHZ]->ht_cap, priv); 3035 3036 if ((adapter->config_bands & BAND_A) && adapter->is_hw_11ac_capable) 3037 mwifiex_setup_vht_caps( 3038 &wiphy->bands[NL80211_BAND_5GHZ]->vht_cap, priv); 3039 3040 dev_net_set(dev, wiphy_net(wiphy)); 3041 dev->ieee80211_ptr = &priv->wdev; 3042 dev->ieee80211_ptr->iftype = priv->bss_mode; 3043 SET_NETDEV_DEV(dev, wiphy_dev(wiphy)); 3044 3045 dev->flags |= IFF_BROADCAST | IFF_MULTICAST; 3046 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT; 3047 dev->hard_header_len += MWIFIEX_MIN_DATA_HEADER_LEN; 3048 dev->ethtool_ops = &mwifiex_ethtool_ops; 3049 3050 mdev_priv = netdev_priv(dev); 3051 *((unsigned long *) mdev_priv) = (unsigned long) priv; 3052 3053 SET_NETDEV_DEV(dev, adapter->dev); 3054 3055 priv->dfs_cac_workqueue = alloc_workqueue("MWIFIEX_DFS_CAC%s", 3056 WQ_HIGHPRI | 3057 WQ_MEM_RECLAIM | 3058 WQ_UNBOUND, 1, name); 3059 if (!priv->dfs_cac_workqueue) { 3060 mwifiex_dbg(adapter, ERROR, "cannot alloc DFS CAC queue\n"); 3061 ret = -ENOMEM; 3062 goto err_alloc_cac; 3063 } 3064 3065 INIT_DELAYED_WORK(&priv->dfs_cac_work, mwifiex_dfs_cac_work_queue); 3066 3067 priv->dfs_chan_sw_workqueue = alloc_workqueue("MWIFIEX_DFS_CHSW%s", 3068 WQ_HIGHPRI | WQ_UNBOUND | 3069 WQ_MEM_RECLAIM, 1, name); 3070 if (!priv->dfs_chan_sw_workqueue) { 3071 mwifiex_dbg(adapter, ERROR, "cannot alloc DFS channel sw queue\n"); 3072 ret = -ENOMEM; 3073 goto err_alloc_chsw; 3074 } 3075 3076 INIT_DELAYED_WORK(&priv->dfs_chan_sw_work, 3077 mwifiex_dfs_chan_sw_work_queue); 3078 3079 mutex_init(&priv->async_mutex); 3080 3081 /* Register network device */ 3082 if (register_netdevice(dev)) { 3083 mwifiex_dbg(adapter, ERROR, "cannot register network device\n"); 3084 ret = -EFAULT; 3085 goto err_reg_netdev; 3086 } 3087 3088 mwifiex_dbg(adapter, INFO, 3089 "info: %s: Marvell 802.11 Adapter\n", dev->name); 3090 3091 #ifdef CONFIG_DEBUG_FS 3092 mwifiex_dev_debugfs_init(priv); 3093 #endif 3094 3095 switch (type) { 3096 case NL80211_IFTYPE_UNSPECIFIED: 3097 case NL80211_IFTYPE_STATION: 3098 case NL80211_IFTYPE_ADHOC: 3099 adapter->curr_iface_comb.sta_intf++; 3100 break; 3101 case NL80211_IFTYPE_AP: 3102 adapter->curr_iface_comb.uap_intf++; 3103 break; 3104 case NL80211_IFTYPE_P2P_CLIENT: 3105 adapter->curr_iface_comb.p2p_intf++; 3106 break; 3107 default: 3108 /* This should be dead code; checked above */ 3109 mwifiex_dbg(adapter, ERROR, "type not supported\n"); 3110 return ERR_PTR(-EINVAL); 3111 } 3112 3113 return &priv->wdev; 3114 3115 err_reg_netdev: 3116 destroy_workqueue(priv->dfs_chan_sw_workqueue); 3117 priv->dfs_chan_sw_workqueue = NULL; 3118 err_alloc_chsw: 3119 destroy_workqueue(priv->dfs_cac_workqueue); 3120 priv->dfs_cac_workqueue = NULL; 3121 err_alloc_cac: 3122 free_netdev(dev); 3123 priv->netdev = NULL; 3124 err_sta_init: 3125 err_set_bss_mode: 3126 err_alloc_netdev: 3127 memset(&priv->wdev, 0, sizeof(priv->wdev)); 3128 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED; 3129 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED; 3130 return ERR_PTR(ret); 3131 } 3132 EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf); 3133 3134 /* 3135 * del_virtual_intf: remove the virtual interface determined by dev 3136 */ 3137 int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev) 3138 { 3139 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev); 3140 struct mwifiex_adapter *adapter = priv->adapter; 3141 struct sk_buff *skb, *tmp; 3142 3143 #ifdef CONFIG_DEBUG_FS 3144 mwifiex_dev_debugfs_remove(priv); 3145 #endif 3146 3147 if (priv->sched_scanning) 3148 priv->sched_scanning = false; 3149 3150 mwifiex_stop_net_dev_queue(priv->netdev, adapter); 3151 3152 skb_queue_walk_safe(&priv->bypass_txq, skb, tmp) { 3153 skb_unlink(skb, &priv->bypass_txq); 3154 mwifiex_write_data_complete(priv->adapter, skb, 0, -1); 3155 } 3156 3157 if (netif_carrier_ok(priv->netdev)) 3158 netif_carrier_off(priv->netdev); 3159 3160 if (wdev->netdev->reg_state == NETREG_REGISTERED) 3161 unregister_netdevice(wdev->netdev); 3162 3163 if (priv->dfs_cac_workqueue) { 3164 flush_workqueue(priv->dfs_cac_workqueue); 3165 destroy_workqueue(priv->dfs_cac_workqueue); 3166 priv->dfs_cac_workqueue = NULL; 3167 } 3168 3169 if (priv->dfs_chan_sw_workqueue) { 3170 flush_workqueue(priv->dfs_chan_sw_workqueue); 3171 destroy_workqueue(priv->dfs_chan_sw_workqueue); 3172 priv->dfs_chan_sw_workqueue = NULL; 3173 } 3174 /* Clear the priv in adapter */ 3175 priv->netdev = NULL; 3176 3177 switch (priv->bss_mode) { 3178 case NL80211_IFTYPE_UNSPECIFIED: 3179 case NL80211_IFTYPE_STATION: 3180 case NL80211_IFTYPE_ADHOC: 3181 adapter->curr_iface_comb.sta_intf--; 3182 break; 3183 case NL80211_IFTYPE_AP: 3184 adapter->curr_iface_comb.uap_intf--; 3185 break; 3186 case NL80211_IFTYPE_P2P_CLIENT: 3187 case NL80211_IFTYPE_P2P_GO: 3188 adapter->curr_iface_comb.p2p_intf--; 3189 break; 3190 default: 3191 mwifiex_dbg(adapter, ERROR, 3192 "del_virtual_intf: type not supported\n"); 3193 break; 3194 } 3195 3196 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED; 3197 3198 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA || 3199 GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) 3200 kfree(priv->hist_data); 3201 3202 return 0; 3203 } 3204 EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf); 3205 3206 static bool 3207 mwifiex_is_pattern_supported(struct cfg80211_pkt_pattern *pat, s8 *byte_seq, 3208 u8 max_byte_seq) 3209 { 3210 int j, k, valid_byte_cnt = 0; 3211 bool dont_care_byte = false; 3212 3213 for (j = 0; j < DIV_ROUND_UP(pat->pattern_len, 8); j++) { 3214 for (k = 0; k < 8; k++) { 3215 if (pat->mask[j] & 1 << k) { 3216 memcpy(byte_seq + valid_byte_cnt, 3217 &pat->pattern[j * 8 + k], 1); 3218 valid_byte_cnt++; 3219 if (dont_care_byte) 3220 return false; 3221 } else { 3222 if (valid_byte_cnt) 3223 dont_care_byte = true; 3224 } 3225 3226 /* wildcard bytes record as the offset 3227 * before the valid byte 3228 */ 3229 if (!valid_byte_cnt && !dont_care_byte) 3230 pat->pkt_offset++; 3231 3232 if (valid_byte_cnt > max_byte_seq) 3233 return false; 3234 } 3235 } 3236 3237 byte_seq[max_byte_seq] = valid_byte_cnt; 3238 3239 return true; 3240 } 3241 3242 #ifdef CONFIG_PM 3243 static void mwifiex_set_auto_arp_mef_entry(struct mwifiex_private *priv, 3244 struct mwifiex_mef_entry *mef_entry) 3245 { 3246 int i, filt_num = 0, num_ipv4 = 0; 3247 struct in_device *in_dev; 3248 struct in_ifaddr *ifa; 3249 __be32 ips[MWIFIEX_MAX_SUPPORTED_IPADDR]; 3250 struct mwifiex_adapter *adapter = priv->adapter; 3251 3252 mef_entry->mode = MEF_MODE_HOST_SLEEP; 3253 mef_entry->action = MEF_ACTION_AUTO_ARP; 3254 3255 /* Enable ARP offload feature */ 3256 memset(ips, 0, sizeof(ips)); 3257 for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) { 3258 if (adapter->priv[i]->netdev) { 3259 in_dev = __in_dev_get_rtnl(adapter->priv[i]->netdev); 3260 if (!in_dev) 3261 continue; 3262 ifa = in_dev->ifa_list; 3263 if (!ifa || !ifa->ifa_local) 3264 continue; 3265 ips[i] = ifa->ifa_local; 3266 num_ipv4++; 3267 } 3268 } 3269 3270 for (i = 0; i < num_ipv4; i++) { 3271 if (!ips[i]) 3272 continue; 3273 mef_entry->filter[filt_num].repeat = 1; 3274 memcpy(mef_entry->filter[filt_num].byte_seq, 3275 (u8 *)&ips[i], sizeof(ips[i])); 3276 mef_entry->filter[filt_num]. 3277 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] = 3278 sizeof(ips[i]); 3279 mef_entry->filter[filt_num].offset = 46; 3280 mef_entry->filter[filt_num].filt_type = TYPE_EQ; 3281 if (filt_num) { 3282 mef_entry->filter[filt_num].filt_action = 3283 TYPE_OR; 3284 } 3285 filt_num++; 3286 } 3287 3288 mef_entry->filter[filt_num].repeat = 1; 3289 mef_entry->filter[filt_num].byte_seq[0] = 0x08; 3290 mef_entry->filter[filt_num].byte_seq[1] = 0x06; 3291 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] = 2; 3292 mef_entry->filter[filt_num].offset = 20; 3293 mef_entry->filter[filt_num].filt_type = TYPE_EQ; 3294 mef_entry->filter[filt_num].filt_action = TYPE_AND; 3295 } 3296 3297 static int mwifiex_set_wowlan_mef_entry(struct mwifiex_private *priv, 3298 struct mwifiex_ds_mef_cfg *mef_cfg, 3299 struct mwifiex_mef_entry *mef_entry, 3300 struct cfg80211_wowlan *wowlan) 3301 { 3302 int i, filt_num = 0, ret = 0; 3303 bool first_pat = true; 3304 u8 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ + 1]; 3305 static const u8 ipv4_mc_mac[] = {0x33, 0x33}; 3306 static const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e}; 3307 3308 mef_entry->mode = MEF_MODE_HOST_SLEEP; 3309 mef_entry->action = MEF_ACTION_ALLOW_AND_WAKEUP_HOST; 3310 3311 for (i = 0; i < wowlan->n_patterns; i++) { 3312 memset(byte_seq, 0, sizeof(byte_seq)); 3313 if (!mwifiex_is_pattern_supported(&wowlan->patterns[i], 3314 byte_seq, 3315 MWIFIEX_MEF_MAX_BYTESEQ)) { 3316 mwifiex_dbg(priv->adapter, ERROR, 3317 "Pattern not supported\n"); 3318 return -EOPNOTSUPP; 3319 } 3320 3321 if (!wowlan->patterns[i].pkt_offset) { 3322 if (!(byte_seq[0] & 0x01) && 3323 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 1)) { 3324 mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST; 3325 continue; 3326 } else if (is_broadcast_ether_addr(byte_seq)) { 3327 mef_cfg->criteria |= MWIFIEX_CRITERIA_BROADCAST; 3328 continue; 3329 } else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) && 3330 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 2)) || 3331 (!memcmp(byte_seq, ipv6_mc_mac, 3) && 3332 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 3))) { 3333 mef_cfg->criteria |= MWIFIEX_CRITERIA_MULTICAST; 3334 continue; 3335 } 3336 } 3337 mef_entry->filter[filt_num].repeat = 1; 3338 mef_entry->filter[filt_num].offset = 3339 wowlan->patterns[i].pkt_offset; 3340 memcpy(mef_entry->filter[filt_num].byte_seq, byte_seq, 3341 sizeof(byte_seq)); 3342 mef_entry->filter[filt_num].filt_type = TYPE_EQ; 3343 3344 if (first_pat) { 3345 first_pat = false; 3346 mwifiex_dbg(priv->adapter, INFO, "Wake on patterns\n"); 3347 } else { 3348 mef_entry->filter[filt_num].filt_action = TYPE_AND; 3349 } 3350 3351 filt_num++; 3352 } 3353 3354 if (wowlan->magic_pkt) { 3355 mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST; 3356 mef_entry->filter[filt_num].repeat = 16; 3357 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr, 3358 ETH_ALEN); 3359 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] = 3360 ETH_ALEN; 3361 mef_entry->filter[filt_num].offset = 28; 3362 mef_entry->filter[filt_num].filt_type = TYPE_EQ; 3363 if (filt_num) 3364 mef_entry->filter[filt_num].filt_action = TYPE_OR; 3365 3366 filt_num++; 3367 mef_entry->filter[filt_num].repeat = 16; 3368 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr, 3369 ETH_ALEN); 3370 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] = 3371 ETH_ALEN; 3372 mef_entry->filter[filt_num].offset = 56; 3373 mef_entry->filter[filt_num].filt_type = TYPE_EQ; 3374 mef_entry->filter[filt_num].filt_action = TYPE_OR; 3375 mwifiex_dbg(priv->adapter, INFO, "Wake on magic packet\n"); 3376 } 3377 return ret; 3378 } 3379 3380 static int mwifiex_set_mef_filter(struct mwifiex_private *priv, 3381 struct cfg80211_wowlan *wowlan) 3382 { 3383 int ret = 0, num_entries = 1; 3384 struct mwifiex_ds_mef_cfg mef_cfg; 3385 struct mwifiex_mef_entry *mef_entry; 3386 3387 if (wowlan->n_patterns || wowlan->magic_pkt) 3388 num_entries++; 3389 3390 mef_entry = kcalloc(num_entries, sizeof(*mef_entry), GFP_KERNEL); 3391 if (!mef_entry) 3392 return -ENOMEM; 3393 3394 memset(&mef_cfg, 0, sizeof(mef_cfg)); 3395 mef_cfg.criteria |= MWIFIEX_CRITERIA_BROADCAST | 3396 MWIFIEX_CRITERIA_UNICAST; 3397 mef_cfg.num_entries = num_entries; 3398 mef_cfg.mef_entry = mef_entry; 3399 3400 mwifiex_set_auto_arp_mef_entry(priv, &mef_entry[0]); 3401 3402 if (wowlan->n_patterns || wowlan->magic_pkt) { 3403 ret = mwifiex_set_wowlan_mef_entry(priv, &mef_cfg, 3404 &mef_entry[1], wowlan); 3405 if (ret) 3406 goto err; 3407 } 3408 3409 if (!mef_cfg.criteria) 3410 mef_cfg.criteria = MWIFIEX_CRITERIA_BROADCAST | 3411 MWIFIEX_CRITERIA_UNICAST | 3412 MWIFIEX_CRITERIA_MULTICAST; 3413 3414 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MEF_CFG, 3415 HostCmd_ACT_GEN_SET, 0, 3416 &mef_cfg, true); 3417 3418 err: 3419 kfree(mef_entry); 3420 return ret; 3421 } 3422 3423 static int mwifiex_cfg80211_suspend(struct wiphy *wiphy, 3424 struct cfg80211_wowlan *wowlan) 3425 { 3426 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy); 3427 struct mwifiex_ds_hs_cfg hs_cfg; 3428 int i, ret = 0, retry_num = 10; 3429 struct mwifiex_private *priv; 3430 struct mwifiex_private *sta_priv = 3431 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA); 3432 3433 sta_priv->scan_aborting = true; 3434 for (i = 0; i < adapter->priv_num; i++) { 3435 priv = adapter->priv[i]; 3436 mwifiex_abort_cac(priv); 3437 } 3438 3439 mwifiex_cancel_all_pending_cmd(adapter); 3440 3441 for (i = 0; i < adapter->priv_num; i++) { 3442 priv = adapter->priv[i]; 3443 if (priv && priv->netdev) 3444 netif_device_detach(priv->netdev); 3445 } 3446 3447 for (i = 0; i < retry_num; i++) { 3448 if (!mwifiex_wmm_lists_empty(adapter) || 3449 !mwifiex_bypass_txlist_empty(adapter) || 3450 !skb_queue_empty(&adapter->tx_data_q)) 3451 usleep_range(10000, 15000); 3452 else 3453 break; 3454 } 3455 3456 if (!wowlan) { 3457 mwifiex_dbg(adapter, ERROR, 3458 "None of the WOWLAN triggers enabled\n"); 3459 ret = 0; 3460 goto done; 3461 } 3462 3463 if (!sta_priv->media_connected && !wowlan->nd_config) { 3464 mwifiex_dbg(adapter, ERROR, 3465 "Can not configure WOWLAN in disconnected state\n"); 3466 ret = 0; 3467 goto done; 3468 } 3469 3470 ret = mwifiex_set_mef_filter(sta_priv, wowlan); 3471 if (ret) { 3472 mwifiex_dbg(adapter, ERROR, "Failed to set MEF filter\n"); 3473 goto done; 3474 } 3475 3476 memset(&hs_cfg, 0, sizeof(hs_cfg)); 3477 hs_cfg.conditions = le32_to_cpu(adapter->hs_cfg.conditions); 3478 3479 if (wowlan->nd_config) { 3480 mwifiex_dbg(adapter, INFO, "Wake on net detect\n"); 3481 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT; 3482 mwifiex_cfg80211_sched_scan_start(wiphy, sta_priv->netdev, 3483 wowlan->nd_config); 3484 } 3485 3486 if (wowlan->disconnect) { 3487 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT; 3488 mwifiex_dbg(sta_priv->adapter, INFO, "Wake on device disconnect\n"); 3489 } 3490 3491 hs_cfg.is_invoke_hostcmd = false; 3492 hs_cfg.gpio = adapter->hs_cfg.gpio; 3493 hs_cfg.gap = adapter->hs_cfg.gap; 3494 ret = mwifiex_set_hs_params(sta_priv, HostCmd_ACT_GEN_SET, 3495 MWIFIEX_SYNC_CMD, &hs_cfg); 3496 if (ret) 3497 mwifiex_dbg(adapter, ERROR, "Failed to set HS params\n"); 3498 3499 done: 3500 sta_priv->scan_aborting = false; 3501 return ret; 3502 } 3503 3504 static int mwifiex_cfg80211_resume(struct wiphy *wiphy) 3505 { 3506 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy); 3507 struct mwifiex_private *priv; 3508 struct mwifiex_ds_wakeup_reason wakeup_reason; 3509 struct cfg80211_wowlan_wakeup wakeup_report; 3510 int i; 3511 bool report_wakeup_reason = true; 3512 3513 for (i = 0; i < adapter->priv_num; i++) { 3514 priv = adapter->priv[i]; 3515 if (priv && priv->netdev) 3516 netif_device_attach(priv->netdev); 3517 } 3518 3519 if (!wiphy->wowlan_config) 3520 goto done; 3521 3522 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA); 3523 mwifiex_get_wakeup_reason(priv, HostCmd_ACT_GEN_GET, MWIFIEX_SYNC_CMD, 3524 &wakeup_reason); 3525 memset(&wakeup_report, 0, sizeof(struct cfg80211_wowlan_wakeup)); 3526 3527 wakeup_report.pattern_idx = -1; 3528 3529 switch (wakeup_reason.hs_wakeup_reason) { 3530 case NO_HSWAKEUP_REASON: 3531 break; 3532 case BCAST_DATA_MATCHED: 3533 break; 3534 case MCAST_DATA_MATCHED: 3535 break; 3536 case UCAST_DATA_MATCHED: 3537 break; 3538 case MASKTABLE_EVENT_MATCHED: 3539 break; 3540 case NON_MASKABLE_EVENT_MATCHED: 3541 if (wiphy->wowlan_config->disconnect) 3542 wakeup_report.disconnect = true; 3543 if (wiphy->wowlan_config->nd_config) 3544 wakeup_report.net_detect = adapter->nd_info; 3545 break; 3546 case NON_MASKABLE_CONDITION_MATCHED: 3547 break; 3548 case MAGIC_PATTERN_MATCHED: 3549 if (wiphy->wowlan_config->magic_pkt) 3550 wakeup_report.magic_pkt = true; 3551 if (wiphy->wowlan_config->n_patterns) 3552 wakeup_report.pattern_idx = 1; 3553 break; 3554 case GTK_REKEY_FAILURE: 3555 if (wiphy->wowlan_config->gtk_rekey_failure) 3556 wakeup_report.gtk_rekey_failure = true; 3557 break; 3558 default: 3559 report_wakeup_reason = false; 3560 break; 3561 } 3562 3563 if (report_wakeup_reason) 3564 cfg80211_report_wowlan_wakeup(&priv->wdev, &wakeup_report, 3565 GFP_KERNEL); 3566 3567 done: 3568 if (adapter->nd_info) { 3569 for (i = 0 ; i < adapter->nd_info->n_matches ; i++) 3570 kfree(adapter->nd_info->matches[i]); 3571 kfree(adapter->nd_info); 3572 adapter->nd_info = NULL; 3573 } 3574 3575 return 0; 3576 } 3577 3578 static void mwifiex_cfg80211_set_wakeup(struct wiphy *wiphy, 3579 bool enabled) 3580 { 3581 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy); 3582 3583 device_set_wakeup_enable(adapter->dev, enabled); 3584 } 3585 3586 static int mwifiex_set_rekey_data(struct wiphy *wiphy, struct net_device *dev, 3587 struct cfg80211_gtk_rekey_data *data) 3588 { 3589 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 3590 3591 if (!ISSUPP_FIRMWARE_SUPPLICANT(priv->adapter->fw_cap_info)) 3592 return -EOPNOTSUPP; 3593 3594 return mwifiex_send_cmd(priv, HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG, 3595 HostCmd_ACT_GEN_SET, 0, data, true); 3596 } 3597 3598 #endif 3599 3600 static int mwifiex_get_coalesce_pkt_type(u8 *byte_seq) 3601 { 3602 static const u8 ipv4_mc_mac[] = {0x33, 0x33}; 3603 static const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e}; 3604 static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff}; 3605 3606 if ((byte_seq[0] & 0x01) && 3607 (byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 1)) 3608 return PACKET_TYPE_UNICAST; 3609 else if (!memcmp(byte_seq, bc_mac, 4)) 3610 return PACKET_TYPE_BROADCAST; 3611 else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) && 3612 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 2) || 3613 (!memcmp(byte_seq, ipv6_mc_mac, 3) && 3614 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 3)) 3615 return PACKET_TYPE_MULTICAST; 3616 3617 return 0; 3618 } 3619 3620 static int 3621 mwifiex_fill_coalesce_rule_info(struct mwifiex_private *priv, 3622 struct cfg80211_coalesce_rules *crule, 3623 struct mwifiex_coalesce_rule *mrule) 3624 { 3625 u8 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ + 1]; 3626 struct filt_field_param *param; 3627 int i; 3628 3629 mrule->max_coalescing_delay = crule->delay; 3630 3631 param = mrule->params; 3632 3633 for (i = 0; i < crule->n_patterns; i++) { 3634 memset(byte_seq, 0, sizeof(byte_seq)); 3635 if (!mwifiex_is_pattern_supported(&crule->patterns[i], 3636 byte_seq, 3637 MWIFIEX_COALESCE_MAX_BYTESEQ)) { 3638 mwifiex_dbg(priv->adapter, ERROR, 3639 "Pattern not supported\n"); 3640 return -EOPNOTSUPP; 3641 } 3642 3643 if (!crule->patterns[i].pkt_offset) { 3644 u8 pkt_type; 3645 3646 pkt_type = mwifiex_get_coalesce_pkt_type(byte_seq); 3647 if (pkt_type && mrule->pkt_type) { 3648 mwifiex_dbg(priv->adapter, ERROR, 3649 "Multiple packet types not allowed\n"); 3650 return -EOPNOTSUPP; 3651 } else if (pkt_type) { 3652 mrule->pkt_type = pkt_type; 3653 continue; 3654 } 3655 } 3656 3657 if (crule->condition == NL80211_COALESCE_CONDITION_MATCH) 3658 param->operation = RECV_FILTER_MATCH_TYPE_EQ; 3659 else 3660 param->operation = RECV_FILTER_MATCH_TYPE_NE; 3661 3662 param->operand_len = byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ]; 3663 memcpy(param->operand_byte_stream, byte_seq, 3664 param->operand_len); 3665 param->offset = crule->patterns[i].pkt_offset; 3666 param++; 3667 3668 mrule->num_of_fields++; 3669 } 3670 3671 if (!mrule->pkt_type) { 3672 mwifiex_dbg(priv->adapter, ERROR, 3673 "Packet type can not be determined\n"); 3674 return -EOPNOTSUPP; 3675 } 3676 3677 return 0; 3678 } 3679 3680 static int mwifiex_cfg80211_set_coalesce(struct wiphy *wiphy, 3681 struct cfg80211_coalesce *coalesce) 3682 { 3683 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy); 3684 int i, ret; 3685 struct mwifiex_ds_coalesce_cfg coalesce_cfg; 3686 struct mwifiex_private *priv = 3687 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA); 3688 3689 memset(&coalesce_cfg, 0, sizeof(coalesce_cfg)); 3690 if (!coalesce) { 3691 mwifiex_dbg(adapter, WARN, 3692 "Disable coalesce and reset all previous rules\n"); 3693 return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG, 3694 HostCmd_ACT_GEN_SET, 0, 3695 &coalesce_cfg, true); 3696 } 3697 3698 coalesce_cfg.num_of_rules = coalesce->n_rules; 3699 for (i = 0; i < coalesce->n_rules; i++) { 3700 ret = mwifiex_fill_coalesce_rule_info(priv, &coalesce->rules[i], 3701 &coalesce_cfg.rule[i]); 3702 if (ret) { 3703 mwifiex_dbg(adapter, ERROR, 3704 "Recheck the patterns provided for rule %d\n", 3705 i + 1); 3706 return ret; 3707 } 3708 } 3709 3710 return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG, 3711 HostCmd_ACT_GEN_SET, 0, &coalesce_cfg, true); 3712 } 3713 3714 /* cfg80211 ops handler for tdls_mgmt. 3715 * Function prepares TDLS action frame packets and forwards them to FW 3716 */ 3717 static int 3718 mwifiex_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev, 3719 const u8 *peer, u8 action_code, u8 dialog_token, 3720 u16 status_code, u32 peer_capability, 3721 bool initiator, const u8 *extra_ies, 3722 size_t extra_ies_len) 3723 { 3724 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 3725 int ret; 3726 3727 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)) 3728 return -ENOTSUPP; 3729 3730 /* make sure we are in station mode and connected */ 3731 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected)) 3732 return -ENOTSUPP; 3733 3734 switch (action_code) { 3735 case WLAN_TDLS_SETUP_REQUEST: 3736 mwifiex_dbg(priv->adapter, MSG, 3737 "Send TDLS Setup Request to %pM status_code=%d\n", 3738 peer, status_code); 3739 mwifiex_add_auto_tdls_peer(priv, peer); 3740 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code, 3741 dialog_token, status_code, 3742 extra_ies, extra_ies_len); 3743 break; 3744 case WLAN_TDLS_SETUP_RESPONSE: 3745 mwifiex_add_auto_tdls_peer(priv, peer); 3746 mwifiex_dbg(priv->adapter, MSG, 3747 "Send TDLS Setup Response to %pM status_code=%d\n", 3748 peer, status_code); 3749 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code, 3750 dialog_token, status_code, 3751 extra_ies, extra_ies_len); 3752 break; 3753 case WLAN_TDLS_SETUP_CONFIRM: 3754 mwifiex_dbg(priv->adapter, MSG, 3755 "Send TDLS Confirm to %pM status_code=%d\n", peer, 3756 status_code); 3757 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code, 3758 dialog_token, status_code, 3759 extra_ies, extra_ies_len); 3760 break; 3761 case WLAN_TDLS_TEARDOWN: 3762 mwifiex_dbg(priv->adapter, MSG, 3763 "Send TDLS Tear down to %pM\n", peer); 3764 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code, 3765 dialog_token, status_code, 3766 extra_ies, extra_ies_len); 3767 break; 3768 case WLAN_TDLS_DISCOVERY_REQUEST: 3769 mwifiex_dbg(priv->adapter, MSG, 3770 "Send TDLS Discovery Request to %pM\n", peer); 3771 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code, 3772 dialog_token, status_code, 3773 extra_ies, extra_ies_len); 3774 break; 3775 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES: 3776 mwifiex_dbg(priv->adapter, MSG, 3777 "Send TDLS Discovery Response to %pM\n", peer); 3778 ret = mwifiex_send_tdls_action_frame(priv, peer, action_code, 3779 dialog_token, status_code, 3780 extra_ies, extra_ies_len); 3781 break; 3782 default: 3783 mwifiex_dbg(priv->adapter, ERROR, 3784 "Unknown TDLS mgmt/action frame %pM\n", peer); 3785 ret = -EINVAL; 3786 break; 3787 } 3788 3789 return ret; 3790 } 3791 3792 static int 3793 mwifiex_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev, 3794 const u8 *peer, enum nl80211_tdls_operation action) 3795 { 3796 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 3797 3798 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) || 3799 !(wiphy->flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) 3800 return -ENOTSUPP; 3801 3802 /* make sure we are in station mode and connected */ 3803 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected)) 3804 return -ENOTSUPP; 3805 3806 mwifiex_dbg(priv->adapter, MSG, 3807 "TDLS peer=%pM, oper=%d\n", peer, action); 3808 3809 switch (action) { 3810 case NL80211_TDLS_ENABLE_LINK: 3811 action = MWIFIEX_TDLS_ENABLE_LINK; 3812 break; 3813 case NL80211_TDLS_DISABLE_LINK: 3814 action = MWIFIEX_TDLS_DISABLE_LINK; 3815 break; 3816 case NL80211_TDLS_TEARDOWN: 3817 /* shouldn't happen!*/ 3818 mwifiex_dbg(priv->adapter, ERROR, 3819 "tdls_oper: teardown from driver not supported\n"); 3820 return -EINVAL; 3821 case NL80211_TDLS_SETUP: 3822 /* shouldn't happen!*/ 3823 mwifiex_dbg(priv->adapter, ERROR, 3824 "tdls_oper: setup from driver not supported\n"); 3825 return -EINVAL; 3826 case NL80211_TDLS_DISCOVERY_REQ: 3827 /* shouldn't happen!*/ 3828 mwifiex_dbg(priv->adapter, ERROR, 3829 "tdls_oper: discovery from driver not supported\n"); 3830 return -EINVAL; 3831 default: 3832 mwifiex_dbg(priv->adapter, ERROR, 3833 "tdls_oper: operation not supported\n"); 3834 return -ENOTSUPP; 3835 } 3836 3837 return mwifiex_tdls_oper(priv, peer, action); 3838 } 3839 3840 static int 3841 mwifiex_cfg80211_tdls_chan_switch(struct wiphy *wiphy, struct net_device *dev, 3842 const u8 *addr, u8 oper_class, 3843 struct cfg80211_chan_def *chandef) 3844 { 3845 struct mwifiex_sta_node *sta_ptr; 3846 unsigned long flags; 3847 u16 chan; 3848 u8 second_chan_offset, band; 3849 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 3850 3851 spin_lock_irqsave(&priv->sta_list_spinlock, flags); 3852 sta_ptr = mwifiex_get_sta_entry(priv, addr); 3853 if (!sta_ptr) { 3854 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags); 3855 wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n", 3856 __func__, addr); 3857 return -ENOENT; 3858 } 3859 3860 if (!(sta_ptr->tdls_cap.extcap.ext_capab[3] & 3861 WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)) { 3862 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags); 3863 wiphy_err(wiphy, "%pM do not support tdls cs\n", addr); 3864 return -ENOENT; 3865 } 3866 3867 if (sta_ptr->tdls_status == TDLS_CHAN_SWITCHING || 3868 sta_ptr->tdls_status == TDLS_IN_OFF_CHAN) { 3869 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags); 3870 wiphy_err(wiphy, "channel switch is running, abort request\n"); 3871 return -EALREADY; 3872 } 3873 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags); 3874 3875 chan = chandef->chan->hw_value; 3876 second_chan_offset = mwifiex_get_sec_chan_offset(chan); 3877 band = chandef->chan->band; 3878 mwifiex_start_tdls_cs(priv, addr, chan, second_chan_offset, band); 3879 3880 return 0; 3881 } 3882 3883 static void 3884 mwifiex_cfg80211_tdls_cancel_chan_switch(struct wiphy *wiphy, 3885 struct net_device *dev, 3886 const u8 *addr) 3887 { 3888 struct mwifiex_sta_node *sta_ptr; 3889 unsigned long flags; 3890 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 3891 3892 spin_lock_irqsave(&priv->sta_list_spinlock, flags); 3893 sta_ptr = mwifiex_get_sta_entry(priv, addr); 3894 if (!sta_ptr) { 3895 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags); 3896 wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n", 3897 __func__, addr); 3898 } else if (!(sta_ptr->tdls_status == TDLS_CHAN_SWITCHING || 3899 sta_ptr->tdls_status == TDLS_IN_BASE_CHAN || 3900 sta_ptr->tdls_status == TDLS_IN_OFF_CHAN)) { 3901 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags); 3902 wiphy_err(wiphy, "tdls chan switch not initialize by %pM\n", 3903 addr); 3904 } else { 3905 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags); 3906 mwifiex_stop_tdls_cs(priv, addr); 3907 } 3908 } 3909 3910 static int 3911 mwifiex_cfg80211_add_station(struct wiphy *wiphy, struct net_device *dev, 3912 const u8 *mac, struct station_parameters *params) 3913 { 3914 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 3915 3916 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) 3917 return -ENOTSUPP; 3918 3919 /* make sure we are in station mode and connected */ 3920 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected) 3921 return -ENOTSUPP; 3922 3923 return mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CREATE_LINK); 3924 } 3925 3926 static int 3927 mwifiex_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, 3928 struct cfg80211_csa_settings *params) 3929 { 3930 struct ieee_types_header *chsw_ie; 3931 struct ieee80211_channel_sw_ie *channel_sw; 3932 int chsw_msec; 3933 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 3934 3935 if (priv->adapter->scan_processing) { 3936 mwifiex_dbg(priv->adapter, ERROR, 3937 "radar detection: scan in process...\n"); 3938 return -EBUSY; 3939 } 3940 3941 if (priv->wdev.cac_started) 3942 return -EBUSY; 3943 3944 if (cfg80211_chandef_identical(¶ms->chandef, 3945 &priv->dfs_chandef)) 3946 return -EINVAL; 3947 3948 chsw_ie = (void *)cfg80211_find_ie(WLAN_EID_CHANNEL_SWITCH, 3949 params->beacon_csa.tail, 3950 params->beacon_csa.tail_len); 3951 if (!chsw_ie) { 3952 mwifiex_dbg(priv->adapter, ERROR, 3953 "Could not parse channel switch announcement IE\n"); 3954 return -EINVAL; 3955 } 3956 3957 channel_sw = (void *)(chsw_ie + 1); 3958 if (channel_sw->mode) { 3959 if (netif_carrier_ok(priv->netdev)) 3960 netif_carrier_off(priv->netdev); 3961 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter); 3962 } 3963 3964 if (mwifiex_del_mgmt_ies(priv)) 3965 mwifiex_dbg(priv->adapter, ERROR, 3966 "Failed to delete mgmt IEs!\n"); 3967 3968 if (mwifiex_set_mgmt_ies(priv, ¶ms->beacon_csa)) { 3969 mwifiex_dbg(priv->adapter, ERROR, 3970 "%s: setting mgmt ies failed\n", __func__); 3971 return -EFAULT; 3972 } 3973 3974 memcpy(&priv->dfs_chandef, ¶ms->chandef, sizeof(priv->dfs_chandef)); 3975 memcpy(&priv->beacon_after, ¶ms->beacon_after, 3976 sizeof(priv->beacon_after)); 3977 3978 chsw_msec = max(channel_sw->count * priv->bss_cfg.beacon_period, 100); 3979 queue_delayed_work(priv->dfs_chan_sw_workqueue, &priv->dfs_chan_sw_work, 3980 msecs_to_jiffies(chsw_msec)); 3981 return 0; 3982 } 3983 3984 static int mwifiex_cfg80211_get_channel(struct wiphy *wiphy, 3985 struct wireless_dev *wdev, 3986 struct cfg80211_chan_def *chandef) 3987 { 3988 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev); 3989 struct mwifiex_bssdescriptor *curr_bss; 3990 struct ieee80211_channel *chan; 3991 enum nl80211_channel_type chan_type; 3992 enum nl80211_band band; 3993 int freq; 3994 int ret = -ENODATA; 3995 3996 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP && 3997 cfg80211_chandef_valid(&priv->bss_chandef)) { 3998 *chandef = priv->bss_chandef; 3999 ret = 0; 4000 } else if (priv->media_connected) { 4001 curr_bss = &priv->curr_bss_params.bss_descriptor; 4002 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band); 4003 freq = ieee80211_channel_to_frequency(curr_bss->channel, band); 4004 chan = ieee80211_get_channel(wiphy, freq); 4005 4006 if (priv->ht_param_present) { 4007 chan_type = mwifiex_get_chan_type(priv); 4008 cfg80211_chandef_create(chandef, chan, chan_type); 4009 } else { 4010 cfg80211_chandef_create(chandef, chan, 4011 NL80211_CHAN_NO_HT); 4012 } 4013 ret = 0; 4014 } 4015 4016 return ret; 4017 } 4018 4019 #ifdef CONFIG_NL80211_TESTMODE 4020 4021 enum mwifiex_tm_attr { 4022 __MWIFIEX_TM_ATTR_INVALID = 0, 4023 MWIFIEX_TM_ATTR_CMD = 1, 4024 MWIFIEX_TM_ATTR_DATA = 2, 4025 4026 /* keep last */ 4027 __MWIFIEX_TM_ATTR_AFTER_LAST, 4028 MWIFIEX_TM_ATTR_MAX = __MWIFIEX_TM_ATTR_AFTER_LAST - 1, 4029 }; 4030 4031 static const struct nla_policy mwifiex_tm_policy[MWIFIEX_TM_ATTR_MAX + 1] = { 4032 [MWIFIEX_TM_ATTR_CMD] = { .type = NLA_U32 }, 4033 [MWIFIEX_TM_ATTR_DATA] = { .type = NLA_BINARY, 4034 .len = MWIFIEX_SIZE_OF_CMD_BUFFER }, 4035 }; 4036 4037 enum mwifiex_tm_command { 4038 MWIFIEX_TM_CMD_HOSTCMD = 0, 4039 }; 4040 4041 static int mwifiex_tm_cmd(struct wiphy *wiphy, struct wireless_dev *wdev, 4042 void *data, int len) 4043 { 4044 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev); 4045 struct mwifiex_ds_misc_cmd *hostcmd; 4046 struct nlattr *tb[MWIFIEX_TM_ATTR_MAX + 1]; 4047 struct sk_buff *skb; 4048 int err; 4049 4050 if (!priv) 4051 return -EINVAL; 4052 4053 err = nla_parse(tb, MWIFIEX_TM_ATTR_MAX, data, len, mwifiex_tm_policy, 4054 NULL); 4055 if (err) 4056 return err; 4057 4058 if (!tb[MWIFIEX_TM_ATTR_CMD]) 4059 return -EINVAL; 4060 4061 switch (nla_get_u32(tb[MWIFIEX_TM_ATTR_CMD])) { 4062 case MWIFIEX_TM_CMD_HOSTCMD: 4063 if (!tb[MWIFIEX_TM_ATTR_DATA]) 4064 return -EINVAL; 4065 4066 hostcmd = kzalloc(sizeof(*hostcmd), GFP_KERNEL); 4067 if (!hostcmd) 4068 return -ENOMEM; 4069 4070 hostcmd->len = nla_len(tb[MWIFIEX_TM_ATTR_DATA]); 4071 memcpy(hostcmd->cmd, nla_data(tb[MWIFIEX_TM_ATTR_DATA]), 4072 hostcmd->len); 4073 4074 if (mwifiex_send_cmd(priv, 0, 0, 0, hostcmd, true)) { 4075 dev_err(priv->adapter->dev, "Failed to process hostcmd\n"); 4076 return -EFAULT; 4077 } 4078 4079 /* process hostcmd response*/ 4080 skb = cfg80211_testmode_alloc_reply_skb(wiphy, hostcmd->len); 4081 if (!skb) 4082 return -ENOMEM; 4083 err = nla_put(skb, MWIFIEX_TM_ATTR_DATA, 4084 hostcmd->len, hostcmd->cmd); 4085 if (err) { 4086 kfree_skb(skb); 4087 return -EMSGSIZE; 4088 } 4089 4090 err = cfg80211_testmode_reply(skb); 4091 kfree(hostcmd); 4092 return err; 4093 default: 4094 return -EOPNOTSUPP; 4095 } 4096 } 4097 #endif 4098 4099 static int 4100 mwifiex_cfg80211_start_radar_detection(struct wiphy *wiphy, 4101 struct net_device *dev, 4102 struct cfg80211_chan_def *chandef, 4103 u32 cac_time_ms) 4104 { 4105 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 4106 struct mwifiex_radar_params radar_params; 4107 4108 if (priv->adapter->scan_processing) { 4109 mwifiex_dbg(priv->adapter, ERROR, 4110 "radar detection: scan already in process...\n"); 4111 return -EBUSY; 4112 } 4113 4114 if (!mwifiex_is_11h_active(priv)) { 4115 mwifiex_dbg(priv->adapter, INFO, 4116 "Enable 11h extensions in FW\n"); 4117 if (mwifiex_11h_activate(priv, true)) { 4118 mwifiex_dbg(priv->adapter, ERROR, 4119 "Failed to activate 11h extensions!!"); 4120 return -1; 4121 } 4122 priv->state_11h.is_11h_active = true; 4123 } 4124 4125 memset(&radar_params, 0, sizeof(struct mwifiex_radar_params)); 4126 radar_params.chandef = chandef; 4127 radar_params.cac_time_ms = cac_time_ms; 4128 4129 memcpy(&priv->dfs_chandef, chandef, sizeof(priv->dfs_chandef)); 4130 4131 if (mwifiex_send_cmd(priv, HostCmd_CMD_CHAN_REPORT_REQUEST, 4132 HostCmd_ACT_GEN_SET, 0, &radar_params, true)) 4133 return -1; 4134 4135 queue_delayed_work(priv->dfs_cac_workqueue, &priv->dfs_cac_work, 4136 msecs_to_jiffies(cac_time_ms)); 4137 return 0; 4138 } 4139 4140 static int 4141 mwifiex_cfg80211_change_station(struct wiphy *wiphy, struct net_device *dev, 4142 const u8 *mac, 4143 struct station_parameters *params) 4144 { 4145 int ret; 4146 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 4147 4148 /* we support change_station handler only for TDLS peers*/ 4149 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) 4150 return -ENOTSUPP; 4151 4152 /* make sure we are in station mode and connected */ 4153 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected) 4154 return -ENOTSUPP; 4155 4156 priv->sta_params = params; 4157 4158 ret = mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CONFIG_LINK); 4159 priv->sta_params = NULL; 4160 4161 return ret; 4162 } 4163 4164 /* station cfg80211 operations */ 4165 static struct cfg80211_ops mwifiex_cfg80211_ops = { 4166 .add_virtual_intf = mwifiex_add_virtual_intf, 4167 .del_virtual_intf = mwifiex_del_virtual_intf, 4168 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf, 4169 .scan = mwifiex_cfg80211_scan, 4170 .connect = mwifiex_cfg80211_connect, 4171 .disconnect = mwifiex_cfg80211_disconnect, 4172 .get_station = mwifiex_cfg80211_get_station, 4173 .dump_station = mwifiex_cfg80211_dump_station, 4174 .dump_survey = mwifiex_cfg80211_dump_survey, 4175 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params, 4176 .join_ibss = mwifiex_cfg80211_join_ibss, 4177 .leave_ibss = mwifiex_cfg80211_leave_ibss, 4178 .add_key = mwifiex_cfg80211_add_key, 4179 .del_key = mwifiex_cfg80211_del_key, 4180 .set_default_mgmt_key = mwifiex_cfg80211_set_default_mgmt_key, 4181 .mgmt_tx = mwifiex_cfg80211_mgmt_tx, 4182 .mgmt_frame_register = mwifiex_cfg80211_mgmt_frame_register, 4183 .remain_on_channel = mwifiex_cfg80211_remain_on_channel, 4184 .cancel_remain_on_channel = mwifiex_cfg80211_cancel_remain_on_channel, 4185 .set_default_key = mwifiex_cfg80211_set_default_key, 4186 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt, 4187 .set_tx_power = mwifiex_cfg80211_set_tx_power, 4188 .get_tx_power = mwifiex_cfg80211_get_tx_power, 4189 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask, 4190 .start_ap = mwifiex_cfg80211_start_ap, 4191 .stop_ap = mwifiex_cfg80211_stop_ap, 4192 .change_beacon = mwifiex_cfg80211_change_beacon, 4193 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config, 4194 .set_antenna = mwifiex_cfg80211_set_antenna, 4195 .get_antenna = mwifiex_cfg80211_get_antenna, 4196 .del_station = mwifiex_cfg80211_del_station, 4197 .sched_scan_start = mwifiex_cfg80211_sched_scan_start, 4198 .sched_scan_stop = mwifiex_cfg80211_sched_scan_stop, 4199 #ifdef CONFIG_PM 4200 .suspend = mwifiex_cfg80211_suspend, 4201 .resume = mwifiex_cfg80211_resume, 4202 .set_wakeup = mwifiex_cfg80211_set_wakeup, 4203 .set_rekey_data = mwifiex_set_rekey_data, 4204 #endif 4205 .set_coalesce = mwifiex_cfg80211_set_coalesce, 4206 .tdls_mgmt = mwifiex_cfg80211_tdls_mgmt, 4207 .tdls_oper = mwifiex_cfg80211_tdls_oper, 4208 .tdls_channel_switch = mwifiex_cfg80211_tdls_chan_switch, 4209 .tdls_cancel_channel_switch = mwifiex_cfg80211_tdls_cancel_chan_switch, 4210 .add_station = mwifiex_cfg80211_add_station, 4211 .change_station = mwifiex_cfg80211_change_station, 4212 CFG80211_TESTMODE_CMD(mwifiex_tm_cmd) 4213 .get_channel = mwifiex_cfg80211_get_channel, 4214 .start_radar_detection = mwifiex_cfg80211_start_radar_detection, 4215 .channel_switch = mwifiex_cfg80211_channel_switch, 4216 }; 4217 4218 #ifdef CONFIG_PM 4219 static const struct wiphy_wowlan_support mwifiex_wowlan_support = { 4220 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT | 4221 WIPHY_WOWLAN_NET_DETECT | WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | 4222 WIPHY_WOWLAN_GTK_REKEY_FAILURE, 4223 .n_patterns = MWIFIEX_MEF_MAX_FILTERS, 4224 .pattern_min_len = 1, 4225 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN, 4226 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN, 4227 .max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS, 4228 }; 4229 4230 static const struct wiphy_wowlan_support mwifiex_wowlan_support_no_gtk = { 4231 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT | 4232 WIPHY_WOWLAN_NET_DETECT, 4233 .n_patterns = MWIFIEX_MEF_MAX_FILTERS, 4234 .pattern_min_len = 1, 4235 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN, 4236 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN, 4237 .max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS, 4238 }; 4239 #endif 4240 4241 static bool mwifiex_is_valid_alpha2(const char *alpha2) 4242 { 4243 if (!alpha2 || strlen(alpha2) != 2) 4244 return false; 4245 4246 if (isalpha(alpha2[0]) && isalpha(alpha2[1])) 4247 return true; 4248 4249 return false; 4250 } 4251 4252 static const struct wiphy_coalesce_support mwifiex_coalesce_support = { 4253 .n_rules = MWIFIEX_COALESCE_MAX_RULES, 4254 .max_delay = MWIFIEX_MAX_COALESCING_DELAY, 4255 .n_patterns = MWIFIEX_COALESCE_MAX_FILTERS, 4256 .pattern_min_len = 1, 4257 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN, 4258 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN, 4259 }; 4260 4261 int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter) 4262 { 4263 u32 n_channels_bg, n_channels_a = 0; 4264 4265 n_channels_bg = mwifiex_band_2ghz.n_channels; 4266 4267 if (adapter->config_bands & BAND_A) 4268 n_channels_a = mwifiex_band_5ghz.n_channels; 4269 4270 /* allocate twice the number total channels, since the driver issues an 4271 * additional active scan request for hidden SSIDs on passive channels. 4272 */ 4273 adapter->num_in_chan_stats = 2 * (n_channels_bg + n_channels_a); 4274 adapter->chan_stats = vmalloc(array_size(sizeof(*adapter->chan_stats), 4275 adapter->num_in_chan_stats)); 4276 4277 if (!adapter->chan_stats) 4278 return -ENOMEM; 4279 4280 return 0; 4281 } 4282 4283 /* 4284 * This function registers the device with CFG802.11 subsystem. 4285 * 4286 * The function creates the wireless device/wiphy, populates it with 4287 * default parameters and handler function pointers, and finally 4288 * registers the device. 4289 */ 4290 4291 int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter) 4292 { 4293 int ret; 4294 void *wdev_priv; 4295 struct wiphy *wiphy; 4296 struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA]; 4297 u8 *country_code; 4298 u32 thr, retry; 4299 4300 /* create a new wiphy for use with cfg80211 */ 4301 wiphy = wiphy_new(&mwifiex_cfg80211_ops, 4302 sizeof(struct mwifiex_adapter *)); 4303 if (!wiphy) { 4304 mwifiex_dbg(adapter, ERROR, 4305 "%s: creating new wiphy\n", __func__); 4306 return -ENOMEM; 4307 } 4308 wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH; 4309 wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN; 4310 wiphy->mgmt_stypes = mwifiex_mgmt_stypes; 4311 wiphy->max_remain_on_channel_duration = 5000; 4312 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | 4313 BIT(NL80211_IFTYPE_ADHOC) | 4314 BIT(NL80211_IFTYPE_P2P_CLIENT) | 4315 BIT(NL80211_IFTYPE_P2P_GO) | 4316 BIT(NL80211_IFTYPE_AP); 4317 4318 wiphy->bands[NL80211_BAND_2GHZ] = &mwifiex_band_2ghz; 4319 if (adapter->config_bands & BAND_A) 4320 wiphy->bands[NL80211_BAND_5GHZ] = &mwifiex_band_5ghz; 4321 else 4322 wiphy->bands[NL80211_BAND_5GHZ] = NULL; 4323 4324 if (adapter->drcs_enabled && ISSUPP_DRCS_ENABLED(adapter->fw_cap_info)) 4325 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_drcs; 4326 else if (adapter->is_hw_11ac_capable) 4327 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_vht; 4328 else 4329 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta; 4330 wiphy->n_iface_combinations = 1; 4331 4332 /* Initialize cipher suits */ 4333 wiphy->cipher_suites = mwifiex_cipher_suites; 4334 wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites); 4335 4336 if (adapter->regd) { 4337 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG | 4338 REGULATORY_DISABLE_BEACON_HINTS | 4339 REGULATORY_COUNTRY_IE_IGNORE; 4340 wiphy_apply_custom_regulatory(wiphy, adapter->regd); 4341 } 4342 4343 ether_addr_copy(wiphy->perm_addr, adapter->perm_addr); 4344 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; 4345 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME | 4346 WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD | 4347 WIPHY_FLAG_AP_UAPSD | 4348 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL | 4349 WIPHY_FLAG_HAS_CHANNEL_SWITCH | 4350 WIPHY_FLAG_PS_ON_BY_DEFAULT; 4351 4352 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info)) 4353 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS | 4354 WIPHY_FLAG_TDLS_EXTERNAL_SETUP; 4355 4356 #ifdef CONFIG_PM 4357 if (ISSUPP_FIRMWARE_SUPPLICANT(priv->adapter->fw_cap_info)) 4358 wiphy->wowlan = &mwifiex_wowlan_support; 4359 else 4360 wiphy->wowlan = &mwifiex_wowlan_support_no_gtk; 4361 #endif 4362 4363 wiphy->coalesce = &mwifiex_coalesce_support; 4364 4365 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS | 4366 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 | 4367 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P; 4368 4369 wiphy->max_sched_scan_reqs = 1; 4370 wiphy->max_sched_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH; 4371 wiphy->max_sched_scan_ie_len = MWIFIEX_MAX_VSIE_LEN; 4372 wiphy->max_match_sets = MWIFIEX_MAX_SSID_LIST_LENGTH; 4373 4374 wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1; 4375 wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1; 4376 4377 wiphy->features |= NL80211_FEATURE_HT_IBSS | 4378 NL80211_FEATURE_INACTIVITY_TIMER | 4379 NL80211_FEATURE_LOW_PRIORITY_SCAN | 4380 NL80211_FEATURE_NEED_OBSS_SCAN; 4381 4382 if (ISSUPP_RANDOM_MAC(adapter->fw_cap_info)) 4383 wiphy->features |= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR | 4384 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR | 4385 NL80211_FEATURE_ND_RANDOM_MAC_ADDR; 4386 4387 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info)) 4388 wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH; 4389 4390 if (adapter->fw_api_ver == MWIFIEX_FW_V15) 4391 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS; 4392 4393 /* Reserve space for mwifiex specific private data for BSS */ 4394 wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv); 4395 4396 wiphy->reg_notifier = mwifiex_reg_notifier; 4397 4398 /* Set struct mwifiex_adapter pointer in wiphy_priv */ 4399 wdev_priv = wiphy_priv(wiphy); 4400 *(unsigned long *)wdev_priv = (unsigned long)adapter; 4401 4402 set_wiphy_dev(wiphy, priv->adapter->dev); 4403 4404 ret = wiphy_register(wiphy); 4405 if (ret < 0) { 4406 mwifiex_dbg(adapter, ERROR, 4407 "%s: wiphy_register failed: %d\n", __func__, ret); 4408 wiphy_free(wiphy); 4409 return ret; 4410 } 4411 4412 if (!adapter->regd) { 4413 if (reg_alpha2 && mwifiex_is_valid_alpha2(reg_alpha2)) { 4414 mwifiex_dbg(adapter, INFO, 4415 "driver hint alpha2: %2.2s\n", reg_alpha2); 4416 regulatory_hint(wiphy, reg_alpha2); 4417 } else { 4418 if (adapter->region_code == 0x00) { 4419 mwifiex_dbg(adapter, WARN, 4420 "Ignore world regulatory domain\n"); 4421 } else { 4422 wiphy->regulatory_flags |= 4423 REGULATORY_DISABLE_BEACON_HINTS | 4424 REGULATORY_COUNTRY_IE_IGNORE; 4425 country_code = 4426 mwifiex_11d_code_2_region( 4427 adapter->region_code); 4428 if (country_code && 4429 regulatory_hint(wiphy, country_code)) 4430 mwifiex_dbg(priv->adapter, ERROR, 4431 "regulatory_hint() failed\n"); 4432 } 4433 } 4434 } 4435 4436 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB, 4437 HostCmd_ACT_GEN_GET, FRAG_THRESH_I, &thr, true); 4438 wiphy->frag_threshold = thr; 4439 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB, 4440 HostCmd_ACT_GEN_GET, RTS_THRESH_I, &thr, true); 4441 wiphy->rts_threshold = thr; 4442 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB, 4443 HostCmd_ACT_GEN_GET, SHORT_RETRY_LIM_I, &retry, true); 4444 wiphy->retry_short = (u8) retry; 4445 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB, 4446 HostCmd_ACT_GEN_GET, LONG_RETRY_LIM_I, &retry, true); 4447 wiphy->retry_long = (u8) retry; 4448 4449 adapter->wiphy = wiphy; 4450 return ret; 4451 } 4452