Coverage Report

Created: 2025-10-28 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hostap/wpa_supplicant/events.c
Line
Count
Source
1
/*
2
 * WPA Supplicant - Driver event processing
3
 * Copyright (c) 2003-2019, 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
9
#include "includes.h"
10
11
#include "common.h"
12
#include "utils/crc32.h"
13
#include "eapol_supp/eapol_supp_sm.h"
14
#include "rsn_supp/wpa.h"
15
#include "eloop.h"
16
#include "config.h"
17
#include "l2_packet/l2_packet.h"
18
#include "wpa_supplicant_i.h"
19
#include "driver_i.h"
20
#include "pcsc_funcs.h"
21
#include "rsn_supp/preauth.h"
22
#include "rsn_supp/pmksa_cache.h"
23
#include "common/wpa_ctrl.h"
24
#include "eap_peer/eap.h"
25
#include "ap/hostapd.h"
26
#include "ap/sta_info.h"
27
#include "p2p/p2p.h"
28
#include "fst/fst.h"
29
#include "wnm_sta.h"
30
#include "notify.h"
31
#include "common/ieee802_11_defs.h"
32
#include "common/ieee802_11_common.h"
33
#include "common/gas_server.h"
34
#include "common/dpp.h"
35
#include "common/ptksa_cache.h"
36
#include "crypto/random.h"
37
#include "bssid_ignore.h"
38
#include "wpas_glue.h"
39
#include "wps_supplicant.h"
40
#include "ibss_rsn.h"
41
#include "sme.h"
42
#include "gas_query.h"
43
#include "p2p_supplicant.h"
44
#include "bgscan.h"
45
#include "autoscan.h"
46
#include "ap.h"
47
#include "bss.h"
48
#include "scan.h"
49
#include "offchannel.h"
50
#include "interworking.h"
51
#include "mesh.h"
52
#include "mesh_mpm.h"
53
#include "wmm_ac.h"
54
#include "nan_usd.h"
55
#include "dpp_supplicant.h"
56
#include "pr_supplicant.h"
57
58
59
#define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
60
61
62
#ifndef CONFIG_NO_SCAN_PROCESSING
63
static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
64
                int new_scan, int own_request,
65
                bool trigger_6ghz_scan,
66
                union wpa_event_data *data);
67
#endif /* CONFIG_NO_SCAN_PROCESSING */
68
69
70
int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
71
0
{
72
0
  struct os_reltime now;
73
74
0
  if (ssid == NULL || ssid->disabled_until.sec == 0)
75
0
    return 0;
76
77
0
  os_get_reltime(&now);
78
0
  if (ssid->disabled_until.sec > now.sec)
79
0
    return ssid->disabled_until.sec - now.sec;
80
81
0
  wpas_clear_temp_disabled(wpa_s, ssid, 0);
82
83
0
  return 0;
84
0
}
85
86
87
#ifndef CONFIG_NO_SCAN_PROCESSING
88
/**
89
 * wpas_reenabled_network_time - Time until first network is re-enabled
90
 * @wpa_s: Pointer to wpa_supplicant data
91
 * Returns: If all enabled networks are temporarily disabled, returns the time
92
 *  (in sec) until the first network is re-enabled. Otherwise returns 0.
93
 *
94
 * This function is used in case all enabled networks are temporarily disabled,
95
 * in which case it returns the time (in sec) that the first network will be
96
 * re-enabled. The function assumes that at least one network is enabled.
97
 */
98
static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
99
0
{
100
0
  struct wpa_ssid *ssid;
101
0
  int disabled_for, res = 0;
102
103
0
#ifdef CONFIG_INTERWORKING
104
0
  if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
105
0
      wpa_s->conf->cred)
106
0
    return 0;
107
0
#endif /* CONFIG_INTERWORKING */
108
109
0
  for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
110
0
    if (ssid->disabled)
111
0
      continue;
112
113
0
    disabled_for = wpas_temp_disabled(wpa_s, ssid);
114
0
    if (!disabled_for)
115
0
      return 0;
116
117
0
    if (!res || disabled_for < res)
118
0
      res = disabled_for;
119
0
  }
120
121
0
  return res;
122
0
}
123
#endif /* CONFIG_NO_SCAN_PROCESSING */
124
125
126
void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
127
0
{
128
0
  struct wpa_supplicant *wpa_s = eloop_ctx;
129
130
0
  if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
131
0
    return;
132
133
0
  wpa_dbg(wpa_s, MSG_DEBUG,
134
0
    "Try to associate due to network getting re-enabled");
135
0
  if (wpa_supplicant_fast_associate(wpa_s) != 1) {
136
0
    wpa_supplicant_cancel_sched_scan(wpa_s);
137
0
    wpa_supplicant_req_scan(wpa_s, 0, 0);
138
0
  }
139
0
}
140
141
142
static struct wpa_bss * __wpa_supplicant_get_new_bss(
143
  struct wpa_supplicant *wpa_s, const u8 *bssid, const u8 *ssid,
144
  size_t ssid_len)
145
0
{
146
0
  if (ssid && ssid_len > 0)
147
0
    return wpa_bss_get(wpa_s, bssid, ssid, ssid_len);
148
0
  else
149
0
    return wpa_bss_get_bssid(wpa_s, bssid);
150
0
}
151
152
153
static struct wpa_bss * _wpa_supplicant_get_new_bss(
154
  struct wpa_supplicant *wpa_s, const u8 *bssid, const u8 *ssid,
155
  size_t ssid_len, bool try_update_scan_results)
156
0
{
157
0
  struct wpa_bss *bss = __wpa_supplicant_get_new_bss(wpa_s, bssid, ssid,
158
0
                 ssid_len);
159
160
0
  if (bss || !try_update_scan_results)
161
0
    return bss;
162
163
0
  wpa_supplicant_update_scan_results(wpa_s, bssid);
164
165
0
  return __wpa_supplicant_get_new_bss(wpa_s, bssid, ssid, ssid_len);
166
0
}
167
168
169
static struct wpa_bss * wpa_supplicant_get_new_bss(
170
  struct wpa_supplicant *wpa_s, const u8 *bssid)
171
0
{
172
0
  struct wpa_bss *bss = NULL;
173
0
  struct wpa_ssid *ssid = wpa_s->current_ssid;
174
0
  u8 drv_ssid[SSID_MAX_LEN];
175
0
  int res;
176
0
  bool try_update_scan_results = true;
177
178
0
  res = wpa_drv_get_ssid(wpa_s, drv_ssid);
179
0
  if (res > 0) {
180
0
    bss = _wpa_supplicant_get_new_bss(wpa_s, bssid, drv_ssid, res,
181
0
              try_update_scan_results);
182
0
    try_update_scan_results = false;
183
0
  }
184
0
  if (!bss && ssid && ssid->ssid_len > 0) {
185
0
    bss = _wpa_supplicant_get_new_bss(wpa_s, bssid, ssid->ssid,
186
0
              ssid->ssid_len,
187
0
              try_update_scan_results);
188
0
    try_update_scan_results = false;
189
0
  }
190
0
  if (!bss)
191
0
    bss = _wpa_supplicant_get_new_bss(wpa_s, bssid, NULL, 0,
192
0
              try_update_scan_results);
193
194
0
  return bss;
195
0
}
196
197
198
static struct wpa_bss *
199
wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s, const u8 *bssid)
200
0
{
201
0
  struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
202
203
0
  if (bss)
204
0
    wpa_s->current_bss = bss;
205
206
0
  return bss;
207
0
}
208
209
210
static void wpa_supplicant_update_link_bss(struct wpa_supplicant *wpa_s,
211
             u8 link_id, const u8 *bssid)
212
0
{
213
0
  struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
214
215
0
  if (bss)
216
0
    wpa_s->links[link_id].bss = bss;
217
0
}
218
219
220
static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s,
221
          union wpa_event_data *data)
222
0
{
223
0
  struct wpa_ssid *ssid, *old_ssid;
224
0
  struct wpa_bss *bss;
225
0
  u8 drv_ssid[SSID_MAX_LEN];
226
0
  size_t drv_ssid_len;
227
0
  int res;
228
229
0
  if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
230
0
    wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
231
232
0
    if (wpa_s->current_ssid->ssid_len == 0)
233
0
      return 0; /* current profile still in use */
234
0
    res = wpa_drv_get_ssid(wpa_s, drv_ssid);
235
0
    if (res < 0) {
236
0
      wpa_msg(wpa_s, MSG_INFO,
237
0
        "Failed to read SSID from driver");
238
0
      return 0; /* try to use current profile */
239
0
    }
240
0
    drv_ssid_len = res;
241
242
0
    if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
243
0
        os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
244
0
            drv_ssid_len) == 0)
245
0
      return 0; /* current profile still in use */
246
247
#ifdef CONFIG_OWE
248
    if ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
249
        wpa_s->current_bss &&
250
        (wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION) &&
251
        drv_ssid_len == wpa_s->current_bss->ssid_len &&
252
        os_memcmp(drv_ssid, wpa_s->current_bss->ssid,
253
            drv_ssid_len) == 0)
254
      return 0; /* current profile still in use */
255
#endif /* CONFIG_OWE */
256
257
0
    wpa_msg(wpa_s, MSG_DEBUG,
258
0
      "Driver-initiated BSS selection changed the SSID to %s",
259
0
      wpa_ssid_txt(drv_ssid, drv_ssid_len));
260
    /* continue selecting a new network profile */
261
0
  }
262
263
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
264
0
    "information");
265
0
  ssid = wpa_supplicant_get_ssid(wpa_s);
266
0
  if (ssid == NULL) {
267
0
    wpa_msg(wpa_s, MSG_INFO,
268
0
      "No network configuration found for the current AP");
269
0
    return -1;
270
0
  }
271
272
0
  if (wpas_network_disabled(wpa_s, ssid)) {
273
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
274
0
    return -1;
275
0
  }
276
277
0
  if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
278
0
      disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
279
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
280
0
    return -1;
281
0
  }
282
283
0
  res = wpas_temp_disabled(wpa_s, ssid);
284
0
  if (res > 0) {
285
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
286
0
      "disabled for %d second(s)", res);
287
0
    return -1;
288
0
  }
289
290
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
291
0
    "current AP");
292
0
  bss = wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
293
0
  if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
294
0
    u8 wpa_ie[80];
295
0
    size_t wpa_ie_len = sizeof(wpa_ie);
296
0
    bool skip_default_rsne;
297
298
    /* Do not override RSNE/RSNXE with the default values if the
299
     * driver indicated the actual values used in the
300
     * (Re)Association Request frame. */
301
0
    skip_default_rsne = data && data->assoc_info.req_ies;
302
0
    if (wpa_supplicant_set_suites(wpa_s, bss, ssid,
303
0
                wpa_ie, &wpa_ie_len,
304
0
                skip_default_rsne) < 0)
305
0
      wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
306
0
  } else {
307
0
    wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
308
0
  }
309
310
0
  if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
311
0
    eapol_sm_invalidate_cached_session(wpa_s->eapol);
312
0
  old_ssid = wpa_s->current_ssid;
313
0
  wpa_s->current_ssid = ssid;
314
315
0
  wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
316
0
  wpa_supplicant_initiate_eapol(wpa_s);
317
0
  if (old_ssid != wpa_s->current_ssid)
318
0
    wpas_notify_network_changed(wpa_s);
319
320
0
  return 0;
321
0
}
322
323
324
void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
325
0
{
326
0
  struct wpa_supplicant *wpa_s = eloop_ctx;
327
328
0
  if (wpa_s->countermeasures) {
329
0
    wpa_s->countermeasures = 0;
330
0
    wpa_drv_set_countermeasures(wpa_s, 0);
331
0
    wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
332
333
    /*
334
     * It is possible that the device is sched scanning, which means
335
     * that a connection attempt will be done only when we receive
336
     * scan results. However, in this case, it would be preferable
337
     * to scan and connect immediately, so cancel the sched_scan and
338
     * issue a regular scan flow.
339
     */
340
0
    wpa_supplicant_cancel_sched_scan(wpa_s);
341
0
    wpa_supplicant_req_scan(wpa_s, 0, 0);
342
0
  }
343
0
}
344
345
346
void wpas_reset_mlo_info(struct wpa_supplicant *wpa_s)
347
0
{
348
0
  int i;
349
350
0
  if (!wpa_s->valid_links)
351
0
    return;
352
353
0
  wpa_s->valid_links = 0;
354
0
  wpa_s->mlo_assoc_link_id = 0;
355
0
  os_memset(wpa_s->ap_mld_addr, 0, ETH_ALEN);
356
0
  for (i = 0; i < MAX_NUM_MLD_LINKS; i++)
357
0
    wpabuf_free(wpa_s->links[i].ies);
358
0
  os_memset(wpa_s->links, 0, sizeof(wpa_s->links));
359
0
}
360
361
362
void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
363
0
{
364
0
  int bssid_changed;
365
366
0
  wnm_bss_keep_alive_deinit(wpa_s);
367
368
#ifdef CONFIG_IBSS_RSN
369
  ibss_rsn_deinit(wpa_s->ibss_rsn);
370
  wpa_s->ibss_rsn = NULL;
371
#endif /* CONFIG_IBSS_RSN */
372
373
#ifdef CONFIG_AP
374
  wpa_supplicant_ap_deinit(wpa_s);
375
#endif /* CONFIG_AP */
376
377
0
#ifdef CONFIG_HS20
378
  /* Clear possibly configured frame filters */
379
0
  wpa_drv_configure_frame_filters(wpa_s, 0);
380
0
#endif /* CONFIG_HS20 */
381
382
0
  if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
383
0
    return;
384
385
0
  if (os_reltime_initialized(&wpa_s->session_start)) {
386
0
    os_reltime_age(&wpa_s->session_start, &wpa_s->session_length);
387
0
    wpa_s->session_start.sec = 0;
388
0
    wpa_s->session_start.usec = 0;
389
0
    wpas_notify_session_length(wpa_s);
390
0
  }
391
392
0
  wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
393
0
  bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
394
0
  os_memset(wpa_s->bssid, 0, ETH_ALEN);
395
0
  os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
396
0
  sme_clear_on_disassoc(wpa_s);
397
0
  wpa_s->current_bss = NULL;
398
0
  wpa_s->assoc_freq = 0;
399
400
0
  if (bssid_changed)
401
0
    wpas_notify_bssid_changed(wpa_s);
402
403
0
  eapol_sm_notify_portEnabled(wpa_s->eapol, false);
404
0
  eapol_sm_notify_portValid(wpa_s->eapol, false);
405
0
  if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
406
0
      wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
407
0
      wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port)
408
0
    eapol_sm_notify_eap_success(wpa_s->eapol, false);
409
0
  wpa_s->drv_authorized_port = 0;
410
0
  wpa_s->ap_ies_from_associnfo = 0;
411
0
  wpa_s->current_ssid = NULL;
412
0
  eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
413
0
  wpa_s->key_mgmt = 0;
414
0
  wpa_s->allowed_key_mgmts = 0;
415
416
0
#ifndef CONFIG_NO_RRM
417
0
  wpas_rrm_reset(wpa_s);
418
0
#endif /* CONFIG_NO_RRM */
419
0
  wpa_s->wnmsleep_used = 0;
420
0
#ifdef CONFIG_WNM
421
0
  wpa_s->wnm_mode = 0;
422
0
#endif /* CONFIG_WNM */
423
0
  wnm_clear_coloc_intf_reporting(wpa_s);
424
0
  wpa_s->disable_mbo_oce = 0;
425
426
#ifdef CONFIG_TESTING_OPTIONS
427
  wpa_s->last_tk_alg = WPA_ALG_NONE;
428
  os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk));
429
#endif /* CONFIG_TESTING_OPTIONS */
430
0
  wpa_s->ieee80211ac = 0;
431
432
0
  if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0)
433
0
    wpa_s->enabled_4addr_mode = 0;
434
435
0
  wpa_s->wps_scan_done = false;
436
0
  wpas_reset_mlo_info(wpa_s);
437
0
#ifndef CONFIG_NO_ROBUST_AV
438
0
  wpas_scs_deinit(wpa_s);
439
0
#endif /* CONFIG_NO_ROBUST_AV */
440
441
#ifdef CONFIG_SME
442
  wpa_s->sme.bss_max_idle_period = 0;
443
#endif /* CONFIG_SME */
444
445
0
  wpa_s->ssid_verified = false;
446
0
  wpa_s->bigtk_set = false;
447
448
0
  wpabuf_free(wpa_s->pending_eapol_rx);
449
0
  wpa_s->pending_eapol_rx = NULL;
450
0
}
451
452
453
static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
454
0
{
455
0
  struct wpa_ie_data ie;
456
0
  int pmksa_set = -1;
457
0
  size_t i;
458
0
  struct rsn_pmksa_cache_entry *cur_pmksa;
459
460
  /* Start with assumption of no PMKSA cache entry match for cases other
461
   * than SAE. In particular, this is needed to generate the PMKSA cache
462
   * entries for Suite B cases with driver-based roaming indication. */
463
0
  cur_pmksa = pmksa_cache_get_current(wpa_s->wpa);
464
0
  if (cur_pmksa && !wpa_key_mgmt_sae(cur_pmksa->akmp))
465
0
    pmksa_cache_clear_current(wpa_s->wpa);
466
467
0
  if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
468
0
      ie.pmkid == NULL)
469
0
    return;
470
471
0
  for (i = 0; i < ie.num_pmkid; i++) {
472
0
    pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
473
0
                ie.pmkid + i * PMKID_LEN,
474
0
                NULL, NULL, 0, NULL, 0,
475
0
                true);
476
0
    if (pmksa_set == 0) {
477
0
      eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
478
0
      wpa_sm_set_pmk_from_pmksa(wpa_s->wpa);
479
0
      break;
480
0
    }
481
0
  }
482
483
0
  wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
484
0
    "PMKSA cache", pmksa_set == 0 ? "" : "not ");
485
0
}
486
487
488
static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
489
             union wpa_event_data *data)
490
0
{
491
0
  if (data == NULL) {
492
0
    wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
493
0
      "event");
494
0
    return;
495
0
  }
496
0
  wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
497
0
    " index=%d preauth=%d",
498
0
    MAC2STR(data->pmkid_candidate.bssid),
499
0
    data->pmkid_candidate.index,
500
0
    data->pmkid_candidate.preauth);
501
502
0
  pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
503
0
          data->pmkid_candidate.index,
504
0
          data->pmkid_candidate.preauth);
505
0
}
506
507
508
static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
509
0
{
510
0
  if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
511
0
      wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
512
0
    return 0;
513
514
0
#ifdef IEEE8021X_EAPOL
515
0
  if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
516
0
      wpa_s->current_ssid &&
517
0
      !(wpa_s->current_ssid->eapol_flags &
518
0
        (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
519
0
         EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
520
    /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
521
     * plaintext or static WEP keys). */
522
0
    return 0;
523
0
  }
524
0
#endif /* IEEE8021X_EAPOL */
525
526
0
  return 1;
527
0
}
528
529
530
/**
531
 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
532
 * @wpa_s: pointer to wpa_supplicant data
533
 * @ssid: Configuration data for the network
534
 * Returns: 0 on success, -1 on failure
535
 *
536
 * This function is called when starting authentication with a network that is
537
 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
538
 */
539
int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
540
            struct wpa_ssid *ssid)
541
0
{
542
0
#ifdef IEEE8021X_EAPOL
543
#ifdef PCSC_FUNCS
544
  int aka = 0, sim = 0;
545
546
  if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
547
      wpa_s->scard != NULL || wpa_s->conf->external_sim)
548
    return 0;
549
550
  if (ssid == NULL || ssid->eap.eap_methods == NULL) {
551
    sim = 1;
552
    aka = 1;
553
  } else {
554
    struct eap_method_type *eap = ssid->eap.eap_methods;
555
    while (eap->vendor != EAP_VENDOR_IETF ||
556
           eap->method != EAP_TYPE_NONE) {
557
      if (eap->vendor == EAP_VENDOR_IETF) {
558
        if (eap->method == EAP_TYPE_SIM)
559
          sim = 1;
560
        else if (eap->method == EAP_TYPE_AKA ||
561
           eap->method == EAP_TYPE_AKA_PRIME)
562
          aka = 1;
563
      }
564
      eap++;
565
    }
566
  }
567
568
  if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
569
    sim = 0;
570
  if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
571
      eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
572
      NULL)
573
    aka = 0;
574
575
  if (!sim && !aka) {
576
    wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
577
      "use SIM, but neither EAP-SIM nor EAP-AKA are "
578
      "enabled");
579
    return 0;
580
  }
581
582
  wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
583
    "(sim=%d aka=%d) - initialize PCSC", sim, aka);
584
585
  wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
586
  if (wpa_s->scard == NULL) {
587
    wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
588
      "(pcsc-lite)");
589
    return -1;
590
  }
591
  wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
592
  eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
593
#endif /* PCSC_FUNCS */
594
0
#endif /* IEEE8021X_EAPOL */
595
596
0
  return 0;
597
0
}
598
599
600
#ifndef CONFIG_NO_SCAN_PROCESSING
601
602
#ifdef CONFIG_WEP
603
static int has_wep_key(struct wpa_ssid *ssid)
604
{
605
  int i;
606
607
  for (i = 0; i < NUM_WEP_KEYS; i++) {
608
    if (ssid->wep_key_len[i])
609
      return 1;
610
  }
611
612
  return 0;
613
}
614
#endif /* CONFIG_WEP */
615
616
617
static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
618
          struct wpa_ssid *ssid)
619
0
{
620
0
  int privacy = 0;
621
622
0
  if (ssid->mixed_cell)
623
0
    return 1;
624
625
#ifdef CONFIG_WPS
626
  if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
627
    return 1;
628
#endif /* CONFIG_WPS */
629
630
#ifdef CONFIG_OWE
631
  if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only)
632
    return 1;
633
#endif /* CONFIG_OWE */
634
635
#ifdef CONFIG_WEP
636
  if (has_wep_key(ssid))
637
    privacy = 1;
638
#endif /* CONFIG_WEP */
639
640
0
#ifdef IEEE8021X_EAPOL
641
0
  if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
642
0
      ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
643
0
         EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
644
0
    privacy = 1;
645
0
#endif /* IEEE8021X_EAPOL */
646
647
0
  if (wpa_key_mgmt_wpa(ssid->key_mgmt))
648
0
    privacy = 1;
649
650
0
  if (bss->caps & IEEE80211_CAP_PRIVACY)
651
0
    return privacy;
652
0
  return !privacy;
653
0
}
654
655
656
static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
657
           struct wpa_ssid *ssid,
658
           struct wpa_bss *bss, int debug_print)
659
0
{
660
0
  struct wpa_ie_data ie;
661
0
  int proto_match = 0;
662
0
  const u8 *rsn_ie, *wpa_ie;
663
0
  int ret;
664
#ifdef CONFIG_WEP
665
  int wep_ok;
666
#endif /* CONFIG_WEP */
667
0
  bool is_6ghz_bss = is_6ghz_freq(bss->freq);
668
669
0
  ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
670
0
  if (ret >= 0)
671
0
    return ret;
672
673
#ifdef CONFIG_WEP
674
  /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
675
  wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
676
    (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
677
      ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
678
     (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
679
#endif /* CONFIG_WEP */
680
681
0
  rsn_ie = wpa_bss_get_rsne(wpa_s, bss, ssid, false);
682
0
  if (is_6ghz_bss && !rsn_ie) {
683
0
    if (debug_print)
684
0
      wpa_dbg(wpa_s, MSG_DEBUG,
685
0
        "   skip - 6 GHz BSS without RSNE");
686
0
    return 0;
687
0
  }
688
689
0
  while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
690
0
    proto_match++;
691
692
0
    if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
693
0
      if (debug_print)
694
0
        wpa_dbg(wpa_s, MSG_DEBUG,
695
0
          "   skip RSN IE - parse failed");
696
0
      break;
697
0
    }
698
0
    if (!ie.has_pairwise)
699
0
      ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq);
700
0
    if (!ie.has_group)
701
0
      ie.group_cipher = wpa_default_rsn_cipher(bss->freq);
702
703
0
    if (is_6ghz_bss || !is_zero_ether_addr(bss->mld_addr)) {
704
      /* WEP and TKIP are not allowed on 6 GHz/MLD */
705
0
      ie.pairwise_cipher &= ~(WPA_CIPHER_WEP40 |
706
0
            WPA_CIPHER_WEP104 |
707
0
            WPA_CIPHER_TKIP);
708
0
      ie.group_cipher &= ~(WPA_CIPHER_WEP40 |
709
0
               WPA_CIPHER_WEP104 |
710
0
               WPA_CIPHER_TKIP);
711
0
    }
712
713
#ifdef CONFIG_WEP
714
    if (wep_ok &&
715
        (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
716
    {
717
      if (debug_print)
718
        wpa_dbg(wpa_s, MSG_DEBUG,
719
          "   selected based on TSN in RSN IE");
720
      return 1;
721
    }
722
#endif /* CONFIG_WEP */
723
724
0
    if (!(ie.proto & ssid->proto)) {
725
0
      if (debug_print)
726
0
        wpa_dbg(wpa_s, MSG_DEBUG,
727
0
          "   skip RSN IE - proto mismatch");
728
0
      break;
729
0
    }
730
731
0
    if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
732
0
      if (debug_print)
733
0
        wpa_dbg(wpa_s, MSG_DEBUG,
734
0
          "   skip RSN IE - PTK cipher mismatch");
735
0
      break;
736
0
    }
737
738
0
    if (!(ie.group_cipher & ssid->group_cipher)) {
739
0
      if (debug_print)
740
0
        wpa_dbg(wpa_s, MSG_DEBUG,
741
0
          "   skip RSN IE - GTK cipher mismatch");
742
0
      break;
743
0
    }
744
745
0
    if (ssid->group_mgmt_cipher &&
746
0
        !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) {
747
0
      if (debug_print)
748
0
        wpa_dbg(wpa_s, MSG_DEBUG,
749
0
          "   skip RSN IE - group mgmt cipher mismatch");
750
0
      break;
751
0
    }
752
753
0
    if (is_6ghz_bss) {
754
      /* MFPC must be supported on 6 GHz */
755
0
      if (!(ie.capabilities & WPA_CAPABILITY_MFPC)) {
756
0
        if (debug_print)
757
0
          wpa_dbg(wpa_s, MSG_DEBUG,
758
0
            "   skip RSNE - 6 GHz without MFPC");
759
0
        break;
760
0
      }
761
762
      /* WPA PSK is not allowed on the 6 GHz band */
763
0
      ie.key_mgmt &= ~(WPA_KEY_MGMT_PSK |
764
0
           WPA_KEY_MGMT_FT_PSK |
765
0
           WPA_KEY_MGMT_PSK_SHA256);
766
0
    }
767
768
0
    if (!(ie.key_mgmt & ssid->key_mgmt)) {
769
0
      if (debug_print)
770
0
        wpa_dbg(wpa_s, MSG_DEBUG,
771
0
          "   skip RSN IE - key mgmt mismatch");
772
0
      break;
773
0
    }
774
775
0
    if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
776
0
        wpas_get_ssid_pmf(wpa_s, ssid) ==
777
0
        MGMT_FRAME_PROTECTION_REQUIRED) {
778
0
      if (debug_print)
779
0
        wpa_dbg(wpa_s, MSG_DEBUG,
780
0
          "   skip RSN IE - no mgmt frame protection");
781
0
      break;
782
0
    }
783
0
    if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
784
0
        wpas_get_ssid_pmf(wpa_s, ssid) ==
785
0
        NO_MGMT_FRAME_PROTECTION) {
786
0
      if (debug_print)
787
0
        wpa_dbg(wpa_s, MSG_DEBUG,
788
0
          "   skip RSN IE - no mgmt frame protection enabled but AP requires it");
789
0
      break;
790
0
    }
791
792
0
    if (debug_print)
793
0
      wpa_dbg(wpa_s, MSG_DEBUG,
794
0
        "   selected based on RSN IE");
795
0
    return 1;
796
0
  }
797
798
0
  if (is_6ghz_bss) {
799
0
    if (debug_print)
800
0
      wpa_dbg(wpa_s, MSG_DEBUG,
801
0
        "   skip - 6 GHz BSS without matching RSNE");
802
0
    return 0;
803
0
  }
804
805
0
  wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
806
807
0
  if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED &&
808
0
      (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) {
809
#ifdef CONFIG_OWE
810
    if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && ssid->owe_only &&
811
        !wpa_ie && !rsn_ie &&
812
        wpa_s->owe_transition_select &&
813
        wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
814
        ssid->owe_transition_bss_select_count + 1 <=
815
        MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
816
      ssid->owe_transition_bss_select_count++;
817
      if (debug_print)
818
        wpa_dbg(wpa_s, MSG_DEBUG,
819
          "   skip OWE open BSS (selection count %d does not exceed %d)",
820
          ssid->owe_transition_bss_select_count,
821
          MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
822
      wpa_s->owe_transition_search = 1;
823
      return 0;
824
    }
825
#endif /* CONFIG_OWE */
826
0
    if (debug_print)
827
0
      wpa_dbg(wpa_s, MSG_DEBUG,
828
0
        "   skip - MFP Required but network not MFP Capable");
829
0
    return 0;
830
0
  }
831
832
0
  while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
833
0
    proto_match++;
834
835
0
    if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
836
0
      if (debug_print)
837
0
        wpa_dbg(wpa_s, MSG_DEBUG,
838
0
          "   skip WPA IE - parse failed");
839
0
      break;
840
0
    }
841
842
#ifdef CONFIG_WEP
843
    if (wep_ok &&
844
        (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
845
    {
846
      if (debug_print)
847
        wpa_dbg(wpa_s, MSG_DEBUG,
848
          "   selected based on TSN in WPA IE");
849
      return 1;
850
    }
851
#endif /* CONFIG_WEP */
852
853
0
    if (!(ie.proto & ssid->proto)) {
854
0
      if (debug_print)
855
0
        wpa_dbg(wpa_s, MSG_DEBUG,
856
0
          "   skip WPA IE - proto mismatch");
857
0
      break;
858
0
    }
859
860
0
    if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
861
0
      if (debug_print)
862
0
        wpa_dbg(wpa_s, MSG_DEBUG,
863
0
          "   skip WPA IE - PTK cipher mismatch");
864
0
      break;
865
0
    }
866
867
0
    if (!(ie.group_cipher & ssid->group_cipher)) {
868
0
      if (debug_print)
869
0
        wpa_dbg(wpa_s, MSG_DEBUG,
870
0
          "   skip WPA IE - GTK cipher mismatch");
871
0
      break;
872
0
    }
873
874
0
    if (!(ie.key_mgmt & ssid->key_mgmt)) {
875
0
      if (debug_print)
876
0
        wpa_dbg(wpa_s, MSG_DEBUG,
877
0
          "   skip WPA IE - key mgmt mismatch");
878
0
      break;
879
0
    }
880
881
0
    if (debug_print)
882
0
      wpa_dbg(wpa_s, MSG_DEBUG,
883
0
        "   selected based on WPA IE");
884
0
    return 1;
885
0
  }
886
887
0
  if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
888
0
      !rsn_ie) {
889
0
    if (debug_print)
890
0
      wpa_dbg(wpa_s, MSG_DEBUG,
891
0
        "   allow for non-WPA IEEE 802.1X");
892
0
    return 1;
893
0
  }
894
895
#ifdef CONFIG_OWE
896
  if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only &&
897
      !wpa_ie && !rsn_ie) {
898
    if (wpa_s->owe_transition_select &&
899
        wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) &&
900
        ssid->owe_transition_bss_select_count + 1 <=
901
        MAX_OWE_TRANSITION_BSS_SELECT_COUNT) {
902
      ssid->owe_transition_bss_select_count++;
903
      if (debug_print)
904
        wpa_dbg(wpa_s, MSG_DEBUG,
905
          "   skip OWE transition BSS (selection count %d does not exceed %d)",
906
          ssid->owe_transition_bss_select_count,
907
          MAX_OWE_TRANSITION_BSS_SELECT_COUNT);
908
      wpa_s->owe_transition_search = 1;
909
      return 0;
910
    }
911
    if (debug_print)
912
      wpa_dbg(wpa_s, MSG_DEBUG,
913
        "   allow in OWE transition mode");
914
    return 1;
915
  }
916
#endif /* CONFIG_OWE */
917
918
0
  if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
919
0
      wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
920
0
    if (debug_print)
921
0
      wpa_dbg(wpa_s, MSG_DEBUG,
922
0
        "   skip - no WPA/RSN proto match");
923
0
    return 0;
924
0
  }
925
926
0
  if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
927
0
    if (debug_print)
928
0
      wpa_dbg(wpa_s, MSG_DEBUG, "   allow in non-WPA/WPA2");
929
0
    return 1;
930
0
  }
931
932
0
  if (debug_print)
933
0
    wpa_dbg(wpa_s, MSG_DEBUG,
934
0
      "   reject due to mismatch with WPA/WPA2");
935
936
0
  return 0;
937
0
}
938
939
940
static int freq_allowed(int *freqs, int freq)
941
0
{
942
0
  int i;
943
944
0
  if (freqs == NULL)
945
0
    return 1;
946
947
0
  for (i = 0; freqs[i]; i++)
948
0
    if (freqs[i] == freq)
949
0
      return 1;
950
0
  return 0;
951
0
}
952
953
954
static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
955
          struct wpa_bss *bss, int debug_print)
