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