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