blob: 14167996d767a2abf056bb98242d02ecc004ed02 [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 Piuse746d6b2017-03-21 08:53:04 -0700306void wpas_hidl_notify_bssid_changed(struct wpa_supplicant *wpa_s)
307{
308 if (!wpa_s)
309 return;
310
311 wpa_printf(MSG_DEBUG, "Notifying bssid changed to hidl control");
312
313 HidlManager *hidl_manager = HidlManager::getInstance();
314 if (!hidl_manager)
315 return;
316
317 hidl_manager->notifyBssidChanged(wpa_s);
318}
319
Roshan Pius14932752017-01-11 09:48:58 -0800320void wpas_hidl_notify_wps_event_fail(
321 struct wpa_supplicant *wpa_s, uint8_t *peer_macaddr, uint16_t config_error,
322 uint16_t error_indication)
323{
324 if (!wpa_s || !peer_macaddr)
325 return;
326
327 wpa_printf(
328 MSG_DEBUG, "Notifying Wps event fail to hidl control: %d, %d",
329 config_error, error_indication);
330
331 HidlManager *hidl_manager = HidlManager::getInstance();
332 if (!hidl_manager)
333 return;
334
335 hidl_manager->notifyWpsEventFail(
336 wpa_s, peer_macaddr, config_error, error_indication);
337}
338
339void wpas_hidl_notify_wps_event_success(struct wpa_supplicant *wpa_s)
340{
341 if (!wpa_s)
342 return;
343
344 wpa_printf(MSG_DEBUG, "Notifying Wps event success to hidl control");
345
346 HidlManager *hidl_manager = HidlManager::getInstance();
347 if (!hidl_manager)
348 return;
349
350 hidl_manager->notifyWpsEventSuccess(wpa_s);
351}
352
353void wpas_hidl_notify_wps_event_pbc_overlap(struct wpa_supplicant *wpa_s)
354{
355 if (!wpa_s)
356 return;
357
358 wpa_printf(
359 MSG_DEBUG, "Notifying Wps event PBC overlap to hidl control");
360
361 HidlManager *hidl_manager = HidlManager::getInstance();
362 if (!hidl_manager)
363 return;
364
365 hidl_manager->notifyWpsEventPbcOverlap(wpa_s);
366}
Roshan Piusfd2fd662017-01-23 13:41:57 -0800367
368void wpas_hidl_notify_p2p_device_found(
369 struct wpa_supplicant *wpa_s, const u8 *addr,
370 const struct p2p_peer_info *info, const u8 *peer_wfd_device_info,
371 u8 peer_wfd_device_info_len)
372{
Roshan Pius73d28fd2017-03-30 16:07:33 -0700373 if (!wpa_s || !addr || !info)
Roshan Piusfd2fd662017-01-23 13:41:57 -0800374 return;
375
376 wpa_printf(
377 MSG_DEBUG, "Notifying P2P device found to hidl control " MACSTR,
378 MAC2STR(info->p2p_device_addr));
379
380 HidlManager *hidl_manager = HidlManager::getInstance();
381 if (!hidl_manager)
382 return;
383
384 hidl_manager->notifyP2pDeviceFound(
385 wpa_s, addr, info, peer_wfd_device_info, peer_wfd_device_info_len);
386}
387
388void wpas_hidl_notify_p2p_device_lost(
389 struct wpa_supplicant *wpa_s, const u8 *p2p_device_addr)
390{
391 if (!wpa_s || !p2p_device_addr)
392 return;
393
394 wpa_printf(
395 MSG_DEBUG, "Notifying P2P device lost to hidl control " MACSTR,
396 MAC2STR(p2p_device_addr));
397
398 HidlManager *hidl_manager = HidlManager::getInstance();
399 if (!hidl_manager)
400 return;
401
402 hidl_manager->notifyP2pDeviceLost(wpa_s, p2p_device_addr);
403}
404
405void wpas_hidl_notify_p2p_find_stopped(struct wpa_supplicant *wpa_s)
406{
407 if (!wpa_s)
408 return;
409
410 wpa_printf(MSG_DEBUG, "Notifying P2P find stop to hidl control");
411
412 HidlManager *hidl_manager = HidlManager::getInstance();
413 if (!hidl_manager)
414 return;
415
416 hidl_manager->notifyP2pFindStopped(wpa_s);
417}
418
419void wpas_hidl_notify_p2p_go_neg_req(
420 struct wpa_supplicant *wpa_s, const u8 *src_addr, u16 dev_passwd_id,
421 u8 go_intent)
422{
423 if (!wpa_s || !src_addr)
424 return;
425
426 wpa_printf(
427 MSG_DEBUG,
428 "Notifying P2P GO negotiation request to hidl control " MACSTR,
429 MAC2STR(src_addr));
430
431 HidlManager *hidl_manager = HidlManager::getInstance();
432 if (!hidl_manager)
433 return;
434
435 hidl_manager->notifyP2pGoNegReq(
436 wpa_s, src_addr, dev_passwd_id, go_intent);
437}
438
439void wpas_hidl_notify_p2p_go_neg_completed(
440 struct wpa_supplicant *wpa_s, const struct p2p_go_neg_results *res)
441{
442 if (!wpa_s || !res)
443 return;
444
445 wpa_printf(
446 MSG_DEBUG,
447 "Notifying P2P GO negotiation completed to hidl control: %d",
448 res->status);
449
450 HidlManager *hidl_manager = HidlManager::getInstance();
451 if (!hidl_manager)
452 return;
453
454 hidl_manager->notifyP2pGoNegCompleted(wpa_s, res);
455}
456
457void wpas_hidl_notify_p2p_group_formation_failure(
458 struct wpa_supplicant *wpa_s, const char *reason)
459{
460 if (!wpa_s || !reason)
461 return;
462
463 wpa_printf(
464 MSG_DEBUG,
465 "Notifying P2P Group formation failure to hidl control: %s",
466 reason);
467
468 HidlManager *hidl_manager = HidlManager::getInstance();
469 if (!hidl_manager)
470 return;
471
472 hidl_manager->notifyP2pGroupFormationFailure(wpa_s, reason);
473}
474
475void wpas_hidl_notify_p2p_group_started(
476 struct wpa_supplicant *wpa_s, const struct wpa_ssid *ssid, int persistent,
Roshan Pius7a1c8482017-04-12 17:05:10 -0700477 int client)
Roshan Piusfd2fd662017-01-23 13:41:57 -0800478{
Roshan Pius7a1c8482017-04-12 17:05:10 -0700479 if (!wpa_s || !ssid)
Roshan Piusfd2fd662017-01-23 13:41:57 -0800480 return;
481
482 wpa_printf(
483 MSG_DEBUG, "Notifying P2P Group start to hidl control: %d",
484 ssid->id);
485
486 HidlManager *hidl_manager = HidlManager::getInstance();
487 if (!hidl_manager)
488 return;
489
Roshan Pius7a1c8482017-04-12 17:05:10 -0700490 hidl_manager->notifyP2pGroupStarted(wpa_s, ssid, persistent, client);
Roshan Piusfd2fd662017-01-23 13:41:57 -0800491}
492
493void wpas_hidl_notify_p2p_group_removed(
494 struct wpa_supplicant *wpa_s, const struct wpa_ssid *ssid, const char *role)
495{
496 if (!wpa_s || !ssid || !role)
497 return;
498
499 wpa_printf(
500 MSG_DEBUG, "Notifying P2P Group removed to hidl control: %d",
501 ssid->id);
502
503 HidlManager *hidl_manager = HidlManager::getInstance();
504 if (!hidl_manager)
505 return;
506
507 hidl_manager->notifyP2pGroupRemoved(wpa_s, ssid, role);
508}
509
510void wpas_hidl_notify_p2p_invitation_received(
511 struct wpa_supplicant *wpa_s, const u8 *sa, const u8 *go_dev_addr,
512 const u8 *bssid, int id, int op_freq)
513{
514 if (!wpa_s || !sa || !go_dev_addr || !bssid)
515 return;
516
517 wpa_printf(
518 MSG_DEBUG,
519 "Notifying P2P invitation received to hidl control: %d " MACSTR, id,
520 MAC2STR(bssid));
521
522 HidlManager *hidl_manager = HidlManager::getInstance();
523 if (!hidl_manager)
524 return;
525
526 hidl_manager->notifyP2pInvitationReceived(
527 wpa_s, sa, go_dev_addr, bssid, id, op_freq);
528}
529
530void wpas_hidl_notify_p2p_invitation_result(
531 struct wpa_supplicant *wpa_s, int status, const u8 *bssid)
532{
533 if (!wpa_s || !bssid)
534 return;
535
536 wpa_printf(
537 MSG_DEBUG,
538 "Notifying P2P invitation result to hidl control: " MACSTR,
539 MAC2STR(bssid));
540
541 HidlManager *hidl_manager = HidlManager::getInstance();
542 if (!hidl_manager)
543 return;
544
545 hidl_manager->notifyP2pInvitationResult(wpa_s, status, bssid);
546}
547
548void wpas_hidl_notify_p2p_provision_discovery(
549 struct wpa_supplicant *wpa_s, const u8 *dev_addr, int request,
550 enum p2p_prov_disc_status status, u16 config_methods,
551 unsigned int generated_pin)
552{
553 if (!wpa_s || !dev_addr)
554 return;
555
556 wpa_printf(
557 MSG_DEBUG,
558 "Notifying P2P provision discovery to hidl control " MACSTR,
559 MAC2STR(dev_addr));
560
561 HidlManager *hidl_manager = HidlManager::getInstance();
562 if (!hidl_manager)
563 return;
564
565 hidl_manager->notifyP2pProvisionDiscovery(
566 wpa_s, dev_addr, request, status, config_methods, generated_pin);
567}
568
569void wpas_hidl_notify_p2p_sd_response(
570 struct wpa_supplicant *wpa_s, const u8 *sa, u16 update_indic,
571 const u8 *tlvs, size_t tlvs_len)
572{
573 if (!wpa_s || !sa || !tlvs)
574 return;
575
576 wpa_printf(
577 MSG_DEBUG,
578 "Notifying P2P service discovery response to hidl control " MACSTR,
579 MAC2STR(sa));
580
581 HidlManager *hidl_manager = HidlManager::getInstance();
582 if (!hidl_manager)
583 return;
584
585 hidl_manager->notifyP2pSdResponse(
586 wpa_s, sa, update_indic, tlvs, tlvs_len);
587}
588
589void wpas_hidl_notify_ap_sta_authorized(
590 struct wpa_supplicant *wpa_s, const u8 *sta, const u8 *p2p_dev_addr)
591{
592 if (!wpa_s || !sta || !p2p_dev_addr)
593 return;
594
595 wpa_printf(
596 MSG_DEBUG,
597 "Notifying P2P AP STA authorized to hidl control " MACSTR,
598 MAC2STR(sta));
599
600 HidlManager *hidl_manager = HidlManager::getInstance();
601 if (!hidl_manager)
602 return;
603
604 hidl_manager->notifyApStaAuthorized(wpa_s, sta, p2p_dev_addr);
605}
606
607void wpas_hidl_notify_ap_sta_deauthorized(
608 struct wpa_supplicant *wpa_s, const u8 *sta, const u8 *p2p_dev_addr)
609{
610 if (!wpa_s || !sta || !p2p_dev_addr)
611 return;
612
613 wpa_printf(
614 MSG_DEBUG,
615 "Notifying P2P AP STA deauthorized to hidl control " MACSTR,
616 MAC2STR(sta));
617
618 HidlManager *hidl_manager = HidlManager::getInstance();
619 if (!hidl_manager)
620 return;
621
622 hidl_manager->notifyApStaDeauthorized(wpa_s, sta, p2p_dev_addr);
623}