Coverage Report

Created: 2025-07-18 06:03

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