Coverage Report

Created: 2026-10-16 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hostap/wpa_supplicant/notify.c
Line
Count
Source
1
/*
2
 * wpa_supplicant - Event notifications
3
 * Copyright (c) 2009-2010, 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 "utils/includes.h"
10
11
#include "utils/common.h"
12
#include "common/wpa_ctrl.h"
13
#include "common/nan_de.h"
14
#include "common/proximity_ranging.h"
15
#include "config.h"
16
#include "wpa_supplicant_i.h"
17
#include "wps_supplicant.h"
18
#include "binder/binder.h"
19
#include "dbus/dbus_common.h"
20
#include "dbus/dbus_new.h"
21
#include "rsn_supp/wpa.h"
22
#include "rsn_supp/pmksa_cache.h"
23
#include "fst/fst.h"
24
#include "crypto/tls.h"
25
#include "bss.h"
26
#include "driver_i.h"
27
#include "scan.h"
28
#include "p2p_supplicant.h"
29
#include "sme.h"
30
#include "notify.h"
31
32
int wpas_notify_supplicant_initialized(struct wpa_global *global)
33
0
{
34
#ifdef CONFIG_CTRL_IFACE_DBUS_NEW
35
  if (global->params.dbus_ctrl_interface) {
36
    global->dbus = wpas_dbus_init(global);
37
    if (global->dbus == NULL)
38
      return -1;
39
  }
40
#endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
41
42
#ifdef CONFIG_BINDER
43
  global->binder = wpas_binder_init(global);
44
  if (!global->binder)
45
    return -1;
46
#endif /* CONFIG_BINDER */
47
48
0
  return 0;
49
0
}
50
51
52
void wpas_notify_supplicant_deinitialized(struct wpa_global *global)
53
0
{
54
#ifdef CONFIG_CTRL_IFACE_DBUS_NEW
55
  if (global->dbus)
56
    wpas_dbus_deinit(global->dbus);
57
#endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
58
59
#ifdef CONFIG_BINDER
60
  if (global->binder)
61
    wpas_binder_deinit(global->binder);
62
#endif /* CONFIG_BINDER */
63
0
}
64
65
66
int wpas_notify_iface_added(struct wpa_supplicant *wpa_s)
67
0
{
68
0
  if (wpa_s->p2p_mgmt)
69
0
    return 0;
70
71
0
  if (wpas_dbus_register_interface(wpa_s))
72
0
    return -1;
73
74
0
  return 0;
75
0
}
76
77
78
void wpas_notify_iface_removed(struct wpa_supplicant *wpa_s)
79
0
{
80
0
  if (wpa_s->p2p_mgmt)
81
0
    return;
82
83
  /* unregister interface in new DBus ctrl iface */
84
0
  wpas_dbus_unregister_interface(wpa_s);
85
0
}
86
87
88
void wpas_notify_state_changed(struct wpa_supplicant *wpa_s,
89
             enum wpa_states new_state,
90
             enum wpa_states old_state)
91
0
{
92
0
  struct wpa_ssid *ssid = wpa_s->current_ssid;
93
94
0
  if (wpa_s->p2p_mgmt)
95
0
    return;
96
97
  /* notify the new DBus API */
98
0
  wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_STATE);
99
100
#ifdef CONFIG_FST
101
  if (wpa_s->fst && !is_zero_ether_addr(wpa_s->bssid)) {
102
    if (new_state == WPA_COMPLETED)
103
      fst_notify_peer_connected(wpa_s->fst, wpa_s->bssid);
104
    else if (old_state >= WPA_ASSOCIATED &&
105
       new_state < WPA_ASSOCIATED)
106
      fst_notify_peer_disconnected(wpa_s->fst, wpa_s->bssid);
107
  }
108
#endif /* CONFIG_FST */
109
110
0
  if (new_state == WPA_COMPLETED) {
111
0
    wpas_p2p_notif_connected(wpa_s);
112
0
    if (ssid && !wpa_s->sta_roaming_disabled)
113
0
      wpa_drv_roaming(wpa_s, !ssid->bssid_set,
114
0
          ssid->bssid_set ? ssid->bssid : NULL);
115
0
  } else if (old_state >= WPA_ASSOCIATED && new_state < WPA_ASSOCIATED) {
116
0
    wpas_p2p_notif_disconnected(wpa_s);
117
0
  }
118
119
0
  sme_state_changed(wpa_s);
120
121
#ifdef ANDROID
122
  wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
123
         "id=%d state=%d BSSID=" MACSTR " SSID=%s",
124
         wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
125
         new_state,
126
         MAC2STR(wpa_s->bssid),
127
         wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
128
         wpa_ssid_txt(wpa_s->current_ssid->ssid,
129
          wpa_s->current_ssid->ssid_len) : "");
130
#endif /* ANDROID */
131
0
}
132
133
134
void wpas_notify_disconnect_reason(struct wpa_supplicant *wpa_s)
135
0
{
136
0
  if (wpa_s->p2p_mgmt)
137
0
    return;
138
139
0
  wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_DISCONNECT_REASON);
140
0
}
141
142
143
void wpas_notify_auth_status_code(struct wpa_supplicant *wpa_s)
144
0
{
145
0
  if (wpa_s->p2p_mgmt)
146
0
    return;
147
148
0
  wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_AUTH_STATUS_CODE);
149
0
}
150
151
152
void wpas_notify_assoc_status_code(struct wpa_supplicant *wpa_s)
153
0
{
154
0
  if (wpa_s->p2p_mgmt)
155
0
    return;
156
157
0
  wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_ASSOC_STATUS_CODE);
158
0
}
159
160
161
void wpas_notify_roam_time(struct wpa_supplicant *wpa_s)
162
0
{
163
0
  if (wpa_s->p2p_mgmt)
164
0
    return;
165
166
0
  wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_ROAM_TIME);
167
0
}
168
169
170
void wpas_notify_roam_complete(struct wpa_supplicant *wpa_s)
171
0
{
172
0
  if (wpa_s->p2p_mgmt)
173
0
    return;
174
175
0
  wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_ROAM_COMPLETE);
176
0
}
177
178
179
void wpas_notify_scan_in_progress_6ghz(struct wpa_supplicant *wpa_s)
180
0
{
181
0
  if (wpa_s->p2p_mgmt)
182
0
    return;
183
184
0
  wpas_dbus_signal_prop_changed(wpa_s,
185
0
              WPAS_DBUS_PROP_SCAN_IN_PROGRESS_6GHZ);
186
0
}
187
188
189
void wpas_notify_session_length(struct wpa_supplicant *wpa_s)
190
0
{
191
0
  if (wpa_s->p2p_mgmt)
192
0
    return;
193
194
0
  wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_SESSION_LENGTH);
195
0
}
196
197
198
void wpas_notify_bss_tm_status(struct wpa_supplicant *wpa_s)
199
0
{
200
0
  if (wpa_s->p2p_mgmt)
201
0
    return;
202
203
0
  wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_BSS_TM_STATUS);
204
0
}
205
206
207
void wpas_notify_network_changed(struct wpa_supplicant *wpa_s)
208
0
{
209
0
  if (wpa_s->p2p_mgmt)
210
0
    return;
211
212
0
  wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_NETWORK);
213
0
}
214
215
216
void wpas_notify_ap_scan_changed(struct wpa_supplicant *wpa_s)
217
0
{
218
0
  if (wpa_s->p2p_mgmt)
219
0
    return;
220
221
0
  wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_AP_SCAN);
222
0
}
223
224
225
void wpas_notify_bssid_changed(struct wpa_supplicant *wpa_s)
226
0
{
227
0
  if (wpa_s->p2p_mgmt)
228
0
    return;
229
230
0
  wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_BSS);
231
0
}
232
233
234
void wpas_notify_mac_address_changed(struct wpa_supplicant *wpa_s)
235
0
{
236
0
  if (wpa_s->p2p_mgmt)
237
0
    return;
238
239
0
  wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_MAC_ADDRESS);
240
0
}
241
242
243
void wpas_notify_auth_changed(struct wpa_supplicant *wpa_s)
244
0
{
245
0
  if (wpa_s->p2p_mgmt)
246
0
    return;
247
248
0
  wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_AUTH_MODE);
249
0
}
250
251
252
void wpas_notify_network_enabled_changed(struct wpa_supplicant *wpa_s,
253
           struct wpa_ssid *ssid)
254
0
{
255
0
  if (wpa_s->p2p_mgmt)
256
0
    return;
257
258
0
  wpas_dbus_signal_network_enabled_changed(wpa_s, ssid);
259
0
}
260
261
262
void wpas_notify_network_selected(struct wpa_supplicant *wpa_s,
263
          struct wpa_ssid *ssid)
