xref: /dragonfly/contrib/wpa_supplicant/wpa_supplicant/notify.c (revision 3a84a4273475ed07d0ab1c2dfeffdfedef35d9cd)
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 
wpas_notify_supplicant_initialized(struct wpa_global * global)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 
wpas_notify_supplicant_deinitialized(struct wpa_global * global)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 
wpas_notify_iface_added(struct wpa_supplicant * wpa_s)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 
wpas_notify_iface_removed(struct wpa_supplicant * wpa_s)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 
wpas_notify_state_changed(struct wpa_supplicant * wpa_s,enum wpa_states new_state,enum wpa_states old_state)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 
wpas_notify_disconnect_reason(struct wpa_supplicant * wpa_s)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 
wpas_notify_auth_status_code(struct wpa_supplicant * wpa_s)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 
wpas_notify_assoc_status_code(struct wpa_supplicant * wpa_s)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 
wpas_notify_roam_time(struct wpa_supplicant * wpa_s)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 
wpas_notify_roam_complete(struct wpa_supplicant * wpa_s)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 
wpas_notify_session_length(struct wpa_supplicant * wpa_s)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 
wpas_notify_bss_tm_status(struct wpa_supplicant * wpa_s)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 
wpas_notify_network_changed(struct wpa_supplicant * wpa_s)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 
wpas_notify_ap_scan_changed(struct wpa_supplicant * wpa_s)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 
wpas_notify_bssid_changed(struct wpa_supplicant * wpa_s)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 
wpas_notify_auth_changed(struct wpa_supplicant * wpa_s)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 
wpas_notify_network_enabled_changed(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid)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 
wpas_notify_network_selected(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid)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 
wpas_notify_network_request(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid,enum wpa_ctrl_req_type rtype,const char * default_txt)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 
wpas_notify_scanning(struct wpa_supplicant * wpa_s)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 
wpas_notify_scan_done(struct wpa_supplicant * wpa_s,int success)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 
wpas_notify_scan_results(struct wpa_supplicant * wpa_s)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 
wpas_notify_wps_credential(struct wpa_supplicant * wpa_s,const struct wps_credential * cred)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 
wpas_notify_wps_event_m2d(struct wpa_supplicant * wpa_s,struct wps_event_m2d * m2d)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 
wpas_notify_wps_event_fail(struct wpa_supplicant * wpa_s,struct wps_event_fail * fail)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 
wpas_notify_wps_event_success(struct wpa_supplicant * wpa_s)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 
wpas_notify_wps_event_pbc_overlap(struct wpa_supplicant * wpa_s)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 
wpas_notify_network_added(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid)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 
wpas_notify_persistent_group_added(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid)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 
wpas_notify_persistent_group_removed(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid)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 
wpas_notify_network_removed(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid)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 
392 
wpas_notify_bss_added(struct wpa_supplicant * wpa_s,u8 bssid[],unsigned int id)393 void wpas_notify_bss_added(struct wpa_supplicant *wpa_s,
394                                  u8 bssid[], unsigned int id)
395 {
396           if (wpa_s->p2p_mgmt)
397                     return;
398 
399           wpas_dbus_register_bss(wpa_s, bssid, id);
400           wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_ADDED "%u " MACSTR,
401                          id, MAC2STR(bssid));
402 }
403 
404 
wpas_notify_bss_removed(struct wpa_supplicant * wpa_s,u8 bssid[],unsigned int id)405 void wpas_notify_bss_removed(struct wpa_supplicant *wpa_s,
406                                    u8 bssid[], unsigned int id)
407 {
408           if (wpa_s->p2p_mgmt)
409                     return;
410 
411           wpas_dbus_unregister_bss(wpa_s, bssid, id);
412           wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_BSS_REMOVED "%u " MACSTR,
413                          id, MAC2STR(bssid));
414 }
415 
416 
wpas_notify_bss_freq_changed(struct wpa_supplicant * wpa_s,unsigned int id)417 void wpas_notify_bss_freq_changed(struct wpa_supplicant *wpa_s,
418                                           unsigned int id)
419 {
420           if (wpa_s->p2p_mgmt)
421                     return;
422 
423           wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_FREQ, id);
424 }
425 
426 
wpas_notify_bss_signal_changed(struct wpa_supplicant * wpa_s,unsigned int id)427 void wpas_notify_bss_signal_changed(struct wpa_supplicant *wpa_s,
428                                             unsigned int id)
429 {
430           if (wpa_s->p2p_mgmt)
431                     return;
432 
433           wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_SIGNAL,
434                                                     id);
435 }
436 
437 
wpas_notify_bss_privacy_changed(struct wpa_supplicant * wpa_s,unsigned int id)438 void wpas_notify_bss_privacy_changed(struct wpa_supplicant *wpa_s,
439                                              unsigned int id)
440 {
441           if (wpa_s->p2p_mgmt)
442                     return;
443 
444           wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_PRIVACY,
445                                                     id);
446 }
447 
448 
wpas_notify_bss_mode_changed(struct wpa_supplicant * wpa_s,unsigned int id)449 void wpas_notify_bss_mode_changed(struct wpa_supplicant *wpa_s,
450                                           unsigned int id)
451 {
452           if (wpa_s->p2p_mgmt)
453                     return;
454 
455           wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_MODE, id);
456 }
457 
458 
wpas_notify_bss_wpaie_changed(struct wpa_supplicant * wpa_s,unsigned int id)459 void wpas_notify_bss_wpaie_changed(struct wpa_supplicant *wpa_s,
460                                            unsigned int id)
461 {
462           if (wpa_s->p2p_mgmt)
463                     return;
464 
465           wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_WPA, id);
466 }
467 
468 
wpas_notify_bss_rsnie_changed(struct wpa_supplicant * wpa_s,unsigned int id)469 void wpas_notify_bss_rsnie_changed(struct wpa_supplicant *wpa_s,
470                                            unsigned int id)
471 {
472           if (wpa_s->p2p_mgmt)
473                     return;
474 
475           wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RSN, id);
476 }
477 
478 
wpas_notify_bss_wps_changed(struct wpa_supplicant * wpa_s,unsigned int id)479 void wpas_notify_bss_wps_changed(struct wpa_supplicant *wpa_s,
480                                          unsigned int id)
481 {
482           if (wpa_s->p2p_mgmt)
483                     return;
484 
485 #ifdef CONFIG_WPS
486           wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_WPS, id);
487 #endif /* CONFIG_WPS */
488 }
489 
490 
wpas_notify_bss_ies_changed(struct wpa_supplicant * wpa_s,unsigned int id)491 void wpas_notify_bss_ies_changed(struct wpa_supplicant *wpa_s,
492                                            unsigned int id)
493 {
494           if (wpa_s->p2p_mgmt)
495                     return;
496 
497           wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_IES, id);
498 }
499 
500 
wpas_notify_bss_rates_changed(struct wpa_supplicant * wpa_s,unsigned int id)501 void wpas_notify_bss_rates_changed(struct wpa_supplicant *wpa_s,
502                                            unsigned int id)
503 {
504           if (wpa_s->p2p_mgmt)
505                     return;
506 
507           wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_RATES, id);
508 }
509 
510 
wpas_notify_bss_seen(struct wpa_supplicant * wpa_s,unsigned int id)511 void wpas_notify_bss_seen(struct wpa_supplicant *wpa_s, unsigned int id)
512 {
513           if (wpa_s->p2p_mgmt)
514                     return;
515 
516           wpas_dbus_bss_signal_prop_changed(wpa_s, WPAS_DBUS_BSS_PROP_AGE, id);
517 }
518 
519 
wpas_notify_blob_added(struct wpa_supplicant * wpa_s,const char * name)520 void wpas_notify_blob_added(struct wpa_supplicant *wpa_s, const char *name)
521 {
522           if (wpa_s->p2p_mgmt)
523                     return;
524 
525           wpas_dbus_signal_blob_added(wpa_s, name);
526 }
527 
528 
wpas_notify_blob_removed(struct wpa_supplicant * wpa_s,const char * name)529 void wpas_notify_blob_removed(struct wpa_supplicant *wpa_s, const char *name)
530 {
531           if (wpa_s->p2p_mgmt)
532                     return;
533 
534           wpas_dbus_signal_blob_removed(wpa_s, name);
535 }
536 
537 
wpas_notify_debug_level_changed(struct wpa_global * global)538 void wpas_notify_debug_level_changed(struct wpa_global *global)
539 {
540           wpas_dbus_signal_debug_level_changed(global);
541 }
542 
543 
wpas_notify_debug_timestamp_changed(struct wpa_global * global)544 void wpas_notify_debug_timestamp_changed(struct wpa_global *global)
545 {
546           wpas_dbus_signal_debug_timestamp_changed(global);
547 }
548 
549 
wpas_notify_debug_show_keys_changed(struct wpa_global * global)550 void wpas_notify_debug_show_keys_changed(struct wpa_global *global)
551 {
552           wpas_dbus_signal_debug_show_keys_changed(global);
553 }
554 
555 
wpas_notify_suspend(struct wpa_global * global)556 void wpas_notify_suspend(struct wpa_global *global)
557 {
558           struct wpa_supplicant *wpa_s;
559 
560           os_get_time(&global->suspend_time);
561           wpa_printf(MSG_DEBUG, "System suspend notification");
562           for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
563                     wpa_drv_suspend(wpa_s);
564 }
565 
566 
wpas_notify_resume(struct wpa_global * global)567 void wpas_notify_resume(struct wpa_global *global)
568 {
569           struct os_time now;
570           int slept;
571           struct wpa_supplicant *wpa_s;
572 
573           if (global->suspend_time.sec == 0)
574                     slept = -1;
575           else {
576                     os_get_time(&now);
577                     slept = now.sec - global->suspend_time.sec;
578           }
579           wpa_printf(MSG_DEBUG, "System resume notification (slept %d seconds)",
580                        slept);
581 
582           for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
583                     wpa_drv_resume(wpa_s);
584                     if (wpa_s->wpa_state == WPA_DISCONNECTED)
585                               wpa_supplicant_req_scan(wpa_s, 0, 100000);
586           }
587 }
588 
589 
590 #ifdef CONFIG_P2P
591 
wpas_notify_p2p_find_stopped(struct wpa_supplicant * wpa_s)592 void wpas_notify_p2p_find_stopped(struct wpa_supplicant *wpa_s)
593 {
594           /* Notify P2P find has stopped */
595           wpas_dbus_signal_p2p_find_stopped(wpa_s);
596 }
597 
598 
wpas_notify_p2p_device_found(struct wpa_supplicant * wpa_s,const u8 * dev_addr,int new_device)599 void wpas_notify_p2p_device_found(struct wpa_supplicant *wpa_s,
600                                           const u8 *dev_addr, int new_device)
601 {
602           if (new_device) {
603                     /* Create the new peer object */
604                     wpas_dbus_register_peer(wpa_s, dev_addr);
605           }
606 
607           /* Notify a new peer has been detected*/
608           wpas_dbus_signal_peer_device_found(wpa_s, dev_addr);
609 }
610 
611 
wpas_notify_p2p_device_lost(struct wpa_supplicant * wpa_s,const u8 * dev_addr)612 void wpas_notify_p2p_device_lost(struct wpa_supplicant *wpa_s,
613                                          const u8 *dev_addr)
614 {
615           wpas_dbus_unregister_peer(wpa_s, dev_addr);
616 
617           /* Create signal on interface object*/
618           wpas_dbus_signal_peer_device_lost(wpa_s, dev_addr);
619 }
620 
621 
wpas_notify_p2p_group_removed(struct wpa_supplicant * wpa_s,const struct wpa_ssid * ssid,const char * role)622 void wpas_notify_p2p_group_removed(struct wpa_supplicant *wpa_s,
623                                            const struct wpa_ssid *ssid,
624                                            const char *role)
625 {
626           wpas_dbus_signal_p2p_group_removed(wpa_s, role);
627 
628           wpas_dbus_unregister_p2p_group(wpa_s, ssid);
629 }
630 
631 
wpas_notify_p2p_go_neg_req(struct wpa_supplicant * wpa_s,const u8 * src,u16 dev_passwd_id,u8 go_intent)632 void wpas_notify_p2p_go_neg_req(struct wpa_supplicant *wpa_s,
633                                         const u8 *src, u16 dev_passwd_id, u8 go_intent)
634 {
635           wpas_dbus_signal_p2p_go_neg_req(wpa_s, src, dev_passwd_id, go_intent);
636 }
637 
638 
wpas_notify_p2p_go_neg_completed(struct wpa_supplicant * wpa_s,struct p2p_go_neg_results * res)639 void wpas_notify_p2p_go_neg_completed(struct wpa_supplicant *wpa_s,
640                                               struct p2p_go_neg_results *res)
641 {
642           wpas_dbus_signal_p2p_go_neg_resp(wpa_s, res);
643 }
644 
645 
wpas_notify_p2p_invitation_result(struct wpa_supplicant * wpa_s,int status,const u8 * bssid)646 void wpas_notify_p2p_invitation_result(struct wpa_supplicant *wpa_s,
647                                                int status, const u8 *bssid)
648 {
649           wpas_dbus_signal_p2p_invitation_result(wpa_s, status, bssid);
650 }
651 
652 
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)653 void wpas_notify_p2p_sd_request(struct wpa_supplicant *wpa_s,
654                                         int freq, const u8 *sa, u8 dialog_token,
655                                         u16 update_indic, const u8 *tlvs,
656                                         size_t tlvs_len)
657 {
658           wpas_dbus_signal_p2p_sd_request(wpa_s, freq, sa, dialog_token,
659                                                   update_indic, tlvs, tlvs_len);
660 }
661 
662 
wpas_notify_p2p_sd_response(struct wpa_supplicant * wpa_s,const u8 * sa,u16 update_indic,const u8 * tlvs,size_t tlvs_len)663 void wpas_notify_p2p_sd_response(struct wpa_supplicant *wpa_s,
664                                          const u8 *sa, u16 update_indic,
665                                          const u8 *tlvs, size_t tlvs_len)
666 {
667           wpas_dbus_signal_p2p_sd_response(wpa_s, sa, update_indic,
668                                                    tlvs, tlvs_len);
669 }
670 
671 
672 /**
673  * wpas_notify_p2p_provision_discovery - Notification of provision discovery
674  * @dev_addr: Who sent the request or responded to our request.
675  * @request: Will be 1 if request, 0 for response.
676  * @status: Valid only in case of response (0 in case of success)
677  * @config_methods: WPS config methods
678  * @generated_pin: PIN to be displayed in case of WPS_CONFIG_DISPLAY method
679  *
680  * This can be used to notify:
681  * - Requests or responses
682  * - Various config methods
683  * - Failure condition in case of response
684  */
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)685 void wpas_notify_p2p_provision_discovery(struct wpa_supplicant *wpa_s,
686                                                    const u8 *dev_addr, int request,
687                                                    enum p2p_prov_disc_status status,
688                                                    u16 config_methods,
689                                                    unsigned int generated_pin)
690 {
691           wpas_dbus_signal_p2p_provision_discovery(wpa_s, dev_addr, request,
692                                                              status, config_methods,
693                                                              generated_pin);
694 }
695 
696 
wpas_notify_p2p_group_started(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid,int persistent,int client,const u8 * ip)697 void wpas_notify_p2p_group_started(struct wpa_supplicant *wpa_s,
698                                            struct wpa_ssid *ssid, int persistent,
699                                            int client, const u8 *ip)
700 {
701           /* Notify a group has been started */
702           wpas_dbus_register_p2p_group(wpa_s, ssid);
703 
704           wpas_dbus_signal_p2p_group_started(wpa_s, client, persistent, ip);
705 }
706 
707 
wpas_notify_p2p_group_formation_failure(struct wpa_supplicant * wpa_s,const char * reason)708 void wpas_notify_p2p_group_formation_failure(struct wpa_supplicant *wpa_s,
709                                                        const char *reason)
710 {
711           /* Notify a group formation failed */
712           wpas_dbus_signal_p2p_group_formation_failure(wpa_s, reason);
713 }
714 
715 
wpas_notify_p2p_wps_failed(struct wpa_supplicant * wpa_s,struct wps_event_fail * fail)716 void wpas_notify_p2p_wps_failed(struct wpa_supplicant *wpa_s,
717                                         struct wps_event_fail *fail)
718 {
719           wpas_dbus_signal_p2p_wps_failed(wpa_s, fail);
720 }
721 
722 
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)723 void wpas_notify_p2p_invitation_received(struct wpa_supplicant *wpa_s,
724                                                    const u8 *sa, const u8 *go_dev_addr,
725                                                    const u8 *bssid, int id, int op_freq)
726 {
727           /* Notify a P2P Invitation Request */
728           wpas_dbus_signal_p2p_invitation_received(wpa_s, sa, go_dev_addr, bssid,
729                                                              id, op_freq);
730 }
731 
732 #endif /* CONFIG_P2P */
733 
734 
wpas_notify_ap_sta_authorized(struct wpa_supplicant * wpa_s,const u8 * sta,const u8 * p2p_dev_addr)735 static void wpas_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s,
736                                                     const u8 *sta,
737                                                     const u8 *p2p_dev_addr)
738 {
739 #ifdef CONFIG_P2P
740           wpas_p2p_notify_ap_sta_authorized(wpa_s, p2p_dev_addr);
741 
742           /*
743            * Create 'peer-joined' signal on group object -- will also
744            * check P2P itself.
745            */
746           if (p2p_dev_addr)
747                     wpas_dbus_signal_p2p_peer_joined(wpa_s, p2p_dev_addr);
748 #endif /* CONFIG_P2P */
749 
750           /* Register the station */
751           wpas_dbus_register_sta(wpa_s, sta);
752 
753           /* Notify listeners a new station has been authorized */
754           wpas_dbus_signal_sta_authorized(wpa_s, sta);
755 }
756 
757 
wpas_notify_ap_sta_deauthorized(struct wpa_supplicant * wpa_s,const u8 * sta,const u8 * p2p_dev_addr)758 static void wpas_notify_ap_sta_deauthorized(struct wpa_supplicant *wpa_s,
759                                                       const u8 *sta,
760                                                       const u8 *p2p_dev_addr)
761 {
762 #ifdef CONFIG_P2P
763           /*
764            * Create 'peer-disconnected' signal on group object if this
765            * is a P2P group.
766            */
767           if (p2p_dev_addr)
768                     wpas_dbus_signal_p2p_peer_disconnected(wpa_s, p2p_dev_addr);
769 #endif /* CONFIG_P2P */
770 
771           /* Notify listeners a station has been deauthorized */
772           wpas_dbus_signal_sta_deauthorized(wpa_s, sta);
773 
774           /* Unregister the station */
775           wpas_dbus_unregister_sta(wpa_s, sta);
776 }
777 
778 
wpas_notify_sta_authorized(struct wpa_supplicant * wpa_s,const u8 * mac_addr,int authorized,const u8 * p2p_dev_addr)779 void wpas_notify_sta_authorized(struct wpa_supplicant *wpa_s,
780                                         const u8 *mac_addr, int authorized,
781                                         const u8 *p2p_dev_addr)
782 {
783           if (authorized)
784                     wpas_notify_ap_sta_authorized(wpa_s, mac_addr, p2p_dev_addr);
785           else
786                     wpas_notify_ap_sta_deauthorized(wpa_s, mac_addr, p2p_dev_addr);
787 }
788 
789 
wpas_notify_certification(struct wpa_supplicant * wpa_s,struct tls_cert_data * cert,const char * cert_hash)790 void wpas_notify_certification(struct wpa_supplicant *wpa_s,
791                                      struct tls_cert_data *cert,
792                                      const char *cert_hash)
793 {
794           int i;
795 
796           wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_EAP_PEER_CERT
797                     "depth=%d subject='%s'%s%s%s",
798                     cert->depth, cert->subject, cert_hash ? " hash=" : "",
799                     cert_hash ? cert_hash : "",
800                     cert->tod ? " tod=1" : "");
801 
802           if (cert->cert) {
803                     char *cert_hex;
804                     size_t len = wpabuf_len(cert->cert) * 2 + 1;
805                     cert_hex = os_malloc(len);
806                     if (cert_hex) {
807                               wpa_snprintf_hex(cert_hex, len, wpabuf_head(cert->cert),
808                                                    wpabuf_len(cert->cert));
809                               wpa_msg_ctrl(wpa_s, MSG_INFO,
810                                              WPA_EVENT_EAP_PEER_CERT
811                                              "depth=%d subject='%s' cert=%s",
812                                              cert->depth, cert->subject, cert_hex);
813                               os_free(cert_hex);
814                     }
815           }
816 
817           for (i = 0; i < cert->num_altsubject; i++)
818                     wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_EAP_PEER_ALT
819                               "depth=%d %s", cert->depth, cert->altsubject[i]);
820 
821           /* notify the new DBus API */
822           wpas_dbus_signal_certification(wpa_s, cert->depth, cert->subject,
823                                                cert->altsubject, cert->num_altsubject,
824                                                cert_hash, cert->cert);
825 }
826 
827 
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)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 
wpas_notify_eap_status(struct wpa_supplicant * wpa_s,const char * status,const char * parameter)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 
wpas_notify_eap_error(struct wpa_supplicant * wpa_s,int error_code)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 
wpas_notify_network_bssid_set_changed(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid)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 
wpas_notify_network_type_changed(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid)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 
wpas_notify_mesh_group_started(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid)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 
wpas_notify_mesh_group_removed(struct wpa_supplicant * wpa_s,const u8 * meshid,u8 meshid_len,u16 reason_code)902 void wpas_notify_mesh_group_removed(struct wpa_supplicant *wpa_s,
903                                             const u8 *meshid, u8 meshid_len,
904                                             u16 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 
wpas_notify_mesh_peer_connected(struct wpa_supplicant * wpa_s,const u8 * peer_addr)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 
wpas_notify_mesh_peer_disconnected(struct wpa_supplicant * wpa_s,const u8 * peer_addr,u16 reason_code)924 void wpas_notify_mesh_peer_disconnected(struct wpa_supplicant *wpa_s,
925                                                   const u8 *peer_addr, u16 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