blob: 409547f0702944906d118c4da4b5390af3fd0699 [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 Piusbded3202016-11-15 10:34:04 -080011#include "hidl_return_util.h"
Roshan Pius7c0ebf22016-09-20 15:11:56 -070012#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 {
Roshan Piusbded3202016-11-15 10:34:04 -080020using hidl_return_util::validateAndCall;
Dmitry Shmidte4663042016-04-04 10:07:49 -070021
Roshan Pius7c0ebf22016-09-20 15:11:56 -070022// These are hardcoded for android.
23const char Supplicant::kDriverName[] = "nl80211";
24const char Supplicant::kConfigFilePath[] =
25 "/data/misc/wifi/wpa_supplicant.conf";
26
27Supplicant::Supplicant(struct wpa_global* global) : wpa_global_(global) {}
Roshan Piusbded3202016-11-15 10:34:04 -080028bool Supplicant::isValid()
29{
30 // This top level object cannot be invalidated.
31 return true;
32}
33
Roshan Pius7c0ebf22016-09-20 15:11:56 -070034Return<void> Supplicant::getInterface(
Roshan Piuse286edf2016-11-01 16:56:42 -070035 const IfaceInfo& iface_info, getInterface_cb _hidl_cb)
Dmitry Shmidte4663042016-04-04 10:07:49 -070036{
Roshan Piusbded3202016-11-15 10:34:04 -080037 return validateAndCall(
38 this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
39 &Supplicant::getInterfaceInternal, _hidl_cb, iface_info);
Dmitry Shmidte4663042016-04-04 10:07:49 -070040}
41
Roshan Pius7c0ebf22016-09-20 15:11:56 -070042Return<void> Supplicant::listInterfaces(listInterfaces_cb _hidl_cb)
Roshan Piusc9422c72016-07-11 10:18:22 -070043{
Roshan Piusbded3202016-11-15 10:34:04 -080044 return validateAndCall(
45 this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
46 &Supplicant::listInterfacesInternal, _hidl_cb);
Roshan Piusc9422c72016-07-11 10:18:22 -070047}
48
Roshan Pius7c0ebf22016-09-20 15:11:56 -070049Return<void> Supplicant::registerCallback(
50 const sp<ISupplicantCallback>& callback, registerCallback_cb _hidl_cb)
Roshan Piusc9422c72016-07-11 10:18:22 -070051{
Roshan Piusbded3202016-11-15 10:34:04 -080052 return validateAndCall(
53 this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
54 &Supplicant::registerCallbackInternal, _hidl_cb, callback);
Roshan Piusc9422c72016-07-11 10:18:22 -070055}
56
Roshan Pius7c0ebf22016-09-20 15:11:56 -070057Return<void> Supplicant::setDebugParams(
58 ISupplicant::DebugLevel level, bool show_timestamp, bool show_keys,
59 setDebugParams_cb _hidl_cb)
Roshan Piusc9422c72016-07-11 10:18:22 -070060{
Roshan Piusbded3202016-11-15 10:34:04 -080061 return validateAndCall(
62 this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
63 &Supplicant::setDebugParamsInternal, _hidl_cb, level,
64 show_timestamp, show_keys);
Roshan Piusc9422c72016-07-11 10:18:22 -070065}
Roshan Pius7c0ebf22016-09-20 15:11:56 -070066
Roshan Pius36e21402016-11-15 15:59:42 -080067Return<void> Supplicant::setConcurrencyPriority(
68 IfaceType type, setConcurrencyPriority_cb _hidl_cb)
69{
70 return validateAndCall(
71 this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
72 &Supplicant::setConcurrencyPriorityInternal, _hidl_cb, type);
73}
74
Roshan Pius7c0ebf22016-09-20 15:11:56 -070075Return<ISupplicant::DebugLevel> Supplicant::getDebugLevel()
76{
Roshan Piusbded3202016-11-15 10:34:04 -080077 // TODO: Add SupplicantStatus in this method return for uniformity with
78 // the other methods in supplicant HIDL interface.
Roshan Pius7c0ebf22016-09-20 15:11:56 -070079 return (ISupplicant::DebugLevel)wpa_debug_level;
80}
81
82Return<bool> Supplicant::isDebugShowTimestampEnabled()
83{
Roshan Piusbded3202016-11-15 10:34:04 -080084 // TODO: Add SupplicantStatus in this method return for uniformity with
85 // the other methods in supplicant HIDL interface.
86 return ((wpa_debug_timestamp != 0) ? true : false);
Roshan Pius7c0ebf22016-09-20 15:11:56 -070087}
88
89Return<bool> Supplicant::isDebugShowKeysEnabled()
90{
Roshan Piusbded3202016-11-15 10:34:04 -080091 // TODO: Add SupplicantStatus in this method return for uniformity with
92 // the other methods in supplicant HIDL interface.
93 return ((wpa_debug_show_keys != 0) ? true : false);
94}
95
96std::pair<SupplicantStatus, sp<ISupplicantIface>>
97Supplicant::getInterfaceInternal(const IfaceInfo& iface_info)
98{
99 struct wpa_supplicant* wpa_s =
100 wpa_supplicant_get_iface(wpa_global_, iface_info.name.c_str());
101 if (!wpa_s) {
102 return {{SupplicantStatusCode::FAILURE_IFACE_UNKNOWN, ""},
103 nullptr};
104 }
105 HidlManager* hidl_manager = HidlManager::getInstance();
106 if (iface_info.type == IfaceType::P2P) {
107 android::sp<ISupplicantP2pIface> iface;
108 if (!hidl_manager ||
109 hidl_manager->getP2pIfaceHidlObjectByIfname(
110 wpa_s->ifname, &iface)) {
111 return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""},
112 iface};
113 }
114 return {{SupplicantStatusCode::SUCCESS, ""}, iface};
115 } else {
116 android::sp<ISupplicantStaIface> iface;
117 if (!hidl_manager ||
118 hidl_manager->getStaIfaceHidlObjectByIfname(
119 wpa_s->ifname, &iface)) {
120 return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""},
121 iface};
122 }
123 return {{SupplicantStatusCode::SUCCESS, ""}, iface};
124 }
125}
126
127std::pair<SupplicantStatus, std::vector<ISupplicant::IfaceInfo>>
128Supplicant::listInterfacesInternal()
129{
130 std::vector<ISupplicant::IfaceInfo> ifaces;
131 for (struct wpa_supplicant* wpa_s = wpa_global_->ifaces; wpa_s;
132 wpa_s = wpa_s->next) {
133 if (wpa_s->global->p2p_init_wpa_s == wpa_s) {
134 ifaces.emplace_back(ISupplicant::IfaceInfo{
135 IfaceType::P2P, wpa_s->ifname});
136 } else {
137 ifaces.emplace_back(ISupplicant::IfaceInfo{
138 IfaceType::STA, wpa_s->ifname});
139 }
140 }
141 return {{SupplicantStatusCode::SUCCESS, ""}, std::move(ifaces)};
142}
143
144SupplicantStatus Supplicant::registerCallbackInternal(
145 const sp<ISupplicantCallback>& callback)
146{
147 HidlManager* hidl_manager = HidlManager::getInstance();
148 if (!hidl_manager ||
149 hidl_manager->addSupplicantCallbackHidlObject(callback)) {
150 return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
151 }
152 return {SupplicantStatusCode::SUCCESS, ""};
153}
154
155SupplicantStatus Supplicant::setDebugParamsInternal(
156 ISupplicant::DebugLevel level, bool show_timestamp, bool show_keys)
157{
158 if (wpa_supplicant_set_debug_params(
159 wpa_global_, static_cast<uint32_t>(level), show_timestamp,
160 show_keys)) {
161 return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
162 }
163 return {SupplicantStatusCode::SUCCESS, ""};
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700164}
Roshan Pius36e21402016-11-15 15:59:42 -0800165
166SupplicantStatus Supplicant::setConcurrencyPriorityInternal(IfaceType type)
167{
Roshan Piusa1262872016-12-08 11:05:24 -0800168 if (type == IfaceType::STA) {
169 wpa_global_->conc_pref =
170 wpa_global::wpa_conc_pref::WPA_CONC_PREF_STA;
171 } else if (type == IfaceType::P2P) {
172 wpa_global_->conc_pref =
173 wpa_global::wpa_conc_pref::WPA_CONC_PREF_P2P;
174 } else {
175 return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
176 }
Roshan Pius36e21402016-11-15 15:59:42 -0800177 return SupplicantStatus{SupplicantStatusCode::SUCCESS, ""};
178}
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700179} // namespace implementation
180} // namespace V1_0
181} // namespace wifi
182} // namespace supplicant
183} // namespace hardware
184} // namespace android