956
0
{
957
0
  const struct hostapd_hw_modes *mode = NULL, *modes;
958
0
  const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
959
0
  const u8 *rate_ie;
960
0
  int i, j, k;
961
962
0
  if (bss->freq == 0)
963
0
    return 1; /* Cannot do matching without knowing band */
964
965
0
  modes = wpa_s->hw.modes;
966
0
  if (modes == NULL) {
967
    /*
968
     * The driver does not provide any additional information
969
     * about the utilized hardware, so allow the connection attempt
970
     * to continue.
971
     */
972
0
    return 1;
973
0
  }
974
975
0
  for (i = 0; i < wpa_s->hw.num_modes; i++) {
976
0
    for (j = 0; j < modes[i].num_channels; j++) {
977
0
      int freq = modes[i].channels[j].freq;
978
0
      if (freq == bss->freq) {
979
0
        if (mode &&
980
0
            mode->mode == HOSTAPD_MODE_IEEE80211G)
981
0
          break; /* do not allow 802.11b replace
982
            * 802.11g */
983
0
        mode = &modes[i];
984
0
        break;
985
0
      }
986
0
    }
987
0
  }
988
989
0
  if (mode == NULL)
990
0
    return 0;
991
992
0
  for (i = 0; i < (int) sizeof(scan_ie); i++) {
993
0
    rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
994
0
    if (rate_ie == NULL)
995
0
      continue;
996
997
0
    for (j = 2; j < rate_ie[1] + 2; j++) {
998
0
      int flagged = !!(rate_ie[j] & 0x80);
999
0
      int r = (rate_ie[j] & 0x7f) * 5;
1000
1001
      /*
1002
       * IEEE Std 802.11n-2009 7.3.2.2:
1003
       * The new BSS Membership selector value is encoded
1004
       * like a legacy basic rate, but it is not a rate and
1005
       * only indicates if the BSS members are required to
1006
       * support the mandatory features of Clause 20 [HT PHY]
1007
       * in order to join the BSS.
1008
       */
1009
0
      if (flagged && ((rate_ie[j] & 0x7f) ==
1010
0
          BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
1011
0
        if (!ht_supported(mode)) {
1012
0
          if (debug_print)
1013
0
            wpa_dbg(wpa_s, MSG_DEBUG,
1014
0
              "   hardware does not support HT PHY");
1015
0
          return 0;
1016
0
        }
1017
0
        continue;
1018
0
      }
1019
1020
      /* There's also a VHT selector for 802.11ac */
1021
0
      if (flagged && ((rate_ie[j] & 0x7f) ==
1022
0
          BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
1023
0
        if (!vht_supported(mode)) {
1024
0
          if (debug_print)
1025
0
            wpa_dbg(wpa_s, MSG_DEBUG,
1026
0
              "   hardware does not support VHT PHY");
1027
0
          return 0;
1028
0
        }
1029
0
        continue;
1030
0
      }
1031
1032
0
      if (flagged && ((rate_ie[j] & 0x7f) ==
1033
0
          BSS_MEMBERSHIP_SELECTOR_HE_PHY)) {
1034
0
        if (!he_supported(mode, IEEE80211_MODE_INFRA)) {
1035
0
          if (debug_print)
1036
0
            wpa_dbg(wpa_s, MSG_DEBUG,
1037
0
              "   hardware does not support HE PHY");
1038
0
          return 0;
1039
0
        }
1040
0
        continue;
1041
0
      }
1042
1043
#ifdef CONFIG_SAE
1044
      if (flagged && ((rate_ie[j] & 0x7f) ==
1045
          BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) {
1046
        if (wpas_get_ssid_sae_pwe(wpa_s, ssid) ==
1047
            SAE_PWE_HUNT_AND_PECK &&
1048
            !ssid->sae_password_id &&
1049
            !is_6ghz_freq(bss->freq) &&
1050
            wpa_key_mgmt_sae(ssid->key_mgmt)) {
1051
          if (debug_print)
1052
            wpa_dbg(wpa_s, MSG_DEBUG,
1053
              "   SAE H2E disabled");
1054
#ifdef CONFIG_TESTING_OPTIONS
1055
          if (wpa_s->ignore_sae_h2e_only) {
1056
            wpa_dbg(wpa_s, MSG_DEBUG,
1057
              "TESTING: Ignore SAE H2E requirement mismatch");
1058
            continue;
1059
          }
1060
#endif /* CONFIG_TESTING_OPTIONS */
1061
          return 0;
1062
        }
1063
        continue;
1064
      }
1065
#endif /* CONFIG_SAE */
1066
1067
0
      if (!flagged)
1068
0
        continue;
1069
1070
      /* check for legacy basic rates */
1071
0
      for (k = 0; k < mode->num_rates; k++) {
1072
0
        if (mode->rates[k] == r)
1073
0
          break;
1074
0
      }
1075
0
      if (k == mode->num_rates) {
1076
        /*
1077
         * IEEE Std 802.11-2007 7.3.2.2 demands that in
1078
         * order to join a BSS all required rates
1079
         * have to be supported by the hardware.
1080
         */
1081
0
        if (debug_print)
1082
0
          wpa_dbg(wpa_s, MSG_DEBUG,
1083
0
            "   hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
1084
0
            r / 10, r % 10,
1085
0
            bss->freq, mode->mode, mode->num_rates);
1086
0
        return 0;
1087
0
      }
1088
0
    }
1089
0
  }
1090
1091
0
  return 1;
1092
0
}
1093
1094
1095
/*
1096
 * Test whether BSS is in an ESS.
1097
 * This is done differently in DMG (60 GHz) and non-DMG bands
1098
 */
1099
static int bss_is_ess(struct wpa_bss *bss)
1100
0
{
1101
0
  if (bss_is_dmg(bss)) {
1102
0
    return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
1103
0
      IEEE80211_CAP_DMG_AP;
1104
0
  }
1105
1106
0
  return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
1107
0
    IEEE80211_CAP_ESS);
1108
0
}
1109
1110
1111
static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
1112
0
{
1113
0
  size_t i;
1114
1115
0
  for (i = 0; i < ETH_ALEN; i++) {
1116
0
    if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
1117
0
      return 0;
1118
0
  }
1119
0
  return 1;
1120
0
}
1121
1122
1123
static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
1124
0
{
1125
0
  size_t i;
1126
1127
0
  for (i = 0; i < num; i++) {
1128
0
    const u8 *a = list + i * ETH_ALEN * 2;
1129
0
    const u8 *m = a + ETH_ALEN;
1130
1131
0
    if (match_mac_mask(a, addr, m))
1132
0
      return 1;
1133
0
  }
1134
0
  return 0;
1135
0
}
1136
1137
1138
static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
1139
         const u8 **ret_ssid, size_t *ret_ssid_len)
1140
0
{
1141
#ifdef CONFIG_OWE
1142
  const u8 *owe, *bssid;
1143
1144
  owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
1145
  if (!owe || !wpa_bss_get_rsne(wpa_s, bss, NULL, false))
1146
    return;
1147
1148
  if (wpas_get_owe_trans_network(owe, &bssid, ret_ssid, ret_ssid_len))
1149
    return;
1150
1151
  /* Match the profile SSID against the OWE transition mode SSID on the
1152
   * open network. */
1153
  wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR
1154
    " SSID: %s", MAC2STR(bssid),
1155
    wpa_ssid_txt(*ret_ssid, *ret_ssid_len));
1156
1157
  if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) {
1158
    struct wpa_ssid *ssid;
1159
1160
    for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1161
      if (wpas_network_disabled(wpa_s, ssid))
1162
        continue;
1163
      if (ssid->ssid_len == *ret_ssid_len &&
1164
          os_memcmp(ssid->ssid, *ret_ssid, *ret_ssid_len) ==
1165
          0) {
1166
        /* OWE BSS in transition mode for a currently
1167
         * enabled OWE network. */
1168
        wpa_dbg(wpa_s, MSG_DEBUG,
1169
          "OWE: transition mode OWE SSID for active OWE profile");
1170
        bss->flags |= WPA_BSS_OWE_TRANSITION;
1171
        break;
1172
      }
1173
    }
1174
  }
1175
#endif /* CONFIG_OWE */
1176
0
}
1177
1178
1179
static bool wpas_valid_ml_bss(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
1180
0
{
1181
0
  u16 removed_links;
1182
1183
0
  if (!bss->valid_links)
1184
0
    return true;
1185
1186
  /* Check if the current BSS is going to be removed */
1187
0
  removed_links = wpa_bss_parse_reconf_ml_element(wpa_s, bss);
1188
0
  if (BIT(bss->mld_link_id) & removed_links)
1189
0
    return false;
1190
1191
0
  return true;
1192
0
}
1193
1194
1195
int disabled_freq(struct wpa_supplicant *wpa_s, int freq)
1196
0
{
1197
0
  int i, j;
1198
1199
0
  if (!wpa_s->hw.modes || !wpa_s->hw.num_modes)
1200
0
    return 0;
1201
1202
0
  for (j = 0; j < wpa_s->hw.num_modes; j++) {
1203
0
    struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j];
1204
1205
0
    for (i = 0; i < mode->num_channels; i++) {
1206
0
      struct hostapd_channel_data *chan = &mode->channels[i];
1207
1208
0
      if (chan->freq == freq)
1209
0
        return !!(chan->flag & HOSTAPD_CHAN_DISABLED);
1210
0
    }
1211
0
  }
1212
1213
0
  return 1;
1214
0
}
1215
1216
1217
static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1218
          const u8 *match_ssid, size_t match_ssid_len,
1219
          struct wpa_bss *bss, int bssid_ignore_count,
1220
          bool debug_print, bool link);
1221
1222
1223
#ifdef CONFIG_SAE_PK
1224
static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s,
1225
            struct wpa_bss *orig_bss,
1226
            struct wpa_ssid *ssid,
1227
            const u8 *match_ssid,
1228
            size_t match_ssid_len)
1229
{
1230
  struct wpa_bss *bss;
1231
1232
  dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1233
    int count;
1234
    const u8 *ie;
1235
1236
    if (bss == orig_bss)
1237
      continue;
1238
    ie = wpa_bss_get_rsnxe(wpa_s, bss, ssid, false);
1239
    if (!(ieee802_11_rsnx_capab(ie, WLAN_RSNX_CAPAB_SAE_PK)))
1240
      continue;
1241
1242
    /* TODO: Could be more thorough in checking what kind of
1243
     * signal strength or throughput estimate would be acceptable
1244
     * compared to the originally selected BSS. */
1245
    if (bss->est_throughput < 2000)
1246
      return false;
1247
1248
    count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1249
    if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1250
            bss, count, false, false))
1251
      return true;
1252
  }
1253
1254
  return false;
1255
}
1256
#endif /* CONFIG_SAE_PK */
1257
1258
1259
static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
1260
          const u8 *match_ssid, size_t match_ssid_len,
1261
          struct wpa_bss *bss, int bssid_ignore_count,
1262
          bool debug_print, bool link)
1263
0
{
1264
0
  int res;
1265
0
  bool wpa, check_ssid = false;
1266
#ifdef CONFIG_MBO
1267
  const u8 *assoc_disallow;
1268
#endif /* CONFIG_MBO */
1269
#ifdef CONFIG_SAE
1270
  u8 rsnxe_capa = 0;
1271
  enum sae_pwe sae_pwe;
1272
#endif /* CONFIG_SAE */
1273
0
  const u8 *ie;
1274
1275
0
  ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1276
0
  wpa = ie && ie[1];
1277
0
  ie = wpa_bss_get_rsne(wpa_s, bss, ssid, false);
1278
0
  wpa |= ie && ie[1];
1279
1280
#ifdef CONFIG_SAE
1281
  ie = wpa_bss_get_rsnxe(wpa_s, bss, ssid, false);
1282
  if (ie && ie[0] == WLAN_EID_VENDOR_SPECIFIC && ie[1] >= 4 + 1)
1283
    rsnxe_capa = ie[4 + 2];
1284
  else if (ie && ie[1] >= 1)
1285
    rsnxe_capa = ie[2];
1286
#endif /* CONFIG_SAE */
1287
1288
0
  check_ssid = wpa || ssid->ssid_len > 0;
1289
1290
0
  if (wpas_network_disabled(wpa_s, ssid)) {
1291
0
    if (debug_print)
1292
0
      wpa_dbg(wpa_s, MSG_DEBUG, "   skip - disabled");
1293
0
    return false;
1294
0
  }
1295
1296
0
  res = wpas_temp_disabled(wpa_s, ssid);
1297
0
  if (res > 0) {
1298
0
    if (debug_print)
1299
0
      wpa_dbg(wpa_s, MSG_DEBUG,
1300
0
        "   skip - disabled temporarily for %d second(s)",
1301
0
        res);
1302
0
    return false;
1303
0
  }
1304
1305
#ifdef CONFIG_WPS
1306
  if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) {
1307
    if (debug_print)
1308
      wpa_dbg(wpa_s, MSG_DEBUG,
1309
        "   skip - BSSID ignored (WPS)");
1310
    return false;
1311
  }
1312
1313
  if (wpa && ssid->ssid_len == 0 &&
1314
      wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
1315
    check_ssid = false;
1316
1317
  if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
1318
    /* Only allow wildcard SSID match if an AP advertises active
1319
     * WPS operation that matches our mode. */
1320
    check_ssid = ssid->ssid_len > 0 ||
1321
      !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss);
1322
  }
1323
#endif /* CONFIG_WPS */
1324
1325
0
  if (ssid->bssid_set && ssid->ssid_len == 0 &&
1326
0
      ether_addr_equal(bss->bssid, ssid->bssid))
1327
0
    check_ssid = false;
1328
1329
0
  if (check_ssid &&
1330
0
      (match_ssid_len != ssid->ssid_len ||
1331
0
       os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) {
1332
0
    if (debug_print)
1333
0
      wpa_dbg(wpa_s, MSG_DEBUG, "   skip - SSID mismatch");
1334
0
    return false;
1335
0
  }
1336
1337
0
  if (!link && ssid->bssid_set &&
1338
0
      !ether_addr_equal(bss->bssid, ssid->bssid)) {
1339
0
    if (debug_print)
1340
0
      wpa_dbg(wpa_s, MSG_DEBUG, "   skip - BSSID mismatch");
1341
0
    return false;
1342
0
  }
1343
1344
  /* check the list of BSSIDs to ignore */
1345
0
  if (ssid->num_bssid_ignore &&
1346
0
      addr_in_list(bss->bssid, ssid->bssid_ignore,
1347
0
       ssid->num_bssid_ignore)) {
1348
0
    if (debug_print)
1349
0
      wpa_dbg(wpa_s, MSG_DEBUG,
1350
0
        "   skip - BSSID configured to be ignored");
1351
0
    return false;
1352
0
  }
1353
1354
  /* if there is a list of accepted BSSIDs, only accept those APs */
1355
0
  if (ssid->num_bssid_accept &&
1356
0
      !addr_in_list(bss->bssid, ssid->bssid_accept,
1357
0
        ssid->num_bssid_accept)) {
1358
0
    if (debug_print)
1359
0
      wpa_dbg(wpa_s, MSG_DEBUG,
1360
0
        "   skip - BSSID not in list of accepted values");
1361
0
    return false;
1362
0
  }
1363
1364
0
  if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print))
1365
0
    return false;
1366
1367
0
  if (!wpa &&
1368
0
      !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
1369
0
      !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
1370
0
      !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
1371
0
      !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
1372
0
    if (debug_print)
1373
0
      wpa_dbg(wpa_s, MSG_DEBUG,
1374
0
        "   skip - non-WPA network not allowed");
1375
0
    return false;
1376
0
  }
1377
1378
#ifdef CONFIG_WEP
1379
  if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) {
1380
    if (debug_print)
1381
      wpa_dbg(wpa_s, MSG_DEBUG,
1382
        "   skip - ignore WPA/WPA2 AP for WEP network block");
1383
    return false;
1384
  }
1385
#endif /* CONFIG_WEP */
1386
1387
0
  if (!wpa_supplicant_match_privacy(bss, ssid)) {
1388
0
    if (debug_print)
1389
0
      wpa_dbg(wpa_s, MSG_DEBUG, "   skip - privacy mismatch");
1390
0
    return false;
1391
0
  }
1392
1393
0
  if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) &&
1394
0
      !bss_is_pbss(bss)) {
1395
0
    if (debug_print)
1396
0
      wpa_dbg(wpa_s, MSG_DEBUG,
1397
0
        "   skip - not ESS, PBSS, or MBSS");
1398
0
    return false;
1399
0
  }
1400
1401
0
  if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
1402
0
    if (debug_print)
1403
0
      wpa_dbg(wpa_s, MSG_DEBUG,
1404
0
        "   skip - PBSS mismatch (ssid %d bss %d)",
1405
0
        ssid->pbss, bss_is_pbss(bss));
1406
0
    return false;
1407
0
  }
1408
1409
0
  if (!freq_allowed(ssid->freq_list, bss->freq)) {
1410
0
    if (debug_print)
1411
0
      wpa_dbg(wpa_s, MSG_DEBUG,
1412
0
        "   skip - frequency not allowed");
1413
0
    return false;
1414
0
  }
1415
1416
#ifdef CONFIG_MESH
1417
  if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 &&
1418
      ssid->frequency != bss->freq) {
1419
    if (debug_print)
1420
      wpa_dbg(wpa_s, MSG_DEBUG,
1421
        "   skip - frequency not allowed (mesh)");
1422
    return false;
1423
  }
1424
#endif /* CONFIG_MESH */
1425
1426
0
  if (!rate_match(wpa_s, ssid, bss, debug_print)) {
1427
0
    if (debug_print)
1428
0
      wpa_dbg(wpa_s, MSG_DEBUG,
1429
0
        "   skip - rate sets do not match");
1430
0
    return false;
1431
0
  }
1432
1433
#ifdef CONFIG_SAE
1434
  /* When using SAE Password Identifier and when operationg on the 6 GHz
1435
   * band, only H2E is allowed. */
1436
  sae_pwe = wpas_get_ssid_sae_pwe(wpa_s, ssid);
1437
  if ((sae_pwe == SAE_PWE_HASH_TO_ELEMENT ||
1438
       is_6ghz_freq(bss->freq) || ssid->sae_password_id) &&
1439
      sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK &&
1440
      wpa_key_mgmt_sae(ssid->key_mgmt) &&
1441
      !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
1442
    if (debug_print)
1443
      wpa_dbg(wpa_s, MSG_DEBUG,
1444
        "   skip - SAE H2E required, but not supported by the AP");
1445
    return false;
1446
  }
1447
#endif /* CONFIG_SAE */
1448
1449
#ifdef CONFIG_SAE_PK
1450
  if (ssid->sae_pk == SAE_PK_MODE_ONLY &&
1451
      !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) {
1452
    if (debug_print)
1453
      wpa_dbg(wpa_s, MSG_DEBUG,
1454
        "   skip - SAE-PK required, but not supported by the AP");
1455
    return false;
1456
  }
1457
#endif /* CONFIG_SAE_PK */
1458
1459
0
#ifndef CONFIG_IBSS_RSN
1460
0
  if (ssid->mode == WPAS_MODE_IBSS &&
1461
0
      !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) {
1462
0
    if (debug_print)
1463
0
      wpa_dbg(wpa_s, MSG_DEBUG,
1464
0
        "   skip - IBSS RSN not supported in the build");
1465
0
    return false;
1466
0
  }
1467
0
#endif /* !CONFIG_IBSS_RSN */
1468
1469
#ifdef CONFIG_P2P
1470
  if (ssid->p2p_group &&
1471
      !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1472
      !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1473
    if (debug_print)
1474
      wpa_dbg(wpa_s, MSG_DEBUG, "   skip - no P2P IE seen");
1475
    return false;
1476
  }
1477
1478
  if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1479
    struct wpabuf *p2p_ie;
1480
    u8 dev_addr[ETH_ALEN];
1481
1482
    ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1483
    if (!ie) {
1484
      if (debug_print)
1485
        wpa_dbg(wpa_s, MSG_DEBUG,
1486
          "   skip - no P2P element");
1487
      return false;
1488
    }
1489
    p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1490
    if (!p2p_ie) {
1491
      if (debug_print)
1492
        wpa_dbg(wpa_s, MSG_DEBUG,
1493
          "   skip - could not fetch P2P element");
1494
      return false;
1495
    }
1496
1497
    if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 ||
1498
        !ether_addr_equal(dev_addr, ssid->go_p2p_dev_addr)) {
1499
      if (debug_print)
1500
        wpa_dbg(wpa_s, MSG_DEBUG,
1501
          "   skip - no matching GO P2P Device Address in P2P element");
1502
      wpabuf_free(p2p_ie);
1503
      return false;
1504
    }
1505
    wpabuf_free(p2p_ie);
1506
  }
1507
1508
  /*
1509
   * TODO: skip the AP if its P2P IE has Group Formation bit set in the
1510
   * P2P Group Capability Bitmap and we are not in Group Formation with
1511
   * that device.
1512
   */
1513
#endif /* CONFIG_P2P */
1514
1515
0
  if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) {
1516
0
    struct os_reltime diff;
1517
1518
0
    os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff);
1519
0
    if (debug_print)
1520
0
      wpa_dbg(wpa_s, MSG_DEBUG,
1521
0
        "   skip - scan result not recent enough (%u.%06u seconds too old)",
1522
0
        (unsigned int) diff.sec,
1523
0
        (unsigned int) diff.usec);
1524
0
    return false;
1525
0
  }
1526
#ifdef CONFIG_MBO
1527
#ifdef CONFIG_TESTING_OPTIONS
1528
  if (wpa_s->ignore_assoc_disallow)
1529
    goto skip_assoc_disallow;
1530
#endif /* CONFIG_TESTING_OPTIONS */
1531
  assoc_disallow = wpas_mbo_check_assoc_disallow(bss);
1532
  if (assoc_disallow && assoc_disallow[1] >= 1) {
1533
    if (debug_print)
1534
      wpa_dbg(wpa_s, MSG_DEBUG,
1535
        "   skip - MBO association disallowed (reason %u)",
1536
        assoc_disallow[2]);
1537
    return false;
1538
  }
1539
1540
  if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) {
1541
    if (debug_print)
1542
      wpa_dbg(wpa_s, MSG_DEBUG,
1543
        "   skip - AP temporarily disallowed");
1544
    return false;
1545
  }
1546
#ifdef CONFIG_TESTING_OPTIONS
1547
skip_assoc_disallow:
1548
#endif /* CONFIG_TESTING_OPTIONS */
1549
#endif /* CONFIG_MBO */
1550
1551
#ifdef CONFIG_DPP
1552
  if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
1553
      !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, wpa_s->own_addr,
1554
         ssid) &&
1555
      (!ssid->dpp_connector || !ssid->dpp_netaccesskey ||
1556
       !ssid->dpp_csign)) {
1557
    if (debug_print)
1558
      wpa_dbg(wpa_s, MSG_DEBUG,
1559
        "   skip - no PMKSA entry for DPP");
1560
    return false;
1561
  }
1562
#endif /* CONFIG_DPP */
1563
1564
#ifdef CONFIG_SAE_PK
1565
  if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC &&
1566
      wpa_key_mgmt_sae(ssid->key_mgmt) &&
1567
      ((ssid->sae_password &&
1568
        sae_pk_valid_password(ssid->sae_password)) ||
1569
       (!ssid->sae_password && ssid->passphrase &&
1570
        sae_pk_valid_password(ssid->passphrase))) &&
1571
      !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) &&
1572
      sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid,
1573
            match_ssid_len)) {
1574
    if (debug_print)
1575
      wpa_dbg(wpa_s, MSG_DEBUG,
1576
        "   skip - another acceptable BSS with SAE-PK in the same ESS");
1577
    return false;
1578
  }
1579
#endif /* CONFIG_SAE_PK */
1580
1581
0
  if (bss->ssid_len == 0) {
1582
#ifdef CONFIG_OWE
1583
    const u8 *owe_ssid = NULL;
1584
    size_t owe_ssid_len = 0;
1585
1586
    owe_trans_ssid(wpa_s, bss, &owe_ssid, &owe_ssid_len);
1587
    if (owe_ssid && owe_ssid_len &&
1588
        owe_ssid_len == ssid->ssid_len &&
1589
        os_memcmp(owe_ssid, ssid->ssid, owe_ssid_len) == 0) {
1590
      if (debug_print)
1591
        wpa_dbg(wpa_s, MSG_DEBUG,
1592
          "   skip - no SSID in BSS entry for a possible OWE transition mode BSS");
1593
      int_array_add_unique(&wpa_s->owe_trans_scan_freq,
1594
               bss->freq);
1595
      return false;
1596
    }
1597
#endif /* CONFIG_OWE */
1598
0
    if (debug_print)
1599
0
      wpa_dbg(wpa_s, MSG_DEBUG,
1600
0
        "   skip - no SSID known for the BSS");
1601
0
    return false;
1602
0
  }
1603
1604
0
  if (!link && !wpas_valid_ml_bss(wpa_s, bss)) {
1605
0
    if (debug_print)
1606
0
      wpa_dbg(wpa_s, MSG_DEBUG,
1607
0
        "   skip - ML BSS going to be removed");
1608
0
    return false;
1609
0
  }
1610
1611
  /* Matching configuration found */
1612
0
  return true;
1613
0
}
1614
1615
1616
struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
1617
             int i, struct wpa_bss *bss,
1618
             struct wpa_ssid *group,
1619
             int only_first_ssid, int debug_print,
1620
             bool link)
1621
0
{
1622
0
  u8 wpa_ie_len, rsn_ie_len;
1623
0
  const u8 *ie;
1624
0
  struct wpa_ssid *ssid;
1625
0
  const u8 *match_ssid;
1626
0
  size_t match_ssid_len;
1627
0
  int bssid_ignore_count;
1628
1629
0
  ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1630
0
  wpa_ie_len = ie ? ie[1] : 0;
1631
1632
0
  ie = wpa_bss_get_rsne(wpa_s, bss, NULL, false);
1633
0
  rsn_ie_len = ie ? ie[1] : 0;
1634
1635
0
  if (debug_print) {
1636
0
    wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR
1637
0
      " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s",
1638
0
      i, MAC2STR(bss->bssid),
1639
0
      wpa_ssid_txt(bss->ssid, bss->ssid_len),
1640
0
      wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
1641
0
      bss->freq,
1642
0
      wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
1643
0
      " wps" : "",
1644
0
      (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
1645
0
       wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE))
1646
0
      ? " p2p" : "");
1647
0
  }
1648
1649
0
  bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid);
1650
0
  if (bssid_ignore_count) {
1651
0
    int limit = 1;
1652
0
    if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
1653
      /*
1654
       * When only a single network is enabled, we can
1655
       * trigger BSSID ignoring on the first failure. This
1656
       * should not be done with multiple enabled networks to
1657
       * avoid getting forced to move into a worse ESS on
1658
       * single error if there are no other BSSes of the
1659
       * current ESS.
1660
       */
1661
0
      limit = 0;
1662
0
    }
1663
0
    if (bssid_ignore_count > limit) {
1664
0
      if (debug_print) {
1665
0
        wpa_dbg(wpa_s, MSG_DEBUG,
1666
0
          "   skip - BSSID ignored (count=%d limit=%d)",
1667
0
          bssid_ignore_count, limit);
1668
0
      }
1669
0
      return NULL;
1670
0
    }
1671
0
  }
1672
1673
0
  match_ssid = bss->ssid;
1674
0
  match_ssid_len = bss->ssid_len;
1675
0
  owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len);
1676
1677
0
  if (match_ssid_len == 0) {
1678
0
    if (debug_print)
1679
0
      wpa_dbg(wpa_s, MSG_DEBUG, "   skip - SSID not known");
1680
0
    return NULL;
1681
0
  }
1682
1683
0
  if (disallowed_bssid(wpa_s, bss->bssid)) {
1684
0
    if (debug_print)
1685
0
      wpa_dbg(wpa_s, MSG_DEBUG, "   skip - BSSID disallowed");
1686
0
    return NULL;
1687
0
  }
1688
1689
0
  if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) {
1690
0
    if (debug_print)
1691
0
      wpa_dbg(wpa_s, MSG_DEBUG, "   skip - SSID disallowed");
1692
0
    return NULL;
1693
0
  }
1694
1695
0
  if (disabled_freq(wpa_s, bss->freq)) {
1696
0
    if (debug_print)
1697
0
      wpa_dbg(wpa_s, MSG_DEBUG, "   skip - channel disabled");
1698
0
    return NULL;
1699
0
  }
1700
1701
0
  if (wnm_is_bss_excluded(wpa_s, bss)) {
1702
0
    if (debug_print)
1703
0
      wpa_dbg(wpa_s, MSG_DEBUG, "   skip - BSSID excluded");
1704
0
    return NULL;
1705
0
  }
1706
1707
0
  for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
1708
0
    if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
1709
0
            bss, bssid_ignore_count, debug_print, link))
1710
0
      return ssid;
1711
0
  }
1712
1713
  /* No matching configuration found */
1714
0
  return NULL;
1715
0
}
1716
1717
1718
struct wpa_bss *
1719
wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
1720
        struct wpa_ssid *group,
1721
        struct wpa_ssid **selected_ssid,
1722
        int only_first_ssid)
1723
1.02k
{
1724
1.02k
  unsigned int i;
1725
1726
1.02k
  if (wpa_s->current_ssid) {
1727
1.02k
    struct wpa_ssid *ssid;
1728
1729
1.02k
    wpa_dbg(wpa_s, MSG_DEBUG,
1730
1.02k
      "Scan results matching the currently selected network");
1731
1.02k
    for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1732
0
      struct wpa_bss *bss = wpa_s->last_scan_res[i];
1733
1734
0
      ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1735
0
              only_first_ssid, 0, false);
1736
0
      if (ssid != wpa_s->current_ssid)
1737
0
        continue;
1738
0
      wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR
1739
0
        " freq=%d level=%d snr=%d est_throughput=%u",
1740
0
        i, MAC2STR(bss->bssid), bss->freq, bss->level,
1741
0
        bss->snr, bss->est_throughput);
1742
0
    }
1743
1.02k
  }
1744
1745
1.02k
  if (only_first_ssid)
1746
1.02k
    wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1747
1.02k
      group->id);
1748
0
  else
1749
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1750
1.02k
      group->priority);
1751
1752
1.02k
  for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1753
0
    struct wpa_bss *bss = wpa_s->last_scan_res[i];
1754
1755
0
    wpa_s->owe_transition_select = 1;
1756
0
    *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1757
0
                only_first_ssid, 1, false);
1758
0
    wpa_s->owe_transition_select = 0;
1759
0
    if (!*selected_ssid)
1760
0
      continue;
1761
0
    wpa_dbg(wpa_s, MSG_DEBUG, "   selected %sBSS " MACSTR
1762
0
      " ssid='%s'",
1763
0
      bss == wpa_s->current_bss ? "current ": "",
1764
0
      MAC2STR(bss->bssid),
1765
0
      wpa_ssid_txt(bss->ssid, bss->ssid_len));
1766
0
    return bss;
1767
0
  }
1768
1769
1.02k
  return NULL;
1770
1.02k
}
1771
1772
1773
struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1774
               struct wpa_ssid **selected_ssid,
1775
               bool clear_ignorelist)
1776
0
{
1777
0
  struct wpa_bss *selected = NULL;
1778
0
  size_t prio;
1779
0
  struct wpa_ssid *next_ssid = NULL;
1780
0
  struct wpa_ssid *ssid;
1781
1782
0
  if (wpa_s->last_scan_res == NULL ||
1783
0
      wpa_s->last_scan_res_used == 0)
1784
0
    return NULL; /* no scan results from last update */
1785
1786
0
  if (wpa_s->next_ssid) {
1787
    /* check that next_ssid is still valid */
1788
0
    for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1789
0
      if (ssid == wpa_s->next_ssid)
1790
0
        break;
1791
0
    }
1792
0
    next_ssid = ssid;
1793
0
    wpa_s->next_ssid = NULL;
1794
0
  }
1795
1796
0
  while (selected == NULL) {
1797
0
    for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1798
0
      if (next_ssid && next_ssid->priority ==
1799
0
          wpa_s->conf->pssid[prio]->priority) {
1800
0
        selected = wpa_supplicant_select_bss(
1801
0
          wpa_s, next_ssid, selected_ssid, 1);
1802
0
        if (selected)
1803
0
          break;
1804
0
      }
1805
0
      selected = wpa_supplicant_select_bss(
1806
0
        wpa_s, wpa_s->conf->pssid[prio],
1807
0
        selected_ssid, 0);
1808
0
      if (selected)
1809
0
        break;
1810
0
    }
1811
1812
0
    if (!selected &&
1813
0
        (wpa_s->bssid_ignore || wnm_active_bss_trans_mgmt(wpa_s)) &&
1814
0
        !wpa_s->countermeasures && clear_ignorelist) {
1815
0
      wpa_dbg(wpa_s, MSG_DEBUG,
1816
0
        "No APs found - clear BSSID ignore list and try again");
1817
0
      wnm_btm_reset(wpa_s);
1818
0
      wpa_bssid_ignore_clear(wpa_s);
1819
0
      wpa_s->bssid_ignore_cleared = true;
1820
0
    } else if (selected == NULL)
1821
0
      break;
1822
0
  }
1823
1824
0
  ssid = *selected_ssid;
1825
0
  if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1826
0
      !ssid->passphrase && !ssid->ext_psk) {
1827
0
    const char *field_name, *txt = NULL;
1828
1829
0
    wpa_dbg(wpa_s, MSG_DEBUG,
1830
0
      "PSK/passphrase not yet available for the selected network");
1831
1832
0
    wpas_notify_network_request(wpa_s, ssid,
1833
0
              WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1834
1835
0
    field_name = wpa_supplicant_ctrl_req_to_string(
1836
0
      WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1837
0
    if (field_name == NULL)
1838
0
      return NULL;
1839
1840
0
    wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1841
1842
0
    selected = NULL;
1843
0
  }
1844
1845
0
  return selected;
1846
0
}
1847
1848
1849
static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1850
          int timeout_sec, int timeout_usec)
1851
0
{
1852
0
  if (!wpa_supplicant_enabled_networks(wpa_s)) {
1853
    /*
1854
     * No networks are enabled; short-circuit request so
1855
     * we don't wait timeout seconds before transitioning
1856
     * to INACTIVE state.
1857
     */
1858
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1859
0
      "since there are no enabled networks");
1860
0
    wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1861
0
    return;
1862
0
  }
1863
1864
0
  wpa_s->scan_for_connection = 1;
1865
0
  wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1866
0
}
1867
1868
1869
static bool ml_link_probe_scan(struct wpa_supplicant *wpa_s)
1870
0
{
1871
0
  if (!wpa_s->ml_connect_probe_ssid || !wpa_s->ml_connect_probe_bss)
1872
0
    return false;
1873
1874
0
  wpa_msg(wpa_s, MSG_DEBUG,
1875
0
    "Request association with " MACSTR " after ML probe",
1876
0
    MAC2STR(wpa_s->ml_connect_probe_bss->bssid));
1877
1878
0
  wpa_supplicant_associate(wpa_s, wpa_s->ml_connect_probe_bss,
1879
0
         wpa_s->ml_connect_probe_ssid);
1880
1881
0
  wpa_s->ml_connect_probe_ssid = NULL;
1882
0
  wpa_s->ml_connect_probe_bss = NULL;
1883
1884
0
  return true;
1885
0
}
1886
1887
1888
static int wpa_supplicant_connect_ml_missing(struct wpa_supplicant *wpa_s,
1889
               struct wpa_bss *selected,
1890
               struct wpa_ssid *ssid)
1891
0
{
1892
0
  int *freqs;
1893
0
  u16 missing_links = 0, removed_links, usable_links;
1894
1895
0
  if (!((wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_MLO) &&
1896
0
        (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)))
1897
0
    return 0;
1898
1899
0
  usable_links = wpa_bss_get_usable_links(wpa_s, selected, NULL,
1900
0
            &missing_links);
1901
0
  if (!usable_links || !missing_links)
1902
0
    return 0;
1903
1904
0
  removed_links = wpa_bss_parse_reconf_ml_element(wpa_s, selected);
1905
0
  missing_links &= ~removed_links;
1906
1907
0
  if (!missing_links)
1908
0
    return 0;
1909
1910
0
  wpa_dbg(wpa_s, MSG_DEBUG,
1911
0
    "MLD: Doing an ML probe for missing links 0x%04x",
1912
0
    missing_links);
1913
1914
0
  freqs = os_malloc(sizeof(int) * 2);
1915
0
  if (!freqs)
1916
0
    return 0;
1917
1918
0
  wpa_s->ml_connect_probe_ssid = ssid;
1919
0
  wpa_s->ml_connect_probe_bss = selected;
1920
1921
0
  freqs[0] = selected->freq;
1922
0
  freqs[1] = 0;
1923
1924
0
  wpa_s->manual_scan_passive = 0;
1925
0
  wpa_s->manual_scan_use_id = 0;
1926
0
  wpa_s->manual_scan_only_new = 0;
1927
0
  wpa_s->scan_id_count = 0;
1928
0
  os_free(wpa_s->manual_scan_freqs);
1929
0
  wpa_s->manual_scan_freqs = freqs;
1930
1931
0
  os_memcpy(wpa_s->ml_probe_bssid, selected->bssid, ETH_ALEN);
1932
1933
  /*
1934
   * In case the ML probe request is intended to retrieve information from
1935
   * the transmitted BSS, the AP MLD ID should be included and should be
1936
   * set to zero.
1937
   * In case the ML probe requested is intended to retrieve information
1938
   * from a non-transmitted BSS, the AP MLD ID should not be included.
1939
   */
1940
0
  if (selected->mld_bss_non_transmitted)
1941
0
    wpa_s->ml_probe_mld_id = -1;
1942
0
  else
1943
0
    wpa_s->ml_probe_mld_id = 0;
1944
1945
0
  if (ssid && ssid->ssid_len) {
1946
0
    os_free(wpa_s->ssids_from_scan_req);
1947
0
    wpa_s->num_ssids_from_scan_req = 0;
1948
1949
0
    wpa_s->ssids_from_scan_req =
1950
0
      os_zalloc(sizeof(struct wpa_ssid_value));
1951
0
    if (wpa_s->ssids_from_scan_req) {
1952
0
      wpa_printf(MSG_DEBUG,
1953
0
           "MLD: ML probe: With direct SSID");
1954
1955
0
      wpa_s->num_ssids_from_scan_req = 1;
1956
0
      wpa_s->ssids_from_scan_req[0].ssid_len = ssid->ssid_len;
1957
0
      os_memcpy(wpa_s->ssids_from_scan_req[0].ssid,
1958
0
          ssid->ssid, ssid->ssid_len);
1959
0
    }
1960
0
  }
1961
1962
0
  wpa_s->ml_probe_links = missing_links;
1963
1964
0
  wpa_s->normal_scans = 0;
1965
0
  wpa_s->scan_req = MANUAL_SCAN_REQ;
1966
0
  wpa_s->after_wps = 0;
1967
0
  wpa_s->known_wps_freq = 0;
1968
0
  wpa_supplicant_req_scan(wpa_s, 0, 0);
1969
1970
0
  return 1;
1971
0
}
1972
1973
1974
int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
1975
         struct wpa_bss *selected,
