Home | History | Annotate | Download | only in 1.0
      1 /*
      2  * hidl interface for wpa_supplicant daemon
      3  * Copyright (c) 2004-2018, Jouni Malinen <j (at) w1.fi>
      4  * Copyright (c) 2004-2018, Roshan Pius <rpius (at) 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;
     25 using android::hardware::wifi::hostapd::V1_0::IHostapd;
     26 using android::hardware::wifi::hostapd::V1_0::implementation::Hostapd;
     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 
     43 	IPCThreadState::self()->disableBackgroundScheduling(true);
     44 	IPCThreadState::self()->setupPolling(&hidl_fd);
     45 	if (hidl_fd < 0)
     46 		goto err;
     47 
     48 	wpa_printf(MSG_INFO, "Processing hidl events on FD %d", hidl_fd);
     49 	// Look for read events from the hidl socket in the eloop.
     50 	if (eloop_register_read_sock(
     51 		hidl_fd, hostapd_hidl_sock_handler, interfaces, NULL) < 0)
     52 		goto err;
     53 	service = new Hostapd(interfaces);
     54 	if (!service)
     55 		goto err;
     56 	if (service->registerAsService() != android::NO_ERROR)
     57 		goto err;
     58 	return 0;
     59 err:
     60 	hostapd_hidl_deinit(interfaces);
     61 	return -1;
     62 }
     63 
     64 void hostapd_hidl_deinit(struct hapd_interfaces *interfaces)
     65 {
     66 	wpa_printf(MSG_DEBUG, "Deiniting hidl control");
     67 	eloop_unregister_read_sock(hidl_fd);
     68 	IPCThreadState::shutdown();
     69 	hidl_fd = -1;
     70 	service.clear();
     71 }
     72