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