Home | History | Annotate | Download | only in wpa_supplicant
      1 /*
      2  * wpa_supplicant - Event notifications
      3  * Copyright (c) 2009-2010, Jouni Malinen <j (at) 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 "binder/binder.h"
     17 #include "dbus/dbus_common.h"
     18 #include "dbus/dbus_old.h"
     19 #include "dbus/dbus_new.h"
     20 #include "rsn_supp/wpa.h"
     21 #include "fst/fst.h"
     22 #include "driver_i.h"
     23 #include "scan.h"
     24 #include "p2p_supplicant.h"
     25 #include "sme.h"
     26 #include "notify.h"
     27 
     28 int wpas_notify_supplicant_initialized(struct wpa_global *global)
     29 {
     30 #ifdef CONFIG_DBUS
     31 	if (global->params.dbus_ctrl_interface) {
     32 		global->dbus = wpas_dbus_init(global);
     33 		if (global->dbus == NULL)
     34 			return -1;
     35 	}
     36 #endif /* CONFIG_DBUS */
     37 
     38 #ifdef CONFIG_BINDER
     39 	global->binder = wpas_binder_init(global);
     40 	if (!global->binder)
     41 		return -1;
     42 #endif /* CONFIG_BINDER */
     43 
     44 	return 0;
     45 }
     46 
     47 
     48 void wpas_notify_supplicant_deinitialized(struct wpa_global *global)
     49 {
     50 #ifdef CONFIG_DBUS
     51 	if (global->dbus)
     52 		wpas_dbus_deinit(global->dbus);
     53 #endif /* CONFIG_DBUS */
     54 
     55 #ifdef CONFIG_BINDER
     56 	if (global->binder)
     57 		wpas_binder_deinit(global->binder);
     58 #endif /* CONFIG_BINDER */
     59 }
     60 
     61 
     62 int wpas_notify_iface_added(struct wpa_supplicant *wpa_s)
     63 {
     64 	if (wpa_s->p2p_mgmt)
     65 		return 0;
     66 
     67 	if (wpas_dbus_register_iface(wpa_s))
     68 		return -1;
     69 
     70 	if (wpas_dbus_register_interface(wpa_s))
     71 		return -1;
     72 
     73 	return 0;
     74 }
     75 
     76 
     77 void wpas_notify_iface_removed(struct wpa_supplicant *wpa_s)
     78 {
     79 	if (wpa_s->p2p_mgmt)
     80 		return;
     81 
     82 	/* unregister interface in old DBus ctrl iface */
     83 	wpas_dbus_unregister_iface(wpa_s);
     84 
     85 	/* unregister interface in new DBus ctrl iface */
     86 	wpas_dbus_unregister_interface(wpa_s);
     87 }
     88 
     89 
     90 void wpas_notify_state_changed(struct wpa_supplicant *wpa_s,
     91 			       enum wpa_states new_state,
     92 			       enum wpa_states old_state)
     93 {
     94 	if (wpa_s->p2p_mgmt)
     95 		return;
     96 
     97 	/* notify the old DBus API */
     98 	wpa_supplicant_dbus_notify_state_change(wpa_s, new_state,
     99 						old_state);
    100 
    101 	/* notify the new DBus API */
    102 	wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_STATE);
    103 
    104 #ifdef CONFIG_FST
    105 	if (wpa_s->fst && !is_zero_ether_addr(wpa_s->bssid)) {
    106 		if (new_state == WPA_COMPLETED)
    107 			fst_notify_peer_connected(wpa_s->fst, wpa_s->bssid);
    108 		else if (old_state >= WPA_ASSOCIATED &&
    109 			 new_state < WPA_ASSOCIATED)
    110 			fst_notify_peer_disconnected(wpa_s->fst, wpa_s->bssid);
    111 	}
    112 #endif /* CONFIG_FST */
    113 
    114 	if (new_state == WPA_COMPLETED)
    115 		wpas_p2p_notif_connected(wpa_s);
    116 	else if (old_state >= WPA_ASSOCIATED && new_state < WPA_ASSOCIATED)
    117 		wpas_p2p_notif_disconnected(wpa_s);
    118 
    119 	sme_state_changed(wpa_s);
    120 
    121 #ifdef ANDROID
    122 	wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
    123 		     "id=%d state=%d BSSID=" MACSTR " SSID=%s",
    124 		     wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
    125 		     new_state,
    126 		     MAC2STR(wpa_s->bssid),
    127 		     wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
    128 		     wpa_ssid_txt(wpa_s->current_ssid->ssid,
    129 				  wpa_s->current_ssid->ssid_len) : "");
    130 #endif /* ANDROID */
    131 }
    132 
    133 
    134 void wpas_notify_disconnect_reason(struct wpa_supplicant *wpa_s)
    135 {
    136 	if (wpa_s->p2p_mgmt)
    137 		return;
    138 
    139 	wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_DISCONNECT_REASON);
    140 }
    141 
    142 
    143 void wpas_notify_assoc_status_code(struct wpa_supplicant *wpa_s)
    144 {
    145 	if (wpa_s->p2p_mgmt)
    146 		return;
    147 
    148 	wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_ASSOC_STATUS_CODE);
    149 }
    150 
    151 
    152 void wpas_notify_network_changed(struct wpa_supplicant *wpa_s)
    153 {
    154 	if (wpa_s->p2p_mgmt)
    155 		return;
    156 
    157 	wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_NETWORK);
    158 }
    159 
    160 
    161 void wpas_notify_ap_scan_changed(struct wpa_supplicant *wpa_s)
    162 {
    163 	if (wpa_s->p2p_mgmt)
    164 		return;
    165 
    166 	wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_AP_SCAN);
    167 }
    168 
    169 
    170 void wpas_notify_bssid_changed(struct wpa_supplicant *wpa_s)
    171 {
    172 	if (wpa_s->p2p_mgmt)
    173 		return;
    174 
    175 	wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_BSS);
    176 }
    177 
    178 
    179 void wpas_notify_auth_changed(struct wpa_supplicant *wpa_s)
    180 {
    181 	if (wpa_s->p2p_mgmt)
    182 		return;
    183 
    184 	wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_CURRENT_AUTH_MODE);
    185 }
    186 
    187 
    188 void wpas_notify_network_enabled_changed(struct wpa_supplicant *wpa_s,
    189 					 struct wpa_ssid *ssid)
    190 {
    191 	if (wpa_s->p2p_mgmt)
    192 		return;
    193 
    194 	wpas_dbus_signal_network_enabled_changed(wpa_s, ssid);
    195 }
    196 
    197 
    198 void wpas_notify_network_selected(struct wpa_supplicant *wpa_s,
    199 				  struct wpa_ssid *ssid)
    200 {
    201 	if (wpa_s->p2p_mgmt)
    202 		return;
    203 
    204 	wpas_dbus_signal_network_selected(wpa_s, ssid->id);
    205 }
    206 
    207 
    208 void wpas_notify_network_request(struct wpa_supplicant *wpa_s,
    209 				 struct wpa_ssid *ssid,
    210 				 enum wpa_ctrl_req_type rtype,
    211 				 const char *default_txt)
    212 {
    213 	if (wpa_s->p2p_mgmt)
    214 		return;
    215 
    216 	wpas_dbus_signal_network_request(wpa_s, ssid, rtype, default_txt);
    217 }
    218 
    219 
    220 void wpas_notify_scanning(struct wpa_supplicant *wpa_s)
    221 {
    222 	if (wpa_s->p2p_mgmt)
    223 		return;
    224 
    225 	/* notify the old DBus API */
    226 	wpa_supplicant_dbus_notify_scanning(wpa_s);
    227 
    228 	/* notify the new DBus API */
    229 	wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_SCANNING);
    230 }
    231 
    232 
    233 void wpas_notify_scan_done(struct wpa_supplicant *wpa_s, int success)
    234 {
    235 	if (wpa_s->p2p_mgmt)
    236 		return;
    237 
    238 	wpas_dbus_signal_scan_done(wpa_s, success);
    239 }
    240 
    241 
    242 void wpas_notify_scan_results(struct wpa_supplicant *wpa_s)
    243 {
    244 	if (wpa_s->p2p_mgmt)
    245 		return;
    246 
    247 	/* notify the old DBus API */
    248 	wpa_supplicant_dbus_notify_scan_results(wpa_s);
    249 
    250 	wpas_wps_notify_scan_results(wpa_s);
    251 }
    252 
    253 
    254 void wpas_notify_wps_credential(struct wpa_supplicant *wpa_s,
    255 				const struct wps_credential *cred)
    256 {
    257 	if (wpa_s->p2p_mgmt)
    258 		return;
    259 
    260 #ifdef CONFIG_WPS
    261 	/* notify the old DBus API */
    262 	wpa_supplicant_dbus_notify_wps_cred(wpa_s, cred);
    263 	/* notify the new DBus API */
    264 	wpas_dbus_signal_wps_cred(wpa_s, cred);
    265 #endif /* CONFIG_WPS */
    266 }
    267 
    268 
    269 void wpas_notify_wps_event_m2d(struct wpa_supplicant *wpa_s,
    270 			       struct wps_event_m2d *m2d)
    271 {
    272 	if (wpa_s->p2p_mgmt)
    273 		return;
    274 
    275 #ifdef CONFIG_WPS
    276 	wpas_dbus_signal_wps_event_m2d(wpa_s, m2d);
    277 #endif /* CONFIG_WPS */
    278 }
    279 
    280 
    281 void wpas_notify_wps_event_fail(struct wpa_supplicant *wpa_s,
    282 				struct wps_event_fail *fail)
    283 {
    284 	if (wpa_s->p2p_mgmt)
    285 		return;
    286 
    287 #ifdef CONFIG_WPS
    288 	wpas_dbus_signal_wps_event_fail(wpa_s, fail);
    289 #endif /* CONFIG_WPS */
    290 }
    291 
    292 
    293 void wpas_notify_wps_event_success(struct wpa_supplicant *wpa_s)
    294 {
    295 	if (wpa_s->p2p_mgmt)
    296 		return;
    297 
    298 #ifdef CONFIG_WPS
    299 	wpas_dbus_signal_wps_event_success(wpa_s);
    300 #endif /* CONFIG_WPS */
    301 }
    302 
    303 void wpas_notify_wps_event_pbc_overlap(struct wpa_supplicant *wpa_s)
    304 {
    305 	if (wpa_s->p2p_mgmt)
    306 		return;
    307 
    308 #ifdef CONFIG_WPS
    309 	wpas_dbus_signal_wps_event_pbc_overlap(wpa_s);
    310 #endif /* CONFIG_WPS */
    311 }
    312 
    313 
    314 void wpas_notify_network_added(struct wpa_supplicant *wpa_s,
    315 			       struct wpa_ssid *ssid)
    316 {
    317 	if (wpa_s->p2p_mgmt)
    318 		return;
    319 
    320 	/*
    321 	 * Networks objects created during any P2P activities should not be
    322 	 * exposed out. They might/will confuse certain non-P2P aware
    323 	 * applications since these network objects won't behave like
    324 	 * regular ones.
    325 	 */
    326 	if (!ssid->p2p_group && wpa_s->global->p2p_group_formation != wpa_s)
    327 		wpas_dbus_register_network(wpa_s, ssid);
    328 }
    329 
    330 
    331 void wpas_notify_persistent_group_added(struct wpa_supplicant *wpa_s,
    332 					struct wpa_ssid *ssid)
    333 {
    334 #ifdef CONFIG_P2P
    335 	wpas_dbus_register_persistent_group(wpa_s, ssid);
    336 #endif /* CONFIG_P2P */
    337 }
    338 
    339 
    340 void wpas_notify_persistent_group_removed(struct wpa_supplicant *wpa_s,
    341 					  struct wpa_ssid *ssid)
    342 {
    343 #ifdef CONFIG_P2P
    344 	wpas_dbus_unregister_persistent_group(wpa_s, ssid->id);
    345 #endif /* CONFIG_P2P */
    346 }
    347 
    348 
    349 void wpas_notify_network_removed(struct wpa_supplicant *wpa_s,
    350 				 struct wpa_ssid *ssid)
    351 {
    352 	if (wpa_s->next_ssid == ssid)
    353 		wpa_s->next_ssid = NULL;
    354 	if (wpa_s->wpa)
    355 		wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
    356 	if (!ssid->p2p_group && wpa_s->global->p2p_group_formation != wpa_s &&
    357 	    !wpa_s->p2p_mgmt)
    358 		wpas_dbus_unregister_network(wpa_s, ssid->id);
    359 	if (network_is_persistent_group(ssid))
    360 		wpas_notify_persistent_group_removed(wpa_s, ssid);
    361 
    362 	wpas_p2p_network_removed(wpa_s, ssid);
    363 }
    364 
    365 
    366 void wpas_notify_bss_added(struct wpa_supplicant *wpa_s,
    367 			   u8 bssid[], unsigned int id)
    368 {
    369 	if (wpa_s->p2p_mgmt)
    370 		return;
    371 
    372 	wpas_dbus_register_bss(wpa_s, bssid, id);
    373 	wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_ADDED "%u " MACSTR,
    374 		     id, MAC2STR(bssid));
    375 }
    376 
    377 
    378 void wpas_notify_bss_removed(struct wpa_supplicant *wpa_s,
    379 			     u8 bssid[], unsigned int id)
    380 {
    381 	if (wpa_s->p2p_mgmt)
    382 		return;
    383 
    384 	wpas_dbus_unregister_bss(wpa_s, bssid, id);
    385 	wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_REMOVED "%u " MACSTR,
    386 		     id, MAC2STR(bssid));
    387 }
    388 
    389 
    390 void wpas_notify_bss_freq_changed(struct wpa_supplicant *wpa_s,
    391 				  unsigned int id)
    392 {
    393 	if (wpa_s->p2p_mgmt)
    394 		return;
    395 
    396 	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_FREQ, id);
    397 }
    398 
    399 
    400 void wpas_notify_bss_signal_changed(struct wpa_supplicant *wpa_s,
    401 				    unsigned int id)
    402 {
    403 	if (wpa_s->p2p_mgmt)
    404 		return;
    405 
    406 	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_SIGNAL,
    407 					  id);
    408 }
    409 
    410 
    411 void wpas_notify_bss_privacy_changed(struct wpa_supplicant *wpa_s,
    412 				     unsigned int id)
    413 {
    414 	if (wpa_s->p2p_mgmt)
    415 		return;
    416 
    417 	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_PRIVACY,
    418 					  id);
    419 }
    420 
    421 
    422 void wpas_notify_bss_mode_changed(struct wpa_supplicant *wpa_s,
    423 				  unsigned int id)
    424 {
    425 	if (wpa_s->p2p_mgmt)
    426 		return;
    427 
    428 	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_MODE, id);
    429 }
    430 
    431 
    432 void wpas_notify_bss_wpaie_changed(struct wpa_supplicant *wpa_s,
    433 				   unsigned int id)
    434 {
    435 	if (wpa_s->p2p_mgmt)
    436 		return;
    437 
    438 	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_WPA, id);
    439 }
    440 
    441 
    442 void wpas_notify_bss_rsnie_changed(struct wpa_supplicant *wpa_s,
    443 				   unsigned int id)
    444 {
    445 	if (wpa_s->p2p_mgmt)
    446 		return;
    447 
    448 	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RSN, id);
    449 }
    450 
    451 
    452 void wpas_notify_bss_wps_changed(struct wpa_supplicant *wpa_s,
    453 				 unsigned int id)
    454 {
    455 	if (wpa_s->p2p_mgmt)
    456 		return;
    457 
    458 #ifdef CONFIG_WPS
    459 	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_WPS, id);
    460 #endif /* CONFIG_WPS */
    461 }
    462 
    463 
    464 void wpas_notify_bss_ies_changed(struct wpa_supplicant *wpa_s,
    465 				   unsigned int id)
    466 {
    467 	if (wpa_s->p2p_mgmt)
    468 		return;
    469 
    470 	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_IES, id);
    471 }
    472 
    473 
    474 void wpas_notify_bss_rates_changed(struct wpa_supplicant *wpa_s,
    475 				   unsigned int id)
    476 {
    477 	if (wpa_s->p2p_mgmt)
    478 		return;
    479 
    480 	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RATES, id);
    481 }
    482 
    483 
    484 void wpas_notify_bss_seen(struct wpa_supplicant *wpa_s, unsigned int id)
    485 {
    486 	if (wpa_s->p2p_mgmt)
    487 		return;
    488 
    489 	wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_AGE, id);
    490 }
    491 
    492 
    493 void wpas_notify_blob_added(struct wpa_supplicant *wpa_s, const char *name)
    494 {
    495 	if (wpa_s->p2p_mgmt)
    496 		return;
    497 
    498 	wpas_dbus_signal_blob_added(wpa_s, name);
    499 }
    500 
    501 
    502 void wpas_notify_blob_removed(struct wpa_supplicant *wpa_s, const char *name)
    503 {
    504 	if (wpa_s->p2p_mgmt)
    505 		return;
    506 
    507 	wpas_dbus_signal_blob_removed(wpa_s, name);
    508 }
    509 
    510 
    511 void wpas_notify_debug_level_changed(struct wpa_global *global)
    512 {
    513 	wpas_dbus_signal_debug_level_changed(global);
    514 }
    515 
    516 
    517 void wpas_notify_debug_timestamp_changed(struct wpa_global *global)
    518 {
    519 	wpas_dbus_signal_debug_timestamp_changed(global);
    520 }
    521 
    522 
    523 void wpas_notify_debug_show_keys_changed(struct wpa_global *global)
    524 {
    525 	wpas_dbus_signal_debug_show_keys_changed(global);
    526 }
    527 
    528 
    529 void wpas_notify_suspend(struct wpa_global *global)
    530 {
    531 	struct wpa_supplicant *wpa_s;
    532 
    533 	os_get_time(&global->suspend_time);
    534 	wpa_printf(MSG_DEBUG, "System suspend notification");
    535 	for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
    536 		wpa_drv_suspend(wpa_s);
    537 }
    538 
    539 
    540 void wpas_notify_resume(struct wpa_global *global)
    541 {
    542 	struct os_time now;
    543 	int slept;
    544 	struct wpa_supplicant *wpa_s;
    545 
    546 	if (global->suspend_time.sec == 0)
    547 		slept = -1;
    548 	else {
    549 		os_get_time(&now);
    550 		slept = now.sec - global->suspend_time.sec;
    551 	}
    552 	wpa_printf(MSG_DEBUG, "System resume notification (slept %d seconds)",
    553 		   slept);
    554 
    555 	for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
    556 		wpa_drv_resume(wpa_s);
    557 		if (wpa_s->wpa_state == WPA_DISCONNECTED)
    558 			wpa_supplicant_req_scan(wpa_s, 0, 100000);
    559 	}
    560 }
    561 
    562 
    563 #ifdef CONFIG_P2P
    564 
    565 void wpas_notify_p2p_find_stopped(struct wpa_supplicant *wpa_s)
    566 {
    567 	/* Notify P2P find has stopped */
    568 	wpas_dbus_signal_p2p_find_stopped(wpa_s);
    569 }
    570 
    571 
    572 void wpas_notify_p2p_device_found(struct wpa_supplicant *wpa_s,
    573 				  const u8 *dev_addr, int new_device)
    574 {
    575 	if (new_device) {
    576 		/* Create the new peer object */
    577 		wpas_dbus_register_peer(wpa_s, dev_addr);
    578 	}
    579 
    580 	/* Notify a new peer has been detected*/
    581 	wpas_dbus_signal_peer_device_found(wpa_s, dev_addr);
    582 }
    583 
    584 
    585 void wpas_notify_p2p_device_lost(struct wpa_supplicant *wpa_s,
    586 				 const u8 *dev_addr)
    587 {
    588 	wpas_dbus_unregister_peer(wpa_s, dev_addr);
    589 
    590 	/* Create signal on interface object*/
    591 	wpas_dbus_signal_peer_device_lost(wpa_s, dev_addr);
    592 }
    593 
    594 
    595 void wpas_notify_p2p_group_removed(struct wpa_supplicant *wpa_s,
    596 				   const struct wpa_ssid *ssid,
    597 				   const char *role)
    598 {
    599 	wpas_dbus_signal_p2p_group_removed(wpa_s, role);
    600 
    601 	wpas_dbus_unregister_p2p_group(wpa_s, ssid);
    602 }
    603 
    604 
    605 void wpas_notify_p2p_go_neg_req(struct wpa_supplicant *wpa_s,
    606 				const u8 *src, u16 dev_passwd_id, u8 go_intent)
    607 {
    608 	wpas_dbus_signal_p2p_go_neg_req(wpa_s, src, dev_passwd_id, go_intent);
    609 }
    610 
    611 
    612 void wpas_notify_p2p_go_neg_completed(struct wpa_supplicant *wpa_s,
    613 				      struct p2p_go_neg_results *res)
    614 {
    615 	wpas_dbus_signal_p2p_go_neg_resp(wpa_s, res);
    616 }
    617 
    618 
    619 void wpas_notify_p2p_invitation_result(struct wpa_supplicant *wpa_s,
    620 				       int status, const u8 *bssid)
    621 {
    622 	wpas_dbus_signal_p2p_invitation_result(wpa_s, status, bssid);
    623 }
    624 
    625 
    626 void wpas_notify_p2p_sd_request(struct wpa_supplicant *wpa_s,
    627 				int freq, const u8 *sa, u8 dialog_token,
    628 				u16 update_indic, const u8 *tlvs,
    629 				size_t tlvs_len)
    630 {
    631 	wpas_dbus_signal_p2p_sd_request(wpa_s, freq, sa, dialog_token,
    632 					update_indic, tlvs, tlvs_len);
    633 }
    634 
    635 
    636 void wpas_notify_p2p_sd_response(struct wpa_supplicant *wpa_s,
    637 				 const u8 *sa, u16 update_indic,
    638 				 const u8 *tlvs, size_t tlvs_len)
    639 {
    640 	wpas_dbus_signal_p2p_sd_response(wpa_s, sa, update_indic,
    641 					 tlvs, tlvs_len);
    642 }
    643 
    644 
    645 /**
    646  * wpas_notify_p2p_provision_discovery - Notification of provision discovery
    647  * @dev_addr: Who sent the request or responded to our request.
    648  * @request: Will be 1 if request, 0 for response.
    649  * @status: Valid only in case of response (0 in case of success)
    650  * @config_methods: WPS config methods
    651  * @generated_pin: PIN to be displayed in case of WPS_CONFIG_DISPLAY method
    652  *
    653  * This can be used to notify:
    654  * - Requests or responses
    655  * - Various config methods
    656  * - Failure condition in case of response
    657  */
    658 void wpas_notify_p2p_provision_discovery(struct wpa_supplicant *wpa_s,
    659 					 const u8 *dev_addr, int request,
    660 					 enum p2p_prov_disc_status status,
    661 					 u16 config_methods,
    662 					 unsigned int generated_pin)
    663 {
    664 	wpas_dbus_signal_p2p_provision_discovery(wpa_s, dev_addr, request,
    665 						 status, config_methods,
    666 						 generated_pin);
    667 }
    668 
    669 
    670 void wpas_notify_p2p_group_started(struct wpa_supplicant *wpa_s,
    671 				   struct wpa_ssid *ssid, int network_id,
    672 				   int client)
    673 {
    674 	/* Notify a group has been started */
    675 	wpas_dbus_register_p2p_group(wpa_s, ssid);
    676 
    677 	wpas_dbus_signal_p2p_group_started(wpa_s, ssid, client, network_id);
    678 }
    679 
    680 
    681 void wpas_notify_p2p_group_formation_failure(struct wpa_supplicant *wpa_s,
    682 					     const char *reason)
    683 {
    684 	/* Notify a group formation failed */
    685 	wpas_dbus_signal_p2p_group_formation_failure(wpa_s, reason);
    686 }
    687 
    688 
    689 void wpas_notify_p2p_wps_failed(struct wpa_supplicant *wpa_s,
    690 				struct wps_event_fail *fail)
    691 {
    692 	wpas_dbus_signal_p2p_wps_failed(wpa_s, fail);
    693 }
    694 
    695 
    696 void wpas_notify_p2p_invitation_received(struct wpa_supplicant *wpa_s,
    697 					 const u8 *sa, const u8 *go_dev_addr,
    698 					 const u8 *bssid, int id, int op_freq)
    699 {
    700 	/* Notify a P2P Invitation Request */
    701 	wpas_dbus_signal_p2p_invitation_received(wpa_s, sa, go_dev_addr, bssid,
    702 						 id, op_freq);
    703 }
    704 
    705 #endif /* CONFIG_P2P */
    706 
    707 
    708 static void wpas_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s,
    709 					  const u8 *sta,
    710 					  const u8 *p2p_dev_addr)
    711 {
    712 #ifdef CONFIG_P2P
    713 	wpas_p2p_notify_ap_sta_authorized(wpa_s, p2p_dev_addr);
    714 
    715 	/*
    716 	 * Create 'peer-joined' signal on group object -- will also
    717 	 * check P2P itself.
    718 	 */
    719 	if (p2p_dev_addr)
    720 		wpas_dbus_signal_p2p_peer_joined(wpa_s, p2p_dev_addr);
    721 #endif /* CONFIG_P2P */
    722 
    723 	/* Notify listeners a new station has been authorized */
    724 	wpas_dbus_signal_sta_authorized(wpa_s, sta);
    725 }
    726 
    727 
    728 static void wpas_notify_ap_sta_deauthorized(struct wpa_supplicant *wpa_s,
    729 					    const u8 *sta,
    730 					    const u8 *p2p_dev_addr)
    731 {
    732 #ifdef CONFIG_P2P
    733 	/*
    734 	 * Create 'peer-disconnected' signal on group object if this
    735 	 * is a P2P group.
    736 	 */
    737 	if (p2p_dev_addr)
    738 		wpas_dbus_signal_p2p_peer_disconnected(wpa_s, p2p_dev_addr);
    739 #endif /* CONFIG_P2P */
    740 
    741 	/* Notify listeners a station has been deauthorized */
    742 	wpas_dbus_signal_sta_deauthorized(wpa_s, sta);
    743 }
    744 
    745 
    746 void wpas_notify_sta_authorized(struct wpa_supplicant *wpa_s,
    747 				const u8 *mac_addr, int authorized,
    748 				const u8 *p2p_dev_addr)
    749 {
    750 	if (authorized)
    751 		wpas_notify_ap_sta_authorized(wpa_s, mac_addr, p2p_dev_addr);
    752 	else
    753 		wpas_notify_ap_sta_deauthorized(wpa_s, mac_addr, p2p_dev_addr);
    754 }
    755 
    756 
    757 void wpas_notify_certification(struct wpa_supplicant *wpa_s, int depth,
    758 			       const char *subject, const char *altsubject[],
    759 			       int num_altsubject, const char *cert_hash,
    760 			       const struct wpabuf *cert)
    761 {
    762 	wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_EAP_PEER_CERT
    763 		"depth=%d subject='%s'%s%s",
    764 		depth, subject, cert_hash ? " hash=" : "",
    765 		cert_hash ? cert_hash : "");
    766 
    767 	if (cert) {
    768 		char *cert_hex;
    769 		size_t len = wpabuf_len(cert) * 2 + 1;
    770 		cert_hex = os_malloc(len);
    771 		if (cert_hex) {
    772 			wpa_snprintf_hex(cert_hex, len, wpabuf_head(cert),
    773 					 wpabuf_len(cert));
    774 			wpa_msg_ctrl(wpa_s, MSG_INFO,
    775 				     WPA_EVENT_EAP_PEER_CERT
    776 				     "depth=%d subject='%s' cert=%s",
    777 				     depth, subject, cert_hex);
    778 			os_free(cert_hex);
    779 		}
    780 	}
    781 
    782 	if (altsubject) {
    783 		int i;
    784 
    785 		for (i = 0; i < num_altsubject; i++)
    786 			wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_EAP_PEER_ALT
    787 				"depth=%d %s", depth, altsubject[i]);
    788 	}
    789 
    790 	/* notify the old DBus API */
    791 	wpa_supplicant_dbus_notify_certification(wpa_s, depth, subject,
    792 						 cert_hash, cert);
    793 	/* notify the new DBus API */
    794 	wpas_dbus_signal_certification(wpa_s, depth, subject, altsubject,
    795 				       num_altsubject, cert_hash, cert);
    796 }
    797 
    798 
    799 void wpas_notify_preq(struct wpa_supplicant *wpa_s,
    800 		      const u8 *addr, const u8 *dst, const u8 *bssid,
    801 		      const u8 *ie, size_t ie_len, u32 ssi_signal)
    802 {
    803 #ifdef CONFIG_AP
    804 	wpas_dbus_signal_preq(wpa_s, addr, dst, bssid, ie, ie_len, ssi_signal);
    805 #endif /* CONFIG_AP */
    806 }
    807 
    808 
    809 void wpas_notify_eap_status(struct wpa_supplicant *wpa_s, const char *status,
    810 			    const char *parameter)
    811 {
    812 	wpas_dbus_signal_eap_status(wpa_s, status, parameter);
    813 	wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_EAP_STATUS
    814 		     "status='%s' parameter='%s'",
    815 		     status, parameter);
    816 }
    817 
    818 
    819 void wpas_notify_network_bssid_set_changed(struct wpa_supplicant *wpa_s,
    820 					   struct wpa_ssid *ssid)
    821 {
    822 	if (wpa_s->current_ssid != ssid)
    823 		return;
    824 
    825 	wpa_dbg(wpa_s, MSG_DEBUG,
    826 		"Network bssid config changed for the current network - within-ESS roaming %s",
    827 		ssid->bssid_set ? "disabled" : "enabled");
    828 
    829 	wpa_drv_roaming(wpa_s, !ssid->bssid_set,
    830 			ssid->bssid_set ? ssid->bssid : NULL);
    831 }
    832 
    833 
    834 void wpas_notify_network_type_changed(struct wpa_supplicant *wpa_s,
    835 				      struct wpa_ssid *ssid)
    836 {
    837 #ifdef CONFIG_P2P
    838 	if (ssid->disabled == 2) {
    839 		/* Changed from normal network profile to persistent group */
    840 		ssid->disabled = 0;
    841 		wpas_dbus_unregister_network(wpa_s, ssid->id);
    842 		ssid->disabled = 2;
    843 		ssid->p2p_persistent_group = 1;
    844 		wpas_dbus_register_persistent_group(wpa_s, ssid);
    845 	} else {
    846 		/* Changed from persistent group to normal network profile */
    847 		wpas_dbus_unregister_persistent_group(wpa_s, ssid->id);
    848 		ssid->p2p_persistent_group = 0;
    849 		wpas_dbus_register_network(wpa_s, ssid);
    850 	}
    851 #endif /* CONFIG_P2P */
    852 }
    853