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