]> git.ipfire.org Git - thirdparty/hostap.git/blame - wpa_supplicant/notify.c
Call wpas_notify_network_removed() on REMOVE_NETWORK
[thirdparty/hostap.git] / wpa_supplicant / notify.c
CommitLineData
8bac466b
JM
1/*
2 * wpa_supplicant - Event notifications
207ef3fb 3 * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
8bac466b
JM
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * Alternatively, this software may be distributed under the terms of BSD
10 * license.
11 *
12 * See README and COPYING for more details.
13 */
14
f0d126d3 15#include "utils/includes.h"
8bac466b 16
f0d126d3
JM
17#include "utils/common.h"
18#include "common/wpa_ctrl.h"
8bac466b
JM
19#include "config.h"
20#include "wpa_supplicant_i.h"
21#include "wps_supplicant.h"
8ddef94b 22#include "dbus/dbus_common.h"
bacfd05f 23#include "dbus/dbus_old.h"
6d59e14c 24#include "dbus/dbus_new.h"
207ef3fb
JM
25#include "driver_i.h"
26#include "scan.h"
72044390 27#include "p2p_supplicant.h"
e29853bb 28#include "sme.h"
8bac466b
JM
29#include "notify.h"
30
dc461de4
WS
31int wpas_notify_supplicant_initialized(struct wpa_global *global)
32{
8ddef94b 33#ifdef CONFIG_DBUS
dc461de4 34 if (global->params.dbus_ctrl_interface) {
8ddef94b
JM
35 global->dbus = wpas_dbus_init(global);
36 if (global->dbus == NULL)
85d3f273 37 return -1;
dc461de4 38 }
8ddef94b 39#endif /* CONFIG_DBUS */
dc461de4
WS
40
41 return 0;
42}
43
44
45void wpas_notify_supplicant_deinitialized(struct wpa_global *global)
46{
8ddef94b
JM
47#ifdef CONFIG_DBUS
48 if (global->dbus)
49 wpas_dbus_deinit(global->dbus);
50#endif /* CONFIG_DBUS */
dc461de4
WS
51}
52
53
54int wpas_notify_iface_added(struct wpa_supplicant *wpa_s)
55{
56 if (wpas_dbus_register_iface(wpa_s))
57 return -1;
58
52bdd880 59 if (wpas_dbus_register_interface(wpa_s))
8fc2fb56
WS
60 return -1;
61
dc461de4
WS
62 return 0;
63}
64
65
dc461de4
WS
66void wpas_notify_iface_removed(struct wpa_supplicant *wpa_s)
67{
68 /* unregister interface in old DBus ctrl iface */
69 wpas_dbus_unregister_iface(wpa_s);
8fc2fb56
WS
70
71 /* unregister interface in new DBus ctrl iface */
52bdd880 72 wpas_dbus_unregister_interface(wpa_s);
dc461de4
WS
73}
74
8bac466b
JM
75
76void wpas_notify_state_changed(struct wpa_supplicant *wpa_s,
71934751
JM
77 enum wpa_states new_state,
78 enum wpa_states old_state)
8bac466b
JM
79{
80 /* notify the old DBus API */
81 wpa_supplicant_dbus_notify_state_change(wpa_s, new_state,
82 old_state);
8fc2fb56
WS
83
84 /* notify the new DBus API */
27f43d8d 85 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_STATE);
72044390
JM
86
87#ifdef CONFIG_P2P
88 if (new_state == WPA_COMPLETED)
89 wpas_p2p_notif_connected(wpa_s);
90 else if (new_state < WPA_ASSOCIATED)
91 wpas_p2p_notif_disconnected(wpa_s);
92#endif /* CONFIG_P2P */
e29853bb
BG
93
94 sme_state_changed(wpa_s);
4e2ead7a
DS
95
96#ifdef ANDROID
97 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
98 "id=%d state=%d BSSID=" MACSTR,
99 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
100 new_state, MAC2STR(wpa_s->pending_bssid));
101#endif /* ANDROID */
8bac466b
JM
102}
103
104
105void wpas_notify_network_changed(struct wpa_supplicant *wpa_s)
106{
52bdd880 107 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_NETWORK);
8bac466b
JM
108}
109
110
111void wpas_notify_ap_scan_changed(struct wpa_supplicant *wpa_s)
112{
52bdd880 113 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_AP_SCAN);
8bac466b
JM
114}
115
116
117void wpas_notify_bssid_changed(struct wpa_supplicant *wpa_s)
118{
52bdd880 119 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_BSS);
8bac466b
JM
120}
121
122
5bbf9f10
PS
123void wpas_notify_auth_changed(struct wpa_supplicant *wpa_s)
124{
125 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_AUTH_MODE);
126}
127
128
8bac466b
JM
129void wpas_notify_network_enabled_changed(struct wpa_supplicant *wpa_s,
130 struct wpa_ssid *ssid)
131{
52bdd880 132 wpas_dbus_signal_network_enabled_changed(wpa_s, ssid);
8bac466b
JM
133}
134
135
136void wpas_notify_network_selected(struct wpa_supplicant *wpa_s,
137 struct wpa_ssid *ssid)
138{
52bdd880 139 wpas_dbus_signal_network_selected(wpa_s, ssid->id);
8bac466b
JM
140}
141
142
8bac466b
JM
143void wpas_notify_scanning(struct wpa_supplicant *wpa_s)
144{
145 /* notify the old DBus API */
146 wpa_supplicant_dbus_notify_scanning(wpa_s);
27f43d8d 147
8fc2fb56 148 /* notify the new DBus API */
52bdd880 149 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_SCANNING);
8bac466b
JM
150}
151
152
153void wpas_notify_scan_done(struct wpa_supplicant *wpa_s, int success)
154{
52bdd880 155 wpas_dbus_signal_scan_done(wpa_s, success);
8bac466b
JM
156}
157
158
159void wpas_notify_scan_results(struct wpa_supplicant *wpa_s)
160{
161 /* notify the old DBus API */
162 wpa_supplicant_dbus_notify_scan_results(wpa_s);
163
164 wpas_wps_notify_scan_results(wpa_s);
165}
166
167
168void wpas_notify_wps_credential(struct wpa_supplicant *wpa_s,
169 const struct wps_credential *cred)
170{
b99b8e15 171#ifdef CONFIG_WPS
8bac466b
JM
172 /* notify the old DBus API */
173 wpa_supplicant_dbus_notify_wps_cred(wpa_s, cred);
8fc2fb56 174 /* notify the new DBus API */
52bdd880 175 wpas_dbus_signal_wps_cred(wpa_s, cred);
b99b8e15 176#endif /* CONFIG_WPS */
8bac466b
JM
177}
178
179
180void wpas_notify_wps_event_m2d(struct wpa_supplicant *wpa_s,
181 struct wps_event_m2d *m2d)
182{
b99b8e15 183#ifdef CONFIG_WPS
52bdd880 184 wpas_dbus_signal_wps_event_m2d(wpa_s, m2d);
b99b8e15 185#endif /* CONFIG_WPS */
8bac466b
JM
186}
187
188
189void wpas_notify_wps_event_fail(struct wpa_supplicant *wpa_s,
190 struct wps_event_fail *fail)
191{
b99b8e15 192#ifdef CONFIG_WPS
52bdd880 193 wpas_dbus_signal_wps_event_fail(wpa_s, fail);
b99b8e15 194#endif /* CONFIG_WPS */
8bac466b
JM
195}
196
197
198void wpas_notify_wps_event_success(struct wpa_supplicant *wpa_s)
199{
b99b8e15 200#ifdef CONFIG_WPS
52bdd880 201 wpas_dbus_signal_wps_event_success(wpa_s);
b99b8e15 202#endif /* CONFIG_WPS */
8bac466b
JM
203}
204
205
206void wpas_notify_network_added(struct wpa_supplicant *wpa_s,
207 struct wpa_ssid *ssid)
208{
c2762e41
JS
209 /*
210 * Networks objects created during any P2P activities should not be
211 * exposed out. They might/will confuse certain non-P2P aware
212 * applications since these network objects won't behave like
213 * regular ones.
214 */
215 if (wpa_s->global->p2p_group_formation != wpa_s)
216 wpas_dbus_register_network(wpa_s, ssid);
217}
218
219
220void wpas_notify_persistent_group_added(struct wpa_supplicant *wpa_s,
221 struct wpa_ssid *ssid)
222{
7a2b53b4 223#ifdef CONFIG_P2P
c2762e41 224 wpas_dbus_register_persistent_group(wpa_s, ssid);
7a2b53b4 225#endif /* CONFIG_P2P */
8bac466b
JM
226}
227
228
28550706
JS
229void wpas_notify_persistent_group_removed(struct wpa_supplicant *wpa_s,
230 struct wpa_ssid *ssid)
231{
7a2b53b4 232#ifdef CONFIG_P2P
28550706 233 wpas_dbus_unregister_persistent_group(wpa_s, ssid->id);
7a2b53b4 234#endif /* CONFIG_P2P */
28550706
JS
235}
236
237
8bac466b
JM
238void wpas_notify_network_removed(struct wpa_supplicant *wpa_s,
239 struct wpa_ssid *ssid)
240{
c2762e41
JS
241 if (wpa_s->global->p2p_group_formation != wpa_s)
242 wpas_dbus_unregister_network(wpa_s, ssid->id);
8bac466b
JM
243}
244
245
71f6e1f6 246void wpas_notify_bss_added(struct wpa_supplicant *wpa_s,
f0d126d3 247 u8 bssid[], unsigned int id)
71f6e1f6 248{
52bdd880 249 wpas_dbus_register_bss(wpa_s, bssid, id);
f0d126d3
JM
250 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_ADDED "%u " MACSTR,
251 id, MAC2STR(bssid));
71f6e1f6
WS
252}
253
254
255void wpas_notify_bss_removed(struct wpa_supplicant *wpa_s,
f0d126d3 256 u8 bssid[], unsigned int id)
71f6e1f6 257{
52bdd880 258 wpas_dbus_unregister_bss(wpa_s, bssid, id);
f0d126d3
JM
259 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_REMOVED "%u " MACSTR,
260 id, MAC2STR(bssid));
71f6e1f6
WS
261}
262
263
158c6c74
WS
264void wpas_notify_bss_freq_changed(struct wpa_supplicant *wpa_s,
265 unsigned int id)
266{
267 wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_FREQ, id);
268}
269
270
271void wpas_notify_bss_signal_changed(struct wpa_supplicant *wpa_s,
272 unsigned int id)
273{
274 wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_SIGNAL,
275 id);
276}
277
278
279void wpas_notify_bss_privacy_changed(struct wpa_supplicant *wpa_s,
280 unsigned int id)
281{
282 wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_PRIVACY,
283 id);
284}
285
286
287void wpas_notify_bss_mode_changed(struct wpa_supplicant *wpa_s,
288 unsigned int id)
289{
290 wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_MODE, id);
291}
292
293
294void wpas_notify_bss_wpaie_changed(struct wpa_supplicant *wpa_s,
295 unsigned int id)
296{
7899e2f4 297 wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_WPA, id);
158c6c74
WS
298}
299
300
301void wpas_notify_bss_rsnie_changed(struct wpa_supplicant *wpa_s,
302 unsigned int id)
303{
7899e2f4 304 wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RSN, id);
158c6c74
WS
305}
306
307
308void wpas_notify_bss_wps_changed(struct wpa_supplicant *wpa_s,
7899e2f4
WS
309 unsigned int id)
310{
311}
312
313
314void wpas_notify_bss_ies_changed(struct wpa_supplicant *wpa_s,
158c6c74
WS
315 unsigned int id)
316{
7899e2f4 317 wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_IES, id);
158c6c74
WS
318}
319
320
321void wpas_notify_bss_rates_changed(struct wpa_supplicant *wpa_s,
322 unsigned int id)
323{
324 wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RATES, id);
325}
326
327
8bac466b
JM
328void wpas_notify_blob_added(struct wpa_supplicant *wpa_s, const char *name)
329{
52bdd880 330 wpas_dbus_signal_blob_added(wpa_s, name);
8bac466b
JM
331}
332
333
334void wpas_notify_blob_removed(struct wpa_supplicant *wpa_s, const char *name)
335{
52bdd880 336 wpas_dbus_signal_blob_removed(wpa_s, name);
8bac466b
JM
337}
338
339
db9133ac 340void wpas_notify_debug_level_changed(struct wpa_global *global)
8bac466b 341{
52bdd880 342 wpas_dbus_signal_debug_level_changed(global);
db9133ac
WS
343}
344
345
346void wpas_notify_debug_timestamp_changed(struct wpa_global *global)
347{
52bdd880 348 wpas_dbus_signal_debug_timestamp_changed(global);
db9133ac
WS
349}
350
351
352void wpas_notify_debug_show_keys_changed(struct wpa_global *global)
353{
52bdd880 354 wpas_dbus_signal_debug_show_keys_changed(global);
8bac466b 355}
207ef3fb
JM
356
357
358void wpas_notify_suspend(struct wpa_global *global)
359{
360 struct wpa_supplicant *wpa_s;
361
362 os_get_time(&global->suspend_time);
363 wpa_printf(MSG_DEBUG, "System suspend notification");
364 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
365 wpa_drv_suspend(wpa_s);
366}
367
368
369void wpas_notify_resume(struct wpa_global *global)
370{
371 struct os_time now;
372 int slept;
373 struct wpa_supplicant *wpa_s;
374
375 if (global->suspend_time.sec == 0)
376 slept = -1;
377 else {
378 os_get_time(&now);
379 slept = now.sec - global->suspend_time.sec;
380 }
381 wpa_printf(MSG_DEBUG, "System resume notification (slept %d seconds)",
382 slept);
383
384 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
385 wpa_drv_resume(wpa_s);
386 if (wpa_s->wpa_state == WPA_DISCONNECTED)
387 wpa_supplicant_req_scan(wpa_s, 0, 100000);
388 }
389}
d642d2d2
JB
390
391
392#ifdef CONFIG_P2P
56eeb8f2 393
d642d2d2
JB
394void wpas_notify_p2p_device_found(struct wpa_supplicant *wpa_s,
395 const u8 *dev_addr, int new_device)
396{
9abafccc
JB
397 if (new_device) {
398 /* Create the new peer object */
399 wpas_dbus_register_peer(wpa_s, dev_addr);
400 }
401
402 /* Notify a new peer has been detected*/
403 wpas_dbus_signal_peer_device_found(wpa_s, dev_addr);
d642d2d2 404}
56eeb8f2
JB
405
406
407void wpas_notify_p2p_device_lost(struct wpa_supplicant *wpa_s,
408 const u8 *dev_addr)
409{
9abafccc
JB
410 wpas_dbus_unregister_peer(wpa_s, dev_addr);
411
412 /* Create signal on interface object*/
413 wpas_dbus_signal_peer_device_lost(wpa_s, dev_addr);
56eeb8f2
JB
414}
415
408af93e
JB
416
417void wpas_notify_p2p_group_removed(struct wpa_supplicant *wpa_s,
418 const struct wpa_ssid *ssid,
419 const char *role)
420{
9abafccc
JB
421 wpas_dbus_unregister_p2p_group(wpa_s, ssid);
422
423 wpas_dbus_signal_p2p_group_removed(wpa_s, role);
408af93e
JB
424}
425
32d1bce0
KRK
426
427void wpas_notify_p2p_go_neg_req(struct wpa_supplicant *wpa_s,
428 const u8 *src, u16 dev_passwd_id)
429{
9abafccc 430 wpas_dbus_signal_p2p_go_neg_req(wpa_s, src, dev_passwd_id);
32d1bce0
KRK
431}
432
c2641bf7
JS
433
434void wpas_notify_p2p_go_neg_completed(struct wpa_supplicant *wpa_s, int status)
435{
9abafccc 436 wpas_dbus_signal_p2p_go_neg_resp(wpa_s, status);
c2641bf7
JS
437}
438
5ccdf84f
JMB
439
440void wpas_notify_p2p_invitation_result(struct wpa_supplicant *wpa_s,
441 int status, const u8 *bssid)
442{
9abafccc 443 wpas_dbus_signal_p2p_invitation_result(wpa_s, status, bssid);
5ccdf84f
JMB
444}
445
e1653cac
KRK
446
447void wpas_notify_p2p_sd_request(struct wpa_supplicant *wpa_s,
448 int freq, const u8 *sa, u8 dialog_token,
449 u16 update_indic, const u8 *tlvs,
450 size_t tlvs_len)
451{
9abafccc
JB
452 wpas_dbus_signal_p2p_sd_request(wpa_s, freq, sa, dialog_token,
453 update_indic, tlvs, tlvs_len);
e1653cac
KRK
454}
455
43a26f60
KRK
456
457void wpas_notify_p2p_sd_response(struct wpa_supplicant *wpa_s,
458 const u8 *sa, u16 update_indic,
459 const u8 *tlvs, size_t tlvs_len)
460{
9abafccc
JB
461 wpas_dbus_signal_p2p_sd_response(wpa_s, sa, update_indic,
462 tlvs, tlvs_len);
43a26f60
KRK
463}
464
dd8a7e05
JB
465
466/**
467 * wpas_notify_p2p_provision_discovery - Notification of provision discovery
468 * @dev_addr: Who sent the request or responded to our request.
469 * @request: Will be 1 if request, 0 for response.
470 * @status: Valid only in case of response (0 in case of success)
471 * @config_methods: WPS config methods
472 * @generated_pin: PIN to be displayed in case of WPS_CONFIG_DISPLAY method
473 *
474 * This can be used to notify:
475 * - Requests or responses
476 * - Various config methods
477 * - Failure condition in case of response
478 */
479void wpas_notify_p2p_provision_discovery(struct wpa_supplicant *wpa_s,
480 const u8 *dev_addr, int request,
481 enum p2p_prov_disc_status status,
482 u16 config_methods,
483 unsigned int generated_pin)
484{
9abafccc
JB
485 wpas_dbus_signal_p2p_provision_discovery(wpa_s, dev_addr, request,
486 status, config_methods,
487 generated_pin);
dd8a7e05 488}
4b6baa2f
JMB
489
490
491void wpas_notify_p2p_group_started(struct wpa_supplicant *wpa_s,
492 struct wpa_ssid *ssid, int network_id,
493 int client)
494{
9abafccc
JB
495 /* Notify a group has been started */
496 wpas_dbus_register_p2p_group(wpa_s, ssid);
497
498 wpas_dbus_signal_p2p_group_started(wpa_s, ssid, client, network_id);
4b6baa2f 499}
3734552f
JS
500
501
502void wpas_notify_p2p_wps_failed(struct wpa_supplicant *wpa_s,
503 struct wps_event_fail *fail)
504{
505 wpas_dbus_signal_p2p_wps_failed(wpa_s, fail);
506}
507
d642d2d2 508#endif /* CONFIG_P2P */
d8a43924
JB
509
510
511static void wpas_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s,
512 const u8 *sta)
513{
692cb226 514#ifdef CONFIG_P2P
9abafccc
JB
515 /*
516 * Register a group member object corresponding to this peer and
517 * emit a PeerJoined signal. This will check if it really is a
518 * P2P group.
519 */
520 wpas_dbus_register_p2p_groupmember(wpa_s, sta);
521
522 /*
523 * Create 'peer-joined' signal on group object -- will also
524 * check P2P itself.
525 */
526 wpas_dbus_signal_p2p_peer_joined(wpa_s, sta);
692cb226 527#endif /* CONFIG_P2P */
d8a43924
JB
528}
529
530
531static void wpas_notify_ap_sta_deauthorized(struct wpa_supplicant *wpa_s,
532 const u8 *sta)
533{
692cb226 534#ifdef CONFIG_P2P
9abafccc
JB
535 /*
536 * Unregister a group member object corresponding to this peer
537 * if this is a P2P group.
538 */
539 wpas_dbus_unregister_p2p_groupmember(wpa_s, sta);
540
541 /*
542 * Create 'peer-disconnected' signal on group object if this
543 * is a P2P group.
544 */
545 wpas_dbus_signal_p2p_peer_disconnected(wpa_s, sta);
692cb226 546#endif /* CONFIG_P2P */
d8a43924
JB
547}
548
549
550void wpas_notify_sta_authorized(struct wpa_supplicant *wpa_s,
551 const u8 *mac_addr, int authorized)
552{
553 if (authorized)
554 wpas_notify_ap_sta_authorized(wpa_s, mac_addr);
555 else
556 wpas_notify_ap_sta_deauthorized(wpa_s, mac_addr);
557}
ade74830
MC
558
559
560void wpas_notify_certification(struct wpa_supplicant *wpa_s, int depth,
561 const char *subject, const char *cert_hash,
562 const struct wpabuf *cert)
563{
4f525d8e
JM
564 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_EAP_PEER_CERT
565 "depth=%d subject='%s'%s%s",
566 depth, subject,
567 cert_hash ? " hash=" : "",
568 cert_hash ? cert_hash : "");
569
570 if (cert) {
571 char *cert_hex;
572 size_t len = wpabuf_len(cert) * 2 + 1;
573 cert_hex = os_malloc(len);
574 if (cert_hex) {
575 wpa_snprintf_hex(cert_hex, len, wpabuf_head(cert),
576 wpabuf_len(cert));
577 wpa_msg_ctrl(wpa_s, MSG_INFO,
578 WPA_EVENT_EAP_PEER_CERT
579 "depth=%d subject='%s' cert=%s",
580 depth, subject, cert_hex);
581 os_free(cert_hex);
582 }
583 }
584
ade74830
MC
585 /* notify the old DBus API */
586 wpa_supplicant_dbus_notify_certification(wpa_s, depth, subject,
587 cert_hash, cert);
588 /* notify the new DBus API */
589 wpas_dbus_signal_certification(wpa_s, depth, subject, cert_hash, cert);
590}