2 * wpa_supplicant - Event notifications
3 * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "common/wpa_ctrl.h"
14 #include "wpa_supplicant_i.h"
15 #include "wps_supplicant.h"
16 #include "dbus/dbus_common.h"
17 #include "dbus/dbus_old.h"
18 #include "dbus/dbus_new.h"
19 #include "rsn_supp/wpa.h"
22 #include "p2p_supplicant.h"
26 int wpas_notify_supplicant_initialized(struct wpa_global
*global
)
29 if (global
->params
.dbus_ctrl_interface
) {
30 global
->dbus
= wpas_dbus_init(global
);
31 if (global
->dbus
== NULL
)
34 #endif /* CONFIG_DBUS */
40 void wpas_notify_supplicant_deinitialized(struct wpa_global
*global
)
44 wpas_dbus_deinit(global
->dbus
);
45 #endif /* CONFIG_DBUS */
49 int wpas_notify_iface_added(struct wpa_supplicant
*wpa_s
)
51 if (wpas_dbus_register_iface(wpa_s
))
54 if (wpas_dbus_register_interface(wpa_s
))
61 void wpas_notify_iface_removed(struct wpa_supplicant
*wpa_s
)
63 /* unregister interface in old DBus ctrl iface */
64 wpas_dbus_unregister_iface(wpa_s
);
66 /* unregister interface in new DBus ctrl iface */
67 wpas_dbus_unregister_interface(wpa_s
);
71 void wpas_notify_state_changed(struct wpa_supplicant
*wpa_s
,
72 enum wpa_states new_state
,
73 enum wpa_states old_state
)
75 /* notify the old DBus API */
76 wpa_supplicant_dbus_notify_state_change(wpa_s
, new_state
,
79 /* notify the new DBus API */
80 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_STATE
);
82 if (new_state
== WPA_COMPLETED
)
83 wpas_p2p_notif_connected(wpa_s
);
84 else if (old_state
>= WPA_ASSOCIATED
&& new_state
< WPA_ASSOCIATED
)
85 wpas_p2p_notif_disconnected(wpa_s
);
87 sme_state_changed(wpa_s
);
90 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
91 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
92 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
94 MAC2STR(wpa_s
->bssid
),
95 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
96 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
97 wpa_s
->current_ssid
->ssid_len
) : "");
102 void wpas_notify_disconnect_reason(struct wpa_supplicant
*wpa_s
)
104 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_DISCONNECT_REASON
);
108 void wpas_notify_network_changed(struct wpa_supplicant
*wpa_s
)
110 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_CURRENT_NETWORK
);
114 void wpas_notify_ap_scan_changed(struct wpa_supplicant
*wpa_s
)
116 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_AP_SCAN
);
120 void wpas_notify_bssid_changed(struct wpa_supplicant
*wpa_s
)
122 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_CURRENT_BSS
);
126 void wpas_notify_auth_changed(struct wpa_supplicant
*wpa_s
)
128 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_CURRENT_AUTH_MODE
);
132 void wpas_notify_network_enabled_changed(struct wpa_supplicant
*wpa_s
,
133 struct wpa_ssid
*ssid
)
135 wpas_dbus_signal_network_enabled_changed(wpa_s
, ssid
);
139 void wpas_notify_network_selected(struct wpa_supplicant
*wpa_s
,
140 struct wpa_ssid
*ssid
)
142 wpas_dbus_signal_network_selected(wpa_s
, ssid
->id
);
146 void wpas_notify_network_request(struct wpa_supplicant
*wpa_s
,
147 struct wpa_ssid
*ssid
,
148 enum wpa_ctrl_req_type rtype
,
149 const char *default_txt
)
151 wpas_dbus_signal_network_request(wpa_s
, ssid
, rtype
, default_txt
);
155 void wpas_notify_scanning(struct wpa_supplicant
*wpa_s
)
157 /* notify the old DBus API */
158 wpa_supplicant_dbus_notify_scanning(wpa_s
);
160 /* notify the new DBus API */
161 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_SCANNING
);
165 void wpas_notify_scan_done(struct wpa_supplicant
*wpa_s
, int success
)
167 wpas_dbus_signal_scan_done(wpa_s
, success
);
171 void wpas_notify_scan_results(struct wpa_supplicant
*wpa_s
)
173 /* notify the old DBus API */
174 wpa_supplicant_dbus_notify_scan_results(wpa_s
);
176 wpas_wps_notify_scan_results(wpa_s
);
180 void wpas_notify_wps_credential(struct wpa_supplicant
*wpa_s
,
181 const struct wps_credential
*cred
)
184 /* notify the old DBus API */
185 wpa_supplicant_dbus_notify_wps_cred(wpa_s
, cred
);
186 /* notify the new DBus API */
187 wpas_dbus_signal_wps_cred(wpa_s
, cred
);
188 #endif /* CONFIG_WPS */
192 void wpas_notify_wps_event_m2d(struct wpa_supplicant
*wpa_s
,
193 struct wps_event_m2d
*m2d
)
196 wpas_dbus_signal_wps_event_m2d(wpa_s
, m2d
);
197 #endif /* CONFIG_WPS */
201 void wpas_notify_wps_event_fail(struct wpa_supplicant
*wpa_s
,
202 struct wps_event_fail
*fail
)
205 wpas_dbus_signal_wps_event_fail(wpa_s
, fail
);
206 #endif /* CONFIG_WPS */
210 void wpas_notify_wps_event_success(struct wpa_supplicant
*wpa_s
)
213 wpas_dbus_signal_wps_event_success(wpa_s
);
214 #endif /* CONFIG_WPS */
218 void wpas_notify_network_added(struct wpa_supplicant
*wpa_s
,
219 struct wpa_ssid
*ssid
)
222 * Networks objects created during any P2P activities should not be
223 * exposed out. They might/will confuse certain non-P2P aware
224 * applications since these network objects won't behave like
227 if (!ssid
->p2p_group
&& wpa_s
->global
->p2p_group_formation
!= wpa_s
)
228 wpas_dbus_register_network(wpa_s
, ssid
);
232 void wpas_notify_persistent_group_added(struct wpa_supplicant
*wpa_s
,
233 struct wpa_ssid
*ssid
)
236 wpas_dbus_register_persistent_group(wpa_s
, ssid
);
237 #endif /* CONFIG_P2P */
241 void wpas_notify_persistent_group_removed(struct wpa_supplicant
*wpa_s
,
242 struct wpa_ssid
*ssid
)
245 wpas_dbus_unregister_persistent_group(wpa_s
, ssid
->id
);
246 #endif /* CONFIG_P2P */
250 void wpas_notify_network_removed(struct wpa_supplicant
*wpa_s
,
251 struct wpa_ssid
*ssid
)
253 if (wpa_s
->next_ssid
== ssid
)
254 wpa_s
->next_ssid
= NULL
;
256 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
257 if (!ssid
->p2p_group
&& wpa_s
->global
->p2p_group_formation
!= wpa_s
)
258 wpas_dbus_unregister_network(wpa_s
, ssid
->id
);
259 wpas_p2p_network_removed(wpa_s
, ssid
);
263 void wpas_notify_bss_added(struct wpa_supplicant
*wpa_s
,
264 u8 bssid
[], unsigned int id
)
266 wpas_dbus_register_bss(wpa_s
, bssid
, id
);
267 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_BSS_ADDED
"%u " MACSTR
,
272 void wpas_notify_bss_removed(struct wpa_supplicant
*wpa_s
,
273 u8 bssid
[], unsigned int id
)
275 wpas_dbus_unregister_bss(wpa_s
, bssid
, id
);
276 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_BSS_REMOVED
"%u " MACSTR
,
281 void wpas_notify_bss_freq_changed(struct wpa_supplicant
*wpa_s
,
284 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_FREQ
, id
);
288 void wpas_notify_bss_signal_changed(struct wpa_supplicant
*wpa_s
,
291 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_SIGNAL
,
296 void wpas_notify_bss_privacy_changed(struct wpa_supplicant
*wpa_s
,
299 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_PRIVACY
,
304 void wpas_notify_bss_mode_changed(struct wpa_supplicant
*wpa_s
,
307 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_MODE
, id
);
311 void wpas_notify_bss_wpaie_changed(struct wpa_supplicant
*wpa_s
,
314 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_WPA
, id
);
318 void wpas_notify_bss_rsnie_changed(struct wpa_supplicant
*wpa_s
,
321 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_RSN
, id
);
325 void wpas_notify_bss_wps_changed(struct wpa_supplicant
*wpa_s
,
329 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_WPS
, id
);
330 #endif /* CONFIG_WPS */
334 void wpas_notify_bss_ies_changed(struct wpa_supplicant
*wpa_s
,
337 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_IES
, id
);
341 void wpas_notify_bss_rates_changed(struct wpa_supplicant
*wpa_s
,
344 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_RATES
, id
);
348 void wpas_notify_bss_seen(struct wpa_supplicant
*wpa_s
, unsigned int id
)
350 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_AGE
, id
);
354 void wpas_notify_blob_added(struct wpa_supplicant
*wpa_s
, const char *name
)
356 wpas_dbus_signal_blob_added(wpa_s
, name
);
360 void wpas_notify_blob_removed(struct wpa_supplicant
*wpa_s
, const char *name
)
362 wpas_dbus_signal_blob_removed(wpa_s
, name
);
366 void wpas_notify_debug_level_changed(struct wpa_global
*global
)
368 wpas_dbus_signal_debug_level_changed(global
);
372 void wpas_notify_debug_timestamp_changed(struct wpa_global
*global
)
374 wpas_dbus_signal_debug_timestamp_changed(global
);
378 void wpas_notify_debug_show_keys_changed(struct wpa_global
*global
)
380 wpas_dbus_signal_debug_show_keys_changed(global
);
384 void wpas_notify_suspend(struct wpa_global
*global
)
386 struct wpa_supplicant
*wpa_s
;
388 os_get_time(&global
->suspend_time
);
389 wpa_printf(MSG_DEBUG
, "System suspend notification");
390 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
)
391 wpa_drv_suspend(wpa_s
);
395 void wpas_notify_resume(struct wpa_global
*global
)
399 struct wpa_supplicant
*wpa_s
;
401 if (global
->suspend_time
.sec
== 0)
405 slept
= now
.sec
- global
->suspend_time
.sec
;
407 wpa_printf(MSG_DEBUG
, "System resume notification (slept %d seconds)",
410 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
411 wpa_drv_resume(wpa_s
);
412 if (wpa_s
->wpa_state
== WPA_DISCONNECTED
)
413 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
420 void wpas_notify_p2p_device_found(struct wpa_supplicant
*wpa_s
,
421 const u8
*dev_addr
, int new_device
)
424 /* Create the new peer object */
425 wpas_dbus_register_peer(wpa_s
, dev_addr
);
428 /* Notify a new peer has been detected*/
429 wpas_dbus_signal_peer_device_found(wpa_s
, dev_addr
);
433 void wpas_notify_p2p_device_lost(struct wpa_supplicant
*wpa_s
,
436 wpas_dbus_unregister_peer(wpa_s
, dev_addr
);
438 /* Create signal on interface object*/
439 wpas_dbus_signal_peer_device_lost(wpa_s
, dev_addr
);
443 void wpas_notify_p2p_group_removed(struct wpa_supplicant
*wpa_s
,
444 const struct wpa_ssid
*ssid
,
447 wpas_dbus_signal_p2p_group_removed(wpa_s
, role
);
449 wpas_dbus_unregister_p2p_group(wpa_s
, ssid
);
453 void wpas_notify_p2p_go_neg_req(struct wpa_supplicant
*wpa_s
,
454 const u8
*src
, u16 dev_passwd_id
)
456 wpas_dbus_signal_p2p_go_neg_req(wpa_s
, src
, dev_passwd_id
);
460 void wpas_notify_p2p_go_neg_completed(struct wpa_supplicant
*wpa_s
,
461 struct p2p_go_neg_results
*res
)
463 wpas_dbus_signal_p2p_go_neg_resp(wpa_s
, res
);
467 void wpas_notify_p2p_invitation_result(struct wpa_supplicant
*wpa_s
,
468 int status
, const u8
*bssid
)
470 wpas_dbus_signal_p2p_invitation_result(wpa_s
, status
, bssid
);
474 void wpas_notify_p2p_sd_request(struct wpa_supplicant
*wpa_s
,
475 int freq
, const u8
*sa
, u8 dialog_token
,
476 u16 update_indic
, const u8
*tlvs
,
479 wpas_dbus_signal_p2p_sd_request(wpa_s
, freq
, sa
, dialog_token
,
480 update_indic
, tlvs
, tlvs_len
);
484 void wpas_notify_p2p_sd_response(struct wpa_supplicant
*wpa_s
,
485 const u8
*sa
, u16 update_indic
,
486 const u8
*tlvs
, size_t tlvs_len
)
488 wpas_dbus_signal_p2p_sd_response(wpa_s
, sa
, update_indic
,
494 * wpas_notify_p2p_provision_discovery - Notification of provision discovery
495 * @dev_addr: Who sent the request or responded to our request.
496 * @request: Will be 1 if request, 0 for response.
497 * @status: Valid only in case of response (0 in case of success)
498 * @config_methods: WPS config methods
499 * @generated_pin: PIN to be displayed in case of WPS_CONFIG_DISPLAY method
501 * This can be used to notify:
502 * - Requests or responses
503 * - Various config methods
504 * - Failure condition in case of response
506 void wpas_notify_p2p_provision_discovery(struct wpa_supplicant
*wpa_s
,
507 const u8
*dev_addr
, int request
,
508 enum p2p_prov_disc_status status
,
510 unsigned int generated_pin
)
512 wpas_dbus_signal_p2p_provision_discovery(wpa_s
, dev_addr
, request
,
513 status
, config_methods
,
518 void wpas_notify_p2p_group_started(struct wpa_supplicant
*wpa_s
,
519 struct wpa_ssid
*ssid
, int network_id
,
522 /* Notify a group has been started */
523 wpas_dbus_register_p2p_group(wpa_s
, ssid
);
525 wpas_dbus_signal_p2p_group_started(wpa_s
, ssid
, client
, network_id
);
529 void wpas_notify_p2p_wps_failed(struct wpa_supplicant
*wpa_s
,
530 struct wps_event_fail
*fail
)
532 wpas_dbus_signal_p2p_wps_failed(wpa_s
, fail
);
535 #endif /* CONFIG_P2P */
538 static void wpas_notify_ap_sta_authorized(struct wpa_supplicant
*wpa_s
,
540 const u8
*p2p_dev_addr
)
543 wpas_p2p_notify_ap_sta_authorized(wpa_s
, p2p_dev_addr
);
546 * Create 'peer-joined' signal on group object -- will also
549 wpas_dbus_signal_p2p_peer_joined(wpa_s
, p2p_dev_addr
);
550 #endif /* CONFIG_P2P */
552 /* Notify listeners a new station has been authorized */
553 wpas_dbus_signal_sta_authorized(wpa_s
, sta
);
557 static void wpas_notify_ap_sta_deauthorized(struct wpa_supplicant
*wpa_s
,
559 const u8
*p2p_dev_addr
)
563 * Create 'peer-disconnected' signal on group object if this
566 wpas_dbus_signal_p2p_peer_disconnected(wpa_s
, p2p_dev_addr
);
567 #endif /* CONFIG_P2P */
569 /* Notify listeners a station has been deauthorized */
570 wpas_dbus_signal_sta_deauthorized(wpa_s
, sta
);
574 void wpas_notify_sta_authorized(struct wpa_supplicant
*wpa_s
,
575 const u8
*mac_addr
, int authorized
,
576 const u8
*p2p_dev_addr
)
579 wpas_notify_ap_sta_authorized(wpa_s
, mac_addr
, p2p_dev_addr
);
581 wpas_notify_ap_sta_deauthorized(wpa_s
, mac_addr
, p2p_dev_addr
);
585 void wpas_notify_certification(struct wpa_supplicant
*wpa_s
, int depth
,
586 const char *subject
, const char *cert_hash
,
587 const struct wpabuf
*cert
)
589 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_EAP_PEER_CERT
590 "depth=%d subject='%s'%s%s",
592 cert_hash
? " hash=" : "",
593 cert_hash
? cert_hash
: "");
597 size_t len
= wpabuf_len(cert
) * 2 + 1;
598 cert_hex
= os_malloc(len
);
600 wpa_snprintf_hex(cert_hex
, len
, wpabuf_head(cert
),
602 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
603 WPA_EVENT_EAP_PEER_CERT
604 "depth=%d subject='%s' cert=%s",
605 depth
, subject
, cert_hex
);
610 /* notify the old DBus API */
611 wpa_supplicant_dbus_notify_certification(wpa_s
, depth
, subject
,
613 /* notify the new DBus API */
614 wpas_dbus_signal_certification(wpa_s
, depth
, subject
, cert_hash
, cert
);
618 void wpas_notify_preq(struct wpa_supplicant
*wpa_s
,
619 const u8
*addr
, const u8
*dst
, const u8
*bssid
,
620 const u8
*ie
, size_t ie_len
, u32 ssi_signal
)
623 wpas_dbus_signal_preq(wpa_s
, addr
, dst
, bssid
, ie
, ie_len
, ssi_signal
);
624 #endif /* CONFIG_AP */
628 void wpas_notify_eap_status(struct wpa_supplicant
*wpa_s
, const char *status
,
629 const char *parameter
)
631 wpas_dbus_signal_eap_status(wpa_s
, status
, parameter
);
632 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_EAP_STATUS
633 "status='%s' parameter='%s'",
638 void wpas_notify_network_bssid_set_changed(struct wpa_supplicant
*wpa_s
,
639 struct wpa_ssid
*ssid
)
641 if (wpa_s
->current_ssid
!= ssid
)
644 wpa_dbg(wpa_s
, MSG_DEBUG
,
645 "Network bssid config changed for the current network - within-ESS roaming %s",
646 ssid
->bssid_set
? "disabled" : "enabled");
648 wpa_drv_roaming(wpa_s
, !ssid
->bssid_set
,
649 ssid
->bssid_set
? ssid
->bssid
: NULL
);