Home | History | Annotate | Line # | Download | only in binder
      1  1.1  christos /*
      2  1.1  christos  * binder interface for wpa_supplicant daemon
      3  1.1  christos  * Copyright (c) 2004-2016, Jouni Malinen <j (at) w1.fi>
      4  1.1  christos  * Copyright (c) 2004-2016, Roshan Pius <rpius (at) google.com>
      5  1.1  christos  *
      6  1.1  christos  * This software may be distributed under the terms of the BSD license.
      7  1.1  christos  * See README for more details.
      8  1.1  christos  */
      9  1.1  christos 
     10  1.1  christos #include <binder/IServiceManager.h>
     11  1.1  christos 
     12  1.1  christos #include "binder_constants.h"
     13  1.1  christos #include "binder_manager.h"
     14  1.1  christos 
     15  1.1  christos extern "C" {
     16  1.1  christos #include "utils/common.h"
     17  1.1  christos #include "utils/includes.h"
     18  1.1  christos }
     19  1.1  christos 
     20  1.1  christos namespace wpa_supplicant_binder {
     21  1.1  christos 
     22  1.1  christos BinderManager *BinderManager::instance_ = NULL;
     23  1.1  christos 
     24  1.1  christos BinderManager *BinderManager::getInstance()
     25  1.1  christos {
     26  1.1  christos 	if (!instance_)
     27  1.1  christos 		instance_ = new BinderManager();
     28  1.1  christos 	return instance_;
     29  1.1  christos }
     30  1.1  christos 
     31  1.1  christos void BinderManager::destroyInstance()
     32  1.1  christos {
     33  1.1  christos 	if (instance_)
     34  1.1  christos 		delete instance_;
     35  1.1  christos 	instance_ = NULL;
     36  1.1  christos }
     37  1.1  christos 
     38  1.1  christos int BinderManager::registerBinderService(struct wpa_global *global)
     39  1.1  christos {
     40  1.1  christos 	/* Create the main binder service object and register with
     41  1.1  christos 	 * system service manager. */
     42  1.1  christos 	supplicant_object_ = new Supplicant(global);
     43  1.1  christos 	android::String16 service_name(binder_constants::kServiceName);
     44  1.1  christos 	android::defaultServiceManager()->addService(
     45  1.1  christos 	    service_name, android::IInterface::asBinder(supplicant_object_));
     46  1.1  christos 	return 0;
     47  1.1  christos }
     48  1.1  christos 
     49  1.1  christos int BinderManager::registerInterface(struct wpa_supplicant *wpa_s)
     50  1.1  christos {
     51  1.1  christos 	if (!wpa_s)
     52  1.1  christos 		return 1;
     53  1.1  christos 
     54  1.1  christos 	/* Using the corresponding wpa_supplicant pointer as key to our
     55  1.1  christos 	 * object map. */
     56  1.1  christos 	const void *iface_key = wpa_s;
     57  1.1  christos 
     58  1.1  christos 	/* Return failure if we already have an object for that iface_key. */
     59  1.1  christos 	if (iface_object_map_.find(iface_key) != iface_object_map_.end())
     60  1.1  christos 		return 1;
     61  1.1  christos 
     62  1.1  christos 	iface_object_map_[iface_key] = new Iface(wpa_s);
     63  1.1  christos 	if (!iface_object_map_[iface_key].get())
     64  1.1  christos 		return 1;
     65  1.1  christos 
     66  1.1  christos 	wpa_s->binder_object_key = iface_key;
     67  1.1  christos 
     68  1.1  christos 	return 0;
     69  1.1  christos }
     70  1.1  christos 
     71  1.1  christos int BinderManager::unregisterInterface(struct wpa_supplicant *wpa_s)
     72  1.1  christos {
     73  1.1  christos 	if (!wpa_s || !wpa_s->binder_object_key)
     74  1.1  christos 		return 1;
     75  1.1  christos 
     76  1.1  christos 	const void *iface_key = wpa_s;
     77  1.1  christos 	if (iface_object_map_.find(iface_key) == iface_object_map_.end())
     78  1.1  christos 		return 1;
     79  1.1  christos 
     80  1.1  christos 	/* Delete the corresponding iface object from our map. */
     81  1.1  christos 	iface_object_map_.erase(iface_key);
     82  1.1  christos 	wpa_s->binder_object_key = NULL;
     83  1.1  christos 	return 0;
     84  1.1  christos }
     85  1.1  christos 
     86  1.1  christos int BinderManager::getIfaceBinderObjectByKey(
     87  1.1  christos     const void *iface_object_key,
     88  1.1  christos     android::sp<fi::w1::wpa_supplicant::IIface> *iface_object)
     89  1.1  christos {
     90  1.1  christos 	if (!iface_object_key || !iface_object)
     91  1.1  christos 		return 1;
     92  1.1  christos 
     93  1.1  christos 	if (iface_object_map_.find(iface_object_key) == iface_object_map_.end())
     94  1.1  christos 		return 1;
     95  1.1  christos 
     96  1.1  christos 	*iface_object = iface_object_map_[iface_object_key];
     97  1.1  christos 	return 0;
     98  1.1  christos }
     99  1.1  christos 
    100  1.1  christos } /* namespace wpa_supplicant_binder */
    101