Gabriel Biren | 72cf9a5 | 2021-06-25 23:29:26 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 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 | |
| 29 | void hostapd_aidl_sock_handler( |
| 30 | int /* sock */, void * /* eloop_ctx */, void * /* sock_ctx */) |
| 31 | { |
| 32 | ABinderProcess_handlePolledCommands(); |
| 33 | } |
| 34 | |
| 35 | int 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; |
| 59 | err: |
| 60 | hostapd_aidl_deinit(interfaces); |
| 61 | return -1; |
| 62 | } |
| 63 | |
| 64 | void hostapd_aidl_deinit(struct hapd_interfaces *interfaces) |
| 65 | { |
| 66 | wpa_printf(MSG_INFO, "Deiniting aidl control"); |
Gabriel Biren | f2f4a31 | 2022-02-11 23:07:33 +0000 | [diff] [blame^] | 67 | // Before aidl deinit, make sure call terminate to clear callback_ |
| 68 | if (service) { |
| 69 | service->terminate(); |
| 70 | } |
Gabriel Biren | 72cf9a5 | 2021-06-25 23:29:26 +0000 | [diff] [blame] | 71 | eloop_unregister_read_sock(aidl_fd); |
| 72 | aidl_fd = -1; |
| 73 | } |