| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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 | #ifdef ANDROID | 
 | 97 | 	wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE | 
 | 98 | 		     "id=%d state=%d BSSID=" MACSTR, | 
 | 99 | 		     wpa_s->current_ssid ? wpa_s->current_ssid->id : -1, | 
 | 100 | 		     new_state, MAC2STR(wpa_s->pending_bssid)); | 
 | 101 | #endif /* ANDROID */ | 
 | 102 | } | 
 | 103 |  | 
 | 104 |  | 
 | 105 | void wpas_notify_network_changed(struct wpa_supplicant *wpa_s) | 
 | 106 | { | 
 | 107 | 	wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_NETWORK); | 
 | 108 | } | 
 | 109 |  | 
 | 110 |  | 
 | 111 | void wpas_notify_ap_scan_changed(struct wpa_supplicant *wpa_s) | 
 | 112 | { | 
 | 113 | 	wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_AP_SCAN); | 
 | 114 | } | 
 | 115 |  | 
 | 116 |  | 
 | 117 | void wpas_notify_bssid_changed(struct wpa_supplicant *wpa_s) | 
 | 118 | { | 
 | 119 | 	wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_BSS); | 
 | 120 | } | 
 | 121 |  | 
 | 122 |  | 
 | 123 | void wpas_notify_auth_changed(struct wpa_supplicant *wpa_s) | 
 | 124 | { | 
 | 125 | 	wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_AUTH_MODE); | 
 | 126 | } | 
 | 127 |  | 
 | 128 |  | 
 | 129 | void wpas_notify_network_enabled_changed(struct wpa_supplicant *wpa_s, | 
 | 130 | 					 struct wpa_ssid *ssid) | 
 | 131 | { | 
 | 132 | 	wpas_dbus_signal_network_enabled_changed(wpa_s, ssid); | 
 | 133 | } | 
 | 134 |  | 
 | 135 |  | 
 | 136 | void wpas_notify_network_selected(struct wpa_supplicant *wpa_s, | 
 | 137 | 				  struct wpa_ssid *ssid) | 
 | 138 | { | 
 | 139 | 	wpas_dbus_signal_network_selected(wpa_s, ssid->id); | 
 | 140 | } | 
 | 141 |  | 
 | 142 |  | 
 | 143 | void wpas_notify_scanning(struct wpa_supplicant *wpa_s) | 
 | 144 | { | 
 | 145 | 	/* notify the old DBus API */ | 
 | 146 | 	wpa_supplicant_dbus_notify_scanning(wpa_s); | 
 | 147 |  | 
 | 148 | 	/* notify the new DBus API */ | 
 | 149 | 	wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_SCANNING); | 
 | 150 | } | 
 | 151 |  | 
 | 152 |  | 
 | 153 | void wpas_notify_scan_done(struct wpa_supplicant *wpa_s, int success) | 
 | 154 | { | 
 | 155 | 	wpas_dbus_signal_scan_done(wpa_s, success); | 
 | 156 | } | 
 | 157 |  | 
 | 158 |  | 
 | 159 | void wpas_notify_scan_results(struct wpa_supplicant *wpa_s) | 
 | 160 | { | 
 | 161 | 	/* notify the old DBus API */ | 
 | 162 | 	wpa_supplicant_dbus_notify_scan_results(wpa_s); | 
 | 163 |  | 
 | 164 | 	wpas_wps_notify_scan_results(wpa_s); | 
 | 165 | } | 
 | 166 |  | 
 | 167 |  | 
 | 168 | void wpas_notify_wps_credential(struct wpa_supplicant *wpa_s, | 
 | 169 | 				const struct wps_credential *cred) | 
 | 170 | { | 
 | 171 | #ifdef CONFIG_WPS | 
 | 172 | 	/* notify the old DBus API */ | 
 | 173 | 	wpa_supplicant_dbus_notify_wps_cred(wpa_s, cred); | 
 | 174 | 	/* notify the new DBus API */ | 
 | 175 | 	wpas_dbus_signal_wps_cred(wpa_s, cred); | 
 | 176 | #endif /* CONFIG_WPS */ | 
 | 177 | } | 
 | 178 |  | 
 | 179 |  | 
 | 180 | void wpas_notify_wps_event_m2d(struct wpa_supplicant *wpa_s, | 
 | 181 | 			       struct wps_event_m2d *m2d) | 
 | 182 | { | 
 | 183 | #ifdef CONFIG_WPS | 
 | 184 | 	wpas_dbus_signal_wps_event_m2d(wpa_s, m2d); | 
 | 185 | #endif /* CONFIG_WPS */ | 
 | 186 | } | 
 | 187 |  | 
 | 188 |  | 
 | 189 | void wpas_notify_wps_event_fail(struct wpa_supplicant *wpa_s, | 
 | 190 | 				struct wps_event_fail *fail) | 
 | 191 | { | 
 | 192 | #ifdef CONFIG_WPS | 
 | 193 | 	wpas_dbus_signal_wps_event_fail(wpa_s, fail); | 
 | 194 | #endif /* CONFIG_WPS */ | 
 | 195 | } | 
 | 196 |  | 
 | 197 |  | 
 | 198 | void wpas_notify_wps_event_success(struct wpa_supplicant *wpa_s) | 
 | 199 | { | 
 | 200 | #ifdef CONFIG_WPS | 
 | 201 | 	wpas_dbus_signal_wps_event_success(wpa_s); | 
 | 202 | #endif /* CONFIG_WPS */ | 
 | 203 | } | 
 | 204 |  | 
 | 205 |  | 
 | 206 | void wpas_notify_network_added(struct wpa_supplicant *wpa_s, | 
 | 207 | 			       struct wpa_ssid *ssid) | 
 | 208 | { | 
 | 209 | 	wpas_dbus_register_network(wpa_s, ssid); | 
 | 210 | } | 
 | 211 |  | 
 | 212 |  | 
 | 213 | void wpas_notify_network_removed(struct wpa_supplicant *wpa_s, | 
 | 214 | 				 struct wpa_ssid *ssid) | 
 | 215 | { | 
 | 216 | 	wpas_dbus_unregister_network(wpa_s, ssid->id); | 
 | 217 | } | 
 | 218 |  | 
 | 219 |  | 
 | 220 | void wpas_notify_bss_added(struct wpa_supplicant *wpa_s, | 
 | 221 | 			   u8 bssid[], unsigned int id) | 
 | 222 | { | 
 | 223 | 	wpas_dbus_register_bss(wpa_s, bssid, id); | 
 | 224 | 	wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_ADDED "%u " MACSTR, | 
 | 225 | 		     id, MAC2STR(bssid)); | 
 | 226 | } | 
 | 227 |  | 
 | 228 |  | 
 | 229 | void wpas_notify_bss_removed(struct wpa_supplicant *wpa_s, | 
 | 230 | 			     u8 bssid[], unsigned int id) | 
 | 231 | { | 
 | 232 | 	wpas_dbus_unregister_bss(wpa_s, bssid, id); | 
 | 233 | 	wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_REMOVED "%u " MACSTR, | 
 | 234 | 		     id, MAC2STR(bssid)); | 
 | 235 | } | 
 | 236 |  | 
 | 237 |  | 
 | 238 | void wpas_notify_bss_freq_changed(struct wpa_supplicant *wpa_s, | 
 | 239 | 				  unsigned int id) | 
 | 240 | { | 
 | 241 | 	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_FREQ, id); | 
 | 242 | } | 
 | 243 |  | 
 | 244 |  | 
 | 245 | void wpas_notify_bss_signal_changed(struct wpa_supplicant *wpa_s, | 
 | 246 | 				    unsigned int id) | 
 | 247 | { | 
 | 248 | 	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_SIGNAL, | 
 | 249 | 					  id); | 
 | 250 | } | 
 | 251 |  | 
 | 252 |  | 
 | 253 | void wpas_notify_bss_privacy_changed(struct wpa_supplicant *wpa_s, | 
 | 254 | 				     unsigned int id) | 
 | 255 | { | 
 | 256 | 	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_PRIVACY, | 
 | 257 | 					  id); | 
 | 258 | } | 
 | 259 |  | 
 | 260 |  | 
 | 261 | void wpas_notify_bss_mode_changed(struct wpa_supplicant *wpa_s, | 
 | 262 | 				  unsigned int id) | 
 | 263 | { | 
 | 264 | 	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_MODE, id); | 
 | 265 | } | 
 | 266 |  | 
 | 267 |  | 
 | 268 | void wpas_notify_bss_wpaie_changed(struct wpa_supplicant *wpa_s, | 
 | 269 | 				   unsigned int id) | 
 | 270 | { | 
 | 271 | 	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_WPA, id); | 
 | 272 | } | 
 | 273 |  | 
 | 274 |  | 
 | 275 | void wpas_notify_bss_rsnie_changed(struct wpa_supplicant *wpa_s, | 
 | 276 | 				   unsigned int id) | 
 | 277 | { | 
 | 278 | 	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RSN, id); | 
 | 279 | } | 
 | 280 |  | 
 | 281 |  | 
 | 282 | void wpas_notify_bss_wps_changed(struct wpa_supplicant *wpa_s, | 
 | 283 | 				 unsigned int id) | 
 | 284 | { | 
 | 285 | } | 
 | 286 |  | 
 | 287 |  | 
 | 288 | void wpas_notify_bss_ies_changed(struct wpa_supplicant *wpa_s, | 
 | 289 | 				   unsigned int id) | 
 | 290 | { | 
 | 291 | 	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_IES, id); | 
 | 292 | } | 
 | 293 |  | 
 | 294 |  | 
 | 295 | void wpas_notify_bss_rates_changed(struct wpa_supplicant *wpa_s, | 
 | 296 | 				   unsigned int id) | 
 | 297 | { | 
 | 298 | 	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RATES, id); | 
 | 299 | } | 
 | 300 |  | 
 | 301 |  | 
 | 302 | void wpas_notify_blob_added(struct wpa_supplicant *wpa_s, const char *name) | 
 | 303 | { | 
 | 304 | 	wpas_dbus_signal_blob_added(wpa_s, name); | 
 | 305 | } | 
 | 306 |  | 
 | 307 |  | 
 | 308 | void wpas_notify_blob_removed(struct wpa_supplicant *wpa_s, const char *name) | 
 | 309 | { | 
 | 310 | 	wpas_dbus_signal_blob_removed(wpa_s, name); | 
 | 311 | } | 
 | 312 |  | 
 | 313 |  | 
 | 314 | void wpas_notify_debug_level_changed(struct wpa_global *global) | 
 | 315 | { | 
 | 316 | 	wpas_dbus_signal_debug_level_changed(global); | 
 | 317 | } | 
 | 318 |  | 
 | 319 |  | 
 | 320 | void wpas_notify_debug_timestamp_changed(struct wpa_global *global) | 
 | 321 | { | 
 | 322 | 	wpas_dbus_signal_debug_timestamp_changed(global); | 
 | 323 | } | 
 | 324 |  | 
 | 325 |  | 
 | 326 | void wpas_notify_debug_show_keys_changed(struct wpa_global *global) | 
 | 327 | { | 
 | 328 | 	wpas_dbus_signal_debug_show_keys_changed(global); | 
 | 329 | } | 
 | 330 |  | 
 | 331 |  | 
 | 332 | void wpas_notify_suspend(struct wpa_global *global) | 
 | 333 | { | 
 | 334 | 	struct wpa_supplicant *wpa_s; | 
 | 335 |  | 
 | 336 | 	os_get_time(&global->suspend_time); | 
 | 337 | 	wpa_printf(MSG_DEBUG, "System suspend notification"); | 
 | 338 | 	for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) | 
 | 339 | 		wpa_drv_suspend(wpa_s); | 
 | 340 | } | 
 | 341 |  | 
 | 342 |  | 
 | 343 | void wpas_notify_resume(struct wpa_global *global) | 
 | 344 | { | 
 | 345 | 	struct os_time now; | 
 | 346 | 	int slept; | 
 | 347 | 	struct wpa_supplicant *wpa_s; | 
 | 348 |  | 
 | 349 | 	if (global->suspend_time.sec == 0) | 
 | 350 | 		slept = -1; | 
 | 351 | 	else { | 
 | 352 | 		os_get_time(&now); | 
 | 353 | 		slept = now.sec - global->suspend_time.sec; | 
 | 354 | 	} | 
 | 355 | 	wpa_printf(MSG_DEBUG, "System resume notification (slept %d seconds)", | 
 | 356 | 		   slept); | 
 | 357 |  | 
 | 358 | 	for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { | 
 | 359 | 		wpa_drv_resume(wpa_s); | 
 | 360 | 		if (wpa_s->wpa_state == WPA_DISCONNECTED) | 
 | 361 | 			wpa_supplicant_req_scan(wpa_s, 0, 100000); | 
 | 362 | 	} | 
 | 363 | } | 
 | 364 |  | 
 | 365 |  | 
 | 366 | #ifdef CONFIG_P2P | 
 | 367 |  | 
 | 368 | void wpas_notify_p2p_device_found(struct wpa_supplicant *wpa_s, | 
 | 369 | 				  const u8 *dev_addr, int new_device) | 
 | 370 | { | 
 | 371 | } | 
 | 372 |  | 
 | 373 |  | 
 | 374 | void wpas_notify_p2p_device_lost(struct wpa_supplicant *wpa_s, | 
 | 375 | 				 const u8 *dev_addr) | 
 | 376 | { | 
 | 377 | } | 
 | 378 |  | 
 | 379 |  | 
 | 380 | void wpas_notify_p2p_group_removed(struct wpa_supplicant *wpa_s, | 
 | 381 | 				   const struct wpa_ssid *ssid, | 
 | 382 | 				   const char *role) | 
 | 383 | { | 
 | 384 | } | 
 | 385 |  | 
 | 386 |  | 
 | 387 | void wpas_notify_p2p_go_neg_req(struct wpa_supplicant *wpa_s, | 
 | 388 | 				const u8 *src, u16 dev_passwd_id) | 
 | 389 | { | 
 | 390 | } | 
 | 391 |  | 
 | 392 |  | 
 | 393 | void wpas_notify_p2p_go_neg_completed(struct wpa_supplicant *wpa_s, int status) | 
 | 394 | { | 
 | 395 | } | 
 | 396 |  | 
 | 397 |  | 
 | 398 | void wpas_notify_p2p_invitation_result(struct wpa_supplicant *wpa_s, | 
 | 399 | 				       int status, const u8 *bssid) | 
 | 400 | { | 
 | 401 | } | 
 | 402 |  | 
 | 403 |  | 
 | 404 | void wpas_notify_p2p_sd_request(struct wpa_supplicant *wpa_s, | 
 | 405 | 				int freq, const u8 *sa, u8 dialog_token, | 
 | 406 | 				u16 update_indic, const u8 *tlvs, | 
 | 407 | 				size_t tlvs_len) | 
 | 408 | { | 
 | 409 | } | 
 | 410 |  | 
 | 411 |  | 
 | 412 | void wpas_notify_p2p_sd_response(struct wpa_supplicant *wpa_s, | 
 | 413 | 				 const u8 *sa, u16 update_indic, | 
 | 414 | 				 const u8 *tlvs, size_t tlvs_len) | 
 | 415 | { | 
 | 416 | } | 
 | 417 |  | 
 | 418 | #endif /* CONFIG_P2P */ | 
 | 419 |  | 
 | 420 |  | 
 | 421 | static void wpas_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s, | 
 | 422 | 					  const u8 *sta) | 
 | 423 | { | 
 | 424 | } | 
 | 425 |  | 
 | 426 |  | 
 | 427 | static void wpas_notify_ap_sta_deauthorized(struct wpa_supplicant *wpa_s, | 
 | 428 | 					    const u8 *sta) | 
 | 429 | { | 
 | 430 | } | 
 | 431 |  | 
 | 432 |  | 
 | 433 | void wpas_notify_sta_authorized(struct wpa_supplicant *wpa_s, | 
 | 434 | 				const u8 *mac_addr, int authorized) | 
 | 435 | { | 
 | 436 | 	if (authorized) | 
 | 437 | 		wpas_notify_ap_sta_authorized(wpa_s, mac_addr); | 
 | 438 | 	else | 
 | 439 | 		wpas_notify_ap_sta_deauthorized(wpa_s, mac_addr); | 
 | 440 | } |