• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * hidl interface for wpa_supplicant daemon
3  * Copyright (c) 2004-2016, Jouni Malinen <j@w1.fi>
4  * Copyright (c) 2004-2016, Roshan Pius <rpius@google.com>
5  *
6  * This software may be distributed under the terms of the BSD license.
7  * See README for more details.
8  */
9 
10 #include <hwbinder/IPCThreadState.h>
11 
12 #include <hidl/HidlTransportSupport.h>
13 #include "hidl_manager.h"
14 
15 extern "C"
16 {
17 #include "hidl.h"
18 #include "hidl_i.h"
19 #include "utils/common.h"
20 #include "utils/eloop.h"
21 #include "utils/includes.h"
22 #include "dpp.h"
23 }
24 
25 using android::hardware::configureRpcThreadpool;
26 using android::hardware::handleTransportPoll;
27 using android::hardware::setupTransportPolling;
28 using android::hardware::wifi::supplicant::V1_3::DppFailureCode;
29 using android::hardware::wifi::supplicant::V1_3::DppProgressCode;
30 using android::hardware::wifi::supplicant::V1_3::DppSuccessCode;
31 using android::hardware::wifi::supplicant::V1_4::implementation::HidlManager;
32 
33 static void wpas_hidl_notify_dpp_failure(struct wpa_supplicant *wpa_s, DppFailureCode code);
34 static void wpas_hidl_notify_dpp_progress(struct wpa_supplicant *wpa_s, DppProgressCode code);
35 static void wpas_hidl_notify_dpp_success(struct wpa_supplicant *wpa_s, DppSuccessCode code);
36 
wpas_hidl_sock_handler(int sock,void *,void *)37 void wpas_hidl_sock_handler(
38     int sock, void * /* eloop_ctx */, void * /* sock_ctx */)
39 {
40 	handleTransportPoll(sock);
41 }
42 
wpas_hidl_init(struct wpa_global * global)43 struct wpas_hidl_priv *wpas_hidl_init(struct wpa_global *global)
44 {
45 	struct wpas_hidl_priv *priv;
46 	HidlManager *hidl_manager;
47 
48 	priv = (wpas_hidl_priv *)os_zalloc(sizeof(*priv));
49 	if (!priv)
50 		return NULL;
51 	priv->global = global;
52 
53 	wpa_printf(MSG_DEBUG, "Initing hidl control");
54 
55 	configureRpcThreadpool(1, true /* callerWillJoin */);
56 	priv->hidl_fd = setupTransportPolling();
57 	if (priv->hidl_fd < 0)
58 		goto err;
59 
60 	wpa_printf(MSG_INFO, "Processing hidl events on FD %d", priv->hidl_fd);
61 	// Look for read events from the hidl socket in the eloop.
62 	if (eloop_register_read_sock(
63 		priv->hidl_fd, wpas_hidl_sock_handler, global, priv) < 0)
64 		goto err;
65 
66 	hidl_manager = HidlManager::getInstance();
67 	if (!hidl_manager)
68 		goto err;
69 	if (hidl_manager->registerHidlService(global)) {
70 		goto err;
71 	}
72 	// We may not need to store this hidl manager reference in the
73 	// global data strucure because we've made it a singleton class.
74 	priv->hidl_manager = (void *)hidl_manager;
75 
76 	return priv;
77 err:
78 	wpas_hidl_deinit(priv);
79 	return NULL;
80 }
81 
wpas_hidl_deinit(struct wpas_hidl_priv * priv)82 void wpas_hidl_deinit(struct wpas_hidl_priv *priv)
83 {
84 	if (!priv)
85 		return;
86 
87 	wpa_printf(MSG_DEBUG, "Deiniting hidl control");
88 
89 	HidlManager::destroyInstance();
90 	eloop_unregister_read_sock(priv->hidl_fd);
91 	os_free(priv);
92 }
93 
wpas_hidl_register_interface(struct wpa_supplicant * wpa_s)94 int wpas_hidl_register_interface(struct wpa_supplicant *wpa_s)
95 {
96 	if (!wpa_s || !wpa_s->global->hidl)
97 		return 1;
98 
99 	wpa_printf(
100 	    MSG_DEBUG, "Registering interface to hidl control: %s",
101 	    wpa_s->ifname);
102 
103 	HidlManager *hidl_manager = HidlManager::getInstance();
104 	if (!hidl_manager)
105 		return 1;
106 
107 	return hidl_manager->registerInterface(wpa_s);
108 }
109 
wpas_hidl_unregister_interface(struct wpa_supplicant * wpa_s)110 int wpas_hidl_unregister_interface(struct wpa_supplicant *wpa_s)
111 {
112 	if (!wpa_s || !wpa_s->global->hidl)
113 		return 1;
114 
115 	wpa_printf(
116 	    MSG_DEBUG, "Deregistering interface from hidl control: %s",
117 	    wpa_s->ifname);
118 
119 	HidlManager *hidl_manager = HidlManager::getInstance();
120 	if (!hidl_manager)
121 		return 1;
122 
123 	return hidl_manager->unregisterInterface(wpa_s);
124 }
125 
wpas_hidl_register_network(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid)126 int wpas_hidl_register_network(
127     struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
128 {
129 	if (!wpa_s || !wpa_s->global->hidl || !ssid)
130 		return 1;
131 
132 	wpa_printf(
133 	    MSG_DEBUG, "Registering network to hidl control: %d", ssid->id);
134 
135 	HidlManager *hidl_manager = HidlManager::getInstance();
136 	if (!hidl_manager)
137 		return 1;
138 
139 	return hidl_manager->registerNetwork(wpa_s, ssid);
140 }
141 
wpas_hidl_unregister_network(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid)142 int wpas_hidl_unregister_network(
143     struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
144 {
145 	if (!wpa_s || !wpa_s->global->hidl || !ssid)
146 		return 1;
147 
148 	wpa_printf(
149 	    MSG_DEBUG, "Deregistering network from hidl control: %d", ssid->id);
150 
151 	HidlManager *hidl_manager = HidlManager::getInstance();
152 	if (!hidl_manager)
153 		return 1;
154 
155 	return hidl_manager->unregisterNetwork(wpa_s, ssid);
156 }
157 
wpas_hidl_notify_state_changed(struct wpa_supplicant * wpa_s)158 int wpas_hidl_notify_state_changed(struct wpa_supplicant *wpa_s)
159 {
160 	if (!wpa_s || !wpa_s->global->hidl)
161 		return 1;
162 
163 	wpa_printf(
164 	    MSG_DEBUG, "Notifying state change event to hidl control: %d",
165 	    wpa_s->wpa_state);
166 
167 	HidlManager *hidl_manager = HidlManager::getInstance();
168 	if (!hidl_manager)
169 		return 1;
170 
171 	return hidl_manager->notifyStateChange(wpa_s);
172 }
173 
wpas_hidl_notify_network_request(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid,enum wpa_ctrl_req_type rtype,const char * default_txt)174 int wpas_hidl_notify_network_request(
175     struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
176     enum wpa_ctrl_req_type rtype, const char *default_txt)
177 {
178 	if (!wpa_s || !wpa_s->global->hidl || !ssid)
179 		return 1;
180 
181 	wpa_printf(
182 	    MSG_DEBUG, "Notifying network request to hidl control: %d",
183 	    ssid->id);
184 
185 	HidlManager *hidl_manager = HidlManager::getInstance();
186 	if (!hidl_manager)
187 		return 1;
188 
189 	return hidl_manager->notifyNetworkRequest(
190 	    wpa_s, ssid, rtype, default_txt);
191 }
192 
wpas_hidl_notify_anqp_query_done(struct wpa_supplicant * wpa_s,const u8 * bssid,const char * result,const struct wpa_bss_anqp * anqp)193 void wpas_hidl_notify_anqp_query_done(
194     struct wpa_supplicant *wpa_s, const u8 *bssid, const char *result,
195     const struct wpa_bss_anqp *anqp)
196 {
197 	if (!wpa_s || !wpa_s->global->hidl || !bssid || !result || !anqp)
198 		return;
199 
200 	wpa_printf(
201 	    MSG_DEBUG,
202 	    "Notifying ANQP query done to hidl control: " MACSTR "result: %s",
203 	    MAC2STR(bssid), result);
204 
205 	HidlManager *hidl_manager = HidlManager::getInstance();
206 	if (!hidl_manager)
207 		return;
208 
209 	hidl_manager->notifyAnqpQueryDone(wpa_s, bssid, result, anqp);
210 }
211 
wpas_hidl_notify_hs20_icon_query_done(struct wpa_supplicant * wpa_s,const u8 * bssid,const char * file_name,const u8 * image,u32 image_length)212 void wpas_hidl_notify_hs20_icon_query_done(
213     struct wpa_supplicant *wpa_s, const u8 *bssid, const char *file_name,
214     const u8 *image, u32 image_length)
215 {
216 	if (!wpa_s || !wpa_s->global->hidl || !bssid || !file_name || !image)
217 		return;
218 
219 	wpa_printf(
220 	    MSG_DEBUG,
221 	    "Notifying HS20 icon query done to hidl control: " MACSTR
222 	    "file_name: %s",
223 	    MAC2STR(bssid), file_name);
224 
225 	HidlManager *hidl_manager = HidlManager::getInstance();
226 	if (!hidl_manager)
227 		return;
228 
229 	hidl_manager->notifyHs20IconQueryDone(
230 	    wpa_s, bssid, file_name, image, image_length);
231 }
232 
wpas_hidl_notify_hs20_rx_subscription_remediation(struct wpa_supplicant * wpa_s,const char * url,u8 osu_method)233 void wpas_hidl_notify_hs20_rx_subscription_remediation(
234     struct wpa_supplicant *wpa_s, const char *url, u8 osu_method)
235 {
236 	if (!wpa_s || !wpa_s->global->hidl || !url)
237 		return;
238 
239 	wpa_printf(
240 	    MSG_DEBUG,
241 	    "Notifying HS20 subscription remediation rx to hidl control: %s",
242 	    url);
243 
244 	HidlManager *hidl_manager = HidlManager::getInstance();
245 	if (!hidl_manager)
246 		return;
247 
248 	hidl_manager->notifyHs20RxSubscriptionRemediation(
249 	    wpa_s, url, osu_method);
250 }
251 
wpas_hidl_notify_hs20_rx_deauth_imminent_notice(struct wpa_supplicant * wpa_s,u8 code,u16 reauth_delay,const char * url)252 void wpas_hidl_notify_hs20_rx_deauth_imminent_notice(
253     struct wpa_supplicant *wpa_s, u8 code, u16 reauth_delay, const char *url)
254 {
255 	if (!wpa_s || !wpa_s->global->hidl)
256 		return;
257 
258 	wpa_printf(
259 	    MSG_DEBUG,
260 	    "Notifying HS20 deauth imminent notice rx to hidl control: %s",
261 	    url ? url : "<no URL>");
262 
263 	HidlManager *hidl_manager = HidlManager::getInstance();
264 	if (!hidl_manager)
265 		return;
266 
267 	hidl_manager->notifyHs20RxDeauthImminentNotice(
268 	    wpa_s, code, reauth_delay, url);
269 }
270 
wpas_hidl_notify_hs20_rx_terms_and_conditions_acceptance(struct wpa_supplicant * wpa_s,const char * url)271 void wpas_hidl_notify_hs20_rx_terms_and_conditions_acceptance(
272 		struct wpa_supplicant *wpa_s, const char *url)
273 {
274 	if (!wpa_s || !wpa_s->global->hidl || !url)
275 		return;
276 
277 	wpa_printf(MSG_DEBUG,
278 			"Notifying HS20 terms and conditions acceptance rx to hidl control: %s",
279 			url);
280 
281 	HidlManager *hidl_manager = HidlManager::getInstance();
282 	if (!hidl_manager)
283 		return;
284 
285 	hidl_manager->notifyHs20RxTermsAndConditionsAcceptance(wpa_s, url);
286 }
287 
wpas_hidl_notify_disconnect_reason(struct wpa_supplicant * wpa_s)288 void wpas_hidl_notify_disconnect_reason(struct wpa_supplicant *wpa_s)
289 {
290 	if (!wpa_s)
291 		return;
292 
293 	wpa_printf(
294 	    MSG_DEBUG, "Notifying disconnect reason to hidl control: %d",
295 	    wpa_s->disconnect_reason);
296 
297 	HidlManager *hidl_manager = HidlManager::getInstance();
298 	if (!hidl_manager)
299 		return;
300 
301 	hidl_manager->notifyDisconnectReason(wpa_s);
302 }
303 
wpas_hidl_notify_assoc_reject(struct wpa_supplicant * wpa_s,const u8 * bssid,u8 timed_out,const u8 * assoc_resp_ie,size_t assoc_resp_ie_len)304 void wpas_hidl_notify_assoc_reject(struct wpa_supplicant *wpa_s,
305     const u8 *bssid, u8 timed_out, const u8 *assoc_resp_ie, size_t assoc_resp_ie_len)
306 {
307 	if (!wpa_s)
308 		return;
309 
310 	wpa_printf(
311 	    MSG_DEBUG, "Notifying assoc reject to hidl control: %d",
312 	    wpa_s->assoc_status_code);
313 
314 	HidlManager *hidl_manager = HidlManager::getInstance();
315 	if (!hidl_manager)
316 		return;
317 
318 	hidl_manager->notifyAssocReject(wpa_s, bssid, timed_out, assoc_resp_ie, assoc_resp_ie_len);
319 }
320 
wpas_hidl_notify_auth_timeout(struct wpa_supplicant * wpa_s)321 void wpas_hidl_notify_auth_timeout(struct wpa_supplicant *wpa_s)
322 {
323 	if (!wpa_s)
324 		return;
325 
326 	wpa_printf(MSG_DEBUG, "Notifying auth timeout to hidl control");
327 
328 	HidlManager *hidl_manager = HidlManager::getInstance();
329 	if (!hidl_manager)
330 		return;
331 
332 	hidl_manager->notifyAuthTimeout(wpa_s);
333 }
334 
wpas_hidl_notify_bssid_changed(struct wpa_supplicant * wpa_s)335 void wpas_hidl_notify_bssid_changed(struct wpa_supplicant *wpa_s)
336 {
337 	if (!wpa_s)
338 		return;
339 
340 	wpa_printf(MSG_DEBUG, "Notifying bssid changed to hidl control");
341 
342 	HidlManager *hidl_manager = HidlManager::getInstance();
343 	if (!hidl_manager)
344 		return;
345 
346 	hidl_manager->notifyBssidChanged(wpa_s);
347 }
348 
wpas_hidl_notify_wps_event_fail(struct wpa_supplicant * wpa_s,uint8_t * peer_macaddr,uint16_t config_error,uint16_t error_indication)349 void wpas_hidl_notify_wps_event_fail(
350     struct wpa_supplicant *wpa_s, uint8_t *peer_macaddr, uint16_t config_error,
351     uint16_t error_indication)
352 {
353 	if (!wpa_s || !peer_macaddr)
354 		return;
355 
356 	wpa_printf(
357 	    MSG_DEBUG, "Notifying Wps event fail to hidl control: %d, %d",
358 	    config_error, error_indication);
359 
360 	HidlManager *hidl_manager = HidlManager::getInstance();
361 	if (!hidl_manager)
362 		return;
363 
364 	hidl_manager->notifyWpsEventFail(
365 	    wpa_s, peer_macaddr, config_error, error_indication);
366 }
367 
wpas_hidl_notify_wps_event_success(struct wpa_supplicant * wpa_s)368 void wpas_hidl_notify_wps_event_success(struct wpa_supplicant *wpa_s)
369 {
370 	if (!wpa_s)
371 		return;
372 
373 	wpa_printf(MSG_DEBUG, "Notifying Wps event success to hidl control");
374 
375 	HidlManager *hidl_manager = HidlManager::getInstance();
376 	if (!hidl_manager)
377 		return;
378 
379 	hidl_manager->notifyWpsEventSuccess(wpa_s);
380 }
381 
wpas_hidl_notify_wps_event_pbc_overlap(struct wpa_supplicant * wpa_s)382 void wpas_hidl_notify_wps_event_pbc_overlap(struct wpa_supplicant *wpa_s)
383 {
384 	if (!wpa_s)
385 		return;
386 
387 	wpa_printf(
388 	    MSG_DEBUG, "Notifying Wps event PBC overlap to hidl control");
389 
390 	HidlManager *hidl_manager = HidlManager::getInstance();
391 	if (!hidl_manager)
392 		return;
393 
394 	hidl_manager->notifyWpsEventPbcOverlap(wpa_s);
395 }
396 
wpas_hidl_notify_p2p_device_found(struct wpa_supplicant * wpa_s,const u8 * addr,const struct p2p_peer_info * info,const u8 * peer_wfd_device_info,u8 peer_wfd_device_info_len,const u8 * peer_wfd_r2_device_info,u8 peer_wfd_r2_device_info_len)397 void wpas_hidl_notify_p2p_device_found(
398     struct wpa_supplicant *wpa_s, const u8 *addr,
399     const struct p2p_peer_info *info, const u8 *peer_wfd_device_info,
400     u8 peer_wfd_device_info_len, const u8 *peer_wfd_r2_device_info,
401     u8 peer_wfd_r2_device_info_len)
402 {
403 	if (!wpa_s || !addr || !info)
404 		return;
405 
406 	wpa_printf(
407 	    MSG_DEBUG, "Notifying P2P device found to hidl control " MACSTR,
408 	    MAC2STR(info->p2p_device_addr));
409 
410 	HidlManager *hidl_manager = HidlManager::getInstance();
411 	if (!hidl_manager)
412 		return;
413 
414 	hidl_manager->notifyP2pDeviceFound(
415 	    wpa_s, addr, info, peer_wfd_device_info,
416 	    peer_wfd_device_info_len, peer_wfd_r2_device_info,
417 	    peer_wfd_r2_device_info_len);
418 }
419 
wpas_hidl_notify_p2p_device_lost(struct wpa_supplicant * wpa_s,const u8 * p2p_device_addr)420 void wpas_hidl_notify_p2p_device_lost(
421     struct wpa_supplicant *wpa_s, const u8 *p2p_device_addr)
422 {
423 	if (!wpa_s || !p2p_device_addr)
424 		return;
425 
426 	wpa_printf(
427 	    MSG_DEBUG, "Notifying P2P device lost to hidl control " MACSTR,
428 	    MAC2STR(p2p_device_addr));
429 
430 	HidlManager *hidl_manager = HidlManager::getInstance();
431 	if (!hidl_manager)
432 		return;
433 
434 	hidl_manager->notifyP2pDeviceLost(wpa_s, p2p_device_addr);
435 }
436 
wpas_hidl_notify_p2p_find_stopped(struct wpa_supplicant * wpa_s)437 void wpas_hidl_notify_p2p_find_stopped(struct wpa_supplicant *wpa_s)
438 {
439 	if (!wpa_s)
440 		return;
441 
442 	wpa_printf(MSG_DEBUG, "Notifying P2P find stop to hidl control");
443 
444 	HidlManager *hidl_manager = HidlManager::getInstance();
445 	if (!hidl_manager)
446 		return;
447 
448 	hidl_manager->notifyP2pFindStopped(wpa_s);
449 }
450 
wpas_hidl_notify_p2p_go_neg_req(struct wpa_supplicant * wpa_s,const u8 * src_addr,u16 dev_passwd_id,u8 go_intent)451 void wpas_hidl_notify_p2p_go_neg_req(
452     struct wpa_supplicant *wpa_s, const u8 *src_addr, u16 dev_passwd_id,
453     u8 go_intent)
454 {
455 	if (!wpa_s || !src_addr)
456 		return;
457 
458 	wpa_printf(
459 	    MSG_DEBUG,
460 	    "Notifying P2P GO negotiation request to hidl control " MACSTR,
461 	    MAC2STR(src_addr));
462 
463 	HidlManager *hidl_manager = HidlManager::getInstance();
464 	if (!hidl_manager)
465 		return;
466 
467 	hidl_manager->notifyP2pGoNegReq(
468 	    wpa_s, src_addr, dev_passwd_id, go_intent);
469 }
470 
wpas_hidl_notify_p2p_go_neg_completed(struct wpa_supplicant * wpa_s,const struct p2p_go_neg_results * res)471 void wpas_hidl_notify_p2p_go_neg_completed(
472     struct wpa_supplicant *wpa_s, const struct p2p_go_neg_results *res)
473 {
474 	if (!wpa_s || !res)
475 		return;
476 
477 	wpa_printf(
478 	    MSG_DEBUG,
479 	    "Notifying P2P GO negotiation completed to hidl control: %d",
480 	    res->status);
481 
482 	HidlManager *hidl_manager = HidlManager::getInstance();
483 	if (!hidl_manager)
484 		return;
485 
486 	hidl_manager->notifyP2pGoNegCompleted(wpa_s, res);
487 }
488 
wpas_hidl_notify_p2p_group_formation_failure(struct wpa_supplicant * wpa_s,const char * reason)489 void wpas_hidl_notify_p2p_group_formation_failure(
490     struct wpa_supplicant *wpa_s, const char *reason)
491 {
492 	if (!wpa_s || !reason)
493 		return;
494 
495 	wpa_printf(
496 	    MSG_DEBUG,
497 	    "Notifying P2P Group formation failure to hidl control: %s",
498 	    reason);
499 
500 	HidlManager *hidl_manager = HidlManager::getInstance();
501 	if (!hidl_manager)
502 		return;
503 
504 	hidl_manager->notifyP2pGroupFormationFailure(wpa_s, reason);
505 }
506 
wpas_hidl_notify_p2p_group_started(struct wpa_supplicant * wpa_s,const struct wpa_ssid * ssid,int persistent,int client)507 void wpas_hidl_notify_p2p_group_started(
508     struct wpa_supplicant *wpa_s, const struct wpa_ssid *ssid, int persistent,
509     int client)
510 {
511 	if (!wpa_s || !ssid)
512 		return;
513 
514 	wpa_printf(
515 	    MSG_DEBUG, "Notifying P2P Group start to hidl control: %d",
516 	    ssid->id);
517 
518 	HidlManager *hidl_manager = HidlManager::getInstance();
519 	if (!hidl_manager)
520 		return;
521 
522 	hidl_manager->notifyP2pGroupStarted(wpa_s, ssid, persistent, client);
523 }
524 
wpas_hidl_notify_p2p_group_removed(struct wpa_supplicant * wpa_s,const struct wpa_ssid * ssid,const char * role)525 void wpas_hidl_notify_p2p_group_removed(
526     struct wpa_supplicant *wpa_s, const struct wpa_ssid *ssid, const char *role)
527 {
528 	if (!wpa_s || !ssid || !role)
529 		return;
530 
531 	wpa_printf(
532 	    MSG_DEBUG, "Notifying P2P Group removed to hidl control: %d",
533 	    ssid->id);
534 
535 	HidlManager *hidl_manager = HidlManager::getInstance();
536 	if (!hidl_manager)
537 		return;
538 
539 	hidl_manager->notifyP2pGroupRemoved(wpa_s, ssid, role);
540 }
541 
wpas_hidl_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)542 void wpas_hidl_notify_p2p_invitation_received(
543     struct wpa_supplicant *wpa_s, const u8 *sa, const u8 *go_dev_addr,
544     const u8 *bssid, int id, int op_freq)
545 {
546 	if (!wpa_s || !sa || !go_dev_addr || !bssid)
547 		return;
548 
549 	wpa_printf(
550 	    MSG_DEBUG,
551 	    "Notifying P2P invitation received to hidl control: %d " MACSTR, id,
552 	    MAC2STR(bssid));
553 
554 	HidlManager *hidl_manager = HidlManager::getInstance();
555 	if (!hidl_manager)
556 		return;
557 
558 	hidl_manager->notifyP2pInvitationReceived(
559 	    wpa_s, sa, go_dev_addr, bssid, id, op_freq);
560 }
561 
wpas_hidl_notify_p2p_invitation_result(struct wpa_supplicant * wpa_s,int status,const u8 * bssid)562 void wpas_hidl_notify_p2p_invitation_result(
563     struct wpa_supplicant *wpa_s, int status, const u8 *bssid)
564 {
565 	if (!wpa_s)
566 		return;
567 	if (bssid) {
568 		wpa_printf(
569 		    MSG_DEBUG,
570 		    "Notifying P2P invitation result to hidl control: " MACSTR,
571 		    MAC2STR(bssid));
572 	} else {
573 		wpa_printf(
574 		    MSG_DEBUG,
575 		    "Notifying P2P invitation result to hidl control: NULL "
576 		    "bssid");
577 	}
578 
579 	HidlManager *hidl_manager = HidlManager::getInstance();
580 	if (!hidl_manager)
581 		return;
582 
583 	hidl_manager->notifyP2pInvitationResult(wpa_s, status, bssid);
584 }
585 
wpas_hidl_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)586 void wpas_hidl_notify_p2p_provision_discovery(
587     struct wpa_supplicant *wpa_s, const u8 *dev_addr, int request,
588     enum p2p_prov_disc_status status, u16 config_methods,
589     unsigned int generated_pin)
590 {
591 	if (!wpa_s || !dev_addr)
592 		return;
593 
594 	wpa_printf(
595 	    MSG_DEBUG,
596 	    "Notifying P2P provision discovery to hidl control " MACSTR,
597 	    MAC2STR(dev_addr));
598 
599 	HidlManager *hidl_manager = HidlManager::getInstance();
600 	if (!hidl_manager)
601 		return;
602 
603 	hidl_manager->notifyP2pProvisionDiscovery(
604 	    wpa_s, dev_addr, request, status, config_methods, generated_pin);
605 }
606 
wpas_hidl_notify_p2p_sd_response(struct wpa_supplicant * wpa_s,const u8 * sa,u16 update_indic,const u8 * tlvs,size_t tlvs_len)607 void wpas_hidl_notify_p2p_sd_response(
608     struct wpa_supplicant *wpa_s, const u8 *sa, u16 update_indic,
609     const u8 *tlvs, size_t tlvs_len)
610 {
611 	if (!wpa_s || !sa || !tlvs)
612 		return;
613 
614 	wpa_printf(
615 	    MSG_DEBUG,
616 	    "Notifying P2P service discovery response to hidl control " MACSTR,
617 	    MAC2STR(sa));
618 
619 	HidlManager *hidl_manager = HidlManager::getInstance();
620 	if (!hidl_manager)
621 		return;
622 
623 	hidl_manager->notifyP2pSdResponse(
624 	    wpa_s, sa, update_indic, tlvs, tlvs_len);
625 }
626 
wpas_hidl_notify_ap_sta_authorized(struct wpa_supplicant * wpa_s,const u8 * sta,const u8 * p2p_dev_addr)627 void wpas_hidl_notify_ap_sta_authorized(
628     struct wpa_supplicant *wpa_s, const u8 *sta, const u8 *p2p_dev_addr)
629 {
630 	if (!wpa_s || !sta)
631 		return;
632 
633 	wpa_printf(
634 	    MSG_DEBUG,
635 	    "Notifying P2P AP STA authorized to hidl control " MACSTR,
636 	    MAC2STR(sta));
637 
638 	HidlManager *hidl_manager = HidlManager::getInstance();
639 	if (!hidl_manager)
640 		return;
641 
642 	hidl_manager->notifyApStaAuthorized(wpa_s, sta, p2p_dev_addr);
643 }
644 
wpas_hidl_notify_ap_sta_deauthorized(struct wpa_supplicant * wpa_s,const u8 * sta,const u8 * p2p_dev_addr)645 void wpas_hidl_notify_ap_sta_deauthorized(
646     struct wpa_supplicant *wpa_s, const u8 *sta, const u8 *p2p_dev_addr)
647 {
648 	if (!wpa_s || !sta)
649 		return;
650 
651 	wpa_printf(
652 	    MSG_DEBUG,
653 	    "Notifying P2P AP STA deauthorized to hidl control " MACSTR,
654 	    MAC2STR(sta));
655 
656 	HidlManager *hidl_manager = HidlManager::getInstance();
657 	if (!hidl_manager)
658 		return;
659 
660 	hidl_manager->notifyApStaDeauthorized(wpa_s, sta, p2p_dev_addr);
661 }
662 
wpas_hidl_notify_eap_error(struct wpa_supplicant * wpa_s,int error_code)663 void wpas_hidl_notify_eap_error(struct wpa_supplicant *wpa_s, int error_code)
664 {
665 	if (!wpa_s)
666 		return;
667 
668 	wpa_printf(MSG_DEBUG, "Notifying EAP Error: %d ", error_code);
669 
670 	HidlManager *hidl_manager = HidlManager::getInstance();
671 	if (!hidl_manager)
672 		return;
673 
674 	hidl_manager->notifyEapError(wpa_s, error_code);
675 }
676 
wpas_hidl_notify_dpp_config_received(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid)677 void wpas_hidl_notify_dpp_config_received(struct wpa_supplicant *wpa_s,
678 	    struct wpa_ssid *ssid)
679 {
680 	if (!wpa_s || !ssid)
681 		return;
682 
683 	wpa_printf(
684 	    MSG_DEBUG,
685 	    "Notifying DPP configuration received for SSID %d", ssid->id);
686 
687 	HidlManager *hidl_manager = HidlManager::getInstance();
688 	if (!hidl_manager)
689 		return;
690 
691 	hidl_manager->notifyDppConfigReceived(wpa_s, ssid);
692 }
693 
wpas_hidl_notify_dpp_config_sent(struct wpa_supplicant * wpa_s)694 void wpas_hidl_notify_dpp_config_sent(struct wpa_supplicant *wpa_s)
695 {
696 	wpas_hidl_notify_dpp_success(wpa_s, DppSuccessCode::CONFIGURATION_SENT);
697 }
698 
699 /* DPP Progress notifications */
wpas_hidl_notify_dpp_auth_success(struct wpa_supplicant * wpa_s)700 void wpas_hidl_notify_dpp_auth_success(struct wpa_supplicant *wpa_s)
701 {
702 	wpas_hidl_notify_dpp_progress(wpa_s, DppProgressCode::AUTHENTICATION_SUCCESS);
703 }
704 
wpas_hidl_notify_dpp_resp_pending(struct wpa_supplicant * wpa_s)705 void wpas_hidl_notify_dpp_resp_pending(struct wpa_supplicant *wpa_s)
706 {
707 	wpas_hidl_notify_dpp_progress(wpa_s, DppProgressCode::RESPONSE_PENDING);
708 }
709 
710 /* DPP Failure notifications */
wpas_hidl_notify_dpp_not_compatible(struct wpa_supplicant * wpa_s)711 void wpas_hidl_notify_dpp_not_compatible(struct wpa_supplicant *wpa_s)
712 {
713 	wpas_hidl_notify_dpp_failure(wpa_s, DppFailureCode::NOT_COMPATIBLE);
714 }
715 
wpas_hidl_notify_dpp_missing_auth(struct wpa_supplicant * wpa_s)716 void wpas_hidl_notify_dpp_missing_auth(struct wpa_supplicant *wpa_s)
717 {
718 	wpas_hidl_notify_dpp_failure(wpa_s, DppFailureCode::AUTHENTICATION);
719 }
720 
wpas_hidl_notify_dpp_configuration_failure(struct wpa_supplicant * wpa_s)721 void wpas_hidl_notify_dpp_configuration_failure(struct wpa_supplicant *wpa_s)
722 {
723 	wpas_hidl_notify_dpp_failure(wpa_s, DppFailureCode::CONFIGURATION);
724 }
725 
wpas_hidl_notify_dpp_timeout(struct wpa_supplicant * wpa_s)726 void wpas_hidl_notify_dpp_timeout(struct wpa_supplicant *wpa_s)
727 {
728 	wpas_hidl_notify_dpp_failure(wpa_s, DppFailureCode::TIMEOUT);
729 }
730 
wpas_hidl_notify_dpp_auth_failure(struct wpa_supplicant * wpa_s)731 void wpas_hidl_notify_dpp_auth_failure(struct wpa_supplicant *wpa_s)
732 {
733 	wpas_hidl_notify_dpp_failure(wpa_s, DppFailureCode::AUTHENTICATION);
734 }
735 
wpas_hidl_notify_dpp_fail(struct wpa_supplicant * wpa_s)736 void wpas_hidl_notify_dpp_fail(struct wpa_supplicant *wpa_s)
737 {
738 	wpas_hidl_notify_dpp_failure(wpa_s, DppFailureCode::FAILURE);
739 }
740 
wpas_hidl_notify_dpp_config_sent_wait_response(struct wpa_supplicant * wpa_s)741 void wpas_hidl_notify_dpp_config_sent_wait_response(struct wpa_supplicant *wpa_s)
742 {
743 	wpas_hidl_notify_dpp_progress(wpa_s, DppProgressCode::CONFIGURATION_SENT_WAITING_RESPONSE);
744 }
745 
746 /* DPP notification helper functions */
wpas_hidl_notify_dpp_failure(struct wpa_supplicant * wpa_s,DppFailureCode code)747 static void wpas_hidl_notify_dpp_failure(struct wpa_supplicant *wpa_s, DppFailureCode code)
748 {
749 	if (!wpa_s)
750 		return;
751 
752 	wpa_printf(
753 	    MSG_DEBUG,
754 	    "Notifying DPP failure event %d", code);
755 
756 	HidlManager *hidl_manager = HidlManager::getInstance();
757 	if (!hidl_manager)
758 		return;
759 
760 	hidl_manager->notifyDppFailure(wpa_s, code);
761 }
762 
wpas_hidl_notify_dpp_progress(struct wpa_supplicant * wpa_s,DppProgressCode code)763 static void wpas_hidl_notify_dpp_progress(struct wpa_supplicant *wpa_s, DppProgressCode code)
764 {
765 	if (!wpa_s)
766 		return;
767 
768 	wpa_printf(
769 	    MSG_DEBUG,
770 	    "Notifying DPP progress event %d", code);
771 
772 	HidlManager *hidl_manager = HidlManager::getInstance();
773 	if (!hidl_manager)
774 		return;
775 
776 	hidl_manager->notifyDppProgress(wpa_s, code);
777 }
778 
wpas_hidl_notify_dpp_config_accepted(struct wpa_supplicant * wpa_s)779 void wpas_hidl_notify_dpp_config_accepted(struct wpa_supplicant *wpa_s)
780 {
781 	wpas_hidl_notify_dpp_progress(wpa_s, DppProgressCode::CONFIGURATION_ACCEPTED);
782 }
783 
wpas_hidl_notify_dpp_config_applied(struct wpa_supplicant * wpa_s)784 static void wpas_hidl_notify_dpp_config_applied(struct wpa_supplicant *wpa_s)
785 {
786 	wpas_hidl_notify_dpp_success(wpa_s, DppSuccessCode::CONFIGURATION_APPLIED);
787 }
788 
wpas_hidl_notify_dpp_success(struct wpa_supplicant * wpa_s,DppSuccessCode code)789 static void wpas_hidl_notify_dpp_success(struct wpa_supplicant *wpa_s, DppSuccessCode code)
790 {
791 	if (!wpa_s)
792 		return;
793 
794 	wpa_printf(
795 	    MSG_DEBUG,
796 	    "Notifying DPP progress event %d", code);
797 
798 	HidlManager *hidl_manager = HidlManager::getInstance();
799 	if (!hidl_manager)
800 		return;
801 
802 	hidl_manager->notifyDppSuccess(wpa_s, code);
803 }
804 
wpas_hidl_notify_dpp_config_rejected(struct wpa_supplicant * wpa_s)805 void wpas_hidl_notify_dpp_config_rejected(struct wpa_supplicant *wpa_s)
806 {
807 	wpas_hidl_notify_dpp_failure(wpa_s, DppFailureCode::CONFIGURATION_REJECTED);
808 }
809 
wpas_hidl_notify_dpp_no_ap_failure(struct wpa_supplicant * wpa_s,const char * ssid,const char * channel_list,unsigned short band_list[],int size)810 static void wpas_hidl_notify_dpp_no_ap_failure(struct wpa_supplicant *wpa_s,
811 		const char *ssid, const char *channel_list, unsigned short band_list[],
812 		int size)
813 {
814 	if (!wpa_s)
815 		return;
816 
817 	wpa_printf(MSG_DEBUG,
818 			"Notifying DPP NO AP event for SSID %s\nTried channels: %s",
819 			ssid ? ssid : "N/A", channel_list ? channel_list : "N/A");
820 
821 	HidlManager *hidl_manager = HidlManager::getInstance();
822 	if (!hidl_manager)
823 		return;
824 
825 	hidl_manager->notifyDppFailure(wpa_s, DppFailureCode::CANNOT_FIND_NETWORK,
826 			ssid, channel_list, band_list, size);
827 }
828 
wpas_hidl_notify_dpp_enrollee_auth_failure(struct wpa_supplicant * wpa_s,const char * ssid,unsigned short band_list[],int size)829 void wpas_hidl_notify_dpp_enrollee_auth_failure(struct wpa_supplicant *wpa_s,
830 		const char *ssid, unsigned short band_list[], int size)
831 {
832 	if (!wpa_s)
833 		return;
834 
835 	wpa_printf(MSG_DEBUG,
836 			"Notifying DPP Enrollee authentication failure, SSID %s",
837 			ssid ? ssid : "N/A");
838 
839 	HidlManager *hidl_manager = HidlManager::getInstance();
840 	if (!hidl_manager)
841 		return;
842 
843 	hidl_manager->notifyDppFailure(wpa_s, DppFailureCode::ENROLLEE_AUTHENTICATION,
844 			ssid, NULL, band_list, size);
845 }
846 
847 
wpas_hidl_notify_dpp_conn_status(struct wpa_supplicant * wpa_s,enum dpp_status_error status,const char * ssid,const char * channel_list,unsigned short band_list[],int size)848 void wpas_hidl_notify_dpp_conn_status(struct wpa_supplicant *wpa_s, enum dpp_status_error status,
849 		const char *ssid, const char *channel_list, unsigned short band_list[], int size)
850 {
851 	switch (status)
852 	{
853 	case DPP_STATUS_OK:
854 		wpas_hidl_notify_dpp_config_applied(wpa_s);
855 		break;
856 
857 	case DPP_STATUS_NO_AP:
858 		wpas_hidl_notify_dpp_no_ap_failure(wpa_s, ssid, channel_list, band_list, size);
859 		break;
860 
861 	case DPP_STATUS_AUTH_FAILURE:
862 		wpas_hidl_notify_dpp_enrollee_auth_failure(wpa_s, ssid, band_list, size);
863 		break;
864 
865 	default:
866 		break;
867 	}
868 }
869 
wpas_hidl_notify_pmk_cache_added(struct wpa_supplicant * wpa_s,struct rsn_pmksa_cache_entry * pmksa_entry)870 void wpas_hidl_notify_pmk_cache_added(
871     struct wpa_supplicant *wpa_s,
872     struct rsn_pmksa_cache_entry *pmksa_entry)
873 {
874 	if (!wpa_s || !pmksa_entry)
875 		return;
876 
877 	HidlManager *hidl_manager = HidlManager::getInstance();
878 	if (!hidl_manager)
879 		return;
880 
881 	wpa_printf(
882 	    MSG_DEBUG,
883 	    "Notifying PMK cache added event");
884 
885 	hidl_manager->notifyPmkCacheAdded(wpa_s, pmksa_entry);
886 }
887 
wpas_hidl_notify_bss_tm_status(struct wpa_supplicant * wpa_s)888 void wpas_hidl_notify_bss_tm_status(struct wpa_supplicant *wpa_s)
889 {
890 	if (!wpa_s)
891 		return;
892 
893 	HidlManager *hidl_manager = HidlManager::getInstance();
894 	if (!hidl_manager)
895 		return;
896 
897 	wpa_printf(MSG_DEBUG, "Notifying BSS transition status");
898 
899 	hidl_manager->notifyBssTmStatus(wpa_s);
900 }
901 
wpas_hidl_notify_transition_disable(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid,u8 bitmap)902 void wpas_hidl_notify_transition_disable(struct wpa_supplicant *wpa_s,
903 					    struct wpa_ssid *ssid,
904 					    u8 bitmap)
905 {
906 	if (!wpa_s || !ssid)
907 		return;
908 
909 	HidlManager *hidl_manager = HidlManager::getInstance();
910 	if (!hidl_manager)
911 		return;
912 
913 	hidl_manager->notifyTransitionDisable(wpa_s, ssid, bitmap);
914 }
915 
wpas_hidl_notify_network_not_found(struct wpa_supplicant * wpa_s)916 void wpas_hidl_notify_network_not_found(struct wpa_supplicant *wpa_s)
917 {
918 	if (!wpa_s)
919 		return;
920 
921 	HidlManager *hidl_manager = HidlManager::getInstance();
922 	if (!hidl_manager)
923 		return;
924 
925 	wpa_printf(MSG_DEBUG, "Notify network not found");
926 
927 	hidl_manager->notifyNetworkNotFound(wpa_s);
928 }
929