1 /*
2 * hidl 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 "hidl_manager.h"
11 #include "hidl_return_util.h"
12 #include "supplicant.h"
13
14 namespace android {
15 namespace hardware {
16 namespace wifi {
17 namespace supplicant {
18 namespace V1_0 {
19 namespace implementation {
20 using hidl_return_util::validateAndCall;
21
22 // These are hardcoded for android.
23 const char Supplicant::kDriverName[] = "nl80211";
24 const char Supplicant::kConfigFilePath[] =
25 "/data/misc/wifi/wpa_supplicant.conf";
26
Supplicant(struct wpa_global * global)27 Supplicant::Supplicant(struct wpa_global* global) : wpa_global_(global) {}
isValid()28 bool Supplicant::isValid()
29 {
30 // This top level object cannot be invalidated.
31 return true;
32 }
33
getInterface(const IfaceInfo & iface_info,getInterface_cb _hidl_cb)34 Return<void> Supplicant::getInterface(
35 const IfaceInfo& iface_info, getInterface_cb _hidl_cb)
36 {
37 return validateAndCall(
38 this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
39 &Supplicant::getInterfaceInternal, _hidl_cb, iface_info);
40 }
41
listInterfaces(listInterfaces_cb _hidl_cb)42 Return<void> Supplicant::listInterfaces(listInterfaces_cb _hidl_cb)
43 {
44 return validateAndCall(
45 this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
46 &Supplicant::listInterfacesInternal, _hidl_cb);
47 }
48
registerCallback(const sp<ISupplicantCallback> & callback,registerCallback_cb _hidl_cb)49 Return<void> Supplicant::registerCallback(
50 const sp<ISupplicantCallback>& callback, registerCallback_cb _hidl_cb)
51 {
52 return validateAndCall(
53 this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
54 &Supplicant::registerCallbackInternal, _hidl_cb, callback);
55 }
56
setDebugParams(ISupplicant::DebugLevel level,bool show_timestamp,bool show_keys,setDebugParams_cb _hidl_cb)57 Return<void> Supplicant::setDebugParams(
58 ISupplicant::DebugLevel level, bool show_timestamp, bool show_keys,
59 setDebugParams_cb _hidl_cb)
60 {
61 return validateAndCall(
62 this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
63 &Supplicant::setDebugParamsInternal, _hidl_cb, level,
64 show_timestamp, show_keys);
65 }
66
setConcurrencyPriority(IfaceType type,setConcurrencyPriority_cb _hidl_cb)67 Return<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
getDebugLevel()75 Return<ISupplicant::DebugLevel> Supplicant::getDebugLevel()
76 {
77 // TODO: Add SupplicantStatus in this method return for uniformity with
78 // the other methods in supplicant HIDL interface.
79 return (ISupplicant::DebugLevel)wpa_debug_level;
80 }
81
isDebugShowTimestampEnabled()82 Return<bool> Supplicant::isDebugShowTimestampEnabled()
83 {
84 // 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);
87 }
88
isDebugShowKeysEnabled()89 Return<bool> Supplicant::isDebugShowKeysEnabled()
90 {
91 // 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
96 std::pair<SupplicantStatus, sp<ISupplicantIface>>
getInterfaceInternal(const IfaceInfo & iface_info)97 Supplicant::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
127 std::pair<SupplicantStatus, std::vector<ISupplicant::IfaceInfo>>
listInterfacesInternal()128 Supplicant::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
registerCallbackInternal(const sp<ISupplicantCallback> & callback)144 SupplicantStatus 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
setDebugParamsInternal(ISupplicant::DebugLevel level,bool show_timestamp,bool show_keys)155 SupplicantStatus 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, ""};
164 }
165
setConcurrencyPriorityInternal(IfaceType type)166 SupplicantStatus Supplicant::setConcurrencyPriorityInternal(IfaceType type)
167 {
168 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 }
177 return SupplicantStatus{SupplicantStatusCode::SUCCESS, ""};
178 }
179 } // namespace implementation
180 } // namespace V1_0
181 } // namespace wifi
182 } // namespace supplicant
183 } // namespace hardware
184 } // namespace android
185