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