blob: b9f6ce2236e2f62c7d664838177b44e62bd32bf9 [file] [log] [blame]
Dmitry Shmidte4663042016-04-04 10:07:49 -07001/*
Roshan Pius57ffbcf2016-09-27 09:12:46 -07002 * hidl interface for wpa_supplicant daemon
Dmitry Shmidte4663042016-04-04 10:07:49 -07003 * 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
Roshan Pius57ffbcf2016-09-27 09:12:46 -070010#include "hidl_manager.h"
Roshan Pius7c0ebf22016-09-20 15:11:56 -070011#include "hidl_return_macros.h"
12#include "supplicant.h"
Dmitry Shmidte4663042016-04-04 10:07:49 -070013
Roshan Pius7c0ebf22016-09-20 15:11:56 -070014namespace android {
15namespace hardware {
16namespace wifi {
17namespace supplicant {
18namespace V1_0 {
19namespace implementation {
Dmitry Shmidte4663042016-04-04 10:07:49 -070020
Roshan Pius7c0ebf22016-09-20 15:11:56 -070021// These are hardcoded for android.
22const char Supplicant::kDriverName[] = "nl80211";
23const char Supplicant::kConfigFilePath[] =
24 "/data/misc/wifi/wpa_supplicant.conf";
25
26Supplicant::Supplicant(struct wpa_global* global) : wpa_global_(global) {}
27Return<void> Supplicant::createInterface(
28 const hidl_string& ifname, createInterface_cb _hidl_cb)
Dmitry Shmidte4663042016-04-04 10:07:49 -070029{
Roshan Pius7c0ebf22016-09-20 15:11:56 -070030 android::sp<ISupplicantIface> iface;
31
32 // Check if required |ifname| argument is empty.
33 if (ifname.size() == 0) {
34 HIDL_RETURN(SupplicantStatusCode::FAILURE_ARGS_INVALID, iface);
Roshan Pius32c15e22016-07-07 13:46:39 -070035 }
Roshan Pius7c0ebf22016-09-20 15:11:56 -070036 // Try to get the wpa_supplicant record for this iface, return
37 // an error if we already control it.
38 if (wpa_supplicant_get_iface(wpa_global_, ifname.c_str()) != NULL) {
39 HIDL_RETURN(SupplicantStatusCode::FAILURE_IFACE_EXISTS, iface);
Roshan Pius32c15e22016-07-07 13:46:39 -070040 }
Dmitry Shmidte4663042016-04-04 10:07:49 -070041
Roshan Pius7c0ebf22016-09-20 15:11:56 -070042 // Otherwise, have wpa_supplicant attach to it.
43 struct wpa_supplicant* wpa_s = NULL;
44 struct wpa_interface iface_params;
45 os_memset(&iface_params, 0, sizeof(iface));
46 iface_params.ifname = ifname.c_str();
47 iface_params.confname = kConfigFilePath;
48 iface_params.driver = kDriverName;
49 wpa_s = wpa_supplicant_add_iface(wpa_global_, &iface_params, NULL);
Roshan Pius32c15e22016-07-07 13:46:39 -070050 if (!wpa_s) {
Roshan Pius7c0ebf22016-09-20 15:11:56 -070051 HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN, iface);
Dmitry Shmidte4663042016-04-04 10:07:49 -070052 }
Roshan Pius7c0ebf22016-09-20 15:11:56 -070053 // The supplicant core creates a corresponding hidl object via
54 // HidlManager when |wpa_supplicant_add_iface| is called.
55 HidlManager* hidl_manager = HidlManager::getInstance();
56 if (!hidl_manager ||
57 hidl_manager->getIfaceHidlObjectByIfname(wpa_s->ifname, &iface)) {
58 HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN, iface);
59 }
60
61 HIDL_RETURN(SupplicantStatusCode::SUCCESS, iface);
Dmitry Shmidte4663042016-04-04 10:07:49 -070062}
63
Roshan Pius7c0ebf22016-09-20 15:11:56 -070064Return<void> Supplicant::removeInterface(
65 const hidl_string& ifname, removeInterface_cb _hidl_cb)
Dmitry Shmidte4663042016-04-04 10:07:49 -070066{
Roshan Pius7c0ebf22016-09-20 15:11:56 -070067 struct wpa_supplicant* wpa_s;
Dmitry Shmidte4663042016-04-04 10:07:49 -070068
69 wpa_s = wpa_supplicant_get_iface(wpa_global_, ifname.c_str());
Roshan Pius32c15e22016-07-07 13:46:39 -070070 if (!wpa_s) {
Roshan Pius7c0ebf22016-09-20 15:11:56 -070071 HIDL_RETURN(SupplicantStatusCode::FAILURE_IFACE_UNKNOWN);
Roshan Pius32c15e22016-07-07 13:46:39 -070072 }
73 if (wpa_supplicant_remove_iface(wpa_global_, wpa_s, 0)) {
Roshan Pius7c0ebf22016-09-20 15:11:56 -070074 HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
Roshan Pius32c15e22016-07-07 13:46:39 -070075 }
Roshan Pius7c0ebf22016-09-20 15:11:56 -070076
77 HIDL_RETURN(SupplicantStatusCode::SUCCESS);
Dmitry Shmidte4663042016-04-04 10:07:49 -070078}
79
Roshan Pius7c0ebf22016-09-20 15:11:56 -070080Return<void> Supplicant::getInterface(
81 const hidl_string& ifname, getInterface_cb _hidl_cb)
Dmitry Shmidte4663042016-04-04 10:07:49 -070082{
Roshan Pius7c0ebf22016-09-20 15:11:56 -070083 android::sp<ISupplicantIface> iface;
Dmitry Shmidte4663042016-04-04 10:07:49 -070084
Roshan Pius7c0ebf22016-09-20 15:11:56 -070085 struct wpa_supplicant* wpa_s =
86 wpa_supplicant_get_iface(wpa_global_, ifname.c_str());
Roshan Pius32c15e22016-07-07 13:46:39 -070087 if (!wpa_s) {
Roshan Pius7c0ebf22016-09-20 15:11:56 -070088 HIDL_RETURN(SupplicantStatusCode::FAILURE_IFACE_UNKNOWN, iface);
Roshan Pius32c15e22016-07-07 13:46:39 -070089 }
Dmitry Shmidte4663042016-04-04 10:07:49 -070090
Roshan Pius7c0ebf22016-09-20 15:11:56 -070091 HidlManager* hidl_manager = HidlManager::getInstance();
Roshan Pius57ffbcf2016-09-27 09:12:46 -070092 if (!hidl_manager ||
Roshan Pius7c0ebf22016-09-20 15:11:56 -070093 hidl_manager->getIfaceHidlObjectByIfname(wpa_s->ifname, &iface)) {
94 HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN, iface);
Roshan Pius32c15e22016-07-07 13:46:39 -070095 }
Dmitry Shmidte4663042016-04-04 10:07:49 -070096
Roshan Pius7c0ebf22016-09-20 15:11:56 -070097 HIDL_RETURN(SupplicantStatusCode::SUCCESS, iface);
Dmitry Shmidte4663042016-04-04 10:07:49 -070098}
99
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700100Return<void> Supplicant::listInterfaces(listInterfaces_cb _hidl_cb)
Roshan Piusc9422c72016-07-11 10:18:22 -0700101{
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700102 std::vector<hidl_string> ifnames;
103 for (struct wpa_supplicant* wpa_s = wpa_global_->ifaces; wpa_s;
104 wpa_s = wpa_s->next) {
105 ifnames.emplace_back(wpa_s->ifname);
Roshan Piusc9422c72016-07-11 10:18:22 -0700106 }
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700107
108 HIDL_RETURN(SupplicantStatusCode::SUCCESS, ifnames);
Roshan Piusc9422c72016-07-11 10:18:22 -0700109}
110
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700111Return<void> Supplicant::registerCallback(
112 const sp<ISupplicantCallback>& callback, registerCallback_cb _hidl_cb)
Roshan Piusc9422c72016-07-11 10:18:22 -0700113{
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700114 HidlManager* hidl_manager = HidlManager::getInstance();
Roshan Pius57ffbcf2016-09-27 09:12:46 -0700115 if (!hidl_manager ||
116 hidl_manager->addSupplicantCallbackHidlObject(callback)) {
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700117 HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
Roshan Pius0470cc82016-07-14 16:37:07 -0700118 }
Roshan Pius0470cc82016-07-14 16:37:07 -0700119
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700120 HIDL_RETURN(SupplicantStatusCode::SUCCESS);
Roshan Piusc9422c72016-07-11 10:18:22 -0700121}
122
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700123Return<void> Supplicant::setDebugParams(
124 ISupplicant::DebugLevel level, bool show_timestamp, bool show_keys,
125 setDebugParams_cb _hidl_cb)
Roshan Piusc9422c72016-07-11 10:18:22 -0700126{
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700127 if (wpa_supplicant_set_debug_params(
128 wpa_global_, static_cast<uint32_t>(level), show_timestamp,
129 show_keys)) {
130 HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
Roshan Piusc9422c72016-07-11 10:18:22 -0700131 }
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700132
133 HIDL_RETURN(SupplicantStatusCode::SUCCESS);
Roshan Piusc9422c72016-07-11 10:18:22 -0700134}
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700135
136Return<ISupplicant::DebugLevel> Supplicant::getDebugLevel()
137{
138 return (ISupplicant::DebugLevel)wpa_debug_level;
139}
140
141Return<bool> Supplicant::isDebugShowTimestampEnabled()
142{
143 return (wpa_debug_timestamp ? true : false);
144}
145
146Return<bool> Supplicant::isDebugShowKeysEnabled()
147{
148 return (wpa_debug_show_keys ? true : false);
149}
150} // namespace implementation
151} // namespace V1_0
152} // namespace wifi
153} // namespace supplicant
154} // namespace hardware
155} // namespace android