blob: 68e4d86fce145951137c4cae7c1499fa16483d65 [file] [log] [blame]
Roshan Piuscc817562017-12-22 14:45:05 -08001/*
2 * hidl interface for wpa_supplicant daemon
3 * Copyright (c) 2004-2018, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2004-2018, 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#include <hidl/HidlTransportSupport.h>
12
13#include "hostapd.h"
14
15extern "C"
16{
17#include "hidl.h"
18#include "utils/common.h"
19#include "utils/eloop.h"
20#include "utils/includes.h"
21}
22
23using android::hardware::configureRpcThreadpool;
24using android::hardware::IPCThreadState;
leslf8b1b402020-08-04 17:09:39 +080025using android::hardware::wifi::hostapd::V1_3::IHostapd;
26using android::hardware::wifi::hostapd::V1_3::implementation::Hostapd;
Roshan Piuscc817562017-12-22 14:45:05 -080027
28// This file is a bridge between the hostapd code written in 'C' and the HIDL
29// interface in C++. So, using "C" style static globals here!
30static int hidl_fd = -1;
31static android::sp<IHostapd> service;
32
33void hostapd_hidl_sock_handler(
34 int /* sock */, void * /* eloop_ctx */, void * /* sock_ctx */)
35{
36 IPCThreadState::self()->handlePolledCommands();
37}
38
39int hostapd_hidl_init(struct hapd_interfaces *interfaces)
40{
41 wpa_printf(MSG_DEBUG, "Initing hidl control");
42
Roshan Piuscc817562017-12-22 14:45:05 -080043 IPCThreadState::self()->setupPolling(&hidl_fd);
44 if (hidl_fd < 0)
45 goto err;
46
47 wpa_printf(MSG_INFO, "Processing hidl events on FD %d", hidl_fd);
48 // Look for read events from the hidl socket in the eloop.
49 if (eloop_register_read_sock(
50 hidl_fd, hostapd_hidl_sock_handler, interfaces, NULL) < 0)
51 goto err;
52 service = new Hostapd(interfaces);
53 if (!service)
54 goto err;
55 if (service->registerAsService() != android::NO_ERROR)
56 goto err;
57 return 0;
58err:
59 hostapd_hidl_deinit(interfaces);
60 return -1;
61}
62
63void hostapd_hidl_deinit(struct hapd_interfaces *interfaces)
64{
65 wpa_printf(MSG_DEBUG, "Deiniting hidl control");
66 eloop_unregister_read_sock(hidl_fd);
67 IPCThreadState::shutdown();
68 hidl_fd = -1;
69 service.clear();
70}