1976
         struct wpa_ssid *ssid)
1977
0
{
1978
0
#ifdef IEEE8021X_EAPOL
1979
0
  if ((eap_is_wps_pbc_enrollee(&ssid->eap) &&
1980
0
       wpas_wps_partner_link_overlap_detect(wpa_s)) ||
1981
0
      wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1982
0
    wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1983
0
      "PBC session overlap");
1984
0
    wpas_notify_wps_event_pbc_overlap(wpa_s);
1985
0
    wpa_s->wps_overlap = true;
1986
#ifdef CONFIG_P2P
1987
    if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1988
        wpa_s->p2p_in_provisioning) {
1989
      eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1990
                 wpa_s, NULL);
1991
      return -1;
1992
    }
1993
#endif /* CONFIG_P2P */
1994
1995
#ifdef CONFIG_WPS
1996
    wpas_wps_pbc_overlap(wpa_s);
1997
    wpas_wps_cancel(wpa_s);
1998
#endif /* CONFIG_WPS */
1999
0
    return -1;
2000
0
  }
2001
0
#endif /* IEEE8021X_EAPOL */
2002
2003
0
  wpa_msg(wpa_s, MSG_DEBUG,
2004
0
    "Considering connect request: reassociate: %d  selected: "
2005
0
    MACSTR "  bssid: " MACSTR "  pending: " MACSTR
2006
0
    "  wpa_state: %s  ssid=%p  current_ssid=%p",
2007
0
    wpa_s->reassociate, MAC2STR(selected->bssid),
2008
0
    MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
2009
0
    wpa_supplicant_state_txt(wpa_s->wpa_state),
2010
0
    ssid, wpa_s->current_ssid);
2011
2012
  /*
2013
   * Do not trigger new association unless the BSSID has changed or if
2014
   * reassociation is requested. If we are in process of associating with
2015
   * the selected BSSID, do not trigger new attempt.
2016
   */
2017
0
  if (wpa_s->reassociate ||
2018
0
      (!ether_addr_equal(selected->bssid, wpa_s->bssid) &&
2019
0
       ((wpa_s->wpa_state != WPA_ASSOCIATING &&
2020
0
         wpa_s->wpa_state != WPA_AUTHENTICATING) ||
2021
0
        (!is_zero_ether_addr(wpa_s->pending_bssid) &&
2022
0
         !ether_addr_equal(selected->bssid, wpa_s->pending_bssid)) ||
2023
0
        (is_zero_ether_addr(wpa_s->pending_bssid) &&
2024
0
         ssid != wpa_s->current_ssid)))) {
2025
0
    if (wpa_supplicant_scard_init(wpa_s, ssid)) {
2026
0
      wpa_supplicant_req_new_scan(wpa_s, 10, 0);
2027
0
      return 0;
2028
0
    }
2029
2030
0
    if (wpa_supplicant_connect_ml_missing(wpa_s, selected, ssid))
2031
0
      return 0;
2032
2033
0
    wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
2034
0
      MAC2STR(selected->bssid));
2035
0
    wpa_supplicant_associate(wpa_s, selected, ssid);
2036
0
  } else {
2037
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
2038
0
      "connect with the selected AP");
2039
0
  }
2040
2041
0
  return 0;
2042
0
}
2043
2044
2045
static struct wpa_ssid *
2046
wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
2047
0
{
2048
0
  size_t prio;
2049
0
  struct wpa_ssid *ssid;
2050
2051
0
  for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
2052
0
    for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
2053
0
    {
2054
0
      if (wpas_network_disabled(wpa_s, ssid))
2055
0
        continue;
2056
0
#ifndef CONFIG_IBSS_RSN
2057
0
      if (ssid->mode == WPAS_MODE_IBSS &&
2058
0
          !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE |
2059
0
            WPA_KEY_MGMT_WPA_NONE))) {
2060
0
        wpa_msg(wpa_s, MSG_INFO,
2061
0
          "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'",
2062
0
          wpa_ssid_txt(ssid->ssid,
2063
0
                 ssid->ssid_len));
2064
0
        continue;
2065
0
      }
2066
0
#endif /* !CONFIG_IBSS_RSN */
2067
0
      if (ssid->mode == WPAS_MODE_IBSS ||
2068
0
          ssid->mode == WPAS_MODE_AP ||
2069
0
          ssid->mode == WPAS_MODE_MESH)
2070
0
        return ssid;
2071
0
    }
2072
0
  }
2073
0
  return NULL;
2074
0
}
2075
2076
2077
/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
2078
 * on BSS added and BSS changed events */
2079
static void wpa_supplicant_rsn_preauth_scan_results(
2080
  struct wpa_supplicant *wpa_s)
2081
0
{
2082
0
  struct wpa_bss *bss;
2083
2084
0
  if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
2085
0
    return;
2086
2087
0
  dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
2088
0
    const u8 *ssid, *rsn;
2089
2090
0
    ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
2091
0
    if (ssid == NULL)
2092
0
      continue;
2093
2094
0
    rsn = wpa_bss_get_rsne(wpa_s, bss, NULL, false);
2095
0
    if (rsn == NULL)
2096
0
      continue;
2097
2098
0
    rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
2099
0
  }
2100
2101
0
}
2102
2103
2104
#ifndef CONFIG_NO_ROAMING
2105
2106
static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise)
2107
0
{
2108
0
  if (noise == WPA_INVALID_NOISE) {
2109
0
    if (IS_5GHZ(frequency)) {
2110
0
      noise = DEFAULT_NOISE_FLOOR_5GHZ;
2111
0
    } else if (is_6ghz_freq(frequency)) {
2112
0
      noise = DEFAULT_NOISE_FLOOR_6GHZ;
2113
0
    } else {
2114
0
      noise = DEFAULT_NOISE_FLOOR_2GHZ;
2115
0
    }
2116
0
  }
2117
0
  return avg_signal - noise;
2118
0
}
2119
2120
2121
static unsigned int
2122
wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
2123
             const struct wpa_bss *bss, int snr)
2124
0
{
2125
0
  int rate = wpa_bss_get_max_rate(bss);
2126
0
  const u8 *ies = wpa_bss_ie_ptr(bss);
2127
0
  size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
2128
0
  enum chan_width max_cw = CHAN_WIDTH_UNKNOWN;
2129
2130
0
  return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq,
2131
0
        &max_cw);
2132
0
}
2133
2134
2135
static int wpas_evaluate_band_score(int frequency)
2136
0
{
2137
0
  if (is_6ghz_freq(frequency))
2138
0
    return 2;
2139
0
  if (IS_5GHZ(frequency))
2140
0
    return 1;
2141
0
  return 0;
2142
0
}
2143
2144
2145
int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s,
2146
             struct wpa_bss *current_bss,
2147
             struct wpa_bss *selected,
2148
             bool poll_current)
2149
0
{
2150
0
  int min_diff, diff;
2151
0
  int cur_band_score, sel_band_score;
2152
0
  int to_5ghz, to_6ghz;
2153
0
  int cur_level, sel_level;
2154
0
  unsigned int cur_est, sel_est;
2155
0
  struct wpa_signal_info si;
2156
0
  int cur_snr = 0;
2157
0
  int ret = 0;
2158
0
  const u8 *cur_ies = wpa_bss_ie_ptr(current_bss);
2159
0
  const u8 *sel_ies = wpa_bss_ie_ptr(selected);
2160
0
  size_t cur_ie_len = current_bss->ie_len ? current_bss->ie_len :
2161
0
    current_bss->beacon_ie_len;
2162
0
  size_t sel_ie_len = selected->ie_len ? selected->ie_len :
2163
0
    selected->beacon_ie_len;
2164
2165
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
2166
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
2167
0
    " freq=%d level=%d snr=%d est_throughput=%u",
2168
0
    MAC2STR(current_bss->bssid),
2169
0
    current_bss->freq, current_bss->level,
2170
0
    current_bss->snr, current_bss->est_throughput);
2171
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
2172
0
    " freq=%d level=%d snr=%d est_throughput=%u",
2173
0
    MAC2STR(selected->bssid), selected->freq, selected->level,
2174
0
    selected->snr, selected->est_throughput);
2175
2176
0
  if (wpas_ap_link_address(wpa_s, selected->bssid)) {
2177
0
    wpa_dbg(wpa_s, MSG_DEBUG, "MLD: associated to selected BSS");
2178
0
    return 0;
2179
0
  }
2180
2181
0
  if (wpa_s->current_ssid->bssid_set &&
2182
0
      ether_addr_equal(selected->bssid, wpa_s->current_ssid->bssid)) {
2183
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
2184
0
      "has preferred BSSID");
2185
0
    return 1;
2186
0
  }
2187
2188
  /*
2189
   * Try to poll the signal from the driver since this will allow to get
2190
   * more accurate values. In some cases, there can be big differences
2191
   * between the RSSI of the Probe Response frames of the AP we are
2192
   * associated with and the Beacon frames we hear from the same AP after
2193
   * association. This can happen, e.g., when there are two antennas that
2194
   * hear the AP very differently. If the driver chooses to hear the
2195
   * Probe Response frames during the scan on the "bad" antenna because
2196
   * it wants to save power, but knows to choose the other antenna after
2197
   * association, we will hear our AP with a low RSSI as part of the
2198
   * scan even when we can hear it decently on the other antenna. To cope
2199
   * with this, ask the driver to teach us how it hears the AP. Also, the
2200
   * scan results may be a bit old, since we can very quickly get fresh
2201
   * information about our currently associated AP.
2202
   */
2203
0
  if (poll_current && wpa_drv_signal_poll(wpa_s, &si) == 0 &&
2204
0
      (si.data.avg_beacon_signal || si.data.avg_signal)) {
2205
    /*
2206
     * Normalize avg_signal to the RSSI over 20 MHz, as the
2207
     * throughput is estimated based on the RSSI over 20 MHz
2208
     */
2209
0
    cur_level = si.data.avg_beacon_signal ?
2210
0
      si.data.avg_beacon_signal :
2211
0
      (si.data.avg_signal -
2212
0
       wpas_channel_width_rssi_bump(cur_ies, cur_ie_len,
2213
0
                  si.chanwidth));
2214
0
    cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level,
2215
0
               si.current_noise);
2216
2217
0
    cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s,
2218
0
                     current_bss,
2219
0
                     cur_snr);
2220
0
    wpa_dbg(wpa_s, MSG_DEBUG,
2221
0
      "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u",
2222
0
      cur_level, cur_snr, cur_est);
2223
0
  } else {
2224
    /* Level and SNR are measured over 20 MHz channel */
2225
0
    cur_level = current_bss->level;
2226
0
    cur_snr = current_bss->snr;
2227
0
    cur_est = current_bss->est_throughput;
2228
0
  }
2229
2230
  /* Adjust the SNR of BSSes based on the channel width. */
2231
0
  cur_level += wpas_channel_width_rssi_bump(cur_ies, cur_ie_len,
2232
0
              current_bss->max_cw);
2233
0
  cur_snr = wpas_adjust_snr_by_chanwidth(cur_ies, cur_ie_len,
2234
0
                 current_bss->max_cw, cur_snr);
2235
2236
0
  sel_est = selected->est_throughput;
2237
0
  sel_level = selected->level +
2238
0
    wpas_channel_width_rssi_bump(sel_ies, sel_ie_len,
2239
0
               selected->max_cw);
2240
2241
0
  if (sel_est > cur_est + 5000) {
2242
0
    wpa_dbg(wpa_s, MSG_DEBUG,
2243
0
      "Allow reassociation - selected BSS has better estimated throughput");
2244
0
    return 1;
2245
0
  }
2246
2247
0
  to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
2248
0
  to_6ghz = is_6ghz_freq(selected->freq) &&
2249
0
    !is_6ghz_freq(current_bss->freq);
2250
2251
0
  if (cur_level < 0 &&
2252
0
      cur_level > sel_level + to_5ghz * 2 + to_6ghz * 2 &&
2253
0
      sel_est < cur_est * 1.2) {
2254
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
2255
0
      "signal level");
2256
0
    return 0;
2257
0
  }
2258
2259
0
  if (cur_est > sel_est + 5000) {
2260
0
    wpa_dbg(wpa_s, MSG_DEBUG,
2261
0
      "Skip roam - Current BSS has better estimated throughput");
2262
0
    return 0;
2263
0
  }
2264
2265
0
  if (cur_snr > GREAT_SNR) {
2266
0
    wpa_dbg(wpa_s, MSG_DEBUG,
2267
0
      "Skip roam - Current BSS has good SNR (%u > %u)",
2268
0
      cur_snr, GREAT_SNR);
2269
0
    return 0;
2270
0
  }
2271
2272
0
  if (cur_level < -85) /* ..-86 dBm */
2273
0
    min_diff = 1;
2274
0
  else if (cur_level < -80) /* -85..-81 dBm */
2275
0
    min_diff = 2;
2276
0
  else if (cur_level < -75) /* -80..-76 dBm */
2277
0
    min_diff = 3;
2278
0
  else if (cur_level < -70) /* -75..-71 dBm */
2279
0
    min_diff = 4;
2280
0
  else if (cur_level < 0) /* -70..-1 dBm */
2281
0
    min_diff = 5;
2282
0
  else /* unspecified units (not in dBm) */
2283
0
    min_diff = 2;
2284
2285
0
  if (cur_est > sel_est * 1.5)
2286
0
    min_diff += 10;
2287
0
  else if (cur_est > sel_est * 1.2)
2288
0
    min_diff += 5;
2289
0
  else if (cur_est > sel_est * 1.1)
2290
0
    min_diff += 2;
2291
0
  else if (cur_est > sel_est)
2292
0
    min_diff++;
2293
0
  else if (sel_est > cur_est * 1.5)
2294
0
    min_diff -= 10;
2295
0
  else if (sel_est > cur_est * 1.2)
2296
0
    min_diff -= 5;
2297
0
  else if (sel_est > cur_est * 1.1)
2298
0
    min_diff -= 2;
2299
0
  else if (sel_est > cur_est)
2300
0
    min_diff--;
2301
2302
0
  cur_band_score = wpas_evaluate_band_score(current_bss->freq);
2303
0
  sel_band_score = wpas_evaluate_band_score(selected->freq);
2304
0
  min_diff += (cur_band_score - sel_band_score) * 2;
2305
0
  if (wpa_s->signal_threshold && cur_level <= wpa_s->signal_threshold &&
2306
0
      sel_level > wpa_s->signal_threshold)
2307
0
    min_diff -= 2;
2308
0
  diff = sel_level - cur_level;
2309
0
  if (diff < min_diff) {
2310
0
    wpa_dbg(wpa_s, MSG_DEBUG,
2311
0
      "Skip roam - too small difference in signal level (%d < %d)",
2312
0
      diff, min_diff);
2313
0
    ret = 0;
2314
0
  } else {
2315
0
    wpa_dbg(wpa_s, MSG_DEBUG,
2316
0
      "Allow reassociation due to difference in signal level (%d >= %d)",
2317
0
      diff, min_diff);
2318
0
    ret = 1;
2319
0
  }
2320
0
  wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR
2321
0
         " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR
2322
0
         " sel_freq=%d sel_level=%d sel_est=%d",
2323
0
         ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM,
2324
0
         MAC2STR(current_bss->bssid),
2325
0
         current_bss->freq, cur_level, cur_est,
2326
0
         MAC2STR(selected->bssid),
2327
0
         selected->freq, sel_level, sel_est);
2328
0
  return ret;
2329
0
}
2330
2331
#endif /* CONFIG_NO_ROAMING */
2332
2333
2334
static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
2335
               struct wpa_bss *selected,
2336
               struct wpa_ssid *ssid)
2337
0
{
2338
0
  struct wpa_bss *current_bss = NULL;
2339
0
  const u8 *bssid;
2340
2341
0
  if (wpa_s->reassociate)
2342
0
    return 1; /* explicit request to reassociate */
2343
0
  if (wpa_s->wpa_state < WPA_ASSOCIATED)
2344
0
    return 1; /* we are not associated; continue */
2345
0
  if (wpa_s->current_ssid == NULL)
2346
0
    return 1; /* unknown current SSID */
2347
0
  if (wpa_s->current_ssid != ssid)
2348
0
    return 1; /* different network block */
2349
2350
0
  if (wpas_driver_bss_selection(wpa_s))
2351
0
    return 0; /* Driver-based roaming */
2352
2353
0
  if (wpa_s->valid_links)
2354
0
    bssid = wpa_s->links[wpa_s->mlo_assoc_link_id].bssid;
2355
0
  else
2356
0
    bssid = wpa_s->bssid;
2357
2358
0
  if (wpa_s->current_ssid->ssid)
2359
0
    current_bss = wpa_bss_get(wpa_s, bssid,
2360
0
            wpa_s->current_ssid->ssid,
2361
0
            wpa_s->current_ssid->ssid_len);
2362
0
  if (!current_bss)
2363
0
    current_bss = wpa_bss_get_bssid(wpa_s, bssid);
2364
2365
0
  if (!current_bss)
2366
0
    return 1; /* current BSS not seen in scan results */
2367
2368
0
  if (current_bss == selected)
2369
0
    return 0;
2370
2371
0
  if (selected->last_update_idx > current_bss->last_update_idx)
2372
0
    return 1; /* current BSS not seen in the last scan */
2373
2374
0
#ifndef CONFIG_NO_ROAMING
2375
0
  return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss,
2376
0
                  selected, true);
2377
#else /* CONFIG_NO_ROAMING */
2378
  return 0;
2379
#endif /* CONFIG_NO_ROAMING */
2380
0
}
2381
2382
2383
static int wpas_trigger_6ghz_scan(struct wpa_supplicant *wpa_s,
2384
          union wpa_event_data *data)
2385
0
{
2386
0
  struct wpa_driver_scan_params params;
2387
0
  unsigned int j;
2388
2389
0
  wpa_dbg(wpa_s, MSG_INFO, "Triggering 6GHz-only scan");
2390
0
  os_memset(&params, 0, sizeof(params));
2391
0
  params.non_coloc_6ghz = wpa_s->last_scan_non_coloc_6ghz;
2392
0
  for (j = 0; j < data->scan_info.num_ssids; j++)
2393
0
    params.ssids[j] = data->scan_info.ssids[j];
2394
0
  params.num_ssids = data->scan_info.num_ssids;
2395
0
  wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, &params,
2396
0
        true, false, false);
2397
0
  if (!wpa_supplicant_trigger_scan(wpa_s, &params, true, true)) {
2398
0
    wpa_s->scan_in_progress_6ghz = true;
2399
0
    wpas_notify_scan_in_progress_6ghz(wpa_s);
2400
0
    os_free(params.freqs);
2401
0
    return 1;
2402
0
  }
2403
0
  wpa_dbg(wpa_s, MSG_INFO, "Failed to trigger 6GHz-only scan");
2404
0
  os_free(params.freqs);
2405
0
  return 0;
2406
0
}
2407
2408
2409
static bool wpas_short_ssid_match(struct wpa_supplicant *wpa_s,
2410
          struct wpa_scan_results *scan_res)
2411
0
{
2412
0
  size_t i;
2413
0
  struct wpa_ssid *ssid = wpa_s->current_ssid;
2414
0
  u32 current_ssid_short = ieee80211_crc32(ssid->ssid, ssid->ssid_len);
2415
2416
0
  for (i = 0; i < scan_res->num; i++) {
2417
0
    struct wpa_scan_res *res = scan_res->res[i];
2418
0
    const u8 *rnr_ie, *ie_end;
2419
0
    const struct ieee80211_neighbor_ap_info *info;
2420
0
    size_t left;
2421
2422
0
    rnr_ie = wpa_scan_get_ie(res, WLAN_EID_REDUCED_NEIGHBOR_REPORT);
2423
0
    if (!rnr_ie)
2424
0
      continue;
2425
2426
0
    ie_end = rnr_ie + 2 + rnr_ie[1];
2427
0
    rnr_ie += 2;
2428
2429
0
    left = ie_end - rnr_ie;
2430
0
    if (left < sizeof(struct ieee80211_neighbor_ap_info))
2431
0
      continue;
2432
2433
0
    info = (const struct ieee80211_neighbor_ap_info *) rnr_ie;
2434
0
    if (info->tbtt_info_len < 11)
2435
0
      continue; /* short SSID not included */
2436
0
    left -= sizeof(struct ieee80211_neighbor_ap_info);
2437
0
    rnr_ie += sizeof(struct ieee80211_neighbor_ap_info);
2438
2439
0
    while (left >= info->tbtt_info_len && rnr_ie + 11 <= ie_end) {
2440
      /* Skip TBTT offset and BSSID */
2441
0
      u32 short_ssid = WPA_GET_LE32(rnr_ie + 1 + ETH_ALEN);
2442
2443
0
      if (short_ssid == current_ssid_short)
2444
0
        return true;
2445
2446
0
      left -= info->tbtt_info_len;
2447
0
      rnr_ie += info->tbtt_info_len;
2448
0
    }
2449
0
  }
2450
2451
0
  return false;
2452
0
}
2453
2454
2455
/*
2456
 * Return a negative value if no scan results could be fetched or if scan
2457
 * results should not be shared with other virtual interfaces.
2458
 * Return 0 if scan results were fetched and may be shared with other
2459
 * interfaces.
2460
 * Return 1 if scan results may be shared with other virtual interfaces but may
2461
 * not trigger any operations.
2462
 * Return 2 if the interface was removed and cannot be used.
2463
 */
2464
static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2465
                union wpa_event_data *data,
2466
                int own_request, int update_only)
2467
0
{
2468
0
  struct wpa_scan_results *scan_res = NULL;
2469
0
  int ret = 0;
2470
0
  int ap = 0;
2471
0
  bool trigger_6ghz_scan;
2472
0
  bool short_ssid_match_found = false;
2473
#ifndef CONFIG_NO_RANDOM_POOL
2474
  size_t i, num;
2475
#endif /* CONFIG_NO_RANDOM_POOL */
2476
2477
#ifdef CONFIG_AP
2478
  if (wpa_s->ap_iface)
2479
    ap = 1;
2480
#endif /* CONFIG_AP */
2481
2482
0
  trigger_6ghz_scan = wpa_s->crossed_6ghz_dom &&
2483
0
    wpa_s->last_scan_all_chan;
2484
0
  wpa_s->crossed_6ghz_dom = false;
2485
0
  wpa_s->last_scan_all_chan = false;
2486
2487
0
  wpa_supplicant_notify_scanning(wpa_s, 0);
2488
2489
0
  scan_res = wpa_supplicant_get_scan_results(wpa_s,
2490
0
               data ? &data->scan_info :
2491
0
               NULL, 1, NULL);
2492
2493
0
  if (wpa_s->scan_in_progress_6ghz) {
2494
0
    wpa_s->scan_in_progress_6ghz = false;
2495
0
    wpas_notify_scan_in_progress_6ghz(wpa_s);
2496
0
  }
2497
2498
0
  if (scan_res == NULL) {
2499
0
    if (wpa_s->conf->ap_scan == 2 || ap ||
2500
0
        wpa_s->scan_res_handler == scan_only_handler)
2501
0
      return -1;
2502
0
    if (!own_request)
2503
0
      return -1;
2504
0
    if (data && data->scan_info.external_scan)
2505
0
      return -1;
2506
0
    if (wpa_s->scan_res_fail_handler) {
2507
0
      void (*handler)(struct wpa_supplicant *wpa_s);
2508
2509
0
      handler = wpa_s->scan_res_fail_handler;
2510
0
      wpa_s->scan_res_fail_handler = NULL;
2511
0
      handler(wpa_s);
2512
0
    } else {
2513
0
      wpa_dbg(wpa_s, MSG_DEBUG,
2514
0
        "Failed to get scan results - try scanning again");
2515
0
      wpa_supplicant_req_new_scan(wpa_s, 1, 0);
2516
0
    }
2517
2518
0
    ret = -1;
2519
0
    goto scan_work_done;
2520
0
  }
2521
2522
#ifndef CONFIG_NO_RANDOM_POOL
2523
  num = scan_res->num;
2524
  if (num > 10)
2525
    num = 10;
2526
  for (i = 0; i < num; i++) {
2527
    u8 buf[5];
2528
    struct wpa_scan_res *res = scan_res->res[i];
2529
    buf[0] = res->bssid[5];
2530
    buf[1] = res->qual & 0xff;
2531
    buf[2] = res->noise & 0xff;
2532
    buf[3] = res->level & 0xff;
2533
    buf[4] = res->tsf & 0xff;
2534
    random_add_randomness(buf, sizeof(buf));
2535
  }
2536
#endif /* CONFIG_NO_RANDOM_POOL */
2537
2538
0
  if (data) {
2539
0
    size_t idx;
2540
2541
0
    wpa_s->last_scan_external = data->scan_info.external_scan;
2542
0
    wpa_s->last_scan_num_ssids = data->scan_info.num_ssids;
2543
0
    for (idx = 0; idx < wpa_s->last_scan_num_ssids; idx++) {
2544
      /* Copy the SSID and its length */
2545
0
      if (idx >= WPAS_MAX_SCAN_SSIDS ||
2546
0
          data->scan_info.ssids[idx].ssid_len > SSID_MAX_LEN)
2547
0
        continue;
2548
2549
0
      os_memcpy(wpa_s->last_scan_ssids[idx].ssid,
2550
0
          data->scan_info.ssids[idx].ssid,
2551
0
          data->scan_info.ssids[idx].ssid_len);
2552
0
      wpa_s->last_scan_ssids[idx].ssid_len =
2553
0
        data->scan_info.ssids[idx].ssid_len;
2554
0
    }
2555
0
  } else {
2556
0
    wpa_s->last_scan_external = false;
2557
0
    wpa_s->last_scan_num_ssids = 0;
2558
0
  }
2559
2560
0
  if (update_only) {
2561
0
    ret = 1;
2562
0
    goto scan_work_done;
2563
0
  }
2564
2565
0
  if (own_request && wpa_s->scan_res_handler &&
2566
0
      !(data && data->scan_info.external_scan)) {
2567
0
    void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
2568
0
           struct wpa_scan_results *scan_res);
2569
2570
0
    scan_res_handler = wpa_s->scan_res_handler;
2571
0
    wpa_s->scan_res_handler = NULL;
2572
0
    scan_res_handler(wpa_s, scan_res);
2573
0
    ret = 1;
2574
0
    goto scan_work_done;
2575
0
  }
2576
2577
0
  wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
2578
0
    wpa_s->own_scan_running,
2579
0
    data ? data->scan_info.external_scan : 0);
2580
0
  if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
2581
0
      wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
2582
0
      own_request && !(data && data->scan_info.external_scan)) {
2583
0
    wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
2584
0
           wpa_s->manual_scan_id);
2585
0
    wpa_s->manual_scan_use_id = 0;
2586
0
  } else {
2587
0
    wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
2588
0
  }
2589
0
  wpas_notify_scan_results(wpa_s);
2590
2591
0
  wpas_notify_scan_done(wpa_s, 1);
2592
2593
0
  if (ap) {
2594
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
2595
#ifdef CONFIG_AP
2596
    if (wpa_s->ap_iface->scan_cb)
2597
      wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
2598
#endif /* CONFIG_AP */
2599
0
    goto scan_work_done;
2600
0
  }
2601
2602
0
  if (data && data->scan_info.external_scan) {
2603
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
2604
0
    wpa_scan_results_free(scan_res);
2605
0
    return 0;
2606
0
  }
2607
2608
0
  if (sme_proc_obss_scan(wpa_s) > 0)
2609
0
    goto scan_work_done;
2610
2611
0
#ifndef CONFIG_NO_RRM
2612
0
  if (own_request && data &&
2613
0
      wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0)
2614
0
    goto scan_work_done;
2615
0
#endif /* CONFIG_NO_RRM */
2616
2617
0
  if (ml_link_probe_scan(wpa_s))
2618
0
    goto scan_work_done;
2619
2620
0
  if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
2621
0
    goto scan_work_done;
2622
2623
0
  if (autoscan_notify_scan(wpa_s, scan_res))
2624
0
    goto scan_work_done;
2625
2626
0
  if (wpa_s->disconnected) {
2627
0
    wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2628
0
    goto scan_work_done;
2629
0
  }
2630
2631
0
  if (!wpas_driver_bss_selection(wpa_s) &&
2632
0
      bgscan_notify_scan(wpa_s, scan_res) == 1)
2633
0
    goto scan_work_done;
2634
2635
0
  wpas_wps_update_ap_info(wpa_s, scan_res);
2636
2637
0
  if (wnm_scan_process(wpa_s, false) > 0)
2638
0
    goto scan_work_done;
2639
2640
0
  if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
2641
0
      wpa_s->wpa_state < WPA_COMPLETED)
2642
0
    goto scan_work_done;
2643
2644
0
  if (wpa_s->current_ssid && trigger_6ghz_scan && own_request && data &&
2645
0
      wpas_short_ssid_match(wpa_s, scan_res)) {
2646
0
    wpa_dbg(wpa_s, MSG_INFO, "Short SSID match in scan results");
2647
0
    short_ssid_match_found = true;
2648
0
  }
2649
2650
0
  wpa_scan_results_free(scan_res);
2651
2652
0
  if (own_request && wpa_s->scan_work) {
2653
0
    struct wpa_radio_work *work = wpa_s->scan_work;
2654
0
    wpa_s->scan_work = NULL;
2655
0
    radio_work_done(work);
2656
0
  }
2657
2658
0
  os_free(wpa_s->last_scan_freqs);
2659
0
  wpa_s->last_scan_freqs = NULL;
2660
0
  wpa_s->num_last_scan_freqs = 0;
2661
0
  if (own_request && data &&
2662
0
      data->scan_info.freqs && data->scan_info.num_freqs) {
2663
0
    wpa_s->last_scan_freqs = os_malloc(sizeof(int) *
2664
0
               data->scan_info.num_freqs);
2665
0
    if (wpa_s->last_scan_freqs) {
2666
0
      os_memcpy(wpa_s->last_scan_freqs,
2667
0
          data->scan_info.freqs,
2668
0
          sizeof(int) * data->scan_info.num_freqs);
2669
0
      wpa_s->num_last_scan_freqs = data->scan_info.num_freqs;
2670
0
    }
2671
0
  }
2672
2673
0
  if (wpa_s->supp_pbc_active && !wpas_wps_partner_link_scan_done(wpa_s))
2674
0
    return ret;
2675
2676
0
  if (short_ssid_match_found && wpas_trigger_6ghz_scan(wpa_s, data) > 0)
2677
0
    return 1;
2678
2679
0
  return wpas_select_network_from_last_scan(wpa_s, 1, own_request,
2680
0
              trigger_6ghz_scan, data);
2681
2682
0
scan_work_done:
2683
0
  wpa_scan_results_free(scan_res);
2684
0
  if (own_request && wpa_s->scan_work) {
2685
0
    struct wpa_radio_work *work = wpa_s->scan_work;
2686
0
    wpa_s->scan_work = NULL;
2687
0
    radio_work_done(work);
2688
0
  }
2689
0
  return ret;
2690
0
}
2691
2692
2693
/**
2694
 * Select a network from the last scan
2695
 * @wpa_s: Pointer to wpa_supplicant data
2696
 * @new_scan: Whether this function was called right after a scan has finished
2697
 * @own_request: Whether the scan was requested by this interface
2698
 * @trigger_6ghz_scan: Whether to trigger a 6ghz-only scan when applicable
2699
 * @data: Scan data from scan that finished if applicable
2700
 *
2701
 * See _wpa_supplicant_event_scan_results() for return values.
2702
 */
2703
static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
2704
                int new_scan, int own_request,
2705
                bool trigger_6ghz_scan,
2706
                union wpa_event_data *data)
2707
0
{
2708
0
  struct wpa_bss *selected;
2709
0
  struct wpa_ssid *ssid = NULL;
2710
0
  int time_to_reenable = wpas_reenabled_network_time(wpa_s);
2711
2712
0
  if (time_to_reenable > 0) {
2713
0
    wpa_dbg(wpa_s, MSG_DEBUG,
2714
0
      "Postpone network selection by %d seconds since all networks are disabled",
2715
0
      time_to_reenable);
2716
0
    eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2717
0
    eloop_register_timeout(time_to_reenable, 0,
2718
0
               wpas_network_reenabled, wpa_s, NULL);
2719
0
    return 0;
2720
0
  }
2721
2722
0
  if (wpa_s->p2p_mgmt)
2723
0
    return 0; /* no normal connection on p2p_mgmt interface */
2724
2725
0
  wpa_s->owe_transition_search = 0;
2726
#ifdef CONFIG_OWE
2727
  os_free(wpa_s->owe_trans_scan_freq);
2728
  wpa_s->owe_trans_scan_freq = NULL;
2729
#endif /* CONFIG_OWE */
2730
0
  selected = wpa_supplicant_pick_network(wpa_s, &ssid, new_scan);
2731
2732
#ifdef CONFIG_MESH
2733
  if (wpa_s->ifmsh) {
2734
    wpa_msg(wpa_s, MSG_INFO,
2735
      "Avoiding join because we already joined a mesh group");
2736
    return 0;
2737
  }
2738
#endif /* CONFIG_MESH */
2739
2740
0
  if (selected) {
2741
0
    int skip;
2742
0
    skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
2743
0
    if (skip) {
2744
0
      if (new_scan)
2745
0
        wpa_supplicant_rsn_preauth_scan_results(wpa_s);
2746
0
      return 0;
2747
0
    }
2748
2749
0
    wpa_s->suitable_network++;
2750
2751
0
    if (ssid != wpa_s->current_ssid &&
2752
0
        wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2753
0
      wpa_s->own_disconnect_req = 1;
2754
0
      wpa_supplicant_deauthenticate(
2755
0
        wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2756
0
    }
2757
2758
0
    if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
2759
0
      wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
2760
0
      return -1;
2761
0
    }
2762
0
    wpa_s->supp_pbc_active = false;
2763
2764
0
    if (new_scan)
2765
0
      wpa_supplicant_rsn_preauth_scan_results(wpa_s);
2766
    /*
2767
     * Do not allow other virtual radios to trigger operations based
2768
     * on these scan results since we do not want them to start
2769
     * other associations at the same time.
2770
     */
2771
0
    return 1;
2772
0
  } else {
2773
0
    wpa_s->no_suitable_network++;
2774
0
    wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
2775
0
    ssid = wpa_supplicant_pick_new_network(wpa_s);
2776
0
    if (ssid) {
2777
0
      wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
2778
0
      wpa_supplicant_associate(wpa_s, NULL, ssid);
2779
0
      if (new_scan)
2780
0
        wpa_supplicant_rsn_preauth_scan_results(wpa_s);
2781
0
    } else if (own_request) {
2782
0
      if (wpa_s->support_6ghz && trigger_6ghz_scan && data &&
2783
0
          wpas_trigger_6ghz_scan(wpa_s, data) > 0)
2784
0
        return 1;
2785
2786
      /*
2787
       * No SSID found. If SCAN results are as a result of
2788
       * own scan request and not due to a scan request on
2789
       * another shared interface, try another scan.
2790
       */
2791
0
      int timeout_sec = wpa_s->scan_interval;
2792
0
      int timeout_usec = 0;
2793
#ifdef CONFIG_P2P
2794
      int res;
2795
2796
      res = wpas_p2p_scan_no_go_seen(wpa_s);
2797
      if (res == 2)
2798
        return 2;
2799
      if (res == 1)
2800
        return 0;
2801
2802
      if (wpas_p2p_retry_limit_exceeded(wpa_s))
2803
        return 0;
2804
2805
      if (wpa_s->p2p_in_provisioning ||
2806
          wpa_s->show_group_started ||
2807
          wpa_s->p2p_in_invitation) {
2808
        /*
2809
         * Use shorter wait during P2P Provisioning
2810
         * state and during P2P join-a-group operation
2811
         * to speed up group formation.
2812
         */
2813
        timeout_sec = 0;
2814
        timeout_usec = 250000;
2815
        wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2816
                  timeout_usec);
2817
        return 0;
2818
      }
2819
#endif /* CONFIG_P2P */
2820
0
#ifdef CONFIG_INTERWORKING
2821
0
      if (wpa_s->conf->auto_interworking &&
2822
0
          wpa_s->conf->interworking &&
2823
0
          wpa_s->conf->cred) {
2824
0
        wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
2825
0
          "start ANQP fetch since no matching "
2826
0
          "networks found");
2827
0
        wpa_s->network_select = 1;
2828
0
        wpa_s->auto_network_select = 1;
2829
0
        interworking_start_fetch_anqp(wpa_s);
2830
0
        return 1;
2831
0
      }
2832
0
#endif /* CONFIG_INTERWORKING */
2833
#ifdef CONFIG_WPS
2834
      if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
2835
        wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
2836
        timeout_sec = 0;
2837
        timeout_usec = 500000;
2838
        wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2839
                  timeout_usec);
