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