264
0
{
265
0
  if (wpa_s->p2p_mgmt)
266
0
    return;
267
268
0
  wpas_dbus_signal_network_selected(wpa_s, ssid->id);
269
0
}
270
271
272
void wpas_notify_network_request(struct wpa_supplicant *wpa_s,
273
         struct wpa_ssid *ssid,
274
         enum wpa_ctrl_req_type rtype,
275
         const char *default_txt)
276
0
{
277
0
  if (wpa_s->p2p_mgmt)
278
0
    return;
279
280
0
  wpas_dbus_signal_network_request(wpa_s, ssid, rtype, default_txt);
281
0
}
282
283
284
void wpas_notify_scanning(struct wpa_supplicant *wpa_s)
285
0
{
286
0
  if (wpa_s->p2p_mgmt)
287
0
    return;
288
289
  /* notify the new DBus API */
290
0
  wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_SCANNING);
291
0
}
292
293
294
void wpas_notify_scan_done(struct wpa_supplicant *wpa_s, int success)
295
0
{
296
0
  if (wpa_s->p2p_mgmt)
297
0
    return;
298
299
0
  wpas_dbus_signal_scan_done(wpa_s, success);
300
0
}
301
302
303
void wpas_notify_scan_results(struct wpa_supplicant *wpa_s)
304
0
{
305
0
  if (wpa_s->p2p_mgmt)
306
0
    return;
307
308
0
  wpas_wps_notify_scan_results(wpa_s);
309
0
}
310
311
312
void wpas_notify_wps_credential(struct wpa_supplicant *wpa_s,
313
        const struct wps_credential *cred)
314
0
{
315
0
  if (wpa_s->p2p_mgmt)
316
0
    return;
317
318
0
#ifdef CONFIG_WPS
319
  /* notify the new DBus API */
320
0
  wpas_dbus_signal_wps_cred(wpa_s, cred);
321
0
#endif /* CONFIG_WPS */
322
0
}
323
324
325
void wpas_notify_wps_event_m2d(struct wpa_supplicant *wpa_s,
326
             struct wps_event_m2d *m2d)
327
0
{
328
0
  if (wpa_s->p2p_mgmt)
329
0
    return;
330
331
0
#ifdef CONFIG_WPS
332
0
  wpas_dbus_signal_wps_event_m2d(wpa_s, m2d);
333
0
#endif /* CONFIG_WPS */
334
0
}
335
336
337
void wpas_notify_wps_event_fail(struct wpa_supplicant *wpa_s,
338
        struct wps_event_fail *fail)
339
0
{
340
0
  if (wpa_s->p2p_mgmt)
341
0
    return;
342
343
0
#ifdef CONFIG_WPS
344
0
  wpas_dbus_signal_wps_event_fail(wpa_s, fail);
345
0
#endif /* CONFIG_WPS */
346
0
}
347
348
349
void wpas_notify_wps_event_success(struct wpa_supplicant *wpa_s)
350
0
{
351
0
  if (wpa_s->p2p_mgmt)
352
0
    return;
353
354
0
#ifdef CONFIG_WPS
355
0
  wpas_dbus_signal_wps_event_success(wpa_s);
356
0
#endif /* CONFIG_WPS */
357
0
}
358
359
void wpas_notify_wps_event_pbc_overlap(struct wpa_supplicant *wpa_s)
360
0
{
361
0
  if (wpa_s->p2p_mgmt)
362
0
    return;
363
364
0
#ifdef CONFIG_WPS
365
0
  wpas_dbus_signal_wps_event_pbc_overlap(wpa_s);
366
0
#endif /* CONFIG_WPS */
367
0
}
368
369
370
void wpas_notify_network_added(struct wpa_supplicant *wpa_s,
371
             struct wpa_ssid *ssid)
372
0
{
373
0
  if (wpa_s->p2p_mgmt)
374
0
    return;
375
376
  /*
377
   * Networks objects created during any P2P activities should not be
378
   * exposed out. They might/will confuse certain non-P2P aware
379
   * applications since these network objects won't behave like
380
   * regular ones.
381
   */
382
0
  if (!ssid->p2p_group && wpa_s->global->p2p_group_formation != wpa_s) {
383
0
    wpas_dbus_register_network(wpa_s, ssid);
384
0
    wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_NETWORK_ADDED "%d",
385
0
           ssid->id);
386
0
  }
387
0
}
388
389
390
void wpas_notify_persistent_group_added(struct wpa_supplicant *wpa_s,
391
          struct wpa_ssid *ssid)
392
0
{
393
#ifdef CONFIG_P2P
394
  wpas_dbus_register_persistent_group(wpa_s, ssid);
395
#endif /* CONFIG_P2P */
396
0
}
397
398
399
void wpas_notify_persistent_group_removed(struct wpa_supplicant *wpa_s,
400
            struct wpa_ssid *ssid)
401
0
{
402
#ifdef CONFIG_P2P
403
  wpas_dbus_unregister_persistent_group(wpa_s, ssid->id);
404
#endif /* CONFIG_P2P */
405
0
}
406
407
408
void wpas_notify_network_removed(struct wpa_supplicant *wpa_s,
409
         struct wpa_ssid *ssid)
410
0
{
411
0
  if (wpa_s->next_ssid == ssid)
412
0
    wpa_s->next_ssid = NULL;
413
0
  if (wpa_s->last_ssid == ssid)
414
0
    wpa_s->last_ssid = NULL;
415
0
  if (wpa_s->current_ssid == ssid)
416
0
    wpa_s->current_ssid = NULL;
417
0
  if (wpa_s->ml_connect_probe_ssid == ssid) {
418
0
    wpa_s->ml_connect_probe_ssid = NULL;
419
0
    wpa_s->ml_connect_probe_bss = NULL;
420
0
  }
421
0
  if (wpa_s->connect_without_scan == ssid)
422
0
    wpa_s->connect_without_scan = NULL;
423
#if defined(CONFIG_SME) && defined(CONFIG_SAE)
424
  if (wpa_s->sme.ext_auth_wpa_ssid == ssid)
425
    wpa_s->sme.ext_auth_wpa_ssid = NULL;
426
#endif /* CONFIG_SME && CONFIG_SAE */
427
0
  if (wpa_s->wpa) {
428
0
    if ((wpa_key_mgmt_sae(ssid->key_mgmt) &&
429
0
         (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_SAE_OFFLOAD_STA)) ||
430
0
        ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) &&
431
0
         (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OWE_OFFLOAD_STA))) {
432
      /* For cases when PMK is generated at the driver */
433
0
      struct wpa_pmkid_params params;
434
435
0
      os_memset(&params, 0, sizeof(params));
436
0
      params.ssid = ssid->ssid;
437
0
      params.ssid_len = ssid->ssid_len;
438
0
      wpa_drv_remove_pmkid(wpa_s, &params);
439
0
    }
440
0
    wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
441
0
  }
442
0
  if (!ssid->p2p_group && wpa_s->global->p2p_group_formation != wpa_s &&
443
0
      !wpa_s->p2p_mgmt) {
444
0
    wpas_dbus_unregister_network(wpa_s, ssid->id);
445
0
    wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_NETWORK_REMOVED "%d",
446
0
           ssid->id);
447
0
  }
448
0
  if (network_is_persistent_group(ssid))
449
0
    wpas_notify_persistent_group_removed(wpa_s, ssid);
450
451
0
  wpas_p2p_network_removed(wpa_s, ssid);
452
0
}
453
454
455
void wpas_notify_bss_added(struct wpa_supplicant *wpa_s,
456
         u8 bssid[], unsigned int id)
457
3.07k
{
458
3.07k
  if (wpa_s->p2p_mgmt)
459
0
    return;
460
461
3.07k
  wpas_dbus_register_bss(wpa_s, bssid, id);
462
3.07k
  wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_ADDED "%u " MACSTR,
463
3.07k
         id, MAC2STR(bssid));
464
3.07k
}
465
466
467
void wpas_notify_bss_removed(struct wpa_supplicant *wpa_s,
468
           u8 bssid[], unsigned int id)
469
3.07k
{
470
3.07k
  if (wpa_s->p2p_mgmt)
471
0
    return;
472
473
3.07k
  wpas_dbus_unregister_bss(wpa_s, bssid, id);
474
3.07k
  wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_REMOVED "%u " MACSTR,
475
3.07k
         id, MAC2STR(bssid));
476
3.07k
}
477
478
479
void wpas_notify_bss_freq_changed(struct wpa_supplicant *wpa_s,
480
          unsigned int id)
