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