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