• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "misc_utils.h"
13 #include "sta_network.h"
14 
15 extern "C"
16 {
17 #include "wps_supplicant.h"
18 }
19 
20 namespace {
21 using android::hardware::wifi::supplicant::V1_0::SupplicantStatus;
22 using android::hardware::wifi::supplicant::V1_2::ISupplicantStaNetwork;
23 using namespace android::hardware::wifi::supplicant::V1_2;
24 
25 constexpr uint8_t kZeroBssid[6] = {0, 0, 0, 0, 0, 0};
26 
27 constexpr uint32_t kAllowedKeyMgmtMask =
28     (static_cast<uint32_t>(ISupplicantStaNetwork::KeyMgmtMask::NONE) |
29      static_cast<uint32_t>(ISupplicantStaNetwork::KeyMgmtMask::WPA_PSK) |
30      static_cast<uint32_t>(ISupplicantStaNetwork::KeyMgmtMask::WPA_EAP) |
31      static_cast<uint32_t>(ISupplicantStaNetwork::KeyMgmtMask::IEEE8021X) |
32      static_cast<uint32_t>(ISupplicantStaNetwork::KeyMgmtMask::FT_EAP) |
33      static_cast<uint32_t>(ISupplicantStaNetwork::KeyMgmtMask::FT_PSK) |
34      static_cast<uint32_t>(ISupplicantStaNetwork::KeyMgmtMask::OSEN) |
35      static_cast<uint32_t>(ISupplicantStaNetwork::KeyMgmtMask::SAE) |
36      static_cast<uint32_t>(ISupplicantStaNetwork::KeyMgmtMask::SUITE_B_192) |
37      static_cast<uint32_t>(ISupplicantStaNetwork::KeyMgmtMask::OWE) |
38      static_cast<uint32_t>(ISupplicantStaNetwork::KeyMgmtMask::WPA_PSK_SHA256) |
39      static_cast<uint32_t>(ISupplicantStaNetwork::KeyMgmtMask::WPA_EAP_SHA256));
40 constexpr uint32_t kAllowedProtoMask =
41     (static_cast<uint32_t>(ISupplicantStaNetwork::ProtoMask::WPA) |
42      static_cast<uint32_t>(ISupplicantStaNetwork::ProtoMask::RSN) |
43      static_cast<uint32_t>(ISupplicantStaNetwork::ProtoMask::OSEN));
44 constexpr uint32_t kAllowedAuthAlgMask =
45     (static_cast<uint32_t>(ISupplicantStaNetwork::AuthAlgMask::OPEN) |
46      static_cast<uint32_t>(ISupplicantStaNetwork::AuthAlgMask::SHARED) |
47      static_cast<uint32_t>(ISupplicantStaNetwork::AuthAlgMask::LEAP));
48 constexpr uint32_t kAllowedGroupCipherMask =
49     (static_cast<uint32_t>(ISupplicantStaNetwork::GroupCipherMask::WEP40) |
50      static_cast<uint32_t>(ISupplicantStaNetwork::GroupCipherMask::WEP104) |
51      static_cast<uint32_t>(ISupplicantStaNetwork::GroupCipherMask::TKIP) |
52      static_cast<uint32_t>(ISupplicantStaNetwork::GroupCipherMask::CCMP) |
53      static_cast<uint32_t>(
54 	 ISupplicantStaNetwork::GroupCipherMask::GTK_NOT_USED) |
55      static_cast<uint32_t>(ISupplicantStaNetwork::GroupCipherMask::GCMP_256));
56 constexpr uint32_t kAllowedPairwisewCipherMask =
57     (static_cast<uint32_t>(ISupplicantStaNetwork::PairwiseCipherMask::NONE) |
58      static_cast<uint32_t>(ISupplicantStaNetwork::PairwiseCipherMask::TKIP) |
59      static_cast<uint32_t>(ISupplicantStaNetwork::PairwiseCipherMask::CCMP) |
60      static_cast<uint32_t>(
61 	 ISupplicantStaNetwork::PairwiseCipherMask::GCMP_256));
62 constexpr uint32_t kAllowedGroupMgmtCipherMask =
63 	(static_cast<uint32_t>(
64 			ISupplicantStaNetwork::GroupMgmtCipherMask::BIP_GMAC_128) |
65 	 static_cast<uint32_t>(
66 			 ISupplicantStaNetwork::GroupMgmtCipherMask::BIP_GMAC_256) |
67 	 static_cast<uint32_t>(
68 			 ISupplicantStaNetwork::GroupMgmtCipherMask::BIP_CMAC_256));
69 
70 constexpr uint32_t kEapMethodMax =
71     static_cast<uint32_t>(ISupplicantStaNetwork::EapMethod::WFA_UNAUTH_TLS) + 1;
72 constexpr char const *kEapMethodStrings[kEapMethodMax] = {
73     "PEAP", "TLS", "TTLS", "PWD", "SIM", "AKA", "AKA'", "WFA-UNAUTH-TLS"};
74 constexpr uint32_t kEapPhase2MethodMax =
75     static_cast<uint32_t>(ISupplicantStaNetwork::EapPhase2Method::AKA_PRIME) +
76     1;
77 constexpr char const *kEapPhase2MethodStrings[kEapPhase2MethodMax] = {
78     "", "PAP", "MSCHAP", "MSCHAPV2", "GTC", "SIM", "AKA", "AKA'"};
79 constexpr char kEapPhase2AuthPrefix[] = "auth=";
80 constexpr char kEapPhase2AuthEapPrefix[] = "autheap=";
81 constexpr char kNetworkEapSimGsmAuthResponse[] = "GSM-AUTH";
82 constexpr char kNetworkEapSimUmtsAuthResponse[] = "UMTS-AUTH";
83 constexpr char kNetworkEapSimUmtsAutsResponse[] = "UMTS-AUTS";
84 constexpr char kNetworkEapSimGsmAuthFailure[] = "GSM-FAIL";
85 constexpr char kNetworkEapSimUmtsAuthFailure[] = "UMTS-FAIL";
86 }  // namespace
87 
88 namespace android {
89 namespace hardware {
90 namespace wifi {
91 namespace supplicant {
92 namespace V1_2 {
93 namespace implementation {
94 using hidl_return_util::validateAndCall;
95 
StaNetwork(struct wpa_global * wpa_global,const char ifname[],int network_id)96 StaNetwork::StaNetwork(
97     struct wpa_global *wpa_global, const char ifname[], int network_id)
98     : wpa_global_(wpa_global),
99       ifname_(ifname),
100       network_id_(network_id),
101       is_valid_(true)
102 {}
103 
invalidate()104 void StaNetwork::invalidate() { is_valid_ = false; }
isValid()105 bool StaNetwork::isValid()
106 {
107 	return (is_valid_ && (retrieveNetworkPtr() != nullptr));
108 }
109 
getId(getId_cb _hidl_cb)110 Return<void> StaNetwork::getId(getId_cb _hidl_cb)
111 {
112 	return validateAndCall(
113 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
114 	    &StaNetwork::getIdInternal, _hidl_cb);
115 }
116 
getInterfaceName(getInterfaceName_cb _hidl_cb)117 Return<void> StaNetwork::getInterfaceName(getInterfaceName_cb _hidl_cb)
118 {
119 	return validateAndCall(
120 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
121 	    &StaNetwork::getInterfaceNameInternal, _hidl_cb);
122 }
123 
getType(getType_cb _hidl_cb)124 Return<void> StaNetwork::getType(getType_cb _hidl_cb)
125 {
126 	return validateAndCall(
127 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
128 	    &StaNetwork::getTypeInternal, _hidl_cb);
129 }
130 
registerCallback(const sp<ISupplicantStaNetworkCallback> & callback,registerCallback_cb _hidl_cb)131 Return<void> StaNetwork::registerCallback(
132     const sp<ISupplicantStaNetworkCallback> &callback,
133     registerCallback_cb _hidl_cb)
134 {
135 	return validateAndCall(
136 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
137 	    &StaNetwork::registerCallbackInternal, _hidl_cb, callback);
138 }
139 
setSsid(const hidl_vec<uint8_t> & ssid,setSsid_cb _hidl_cb)140 Return<void> StaNetwork::setSsid(
141     const hidl_vec<uint8_t> &ssid, setSsid_cb _hidl_cb)
142 {
143 	return validateAndCall(
144 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
145 	    &StaNetwork::setSsidInternal, _hidl_cb, ssid);
146 }
147 
setBssid(const hidl_array<uint8_t,6> & bssid,setBssid_cb _hidl_cb)148 Return<void> StaNetwork::setBssid(
149     const hidl_array<uint8_t, 6> &bssid, setBssid_cb _hidl_cb)
150 {
151 	return validateAndCall(
152 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
153 	    &StaNetwork::setBssidInternal, _hidl_cb, bssid);
154 }
155 
setScanSsid(bool enable,setScanSsid_cb _hidl_cb)156 Return<void> StaNetwork::setScanSsid(bool enable, setScanSsid_cb _hidl_cb)
157 {
158 	return validateAndCall(
159 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
160 	    &StaNetwork::setScanSsidInternal, _hidl_cb, enable);
161 }
162 
setKeyMgmt(uint32_t key_mgmt_mask,setKeyMgmt_cb _hidl_cb)163 Return<void> StaNetwork::setKeyMgmt(
164     uint32_t key_mgmt_mask, setKeyMgmt_cb _hidl_cb)
165 {
166 	return validateAndCall(
167 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
168 	    &StaNetwork::setKeyMgmtInternal, _hidl_cb, key_mgmt_mask);
169 }
170 
setProto(uint32_t proto_mask,setProto_cb _hidl_cb)171 Return<void> StaNetwork::setProto(uint32_t proto_mask, setProto_cb _hidl_cb)
172 {
173 	return validateAndCall(
174 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
175 	    &StaNetwork::setProtoInternal, _hidl_cb, proto_mask);
176 }
177 
setAuthAlg(uint32_t auth_alg_mask,std::function<void (const SupplicantStatus & status)> _hidl_cb)178 Return<void> StaNetwork::setAuthAlg(
179     uint32_t auth_alg_mask,
180     std::function<void(const SupplicantStatus &status)> _hidl_cb)
181 {
182 	return validateAndCall(
183 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
184 	    &StaNetwork::setAuthAlgInternal, _hidl_cb, auth_alg_mask);
185 }
186 
setGroupCipher(uint32_t group_cipher_mask,setGroupCipher_cb _hidl_cb)187 Return<void> StaNetwork::setGroupCipher(
188     uint32_t group_cipher_mask, setGroupCipher_cb _hidl_cb)
189 {
190 	return validateAndCall(
191 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
192 	    &StaNetwork::setGroupCipherInternal, _hidl_cb, group_cipher_mask);
193 }
194 
setPairwiseCipher(uint32_t pairwise_cipher_mask,setPairwiseCipher_cb _hidl_cb)195 Return<void> StaNetwork::setPairwiseCipher(
196     uint32_t pairwise_cipher_mask, setPairwiseCipher_cb _hidl_cb)
197 {
198 	return validateAndCall(
199 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
200 	    &StaNetwork::setPairwiseCipherInternal, _hidl_cb,
201 	    pairwise_cipher_mask);
202 }
203 
setPskPassphrase(const hidl_string & psk,setPskPassphrase_cb _hidl_cb)204 Return<void> StaNetwork::setPskPassphrase(
205     const hidl_string &psk, setPskPassphrase_cb _hidl_cb)
206 {
207 	return validateAndCall(
208 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
209 	    &StaNetwork::setPskPassphraseInternal, _hidl_cb, psk);
210 }
211 
setPsk(const hidl_array<uint8_t,32> & psk,setPsk_cb _hidl_cb)212 Return<void> StaNetwork::setPsk(
213     const hidl_array<uint8_t, 32> &psk, setPsk_cb _hidl_cb)
214 {
215 	return validateAndCall(
216 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
217 	    &StaNetwork::setPskInternal, _hidl_cb, psk);
218 }
219 
setWepKey(uint32_t key_idx,const hidl_vec<uint8_t> & wep_key,setWepKey_cb _hidl_cb)220 Return<void> StaNetwork::setWepKey(
221     uint32_t key_idx, const hidl_vec<uint8_t> &wep_key, setWepKey_cb _hidl_cb)
222 {
223 	return validateAndCall(
224 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
225 	    &StaNetwork::setWepKeyInternal, _hidl_cb, key_idx, wep_key);
226 }
227 
setWepTxKeyIdx(uint32_t key_idx,setWepTxKeyIdx_cb _hidl_cb)228 Return<void> StaNetwork::setWepTxKeyIdx(
229     uint32_t key_idx, setWepTxKeyIdx_cb _hidl_cb)
230 {
231 	return validateAndCall(
232 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
233 	    &StaNetwork::setWepTxKeyIdxInternal, _hidl_cb, key_idx);
234 }
235 
setRequirePmf(bool enable,setRequirePmf_cb _hidl_cb)236 Return<void> StaNetwork::setRequirePmf(bool enable, setRequirePmf_cb _hidl_cb)
237 {
238 	return validateAndCall(
239 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
240 	    &StaNetwork::setRequirePmfInternal, _hidl_cb, enable);
241 }
242 
setEapMethod(ISupplicantStaNetwork::EapMethod method,setEapMethod_cb _hidl_cb)243 Return<void> StaNetwork::setEapMethod(
244     ISupplicantStaNetwork::EapMethod method, setEapMethod_cb _hidl_cb)
245 {
246 	return validateAndCall(
247 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
248 	    &StaNetwork::setEapMethodInternal, _hidl_cb, method);
249 }
250 
setEapPhase2Method(ISupplicantStaNetwork::EapPhase2Method method,setEapPhase2Method_cb _hidl_cb)251 Return<void> StaNetwork::setEapPhase2Method(
252     ISupplicantStaNetwork::EapPhase2Method method,
253     setEapPhase2Method_cb _hidl_cb)
254 {
255 	return validateAndCall(
256 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
257 	    &StaNetwork::setEapPhase2MethodInternal, _hidl_cb, method);
258 }
259 
setEapIdentity(const hidl_vec<uint8_t> & identity,setEapIdentity_cb _hidl_cb)260 Return<void> StaNetwork::setEapIdentity(
261     const hidl_vec<uint8_t> &identity, setEapIdentity_cb _hidl_cb)
262 {
263 	return validateAndCall(
264 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
265 	    &StaNetwork::setEapIdentityInternal, _hidl_cb, identity);
266 }
267 
setEapEncryptedImsiIdentity(const EapSimEncryptedIdentity & identity,setEapEncryptedImsiIdentity_cb _hidl_cb)268 Return<void> StaNetwork::setEapEncryptedImsiIdentity(
269     const EapSimEncryptedIdentity &identity,
270     setEapEncryptedImsiIdentity_cb _hidl_cb)
271 {
272 	return validateAndCall(
273 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
274 	    &StaNetwork::setEapEncryptedImsiIdentityInternal, _hidl_cb,
275 	    identity);
276 }
277 
setEapAnonymousIdentity(const hidl_vec<uint8_t> & identity,setEapAnonymousIdentity_cb _hidl_cb)278 Return<void> StaNetwork::setEapAnonymousIdentity(
279     const hidl_vec<uint8_t> &identity, setEapAnonymousIdentity_cb _hidl_cb)
280 {
281 	return validateAndCall(
282 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
283 	    &StaNetwork::setEapAnonymousIdentityInternal, _hidl_cb, identity);
284 }
285 
setEapPassword(const hidl_vec<uint8_t> & password,setEapPassword_cb _hidl_cb)286 Return<void> StaNetwork::setEapPassword(
287     const hidl_vec<uint8_t> &password, setEapPassword_cb _hidl_cb)
288 {
289 	return validateAndCall(
290 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
291 	    &StaNetwork::setEapPasswordInternal, _hidl_cb, password);
292 }
293 
setEapCACert(const hidl_string & path,setEapCACert_cb _hidl_cb)294 Return<void> StaNetwork::setEapCACert(
295     const hidl_string &path, setEapCACert_cb _hidl_cb)
296 {
297 	return validateAndCall(
298 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
299 	    &StaNetwork::setEapCACertInternal, _hidl_cb, path);
300 }
301 
setEapCAPath(const hidl_string & path,setEapCAPath_cb _hidl_cb)302 Return<void> StaNetwork::setEapCAPath(
303     const hidl_string &path, setEapCAPath_cb _hidl_cb)
304 {
305 	return validateAndCall(
306 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
307 	    &StaNetwork::setEapCAPathInternal, _hidl_cb, path);
308 }
309 
setEapClientCert(const hidl_string & path,setEapClientCert_cb _hidl_cb)310 Return<void> StaNetwork::setEapClientCert(
311     const hidl_string &path, setEapClientCert_cb _hidl_cb)
312 {
313 	return validateAndCall(
314 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
315 	    &StaNetwork::setEapClientCertInternal, _hidl_cb, path);
316 }
317 
setEapPrivateKeyId(const hidl_string & id,setEapPrivateKeyId_cb _hidl_cb)318 Return<void> StaNetwork::setEapPrivateKeyId(
319     const hidl_string &id, setEapPrivateKeyId_cb _hidl_cb)
320 {
321 	return validateAndCall(
322 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
323 	    &StaNetwork::setEapPrivateKeyIdInternal, _hidl_cb, id);
324 }
325 
setEapSubjectMatch(const hidl_string & match,setEapSubjectMatch_cb _hidl_cb)326 Return<void> StaNetwork::setEapSubjectMatch(
327     const hidl_string &match, setEapSubjectMatch_cb _hidl_cb)
328 {
329 	return validateAndCall(
330 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
331 	    &StaNetwork::setEapSubjectMatchInternal, _hidl_cb, match);
332 }
333 
setEapAltSubjectMatch(const hidl_string & match,setEapAltSubjectMatch_cb _hidl_cb)334 Return<void> StaNetwork::setEapAltSubjectMatch(
335     const hidl_string &match, setEapAltSubjectMatch_cb _hidl_cb)
336 {
337 	return validateAndCall(
338 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
339 	    &StaNetwork::setEapAltSubjectMatchInternal, _hidl_cb, match);
340 }
341 
setEapEngine(bool enable,setEapEngine_cb _hidl_cb)342 Return<void> StaNetwork::setEapEngine(bool enable, setEapEngine_cb _hidl_cb)
343 {
344 	return validateAndCall(
345 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
346 	    &StaNetwork::setEapEngineInternal, _hidl_cb, enable);
347 }
348 
setEapEngineID(const hidl_string & id,setEapEngineID_cb _hidl_cb)349 Return<void> StaNetwork::setEapEngineID(
350     const hidl_string &id, setEapEngineID_cb _hidl_cb)
351 {
352 	return validateAndCall(
353 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
354 	    &StaNetwork::setEapEngineIDInternal, _hidl_cb, id);
355 }
356 
setEapDomainSuffixMatch(const hidl_string & match,setEapDomainSuffixMatch_cb _hidl_cb)357 Return<void> StaNetwork::setEapDomainSuffixMatch(
358     const hidl_string &match, setEapDomainSuffixMatch_cb _hidl_cb)
359 {
360 	return validateAndCall(
361 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
362 	    &StaNetwork::setEapDomainSuffixMatchInternal, _hidl_cb, match);
363 }
364 
setProactiveKeyCaching(bool enable,setProactiveKeyCaching_cb _hidl_cb)365 Return<void> StaNetwork::setProactiveKeyCaching(
366     bool enable, setProactiveKeyCaching_cb _hidl_cb)
367 {
368 	return validateAndCall(
369 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
370 	    &StaNetwork::setProactiveKeyCachingInternal, _hidl_cb, enable);
371 }
372 
setIdStr(const hidl_string & id_str,setIdStr_cb _hidl_cb)373 Return<void> StaNetwork::setIdStr(
374     const hidl_string &id_str, setIdStr_cb _hidl_cb)
375 {
376 	return validateAndCall(
377 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
378 	    &StaNetwork::setIdStrInternal, _hidl_cb, id_str);
379 }
380 
setUpdateIdentifier(uint32_t id,setUpdateIdentifier_cb _hidl_cb)381 Return<void> StaNetwork::setUpdateIdentifier(
382     uint32_t id, setUpdateIdentifier_cb _hidl_cb)
383 {
384 	return validateAndCall(
385 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
386 	    &StaNetwork::setUpdateIdentifierInternal, _hidl_cb, id);
387 }
388 
getSsid(getSsid_cb _hidl_cb)389 Return<void> StaNetwork::getSsid(getSsid_cb _hidl_cb)
390 {
391 	return validateAndCall(
392 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
393 	    &StaNetwork::getSsidInternal, _hidl_cb);
394 }
395 
getBssid(getBssid_cb _hidl_cb)396 Return<void> StaNetwork::getBssid(getBssid_cb _hidl_cb)
397 {
398 	return validateAndCall(
399 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
400 	    &StaNetwork::getBssidInternal, _hidl_cb);
401 }
402 
getScanSsid(getScanSsid_cb _hidl_cb)403 Return<void> StaNetwork::getScanSsid(getScanSsid_cb _hidl_cb)
404 {
405 	return validateAndCall(
406 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
407 	    &StaNetwork::getScanSsidInternal, _hidl_cb);
408 }
409 
getKeyMgmt(getKeyMgmt_cb _hidl_cb)410 Return<void> StaNetwork::getKeyMgmt(getKeyMgmt_cb _hidl_cb)
411 {
412 	return validateAndCall(
413 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
414 	    &StaNetwork::getKeyMgmtInternal, _hidl_cb);
415 }
416 
getProto(getProto_cb _hidl_cb)417 Return<void> StaNetwork::getProto(getProto_cb _hidl_cb)
418 {
419 	return validateAndCall(
420 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
421 	    &StaNetwork::getProtoInternal, _hidl_cb);
422 }
423 
getAuthAlg(getAuthAlg_cb _hidl_cb)424 Return<void> StaNetwork::getAuthAlg(getAuthAlg_cb _hidl_cb)
425 {
426 	return validateAndCall(
427 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
428 	    &StaNetwork::getAuthAlgInternal, _hidl_cb);
429 }
430 
getGroupCipher(getGroupCipher_cb _hidl_cb)431 Return<void> StaNetwork::getGroupCipher(getGroupCipher_cb _hidl_cb)
432 {
433 	return validateAndCall(
434 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
435 	    &StaNetwork::getGroupCipherInternal, _hidl_cb);
436 }
437 
getPairwiseCipher(getPairwiseCipher_cb _hidl_cb)438 Return<void> StaNetwork::getPairwiseCipher(getPairwiseCipher_cb _hidl_cb)
439 {
440 	return validateAndCall(
441 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
442 	    &StaNetwork::getPairwiseCipherInternal, _hidl_cb);
443 }
444 
getPskPassphrase(getPskPassphrase_cb _hidl_cb)445 Return<void> StaNetwork::getPskPassphrase(getPskPassphrase_cb _hidl_cb)
446 {
447 	return validateAndCall(
448 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
449 	    &StaNetwork::getPskPassphraseInternal, _hidl_cb);
450 }
451 
getPsk(getPsk_cb _hidl_cb)452 Return<void> StaNetwork::getPsk(getPsk_cb _hidl_cb)
453 {
454 	return validateAndCall(
455 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
456 	    &StaNetwork::getPskInternal, _hidl_cb);
457 }
458 
getSaePassword(getSaePassword_cb _hidl_cb)459 Return<void> StaNetwork::getSaePassword(getSaePassword_cb _hidl_cb)
460 {
461 	return validateAndCall(
462 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
463 	    &StaNetwork::getSaePasswordInternal, _hidl_cb);
464 }
465 
getSaePasswordId(getSaePasswordId_cb _hidl_cb)466 Return<void> StaNetwork::getSaePasswordId(getSaePasswordId_cb _hidl_cb)
467 {
468 	return validateAndCall(
469 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
470 	    &StaNetwork::getSaePasswordIdInternal, _hidl_cb);
471 }
472 
getWepKey(uint32_t key_idx,getWepKey_cb _hidl_cb)473 Return<void> StaNetwork::getWepKey(uint32_t key_idx, getWepKey_cb _hidl_cb)
474 {
475 	return validateAndCall(
476 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
477 	    &StaNetwork::getWepKeyInternal, _hidl_cb, key_idx);
478 }
479 
getWepTxKeyIdx(getWepTxKeyIdx_cb _hidl_cb)480 Return<void> StaNetwork::getWepTxKeyIdx(getWepTxKeyIdx_cb _hidl_cb)
481 {
482 	return validateAndCall(
483 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
484 	    &StaNetwork::getWepTxKeyIdxInternal, _hidl_cb);
485 }
486 
getRequirePmf(getRequirePmf_cb _hidl_cb)487 Return<void> StaNetwork::getRequirePmf(getRequirePmf_cb _hidl_cb)
488 {
489 	return validateAndCall(
490 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
491 	    &StaNetwork::getRequirePmfInternal, _hidl_cb);
492 }
493 
getEapMethod(getEapMethod_cb _hidl_cb)494 Return<void> StaNetwork::getEapMethod(getEapMethod_cb _hidl_cb)
495 {
496 	return validateAndCall(
497 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
498 	    &StaNetwork::getEapMethodInternal, _hidl_cb);
499 }
500 
getEapPhase2Method(getEapPhase2Method_cb _hidl_cb)501 Return<void> StaNetwork::getEapPhase2Method(getEapPhase2Method_cb _hidl_cb)
502 {
503 	return validateAndCall(
504 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
505 	    &StaNetwork::getEapPhase2MethodInternal, _hidl_cb);
506 }
507 
getEapIdentity(getEapIdentity_cb _hidl_cb)508 Return<void> StaNetwork::getEapIdentity(getEapIdentity_cb _hidl_cb)
509 {
510 	return validateAndCall(
511 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
512 	    &StaNetwork::getEapIdentityInternal, _hidl_cb);
513 }
514 
getEapAnonymousIdentity(getEapAnonymousIdentity_cb _hidl_cb)515 Return<void> StaNetwork::getEapAnonymousIdentity(
516     getEapAnonymousIdentity_cb _hidl_cb)
517 {
518 	return validateAndCall(
519 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
520 	    &StaNetwork::getEapAnonymousIdentityInternal, _hidl_cb);
521 }
522 
getEapPassword(getEapPassword_cb _hidl_cb)523 Return<void> StaNetwork::getEapPassword(getEapPassword_cb _hidl_cb)
524 {
525 	return validateAndCall(
526 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
527 	    &StaNetwork::getEapPasswordInternal, _hidl_cb);
528 }
529 
getEapCACert(getEapCACert_cb _hidl_cb)530 Return<void> StaNetwork::getEapCACert(getEapCACert_cb _hidl_cb)
531 {
532 	return validateAndCall(
533 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
534 	    &StaNetwork::getEapCACertInternal, _hidl_cb);
535 }
536 
getEapCAPath(getEapCAPath_cb _hidl_cb)537 Return<void> StaNetwork::getEapCAPath(getEapCAPath_cb _hidl_cb)
538 {
539 	return validateAndCall(
540 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
541 	    &StaNetwork::getEapCAPathInternal, _hidl_cb);
542 }
543 
getEapClientCert(getEapClientCert_cb _hidl_cb)544 Return<void> StaNetwork::getEapClientCert(getEapClientCert_cb _hidl_cb)
545 {
546 	return validateAndCall(
547 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
548 	    &StaNetwork::getEapClientCertInternal, _hidl_cb);
549 }
550 
getEapPrivateKeyId(getEapPrivateKeyId_cb _hidl_cb)551 Return<void> StaNetwork::getEapPrivateKeyId(getEapPrivateKeyId_cb _hidl_cb)
552 {
553 	return validateAndCall(
554 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
555 	    &StaNetwork::getEapPrivateKeyIdInternal, _hidl_cb);
556 }
557 
getEapSubjectMatch(getEapSubjectMatch_cb _hidl_cb)558 Return<void> StaNetwork::getEapSubjectMatch(getEapSubjectMatch_cb _hidl_cb)
559 {
560 	return validateAndCall(
561 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
562 	    &StaNetwork::getEapSubjectMatchInternal, _hidl_cb);
563 }
564 
getEapAltSubjectMatch(getEapAltSubjectMatch_cb _hidl_cb)565 Return<void> StaNetwork::getEapAltSubjectMatch(
566     getEapAltSubjectMatch_cb _hidl_cb)
567 {
568 	return validateAndCall(
569 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
570 	    &StaNetwork::getEapAltSubjectMatchInternal, _hidl_cb);
571 }
572 
getEapEngine(getEapEngine_cb _hidl_cb)573 Return<void> StaNetwork::getEapEngine(getEapEngine_cb _hidl_cb)
574 {
575 	return validateAndCall(
576 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
577 	    &StaNetwork::getEapEngineInternal, _hidl_cb);
578 }
579 
getEapEngineID(getEapEngineID_cb _hidl_cb)580 Return<void> StaNetwork::getEapEngineID(getEapEngineID_cb _hidl_cb)
581 {
582 	return validateAndCall(
583 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
584 	    &StaNetwork::getEapEngineIDInternal, _hidl_cb);
585 }
586 
getEapDomainSuffixMatch(getEapDomainSuffixMatch_cb _hidl_cb)587 Return<void> StaNetwork::getEapDomainSuffixMatch(
588     getEapDomainSuffixMatch_cb _hidl_cb)
589 {
590 	return validateAndCall(
591 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
592 	    &StaNetwork::getEapDomainSuffixMatchInternal, _hidl_cb);
593 }
594 
getIdStr(getIdStr_cb _hidl_cb)595 Return<void> StaNetwork::getIdStr(getIdStr_cb _hidl_cb)
596 {
597 	return validateAndCall(
598 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
599 	    &StaNetwork::getIdStrInternal, _hidl_cb);
600 }
601 
getWpsNfcConfigurationToken(getWpsNfcConfigurationToken_cb _hidl_cb)602 Return<void> StaNetwork::getWpsNfcConfigurationToken(
603     getWpsNfcConfigurationToken_cb _hidl_cb)
604 {
605 	return validateAndCall(
606 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
607 	    &StaNetwork::getWpsNfcConfigurationTokenInternal, _hidl_cb);
608 }
609 
enable(bool no_connect,enable_cb _hidl_cb)610 Return<void> StaNetwork::enable(bool no_connect, enable_cb _hidl_cb)
611 {
612 	return validateAndCall(
613 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
614 	    &StaNetwork::enableInternal, _hidl_cb, no_connect);
615 }
616 
disable(disable_cb _hidl_cb)617 Return<void> StaNetwork::disable(disable_cb _hidl_cb)
618 {
619 	return validateAndCall(
620 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
621 	    &StaNetwork::disableInternal, _hidl_cb);
622 }
623 
select(select_cb _hidl_cb)624 Return<void> StaNetwork::select(select_cb _hidl_cb)
625 {
626 	return validateAndCall(
627 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
628 	    &StaNetwork::selectInternal, _hidl_cb);
629 }
630 
sendNetworkEapSimGsmAuthResponse(const hidl_vec<ISupplicantStaNetwork::NetworkResponseEapSimGsmAuthParams> & vec_params,sendNetworkEapSimGsmAuthResponse_cb _hidl_cb)631 Return<void> StaNetwork::sendNetworkEapSimGsmAuthResponse(
632     const hidl_vec<ISupplicantStaNetwork::NetworkResponseEapSimGsmAuthParams>
633 	&vec_params,
634     sendNetworkEapSimGsmAuthResponse_cb _hidl_cb)
635 {
636 	return validateAndCall(
637 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
638 	    &StaNetwork::sendNetworkEapSimGsmAuthResponseInternal, _hidl_cb,
639 	    vec_params);
640 }
641 
sendNetworkEapSimGsmAuthFailure(sendNetworkEapSimGsmAuthFailure_cb _hidl_cb)642 Return<void> StaNetwork::sendNetworkEapSimGsmAuthFailure(
643     sendNetworkEapSimGsmAuthFailure_cb _hidl_cb)
644 {
645 	return validateAndCall(
646 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
647 	    &StaNetwork::sendNetworkEapSimGsmAuthFailureInternal, _hidl_cb);
648 }
649 
sendNetworkEapSimUmtsAuthResponse(const ISupplicantStaNetwork::NetworkResponseEapSimUmtsAuthParams & params,sendNetworkEapSimUmtsAuthResponse_cb _hidl_cb)650 Return<void> StaNetwork::sendNetworkEapSimUmtsAuthResponse(
651     const ISupplicantStaNetwork::NetworkResponseEapSimUmtsAuthParams &params,
652     sendNetworkEapSimUmtsAuthResponse_cb _hidl_cb)
653 {
654 	return validateAndCall(
655 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
656 	    &StaNetwork::sendNetworkEapSimUmtsAuthResponseInternal, _hidl_cb,
657 	    params);
658 }
659 
sendNetworkEapSimUmtsAutsResponse(const hidl_array<uint8_t,14> & auts,sendNetworkEapSimUmtsAutsResponse_cb _hidl_cb)660 Return<void> StaNetwork::sendNetworkEapSimUmtsAutsResponse(
661     const hidl_array<uint8_t, 14> &auts,
662     sendNetworkEapSimUmtsAutsResponse_cb _hidl_cb)
663 {
664 	return validateAndCall(
665 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
666 	    &StaNetwork::sendNetworkEapSimUmtsAutsResponseInternal, _hidl_cb,
667 	    auts);
668 }
669 
sendNetworkEapSimUmtsAuthFailure(sendNetworkEapSimUmtsAuthFailure_cb _hidl_cb)670 Return<void> StaNetwork::sendNetworkEapSimUmtsAuthFailure(
671     sendNetworkEapSimUmtsAuthFailure_cb _hidl_cb)
672 {
673 	return validateAndCall(
674 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
675 	    &StaNetwork::sendNetworkEapSimUmtsAuthFailureInternal, _hidl_cb);
676 }
677 
sendNetworkEapIdentityResponse(const hidl_vec<uint8_t> & identity,sendNetworkEapIdentityResponse_cb _hidl_cb)678 Return<void> StaNetwork::sendNetworkEapIdentityResponse(
679     const hidl_vec<uint8_t> &identity,
680     sendNetworkEapIdentityResponse_cb _hidl_cb)
681 {
682 	return validateAndCall(
683 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
684 	    &StaNetwork::sendNetworkEapIdentityResponseInternal, _hidl_cb,
685 	    identity);
686 }
687 
sendNetworkEapIdentityResponse_1_1(const EapSimIdentity & identity,const EapSimEncryptedIdentity & encrypted_imsi_identity,sendNetworkEapIdentityResponse_1_1_cb _hidl_cb)688 Return<void> StaNetwork::sendNetworkEapIdentityResponse_1_1(
689     const EapSimIdentity &identity,
690     const EapSimEncryptedIdentity &encrypted_imsi_identity,
691     sendNetworkEapIdentityResponse_1_1_cb _hidl_cb)
692 {
693 	return validateAndCall(
694 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
695 	    &StaNetwork::sendNetworkEapIdentityResponseInternal_1_1, _hidl_cb,
696 	    identity, encrypted_imsi_identity);
697 }
698 
setKeyMgmt_1_2(uint32_t key_mgmt_mask,setKeyMgmt_1_2_cb _hidl_cb)699 Return<void> StaNetwork::setKeyMgmt_1_2(
700     uint32_t key_mgmt_mask, setKeyMgmt_1_2_cb _hidl_cb)
701 {
702 	return validateAndCall(
703 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
704 	    &StaNetwork::setKeyMgmtInternal, _hidl_cb, key_mgmt_mask);
705 }
706 
setGroupCipher_1_2(uint32_t group_cipher_mask,setGroupCipher_1_2_cb _hidl_cb)707 Return<void> StaNetwork::setGroupCipher_1_2(
708     uint32_t group_cipher_mask, setGroupCipher_1_2_cb _hidl_cb)
709 {
710 	return validateAndCall(
711 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
712 	    &StaNetwork::setGroupCipherInternal, _hidl_cb, group_cipher_mask);
713 }
714 
setGroupMgmtCipher(uint32_t group_mgmt_cipher_mask,setGroupMgmtCipher_cb _hidl_cb)715 Return<void> StaNetwork::setGroupMgmtCipher(
716     uint32_t group_mgmt_cipher_mask, setGroupMgmtCipher_cb _hidl_cb)
717 {
718 	return validateAndCall(
719 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
720 	    &StaNetwork::setGroupMgmtCipherInternal,
721 		_hidl_cb, group_mgmt_cipher_mask);
722 }
723 
getGroupMgmtCipher(getGroupMgmtCipher_cb _hidl_cb)724 Return<void> StaNetwork::getGroupMgmtCipher(getGroupMgmtCipher_cb _hidl_cb)
725 {
726 	return validateAndCall(
727 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
728 	    &StaNetwork::getGroupMgmtCipherInternal, _hidl_cb);
729 }
730 
setPairwiseCipher_1_2(uint32_t pairwise_cipher_mask,setPairwiseCipher_1_2_cb _hidl_cb)731 Return<void> StaNetwork::setPairwiseCipher_1_2(
732     uint32_t pairwise_cipher_mask, setPairwiseCipher_1_2_cb _hidl_cb)
733 {
734 	return validateAndCall(
735 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
736 	    &StaNetwork::setPairwiseCipherInternal, _hidl_cb,
737 	    pairwise_cipher_mask);
738 }
739 
getKeyMgmt_1_2(getKeyMgmt_1_2_cb _hidl_cb)740 Return<void> StaNetwork::getKeyMgmt_1_2(getKeyMgmt_1_2_cb _hidl_cb)
741 {
742 	return validateAndCall(
743 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
744 	    &StaNetwork::getKeyMgmtInternal, _hidl_cb);
745 }
746 
getGroupCipher_1_2(getGroupCipher_1_2_cb _hidl_cb)747 Return<void> StaNetwork::getGroupCipher_1_2(getGroupCipher_1_2_cb _hidl_cb)
748 {
749 	return validateAndCall(
750 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
751 	    &StaNetwork::getGroupCipherInternal, _hidl_cb);
752 }
753 
getPairwiseCipher_1_2(getPairwiseCipher_1_2_cb _hidl_cb)754 Return<void> StaNetwork::getPairwiseCipher_1_2(
755     getPairwiseCipher_1_2_cb _hidl_cb)
756 {
757 	return validateAndCall(
758 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
759 	    &StaNetwork::getPairwiseCipherInternal, _hidl_cb);
760 }
761 
enableTlsSuiteBEapPhase1Param(bool enable,enableTlsSuiteBEapPhase1Param_cb _hidl_cb)762 Return<void> StaNetwork::enableTlsSuiteBEapPhase1Param(
763     bool enable, enableTlsSuiteBEapPhase1Param_cb _hidl_cb)
764 {
765 	return validateAndCall(
766 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
767 	    &StaNetwork::enableTlsSuiteBEapPhase1ParamInternal, _hidl_cb, enable);
768 }
769 
enableSuiteBEapOpenSslCiphers(enableSuiteBEapOpenSslCiphers_cb _hidl_cb)770 Return<void> StaNetwork::enableSuiteBEapOpenSslCiphers(
771     enableSuiteBEapOpenSslCiphers_cb _hidl_cb)
772 {
773 	return validateAndCall(
774 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
775 	    &StaNetwork::enableSuiteBEapOpenSslCiphersInternal, _hidl_cb);
776 }
777 
setSaePassword(const hidl_string & sae_password,setSaePassword_cb _hidl_cb)778 Return<void> StaNetwork::setSaePassword(
779     const hidl_string &sae_password, setSaePassword_cb _hidl_cb)
780 {
781 	return validateAndCall(
782 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
783 	    &StaNetwork::setSaePasswordInternal, _hidl_cb, sae_password);
784 }
785 
setSaePasswordId(const hidl_string & sae_password_id,setSaePasswordId_cb _hidl_cb)786 Return<void> StaNetwork::setSaePasswordId(
787     const hidl_string &sae_password_id, setSaePasswordId_cb _hidl_cb)
788 {
789 	return validateAndCall(
790 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
791 	    &StaNetwork::setSaePasswordIdInternal, _hidl_cb, sae_password_id);
792 }
793 
getIdInternal()794 std::pair<SupplicantStatus, uint32_t> StaNetwork::getIdInternal()
795 {
796 	return {{SupplicantStatusCode::SUCCESS, ""}, network_id_};
797 }
798 
getInterfaceNameInternal()799 std::pair<SupplicantStatus, std::string> StaNetwork::getInterfaceNameInternal()
800 {
801 	return {{SupplicantStatusCode::SUCCESS, ""}, ifname_};
802 }
803 
getTypeInternal()804 std::pair<SupplicantStatus, IfaceType> StaNetwork::getTypeInternal()
805 {
806 	return {{SupplicantStatusCode::SUCCESS, ""}, IfaceType::STA};
807 }
808 
registerCallbackInternal(const sp<ISupplicantStaNetworkCallback> & callback)809 SupplicantStatus StaNetwork::registerCallbackInternal(
810     const sp<ISupplicantStaNetworkCallback> &callback)
811 {
812 	HidlManager *hidl_manager = HidlManager::getInstance();
813 	if (!hidl_manager || hidl_manager->addStaNetworkCallbackHidlObject(
814 				 ifname_, network_id_, callback)) {
815 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
816 	}
817 	return {SupplicantStatusCode::SUCCESS, ""};
818 }
819 
setSsidInternal(const std::vector<uint8_t> & ssid)820 SupplicantStatus StaNetwork::setSsidInternal(const std::vector<uint8_t> &ssid)
821 {
822 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
823 	if (ssid.size() == 0 ||
824 	    ssid.size() >
825 		static_cast<uint32_t>(ISupplicantStaNetwork::ParamSizeLimits::
826 					  SSID_MAX_LEN_IN_BYTES)) {
827 		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
828 	}
829 	if (setByteArrayFieldAndResetState(
830 		ssid.data(), ssid.size(), &(wpa_ssid->ssid),
831 		&(wpa_ssid->ssid_len), "ssid")) {
832 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
833 	}
834 	if (wpa_ssid->passphrase) {
835 		wpa_config_update_psk(wpa_ssid);
836 	}
837 	return {SupplicantStatusCode::SUCCESS, ""};
838 }
839 
setBssidInternal(const std::array<uint8_t,6> & bssid)840 SupplicantStatus StaNetwork::setBssidInternal(
841     const std::array<uint8_t, 6> &bssid)
842 {
843 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
844 	int prev_bssid_set = wpa_ssid->bssid_set;
845 	u8 prev_bssid[ETH_ALEN];
846 	os_memcpy(prev_bssid, wpa_ssid->bssid, ETH_ALEN);
847 	// Zero'ed array is used to clear out the BSSID value.
848 	if (os_memcmp(bssid.data(), kZeroBssid, ETH_ALEN) == 0) {
849 		wpa_ssid->bssid_set = 0;
850 		wpa_printf(MSG_MSGDUMP, "BSSID any");
851 	} else {
852 		os_memcpy(wpa_ssid->bssid, bssid.data(), ETH_ALEN);
853 		wpa_ssid->bssid_set = 1;
854 		wpa_hexdump(MSG_MSGDUMP, "BSSID", wpa_ssid->bssid, ETH_ALEN);
855 	}
856 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
857 	if ((wpa_ssid->bssid_set != prev_bssid_set ||
858 	     os_memcmp(wpa_ssid->bssid, prev_bssid, ETH_ALEN) != 0)) {
859 		wpas_notify_network_bssid_set_changed(wpa_s, wpa_ssid);
860 	}
861 	return {SupplicantStatusCode::SUCCESS, ""};
862 }
863 
setScanSsidInternal(bool enable)864 SupplicantStatus StaNetwork::setScanSsidInternal(bool enable)
865 {
866 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
867 	wpa_ssid->scan_ssid = enable ? 1 : 0;
868 	resetInternalStateAfterParamsUpdate();
869 	return {SupplicantStatusCode::SUCCESS, ""};
870 }
871 
setKeyMgmtInternal(uint32_t key_mgmt_mask)872 SupplicantStatus StaNetwork::setKeyMgmtInternal(uint32_t key_mgmt_mask)
873 {
874 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
875 	if (key_mgmt_mask & ~kAllowedKeyMgmtMask) {
876 		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
877 	}
878 	setFastTransitionKeyMgmt(key_mgmt_mask);
879 	wpa_ssid->key_mgmt = key_mgmt_mask;
880 	wpa_printf(MSG_MSGDUMP, "key_mgmt: 0x%x", wpa_ssid->key_mgmt);
881 	resetInternalStateAfterParamsUpdate();
882 	return {SupplicantStatusCode::SUCCESS, ""};
883 }
884 
setProtoInternal(uint32_t proto_mask)885 SupplicantStatus StaNetwork::setProtoInternal(uint32_t proto_mask)
886 {
887 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
888 	if (proto_mask & ~kAllowedProtoMask) {
889 		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
890 	}
891 	wpa_ssid->proto = proto_mask;
892 	wpa_printf(MSG_MSGDUMP, "proto: 0x%x", wpa_ssid->proto);
893 	resetInternalStateAfterParamsUpdate();
894 	return {SupplicantStatusCode::SUCCESS, ""};
895 }
896 
setAuthAlgInternal(uint32_t auth_alg_mask)897 SupplicantStatus StaNetwork::setAuthAlgInternal(uint32_t auth_alg_mask)
898 {
899 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
900 	if (auth_alg_mask & ~kAllowedAuthAlgMask) {
901 		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
902 	}
903 	wpa_ssid->auth_alg = auth_alg_mask;
904 	wpa_printf(MSG_MSGDUMP, "auth_alg: 0x%x", wpa_ssid->auth_alg);
905 	resetInternalStateAfterParamsUpdate();
906 	return {SupplicantStatusCode::SUCCESS, ""};
907 }
908 
setGroupCipherInternal(uint32_t group_cipher_mask)909 SupplicantStatus StaNetwork::setGroupCipherInternal(uint32_t group_cipher_mask)
910 {
911 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
912 	if (group_cipher_mask & ~kAllowedGroupCipherMask) {
913 		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
914 	}
915 	wpa_ssid->group_cipher = group_cipher_mask;
916 	wpa_printf(MSG_MSGDUMP, "group_cipher: 0x%x", wpa_ssid->group_cipher);
917 	resetInternalStateAfterParamsUpdate();
918 	return {SupplicantStatusCode::SUCCESS, ""};
919 }
920 
setPairwiseCipherInternal(uint32_t pairwise_cipher_mask)921 SupplicantStatus StaNetwork::setPairwiseCipherInternal(
922     uint32_t pairwise_cipher_mask)
923 {
924 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
925 	if (pairwise_cipher_mask & ~kAllowedPairwisewCipherMask) {
926 		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
927 	}
928 	wpa_ssid->pairwise_cipher = pairwise_cipher_mask;
929 	wpa_printf(
930 	    MSG_MSGDUMP, "pairwise_cipher: 0x%x", wpa_ssid->pairwise_cipher);
931 	resetInternalStateAfterParamsUpdate();
932 	return {SupplicantStatusCode::SUCCESS, ""};
933 }
934 
setPskPassphraseInternal(const std::string & psk)935 SupplicantStatus StaNetwork::setPskPassphraseInternal(const std::string &psk)
936 {
937 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
938 	if (isPskPassphraseValid(psk)) {
939 		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
940 	}
941 	if (wpa_ssid->passphrase &&
942 	    os_strlen(wpa_ssid->passphrase) == psk.size() &&
943 	    os_memcmp(wpa_ssid->passphrase, psk.c_str(), psk.size()) == 0) {
944 		return {SupplicantStatusCode::SUCCESS, ""};
945 	}
946 	// Flag to indicate if raw psk is calculated or not using
947 	// |wpa_config_update_psk|. Deferred if ssid not already set.
948 	wpa_ssid->psk_set = 0;
949 	if (setStringKeyFieldAndResetState(
950 		psk.c_str(), &(wpa_ssid->passphrase), "psk passphrase")) {
951 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
952 	}
953 	if (wpa_ssid->ssid_len) {
954 		wpa_config_update_psk(wpa_ssid);
955 	}
956 	return {SupplicantStatusCode::SUCCESS, ""};
957 }
958 
setPskInternal(const std::array<uint8_t,32> & psk)959 SupplicantStatus StaNetwork::setPskInternal(const std::array<uint8_t, 32> &psk)
960 {
961 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
962 	WPA_ASSERT(psk.size() == sizeof(wpa_ssid->psk));
963 	str_clear_free(wpa_ssid->passphrase);
964 	wpa_ssid->passphrase = nullptr;
965 	os_memcpy(wpa_ssid->psk, psk.data(), sizeof(wpa_ssid->psk));
966 	wpa_ssid->psk_set = 1;
967 	resetInternalStateAfterParamsUpdate();
968 	return {SupplicantStatusCode::SUCCESS, ""};
969 }
970 
setWepKeyInternal(uint32_t key_idx,const std::vector<uint8_t> & wep_key)971 SupplicantStatus StaNetwork::setWepKeyInternal(
972     uint32_t key_idx, const std::vector<uint8_t> &wep_key)
973 {
974 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
975 	if (key_idx >=
976 	    static_cast<uint32_t>(
977 		ISupplicantStaNetwork::ParamSizeLimits::WEP_KEYS_MAX_NUM)) {
978 		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
979 	}
980 	if (wep_key.size() !=
981 		static_cast<uint32_t>(ISupplicantStaNetwork::ParamSizeLimits::
982 					  WEP40_KEY_LEN_IN_BYTES) &&
983 	    wep_key.size() !=
984 		static_cast<uint32_t>(ISupplicantStaNetwork::ParamSizeLimits::
985 					  WEP104_KEY_LEN_IN_BYTES)) {
986 		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
987 	}
988 	os_memcpy(wpa_ssid->wep_key[key_idx], wep_key.data(), wep_key.size());
989 	wpa_ssid->wep_key_len[key_idx] = wep_key.size();
990 	std::string msg_dump_title("wep_key" + std::to_string(key_idx));
991 	wpa_hexdump_key(
992 	    MSG_MSGDUMP, msg_dump_title.c_str(), wpa_ssid->wep_key[key_idx],
993 	    wpa_ssid->wep_key_len[key_idx]);
994 	resetInternalStateAfterParamsUpdate();
995 	return {SupplicantStatusCode::SUCCESS, ""};
996 }
997 
setWepTxKeyIdxInternal(uint32_t key_idx)998 SupplicantStatus StaNetwork::setWepTxKeyIdxInternal(uint32_t key_idx)
999 {
1000 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1001 	if (key_idx >=
1002 	    static_cast<uint32_t>(
1003 		ISupplicantStaNetwork::ParamSizeLimits::WEP_KEYS_MAX_NUM)) {
1004 		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
1005 	}
1006 	wpa_ssid->wep_tx_keyidx = key_idx;
1007 	resetInternalStateAfterParamsUpdate();
1008 	return {SupplicantStatusCode::SUCCESS, ""};
1009 }
1010 
setRequirePmfInternal(bool enable)1011 SupplicantStatus StaNetwork::setRequirePmfInternal(bool enable)
1012 {
1013 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1014 	wpa_ssid->ieee80211w =
1015 	    enable ? MGMT_FRAME_PROTECTION_REQUIRED : NO_MGMT_FRAME_PROTECTION;
1016 	resetInternalStateAfterParamsUpdate();
1017 	return {SupplicantStatusCode::SUCCESS, ""};
1018 }
1019 
setEapMethodInternal(ISupplicantStaNetwork::EapMethod method)1020 SupplicantStatus StaNetwork::setEapMethodInternal(
1021     ISupplicantStaNetwork::EapMethod method)
1022 {
1023 	uint32_t eap_method_idx = static_cast<
1024 	    std::underlying_type<ISupplicantStaNetwork::EapMethod>::type>(
1025 	    method);
1026 	if (eap_method_idx >= kEapMethodMax) {
1027 		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
1028 	}
1029 
1030 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1031 	int retrieved_vendor, retrieved_method;
1032 	const char *method_str = kEapMethodStrings[eap_method_idx];
1033 	// This string lookup is needed to check if the device supports the
1034 	// corresponding EAP type.
1035 	retrieved_method = eap_peer_get_type(method_str, &retrieved_vendor);
1036 	if (retrieved_vendor == EAP_VENDOR_IETF &&
1037 	    retrieved_method == EAP_TYPE_NONE) {
1038 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1039 	}
1040 	if (wpa_ssid->eap.eap_methods) {
1041 		os_free(wpa_ssid->eap.eap_methods);
1042 	}
1043 	// wpa_supplicant can support setting multiple eap methods for each
1044 	// network. But, this is not really used by Android. So, just adding
1045 	// support for setting one EAP method for each network. The additional
1046 	// |eap_method_type| member in the array is used to indicate the end
1047 	// of list.
1048 	wpa_ssid->eap.eap_methods =
1049 	    (eap_method_type *)os_malloc(sizeof(eap_method_type) * 2);
1050 	if (!wpa_ssid->eap.eap_methods) {
1051 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1052 	}
1053 	wpa_ssid->eap.eap_methods[0].vendor = retrieved_vendor;
1054 	wpa_ssid->eap.eap_methods[0].method = retrieved_method;
1055 	wpa_ssid->eap.eap_methods[1].vendor = EAP_VENDOR_IETF;
1056 	wpa_ssid->eap.eap_methods[1].method = EAP_TYPE_NONE;
1057 
1058 	wpa_ssid->leap = 0;
1059 	wpa_ssid->non_leap = 0;
1060 	if (retrieved_vendor == EAP_VENDOR_IETF &&
1061 	    retrieved_method == EAP_TYPE_LEAP) {
1062 		wpa_ssid->leap++;
1063 	} else {
1064 		wpa_ssid->non_leap++;
1065 	}
1066 	wpa_hexdump(
1067 	    MSG_MSGDUMP, "eap methods", (u8 *)wpa_ssid->eap.eap_methods,
1068 	    sizeof(eap_method_type) * 2);
1069 	resetInternalStateAfterParamsUpdate();
1070 	return {SupplicantStatusCode::SUCCESS, ""};
1071 }
1072 
setEapPhase2MethodInternal(ISupplicantStaNetwork::EapPhase2Method method)1073 SupplicantStatus StaNetwork::setEapPhase2MethodInternal(
1074     ISupplicantStaNetwork::EapPhase2Method method)
1075 {
1076 	uint32_t eap_phase2_method_idx = static_cast<
1077 	    std::underlying_type<ISupplicantStaNetwork::EapPhase2Method>::type>(
1078 	    method);
1079 	if (eap_phase2_method_idx >= kEapPhase2MethodMax) {
1080 		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
1081 	}
1082 
1083 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1084 	// EAP method needs to be set for us to construct the eap
1085 	// phase 2 method string.
1086 	SupplicantStatus status;
1087 	ISupplicantStaNetwork::EapMethod eap_method;
1088 	std::tie(status, eap_method) = getEapMethodInternal();
1089 	if (status.code != SupplicantStatusCode::SUCCESS) {
1090 		return {SupplicantStatusCode::FAILURE_UNKNOWN,
1091 			"EAP method not set"};
1092 	}
1093 	std::string eap_phase2_str;
1094 	if (method == ISupplicantStaNetwork::EapPhase2Method::NONE) {
1095 		eap_phase2_str = "";
1096 	} else if (
1097 	    eap_method == ISupplicantStaNetwork::EapMethod::TTLS &&
1098 	    method == ISupplicantStaNetwork::EapPhase2Method::GTC) {
1099 		eap_phase2_str = kEapPhase2AuthEapPrefix;
1100 	} else {
1101 		eap_phase2_str = kEapPhase2AuthPrefix;
1102 	}
1103 	eap_phase2_str += kEapPhase2MethodStrings[eap_phase2_method_idx];
1104 	if (setStringFieldAndResetState(
1105 		eap_phase2_str.c_str(), &(wpa_ssid->eap.phase2),
1106 		"eap phase2")) {
1107 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1108 	}
1109 	return {SupplicantStatusCode::SUCCESS, ""};
1110 }
1111 
setEapIdentityInternal(const std::vector<uint8_t> & identity)1112 SupplicantStatus StaNetwork::setEapIdentityInternal(
1113     const std::vector<uint8_t> &identity)
1114 {
1115 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1116 	if (setByteArrayFieldAndResetState(
1117 		identity.data(), identity.size(), &(wpa_ssid->eap.identity),
1118 		&(wpa_ssid->eap.identity_len), "eap identity")) {
1119 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1120 	}
1121 	// plain IMSI identity
1122 	if (setByteArrayFieldAndResetState(
1123 		identity.data(), identity.size(),
1124 		&(wpa_ssid->eap.imsi_identity),
1125 		&(wpa_ssid->eap.imsi_identity_len), "eap imsi identity")) {
1126 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1127 	}
1128 	return {SupplicantStatusCode::SUCCESS, ""};
1129 }
1130 
setEapEncryptedImsiIdentityInternal(const std::vector<uint8_t> & identity)1131 SupplicantStatus StaNetwork::setEapEncryptedImsiIdentityInternal(
1132     const std::vector<uint8_t> &identity)
1133 {
1134 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1135 	// encrypted IMSI identity
1136 	if (setByteArrayFieldAndResetState(
1137 		identity.data(), identity.size(), &(wpa_ssid->eap.identity),
1138 		&(wpa_ssid->eap.identity_len), "eap encrypted imsi identity")) {
1139 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1140 	}
1141 	return {SupplicantStatusCode::SUCCESS, ""};
1142 }
1143 
setEapAnonymousIdentityInternal(const std::vector<uint8_t> & identity)1144 SupplicantStatus StaNetwork::setEapAnonymousIdentityInternal(
1145     const std::vector<uint8_t> &identity)
1146 {
1147 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1148 	if (setByteArrayFieldAndResetState(
1149 		identity.data(), identity.size(),
1150 		&(wpa_ssid->eap.anonymous_identity),
1151 		&(wpa_ssid->eap.anonymous_identity_len),
1152 		"eap anonymous_identity")) {
1153 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1154 	}
1155 	return {SupplicantStatusCode::SUCCESS, ""};
1156 }
1157 
setEapPasswordInternal(const std::vector<uint8_t> & password)1158 SupplicantStatus StaNetwork::setEapPasswordInternal(
1159     const std::vector<uint8_t> &password)
1160 {
1161 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1162 	if (setByteArrayKeyFieldAndResetState(
1163 		password.data(), password.size(), &(wpa_ssid->eap.password),
1164 		&(wpa_ssid->eap.password_len), "eap password")) {
1165 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1166 	}
1167 	wpa_ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1168 	wpa_ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
1169 	return {SupplicantStatusCode::SUCCESS, ""};
1170 }
1171 
setEapCACertInternal(const std::string & path)1172 SupplicantStatus StaNetwork::setEapCACertInternal(const std::string &path)
1173 {
1174 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1175 	if (setStringFieldAndResetState(
1176 		path.c_str(), &(wpa_ssid->eap.ca_cert), "eap ca_cert")) {
1177 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1178 	}
1179 	return {SupplicantStatusCode::SUCCESS, ""};
1180 }
1181 
setEapCAPathInternal(const std::string & path)1182 SupplicantStatus StaNetwork::setEapCAPathInternal(const std::string &path)
1183 {
1184 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1185 	if (setStringFieldAndResetState(
1186 		path.c_str(), &(wpa_ssid->eap.ca_path), "eap ca_path")) {
1187 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1188 	}
1189 	return {SupplicantStatusCode::SUCCESS, ""};
1190 }
1191 
setEapClientCertInternal(const std::string & path)1192 SupplicantStatus StaNetwork::setEapClientCertInternal(const std::string &path)
1193 {
1194 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1195 	if (setStringFieldAndResetState(
1196 		path.c_str(), &(wpa_ssid->eap.client_cert),
1197 		"eap client_cert")) {
1198 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1199 	}
1200 	return {SupplicantStatusCode::SUCCESS, ""};
1201 }
1202 
setEapPrivateKeyIdInternal(const std::string & id)1203 SupplicantStatus StaNetwork::setEapPrivateKeyIdInternal(const std::string &id)
1204 {
1205 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1206 	if (setStringFieldAndResetState(
1207 		id.c_str(), &(wpa_ssid->eap.key_id), "eap key_id")) {
1208 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1209 	}
1210 	return {SupplicantStatusCode::SUCCESS, ""};
1211 }
1212 
setEapSubjectMatchInternal(const std::string & match)1213 SupplicantStatus StaNetwork::setEapSubjectMatchInternal(
1214     const std::string &match)
1215 {
1216 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1217 	if (setStringFieldAndResetState(
1218 		match.c_str(), &(wpa_ssid->eap.subject_match),
1219 		"eap subject_match")) {
1220 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1221 	}
1222 	return {SupplicantStatusCode::SUCCESS, ""};
1223 }
1224 
setEapAltSubjectMatchInternal(const std::string & match)1225 SupplicantStatus StaNetwork::setEapAltSubjectMatchInternal(
1226     const std::string &match)
1227 {
1228 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1229 	if (setStringFieldAndResetState(
1230 		match.c_str(), &(wpa_ssid->eap.altsubject_match),
1231 		"eap altsubject_match")) {
1232 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1233 	}
1234 	return {SupplicantStatusCode::SUCCESS, ""};
1235 }
1236 
setEapEngineInternal(bool enable)1237 SupplicantStatus StaNetwork::setEapEngineInternal(bool enable)
1238 {
1239 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1240 	wpa_ssid->eap.engine = enable ? 1 : 0;
1241 	return {SupplicantStatusCode::SUCCESS, ""};
1242 }
1243 
setEapEngineIDInternal(const std::string & id)1244 SupplicantStatus StaNetwork::setEapEngineIDInternal(const std::string &id)
1245 {
1246 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1247 	if (setStringFieldAndResetState(
1248 		id.c_str(), &(wpa_ssid->eap.engine_id), "eap engine_id")) {
1249 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1250 	}
1251 	return {SupplicantStatusCode::SUCCESS, ""};
1252 }
1253 
setEapDomainSuffixMatchInternal(const std::string & match)1254 SupplicantStatus StaNetwork::setEapDomainSuffixMatchInternal(
1255     const std::string &match)
1256 {
1257 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1258 	if (setStringFieldAndResetState(
1259 		match.c_str(), &(wpa_ssid->eap.domain_suffix_match),
1260 		"eap domain_suffix_match")) {
1261 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1262 	}
1263 	return {SupplicantStatusCode::SUCCESS, ""};
1264 }
1265 
setProactiveKeyCachingInternal(bool enable)1266 SupplicantStatus StaNetwork::setProactiveKeyCachingInternal(bool enable)
1267 {
1268 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1269 	wpa_ssid->proactive_key_caching = enable ? 1 : 0;
1270 	resetInternalStateAfterParamsUpdate();
1271 	return {SupplicantStatusCode::SUCCESS, ""};
1272 }
1273 
setIdStrInternal(const std::string & id_str)1274 SupplicantStatus StaNetwork::setIdStrInternal(const std::string &id_str)
1275 {
1276 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1277 	if (setStringFieldAndResetState(
1278 		id_str.c_str(), &(wpa_ssid->id_str), "id_str")) {
1279 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1280 	}
1281 	return {SupplicantStatusCode::SUCCESS, ""};
1282 }
1283 
setUpdateIdentifierInternal(uint32_t id)1284 SupplicantStatus StaNetwork::setUpdateIdentifierInternal(uint32_t id)
1285 {
1286 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1287 	wpa_ssid->update_identifier = id;
1288 	wpa_printf(
1289 	    MSG_MSGDUMP, "update_identifier: %d", wpa_ssid->update_identifier);
1290 	resetInternalStateAfterParamsUpdate();
1291 	return {SupplicantStatusCode::SUCCESS, ""};
1292 }
1293 
getSsidInternal()1294 std::pair<SupplicantStatus, std::vector<uint8_t>> StaNetwork::getSsidInternal()
1295 {
1296 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1297 	std::vector<uint8_t> ssid;
1298 	ssid.assign(wpa_ssid->ssid, wpa_ssid->ssid + wpa_ssid->ssid_len);
1299 	return {{SupplicantStatusCode::SUCCESS, ""}, std::move(ssid)};
1300 }
1301 
1302 std::pair<SupplicantStatus, std::array<uint8_t, 6>>
getBssidInternal()1303 StaNetwork::getBssidInternal()
1304 {
1305 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1306 	std::array<uint8_t, 6> bssid{};
1307 	os_memcpy(bssid.data(), kZeroBssid, ETH_ALEN);
1308 	if (wpa_ssid->bssid_set) {
1309 		os_memcpy(bssid.data(), wpa_ssid->bssid, ETH_ALEN);
1310 	}
1311 	return {{SupplicantStatusCode::SUCCESS, ""}, std::move(bssid)};
1312 }
1313 
getScanSsidInternal()1314 std::pair<SupplicantStatus, bool> StaNetwork::getScanSsidInternal()
1315 {
1316 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1317 	return {{SupplicantStatusCode::SUCCESS, ""},
1318 		(wpa_ssid->scan_ssid == 1)};
1319 }
1320 
getKeyMgmtInternal()1321 std::pair<SupplicantStatus, uint32_t> StaNetwork::getKeyMgmtInternal()
1322 {
1323 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1324 	uint32_t key_mgmt_mask = wpa_ssid->key_mgmt & kAllowedKeyMgmtMask;
1325 
1326 	resetFastTransitionKeyMgmt(key_mgmt_mask);
1327 	return {{SupplicantStatusCode::SUCCESS, ""}, key_mgmt_mask};
1328 }
1329 
getProtoInternal()1330 std::pair<SupplicantStatus, uint32_t> StaNetwork::getProtoInternal()
1331 {
1332 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1333 	return {{SupplicantStatusCode::SUCCESS, ""},
1334 		wpa_ssid->proto & kAllowedProtoMask};
1335 }
1336 
getAuthAlgInternal()1337 std::pair<SupplicantStatus, uint32_t> StaNetwork::getAuthAlgInternal()
1338 {
1339 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1340 	return {{SupplicantStatusCode::SUCCESS, ""},
1341 		wpa_ssid->auth_alg & kAllowedAuthAlgMask};
1342 }
1343 
getGroupCipherInternal()1344 std::pair<SupplicantStatus, uint32_t> StaNetwork::getGroupCipherInternal()
1345 {
1346 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1347 	return {{SupplicantStatusCode::SUCCESS, ""},
1348 		wpa_ssid->group_cipher & kAllowedGroupCipherMask};
1349 }
1350 
getPairwiseCipherInternal()1351 std::pair<SupplicantStatus, uint32_t> StaNetwork::getPairwiseCipherInternal()
1352 {
1353 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1354 	return {{SupplicantStatusCode::SUCCESS, ""},
1355 		wpa_ssid->pairwise_cipher & kAllowedPairwisewCipherMask};
1356 }
1357 
getPskPassphraseInternal()1358 std::pair<SupplicantStatus, std::string> StaNetwork::getPskPassphraseInternal()
1359 {
1360 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1361 	if (!wpa_ssid->passphrase) {
1362 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1363 	}
1364 	return {{SupplicantStatusCode::SUCCESS, ""}, wpa_ssid->passphrase};
1365 }
1366 
1367 std::pair<SupplicantStatus, std::array<uint8_t, 32>>
getPskInternal()1368 StaNetwork::getPskInternal()
1369 {
1370 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1371 	WPA_ASSERT(psk.size() == sizeof(wpa_ssid->psk));
1372 	if (!wpa_ssid->psk_set) {
1373 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1374 	}
1375 	std::array<uint8_t, 32> psk;
1376 	os_memcpy(psk.data(), wpa_ssid->psk, psk.size());
1377 	return {{SupplicantStatusCode::SUCCESS, ""}, psk};
1378 }
1379 
getSaePasswordInternal()1380 std::pair<SupplicantStatus, std::string> StaNetwork::getSaePasswordInternal()
1381 {
1382 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1383 	if (!wpa_ssid->sae_password) {
1384 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1385 	}
1386 	return {{SupplicantStatusCode::SUCCESS, ""}, wpa_ssid->sae_password};
1387 }
1388 
getSaePasswordIdInternal()1389 std::pair<SupplicantStatus, std::string> StaNetwork::getSaePasswordIdInternal()
1390 {
1391 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1392 	if (!wpa_ssid->sae_password_id) {
1393 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1394 	}
1395 	return {{SupplicantStatusCode::SUCCESS, ""}, wpa_ssid->sae_password_id};
1396 }
1397 
getWepKeyInternal(uint32_t key_idx)1398 std::pair<SupplicantStatus, std::vector<uint8_t>> StaNetwork::getWepKeyInternal(
1399     uint32_t key_idx)
1400 {
1401 	std::vector<uint8_t> wep_key;
1402 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1403 	if (key_idx >=
1404 	    static_cast<uint32_t>(
1405 		ISupplicantStaNetwork::ParamSizeLimits::WEP_KEYS_MAX_NUM)) {
1406 		return {{SupplicantStatusCode::FAILURE_ARGS_INVALID, ""},
1407 			wep_key};
1408 	}
1409 	wep_key.assign(
1410 	    wpa_ssid->wep_key[key_idx],
1411 	    wpa_ssid->wep_key[key_idx] + wpa_ssid->wep_key_len[key_idx]);
1412 	return {{SupplicantStatusCode::SUCCESS, ""}, std::move(wep_key)};
1413 }
1414 
getWepTxKeyIdxInternal()1415 std::pair<SupplicantStatus, uint32_t> StaNetwork::getWepTxKeyIdxInternal()
1416 {
1417 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1418 	return {{SupplicantStatusCode::SUCCESS, ""}, wpa_ssid->wep_tx_keyidx};
1419 }
1420 
getRequirePmfInternal()1421 std::pair<SupplicantStatus, bool> StaNetwork::getRequirePmfInternal()
1422 {
1423 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1424 	return {{SupplicantStatusCode::SUCCESS, ""},
1425 		(wpa_ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED)};
1426 }
1427 
1428 std::pair<SupplicantStatus, ISupplicantStaNetwork::EapMethod>
getEapMethodInternal()1429 StaNetwork::getEapMethodInternal()
1430 {
1431 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1432 	if (!wpa_ssid->eap.eap_methods) {
1433 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1434 	}
1435 	// wpa_supplicant can support setting multiple eap methods for each
1436 	// network. But, this is not really used by Android. So, just reading
1437 	// the first EAP method for each network.
1438 	const std::string eap_method_str = eap_get_name(
1439 	    wpa_ssid->eap.eap_methods[0].vendor,
1440 	    static_cast<EapType>(wpa_ssid->eap.eap_methods[0].method));
1441 	size_t eap_method_idx =
1442 	    std::find(
1443 		std::begin(kEapMethodStrings), std::end(kEapMethodStrings),
1444 		eap_method_str) -
1445 	    std::begin(kEapMethodStrings);
1446 	if (eap_method_idx >= kEapMethodMax) {
1447 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1448 	}
1449 	return {{SupplicantStatusCode::SUCCESS, ""},
1450 		static_cast<ISupplicantStaNetwork::EapMethod>(eap_method_idx)};
1451 }
1452 
1453 std::pair<SupplicantStatus, ISupplicantStaNetwork::EapPhase2Method>
getEapPhase2MethodInternal()1454 StaNetwork::getEapPhase2MethodInternal()
1455 {
1456 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1457 	if (!wpa_ssid->eap.phase2) {
1458 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1459 	}
1460 	const std::string eap_phase2_method_str_with_prefix =
1461 	    wpa_ssid->eap.phase2;
1462 	std::string eap_phase2_method_str;
1463 	// Strip out the phase 2 method prefix before doing a reverse lookup
1464 	// of phase 2 string to the Eap Phase 2 type.
1465 	if (eap_phase2_method_str_with_prefix.find(kEapPhase2AuthPrefix) == 0) {
1466 		eap_phase2_method_str =
1467 		    eap_phase2_method_str_with_prefix.substr(
1468 			strlen(kEapPhase2AuthPrefix),
1469 			eap_phase2_method_str_with_prefix.size());
1470 	} else if (
1471 	    eap_phase2_method_str_with_prefix.find(kEapPhase2AuthEapPrefix) ==
1472 	    0) {
1473 		eap_phase2_method_str =
1474 		    eap_phase2_method_str_with_prefix.substr(
1475 			strlen(kEapPhase2AuthEapPrefix),
1476 			eap_phase2_method_str_with_prefix.size());
1477 	}
1478 	size_t eap_phase2_method_idx =
1479 	    std::find(
1480 		std::begin(kEapPhase2MethodStrings),
1481 		std::end(kEapPhase2MethodStrings), eap_phase2_method_str) -
1482 	    std::begin(kEapPhase2MethodStrings);
1483 	if (eap_phase2_method_idx >= kEapPhase2MethodMax) {
1484 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1485 	}
1486 	return {{SupplicantStatusCode::SUCCESS, ""},
1487 		static_cast<ISupplicantStaNetwork::EapPhase2Method>(
1488 		    eap_phase2_method_idx)};
1489 }
1490 
1491 std::pair<SupplicantStatus, std::vector<uint8_t>>
getEapIdentityInternal()1492 StaNetwork::getEapIdentityInternal()
1493 {
1494 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1495 	if (!wpa_ssid->eap.identity) {
1496 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1497 	}
1498 	return {{SupplicantStatusCode::SUCCESS, ""},
1499 		std::vector<uint8_t>(
1500 		    wpa_ssid->eap.identity,
1501 		    wpa_ssid->eap.identity + wpa_ssid->eap.identity_len)};
1502 }
1503 
1504 std::pair<SupplicantStatus, std::vector<uint8_t>>
getEapAnonymousIdentityInternal()1505 StaNetwork::getEapAnonymousIdentityInternal()
1506 {
1507 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1508 	if (!wpa_ssid->eap.anonymous_identity) {
1509 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1510 	}
1511 	return {{SupplicantStatusCode::SUCCESS, ""},
1512 		std::vector<uint8_t>(
1513 		    wpa_ssid->eap.anonymous_identity,
1514 		    wpa_ssid->eap.anonymous_identity +
1515 			wpa_ssid->eap.anonymous_identity_len)};
1516 }
1517 
1518 std::pair<SupplicantStatus, std::vector<uint8_t>>
getEapPasswordInternal()1519 StaNetwork::getEapPasswordInternal()
1520 {
1521 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1522 	if (!wpa_ssid->eap.password) {
1523 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1524 	}
1525 	return {{SupplicantStatusCode::SUCCESS, ""},
1526 		std::vector<uint8_t>(
1527 		    wpa_ssid->eap.password,
1528 		    wpa_ssid->eap.password + wpa_ssid->eap.password_len)};
1529 }
1530 
getEapCACertInternal()1531 std::pair<SupplicantStatus, std::string> StaNetwork::getEapCACertInternal()
1532 {
1533 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1534 	if (!wpa_ssid->eap.ca_cert) {
1535 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1536 	}
1537 	return {{SupplicantStatusCode::SUCCESS, ""},
1538 		reinterpret_cast<char *>(wpa_ssid->eap.ca_cert)};
1539 }
1540 
getEapCAPathInternal()1541 std::pair<SupplicantStatus, std::string> StaNetwork::getEapCAPathInternal()
1542 {
1543 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1544 	if (!wpa_ssid->eap.ca_path) {
1545 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1546 	}
1547 	return {{SupplicantStatusCode::SUCCESS, ""},
1548 		reinterpret_cast<char *>(wpa_ssid->eap.ca_path)};
1549 }
1550 
getEapClientCertInternal()1551 std::pair<SupplicantStatus, std::string> StaNetwork::getEapClientCertInternal()
1552 {
1553 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1554 	if (!wpa_ssid->eap.client_cert) {
1555 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1556 	}
1557 	return {{SupplicantStatusCode::SUCCESS, ""},
1558 		reinterpret_cast<char *>(wpa_ssid->eap.client_cert)};
1559 }
1560 
1561 std::pair<SupplicantStatus, std::string>
getEapPrivateKeyIdInternal()1562 StaNetwork::getEapPrivateKeyIdInternal()
1563 {
1564 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1565 	if (!wpa_ssid->eap.key_id) {
1566 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1567 	}
1568 	return {{SupplicantStatusCode::SUCCESS, ""}, wpa_ssid->eap.key_id};
1569 }
1570 
1571 std::pair<SupplicantStatus, std::string>
getEapSubjectMatchInternal()1572 StaNetwork::getEapSubjectMatchInternal()
1573 {
1574 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1575 	if (!wpa_ssid->eap.subject_match) {
1576 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1577 	}
1578 	return {{SupplicantStatusCode::SUCCESS, ""},
1579 		reinterpret_cast<char *>(wpa_ssid->eap.subject_match)};
1580 }
1581 
1582 std::pair<SupplicantStatus, std::string>
getEapAltSubjectMatchInternal()1583 StaNetwork::getEapAltSubjectMatchInternal()
1584 {
1585 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1586 	if (!wpa_ssid->eap.altsubject_match) {
1587 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1588 	}
1589 	return {{SupplicantStatusCode::SUCCESS, ""},
1590 		reinterpret_cast<char *>(wpa_ssid->eap.altsubject_match)};
1591 }
1592 
getEapEngineInternal()1593 std::pair<SupplicantStatus, bool> StaNetwork::getEapEngineInternal()
1594 {
1595 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1596 	return {{SupplicantStatusCode::SUCCESS, ""}, wpa_ssid->eap.engine == 1};
1597 }
1598 
getEapEngineIDInternal()1599 std::pair<SupplicantStatus, std::string> StaNetwork::getEapEngineIDInternal()
1600 {
1601 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1602 	if (!wpa_ssid->eap.engine_id) {
1603 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1604 	}
1605 	return {{SupplicantStatusCode::SUCCESS, ""}, {wpa_ssid->eap.engine_id}};
1606 }
1607 
1608 std::pair<SupplicantStatus, std::string>
getEapDomainSuffixMatchInternal()1609 StaNetwork::getEapDomainSuffixMatchInternal()
1610 {
1611 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1612 	if (!wpa_ssid->eap.domain_suffix_match) {
1613 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1614 	}
1615 	return {{SupplicantStatusCode::SUCCESS, ""},
1616 		{wpa_ssid->eap.domain_suffix_match}};
1617 }
1618 
getIdStrInternal()1619 std::pair<SupplicantStatus, std::string> StaNetwork::getIdStrInternal()
1620 {
1621 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1622 	if (!wpa_ssid->id_str) {
1623 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1624 	}
1625 	return {{SupplicantStatusCode::SUCCESS, ""}, {wpa_ssid->id_str}};
1626 }
1627 
1628 std::pair<SupplicantStatus, std::vector<uint8_t>>
getWpsNfcConfigurationTokenInternal()1629 StaNetwork::getWpsNfcConfigurationTokenInternal()
1630 {
1631 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1632 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1633 	auto token_buf = misc_utils::createWpaBufUniquePtr(
1634 	    wpas_wps_network_config_token(wpa_s, 0, wpa_ssid));
1635 	if (!token_buf) {
1636 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
1637 	}
1638 	return {{SupplicantStatusCode::SUCCESS, ""},
1639 		misc_utils::convertWpaBufToVector(token_buf.get())};
1640 }
1641 
enableInternal(bool no_connect)1642 SupplicantStatus StaNetwork::enableInternal(bool no_connect)
1643 {
1644 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1645 	if (wpa_ssid->disabled == 2) {
1646 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1647 	}
1648 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1649 	if (no_connect) {
1650 		wpa_ssid->disabled = 0;
1651 	} else {
1652 		wpa_s->scan_min_time.sec = 0;
1653 		wpa_s->scan_min_time.usec = 0;
1654 		wpa_supplicant_enable_network(wpa_s, wpa_ssid);
1655 	}
1656 	return {SupplicantStatusCode::SUCCESS, ""};
1657 }
1658 
disableInternal()1659 SupplicantStatus StaNetwork::disableInternal()
1660 {
1661 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1662 	if (wpa_ssid->disabled == 2) {
1663 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1664 	}
1665 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1666 	wpa_supplicant_disable_network(wpa_s, wpa_ssid);
1667 	return {SupplicantStatusCode::SUCCESS, ""};
1668 }
1669 
selectInternal()1670 SupplicantStatus StaNetwork::selectInternal()
1671 {
1672 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1673 	if (wpa_ssid->disabled == 2) {
1674 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1675 	}
1676 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1677 	wpa_s->scan_min_time.sec = 0;
1678 	wpa_s->scan_min_time.usec = 0;
1679 	// Make sure that the supplicant is updated to the latest
1680 	// MAC address, which might have changed due to MAC randomization.
1681 	wpa_supplicant_update_mac_addr(wpa_s);
1682 	wpa_supplicant_select_network(wpa_s, wpa_ssid);
1683 	return {SupplicantStatusCode::SUCCESS, ""};
1684 }
1685 
sendNetworkEapSimGsmAuthResponseInternal(const std::vector<ISupplicantStaNetwork::NetworkResponseEapSimGsmAuthParams> & vec_params)1686 SupplicantStatus StaNetwork::sendNetworkEapSimGsmAuthResponseInternal(
1687     const std::vector<ISupplicantStaNetwork::NetworkResponseEapSimGsmAuthParams>
1688 	&vec_params)
1689 {
1690 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1691 	// Convert the incoming parameters to a string to pass to
1692 	// wpa_supplicant.
1693 	std::string ctrl_rsp_param = std::string(kNetworkEapSimGsmAuthResponse);
1694 	for (const auto &params : vec_params) {
1695 		uint32_t kc_hex_len = params.kc.size() * 2 + 1;
1696 		std::vector<char> kc_hex(kc_hex_len);
1697 		uint32_t sres_hex_len = params.sres.size() * 2 + 1;
1698 		std::vector<char> sres_hex(sres_hex_len);
1699 		wpa_snprintf_hex(
1700 		    kc_hex.data(), kc_hex.size(), params.kc.data(),
1701 		    params.kc.size());
1702 		wpa_snprintf_hex(
1703 		    sres_hex.data(), sres_hex.size(), params.sres.data(),
1704 		    params.sres.size());
1705 		ctrl_rsp_param += ":" + std::string(kc_hex.data()) + ":" +
1706 				  std::string(sres_hex.data());
1707 	}
1708 	enum wpa_ctrl_req_type rtype = WPA_CTRL_REQ_SIM;
1709 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1710 	if (wpa_supplicant_ctrl_rsp_handle(
1711 		wpa_s, wpa_ssid, rtype, ctrl_rsp_param.c_str(),
1712 		ctrl_rsp_param.size())) {
1713 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1714 	}
1715 	eapol_sm_notify_ctrl_response(wpa_s->eapol);
1716 	wpa_hexdump_ascii_key(
1717 	    MSG_DEBUG, "network sim gsm auth response param",
1718 	    (const u8 *)ctrl_rsp_param.c_str(), ctrl_rsp_param.size());
1719 	return {SupplicantStatusCode::SUCCESS, ""};
1720 }
1721 
sendNetworkEapSimGsmAuthFailureInternal()1722 SupplicantStatus StaNetwork::sendNetworkEapSimGsmAuthFailureInternal()
1723 {
1724 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1725 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1726 	enum wpa_ctrl_req_type rtype = WPA_CTRL_REQ_SIM;
1727 	if (wpa_supplicant_ctrl_rsp_handle(
1728 		wpa_s, wpa_ssid, rtype, kNetworkEapSimGsmAuthFailure,
1729 		strlen(kNetworkEapSimGsmAuthFailure))) {
1730 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1731 	}
1732 	eapol_sm_notify_ctrl_response(wpa_s->eapol);
1733 	return {SupplicantStatusCode::SUCCESS, ""};
1734 }
1735 
sendNetworkEapSimUmtsAuthResponseInternal(const ISupplicantStaNetwork::NetworkResponseEapSimUmtsAuthParams & params)1736 SupplicantStatus StaNetwork::sendNetworkEapSimUmtsAuthResponseInternal(
1737     const ISupplicantStaNetwork::NetworkResponseEapSimUmtsAuthParams &params)
1738 {
1739 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1740 	// Convert the incoming parameters to a string to pass to
1741 	// wpa_supplicant.
1742 	uint32_t ik_hex_len = params.ik.size() * 2 + 1;
1743 	std::vector<char> ik_hex(ik_hex_len);
1744 	uint32_t ck_hex_len = params.ck.size() * 2 + 1;
1745 	std::vector<char> ck_hex(ck_hex_len);
1746 	uint32_t res_hex_len = params.res.size() * 2 + 1;
1747 	std::vector<char> res_hex(res_hex_len);
1748 	wpa_snprintf_hex(
1749 	    ik_hex.data(), ik_hex.size(), params.ik.data(), params.ik.size());
1750 	wpa_snprintf_hex(
1751 	    ck_hex.data(), ck_hex.size(), params.ck.data(), params.ck.size());
1752 	wpa_snprintf_hex(
1753 	    res_hex.data(), res_hex.size(), params.res.data(),
1754 	    params.res.size());
1755 	std::string ctrl_rsp_param =
1756 	    std::string(kNetworkEapSimUmtsAuthResponse) + ":" +
1757 	    std::string(ik_hex.data()) + ":" + std::string(ck_hex.data()) +
1758 	    ":" + std::string(res_hex.data());
1759 	enum wpa_ctrl_req_type rtype = WPA_CTRL_REQ_SIM;
1760 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1761 	if (wpa_supplicant_ctrl_rsp_handle(
1762 		wpa_s, wpa_ssid, rtype, ctrl_rsp_param.c_str(),
1763 		ctrl_rsp_param.size())) {
1764 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1765 	}
1766 	eapol_sm_notify_ctrl_response(wpa_s->eapol);
1767 	wpa_hexdump_ascii_key(
1768 	    MSG_DEBUG, "network sim umts auth response param",
1769 	    (const u8 *)ctrl_rsp_param.c_str(), ctrl_rsp_param.size());
1770 	return {SupplicantStatusCode::SUCCESS, ""};
1771 }
1772 
sendNetworkEapSimUmtsAutsResponseInternal(const std::array<uint8_t,14> & auts)1773 SupplicantStatus StaNetwork::sendNetworkEapSimUmtsAutsResponseInternal(
1774     const std::array<uint8_t, 14> &auts)
1775 {
1776 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1777 	uint32_t auts_hex_len = auts.size() * 2 + 1;
1778 	std::vector<char> auts_hex(auts_hex_len);
1779 	wpa_snprintf_hex(
1780 	    auts_hex.data(), auts_hex.size(), auts.data(), auts.size());
1781 	std::string ctrl_rsp_param =
1782 	    std::string(kNetworkEapSimUmtsAutsResponse) + ":" +
1783 	    std::string(auts_hex.data());
1784 	enum wpa_ctrl_req_type rtype = WPA_CTRL_REQ_SIM;
1785 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1786 	if (wpa_supplicant_ctrl_rsp_handle(
1787 		wpa_s, wpa_ssid, rtype, ctrl_rsp_param.c_str(),
1788 		ctrl_rsp_param.size())) {
1789 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1790 	}
1791 	eapol_sm_notify_ctrl_response(wpa_s->eapol);
1792 	wpa_hexdump_ascii_key(
1793 	    MSG_DEBUG, "network sim umts auts response param",
1794 	    (const u8 *)ctrl_rsp_param.c_str(), ctrl_rsp_param.size());
1795 	return {SupplicantStatusCode::SUCCESS, ""};
1796 }
1797 
sendNetworkEapSimUmtsAuthFailureInternal()1798 SupplicantStatus StaNetwork::sendNetworkEapSimUmtsAuthFailureInternal()
1799 {
1800 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1801 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1802 	enum wpa_ctrl_req_type rtype = WPA_CTRL_REQ_SIM;
1803 	if (wpa_supplicant_ctrl_rsp_handle(
1804 		wpa_s, wpa_ssid, rtype, kNetworkEapSimUmtsAuthFailure,
1805 		strlen(kNetworkEapSimUmtsAuthFailure))) {
1806 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1807 	}
1808 	eapol_sm_notify_ctrl_response(wpa_s->eapol);
1809 	return {SupplicantStatusCode::SUCCESS, ""};
1810 }
1811 
sendNetworkEapIdentityResponseInternal(const std::vector<uint8_t> & identity)1812 SupplicantStatus StaNetwork::sendNetworkEapIdentityResponseInternal(
1813     const std::vector<uint8_t> &identity)
1814 {
1815 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1816 	std::string ctrl_rsp_param(identity.begin(), identity.end());
1817 	enum wpa_ctrl_req_type rtype = WPA_CTRL_REQ_EAP_IDENTITY;
1818 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1819 	if (wpa_supplicant_ctrl_rsp_handle(
1820 		wpa_s, wpa_ssid, rtype, ctrl_rsp_param.c_str(),
1821 		ctrl_rsp_param.size())) {
1822 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1823 	}
1824 	eapol_sm_notify_ctrl_response(wpa_s->eapol);
1825 	wpa_hexdump_ascii_key(
1826 	    MSG_DEBUG, "network identity response param",
1827 	    (const u8 *)ctrl_rsp_param.c_str(), ctrl_rsp_param.size());
1828 	return {SupplicantStatusCode::SUCCESS, ""};
1829 }
1830 
sendNetworkEapIdentityResponseInternal_1_1(const std::vector<uint8_t> & identity,const std::vector<uint8_t> & encrypted_imsi_identity)1831 SupplicantStatus StaNetwork::sendNetworkEapIdentityResponseInternal_1_1(
1832     const std::vector<uint8_t> &identity,
1833     const std::vector<uint8_t> &encrypted_imsi_identity)
1834 {
1835 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1836 	// format: plain identity + ":" + encrypted
1837 	// identity(encrypted_imsi_identity)
1838 	std::string ctrl_rsp_param =
1839 	    std::string(identity.begin(), identity.end()) + ":" +
1840 	    std::string(
1841 		encrypted_imsi_identity.begin(), encrypted_imsi_identity.end());
1842 	enum wpa_ctrl_req_type rtype = WPA_CTRL_REQ_EAP_IDENTITY;
1843 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1844 	if (wpa_supplicant_ctrl_rsp_handle(
1845 		wpa_s, wpa_ssid, rtype, ctrl_rsp_param.c_str(),
1846 		ctrl_rsp_param.size())) {
1847 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1848 	}
1849 	eapol_sm_notify_ctrl_response(wpa_s->eapol);
1850 	wpa_hexdump_ascii_key(
1851 	    MSG_DEBUG, "network identity response param",
1852 	    (const u8 *)ctrl_rsp_param.c_str(), ctrl_rsp_param.size());
1853 	return {SupplicantStatusCode::SUCCESS, ""};
1854 }
1855 
enableTlsSuiteBEapPhase1ParamInternal(bool enable)1856 SupplicantStatus StaNetwork::enableTlsSuiteBEapPhase1ParamInternal(bool enable)
1857 {
1858 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1859 	int val = enable == true ? 1 : 0;
1860 	std::string suiteb_phase1("tls_suiteb=" + std::to_string(val));
1861 
1862 	if (setStringKeyFieldAndResetState(
1863 		suiteb_phase1.c_str(), &(wpa_ssid->eap.phase1), "phase1")) {
1864 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1865 	}
1866 	return {SupplicantStatusCode::SUCCESS, ""};
1867 }
1868 
enableSuiteBEapOpenSslCiphersInternal()1869 SupplicantStatus StaNetwork::enableSuiteBEapOpenSslCiphersInternal()
1870 {
1871 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1872 	const char openssl_suiteb_cipher[] = "SUITEB192";
1873 
1874 	if (setStringKeyFieldAndResetState(
1875 		openssl_suiteb_cipher, &(wpa_ssid->eap.openssl_ciphers),
1876 		"openssl_ciphers")) {
1877 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1878 	}
1879 	return {SupplicantStatusCode::SUCCESS, ""};
1880 }
1881 
setSaePasswordInternal(const std::string & sae_password)1882 SupplicantStatus StaNetwork::setSaePasswordInternal(
1883     const std::string &sae_password)
1884 {
1885 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1886 	if (sae_password.length() < 1) {
1887 		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
1888 	}
1889 	if (wpa_ssid->sae_password &&
1890 	    os_strlen(wpa_ssid->sae_password) == sae_password.length() &&
1891 	    os_memcmp(
1892 		wpa_ssid->sae_password, sae_password.c_str(),
1893 		sae_password.length()) == 0) {
1894 		return {SupplicantStatusCode::SUCCESS, ""};
1895 	}
1896 	wpa_ssid->psk_set = 1;
1897 	if (setStringKeyFieldAndResetState(
1898 		sae_password.c_str(), &(wpa_ssid->sae_password),
1899 		"sae password")) {
1900 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1901 	}
1902 	return {SupplicantStatusCode::SUCCESS, ""};
1903 }
1904 
setSaePasswordIdInternal(const std::string & sae_password_id)1905 SupplicantStatus StaNetwork::setSaePasswordIdInternal(
1906     const std::string &sae_password_id)
1907 {
1908 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1909 	if (sae_password_id.length() < 1) {
1910 		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
1911 	}
1912 	if (wpa_ssid->sae_password_id &&
1913 	    os_strlen(wpa_ssid->sae_password_id) == sae_password_id.length() &&
1914 	    os_memcmp(
1915 		wpa_ssid->sae_password_id, sae_password_id.c_str(),
1916 		sae_password_id.length()) == 0) {
1917 		return {SupplicantStatusCode::SUCCESS, ""};
1918 	}
1919 	wpa_ssid->psk_set = 1;
1920 	if (setStringKeyFieldAndResetState(
1921 		sae_password_id.c_str(), &(wpa_ssid->sae_password_id),
1922 		"sae password id")) {
1923 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
1924 	}
1925 	return {SupplicantStatusCode::SUCCESS, ""};
1926 }
1927 
setGroupMgmtCipherInternal(uint32_t group_mgmt_cipher_mask)1928 SupplicantStatus StaNetwork::setGroupMgmtCipherInternal(uint32_t
1929 		group_mgmt_cipher_mask)
1930 {
1931 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1932 	if (group_mgmt_cipher_mask & ~kAllowedGroupMgmtCipherMask) {
1933 		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
1934 	}
1935 	wpa_ssid->group_mgmt_cipher = group_mgmt_cipher_mask;
1936 	wpa_printf(MSG_MSGDUMP, "group_mgmt_cipher: 0x%x",
1937 			wpa_ssid->group_mgmt_cipher);
1938 	resetInternalStateAfterParamsUpdate();
1939 	return {SupplicantStatusCode::SUCCESS, ""};
1940 }
1941 
getGroupMgmtCipherInternal()1942 std::pair<SupplicantStatus, uint32_t> StaNetwork::getGroupMgmtCipherInternal()
1943 {
1944 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1945 	return {{SupplicantStatusCode::SUCCESS, ""},
1946 		wpa_ssid->group_mgmt_cipher & kAllowedGroupMgmtCipherMask};
1947 }
1948 
1949 /**
1950  * Retrieve the underlying |wpa_ssid| struct pointer for
1951  * this network.
1952  * If the underlying network is removed or the interface
1953  * this network belong to
1954  * is removed, all RPC method calls on this object will
1955  * return failure.
1956  */
retrieveNetworkPtr()1957 struct wpa_ssid *StaNetwork::retrieveNetworkPtr()
1958 {
1959 	wpa_supplicant *wpa_s = retrieveIfacePtr();
1960 	if (!wpa_s)
1961 		return nullptr;
1962 	return wpa_config_get_network(wpa_s->conf, network_id_);
1963 }
1964 
1965 /**
1966  * Retrieve the underlying |wpa_supplicant| struct
1967  * pointer for
1968  * this network.
1969  */
retrieveIfacePtr()1970 struct wpa_supplicant *StaNetwork::retrieveIfacePtr()
1971 {
1972 	return wpa_supplicant_get_iface(wpa_global_, ifname_.c_str());
1973 }
1974 
1975 /**
1976  * Check if the provided psk passhrase is valid or not.
1977  *
1978  * Returns 0 if valid, 1 otherwise.
1979  */
isPskPassphraseValid(const std::string & psk)1980 int StaNetwork::isPskPassphraseValid(const std::string &psk)
1981 {
1982 	if (psk.size() <
1983 		static_cast<uint32_t>(ISupplicantStaNetwork::ParamSizeLimits::
1984 					  PSK_PASSPHRASE_MIN_LEN_IN_BYTES) ||
1985 	    psk.size() >
1986 		static_cast<uint32_t>(ISupplicantStaNetwork::ParamSizeLimits::
1987 					  PSK_PASSPHRASE_MAX_LEN_IN_BYTES)) {
1988 		return 1;
1989 	}
1990 	if (has_ctrl_char((u8 *)psk.c_str(), psk.size())) {
1991 		return 1;
1992 	}
1993 	return 0;
1994 }
1995 
1996 /**
1997  * Reset internal wpa_supplicant state machine state
1998  * after params update (except
1999  * bssid).
2000  */
resetInternalStateAfterParamsUpdate()2001 void StaNetwork::resetInternalStateAfterParamsUpdate()
2002 {
2003 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
2004 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2005 
2006 	wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_ssid);
2007 
2008 	if (wpa_s->current_ssid == wpa_ssid || wpa_s->current_ssid == NULL) {
2009 		/*
2010 		 * Invalidate the EAP session cache if
2011 		 * anything in the
2012 		 * current or previously used
2013 		 * configuration changes.
2014 		 */
2015 		eapol_sm_invalidate_cached_session(wpa_s->eapol);
2016 	}
2017 }
2018 
2019 /**
2020  * Helper function to set value in a string field in |wpa_ssid| structue
2021  * instance for this network.
2022  * This function frees any existing data in these fields.
2023  */
setStringFieldAndResetState(const char * value,uint8_t ** to_update_field,const char * hexdump_prefix)2024 int StaNetwork::setStringFieldAndResetState(
2025     const char *value, uint8_t **to_update_field, const char *hexdump_prefix)
2026 {
2027 	return setStringFieldAndResetState(
2028 	    value, (char **)to_update_field, hexdump_prefix);
2029 }
2030 
2031 /**
2032  * Helper function to set value in a string field in |wpa_ssid| structue
2033  * instance for this network.
2034  * This function frees any existing data in these fields.
2035  */
setStringFieldAndResetState(const char * value,char ** to_update_field,const char * hexdump_prefix)2036 int StaNetwork::setStringFieldAndResetState(
2037     const char *value, char **to_update_field, const char *hexdump_prefix)
2038 {
2039 	int value_len = strlen(value);
2040 	if (*to_update_field) {
2041 		os_free(*to_update_field);
2042 	}
2043 	*to_update_field = dup_binstr(value, value_len);
2044 	if (!(*to_update_field)) {
2045 		return 1;
2046 	}
2047 	wpa_hexdump_ascii(
2048 	    MSG_MSGDUMP, hexdump_prefix, *to_update_field, value_len);
2049 	resetInternalStateAfterParamsUpdate();
2050 	return 0;
2051 }
2052 
2053 /**
2054  * Helper function to set value in a string key field in |wpa_ssid| structue
2055  * instance for this network.
2056  * This function frees any existing data in these fields.
2057  */
setStringKeyFieldAndResetState(const char * value,char ** to_update_field,const char * hexdump_prefix)2058 int StaNetwork::setStringKeyFieldAndResetState(
2059     const char *value, char **to_update_field, const char *hexdump_prefix)
2060 {
2061 	int value_len = strlen(value);
2062 	if (*to_update_field) {
2063 		str_clear_free(*to_update_field);
2064 	}
2065 	*to_update_field = dup_binstr(value, value_len);
2066 	if (!(*to_update_field)) {
2067 		return 1;
2068 	}
2069 	wpa_hexdump_ascii_key(
2070 	    MSG_MSGDUMP, hexdump_prefix, *to_update_field, value_len);
2071 	resetInternalStateAfterParamsUpdate();
2072 	return 0;
2073 }
2074 
2075 /**
2076  * Helper function to set value in a string field with a corresponding length
2077  * field in |wpa_ssid| structue instance for this network.
2078  * This function frees any existing data in these fields.
2079  */
setByteArrayFieldAndResetState(const uint8_t * value,const size_t value_len,uint8_t ** to_update_field,size_t * to_update_field_len,const char * hexdump_prefix)2080 int StaNetwork::setByteArrayFieldAndResetState(
2081     const uint8_t *value, const size_t value_len, uint8_t **to_update_field,
2082     size_t *to_update_field_len, const char *hexdump_prefix)
2083 {
2084 	if (*to_update_field) {
2085 		os_free(*to_update_field);
2086 	}
2087 	*to_update_field = (uint8_t *)os_malloc(value_len);
2088 	if (!(*to_update_field)) {
2089 		return 1;
2090 	}
2091 	os_memcpy(*to_update_field, value, value_len);
2092 	*to_update_field_len = value_len;
2093 
2094 	wpa_hexdump_ascii(
2095 	    MSG_MSGDUMP, hexdump_prefix, *to_update_field,
2096 	    *to_update_field_len);
2097 	resetInternalStateAfterParamsUpdate();
2098 	return 0;
2099 }
2100 
2101 /**
2102  * Helper function to set value in a string key field with a corresponding
2103  * length field in |wpa_ssid| structue instance for this network.
2104  * This function frees any existing data in these fields.
2105  */
setByteArrayKeyFieldAndResetState(const uint8_t * value,const size_t value_len,uint8_t ** to_update_field,size_t * to_update_field_len,const char * hexdump_prefix)2106 int StaNetwork::setByteArrayKeyFieldAndResetState(
2107     const uint8_t *value, const size_t value_len, uint8_t **to_update_field,
2108     size_t *to_update_field_len, const char *hexdump_prefix)
2109 {
2110 	if (*to_update_field) {
2111 		bin_clear_free(*to_update_field, *to_update_field_len);
2112 	}
2113 	*to_update_field = (uint8_t *)os_malloc(value_len);
2114 	if (!(*to_update_field)) {
2115 		return 1;
2116 	}
2117 	os_memcpy(*to_update_field, value, value_len);
2118 	*to_update_field_len = value_len;
2119 
2120 	wpa_hexdump_ascii_key(
2121 	    MSG_MSGDUMP, hexdump_prefix, *to_update_field,
2122 	    *to_update_field_len);
2123 	resetInternalStateAfterParamsUpdate();
2124 	return 0;
2125 }
2126 
2127 /**
2128  * Helper function to set the fast transition bits in the key management
2129  * bitmask, to allow FT support when possible.
2130  */
setFastTransitionKeyMgmt(uint32_t & key_mgmt_mask)2131 void StaNetwork::setFastTransitionKeyMgmt(uint32_t &key_mgmt_mask)
2132 {
2133 	if (key_mgmt_mask & WPA_KEY_MGMT_SAE) {
2134 		key_mgmt_mask |= WPA_KEY_MGMT_FT_SAE;
2135 	}
2136 
2137 	if (key_mgmt_mask & WPA_KEY_MGMT_PSK) {
2138 		key_mgmt_mask |= WPA_KEY_MGMT_FT_PSK;
2139 	}
2140 
2141 	if (key_mgmt_mask & WPA_KEY_MGMT_IEEE8021X) {
2142 		key_mgmt_mask |= WPA_KEY_MGMT_FT_IEEE8021X;
2143 	}
2144 }
2145 
2146 /**
2147  * Helper function to reset the fast transition bits in the key management
2148  * bitmask.
2149  */
resetFastTransitionKeyMgmt(uint32_t & key_mgmt_mask)2150 void StaNetwork::resetFastTransitionKeyMgmt(uint32_t &key_mgmt_mask)
2151 {
2152 	if (key_mgmt_mask & WPA_KEY_MGMT_SAE) {
2153 		key_mgmt_mask &= ~WPA_KEY_MGMT_FT_SAE;
2154 	}
2155 
2156 	if (key_mgmt_mask & WPA_KEY_MGMT_PSK) {
2157 		key_mgmt_mask &= ~WPA_KEY_MGMT_FT_PSK;
2158 	}
2159 
2160 	if (key_mgmt_mask & WPA_KEY_MGMT_IEEE8021X) {
2161 		key_mgmt_mask &= ~WPA_KEY_MGMT_FT_IEEE8021X;
2162 	}
2163 }
2164 }  // namespace implementation
2165 }  // namespace V1_2
2166 }  // namespace supplicant
2167 }  // namespace wifi
2168 }  // namespace hardware
2169 }  // namespace android
2170