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