notify.c revision 225736
1/*
2 * wpa_supplicant - Event notifications
3 * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
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
15#include "utils/includes.h"
16
17#include "utils/common.h"
18#include "common/wpa_ctrl.h"
19#include "config.h"
20#include "wpa_supplicant_i.h"
21#include "wps_supplicant.h"
22#include "dbus/dbus_common.h"
23#include "dbus/dbus_old.h"
24#include "dbus/dbus_new.h"
25#include "driver_i.h"
26#include "scan.h"
27#include "notify.h"
28
29int wpas_notify_supplicant_initialized(struct wpa_global *global)
30{
31#ifdef CONFIG_DBUS
32	if (global->params.dbus_ctrl_interface) {
33		global->dbus = wpas_dbus_init(global);
34		if (global->dbus == NULL)
35			return -1;
36	}
37#endif /* CONFIG_DBUS */
38
39	return 0;
40}
41
42
43void wpas_notify_supplicant_deinitialized(struct wpa_global *global)
44{
45#ifdef CONFIG_DBUS
46	if (global->dbus)
47		wpas_dbus_deinit(global->dbus);
48#endif /* CONFIG_DBUS */
49}
50
51
52int wpas_notify_iface_added(struct wpa_supplicant *wpa_s)
53{
54	if (wpas_dbus_register_iface(wpa_s))
55		return -1;
56
57	if (wpas_dbus_register_interface(wpa_s))
58		return -1;
59
60	return 0;
61}
62
63
64void wpas_notify_iface_removed(struct wpa_supplicant *wpa_s)
65{
66	/* unregister interface in old DBus ctrl iface */
67	wpas_dbus_unregister_iface(wpa_s);
68
69	/* unregister interface in new DBus ctrl iface */
70	wpas_dbus_unregister_interface(wpa_s);
71}
72
73
74void wpas_notify_state_changed(struct wpa_supplicant *wpa_s,
75			       enum wpa_states new_state,
76			       enum wpa_states old_state)
77{
78	/* notify the old DBus API */
79	wpa_supplicant_dbus_notify_state_change(wpa_s, new_state,
80						old_state);
81
82	/* notify the new DBus API */
83	wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_STATE);
84}
85
86
87void wpas_notify_network_changed(struct wpa_supplicant *wpa_s)
88{
89	wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_NETWORK);
90}
91
92
93void wpas_notify_ap_scan_changed(struct wpa_supplicant *wpa_s)
94{
95	wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_AP_SCAN);
96}
97
98
99void wpas_notify_bssid_changed(struct wpa_supplicant *wpa_s)
100{
101	wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_BSS);
102}
103
104
105void wpas_notify_network_enabled_changed(struct wpa_supplicant *wpa_s,
106					 struct wpa_ssid *ssid)
107{
108	wpas_dbus_signal_network_enabled_changed(wpa_s, ssid);
109}
110
111
112void wpas_notify_network_selected(struct wpa_supplicant *wpa_s,
113				  struct wpa_ssid *ssid)
114{
115	wpas_dbus_signal_network_selected(wpa_s, ssid->id);
116}
117
118
119void wpas_notify_scanning(struct wpa_supplicant *wpa_s)
120{
121	/* notify the old DBus API */
122	wpa_supplicant_dbus_notify_scanning(wpa_s);
123
124	/* notify the new DBus API */
125	wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_SCANNING);
126}
127
128
129void wpas_notify_scan_done(struct wpa_supplicant *wpa_s, int success)
130{
131	wpas_dbus_signal_scan_done(wpa_s, success);
132}
133
134
135void wpas_notify_scan_results(struct wpa_supplicant *wpa_s)
136{
137	/* notify the old DBus API */
138	wpa_supplicant_dbus_notify_scan_results(wpa_s);
139
140	wpas_wps_notify_scan_results(wpa_s);
141}
142
143
144void wpas_notify_wps_credential(struct wpa_supplicant *wpa_s,
145				const struct wps_credential *cred)
146{
147#ifdef CONFIG_WPS
148	/* notify the old DBus API */
149	wpa_supplicant_dbus_notify_wps_cred(wpa_s, cred);
150	/* notify the new DBus API */
151	wpas_dbus_signal_wps_cred(wpa_s, cred);
152#endif /* CONFIG_WPS */
153}
154
155
156void wpas_notify_wps_event_m2d(struct wpa_supplicant *wpa_s,
157			       struct wps_event_m2d *m2d)
158{
159#ifdef CONFIG_WPS
160	wpas_dbus_signal_wps_event_m2d(wpa_s, m2d);
161#endif /* CONFIG_WPS */
162}
163
164
165void wpas_notify_wps_event_fail(struct wpa_supplicant *wpa_s,
166				struct wps_event_fail *fail)
167{
168#ifdef CONFIG_WPS
169	wpas_dbus_signal_wps_event_fail(wpa_s, fail);
170#endif /* CONFIG_WPS */
171}
172
173
174void wpas_notify_wps_event_success(struct wpa_supplicant *wpa_s)
175{
176#ifdef CONFIG_WPS
177	wpas_dbus_signal_wps_event_success(wpa_s);
178#endif /* CONFIG_WPS */
179}
180
181
182void wpas_notify_network_added(struct wpa_supplicant *wpa_s,
183			       struct wpa_ssid *ssid)
184{
185	wpas_dbus_register_network(wpa_s, ssid);
186}
187
188
189void wpas_notify_network_removed(struct wpa_supplicant *wpa_s,
190				 struct wpa_ssid *ssid)
191{
192	wpas_dbus_unregister_network(wpa_s, ssid->id);
193}
194
195
196void wpas_notify_bss_added(struct wpa_supplicant *wpa_s,
197			   u8 bssid[], unsigned int id)
198{
199	wpas_dbus_register_bss(wpa_s, bssid, id);
200	wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_ADDED "%u " MACSTR,
201		     id, MAC2STR(bssid));
202}
203
204
205void wpas_notify_bss_removed(struct wpa_supplicant *wpa_s,
206			     u8 bssid[], unsigned int id)
207{
208	wpas_dbus_unregister_bss(wpa_s, bssid, id);
209	wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_REMOVED "%u " MACSTR,
210		     id, MAC2STR(bssid));
211}
212
213
214void wpas_notify_bss_freq_changed(struct wpa_supplicant *wpa_s,
215				  unsigned int id)
216{
217	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_FREQ, id);
218}
219
220
221void wpas_notify_bss_signal_changed(struct wpa_supplicant *wpa_s,
222				    unsigned int id)
223{
224	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_SIGNAL,
225					  id);
226}
227
228
229void wpas_notify_bss_privacy_changed(struct wpa_supplicant *wpa_s,
230				     unsigned int id)
231{
232	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_PRIVACY,
233					  id);
234}
235
236
237void wpas_notify_bss_mode_changed(struct wpa_supplicant *wpa_s,
238				  unsigned int id)
239{
240	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_MODE, id);
241}
242
243
244void wpas_notify_bss_wpaie_changed(struct wpa_supplicant *wpa_s,
245				   unsigned int id)
246{
247	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_WPA, id);
248}
249
250
251void wpas_notify_bss_rsnie_changed(struct wpa_supplicant *wpa_s,
252				   unsigned int id)
253{
254	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RSN, id);
255}
256
257
258void wpas_notify_bss_wps_changed(struct wpa_supplicant *wpa_s,
259				 unsigned int id)
260{
261}
262
263
264void wpas_notify_bss_ies_changed(struct wpa_supplicant *wpa_s,
265				   unsigned int id)
266{
267	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_IES, id);
268}
269
270
271void wpas_notify_bss_rates_changed(struct wpa_supplicant *wpa_s,
272				   unsigned int id)
273{
274	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RATES, id);
275}
276
277
278void wpas_notify_blob_added(struct wpa_supplicant *wpa_s, const char *name)
279{
280	wpas_dbus_signal_blob_added(wpa_s, name);
281}
282
283
284void wpas_notify_blob_removed(struct wpa_supplicant *wpa_s, const char *name)
285{
286	wpas_dbus_signal_blob_removed(wpa_s, name);
287}
288
289
290void wpas_notify_debug_level_changed(struct wpa_global *global)
291{
292	wpas_dbus_signal_debug_level_changed(global);
293}
294
295
296void wpas_notify_debug_timestamp_changed(struct wpa_global *global)
297{
298	wpas_dbus_signal_debug_timestamp_changed(global);
299}
300
301
302void wpas_notify_debug_show_keys_changed(struct wpa_global *global)
303{
304	wpas_dbus_signal_debug_show_keys_changed(global);
305}
306
307
308void wpas_notify_suspend(struct wpa_global *global)
309{
310	struct wpa_supplicant *wpa_s;
311
312	os_get_time(&global->suspend_time);
313	wpa_printf(MSG_DEBUG, "System suspend notification");
314	for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
315		wpa_drv_suspend(wpa_s);
316}
317
318
319void wpas_notify_resume(struct wpa_global *global)
320{
321	struct os_time now;
322	int slept;
323	struct wpa_supplicant *wpa_s;
324
325	if (global->suspend_time.sec == 0)
326		slept = -1;
327	else {
328		os_get_time(&now);
329		slept = now.sec - global->suspend_time.sec;
330	}
331	wpa_printf(MSG_DEBUG, "System resume notification (slept %d seconds)",
332		   slept);
333
334	for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
335		wpa_drv_resume(wpa_s);
336		if (wpa_s->wpa_state == WPA_DISCONNECTED)
337			wpa_supplicant_req_scan(wpa_s, 0, 100000);
338	}
339}
340