2840
        return 0;
2841
      }
2842
#endif /* CONFIG_WPS */
2843
#ifdef CONFIG_OWE
2844
      if (wpa_s->owe_transition_search) {
2845
        wpa_dbg(wpa_s, MSG_DEBUG,
2846
          "OWE: Use shorter wait during transition mode search");
2847
        timeout_sec = 0;
2848
        timeout_usec = 500000;
2849
        if (wpa_s->owe_trans_scan_freq) {
2850
          os_free(wpa_s->next_scan_freqs);
2851
          wpa_s->next_scan_freqs =
2852
            wpa_s->owe_trans_scan_freq;
2853
          wpa_s->owe_trans_scan_freq = NULL;
2854
          timeout_usec = 100000;
2855
        }
2856
        wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2857
                  timeout_usec);
2858
        return 0;
2859
      }
2860
#endif /* CONFIG_OWE */
2861
0
      if (wpa_supplicant_req_sched_scan(wpa_s))
2862
0
        wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
2863
0
                  timeout_usec);
2864
2865
0
      wpa_msg_ctrl(wpa_s, MSG_INFO,
2866
0
             WPA_EVENT_NETWORK_NOT_FOUND);
2867
0
    }
2868
0
  }
2869
0
  return 0;
2870
0
}
2871
2872
2873
static bool equal_scan_freq_list(struct wpa_supplicant *self,
2874
         struct wpa_supplicant *other)
2875
0
{
2876
0
  const int *list1, *list2;
2877
2878
0
  list1 = self->conf->freq_list ? self->conf->freq_list :
2879
0
    self->last_scan_freqs;
2880
0
  list2 = other->conf->freq_list ? other->conf->freq_list :
2881
0
    other->last_scan_freqs;
2882
2883
0
  return int_array_equal(list1, list2);
2884
0
}
2885
2886
2887
static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
2888
               union wpa_event_data *data)
2889
0
{
2890
0
  struct wpa_supplicant *ifs;
2891
0
  int res;
2892
2893
0
  res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0);
2894
0
  if (res == 2) {
2895
    /*
2896
     * Interface may have been removed, so must not dereference
2897
     * wpa_s after this.
2898
     */
2899
0
    return 1;
2900
0
  }
2901
2902
0
  if (res < 0) {
2903
    /*
2904
     * If no scan results could be fetched, then no need to
2905
     * notify those interfaces that did not actually request
2906
     * this scan. Similarly, if scan results started a new operation on this
2907
     * interface, do not notify other interfaces to avoid concurrent
2908
     * operations during a connection attempt.
2909
     */
2910
0
    return 0;
2911
0
  }
2912
2913
  /*
2914
   * Manual scan requests are more specific to a use case than the
2915
   * normal scan requests; hence, skip updating sibling radios.
2916
   */
2917
0
  if (wpa_s->last_scan_req == MANUAL_SCAN_REQ)
2918
0
    return 0;
2919
2920
  /*
2921
   * Check other interfaces to see if they share the same radio and
2922
   * frequency list. If so, they get updated with this same scan info.
2923
   */
2924
0
  dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2925
0
       radio_list) {
2926
0
    if (ifs != wpa_s && equal_scan_freq_list(wpa_s, ifs)) {
2927
0
      wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
2928
0
           "sibling", ifs->ifname);
2929
0
      res = _wpa_supplicant_event_scan_results(ifs, data, 0,
2930
0
                 res > 0);
2931
0
      if (res < 0)
2932
0
        return 0;
2933
0
    }
2934
0
  }
2935
2936
0
  return 0;
2937
0
}
2938
2939
#endif /* CONFIG_NO_SCAN_PROCESSING */
2940
2941
2942
int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2943
0
{
2944
#ifdef CONFIG_NO_SCAN_PROCESSING
2945
  return -1;
2946
#else /* CONFIG_NO_SCAN_PROCESSING */
2947
0
  struct os_reltime now;
2948
2949
0
  wpa_s->ignore_post_flush_scan_res = 0;
2950
2951
0
  if (wpa_s->last_scan_res_used == 0)
2952
0
    return -1;
2953
2954
0
  os_get_reltime(&now);
2955
0
  if (os_reltime_expired(&now, &wpa_s->last_scan,
2956
0
             wpa_s->conf->scan_res_valid_for_connect)) {
2957
0
    wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
2958
0
    return -1;
2959
0
  } else if (wpa_s->crossed_6ghz_dom) {
2960
0
    wpa_printf(MSG_DEBUG, "Fast associate: Crossed 6 GHz domain");
2961
0
    return -1;
2962
0
  }
2963
2964
0
  return wpas_select_network_from_last_scan(wpa_s, 0, 1, false, NULL);
2965
0
#endif /* CONFIG_NO_SCAN_PROCESSING */
2966
0
}
2967
2968
2969
int wpa_wps_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
2970
0
{
2971
#ifdef CONFIG_NO_SCAN_PROCESSING
2972
  return -1;
2973
#else /* CONFIG_NO_SCAN_PROCESSING */
2974
0
  return wpas_select_network_from_last_scan(wpa_s, 1, 1, false, NULL);
2975
0
#endif /* CONFIG_NO_SCAN_PROCESSING */
2976
0
}
2977
2978
2979
#ifdef CONFIG_WNM
2980
2981
static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
2982
0
{
2983
0
  struct wpa_supplicant *wpa_s = eloop_ctx;
2984
2985
0
  if (wpa_s->wpa_state < WPA_ASSOCIATED)
2986
0
    return;
2987
2988
0
  if (!wpa_s->no_keep_alive) {
2989
0
    wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
2990
0
         MAC2STR(wpa_s->bssid));
2991
    /* TODO: could skip this if normal data traffic has been sent */
2992
    /* TODO: Consider using some more appropriate data frame for
2993
     * this */
2994
0
    if (wpa_s->l2)
2995
0
      l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
2996
0
               (u8 *) "", 0);
2997
0
  }
2998
2999
#ifdef CONFIG_SME
3000
  if (wpa_s->sme.bss_max_idle_period) {
3001
    unsigned int msec;
3002
    msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
3003
    if (msec > 100)
3004
      msec -= 100;
3005
    eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
3006
               wnm_bss_keep_alive, wpa_s, NULL);
3007
  }
3008
#endif /* CONFIG_SME */
3009
0
}
3010
3011
3012
static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
3013
           const u8 *ies, size_t ies_len)
3014
0
{
3015
0
  struct ieee802_11_elems elems;
3016
3017
0
  if (ies == NULL)
3018
0
    return;
3019
3020
0
  if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
3021
0
    return;
3022
3023
#ifdef CONFIG_SME
3024
  if (elems.bss_max_idle_period) {
3025
    unsigned int msec;
3026
    wpa_s->sme.bss_max_idle_period =
3027
      WPA_GET_LE16(elems.bss_max_idle_period);
3028
    wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
3029
         "TU)%s", wpa_s->sme.bss_max_idle_period,
3030
         (elems.bss_max_idle_period[2] & 0x01) ?
3031
         " (protected keep-live required)" : "");
3032
    if (wpa_s->sme.bss_max_idle_period == 0)
3033
      wpa_s->sme.bss_max_idle_period = 1;
3034
    if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
3035
      eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
3036
       /* msec times 1000 */
3037
      msec = wpa_s->sme.bss_max_idle_period * 1024;
3038
      if (msec > 100)
3039
        msec -= 100;
3040
      eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
3041
                 wnm_bss_keep_alive, wpa_s,
3042
                 NULL);
3043
    }
3044
  } else {
3045
    wpa_s->sme.bss_max_idle_period = 0;
3046
  }
3047
#endif /* CONFIG_SME */
3048
0
}
3049
3050
#endif /* CONFIG_WNM */
3051
3052
3053
void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
3054
0
{
3055
0
#ifdef CONFIG_WNM
3056
0
  eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
3057
0
#endif /* CONFIG_WNM */
3058
0
}
3059
3060
3061
static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
3062
          size_t len)
3063
0
{
3064
0
  int res;
3065
3066
0
  wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
3067
0
  res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
3068
0
  if (res) {
3069
0
    wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
3070
0
  }
3071
3072
0
  return res;
3073
0
}
3074
3075
3076
static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
3077
              const u8 *ies, size_t ies_len)
3078
0
{
3079
0
  struct ieee802_11_elems elems;
3080
3081
0
  if (ies == NULL)
3082
0
    return;
3083
3084
0
  if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
3085
0
    return;
3086
3087
0
  if (elems.qos_map_set) {
3088
0
    wpas_qos_map_set(wpa_s, elems.qos_map_set,
3089
0
         elems.qos_map_set_len);
3090
0
  }
3091
0
}
3092
3093
3094
static void wpa_supplicant_set_4addr_mode(struct wpa_supplicant *wpa_s)
3095
0
{
3096
0
  if (wpa_s->enabled_4addr_mode) {
3097
0
    wpa_printf(MSG_DEBUG, "4addr mode already set");
3098
0
    return;
3099
0
  }
3100
3101
0
  if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) {
3102
0
    wpa_msg(wpa_s, MSG_ERROR, "Failed to set 4addr mode");
3103
0
    goto fail;
3104
0
  }
3105
0
  wpa_s->enabled_4addr_mode = 1;
3106
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Successfully set 4addr mode");
3107
0
  return;
3108
3109
0
fail:
3110
0
  wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3111
0
}
3112
3113
3114
static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
3115
          const u8 *ies, size_t ies_len)
3116
0
{
3117
0
  struct ieee802_11_elems elems;
3118
0
  struct multi_ap_params multi_ap;
3119
0
  u16 status;
3120
3121
0
  wpa_s->multi_ap_ie = 0;
3122
3123
0
  if (!ies ||
3124
0
      ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed ||
3125
0
      !elems.multi_ap)
3126
0
    return;
3127
3128
0
  status = check_multi_ap_ie(elems.multi_ap + 4, elems.multi_ap_len - 4,
3129
0
           &multi_ap);
3130
0
  if (status != WLAN_STATUS_SUCCESS)
3131
0
    return;
3132
3133
0
  wpa_s->multi_ap_backhaul = !!(multi_ap.capability &
3134
0
              MULTI_AP_BACKHAUL_BSS);
3135
0
  wpa_s->multi_ap_fronthaul = !!(multi_ap.capability &
3136
0
               MULTI_AP_FRONTHAUL_BSS);
3137
0
  wpa_s->multi_ap_ie = 1;
3138
0
}
3139
3140
3141
static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s)
3142
0
{
3143
0
  if (!wpa_s->current_ssid ||
3144
0
      !wpa_s->current_ssid->multi_ap_backhaul_sta)
3145
0
    return;
3146
3147
0
  if (!wpa_s->multi_ap_ie) {
3148
0
    wpa_printf(MSG_INFO,
3149
0
         "AP does not include valid Multi-AP element");
3150
0
    goto fail;
3151
0
  }
3152
3153
0
  if (!wpa_s->multi_ap_backhaul) {
3154
0
    if (wpa_s->multi_ap_fronthaul &&
3155
0
        wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
3156
0
      wpa_printf(MSG_INFO,
3157
0
           "WPS active, accepting fronthaul-only BSS");
3158
      /* Don't set 4addr mode in this case, so just return */
3159
0
      return;
3160
0
    }
3161
0
    wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS");
3162
0
    goto fail;
3163
0
  }
3164
3165
0
  wpa_supplicant_set_4addr_mode(wpa_s);
3166
0
  return;
3167
3168
0
fail:
3169
0
  wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3170
0
}
3171
3172
3173
#ifdef CONFIG_FST
3174
static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
3175
        const u8 *ie, size_t ie_len)
3176
{
3177
  struct mb_ies_info mb_ies;
3178
3179
  if (!ie || !ie_len || !wpa_s->fst)
3180
      return -ENOENT;
3181
3182
  os_memset(&mb_ies, 0, sizeof(mb_ies));
3183
3184
  while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
3185
    size_t len;
3186
3187
    len = 2 + ie[1];
3188
    if (len > ie_len) {
3189
      wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
3190
            ie, ie_len);
3191
      break;
3192
    }
3193
3194
    if (ie[0] == WLAN_EID_MULTI_BAND) {
3195
      wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
3196
           (unsigned int) len);
3197
      mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
3198
      mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
3199
      mb_ies.nof_ies++;
3200
    }
3201
3202
    ie_len -= len;
3203
    ie += len;
3204
  }
3205
3206
  if (mb_ies.nof_ies > 0) {
3207
    wpabuf_free(wpa_s->received_mb_ies);
3208
    wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
3209
    return 0;
3210
  }
3211
3212
  return -ENOENT;
3213
}
3214
#endif /* CONFIG_FST */
3215
3216
3217
static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s,
3218
                union wpa_event_data *data)
3219
0
{
3220
0
  int sel;
3221
0
  const u8 *p;
3222
0
  int l, len;
3223
0
  bool found = false;
3224
0
  struct wpa_ie_data ie;
3225
0
  struct wpa_ssid *ssid = wpa_s->current_ssid;
3226
0
  struct wpa_bss *bss = wpa_s->current_bss;
3227
0
  int pmf;
3228
3229
0
  if (!ssid)
3230
0
    return 0;
3231
3232
0
  p = data->assoc_info.req_ies;
3233
0
  l = data->assoc_info.req_ies_len;
3234
3235
0
  while (p && l >= 2) {
3236
0
    len = p[1] + 2;
3237
0
    if (len > l) {
3238
0
      wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3239
0
            p, l);
3240
0
      break;
3241
0
    }
3242
0
    if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3243
0
          (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3244
0
         (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3245
0
          (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3246
0
         (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
3247
0
      found = true;
3248
0
      break;
3249
0
    }
3250
0
    l -= len;
3251
0
    p += len;
3252
0
  }
3253
3254
0
  if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0) {
3255
0
    wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV, 0);
3256
0
    return 0;
3257
0
  }
3258
3259
0
  wpa_hexdump(MSG_DEBUG,
3260
0
        "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq",
3261
0
        p, l);
3262
3263
  /* Update proto from (Re)Association Request frame info */
3264
0
  wpa_s->wpa_proto = ie.proto;
3265
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto);
3266
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
3267
0
       !!(wpa_s->wpa_proto & WPA_PROTO_RSN));
3268
3269
  /* Update AKMP suite from (Re)Association Request frame info */
3270
0
  sel = ie.key_mgmt;
3271
0
  if (ssid->key_mgmt)
3272
0
    sel &= ssid->key_mgmt;
3273
3274
0
  wpa_dbg(wpa_s, MSG_DEBUG,
3275
0
    "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x",
3276
0
    ie.key_mgmt, ssid->key_mgmt, sel);
3277
0
  if (ie.key_mgmt && !sel) {
3278
0
    wpa_supplicant_deauthenticate(
3279
0
      wpa_s, WLAN_REASON_AKMP_NOT_VALID);
3280
0
    return -1;
3281
0
  }
3282
3283
#ifdef CONFIG_OCV
3284
  if (((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
3285
       (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV)) && ssid->ocv)
3286
    wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV,
3287
         !!(ie.capabilities & WPA_CAPABILITY_OCVC));
3288
#endif /* CONFIG_OCV */
3289
3290
  /*
3291
   * Update PMK in wpa_sm and the driver if roamed to WPA/WPA2 PSK from a
3292
   * different AKM.
3293
   */
3294
0
  if (wpa_s->key_mgmt != ie.key_mgmt &&
3295
0
      wpa_key_mgmt_wpa_psk_no_sae(ie.key_mgmt)) {
3296
0
    if (!ssid->psk_set) {
3297
0
      wpa_dbg(wpa_s, MSG_INFO,
3298
0
        "No PSK available for association");
3299
0
      wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE", NULL);
3300
0
      return -1;
3301
0
    }
3302
3303
0
    wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL, NULL);
3304
0
    if (wpa_s->conf->key_mgmt_offload &&
3305
0
        (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD) &&
3306
0
        wpa_drv_set_key(wpa_s, -1, 0, NULL, 0, 0, NULL, 0,
3307
0
            ssid->psk, PMK_LEN, KEY_FLAG_PMK))
3308
0
      wpa_dbg(wpa_s, MSG_ERROR,
3309
0
        "WPA: Cannot set PMK for key management offload");
3310
0
  }
3311
3312
0
  wpa_s->key_mgmt = ie.key_mgmt;
3313
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
3314
0
  wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d",
3315
0
    wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto),
3316
0
    wpa_s->wpa_proto);
3317
3318
  /* Update pairwise cipher from (Re)Association Request frame info */
3319
0
  sel = ie.pairwise_cipher;
3320
0
  if (ssid->pairwise_cipher)
3321
0
    sel &= ssid->pairwise_cipher;
3322
3323
0
  wpa_dbg(wpa_s, MSG_DEBUG,
3324
0
    "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x",
3325
0
    ie.pairwise_cipher, ssid->pairwise_cipher, sel);
3326
0
  if (ie.pairwise_cipher && !sel) {
3327
0
    wpa_supplicant_deauthenticate(
3328
0
      wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID);
3329
0
    return -1;
3330
0
  }
3331
3332
0
  wpa_s->pairwise_cipher = ie.pairwise_cipher;
3333
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
3334
0
       wpa_s->pairwise_cipher);
3335
0
  wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
3336
0
    wpa_cipher_txt(wpa_s->pairwise_cipher));
3337
3338
  /* Update other parameters based on AP's WPA IE/RSNE, if available */
3339
0
  if (!bss) {
3340
0
    wpa_dbg(wpa_s, MSG_DEBUG,
3341
0
      "WPA: current_bss == NULL - skip AP IE check");
3342
0
    return 0;
3343
0
  }
3344
3345
  /* Update GTK and IGTK from AP's RSNE */
3346
0
  found = false;
3347
3348
0
  if (wpa_s->wpa_proto & WPA_PROTO_RSN) {
3349
0
    const u8 *bss_rsn;
3350
3351
0
    bss_rsn = wpa_bss_get_rsne(wpa_s, bss, ssid,
3352
0
             wpa_s->valid_links);
3353
0
    if (bss_rsn) {
3354
0
      p = bss_rsn;
3355
0
      len = 2 + bss_rsn[1];
3356
0
      found = true;
3357
0
    }
3358
0
  } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) {
3359
0
    const u8 *bss_wpa;
3360
3361
0
    bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3362
0
    if (bss_wpa) {
3363
0
      p = bss_wpa;
3364
0
      len = 2 + bss_wpa[1];
3365
0
      found = true;
3366
0
    }
3367
0
  }
3368
3369
0
  if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0)
3370
0
    return 0;
3371
3372
0
  pmf = wpas_get_ssid_pmf(wpa_s, ssid);
3373
0
  if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
3374
0
      pmf == MGMT_FRAME_PROTECTION_REQUIRED) {
3375
    /* AP does not support MFP, local configuration requires it */
3376
0
    wpa_supplicant_deauthenticate(
3377
0
      wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3378
0
    return -1;
3379
0
  }
3380
0
  if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
3381
0
      pmf == NO_MGMT_FRAME_PROTECTION) {
3382
    /* AP requires MFP, local configuration disables it */
3383
0
    wpa_supplicant_deauthenticate(
3384
0
      wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB);
3385
0
    return -1;
3386
0
  }
3387
3388
  /* Update PMF from local configuration now that MFP validation was done
3389
   * above */
3390
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf);
3391
3392
  /* Update GTK from AP's RSNE */
3393
0
  sel = ie.group_cipher;
3394
0
  if (ssid->group_cipher)
3395
0
    sel &= ssid->group_cipher;
3396
3397
0
  wpa_dbg(wpa_s, MSG_DEBUG,
3398
0
    "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x",
3399
0
    ie.group_cipher, ssid->group_cipher, sel);
3400
0
  if (ie.group_cipher && !sel) {
3401
0
    wpa_supplicant_deauthenticate(
3402
0
      wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID);
3403
0
    return -1;
3404
0
  }
3405
3406
0
  wpa_s->group_cipher = ie.group_cipher;
3407
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
3408
0
  wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
3409
0
    wpa_cipher_txt(wpa_s->group_cipher));
3410
3411
  /* Update IGTK from AP RSN IE */
3412
0
  sel = ie.mgmt_group_cipher;
3413
0
  if (ssid->group_mgmt_cipher)
3414
0
    sel &= ssid->group_mgmt_cipher;
3415
3416
0
  wpa_dbg(wpa_s, MSG_DEBUG,
3417
0
    "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x",
3418
0
    ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel);
3419
3420
0
  if (pmf == NO_MGMT_FRAME_PROTECTION ||
3421
0
      !(ie.capabilities & WPA_CAPABILITY_MFPC)) {
3422
0
    wpa_dbg(wpa_s, MSG_DEBUG,
3423
0
      "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x",
3424
0
      ie.capabilities);
3425
0
    ie.mgmt_group_cipher = 0;
3426
0
  }
3427
3428
0
  if (ie.mgmt_group_cipher && !sel) {
3429
0
    wpa_supplicant_deauthenticate(
3430
0
      wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED);
3431
0
    return -1;
3432
0
  }
3433
3434
0
  wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher;
3435
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
3436
0
       wpa_s->mgmt_group_cipher);
3437
0
  if (wpa_s->mgmt_group_cipher)
3438
0
    wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s",
3439
0
      wpa_cipher_txt(wpa_s->mgmt_group_cipher));
3440
0
  else
3441
0
    wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
3442
3443
0
  return 0;
3444
0
}
3445
3446
3447
static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
3448
            union wpa_event_data *data)
3449
0
{
3450
0
  int l, len, found = 0, wpa_found, rsn_found;
3451
0
#ifndef CONFIG_NO_WPA
3452
0
  int found_x = 0;
3453
0
#endif /* CONFIG_NO_WPA */
3454
0
  const u8 *p, *ie;
3455
0
  u8 bssid[ETH_ALEN];
3456
0
  bool bssid_known;
3457
0
  enum wpa_rsn_override rsn_override;
3458
3459
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
3460
0
  wpa_s->ssid_verified = false;
3461
0
  wpa_s->bigtk_set = false;
3462
#ifdef CONFIG_SAE
3463
#ifdef CONFIG_SME
3464
  /* SAE H2E binds the SSID into PT and that verifies the SSID
3465
   * implicitly. */
3466
  if (wpa_s->sme.sae.state == SAE_ACCEPTED && wpa_s->sme.sae.h2e)
3467
    wpa_s->ssid_verified = true;
3468
#endif /* CONFIG_SME */
3469
#endif /* CONFIG_SAE */
3470
0
  bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0;
3471
0
  if (data->assoc_info.req_ies)
3472
0
    wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
3473
0
          data->assoc_info.req_ies_len);
3474
0
  if (data->assoc_info.resp_ies) {
3475
0
    wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
3476
0
          data->assoc_info.resp_ies_len);
3477
#ifdef CONFIG_TDLS
3478
    wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
3479
          data->assoc_info.resp_ies_len);
3480
#endif /* CONFIG_TDLS */
3481
0
#ifdef CONFIG_WNM
3482
0
    wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3483
0
               data->assoc_info.resp_ies_len);
3484
0
#endif /* CONFIG_WNM */
3485
0
    interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3486
0
            data->assoc_info.resp_ies_len);
3487
0
    if ((wpa_s->hw_capab & BIT(CAPAB_VHT)) &&
3488
0
        get_ie(data->assoc_info.resp_ies,
3489
0
         data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP))
3490
0
      wpa_s->ieee80211ac = 1;
3491
3492
0
    multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
3493
0
              data->assoc_info.resp_ies_len);
3494
0
  }
3495
0
  if (data->assoc_info.beacon_ies)
3496
0
    wpa_hexdump(MSG_DEBUG, "beacon_ies",
3497
0
          data->assoc_info.beacon_ies,
3498
0
          data->assoc_info.beacon_ies_len);
3499
0
  if (data->assoc_info.freq)
3500
0
    wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
3501
0
      data->assoc_info.freq);
3502
3503
0
  wpa_s->connection_set = 0;
3504
0
  if (data->assoc_info.req_ies && data->assoc_info.resp_ies) {
3505
0
    struct ieee802_11_elems req_elems, resp_elems;
3506
3507
0
    if (ieee802_11_parse_elems(data->assoc_info.req_ies,
3508
0
             data->assoc_info.req_ies_len,
3509
0
             &req_elems, 0) != ParseFailed &&
3510
0
        ieee802_11_parse_elems(data->assoc_info.resp_ies,
3511
0
             data->assoc_info.resp_ies_len,
3512
0
             &resp_elems, 0) != ParseFailed) {
3513
0
      wpa_s->connection_set = 1;
3514
0
      wpa_s->connection_ht = req_elems.ht_capabilities &&
3515
0
        resp_elems.ht_capabilities;
3516
      /* Do not include subset of VHT on 2.4 GHz vendor
3517
       * extension in consideration for reporting VHT
3518
       * association. */
3519
0
      wpa_s->connection_vht = req_elems.vht_capabilities &&
3520
0
        resp_elems.vht_capabilities &&
3521
0
        (!data->assoc_info.freq ||
3522
0
         wpas_freq_to_band(data->assoc_info.freq) !=
3523
0
         BAND_2_4_GHZ);
3524
0
      wpa_s->connection_he = req_elems.he_capabilities &&
3525
0
        resp_elems.he_capabilities;
3526
0
      wpa_s->connection_eht = req_elems.eht_capabilities &&
3527
0
        resp_elems.eht_capabilities;
3528
0
      if (req_elems.rrm_enabled)
3529
0
        wpa_s->rrm.rrm_used = 1;
3530
0
    }
3531
0
  }
3532
3533
0
  p = data->assoc_info.req_ies;
3534
0
  l = data->assoc_info.req_ies_len;
3535
3536
  /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
3537
0
  while (p && l >= 2) {
3538
0
    len = p[1] + 2;
3539
0
    if (len > l) {
3540
0
      wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3541
0
            p, l);
3542
0
      break;
3543
0
    }
3544
0
    if (!found &&
3545
0
        ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3546
0
          (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
3547
0
         (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
3548
0
          (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
3549
0
         (p[0] == WLAN_EID_RSN && p[1] >= 2))) {
3550
0
      if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
3551
0
        break;
3552
0
      found = 1;
3553
0
      wpa_find_assoc_pmkid(wpa_s);
3554
0
    }
3555
0
#ifndef CONFIG_NO_WPA
3556
0
    if (!found_x && p[0] == WLAN_EID_RSNX) {
3557
0
      if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len))
3558
0
        break;
3559
0
      found_x = 1;
3560
0
    }
3561
0
#endif /* CONFIG_NO_WPA */
3562
0
    l -= len;
3563
0
    p += len;
3564
0
  }
3565
0
  if (!found && data->assoc_info.req_ies)
3566
0
    wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
3567
0
#ifndef CONFIG_NO_WPA
3568
0
  if (!found_x && data->assoc_info.req_ies)
3569
0
    wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0);
3570
0
#endif /* CONFIG_NO_WPA */
3571
3572
0
  rsn_override = RSN_OVERRIDE_NOT_USED;
3573
0
  ie = get_vendor_ie(data->assoc_info.req_ies,
3574
0
         data->assoc_info.req_ies_len,
3575
0
         RSN_SELECTION_IE_VENDOR_TYPE);
3576
0
  if (ie && ie[1] >= 4 + 1) {
3577
0
    switch (ie[2 + 4]) {
3578
0
    case RSN_SELECTION_RSNE:
3579
0
      rsn_override = RSN_OVERRIDE_RSNE;
3580
0
      break;
3581
0
    case RSN_SELECTION_RSNE_OVERRIDE:
3582
0
      rsn_override = RSN_OVERRIDE_RSNE_OVERRIDE;
3583
0
      break;
3584
0
    case RSN_SELECTION_RSNE_OVERRIDE_2:
3585
0
      rsn_override = RSN_OVERRIDE_RSNE_OVERRIDE_2;
3586
0
      break;
3587
0
    }
3588
0
  }
3589
0
  wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_OVERRIDE, rsn_override);
3590
3591
#ifdef CONFIG_FILS
3592
#ifdef CONFIG_SME
3593
  if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS ||
3594
      wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) {
3595
    if (!data->assoc_info.resp_frame ||
3596
        fils_process_assoc_resp(wpa_s->wpa,
3597
              data->assoc_info.resp_frame,
3598
              data->assoc_info.resp_frame_len) <
3599
        0) {
3600
      wpa_supplicant_deauthenticate(wpa_s,
3601
                  WLAN_REASON_UNSPECIFIED);
3602
      return -1;
3603
    }
3604
3605
    /* FILS use of an AEAD cipher include the SSID element in
3606
     * (Re)Association Request frame in the AAD and since the AP
3607
     * accepted that, the SSID was verified. */
3608
    wpa_s->ssid_verified = true;
3609
  }
3610
#endif /* CONFIG_SME */
3611
3612
  /* Additional processing for FILS when SME is in driver */
3613
  if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS &&
3614
      !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
3615
    wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1);
3616
#endif /* CONFIG_FILS */
3617
3618
#ifdef CONFIG_OWE
3619
  if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
3620
      !(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OWE_OFFLOAD_STA) &&
3621
      (!bssid_known ||
3622
       owe_process_assoc_resp(wpa_s->wpa,
3623
            wpa_s->valid_links ?
3624
            wpa_s->ap_mld_addr : bssid,
3625
            data->assoc_info.resp_ies,
3626
            data->assoc_info.resp_ies_len) < 0)) {
3627
    wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
3628
    return -1;
3629
  }
3630
#endif /* CONFIG_OWE */
3631
3632
#ifdef CONFIG_DPP2
3633
  wpa_sm_set_dpp_z(wpa_s->wpa, NULL);
3634
  if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP &&
3635
      wpa_s->dpp_pfs) {
3636
    struct ieee802_11_elems elems;
3637
3638
    if (ieee802_11_parse_elems(data->assoc_info.resp_ies,
3639
             data->assoc_info.resp_ies_len,
3640
             &elems, 0) == ParseFailed ||
3641
        !elems.owe_dh)
3642
      goto no_pfs;
3643
    if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh,
3644
            elems.owe_dh_len) < 0) {
3645
      wpa_supplicant_deauthenticate(wpa_s,
3646
                  WLAN_REASON_UNSPECIFIED);
3647
      return -1;
3648
    }
3649
3650
    wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret);
3651
  }
3652
no_pfs:
3653
#endif /* CONFIG_DPP2 */
3654
3655
#ifdef CONFIG_IEEE80211R
3656
#ifdef CONFIG_SME
3657
  if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
3658
    if (!bssid_known ||
3659
        wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3660
             data->assoc_info.resp_ies,
3661
             data->assoc_info.resp_ies_len,
3662
             bssid) < 0) {
3663
      wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3664
        "Reassociation Response failed");
3665
      wpa_supplicant_deauthenticate(
3666
        wpa_s, WLAN_REASON_INVALID_IE);
3667
      return -1;
3668
    }
3669
    /* SSID is included in PMK-R0 derivation, so it is verified
3670
     * implicitly. */
3671
    wpa_s->ssid_verified = true;
3672
  }
3673
3674
  p = data->assoc_info.resp_ies;
3675
  l = data->assoc_info.resp_ies_len;
3676
3677
#ifdef CONFIG_WPS_STRICT
3678
  if (p && wpa_s->current_ssid &&
3679
      wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
3680
    struct wpabuf *wps;
3681
    wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
3682
    if (wps == NULL) {
3683
      wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
3684
        "include WPS IE in (Re)Association Response");
3685
      return -1;
3686
    }
3687
3688
    if (wps_validate_assoc_resp(wps) < 0) {
3689
      wpabuf_free(wps);
3690
      wpa_supplicant_deauthenticate(
3691
        wpa_s, WLAN_REASON_INVALID_IE);
3692
      return -1;
3693
    }
3694
    wpabuf_free(wps);
3695
  }
3696
#endif /* CONFIG_WPS_STRICT */
3697
3698
  /* Go through the IEs and make a copy of the MDIE, if present. */
3699
  while (p && l >= 2) {
3700
    len = p[1] + 2;
3701
    if (len > l) {
3702
      wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
3703
            p, l);
3704
      break;
3705
    }
3706
    if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
3707
        p[1] >= MOBILITY_DOMAIN_ID_LEN) {
3708
      wpa_s->sme.ft_used = 1;
3709
      os_memcpy(wpa_s->sme.mobility_domain, p + 2,
3710
          MOBILITY_DOMAIN_ID_LEN);
3711
      break;
3712
    }
3713
    l -= len;
3714
    p += len;
3715
  }
3716
#endif /* CONFIG_SME */
3717
3718
  /* Process FT when SME is in the driver */
3719
  if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
3720
      wpa_ft_is_completed(wpa_s->wpa)) {
3721
    if (!bssid_known ||
3722
        wpa_ft_validate_reassoc_resp(wpa_s->wpa,
3723
             data->assoc_info.resp_ies,
3724
             data->assoc_info.resp_ies_len,
3725
             bssid) < 0) {
3726
      wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
3727
        "Reassociation Response failed");
3728
      wpa_supplicant_deauthenticate(
3729
        wpa_s, WLAN_REASON_INVALID_IE);
3730
      return -1;
3731
    }
3732
    wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
3733
    /* SSID is included in PMK-R0 derivation, so it is verified
3734
     * implicitly. */
3735
    wpa_s->ssid_verified = true;
3736
  }
3737
3738
  wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
3739
           data->assoc_info.resp_ies_len);
3740
#endif /* CONFIG_IEEE80211R */
3741
3742
0
#ifndef CONFIG_NO_ROBUST_AV
3743
0
  if (bssid_known)
3744
0
    wpas_handle_assoc_resp_mscs(wpa_s, bssid,
3745
0
              data->assoc_info.resp_ies,
3746
0
              data->assoc_info.resp_ies_len);
