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 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 10 | #include "supplicant.h" |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 11 | #include "binder_manager.h" |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 12 | |
| 13 | namespace wpa_supplicant_binder { |
| 14 | |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 15 | Supplicant::Supplicant(struct wpa_global *global) : wpa_global_(global) {} |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 16 | |
| 17 | android::binder::Status Supplicant::CreateInterface( |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 18 | const android::os::PersistableBundle ¶ms, |
| 19 | android::sp<fi::w1::wpa_supplicant::IIface> *aidl_return) |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 20 | { |
| 21 | android::String16 driver, ifname, confname, bridge_ifname; |
| 22 | |
| 23 | /* Check if required Ifname argument is missing */ |
Roshan Pius | 32c15e2 | 2016-07-07 13:46:39 -0700 | [diff] [blame] | 24 | if (!params.getString(android::String16("Ifname"), &ifname)) { |
Roshan Pius | d6e3751 | 2016-07-07 13:20:46 -0700 | [diff] [blame] | 25 | return android::binder::Status::fromExceptionCode( |
| 26 | android::binder::Status::EX_ILLEGAL_ARGUMENT, |
| 27 | "Ifname missing in params."); |
Roshan Pius | 32c15e2 | 2016-07-07 13:46:39 -0700 | [diff] [blame] | 28 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 29 | /* Retrieve the remaining params from the dictionary */ |
| 30 | params.getString(android::String16("Driver"), &driver); |
| 31 | params.getString(android::String16("ConfigFile"), &confname); |
| 32 | params.getString(android::String16("BridgeIfname"), &bridge_ifname); |
| 33 | |
| 34 | /* |
| 35 | * Try to get the wpa_supplicant record for this iface, return |
| 36 | * an error if we already control it. |
| 37 | */ |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 38 | if (wpa_supplicant_get_iface( |
Roshan Pius | 32c15e2 | 2016-07-07 13:46:39 -0700 | [diff] [blame] | 39 | wpa_global_, android::String8(ifname).string()) != NULL) { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 40 | return android::binder::Status::fromServiceSpecificError( |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 41 | ERROR_IFACE_EXISTS, |
Roshan Pius | d6e3751 | 2016-07-07 13:20:46 -0700 | [diff] [blame] | 42 | "wpa_supplicant already controls this interface."); |
Roshan Pius | 32c15e2 | 2016-07-07 13:46:39 -0700 | [diff] [blame] | 43 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 44 | |
| 45 | android::binder::Status status; |
| 46 | struct wpa_supplicant *wpa_s = NULL; |
| 47 | struct wpa_interface iface; |
| 48 | |
| 49 | os_memset(&iface, 0, sizeof(iface)); |
| 50 | iface.driver = os_strdup(android::String8(driver).string()); |
| 51 | iface.ifname = os_strdup(android::String8(ifname).string()); |
| 52 | iface.confname = os_strdup(android::String8(confname).string()); |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 53 | iface.bridge_ifname = |
| 54 | os_strdup(android::String8(bridge_ifname).string()); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 55 | /* Otherwise, have wpa_supplicant attach to it. */ |
| 56 | wpa_s = wpa_supplicant_add_iface(wpa_global_, &iface, NULL); |
| 57 | /* The supplicant core creates a corresponding binder object via |
| 58 | * BinderManager when |wpa_supplicant_add_iface| is called. */ |
Roshan Pius | 32c15e2 | 2016-07-07 13:46:39 -0700 | [diff] [blame] | 59 | if (!wpa_s) { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 60 | status = android::binder::Status::fromServiceSpecificError( |
Roshan Pius | d6e3751 | 2016-07-07 13:20:46 -0700 | [diff] [blame] | 61 | ERROR_GENERIC, |
| 62 | "wpa_supplicant couldn't grab this interface."); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 63 | } else { |
| 64 | BinderManager *binder_manager = BinderManager::getInstance(); |
| 65 | |
| 66 | if (!binder_manager || |
Roshan Pius | 32c15e2 | 2016-07-07 13:46:39 -0700 | [diff] [blame] | 67 | binder_manager->getIfaceBinderObjectByIfname( |
| 68 | wpa_s->ifname, aidl_return)) { |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 69 | status = |
| 70 | android::binder::Status::fromServiceSpecificError( |
Roshan Pius | d6e3751 | 2016-07-07 13:20:46 -0700 | [diff] [blame] | 71 | ERROR_GENERIC, |
| 72 | "wpa_supplicant encountered a binder error."); |
Roshan Pius | 32c15e2 | 2016-07-07 13:46:39 -0700 | [diff] [blame] | 73 | } else { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 74 | status = android::binder::Status::ok(); |
Roshan Pius | 32c15e2 | 2016-07-07 13:46:39 -0700 | [diff] [blame] | 75 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 76 | } |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 77 | os_free((void *)iface.driver); |
| 78 | os_free((void *)iface.ifname); |
| 79 | os_free((void *)iface.confname); |
| 80 | os_free((void *)iface.bridge_ifname); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 81 | return status; |
| 82 | } |
| 83 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 84 | android::binder::Status Supplicant::RemoveInterface(const std::string &ifname) |
| 85 | { |
| 86 | struct wpa_supplicant *wpa_s; |
| 87 | |
| 88 | wpa_s = wpa_supplicant_get_iface(wpa_global_, ifname.c_str()); |
Roshan Pius | 32c15e2 | 2016-07-07 13:46:39 -0700 | [diff] [blame] | 89 | if (!wpa_s) { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 90 | return android::binder::Status::fromServiceSpecificError( |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 91 | ERROR_IFACE_UNKNOWN, |
Roshan Pius | d6e3751 | 2016-07-07 13:20:46 -0700 | [diff] [blame] | 92 | "wpa_supplicant does not control this interface."); |
Roshan Pius | 32c15e2 | 2016-07-07 13:46:39 -0700 | [diff] [blame] | 93 | } |
| 94 | if (wpa_supplicant_remove_iface(wpa_global_, wpa_s, 0)) { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 95 | return android::binder::Status::fromServiceSpecificError( |
Roshan Pius | d6e3751 | 2016-07-07 13:20:46 -0700 | [diff] [blame] | 96 | ERROR_GENERIC, |
| 97 | "wpa_supplicant couldn't remove this interface."); |
Roshan Pius | 32c15e2 | 2016-07-07 13:46:39 -0700 | [diff] [blame] | 98 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 99 | return android::binder::Status::ok(); |
| 100 | } |
| 101 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 102 | android::binder::Status Supplicant::GetInterface( |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 103 | const std::string &ifname, |
| 104 | android::sp<fi::w1::wpa_supplicant::IIface> *aidl_return) |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 105 | { |
| 106 | struct wpa_supplicant *wpa_s; |
| 107 | |
| 108 | wpa_s = wpa_supplicant_get_iface(wpa_global_, ifname.c_str()); |
Roshan Pius | 32c15e2 | 2016-07-07 13:46:39 -0700 | [diff] [blame] | 109 | if (!wpa_s) { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 110 | return android::binder::Status::fromServiceSpecificError( |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 111 | ERROR_IFACE_UNKNOWN, |
Roshan Pius | d6e3751 | 2016-07-07 13:20:46 -0700 | [diff] [blame] | 112 | "wpa_supplicant does not control this interface."); |
Roshan Pius | 32c15e2 | 2016-07-07 13:46:39 -0700 | [diff] [blame] | 113 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 114 | |
| 115 | BinderManager *binder_manager = BinderManager::getInstance(); |
| 116 | if (!binder_manager || |
Roshan Pius | 32c15e2 | 2016-07-07 13:46:39 -0700 | [diff] [blame] | 117 | binder_manager->getIfaceBinderObjectByIfname( |
| 118 | wpa_s->ifname, aidl_return)) { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 119 | return android::binder::Status::fromServiceSpecificError( |
Roshan Pius | d6e3751 | 2016-07-07 13:20:46 -0700 | [diff] [blame] | 120 | ERROR_GENERIC, |
| 121 | "wpa_supplicant encountered a binder error."); |
Roshan Pius | 32c15e2 | 2016-07-07 13:46:39 -0700 | [diff] [blame] | 122 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 123 | |
| 124 | return android::binder::Status::ok(); |
| 125 | } |
| 126 | |
| 127 | } /* namespace wpa_supplicant_binder */ |