7b4bbb9f94
Create the skeletal binder interface for wpa_supplicant. The interface hierarchy is based off the existing dbus interface(https://w1.fi/wpa_supplicant/devel/dbus.html). Since we use libbinder, the binder interface codebase needs to be written in C++ and can only be compiled on Android platform for now. The aidl files define binder RPC interfaces. The Android build system generates the corresponding C++ interface classes which needs to be implemented by the server process. The clients can obtain a reference to the binder service (root object) using: android::String16 service_name("fi.w1.wpa_supplicant"); android::sp<android::IBinder> binder = android::defaultServiceManager()->getService(service_name); Once a reference to the root object is retrieved, the clients can obtain references to other RPC objects using that root object methods. Signed-off-by: Roshan Pius <rpius@google.com>
80 lines
2.2 KiB
C++
80 lines
2.2 KiB
C++
/*
|
|
* binder interface for wpa_supplicant daemon
|
|
* Copyright (c) 2004-2016, Jouni Malinen <j@w1.fi>
|
|
* Copyright (c) 2004-2016, Roshan Pius <rpius@google.com>
|
|
*
|
|
* This software may be distributed under the terms of the BSD license.
|
|
* See README for more details.
|
|
*/
|
|
|
|
#include <binder/IPCThreadState.h>
|
|
#include <binder/ProcessState.h>
|
|
#include <binder/IServiceManager.h>
|
|
|
|
#include "binder_manager.h"
|
|
|
|
extern "C" {
|
|
#include "utils/includes.h"
|
|
#include "utils/common.h"
|
|
#include "utils/eloop.h"
|
|
#include "binder.h"
|
|
#include "binder_i.h"
|
|
}
|
|
|
|
void wpas_binder_sock_handler(int sock, void *eloop_ctx, void *sock_ctx)
|
|
{
|
|
struct wpa_global *global = (wpa_global *) eloop_ctx;
|
|
struct wpas_binder_priv *priv = (wpas_binder_priv *) sock_ctx;
|
|
|
|
wpa_printf(MSG_DEBUG, "Processing binder events on FD %d",
|
|
priv->binder_fd);
|
|
android::IPCThreadState::self()->handlePolledCommands();
|
|
}
|
|
|
|
|
|
struct wpas_binder_priv * wpas_binder_init(struct wpa_global *global)
|
|
{
|
|
struct wpas_binder_priv *priv;
|
|
wpa_supplicant_binder::BinderManager *binder_manager;
|
|
|
|
priv = (wpas_binder_priv *) os_zalloc(sizeof(*priv));
|
|
if (!priv)
|
|
return NULL;
|
|
priv->global = global;
|
|
|
|
android::ProcessState::self()->setThreadPoolMaxThreadCount(0);
|
|
android::IPCThreadState::self()->disableBackgroundScheduling(true);
|
|
android::IPCThreadState::self()->setupPolling(&priv->binder_fd);
|
|
wpa_printf(MSG_INFO, "Process binder events on FD %d", priv->binder_fd);
|
|
if (priv->binder_fd < 0)
|
|
goto err;
|
|
/* Look for read events from the binder socket in the eloop. */
|
|
if (eloop_register_read_sock(priv->binder_fd, wpas_binder_sock_handler,
|
|
global, priv) < 0)
|
|
goto err;
|
|
|
|
binder_manager = wpa_supplicant_binder::BinderManager::getInstance();
|
|
if (!binder_manager)
|
|
goto err;
|
|
binder_manager->registerBinderService(global);
|
|
/* We may not need to store this binder manager reference in the
|
|
* global data strucure because we've made it a singleton class. */
|
|
priv->binder_manager = (void *) binder_manager;
|
|
|
|
return priv;
|
|
|
|
err:
|
|
wpas_binder_deinit(priv);
|
|
return NULL;
|
|
}
|
|
|
|
|
|
void wpas_binder_deinit(struct wpas_binder_priv *priv)
|
|
{
|
|
if (!priv)
|
|
return;
|
|
|
|
wpa_supplicant_binder::BinderManager::destroyInstance();
|
|
eloop_unregister_read_sock(priv->binder_fd);
|
|
android::IPCThreadState::shutdown();
|
|
}
|