Coverage Report

Created: 2026-05-30 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hostap/wpa_supplicant/wpa_supplicant.c
Line
Count
Source
1
/*
2
 * WPA Supplicant
3
 * Copyright (c) 2003-2024, Jouni Malinen <j@w1.fi>
4
 *
5
 * This software may be distributed under the terms of the BSD license.
6
 * See README for more details.
7
 *
8
 * This file implements functions for registering and unregistering
9
 * %wpa_supplicant interfaces. In addition, this file contains number of
10
 * functions for managing network connections.
11
 */
12
13
#include "includes.h"
14
#ifdef CONFIG_MATCH_IFACE
15
#include <net/if.h>
16
#include <fnmatch.h>
17
#endif /* CONFIG_MATCH_IFACE */
18
19
#include "common.h"
20
#include "crypto/crypto.h"
21
#include "crypto/random.h"
22
#include "crypto/sha1.h"
23
#include "eapol_supp/eapol_supp_sm.h"
24
#include "eap_peer/eap.h"
25
#include "eap_peer/eap_proxy.h"
26
#include "eap_server/eap_methods.h"
27
#include "rsn_supp/wpa.h"
28
#include "eloop.h"
29
#include "config.h"
30
#include "utils/ext_password.h"
31
#include "l2_packet/l2_packet.h"
32
#include "wpa_supplicant_i.h"
33
#include "driver_i.h"
34
#include "ctrl_iface.h"
35
#include "pcsc_funcs.h"
36
#include "common/version.h"
37
#include "rsn_supp/preauth.h"
38
#include "rsn_supp/pmksa_cache.h"
39
#include "common/wpa_ctrl.h"
40
#include "common/ieee802_11_common.h"
41
#include "common/ieee802_11_defs.h"
42
#include "common/hw_features_common.h"
43
#include "common/gas_server.h"
44
#include "common/dpp.h"
45
#include "common/ptksa_cache.h"
46
#include "common/proc_coord.h"
47
#include "p2p/p2p.h"
48
#include "fst/fst.h"
49
#include "bssid_ignore.h"
50
#include "wpas_glue.h"
51
#include "wps_supplicant.h"
52
#include "ibss_rsn.h"
53
#include "sme.h"
54
#include "gas_query.h"
55
#include "ap.h"
56
#include "p2p_supplicant.h"
57
#include "wifi_display.h"
58
#include "notify.h"
59
#include "bgscan.h"
60
#include "autoscan.h"
61
#include "bss.h"
62
#include "scan.h"
63
#include "offchannel.h"
64
#include "hs20_supplicant.h"
65
#include "wnm_sta.h"
66
#include "wpas_kay.h"
67
#include "mesh.h"
68
#include "dpp_supplicant.h"
69
#include "pr_supplicant.h"
70
#include "nan_supplicant.h"
71
#ifdef CONFIG_MESH
72
#include "ap/ap_config.h"
73
#include "ap/hostapd.h"
74
#endif /* CONFIG_MESH */
75
76
const char *const wpa_supplicant_version =
77
"wpa_supplicant v" VERSION_STR "\n"
78
"Copyright (c) 2003-2024, Jouni Malinen <j@w1.fi> and contributors";
79
80
const char *const wpa_supplicant_license =
81
"This software may be distributed under the terms of the BSD license.\n"
82
"See README for more details.\n"
83
#ifdef EAP_TLS_OPENSSL
84
"\nThis product includes software developed by the OpenSSL Project\n"
85
"for use in the OpenSSL Toolkit (http://www.openssl.org/)\n"
86
#endif /* EAP_TLS_OPENSSL */
87
;
88
89
#ifndef CONFIG_NO_STDOUT_DEBUG
90
/* Long text divided into parts in order to fit in C89 strings size limits. */
91
const char *const wpa_supplicant_full_license1 =
92
"";
93
const char *const wpa_supplicant_full_license2 =
94
"This software may be distributed under the terms of the BSD license.\n"
95
"\n"
96
"Redistribution and use in source and binary forms, with or without\n"
97
"modification, are permitted provided that the following conditions are\n"
98
"met:\n"
99
"\n";
100
const char *const wpa_supplicant_full_license3 =
101
"1. Redistributions of source code must retain the above copyright\n"
102
"   notice, this list of conditions and the following disclaimer.\n"
103
"\n"
104
"2. Redistributions in binary form must reproduce the above copyright\n"
105
"   notice, this list of conditions and the following disclaimer in the\n"
106
"   documentation and/or other materials provided with the distribution.\n"
107
"\n";
108
const char *const wpa_supplicant_full_license4 =
109
"3. Neither the name(s) of the above-listed copyright holder(s) nor the\n"
110
"   names of its contributors may be used to endorse or promote products\n"
111
"   derived from this software without specific prior written permission.\n"
112
"\n"
113
"THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n"
114
"\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n"
115
"LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n"
116
"A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n";
117
const char *const wpa_supplicant_full_license5 =
118
"OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n"
119
"SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n"
120
"LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n"
121
"DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n"
122
"THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"
123
"(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"
124
"OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
125
"\n";
126
#endif /* CONFIG_NO_STDOUT_DEBUG */
127
128
129
static void wpa_bss_tmp_disallow_timeout(void *eloop_ctx, void *timeout_ctx);
130
static void wpas_verify_ssid_beacon(void *eloop_ctx, void *timeout_ctx);
131
#if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL)
132
static void wpas_update_fils_connect_params(struct wpa_supplicant *wpa_s);
133
#endif /* CONFIG_FILS && IEEE8021X_EAPOL */
134
#ifdef CONFIG_OWE
135
static void wpas_update_owe_connect_params(struct wpa_supplicant *wpa_s);
136
#endif /* CONFIG_OWE */
137
static void radio_remove_pending_connect(struct wpa_supplicant *wpa_s,
138
           const struct wpa_ssid *ssid);
139
140
141
#ifdef CONFIG_WEP
142
/* Configure default/group WEP keys for static WEP */
143
int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
144
{
145
  int i, set = 0;
146
147
  for (i = 0; i < NUM_WEP_KEYS; i++) {
148
    if (ssid->wep_key_len[i] == 0)
149
      continue;
150
151
    set = 1;
152
    wpa_drv_set_key(wpa_s, -1, WPA_ALG_WEP, NULL,
153
        i, i == ssid->wep_tx_keyidx, NULL, 0,
154
        ssid->wep_key[i], ssid->wep_key_len[i],
155
        i == ssid->wep_tx_keyidx ?
156
        KEY_FLAG_GROUP_RX_TX_DEFAULT :
157
        KEY_FLAG_GROUP_RX_TX);
158
  }
159
160
  return set;
161
}
162
#endif /* CONFIG_WEP */
163
164
165
int wpa_supplicant_set_wpa_none_key(struct wpa_supplicant *wpa_s,
166
            struct wpa_ssid *ssid)
167
0
{
168
0
  u8 key[32];
169
0
  size_t keylen;
170
0
  enum wpa_alg alg;
171
0
  u8 seq[6] = { 0 };
172
0
  int ret;
173
174
  /* IBSS/WPA-None uses only one key (Group) for both receiving and
175
   * sending unicast and multicast packets. */
176
177
0
  if (ssid->mode != WPAS_MODE_IBSS) {
178
0
    wpa_msg(wpa_s, MSG_INFO, "WPA: Invalid mode %d (not "
179
0
      "IBSS/ad-hoc) for WPA-None", ssid->mode);
180
0
    return -1;
181
0
  }
182
183
0
  if (!ssid->psk_set) {
184
0
    wpa_msg(wpa_s, MSG_INFO, "WPA: No PSK configured for "
185
0
      "WPA-None");
186
0
    return -1;
187
0
  }
188
189
0
  switch (wpa_s->group_cipher) {
190
0
  case WPA_CIPHER_CCMP:
191
0
    os_memcpy(key, ssid->psk, 16);
192
0
    keylen = 16;
193
0
    alg = WPA_ALG_CCMP;
194
0
    break;
195
0
  case WPA_CIPHER_GCMP:
196
0
    os_memcpy(key, ssid->psk, 16);
197
0
    keylen = 16;
198
0
    alg = WPA_ALG_GCMP;
199
0
    break;
200
0
  case WPA_CIPHER_TKIP:
201
    /* WPA-None uses the same Michael MIC key for both TX and RX */
202
0
    os_memcpy(key, ssid->psk, 16 + 8);
203
0
    os_memcpy(key + 16 + 8, ssid->psk + 16, 8);
204
0
    keylen = 32;
205
0
    alg = WPA_ALG_TKIP;
206
0
    break;
207
0
  default:
208
0
    wpa_msg(wpa_s, MSG_INFO, "WPA: Invalid group cipher %d for "
209
0
      "WPA-None", wpa_s->group_cipher);
210
0
    return -1;
211
0
  }
212
213
  /* TODO: should actually remember the previously used seq#, both for TX
214
   * and RX from each STA.. */
215
216
0
  ret = wpa_drv_set_key(wpa_s, -1, alg, NULL, 0, 1, seq, 6, key, keylen,
217
0
            KEY_FLAG_GROUP_RX_TX_DEFAULT);
218
0
  os_memset(key, 0, sizeof(key));
219
0
  return ret;
220
0
}
221
222
223
static void wpa_supplicant_timeout(void *eloop_ctx, void *timeout_ctx)
224
0
{
225
0
  struct wpa_supplicant *wpa_s = eloop_ctx;
226
0
  const u8 *bssid = wpa_s->bssid;
227
0
  if (!is_zero_ether_addr(wpa_s->pending_bssid) &&
228
0
      (wpa_s->wpa_state == WPA_AUTHENTICATING ||
229
0
       wpa_s->wpa_state == WPA_ASSOCIATING))
230
0
    bssid = wpa_s->pending_bssid;
231
0
  wpa_msg(wpa_s, MSG_INFO, "Authentication with " MACSTR " timed out.",
232
0
    MAC2STR(bssid));
233
0
  wpa_bssid_ignore_add(wpa_s, bssid);
234
0
  wpa_sm_notify_disassoc(wpa_s->wpa);
235
0
  wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
236
0
  wpa_s->reassociate = 1;
237
238
  /*
239
   * If we timed out, the AP or the local radio may be busy.
240
   * So, wait a second until scanning again.
241
   */
242
0
  wpa_supplicant_req_scan(wpa_s, 1, 0);
243
0
}
244
245
246
/**
247
 * wpa_supplicant_req_auth_timeout - Schedule a timeout for authentication
248
 * @wpa_s: Pointer to wpa_supplicant data
249
 * @sec: Number of seconds after which to time out authentication
250
 * @usec: Number of microseconds after which to time out authentication
251
 *
252
 * This function is used to schedule a timeout for the current authentication
253
 * attempt.
254
 */
255
void wpa_supplicant_req_auth_timeout(struct wpa_supplicant *wpa_s,
256
             int sec, int usec)
257
0
{
258
0
  if (wpa_s->conf->ap_scan == 0 &&
259
0
      (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED))
260
0
    return;
261
262
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Setting authentication timeout: %d sec "
263
0
    "%d usec", sec, usec);
264
0
  eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
265
0
  wpa_s->last_auth_timeout_sec = sec;
266
0
  eloop_register_timeout(sec, usec, wpa_supplicant_timeout, wpa_s, NULL);
267
0
}
268
269
270
/*
271
 * wpas_auth_timeout_restart - Restart and change timeout for authentication
272
 * @wpa_s: Pointer to wpa_supplicant data
273
 * @sec_diff: difference in seconds applied to original timeout value
274
 */
275
void wpas_auth_timeout_restart(struct wpa_supplicant *wpa_s, int sec_diff)
276
0
{
277
0
  int new_sec = wpa_s->last_auth_timeout_sec + sec_diff;
278
279
0
  if (eloop_is_timeout_registered(wpa_supplicant_timeout, wpa_s, NULL)) {
280
0
    wpa_dbg(wpa_s, MSG_DEBUG,
281
0
      "Authentication timeout restart: %d sec", new_sec);
282
0
    eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
283
0
    eloop_register_timeout(new_sec, 0, wpa_supplicant_timeout,
284
0
               wpa_s, NULL);
285
0
  }
286
0
}
287
288
289
/**
290
 * wpa_supplicant_cancel_auth_timeout - Cancel authentication timeout
291
 * @wpa_s: Pointer to wpa_supplicant data
292
 *
293
 * This function is used to cancel authentication timeout scheduled with
294
 * wpa_supplicant_req_auth_timeout() and it is called when authentication has
295
 * been completed.
296
 */
297
void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant *wpa_s)
298
0
{
299
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling authentication timeout");
300
0
  eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
301
0
  wpa_bssid_ignore_del(wpa_s, wpa_s->bssid);
302
0
  os_free(wpa_s->last_con_fail_realm);
303
0
  wpa_s->last_con_fail_realm = NULL;
304
0
  wpa_s->last_con_fail_realm_len = 0;
305
0
}
306
307
308
/**
309
 * wpa_supplicant_initiate_eapol - Configure EAPOL state machine
310
 * @wpa_s: Pointer to wpa_supplicant data
311
 *
312
 * This function is used to configure EAPOL state machine based on the selected
313
 * authentication mode.
314
 */
315
void wpa_supplicant_initiate_eapol(struct wpa_supplicant *wpa_s)
316
0
{
317
0
#ifdef IEEE8021X_EAPOL
318
0
  struct eapol_config eapol_conf;
319
0
  struct wpa_ssid *ssid = wpa_s->current_ssid;
320
321
#ifdef CONFIG_IBSS_RSN
322
  if (ssid->mode == WPAS_MODE_IBSS &&
323
      wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
324
      wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE) {
325
    /*
326
     * RSN IBSS authentication is per-STA and we can disable the
327
     * per-BSSID EAPOL authentication.
328
     */
329
    eapol_sm_notify_portControl(wpa_s->eapol, ForceAuthorized);
330
    eapol_sm_notify_eap_success(wpa_s->eapol, true);
331
    eapol_sm_notify_eap_fail(wpa_s->eapol, false);
332
    return;
333
  }
334
#endif /* CONFIG_IBSS_RSN */
335
336
0
  eapol_sm_notify_eap_success(wpa_s->eapol, false);
337
0
  eapol_sm_notify_eap_fail(wpa_s->eapol, false);
338
339
0
  if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
340
0
      wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
341
0
    eapol_sm_notify_portControl(wpa_s->eapol, ForceAuthorized);
342
0
  else
343
0
    eapol_sm_notify_portControl(wpa_s->eapol, Auto);
344
345
0
  os_memset(&eapol_conf, 0, sizeof(eapol_conf));
346
0
  if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
347
0
    eapol_conf.accept_802_1x_keys = 1;
348
0
    eapol_conf.required_keys = 0;
349
0
    if (ssid->eapol_flags & EAPOL_FLAG_REQUIRE_KEY_UNICAST) {
350
0
      eapol_conf.required_keys |= EAPOL_REQUIRE_KEY_UNICAST;
351
0
    }
352
0
    if (ssid->eapol_flags & EAPOL_FLAG_REQUIRE_KEY_BROADCAST) {
353
0
      eapol_conf.required_keys |=
354
0
        EAPOL_REQUIRE_KEY_BROADCAST;
355
0
    }
356
357
0
    if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED)
358
0
      eapol_conf.required_keys = 0;
359
0
  }
360
0
  eapol_conf.fast_reauth = wpa_s->conf->fast_reauth;
361
0
  eapol_conf.workaround = ssid->eap_workaround;
362
0
  eapol_conf.eap_disabled =
363
0
    !wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) &&
364
0
    wpa_s->key_mgmt != WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
365
0
    wpa_s->key_mgmt != WPA_KEY_MGMT_WPS;
366
0
  eapol_conf.external_sim = wpa_s->conf->external_sim;
367
368
#ifdef CONFIG_WPS
369
  if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
370
    eapol_conf.wps |= EAPOL_LOCAL_WPS_IN_USE;
371
    if (wpa_s->current_bss) {
372
      struct wpabuf *ie;
373
      ie = wpa_bss_get_vendor_ie_multi(wpa_s->current_bss,
374
               WPS_IE_VENDOR_TYPE);
375
      if (ie) {
376
        if (wps_is_20(ie))
377
          eapol_conf.wps |=
378
            EAPOL_PEER_IS_WPS20_AP;
379
        wpabuf_free(ie);
380
      }
381
    }
382
  }
383
#endif /* CONFIG_WPS */
384
385
0
  eapol_sm_notify_config(wpa_s->eapol, &ssid->eap, &eapol_conf);
386
387
#ifdef CONFIG_MACSEC
388
  if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE && ssid->mka_psk_set)
389
    ieee802_1x_create_preshared_mka(wpa_s, ssid);
390
  else
391
    ieee802_1x_alloc_kay_sm(wpa_s, ssid);
392
#endif /* CONFIG_MACSEC */
393
0
#endif /* IEEE8021X_EAPOL */
394
0
}
395
396
397
/**
398
 * wpa_supplicant_set_non_wpa_policy - Set WPA parameters to non-WPA mode
399
 * @wpa_s: Pointer to wpa_supplicant data
400
 * @ssid: Configuration data for the network
401
 *
402
 * This function is used to configure WPA state machine and related parameters
403
 * to a mode where WPA is not enabled. This is called as part of the
404
 * authentication configuration when the selected network does not use WPA.
405
 */
406
void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant *wpa_s,
407
               struct wpa_ssid *ssid)
408
0
{
409
#ifdef CONFIG_WEP
410
  int i;
411
#endif /* CONFIG_WEP */
412
0
  struct wpa_sm_mlo mlo;
413
414
0
  if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
415
0
    wpa_s->key_mgmt = WPA_KEY_MGMT_WPS;
416
0
  else if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)
417
0
    wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
418
0
  else
419
0
    wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
420
0
  wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
421
0
  wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
422
0
  wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
423
0
  wpa_sm_set_ap_rsne_override(wpa_s->wpa, NULL, 0);
424
0
  wpa_sm_set_ap_rsne_override_2(wpa_s->wpa, NULL, 0);
425
0
  wpa_sm_set_ap_rsnxe_override(wpa_s->wpa, NULL, 0);
426
0
  wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
427
0
#ifndef CONFIG_NO_WPA
428
0
  wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
429
0
#endif /* CONFIG_NO_WPA */
430
0
  wpa_s->rsnxe_len = 0;
431
0
  wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
432
0
  wpa_s->group_cipher = WPA_CIPHER_NONE;
433
0
  wpa_s->mgmt_group_cipher = 0;
434
435
#ifdef CONFIG_WEP
436
  for (i = 0; i < NUM_WEP_KEYS; i++) {
437
    if (ssid->wep_key_len[i] > 5) {
438
      wpa_s->pairwise_cipher = WPA_CIPHER_WEP104;
439
      wpa_s->group_cipher = WPA_CIPHER_WEP104;
440
      break;
441
    } else if (ssid->wep_key_len[i] > 0) {
442
      wpa_s->pairwise_cipher = WPA_CIPHER_WEP40;
443
      wpa_s->group_cipher = WPA_CIPHER_WEP40;
444
      break;
445
    }
446
  }
447
#endif /* CONFIG_WEP */
448
449
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED, 0);
450
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
451
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
452
0
       wpa_s->pairwise_cipher);
453
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
454
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
455
0
       wpa_s->mgmt_group_cipher);
456
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_SSID_PROTECTION, 0);
457
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_ASSOC_ENC, 0);
458
459
0
  pmksa_cache_clear_current(wpa_s->wpa);
460
0
  os_memset(&mlo, 0, sizeof(mlo));
461
0
  wpa_sm_set_mlo_params(wpa_s->wpa, &mlo);
462
0
}
463
464
465
void free_hw_features(struct wpa_supplicant *wpa_s)
466
0
{
467
0
  int i;
468
0
  if (wpa_s->hw.modes == NULL)
469
0
    return;
470
471
0
  for (i = 0; i < wpa_s->hw.num_modes; i++) {
472
0
    os_free(wpa_s->hw.modes[i].channels);
473
0
    os_free(wpa_s->hw.modes[i].rates);
474
0
  }
475
476
0
  os_free(wpa_s->hw.modes);
477
0
  wpa_s->hw.modes = NULL;
478
0
}
479
480
481
static void remove_bss_tmp_disallowed_entry(struct wpa_supplicant *wpa_s,
482
              struct wpa_bss_tmp_disallowed *bss)
483
0
{
484
0
  eloop_cancel_timeout(wpa_bss_tmp_disallow_timeout, wpa_s, bss);
485
0
  dl_list_del(&bss->list);
486
0
  os_free(bss);
487
0
}
488
489
490
void free_bss_tmp_disallowed(struct wpa_supplicant *wpa_s)
491
0
{
492
0
  struct wpa_bss_tmp_disallowed *bss, *prev;
493
494
0
  dl_list_for_each_safe(bss, prev, &wpa_s->bss_tmp_disallowed,
495
0
            struct wpa_bss_tmp_disallowed, list)
496
0
    remove_bss_tmp_disallowed_entry(wpa_s, bss);
497
0
}
498
499
500
void wpas_flush_fils_hlp_req(struct wpa_supplicant *wpa_s)
501
0
{
502
0
  struct fils_hlp_req *req;
503
504
0
  while ((req = dl_list_first(&wpa_s->fils_hlp_req, struct fils_hlp_req,
505
0
            list)) != NULL) {
506
0
    dl_list_del(&req->list);
507
0
    wpabuf_free(req->pkt);
508
0
    os_free(req);
509
0
  }
510
0
}
511
512
513
static struct wpabuf * wpas_wfa_gen_capab_attr(struct wpa_supplicant *wpa_s)
514
0
{
515
0
  struct wpabuf *attr;
516
0
  size_t gen_len, supp_len;
517
0
  const u8 *supp;
518
0
  u8 supp_buf[1];
519
520
0
  if (wpa_s->conf->wfa_gen_capa == WFA_GEN_CAPA_DISABLED)
521
0
    return NULL;
522
523
0
  if (!wpa_s->conf->wfa_gen_capa_supp ||
524
0
      wpabuf_len(wpa_s->conf->wfa_gen_capa_supp) == 0) {
525
0
    supp_len = 1;
526
0
    supp_buf[0] = 0;
527
0
    if (wpa_s->hw_capab & BIT(CAPAB_HT))
528
0
      supp_buf[0] |= BIT(0); /* Wi-Fi 4 */
529
0
    if (wpa_s->hw_capab & BIT(CAPAB_VHT))
530
0
      supp_buf[0] |= BIT(1); /* Wi-Fi 5 */
531
0
    if (wpa_s->hw_capab & BIT(CAPAB_HE))
532
0
      supp_buf[0] |= BIT(2); /* Wi-Fi 6 */
533
0
    if (wpa_s->hw_capab & BIT(CAPAB_EHT))
534
0
      supp_buf[0] |= BIT(3); /* Wi-Fi 7 */
535
0
    supp = supp_buf;
536
0
  } else {
537
0
    supp_len = wpabuf_len(wpa_s->conf->wfa_gen_capa_supp);
538
0
    supp = wpabuf_head(wpa_s->conf->wfa_gen_capa_supp);
539
0
  }
540
541
0
  gen_len = 1 + supp_len;
542
543
0
  attr = wpabuf_alloc(2 + gen_len);
544
0
  if (!attr)
545
0
    return NULL;
546
547
0
  wpabuf_put_u8(attr, WFA_CAPA_ATTR_GENERATIONAL_CAPAB);
548
0
  wpabuf_put_u8(attr, gen_len);
549
0
  wpabuf_put_u8(attr, supp_len);
550
0
  wpabuf_put_data(attr, supp, supp_len);
551
552
0
  return attr;
553
0
}
554
555
556
557
static void wpas_wfa_capab_tx(void *eloop_ctx, void *timeout_ctx)
558
0
{
559
0
  struct wpa_supplicant *wpa_s = eloop_ctx;
560
0
  struct wpabuf *attr, *buf;
561
0
  size_t buf_len;
562
563
0
  if (wpa_s->conf->wfa_gen_capa != WFA_GEN_CAPA_PROTECTED ||
564
0
      wpa_s->wpa_state != WPA_COMPLETED ||
565
0
      !pmf_in_use(wpa_s, wpa_s->bssid))
566
0
    return;
567
568
0
  attr = wpas_wfa_gen_capab_attr(wpa_s);
569
0
  if (!attr)
570
0
    return;
571
572
0
  buf_len = 1 + 3 + 1 + 1 + wpabuf_len(attr);
573
0
  buf = wpabuf_alloc(buf_len);
574
0
  if (!buf) {
575
0
    wpabuf_free(attr);
576
0
    return;
577
0
  }
578
579
0
  wpabuf_put_u8(buf, WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED);
580
0
  wpabuf_put_be32(buf, WFA_CAPAB_VENDOR_TYPE);
581
0
  wpabuf_put_u8(buf, 0); /* Capabilities Length */
582
0
  wpabuf_put_buf(buf, attr);
583
0
  wpabuf_free(attr);
584
585
0
  wpa_printf(MSG_DEBUG, "WFA: Send WFA Capabilities frame");
586
0
  if (wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
587
0
        wpa_s->own_addr, wpa_s->bssid,
588
0
        wpabuf_head(buf), wpabuf_len(buf), 0) < 0)
589
0
    wpa_printf(MSG_DEBUG,
590
0
         "WFA: Failed to send WFA Capabilities frame");
591
592
0
  wpabuf_free(buf);
593
0
}
594
595
596
void wpas_clear_disabled_interface(void *eloop_ctx, void *timeout_ctx)
597
0
{
598
0
  struct wpa_supplicant *wpa_s = eloop_ctx;
599
600
0
  if (wpa_s->wpa_state != WPA_INTERFACE_DISABLED)
601
0
    return;
602
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Clear cached state on disabled interface");
603
0
  wpa_bss_flush(wpa_s);
604
0
}
605
606
607
#ifdef CONFIG_TESTING_OPTIONS
608
void wpas_clear_driver_signal_override(struct wpa_supplicant *wpa_s)
609
{
610
  struct driver_signal_override *dso;
611
612
  while ((dso = dl_list_first(&wpa_s->drv_signal_override,
613
            struct driver_signal_override, list))) {
614
    dl_list_del(&dso->list);
615
    os_free(dso);
616
  }
617
}
618
#endif /* CONFIG_TESTING_OPTIONS */
619
620
621
static void wpa_supplicant_cleanup(struct wpa_supplicant *wpa_s)
622
0
{
623
0
  int i;
624
625
0
  bgscan_deinit(wpa_s);
626
0
  autoscan_deinit(wpa_s);
627
0
  scard_deinit(wpa_s->scard);
628
0
  wpa_s->scard = NULL;
629
0
  wpa_sm_set_scard_ctx(wpa_s->wpa, NULL);
630
0
  eapol_sm_register_scard_ctx(wpa_s->eapol, NULL);
631
0
  l2_packet_deinit(wpa_s->l2);
632
0
  wpa_s->l2 = NULL;
633
0
  if (wpa_s->l2_br) {
634
0
    l2_packet_deinit(wpa_s->l2_br);
635
0
    wpa_s->l2_br = NULL;
636
0
  }
637
#ifdef CONFIG_TESTING_OPTIONS
638
  l2_packet_deinit(wpa_s->l2_test);
639
  wpa_s->l2_test = NULL;
640
  os_free(wpa_s->get_pref_freq_list_override);
641
  wpa_s->get_pref_freq_list_override = NULL;
642
  wpabuf_free(wpa_s->last_assoc_req_wpa_ie);
643
  wpa_s->last_assoc_req_wpa_ie = NULL;
644
  os_free(wpa_s->extra_sae_rejected_groups);
645
  wpa_s->extra_sae_rejected_groups = NULL;
646
  wpabuf_free(wpa_s->rsne_override_eapol);
647
  wpa_s->rsne_override_eapol = NULL;
648
  wpabuf_free(wpa_s->rsnxe_override_assoc);
649
  wpa_s->rsnxe_override_assoc = NULL;
650
  wpabuf_free(wpa_s->rsnxe_override_eapol);
651
  wpa_s->rsnxe_override_eapol = NULL;
652
  wpas_clear_driver_signal_override(wpa_s);
653
  for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
654
    wpabuf_free(wpa_s->link_ies[i]);
655
    wpa_s->link_ies[i] = NULL;
656
  }
657
#endif /* CONFIG_TESTING_OPTIONS */
658
659
0
  if (wpa_s->conf != NULL) {
660
0
    struct wpa_ssid *ssid;
661
0
    for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
662
0
      wpas_notify_network_removed(wpa_s, ssid);
663
0
  }
664
665
0
  os_free(wpa_s->confname);
666
0
  wpa_s->confname = NULL;
667
668
0
  os_free(wpa_s->confanother);
669
0
  wpa_s->confanother = NULL;
670
671
0
  os_free(wpa_s->last_con_fail_realm);
672
0
  wpa_s->last_con_fail_realm = NULL;
673
0
  wpa_s->last_con_fail_realm_len = 0;
674
675
0
  wpa_sm_set_eapol(wpa_s->wpa, NULL);
676
0
  eapol_sm_deinit(wpa_s->eapol);
677
0
  wpa_s->eapol = NULL;
678
679
0
  rsn_preauth_deinit(wpa_s->wpa);
680
681
#ifdef CONFIG_TDLS
682
  wpa_tdls_deinit(wpa_s->wpa);
683
#endif /* CONFIG_TDLS */
684
685
0
#ifndef CONFIG_NO_WMM_AC
686
0
  wmm_ac_clear_saved_tspecs(wpa_s);
687
0
#endif /* CONFIG_NO_WMM_AC */
688
0
  pmksa_candidate_free(wpa_s->wpa);
689
0
  ptksa_cache_deinit(wpa_s->ptksa);
690
0
  wpa_s->ptksa = NULL;
691
0
  wpa_sm_deinit(wpa_s->wpa);
692
0
  wpa_s->wpa = NULL;
693
0
  wpa_bssid_ignore_clear(wpa_s);
694
695
#ifdef CONFIG_PASN
696
  wpas_pasn_auth_stop(wpa_s);
697
#endif /* CONFIG_PASN */
698
699
0
  wpa_bss_deinit(wpa_s);
700
701
0
  wpa_supplicant_cancel_delayed_sched_scan(wpa_s);
702
0
  wpa_supplicant_cancel_scan(wpa_s);
703
0
  wpa_supplicant_cancel_auth_timeout(wpa_s);
704
0
  eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
705
#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
706
  eloop_cancel_timeout(wpa_supplicant_delayed_mic_error_report,
707
           wpa_s, NULL);
708
#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
709
710
0
  eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
711
0
  eloop_cancel_timeout(wpas_clear_disabled_interface, wpa_s, NULL);
712
0
  eloop_cancel_timeout(wpas_verify_ssid_beacon, wpa_s, NULL);
713
0
  eloop_cancel_timeout(wpas_wfa_capab_tx, wpa_s, NULL);
714
715
0
  wpas_wps_deinit(wpa_s);
716
717
0
  wpabuf_free(wpa_s->pending_eapol_rx);
718
0
  wpa_s->pending_eapol_rx = NULL;
719
720
#ifdef CONFIG_IBSS_RSN
721
  ibss_rsn_deinit(wpa_s->ibss_rsn);
722
  wpa_s->ibss_rsn = NULL;
723
#endif /* CONFIG_IBSS_RSN */
724
725
0
  sme_deinit(wpa_s);
726
727
#ifdef CONFIG_AP
728
  wpa_supplicant_ap_deinit(wpa_s);
729
#endif /* CONFIG_AP */
730
731
0
  wpas_p2p_deinit(wpa_s);
732
733
0
  wpas_pr_deinit(wpa_s);
734
735
#ifdef CONFIG_OFFCHANNEL
736
  offchannel_deinit(wpa_s);
737
#endif /* CONFIG_OFFCHANNEL */
738
739
0
  wpa_supplicant_cancel_sched_scan(wpa_s);
740
741
0
  os_free(wpa_s->next_scan_freqs);
742
0
  wpa_s->next_scan_freqs = NULL;
743
744
0
  os_free(wpa_s->manual_scan_freqs);
745
0
  wpa_s->manual_scan_freqs = NULL;
746
0
  os_free(wpa_s->select_network_scan_freqs);
747
0
  wpa_s->select_network_scan_freqs = NULL;
748
749
0
  os_free(wpa_s->manual_sched_scan_freqs);
750
0
  wpa_s->manual_sched_scan_freqs = NULL;
751
752
0
  wpas_mac_addr_rand_scan_clear(wpa_s, MAC_ADDR_RAND_ALL);
753
754
  /*
755
   * Need to remove any pending gas-query radio work before the
756
   * gas_query_deinit() call because gas_query::work has not yet been set
757
   * for works that have not been started. gas_query_free() will be unable
758
   * to cancel such pending radio works and once the pending gas-query
759
   * radio work eventually gets removed, the deinit notification call to
760
   * gas_query_start_cb() would result in dereferencing freed memory.
761
   */
762
0
  if (wpa_s->radio)
763
0
    radio_remove_works(wpa_s, "gas-query", 0);
764
0
  gas_query_deinit(wpa_s->gas);
765
0
  wpa_s->gas = NULL;
766
0
  gas_server_deinit(wpa_s->gas_server);
767
0
  wpa_s->gas_server = NULL;
768
769
0
  free_hw_features(wpa_s);
770
771
0
  ieee802_1x_dealloc_kay_sm(wpa_s);
772
773
0
  os_free(wpa_s->bssid_filter);
774
0
  wpa_s->bssid_filter = NULL;
775
776
0
  os_free(wpa_s->disallow_aps_bssid);
777
0
  wpa_s->disallow_aps_bssid = NULL;
778
0
  os_free(wpa_s->disallow_aps_ssid);
779
0
  wpa_s->disallow_aps_ssid = NULL;
780
781
0
  wnm_bss_keep_alive_deinit(wpa_s);
782
0
  wnm_btm_reset(wpa_s);
783
784
0
  ext_password_deinit(wpa_s->ext_pw);
785
0
  wpa_s->ext_pw = NULL;
786
787
0
  wpabuf_free(wpa_s->last_gas_resp);
788
0
  wpa_s->last_gas_resp = NULL;
789
0
  wpabuf_free(wpa_s->prev_gas_resp);
790
0
  wpa_s->prev_gas_resp = NULL;
791
792
0
  os_free(wpa_s->last_scan_res);
793
0
  wpa_s->last_scan_res = NULL;
794
795
#ifdef CONFIG_P2P
796
  os_free(wpa_s->p2p_pmksa_entry);
797
  wpa_s->p2p_pmksa_entry = NULL;
798
#endif /* CONFIG_P2P */
799
800
0
  if (wpa_s->drv_priv)
801
0
    wpa_drv_configure_frame_filters(wpa_s, 0);
802
803
0
  for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) {
804
0
    wpabuf_free(wpa_s->vendor_elem[i]);
805
0
    wpa_s->vendor_elem[i] = NULL;
806
0
  }
807
808
0
#ifndef CONFIG_NO_WMM_AC
809
0
  wmm_ac_notify_disassoc(wpa_s);
810
0
#endif /* CONFIG_NO_WMM_AC */
811
812
0
  wpa_s->sched_scan_plans_num = 0;
813
0
  os_free(wpa_s->sched_scan_plans);
814
0
  wpa_s->sched_scan_plans = NULL;
815
816
#ifdef CONFIG_MBO
817
  wpa_s->non_pref_chan_num = 0;
818
  os_free(wpa_s->non_pref_chan);
819
  wpa_s->non_pref_chan = NULL;
820
#endif /* CONFIG_MBO */
821
822
0
  free_bss_tmp_disallowed(wpa_s);
823
824
0
  wpabuf_free(wpa_s->lci);
825
0
  wpa_s->lci = NULL;
826
0
#ifndef CONFIG_NO_RRM
827
0
  wpas_clear_beacon_rep_data(wpa_s);
828
0
#endif /* CONFIG_NO_RRM */
829
830
#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
831
#ifdef CONFIG_MESH
832
  {
833
    struct external_pmksa_cache *entry;
834
835
    while ((entry = dl_list_last(&wpa_s->mesh_external_pmksa_cache,
836
               struct external_pmksa_cache,
837
               list)) != NULL) {
838
      dl_list_del(&entry->list);
839
      os_free(entry->pmksa_cache);
840
      os_free(entry);
841
    }
842
  }
843
#endif /* CONFIG_MESH */
844
#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
845
846
0
  wpas_flush_fils_hlp_req(wpa_s);
847
848
0
  wpabuf_free(wpa_s->ric_ies);
849
0
  wpa_s->ric_ies = NULL;
850
851
#ifdef CONFIG_DPP
852
  wpas_dpp_deinit(wpa_s);
853
  dpp_global_deinit(wpa_s->dpp);
854
  wpa_s->dpp = NULL;
855
#endif /* CONFIG_DPP */
856
857
0
  wpas_nan_de_deinit(wpa_s);
858
859
#ifdef CONFIG_PASN
860
  wpas_pasn_auth_stop(wpa_s);
861
  wpas_pasn_free_params(wpa_s);
862
#endif /* CONFIG_PASN */
863
0
#ifndef CONFIG_NO_ROBUST_AV
864
0
  wpas_scs_deinit(wpa_s);
865
0
  wpas_dscp_deinit(wpa_s);
866
0
#endif /* CONFIG_NO_ROBUST_AV */
867
868
#ifdef CONFIG_OWE
869
  os_free(wpa_s->owe_trans_scan_freq);
870
  wpa_s->owe_trans_scan_freq = NULL;
871
#endif /* CONFIG_OWE */
872
873
0
  for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
874
0
    wpabuf_free(wpa_s->links[i].ies);
875
0
    wpa_s->links[i].ies = NULL;
876
0
  }
877
0
}
878
879
880
/**
881
 * wpa_clear_keys - Clear keys configured for the driver
882
 * @wpa_s: Pointer to wpa_supplicant data
883
 * @addr: Previously used BSSID or %NULL if not available
884
 *
885
 * This function clears the encryption keys that has been previously configured
886
 * for the driver.
887
 */
888
void wpa_clear_keys(struct wpa_supplicant *wpa_s, const u8 *addr)
889
0
{
890
0
  int i, max = 6;
891
892
  /* MLME-DELETEKEYS.request */
893
0
  for (i = 0; i < max; i++) {
894
0
    if (wpa_s->keys_cleared & BIT(i))
895
0
      continue;
896
0
    wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, i, 0, NULL, 0,
897
0
        NULL, 0, KEY_FLAG_GROUP);
898
0
  }
899
  /* Pairwise Key ID 1 for Extended Key ID is tracked in bit 15 */
900
0
  if (~wpa_s->keys_cleared & (BIT(0) | BIT(15)) && addr &&
901
0
      !is_zero_ether_addr(addr)) {
902
0
    if (!(wpa_s->keys_cleared & BIT(0)))
903
0
      wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, addr, 0, 0,
904
0
          NULL, 0, NULL, 0, KEY_FLAG_PAIRWISE);
905
0
    if (!(wpa_s->keys_cleared & BIT(15)))
906
0
      wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, addr, 1, 0,
907
0
          NULL, 0, NULL, 0, KEY_FLAG_PAIRWISE);
908
    /* MLME-SETPROTECTION.request(None) */
909
0
    wpa_drv_mlme_setprotection(
910
0
      wpa_s, addr,
911
0
      MLME_SETPROTECTION_PROTECT_TYPE_NONE,
912
0
      MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
913
0
  }
914
0
  wpa_s->keys_cleared = (u32) -1;
915
0
}
916
917
918
/**
919
 * wpa_supplicant_state_txt - Get the connection state name as a text string
920
 * @state: State (wpa_state; WPA_*)
921
 * Returns: The state name as a printable text string
922
 */
923
const char * wpa_supplicant_state_txt(enum wpa_states state)
924
0
{
925
0
  switch (state) {
926
0
  case WPA_DISCONNECTED:
927
0
    return "DISCONNECTED";
928
0
  case WPA_INACTIVE:
929
0
    return "INACTIVE";
930
0
  case WPA_INTERFACE_DISABLED:
931
0
    return "INTERFACE_DISABLED";
932
0
  case WPA_SCANNING:
933
0
    return "SCANNING";
934
0
  case WPA_AUTHENTICATING:
935
0
    return "AUTHENTICATING";
936
0
  case WPA_ASSOCIATING:
937
0
    return "ASSOCIATING";
938
0
  case WPA_ASSOCIATED:
939
0
    return "ASSOCIATED";
940
0
  case WPA_4WAY_HANDSHAKE:
941
0
    return "4WAY_HANDSHAKE";
942
0
  case WPA_GROUP_HANDSHAKE:
943
0
    return "GROUP_HANDSHAKE";
944
0
  case WPA_COMPLETED:
945
0
    return "COMPLETED";
946
0
  default:
947
0
    return "UNKNOWN";
948
0
  }
949
0
}
950
951
952
#ifdef CONFIG_BGSCAN
953
954
static void wpa_supplicant_stop_bgscan(struct wpa_supplicant *wpa_s)
955
{
956
  if (wpa_s->bgscan_ssid) {
957
    bgscan_deinit(wpa_s);
958
    wpa_s->bgscan_ssid = NULL;
959
  }
960
}
961
962
963
/**
964
 * wpa_supplicant_reset_bgscan - Reset the bgscan for the current SSID.
965
 * @wpa_s: Pointer to the wpa_supplicant data
966
 *
967
 * Stop, start, or reconfigure the scan parameters depending on the method.
968
 */
969
void wpa_supplicant_reset_bgscan(struct wpa_supplicant *wpa_s)
970
{
971
  const char *name;
972
973
  if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan)
974
    name = wpa_s->current_ssid->bgscan;
975
  else
976
    name = wpa_s->conf->bgscan;
977
  if (!name || name[0] == '\0') {
978
    wpa_supplicant_stop_bgscan(wpa_s);
979
    return;
980
  }
981
  if (wpas_driver_bss_selection(wpa_s))
982
    return;
983
#ifdef CONFIG_P2P
984
  if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)
985
    return;
986
#endif /* CONFIG_P2P */
987
988
  bgscan_deinit(wpa_s);
989
  if (wpa_s->current_ssid) {
990
    if (bgscan_init(wpa_s, wpa_s->current_ssid, name)) {
991
      wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize "
992
        "bgscan");
993
      /*
994
       * Live without bgscan; it is only used as a roaming
995
       * optimization, so the initial connection is not
996
       * affected.
997
       */
998
    } else {
999
      struct wpa_scan_results *scan_res;
1000
      wpa_s->bgscan_ssid = wpa_s->current_ssid;
1001
      scan_res = wpa_supplicant_get_scan_results(wpa_s, NULL,
1002
                   0, NULL);
1003
      if (scan_res) {
1004
        bgscan_notify_scan(wpa_s, scan_res);
1005
        wpa_scan_results_free(scan_res);
1006
      }
1007
    }
1008
  } else
1009
    wpa_s->bgscan_ssid = NULL;
1010
}
1011
1012
#endif /* CONFIG_BGSCAN */
1013
1014
1015
static void wpa_supplicant_start_autoscan(struct wpa_supplicant *wpa_s)
1016
0
{
1017
0
  if (autoscan_init(wpa_s, 0))
1018
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize autoscan");
1019
0
}
1020
1021
1022
static void wpa_supplicant_stop_autoscan(struct wpa_supplicant *wpa_s)
1023
0
{
1024
0
  autoscan_deinit(wpa_s);
1025
0
}
1026
1027
1028
void wpa_supplicant_reinit_autoscan(struct wpa_supplicant *wpa_s)
1029
0
{
1030
0
  if (wpa_s->wpa_state == WPA_DISCONNECTED ||
1031
0
      wpa_s->wpa_state == WPA_SCANNING) {
1032
0
    autoscan_deinit(wpa_s);
1033
0
    wpa_supplicant_start_autoscan(wpa_s);
1034
0
  }
1035
0
}
1036
1037
1038
static void wpas_verify_ssid_beacon(void *eloop_ctx, void *timeout_ctx)
1039
0
{
1040
0
  struct wpa_supplicant *wpa_s = eloop_ctx;
1041
0
  struct wpa_bss *bss;
1042
0
  const u8 *ssid;
1043
0
  size_t ssid_len;
1044
1045
0
  if (!wpa_s->current_ssid || !wpa_s->current_bss)
1046
0
    return;
1047
1048
0
  ssid = wpa_s->current_bss->ssid;
1049
0
  ssid_len = wpa_s->current_bss->ssid_len;
1050
1051
0
  if (wpa_s->current_ssid->ssid_len &&
1052
0
      (wpa_s->current_ssid->ssid_len != ssid_len ||
1053
0
       os_memcmp(wpa_s->current_ssid->ssid, ssid, ssid_len) != 0))
1054
0
    return;
1055
1056
0
  if (wpa_s->wpa_state < WPA_4WAY_HANDSHAKE ||
1057
0
      !wpa_s->bigtk_set || wpa_s->ssid_verified)
1058
0
    return;
1059
1060
0
  wpa_printf(MSG_DEBUG,
1061
0
       "SSID not yet verified; check if the driver has received a verified Beacon frame");
1062
0
  if (wpa_supplicant_update_scan_results(wpa_s, wpa_s->bssid) < 0)
1063
0
    return;
1064
1065
  /* wpa->current_bss might have changed due to memory reallocation, so
1066
   * need to update ssid/ssid_len */
1067
0
  if (!wpa_s->current_bss)
1068
0
    return;
1069
0
  ssid = wpa_s->current_bss->ssid;
1070
0
  ssid_len = wpa_s->current_bss->ssid_len;
1071
1072
0
  bss = wpa_bss_get_bssid_latest(wpa_s, wpa_s->bssid);
1073
0
  if (!bss)
1074
0
    return;
1075
0
  wpa_printf(MSG_DEBUG, "The current beacon time stamp: 0x%llx",
1076
0
       (long long unsigned int) bss->tsf);
1077
0
  if (bss->tsf > wpa_s->first_beacon_tsf) {
1078
0
    const u8 *ie;
1079
1080
0
    wpa_printf(MSG_DEBUG,
1081
0
         "Verified Beacon frame has been received");
1082
0
    wpa_s->beacons_checked++;
1083
1084
0
    ie = wpa_bss_get_ie_beacon(bss, WLAN_EID_SSID);
1085
0
    if (ie && ie[1] == ssid_len &&
1086
0
        os_memcmp(&ie[2], ssid, ssid_len) == 0) {
1087
0
      wpa_printf(MSG_DEBUG,
1088
0
           "SSID verified based on a Beacon frame and beacon protection");
1089
0
      wpa_s->ssid_verified = true;
1090
0
      return;
1091
0
    }
1092
1093
    /* TODO: Multiple BSSID element */
1094
0
  }
1095
1096
0
  if (wpa_s->beacons_checked < 16) {
1097
0
    eloop_register_timeout(wpa_s->next_beacon_check, 0,
1098
0
               wpas_verify_ssid_beacon, wpa_s, NULL);
1099
0
    wpa_s->next_beacon_check++;
1100
0
  }
1101
0
}
1102
1103
1104
static void wpas_verify_ssid_beacon_prot(struct wpa_supplicant *wpa_s)
1105
0
{
1106
0
  struct wpa_bss *bss;
1107
1108
0
  wpa_printf(MSG_DEBUG,
1109
0
       "SSID not yet verified; try to verify using beacon protection");
1110
  /* Fetch the current scan result which is likely based on not yet
1111
   * verified payload since the current BIGTK was just received. Any
1112
   * newer update in the future with a larger timestamp value is an
1113
   * indication that a verified Beacon frame has been received. */
1114
0
  if (wpa_supplicant_update_scan_results(wpa_s, wpa_s->bssid) < 0)
1115
0
    return;
1116
1117
0
  bss = wpa_bss_get_bssid_latest(wpa_s, wpa_s->bssid);
1118
0
  if (!bss)
1119
0
    return;
1120
0
  wpa_printf(MSG_DEBUG, "The initial beacon time stamp: 0x%llx",
1121
0
       (long long unsigned int) bss->tsf);
1122
0
  wpa_s->first_beacon_tsf = bss->tsf;
1123
0
  wpa_s->beacons_checked = 0;
1124
0
  wpa_s->next_beacon_check = 1;
1125
0
  eloop_cancel_timeout(wpas_verify_ssid_beacon, wpa_s, NULL);
1126
0
  eloop_register_timeout(1, 0, wpas_verify_ssid_beacon, wpa_s, NULL);
1127
0
}
1128
1129
1130
/**
1131
 * wpa_supplicant_set_state - Set current connection state
1132
 * @wpa_s: Pointer to wpa_supplicant data
1133
 * @state: The new connection state
1134
 *
1135
 * This function is called whenever the connection state changes, e.g.,
1136
 * association is completed for WPA/WPA2 4-Way Handshake is started.
1137
 */
1138
void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s,
1139
            enum wpa_states state)
1140
0
{
1141
0
  enum wpa_states old_state = wpa_s->wpa_state;
1142
#if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL)
1143
  bool update_fils_connect_params = false;
1144
#endif /* CONFIG_FILS && IEEE8021X_EAPOL */
1145
1146
0
  wpa_dbg(wpa_s, MSG_DEBUG, "State: %s -> %s",
1147
0
    wpa_supplicant_state_txt(wpa_s->wpa_state),
1148
0
    wpa_supplicant_state_txt(state));
1149
1150
0
  if (state == WPA_COMPLETED &&
1151
0
      os_reltime_initialized(&wpa_s->roam_start)) {
1152
0
    os_reltime_age(&wpa_s->roam_start, &wpa_s->roam_time);
1153
0
    wpa_s->roam_start.sec = 0;
1154
0
    wpa_s->roam_start.usec = 0;
1155
0
    wpas_notify_auth_changed(wpa_s);
1156
0
    wpas_notify_roam_time(wpa_s);
1157
0
    wpas_notify_roam_complete(wpa_s);
1158
0
  } else if (state == WPA_DISCONNECTED &&
1159
0
       os_reltime_initialized(&wpa_s->roam_start)) {
1160
0
    wpa_s->roam_start.sec = 0;
1161
0
    wpa_s->roam_start.usec = 0;
1162
0
    wpa_s->roam_time.sec = 0;
1163
0
    wpa_s->roam_time.usec = 0;
1164
0
    wpas_notify_roam_complete(wpa_s);
1165
0
  }
1166
1167
0
  if (state == WPA_INTERFACE_DISABLED) {
1168
    /* Assure normal scan when interface is restored */
1169
0
    wpa_s->normal_scans = 0;
1170
1171
    /*
1172
     * A NAN management interface is not expected to be disabled. If
1173
     * it disabled, it means that NAN functionality is no longer
1174
     * possible so deinit (which would also stop any ongoing NAN
1175
     * operations).
1176
     */
1177
0
    if (wpa_s->nan_mgmt)
1178
0
      wpas_nan_deinit(wpa_s);
1179
0
  }
1180
1181
0
  if (state == WPA_COMPLETED) {
1182
0
    wpas_connect_work_done(wpa_s);
1183
    /* Reinitialize normal_scan counter */
1184
0
    wpa_s->normal_scans = 0;
1185
0
  }
1186
1187
#ifdef CONFIG_P2P
1188
  /*
1189
   * P2PS client has to reply to Probe Request frames received on the
1190
   * group operating channel. Enable Probe Request frame reporting for
1191
   * P2P connected client in case p2p_cli_probe configuration property is
1192
   * set to 1.
1193
   */
1194
  if (wpa_s->conf->p2p_cli_probe && wpa_s->current_ssid &&
1195
      wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
1196
      wpa_s->current_ssid->p2p_group) {
1197
    if (state == WPA_COMPLETED && !wpa_s->p2p_cli_probe) {
1198
      wpa_dbg(wpa_s, MSG_DEBUG,
1199
        "P2P: Enable CLI Probe Request RX reporting");
1200
      wpa_s->p2p_cli_probe =
1201
        wpa_drv_probe_req_report(wpa_s, 1) >= 0;
1202
    } else if (state != WPA_COMPLETED && wpa_s->p2p_cli_probe) {
1203
      wpa_dbg(wpa_s, MSG_DEBUG,
1204
        "P2P: Disable CLI Probe Request RX reporting");
1205
      wpa_s->p2p_cli_probe = 0;
1206
      wpa_drv_probe_req_report(wpa_s, 0);
1207
    }
1208
  }
1209
#endif /* CONFIG_P2P */
1210
1211
0
  if (state != WPA_SCANNING)
1212
0
    wpa_supplicant_notify_scanning(wpa_s, 0);
1213
1214
0
  if (state == WPA_COMPLETED && wpa_s->new_connection) {
1215
0
    struct wpa_ssid *ssid = wpa_s->current_ssid;
1216
0
    int fils_hlp_sent = 0;
1217
0
    char mld_addr[50];
1218
1219
0
    mld_addr[0] = '\0';
1220
0
    if (wpa_s->valid_links)
1221
0
      os_snprintf(mld_addr, sizeof(mld_addr),
1222
0
            " ap_mld_addr=" MACSTR,
1223
0
            MAC2STR(wpa_s->ap_mld_addr));
1224
1225
#ifdef CONFIG_SME
1226
    if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1227
        wpa_auth_alg_fils(wpa_s->sme.auth_alg))
1228
      fils_hlp_sent = 1;
1229
#endif /* CONFIG_SME */
1230
0
    if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1231
0
        wpa_auth_alg_fils(wpa_s->auth_alg))
1232
0
      fils_hlp_sent = 1;
1233
1234
0
#if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
1235
0
    wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED "- Connection to "
1236
0
      MACSTR " completed [id=%d id_str=%s%s]%s",
1237
0
      MAC2STR(wpa_s->bssid),
1238
0
      ssid ? ssid->id : -1,
1239
0
      ssid && ssid->id_str ? ssid->id_str : "",
1240
0
      fils_hlp_sent ? " FILS_HLP_SENT" : "", mld_addr);
1241
0
#endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
1242
0
    wpas_clear_temp_disabled(wpa_s, ssid, 1);
1243
0
    wpa_s->consecutive_conn_failures = 0;
1244
0
    wpa_s->new_connection = 0;
1245
0
    wpa_drv_set_operstate(wpa_s, 1);
1246
#ifndef IEEE8021X_EAPOL
1247
    wpa_drv_set_supp_port(wpa_s, 1);
1248
#endif /* IEEE8021X_EAPOL */
1249
0
    wpa_s->after_wps = 0;
1250
0
    wpa_s->known_wps_freq = 0;
1251
0
    wpas_p2p_completed(wpa_s);
1252
1253
0
    sme_sched_obss_scan(wpa_s, 1);
1254
1255
#if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL)
1256
    if (!fils_hlp_sent && ssid && ssid->eap.erp)
1257
      update_fils_connect_params = true;
1258
#endif /* CONFIG_FILS && IEEE8021X_EAPOL */
1259
#ifdef CONFIG_OWE
1260
    if (ssid && (ssid->key_mgmt & WPA_KEY_MGMT_OWE))
1261
      wpas_update_owe_connect_params(wpa_s);
1262
#endif /* CONFIG_OWE */
1263
0
    if (wpa_s->conf->wfa_gen_capa == WFA_GEN_CAPA_PROTECTED &&
1264
0
        pmf_in_use(wpa_s, wpa_s->bssid)) {
1265
0
      eloop_cancel_timeout(wpas_wfa_capab_tx, wpa_s, NULL);
1266
0
      eloop_register_timeout(0, 100000, wpas_wfa_capab_tx,
1267
0
                 wpa_s, NULL);
1268
0
    }
1269
0
  } else if (state == WPA_DISCONNECTED || state == WPA_ASSOCIATING ||
1270
0
       state == WPA_ASSOCIATED) {
1271
0
    wpa_s->new_connection = 1;
1272
0
    wpa_drv_set_operstate(wpa_s, 0);
1273
#ifndef IEEE8021X_EAPOL
1274
    wpa_drv_set_supp_port(wpa_s, 0);
1275
#endif /* IEEE8021X_EAPOL */
1276
0
    sme_sched_obss_scan(wpa_s, 0);
1277
0
  }
1278
0
  wpa_s->wpa_state = state;
1279
1280
0
#ifndef CONFIG_NO_ROBUST_AV
1281
0
  if (state == WPA_COMPLETED && dl_list_len(&wpa_s->active_scs_ids) &&
1282
0
      wpa_s->scs_reconfigure)
1283
0
    wpas_scs_reconfigure(wpa_s);
1284
0
#endif /* CONFIG_NO_ROBUST_AV */
1285
1286
#ifdef CONFIG_BGSCAN
1287
  if (state == WPA_COMPLETED && wpa_s->current_ssid != wpa_s->bgscan_ssid)
1288
    wpa_supplicant_reset_bgscan(wpa_s);
1289
  else if (state < WPA_ASSOCIATED)
1290
    wpa_supplicant_stop_bgscan(wpa_s);
1291
#endif /* CONFIG_BGSCAN */
1292
1293
0
  if (state > WPA_SCANNING)
1294
0
    wpa_supplicant_stop_autoscan(wpa_s);
1295
1296
0
  if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
1297
0
    wpa_supplicant_start_autoscan(wpa_s);
1298
1299
0
  if (state == WPA_COMPLETED || state == WPA_INTERFACE_DISABLED ||
1300
0
      state == WPA_INACTIVE)
1301
0
    wnm_btm_reset(wpa_s);
1302
1303
0
#ifndef CONFIG_NO_WMM_AC
1304
0
  if (old_state >= WPA_ASSOCIATED && wpa_s->wpa_state < WPA_ASSOCIATED)
1305
0
    wmm_ac_notify_disassoc(wpa_s);
1306
0
#endif /* CONFIG_NO_WMM_AC */
1307
1308
0
  if (wpa_s->wpa_state != old_state) {
1309
0
    wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state);
1310
1311
    /*
1312
     * Notify the P2P Device interface about a state change in one
1313
     * of the interfaces.
1314
     */
1315
0
    wpas_p2p_indicate_state_change(wpa_s);
1316
1317
0
    if (wpa_s->wpa_state == WPA_COMPLETED ||
1318
0
        old_state == WPA_COMPLETED)
1319
0
      wpas_notify_auth_changed(wpa_s);
1320
#ifdef CONFIG_DPP2
1321
    if (wpa_s->wpa_state == WPA_COMPLETED)
1322
      wpas_dpp_connected(wpa_s);
1323
#endif /* CONFIG_DPP2 */
1324
1325
0
    if (wpa_s->wpa_state == WPA_COMPLETED &&
1326
0
        wpa_s->bigtk_set && !wpa_s->ssid_verified)
1327
0
      wpas_verify_ssid_beacon_prot(wpa_s);
1328
0
  }
1329
#if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL)
1330
  if (update_fils_connect_params)
1331
    wpas_update_fils_connect_params(wpa_s);
1332
#endif /* CONFIG_FILS && IEEE8021X_EAPOL */
1333
1334
0
  wpas_nan_usd_state_change_notif(wpa_s);
1335
0
}
1336
1337
1338
void wpa_supplicant_terminate_proc(struct wpa_global *global)
1339
0
{
1340
0
  int pending = 0;
1341
#ifdef CONFIG_WPS
1342
  struct wpa_supplicant *wpa_s = global->ifaces;
1343
  while (wpa_s) {
1344
    struct wpa_supplicant *next = wpa_s->next;
1345
    if (wpas_wps_terminate_pending(wpa_s) == 1)
1346
      pending = 1;
1347
#ifdef CONFIG_P2P
1348
    if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE ||
1349
        (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group))
1350
      wpas_p2p_disconnect(wpa_s);
1351
#endif /* CONFIG_P2P */
1352
    wpa_s = next;
1353
  }
1354
#endif /* CONFIG_WPS */
1355
0
  if (pending)
1356
0
    return;
1357
0
  eloop_terminate();
1358
0
}
1359
1360
1361
static void wpa_supplicant_terminate(int sig, void *signal_ctx)
1362
0
{
1363
0
  struct wpa_global *global = signal_ctx;
1364
0
  wpa_supplicant_terminate_proc(global);
1365
0
}
1366
1367
1368
void wpa_supplicant_clear_status(struct wpa_supplicant *wpa_s)
1369
0
{
1370
0
  enum wpa_states old_state = wpa_s->wpa_state;
1371
0
  enum wpa_states new_state;
1372
1373
0
  if (old_state == WPA_SCANNING)
1374
0
    new_state = WPA_SCANNING;
1375
0
  else
1376
0
    new_state = WPA_DISCONNECTED;
1377
1378
0
  wpa_s->pairwise_cipher = 0;
1379
0
  wpa_s->group_cipher = 0;
1380
0
  wpa_s->mgmt_group_cipher = 0;
1381
0
  wpa_s->key_mgmt = 0;
1382
0
  wpa_s->allowed_key_mgmts = 0;
1383
0
  if (wpa_s->wpa_state != WPA_INTERFACE_DISABLED)
1384
0
    wpa_supplicant_set_state(wpa_s, new_state);
1385
1386
0
  if (wpa_s->wpa_state != old_state)
1387
0
    wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state);
1388
0
}
1389
1390
1391
/**
1392
 * wpa_supplicant_reload_configuration - Reload configuration data
1393
 * @wpa_s: Pointer to wpa_supplicant data
1394
 * Returns: 0 on success or -1 if configuration parsing failed
1395
 *
1396
 * This function can be used to request that the configuration data is reloaded
1397
 * (e.g., after configuration file change). This function is reloading
1398
 * configuration only for one interface, so this may need to be called multiple
1399
 * times if %wpa_supplicant is controlling multiple interfaces and all
1400
 * interfaces need reconfiguration.
1401
 */
1402
int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s)
1403
0
{
1404
0
  struct wpa_config *conf;
1405
0
  int reconf_ctrl;
1406
0
  int old_ap_scan;
1407
1408
0
  if (wpa_s->confname == NULL)
1409
0
    return -1;
1410
0
  conf = wpa_config_read(wpa_s->confname, NULL, false,
1411
0
             wpa_s->global->params.show_details);
1412
0
  if (conf == NULL) {
1413
0
    wpa_msg(wpa_s, MSG_ERROR, "Failed to parse the configuration "
1414
0
      "file '%s' - exiting", wpa_s->confname);
1415
0
    return -1;
1416
0
  }
1417
0
  if (wpa_s->confanother &&
1418
0
      !wpa_config_read(wpa_s->confanother, conf, true,
1419
0
           wpa_s->global->params.show_details)) {
1420
0
    wpa_msg(wpa_s, MSG_ERROR,
1421
0
      "Failed to parse the configuration file '%s' - exiting",
1422
0
      wpa_s->confanother);
1423
0
    return -1;
1424
0
  }
1425
1426
0
  conf->changed_parameters = (unsigned int) -1;
1427
1428
0
  reconf_ctrl = !!conf->ctrl_interface != !!wpa_s->conf->ctrl_interface
1429
0
    || (conf->ctrl_interface && wpa_s->conf->ctrl_interface &&
1430
0
        os_strcmp(conf->ctrl_interface,
1431
0
            wpa_s->conf->ctrl_interface) != 0);
1432
1433
0
  if (reconf_ctrl) {
1434
0
    wpa_supplicant_ctrl_iface_deinit(wpa_s, wpa_s->ctrl_iface);
1435
0
    wpa_s->ctrl_iface = NULL;
1436
0
  }
1437
1438
0
  eapol_sm_invalidate_cached_session(wpa_s->eapol);
1439
0
  if (wpa_s->current_ssid) {
1440
0
    if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1441
0
      wpa_s->own_disconnect_req = 1;
1442
0
    wpa_supplicant_deauthenticate(wpa_s,
1443
0
                WLAN_REASON_DEAUTH_LEAVING);
1444
0
  }
1445
1446
  /*
1447
   * TODO: should notify EAPOL SM about changes in opensc_engine_path,
1448
   * pkcs11_engine_path, pkcs11_module_path, openssl_ciphers.
1449
   */
1450
0
  if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
1451
0
      wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
1452
0
      wpa_s->key_mgmt == WPA_KEY_MGMT_DPP) {
1453
    /*
1454
     * Clear forced success to clear EAP state for next
1455
     * authentication.
1456
     */
1457
0
    eapol_sm_notify_eap_success(wpa_s->eapol, false);
1458
0
  }
1459
0
  eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
1460
0
  wpa_sm_set_config(wpa_s->wpa, NULL);
1461
0
  wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
1462
0
  wpa_sm_set_fast_reauth(wpa_s->wpa, wpa_s->conf->fast_reauth);
1463
0
  rsn_preauth_deinit(wpa_s->wpa);
1464
1465
0
  old_ap_scan = wpa_s->conf->ap_scan;
1466
0
  wpa_config_free(wpa_s->conf);
1467
0
  wpa_s->conf = conf;
1468
0
  if (old_ap_scan != wpa_s->conf->ap_scan)
1469
0
    wpas_notify_ap_scan_changed(wpa_s);
1470
1471
0
  if (reconf_ctrl)
1472
0
    wpa_s->ctrl_iface = wpa_supplicant_ctrl_iface_init(wpa_s);
1473
1474
0
  wpa_supplicant_update_config(wpa_s);
1475
1476
0
  wpa_supplicant_clear_status(wpa_s);
1477
0
  if (wpa_supplicant_enabled_networks(wpa_s)) {
1478
0
    wpa_s->reassociate = 1;
1479
0
    wpa_supplicant_req_scan(wpa_s, 0, 0);
1480
0
  }
1481
0
  wpa_bssid_ignore_clear(wpa_s);
1482
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Reconfiguration completed");
1483
0
  return 0;
1484
0
}
1485
1486
1487
static void wpa_supplicant_reconfig(int sig, void *signal_ctx)
1488
0
{
1489
0
  struct wpa_global *global = signal_ctx;
1490
0
  struct wpa_supplicant *wpa_s;
1491
0
  for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
1492
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Signal %d received - reconfiguring",
1493
0
      sig);
1494
0
    if (wpa_supplicant_reload_configuration(wpa_s) < 0) {
1495
0
      wpa_supplicant_terminate_proc(global);
1496
0
    }
1497
0
  }
1498
1499
0
  if (wpa_debug_reopen_file() < 0) {
1500
    /* Ignore errors since we cannot really do much to fix this */
1501
0
    wpa_printf(MSG_DEBUG, "Could not reopen debug log file");
1502
0
  }
1503
0
}
1504
1505
1506
static int wpa_supplicant_suites_from_ai(struct wpa_supplicant *wpa_s,
1507
           struct wpa_ssid *ssid,
1508
           struct wpa_ie_data *ie)
1509
0
{
1510
0
  int ret = wpa_sm_parse_own_wpa_ie(wpa_s->wpa, ie);
1511
0
  if (ret) {
1512
0
    if (ret == -2) {
1513
0
      wpa_msg(wpa_s, MSG_INFO, "WPA: Failed to parse WPA IE "
1514
0
        "from association info");
1515
0
    }
1516
0
    return -1;
1517
0
  }
1518
1519
0
  wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Using WPA IE from AssocReq to set "
1520
0
    "cipher suites");
1521
0
  if (!(ie->group_cipher & ssid->group_cipher)) {
1522
0
    wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled group "
1523
0
      "cipher 0x%x (mask 0x%x) - reject",
1524
0
      ie->group_cipher, ssid->group_cipher);
1525
0
    return -1;
1526
0
  }
1527
0
  if (!(ie->pairwise_cipher & ssid->pairwise_cipher)) {
1528
0
    wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled pairwise "
1529
0
      "cipher 0x%x (mask 0x%x) - reject",
1530
0
      ie->pairwise_cipher, ssid->pairwise_cipher);
1531
0
    return -1;
1532
0
  }
1533
0
  if (!(ie->key_mgmt & ssid->key_mgmt)) {
1534
0
    wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled key "
1535
0
      "management 0x%x (mask 0x%x) - reject",
1536
0
      ie->key_mgmt, ssid->key_mgmt);
1537
0
    return -1;
1538
0
  }
1539
1540
0
  if (!(ie->capabilities & WPA_CAPABILITY_MFPC) &&
1541
0
      wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED) {
1542
0
    wpa_msg(wpa_s, MSG_INFO, "WPA: Driver associated with an AP "
1543
0
      "that does not support management frame protection - "
1544
0
      "reject");
1545
0
    return -1;
1546
0
  }
1547
1548
0
  return 0;
1549
0
}
1550
1551
1552
static int matching_ciphers(struct wpa_ssid *ssid, struct wpa_ie_data *ie,
1553
          int freq)
1554
0
{
1555
0
  if (!ie->has_group)
1556
0
    ie->group_cipher = wpa_default_rsn_cipher(freq);
1557
0
  if (!ie->has_pairwise)
1558
0
    ie->pairwise_cipher = wpa_default_rsn_cipher(freq);
1559
0
  return (ie->group_cipher & ssid->group_cipher) &&
1560
0
    (ie->pairwise_cipher & ssid->pairwise_cipher);
1561
0
}
1562
1563
1564
void wpas_set_mgmt_group_cipher(struct wpa_supplicant *wpa_s,
1565
        struct wpa_ssid *ssid, struct wpa_ie_data *ie)
1566
0
{
1567
0
  int sel;
1568
1569
0
  sel = ie->mgmt_group_cipher;
1570
0
  if (ssid->group_mgmt_cipher)
1571
0
    sel &= ssid->group_mgmt_cipher;
1572
0
  if (wpas_get_ssid_pmf(wpa_s, ssid) == NO_MGMT_FRAME_PROTECTION ||
1573
0
      !(ie->capabilities & WPA_CAPABILITY_MFPC))
1574
0
    sel = 0;
1575
0
  wpa_dbg(wpa_s, MSG_DEBUG,
1576
0
    "WPA: AP mgmt_group_cipher 0x%x network profile mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
1577
0
    ie->mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
1578
0
  if (sel & WPA_CIPHER_AES_128_CMAC) {
1579
0
    wpa_s->mgmt_group_cipher = WPA_CIPHER_AES_128_CMAC;
1580
0
    wpa_dbg(wpa_s, MSG_DEBUG,
1581
0
      "WPA: using MGMT group cipher AES-128-CMAC");
1582
0
  } else if (sel & WPA_CIPHER_BIP_GMAC_128) {
1583
0
    wpa_s->mgmt_group_cipher = WPA_CIPHER_BIP_GMAC_128;
1584
0
    wpa_dbg(wpa_s, MSG_DEBUG,
1585
0
      "WPA: using MGMT group cipher BIP-GMAC-128");
1586
0
  } else if (sel & WPA_CIPHER_BIP_GMAC_256) {
1587
0
    wpa_s->mgmt_group_cipher = WPA_CIPHER_BIP_GMAC_256;
1588
0
    wpa_dbg(wpa_s, MSG_DEBUG,
1589
0
      "WPA: using MGMT group cipher BIP-GMAC-256");
1590
0
  } else if (sel & WPA_CIPHER_BIP_CMAC_256) {
1591
0
    wpa_s->mgmt_group_cipher = WPA_CIPHER_BIP_CMAC_256;
1592
0
    wpa_dbg(wpa_s, MSG_DEBUG,
1593
0
      "WPA: using MGMT group cipher BIP-CMAC-256");
1594
0
  } else {
1595
0
    wpa_s->mgmt_group_cipher = 0;
1596
0
    wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
1597
0
  }
1598
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
1599
0
       wpa_s->mgmt_group_cipher);
1600
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP,
1601
0
       wpas_get_ssid_pmf(wpa_s, ssid));
1602
0
}
1603
1604
/**
1605
 * wpa_supplicant_get_psk - Get PSK from config or external database
1606
 * @wpa_s: Pointer to wpa_supplicant data
1607
 * @bss: Scan results for the selected BSS, or %NULL if not available
1608
 * @ssid: Configuration data for the selected network
1609
 * @psk: Buffer for the PSK
1610
 * Returns: 0 on success or -1 if configuration parsing failed
1611
 *
1612
 * This function obtains the PSK for a network, either included inline in the
1613
 * config or retrieved from an external database.
1614
 */
1615
static int wpa_supplicant_get_psk(struct wpa_supplicant *wpa_s,
1616
          struct wpa_bss *bss, struct wpa_ssid *ssid,
1617
          u8 *psk)
1618
0
{
1619
0
  if (ssid->psk_set) {
1620
0
    wpa_hexdump_key(MSG_MSGDUMP, "PSK (set in config)",
1621
0
        ssid->psk, PMK_LEN);
1622
0
    os_memcpy(psk, ssid->psk, PMK_LEN);
1623
0
    return 0;
1624
0
  }
1625
1626
0
#ifndef CONFIG_NO_PBKDF2
1627
0
  if (bss && ssid->bssid_set && ssid->ssid_len == 0 && ssid->passphrase) {
1628
0
    if (pbkdf2_sha1(ssid->passphrase, bss->ssid, bss->ssid_len,
1629
0
        4096, psk, PMK_LEN) != 0) {
1630
0
      wpa_msg(wpa_s, MSG_WARNING, "Error in pbkdf2_sha1()");
1631
0
      return -1;
1632
0
    }
1633
0
    wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
1634
0
        psk, PMK_LEN);
1635
0
    return 0;
1636
0
  }
1637
0
#endif /* CONFIG_NO_PBKDF2 */
1638
1639
#ifdef CONFIG_EXT_PASSWORD
1640
  if (ssid->ext_psk) {
1641
    struct wpabuf *pw = ext_password_get(wpa_s->ext_pw,
1642
                 ssid->ext_psk);
1643
    char pw_str[64 + 1];
1644
1645
    if (!pw) {
1646
      wpa_msg(wpa_s, MSG_INFO,
1647
        "EXT PW: No PSK found from external storage");
1648
      return -1;
1649
    }
1650
1651
    if (wpabuf_len(pw) < 8 || wpabuf_len(pw) > 64) {
1652
      wpa_msg(wpa_s, MSG_INFO,
1653
        "EXT PW: Unexpected PSK length %d in external storage",
1654
        (int) wpabuf_len(pw));
1655
      ext_password_free(pw);
1656
      return -1;
1657
    }
1658
1659
    os_memcpy(pw_str, wpabuf_head(pw), wpabuf_len(pw));
1660
    pw_str[wpabuf_len(pw)] = '\0';
1661
1662
#ifndef CONFIG_NO_PBKDF2
1663
    if (wpabuf_len(pw) >= 8 && wpabuf_len(pw) < 64 && bss)
1664
    {
1665
      if (pbkdf2_sha1(pw_str, bss->ssid, bss->ssid_len,
1666
          4096, psk, PMK_LEN) != 0) {
1667
        wpa_msg(wpa_s, MSG_WARNING,
1668
          "Error in pbkdf2_sha1()");
1669
        forced_memzero(pw_str, sizeof(pw_str));
1670
        ext_password_free(pw);
1671
        return -1;
1672
      }
1673
      wpa_hexdump_key(MSG_MSGDUMP,
1674
          "PSK (from external passphrase)",
1675
          psk, PMK_LEN);
1676
    } else
1677
#endif /* CONFIG_NO_PBKDF2 */
1678
    if (wpabuf_len(pw) == 2 * PMK_LEN) {
1679
      if (hexstr2bin(pw_str, psk, PMK_LEN) < 0) {
1680
        wpa_msg(wpa_s, MSG_INFO,
1681
          "EXT PW: Invalid PSK hex string");
1682
        forced_memzero(pw_str, sizeof(pw_str));
1683
        ext_password_free(pw);
1684
        return -1;
1685
      }
1686
      wpa_hexdump_key(MSG_MSGDUMP, "PSK (from external PSK)",
1687
          psk, PMK_LEN);
1688
    } else {
1689
      wpa_msg(wpa_s, MSG_INFO,
1690
        "EXT PW: No suitable PSK available");
1691
      forced_memzero(pw_str, sizeof(pw_str));
1692
      ext_password_free(pw);
1693
      return -1;
1694
    }
1695
1696
    forced_memzero(pw_str, sizeof(pw_str));
1697
    ext_password_free(pw);
1698
1699
    return 0;
1700
  }
1701
#endif /* CONFIG_EXT_PASSWORD */
1702
1703
0
  return -1;
1704
0
}
1705
1706
1707
static void wpas_update_allowed_key_mgmt(struct wpa_supplicant *wpa_s,
1708
           struct wpa_ssid *ssid)
1709
0
{
1710
0
  int akm_count = wpa_s->max_num_akms;
1711
0
  u8 capab = 0;
1712
#ifdef CONFIG_SAE
1713
  enum sae_pwe sae_pwe;
1714
#endif /* CONFIG_SAE */
1715
1716
0
  if (akm_count < 2)
1717
0
    return;
1718
1719
0
  akm_count--;
1720
0
  wpa_s->allowed_key_mgmts = 0;
1721
0
  switch (wpa_s->key_mgmt) {
1722
0
  case WPA_KEY_MGMT_PSK:
1723
0
    if (ssid->key_mgmt & WPA_KEY_MGMT_SAE) {
1724
0
      akm_count--;
1725
0
      wpa_s->allowed_key_mgmts |= WPA_KEY_MGMT_SAE;
1726
0
    }
1727
0
    if (!akm_count)
1728
0
      break;
1729
0
    if (ssid->key_mgmt & WPA_KEY_MGMT_SAE_EXT_KEY) {
1730
0
      akm_count--;
1731
0
      wpa_s->allowed_key_mgmts |= WPA_KEY_MGMT_SAE_EXT_KEY;
1732
0
    }
1733
0
    if (!akm_count)
1734
0
      break;
1735
0
    if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
1736
0
      wpa_s->allowed_key_mgmts |=
1737
0
        WPA_KEY_MGMT_PSK_SHA256;
1738
0
    break;
1739
0
  case WPA_KEY_MGMT_PSK_SHA256:
1740
0
    if (ssid->key_mgmt & WPA_KEY_MGMT_SAE) {
1741
0
      akm_count--;
1742
0
      wpa_s->allowed_key_mgmts |= WPA_KEY_MGMT_SAE;
1743
0
    }
1744
0
    if (!akm_count)
1745
0
      break;
1746
0
    if (ssid->key_mgmt & WPA_KEY_MGMT_SAE_EXT_KEY) {
1747
0
      akm_count--;
1748
0
      wpa_s->allowed_key_mgmts |= WPA_KEY_MGMT_SAE_EXT_KEY;
1749
0
    }
1750
0
    if (!akm_count)
1751
0
      break;
1752
0
    if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
1753
0
      wpa_s->allowed_key_mgmts |= WPA_KEY_MGMT_PSK;
1754
0
    break;
1755
0
  case WPA_KEY_MGMT_SAE:
1756
0
    if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) {
1757
0
      akm_count--;
1758
0
      wpa_s->allowed_key_mgmts |= WPA_KEY_MGMT_PSK;
1759
0
    }
1760
0
    if (!akm_count)
1761
0
      break;
1762
0
    if (ssid->key_mgmt & WPA_KEY_MGMT_SAE_EXT_KEY) {
1763
0
      akm_count--;
1764
0
      wpa_s->allowed_key_mgmts |= WPA_KEY_MGMT_SAE_EXT_KEY;
1765
0
    }
1766
0
    if (!akm_count)
1767
0
      break;
1768
0
    if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
1769
0
      wpa_s->allowed_key_mgmts |=
1770
0
        WPA_KEY_MGMT_PSK_SHA256;
1771
0
    break;
1772
0
  case WPA_KEY_MGMT_SAE_EXT_KEY:
1773
0
    if (ssid->key_mgmt & WPA_KEY_MGMT_SAE) {
1774
0
      akm_count--;
1775
0
      wpa_s->allowed_key_mgmts |= WPA_KEY_MGMT_SAE;
1776
0
    }
1777
0
    if (!akm_count)
1778
0
      break;
1779
0
    if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) {
1780
0
      akm_count--;
1781
0
      wpa_s->allowed_key_mgmts |= WPA_KEY_MGMT_PSK;
1782
0
    }
1783
0
    if (!akm_count)
1784
0
      break;
1785
0
    if (ssid->key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
1786
0
      wpa_s->allowed_key_mgmts |=
1787
0
        WPA_KEY_MGMT_PSK_SHA256;
1788
0
    break;
1789
0
  default:
1790
0
    return;
1791
0
  }
1792
1793
#ifdef CONFIG_SAE
1794
  sae_pwe = wpas_get_ssid_sae_pwe(wpa_s, ssid);
1795
  if (sae_pwe != SAE_PWE_HUNT_AND_PECK &&
1796
      sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK)
1797
    capab |= BIT(WLAN_RSNX_CAPAB_SAE_H2E);
1798
#ifdef CONFIG_SAE_PK
1799
  if (ssid->sae_pk)
1800
    capab |= BIT(WLAN_RSNX_CAPAB_SAE_PK);
1801
#endif /* CONFIG_SAE_PK */
1802
#endif /* CONFIG_SAE */
1803
1804
0
  if (!((wpa_s->allowed_key_mgmts &
1805
0
         (WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_SAE_EXT_KEY)) && capab))
1806
0
    return;
1807
1808
0
  if (!wpa_s->rsnxe_len) {
1809
0
    wpa_s->rsnxe_len = 3;
1810
0
    wpa_s->rsnxe[0] = WLAN_EID_RSNX;
1811
0
    wpa_s->rsnxe[1] = 1;
1812
0
    wpa_s->rsnxe[2] = 0;
1813
0
  }
1814
1815
0
  wpa_s->rsnxe[2] |= capab;
1816
0
}
1817
1818
1819
/**
1820
 * wpa_supplicant_set_suites - Set authentication and encryption parameters
1821
 * @wpa_s: Pointer to wpa_supplicant data
1822
 * @bss: Scan results for the selected BSS, or %NULL if not available
1823
 * @ssid: Configuration data for the selected network
1824
 * @wpa_ie: Buffer for the WPA/RSN IE
1825
 * @wpa_ie_len: Maximum wpa_ie buffer size on input. This is changed to be the
1826
 * used buffer length in case the functions returns success.
1827
 * @skip_default_rsne: Whether to skip setting of the default RSNE/RSNXE
1828
 * Returns: 0 on success or -1 on failure
1829
 *
1830
 * This function is used to configure authentication and encryption parameters
1831
 * based on the network configuration and scan result for the selected BSS (if
1832
 * available).
1833
 */
1834
int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
1835
            struct wpa_bss *bss, struct wpa_ssid *ssid,
1836
            u8 *wpa_ie, size_t *wpa_ie_len,
1837
            bool skip_default_rsne)
1838
0
{
1839
0
  struct wpa_ie_data ie;
1840
0
  int sel, proto;
1841
#ifdef CONFIG_SAE
1842
  enum sae_pwe sae_pwe;
1843
#endif /* CONFIG_SAE */
1844
0
  const u8 *bss_wpa, *bss_rsn, *bss_rsnx;
1845
0
  bool wmm;
1846
0
  struct rsn_pmksa_cache_entry *pmksa;
1847
1848
0
  if (bss) {
1849
0
    bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1850
0
    bss_rsn = wpa_bss_get_rsne(wpa_s, bss, ssid, false);
1851
0
    bss_rsnx = wpa_bss_get_rsnxe(wpa_s, bss, ssid, false);
1852
0
  } else {
1853
0
    bss_wpa = bss_rsn = bss_rsnx = NULL;
1854
0
  }
1855
1856
0
  if (bss_rsn && (ssid->proto & WPA_PROTO_RSN) &&
1857
0
      wpa_parse_wpa_ie(bss_rsn, 2 + bss_rsn[1], &ie) == 0 &&
1858
0
      matching_ciphers(ssid, &ie, bss->freq) &&
1859
0
      (ie.key_mgmt & ssid->key_mgmt)) {
1860
0
    wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using IEEE 802.11i/D9.0");
1861
0
    proto = WPA_PROTO_RSN;
1862
0
  } else if (bss_wpa && (ssid->proto & WPA_PROTO_WPA) &&
1863
0
       wpa_parse_wpa_ie(bss_wpa, 2 + bss_wpa[1], &ie) == 0 &&
1864
0
       (ie.group_cipher & ssid->group_cipher) &&
1865
0
       (ie.pairwise_cipher & ssid->pairwise_cipher) &&
1866
0
       (ie.key_mgmt & ssid->key_mgmt)) {
1867
0
    wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using IEEE 802.11i/D3.0");
1868
0
    proto = WPA_PROTO_WPA;
1869
0
  } else if (bss) {
1870
0
    wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select WPA/RSN");
1871
0
    wpa_dbg(wpa_s, MSG_DEBUG,
1872
0
      "WPA: ssid proto=0x%x pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x",
1873
0
      ssid->proto, ssid->pairwise_cipher, ssid->group_cipher,
1874
0
      ssid->key_mgmt);
1875
0
    wpa_dbg(wpa_s, MSG_DEBUG, "WPA: BSS " MACSTR " ssid='%s'%s%s",
1876
0
      MAC2STR(bss->bssid),
1877
0
      wpa_ssid_txt(bss->ssid, bss->ssid_len),
1878
0
      bss_wpa ? " WPA" : "",
1879
0
      bss_rsn ? " RSN" : "");
1880
0
    if (bss_rsn) {
1881
0
      wpa_hexdump(MSG_DEBUG, "RSN", bss_rsn, 2 + bss_rsn[1]);
1882
0
      if (wpa_parse_wpa_ie(bss_rsn, 2 + bss_rsn[1], &ie)) {
1883
0
        wpa_dbg(wpa_s, MSG_DEBUG,
1884
0
          "Could not parse RSN element");
1885
0
      } else {
1886
0
        wpa_dbg(wpa_s, MSG_DEBUG,
1887
0
          "RSN: pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x",
1888
0
          ie.pairwise_cipher, ie.group_cipher,
1889
0
          ie.key_mgmt);
1890
0
      }
1891
0
    }
1892
0
    if (bss_wpa) {
1893
0
      wpa_hexdump(MSG_DEBUG, "WPA", bss_wpa, 2 + bss_wpa[1]);
1894
0
      if (wpa_parse_wpa_ie(bss_wpa, 2 + bss_wpa[1], &ie)) {
1895
0
        wpa_dbg(wpa_s, MSG_DEBUG,
1896
0
          "Could not parse WPA element");
1897
0
      } else {
1898
0
        wpa_dbg(wpa_s, MSG_DEBUG,
1899
0
          "WPA: pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x",
1900
0
          ie.pairwise_cipher, ie.group_cipher,
1901
0
          ie.key_mgmt);
1902
0
      }
1903
0
    }
1904
0
    return -1;
1905
0
  } else {
1906
0
    if (ssid->proto & WPA_PROTO_RSN)
1907
0
      proto = WPA_PROTO_RSN;
1908
0
    else
1909
0
      proto = WPA_PROTO_WPA;
1910
0
    if (wpa_supplicant_suites_from_ai(wpa_s, ssid, &ie) < 0) {
1911
0
      os_memset(&ie, 0, sizeof(ie));
1912
0
      ie.group_cipher = ssid->group_cipher;
1913
0
      ie.pairwise_cipher = ssid->pairwise_cipher;
1914
0
      ie.key_mgmt = ssid->key_mgmt;
1915
0
      ie.mgmt_group_cipher = 0;
1916
0
      if (ssid->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
1917
0
        if (ssid->group_mgmt_cipher &
1918
0
            WPA_CIPHER_BIP_GMAC_256)
1919
0
          ie.mgmt_group_cipher =
1920
0
            WPA_CIPHER_BIP_GMAC_256;
1921
0
        else if (ssid->group_mgmt_cipher &
1922
0
           WPA_CIPHER_BIP_CMAC_256)
1923
0
          ie.mgmt_group_cipher =
1924
0
            WPA_CIPHER_BIP_CMAC_256;
1925
0
        else if (ssid->group_mgmt_cipher &
1926
0
           WPA_CIPHER_BIP_GMAC_128)
1927
0
          ie.mgmt_group_cipher =
1928
0
            WPA_CIPHER_BIP_GMAC_128;
1929
0
        else
1930
0
          ie.mgmt_group_cipher =
1931
0
            WPA_CIPHER_AES_128_CMAC;
1932
0
      }
1933
#ifdef CONFIG_OWE
1934
      if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1935
          !ssid->owe_only &&
1936
          !bss_wpa && !bss_rsn) {
1937
        wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
1938
        wpa_s->wpa_proto = 0;
1939
        *wpa_ie_len = 0;
1940
        return 0;
1941
      }
1942
#endif /* CONFIG_OWE */
1943
0
      wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Set cipher suites "
1944
0
        "based on configuration");
1945
0
    } else
1946
0
      proto = ie.proto;
1947
0
  }
1948
1949
0
  wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected cipher suites: group %d "
1950
0
    "pairwise %d key_mgmt %d proto %d",
1951
0
    ie.group_cipher, ie.pairwise_cipher, ie.key_mgmt, proto);
1952
0
  if (ssid->ieee80211w) {
1953
0
    wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected mgmt group cipher %d",
1954
0
      ie.mgmt_group_cipher);
1955
0
  }
1956
1957
0
  wpa_s->wpa_proto = proto;
1958
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, proto);
1959
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
1960
0
       !!(ssid->proto & WPA_PROTO_RSN));
1961
1962
0
  if (bss || !wpa_s->ap_ies_from_associnfo) {
1963
0
    const u8 *rsnoe = NULL, *rsno2e = NULL, *rsnxoe = NULL;
1964
1965
0
    if (bss) {
1966
0
      bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1967
0
      bss_rsnx = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
1968
0
      rsnoe = wpa_bss_get_vendor_ie(
1969
0
        bss, RSNE_OVERRIDE_IE_VENDOR_TYPE);
1970
0
      rsno2e = wpa_bss_get_vendor_ie(
1971
0
        bss, RSNE_OVERRIDE_2_IE_VENDOR_TYPE);
1972
0
      rsnxoe = wpa_bss_get_vendor_ie(
1973
0
        bss, RSNXE_OVERRIDE_IE_VENDOR_TYPE);
1974
0
    }
1975
1976
0
    if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1977
0
           bss_wpa ? 2 + bss_wpa[1] : 0) ||
1978
0
        wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1979
0
           bss_rsn ? 2 + bss_rsn[1] : 0) ||
1980
0
        wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
1981
0
          bss_rsnx ? 2 + bss_rsnx[1] : 0) ||
1982
0
        wpa_sm_set_ap_rsne_override(wpa_s->wpa, rsnoe,
1983
0
            rsnoe ? 2 + rsnoe[1] : 0) ||
1984
0
        wpa_sm_set_ap_rsne_override_2(wpa_s->wpa, rsno2e,
1985
0
              rsno2e ? 2 + rsno2e[1] : 0) ||
1986
0
        wpa_sm_set_ap_rsnxe_override(wpa_s->wpa, rsnxoe,
1987
0
             rsnxoe ? 2 + rsnxoe[1] : 0))
1988
0
      return -1;
1989
0
  }
1990
1991
#ifdef CONFIG_NO_WPA
1992
  wpa_s->group_cipher = WPA_CIPHER_NONE;
1993
  wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
1994
#else /* CONFIG_NO_WPA */
1995
0
  sel = ie.group_cipher & ssid->group_cipher;
1996
0
  wpa_dbg(wpa_s, MSG_DEBUG,
1997
0
    "WPA: AP group 0x%x network profile group 0x%x; available group 0x%x",
1998
0
    ie.group_cipher, ssid->group_cipher, sel);
1999
0
  wpa_s->group_cipher = wpa_pick_group_cipher(sel);
2000
0
  if (wpa_s->group_cipher < 0) {
2001
0
    wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select group "
2002
0
      "cipher");
2003
0
    return -1;
2004
0
  }
2005
0
  wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
2006
0
    wpa_cipher_txt(wpa_s->group_cipher));
2007
2008
0
  sel = ie.pairwise_cipher & ssid->pairwise_cipher;
2009
0
  wpa_dbg(wpa_s, MSG_DEBUG,
2010
0
    "WPA: AP pairwise 0x%x network profile pairwise 0x%x; available pairwise 0x%x",
2011
0
    ie.pairwise_cipher, ssid->pairwise_cipher, sel);
2012
0
  wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(sel, 1);
2013
0
  if (wpa_s->pairwise_cipher < 0) {
2014
0
    wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select pairwise "
2015
0
      "cipher");
2016
0
    return -1;
2017
0
  }
2018
0
  wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
2019
0
    wpa_cipher_txt(wpa_s->pairwise_cipher));
2020
0
#endif /* CONFIG_NO_WPA */
2021
2022
0
  sel = ie.key_mgmt & ssid->key_mgmt;
2023
#ifdef CONFIG_SAE
2024
  if ((!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) &&
2025
       !(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_SAE_OFFLOAD_STA)) ||
2026
      wpas_is_sae_avoided(wpa_s, ssid, &ie))
2027
    sel &= ~(WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_SAE_EXT_KEY |
2028
       WPA_KEY_MGMT_FT_SAE | WPA_KEY_MGMT_FT_SAE_EXT_KEY);
2029
#endif /* CONFIG_SAE */
2030
#ifdef CONFIG_IEEE80211R
2031
  if (!(wpa_s->drv_flags & (WPA_DRIVER_FLAGS_SME |
2032
          WPA_DRIVER_FLAGS_UPDATE_FT_IES)))
2033
    sel &= ~WPA_KEY_MGMT_FT;
2034
#endif /* CONFIG_IEEE80211R */
2035
0
  wpa_dbg(wpa_s, MSG_DEBUG,
2036
0
    "WPA: AP key_mgmt 0x%x network profile key_mgmt 0x%x; available key_mgmt 0x%x",
2037
0
    ie.key_mgmt, ssid->key_mgmt, sel);
2038
0
  if (0) {
2039
#ifdef CONFIG_IEEE80211R
2040
#ifdef CONFIG_SHA384
2041
  } else if ((sel & WPA_KEY_MGMT_FT_IEEE8021X_SHA384) &&
2042
       os_strcmp(wpa_supplicant_get_eap_mode(wpa_s), "LEAP") != 0) {
2043
    wpa_s->key_mgmt = WPA_KEY_MGMT_FT_IEEE8021X_SHA384;
2044
    wpa_dbg(wpa_s, MSG_DEBUG,
2045
      "WPA: using KEY_MGMT FT/802.1X-SHA384");
2046
    if (!ssid->ft_eap_pmksa_caching &&
2047
        pmksa_cache_get_current(wpa_s->wpa)) {
2048
      /* PMKSA caching with FT may have interoperability
2049
       * issues, so disable that case by default for now. */
2050
      wpa_dbg(wpa_s, MSG_DEBUG,
2051
        "WPA: Disable PMKSA caching for FT/802.1X connection");
2052
      pmksa_cache_clear_current(wpa_s->wpa);
2053
    }
2054
#endif /* CONFIG_SHA384 */
2055
#endif /* CONFIG_IEEE80211R */
2056
#ifdef CONFIG_SUITEB192
2057
  } else if (sel & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
2058
    wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SUITE_B_192;
2059
    wpa_dbg(wpa_s, MSG_DEBUG,
2060
      "WPA: using KEY_MGMT 802.1X with Suite B (192-bit)");
2061
#endif /* CONFIG_SUITEB192 */
2062
#ifdef CONFIG_SUITEB
2063
  } else if (sel & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
2064
    wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SUITE_B;
2065
    wpa_dbg(wpa_s, MSG_DEBUG,
2066
      "WPA: using KEY_MGMT 802.1X with Suite B");
2067
#endif /* CONFIG_SUITEB */
2068
#ifdef CONFIG_SHA384
2069
  } else if (sel & WPA_KEY_MGMT_IEEE8021X_SHA384) {
2070
    wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SHA384;
2071
    wpa_dbg(wpa_s, MSG_DEBUG,
2072
      "WPA: using KEY_MGMT 802.1X with SHA384");
2073
#endif /* CONFIG_SHA384 */
2074
#ifdef CONFIG_FILS
2075
#ifdef CONFIG_IEEE80211R
2076
  } else if (sel & WPA_KEY_MGMT_FT_FILS_SHA384) {
2077
    wpa_s->key_mgmt = WPA_KEY_MGMT_FT_FILS_SHA384;
2078
    wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT-FILS-SHA384");
2079
#endif /* CONFIG_IEEE80211R */
2080
  } else if (sel & WPA_KEY_MGMT_FILS_SHA384) {
2081
    wpa_s->key_mgmt = WPA_KEY_MGMT_FILS_SHA384;
2082
    wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FILS-SHA384");
2083
#ifdef CONFIG_IEEE80211R
2084
  } else if (sel & WPA_KEY_MGMT_FT_FILS_SHA256) {
2085
    wpa_s->key_mgmt = WPA_KEY_MGMT_FT_FILS_SHA256;
2086
    wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT-FILS-SHA256");
2087
#endif /* CONFIG_IEEE80211R */
2088
  } else if (sel & WPA_KEY_MGMT_FILS_SHA256) {
2089
    wpa_s->key_mgmt = WPA_KEY_MGMT_FILS_SHA256;
2090
    wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FILS-SHA256");
2091
#endif /* CONFIG_FILS */
2092
#ifdef CONFIG_IEEE80211R
2093
  } else if ((sel & WPA_KEY_MGMT_FT_IEEE8021X) &&
2094
       os_strcmp(wpa_supplicant_get_eap_mode(wpa_s), "LEAP") != 0) {
2095
    wpa_s->key_mgmt = WPA_KEY_MGMT_FT_IEEE8021X;
2096
    wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT/802.1X");
2097
    if (!ssid->ft_eap_pmksa_caching &&
2098
        pmksa_cache_get_current(wpa_s->wpa)) {
2099
      /* PMKSA caching with FT may have interoperability
2100
       * issues, so disable that case by default for now. */
2101
      wpa_dbg(wpa_s, MSG_DEBUG,
2102
        "WPA: Disable PMKSA caching for FT/802.1X connection");
2103
      pmksa_cache_clear_current(wpa_s->wpa);
2104
    }
2105
#endif /* CONFIG_IEEE80211R */
2106
#ifdef CONFIG_DPP
2107
  } else if (sel & WPA_KEY_MGMT_DPP) {
2108
    wpa_s->key_mgmt = WPA_KEY_MGMT_DPP;
2109
    wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT DPP");
2110
#endif /* CONFIG_DPP */
2111
#ifdef CONFIG_SAE
2112
  } else if (sel & WPA_KEY_MGMT_FT_SAE_EXT_KEY) {
2113
    wpa_s->key_mgmt = WPA_KEY_MGMT_FT_SAE_EXT_KEY;
2114
    wpa_dbg(wpa_s, MSG_DEBUG,
2115
      "RSN: using KEY_MGMT FT/SAE (ext key)");
2116
  } else if (sel & WPA_KEY_MGMT_SAE_EXT_KEY) {
2117
    wpa_s->key_mgmt = WPA_KEY_MGMT_SAE_EXT_KEY;
2118
    wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT SAE (ext key)");
2119
  } else if (sel & WPA_KEY_MGMT_FT_SAE) {
2120
    wpa_s->key_mgmt = WPA_KEY_MGMT_FT_SAE;
2121
    wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT FT/SAE");
2122
  } else if (sel & WPA_KEY_MGMT_SAE) {
2123
    wpa_s->key_mgmt = WPA_KEY_MGMT_SAE;
2124
    wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT SAE");
2125
#endif /* CONFIG_SAE */
2126
#ifdef CONFIG_IEEE80211R
2127
  } else if (sel & WPA_KEY_MGMT_FT_PSK) {
2128
    wpa_s->key_mgmt = WPA_KEY_MGMT_FT_PSK;
2129
    wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT/PSK");
2130
#endif /* CONFIG_IEEE80211R */
2131
0
  } else if (sel & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2132
0
    wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SHA256;
2133
0
    wpa_dbg(wpa_s, MSG_DEBUG,
2134
0
      "WPA: using KEY_MGMT 802.1X with SHA256");
2135
0
  } else if (sel & WPA_KEY_MGMT_PSK_SHA256) {
2136
0
    wpa_s->key_mgmt = WPA_KEY_MGMT_PSK_SHA256;
2137
0
    wpa_dbg(wpa_s, MSG_DEBUG,
2138
0
      "WPA: using KEY_MGMT PSK with SHA256");
2139
0
  } else if (sel & WPA_KEY_MGMT_IEEE8021X) {
2140
0
    wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X;
2141
0
    wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT 802.1X");
2142
0
  } else if (sel & WPA_KEY_MGMT_PSK) {
2143
0
    wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
2144
0
    wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT WPA-PSK");
2145
0
  } else if (sel & WPA_KEY_MGMT_WPA_NONE) {
2146
0
    wpa_s->key_mgmt = WPA_KEY_MGMT_WPA_NONE;
2147
0
    wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT WPA-NONE");
2148
#ifdef CONFIG_OWE
2149
  } else if (sel & WPA_KEY_MGMT_OWE) {
2150
    wpa_s->key_mgmt = WPA_KEY_MGMT_OWE;
2151
    wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT OWE");
2152
#endif /* CONFIG_OWE */
2153
#ifdef CONFIG_ENC_ASSOC
2154
  } else if (sel & WPA_KEY_MGMT_EPPKE) {
2155
    wpa_s->key_mgmt = WPA_KEY_MGMT_EPPKE;
2156
    wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT EPPKE");
2157
#endif /* CONFIG_ENC_ASSOC */
2158
0
  } else {
2159
0
    wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select "
2160
0
      "authenticated key management type");
2161
0
    return -1;
2162
0
  }
2163
2164
  /* There might be a PMKSA cache entry for the target AP, but the current
2165
   * connection is trying to use PSK (which does not use PMKSA caching) or
2166
   * an AKM that does not match the one that was used to generate the
2167
   * selected PMKSA entry. The previously selected PMKSA cache entry needs
2168
   * to be cleared in such cases to avoid indicating an incorrect PMKID
2169
   * and exchange that would likely end up failing with the AP attempting
2170
   * to use a different PMK. This is not really supposed to happen in
2171
   * normal use cases, but it is possible that some corner cases of the AP
2172
   * changing its configuration might trigger a failure due to mismatching
2173
   * PMK. */
2174
0
  pmksa = pmksa_cache_get_current(wpa_s->wpa);
2175
0
  if (pmksa &&
2176
0
      (wpa_key_mgmt_wpa_psk_no_sae(wpa_s->key_mgmt) ||
2177
0
       (pmksa->akmp && pmksa->akmp != wpa_s->key_mgmt))) {
2178
0
    wpa_printf(MSG_DEBUG,
2179
0
         "RSN: Disable PMKSA caching due to incompatible AKMP (PMKSA: 0x%x, selected: 0x%x)",
2180
0
         pmksa->akmp, wpa_s->key_mgmt);
2181
0
    pmksa_cache_clear_current(wpa_s->wpa);
2182
0
  }
2183
2184
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
2185
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
2186
0
       wpa_s->pairwise_cipher);
2187
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
2188
2189
0
  if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
2190
0
      (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED ||
2191
0
       (bss && is_6ghz_freq(bss->freq)))) {
2192
0
    wpa_msg(wpa_s, MSG_INFO,
2193
0
      "RSN: Management frame protection required but the selected AP does not enable it");
2194
0
    return -1;
2195
0
  }
2196
2197
0
  wpas_set_mgmt_group_cipher(wpa_s, ssid, &ie);
2198
#ifdef CONFIG_OCV
2199
  if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
2200
      (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV))
2201
    wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV, ssid->ocv);
2202
#endif /* CONFIG_OCV */
2203
#ifdef CONFIG_SAE
2204
  sae_pwe = wpas_get_ssid_sae_pwe(wpa_s, ssid);
2205
  if ((ssid->sae_password_id ||
2206
       wpa_key_mgmt_sae_ext_key(wpa_s->key_mgmt)) &&
2207
      sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK)
2208
    sae_pwe = SAE_PWE_HASH_TO_ELEMENT;
2209
  if (bss && is_6ghz_freq(bss->freq) &&
2210
      sae_pwe == SAE_PWE_HUNT_AND_PECK) {
2211
    wpa_dbg(wpa_s, MSG_DEBUG,
2212
      "RSN: Enable SAE hash-to-element mode for 6 GHz BSS");
2213
    sae_pwe = SAE_PWE_BOTH;
2214
  }
2215
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_SAE_PWE, sae_pwe);
2216
#ifdef CONFIG_SAE_PK
2217
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_SAE_PK,
2218
       wpa_key_mgmt_sae(ssid->key_mgmt) &&
2219
       ssid->sae_pk != SAE_PK_MODE_DISABLED &&
2220
       ((ssid->sae_password &&
2221
         sae_pk_valid_password(ssid->sae_password)) ||
2222
        (!ssid->sae_password && ssid->passphrase &&
2223
         sae_pk_valid_password(ssid->passphrase))));
2224
#endif /* CONFIG_SAE_PK */
2225
#endif /* CONFIG_SAE */
2226
0
  if (bss && is_6ghz_freq(bss->freq) &&
2227
0
      wpas_get_ssid_pmf(wpa_s, ssid) != MGMT_FRAME_PROTECTION_REQUIRED) {
2228
0
    wpa_dbg(wpa_s, MSG_DEBUG, "RSN: Force MFPR=1 on 6 GHz");
2229
0
    wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP,
2230
0
         MGMT_FRAME_PROTECTION_REQUIRED);
2231
0
  }
2232
#ifdef CONFIG_TESTING_OPTIONS
2233
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_FT_RSNXE_USED,
2234
       wpa_s->ft_rsnxe_used);
2235
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_EAPOL,
2236
       wpa_s->oci_freq_override_eapol);
2237
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_EAPOL_G2,
2238
       wpa_s->oci_freq_override_eapol_g2);
2239
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_FT_ASSOC,
2240
       wpa_s->oci_freq_override_ft_assoc);
2241
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_FILS_ASSOC,
2242
       wpa_s->oci_freq_override_fils_assoc);
2243
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_DISABLE_EAPOL_G2_TX,
2244
       wpa_s->disable_eapol_g2_tx);
2245
  wpa_sm_set_param(wpa_s->wpa,
2246
       WPA_PARAM_EAPOL_2_KEY_INFO_SET_MASK,
2247
       wpa_s->eapol_2_key_info_set_mask);
2248
#endif /* CONFIG_TESTING_OPTIONS */
2249
2250
  /* Extended Key ID is only supported in infrastructure BSS so far */
2251
0
  if (ssid->mode == WPAS_MODE_INFRA && wpa_s->conf->extended_key_id &&
2252
0
      (ssid->proto & WPA_PROTO_RSN) &&
2253
0
      ssid->pairwise_cipher & (WPA_CIPHER_CCMP | WPA_CIPHER_CCMP_256 |
2254
0
             WPA_CIPHER_GCMP | WPA_CIPHER_GCMP_256) &&
2255
0
      (wpa_s->drv_flags & WPA_DRIVER_FLAGS_EXTENDED_KEY_ID)) {
2256
0
    int use_ext_key_id = 0;
2257
2258
0
    wpa_msg(wpa_s, MSG_DEBUG,
2259
0
      "WPA: Enable Extended Key ID support");
2260
0
    wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_EXT_KEY_ID,
2261
0
         wpa_s->conf->extended_key_id);
2262
0
    if (bss_rsn &&
2263
0
        wpa_s->conf->extended_key_id &&
2264
0
        wpa_s->pairwise_cipher != WPA_CIPHER_TKIP &&
2265
0
        (ie.capabilities & WPA_CAPABILITY_EXT_KEY_ID_FOR_UNICAST))
2266
0
      use_ext_key_id = 1;
2267
0
    wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_USE_EXT_KEY_ID,
2268
0
         use_ext_key_id);
2269
0
  } else {
2270
0
    wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_EXT_KEY_ID, 0);
2271
0
    wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_USE_EXT_KEY_ID, 0);
2272
0
  }
2273
2274
  /* Mark WMM enabled for any HT/VHT/HE/EHT/UHR association to get more
2275
   * appropriate advertisement of the supported number of PTKSA receive
2276
   * counters. In theory, this could be based on a driver capability, but
2277
   * in practice all cases using WMM support at least eight replay
2278
   * counters, so use a hardcoded value for now since there is no explicit
2279
   * driver capability indication for this.
2280
   *
2281
   * In addition, claim WMM to be enabled if the AP supports it since it
2282
   * is far more likely for any current device to support WMM. */
2283
0
  wmm = wpa_s->connection_set &&
2284
0
    (wpa_s->connection_ht || wpa_s->connection_vht ||
2285
0
     wpa_s->connection_he || wpa_s->connection_eht ||
2286
0
     wpa_s->connection_uhr);
2287
0
  if (!wmm && bss)
2288
0
    wmm = !!wpa_bss_get_vendor_ie(bss, WMM_IE_VENDOR_TYPE);
2289
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_WMM_ENABLED, wmm);
2290
2291
0
  if (ssid->ssid_protection && proto == WPA_PROTO_RSN) {
2292
0
    bool ssid_prot;
2293
2294
    /* Enable SSID protection based on the AP advertising support
2295
     * for it to avoid potential interoperability issues with
2296
     * incorrect AP behavior if we were to send an "unexpected"
2297
     * RSNXE with multiple octets of payload. */
2298
0
    ssid_prot = ieee802_11_rsnx_capab(
2299
0
      bss_rsnx, WLAN_RSNX_CAPAB_SSID_PROTECTION);
2300
0
    if (!skip_default_rsne)
2301
0
      wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_SSID_PROTECTION,
2302
0
           proto == WPA_PROTO_RSN && ssid_prot);
2303
0
  } else {
2304
0
    wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_SSID_PROTECTION, false);
2305
0
  }
2306
2307
#ifdef CONFIG_ENC_ASSOC
2308
  if (proto == WPA_PROTO_RSN &&
2309
      (wpa_s->drv_flags2 &
2310
       WPA_DRIVER_FLAGS2_ASSOCIATION_FRAME_ENCRYPTION)) {
2311
    bool assoc_enc;
2312
2313
    /* Enable association frame encryption based on the AP
2314
     * advertising support for it to avoid potential
2315
     * interoperability issues with incorrect AP behavior if we
2316
     * were to send an "unexpected" RSNXE with multiple octets of
2317
     * payload. */
2318
    assoc_enc = ieee802_11_rsnx_capab(
2319
      bss_rsnx, WLAN_RSNX_CAPAB_ASSOC_FRAME_ENCRYPTION);
2320
    if (!skip_default_rsne)
2321
      wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_ASSOC_ENC,
2322
           assoc_enc);
2323
  } else {
2324
    wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_ASSOC_ENC, false);
2325
  }
2326
#endif /* CONFIG_ENC_ASSOC */
2327
2328
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_SPP_AMSDU,
2329
0
       (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_SPP_AMSDU) &&
2330
0
       ieee802_11_rsnx_capab(bss_rsnx,
2331
0
                 WLAN_RSNX_CAPAB_SPP_A_MSDU) &&
2332
0
       wpa_s->pairwise_cipher & (WPA_CIPHER_CCMP_256 |
2333
0
               WPA_CIPHER_GCMP_256 |
2334
0
               WPA_CIPHER_CCMP |
2335
0
               WPA_CIPHER_GCMP) &&
2336
0
       (wpa_s->wpa_proto & WPA_PROTO_RSN));
2337
2338
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_SAE_PW_ID_CHANGE,
2339
0
       ssid->sae_password_id && ssid->sae_password_id_change);
2340
#ifdef CONFIG_PMKSA_PRIVACY
2341
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PMKSA_CACHING_PRIVACY,
2342
       ssid->pmksa_privacy);
2343
#endif /* CONFIG_PMKSA_PRIVACY */
2344
2345
0
  if (!skip_default_rsne) {
2346
0
    if (wpa_sm_set_assoc_wpa_ie_default(wpa_s->wpa, wpa_ie,
2347
0
                wpa_ie_len)) {
2348
0
      wpa_msg(wpa_s, MSG_WARNING,
2349
0
        "RSN: Failed to generate RSNE/WPA IE");
2350
0
      return -1;
2351
0
    }
2352
2353
0
#ifndef CONFIG_NO_WPA
2354
0
    wpa_s->rsnxe_len = sizeof(wpa_s->rsnxe);
2355
0
    if (wpa_sm_set_assoc_rsnxe_default(wpa_s->wpa, wpa_s->rsnxe,
2356
0
               &wpa_s->rsnxe_len)) {
2357
0
      wpa_msg(wpa_s, MSG_WARNING,
2358
0
        "RSN: Failed to generate RSNXE");
2359
0
      return -1;
2360
0
    }
2361
0
#endif /* CONFIG_NO_WPA */
2362
0
  }
2363
2364
0
  if (0) {
2365
#ifdef CONFIG_DPP
2366
  } else if (wpa_s->key_mgmt == WPA_KEY_MGMT_DPP) {
2367
    /* Use PMK from DPP network introduction (PMKSA entry) */
2368
    wpa_sm_set_pmk_from_pmksa(wpa_s->wpa);
2369
#ifdef CONFIG_DPP2
2370
    wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_DPP_PFS, ssid->dpp_pfs);
2371
#endif /* CONFIG_DPP2 */
2372
#endif /* CONFIG_DPP */
2373
0
  } else if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt)) {
2374
0
    int psk_set = 0;
2375
2376
0
    if (wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt)) {
2377
0
      u8 psk[PMK_LEN];
2378
2379
0
      if (wpa_supplicant_get_psk(wpa_s, bss, ssid,
2380
0
               psk) == 0) {
2381
0
        wpa_sm_set_pmk(wpa_s->wpa, psk, PMK_LEN, NULL,
2382
0
                 NULL);
2383
0
        psk_set = 1;
2384
0
      }
2385
0
      forced_memzero(psk, sizeof(psk));
2386
0
    }
2387
2388
0
    if (wpa_key_mgmt_sae(ssid->key_mgmt) &&
2389
0
        (ssid->sae_password || ssid->passphrase || ssid->ext_psk))
2390
0
      psk_set = 1;
2391
2392
0
    if (!psk_set && !ssid->pmk_valid) {
2393
0
      wpa_msg(wpa_s, MSG_INFO,
2394
0
        "No PSK/PMK available for association");
2395
0
      wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE", NULL);
2396
0
      return -1;
2397
0
    }
2398
#ifdef CONFIG_OWE
2399
  } else if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE) {
2400
    /* OWE Diffie-Hellman exchange in (Re)Association
2401
     * Request/Response frames set the PMK, so do not override it
2402
     * here. */
2403
#endif /* CONFIG_OWE */
2404
0
  } else
2405
0
    wpa_sm_set_pmk_from_pmksa(wpa_s->wpa);
2406
2407
0
  if (ssid->mode != WPAS_MODE_IBSS &&
2408
0
      !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED) &&
2409
0
      (ssid->wpa_deny_ptk0_rekey == PTK0_REKEY_ALLOW_NEVER ||
2410
0
       (ssid->wpa_deny_ptk0_rekey == PTK0_REKEY_ALLOW_LOCAL_OK &&
2411
0
        !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAFE_PTK0_REKEYS)))) {
2412
0
    wpa_msg(wpa_s, MSG_INFO,
2413
0
      "Disable PTK0 rekey support - replaced with reconnect");
2414
0
    wpa_s->deny_ptk0_rekey = 1;
2415
0
    wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_DENY_PTK0_REKEY, 1);
2416
0
  } else {
2417
0
    wpa_s->deny_ptk0_rekey = 0;
2418
0
    wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_DENY_PTK0_REKEY, 0);
2419
0
  }
2420
2421
0
  if (wpa_key_mgmt_cross_akm(wpa_s->key_mgmt) &&
2422
0
      !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2423
0
    wpas_update_allowed_key_mgmt(wpa_s, ssid);
2424
2425
0
  return 0;
2426
0
}
2427
2428
2429
static void wpas_ext_capab_byte(struct wpa_supplicant *wpa_s, u8 *pos, int idx,
2430
        struct wpa_bss *bss)
2431
0
{
2432
0
#ifndef CONFIG_NO_ROBUST_AV
2433
0
  bool scs = true, mscs = true;
2434
0
#endif /* CONFIG_NO_ROBUST_AV */
2435
2436
0
  *pos = 0x00;
2437
2438
0
  switch (idx) {
2439
0
  case 0: /* Bits 0-7 */
2440
0
    break;
2441
0
  case 1: /* Bits 8-15 */
2442
0
    if (wpa_s->conf->coloc_intf_reporting) {
2443
      /* Bit 13 - Collocated Interference Reporting */
2444
0
      *pos |= 0x20;
2445
0
    }
2446
0
    break;
2447
0
  case 2: /* Bits 16-23 */
2448
0
#ifdef CONFIG_WNM
2449
0
    *pos |= 0x02; /* Bit 17 - WNM-Sleep Mode */
2450
0
    if ((wpas_driver_bss_selection(wpa_s) ||
2451
0
         !wpa_s->disable_mbo_oce) &&
2452
0
        !wpa_s->conf->disable_btm)
2453
0
      *pos |= 0x08; /* Bit 19 - BSS Transition */
2454
0
#endif /* CONFIG_WNM */
2455
0
    break;
2456
0
  case 3: /* Bits 24-31 */
2457
0
#ifdef CONFIG_WNM
2458
0
    *pos |= 0x02; /* Bit 25 - SSID List */
2459
0
#endif /* CONFIG_WNM */
2460
0
#ifdef CONFIG_INTERWORKING
2461
0
    if (wpa_s->conf->interworking)
2462
0
      *pos |= 0x80; /* Bit 31 - Interworking */
2463
0
#endif /* CONFIG_INTERWORKING */
2464
0
    break;
2465
0
  case 4: /* Bits 32-39 */
2466
0
#ifdef CONFIG_INTERWORKING
2467
0
    if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_QOS_MAPPING)
2468
0
      *pos |= 0x01; /* Bit 32 - QoS Map */
2469
0
#endif /* CONFIG_INTERWORKING */
2470
0
    break;
2471
0
  case 5: /* Bits 40-47 */
2472
0
#ifdef CONFIG_HS20
2473
0
    if (wpa_s->conf->hs20)
2474
0
      *pos |= 0x40; /* Bit 46 - WNM-Notification */
2475
0
#endif /* CONFIG_HS20 */
2476
#ifdef CONFIG_MBO
2477
    *pos |= 0x40; /* Bit 46 - WNM-Notification */
2478
#endif /* CONFIG_MBO */
2479
0
    break;
2480
0
  case 6: /* Bits 48-55 */
2481
0
#ifndef CONFIG_NO_ROBUST_AV
2482
#ifdef CONFIG_TESTING_OPTIONS
2483
    if (wpa_s->disable_scs_support)
2484
      scs = false;
2485
#endif /* CONFIG_TESTING_OPTIONS */
2486
0
    if (bss && !wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_SCS)) {
2487
      /* Drop own SCS capability indication since the AP does
2488
       * not support it. This is needed to avoid
2489
       * interoperability issues with APs that get confused
2490
       * with Extended Capabilities element. */
2491
0
      scs = false;
2492
0
    }
2493
0
    if (scs)
2494
0
      *pos |= 0x40; /* Bit 54 - SCS */
2495
0
#endif /* CONFIG_NO_ROBUST_AV */
2496
0
    break;
2497
0
  case 7: /* Bits 56-63 */
2498
0
    break;
2499
0
  case 8: /* Bits 64-71 */
2500
0
    if (wpa_s->conf->ftm_responder)
2501
0
      *pos |= 0x40; /* Bit 70 - FTM responder */
2502
0
    if (wpa_s->conf->ftm_initiator)
2503
0
      *pos |= 0x80; /* Bit 71 - FTM initiator */
2504
0
    break;
2505
0
  case 9: /* Bits 72-79 */
2506
#ifdef CONFIG_FILS
2507
    if (!wpa_s->disable_fils)
2508
      *pos |= 0x01;
2509
#endif /* CONFIG_FILS */
2510
0
    if (wpa_s->conf->twt_requester)
2511
0
      *pos |= 0x20; /* Bit 77 - TWT Requester Support */
2512
0
    break;
2513
0
  case 10: /* Bits 80-87 */
2514
0
#ifndef CONFIG_NO_ROBUST_AV
2515
#ifdef CONFIG_TESTING_OPTIONS
2516
    if (wpa_s->disable_mscs_support)
2517
      mscs = false;
2518
#endif /* CONFIG_TESTING_OPTIONS */
2519
0
    if (bss && !wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_MSCS)) {
2520
      /* Drop own MSCS capability indication since the AP does
2521
       * not support it. This is needed to avoid
2522
       * interoperability issues with APs that get confused
2523
       * with Extended Capabilities element. */
2524
0
      mscs = false;
2525
0
    }
2526
0
    if (mscs)
2527
0
      *pos |= 0x20; /* Bit 85 - Mirrored SCS */
2528
0
#endif /* CONFIG_NO_ROBUST_AV */
2529
0
    break;
2530
0
  }
2531
0
}
2532
2533
2534
int wpas_build_ext_capab(struct wpa_supplicant *wpa_s, u8 *buf,
2535
        size_t buflen, struct wpa_bss *bss)
2536
0
{
2537
0
  u8 *pos = buf;
2538
0
  u8 len = 11, i;
2539
2540
0
  if (len < wpa_s->extended_capa_len)
2541
0
    len = wpa_s->extended_capa_len;
2542
0
  if (buflen < (size_t) len + 2) {
2543
0
    wpa_printf(MSG_INFO,
2544
0
         "Not enough room for building extended capabilities element");
2545
0
    return -1;
2546
0
  }
2547
2548
0
  *pos++ = WLAN_EID_EXT_CAPAB;
2549
0
  *pos++ = len;
2550
0
  for (i = 0; i < len; i++, pos++) {
2551
0
    wpas_ext_capab_byte(wpa_s, pos, i, bss);
2552
2553
0
    if (i < wpa_s->extended_capa_len) {
2554
0
      *pos &= ~wpa_s->extended_capa_mask[i];
2555
0
      *pos |= wpa_s->extended_capa[i];
2556
0
    }
2557
0
  }
2558
2559
0
  while (len > 0 && buf[1 + len] == 0) {
2560
0
    len--;
2561
0
    buf[1] = len;
2562
0
  }
2563
0
  if (len == 0)
2564
0
    return 0;
2565
2566
0
  return 2 + len;
2567
0
}
2568
2569
2570
static int wpas_valid_bss(struct wpa_supplicant *wpa_s,
2571
        struct wpa_bss *test_bss)
2572
0
{
2573
0
  struct wpa_bss *bss;
2574
2575
0
  dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
2576
0
    if (bss == test_bss)
2577
0
      return 1;
2578
0
  }
2579
2580
0
  return 0;
2581
0
}
2582
2583
2584
static int wpas_valid_ssid(struct wpa_supplicant *wpa_s,
2585
         struct wpa_ssid *test_ssid)
2586
0
{
2587
0
  struct wpa_ssid *ssid;
2588
2589
0
  for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
2590
0
    if (ssid == test_ssid)
2591
0
      return 1;
2592
0
  }
2593
2594
0
  return 0;
2595
0
}
2596
2597
2598
int wpas_valid_bss_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *test_bss,
2599
      struct wpa_ssid *test_ssid)
2600
0
{
2601
0
  if (test_bss && !wpas_valid_bss(wpa_s, test_bss))
2602
0
    return 0;
2603
2604
0
  return test_ssid == NULL || wpas_valid_ssid(wpa_s, test_ssid);
2605
0
}
2606
2607
2608
void wpas_connect_work_free(struct wpa_connect_work *cwork)
2609
0
{
2610
0
  if (cwork == NULL)
2611
0
    return;
2612
0
  os_free(cwork);
2613
0
}
2614
2615
2616
void wpas_connect_work_done(struct wpa_supplicant *wpa_s)
2617
0
{
2618
0
  struct wpa_connect_work *cwork;
2619
0
  struct wpa_radio_work *work = wpa_s->connect_work;
2620
2621
0
  if (!work)
2622
0
    return;
2623
2624
0
  wpa_s->connect_work = NULL;
2625
0
  cwork = work->ctx;
2626
0
  work->ctx = NULL;
2627
0
  wpas_connect_work_free(cwork);
2628
0
  radio_work_done(work);
2629
0
}
2630
2631
2632
int wpas_update_random_addr(struct wpa_supplicant *wpa_s,
2633
          enum wpas_mac_addr_style style,
2634
          struct wpa_ssid *ssid)
2635
0
{
2636
0
  struct os_reltime now;
2637
0
  u8 addr[ETH_ALEN];
2638
2639
0
  os_get_reltime(&now);
2640
  /* Random addresses are valid within a given ESS so check
2641
   * expiration/value only when continuing to use the same ESS. */
2642
0
  if (wpa_s->last_mac_addr_style == style && wpa_s->reassoc_same_ess) {
2643
0
    if (style == WPAS_MAC_ADDR_STYLE_DEDICATED_PER_ESS) {
2644
      /* Pregenerated addresses do not expire but their value
2645
       * might have changed, so let's check that. */
2646
0
      if (ssid &&
2647
0
          ether_addr_equal(wpa_s->own_addr, ssid->mac_value))
2648
0
        return 0;
2649
0
    } else if ((wpa_s->last_mac_addr_change.sec != 0 ||
2650
0
          wpa_s->last_mac_addr_change.usec != 0) &&
2651
0
         !os_reltime_expired(
2652
0
           &now,
2653
0
           &wpa_s->last_mac_addr_change,
2654
0
           wpa_s->conf->rand_addr_lifetime)) {
2655
0
      wpa_msg(wpa_s, MSG_DEBUG,
2656
0
        "Previously selected random MAC address has not yet expired");
2657
0
      return 0;
2658
0
    }
2659
0
  }
2660
2661
0
  switch (style) {
2662
0
  case WPAS_MAC_ADDR_STYLE_RANDOM:
2663
0
    if (random_mac_addr(addr) < 0)
2664
0
      return -1;
2665
0
    break;
2666
0
  case WPAS_MAC_ADDR_STYLE_RANDOM_SAME_OUI:
2667
0
    os_memcpy(addr, wpa_s->perm_addr, ETH_ALEN);
2668
0
    if (random_mac_addr_keep_oui(addr) < 0)
2669
0
      return -1;
2670
0
    break;
2671
0
  case WPAS_MAC_ADDR_STYLE_DEDICATED_PER_ESS:
2672
0
    if (!ssid) {
2673
0
      wpa_msg(wpa_s, MSG_INFO,
2674
0
        "Invalid 'ssid' for address policy 3");
2675
0
      return -1;
2676
0
    }
2677
0
    os_memcpy(addr, ssid->mac_value, ETH_ALEN);
2678
0
    break;
2679
0
  default:
2680
0
    return -1;
2681
0
  }
2682
2683
0
  if (wpa_drv_set_mac_addr(wpa_s, addr) < 0) {
2684
0
    wpa_msg(wpa_s, MSG_INFO,
2685
0
      "Failed to set random MAC address");
2686
0
    return -1;
2687
0
  }
2688
2689
0
  os_get_reltime(&wpa_s->last_mac_addr_change);
2690
0
  wpa_s->mac_addr_changed = 1;
2691
0
  wpa_s->last_mac_addr_style = style;
2692
2693
0
  if (wpa_supplicant_update_mac_addr(wpa_s) < 0) {
2694
0
    wpa_msg(wpa_s, MSG_INFO,
2695
0
      "Could not update MAC address information");
2696
0
    return -1;
2697
0
  }
2698
2699
0
  wpas_p2p_update_dev_addr(wpa_s);
2700
0
  wpas_pr_update_dev_addr(wpa_s);
2701
2702
0
  wpa_msg(wpa_s, MSG_DEBUG, "Using random MAC address " MACSTR,
2703
0
    MAC2STR(addr));
2704
2705
0
  return 1;
2706
0
}
2707
2708
2709
int wpas_update_random_addr_disassoc(struct wpa_supplicant *wpa_s)
2710
0
{
2711
0
  if (wpa_s->wpa_state >= WPA_AUTHENTICATING ||
2712
0
      !wpa_s->conf->preassoc_mac_addr)
2713
0
    return 0;
2714
2715
0
  return wpas_update_random_addr(wpa_s, wpa_s->conf->preassoc_mac_addr,
2716
0
               NULL);
2717
0
}
2718
2719
2720
void wpa_s_setup_sae_pt(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
2721
      bool force)
2722
0
{
2723
#ifdef CONFIG_SAE
2724
  struct wpa_config *conf = wpa_s->conf;
2725
  int *groups = conf->sae_groups;
2726
  int default_groups[] = { 19, 20, 21, 0 };
2727
  const char *password;
2728
  enum sae_pwe sae_pwe;
2729
  const u8 *password_id = (const u8 *) ssid->sae_password_id;
2730
  size_t password_id_len = ssid->sae_password_id ?
2731
    os_strlen(ssid->sae_password_id) : 0;
2732
  struct wpabuf_array *ids;
2733
2734
  if (!groups || groups[0] <= 0)
2735
    groups = default_groups;
2736
2737
  password = ssid->sae_password;
2738
  if (!password)
2739
    password = ssid->passphrase;
2740
2741
  sae_pwe = wpas_get_ssid_sae_pwe(wpa_s, ssid);
2742
2743
  if (!password ||
2744
      !wpa_key_mgmt_sae(ssid->key_mgmt) ||
2745
      (sae_pwe == SAE_PWE_HUNT_AND_PECK && !ssid->sae_password_id &&
2746
       !wpa_key_mgmt_sae_ext_key(ssid->key_mgmt) &&
2747
       !force &&
2748
       !sae_pk_valid_password(password)) ||
2749
      sae_pwe == SAE_PWE_FORCE_HUNT_AND_PECK) {
2750
    /* PT derivation not needed */
2751
    sae_deinit_pt(ssid->pt);
2752
    ssid->pt = NULL;
2753
    return;
2754
  }
2755
2756
  ids = ssid->alt_sae_password_ids;
2757
  if (ids && ids->num) {
2758
    unsigned int idx = os_random() % ids->num;
2759
    struct wpabuf *id = ids->buf[idx];
2760
2761
    password_id = wpabuf_head(id);
2762
    password_id_len = wpabuf_len(id);
2763
    wpa_hexdump(MSG_DEBUG,
2764
          "SAE: Prepare PT for alternative password ID",
2765
          password_id, password_id_len);
2766
    ssid->alt_sae_passwords_ids_idx = idx;
2767
    ssid->alt_sae_passwords_ids_used = true;
2768
  }
2769
2770
  if (ssid->pt) {
2771
    if (!password_id && !ssid->pt->password_id)
2772
      return; /* PT already derived for no PW ID */
2773
    if (password_id && ssid->pt->password_id &&
2774
        password_id_len == wpabuf_len(ssid->pt->password_id) &&
2775
        os_memcmp(password_id, wpabuf_head(ssid->pt->password_id),
2776
            password_id_len) == 0)
2777
      return; /* PT already derived for same PW ID */
2778
2779
    /* PT was derived for another password identifier */
2780
    sae_deinit_pt(ssid->pt);
2781
    ssid->pt = NULL;
2782
  }
2783
  ssid->pt = sae_derive_pt(groups, ssid->ssid, ssid->ssid_len,
2784
         (const u8 *) password, os_strlen(password),
2785
         password_id, password_id_len);
2786
#endif /* CONFIG_SAE */
2787
0
}
2788
2789
2790
void wpa_s_clear_sae_rejected(struct wpa_supplicant *wpa_s)
2791
0
{
2792
#if defined(CONFIG_SAE) && defined(CONFIG_SME)
2793
  os_free(wpa_s->sme.sae_rejected_groups);
2794
  wpa_s->sme.sae_rejected_groups = NULL;
2795
#ifdef CONFIG_TESTING_OPTIONS
2796
  if (wpa_s->extra_sae_rejected_groups) {
2797
    int i, *groups = wpa_s->extra_sae_rejected_groups;
2798
2799
    for (i = 0; groups[i]; i++) {
2800
      wpa_printf(MSG_DEBUG,
2801
           "TESTING: Indicate rejection of an extra SAE group %d",
2802
           groups[i]);
2803
      int_array_add_unique(&wpa_s->sme.sae_rejected_groups,
2804
               groups[i]);
2805
    }
2806
  }
2807
#endif /* CONFIG_TESTING_OPTIONS */
2808
#endif /* CONFIG_SAE && CONFIG_SME */
2809
0
}
2810
2811
2812
int wpas_restore_permanent_mac_addr(struct wpa_supplicant *wpa_s)
2813
0
{
2814
0
  if (wpa_drv_set_mac_addr(wpa_s, NULL) < 0) {
2815
0
    wpa_msg(wpa_s, MSG_INFO,
2816
0
      "Could not restore permanent MAC address");
2817
0
    return -1;
2818
0
  }
2819
0
  wpa_s->mac_addr_changed = 0;
2820
0
  if (wpa_supplicant_update_mac_addr(wpa_s) < 0) {
2821
0
    wpa_msg(wpa_s, MSG_INFO,
2822
0
      "Could not update MAC address information");
2823
0
    return -1;
2824
0
  }
2825
2826
0
  wpas_p2p_update_dev_addr(wpa_s);
2827
2828
0
  wpa_msg(wpa_s, MSG_DEBUG, "Using permanent MAC address");
2829
0
  return 0;
2830
0
}
2831
2832
2833
static void wpas_start_assoc_cb(struct wpa_radio_work *work, int deinit);
2834
2835
/**
2836
 * wpa_supplicant_associate - Request association
2837
 * @wpa_s: Pointer to wpa_supplicant data
2838
 * @bss: Scan results for the selected BSS, or %NULL if not available
2839
 * @ssid: Configuration data for the selected network
2840
 *
2841
 * This function is used to request %wpa_supplicant to associate with a BSS.
2842
 */
2843
void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
2844
            struct wpa_bss *bss, struct wpa_ssid *ssid)
2845
0
{
2846
0
  bool clear_rejected = true;
2847
0
  struct wpa_connect_work *cwork;
2848
0
  enum wpas_mac_addr_style rand_style;
2849
2850
0
  wpa_s->own_disconnect_req = 0;
2851
0
  wpa_s->own_reconnect_req = 0;
2852
2853
  /*
2854
   * If we are starting a new connection, any previously pending EAPOL
2855
   * RX cannot be valid anymore.
2856
   */
2857
0
  wpabuf_free(wpa_s->pending_eapol_rx);
2858
0
  wpa_s->pending_eapol_rx = NULL;
2859
2860
0
  if (ssid->mac_addr == WPAS_MAC_ADDR_STYLE_NOT_SET)
2861
0
    rand_style = wpa_s->conf->mac_addr;
2862
0
  else
2863
0
    rand_style = ssid->mac_addr;
2864
2865
0
  wpa_s->eapol_failed = 0;
2866
0
  wpa_s->multi_ap_ie = 0;
2867
0
#ifndef CONFIG_NO_WMM_AC
2868
0
  wmm_ac_clear_saved_tspecs(wpa_s);
2869
0
#endif /* CONFIG_NO_WMM_AC */
2870
0
#ifdef CONFIG_WNM
2871
0
  wpa_s->wnm_mode = 0;
2872
0
  wpa_s->wnm_target_bss = NULL;
2873
0
#endif /* CONFIG_WNM */
2874
0
  wpa_s->reassoc_same_bss = 0;
2875
0
  wpa_s->reassoc_same_ess = 0;
2876
#ifdef CONFIG_TESTING_OPTIONS
2877
  wpa_s->testing_resend_assoc = 0;
2878
#endif /* CONFIG_TESTING_OPTIONS */
2879
2880
0
  if (wpa_s->last_ssid == ssid) {
2881
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Re-association to the same ESS");
2882
0
    wpa_s->reassoc_same_ess = 1;
2883
0
    if (wpa_s->current_bss && wpa_s->current_bss == bss) {
2884
0
#ifndef CONFIG_NO_WMM_AC
2885
0
      wmm_ac_save_tspecs(wpa_s);
2886
0
#endif /* CONFIG_NO_WMM_AC */
2887
0
      wpa_s->reassoc_same_bss = 1;
2888
0
      clear_rejected = false;
2889
0
    } else if (wpa_s->current_bss && wpa_s->current_bss != bss) {
2890
0
      os_get_reltime(&wpa_s->roam_start);
2891
0
    }
2892
0
  }
2893
2894
0
  if (clear_rejected)
2895
0
    wpa_s_clear_sae_rejected(wpa_s);
2896
2897
#ifdef CONFIG_SAE
2898
  wpa_s_setup_sae_pt(wpa_s, ssid, false);
2899
#endif /* CONFIG_SAE */
2900
2901
0
  if (rand_style > WPAS_MAC_ADDR_STYLE_PERMANENT) {
2902
0
    int status = wpas_update_random_addr(wpa_s, rand_style, ssid);
2903
2904
0
    if (status < 0)
2905
0
      return;
2906
0
    if (rand_style != WPAS_MAC_ADDR_STYLE_DEDICATED_PER_ESS &&
2907
0
        status > 0) /* MAC changed */
2908
0
      wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2909
0
  } else if (rand_style == WPAS_MAC_ADDR_STYLE_PERMANENT &&
2910
0
       wpa_s->mac_addr_changed) {
2911
0
    if (wpas_restore_permanent_mac_addr(wpa_s) < 0)
2912
0
      return;
2913
0
  }
2914
0
  wpa_s->last_ssid = ssid;
2915
2916
#ifdef CONFIG_IBSS_RSN
2917
  ibss_rsn_deinit(wpa_s->ibss_rsn);
2918
  wpa_s->ibss_rsn = NULL;
2919
#else /* CONFIG_IBSS_RSN */
2920
0
  if (ssid->mode == WPAS_MODE_IBSS &&
2921
0
      !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
2922
0
    wpa_msg(wpa_s, MSG_INFO,
2923
0
      "IBSS RSN not supported in the build");
2924
0
    return;
2925
0
  }
2926
0
#endif /* CONFIG_IBSS_RSN */
2927
2928
0
  if (ssid->mode == WPAS_MODE_AP || ssid->mode == WPAS_MODE_P2P_GO ||
2929
0
      ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
2930
#ifdef CONFIG_AP
2931
    if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP)) {
2932
      wpa_msg(wpa_s, MSG_INFO, "Driver does not support AP "
2933
        "mode");
2934
      return;
2935
    }
2936
    if (wpa_supplicant_create_ap(wpa_s, ssid) < 0) {
2937
      wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2938
      if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
2939
        wpas_p2p_ap_setup_failed(wpa_s);
2940
      return;
2941
    }
2942
    wpa_s->current_bss = bss;
2943
#else /* CONFIG_AP */
2944
0
    wpa_msg(wpa_s, MSG_ERROR, "AP mode support not included in "
2945
0
      "the build");
2946
0
#endif /* CONFIG_AP */
2947
0
    return;
2948
0
  }
2949
2950
0
  if (ssid->mode == WPAS_MODE_MESH) {
2951
#ifdef CONFIG_MESH
2952
    if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_MESH)) {
2953
      wpa_msg(wpa_s, MSG_INFO,
2954
        "Driver does not support mesh mode");
2955
      return;
2956
    }
2957
    if (bss)
2958
      ssid->frequency = bss->freq;
2959
    if (wpa_supplicant_join_mesh(wpa_s, ssid) < 0) {
2960
      wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
2961
      wpa_msg(wpa_s, MSG_ERROR, "Could not join mesh");
2962
      return;
2963
    }
2964
    wpa_s->current_bss = bss;
2965
#else /* CONFIG_MESH */
2966
0
    wpa_msg(wpa_s, MSG_ERROR,
2967
0
      "mesh mode support not included in the build");
2968
0
#endif /* CONFIG_MESH */
2969
0
    return;
2970
0
  }
2971
2972
  /*
2973
   * Set WPA state machine configuration to match the selected network now
2974
   * so that the information is available before wpas_start_assoc_cb()
2975
   * gets called. This is needed at least for RSN pre-authentication where
2976
   * candidate APs are added to a list based on scan result processing
2977
   * before completion of the first association.
2978
   */
2979
0
  wpa_supplicant_rsn_supp_set_config(wpa_s, ssid);
2980
2981
#ifdef CONFIG_DPP
2982
  if (wpas_dpp_check_connect(wpa_s, ssid, bss) != 0)
2983
    return;
2984
#endif /* CONFIG_DPP */
2985
2986
#ifdef CONFIG_TDLS
2987
  if (bss)
2988
    wpa_tdls_ap_ies(wpa_s->wpa, wpa_bss_ie_ptr(bss), bss->ie_len);
2989
#endif /* CONFIG_TDLS */
2990
2991
#ifdef CONFIG_MBO
2992
  wpas_mbo_check_pmf(wpa_s, bss, ssid);
2993
#endif /* CONFIG_MBO */
2994
2995
0
  if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2996
0
      ssid->mode == WPAS_MODE_INFRA) {
2997
0
    sme_authenticate(wpa_s, bss, ssid);
2998
0
    return;
2999
0
  }
3000
3001
0
  if (wpa_s->connect_work) {
3002
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Reject wpa_supplicant_associate() call since connect_work exist");
3003
0
    return;
3004
0
  }
3005
3006
0
  if (radio_work_pending(wpa_s, "connect")) {
3007
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Reject wpa_supplicant_associate() call since pending work exist");
3008
0
    return;
3009
0
  }
3010
3011
#ifdef CONFIG_SME
3012
  if (ssid->mode == WPAS_MODE_IBSS || ssid->mode == WPAS_MODE_MESH) {
3013
    /* Clear possibly set auth_alg, if any, from last attempt. */
3014
    wpa_s->sme.auth_alg = WPA_AUTH_ALG_OPEN;
3015
  }
3016
#endif /* CONFIG_SME */
3017
3018
0
  wpas_abort_ongoing_scan(wpa_s);
3019
3020
0
  cwork = os_zalloc(sizeof(*cwork));
3021
0
  if (cwork == NULL)
3022
0
    return;
3023
3024
0
  cwork->bss = bss;
3025
0
  cwork->ssid = ssid;
3026
3027
0
  if (!radio_add_work(wpa_s, bss ? bss->freq : 0, "connect", 1,
3028
0
          wpas_start_assoc_cb, cwork)) {
3029
0
    os_free(cwork);
3030
0
  }
3031
0
}
3032
3033
3034
static int bss_is_ibss(struct wpa_bss *bss)
3035
0
{
3036
0
  return (bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
3037
0
    IEEE80211_CAP_IBSS;
3038
0
}
3039
3040
3041
static int drv_supports_vht(struct wpa_supplicant *wpa_s,
3042
          const struct wpa_ssid *ssid)
3043
0
{
3044
0
  enum hostapd_hw_mode hw_mode;
3045
0
  struct hostapd_hw_modes *mode = NULL;
3046
0
  u8 channel;
3047
0
  int i;
3048
3049
0
  hw_mode = ieee80211_freq_to_chan(ssid->frequency, &channel);
3050
0
  if (hw_mode == NUM_HOSTAPD_MODES)
3051
0
    return 0;
3052
0
  for (i = 0; wpa_s->hw.modes && i < wpa_s->hw.num_modes; i++) {
3053
0
    if (wpa_s->hw.modes[i].mode == hw_mode) {
3054
0
      mode = &wpa_s->hw.modes[i];
3055
0
      break;
3056
0
    }
3057
0
  }
3058
3059
0
  if (!mode)
3060
0
    return 0;
3061
3062
0
  return mode->vht_capab != 0;
3063
0
}
3064
3065
3066
static bool ibss_mesh_is_80mhz_avail(int channel, struct hostapd_hw_modes *mode)
3067
0
{
3068
0
  int i;
3069
3070
0
  for (i = channel; i < channel + 16; i += 4) {
3071
0
    struct hostapd_channel_data *chan;
3072
3073
0
    chan = hw_get_channel_chan(mode, i, NULL);
3074
0
    if (!chan ||
3075
0
        chan->flag & (HOSTAPD_CHAN_DISABLED | HOSTAPD_CHAN_NO_IR))
3076
0
      return false;
3077
0
  }
3078
3079
0
  return true;
3080
0
}
3081
3082
3083
static struct wpa_bss * ibss_find_existing_bss(struct wpa_supplicant *wpa_s,
3084
                 const struct wpa_ssid *ssid)
3085
0
{
3086
0
  unsigned int j;
3087
3088
0
  for (j = 0; j < wpa_s->last_scan_res_used; j++) {
3089
0
    struct wpa_bss *bss = wpa_s->last_scan_res[j];
3090
3091
0
    if (!bss_is_ibss(bss))
3092
0
      continue;
3093
3094
0
    if (ssid->ssid_len == bss->ssid_len &&
3095
0
        os_memcmp(ssid->ssid, bss->ssid, bss->ssid_len) == 0)
3096
0
      return bss;
3097
0
  }
3098
0
  return NULL;
3099
0
}
3100
3101
3102
static bool ibss_mesh_can_use_ht(struct wpa_supplicant *wpa_s,
3103
         const struct wpa_ssid *ssid,
3104
         struct hostapd_hw_modes *mode)
3105
0
{
3106
  /* For IBSS check HT_IBSS flag */
3107
0
  if (ssid->mode == WPAS_MODE_IBSS &&
3108
0
      !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_HT_IBSS))
3109
0
    return false;
3110
3111
0
  if (wpa_s->group_cipher == WPA_CIPHER_WEP40 ||
3112
0
      wpa_s->group_cipher == WPA_CIPHER_WEP104 ||
3113
0
      wpa_s->pairwise_cipher == WPA_CIPHER_TKIP) {
3114
0
    wpa_printf(MSG_DEBUG,
3115
0
         "IBSS: WEP/TKIP detected, do not try to enable HT");
3116
0
    return false;
3117
0
  }
3118
3119
0
  if (!ht_supported(mode))
3120
0
    return false;
3121
3122
#ifdef CONFIG_HT_OVERRIDES
3123
  if (ssid->disable_ht)
3124
    return false;
3125
#endif /* CONFIG_HT_OVERRIDES */
3126
3127
0
  return true;
3128
0
}
3129
3130
3131
static bool ibss_mesh_can_use_vht(struct wpa_supplicant *wpa_s,
3132
          const struct wpa_ssid *ssid,
3133
          struct hostapd_hw_modes *mode)
3134
0
{
3135
0
  if (mode->mode != HOSTAPD_MODE_IEEE80211A)
3136
0
    return false;
3137
3138
0
  if (!drv_supports_vht(wpa_s, ssid))
3139
0
    return false;
3140
3141
  /* For IBSS check VHT_IBSS flag */
3142
0
  if (ssid->mode == WPAS_MODE_IBSS &&
3143
0
      !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_VHT_IBSS))
3144
0
    return false;
3145
3146
0
  if (!vht_supported(mode))
3147
0
    return false;
3148
3149
#ifdef CONFIG_VHT_OVERRIDES
3150
  if (ssid->disable_vht)
3151
    return false;
3152
#endif /* CONFIG_VHT_OVERRIDES */
3153
3154
0
  return true;
3155
0
}
3156
3157
3158
static bool ibss_mesh_can_use_he(struct wpa_supplicant *wpa_s,
3159
         const struct wpa_ssid *ssid,
3160
         const struct hostapd_hw_modes *mode,
3161
         int ieee80211_mode)
3162
0
{
3163
#ifdef CONFIG_HE_OVERRIDES
3164
  if (ssid->disable_he)
3165
    return false;
3166
#endif /* CONFIG_HE_OVERRIDES */
3167
3168
0
  switch (mode->mode) {
3169
0
  case HOSTAPD_MODE_IEEE80211G:
3170
0
  case HOSTAPD_MODE_IEEE80211B:
3171
0
  case HOSTAPD_MODE_IEEE80211A:
3172
0
    return mode->he_capab[ieee80211_mode].he_supported;
3173
0
  default:
3174
0
    return false;
3175
0
  }
3176
0
}
3177
3178
3179
static bool ibss_mesh_can_use_eht(struct wpa_supplicant *wpa_s,
3180
          const struct wpa_ssid *ssid,
3181
          const struct hostapd_hw_modes *mode,
3182
          int ieee80211_mode)
3183
0
{
3184
0
  if (ssid->disable_eht)
3185
0
    return false;
3186
3187
0
  switch(mode->mode) {
3188
0
  case HOSTAPD_MODE_IEEE80211G:
3189
0
  case HOSTAPD_MODE_IEEE80211B:
3190
0
  case HOSTAPD_MODE_IEEE80211A:
3191
0
    return mode->eht_capab[ieee80211_mode].eht_supported;
3192
0
  default:
3193
0
    return false;
3194
0
  }
3195
0
}
3196
3197
3198
static void ibss_mesh_select_40mhz(struct wpa_supplicant *wpa_s,
3199
           const struct wpa_ssid *ssid,
3200
           struct hostapd_hw_modes *mode,
3201
           struct hostapd_freq_params *freq,
3202
           int obss_scan, bool is_6ghz)
3203
0
{
3204
0
  int chan_idx;
3205
0
  struct hostapd_channel_data *pri_chan = NULL, *sec_chan = NULL;
3206
0
  int i, res;
3207
0
  unsigned int j;
3208
0
  static const int ht40plus_5ghz[] = {
3209
0
    36, 44, 52, 60, 100, 108, 116, 124, 132, 140,
3210
0
    149, 157, 165, 173, 184, 192
3211
0
  };
3212
0
  static const int ht40plus_6ghz[] = {
3213
0
    1, 9, 17, 25, 33, 41, 49, 57, 65, 73,
3214
0
    81, 89, 97, 105, 113, 121, 129, 137, 145, 153,
3215
0
    161, 169, 177, 185, 193, 201, 209, 217, 225
3216
0
  };
3217
3218
0
  int ht40 = -1;
3219
3220
0
  if (!freq->ht_enabled && !is_6ghz)
3221
0
    return;
3222
3223
0
  for (chan_idx = 0; chan_idx < mode->num_channels; chan_idx++) {
3224
0
    pri_chan = &mode->channels[chan_idx];
3225
0
    if (pri_chan->chan == freq->channel)
3226
0
      break;
3227
0
    pri_chan = NULL;
3228
0
  }
3229
0
  if (!pri_chan)
3230
0
    return;
3231
3232
  /* Check primary channel flags */
3233
0
  if (pri_chan->flag & (HOSTAPD_CHAN_DISABLED | HOSTAPD_CHAN_NO_IR))
3234
0
    return;
3235
3236
#ifdef CONFIG_HT_OVERRIDES
3237
  if (ssid->disable_ht40)
3238
    return;
3239
#endif
3240
3241
  /* Check/setup HT40+/HT40- */
3242
0
  if (is_6ghz) {
3243
0
    for (j = 0; j < ARRAY_SIZE(ht40plus_6ghz); j++) {
3244
0
      if (ht40plus_6ghz[j] == freq->channel) {
3245
0
        ht40 = 1;
3246
0
        break;
3247
0
      }
3248
0
    }
3249
0
  } else {
3250
0
    for (j = 0; j < ARRAY_SIZE(ht40plus_5ghz); j++) {
3251
0
      if (ht40plus_5ghz[j] == freq->channel) {
3252
0
        ht40 = 1;
3253
0
        break;
3254
0
      }
3255
0
    }
3256
0
  }
3257
3258
  /* Find secondary channel */
3259
0
  for (i = 0; i < mode->num_channels; i++) {
3260
0
    sec_chan = &mode->channels[i];
3261
0
    if (sec_chan->chan == freq->channel + ht40 * 4)
3262
0
      break;
3263
0
    sec_chan = NULL;
3264
0
  }
3265
0
  if (!sec_chan)
3266
0
    return;
3267
3268
  /* Check secondary channel flags */
3269
0
  if (sec_chan->flag & (HOSTAPD_CHAN_DISABLED | HOSTAPD_CHAN_NO_IR))
3270
0
    return;
3271
3272
0
  if (freq->ht_enabled) {
3273
0
    if (ht40 == -1) {
3274
0
      if (!(pri_chan->flag & HOSTAPD_CHAN_HT40MINUS))
3275
0
        return;
3276
0
    } else {
3277
0
      if (!(pri_chan->flag & HOSTAPD_CHAN_HT40PLUS))
3278
0
        return;
3279
0
    }
3280
0
  }
3281
0
  freq->sec_channel_offset = ht40;
3282
3283
0
  if (obss_scan) {
3284
0
    struct wpa_scan_results *scan_res;
3285
3286
0
    scan_res = wpa_supplicant_get_scan_results(wpa_s, NULL, 0,
3287
0
                 NULL);
3288
0
    if (scan_res == NULL) {
3289
      /* Back to HT20 */
3290
0
      freq->sec_channel_offset = 0;
3291
0
      return;
3292
0
    }
3293
3294
0
    res = check_40mhz_5g(scan_res, pri_chan, sec_chan);
3295
0
    switch (res) {
3296
0
    case 0:
3297
      /* Back to HT20 */
3298
0
      freq->sec_channel_offset = 0;
3299
0
      break;
3300
0
    case 1:
3301
      /* Configuration allowed */
3302
0
      break;
3303
0
    case 2:
3304
      /* Switch pri/sec channels */
3305
0
      freq->freq = hw_get_freq(mode, sec_chan->chan);
3306
0
      freq->sec_channel_offset = -freq->sec_channel_offset;
3307
0
      freq->channel = sec_chan->chan;
3308
0
      break;
3309
0
    default:
3310
0
      freq->sec_channel_offset = 0;
3311
0
      break;
3312
0
    }
3313
3314
0
    wpa_scan_results_free(scan_res);
3315
0
  }
3316
3317
0
  wpa_printf(MSG_DEBUG,
3318
0
       "IBSS/mesh: setup freq channel %d, sec_channel_offset %d",
3319
0
       freq->channel, freq->sec_channel_offset);
3320
0
}
3321
3322
3323
static int ibss_get_center_320mhz(int channel)
3324
0
{
3325
0
  int seg0;
3326
3327
0
  if (channel >= 1 && channel <= 45)
3328
0
    seg0 = 31;
3329
0
  else if (channel >= 49 && channel <= 77)
3330
0
    seg0 = 63;
3331
0
  else if (channel >= 81 && channel <= 109)
3332
0
    seg0 = 95;
3333
0
  else if (channel >= 113 && channel <= 141)
3334
0
    seg0 = 127;
3335
0
  else if (channel >= 145 && channel <= 173)
3336
0
    seg0 = 159;
3337
0
  else
3338
0
    seg0 = 191;
3339
3340
0
  return seg0;
3341
0
}
3342
3343
3344
static bool ibss_mesh_select_80_160mhz(struct wpa_supplicant *wpa_s,
3345
               const struct wpa_ssid *ssid,
3346
               struct hostapd_hw_modes *mode,
3347
               struct hostapd_freq_params *freq,
3348
0
               int ieee80211_mode, bool is_6ghz) {
3349
0
  static const int bw80[] = {
3350
0
    5180, 5260, 5500, 5580, 5660, 5745, 5825,
3351
0
    5955, 6035, 6115, 6195, 6275, 6355, 6435,
3352
0
    6515, 6595, 6675, 6755, 6835, 6915, 6995
3353
0
  };
3354
0
  static const int bw160[] = {
3355
0
    5180, 5500, 5745, 5955, 6115, 6275, 6435,
3356
0
    6595, 6755, 6915
3357
0
  };
3358
0
  static const int bw320[]= {
3359
0
    5955, 6255, 6115, 6415, 6275, 6575, 6435,
3360
0
    6735, 6595, 6895, 6755, 7055
3361
0
  };
3362
3363
0
  struct hostapd_freq_params vht_freq;
3364
0
  struct hostapd_channel_info info;
3365
0
  int i;
3366
0
  unsigned int j, k;
3367
0
  int chwidth, seg0, seg1;
3368
0
  int offset_in_160 = 1;
3369
0
  int offset_in_320 = 0;
3370
0
  u32 vht_caps = 0;
3371
0
  u8 channel = freq->channel;
3372
3373
0
  if (!freq->vht_enabled && !freq->he_enabled)
3374
0
    return true;
3375
3376
0
  vht_freq = *freq;
3377
3378
0
  chwidth = CONF_OPER_CHWIDTH_USE_HT;
3379
0
  seg0 = freq->channel + 2 * freq->sec_channel_offset;
3380
0
  seg1 = 0;
3381
0
  if (freq->sec_channel_offset == 0) {
3382
0
    seg0 = 0;
3383
    /* Don't try 80 MHz if 40 MHz failed, except in 6 GHz */
3384
0
    if (freq->ht_enabled && !is_6ghz)
3385
0
      goto skip_80mhz;
3386
0
  }
3387
0
  if (ssid->max_oper_chwidth == CONF_OPER_CHWIDTH_USE_HT)
3388
0
    goto skip_80mhz;
3389
3390
  /* setup center_freq1, bandwidth */
3391
0
  for (j = 0; j < ARRAY_SIZE(bw80); j++) {
3392
0
    if (freq->freq >= bw80[j] &&
3393
0
        freq->freq < bw80[j] + 80)
3394
0
      break;
3395
0
  }
3396
3397
0
  if (j == ARRAY_SIZE(bw80) ||
3398
0
      ieee80211_freq_to_chan(bw80[j], &channel) == NUM_HOSTAPD_MODES)
3399
0
    goto skip_80mhz;
3400
3401
  /* Use 40 MHz if channel not usable */
3402
0
  if (!ibss_mesh_is_80mhz_avail(channel, mode))
3403
0
    goto skip_80mhz;
3404
3405
0
  chwidth = CONF_OPER_CHWIDTH_80MHZ;
3406
0
  seg0 = channel + 6;
3407
0
  seg1 = 0;
3408
3409
0
  for (k = 0; k < ARRAY_SIZE(bw160); k++) {
3410
0
    if (bw80[j] >= bw160[k] &&
3411
0
        bw80[j] < bw160[k] + 160) {
3412
0
      if (bw80[j] == bw160[k])
3413
0
        offset_in_160 = 1;
3414
0
      else
3415
0
        offset_in_160 = -1;
3416
0
      break;
3417
0
    }
3418
0
  }
3419
3420
0
  for (k = 0; k < ARRAY_SIZE(bw320); k++) {
3421
0
    if (bw80[j] >= bw320[k] &&
3422
0
        bw80[j] < bw320[k] + 320) {
3423
0
      if (bw80[j] == bw320[k])
3424
0
        offset_in_320 = 0;
3425
0
      else if (bw80[j] == bw320[k] + 80)
3426
0
        offset_in_320 = 1;
3427
0
      else if (bw80[j] == bw320[k] + 160)
3428
0
        offset_in_320 = 2;
3429
0
      else
3430
0
        offset_in_320 = 3;
3431
0
      break;
3432
0
    }
3433
0
  }
3434
3435
  /* In 160 MHz, the initial four 20 MHz channels were validated
3436
   * above. If 160 MHz is supported, check the remaining four 20 MHz
3437
   * channels for the total of 160 MHz bandwidth.
3438
   */
3439
0
  if ((mode->he_capab[ieee80211_mode].phy_cap[
3440
0
         HE_PHYCAP_CHANNEL_WIDTH_SET_IDX] &
3441
0
       HE_PHYCAP_CHANNEL_WIDTH_SET_160MHZ_IN_5G) &&
3442
0
      (ssid->max_oper_chwidth == CONF_OPER_CHWIDTH_160MHZ ||
3443
0
       ssid->max_oper_chwidth == CONF_OPER_CHWIDTH_320MHZ) &&
3444
0
      ibss_mesh_is_80mhz_avail(channel + 16 * offset_in_160, mode)) {
3445
0
    for (j = 0; j < ARRAY_SIZE(bw160); j++) {
3446
0
      u8 start_chan;
3447
3448
0
      if (freq->freq >= bw160[j] &&
3449
0
          freq->freq < bw160[j] + 160) {
3450
0
        chwidth = CONF_OPER_CHWIDTH_160MHZ;
3451
0
        ieee80211_freq_to_chan(bw160[j], &start_chan);
3452
0
        seg0 = start_chan + 14;
3453
0
        break;
3454
0
      }
3455
0
    }
3456
0
  }
3457
3458
  /* In 320 MHz, the initial four 20 MHz channels were validated
3459
   * above. If 320 MHz is supported, check the remaining 12 20 MHz
3460
   * channels for the total of 320 MHz bandwidth for 6 GHz.
3461
   */
3462
0
  if ((mode->eht_capab[ieee80211_mode].phy_cap[
3463
0
         EHT_PHYCAP_320MHZ_IN_6GHZ_SUPPORT_IDX] &
3464
0
       EHT_PHYCAP_320MHZ_IN_6GHZ_SUPPORT_MASK) && is_6ghz &&
3465
0
      ssid->max_oper_chwidth == CONF_OPER_CHWIDTH_320MHZ &&
3466
0
      ibss_mesh_is_80mhz_avail(channel + 16 -
3467
0
             64 * ((offset_in_320 + 1) / 4), mode) &&
3468
0
      ibss_mesh_is_80mhz_avail(channel + 32 -
3469
0
             64 * ((offset_in_320 + 2) / 4), mode) &&
3470
0
      ibss_mesh_is_80mhz_avail(channel + 48 -
3471
0
             64 * ((offset_in_320 + 3) / 4), mode)) {
3472
0
    for (j = 0; j < ARRAY_SIZE(bw320); j += 2) {
3473
0
      if (freq->freq >= bw320[j] &&
3474
0
          freq->freq <= bw320[j + 1]) {
3475
0
        chwidth = CONF_OPER_CHWIDTH_320MHZ;
3476
0
        seg0 = ibss_get_center_320mhz(freq->channel);
3477
0
        break;
3478
0
      }
3479
0
    }
3480
0
  }
3481
3482
0
  if (ssid->max_oper_chwidth == CONF_OPER_CHWIDTH_80P80MHZ) {
3483
    /* setup center_freq2, bandwidth */
3484
0
    for (k = 0; k < ARRAY_SIZE(bw80); k++) {
3485
      /* Only accept 80 MHz segments separated by a gap */
3486
0
      if (j == k || abs(bw80[j] - bw80[k]) == 80)
3487
0
        continue;
3488
3489
0
      if (ieee80211_freq_to_chan(bw80[k], &channel) ==
3490
0
          NUM_HOSTAPD_MODES)
3491
0
        break;
3492
3493
0
      for (i = channel; i < channel + 16; i += 4) {
3494
0
        struct hostapd_channel_data *chan;
3495
3496
0
        chan = hw_get_channel_chan(mode, i, NULL);
3497
0
        if (!chan)
3498
0
          continue;
3499
3500
0
        if (chan->flag & (HOSTAPD_CHAN_DISABLED |
3501
0
              HOSTAPD_CHAN_NO_IR |
3502
0
              HOSTAPD_CHAN_RADAR))
3503
0
          continue;
3504
3505
        /* Found a suitable second segment for 80+80 */
3506
0
        chwidth = CONF_OPER_CHWIDTH_80P80MHZ;
3507
0
        if (!is_6ghz)
3508
0
          vht_caps |=
3509
0
            VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
3510
0
        seg1 = channel + 6;
3511
0
      }
3512
3513
0
      if (chwidth == CONF_OPER_CHWIDTH_80P80MHZ)
3514
0
        break;
3515
0
    }
3516
0
  } else if (ssid->max_oper_chwidth == CONF_OPER_CHWIDTH_160MHZ) {
3517
0
    if (freq->freq == 5180) {
3518
0
      chwidth = CONF_OPER_CHWIDTH_160MHZ;
3519
0
      vht_caps |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
3520
0
      seg0 = 50;
3521
0
    } else if (freq->freq == 5520) {
3522
0
      chwidth = CONF_OPER_CHWIDTH_160MHZ;
3523
0
      vht_caps |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
3524
0
      seg0 = 114;
3525
0
    }
3526
0
  }
3527
3528
0
skip_80mhz:
3529
0
  info = (struct hostapd_channel_info) {
3530
0
    .mode = mode->mode,
3531
0
    .freq = freq->freq,
3532
0
    .channel = freq->channel,
3533
0
    .edmg.enabled = ssid->enable_edmg,
3534
0
    .edmg.channel = ssid->edmg_channel,
3535
0
    .ht.enabled = freq->ht_enabled,
3536
0
    .vht.enabled = freq->vht_enabled,
3537
0
    .he.enabled = freq->he_enabled,
3538
0
    .eht.enabled = freq->eht_enabled,
3539
0
    .ht.sec_channel_offset = freq->sec_channel_offset,
3540
0
    .oper_chwidth = chwidth,
3541
0
    .center_segment0 = seg0,
3542
0
    .center_segment1 = seg1,
3543
0
    .vht.caps = vht_caps,
3544
0
    .he.cap = &mode->he_capab[ieee80211_mode],
3545
0
    .eht.cap = &mode->eht_capab[ieee80211_mode],
3546
0
  };
3547
0
  if (hostapd_set_freq_params(&vht_freq, &info))
3548
0
    return false;
3549
3550
0
  *freq = vht_freq;
3551
3552
0
  wpa_printf(MSG_DEBUG, "IBSS: VHT setup freq cf1 %d, cf2 %d, bw %d",
3553
0
       freq->center_freq1, freq->center_freq2, freq->bandwidth);
3554
0
  return true;
3555
0
}
3556
3557
3558
void ibss_mesh_setup_freq(struct wpa_supplicant *wpa_s,
3559
        const struct wpa_ssid *ssid,
3560
        struct hostapd_freq_params *freq)
3561
0
{
3562
0
  int ieee80211_mode = wpas_mode_to_ieee80211_mode(ssid->mode);
3563
0
  enum hostapd_hw_mode hw_mode;
3564
0
  struct hostapd_hw_modes *mode = NULL;
3565
0
  int obss_scan = 1;
3566
0
  u8 channel;
3567
0
  bool is_6ghz, is_24ghz;
3568
3569
0
  freq->freq = ssid->frequency;
3570
3571
0
  if (ssid->mode == WPAS_MODE_IBSS && !ssid->fixed_freq) {
3572
0
    struct wpa_bss *bss = ibss_find_existing_bss(wpa_s, ssid);
3573
3574
0
    if (bss) {
3575
0
      wpa_printf(MSG_DEBUG,
3576
0
           "IBSS already found in scan results, adjust control freq: %d",
3577
0
           bss->freq);
3578
0
      freq->freq = bss->freq;
3579
0
      obss_scan = 0;
3580
0
    }
3581
0
  }
3582
3583
0
  hw_mode = ieee80211_freq_to_chan(freq->freq, &channel);
3584
0
  mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes,
3585
0
      hw_mode, is_6ghz_freq(ssid->frequency));
3586
3587
0
  if (!mode)
3588
0
    return;
3589
3590
0
  is_24ghz = hw_mode == HOSTAPD_MODE_IEEE80211G ||
3591
0
    hw_mode == HOSTAPD_MODE_IEEE80211B;
3592
3593
0
  is_6ghz = is_6ghz_freq(freq->freq);
3594
3595
0
  freq->ht_enabled = 0;
3596
0
  freq->vht_enabled = 0;
3597
0
  freq->he_enabled = 0;
3598
0
  freq->eht_enabled = 0;
3599
3600
0
  if (!is_6ghz)
3601
0
    freq->ht_enabled = ibss_mesh_can_use_ht(wpa_s, ssid, mode);
3602
0
  if (freq->ht_enabled)
3603
0
    freq->vht_enabled = ibss_mesh_can_use_vht(wpa_s, ssid, mode);
3604
0
  if (freq->vht_enabled || (freq->ht_enabled && is_24ghz) || is_6ghz)
3605
0
    freq->he_enabled = ibss_mesh_can_use_he(wpa_s, ssid, mode,
3606
0
              ieee80211_mode);
3607
0
  freq->channel = channel;
3608
  /* Setup higher BW only for 5 and 6 GHz */
3609
0
  if (mode->mode == HOSTAPD_MODE_IEEE80211A) {
3610
0
    ibss_mesh_select_40mhz(wpa_s, ssid, mode, freq, obss_scan,
3611
0
               is_6ghz);
3612
0
    if (!ibss_mesh_select_80_160mhz(wpa_s, ssid, mode, freq,
3613
0
            ieee80211_mode, is_6ghz))
3614
0
      freq->he_enabled = freq->vht_enabled = false;
3615
0
  }
3616
3617
0
  if (freq->he_enabled)
3618
0
    freq->eht_enabled = ibss_mesh_can_use_eht(wpa_s, ssid, mode,
3619
0
                ieee80211_mode);
3620
0
}
3621
3622
3623
#ifdef CONFIG_FILS
3624
static size_t wpas_add_fils_hlp_req(struct wpa_supplicant *wpa_s, u8 *ie_buf,
3625
            size_t ie_buf_len)
3626
{
3627
  struct fils_hlp_req *req;
3628
  size_t rem_len, hdr_len, hlp_len, len, ie_len = 0;
3629
  const u8 *pos;
3630
  u8 *buf = ie_buf;
3631
3632
  dl_list_for_each(req, &wpa_s->fils_hlp_req, struct fils_hlp_req,
3633
       list) {
3634
    rem_len = ie_buf_len - ie_len;
3635
    pos = wpabuf_head(req->pkt);
3636
    hdr_len = 1 + 2 * ETH_ALEN + 6;
3637
    hlp_len = wpabuf_len(req->pkt);
3638
3639
    if (rem_len < 2 + hdr_len + hlp_len) {
3640
      wpa_printf(MSG_ERROR,
3641
           "FILS: Cannot fit HLP - rem_len=%lu to_fill=%lu",
3642
           (unsigned long) rem_len,
3643
           (unsigned long) (2 + hdr_len + hlp_len));
3644
      break;
3645
    }
3646
3647
    len = (hdr_len + hlp_len) > 255 ? 255 : hdr_len + hlp_len;
3648
    /* Element ID */
3649
    *buf++ = WLAN_EID_EXTENSION;
3650
    /* Length */
3651
    *buf++ = len;
3652
    /* Element ID Extension */
3653
    *buf++ = WLAN_EID_EXT_FILS_HLP_CONTAINER;
3654
    /* Destination MAC address */
3655
    os_memcpy(buf, req->dst, ETH_ALEN);
3656
    buf += ETH_ALEN;
3657
    /* Source MAC address */
3658
    os_memcpy(buf, wpa_s->own_addr, ETH_ALEN);
3659
    buf += ETH_ALEN;
3660
    /* LLC/SNAP Header */
3661
    os_memcpy(buf, "\xaa\xaa\x03\x00\x00\x00", 6);
3662
    buf += 6;
3663
    /* HLP Packet */
3664
    os_memcpy(buf, pos, len - hdr_len);
3665
    buf += len - hdr_len;
3666
    pos += len - hdr_len;
3667
3668
    hlp_len -= len - hdr_len;
3669
    ie_len += 2 + len;
3670
    rem_len -= 2 + len;
3671
3672
    while (hlp_len) {
3673
      len = (hlp_len > 255) ? 255 : hlp_len;
3674
      if (rem_len < 2 + len)
3675
        break;
3676
      *buf++ = WLAN_EID_FRAGMENT;
3677
      *buf++ = len;
3678
      os_memcpy(buf, pos, len);
3679
      buf += len;
3680
      pos += len;
3681
3682
      hlp_len -= len;
3683
      ie_len += 2 + len;
3684
      rem_len -= 2 + len;
3685
    }
3686
  }
3687
3688
  return ie_len;
3689
}
3690
3691
3692
int wpa_is_fils_supported(struct wpa_supplicant *wpa_s)
3693
{
3694
  return (((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3695
     (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SUPPORT_FILS)) ||
3696
    (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3697
     (wpa_s->drv_flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD)));
3698
}
3699
3700
3701
int wpa_is_fils_sk_pfs_supported(struct wpa_supplicant *wpa_s)
3702
{
3703
#ifdef CONFIG_FILS_SK_PFS
3704
  return (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3705
    (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SUPPORT_FILS);
3706
#else /* CONFIG_FILS_SK_PFS */
3707
  return 0;
3708
#endif /* CONFIG_FILS_SK_PFS */
3709
}
3710
3711
#endif /* CONFIG_FILS */
3712
3713
3714
bool wpa_is_non_eht_scs_traffic_desc_supported(struct wpa_bss *bss)
3715
0
{
3716
0
  const u8 *wfa_capa;
3717
3718
0
  if (!bss)
3719
0
    return false;
3720
3721
  /* Get WFA capability from Beacon or Probe Response frame elements */
3722
0
  wfa_capa = wpa_bss_get_vendor_ie(bss, WFA_CAPA_IE_VENDOR_TYPE);
3723
0
  if (!wfa_capa)
3724
0
    wfa_capa = wpa_bss_get_vendor_ie_beacon(
3725
0
      bss, WFA_CAPA_IE_VENDOR_TYPE);
3726
3727
0
  if (!wfa_capa || wfa_capa[1] < 6 || wfa_capa[6] < 1 ||
3728
0
      !(wfa_capa[7] & WFA_CAPA_QM_NON_EHT_SCS_TRAFFIC_DESC)) {
3729
    /* AP does not enable QM non EHT traffic description policy */
3730
0
    return false;
3731
0
  }
3732
3733
0
  return true;
3734
0
}
3735
3736
3737
int wpas_populate_wfa_capa(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3738
         u8 *wpa_ie, size_t wpa_ie_len, size_t max_wpa_ie_len)
3739
0
{
3740
0
  struct wpabuf *wfa_ie = NULL, *attr = NULL;
3741
0
  u8 wfa_capa[1];
3742
0
  u8 capab_len = 0;
3743
0
  size_t wfa_ie_len, buf_len;
3744
3745
0
  os_memset(wfa_capa, 0, sizeof(wfa_capa));
3746
0
#ifndef CONFIG_NO_ROBUST_AV
3747
0
  if (wpa_s->enable_dscp_policy_capa)
3748
0
    wfa_capa[0] |= WFA_CAPA_QM_DSCP_POLICY;
3749
0
#endif /* CONFIG_NO_ROBUST_AV */
3750
3751
0
  if (wpa_is_non_eht_scs_traffic_desc_supported(bss))
3752
0
    wfa_capa[0] |= WFA_CAPA_QM_NON_EHT_SCS_TRAFFIC_DESC;
3753
3754
0
  if (wfa_capa[0])
3755
0
    capab_len = 1;
3756
3757
0
  if (wpa_s->conf->wfa_gen_capa == WFA_GEN_CAPA_UNPROTECTED)
3758
0
    attr = wpas_wfa_gen_capab_attr(wpa_s);
3759
3760
0
  if (capab_len == 0 && !attr)
3761
0
    return wpa_ie_len;
3762
3763
  /* Wi-Fi Alliance element */
3764
0
  buf_len = 1 + /* Element ID */
3765
0
      1 + /* Length */
3766
0
      3 + /* OUI */
3767
0
      1 + /* OUI Type */
3768
0
      1 + /* Capabilities Length */
3769
0
      capab_len + /* Capabilities */
3770
0
      (attr ? wpabuf_len(attr) : 0) /* Attributes */;
3771
0
  wfa_ie = wpabuf_alloc(buf_len);
3772
0
  if (!wfa_ie) {
3773
0
    wpabuf_free(attr);
3774
0
    return wpa_ie_len;
3775
0
  }
3776
3777
0
  wpabuf_put_u8(wfa_ie, WLAN_EID_VENDOR_SPECIFIC);
3778
0
  wpabuf_put_u8(wfa_ie, buf_len - 2);
3779
0
  wpabuf_put_be24(wfa_ie, OUI_WFA);
3780
0
  wpabuf_put_u8(wfa_ie, WFA_CAPA_OUI_TYPE);
3781
0
  wpabuf_put_u8(wfa_ie, capab_len);
3782
0
  wpabuf_put_data(wfa_ie, wfa_capa, capab_len);
3783
0
  if (attr)
3784
0
    wpabuf_put_buf(wfa_ie, attr);
3785
0
  wpabuf_free(attr);
3786
3787
0
  wfa_ie_len = wpabuf_len(wfa_ie);
3788
0
  if (wpa_ie_len + wfa_ie_len <= max_wpa_ie_len) {
3789
0
    wpa_hexdump_buf(MSG_MSGDUMP, "WFA Capabilities element",
3790
0
        wfa_ie);
3791
0
    os_memcpy(wpa_ie + wpa_ie_len, wpabuf_head(wfa_ie),
3792
0
        wfa_ie_len);
3793
0
    wpa_ie_len += wfa_ie_len;
3794
0
  }
3795
3796
0
  wpabuf_free(wfa_ie);
3797
0
  return wpa_ie_len;
3798
0
}
3799
3800
3801
static u8 * wpas_populate_assoc_ies(
3802
  struct wpa_supplicant *wpa_s,
3803
  struct wpa_bss *bss, struct wpa_ssid *ssid,
3804
  struct wpa_driver_associate_params *params,
3805
  enum wpa_drv_update_connect_params_mask *mask)
3806
0
{
3807
0
  u8 *wpa_ie;
3808
0
  size_t max_wpa_ie_len = 500;
3809
0
  size_t wpa_ie_len;
3810
0
  int algs = WPA_AUTH_ALG_OPEN;
3811
#ifdef CONFIG_MBO
3812
  const u8 *mbo_ie;
3813
#endif
3814
#if defined(CONFIG_SAE) || defined(CONFIG_FILS)
3815
  int pmksa_cached = 0;
3816
#endif /* CONFIG_SAE || CONFIG_FILS */
3817
#ifdef CONFIG_FILS
3818
  const u8 *realm, *username, *rrk;
3819
  size_t realm_len, username_len, rrk_len;
3820
  u16 next_seq_num;
3821
  struct fils_hlp_req *req;
3822
3823
  dl_list_for_each(req, &wpa_s->fils_hlp_req, struct fils_hlp_req,
3824
       list) {
3825
    max_wpa_ie_len += 3 + 2 * ETH_ALEN + 6 + wpabuf_len(req->pkt) +
3826
          2 + 2 * wpabuf_len(req->pkt) / 255;
3827
  }
3828
#endif /* CONFIG_FILS */
3829
3830
0
  wpa_ie = os_malloc(max_wpa_ie_len);
3831
0
  if (!wpa_ie) {
3832
0
    wpa_printf(MSG_ERROR,
3833
0
         "Failed to allocate connect IE buffer for %lu bytes",
3834
0
         (unsigned long) max_wpa_ie_len);
3835
0
    return NULL;
3836
0
  }
3837
3838
0
  if (bss && (wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE) ||
3839
0
        wpa_bss_get_rsne(wpa_s, bss, ssid, false)) &&
3840
0
      wpa_key_mgmt_wpa(ssid->key_mgmt)) {
3841
0
    int try_opportunistic;
3842
0
    const u8 *cache_id = NULL;
3843
0
    const u8 *addr = bss->bssid;
3844
3845
0
    if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3846
0
        (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_MLO) &&
3847
0
        !is_zero_ether_addr(bss->mld_addr))
3848
0
      addr = bss->mld_addr;
3849
3850
0
    if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3851
0
        wpa_s->valid_links)
3852
0
      addr = wpa_s->ap_mld_addr;
3853
3854
0
    try_opportunistic = (ssid->proactive_key_caching < 0 ?
3855
0
             wpa_s->conf->okc :
3856
0
             ssid->proactive_key_caching) &&
3857
0
      (ssid->proto & WPA_PROTO_RSN);
3858
#ifdef CONFIG_FILS
3859
    if (wpa_key_mgmt_fils(ssid->key_mgmt))
3860
      cache_id = wpa_bss_get_fils_cache_id(bss);
3861
#endif /* CONFIG_FILS */
3862
0
    if (pmksa_cache_set_current(wpa_s->wpa, NULL, addr,
3863
0
              ssid, try_opportunistic,
3864
0
              cache_id, 0, false) == 0) {
3865
0
      eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
3866
#if defined(CONFIG_SAE) || defined(CONFIG_FILS)
3867
      pmksa_cached = 1;
3868
#endif /* CONFIG_SAE || CONFIG_FILS */
3869
0
    }
3870
0
    wpa_ie_len = max_wpa_ie_len;
3871
0
    if (wpa_supplicant_set_suites(wpa_s, bss, ssid,
3872
0
                wpa_ie, &wpa_ie_len, false)) {
3873
0
      wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to set WPA "
3874
0
        "key management and encryption suites");
3875
0
      os_free(wpa_ie);
3876
0
      return NULL;
3877
0
    }
3878
0
  } else if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && bss &&
3879
0
       wpa_key_mgmt_wpa_ieee8021x(ssid->key_mgmt)) {
3880
    /*
3881
     * Both WPA and non-WPA IEEE 802.1X enabled in configuration -
3882
     * use non-WPA since the scan results did not indicate that the
3883
     * AP is using WPA or WPA2.
3884
     */
3885
0
    wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
3886
0
    wpa_ie_len = 0;
3887
0
    wpa_s->wpa_proto = 0;
3888
0
  } else if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
3889
0
    wpa_ie_len = max_wpa_ie_len;
3890
0
    if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
3891
0
                wpa_ie, &wpa_ie_len, false)) {
3892
0
      wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to set WPA "
3893
0
        "key management and encryption suites (no "
3894
0
        "scan results)");
3895
0
      os_free(wpa_ie);
3896
0
      return NULL;
3897
0
    }
3898
#ifdef CONFIG_WPS
3899
  } else if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
3900
    struct wpabuf *wps_ie;
3901
    wps_ie = wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid));
3902
    if (wps_ie && wpabuf_len(wps_ie) <= max_wpa_ie_len) {
3903
      wpa_ie_len = wpabuf_len(wps_ie);
3904
      os_memcpy(wpa_ie, wpabuf_head(wps_ie), wpa_ie_len);
3905
    } else
3906
      wpa_ie_len = 0;
3907
    wpabuf_free(wps_ie);
3908
    wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
3909
    if (!bss || (bss->caps & IEEE80211_CAP_PRIVACY))
3910
      params->wps = WPS_MODE_PRIVACY;
3911
    else
3912
      params->wps = WPS_MODE_OPEN;
3913
    wpa_s->wpa_proto = 0;
3914
#endif /* CONFIG_WPS */
3915
0
  } else {
3916
0
    wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
3917
0
    wpa_ie_len = 0;
3918
0
    wpa_s->wpa_proto = 0;
3919
0
  }
3920
3921
0
#ifdef IEEE8021X_EAPOL
3922
0
  if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
3923
0
    if (ssid->leap) {
3924
0
      if (ssid->non_leap == 0)
3925
0
        algs = WPA_AUTH_ALG_LEAP;
3926
0
      else
3927
0
        algs |= WPA_AUTH_ALG_LEAP;
3928
0
    }
3929
0
  }
3930
3931
#ifdef CONFIG_FILS
3932
  /* Clear FILS association */
3933
  wpa_sm_set_reset_fils_completed(wpa_s->wpa, 0);
3934
3935
  if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD) &&
3936
      ssid->eap.erp && wpa_key_mgmt_fils(wpa_s->key_mgmt) &&
3937
      eapol_sm_get_erp_info(wpa_s->eapol, &ssid->eap, &username,
3938
          &username_len, &realm, &realm_len,
3939
          &next_seq_num, &rrk, &rrk_len) == 0 &&
3940
      (!wpa_s->last_con_fail_realm ||
3941
       wpa_s->last_con_fail_realm_len != realm_len ||
3942
       os_memcmp(wpa_s->last_con_fail_realm, realm, realm_len) != 0)) {
3943
    algs = WPA_AUTH_ALG_FILS;
3944
    params->fils_erp_username = username;
3945
    params->fils_erp_username_len = username_len;
3946
    params->fils_erp_realm = realm;
3947
    params->fils_erp_realm_len = realm_len;
3948
    params->fils_erp_next_seq_num = next_seq_num;
3949
    params->fils_erp_rrk = rrk;
3950
    params->fils_erp_rrk_len = rrk_len;
3951
3952
    if (mask)
3953
      *mask |= WPA_DRV_UPDATE_FILS_ERP_INFO;
3954
  } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD) &&
3955
       ssid->eap.erp && wpa_key_mgmt_fils(wpa_s->key_mgmt) &&
3956
       pmksa_cached) {
3957
    algs = WPA_AUTH_ALG_FILS;
3958
  }
3959
#endif /* CONFIG_FILS */
3960
0
#endif /* IEEE8021X_EAPOL */
3961
#ifdef CONFIG_SAE
3962
  if (wpa_key_mgmt_sae(wpa_s->key_mgmt))
3963
    algs = WPA_AUTH_ALG_SAE;
3964
#endif /* CONFIG_SAE */
3965
3966
#ifdef CONFIG_IEEE8021X_AUTH
3967
  if (ssid->eap_over_auth_frame &&
3968
      (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_802_1X_AUTH) &&
3969
      wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt &
3970
               ~WPA_KEY_MGMT_IEEE8021X)) {
3971
    wpa_dbg(wpa_s, MSG_DEBUG,
3972
      "IEEE 802.1X Authentication using Authentication frames");
3973
    algs = WPA_AUTH_ALG_802_1X;
3974
  }
3975
#endif /* CONFIG_IEEE8021X_AUTH */
3976
3977
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Automatic auth_alg selection: 0x%x", algs);
3978
0
  if (ssid->auth_alg) {
3979
0
    algs = ssid->auth_alg;
3980
0
    wpa_dbg(wpa_s, MSG_DEBUG,
3981
0
      "Overriding auth_alg selection: 0x%x", algs);
3982
0
  }
3983
3984
#ifdef CONFIG_SAE
3985
  if (pmksa_cached && algs == WPA_AUTH_ALG_SAE) {
3986
    wpa_dbg(wpa_s, MSG_DEBUG,
3987
      "SAE: Use WPA_AUTH_ALG_OPEN for PMKSA caching attempt");
3988
    algs = WPA_AUTH_ALG_OPEN;
3989
  }
3990
#endif /* CONFIG_SAE */
3991
3992
#ifdef CONFIG_P2P
3993
  if (wpa_s->global->p2p) {
3994
    u8 *pos;
3995
    size_t len;
3996
    int res;
3997
    pos = wpa_ie + wpa_ie_len;
3998
    len = max_wpa_ie_len - wpa_ie_len;
3999
    res = wpas_p2p_assoc_req_ie(wpa_s, bss, pos, len,
4000
              ssid->p2p_group);
4001
    if (res >= 0)
4002
      wpa_ie_len += res;
4003
  }
4004
4005
  wpa_s->cross_connect_disallowed = 0;
4006
  if (bss) {
4007
    struct wpabuf *p2p;
4008
    p2p = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
4009
    if (p2p) {
4010
      wpa_s->cross_connect_disallowed =
4011
        p2p_get_cross_connect_disallowed(p2p);
4012
      wpabuf_free(p2p);
4013
      wpa_dbg(wpa_s, MSG_DEBUG, "P2P: WLAN AP %s cross "
4014
        "connection",
4015
        wpa_s->cross_connect_disallowed ?
4016
        "disallows" : "allows");
4017
    }
4018
  }
4019
4020
  os_memset(wpa_s->p2p_ip_addr_info, 0, sizeof(wpa_s->p2p_ip_addr_info));
4021
#endif /* CONFIG_P2P */
4022
4023
0
#ifndef CONFIG_NO_RRM
4024
0
  if (bss) {
4025
0
    wpa_ie_len += wpas_supp_op_class_ie(wpa_s, ssid, bss,
4026
0
                wpa_ie + wpa_ie_len,
4027
0
                max_wpa_ie_len -
4028
0
                wpa_ie_len);
4029
0
  }
4030
0
#endif /* CONFIG_NO_RRM */
4031
4032
  /*
4033
   * Workaround: Add Extended Capabilities element only if the AP
4034
   * included this element in Beacon/Probe Response frames. Some older
4035
   * APs seem to have interoperability issues if this element is
4036
   * included, so while the standard may require us to include the
4037
   * element in all cases, it is justifiable to skip it to avoid
4038
   * interoperability issues.
4039
   */
4040
0
  if (ssid->p2p_group)
4041
0
    wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_CLIENT);
4042
0
  else
4043
0
    wpa_drv_get_ext_capa(wpa_s, WPA_IF_STATION);
4044
4045
0
  if (!bss || wpa_bss_get_ie(bss, WLAN_EID_EXT_CAPAB)) {
4046
0
    u8 ext_capab[18];
4047
0
    int ext_capab_len;
4048
0
    ext_capab_len = wpas_build_ext_capab(wpa_s, ext_capab,
4049
0
                 sizeof(ext_capab), bss);
4050
0
    if (ext_capab_len > 0 &&
4051
0
        wpa_ie_len + ext_capab_len <= max_wpa_ie_len) {
4052
0
      u8 *pos = wpa_ie;
4053
0
      if (wpa_ie_len > 0 && pos[0] == WLAN_EID_RSN)
4054
0
        pos += 2 + pos[1];
4055
0
      os_memmove(pos + ext_capab_len, pos,
4056
0
           wpa_ie_len - (pos - wpa_ie));
4057
0
      wpa_ie_len += ext_capab_len;
4058
0
      os_memcpy(pos, ext_capab, ext_capab_len);
4059
0
    }
4060
0
  }
4061
4062
0
  if (ssid->max_idle && wpa_ie_len + 5 <= max_wpa_ie_len) {
4063
0
    u8 *pos = wpa_ie;
4064
4065
0
    *pos++ = WLAN_EID_BSS_MAX_IDLE_PERIOD;
4066
0
    *pos++ = 3;
4067
0
    WPA_PUT_LE16(pos, ssid->max_idle);
4068
0
    pos += 2;
4069
0
    *pos = 0; /* Idle Options */
4070
0
    wpa_ie_len += 5;
4071
0
  }
4072
4073
0
#ifdef CONFIG_HS20
4074
0
  if (is_hs20_network(wpa_s, ssid, bss)) {
4075
0
    struct wpabuf *hs20;
4076
4077
0
    hs20 = wpabuf_alloc(20 + MAX_ROAMING_CONS_OI_LEN);
4078
0
    if (hs20) {
4079
0
      int pps_mo_id = hs20_get_pps_mo_id(wpa_s, ssid);
4080
0
      size_t len;
4081
4082
0
      wpas_hs20_add_indication(hs20, pps_mo_id,
4083
0
             get_hs20_version(bss));
4084
0
      wpas_hs20_add_roam_cons_sel(hs20, ssid);
4085
0
      len = max_wpa_ie_len - wpa_ie_len;
4086
0
      if (wpabuf_len(hs20) <= len) {
4087
0
        os_memcpy(wpa_ie + wpa_ie_len,
4088
0
            wpabuf_head(hs20), wpabuf_len(hs20));
4089
0
        wpa_ie_len += wpabuf_len(hs20);
4090
0
      }
4091
0
      wpabuf_free(hs20);
4092
0
    }
4093
0
  }
4094
0
#endif /* CONFIG_HS20 */
4095
4096
0
  wpas_configure_frame_filters(wpa_s);
4097
4098
0
  if (wpa_s->vendor_elem[VENDOR_ELEM_ASSOC_REQ]) {
4099
0
    struct wpabuf *buf = wpa_s->vendor_elem[VENDOR_ELEM_ASSOC_REQ];
4100
0
    size_t len;
4101
4102
0
    len = max_wpa_ie_len - wpa_ie_len;
4103
0
    if (wpabuf_len(buf) <= len) {
4104
0
      os_memcpy(wpa_ie + wpa_ie_len,
4105
0
          wpabuf_head(buf), wpabuf_len(buf));
4106
0
      wpa_ie_len += wpabuf_len(buf);
4107
0
    }
4108
0
  }
4109
4110
#ifdef CONFIG_FST
4111
  if (wpa_s->fst_ies) {
4112
    int fst_ies_len = wpabuf_len(wpa_s->fst_ies);
4113
4114
    if (wpa_ie_len + fst_ies_len <= max_wpa_ie_len) {
4115
      os_memcpy(wpa_ie + wpa_ie_len,
4116
          wpabuf_head(wpa_s->fst_ies), fst_ies_len);
4117
      wpa_ie_len += fst_ies_len;
4118
    }
4119
  }
4120
#endif /* CONFIG_FST */
4121
4122
#ifdef CONFIG_MBO
4123
  mbo_ie = bss ? wpa_bss_get_vendor_ie(bss, MBO_IE_VENDOR_TYPE) : NULL;
4124
  if (!wpa_s->disable_mbo_oce && mbo_ie) {
4125
    int len;
4126
4127
    len = wpas_mbo_ie(wpa_s, wpa_ie + wpa_ie_len,
4128
          max_wpa_ie_len - wpa_ie_len,
4129
          !!mbo_attr_from_mbo_ie(mbo_ie,
4130
               OCE_ATTR_ID_CAPA_IND));
4131
    if (len >= 0)
4132
      wpa_ie_len += len;
4133
  }
4134
#endif /* CONFIG_MBO */
4135
4136
#ifdef CONFIG_FILS
4137
  if (algs == WPA_AUTH_ALG_FILS) {
4138
    size_t len;
4139
4140
    len = wpas_add_fils_hlp_req(wpa_s, wpa_ie + wpa_ie_len,
4141
              max_wpa_ie_len - wpa_ie_len);
4142
    wpa_ie_len += len;
4143
  }
4144
#endif /* CONFIG_FILS */
4145
4146
#ifdef CONFIG_OWE
4147
#ifdef CONFIG_TESTING_OPTIONS
4148
  if (get_ie_ext(wpa_ie, wpa_ie_len, WLAN_EID_EXT_OWE_DH_PARAM)) {
4149
    wpa_printf(MSG_INFO, "TESTING: Override OWE DH element");
4150
  } else
4151
#endif /* CONFIG_TESTING_OPTIONS */
4152
  if (algs == WPA_AUTH_ALG_OPEN &&
4153
      ssid->key_mgmt == WPA_KEY_MGMT_OWE &&
4154
      !(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OWE_OFFLOAD_STA)) {
4155
    struct wpabuf *owe_ie;
4156
    u16 group;
4157
4158
    if (ssid->owe_group) {
4159
      group = ssid->owe_group;
4160
    } else if (wpa_s->assoc_status_code ==
4161
         WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) {
4162
      if (wpa_s->last_owe_group == 19)
4163
        group = 20;
4164
      else if (wpa_s->last_owe_group == 20)
4165
        group = 21;
4166
      else
4167
        group = OWE_DH_GROUP;
4168
    } else {
4169
      group = OWE_DH_GROUP;
4170
    }
4171
4172
    wpa_s->last_owe_group = group;
4173
    wpa_printf(MSG_DEBUG, "OWE: Try to use group %u", group);
4174
    owe_ie = owe_build_assoc_req(wpa_s->wpa, group);
4175
    if (owe_ie &&
4176
        wpabuf_len(owe_ie) <= max_wpa_ie_len - wpa_ie_len) {
4177
      os_memcpy(wpa_ie + wpa_ie_len,
4178
          wpabuf_head(owe_ie), wpabuf_len(owe_ie));
4179
      wpa_ie_len += wpabuf_len(owe_ie);
4180
    }
4181
    wpabuf_free(owe_ie);
4182
  }
4183
#endif /* CONFIG_OWE */
4184
4185
#ifdef CONFIG_DPP2
4186
  if (DPP_VERSION > 1 &&
4187
      wpa_sm_get_key_mgmt(wpa_s->wpa) == WPA_KEY_MGMT_DPP &&
4188
      ssid->dpp_netaccesskey &&
4189
      ssid->dpp_pfs != 2 && !ssid->dpp_pfs_fallback) {
4190
    struct rsn_pmksa_cache_entry *pmksa;
4191
4192
    pmksa = pmksa_cache_get_current(wpa_s->wpa);
4193
    if (!pmksa || !pmksa->dpp_pfs)
4194
      goto pfs_fail;
4195
4196
    dpp_pfs_free(wpa_s->dpp_pfs);
4197
    wpa_s->dpp_pfs = dpp_pfs_init(ssid->dpp_netaccesskey,
4198
                ssid->dpp_netaccesskey_len);
4199
    if (!wpa_s->dpp_pfs) {
4200
      wpa_printf(MSG_DEBUG, "DPP: Could not initialize PFS");
4201
      /* Try to continue without PFS */
4202
      goto pfs_fail;
4203
    }
4204
    if (wpabuf_len(wpa_s->dpp_pfs->ie) <=
4205
        max_wpa_ie_len - wpa_ie_len) {
4206
      os_memcpy(wpa_ie + wpa_ie_len,
4207
          wpabuf_head(wpa_s->dpp_pfs->ie),
4208
          wpabuf_len(wpa_s->dpp_pfs->ie));
4209
      wpa_ie_len += wpabuf_len(wpa_s->dpp_pfs->ie);
4210
    }
4211
  }
4212
pfs_fail:
4213
#endif /* CONFIG_DPP2 */
4214
4215
#ifdef CONFIG_IEEE80211R
4216
  /*
4217
   * Add MDIE under these conditions: the network profile allows FT,
4218
   * the AP supports FT, and the mobility domain ID matches.
4219
   */
4220
  if (bss && wpa_key_mgmt_ft(wpa_sm_get_key_mgmt(wpa_s->wpa))) {
4221
    const u8 *mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
4222
4223
    if (mdie && mdie[1] >= MOBILITY_DOMAIN_ID_LEN) {
4224
      size_t len = 0;
4225
      const u8 *md = mdie + 2;
4226
      const u8 *wpa_md = wpa_sm_get_ft_md(wpa_s->wpa);
4227
4228
      if (os_memcmp(md, wpa_md,
4229
              MOBILITY_DOMAIN_ID_LEN) == 0) {
4230
        /* Add mobility domain IE */
4231
        len = wpa_ft_add_mdie(
4232
          wpa_s->wpa, wpa_ie + wpa_ie_len,
4233
          max_wpa_ie_len - wpa_ie_len, mdie);
4234
        wpa_ie_len += len;
4235
      }
4236
#ifdef CONFIG_SME
4237
      if (len > 0 && wpa_s->sme.ft_used &&
4238
          wpa_sm_has_ft_keys(wpa_s->wpa, md)) {
4239
        wpa_dbg(wpa_s, MSG_DEBUG,
4240
          "SME: Trying to use FT over-the-air");
4241
        algs |= WPA_AUTH_ALG_FT;
4242
      }
4243
#endif /* CONFIG_SME */
4244
    }
4245
  }
4246
#endif /* CONFIG_IEEE80211R */
4247
4248
#ifdef CONFIG_TESTING_OPTIONS
4249
  if (wpa_s->rsnxe_override_assoc &&
4250
      wpabuf_len(wpa_s->rsnxe_override_assoc) <=
4251
      max_wpa_ie_len - wpa_ie_len) {
4252
    wpa_printf(MSG_DEBUG, "TESTING: RSNXE AssocReq override");
4253
    os_memcpy(wpa_ie + wpa_ie_len,
4254
        wpabuf_head(wpa_s->rsnxe_override_assoc),
4255
        wpabuf_len(wpa_s->rsnxe_override_assoc));
4256
    wpa_ie_len += wpabuf_len(wpa_s->rsnxe_override_assoc);
4257
  } else
4258
#endif /* CONFIG_TESTING_OPTIONS */
4259
0
  if (wpa_s->rsnxe_len > 0 &&
4260
0
      wpa_s->rsnxe_len <= max_wpa_ie_len - wpa_ie_len) {
4261
0
    os_memcpy(wpa_ie + wpa_ie_len, wpa_s->rsnxe, wpa_s->rsnxe_len);
4262
0
    wpa_ie_len += wpa_s->rsnxe_len;
4263
0
  }
4264
4265
0
#ifndef CONFIG_NO_ROBUST_AV
4266
#ifdef CONFIG_TESTING_OPTIONS
4267
  if (wpa_s->disable_mscs_support)
4268
    goto mscs_end;
4269
#endif /* CONFIG_TESTING_OPTIONS */
4270
0
  if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_MSCS) &&
4271
0
      wpa_s->robust_av.valid_config) {
4272
0
    struct wpabuf *mscs_ie;
4273
0
    size_t mscs_ie_len, buf_len;
4274
4275
0
    buf_len = 3 + /* MSCS descriptor IE header */
4276
0
        1 + /* Request type */
4277
0
        2 + /* User priority control */
4278
0
        4 + /* Stream timeout */
4279
0
        3 + /* TCLAS Mask IE header */
4280
0
        wpa_s->robust_av.frame_classifier_len;
4281
0
    mscs_ie = wpabuf_alloc(buf_len);
4282
0
    if (!mscs_ie) {
4283
0
      wpa_printf(MSG_INFO,
4284
0
           "MSCS: Failed to allocate MSCS IE");
4285
0
      goto mscs_end;
4286
0
    }
4287
4288
0
    wpas_populate_mscs_descriptor_ie(&wpa_s->robust_av, mscs_ie);
4289
0
    if ((wpa_ie_len + wpabuf_len(mscs_ie)) <= max_wpa_ie_len) {
4290
0
      wpa_hexdump_buf(MSG_MSGDUMP, "MSCS IE", mscs_ie);
4291
0
      mscs_ie_len = wpabuf_len(mscs_ie);
4292
0
      os_memcpy(wpa_ie + wpa_ie_len, wpabuf_head(mscs_ie),
4293
0
          mscs_ie_len);
4294
0
      wpa_ie_len += mscs_ie_len;
4295
0
    }
4296
4297
0
    wpabuf_free(mscs_ie);
4298
0
  }
4299
0
mscs_end:
4300
0
#endif /* CONFIG_NO_ROBUST_AV */
4301
4302
0
  wpa_ie_len = wpas_populate_wfa_capa(wpa_s, bss, wpa_ie, wpa_ie_len,
4303
0
              max_wpa_ie_len);
4304
4305
0
  if (ssid->multi_ap_backhaul_sta) {
4306
0
    size_t multi_ap_ie_len;
4307
0
    struct multi_ap_params multi_ap = { 0 };
4308
4309
0
    multi_ap.capability = MULTI_AP_BACKHAUL_STA;
4310
0
    multi_ap.profile = ssid->multi_ap_profile;
4311
4312
0
    multi_ap_ie_len = add_multi_ap_ie(wpa_ie + wpa_ie_len,
4313
0
              max_wpa_ie_len - wpa_ie_len,
4314
0
              &multi_ap);
4315
0
    if (multi_ap_ie_len == 0) {
4316
0
      wpa_printf(MSG_ERROR,
4317
0
           "Multi-AP: Failed to build Multi-AP IE");
4318
0
      os_free(wpa_ie);
4319
0
      return NULL;
4320
0
    }
4321
0
    wpa_ie_len += multi_ap_ie_len;
4322
0
  }
4323
4324
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_OVERRIDE_SUPPORT,
4325
0
       wpas_rsn_overriding(wpa_s, ssid));
4326
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_OVERRIDE,
4327
0
       RSN_OVERRIDE_NOT_USED);
4328
0
  if (wpas_rsn_overriding(wpa_s, ssid) &&
4329
0
      wpas_ap_supports_rsn_overriding(wpa_s, bss) &&
4330
0
      wpa_ie_len + 2 + 4 + 1 <= max_wpa_ie_len) {
4331
0
    u8 *pos = wpa_ie + wpa_ie_len, *start = pos;
4332
0
    const u8 *ie;
4333
0
    enum rsn_selection_variant variant = RSN_SELECTION_RSNE;
4334
4335
0
    wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_OVERRIDE,
4336
0
         RSN_OVERRIDE_RSNE);
4337
0
    ie = wpa_bss_get_rsne(wpa_s, bss, ssid, wpa_s->valid_links);
4338
0
    if (ie && ie[0] == WLAN_EID_VENDOR_SPECIFIC && ie[1] >= 4) {
4339
0
      u32 type;
4340
4341
0
      type = WPA_GET_BE32(&ie[2]);
4342
0
      if (type == RSNE_OVERRIDE_IE_VENDOR_TYPE) {
4343
0
        variant = RSN_SELECTION_RSNE_OVERRIDE;
4344
0
        wpa_sm_set_param(wpa_s->wpa,
4345
0
             WPA_PARAM_RSN_OVERRIDE,
4346
0
             RSN_OVERRIDE_RSNE_OVERRIDE);
4347
0
      } else if (type == RSNE_OVERRIDE_2_IE_VENDOR_TYPE) {
4348
0
        variant = RSN_SELECTION_RSNE_OVERRIDE_2;
4349
0
        wpa_sm_set_param(wpa_s->wpa,
4350
0
             WPA_PARAM_RSN_OVERRIDE,
4351
0
             RSN_OVERRIDE_RSNE_OVERRIDE_2);
4352
0
      }
4353
0
    }
4354
4355
    /* Indicate which RSNE variant was used */
4356
0
    *pos++ = WLAN_EID_VENDOR_SPECIFIC;
4357
0
    *pos++ = 4 + 1;
4358
0
    WPA_PUT_BE32(pos, RSN_SELECTION_IE_VENDOR_TYPE);
4359
0
    pos += 4;
4360
0
    *pos++ = variant;
4361
0
    wpa_hexdump(MSG_MSGDUMP, "RSN Selection", start, pos - start);
4362
0
    wpa_ie_len += pos - start;
4363
0
  }
4364
4365
0
  params->rsn_overriding = wpas_rsn_overriding(wpa_s, ssid);
4366
0
  params->wpa_ie = wpa_ie;
4367
0
  params->wpa_ie_len = wpa_ie_len;
4368
0
  params->auth_alg = algs;
4369
0
  if (mask)
4370
0
    *mask |= WPA_DRV_UPDATE_ASSOC_IES | WPA_DRV_UPDATE_AUTH_TYPE;
4371
4372
0
  return wpa_ie;
4373
0
}
4374
4375
4376
#ifdef CONFIG_OWE
4377
static void wpas_update_owe_connect_params(struct wpa_supplicant *wpa_s)
4378
{
4379
  struct wpa_driver_associate_params params;
4380
  u8 *wpa_ie;
4381
4382
  os_memset(&params, 0, sizeof(params));
4383
  wpa_ie = wpas_populate_assoc_ies(wpa_s, wpa_s->current_bss,
4384
           wpa_s->current_ssid, &params, NULL);
4385
  if (!wpa_ie)
4386
    return;
4387
4388
  wpa_drv_update_connect_params(wpa_s, &params, WPA_DRV_UPDATE_ASSOC_IES);
4389
  os_free(wpa_ie);
4390
}
4391
#endif /* CONFIG_OWE */
4392
4393
4394
#if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL)
4395
static void wpas_update_fils_connect_params(struct wpa_supplicant *wpa_s)
4396
{
4397
  struct wpa_driver_associate_params params;
4398
  enum wpa_drv_update_connect_params_mask mask = 0;
4399
  u8 *wpa_ie;
4400
4401
  if (wpa_s->auth_alg != WPA_AUTH_ALG_OPEN)
4402
    return; /* nothing to do */
4403
4404
  os_memset(&params, 0, sizeof(params));
4405
  wpa_ie = wpas_populate_assoc_ies(wpa_s, wpa_s->current_bss,
4406
           wpa_s->current_ssid, &params, &mask);
4407
  if (!wpa_ie)
4408
    return;
4409
4410
  if (params.auth_alg == WPA_AUTH_ALG_FILS) {
4411
    wpa_s->auth_alg = params.auth_alg;
4412
    wpa_drv_update_connect_params(wpa_s, &params, mask);
4413
  }
4414
4415
  os_free(wpa_ie);
4416
}
4417
#endif /* CONFIG_FILS && IEEE8021X_EAPOL */
4418
4419
4420
static u8 wpa_ie_get_edmg_oper_chans(const u8 *edmg_ie)
4421
0
{
4422
0
  if (!edmg_ie || edmg_ie[1] < 6)
4423
0
    return 0;
4424
0
  return edmg_ie[EDMG_BSS_OPERATING_CHANNELS_OFFSET];
4425
0
}
4426
4427
4428
static u8 wpa_ie_get_edmg_oper_chan_width(const u8 *edmg_ie)
4429
0
{
4430
0
  if (!edmg_ie || edmg_ie[1] < 6)
4431
0
    return 0;
4432
0
  return edmg_ie[EDMG_OPERATING_CHANNEL_WIDTH_OFFSET];
4433
0
}
4434
4435
4436
/* Returns the intersection of two EDMG configurations.
4437
 * Note: The current implementation is limited to CB2 only (CB1 included),
4438
 * i.e., the implementation supports up to 2 contiguous channels.
4439
 * For supporting non-contiguous (aggregated) channels and for supporting
4440
 * CB3 and above, this function will need to be extended.
4441
 */
4442
static struct ieee80211_edmg_config
4443
get_edmg_intersection(struct ieee80211_edmg_config a,
4444
          struct ieee80211_edmg_config b,
4445
          u8 primary_channel)
4446
0
{
4447
0
  struct ieee80211_edmg_config result;
4448
0
  int i, contiguous = 0;
4449
0
  int max_contiguous = 0;
4450
4451
0
  result.channels = b.channels & a.channels;
4452
0
  if (!result.channels) {
4453
0
    wpa_printf(MSG_DEBUG,
4454
0
         "EDMG not possible: cannot intersect channels 0x%x and 0x%x",
4455
0
         a.channels, b.channels);
4456
0
    goto fail;
4457
0
  }
4458
4459
0
  if (!(result.channels & BIT(primary_channel - 1))) {
4460
0
    wpa_printf(MSG_DEBUG,
4461
0
         "EDMG not possible: the primary channel %d is not one of the intersected channels 0x%x",
4462
0
         primary_channel, result.channels);
4463
0
    goto fail;
4464
0
  }
4465
4466
  /* Find max contiguous channels */
4467
0
  for (i = 0; i < 6; i++) {
4468
0
    if (result.channels & BIT(i))
4469
0
      contiguous++;
4470
0
    else
4471
0
      contiguous = 0;
4472
4473
0
    if (contiguous > max_contiguous)
4474
0
      max_contiguous = contiguous;
4475
0
  }
4476
4477
  /* Assuming AP and STA supports ONLY contiguous channels,
4478
   * bw configuration can have value between 4-7.
4479
   */
4480
0
  if ((b.bw_config < a.bw_config))
4481
0
    result.bw_config = b.bw_config;
4482
0
  else
4483
0
    result.bw_config = a.bw_config;
4484
4485
0
  if ((max_contiguous >= 2 && result.bw_config < EDMG_BW_CONFIG_5) ||
4486
0
      (max_contiguous >= 1 && result.bw_config < EDMG_BW_CONFIG_4)) {
4487
0
    wpa_printf(MSG_DEBUG,
4488
0
         "EDMG not possible: not enough contiguous channels %d for supporting CB1 or CB2",
4489
0
         max_contiguous);
4490
0
    goto fail;
4491
0
  }
4492
4493
0
  return result;
4494
4495
0
fail:
4496
0
  result.channels = 0;
4497
0
  result.bw_config = 0;
4498
0
  return result;
4499
0
}
4500
4501
4502
static struct ieee80211_edmg_config
4503
get_supported_edmg(struct wpa_supplicant *wpa_s,
4504
       struct hostapd_freq_params *freq,
4505
       struct ieee80211_edmg_config request_edmg)
4506
0
{
4507
0
  enum hostapd_hw_mode hw_mode;
4508
0
  struct hostapd_hw_modes *mode = NULL;
4509
0
  u8 primary_channel;
4510
4511
0
  if (!wpa_s->hw.modes)
4512
0
    goto fail;
4513
4514
0
  hw_mode = ieee80211_freq_to_chan(freq->freq, &primary_channel);
4515
0
  if (hw_mode == NUM_HOSTAPD_MODES)
4516
0
    goto fail;
4517
4518
0
  mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, hw_mode, false);
4519
0
  if (!mode)
4520
0
    goto fail;
4521
4522
0
  return get_edmg_intersection(mode->edmg, request_edmg, primary_channel);
4523
4524
0
fail:
4525
0
  request_edmg.channels = 0;
4526
0
  request_edmg.bw_config = 0;
4527
0
  return request_edmg;
4528
0
}
4529
4530
4531
#ifdef CONFIG_MBO
4532
void wpas_update_mbo_connect_params(struct wpa_supplicant *wpa_s)
4533
{
4534
  struct wpa_driver_associate_params params;
4535
  u8 *wpa_ie;
4536
4537
  /*
4538
   * Update MBO connect params only in case of change of MBO attributes
4539
   * when connected, if the AP support MBO.
4540
   */
4541
4542
  if (wpa_s->wpa_state != WPA_COMPLETED || !wpa_s->current_ssid ||
4543
      !wpa_s->current_bss ||
4544
      !wpa_bss_get_vendor_ie(wpa_s->current_bss, MBO_IE_VENDOR_TYPE))
4545
    return;
4546
4547
  os_memset(&params, 0, sizeof(params));
4548
  wpa_ie = wpas_populate_assoc_ies(wpa_s, wpa_s->current_bss,
4549
           wpa_s->current_ssid, &params, NULL);
4550
  if (!wpa_ie)
4551
    return;
4552
4553
  wpa_drv_update_connect_params(wpa_s, &params, WPA_DRV_UPDATE_ASSOC_IES);
4554
  os_free(wpa_ie);
4555
}
4556
#endif /* CONFIG_MBO */
4557
4558
4559
static void wpas_start_assoc_cb(struct wpa_radio_work *work, int deinit)
4560
0
{
4561
0
  struct wpa_connect_work *cwork = work->ctx;
4562
0
  struct wpa_bss *bss = cwork->bss;
4563
0
  struct wpa_ssid *ssid = cwork->ssid;
4564
0
  struct wpa_supplicant *wpa_s = work->wpa_s;
4565
0
  u8 *wpa_ie;
4566
0
  const u8 *edmg_ie_oper;
4567
0
  int use_crypt, ret, bssid_changed;
4568
0
  unsigned int cipher_pairwise, cipher_group, cipher_group_mgmt;
4569
0
  struct wpa_driver_associate_params params;
4570
0
  u8 psk[PMK_LEN];
4571
0
#if defined(CONFIG_WEP) || defined(IEEE8021X_EAPOL)
4572
0
  int wep_keys_set = 0;
4573
0
#endif /* CONFIG_WEP || IEEE8021X_EAPOL */
4574
0
  int assoc_failed = 0;
4575
0
  struct wpa_ssid *old_ssid;
4576
0
  u8 prev_bssid[ETH_ALEN];
4577
#ifdef CONFIG_HT_OVERRIDES
4578
  struct ieee80211_ht_capabilities htcaps;
4579
  struct ieee80211_ht_capabilities htcaps_mask;
4580
#endif /* CONFIG_HT_OVERRIDES */
4581
#ifdef CONFIG_VHT_OVERRIDES
4582
       struct ieee80211_vht_capabilities vhtcaps;
4583
       struct ieee80211_vht_capabilities vhtcaps_mask;
4584
#endif /* CONFIG_VHT_OVERRIDES */
4585
4586
0
  wpa_s->roam_in_progress = false;
4587
0
#ifdef CONFIG_WNM
4588
0
  wpa_s->bss_trans_mgmt_in_progress = false;
4589
0
#endif /* CONFIG_WNM */
4590
0
  wpa_s->no_suitable_network = 0;
4591
4592
0
  if (deinit) {
4593
0
    if (work->started) {
4594
0
      wpa_s->connect_work = NULL;
4595
4596
      /* cancel possible auth. timeout */
4597
0
      eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s,
4598
0
               NULL);
4599
0
    }
4600
0
    wpas_connect_work_free(cwork);
4601
0
    return;
4602
0
  }
4603
4604
0
  wpa_s->connect_work = work;
4605
4606
0
  if (cwork->bss_removed || !wpas_valid_bss_ssid(wpa_s, bss, ssid) ||
4607
0
      wpas_network_disabled(wpa_s, ssid)) {
4608
0
    wpa_dbg(wpa_s, MSG_DEBUG, "BSS/SSID entry for association not valid anymore - drop connection attempt");
4609
0
    wpas_connect_work_done(wpa_s);
4610
0
    return;
4611
0
  }
4612
4613
  /*
4614
   * Set the current AP's BSSID (for non-MLO connection) or MLD address
4615
   * (for MLO connection) as the previous BSSID for reassociation requests
4616
   * handled by SME-in-driver. If wpa_supplicant is in disconnected state,
4617
   * prev_bssid will be zero as both wpa_s->valid_links and wpa_s->bssid
4618
   * will be zero.
4619
   */
4620
0
  os_memcpy(prev_bssid,
4621
0
      wpa_s->valid_links ? wpa_s->ap_mld_addr : wpa_s->bssid,
4622
0
      ETH_ALEN);
4623
0
  os_memset(&params, 0, sizeof(params));
4624
0
  wpa_s->reassociate = 0;
4625
0
  wpa_s->eap_expected_failure = 0;
4626
4627
  /* Starting new association, so clear the possibly used WPA IE from the
4628
   * previous association. */
4629
0
  wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
4630
0
#ifndef CONFIG_NO_WPA
4631
0
  wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
4632
0
#endif /* CONFIG_NO_WPA */
4633
0
  wpa_s->rsnxe_len = 0;
4634
0
#ifndef CONFIG_NO_ROBUST_AV
4635
0
  wpa_s->mscs_setup_done = false;
4636
0
#endif /* CONFIG_NO_ROBUST_AV */
4637
4638
0
  wpa_ie = wpas_populate_assoc_ies(wpa_s, bss, ssid, &params, NULL);
4639
0
  if (!wpa_ie) {
4640
0
    wpas_connect_work_done(wpa_s);
4641
0
    return;
4642
0
  }
4643
4644
0
  if (bss &&
4645
0
      (!wpas_driver_bss_selection(wpa_s) || wpas_wps_searching(wpa_s))) {
4646
#ifdef CONFIG_IEEE80211R
4647
    const u8 *ie, *md = NULL;
4648
#endif /* CONFIG_IEEE80211R */
4649
0
    wpa_msg(wpa_s, MSG_INFO, "Trying to associate with " MACSTR
4650
0
      " (SSID='%s' freq=%d MHz)", MAC2STR(bss->bssid),
4651
0
      wpa_ssid_txt(bss->ssid, bss->ssid_len), bss->freq);
4652
0
    bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
4653
0
    os_memset(wpa_s->bssid, 0, ETH_ALEN);
4654
0
    os_memcpy(wpa_s->pending_bssid, bss->bssid, ETH_ALEN);
4655
0
    if (bssid_changed)
4656
0
      wpas_notify_bssid_changed(wpa_s);
4657
#ifdef CONFIG_IEEE80211R
4658
    ie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
4659
    if (ie && ie[1] >= MOBILITY_DOMAIN_ID_LEN)
4660
      md = ie + 2;
4661
    wpa_sm_set_ft_params(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0);
4662
    if (md) {
4663
      /* Prepare for the next transition */
4664
      wpa_ft_prepare_auth_request(wpa_s->wpa, ie);
4665
    }
4666
#endif /* CONFIG_IEEE80211R */
4667
#ifdef CONFIG_WPS
4668
  } else if ((ssid->ssid == NULL || ssid->ssid_len == 0) &&
4669
       wpa_s->conf->ap_scan == 2 &&
4670
       (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
4671
    /* Use ap_scan==1 style network selection to find the network
4672
     */
4673
    wpas_connect_work_done(wpa_s);
4674
    wpa_s->scan_req = MANUAL_SCAN_REQ;
4675
    wpa_s->reassociate = 1;
4676
    wpa_supplicant_req_scan(wpa_s, 0, 0);
4677
    os_free(wpa_ie);
4678
    return;
4679
#endif /* CONFIG_WPS */
4680
0
  } else {
4681
0
    wpa_msg(wpa_s, MSG_INFO, "Trying to associate with SSID '%s'",
4682
0
      wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
4683
0
    if (bss)
4684
0
      os_memcpy(wpa_s->pending_bssid, bss->bssid, ETH_ALEN);
4685
0
    else
4686
0
      os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
4687
0
  }
4688
0
  if (!wpa_s->pno)
4689
0
    wpa_supplicant_cancel_sched_scan(wpa_s);
4690
4691
0
  wpa_supplicant_cancel_scan(wpa_s);
4692
4693
0
  wpa_clear_keys(wpa_s, bss ? bss->bssid : NULL);
4694
0
  use_crypt = 1;
4695
0
  cipher_pairwise = wpa_s->pairwise_cipher;
4696
0
  cipher_group = wpa_s->group_cipher;
4697
0
  cipher_group_mgmt = wpa_s->mgmt_group_cipher;
4698
0
  if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4699
0
      wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
4700
0
    if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE)
4701
0
      use_crypt = 0;
4702
#ifdef CONFIG_WEP
4703
    if (wpa_set_wep_keys(wpa_s, ssid)) {
4704
      use_crypt = 1;
4705
      wep_keys_set = 1;
4706
    }
4707
#endif /* CONFIG_WEP */
4708
0
  }
4709
0
  if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)
4710
0
    use_crypt = 0;
4711
4712
0
#ifdef IEEE8021X_EAPOL
4713
0
  if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
4714
0
    if ((ssid->eapol_flags &
4715
0
         (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
4716
0
          EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) == 0 &&
4717
0
        !wep_keys_set) {
4718
0
      use_crypt = 0;
4719
0
    } else {
4720
      /* Assume that dynamic WEP-104 keys will be used and
4721
       * set cipher suites in order for drivers to expect
4722
       * encryption. */
4723
0
      cipher_pairwise = cipher_group = WPA_CIPHER_WEP104;
4724
0
    }
4725
0
  }
4726
0
#endif /* IEEE8021X_EAPOL */
4727
4728
0
  if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
4729
    /* Set the key before (and later after) association */
4730
0
    wpa_supplicant_set_wpa_none_key(wpa_s, ssid);
4731
0
  }
4732
4733
  /* Set current_ssid before changing state to ASSOCIATING, so that the
4734
   * selected SSID is available to wpas_notify_state_changed(). */
4735
0
  old_ssid = wpa_s->current_ssid;
4736
0
  wpa_s->current_ssid = ssid;
4737
4738
0
  wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATING);
4739
0
  if (bss) {
4740
0
    params.ssid = bss->ssid;
4741
0
    params.ssid_len = bss->ssid_len;
4742
0
    if (!wpas_driver_bss_selection(wpa_s) || ssid->bssid_set ||
4743
0
        wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
4744
0
      wpa_printf(MSG_DEBUG, "Limit connection to BSSID "
4745
0
           MACSTR " freq=%u MHz based on scan results "
4746
0
           "(bssid_set=%d wps=%d)",
4747
0
           MAC2STR(bss->bssid), bss->freq,
4748
0
           ssid->bssid_set,
4749
0
           wpa_s->key_mgmt == WPA_KEY_MGMT_WPS);
4750
0
      params.bssid = bss->bssid;
4751
0
      params.freq.freq = bss->freq;
4752
0
    }
4753
0
    params.bssid_hint = bss->bssid;
4754
0
    params.freq_hint = bss->freq;
4755
0
    params.pbss = bss_is_pbss(bss);
4756
0
  } else {
4757
0
    if (ssid->bssid_hint_set)
4758
0
      params.bssid_hint = ssid->bssid_hint;
4759
4760
0
    params.ssid = ssid->ssid;
4761
0
    params.ssid_len = ssid->ssid_len;
4762
0
    params.pbss = (ssid->pbss != 2) ? ssid->pbss : 0;
4763
0
  }
4764
4765
0
  params.bssid_filter = wpa_s->bssid_filter;
4766
0
  params.bssid_filter_count = wpa_s->bssid_filter_count;
4767
4768
0
  if (ssid->mode == WPAS_MODE_IBSS && ssid->bssid_set &&
4769
0
      wpa_s->conf->ap_scan == 2) {
4770
0
    params.bssid = ssid->bssid;
4771
0
    params.fixed_bssid = 1;
4772
0
  }
4773
4774
  /* Initial frequency for IBSS/mesh */
4775
0
  if ((ssid->mode == WPAS_MODE_IBSS || ssid->mode == WPAS_MODE_MESH) &&
4776
0
      ssid->frequency > 0 && params.freq.freq == 0)
4777
0
    ibss_mesh_setup_freq(wpa_s, ssid, &params.freq);
4778
4779
0
  if (ssid->mode == WPAS_MODE_IBSS) {
4780
0
    params.fixed_freq = ssid->fixed_freq;
4781
0
    if (ssid->beacon_int)
4782
0
      params.beacon_int = ssid->beacon_int;
4783
0
    else
4784
0
      params.beacon_int = wpa_s->conf->beacon_int;
4785
0
  }
4786
4787
0
  if (bss && ssid->enable_edmg)
4788
0
    edmg_ie_oper = wpa_bss_get_ie_ext(bss,
4789
0
              WLAN_EID_EXT_EDMG_OPERATION);
4790
0
  else
4791
0
    edmg_ie_oper = NULL;
4792
4793
0
  if (edmg_ie_oper) {
4794
0
    params.freq.edmg.channels =
4795
0
      wpa_ie_get_edmg_oper_chans(edmg_ie_oper);
4796
0
    params.freq.edmg.bw_config =
4797
0
      wpa_ie_get_edmg_oper_chan_width(edmg_ie_oper);
4798
0
    wpa_printf(MSG_DEBUG,
4799
0
         "AP supports EDMG channels 0x%x, bw_config %d",
4800
0
         params.freq.edmg.channels,
4801
0
         params.freq.edmg.bw_config);
4802
4803
    /* User may ask for specific EDMG channel for EDMG connection
4804
     * (must be supported by AP)
4805
     */
4806
0
    if (ssid->edmg_channel) {
4807
0
      struct ieee80211_edmg_config configured_edmg;
4808
0
      enum hostapd_hw_mode hw_mode;
4809
0
      u8 primary_channel;
4810
4811
0
      hw_mode = ieee80211_freq_to_chan(bss->freq,
4812
0
               &primary_channel);
4813
0
      if (hw_mode == NUM_HOSTAPD_MODES)
4814
0
        goto edmg_fail;
4815
4816
0
      hostapd_encode_edmg_chan(ssid->enable_edmg,
4817
0
             ssid->edmg_channel,
4818
0
             primary_channel,
4819
0
             &configured_edmg);
4820
4821
0
      if (ieee802_edmg_is_allowed(params.freq.edmg,
4822
0
                configured_edmg)) {
4823
0
        params.freq.edmg = configured_edmg;
4824
0
        wpa_printf(MSG_DEBUG,
4825
0
             "Use EDMG channel %d for connection",
4826
0
             ssid->edmg_channel);
4827
0
      } else {
4828
0
      edmg_fail:
4829
0
        params.freq.edmg.channels = 0;
4830
0
        params.freq.edmg.bw_config = 0;
4831
0
        wpa_printf(MSG_WARNING,
4832
0
             "EDMG channel %d not supported by AP, fallback to DMG",
4833
0
             ssid->edmg_channel);
4834
0
      }
4835
0
    }
4836
4837
0
    if (params.freq.edmg.channels) {
4838
0
      wpa_printf(MSG_DEBUG,
4839
0
           "EDMG before: channels 0x%x, bw_config %d",
4840
0
           params.freq.edmg.channels,
4841
0
           params.freq.edmg.bw_config);
4842
0
      params.freq.edmg = get_supported_edmg(wpa_s,
4843
0
                    &params.freq,
4844
0
                    params.freq.edmg);
4845
0
      wpa_printf(MSG_DEBUG,
4846
0
           "EDMG after: channels 0x%x, bw_config %d",
4847
0
           params.freq.edmg.channels,
4848
0
           params.freq.edmg.bw_config);
4849
0
    }
4850
0
  }
4851
4852
0
  params.pairwise_suite = cipher_pairwise;
4853
0
  params.group_suite = cipher_group;
4854
0
  params.mgmt_group_suite = cipher_group_mgmt;
4855
0
  params.key_mgmt_suite = wpa_s->key_mgmt;
4856
0
  params.allowed_key_mgmts = wpa_s->allowed_key_mgmts;
4857
0
  params.wpa_proto = wpa_s->wpa_proto;
4858
0
  wpa_s->auth_alg = params.auth_alg;
4859
0
  params.mode = ssid->mode;
4860
0
  params.bg_scan_period = ssid->bg_scan_period;
4861
#ifdef CONFIG_WEP
4862
  {
4863
    int i;
4864
4865
    for (i = 0; i < NUM_WEP_KEYS; i++) {
4866
      if (ssid->wep_key_len[i])
4867
        params.wep_key[i] = ssid->wep_key[i];
4868
      params.wep_key_len[i] = ssid->wep_key_len[i];
4869
    }
4870
    params.wep_tx_keyidx = ssid->wep_tx_keyidx;
4871
  }
4872
#endif /* CONFIG_WEP */
4873
4874
0
  if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
4875
0
      (params.key_mgmt_suite == WPA_KEY_MGMT_PSK ||
4876
0
       params.key_mgmt_suite == WPA_KEY_MGMT_FT_PSK ||
4877
0
       (params.allowed_key_mgmts &
4878
0
        (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_FT_PSK)))) {
4879
0
    params.passphrase = ssid->passphrase;
4880
0
    if (wpa_supplicant_get_psk(wpa_s, bss, ssid, psk) == 0)
4881
0
      params.psk = psk;
4882
0
  }
4883
4884
0
  if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
4885
0
      (params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
4886
0
       params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
4887
0
       params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B ||
4888
0
       params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 ||
4889
0
       params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA384))
4890
0
    params.req_handshake_offload = 1;
4891
4892
0
  if (wpa_s->conf->key_mgmt_offload) {
4893
0
    if (params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
4894
0
        params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
4895
0
        params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B ||
4896
0
        params.key_mgmt_suite ==
4897
0
        WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 ||
4898
0
        params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA384)
4899
0
      params.req_key_mgmt_offload =
4900
0
        ssid->proactive_key_caching < 0 ?
4901
0
        wpa_s->conf->okc : ssid->proactive_key_caching;
4902
0
    else
4903
0
      params.req_key_mgmt_offload = 1;
4904
4905
0
    if ((wpa_key_mgmt_wpa_psk_no_sae(params.key_mgmt_suite) ||
4906
0
         wpa_key_mgmt_wpa_psk_no_sae(params.allowed_key_mgmts)) &&
4907
0
        wpa_supplicant_get_psk(wpa_s, bss, ssid, psk) == 0)
4908
0
      params.psk = psk;
4909
0
  }
4910
4911
0
  if ((wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_SAE_OFFLOAD_STA) &&
4912
0
      wpa_key_mgmt_sae(params.key_mgmt_suite)) {
4913
0
    params.auth_alg = WPA_AUTH_ALG_SAE;
4914
0
    if (ssid->sae_password) {
4915
0
      params.sae_password = ssid->sae_password;
4916
0
      params.sae_password_id = ssid->sae_password_id;
4917
0
    } else if (ssid->passphrase) {
4918
0
      params.passphrase = ssid->passphrase;
4919
0
    }
4920
0
  }
4921
4922
#ifdef CONFIG_ENC_ASSOC
4923
  if (wpa_key_mgmt_eppke(ssid->key_mgmt) &&
4924
      wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_EPPKE) {
4925
    params.eppke_supported = true;
4926
    if (wpa_key_mgmt_sae_ext_key(params.key_mgmt_suite) ||
4927
        wpa_key_mgmt_sae_ext_key(params.allowed_key_mgmts) ||
4928
        wpa_key_mgmt_eppke(params.key_mgmt_suite)) {
4929
      wpa_dbg(wpa_s, MSG_DEBUG, "EPPKE authentication");
4930
      params.auth_alg = WPA_AUTH_ALG_EPPKE;
4931
    }
4932
  }
4933
#endif /* CONFIG_ENC_ASSOC */
4934
4935
0
  params.drop_unencrypted = use_crypt;
4936
4937
0
  params.mgmt_frame_protection = wpas_get_ssid_pmf(wpa_s, ssid);
4938
0
  if (params.mgmt_frame_protection != NO_MGMT_FRAME_PROTECTION && bss) {
4939
0
    const u8 *rsn = wpa_bss_get_rsne(wpa_s, bss, ssid, false);
4940
0
    struct wpa_ie_data ie;
4941
0
    if (!wpas_driver_bss_selection(wpa_s) && rsn &&
4942
0
        wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ie) == 0 &&
4943
0
        ie.capabilities &
4944
0
        (WPA_CAPABILITY_MFPC | WPA_CAPABILITY_MFPR)) {
4945
0
      wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected AP supports "
4946
0
        "MFP: require MFP");
4947
0
      params.mgmt_frame_protection =
4948
0
        MGMT_FRAME_PROTECTION_REQUIRED;
4949
#ifdef CONFIG_OWE
4950
    } else if (!rsn && (ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
4951
         !ssid->owe_only) {
4952
      params.mgmt_frame_protection = NO_MGMT_FRAME_PROTECTION;
4953
#endif /* CONFIG_OWE */
4954
0
    }
4955
0
  }
4956
4957
0
  params.p2p = ssid->p2p_group;
4958
4959
0
  if (wpa_s->p2pdev->set_sta_uapsd)
4960
0
    params.uapsd = wpa_s->p2pdev->sta_uapsd;
4961
0
  else
4962
0
    params.uapsd = -1;
4963
4964
#ifdef CONFIG_HT_OVERRIDES
4965
  os_memset(&htcaps, 0, sizeof(htcaps));
4966
  os_memset(&htcaps_mask, 0, sizeof(htcaps_mask));
4967
  params.htcaps = (u8 *) &htcaps;
4968
  params.htcaps_mask = (u8 *) &htcaps_mask;
4969
  wpa_supplicant_apply_ht_overrides(wpa_s, ssid, &params);
4970
#endif /* CONFIG_HT_OVERRIDES */
4971
#ifdef CONFIG_VHT_OVERRIDES
4972
  os_memset(&vhtcaps, 0, sizeof(vhtcaps));
4973
  os_memset(&vhtcaps_mask, 0, sizeof(vhtcaps_mask));
4974
  params.vhtcaps = &vhtcaps;
4975
  params.vhtcaps_mask = &vhtcaps_mask;
4976
  wpa_supplicant_apply_vht_overrides(wpa_s, ssid, &params);
4977
#endif /* CONFIG_VHT_OVERRIDES */
4978
#ifdef CONFIG_HE_OVERRIDES
4979
  wpa_supplicant_apply_he_overrides(wpa_s, ssid, &params);
4980
#endif /* CONFIG_HE_OVERRIDES */
4981
0
  wpa_supplicant_apply_eht_overrides(wpa_s, ssid, &params);
4982
0
  wpa_supplicant_apply_uhr_overrides(wpa_s, ssid, &params);
4983
4984
#ifdef CONFIG_P2P
4985
  /*
4986
   * If multi-channel concurrency is not supported, check for any
4987
   * frequency conflict. In case of any frequency conflict, remove the
4988
   * least prioritized connection.
4989
   */
4990
  if (wpa_s->num_multichan_concurrent < 2) {
4991
    int freq, num;
4992
    num = get_shared_radio_freqs(wpa_s, &freq, 1, false);
4993
    if (num > 0 && freq > 0 && freq != params.freq.freq) {
4994
      wpa_printf(MSG_DEBUG,
4995
           "Assoc conflicting freq found (%d != %d)",
4996
           freq, params.freq.freq);
4997
      if (wpas_p2p_handle_frequency_conflicts(
4998
            wpa_s, params.freq.freq, ssid) < 0) {
4999
        wpas_connect_work_done(wpa_s);
5000
        os_free(wpa_ie);
5001
        return;
5002
      }
5003
    }
5004
  }
5005
#endif /* CONFIG_P2P */
5006
5007
0
  if (wpa_s->reassoc_same_ess && !is_zero_ether_addr(prev_bssid) &&
5008
0
      old_ssid)
5009
0
    params.prev_bssid = prev_bssid;
5010
5011
#ifdef CONFIG_SAE
5012
  params.sae_pwe = wpas_get_ssid_sae_pwe(wpa_s, ssid);
5013
#endif /* CONFIG_SAE */
5014
5015
0
  ret = wpa_drv_associate(wpa_s, &params);
5016
0
  forced_memzero(psk, sizeof(psk));
5017
0
  os_free(wpa_ie);
5018
0
  if (ret < 0) {
5019
0
    wpa_msg(wpa_s, MSG_INFO, "Association request to the driver "
5020
0
      "failed");
5021
0
    if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_VALID_ERROR_CODES) {
5022
      /*
5023
       * The driver is known to mean what is saying, so we
5024
       * can stop right here; the association will not
5025
       * succeed.
5026
       */
5027
0
      wpas_connection_failed(wpa_s, wpa_s->pending_bssid,
5028
0
                 NULL);
5029
0
      wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
5030
0
      os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
5031
0
      return;
5032
0
    }
5033
    /* try to continue anyway; new association will be tried again
5034
     * after timeout */
5035
0
    assoc_failed = 1;
5036
0
  }
5037
5038
0
  if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
5039
    /* Set the key after the association just in case association
5040
     * cleared the previously configured key. */
5041
0
    wpa_supplicant_set_wpa_none_key(wpa_s, ssid);
5042
    /* No need to timeout authentication since there is no key
5043
     * management. */
5044
0
    wpa_supplicant_cancel_auth_timeout(wpa_s);
5045
0
    wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
5046
#ifdef CONFIG_IBSS_RSN
5047
  } else if (ssid->mode == WPAS_MODE_IBSS &&
5048
       wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
5049
       wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE) {
5050
    /*
5051
     * RSN IBSS authentication is per-STA and we can disable the
5052
     * per-BSSID authentication.
5053
     */
5054
    wpa_supplicant_cancel_auth_timeout(wpa_s);
5055
#endif /* CONFIG_IBSS_RSN */
5056
0
  } else {
5057
    /* Timeout for IEEE 802.11 authentication and association */
5058
0
    int timeout = 60;
5059
5060
0
    if (assoc_failed) {
5061
      /* give IBSS a bit more time */
5062
0
      timeout = ssid->mode == WPAS_MODE_IBSS ? 10 : 5;
5063
0
    } else if (wpa_s->conf->ap_scan == 1) {
5064
      /* give IBSS a bit more time */
5065
0
      timeout = ssid->mode == WPAS_MODE_IBSS ? 20 : 10;
5066
0
    }
5067
0
    wpa_supplicant_req_auth_timeout(wpa_s, timeout, 0);
5068
0
  }
5069
5070
#ifdef CONFIG_P2P
5071
  if (ssid->pmk_valid && wpa_s->p2p_pmksa_entry &&
5072
      !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
5073
    wpa_sm_pmksa_cache_add_entry(wpa_s->wpa,
5074
               wpa_s->p2p_pmksa_entry);
5075
    wpa_s->p2p_pmksa_entry = NULL;
5076
  }
5077
#endif /* CONFIG_P2P */
5078
5079
#ifdef CONFIG_WEP
5080
  if (wep_keys_set &&
5081
      (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC)) {
5082
    /* Set static WEP keys again */
5083
    wpa_set_wep_keys(wpa_s, ssid);
5084
  }
5085
#endif /* CONFIG_WEP */
5086
5087
0
  if (old_ssid && old_ssid != ssid) {
5088
    /*
5089
     * Do not allow EAP session resumption between different
5090
     * network configurations.
5091
     */
5092
0
    eapol_sm_invalidate_cached_session(wpa_s->eapol);
5093
0
  }
5094
5095
0
  if (!wpas_driver_bss_selection(wpa_s) ||
5096
#ifdef CONFIG_P2P
5097
      wpa_s->p2p_in_invitation ||
5098
#endif /* CONFIG_P2P */
5099
0
      ssid->bssid_set) {
5100
0
    wpa_s->current_bss = bss;
5101
0
    wpas_configure_frame_filters(wpa_s);
5102
0
  }
5103
5104
0
  wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
5105
0
  if (bss)
5106
0
    wpa_sm_set_ssid(wpa_s->wpa, bss->ssid, bss->ssid_len);
5107
0
  wpa_supplicant_initiate_eapol(wpa_s);
5108
0
  if (old_ssid != wpa_s->current_ssid)
5109
0
    wpas_notify_network_changed(wpa_s);
5110
0
  if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
5111
0
    wpas_notify_auth_changed(wpa_s);
5112
0
}
5113
5114
5115
static void wpa_supplicant_clear_connection(struct wpa_supplicant *wpa_s,
5116
              const u8 *addr)
5117
0
{
5118
0
  struct wpa_ssid *old_ssid;
5119
5120
0
  wpa_s->ml_connect_probe_ssid = NULL;
5121
0
  wpa_s->ml_connect_probe_bss = NULL;
5122
0
  wpas_connect_work_done(wpa_s);
5123
0
  wpa_clear_keys(wpa_s, addr);
5124
0
  old_ssid = wpa_s->current_ssid;
5125
0
  wpa_supplicant_mark_disassoc(wpa_s);
5126
0
  wpa_sm_set_config(wpa_s->wpa, NULL);
5127
0
  eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
5128
0
  if (old_ssid != wpa_s->current_ssid)
5129
0
    wpas_notify_network_changed(wpa_s);
5130
5131
0
#ifndef CONFIG_NO_ROBUST_AV
5132
0
  wpas_scs_deinit(wpa_s);
5133
0
  wpas_dscp_deinit(wpa_s);
5134
0
#endif /* CONFIG_NO_ROBUST_AV */
5135
0
  eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
5136
0
}
5137
5138
5139
/**
5140
 * wpa_supplicant_deauthenticate - Deauthenticate the current connection
5141
 * @wpa_s: Pointer to wpa_supplicant data
5142
 * @reason_code: IEEE 802.11 reason code for the deauthenticate frame
5143
 *
5144
 * This function is used to request %wpa_supplicant to deauthenticate from the
5145
 * current AP.
5146
 */
5147
void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,
5148
           u16 reason_code)
5149
0
{
5150
0
  u8 *addr = NULL;
5151
0
  union wpa_event_data event;
5152
0
  int zero_addr = 0;
5153
5154
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Request to deauthenticate - bssid=" MACSTR
5155
0
    " pending_bssid=" MACSTR
5156
0
    " reason=%d (%s) state=%s valid_links=0x%x ap_mld_addr=" MACSTR,
5157
0
    MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
5158
0
    reason_code, reason2str(reason_code),
5159
0
    wpa_supplicant_state_txt(wpa_s->wpa_state), wpa_s->valid_links,
5160
0
    MAC2STR(wpa_s->ap_mld_addr));
5161
5162
0
  if (wpa_s->valid_links && !is_zero_ether_addr(wpa_s->ap_mld_addr))
5163
0
    addr = wpa_s->ap_mld_addr;
5164
0
  else if (!is_zero_ether_addr(wpa_s->pending_bssid) &&
5165
0
     (wpa_s->wpa_state == WPA_AUTHENTICATING ||
5166
0
      wpa_s->wpa_state == WPA_ASSOCIATING))
5167
0
    addr = wpa_s->pending_bssid;
5168
0
  else if (!is_zero_ether_addr(wpa_s->bssid))
5169
0
    addr = wpa_s->bssid;
5170
0
  else if (wpa_s->wpa_state == WPA_ASSOCIATING) {
5171
    /*
5172
     * When using driver-based BSS selection, we may not know the
5173
     * BSSID with which we are currently trying to associate. We
5174
     * need to notify the driver of this disconnection even in such
5175
     * a case, so use the all zeros address here.
5176
     */
5177
0
    addr = wpa_s->bssid;
5178
0
    zero_addr = 1;
5179
0
  }
5180
5181
0
  if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
5182
0
    wpa_s->enabled_4addr_mode = 0;
5183
5184
#ifdef CONFIG_TDLS
5185
  wpa_tdls_teardown_peers(wpa_s->wpa);
5186
#endif /* CONFIG_TDLS */
5187
5188
#ifdef CONFIG_MESH
5189
  if (wpa_s->ifmsh) {
5190
    struct mesh_conf *mconf;
5191
5192
    mconf = wpa_s->ifmsh->mconf;
5193
    wpa_msg(wpa_s, MSG_INFO, MESH_GROUP_REMOVED "%s",
5194
      wpa_s->ifname);
5195
    wpas_notify_mesh_group_removed(wpa_s, mconf->meshid,
5196
                 mconf->meshid_len, reason_code);
5197
    wpa_supplicant_leave_mesh(wpa_s, true);
5198
  }
5199
#endif /* CONFIG_MESH */
5200
5201
0
  if (addr) {
5202
0
    wpa_drv_deauthenticate(wpa_s, addr, reason_code);
5203
0
    os_memset(&event, 0, sizeof(event));
5204
0
    event.deauth_info.reason_code = reason_code;
5205
0
    event.deauth_info.locally_generated = 1;
5206
0
    wpa_supplicant_event(wpa_s, EVENT_DEAUTH, &event);
5207
0
    if (zero_addr)
5208
0
      addr = NULL;
5209
0
  }
5210
5211
0
  wpa_supplicant_clear_connection(wpa_s, addr);
5212
0
}
5213
5214
5215
void wpa_supplicant_reconnect(struct wpa_supplicant *wpa_s)
5216
0
{
5217
0
  wpa_s->own_reconnect_req = 1;
5218
0
  wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
5219
5220
0
}
5221
5222
5223
static void wpa_supplicant_enable_one_network(struct wpa_supplicant *wpa_s,
5224
                struct wpa_ssid *ssid)
5225
0
{
5226
0
  if (!ssid || !ssid->disabled || ssid->disabled == 2)
5227
0
    return;
5228
5229
0
  ssid->disabled = 0;
5230
0
  ssid->owe_transition_bss_select_count = 0;
5231
0
  wpas_clear_temp_disabled(wpa_s, ssid, 1);
5232
0
  wpas_notify_network_enabled_changed(wpa_s, ssid);
5233
5234
  /*
5235
   * Try to reassociate since there is no current configuration and a new
5236
   * network was made available.
5237
   */
5238
0
  if (!wpa_s->current_ssid && !wpa_s->disconnected)
5239
0
    wpa_s->reassociate = 1;
5240
0
}
5241
5242
5243
/**
5244
 * wpa_supplicant_add_network - Add a new network
5245
 * @wpa_s: wpa_supplicant structure for a network interface
5246
 * Returns: The new network configuration or %NULL if operation failed
5247
 *
5248
 * This function performs the following operations:
5249
 * 1. Adds a new network.
5250
 * 2. Send network addition notification.
5251
 * 3. Marks the network disabled.
5252
 * 4. Set network default parameters.
5253
 */
5254
struct wpa_ssid * wpa_supplicant_add_network(struct wpa_supplicant *wpa_s)
5255
0
{
5256
0
  struct wpa_ssid *ssid;
5257
5258
0
  ssid = wpa_config_add_network(wpa_s->conf);
5259
0
  if (!ssid)
5260
0
    return NULL;
5261
0
  wpas_notify_network_added(wpa_s, ssid);
5262
0
  ssid->disabled = 1;
5263
0
  wpa_config_set_network_defaults(ssid);
5264
5265
0
  return ssid;
5266
0
}
5267
5268
5269
/**
5270
 * wpa_supplicant_remove_network - Remove a configured network based on id
5271
 * @wpa_s: wpa_supplicant structure for a network interface
5272
 * @id: Unique network id to search for
5273
 * Returns: 0 on success, or -1 if the network was not found, -2 if the network
5274
 * could not be removed
5275
 *
5276
 * This function performs the following operations:
5277
 * 1. Removes the network.
5278
 * 2. Send network removal notification.
5279
 * 3. Update internal state machines.
5280
 * 4. Stop any running sched scans.
5281
 */
5282
int wpa_supplicant_remove_network(struct wpa_supplicant *wpa_s, int id)
5283
0
{
5284
0
  struct wpa_ssid *ssid, *prev = wpa_s->current_ssid;
5285
0
  int was_disabled;
5286
5287
0
  ssid = wpa_config_get_network(wpa_s->conf, id);
5288
0
  if (!ssid)
5289
0
    return -1;
5290
0
  wpas_notify_network_removed(wpa_s, ssid);
5291
0
  radio_remove_pending_connect(wpa_s, ssid);
5292
5293
0
  if (ssid == prev || !prev) {
5294
#ifdef CONFIG_SME
5295
    wpa_s->sme.prev_bssid_set = 0;
5296
#endif /* CONFIG_SME */
5297
    /*
5298
     * Invalidate the EAP session cache if the current or
5299
     * previously used network is removed.
5300
     */
5301
0
    eapol_sm_invalidate_cached_session(wpa_s->eapol);
5302
0
  }
5303
5304
0
  if (ssid == prev) {
5305
0
    wpa_sm_set_config(wpa_s->wpa, NULL);
5306
0
    eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
5307
5308
0
    if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
5309
0
      wpa_s->own_disconnect_req = 1;
5310
0
    wpa_supplicant_deauthenticate(wpa_s,
5311
0
                WLAN_REASON_DEAUTH_LEAVING);
5312
0
  }
5313
5314
0
  was_disabled = ssid->disabled;
5315
5316
0
  if (wpa_config_remove_network(wpa_s->conf, id) < 0)
5317
0
    return -2;
5318
5319
0
  if (!was_disabled && wpa_s->sched_scanning) {
5320
0
    wpa_printf(MSG_DEBUG,
5321
0
         "Stop ongoing sched_scan to remove network from filters");
5322
0
    wpa_supplicant_cancel_sched_scan(wpa_s);
5323
0
    wpa_supplicant_req_scan(wpa_s, 0, 0);
5324
0
  }
5325
5326
0
  return 0;
5327
0
}
5328
5329
5330
/**
5331
 * wpa_supplicant_remove_all_networks - Remove all configured networks
5332
 * @wpa_s: wpa_supplicant structure for a network interface
5333
 * Returns: 0 on success (errors are currently ignored)
5334
 *
5335
 * This function performs the following operations:
5336
 * 1. Remove all networks.
5337
 * 2. Send network removal notifications.
5338
 * 3. Update internal state machines.
5339
 * 4. Stop any running sched scans.
5340
 */
5341
int wpa_supplicant_remove_all_networks(struct wpa_supplicant *wpa_s)
5342
0
{
5343
0
  struct wpa_ssid *ssid;
5344
5345
0
  if (wpa_s->drv_flags2 &
5346
0
      (WPA_DRIVER_FLAGS2_SAE_OFFLOAD_STA |
5347
0
       WPA_DRIVER_FLAGS2_OWE_OFFLOAD_STA))
5348
0
    wpa_drv_flush_pmkid(wpa_s);
5349
5350
0
  if (wpa_s->sched_scanning)
5351
0
    wpa_supplicant_cancel_sched_scan(wpa_s);
5352
5353
0
  eapol_sm_invalidate_cached_session(wpa_s->eapol);
5354
0
  if (wpa_s->current_ssid) {
5355
#ifdef CONFIG_SME
5356
    wpa_s->sme.prev_bssid_set = 0;
5357
#endif /* CONFIG_SME */
5358
0
    wpa_sm_set_config(wpa_s->wpa, NULL);
5359
0
    eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
5360
0
    if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
5361
0
      wpa_s->own_disconnect_req = 1;
5362
0
    wpa_supplicant_deauthenticate(
5363
0
      wpa_s, WLAN_REASON_DEAUTH_LEAVING);
5364
0
  }
5365
0
  ssid = wpa_s->conf->ssid;
5366
0
  while (ssid) {
5367
0
    struct wpa_ssid *remove_ssid = ssid;
5368
0
    int id;
5369
5370
0
    id = ssid->id;
5371
0
    ssid = ssid->next;
5372
0
    wpas_notify_network_removed(wpa_s, remove_ssid);
5373
0
    wpa_config_remove_network(wpa_s->conf, id);
5374
0
  }
5375
0
  return 0;
5376
0
}
5377
5378
5379
/**
5380
 * wpa_supplicant_enable_network - Mark a configured network as enabled
5381
 * @wpa_s: wpa_supplicant structure for a network interface
5382
 * @ssid: wpa_ssid structure for a configured network or %NULL
5383
 *
5384
 * Enables the specified network or all networks if no network specified.
5385
 */
5386
void wpa_supplicant_enable_network(struct wpa_supplicant *wpa_s,
5387
           struct wpa_ssid *ssid)
5388
0
{
5389
0
  if (ssid == NULL) {
5390
0
    for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
5391
0
      wpa_supplicant_enable_one_network(wpa_s, ssid);
5392
0
  } else
5393
0
    wpa_supplicant_enable_one_network(wpa_s, ssid);
5394
5395
0
  if (wpa_s->reassociate && !wpa_s->disconnected &&
5396
0
      (!wpa_s->current_ssid ||
5397
0
       wpa_s->wpa_state == WPA_DISCONNECTED ||
5398
0
       wpa_s->wpa_state == WPA_SCANNING)) {
5399
0
    if (wpa_s->sched_scanning) {
5400
0
      wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to add "
5401
0
           "new network to scan filters");
5402
0
      wpa_supplicant_cancel_sched_scan(wpa_s);
5403
0
    }
5404
5405
0
    if (wpa_supplicant_fast_associate(wpa_s) != 1) {
5406
0
      wpa_s->scan_req = NORMAL_SCAN_REQ;
5407
0
      wpa_supplicant_req_scan(wpa_s, 0, 0);
5408
0
    }
5409
0
  }
5410
0
}
5411
5412
5413
/**
5414
 * wpa_supplicant_disable_network - Mark a configured network as disabled
5415
 * @wpa_s: wpa_supplicant structure for a network interface
5416
 * @ssid: wpa_ssid structure for a configured network or %NULL
5417
 *
5418
 * Disables the specified network or all networks if no network specified.
5419
 */
5420
void wpa_supplicant_disable_network(struct wpa_supplicant *wpa_s,
5421
            struct wpa_ssid *ssid)
5422
0
{
5423
0
  struct wpa_ssid *other_ssid;
5424
0
  int was_disabled;
5425
5426
0
  if (ssid == NULL) {
5427
0
    if (wpa_s->sched_scanning)
5428
0
      wpa_supplicant_cancel_sched_scan(wpa_s);
5429
5430
0
    for (other_ssid = wpa_s->conf->ssid; other_ssid;
5431
0
         other_ssid = other_ssid->next) {
5432
0
      was_disabled = other_ssid->disabled;
5433
0
      if (was_disabled == 2)
5434
0
        continue; /* do not change persistent P2P group
5435
             * data */
5436
5437
0
      other_ssid->disabled = 1;
5438
5439
0
      if (was_disabled != other_ssid->disabled)
5440
0
        wpas_notify_network_enabled_changed(
5441
0
          wpa_s, other_ssid);
5442
0
    }
5443
0
    if (wpa_s->current_ssid) {
5444
0
      if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
5445
0
        wpa_s->own_disconnect_req = 1;
5446
0
      wpa_supplicant_deauthenticate(
5447
0
        wpa_s, WLAN_REASON_DEAUTH_LEAVING);
5448
0
    }
5449
0
  } else if (ssid->disabled != 2) {
5450
0
    if (ssid == wpa_s->current_ssid) {
5451
0
      if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
5452
0
        wpa_s->own_disconnect_req = 1;
5453
0
      wpa_supplicant_deauthenticate(
5454
0
        wpa_s, WLAN_REASON_DEAUTH_LEAVING);
5455
0
    }
5456
5457
0
    was_disabled = ssid->disabled;
5458
5459
0
    ssid->disabled = 1;
5460
5461
0
    if (was_disabled != ssid->disabled) {
5462
0
      wpas_notify_network_enabled_changed(wpa_s, ssid);
5463
0
      if (wpa_s->sched_scanning) {
5464
0
        wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan "
5465
0
             "to remove network from filters");
5466
0
        wpa_supplicant_cancel_sched_scan(wpa_s);
5467
0
        wpa_supplicant_req_scan(wpa_s, 0, 0);
5468
0
      }
5469
0
    }
5470
0
  }
5471
0
}
5472
5473
5474
static bool ssid_in_last_scan(struct wpa_supplicant *wpa_s,
5475
            struct wpa_ssid *ssid)
5476
0
{
5477
0
  size_t i;
5478
5479
  /* Check if the previous scan included the selected network */
5480
0
  if (wpa_s->last_scan_num_ssids <= 1 ||
5481
0
      !ssid->ssid || ssid->ssid_len == 0)
5482
0
    return false;
5483
5484
  /* Iterate through the previous scan SSIDs */
5485
0
  for (i = 0; i < wpa_s->last_scan_num_ssids;  i++) {
5486
0
    if (os_memcmp(wpa_s->last_scan_ssids[i].ssid, ssid->ssid,
5487
0
            ssid->ssid_len) == 0)
5488
0
      return true;
5489
0
  }
5490
5491
0
  return false;
5492
0
}
5493
5494
5495
/**
5496
 * Checks whether an SSID was discovered in the last scan.
5497
 * @wpa_s: wpa_supplicant structure for a network interface.
5498
 * @ssid: wpa_ssid structure for a configured network.
5499
 * Returns: true if ssid found, false otherwise.
5500
 */
5501
static bool ssid_in_last_scan_res(struct wpa_supplicant *wpa_s,
5502
          struct wpa_ssid *ssid)
5503
0
{
5504
0
  size_t i;
5505
5506
0
  if (!wpa_s->last_scan_res || !ssid->ssid || ssid->ssid_len == 0)
5507
0
    return false;
5508
5509
0
  for (i = 0; i < wpa_s->last_scan_res_used; i++) {
5510
0
    if (os_memcmp(wpa_s->last_scan_res[i]->ssid,
5511
0
            ssid->ssid, ssid->ssid_len) == 0)
5512
0
      return true;
5513
0
  }
5514
5515
0
  return false;
5516
0
}
5517
5518
5519
/**
5520
 * wpa_supplicant_select_network - Attempt association with a network
5521
 * @wpa_s: wpa_supplicant structure for a network interface
5522
 * @ssid: wpa_ssid structure for a configured network or %NULL for any network
5523
 */
5524
void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s,
5525
           struct wpa_ssid *ssid)
5526
0
{
5527
5528
0
  struct wpa_ssid *other_ssid;
5529
0
  int disconnected = 0;
5530
0
  bool request_new_scan = false;
5531
5532
0
  if (ssid && ssid != wpa_s->current_ssid && wpa_s->current_ssid) {
5533
0
    if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
5534
0
      wpa_s->own_disconnect_req = 1;
5535
0
    wpa_supplicant_deauthenticate(
5536
0
      wpa_s, WLAN_REASON_DEAUTH_LEAVING);
5537
0
    disconnected = 1;
5538
0
  }
5539
5540
0
  if (ssid)
5541
0
    wpas_clear_temp_disabled(wpa_s, ssid, 1);
5542
5543
  /*
5544
   * Mark all other networks disabled or mark all networks enabled if no
5545
   * network specified.
5546
   */
5547
0
  for (other_ssid = wpa_s->conf->ssid; other_ssid;
5548
0
       other_ssid = other_ssid->next) {
5549
0
    int was_disabled = other_ssid->disabled;
5550
0
    if (was_disabled == 2)
5551
0
      continue; /* do not change persistent P2P group data */
5552
5553
0
    other_ssid->disabled = ssid ? (ssid->id != other_ssid->id) : 0;
5554
0
    if (was_disabled && !other_ssid->disabled)
5555
0
      wpas_clear_temp_disabled(wpa_s, other_ssid, 0);
5556
5557
0
    if (was_disabled != other_ssid->disabled)
5558
0
      wpas_notify_network_enabled_changed(wpa_s, other_ssid);
5559
0
  }
5560
5561
0
  if (ssid && ssid == wpa_s->current_ssid && wpa_s->current_ssid &&
5562
0
      wpa_s->wpa_state >= WPA_AUTHENTICATING) {
5563
    /* We are already associated with the selected network */
5564
0
    wpa_printf(MSG_DEBUG, "Already associated with the "
5565
0
         "selected network - do nothing");
5566
0
    return;
5567
0
  }
5568
5569
0
  if (ssid) {
5570
0
    wpa_s->current_ssid = ssid;
5571
0
    eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
5572
0
    wpa_s->connect_without_scan =
5573
0
      (ssid->mode == WPAS_MODE_MESH ||
5574
0
       ssid->mode == WPAS_MODE_AP) ? ssid : NULL;
5575
5576
0
    if (ssid->scan_ssid) {
5577
0
      if (ssid_in_last_scan(wpa_s, ssid)) {
5578
0
        wpa_printf(MSG_DEBUG,
5579
0
             "Hidden network was scanned for in last scan");
5580
0
      } else if (ssid_in_last_scan_res(wpa_s, ssid)) {
5581
0
        wpa_printf(MSG_DEBUG,
5582
0
             "Hidden network was found in last scan results");
5583
0
      } else {
5584
0
        request_new_scan = true;
5585
0
        wpa_printf(MSG_DEBUG,
5586
0
             "Request a new scan for hidden network");
5587
0
      }
5588
0
    }
5589
5590
0
    if (!request_new_scan && (ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
5591
0
        !ssid->owe_only) {
5592
0
      wpa_printf(MSG_DEBUG,
5593
0
           "Request a new scan for OWE transition SSID");
5594
0
      request_new_scan = true;
5595
0
    }
5596
5597
    /*
5598
     * Don't optimize next scan freqs since a new ESS has been
5599
     * selected.
5600
     */
5601
0
    os_free(wpa_s->next_scan_freqs);
5602
0
    wpa_s->next_scan_freqs = NULL;
5603
0
  } else {
5604
0
    wpa_s->connect_without_scan = NULL;
5605
0
  }
5606
5607
0
  wpa_s->disconnected = 0;
5608
0
  wpa_s->reassociate = 1;
5609
0
  wpa_s_clear_sae_rejected(wpa_s);
5610
0
  wpa_s->last_owe_group = 0;
5611
0
  if (ssid) {
5612
0
    ssid->owe_transition_bss_select_count = 0;
5613
0
    wpa_s_setup_sae_pt(wpa_s, ssid, false);
5614
0
  }
5615
5616
0
  if (wpa_s->connect_without_scan || request_new_scan ||
5617
0
      wpa_supplicant_fast_associate(wpa_s) != 1) {
5618
0
    wpa_s->scan_req = NORMAL_SCAN_REQ;
5619
0
    wpas_scan_reset_sched_scan(wpa_s);
5620
0
    wpa_supplicant_req_scan(wpa_s, 0, disconnected ? 100000 : 0);
5621
0
  }
5622
5623
0
  if (ssid)
5624
0
    wpas_notify_network_selected(wpa_s, ssid);
5625
0
}
5626
5627
5628
/**
5629
 * wpas_remove_cred - Remove the specified credential and all the network
5630
 * entries created based on the removed credential
5631
 * @wpa_s: wpa_supplicant structure for a network interface
5632
 * @cred: The credential to remove
5633
 * Returns: 0 on success, -1 on failure
5634
 */
5635
int wpas_remove_cred(struct wpa_supplicant *wpa_s, struct wpa_cred *cred)
5636
0
{
5637
0
  struct wpa_ssid *ssid, *next;
5638
0
  int id;
5639
5640
0
  if (!cred) {
5641
0
    wpa_printf(MSG_DEBUG, "Could not find cred");
5642
0
    return -1;
5643
0
  }
5644
5645
0
  id = cred->id;
5646
0
  if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
5647
0
    wpa_printf(MSG_DEBUG, "Could not find cred %d", id);
5648
0
    return -1;
5649
0
  }
5650
5651
0
  wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
5652
5653
  /* Remove any network entry created based on the removed credential */
5654
0
  ssid = wpa_s->conf->ssid;
5655
0
  while (ssid) {
5656
0
    next = ssid->next;
5657
5658
0
    if (ssid->parent_cred == cred) {
5659
0
      wpa_printf(MSG_DEBUG,
5660
0
           "Remove network id %d since it used the removed credential",
5661
0
           ssid->id);
5662
0
      if (wpa_supplicant_remove_network(wpa_s, ssid->id) ==
5663
0
          -1) {
5664
0
        wpa_printf(MSG_DEBUG,
5665
0
             "Could not find network id=%d",
5666
0
             ssid->id);
5667
0
      }
5668
0
    }
5669
5670
0
    ssid = next;
5671
0
  }
5672
5673
0
  return 0;
5674
0
}
5675
5676
5677
/**
5678
 * wpas_remove_cred - Remove all the Interworking credentials
5679
 * @wpa_s: wpa_supplicant structure for a network interface
5680
 * Returns: 0 on success, -1 on failure
5681
 */
5682
int wpas_remove_all_creds(struct wpa_supplicant *wpa_s)
5683
0
{
5684
0
  int res, ret = 0;
5685
0
  struct wpa_cred *cred, *prev;
5686
5687
0
  cred = wpa_s->conf->cred;
5688
0
  while (cred) {
5689
0
    prev = cred;
5690
0
    cred = cred->next;
5691
0
    res = wpas_remove_cred(wpa_s, prev);
5692
0
    if (res < 0) {
5693
0
      wpa_printf(MSG_DEBUG,
5694
0
           "Removal of all credentials failed - failed to remove credential id=%d",
5695
0
           prev->id);
5696
0
      ret = -1;
5697
0
    }
5698
0
  }
5699
5700
0
  return ret;
5701
0
}
5702
5703
5704
/**
5705
 * wpas_set_pkcs11_engine_and_module_path - Set PKCS #11 engine and module path
5706
 * @wpa_s: wpa_supplicant structure for a network interface
5707
 * @pkcs11_engine_path: PKCS #11 engine path or NULL
5708
 * @pkcs11_module_path: PKCS #11 module path or NULL
5709
 * Returns: 0 on success; -1 on failure
5710
 *
5711
 * Sets the PKCS #11 engine and module path. Both have to be NULL or a valid
5712
 * path. If resetting the EAPOL state machine with the new PKCS #11 engine and
5713
 * module path fails the paths will be reset to the default value (NULL).
5714
 */
5715
int wpas_set_pkcs11_engine_and_module_path(struct wpa_supplicant *wpa_s,
5716
             const char *pkcs11_engine_path,
5717
             const char *pkcs11_module_path)
5718
0
{
5719
0
  char *pkcs11_engine_path_copy = NULL;
5720
0
  char *pkcs11_module_path_copy = NULL;
5721
5722
0
  if (pkcs11_engine_path != NULL) {
5723
0
    pkcs11_engine_path_copy = os_strdup(pkcs11_engine_path);
5724
0
    if (pkcs11_engine_path_copy == NULL)
5725
0
      return -1;
5726
0
  }
5727
0
  if (pkcs11_module_path != NULL) {
5728
0
    pkcs11_module_path_copy = os_strdup(pkcs11_module_path);
5729
0
    if (pkcs11_module_path_copy == NULL) {
5730
0
      os_free(pkcs11_engine_path_copy);
5731
0
      return -1;
5732
0
    }
5733
0
  }
5734
5735
0
#ifndef CONFIG_PKCS11_ENGINE_PATH
5736
0
  os_free(wpa_s->conf->pkcs11_engine_path);
5737
0
  wpa_s->conf->pkcs11_engine_path = pkcs11_engine_path_copy;
5738
0
#endif /* CONFIG_PKCS11_ENGINE_PATH */
5739
0
#ifndef CONFIG_PKCS11_MODULE_PATH
5740
0
  os_free(wpa_s->conf->pkcs11_module_path);
5741
0
  wpa_s->conf->pkcs11_module_path = pkcs11_module_path_copy;
5742
0
#endif /* CONFIG_PKCS11_MODULE_PATH */
5743
5744
0
  wpa_sm_set_eapol(wpa_s->wpa, NULL);
5745
0
  eapol_sm_deinit(wpa_s->eapol);
5746
0
  wpa_s->eapol = NULL;
5747
0
  if (wpa_supplicant_init_eapol(wpa_s)) {
5748
    /* Error -> Reset paths to the default value (NULL) once. */
5749
0
    if (pkcs11_engine_path != NULL && pkcs11_module_path != NULL)
5750
0
      wpas_set_pkcs11_engine_and_module_path(wpa_s, NULL,
5751
0
                     NULL);
5752
5753
0
    return -1;
5754
0
  }
5755
0
  wpa_sm_set_eapol(wpa_s->wpa, wpa_s->eapol);
5756
5757
0
  return 0;
5758
0
}
5759
5760
5761
/**
5762
 * wpa_supplicant_set_ap_scan - Set AP scan mode for interface
5763
 * @wpa_s: wpa_supplicant structure for a network interface
5764
 * @ap_scan: AP scan mode
5765
 * Returns: 0 if succeed or -1 if ap_scan has an invalid value
5766
 *
5767
 */
5768
int wpa_supplicant_set_ap_scan(struct wpa_supplicant *wpa_s, int ap_scan)
5769
0
{
5770
5771
0
  int old_ap_scan;
5772
5773
0
  if (ap_scan < 0 || ap_scan > 2)
5774
0
    return -1;
5775
5776
0
  if (ap_scan == 2 && os_strcmp(wpa_s->driver->name, "nl80211") == 0) {
5777
0
    wpa_printf(MSG_INFO,
5778
0
         "Note: nl80211 driver interface is not designed to be used with ap_scan=2; this can result in connection failures");
5779
0
  }
5780
5781
#ifdef ANDROID
5782
  if (ap_scan == 2 && ap_scan != wpa_s->conf->ap_scan &&
5783
      wpa_s->wpa_state >= WPA_ASSOCIATING &&
5784
      wpa_s->wpa_state < WPA_COMPLETED) {
5785
    wpa_printf(MSG_ERROR, "ap_scan = %d (%d) rejected while "
5786
         "associating", wpa_s->conf->ap_scan, ap_scan);
5787
    return 0;
5788
  }
5789
#endif /* ANDROID */
5790
5791
0
  old_ap_scan = wpa_s->conf->ap_scan;
5792
0
  wpa_s->conf->ap_scan = ap_scan;
5793
5794
0
  if (old_ap_scan != wpa_s->conf->ap_scan)
5795
0
    wpas_notify_ap_scan_changed(wpa_s);
5796
5797
0
  return 0;
5798
0
}
5799
5800
5801
/**
5802
 * wpa_supplicant_set_bss_expiration_age - Set BSS entry expiration age
5803
 * @wpa_s: wpa_supplicant structure for a network interface
5804
 * @expire_age: Expiration age in seconds
5805
 * Returns: 0 if succeed or -1 if expire_age has an invalid value
5806
 *
5807
 */
5808
int wpa_supplicant_set_bss_expiration_age(struct wpa_supplicant *wpa_s,
5809
            unsigned int bss_expire_age)
5810
0
{
5811
0
  if (bss_expire_age < 10) {
5812
0
    wpa_msg(wpa_s, MSG_ERROR, "Invalid bss expiration age %u",
5813
0
      bss_expire_age);
5814
0
    return -1;
5815
0
  }
5816
0
  wpa_msg(wpa_s, MSG_DEBUG, "Setting bss expiration age: %d sec",
5817
0
    bss_expire_age);
5818
0
  wpa_s->conf->bss_expiration_age = bss_expire_age;
5819
5820
0
  return 0;
5821
0
}
5822
5823
5824
/**
5825
 * wpa_supplicant_set_bss_expiration_count - Set BSS entry expiration scan count
5826
 * @wpa_s: wpa_supplicant structure for a network interface
5827
 * @expire_count: number of scans after which an unseen BSS is reclaimed
5828
 * Returns: 0 if succeed or -1 if expire_count has an invalid value
5829
 *
5830
 */
5831
int wpa_supplicant_set_bss_expiration_count(struct wpa_supplicant *wpa_s,
5832
              unsigned int bss_expire_count)
5833
0
{
5834
0
  if (bss_expire_count < 1) {
5835
0
    wpa_msg(wpa_s, MSG_ERROR, "Invalid bss expiration count %u",
5836
0
      bss_expire_count);
5837
0
    return -1;
5838
0
  }
5839
0
  wpa_msg(wpa_s, MSG_DEBUG, "Setting bss expiration scan count: %u",
5840
0
    bss_expire_count);
5841
0
  wpa_s->conf->bss_expiration_scan_count = bss_expire_count;
5842
5843
0
  return 0;
5844
0
}
5845
5846
5847
/**
5848
 * wpa_supplicant_set_scan_interval - Set scan interval
5849
 * @wpa_s: wpa_supplicant structure for a network interface
5850
 * @scan_interval: scan interval in seconds
5851
 * Returns: 0 if succeed or -1 if scan_interval has an invalid value
5852
 *
5853
 */
5854
int wpa_supplicant_set_scan_interval(struct wpa_supplicant *wpa_s,
5855
             int scan_interval)
5856
0
{
5857
0
  if (scan_interval < 0) {
5858
0
    wpa_msg(wpa_s, MSG_ERROR, "Invalid scan interval %d",
5859
0
      scan_interval);
5860
0
    return -1;
5861
0
  }
5862
0
  wpa_msg(wpa_s, MSG_DEBUG, "Setting scan interval: %d sec",
5863
0
    scan_interval);
5864
0
  wpa_supplicant_update_scan_int(wpa_s, scan_interval);
5865
5866
0
  return 0;
5867
0
}
5868
5869
5870
/**
5871
 * wpa_supplicant_set_debug_params - Set global debug params
5872
 * @global: wpa_global structure
5873
 * @debug_level: debug level
5874
 * @debug_timestamp: determines if show timestamp in debug data
5875
 * @debug_show_keys: determines if show keys in debug data
5876
 * Returns: 0 if succeed or -1 if debug_level has wrong value
5877
 */
5878
int wpa_supplicant_set_debug_params(struct wpa_global *global, int debug_level,
5879
            int debug_timestamp, int debug_show_keys)
5880
0
{
5881
5882
0
  int old_level, old_timestamp, old_show_keys;
5883
5884
  /* check for allowed debuglevels */
5885
0
  if (debug_level != MSG_EXCESSIVE &&
5886
0
      debug_level != MSG_MSGDUMP &&
5887
0
      debug_level != MSG_DEBUG &&
5888
0
      debug_level != MSG_INFO &&
5889
0
      debug_level != MSG_WARNING &&
5890
0
      debug_level != MSG_ERROR)
5891
0
    return -1;
5892
5893
0
  old_level = wpa_debug_level;
5894
0
  old_timestamp = wpa_debug_timestamp;
5895
0
  old_show_keys = wpa_debug_show_keys;
5896
5897
0
  wpa_debug_level = debug_level;
5898
0
  wpa_debug_timestamp = debug_timestamp ? 1 : 0;
5899
0
  wpa_debug_show_keys = debug_show_keys ? 1 : 0;
5900
5901
0
  if (wpa_debug_level != old_level)
5902
0
    wpas_notify_debug_level_changed(global);
5903
0
  if (wpa_debug_timestamp != old_timestamp)
5904
0
    wpas_notify_debug_timestamp_changed(global);
5905
0
  if (wpa_debug_show_keys != old_show_keys)
5906
0
    wpas_notify_debug_show_keys_changed(global);
5907
5908
0
  return 0;
5909
0
}
5910
5911
5912
#ifdef CONFIG_OWE
5913
static int owe_trans_ssid_match(struct wpa_supplicant *wpa_s, const u8 *bssid,
5914
        const u8 *entry_ssid, size_t entry_ssid_len)
5915
{
5916
  const u8 *owe, *owe_bssid, *owe_ssid;
5917
  size_t owe_ssid_len;
5918
  struct wpa_bss *bss;
5919
5920
  /* Check network profile SSID aganst the SSID in the
5921
   * OWE Transition Mode element. */
5922
5923
  bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
5924
  if (!bss)
5925
    return 0;
5926
5927
  owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
5928
  if (!owe)
5929
    return 0;
5930
5931
  if (wpas_get_owe_trans_network(owe, &owe_bssid, &owe_ssid,
5932
               &owe_ssid_len))
5933
    return 0;
5934
5935
  return entry_ssid_len == owe_ssid_len &&
5936
    os_memcmp(owe_ssid, entry_ssid, owe_ssid_len) == 0;
5937
}
5938
#endif /* CONFIG_OWE */
5939
5940
5941
/**
5942
 * wpa_supplicant_get_ssid - Get a pointer to the current network structure
5943
 * @wpa_s: Pointer to wpa_supplicant data
5944
 * Returns: A pointer to the current network structure or %NULL on failure
5945
 */
5946
struct wpa_ssid * wpa_supplicant_get_ssid(struct wpa_supplicant *wpa_s)
5947
0
{
5948
0
  struct wpa_ssid *entry;
5949
0
  u8 ssid[SSID_MAX_LEN];
5950
0
  int res;
5951
0
  size_t ssid_len;
5952
0
  u8 bssid[ETH_ALEN];
5953
0
  int wired;
5954
5955
0
  res = wpa_drv_get_ssid(wpa_s, ssid);
5956
0
  if (res < 0) {
5957
0
    wpa_msg(wpa_s, MSG_WARNING, "Could not read SSID from "
5958
0
      "driver");
5959
0
    return NULL;
5960
0
  }
5961
0
  ssid_len = res;
5962
5963
0
  if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
5964
0
    wpa_msg(wpa_s, MSG_WARNING, "Could not read BSSID from "
5965
0
      "driver");
5966
0
    return NULL;
5967
0
  }
5968
5969
0
  wired = wpa_s->conf->ap_scan == 0 &&
5970
0
    (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED);
5971
5972
0
  entry = wpa_s->conf->ssid;
5973
0
  while (entry) {
5974
0
    if (!wpas_network_disabled(wpa_s, entry) &&
5975
0
        ((ssid_len == entry->ssid_len &&
5976
0
          (!entry->ssid ||
5977
0
           os_memcmp(ssid, entry->ssid, ssid_len) == 0)) ||
5978
0
         wired) &&
5979
0
        (wpa_s->valid_links || !entry->bssid_set ||
5980
0
         ether_addr_equal(bssid, entry->bssid)))
5981
0
      return entry;
5982
#ifdef CONFIG_WPS
5983
    if (!wpas_network_disabled(wpa_s, entry) &&
5984
        (entry->key_mgmt & WPA_KEY_MGMT_WPS) &&
5985
        (entry->ssid == NULL || entry->ssid_len == 0) &&
5986
        (wpa_s->valid_links || !entry->bssid_set ||
5987
         ether_addr_equal(bssid, entry->bssid)))
5988
      return entry;
5989
#endif /* CONFIG_WPS */
5990
5991
#ifdef CONFIG_OWE
5992
    if (!wpas_network_disabled(wpa_s, entry) &&
5993
        (entry->ssid &&
5994
         owe_trans_ssid_match(wpa_s, bssid, entry->ssid,
5995
            entry->ssid_len)) &&
5996
        (wpa_s->valid_links || !entry->bssid_set ||
5997
         ether_addr_equal(bssid, entry->bssid)))
5998
      return entry;
5999
#endif /* CONFIG_OWE */
6000
6001
0
    if (!wpas_network_disabled(wpa_s, entry) && entry->bssid_set &&
6002
0
        entry->ssid_len == 0 &&
6003
0
        ether_addr_equal(bssid, entry->bssid))
6004
0
      return entry;
6005
6006
0
    entry = entry->next;
6007
0
  }
6008
6009
0
  return NULL;
6010
0
}
6011
6012
6013
static int select_driver(struct wpa_supplicant *wpa_s, int i)
6014
0
{
6015
0
  struct wpa_global *global = wpa_s->global;
6016
6017
0
  if (wpa_drivers[i]->global_init && global->drv_priv[i] == NULL) {
6018
0
    global->drv_priv[i] = wpa_drivers[i]->global_init(global);
6019
0
    if (global->drv_priv[i] == NULL) {
6020
0
      wpa_printf(MSG_ERROR, "Failed to initialize driver "
6021
0
           "'%s'", wpa_drivers[i]->name);
6022
0
      return -1;
6023
0
    }
6024
0
  }
6025
6026
0
  wpa_s->driver = wpa_drivers[i];
6027
0
  wpa_s->global_drv_priv = global->drv_priv[i];
6028
6029
0
  return 0;
6030
0
}
6031
6032
6033
static int wpa_supplicant_set_driver(struct wpa_supplicant *wpa_s,
6034
             const char *name)
6035
0
{
6036
0
  int i;
6037
0
  size_t len;
6038
0
  const char *pos, *driver = name;
6039
6040
0
  if (wpa_s == NULL)
6041
0
    return -1;
6042
6043
0
  if (wpa_drivers[0] == NULL) {
6044
0
    wpa_msg(wpa_s, MSG_ERROR, "No driver interfaces build into "
6045
0
      "wpa_supplicant");
6046
0
    return -1;
6047
0
  }
6048
6049
0
  if (name == NULL) {
6050
    /* Default to first successful driver in the list */
6051
0
    for (i = 0; wpa_drivers[i]; i++) {
6052
0
      if (select_driver(wpa_s, i) == 0)
6053
0
        return 0;
6054
0
    }
6055
    /* Drivers have each reported failure, so no wpa_msg() here. */
6056
0
    return -1;
6057
0
  }
6058
6059
0
  do {
6060
0
    pos = os_strchr(driver, ',');
6061
0
    if (pos)
6062
0
      len = pos - driver;
6063
0
    else
6064
0
      len = os_strlen(driver);
6065
6066
0
    for (i = 0; wpa_drivers[i]; i++) {
6067
0
      if (os_strlen(wpa_drivers[i]->name) == len &&
6068
0
          os_strncmp(driver, wpa_drivers[i]->name, len) ==
6069
0
          0) {
6070
        /* First driver that succeeds wins */
6071
0
        if (select_driver(wpa_s, i) == 0)
6072
0
          return 0;
6073
0
      }
6074
0
    }
6075
6076
0
    driver = pos + 1;
6077
0
  } while (pos);
6078
6079
0
  wpa_msg(wpa_s, MSG_ERROR, "Unsupported driver '%s'", name);
6080
0
  return -1;
6081
0
}
6082
6083
6084
/**
6085
 * wpa_supplicant_rx_eapol - Deliver a received EAPOL frame to wpa_supplicant
6086
 * @ctx: Context pointer (wpa_s); this is the ctx variable registered
6087
 *  with struct wpa_driver_ops::init()
6088
 * @src_addr: Source address of the EAPOL frame
6089
 * @buf: EAPOL data starting from the EAPOL header (i.e., no Ethernet header)
6090
 * @len: Length of the EAPOL data
6091
 * @encrypted: Whether the frame was encrypted
6092
 *
6093
 * This function is called for each received EAPOL frame. Most driver
6094
 * interfaces rely on more generic OS mechanism for receiving frames through
6095
 * l2_packet, but if such a mechanism is not available, the driver wrapper may
6096
 * take care of received EAPOL frames and deliver them to the core supplicant
6097
 * code by calling this function.
6098
 */
6099
void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
6100
           const u8 *buf, size_t len,
6101
           enum frame_encryption encrypted)
6102
0
{
6103
0
  struct wpa_supplicant *wpa_s = ctx;
6104
0
  const u8 *connected_addr = wpa_s->valid_links ?
6105
0
    wpa_s->ap_mld_addr : wpa_s->bssid;
6106
6107
0
  wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR " (encrypted=%d)",
6108
0
    MAC2STR(src_addr), encrypted);
6109
0
  wpa_hexdump(MSG_MSGDUMP, "RX EAPOL", buf, len);
6110
6111
0
  if (wpa_s->own_disconnect_req) {
6112
0
    wpa_printf(MSG_DEBUG,
6113
0
         "Drop received EAPOL frame as we are disconnecting");
6114
0
    return;
6115
0
  }
6116
6117
#ifdef CONFIG_TESTING_OPTIONS
6118
  wpa_msg_ctrl(wpa_s, MSG_INFO, "EAPOL-RX " MACSTR " %zu",
6119
         MAC2STR(src_addr), len);
6120
  if (wpa_s->ignore_auth_resp) {
6121
    wpa_printf(MSG_INFO, "RX EAPOL - ignore_auth_resp active!");
6122
    return;
6123
  }
6124
#endif /* CONFIG_TESTING_OPTIONS */
6125
6126
0
  if (wpa_s->wpa_state < WPA_ASSOCIATED ||
6127
0
      wpa_s->ext_auth_to_same_bss ||
6128
0
      (wpa_s->last_eapol_matches_bssid &&
6129
#ifdef CONFIG_AP
6130
       !wpa_s->ap_iface &&
6131
#endif /* CONFIG_AP */
6132
0
       !ether_addr_equal(src_addr, connected_addr))) {
6133
    /*
6134
     * There is possible race condition between receiving the
6135
     * association event and the EAPOL frame since they are coming
6136
     * through different paths from the driver. In order to avoid
6137
     * issues in trying to process the EAPOL frame before receiving
6138
     * association information, lets queue it for processing until
6139
     * the association event is received. This may also be needed in
6140
     * driver-based roaming case, so also use src_addr != BSSID as a
6141
     * trigger if we have previously confirmed that the
6142
     * Authenticator uses BSSID as the src_addr (which is not the
6143
     * case with wired IEEE 802.1X).
6144
     */
6145
0
    wpa_dbg(wpa_s, MSG_DEBUG,
6146
0
      "Not associated - Delay processing of received EAPOL frame (state=%s connected_addr="
6147
0
      MACSTR ")",
6148
0
      wpa_supplicant_state_txt(wpa_s->wpa_state),
6149
0
      MAC2STR(connected_addr));
6150
0
  delay_processing:
6151
0
    wpabuf_free(wpa_s->pending_eapol_rx);
6152
0
    wpa_s->pending_eapol_rx = wpabuf_alloc_copy(buf, len);
6153
0
    if (wpa_s->pending_eapol_rx) {
6154
0
      os_get_reltime(&wpa_s->pending_eapol_rx_time);
6155
0
      os_memcpy(wpa_s->pending_eapol_rx_src, src_addr,
6156
0
          ETH_ALEN);
6157
0
      wpa_s->pending_eapol_encrypted = encrypted;
6158
0
    }
6159
0
    return;
6160
0
  }
6161
6162
0
  wpa_s->last_eapol_matches_bssid =
6163
0
    ether_addr_equal(src_addr, connected_addr);
6164
6165
#ifdef CONFIG_AP
6166
  if (wpa_s->ap_iface) {
6167
    wpa_supplicant_ap_rx_eapol(wpa_s, src_addr, buf, len,
6168
             encrypted);
6169
    return;
6170
  }
6171
#endif /* CONFIG_AP */
6172
6173
0
  if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) {
6174
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Ignored received EAPOL frame since "
6175
0
      "no key management is configured");
6176
0
    return;
6177
0
  }
6178
6179
0
  if (wpa_s->eapol_received == 0 &&
6180
0
      (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) ||
6181
0
       !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
6182
0
       wpa_s->wpa_state != WPA_COMPLETED) &&
6183
0
      (wpa_s->current_ssid == NULL ||
6184
0
       wpa_s->current_ssid->mode != WPAS_MODE_IBSS)) {
6185
    /* Timeout for completing IEEE 802.1X and WPA authentication */
6186
0
    int timeout = 10;
6187
6188
0
    if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
6189
0
        wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA ||
6190
0
        wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
6191
      /* Use longer timeout for IEEE 802.1X/EAP */
6192
0
      timeout = 70;
6193
0
    }
6194
6195
#ifdef CONFIG_WPS
6196
    if (wpa_s->current_ssid && wpa_s->current_bss &&
6197
        (wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
6198
        eap_is_wps_pin_enrollee(&wpa_s->current_ssid->eap)) {
6199
      /*
6200
       * Use shorter timeout if going through WPS AP iteration
6201
       * for PIN config method with an AP that does not
6202
       * advertise Selected Registrar.
6203
       */
6204
      struct wpabuf *wps_ie;
6205
6206
      wps_ie = wpa_bss_get_vendor_ie_multi(
6207
        wpa_s->current_bss, WPS_IE_VENDOR_TYPE);
6208
      if (wps_ie &&
6209
          !wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1))
6210
        timeout = 10;
6211
      wpabuf_free(wps_ie);
6212
    }
6213
#endif /* CONFIG_WPS */
6214
6215
0
    wpa_supplicant_req_auth_timeout(wpa_s, timeout, 0);
6216
0
  }
6217
0
  wpa_s->eapol_received++;
6218
6219
0
  if (wpa_s->countermeasures) {
6220
0
    wpa_msg(wpa_s, MSG_INFO, "WPA: Countermeasures - dropped "
6221
0
      "EAPOL packet");
6222
0
    return;
6223
0
  }
6224
6225
#ifdef CONFIG_IBSS_RSN
6226
  if (wpa_s->current_ssid &&
6227
      wpa_s->current_ssid->mode == WPAS_MODE_IBSS) {
6228
    ibss_rsn_rx_eapol(wpa_s->ibss_rsn, src_addr, buf, len,
6229
          encrypted);
6230
    return;
6231
  }
6232
#endif /* CONFIG_IBSS_RSN */
6233
6234
  /* Source address of the incoming EAPOL frame could be compared to the
6235
   * current BSSID. However, it is possible that a centralized
6236
   * Authenticator could be using another MAC address than the BSSID of
6237
   * an AP, so just allow any address to be used for now. The replies are
6238
   * still sent to the current BSSID (if available), though. */
6239
6240
0
  os_memcpy(wpa_s->last_eapol_src, src_addr, ETH_ALEN);
6241
0
  if (!wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) &&
6242
0
      wpa_s->key_mgmt != WPA_KEY_MGMT_OWE &&
6243
0
      wpa_s->key_mgmt != WPA_KEY_MGMT_DPP &&
6244
0
      eapol_sm_rx_eapol(wpa_s->eapol, src_addr, buf, len,
6245
0
            encrypted) > 0)
6246
0
    return;
6247
0
  wpa_drv_poll(wpa_s);
6248
0
  if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
6249
0
    if (wpa_sm_rx_eapol(wpa_s->wpa, src_addr, buf, len,
6250
0
            encrypted) == -2 &&
6251
#ifdef CONFIG_AP
6252
        !wpa_s->ap_iface &&
6253
#endif /* CONFIG_AP */
6254
0
        wpa_s->last_eapol_matches_bssid) {
6255
      /* Handle the case where reassociation occurs to the
6256
       * current connected AP */
6257
0
      wpa_dbg(wpa_s, MSG_DEBUG,
6258
0
        "Delay processing of received EAPOL frame for reassociation to the current connected AP (state=%s connected_addr="
6259
0
        MACSTR ")",
6260
0
        wpa_supplicant_state_txt(wpa_s->wpa_state),
6261
0
        MAC2STR(connected_addr));
6262
0
      goto delay_processing;
6263
0
    }
6264
0
  } else if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
6265
    /*
6266
     * Set portValid = true here since we are going to skip 4-way
6267
     * handshake processing which would normally set portValid. We
6268
     * need this to allow the EAPOL state machines to be completed
6269
     * without going through EAPOL-Key handshake.
6270
     */
6271
0
    eapol_sm_notify_portValid(wpa_s->eapol, true);
6272
0
  }
6273
0
}
6274
6275
6276
static void wpa_supplicant_rx_eapol_cb(void *ctx, const u8 *src_addr,
6277
               const u8 *buf, size_t len)
6278
0
{
6279
0
  wpa_supplicant_rx_eapol(ctx, src_addr, buf, len,
6280
0
        FRAME_ENCRYPTION_UNKNOWN);
6281
0
}
6282
6283
6284
static int wpas_eapol_needs_l2_packet(struct wpa_supplicant *wpa_s)
6285
0
{
6286
0
  return !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_CONTROL_PORT) ||
6287
0
    !(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX);
6288
0
}
6289
6290
6291
int wpa_supplicant_update_mac_addr(struct wpa_supplicant *wpa_s)
6292
0
{
6293
0
  u8 prev_mac_addr[ETH_ALEN];
6294
6295
0
  os_memcpy(prev_mac_addr, wpa_s->own_addr, ETH_ALEN);
6296
6297
0
  if ((!wpa_s->p2p_mgmt ||
6298
0
       !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) &&
6299
0
      !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE) &&
6300
0
      !wpa_s->nan_mgmt) {
6301
0
    l2_packet_deinit(wpa_s->l2);
6302
0
    wpa_s->l2 = l2_packet_init(wpa_s->ifname,
6303
0
             wpa_drv_get_mac_addr(wpa_s),
6304
0
             ETH_P_EAPOL,
6305
0
             wpas_eapol_needs_l2_packet(wpa_s) ?
6306
0
             wpa_supplicant_rx_eapol_cb : NULL,
6307
0
             wpa_s, 0);
6308
0
    if (wpa_s->l2 == NULL)
6309
0
      return -1;
6310
6311
0
    if (l2_packet_set_packet_filter(wpa_s->l2,
6312
0
            L2_PACKET_FILTER_PKTTYPE))
6313
0
      wpa_dbg(wpa_s, MSG_DEBUG,
6314
0
        "Failed to attach pkt_type filter");
6315
6316
0
    if (l2_packet_get_own_addr(wpa_s->l2, wpa_s->own_addr)) {
6317
0
      wpa_msg(wpa_s, MSG_ERROR,
6318
0
        "Failed to get own L2 address");
6319
0
      return -1;
6320
0
    }
6321
0
  } else {
6322
0
    const u8 *addr = wpa_drv_get_mac_addr(wpa_s);
6323
0
    if (addr)
6324
0
      os_memcpy(wpa_s->own_addr, addr, ETH_ALEN);
6325
0
  }
6326
6327
0
  wpa_sm_set_own_addr(wpa_s->wpa, wpa_s->own_addr);
6328
0
  wpas_wps_update_mac_addr(wpa_s);
6329
6330
#ifdef CONFIG_NAN_USD
6331
  if (wpa_s->nan_de)
6332
    nan_de_update_nmi(wpa_s->nan_de, wpa_s->own_addr);
6333
#endif /* CONFIG_NAN_USD */
6334
6335
#ifdef CONFIG_FST
6336
  if (wpa_s->fst)
6337
    fst_update_mac_addr(wpa_s->fst, wpa_s->own_addr);
6338
#endif /* CONFIG_FST */
6339
6340
0
  if (!ether_addr_equal(prev_mac_addr, wpa_s->own_addr))
6341
0
    wpas_notify_mac_address_changed(wpa_s);
6342
6343
0
  return 0;
6344
0
}
6345
6346
6347
static void wpa_supplicant_rx_eapol_bridge(void *ctx, const u8 *src_addr,
6348
             const u8 *buf, size_t len)
6349
0
{
6350
0
  struct wpa_supplicant *wpa_s = ctx;
6351
0
  const struct l2_ethhdr *eth;
6352
6353
0
  if (len < sizeof(*eth))
6354
0
    return;
6355
0
  eth = (const struct l2_ethhdr *) buf;
6356
6357
0
  if (!ether_addr_equal(eth->h_dest, wpa_s->own_addr) &&
6358
0
      !(eth->h_dest[0] & 0x01)) {
6359
0
    wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR " to " MACSTR
6360
0
      " (bridge - not for this interface - ignore)",
6361
0
      MAC2STR(src_addr), MAC2STR(eth->h_dest));
6362
0
    return;
6363
0
  }
6364
6365
0
  wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR " to " MACSTR
6366
0
    " (bridge)", MAC2STR(src_addr), MAC2STR(eth->h_dest));
6367
0
  wpa_supplicant_rx_eapol(wpa_s, src_addr, buf + sizeof(*eth),
6368
0
        len - sizeof(*eth), FRAME_ENCRYPTION_UNKNOWN);
6369
0
}
6370
6371
6372
int wpa_supplicant_update_bridge_ifname(struct wpa_supplicant *wpa_s,
6373
          const char *bridge_ifname)
6374
0
{
6375
0
  if (wpa_s->wpa_state > WPA_SCANNING)
6376
0
    return -EBUSY;
6377
6378
0
  if (bridge_ifname &&
6379
0
      os_strlen(bridge_ifname) >= sizeof(wpa_s->bridge_ifname))
6380
0
    return -EINVAL;
6381
6382
0
  if (!bridge_ifname)
6383
0
    bridge_ifname = "";
6384
6385
0
  if (os_strcmp(wpa_s->bridge_ifname, bridge_ifname) == 0)
6386
0
    return 0;
6387
6388
0
  if (wpa_s->l2_br) {
6389
0
    l2_packet_deinit(wpa_s->l2_br);
6390
0
    wpa_s->l2_br = NULL;
6391
0
  }
6392
6393
0
  os_strlcpy(wpa_s->bridge_ifname, bridge_ifname,
6394
0
       sizeof(wpa_s->bridge_ifname));
6395
6396
0
  if (wpa_s->bridge_ifname[0]) {
6397
0
    wpa_dbg(wpa_s, MSG_DEBUG,
6398
0
      "Receiving packets from bridge interface '%s'",
6399
0
      wpa_s->bridge_ifname);
6400
0
    wpa_s->l2_br = l2_packet_init_bridge(
6401
0
      wpa_s->bridge_ifname, wpa_s->ifname, wpa_s->own_addr,
6402
0
      ETH_P_EAPOL, wpa_supplicant_rx_eapol_bridge, wpa_s, 1);
6403
0
    if (!wpa_s->l2_br) {
6404
0
      wpa_msg(wpa_s, MSG_ERROR,
6405
0
        "Failed to open l2_packet connection for the bridge interface '%s'",
6406
0
        wpa_s->bridge_ifname);
6407
0
      goto fail;
6408
0
    }
6409
0
  }
6410
6411
#ifdef CONFIG_TDLS
6412
  if (!wpa_s->p2p_mgmt && wpa_tdls_init(wpa_s->wpa))
6413
    goto fail;
6414
#endif /* CONFIG_TDLS */
6415
6416
0
  return 0;
6417
0
fail:
6418
0
  wpa_s->bridge_ifname[0] = 0;
6419
0
  if (wpa_s->l2_br) {
6420
0
    l2_packet_deinit(wpa_s->l2_br);
6421
0
    wpa_s->l2_br = NULL;
6422
0
  }
6423
#ifdef CONFIG_TDLS
6424
  if (!wpa_s->p2p_mgmt)
6425
    wpa_tdls_init(wpa_s->wpa);
6426
#endif /* CONFIG_TDLS */
6427
0
  return -EIO;
6428
0
}
6429
6430
6431
/**
6432
 * wpa_supplicant_driver_init - Initialize driver interface parameters
6433
 * @wpa_s: Pointer to wpa_supplicant data
6434
 * Returns: 0 on success, -1 on failure
6435
 *
6436
 * This function is called to initialize driver interface parameters.
6437
 * wpa_drv_init() must have been called before this function to initialize the
6438
 * driver interface.
6439
 */
6440
int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s)
6441
0
{
6442
0
  static int interface_count = 0;
6443
6444
0
  if (wpa_supplicant_update_mac_addr(wpa_s) < 0)
6445
0
    return -1;
6446
6447
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Own MAC address: " MACSTR,
6448
0
    MAC2STR(wpa_s->own_addr));
6449
0
  os_memcpy(wpa_s->perm_addr, wpa_s->own_addr, ETH_ALEN);
6450
0
  wpa_sm_set_own_addr(wpa_s->wpa, wpa_s->own_addr);
6451
6452
0
  if (wpa_s->bridge_ifname[0] && wpas_eapol_needs_l2_packet(wpa_s)) {
6453
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Receiving packets from bridge "
6454
0
      "interface '%s'", wpa_s->bridge_ifname);
6455
0
    wpa_s->l2_br = l2_packet_init_bridge(
6456
0
      wpa_s->bridge_ifname, wpa_s->ifname, wpa_s->own_addr,
6457
0
      ETH_P_EAPOL, wpa_supplicant_rx_eapol_bridge, wpa_s, 1);
6458
0
    if (wpa_s->l2_br == NULL) {
6459
0
      wpa_msg(wpa_s, MSG_ERROR, "Failed to open l2_packet "
6460
0
        "connection for the bridge interface '%s'",
6461
0
        wpa_s->bridge_ifname);
6462
0
      return -1;
6463
0
    }
6464
0
  }
6465
6466
0
  if (wpa_s->conf->ap_scan == 2 &&
6467
0
      os_strcmp(wpa_s->driver->name, "nl80211") == 0) {
6468
0
    wpa_printf(MSG_INFO,
6469
0
         "Note: nl80211 driver interface is not designed to be used with ap_scan=2; this can result in connection failures");
6470
0
  }
6471
6472
0
  wpa_clear_keys(wpa_s, NULL);
6473
6474
  /* Make sure that TKIP countermeasures are not left enabled (could
6475
   * happen if wpa_supplicant is killed during countermeasures. */
6476
0
  wpa_drv_set_countermeasures(wpa_s, 0);
6477
6478
0
  wpa_dbg(wpa_s, MSG_DEBUG, "RSN: flushing PMKID list in the driver");
6479
0
  wpa_drv_flush_pmkid(wpa_s);
6480
6481
0
  wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
6482
0
  wpa_s->prev_scan_wildcard = 0;
6483
6484
0
  if (wpa_supplicant_enabled_networks(wpa_s)) {
6485
0
    if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6486
0
      wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
6487
0
      interface_count = 0;
6488
0
    }
6489
0
#ifndef ANDROID
6490
0
    if (!wpa_s->p2p_mgmt &&
6491
0
        wpa_supplicant_delayed_sched_scan(wpa_s,
6492
0
                  interface_count % 3,
6493
0
                  100000))
6494
0
      wpa_supplicant_req_scan(wpa_s, interface_count % 3,
6495
0
            100000);
6496
0
#endif /* ANDROID */
6497
0
    interface_count++;
6498
0
  } else
6499
0
    wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
6500
6501
0
  return 0;
6502
0
}
6503
6504
6505
static int wpa_supplicant_daemon(const char *pid_file)
6506
0
{
6507
0
  wpa_printf(MSG_DEBUG, "Daemonize..");
6508
0
  return os_daemonize(pid_file);
6509
0
}
6510
6511
6512
static struct wpa_supplicant *
6513
wpa_supplicant_alloc(struct wpa_supplicant *parent)
6514
0
{
6515
0
  struct wpa_supplicant *wpa_s;
6516
6517
0
  wpa_s = os_zalloc(sizeof(*wpa_s));
6518
0
  if (wpa_s == NULL)
6519
0
    return NULL;
6520
0
  wpa_s->scan_req = INITIAL_SCAN_REQ;
6521
0
  wpa_s->scan_interval = 5;
6522
0
  wpa_s->new_connection = 1;
6523
0
  wpa_s->parent = parent ? parent : wpa_s;
6524
0
  wpa_s->p2pdev = wpa_s->parent;
6525
#ifdef CONFIG_P2P
6526
  if (parent)
6527
    wpa_s->p2p_mode = parent->p2p_mode;
6528
#endif /* CONFIG_P2P */
6529
0
  wpa_s->sched_scanning = 0;
6530
0
  wpa_s->setband_mask = WPA_SETBAND_AUTO;
6531
6532
0
  dl_list_init(&wpa_s->bss_tmp_disallowed);
6533
0
  dl_list_init(&wpa_s->fils_hlp_req);
6534
#ifdef CONFIG_TESTING_OPTIONS
6535
  dl_list_init(&wpa_s->drv_signal_override);
6536
  wpa_s->test_assoc_comeback_type = -1;
6537
#endif /* CONFIG_TESTING_OPTIONS */
6538
0
#ifndef CONFIG_NO_ROBUST_AV
6539
0
  dl_list_init(&wpa_s->active_scs_ids);
6540
0
#endif /* CONFIG_NO_ROBUST_AV */
6541
0
  wpa_s->ml_probe_mld_id = -1;
6542
6543
#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
6544
#ifdef CONFIG_MESH
6545
  dl_list_init(&wpa_s->mesh_external_pmksa_cache);
6546
#endif /* CONFIG_MESH */
6547
#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
6548
6549
0
  return wpa_s;
6550
0
}
6551
6552
6553
#ifdef CONFIG_HT_OVERRIDES
6554
6555
static int wpa_set_htcap_mcs(struct wpa_supplicant *wpa_s,
6556
           struct ieee80211_ht_capabilities *htcaps,
6557
           struct ieee80211_ht_capabilities *htcaps_mask,
6558
           const char *ht_mcs)
6559
{
6560
  /* parse ht_mcs into hex array */
6561
  int i;
6562
  const char *tmp = ht_mcs;
6563
  char *end = NULL;
6564
6565
  /* If ht_mcs is null, do not set anything */
6566
  if (!ht_mcs)
6567
    return 0;
6568
6569
  /* This is what we are setting in the kernel */
6570
  os_memset(&htcaps->supported_mcs_set, 0, IEEE80211_HT_MCS_MASK_LEN);
6571
6572
  wpa_msg(wpa_s, MSG_DEBUG, "set_htcap, ht_mcs -:%s:-", ht_mcs);
6573
6574
  for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
6575
    long v;
6576
6577
    errno = 0;
6578
    v = strtol(tmp, &end, 16);
6579
6580
    if (errno == 0) {
6581
      wpa_msg(wpa_s, MSG_DEBUG,
6582
        "htcap value[%i]: %ld end: %p  tmp: %p",
6583
        i, v, end, tmp);
6584
      if (end == tmp)
6585
        break;
6586
6587
      htcaps->supported_mcs_set[i] = v;
6588
      tmp = end;
6589
    } else {
6590
      wpa_msg(wpa_s, MSG_ERROR,
6591
        "Failed to parse ht-mcs: %s, error: %s\n",
6592
        ht_mcs, strerror(errno));
6593
      return -1;
6594
    }
6595
  }
6596
6597
  /*
6598
   * If we were able to parse any values, then set mask for the MCS set.
6599
   */
6600
  if (i) {
6601
    os_memset(&htcaps_mask->supported_mcs_set, 0xff,
6602
        IEEE80211_HT_MCS_MASK_LEN - 1);
6603
    /* skip the 3 reserved bits */
6604
    htcaps_mask->supported_mcs_set[IEEE80211_HT_MCS_MASK_LEN - 1] =
6605
      0x1f;
6606
  }
6607
6608
  return 0;
6609
}
6610
6611
6612
static int wpa_disable_max_amsdu(struct wpa_supplicant *wpa_s,
6613
         struct ieee80211_ht_capabilities *htcaps,
6614
         struct ieee80211_ht_capabilities *htcaps_mask,
6615
         int disabled)
6616
{
6617
  le16 msk;
6618
6619
  if (disabled == -1)
6620
    return 0;
6621
6622
  wpa_msg(wpa_s, MSG_DEBUG, "set_disable_max_amsdu: %d", disabled);
6623
6624
  msk = host_to_le16(HT_CAP_INFO_MAX_AMSDU_SIZE);
6625
  htcaps_mask->ht_capabilities_info |= msk;
6626
  if (disabled)
6627
    htcaps->ht_capabilities_info &= msk;
6628
  else
6629
    htcaps->ht_capabilities_info |= msk;
6630
6631
  return 0;
6632
}
6633
6634
6635
static int wpa_set_ampdu_factor(struct wpa_supplicant *wpa_s,
6636
        struct ieee80211_ht_capabilities *htcaps,
6637
        struct ieee80211_ht_capabilities *htcaps_mask,
6638
        int factor)
6639
{
6640
  if (factor == -1)
6641
    return 0;
6642
6643
  wpa_msg(wpa_s, MSG_DEBUG, "set_ampdu_factor: %d", factor);
6644
6645
  if (factor < 0 || factor > 3) {
6646
    wpa_msg(wpa_s, MSG_ERROR, "ampdu_factor: %d out of range. "
6647
      "Must be 0-3 or -1", factor);
6648
    return -EINVAL;
6649
  }
6650
6651
  htcaps_mask->a_mpdu_params |= 0x3; /* 2 bits for factor */
6652
  htcaps->a_mpdu_params &= ~0x3;
6653
  htcaps->a_mpdu_params |= factor & 0x3;
6654
6655
  return 0;
6656
}
6657
6658
6659
static int wpa_set_ampdu_density(struct wpa_supplicant *wpa_s,
6660
         struct ieee80211_ht_capabilities *htcaps,
6661
         struct ieee80211_ht_capabilities *htcaps_mask,
6662
         int density)
6663
{
6664
  if (density == -1)
6665
    return 0;
6666
6667
  wpa_msg(wpa_s, MSG_DEBUG, "set_ampdu_density: %d", density);
6668
6669
  if (density < 0 || density > 7) {
6670
    wpa_msg(wpa_s, MSG_ERROR,
6671
      "ampdu_density: %d out of range. Must be 0-7 or -1.",
6672
      density);
6673
    return -EINVAL;
6674
  }
6675
6676
  htcaps_mask->a_mpdu_params |= 0x1C;
6677
  htcaps->a_mpdu_params &= ~(0x1C);
6678
  htcaps->a_mpdu_params |= (density << 2) & 0x1C;
6679
6680
  return 0;
6681
}
6682
6683
6684
static int wpa_set_disable_ht40(struct wpa_supplicant *wpa_s,
6685
        struct ieee80211_ht_capabilities *htcaps,
6686
        struct ieee80211_ht_capabilities *htcaps_mask,
6687
        int disabled)
6688
{
6689
  if (disabled)
6690
    wpa_msg(wpa_s, MSG_DEBUG, "set_disable_ht40: %d", disabled);
6691
6692
  set_disable_ht40(htcaps, disabled);
6693
  set_disable_ht40(htcaps_mask, 0);
6694
6695
  return 0;
6696
}
6697
6698
6699
static int wpa_set_disable_sgi(struct wpa_supplicant *wpa_s,
6700
             struct ieee80211_ht_capabilities *htcaps,
6701
             struct ieee80211_ht_capabilities *htcaps_mask,
6702
             int disabled)
6703
{
6704
  /* Masking these out disables SGI */
6705
  le16 msk = host_to_le16(HT_CAP_INFO_SHORT_GI20MHZ |
6706
        HT_CAP_INFO_SHORT_GI40MHZ);
6707
6708
  if (disabled)
6709
    wpa_msg(wpa_s, MSG_DEBUG, "set_disable_sgi: %d", disabled);
6710
6711
  if (disabled)
6712
    htcaps->ht_capabilities_info &= ~msk;
6713
  else
6714
    htcaps->ht_capabilities_info |= msk;
6715
6716
  htcaps_mask->ht_capabilities_info |= msk;
6717
6718
  return 0;
6719
}
6720
6721
6722
static int wpa_set_disable_ldpc(struct wpa_supplicant *wpa_s,
6723
             struct ieee80211_ht_capabilities *htcaps,
6724
             struct ieee80211_ht_capabilities *htcaps_mask,
6725
             int disabled)
6726
{
6727
  /* Masking these out disables LDPC */
6728
  le16 msk = host_to_le16(HT_CAP_INFO_LDPC_CODING_CAP);
6729
6730
  if (disabled)
6731
    wpa_msg(wpa_s, MSG_DEBUG, "set_disable_ldpc: %d", disabled);
6732
6733
  if (disabled)
6734
    htcaps->ht_capabilities_info &= ~msk;
6735
  else
6736
    htcaps->ht_capabilities_info |= msk;
6737
6738
  htcaps_mask->ht_capabilities_info |= msk;
6739
6740
  return 0;
6741
}
6742
6743
6744
static int wpa_set_tx_stbc(struct wpa_supplicant *wpa_s,
6745
         struct ieee80211_ht_capabilities *htcaps,
6746
         struct ieee80211_ht_capabilities *htcaps_mask,
6747
         int tx_stbc)
6748
{
6749
  le16 msk = host_to_le16(HT_CAP_INFO_TX_STBC);
6750
6751
  if (tx_stbc == -1)
6752
    return 0;
6753
6754
  wpa_msg(wpa_s, MSG_DEBUG, "set_tx_stbc: %d", tx_stbc);
6755
6756
  if (tx_stbc < 0 || tx_stbc > 1) {
6757
    wpa_msg(wpa_s, MSG_ERROR,
6758
      "tx_stbc: %d out of range. Must be 0-1 or -1", tx_stbc);
6759
    return -EINVAL;
6760
  }
6761
6762
  htcaps_mask->ht_capabilities_info |= msk;
6763
  htcaps->ht_capabilities_info &= ~msk;
6764
  htcaps->ht_capabilities_info |= host_to_le16(tx_stbc << 7) & msk;
6765
6766
  return 0;
6767
}
6768
6769
6770
static int wpa_set_rx_stbc(struct wpa_supplicant *wpa_s,
6771
         struct ieee80211_ht_capabilities *htcaps,
6772
         struct ieee80211_ht_capabilities *htcaps_mask,
6773
         int rx_stbc)
6774
{
6775
  le16 msk = host_to_le16(HT_CAP_INFO_RX_STBC_MASK);
6776
6777
  if (rx_stbc == -1)
6778
    return 0;
6779
6780
  wpa_msg(wpa_s, MSG_DEBUG, "set_rx_stbc: %d", rx_stbc);
6781
6782
  if (rx_stbc < 0 || rx_stbc > 3) {
6783
    wpa_msg(wpa_s, MSG_ERROR,
6784
      "rx_stbc: %d out of range. Must be 0-3 or -1", rx_stbc);
6785
    return -EINVAL;
6786
  }
6787
6788
  htcaps_mask->ht_capabilities_info |= msk;
6789
  htcaps->ht_capabilities_info &= ~msk;
6790
  htcaps->ht_capabilities_info |= host_to_le16(rx_stbc << 8) & msk;
6791
6792
  return 0;
6793
}
6794
6795
6796
void wpa_supplicant_apply_ht_overrides(
6797
  struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
6798
  struct wpa_driver_associate_params *params)
6799
{
6800
  struct ieee80211_ht_capabilities *htcaps;
6801
  struct ieee80211_ht_capabilities *htcaps_mask;
6802
6803
  if (!ssid)
6804
    return;
6805
6806
  params->disable_ht = ssid->disable_ht;
6807
  if (!params->htcaps || !params->htcaps_mask)
6808
    return;
6809
6810
  htcaps = (struct ieee80211_ht_capabilities *) params->htcaps;
6811
  htcaps_mask = (struct ieee80211_ht_capabilities *) params->htcaps_mask;
6812
  wpa_set_htcap_mcs(wpa_s, htcaps, htcaps_mask, ssid->ht_mcs);
6813
  wpa_disable_max_amsdu(wpa_s, htcaps, htcaps_mask,
6814
            ssid->disable_max_amsdu);
6815
  wpa_set_ampdu_factor(wpa_s, htcaps, htcaps_mask, ssid->ampdu_factor);
6816
  wpa_set_ampdu_density(wpa_s, htcaps, htcaps_mask, ssid->ampdu_density);
6817
  wpa_set_disable_ht40(wpa_s, htcaps, htcaps_mask, ssid->disable_ht40);
6818
  wpa_set_disable_sgi(wpa_s, htcaps, htcaps_mask, ssid->disable_sgi);
6819
  wpa_set_disable_ldpc(wpa_s, htcaps, htcaps_mask, ssid->disable_ldpc);
6820
  wpa_set_rx_stbc(wpa_s, htcaps, htcaps_mask, ssid->rx_stbc);
6821
  wpa_set_tx_stbc(wpa_s, htcaps, htcaps_mask, ssid->tx_stbc);
6822
6823
  if (ssid->ht40_intolerant) {
6824
    le16 bit = host_to_le16(HT_CAP_INFO_40MHZ_INTOLERANT);
6825
    htcaps->ht_capabilities_info |= bit;
6826
    htcaps_mask->ht_capabilities_info |= bit;
6827
  }
6828
}
6829
6830
#endif /* CONFIG_HT_OVERRIDES */
6831
6832
6833
#ifdef CONFIG_VHT_OVERRIDES
6834
void wpa_supplicant_apply_vht_overrides(
6835
  struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
6836
  struct wpa_driver_associate_params *params)
6837
{
6838
  struct ieee80211_vht_capabilities *vhtcaps;
6839
  struct ieee80211_vht_capabilities *vhtcaps_mask;
6840
6841
  if (!ssid)
6842
    return;
6843
6844
  params->disable_vht = ssid->disable_vht;
6845
6846
  vhtcaps = (void *) params->vhtcaps;
6847
  vhtcaps_mask = (void *) params->vhtcaps_mask;
6848
6849
  if (!vhtcaps || !vhtcaps_mask)
6850
    return;
6851
6852
  vhtcaps->vht_capabilities_info = host_to_le32(ssid->vht_capa);
6853
  vhtcaps_mask->vht_capabilities_info = host_to_le32(ssid->vht_capa_mask);
6854
6855
#ifdef CONFIG_HT_OVERRIDES
6856
  if (ssid->disable_sgi) {
6857
    vhtcaps_mask->vht_capabilities_info |=
6858
      host_to_le32(VHT_CAP_SHORT_GI_80 |
6859
             VHT_CAP_SHORT_GI_160);
6860
    vhtcaps->vht_capabilities_info &=
6861
      host_to_le32(~(VHT_CAP_SHORT_GI_80 |
6862
               VHT_CAP_SHORT_GI_160));
6863
    wpa_msg(wpa_s, MSG_DEBUG,
6864
      "disable-sgi override specified, vht-caps: 0x%x",
6865
      le_to_host32(vhtcaps->vht_capabilities_info));
6866
  }
6867
6868
  /* if max ampdu is <= 3, we have to make the HT cap the same */
6869
  if (ssid->vht_capa_mask & VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX) {
6870
    int max_ampdu;
6871
6872
    max_ampdu = (ssid->vht_capa &
6873
           VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX) >>
6874
      VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX_SHIFT;
6875
6876
    max_ampdu = max_ampdu < 3 ? max_ampdu : 3;
6877
    wpa_set_ampdu_factor(wpa_s,
6878
             (void *) params->htcaps,
6879
             (void *) params->htcaps_mask,
6880
             max_ampdu);
6881
  }
6882
#endif /* CONFIG_HT_OVERRIDES */
6883
6884
#define OVERRIDE_MCS(i)             \
6885
  if (ssid->vht_tx_mcs_nss_ ##i >= 0) {       \
6886
    vhtcaps_mask->vht_supported_mcs_set.tx_map |=   \
6887
      host_to_le16(3 << 2 * (i - 1));     \
6888
    vhtcaps->vht_supported_mcs_set.tx_map |=    \
6889
      host_to_le16(ssid->vht_tx_mcs_nss_ ##i << \
6890
             2 * (i - 1));      \
6891
  }               \
6892
  if (ssid->vht_rx_mcs_nss_ ##i >= 0) {       \
6893
    vhtcaps_mask->vht_supported_mcs_set.rx_map |=   \
6894
      host_to_le16(3 << 2 * (i - 1));     \
6895
    vhtcaps->vht_supported_mcs_set.rx_map |=    \
6896
      host_to_le16(ssid->vht_rx_mcs_nss_ ##i << \
6897
             2 * (i - 1));      \
6898
  }
6899
6900
  OVERRIDE_MCS(1);
6901
  OVERRIDE_MCS(2);
6902
  OVERRIDE_MCS(3);
6903
  OVERRIDE_MCS(4);
6904
  OVERRIDE_MCS(5);
6905
  OVERRIDE_MCS(6);
6906
  OVERRIDE_MCS(7);
6907
  OVERRIDE_MCS(8);
6908
}
6909
#endif /* CONFIG_VHT_OVERRIDES */
6910
6911
6912
#ifdef CONFIG_HE_OVERRIDES
6913
void wpa_supplicant_apply_he_overrides(
6914
  struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
6915
  struct wpa_driver_associate_params *params)
6916
{
6917
  if (!ssid)
6918
    return;
6919
6920
  params->disable_he = ssid->disable_he;
6921
}
6922
#endif /* CONFIG_HE_OVERRIDES */
6923
6924
6925
void wpa_supplicant_apply_eht_overrides(
6926
  struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
6927
  struct wpa_driver_associate_params *params)
6928
0
{
6929
0
  if (!ssid)
6930
0
    return;
6931
6932
0
  params->disable_eht = ssid->disable_eht;
6933
0
}
6934
6935
6936
void wpa_supplicant_apply_uhr_overrides(
6937
  struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
6938
  struct wpa_driver_associate_params *params)
6939
0
{
6940
0
  if (!ssid)
6941
0
    return;
6942
6943
0
  params->disable_uhr = ssid->disable_uhr;
6944
0
}
6945
6946
6947
static int pcsc_reader_init(struct wpa_supplicant *wpa_s)
6948
0
{
6949
#ifdef PCSC_FUNCS
6950
  size_t len;
6951
6952
  if (!wpa_s->conf->pcsc_reader)
6953
    return 0;
6954
6955
  wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
6956
  if (!wpa_s->scard)
6957
    return 1;
6958
6959
  if (wpa_s->conf->pcsc_pin &&
6960
      scard_set_pin(wpa_s->scard, wpa_s->conf->pcsc_pin) < 0) {
6961
    scard_deinit(wpa_s->scard);
6962
    wpa_s->scard = NULL;
6963
    wpa_msg(wpa_s, MSG_ERROR, "PC/SC PIN validation failed");
6964
    return -1;
6965
  }
6966
6967
  len = sizeof(wpa_s->imsi) - 1;
6968
  if (scard_get_imsi(wpa_s->scard, wpa_s->imsi, &len)) {
6969
    scard_deinit(wpa_s->scard);
6970
    wpa_s->scard = NULL;
6971
    wpa_msg(wpa_s, MSG_ERROR, "Could not read IMSI");
6972
    return -1;
6973
  }
6974
  wpa_s->imsi[len] = '\0';
6975
6976
  wpa_s->mnc_len = scard_get_mnc_len(wpa_s->scard);
6977
6978
  wpa_printf(MSG_DEBUG, "SCARD: IMSI %s (MNC length %d)",
6979
       wpa_s->imsi, wpa_s->mnc_len);
6980
6981
  wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
6982
  eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
6983
#endif /* PCSC_FUNCS */
6984
6985
0
  return 0;
6986
0
}
6987
6988
6989
int wpas_init_ext_pw(struct wpa_supplicant *wpa_s)
6990
0
{
6991
0
  char *val, *pos;
6992
6993
0
  ext_password_deinit(wpa_s->ext_pw);
6994
0
  wpa_s->ext_pw = NULL;
6995
0
  eapol_sm_set_ext_pw_ctx(wpa_s->eapol, NULL);
6996
6997
0
  if (!wpa_s->conf->ext_password_backend)
6998
0
    return 0;
6999
7000
0
  val = os_strdup(wpa_s->conf->ext_password_backend);
7001
0
  if (val == NULL)
7002
0
    return -1;
7003
0
  pos = os_strchr(val, ':');
7004
0
  if (pos)
7005
0
    *pos++ = '\0';
7006
7007
0
  wpa_printf(MSG_DEBUG, "EXT PW: Initialize backend '%s'", val);
7008
7009
0
  wpa_s->ext_pw = ext_password_init(val, pos);
7010
0
  os_free(val);
7011
0
  if (wpa_s->ext_pw == NULL) {
7012
0
    wpa_printf(MSG_DEBUG, "EXT PW: Failed to initialize backend");
7013
0
    return -1;
7014
0
  }
7015
0
  eapol_sm_set_ext_pw_ctx(wpa_s->eapol, wpa_s->ext_pw);
7016
7017
0
  return 0;
7018
0
}
7019
7020
7021
#ifdef CONFIG_FST
7022
7023
static const u8 * wpas_fst_get_bssid_cb(void *ctx)
7024
{
7025
  struct wpa_supplicant *wpa_s = ctx;
7026
7027
  return (is_zero_ether_addr(wpa_s->bssid) ||
7028
    wpa_s->wpa_state != WPA_COMPLETED) ? NULL : wpa_s->bssid;
7029
}
7030
7031
7032
static void wpas_fst_get_channel_info_cb(void *ctx,
7033
           enum hostapd_hw_mode *hw_mode,
7034
           u8 *channel)
7035
{
7036
  struct wpa_supplicant *wpa_s = ctx;
7037
7038
  if (wpa_s->current_bss) {
7039
    *hw_mode = ieee80211_freq_to_chan(wpa_s->current_bss->freq,
7040
              channel);
7041
  } else if (wpa_s->hw.num_modes) {
7042
    *hw_mode = wpa_s->hw.modes[0].mode;
7043
  } else {
7044
    WPA_ASSERT(0);
7045
    *hw_mode = 0;
7046
  }
7047
}
7048
7049
7050
static int wpas_fst_get_hw_modes(void *ctx, struct hostapd_hw_modes **modes)
7051
{
7052
  struct wpa_supplicant *wpa_s = ctx;
7053
7054
  *modes = wpa_s->hw.modes;
7055
  return wpa_s->hw.num_modes;
7056
}
7057
7058
7059
static void wpas_fst_set_ies_cb(void *ctx, const struct wpabuf *fst_ies)
7060
{
7061
  struct wpa_supplicant *wpa_s = ctx;
7062
7063
  wpa_hexdump_buf(MSG_DEBUG, "FST: Set IEs", fst_ies);
7064
  wpa_s->fst_ies = fst_ies;
7065
}
7066
7067
7068
static int wpas_fst_send_action_cb(void *ctx, const u8 *da, struct wpabuf *data)
7069
{
7070
  struct wpa_supplicant *wpa_s = ctx;
7071
7072
  if (!ether_addr_equal(wpa_s->bssid, da)) {
7073
    wpa_printf(MSG_INFO, "FST:%s:bssid=" MACSTR " != da=" MACSTR,
7074
         __func__, MAC2STR(wpa_s->bssid), MAC2STR(da));
7075
    return -1;
7076
  }
7077
  return wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
7078
           wpa_s->own_addr, wpa_s->bssid,
7079
           wpabuf_head(data), wpabuf_len(data),
7080
           0);
7081
}
7082
7083
7084
static const struct wpabuf * wpas_fst_get_mb_ie_cb(void *ctx, const u8 *addr)
7085
{
7086
  struct wpa_supplicant *wpa_s = ctx;
7087
7088
  WPA_ASSERT(ether_addr_equal(wpa_s->bssid, addr));
7089
  return wpa_s->received_mb_ies;
7090
}
7091
7092
7093
static void wpas_fst_update_mb_ie_cb(void *ctx, const u8 *addr,
7094
             const u8 *buf, size_t size)
7095
{
7096
  struct wpa_supplicant *wpa_s = ctx;
7097
  struct mb_ies_info info;
7098
7099
  WPA_ASSERT(ether_addr_equal(wpa_s->bssid, addr));
7100
7101
  if (!mb_ies_info_by_ies(&info, buf, size)) {
7102
    wpabuf_free(wpa_s->received_mb_ies);
7103
    wpa_s->received_mb_ies = mb_ies_by_info(&info);
7104
  }
7105
}
7106
7107
7108
static const u8 * wpas_fst_get_peer_first(void *ctx,
7109
            struct fst_get_peer_ctx **get_ctx,
7110
            bool mb_only)
7111
{
7112
  struct wpa_supplicant *wpa_s = ctx;
7113
7114
  *get_ctx = NULL;
7115
  if (!is_zero_ether_addr(wpa_s->bssid))
7116
    return (wpa_s->received_mb_ies || !mb_only) ?
7117
      wpa_s->bssid : NULL;
7118
  return NULL;
7119
}
7120
7121
7122
static const u8 * wpas_fst_get_peer_next(void *ctx,
7123
           struct fst_get_peer_ctx **get_ctx,
7124
           bool mb_only)
7125
{
7126
  return NULL;
7127
}
7128
7129
void fst_wpa_supplicant_fill_iface_obj(struct wpa_supplicant *wpa_s,
7130
               struct fst_wpa_obj *iface_obj)
7131
{
7132
  os_memset(iface_obj, 0, sizeof(*iface_obj));
7133
  iface_obj->ctx              = wpa_s;
7134
  iface_obj->get_bssid        = wpas_fst_get_bssid_cb;
7135
  iface_obj->get_channel_info = wpas_fst_get_channel_info_cb;
7136
  iface_obj->get_hw_modes     = wpas_fst_get_hw_modes;
7137
  iface_obj->set_ies          = wpas_fst_set_ies_cb;
7138
  iface_obj->send_action      = wpas_fst_send_action_cb;
7139
  iface_obj->get_mb_ie        = wpas_fst_get_mb_ie_cb;
7140
  iface_obj->update_mb_ie     = wpas_fst_update_mb_ie_cb;
7141
  iface_obj->get_peer_first   = wpas_fst_get_peer_first;
7142
  iface_obj->get_peer_next    = wpas_fst_get_peer_next;
7143
}
7144
#endif /* CONFIG_FST */
7145
7146
static int wpas_set_wowlan_triggers(struct wpa_supplicant *wpa_s,
7147
            const struct wpa_driver_capa *capa)
7148
0
{
7149
0
  struct wowlan_triggers *triggers;
7150
0
  int ret = 0;
7151
7152
0
  if (!wpa_s->conf->wowlan_triggers)
7153
0
    return 0;
7154
7155
0
  triggers = wpa_get_wowlan_triggers(wpa_s->conf->wowlan_triggers, capa);
7156
0
  if (triggers) {
7157
0
    ret = wpa_drv_wowlan(wpa_s, triggers);
7158
0
    os_free(triggers);
7159
0
  }
7160
0
  return ret;
7161
0
}
7162
7163
7164
enum wpa_radio_work_band wpas_freq_to_band(int freq)
7165
0
{
7166
0
  if (freq < 3000)
7167
0
    return BAND_2_4_GHZ;
7168
0
  if (freq > 50000)
7169
0
    return BAND_60_GHZ;
7170
0
  return BAND_5_GHZ;
7171
0
}
7172
7173
7174
unsigned int wpas_get_bands(struct wpa_supplicant *wpa_s, const int *freqs)
7175
0
{
7176
0
  int i;
7177
0
  unsigned int band = 0;
7178
7179
0
  if (freqs) {
7180
    /* freqs are specified for the radio work */
7181
0
    for (i = 0; freqs[i]; i++)
7182
0
      band |= wpas_freq_to_band(freqs[i]);
7183
0
  } else {
7184
    /*
7185
     * freqs are not specified, implies all
7186
     * the supported freqs by HW
7187
     */
7188
0
    for (i = 0; i < wpa_s->hw.num_modes; i++) {
7189
0
      if (wpa_s->hw.modes[i].num_channels != 0) {
7190
0
        if (wpa_s->hw.modes[i].mode ==
7191
0
            HOSTAPD_MODE_IEEE80211B ||
7192
0
            wpa_s->hw.modes[i].mode ==
7193
0
            HOSTAPD_MODE_IEEE80211G)
7194
0
          band |= BAND_2_4_GHZ;
7195
0
        else if (wpa_s->hw.modes[i].mode ==
7196
0
           HOSTAPD_MODE_IEEE80211A)
7197
0
          band |= BAND_5_GHZ;
7198
0
        else if (wpa_s->hw.modes[i].mode ==
7199
0
           HOSTAPD_MODE_IEEE80211AD)
7200
0
          band |= BAND_60_GHZ;
7201
0
        else if (wpa_s->hw.modes[i].mode ==
7202
0
           HOSTAPD_MODE_IEEE80211ANY)
7203
0
          band = BAND_2_4_GHZ | BAND_5_GHZ |
7204
0
            BAND_60_GHZ;
7205
0
      }
7206
0
    }
7207
0
  }
7208
7209
0
  return band;
7210
0
}
7211
7212
7213
static struct wpa_radio * radio_add_interface(struct wpa_supplicant *wpa_s,
7214
                const char *rn)
7215
0
{
7216
0
  struct wpa_supplicant *iface = wpa_s->global->ifaces;
7217
0
  struct wpa_radio *radio;
7218
7219
0
  while (rn && iface) {
7220
0
    radio = iface->radio;
7221
0
    if (radio && os_strcmp(rn, radio->name) == 0) {
7222
0
      wpa_printf(MSG_DEBUG, "Add interface %s to existing radio %s",
7223
0
           wpa_s->ifname, rn);
7224
0
      dl_list_add(&radio->ifaces, &wpa_s->radio_list);
7225
0
      return radio;
7226
0
    }
7227
7228
0
    iface = iface->next;
7229
0
  }
7230
7231
0
  wpa_printf(MSG_DEBUG, "Add interface %s to a new radio %s",
7232
0
       wpa_s->ifname, rn ? rn : "N/A");
7233
0
  radio = os_zalloc(sizeof(*radio));
7234
0
  if (radio == NULL)
7235
0
    return NULL;
7236
7237
0
  if (rn)
7238
0
    os_strlcpy(radio->name, rn, sizeof(radio->name));
7239
0
  dl_list_init(&radio->ifaces);
7240
0
  dl_list_init(&radio->work);
7241
0
  dl_list_add(&radio->ifaces, &wpa_s->radio_list);
7242
7243
0
  return radio;
7244
0
}
7245
7246
7247
static void radio_work_free(struct wpa_radio_work *work)
7248
0
{
7249
0
  if (work->wpa_s->scan_work == work) {
7250
    /* This should not really happen. */
7251
0
    wpa_dbg(work->wpa_s, MSG_INFO, "Freeing radio work '%s'@%p (started=%d) that is marked as scan_work",
7252
0
      work->type, work, work->started);
7253
0
    work->wpa_s->scan_work = NULL;
7254
0
  }
7255
7256
#ifdef CONFIG_P2P
7257
  if (work->wpa_s->p2p_scan_work == work) {
7258
    /* This should not really happen. */
7259
    wpa_dbg(work->wpa_s, MSG_INFO, "Freeing radio work '%s'@%p (started=%d) that is marked as p2p_scan_work",
7260
      work->type, work, work->started);
7261
    work->wpa_s->p2p_scan_work = NULL;
7262
  }
7263
#endif /* CONFIG_P2P */
7264
7265
0
  if (work->started) {
7266
0
    work->wpa_s->radio->num_active_works--;
7267
0
    wpa_dbg(work->wpa_s, MSG_DEBUG,
7268
0
      "radio_work_free('%s'@%p): num_active_works --> %u",
7269
0
      work->type, work,
7270
0
      work->wpa_s->radio->num_active_works);
7271
0
  }
7272
7273
0
  os_free(work);
7274
0
}
7275
7276
7277
static int radio_work_is_connect(struct wpa_radio_work *work)
7278
0
{
7279
0
  return os_strcmp(work->type, "sme-connect") == 0 ||
7280
0
    os_strcmp(work->type, "connect") == 0;
7281
0
}
7282
7283
7284
static int radio_work_is_scan(struct wpa_radio_work *work)
7285
0
{
7286
0
  return os_strcmp(work->type, "scan") == 0 ||
7287
0
    os_strcmp(work->type, "p2p-scan") == 0;
7288
0
}
7289
7290
7291
static struct wpa_radio_work * radio_work_get_next_work(struct wpa_radio *radio)
7292
0
{
7293
0
  struct wpa_radio_work *active_work = NULL;
7294
0
  struct wpa_radio_work *tmp;
7295
7296
  /* Get the active work to know the type and band. */
7297
0
  dl_list_for_each(tmp, &radio->work, struct wpa_radio_work, list) {
7298
0
    if (tmp->started) {
7299
0
      active_work = tmp;
7300
0
      break;
7301
0
    }
7302
0
  }
7303
7304
0
  if (!active_work) {
7305
    /* No active work, start one */
7306
0
    radio->num_active_works = 0;
7307
0
    dl_list_for_each(tmp, &radio->work, struct wpa_radio_work,
7308
0
         list) {
7309
0
      if (os_strcmp(tmp->type, "scan") == 0 &&
7310
0
          external_scan_running(radio) &&
7311
0
          (((struct wpa_driver_scan_params *)
7312
0
            tmp->ctx)->only_new_results ||
7313
0
           tmp->wpa_s->clear_driver_scan_cache))
7314
0
        continue;
7315
0
      return tmp;
7316
0
    }
7317
0
    return NULL;
7318
0
  }
7319
7320
0
  if (radio_work_is_connect(active_work)) {
7321
    /*
7322
     * If the active work is either connect or sme-connect,
7323
     * do not parallelize them with other radio works.
7324
     */
7325
0
    wpa_dbg(active_work->wpa_s, MSG_DEBUG,
7326
0
      "Do not parallelize radio work with %s",
7327
0
      active_work->type);
7328
0
    return NULL;
7329
0
  }
7330
7331
0
  dl_list_for_each(tmp, &radio->work, struct wpa_radio_work, list) {
7332
0
    if (tmp->started)
7333
0
      continue;
7334
7335
    /*
7336
     * If connect or sme-connect are enqueued, parallelize only
7337
     * those operations ahead of them in the queue.
7338
     */
7339
0
    if (radio_work_is_connect(tmp))
7340
0
      break;
7341
7342
    /* Serialize parallel scan and p2p_scan operations on the same
7343
     * interface since the driver_nl80211 mechanism for tracking
7344
     * scan cookies does not yet have support for this. */
7345
0
    if (active_work->wpa_s == tmp->wpa_s &&
7346
0
        radio_work_is_scan(active_work) &&
7347
0
        radio_work_is_scan(tmp)) {
7348
0
      wpa_dbg(active_work->wpa_s, MSG_DEBUG,
7349
0
        "Do not start work '%s' when another work '%s' is already scheduled",
7350
0
        tmp->type, active_work->type);
7351
0
      continue;
7352
0
    }
7353
    /*
7354
     * Check that the radio works are distinct and
7355
     * on different bands.
7356
     */
7357
0
    if (os_strcmp(active_work->type, tmp->type) != 0 &&
7358
0
        (active_work->bands != tmp->bands)) {
7359
      /*
7360
       * If a scan has to be scheduled through nl80211 scan
7361
       * interface and if an external scan is already running,
7362
       * do not schedule the scan since it is likely to get
7363
       * rejected by kernel.
7364
       */
7365
0
      if (os_strcmp(tmp->type, "scan") == 0 &&
7366
0
          external_scan_running(radio) &&
7367
0
          (((struct wpa_driver_scan_params *)
7368
0
            tmp->ctx)->only_new_results ||
7369
0
           tmp->wpa_s->clear_driver_scan_cache))
7370
0
        continue;
7371
7372
0
      wpa_dbg(active_work->wpa_s, MSG_DEBUG,
7373
0
        "active_work:%s new_work:%s",
7374
0
        active_work->type, tmp->type);
7375
0
      return tmp;
7376
0
    }
7377
0
  }
7378
7379
  /* Did not find a radio work to schedule in parallel. */
7380
0
  return NULL;
7381
0
}
7382
7383
7384
static void radio_start_next_work(void *eloop_ctx, void *timeout_ctx)
7385
0
{
7386
0
  struct wpa_radio *radio = eloop_ctx;
7387
0
  struct wpa_radio_work *work;
7388
0
  struct os_reltime now, diff;
7389
0
  struct wpa_supplicant *wpa_s;
7390
7391
0
  work = dl_list_first(&radio->work, struct wpa_radio_work, list);
7392
0
  if (work == NULL) {
7393
0
    radio->num_active_works = 0;
7394
0
    return;
7395
0
  }
7396
7397
0
  wpa_s = dl_list_first(&radio->ifaces, struct wpa_supplicant,
7398
0
            radio_list);
7399
7400
0
  if (!(wpa_s &&
7401
0
        wpa_s->drv_flags & WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS)) {
7402
0
    if (work->started)
7403
0
      return; /* already started and still in progress */
7404
7405
0
    if (wpa_s && external_scan_running(wpa_s->radio)) {
7406
0
      wpa_printf(MSG_DEBUG, "Delay radio work start until externally triggered scan completes");
7407
0
      return;
7408
0
    }
7409
0
  } else {
7410
0
    work = NULL;
7411
0
    if (radio->num_active_works < MAX_ACTIVE_WORKS) {
7412
      /* get the work to schedule next */
7413
0
      work = radio_work_get_next_work(radio);
7414
0
    }
7415
0
    if (!work)
7416
0
      return;
7417
0
  }
7418
7419
0
  wpa_s = work->wpa_s;
7420
0
  os_get_reltime(&now);
7421
0
  os_reltime_sub(&now, &work->time, &diff);
7422
0
  wpa_dbg(wpa_s, MSG_DEBUG,
7423
0
    "Starting radio work '%s'@%p after %ld.%06ld second wait",
7424
0
    work->type, work, diff.sec, diff.usec);
7425
0
  work->started = 1;
7426
0
  work->time = now;
7427
0
  radio->num_active_works++;
7428
7429
0
  work->cb(work, 0);
7430
7431
0
  if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS) &&
7432
0
      radio->num_active_works < MAX_ACTIVE_WORKS)
7433
0
    radio_work_check_next(wpa_s);
7434
0
}
7435
7436
7437
/*
7438
 * This function removes both started and pending radio works running on
7439
 * the provided interface's radio.
7440
 * Prior to the removal of the radio work, its callback (cb) is called with
7441
 * deinit set to be 1. Each work's callback is responsible for clearing its
7442
 * internal data and restoring to a correct state.
7443
 * @wpa_s: wpa_supplicant data
7444
 * @type: type of works to be removed
7445
 * @remove_all: 1 to remove all the works on this radio, 0 to remove only
7446
 * this interface's works.
7447
 */
7448
void radio_remove_works(struct wpa_supplicant *wpa_s,
7449
      const char *type, int remove_all)
7450
0
{
7451
0
  struct wpa_radio_work *work, *tmp;
7452
0
  struct wpa_radio *radio = wpa_s->radio;
7453
7454
0
  dl_list_for_each_safe(work, tmp, &radio->work, struct wpa_radio_work,
7455
0
            list) {
7456
0
    if (type && os_strcmp(type, work->type) != 0)
7457
0
      continue;
7458
7459
    /* skip other ifaces' works */
7460
0
    if (!remove_all && work->wpa_s != wpa_s)
7461
0
      continue;
7462
7463
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Remove radio work '%s'@%p%s",
7464
0
      work->type, work, work->started ? " (started)" : "");
7465
0
    dl_list_del(&work->list);
7466
0
    work->cb(work, 1);
7467
0
    radio_work_free(work);
7468
0
  }
7469
7470
  /* in case we removed the started work */
7471
0
  radio_work_check_next(wpa_s);
7472
0
}
7473
7474
7475
static void radio_remove_pending_connect(struct wpa_supplicant *wpa_s,
7476
           const struct wpa_ssid *ssid)
7477
0
{
7478
0
  struct wpa_radio_work *work, *tmp;
7479
0
  struct wpa_radio *radio = wpa_s->radio;
7480
0
  struct wpa_connect_work *cwork;
7481
7482
0
  dl_list_for_each_safe(work, tmp, &radio->work, struct wpa_radio_work,
7483
0
            list) {
7484
0
    if (!radio_work_is_connect(work))
7485
0
      continue;
7486
7487
0
    cwork = work->ctx;
7488
0
    if (cwork->ssid != ssid)
7489
0
      continue;
7490
7491
0
    wpa_printf(MSG_DEBUG, "Remove radio work '%s'@%p ssid=%s",
7492
0
         work->type, work,
7493
0
         wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
7494
0
    dl_list_del(&work->list);
7495
0
    work->cb(work, 1);
7496
0
    radio_work_free(work);
7497
0
  }
7498
0
}
7499
7500
7501
static void radio_remove_interface(struct wpa_supplicant *wpa_s)
7502
0
{
7503
0
  struct wpa_radio *radio = wpa_s->radio;
7504
7505
0
  if (!radio)
7506
0
    return;
7507
7508
0
  wpa_printf(MSG_DEBUG, "Remove interface %s from radio %s",
7509
0
       wpa_s->ifname, radio->name);
7510
0
  dl_list_del(&wpa_s->radio_list);
7511
0
  radio_remove_works(wpa_s, NULL, 0);
7512
  /* If the interface that triggered the external scan was removed, the
7513
   * external scan is no longer running. */
7514
0
  if (wpa_s == radio->external_scan_req_interface)
7515
0
    radio->external_scan_req_interface = NULL;
7516
0
  wpa_s->radio = NULL;
7517
0
  if (!dl_list_empty(&radio->ifaces))
7518
0
    return; /* Interfaces remain for this radio */
7519
7520
0
  wpa_printf(MSG_DEBUG, "Remove radio %s", radio->name);
7521
0
  eloop_cancel_timeout(radio_start_next_work, radio, NULL);
7522
0
  os_free(radio);
7523
0
}
7524
7525
7526
void radio_work_check_next(struct wpa_supplicant *wpa_s)
7527
0
{
7528
0
  struct wpa_radio *radio = wpa_s->radio;
7529
7530
0
  if (dl_list_empty(&radio->work))
7531
0
    return;
7532
0
  if (wpa_s->ext_work_in_progress) {
7533
0
    wpa_printf(MSG_DEBUG,
7534
0
         "External radio work in progress - delay start of pending item");
7535
0
    return;
7536
0
  }
7537
0
  eloop_cancel_timeout(radio_start_next_work, radio, NULL);
7538
0
  eloop_register_timeout(0, 0, radio_start_next_work, radio, NULL);
7539
0
}
7540
7541
7542
/**
7543
 * radio_add_work - Add a radio work item
7544
 * @wpa_s: Pointer to wpa_supplicant data
7545
 * @freq: Frequency of the offchannel operation in MHz or 0
7546
 * @type: Unique identifier for each type of work
7547
 * @next: Force as the next work to be executed
7548
 * @cb: Callback function for indicating when radio is available
7549
 * @ctx: Context pointer for the work (work->ctx in cb())
7550
 * Returns: Pointer to the newly created work, or %NULL on failure
7551
 *
7552
 * This function is used to request time for an operation that requires
7553
 * exclusive radio control. Once the radio is available, the registered callback
7554
 * function will be called. radio_work_done() must be called once the exclusive
7555
 * radio operation has been completed, so that the radio is freed for other
7556
 * operations. The special case of deinit=1 is used to free the context data
7557
 * during interface removal. That does not allow the callback function to start
7558
 * the radio operation, i.e., it must free any resources allocated for the radio
7559
 * work and return.
7560
 *
7561
 * The @freq parameter can be used to indicate a single channel on which the
7562
 * offchannel operation will occur. This may allow multiple radio work
7563
 * operations to be performed in parallel if they apply for the same channel.
7564
 * Setting this to 0 indicates that the work item may use multiple channels or
7565
 * requires exclusive control of the radio.
7566
 */
7567
struct wpa_radio_work *
7568
radio_add_work(struct wpa_supplicant *wpa_s, unsigned int freq,
7569
         const char *type, int next,
7570
         void (*cb)(struct wpa_radio_work *work, int deinit),
7571
         void *ctx)
7572
0
{
7573
0
  struct wpa_radio *radio = wpa_s->radio;
7574
0
  struct wpa_radio_work *work;
7575
0
  int was_empty;
7576
7577
0
  work = os_zalloc(sizeof(*work));
7578
0
  if (work == NULL)
7579
0
    return NULL;
7580
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Add radio work '%s'@%p", type, work);
7581
0
  os_get_reltime(&work->time);
7582
0
  work->freq = freq;
7583
0
  work->type = type;
7584
0
  work->wpa_s = wpa_s;
7585
0
  work->cb = cb;
7586
0
  work->ctx = ctx;
7587
7588
0
  if (freq)
7589
0
    work->bands = wpas_freq_to_band(freq);
7590
0
  else if (os_strcmp(type, "scan") == 0 ||
7591
0
     os_strcmp(type, "p2p-scan") == 0)
7592
0
    work->bands = wpas_get_bands(wpa_s,
7593
0
               ((struct wpa_driver_scan_params *)
7594
0
                ctx)->freqs);
7595
0
  else
7596
0
    work->bands = wpas_get_bands(wpa_s, NULL);
7597
7598
0
  was_empty = dl_list_empty(&wpa_s->radio->work);
7599
0
  if (next)
7600
0
    dl_list_add(&wpa_s->radio->work, &work->list);
7601
0
  else
7602
0
    dl_list_add_tail(&wpa_s->radio->work, &work->list);
7603
0
  if (was_empty) {
7604
0
    wpa_dbg(wpa_s, MSG_DEBUG, "First radio work item in the queue - schedule start immediately");
7605
0
    radio_work_check_next(wpa_s);
7606
0
  } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_OFFCHANNEL_SIMULTANEOUS)
7607
0
       && radio->num_active_works < MAX_ACTIVE_WORKS) {
7608
0
    wpa_dbg(wpa_s, MSG_DEBUG,
7609
0
      "Try to schedule a radio work (num_active_works=%u)",
7610
0
      radio->num_active_works);
7611
0
    radio_work_check_next(wpa_s);
7612
0
  }
7613
7614
0
  return work;
7615
0
}
7616
7617
7618
/**
7619
 * radio_work_done - Indicate that a radio work item has been completed
7620
 * @work: Completed work
7621
 *
7622
 * This function is called once the callback function registered with
7623
 * radio_add_work() has completed its work.
7624
 */
7625
void radio_work_done(struct wpa_radio_work *work)
7626
0
{
7627
0
  struct wpa_supplicant *wpa_s = work->wpa_s;
7628
0
  struct os_reltime now, diff;
7629
0
  unsigned int started = work->started;
7630
7631
  /* If next is poisoned, then we are free'ing it already */
7632
0
  if (work->list.next == NULL)
7633
0
    return;
7634
7635
0
  os_get_reltime(&now);
7636
0
  os_reltime_sub(&now, &work->time, &diff);
7637
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Radio work '%s'@%p %s in %ld.%06ld seconds",
7638
0
    work->type, work, started ? "done" : "canceled",
7639
0
    diff.sec, diff.usec);
7640
0
  dl_list_del(&work->list);
7641
0
  radio_work_free(work);
7642
0
  if (started)
7643
0
    radio_work_check_next(wpa_s);
7644
0
}
7645
7646
7647
struct wpa_radio_work *
7648
radio_work_pending(struct wpa_supplicant *wpa_s, const char *type)
7649
0
{
7650
0
  struct wpa_radio_work *work;
7651
0
  struct wpa_radio *radio = wpa_s->radio;
7652
7653
0
  dl_list_for_each(work, &radio->work, struct wpa_radio_work, list) {
7654
0
    if (work->wpa_s == wpa_s && os_strcmp(work->type, type) == 0)
7655
0
      return work;
7656
0
  }
7657
7658
0
  return NULL;
7659
0
}
7660
7661
7662
static int wpas_init_driver(struct wpa_supplicant *wpa_s,
7663
          const struct wpa_interface *iface)
7664
0
{
7665
0
  const char *ifname, *driver, *rn;
7666
7667
0
  driver = iface->driver;
7668
0
next_driver:
7669
0
  if (wpa_supplicant_set_driver(wpa_s, driver) < 0)
7670
0
    return -1;
7671
7672
0
  wpa_s->drv_priv = wpa_drv_init(wpa_s, wpa_s->ifname);
7673
0
  if (wpa_s->drv_priv == NULL) {
7674
0
    const char *pos;
7675
0
    int level = MSG_ERROR;
7676
7677
0
    pos = driver ? os_strchr(driver, ',') : NULL;
7678
0
    if (pos) {
7679
0
      wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize "
7680
0
        "driver interface - try next driver wrapper");
7681
0
      driver = pos + 1;
7682
0
      goto next_driver;
7683
0
    }
7684
7685
#ifdef CONFIG_MATCH_IFACE
7686
    if (wpa_s->matched == WPA_IFACE_MATCHED_NULL)
7687
      level = MSG_DEBUG;
7688
#endif /* CONFIG_MATCH_IFACE */
7689
0
    wpa_msg(wpa_s, level, "Failed to initialize driver interface");
7690
0
    return -1;
7691
0
  }
7692
0
  if (wpa_drv_set_param(wpa_s, wpa_s->conf->driver_param) < 0) {
7693
0
    wpa_msg(wpa_s, MSG_ERROR, "Driver interface rejected "
7694
0
      "driver_param '%s'", wpa_s->conf->driver_param);
7695
0
    return -1;
7696
0
  }
7697
7698
0
  ifname = wpa_drv_get_ifname(wpa_s);
7699
0
  if (ifname && os_strcmp(ifname, wpa_s->ifname) != 0) {
7700
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Driver interface replaced "
7701
0
      "interface name with '%s'", ifname);
7702
0
    os_strlcpy(wpa_s->ifname, ifname, sizeof(wpa_s->ifname));
7703
0
  }
7704
7705
0
  rn = wpa_driver_get_radio_name(wpa_s);
7706
0
  if (rn && rn[0] == '\0')
7707
0
    rn = NULL;
7708
7709
0
  wpa_s->radio = radio_add_interface(wpa_s, rn);
7710
0
  if (wpa_s->radio == NULL)
7711
0
    return -1;
7712
7713
0
  return 0;
7714
0
}
7715
7716
7717
#ifdef CONFIG_GAS_SERVER
7718
7719
static void wpas_gas_server_tx_status(struct wpa_supplicant *wpa_s,
7720
              unsigned int freq, const u8 *dst,
7721
              const u8 *src, const u8 *bssid,
7722
              const u8 *data, size_t data_len,
7723
              enum offchannel_send_action_result result)
7724
{
7725
  wpa_printf(MSG_DEBUG, "GAS: TX status: freq=%u dst=" MACSTR
7726
       " result=%s",
7727
       freq, MAC2STR(dst),
7728
       result == OFFCHANNEL_SEND_ACTION_SUCCESS ? "SUCCESS" :
7729
       (result == OFFCHANNEL_SEND_ACTION_NO_ACK ? "no-ACK" :
7730
        "FAILED"));
7731
  gas_server_tx_status(wpa_s->gas_server, dst, data, data_len,
7732
           result == OFFCHANNEL_SEND_ACTION_SUCCESS);
7733
}
7734
7735
7736
static void wpas_gas_server_tx(void *ctx, int freq, const u8 *da,
7737
             struct wpabuf *buf, unsigned int wait_time)
7738
{
7739
  struct wpa_supplicant *wpa_s = ctx;
7740
  const u8 broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
7741
7742
  if (wait_time > wpa_s->max_remain_on_chan)
7743
    wait_time = wpa_s->max_remain_on_chan;
7744
7745
  offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, broadcast,
7746
             wpabuf_head(buf), wpabuf_len(buf),
7747
             wait_time, wpas_gas_server_tx_status, 0);
7748
}
7749
7750
#endif /* CONFIG_GAS_SERVER */
7751
7752
static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s,
7753
             const struct wpa_interface *iface)
7754
0
{
7755
0
  struct wpa_driver_capa capa;
7756
0
  int capa_res;
7757
0
  u8 dfs_domain;
7758
7759
0
  wpa_printf(MSG_DEBUG, "Initializing interface '%s' conf '%s' driver "
7760
0
       "'%s' ctrl_interface '%s' bridge '%s'", iface->ifname,
7761
0
       iface->confname ? iface->confname : "N/A",
7762
0
       iface->driver ? iface->driver : "default",
7763
0
       iface->ctrl_interface ? iface->ctrl_interface : "N/A",
7764
0
       iface->bridge_ifname ? iface->bridge_ifname : "N/A");
7765
7766
0
  if (iface->confname) {
7767
#ifdef CONFIG_BACKEND_FILE
7768
    wpa_s->confname = os_rel2abs_path(iface->confname);
7769
    if (wpa_s->confname == NULL) {
7770
      wpa_printf(MSG_ERROR, "Failed to get absolute path "
7771
           "for configuration file '%s'.",
7772
           iface->confname);
7773
      return -1;
7774
    }
7775
    wpa_printf(MSG_DEBUG, "Configuration file '%s' -> '%s'",
7776
         iface->confname, wpa_s->confname);
7777
#else /* CONFIG_BACKEND_FILE */
7778
0
    wpa_s->confname = os_strdup(iface->confname);
7779
0
#endif /* CONFIG_BACKEND_FILE */
7780
0
    wpa_s->conf = wpa_config_read(
7781
0
      wpa_s->confname, NULL, false,
7782
0
      wpa_s->global->params.show_details);
7783
0
    if (wpa_s->conf == NULL) {
7784
0
      wpa_printf(MSG_ERROR, "Failed to read or parse "
7785
0
           "configuration '%s'.", wpa_s->confname);
7786
0
      return -1;
7787
0
    }
7788
0
    wpa_s->confanother = os_rel2abs_path(iface->confanother);
7789
0
    if (wpa_s->confanother &&
7790
0
        !wpa_config_read(wpa_s->confanother, wpa_s->conf, true,
7791
0
             wpa_s->global->params.show_details)) {
7792
0
      wpa_printf(MSG_ERROR,
7793
0
           "Failed to read or parse configuration '%s'.",
7794
0
           wpa_s->confanother);
7795
0
      return -1;
7796
0
    }
7797
7798
    /*
7799
     * Override ctrl_interface and driver_param if set on command
7800
     * line.
7801
     */
7802
0
    if (iface->ctrl_interface) {
7803
0
      os_free(wpa_s->conf->ctrl_interface);
7804
0
      wpa_s->conf->ctrl_interface =
7805
0
        os_strdup(iface->ctrl_interface);
7806
0
      if (!wpa_s->conf->ctrl_interface) {
7807
0
        wpa_printf(MSG_ERROR,
7808
0
             "Failed to duplicate control interface '%s'.",
7809
0
             iface->ctrl_interface);
7810
0
        return -1;
7811
0
      }
7812
0
    }
7813
7814
0
    if (iface->driver_param) {
7815
0
      os_free(wpa_s->conf->driver_param);
7816
0
      wpa_s->conf->driver_param =
7817
0
        os_strdup(iface->driver_param);
7818
0
      if (!wpa_s->conf->driver_param) {
7819
0
        wpa_printf(MSG_ERROR,
7820
0
             "Failed to duplicate driver param '%s'.",
7821
0
             iface->driver_param);
7822
0
        return -1;
7823
0
      }
7824
0
    }
7825
7826
0
    if (iface->p2p_mgmt && !iface->ctrl_interface) {
7827
0
      os_free(wpa_s->conf->ctrl_interface);
7828
0
      wpa_s->conf->ctrl_interface = NULL;
7829
0
    }
7830
0
  } else
7831
0
    wpa_s->conf = wpa_config_alloc_empty(iface->ctrl_interface,
7832
0
                 iface->driver_param);
7833
7834
0
  if (wpa_s->conf == NULL) {
7835
0
    wpa_printf(MSG_ERROR, "\nNo configuration found.");
7836
0
    return -1;
7837
0
  }
7838
7839
0
  if (iface->ifname == NULL) {
7840
0
    wpa_printf(MSG_ERROR, "\nInterface name is required.");
7841
0
    return -1;
7842
0
  }
7843
0
  if (os_strlen(iface->ifname) >= sizeof(wpa_s->ifname)) {
7844
0
    wpa_printf(MSG_ERROR, "\nToo long interface name '%s'.",
7845
0
         iface->ifname);
7846
0
    return -1;
7847
0
  }
7848
0
  os_strlcpy(wpa_s->ifname, iface->ifname, sizeof(wpa_s->ifname));
7849
#ifdef CONFIG_MATCH_IFACE
7850
  wpa_s->matched = iface->matched;
7851
#endif /* CONFIG_MATCH_IFACE */
7852
7853
0
  if (iface->bridge_ifname) {
7854
0
    if (os_strlen(iface->bridge_ifname) >=
7855
0
        sizeof(wpa_s->bridge_ifname)) {
7856
0
      wpa_printf(MSG_ERROR, "\nToo long bridge interface "
7857
0
           "name '%s'.", iface->bridge_ifname);
7858
0
      return -1;
7859
0
    }
7860
0
    os_strlcpy(wpa_s->bridge_ifname, iface->bridge_ifname,
7861
0
         sizeof(wpa_s->bridge_ifname));
7862
0
  }
7863
7864
  /* RSNA Supplicant Key Management - INITIALIZE */
7865
0
  eapol_sm_notify_portEnabled(wpa_s->eapol, false);
7866
0
  eapol_sm_notify_portValid(wpa_s->eapol, false);
7867
7868
  /* Initialize driver interface and register driver event handler before
7869
   * L2 receive handler so that association events are processed before
7870
   * EAPOL-Key packets if both become available for the same select()
7871
   * call. */
7872
0
  if (wpas_init_driver(wpa_s, iface) < 0)
7873
0
    return -1;
7874
7875
0
  if (wpa_supplicant_init_wpa(wpa_s) < 0)
7876
0
    return -1;
7877
7878
0
  wpa_sm_set_ifname(wpa_s->wpa, wpa_s->ifname,
7879
0
        wpa_s->bridge_ifname[0] ? wpa_s->bridge_ifname :
7880
0
        NULL);
7881
0
  wpa_sm_set_fast_reauth(wpa_s->wpa, wpa_s->conf->fast_reauth);
7882
7883
0
  if (wpa_s->conf->dot11RSNAConfigPMKLifetime &&
7884
0
      wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
7885
0
           wpa_s->conf->dot11RSNAConfigPMKLifetime)) {
7886
0
    wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for "
7887
0
      "dot11RSNAConfigPMKLifetime");
7888
0
    return -1;
7889
0
  }
7890
7891
0
  if (wpa_s->conf->dot11RSNAConfigPMKReauthThreshold &&
7892
0
      wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
7893
0
           wpa_s->conf->dot11RSNAConfigPMKReauthThreshold)) {
7894
0
    wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for "
7895
0
      "dot11RSNAConfigPMKReauthThreshold");
7896
0
    return -1;
7897
0
  }
7898
7899
0
  if (wpa_s->conf->dot11RSNAConfigSATimeout &&
7900
0
      wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT,
7901
0
           wpa_s->conf->dot11RSNAConfigSATimeout)) {
7902
0
    wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for "
7903
0
      "dot11RSNAConfigSATimeout");
7904
0
    return -1;
7905
0
  }
7906
7907
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_FT_PREPEND_PMKID,
7908
0
       wpa_s->conf->ft_prepend_pmkid);
7909
7910
0
  wpa_s->hw.modes = wpa_drv_get_hw_feature_data(wpa_s,
7911
0
                  &wpa_s->hw.num_modes,
7912
0
                  &wpa_s->hw.flags,
7913
0
                  &dfs_domain);
7914
0
  wpa_s->hw_dfs_domain = dfs_domain;
7915
0
  if (wpa_s->hw.modes) {
7916
0
    u16 i;
7917
7918
0
    for (i = 0; i < wpa_s->hw.num_modes; i++) {
7919
0
      if (wpa_s->hw.modes[i].eht_capab[IEEE80211_MODE_INFRA].
7920
0
          eht_supported)
7921
0
        wpa_s->hw_capab |= BIT(CAPAB_EHT);
7922
0
      if (wpa_s->hw.modes[i].he_capab[IEEE80211_MODE_INFRA].
7923
0
          he_supported)
7924
0
        wpa_s->hw_capab |= BIT(CAPAB_HE);
7925
0
      if (wpa_s->hw.modes[i].vht_capab)
7926
0
        wpa_s->hw_capab |= BIT(CAPAB_VHT);
7927
0
      if (wpa_s->hw.modes[i].ht_capab)
7928
0
        wpa_s->hw_capab |= BIT(CAPAB_HT);
7929
0
    }
7930
0
    wpa_s->support_6ghz = wpas_is_6ghz_supported(wpa_s, false);
7931
0
  }
7932
7933
0
  capa_res = wpa_drv_get_capa(wpa_s, &capa);
7934
0
  if (capa_res == 0) {
7935
0
    u16 eml_capa, mld_capa;
7936
7937
0
    wpa_s->drv_capa_known = 1;
7938
0
    wpa_s->drv_flags = capa.flags;
7939
0
    wpa_s->drv_flags2 = capa.flags2;
7940
0
    wpa_s->drv_enc = capa.enc;
7941
0
    wpa_s->drv_key_mgmt = capa.key_mgmt;
7942
0
    wpa_s->drv_rrm_flags = capa.rrm_flags;
7943
0
    wpa_s->drv_max_acl_mac_addrs = capa.max_acl_mac_addrs;
7944
0
    wpa_s->probe_resp_offloads = capa.probe_resp_offloads;
7945
0
    wpa_s->max_scan_ssids = capa.max_scan_ssids;
7946
0
    wpa_s->max_sched_scan_ssids = capa.max_sched_scan_ssids;
7947
0
    wpa_s->max_sched_scan_plans = capa.max_sched_scan_plans;
7948
0
    wpa_s->max_sched_scan_plan_interval =
7949
0
      capa.max_sched_scan_plan_interval;
7950
0
    wpa_s->max_sched_scan_plan_iterations =
7951
0
      capa.max_sched_scan_plan_iterations;
7952
0
    wpa_s->sched_scan_supported = capa.sched_scan_supported;
7953
0
    wpa_s->max_match_sets = capa.max_match_sets;
7954
0
    wpa_s->max_remain_on_chan = capa.max_remain_on_chan;
7955
0
    wpa_s->max_stations = capa.max_stations;
7956
0
    wpa_s->extended_capa = capa.extended_capa;
7957
0
    wpa_s->extended_capa_mask = capa.extended_capa_mask;
7958
0
    wpa_s->extended_capa_len = capa.extended_capa_len;
7959
0
    wpa_s->num_multichan_concurrent =
7960
0
      capa.num_multichan_concurrent;
7961
0
#ifndef CONFIG_NO_WMM_AC
7962
0
    wpa_s->wmm_ac_supported = capa.wmm_ac_supported;
7963
0
#endif /* CONFIG_NO_WMM_AC */
7964
0
    wpa_s->max_num_akms = capa.max_num_akms;
7965
7966
0
    if (capa.mac_addr_rand_scan_supported)
7967
0
      wpa_s->mac_addr_rand_supported |= MAC_ADDR_RAND_SCAN;
7968
0
    if (wpa_s->sched_scan_supported &&
7969
0
        capa.mac_addr_rand_sched_scan_supported)
7970
0
      wpa_s->mac_addr_rand_supported |=
7971
0
        (MAC_ADDR_RAND_SCHED_SCAN | MAC_ADDR_RAND_PNO);
7972
0
    wpa_s->drv_max_probe_req_ie_len = capa.max_probe_req_ie_len;
7973
7974
0
    wpa_drv_get_ext_capa(wpa_s, WPA_IF_STATION);
7975
0
    if (wpa_s->extended_capa &&
7976
0
        wpa_s->extended_capa_len >= 3 &&
7977
0
        wpa_s->extended_capa[2] & 0x40)
7978
0
      wpa_s->multi_bss_support = 1;
7979
7980
0
    if (wpa_drv_get_mld_capa(wpa_s, WPA_IF_STATION,
7981
0
           &eml_capa, &mld_capa) == 0) {
7982
0
      wpa_s->eml_capa = eml_capa;
7983
0
      wpa_s->mld_capa = mld_capa;
7984
0
    }
7985
0
  } else {
7986
0
    wpa_s->drv_max_probe_req_ie_len = 1500;
7987
0
  }
7988
#ifdef CONFIG_PASN
7989
  wpa_pasn_sm_set_caps(wpa_s->wpa, wpa_s->drv_flags2);
7990
#endif /* CONFIG_PASN */
7991
7992
#ifdef CONFIG_IEEE8021X_AUTH
7993
  wpa_sm_set_802_1x_auth_caps(wpa_s->wpa, wpa_s->drv_flags2);
7994
#endif /* CONFIG_IEEE8021X_AUTH */
7995
7996
0
  wpa_sm_set_driver_bss_selection(wpa_s->wpa,
7997
0
          !!(wpa_s->drv_flags &
7998
0
             WPA_DRIVER_FLAGS_BSS_SELECTION));
7999
0
  if (wpa_s->max_remain_on_chan == 0)
8000
0
    wpa_s->max_remain_on_chan = 1000;
8001
8002
  /*
8003
   * Only take p2p_mgmt parameters when P2P Device is supported.
8004
   * Doing it here as it determines whether l2_packet_init() will be done
8005
   * during wpa_supplicant_driver_init().
8006
   */
8007
0
  if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)
8008
0
    wpa_s->p2p_mgmt = iface->p2p_mgmt;
8009
8010
0
  wpa_s->nan_mgmt = iface->nan_mgmt;
8011
0
  wpa_s->nan_data = iface->nan_data;
8012
8013
0
  if ((wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_P2P_ASSISTED_DFS) &&
8014
0
      wpa_s->conf->p2p_assisted_dfs_chan_enable)
8015
0
    wpa_s->allow_p2p_assisted_dfs = true;
8016
8017
0
  if (wpa_s->num_multichan_concurrent == 0)
8018
0
    wpa_s->num_multichan_concurrent = 1;
8019
8020
0
  if (wpa_supplicant_driver_init(wpa_s) < 0)
8021
0
    return -1;
8022
8023
#ifdef CONFIG_TDLS
8024
  if (!iface->p2p_mgmt && !iface->nan_mgmt && wpa_tdls_init(wpa_s->wpa))
8025
    return -1;
8026
#endif /* CONFIG_TDLS */
8027
8028
0
  if (wpa_s->conf->country[0] && wpa_s->conf->country[1] &&
8029
0
      wpa_drv_set_country(wpa_s, wpa_s->conf->country)) {
8030
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Failed to set country");
8031
0
    return -1;
8032
0
  }
8033
8034
#ifdef CONFIG_FST
8035
  if (wpa_s->conf->fst_group_id) {
8036
    struct fst_iface_cfg cfg;
8037
    struct fst_wpa_obj iface_obj;
8038
8039
    fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj);
8040
    os_strlcpy(cfg.group_id, wpa_s->conf->fst_group_id,
8041
         sizeof(cfg.group_id));
8042
    cfg.priority = wpa_s->conf->fst_priority;
8043
    cfg.llt = wpa_s->conf->fst_llt;
8044
8045
    wpa_s->fst = fst_attach(wpa_s->ifname, wpa_s->own_addr,
8046
          &iface_obj, &cfg);
8047
    if (!wpa_s->fst) {
8048
      wpa_msg(wpa_s, MSG_ERROR,
8049
        "FST: Cannot attach iface %s to group %s",
8050
        wpa_s->ifname, cfg.group_id);
8051
      return -1;
8052
    }
8053
  }
8054
#endif /* CONFIG_FST */
8055
8056
0
  if (wpas_wps_init(wpa_s))
8057
0
    return -1;
8058
8059
#ifdef CONFIG_GAS_SERVER
8060
  wpa_s->gas_server = gas_server_init(wpa_s, wpas_gas_server_tx);
8061
  if (!wpa_s->gas_server) {
8062
    wpa_printf(MSG_ERROR, "Failed to initialize GAS server");
8063
    return -1;
8064
  }
8065
#endif /* CONFIG_GAS_SERVER */
8066
8067
#ifdef CONFIG_DPP
8068
  if (wpas_dpp_init(wpa_s) < 0)
8069
    return -1;
8070
#endif /* CONFIG_DPP */
8071
8072
0
  if (wpas_nan_de_init(wpa_s) < 0)
8073
0
    return -1;
8074
8075
#ifdef CONFIG_NAN
8076
  os_memcpy(&wpa_s->nan_capa, &capa.nan_capa,
8077
      sizeof(wpa_s->nan_capa));
8078
#endif /* CONFIG_NAN */
8079
8080
0
  if (wpa_supplicant_init_eapol(wpa_s) < 0)
8081
0
    return -1;
8082
0
  wpa_sm_set_eapol(wpa_s->wpa, wpa_s->eapol);
8083
8084
0
  wpa_s->ctrl_iface = wpa_supplicant_ctrl_iface_init(wpa_s);
8085
0
  if (wpa_s->ctrl_iface == NULL) {
8086
0
    wpa_printf(MSG_ERROR,
8087
0
         "Failed to initialize control interface '%s'.\n"
8088
0
         "You may have another wpa_supplicant process "
8089
0
         "already running or the file was\n"
8090
0
         "left by an unclean termination of wpa_supplicant "
8091
0
         "in which case you will need\n"
8092
0
         "to manually remove this file before starting "
8093
0
         "wpa_supplicant again.\n",
8094
0
         wpa_s->conf->ctrl_interface);
8095
0
    return -1;
8096
0
  }
8097
8098
0
  wpa_s->gas = gas_query_init(wpa_s);
8099
0
  if (wpa_s->gas == NULL) {
8100
0
    wpa_printf(MSG_ERROR, "Failed to initialize GAS query");
8101
0
    return -1;
8102
0
  }
8103
8104
#ifdef CONFIG_P2P
8105
  if (wpa_s->drv_flags2 & (WPA_DRIVER_FLAGS2_P2P_FEATURE_V2 |
8106
         WPA_DRIVER_FLAGS2_P2P_FEATURE_PCC_MODE)) {
8107
    wpa_s->p2p_pairing_setup = true;
8108
    wpa_s->p2p_pairing_cache = true;
8109
  }
8110
#endif /* CONFIG_P2P */
8111
8112
0
  if ((!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) ||
8113
0
       wpa_s->p2p_mgmt) &&
8114
0
      wpas_p2p_init(wpa_s->global, wpa_s) < 0) {
8115
0
    wpa_msg(wpa_s, MSG_ERROR, "Failed to init P2P");
8116
0
    return -1;
8117
0
  }
8118
8119
0
  if (!capa.ranging_type.pd_support) {
8120
0
    wpa_printf(MSG_DEBUG,
8121
0
         "PR: Driver does not support Proximity Ranging - PR disabled");
8122
0
  } else if (wpas_pr_init(wpa_s->global, wpa_s, &capa) < 0) {
8123
0
    return -1;
8124
0
  }
8125
8126
0
  if (wpa_bss_init(wpa_s) < 0)
8127
0
    return -1;
8128
8129
  /*
8130
   * Set Wake-on-WLAN triggers, if configured.
8131
   * Note: We don't restore/remove the triggers on shutdown (it doesn't
8132
   * have effect anyway when the interface is down).
8133
   */
8134
0
  if (capa_res == 0 && wpas_set_wowlan_triggers(wpa_s, &capa) < 0)
8135
0
    return -1;
8136
8137
#ifdef CONFIG_EAP_PROXY
8138
{
8139
  size_t len;
8140
  wpa_s->mnc_len = eapol_sm_get_eap_proxy_imsi(wpa_s->eapol, -1,
8141
                 wpa_s->imsi, &len);
8142
  if (wpa_s->mnc_len > 0) {
8143
    wpa_s->imsi[len] = '\0';
8144
    wpa_printf(MSG_DEBUG, "eap_proxy: IMSI %s (MNC length %d)",
8145
         wpa_s->imsi, wpa_s->mnc_len);
8146
  } else {
8147
    wpa_printf(MSG_DEBUG, "eap_proxy: IMSI not available");
8148
  }
8149
}
8150
#endif /* CONFIG_EAP_PROXY */
8151
8152
0
  if (pcsc_reader_init(wpa_s) < 0)
8153
0
    return -1;
8154
8155
0
  if (wpas_init_ext_pw(wpa_s) < 0)
8156
0
    return -1;
8157
8158
0
#ifndef CONFIG_NO_RRM
8159
0
  wpas_rrm_reset(wpa_s);
8160
0
#endif /* CONFIG_NO_RRM */
8161
8162
0
  wpas_sched_scan_plans_set(wpa_s, wpa_s->conf->sched_scan_plans);
8163
8164
#ifdef CONFIG_MBO
8165
  if (!wpa_s->disable_mbo_oce && wpa_s->conf->oce) {
8166
    if ((wpa_s->conf->oce & OCE_STA) &&
8167
        (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA))
8168
      wpa_s->enable_oce = OCE_STA;
8169
    if ((wpa_s->conf->oce & OCE_STA_CFON) &&
8170
        (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA_CFON)) {
8171
      /* TODO: Need to add STA-CFON support */
8172
      wpa_printf(MSG_ERROR,
8173
           "OCE STA-CFON feature is not yet supported");
8174
    }
8175
  }
8176
  wpas_mbo_update_non_pref_chan(wpa_s, wpa_s->conf->non_pref_chan);
8177
#endif /* CONFIG_MBO */
8178
8179
0
  wpa_supplicant_set_default_scan_ies(wpa_s);
8180
8181
0
  if (wpa_s->nan_mgmt && wpas_nan_init(wpa_s) < 0) {
8182
0
    wpa_msg(wpa_s, MSG_ERROR, "Failed to init NAN");
8183
0
    return -1;
8184
0
  }
8185
8186
0
  return 0;
8187
0
}
8188
8189
8190
static void wpa_supplicant_deinit_iface(struct wpa_supplicant *wpa_s,
8191
          int notify, int terminate)
8192
0
{
8193
0
  struct wpa_global *global = wpa_s->global;
8194
0
  struct wpa_supplicant *iface, *prev;
8195
8196
0
  if (wpa_s == wpa_s->parent)
8197
0
    wpas_p2p_group_remove(wpa_s, "*");
8198
8199
0
  iface = global->ifaces;
8200
0
  while (iface) {
8201
0
    if (iface->p2pdev == wpa_s)
8202
0
      iface->p2pdev = iface->parent;
8203
0
    if (iface == wpa_s || iface->parent != wpa_s) {
8204
0
      iface = iface->next;
8205
0
      continue;
8206
0
    }
8207
0
    wpa_printf(MSG_DEBUG,
8208
0
         "Remove remaining child interface %s from parent %s",
8209
0
         iface->ifname, wpa_s->ifname);
8210
0
    prev = iface;
8211
0
    iface = iface->next;
8212
0
    wpa_supplicant_remove_iface(global, prev, terminate);
8213
0
  }
8214
8215
0
  wpa_s->disconnected = 1;
8216
0
  if (wpa_s->drv_priv) {
8217
    /*
8218
     * Don't deauthenticate if WoWLAN is enable and not explicitly
8219
     * been configured to disconnect.
8220
     */
8221
0
    if (!wpa_drv_get_wowlan(wpa_s) ||
8222
0
        wpa_s->conf->wowlan_disconnect_on_deinit) {
8223
0
      wpa_supplicant_deauthenticate(
8224
0
        wpa_s, WLAN_REASON_DEAUTH_LEAVING);
8225
8226
0
      wpa_drv_set_countermeasures(wpa_s, 0);
8227
0
      wpa_clear_keys(wpa_s, NULL);
8228
0
    } else {
8229
0
      wpa_msg(wpa_s, MSG_INFO,
8230
0
        "Do not deauthenticate as part of interface deinit since WoWLAN is enabled");
8231
0
    }
8232
0
  }
8233
8234
0
  wpa_supplicant_cleanup(wpa_s);
8235
0
  wpas_p2p_deinit_iface(wpa_s);
8236
8237
0
  wpas_nan_deinit(wpa_s);
8238
8239
0
  wpas_ctrl_radio_work_flush(wpa_s);
8240
0
  radio_remove_interface(wpa_s);
8241
8242
#ifdef CONFIG_FST
8243
  if (wpa_s->fst) {
8244
    fst_detach(wpa_s->fst);
8245
    wpa_s->fst = NULL;
8246
  }
8247
  if (wpa_s->received_mb_ies) {
8248
    wpabuf_free(wpa_s->received_mb_ies);
8249
    wpa_s->received_mb_ies = NULL;
8250
  }
8251
#endif /* CONFIG_FST */
8252
8253
0
  if (wpa_s->drv_priv)
8254
0
    wpa_drv_deinit(wpa_s);
8255
8256
0
  if (notify)
8257
0
    wpas_notify_iface_removed(wpa_s);
8258
8259
0
  if (terminate)
8260
0
    wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TERMINATING);
8261
8262
0
  wpa_supplicant_ctrl_iface_deinit(wpa_s, wpa_s->ctrl_iface);
8263
0
  wpa_s->ctrl_iface = NULL;
8264
8265
#ifdef CONFIG_MESH
8266
  if (wpa_s->ifmsh) {
8267
    wpa_supplicant_mesh_iface_deinit(wpa_s, wpa_s->ifmsh, true);
8268
    wpa_s->ifmsh = NULL;
8269
  }
8270
#endif /* CONFIG_MESH */
8271
8272
0
  if (wpa_s->conf != NULL) {
8273
0
    wpa_config_free(wpa_s->conf);
8274
0
    wpa_s->conf = NULL;
8275
0
  }
8276
8277
0
  os_free(wpa_s->ssids_from_scan_req);
8278
0
  os_free(wpa_s->last_scan_freqs);
8279
8280
0
  os_free(wpa_s);
8281
0
}
8282
8283
8284
#ifdef CONFIG_MATCH_IFACE
8285
8286
/**
8287
 * wpa_supplicant_match_iface - Match an interface description to a name
8288
 * @global: Pointer to global data from wpa_supplicant_init()
8289
 * @ifname: Name of the interface to match
8290
 * Returns: Pointer to the created interface description or %NULL on failure
8291
 */
8292
struct wpa_interface * wpa_supplicant_match_iface(struct wpa_global *global,
8293
              const char *ifname)
8294
{
8295
  int i;
8296
  struct wpa_interface *iface, *miface;
8297
8298
  for (i = 0; i < global->params.match_iface_count; i++) {
8299
    miface = &global->params.match_ifaces[i];
8300
    if (!miface->ifname ||
8301
        fnmatch(miface->ifname, ifname, 0) == 0) {
8302
      iface = os_zalloc(sizeof(*iface));
8303
      if (!iface)
8304
        return NULL;
8305
      *iface = *miface;
8306
      if (!miface->ifname)
8307
        iface->matched = WPA_IFACE_MATCHED_NULL;
8308
      else
8309
        iface->matched = WPA_IFACE_MATCHED;
8310
      iface->ifname = ifname;
8311
      return iface;
8312
    }
8313
  }
8314
8315
  return NULL;
8316
}
8317
8318
8319
/**
8320
 * wpa_supplicant_match_existing - Match existing interfaces
8321
 * @global: Pointer to global data from wpa_supplicant_init()
8322
 * Returns: 0 on success, -1 on failure
8323
 */
8324
static int wpa_supplicant_match_existing(struct wpa_global *global)
8325
{
8326
  struct if_nameindex *ifi, *ifp;
8327
  struct wpa_supplicant *wpa_s;
8328
  struct wpa_interface *iface;
8329
8330
  ifp = if_nameindex();
8331
  if (!ifp) {
8332
    wpa_printf(MSG_ERROR, "if_nameindex: %s", strerror(errno));
8333
    return -1;
8334
  }
8335
8336
  for (ifi = ifp; ifi->if_name; ifi++) {
8337
    wpa_s = wpa_supplicant_get_iface(global, ifi->if_name);
8338
    if (wpa_s)
8339
      continue;
8340
    iface = wpa_supplicant_match_iface(global, ifi->if_name);
8341
    if (iface) {
8342
      wpa_supplicant_add_iface(global, iface, NULL);
8343
      os_free(iface);
8344
    }
8345
  }
8346
8347
  if_freenameindex(ifp);
8348
  return 0;
8349
}
8350
8351
#endif /* CONFIG_MATCH_IFACE */
8352
8353
8354
/**
8355
 * wpa_supplicant_add_iface - Add a new network interface
8356
 * @global: Pointer to global data from wpa_supplicant_init()
8357
 * @iface: Interface configuration options
8358
 * @parent: Parent interface or %NULL to assign new interface as parent
8359
 * Returns: Pointer to the created interface or %NULL on failure
8360
 *
8361
 * This function is used to add new network interfaces for %wpa_supplicant.
8362
 * This can be called before wpa_supplicant_run() to add interfaces before the
8363
 * main event loop has been started. In addition, new interfaces can be added
8364
 * dynamically while %wpa_supplicant is already running. This could happen,
8365
 * e.g., when a hotplug network adapter is inserted.
8366
 */
8367
struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global,
8368
             struct wpa_interface *iface,
8369
             struct wpa_supplicant *parent)
8370
0
{
8371
0
  struct wpa_supplicant *wpa_s;
8372
0
  struct wpa_interface t_iface;
8373
0
  struct wpa_ssid *ssid;
8374
8375
0
  if (global == NULL || iface == NULL)
8376
0
    return NULL;
8377
8378
0
  wpa_s = wpa_supplicant_alloc(parent);
8379
0
  if (wpa_s == NULL)
8380
0
    return NULL;
8381
8382
0
  wpa_s->global = global;
8383
8384
0
  t_iface = *iface;
8385
0
  if (global->params.override_driver) {
8386
0
    wpa_printf(MSG_DEBUG, "Override interface parameter: driver "
8387
0
         "('%s' -> '%s')",
8388
0
         iface->driver, global->params.override_driver);
8389
0
    t_iface.driver = global->params.override_driver;
8390
0
  }
8391
0
  if (global->params.override_ctrl_interface) {
8392
0
    wpa_printf(MSG_DEBUG, "Override interface parameter: "
8393
0
         "ctrl_interface ('%s' -> '%s')",
8394
0
         iface->ctrl_interface,
8395
0
         global->params.override_ctrl_interface);
8396
0
    t_iface.ctrl_interface =
8397
0
      global->params.override_ctrl_interface;
8398
0
  }
8399
0
  if (wpa_supplicant_init_iface(wpa_s, &t_iface)) {
8400
0
    wpa_printf(MSG_DEBUG, "Failed to add interface %s",
8401
0
         iface->ifname);
8402
0
    wpa_supplicant_deinit_iface(wpa_s, 0, 0);
8403
0
    return NULL;
8404
0
  }
8405
8406
0
  if (iface->p2p_mgmt == 0 && !iface->nan_mgmt) {
8407
    /* Notify the control interfaces about new iface */
8408
0
    if (wpas_notify_iface_added(wpa_s)) {
8409
0
      wpa_supplicant_deinit_iface(wpa_s, 1, 0);
8410
0
      return NULL;
8411
0
    }
8412
8413
0
    for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
8414
0
      wpas_notify_network_added(wpa_s, ssid);
8415
0
  }
8416
8417
0
  wpa_s->next = global->ifaces;
8418
0
  global->ifaces = wpa_s;
8419
8420
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Added interface %s", wpa_s->ifname);
8421
0
  wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
8422
8423
#ifdef CONFIG_P2P
8424
  if (!wpa_s->global->p2p && !wpas_is_nan_iface(wpa_s) &&
8425
      !wpa_s->global->p2p_disabled && !wpa_s->conf->p2p_disabled &&
8426
      (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
8427
      wpas_p2p_add_p2pdev_interface(
8428
        wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
8429
    wpa_printf(MSG_INFO,
8430
         "P2P: Failed to enable P2P Device interface");
8431
    /* Try to continue without. P2P will be disabled. */
8432
  }
8433
#endif /* CONFIG_P2P */
8434
8435
0
  return wpa_s;
8436
0
}
8437
8438
8439
/**
8440
 * wpa_supplicant_remove_iface - Remove a network interface
8441
 * @global: Pointer to global data from wpa_supplicant_init()
8442
 * @wpa_s: Pointer to the network interface to be removed
8443
 * Returns: 0 if interface was removed, -1 if interface was not found
8444
 *
8445
 * This function can be used to dynamically remove network interfaces from
8446
 * %wpa_supplicant, e.g., when a hotplug network adapter is ejected. In
8447
 * addition, this function is used to remove all remaining interfaces when
8448
 * %wpa_supplicant is terminated.
8449
 */
8450
int wpa_supplicant_remove_iface(struct wpa_global *global,
8451
        struct wpa_supplicant *wpa_s,
8452
        int terminate)
8453
0
{
8454
0
  struct wpa_supplicant *prev;
8455
#ifdef CONFIG_MESH
8456
  unsigned int mesh_if_created = wpa_s->mesh_if_created;
8457
  char *ifname = NULL;
8458
  struct wpa_supplicant *parent = wpa_s->parent;
8459
#endif /* CONFIG_MESH */
8460
8461
  /* Remove interface from the global list of interfaces */
8462
0
  prev = global->ifaces;
8463
0
  if (prev == wpa_s) {
8464
0
    global->ifaces = wpa_s->next;
8465
0
  } else {
8466
0
    while (prev && prev->next != wpa_s)
8467
0
      prev = prev->next;
8468
0
    if (prev == NULL)
8469
0
      return -1;
8470
0
    prev->next = wpa_s->next;
8471
0
  }
8472
8473
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Removing interface %s", wpa_s->ifname);
8474
8475
#ifdef CONFIG_MESH
8476
  if (mesh_if_created) {
8477
    ifname = os_strdup(wpa_s->ifname);
8478
    if (ifname == NULL) {
8479
      wpa_dbg(wpa_s, MSG_ERROR,
8480
        "mesh: Failed to malloc ifname");
8481
      return -1;
8482
    }
8483
  }
8484
#endif /* CONFIG_MESH */
8485
8486
0
  if (global->p2p_group_formation == wpa_s)
8487
0
    global->p2p_group_formation = NULL;
8488
0
  if (global->p2p_invite_group == wpa_s)
8489
0
    global->p2p_invite_group = NULL;
8490
0
  wpa_supplicant_deinit_iface(wpa_s, 1, terminate);
8491
8492
#ifdef CONFIG_MESH
8493
  if (mesh_if_created) {
8494
    wpa_drv_if_remove(parent, WPA_IF_MESH, ifname);
8495
    os_free(ifname);
8496
  }
8497
#endif /* CONFIG_MESH */
8498
8499
0
  return 0;
8500
0
}
8501
8502
8503
/**
8504
 * wpa_supplicant_get_eap_mode - Get the current EAP mode
8505
 * @wpa_s: Pointer to the network interface
8506
 * Returns: Pointer to the eap mode or the string "UNKNOWN" if not found
8507
 */
8508
const char * wpa_supplicant_get_eap_mode(struct wpa_supplicant *wpa_s)
8509
0
{
8510
0
  const char *eapol_method;
8511
8512
0
        if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) == 0 &&
8513
0
            wpa_s->key_mgmt != WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
8514
0
    return "NO-EAP";
8515
0
  }
8516
8517
0
  eapol_method = eapol_sm_get_method_name(wpa_s->eapol);
8518
0
  if (eapol_method == NULL)
8519
0
    return "UNKNOWN-EAP";
8520
8521
0
  return eapol_method;
8522
0
}
8523
8524
8525
/**
8526
 * wpa_supplicant_get_iface - Get a new network interface
8527
 * @global: Pointer to global data from wpa_supplicant_init()
8528
 * @ifname: Interface name
8529
 * Returns: Pointer to the interface or %NULL if not found
8530
 */
8531
struct wpa_supplicant * wpa_supplicant_get_iface(struct wpa_global *global,
8532
             const char *ifname)
8533
0
{
8534
0
  struct wpa_supplicant *wpa_s;
8535
8536
0
  for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
8537
0
    if (os_strcmp(wpa_s->ifname, ifname) == 0)
8538
0
      return wpa_s;
8539
0
  }
8540
0
  return NULL;
8541
0
}
8542
8543
8544
#ifndef CONFIG_NO_WPA_MSG
8545
static const char * wpa_supplicant_msg_ifname_cb(void *ctx)
8546
0
{
8547
0
  struct wpa_supplicant *wpa_s = ctx;
8548
0
  if (wpa_s == NULL)
8549
0
    return NULL;
8550
0
  return wpa_s->ifname;
8551
0
}
8552
#endif /* CONFIG_NO_WPA_MSG */
8553
8554
8555
#ifndef WPA_SUPPLICANT_CLEANUP_INTERVAL
8556
0
#define WPA_SUPPLICANT_CLEANUP_INTERVAL 10
8557
#endif /* WPA_SUPPLICANT_CLEANUP_INTERVAL */
8558
8559
/* Periodic cleanup tasks */
8560
static void wpas_periodic(void *eloop_ctx, void *timeout_ctx)
8561
0
{
8562
0
  struct wpa_global *global = eloop_ctx;
8563
0
  struct wpa_supplicant *wpa_s;
8564
8565
0
  eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL, 0,
8566
0
             wpas_periodic, global, NULL);
8567
8568
#ifdef CONFIG_P2P
8569
  if (global->p2p)
8570
    p2p_expire_peers(global->p2p);
8571
#endif /* CONFIG_P2P */
8572
8573
0
  for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
8574
0
    wpa_bss_flush_by_age(wpa_s, wpa_s->conf->bss_expiration_age);
8575
#ifdef CONFIG_AP
8576
    ap_periodic(wpa_s);
8577
#endif /* CONFIG_AP */
8578
0
  }
8579
0
}
8580
8581
8582
/**
8583
 * wpa_supplicant_init - Initialize %wpa_supplicant
8584
 * @params: Parameters for %wpa_supplicant
8585
 * Returns: Pointer to global %wpa_supplicant data, or %NULL on failure
8586
 *
8587
 * This function is used to initialize %wpa_supplicant. After successful
8588
 * initialization, the returned data pointer can be used to add and remove
8589
 * network interfaces, and eventually, to deinitialize %wpa_supplicant.
8590
 */
8591
struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
8592
0
{
8593
0
  struct wpa_global *global;
8594
0
  int ret, i;
8595
8596
0
  if (params == NULL)
8597
0
    return NULL;
8598
8599
#ifdef CONFIG_DRIVER_NDIS
8600
  {
8601
    void driver_ndis_init_ops(void);
8602
    driver_ndis_init_ops();
8603
  }
8604
#endif /* CONFIG_DRIVER_NDIS */
8605
8606
0
#ifndef CONFIG_NO_WPA_MSG
8607
0
  wpa_msg_register_ifname_cb(wpa_supplicant_msg_ifname_cb);
8608
0
#endif /* CONFIG_NO_WPA_MSG */
8609
8610
0
  if (params->wpa_debug_file_path)
8611
0
    wpa_debug_open_file(params->wpa_debug_file_path);
8612
0
  if (!params->wpa_debug_file_path && !params->wpa_debug_syslog)
8613
0
    wpa_debug_setup_stdout();
8614
0
  if (params->wpa_debug_syslog)
8615
0
    wpa_debug_open_syslog();
8616
0
  if (params->wpa_debug_tracing) {
8617
0
    ret = wpa_debug_open_linux_tracing();
8618
0
    if (ret) {
8619
0
      wpa_printf(MSG_ERROR,
8620
0
           "Failed to enable trace logging");
8621
0
      return NULL;
8622
0
    }
8623
0
  }
8624
8625
0
  ret = eap_register_methods();
8626
0
  if (ret) {
8627
0
    wpa_printf(MSG_ERROR, "Failed to register EAP methods");
8628
0
    if (ret == -2)
8629
0
      wpa_printf(MSG_ERROR, "Two or more EAP methods used "
8630
0
           "the same EAP type.");
8631
0
    return NULL;
8632
0
  }
8633
8634
0
  global = os_zalloc(sizeof(*global));
8635
0
  if (global == NULL)
8636
0
    return NULL;
8637
0
  dl_list_init(&global->p2p_srv_bonjour);
8638
0
  dl_list_init(&global->p2p_srv_upnp);
8639
0
  global->params.daemonize = params->daemonize;
8640
0
  global->params.wait_for_monitor = params->wait_for_monitor;
8641
0
  global->params.dbus_ctrl_interface = params->dbus_ctrl_interface;
8642
0
  global->params.show_details = params->show_details;
8643
8644
0
  if (params->pid_file) {
8645
0
    global->params.pid_file = os_strdup(params->pid_file);
8646
0
    if (!global->params.pid_file) {
8647
0
      wpa_supplicant_deinit(global);
8648
0
      return NULL;
8649
0
    }
8650
0
  }
8651
8652
0
  if (params->ctrl_interface) {
8653
0
    global->params.ctrl_interface =
8654
0
      os_strdup(params->ctrl_interface);
8655
0
    if (!global->params.ctrl_interface) {
8656
0
      wpa_supplicant_deinit(global);
8657
0
      return NULL;
8658
0
    }
8659
0
  }
8660
8661
0
  if (params->ctrl_interface_group) {
8662
0
    global->params.ctrl_interface_group =
8663
0
      os_strdup(params->ctrl_interface_group);
8664
0
    if (!global->params.ctrl_interface_group) {
8665
0
      wpa_supplicant_deinit(global);
8666
0
      return NULL;
8667
0
    }
8668
0
  }
8669
8670
0
  if (params->override_driver) {
8671
0
    global->params.override_driver =
8672
0
      os_strdup(params->override_driver);
8673
0
    if (!global->params.override_driver) {
8674
0
      wpa_supplicant_deinit(global);
8675
0
      return NULL;
8676
0
    }
8677
0
  }
8678
8679
0
  if (params->override_ctrl_interface) {
8680
0
    global->params.override_ctrl_interface =
8681
0
      os_strdup(params->override_ctrl_interface);
8682
0
    if (!global->params.override_ctrl_interface) {
8683
0
      wpa_supplicant_deinit(global);
8684
0
      return NULL;
8685
0
    }
8686
0
  }
8687
8688
#ifdef CONFIG_MATCH_IFACE
8689
  global->params.match_iface_count = params->match_iface_count;
8690
  if (params->match_iface_count) {
8691
    global->params.match_ifaces =
8692
      os_calloc(params->match_iface_count,
8693
          sizeof(struct wpa_interface));
8694
    if (!global->params.match_ifaces) {
8695
      wpa_printf(MSG_ERROR,
8696
           "Failed to allocate match interfaces");
8697
      wpa_supplicant_deinit(global);
8698
      return NULL;
8699
    }
8700
    os_memcpy(global->params.match_ifaces,
8701
        params->match_ifaces,
8702
        params->match_iface_count *
8703
        sizeof(struct wpa_interface));
8704
  }
8705
#endif /* CONFIG_MATCH_IFACE */
8706
#ifdef CONFIG_P2P
8707
  if (params->conf_p2p_dev) {
8708
    global->params.conf_p2p_dev =
8709
      os_strdup(params->conf_p2p_dev);
8710
    if (!global->params.conf_p2p_dev) {
8711
      wpa_printf(MSG_ERROR, "Failed to allocate conf p2p");
8712
      wpa_supplicant_deinit(global);
8713
      return NULL;
8714
    }
8715
  }
8716
#endif /* CONFIG_P2P */
8717
0
  wpa_debug_level = global->params.wpa_debug_level =
8718
0
    params->wpa_debug_level;
8719
0
  wpa_debug_show_keys = global->params.wpa_debug_show_keys =
8720
0
    params->wpa_debug_show_keys;
8721
0
  wpa_debug_timestamp = global->params.wpa_debug_timestamp =
8722
0
    params->wpa_debug_timestamp;
8723
8724
0
  wpa_printf(MSG_DEBUG, "wpa_supplicant v%s", VERSION_STR);
8725
8726
0
  if (eloop_init()) {
8727
0
    wpa_printf(MSG_ERROR, "Failed to initialize event loop");
8728
0
    wpa_supplicant_deinit(global);
8729
0
    return NULL;
8730
0
  }
8731
8732
0
  random_init(params->entropy_file);
8733
8734
#ifdef CONFIG_PROCESS_COORDINATION
8735
  if (params->proc_coord_dir) {
8736
    global->pc = proc_coord_init(params->proc_coord_dir);
8737
    if (!global->pc) {
8738
      wpa_supplicant_deinit(global);
8739
      return NULL;
8740
    }
8741
  }
8742
#endif /* CONFIG_PROCESS_COORDINATION */
8743
8744
0
  global->ctrl_iface = wpa_supplicant_global_ctrl_iface_init(global);
8745
0
  if (global->ctrl_iface == NULL) {
8746
0
    wpa_supplicant_deinit(global);
8747
0
    return NULL;
8748
0
  }
8749
8750
0
  if (wpas_notify_supplicant_initialized(global)) {
8751
0
    wpa_supplicant_deinit(global);
8752
0
    return NULL;
8753
0
  }
8754
8755
0
  for (i = 0; wpa_drivers[i]; i++)
8756
0
    global->drv_count++;
8757
0
  if (global->drv_count == 0) {
8758
0
    wpa_printf(MSG_ERROR, "No drivers enabled");
8759
0
    wpa_supplicant_deinit(global);
8760
0
    return NULL;
8761
0
  }
8762
0
  global->drv_priv = os_calloc(global->drv_count, sizeof(void *));
8763
0
  if (global->drv_priv == NULL) {
8764
0
    wpa_supplicant_deinit(global);
8765
0
    return NULL;
8766
0
  }
8767
8768
#ifdef CONFIG_WIFI_DISPLAY
8769
  if (wifi_display_init(global) < 0) {
8770
    wpa_printf(MSG_ERROR, "Failed to initialize Wi-Fi Display");
8771
    wpa_supplicant_deinit(global);
8772
    return NULL;
8773
  }
8774
#endif /* CONFIG_WIFI_DISPLAY */
8775
8776
0
  eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL, 0,
8777
0
             wpas_periodic, global, NULL);
8778
8779
0
  return global;
8780
0
}
8781
8782
8783
/**
8784
 * wpa_supplicant_run - Run the %wpa_supplicant main event loop
8785
 * @global: Pointer to global data from wpa_supplicant_init()
8786
 * Returns: 0 after successful event loop run, -1 on failure
8787
 *
8788
 * This function starts the main event loop and continues running as long as
8789
 * there are any remaining events. In most cases, this function is running as
8790
 * long as the %wpa_supplicant process in still in use.
8791
 */
8792
int wpa_supplicant_run(struct wpa_global *global)
8793
0
{
8794
0
  struct wpa_supplicant *wpa_s;
8795
8796
0
  if (global->params.daemonize &&
8797
0
      (wpa_supplicant_daemon(global->params.pid_file) ||
8798
0
       eloop_sock_requeue()))
8799
0
    return -1;
8800
8801
#ifdef CONFIG_MATCH_IFACE
8802
  if (wpa_supplicant_match_existing(global))
8803
    return -1;
8804
#endif
8805
8806
0
  if (global->params.wait_for_monitor) {
8807
0
    for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
8808
0
      if (wpa_s->ctrl_iface && !wpa_s->p2p_mgmt)
8809
0
        wpa_supplicant_ctrl_iface_wait(
8810
0
          wpa_s->ctrl_iface);
8811
0
  }
8812
8813
0
  eloop_register_signal_terminate(wpa_supplicant_terminate, global);
8814
0
  eloop_register_signal_reconfig(wpa_supplicant_reconfig, global);
8815
8816
0
  eloop_run();
8817
8818
0
  return 0;
8819
0
}
8820
8821
8822
/**
8823
 * wpa_supplicant_deinit - Deinitialize %wpa_supplicant
8824
 * @global: Pointer to global data from wpa_supplicant_init()
8825
 *
8826
 * This function is called to deinitialize %wpa_supplicant and to free all
8827
 * allocated resources. Remaining network interfaces will also be removed.
8828
 */
8829
void wpa_supplicant_deinit(struct wpa_global *global)
8830
0
{
8831
0
  int i;
8832
8833
0
  if (global == NULL)
8834
0
    return;
8835
8836
0
  eloop_cancel_timeout(wpas_periodic, global, NULL);
8837
8838
#ifdef CONFIG_WIFI_DISPLAY
8839
  wifi_display_deinit(global);
8840
#endif /* CONFIG_WIFI_DISPLAY */
8841
8842
0
  while (global->ifaces)
8843
0
    wpa_supplicant_remove_iface(global, global->ifaces, 1);
8844
8845
0
  if (global->ctrl_iface)
8846
0
    wpa_supplicant_global_ctrl_iface_deinit(global->ctrl_iface);
8847
8848
0
  wpas_notify_supplicant_deinitialized(global);
8849
8850
0
  eap_peer_unregister_methods();
8851
#ifdef CONFIG_AP
8852
  eap_server_unregister_methods();
8853
#endif /* CONFIG_AP */
8854
8855
0
  for (i = 0; wpa_drivers[i] && global->drv_priv; i++) {
8856
0
    if (!global->drv_priv[i])
8857
0
      continue;
8858
0
    wpa_drivers[i]->global_deinit(global->drv_priv[i]);
8859
0
  }
8860
0
  os_free(global->drv_priv);
8861
8862
0
  random_deinit();
8863
8864
#ifdef CONFIG_PROCESS_COORDINATION
8865
  proc_coord_deinit(global->pc);
8866
#endif /* CONFIG_PROCESS_COORDINATION */
8867
8868
0
  eloop_destroy();
8869
8870
0
  if (global->params.pid_file) {
8871
0
    os_daemonize_terminate(global->params.pid_file);
8872
0
    os_free(global->params.pid_file);
8873
0
  }
8874
0
  os_free(global->params.ctrl_interface);
8875
0
  os_free(global->params.ctrl_interface_group);
8876
0
  os_free(global->params.override_driver);
8877
0
  os_free(global->params.override_ctrl_interface);
8878
#ifdef CONFIG_MATCH_IFACE
8879
  os_free(global->params.match_ifaces);
8880
#endif /* CONFIG_MATCH_IFACE */
8881
#ifdef CONFIG_P2P
8882
  os_free(global->params.conf_p2p_dev);
8883
#endif /* CONFIG_P2P */
8884
8885
0
  os_free(global->p2p_disallow_freq.range);
8886
0
  os_free(global->p2p_go_avoid_freq.range);
8887
0
  os_free(global->add_psk);
8888
8889
0
  os_free(global);
8890
0
  wpa_debug_close_syslog();
8891
0
  wpa_debug_close_file();
8892
0
  wpa_debug_close_linux_tracing();
8893
0
}
8894
8895
8896
int wpa_supplicant_parse_config(const char *fname)
8897
0
{
8898
0
  struct wpa_config *conf;
8899
0
  int ret = -1;
8900
8901
0
  wpa_printf(MSG_INFO, "Validating parsing of %s", fname);
8902
0
  conf = wpa_config_read(fname, NULL, false, true);
8903
0
  if (conf) {
8904
0
    wpa_printf(MSG_INFO, "Parsing succeeded");
8905
0
    ret = 0;
8906
0
    wpa_config_free(conf);
8907
0
  } else {
8908
0
    wpa_printf(MSG_INFO, "Parsing failed");
8909
0
  }
8910
0
  return ret;
8911
0
}
8912
8913
8914
void wpa_supplicant_update_config(struct wpa_supplicant *wpa_s)
8915
0
{
8916
0
  if ((wpa_s->conf->changed_parameters & CFG_CHANGED_COUNTRY) &&
8917
0
      wpa_s->conf->country[0] && wpa_s->conf->country[1]) {
8918
0
    char country[3];
8919
0
    country[0] = wpa_s->conf->country[0];
8920
0
    country[1] = wpa_s->conf->country[1];
8921
0
    country[2] = '\0';
8922
0
    if (wpa_drv_set_country(wpa_s, country) < 0) {
8923
0
      wpa_printf(MSG_ERROR, "Failed to set country code "
8924
0
           "'%s'", country);
8925
0
    }
8926
0
  }
8927
8928
0
  if (wpa_s->conf->changed_parameters & CFG_CHANGED_EXT_PW_BACKEND)
8929
0
    wpas_init_ext_pw(wpa_s);
8930
8931
0
  if (wpa_s->conf->changed_parameters & CFG_CHANGED_SCHED_SCAN_PLANS)
8932
0
    wpas_sched_scan_plans_set(wpa_s, wpa_s->conf->sched_scan_plans);
8933
8934
0
  if (wpa_s->conf->changed_parameters & CFG_CHANGED_WOWLAN_TRIGGERS) {
8935
0
    struct wpa_driver_capa capa;
8936
0
    int res = wpa_drv_get_capa(wpa_s, &capa);
8937
8938
0
    if (res == 0 && wpas_set_wowlan_triggers(wpa_s, &capa) < 0)
8939
0
      wpa_printf(MSG_ERROR,
8940
0
           "Failed to update wowlan_triggers to '%s'",
8941
0
           wpa_s->conf->wowlan_triggers);
8942
0
  }
8943
8944
0
  if (wpa_s->conf->changed_parameters & CFG_CHANGED_DISABLE_BTM)
8945
0
    wpa_supplicant_set_default_scan_ies(wpa_s);
8946
8947
0
  if (wpa_s->conf->changed_parameters & CFG_CHANGED_FT_PREPEND_PMKID)
8948
0
    wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_FT_PREPEND_PMKID,
8949
0
         wpa_s->conf->ft_prepend_pmkid);
8950
8951
#ifdef CONFIG_P2P
8952
  if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_DISABLED)
8953
    wpas_p2p_disabled_changed(wpa_s);
8954
#endif /* CONFIG_P2P */
8955
8956
#ifdef CONFIG_BGSCAN
8957
  /*
8958
   * We default to global bgscan parameters only when per-network bgscan
8959
   * parameters aren't set. Only bother resetting bgscan parameters if
8960
   * this is the case.
8961
   */
8962
  if ((wpa_s->conf->changed_parameters & CFG_CHANGED_BGSCAN) &&
8963
      wpa_s->current_ssid && !wpa_s->current_ssid->bgscan &&
8964
      wpa_s->wpa_state == WPA_COMPLETED)
8965
    wpa_supplicant_reset_bgscan(wpa_s);
8966
#endif /* CONFIG_BGSCAN */
8967
8968
#ifdef CONFIG_WPS
8969
  wpas_wps_update_config(wpa_s);
8970
#endif /* CONFIG_WPS */
8971
0
  wpas_p2p_update_config(wpa_s);
8972
0
  wpa_s->conf->changed_parameters = 0;
8973
0
}
8974
8975
8976
void wpas_connection_failed(struct wpa_supplicant *wpa_s, const u8 *bssid,
8977
          const u8 **link_bssids)
8978
0
{
8979
0
  int timeout;
8980
0
  int count;
8981
8982
0
  wpas_connect_work_done(wpa_s);
8983
8984
  /*
8985
   * Remove possible authentication timeout since the connection failed.
8986
   */
8987
0
  eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
8988
8989
  /*
8990
   * There is no point in ignoring the AP temporarily if this event is
8991
   * generated based on local request to disconnect.
8992
   */
8993
0
  if (wpa_s->own_disconnect_req || wpa_s->own_reconnect_req) {
8994
0
    wpa_s->own_disconnect_req = 0;
8995
0
    wpa_dbg(wpa_s, MSG_DEBUG,
8996
0
      "Ignore connection failure due to local request to disconnect");
8997
0
    return;
8998
0
  }
8999
0
  if (wpa_s->disconnected) {
9000
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Ignore connection failure "
9001
0
      "indication since interface has been put into "
9002
0
      "disconnected state");
9003
0
    return;
9004
0
  }
9005
9006
  /* Also mark links as failed */
9007
0
  while (link_bssids && *link_bssids) {
9008
0
    wpa_bssid_ignore_add(wpa_s, *link_bssids);
9009
0
    link_bssids++;
9010
0
  }
9011
9012
  /*
9013
   * Add the failed BSSID into the ignore list and speed up next scan
9014
   * attempt if there could be other APs that could accept association.
9015
   */
9016
0
  count = wpa_bssid_ignore_add(wpa_s, bssid);
9017
9018
  /*
9019
   * This BSS was not in the ignore list before. If there is
9020
   * another BSS available for the same ESS, we should try that
9021
   * next. Otherwise, we may as well try this one once more
9022
   * before allowing other, likely worse, ESSes to be considered.
9023
   */
9024
0
  if (count == 1 && wpa_supplicant_fast_associate(wpa_s) == 1)
9025
0
    return;
9026
9027
0
  wpa_s->consecutive_conn_failures++;
9028
9029
0
  if (wpa_s->consecutive_conn_failures > 3 && wpa_s->current_ssid) {
9030
0
    wpa_printf(MSG_DEBUG, "Continuous association failures - "
9031
0
         "consider temporary network disabling");
9032
0
    wpas_auth_failed(wpa_s, "CONN_FAILED", bssid);
9033
0
  }
9034
  /*
9035
   * Multiple consecutive connection failures mean that other APs are
9036
   * either not available or have already been tried, so we can start
9037
   * increasing the delay here to avoid constant scanning.
9038
   */
9039
0
  switch (wpa_s->consecutive_conn_failures) {
9040
0
  case 1:
9041
0
    timeout = 100;
9042
0
    break;
9043
0
  case 2:
9044
0
    timeout = 500;
9045
0
    break;
9046
0
  case 3:
9047
0
    timeout = 1000;
9048
0
    break;
9049
0
  case 4:
9050
0
    timeout = 5000;
9051
0
    break;
9052
0
  default:
9053
0
    timeout = 10000;
9054
0
    break;
9055
0
  }
9056
9057
0
  wpa_dbg(wpa_s, MSG_DEBUG,
9058
0
    "Consecutive connection failures: %d --> request scan in %d ms",
9059
0
    wpa_s->consecutive_conn_failures, timeout);
9060
9061
  /* speed up the connection attempt with normal scan */
9062
0
  wpa_s->normal_scans = 0;
9063
0
  wpa_supplicant_req_scan(wpa_s, timeout / 1000,
9064
0
        1000 * (timeout % 1000));
9065
0
}
9066
9067
9068
#ifdef CONFIG_FILS
9069
9070
void fils_pmksa_cache_flush(struct wpa_supplicant *wpa_s)
9071
{
9072
  struct wpa_ssid *ssid = wpa_s->current_ssid;
9073
  const u8 *realm, *username, *rrk;
9074
  size_t realm_len, username_len, rrk_len;
9075
  u16 next_seq_num;
9076
9077
  /* Clear the PMKSA cache entry if FILS authentication was rejected.
9078
   * Check for ERP keys existing to limit when this can be done since
9079
   * the rejection response is not protected and such triggers should
9080
   * really not allow internal state to be modified unless required to
9081
   * avoid significant issues in functionality. In addition, drop
9082
   * externally configure PMKSA entries even without ERP keys since it
9083
   * is possible for an external component to add PMKSA entries for FILS
9084
   * authentication without restoring previously generated ERP keys.
9085
   *
9086
   * In this case, this is needed to allow recovery from cases where the
9087
   * AP or authentication server has dropped PMKSAs and ERP keys. */
9088
  if (!ssid || !ssid->eap.erp || !wpa_key_mgmt_fils(ssid->key_mgmt))
9089
    return;
9090
9091
  if (eapol_sm_get_erp_info(wpa_s->eapol, &ssid->eap,
9092
          &username, &username_len,
9093
          &realm, &realm_len, &next_seq_num,
9094
          &rrk, &rrk_len) != 0 ||
9095
      !realm) {
9096
    wpa_dbg(wpa_s, MSG_DEBUG,
9097
      "FILS: Drop external PMKSA cache entry");
9098
    wpa_sm_aborted_external_cached(wpa_s->wpa);
9099
    wpa_sm_external_pmksa_cache_flush(wpa_s->wpa, ssid);
9100
    return;
9101
  }
9102
9103
  wpa_dbg(wpa_s, MSG_DEBUG, "FILS: Drop PMKSA cache entry");
9104
  wpa_sm_aborted_cached(wpa_s->wpa);
9105
  wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
9106
}
9107
9108
9109
void fils_connection_failure(struct wpa_supplicant *wpa_s)
9110
{
9111
  struct wpa_ssid *ssid = wpa_s->current_ssid;
9112
  const u8 *realm, *username, *rrk;
9113
  size_t realm_len, username_len, rrk_len;
9114
  u16 next_seq_num;
9115
9116
  if (!ssid || !ssid->eap.erp || !wpa_key_mgmt_fils(ssid->key_mgmt) ||
9117
      eapol_sm_get_erp_info(wpa_s->eapol, &ssid->eap,
9118
          &username, &username_len,
9119
          &realm, &realm_len, &next_seq_num,
9120
          &rrk, &rrk_len) != 0 ||
9121
      !realm)
9122
    return;
9123
9124
  wpa_hexdump_ascii(MSG_DEBUG,
9125
        "FILS: Store last connection failure realm",
9126
        realm, realm_len);
9127
  os_free(wpa_s->last_con_fail_realm);
9128
  wpa_s->last_con_fail_realm = os_malloc(realm_len);
9129
  if (wpa_s->last_con_fail_realm) {
9130
    wpa_s->last_con_fail_realm_len = realm_len;
9131
    os_memcpy(wpa_s->last_con_fail_realm, realm, realm_len);
9132
  }
9133
}
9134
#endif /* CONFIG_FILS */
9135
9136
9137
int wpas_driver_bss_selection(struct wpa_supplicant *wpa_s)
9138
0
{
9139
0
  return wpa_s->conf->ap_scan == 2 ||
9140
0
    (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION);
9141
0
}
9142
9143
9144
static bool wpas_driver_rsn_override(struct wpa_supplicant *wpa_s)
9145
0
{
9146
0
  return !!(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_RSN_OVERRIDE_STA);
9147
0
}
9148
9149
9150
bool wpas_rsn_overriding(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
9151
0
{
9152
0
  enum wpas_rsn_overriding rsno;
9153
9154
0
  if (ssid && ssid->rsn_overriding != RSN_OVERRIDING_NOT_SET)
9155
0
    rsno = ssid->rsn_overriding;
9156
0
  else
9157
0
    rsno = wpa_s->conf->rsn_overriding;
9158
9159
0
  if (rsno == RSN_OVERRIDING_DISABLED)
9160
0
    return false;
9161
9162
0
  if (rsno == RSN_OVERRIDING_ENABLED)
9163
0
    return true;
9164
9165
0
  if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
9166
0
      wpas_driver_bss_selection(wpa_s))
9167
0
    return wpas_driver_rsn_override(wpa_s);
9168
9169
0
  return true;
9170
0
}
9171
9172
9173
#if defined(CONFIG_CTRL_IFACE) || defined(CONFIG_CTRL_IFACE_DBUS_NEW)
9174
int wpa_supplicant_ctrl_iface_ctrl_rsp_handle(struct wpa_supplicant *wpa_s,
9175
                struct wpa_ssid *ssid,
9176
                const char *field,
9177
                const char *value)
9178
{
9179
#ifdef IEEE8021X_EAPOL
9180
  struct eap_peer_config *eap = &ssid->eap;
9181
9182
  wpa_printf(MSG_DEBUG, "CTRL_IFACE: response handle field=%s", field);
9183
  wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: response value",
9184
            (const u8 *) value, os_strlen(value));
9185
9186
  switch (wpa_supplicant_ctrl_req_from_string(field)) {
9187
  case WPA_CTRL_REQ_EAP_IDENTITY:
9188
    os_free(eap->identity);
9189
    eap->identity = (u8 *) os_strdup(value);
9190
    if (!eap->identity)
9191
      return -1;
9192
    eap->identity_len = os_strlen(value);
9193
    eap->pending_req_identity = 0;
9194
    if (ssid == wpa_s->current_ssid)
9195
      wpa_s->reassociate = 1;
9196
    break;
9197
  case WPA_CTRL_REQ_EAP_PASSWORD:
9198
    bin_clear_free(eap->password, eap->password_len);
9199
    eap->password = (u8 *) os_strdup(value);
9200
    if (!eap->password)
9201
      return -1;
9202
    eap->password_len = os_strlen(value);
9203
    eap->pending_req_password = 0;
9204
    if (ssid == wpa_s->current_ssid)
9205
      wpa_s->reassociate = 1;
9206
    break;
9207
  case WPA_CTRL_REQ_EAP_NEW_PASSWORD:
9208
    bin_clear_free(eap->new_password, eap->new_password_len);
9209
    eap->new_password = (u8 *) os_strdup(value);
9210
    if (!eap->new_password)
9211
      return -1;
9212
    eap->new_password_len = os_strlen(value);
9213
    eap->pending_req_new_password = 0;
9214
    if (ssid == wpa_s->current_ssid)
9215
      wpa_s->reassociate = 1;
9216
    break;
9217
  case WPA_CTRL_REQ_EAP_PIN:
9218
    str_clear_free(eap->cert.pin);
9219
    eap->cert.pin = os_strdup(value);
9220
    if (!eap->cert.pin)
9221
      return -1;
9222
    eap->pending_req_pin = 0;
9223
    if (ssid == wpa_s->current_ssid)
9224
      wpa_s->reassociate = 1;
9225
    break;
9226
  case WPA_CTRL_REQ_EAP_OTP:
9227
    bin_clear_free(eap->otp, eap->otp_len);
9228
    eap->otp = (u8 *) os_strdup(value);
9229
    if (!eap->otp)
9230
      return -1;
9231
    eap->otp_len = os_strlen(value);
9232
    os_free(eap->pending_req_otp);
9233
    eap->pending_req_otp = NULL;
9234
    eap->pending_req_otp_len = 0;
9235
    break;
9236
  case WPA_CTRL_REQ_EAP_PASSPHRASE:
9237
    str_clear_free(eap->cert.private_key_passwd);
9238
    eap->cert.private_key_passwd = os_strdup(value);
9239
    if (!eap->cert.private_key_passwd)
9240
      return -1;
9241
    eap->pending_req_passphrase = 0;
9242
    if (ssid == wpa_s->current_ssid)
9243
      wpa_s->reassociate = 1;
9244
    break;
9245
  case WPA_CTRL_REQ_SIM:
9246
    str_clear_free(eap->external_sim_resp);
9247
    eap->external_sim_resp = os_strdup(value);
9248
    if (!eap->external_sim_resp)
9249
      return -1;
9250
    eap->pending_req_sim = 0;
9251
    break;
9252
  case WPA_CTRL_REQ_PSK_PASSPHRASE:
9253
    if (wpa_config_set(ssid, "psk", value, 0) < 0)
9254
      return -1;
9255
    ssid->mem_only_psk = 1;
9256
    if (ssid->passphrase)
9257
      wpa_config_update_psk(ssid);
9258
    if (wpa_s->wpa_state == WPA_SCANNING && !wpa_s->scanning)
9259
      wpa_supplicant_req_scan(wpa_s, 0, 0);
9260
    break;
9261
  case WPA_CTRL_REQ_EXT_CERT_CHECK:
9262
    if (eap->pending_ext_cert_check != PENDING_CHECK)
9263
      return -1;
9264
    if (os_strcmp(value, "good") == 0)
9265
      eap->pending_ext_cert_check = EXT_CERT_CHECK_GOOD;
9266
    else if (os_strcmp(value, "bad") == 0)
9267
      eap->pending_ext_cert_check = EXT_CERT_CHECK_BAD;
9268
    else
9269
      return -1;
9270
    break;
9271
  default:
9272
    wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown field '%s'", field);
9273
    return -1;
9274
  }
9275
9276
  return 0;
9277
#else /* IEEE8021X_EAPOL */
9278
  wpa_printf(MSG_DEBUG, "CTRL_IFACE: IEEE 802.1X not included");
9279
  return -1;
9280
#endif /* IEEE8021X_EAPOL */
9281
}
9282
#endif /* CONFIG_CTRL_IFACE || CONFIG_CTRL_IFACE_DBUS_NEW */
9283
9284
9285
int wpas_network_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
9286
0
{
9287
#ifdef CONFIG_WEP
9288
  int i;
9289
  unsigned int drv_enc;
9290
#endif /* CONFIG_WEP */
9291
9292
0
  if (wpa_s->p2p_mgmt)
9293
0
    return 1; /* no normal network profiles on p2p_mgmt interface */
9294
9295
0
  if (ssid == NULL)
9296
0
    return 1;
9297
9298
0
  if (ssid->disabled)
9299
0
    return 1;
9300
9301
#ifdef CONFIG_WEP
9302
  if (wpa_s->drv_capa_known)
9303
    drv_enc = wpa_s->drv_enc;
9304
  else
9305
    drv_enc = (unsigned int) -1;
9306
9307
  for (i = 0; i < NUM_WEP_KEYS; i++) {
9308
    size_t len = ssid->wep_key_len[i];
9309
    if (len == 0)
9310
      continue;
9311
    if (len == 5 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP40))
9312
      continue;
9313
    if (len == 13 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP104))
9314
      continue;
9315
    if (len == 16 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP128))
9316
      continue;
9317
    return 1; /* invalid WEP key */
9318
  }
9319
#endif /* CONFIG_WEP */
9320
9321
0
  if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt) && !ssid->psk_set &&
9322
0
      (!ssid->passphrase || ssid->ssid_len != 0) && !ssid->ext_psk &&
9323
0
      !(wpa_key_mgmt_sae(ssid->key_mgmt) &&
9324
0
        (ssid->passphrase || ssid->sae_password || ssid->pmk_valid)) &&
9325
0
      !ssid->mem_only_psk)
9326
0
    return 1;
9327
9328
0
#ifdef IEEE8021X_EAPOL
9329
#ifdef CRYPTO_RSA_OAEP_SHA256
9330
  if (ssid->eap.imsi_privacy_cert) {
9331
    struct crypto_rsa_key *key;
9332
    bool failed = false;
9333
9334
    key = crypto_rsa_key_read(ssid->eap.imsi_privacy_cert, false);
9335
    if (!key)
9336
      failed = true;
9337
    crypto_rsa_key_free(key);
9338
    if (failed) {
9339
      wpa_printf(MSG_DEBUG,
9340
           "Invalid imsi_privacy_cert (%s) - disable network",
9341
           ssid->eap.imsi_privacy_cert);
9342
      return 1;
9343
    }
9344
  }
9345
#endif /* CRYPTO_RSA_OAEP_SHA256 */
9346
0
#endif /* IEEE8021X_EAPOL */
9347
9348
0
  return 0;
9349
0
}
9350
9351
9352
int wpas_get_ssid_pmf(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
9353
0
{
9354
0
  if (ssid == NULL || ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT) {
9355
0
    if (wpa_s->conf->pmf == MGMT_FRAME_PROTECTION_OPTIONAL &&
9356
0
        !(wpa_s->drv_enc & WPA_DRIVER_CAPA_ENC_BIP)) {
9357
      /*
9358
       * Driver does not support BIP -- ignore pmf=1 default
9359
       * since the connection with PMF would fail and the
9360
       * configuration does not require PMF to be enabled.
9361
       */
9362
0
      return NO_MGMT_FRAME_PROTECTION;
9363
0
    }
9364
9365
0
    if (ssid &&
9366
0
        (ssid->key_mgmt &
9367
0
         ~(WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPS |
9368
0
           WPA_KEY_MGMT_IEEE8021X_NO_WPA)) == 0) {
9369
      /*
9370
       * Do not use the default PMF value for non-RSN networks
9371
       * since PMF is available only with RSN and pmf=2
9372
       * configuration would otherwise prevent connections to
9373
       * all open networks.
9374
       */
9375
0
      return NO_MGMT_FRAME_PROTECTION;
9376
0
    }
9377
9378
#ifdef CONFIG_OCV
9379
    /* Enable PMF if OCV is being enabled */
9380
    if (wpa_s->conf->pmf == NO_MGMT_FRAME_PROTECTION &&
9381
        ssid && ssid->ocv)
9382
      return MGMT_FRAME_PROTECTION_OPTIONAL;
9383
#endif /* CONFIG_OCV */
9384
9385
0
    return wpa_s->conf->pmf;
9386
0
  }
9387
9388
0
  return ssid->ieee80211w;
9389
0
}
9390
9391
9392
#ifdef CONFIG_SAE
9393
9394
enum sae_pwe wpas_get_ssid_sae_pwe(struct wpa_supplicant *wpa_s,
9395
           struct wpa_ssid *ssid)
9396
{
9397
  if (!ssid || ssid->sae_pwe == DEFAULT_SAE_PWE)
9398
    return wpa_s->conf->sae_pwe;
9399
  return ssid->sae_pwe;
9400
}
9401
9402
9403
bool wpas_is_sae_avoided(struct wpa_supplicant *wpa_s,
9404
       struct wpa_ssid *ssid,
9405
       const struct wpa_ie_data *ie)
9406
{
9407
  return wpa_s->conf->sae_check_mfp &&
9408
    (!(ie->capabilities &
9409
       (WPA_CAPABILITY_MFPC | WPA_CAPABILITY_MFPR)) ||
9410
     wpas_get_ssid_pmf(wpa_s, ssid) == NO_MGMT_FRAME_PROTECTION);
9411
}
9412
9413
#endif /* CONFIG_SAE */
9414
9415
9416
int pmf_in_use(struct wpa_supplicant *wpa_s, const u8 *addr)
9417
0
{
9418
0
  if (wpa_s->current_ssid == NULL ||
9419
0
      wpa_s->wpa_state < WPA_4WAY_HANDSHAKE)
9420
0
    return 0;
9421
0
  if (wpa_s->valid_links) {
9422
0
    if (!ether_addr_equal(addr, wpa_s->ap_mld_addr) &&
9423
0
        !wpas_ap_link_address(wpa_s, addr))
9424
0
      return 0;
9425
0
  } else {
9426
0
    if (!ether_addr_equal(addr, wpa_s->bssid))
9427
0
      return 0;
9428
0
  }
9429
0
  return wpa_sm_pmf_enabled(wpa_s->wpa);
9430
0
}
9431
9432
9433
int wpas_is_p2p_prioritized(struct wpa_supplicant *wpa_s)
9434
0
{
9435
0
  if (wpa_s->global->conc_pref == WPA_CONC_PREF_P2P)
9436
0
    return 1;
9437
0
  if (wpa_s->global->conc_pref == WPA_CONC_PREF_STA)
9438
0
    return 0;
9439
0
  return -1;
9440
0
}
9441
9442
9443
void wpas_auth_failed(struct wpa_supplicant *wpa_s, const char *reason,
9444
          const u8 *bssid)
9445
0
{
9446
0
  struct wpa_ssid *ssid = wpa_s->current_ssid;
9447
0
  int dur;
9448
0
  struct os_reltime now;
9449
9450
0
  if (ssid == NULL) {
9451
0
    wpa_printf(MSG_DEBUG, "Authentication failure but no known "
9452
0
         "SSID block");
9453
0
    return;
9454
0
  }
9455
9456
0
  if (ssid->key_mgmt == WPA_KEY_MGMT_WPS)
9457
0
    return;
9458
9459
0
  ssid->auth_failures++;
9460
9461
#ifdef CONFIG_P2P
9462
  if (ssid->p2p_group &&
9463
      (wpa_s->p2p_in_provisioning || wpa_s->show_group_started)) {
9464
    /*
9465
     * Skip the wait time since there is a short timeout on the
9466
     * connection to a P2P group.
9467
     */
9468
    return;
9469
  }
9470
#endif /* CONFIG_P2P */
9471
9472
0
  if (ssid->auth_failures > 50)
9473
0
    dur = 300;
9474
0
  else if (ssid->auth_failures > 10)
9475
0
    dur = 120;
9476
0
  else if (ssid->auth_failures > 5)
9477
0
    dur = 90;
9478
0
  else if (ssid->auth_failures > 3)
9479
0
    dur = 60;
9480
0
  else if (ssid->auth_failures > 2)
9481
0
    dur = 30;
9482
0
  else if (ssid->auth_failures > 1)
9483
0
    dur = 20;
9484
0
  else
9485
0
    dur = 10;
9486
9487
0
  if (ssid->auth_failures > 1 &&
9488
0
      wpa_key_mgmt_wpa_ieee8021x(ssid->key_mgmt))
9489
0
    dur += os_random() % (ssid->auth_failures * 10);
9490
9491
0
  os_get_reltime(&now);
9492
0
  if (now.sec + dur <= ssid->disabled_until.sec)
9493
0
    return;
9494
9495
0
  ssid->disabled_until.sec = now.sec + dur;
9496
9497
0
  wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TEMP_DISABLED
9498
0
    "id=%d ssid=\"%s\" auth_failures=%u duration=%d reason=%s",
9499
0
    ssid->id, wpa_ssid_txt(ssid->ssid, ssid->ssid_len),
9500
0
    ssid->auth_failures, dur, reason);
9501
9502
0
  if (bssid)
9503
0
    os_memcpy(ssid->disabled_due_to, bssid, ETH_ALEN);
9504
0
}
9505
9506
9507
void wpas_clear_temp_disabled(struct wpa_supplicant *wpa_s,
9508
            struct wpa_ssid *ssid, int clear_failures)
9509
0
{
9510
0
  if (ssid == NULL)
9511
0
    return;
9512
9513
0
  if (ssid->disabled_until.sec) {
9514
0
    wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REENABLED
9515
0
      "id=%d ssid=\"%s\"",
9516
0
      ssid->id, wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
9517
0
  }
9518
0
  ssid->disabled_until.sec = 0;
9519
0
  ssid->disabled_until.usec = 0;
9520
0
  if (clear_failures) {
9521
0
    ssid->auth_failures = 0;
9522
0
  } else if (!is_zero_ether_addr(ssid->disabled_due_to)) {
9523
0
    wpa_printf(MSG_DEBUG, "Mark BSSID " MACSTR
9524
0
         " ignored to allow a lower priority BSS, if any, to be tried next",
9525
0
         MAC2STR(ssid->disabled_due_to));
9526
0
    wpa_bssid_ignore_add(wpa_s, ssid->disabled_due_to);
9527
0
    os_memset(ssid->disabled_due_to, 0, ETH_ALEN);
9528
0
  }
9529
0
}
9530
9531
9532
int disallowed_bssid(struct wpa_supplicant *wpa_s, const u8 *bssid)
9533
0
{
9534
0
  size_t i;
9535
9536
0
  if (wpa_s->disallow_aps_bssid == NULL)
9537
0
    return 0;
9538
9539
0
  for (i = 0; i < wpa_s->disallow_aps_bssid_count; i++) {
9540
0
    if (ether_addr_equal(wpa_s->disallow_aps_bssid + i * ETH_ALEN,
9541
0
             bssid))
9542
0
      return 1;
9543
0
  }
9544
9545
0
  return 0;
9546
0
}
9547
9548
9549
int disallowed_ssid(struct wpa_supplicant *wpa_s, const u8 *ssid,
9550
        size_t ssid_len)
9551
0
{
9552
0
  size_t i;
9553
9554
0
  if (wpa_s->disallow_aps_ssid == NULL || ssid == NULL)
9555
0
    return 0;
9556
9557
0
  for (i = 0; i < wpa_s->disallow_aps_ssid_count; i++) {
9558
0
    struct wpa_ssid_value *s = &wpa_s->disallow_aps_ssid[i];
9559
0
    if (ssid_len == s->ssid_len &&
9560
0
        os_memcmp(ssid, s->ssid, ssid_len) == 0)
9561
0
      return 1;
9562
0
  }
9563
9564
0
  return 0;
9565
0
}
9566
9567
9568
/**
9569
 * wpas_request_connection - Request a new connection
9570
 * @wpa_s: Pointer to the network interface
9571
 *
9572
 * This function is used to request a new connection to be found. It will mark
9573
 * the interface to allow reassociation and request a new scan to find a
9574
 * suitable network to connect to.
9575
 */
9576
void wpas_request_connection(struct wpa_supplicant *wpa_s)
9577
0
{
9578
0
  wpa_s->normal_scans = 0;
9579
0
  wpa_s->scan_req = NORMAL_SCAN_REQ;
9580
0
  wpa_supplicant_reinit_autoscan(wpa_s);
9581
0
  wpa_s->disconnected = 0;
9582
0
  wpa_s->reassociate = 1;
9583
0
  wpa_s->last_owe_group = 0;
9584
#ifdef CONFIG_PASN
9585
  wpa_pasn_reset(&wpa_s->pasn);
9586
#endif /* CONFIG_PASN */
9587
9588
0
  if (wpa_supplicant_fast_associate(wpa_s) != 1)
9589
0
    wpa_supplicant_req_scan(wpa_s, 0, 0);
9590
0
  else
9591
0
    wpa_s->reattach = 0;
9592
0
}
9593
9594
9595
/**
9596
 * wpas_request_disconnection - Request disconnection
9597
 * @wpa_s: Pointer to the network interface
9598
 *
9599
 * This function is used to request disconnection from the currently connected
9600
 * network. This will stop any ongoing scans and initiate deauthentication.
9601
 */
9602
void wpas_request_disconnection(struct wpa_supplicant *wpa_s)
9603
0
{
9604
#ifdef CONFIG_SME
9605
  wpa_s->sme.prev_bssid_set = 0;
9606
#endif /* CONFIG_SME */
9607
0
  wpa_s->reassociate = 0;
9608
0
  wpa_s->disconnected = 1;
9609
0
  wpa_supplicant_cancel_sched_scan(wpa_s);
9610
0
  wpa_supplicant_cancel_scan(wpa_s);
9611
0
  wpas_abort_ongoing_scan(wpa_s);
9612
0
  wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
9613
0
  eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
9614
0
  radio_remove_works(wpa_s, "connect", 0);
9615
0
  radio_remove_works(wpa_s, "sme-connect", 0);
9616
0
  wpa_s->roam_in_progress = false;
9617
0
#ifdef CONFIG_WNM
9618
0
  wpa_s->bss_trans_mgmt_in_progress = false;
9619
0
#endif /* CONFIG_WNM */
9620
0
}
9621
9622
9623
void dump_freq_data(struct wpa_supplicant *wpa_s, const char *title,
9624
        struct wpa_used_freq_data *freqs_data,
9625
        unsigned int len)
9626
0
{
9627
0
  unsigned int i;
9628
9629
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Shared frequencies (len=%u): %s",
9630
0
    len, title);
9631
0
  for (i = 0; i < len; i++) {
9632
0
    struct wpa_used_freq_data *cur = &freqs_data[i];
9633
0
    wpa_dbg(wpa_s, MSG_DEBUG, "freq[%u]: %d, flags=0x%X",
9634
0
      i, cur->freq, cur->flags);
9635
0
  }
9636
0
}
9637
9638
9639
/*
9640
 * Find the operating frequencies of any of the virtual interfaces that
9641
 * are using the same radio as the current interface, and in addition, get
9642
 * information about the interface types that are using the frequency.
9643
 */
9644
int get_shared_radio_freqs_data(struct wpa_supplicant *wpa_s,
9645
        struct wpa_used_freq_data *freqs_data,
9646
        unsigned int len, bool exclude_current)
9647
0
{
9648
0
  struct wpa_supplicant *ifs;
9649
0
  u8 bssid[ETH_ALEN];
9650
0
  unsigned int idx = 0, i;
9651
9652
0
  wpa_dbg(wpa_s, MSG_DEBUG,
9653
0
    "Determining shared radio frequencies (max len %u)", len);
9654
0
  os_memset(freqs_data, 0, sizeof(struct wpa_used_freq_data) * len);
9655
9656
0
  dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
9657
0
       radio_list) {
9658
0
    int freqs[MAX_NUM_MLD_LINKS];
9659
0
    unsigned int j, n_freqs = 0;
9660
9661
0
    if (idx == len)
9662
0
      break;
9663
9664
0
    if (exclude_current && ifs == wpa_s)
9665
0
      continue;
9666
9667
0
    if (!ifs->current_ssid ||
9668
0
        (!ifs->assoc_freq && !ifs->valid_links))
9669
0
      continue;
9670
9671
0
    if (ifs->current_ssid->mode == WPAS_MODE_AP ||
9672
0
        ifs->current_ssid->mode == WPAS_MODE_P2P_GO ||
9673
0
        ifs->current_ssid->mode == WPAS_MODE_MESH) {
9674
0
      freqs[n_freqs++] = ifs->current_ssid->frequency;
9675
0
    } else if (ifs->valid_links) {
9676
0
      struct driver_sta_mlo_info drv_mlo;
9677
9678
0
      os_memset(&drv_mlo, 0, sizeof(drv_mlo));
9679
9680
0
      if (wpas_drv_get_sta_mlo_info(ifs, &drv_mlo)) {
9681
0
        wpa_dbg(wpa_s, MSG_INFO,
9682
0
          "Failed to get MLO link info");
9683
0
        continue;
9684
0
      }
9685
9686
0
      if (!drv_mlo.valid_links)
9687
0
        continue;
9688
9689
0
      for_each_link(drv_mlo.valid_links, j) {
9690
0
        if (!drv_mlo.links[j].freq)
9691
0
          continue;
9692
9693
0
        freqs[n_freqs++] = drv_mlo.links[j].freq;
9694
0
      }
9695
0
    } else if (wpa_drv_get_bssid(ifs, bssid) == 0) {
9696
0
      freqs[n_freqs++] = ifs->assoc_freq;
9697
0
    } else {
9698
0
      continue;
9699
0
    }
9700
9701
    /* Hold only distinct freqs */
9702
0
    for (j = 0; j < n_freqs && idx < len; j++) {
9703
0
      for (i = 0; i < idx; i++)
9704
0
        if (freqs_data[i].freq == freqs[j])
9705
0
          break;
9706
9707
0
      if (i == idx)
9708
0
        freqs_data[idx++].freq = freqs[j];
9709
9710
0
      if (ifs->current_ssid->mode == WPAS_MODE_INFRA) {
9711
0
        freqs_data[i].flags |=
9712
0
          ifs->current_ssid->p2p_group ?
9713
0
          WPA_FREQ_USED_BY_P2P_CLIENT :
9714
0
          WPA_FREQ_USED_BY_INFRA_STATION;
9715
0
      }
9716
0
    }
9717
0
  }
9718
9719
0
  dump_freq_data(wpa_s, "completed iteration", freqs_data, idx);
9720
0
  return idx;
9721
0
}
9722
9723
9724
/*
9725
 * Find the operating frequencies of any of the virtual interfaces that
9726
 * are using the same radio as the current interface.
9727
 */
9728
int get_shared_radio_freqs(struct wpa_supplicant *wpa_s,
9729
         int *freq_array, unsigned int len,
9730
         bool exclude_current)
9731
0
{
9732
0
  struct wpa_used_freq_data *freqs_data;
9733
0
  int num, i;
9734
9735
0
  os_memset(freq_array, 0, sizeof(int) * len);
9736
9737
0
  freqs_data = os_calloc(len, sizeof(struct wpa_used_freq_data));
9738
0
  if (!freqs_data)
9739
0
    return -1;
9740
9741
0
  num = get_shared_radio_freqs_data(wpa_s, freqs_data, len,
9742
0
            exclude_current);
9743
0
  for (i = 0; i < num; i++)
9744
0
    freq_array[i] = freqs_data[i].freq;
9745
9746
0
  os_free(freqs_data);
9747
9748
0
  return num;
9749
0
}
9750
9751
9752
struct wpa_supplicant *
9753
wpas_vendor_elem(struct wpa_supplicant *wpa_s, enum wpa_vendor_elem_frame frame)
9754
0
{
9755
0
  switch (frame) {
9756
#ifdef CONFIG_P2P
9757
  case VENDOR_ELEM_PROBE_REQ_P2P:
9758
  case VENDOR_ELEM_PROBE_RESP_P2P:
9759
  case VENDOR_ELEM_PROBE_RESP_P2P_GO:
9760
  case VENDOR_ELEM_BEACON_P2P_GO:
9761
  case VENDOR_ELEM_P2P_PD_REQ:
9762
  case VENDOR_ELEM_P2P_PD_RESP:
9763
  case VENDOR_ELEM_P2P_GO_NEG_REQ:
9764
  case VENDOR_ELEM_P2P_GO_NEG_RESP:
9765
  case VENDOR_ELEM_P2P_GO_NEG_CONF:
9766
  case VENDOR_ELEM_P2P_INV_REQ:
9767
  case VENDOR_ELEM_P2P_INV_RESP:
9768
  case VENDOR_ELEM_P2P_ASSOC_REQ:
9769
  case VENDOR_ELEM_P2P_ASSOC_RESP:
9770
    return wpa_s->p2pdev;
9771
#endif /* CONFIG_P2P */
9772
0
  default:
9773
0
    return wpa_s;
9774
0
  }
9775
0
}
9776
9777
9778
void wpas_vendor_elem_update(struct wpa_supplicant *wpa_s)
9779
0
{
9780
0
  unsigned int i;
9781
0
  char buf[30];
9782
9783
0
  wpa_printf(MSG_DEBUG, "Update vendor elements");
9784
9785
0
  for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) {
9786
0
    if (wpa_s->vendor_elem[i]) {
9787
0
      int res;
9788
9789
0
      res = os_snprintf(buf, sizeof(buf), "frame[%u]", i);
9790
0
      if (!os_snprintf_error(sizeof(buf), res)) {
9791
0
        wpa_hexdump_buf(MSG_DEBUG, buf,
9792
0
            wpa_s->vendor_elem[i]);
9793
0
      }
9794
0
    }
9795
0
  }
9796
9797
#ifdef CONFIG_P2P
9798
  if (wpa_s->parent == wpa_s &&
9799
      wpa_s->global->p2p &&
9800
      !wpa_s->global->p2p_disabled)
9801
    p2p_set_vendor_elems(wpa_s->global->p2p, wpa_s->vendor_elem);
9802
#endif /* CONFIG_P2P */
9803
0
}
9804
9805
9806
int wpas_vendor_elem_remove(struct wpa_supplicant *wpa_s, int frame,
9807
          const u8 *elem, size_t len)
9808
0
{
9809
0
  u8 *ie, *end;
9810
9811
0
  ie = wpabuf_mhead_u8(wpa_s->vendor_elem[frame]);
9812
0
  end = ie + wpabuf_len(wpa_s->vendor_elem[frame]);
9813
9814
0
  for (; ie + 1 < end; ie += 2 + ie[1]) {
9815
0
    if (ie + len > end)
9816
0
      break;
9817
0
    if (os_memcmp(ie, elem, len) != 0)
9818
0
      continue;
9819
9820
0
    if (wpabuf_len(wpa_s->vendor_elem[frame]) == len) {
9821
0
      wpabuf_free(wpa_s->vendor_elem[frame]);
9822
0
      wpa_s->vendor_elem[frame] = NULL;
9823
0
    } else {
9824
0
      os_memmove(ie, ie + len, end - (ie + len));
9825
0
      wpa_s->vendor_elem[frame]->used -= len;
9826
0
    }
9827
0
    wpas_vendor_elem_update(wpa_s);
9828
0
    return 0;
9829
0
  }
9830
9831
0
  return -1;
9832
0
}
9833
9834
9835
struct hostapd_hw_modes * get_mode(struct hostapd_hw_modes *modes,
9836
           u16 num_modes, enum hostapd_hw_mode mode,
9837
           bool is_6ghz)
9838
0
{
9839
0
  u16 i;
9840
9841
0
  if (!modes)
9842
0
    return NULL;
9843
9844
0
  for (i = 0; i < num_modes; i++) {
9845
0
    if (modes[i].mode != mode ||
9846
0
        !modes[i].num_channels || !modes[i].channels)
9847
0
      continue;
9848
0
    if (is_6ghz == modes[i].is_6ghz)
9849
0
      return &modes[i];
9850
0
  }
9851
9852
0
  return NULL;
9853
0
}
9854
9855
9856
struct hostapd_hw_modes * get_mode_with_freq(struct hostapd_hw_modes *modes,
9857
               u16 num_modes, int freq)
9858
0
{
9859
0
  int i, j;
9860
9861
0
  for (i = 0; i < num_modes; i++) {
9862
0
    for (j = 0; j < modes[i].num_channels; j++) {
9863
0
      if (freq == modes[i].channels[j].freq)
9864
0
        return &modes[i];
9865
0
    }
9866
0
  }
9867
9868
0
  return NULL;
9869
0
}
9870
9871
9872
static struct
9873
wpa_bss_tmp_disallowed * wpas_get_disallowed_bss(struct wpa_supplicant *wpa_s,
9874
             const u8 *bssid)
9875
0
{
9876
0
  struct wpa_bss_tmp_disallowed *bss;
9877
9878
0
  dl_list_for_each(bss, &wpa_s->bss_tmp_disallowed,
9879
0
       struct wpa_bss_tmp_disallowed, list) {
9880
0
    if (ether_addr_equal(bssid, bss->bssid))
9881
0
      return bss;
9882
0
  }
9883
9884
0
  return NULL;
9885
0
}
9886
9887
9888
static int wpa_set_driver_tmp_disallow_list(struct wpa_supplicant *wpa_s)
9889
0
{
9890
0
  struct wpa_bss_tmp_disallowed *tmp;
9891
0
  unsigned int num_bssid = 0;
9892
0
  u8 *bssids;
9893
0
  int ret;
9894
9895
0
  bssids = os_malloc(dl_list_len(&wpa_s->bss_tmp_disallowed) * ETH_ALEN);
9896
0
  if (!bssids)
9897
0
    return -1;
9898
0
  dl_list_for_each(tmp, &wpa_s->bss_tmp_disallowed,
9899
0
       struct wpa_bss_tmp_disallowed, list) {
9900
0
    os_memcpy(&bssids[num_bssid * ETH_ALEN], tmp->bssid,
9901
0
        ETH_ALEN);
9902
0
    num_bssid++;
9903
0
  }
9904
0
  ret = wpa_drv_set_bssid_tmp_disallow(wpa_s, num_bssid, bssids);
9905
0
  os_free(bssids);
9906
0
  return ret;
9907
0
}
9908
9909
9910
static void wpa_bss_tmp_disallow_timeout(void *eloop_ctx, void *timeout_ctx)
9911
0
{
9912
0
  struct wpa_supplicant *wpa_s = eloop_ctx;
9913
0
  struct wpa_bss_tmp_disallowed *tmp, *bss = timeout_ctx;
9914
9915
  /* Make sure the bss is not already freed */
9916
0
  dl_list_for_each(tmp, &wpa_s->bss_tmp_disallowed,
9917
0
       struct wpa_bss_tmp_disallowed, list) {
9918
0
    if (bss == tmp) {
9919
0
      remove_bss_tmp_disallowed_entry(wpa_s, tmp);
9920
0
      wpa_set_driver_tmp_disallow_list(wpa_s);
9921
0
      break;
9922
0
    }
9923
0
  }
9924
0
}
9925
9926
9927
void wpa_bss_tmp_disallow(struct wpa_supplicant *wpa_s, const u8 *bssid,
9928
        unsigned int sec, int rssi_threshold)
9929
0
{
9930
0
  struct wpa_bss_tmp_disallowed *bss;
9931
9932
0
  bss = wpas_get_disallowed_bss(wpa_s, bssid);
9933
0
  if (bss) {
9934
0
    eloop_cancel_timeout(wpa_bss_tmp_disallow_timeout, wpa_s, bss);
9935
0
    goto finish;
9936
0
  }
9937
9938
0
  bss = os_malloc(sizeof(*bss));
9939
0
  if (!bss) {
9940
0
    wpa_printf(MSG_DEBUG,
9941
0
         "Failed to allocate memory for temp disallow BSS");
9942
0
    return;
9943
0
  }
9944
9945
0
  os_memcpy(bss->bssid, bssid, ETH_ALEN);
9946
0
  dl_list_add(&wpa_s->bss_tmp_disallowed, &bss->list);
9947
0
  wpa_set_driver_tmp_disallow_list(wpa_s);
9948
9949
0
finish:
9950
0
  bss->rssi_threshold = rssi_threshold;
9951
0
  eloop_register_timeout(sec, 0, wpa_bss_tmp_disallow_timeout,
9952
0
             wpa_s, bss);
9953
0
}
9954
9955
9956
int wpa_is_bss_tmp_disallowed(struct wpa_supplicant *wpa_s,
9957
            struct wpa_bss *bss)
9958
0
{
9959
0
  struct wpa_bss_tmp_disallowed *disallowed = NULL, *tmp, *prev;
9960
9961
0
  dl_list_for_each_safe(tmp, prev, &wpa_s->bss_tmp_disallowed,
9962
0
       struct wpa_bss_tmp_disallowed, list) {
9963
0
    if (ether_addr_equal(bss->bssid, tmp->bssid)) {
9964
0
      disallowed = tmp;
9965
0
      break;
9966
0
    }
9967
0
  }
9968
0
  if (!disallowed)
9969
0
    return 0;
9970
9971
0
  if (disallowed->rssi_threshold != 0 &&
9972
0
      bss->level > disallowed->rssi_threshold) {
9973
0
    remove_bss_tmp_disallowed_entry(wpa_s, disallowed);
9974
0
    wpa_set_driver_tmp_disallow_list(wpa_s);
9975
0
    return 0;
9976
0
  }
9977
9978
0
  return 1;
9979
0
}
9980
9981
9982
int wpas_enable_mac_addr_randomization(struct wpa_supplicant *wpa_s,
9983
               unsigned int type, const u8 *addr,
9984
               const u8 *mask)
9985
0
{
9986
0
  if ((addr && !mask) || (!addr && mask)) {
9987
0
    wpa_printf(MSG_INFO,
9988
0
         "MAC_ADDR_RAND_SCAN invalid addr/mask combination");
9989
0
    return -1;
9990
0
  }
9991
9992
0
  if (addr && mask && (!(mask[0] & 0x01) || (addr[0] & 0x01))) {
9993
0
    wpa_printf(MSG_INFO,
9994
0
         "MAC_ADDR_RAND_SCAN cannot allow multicast address");
9995
0
    return -1;
9996
0
  }
9997
9998
0
  if (type & MAC_ADDR_RAND_SCAN) {
9999
0
    if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCAN,
10000
0
            addr, mask))
10001
0
      return -1;
10002
0
  }
10003
10004
0
  if (type & MAC_ADDR_RAND_SCHED_SCAN) {
10005
0
    if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCHED_SCAN,
10006
0
            addr, mask))
10007
0
      return -1;
10008
10009
0
    if (wpa_s->sched_scanning && !wpa_s->pno)
10010
0
      wpas_scan_restart_sched_scan(wpa_s);
10011
0
  }
10012
10013
0
  if (type & MAC_ADDR_RAND_PNO) {
10014
0
    if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_PNO,
10015
0
            addr, mask))
10016
0
      return -1;
10017
10018
0
    if (wpa_s->pno) {
10019
0
      wpas_stop_pno(wpa_s);
10020
0
      wpas_start_pno(wpa_s);
10021
0
    }
10022
0
  }
10023
10024
0
  return 0;
10025
0
}
10026
10027
10028
int wpas_disable_mac_addr_randomization(struct wpa_supplicant *wpa_s,
10029
          unsigned int type)
10030
0
{
10031
0
  wpas_mac_addr_rand_scan_clear(wpa_s, type);
10032
0
  if (wpa_s->pno) {
10033
0
    if (type & MAC_ADDR_RAND_PNO) {
10034
0
      wpas_stop_pno(wpa_s);
10035
0
      wpas_start_pno(wpa_s);
10036
0
    }
10037
0
  } else if (wpa_s->sched_scanning && (type & MAC_ADDR_RAND_SCHED_SCAN)) {
10038
0
    wpas_scan_restart_sched_scan(wpa_s);
10039
0
  }
10040
10041
0
  return 0;
10042
0
}
10043
10044
10045
int wpa_drv_signal_poll(struct wpa_supplicant *wpa_s,
10046
      struct wpa_signal_info *si)
10047
0
{
10048
0
  int res;
10049
10050
0
  if (!wpa_s->driver->signal_poll)
10051
0
    return -1;
10052
10053
0
  res = wpa_s->driver->signal_poll(wpa_s->drv_priv, si);
10054
10055
#ifdef CONFIG_TESTING_OPTIONS
10056
  if (res == 0) {
10057
    struct driver_signal_override *dso;
10058
10059
    dl_list_for_each(dso, &wpa_s->drv_signal_override,
10060
         struct driver_signal_override, list) {
10061
      if (!ether_addr_equal(wpa_s->bssid, dso->bssid))
10062
        continue;
10063
      wpa_printf(MSG_DEBUG,
10064
           "Override driver signal_poll information: current_signal: %d->%d avg_signal: %d->%d avg_beacon_signal: %d->%d current_noise: %d->%d",
10065
           si->data.signal,
10066
           dso->si_current_signal,
10067
           si->data.avg_signal,
10068
           dso->si_avg_signal,
10069
           si->data.avg_beacon_signal,
10070
           dso->si_avg_beacon_signal,
10071
           si->current_noise,
10072
           dso->si_current_noise);
10073
      si->data.signal = dso->si_current_signal;
10074
      si->data.avg_signal = dso->si_avg_signal;
10075
      si->data.avg_beacon_signal = dso->si_avg_beacon_signal;
10076
      si->current_noise = dso->si_current_noise;
10077
      break;
10078
    }
10079
  }
10080
#endif /* CONFIG_TESTING_OPTIONS */
10081
10082
0
  return res;
10083
0
}
10084
10085
10086
struct wpa_scan_results *
10087
wpa_drv_get_scan_results(struct wpa_supplicant *wpa_s, const u8 *bssid)
10088
1.14k
{
10089
1.14k
  struct wpa_scan_results *scan_res;
10090
#ifdef CONFIG_TESTING_OPTIONS
10091
  size_t idx;
10092
#endif /* CONFIG_TESTING_OPTIONS */
10093
10094
1.14k
  if (wpa_s->driver->get_scan_results)
10095
0
    scan_res = wpa_s->driver->get_scan_results(wpa_s->drv_priv,
10096
0
                 bssid);
10097
1.14k
  else if (wpa_s->driver->get_scan_results2)
10098
0
    scan_res = wpa_s->driver->get_scan_results2(wpa_s->drv_priv);
10099
1.14k
  else
10100
1.14k
    return NULL;
10101
10102
10103
#ifdef CONFIG_TESTING_OPTIONS
10104
  for (idx = 0; scan_res && idx < scan_res->num; idx++) {
10105
    struct driver_signal_override *dso;
10106
    struct wpa_scan_res *res = scan_res->res[idx];
10107
10108
    dl_list_for_each(dso, &wpa_s->drv_signal_override,
10109
         struct driver_signal_override, list) {
10110
      if (!ether_addr_equal(res->bssid, dso->bssid))
10111
        continue;
10112
      wpa_printf(MSG_DEBUG,
10113
           "Override driver scan signal level %d->%d for "
10114
           MACSTR,
10115
           res->level, dso->scan_level,
10116
           MAC2STR(res->bssid));
10117
      res->flags |= WPA_SCAN_QUAL_INVALID;
10118
      if (dso->scan_level < 0)
10119
        res->flags |= WPA_SCAN_LEVEL_DBM;
10120
      else
10121
        res->flags &= ~WPA_SCAN_LEVEL_DBM;
10122
      res->level = dso->scan_level;
10123
      break;
10124
    }
10125
  }
10126
#endif /* CONFIG_TESTING_OPTIONS */
10127
10128
0
  return scan_res;
10129
1.14k
}
10130
10131
10132
bool wpas_ap_link_address(struct wpa_supplicant *wpa_s, const u8 *addr)
10133
0
{
10134
0
  int i;
10135
10136
0
  if (!wpa_s->valid_links)
10137
0
    return false;
10138
10139
0
  for_each_link(wpa_s->valid_links, i) {
10140
0
    if (ether_addr_equal(wpa_s->links[i].bssid, addr))
10141
0
      return true;
10142
0
  }
10143
10144
0
  return false;
10145
0
}
10146
10147
10148
int wpa_drv_send_action(struct wpa_supplicant *wpa_s, unsigned int freq,
10149
      unsigned int wait, const u8 *dst, const u8 *src,
10150
      const u8 *bssid, const u8 *data, size_t data_len,
10151
      int no_cck)
10152
23
{
10153
23
  if (!wpa_s->driver->send_action)
10154
23
    return -1;
10155
10156
0
  if (data_len > 0 && data[0] != WLAN_ACTION_PUBLIC) {
10157
0
    if (wpas_ap_link_address(wpa_s, dst))
10158
0
      dst = wpa_s->ap_mld_addr;
10159
10160
0
    if (wpas_ap_link_address(wpa_s, bssid))
10161
0
      bssid = wpa_s->ap_mld_addr;
10162
0
  }
10163
10164
0
  return wpa_s->driver->send_action(wpa_s->drv_priv, freq, wait, dst, src,
10165
0
            bssid, data, data_len, no_cck, -1);
10166
23
}
10167
10168
10169
bool wpas_is_6ghz_supported(struct wpa_supplicant *wpa_s, bool only_enabled)
10170
0
{
10171
0
  struct hostapd_channel_data *chnl;
10172
0
  int i, j;
10173
10174
0
  for (i = 0; i < wpa_s->hw.num_modes; i++) {
10175
0
    if (wpa_s->hw.modes[i].mode == HOSTAPD_MODE_IEEE80211A) {
10176
0
      chnl = wpa_s->hw.modes[i].channels;
10177
0
      for (j = 0; j < wpa_s->hw.modes[i].num_channels; j++) {
10178
0
        if (only_enabled &&
10179
0
            (chnl[j].flag & HOSTAPD_CHAN_DISABLED))
10180
0
          continue;
10181
0
        if (is_6ghz_freq(chnl[j].freq))
10182
0
          return true;
10183
0
      }
10184
0
    }
10185
0
  }
10186
10187
0
  return false;
10188
0
}
10189
10190
10191
bool wpas_ap_supports_rsn_overriding(struct wpa_supplicant *wpa_s,
10192
             struct wpa_bss *bss)
10193
0
{
10194
0
  int i;
10195
10196
0
  if (!bss)
10197
0
    return false;
10198
0
  if (wpa_bss_get_vendor_ie(bss, RSNE_OVERRIDE_IE_VENDOR_TYPE) ||
10199
0
      wpa_bss_get_vendor_ie(bss, RSNE_OVERRIDE_2_IE_VENDOR_TYPE))
10200
0
    return true;
10201
10202
0
  if (!wpa_s->valid_links)
10203
0
    return false;
10204
10205
0
  for_each_link(wpa_s->valid_links, i) {
10206
0
    if (wpa_s->links[i].bss &&
10207
0
        (wpa_bss_get_vendor_ie(wpa_s->links[i].bss,
10208
0
             RSNE_OVERRIDE_IE_VENDOR_TYPE) ||
10209
0
         wpa_bss_get_vendor_ie(wpa_s->links[i].bss,
10210
0
             RSNE_OVERRIDE_2_IE_VENDOR_TYPE)))
10211
0
      return true;
10212
0
  }
10213
10214
0
  return false;
10215
0
}
10216
10217
10218
bool wpas_ap_supports_rsn_overriding_2(struct wpa_supplicant *wpa_s,
10219
               struct wpa_bss *bss)
10220
0
{
10221
0
  int i;
10222
10223
0
  if (!bss)
10224
0
    return false;
10225
0
  if (wpa_bss_get_vendor_ie(bss, RSNE_OVERRIDE_2_IE_VENDOR_TYPE))
10226
0
    return true;
10227
10228
0
  if (!wpa_s->valid_links)
10229
0
    return false;
10230
10231
0
  for_each_link(wpa_s->valid_links, i) {
10232
0
    if (wpa_s->links[i].bss &&
10233
0
        wpa_bss_get_vendor_ie(wpa_s->links[i].bss,
10234
0
            RSNE_OVERRIDE_2_IE_VENDOR_TYPE))
10235
0
      return true;
10236
0
  }
10237
10238
0
  return false;
10239
0
}
10240
10241
10242
int wpas_get_owe_trans_network(const u8 *owe_ie, const u8 **bssid,
10243
             const u8 **ssid, size_t *ssid_len)
10244
0
{
10245
#ifdef CONFIG_OWE
10246
  const u8 *pos, *end;
10247
  u8 ssid_len_tmp;
10248
10249
  if (!owe_ie)
10250
    return -1;
10251
10252
  pos = owe_ie + 6;
10253
  end = owe_ie + 2 + owe_ie[1];
10254
10255
  if (end - pos < ETH_ALEN + 1)
10256
    return -1;
10257
  *bssid = pos;
10258
  pos += ETH_ALEN;
10259
  ssid_len_tmp = *pos++;
10260
  if (end - pos < ssid_len_tmp || ssid_len_tmp > SSID_MAX_LEN)
10261
    return -1;
10262
10263
  *ssid = pos;
10264
  *ssid_len = ssid_len_tmp;
10265
10266
  return 0;
10267
#else /* CONFIG_OWE */
10268
0
  return -1;
10269
0
#endif /* CONFIG_OWE */
10270
0
}
10271
10272
10273
void wpas_update_dfs_ap_info(struct wpa_supplicant *wpa_s, int freq,
10274
           enum chan_width ap_ch_width,
10275
           bool disconnect_evt)
10276
0
{
10277
0
  if (disconnect_evt) {
10278
0
    wpa_printf(MSG_DEBUG, "Disconnect event of DFS AP");
10279
0
    wpa_s->sta_connected_freq = 0;
10280
0
    wpa_s->sta_connected_chan_width = CHAN_WIDTH_UNKNOWN;
10281
0
  } else {
10282
0
    wpa_s->sta_connected_freq = freq;
10283
0
    wpa_s->sta_connected_chan_width = ap_ch_width;
10284
0
  }
10285
0
  wpa_s->dfs_ap_connected = !disconnect_evt;
10286
10287
#ifdef CONFIG_P2P
10288
  if (wpa_s->global->p2p)
10289
    p2p_update_dfs_ap_info(wpa_s->global->p2p, freq, ap_ch_width,
10290
               disconnect_evt);
10291
#endif /* CONFIG_P2P */
10292
0
}
10293
10294
10295
void wpas_configure_frame_filters(struct wpa_supplicant *wpa_s)
10296
0
{
10297
0
  struct wpa_bss *bss = wpa_s->current_bss;
10298
0
  u32 filter = 0;
10299
0
  bool hs20, proxy_arp_capa;
10300
10301
0
  if (!bss)
10302
0
    return;
10303
10304
0
#ifdef CONFIG_HS20
10305
0
  hs20 = is_hs20_network(wpa_s, wpa_s->current_ssid, bss);
10306
#else /* CONFIG_HS20 */
10307
  hs20 = false;
10308
#endif /* CONFIG_HS20 */
10309
10310
0
  if (wpa_s->current_ssid &&
10311
0
      wpa_s->current_ssid->drop_unicast_ip_in_l2_multicast) {
10312
0
    filter |= WPA_DATA_FRAME_FILTER_FLAG_GTK;
10313
0
  } else if (!hs20) {
10314
    /* Not configuring frame filtering - BSS is not a Hotspot 2.0
10315
     * network */
10316
0
    return;
10317
0
  } else {
10318
0
#ifdef CONFIG_HS20
10319
0
    const u8 *ie;
10320
10321
0
    ie = wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE);
10322
10323
    /* Check if DGAF disabled bit is zero (5th byte in the IE) */
10324
0
    if (!ie || ie[1] < 5)
10325
0
      wpa_printf(MSG_DEBUG,
10326
0
           "Not configuring frame filtering - Can't extract DGAF bit");
10327
0
    else if (!(ie[6] & HS20_DGAF_DISABLED))
10328
0
      filter |= WPA_DATA_FRAME_FILTER_FLAG_GTK;
10329
0
#endif /* CONFIG_HS20 */
10330
0
  }
10331
10332
0
  proxy_arp_capa = wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_PROXY_ARP);
10333
10334
0
  if ((hs20 && proxy_arp_capa) ||
10335
0
      (wpa_s->current_ssid &&
10336
0
       wpa_s->current_ssid->always_use_proxy_arp == 2) ||
10337
0
      (proxy_arp_capa && wpa_s->current_ssid &&
10338
0
       wpa_s->current_ssid->always_use_proxy_arp == 1))
10339
0
    filter |= WPA_DATA_FRAME_FILTER_FLAG_ARP |
10340
0
      WPA_DATA_FRAME_FILTER_FLAG_NA;
10341
10342
0
  wpa_drv_configure_frame_filters(wpa_s, filter);
10343
0
}