3747
0
#endif /* CONFIG_NO_ROBUST_AV */
3748
3749
  /* WPA/RSN IE from Beacon/ProbeResp */
3750
0
  p = data->assoc_info.beacon_ies;
3751
0
  l = data->assoc_info.beacon_ies_len;
3752
3753
  /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
3754
   */
3755
0
  wpa_found = rsn_found = 0;
3756
0
  while (p && l >= 2) {
3757
0
    len = p[1] + 2;
3758
0
    if (len > l) {
3759
0
      wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
3760
0
            p, l);
3761
0
      break;
3762
0
    }
3763
0
    if (!wpa_found &&
3764
0
        p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3765
0
        os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
3766
0
      wpa_found = 1;
3767
0
      wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
3768
0
    }
3769
3770
0
    if (!rsn_found &&
3771
0
        p[0] == WLAN_EID_RSN && p[1] >= 2) {
3772
0
      rsn_found = 1;
3773
0
      wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
3774
0
    }
3775
3776
0
    if (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3777
0
        WPA_GET_BE32(&p[2]) == RSNE_OVERRIDE_2_IE_VENDOR_TYPE)
3778
0
      wpa_sm_set_ap_rsne_override_2(wpa_s->wpa, p, len);
3779
3780
0
    if (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3781
0
        WPA_GET_BE32(&p[2]) == RSNE_OVERRIDE_IE_VENDOR_TYPE)
3782
0
      wpa_sm_set_ap_rsne_override(wpa_s->wpa, p, len);
3783
3784
0
    if (p[0] == WLAN_EID_RSNX && p[1] >= 1)
3785
0
      wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len);
3786
3787
0
    if (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
3788
0
        WPA_GET_BE32(&p[2]) == RSNXE_OVERRIDE_IE_VENDOR_TYPE)
3789
0
      wpa_sm_set_ap_rsnxe_override(wpa_s->wpa, p, len);
3790
3791
0
    l -= len;
3792
0
    p += len;
3793
0
  }
3794
3795
0
  if (!wpa_found && data->assoc_info.beacon_ies)
3796
0
    wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
3797
0
  if (!rsn_found && data->assoc_info.beacon_ies) {
3798
0
    wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
3799
0
    wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0);
3800
0
    wpa_sm_set_ap_rsne_override(wpa_s->wpa, NULL, 0);
3801
0
    wpa_sm_set_ap_rsne_override_2(wpa_s->wpa, NULL, 0);
3802
0
    wpa_sm_set_ap_rsnxe_override(wpa_s->wpa, NULL, 0);
3803
0
  }
3804
0
  if (wpa_found || rsn_found)
3805
0
    wpa_s->ap_ies_from_associnfo = 1;
3806
3807
0
  if (wpa_s->assoc_freq && data->assoc_info.freq) {
3808
0
    struct wpa_bss *bss;
3809
0
    unsigned int freq = 0;
3810
3811
0
    if (bssid_known) {
3812
0
      bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
3813
0
      if (bss)
3814
0
        freq = bss->freq;
3815
0
    }
3816
0
    if (freq != data->assoc_info.freq) {
3817
0
      wpa_printf(MSG_DEBUG,
3818
0
           "Operating frequency changed from %u to %u MHz",
3819
0
           wpa_s->assoc_freq, data->assoc_info.freq);
3820
0
      wpa_supplicant_update_scan_results(wpa_s, bssid);
3821
0
    }
3822
0
  }
3823
3824
0
  wpa_s->assoc_freq = data->assoc_info.freq;
3825
3826
0
#ifndef CONFIG_NO_ROBUST_AV
3827
0
  wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies,
3828
0
          data->assoc_info.resp_ies_len);
3829
0
#endif /* CONFIG_NO_ROBUST_AV */
3830
3831
0
  return 0;
3832
0
}
3833
3834
3835
static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
3836
0
{
3837
0
  const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL;
3838
0
  const u8 *rsnoe, *rsno2e, *rsnxoe;
3839
3840
0
  if (!wpa_s->current_bss || !wpa_s->current_ssid)
3841
0
    return -1;
3842
3843
0
  if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
3844
0
    return 0;
3845
3846
0
  bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3847
0
          WPA_IE_VENDOR_TYPE);
3848
0
  bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
3849
0
  bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX);
3850
0
  rsnoe = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3851
0
              RSNE_OVERRIDE_IE_VENDOR_TYPE);
3852
0
  rsno2e = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3853
0
               RSNE_OVERRIDE_2_IE_VENDOR_TYPE);
3854
0
  rsnxoe = wpa_bss_get_vendor_ie(wpa_s->current_bss,
3855
0
               RSNXE_OVERRIDE_IE_VENDOR_TYPE);
3856
3857
0
  if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
3858
0
         bss_wpa ? 2 + bss_wpa[1] : 0) ||
3859
0
      wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
3860
0
         bss_rsn ? 2 + bss_rsn[1] : 0) ||
3861
0
      wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx,
3862
0
         bss_rsnx ? 2 + bss_rsnx[1] : 0) ||
3863
0
      wpa_sm_set_ap_rsne_override(wpa_s->wpa, rsnoe,
3864
0
          rsnoe ? 2 + rsnoe[1] : 0) ||
3865
0
      wpa_sm_set_ap_rsne_override_2(wpa_s->wpa, rsno2e,
3866
0
            rsno2e ? 2 + rsno2e[1] : 0) ||
3867
0
      wpa_sm_set_ap_rsnxe_override(wpa_s->wpa, rsnxoe,
3868
0
           rsnxoe ? 2 + rsnxoe[1] : 0))
3869
0
    return -1;
3870
3871
0
  return 0;
3872
0
}
3873
3874
3875
static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
3876
             union wpa_event_data *data)
3877
0
{
3878
#ifdef CONFIG_FST
3879
  struct assoc_info *ai = data ? &data->assoc_info : NULL;
3880
  struct wpa_bss *bss = wpa_s->current_bss;
3881
  const u8 *ieprb, *iebcn;
3882
3883
  wpabuf_free(wpa_s->received_mb_ies);
3884
  wpa_s->received_mb_ies = NULL;
3885
3886
  if (ai &&
3887
      !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
3888
    wpa_printf(MSG_DEBUG,
3889
         "FST: MB IEs updated from Association Response frame");
3890
    return;
3891
  }
3892
3893
  if (ai &&
3894
      !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
3895
    wpa_printf(MSG_DEBUG,
3896
         "FST: MB IEs updated from association event Beacon IEs");
3897
    return;
3898
  }
3899
3900
  if (!bss)
3901
    return;
3902
3903
  ieprb = wpa_bss_ie_ptr(bss);
3904
  iebcn = ieprb + bss->ie_len;
3905
3906
  if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
3907
    wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
3908
  else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
3909
    wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
3910
#endif /* CONFIG_FST */
3911
0
}
3912
3913
3914
static unsigned int wpas_ml_parse_assoc(struct wpa_supplicant *wpa_s,
3915
          struct ieee802_11_elems *elems,
3916
          struct ml_sta_link_info *ml_info)
3917
0
{
3918
0
  struct wpabuf *mlbuf;
3919
0
  struct ieee80211_eht_ml *ml;
3920
0
  size_t ml_len;
3921
0
  struct eht_ml_basic_common_info *common_info;
3922
0
  const u8 *pos;
3923
0
  u16 eml_capa = 0, mld_capa = 0;
3924
0
  const u16 control = MULTI_LINK_CONTROL_TYPE_BASIC |
3925
0
    BASIC_MULTI_LINK_CTRL_PRES_LINK_ID |
3926
0
    BASIC_MULTI_LINK_CTRL_PRES_BSS_PARAM_CH_COUNT;
3927
0
  u8 expected_common_info_len = 9;
3928
0
  unsigned int i = 0;
3929
0
  u16 ml_control;
3930
3931
0
  if (!wpa_s->valid_links || !elems->basic_mle || !elems->basic_mle_len)
3932
0
    return 0;
3933
3934
0
  mlbuf = ieee802_11_defrag(elems->basic_mle, elems->basic_mle_len, true);
3935
0
  if (!mlbuf)
3936
0
    return 0;
3937
3938
0
  ml = (struct ieee80211_eht_ml *) wpabuf_head(mlbuf);
3939
0
  ml_len = wpabuf_len(mlbuf);
3940
0
  if (ml_len < sizeof(*ml))
3941
0
    goto out;
3942
3943
0
  os_memset(ml_info, 0, sizeof(*ml_info) * MAX_NUM_MLD_LINKS);
3944
3945
0
  ml_control = le_to_host16(ml->ml_control);
3946
3947
0
  if ((ml_control & control) != control) {
3948
0
    wpa_printf(MSG_DEBUG, "MLD: Invalid presence BM=0x%x",
3949
0
         ml_control);
3950
0
    goto out;
3951
0
  }
3952
3953
0
  if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
3954
0
    wpa_printf(MSG_DEBUG, "MLD: EML capabilities included");
3955
0
    expected_common_info_len += 2;
3956
0
  }
3957
3958
0
  if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
3959
0
    wpa_printf(MSG_DEBUG, "MLD: MLD capabilities included");
3960
0
    expected_common_info_len += 2;
3961
0
  }
3962
3963
0
  if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO) {
3964
0
    wpa_printf(MSG_DEBUG,
3965
0
         "MLD: Unexpected: medium sync delay info present");
3966
0
    expected_common_info_len += 2;
3967
0
  }
3968
3969
0
  if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_AP_MLD_ID) {
3970
0
    wpa_printf(MSG_DEBUG,
3971
0
         "MLD: Unexpected: MLD ID present");
3972
0
    expected_common_info_len++;
3973
0
  }
3974
3975
0
  if (sizeof(*ml) + expected_common_info_len > ml_len) {
3976
0
    wpa_printf(MSG_DEBUG,
3977
0
         "MLD: Not enough bytes for common info. ml_len=%zu",
3978
0
         ml_len);
3979
0
    goto out;
3980
0
  }
3981
3982
0
  common_info = (struct eht_ml_basic_common_info *) ml->variable;
3983
0
  if (common_info->len < expected_common_info_len) {
3984
0
    wpa_printf(MSG_DEBUG,
3985
0
         "MLD: Invalid common info len=%u. expected=%u",
3986
0
         common_info->len, expected_common_info_len);
3987
0
    goto out;
3988
0
  }
3989
3990
0
  wpa_printf(MSG_DEBUG, "MLD: address: " MACSTR,
3991
0
       MAC2STR(common_info->mld_addr));
3992
3993
0
  if (!ether_addr_equal(wpa_s->ap_mld_addr, common_info->mld_addr)) {
3994
0
    wpa_printf(MSG_DEBUG, "MLD: Mismatching MLD address (expected "
3995
0
         MACSTR ")", MAC2STR(wpa_s->ap_mld_addr));
3996
0
    goto out;
3997
0
  }
3998
3999
0
  pos = common_info->variable;
4000
4001
  /* Store the information for the association link */
4002
0
  ml_info[i].link_id = *pos;
4003
0
  pos++;
4004
4005
  /* Skip the BSS Parameters Change Count */
4006
0
  pos++;
4007
4008
  /* Skip the Medium Synchronization Delay Information if present  */
4009
0
  if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO)
4010
0
    pos += 2;
4011
4012
0
  if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
4013
0
    eml_capa = WPA_GET_LE16(pos);
4014
0
    pos += 2;
4015
0
  }
4016
4017
0
  if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
4018
0
    mld_capa = WPA_GET_LE16(pos);
4019
0
    pos += 2;
4020
0
  }
4021
4022
0
  wpa_printf(MSG_DEBUG,
4023
0
       "MLD: link_id=%u, eml=0x%x, mld=0x%x",
4024
0
       ml_info[i].link_id, eml_capa, mld_capa);
4025
4026
0
  i++;
4027
4028
0
  pos = ((u8 *) common_info) + common_info->len;
4029
0
  ml_len -= sizeof(*ml) + common_info->len;
4030
0
  while (ml_len > 2 && i < MAX_NUM_MLD_LINKS) {
4031
0
    size_t sub_elem_len, sta_info_len, sta_info_len_min;
4032
0
    u8 nstr_bitmap_len = 0;
4033
0
    u16 ctrl;
4034
0
    const u8 *end;
4035
0
    int num_frag_subelems;
4036
4037
0
    num_frag_subelems =
4038
0
      ieee802_11_defrag_mle_subelem(mlbuf, pos,
4039
0
                  &sub_elem_len);
4040
0
    if (num_frag_subelems < 0) {
4041
0
      wpa_printf(MSG_DEBUG,
4042
0
           "MLD: Failed to parse MLE subelem");
4043
0
      goto out;
4044
0
    }
4045
4046
0
    ml_len -= num_frag_subelems * 2;
4047
4048
0
    wpa_printf(MSG_DEBUG, "MLD: Subelement len=%zu", sub_elem_len);
4049
4050
0
    if (sub_elem_len > ml_len - 2) {
4051
0
      wpa_printf(MSG_DEBUG,
4052
0
           "MLD: Invalid link info len: %zu > %zu",
4053
0
           2 + sub_elem_len, ml_len);
4054
0
      goto out;
4055
0
    }
4056
4057
0
    switch (*pos) {
4058
0
    case EHT_ML_SUB_ELEM_PER_STA_PROFILE:
4059
0
      break;
4060
0
    case EHT_ML_SUB_ELEM_FRAGMENT:
4061
0
    case EHT_ML_SUB_ELEM_VENDOR:
4062
0
      wpa_printf(MSG_DEBUG,
4063
0
           "MLD: Skip subelement id=%u, len=%zu",
4064
0
           *pos, sub_elem_len);
4065
0
      pos += 2 + sub_elem_len;
4066
0
      ml_len -= 2 + sub_elem_len;
4067
0
      continue;
4068
0
    default:
4069
0
      wpa_printf(MSG_DEBUG, "MLD: Unknown subelement ID=%u",
4070
0
           *pos);
4071
0
      goto out;
4072
0
    }
4073
4074
0
    end = pos + 2 + sub_elem_len;
4075
4076
    /* Skip the subelement ID and the length */
4077
0
    pos += 2;
4078
0
    ml_len -= 2;
4079
4080
0
    if (end - pos < 2)
4081
0
      goto out;
4082
4083
    /* Get the station control field */
4084
0
    ctrl = WPA_GET_LE16(pos);
4085
4086
0
    pos += 2;
4087
0
    ml_len -= 2;
4088
4089
0
    if (!(ctrl & EHT_PER_STA_CTRL_COMPLETE_PROFILE_MSK)) {
4090
0
      wpa_printf(MSG_DEBUG,
4091
0
           "MLD: Per STA complete profile expected");
4092
0
      goto out;
4093
0
    }
4094
4095
0
    if (!(ctrl & EHT_PER_STA_CTRL_MAC_ADDR_PRESENT_MSK)) {
4096
0
      wpa_printf(MSG_DEBUG,
4097
0
           "MLD: Per STA MAC address not present");
4098
0
      goto out;
4099
0
    }
4100
4101
0
    if (!(ctrl & EHT_PER_STA_CTRL_TSF_OFFSET_PRESENT_MSK)) {
4102
0
      wpa_printf(MSG_DEBUG,
4103
0
           "MLD: Per STA TSF offset not present");
4104
0
      goto out;
4105
0
    }
4106
4107
0
    if (!(ctrl & EHT_PER_STA_CTRL_BEACON_INTERVAL_PRESENT_MSK)) {
4108
0
      wpa_printf(MSG_DEBUG,
4109
0
           "MLD: Beacon interval not present");
4110
0
      goto out;
4111
0
    }
4112
4113
0
    if (!(ctrl & EHT_PER_STA_CTRL_DTIM_INFO_PRESENT_MSK)) {
4114
0
      wpa_printf(MSG_DEBUG,
4115
0
           "MLD:  DTIM information not present");
4116
0
      goto out;
4117
0
    }
4118
4119
0
    if (ctrl & EHT_PER_STA_CTRL_NSTR_LINK_PAIR_PRESENT_MSK) {
4120
0
      if (ctrl & EHT_PER_STA_CTRL_NSTR_BM_SIZE_MSK)
4121
0
        nstr_bitmap_len = 2;
4122
0
      else
4123
0
        nstr_bitmap_len = 1;
4124
0
    }
4125
4126
0
    if (!(ctrl & EHT_PER_STA_CTRL_BSS_PARAM_CNT_PRESENT_MSK)) {
4127
0
      wpa_printf(MSG_DEBUG,
4128
0
           "MLD:  BSS params change count not present");
4129
0
      goto out;
4130
0
    }
4131
4132
0
    sta_info_len_min = 1 + ETH_ALEN + 8 + 2 + 2 + 1 +
4133
0
      nstr_bitmap_len;
4134
0
    if (sta_info_len_min > ml_len ||
4135
0
        sta_info_len_min > (size_t) (end - pos) ||
4136
0
        sta_info_len_min + 2 > sub_elem_len) {
4137
0
      wpa_printf(MSG_DEBUG,
4138
0
           "MLD: Invalid STA info min len=%zu, len=%u",
4139
0
           sta_info_len_min, *pos);
4140
0
      goto out;
4141
0
    }
4142
0
    sta_info_len = *pos;
4143
0
    if (sta_info_len > ml_len ||
4144
0
        sta_info_len > sub_elem_len - 2 ||
4145
0
        sta_info_len < sta_info_len_min) {
4146
0
      wpa_printf(MSG_DEBUG,
4147
0
           "MLD: Invalid STA info min len=%zu, len=%zu",
4148
0
           sta_info_len_min, sta_info_len);
4149
0
      goto out;
4150
0
    }
4151
4152
    /* Get the link address */
4153
0
    wpa_printf(MSG_DEBUG,
4154
0
         "MLD: link addr: " MACSTR " nstr BM len=%u",
4155
0
         MAC2STR(pos + 1), nstr_bitmap_len);
4156
4157
0
    ml_info[i].link_id = ctrl & EHT_PER_STA_CTRL_LINK_ID_MSK;
4158
0
    os_memcpy(ml_info[i].bssid, pos + 1, ETH_ALEN);
4159
4160
0
    pos += sta_info_len;
4161
0
    ml_len -= sta_info_len;
4162
4163
0
    wpa_printf(MSG_DEBUG, "MLD: sub_elem_len=%zu, sta_info_len=%zu",
4164
0
         sub_elem_len, sta_info_len);
4165
4166
0
    sub_elem_len -= sta_info_len + 2;
4167
0
    if (sub_elem_len < 4) {
4168
0
      wpa_printf(MSG_DEBUG, "MLD: Per STA profile too short");
4169
0
      goto out;
4170
0
    }
4171
4172
0
    wpa_hexdump(MSG_MSGDUMP, "MLD: STA profile", pos, sub_elem_len);
4173
0
    ml_info[i].status = WPA_GET_LE16(pos + 2);
4174
4175
0
    if (sub_elem_len > ml_len)
4176
0
      goto out;
4177
0
    pos += sub_elem_len;
4178
0
    ml_len -= sub_elem_len;
4179
4180
0
    i++;
4181
0
  }
4182
4183
0
  wpabuf_free(mlbuf);
4184
0
  return i;
4185
0
out:
4186
0
  wpabuf_free(mlbuf);
4187
0
  return 0;
4188
0
}
4189
4190
4191
static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s)
4192
0
{
4193
0
  struct driver_sta_mlo_info mlo;
4194
0
  int i;
4195
4196
0
  os_memset(&mlo, 0, sizeof(mlo));
4197
0
  if (wpas_drv_get_sta_mlo_info(wpa_s, &mlo)) {
4198
0
    wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO link info");
4199
0
    wpa_supplicant_deauthenticate(wpa_s,
4200
0
                WLAN_REASON_DEAUTH_LEAVING);
4201
0
    return -1;
4202
0
  }
4203
4204
0
  if (wpa_s->valid_links == mlo.valid_links) {
4205
0
    bool match = true;
4206
4207
0
    if (!mlo.valid_links)
4208
0
      return 0;
4209
4210
0
    for_each_link(mlo.valid_links, i) {
4211
0
      if (!ether_addr_equal(wpa_s->links[i].addr,
4212
0
                mlo.links[i].addr) ||
4213
0
          !ether_addr_equal(wpa_s->links[i].bssid,
4214
0
                mlo.links[i].bssid)) {
4215
0
        match = false;
4216
0
        break;
4217
0
      }
4218
0
    }
4219
4220
0
    if (match && wpa_s->mlo_assoc_link_id == mlo.assoc_link_id &&
4221
0
        ether_addr_equal(wpa_s->ap_mld_addr, mlo.ap_mld_addr))
4222
0
      return 0;
4223
0
  }
4224
4225
0
  wpa_s->valid_links = mlo.valid_links;
4226
0
  wpa_s->mlo_assoc_link_id = mlo.assoc_link_id;
4227
0
  os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN);
4228
0
  for_each_link(wpa_s->valid_links, i) {
4229
0
    os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN);
4230
0
    os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN);
4231
0
    wpa_s->links[i].freq = mlo.links[i].freq;
4232
0
    wpa_supplicant_update_link_bss(wpa_s, i, mlo.links[i].bssid);
4233
0
  }
4234
4235
0
  return 0;
4236
0
}
4237
4238
4239
static int wpa_sm_set_ml_info(struct wpa_supplicant *wpa_s)
4240
0
{
4241
0
  struct driver_sta_mlo_info drv_mlo;
4242
0
  struct wpa_sm_mlo wpa_mlo;
4243
0
  int i;
4244
4245
0
  os_memset(&drv_mlo, 0, sizeof(drv_mlo));
4246
0
  if (wpas_drv_get_sta_mlo_info(wpa_s, &drv_mlo)) {
4247
0
    wpa_dbg(wpa_s, MSG_INFO, "Failed to get MLO link info");
4248
0
    return -1;
4249
0
  }
4250
4251
0
  os_memset(&wpa_mlo, 0, sizeof(wpa_mlo));
4252
0
  if (!drv_mlo.valid_links)
4253
0
    goto out;
4254
4255
0
  os_memcpy(wpa_mlo.ap_mld_addr, drv_mlo.ap_mld_addr, ETH_ALEN);
4256
0
  wpa_mlo.assoc_link_id = drv_mlo.assoc_link_id;
4257
0
  wpa_mlo.valid_links = drv_mlo.valid_links;
4258
0
  wpa_mlo.req_links = drv_mlo.req_links;
4259
4260
0
  for_each_link(drv_mlo.req_links, i) {
4261
0
    struct wpa_bss *bss;
4262
0
    const u8 *rsne, *rsnxe, *rsnoe, *rsno2e, *rsnxoe;
4263
4264
0
    bss = wpa_supplicant_get_new_bss(wpa_s, drv_mlo.links[i].bssid);
4265
0
    if (!bss) {
4266
0
      wpa_dbg(wpa_s, MSG_INFO,
4267
0
        "Failed to get MLO link %d BSS", i);
4268
0
      return -1;
4269
0
    }
4270
4271
0
    rsne = wpa_bss_get_ie(bss, WLAN_EID_RSN);
4272
0
    rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
4273
0
    rsnoe = wpa_bss_get_vendor_ie(bss,
4274
0
                RSNE_OVERRIDE_IE_VENDOR_TYPE);
4275
0
    rsno2e = wpa_bss_get_vendor_ie(bss,
4276
0
                 RSNE_OVERRIDE_2_IE_VENDOR_TYPE);
4277
0
    rsnxoe = wpa_bss_get_vendor_ie(bss,
4278
0
                 RSNXE_OVERRIDE_IE_VENDOR_TYPE);
4279
4280
0
    wpa_mlo.links[i].ap_rsne = rsne ? (u8 *) rsne : NULL;
4281
0
    wpa_mlo.links[i].ap_rsne_len = rsne ? 2 + rsne[1] : 0;
4282
0
    wpa_mlo.links[i].ap_rsnxe = rsnxe ? (u8 *) rsnxe : NULL;
4283
0
    wpa_mlo.links[i].ap_rsnxe_len = rsnxe ? 2 + rsnxe[1] : 0;
4284
0
    wpa_mlo.links[i].ap_rsnoe = rsnoe ? (u8 *) rsnoe : NULL;
4285
0
    wpa_mlo.links[i].ap_rsnoe_len = rsnoe ? 2 + rsnoe[1] : 0;
4286
0
    wpa_mlo.links[i].ap_rsno2e = rsno2e ? (u8 *) rsno2e : NULL;
4287
0
    wpa_mlo.links[i].ap_rsno2e_len = rsno2e ? 2 + rsno2e[1] : 0;
4288
0
    wpa_mlo.links[i].ap_rsnxoe = rsnxoe ? (u8 *) rsnxoe : NULL;
4289
0
    wpa_mlo.links[i].ap_rsnxoe_len = rsnxoe ? 2 + rsnxoe[1] : 0;
4290
4291
0
    os_memcpy(wpa_mlo.links[i].bssid, drv_mlo.links[i].bssid,
4292
0
        ETH_ALEN);
4293
0
    os_memcpy(wpa_mlo.links[i].addr, drv_mlo.links[i].addr,
4294
0
        ETH_ALEN);
4295
0
  }
4296
4297
0
out:
4298
0
  return wpa_sm_set_mlo_params(wpa_s->wpa, &wpa_mlo);
4299
0
}
4300
4301
4302
static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
4303
               union wpa_event_data *data)
4304
0
{
4305
0
  u8 bssid[ETH_ALEN];
4306
0
  int ft_completed, already_authorized;
4307
0
  int new_bss = 0;
4308
#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
4309
  struct wpa_bss *bss;
4310
#endif /* CONFIG_FILS || CONFIG_MBO */
4311
4312
#ifdef CONFIG_AP
4313
  if (wpa_s->ap_iface) {
4314
    if (!data)
4315
      return;
4316
    hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
4317
            data->assoc_info.addr,
4318
            data->assoc_info.req_ies,
4319
            data->assoc_info.req_ies_len, NULL, 0,
4320
            NULL, data->assoc_info.reassoc);
4321
    return;
4322
  }
4323
#endif /* CONFIG_AP */
4324
4325
0
  eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
4326
0
  wpa_s->own_reconnect_req = 0;
4327
4328
0
  ft_completed = wpa_ft_is_completed(wpa_s->wpa);
4329
4330
0
  if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
4331
0
    wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
4332
0
    wpa_supplicant_deauthenticate(
4333
0
      wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4334
0
    return;
4335
0
  }
4336
4337
0
  if (wpa_drv_get_mlo_info(wpa_s) < 0) {
4338
0
    wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO connection info");
4339
0
    wpa_supplicant_deauthenticate(wpa_s,
4340
0
                WLAN_REASON_DEAUTH_LEAVING);
4341
0
    return;
4342
0
  }
4343
4344
0
  if (ft_completed &&
4345
0
      (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) {
4346
0
    wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR,
4347
0
      MAC2STR(bssid));
4348
0
    if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) {
4349
0
      wpa_printf(MSG_ERROR,
4350
0
           "Can't find target AP's information!");
4351
0
      return;
4352
0
    }
4353
0
    wpa_supplicant_assoc_update_ie(wpa_s);
4354
0
  }
4355
4356
0
  if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
4357
0
    return;
4358
  /*
4359
   * FILS authentication can share the same mechanism to mark the
4360
   * connection fully authenticated, so set ft_completed also based on
4361
   * FILS result.
4362
   */
4363
0
  if (!ft_completed)
4364
0
    ft_completed = wpa_fils_is_completed(wpa_s->wpa);
4365
4366
0
  wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
4367
0
  if (!ether_addr_equal(bssid, wpa_s->bssid)) {
4368
0
    if (os_reltime_initialized(&wpa_s->session_start)) {
4369
0
      os_reltime_age(&wpa_s->session_start,
4370
0
               &wpa_s->session_length);
4371
0
      wpa_s->session_start.sec = 0;
4372
0
      wpa_s->session_start.usec = 0;
4373
0
      wpas_notify_session_length(wpa_s);
4374
0
    } else {
4375
0
      wpas_notify_auth_changed(wpa_s);
4376
0
      os_get_reltime(&wpa_s->session_start);
4377
0
    }
4378
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
4379
0
      MACSTR, MAC2STR(bssid));
4380
0
    new_bss = 1;
4381
0
    random_add_randomness(bssid, ETH_ALEN);
4382
0
    os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
4383
0
    os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
4384
0
    wpas_notify_bssid_changed(wpa_s);
4385
4386
0
    if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
4387
0
      wpa_clear_keys(wpa_s, bssid);
4388
0
    }
4389
0
    if (wpa_supplicant_select_config(wpa_s, data) < 0) {
4390
0
      wpa_supplicant_deauthenticate(
4391
0
        wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4392
0
      return;
4393
0
    }
4394
0
  }
4395
4396
0
  if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
4397
0
      data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0)
4398
0
    return;
4399
4400
0
  multi_ap_set_4addr_mode(wpa_s);
4401
4402
0
  if (wpa_s->conf->ap_scan == 1 &&
4403
0
      wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
4404
0
    if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
4405
0
      wpa_msg(wpa_s, MSG_WARNING,
4406
0
        "WPA/RSN IEs not updated");
4407
0
  }
4408
4409
0
  wpas_fst_update_mb_assoc(wpa_s, data);
4410
4411
#ifdef CONFIG_SME
4412
  /*
4413
   * Cache the current AP's BSSID (for non-MLO connection) or MLD address
4414
   * (for MLO connection) as the previous BSSID for subsequent
4415
   * reassociation requests handled by SME-in-wpa_supplicant.
4416
   */
4417
  os_memcpy(wpa_s->sme.prev_bssid,
4418
      wpa_s->valid_links ? wpa_s->ap_mld_addr : bssid, ETH_ALEN);
4419
  wpa_s->sme.prev_bssid_set = 1;
4420
  wpa_s->sme.last_unprot_disconnect.sec = 0;
4421
#endif /* CONFIG_SME */
4422
4423
0
  wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
4424
0
  if (wpa_s->current_ssid) {
4425
    /* When using scanning (ap_scan=1), SIM PC/SC interface can be
4426
     * initialized before association, but for other modes,
4427
     * initialize PC/SC here, if the current configuration needs
4428
     * smartcard or SIM/USIM. */
4429
0
    wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
4430
0
  }
4431
0
  wpa_sm_notify_assoc(wpa_s->wpa, bssid);
4432
4433
0
  if (wpa_sm_set_ml_info(wpa_s)) {
4434
0
    wpa_dbg(wpa_s, MSG_INFO,
4435
0
      "Failed to set MLO connection info to wpa_sm");
4436
0
    wpa_supplicant_deauthenticate(wpa_s,
4437
0
                WLAN_REASON_DEAUTH_LEAVING);
4438
0
    return;
4439
0
  }
4440
4441
0
  if (wpa_s->l2)
4442
0
    l2_packet_notify_auth_start(wpa_s->l2);
4443
4444
0
  already_authorized = data && data->assoc_info.authorized;
4445
4446
  /*
4447
   * Set portEnabled first to false in order to get EAP state machine out
4448
   * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
4449
   * state machine may transit to AUTHENTICATING state based on obsolete
4450
   * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
4451
   * AUTHENTICATED without ever giving chance to EAP state machine to
4452
   * reset the state.
4453
   */
4454
0
  if (!ft_completed && !already_authorized) {
4455
0
    eapol_sm_notify_portEnabled(wpa_s->eapol, false);
4456
0
    eapol_sm_notify_portValid(wpa_s->eapol, false);
4457
0
  }
4458
0
  if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4459
0
      wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
4460
0
      wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed ||
4461
0
      already_authorized || wpa_s->drv_authorized_port)
4462
0
    eapol_sm_notify_eap_success(wpa_s->eapol, false);
4463
  /* 802.1X::portControl = Auto */
4464
0
  eapol_sm_notify_portEnabled(wpa_s->eapol, true);
4465
0
  wpa_s->eapol_received = 0;
4466
0
  if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4467
0
      wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
4468
0
      (wpa_s->current_ssid &&
4469
0
       wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) {
4470
0
    if (wpa_s->current_ssid &&
4471
0
        wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
4472
0
        (wpa_s->drv_flags &
4473
0
         WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
4474
      /*
4475
       * Set the key after having received joined-IBSS event
4476
       * from the driver.
4477
       */
4478
0
      wpa_supplicant_set_wpa_none_key(wpa_s,
4479
0
              wpa_s->current_ssid);
4480
0
    }
4481
0
    wpa_supplicant_cancel_auth_timeout(wpa_s);
4482
0
    wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4483
0
  } else if (!ft_completed) {
4484
    /* Timeout for receiving the first EAPOL packet */
4485
0
    wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
4486
0
  }
4487
0
  wpa_supplicant_cancel_scan(wpa_s);
4488
4489
0
  if (ft_completed) {
4490
    /*
4491
     * FT protocol completed - make sure EAPOL state machine ends
4492
     * up in authenticated.
4493
     */
4494
0
    wpa_supplicant_cancel_auth_timeout(wpa_s);
4495
0
    wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4496
0
    eapol_sm_notify_portValid(wpa_s->eapol, true);
4497
0
    eapol_sm_notify_eap_success(wpa_s->eapol, true);
4498
0
  } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) &&
4499
0
       wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
4500
0
    if (already_authorized) {
4501
      /*
4502
       * We are done; the driver will take care of RSN 4-way
4503
       * handshake.
4504
       */
4505
0
      wpa_supplicant_cancel_auth_timeout(wpa_s);
4506
0
      wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
4507
0
      eapol_sm_notify_portValid(wpa_s->eapol, true);
4508
0
      eapol_sm_notify_eap_success(wpa_s->eapol, true);
4509
0
    } else {
4510
      /* Update port, WPA_COMPLETED state from the
4511
       * EVENT_PORT_AUTHORIZED handler when the driver is done
4512
       * with the 4-way handshake.
4513
       */
4514
0
      wpa_msg(wpa_s, MSG_DEBUG,
4515
0
        "ASSOC INFO: wait for driver port authorized indication");
4516
0
    }
4517
0
  } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) &&
4518
0
       wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
4519
    /*
4520
     * The driver will take care of RSN 4-way handshake, so we need
4521
     * to allow EAPOL supplicant to complete its work without
4522
     * waiting for WPA supplicant.
4523
     */
4524
0
    eapol_sm_notify_portValid(wpa_s->eapol, true);
4525
0
  }
4526
4527
0
  wpa_s->last_eapol_matches_bssid = 0;
4528
4529
#ifdef CONFIG_TESTING_OPTIONS
4530
  if (wpa_s->rsne_override_eapol) {
4531
    wpa_printf(MSG_DEBUG,
4532
         "TESTING: RSNE EAPOL-Key msg 2/4 override");
4533
    wpa_sm_set_assoc_wpa_ie(wpa_s->wpa,
4534
          wpabuf_head(wpa_s->rsne_override_eapol),
4535
          wpabuf_len(wpa_s->rsne_override_eapol));
4536
  }
4537
  if (wpa_s->rsnxe_override_eapol) {
4538
    wpa_printf(MSG_DEBUG,
4539
         "TESTING: RSNXE EAPOL-Key msg 2/4 override");
4540
    wpa_sm_set_assoc_rsnxe(wpa_s->wpa,
4541
               wpabuf_head(wpa_s->rsnxe_override_eapol),
4542
               wpabuf_len(wpa_s->rsnxe_override_eapol));
4543
  }
