Move wpa_supplicant specific scan code away from src/drivers
[libeap.git] / wpa_supplicant / notify.c
1 /*
2  * wpa_supplicant - Event notifications
3  * Copyright (c) 2009, 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 "notify.h"
26
27 int wpas_notify_supplicant_initialized(struct wpa_global *global)
28 {
29 #ifdef CONFIG_DBUS
30         if (global->params.dbus_ctrl_interface) {
31                 global->dbus = wpas_dbus_init(global);
32                 if (global->dbus == NULL)
33                         return -1;
34         }
35 #endif /* CONFIG_DBUS */
36
37         return 0;
38 }
39
40
41 void wpas_notify_supplicant_deinitialized(struct wpa_global *global)
42 {
43 #ifdef CONFIG_DBUS
44         if (global->dbus)
45                 wpas_dbus_deinit(global->dbus);
46 #endif /* CONFIG_DBUS */
47 }
48
49
50 int wpas_notify_iface_added(struct wpa_supplicant *wpa_s)
51 {
52         if (wpas_dbus_register_iface(wpa_s))
53                 return -1;
54
55         if (wpas_dbus_register_interface(wpa_s))
56                 return -1;
57
58         return 0;
59 }
60
61
62 void wpas_notify_iface_removed(struct wpa_supplicant *wpa_s)
63 {
64         /* unregister interface in old DBus ctrl iface */
65         wpas_dbus_unregister_iface(wpa_s);
66
67         /* unregister interface in new DBus ctrl iface */
68         wpas_dbus_unregister_interface(wpa_s);
69 }
70
71
72 void wpas_notify_state_changed(struct wpa_supplicant *wpa_s,
73                                enum wpa_states new_state,
74                                enum wpa_states old_state)
75 {
76         /* notify the old DBus API */
77         wpa_supplicant_dbus_notify_state_change(wpa_s, new_state,
78                                                 old_state);
79
80         /* notify the new DBus API */
81         wpas_dbus_signal_state_changed(wpa_s, new_state, old_state);
82 }
83
84
85 void wpas_notify_network_changed(struct wpa_supplicant *wpa_s)
86 {
87         wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_NETWORK);
88 }
89
90
91 void wpas_notify_ap_scan_changed(struct wpa_supplicant *wpa_s)
92 {
93         wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_AP_SCAN);
94 }
95
96
97 void wpas_notify_bssid_changed(struct wpa_supplicant *wpa_s)
98 {
99         wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_BSS);
100 }
101
102
103 void wpas_notify_network_enabled_changed(struct wpa_supplicant *wpa_s,
104                                          struct wpa_ssid *ssid)
105 {
106         wpas_dbus_signal_network_enabled_changed(wpa_s, ssid);
107 }
108
109
110 void wpas_notify_network_selected(struct wpa_supplicant *wpa_s,
111                                   struct wpa_ssid *ssid)
112 {
113         wpas_dbus_signal_network_selected(wpa_s, ssid->id);
114 }
115
116
117 void wpas_notify_scanning(struct wpa_supplicant *wpa_s)
118 {
119         /* notify the old DBus API */
120         wpa_supplicant_dbus_notify_scanning(wpa_s);
121         /* notify the new DBus API */
122         wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_SCANNING);
123 }
124
125
126 void wpas_notify_scan_done(struct wpa_supplicant *wpa_s, int success)
127 {
128         wpas_dbus_signal_scan_done(wpa_s, success);
129 }
130
131
132 void wpas_notify_scan_results(struct wpa_supplicant *wpa_s)
133 {
134         /* notify the old DBus API */
135         wpa_supplicant_dbus_notify_scan_results(wpa_s);
136
137         wpas_wps_notify_scan_results(wpa_s);
138 }
139
140
141 void wpas_notify_wps_credential(struct wpa_supplicant *wpa_s,
142                                 const struct wps_credential *cred)
143 {
144 #ifdef CONFIG_WPS
145         /* notify the old DBus API */
146         wpa_supplicant_dbus_notify_wps_cred(wpa_s, cred);
147         /* notify the new DBus API */
148         wpas_dbus_signal_wps_cred(wpa_s, cred);
149 #endif /* CONFIG_WPS */
150 }
151
152
153 void wpas_notify_wps_event_m2d(struct wpa_supplicant *wpa_s,
154                                struct wps_event_m2d *m2d)
155 {
156 #ifdef CONFIG_WPS
157         wpas_dbus_signal_wps_event_m2d(wpa_s, m2d);
158 #endif /* CONFIG_WPS */
159 }
160
161
162 void wpas_notify_wps_event_fail(struct wpa_supplicant *wpa_s,
163                                 struct wps_event_fail *fail)
164 {
165 #ifdef CONFIG_WPS
166         wpas_dbus_signal_wps_event_fail(wpa_s, fail);
167 #endif /* CONFIG_WPS */
168 }
169
170
171 void wpas_notify_wps_event_success(struct wpa_supplicant *wpa_s)
172 {
173 #ifdef CONFIG_WPS
174         wpas_dbus_signal_wps_event_success(wpa_s);
175 #endif /* CONFIG_WPS */
176 }
177
178
179 void wpas_notify_network_added(struct wpa_supplicant *wpa_s,
180                                struct wpa_ssid *ssid)
181 {
182         wpas_dbus_register_network(wpa_s, ssid);
183 }
184
185
186 void wpas_notify_network_removed(struct wpa_supplicant *wpa_s,
187                                  struct wpa_ssid *ssid)
188 {
189         wpas_dbus_unregister_network(wpa_s, ssid->id);
190 }
191
192
193 void wpas_notify_bss_added(struct wpa_supplicant *wpa_s,
194                            u8 bssid[], unsigned int id)
195 {
196         wpas_dbus_register_bss(wpa_s, bssid, id);
197         wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_ADDED "%u " MACSTR,
198                      id, MAC2STR(bssid));
199 }
200
201
202 void wpas_notify_bss_removed(struct wpa_supplicant *wpa_s,
203                              u8 bssid[], unsigned int id)
204 {
205         wpas_dbus_unregister_bss(wpa_s, bssid, id);
206         wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_REMOVED "%u " MACSTR,
207                      id, MAC2STR(bssid));
208 }
209
210
211 void wpas_notify_blob_added(struct wpa_supplicant *wpa_s, const char *name)
212 {
213         wpas_dbus_signal_blob_added(wpa_s, name);
214 }
215
216
217 void wpas_notify_blob_removed(struct wpa_supplicant *wpa_s, const char *name)
218 {
219         wpas_dbus_signal_blob_removed(wpa_s, name);
220 }
221
222
223 void wpas_notify_debug_level_changed(struct wpa_global *global)
224 {
225         wpas_dbus_signal_debug_level_changed(global);
226 }
227
228
229 void wpas_notify_debug_timestamp_changed(struct wpa_global *global)
230 {
231         wpas_dbus_signal_debug_timestamp_changed(global);
232 }
233
234
235 void wpas_notify_debug_show_keys_changed(struct wpa_global *global)
236 {
237         wpas_dbus_signal_debug_show_keys_changed(global);
238 }