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