notify.c revision 252726
1/* 2 * wpa_supplicant - Event notifications 3 * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi> 4 * 5 * This software may be distributed under the terms of the BSD license. 6 * See README for more details. 7 */ 8 9#include "utils/includes.h" 10 11#include "utils/common.h" 12#include "common/wpa_ctrl.h" 13#include "config.h" 14#include "wpa_supplicant_i.h" 15#include "wps_supplicant.h" 16#include "dbus/dbus_common.h" 17#include "dbus/dbus_old.h" 18#include "dbus/dbus_new.h" 19#include "rsn_supp/wpa.h" 20#include "driver_i.h" 21#include "scan.h" 22#include "p2p_supplicant.h" 23#include "sme.h" 24#include "notify.h" 25 26int wpas_notify_supplicant_initialized(struct wpa_global *global) 27{ 28#ifdef CONFIG_DBUS 29 if (global->params.dbus_ctrl_interface) { 30 global->dbus = wpas_dbus_init(global); 31 if (global->dbus == NULL) 32 return -1; 33 } 34#endif /* CONFIG_DBUS */ 35 36 return 0; 37} 38 39 40void wpas_notify_supplicant_deinitialized(struct wpa_global *global) 41{ 42#ifdef CONFIG_DBUS 43 if (global->dbus) 44 wpas_dbus_deinit(global->dbus); 45#endif /* CONFIG_DBUS */ 46} 47 48 49int wpas_notify_iface_added(struct wpa_supplicant *wpa_s) 50{ 51 if (wpas_dbus_register_iface(wpa_s)) 52 return -1; 53 54 if (wpas_dbus_register_interface(wpa_s)) 55 return -1; 56 57 return 0; 58} 59 60 61void wpas_notify_iface_removed(struct wpa_supplicant *wpa_s) 62{ 63 /* unregister interface in old DBus ctrl iface */ 64 wpas_dbus_unregister_iface(wpa_s); 65 66 /* unregister interface in new DBus ctrl iface */ 67 wpas_dbus_unregister_interface(wpa_s); 68} 69 70 71void wpas_notify_state_changed(struct wpa_supplicant *wpa_s, 72 enum wpa_states new_state, 73 enum wpa_states old_state) 74{ 75 /* notify the old DBus API */ 76 wpa_supplicant_dbus_notify_state_change(wpa_s, new_state, 77 old_state); 78 79 /* notify the new DBus API */ 80 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_STATE); 81 82#ifdef CONFIG_P2P 83 if (new_state == WPA_COMPLETED) 84 wpas_p2p_notif_connected(wpa_s); 85 else if (old_state >= WPA_ASSOCIATED && new_state < WPA_ASSOCIATED) 86 wpas_p2p_notif_disconnected(wpa_s); 87#endif /* CONFIG_P2P */ 88 89 sme_state_changed(wpa_s); 90 91#ifdef ANDROID 92 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE 93 "id=%d state=%d BSSID=" MACSTR, 94 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1, 95 new_state, MAC2STR(wpa_s->pending_bssid)); 96#endif /* ANDROID */ 97} 98 99 100void wpas_notify_disconnect_reason(struct wpa_supplicant *wpa_s) 101{ 102 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_DISCONNECT_REASON); 103} 104 105 106void wpas_notify_network_changed(struct wpa_supplicant *wpa_s) 107{ 108 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_NETWORK); 109} 110 111 112void wpas_notify_ap_scan_changed(struct wpa_supplicant *wpa_s) 113{ 114 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_AP_SCAN); 115} 116 117 118void wpas_notify_bssid_changed(struct wpa_supplicant *wpa_s) 119{ 120 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_BSS); 121} 122 123 124void wpas_notify_auth_changed(struct wpa_supplicant *wpa_s) 125{ 126 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_AUTH_MODE); 127} 128 129 130void wpas_notify_network_enabled_changed(struct wpa_supplicant *wpa_s, 131 struct wpa_ssid *ssid) 132{ 133 wpas_dbus_signal_network_enabled_changed(wpa_s, ssid); 134} 135 136 137void wpas_notify_network_selected(struct wpa_supplicant *wpa_s, 138 struct wpa_ssid *ssid) 139{ 140 wpas_dbus_signal_network_selected(wpa_s, ssid->id); 141} 142 143 144void wpas_notify_network_request(struct wpa_supplicant *wpa_s, 145 struct wpa_ssid *ssid, 146 enum wpa_ctrl_req_type rtype, 147 const char *default_txt) 148{ 149 wpas_dbus_signal_network_request(wpa_s, ssid, rtype, default_txt); 150} 151 152 153void wpas_notify_scanning(struct wpa_supplicant *wpa_s) 154{ 155 /* notify the old DBus API */ 156 wpa_supplicant_dbus_notify_scanning(wpa_s); 157 158 /* notify the new DBus API */ 159 wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_SCANNING); 160} 161 162 163void wpas_notify_scan_done(struct wpa_supplicant *wpa_s, int success) 164{ 165 wpas_dbus_signal_scan_done(wpa_s, success); 166} 167 168 169void wpas_notify_scan_results(struct wpa_supplicant *wpa_s) 170{ 171 /* notify the old DBus API */ 172 wpa_supplicant_dbus_notify_scan_results(wpa_s); 173 174 wpas_wps_notify_scan_results(wpa_s); 175} 176 177 178void wpas_notify_wps_credential(struct wpa_supplicant *wpa_s, 179 const struct wps_credential *cred) 180{ 181#ifdef CONFIG_WPS 182 /* notify the old DBus API */ 183 wpa_supplicant_dbus_notify_wps_cred(wpa_s, cred); 184 /* notify the new DBus API */ 185 wpas_dbus_signal_wps_cred(wpa_s, cred); 186#endif /* CONFIG_WPS */ 187} 188 189 190void wpas_notify_wps_event_m2d(struct wpa_supplicant *wpa_s, 191 struct wps_event_m2d *m2d) 192{ 193#ifdef CONFIG_WPS 194 wpas_dbus_signal_wps_event_m2d(wpa_s, m2d); 195#endif /* CONFIG_WPS */ 196} 197 198 199void wpas_notify_wps_event_fail(struct wpa_supplicant *wpa_s, 200 struct wps_event_fail *fail) 201{ 202#ifdef CONFIG_WPS 203 wpas_dbus_signal_wps_event_fail(wpa_s, fail); 204#endif /* CONFIG_WPS */ 205} 206 207 208void wpas_notify_wps_event_success(struct wpa_supplicant *wpa_s) 209{ 210#ifdef CONFIG_WPS 211 wpas_dbus_signal_wps_event_success(wpa_s); 212#endif /* CONFIG_WPS */ 213} 214 215 216void wpas_notify_network_added(struct wpa_supplicant *wpa_s, 217 struct wpa_ssid *ssid) 218{ 219 /* 220 * Networks objects created during any P2P activities should not be 221 * exposed out. They might/will confuse certain non-P2P aware 222 * applications since these network objects won't behave like 223 * regular ones. 224 */ 225 if (wpa_s->global->p2p_group_formation != wpa_s) 226 wpas_dbus_register_network(wpa_s, ssid); 227} 228 229 230void wpas_notify_persistent_group_added(struct wpa_supplicant *wpa_s, 231 struct wpa_ssid *ssid) 232{ 233#ifdef CONFIG_P2P 234 wpas_dbus_register_persistent_group(wpa_s, ssid); 235#endif /* CONFIG_P2P */ 236} 237 238 239void wpas_notify_persistent_group_removed(struct wpa_supplicant *wpa_s, 240 struct wpa_ssid *ssid) 241{ 242#ifdef CONFIG_P2P 243 wpas_dbus_unregister_persistent_group(wpa_s, ssid->id); 244#endif /* CONFIG_P2P */ 245} 246 247 248void wpas_notify_network_removed(struct wpa_supplicant *wpa_s, 249 struct wpa_ssid *ssid) 250{ 251 if (wpa_s->wpa) 252 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); 253 if (wpa_s->global->p2p_group_formation != wpa_s) 254 wpas_dbus_unregister_network(wpa_s, ssid->id); 255#ifdef CONFIG_P2P 256 wpas_p2p_network_removed(wpa_s, ssid); 257#endif /* CONFIG_P2P */ 258} 259 260 261void wpas_notify_bss_added(struct wpa_supplicant *wpa_s, 262 u8 bssid[], unsigned int id) 263{ 264 wpas_dbus_register_bss(wpa_s, bssid, id); 265 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_ADDED "%u " MACSTR, 266 id, MAC2STR(bssid)); 267} 268 269 270void wpas_notify_bss_removed(struct wpa_supplicant *wpa_s, 271 u8 bssid[], unsigned int id) 272{ 273 wpas_dbus_unregister_bss(wpa_s, bssid, id); 274 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_REMOVED "%u " MACSTR, 275 id, MAC2STR(bssid)); 276} 277 278 279void wpas_notify_bss_freq_changed(struct wpa_supplicant *wpa_s, 280 unsigned int id) 281{ 282 wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_FREQ, id); 283} 284 285 286void wpas_notify_bss_signal_changed(struct wpa_supplicant *wpa_s, 287 unsigned int id) 288{ 289 wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_SIGNAL, 290 id); 291} 292 293 294void wpas_notify_bss_privacy_changed(struct wpa_supplicant *wpa_s, 295 unsigned int id) 296{ 297 wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_PRIVACY, 298 id); 299} 300 301 302void wpas_notify_bss_mode_changed(struct wpa_supplicant *wpa_s, 303 unsigned int id) 304{ 305 wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_MODE, id); 306} 307 308 309void wpas_notify_bss_wpaie_changed(struct wpa_supplicant *wpa_s, 310 unsigned int id) 311{ 312 wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_WPA, id); 313} 314 315 316void wpas_notify_bss_rsnie_changed(struct wpa_supplicant *wpa_s, 317 unsigned int id) 318{ 319 wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RSN, id); 320} 321 322 323void wpas_notify_bss_wps_changed(struct wpa_supplicant *wpa_s, 324 unsigned int id) 325{ 326#ifdef CONFIG_WPS 327 wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_WPS, id); 328#endif /* CONFIG_WPS */ 329} 330 331 332void wpas_notify_bss_ies_changed(struct wpa_supplicant *wpa_s, 333 unsigned int id) 334{ 335 wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_IES, id); 336} 337 338 339void wpas_notify_bss_rates_changed(struct wpa_supplicant *wpa_s, 340 unsigned int id) 341{ 342 wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RATES, id); 343} 344 345 346void wpas_notify_blob_added(struct wpa_supplicant *wpa_s, const char *name) 347{ 348 wpas_dbus_signal_blob_added(wpa_s, name); 349} 350 351 352void wpas_notify_blob_removed(struct wpa_supplicant *wpa_s, const char *name) 353{ 354 wpas_dbus_signal_blob_removed(wpa_s, name); 355} 356 357 358void wpas_notify_debug_level_changed(struct wpa_global *global) 359{ 360 wpas_dbus_signal_debug_level_changed(global); 361} 362 363 364void wpas_notify_debug_timestamp_changed(struct wpa_global *global) 365{ 366 wpas_dbus_signal_debug_timestamp_changed(global); 367} 368 369 370void wpas_notify_debug_show_keys_changed(struct wpa_global *global) 371{ 372 wpas_dbus_signal_debug_show_keys_changed(global); 373} 374 375 376void wpas_notify_suspend(struct wpa_global *global) 377{ 378 struct wpa_supplicant *wpa_s; 379 380 os_get_time(&global->suspend_time); 381 wpa_printf(MSG_DEBUG, "System suspend notification"); 382 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) 383 wpa_drv_suspend(wpa_s); 384} 385 386 387void wpas_notify_resume(struct wpa_global *global) 388{ 389 struct os_time now; 390 int slept; 391 struct wpa_supplicant *wpa_s; 392 393 if (global->suspend_time.sec == 0) 394 slept = -1; 395 else { 396 os_get_time(&now); 397 slept = now.sec - global->suspend_time.sec; 398 } 399 wpa_printf(MSG_DEBUG, "System resume notification (slept %d seconds)", 400 slept); 401 402 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { 403 wpa_drv_resume(wpa_s); 404 if (wpa_s->wpa_state == WPA_DISCONNECTED) 405 wpa_supplicant_req_scan(wpa_s, 0, 100000); 406 } 407} 408 409 410#ifdef CONFIG_P2P 411 412void wpas_notify_p2p_device_found(struct wpa_supplicant *wpa_s, 413 const u8 *dev_addr, int new_device) 414{ 415 if (new_device) { 416 /* Create the new peer object */ 417 wpas_dbus_register_peer(wpa_s, dev_addr); 418 } 419 420 /* Notify a new peer has been detected*/ 421 wpas_dbus_signal_peer_device_found(wpa_s, dev_addr); 422} 423 424 425void wpas_notify_p2p_device_lost(struct wpa_supplicant *wpa_s, 426 const u8 *dev_addr) 427{ 428 wpas_dbus_unregister_peer(wpa_s, dev_addr); 429 430 /* Create signal on interface object*/ 431 wpas_dbus_signal_peer_device_lost(wpa_s, dev_addr); 432} 433 434 435void wpas_notify_p2p_group_removed(struct wpa_supplicant *wpa_s, 436 const struct wpa_ssid *ssid, 437 const char *role) 438{ 439 wpas_dbus_unregister_p2p_group(wpa_s, ssid); 440 441 wpas_dbus_signal_p2p_group_removed(wpa_s, role); 442} 443 444 445void wpas_notify_p2p_go_neg_req(struct wpa_supplicant *wpa_s, 446 const u8 *src, u16 dev_passwd_id) 447{ 448 wpas_dbus_signal_p2p_go_neg_req(wpa_s, src, dev_passwd_id); 449} 450 451 452void wpas_notify_p2p_go_neg_completed(struct wpa_supplicant *wpa_s, 453 struct p2p_go_neg_results *res) 454{ 455 wpas_dbus_signal_p2p_go_neg_resp(wpa_s, res); 456} 457 458 459void wpas_notify_p2p_invitation_result(struct wpa_supplicant *wpa_s, 460 int status, const u8 *bssid) 461{ 462 wpas_dbus_signal_p2p_invitation_result(wpa_s, status, bssid); 463} 464 465 466void wpas_notify_p2p_sd_request(struct wpa_supplicant *wpa_s, 467 int freq, const u8 *sa, u8 dialog_token, 468 u16 update_indic, const u8 *tlvs, 469 size_t tlvs_len) 470{ 471 wpas_dbus_signal_p2p_sd_request(wpa_s, freq, sa, dialog_token, 472 update_indic, tlvs, tlvs_len); 473} 474 475 476void wpas_notify_p2p_sd_response(struct wpa_supplicant *wpa_s, 477 const u8 *sa, u16 update_indic, 478 const u8 *tlvs, size_t tlvs_len) 479{ 480 wpas_dbus_signal_p2p_sd_response(wpa_s, sa, update_indic, 481 tlvs, tlvs_len); 482} 483 484 485/** 486 * wpas_notify_p2p_provision_discovery - Notification of provision discovery 487 * @dev_addr: Who sent the request or responded to our request. 488 * @request: Will be 1 if request, 0 for response. 489 * @status: Valid only in case of response (0 in case of success) 490 * @config_methods: WPS config methods 491 * @generated_pin: PIN to be displayed in case of WPS_CONFIG_DISPLAY method 492 * 493 * This can be used to notify: 494 * - Requests or responses 495 * - Various config methods 496 * - Failure condition in case of response 497 */ 498void wpas_notify_p2p_provision_discovery(struct wpa_supplicant *wpa_s, 499 const u8 *dev_addr, int request, 500 enum p2p_prov_disc_status status, 501 u16 config_methods, 502 unsigned int generated_pin) 503{ 504 wpas_dbus_signal_p2p_provision_discovery(wpa_s, dev_addr, request, 505 status, config_methods, 506 generated_pin); 507} 508 509 510void wpas_notify_p2p_group_started(struct wpa_supplicant *wpa_s, 511 struct wpa_ssid *ssid, int network_id, 512 int client) 513{ 514 /* Notify a group has been started */ 515 wpas_dbus_register_p2p_group(wpa_s, ssid); 516 517 wpas_dbus_signal_p2p_group_started(wpa_s, ssid, client, network_id); 518} 519 520 521void wpas_notify_p2p_wps_failed(struct wpa_supplicant *wpa_s, 522 struct wps_event_fail *fail) 523{ 524 wpas_dbus_signal_p2p_wps_failed(wpa_s, fail); 525} 526 527#endif /* CONFIG_P2P */ 528 529 530static void wpas_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s, 531 const u8 *sta, 532 const u8 *p2p_dev_addr) 533{ 534#ifdef CONFIG_P2P 535 wpas_p2p_notify_ap_sta_authorized(wpa_s, p2p_dev_addr); 536 537 /* 538 * Register a group member object corresponding to this peer and 539 * emit a PeerJoined signal. This will check if it really is a 540 * P2P group. 541 */ 542 wpas_dbus_register_p2p_groupmember(wpa_s, sta); 543 544 /* 545 * Create 'peer-joined' signal on group object -- will also 546 * check P2P itself. 547 */ 548 wpas_dbus_signal_p2p_peer_joined(wpa_s, sta); 549#endif /* CONFIG_P2P */ 550} 551 552 553static void wpas_notify_ap_sta_deauthorized(struct wpa_supplicant *wpa_s, 554 const u8 *sta) 555{ 556#ifdef CONFIG_P2P 557 /* 558 * Unregister a group member object corresponding to this peer 559 * if this is a P2P group. 560 */ 561 wpas_dbus_unregister_p2p_groupmember(wpa_s, sta); 562 563 /* 564 * Create 'peer-disconnected' signal on group object if this 565 * is a P2P group. 566 */ 567 wpas_dbus_signal_p2p_peer_disconnected(wpa_s, sta); 568#endif /* CONFIG_P2P */ 569} 570 571 572void wpas_notify_sta_authorized(struct wpa_supplicant *wpa_s, 573 const u8 *mac_addr, int authorized, 574 const u8 *p2p_dev_addr) 575{ 576 if (authorized) 577 wpas_notify_ap_sta_authorized(wpa_s, mac_addr, p2p_dev_addr); 578 else 579 wpas_notify_ap_sta_deauthorized(wpa_s, mac_addr); 580} 581 582 583void wpas_notify_certification(struct wpa_supplicant *wpa_s, int depth, 584 const char *subject, const char *cert_hash, 585 const struct wpabuf *cert) 586{ 587 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_EAP_PEER_CERT 588 "depth=%d subject='%s'%s%s", 589 depth, subject, 590 cert_hash ? " hash=" : "", 591 cert_hash ? cert_hash : ""); 592 593 if (cert) { 594 char *cert_hex; 595 size_t len = wpabuf_len(cert) * 2 + 1; 596 cert_hex = os_malloc(len); 597 if (cert_hex) { 598 wpa_snprintf_hex(cert_hex, len, wpabuf_head(cert), 599 wpabuf_len(cert)); 600 wpa_msg_ctrl(wpa_s, MSG_INFO, 601 WPA_EVENT_EAP_PEER_CERT 602 "depth=%d subject='%s' cert=%s", 603 depth, subject, cert_hex); 604 os_free(cert_hex); 605 } 606 } 607 608 /* notify the old DBus API */ 609 wpa_supplicant_dbus_notify_certification(wpa_s, depth, subject, 610 cert_hash, cert); 611 /* notify the new DBus API */ 612 wpas_dbus_signal_certification(wpa_s, depth, subject, cert_hash, cert); 613} 614 615 616void wpas_notify_preq(struct wpa_supplicant *wpa_s, 617 const u8 *addr, const u8 *dst, const u8 *bssid, 618 const u8 *ie, size_t ie_len, u32 ssi_signal) 619{ 620#ifdef CONFIG_AP 621 wpas_dbus_signal_preq(wpa_s, addr, dst, bssid, ie, ie_len, ssi_signal); 622#endif /* CONFIG_AP */ 623} 624 625 626void wpas_notify_eap_status(struct wpa_supplicant *wpa_s, const char *status, 627 const char *parameter) 628{ 629 wpas_dbus_signal_eap_status(wpa_s, status, parameter); 630} 631