481
0
{
482
0
  if (wpa_s->p2p_mgmt)
483
0
    return;
484
485
0
  wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_FREQ, id);
486
0
}
487
488
489
void wpas_notify_bss_signal_changed(struct wpa_supplicant *wpa_s,
490
            unsigned int id)
491
0
{
492
0
  if (wpa_s->p2p_mgmt)
493
0
    return;
494
495
0
  wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_SIGNAL,
496
0
            id);
497
0
}
498
499
500
void wpas_notify_bss_privacy_changed(struct wpa_supplicant *wpa_s,
501
             unsigned int id)
502
0
{
503
0
  if (wpa_s->p2p_mgmt)
504
0
    return;
505
506
0
  wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_PRIVACY,
507
0
            id);
508
0
}
509
510
511
void wpas_notify_bss_mode_changed(struct wpa_supplicant *wpa_s,
512
          unsigned int id)
513
0
{
514
0
  if (wpa_s->p2p_mgmt)
515
0
    return;
516
517
0
  wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_MODE, id);
518
0
}
519
520
521
void wpas_notify_bss_wpaie_changed(struct wpa_supplicant *wpa_s,
522
           unsigned int id)
523
0
{
524
0
  if (wpa_s->p2p_mgmt)
525
0
    return;
526
527
0
  wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_WPA, id);
528
0
}
529
530
531
void wpas_notify_bss_rsnie_changed(struct wpa_supplicant *wpa_s,
532
           unsigned int id)
533
0
{
534
0
  if (wpa_s->p2p_mgmt)
535
0
    return;
536
537
0
  wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RSN, id);
538
0
}
539
540
541
void wpas_notify_bss_wps_changed(struct wpa_supplicant *wpa_s,
542
         unsigned int id)
543
0
{
544
0
  if (wpa_s->p2p_mgmt)
545
0
    return;
546
547
0
#ifdef CONFIG_WPS
548
0
  wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_WPS, id);
549
0
#endif /* CONFIG_WPS */
550
0
}
551
552
553
void wpas_notify_bss_ies_changed(struct wpa_supplicant *wpa_s,
554
           unsigned int id)
555
0
{
556
0
  if (wpa_s->p2p_mgmt)
557
0
    return;
558
559
0
  wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_IES, id);
560
0
}
561
562
563
void wpas_notify_bss_rates_changed(struct wpa_supplicant *wpa_s,
564
           unsigned int id)
565
0
{
566
0
  if (wpa_s->p2p_mgmt)
567
0
    return;
568
569
0
  wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RATES, id);
570
0
}
571
572
573
void wpas_notify_bss_seen(struct wpa_supplicant *wpa_s, unsigned int id)
574
0
{
575
0
  if (wpa_s->p2p_mgmt)
576
0
    return;
577
578
0
  wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_AGE, id);
579
0
}
580
581
582
void wpas_notify_bss_anqp_changed(struct wpa_supplicant *wpa_s, unsigned int id)
583
0
{
584
0
  if (wpa_s->p2p_mgmt)
585
0
    return;
586
587
0
  wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_ANQP, id);
588
0
}
589
590
591
void wpas_notify_blob_added(struct wpa_supplicant *wpa_s, const char *name)
592
0
{
593
0
  if (wpa_s->p2p_mgmt)
594
0
    return;
595
596
0
  wpas_dbus_signal_blob_added(wpa_s, name);
597
0
}
598
599
600
void wpas_notify_blob_removed(struct wpa_supplicant *wpa_s, const char *name)
601
0
{
602
0
  if (wpa_s->p2p_mgmt)
603
0
    return;
604
605
0
  wpas_dbus_signal_blob_removed(wpa_s, name);
606
0
}
607
608
609
void wpas_notify_debug_level_changed(struct wpa_global *global)
610
0
{
611
0
  wpas_dbus_signal_debug_level_changed(global);
612
0
}
613
614
615
void wpas_notify_debug_timestamp_changed(struct wpa_global *global)
616
0
{
617
0
  wpas_dbus_signal_debug_timestamp_changed(global);
618
0
}
619
620
621
void wpas_notify_debug_show_keys_changed(struct wpa_global *global)
622
0
{
623
0
  wpas_dbus_signal_debug_show_keys_changed(global);
624
0
}
625
626
627
void wpas_notify_suspend(struct wpa_global *global)
628
0
{
629
0
  struct wpa_supplicant *wpa_s;
630
631
0
  os_get_time(&global->suspend_time);
632
0
  wpa_printf(MSG_DEBUG, "System suspend notification");
633
0
  for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
634
0
    wpa_drv_suspend(wpa_s);
635
0
}
636
637
638
void wpas_notify_resume(struct wpa_global *global)
639
0
{
640
0
  struct os_time now;
641
0
  int slept;
642
0
  struct wpa_supplicant *wpa_s;
643
644
0
  if (global->suspend_time.sec == 0)
645
0
    slept = -1;
646
0
  else {
647
0
    os_get_time(&now);
648
0
    slept = now.sec - global->suspend_time.sec;
649
0
  }
650
0
  wpa_printf(MSG_DEBUG, "System resume notification (slept %d seconds)",
651
0
       slept);
652
653
0
  for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
654
0
    wpa_drv_resume(wpa_s);
655
0
    if (wpa_s->wpa_state == WPA_DISCONNECTED)
656
0
      wpa_supplicant_req_scan(wpa_s, 0, 100000);
657
0
  }
658
0
}
659
660
661
#ifdef CONFIG_P2P
662
663
void wpas_notify_p2p_find_stopped(struct wpa_supplicant *wpa_s)
664
{
665
  /* Notify P2P find has stopped */
666
  wpas_dbus_signal_p2p_find_stopped(wpa_s);
667
}
668
669
670
void wpas_notify_p2p_device_found(struct wpa_supplicant *wpa_s,
671
          const u8 *dev_addr, int new_device)
672
{
673
  if (new_device) {
674
    /* Create the new peer object */
675
    wpas_dbus_register_peer(wpa_s, dev_addr);
676
  }
677
678
  /* Notify a new peer has been detected*/
679
  wpas_dbus_signal_peer_device_found(wpa_s, dev_addr);
680
}
681
682
683
void wpas_notify_p2p_device_lost(struct wpa_supplicant *wpa_s,
684
         const u8 *dev_addr)
685
{
686
  wpas_dbus_unregister_peer(wpa_s, dev_addr);
687
688
  /* Create signal on interface object*/
689
  wpas_dbus_signal_peer_device_lost(wpa_s, dev_addr);
690
}
691
692
693
void wpas_notify_p2p_group_removed(struct wpa_supplicant *wpa_s,
694
           const struct wpa_ssid *ssid,
695
           const char *role)
696
{
697
  wpas_dbus_signal_p2p_group_removed(wpa_s, role);
698
699
  wpas_dbus_unregister_p2p_group(wpa_s, ssid);
700
}
701
702
703
void wpas_notify_p2p_go_neg_req(struct wpa_supplicant *wpa_s,
704
        const u8 *src, u16 dev_passwd_id, u8 go_intent)
705
{
706
  wpas_dbus_signal_p2p_go_neg_req(wpa_s, src, dev_passwd_id, go_intent);
707
}
708
709
710
void wpas_notify_p2p_go_neg_completed(struct wpa_supplicant *wpa_s,
711
              struct p2p_go_neg_results *res)
712
{
713
  wpas_dbus_signal_p2p_go_neg_resp(wpa_s, res);
714
}
715
716
717
void wpas_notify_p2p_invitation_result(struct wpa_supplicant *wpa_s,
718
               int status, const u8 *bssid)
719
{
720
  wpas_dbus_signal_p2p_invitation_result(wpa_s, status, bssid);
721
}
722
723
724
void wpas_notify_p2p_sd_request(struct wpa_supplicant *wpa_s,
725
        int freq, const u8 *sa, u8 dialog_token,
726
        u16 update_indic, const u8 *tlvs,
727
        size_t tlvs_len)
728
{
729
  wpas_dbus_signal_p2p_sd_request(wpa_s, freq, sa, dialog_token,
730
          update_indic, tlvs, tlvs_len);
731
}
732
733
734
void wpas_notify_p2p_sd_response(struct wpa_supplicant *wpa_s,
735
         const u8 *sa, u16 update_indic,
736
         const u8 *tlvs, size_t tlvs_len)
