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 "iface_config_utils.h"
13 #include "misc_utils.h"
14 #include "sta_iface.h"
15 
16 extern "C"
17 {
18 #include "utils/eloop.h"
19 #include "gas_query.h"
20 #include "interworking.h"
21 #include "hs20_supplicant.h"
22 #include "wps_supplicant.h"
23 #include "dpp.h"
24 #include "dpp_supplicant.h"
25 #include "rsn_supp/wpa.h"
26 #include "rsn_supp/pmksa_cache.h"
27 }
28 
29 namespace {
30 using ISupplicantStaNetworkV1_2 =
31 	android::hardware::wifi::supplicant::V1_2::ISupplicantStaNetwork;
32 using ISupplicantStaNetworkV1_3 =
33 	android::hardware::wifi::supplicant::V1_3::ISupplicantStaNetwork;
34 using android::hardware::wifi::V1_0::WifiChannelWidthInMhz;
35 using android::hardware::wifi::supplicant::V1_0::SupplicantStatus;
36 using android::hardware::wifi::supplicant::V1_0::SupplicantStatusCode;
37 using android::hardware::wifi::supplicant::V1_0::ISupplicantStaNetwork;
38 using android::hardware::wifi::supplicant::V1_3::WifiTechnology;
39 using android::hardware::wifi::supplicant::V1_4::ISupplicantStaIface;
40 using android::hardware::wifi::supplicant::V1_4::ConnectionCapabilities;
41 using android::hardware::wifi::supplicant::V1_4::LegacyMode;
42 using android::hardware::wifi::supplicant::V1_4::implementation::HidlManager;
43 using android::hardware::wifi::supplicant::V1_4::DppResponderBootstrapInfo;
44 using android::hardware::wifi::supplicant::V1_4::DppCurve;
45 
46 constexpr uint32_t kMaxAnqpElems = 100;
47 constexpr char kGetMacAddress[] = "MACADDR";
48 constexpr char kStartRxFilter[] = "RXFILTER-START";
49 constexpr char kStopRxFilter[] = "RXFILTER-STOP";
50 constexpr char kAddRxFilter[] = "RXFILTER-ADD";
51 constexpr char kRemoveRxFilter[] = "RXFILTER-REMOVE";
52 constexpr char kSetBtCoexistenceMode[] = "BTCOEXMODE";
53 constexpr char kSetBtCoexistenceScanStart[] = "BTCOEXSCAN-START";
54 constexpr char kSetBtCoexistenceScanStop[] = "BTCOEXSCAN-STOP";
55 constexpr char kSetSupendModeEnabled[] = "SETSUSPENDMODE 1";
56 constexpr char kSetSupendModeDisabled[] = "SETSUSPENDMODE 0";
57 constexpr char kSetCountryCode[] = "COUNTRY";
58 constexpr uint32_t kExtRadioWorkDefaultTimeoutInSec = static_cast<uint32_t>(
59     ISupplicantStaIface::ExtRadioWorkDefaults::TIMEOUT_IN_SECS);
60 constexpr char kExtRadioWorkNamePrefix[] = "ext:";
61 
convertHidlRxFilterTypeToInternal(ISupplicantStaIface::RxFilterType type)62 uint8_t convertHidlRxFilterTypeToInternal(
63     ISupplicantStaIface::RxFilterType type)
64 {
65 	switch (type) {
66 	case ISupplicantStaIface::RxFilterType::V4_MULTICAST:
67 		return 2;
68 	case ISupplicantStaIface::RxFilterType::V6_MULTICAST:
69 		return 3;
70 	};
71 	WPA_ASSERT(false);
72 }
73 
convertHidlBtCoexModeToInternal(ISupplicantStaIface::BtCoexistenceMode mode)74 uint8_t convertHidlBtCoexModeToInternal(
75     ISupplicantStaIface::BtCoexistenceMode mode)
76 {
77 	switch (mode) {
78 	case ISupplicantStaIface::BtCoexistenceMode::ENABLED:
79 		return 0;
80 	case ISupplicantStaIface::BtCoexistenceMode::DISABLED:
81 		return 1;
82 	case ISupplicantStaIface::BtCoexistenceMode::SENSE:
83 		return 2;
84 	};
85 	WPA_ASSERT(false);
86 }
87 
doZeroArgDriverCommand(struct wpa_supplicant * wpa_s,const char * cmd)88 SupplicantStatus doZeroArgDriverCommand(
89     struct wpa_supplicant *wpa_s, const char *cmd)
90 {
91 	std::vector<char> cmd_vec(cmd, cmd + strlen(cmd) + 1);
92 	char driver_cmd_reply_buf[4096] = {};
93 	if (wpa_drv_driver_cmd(
94 		wpa_s, cmd_vec.data(), driver_cmd_reply_buf,
95 		sizeof(driver_cmd_reply_buf))) {
96 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
97 	}
98 	return {SupplicantStatusCode::SUCCESS, ""};
99 }
100 
doOneArgDriverCommand(struct wpa_supplicant * wpa_s,const char * cmd,uint8_t arg)101 SupplicantStatus doOneArgDriverCommand(
102     struct wpa_supplicant *wpa_s, const char *cmd, uint8_t arg)
103 {
104 	std::string cmd_str = std::string(cmd) + " " + std::to_string(arg);
105 	return doZeroArgDriverCommand(wpa_s, cmd_str.c_str());
106 }
107 
doOneArgDriverCommand(struct wpa_supplicant * wpa_s,const char * cmd,const std::string & arg)108 SupplicantStatus doOneArgDriverCommand(
109     struct wpa_supplicant *wpa_s, const char *cmd, const std::string &arg)
110 {
111 	std::string cmd_str = std::string(cmd) + " " + arg;
112 	return doZeroArgDriverCommand(wpa_s, cmd_str.c_str());
113 }
114 
endExtRadioWork(struct wpa_radio_work * work)115 void endExtRadioWork(struct wpa_radio_work *work)
116 {
117 	auto *ework = static_cast<struct wpa_external_work *>(work->ctx);
118 	work->wpa_s->ext_work_in_progress = 0;
119 	radio_work_done(work);
120 	os_free(ework);
121 }
122 
extRadioWorkTimeoutCb(void * eloop_ctx,void * timeout_ctx)123 void extRadioWorkTimeoutCb(void *eloop_ctx, void *timeout_ctx)
124 {
125 	auto *work = static_cast<struct wpa_radio_work *>(eloop_ctx);
126 	auto *ework = static_cast<struct wpa_external_work *>(work->ctx);
127 	wpa_dbg(
128 	    work->wpa_s, MSG_DEBUG, "Timing out external radio work %u (%s)",
129 	    ework->id, work->type);
130 
131 	HidlManager *hidl_manager = HidlManager::getInstance();
132 	WPA_ASSERT(hidl_manager);
133 	hidl_manager->notifyExtRadioWorkTimeout(work->wpa_s, ework->id);
134 
135 	endExtRadioWork(work);
136 }
137 
startExtRadioWork(struct wpa_radio_work * work)138 void startExtRadioWork(struct wpa_radio_work *work)
139 {
140 	auto *ework = static_cast<struct wpa_external_work *>(work->ctx);
141 	work->wpa_s->ext_work_in_progress = 1;
142 	if (!ework->timeout) {
143 		ework->timeout = kExtRadioWorkDefaultTimeoutInSec;
144 	}
145 	eloop_register_timeout(
146 	    ework->timeout, 0, extRadioWorkTimeoutCb, work, nullptr);
147 }
148 
extRadioWorkStartCb(struct wpa_radio_work * work,int deinit)149 void extRadioWorkStartCb(struct wpa_radio_work *work, int deinit)
150 {
151 	// deinit==1 is invoked during interface removal. Since the HIDL
152 	// interface does not support interface addition/removal, we don't
153 	// need to handle this scenario.
154 	WPA_ASSERT(!deinit);
155 
156 	auto *ework = static_cast<struct wpa_external_work *>(work->ctx);
157 	wpa_dbg(
158 	    work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
159 	    ework->id, ework->type);
160 
161 	HidlManager *hidl_manager = HidlManager::getInstance();
162 	WPA_ASSERT(hidl_manager);
163 	hidl_manager->notifyExtRadioWorkStart(work->wpa_s, ework->id);
164 
165 	startExtRadioWork(work);
166 }
167 
convertWpaKeyMgmtCapabilitiesToHidl(struct wpa_supplicant * wpa_s,struct wpa_driver_capa * capa)168 uint32_t convertWpaKeyMgmtCapabilitiesToHidl (
169     struct wpa_supplicant *wpa_s, struct wpa_driver_capa *capa) {
170 
171 	uint32_t mask = 0;
172 	/* Logic from ctrl_iface.c, NONE and IEEE8021X have no capability
173 	 * flags and always enabled.
174 	 */
175 	mask |=
176 	    (ISupplicantStaNetwork::KeyMgmtMask::NONE |
177 	     ISupplicantStaNetwork::KeyMgmtMask::IEEE8021X);
178 
179 	if (capa->key_mgmt &
180 	    (WPA_DRIVER_CAPA_KEY_MGMT_WPA | WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
181 		mask |= ISupplicantStaNetwork::KeyMgmtMask::WPA_EAP;
182 	}
183 
184 	if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
185 			     WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
186 		mask |= ISupplicantStaNetwork::KeyMgmtMask::WPA_PSK;
187 	}
188 #ifdef CONFIG_SUITEB192
189 	if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
190 		mask |= ISupplicantStaNetworkV1_2::ISupplicantStaNetwork::KeyMgmtMask::SUITE_B_192;
191 	}
192 #endif /* CONFIG_SUITEB192 */
193 #ifdef CONFIG_OWE
194 	if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) {
195 		mask |= ISupplicantStaNetworkV1_2::ISupplicantStaNetwork::KeyMgmtMask::OWE;
196 	}
197 #endif /* CONFIG_OWE */
198 #ifdef CONFIG_SAE
199 	if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
200 		mask |= ISupplicantStaNetworkV1_2::ISupplicantStaNetwork::KeyMgmtMask::SAE;
201 	}
202 #endif /* CONFIG_SAE */
203 #ifdef CONFIG_DPP
204 	if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) {
205 		mask |= ISupplicantStaNetworkV1_2::ISupplicantStaNetwork::KeyMgmtMask::DPP;
206 	}
207 #endif
208 #ifdef CONFIG_WAPI_INTERFACE
209 	mask |= ISupplicantStaNetworkV1_3::ISupplicantStaNetwork::KeyMgmtMask::WAPI_PSK;
210 	mask |= ISupplicantStaNetworkV1_3::ISupplicantStaNetwork::KeyMgmtMask::WAPI_CERT;
211 #endif /* CONFIG_WAPI_INTERFACE */
212 #ifdef CONFIG_FILS
213 	if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) {
214 		mask |= ISupplicantStaNetworkV1_3::ISupplicantStaNetwork::KeyMgmtMask::FILS_SHA256;
215 	}
216 	if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) {
217 		mask |= ISupplicantStaNetworkV1_3::ISupplicantStaNetwork::KeyMgmtMask::FILS_SHA384;
218 	}
219 #endif /* CONFIG_FILS */
220 	return mask;
221 }
222 
getDppListenChannel(struct wpa_supplicant * wpa_s,int32_t * listen_channel)223 const std::string getDppListenChannel(struct wpa_supplicant *wpa_s, int32_t *listen_channel)
224 {
225 	struct hostapd_hw_modes *mode;
226 	int chan44 = 0, chan149 = 0;
227 	*listen_channel = 0;
228 
229 	/* Check if device support 2.4GHz band*/
230 	mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes,
231 			HOSTAPD_MODE_IEEE80211G, 0);
232 	if (mode) {
233 		*listen_channel = 6;
234 		return "81/6";
235 	}
236 	/* Check if device support 5GHz band */
237 	mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes,
238 			HOSTAPD_MODE_IEEE80211A, 0);
239 	if (mode) {
240 		for (int i = 0; i < mode->num_channels; i++) {
241 			struct hostapd_channel_data *chan = &mode->channels[i];
242 
243 			if (chan->flag & (HOSTAPD_CHAN_DISABLED |
244 					  HOSTAPD_CHAN_RADAR))
245 				continue;
246 			if (chan->freq == 5220)
247 				chan44 = 1;
248 			if (chan->freq == 5745)
249 				chan149 = 1;
250 		}
251 		if (chan149) {
252 			*listen_channel = 149;
253 			return "124/149";
254 		} else if (chan44) {
255 			*listen_channel = 44;
256 			return "115/44";
257 		}
258 	}
259 
260 	return "";
261 }
262 
convertCurveTypeToName(DppCurve curve)263 const std::string convertCurveTypeToName(DppCurve curve)
264 {
265 	switch (curve) {
266 	case DppCurve::PRIME256V1:
267 		return "prime256v1";
268 	case DppCurve::SECP384R1:
269 		return "secp384r1";
270 	case DppCurve::SECP521R1:
271 		return "secp521r1";
272 	case DppCurve::BRAINPOOLP256R1:
273 		return "brainpoolP256r1";
274 	case DppCurve::BRAINPOOLP384R1:
275 		return "brainpoolP384r1";
276 	case DppCurve::BRAINPOOLP512R1:
277 		return "brainpoolP512r1";
278 	}
279 	WPA_ASSERT(false);
280 }
281 
282 }  // namespace
283 
284 namespace android {
285 namespace hardware {
286 namespace wifi {
287 namespace supplicant {
288 namespace V1_4 {
289 namespace implementation {
290 using hidl_return_util::validateAndCall;
291 using V1_0::ISupplicantStaIfaceCallback;
292 using V1_0::SupplicantStatusCode;
293 
StaIface(struct wpa_global * wpa_global,const char ifname[])294 StaIface::StaIface(struct wpa_global *wpa_global, const char ifname[])
295     : wpa_global_(wpa_global), ifname_(ifname), is_valid_(true)
296 {}
297 
invalidate()298 void StaIface::invalidate() { is_valid_ = false; }
isValid()299 bool StaIface::isValid()
300 {
301 	return (is_valid_ && (retrieveIfacePtr() != nullptr));
302 }
303 
getName(getName_cb _hidl_cb)304 Return<void> StaIface::getName(getName_cb _hidl_cb)
305 {
306 	return validateAndCall(
307 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
308 	    &StaIface::getNameInternal, _hidl_cb);
309 }
310 
getType(getType_cb _hidl_cb)311 Return<void> StaIface::getType(getType_cb _hidl_cb)
312 {
313 	return validateAndCall(
314 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
315 	    &StaIface::getTypeInternal, _hidl_cb);
316 }
317 
addNetwork(addNetwork_cb _hidl_cb)318 Return<void> StaIface::addNetwork(addNetwork_cb _hidl_cb)
319 {
320 	return validateAndCall(
321 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
322 	    &StaIface::addNetworkInternal, _hidl_cb);
323 }
324 
removeNetwork(SupplicantNetworkId id,removeNetwork_cb _hidl_cb)325 Return<void> StaIface::removeNetwork(
326     SupplicantNetworkId id, removeNetwork_cb _hidl_cb)
327 {
328 	return validateAndCall(
329 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
330 	    &StaIface::removeNetworkInternal, _hidl_cb, id);
331 }
332 
filsHlpFlushRequest(filsHlpFlushRequest_cb _hidl_cb)333 Return<void> StaIface::filsHlpFlushRequest(filsHlpFlushRequest_cb _hidl_cb)
334 {
335 	return validateAndCall(
336 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
337 	    &StaIface::filsHlpFlushRequestInternal, _hidl_cb);
338 }
339 
filsHlpAddRequest(const hidl_array<uint8_t,6> & dst_mac,const hidl_vec<uint8_t> & pkt,filsHlpAddRequest_cb _hidl_cb)340 Return<void> StaIface::filsHlpAddRequest(
341     const hidl_array<uint8_t, 6> &dst_mac, const hidl_vec<uint8_t> &pkt,
342     filsHlpAddRequest_cb _hidl_cb)
343 {
344 	return validateAndCall(
345 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
346 	    &StaIface::filsHlpAddRequestInternal, _hidl_cb, dst_mac, pkt);
347 }
348 
getNetwork(SupplicantNetworkId id,getNetwork_cb _hidl_cb)349 Return<void> StaIface::getNetwork(
350     SupplicantNetworkId id, getNetwork_cb _hidl_cb)
351 {
352 	return validateAndCall(
353 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
354 	    &StaIface::getNetworkInternal, _hidl_cb, id);
355 }
356 
listNetworks(listNetworks_cb _hidl_cb)357 Return<void> StaIface::listNetworks(listNetworks_cb _hidl_cb)
358 {
359 	return validateAndCall(
360 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
361 	    &StaIface::listNetworksInternal, _hidl_cb);
362 }
363 
registerCallback(const sp<ISupplicantStaIfaceCallback> & callback,registerCallback_cb _hidl_cb)364 Return<void> StaIface::registerCallback(
365     const sp<ISupplicantStaIfaceCallback> &callback,
366     registerCallback_cb _hidl_cb)
367 {
368 	return validateAndCall(
369 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
370 	    &StaIface::registerCallbackInternal, _hidl_cb, callback);
371 }
372 
registerCallback_1_1(const sp<V1_1::ISupplicantStaIfaceCallback> & callback,registerCallback_cb _hidl_cb)373 Return<void> StaIface::registerCallback_1_1(
374     const sp<V1_1::ISupplicantStaIfaceCallback> &callback,
375     registerCallback_cb _hidl_cb)
376 {
377 	sp<V1_0::ISupplicantStaIfaceCallback> callback_1_0 = callback;
378 	return validateAndCall(
379 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
380 	    &StaIface::registerCallbackInternal, _hidl_cb, callback_1_0);
381 }
382 
registerCallback_1_2(const sp<V1_2::ISupplicantStaIfaceCallback> & callback,registerCallback_cb _hidl_cb)383 Return<void> StaIface::registerCallback_1_2(
384     const sp<V1_2::ISupplicantStaIfaceCallback> &callback,
385     registerCallback_cb _hidl_cb)
386 {
387 	sp<V1_1::ISupplicantStaIfaceCallback> callback_1_1 = callback;
388 	return validateAndCall(
389 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
390 	    &StaIface::registerCallbackInternal, _hidl_cb, callback_1_1);
391 }
392 
registerCallback_1_3(const sp<V1_3::ISupplicantStaIfaceCallback> & callback,registerCallback_cb _hidl_cb)393 Return<void> StaIface::registerCallback_1_3(
394     const sp<V1_3::ISupplicantStaIfaceCallback> &callback,
395     registerCallback_cb _hidl_cb)
396 {
397 	sp<V1_3::ISupplicantStaIfaceCallback> callback_1_3 = callback;
398 	return validateAndCall(
399 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
400 	    &StaIface::registerCallbackInternal, _hidl_cb, callback_1_3);
401 }
402 
registerCallback_1_4(const sp<V1_4::ISupplicantStaIfaceCallback> & callback,registerCallback_1_4_cb _hidl_cb)403 Return<void> StaIface::registerCallback_1_4(
404     const sp<V1_4::ISupplicantStaIfaceCallback> &callback,
405     registerCallback_1_4_cb _hidl_cb)
406 {
407 	sp<V1_4::ISupplicantStaIfaceCallback> callback_1_4 = callback;
408 	return validateAndCall(
409 	    this, V1_4::SupplicantStatusCode::FAILURE_IFACE_INVALID,
410 	    &StaIface::registerCallbackInternal_1_4, _hidl_cb, callback_1_4);
411 }
412 
reassociate(reassociate_cb _hidl_cb)413 Return<void> StaIface::reassociate(reassociate_cb _hidl_cb)
414 {
415 	return validateAndCall(
416 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
417 	    &StaIface::reassociateInternal, _hidl_cb);
418 }
419 
reconnect(reconnect_cb _hidl_cb)420 Return<void> StaIface::reconnect(reconnect_cb _hidl_cb)
421 {
422 	return validateAndCall(
423 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
424 	    &StaIface::reconnectInternal, _hidl_cb);
425 }
426 
disconnect(disconnect_cb _hidl_cb)427 Return<void> StaIface::disconnect(disconnect_cb _hidl_cb)
428 {
429 	return validateAndCall(
430 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
431 	    &StaIface::disconnectInternal, _hidl_cb);
432 }
433 
setPowerSave(bool enable,setPowerSave_cb _hidl_cb)434 Return<void> StaIface::setPowerSave(bool enable, setPowerSave_cb _hidl_cb)
435 {
436 	return validateAndCall(
437 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
438 	    &StaIface::setPowerSaveInternal, _hidl_cb, enable);
439 }
440 
initiateTdlsDiscover(const hidl_array<uint8_t,6> & mac_address,initiateTdlsDiscover_cb _hidl_cb)441 Return<void> StaIface::initiateTdlsDiscover(
442     const hidl_array<uint8_t, 6> &mac_address, initiateTdlsDiscover_cb _hidl_cb)
443 {
444 	return validateAndCall(
445 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
446 	    &StaIface::initiateTdlsDiscoverInternal, _hidl_cb, mac_address);
447 }
448 
initiateTdlsSetup(const hidl_array<uint8_t,6> & mac_address,initiateTdlsSetup_cb _hidl_cb)449 Return<void> StaIface::initiateTdlsSetup(
450     const hidl_array<uint8_t, 6> &mac_address, initiateTdlsSetup_cb _hidl_cb)
451 {
452 	return validateAndCall(
453 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
454 	    &StaIface::initiateTdlsSetupInternal, _hidl_cb, mac_address);
455 }
456 
initiateTdlsTeardown(const hidl_array<uint8_t,6> & mac_address,initiateTdlsTeardown_cb _hidl_cb)457 Return<void> StaIface::initiateTdlsTeardown(
458     const hidl_array<uint8_t, 6> &mac_address, initiateTdlsTeardown_cb _hidl_cb)
459 {
460 	return validateAndCall(
461 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
462 	    &StaIface::initiateTdlsTeardownInternal, _hidl_cb, mac_address);
463 }
initiateAnqpQuery(const hidl_array<uint8_t,6> & mac_address,const hidl_vec<V1_0::ISupplicantStaIface::AnqpInfoId> & info_elements,const hidl_vec<ISupplicantStaIface::Hs20AnqpSubtypes> & sub_types,initiateAnqpQuery_cb _hidl_cb)464 Return<void> StaIface::initiateAnqpQuery(
465     const hidl_array<uint8_t, 6> &mac_address,
466     const hidl_vec<V1_0::ISupplicantStaIface::AnqpInfoId> &info_elements,
467     const hidl_vec<ISupplicantStaIface::Hs20AnqpSubtypes> &sub_types,
468     initiateAnqpQuery_cb _hidl_cb)
469 {
470 	return validateAndCall(
471 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
472 	    &StaIface::initiateAnqpQueryInternal, _hidl_cb, mac_address,
473 	    info_elements, sub_types);
474 }
475 
initiateVenueUrlAnqpQuery(const hidl_array<uint8_t,6> & mac_address,initiateVenueUrlAnqpQuery_cb _hidl_cb)476 Return<void> StaIface::initiateVenueUrlAnqpQuery(
477     const hidl_array<uint8_t, 6> &mac_address,
478 	initiateVenueUrlAnqpQuery_cb _hidl_cb)
479 {
480 	return validateAndCall(
481 	    this, V1_4::SupplicantStatusCode::FAILURE_IFACE_INVALID,
482 	    &StaIface::initiateVenueUrlAnqpQueryInternal, _hidl_cb, mac_address);
483 }
484 
initiateHs20IconQuery(const hidl_array<uint8_t,6> & mac_address,const hidl_string & file_name,initiateHs20IconQuery_cb _hidl_cb)485 Return<void> StaIface::initiateHs20IconQuery(
486     const hidl_array<uint8_t, 6> &mac_address, const hidl_string &file_name,
487     initiateHs20IconQuery_cb _hidl_cb)
488 {
489 	return validateAndCall(
490 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
491 	    &StaIface::initiateHs20IconQueryInternal, _hidl_cb, mac_address,
492 	    file_name);
493 }
494 
getMacAddress(getMacAddress_cb _hidl_cb)495 Return<void> StaIface::getMacAddress(getMacAddress_cb _hidl_cb)
496 {
497 	return validateAndCall(
498 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
499 	    &StaIface::getMacAddressInternal, _hidl_cb);
500 }
501 
startRxFilter(startRxFilter_cb _hidl_cb)502 Return<void> StaIface::startRxFilter(startRxFilter_cb _hidl_cb)
503 {
504 	return validateAndCall(
505 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
506 	    &StaIface::startRxFilterInternal, _hidl_cb);
507 }
508 
stopRxFilter(stopRxFilter_cb _hidl_cb)509 Return<void> StaIface::stopRxFilter(stopRxFilter_cb _hidl_cb)
510 {
511 	return validateAndCall(
512 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
513 	    &StaIface::stopRxFilterInternal, _hidl_cb);
514 }
515 
addRxFilter(ISupplicantStaIface::RxFilterType type,addRxFilter_cb _hidl_cb)516 Return<void> StaIface::addRxFilter(
517     ISupplicantStaIface::RxFilterType type, addRxFilter_cb _hidl_cb)
518 {
519 	return validateAndCall(
520 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
521 	    &StaIface::addRxFilterInternal, _hidl_cb, type);
522 }
523 
removeRxFilter(ISupplicantStaIface::RxFilterType type,removeRxFilter_cb _hidl_cb)524 Return<void> StaIface::removeRxFilter(
525     ISupplicantStaIface::RxFilterType type, removeRxFilter_cb _hidl_cb)
526 {
527 	return validateAndCall(
528 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
529 	    &StaIface::removeRxFilterInternal, _hidl_cb, type);
530 }
531 
setBtCoexistenceMode(ISupplicantStaIface::BtCoexistenceMode mode,setBtCoexistenceMode_cb _hidl_cb)532 Return<void> StaIface::setBtCoexistenceMode(
533     ISupplicantStaIface::BtCoexistenceMode mode,
534     setBtCoexistenceMode_cb _hidl_cb)
535 {
536 	return validateAndCall(
537 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
538 	    &StaIface::setBtCoexistenceModeInternal, _hidl_cb, mode);
539 }
540 
setBtCoexistenceScanModeEnabled(bool enable,setBtCoexistenceScanModeEnabled_cb _hidl_cb)541 Return<void> StaIface::setBtCoexistenceScanModeEnabled(
542     bool enable, setBtCoexistenceScanModeEnabled_cb _hidl_cb)
543 {
544 	return validateAndCall(
545 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
546 	    &StaIface::setBtCoexistenceScanModeEnabledInternal, _hidl_cb,
547 	    enable);
548 }
549 
setSuspendModeEnabled(bool enable,setSuspendModeEnabled_cb _hidl_cb)550 Return<void> StaIface::setSuspendModeEnabled(
551     bool enable, setSuspendModeEnabled_cb _hidl_cb)
552 {
553 	return validateAndCall(
554 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
555 	    &StaIface::setSuspendModeEnabledInternal, _hidl_cb, enable);
556 }
557 
setCountryCode(const hidl_array<int8_t,2> & code,setCountryCode_cb _hidl_cb)558 Return<void> StaIface::setCountryCode(
559     const hidl_array<int8_t, 2> &code, setCountryCode_cb _hidl_cb)
560 {
561 	return validateAndCall(
562 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
563 	    &StaIface::setCountryCodeInternal, _hidl_cb, code);
564 }
565 
startWpsRegistrar(const hidl_array<uint8_t,6> & bssid,const hidl_string & pin,startWpsRegistrar_cb _hidl_cb)566 Return<void> StaIface::startWpsRegistrar(
567     const hidl_array<uint8_t, 6> &bssid, const hidl_string &pin,
568     startWpsRegistrar_cb _hidl_cb)
569 {
570 	return validateAndCall(
571 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
572 	    &StaIface::startWpsRegistrarInternal, _hidl_cb, bssid, pin);
573 }
574 
startWpsPbc(const hidl_array<uint8_t,6> & bssid,startWpsPbc_cb _hidl_cb)575 Return<void> StaIface::startWpsPbc(
576     const hidl_array<uint8_t, 6> &bssid, startWpsPbc_cb _hidl_cb)
577 {
578 	return validateAndCall(
579 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
580 	    &StaIface::startWpsPbcInternal, _hidl_cb, bssid);
581 }
582 
startWpsPinKeypad(const hidl_string & pin,startWpsPinKeypad_cb _hidl_cb)583 Return<void> StaIface::startWpsPinKeypad(
584     const hidl_string &pin, startWpsPinKeypad_cb _hidl_cb)
585 {
586 	return validateAndCall(
587 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
588 	    &StaIface::startWpsPinKeypadInternal, _hidl_cb, pin);
589 }
590 
startWpsPinDisplay(const hidl_array<uint8_t,6> & bssid,startWpsPinDisplay_cb _hidl_cb)591 Return<void> StaIface::startWpsPinDisplay(
592     const hidl_array<uint8_t, 6> &bssid, startWpsPinDisplay_cb _hidl_cb)
593 {
594 	return validateAndCall(
595 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
596 	    &StaIface::startWpsPinDisplayInternal, _hidl_cb, bssid);
597 }
598 
cancelWps(cancelWps_cb _hidl_cb)599 Return<void> StaIface::cancelWps(cancelWps_cb _hidl_cb)
600 {
601 	return validateAndCall(
602 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
603 	    &StaIface::cancelWpsInternal, _hidl_cb);
604 }
605 
setWpsDeviceName(const hidl_string & name,setWpsDeviceName_cb _hidl_cb)606 Return<void> StaIface::setWpsDeviceName(
607     const hidl_string &name, setWpsDeviceName_cb _hidl_cb)
608 {
609 	return validateAndCall(
610 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
611 	    &StaIface::setWpsDeviceNameInternal, _hidl_cb, name);
612 }
613 
setWpsDeviceType(const hidl_array<uint8_t,8> & type,setWpsDeviceType_cb _hidl_cb)614 Return<void> StaIface::setWpsDeviceType(
615     const hidl_array<uint8_t, 8> &type, setWpsDeviceType_cb _hidl_cb)
616 {
617 	return validateAndCall(
618 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
619 	    &StaIface::setWpsDeviceTypeInternal, _hidl_cb, type);
620 }
621 
setWpsManufacturer(const hidl_string & manufacturer,setWpsManufacturer_cb _hidl_cb)622 Return<void> StaIface::setWpsManufacturer(
623     const hidl_string &manufacturer, setWpsManufacturer_cb _hidl_cb)
624 {
625 	return validateAndCall(
626 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
627 	    &StaIface::setWpsManufacturerInternal, _hidl_cb, manufacturer);
628 }
629 
setWpsModelName(const hidl_string & model_name,setWpsModelName_cb _hidl_cb)630 Return<void> StaIface::setWpsModelName(
631     const hidl_string &model_name, setWpsModelName_cb _hidl_cb)
632 {
633 	return validateAndCall(
634 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
635 	    &StaIface::setWpsModelNameInternal, _hidl_cb, model_name);
636 }
637 
setWpsModelNumber(const hidl_string & model_number,setWpsModelNumber_cb _hidl_cb)638 Return<void> StaIface::setWpsModelNumber(
639     const hidl_string &model_number, setWpsModelNumber_cb _hidl_cb)
640 {
641 	return validateAndCall(
642 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
643 	    &StaIface::setWpsModelNumberInternal, _hidl_cb, model_number);
644 }
645 
setWpsSerialNumber(const hidl_string & serial_number,setWpsSerialNumber_cb _hidl_cb)646 Return<void> StaIface::setWpsSerialNumber(
647     const hidl_string &serial_number, setWpsSerialNumber_cb _hidl_cb)
648 {
649 	return validateAndCall(
650 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
651 	    &StaIface::setWpsSerialNumberInternal, _hidl_cb, serial_number);
652 }
653 
setWpsConfigMethods(uint16_t config_methods,setWpsConfigMethods_cb _hidl_cb)654 Return<void> StaIface::setWpsConfigMethods(
655     uint16_t config_methods, setWpsConfigMethods_cb _hidl_cb)
656 {
657 	return validateAndCall(
658 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
659 	    &StaIface::setWpsConfigMethodsInternal, _hidl_cb, config_methods);
660 }
661 
setExternalSim(bool useExternalSim,setExternalSim_cb _hidl_cb)662 Return<void> StaIface::setExternalSim(
663     bool useExternalSim, setExternalSim_cb _hidl_cb)
664 {
665 	return validateAndCall(
666 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
667 	    &StaIface::setExternalSimInternal, _hidl_cb, useExternalSim);
668 }
669 
addExtRadioWork(const hidl_string & name,uint32_t freq_in_mhz,uint32_t timeout_in_sec,addExtRadioWork_cb _hidl_cb)670 Return<void> StaIface::addExtRadioWork(
671     const hidl_string &name, uint32_t freq_in_mhz, uint32_t timeout_in_sec,
672     addExtRadioWork_cb _hidl_cb)
673 {
674 	return validateAndCall(
675 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
676 	    &StaIface::addExtRadioWorkInternal, _hidl_cb, name, freq_in_mhz,
677 	    timeout_in_sec);
678 }
679 
removeExtRadioWork(uint32_t id,removeExtRadioWork_cb _hidl_cb)680 Return<void> StaIface::removeExtRadioWork(
681     uint32_t id, removeExtRadioWork_cb _hidl_cb)
682 {
683 	return validateAndCall(
684 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
685 	    &StaIface::removeExtRadioWorkInternal, _hidl_cb, id);
686 }
687 
enableAutoReconnect(bool enable,enableAutoReconnect_cb _hidl_cb)688 Return<void> StaIface::enableAutoReconnect(
689     bool enable, enableAutoReconnect_cb _hidl_cb)
690 {
691 	return validateAndCall(
692 	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
693 	    &StaIface::enableAutoReconnectInternal, _hidl_cb, enable);
694 }
695 
getKeyMgmtCapabilities(getKeyMgmtCapabilities_cb _hidl_cb)696 Return<void> StaIface::getKeyMgmtCapabilities(
697     getKeyMgmtCapabilities_cb _hidl_cb)
698 {
699 	return validateAndCall(
700 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
701 	    &StaIface::getKeyMgmtCapabilitiesInternal, _hidl_cb);
702 }
703 
addDppPeerUri(const hidl_string & uri,addDppPeerUri_cb _hidl_cb)704 Return<void> StaIface::addDppPeerUri(const hidl_string& uri,
705 		addDppPeerUri_cb _hidl_cb)
706 {
707 	return validateAndCall(
708 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
709 	    &StaIface::addDppPeerUriInternal, _hidl_cb, uri);
710 }
711 
removeDppUri(uint32_t bootstrap_id,removeDppUri_cb _hidl_cb)712 Return<void> StaIface::removeDppUri(uint32_t bootstrap_id,
713 		removeDppUri_cb _hidl_cb)
714 {
715 	return validateAndCall(
716 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
717 	    &StaIface::removeDppUriInternal, _hidl_cb, bootstrap_id);
718 }
719 
startDppConfiguratorInitiator(uint32_t peer_bootstrap_id,uint32_t own_bootstrap_id,const hidl_string & ssid,const hidl_string & password,const hidl_string & psk,DppNetRole net_role,DppAkm security_akm,startDppConfiguratorInitiator_cb _hidl_cb)720 Return<void> StaIface::startDppConfiguratorInitiator(uint32_t peer_bootstrap_id,
721 		uint32_t own_bootstrap_id, const hidl_string& ssid,
722 		const hidl_string& password, const hidl_string& psk,
723 		DppNetRole net_role, DppAkm security_akm,
724 		startDppConfiguratorInitiator_cb _hidl_cb)
725 {
726 	return validateAndCall(
727 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
728 	    &StaIface::startDppConfiguratorInitiatorInternal, _hidl_cb, peer_bootstrap_id,
729 		own_bootstrap_id, ssid, password, psk, net_role, security_akm);
730 }
731 
startDppEnrolleeInitiator(uint32_t peer_bootstrap_id,uint32_t own_bootstrap_id,startDppConfiguratorInitiator_cb _hidl_cb)732 Return<void> StaIface::startDppEnrolleeInitiator(uint32_t peer_bootstrap_id,
733 		uint32_t own_bootstrap_id, startDppConfiguratorInitiator_cb _hidl_cb)
734 {
735 	return validateAndCall(
736 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
737 	    &StaIface::startDppEnrolleeInitiatorInternal, _hidl_cb, peer_bootstrap_id,
738 		own_bootstrap_id);
739 }
740 
stopDppInitiator(stopDppInitiator_cb _hidl_cb)741 Return<void> StaIface::stopDppInitiator(stopDppInitiator_cb _hidl_cb)
742 {
743 	return validateAndCall(
744 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
745 	    &StaIface::stopDppInitiatorInternal, _hidl_cb);
746 }
747 
generateDppBootstrapInfoForResponder(const hidl_array<uint8_t,6> & mac_address,const hidl_string & device_info,DppCurve curve,generateDppBootstrapInfoForResponder_cb _hidl_cb)748 Return<void> StaIface::generateDppBootstrapInfoForResponder(
749 		const hidl_array<uint8_t, 6> &mac_address, const hidl_string& device_info,
750 		DppCurve curve, generateDppBootstrapInfoForResponder_cb _hidl_cb)
751 {
752 	return validateAndCall(
753 	    this, V1_4::SupplicantStatusCode::FAILURE_IFACE_INVALID,
754 	    &StaIface::generateDppBootstrapInfoForResponderInternal, _hidl_cb, mac_address,
755 	    device_info, curve);
756 }
757 
startDppEnrolleeResponder(uint32_t listen_channel,startDppEnrolleeResponder_cb _hidl_cb)758 Return<void> StaIface::startDppEnrolleeResponder(
759 		uint32_t listen_channel, startDppEnrolleeResponder_cb _hidl_cb)
760 {
761 	return validateAndCall(
762 	    this, V1_4::SupplicantStatusCode::FAILURE_IFACE_INVALID,
763 	    &StaIface::startDppEnrolleeResponderInternal, _hidl_cb, listen_channel);
764 }
765 
stopDppResponder(uint32_t own_bootstrap_id,stopDppResponder_cb _hidl_cb)766 Return<void> StaIface::stopDppResponder(uint32_t own_bootstrap_id, stopDppResponder_cb _hidl_cb)
767 {
768 	return validateAndCall(
769 	    this, V1_4::SupplicantStatusCode::FAILURE_IFACE_INVALID,
770 	    &StaIface::stopDppResponderInternal, _hidl_cb, own_bootstrap_id);
771 }
772 
getWpaDriverCapabilities(getWpaDriverCapabilities_cb _hidl_cb)773 Return<void> StaIface::getWpaDriverCapabilities(
774 		getWpaDriverCapabilities_cb _hidl_cb)
775 {
776 	return validateAndCall(
777 	    this, SupplicantStatusCode::FAILURE_UNKNOWN,
778 	    &StaIface::getWpaDriverCapabilitiesInternal, _hidl_cb);
779 }
780 
getWpaDriverCapabilities_1_4(getWpaDriverCapabilities_1_4_cb _hidl_cb)781 Return<void> StaIface::getWpaDriverCapabilities_1_4(
782 		getWpaDriverCapabilities_1_4_cb _hidl_cb)
783 {
784 	return validateAndCall(
785 	    this, V1_4::SupplicantStatusCode::FAILURE_UNKNOWN,
786 	    &StaIface::getWpaDriverCapabilitiesInternal_1_4, _hidl_cb);
787 }
788 
setMboCellularDataStatus(bool available,setMboCellularDataStatus_cb _hidl_cb)789 Return<void> StaIface::setMboCellularDataStatus(bool available,
790 		setMboCellularDataStatus_cb _hidl_cb)
791 {
792 	return validateAndCall(
793 	    this, SupplicantStatusCode::FAILURE_UNKNOWN,
794 	    &StaIface::setMboCellularDataStatusInternal, _hidl_cb, available);
795 }
796 
getKeyMgmtCapabilities_1_3(getKeyMgmtCapabilities_1_3_cb _hidl_cb)797 Return<void> StaIface::getKeyMgmtCapabilities_1_3(
798     getKeyMgmtCapabilities_1_3_cb _hidl_cb)
799 {
800 	return validateAndCall(
801 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
802 	    &StaIface::getKeyMgmtCapabilitiesInternal_1_3, _hidl_cb);
803 }
804 
getNameInternal()805 std::pair<SupplicantStatus, std::string> StaIface::getNameInternal()
806 {
807 	return {{SupplicantStatusCode::SUCCESS, ""}, ifname_};
808 }
809 
getTypeInternal()810 std::pair<SupplicantStatus, IfaceType> StaIface::getTypeInternal()
811 {
812 	return {{SupplicantStatusCode::SUCCESS, ""}, IfaceType::STA};
813 }
814 
filsHlpFlushRequestInternal()815 SupplicantStatus StaIface::filsHlpFlushRequestInternal()
816 {
817 #ifdef CONFIG_FILS
818 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
819 
820 	wpas_flush_fils_hlp_req(wpa_s);
821 	return {SupplicantStatusCode::SUCCESS, ""};
822 #else /* CONFIG_FILS */
823 	return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
824 #endif /* CONFIG_FILS */
825 }
826 
filsHlpAddRequestInternal(const std::array<uint8_t,6> & dst_mac,const std::vector<uint8_t> & pkt)827 SupplicantStatus StaIface::filsHlpAddRequestInternal(
828     const std::array<uint8_t, 6> &dst_mac, const std::vector<uint8_t> &pkt)
829 {
830 #ifdef CONFIG_FILS
831 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
832 	struct fils_hlp_req *req;
833 
834 	if (!pkt.size())
835 		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
836 
837 
838 	req = (struct fils_hlp_req *)os_zalloc(sizeof(*req));
839 	if (!req)
840 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
841 
842 	os_memcpy(req->dst, dst_mac.data(), ETH_ALEN);
843 
844 	req->pkt = wpabuf_alloc_copy(pkt.data(), pkt.size());
845 	if (!req->pkt) {
846 		os_free(req);
847 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
848 	}
849 
850 	dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list);
851 	return {SupplicantStatusCode::SUCCESS, ""};
852 #else /* CONFIG_FILS */
853 	return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
854 #endif /* CONFIG_FILS */
855 }
856 
857 std::pair<SupplicantStatus, sp<ISupplicantNetwork>>
addNetworkInternal()858 StaIface::addNetworkInternal()
859 {
860 	android::sp<V1_3::ISupplicantStaNetwork> network;
861 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
862 	struct wpa_ssid *ssid = wpa_supplicant_add_network(wpa_s);
863 	if (!ssid) {
864 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, network};
865 	}
866 	HidlManager *hidl_manager = HidlManager::getInstance();
867 	if (!hidl_manager ||
868 	    hidl_manager->getStaNetworkHidlObjectByIfnameAndNetworkId(
869 		wpa_s->ifname, ssid->id, &network)) {
870 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, network};
871 	}
872 	return {{SupplicantStatusCode::SUCCESS, ""}, network};
873 }
874 
getConnectionCapabilities(getConnectionCapabilities_cb _hidl_cb)875 Return<void> StaIface::getConnectionCapabilities(
876     getConnectionCapabilities_cb _hidl_cb)
877 {
878 	return validateAndCall(
879 	    this, SupplicantStatusCode::FAILURE_UNKNOWN,
880 	    &StaIface::getConnectionCapabilitiesInternal, _hidl_cb);
881 }
882 
getConnectionCapabilities_1_4(getConnectionCapabilities_1_4_cb _hidl_cb)883 Return<void> StaIface::getConnectionCapabilities_1_4(
884     getConnectionCapabilities_1_4_cb _hidl_cb)
885 {
886 	return validateAndCall(
887 	    this, V1_4::SupplicantStatusCode::FAILURE_UNKNOWN,
888 	    &StaIface::getConnectionCapabilitiesInternal_1_4, _hidl_cb);
889 }
890 
removeNetworkInternal(SupplicantNetworkId id)891 SupplicantStatus StaIface::removeNetworkInternal(SupplicantNetworkId id)
892 {
893 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
894 	int result = wpa_supplicant_remove_network(wpa_s, id);
895 	if (result == -1) {
896 		return {SupplicantStatusCode::FAILURE_NETWORK_UNKNOWN, ""};
897 	}
898 	if (result != 0) {
899 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
900 	}
901 	return {SupplicantStatusCode::SUCCESS, ""};
902 }
903 
904 std::pair<SupplicantStatus, sp<ISupplicantNetwork>>
getNetworkInternal(SupplicantNetworkId id)905 StaIface::getNetworkInternal(SupplicantNetworkId id)
906 {
907 	android::sp<V1_3::ISupplicantStaNetwork> network;
908 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
909 	struct wpa_ssid *ssid = wpa_config_get_network(wpa_s->conf, id);
910 	if (!ssid) {
911 		return {{SupplicantStatusCode::FAILURE_NETWORK_UNKNOWN, ""},
912 			network};
913 	}
914 	HidlManager *hidl_manager = HidlManager::getInstance();
915 	if (!hidl_manager ||
916 	    hidl_manager->getStaNetworkHidlObjectByIfnameAndNetworkId(
917 		wpa_s->ifname, ssid->id, &network)) {
918 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, network};
919 	}
920 	return {{SupplicantStatusCode::SUCCESS, ""}, network};
921 }
922 
923 std::pair<SupplicantStatus, std::vector<SupplicantNetworkId>>
listNetworksInternal()924 StaIface::listNetworksInternal()
925 {
926 	std::vector<SupplicantNetworkId> network_ids;
927 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
928 	for (struct wpa_ssid *wpa_ssid = wpa_s->conf->ssid; wpa_ssid;
929 	     wpa_ssid = wpa_ssid->next) {
930 		network_ids.emplace_back(wpa_ssid->id);
931 	}
932 	return {{SupplicantStatusCode::SUCCESS, ""}, std::move(network_ids)};
933 }
934 
registerCallbackInternal(const sp<ISupplicantStaIfaceCallback> & callback)935 SupplicantStatus StaIface::registerCallbackInternal(
936     const sp<ISupplicantStaIfaceCallback> &callback)
937 {
938 	return {SupplicantStatusCode::FAILURE_UNKNOWN, "deprecated"};
939 }
940 
registerCallbackInternal_1_4(const sp<V1_4::ISupplicantStaIfaceCallback> & callback)941 V1_4::SupplicantStatus StaIface::registerCallbackInternal_1_4(
942     const sp<V1_4::ISupplicantStaIfaceCallback> &callback)
943 {
944 	HidlManager *hidl_manager = HidlManager::getInstance();
945 	if (!hidl_manager ||
946 	    hidl_manager->addStaIfaceCallbackHidlObject(ifname_, callback)) {
947 		return {V1_4::SupplicantStatusCode::FAILURE_UNKNOWN, ""};
948 	}
949 	return {V1_4::SupplicantStatusCode::SUCCESS, ""};
950 }
951 
reassociateInternal()952 SupplicantStatus StaIface::reassociateInternal()
953 {
954 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
955 	if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
956 		return {SupplicantStatusCode::FAILURE_IFACE_DISABLED, ""};
957 	}
958 	wpas_request_connection(wpa_s);
959 	return {SupplicantStatusCode::SUCCESS, ""};
960 }
961 
reconnectInternal()962 SupplicantStatus StaIface::reconnectInternal()
963 {
964 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
965 	if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
966 		return {SupplicantStatusCode::FAILURE_IFACE_DISABLED, ""};
967 	}
968 	if (!wpa_s->disconnected) {
969 		return {SupplicantStatusCode::FAILURE_IFACE_NOT_DISCONNECTED,
970 			""};
971 	}
972 	wpas_request_connection(wpa_s);
973 	return {SupplicantStatusCode::SUCCESS, ""};
974 }
975 
disconnectInternal()976 SupplicantStatus StaIface::disconnectInternal()
977 {
978 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
979 	if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
980 		return {SupplicantStatusCode::FAILURE_IFACE_DISABLED, ""};
981 	}
982 	wpas_request_disconnection(wpa_s);
983 	return {SupplicantStatusCode::SUCCESS, ""};
984 }
985 
setPowerSaveInternal(bool enable)986 SupplicantStatus StaIface::setPowerSaveInternal(bool enable)
987 {
988 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
989 	if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
990 		return {SupplicantStatusCode::FAILURE_IFACE_DISABLED, ""};
991 	}
992 	if (wpa_drv_set_p2p_powersave(wpa_s, enable, -1, -1)) {
993 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
994 	}
995 	return {SupplicantStatusCode::SUCCESS, ""};
996 }
997 
initiateTdlsDiscoverInternal(const std::array<uint8_t,6> & mac_address)998 SupplicantStatus StaIface::initiateTdlsDiscoverInternal(
999     const std::array<uint8_t, 6> &mac_address)
1000 {
1001 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1002 	int ret;
1003 	const u8 *peer = mac_address.data();
1004 	if (wpa_tdls_is_external_setup(wpa_s->wpa)) {
1005 		ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
1006 	} else {
1007 		ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
1008 	}
1009 	if (ret) {
1010 		wpa_printf(MSG_INFO, "StaIface: TDLS discover failed: %d", ret);
1011 	}
1012 	return {SupplicantStatusCode::SUCCESS, ""};
1013 }
1014 
initiateTdlsSetupInternal(const std::array<uint8_t,6> & mac_address)1015 SupplicantStatus StaIface::initiateTdlsSetupInternal(
1016     const std::array<uint8_t, 6> &mac_address)
1017 {
1018 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1019 	int ret;
1020 	const u8 *peer = mac_address.data();
1021 	if (wpa_tdls_is_external_setup(wpa_s->wpa) &&
1022 	    !(wpa_s->conf->tdls_external_control)) {
1023 		wpa_tdls_remove(wpa_s->wpa, peer);
1024 		ret = wpa_tdls_start(wpa_s->wpa, peer);
1025 	} else {
1026 		ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
1027 	}
1028 	if (ret) {
1029 		wpa_printf(MSG_INFO, "StaIface: TDLS setup failed: %d", ret);
1030 	}
1031 	return {SupplicantStatusCode::SUCCESS, ""};
1032 }
1033 
initiateTdlsTeardownInternal(const std::array<uint8_t,6> & mac_address)1034 SupplicantStatus StaIface::initiateTdlsTeardownInternal(
1035     const std::array<uint8_t, 6> &mac_address)
1036 {
1037 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1038 	int ret;
1039 	const u8 *peer = mac_address.data();
1040 	if (wpa_tdls_is_external_setup(wpa_s->wpa) &&
1041 	    !(wpa_s->conf->tdls_external_control)) {
1042 		ret = wpa_tdls_teardown_link(
1043 		    wpa_s->wpa, peer, WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
1044 	} else {
1045 		ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
1046 	}
1047 	if (ret) {
1048 		wpa_printf(MSG_INFO, "StaIface: TDLS teardown failed: %d", ret);
1049 	}
1050 	return {SupplicantStatusCode::SUCCESS, ""};
1051 }
1052 
initiateAnqpQueryInternal(const std::array<uint8_t,6> & mac_address,const std::vector<ISupplicantStaIface::AnqpInfoId> & info_elements,const std::vector<ISupplicantStaIface::Hs20AnqpSubtypes> & sub_types)1053 SupplicantStatus StaIface::initiateAnqpQueryInternal(
1054     const std::array<uint8_t, 6> &mac_address,
1055     const std::vector<ISupplicantStaIface::AnqpInfoId> &info_elements,
1056     const std::vector<ISupplicantStaIface::Hs20AnqpSubtypes> &sub_types)
1057 {
1058 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1059 	if (info_elements.size() > kMaxAnqpElems) {
1060 		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
1061 	}
1062 	uint16_t info_elems_buf[kMaxAnqpElems];
1063 	uint32_t num_info_elems = 0;
1064 	for (const auto &info_element : info_elements) {
1065 		info_elems_buf[num_info_elems++] =
1066 		    static_cast<std::underlying_type<
1067 			ISupplicantStaIface::AnqpInfoId>::type>(info_element);
1068 	}
1069 	uint32_t sub_types_bitmask = 0;
1070 	for (const auto &type : sub_types) {
1071 		sub_types_bitmask |= BIT(
1072 		    static_cast<std::underlying_type<
1073 			ISupplicantStaIface::Hs20AnqpSubtypes>::type>(type));
1074 	}
1075 
1076 	if (anqp_send_req(
1077 		wpa_s, mac_address.data(), 0, info_elems_buf, num_info_elems,
1078 		sub_types_bitmask, 0)) {
1079 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1080 	}
1081 	return {SupplicantStatusCode::SUCCESS, ""};
1082 }
1083 
initiateVenueUrlAnqpQueryInternal(const std::array<uint8_t,6> & mac_address)1084 V1_4::SupplicantStatus StaIface::initiateVenueUrlAnqpQueryInternal(
1085     const std::array<uint8_t, 6> &mac_address)
1086 {
1087 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1088 	uint16_t info_elems_buf[1] = {ANQP_VENUE_URL};
1089 
1090 	if (anqp_send_req(
1091 		wpa_s, mac_address.data(), 0, info_elems_buf, 1, 0, 0)) {
1092 		return {V1_4::SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1093 	}
1094 	return {V1_4::SupplicantStatusCode::SUCCESS, ""};
1095 }
1096 
initiateHs20IconQueryInternal(const std::array<uint8_t,6> & mac_address,const std::string & file_name)1097 SupplicantStatus StaIface::initiateHs20IconQueryInternal(
1098     const std::array<uint8_t, 6> &mac_address, const std::string &file_name)
1099 {
1100 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1101 	wpa_s->fetch_osu_icon_in_progress = 0;
1102 	if (hs20_anqp_send_req(
1103 		wpa_s, mac_address.data(), BIT(HS20_STYPE_ICON_REQUEST),
1104 		reinterpret_cast<const uint8_t *>(file_name.c_str()),
1105 		file_name.size(), true)) {
1106 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1107 	}
1108 	return {SupplicantStatusCode::SUCCESS, ""};
1109 }
1110 
1111 std::pair<SupplicantStatus, std::array<uint8_t, 6>>
getMacAddressInternal()1112 StaIface::getMacAddressInternal()
1113 {
1114 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1115 	std::vector<char> cmd(
1116 	    kGetMacAddress, kGetMacAddress + sizeof(kGetMacAddress));
1117 	char driver_cmd_reply_buf[4096] = {};
1118 	int ret = wpa_drv_driver_cmd(
1119 	    wpa_s, cmd.data(), driver_cmd_reply_buf,
1120 	    sizeof(driver_cmd_reply_buf));
1121 	// Reply is of the format: "Macaddr = XX:XX:XX:XX:XX:XX"
1122 	std::string reply_str = driver_cmd_reply_buf;
1123 	if (ret < 0 || reply_str.empty() ||
1124 	    reply_str.find("=") == std::string::npos) {
1125 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1126 	}
1127 	// Remove all whitespace first and then split using the delimiter "=".
1128 	reply_str.erase(
1129 	    remove_if(reply_str.begin(), reply_str.end(), isspace),
1130 	    reply_str.end());
1131 	std::string mac_addr_str =
1132 	    reply_str.substr(reply_str.find("=") + 1, reply_str.size());
1133 	std::array<uint8_t, 6> mac_addr;
1134 	if (hwaddr_aton(mac_addr_str.c_str(), mac_addr.data())) {
1135 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1136 	}
1137 	return {{SupplicantStatusCode::SUCCESS, ""}, mac_addr};
1138 }
1139 
startRxFilterInternal()1140 SupplicantStatus StaIface::startRxFilterInternal()
1141 {
1142 	return doZeroArgDriverCommand(retrieveIfacePtr(), kStartRxFilter);
1143 }
1144 
stopRxFilterInternal()1145 SupplicantStatus StaIface::stopRxFilterInternal()
1146 {
1147 	return doZeroArgDriverCommand(retrieveIfacePtr(), kStopRxFilter);
1148 }
1149 
addRxFilterInternal(ISupplicantStaIface::RxFilterType type)1150 SupplicantStatus StaIface::addRxFilterInternal(
1151     ISupplicantStaIface::RxFilterType type)
1152 {
1153 	return doOneArgDriverCommand(
1154 	    retrieveIfacePtr(), kAddRxFilter,
1155 	    convertHidlRxFilterTypeToInternal(type));
1156 }
1157 
removeRxFilterInternal(ISupplicantStaIface::RxFilterType type)1158 SupplicantStatus StaIface::removeRxFilterInternal(
1159     ISupplicantStaIface::RxFilterType type)
1160 {
1161 	return doOneArgDriverCommand(
1162 	    retrieveIfacePtr(), kRemoveRxFilter,
1163 	    convertHidlRxFilterTypeToInternal(type));
1164 }
1165 
setBtCoexistenceModeInternal(ISupplicantStaIface::BtCoexistenceMode mode)1166 SupplicantStatus StaIface::setBtCoexistenceModeInternal(
1167     ISupplicantStaIface::BtCoexistenceMode mode)
1168 {
1169 	return doOneArgDriverCommand(
1170 	    retrieveIfacePtr(), kSetBtCoexistenceMode,
1171 	    convertHidlBtCoexModeToInternal(mode));
1172 }
1173 
setBtCoexistenceScanModeEnabledInternal(bool enable)1174 SupplicantStatus StaIface::setBtCoexistenceScanModeEnabledInternal(bool enable)
1175 {
1176 	const char *cmd;
1177 	if (enable) {
1178 		cmd = kSetBtCoexistenceScanStart;
1179 	} else {
1180 		cmd = kSetBtCoexistenceScanStop;
1181 	}
1182 	return doZeroArgDriverCommand(retrieveIfacePtr(), cmd);
1183 }
1184 
setSuspendModeEnabledInternal(bool enable)1185 SupplicantStatus StaIface::setSuspendModeEnabledInternal(bool enable)
1186 {
1187 	const char *cmd;
1188 	if (enable) {
1189 		cmd = kSetSupendModeEnabled;
1190 	} else {
1191 		cmd = kSetSupendModeDisabled;
1192 	}
1193 	return doZeroArgDriverCommand(retrieveIfacePtr(), cmd);
1194 }
1195 
setCountryCodeInternal(const std::array<int8_t,2> & code)1196 SupplicantStatus StaIface::setCountryCodeInternal(
1197     const std::array<int8_t, 2> &code)
1198 {
1199 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1200 	SupplicantStatus status = doOneArgDriverCommand(
1201 	    wpa_s, kSetCountryCode,
1202 	    std::string(std::begin(code), std::end(code)));
1203 	if (status.code != SupplicantStatusCode::SUCCESS) {
1204 		return status;
1205 	}
1206 	struct p2p_data *p2p = wpa_s->global->p2p;
1207 	if (p2p) {
1208 		char country[3];
1209 		country[0] = code[0];
1210 		country[1] = code[1];
1211 		country[2] = 0x04;
1212 		p2p_set_country(p2p, country);
1213 	}
1214 	return {SupplicantStatusCode::SUCCESS, ""};
1215 }
1216 
startWpsRegistrarInternal(const std::array<uint8_t,6> & bssid,const std::string & pin)1217 SupplicantStatus StaIface::startWpsRegistrarInternal(
1218     const std::array<uint8_t, 6> &bssid, const std::string &pin)
1219 {
1220 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1221 	if (wpas_wps_start_reg(wpa_s, bssid.data(), pin.c_str(), nullptr)) {
1222 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1223 	}
1224 	return {SupplicantStatusCode::SUCCESS, ""};
1225 }
1226 
startWpsPbcInternal(const std::array<uint8_t,6> & bssid)1227 SupplicantStatus StaIface::startWpsPbcInternal(
1228     const std::array<uint8_t, 6> &bssid)
1229 {
1230 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1231 	const uint8_t *bssid_addr =
1232 	    is_zero_ether_addr(bssid.data()) ? nullptr : bssid.data();
1233 	if (wpas_wps_start_pbc(wpa_s, bssid_addr, 0, 0)) {
1234 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1235 	}
1236 	return {SupplicantStatusCode::SUCCESS, ""};
1237 }
1238 
startWpsPinKeypadInternal(const std::string & pin)1239 SupplicantStatus StaIface::startWpsPinKeypadInternal(const std::string &pin)
1240 {
1241 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1242 	if (wpas_wps_start_pin(
1243 		wpa_s, nullptr, pin.c_str(), 0, DEV_PW_DEFAULT)) {
1244 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1245 	}
1246 	return {SupplicantStatusCode::SUCCESS, ""};
1247 }
1248 
startWpsPinDisplayInternal(const std::array<uint8_t,6> & bssid)1249 std::pair<SupplicantStatus, std::string> StaIface::startWpsPinDisplayInternal(
1250     const std::array<uint8_t, 6> &bssid)
1251 {
1252 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1253 	const uint8_t *bssid_addr =
1254 	    is_zero_ether_addr(bssid.data()) ? nullptr : bssid.data();
1255 	int pin =
1256 	    wpas_wps_start_pin(wpa_s, bssid_addr, nullptr, 0, DEV_PW_DEFAULT);
1257 	if (pin < 0) {
1258 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, ""};
1259 	}
1260 	return {{SupplicantStatusCode::SUCCESS, ""},
1261 		misc_utils::convertWpsPinToString(pin)};
1262 }
1263 
cancelWpsInternal()1264 SupplicantStatus StaIface::cancelWpsInternal()
1265 {
1266 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1267 	if (wpas_wps_cancel(wpa_s)) {
1268 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1269 	}
1270 	return {SupplicantStatusCode::SUCCESS, ""};
1271 }
1272 
setWpsDeviceNameInternal(const std::string & name)1273 SupplicantStatus StaIface::setWpsDeviceNameInternal(const std::string &name)
1274 {
1275 	return iface_config_utils::setWpsDeviceName(retrieveIfacePtr(), name);
1276 }
1277 
setWpsDeviceTypeInternal(const std::array<uint8_t,8> & type)1278 SupplicantStatus StaIface::setWpsDeviceTypeInternal(
1279     const std::array<uint8_t, 8> &type)
1280 {
1281 	return iface_config_utils::setWpsDeviceType(retrieveIfacePtr(), type);
1282 }
1283 
setWpsManufacturerInternal(const std::string & manufacturer)1284 SupplicantStatus StaIface::setWpsManufacturerInternal(
1285     const std::string &manufacturer)
1286 {
1287 	return iface_config_utils::setWpsManufacturer(
1288 	    retrieveIfacePtr(), manufacturer);
1289 }
1290 
setWpsModelNameInternal(const std::string & model_name)1291 SupplicantStatus StaIface::setWpsModelNameInternal(
1292     const std::string &model_name)
1293 {
1294 	return iface_config_utils::setWpsModelName(
1295 	    retrieveIfacePtr(), model_name);
1296 }
1297 
setWpsModelNumberInternal(const std::string & model_number)1298 SupplicantStatus StaIface::setWpsModelNumberInternal(
1299     const std::string &model_number)
1300 {
1301 	return iface_config_utils::setWpsModelNumber(
1302 	    retrieveIfacePtr(), model_number);
1303 }
1304 
setWpsSerialNumberInternal(const std::string & serial_number)1305 SupplicantStatus StaIface::setWpsSerialNumberInternal(
1306     const std::string &serial_number)
1307 {
1308 	return iface_config_utils::setWpsSerialNumber(
1309 	    retrieveIfacePtr(), serial_number);
1310 }
1311 
setWpsConfigMethodsInternal(uint16_t config_methods)1312 SupplicantStatus StaIface::setWpsConfigMethodsInternal(uint16_t config_methods)
1313 {
1314 	return iface_config_utils::setWpsConfigMethods(
1315 	    retrieveIfacePtr(), config_methods);
1316 }
1317 
setExternalSimInternal(bool useExternalSim)1318 SupplicantStatus StaIface::setExternalSimInternal(bool useExternalSim)
1319 {
1320 	return iface_config_utils::setExternalSim(
1321 	    retrieveIfacePtr(), useExternalSim);
1322 }
1323 
addExtRadioWorkInternal(const std::string & name,uint32_t freq_in_mhz,uint32_t timeout_in_sec)1324 std::pair<SupplicantStatus, uint32_t> StaIface::addExtRadioWorkInternal(
1325     const std::string &name, uint32_t freq_in_mhz, uint32_t timeout_in_sec)
1326 {
1327 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1328 	auto *ework = static_cast<struct wpa_external_work *>(
1329 	    os_zalloc(sizeof(struct wpa_external_work)));
1330 	if (!ework) {
1331 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""},
1332 			UINT32_MAX};
1333 	}
1334 
1335 	std::string radio_work_name = kExtRadioWorkNamePrefix + name;
1336 	os_strlcpy(ework->type, radio_work_name.c_str(), sizeof(ework->type));
1337 	ework->timeout = timeout_in_sec;
1338 	wpa_s->ext_work_id++;
1339 	if (wpa_s->ext_work_id == 0) {
1340 		wpa_s->ext_work_id++;
1341 	}
1342 	ework->id = wpa_s->ext_work_id;
1343 
1344 	if (radio_add_work(
1345 		wpa_s, freq_in_mhz, ework->type, 0, extRadioWorkStartCb,
1346 		ework)) {
1347 		os_free(ework);
1348 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""},
1349 			UINT32_MAX};
1350 	}
1351 	return {SupplicantStatus{SupplicantStatusCode::SUCCESS, ""}, ework->id};
1352 }
1353 
removeExtRadioWorkInternal(uint32_t id)1354 SupplicantStatus StaIface::removeExtRadioWorkInternal(uint32_t id)
1355 {
1356 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1357 	struct wpa_radio_work *work;
1358 	dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
1359 	{
1360 		if (os_strncmp(
1361 			work->type, kExtRadioWorkNamePrefix,
1362 			sizeof(kExtRadioWorkNamePrefix)) != 0)
1363 			continue;
1364 
1365 		auto *ework =
1366 		    static_cast<struct wpa_external_work *>(work->ctx);
1367 		if (ework->id != id)
1368 			continue;
1369 
1370 		wpa_dbg(
1371 		    wpa_s, MSG_DEBUG, "Completed external radio work %u (%s)",
1372 		    ework->id, ework->type);
1373 		eloop_cancel_timeout(extRadioWorkTimeoutCb, work, NULL);
1374 		endExtRadioWork(work);
1375 
1376 		return {SupplicantStatusCode::SUCCESS, ""};
1377 	}
1378 	return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1379 }
1380 
enableAutoReconnectInternal(bool enable)1381 SupplicantStatus StaIface::enableAutoReconnectInternal(bool enable)
1382 {
1383 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1384 	wpa_s->auto_reconnect_disabled = enable ? 0 : 1;
1385 	return {SupplicantStatusCode::SUCCESS, ""};
1386 }
1387 
1388 std::pair<SupplicantStatus, uint32_t>
getKeyMgmtCapabilitiesInternal()1389 StaIface::getKeyMgmtCapabilitiesInternal()
1390 {
1391 	return {{SupplicantStatusCode::FAILURE_UNKNOWN, "deprecated"}, 0};
1392 }
1393 
1394 std::pair<SupplicantStatus, uint32_t>
addDppPeerUriInternal(const std::string & uri)1395 StaIface::addDppPeerUriInternal(const std::string& uri)
1396 {
1397 #ifdef CONFIG_DPP
1398 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1399 	int32_t id;
1400 
1401 	id = wpas_dpp_qr_code(wpa_s, uri.c_str());
1402 
1403 	if (id > 0) {
1404 		return {{SupplicantStatusCode::SUCCESS, ""}, id};
1405 	}
1406 #endif
1407 	return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, -1};
1408 }
1409 
removeDppUriInternal(uint32_t bootstrap_id)1410 SupplicantStatus StaIface::removeDppUriInternal(uint32_t bootstrap_id)
1411 {
1412 #ifdef CONFIG_DPP
1413 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1414 	std::string bootstrap_id_str;
1415 
1416 	if (bootstrap_id == 0) {
1417 		bootstrap_id_str = "*";
1418 	}
1419 	else {
1420 		bootstrap_id_str = std::to_string(bootstrap_id);
1421 	}
1422 
1423 	if (dpp_bootstrap_remove(wpa_s->dpp, bootstrap_id_str.c_str()) >= 0) {
1424 		return {SupplicantStatusCode::SUCCESS, ""};
1425 	}
1426 #endif
1427 	return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1428 }
1429 
startDppConfiguratorInitiatorInternal(uint32_t peer_bootstrap_id,uint32_t own_bootstrap_id,const std::string & ssid,const std::string & password,const std::string & psk,DppNetRole net_role,DppAkm security_akm)1430 SupplicantStatus StaIface::startDppConfiguratorInitiatorInternal(
1431 		uint32_t peer_bootstrap_id,	uint32_t own_bootstrap_id,
1432 		const std::string& ssid, const std::string& password,
1433 		const std::string& psk, DppNetRole net_role, DppAkm security_akm)
1434 {
1435 #ifdef CONFIG_DPP
1436 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1437 	std::string cmd = "";
1438 
1439 	if (net_role != DppNetRole::AP &&
1440 			net_role != DppNetRole::STA) {
1441 		wpa_printf(MSG_ERROR,
1442 			   "DPP: Error: Invalid network role specified: %d", net_role);
1443 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1444 	}
1445 
1446 	cmd += " peer=" + std::to_string(peer_bootstrap_id);
1447 	cmd += (own_bootstrap_id > 0) ?
1448 			" own=" + std::to_string(own_bootstrap_id) : "";
1449 
1450 	/* Check for supported AKMs */
1451 	if (security_akm != DppAkm::PSK && security_akm != DppAkm::SAE &&
1452 			security_akm != DppAkm::PSK_SAE) {
1453 		wpa_printf(MSG_ERROR, "DPP: Error: invalid AKM specified: %d",
1454 				security_akm);
1455 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1456 	}
1457 
1458 	/* SAE AKM requires SSID and password to be initialized */
1459 	if ((security_akm == DppAkm::SAE ||
1460 			security_akm == DppAkm::PSK_SAE) &&
1461 			(ssid.empty() || password.empty())) {
1462 		wpa_printf(MSG_ERROR, "DPP: Error: Password or SSID not specified");
1463 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1464 	} else if (security_akm == DppAkm::PSK ||
1465 			security_akm == DppAkm::PSK_SAE) {
1466 		/* PSK AKM requires SSID and password/psk to be initialized */
1467 		if (ssid.empty()) {
1468 			wpa_printf(MSG_ERROR, "DPP: Error: SSID not specified");
1469 			return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1470 		}
1471 		if (password.empty() && psk.empty()) {
1472 			wpa_printf(MSG_ERROR, "DPP: Error: Password or PSK not specified");
1473 			return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1474 		}
1475 	}
1476 
1477 	cmd += " role=configurator";
1478 	cmd += (ssid.empty()) ? "" : " ssid=" + ssid;
1479 
1480 	if (!psk.empty()) {
1481 		cmd += " psk=" + psk;
1482 	} else {
1483 		cmd += (password.empty()) ? "" : " pass=" + password;
1484 	}
1485 
1486 	std::string role = "";
1487 	if (net_role == DppNetRole::AP) {
1488 		role = "ap-";
1489 	}
1490 	else {
1491 		role = "sta-";
1492 	}
1493 
1494 	switch (security_akm) {
1495 	case DppAkm::PSK:
1496 		role += "psk";
1497 		break;
1498 
1499 	case DppAkm::SAE:
1500 		role += "sae";
1501 		break;
1502 
1503 	case DppAkm::PSK_SAE:
1504 		role += "psk-sae";
1505 		break;
1506 
1507 	default:
1508 		wpa_printf(MSG_ERROR,
1509 			   "DPP: Invalid or unsupported security AKM specified: %d", security_akm);
1510 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1511 	}
1512 
1513 	cmd += " conf=";
1514 	cmd += role;
1515 
1516 	if (net_role == DppNetRole::STA) {
1517 		/* DPP R2 connection status request */
1518 		cmd += " conn_status=1";
1519 	}
1520 
1521 	wpa_printf(MSG_DEBUG,
1522 		   "DPP initiator command: %s", cmd.c_str());
1523 
1524 	if (wpas_dpp_auth_init(wpa_s, cmd.c_str()) == 0) {
1525 		return {SupplicantStatusCode::SUCCESS, ""};
1526 	}
1527 #endif
1528 	return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1529 }
1530 
startDppEnrolleeInitiatorInternal(uint32_t peer_bootstrap_id,uint32_t own_bootstrap_id)1531 SupplicantStatus StaIface::startDppEnrolleeInitiatorInternal(uint32_t peer_bootstrap_id,
1532 			uint32_t own_bootstrap_id) {
1533 #ifdef CONFIG_DPP
1534 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1535 	std::string cmd = "";
1536 
1537 	/* Report received configuration to HIDL and create an internal profile */
1538 	wpa_s->conf->dpp_config_processing = 1;
1539 
1540 	cmd += " peer=" + std::to_string(peer_bootstrap_id);
1541 	cmd += (own_bootstrap_id > 0) ?
1542 			" own=" + std::to_string(own_bootstrap_id) : "";
1543 
1544 	cmd += " role=enrollee";
1545 
1546 	wpa_printf(MSG_DEBUG,
1547 		   "DPP initiator command: %s", cmd.c_str());
1548 
1549 	if (wpas_dpp_auth_init(wpa_s, cmd.c_str()) == 0) {
1550 		return {SupplicantStatusCode::SUCCESS, ""};
1551 	}
1552 #endif
1553 	return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1554 }
stopDppInitiatorInternal()1555 SupplicantStatus StaIface::stopDppInitiatorInternal()
1556 {
1557 #ifdef CONFIG_DPP
1558 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1559 
1560 	wpas_dpp_stop(wpa_s);
1561 	return {SupplicantStatusCode::SUCCESS, ""};
1562 #else
1563 	return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1564 #endif
1565 }
1566 
1567 std::pair<V1_4::SupplicantStatus, DppResponderBootstrapInfo>
generateDppBootstrapInfoForResponderInternal(const std::array<uint8_t,6> & mac_address,const std::string & device_info,DppCurve curve)1568 StaIface::generateDppBootstrapInfoForResponderInternal(const std::array<uint8_t, 6> &mac_address,
1569 		const std::string& device_info, DppCurve curve)
1570 {
1571 #ifdef CONFIG_DPP
1572 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1573 	std::string cmd = "type=qrcode";
1574 	int32_t id;
1575 	int32_t listen_channel = 0;
1576 	struct DppResponderBootstrapInfo bootstrap_info;
1577 	const char *uri;
1578 	std::string listen_channel_str;
1579 	std::string mac_addr_str;
1580 	char buf[3] = {0};
1581 
1582 	cmd += (device_info.empty()) ? "" : " info=" + device_info;
1583 
1584 	listen_channel_str = getDppListenChannel(wpa_s, &listen_channel);
1585 	if (listen_channel == 0) {
1586 		wpa_printf(MSG_ERROR, "StaIface: Failed to derive DPP listen channel");
1587 		return {{V1_4::SupplicantStatusCode::FAILURE_UNKNOWN, ""}, bootstrap_info};
1588 	}
1589 	cmd += " chan=" + listen_channel_str;
1590 
1591 	cmd += " mac=";
1592 	for (int i = 0;i < 6;i++) {
1593 		snprintf(buf, sizeof(buf), "%02x", mac_address[i]);
1594 		mac_addr_str.append(buf);
1595 	}
1596 	cmd += mac_addr_str;
1597 
1598 	cmd += " curve=" + convertCurveTypeToName(curve);
1599 
1600 	id = dpp_bootstrap_gen(wpa_s->dpp, cmd.c_str());
1601 	wpa_printf(MSG_DEBUG,
1602 		   "DPP generate bootstrap QR code command: %s id: %d", cmd.c_str(), id);
1603 	if (id > 0) {
1604 		uri = dpp_bootstrap_get_uri(wpa_s->dpp, id);
1605 		if (uri) {
1606 			wpa_printf(MSG_DEBUG, "DPP Bootstrap info: id: %d "
1607 				   "listen_channel: %d uri: %s", id, listen_channel, uri);
1608 			bootstrap_info.bootstrapId = id;
1609 			bootstrap_info.listenChannel = listen_channel;
1610 			bootstrap_info.uri = uri;
1611 			return {{V1_4::SupplicantStatusCode::SUCCESS, ""}, bootstrap_info};
1612 		}
1613 	}
1614 	return {{V1_4::SupplicantStatusCode::FAILURE_UNKNOWN, ""}, bootstrap_info};
1615 #else
1616 	return {{V1_4::SupplicantStatusCode::FAILURE_UNSUPPORTED, ""}, bootstrap_info};
1617 #endif
1618 }
1619 
startDppEnrolleeResponderInternal(uint32_t listen_channel)1620 V1_4::SupplicantStatus StaIface::startDppEnrolleeResponderInternal(uint32_t listen_channel)
1621 {
1622 #ifdef CONFIG_DPP
1623 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1624 	std::string cmd = "";
1625 	uint32_t freq = (listen_channel <= 14 ? 2407 : 5000) + listen_channel * 5;
1626 
1627 	/* Report received configuration to HIDL and create an internal profile */
1628 	wpa_s->conf->dpp_config_processing = 1;
1629 
1630 	cmd += std::to_string(freq);
1631 	cmd += " role=enrollee netrole=sta";
1632 
1633 	wpa_printf(MSG_DEBUG,
1634 		   "DPP Enrollee Responder command: %s", cmd.c_str());
1635 
1636 	if (wpas_dpp_listen(wpa_s, cmd.c_str()) == 0) {
1637 		return {V1_4::SupplicantStatusCode::SUCCESS, ""};
1638 	}
1639 	return {V1_4::SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1640 #else
1641 	return {V1_4::SupplicantStatusCode::FAILURE_UNSUPPORTED, ""};
1642 #endif
1643 }
1644 
stopDppResponderInternal(uint32_t own_bootstrap_id)1645 V1_4::SupplicantStatus StaIface::stopDppResponderInternal(uint32_t own_bootstrap_id)
1646 {
1647 #ifdef CONFIG_DPP
1648 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1649 	std::string bootstrap_id_str;
1650 
1651 	if (own_bootstrap_id == 0) {
1652 		bootstrap_id_str = "*";
1653 	}
1654 	else {
1655 		bootstrap_id_str = std::to_string(own_bootstrap_id);
1656 	}
1657 
1658 	wpa_printf(MSG_DEBUG, "DPP Stop DPP Responder id: %d ", own_bootstrap_id);
1659 	wpas_dpp_stop(wpa_s);
1660 	wpas_dpp_listen_stop(wpa_s);
1661 
1662 	if (dpp_bootstrap_remove(wpa_s->dpp, bootstrap_id_str.c_str()) < 0) {
1663 		wpa_printf(MSG_ERROR, "StaIface: dpp_bootstrap_remove failed");
1664 	}
1665 
1666 	return {V1_4::SupplicantStatusCode::SUCCESS, ""};
1667 #else
1668 	return {V1_4::SupplicantStatusCode::FAILURE_UNSUPPORTED, ""};
1669 #endif
1670 }
1671 
1672 std::pair<SupplicantStatus, android::hardware::wifi::supplicant::V1_3::ConnectionCapabilities>
getConnectionCapabilitiesInternal()1673 StaIface::getConnectionCapabilitiesInternal()
1674 {
1675   struct android::hardware::wifi::supplicant::V1_3::ConnectionCapabilities capa;
1676 	return {{SupplicantStatusCode::FAILURE_UNKNOWN, "deprecated"}, capa};
1677 }
1678 
1679 std::pair<V1_4::SupplicantStatus, ConnectionCapabilities>
getConnectionCapabilitiesInternal_1_4()1680 StaIface::getConnectionCapabilitiesInternal_1_4()
1681 {
1682 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1683 	struct ConnectionCapabilities capa;
1684 
1685 	if (wpa_s->connection_set) {
1686 		capa.legacyMode = LegacyMode::UNKNOWN;
1687 		if (wpa_s->connection_he) {
1688 			capa.V1_3.technology = WifiTechnology::HE;
1689 		} else if (wpa_s->connection_vht) {
1690 			capa.V1_3.technology = WifiTechnology::VHT;
1691 		} else if (wpa_s->connection_ht) {
1692 			capa.V1_3.technology = WifiTechnology::HT;
1693 		} else {
1694 			capa.V1_3.technology = WifiTechnology::LEGACY;
1695 			if (wpas_freq_to_band(wpa_s->assoc_freq) == BAND_2_4_GHZ) {
1696 				capa.legacyMode = (wpa_s->connection_11b_only) ? LegacyMode::B_MODE
1697 						: LegacyMode::G_MODE;
1698 			} else {
1699 				capa.legacyMode = LegacyMode::A_MODE;
1700 			}
1701 		}
1702 		switch (wpa_s->connection_channel_bandwidth) {
1703 		case CHAN_WIDTH_20:
1704 			capa.V1_3.channelBandwidth = WifiChannelWidthInMhz::WIDTH_20;
1705 			break;
1706 		case CHAN_WIDTH_40:
1707 			capa.V1_3.channelBandwidth = WifiChannelWidthInMhz::WIDTH_40;
1708 			break;
1709 		case CHAN_WIDTH_80:
1710 			capa.V1_3.channelBandwidth = WifiChannelWidthInMhz::WIDTH_80;
1711 			break;
1712 		case CHAN_WIDTH_160:
1713 			capa.V1_3.channelBandwidth = WifiChannelWidthInMhz::WIDTH_160;
1714 			break;
1715 		case CHAN_WIDTH_80P80:
1716 			capa.V1_3.channelBandwidth = WifiChannelWidthInMhz::WIDTH_80P80;
1717 			break;
1718 		default:
1719 			capa.V1_3.channelBandwidth = WifiChannelWidthInMhz::WIDTH_20;
1720 			break;
1721 		}
1722 		capa.V1_3.maxNumberRxSpatialStreams = wpa_s->connection_max_nss_rx;
1723 		capa.V1_3.maxNumberTxSpatialStreams = wpa_s->connection_max_nss_tx;
1724 	} else {
1725 		capa.V1_3.technology = WifiTechnology::UNKNOWN;
1726 		capa.V1_3.channelBandwidth = WifiChannelWidthInMhz::WIDTH_20;
1727 		capa.V1_3.maxNumberTxSpatialStreams = 1;
1728 		capa.V1_3.maxNumberRxSpatialStreams = 1;
1729 		capa.legacyMode = LegacyMode::UNKNOWN;
1730 	}
1731 	return {{V1_4::SupplicantStatusCode::SUCCESS, ""}, capa};
1732 }
1733 
1734 std::pair<SupplicantStatus, uint32_t>
getWpaDriverCapabilitiesInternal()1735 StaIface::getWpaDriverCapabilitiesInternal()
1736 {
1737 	return {{SupplicantStatusCode::FAILURE_UNKNOWN, "deprecated"}, 0};
1738 }
1739 
1740 std::pair<V1_4::SupplicantStatus, uint32_t>
getWpaDriverCapabilitiesInternal_1_4()1741 StaIface::getWpaDriverCapabilitiesInternal_1_4()
1742 {
1743 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1744 	uint32_t mask = 0;
1745 
1746 #ifdef CONFIG_MBO
1747 	/* MBO has no capability flags. It's mainly legacy 802.11v BSS
1748 	 * transition + Cellular steering. 11v is a default feature in
1749 	 * supplicant. And cellular steering is handled in framework.
1750 	 */
1751 	mask |= V1_3::WpaDriverCapabilitiesMask::MBO;
1752 	if (wpa_s->enable_oce & OCE_STA) {
1753 		mask |= V1_3::WpaDriverCapabilitiesMask::OCE;
1754 	}
1755 #endif
1756 #ifdef CONFIG_SAE_PK
1757 	mask |= V1_4::WpaDriverCapabilitiesMask::SAE_PK;
1758 #endif
1759 	mask |= V1_4::WpaDriverCapabilitiesMask::WFD_R2;
1760 
1761 	wpa_printf(MSG_DEBUG, "Driver capability mask: 0x%x", mask);
1762 
1763 	return {{V1_4::SupplicantStatusCode::SUCCESS, ""}, mask};
1764 }
1765 
setMboCellularDataStatusInternal(bool available)1766 SupplicantStatus StaIface::setMboCellularDataStatusInternal(bool available)
1767 {
1768 #ifdef CONFIG_MBO
1769 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1770 	enum mbo_cellular_capa mbo_cell_capa;
1771 
1772 	if (available) {
1773 		mbo_cell_capa = MBO_CELL_CAPA_AVAILABLE;
1774 	} else {
1775 		mbo_cell_capa = MBO_CELL_CAPA_NOT_AVAILABLE;
1776 	}
1777 
1778 #ifdef ENABLE_PRIV_CMD_UPDATE_MBO_CELL_STATUS
1779 	char mbo_cmd[32];
1780 	char buf[32];
1781 
1782 	os_snprintf(mbo_cmd, sizeof(mbo_cmd), "%s %d", "MBO CELL_DATA_CAP", mbo_cell_capa);
1783 	if (wpa_drv_driver_cmd(wpa_s, mbo_cmd, buf, sizeof(buf)) < 0) {
1784 		wpa_printf(MSG_ERROR, "MBO CELL_DATA_CAP cmd failed CAP:%d", mbo_cell_capa);
1785 	}
1786 #else
1787 	wpas_mbo_update_cell_capa(wpa_s, mbo_cell_capa);
1788 #endif
1789 
1790 	return {SupplicantStatusCode::SUCCESS, ""};
1791 #else
1792 	return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1793 #endif
1794 }
1795 
1796 std::pair<SupplicantStatus, uint32_t>
getKeyMgmtCapabilitiesInternal_1_3()1797 StaIface::getKeyMgmtCapabilitiesInternal_1_3()
1798 {
1799 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1800 	struct wpa_driver_capa capa;
1801 	uint32_t mask = 0;
1802 
1803 	/* Get capabilities from driver and populate the key management mask */
1804 	if (wpa_drv_get_capa(wpa_s, &capa) < 0) {
1805 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, mask};
1806 	}
1807 
1808 	return {{SupplicantStatusCode::SUCCESS, ""},
1809 	    convertWpaKeyMgmtCapabilitiesToHidl(wpa_s, &capa)};
1810 }
1811 
1812 /**
1813  * Retrieve the underlying |wpa_supplicant| struct
1814  * pointer for this iface.
1815  * If the underlying iface is removed, then all RPC method calls on this object
1816  * will return failure.
1817  */
retrieveIfacePtr()1818 wpa_supplicant *StaIface::retrieveIfacePtr()
1819 {
1820 	return wpa_supplicant_get_iface(wpa_global_, ifname_.c_str());
1821 }
1822 }  // namespace implementation
1823 }  // namespace V1_4
1824 }  // namespace supplicant
1825 }  // namespace wifi
1826 }  // namespace hardware
1827 }  // namespace android
1828