1 /*
2 * aidl interface for wpa_supplicant daemon
3 * Copyright (c) 2004-2018, Jouni Malinen <[email protected]>
4 * Copyright (c) 2004-2018, Roshan Pius <[email protected]>
5 *
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
8 */
9
10 #include "hostapd.h"
11 #include <android/binder_process.h>
12 #include <android/binder_manager.h>
13
14 extern "C"
15 {
16 #include "aidl.h"
17 #include "utils/common.h"
18 #include "utils/eloop.h"
19 #include "utils/includes.h"
20 }
21
22 using aidl::android::hardware::wifi::hostapd::Hostapd;
23
24 // This file is a bridge between the hostapd code written in 'C' and the aidl
25 // interface in C++. So, using "C" style static globals here!
26 static int aidl_fd = -1;
27 static std::shared_ptr<Hostapd> service;
28
hostapd_aidl_sock_handler(int,void *,void *)29 void hostapd_aidl_sock_handler(
30 int /* sock */, void * /* eloop_ctx */, void * /* sock_ctx */)
31 {
32 ABinderProcess_handlePolledCommands();
33 }
34
hostapd_aidl_init(struct hapd_interfaces * interfaces)35 int hostapd_aidl_init(struct hapd_interfaces *interfaces)
36 {
37 wpa_printf(MSG_INFO, "Initializing aidl control");
38 wpa_printf(MSG_INFO, "Interface version: %d", Hostapd::version);
39 std::string instance; // declared here to allow use of goto
40
41 ABinderProcess_setupPolling(&aidl_fd);
42 if (aidl_fd < 0)
43 goto err;
44
45 wpa_printf(MSG_INFO, "Processing aidl events on FD %d", aidl_fd);
46 // Look for read events from the aidl socket in the eloop.
47 if (eloop_register_read_sock(
48 aidl_fd, hostapd_aidl_sock_handler, interfaces, NULL) < 0)
49 goto err;
50
51 wpa_printf(MSG_DEBUG, "Make service");
52 service = ndk::SharedRefBase::make<Hostapd>(interfaces);
53 if (!service)
54 goto err;
55 wpa_printf(MSG_DEBUG, "Add service");
56 instance = std::string() + Hostapd::descriptor + "/default";
57 if (AServiceManager_addService(service->asBinder().get(), instance.c_str()) != STATUS_OK)
58 goto err;
59 return 0;
60 err:
61 hostapd_aidl_deinit(interfaces);
62 return -1;
63 }
64
hostapd_aidl_deinit(struct hapd_interfaces * interfaces)65 void hostapd_aidl_deinit(struct hapd_interfaces *interfaces)
66 {
67 wpa_printf(MSG_INFO, "Deiniting aidl control");
68 // Before aidl deinit, make sure call terminate to clear callback_
69 if (service) {
70 service->terminate();
71 }
72 eloop_unregister_read_sock(aidl_fd);
73 aidl_fd = -1;
74 }
75