2 * binder interface for wpa_supplicant daemon
3 * Copyright (c) 2004-2016, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2004-2016, Roshan Pius <rpius@google.com>
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
10 #include <binder/IServiceManager.h>
12 #include "binder_manager.h"
15 #include "utils/includes.h"
16 #include "utils/common.h"
19 namespace wpa_supplicant_binder {
21 const char BinderManager::kBinderServiceName[] = "fi.w1.wpa_supplicant";
22 BinderManager *BinderManager::instance_ = NULL;
25 BinderManager * BinderManager::getInstance()
28 instance_ = new BinderManager();
33 void BinderManager::destroyInstance()
41 int BinderManager::registerBinderService(struct wpa_global *global)
43 /* Create the main binder service object and register with
44 * system service manager. */
45 supplicant_object_ = new Supplicant(global);
46 android::String16 service_name(kBinderServiceName);
47 android::defaultServiceManager()->addService(
49 android::IInterface::asBinder(supplicant_object_));
54 int BinderManager::registerInterface(struct wpa_supplicant *wpa_s)
59 /* Using the corresponding wpa_supplicant pointer as key to our
61 const void *iface_key = wpa_s;
63 /* Return failure if we already have an object for that iface_key. */
64 if (iface_object_map_.find(iface_key) != iface_object_map_.end())
67 iface_object_map_[iface_key] = new Iface(wpa_s);
68 if (!iface_object_map_[iface_key].get())
71 wpa_s->binder_object_key = iface_key;
77 int BinderManager::unregisterInterface(struct wpa_supplicant *wpa_s)
79 if (!wpa_s || !wpa_s->binder_object_key)
82 const void *iface_key = wpa_s;
83 if (iface_object_map_.find(iface_key) == iface_object_map_.end())
86 /* Delete the corresponding iface object from our map. */
87 iface_object_map_.erase(iface_key);
88 wpa_s->binder_object_key = NULL;
93 int BinderManager::getIfaceBinderObjectByKey(
94 const void *iface_object_key,
95 android::sp<fi::w1::wpa_supplicant::IIface> *iface_object)
97 if (!iface_object_key || !iface_object)
100 if (iface_object_map_.find(iface_object_key) == iface_object_map_.end())
103 *iface_object = iface_object_map_[iface_object_key];
107 } /* namespace wpa_supplicant_binder */