blob: c6088eda67b7075d6932f8a3b8c15c43a0d895ab [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{
Gabriel Biren56b62df2022-06-16 17:38:54 +000037 wpa_printf(MSG_INFO, "Initializing aidl control");
38 wpa_printf(MSG_INFO, "Interface version: %d", Hostapd::version);
Gabriel Biren72cf9a52021-06-25 23:29:26 +000039 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;
60err:
61 hostapd_aidl_deinit(interfaces);
62 return -1;
63}
64
65void hostapd_aidl_deinit(struct hapd_interfaces *interfaces)
66{
67 wpa_printf(MSG_INFO, "Deiniting aidl control");
Gabriel Birenf2f4a312022-02-11 23:07:33 +000068 // Before aidl deinit, make sure call terminate to clear callback_
69 if (service) {
70 service->terminate();
71 }
Gabriel Biren72cf9a52021-06-25 23:29:26 +000072 eloop_unregister_read_sock(aidl_fd);
73 aidl_fd = -1;
74}