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