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