4544
#endif /* CONFIG_TESTING_OPTIONS */
4545
4546
0
  if (wpa_s->pending_eapol_rx) {
4547
0
    struct os_reltime now, age;
4548
0
    os_get_reltime(&now);
4549
0
    os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
4550
0
    if (age.sec == 0 && age.usec < 200000 &&
4551
0
        ether_addr_equal(wpa_s->pending_eapol_rx_src,
4552
0
             wpa_s->valid_links ? wpa_s->ap_mld_addr :
4553
0
             bssid)) {
4554
0
      wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
4555
0
        "frame that was received just before "
4556
0
        "association notification");
4557
0
      wpa_supplicant_rx_eapol(
4558
0
        wpa_s, wpa_s->pending_eapol_rx_src,
4559
0
        wpabuf_head(wpa_s->pending_eapol_rx),
4560
0
        wpabuf_len(wpa_s->pending_eapol_rx),
4561
0
        wpa_s->pending_eapol_encrypted);
4562
0
    }
4563
0
    wpabuf_free(wpa_s->pending_eapol_rx);
4564
0
    wpa_s->pending_eapol_rx = NULL;
4565
0
  }
4566
4567
#ifdef CONFIG_WEP
4568
  if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
4569
       wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
4570
      wpa_s->current_ssid &&
4571
      (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
4572
    /* Set static WEP keys again */
4573
    wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
4574
  }
4575
#endif /* CONFIG_WEP */
4576
4577
#ifdef CONFIG_IBSS_RSN
4578
  if (wpa_s->current_ssid &&
4579
      wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
4580
      wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
4581
      wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
4582
      wpa_s->ibss_rsn == NULL) {
4583
    wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
4584
    if (!wpa_s->ibss_rsn) {
4585
      wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
4586
      wpa_supplicant_deauthenticate(
4587
        wpa_s, WLAN_REASON_DEAUTH_LEAVING);
4588
      return;
4589
    }
4590
4591
    ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
4592
  }
4593
#endif /* CONFIG_IBSS_RSN */
4594
4595
0
  wpas_wps_notify_assoc(wpa_s, bssid);
4596
4597
0
#ifndef CONFIG_NO_WMM_AC
4598
0
  if (data) {
4599
0
    wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
4600
0
            data->assoc_info.resp_ies_len,
4601
0
            &data->assoc_info.wmm_params);
4602
4603
0
    if (wpa_s->reassoc_same_bss)
4604
0
      wmm_ac_restore_tspecs(wpa_s);
4605
0
  }
4606
0
#endif /* CONFIG_NO_WMM_AC */
4607
4608
#if defined(CONFIG_FILS) || defined(CONFIG_MBO)
4609
  bss = wpa_bss_get_bssid(wpa_s, bssid);
4610
#endif /* CONFIG_FILS || CONFIG_MBO */
4611
#ifdef CONFIG_FILS
4612
  if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) {
4613
    const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
4614
4615
    if (fils_cache_id)
4616
      wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id);
4617
  }
4618
#endif /* CONFIG_FILS */
4619
4620
#ifdef CONFIG_MBO
4621
  wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid);
4622
#endif /* CONFIG_MBO */
4623
4624
#ifdef CONFIG_DPP2
4625
  wpa_s->dpp_pfs_fallback = 0;
4626
#endif /* CONFIG_DPP2 */
4627
4628
0
  if (wpa_s->current_ssid && wpa_s->current_ssid->enable_4addr_mode)
4629
0
    wpa_supplicant_set_4addr_mode(wpa_s);
4630
0
}
4631
4632
4633
static int disconnect_reason_recoverable(u16 reason_code)
4634
0
{
4635
0
  return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
4636
0
    reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
4637
0
    reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
4638
0
}
4639
4640
4641
static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
4642
            u16 reason_code,
4643
            int locally_generated)
4644
0
{
4645
0
  const u8 *bssid;
4646
4647
0
  bssid = wpa_s->bssid;
4648
0
  if (is_zero_ether_addr(bssid))
4649
0
    bssid = wpa_s->pending_bssid;
4650
4651
0
  if (!is_zero_ether_addr(bssid) ||
4652
0
      wpa_s->wpa_state >= WPA_AUTHENTICATING) {
4653
0
    wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
4654
0
      " reason=%d%s",
4655
0
      MAC2STR(bssid), reason_code,
4656
0
      locally_generated ? " locally_generated=1" : "");
4657
0
  }
4658
0
}
4659
4660
4661
static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
4662
         int locally_generated)
4663
0
{
4664
0
  if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
4665
0
      !wpa_s->new_connection ||
4666
0
      !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
4667
0
      wpa_key_mgmt_sae(wpa_s->key_mgmt))
4668
0
    return 0; /* Not in initial 4-way handshake with PSK */
4669
4670
  /*
4671
   * It looks like connection was lost while trying to go through PSK
4672
   * 4-way handshake. Filter out known disconnection cases that are caused
4673
   * by something else than PSK mismatch to avoid confusing reports.
4674
   */
4675
4676
0
  if (locally_generated) {
4677
0
    if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
4678
0
      return 0;
4679
0
    if (reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY)
4680
0
      return 0;
4681
0
  }
4682
4683
0
  return 1;
4684
0
}
4685
4686
4687
static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
4688
             u16 reason_code,
4689
             int locally_generated)
4690
0
{
4691
0
  const u8 *bssid;
4692
0
  struct wpa_bss *fast_reconnect = NULL;
4693
0
  struct wpa_ssid *fast_reconnect_ssid = NULL;
4694
0
  struct wpa_bss *curr = NULL;
4695
4696
0
  if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
4697
0
      reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
4698
0
      locally_generated)
4699
    /*
4700
     * Remove the inactive AP (which is probably out of range) from
4701
     * the BSS list after marking disassociation. In particular
4702
     * mac80211-based drivers use the
4703
     * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
4704
     * locally generated disconnection events for cases where the
4705
     * AP does not reply anymore.
4706
     */
4707
0
    curr = wpa_s->current_bss;
4708
4709
0
  if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
4710
0
    wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
4711
0
      "pre-shared key may be incorrect");
4712
0
    if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
4713
0
      return; /* P2P group removed */
4714
0
    bssid = wpa_s->bssid;
4715
0
    if (is_zero_ether_addr(bssid))
4716
0
      bssid = wpa_s->pending_bssid;
4717
0
    wpa_bssid_ignore_add(wpa_s, bssid);
4718
0
    wpas_auth_failed(wpa_s, "WRONG_KEY", wpa_s->pending_bssid);
4719
0
    wpas_notify_psk_mismatch(wpa_s);
4720
0
  }
4721
0
  if (!wpa_s->disconnected &&
4722
0
      (!wpa_s->auto_reconnect_disabled ||
4723
0
       wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
4724
0
       wpas_wps_searching(wpa_s) ||
4725
0
       wpas_wps_reenable_networks_pending(wpa_s))) {
4726
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
4727
0
      "reconnect (wps=%d/%d wpa_state=%d)",
4728
0
      wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
4729
0
      wpas_wps_searching(wpa_s),
4730
0
      wpa_s->wpa_state);
4731
0
    if (wpa_s->wpa_state == WPA_COMPLETED &&
4732
0
        wpa_s->current_ssid &&
4733
0
        wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
4734
0
        (wpa_s->own_reconnect_req ||
4735
0
         (!locally_generated &&
4736
0
          disconnect_reason_recoverable(reason_code)))) {
4737
      /*
4738
       * It looks like the AP has dropped association with
4739
       * us, but could allow us to get back in. This is also
4740
       * triggered for cases where local reconnection request
4741
       * is used to force reassociation with the same BSS.
4742
       * Try to reconnect to the same BSS without a full scan
4743
       * to save time for some common cases.
4744
       */
4745
0
      fast_reconnect = wpa_s->current_bss;
4746
0
      fast_reconnect_ssid = wpa_s->current_ssid;
4747
0
    } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) {
4748
0
      wpa_supplicant_req_scan(wpa_s, 0, 100000);
4749
0
    } else {
4750
0
      wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
4751
0
        "immediate scan");
4752
0
    }
4753
0
  } else {
4754
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
4755
0
      "try to re-connect");
4756
0
    wpa_s->reassociate = 0;
4757
0
    wpa_s->disconnected = 1;
4758
0
    if (!wpa_s->pno)
4759
0
      wpa_supplicant_cancel_sched_scan(wpa_s);
4760
0
  }
4761
0
  bssid = wpa_s->bssid;
4762
0
  if (is_zero_ether_addr(bssid))
4763
0
    bssid = wpa_s->pending_bssid;
4764
0
  if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
4765
0
    wpas_connection_failed(wpa_s, bssid, NULL);
4766
0
  wpa_sm_notify_disassoc(wpa_s->wpa);
4767
0
  ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE);
4768
4769
0
  if (locally_generated)
4770
0
    wpa_s->disconnect_reason = -reason_code;
4771
0
  else
4772
0
    wpa_s->disconnect_reason = reason_code;
4773
0
  wpas_notify_disconnect_reason(wpa_s);
4774
#ifdef CONFIG_DPP2
4775
  wpas_dpp_send_conn_status_result(wpa_s, DPP_STATUS_AUTH_FAILURE);
4776
#endif /* CONFIG_DPP2 */
4777
0
  if (wpa_supplicant_dynamic_keys(wpa_s)) {
4778
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
4779
0
    wpa_clear_keys(wpa_s, wpa_s->bssid);
4780
0
  }
4781
0
  wpa_supplicant_mark_disassoc(wpa_s);
4782
4783
0
  if (curr)
4784
0
    wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
4785
4786
0
  if (fast_reconnect &&
4787
0
      !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
4788
0
      !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
4789
0
      !disallowed_ssid(wpa_s, fast_reconnect->ssid,
4790
0
           fast_reconnect->ssid_len) &&
4791
0
      !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
4792
0
      !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) {
4793
0
#ifndef CONFIG_NO_SCAN_PROCESSING
4794
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
4795
0
    if (wpa_supplicant_connect(wpa_s, fast_reconnect,
4796
0
             fast_reconnect_ssid) < 0) {
4797
      /* Recover through full scan */
4798
0
      wpa_supplicant_req_scan(wpa_s, 0, 100000);
4799
0
    }
4800
0
#endif /* CONFIG_NO_SCAN_PROCESSING */
4801
0
  } else if (fast_reconnect) {
4802
    /*
4803
     * Could not reconnect to the same BSS due to network being
4804
     * disabled. Use a new scan to match the alternative behavior
4805
     * above, i.e., to continue automatic reconnection attempt in a
4806
     * way that enforces disabled network rules.
4807
     */
4808
0
    wpa_supplicant_req_scan(wpa_s, 0, 100000);
4809
0
  }
4810
0
}
4811
4812
4813
#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
4814
void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
4815
{
4816
  struct wpa_supplicant *wpa_s = eloop_ctx;
4817
4818
  if (!wpa_s->pending_mic_error_report)
4819
    return;
4820
4821
  wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
4822
  wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
4823
  wpa_s->pending_mic_error_report = 0;
4824
}
4825
#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4826
4827
4828
static void
4829
wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
4830
           union wpa_event_data *data)
4831
0
{
4832
0
  int pairwise;
4833
0
  struct os_reltime t;
4834
4835
0
  wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
4836
0
  pairwise = (data && data->michael_mic_failure.unicast);
4837
0
  os_get_reltime(&t);
4838
0
  if ((os_reltime_initialized(&wpa_s->last_michael_mic_error) &&
4839
0
       !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
4840
0
      wpa_s->pending_mic_error_report) {
4841
0
    if (wpa_s->pending_mic_error_report) {
4842
      /*
4843
       * Send the pending MIC error report immediately since
4844
       * we are going to start countermeasures and AP better
4845
       * do the same.
4846
       */
4847
0
      wpa_sm_key_request(wpa_s->wpa, 1,
4848
0
             wpa_s->pending_mic_error_pairwise);
4849
0
    }
4850
4851
    /* Send the new MIC error report immediately since we are going
4852
     * to start countermeasures and AP better do the same.
4853
     */
4854
0
    wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4855
4856
    /* initialize countermeasures */
4857
0
    wpa_s->countermeasures = 1;
4858
4859
0
    wpa_bssid_ignore_add(wpa_s, wpa_s->bssid);
4860
4861
0
    wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
4862
4863
    /*
4864
     * Need to wait for completion of request frame. We do not get
4865
     * any callback for the message completion, so just wait a
4866
     * short while and hope for the best. */
4867
0
    os_sleep(0, 10000);
4868
4869
0
    wpa_drv_set_countermeasures(wpa_s, 1);
4870
0
    wpa_supplicant_deauthenticate(wpa_s,
4871
0
                WLAN_REASON_MICHAEL_MIC_FAILURE);
4872
0
    eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
4873
0
             wpa_s, NULL);
4874
0
    eloop_register_timeout(60, 0,
4875
0
               wpa_supplicant_stop_countermeasures,
4876
0
               wpa_s, NULL);
4877
    /* TODO: mark the AP rejected for 60 second. STA is
4878
     * allowed to associate with another AP.. */
4879
0
  } else {
4880
#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
4881
    if (wpa_s->mic_errors_seen) {
4882
      /*
4883
       * Reduce the effectiveness of Michael MIC error
4884
       * reports as a means for attacking against TKIP if
4885
       * more than one MIC failure is noticed with the same
4886
       * PTK. We delay the transmission of the reports by a
4887
       * random time between 0 and 60 seconds in order to
4888
       * force the attacker wait 60 seconds before getting
4889
       * the information on whether a frame resulted in a MIC
4890
       * failure.
4891
       */
4892
      u8 rval[4];
4893
      int sec;
4894
4895
      if (os_get_random(rval, sizeof(rval)) < 0)
4896
        sec = os_random() % 60;
4897
      else
4898
        sec = WPA_GET_BE32(rval) % 60;
4899
      wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
4900
        "report %d seconds", sec);
4901
      wpa_s->pending_mic_error_report = 1;
4902
      wpa_s->pending_mic_error_pairwise = pairwise;
4903
      eloop_cancel_timeout(
4904
        wpa_supplicant_delayed_mic_error_report,
4905
        wpa_s, NULL);
4906
      eloop_register_timeout(
4907
        sec, os_random() % 1000000,
4908
        wpa_supplicant_delayed_mic_error_report,
4909
        wpa_s, NULL);
4910
    } else {
4911
      wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4912
    }
4913
#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4914
0
    wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
4915
0
#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
4916
0
  }
4917
0
  wpa_s->last_michael_mic_error = t;
4918
0
  wpa_s->mic_errors_seen++;
4919
0
}
4920
4921
4922
#ifdef CONFIG_TERMINATE_ONLASTIF
4923
static int any_interfaces(struct wpa_supplicant *head)
4924
{
4925
  struct wpa_supplicant *wpa_s;
4926
4927
  for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
4928
    if (!wpa_s->interface_removed)
4929
      return 1;
4930
  return 0;
4931
}
4932
#endif /* CONFIG_TERMINATE_ONLASTIF */
4933
4934
4935
static void
4936
wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
4937
              union wpa_event_data *data)
4938
0
{
4939
0
  if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
4940
0
    return;
4941
4942
0
  switch (data->interface_status.ievent) {
4943
0
  case EVENT_INTERFACE_ADDED:
4944
0
    if (!wpa_s->interface_removed)
4945
0
      break;
4946
0
    wpa_s->interface_removed = 0;
4947
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
4948
0
    if (wpa_supplicant_driver_init(wpa_s) < 0) {
4949
0
      wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
4950
0
        "driver after interface was added");
4951
0
    }
4952
4953
#ifdef CONFIG_P2P
4954
    if (!wpa_s->global->p2p &&
4955
        !wpa_s->global->p2p_disabled &&
4956
        !wpa_s->conf->p2p_disabled &&
4957
        (wpa_s->drv_flags &
4958
         WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4959
        wpas_p2p_add_p2pdev_interface(
4960
          wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
4961
      wpa_printf(MSG_INFO,
4962
           "P2P: Failed to enable P2P Device interface");
4963
      /* Try to continue without. P2P will be disabled. */
4964
    }
4965
#endif /* CONFIG_P2P */
4966
4967
0
    break;
4968
0
  case EVENT_INTERFACE_REMOVED:
4969
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
4970
0
    wpa_s->interface_removed = 1;
4971
0
    wpa_supplicant_mark_disassoc(wpa_s);
4972
0
    wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
4973
0
    l2_packet_deinit(wpa_s->l2);
4974
0
    wpa_s->l2 = NULL;
4975
4976
#ifdef CONFIG_P2P
4977
    if (wpa_s->global->p2p &&
4978
        wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
4979
        (wpa_s->drv_flags &
4980
         WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
4981
      wpa_dbg(wpa_s, MSG_DEBUG,
4982
        "Removing P2P Device interface");
4983
      wpa_supplicant_remove_iface(
4984
        wpa_s->global, wpa_s->global->p2p_init_wpa_s,
4985
        0);
4986
      wpa_s->global->p2p_init_wpa_s = NULL;
4987
    }
4988
#endif /* CONFIG_P2P */
4989
4990
#ifdef CONFIG_MATCH_IFACE
4991
    if (wpa_s->matched) {
4992
      wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
4993
      break;
4994
    }
4995
#endif /* CONFIG_MATCH_IFACE */
4996
4997
#ifdef CONFIG_TERMINATE_ONLASTIF
4998
    /* check if last interface */
4999
    if (!any_interfaces(wpa_s->global->ifaces))
5000
      eloop_terminate();
5001
#endif /* CONFIG_TERMINATE_ONLASTIF */
5002
0
    break;
5003
0
  }
5004
0
}
5005
5006
5007
#ifdef CONFIG_TDLS
5008
static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
5009
              union wpa_event_data *data)
5010
{
5011
  if (data == NULL)
5012
    return;
5013
  switch (data->tdls.oper) {
5014
  case TDLS_REQUEST_SETUP:
5015
    wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
5016
    if (wpa_tdls_is_external_setup(wpa_s->wpa))
5017
      wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
5018
    else
5019
      wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
5020
    break;
5021
  case TDLS_REQUEST_TEARDOWN:
5022
    if (wpa_tdls_is_external_setup(wpa_s->wpa))
5023
      wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
5024
                 data->tdls.reason_code);
5025
    else
5026
      wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
5027
            data->tdls.peer);
5028
    break;
5029
  case TDLS_REQUEST_DISCOVER:
5030
      wpa_tdls_send_discovery_request(wpa_s->wpa,
5031
              data->tdls.peer);
5032
    break;
5033
  }
5034
}
5035
#endif /* CONFIG_TDLS */
5036
5037
5038
#ifdef CONFIG_WNM
5039
static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
5040
             union wpa_event_data *data)
5041
0
{
5042
0
  if (data == NULL)
5043
0
    return;
5044
0
  switch (data->wnm.oper) {
5045
0
  case WNM_OPER_SLEEP:
5046
0
    wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
5047
0
         "(action=%d, intval=%d)",
5048
0
         data->wnm.sleep_action, data->wnm.sleep_intval);
5049
0
    ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
5050
0
               data->wnm.sleep_intval, NULL);
5051
0
    break;
5052
0
  }
5053
0
}
5054
#endif /* CONFIG_WNM */
5055
5056
5057
#ifdef CONFIG_IEEE80211R
5058
static void
5059
wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
5060
         union wpa_event_data *data)
5061
{
5062
  if (data == NULL)
5063
    return;
5064
5065
  if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
5066
            data->ft_ies.ies_len,
5067
            data->ft_ies.ft_action,
5068
            data->ft_ies.target_ap,
5069
            data->ft_ies.ric_ies,
5070
            data->ft_ies.ric_ies_len) < 0) {
5071
    /* TODO: prevent MLME/driver from trying to associate? */
5072
  }
5073
}
5074
#endif /* CONFIG_IEEE80211R */
5075
5076
5077
#ifdef CONFIG_IBSS_RSN
5078
static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
5079
            union wpa_event_data *data)
5080
{
5081
  struct wpa_ssid *ssid;
5082
  if (wpa_s->wpa_state < WPA_ASSOCIATED)
5083
    return;
5084
  if (data == NULL)
5085
    return;
5086
  ssid = wpa_s->current_ssid;
5087
  if (ssid == NULL)
5088
    return;
5089
  if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
5090
    return;
5091
5092
  ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
5093
}
5094
5095
5096
static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
5097
             union wpa_event_data *data)
5098
{
5099
  struct wpa_ssid *ssid = wpa_s->current_ssid;
5100
5101
  if (ssid == NULL)
5102
    return;
5103
5104
  /* check if the ssid is correctly configured as IBSS/RSN */
5105
  if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
5106
    return;
5107
5108
  ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
5109
           data->rx_mgmt.frame_len);
5110
}
5111
#endif /* CONFIG_IBSS_RSN */
5112
5113
5114
#ifdef CONFIG_IEEE80211R
5115
static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
5116
       size_t len)
5117
{
5118
  const u8 *sta_addr, *target_ap_addr;
5119
  u16 status;
5120
5121
  wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
5122
  if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
5123
    return; /* only SME case supported for now */
5124
  if (len < 1 + 2 * ETH_ALEN + 2)
5125
    return;
5126
  if (data[0] != 2)
5127
    return; /* Only FT Action Response is supported for now */
5128
  sta_addr = data + 1;
5129
  target_ap_addr = data + 1 + ETH_ALEN;
5130
  status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
5131
  wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
5132
    MACSTR " TargetAP " MACSTR " status %u",
5133
    MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
5134
5135
  if (!ether_addr_equal(sta_addr, wpa_s->own_addr)) {
5136
    wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
5137
      " in FT Action Response", MAC2STR(sta_addr));
5138
    return;
5139
  }
5140
5141
  if (status) {
5142
    wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
5143
      "failure (status code %d)", status);
5144
    /* TODO: report error to FT code(?) */
5145
    return;
5146
  }
5147
5148
  if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
5149
            len - (1 + 2 * ETH_ALEN + 2), 1,
5150
            target_ap_addr, NULL, 0) < 0)
5151
    return;
5152
5153
#ifdef CONFIG_SME
5154
  {
5155
    struct wpa_bss *bss;
5156
    bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
5157
    if (bss)
5158
      wpa_s->sme.freq = bss->freq;
5159
    wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
5160
    sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
5161
            WLAN_AUTH_FT);
5162
  }
5163
#endif /* CONFIG_SME */
5164
}
5165
#endif /* CONFIG_IEEE80211R */
5166
5167
5168
static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
5169
                 struct unprot_deauth *e)
5170
0
{
5171
0
  wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
5172
0
       "dropped: " MACSTR " -> " MACSTR
5173
0
       " (reason code %u)",
5174
0
       MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
5175
0
  sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
5176
0
}
5177
5178
5179
static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
5180
             struct unprot_disassoc *e)
5181
0
{
5182
0
  wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
5183
0
       "dropped: " MACSTR " -> " MACSTR
5184
0
       " (reason code %u)",
5185
0
       MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
5186
0
  sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
5187
0
}
5188
5189
5190
static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
5191
          u16 reason_code, int locally_generated,
5192
          const u8 *ie, size_t ie_len, int deauth)
5193
0
{
5194
#ifdef CONFIG_AP
5195
  if (wpa_s->ap_iface && addr) {
5196
    hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
5197
    return;
5198
  }
5199
5200
  if (wpa_s->ap_iface) {
5201
    wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
5202
    return;
5203
  }
5204
#endif /* CONFIG_AP */
5205
5206
0
  if (!locally_generated)
5207
0
    wpa_s->own_disconnect_req = 0;
5208
5209
0
  wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
5210
5211
0
  if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
5212
0
        ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
5213
0
    (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
5214
0
         eapol_sm_failed(wpa_s->eapol))) &&
5215
0
       !wpa_s->eap_expected_failure))
5216
0
    wpas_auth_failed(wpa_s, "AUTH_FAILED", addr);
5217
5218
#ifdef CONFIG_P2P
5219
  if (deauth && reason_code > 0) {
5220
    if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
5221
            locally_generated) > 0) {
5222
      /*
5223
       * The interface was removed, so cannot continue
5224
       * processing any additional operations after this.
5225
       */
5226
      return;
5227
    }
5228
  }
5229
#endif /* CONFIG_P2P */
5230
5231
0
  wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
5232
0
               locally_generated);
5233
0
}
5234
5235
5236
static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
5237
        struct disassoc_info *info)
5238
0
{
5239
0
  u16 reason_code = 0;
5240
0
  int locally_generated = 0;
5241
0
  const u8 *addr = NULL;
5242
0
  const u8 *ie = NULL;
5243
0
  size_t ie_len = 0;
5244
5245
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
5246
5247
0
  if (info) {
5248
0
    addr = info->addr;
5249
0
    ie = info->ie;
5250
0
    ie_len = info->ie_len;
5251
0
    reason_code = info->reason_code;
5252
0
    locally_generated = info->locally_generated;
5253
0
    wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code,
5254
0
      reason2str(reason_code),
5255
0
      locally_generated ? " locally_generated=1" : "");
5256
0
    if (addr)
5257
0
      wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
5258
0
        MAC2STR(addr));
5259
0
    wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
5260
0
          ie, ie_len);
5261
0
  }
5262
5263
#ifdef CONFIG_AP
5264
  if (wpa_s->ap_iface && info && info->addr) {
5265
    hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
5266
    return;
5267
  }
5268
5269
  if (wpa_s->ap_iface) {
5270
    wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
5271
    return;
5272
  }
5273
#endif /* CONFIG_AP */
5274
5275
#ifdef CONFIG_P2P
5276
  if (info) {
5277
    wpas_p2p_disassoc_notif(
5278
      wpa_s, info->addr, reason_code, info->ie, info->ie_len,
5279
      locally_generated);
5280
  }
5281
#endif /* CONFIG_P2P */
5282
5283
0
  if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5284
0
    sme_event_disassoc(wpa_s, info);
5285
5286
0
  wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
5287
0
            ie, ie_len, 0);
5288
0
}
5289
5290
5291
static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
5292
            struct deauth_info *info)
5293
0
{
5294
0
  u16 reason_code = 0;
5295
0
  int locally_generated = 0;
5296
0
  const u8 *addr = NULL;
5297
0
  const u8 *ie = NULL;
5298
0
  size_t ie_len = 0;
5299
5300
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
5301
5302
0
  if (info) {
5303
0
    addr = info->addr;
5304
0
    ie = info->ie;
5305
0
    ie_len = info->ie_len;
5306
0
    reason_code = info->reason_code;
5307
0
    locally_generated = info->locally_generated;
5308
0
    wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s",
5309
0
      reason_code, reason2str(reason_code),
5310
0
      locally_generated ? " locally_generated=1" : "");
5311
0
    if (addr) {
5312
0
      wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
5313
0
        MAC2STR(addr));
5314
0
    }
5315
0
    wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
5316
0
          ie, ie_len);
5317
0
  }
5318
5319
0
  wpa_reset_ft_completed(wpa_s->wpa);
5320
5321
0
  wpas_event_disconnect(wpa_s, addr, reason_code,
5322
0
            locally_generated, ie, ie_len, 1);
5323
0
}
5324
5325
5326
static const char * reg_init_str(enum reg_change_initiator init)
5327
0
{
5328
0
  switch (init) {
5329
0
  case REGDOM_SET_BY_CORE:
5330
0
    return "CORE";
5331
0
  case REGDOM_SET_BY_USER:
5332
0
    return "USER";
5333
0
  case REGDOM_SET_BY_DRIVER:
5334
0
    return "DRIVER";
5335
0
  case REGDOM_SET_BY_COUNTRY_IE:
5336
0
    return "COUNTRY_IE";
5337
0
  case REGDOM_BEACON_HINT:
5338
0
    return "BEACON_HINT";
5339
0
  }
5340
0
  return "?";
5341
0
}
5342
5343
5344
static const char * reg_type_str(enum reg_type type)
5345
0
{
5346
0
  switch (type) {
5347
0
  case REGDOM_TYPE_UNKNOWN:
5348
0
    return "UNKNOWN";
5349
0
  case REGDOM_TYPE_COUNTRY:
5350
0
    return "COUNTRY";
5351
0
  case REGDOM_TYPE_WORLD:
5352
0
    return "WORLD";
5353
0
  case REGDOM_TYPE_CUSTOM_WORLD:
5354
0
    return "CUSTOM_WORLD";
5355
0
  case REGDOM_TYPE_INTERSECTION:
5356
0
    return "INTERSECTION";
5357
0
  }
5358
0
  return "?";
5359
0
}
5360
5361
5362
static void wpas_beacon_hint(struct wpa_supplicant *wpa_s, const char *title,
5363
           struct frequency_attrs *attrs)
5364
0
{
5365
0
  if (!attrs->freq)
5366
0
    return;
5367
0
  wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_BEACON_HINT
5368
0
    "%s freq=%u max_tx_power=%u%s%s%s",
5369
0
    title, attrs->freq, attrs->max_tx_power,
5370
0
    attrs->disabled ? " disabled=1" : "",
5371
0
    attrs->no_ir ? " no_ir=1" : "",
5372
0
    attrs->radar ? " radar=1" : "");
5373
0
}
5374
5375
5376
void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s,
5377
          struct channel_list_changed *info)
5378
0
{
5379
0
  struct wpa_supplicant *ifs;
5380
0
  u8 dfs_domain;
5381
5382
  /*
5383
   * To allow backwards compatibility with higher level layers that
5384
   * assumed the REGDOM_CHANGE event is sent over the initially added
5385
   * interface. Find the highest parent of this interface and use it to
5386
   * send the event.
5387
   */
5388
0
  for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
5389
0
    ;
5390
5391
0
  if (info) {
5392
0
    wpa_msg(ifs, MSG_INFO,
5393
0
      WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
5394
0
      reg_init_str(info->initiator), reg_type_str(info->type),
5395
0
      info->alpha2[0] ? " alpha2=" : "",
5396
0
      info->alpha2[0] ? info->alpha2 : "");
5397
5398
0
    if (info->initiator == REGDOM_BEACON_HINT) {
5399
0
      wpas_beacon_hint(ifs, "before",
5400
0
           &info->beacon_hint_before);
5401
0
      wpas_beacon_hint(ifs, "after",
5402
0
           &info->beacon_hint_after);
5403
0
    }
5404
0
  }
5405
5406
0
  if (wpa_s->drv_priv == NULL)
5407
0
    return; /* Ignore event during drv initialization */
5408
5409
0
  dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
5410
0
       radio_list) {
5411
0
    bool was_6ghz_enabled;
5412
5413
0
    wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
5414
0
         ifs->ifname);
5415
0
    free_hw_features(ifs);
5416
0
    ifs->hw.modes = wpa_drv_get_hw_feature_data(
5417
0
      ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain);
5418
5419
0
    was_6ghz_enabled = ifs->is_6ghz_enabled;
5420
0
    ifs->is_6ghz_enabled = wpas_is_6ghz_supported(ifs, true);
5421
5422
    /* Restart PNO/sched_scan with updated channel list */
5423
0
    if (ifs->pno) {
5424
0
      wpas_stop_pno(ifs);
5425
0
      wpas_start_pno(ifs);
5426
0
    } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
5427
0
      wpa_dbg(ifs, MSG_DEBUG,
5428
0
        "Channel list changed - restart sched_scan");
5429
0
      wpas_scan_restart_sched_scan(ifs);
5430
0
    } else if (!was_6ghz_enabled && ifs->is_6ghz_enabled) {
5431
0
      wpa_dbg(ifs, MSG_INFO,
5432
0
        "Channel list changed: 6 GHz was enabled");
5433
5434
0
      ifs->crossed_6ghz_dom = true;
5435
0
    }
5436
0
  }
5437
5438
0
  wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
5439
0
}
5440
5441
5442
static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
5443
              const u8 *frame, size_t len, int freq,
5444
              int rssi)
5445
0
{
5446
0
  const struct ieee80211_mgmt *mgmt;
5447
0
  const u8 *payload;
5448
0
  size_t plen;
5449
0
  u8 category;
5450
5451
0
  if (len < IEEE80211_HDRLEN + 2)
5452
0
    return;
5453
5454
0
  mgmt = (const struct ieee80211_mgmt *) frame;
5455
0
  payload = frame + IEEE80211_HDRLEN;
5456
0
  category = *payload++;
5457
0
  plen = len - IEEE80211_HDRLEN - 1;
5458
5459
0
  wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
5460
0
    " Category=%u DataLen=%d freq=%d MHz",
5461
0
    MAC2STR(mgmt->sa), category, (int) plen, freq);
5462
5463
0
#ifndef CONFIG_NO_WMM_AC
5464
0
  if (category == WLAN_ACTION_WMM) {
5465
0
    wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
5466
0
    return;
5467
0
  }
5468
0
#endif /* CONFIG_NO_WMM_AC */
5469
5470
#ifdef CONFIG_IEEE80211R
5471
  if (category == WLAN_ACTION_FT) {
5472
    ft_rx_action(wpa_s, payload, plen);
5473
    return;
5474
  }
5475
#endif /* CONFIG_IEEE80211R */
5476
5477
#ifdef CONFIG_SME
5478
  if (category == WLAN_ACTION_SA_QUERY) {
5479
    sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen);
5480
    return;
5481
  }
5482
#endif /* CONFIG_SME */
5483
5484
0
#ifdef CONFIG_WNM
5485
0
  if (mgmt->u.action.category == WLAN_ACTION_WNM) {
5486
0
    ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
5487
0
    return;
5488
0
  }
5489
0
#endif /* CONFIG_WNM */
5490
5491
0
#ifdef CONFIG_GAS
5492
0
  if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
5493
0
       mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
5494
0
      gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
5495
0
       mgmt->u.action.category,
5496
0
       payload, plen, freq) == 0)
5497
0
    return;
5498
0
#endif /* CONFIG_GAS */
5499
5500
#ifdef CONFIG_GAS_SERVER
5501
  if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
5502
       mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
5503
      gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid,
5504
        mgmt->u.action.category,
5505
        payload, plen, freq) == 0)
5506
    return;
5507
#endif /* CONFIG_GAS_SERVER */
5508
5509
#ifdef CONFIG_TDLS
5510
  if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
5511
      payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
5512
    wpa_dbg(wpa_s, MSG_DEBUG,
5513
      "TDLS: Received Discovery Response from " MACSTR,
5514
      MAC2STR(mgmt->sa));
5515
    if (wpa_s->valid_links &&
5516
        wpa_tdls_process_discovery_response(wpa_s->wpa, mgmt->sa,
5517
              &payload[1], plen - 1))
5518
      wpa_dbg(wpa_s, MSG_ERROR,
5519
        "TDLS: Discovery Response process failed for "
5520
        MACSTR, MAC2STR(mgmt->sa));
5521
    return;
5522
  }
5523
#endif /* CONFIG_TDLS */
5524
5525
0
#ifdef CONFIG_INTERWORKING
5526
0
  if (category == WLAN_ACTION_QOS && plen >= 1 &&
5527
0
      payload[0] == QOS_QOS_MAP_CONFIG) {
5528
0
    const u8 *pos = payload + 1;
5529
0
    size_t qlen = plen - 1;
5530
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
5531
0
      MACSTR, MAC2STR(mgmt->sa));
5532
0
    if (ether_addr_equal(mgmt->sa, wpa_s->bssid) &&
5533
0
        qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
5534
0
        pos[1] <= qlen - 2 && pos[1] >= 16)
5535
0
      wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
5536
0
    return;
5537
0
  }
5538
0
#endif /* CONFIG_INTERWORKING */
5539
5540
0
#ifndef CONFIG_NO_RRM
5541
0
  if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
5542
0
      payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
5543
0
    wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
5544
0
                mgmt->da,
5545
0
                payload + 1,
5546
0
                plen - 1);
5547
0
    return;
5548
0
  }
5549
5550
0
  if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
5551
0
      payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
5552
0
    wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
5553
0
    return;
5554
0
  }
5555
5556
0
  if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
5557
0
      payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
5558
0
    wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
5559
0
               payload + 1, plen - 1,
5560
0
               rssi);
5561
0
    return;
5562
0
  }
5563
0
#endif /* CONFIG_NO_RRM */
5564
5565
#ifdef CONFIG_FST
5566
  if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
5567
    fst_rx_action(wpa_s->fst, mgmt, len);
5568
    return;
5569
  }
