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