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