1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * nxpwifi: association and ad-hoc start/join 4 * 5 * Copyright 2011-2024 NXP 6 */ 7 8 #include "cfg.h" 9 #include "util.h" 10 #include "fw.h" 11 #include "main.h" 12 #include "cmdevt.h" 13 #include "wmm.h" 14 #include "11n.h" 15 #include "11ac.h" 16 #include "11ax.h" 17 18 #define CAPINFO_MASK (~(BIT(15) | BIT(14) | BIT(12) | BIT(11) | BIT(9))) 19 20 /* Append generic IE as pass-through TLV for join */ 21 static int 22 nxpwifi_cmd_append_generic_ie(struct nxpwifi_private *priv, u8 **buffer) 23 { 24 int ret_len = 0; 25 struct nxpwifi_ie_types_header ie_header; 26 27 /* Null Checks */ 28 if (!buffer) 29 return 0; 30 if (!(*buffer)) 31 return 0; 32 33 /* 34 * If there is a generic element buffer setup, append it to the return 35 * parameter buffer pointer. 36 */ 37 if (priv->gen_ie_buf_len) { 38 nxpwifi_dbg(priv->adapter, INFO, 39 "info: %s: append generic element len %d to %p\n", 40 __func__, priv->gen_ie_buf_len, *buffer); 41 42 /* Wrap the generic element buffer with a pass through TLV type */ 43 ie_header.type = cpu_to_le16(TLV_TYPE_PASSTHROUGH); 44 ie_header.len = cpu_to_le16(priv->gen_ie_buf_len); 45 memcpy(*buffer, &ie_header, sizeof(ie_header)); 46 47 /* 48 * Increment the return size and the return buffer pointer 49 * param 50 */ 51 *buffer += sizeof(ie_header); 52 ret_len += sizeof(ie_header); 53 54 /* 55 * Copy the generic element buffer to the output buffer, advance 56 * pointer 57 */ 58 memcpy(*buffer, priv->gen_ie_buf, priv->gen_ie_buf_len); 59 60 /* 61 * Increment the return size and the return buffer pointer 62 * param 63 */ 64 *buffer += priv->gen_ie_buf_len; 65 ret_len += priv->gen_ie_buf_len; 66 67 /* Reset the generic element buffer */ 68 priv->gen_ie_buf_len = 0; 69 } 70 71 /* return the length appended to the buffer */ 72 return ret_len; 73 } 74 75 /* Append TSF timestamp (AP TSF and local RX TSF) for reassoc */ 76 static int 77 nxpwifi_cmd_append_tsf_tlv(struct nxpwifi_private *priv, u8 **buffer, 78 struct nxpwifi_bssdescriptor *bss_desc) 79 { 80 struct nxpwifi_ie_types_tsf_timestamp tsf_tlv; 81 __le64 tsf_val; 82 83 /* Null Checks */ 84 if (!buffer) 85 return 0; 86 if (!*buffer) 87 return 0; 88 89 memset(&tsf_tlv, 0x00, sizeof(struct nxpwifi_ie_types_tsf_timestamp)); 90 91 tsf_tlv.header.type = cpu_to_le16(TLV_TYPE_TSFTIMESTAMP); 92 tsf_tlv.header.len = cpu_to_le16(2 * sizeof(tsf_val)); 93 94 memcpy(*buffer, &tsf_tlv, sizeof(tsf_tlv.header)); 95 *buffer += sizeof(tsf_tlv.header); 96 97 /* TSF at the time when beacon/probe_response was received */ 98 tsf_val = cpu_to_le64(bss_desc->fw_tsf); 99 memcpy(*buffer, &tsf_val, sizeof(tsf_val)); 100 *buffer += sizeof(tsf_val); 101 102 tsf_val = cpu_to_le64(bss_desc->timestamp); 103 104 nxpwifi_dbg(priv->adapter, INFO, 105 "info: %s: TSF offset calc: %016llx - %016llx\n", 106 __func__, bss_desc->timestamp, bss_desc->fw_tsf); 107 108 memcpy(*buffer, &tsf_val, sizeof(tsf_val)); 109 *buffer += sizeof(tsf_val); 110 111 return sizeof(tsf_tlv.header) + (2 * sizeof(tsf_val)); 112 } 113 114 /* Compute intersection of two rate sets; rate1 updated in-place */ 115 static int nxpwifi_get_common_rates(struct nxpwifi_private *priv, u8 *rate1, 116 u32 rate1_size, u8 *rate2, u32 rate2_size) 117 { 118 int ret; 119 u8 *ptr = rate1, *tmp; 120 u32 i, j; 121 122 tmp = kmemdup(rate1, rate1_size, GFP_KERNEL); 123 if (!tmp) 124 return -ENOMEM; 125 126 memset(rate1, 0, rate1_size); 127 128 for (i = 0; i < rate2_size && rate2[i]; i++) { 129 for (j = 0; j < rate1_size && tmp[j]; j++) { 130 /* 131 * Check common rate, excluding the bit for 132 * basic rate 133 */ 134 if ((rate2[i] & 0x7F) == (tmp[j] & 0x7F)) { 135 *rate1++ = tmp[j]; 136 break; 137 } 138 } 139 } 140 141 nxpwifi_dbg(priv->adapter, INFO, "info: Tx data rate set to %#x\n", 142 priv->data_rate); 143 144 if (!priv->is_data_rate_auto) { 145 while (*ptr) { 146 if ((*ptr & 0x7f) == priv->data_rate) { 147 ret = 0; 148 goto done; 149 } 150 ptr++; 151 } 152 nxpwifi_dbg(priv->adapter, ERROR, 153 "previously set fixed data rate %#x\t" 154 "is not compatible with the network\n", 155 priv->data_rate); 156 157 ret = -EPERM; 158 goto done; 159 } 160 161 ret = 0; 162 done: 163 kfree(tmp); 164 return ret; 165 } 166 167 /* Build common rates from BSS descriptor into out_rates */ 168 static int 169 nxpwifi_setup_rates_from_bssdesc(struct nxpwifi_private *priv, 170 struct nxpwifi_bssdescriptor *bss_desc, 171 u8 *out_rates, u32 *out_rates_size) 172 { 173 u8 card_rates[NXPWIFI_SUPPORTED_RATES]; 174 u32 card_rates_size; 175 int ret; 176 177 /* Copy AP supported rates */ 178 memcpy(out_rates, bss_desc->supported_rates, NXPWIFI_SUPPORTED_RATES); 179 /* Get the STA supported rates */ 180 card_rates_size = nxpwifi_get_active_data_rates(priv, card_rates); 181 /* Get the common rates between AP and STA supported rates */ 182 ret = nxpwifi_get_common_rates(priv, out_rates, NXPWIFI_SUPPORTED_RATES, 183 card_rates, card_rates_size); 184 if (ret) { 185 *out_rates_size = 0; 186 nxpwifi_dbg(priv->adapter, ERROR, 187 "%s: cannot get common rates\n", 188 __func__); 189 } else { 190 *out_rates_size = 191 min_t(size_t, strlen(out_rates), NXPWIFI_SUPPORTED_RATES); 192 } 193 194 return ret; 195 } 196 197 /* Append WPS IE as pass-through TLV for join */ 198 static int 199 nxpwifi_cmd_append_wps_ie(struct nxpwifi_private *priv, u8 **buffer) 200 { 201 int ret_len = 0; 202 struct nxpwifi_ie_types_header ie_header; 203 204 if (!buffer || !*buffer) 205 return 0; 206 207 /* 208 * If there is a wps element buffer setup, append it to the return 209 * parameter buffer pointer. 210 */ 211 if (priv->wps_ie_len) { 212 nxpwifi_dbg(priv->adapter, CMD, 213 "cmd: append wps element %d to %p\n", 214 priv->wps_ie_len, *buffer); 215 216 /* Wrap the generic element buffer with a pass through TLV type */ 217 ie_header.type = cpu_to_le16(TLV_TYPE_PASSTHROUGH); 218 ie_header.len = cpu_to_le16(priv->wps_ie_len); 219 memcpy(*buffer, &ie_header, sizeof(ie_header)); 220 *buffer += sizeof(ie_header); 221 ret_len += sizeof(ie_header); 222 223 memcpy(*buffer, priv->wps_ie, priv->wps_ie_len); 224 *buffer += priv->wps_ie_len; 225 ret_len += priv->wps_ie_len; 226 } 227 228 kfree(priv->wps_ie); 229 priv->wps_ie_len = 0; 230 return ret_len; 231 } 232 233 /* Append WPA/WPA2 RSN IE TLV */ 234 static int nxpwifi_append_rsn_ie_wpa_wpa2(struct nxpwifi_private *priv, 235 u8 **buffer) 236 { 237 struct nxpwifi_ie_types_rsn_param_set *rsn_ie_tlv; 238 int rsn_ie_len; 239 240 if (!buffer || !(*buffer)) 241 return 0; 242 243 rsn_ie_tlv = (struct nxpwifi_ie_types_rsn_param_set *)(*buffer); 244 rsn_ie_tlv->header.type = cpu_to_le16((u16)priv->wpa_ie[0]); 245 rsn_ie_tlv->header.type = 246 cpu_to_le16(le16_to_cpu(rsn_ie_tlv->header.type) & 0x00FF); 247 rsn_ie_tlv->header.len = cpu_to_le16((u16)priv->wpa_ie[1]); 248 rsn_ie_tlv->header.len = cpu_to_le16(le16_to_cpu(rsn_ie_tlv->header.len) 249 & 0x00FF); 250 if (le16_to_cpu(rsn_ie_tlv->header.len) <= (sizeof(priv->wpa_ie) - 2)) 251 memcpy(rsn_ie_tlv->rsn_ie, &priv->wpa_ie[2], 252 le16_to_cpu(rsn_ie_tlv->header.len)); 253 else 254 return -ENOMEM; 255 256 rsn_ie_len = sizeof(rsn_ie_tlv->header) + 257 le16_to_cpu(rsn_ie_tlv->header.len); 258 *buffer += rsn_ie_len; 259 260 return rsn_ie_len; 261 } 262 263 /* Build 802.11 association command and required TLVs */ 264 int nxpwifi_cmd_802_11_associate(struct nxpwifi_private *priv, 265 struct host_cmd_ds_command *cmd, 266 struct nxpwifi_bssdescriptor *bss_desc) 267 { 268 struct nxpwifi_adapter *adapter = priv->adapter; 269 struct host_cmd_ds_802_11_associate *assoc = &cmd->params.associate; 270 struct nxpwifi_ie_types_host_mlme *host_mlme_tlv; 271 struct nxpwifi_ie_types_ssid_param_set *ssid_tlv; 272 struct nxpwifi_ie_types_phy_param_set *phy_tlv; 273 struct nxpwifi_ie_types_ss_param_set *ss_tlv; 274 struct nxpwifi_ie_types_rates_param_set *rates_tlv; 275 struct nxpwifi_ie_types_auth_type *auth_tlv; 276 struct nxpwifi_ie_types_sae_pwe_mode *sae_pwe_tlv; 277 struct nxpwifi_ie_types_chan_list_param_set *chan_tlv; 278 u8 rates[NXPWIFI_SUPPORTED_RATES]; 279 u32 rates_size; 280 u16 tmp_cap; 281 u8 *pos; 282 int rsn_ie_len = 0; 283 int ret; 284 285 pos = (u8 *)assoc; 286 287 cmd->command = cpu_to_le16(HOST_CMD_802_11_ASSOCIATE); 288 289 /* Save so we know which BSS Desc to use in the response handler */ 290 priv->attempted_bss_desc = bss_desc; 291 292 memcpy(assoc->peer_sta_addr, 293 bss_desc->mac_address, sizeof(assoc->peer_sta_addr)); 294 pos += sizeof(assoc->peer_sta_addr); 295 296 /* Set the listen interval */ 297 assoc->listen_interval = cpu_to_le16(priv->listen_interval); 298 /* Set the beacon period */ 299 assoc->beacon_period = cpu_to_le16(bss_desc->beacon_period); 300 301 pos += sizeof(assoc->cap_info_bitmap); 302 pos += sizeof(assoc->listen_interval); 303 pos += sizeof(assoc->beacon_period); 304 pos += sizeof(assoc->dtim_period); 305 306 host_mlme_tlv = (struct nxpwifi_ie_types_host_mlme *)pos; 307 host_mlme_tlv->header.type = cpu_to_le16(TLV_TYPE_HOST_MLME); 308 host_mlme_tlv->header.len = cpu_to_le16(sizeof(host_mlme_tlv->host_mlme)); 309 host_mlme_tlv->host_mlme = 1; 310 pos += sizeof(host_mlme_tlv->header) + sizeof(host_mlme_tlv->host_mlme); 311 312 ssid_tlv = (struct nxpwifi_ie_types_ssid_param_set *)pos; 313 ssid_tlv->header.type = cpu_to_le16(WLAN_EID_SSID); 314 ssid_tlv->header.len = cpu_to_le16((u16)bss_desc->ssid.ssid_len); 315 memcpy(ssid_tlv->ssid, bss_desc->ssid.ssid, 316 le16_to_cpu(ssid_tlv->header.len)); 317 pos += sizeof(ssid_tlv->header) + le16_to_cpu(ssid_tlv->header.len); 318 319 phy_tlv = (struct nxpwifi_ie_types_phy_param_set *)pos; 320 phy_tlv->header.type = cpu_to_le16(WLAN_EID_DS_PARAMS); 321 phy_tlv->header.len = cpu_to_le16(sizeof(phy_tlv->fh_ds.ds_param_set)); 322 memcpy(&phy_tlv->fh_ds.ds_param_set, 323 &bss_desc->phy_param_set.ds_param_set.current_chan, 324 sizeof(phy_tlv->fh_ds.ds_param_set)); 325 pos += sizeof(phy_tlv->header) + le16_to_cpu(phy_tlv->header.len); 326 327 ss_tlv = (struct nxpwifi_ie_types_ss_param_set *)pos; 328 ss_tlv->header.type = cpu_to_le16(WLAN_EID_CF_PARAMS); 329 ss_tlv->header.len = cpu_to_le16(sizeof(ss_tlv->cf_ibss.cf_param_set)); 330 pos += sizeof(ss_tlv->header) + le16_to_cpu(ss_tlv->header.len); 331 332 /* Get the common rates supported between the driver and the BSS Desc */ 333 ret = nxpwifi_setup_rates_from_bssdesc(priv, bss_desc, 334 rates, &rates_size); 335 if (ret) 336 return ret; 337 338 /* Save the data rates into Current BSS state structure */ 339 priv->curr_bss_params.num_of_rates = rates_size; 340 memcpy(&priv->curr_bss_params.data_rates, rates, rates_size); 341 342 /* Setup the Rates TLV in the association command */ 343 rates_tlv = (struct nxpwifi_ie_types_rates_param_set *)pos; 344 rates_tlv->header.type = cpu_to_le16(WLAN_EID_SUPP_RATES); 345 rates_tlv->header.len = cpu_to_le16((u16)rates_size); 346 memcpy(rates_tlv->rates, rates, rates_size); 347 pos += sizeof(rates_tlv->header) + rates_size; 348 nxpwifi_dbg(adapter, INFO, "info: ASSOC_CMD: rates size = %d\n", 349 rates_size); 350 351 /* Add the Authentication type */ 352 auth_tlv = (struct nxpwifi_ie_types_auth_type *)pos; 353 auth_tlv->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE); 354 auth_tlv->header.len = cpu_to_le16(sizeof(auth_tlv->auth_type)); 355 if (priv->sec_info.wep_enabled) 356 auth_tlv->auth_type = 357 cpu_to_le16((u16)priv->sec_info.authentication_mode); 358 else 359 auth_tlv->auth_type = cpu_to_le16(NL80211_AUTHTYPE_OPEN_SYSTEM); 360 361 pos += sizeof(auth_tlv->header) + le16_to_cpu(auth_tlv->header.len); 362 363 if (priv->sec_info.authentication_mode == WLAN_AUTH_SAE) { 364 auth_tlv->auth_type = cpu_to_le16(NXPWIFI_AUTHTYPE_SAE); 365 if (bss_desc->bcn_rsnx_ie && 366 bss_desc->bcn_rsnx_ie->datalen && 367 (bss_desc->bcn_rsnx_ie->data[0] & 368 WLAN_RSNX_CAPA_SAE_H2E)) { 369 sae_pwe_tlv = 370 (struct nxpwifi_ie_types_sae_pwe_mode *)pos; 371 sae_pwe_tlv->header.type = 372 cpu_to_le16(TLV_TYPE_SAE_PWE_MODE); 373 sae_pwe_tlv->header.len = 374 cpu_to_le16(sizeof(sae_pwe_tlv->pwe[0])); 375 sae_pwe_tlv->pwe[0] = bss_desc->bcn_rsnx_ie->data[0]; 376 pos += sizeof(sae_pwe_tlv->header) + 377 sizeof(sae_pwe_tlv->pwe[0]); 378 } 379 } 380 381 if (IS_SUPPORT_MULTI_BANDS(adapter) && 382 !(ISSUPP_11NENABLED(adapter->fw_cap_info) && 383 !bss_desc->disable_11n && 384 (priv->config_bands & BAND_GN || 385 priv->config_bands & BAND_AN) && 386 bss_desc->bcn_ht_cap)) { 387 /* 388 * Append a channel TLV for the channel the attempted AP was 389 * found on 390 */ 391 chan_tlv = (struct nxpwifi_ie_types_chan_list_param_set *)pos; 392 chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST); 393 chan_tlv->header.len = 394 cpu_to_le16(sizeof(struct nxpwifi_chan_scan_param_set)); 395 396 memset(chan_tlv->chan_scan_param, 0x00, 397 sizeof(struct nxpwifi_chan_scan_param_set)); 398 chan_tlv->chan_scan_param[0].chan_number = 399 (bss_desc->phy_param_set.ds_param_set.current_chan); 400 nxpwifi_dbg(adapter, INFO, "info: Assoc: TLV Chan = %d\n", 401 chan_tlv->chan_scan_param[0].chan_number); 402 403 chan_tlv->chan_scan_param[0].band_cfg = 404 nxpwifi_band_to_radio_type((u8)bss_desc->bss_band); 405 406 nxpwifi_dbg(adapter, INFO, "info: Assoc: TLV Band = %d\n", 407 chan_tlv->chan_scan_param[0].band_cfg); 408 pos += sizeof(chan_tlv->header) + 409 sizeof(struct nxpwifi_chan_scan_param_set); 410 } 411 412 if (!priv->wps.session_enable) { 413 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled) 414 rsn_ie_len = nxpwifi_append_rsn_ie_wpa_wpa2(priv, &pos); 415 416 if (rsn_ie_len == -ENOMEM) 417 return -ENOMEM; 418 } 419 420 if (ISSUPP_11NENABLED(adapter->fw_cap_info) && 421 !bss_desc->disable_11n && 422 (priv->config_bands & BAND_GN || 423 priv->config_bands & BAND_AN)) 424 nxpwifi_cmd_append_11n_tlv(priv, bss_desc, &pos); 425 426 if (ISSUPP_11ACENABLED(adapter->fw_cap_info) && 427 !bss_desc->disable_11n && !bss_desc->disable_11ac && 428 (priv->config_bands & BAND_GAC || 429 priv->config_bands & BAND_AAC)) 430 nxpwifi_cmd_append_11ac_tlv(priv, bss_desc, &pos); 431 432 if (ISSUPP_11AXENABLED(adapter->fw_cap_ext) && 433 nxpwifi_11ax_bandconfig_allowed(priv, bss_desc)) 434 nxpwifi_cmd_append_11ax_tlv(priv, bss_desc, &pos); 435 436 /* Append vendor specific element TLV */ 437 nxpwifi_cmd_append_vsie_tlv(priv, NXPWIFI_VSIE_MASK_ASSOC, &pos); 438 439 nxpwifi_wmm_process_association_req(priv, &pos, &bss_desc->wmm_ie, 440 bss_desc->bcn_ht_cap); 441 442 if (priv->wps.session_enable && priv->wps_ie_len) 443 nxpwifi_cmd_append_wps_ie(priv, &pos); 444 445 nxpwifi_cmd_append_generic_ie(priv, &pos); 446 447 nxpwifi_cmd_append_tsf_tlv(priv, &pos, bss_desc); 448 449 nxpwifi_11h_process_join(priv, &pos, bss_desc); 450 451 cmd->size = cpu_to_le16((u16)(pos - (u8 *)assoc) + S_DS_GEN); 452 453 /* Set the Capability info at last */ 454 tmp_cap = bss_desc->cap_info_bitmap; 455 456 if (priv->config_bands == BAND_B) 457 tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME; 458 459 tmp_cap &= CAPINFO_MASK; 460 nxpwifi_dbg(adapter, INFO, 461 "info: ASSOC_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n", 462 tmp_cap, CAPINFO_MASK); 463 assoc->cap_info_bitmap = cpu_to_le16(tmp_cap); 464 465 return ret; 466 } 467 468 static const char *assoc_failure_reason_to_str(u16 cap_info) 469 { 470 switch (cap_info) { 471 case CONNECT_ERR_AUTH_ERR_STA_FAILURE: 472 return "CONNECT_ERR_AUTH_ERR_STA_FAILURE"; 473 case CONNECT_ERR_AUTH_MSG_UNHANDLED: 474 return "CONNECT_ERR_AUTH_MSG_UNHANDLED"; 475 case CONNECT_ERR_ASSOC_ERR_TIMEOUT: 476 return "CONNECT_ERR_ASSOC_ERR_TIMEOUT"; 477 case CONNECT_ERR_ASSOC_ERR_AUTH_REFUSED: 478 return "CONNECT_ERR_ASSOC_ERR_AUTH_REFUSED"; 479 case CONNECT_ERR_STA_FAILURE: 480 return "CONNECT_ERR_STA_FAILURE"; 481 } 482 483 return "Unknown connect failure"; 484 } 485 486 /* 487 * Handle association command response. 488 * Parse cap_info/status_code/AID and copy IEs, update connection state, 489 * WMM and HT/HE parameters, queues and filters. On failure, return the 490 * IEEE status code or a mapped timeout error. 491 */ 492 int nxpwifi_ret_802_11_associate(struct nxpwifi_private *priv, 493 struct host_cmd_ds_command *resp) 494 { 495 struct nxpwifi_adapter *adapter = priv->adapter; 496 int ret = 0; 497 struct ieee_types_assoc_rsp *assoc_rsp; 498 struct nxpwifi_bssdescriptor *bss_desc; 499 bool enable_data = true; 500 u16 cap_info, status_code, aid; 501 const u8 *ie_ptr; 502 struct ieee80211_ht_operation *assoc_resp_ht_oper; 503 struct ieee80211_mgmt *hdr; 504 505 if (!priv->attempted_bss_desc) { 506 nxpwifi_dbg(adapter, ERROR, 507 "%s: failed, association terminated by host\n", 508 __func__); 509 goto done; 510 } 511 512 hdr = (struct ieee80211_mgmt *)&resp->params; 513 if (!memcmp(hdr->bssid, priv->attempted_bss_desc->mac_address, 514 ETH_ALEN)) 515 assoc_rsp = (struct ieee_types_assoc_rsp *)&hdr->u.assoc_resp; 516 else 517 assoc_rsp = (struct ieee_types_assoc_rsp *)&resp->params; 518 519 cap_info = le16_to_cpu(assoc_rsp->cap_info_bitmap); 520 status_code = le16_to_cpu(assoc_rsp->status_code); 521 aid = le16_to_cpu(assoc_rsp->a_id); 522 523 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) 524 nxpwifi_dbg(adapter, ERROR, 525 "invalid AID value 0x%x; bits 15:14 not set\n", aid); 526 527 aid &= ~(BIT(15) | BIT(14)); 528 529 priv->assoc_rsp_size = min(le16_to_cpu(resp->size) - S_DS_GEN, 530 sizeof(priv->assoc_rsp_buf)); 531 532 assoc_rsp->a_id = cpu_to_le16(aid); 533 memcpy(priv->assoc_rsp_buf, &resp->params, priv->assoc_rsp_size); 534 535 if (status_code) { 536 adapter->dbg.num_cmd_assoc_failure++; 537 nxpwifi_dbg(adapter, ERROR, 538 "ASSOC_RESP: failed,\t" 539 "status code=%d err=%#x a_id=%#x\n", 540 status_code, cap_info, 541 le16_to_cpu(assoc_rsp->a_id)); 542 543 nxpwifi_dbg(adapter, ERROR, "assoc failure: reason %s\n", 544 assoc_failure_reason_to_str(cap_info)); 545 if (cap_info == CONNECT_ERR_ASSOC_ERR_TIMEOUT) { 546 if (status_code == NXPWIFI_ASSOC_CMD_FAILURE_AUTH) { 547 ret = WLAN_STATUS_AUTH_TIMEOUT; 548 nxpwifi_dbg(adapter, ERROR, 549 "ASSOC_RESP: AUTH timeout\n"); 550 } else { 551 ret = WLAN_STATUS_UNSPECIFIED_FAILURE; 552 nxpwifi_dbg(adapter, ERROR, 553 "ASSOC_RESP: UNSPECIFIED failure\n"); 554 } 555 556 priv->assoc_rsp_size = 0; 557 } else { 558 ret = status_code; 559 } 560 561 goto done; 562 } 563 564 /* Send a Media Connected event, according to the Spec */ 565 priv->media_connected = true; 566 567 adapter->ps_state = PS_STATE_AWAKE; 568 adapter->pps_uapsd_mode = false; 569 adapter->tx_lock_flag = false; 570 571 /* Set the attempted BSSID Index to current */ 572 bss_desc = priv->attempted_bss_desc; 573 574 nxpwifi_dbg(adapter, INFO, "info: ASSOC_RESP: %s\n", 575 bss_desc->ssid.ssid); 576 577 /* Make a copy of current BSSID descriptor */ 578 memcpy(&priv->curr_bss_params.bss_descriptor, 579 bss_desc, sizeof(struct nxpwifi_bssdescriptor)); 580 581 /* Update curr_bss_params */ 582 priv->curr_bss_params.bss_descriptor.channel = 583 bss_desc->phy_param_set.ds_param_set.current_chan; 584 585 priv->curr_bss_params.band = (u8)bss_desc->bss_band; 586 587 if (bss_desc->wmm_ie.element_id == WLAN_EID_VENDOR_SPECIFIC) 588 priv->curr_bss_params.wmm_enabled = true; 589 else 590 priv->curr_bss_params.wmm_enabled = false; 591 592 if ((priv->wmm_required || bss_desc->bcn_ht_cap) && 593 priv->curr_bss_params.wmm_enabled) 594 priv->wmm_enabled = true; 595 else 596 priv->wmm_enabled = false; 597 598 priv->curr_bss_params.wmm_uapsd_enabled = false; 599 600 priv->curr_bss_params.wmm_uapsd_enabled = priv->wmm_enabled && 601 (bss_desc->wmm_ie.qos_info & IEEE80211_WMM_IE_AP_QOSINFO_UAPSD); 602 603 /* Store the bandwidth information from assoc response */ 604 ie_ptr = cfg80211_find_ie(WLAN_EID_HT_OPERATION, assoc_rsp->ie_buffer, 605 priv->assoc_rsp_size 606 - sizeof(struct ieee_types_assoc_rsp)); 607 if (ie_ptr) { 608 assoc_resp_ht_oper = (struct ieee80211_ht_operation *)(ie_ptr 609 + sizeof(struct element)); 610 priv->assoc_resp_ht_param = assoc_resp_ht_oper->ht_param; 611 priv->ht_param_present = true; 612 } else { 613 priv->ht_param_present = false; 614 } 615 616 nxpwifi_dbg(adapter, INFO, 617 "info: ASSOC_RESP: curr_pkt_filter is %#x\n", 618 priv->curr_pkt_filter); 619 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled) 620 priv->wpa_is_gtk_set = false; 621 622 if (priv->wmm_enabled) { 623 /* Don't re-enable carrier until we get the WMM_GET_STATUS event */ 624 enable_data = false; 625 } else { 626 /* Since WMM is not enabled, setup the queues with the defaults */ 627 nxpwifi_wmm_setup_queue_priorities(priv, NULL); 628 nxpwifi_wmm_setup_ac_downgrade(priv); 629 } 630 631 if (enable_data) 632 nxpwifi_dbg(adapter, INFO, 633 "info: post association, re-enabling data flow\n"); 634 635 /* Reset SNR/NF/RSSI values */ 636 priv->data_rssi_last = 0; 637 priv->data_nf_last = 0; 638 priv->data_rssi_avg = 0; 639 priv->data_nf_avg = 0; 640 priv->bcn_rssi_last = 0; 641 priv->bcn_nf_last = 0; 642 priv->bcn_rssi_avg = 0; 643 priv->bcn_nf_avg = 0; 644 priv->rxpd_rate = 0; 645 priv->rxpd_htinfo = 0; 646 647 nxpwifi_save_curr_bcn(priv); 648 649 adapter->dbg.num_cmd_assoc_success++; 650 651 nxpwifi_dbg(adapter, MSG, "assoc: associated with %pM\n", 652 priv->attempted_bss_desc->mac_address); 653 654 /* Add the ra_list here for infra mode as there will be only 1 ra always */ 655 nxpwifi_ralist_add(priv, 656 priv->curr_bss_params.bss_descriptor.mac_address); 657 658 netif_carrier_on(priv->netdev); 659 nxpwifi_wake_up_net_dev_queue(priv->netdev, adapter); 660 661 if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled) 662 priv->scan_block = true; 663 else 664 priv->port_open = true; 665 666 done: 667 /* Need to indicate IOCTL complete */ 668 if (adapter->curr_cmd->wait_q_enabled) { 669 if (ret) 670 adapter->cmd_wait_q.status = -1; 671 else 672 adapter->cmd_wait_q.status = 0; 673 } 674 675 return ret; 676 } 677 678 /* Associate to the specified BSS (STA only) */ 679 int nxpwifi_associate(struct nxpwifi_private *priv, 680 struct nxpwifi_bssdescriptor *bss_desc) 681 { 682 /* 683 * Return error if the adapter is not STA role or table entry 684 * is not marked as infra. 685 */ 686 if ((GET_BSS_ROLE(priv) != NXPWIFI_BSS_ROLE_STA) || 687 bss_desc->bss_mode != NL80211_IFTYPE_STATION) 688 return -EINVAL; 689 690 if (ISSUPP_11ACENABLED(priv->adapter->fw_cap_info) && 691 !bss_desc->disable_11n && !bss_desc->disable_11ac && 692 priv->config_bands & BAND_AAC) 693 nxpwifi_set_11ac_ba_params(priv); 694 else 695 nxpwifi_set_ba_params(priv); 696 697 /* 698 * Clear any past association response stored for application 699 * retrieval 700 */ 701 priv->assoc_rsp_size = 0; 702 703 return nxpwifi_send_cmd(priv, HOST_CMD_802_11_ASSOCIATE, 704 HOST_ACT_GEN_SET, 0, bss_desc, true); 705 } 706 707 /* Send deauth to disconnect from an infrastructure BSS */ 708 static int nxpwifi_deauthenticate_infra(struct nxpwifi_private *priv, u8 *mac) 709 { 710 u8 mac_address[ETH_ALEN]; 711 int ret; 712 713 if (!mac || is_zero_ether_addr(mac)) 714 memcpy(mac_address, 715 priv->curr_bss_params.bss_descriptor.mac_address, 716 ETH_ALEN); 717 else 718 memcpy(mac_address, mac, ETH_ALEN); 719 720 ret = nxpwifi_send_cmd(priv, HOST_CMD_802_11_DEAUTHENTICATE, 721 HOST_ACT_GEN_SET, 0, mac_address, true); 722 723 return ret; 724 } 725 726 /* Disconnect from the current BSS (STA/P2P/AP) */ 727 int nxpwifi_deauthenticate(struct nxpwifi_private *priv, u8 *mac) 728 { 729 int ret = 0; 730 731 if (!priv->media_connected) 732 return 0; 733 734 priv->auth_flag = 0; 735 priv->auth_alg = WLAN_AUTH_NONE; 736 priv->host_mlme_reg = false; 737 priv->mgmt_frame_mask = 0; 738 739 ret = nxpwifi_send_cmd(priv, HOST_CMD_MGMT_FRAME_REG, 740 HOST_ACT_GEN_SET, 0, 741 &priv->mgmt_frame_mask, false); 742 if (ret) { 743 nxpwifi_dbg(priv->adapter, ERROR, 744 "could not unregister mgmt frame rx\n"); 745 return ret; 746 } 747 748 switch (priv->bss_mode) { 749 case NL80211_IFTYPE_STATION: 750 ret = nxpwifi_deauthenticate_infra(priv, mac); 751 if (ret) 752 cfg80211_disconnected(priv->netdev, 0, NULL, 0, 753 true, GFP_KERNEL); 754 break; 755 case NL80211_IFTYPE_AP: 756 ret = nxpwifi_send_cmd(priv, HOST_CMD_UAP_BSS_STOP, 757 HOST_ACT_GEN_SET, 0, NULL, true); 758 break; 759 default: 760 break; 761 } 762 763 return ret; 764 } 765 766 /* Deauthenticate/disconnect from all BSS. */ 767 void nxpwifi_deauthenticate_all(struct nxpwifi_adapter *adapter) 768 { 769 struct nxpwifi_private *priv; 770 int i; 771 772 for (i = 0; i < adapter->priv_num; i++) { 773 priv = adapter->priv[i]; 774 nxpwifi_deauthenticate(priv, NULL); 775 } 776 } 777 EXPORT_SYMBOL_GPL(nxpwifi_deauthenticate_all); 778 779 /* Convert band to radio type used in channel TLV. */ 780 u8 nxpwifi_band_to_radio_type(u16 config_bands) 781 { 782 if (config_bands & BAND_A || config_bands & BAND_AN || 783 config_bands & BAND_AAC || config_bands & BAND_AAX) 784 return HOST_SCAN_RADIO_TYPE_A; 785 786 return HOST_SCAN_RADIO_TYPE_BG; 787 } 788