737
{
738
  wpas_dbus_signal_p2p_sd_response(wpa_s, sa, update_indic,
739
           tlvs, tlvs_len);
740
}
741
742
743
/**
744
 * wpas_notify_p2p_provision_discovery - Notification of provision discovery
745
 * @dev_addr: Who sent the request or responded to our request.
746
 * @request: Will be 1 if request, 0 for response.
747
 * @status: Valid only in case of response (0 in case of success)
748
 * @config_methods: WPS config methods
749
 * @generated_pin: PIN to be displayed in case of WPS_CONFIG_DISPLAY method
750
 *
751
 * This can be used to notify:
752
 * - Requests or responses
753
 * - Various config methods
754
 * - Failure condition in case of response
755
 */
756
void wpas_notify_p2p_provision_discovery(struct wpa_supplicant *wpa_s,
757
           const u8 *dev_addr, int request,
758
           enum p2p_prov_disc_status status,
759
           u16 config_methods,
760
           unsigned int generated_pin)
761
{
762
  wpas_dbus_signal_p2p_provision_discovery(wpa_s, dev_addr, request,
763
             status, config_methods,
764
             generated_pin);
765
}
766
767
768
void wpas_notify_p2p_group_started(struct wpa_supplicant *wpa_s,
769
           struct wpa_ssid *ssid, int persistent,
770
           int client, const u8 *ip)
771
{
772
  /* Notify a group has been started */
773
  wpas_dbus_register_p2p_group(wpa_s, ssid);
774
775
  wpas_dbus_signal_p2p_group_started(wpa_s, client, persistent, ip);
776
}
777
778
779
void wpas_notify_p2p_group_formation_failure(struct wpa_supplicant *wpa_s,
780
               const char *reason)
781
{
782
  /* Notify a group formation failed */
783
  wpas_dbus_signal_p2p_group_formation_failure(wpa_s, reason);
784
}
785
786
787
void wpas_notify_p2p_wps_failed(struct wpa_supplicant *wpa_s,
788
        struct wps_event_fail *fail)
789
{
790
  wpas_dbus_signal_p2p_wps_failed(wpa_s, fail);
791
}
792
793
794
void wpas_notify_p2p_invitation_received(struct wpa_supplicant *wpa_s,
795
           const u8 *sa, const u8 *go_dev_addr,
796
           const u8 *bssid, int id, int op_freq)
797
{
798
  /* Notify a P2P Invitation Request */
799
  wpas_dbus_signal_p2p_invitation_received(wpa_s, sa, go_dev_addr, bssid,
800
             id, op_freq);
801
}
802
803
void wpas_notify_p2p_bootstrap_req(struct wpa_supplicant *wpa_s,
804
           const u8 *src, u16 bootstrap_method)
805
{
806
  wpas_dbus_signal_p2p_bootstrap_req(wpa_s, src, bootstrap_method);
807
}
808
809
void wpas_notify_p2p_bootstrap_rsp(struct wpa_supplicant *wpa_s,
810
           const u8 *src, int status,
811
           u16 bootstrap_method)
812
{
813
  wpas_dbus_signal_p2p_bootstrap_rsp(wpa_s, src, status,
814
             bootstrap_method);
815
}
816
817
#endif /* CONFIG_P2P */
818
819
820
static void wpas_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s,
821
            const u8 *sta,
822
            const u8 *p2p_dev_addr, const u8 *ip)
823
0
{
824
#ifdef CONFIG_P2P
825
  wpas_p2p_notify_ap_sta_authorized(wpa_s, p2p_dev_addr);
826
827
  /*
828
   * Create 'peer-joined' signal on group object -- will also
829
   * check P2P itself.
830
   */
831
  if (p2p_dev_addr)
832
    wpas_dbus_signal_p2p_peer_joined(wpa_s, p2p_dev_addr);
833
#endif /* CONFIG_P2P */
834
835
  /* Register the station */
836
0
  wpas_dbus_register_sta(wpa_s, sta);
837
838
  /* Notify listeners a new station has been authorized */
839
0
  wpas_dbus_signal_sta_authorized(wpa_s, sta);
840
0
}
841
842
843
static void wpas_notify_ap_sta_deauthorized(struct wpa_supplicant *wpa_s,
844
              const u8 *sta,
845
              const u8 *p2p_dev_addr)
846
0
{
847
#ifdef CONFIG_P2P
848
  /*
849
   * Create 'peer-disconnected' signal on group object if this
850
   * is a P2P group.
851
   */
852
  if (p2p_dev_addr)
853
    wpas_dbus_signal_p2p_peer_disconnected(wpa_s, p2p_dev_addr);
854
#endif /* CONFIG_P2P */
855
856
  /* Notify listeners a station has been deauthorized */
857
0
  wpas_dbus_signal_sta_deauthorized(wpa_s, sta);
858
859
  /* Unregister the station */
860
0
  wpas_dbus_unregister_sta(wpa_s, sta);
861
0
}
862
863
864
void wpas_notify_sta_authorized(struct wpa_supplicant *wpa_s,
865
        const u8 *mac_addr, int authorized,
866
        const u8 *p2p_dev_addr, const u8 *ip)
867
0
{
868
0
  if (authorized)
869
0
    wpas_notify_ap_sta_authorized(wpa_s, mac_addr, p2p_dev_addr,
870
0
                ip);
871
0
  else
872
0
    wpas_notify_ap_sta_deauthorized(wpa_s, mac_addr, p2p_dev_addr);
873
0
}
874
875
876
void wpas_notify_certification(struct wpa_supplicant *wpa_s,
877
             struct tls_cert_data *cert,
878
             const char *cert_hash)
879
0
{
880
0
  int i;
881
882
0
  wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_EAP_PEER_CERT
883
0
    "depth=%d subject='%s'%s%s%s%s",
884
0
    cert->depth, cert->subject, cert_hash ? " hash=" : "",
885
0
    cert_hash ? cert_hash : "",
886
0
    cert->tod == 2 ? " tod=2" : "",
887
0
    cert->tod == 1 ? " tod=1" : "");
888
889
0
  if (cert->cert) {
890
0
    char *cert_hex;
891
0
    size_t len = wpabuf_len(cert->cert) * 2 + 1;
892
0
    cert_hex = os_malloc(len);
893
0
    if (cert_hex) {
894
0
      wpa_snprintf_hex(cert_hex, len, wpabuf_head(cert->cert),
895
0
           wpabuf_len(cert->cert));
896
0
      wpa_msg_ctrl(wpa_s, MSG_INFO,
897
0
             WPA_EVENT_EAP_PEER_CERT
898
0
             "depth=%d subject='%s' cert=%s",
899
0
             cert->depth, cert->subject, cert_hex);
900
0
      os_free(cert_hex);
901
0
    }
902
0
  }
903
904
0
  for (i = 0; i < cert->num_altsubject; i++)
905
0
    wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_EAP_PEER_ALT
906
0
      "depth=%d %s", cert->depth, cert->altsubject[i]);
907
908
  /* notify the new DBus API */
909
0
  wpas_dbus_signal_certification(wpa_s, cert->depth, cert->subject,
910
0
               cert->altsubject, cert->num_altsubject,
911
0
               cert_hash, cert->cert);
912
0
}
913
914
915
void wpas_notify_preq(struct wpa_supplicant *wpa_s,
916
          const u8 *addr, const u8 *dst, const u8 *bssid,
917
          const u8 *ie, size_t ie_len, u32 ssi_signal)
918
0
{
919
#ifdef CONFIG_AP
920
  wpas_dbus_signal_preq(wpa_s, addr, dst, bssid, ie, ie_len, ssi_signal);
921
#endif /* CONFIG_AP */
922
0
}
923
924
925
void wpas_notify_eap_status(struct wpa_supplicant *wpa_s, const char *status,
926
          const char *parameter)
927
0
{
928
0
  wpas_dbus_signal_eap_status(wpa_s, status, parameter);
929
0
  wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_EAP_STATUS
930
0
         "status='%s' parameter='%s'",
931
0
         status, parameter);
932
0
}
933
934
935
void wpas_notify_eap_error(struct wpa_supplicant *wpa_s, int error_code)
936
0
{
937
0
  wpa_msg(wpa_s, MSG_ERROR, WPA_EVENT_EAP_ERROR_CODE "%d", error_code);
938
0
}
939
940
941
void wpas_notify_psk_mismatch(struct wpa_supplicant *wpa_s)
942
0
{
943
0
  wpas_dbus_signal_psk_mismatch(wpa_s);
944
0
}
945
946
947
void wpas_notify_sae_password_mismatch(struct wpa_supplicant *wpa_s)
948
0
{
949
0
  wpas_dbus_signal_sae_password_mismatch(wpa_s);
950
0
}
951
952
953
void wpas_notify_network_bssid_set_changed(struct wpa_supplicant *wpa_s,
954
             struct wpa_ssid *ssid)
