Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 15 | extern "C" |
| 16 | { |
| 17 | #include "hidl.h" |
| 18 | #include "utils/common.h" |
| 19 | #include "utils/eloop.h" |
| 20 | #include "utils/includes.h" |
| 21 | } |
| 22 | |
| 23 | using android::hardware::configureRpcThreadpool; |
| 24 | using android::hardware::IPCThreadState; |
lesl | f8b1b40 | 2020-08-04 17:09:39 +0800 | [diff] [blame^] | 25 | using android::hardware::wifi::hostapd::V1_3::IHostapd; |
| 26 | using android::hardware::wifi::hostapd::V1_3::implementation::Hostapd; |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 27 | |
| 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! |
| 30 | static int hidl_fd = -1; |
| 31 | static android::sp<IHostapd> service; |
| 32 | |
| 33 | void hostapd_hidl_sock_handler( |
| 34 | int /* sock */, void * /* eloop_ctx */, void * /* sock_ctx */) |
| 35 | { |
| 36 | IPCThreadState::self()->handlePolledCommands(); |
| 37 | } |
| 38 | |
| 39 | int hostapd_hidl_init(struct hapd_interfaces *interfaces) |
| 40 | { |
| 41 | wpa_printf(MSG_DEBUG, "Initing hidl control"); |
| 42 | |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 43 | 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; |
| 58 | err: |
| 59 | hostapd_hidl_deinit(interfaces); |
| 60 | return -1; |
| 61 | } |
| 62 | |
| 63 | void 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 | } |