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 net_device *netdev, 145 int link_id, u8 key_index, bool pairwise, 146 const u8 *mac_addr) 147 { 148 struct mwifiex_private *priv = mwifiex_netdev_get_priv(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 net_device *netdev, 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(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 net_device *netdev, 522 int link_id, 523 u8 key_index) 524 { 525 struct mwifiex_private *priv = mwifiex_netdev_get_priv(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(sizeof(*bss_cfg), GFP_KERNEL); 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 net_device *dev, 1558 const u8 *mac, struct station_info *sinfo) 1559 { 1560 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 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 net_device *dev, 1575 int idx, u8 *mac, struct station_info *sinfo) 1576 { 1577 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 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 net_device *dev, 1905 struct station_del_parameters *params) 1906 { 1907 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 1908 struct mwifiex_sta_node *sta_node; 1909 u8 deauth_mac[ETH_ALEN]; 1910 1911 if (!priv->bss_started && priv->wdev.links[0].cac_started) { 1912 mwifiex_dbg(priv->adapter, INFO, "%s: abort CAC!\n", __func__); 1913 mwifiex_abort_cac(priv); 1914 } 1915 1916 if (list_empty(&priv->sta_list) || !priv->bss_started) 1917 return 0; 1918 1919 if (!params->mac || is_broadcast_ether_addr(params->mac)) 1920 return 0; 1921 1922 mwifiex_dbg(priv->adapter, INFO, "%s: mac address %pM\n", 1923 __func__, params->mac); 1924 1925 eth_zero_addr(deauth_mac); 1926 1927 spin_lock_bh(&priv->sta_list_spinlock); 1928 sta_node = mwifiex_get_sta_entry(priv, params->mac); 1929 if (sta_node) 1930 ether_addr_copy(deauth_mac, params->mac); 1931 spin_unlock_bh(&priv->sta_list_spinlock); 1932 1933 if (is_valid_ether_addr(deauth_mac)) { 1934 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_STA_DEAUTH, 1935 HostCmd_ACT_GEN_SET, 0, 1936 deauth_mac, true)) 1937 return -1; 1938 } 1939 1940 return 0; 1941 } 1942 1943 static int 1944 mwifiex_cfg80211_set_antenna(struct wiphy *wiphy, int radio_idx, u32 tx_ant, 1945 u32 rx_ant) 1946 { 1947 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy); 1948 struct mwifiex_private *priv = mwifiex_get_priv(adapter, 1949 MWIFIEX_BSS_ROLE_ANY); 1950 struct mwifiex_ds_ant_cfg ant_cfg; 1951 1952 if (!tx_ant || !rx_ant) 1953 return -EOPNOTSUPP; 1954 1955 if (adapter->hw_dev_mcs_support != HT_STREAM_2X2) { 1956 /* Not a MIMO chip. User should provide specific antenna number 1957 * for Tx/Rx path or enable all antennas for diversity 1958 */ 1959 if (tx_ant != rx_ant) 1960 return -EOPNOTSUPP; 1961 1962 if ((tx_ant & (tx_ant - 1)) && 1963 (tx_ant != BIT(adapter->number_of_antenna) - 1)) 1964 return -EOPNOTSUPP; 1965 1966 if ((tx_ant == BIT(adapter->number_of_antenna) - 1) && 1967 (priv->adapter->number_of_antenna > 1)) { 1968 tx_ant = RF_ANTENNA_AUTO; 1969 rx_ant = RF_ANTENNA_AUTO; 1970 } 1971 } else { 1972 struct ieee80211_sta_ht_cap *ht_info; 1973 int rx_mcs_supp; 1974 enum nl80211_band band; 1975 1976 if ((tx_ant == 0x1 && rx_ant == 0x1)) { 1977 adapter->user_dev_mcs_support = HT_STREAM_1X1; 1978 if (adapter->is_hw_11ac_capable) 1979 adapter->usr_dot_11ac_mcs_support = 1980 MWIFIEX_11AC_MCS_MAP_1X1; 1981 } else { 1982 adapter->user_dev_mcs_support = HT_STREAM_2X2; 1983 if (adapter->is_hw_11ac_capable) 1984 adapter->usr_dot_11ac_mcs_support = 1985 MWIFIEX_11AC_MCS_MAP_2X2; 1986 } 1987 1988 for (band = 0; band < NUM_NL80211_BANDS; band++) { 1989 if (!adapter->wiphy->bands[band]) 1990 continue; 1991 1992 ht_info = &adapter->wiphy->bands[band]->ht_cap; 1993 rx_mcs_supp = 1994 GET_RXMCSSUPP(adapter->user_dev_mcs_support); 1995 memset(&ht_info->mcs, 0, adapter->number_of_antenna); 1996 memset(&ht_info->mcs, 0xff, rx_mcs_supp); 1997 } 1998 } 1999 2000 ant_cfg.tx_ant = tx_ant; 2001 ant_cfg.rx_ant = rx_ant; 2002 2003 return mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA, 2004 HostCmd_ACT_GEN_SET, 0, &ant_cfg, true); 2005 } 2006 2007 static int 2008 mwifiex_cfg80211_get_antenna(struct wiphy *wiphy, int radio_idx, u32 *tx_ant, 2009 u32 *rx_ant) 2010 { 2011 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy); 2012 struct mwifiex_private *priv = mwifiex_get_priv(adapter, 2013 MWIFIEX_BSS_ROLE_ANY); 2014 mwifiex_send_cmd(priv, HostCmd_CMD_RF_ANTENNA, 2015 HostCmd_ACT_GEN_GET, 0, NULL, true); 2016 2017 *tx_ant = priv->tx_ant; 2018 *rx_ant = priv->rx_ant; 2019 2020 return 0; 2021 } 2022 2023 /* cfg80211 operation handler for stop ap. 2024 * Function stops BSS running at uAP interface. 2025 */ 2026 static int mwifiex_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *dev, 2027 unsigned int link_id) 2028 { 2029 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 2030 2031 mwifiex_abort_cac(priv); 2032 2033 if (mwifiex_del_mgmt_ies(priv)) 2034 mwifiex_dbg(priv->adapter, ERROR, 2035 "Failed to delete mgmt IEs!\n"); 2036 2037 priv->ap_11n_enabled = 0; 2038 memset(&priv->bss_cfg, 0, sizeof(priv->bss_cfg)); 2039 2040 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_STOP, 2041 HostCmd_ACT_GEN_SET, 0, NULL, true)) { 2042 mwifiex_dbg(priv->adapter, ERROR, 2043 "Failed to stop the BSS\n"); 2044 return -1; 2045 } 2046 2047 if (mwifiex_send_cmd(priv, HOST_CMD_APCMD_SYS_RESET, 2048 HostCmd_ACT_GEN_SET, 0, NULL, true)) { 2049 mwifiex_dbg(priv->adapter, ERROR, 2050 "Failed to reset BSS\n"); 2051 return -1; 2052 } 2053 2054 if (netif_carrier_ok(priv->netdev)) 2055 netif_carrier_off(priv->netdev); 2056 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter); 2057 2058 return 0; 2059 } 2060 2061 /* cfg80211 operation handler for start_ap. 2062 * Function sets beacon period, DTIM period, SSID and security into 2063 * AP config structure. 2064 * AP is configured with these settings and BSS is started. 2065 */ 2066 static int mwifiex_cfg80211_start_ap(struct wiphy *wiphy, 2067 struct net_device *dev, 2068 struct cfg80211_ap_settings *params) 2069 { 2070 struct mwifiex_uap_bss_param *bss_cfg; 2071 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 2072 2073 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_UAP) 2074 return -1; 2075 2076 bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL); 2077 if (!bss_cfg) 2078 return -ENOMEM; 2079 2080 mwifiex_set_sys_config_invalid_data(bss_cfg); 2081 2082 memcpy(bss_cfg->mac_addr, priv->curr_addr, ETH_ALEN); 2083 2084 if (params->beacon_interval) 2085 bss_cfg->beacon_period = params->beacon_interval; 2086 if (params->dtim_period) 2087 bss_cfg->dtim_period = params->dtim_period; 2088 2089 if (params->ssid && params->ssid_len) { 2090 memcpy(bss_cfg->ssid.ssid, params->ssid, params->ssid_len); 2091 bss_cfg->ssid.ssid_len = params->ssid_len; 2092 } 2093 if (params->inactivity_timeout > 0) { 2094 /* sta_ao_timer/ps_sta_ao_timer is in unit of 100ms */ 2095 bss_cfg->sta_ao_timer = 10 * params->inactivity_timeout; 2096 bss_cfg->ps_sta_ao_timer = 10 * params->inactivity_timeout; 2097 } 2098 2099 switch (params->hidden_ssid) { 2100 case NL80211_HIDDEN_SSID_NOT_IN_USE: 2101 bss_cfg->bcast_ssid_ctl = 1; 2102 break; 2103 case NL80211_HIDDEN_SSID_ZERO_LEN: 2104 bss_cfg->bcast_ssid_ctl = 0; 2105 break; 2106 case NL80211_HIDDEN_SSID_ZERO_CONTENTS: 2107 bss_cfg->bcast_ssid_ctl = 2; 2108 break; 2109 default: 2110 kfree(bss_cfg); 2111 return -EINVAL; 2112 } 2113 2114 mwifiex_uap_set_channel(priv, bss_cfg, params->chandef); 2115 mwifiex_set_uap_rates(bss_cfg, params); 2116 2117 if (mwifiex_set_secure_params(priv, bss_cfg, params)) { 2118 mwifiex_dbg(priv->adapter, ERROR, 2119 "Failed to parse security parameters!\n"); 2120 goto out; 2121 } 2122 2123 mwifiex_set_ht_params(priv, bss_cfg, params); 2124 2125 if (priv->adapter->is_hw_11ac_capable) { 2126 mwifiex_set_vht_params(priv, bss_cfg, params); 2127 mwifiex_set_vht_width(priv, params->chandef.width, 2128 priv->ap_11ac_enabled); 2129 } 2130 2131 if (priv->ap_11ac_enabled) 2132 mwifiex_set_11ac_ba_params(priv); 2133 else 2134 mwifiex_set_ba_params(priv); 2135 2136 mwifiex_set_wmm_params(priv, bss_cfg, params); 2137 2138 if (mwifiex_is_11h_active(priv)) 2139 mwifiex_set_tpc_params(priv, bss_cfg, params); 2140 2141 if (mwifiex_is_11h_active(priv) && 2142 !cfg80211_chandef_dfs_required(wiphy, ¶ms->chandef, 2143 priv->bss_mode)) { 2144 mwifiex_dbg(priv->adapter, INFO, 2145 "Disable 11h extensions in FW\n"); 2146 if (mwifiex_11h_activate(priv, false)) { 2147 mwifiex_dbg(priv->adapter, ERROR, 2148 "Failed to disable 11h extensions!!"); 2149 goto out; 2150 } 2151 priv->state_11h.is_11h_active = false; 2152 } 2153 2154 mwifiex_config_uap_11d(priv, ¶ms->beacon); 2155 2156 if (mwifiex_config_start_uap(priv, bss_cfg)) { 2157 mwifiex_dbg(priv->adapter, ERROR, 2158 "Failed to start AP\n"); 2159 goto out; 2160 } 2161 2162 if (mwifiex_set_mgmt_ies(priv, ¶ms->beacon)) 2163 goto out; 2164 2165 if (!netif_carrier_ok(priv->netdev)) 2166 netif_carrier_on(priv->netdev); 2167 mwifiex_wake_up_net_dev_queue(priv->netdev, priv->adapter); 2168 2169 memcpy(&priv->bss_cfg, bss_cfg, sizeof(priv->bss_cfg)); 2170 kfree(bss_cfg); 2171 return 0; 2172 2173 out: 2174 kfree(bss_cfg); 2175 return -1; 2176 } 2177 2178 /* 2179 * CFG802.11 operation handler for disconnection request. 2180 * 2181 * This function does not work when there is already a disconnection 2182 * procedure going on. 2183 */ 2184 static int 2185 mwifiex_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev, 2186 u16 reason_code) 2187 { 2188 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 2189 2190 if (!mwifiex_stop_bg_scan(priv)) 2191 cfg80211_sched_scan_stopped_locked(priv->wdev.wiphy, 0); 2192 2193 if (mwifiex_deauthenticate(priv, NULL)) 2194 return -EFAULT; 2195 2196 eth_zero_addr(priv->cfg_bssid); 2197 priv->hs2_enabled = false; 2198 2199 return 0; 2200 } 2201 2202 /* 2203 * This function informs the CFG802.11 subsystem of a new IBSS. 2204 * 2205 * The following information are sent to the CFG802.11 subsystem 2206 * to register the new IBSS. If we do not register the new IBSS, 2207 * a kernel panic will result. 2208 * - SSID 2209 * - SSID length 2210 * - BSSID 2211 * - Channel 2212 */ 2213 static int mwifiex_cfg80211_inform_ibss_bss(struct mwifiex_private *priv) 2214 { 2215 struct ieee80211_channel *chan; 2216 struct mwifiex_bss_info bss_info; 2217 struct cfg80211_bss *bss; 2218 int ie_len; 2219 u8 ie_buf[IEEE80211_MAX_SSID_LEN + sizeof(struct ieee_types_header)]; 2220 enum nl80211_band band; 2221 2222 if (mwifiex_get_bss_info(priv, &bss_info)) 2223 return -1; 2224 2225 ie_buf[0] = WLAN_EID_SSID; 2226 ie_buf[1] = bss_info.ssid.ssid_len; 2227 2228 memcpy(&ie_buf[sizeof(struct ieee_types_header)], 2229 &bss_info.ssid.ssid, bss_info.ssid.ssid_len); 2230 ie_len = ie_buf[1] + sizeof(struct ieee_types_header); 2231 2232 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band); 2233 chan = ieee80211_get_channel(priv->wdev.wiphy, 2234 ieee80211_channel_to_frequency(bss_info.bss_chan, 2235 band)); 2236 2237 bss = cfg80211_inform_bss(priv->wdev.wiphy, chan, 2238 CFG80211_BSS_FTYPE_UNKNOWN, 2239 bss_info.bssid, 0, WLAN_CAPABILITY_IBSS, 2240 0, ie_buf, ie_len, 0, GFP_KERNEL); 2241 if (bss) { 2242 cfg80211_put_bss(priv->wdev.wiphy, bss); 2243 ether_addr_copy(priv->cfg_bssid, bss_info.bssid); 2244 } 2245 2246 return 0; 2247 } 2248 2249 /* 2250 * This function connects with a BSS. 2251 * 2252 * This function handles both Infra and Ad-Hoc modes. It also performs 2253 * validity checking on the provided parameters, disconnects from the 2254 * current BSS (if any), sets up the association/scan parameters, 2255 * including security settings, and performs specific SSID scan before 2256 * trying to connect. 2257 * 2258 * For Infra mode, the function returns failure if the specified SSID 2259 * is not found in scan table. However, for Ad-Hoc mode, it can create 2260 * the IBSS if it does not exist. On successful completion in either case, 2261 * the function notifies the CFG802.11 subsystem of the new BSS connection. 2262 */ 2263 static int 2264 mwifiex_cfg80211_assoc(struct mwifiex_private *priv, size_t ssid_len, 2265 const u8 *ssid, const u8 *bssid, int mode, 2266 struct ieee80211_channel *channel, 2267 struct cfg80211_connect_params *sme, bool privacy, 2268 struct cfg80211_bss **sel_bss) 2269 { 2270 struct cfg80211_ssid req_ssid; 2271 int ret, auth_type = 0; 2272 struct cfg80211_bss *bss = NULL; 2273 u8 is_scanning_required = 0; 2274 2275 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid)); 2276 2277 req_ssid.ssid_len = ssid_len; 2278 if (ssid_len > IEEE80211_MAX_SSID_LEN) { 2279 mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n"); 2280 return -EINVAL; 2281 } 2282 2283 memcpy(req_ssid.ssid, ssid, ssid_len); 2284 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) { 2285 mwifiex_dbg(priv->adapter, ERROR, "invalid SSID - aborting\n"); 2286 return -EINVAL; 2287 } 2288 2289 /* As this is new association, clear locally stored 2290 * keys and security related flags */ 2291 priv->sec_info.wpa_enabled = false; 2292 priv->sec_info.wpa2_enabled = false; 2293 priv->wep_key_curr_index = 0; 2294 priv->sec_info.encryption_mode = 0; 2295 priv->sec_info.is_authtype_auto = 0; 2296 ret = mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1); 2297 2298 if (mode == NL80211_IFTYPE_ADHOC) { 2299 u16 enable = true; 2300 2301 /* set ibss coalescing_status */ 2302 ret = mwifiex_send_cmd( 2303 priv, 2304 HostCmd_CMD_802_11_IBSS_COALESCING_STATUS, 2305 HostCmd_ACT_GEN_SET, 0, &enable, true); 2306 if (ret) 2307 return ret; 2308 2309 /* "privacy" is set only for ad-hoc mode */ 2310 if (privacy) { 2311 /* 2312 * Keep WLAN_CIPHER_SUITE_WEP104 for now so that 2313 * the firmware can find a matching network from the 2314 * scan. The cfg80211 does not give us the encryption 2315 * mode at this stage so just setting it to WEP here. 2316 */ 2317 priv->sec_info.encryption_mode = 2318 WLAN_CIPHER_SUITE_WEP104; 2319 priv->sec_info.authentication_mode = 2320 NL80211_AUTHTYPE_OPEN_SYSTEM; 2321 } 2322 2323 goto done; 2324 } 2325 2326 /* Now handle infra mode. "sme" is valid for infra mode only */ 2327 if (sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) { 2328 auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM; 2329 priv->sec_info.is_authtype_auto = 1; 2330 } else { 2331 auth_type = sme->auth_type; 2332 } 2333 2334 if (sme->crypto.n_ciphers_pairwise) { 2335 priv->sec_info.encryption_mode = 2336 sme->crypto.ciphers_pairwise[0]; 2337 priv->sec_info.authentication_mode = auth_type; 2338 } 2339 2340 if (sme->crypto.cipher_group) { 2341 priv->sec_info.encryption_mode = sme->crypto.cipher_group; 2342 priv->sec_info.authentication_mode = auth_type; 2343 } 2344 if (sme->ie) 2345 ret = mwifiex_set_gen_ie(priv, sme->ie, sme->ie_len); 2346 2347 if (sme->key) { 2348 if (mwifiex_is_alg_wep(priv->sec_info.encryption_mode)) { 2349 mwifiex_dbg(priv->adapter, INFO, 2350 "info: setting wep encryption\t" 2351 "with key len %d\n", sme->key_len); 2352 priv->wep_key_curr_index = sme->key_idx; 2353 ret = mwifiex_set_encode(priv, NULL, sme->key, 2354 sme->key_len, sme->key_idx, 2355 NULL, 0); 2356 } 2357 } 2358 done: 2359 /* 2360 * Scan entries are valid for some time (15 sec). So we can save one 2361 * active scan time if we just try cfg80211_get_bss first. If it fails 2362 * then request scan and cfg80211_get_bss() again for final output. 2363 */ 2364 while (1) { 2365 if (is_scanning_required) { 2366 /* Do specific SSID scanning */ 2367 if (mwifiex_request_scan(priv, &req_ssid)) { 2368 mwifiex_dbg(priv->adapter, ERROR, "scan error\n"); 2369 return -EFAULT; 2370 } 2371 } 2372 2373 /* Find the BSS we want using available scan results */ 2374 if (mode == NL80211_IFTYPE_ADHOC) 2375 bss = cfg80211_get_bss(priv->wdev.wiphy, channel, 2376 bssid, ssid, ssid_len, 2377 IEEE80211_BSS_TYPE_IBSS, 2378 IEEE80211_PRIVACY_ANY); 2379 else 2380 bss = cfg80211_get_bss(priv->wdev.wiphy, channel, 2381 bssid, ssid, ssid_len, 2382 IEEE80211_BSS_TYPE_ESS, 2383 IEEE80211_PRIVACY_ANY); 2384 2385 if (!bss) { 2386 if (is_scanning_required) { 2387 mwifiex_dbg(priv->adapter, MSG, 2388 "assoc: requested bss not found in scan results\n"); 2389 break; 2390 } 2391 is_scanning_required = 1; 2392 } else { 2393 mwifiex_dbg(priv->adapter, MSG, 2394 "info: trying to associate to bssid %pM\n", 2395 bss->bssid); 2396 memcpy(&priv->cfg_bssid, bss->bssid, ETH_ALEN); 2397 break; 2398 } 2399 } 2400 2401 if (bss) 2402 cfg80211_ref_bss(priv->adapter->wiphy, bss); 2403 2404 ret = mwifiex_bss_start(priv, bss, &req_ssid); 2405 if (ret) 2406 goto cleanup; 2407 2408 if (mode == NL80211_IFTYPE_ADHOC) { 2409 /* Inform the BSS information to kernel, otherwise 2410 * kernel will give a panic after successful assoc */ 2411 if (mwifiex_cfg80211_inform_ibss_bss(priv)) { 2412 ret = -EFAULT; 2413 goto cleanup; 2414 } 2415 } 2416 2417 /* Pass the selected BSS entry to caller. */ 2418 if (sel_bss) { 2419 *sel_bss = bss; 2420 bss = NULL; 2421 } 2422 2423 cleanup: 2424 if (bss) 2425 cfg80211_put_bss(priv->adapter->wiphy, bss); 2426 return ret; 2427 } 2428 2429 /* 2430 * CFG802.11 operation handler for association request. 2431 * 2432 * This function does not work when the current mode is set to Ad-Hoc, or 2433 * when there is already an association procedure going on. The given BSS 2434 * information is used to associate. 2435 */ 2436 static int 2437 mwifiex_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev, 2438 struct cfg80211_connect_params *sme) 2439 { 2440 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 2441 struct mwifiex_adapter *adapter = priv->adapter; 2442 struct cfg80211_bss *bss = NULL; 2443 int ret; 2444 2445 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA) { 2446 mwifiex_dbg(adapter, ERROR, 2447 "%s: reject infra assoc request in non-STA role\n", 2448 dev->name); 2449 return -EINVAL; 2450 } 2451 2452 if (priv->wdev.connected) { 2453 mwifiex_dbg(adapter, ERROR, 2454 "%s: already connected\n", dev->name); 2455 return -EALREADY; 2456 } 2457 2458 if (priv->scan_block) 2459 priv->scan_block = false; 2460 2461 if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags) || 2462 test_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags)) { 2463 mwifiex_dbg(adapter, ERROR, 2464 "%s: Ignore connection.\t" 2465 "Card removed or FW in bad state\n", 2466 dev->name); 2467 return -EFAULT; 2468 } 2469 2470 mwifiex_dbg(adapter, INFO, 2471 "info: Trying to associate to bssid %pM\n", sme->bssid); 2472 2473 if (!mwifiex_stop_bg_scan(priv)) 2474 cfg80211_sched_scan_stopped_locked(priv->wdev.wiphy, 0); 2475 2476 ret = mwifiex_cfg80211_assoc(priv, sme->ssid_len, sme->ssid, sme->bssid, 2477 priv->bss_mode, sme->channel, sme, 0, 2478 &bss); 2479 if (!ret) { 2480 cfg80211_connect_bss(priv->netdev, priv->cfg_bssid, bss, NULL, 2481 0, NULL, 0, WLAN_STATUS_SUCCESS, 2482 GFP_KERNEL, NL80211_TIMEOUT_UNSPECIFIED); 2483 mwifiex_dbg(priv->adapter, MSG, 2484 "info: associated to bssid %pM successfully\n", 2485 priv->cfg_bssid); 2486 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) && 2487 priv->adapter->auto_tdls && 2488 priv->bss_type == MWIFIEX_BSS_TYPE_STA) 2489 mwifiex_setup_auto_tdls_timer(priv); 2490 } else { 2491 mwifiex_dbg(priv->adapter, ERROR, 2492 "info: association to bssid %pM failed\n", 2493 priv->cfg_bssid); 2494 eth_zero_addr(priv->cfg_bssid); 2495 2496 if (ret > 0) 2497 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, 2498 NULL, 0, NULL, 0, ret, 2499 GFP_KERNEL); 2500 else 2501 cfg80211_connect_result(priv->netdev, priv->cfg_bssid, 2502 NULL, 0, NULL, 0, 2503 WLAN_STATUS_UNSPECIFIED_FAILURE, 2504 GFP_KERNEL); 2505 } 2506 2507 return 0; 2508 } 2509 2510 /* 2511 * This function sets following parameters for ibss network. 2512 * - channel 2513 * - start band 2514 * - 11n flag 2515 * - secondary channel offset 2516 */ 2517 static int mwifiex_set_ibss_params(struct mwifiex_private *priv, 2518 struct cfg80211_ibss_params *params) 2519 { 2520 struct mwifiex_adapter *adapter = priv->adapter; 2521 int index = 0, i; 2522 u8 config_bands = 0; 2523 2524 if (params->chandef.chan->band == NL80211_BAND_2GHZ) { 2525 if (!params->basic_rates) { 2526 config_bands = BAND_B | BAND_G; 2527 } else { 2528 for (i = 0; i < mwifiex_band_2ghz.n_bitrates; i++) { 2529 /* 2530 * Rates below 6 Mbps in the table are CCK 2531 * rates; 802.11b and from 6 they are OFDM; 2532 * 802.11G 2533 */ 2534 if (mwifiex_rates[i].bitrate == 60) { 2535 index = 1 << i; 2536 break; 2537 } 2538 } 2539 2540 if (params->basic_rates < index) { 2541 config_bands = BAND_B; 2542 } else { 2543 config_bands = BAND_G; 2544 if (params->basic_rates % index) 2545 config_bands |= BAND_B; 2546 } 2547 } 2548 2549 if (cfg80211_get_chandef_type(¶ms->chandef) != 2550 NL80211_CHAN_NO_HT) 2551 config_bands |= BAND_G | BAND_GN; 2552 } else { 2553 if (cfg80211_get_chandef_type(¶ms->chandef) == 2554 NL80211_CHAN_NO_HT) 2555 config_bands = BAND_A; 2556 else 2557 config_bands = BAND_AN | BAND_A; 2558 } 2559 2560 if (!((config_bands | adapter->fw_bands) & ~adapter->fw_bands)) { 2561 adapter->config_bands = config_bands; 2562 adapter->adhoc_start_band = config_bands; 2563 2564 if ((config_bands & BAND_GN) || (config_bands & BAND_AN)) 2565 adapter->adhoc_11n_enabled = true; 2566 else 2567 adapter->adhoc_11n_enabled = false; 2568 } 2569 2570 adapter->sec_chan_offset = 2571 mwifiex_chan_type_to_sec_chan_offset( 2572 cfg80211_get_chandef_type(¶ms->chandef)); 2573 priv->adhoc_channel = ieee80211_frequency_to_channel( 2574 params->chandef.chan->center_freq); 2575 2576 mwifiex_dbg(adapter, INFO, 2577 "info: set ibss band %d, chan %d, chan offset %d\n", 2578 config_bands, priv->adhoc_channel, 2579 adapter->sec_chan_offset); 2580 2581 return 0; 2582 } 2583 2584 /* 2585 * CFG802.11 operation handler to join an IBSS. 2586 * 2587 * This function does not work in any mode other than Ad-Hoc, or if 2588 * a join operation is already in progress. 2589 */ 2590 static int 2591 mwifiex_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev, 2592 struct cfg80211_ibss_params *params) 2593 { 2594 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 2595 int ret = 0; 2596 2597 if (priv->bss_mode != NL80211_IFTYPE_ADHOC) { 2598 mwifiex_dbg(priv->adapter, ERROR, 2599 "request to join ibss received\t" 2600 "when station is not in ibss mode\n"); 2601 goto done; 2602 } 2603 2604 mwifiex_dbg(priv->adapter, MSG, "info: trying to join to bssid %pM\n", 2605 params->bssid); 2606 2607 mwifiex_set_ibss_params(priv, params); 2608 2609 ret = mwifiex_cfg80211_assoc(priv, params->ssid_len, params->ssid, 2610 params->bssid, priv->bss_mode, 2611 params->chandef.chan, NULL, 2612 params->privacy, NULL); 2613 done: 2614 if (!ret) { 2615 cfg80211_ibss_joined(priv->netdev, priv->cfg_bssid, 2616 params->chandef.chan, GFP_KERNEL); 2617 mwifiex_dbg(priv->adapter, MSG, 2618 "info: joined/created adhoc network with bssid\t" 2619 "%pM successfully\n", priv->cfg_bssid); 2620 } else { 2621 mwifiex_dbg(priv->adapter, ERROR, 2622 "info: failed creating/joining adhoc network\n"); 2623 } 2624 2625 return ret; 2626 } 2627 2628 /* 2629 * CFG802.11 operation handler to leave an IBSS. 2630 * 2631 * This function does not work if a leave operation is 2632 * already in progress. 2633 */ 2634 static int 2635 mwifiex_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev) 2636 { 2637 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 2638 2639 mwifiex_dbg(priv->adapter, MSG, "info: disconnecting from essid %pM\n", 2640 priv->cfg_bssid); 2641 if (mwifiex_deauthenticate(priv, NULL)) 2642 return -EFAULT; 2643 2644 eth_zero_addr(priv->cfg_bssid); 2645 2646 return 0; 2647 } 2648 2649 /* 2650 * CFG802.11 operation handler for scan request. 2651 * 2652 * This function issues a scan request to the firmware based upon 2653 * the user specified scan configuration. On successful completion, 2654 * it also informs the results. 2655 */ 2656 static int 2657 mwifiex_cfg80211_scan(struct wiphy *wiphy, 2658 struct cfg80211_scan_request *request) 2659 { 2660 struct net_device *dev = request->wdev->netdev; 2661 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 2662 int i, offset, ret; 2663 struct ieee80211_channel *chan; 2664 struct ieee_types_header *ie; 2665 struct mwifiex_user_scan_cfg *user_scan_cfg; 2666 u8 mac_addr[ETH_ALEN]; 2667 2668 mwifiex_dbg(priv->adapter, CMD, 2669 "info: received scan request on %s\n", dev->name); 2670 2671 /* Block scan request if scan operation or scan cleanup when interface 2672 * is disabled is in process 2673 */ 2674 if (priv->scan_request || priv->scan_aborting) { 2675 mwifiex_dbg(priv->adapter, WARN, 2676 "cmd: Scan already in process..\n"); 2677 return -EBUSY; 2678 } 2679 2680 if (!priv->wdev.connected && priv->scan_block) 2681 priv->scan_block = false; 2682 2683 if (!mwifiex_stop_bg_scan(priv)) 2684 cfg80211_sched_scan_stopped_locked(priv->wdev.wiphy, 0); 2685 2686 user_scan_cfg = kzalloc(sizeof(*user_scan_cfg), GFP_KERNEL); 2687 if (!user_scan_cfg) 2688 return -ENOMEM; 2689 2690 priv->scan_request = request; 2691 2692 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { 2693 get_random_mask_addr(mac_addr, request->mac_addr, 2694 request->mac_addr_mask); 2695 ether_addr_copy(request->mac_addr, mac_addr); 2696 ether_addr_copy(user_scan_cfg->random_mac, mac_addr); 2697 } 2698 2699 user_scan_cfg->num_ssids = request->n_ssids; 2700 user_scan_cfg->ssid_list = request->ssids; 2701 2702 if (request->ie && request->ie_len) { 2703 offset = 0; 2704 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) { 2705 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR) 2706 continue; 2707 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN; 2708 ie = (struct ieee_types_header *)(request->ie + offset); 2709 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len); 2710 offset += sizeof(*ie) + ie->len; 2711 2712 if (offset >= request->ie_len) 2713 break; 2714 } 2715 } 2716 2717 for (i = 0; i < min_t(u32, request->n_channels, 2718 MWIFIEX_USER_SCAN_CHAN_MAX); i++) { 2719 chan = request->channels[i]; 2720 user_scan_cfg->chan_list[i].chan_number = chan->hw_value; 2721 user_scan_cfg->chan_list[i].radio_type = chan->band; 2722 2723 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids) 2724 user_scan_cfg->chan_list[i].scan_type = 2725 MWIFIEX_SCAN_TYPE_PASSIVE; 2726 else 2727 user_scan_cfg->chan_list[i].scan_type = 2728 MWIFIEX_SCAN_TYPE_ACTIVE; 2729 2730 user_scan_cfg->chan_list[i].scan_time = 0; 2731 } 2732 2733 if (priv->adapter->scan_chan_gap_enabled && 2734 mwifiex_is_any_intf_active(priv)) 2735 user_scan_cfg->scan_chan_gap = 2736 priv->adapter->scan_chan_gap_time; 2737 2738 ret = mwifiex_scan_networks(priv, user_scan_cfg); 2739 kfree(user_scan_cfg); 2740 if (ret) { 2741 mwifiex_dbg(priv->adapter, ERROR, 2742 "scan failed: %d\n", ret); 2743 priv->scan_aborting = false; 2744 priv->scan_request = NULL; 2745 return ret; 2746 } 2747 2748 if (request->ie && request->ie_len) { 2749 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) { 2750 if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) { 2751 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR; 2752 memset(&priv->vs_ie[i].ie, 0, 2753 MWIFIEX_MAX_VSIE_LEN); 2754 } 2755 } 2756 } 2757 return 0; 2758 } 2759 2760 /* CFG802.11 operation handler for sched_scan_start. 2761 * 2762 * This function issues a bgscan config request to the firmware based upon 2763 * the user specified sched_scan configuration. On successful completion, 2764 * firmware will generate BGSCAN_REPORT event, driver should issue bgscan 2765 * query command to get sched_scan results from firmware. 2766 */ 2767 static int 2768 mwifiex_cfg80211_sched_scan_start(struct wiphy *wiphy, 2769 struct net_device *dev, 2770 struct cfg80211_sched_scan_request *request) 2771 { 2772 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 2773 int i, offset; 2774 struct ieee80211_channel *chan; 2775 struct mwifiex_bg_scan_cfg *bgscan_cfg; 2776 struct ieee_types_header *ie; 2777 2778 if (!request || (!request->n_ssids && !request->n_match_sets)) { 2779 wiphy_err(wiphy, "%s : Invalid Sched_scan parameters", 2780 __func__); 2781 return -EINVAL; 2782 } 2783 2784 wiphy_info(wiphy, "sched_scan start : n_ssids=%d n_match_sets=%d ", 2785 request->n_ssids, request->n_match_sets); 2786 wiphy_info(wiphy, "n_channels=%d interval=%d ie_len=%d\n", 2787 request->n_channels, request->scan_plans->interval, 2788 (int)request->ie_len); 2789 2790 bgscan_cfg = kzalloc(sizeof(*bgscan_cfg), GFP_KERNEL); 2791 if (!bgscan_cfg) 2792 return -ENOMEM; 2793 2794 if (priv->scan_request || priv->scan_aborting) 2795 bgscan_cfg->start_later = true; 2796 2797 bgscan_cfg->num_ssids = request->n_match_sets; 2798 bgscan_cfg->ssid_list = request->match_sets; 2799 2800 if (request->ie && request->ie_len) { 2801 offset = 0; 2802 for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) { 2803 if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR) 2804 continue; 2805 priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_BGSCAN; 2806 ie = (struct ieee_types_header *)(request->ie + offset); 2807 memcpy(&priv->vs_ie[i].ie, ie, sizeof(*ie) + ie->len); 2808 offset += sizeof(*ie) + ie->len; 2809 2810 if (offset >= request->ie_len) 2811 break; 2812 } 2813 } 2814 2815 for (i = 0; i < min_t(u32, request->n_channels, 2816 MWIFIEX_BG_SCAN_CHAN_MAX); i++) { 2817 chan = request->channels[i]; 2818 bgscan_cfg->chan_list[i].chan_number = chan->hw_value; 2819 bgscan_cfg->chan_list[i].radio_type = chan->band; 2820 2821 if ((chan->flags & IEEE80211_CHAN_NO_IR) || !request->n_ssids) 2822 bgscan_cfg->chan_list[i].scan_type = 2823 MWIFIEX_SCAN_TYPE_PASSIVE; 2824 else 2825 bgscan_cfg->chan_list[i].scan_type = 2826 MWIFIEX_SCAN_TYPE_ACTIVE; 2827 2828 bgscan_cfg->chan_list[i].scan_time = 0; 2829 } 2830 2831 bgscan_cfg->chan_per_scan = min_t(u32, request->n_channels, 2832 MWIFIEX_BG_SCAN_CHAN_MAX); 2833 2834 /* Use at least 15 second for per scan cycle */ 2835 bgscan_cfg->scan_interval = (request->scan_plans->interval > 2836 MWIFIEX_BGSCAN_INTERVAL) ? 2837 request->scan_plans->interval : 2838 MWIFIEX_BGSCAN_INTERVAL; 2839 2840 bgscan_cfg->repeat_count = MWIFIEX_BGSCAN_REPEAT_COUNT; 2841 bgscan_cfg->report_condition = MWIFIEX_BGSCAN_SSID_MATCH | 2842 MWIFIEX_BGSCAN_WAIT_ALL_CHAN_DONE; 2843 bgscan_cfg->bss_type = MWIFIEX_BSS_MODE_INFRA; 2844 bgscan_cfg->action = MWIFIEX_BGSCAN_ACT_SET; 2845 bgscan_cfg->enable = true; 2846 if (request->min_rssi_thold != NL80211_SCAN_RSSI_THOLD_OFF) { 2847 bgscan_cfg->report_condition |= MWIFIEX_BGSCAN_SSID_RSSI_MATCH; 2848 bgscan_cfg->rssi_threshold = request->min_rssi_thold; 2849 } 2850 2851 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_BG_SCAN_CONFIG, 2852 HostCmd_ACT_GEN_SET, 0, bgscan_cfg, true)) { 2853 kfree(bgscan_cfg); 2854 return -EFAULT; 2855 } 2856 2857 priv->sched_scanning = true; 2858 2859 kfree(bgscan_cfg); 2860 return 0; 2861 } 2862 2863 /* CFG802.11 operation handler for sched_scan_stop. 2864 * 2865 * This function issues a bgscan config command to disable 2866 * previous bgscan configuration in the firmware 2867 */ 2868 static int mwifiex_cfg80211_sched_scan_stop(struct wiphy *wiphy, 2869 struct net_device *dev, u64 reqid) 2870 { 2871 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 2872 2873 wiphy_info(wiphy, "sched scan stop!"); 2874 mwifiex_stop_bg_scan(priv); 2875 2876 return 0; 2877 } 2878 2879 static void mwifiex_setup_vht_caps(struct ieee80211_sta_vht_cap *vht_info, 2880 struct mwifiex_private *priv) 2881 { 2882 struct mwifiex_adapter *adapter = priv->adapter; 2883 2884 vht_info->vht_supported = true; 2885 2886 vht_info->cap = adapter->hw_dot_11ac_dev_cap; 2887 /* Update MCS support for VHT */ 2888 vht_info->vht_mcs.rx_mcs_map = cpu_to_le16( 2889 adapter->hw_dot_11ac_mcs_support & 0xFFFF); 2890 vht_info->vht_mcs.rx_highest = 0; 2891 vht_info->vht_mcs.tx_mcs_map = cpu_to_le16( 2892 adapter->hw_dot_11ac_mcs_support >> 16); 2893 vht_info->vht_mcs.tx_highest = 0; 2894 } 2895 2896 /* 2897 * This function sets up the CFG802.11 specific HT capability fields 2898 * with default values. 2899 * 2900 * The following default values are set - 2901 * - HT Supported = True 2902 * - Maximum AMPDU length factor = IEEE80211_HT_MAX_AMPDU_64K 2903 * - Minimum AMPDU spacing = IEEE80211_HT_MPDU_DENSITY_NONE 2904 * - HT Capabilities supported by firmware 2905 * - MCS information, Rx mask = 0xff 2906 * - MCD information, Tx parameters = IEEE80211_HT_MCS_TX_DEFINED (0x01) 2907 */ 2908 static void 2909 mwifiex_setup_ht_caps(struct ieee80211_sta_ht_cap *ht_info, 2910 struct mwifiex_private *priv) 2911 { 2912 int rx_mcs_supp; 2913 struct mwifiex_adapter *adapter = priv->adapter; 2914 2915 ht_info->ht_supported = true; 2916 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; 2917 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE; 2918 2919 /* Fill HT capability information */ 2920 if (ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap)) 2921 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; 2922 else 2923 ht_info->cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; 2924 2925 if (ISSUPP_SHORTGI20(adapter->hw_dot_11n_dev_cap)) 2926 ht_info->cap |= IEEE80211_HT_CAP_SGI_20; 2927 else 2928 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_20; 2929 2930 if (ISSUPP_SHORTGI40(adapter->hw_dot_11n_dev_cap)) 2931 ht_info->cap |= IEEE80211_HT_CAP_SGI_40; 2932 else 2933 ht_info->cap &= ~IEEE80211_HT_CAP_SGI_40; 2934 2935 if (adapter->user_dev_mcs_support == HT_STREAM_2X2) 2936 ht_info->cap |= 2 << IEEE80211_HT_CAP_RX_STBC_SHIFT; 2937 else 2938 ht_info->cap |= 1 << IEEE80211_HT_CAP_RX_STBC_SHIFT; 2939 2940 if (ISSUPP_TXSTBC(adapter->hw_dot_11n_dev_cap)) 2941 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC; 2942 else 2943 ht_info->cap &= ~IEEE80211_HT_CAP_TX_STBC; 2944 2945 if (ISSUPP_GREENFIELD(adapter->hw_dot_11n_dev_cap)) 2946 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD; 2947 else 2948 ht_info->cap &= ~IEEE80211_HT_CAP_GRN_FLD; 2949 2950 if (ISENABLED_40MHZ_INTOLERANT(adapter->hw_dot_11n_dev_cap)) 2951 ht_info->cap |= IEEE80211_HT_CAP_40MHZ_INTOLERANT; 2952 else 2953 ht_info->cap &= ~IEEE80211_HT_CAP_40MHZ_INTOLERANT; 2954 2955 if (ISSUPP_RXLDPC(adapter->hw_dot_11n_dev_cap)) 2956 ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING; 2957 else 2958 ht_info->cap &= ~IEEE80211_HT_CAP_LDPC_CODING; 2959 2960 ht_info->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU; 2961 ht_info->cap |= IEEE80211_HT_CAP_SM_PS; 2962 2963 rx_mcs_supp = GET_RXMCSSUPP(adapter->user_dev_mcs_support); 2964 2965 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs)); 2966 /* Set MCS for 1x1/2x2 */ 2967 memset(ht_info->mcs.rx_mask, 0xff, rx_mcs_supp); 2968 2969 if (priv->bss_mode == NL80211_IFTYPE_STATION || 2970 ISSUPP_CHANWIDTH40(adapter->hw_dot_11n_dev_cap)) 2971 /* Set MCS32 for infra mode or ad-hoc mode with 40MHz support */ 2972 SETHT_MCS32(ht_info->mcs.rx_mask); 2973 2974 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; 2975 } 2976 2977 /* 2978 * create a new virtual interface with the given name and name assign type 2979 */ 2980 struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy, 2981 const char *name, 2982 unsigned char name_assign_type, 2983 enum nl80211_iftype type, 2984 struct vif_params *params) 2985 { 2986 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy); 2987 struct mwifiex_private *priv; 2988 struct net_device *dev; 2989 void *mdev_priv; 2990 int ret; 2991 2992 if (!adapter) 2993 return ERR_PTR(-EFAULT); 2994 2995 switch (type) { 2996 case NL80211_IFTYPE_UNSPECIFIED: 2997 case NL80211_IFTYPE_STATION: 2998 case NL80211_IFTYPE_ADHOC: 2999 if (adapter->curr_iface_comb.sta_intf == 3000 adapter->iface_limit.sta_intf) { 3001 mwifiex_dbg(adapter, ERROR, 3002 "cannot create multiple sta/adhoc ifaces\n"); 3003 return ERR_PTR(-EINVAL); 3004 } 3005 3006 priv = mwifiex_get_unused_priv_by_bss_type( 3007 adapter, MWIFIEX_BSS_TYPE_STA); 3008 if (!priv) { 3009 mwifiex_dbg(adapter, ERROR, 3010 "could not get free private struct\n"); 3011 return ERR_PTR(-EFAULT); 3012 } 3013 3014 priv->wdev.iftype = NL80211_IFTYPE_STATION; 3015 3016 if (type == NL80211_IFTYPE_UNSPECIFIED) 3017 priv->bss_mode = NL80211_IFTYPE_STATION; 3018 else 3019 priv->bss_mode = type; 3020 3021 priv->bss_type = MWIFIEX_BSS_TYPE_STA; 3022 priv->bss_role = MWIFIEX_BSS_ROLE_STA; 3023 3024 break; 3025 case NL80211_IFTYPE_AP: 3026 if (adapter->curr_iface_comb.uap_intf == 3027 adapter->iface_limit.uap_intf) { 3028 mwifiex_dbg(adapter, ERROR, 3029 "cannot create multiple AP ifaces\n"); 3030 return ERR_PTR(-EINVAL); 3031 } 3032 3033 priv = mwifiex_get_unused_priv_by_bss_type( 3034 adapter, MWIFIEX_BSS_TYPE_UAP); 3035 if (!priv) { 3036 mwifiex_dbg(adapter, ERROR, 3037 "could not get free private struct\n"); 3038 return ERR_PTR(-EFAULT); 3039 } 3040 3041 priv->wdev.iftype = NL80211_IFTYPE_AP; 3042 3043 priv->bss_type = MWIFIEX_BSS_TYPE_UAP; 3044 priv->bss_role = MWIFIEX_BSS_ROLE_UAP; 3045 priv->bss_mode = type; 3046 3047 break; 3048 case NL80211_IFTYPE_P2P_CLIENT: 3049 if (adapter->curr_iface_comb.p2p_intf == 3050 adapter->iface_limit.p2p_intf) { 3051 mwifiex_dbg(adapter, ERROR, 3052 "cannot create multiple P2P ifaces\n"); 3053 return ERR_PTR(-EINVAL); 3054 } 3055 3056 priv = mwifiex_get_unused_priv_by_bss_type( 3057 adapter, MWIFIEX_BSS_TYPE_P2P); 3058 if (!priv) { 3059 mwifiex_dbg(adapter, ERROR, 3060 "could not get free private struct\n"); 3061 return ERR_PTR(-EFAULT); 3062 } 3063 3064 /* At start-up, wpa_supplicant tries to change the interface 3065 * to NL80211_IFTYPE_STATION if it is not managed mode. 3066 */ 3067 priv->wdev.iftype = NL80211_IFTYPE_P2P_CLIENT; 3068 priv->bss_mode = NL80211_IFTYPE_P2P_CLIENT; 3069 3070 /* Setting bss_type to P2P tells firmware that this interface 3071 * is receiving P2P peers found during find phase and doing 3072 * action frame handshake. 3073 */ 3074 priv->bss_type = MWIFIEX_BSS_TYPE_P2P; 3075 3076 priv->bss_role = MWIFIEX_BSS_ROLE_STA; 3077 3078 if (mwifiex_cfg80211_init_p2p_client(priv)) { 3079 memset(&priv->wdev, 0, sizeof(priv->wdev)); 3080 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED; 3081 return ERR_PTR(-EFAULT); 3082 } 3083 3084 break; 3085 default: 3086 mwifiex_dbg(adapter, ERROR, "type not supported\n"); 3087 return ERR_PTR(-EINVAL); 3088 } 3089 3090 priv->wdev.wiphy = wiphy; 3091 priv->bss_priority = 0; 3092 priv->bss_started = 0; 3093 priv->frame_type = MWIFIEX_DATA_FRAME_TYPE_ETH_II; 3094 3095 dev = alloc_netdev_mqs(sizeof(struct mwifiex_private *), name, 3096 name_assign_type, ether_setup, 3097 IEEE80211_NUM_ACS, 1); 3098 if (!dev) { 3099 mwifiex_dbg(adapter, ERROR, 3100 "no memory available for netdevice\n"); 3101 ret = -ENOMEM; 3102 goto err_alloc_netdev; 3103 } 3104 3105 mwifiex_init_priv_params(priv, dev); 3106 3107 priv->netdev = dev; 3108 3109 if (!adapter->mfg_mode) { 3110 mwifiex_set_mac_address(priv, dev, false, NULL); 3111 3112 ret = mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE, 3113 HostCmd_ACT_GEN_SET, 0, NULL, true); 3114 if (ret) 3115 goto err_set_bss_mode; 3116 3117 ret = mwifiex_sta_init_cmd(priv, false); 3118 if (ret) 3119 goto err_sta_init; 3120 } 3121 3122 mwifiex_setup_ht_caps(&wiphy->bands[NL80211_BAND_2GHZ]->ht_cap, priv); 3123 if (adapter->is_hw_11ac_capable) 3124 mwifiex_setup_vht_caps( 3125 &wiphy->bands[NL80211_BAND_2GHZ]->vht_cap, priv); 3126 3127 if (adapter->config_bands & BAND_A) 3128 mwifiex_setup_ht_caps( 3129 &wiphy->bands[NL80211_BAND_5GHZ]->ht_cap, priv); 3130 3131 if ((adapter->config_bands & BAND_A) && adapter->is_hw_11ac_capable) 3132 mwifiex_setup_vht_caps( 3133 &wiphy->bands[NL80211_BAND_5GHZ]->vht_cap, priv); 3134 3135 dev_net_set(dev, wiphy_net(wiphy)); 3136 dev->ieee80211_ptr = &priv->wdev; 3137 dev->ieee80211_ptr->iftype = priv->bss_mode; 3138 SET_NETDEV_DEV(dev, wiphy_dev(wiphy)); 3139 3140 dev->flags |= IFF_BROADCAST | IFF_MULTICAST; 3141 dev->watchdog_timeo = MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT; 3142 dev->needed_headroom = MWIFIEX_MIN_DATA_HEADER_LEN; 3143 dev->ethtool_ops = &mwifiex_ethtool_ops; 3144 3145 mdev_priv = netdev_priv(dev); 3146 *((unsigned long *) mdev_priv) = (unsigned long) priv; 3147 3148 SET_NETDEV_DEV(dev, adapter->dev); 3149 3150 priv->dfs_cac_workqueue = alloc_workqueue("MWIFIEX_DFS_CAC%s", 3151 WQ_HIGHPRI | 3152 WQ_MEM_RECLAIM | 3153 WQ_UNBOUND, 0, name); 3154 if (!priv->dfs_cac_workqueue) { 3155 mwifiex_dbg(adapter, ERROR, "cannot alloc DFS CAC queue\n"); 3156 ret = -ENOMEM; 3157 goto err_alloc_cac; 3158 } 3159 3160 INIT_DELAYED_WORK(&priv->dfs_cac_work, mwifiex_dfs_cac_work_queue); 3161 3162 priv->dfs_chan_sw_workqueue = alloc_workqueue("MWIFIEX_DFS_CHSW%s", 3163 WQ_HIGHPRI | WQ_UNBOUND | 3164 WQ_MEM_RECLAIM, 0, name); 3165 if (!priv->dfs_chan_sw_workqueue) { 3166 mwifiex_dbg(adapter, ERROR, "cannot alloc DFS channel sw queue\n"); 3167 ret = -ENOMEM; 3168 goto err_alloc_chsw; 3169 } 3170 3171 INIT_DELAYED_WORK(&priv->dfs_chan_sw_work, 3172 mwifiex_dfs_chan_sw_work_queue); 3173 3174 mutex_init(&priv->async_mutex); 3175 3176 /* Register network device */ 3177 if (cfg80211_register_netdevice(dev)) { 3178 mwifiex_dbg(adapter, ERROR, "cannot register network device\n"); 3179 ret = -EFAULT; 3180 goto err_reg_netdev; 3181 } 3182 3183 mwifiex_dbg(adapter, INFO, 3184 "info: %s: Marvell 802.11 Adapter\n", dev->name); 3185 3186 #ifdef CONFIG_DEBUG_FS 3187 mwifiex_dev_debugfs_init(priv); 3188 #endif 3189 3190 update_vif_type_counter(adapter, type, +1); 3191 3192 return &priv->wdev; 3193 3194 err_reg_netdev: 3195 destroy_workqueue(priv->dfs_chan_sw_workqueue); 3196 priv->dfs_chan_sw_workqueue = NULL; 3197 err_alloc_chsw: 3198 destroy_workqueue(priv->dfs_cac_workqueue); 3199 priv->dfs_cac_workqueue = NULL; 3200 err_alloc_cac: 3201 free_netdev(dev); 3202 priv->netdev = NULL; 3203 err_sta_init: 3204 err_set_bss_mode: 3205 err_alloc_netdev: 3206 memset(&priv->wdev, 0, sizeof(priv->wdev)); 3207 priv->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED; 3208 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED; 3209 return ERR_PTR(ret); 3210 } 3211 EXPORT_SYMBOL_GPL(mwifiex_add_virtual_intf); 3212 3213 /* 3214 * del_virtual_intf: remove the virtual interface determined by dev 3215 */ 3216 int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev) 3217 { 3218 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev); 3219 struct mwifiex_adapter *adapter = priv->adapter; 3220 struct sk_buff *skb, *tmp; 3221 3222 #ifdef CONFIG_DEBUG_FS 3223 mwifiex_dev_debugfs_remove(priv); 3224 #endif 3225 3226 if (priv->sched_scanning) 3227 priv->sched_scanning = false; 3228 3229 mwifiex_stop_net_dev_queue(priv->netdev, adapter); 3230 3231 skb_queue_walk_safe(&priv->bypass_txq, skb, tmp) { 3232 skb_unlink(skb, &priv->bypass_txq); 3233 mwifiex_write_data_complete(priv->adapter, skb, 0, -1); 3234 } 3235 3236 if (netif_carrier_ok(priv->netdev)) 3237 netif_carrier_off(priv->netdev); 3238 3239 if (wdev->netdev->reg_state == NETREG_REGISTERED) 3240 cfg80211_unregister_netdevice(wdev->netdev); 3241 3242 if (priv->dfs_cac_workqueue) { 3243 destroy_workqueue(priv->dfs_cac_workqueue); 3244 priv->dfs_cac_workqueue = NULL; 3245 } 3246 3247 if (priv->dfs_chan_sw_workqueue) { 3248 destroy_workqueue(priv->dfs_chan_sw_workqueue); 3249 priv->dfs_chan_sw_workqueue = NULL; 3250 } 3251 /* Clear the priv in adapter */ 3252 priv->netdev = NULL; 3253 3254 update_vif_type_counter(adapter, priv->bss_mode, -1); 3255 3256 priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED; 3257 3258 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA || 3259 GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) 3260 kfree(priv->hist_data); 3261 3262 return 0; 3263 } 3264 EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf); 3265 3266 static bool 3267 mwifiex_is_pattern_supported(struct cfg80211_pkt_pattern *pat, s8 *byte_seq, 3268 u8 max_byte_seq) 3269 { 3270 int j, k, valid_byte_cnt = 0; 3271 bool dont_care_byte = false; 3272 3273 for (j = 0; j < DIV_ROUND_UP(pat->pattern_len, 8); j++) { 3274 for (k = 0; k < 8; k++) { 3275 if (pat->mask[j] & 1 << k) { 3276 memcpy(byte_seq + valid_byte_cnt, 3277 &pat->pattern[j * 8 + k], 1); 3278 valid_byte_cnt++; 3279 if (dont_care_byte) 3280 return false; 3281 } else { 3282 if (valid_byte_cnt) 3283 dont_care_byte = true; 3284 } 3285 3286 /* wildcard bytes record as the offset 3287 * before the valid byte 3288 */ 3289 if (!valid_byte_cnt && !dont_care_byte) 3290 pat->pkt_offset++; 3291 3292 if (valid_byte_cnt > max_byte_seq) 3293 return false; 3294 } 3295 } 3296 3297 byte_seq[max_byte_seq] = valid_byte_cnt; 3298 3299 return true; 3300 } 3301 3302 #ifdef CONFIG_PM 3303 static void mwifiex_set_auto_arp_mef_entry(struct mwifiex_private *priv, 3304 struct mwifiex_mef_entry *mef_entry) 3305 { 3306 int i, filt_num = 0, num_ipv4 = 0; 3307 struct in_device *in_dev; 3308 struct in_ifaddr *ifa; 3309 __be32 ips[MWIFIEX_MAX_SUPPORTED_IPADDR]; 3310 struct mwifiex_adapter *adapter = priv->adapter; 3311 3312 mef_entry->mode = MEF_MODE_HOST_SLEEP; 3313 mef_entry->action = MEF_ACTION_AUTO_ARP; 3314 3315 /* Enable ARP offload feature */ 3316 memset(ips, 0, sizeof(ips)); 3317 for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) { 3318 if (adapter->priv[i]->netdev) { 3319 in_dev = __in_dev_get_rtnl(adapter->priv[i]->netdev); 3320 if (!in_dev) 3321 continue; 3322 ifa = rtnl_dereference(in_dev->ifa_list); 3323 if (!ifa || !ifa->ifa_local) 3324 continue; 3325 ips[i] = ifa->ifa_local; 3326 num_ipv4++; 3327 } 3328 } 3329 3330 for (i = 0; i < num_ipv4; i++) { 3331 if (!ips[i]) 3332 continue; 3333 mef_entry->filter[filt_num].repeat = 1; 3334 memcpy(mef_entry->filter[filt_num].byte_seq, 3335 (u8 *)&ips[i], sizeof(ips[i])); 3336 mef_entry->filter[filt_num]. 3337 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] = 3338 sizeof(ips[i]); 3339 mef_entry->filter[filt_num].offset = 46; 3340 mef_entry->filter[filt_num].filt_type = TYPE_EQ; 3341 if (filt_num) { 3342 mef_entry->filter[filt_num].filt_action = 3343 TYPE_OR; 3344 } 3345 filt_num++; 3346 } 3347 3348 mef_entry->filter[filt_num].repeat = 1; 3349 mef_entry->filter[filt_num].byte_seq[0] = 0x08; 3350 mef_entry->filter[filt_num].byte_seq[1] = 0x06; 3351 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] = 2; 3352 mef_entry->filter[filt_num].offset = 20; 3353 mef_entry->filter[filt_num].filt_type = TYPE_EQ; 3354 mef_entry->filter[filt_num].filt_action = TYPE_AND; 3355 } 3356 3357 static int mwifiex_set_wowlan_mef_entry(struct mwifiex_private *priv, 3358 struct mwifiex_ds_mef_cfg *mef_cfg, 3359 struct mwifiex_mef_entry *mef_entry, 3360 struct cfg80211_wowlan *wowlan) 3361 { 3362 int i, filt_num = 0, ret = 0; 3363 bool first_pat = true; 3364 u8 byte_seq[MWIFIEX_MEF_MAX_BYTESEQ + 1]; 3365 static const u8 ipv4_mc_mac[] = {0x33, 0x33}; 3366 static const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e}; 3367 3368 mef_entry->mode = MEF_MODE_HOST_SLEEP; 3369 mef_entry->action = MEF_ACTION_ALLOW_AND_WAKEUP_HOST; 3370 3371 for (i = 0; i < wowlan->n_patterns; i++) { 3372 memset(byte_seq, 0, sizeof(byte_seq)); 3373 if (!mwifiex_is_pattern_supported(&wowlan->patterns[i], 3374 byte_seq, 3375 MWIFIEX_MEF_MAX_BYTESEQ)) { 3376 mwifiex_dbg(priv->adapter, ERROR, 3377 "Pattern not supported\n"); 3378 return -EOPNOTSUPP; 3379 } 3380 3381 if (!wowlan->patterns[i].pkt_offset) { 3382 if (is_unicast_ether_addr(byte_seq) && 3383 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 1)) { 3384 mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST; 3385 continue; 3386 } else if (is_broadcast_ether_addr(byte_seq)) { 3387 mef_cfg->criteria |= MWIFIEX_CRITERIA_BROADCAST; 3388 continue; 3389 } else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) && 3390 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 2)) || 3391 (!memcmp(byte_seq, ipv6_mc_mac, 3) && 3392 (byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] == 3))) { 3393 mef_cfg->criteria |= MWIFIEX_CRITERIA_MULTICAST; 3394 continue; 3395 } 3396 } 3397 mef_entry->filter[filt_num].repeat = 1; 3398 mef_entry->filter[filt_num].offset = 3399 wowlan->patterns[i].pkt_offset; 3400 memcpy(mef_entry->filter[filt_num].byte_seq, byte_seq, 3401 sizeof(byte_seq)); 3402 mef_entry->filter[filt_num].filt_type = TYPE_EQ; 3403 3404 if (first_pat) { 3405 first_pat = false; 3406 mwifiex_dbg(priv->adapter, INFO, "Wake on patterns\n"); 3407 } else { 3408 mef_entry->filter[filt_num].filt_action = TYPE_AND; 3409 } 3410 3411 filt_num++; 3412 } 3413 3414 if (wowlan->magic_pkt) { 3415 mef_cfg->criteria |= MWIFIEX_CRITERIA_UNICAST; 3416 mef_entry->filter[filt_num].repeat = 16; 3417 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr, 3418 ETH_ALEN); 3419 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] = 3420 ETH_ALEN; 3421 mef_entry->filter[filt_num].offset = 28; 3422 mef_entry->filter[filt_num].filt_type = TYPE_EQ; 3423 if (filt_num) 3424 mef_entry->filter[filt_num].filt_action = TYPE_OR; 3425 3426 filt_num++; 3427 mef_entry->filter[filt_num].repeat = 16; 3428 memcpy(mef_entry->filter[filt_num].byte_seq, priv->curr_addr, 3429 ETH_ALEN); 3430 mef_entry->filter[filt_num].byte_seq[MWIFIEX_MEF_MAX_BYTESEQ] = 3431 ETH_ALEN; 3432 mef_entry->filter[filt_num].offset = 56; 3433 mef_entry->filter[filt_num].filt_type = TYPE_EQ; 3434 mef_entry->filter[filt_num].filt_action = TYPE_OR; 3435 mwifiex_dbg(priv->adapter, INFO, "Wake on magic packet\n"); 3436 } 3437 return ret; 3438 } 3439 3440 static int mwifiex_set_mef_filter(struct mwifiex_private *priv, 3441 struct cfg80211_wowlan *wowlan) 3442 { 3443 int ret = 0, num_entries = 1; 3444 struct mwifiex_ds_mef_cfg mef_cfg; 3445 struct mwifiex_mef_entry *mef_entry; 3446 3447 if (wowlan->n_patterns || wowlan->magic_pkt) 3448 num_entries++; 3449 3450 mef_entry = kcalloc(num_entries, sizeof(*mef_entry), GFP_KERNEL); 3451 if (!mef_entry) 3452 return -ENOMEM; 3453 3454 memset(&mef_cfg, 0, sizeof(mef_cfg)); 3455 mef_cfg.criteria |= MWIFIEX_CRITERIA_BROADCAST | 3456 MWIFIEX_CRITERIA_UNICAST; 3457 mef_cfg.num_entries = num_entries; 3458 mef_cfg.mef_entry = mef_entry; 3459 3460 mwifiex_set_auto_arp_mef_entry(priv, &mef_entry[0]); 3461 3462 if (wowlan->n_patterns || wowlan->magic_pkt) { 3463 ret = mwifiex_set_wowlan_mef_entry(priv, &mef_cfg, 3464 &mef_entry[1], wowlan); 3465 if (ret) 3466 goto err; 3467 } 3468 3469 if (!mef_cfg.criteria) 3470 mef_cfg.criteria = MWIFIEX_CRITERIA_BROADCAST | 3471 MWIFIEX_CRITERIA_UNICAST | 3472 MWIFIEX_CRITERIA_MULTICAST; 3473 3474 ret = mwifiex_send_cmd(priv, HostCmd_CMD_MEF_CFG, 3475 HostCmd_ACT_GEN_SET, 0, 3476 &mef_cfg, true); 3477 3478 err: 3479 kfree(mef_entry); 3480 return ret; 3481 } 3482 3483 static int mwifiex_cfg80211_suspend(struct wiphy *wiphy, 3484 struct cfg80211_wowlan *wowlan) 3485 { 3486 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy); 3487 struct mwifiex_ds_hs_cfg hs_cfg; 3488 int i, ret = 0, retry_num = 10; 3489 struct mwifiex_private *priv; 3490 struct mwifiex_private *sta_priv = 3491 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA); 3492 3493 sta_priv->scan_aborting = true; 3494 for (i = 0; i < adapter->priv_num; i++) { 3495 priv = adapter->priv[i]; 3496 mwifiex_abort_cac(priv); 3497 } 3498 3499 mwifiex_cancel_all_pending_cmd(adapter); 3500 3501 for (i = 0; i < adapter->priv_num; i++) { 3502 priv = adapter->priv[i]; 3503 if (priv->netdev) 3504 netif_device_detach(priv->netdev); 3505 } 3506 3507 for (i = 0; i < retry_num; i++) { 3508 if (!mwifiex_wmm_lists_empty(adapter) || 3509 !mwifiex_bypass_txlist_empty(adapter) || 3510 !skb_queue_empty(&adapter->tx_data_q)) 3511 usleep_range(10000, 15000); 3512 else 3513 break; 3514 } 3515 3516 if (!wowlan) { 3517 mwifiex_dbg(adapter, INFO, 3518 "None of the WOWLAN triggers enabled\n"); 3519 ret = 0; 3520 goto done; 3521 } 3522 3523 if (!sta_priv->media_connected && !wowlan->nd_config) { 3524 mwifiex_dbg(adapter, ERROR, 3525 "Can not configure WOWLAN in disconnected state\n"); 3526 ret = 0; 3527 goto done; 3528 } 3529 3530 ret = mwifiex_set_mef_filter(sta_priv, wowlan); 3531 if (ret) { 3532 mwifiex_dbg(adapter, ERROR, "Failed to set MEF filter\n"); 3533 goto done; 3534 } 3535 3536 memset(&hs_cfg, 0, sizeof(hs_cfg)); 3537 hs_cfg.conditions = le32_to_cpu(adapter->hs_cfg.conditions); 3538 3539 if (wowlan->nd_config) { 3540 mwifiex_dbg(adapter, INFO, "Wake on net detect\n"); 3541 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT; 3542 mwifiex_cfg80211_sched_scan_start(wiphy, sta_priv->netdev, 3543 wowlan->nd_config); 3544 } 3545 3546 if (wowlan->disconnect) { 3547 hs_cfg.conditions |= HS_CFG_COND_MAC_EVENT; 3548 mwifiex_dbg(sta_priv->adapter, INFO, "Wake on device disconnect\n"); 3549 } 3550 3551 hs_cfg.is_invoke_hostcmd = false; 3552 hs_cfg.gpio = adapter->hs_cfg.gpio; 3553 hs_cfg.gap = adapter->hs_cfg.gap; 3554 ret = mwifiex_set_hs_params(sta_priv, HostCmd_ACT_GEN_SET, 3555 MWIFIEX_SYNC_CMD, &hs_cfg); 3556 if (ret) 3557 mwifiex_dbg(adapter, ERROR, "Failed to set HS params\n"); 3558 3559 done: 3560 sta_priv->scan_aborting = false; 3561 return ret; 3562 } 3563 3564 static int mwifiex_cfg80211_resume(struct wiphy *wiphy) 3565 { 3566 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy); 3567 struct mwifiex_private *priv; 3568 struct mwifiex_ds_wakeup_reason wakeup_reason; 3569 struct cfg80211_wowlan_wakeup wakeup_report; 3570 int i; 3571 bool report_wakeup_reason = true; 3572 3573 for (i = 0; i < adapter->priv_num; i++) { 3574 priv = adapter->priv[i]; 3575 if (priv->netdev) 3576 netif_device_attach(priv->netdev); 3577 } 3578 3579 if (!wiphy->wowlan_config) 3580 goto done; 3581 3582 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA); 3583 mwifiex_get_wakeup_reason(priv, HostCmd_ACT_GEN_GET, MWIFIEX_SYNC_CMD, 3584 &wakeup_reason); 3585 memset(&wakeup_report, 0, sizeof(struct cfg80211_wowlan_wakeup)); 3586 3587 wakeup_report.pattern_idx = -1; 3588 3589 switch (wakeup_reason.hs_wakeup_reason) { 3590 case NO_HSWAKEUP_REASON: 3591 break; 3592 case BCAST_DATA_MATCHED: 3593 break; 3594 case MCAST_DATA_MATCHED: 3595 break; 3596 case UCAST_DATA_MATCHED: 3597 break; 3598 case MASKTABLE_EVENT_MATCHED: 3599 break; 3600 case NON_MASKABLE_EVENT_MATCHED: 3601 if (wiphy->wowlan_config->disconnect) 3602 wakeup_report.disconnect = true; 3603 if (wiphy->wowlan_config->nd_config) 3604 wakeup_report.net_detect = adapter->nd_info; 3605 break; 3606 case NON_MASKABLE_CONDITION_MATCHED: 3607 break; 3608 case MAGIC_PATTERN_MATCHED: 3609 if (wiphy->wowlan_config->magic_pkt) 3610 wakeup_report.magic_pkt = true; 3611 if (wiphy->wowlan_config->n_patterns) 3612 wakeup_report.pattern_idx = 1; 3613 break; 3614 case GTK_REKEY_FAILURE: 3615 if (wiphy->wowlan_config->gtk_rekey_failure) 3616 wakeup_report.gtk_rekey_failure = true; 3617 break; 3618 default: 3619 report_wakeup_reason = false; 3620 break; 3621 } 3622 3623 if (report_wakeup_reason) 3624 cfg80211_report_wowlan_wakeup(&priv->wdev, &wakeup_report, 3625 GFP_KERNEL); 3626 3627 done: 3628 if (adapter->nd_info) { 3629 for (i = 0 ; i < adapter->nd_info->n_matches ; i++) 3630 kfree(adapter->nd_info->matches[i]); 3631 kfree(adapter->nd_info); 3632 adapter->nd_info = NULL; 3633 } 3634 3635 return 0; 3636 } 3637 3638 static void mwifiex_cfg80211_set_wakeup(struct wiphy *wiphy, 3639 bool enabled) 3640 { 3641 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy); 3642 3643 device_set_wakeup_enable(adapter->dev, enabled); 3644 } 3645 3646 static int mwifiex_set_rekey_data(struct wiphy *wiphy, struct net_device *dev, 3647 struct cfg80211_gtk_rekey_data *data) 3648 { 3649 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 3650 3651 if (!ISSUPP_FIRMWARE_SUPPLICANT(priv->adapter->fw_cap_info)) 3652 return -EOPNOTSUPP; 3653 3654 if (priv->adapter->host_mlme_enabled) 3655 return 0; 3656 3657 return mwifiex_send_cmd(priv, HostCmd_CMD_GTK_REKEY_OFFLOAD_CFG, 3658 HostCmd_ACT_GEN_SET, 0, data, true); 3659 } 3660 3661 #endif 3662 3663 static int mwifiex_get_coalesce_pkt_type(u8 *byte_seq) 3664 { 3665 static const u8 ipv4_mc_mac[] = {0x33, 0x33}; 3666 static const u8 ipv6_mc_mac[] = {0x01, 0x00, 0x5e}; 3667 static const u8 bc_mac[] = {0xff, 0xff, 0xff, 0xff}; 3668 3669 if ((byte_seq[0] & 0x01) && 3670 (byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 1)) 3671 return PACKET_TYPE_UNICAST; 3672 else if (!memcmp(byte_seq, bc_mac, 4)) 3673 return PACKET_TYPE_BROADCAST; 3674 else if ((!memcmp(byte_seq, ipv4_mc_mac, 2) && 3675 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 2) || 3676 (!memcmp(byte_seq, ipv6_mc_mac, 3) && 3677 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ] == 3)) 3678 return PACKET_TYPE_MULTICAST; 3679 3680 return 0; 3681 } 3682 3683 static int 3684 mwifiex_fill_coalesce_rule_info(struct mwifiex_private *priv, 3685 struct cfg80211_coalesce_rules *crule, 3686 struct mwifiex_coalesce_rule *mrule) 3687 { 3688 u8 byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ + 1]; 3689 struct filt_field_param *param; 3690 int i; 3691 3692 mrule->max_coalescing_delay = crule->delay; 3693 3694 param = mrule->params; 3695 3696 for (i = 0; i < crule->n_patterns; i++) { 3697 memset(byte_seq, 0, sizeof(byte_seq)); 3698 if (!mwifiex_is_pattern_supported(&crule->patterns[i], 3699 byte_seq, 3700 MWIFIEX_COALESCE_MAX_BYTESEQ)) { 3701 mwifiex_dbg(priv->adapter, ERROR, 3702 "Pattern not supported\n"); 3703 return -EOPNOTSUPP; 3704 } 3705 3706 if (!crule->patterns[i].pkt_offset) { 3707 u8 pkt_type; 3708 3709 pkt_type = mwifiex_get_coalesce_pkt_type(byte_seq); 3710 if (pkt_type && mrule->pkt_type) { 3711 mwifiex_dbg(priv->adapter, ERROR, 3712 "Multiple packet types not allowed\n"); 3713 return -EOPNOTSUPP; 3714 } else if (pkt_type) { 3715 mrule->pkt_type = pkt_type; 3716 continue; 3717 } 3718 } 3719 3720 if (crule->condition == NL80211_COALESCE_CONDITION_MATCH) 3721 param->operation = RECV_FILTER_MATCH_TYPE_EQ; 3722 else 3723 param->operation = RECV_FILTER_MATCH_TYPE_NE; 3724 3725 param->operand_len = byte_seq[MWIFIEX_COALESCE_MAX_BYTESEQ]; 3726 memcpy(param->operand_byte_stream, byte_seq, 3727 param->operand_len); 3728 param->offset = crule->patterns[i].pkt_offset; 3729 param++; 3730 3731 mrule->num_of_fields++; 3732 } 3733 3734 if (!mrule->pkt_type) { 3735 mwifiex_dbg(priv->adapter, ERROR, 3736 "Packet type can not be determined\n"); 3737 return -EOPNOTSUPP; 3738 } 3739 3740 return 0; 3741 } 3742 3743 static int mwifiex_cfg80211_set_coalesce(struct wiphy *wiphy, 3744 struct cfg80211_coalesce *coalesce) 3745 { 3746 struct mwifiex_adapter *adapter = mwifiex_cfg80211_get_adapter(wiphy); 3747 int i, ret; 3748 struct mwifiex_ds_coalesce_cfg coalesce_cfg; 3749 struct mwifiex_private *priv = 3750 mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA); 3751 3752 memset(&coalesce_cfg, 0, sizeof(coalesce_cfg)); 3753 if (!coalesce) { 3754 mwifiex_dbg(adapter, WARN, 3755 "Disable coalesce and reset all previous rules\n"); 3756 return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG, 3757 HostCmd_ACT_GEN_SET, 0, 3758 &coalesce_cfg, true); 3759 } 3760 3761 coalesce_cfg.num_of_rules = coalesce->n_rules; 3762 for (i = 0; i < coalesce->n_rules; i++) { 3763 ret = mwifiex_fill_coalesce_rule_info(priv, &coalesce->rules[i], 3764 &coalesce_cfg.rule[i]); 3765 if (ret) { 3766 mwifiex_dbg(adapter, ERROR, 3767 "Recheck the patterns provided for rule %d\n", 3768 i + 1); 3769 return ret; 3770 } 3771 } 3772 3773 return mwifiex_send_cmd(priv, HostCmd_CMD_COALESCE_CFG, 3774 HostCmd_ACT_GEN_SET, 0, &coalesce_cfg, true); 3775 } 3776 3777 /* cfg80211 ops handler for tdls_mgmt. 3778 * Function prepares TDLS action frame packets and forwards them to FW 3779 */ 3780 static int 3781 mwifiex_cfg80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev, 3782 const u8 *peer, int link_id, u8 action_code, 3783 u8 dialog_token, u16 status_code, 3784 u32 peer_capability, bool initiator, 3785 const u8 *extra_ies, size_t extra_ies_len) 3786 { 3787 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 3788 int ret; 3789 3790 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)) 3791 return -EOPNOTSUPP; 3792 3793 /* make sure we are in station mode and connected */ 3794 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected)) 3795 return -EOPNOTSUPP; 3796 3797 switch (action_code) { 3798 case WLAN_TDLS_SETUP_REQUEST: 3799 mwifiex_dbg(priv->adapter, MSG, 3800 "Send TDLS Setup Request to %pM status_code=%d\n", 3801 peer, status_code); 3802 mwifiex_add_auto_tdls_peer(priv, peer); 3803 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code, 3804 dialog_token, status_code, 3805 extra_ies, extra_ies_len); 3806 break; 3807 case WLAN_TDLS_SETUP_RESPONSE: 3808 mwifiex_add_auto_tdls_peer(priv, peer); 3809 mwifiex_dbg(priv->adapter, MSG, 3810 "Send TDLS Setup Response to %pM status_code=%d\n", 3811 peer, status_code); 3812 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code, 3813 dialog_token, status_code, 3814 extra_ies, extra_ies_len); 3815 break; 3816 case WLAN_TDLS_SETUP_CONFIRM: 3817 mwifiex_dbg(priv->adapter, MSG, 3818 "Send TDLS Confirm to %pM status_code=%d\n", peer, 3819 status_code); 3820 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code, 3821 dialog_token, status_code, 3822 extra_ies, extra_ies_len); 3823 break; 3824 case WLAN_TDLS_TEARDOWN: 3825 mwifiex_dbg(priv->adapter, MSG, 3826 "Send TDLS Tear down to %pM\n", peer); 3827 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code, 3828 dialog_token, status_code, 3829 extra_ies, extra_ies_len); 3830 break; 3831 case WLAN_TDLS_DISCOVERY_REQUEST: 3832 mwifiex_dbg(priv->adapter, MSG, 3833 "Send TDLS Discovery Request to %pM\n", peer); 3834 ret = mwifiex_send_tdls_data_frame(priv, peer, action_code, 3835 dialog_token, status_code, 3836 extra_ies, extra_ies_len); 3837 break; 3838 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES: 3839 mwifiex_dbg(priv->adapter, MSG, 3840 "Send TDLS Discovery Response to %pM\n", peer); 3841 ret = mwifiex_send_tdls_action_frame(priv, peer, action_code, 3842 dialog_token, status_code, 3843 extra_ies, extra_ies_len); 3844 break; 3845 default: 3846 mwifiex_dbg(priv->adapter, ERROR, 3847 "Unknown TDLS mgmt/action frame %pM\n", peer); 3848 ret = -EINVAL; 3849 break; 3850 } 3851 3852 return ret; 3853 } 3854 3855 static int 3856 mwifiex_cfg80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev, 3857 const u8 *peer, enum nl80211_tdls_operation action) 3858 { 3859 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 3860 3861 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) || 3862 !(wiphy->flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) 3863 return -EOPNOTSUPP; 3864 3865 /* make sure we are in station mode and connected */ 3866 if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected)) 3867 return -EOPNOTSUPP; 3868 3869 mwifiex_dbg(priv->adapter, MSG, 3870 "TDLS peer=%pM, oper=%d\n", peer, action); 3871 3872 switch (action) { 3873 case NL80211_TDLS_ENABLE_LINK: 3874 action = MWIFIEX_TDLS_ENABLE_LINK; 3875 break; 3876 case NL80211_TDLS_DISABLE_LINK: 3877 action = MWIFIEX_TDLS_DISABLE_LINK; 3878 break; 3879 case NL80211_TDLS_TEARDOWN: 3880 /* shouldn't happen!*/ 3881 mwifiex_dbg(priv->adapter, ERROR, 3882 "tdls_oper: teardown from driver not supported\n"); 3883 return -EINVAL; 3884 case NL80211_TDLS_SETUP: 3885 /* shouldn't happen!*/ 3886 mwifiex_dbg(priv->adapter, ERROR, 3887 "tdls_oper: setup from driver not supported\n"); 3888 return -EINVAL; 3889 case NL80211_TDLS_DISCOVERY_REQ: 3890 /* shouldn't happen!*/ 3891 mwifiex_dbg(priv->adapter, ERROR, 3892 "tdls_oper: discovery from driver not supported\n"); 3893 return -EINVAL; 3894 default: 3895 mwifiex_dbg(priv->adapter, ERROR, 3896 "tdls_oper: operation not supported\n"); 3897 return -EOPNOTSUPP; 3898 } 3899 3900 return mwifiex_tdls_oper(priv, peer, action); 3901 } 3902 3903 static int 3904 mwifiex_cfg80211_tdls_chan_switch(struct wiphy *wiphy, struct net_device *dev, 3905 const u8 *addr, u8 oper_class, 3906 struct cfg80211_chan_def *chandef) 3907 { 3908 struct mwifiex_sta_node *sta_ptr; 3909 u16 chan; 3910 u8 second_chan_offset, band; 3911 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 3912 3913 spin_lock_bh(&priv->sta_list_spinlock); 3914 sta_ptr = mwifiex_get_sta_entry(priv, addr); 3915 if (!sta_ptr) { 3916 spin_unlock_bh(&priv->sta_list_spinlock); 3917 wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n", 3918 __func__, addr); 3919 return -ENOENT; 3920 } 3921 3922 if (!(sta_ptr->tdls_cap.extcap.ext_capab[3] & 3923 WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)) { 3924 spin_unlock_bh(&priv->sta_list_spinlock); 3925 wiphy_err(wiphy, "%pM do not support tdls cs\n", addr); 3926 return -ENOENT; 3927 } 3928 3929 if (sta_ptr->tdls_status == TDLS_CHAN_SWITCHING || 3930 sta_ptr->tdls_status == TDLS_IN_OFF_CHAN) { 3931 spin_unlock_bh(&priv->sta_list_spinlock); 3932 wiphy_err(wiphy, "channel switch is running, abort request\n"); 3933 return -EALREADY; 3934 } 3935 spin_unlock_bh(&priv->sta_list_spinlock); 3936 3937 chan = chandef->chan->hw_value; 3938 second_chan_offset = mwifiex_get_sec_chan_offset(chan); 3939 band = chandef->chan->band; 3940 mwifiex_start_tdls_cs(priv, addr, chan, second_chan_offset, band); 3941 3942 return 0; 3943 } 3944 3945 static void 3946 mwifiex_cfg80211_tdls_cancel_chan_switch(struct wiphy *wiphy, 3947 struct net_device *dev, 3948 const u8 *addr) 3949 { 3950 struct mwifiex_sta_node *sta_ptr; 3951 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 3952 3953 spin_lock_bh(&priv->sta_list_spinlock); 3954 sta_ptr = mwifiex_get_sta_entry(priv, addr); 3955 if (!sta_ptr) { 3956 spin_unlock_bh(&priv->sta_list_spinlock); 3957 wiphy_err(wiphy, "%s: Invalid TDLS peer %pM\n", 3958 __func__, addr); 3959 } else if (!(sta_ptr->tdls_status == TDLS_CHAN_SWITCHING || 3960 sta_ptr->tdls_status == TDLS_IN_BASE_CHAN || 3961 sta_ptr->tdls_status == TDLS_IN_OFF_CHAN)) { 3962 spin_unlock_bh(&priv->sta_list_spinlock); 3963 wiphy_err(wiphy, "tdls chan switch not initialize by %pM\n", 3964 addr); 3965 } else { 3966 spin_unlock_bh(&priv->sta_list_spinlock); 3967 mwifiex_stop_tdls_cs(priv, addr); 3968 } 3969 } 3970 3971 static int 3972 mwifiex_cfg80211_uap_add_station(struct mwifiex_private *priv, const u8 *mac, 3973 struct station_parameters *params) 3974 { 3975 struct mwifiex_sta_info add_sta; 3976 int ret; 3977 3978 memcpy(add_sta.peer_mac, mac, ETH_ALEN); 3979 add_sta.params = params; 3980 3981 ret = mwifiex_send_cmd(priv, HostCmd_CMD_ADD_NEW_STATION, 3982 HostCmd_ACT_ADD_STA, 0, (void *)&add_sta, true); 3983 3984 if (!ret) { 3985 struct station_info *sinfo; 3986 3987 sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL); 3988 if (!sinfo) 3989 return -ENOMEM; 3990 3991 cfg80211_new_sta(priv->netdev, mac, sinfo, GFP_KERNEL); 3992 kfree(sinfo); 3993 } 3994 3995 return ret; 3996 } 3997 3998 static int 3999 mwifiex_cfg80211_add_station(struct wiphy *wiphy, struct net_device *dev, 4000 const u8 *mac, struct station_parameters *params) 4001 { 4002 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 4003 4004 if (priv->adapter->host_mlme_enabled && 4005 (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)) 4006 return mwifiex_cfg80211_uap_add_station(priv, mac, params); 4007 4008 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) 4009 return -EOPNOTSUPP; 4010 4011 /* make sure we are in station mode and connected */ 4012 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected) 4013 return -EOPNOTSUPP; 4014 4015 return mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CREATE_LINK); 4016 } 4017 4018 static int 4019 mwifiex_cfg80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, 4020 struct cfg80211_csa_settings *params) 4021 { 4022 struct ieee_types_header *chsw_ie; 4023 struct ieee80211_channel_sw_ie *channel_sw; 4024 int chsw_msec; 4025 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 4026 4027 if (priv->adapter->scan_processing) { 4028 mwifiex_dbg(priv->adapter, ERROR, 4029 "radar detection: scan in process...\n"); 4030 return -EBUSY; 4031 } 4032 4033 if (priv->wdev.links[0].cac_started) 4034 return -EBUSY; 4035 4036 if (cfg80211_chandef_identical(¶ms->chandef, 4037 &priv->dfs_chandef)) 4038 return -EINVAL; 4039 4040 chsw_ie = (void *)cfg80211_find_ie(WLAN_EID_CHANNEL_SWITCH, 4041 params->beacon_csa.tail, 4042 params->beacon_csa.tail_len); 4043 if (!chsw_ie) { 4044 mwifiex_dbg(priv->adapter, ERROR, 4045 "Could not parse channel switch announcement IE\n"); 4046 return -EINVAL; 4047 } 4048 4049 channel_sw = (void *)(chsw_ie + 1); 4050 if (channel_sw->mode) { 4051 if (netif_carrier_ok(priv->netdev)) 4052 netif_carrier_off(priv->netdev); 4053 mwifiex_stop_net_dev_queue(priv->netdev, priv->adapter); 4054 } 4055 4056 if (mwifiex_del_mgmt_ies(priv)) 4057 mwifiex_dbg(priv->adapter, ERROR, 4058 "Failed to delete mgmt IEs!\n"); 4059 4060 if (mwifiex_set_mgmt_ies(priv, ¶ms->beacon_csa)) { 4061 mwifiex_dbg(priv->adapter, ERROR, 4062 "%s: setting mgmt ies failed\n", __func__); 4063 return -EFAULT; 4064 } 4065 4066 memcpy(&priv->dfs_chandef, ¶ms->chandef, sizeof(priv->dfs_chandef)); 4067 memcpy(&priv->beacon_after, ¶ms->beacon_after, 4068 sizeof(priv->beacon_after)); 4069 4070 chsw_msec = max(channel_sw->count * priv->bss_cfg.beacon_period, 100); 4071 queue_delayed_work(priv->dfs_chan_sw_workqueue, &priv->dfs_chan_sw_work, 4072 msecs_to_jiffies(chsw_msec)); 4073 return 0; 4074 } 4075 4076 static int mwifiex_cfg80211_get_channel(struct wiphy *wiphy, 4077 struct wireless_dev *wdev, 4078 unsigned int link_id, 4079 struct cfg80211_chan_def *chandef) 4080 { 4081 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev); 4082 struct mwifiex_bssdescriptor *curr_bss; 4083 struct ieee80211_channel *chan; 4084 enum nl80211_channel_type chan_type; 4085 enum nl80211_band band; 4086 int freq; 4087 int ret = -ENODATA; 4088 4089 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP && 4090 cfg80211_chandef_valid(&priv->bss_chandef)) { 4091 *chandef = priv->bss_chandef; 4092 ret = 0; 4093 } else if (priv->media_connected) { 4094 curr_bss = &priv->curr_bss_params.bss_descriptor; 4095 band = mwifiex_band_to_radio_type(priv->curr_bss_params.band); 4096 freq = ieee80211_channel_to_frequency(curr_bss->channel, band); 4097 chan = ieee80211_get_channel(wiphy, freq); 4098 4099 if (priv->ht_param_present) { 4100 chan_type = mwifiex_get_chan_type(priv); 4101 cfg80211_chandef_create(chandef, chan, chan_type); 4102 } else { 4103 cfg80211_chandef_create(chandef, chan, 4104 NL80211_CHAN_NO_HT); 4105 } 4106 ret = 0; 4107 } 4108 4109 return ret; 4110 } 4111 4112 #ifdef CONFIG_NL80211_TESTMODE 4113 4114 enum mwifiex_tm_attr { 4115 __MWIFIEX_TM_ATTR_INVALID = 0, 4116 MWIFIEX_TM_ATTR_CMD = 1, 4117 MWIFIEX_TM_ATTR_DATA = 2, 4118 4119 /* keep last */ 4120 __MWIFIEX_TM_ATTR_AFTER_LAST, 4121 MWIFIEX_TM_ATTR_MAX = __MWIFIEX_TM_ATTR_AFTER_LAST - 1, 4122 }; 4123 4124 static const struct nla_policy mwifiex_tm_policy[MWIFIEX_TM_ATTR_MAX + 1] = { 4125 [MWIFIEX_TM_ATTR_CMD] = { .type = NLA_U32 }, 4126 [MWIFIEX_TM_ATTR_DATA] = { .type = NLA_BINARY, 4127 .len = MWIFIEX_SIZE_OF_CMD_BUFFER }, 4128 }; 4129 4130 enum mwifiex_tm_command { 4131 MWIFIEX_TM_CMD_HOSTCMD = 0, 4132 }; 4133 4134 static int mwifiex_tm_cmd(struct wiphy *wiphy, struct wireless_dev *wdev, 4135 void *data, int len) 4136 { 4137 struct mwifiex_private *priv = mwifiex_netdev_get_priv(wdev->netdev); 4138 struct mwifiex_ds_misc_cmd *hostcmd; 4139 struct nlattr *tb[MWIFIEX_TM_ATTR_MAX + 1]; 4140 struct sk_buff *skb; 4141 int err; 4142 4143 if (!priv) 4144 return -EINVAL; 4145 4146 err = nla_parse_deprecated(tb, MWIFIEX_TM_ATTR_MAX, data, len, 4147 mwifiex_tm_policy, NULL); 4148 if (err) 4149 return err; 4150 4151 if (!tb[MWIFIEX_TM_ATTR_CMD]) 4152 return -EINVAL; 4153 4154 switch (nla_get_u32(tb[MWIFIEX_TM_ATTR_CMD])) { 4155 case MWIFIEX_TM_CMD_HOSTCMD: 4156 if (!tb[MWIFIEX_TM_ATTR_DATA]) 4157 return -EINVAL; 4158 4159 hostcmd = kzalloc(sizeof(*hostcmd), GFP_KERNEL); 4160 if (!hostcmd) 4161 return -ENOMEM; 4162 4163 hostcmd->len = nla_len(tb[MWIFIEX_TM_ATTR_DATA]); 4164 memcpy(hostcmd->cmd, nla_data(tb[MWIFIEX_TM_ATTR_DATA]), 4165 hostcmd->len); 4166 4167 if (mwifiex_send_cmd(priv, 0, 0, 0, hostcmd, true)) { 4168 dev_err(priv->adapter->dev, "Failed to process hostcmd\n"); 4169 kfree(hostcmd); 4170 return -EFAULT; 4171 } 4172 4173 /* process hostcmd response*/ 4174 skb = cfg80211_testmode_alloc_reply_skb(wiphy, hostcmd->len); 4175 if (!skb) { 4176 kfree(hostcmd); 4177 return -ENOMEM; 4178 } 4179 err = nla_put(skb, MWIFIEX_TM_ATTR_DATA, 4180 hostcmd->len, hostcmd->cmd); 4181 if (err) { 4182 kfree(hostcmd); 4183 kfree_skb(skb); 4184 return -EMSGSIZE; 4185 } 4186 4187 err = cfg80211_testmode_reply(skb); 4188 kfree(hostcmd); 4189 return err; 4190 default: 4191 return -EOPNOTSUPP; 4192 } 4193 } 4194 #endif 4195 4196 static int 4197 mwifiex_cfg80211_start_radar_detection(struct wiphy *wiphy, 4198 struct net_device *dev, 4199 struct cfg80211_chan_def *chandef, 4200 u32 cac_time_ms, int link_id) 4201 { 4202 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 4203 struct mwifiex_radar_params radar_params; 4204 4205 if (priv->adapter->scan_processing) { 4206 mwifiex_dbg(priv->adapter, ERROR, 4207 "radar detection: scan already in process...\n"); 4208 return -EBUSY; 4209 } 4210 4211 if (!mwifiex_is_11h_active(priv)) { 4212 mwifiex_dbg(priv->adapter, INFO, 4213 "Enable 11h extensions in FW\n"); 4214 if (mwifiex_11h_activate(priv, true)) { 4215 mwifiex_dbg(priv->adapter, ERROR, 4216 "Failed to activate 11h extensions!!"); 4217 return -1; 4218 } 4219 priv->state_11h.is_11h_active = true; 4220 } 4221 4222 memset(&radar_params, 0, sizeof(struct mwifiex_radar_params)); 4223 radar_params.chandef = chandef; 4224 radar_params.cac_time_ms = cac_time_ms; 4225 4226 memcpy(&priv->dfs_chandef, chandef, sizeof(priv->dfs_chandef)); 4227 4228 if (mwifiex_send_cmd(priv, HostCmd_CMD_CHAN_REPORT_REQUEST, 4229 HostCmd_ACT_GEN_SET, 0, &radar_params, true)) 4230 return -1; 4231 4232 queue_delayed_work(priv->dfs_cac_workqueue, &priv->dfs_cac_work, 4233 msecs_to_jiffies(cac_time_ms)); 4234 return 0; 4235 } 4236 4237 static int 4238 mwifiex_cfg80211_change_station(struct wiphy *wiphy, struct net_device *dev, 4239 const u8 *mac, 4240 struct station_parameters *params) 4241 { 4242 int ret; 4243 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 4244 4245 if (priv->adapter->host_mlme_enabled && 4246 (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP)) 4247 return 0; 4248 4249 /* we support change_station handler only for TDLS peers*/ 4250 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) 4251 return -EOPNOTSUPP; 4252 4253 /* make sure we are in station mode and connected */ 4254 if ((priv->bss_type != MWIFIEX_BSS_TYPE_STA) || !priv->media_connected) 4255 return -EOPNOTSUPP; 4256 4257 priv->sta_params = params; 4258 4259 ret = mwifiex_tdls_oper(priv, mac, MWIFIEX_TDLS_CONFIG_LINK); 4260 priv->sta_params = NULL; 4261 4262 return ret; 4263 } 4264 4265 static int 4266 mwifiex_cfg80211_authenticate(struct wiphy *wiphy, 4267 struct net_device *dev, 4268 struct cfg80211_auth_request *req) 4269 { 4270 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 4271 struct mwifiex_adapter *adapter = priv->adapter; 4272 struct sk_buff *skb; 4273 u16 pkt_len, auth_alg; 4274 int ret; 4275 struct mwifiex_ieee80211_mgmt *mgmt; 4276 struct mwifiex_txinfo *tx_info; 4277 u32 tx_control = 0, pkt_type = PKT_TYPE_MGMT; 4278 u8 trans = 1, status_code = 0; 4279 u8 *varptr = NULL; 4280 4281 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) { 4282 mwifiex_dbg(priv->adapter, ERROR, "Interface role is AP\n"); 4283 return -EFAULT; 4284 } 4285 4286 if (priv->wdev.iftype != NL80211_IFTYPE_STATION) { 4287 mwifiex_dbg(priv->adapter, ERROR, 4288 "Interface type is not correct (type %d)\n", 4289 priv->wdev.iftype); 4290 return -EINVAL; 4291 } 4292 4293 if (priv->auth_alg != WLAN_AUTH_SAE && 4294 (priv->auth_flag & HOST_MLME_AUTH_PENDING)) { 4295 mwifiex_dbg(priv->adapter, ERROR, "Pending auth on going\n"); 4296 return -EBUSY; 4297 } 4298 4299 if (!priv->host_mlme_reg) { 4300 priv->host_mlme_reg = true; 4301 priv->mgmt_frame_mask |= HOST_MLME_MGMT_MASK; 4302 mwifiex_send_cmd(priv, HostCmd_CMD_MGMT_FRAME_REG, 4303 HostCmd_ACT_GEN_SET, 0, 4304 &priv->mgmt_frame_mask, false); 4305 } 4306 4307 switch (req->auth_type) { 4308 case NL80211_AUTHTYPE_OPEN_SYSTEM: 4309 auth_alg = WLAN_AUTH_OPEN; 4310 break; 4311 case NL80211_AUTHTYPE_SHARED_KEY: 4312 auth_alg = WLAN_AUTH_SHARED_KEY; 4313 break; 4314 case NL80211_AUTHTYPE_FT: 4315 auth_alg = WLAN_AUTH_FT; 4316 break; 4317 case NL80211_AUTHTYPE_NETWORK_EAP: 4318 auth_alg = WLAN_AUTH_LEAP; 4319 break; 4320 case NL80211_AUTHTYPE_SAE: 4321 auth_alg = WLAN_AUTH_SAE; 4322 break; 4323 default: 4324 mwifiex_dbg(priv->adapter, ERROR, 4325 "unsupported auth type=%d\n", req->auth_type); 4326 return -EOPNOTSUPP; 4327 } 4328 4329 if (!priv->auth_flag) { 4330 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_SET, 4331 req->bss->channel, 4332 AUTH_TX_DEFAULT_WAIT_TIME); 4333 4334 if (!ret) { 4335 priv->roc_cfg.cookie = get_random_u32() | 1; 4336 priv->roc_cfg.chan = *req->bss->channel; 4337 } else { 4338 return -EFAULT; 4339 } 4340 } 4341 4342 priv->sec_info.authentication_mode = auth_alg; 4343 4344 mwifiex_cancel_scan(adapter); 4345 4346 pkt_len = (u16)req->ie_len + req->auth_data_len + 4347 MWIFIEX_MGMT_HEADER_LEN + MWIFIEX_AUTH_BODY_LEN; 4348 if (req->auth_data_len >= 4) 4349 pkt_len -= 4; 4350 4351 skb = dev_alloc_skb(MWIFIEX_MIN_DATA_HEADER_LEN + 4352 MWIFIEX_MGMT_FRAME_HEADER_SIZE + 4353 pkt_len + sizeof(pkt_len)); 4354 if (!skb) { 4355 mwifiex_dbg(priv->adapter, ERROR, 4356 "allocate skb failed for management frame\n"); 4357 return -ENOMEM; 4358 } 4359 4360 tx_info = MWIFIEX_SKB_TXCB(skb); 4361 memset(tx_info, 0, sizeof(*tx_info)); 4362 tx_info->bss_num = priv->bss_num; 4363 tx_info->bss_type = priv->bss_type; 4364 tx_info->pkt_len = pkt_len; 4365 4366 skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN + 4367 MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len)); 4368 memcpy(skb_push(skb, sizeof(pkt_len)), &pkt_len, sizeof(pkt_len)); 4369 memcpy(skb_push(skb, sizeof(tx_control)), 4370 &tx_control, sizeof(tx_control)); 4371 memcpy(skb_push(skb, sizeof(pkt_type)), &pkt_type, sizeof(pkt_type)); 4372 4373 mgmt = (struct mwifiex_ieee80211_mgmt *)skb_put(skb, pkt_len); 4374 memset(mgmt, 0, pkt_len); 4375 mgmt->frame_control = 4376 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH); 4377 memcpy(mgmt->da, req->bss->bssid, ETH_ALEN); 4378 memcpy(mgmt->sa, priv->curr_addr, ETH_ALEN); 4379 memcpy(mgmt->bssid, req->bss->bssid, ETH_ALEN); 4380 eth_broadcast_addr(mgmt->addr4); 4381 4382 if (req->auth_data_len >= 4) { 4383 if (req->auth_type == NL80211_AUTHTYPE_SAE) { 4384 __le16 *pos = (__le16 *)req->auth_data; 4385 4386 trans = le16_to_cpu(pos[0]); 4387 status_code = le16_to_cpu(pos[1]); 4388 } 4389 memcpy((u8 *)(&mgmt->auth.variable), req->auth_data + 4, 4390 req->auth_data_len - 4); 4391 varptr = (u8 *)&mgmt->auth.variable + 4392 (req->auth_data_len - 4); 4393 } 4394 4395 mgmt->auth.auth_alg = cpu_to_le16(auth_alg); 4396 mgmt->auth.auth_transaction = cpu_to_le16(trans); 4397 mgmt->auth.status_code = cpu_to_le16(status_code); 4398 4399 if (req->ie && req->ie_len) { 4400 if (!varptr) 4401 varptr = (u8 *)&mgmt->auth.variable; 4402 memcpy((u8 *)varptr, req->ie, req->ie_len); 4403 } 4404 4405 priv->auth_flag = HOST_MLME_AUTH_PENDING; 4406 priv->auth_alg = auth_alg; 4407 4408 skb->priority = WMM_HIGHEST_PRIORITY; 4409 __net_timestamp(skb); 4410 4411 mwifiex_dbg(priv->adapter, MSG, 4412 "auth: send authentication to %pM\n", req->bss->bssid); 4413 4414 mwifiex_queue_tx_pkt(priv, skb); 4415 4416 return 0; 4417 } 4418 4419 static int 4420 mwifiex_cfg80211_associate(struct wiphy *wiphy, struct net_device *dev, 4421 struct cfg80211_assoc_request *req) 4422 { 4423 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); 4424 struct mwifiex_adapter *adapter = priv->adapter; 4425 int ret; 4426 struct cfg80211_ssid req_ssid; 4427 const u8 *ssid_ie; 4428 4429 if (GET_BSS_ROLE(priv) != MWIFIEX_BSS_ROLE_STA) { 4430 mwifiex_dbg(adapter, ERROR, 4431 "%s: reject infra assoc request in non-STA role\n", 4432 dev->name); 4433 return -EINVAL; 4434 } 4435 4436 if (test_bit(MWIFIEX_SURPRISE_REMOVED, &adapter->work_flags) || 4437 test_bit(MWIFIEX_IS_CMD_TIMEDOUT, &adapter->work_flags)) { 4438 mwifiex_dbg(adapter, ERROR, 4439 "%s: Ignore association.\t" 4440 "Card removed or FW in bad state\n", 4441 dev->name); 4442 return -EFAULT; 4443 } 4444 4445 if (priv->auth_alg == WLAN_AUTH_SAE) 4446 priv->auth_flag = HOST_MLME_AUTH_DONE; 4447 4448 if (priv->auth_flag && !(priv->auth_flag & HOST_MLME_AUTH_DONE)) 4449 return -EBUSY; 4450 4451 if (priv->roc_cfg.cookie) { 4452 ret = mwifiex_remain_on_chan_cfg(priv, HostCmd_ACT_GEN_REMOVE, 4453 &priv->roc_cfg.chan, 0); 4454 if (!ret) 4455 memset(&priv->roc_cfg, 0, 4456 sizeof(struct mwifiex_roc_cfg)); 4457 else 4458 return -EFAULT; 4459 } 4460 4461 if (!mwifiex_stop_bg_scan(priv)) 4462 cfg80211_sched_scan_stopped_locked(priv->wdev.wiphy, 0); 4463 4464 memset(&req_ssid, 0, sizeof(struct cfg80211_ssid)); 4465 rcu_read_lock(); 4466 ssid_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID); 4467 4468 if (!ssid_ie) 4469 goto ssid_err; 4470 4471 req_ssid.ssid_len = ssid_ie[1]; 4472 if (req_ssid.ssid_len > IEEE80211_MAX_SSID_LEN) { 4473 mwifiex_dbg(adapter, ERROR, "invalid SSID - aborting\n"); 4474 goto ssid_err; 4475 } 4476 4477 memcpy(req_ssid.ssid, ssid_ie + 2, req_ssid.ssid_len); 4478 if (!req_ssid.ssid_len || req_ssid.ssid[0] < 0x20) { 4479 mwifiex_dbg(adapter, ERROR, "invalid SSID - aborting\n"); 4480 goto ssid_err; 4481 } 4482 rcu_read_unlock(); 4483 4484 /* As this is new association, clear locally stored 4485 * keys and security related flags 4486 */ 4487 priv->sec_info.wpa_enabled = false; 4488 priv->sec_info.wpa2_enabled = false; 4489 priv->wep_key_curr_index = 0; 4490 priv->sec_info.encryption_mode = 0; 4491 priv->sec_info.is_authtype_auto = 0; 4492 if (mwifiex_set_encode(priv, NULL, NULL, 0, 0, NULL, 1)) { 4493 mwifiex_dbg(priv->adapter, ERROR, "deleting the crypto keys\n"); 4494 return -EFAULT; 4495 } 4496 4497 if (req->crypto.n_ciphers_pairwise) 4498 priv->sec_info.encryption_mode = 4499 req->crypto.ciphers_pairwise[0]; 4500 4501 if (req->crypto.cipher_group) 4502 priv->sec_info.encryption_mode = req->crypto.cipher_group; 4503 4504 if (req->ie) 4505 mwifiex_set_gen_ie(priv, req->ie, req->ie_len); 4506 4507 memcpy(priv->cfg_bssid, req->bss->bssid, ETH_ALEN); 4508 4509 mwifiex_dbg(adapter, MSG, 4510 "assoc: send association to %pM\n", req->bss->bssid); 4511 4512 cfg80211_ref_bss(adapter->wiphy, req->bss); 4513 ret = mwifiex_bss_start(priv, req->bss, &req_ssid); 4514 if (ret) { 4515 priv->auth_flag = 0; 4516 priv->auth_alg = WLAN_AUTH_NONE; 4517 eth_zero_addr(priv->cfg_bssid); 4518 } 4519 4520 if (priv->assoc_rsp_size) { 4521 priv->req_bss = req->bss; 4522 adapter->assoc_resp_received = true; 4523 queue_work(adapter->host_mlme_workqueue, 4524 &adapter->host_mlme_work); 4525 } 4526 4527 cfg80211_put_bss(priv->adapter->wiphy, req->bss); 4528 4529 return 0; 4530 4531 ssid_err: 4532 rcu_read_unlock(); 4533 return -EFAULT; 4534 } 4535 4536 static int 4537 mwifiex_cfg80211_deauthenticate(struct wiphy *wiphy, 4538 struct net_device *dev, 4539 struct cfg80211_deauth_request *req) 4540 { 4541 return mwifiex_cfg80211_disconnect(wiphy, dev, req->reason_code); 4542 } 4543 4544 static int 4545 mwifiex_cfg80211_disassociate(struct wiphy *wiphy, 4546 struct net_device *dev, 4547 struct cfg80211_disassoc_request *req) 4548 { 4549 return mwifiex_cfg80211_disconnect(wiphy, dev, req->reason_code); 4550 } 4551 4552 static int 4553 mwifiex_cfg80211_probe_client(struct wiphy *wiphy, 4554 struct net_device *dev, const u8 *peer, 4555 u64 *cookie) 4556 { 4557 /* hostapd looks for NL80211_CMD_PROBE_CLIENT support; otherwise, 4558 * it requires monitor-mode support (which mwifiex doesn't support). 4559 * Provide fake probe_client support to work around this. 4560 */ 4561 return -EOPNOTSUPP; 4562 } 4563 4564 /* station cfg80211 operations */ 4565 static const struct cfg80211_ops mwifiex_cfg80211_ops = { 4566 .add_virtual_intf = mwifiex_add_virtual_intf, 4567 .del_virtual_intf = mwifiex_del_virtual_intf, 4568 .change_virtual_intf = mwifiex_cfg80211_change_virtual_intf, 4569 .scan = mwifiex_cfg80211_scan, 4570 .connect = mwifiex_cfg80211_connect, 4571 .disconnect = mwifiex_cfg80211_disconnect, 4572 .get_station = mwifiex_cfg80211_get_station, 4573 .dump_station = mwifiex_cfg80211_dump_station, 4574 .dump_survey = mwifiex_cfg80211_dump_survey, 4575 .set_wiphy_params = mwifiex_cfg80211_set_wiphy_params, 4576 .join_ibss = mwifiex_cfg80211_join_ibss, 4577 .leave_ibss = mwifiex_cfg80211_leave_ibss, 4578 .add_key = mwifiex_cfg80211_add_key, 4579 .del_key = mwifiex_cfg80211_del_key, 4580 .set_default_mgmt_key = mwifiex_cfg80211_set_default_mgmt_key, 4581 .mgmt_tx = mwifiex_cfg80211_mgmt_tx, 4582 .update_mgmt_frame_registrations = 4583 mwifiex_cfg80211_update_mgmt_frame_registrations, 4584 .remain_on_channel = mwifiex_cfg80211_remain_on_channel, 4585 .cancel_remain_on_channel = mwifiex_cfg80211_cancel_remain_on_channel, 4586 .set_default_key = mwifiex_cfg80211_set_default_key, 4587 .set_power_mgmt = mwifiex_cfg80211_set_power_mgmt, 4588 .set_tx_power = mwifiex_cfg80211_set_tx_power, 4589 .get_tx_power = mwifiex_cfg80211_get_tx_power, 4590 .set_bitrate_mask = mwifiex_cfg80211_set_bitrate_mask, 4591 .start_ap = mwifiex_cfg80211_start_ap, 4592 .stop_ap = mwifiex_cfg80211_stop_ap, 4593 .change_beacon = mwifiex_cfg80211_change_beacon, 4594 .set_cqm_rssi_config = mwifiex_cfg80211_set_cqm_rssi_config, 4595 .set_antenna = mwifiex_cfg80211_set_antenna, 4596 .get_antenna = mwifiex_cfg80211_get_antenna, 4597 .del_station = mwifiex_cfg80211_del_station, 4598 .sched_scan_start = mwifiex_cfg80211_sched_scan_start, 4599 .sched_scan_stop = mwifiex_cfg80211_sched_scan_stop, 4600 #ifdef CONFIG_PM 4601 .suspend = mwifiex_cfg80211_suspend, 4602 .resume = mwifiex_cfg80211_resume, 4603 .set_wakeup = mwifiex_cfg80211_set_wakeup, 4604 .set_rekey_data = mwifiex_set_rekey_data, 4605 #endif 4606 .set_coalesce = mwifiex_cfg80211_set_coalesce, 4607 .tdls_mgmt = mwifiex_cfg80211_tdls_mgmt, 4608 .tdls_oper = mwifiex_cfg80211_tdls_oper, 4609 .tdls_channel_switch = mwifiex_cfg80211_tdls_chan_switch, 4610 .tdls_cancel_channel_switch = mwifiex_cfg80211_tdls_cancel_chan_switch, 4611 .add_station = mwifiex_cfg80211_add_station, 4612 .change_station = mwifiex_cfg80211_change_station, 4613 CFG80211_TESTMODE_CMD(mwifiex_tm_cmd) 4614 .get_channel = mwifiex_cfg80211_get_channel, 4615 .start_radar_detection = mwifiex_cfg80211_start_radar_detection, 4616 .channel_switch = mwifiex_cfg80211_channel_switch, 4617 }; 4618 4619 #ifdef CONFIG_PM 4620 static const struct wiphy_wowlan_support mwifiex_wowlan_support = { 4621 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT | 4622 WIPHY_WOWLAN_NET_DETECT | WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | 4623 WIPHY_WOWLAN_GTK_REKEY_FAILURE, 4624 .n_patterns = MWIFIEX_MEF_MAX_FILTERS, 4625 .pattern_min_len = 1, 4626 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN, 4627 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN, 4628 .max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS, 4629 }; 4630 4631 static const struct wiphy_wowlan_support mwifiex_wowlan_support_no_gtk = { 4632 .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT | 4633 WIPHY_WOWLAN_NET_DETECT, 4634 .n_patterns = MWIFIEX_MEF_MAX_FILTERS, 4635 .pattern_min_len = 1, 4636 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN, 4637 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN, 4638 .max_nd_match_sets = MWIFIEX_MAX_ND_MATCH_SETS, 4639 }; 4640 #endif 4641 4642 static bool mwifiex_is_valid_alpha2(const char *alpha2) 4643 { 4644 if (!alpha2 || strlen(alpha2) != 2) 4645 return false; 4646 4647 if (isalpha(alpha2[0]) && isalpha(alpha2[1])) 4648 return true; 4649 4650 return false; 4651 } 4652 4653 static const struct wiphy_coalesce_support mwifiex_coalesce_support = { 4654 .n_rules = MWIFIEX_COALESCE_MAX_RULES, 4655 .max_delay = MWIFIEX_MAX_COALESCING_DELAY, 4656 .n_patterns = MWIFIEX_COALESCE_MAX_FILTERS, 4657 .pattern_min_len = 1, 4658 .pattern_max_len = MWIFIEX_MAX_PATTERN_LEN, 4659 .max_pkt_offset = MWIFIEX_MAX_OFFSET_LEN, 4660 }; 4661 4662 int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter) 4663 { 4664 u32 n_channels_bg, n_channels_a = 0; 4665 4666 n_channels_bg = mwifiex_band_2ghz.n_channels; 4667 4668 if (adapter->config_bands & BAND_A) 4669 n_channels_a = mwifiex_band_5ghz.n_channels; 4670 4671 /* allocate twice the number total channels, since the driver issues an 4672 * additional active scan request for hidden SSIDs on passive channels. 4673 */ 4674 adapter->num_in_chan_stats = 2 * (n_channels_bg + n_channels_a); 4675 adapter->chan_stats = kcalloc(adapter->num_in_chan_stats, 4676 sizeof(*adapter->chan_stats), 4677 GFP_KERNEL); 4678 4679 if (!adapter->chan_stats) 4680 return -ENOMEM; 4681 4682 return 0; 4683 } 4684 4685 /* 4686 * This function registers the device with CFG802.11 subsystem. 4687 * 4688 * The function creates the wireless device/wiphy, populates it with 4689 * default parameters and handler function pointers, and finally 4690 * registers the device. 4691 */ 4692 4693 int mwifiex_register_cfg80211(struct mwifiex_adapter *adapter) 4694 { 4695 int ret; 4696 void *wdev_priv; 4697 struct wiphy *wiphy; 4698 struct mwifiex_private *priv = adapter->priv[MWIFIEX_BSS_TYPE_STA]; 4699 const u8 *country_code; 4700 u32 thr, retry; 4701 struct cfg80211_ops *ops; 4702 4703 ops = devm_kmemdup(adapter->dev, &mwifiex_cfg80211_ops, 4704 sizeof(mwifiex_cfg80211_ops), GFP_KERNEL); 4705 if (!ops) 4706 return -ENOMEM; 4707 4708 /* create a new wiphy for use with cfg80211 */ 4709 wiphy = wiphy_new(ops, sizeof(struct mwifiex_adapter *)); 4710 if (!wiphy) { 4711 mwifiex_dbg(adapter, ERROR, 4712 "%s: creating new wiphy\n", __func__); 4713 return -ENOMEM; 4714 } 4715 if (adapter->host_mlme_enabled) { 4716 ops->auth = mwifiex_cfg80211_authenticate; 4717 ops->assoc = mwifiex_cfg80211_associate; 4718 ops->deauth = mwifiex_cfg80211_deauthenticate; 4719 ops->disassoc = mwifiex_cfg80211_disassociate; 4720 ops->disconnect = NULL; 4721 ops->connect = NULL; 4722 ops->probe_client = mwifiex_cfg80211_probe_client; 4723 } 4724 wiphy->max_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH; 4725 wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN; 4726 if (adapter->host_mlme_enabled) { 4727 memcpy(adapter->mwifiex_mgmt_stypes, 4728 mwifiex_mgmt_stypes, 4729 NUM_NL80211_IFTYPES * 4730 sizeof(struct ieee80211_txrx_stypes)); 4731 4732 adapter->mwifiex_mgmt_stypes[NL80211_IFTYPE_AP].tx = 0xffff; 4733 adapter->mwifiex_mgmt_stypes[NL80211_IFTYPE_AP].rx = 4734 BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) | 4735 BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) | 4736 BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | 4737 BIT(IEEE80211_STYPE_DISASSOC >> 4) | 4738 BIT(IEEE80211_STYPE_AUTH >> 4) | 4739 BIT(IEEE80211_STYPE_DEAUTH >> 4) | 4740 BIT(IEEE80211_STYPE_ACTION >> 4); 4741 wiphy->mgmt_stypes = adapter->mwifiex_mgmt_stypes; 4742 } else { 4743 wiphy->mgmt_stypes = mwifiex_mgmt_stypes; 4744 } 4745 wiphy->max_remain_on_channel_duration = 5000; 4746 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | 4747 BIT(NL80211_IFTYPE_P2P_CLIENT) | 4748 BIT(NL80211_IFTYPE_P2P_GO) | 4749 BIT(NL80211_IFTYPE_AP); 4750 4751 wiphy->max_num_akm_suites = CFG80211_MAX_NUM_AKM_SUITES; 4752 4753 if (ISSUPP_ADHOC_ENABLED(adapter->fw_cap_info)) 4754 wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC); 4755 4756 wiphy->bands[NL80211_BAND_2GHZ] = devm_kmemdup(adapter->dev, 4757 &mwifiex_band_2ghz, 4758 sizeof(mwifiex_band_2ghz), 4759 GFP_KERNEL); 4760 if (!wiphy->bands[NL80211_BAND_2GHZ]) { 4761 ret = -ENOMEM; 4762 goto err; 4763 } 4764 4765 if (adapter->config_bands & BAND_A) { 4766 wiphy->bands[NL80211_BAND_5GHZ] = devm_kmemdup(adapter->dev, 4767 &mwifiex_band_5ghz, 4768 sizeof(mwifiex_band_5ghz), 4769 GFP_KERNEL); 4770 if (!wiphy->bands[NL80211_BAND_5GHZ]) { 4771 ret = -ENOMEM; 4772 goto err; 4773 } 4774 } else { 4775 wiphy->bands[NL80211_BAND_5GHZ] = NULL; 4776 } 4777 4778 if (adapter->drcs_enabled && ISSUPP_DRCS_ENABLED(adapter->fw_cap_info)) 4779 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_drcs; 4780 else if (adapter->is_hw_11ac_capable) 4781 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta_vht; 4782 else 4783 wiphy->iface_combinations = &mwifiex_iface_comb_ap_sta; 4784 wiphy->n_iface_combinations = 1; 4785 4786 wiphy->max_ap_assoc_sta = max_t(typeof(wiphy->max_ap_assoc_sta), 4787 adapter->max_sta_conn, 4788 adapter->max_p2p_conn); 4789 4790 /* Initialize cipher suits */ 4791 wiphy->cipher_suites = mwifiex_cipher_suites; 4792 wiphy->n_cipher_suites = ARRAY_SIZE(mwifiex_cipher_suites); 4793 4794 if (adapter->regd) { 4795 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG | 4796 REGULATORY_DISABLE_BEACON_HINTS | 4797 REGULATORY_COUNTRY_IE_IGNORE; 4798 wiphy_apply_custom_regulatory(wiphy, adapter->regd); 4799 } 4800 4801 ether_addr_copy(wiphy->perm_addr, adapter->perm_addr); 4802 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; 4803 wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD | 4804 WIPHY_FLAG_AP_UAPSD | 4805 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL | 4806 WIPHY_FLAG_HAS_CHANNEL_SWITCH | 4807 WIPHY_FLAG_NETNS_OK | 4808 WIPHY_FLAG_PS_ON_BY_DEFAULT; 4809 4810 if (adapter->host_mlme_enabled) 4811 wiphy->flags |= WIPHY_FLAG_REPORTS_OBSS; 4812 else 4813 wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME; 4814 4815 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info)) 4816 wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS | 4817 WIPHY_FLAG_TDLS_EXTERNAL_SETUP; 4818 4819 #ifdef CONFIG_PM 4820 if (ISSUPP_FIRMWARE_SUPPLICANT(priv->adapter->fw_cap_info)) 4821 wiphy->wowlan = &mwifiex_wowlan_support; 4822 else 4823 wiphy->wowlan = &mwifiex_wowlan_support_no_gtk; 4824 #endif 4825 4826 wiphy->coalesce = &mwifiex_coalesce_support; 4827 4828 wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS | 4829 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 | 4830 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P; 4831 4832 wiphy->max_sched_scan_reqs = 1; 4833 wiphy->max_sched_scan_ssids = MWIFIEX_MAX_SSID_LIST_LENGTH; 4834 wiphy->max_sched_scan_ie_len = MWIFIEX_MAX_VSIE_LEN; 4835 wiphy->max_match_sets = MWIFIEX_MAX_SSID_LIST_LENGTH; 4836 4837 wiphy->available_antennas_tx = BIT(adapter->number_of_antenna) - 1; 4838 wiphy->available_antennas_rx = BIT(adapter->number_of_antenna) - 1; 4839 4840 wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER | 4841 NL80211_FEATURE_LOW_PRIORITY_SCAN | 4842 NL80211_FEATURE_NEED_OBSS_SCAN; 4843 4844 if (adapter->host_mlme_enabled) 4845 wiphy->features |= NL80211_FEATURE_SAE; 4846 4847 if (ISSUPP_ADHOC_ENABLED(adapter->fw_cap_info)) 4848 wiphy->features |= NL80211_FEATURE_HT_IBSS; 4849 4850 if (ISSUPP_RANDOM_MAC(adapter->fw_cap_info)) 4851 wiphy->features |= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR | 4852 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR | 4853 NL80211_FEATURE_ND_RANDOM_MAC_ADDR; 4854 4855 if (ISSUPP_TDLS_ENABLED(adapter->fw_cap_info)) 4856 wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH; 4857 4858 if (adapter->fw_api_ver == MWIFIEX_FW_V15) 4859 wiphy->features |= NL80211_FEATURE_SK_TX_STATUS; 4860 4861 /* Reserve space for mwifiex specific private data for BSS */ 4862 wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv); 4863 4864 wiphy->reg_notifier = mwifiex_reg_notifier; 4865 4866 /* Set struct mwifiex_adapter pointer in wiphy_priv */ 4867 wdev_priv = wiphy_priv(wiphy); 4868 *(unsigned long *)wdev_priv = (unsigned long)adapter; 4869 4870 set_wiphy_dev(wiphy, priv->adapter->dev); 4871 4872 ret = wiphy_register(wiphy); 4873 if (ret < 0) { 4874 mwifiex_dbg(adapter, ERROR, 4875 "%s: wiphy_register failed: %d\n", __func__, ret); 4876 goto err; 4877 } 4878 4879 if (!adapter->regd) { 4880 if (reg_alpha2 && mwifiex_is_valid_alpha2(reg_alpha2)) { 4881 mwifiex_dbg(adapter, INFO, 4882 "driver hint alpha2: %2.2s\n", reg_alpha2); 4883 regulatory_hint(wiphy, reg_alpha2); 4884 } else { 4885 if (adapter->region_code == 0x00) { 4886 mwifiex_dbg(adapter, WARN, 4887 "Ignore world regulatory domain\n"); 4888 } else { 4889 wiphy->regulatory_flags |= 4890 REGULATORY_DISABLE_BEACON_HINTS | 4891 REGULATORY_COUNTRY_IE_IGNORE; 4892 country_code = 4893 mwifiex_11d_code_2_region( 4894 adapter->region_code); 4895 if (country_code && 4896 regulatory_hint(wiphy, country_code)) 4897 mwifiex_dbg(priv->adapter, ERROR, 4898 "regulatory_hint() failed\n"); 4899 } 4900 } 4901 } 4902 4903 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB, 4904 HostCmd_ACT_GEN_GET, FRAG_THRESH_I, &thr, true); 4905 wiphy->frag_threshold = thr; 4906 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB, 4907 HostCmd_ACT_GEN_GET, RTS_THRESH_I, &thr, true); 4908 wiphy->rts_threshold = thr; 4909 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB, 4910 HostCmd_ACT_GEN_GET, SHORT_RETRY_LIM_I, &retry, true); 4911 wiphy->retry_short = (u8) retry; 4912 mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB, 4913 HostCmd_ACT_GEN_GET, LONG_RETRY_LIM_I, &retry, true); 4914 wiphy->retry_long = (u8) retry; 4915 4916 adapter->wiphy = wiphy; 4917 return ret; 4918 4919 err: 4920 wiphy_free(wiphy); 4921 4922 return ret; 4923 } 4924