955
0
{
956
0
  if (wpa_s->current_ssid != ssid)
957
0
    return;
958
959
0
  wpa_dbg(wpa_s, MSG_DEBUG,
960
0
    "Network bssid config changed for the current network - within-ESS roaming %s",
961
0
    ssid->bssid_set ? "disabled" : "enabled");
962
963
0
  wpa_drv_roaming(wpa_s, !ssid->bssid_set,
964
0
      ssid->bssid_set ? ssid->bssid : NULL);
965
0
}
966
967
968
void wpas_notify_network_type_changed(struct wpa_supplicant *wpa_s,
969
              struct wpa_ssid *ssid)
970
0
{
971
#ifdef CONFIG_P2P
972
  if (ssid->disabled == 2) {
973
    /* Changed from normal network profile to persistent group */
974
    ssid->disabled = 0;
975
    wpas_dbus_unregister_network(wpa_s, ssid->id);
976
    ssid->disabled = 2;
977
    ssid->p2p_persistent_group = 1;
978
    wpas_dbus_register_persistent_group(wpa_s, ssid);
979
  } else {
980
    /* Changed from persistent group to normal network profile */
981
    wpas_dbus_unregister_persistent_group(wpa_s, ssid->id);
982
    ssid->p2p_persistent_group = 0;
983
    wpas_dbus_register_network(wpa_s, ssid);
984
  }
985
#endif /* CONFIG_P2P */
986
0
}
987
988
989
#ifdef CONFIG_MESH
990
991
void wpas_notify_mesh_group_started(struct wpa_supplicant *wpa_s,
992
            struct wpa_ssid *ssid)
993
{
994
  if (wpa_s->p2p_mgmt)
995
    return;
996
997
  wpas_dbus_signal_mesh_group_started(wpa_s, ssid);
998
}
999
1000
1001
void wpas_notify_mesh_group_removed(struct wpa_supplicant *wpa_s,
1002
            const u8 *meshid, u8 meshid_len,
1003
            u16 reason_code)
1004
{
1005
  if (wpa_s->p2p_mgmt)
1006
    return;
1007
1008
  wpas_dbus_signal_mesh_group_removed(wpa_s, meshid, meshid_len,
1009
              reason_code);
1010
}
1011
1012
1013
void wpas_notify_mesh_peer_connected(struct wpa_supplicant *wpa_s,
1014
             const u8 *peer_addr)
1015
{
1016
  if (wpa_s->p2p_mgmt)
1017
    return;
1018
1019
  wpa_msg(wpa_s, MSG_INFO, MESH_PEER_CONNECTED MACSTR,
1020
    MAC2STR(peer_addr));
1021
  wpas_dbus_signal_mesh_peer_connected(wpa_s, peer_addr);
1022
}
1023
1024
1025
void wpas_notify_mesh_peer_disconnected(struct wpa_supplicant *wpa_s,
1026
          const u8 *peer_addr, u16 reason_code)
1027
{
1028
  if (wpa_s->p2p_mgmt)
1029
    return;
1030
1031
  wpa_msg(wpa_s, MSG_INFO, MESH_PEER_DISCONNECTED MACSTR,
1032
    MAC2STR(peer_addr));
1033
  wpas_dbus_signal_mesh_peer_disconnected(wpa_s, peer_addr, reason_code);
1034
}
1035
1036
#endif /* CONFIG_MESH */
1037
1038
1039
#ifdef CONFIG_INTERWORKING
1040
1041
void wpas_notify_interworking_ap_added(struct wpa_supplicant *wpa_s,
1042
               struct wpa_bss *bss,
1043
               struct wpa_cred *cred, int excluded,
1044
               const char *type, int bh, int bss_load,
1045
               int conn_capab)
1046
0
{
1047
0
  wpa_msg(wpa_s, MSG_INFO, "%s" MACSTR " type=%s%s%s%s id=%d priority=%d sp_priority=%d",
1048
0
    excluded ? INTERWORKING_EXCLUDED : INTERWORKING_AP,
1049
0
    MAC2STR(bss->bssid), type,
1050
0
    bh ? " below_min_backhaul=1" : "",
1051
0
    bss_load ? " over_max_bss_load=1" : "",
1052
0
    conn_capab ? " conn_capab_missing=1" : "",
1053
0
    cred->id, cred->priority, cred->sp_priority);
1054
1055
0
  wpas_dbus_signal_interworking_ap_added(wpa_s, bss, cred, type, excluded,
1056
0
                 bh, bss_load, conn_capab);
1057
0
}
1058
1059
1060
void wpas_notify_interworking_select_done(struct wpa_supplicant *wpa_s)
1061
0
{
1062
0
  wpas_dbus_signal_interworking_select_done(wpa_s);
1063
0
}
1064
1065
1066
void wpas_notify_anqp_query_done(struct wpa_supplicant *wpa_s,
1067
         const u8 *dst, const char *result)
1068
0
{
1069
0
  wpa_msg(wpa_s, MSG_INFO, ANQP_QUERY_DONE "addr=" MACSTR " result=%s",
1070
0
    MAC2STR(dst), result);
1071
1072
0
  wpas_dbus_signal_anqp_query_done(wpa_s, dst, result);
1073
0
}
1074
1075
#endif /* CONFIG_INTERWORKING */
1076
1077
1078
void wpas_notify_pmk_cache_added(struct wpa_supplicant *wpa_s,
1079
         struct rsn_pmksa_cache_entry *entry)
1080
0
{
1081
  /* TODO: Notify external entities of the added PMKSA cache entry */
1082
0
}
1083
1084
1085
void wpas_notify_signal_change(struct wpa_supplicant *wpa_s)
1086
0
{
1087
0
  wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_SIGNAL_CHANGE);
1088
0
}
1089
1090
1091
#ifdef CONFIG_HS20
1092
void wpas_notify_hs20_t_c_acceptance(struct wpa_supplicant *wpa_s,
1093
             const char *url)
1094
0
{
1095
0
  wpa_msg(wpa_s, MSG_INFO, HS20_T_C_ACCEPTANCE "%s", url);
1096
0
  wpas_dbus_signal_hs20_t_c_acceptance(wpa_s, url);
1097
0
}
1098
#endif /* CONFIG_HS20 */
1099
1100
1101
#if defined(CONFIG_NAN) || defined(CONFIG_NAN_USD)
1102
1103
void wpas_notify_nan_discovery_result(struct wpa_supplicant *wpa_s,
1104
              struct nan_discovery_result *res)
