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
);
83 if (new_state
== WPA_COMPLETED
)
84 wpas_p2p_notif_connected(wpa_s
);
85 else if (old_state
>= WPA_ASSOCIATED
&& new_state
< WPA_ASSOCIATED
)
86 wpas_p2p_notif_disconnected(wpa_s
);
87 #endif /* CONFIG_P2P */
89 sme_state_changed(wpa_s
);
92 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
93 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
94 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
96 MAC2STR(wpa_s
->bssid
),
97 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
98 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
99 wpa_s
->current_ssid
->ssid_len
) : "");
104 void wpas_notify_disconnect_reason(struct wpa_supplicant
*wpa_s
)
106 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_DISCONNECT_REASON
);
110 void wpas_notify_network_changed(struct wpa_supplicant
*wpa_s
)
112 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_CURRENT_NETWORK
);
116 void wpas_notify_ap_scan_changed(struct wpa_supplicant
*wpa_s
)
118 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_AP_SCAN
);
122 void wpas_notify_bssid_changed(struct wpa_supplicant
*wpa_s
)
124 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_CURRENT_BSS
);
128 void wpas_notify_auth_changed(struct wpa_supplicant
*wpa_s
)
130 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_CURRENT_AUTH_MODE
);
134 void wpas_notify_network_enabled_changed(struct wpa_supplicant
*wpa_s
,
135 struct wpa_ssid
*ssid
)
137 wpas_dbus_signal_network_enabled_changed(wpa_s
, ssid
);
141 void wpas_notify_network_selected(struct wpa_supplicant
*wpa_s
,
142 struct wpa_ssid
*ssid
)
144 wpas_dbus_signal_network_selected(wpa_s
, ssid
->id
);
148 void wpas_notify_network_request(struct wpa_supplicant
*wpa_s
,
149 struct wpa_ssid
*ssid
,
150 enum wpa_ctrl_req_type rtype
,
151 const char *default_txt
)
153 wpas_dbus_signal_network_request(wpa_s
, ssid
, rtype
, default_txt
);
157 void wpas_notify_scanning(struct wpa_supplicant
*wpa_s
)
159 /* notify the old DBus API */
160 wpa_supplicant_dbus_notify_scanning(wpa_s
);
162 /* notify the new DBus API */
163 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_SCANNING
);
167 void wpas_notify_scan_done(struct wpa_supplicant
*wpa_s
, int success
)
169 wpas_dbus_signal_scan_done(wpa_s
, success
);
173 void wpas_notify_scan_results(struct wpa_supplicant
*wpa_s
)
175 /* notify the old DBus API */
176 wpa_supplicant_dbus_notify_scan_results(wpa_s
);
178 wpas_wps_notify_scan_results(wpa_s
);
182 void wpas_notify_wps_credential(struct wpa_supplicant
*wpa_s
,
183 const struct wps_credential
*cred
)
186 /* notify the old DBus API */
187 wpa_supplicant_dbus_notify_wps_cred(wpa_s
, cred
);
188 /* notify the new DBus API */
189 wpas_dbus_signal_wps_cred(wpa_s
, cred
);
190 #endif /* CONFIG_WPS */
194 void wpas_notify_wps_event_m2d(struct wpa_supplicant
*wpa_s
,
195 struct wps_event_m2d
*m2d
)
198 wpas_dbus_signal_wps_event_m2d(wpa_s
, m2d
);
199 #endif /* CONFIG_WPS */
203 void wpas_notify_wps_event_fail(struct wpa_supplicant
*wpa_s
,
204 struct wps_event_fail
*fail
)
207 wpas_dbus_signal_wps_event_fail(wpa_s
, fail
);
208 #endif /* CONFIG_WPS */
212 void wpas_notify_wps_event_success(struct wpa_supplicant
*wpa_s
)
215 wpas_dbus_signal_wps_event_success(wpa_s
);
216 #endif /* CONFIG_WPS */
220 void wpas_notify_network_added(struct wpa_supplicant
*wpa_s
,
221 struct wpa_ssid
*ssid
)
224 * Networks objects created during any P2P activities should not be
225 * exposed out. They might/will confuse certain non-P2P aware
226 * applications since these network objects won't behave like
229 if (!ssid
->p2p_group
&& wpa_s
->global
->p2p_group_formation
!= wpa_s
)
230 wpas_dbus_register_network(wpa_s
, ssid
);
234 void wpas_notify_persistent_group_added(struct wpa_supplicant
*wpa_s
,
235 struct wpa_ssid
*ssid
)
238 wpas_dbus_register_persistent_group(wpa_s
, ssid
);
239 #endif /* CONFIG_P2P */
243 void wpas_notify_persistent_group_removed(struct wpa_supplicant
*wpa_s
,
244 struct wpa_ssid
*ssid
)
247 wpas_dbus_unregister_persistent_group(wpa_s
, ssid
->id
);
248 #endif /* CONFIG_P2P */
252 void wpas_notify_network_removed(struct wpa_supplicant
*wpa_s
,
253 struct wpa_ssid
*ssid
)
255 if (wpa_s
->next_ssid
== ssid
)
256 wpa_s
->next_ssid
= NULL
;
258 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
259 if (!ssid
->p2p_group
&& wpa_s
->global
->p2p_group_formation
!= wpa_s
)
260 wpas_dbus_unregister_network(wpa_s
, ssid
->id
);
262 wpas_p2p_network_removed(wpa_s
, ssid
);
263 #endif /* CONFIG_P2P */
267 void wpas_notify_bss_added(struct wpa_supplicant
*wpa_s
,
268 u8 bssid
[], unsigned int id
)
270 wpas_dbus_register_bss(wpa_s
, bssid
, id
);
271 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_BSS_ADDED
"%u " MACSTR
,
276 void wpas_notify_bss_removed(struct wpa_supplicant
*wpa_s
,
277 u8 bssid
[], unsigned int id
)
279 wpas_dbus_unregister_bss(wpa_s
, bssid
, id
);
280 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_BSS_REMOVED
"%u " MACSTR
,
285 void wpas_notify_bss_freq_changed(struct wpa_supplicant
*wpa_s
,
288 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_FREQ
, id
);
292 void wpas_notify_bss_signal_changed(struct wpa_supplicant
*wpa_s
,
295 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_SIGNAL
,
300 void wpas_notify_bss_privacy_changed(struct wpa_supplicant
*wpa_s
,
303 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_PRIVACY
,
308 void wpas_notify_bss_mode_changed(struct wpa_supplicant
*wpa_s
,
311 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_MODE
, id
);
315 void wpas_notify_bss_wpaie_changed(struct wpa_supplicant
*wpa_s
,
318 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_WPA
, id
);
322 void wpas_notify_bss_rsnie_changed(struct wpa_supplicant
*wpa_s
,
325 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_RSN
, id
);
329 void wpas_notify_bss_wps_changed(struct wpa_supplicant
*wpa_s
,
333 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_WPS
, id
);
334 #endif /* CONFIG_WPS */
338 void wpas_notify_bss_ies_changed(struct wpa_supplicant
*wpa_s
,
341 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_IES
, id
);
345 void wpas_notify_bss_rates_changed(struct wpa_supplicant
*wpa_s
,
348 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_RATES
, id
);
352 void wpas_notify_blob_added(struct wpa_supplicant
*wpa_s
, const char *name
)
354 wpas_dbus_signal_blob_added(wpa_s
, name
);
358 void wpas_notify_blob_removed(struct wpa_supplicant
*wpa_s
, const char *name
)
360 wpas_dbus_signal_blob_removed(wpa_s
, name
);
364 void wpas_notify_debug_level_changed(struct wpa_global
*global
)
366 wpas_dbus_signal_debug_level_changed(global
);
370 void wpas_notify_debug_timestamp_changed(struct wpa_global
*global
)
372 wpas_dbus_signal_debug_timestamp_changed(global
);
376 void wpas_notify_debug_show_keys_changed(struct wpa_global
*global
)
378 wpas_dbus_signal_debug_show_keys_changed(global
);
382 void wpas_notify_suspend(struct wpa_global
*global
)
384 struct wpa_supplicant
*wpa_s
;
386 os_get_time(&global
->suspend_time
);
387 wpa_printf(MSG_DEBUG
, "System suspend notification");
388 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
)
389 wpa_drv_suspend(wpa_s
);
393 void wpas_notify_resume(struct wpa_global
*global
)
397 struct wpa_supplicant
*wpa_s
;
399 if (global
->suspend_time
.sec
== 0)
403 slept
= now
.sec
- global
->suspend_time
.sec
;
405 wpa_printf(MSG_DEBUG
, "System resume notification (slept %d seconds)",
408 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
409 wpa_drv_resume(wpa_s
);
410 if (wpa_s
->wpa_state
== WPA_DISCONNECTED
)
411 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
418 void wpas_notify_p2p_device_found(struct wpa_supplicant
*wpa_s
,
419 const u8
*dev_addr
, int new_device
)
422 /* Create the new peer object */
423 wpas_dbus_register_peer(wpa_s
, dev_addr
);
426 /* Notify a new peer has been detected*/
427 wpas_dbus_signal_peer_device_found(wpa_s
, dev_addr
);
431 void wpas_notify_p2p_device_lost(struct wpa_supplicant
*wpa_s
,
434 wpas_dbus_unregister_peer(wpa_s
, dev_addr
);
436 /* Create signal on interface object*/
437 wpas_dbus_signal_peer_device_lost(wpa_s
, dev_addr
);
441 void wpas_notify_p2p_group_removed(struct wpa_supplicant
*wpa_s
,
442 const struct wpa_ssid
*ssid
,
445 wpas_dbus_unregister_p2p_group(wpa_s
, ssid
);
447 wpas_dbus_signal_p2p_group_removed(wpa_s
, role
);
451 void wpas_notify_p2p_go_neg_req(struct wpa_supplicant
*wpa_s
,
452 const u8
*src
, u16 dev_passwd_id
)
454 wpas_dbus_signal_p2p_go_neg_req(wpa_s
, src
, dev_passwd_id
);
458 void wpas_notify_p2p_go_neg_completed(struct wpa_supplicant
*wpa_s
,
459 struct p2p_go_neg_results
*res
)
461 wpas_dbus_signal_p2p_go_neg_resp(wpa_s
, res
);
465 void wpas_notify_p2p_invitation_result(struct wpa_supplicant
*wpa_s
,
466 int status
, const u8
*bssid
)
468 wpas_dbus_signal_p2p_invitation_result(wpa_s
, status
, bssid
);
472 void wpas_notify_p2p_sd_request(struct wpa_supplicant
*wpa_s
,
473 int freq
, const u8
*sa
, u8 dialog_token
,
474 u16 update_indic
, const u8
*tlvs
,
477 wpas_dbus_signal_p2p_sd_request(wpa_s
, freq
, sa
, dialog_token
,
478 update_indic
, tlvs
, tlvs_len
);
482 void wpas_notify_p2p_sd_response(struct wpa_supplicant
*wpa_s
,
483 const u8
*sa
, u16 update_indic
,
484 const u8
*tlvs
, size_t tlvs_len
)
486 wpas_dbus_signal_p2p_sd_response(wpa_s
, sa
, update_indic
,
492 * wpas_notify_p2p_provision_discovery - Notification of provision discovery
493 * @dev_addr: Who sent the request or responded to our request.
494 * @request: Will be 1 if request, 0 for response.
495 * @status: Valid only in case of response (0 in case of success)
496 * @config_methods: WPS config methods
497 * @generated_pin: PIN to be displayed in case of WPS_CONFIG_DISPLAY method
499 * This can be used to notify:
500 * - Requests or responses
501 * - Various config methods
502 * - Failure condition in case of response
504 void wpas_notify_p2p_provision_discovery(struct wpa_supplicant
*wpa_s
,
505 const u8
*dev_addr
, int request
,
506 enum p2p_prov_disc_status status
,
508 unsigned int generated_pin
)
510 wpas_dbus_signal_p2p_provision_discovery(wpa_s
, dev_addr
, request
,
511 status
, config_methods
,
516 void wpas_notify_p2p_group_started(struct wpa_supplicant
*wpa_s
,
517 struct wpa_ssid
*ssid
, int network_id
,
520 /* Notify a group has been started */
521 wpas_dbus_register_p2p_group(wpa_s
, ssid
);
523 wpas_dbus_signal_p2p_group_started(wpa_s
, ssid
, client
, network_id
);
527 void wpas_notify_p2p_wps_failed(struct wpa_supplicant
*wpa_s
,
528 struct wps_event_fail
*fail
)
530 wpas_dbus_signal_p2p_wps_failed(wpa_s
, fail
);
533 #endif /* CONFIG_P2P */
536 static void wpas_notify_ap_sta_authorized(struct wpa_supplicant
*wpa_s
,
538 const u8
*p2p_dev_addr
)
541 wpas_p2p_notify_ap_sta_authorized(wpa_s
, p2p_dev_addr
);
544 * Register a group member object corresponding to this peer and
545 * emit a PeerJoined signal. This will check if it really is a
548 wpas_dbus_register_p2p_groupmember(wpa_s
, sta
);
551 * Create 'peer-joined' signal on group object -- will also
554 wpas_dbus_signal_p2p_peer_joined(wpa_s
, sta
);
555 #endif /* CONFIG_P2P */
557 /* Notify listeners a new station has been authorized */
558 wpas_dbus_signal_sta_authorized(wpa_s
, sta
);
562 static void wpas_notify_ap_sta_deauthorized(struct wpa_supplicant
*wpa_s
,
567 * Unregister a group member object corresponding to this peer
568 * if this is a P2P group.
570 wpas_dbus_unregister_p2p_groupmember(wpa_s
, sta
);
573 * Create 'peer-disconnected' signal on group object if this
576 wpas_dbus_signal_p2p_peer_disconnected(wpa_s
, sta
);
577 #endif /* CONFIG_P2P */
579 /* Notify listeners a station has been deauthorized */
580 wpas_dbus_signal_sta_deauthorized(wpa_s
, sta
);
584 void wpas_notify_sta_authorized(struct wpa_supplicant
*wpa_s
,
585 const u8
*mac_addr
, int authorized
,
586 const u8
*p2p_dev_addr
)
589 wpas_notify_ap_sta_authorized(wpa_s
, mac_addr
, p2p_dev_addr
);
591 wpas_notify_ap_sta_deauthorized(wpa_s
, mac_addr
);
595 void wpas_notify_certification(struct wpa_supplicant
*wpa_s
, int depth
,
596 const char *subject
, const char *cert_hash
,
597 const struct wpabuf
*cert
)
599 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_EAP_PEER_CERT
600 "depth=%d subject='%s'%s%s",
602 cert_hash
? " hash=" : "",
603 cert_hash
? cert_hash
: "");
607 size_t len
= wpabuf_len(cert
) * 2 + 1;
608 cert_hex
= os_malloc(len
);
610 wpa_snprintf_hex(cert_hex
, len
, wpabuf_head(cert
),
612 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
613 WPA_EVENT_EAP_PEER_CERT
614 "depth=%d subject='%s' cert=%s",
615 depth
, subject
, cert_hex
);
620 /* notify the old DBus API */
621 wpa_supplicant_dbus_notify_certification(wpa_s
, depth
, subject
,
623 /* notify the new DBus API */
624 wpas_dbus_signal_certification(wpa_s
, depth
, subject
, cert_hash
, cert
);
628 void wpas_notify_preq(struct wpa_supplicant
*wpa_s
,
629 const u8
*addr
, const u8
*dst
, const u8
*bssid
,
630 const u8
*ie
, size_t ie_len
, u32 ssi_signal
)
633 wpas_dbus_signal_preq(wpa_s
, addr
, dst
, bssid
, ie
, ie_len
, ssi_signal
);
634 #endif /* CONFIG_AP */
638 void wpas_notify_eap_status(struct wpa_supplicant
*wpa_s
, const char *status
,
639 const char *parameter
)
641 wpas_dbus_signal_eap_status(wpa_s
, status
, parameter
);
642 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_EAP_STATUS
643 "status='%s' parameter='%s'",