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