1105
{
1106
  char *ssi_hex, *pmkid_hex = NULL;
1107
  char *cipher_suites_str = NULL;
1108
  char proxied[100];
1109
  const char *locale;
1110
  const char *vendor;
1111
  const char *model;
1112
  const char *pname;
1113
1114
  ssi_hex = os_zalloc(2 * res->ssi_len + 1);
1115
  if (!ssi_hex)
1116
    return;
1117
  if (res->ssi)
1118
    wpa_snprintf_hex(ssi_hex, 2 * res->ssi_len + 1,
1119
         res->ssi, res->ssi_len);
1120
1121
  if (res->pmkid_list && res->pmkid_count > 0) {
1122
    const size_t pmkid_hex_len = 2 * PMKID_LEN + 1;
1123
    unsigned int i;
1124
1125
    pmkid_hex = os_zalloc(res->pmkid_count * pmkid_hex_len);
1126
    if (pmkid_hex) {
1127
      for (i = 0; i < res->pmkid_count; i++) {
1128
        char *pos = &pmkid_hex[i * pmkid_hex_len];
1129
1130
        wpa_snprintf_hex(
1131
          pos, pmkid_hex_len,
1132
          &res->pmkid_list[i * PMKID_LEN],
1133
          PMKID_LEN);
1134
        if (i < res->pmkid_count - 1)
1135
          pos[2 * PMKID_LEN] = ',';
1136
      }
1137
    }
1138
  }
1139
1140
  if (res->cipher_suites && res->n_cipher_suites > 0) {
1141
    char *pos;
1142
    unsigned int i;
1143
1144
    /* Allocate enough space for trailing space after each cipher */
1145
    cipher_suites_str = os_zalloc(res->n_cipher_suites * 2);
1146
    if (!cipher_suites_str)
1147
      goto err;
1148
1149
    pos = cipher_suites_str;
1150
1151
    for (i = 0; i < res->n_cipher_suites; i++) {
1152
      int ret;
1153
      size_t left = res->n_cipher_suites * 2 -
1154
        (pos - cipher_suites_str);
1155
1156
      ret = os_snprintf(pos, left, "%s%u", i > 0 ? "," : "",
1157
            res->cipher_suites[i]);
1158
      if (os_snprintf_error(left, ret))
1159
        break;
1160
      pos += ret;
1161
    }
1162
  }
1163
err:
1164
  locale = res->psi_locale ? res->psi_locale : "";
1165
  vendor = res->psi_vendor_name ? res->psi_vendor_name : "";
1166
  model = res->psi_model_name ? res->psi_model_name : "";
1167
  pname = res->psi_pairing_name ? res->psi_pairing_name : "";
1168
1169
  if (res->orig_addr)
1170
    os_snprintf(proxied, sizeof(proxied),
1171
          " orig_nmi=" MACSTR " proxied",
1172
          MAC2STR(res->orig_addr));
1173
  else
1174
    proxied[0] = '\0';
1175
1176
  wpa_msg_global(wpa_s, MSG_INFO, NAN_DISCOVERY_RESULT
1177
           "subscribe_id=%d publish_id=%d address=" MACSTR
1178
           " fsd=%d fsd_gas=%d srv_proto_type=%u ssi=%s%s%s%s%s pairing_setup_supp=%d npk_nik_caching_supp=%d pbm=0x%04x data_path=%d%s%s%s%s%s%s%s%s%s",
1179
           res->subscribe_id, res->peer_publish_id,
1180
           MAC2STR(res->peer_addr),
1181
           res->fsd, res->fsd_gas, res->srv_proto_type, ssi_hex,
1182
           pmkid_hex ? " pmkid=" : "",
1183
           pmkid_hex ? pmkid_hex : "",
1184
           cipher_suites_str ? " cipher_suites=" : "",
1185
           cipher_suites_str ? cipher_suites_str : "",
1186
           res->pairing_setup_supp, res->npk_nik_caching_supp,
1187
           res->pbm, res->data_path, proxied,
1188
           res->psi_locale ? " locale=" : "", locale,
1189
           res->psi_vendor_name ? " vendorName=" : "", vendor,
1190
           res->psi_model_name ? " modelName=" : "", model,
1191
           res->psi_pairing_name ? " pairingName=" : "", pname);
1192
  os_free(ssi_hex);
1193
  os_free(pmkid_hex);
1194
  os_free(cipher_suites_str);
1195
1196
  wpas_dbus_signal_nan_discovery_result(wpa_s,
1197
                res->srv_proto_type,
1198
                res->subscribe_id,
1199
                res->peer_publish_id,
1200
                res->peer_addr,
1201
                res->fsd, res->fsd_gas,
1202
                res->ssi, res->ssi_len,
1203
                res->orig_addr);
1204
}
1205
1206
1207
void wpas_notify_nan_replied(struct wpa_supplicant *wpa_s,
1208
           enum nan_service_protocol_type srv_proto_type,
1209
           int publish_id, int peer_subscribe_id,
1210
           const u8 *peer_addr,
1211
           const u8 *ssi, size_t ssi_len)
1212
{
1213
  char *ssi_hex;
1214
1215
  ssi_hex = os_zalloc(2 * ssi_len + 1);
1216
  if (!ssi_hex)
1217
    return;
1218
  if (ssi)
1219
    wpa_snprintf_hex(ssi_hex, 2 * ssi_len + 1, ssi, ssi_len);
1220
  wpa_msg_global(wpa_s, MSG_INFO, NAN_REPLIED
1221
           "publish_id=%d address=" MACSTR
1222
           " subscribe_id=%d srv_proto_type=%u ssi=%s",
1223
           publish_id, MAC2STR(peer_addr), peer_subscribe_id,
1224
           srv_proto_type, ssi_hex);
1225
  os_free(ssi_hex);
1226
1227
  wpas_dbus_signal_nan_replied(wpa_s, srv_proto_type, publish_id,
1228
             peer_subscribe_id, peer_addr,
1229
             ssi, ssi_len);
1230
}
1231
1232
1233
void wpas_notify_nan_receive(struct wpa_supplicant *wpa_s, int id,
1234
           int peer_instance_id, const u8 *peer_addr,
1235
           const u8 *ssi, size_t ssi_len)
1236
{
1237
  char *ssi_hex;
1238
1239
  ssi_hex = os_zalloc(2 * ssi_len + 1);
1240
  if (!ssi_hex)
1241
    return;
1242
  if (ssi)
1243
    wpa_snprintf_hex(ssi_hex, 2 * ssi_len + 1, ssi, ssi_len);
1244
  wpa_msg_global(wpa_s, MSG_INFO, NAN_RECEIVE
1245
           "id=%d peer_instance_id=%d address=" MACSTR " ssi=%s",
1246
           id, peer_instance_id, MAC2STR(peer_addr), ssi_hex);
1247
  os_free(ssi_hex);
1248
1249
  wpas_dbus_signal_nan_receive(wpa_s, id, peer_instance_id, peer_addr,
1250
             ssi, ssi_len);
1251
}
1252
1253
1254
static const char * nan_reason_txt(enum nan_de_reason reason)
1255
{
1256
  switch (reason) {
1257
  case NAN_DE_REASON_TIMEOUT:
1258
    return "timeout";
1259
  case NAN_DE_REASON_USER_REQUEST:
1260
    return "user-request";
1261
  case NAN_DE_REASON_FAILURE:
1262
    return "failure";
1263
  }
1264
1265
  return "unknown";
1266
}
1267
1268
1269
void wpas_notify_nan_publish_terminated(struct wpa_supplicant *wpa_s,
1270
          int publish_id,
1271
          enum nan_de_reason reason)
1272
{
1273
  wpa_msg_global(wpa_s, MSG_INFO, NAN_PUBLISH_TERMINATED
1274
           "publish_id=%d reason=%s",
1275
           publish_id, nan_reason_txt(reason));
1276
  wpas_dbus_signal_nan_publish_terminated(wpa_s, publish_id,
1277
            nan_reason_txt(reason));
1278
}
1279
1280
1281
void wpas_notify_nan_subscribe_terminated(struct wpa_supplicant *wpa_s,
1282
            int subscribe_id,
1283
            enum nan_de_reason reason)
1284
{
1285
  wpa_msg_global(wpa_s, MSG_INFO, NAN_SUBSCRIBE_TERMINATED
1286
           "subscribe_id=%d reason=%s",
1287
           subscribe_id, nan_reason_txt(reason));
1288
  wpas_dbus_signal_nan_subscribe_terminated(wpa_s, subscribe_id,
1289
              nan_reason_txt(reason));
1290
}
1291
1292
1293
void wpas_notify_nan_transmit_req_status(struct wpa_supplicant *wpa_s,
1294
           u32 cookie, bool acked)
1295
{
1296
  wpa_msg_global(wpa_s, MSG_INFO, NAN_TRANSMIT_STATUS
1297
           "cookie=%u acked=%u", cookie, acked);
1298
}
1299
1300
1301
void wpas_notify_nan_bootstrap_request(struct wpa_supplicant *wpa_s,
1302
               const u8 *peer_nmi, u16 pbm,
1303
               int handle, u8 requestor_instance_id,
1304
               const char *locale,
1305
               const char *vendor_name,
1306
               const char *model_name,
1307
               const char *pairing_name)
1308
{
1309
  wpa_msg_global(wpa_s, MSG_INFO, NAN_BOOTSTRAP_REQUEST
1310
           "peer_nmi=" MACSTR
1311
           " pbm=0x%04x handle=%d requestor_instance_id=%u%s%s%s%s%s%s%s%s",
1312
           MAC2STR(peer_nmi), pbm, handle, requestor_instance_id,
1313
           locale ? " locale=" : "", locale ? locale : "",
1314
           vendor_name ? " vendorName=" : "",
1315
           vendor_name ? vendor_name : "",
1316
           model_name ? " modelName=" : "",
1317
           model_name ? model_name : "",
1318
           pairing_name ? " pairingName=" : "",
1319
           pairing_name ? pairing_name : "");
1320
}
1321
1322
1323
void wpas_notify_nan_bootstrap_success(struct wpa_supplicant *wpa_s,
1324
               const u8 *peer_nmi, u16 pbm,
1325
               int handle, u8 requestor_instance_id)
1326
{
1327
  wpa_msg_global(wpa_s, MSG_INFO, NAN_BOOTSTRAP_SUCCESS
1328
           "peer_nmi=" MACSTR
1329
           " pbm=0x%04x handle=%d requestor_instance_id=%u",
1330
           MAC2STR(peer_nmi), pbm, handle, requestor_instance_id);
1331
}
1332
1333
1334
void wpas_notify_nan_bootstrap_failure(struct wpa_supplicant *wpa_s,
1335
               const u8 *peer_nmi, u16 pbm,
1336
               u8 reason, int handle,
1337
               u8 requestor_instance_id)
