blob: ffc482f7ab10eba5ef42420721eb11fc95ea2c24 [file] [log] [blame]
Roshan Pius57ffbcf2016-09-27 09:12:46 -07001/*
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
Roshan Pius7c0ebf22016-09-20 15:11:56 -070010#include <hwbinder/IPCThreadState.h>
Roshan Pius57ffbcf2016-09-27 09:12:46 -070011
Martijn Coenenb7fca8a2016-12-28 17:11:37 +010012#include <hidl/HidlTransportSupport.h>
Roshan Pius57ffbcf2016-09-27 09:12:46 -070013#include "hidl_manager.h"
14
15extern "C" {
16#include "hidl.h"
17#include "hidl_i.h"
18#include "utils/common.h"
19#include "utils/eloop.h"
20#include "utils/includes.h"
21}
22
Martijn Coenenb7fca8a2016-12-28 17:11:37 +010023using android::hardware::configureRpcThreadpool;
Roshan Pius7c0ebf22016-09-20 15:11:56 -070024using android::hardware::IPCThreadState;
25using android::hardware::wifi::supplicant::V1_0::implementation::HidlManager;
26
Roshan Pius57ffbcf2016-09-27 09:12:46 -070027void wpas_hidl_sock_handler(
Roshan Piuscb5faa02017-01-10 09:51:00 -080028 int /* sock */, void * /* eloop_ctx */, void * /* sock_ctx */)
Roshan Pius57ffbcf2016-09-27 09:12:46 -070029{
Roshan Pius7c0ebf22016-09-20 15:11:56 -070030 IPCThreadState::self()->handlePolledCommands();
Roshan Pius57ffbcf2016-09-27 09:12:46 -070031}
32
33struct wpas_hidl_priv *wpas_hidl_init(struct wpa_global *global)
34{
35 struct wpas_hidl_priv *priv;
Roshan Pius7c0ebf22016-09-20 15:11:56 -070036 HidlManager *hidl_manager;
Roshan Pius57ffbcf2016-09-27 09:12:46 -070037
38 priv = (wpas_hidl_priv *)os_zalloc(sizeof(*priv));
39 if (!priv)
40 return NULL;
41 priv->global = global;
42
43 wpa_printf(MSG_DEBUG, "Initing hidl control");
44
Martijn Coenenb7fca8a2016-12-28 17:11:37 +010045 configureRpcThreadpool(1, true /* callerWillJoin */);
Roshan Pius7c0ebf22016-09-20 15:11:56 -070046 IPCThreadState::self()->disableBackgroundScheduling(true);
47 IPCThreadState::self()->setupPolling(&priv->hidl_fd);
Roshan Pius57ffbcf2016-09-27 09:12:46 -070048 if (priv->hidl_fd < 0)
49 goto err;
50
Roshan Pius7c0ebf22016-09-20 15:11:56 -070051 wpa_printf(MSG_INFO, "Processing hidl events on FD %d", priv->hidl_fd);
52 // Look for read events from the hidl socket in the eloop.
Roshan Pius57ffbcf2016-09-27 09:12:46 -070053 if (eloop_register_read_sock(
54 priv->hidl_fd, wpas_hidl_sock_handler, global, priv) < 0)
55 goto err;
56
Roshan Pius7c0ebf22016-09-20 15:11:56 -070057 hidl_manager = HidlManager::getInstance();
Roshan Pius57ffbcf2016-09-27 09:12:46 -070058 if (!hidl_manager)
59 goto err;
60 hidl_manager->registerHidlService(global);
Roshan Pius7c0ebf22016-09-20 15:11:56 -070061 // We may not need to store this hidl manager reference in the
62 // global data strucure because we've made it a singleton class.
Roshan Pius57ffbcf2016-09-27 09:12:46 -070063 priv->hidl_manager = (void *)hidl_manager;
64
65 return priv;
66err:
67 wpas_hidl_deinit(priv);
68 return NULL;
69}
70
71void wpas_hidl_deinit(struct wpas_hidl_priv *priv)
72{
73 if (!priv)
74 return;
75
76 wpa_printf(MSG_DEBUG, "Deiniting hidl control");
77
Roshan Pius7c0ebf22016-09-20 15:11:56 -070078 HidlManager::destroyInstance();
Roshan Pius57ffbcf2016-09-27 09:12:46 -070079 eloop_unregister_read_sock(priv->hidl_fd);
Roshan Pius7c0ebf22016-09-20 15:11:56 -070080 IPCThreadState::shutdown();
Roshan Pius57ffbcf2016-09-27 09:12:46 -070081 os_free(priv);
82}
83
84int wpas_hidl_register_interface(struct wpa_supplicant *wpa_s)
85{
86 if (!wpa_s || !wpa_s->global->hidl)
87 return 1;
88
89 wpa_printf(
90 MSG_DEBUG, "Registering interface to hidl control: %s",
91 wpa_s->ifname);
92
Roshan Pius7c0ebf22016-09-20 15:11:56 -070093 HidlManager *hidl_manager = HidlManager::getInstance();
Roshan Pius57ffbcf2016-09-27 09:12:46 -070094 if (!hidl_manager)
95 return 1;
96
97 return hidl_manager->registerInterface(wpa_s);
98}
99
100int wpas_hidl_unregister_interface(struct wpa_supplicant *wpa_s)
101{
102 if (!wpa_s || !wpa_s->global->hidl)
103 return 1;
104
105 wpa_printf(
106 MSG_DEBUG, "Deregistering interface from hidl control: %s",
107 wpa_s->ifname);
108
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700109 HidlManager *hidl_manager = HidlManager::getInstance();
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700110 if (!hidl_manager)
111 return 1;
112
113 return hidl_manager->unregisterInterface(wpa_s);
114}
115
116int wpas_hidl_register_network(
117 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
118{
119 if (!wpa_s || !wpa_s->global->hidl || !ssid)
120 return 1;
121
122 wpa_printf(
123 MSG_DEBUG, "Registering network to hidl control: %d", ssid->id);
124
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700125 HidlManager *hidl_manager = HidlManager::getInstance();
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700126 if (!hidl_manager)
127 return 1;
128
129 return hidl_manager->registerNetwork(wpa_s, ssid);
130}
131
132int wpas_hidl_unregister_network(
133 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
134{
135 if (!wpa_s || !wpa_s->global->hidl || !ssid)
136 return 1;
137
138 wpa_printf(
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700139 MSG_DEBUG, "Deregistering network from hidl control: %d", ssid->id);
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700140
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700141 HidlManager *hidl_manager = HidlManager::getInstance();
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700142 if (!hidl_manager)
143 return 1;
144
145 return hidl_manager->unregisterNetwork(wpa_s, ssid);
146}
147
148int wpas_hidl_notify_state_changed(struct wpa_supplicant *wpa_s)
149{
150 if (!wpa_s || !wpa_s->global->hidl)
151 return 1;
152
153 wpa_printf(
154 MSG_DEBUG, "Notifying state change event to hidl control: %d",
155 wpa_s->wpa_state);
156
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700157 HidlManager *hidl_manager = HidlManager::getInstance();
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700158 if (!hidl_manager)
159 return 1;
160
161 return hidl_manager->notifyStateChange(wpa_s);
162}
163
164int wpas_hidl_notify_network_request(
165 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
166 enum wpa_ctrl_req_type rtype, const char *default_txt)
167{
168 if (!wpa_s || !wpa_s->global->hidl || !ssid)
169 return 1;
170
171 wpa_printf(
172 MSG_DEBUG, "Notifying network request to hidl control: %d",
173 ssid->id);
174
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700175 HidlManager *hidl_manager = HidlManager::getInstance();
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700176 if (!hidl_manager)
177 return 1;
178
179 return hidl_manager->notifyNetworkRequest(
180 wpa_s, ssid, rtype, default_txt);
181}
Roshan Pius9322a342016-12-12 14:45:02 -0800182
183void wpas_hidl_notify_anqp_query_done(
184 struct wpa_supplicant *wpa_s, const u8 *bssid, const char *result,
185 const struct wpa_bss_anqp *anqp)
186{
187 if (!wpa_s || !wpa_s->global->hidl || !bssid || !result || !anqp)
188 return;
189
190 wpa_printf(
191 MSG_DEBUG,
192 "Notifying ANQP query done to hidl control: " MACSTR "result: %s",
193 MAC2STR(bssid), result);
194
195 HidlManager *hidl_manager = HidlManager::getInstance();
196 if (!hidl_manager)
197 return;
198
199 hidl_manager->notifyAnqpQueryDone(wpa_s, bssid, result, anqp);
200}
201
202void wpas_hidl_notify_hs20_icon_query_done(
203 struct wpa_supplicant *wpa_s, const u8 *bssid, const char *file_name,
204 const u8 *image, u32 image_length)
205{
206 if (!wpa_s || !wpa_s->global->hidl || !bssid || !file_name || !image)
207 return;
208
209 wpa_printf(
210 MSG_DEBUG, "Notifying HS20 icon query done to hidl control: " MACSTR
211 "file_name: %s",
212 MAC2STR(bssid), file_name);
213
214 HidlManager *hidl_manager = HidlManager::getInstance();
215 if (!hidl_manager)
216 return;
217
218 hidl_manager->notifyHs20IconQueryDone(
219 wpa_s, bssid, file_name, image, image_length);
220}
221
222void wpas_hidl_notify_hs20_rx_subscription_remediation(
223 struct wpa_supplicant *wpa_s, const char *url, u8 osu_method)
224{
225 if (!wpa_s || !wpa_s->global->hidl || !url)
226 return;
227
228 wpa_printf(
229 MSG_DEBUG,
230 "Notifying HS20 subscription remediation rx to hidl control: %s",
231 url);
232
233 HidlManager *hidl_manager = HidlManager::getInstance();
234 if (!hidl_manager)
235 return;
236
237 hidl_manager->notifyHs20RxSubscriptionRemediation(
238 wpa_s, url, osu_method);
239}
240
241void wpas_hidl_notify_hs20_rx_deauth_imminent_notice(
242 struct wpa_supplicant *wpa_s, u8 code, u16 reauth_delay, const char *url)
243{
244 if (!wpa_s || !wpa_s->global->hidl || !url)
245 return;
246
247 wpa_printf(
248 MSG_DEBUG,
249 "Notifying HS20 deauth imminent notice rx to hidl control: %s",
250 url);
251
252 HidlManager *hidl_manager = HidlManager::getInstance();
253 if (!hidl_manager)
254 return;
255
256 hidl_manager->notifyHs20RxDeauthImminentNotice(
257 wpa_s, code, reauth_delay, url);
258}
Roshan Pius0974e962016-12-12 17:05:51 -0800259
260void wpas_hidl_notify_disconnect_reason(struct wpa_supplicant *wpa_s)
261{
262 if (!wpa_s)
263 return;
264
265 wpa_printf(
266 MSG_DEBUG, "Notifying disconnect reason to hidl control: %d",
267 wpa_s->disconnect_reason);
268
269 HidlManager *hidl_manager = HidlManager::getInstance();
270 if (!hidl_manager)
271 return;
272
273 hidl_manager->notifyDisconnectReason(wpa_s);
274}
275
276void wpas_hidl_notify_assoc_reject(struct wpa_supplicant *wpa_s)
277{
278 if (!wpa_s)
279 return;
280
281 wpa_printf(
282 MSG_DEBUG, "Notifying assoc reject to hidl control: %d",
283 wpa_s->assoc_status_code);
284
285 HidlManager *hidl_manager = HidlManager::getInstance();
286 if (!hidl_manager)
287 return;
288
289 hidl_manager->notifyAssocReject(wpa_s);
290}
Roshan Pius14932752017-01-11 09:48:58 -0800291
Roshan Pius38e96762017-01-23 14:52:00 -0800292void wpas_hidl_notify_auth_timeout(struct wpa_supplicant *wpa_s)
293{
294 if (!wpa_s)
295 return;
296
297 wpa_printf(MSG_DEBUG, "Notifying auth timeout to hidl control");
298
299 HidlManager *hidl_manager = HidlManager::getInstance();
300 if (!hidl_manager)
301 return;
302
303 hidl_manager->notifyAuthTimeout(wpa_s);
304}
305
Roshan Pius14932752017-01-11 09:48:58 -0800306void wpas_hidl_notify_wps_event_fail(
307 struct wpa_supplicant *wpa_s, uint8_t *peer_macaddr, uint16_t config_error,
308 uint16_t error_indication)
309{
310 if (!wpa_s || !peer_macaddr)
311 return;
312
313 wpa_printf(
314 MSG_DEBUG, "Notifying Wps event fail to hidl control: %d, %d",
315 config_error, error_indication);
316
317 HidlManager *hidl_manager = HidlManager::getInstance();
318 if (!hidl_manager)
319 return;
320
321 hidl_manager->notifyWpsEventFail(
322 wpa_s, peer_macaddr, config_error, error_indication);
323}
324
325void wpas_hidl_notify_wps_event_success(struct wpa_supplicant *wpa_s)
326{
327 if (!wpa_s)
328 return;
329
330 wpa_printf(MSG_DEBUG, "Notifying Wps event success to hidl control");
331
332 HidlManager *hidl_manager = HidlManager::getInstance();
333 if (!hidl_manager)
334 return;
335
336 hidl_manager->notifyWpsEventSuccess(wpa_s);
337}
338
339void wpas_hidl_notify_wps_event_pbc_overlap(struct wpa_supplicant *wpa_s)
340{
341 if (!wpa_s)
342 return;
343
344 wpa_printf(
345 MSG_DEBUG, "Notifying Wps event PBC overlap to hidl control");
346
347 HidlManager *hidl_manager = HidlManager::getInstance();
348 if (!hidl_manager)
349 return;
350
351 hidl_manager->notifyWpsEventPbcOverlap(wpa_s);
352}
Roshan Piusfd2fd662017-01-23 13:41:57 -0800353
354void wpas_hidl_notify_p2p_device_found(
355 struct wpa_supplicant *wpa_s, const u8 *addr,
356 const struct p2p_peer_info *info, const u8 *peer_wfd_device_info,
357 u8 peer_wfd_device_info_len)
358{
359 if (!wpa_s || !addr || !info || !peer_wfd_device_info)
360 return;
361
362 wpa_printf(
363 MSG_DEBUG, "Notifying P2P device found to hidl control " MACSTR,
364 MAC2STR(info->p2p_device_addr));
365
366 HidlManager *hidl_manager = HidlManager::getInstance();
367 if (!hidl_manager)
368 return;
369
370 hidl_manager->notifyP2pDeviceFound(
371 wpa_s, addr, info, peer_wfd_device_info, peer_wfd_device_info_len);
372}
373
374void wpas_hidl_notify_p2p_device_lost(
375 struct wpa_supplicant *wpa_s, const u8 *p2p_device_addr)
376{
377 if (!wpa_s || !p2p_device_addr)
378 return;
379
380 wpa_printf(
381 MSG_DEBUG, "Notifying P2P device lost to hidl control " MACSTR,
382 MAC2STR(p2p_device_addr));
383
384 HidlManager *hidl_manager = HidlManager::getInstance();
385 if (!hidl_manager)
386 return;
387
388 hidl_manager->notifyP2pDeviceLost(wpa_s, p2p_device_addr);
389}
390
391void wpas_hidl_notify_p2p_find_stopped(struct wpa_supplicant *wpa_s)
392{
393 if (!wpa_s)
394 return;
395
396 wpa_printf(MSG_DEBUG, "Notifying P2P find stop to hidl control");
397
398 HidlManager *hidl_manager = HidlManager::getInstance();
399 if (!hidl_manager)
400 return;
401
402 hidl_manager->notifyP2pFindStopped(wpa_s);
403}
404
405void wpas_hidl_notify_p2p_go_neg_req(
406 struct wpa_supplicant *wpa_s, const u8 *src_addr, u16 dev_passwd_id,
407 u8 go_intent)
408{
409 if (!wpa_s || !src_addr)
410 return;
411
412 wpa_printf(
413 MSG_DEBUG,
414 "Notifying P2P GO negotiation request to hidl control " MACSTR,
415 MAC2STR(src_addr));
416
417 HidlManager *hidl_manager = HidlManager::getInstance();
418 if (!hidl_manager)
419 return;
420
421 hidl_manager->notifyP2pGoNegReq(
422 wpa_s, src_addr, dev_passwd_id, go_intent);
423}
424
425void wpas_hidl_notify_p2p_go_neg_completed(
426 struct wpa_supplicant *wpa_s, const struct p2p_go_neg_results *res)
427{
428 if (!wpa_s || !res)
429 return;
430
431 wpa_printf(
432 MSG_DEBUG,
433 "Notifying P2P GO negotiation completed to hidl control: %d",
434 res->status);
435
436 HidlManager *hidl_manager = HidlManager::getInstance();
437 if (!hidl_manager)
438 return;
439
440 hidl_manager->notifyP2pGoNegCompleted(wpa_s, res);
441}
442
443void wpas_hidl_notify_p2p_group_formation_failure(
444 struct wpa_supplicant *wpa_s, const char *reason)
445{
446 if (!wpa_s || !reason)
447 return;
448
449 wpa_printf(
450 MSG_DEBUG,
451 "Notifying P2P Group formation failure to hidl control: %s",
452 reason);
453
454 HidlManager *hidl_manager = HidlManager::getInstance();
455 if (!hidl_manager)
456 return;
457
458 hidl_manager->notifyP2pGroupFormationFailure(wpa_s, reason);
459}
460
461void wpas_hidl_notify_p2p_group_started(
462 struct wpa_supplicant *wpa_s, const struct wpa_ssid *ssid, int persistent,
463 int client, const u8 *ip)
464{
465 if (!wpa_s || !ssid || !ip)
466 return;
467
468 wpa_printf(
469 MSG_DEBUG, "Notifying P2P Group start to hidl control: %d",
470 ssid->id);
471
472 HidlManager *hidl_manager = HidlManager::getInstance();
473 if (!hidl_manager)
474 return;
475
476 hidl_manager->notifyP2pGroupStarted(
477 wpa_s, ssid, persistent, client, ip);
478}
479
480void wpas_hidl_notify_p2p_group_removed(
481 struct wpa_supplicant *wpa_s, const struct wpa_ssid *ssid, const char *role)
482{
483 if (!wpa_s || !ssid || !role)
484 return;
485
486 wpa_printf(
487 MSG_DEBUG, "Notifying P2P Group removed to hidl control: %d",
488 ssid->id);
489
490 HidlManager *hidl_manager = HidlManager::getInstance();
491 if (!hidl_manager)
492 return;
493
494 hidl_manager->notifyP2pGroupRemoved(wpa_s, ssid, role);
495}
496
497void wpas_hidl_notify_p2p_invitation_received(
498 struct wpa_supplicant *wpa_s, const u8 *sa, const u8 *go_dev_addr,
499 const u8 *bssid, int id, int op_freq)
500{
501 if (!wpa_s || !sa || !go_dev_addr || !bssid)
502 return;
503
504 wpa_printf(
505 MSG_DEBUG,
506 "Notifying P2P invitation received to hidl control: %d " MACSTR, id,
507 MAC2STR(bssid));
508
509 HidlManager *hidl_manager = HidlManager::getInstance();
510 if (!hidl_manager)
511 return;
512
513 hidl_manager->notifyP2pInvitationReceived(
514 wpa_s, sa, go_dev_addr, bssid, id, op_freq);
515}
516
517void wpas_hidl_notify_p2p_invitation_result(
518 struct wpa_supplicant *wpa_s, int status, const u8 *bssid)
519{
520 if (!wpa_s || !bssid)
521 return;
522
523 wpa_printf(
524 MSG_DEBUG,
525 "Notifying P2P invitation result to hidl control: " MACSTR,
526 MAC2STR(bssid));
527
528 HidlManager *hidl_manager = HidlManager::getInstance();
529 if (!hidl_manager)
530 return;
531
532 hidl_manager->notifyP2pInvitationResult(wpa_s, status, bssid);
533}
534
535void wpas_hidl_notify_p2p_provision_discovery(
536 struct wpa_supplicant *wpa_s, const u8 *dev_addr, int request,
537 enum p2p_prov_disc_status status, u16 config_methods,
538 unsigned int generated_pin)
539{
540 if (!wpa_s || !dev_addr)
541 return;
542
543 wpa_printf(
544 MSG_DEBUG,
545 "Notifying P2P provision discovery to hidl control " MACSTR,
546 MAC2STR(dev_addr));
547
548 HidlManager *hidl_manager = HidlManager::getInstance();
549 if (!hidl_manager)
550 return;
551
552 hidl_manager->notifyP2pProvisionDiscovery(
553 wpa_s, dev_addr, request, status, config_methods, generated_pin);
554}
555
556void wpas_hidl_notify_p2p_sd_response(
557 struct wpa_supplicant *wpa_s, const u8 *sa, u16 update_indic,
558 const u8 *tlvs, size_t tlvs_len)
559{
560 if (!wpa_s || !sa || !tlvs)
561 return;
562
563 wpa_printf(
564 MSG_DEBUG,
565 "Notifying P2P service discovery response to hidl control " MACSTR,
566 MAC2STR(sa));
567
568 HidlManager *hidl_manager = HidlManager::getInstance();
569 if (!hidl_manager)
570 return;
571
572 hidl_manager->notifyP2pSdResponse(
573 wpa_s, sa, update_indic, tlvs, tlvs_len);
574}
575
576void wpas_hidl_notify_ap_sta_authorized(
577 struct wpa_supplicant *wpa_s, const u8 *sta, const u8 *p2p_dev_addr)
578{
579 if (!wpa_s || !sta || !p2p_dev_addr)
580 return;
581
582 wpa_printf(
583 MSG_DEBUG,
584 "Notifying P2P AP STA authorized to hidl control " MACSTR,
585 MAC2STR(sta));
586
587 HidlManager *hidl_manager = HidlManager::getInstance();
588 if (!hidl_manager)
589 return;
590
591 hidl_manager->notifyApStaAuthorized(wpa_s, sta, p2p_dev_addr);
592}
593
594void wpas_hidl_notify_ap_sta_deauthorized(
595 struct wpa_supplicant *wpa_s, const u8 *sta, const u8 *p2p_dev_addr)
596{
597 if (!wpa_s || !sta || !p2p_dev_addr)
598 return;
599
600 wpa_printf(
601 MSG_DEBUG,
602 "Notifying P2P AP STA deauthorized to hidl control " MACSTR,
603 MAC2STR(sta));
604
605 HidlManager *hidl_manager = HidlManager::getInstance();
606 if (!hidl_manager)
607 return;
608
609 hidl_manager->notifyApStaDeauthorized(wpa_s, sta, p2p_dev_addr);
610}