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