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
)
54 if (wpas_dbus_register_iface(wpa_s
))
57 if (wpas_dbus_register_interface(wpa_s
))
64 void wpas_notify_iface_removed(struct wpa_supplicant
*wpa_s
)
69 /* unregister interface in old DBus ctrl iface */
70 wpas_dbus_unregister_iface(wpa_s
);
72 /* unregister interface in new DBus ctrl iface */
73 wpas_dbus_unregister_interface(wpa_s
);
77 void wpas_notify_state_changed(struct wpa_supplicant
*wpa_s
,
78 enum wpa_states new_state
,
79 enum wpa_states old_state
)
84 /* notify the old DBus API */
85 wpa_supplicant_dbus_notify_state_change(wpa_s
, new_state
,
88 /* notify the new DBus API */
89 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_STATE
);
91 if (new_state
== WPA_COMPLETED
)
92 wpas_p2p_notif_connected(wpa_s
);
93 else if (old_state
>= WPA_ASSOCIATED
&& new_state
< WPA_ASSOCIATED
)
94 wpas_p2p_notif_disconnected(wpa_s
);
96 sme_state_changed(wpa_s
);
99 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
100 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
101 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
103 MAC2STR(wpa_s
->bssid
),
104 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
105 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
106 wpa_s
->current_ssid
->ssid_len
) : "");
111 void wpas_notify_disconnect_reason(struct wpa_supplicant
*wpa_s
)
116 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_DISCONNECT_REASON
);
120 void wpas_notify_network_changed(struct wpa_supplicant
*wpa_s
)
125 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_CURRENT_NETWORK
);
129 void wpas_notify_ap_scan_changed(struct wpa_supplicant
*wpa_s
)
134 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_AP_SCAN
);
138 void wpas_notify_bssid_changed(struct wpa_supplicant
*wpa_s
)
143 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_CURRENT_BSS
);
147 void wpas_notify_auth_changed(struct wpa_supplicant
*wpa_s
)
152 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_CURRENT_AUTH_MODE
);
156 void wpas_notify_network_enabled_changed(struct wpa_supplicant
*wpa_s
,
157 struct wpa_ssid
*ssid
)
162 wpas_dbus_signal_network_enabled_changed(wpa_s
, ssid
);
166 void wpas_notify_network_selected(struct wpa_supplicant
*wpa_s
,
167 struct wpa_ssid
*ssid
)
172 wpas_dbus_signal_network_selected(wpa_s
, ssid
->id
);
176 void wpas_notify_network_request(struct wpa_supplicant
*wpa_s
,
177 struct wpa_ssid
*ssid
,
178 enum wpa_ctrl_req_type rtype
,
179 const char *default_txt
)
184 wpas_dbus_signal_network_request(wpa_s
, ssid
, rtype
, default_txt
);
188 void wpas_notify_scanning(struct wpa_supplicant
*wpa_s
)
193 /* notify the old DBus API */
194 wpa_supplicant_dbus_notify_scanning(wpa_s
);
196 /* notify the new DBus API */
197 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_SCANNING
);
201 void wpas_notify_scan_done(struct wpa_supplicant
*wpa_s
, int success
)
206 wpas_dbus_signal_scan_done(wpa_s
, success
);
210 void wpas_notify_scan_results(struct wpa_supplicant
*wpa_s
)
215 /* notify the old DBus API */
216 wpa_supplicant_dbus_notify_scan_results(wpa_s
);
218 wpas_wps_notify_scan_results(wpa_s
);
222 void wpas_notify_wps_credential(struct wpa_supplicant
*wpa_s
,
223 const struct wps_credential
*cred
)
229 /* notify the old DBus API */
230 wpa_supplicant_dbus_notify_wps_cred(wpa_s
, cred
);
231 /* notify the new DBus API */
232 wpas_dbus_signal_wps_cred(wpa_s
, cred
);
233 #endif /* CONFIG_WPS */
237 void wpas_notify_wps_event_m2d(struct wpa_supplicant
*wpa_s
,
238 struct wps_event_m2d
*m2d
)
244 wpas_dbus_signal_wps_event_m2d(wpa_s
, m2d
);
245 #endif /* CONFIG_WPS */
249 void wpas_notify_wps_event_fail(struct wpa_supplicant
*wpa_s
,
250 struct wps_event_fail
*fail
)
256 wpas_dbus_signal_wps_event_fail(wpa_s
, fail
);
257 #endif /* CONFIG_WPS */
261 void wpas_notify_wps_event_success(struct wpa_supplicant
*wpa_s
)
267 wpas_dbus_signal_wps_event_success(wpa_s
);
268 #endif /* CONFIG_WPS */
272 void wpas_notify_network_added(struct wpa_supplicant
*wpa_s
,
273 struct wpa_ssid
*ssid
)
279 * Networks objects created during any P2P activities should not be
280 * exposed out. They might/will confuse certain non-P2P aware
281 * applications since these network objects won't behave like
284 if (!ssid
->p2p_group
&& wpa_s
->global
->p2p_group_formation
!= wpa_s
)
285 wpas_dbus_register_network(wpa_s
, ssid
);
289 void wpas_notify_persistent_group_added(struct wpa_supplicant
*wpa_s
,
290 struct wpa_ssid
*ssid
)
293 wpas_dbus_register_persistent_group(wpa_s
, ssid
);
294 #endif /* CONFIG_P2P */
298 void wpas_notify_persistent_group_removed(struct wpa_supplicant
*wpa_s
,
299 struct wpa_ssid
*ssid
)
302 wpas_dbus_unregister_persistent_group(wpa_s
, ssid
->id
);
303 #endif /* CONFIG_P2P */
307 void wpas_notify_network_removed(struct wpa_supplicant
*wpa_s
,
308 struct wpa_ssid
*ssid
)
313 if (wpa_s
->next_ssid
== ssid
)
314 wpa_s
->next_ssid
= NULL
;
316 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
317 if (!ssid
->p2p_group
&& wpa_s
->global
->p2p_group_formation
!= wpa_s
)
318 wpas_dbus_unregister_network(wpa_s
, ssid
->id
);
319 wpas_p2p_network_removed(wpa_s
, ssid
);
323 void wpas_notify_bss_added(struct wpa_supplicant
*wpa_s
,
324 u8 bssid
[], unsigned int id
)
329 wpas_dbus_register_bss(wpa_s
, bssid
, id
);
330 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_BSS_ADDED
"%u " MACSTR
,
335 void wpas_notify_bss_removed(struct wpa_supplicant
*wpa_s
,
336 u8 bssid
[], unsigned int id
)
341 wpas_dbus_unregister_bss(wpa_s
, bssid
, id
);
342 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_BSS_REMOVED
"%u " MACSTR
,
347 void wpas_notify_bss_freq_changed(struct wpa_supplicant
*wpa_s
,
353 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_FREQ
, id
);
357 void wpas_notify_bss_signal_changed(struct wpa_supplicant
*wpa_s
,
363 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_SIGNAL
,
368 void wpas_notify_bss_privacy_changed(struct wpa_supplicant
*wpa_s
,
374 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_PRIVACY
,
379 void wpas_notify_bss_mode_changed(struct wpa_supplicant
*wpa_s
,
385 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_MODE
, id
);
389 void wpas_notify_bss_wpaie_changed(struct wpa_supplicant
*wpa_s
,
395 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_WPA
, id
);
399 void wpas_notify_bss_rsnie_changed(struct wpa_supplicant
*wpa_s
,
405 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_RSN
, id
);
409 void wpas_notify_bss_wps_changed(struct wpa_supplicant
*wpa_s
,
416 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_WPS
, id
);
417 #endif /* CONFIG_WPS */
421 void wpas_notify_bss_ies_changed(struct wpa_supplicant
*wpa_s
,
427 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_IES
, id
);
431 void wpas_notify_bss_rates_changed(struct wpa_supplicant
*wpa_s
,
437 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_RATES
, id
);
441 void wpas_notify_bss_seen(struct wpa_supplicant
*wpa_s
, unsigned int id
)
446 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_AGE
, id
);
450 void wpas_notify_blob_added(struct wpa_supplicant
*wpa_s
, const char *name
)
455 wpas_dbus_signal_blob_added(wpa_s
, name
);
459 void wpas_notify_blob_removed(struct wpa_supplicant
*wpa_s
, const char *name
)
464 wpas_dbus_signal_blob_removed(wpa_s
, name
);
468 void wpas_notify_debug_level_changed(struct wpa_global
*global
)
470 wpas_dbus_signal_debug_level_changed(global
);
474 void wpas_notify_debug_timestamp_changed(struct wpa_global
*global
)
476 wpas_dbus_signal_debug_timestamp_changed(global
);
480 void wpas_notify_debug_show_keys_changed(struct wpa_global
*global
)
482 wpas_dbus_signal_debug_show_keys_changed(global
);
486 void wpas_notify_suspend(struct wpa_global
*global
)
488 struct wpa_supplicant
*wpa_s
;
490 os_get_time(&global
->suspend_time
);
491 wpa_printf(MSG_DEBUG
, "System suspend notification");
492 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
)
493 wpa_drv_suspend(wpa_s
);
497 void wpas_notify_resume(struct wpa_global
*global
)
501 struct wpa_supplicant
*wpa_s
;
503 if (global
->suspend_time
.sec
== 0)
507 slept
= now
.sec
- global
->suspend_time
.sec
;
509 wpa_printf(MSG_DEBUG
, "System resume notification (slept %d seconds)",
512 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
513 wpa_drv_resume(wpa_s
);
514 if (wpa_s
->wpa_state
== WPA_DISCONNECTED
)
515 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
522 void wpas_notify_p2p_device_found(struct wpa_supplicant
*wpa_s
,
523 const u8
*dev_addr
, int new_device
)
526 /* Create the new peer object */
527 wpas_dbus_register_peer(wpa_s
, dev_addr
);
530 /* Notify a new peer has been detected*/
531 wpas_dbus_signal_peer_device_found(wpa_s
, dev_addr
);
535 void wpas_notify_p2p_device_lost(struct wpa_supplicant
*wpa_s
,
538 wpas_dbus_unregister_peer(wpa_s
, dev_addr
);
540 /* Create signal on interface object*/
541 wpas_dbus_signal_peer_device_lost(wpa_s
, dev_addr
);
545 void wpas_notify_p2p_group_removed(struct wpa_supplicant
*wpa_s
,
546 const struct wpa_ssid
*ssid
,
549 wpas_dbus_signal_p2p_group_removed(wpa_s
, role
);
551 wpas_dbus_unregister_p2p_group(wpa_s
, ssid
);
555 void wpas_notify_p2p_go_neg_req(struct wpa_supplicant
*wpa_s
,
556 const u8
*src
, u16 dev_passwd_id
)
558 wpas_dbus_signal_p2p_go_neg_req(wpa_s
, src
, dev_passwd_id
);
562 void wpas_notify_p2p_go_neg_completed(struct wpa_supplicant
*wpa_s
,
563 struct p2p_go_neg_results
*res
)
565 wpas_dbus_signal_p2p_go_neg_resp(wpa_s
, res
);
569 void wpas_notify_p2p_invitation_result(struct wpa_supplicant
*wpa_s
,
570 int status
, const u8
*bssid
)
572 wpas_dbus_signal_p2p_invitation_result(wpa_s
, status
, bssid
);
576 void wpas_notify_p2p_sd_request(struct wpa_supplicant
*wpa_s
,
577 int freq
, const u8
*sa
, u8 dialog_token
,
578 u16 update_indic
, const u8
*tlvs
,
581 wpas_dbus_signal_p2p_sd_request(wpa_s
, freq
, sa
, dialog_token
,
582 update_indic
, tlvs
, tlvs_len
);
586 void wpas_notify_p2p_sd_response(struct wpa_supplicant
*wpa_s
,
587 const u8
*sa
, u16 update_indic
,
588 const u8
*tlvs
, size_t tlvs_len
)
590 wpas_dbus_signal_p2p_sd_response(wpa_s
, sa
, update_indic
,
596 * wpas_notify_p2p_provision_discovery - Notification of provision discovery
597 * @dev_addr: Who sent the request or responded to our request.
598 * @request: Will be 1 if request, 0 for response.
599 * @status: Valid only in case of response (0 in case of success)
600 * @config_methods: WPS config methods
601 * @generated_pin: PIN to be displayed in case of WPS_CONFIG_DISPLAY method
603 * This can be used to notify:
604 * - Requests or responses
605 * - Various config methods
606 * - Failure condition in case of response
608 void wpas_notify_p2p_provision_discovery(struct wpa_supplicant
*wpa_s
,
609 const u8
*dev_addr
, int request
,
610 enum p2p_prov_disc_status status
,
612 unsigned int generated_pin
)
614 wpas_dbus_signal_p2p_provision_discovery(wpa_s
, dev_addr
, request
,
615 status
, config_methods
,
620 void wpas_notify_p2p_group_started(struct wpa_supplicant
*wpa_s
,
621 struct wpa_ssid
*ssid
, int network_id
,
624 /* Notify a group has been started */
625 wpas_dbus_register_p2p_group(wpa_s
, ssid
);
627 wpas_dbus_signal_p2p_group_started(wpa_s
, ssid
, client
, network_id
);
631 void wpas_notify_p2p_wps_failed(struct wpa_supplicant
*wpa_s
,
632 struct wps_event_fail
*fail
)
634 wpas_dbus_signal_p2p_wps_failed(wpa_s
, fail
);
637 #endif /* CONFIG_P2P */
640 static void wpas_notify_ap_sta_authorized(struct wpa_supplicant
*wpa_s
,
642 const u8
*p2p_dev_addr
)
645 wpas_p2p_notify_ap_sta_authorized(wpa_s
, p2p_dev_addr
);
648 * Create 'peer-joined' signal on group object -- will also
651 wpas_dbus_signal_p2p_peer_joined(wpa_s
, p2p_dev_addr
);
652 #endif /* CONFIG_P2P */
654 /* Notify listeners a new station has been authorized */
655 wpas_dbus_signal_sta_authorized(wpa_s
, sta
);
659 static void wpas_notify_ap_sta_deauthorized(struct wpa_supplicant
*wpa_s
,
661 const u8
*p2p_dev_addr
)
665 * Create 'peer-disconnected' signal on group object if this
668 wpas_dbus_signal_p2p_peer_disconnected(wpa_s
, p2p_dev_addr
);
669 #endif /* CONFIG_P2P */
671 /* Notify listeners a station has been deauthorized */
672 wpas_dbus_signal_sta_deauthorized(wpa_s
, sta
);
676 void wpas_notify_sta_authorized(struct wpa_supplicant
*wpa_s
,
677 const u8
*mac_addr
, int authorized
,
678 const u8
*p2p_dev_addr
)
681 wpas_notify_ap_sta_authorized(wpa_s
, mac_addr
, p2p_dev_addr
);
683 wpas_notify_ap_sta_deauthorized(wpa_s
, mac_addr
, p2p_dev_addr
);
687 void wpas_notify_certification(struct wpa_supplicant
*wpa_s
, int depth
,
688 const char *subject
, const char *cert_hash
,
689 const struct wpabuf
*cert
)
691 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_EAP_PEER_CERT
692 "depth=%d subject='%s'%s%s",
694 cert_hash
? " hash=" : "",
695 cert_hash
? cert_hash
: "");
699 size_t len
= wpabuf_len(cert
) * 2 + 1;
700 cert_hex
= os_malloc(len
);
702 wpa_snprintf_hex(cert_hex
, len
, wpabuf_head(cert
),
704 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
705 WPA_EVENT_EAP_PEER_CERT
706 "depth=%d subject='%s' cert=%s",
707 depth
, subject
, cert_hex
);
712 /* notify the old DBus API */
713 wpa_supplicant_dbus_notify_certification(wpa_s
, depth
, subject
,
715 /* notify the new DBus API */
716 wpas_dbus_signal_certification(wpa_s
, depth
, subject
, cert_hash
, cert
);
720 void wpas_notify_preq(struct wpa_supplicant
*wpa_s
,
721 const u8
*addr
, const u8
*dst
, const u8
*bssid
,
722 const u8
*ie
, size_t ie_len
, u32 ssi_signal
)
725 wpas_dbus_signal_preq(wpa_s
, addr
, dst
, bssid
, ie
, ie_len
, ssi_signal
);
726 #endif /* CONFIG_AP */
730 void wpas_notify_eap_status(struct wpa_supplicant
*wpa_s
, const char *status
,
731 const char *parameter
)
733 wpas_dbus_signal_eap_status(wpa_s
, status
, parameter
);
734 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_EAP_STATUS
735 "status='%s' parameter='%s'",
740 void wpas_notify_network_bssid_set_changed(struct wpa_supplicant
*wpa_s
,
741 struct wpa_ssid
*ssid
)
743 if (wpa_s
->current_ssid
!= ssid
)
746 wpa_dbg(wpa_s
, MSG_DEBUG
,
747 "Network bssid config changed for the current network - within-ESS roaming %s",
748 ssid
->bssid_set
? "disabled" : "enabled");
750 wpa_drv_roaming(wpa_s
, !ssid
->bssid_set
,
751 ssid
->bssid_set
? ssid
->bssid
: NULL
);