1338
{
1339
  wpa_msg_global(wpa_s, MSG_INFO, NAN_BOOTSTRAP_FAILURE
1340
           "peer_nmi=" MACSTR
1341
           " pbm=0x%04x reason=%u handle=%d requestor_instance_id=%u",
1342
           MAC2STR(peer_nmi), pbm, reason, handle,
1343
           requestor_instance_id);
1344
}
1345
1346
1347
#ifdef CONFIG_PASN
1348
1349
void wpas_notify_nan_nik_received(struct wpa_supplicant *wpa_s,
1350
          const u8 *nik, size_t nik_len,
1351
          int cipher_ver, int akmp,
1352
          const u8 *npk, size_t npk_len,
1353
          int nik_lifetime, int identity_id)
1354
{
1355
  char *nik_hex, *npk_hex;
1356
  size_t nik_hex_len = 2 * nik_len + 1;
1357
  size_t npk_hex_len = 2 * npk_len + 1;
1358
1359
  nik_hex = os_malloc(nik_hex_len);
1360
  npk_hex = os_malloc(npk_hex_len);
1361
  if (!nik_hex || !npk_hex) {
1362
    wpa_printf(MSG_INFO,
1363
         "NAN NIK received: Failed to allocate memory");
1364
    goto out;
1365
  }
1366
1367
  wpa_snprintf_hex(nik_hex, nik_hex_len, nik, nik_len);
1368
  wpa_snprintf_hex(npk_hex, npk_hex_len, npk, npk_len);
1369
1370
  wpa_msg_global(wpa_s, MSG_INFO, NAN_NIK_RECEIVED
1371
           "nik=%s cipher_version=%d akmp=%s pmk=%s lifetime=%d identity_id=%d",
1372
           nik_hex, cipher_ver,
1373
           wpa_key_mgmt_txt(akmp, WPA_PROTO_RSN),
1374
           npk_hex, nik_lifetime, identity_id);
1375
1376
out:
1377
  bin_clear_free(nik_hex, nik_hex_len);
1378
  bin_clear_free(npk_hex, npk_hex_len);
1379
}
1380
1381
1382
void wpas_notify_nan_pairing_request(struct wpa_supplicant *wpa_s,
1383
             const u8 *peer_nmi, u8 csid,
1384
             u8 instance_id, int key_mgmt,
1385
             bool verify)
1386
{
1387
  wpa_msg_global(wpa_s, MSG_INFO, NAN_PAIRING_REQUEST
1388
           "peer_nmi=" MACSTR
1389
           " csid=%u instance_id=%u key_mgmt=%s verify=%d",
1390
           MAC2STR(peer_nmi), csid, instance_id,
1391
           wpa_key_mgmt_txt(key_mgmt, WPA_PROTO_RSN),
1392
           verify);
1393
}
1394
1395
#endif /* CONFIG_PASN */
1396
1397
1398
void wpas_notify_nan_ndp_request(struct wpa_supplicant *wpa_s,
1399
         const u8 *peer_nmi, const u8 *init_ndi,
1400
         u32 ndp_id, u8 publish_inst_id,
1401
         const u8 *ssi, size_t ssi_len, u32 csid)
1402
{
1403
  char *ssi_hex = NULL;
1404
1405
  if (ssi) {
1406
    ssi_hex = os_zalloc(2 * ssi_len + 1);
1407
    if (!ssi_hex)
1408
      return;
1409
1410
    wpa_snprintf_hex(ssi_hex, 2 * ssi_len + 1, ssi, ssi_len);
1411
  }
1412
1413
  wpa_msg_global(wpa_s, MSG_INFO, NAN_NDP_REQUEST "peer_nmi=" MACSTR
1414
           " init_ndi=" MACSTR
1415
           " ndp_id=%u publish_inst_id=%u ssi=%s csid=%u",
1416
           MAC2STR(peer_nmi), MAC2STR(init_ndi),
1417
           ndp_id, publish_inst_id,
1418
           ssi_hex ? ssi_hex : "", csid);
1419
1420
  os_free(ssi_hex);
1421
}
1422
1423
1424
void wpas_notify_nan_ndp_counter_request(struct wpa_supplicant *wpa_s,
1425
           const u8 *peer_nmi,
1426
           const u8 *init_ndi, u32 ndp_id,
1427
           const u8 *ssi, size_t ssi_len)
1428
{
1429
  char *ssi_hex = NULL;
1430
1431
  if (ssi) {
1432
    ssi_hex = os_zalloc(2 * ssi_len + 1);
1433
    if (!ssi_hex)
1434
      return;
1435
1436
    wpa_snprintf_hex(ssi_hex, 2 * ssi_len + 1, ssi, ssi_len);
1437
  }
1438
1439
  wpa_msg_global(wpa_s, MSG_INFO, NAN_NDP_COUNTER_REQUEST
1440
           "peer_nmi=" MACSTR " init_ndi=" MACSTR
1441
           " ndp_id=%u ssi=%s",
1442
           MAC2STR(peer_nmi), MAC2STR(init_ndi),
1443
           ndp_id, ssi_hex ? ssi_hex : "");
1444
1445
  os_free(ssi_hex);
1446
}
1447
1448
1449
void wpas_notify_nan_ndp_connected(struct wpa_supplicant *wpa_s,
1450
           const u8 *peer_nmi, u32 ndp_id,
1451
           const u8 *local_ndi,
1452
           const u8 *peer_ndi,
1453
           const u8 *ssi, size_t ssi_len,
1454
           const u8 *interface_id)
1455
{
1456
  char *ssi_hex = NULL, *interface_id_hex = NULL;
1457
1458
  if (ssi) {
1459
    ssi_hex = os_zalloc(2 * ssi_len + 1);
1460
    if (!ssi_hex)
1461
      return;
1462
1463
    wpa_snprintf_hex(ssi_hex, 2 * ssi_len + 1, ssi, ssi_len);
1464
  }
1465
1466
  if (interface_id) {
1467
    interface_id_hex =
1468
      os_zalloc(2 * NAN_NDPE_TLV_IPV6_LINK_LOCAL_LEN + 1);
1469
    if (!interface_id_hex)
1470
      return;
1471
1472
    wpa_snprintf_hex(interface_id_hex,
1473
         2 * NAN_NDPE_TLV_IPV6_LINK_LOCAL_LEN + 1,
1474
         interface_id,
1475
         NAN_NDPE_TLV_IPV6_LINK_LOCAL_LEN);
1476
  }
1477
1478
  wpa_msg_global(wpa_s, MSG_INFO, NAN_NDP_CONNECTED "peer=" MACSTR
1479
           " ndp_id=%u local_ndi=" MACSTR
1480
           " peer_ndi=" MACSTR " ssi=%s interface_id=%s",
1481
           MAC2STR(peer_nmi), ndp_id,
1482
           MAC2STR(local_ndi), MAC2STR(peer_ndi),
1483
           ssi_hex ? ssi_hex : "",
1484
           interface_id ? interface_id_hex : "");
1485
1486
  os_free(ssi_hex);
1487
  os_free(interface_id_hex);
1488
}
1489
1490
1491
void wpas_notify_nan_ndp_disconnected(struct wpa_supplicant *wpa_s,
1492
              const u8 *peer_nmi, u32 ndp_id,
1493
              const u8 *local_ndi,
1494
              const u8 *peer_ndi,
1495
              enum nan_reason reason,
1496
              bool locally_generated,
1497
              bool failure)
1498
{
1499
  wpa_msg_global(wpa_s, MSG_INFO, NAN_NDP_DISCONNECTED
1500
           "peer=" MACSTR " ndp_id=%u local_ndi=" MACSTR
1501
           " peer_ndi=" MACSTR
1502
           " reason=%u locally_generated=%d, failure=%d",
1503
           MAC2STR(peer_nmi), ndp_id,
1504
           MAC2STR(local_ndi), MAC2STR(peer_ndi), reason,
1505
           locally_generated, failure);
1506
}
1507
1508
1509
void wpas_notify_nan_cluster_join(struct wpa_supplicant *wpa_s,
1510
          const u8 *cluster_id, bool new_cluster)
