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