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
,
94 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
95 new_state
, MAC2STR(wpa_s
->pending_bssid
));
100 void wpas_notify_disconnect_reason(struct wpa_supplicant
*wpa_s
)
102 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_DISCONNECT_REASON
);
106 void wpas_notify_network_changed(struct wpa_supplicant
*wpa_s
)
108 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_CURRENT_NETWORK
);
112 void wpas_notify_ap_scan_changed(struct wpa_supplicant
*wpa_s
)
114 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_AP_SCAN
);
118 void wpas_notify_bssid_changed(struct wpa_supplicant
*wpa_s
)
120 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_CURRENT_BSS
);
124 void wpas_notify_auth_changed(struct wpa_supplicant
*wpa_s
)
126 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_CURRENT_AUTH_MODE
);
130 void wpas_notify_network_enabled_changed(struct wpa_supplicant
*wpa_s
,
131 struct wpa_ssid
*ssid
)
133 wpas_dbus_signal_network_enabled_changed(wpa_s
, ssid
);
137 void wpas_notify_network_selected(struct wpa_supplicant
*wpa_s
,
138 struct wpa_ssid
*ssid
)
140 wpas_dbus_signal_network_selected(wpa_s
, ssid
->id
);
144 void wpas_notify_network_request(struct wpa_supplicant
*wpa_s
,
145 struct wpa_ssid
*ssid
,
146 enum wpa_ctrl_req_type rtype
,
147 const char *default_txt
)
149 wpas_dbus_signal_network_request(wpa_s
, ssid
, rtype
, default_txt
);
153 void wpas_notify_scanning(struct wpa_supplicant
*wpa_s
)
155 /* notify the old DBus API */
156 wpa_supplicant_dbus_notify_scanning(wpa_s
);
158 /* notify the new DBus API */
159 wpas_dbus_signal_prop_changed(wpa_s
, WPAS_DBUS_PROP_SCANNING
);
163 void wpas_notify_scan_done(struct wpa_supplicant
*wpa_s
, int success
)
165 wpas_dbus_signal_scan_done(wpa_s
, success
);
169 void wpas_notify_scan_results(struct wpa_supplicant
*wpa_s
)
171 /* notify the old DBus API */
172 wpa_supplicant_dbus_notify_scan_results(wpa_s
);
174 wpas_wps_notify_scan_results(wpa_s
);
178 void wpas_notify_wps_credential(struct wpa_supplicant
*wpa_s
,
179 const struct wps_credential
*cred
)
182 /* notify the old DBus API */
183 wpa_supplicant_dbus_notify_wps_cred(wpa_s
, cred
);
184 /* notify the new DBus API */
185 wpas_dbus_signal_wps_cred(wpa_s
, cred
);
186 #endif /* CONFIG_WPS */
190 void wpas_notify_wps_event_m2d(struct wpa_supplicant
*wpa_s
,
191 struct wps_event_m2d
*m2d
)
194 wpas_dbus_signal_wps_event_m2d(wpa_s
, m2d
);
195 #endif /* CONFIG_WPS */
199 void wpas_notify_wps_event_fail(struct wpa_supplicant
*wpa_s
,
200 struct wps_event_fail
*fail
)
203 wpas_dbus_signal_wps_event_fail(wpa_s
, fail
);
204 #endif /* CONFIG_WPS */
208 void wpas_notify_wps_event_success(struct wpa_supplicant
*wpa_s
)
211 wpas_dbus_signal_wps_event_success(wpa_s
);
212 #endif /* CONFIG_WPS */
216 void wpas_notify_network_added(struct wpa_supplicant
*wpa_s
,
217 struct wpa_ssid
*ssid
)
220 * Networks objects created during any P2P activities should not be
221 * exposed out. They might/will confuse certain non-P2P aware
222 * applications since these network objects won't behave like
225 if (wpa_s
->global
->p2p_group_formation
!= wpa_s
)
226 wpas_dbus_register_network(wpa_s
, ssid
);
230 void wpas_notify_persistent_group_added(struct wpa_supplicant
*wpa_s
,
231 struct wpa_ssid
*ssid
)
234 wpas_dbus_register_persistent_group(wpa_s
, ssid
);
235 #endif /* CONFIG_P2P */
239 void wpas_notify_persistent_group_removed(struct wpa_supplicant
*wpa_s
,
240 struct wpa_ssid
*ssid
)
243 wpas_dbus_unregister_persistent_group(wpa_s
, ssid
->id
);
244 #endif /* CONFIG_P2P */
248 void wpas_notify_network_removed(struct wpa_supplicant
*wpa_s
,
249 struct wpa_ssid
*ssid
)
252 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
253 if (wpa_s
->global
->p2p_group_formation
!= wpa_s
)
254 wpas_dbus_unregister_network(wpa_s
, ssid
->id
);
256 wpas_p2p_network_removed(wpa_s
, ssid
);
257 #endif /* CONFIG_P2P */
261 void wpas_notify_bss_added(struct wpa_supplicant
*wpa_s
,
262 u8 bssid
[], unsigned int id
)
264 wpas_dbus_register_bss(wpa_s
, bssid
, id
);
265 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_BSS_ADDED
"%u " MACSTR
,
270 void wpas_notify_bss_removed(struct wpa_supplicant
*wpa_s
,
271 u8 bssid
[], unsigned int id
)
273 wpas_dbus_unregister_bss(wpa_s
, bssid
, id
);
274 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_BSS_REMOVED
"%u " MACSTR
,
279 void wpas_notify_bss_freq_changed(struct wpa_supplicant
*wpa_s
,
282 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_FREQ
, id
);
286 void wpas_notify_bss_signal_changed(struct wpa_supplicant
*wpa_s
,
289 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_SIGNAL
,
294 void wpas_notify_bss_privacy_changed(struct wpa_supplicant
*wpa_s
,
297 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_PRIVACY
,
302 void wpas_notify_bss_mode_changed(struct wpa_supplicant
*wpa_s
,
305 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_MODE
, id
);
309 void wpas_notify_bss_wpaie_changed(struct wpa_supplicant
*wpa_s
,
312 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_WPA
, id
);
316 void wpas_notify_bss_rsnie_changed(struct wpa_supplicant
*wpa_s
,
319 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_RSN
, id
);
323 void wpas_notify_bss_wps_changed(struct wpa_supplicant
*wpa_s
,
329 void wpas_notify_bss_ies_changed(struct wpa_supplicant
*wpa_s
,
332 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_IES
, id
);
336 void wpas_notify_bss_rates_changed(struct wpa_supplicant
*wpa_s
,
339 wpas_dbus_bss_signal_prop_changed(wpa_s
, WPAS_DBUS_BSS_PROP_RATES
, id
);
343 void wpas_notify_blob_added(struct wpa_supplicant
*wpa_s
, const char *name
)
345 wpas_dbus_signal_blob_added(wpa_s
, name
);
349 void wpas_notify_blob_removed(struct wpa_supplicant
*wpa_s
, const char *name
)
351 wpas_dbus_signal_blob_removed(wpa_s
, name
);
355 void wpas_notify_debug_level_changed(struct wpa_global
*global
)
357 wpas_dbus_signal_debug_level_changed(global
);
361 void wpas_notify_debug_timestamp_changed(struct wpa_global
*global
)
363 wpas_dbus_signal_debug_timestamp_changed(global
);
367 void wpas_notify_debug_show_keys_changed(struct wpa_global
*global
)
369 wpas_dbus_signal_debug_show_keys_changed(global
);
373 void wpas_notify_suspend(struct wpa_global
*global
)
375 struct wpa_supplicant
*wpa_s
;
377 os_get_time(&global
->suspend_time
);
378 wpa_printf(MSG_DEBUG
, "System suspend notification");
379 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
)
380 wpa_drv_suspend(wpa_s
);
384 void wpas_notify_resume(struct wpa_global
*global
)
388 struct wpa_supplicant
*wpa_s
;
390 if (global
->suspend_time
.sec
== 0)
394 slept
= now
.sec
- global
->suspend_time
.sec
;
396 wpa_printf(MSG_DEBUG
, "System resume notification (slept %d seconds)",
399 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
400 wpa_drv_resume(wpa_s
);
401 if (wpa_s
->wpa_state
== WPA_DISCONNECTED
)
402 wpa_supplicant_req_scan(wpa_s
, 0, 100000);
409 void wpas_notify_p2p_device_found(struct wpa_supplicant
*wpa_s
,
410 const u8
*dev_addr
, int new_device
)
413 /* Create the new peer object */
414 wpas_dbus_register_peer(wpa_s
, dev_addr
);
417 /* Notify a new peer has been detected*/
418 wpas_dbus_signal_peer_device_found(wpa_s
, dev_addr
);
422 void wpas_notify_p2p_device_lost(struct wpa_supplicant
*wpa_s
,
425 wpas_dbus_unregister_peer(wpa_s
, dev_addr
);
427 /* Create signal on interface object*/
428 wpas_dbus_signal_peer_device_lost(wpa_s
, dev_addr
);
432 void wpas_notify_p2p_group_removed(struct wpa_supplicant
*wpa_s
,
433 const struct wpa_ssid
*ssid
,
436 wpas_dbus_unregister_p2p_group(wpa_s
, ssid
);
438 wpas_dbus_signal_p2p_group_removed(wpa_s
, role
);
442 void wpas_notify_p2p_go_neg_req(struct wpa_supplicant
*wpa_s
,
443 const u8
*src
, u16 dev_passwd_id
)
445 wpas_dbus_signal_p2p_go_neg_req(wpa_s
, src
, dev_passwd_id
);
449 void wpas_notify_p2p_go_neg_completed(struct wpa_supplicant
*wpa_s
,
450 struct p2p_go_neg_results
*res
)
452 wpas_dbus_signal_p2p_go_neg_resp(wpa_s
, res
);
456 void wpas_notify_p2p_invitation_result(struct wpa_supplicant
*wpa_s
,
457 int status
, const u8
*bssid
)
459 wpas_dbus_signal_p2p_invitation_result(wpa_s
, status
, bssid
);
463 void wpas_notify_p2p_sd_request(struct wpa_supplicant
*wpa_s
,
464 int freq
, const u8
*sa
, u8 dialog_token
,
465 u16 update_indic
, const u8
*tlvs
,
468 wpas_dbus_signal_p2p_sd_request(wpa_s
, freq
, sa
, dialog_token
,
469 update_indic
, tlvs
, tlvs_len
);
473 void wpas_notify_p2p_sd_response(struct wpa_supplicant
*wpa_s
,
474 const u8
*sa
, u16 update_indic
,
475 const u8
*tlvs
, size_t tlvs_len
)
477 wpas_dbus_signal_p2p_sd_response(wpa_s
, sa
, update_indic
,
483 * wpas_notify_p2p_provision_discovery - Notification of provision discovery
484 * @dev_addr: Who sent the request or responded to our request.
485 * @request: Will be 1 if request, 0 for response.
486 * @status: Valid only in case of response (0 in case of success)
487 * @config_methods: WPS config methods
488 * @generated_pin: PIN to be displayed in case of WPS_CONFIG_DISPLAY method
490 * This can be used to notify:
491 * - Requests or responses
492 * - Various config methods
493 * - Failure condition in case of response
495 void wpas_notify_p2p_provision_discovery(struct wpa_supplicant
*wpa_s
,
496 const u8
*dev_addr
, int request
,
497 enum p2p_prov_disc_status status
,
499 unsigned int generated_pin
)
501 wpas_dbus_signal_p2p_provision_discovery(wpa_s
, dev_addr
, request
,
502 status
, config_methods
,
507 void wpas_notify_p2p_group_started(struct wpa_supplicant
*wpa_s
,
508 struct wpa_ssid
*ssid
, int network_id
,
511 /* Notify a group has been started */
512 wpas_dbus_register_p2p_group(wpa_s
, ssid
);
514 wpas_dbus_signal_p2p_group_started(wpa_s
, ssid
, client
, network_id
);
518 void wpas_notify_p2p_wps_failed(struct wpa_supplicant
*wpa_s
,
519 struct wps_event_fail
*fail
)
521 wpas_dbus_signal_p2p_wps_failed(wpa_s
, fail
);
524 #endif /* CONFIG_P2P */
527 static void wpas_notify_ap_sta_authorized(struct wpa_supplicant
*wpa_s
,
529 const u8
*p2p_dev_addr
)
532 wpas_p2p_notify_ap_sta_authorized(wpa_s
, p2p_dev_addr
);
535 * Register a group member object corresponding to this peer and
536 * emit a PeerJoined signal. This will check if it really is a
539 wpas_dbus_register_p2p_groupmember(wpa_s
, sta
);
542 * Create 'peer-joined' signal on group object -- will also
545 wpas_dbus_signal_p2p_peer_joined(wpa_s
, sta
);
546 #endif /* CONFIG_P2P */
550 static void wpas_notify_ap_sta_deauthorized(struct wpa_supplicant
*wpa_s
,
555 * Unregister a group member object corresponding to this peer
556 * if this is a P2P group.
558 wpas_dbus_unregister_p2p_groupmember(wpa_s
, sta
);
561 * Create 'peer-disconnected' signal on group object if this
564 wpas_dbus_signal_p2p_peer_disconnected(wpa_s
, sta
);
565 #endif /* CONFIG_P2P */
569 void wpas_notify_sta_authorized(struct wpa_supplicant
*wpa_s
,
570 const u8
*mac_addr
, int authorized
,
571 const u8
*p2p_dev_addr
)
574 wpas_notify_ap_sta_authorized(wpa_s
, mac_addr
, p2p_dev_addr
);
576 wpas_notify_ap_sta_deauthorized(wpa_s
, mac_addr
);
580 void wpas_notify_certification(struct wpa_supplicant
*wpa_s
, int depth
,
581 const char *subject
, const char *cert_hash
,
582 const struct wpabuf
*cert
)
584 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_EAP_PEER_CERT
585 "depth=%d subject='%s'%s%s",
587 cert_hash
? " hash=" : "",
588 cert_hash
? cert_hash
: "");
592 size_t len
= wpabuf_len(cert
) * 2 + 1;
593 cert_hex
= os_malloc(len
);
595 wpa_snprintf_hex(cert_hex
, len
, wpabuf_head(cert
),
597 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
598 WPA_EVENT_EAP_PEER_CERT
599 "depth=%d subject='%s' cert=%s",
600 depth
, subject
, cert_hex
);
605 /* notify the old DBus API */
606 wpa_supplicant_dbus_notify_certification(wpa_s
, depth
, subject
,
608 /* notify the new DBus API */
609 wpas_dbus_signal_certification(wpa_s
, depth
, subject
, cert_hash
, cert
);
613 void wpas_notify_preq(struct wpa_supplicant
*wpa_s
,
614 const u8
*addr
, const u8
*dst
, const u8
*bssid
,
615 const u8
*ie
, size_t ie_len
, u32 ssi_signal
)
618 wpas_dbus_signal_preq(wpa_s
, addr
, dst
, bssid
, ie
, ie_len
, ssi_signal
);
619 #endif /* CONFIG_AP */
623 void wpas_notify_eap_status(struct wpa_supplicant
*wpa_s
, const char *status
,
624 const char *parameter
)
626 wpas_dbus_signal_eap_status(wpa_s
, status
, parameter
);