1511
{
1512
  wpa_msg_global(wpa_s, MSG_INFO, NAN_CLUSTER_JOIN "cluster_id=" MACSTR
1513
           " new=%d", MAC2STR(cluster_id), new_cluster);
1514
}
1515
1516
1517
void wpas_notify_nan_schedule_changed(struct wpa_supplicant *wpa_s,
1518
              const u8 *peer_nmi)
1519
{
1520
  wpa_msg_global(wpa_s, MSG_INFO,
1521
           NAN_PEER_SCHEDULE_CHANGED "peer_nmi=" MACSTR,
1522
           MAC2STR(peer_nmi));
1523
}
1524
1525
1526
void wpas_notify_nan_sched_update_done(struct wpa_supplicant *wpa_s,
1527
               bool success)
1528
{
1529
  wpa_msg_global(wpa_s, MSG_INFO, NAN_SCHEDULE_UPDATE_DONE "status=%s",
1530
           success ? "success" : "failure");
1531
}
1532
1533
1534
void wpas_notify_nan_pairing_status(struct wpa_supplicant *wpa_s,
1535
            const u8 *peer_addr, int akmp,
1536
            int cipher, u16 status,
1537
            const u8 *nd_pmk,
1538
            const char *psi_locale,
1539
            const char *psi_vendor_name,
1540
            const char *psi_model_name,
1541
            const char *psi_pairing_name)
1542
{
1543
  char nd_pmk_hex[2 * PMK_LEN + 1];
1544
1545
  if (nd_pmk)
1546
    wpa_snprintf_hex(nd_pmk_hex, sizeof(nd_pmk_hex), nd_pmk,
1547
         PMK_LEN);
1548
  else
1549
    nd_pmk_hex[0] = '\0';
1550
1551
  wpa_msg_global(wpa_s, MSG_INFO, NAN_PAIRING_STATUS "addr=" MACSTR
1552
           " akmp=%s cipher=%s status=%s%s%s%s%s%s%s%s%s%s%s",
1553
           MAC2STR(peer_addr),
1554
           wpa_key_mgmt_txt(akmp, WPA_PROTO_RSN),
1555
           wpa_cipher_txt(cipher),
1556
           status == WLAN_STATUS_SUCCESS ? "success" : "failure",
1557
           nd_pmk ? " nd_pmk=" : "",
1558
           nd_pmk ? nd_pmk_hex : "",
1559
           psi_locale ? " locale=" : "",
1560
           psi_locale ? psi_locale : "",
1561
           psi_vendor_name ? " vendorName=" : "",
1562
           psi_vendor_name ? psi_vendor_name : "",
1563
           psi_model_name ? " modelName=" : "",
1564
           psi_model_name ? psi_model_name : "",
1565
           psi_pairing_name ? " pairingName=" : "",
1566
           psi_pairing_name ? psi_pairing_name : "");
1567
  forced_memzero(nd_pmk_hex, sizeof(nd_pmk_hex));
1568
}
1569
1570
1571
void wpas_notify_nan_chan_evacuation(struct wpa_supplicant *wpa_s,
1572
             u8 map_id, int freq)
1573
{
1574
  wpa_msg_global(wpa_s, MSG_INFO,
1575
           NAN_CHAN_EVACUATION "map_id=%u freq=%d",
1576
           map_id, freq);
1577
}
1578
1579
1580
void wpas_notify_nan_stopped(struct wpa_supplicant *wpa_s)
1581
{
1582
  wpa_msg_global(wpa_s, MSG_INFO, NAN_STOPPED "ifname=%s",
1583
           wpa_s->ifname);
1584
}
1585
1586
#endif /* CONFIG_NAN || CONFIG_NAN_USD */
1587
1588
1589
#ifdef CONFIG_PR
1590
1591
void wpas_notify_pr_pasn_result(struct wpa_supplicant *wpa_s, u8 role,
1592
        u8 protocol_type, u8 op_class, u8 op_channel,
1593
        const char *country)
1594
{
1595
  wpa_msg_global(wpa_s, MSG_INFO, PR_PASN_RESULT
1596
           "SUCCESS role=%u protocol=%u opclass=%u channel=%u cc=%c%c",
1597
           role, protocol_type, op_class, op_channel,
1598
           country[0], country[1]);
1599
}
1600
1601
1602
void wpas_notify_pr_negotiation_started(struct wpa_supplicant *wpa_s,
1603
          const u8 *peer_addr, u8 role,
1604
          u8 protocol_type)
1605
{
1606
  wpa_msg_global(wpa_s, MSG_INFO, PR_PASN_NEGOTIATION_STARTED
1607
           "peer_addr=" MACSTR " role=%u protocol=%u",
1608
           MAC2STR(peer_addr), role, protocol_type);
1609
}
1610
1611
1612
void wpas_notify_pr_ranging_params(struct wpa_supplicant *wpa_s,
1613
           const u8 *dev_addr, const u8 *peer_addr,
1614
           u8 ranging_role, u8 protocol_type, int freq,
1615
           int channel, int bw, int format_bw)
1616
{
1617
  wpa_msg_global(wpa_s, MSG_INFO, PR_RANGING_PARAMS
1618
           "dev_addr=" MACSTR " peer_addr=" MACSTR
1619
           " role=%u protocol=%u freq=%d channel=%d bw=%d format_bw=%d",
1620
           MAC2STR(dev_addr), MAC2STR(peer_addr), ranging_role,
1621
           protocol_type, freq, channel, bw, format_bw);
1622
}
1623
1624
1625
void wpas_notify_pr_measurement_result(
1626
  struct wpa_supplicant *wpa_s,
1627
  const struct peer_measurement_result *result)
1628
{
1629
  char rtt[32] = "";
1630
  char dist[32] = "";
1631
1632
  if (result->ftm.fail) {
1633
    wpa_msg_global(wpa_s, MSG_INFO, PR_EVENT_PEER_MEASUREMENT
1634
             "addr=" MACSTR
1635
             " status=%u burst_index=%u fail=1 fail_reason=%u",
1636
             MAC2STR(result->addr), result->status,
1637
             result->ftm.burst_index,
1638
             result->ftm.fail_reason);
1639
    return;
1640
  }
1641
1642
  if (result->ftm.rtt_avg || result->ftm.has_data)
1643
    os_snprintf(rtt, sizeof(rtt), " rtt_avg=%lld",
1644
          (long long) result->ftm.rtt_avg);
1645
  if (result->ftm.dist_avg || result->ftm.has_data)
1646
    os_snprintf(dist, sizeof(dist), " dist_avg=%lld",
1647
          (long long) result->ftm.dist_avg);
1648
1649
  wpa_msg_global(wpa_s, MSG_INFO, PR_EVENT_PEER_MEASUREMENT
1650
           "addr=" MACSTR " status=%u burst_index=%u%s%s",
1651
           MAC2STR(result->addr), result->status,
1652
           result->ftm.burst_index, rtt, dist);
1653
}
1654
1655
1656
void wpas_notify_pr_ranging_complete(struct wpa_supplicant *wpa_s, u64 cookie)
1657
{
1658
  wpa_msg_global(wpa_s, MSG_INFO, PR_EVENT_RANGING_COMPLETE
1659
           "cookie=%llu", (unsigned long long) cookie);
1660
}
1661
1662
1663
void wpas_notify_pr_device_found(struct wpa_supplicant *wpa_s,
1664
         const struct pr_device *dev)
1665
{
1666
  wpa_msg_global(wpa_s, MSG_INFO, PR_PEER_FOUND
1667
           "peer_addr=" MACSTR
1668
           " pasn_type=0x%02x name=%s edca=%d edca_ista=%d edca_rsta=%d ntb=%d ntb_ista=%d ntb_rsta=%d secure_ltf=%d 6ghz=%d freq=%d dik_valid=%d",
1669
           MAC2STR(dev->pr_device_addr),
1670
           dev->pr_caps.pasn_type,
1671
           dev->pr_caps.device_name,
1672
           dev->pr_caps.edca_support,
1673
           dev->edca_caps.ista_support,
1674
           dev->edca_caps.rsta_support,
1675
           dev->pr_caps.ntb_support,
1676
           dev->ntb_caps.ista_support,
1677
           dev->ntb_caps.rsta_support,
1678
           dev->pr_caps.secure_he_ltf,
1679
           dev->pr_caps.support_6ghz,
1680
           dev->listen_freq,
1681
           dev->dik_valid);
1682
}
1683
1684
1685
void wpas_notify_pr_ranging_terminated(struct wpa_supplicant *wpa_s, int reason)
1686
{
1687
  wpa_msg_global(wpa_s, MSG_INFO, PR_RANGING_TERMINATED "reason=%d",
1688
           reason);
1689
}
1690
1691
#endif /* CONFIG_PR */