blob: e9032217fd5b125622a0396c01c3f5fa93a60ef5 [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
67Return<ISupplicant::DebugLevel> Supplicant::getDebugLevel()
68{
Roshan Piusbded3202016-11-15 10:34:04 -080069 // TODO: Add SupplicantStatus in this method return for uniformity with
70 // the other methods in supplicant HIDL interface.
Roshan Pius7c0ebf22016-09-20 15:11:56 -070071 return (ISupplicant::DebugLevel)wpa_debug_level;
72}
73
74Return<bool> Supplicant::isDebugShowTimestampEnabled()
75{
Roshan Piusbded3202016-11-15 10:34:04 -080076 // TODO: Add SupplicantStatus in this method return for uniformity with
77 // the other methods in supplicant HIDL interface.
78 return ((wpa_debug_timestamp != 0) ? true : false);
Roshan Pius7c0ebf22016-09-20 15:11:56 -070079}
80
81Return<bool> Supplicant::isDebugShowKeysEnabled()
82{
Roshan Piusbded3202016-11-15 10:34:04 -080083 // TODO: Add SupplicantStatus in this method return for uniformity with
84 // the other methods in supplicant HIDL interface.
85 return ((wpa_debug_show_keys != 0) ? true : false);
86}
87
88std::pair<SupplicantStatus, sp<ISupplicantIface>>
89Supplicant::getInterfaceInternal(const IfaceInfo& iface_info)
90{
91 struct wpa_supplicant* wpa_s =
92 wpa_supplicant_get_iface(wpa_global_, iface_info.name.c_str());
93 if (!wpa_s) {
94 return {{SupplicantStatusCode::FAILURE_IFACE_UNKNOWN, ""},
95 nullptr};
96 }
97 HidlManager* hidl_manager = HidlManager::getInstance();
98 if (iface_info.type == IfaceType::P2P) {
99 android::sp<ISupplicantP2pIface> iface;
100 if (!hidl_manager ||
101 hidl_manager->getP2pIfaceHidlObjectByIfname(
102 wpa_s->ifname, &iface)) {
103 return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""},
104 iface};
105 }
106 return {{SupplicantStatusCode::SUCCESS, ""}, iface};
107 } else {
108 android::sp<ISupplicantStaIface> iface;
109 if (!hidl_manager ||
110 hidl_manager->getStaIfaceHidlObjectByIfname(
111 wpa_s->ifname, &iface)) {
112 return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""},
113 iface};
114 }
115 return {{SupplicantStatusCode::SUCCESS, ""}, iface};
116 }
117}
118
119std::pair<SupplicantStatus, std::vector<ISupplicant::IfaceInfo>>
120Supplicant::listInterfacesInternal()
121{
122 std::vector<ISupplicant::IfaceInfo> ifaces;
123 for (struct wpa_supplicant* wpa_s = wpa_global_->ifaces; wpa_s;
124 wpa_s = wpa_s->next) {
125 if (wpa_s->global->p2p_init_wpa_s == wpa_s) {
126 ifaces.emplace_back(ISupplicant::IfaceInfo{
127 IfaceType::P2P, wpa_s->ifname});
128 } else {
129 ifaces.emplace_back(ISupplicant::IfaceInfo{
130 IfaceType::STA, wpa_s->ifname});
131 }
132 }
133 return {{SupplicantStatusCode::SUCCESS, ""}, std::move(ifaces)};
134}
135
136SupplicantStatus Supplicant::registerCallbackInternal(
137 const sp<ISupplicantCallback>& callback)
138{
139 HidlManager* hidl_manager = HidlManager::getInstance();
140 if (!hidl_manager ||
141 hidl_manager->addSupplicantCallbackHidlObject(callback)) {
142 return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
143 }
144 return {SupplicantStatusCode::SUCCESS, ""};
145}
146
147SupplicantStatus Supplicant::setDebugParamsInternal(
148 ISupplicant::DebugLevel level, bool show_timestamp, bool show_keys)
149{
150 if (wpa_supplicant_set_debug_params(
151 wpa_global_, static_cast<uint32_t>(level), show_timestamp,
152 show_keys)) {
153 return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
154 }
155 return {SupplicantStatusCode::SUCCESS, ""};
Roshan Pius7c0ebf22016-09-20 15:11:56 -0700156}
157} // namespace implementation
158} // namespace V1_0
159} // namespace wifi
160} // namespace supplicant
161} // namespace hardware
162} // namespace android