blob: 68a77148011d7e5085030f703d133edaa6b0af07 [file] [log] [blame]
Gabriel Biren72cf9a52021-06-25 23:29:26 +00001/*
2 * aidl 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 "hostapd.h"
11#include <android/binder_process.h>
12#include <android/binder_manager.h>
13
14extern "C"
15{
16#include "aidl.h"
17#include "utils/common.h"
18#include "utils/eloop.h"
19#include "utils/includes.h"
20}
21
22using 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!
26static int aidl_fd = -1;
27static std::shared_ptr<Hostapd> service;
28
29void hostapd_aidl_sock_handler(
30 int /* sock */, void * /* eloop_ctx */, void * /* sock_ctx */)
31{
32 ABinderProcess_handlePolledCommands();
33}
34
35int hostapd_aidl_init(struct hapd_interfaces *interfaces)
36{
37 wpa_printf(MSG_DEBUG, "Initializing aidl control");
38 std::string instance; // declared here to allow use of goto
39
40 ABinderProcess_setupPolling(&aidl_fd);
41 if (aidl_fd < 0)
42 goto err;
43
44 wpa_printf(MSG_INFO, "Processing aidl events on FD %d", aidl_fd);
45 // Look for read events from the aidl socket in the eloop.
46 if (eloop_register_read_sock(
47 aidl_fd, hostapd_aidl_sock_handler, interfaces, NULL) < 0)
48 goto err;
49
50 wpa_printf(MSG_DEBUG, "Make service");
51 service = ndk::SharedRefBase::make<Hostapd>(interfaces);
52 if (!service)
53 goto err;
54 wpa_printf(MSG_DEBUG, "Add service");
55 instance = std::string() + Hostapd::descriptor + "/default";
56 if (AServiceManager_addService(service->asBinder().get(), instance.c_str()) != STATUS_OK)
57 goto err;
58 return 0;
59err:
60 hostapd_aidl_deinit(interfaces);
61 return -1;
62}
63
64void hostapd_aidl_deinit(struct hapd_interfaces *interfaces)
65{
66 wpa_printf(MSG_INFO, "Deiniting aidl control");
67 // Before aidl init, make sure call terminate to clear callback_
68 service->terminate();
69 eloop_unregister_read_sock(aidl_fd);
70 aidl_fd = -1;
71}