5570
#endif /* CONFIG_FST */
5571
5572
#ifdef CONFIG_NAN_USD
5573
  if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
5574
      payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
5575
      WPA_GET_BE32(&payload[1]) == NAN_SDF_VENDOR_TYPE) {
5576
    payload += 5;
5577
    plen -= 5;
5578
    wpas_nan_usd_rx_sdf(wpa_s, mgmt->sa, mgmt->bssid, freq,
5579
            payload, plen);
5580
    return;
5581
  }
5582
#endif /* CONFIG_NAN_USD */
5583
5584
#ifdef CONFIG_DPP
5585
  if (category == WLAN_ACTION_PUBLIC && plen >= 5 &&
5586
      payload[0] == WLAN_PA_VENDOR_SPECIFIC &&
5587
      WPA_GET_BE24(&payload[1]) == OUI_WFA &&
5588
      payload[4] == DPP_OUI_TYPE) {
5589
    payload++;
5590
    plen--;
5591
    wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq);
5592
    return;
5593
  }
5594
#endif /* CONFIG_DPP */
5595
5596
0
#ifndef CONFIG_NO_ROBUST_AV
5597
0
  if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
5598
0
      payload[0] == ROBUST_AV_SCS_RESP) {
5599
0
    wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa,
5600
0
                  payload + 1, plen - 1);
5601
0
    return;
5602
0
  }
5603
5604
0
  if (category == WLAN_ACTION_ROBUST_AV_STREAMING &&
5605
0
      payload[0] == ROBUST_AV_MSCS_RESP) {
5606
0
    wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa,
5607
0
              payload + 1, plen - 1);
5608
0
    return;
5609
0
  }
5610
5611
0
  if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 &&
5612
0
      WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) {
5613
0
    wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa,
5614
0
             payload + 4, plen - 4);
5615
0
    return;
5616
0
  }
5617
0
#endif /* CONFIG_NO_ROBUST_AV */
5618
5619
0
  wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
5620
0
         category, payload, plen, freq);
5621
0
  if (wpa_s->ifmsh)
5622
0
    mesh_mpm_action_rx(wpa_s, mgmt, len);
5623
0
}
5624
5625
5626
static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
5627
               union wpa_event_data *event)
5628
0
{
5629
0
  struct wpa_freq_range_list *list;
5630
0
  char *str = NULL;
5631
5632
0
  list = &event->freq_range;
5633
5634
0
  if (list->num)
5635
0
    str = freq_range_list_str(list);
5636
0
  wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
5637
0
    str ? str : "");
5638
5639
#ifdef CONFIG_P2P
5640
  if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
5641
    wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
5642
      __func__);
5643
  } else {
5644
    wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
5645
5646
    /*
5647
     * The update channel flow will also take care of moving a GO
5648
     * from the unsafe frequency if needed.
5649
     */
5650
    wpas_p2p_update_channel_list(wpa_s,
5651
               WPAS_P2P_CHANNEL_UPDATE_AVOID);
5652
  }
5653
#endif /* CONFIG_P2P */
5654
5655
0
  os_free(str);
5656
0
}
5657
5658
5659
static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s)
5660
0
{
5661
0
  if (wpa_s->wpa_state == WPA_ASSOCIATED) {
5662
0
    wpa_supplicant_cancel_auth_timeout(wpa_s);
5663
0
    wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
5664
0
    eapol_sm_notify_portValid(wpa_s->eapol, true);
5665
0
    eapol_sm_notify_eap_success(wpa_s->eapol, true);
5666
0
    wpa_s->drv_authorized_port = 1;
5667
0
  }
5668
0
}
5669
5670
5671
static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s,
5672
              int freq)
5673
0
{
5674
0
  size_t i;
5675
0
  int j;
5676
5677
0
  for (i = 0; i < wpa_s->hw.num_modes; i++) {
5678
0
    const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i];
5679
5680
0
    for (j = 0; j < mode->num_channels; j++) {
5681
0
      const struct hostapd_channel_data *chan;
5682
5683
0
      chan = &mode->channels[j];
5684
0
      if (chan->freq == freq)
5685
0
        return chan->dfs_cac_ms;
5686
0
    }
5687
0
  }
5688
5689
0
  return 0;
5690
0
}
5691
5692
5693
static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
5694
               struct dfs_event *radar)
5695
0
{
5696
#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
5697
  if (wpa_s->ap_iface || wpa_s->ifmsh) {
5698
    wpas_ap_event_dfs_cac_started(wpa_s, radar);
5699
  } else
5700
#endif /* NEED_AP_MLME && CONFIG_AP */
5701
0
  {
5702
0
    unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq);
5703
5704
0
    cac_time /= 1000; /* convert from ms to sec */
5705
0
    if (!cac_time)
5706
0
      cac_time = 10 * 60; /* max timeout: 10 minutes */
5707
5708
    /* Restart auth timeout: CAC time added to initial timeout */
5709
0
    wpas_auth_timeout_restart(wpa_s, cac_time);
5710
0
  }
5711
0
}
5712
5713
5714
static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
5715
          struct dfs_event *radar)
5716
0
{
5717
#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
5718
  if (wpa_s->ap_iface || wpa_s->ifmsh) {
5719
    wpas_ap_event_dfs_cac_finished(wpa_s, radar);
5720
  } else
5721
#endif /* NEED_AP_MLME && CONFIG_AP */
5722
0
  {
5723
    /* Restart auth timeout with original value after CAC is
5724
     * finished */
5725
0
    wpas_auth_timeout_restart(wpa_s, 0);
5726
0
  }
5727
0
}
5728
5729
5730
static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
5731
               struct dfs_event *radar)
5732
0
{
5733
#if defined(NEED_AP_MLME) && defined(CONFIG_AP)
5734
  if (wpa_s->ap_iface || wpa_s->ifmsh) {
5735
    wpas_ap_event_dfs_cac_aborted(wpa_s, radar);
5736
  } else
5737
#endif /* NEED_AP_MLME && CONFIG_AP */
5738
0
  {
5739
    /* Restart auth timeout with original value after CAC is
5740
     * aborted */
5741
0
    wpas_auth_timeout_restart(wpa_s, 0);
5742
0
  }
5743
0
}
5744
5745
5746
static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
5747
              union wpa_event_data *data)
5748
0
{
5749
0
  wpa_dbg(wpa_s, MSG_DEBUG,
5750
0
    "Connection authorized by device, previous state %d",
5751
0
    wpa_s->wpa_state);
5752
5753
0
  wpa_supplicant_event_port_authorized(wpa_s);
5754
5755
0
  wpa_s->last_eapol_matches_bssid = 1;
5756
5757
0
  wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
5758
0
  wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
5759
0
             data->assoc_info.ptk_kck_len,
5760
0
             data->assoc_info.ptk_kek,
5761
0
             data->assoc_info.ptk_kek_len);
5762
#ifdef CONFIG_FILS
5763
  if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
5764
    struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
5765
    const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss);
5766
5767
    /* Update ERP next sequence number */
5768
    eapol_sm_update_erp_next_seq_num(
5769
      wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num);
5770
5771
    if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) {
5772
      /* Add the new PMK and PMKID to the PMKSA cache */
5773
      wpa_sm_pmksa_cache_add(wpa_s->wpa,
5774
                 data->assoc_info.fils_pmk,
5775
                 data->assoc_info.fils_pmk_len,
5776
                 data->assoc_info.fils_pmkid,
5777
                 wpa_s->valid_links ?
5778
                 wpa_s->ap_mld_addr :
5779
                 wpa_s->bssid,
5780
                 fils_cache_id);
5781
    } else if (data->assoc_info.fils_pmkid) {
5782
      /* Update the current PMKSA used for this connection */
5783
      pmksa_cache_set_current(wpa_s->wpa,
5784
            data->assoc_info.fils_pmkid,
5785
            NULL, NULL, 0, NULL, 0, true);
5786
    }
5787
  }
5788
#endif /* CONFIG_FILS */
5789
0
}
5790
5791
5792
static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code)
5793
0
{
5794
0
  switch (code) {
5795
0
  case STA_CONNECT_FAIL_REASON_UNSPECIFIED:
5796
0
    return "";
5797
0
  case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND:
5798
0
    return "no_bss_found";
5799
0
  case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL:
5800
0
    return "auth_tx_fail";
5801
0
  case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED:
5802
0
    return "auth_no_ack_received";
5803
0
  case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED:
5804
0
    return "auth_no_resp_received";
5805
0
  case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL:
5806
0
    return "assoc_req_tx_fail";
5807
0
  case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED:
5808
0
    return "assoc_no_ack_received";
5809
0
  case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED:
5810
0
    return "assoc_no_resp_received";
5811
0
  default:
5812
0
    return "unknown_reason";
5813
0
  }
5814
0
}
5815
5816
5817
static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s,
5818
            union wpa_event_data *data)
5819
0
{
5820
0
  const u8 *bssid = data->assoc_reject.bssid;
5821
0
  struct ieee802_11_elems elems;
5822
0
  struct ml_sta_link_info ml_info[MAX_NUM_MLD_LINKS];
5823
0
  const u8 *link_bssids[MAX_NUM_MLD_LINKS + 1];
5824
#ifdef CONFIG_MBO
5825
  struct wpa_bss *reject_bss;
5826
#endif /* CONFIG_MBO */
5827
5828
0
  if (!bssid || is_zero_ether_addr(bssid))
5829
0
    bssid = wpa_s->pending_bssid;
5830
#ifdef CONFIG_MBO
5831
  if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
5832
    reject_bss = wpa_s->current_bss;
5833
  else
5834
    reject_bss = wpa_bss_get_bssid(wpa_s, bssid);
5835
#endif /* CONFIG_MBO */
5836
5837
0
  if (data->assoc_reject.bssid)
5838
0
    wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
5839
0
      "bssid=" MACSTR " status_code=%u%s%s%s%s%s",
5840
0
      MAC2STR(data->assoc_reject.bssid),
5841
0
      data->assoc_reject.status_code,
5842
0
      data->assoc_reject.timed_out ? " timeout" : "",
5843
0
      data->assoc_reject.timeout_reason ? "=" : "",
5844
0
      data->assoc_reject.timeout_reason ?
5845
0
      data->assoc_reject.timeout_reason : "",
5846
0
      data->assoc_reject.reason_code !=
5847
0
      STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5848
0
      " qca_driver_reason=" : "",
5849
0
      connect_fail_reason(data->assoc_reject.reason_code));
5850
0
  else
5851
0
    wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
5852
0
      "status_code=%u%s%s%s%s%s",
5853
0
      data->assoc_reject.status_code,
5854
0
      data->assoc_reject.timed_out ? " timeout" : "",
5855
0
      data->assoc_reject.timeout_reason ? "=" : "",
5856
0
      data->assoc_reject.timeout_reason ?
5857
0
      data->assoc_reject.timeout_reason : "",
5858
0
      data->assoc_reject.reason_code !=
5859
0
      STA_CONNECT_FAIL_REASON_UNSPECIFIED ?
5860
0
      " qca_driver_reason=" : "",
5861
0
      connect_fail_reason(data->assoc_reject.reason_code));
5862
0
  wpa_s->assoc_status_code = data->assoc_reject.status_code;
5863
0
  wpas_notify_assoc_status_code(wpa_s);
5864
5865
#ifdef CONFIG_OWE
5866
  if (data->assoc_reject.status_code ==
5867
      WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
5868
      wpa_s->key_mgmt == WPA_KEY_MGMT_OWE &&
5869
      wpa_s->current_ssid &&
5870
      wpa_s->current_ssid->owe_group == 0 &&
5871
      wpa_s->last_owe_group != 21) {
5872
    struct wpa_ssid *ssid = wpa_s->current_ssid;
5873
    struct wpa_bss *bss = wpa_s->current_bss;
5874
5875
    if (!bss) {
5876
      bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5877
      if (!bss) {
5878
        wpas_connection_failed(wpa_s, bssid, NULL);
5879
        wpa_supplicant_mark_disassoc(wpa_s);
5880
        return;
5881
      }
5882
    }
5883
    wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group");
5884
    wpas_connect_work_done(wpa_s);
5885
    wpa_supplicant_mark_disassoc(wpa_s);
5886
    wpa_supplicant_connect(wpa_s, bss, ssid);
5887
    return;
5888
  }
5889
#endif /* CONFIG_OWE */
5890
5891
#ifdef CONFIG_DPP2
5892
  /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is
5893
   * the status code defined in the DPP R2 tech spec.
5894
   * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an
5895
   * interoperability workaround with older hostapd implementation. */
5896
  if (DPP_VERSION > 1 && wpa_s->current_ssid &&
5897
      (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP ||
5898
       ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) &&
5899
        wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) &&
5900
      wpa_s->current_ssid->dpp_pfs == 0 &&
5901
      (data->assoc_reject.status_code ==
5902
       WLAN_STATUS_ASSOC_DENIED_UNSPEC ||
5903
       data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) {
5904
    struct wpa_ssid *ssid = wpa_s->current_ssid;
5905
    struct wpa_bss *bss = wpa_s->current_bss;
5906
5907
    wpa_s->current_ssid->dpp_pfs_fallback ^= 1;
5908
    if (!bss)
5909
      bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
5910
    if (!bss || wpa_s->dpp_pfs_fallback) {
5911
      wpa_printf(MSG_DEBUG,
5912
           "DPP: Updated PFS policy for next try");
5913
      wpas_connection_failed(wpa_s, bssid, NULL);
5914
      wpa_supplicant_mark_disassoc(wpa_s);
5915
      return;
5916
    }
5917
    wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy");
5918
    wpa_s->dpp_pfs_fallback = 1;
5919
    wpas_connect_work_done(wpa_s);
5920
    wpa_supplicant_mark_disassoc(wpa_s);
5921
    wpa_supplicant_connect(wpa_s, bss, ssid);
5922
    return;
5923
  }
5924
#endif /* CONFIG_DPP2 */
5925
5926
#ifdef CONFIG_MBO
5927
  if (data->assoc_reject.status_code ==
5928
      WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
5929
      reject_bss && data->assoc_reject.resp_ies) {
5930
    const u8 *rssi_rej;
5931
5932
    rssi_rej = mbo_get_attr_from_ies(
5933
      data->assoc_reject.resp_ies,
5934
      data->assoc_reject.resp_ies_len,
5935
      OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT);
5936
    if (rssi_rej && rssi_rej[1] == 2) {
5937
      wpa_printf(MSG_DEBUG,
5938
           "OCE: RSSI-based association rejection from "
5939
           MACSTR " (Delta RSSI: %u, Retry Delay: %u)",
5940
           MAC2STR(reject_bss->bssid),
5941
           rssi_rej[2], rssi_rej[3]);
5942
      wpa_bss_tmp_disallow(wpa_s,
5943
               reject_bss->bssid,
5944
               rssi_rej[3],
5945
               rssi_rej[2] + reject_bss->level);
5946
    }
5947
  }
5948
#endif /* CONFIG_MBO */
5949
5950
  /* Check for other failed links in the response */
5951
0
  os_memset(link_bssids, 0, sizeof(link_bssids));
5952
0
  if (ieee802_11_parse_elems(data->assoc_reject.resp_ies,
5953
0
           data->assoc_reject.resp_ies_len,
5954
0
           &elems, 1) != ParseFailed) {
5955
0
    unsigned int n_links, i, idx;
5956
5957
0
    idx = 0;
5958
0
    n_links = wpas_ml_parse_assoc(wpa_s, &elems, ml_info);
5959
5960
0
    for (i = 1; i < n_links; i++) {
5961
      /* The status cannot be success here.
5962
       * Add the link to the failed list if it is reporting
5963
       * an error. The only valid "non-error" status is
5964
       * TX_LINK_NOT_ACCEPTED as that means this link may
5965
       * still accept an association from us.
5966
       */
5967
0
      if (ml_info[i].status !=
5968
0
          WLAN_STATUS_DENIED_TX_LINK_NOT_ACCEPTED) {
5969
0
        link_bssids[idx] = ml_info[i].bssid;
5970
0
        idx++;
5971
0
      }
5972
0
    }
5973
0
  }
5974
5975
0
  if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
5976
0
    sme_event_assoc_reject(wpa_s, data, link_bssids);
5977
0
    return;
5978
0
  }
5979
5980
  /* Driver-based SME cases */
5981
5982
#ifdef CONFIG_SAE
5983
  if (wpa_s->current_ssid &&
5984
      wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) &&
5985
      !data->assoc_reject.timed_out) {
5986
    wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry");
5987
    wpa_sm_aborted_cached(wpa_s->wpa);
5988
    wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5989
  }
5990
#endif /* CONFIG_SAE */
5991
5992
#ifdef CONFIG_DPP
5993
  if (wpa_s->current_ssid &&
5994
      wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP &&
5995
      !data->assoc_reject.timed_out) {
5996
    wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry");
5997
    wpa_sm_aborted_cached(wpa_s->wpa);
5998
    wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid);
5999
  }
6000
#endif /* CONFIG_DPP */
6001
6002
#ifdef CONFIG_FILS
6003
  /* Update ERP next sequence number */
6004
  if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) {
6005
    fils_pmksa_cache_flush(wpa_s);
6006
    eapol_sm_update_erp_next_seq_num(
6007
      wpa_s->eapol,
6008
      data->assoc_reject.fils_erp_next_seq_num);
6009
    fils_connection_failure(wpa_s);
6010
  }
6011
#endif /* CONFIG_FILS */
6012
6013
0
  wpas_connection_failed(wpa_s, bssid, link_bssids);
6014
0
  wpa_supplicant_mark_disassoc(wpa_s);
6015
0
}
6016
6017
6018
static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s,
6019
             struct unprot_beacon *data)
6020
0
{
6021
0
  struct wpabuf *buf;
6022
0
  int res;
6023
6024
0
  if (!data || wpa_s->wpa_state != WPA_COMPLETED ||
6025
0
      !ether_addr_equal(data->sa, wpa_s->bssid))
6026
0
    return;
6027
0
  wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR,
6028
0
    MAC2STR(data->sa));
6029
6030
0
  buf = wpabuf_alloc(4);
6031
0
  if (!buf)
6032
0
    return;
6033
6034
0
  wpabuf_put_u8(buf, WLAN_ACTION_WNM);
6035
0
  wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
6036
0
  wpabuf_put_u8(buf, 1); /* Dialog Token */
6037
0
  wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE);
6038
6039
0
  res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
6040
0
          wpa_s->own_addr, wpa_s->bssid,
6041
0
          wpabuf_head(buf), wpabuf_len(buf), 0);
6042
0
  if (res < 0)
6043
0
    wpa_printf(MSG_DEBUG,
6044
0
         "Failed to send WNM-Notification Request frame");
6045
6046
0
  wpabuf_free(buf);
6047
0
}
6048
6049
6050
static const char * bitmap_to_str(u8 value, char *buf)
6051
0
{
6052
0
  char *pos = buf;
6053
0
  int i, k = 0;
6054
6055
0
  for (i = 7; i >= 0; i--)
6056
0
    pos[k++] = (value & BIT(i)) ? '1' : '0';
6057
6058
0
  pos[8] = '\0';
6059
0
  return pos;
6060
0
}
6061
6062
6063
static void wpas_tid_link_map(struct wpa_supplicant *wpa_s,
6064
            struct tid_link_map_info *info)
6065
0
{
6066
0
  char map_info[1000], *pos, *end;
6067
0
  int res, i;
6068
6069
0
  pos = map_info;
6070
0
  end = pos + sizeof(map_info);
6071
0
  res = os_snprintf(map_info, sizeof(map_info), "default=%d",
6072
0
        info->default_map);
6073
0
  if (os_snprintf_error(end - pos, res))
6074
0
    return;
6075
0
  pos += res;
6076
6077
0
  if (!info->default_map) {
6078
0
    for_each_link(info->valid_links, i) {
6079
0
      char uplink_map_str[9];
6080
0
      char downlink_map_str[9];
6081
6082
0
      bitmap_to_str(info->t2lmap[i].uplink, uplink_map_str);
6083
0
      bitmap_to_str(info->t2lmap[i].downlink,
6084
0
              downlink_map_str);
6085
6086
0
      res = os_snprintf(pos, end - pos,
6087
0
            " link_id=%d up_link=%s down_link=%s",
6088
0
            i, uplink_map_str,
6089
0
            downlink_map_str);
6090
0
      if (os_snprintf_error(end - pos, res))
6091
0
        return;
6092
0
      pos += res;
6093
0
    }
6094
0
  }
6095
6096
0
  wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_T2LM_UPDATE "%s", map_info);
6097
0
}
6098
6099
6100
static void wpas_setup_link_reconfig(struct wpa_supplicant *wpa_s,
6101
             struct reconfig_info *info)
6102
0
{
6103
0
  const u8 *key_data = info->resp_ie;
6104
0
  size_t key_data_len = 0;
6105
0
  const u8 *ies, *end;
6106
0
  bool success = false;
6107
0
  int i;
6108
6109
0
  if (!info->added_links) {
6110
0
    wpa_printf(MSG_INFO, "No links to be added");
6111
0
    return;
6112
0
  }
6113
6114
0
  if (wpa_drv_get_mlo_info(wpa_s) < 0) {
6115
0
    wpa_printf(MSG_INFO,
6116
0
         "SETUP_LINK_RECONFIG: Failed to set reconfig info to wpa_s");
6117
0
    return;
6118
0
  }
6119
6120
0
  if (wpa_sm_set_ml_info(wpa_s)) {
6121
0
    wpa_printf(MSG_ERROR,
6122
0
         "SETUP_LINK_RECONFIG: Failed to set reconfig info to wpa_sm");
6123
0
    return;
6124
0
  }
6125
6126
0
  wpa_hexdump(MSG_DEBUG, "MLD: Reconfiguration Status List",
6127
0
        info->status_list, info->count * 3);
6128
0
  for (i = 0; i < info->count; i++) {
6129
0
    if (WPA_GET_LE16(info->status_list + i * 3 + 1) ==
6130
0
        WLAN_STATUS_SUCCESS)
6131
0
      success = true;
6132
0
  }
6133
6134
0
  if (!key_data || info->resp_ie_len == 0)
6135
0
    return;
6136
6137
0
  if (success) {
6138
    /* Starting with Group Key Data subfield, Key Data Length
6139
     * field */
6140
0
    if (info->resp_ie_len < 1U + key_data[0]) {
6141
0
      wpa_printf(MSG_INFO,
6142
0
           "MLD: Invalid keys in the link setup response");
6143
0
      return;
6144
0
    }
6145
6146
0
    key_data_len = key_data[0];
6147
0
    key_data++;
6148
0
    wpa_hexdump_key(MSG_DEBUG,
6149
0
        "MLD: Link reconfig resp - Group Key Data",
6150
0
        key_data, key_data_len);
6151
6152
0
    if (wpa_sm_install_mlo_group_keys(wpa_s->wpa, key_data,
6153
0
              key_data_len,
6154
0
              info->added_links)) {
6155
0
      wpa_printf(MSG_ERROR,
6156
0
           "SETUP_LINK_RECONFIG: Failed to install group keys for added links");
6157
0
      return;
6158
0
    }
6159
0
  }
6160
6161
0
  ies = key_data + key_data_len;
6162
0
  end = info->resp_ie + info->resp_ie_len;
6163
0
  wpa_hexdump(MSG_DEBUG, "MLD: Link reconfig resp - IEs", ies, end - ies);
6164
6165
0
  wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_LINK_RECONFIG "valid_links=0x%x",
6166
0
    wpa_s->valid_links);
6167
0
}
6168
6169
6170
static void wpas_link_reconfig(struct wpa_supplicant *wpa_s)
6171
0
{
6172
0
  u8 bssid[ETH_ALEN];
6173
6174
0
  if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
6175
0
    wpa_printf(MSG_ERROR, "LINK_RECONFIG: Failed to get BSSID");
6176
0
    wpa_supplicant_deauthenticate(wpa_s,
6177
0
                WLAN_REASON_DEAUTH_LEAVING);
6178
0
    return;
6179
0
  }
6180
6181
0
  if (!ether_addr_equal(bssid, wpa_s->bssid)) {
6182
0
    os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
6183
0
    wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid);
6184
0
    wpas_notify_bssid_changed(wpa_s);
6185
0
  }
6186
6187
0
  if (wpa_drv_get_mlo_info(wpa_s) < 0) {
6188
0
    wpa_printf(MSG_ERROR,
6189
0
         "LINK_RECONFIG: Failed to get MLO connection info");
6190
0
    wpa_supplicant_deauthenticate(wpa_s,
6191
0
                WLAN_REASON_DEAUTH_LEAVING);
6192
0
    return;
6193
0
  }
6194
6195
0
  if (wpa_sm_set_ml_info(wpa_s)) {
6196
0
    wpa_printf(MSG_ERROR,
6197
0
         "LINK_RECONFIG: Failed to set MLO connection info to wpa_sm");
6198
0
    wpa_supplicant_deauthenticate(wpa_s,
6199
0
                WLAN_REASON_DEAUTH_LEAVING);
6200
0
    return;
6201
0
  }
6202
6203
0
  wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_LINK_RECONFIG "valid_links=0x%x",
6204
0
    wpa_s->valid_links);
6205
0
}
6206
6207
6208
#ifdef CONFIG_PASN
6209
static int wpas_pasn_auth(struct wpa_supplicant *wpa_s,
6210
        const struct ieee80211_mgmt *mgmt, size_t len,
6211
        int freq)
6212
{
6213
  struct ieee802_11_elems elems;
6214
  size_t auth_length;
6215
6216
  auth_length = IEEE80211_HDRLEN + sizeof(mgmt->u.auth);
6217
6218
  if (len < auth_length) {
6219
    wpa_printf(MSG_DEBUG, "PASN: Too short Authentication frame");
6220
    return -2;
6221
  }
6222
6223
  if (le_to_host16(mgmt->u.auth.auth_alg) != WLAN_AUTH_PASN) {
6224
    wpa_printf(MSG_DEBUG,
6225
         "PASN: Not a PASN Authentication frame, skip frame parsing");
6226
    return -2;
6227
  }
6228
6229
  if (ieee802_11_parse_elems(mgmt->u.auth.variable,
6230
           len - offsetof(struct ieee80211_mgmt,
6231
              u.auth.variable),
6232
           &elems, 1) == ParseFailed) {
6233
    wpa_printf(MSG_DEBUG,
6234
         "PASN: Failed parsing Authentication frame");
6235
    return -2;
6236
  }
6237
6238
#ifdef CONFIG_P2P
6239
  if (elems.p2p2_ie && elems.p2p2_ie_len)
6240
    return wpas_p2p_pasn_auth_rx(wpa_s, mgmt, len, freq);
6241
#endif /* CONFIG_P2P */
6242
#ifdef CONFIG_PR
6243
  if (elems.proximity_ranging && elems.proximity_ranging_len)
6244
    return wpas_pr_pasn_auth_rx(wpa_s, mgmt, len, freq);
6245
#endif /* CONFIG_PR */
6246
6247
  return wpas_pasn_auth_rx(wpa_s, mgmt, len);
6248
}
6249
#endif /* CONFIG_PASN */
6250
6251
6252
void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
6253
        union wpa_event_data *data)
6254
0
{
6255
0
  struct wpa_supplicant *wpa_s = ctx;
6256
0
  int resched;
6257
0
  struct os_reltime age, clear_at;
6258
0
#ifndef CONFIG_NO_STDOUT_DEBUG
6259
0
  int level = MSG_DEBUG;
6260
0
#endif /* CONFIG_NO_STDOUT_DEBUG */
6261
6262
0
  if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
6263
0
      event != EVENT_INTERFACE_ENABLED &&
6264
0
      event != EVENT_INTERFACE_STATUS &&
6265
0
      event != EVENT_SCAN_RESULTS &&
6266
0
      event != EVENT_SCHED_SCAN_STOPPED) {
6267
0
    wpa_dbg(wpa_s, MSG_DEBUG,
6268
0
      "Ignore event %s (%d) while interface is disabled",
6269
0
      event_to_string(event), event);
6270
0
    return;
6271
0
  }
6272
6273
0
#ifndef CONFIG_NO_STDOUT_DEBUG
6274
0
  if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
6275
0
    const struct ieee80211_hdr *hdr;
6276
0
    u16 fc;
6277
0
    hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
6278
0
    fc = le_to_host16(hdr->frame_control);
6279
0
    if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
6280
0
        WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
6281
0
      level = MSG_EXCESSIVE;
6282
0
  }
6283
6284
0
  wpa_dbg(wpa_s, level, "Event %s (%d) received",
6285
0
    event_to_string(event), event);
6286
0
#endif /* CONFIG_NO_STDOUT_DEBUG */
6287
6288
0
  switch (event) {
6289
0
  case EVENT_AUTH:
6290
#ifdef CONFIG_FST
6291
    if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
6292
            data->auth.ies_len))
6293
      wpa_printf(MSG_DEBUG,
6294
           "FST: MB IEs updated from auth IE");
6295
#endif /* CONFIG_FST */
6296
0
    sme_event_auth(wpa_s, data);
6297
0
    wpa_s->auth_status_code = data->auth.status_code;
6298
0
    wpas_notify_auth_status_code(wpa_s);
6299
0
    break;
6300
0
  case EVENT_ASSOC:
6301
#ifdef CONFIG_TESTING_OPTIONS
6302
    if (wpa_s->ignore_auth_resp) {
6303
      wpa_printf(MSG_INFO,
6304
           "EVENT_ASSOC - ignore_auth_resp active!");
6305
      break;
6306
    }
6307
    if (wpa_s->testing_resend_assoc) {
6308
      wpa_printf(MSG_INFO,
6309
           "EVENT_DEAUTH - testing_resend_assoc");
6310
      break;
6311
    }
6312
#endif /* CONFIG_TESTING_OPTIONS */
6313
0
    if (wpa_s->disconnected) {
6314
0
      wpa_printf(MSG_INFO,
6315
0
           "Ignore unexpected EVENT_ASSOC in disconnected state");
6316
0
      break;
6317
0
    }
6318
0
#ifndef CONFIG_NO_ROBUST_AV
6319
0
    if (dl_list_len(&wpa_s->active_scs_ids) > 0) {
6320
0
      wpa_printf(MSG_DEBUG,
6321
0
           "SCS rules renegotiation required after roaming");
6322
0
      wpa_s->scs_reconfigure = true;
6323
0
    }
6324
0
#endif /* CONFIG_NO_ROBUST_AV */
6325
0
    wpa_supplicant_event_assoc(wpa_s, data);
6326
0
    wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS;
6327
0
    if (data &&
6328
0
        (data->assoc_info.authorized ||
6329
0
         (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
6330
0
          wpa_fils_is_completed(wpa_s->wpa))))
6331
0
      wpa_supplicant_event_assoc_auth(wpa_s, data);
6332
0
    if (data) {
6333
0
      wpa_msg(wpa_s, MSG_INFO,
6334
0
        WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
6335
0
        data->assoc_info.subnet_status);
6336
0
    }
6337
0
    break;
6338
0
  case EVENT_DISASSOC:
6339
0
    wpas_event_disassoc(wpa_s,
6340
0
            data ? &data->disassoc_info : NULL);
6341
0
    break;
6342
0
  case EVENT_DEAUTH:
6343
#ifdef CONFIG_TESTING_OPTIONS
6344
    if (wpa_s->ignore_auth_resp) {
6345
      wpa_printf(MSG_INFO,
6346
           "EVENT_DEAUTH - ignore_auth_resp active!");
6347
      break;
6348
    }
6349
    if (wpa_s->testing_resend_assoc) {
6350
      wpa_printf(MSG_INFO,
6351
           "EVENT_DEAUTH - testing_resend_assoc");
6352
      break;
6353
    }
6354
#endif /* CONFIG_TESTING_OPTIONS */
6355
0
    wpas_event_deauth(wpa_s,
6356
0
          data ? &data->deauth_info : NULL);
6357
0
    break;
6358
0
  case EVENT_LINK_RECONFIG:
6359
0
    wpas_link_reconfig(wpa_s);
6360
0
    break;
6361
0
  case EVENT_MICHAEL_MIC_FAILURE:
6362
0
    wpa_supplicant_event_michael_mic_failure(wpa_s, data);
6363
0
    break;
6364
0
#ifndef CONFIG_NO_SCAN_PROCESSING
6365
0
  case EVENT_SCAN_STARTED:
6366
0
    if (wpa_s->own_scan_requested ||
6367
0
        (data && !data->scan_info.external_scan)) {
6368
0
      struct os_reltime diff;
6369
6370
0
      os_get_reltime(&wpa_s->scan_start_time);
6371
0
      os_reltime_sub(&wpa_s->scan_start_time,
6372
0
               &wpa_s->scan_trigger_time, &diff);
6373
0
      wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
6374
0
        diff.sec, diff.usec);
6375
0
      wpa_s->own_scan_requested = 0;
6376
0
      wpa_s->own_scan_running = 1;
6377
0
      if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
6378
0
          wpa_s->manual_scan_use_id) {
6379
0
        wpa_msg_ctrl(wpa_s, MSG_INFO,
6380
0
               WPA_EVENT_SCAN_STARTED "id=%u",
6381
0
               wpa_s->manual_scan_id);
6382
0
      } else {
6383
0
        wpa_msg_ctrl(wpa_s, MSG_INFO,
6384
0
               WPA_EVENT_SCAN_STARTED);
6385
0
      }
6386
0
    } else {
6387
0
      wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
6388
0
      wpa_s->radio->external_scan_req_interface = wpa_s;
6389
0
      wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
6390
0
    }
6391
0
    break;
6392
0
  case EVENT_SCAN_RESULTS:
6393
0
    if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6394
0
      wpa_s->scan_res_handler = NULL;
6395
0
      wpa_s->own_scan_running = 0;
6396
0
      wpa_s->radio->external_scan_req_interface = NULL;
6397
0
      wpa_s->last_scan_req = NORMAL_SCAN_REQ;
6398
0
      break;
6399
0
    }
6400
6401
0
    if (!(data && data->scan_info.external_scan) &&
6402
0
        os_reltime_initialized(&wpa_s->scan_start_time)) {
6403
0
      struct os_reltime now, diff;
6404
0
      os_get_reltime(&now);
6405
0
      os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
6406
0
      wpa_s->scan_start_time.sec = 0;
6407
0
      wpa_s->scan_start_time.usec = 0;
6408
0
      wpa_s->wps_scan_done = true;
6409
0
      wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
6410
0
        diff.sec, diff.usec);
6411
0
    }
6412
0
    if (wpa_supplicant_event_scan_results(wpa_s, data))
6413
0
      break; /* interface may have been removed */
6414
0
    if (!(data && data->scan_info.external_scan))
6415
0
      wpa_s->own_scan_running = 0;
6416
0
    if (data && data->scan_info.nl_scan_event)
6417
0
      wpa_s->radio->external_scan_req_interface = NULL;
6418
0
    radio_work_check_next(wpa_s);
6419
0
    break;
6420
0
#endif /* CONFIG_NO_SCAN_PROCESSING */
6421
0
  case EVENT_ASSOCINFO:
6422
0
    wpa_supplicant_event_associnfo(wpa_s, data);
6423
0
    break;
6424
0
  case EVENT_INTERFACE_STATUS:
6425
0
    wpa_supplicant_event_interface_status(wpa_s, data);
6426
0
    break;
6427
0
  case EVENT_PMKID_CANDIDATE:
6428
0
    wpa_supplicant_event_pmkid_candidate(wpa_s, data);
6429
0
    break;
6430
#ifdef CONFIG_TDLS
6431
  case EVENT_TDLS:
6432
    wpa_supplicant_event_tdls(wpa_s, data);
6433
    break;
6434
#endif /* CONFIG_TDLS */
6435
0
#ifdef CONFIG_WNM
6436
0
  case EVENT_WNM:
6437
0
    wpa_supplicant_event_wnm(wpa_s, data);
6438
0
    break;
6439
0
#endif /* CONFIG_WNM */
6440
#ifdef CONFIG_IEEE80211R
6441
  case EVENT_FT_RESPONSE:
6442
    wpa_supplicant_event_ft_response(wpa_s, data);
6443
    break;
6444
#endif /* CONFIG_IEEE80211R */
6445
#ifdef CONFIG_IBSS_RSN
6446
  case EVENT_IBSS_RSN_START:
6447
    wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
6448
    break;
6449
#endif /* CONFIG_IBSS_RSN */
6450
0
  case EVENT_ASSOC_REJECT:
6451
0
    wpas_event_assoc_reject(wpa_s, data);
6452
0
    break;
6453
0
  case EVENT_AUTH_TIMED_OUT:
6454
    /* It is possible to get this event from earlier connection */
6455
0
    if (wpa_s->current_ssid &&
6456
0
        wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
6457
0
      wpa_dbg(wpa_s, MSG_DEBUG,
6458
0
        "Ignore AUTH_TIMED_OUT in mesh configuration");
6459
0
      break;
6460
0
    }
6461
0
    if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6462
0
      sme_event_auth_timed_out(wpa_s, data);
6463
0
    break;
6464
0
  case EVENT_ASSOC_TIMED_OUT:
6465
    /* It is possible to get this event from earlier connection */
6466
0
    if (wpa_s->current_ssid &&
6467
0
        wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
6468
0
      wpa_dbg(wpa_s, MSG_DEBUG,
6469
0
        "Ignore ASSOC_TIMED_OUT in mesh configuration");
6470
0
      break;
6471
0
    }
6472
0
    if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6473
0
      sme_event_assoc_timed_out(wpa_s, data);
6474
0
    break;
6475
0
  case EVENT_TX_STATUS:
6476
0
    wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
6477
0
      " type=%d stype=%d",
6478
0
      MAC2STR(data->tx_status.dst),
6479
0
      data->tx_status.type, data->tx_status.stype);
6480
0
#ifdef CONFIG_WNM
6481
0
    if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6482
0
        data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
6483
0
        wnm_btm_resp_tx_status(wpa_s, data->tx_status.data,
6484
0
             data->tx_status.data_len) == 0)
6485
0
      break;
6486
0
#endif /* CONFIG_WNM */
6487
#ifdef CONFIG_PASN
6488
#ifdef CONFIG_P2P
6489
    if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6490
        data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
6491
        !wpa_s->pasn_auth_work &&
6492
        wpa_s->p2p_pasn_auth_work &&
6493
        wpas_p2p_pasn_auth_tx_status(wpa_s,
6494
             data->tx_status.data,
6495
             data->tx_status.data_len,
6496
             data->tx_status.ack) == 0)
6497
      break;
6498
#endif /* CONFIG_P2P */
6499
#ifdef CONFIG_PR
6500
    if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6501
        data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
6502
        !wpa_s->pasn_auth_work &&
6503
        wpa_s->pr_pasn_auth_work &&
6504
        wpas_pr_pasn_auth_tx_status(wpa_s,
6505
            data->tx_status.data,
6506
            data->tx_status.data_len,
6507
            data->tx_status.ack) == 0)
6508
      break;
6509
#endif /* CONFIG_PR */
6510
    if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6511
        data->tx_status.stype == WLAN_FC_STYPE_AUTH &&
6512
        wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data,
6513
               data->tx_status.data_len,
6514
               data->tx_status.ack) == 0)
6515
      break;
6516
#endif /* CONFIG_PASN */
6517
#ifdef CONFIG_AP
6518
    if (wpa_s->ap_iface == NULL) {
6519
#ifdef CONFIG_OFFCHANNEL
6520
      if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6521
          data->tx_status.stype == WLAN_FC_STYPE_ACTION)
6522
        offchannel_send_action_tx_status(
6523
          wpa_s, data->tx_status.dst,
6524
          data->tx_status.data,
6525
          data->tx_status.data_len,
6526
          data->tx_status.ack ?
6527
          OFFCHANNEL_SEND_ACTION_SUCCESS :
6528
          OFFCHANNEL_SEND_ACTION_NO_ACK);
6529
#endif /* CONFIG_OFFCHANNEL */
6530
      break;
6531
    }
6532
#endif /* CONFIG_AP */
6533
#ifdef CONFIG_OFFCHANNEL
6534
    wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
6535
      MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
6536
    /*
6537
     * Catch TX status events for Action frames we sent via group
6538
     * interface in GO mode, or via standalone AP interface.
6539
     * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
6540
     * except when the primary interface is used as a GO interface
6541
     * (for drivers which do not have group interface concurrency)
6542
     */
6543
    if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
6544
        data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
6545
        ether_addr_equal(wpa_s->p2pdev->pending_action_dst,
6546
             data->tx_status.dst)) {
6547
      offchannel_send_action_tx_status(
6548
        wpa_s->p2pdev, data->tx_status.dst,
6549
        data->tx_status.data,
6550
        data->tx_status.data_len,
6551
        data->tx_status.ack ?
6552
        OFFCHANNEL_SEND_ACTION_SUCCESS :
6553
        OFFCHANNEL_SEND_ACTION_NO_ACK);
6554
      break;
6555
    }
6556
#endif /* CONFIG_OFFCHANNEL */
6557
#ifdef CONFIG_AP
6558
    switch (data->tx_status.type) {
6559
    case WLAN_FC_TYPE_MGMT:
6560
      ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
6561
              data->tx_status.data_len,
6562
              data->tx_status.stype,
6563
              data->tx_status.ack);
6564
      break;
6565
    case WLAN_FC_TYPE_DATA:
6566
      ap_tx_status(wpa_s, data->tx_status.dst,
6567
             data->tx_status.data,
6568
             data->tx_status.data_len,
6569
             data->tx_status.ack);
6570
      break;
6571
    }
6572
#endif /* CONFIG_AP */
6573
0
    break;
6574
#ifdef CONFIG_AP
6575
  case EVENT_EAPOL_TX_STATUS:
6576
    ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
6577
           data->eapol_tx_status.data,
6578
           data->eapol_tx_status.data_len,
6579
           data->eapol_tx_status.ack);
6580
    break;
6581
  case EVENT_DRIVER_CLIENT_POLL_OK:
6582
    ap_client_poll_ok(wpa_s, data->client_poll.addr);
6583
    break;
6584
  case EVENT_RX_FROM_UNKNOWN:
6585
    if (wpa_s->ap_iface == NULL)
6586
      break;
6587
    ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
6588
               data->rx_from_unknown.wds);
6589
    break;
6590
#endif /* CONFIG_AP */
6591
6592
0
  case EVENT_LINK_CH_SWITCH_STARTED:
6593
0
  case EVENT_LINK_CH_SWITCH:
6594
0
    if (!data || !wpa_s->current_ssid ||
6595
0
        !(wpa_s->valid_links & BIT(data->ch_switch.link_id)))
6596
0
      break;
6597
6598
0
    wpa_msg(wpa_s, MSG_INFO,
6599
0
      "%sfreq=%d link_id=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
6600
0
      event == EVENT_LINK_CH_SWITCH ?
6601
0
      WPA_EVENT_LINK_CHANNEL_SWITCH :
6602
0
      WPA_EVENT_LINK_CHANNEL_SWITCH_STARTED,
6603
0
      data->ch_switch.freq,
6604
0
      data->ch_switch.link_id,
6605
0
      data->ch_switch.ht_enabled,
6606
0
      data->ch_switch.ch_offset,
6607
0
      channel_width_to_string(data->ch_switch.ch_width),
6608
0
      data->ch_switch.cf1,
6609
0
      data->ch_switch.cf2);
6610
0
    if (event == EVENT_LINK_CH_SWITCH_STARTED)
6611
0
      break;
6612
6613
0
    wpa_s->links[data->ch_switch.link_id].freq =
6614
0
      data->ch_switch.freq;
6615
0
    if (wpa_s->links[data->ch_switch.link_id].bss &&
6616
0
        wpa_s->links[data->ch_switch.link_id].bss->freq !=
6617
0
        data->ch_switch.freq) {
6618
0
      wpa_s->links[data->ch_switch.link_id].bss->freq =
6619
0
        data->ch_switch.freq;
6620
0
      notify_bss_changes(
6621
0
        wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
6622
0
        wpa_s->links[data->ch_switch.link_id].bss);
6623
0
    }
6624
0
    break;
6625
0
  case EVENT_CH_SWITCH_STARTED:
6626
0
  case EVENT_CH_SWITCH:
6627
0
    if (!data || !wpa_s->current_ssid)
6628
0
      break;
6629
6630
0
    wpa_msg(wpa_s, MSG_INFO,
6631
0
      "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
6632
0
      event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH :
6633
0
      WPA_EVENT_CHANNEL_SWITCH_STARTED,
6634
0
      data->ch_switch.freq,
6635
0
      data->ch_switch.ht_enabled,
6636
0
      data->ch_switch.ch_offset,
6637
0
      channel_width_to_string(data->ch_switch.ch_width),
6638
0
      data->ch_switch.cf1,
6639
0
      data->ch_switch.cf2);
6640
0
    if (event == EVENT_CH_SWITCH_STARTED)
6641
0
      break;
6642
6643
0
    wpa_s->assoc_freq = data->ch_switch.freq;
6644
0
    wpa_s->current_ssid->frequency = data->ch_switch.freq;
6645
0
    if (wpa_s->current_bss &&
6646
0
        wpa_s->current_bss->freq != data->ch_switch.freq) {
6647
0
      wpa_s->current_bss->freq = data->ch_switch.freq;
6648
0
      notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG,
6649
0
             wpa_s->current_bss);
6650
0
    }
6651
6652
#ifdef CONFIG_SME
6653
    switch (data->ch_switch.ch_offset) {
6654
    case 1:
6655
      wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE;
6656
      break;
6657
    case -1:
6658
      wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW;
6659
      break;
6660
    default:
6661
      wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN;
6662
      break;
6663
    }
6664
#endif /* CONFIG_SME */
6665
6666
#ifdef CONFIG_AP
6667
    if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
6668
        wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
6669
        wpa_s->current_ssid->mode == WPAS_MODE_MESH ||
6670
        wpa_s->current_ssid->mode ==
6671
        WPAS_MODE_P2P_GROUP_FORMATION) {
6672
      wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
6673
            data->ch_switch.ht_enabled,
6674
            data->ch_switch.ch_offset,
6675
            data->ch_switch.ch_width,
6676
            data->ch_switch.cf1,
6677
            data->ch_switch.cf2,
6678
            data->ch_switch.punct_bitmap,
6679
            1);
6680
    }
6681
#endif /* CONFIG_AP */
6682
6683
0
    if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
6684
0
      sme_event_ch_switch(wpa_s);
6685
6686
0
    wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
6687
0
    wnm_clear_coloc_intf_reporting(wpa_s);
6688
0
    break;
6689
#ifdef CONFIG_AP
6690
#ifdef NEED_AP_MLME
6691
  case EVENT_DFS_RADAR_DETECTED:
6692
    if (data)
6693
      wpas_ap_event_dfs_radar_detected(wpa_s,
6694
               &data->dfs_event);
6695
    break;
6696
  case EVENT_DFS_NOP_FINISHED:
6697
    if (data)
6698
      wpas_ap_event_dfs_cac_nop_finished(wpa_s,
6699
                 &data->dfs_event);
6700
    break;
6701
#endif /* NEED_AP_MLME */
6702
#endif /* CONFIG_AP */
6703
0
  case EVENT_DFS_CAC_STARTED:
6704
0
    if (data)
6705
0
      wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
6706
0
    break;
6707
0
  case EVENT_DFS_CAC_FINISHED:
6708
0
    if (data)
6709
0
      wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
6710
0
    break;
6711
0
  case EVENT_DFS_CAC_ABORTED:
6712
0
    if (data)
6713
0
      wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
6714
0
    break;
6715
0
  case EVENT_RX_MGMT: {
6716
0
    u16 fc, stype;
6717
0
    const struct ieee80211_mgmt *mgmt;
6718
6719
#ifdef CONFIG_TESTING_OPTIONS
6720
    if (wpa_s->ext_mgmt_frame_handling) {
6721
      struct rx_mgmt *rx = &data->rx_mgmt;
6722
      size_t hex_len = 2 * rx->frame_len + 1;
6723
      char *hex = os_malloc(hex_len);
6724
      if (hex) {
6725
        wpa_snprintf_hex(hex, hex_len,
6726
             rx->frame, rx->frame_len);
6727
        wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
6728
          rx->freq, rx->datarate, rx->ssi_signal,
6729
          hex);
6730
        os_free(hex);
6731
      }
6732
      break;
6733
    }
6734
#endif /* CONFIG_TESTING_OPTIONS */
6735
6736
0
    mgmt = (const struct ieee80211_mgmt *)
6737
0
      data->rx_mgmt.frame;
6738
0
    fc = le_to_host16(mgmt->frame_control);
6739
0
    stype = WLAN_FC_GET_STYPE(fc);
6740
6741
#ifdef CONFIG_AP
6742
    if (wpa_s->ap_iface == NULL) {
6743
#endif /* CONFIG_AP */
6744
#ifdef CONFIG_P2P
6745
      if (stype == WLAN_FC_STYPE_PROBE_REQ &&
6746
          data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
6747
        const u8 *src = mgmt->sa;
6748
        const u8 *ie;
6749
        size_t ie_len;
6750
6751
        ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6752
        ie_len = data->rx_mgmt.frame_len -
6753
          IEEE80211_HDRLEN;
6754
        wpas_p2p_probe_req_rx(
6755
          wpa_s, src, mgmt->da,
6756
          mgmt->bssid, ie, ie_len,
6757
          data->rx_mgmt.freq,
6758
          data->rx_mgmt.ssi_signal);
6759
        break;
6760
      }
6761
#endif /* CONFIG_P2P */
6762
#ifdef CONFIG_IBSS_RSN
6763
      if (wpa_s->current_ssid &&
6764
          wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
6765
          stype == WLAN_FC_STYPE_AUTH &&
6766
          data->rx_mgmt.frame_len >= 30) {
6767
        wpa_supplicant_event_ibss_auth(wpa_s, data);
6768
        break;
6769
      }
6770
#endif /* CONFIG_IBSS_RSN */
6771
6772
0
      if (stype == WLAN_FC_STYPE_ACTION) {
6773
0
        wpas_event_rx_mgmt_action(
6774
0
          wpa_s, data->rx_mgmt.frame,
6775
0
          data->rx_mgmt.frame_len,
6776
0
          data->rx_mgmt.freq,
6777
0
          data->rx_mgmt.ssi_signal);
6778
0
        break;
6779
0
      }
6780
6781
0
      if (wpa_s->ifmsh) {
6782
0
        mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
6783
0
        break;
6784
0
      }
6785
#ifdef CONFIG_PASN
6786
      if (stype == WLAN_FC_STYPE_AUTH &&
6787
          wpas_pasn_auth(wpa_s, mgmt, data->rx_mgmt.frame_len,
6788
             data->rx_mgmt.freq) != -2)
6789
        break;
6790
#endif /* CONFIG_PASN */
6791
6792
#ifdef CONFIG_SAE
6793
      if (stype == WLAN_FC_STYPE_AUTH &&
6794
          !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
6795
          (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
6796
        sme_external_auth_mgmt_rx(
6797
          wpa_s, data->rx_mgmt.frame,
6798
          data->rx_mgmt.frame_len);
6799
        break;
6800
      }
6801
#endif /* CONFIG_SAE */
6802
0
      wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
6803
0
        "management frame in non-AP mode");
6804
0
      break;
6805
#ifdef CONFIG_AP
6806
    }
6807
6808
    if (stype == WLAN_FC_STYPE_PROBE_REQ &&
6809
        data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
6810
      const u8 *ie;
6811
      size_t ie_len;
6812
6813
      ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
6814
      ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
6815
6816
      wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
6817
           mgmt->bssid, ie, ie_len,
6818
           data->rx_mgmt.ssi_signal);
6819
    }
6820
6821
    ap_mgmt_rx(wpa_s, &data->rx_mgmt);
6822
#endif /* CONFIG_AP */
6823
0
    break;
6824
0
    }
6825
0
  case EVENT_RX_PROBE_REQ:
6826
0
    if (data->rx_probe_req.sa == NULL ||
6827
0
        data->rx_probe_req.ie == NULL)
6828
0
      break;
6829
#ifdef CONFIG_AP
6830
    if (wpa_s->ap_iface) {
6831
      hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
6832
               data->rx_probe_req.sa,
6833
               data->rx_probe_req.da,
6834
               data->rx_probe_req.bssid,
6835
               data->rx_probe_req.ie,
6836
               data->rx_probe_req.ie_len,
6837
               data->rx_probe_req.ssi_signal);
6838
      break;
6839
    }
6840
#endif /* CONFIG_AP */
6841
0
    wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
6842
0
              data->rx_probe_req.da,
6843
0
              data->rx_probe_req.bssid,
6844
0
              data->rx_probe_req.ie,
6845
0
              data->rx_probe_req.ie_len,
6846
0
              0,
6847
0
              data->rx_probe_req.ssi_signal);
6848
0
    break;
6849
0
  case EVENT_REMAIN_ON_CHANNEL:
6850
#ifdef CONFIG_OFFCHANNEL
6851
    offchannel_remain_on_channel_cb(
6852
      wpa_s, data->remain_on_channel.freq,
6853
      data->remain_on_channel.duration);
6854
#endif /* CONFIG_OFFCHANNEL */
6855
0
    wpas_p2p_remain_on_channel_cb(
6856
0
      wpa_s, data->remain_on_channel.freq,
6857
0
      data->remain_on_channel.duration);
6858
#ifdef CONFIG_DPP
6859
    wpas_dpp_remain_on_channel_cb(
6860
      wpa_s, data->remain_on_channel.freq,
6861
      data->remain_on_channel.duration);
6862
#endif /* CONFIG_DPP */
6863
#ifdef CONFIG_NAN_USD
6864
    wpas_nan_usd_remain_on_channel_cb(
6865
      wpa_s, data->remain_on_channel.freq,
6866
      data->remain_on_channel.duration);
6867
#endif /* CONFIG_NAN_USD */
6868
0
    break;
6869
0
  case EVENT_CANCEL_REMAIN_ON_CHANNEL:
6870
#ifdef CONFIG_OFFCHANNEL
6871
    offchannel_cancel_remain_on_channel_cb(
6872
      wpa_s, data->remain_on_channel.freq);
6873
#endif /* CONFIG_OFFCHANNEL */
6874
0
    wpas_p2p_cancel_remain_on_channel_cb(
6875
0
      wpa_s, data->remain_on_channel.freq);
6876
#ifdef CONFIG_DPP
6877
    wpas_dpp_cancel_remain_on_channel_cb(
6878
      wpa_s, data->remain_on_channel.freq);
6879
#endif /* CONFIG_DPP */
6880
#ifdef CONFIG_NAN_USD
6881
    wpas_nan_usd_cancel_remain_on_channel_cb(
6882
      wpa_s, data->remain_on_channel.freq);
6883
#endif /* CONFIG_NAN_USD */
6884
0
    break;
6885
0
  case EVENT_EAPOL_RX:
6886
0
    wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
6887
0
          data->eapol_rx.data,
6888
0
          data->eapol_rx.data_len,
6889
0
          data->eapol_rx.encrypted);
6890
0
    break;
6891
0
  case EVENT_SIGNAL_CHANGE:
6892
0
    wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
6893
0
           "above=%d signal=%d noise=%d txrate=%lu",
6894
0
           data->signal_change.above_threshold,
6895
0
           data->signal_change.data.signal,
6896
0
           data->signal_change.current_noise,
6897
0
           data->signal_change.data.current_tx_rate);
6898
0
    wpa_bss_update_level(wpa_s->current_bss,
6899
0
             data->signal_change.data.signal);
6900
0
    bgscan_notify_signal_change(
6901
0
      wpa_s, data->signal_change.above_threshold,
6902
0
      data->signal_change.data.signal,
6903
0
      data->signal_change.current_noise,
6904
0
      data->signal_change.data.current_tx_rate);
6905
0
    os_memcpy(&wpa_s->last_signal_info, data,
6906
0
        sizeof(struct wpa_signal_info));
6907
0
    wpas_notify_signal_change(wpa_s);
6908
0
    break;
6909
0
  case EVENT_INTERFACE_MAC_CHANGED:
6910
0
    wpa_supplicant_update_mac_addr(wpa_s);
6911
0
    wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6912
0
    break;
6913
0
  case EVENT_INTERFACE_ENABLED:
6914
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
6915
0
    if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6916
0
      u8 addr[ETH_ALEN];
6917
6918
0
      eloop_cancel_timeout(wpas_clear_disabled_interface,
6919
0
               wpa_s, NULL);
6920
0
      os_memcpy(addr, wpa_s->own_addr, ETH_ALEN);
6921
0
      wpa_supplicant_update_mac_addr(wpa_s);
6922
0
      if (!ether_addr_equal(addr, wpa_s->own_addr))
6923
0
        wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6924
0
      else
6925
0
        wpa_sm_pmksa_cache_reconfig(wpa_s->wpa);
6926
0
      wpa_supplicant_set_default_scan_ies(wpa_s);
6927
0
      if (wpa_s->p2p_mgmt) {
6928
0
        wpa_supplicant_set_state(wpa_s,
6929
0
               WPA_DISCONNECTED);
6930
0
        break;
6931
0
      }
6932
6933
#ifdef CONFIG_AP
6934
      if (!wpa_s->ap_iface) {
6935
        wpa_supplicant_set_state(wpa_s,
6936
               WPA_DISCONNECTED);
6937
        wpa_s->scan_req = NORMAL_SCAN_REQ;
6938
        wpa_supplicant_req_scan(wpa_s, 0, 0);
6939
      } else
6940
        wpa_supplicant_set_state(wpa_s,
6941
               WPA_COMPLETED);
6942
#else /* CONFIG_AP */
6943
0
      wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
6944
0
      wpa_supplicant_req_scan(wpa_s, 0, 0);
6945
0
#endif /* CONFIG_AP */
6946
0
    }
6947
0
    break;
6948
0
  case EVENT_INTERFACE_DISABLED:
6949
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
6950
#ifdef CONFIG_P2P
6951
    if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
6952
        (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
6953
         wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
6954
      /*
6955
       * Mark interface disabled if this happens to end up not
6956
       * being removed as a separate P2P group interface.
6957
       */
6958
      wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
6959
      /*
6960
       * The interface was externally disabled. Remove
6961
       * it assuming an external entity will start a
6962
       * new session if needed.
6963
       */
6964
      if (wpa_s->current_ssid &&
6965
          wpa_s->current_ssid->p2p_group)
6966
        wpas_p2p_interface_unavailable(wpa_s);
6967
      else
6968
        wpas_p2p_disconnect(wpa_s);
6969
      /*
6970
       * wpa_s instance may have been freed, so must not use
6971
       * it here anymore.
6972
       */
6973
      break;
6974
    }
6975
    if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
6976
        p2p_in_progress(wpa_s->global->p2p) > 1) {
6977
      /* This radio work will be cancelled, so clear P2P
6978
       * state as well.
6979
       */
6980
      p2p_stop_find(wpa_s->global->p2p);
6981
    }
6982
#endif /* CONFIG_P2P */
6983
6984
0
    if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
6985
      /*
6986
       * Indicate disconnection to keep ctrl_iface events
6987
       * consistent.
6988
       */
6989
0
      wpa_supplicant_event_disassoc(
6990
0
        wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
6991
0
    }
6992
0
    wpa_supplicant_mark_disassoc(wpa_s);
6993
0
    os_reltime_age(&wpa_s->last_scan, &age);
6994
0
    if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) {
6995
0
      clear_at.sec = wpa_s->conf->scan_res_valid_for_connect;
6996
0
      clear_at.usec = 0;
6997
0
    } else {
6998
0
      struct os_reltime tmp;
6999
7000
0
      tmp.sec = wpa_s->conf->scan_res_valid_for_connect;
7001
0
      tmp.usec = 0;
7002
0
      os_reltime_sub(&tmp, &age, &clear_at);
7003
0
    }
7004
0
    eloop_register_timeout(clear_at.sec, clear_at.usec,
7005
0
               wpas_clear_disabled_interface,
7006
0
               wpa_s, NULL);
7007
0
    radio_remove_works(wpa_s, NULL, 0);
7008
7009
0
    wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
7010
0
    break;
7011
0
  case EVENT_CHANNEL_LIST_CHANGED:
7012
0
    wpa_supplicant_update_channel_list(
7013
0
      wpa_s, &data->channel_list_changed);
7014
0
    break;
7015
0
  case EVENT_INTERFACE_UNAVAILABLE:
7016
0
    wpas_p2p_interface_unavailable(wpa_s);
7017
0
    break;
7018
0
  case EVENT_BEST_CHANNEL:
7019
0
    wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
7020
0
      "(%d %d %d)",
7021
0
      data->best_chan.freq_24, data->best_chan.freq_5,
7022
0
      data->best_chan.freq_overall);
7023
0
    wpa_s->best_24_freq = data->best_chan.freq_24;
7024
0
    wpa_s->best_5_freq = data->best_chan.freq_5;
7025
0
    wpa_s->best_overall_freq = data->best_chan.freq_overall;
7026
0
    wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
7027
0
                data->best_chan.freq_5,
7028
0
                data->best_chan.freq_overall);
7029
0
    break;
7030
0
  case EVENT_UNPROT_DEAUTH:
7031
0
    wpa_supplicant_event_unprot_deauth(wpa_s,
7032
0
               &data->unprot_deauth);
7033
0
    break;
7034
0
  case EVENT_UNPROT_DISASSOC:
7035
0
    wpa_supplicant_event_unprot_disassoc(wpa_s,
7036
0
                 &data->unprot_disassoc);
7037
0
    break;
7038
0
  case EVENT_STATION_LOW_ACK:
7039
#ifdef CONFIG_AP
7040
    if (wpa_s->ap_iface && data)
7041
      hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
7042
              data->low_ack.addr);
7043
#endif /* CONFIG_AP */
7044
#ifdef CONFIG_TDLS
7045
    if (data)
7046
      wpa_tdls_disable_unreachable_link(wpa_s->wpa,
7047
                data->low_ack.addr);
7048
#endif /* CONFIG_TDLS */
7049
0
    break;
7050
0
  case EVENT_IBSS_PEER_LOST:
7051
#ifdef CONFIG_IBSS_RSN
7052
    ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
7053
#endif /* CONFIG_IBSS_RSN */
7054
0
    break;
7055
0
  case EVENT_DRIVER_GTK_REKEY:
7056
0
    if (!ether_addr_equal(data->driver_gtk_rekey.bssid,
7057
0
              wpa_s->bssid))
7058
0
      break;
7059
0
    if (!wpa_s->wpa)
7060
0
      break;
7061
0
    wpa_sm_update_replay_ctr(wpa_s->wpa,
7062
0
           data->driver_gtk_rekey.replay_ctr);
7063
0
    break;
7064
0
  case EVENT_SCHED_SCAN_STOPPED:
7065
0
    wpa_s->sched_scanning = 0;
7066
0
    resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
7067
0
    wpa_supplicant_notify_scanning(wpa_s, 0);
7068
7069
0
    if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
7070
0
      break;
7071
7072
    /*
7073
     * If the driver stopped scanning without being requested to,
7074
     * request a new scan to continue scanning for networks.
7075
     */
7076
0
    if (!wpa_s->sched_scan_stop_req &&
7077
0
        wpa_s->wpa_state == WPA_SCANNING) {
7078
0
      wpa_dbg(wpa_s, MSG_DEBUG,
7079
0
        "Restart scanning after unexpected sched_scan stop event");
7080
0
      wpa_supplicant_req_scan(wpa_s, 1, 0);
7081
0
      break;
7082
0
    }
7083
7084
0
    wpa_s->sched_scan_stop_req = 0;
7085
7086
    /*
7087
     * Start a new sched scan to continue searching for more SSIDs
7088
     * either if timed out or PNO schedule scan is pending.
7089
     */
7090
0
    if (wpa_s->sched_scan_timed_out) {
7091
0
      wpa_supplicant_req_sched_scan(wpa_s);
7092
0
    } else if (wpa_s->pno_sched_pending) {
7093
0
      wpa_s->pno_sched_pending = 0;
7094
0
      wpas_start_pno(wpa_s);
7095
0
    } else if (resched) {
7096
0
      wpa_supplicant_req_scan(wpa_s, 0, 0);
7097
0
    }
7098
7099
0
    break;
7100
0
  case EVENT_WPS_BUTTON_PUSHED:
7101
#ifdef CONFIG_WPS
7102
    wpas_wps_start_pbc(wpa_s, NULL, 0, 0);
7103
#endif /* CONFIG_WPS */
7104
0
    break;
7105
0
  case EVENT_AVOID_FREQUENCIES:
7106
0
    wpa_supplicant_notify_avoid_freq(wpa_s, data);
7107
0
    break;
7108
0
  case EVENT_CONNECT_FAILED_REASON:
7109
#ifdef CONFIG_AP
7110
    if (!wpa_s->ap_iface || !data)
7111
      break;
7112
    hostapd_event_connect_failed_reason(
7113
      wpa_s->ap_iface->bss[0],
7114
      data->connect_failed_reason.addr,
7115
      data->connect_failed_reason.code);
7116
#endif /* CONFIG_AP */
7117
0
    break;
7118
0
  case EVENT_NEW_PEER_CANDIDATE:
7119
#ifdef CONFIG_MESH
7120
    if (!wpa_s->ifmsh || !data)
7121
      break;
7122
    wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
7123
             data->mesh_peer.ies,
7124
             data->mesh_peer.ie_len);
7125
#endif /* CONFIG_MESH */
7126
0
    break;
7127
0
  case EVENT_SURVEY:
7128
#ifdef CONFIG_AP
7129
    if (!wpa_s->ap_iface)
7130
      break;
7131
    hostapd_event_get_survey(wpa_s->ap_iface,
7132
           &data->survey_results);
7133
#endif /* CONFIG_AP */
7134
0
    break;
7135
0
  case EVENT_ACS_CHANNEL_SELECTED:
7136
#ifdef CONFIG_AP
7137
#ifdef CONFIG_ACS
7138
    if (!wpa_s->ap_iface)
7139
      break;
7140
    hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
7141
               &data->acs_selected_channels);
7142
#endif /* CONFIG_ACS */
7143
#endif /* CONFIG_AP */
7144
0
    break;
7145
0
  case EVENT_P2P_LO_STOP:
7146
#ifdef CONFIG_P2P
7147
    wpa_s->p2p_lo_started = 0;
7148
    wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
7149
      P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
7150
      data->p2p_lo_stop.reason_code);
7151
#endif /* CONFIG_P2P */
7152
0
    break;
7153
0
  case EVENT_BEACON_LOSS:
7154
0
    if (!wpa_s->current_bss || !wpa_s->current_ssid)
7155
0
      break;
7156
0
    wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
7157
0
    bgscan_notify_beacon_loss(wpa_s);
7158
0
    break;
7159
0
  case EVENT_EXTERNAL_AUTH:
7160
#ifdef CONFIG_SAE
7161
    if (!wpa_s->current_ssid) {
7162
      wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL");
7163
      break;
7164
    }
7165
    sme_external_auth_trigger(wpa_s, data);
7166
#endif /* CONFIG_SAE */
7167
0
    break;
7168
#ifdef CONFIG_PASN
7169
  case EVENT_PASN_AUTH:
7170
    wpas_pasn_auth_trigger(wpa_s, &data->pasn_auth);
7171
    break;
7172
#endif /* CONFIG_PASN */
7173
0
  case EVENT_PORT_AUTHORIZED:
7174
#ifdef CONFIG_AP
7175
    if (wpa_s->ap_iface && wpa_s->ap_iface->bss[0]) {
7176
      struct sta_info *sta;
7177
7178
      sta = ap_get_sta(wpa_s->ap_iface->bss[0],
7179
           data->port_authorized.sta_addr);
7180
      if (sta)
7181
        ap_sta_set_authorized(wpa_s->ap_iface->bss[0],
7182
                  sta, 1);
7183
      else
7184
        wpa_printf(MSG_DEBUG,
7185
             "No STA info matching port authorized event found");
7186
      break;
7187
    }
7188
#endif /* CONFIG_AP */
7189
0
#ifndef CONFIG_NO_WPA
7190
0
    if (data->port_authorized.td_bitmap_len) {
7191
0
      wpa_printf(MSG_DEBUG,
7192
0
           "WPA3: Transition Disable bitmap from the driver event: 0x%x",
7193
0
           data->port_authorized.td_bitmap[0]);
7194
0
      wpas_transition_disable(
7195
0
        wpa_s, data->port_authorized.td_bitmap[0]);
7196
0
    }
7197
0
#endif /* CONFIG_NO_WPA */
7198
0
    wpa_supplicant_event_port_authorized(wpa_s);
7199
0
    break;
7200
0
  case EVENT_STATION_OPMODE_CHANGED:
7201
#ifdef CONFIG_AP
7202
    if (!wpa_s->ap_iface || !data)
7203
      break;
7204
7205
    hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0],
7206
             data->sta_opmode.addr,
7207
             data->sta_opmode.smps_mode,
7208
             data->sta_opmode.chan_width,
7209
             data->sta_opmode.rx_nss);
7210
#endif /* CONFIG_AP */
7211
0
    break;
7212
0
  case EVENT_UNPROT_BEACON:
7213
0
    wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon);
7214
0
    break;
7215
0
  case EVENT_TX_WAIT_EXPIRE:
7216
#ifdef CONFIG_DPP
7217
    wpas_dpp_tx_wait_expire(wpa_s);
7218
#endif /* CONFIG_DPP */
7219
#ifdef CONFIG_NAN_USD
7220
    wpas_nan_usd_tx_wait_expire(wpa_s);
7221
#endif /* CONFIG_NAN_USD */
7222
0
    break;
7223
0
  case EVENT_TID_LINK_MAP:
7224
0
    if (data)
7225
0
      wpas_tid_link_map(wpa_s, &data->t2l_map_info);
7226
0
    break;
7227
0
  case EVENT_SETUP_LINK_RECONFIG:
7228
0
    if (data)
7229
0
      wpas_setup_link_reconfig(wpa_s, &data->reconfig_info);
7230
0
    break;
7231
0
  default:
7232
0
    wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
7233
0
    break;
7234
0
  }
7235
0
}
7236
7237
7238
void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
7239
         union wpa_event_data *data)
7240
0
{
7241
0
  struct wpa_supplicant *wpa_s;
7242
7243
0
  if (event != EVENT_INTERFACE_STATUS)
7244
0
    return;
7245
7246
0
  wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
7247
0
  if (wpa_s && wpa_s->driver->get_ifindex) {
7248
0
    unsigned int ifindex;
7249
7250
0
    ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
7251
0
    if (ifindex != data->interface_status.ifindex) {
7252
0
      wpa_dbg(wpa_s, MSG_DEBUG,
7253
0
        "interface status ifindex %d mismatch (%d)",
7254
0
        ifindex, data->interface_status.ifindex);
7255
0
      return;
7256
0
    }
7257
0
  }
7258
#ifdef CONFIG_MATCH_IFACE
7259
  else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
7260
    struct wpa_interface *wpa_i;
7261
7262
    wpa_i = wpa_supplicant_match_iface(
7263
      ctx, data->interface_status.ifname);
7264
    if (!wpa_i)
7265
      return;
7266
    wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
7267
    os_free(wpa_i);
7268
  }
7269
#endif /* CONFIG_MATCH_IFACE */
7270
7271
0
  if (wpa_s)
7272
0
    wpa_supplicant_event(wpa_s, event, data);
7273
0
}