1 /*
2 * WPA Supplicant - Sta network Aidl interface
3 * Copyright (c) 2021, Google Inc. All rights reserved.
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9 #include "aidl_manager.h"
10 #include "aidl_return_util.h"
11 #include "misc_utils.h"
12 #include "sta_network.h"
13
14 extern "C"
15 {
16 #include "wps_supplicant.h"
17 }
18
19 namespace {
20 using aidl::android::hardware::wifi::supplicant::AuthAlgMask;
21 using aidl::android::hardware::wifi::supplicant::EapMethod;
22 using aidl::android::hardware::wifi::supplicant::EapPhase2Method;
23 using aidl::android::hardware::wifi::supplicant::GroupCipherMask;
24 using aidl::android::hardware::wifi::supplicant::GroupMgmtCipherMask;
25 using aidl::android::hardware::wifi::supplicant::ISupplicantStaNetwork;
26 using aidl::android::hardware::wifi::supplicant::KeyMgmtMask;
27 using aidl::android::hardware::wifi::supplicant::PairwiseCipherMask;
28 using aidl::android::hardware::wifi::supplicant::ProtoMask;
29
30 constexpr uint8_t kZeroBssid[6] = {0, 0, 0, 0, 0, 0};
31
32 constexpr uint32_t kAllowedKeyMgmtMask =
33 (static_cast<uint32_t>(KeyMgmtMask::NONE) |
34 static_cast<uint32_t>(KeyMgmtMask::WPA_PSK) |
35 static_cast<uint32_t>(KeyMgmtMask::WPA_EAP) |
36 static_cast<uint32_t>(KeyMgmtMask::IEEE8021X) |
37 static_cast<uint32_t>(KeyMgmtMask::FT_EAP) |
38 static_cast<uint32_t>(KeyMgmtMask::FT_PSK) |
39 static_cast<uint32_t>(KeyMgmtMask::OSEN) |
40 static_cast<uint32_t>(KeyMgmtMask::SAE) |
41 static_cast<uint32_t>(KeyMgmtMask::SUITE_B_192) |
42 static_cast<uint32_t>(KeyMgmtMask::OWE) |
43 static_cast<uint32_t>(KeyMgmtMask::WPA_PSK_SHA256) |
44 static_cast<uint32_t>(KeyMgmtMask::WPA_EAP_SHA256) |
45 static_cast<uint32_t>(KeyMgmtMask::WAPI_PSK) |
46 static_cast<uint32_t>(KeyMgmtMask::WAPI_CERT) |
47 static_cast<uint32_t>(KeyMgmtMask::FILS_SHA256) |
48 static_cast<uint32_t>(KeyMgmtMask::FILS_SHA384) |
49 static_cast<uint32_t>(KeyMgmtMask::DPP));
50 constexpr uint32_t kAllowedProtoMask =
51 (static_cast<uint32_t>(ProtoMask::WPA) |
52 static_cast<uint32_t>(ProtoMask::RSN) |
53 static_cast<uint32_t>(ProtoMask::OSEN) |
54 static_cast<uint32_t>(ProtoMask::WAPI));
55 constexpr uint32_t kAllowedAuthAlgMask =
56 (static_cast<uint32_t>(AuthAlgMask::OPEN) |
57 static_cast<uint32_t>(AuthAlgMask::SHARED) |
58 static_cast<uint32_t>(AuthAlgMask::LEAP) |
59 static_cast<uint32_t>(AuthAlgMask::SAE));
60 constexpr uint32_t kAllowedGroupCipherMask =
61 (static_cast<uint32_t>(GroupCipherMask::WEP40) |
62 static_cast<uint32_t>(GroupCipherMask::WEP104) |
63 static_cast<uint32_t>(GroupCipherMask::TKIP) |
64 static_cast<uint32_t>(GroupCipherMask::CCMP) |
65 static_cast<uint32_t>(
66 GroupCipherMask::GTK_NOT_USED) |
67 static_cast<uint32_t>(GroupCipherMask::GCMP_256) |
68 static_cast<uint32_t>(GroupCipherMask::SMS4) |
69 static_cast<uint32_t>(GroupCipherMask::GCMP_128));
70 constexpr uint32_t kAllowedPairwisewCipherMask =
71 (static_cast<uint32_t>(PairwiseCipherMask::NONE) |
72 static_cast<uint32_t>(PairwiseCipherMask::TKIP) |
73 static_cast<uint32_t>(PairwiseCipherMask::CCMP) |
74 static_cast<uint32_t>(
75 PairwiseCipherMask::GCMP_256) |
76 static_cast<uint32_t>(
77 PairwiseCipherMask::SMS4) |
78 static_cast<uint32_t>(PairwiseCipherMask::GCMP_128));
79 constexpr uint32_t kAllowedGroupMgmtCipherMask =
80 (static_cast<uint32_t>(
81 GroupMgmtCipherMask::BIP_GMAC_128) |
82 static_cast<uint32_t>(
83 GroupMgmtCipherMask::BIP_GMAC_256) |
84 static_cast<uint32_t>(
85 GroupMgmtCipherMask::BIP_CMAC_256));
86
87 constexpr uint32_t kEapMethodMax =
88 static_cast<uint32_t>(EapMethod::WFA_UNAUTH_TLS) + 1;
89 constexpr char const *kEapMethodStrings[kEapMethodMax] = {
90 "PEAP", "TLS", "TTLS", "PWD", "SIM", "AKA", "AKA'", "WFA-UNAUTH-TLS"};
91 constexpr uint32_t kEapPhase2MethodMax =
92 static_cast<uint32_t>(EapPhase2Method::AKA_PRIME) + 1;
93 constexpr char const *kEapPhase2MethodStrings[kEapPhase2MethodMax] = {
94 "", "PAP", "MSCHAP", "MSCHAPV2", "GTC", "SIM", "AKA", "AKA'"};
95 constexpr char kEapPhase2AuthPrefix[] = "auth=";
96 constexpr char kEapPhase2AuthEapPrefix[] = "autheap=";
97 constexpr char kNetworkEapSimGsmAuthResponse[] = "GSM-AUTH";
98 constexpr char kNetworkEapSimUmtsAuthResponse[] = "UMTS-AUTH";
99 constexpr char kNetworkEapSimUmtsAutsResponse[] = "UMTS-AUTS";
100 constexpr char kNetworkEapSimGsmAuthFailure[] = "GSM-FAIL";
101 constexpr char kNetworkEapSimUmtsAuthFailure[] = "UMTS-FAIL";
102
103 #ifdef CONFIG_WAPI_INTERFACE
104 std::string dummyWapiCertSuite;
105 std::vector<uint8_t> dummyWapiPsk;
106 #endif /* CONFIG_WAPI_INTERFACE */
107 } // namespace
108
109 namespace aidl {
110 namespace android {
111 namespace hardware {
112 namespace wifi {
113 namespace supplicant {
114 using aidl_return_util::validateAndCall;
115 using misc_utils::createStatus;
116 using misc_utils::createStatusWithMsg;
117
StaNetwork(struct wpa_global * wpa_global,const char ifname[],int network_id)118 StaNetwork::StaNetwork(
119 struct wpa_global *wpa_global, const char ifname[], int network_id)
120 : wpa_global_(wpa_global),
121 ifname_(ifname),
122 network_id_(network_id),
123 is_valid_(true)
124 {}
125
invalidate()126 void StaNetwork::invalidate() { is_valid_ = false; }
isValid()127 bool StaNetwork::isValid()
128 {
129 return (is_valid_ && (retrieveNetworkPtr() != nullptr));
130 }
131
getId(int32_t * _aidl_return)132 ::ndk::ScopedAStatus StaNetwork::getId(
133 int32_t* _aidl_return)
134 {
135 return validateAndCall(
136 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
137 &StaNetwork::getIdInternal, _aidl_return);
138 }
139
getInterfaceName(std::string * _aidl_return)140 ::ndk::ScopedAStatus StaNetwork::getInterfaceName(
141 std::string* _aidl_return)
142 {
143 return validateAndCall(
144 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
145 &StaNetwork::getInterfaceNameInternal, _aidl_return);
146 }
147
getType(IfaceType * _aidl_return)148 ::ndk::ScopedAStatus StaNetwork::getType(
149 IfaceType* _aidl_return)
150 {
151 return validateAndCall(
152 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
153 &StaNetwork::getTypeInternal, _aidl_return);
154 }
155
registerCallback(const std::shared_ptr<ISupplicantStaNetworkCallback> & in_callback)156 ::ndk::ScopedAStatus StaNetwork::registerCallback(
157 const std::shared_ptr<ISupplicantStaNetworkCallback>& in_callback)
158 {
159 return validateAndCall(
160 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
161 &StaNetwork::registerCallbackInternal, in_callback);
162 }
163
setSsid(const std::vector<uint8_t> & in_ssid)164 ::ndk::ScopedAStatus StaNetwork::setSsid(
165 const std::vector<uint8_t>& in_ssid)
166 {
167 return validateAndCall(
168 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
169 &StaNetwork::setSsidInternal, in_ssid);
170 }
171
setBssid(const std::vector<uint8_t> & in_bssid)172 ::ndk::ScopedAStatus StaNetwork::setBssid(
173 const std::vector<uint8_t>& in_bssid)
174 {
175 return validateAndCall(
176 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
177 &StaNetwork::setBssidInternal, in_bssid);
178 }
179
setDppKeys(const DppConnectionKeys & in_keys)180 ::ndk::ScopedAStatus StaNetwork::setDppKeys(const DppConnectionKeys& in_keys)
181 {
182 return validateAndCall(
183 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
184 &StaNetwork::setDppKeysInternal, in_keys);
185 }
186
setScanSsid(bool in_enable)187 ::ndk::ScopedAStatus StaNetwork::setScanSsid(bool in_enable)
188 {
189 return validateAndCall(
190 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
191 &StaNetwork::setScanSsidInternal, in_enable);
192 }
193
setKeyMgmt(KeyMgmtMask in_keyMgmtMask)194 ::ndk::ScopedAStatus StaNetwork::setKeyMgmt(
195 KeyMgmtMask in_keyMgmtMask)
196 {
197 return validateAndCall(
198 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
199 &StaNetwork::setKeyMgmtInternal, in_keyMgmtMask);
200 }
201
setProto(ProtoMask in_protoMask)202 ::ndk::ScopedAStatus StaNetwork::setProto(
203 ProtoMask in_protoMask)
204 {
205 return validateAndCall(
206 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
207 &StaNetwork::setProtoInternal, in_protoMask);
208 }
209
setAuthAlg(AuthAlgMask in_authAlgMask)210 ::ndk::ScopedAStatus StaNetwork::setAuthAlg(
211 AuthAlgMask in_authAlgMask)
212 {
213 return validateAndCall(
214 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
215 &StaNetwork::setAuthAlgInternal, in_authAlgMask);
216 }
217
setGroupCipher(GroupCipherMask in_groupCipherMask)218 ::ndk::ScopedAStatus StaNetwork::setGroupCipher(
219 GroupCipherMask in_groupCipherMask)
220 {
221 return validateAndCall(
222 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
223 &StaNetwork::setGroupCipherInternal, in_groupCipherMask);
224 }
225
setPairwiseCipher(PairwiseCipherMask in_pairwiseCipherMask)226 ::ndk::ScopedAStatus StaNetwork::setPairwiseCipher(
227 PairwiseCipherMask in_pairwiseCipherMask)
228 {
229 return validateAndCall(
230 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
231 &StaNetwork::setPairwiseCipherInternal,
232 in_pairwiseCipherMask);
233 }
234
setPskPassphrase(const std::string & in_psk)235 ::ndk::ScopedAStatus StaNetwork::setPskPassphrase(
236 const std::string& in_psk)
237 {
238 return validateAndCall(
239 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
240 &StaNetwork::setPskPassphraseInternal, in_psk);
241 }
242
setPsk(const std::vector<uint8_t> & in_psk)243 ::ndk::ScopedAStatus StaNetwork::setPsk(
244 const std::vector<uint8_t>& in_psk)
245 {
246 return validateAndCall(
247 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
248 &StaNetwork::setPskInternal, in_psk);
249 }
250
setWepKey(int32_t in_keyIdx,const std::vector<uint8_t> & in_wepKey)251 ::ndk::ScopedAStatus StaNetwork::setWepKey(
252 int32_t in_keyIdx, const std::vector<uint8_t>& in_wepKey)
253 {
254 return validateAndCall(
255 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
256 &StaNetwork::setWepKeyInternal, in_keyIdx, in_wepKey);
257 }
258
setWepTxKeyIdx(int32_t in_keyIdx)259 ::ndk::ScopedAStatus StaNetwork::setWepTxKeyIdx(
260 int32_t in_keyIdx)
261 {
262 return validateAndCall(
263 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
264 &StaNetwork::setWepTxKeyIdxInternal, in_keyIdx);
265 }
266
setRequirePmf(bool in_enable)267 ::ndk::ScopedAStatus StaNetwork::setRequirePmf(bool in_enable)
268 {
269 return validateAndCall(
270 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
271 &StaNetwork::setRequirePmfInternal, in_enable);
272 }
273
setEapMethod(EapMethod in_method)274 ::ndk::ScopedAStatus StaNetwork::setEapMethod(
275 EapMethod in_method)
276 {
277 return validateAndCall(
278 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
279 &StaNetwork::setEapMethodInternal, in_method);
280 }
281
setEapPhase2Method(EapPhase2Method in_method)282 ::ndk::ScopedAStatus StaNetwork::setEapPhase2Method(
283 EapPhase2Method in_method)
284 {
285 return validateAndCall(
286 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
287 &StaNetwork::setEapPhase2MethodInternal, in_method);
288 }
289
setEapIdentity(const std::vector<uint8_t> & in_identity)290 ::ndk::ScopedAStatus StaNetwork::setEapIdentity(
291 const std::vector<uint8_t>& in_identity)
292 {
293 return validateAndCall(
294 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
295 &StaNetwork::setEapIdentityInternal, in_identity);
296 }
297
setEapEncryptedImsiIdentity(const std::vector<uint8_t> & in_identity)298 ::ndk::ScopedAStatus StaNetwork::setEapEncryptedImsiIdentity(
299 const std::vector<uint8_t>& in_identity)
300 {
301 return validateAndCall(
302 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
303 &StaNetwork::setEapEncryptedImsiIdentityInternal,
304 in_identity);
305 }
306
setEapAnonymousIdentity(const std::vector<uint8_t> & in_identity)307 ::ndk::ScopedAStatus StaNetwork::setEapAnonymousIdentity(
308 const std::vector<uint8_t>& in_identity)
309 {
310 return validateAndCall(
311 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
312 &StaNetwork::setEapAnonymousIdentityInternal, in_identity);
313 }
314
setEapPassword(const std::vector<uint8_t> & in_password)315 ::ndk::ScopedAStatus StaNetwork::setEapPassword(
316 const std::vector<uint8_t>& in_password)
317 {
318 return validateAndCall(
319 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
320 &StaNetwork::setEapPasswordInternal, in_password);
321 }
322
setEapCACert(const std::string & in_path)323 ::ndk::ScopedAStatus StaNetwork::setEapCACert(
324 const std::string& in_path)
325 {
326 return validateAndCall(
327 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
328 &StaNetwork::setEapCACertInternal, in_path);
329 }
330
setEapCAPath(const std::string & in_path)331 ::ndk::ScopedAStatus StaNetwork::setEapCAPath(
332 const std::string& in_path)
333 {
334 return validateAndCall(
335 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
336 &StaNetwork::setEapCAPathInternal, in_path);
337 }
338
setEapClientCert(const std::string & in_path)339 ::ndk::ScopedAStatus StaNetwork::setEapClientCert(
340 const std::string& in_path)
341 {
342 return validateAndCall(
343 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
344 &StaNetwork::setEapClientCertInternal, in_path);
345 }
346
setEapPrivateKeyId(const std::string & in_id)347 ::ndk::ScopedAStatus StaNetwork::setEapPrivateKeyId(
348 const std::string& in_id)
349 {
350 return validateAndCall(
351 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
352 &StaNetwork::setEapPrivateKeyIdInternal, in_id);
353 }
354
setEapSubjectMatch(const std::string & in_match)355 ::ndk::ScopedAStatus StaNetwork::setEapSubjectMatch(
356 const std::string& in_match)
357 {
358 return validateAndCall(
359 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
360 &StaNetwork::setEapSubjectMatchInternal, in_match);
361 }
362
setEapAltSubjectMatch(const std::string & in_match)363 ::ndk::ScopedAStatus StaNetwork::setEapAltSubjectMatch(
364 const std::string& in_match)
365 {
366 return validateAndCall(
367 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
368 &StaNetwork::setEapAltSubjectMatchInternal, in_match);
369 }
370
setEapEngine(bool in_enable)371 ::ndk::ScopedAStatus StaNetwork::setEapEngine(bool in_enable)
372 {
373 return validateAndCall(
374 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
375 &StaNetwork::setEapEngineInternal, in_enable);
376 }
377
setEapEngineID(const std::string & in_id)378 ::ndk::ScopedAStatus StaNetwork::setEapEngineID(
379 const std::string& in_id)
380 {
381 return validateAndCall(
382 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
383 &StaNetwork::setEapEngineIDInternal, in_id);
384 }
385
setEapDomainSuffixMatch(const std::string & in_match)386 ::ndk::ScopedAStatus StaNetwork::setEapDomainSuffixMatch(
387 const std::string& in_match)
388 {
389 return validateAndCall(
390 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
391 &StaNetwork::setEapDomainSuffixMatchInternal, in_match);
392 }
393
setProactiveKeyCaching(bool in_enable)394 ::ndk::ScopedAStatus StaNetwork::setProactiveKeyCaching(
395 bool in_enable)
396 {
397 return validateAndCall(
398 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
399 &StaNetwork::setProactiveKeyCachingInternal, in_enable);
400 }
401
setIdStr(const std::string & in_idStr)402 ::ndk::ScopedAStatus StaNetwork::setIdStr(
403 const std::string& in_idStr)
404 {
405 return validateAndCall(
406 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
407 &StaNetwork::setIdStrInternal, in_idStr);
408 }
409
setUpdateIdentifier(int32_t in_id)410 ::ndk::ScopedAStatus StaNetwork::setUpdateIdentifier(
411 int32_t in_id)
412 {
413 return validateAndCall(
414 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
415 &StaNetwork::setUpdateIdentifierInternal, in_id);
416 }
417
setWapiCertSuite(const std::string & in_suite)418 ::ndk::ScopedAStatus StaNetwork::setWapiCertSuite(
419 const std::string& in_suite)
420 {
421 return validateAndCall(
422 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
423 &StaNetwork::setWapiCertSuiteInternal, in_suite);
424 }
425
setEdmg(bool in_enable)426 ::ndk::ScopedAStatus StaNetwork::setEdmg(bool in_enable)
427 {
428 return validateAndCall(
429 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
430 &StaNetwork::setEdmgInternal, in_enable);
431 }
432
getSsid(std::vector<uint8_t> * _aidl_return)433 ::ndk::ScopedAStatus StaNetwork::getSsid(
434 std::vector<uint8_t>* _aidl_return)
435 {
436 return validateAndCall(
437 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
438 &StaNetwork::getSsidInternal, _aidl_return);
439 }
440
getBssid(std::vector<uint8_t> * _aidl_return)441 ndk::ScopedAStatus StaNetwork::getBssid(
442 std::vector<uint8_t>* _aidl_return)
443 {
444 return validateAndCall(
445 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
446 &StaNetwork::getBssidInternal, _aidl_return);
447 }
448
getScanSsid(bool * _aidl_return)449 ::ndk::ScopedAStatus StaNetwork::getScanSsid(
450 bool* _aidl_return)
451 {
452 return validateAndCall(
453 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
454 &StaNetwork::getScanSsidInternal, _aidl_return);
455 }
456
getKeyMgmt(KeyMgmtMask * _aidl_return)457 ::ndk::ScopedAStatus StaNetwork::getKeyMgmt(
458 KeyMgmtMask* _aidl_return)
459 {
460 return validateAndCall(
461 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
462 &StaNetwork::getKeyMgmtInternal, _aidl_return);
463 }
464
getProto(ProtoMask * _aidl_return)465 ::ndk::ScopedAStatus StaNetwork::getProto(
466 ProtoMask* _aidl_return)
467 {
468 return validateAndCall(
469 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
470 &StaNetwork::getProtoInternal, _aidl_return);
471 }
472
getAuthAlg(AuthAlgMask * _aidl_return)473 ::ndk::ScopedAStatus StaNetwork::getAuthAlg(
474 AuthAlgMask* _aidl_return)
475 {
476 return validateAndCall(
477 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
478 &StaNetwork::getAuthAlgInternal, _aidl_return);
479 }
480
getGroupCipher(GroupCipherMask * _aidl_return)481 ::ndk::ScopedAStatus StaNetwork::getGroupCipher(
482 GroupCipherMask* _aidl_return)
483 {
484 return validateAndCall(
485 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
486 &StaNetwork::getGroupCipherInternal, _aidl_return);
487 }
488
getPairwiseCipher(PairwiseCipherMask * _aidl_return)489 ::ndk::ScopedAStatus StaNetwork::getPairwiseCipher(
490 PairwiseCipherMask* _aidl_return)
491 {
492 return validateAndCall(
493 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
494 &StaNetwork::getPairwiseCipherInternal, _aidl_return);
495 }
496
getPskPassphrase(std::string * _aidl_return)497 ::ndk::ScopedAStatus StaNetwork::getPskPassphrase(
498 std::string* _aidl_return)
499 {
500 return validateAndCall(
501 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
502 &StaNetwork::getPskPassphraseInternal, _aidl_return);
503 }
504
getPsk(std::vector<uint8_t> * _aidl_return)505 ::ndk::ScopedAStatus StaNetwork::getPsk(
506 std::vector<uint8_t>* _aidl_return)
507 {
508 return validateAndCall(
509 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
510 &StaNetwork::getPskInternal, _aidl_return);
511 }
512
getSaePassword(std::string * _aidl_return)513 ::ndk::ScopedAStatus StaNetwork::getSaePassword(
514 std::string* _aidl_return)
515 {
516 return validateAndCall(
517 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
518 &StaNetwork::getSaePasswordInternal, _aidl_return);
519 }
520
getSaePasswordId(std::string * _aidl_return)521 ::ndk::ScopedAStatus StaNetwork::getSaePasswordId(
522 std::string* _aidl_return)
523 {
524 return validateAndCall(
525 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
526 &StaNetwork::getSaePasswordIdInternal, _aidl_return);
527 }
528
getWepKey(int32_t in_keyIdx,std::vector<uint8_t> * _aidl_return)529 ::ndk::ScopedAStatus StaNetwork::getWepKey(
530 int32_t in_keyIdx,
531 std::vector<uint8_t>* _aidl_return)
532 {
533 return validateAndCall(
534 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
535 &StaNetwork::getWepKeyInternal, _aidl_return, in_keyIdx);
536 }
537
getWepTxKeyIdx(int32_t * _aidl_return)538 ::ndk::ScopedAStatus StaNetwork::getWepTxKeyIdx(
539 int32_t* _aidl_return)
540 {
541 return validateAndCall(
542 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
543 &StaNetwork::getWepTxKeyIdxInternal, _aidl_return);
544 }
545
getRequirePmf(bool * _aidl_return)546 ::ndk::ScopedAStatus StaNetwork::getRequirePmf(
547 bool* _aidl_return)
548 {
549 return validateAndCall(
550 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
551 &StaNetwork::getRequirePmfInternal, _aidl_return);
552 }
553
getEapMethod(EapMethod * _aidl_return)554 ::ndk::ScopedAStatus StaNetwork::getEapMethod(
555 EapMethod* _aidl_return)
556 {
557 return validateAndCall(
558 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
559 &StaNetwork::getEapMethodInternal, _aidl_return);
560 }
561
getEapPhase2Method(EapPhase2Method * _aidl_return)562 ::ndk::ScopedAStatus StaNetwork::getEapPhase2Method(
563 EapPhase2Method* _aidl_return)
564 {
565 return validateAndCall(
566 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
567 &StaNetwork::getEapPhase2MethodInternal, _aidl_return);
568 }
569
getEapIdentity(std::vector<uint8_t> * _aidl_return)570 ::ndk::ScopedAStatus StaNetwork::getEapIdentity(
571 std::vector<uint8_t>* _aidl_return)
572 {
573 return validateAndCall(
574 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
575 &StaNetwork::getEapIdentityInternal, _aidl_return);
576 }
577
getEapAnonymousIdentity(std::vector<uint8_t> * _aidl_return)578 ::ndk::ScopedAStatus StaNetwork::getEapAnonymousIdentity(
579 std::vector<uint8_t>* _aidl_return)
580 {
581 return validateAndCall(
582 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
583 &StaNetwork::getEapAnonymousIdentityInternal, _aidl_return);
584 }
585
getEapPassword(std::vector<uint8_t> * _aidl_return)586 ::ndk::ScopedAStatus StaNetwork::getEapPassword(
587 std::vector<uint8_t>* _aidl_return)
588 {
589 return validateAndCall(
590 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
591 &StaNetwork::getEapPasswordInternal, _aidl_return);
592 }
593
getEapCACert(std::string * _aidl_return)594 ::ndk::ScopedAStatus StaNetwork::getEapCACert(
595 std::string* _aidl_return)
596 {
597 return validateAndCall(
598 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
599 &StaNetwork::getEapCACertInternal, _aidl_return);
600 }
601
getEapCAPath(std::string * _aidl_return)602 ::ndk::ScopedAStatus StaNetwork::getEapCAPath(
603 std::string* _aidl_return)
604 {
605 return validateAndCall(
606 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
607 &StaNetwork::getEapCAPathInternal, _aidl_return);
608 }
609
getEapClientCert(std::string * _aidl_return)610 ::ndk::ScopedAStatus StaNetwork::getEapClientCert(
611 std::string* _aidl_return)
612 {
613 return validateAndCall(
614 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
615 &StaNetwork::getEapClientCertInternal, _aidl_return);
616 }
617
getEapPrivateKeyId(std::string * _aidl_return)618 ::ndk::ScopedAStatus StaNetwork::getEapPrivateKeyId(
619 std::string* _aidl_return)
620 {
621 return validateAndCall(
622 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
623 &StaNetwork::getEapPrivateKeyIdInternal, _aidl_return);
624 }
625
getEapSubjectMatch(std::string * _aidl_return)626 ::ndk::ScopedAStatus StaNetwork::getEapSubjectMatch(
627 std::string* _aidl_return)
628 {
629 return validateAndCall(
630 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
631 &StaNetwork::getEapSubjectMatchInternal, _aidl_return);
632 }
633
getEapAltSubjectMatch(std::string * _aidl_return)634 ::ndk::ScopedAStatus StaNetwork::getEapAltSubjectMatch(
635 std::string* _aidl_return)
636 {
637 return validateAndCall(
638 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
639 &StaNetwork::getEapAltSubjectMatchInternal, _aidl_return);
640 }
641
getEapEngine(bool * _aidl_return)642 ::ndk::ScopedAStatus StaNetwork::getEapEngine(
643 bool* _aidl_return)
644 {
645 return validateAndCall(
646 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
647 &StaNetwork::getEapEngineInternal, _aidl_return);
648 }
649
getEapEngineId(std::string * _aidl_return)650 ::ndk::ScopedAStatus StaNetwork::getEapEngineId(
651 std::string* _aidl_return)
652 {
653 return validateAndCall(
654 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
655 &StaNetwork::getEapEngineIdInternal, _aidl_return);
656 }
657
getEapDomainSuffixMatch(std::string * _aidl_return)658 ::ndk::ScopedAStatus StaNetwork::getEapDomainSuffixMatch(
659 std::string* _aidl_return)
660 {
661 return validateAndCall(
662 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
663 &StaNetwork::getEapDomainSuffixMatchInternal, _aidl_return);
664 }
665
getIdStr(std::string * _aidl_return)666 ::ndk::ScopedAStatus StaNetwork::getIdStr(
667 std::string* _aidl_return)
668 {
669 return validateAndCall(
670 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
671 &StaNetwork::getIdStrInternal, _aidl_return);
672 }
673
getWpsNfcConfigurationToken(std::vector<uint8_t> * _aidl_return)674 ::ndk::ScopedAStatus StaNetwork::getWpsNfcConfigurationToken(
675 std::vector<uint8_t>* _aidl_return)
676 {
677 return validateAndCall(
678 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
679 &StaNetwork::getWpsNfcConfigurationTokenInternal, _aidl_return);
680 }
681
getWapiCertSuite(std::string * _aidl_return)682 ::ndk::ScopedAStatus StaNetwork::getWapiCertSuite(
683 std::string* _aidl_return)
684 {
685 return validateAndCall(
686 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
687 &StaNetwork::getWapiCertSuiteInternal, _aidl_return);
688 }
689
getEdmg(bool * _aidl_return)690 ::ndk::ScopedAStatus StaNetwork::getEdmg(
691 bool* _aidl_return)
692 {
693 return validateAndCall(
694 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
695 &StaNetwork::getEdmgInternal, _aidl_return);
696 }
697
enable(bool in_noConnect)698 ::ndk::ScopedAStatus StaNetwork::enable(bool in_noConnect)
699 {
700 return validateAndCall(
701 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
702 &StaNetwork::enableInternal, in_noConnect);
703 }
704
disable()705 ::ndk::ScopedAStatus StaNetwork::disable()
706 {
707 return validateAndCall(
708 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
709 &StaNetwork::disableInternal);
710 }
711
select()712 ::ndk::ScopedAStatus StaNetwork::select()
713 {
714 return validateAndCall(
715 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
716 &StaNetwork::selectInternal);
717 }
718
sendNetworkEapSimGsmAuthResponse(const std::vector<NetworkResponseEapSimGsmAuthParams> & in_params)719 ::ndk::ScopedAStatus StaNetwork::sendNetworkEapSimGsmAuthResponse(
720 const std::vector<NetworkResponseEapSimGsmAuthParams>& in_params)
721 {
722 return validateAndCall(
723 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
724 &StaNetwork::sendNetworkEapSimGsmAuthResponseInternal,
725 in_params);
726 }
727
sendNetworkEapSimGsmAuthFailure()728 ::ndk::ScopedAStatus StaNetwork::sendNetworkEapSimGsmAuthFailure()
729 {
730 return validateAndCall(
731 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
732 &StaNetwork::sendNetworkEapSimGsmAuthFailureInternal);
733 }
734
sendNetworkEapSimUmtsAuthResponse(const NetworkResponseEapSimUmtsAuthParams & in_params)735 ::ndk::ScopedAStatus StaNetwork::sendNetworkEapSimUmtsAuthResponse(
736 const NetworkResponseEapSimUmtsAuthParams& in_params)
737 {
738 return validateAndCall(
739 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
740 &StaNetwork::sendNetworkEapSimUmtsAuthResponseInternal,
741 in_params);
742 }
743
sendNetworkEapSimUmtsAutsResponse(const std::vector<uint8_t> & in_auts)744 ::ndk::ScopedAStatus StaNetwork::sendNetworkEapSimUmtsAutsResponse(
745 const std::vector<uint8_t>& in_auts)
746 {
747 return validateAndCall(
748 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
749 &StaNetwork::sendNetworkEapSimUmtsAutsResponseInternal,
750 in_auts);
751 }
752
sendNetworkEapSimUmtsAuthFailure()753 ::ndk::ScopedAStatus StaNetwork::sendNetworkEapSimUmtsAuthFailure()
754 {
755 return validateAndCall(
756 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
757 &StaNetwork::sendNetworkEapSimUmtsAuthFailureInternal);
758 }
759
sendNetworkEapIdentityResponse(const std::vector<uint8_t> & in_identity,const std::vector<uint8_t> & in_encryptedIdentity)760 ::ndk::ScopedAStatus StaNetwork::sendNetworkEapIdentityResponse(
761 const std::vector<uint8_t>& in_identity,
762 const std::vector<uint8_t>& in_encryptedIdentity)
763 {
764 return validateAndCall(
765 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
766 &StaNetwork::sendNetworkEapIdentityResponseInternal,
767 in_identity, in_encryptedIdentity);
768 }
769
setGroupMgmtCipher(GroupMgmtCipherMask in_groupMgmtCipherMask)770 ::ndk::ScopedAStatus StaNetwork::setGroupMgmtCipher(
771 GroupMgmtCipherMask in_groupMgmtCipherMask)
772 {
773 return validateAndCall(
774 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
775 &StaNetwork::setGroupMgmtCipherInternal,
776 in_groupMgmtCipherMask);
777 }
778
getGroupMgmtCipher(GroupMgmtCipherMask * _aidl_return)779 ::ndk::ScopedAStatus StaNetwork::getGroupMgmtCipher(
780 GroupMgmtCipherMask* _aidl_return)
781 {
782 return validateAndCall(
783 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
784 &StaNetwork::getGroupMgmtCipherInternal, _aidl_return);
785 }
786
enableTlsSuiteBEapPhase1Param(bool in_enable)787 ::ndk::ScopedAStatus StaNetwork::enableTlsSuiteBEapPhase1Param(
788 bool in_enable)
789 {
790 return validateAndCall(
791 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
792 &StaNetwork::enableTlsSuiteBEapPhase1ParamInternal, in_enable);
793 }
794
enableSuiteBEapOpenSslCiphers()795 ::ndk::ScopedAStatus StaNetwork::enableSuiteBEapOpenSslCiphers()
796 {
797 return validateAndCall(
798 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
799 &StaNetwork::enableSuiteBEapOpenSslCiphersInternal);
800 }
801
setSaePassword(const std::string & in_saePassword)802 ::ndk::ScopedAStatus StaNetwork::setSaePassword(
803 const std::string& in_saePassword)
804 {
805 return validateAndCall(
806 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
807 &StaNetwork::setSaePasswordInternal, in_saePassword);
808 }
809
setSaePasswordId(const std::string & in_saePasswordId)810 ::ndk::ScopedAStatus StaNetwork::setSaePasswordId(
811 const std::string& in_saePasswordId)
812 {
813 return validateAndCall(
814 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
815 &StaNetwork::setSaePasswordIdInternal, in_saePasswordId);
816 }
817
setOcsp(OcspType in_ocspType)818 ::ndk::ScopedAStatus StaNetwork::setOcsp(
819 OcspType in_ocspType)
820 {
821 return validateAndCall(
822 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
823 &StaNetwork::setOcspInternal, in_ocspType);
824 }
825
getOcsp(OcspType * _aidl_return)826 ::ndk::ScopedAStatus StaNetwork::getOcsp(
827 OcspType* _aidl_return)
828 {
829 return validateAndCall(
830 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
831 &StaNetwork::getOcspInternal, _aidl_return);
832 }
833
setPmkCache(const std::vector<uint8_t> & in_serializedEntry)834 ::ndk::ScopedAStatus StaNetwork::setPmkCache(
835 const std::vector<uint8_t>& in_serializedEntry)
836 {
837 return validateAndCall(
838 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
839 &StaNetwork::setPmkCacheInternal, in_serializedEntry);
840 }
841
setEapErp(bool in_enable)842 ::ndk::ScopedAStatus StaNetwork::setEapErp(
843 bool in_enable)
844 {
845 return validateAndCall(
846 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
847 &StaNetwork::setEapErpInternal, in_enable);
848 }
849
setSaeH2eMode(SaeH2eMode in_mode)850 ::ndk::ScopedAStatus StaNetwork::setSaeH2eMode(
851 SaeH2eMode in_mode)
852 {
853 return validateAndCall(
854 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
855 &StaNetwork::setSaeH2eModeInternal, in_mode);
856 }
857
enableSaePkOnlyMode(bool in_enable)858 ::ndk::ScopedAStatus StaNetwork::enableSaePkOnlyMode(
859 bool in_enable)
860 {
861 return validateAndCall(
862 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
863 &StaNetwork::enableSaePkOnlyModeInternal, in_enable);
864 }
865
setRoamingConsortiumSelection(const std::vector<uint8_t> & in_selectedRcoi)866 ::ndk::ScopedAStatus StaNetwork::setRoamingConsortiumSelection(
867 const std::vector<uint8_t>& in_selectedRcoi)
868 {
869 return validateAndCall(
870 this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
871 &StaNetwork::setRoamingConsortiumSelectionInternal, in_selectedRcoi);
872 }
873
getIdInternal()874 std::pair<uint32_t, ndk::ScopedAStatus> StaNetwork::getIdInternal()
875 {
876 return {network_id_, ndk::ScopedAStatus::ok()};
877 }
878
getInterfaceNameInternal()879 std::pair<std::string, ndk::ScopedAStatus> StaNetwork::getInterfaceNameInternal()
880 {
881 return {ifname_, ndk::ScopedAStatus::ok()};
882 }
883
getTypeInternal()884 std::pair<IfaceType, ndk::ScopedAStatus> StaNetwork::getTypeInternal()
885 {
886 return {IfaceType::STA, ndk::ScopedAStatus::ok()};
887 }
888
registerCallbackInternal(const std::shared_ptr<ISupplicantStaNetworkCallback> & callback)889 ndk::ScopedAStatus StaNetwork::registerCallbackInternal(
890 const std::shared_ptr<ISupplicantStaNetworkCallback> &callback)
891 {
892 AidlManager *aidl_manager = AidlManager::getInstance();
893 if (!aidl_manager || aidl_manager->addStaNetworkCallbackAidlObject(
894 ifname_, network_id_, callback)) {
895 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
896 }
897 return ndk::ScopedAStatus::ok();
898 }
899
setSsidInternal(const std::vector<uint8_t> & ssid)900 ndk::ScopedAStatus StaNetwork::setSsidInternal(const std::vector<uint8_t> &ssid)
901 {
902 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
903 if (ssid.size() == 0 ||
904 ssid.size() >
905 static_cast<uint32_t>(ISupplicantStaNetwork::
906 SSID_MAX_LEN_IN_BYTES)) {
907 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
908 }
909 if (setByteArrayFieldAndResetState(
910 ssid.data(), ssid.size(), &(wpa_ssid->ssid),
911 &(wpa_ssid->ssid_len), "ssid")) {
912 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
913 }
914 if (wpa_ssid->passphrase) {
915 wpa_config_update_psk(wpa_ssid);
916 }
917 return ndk::ScopedAStatus::ok();
918 }
919
setBssidInternal(const std::vector<uint8_t> & bssid)920 ndk::ScopedAStatus StaNetwork::setBssidInternal(
921 const std::vector<uint8_t> &bssid)
922 {
923 if (bssid.size() != ETH_ALEN) {
924 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
925 }
926 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
927 int prev_bssid_set = wpa_ssid->bssid_set;
928 u8 prev_bssid[ETH_ALEN];
929 os_memcpy(prev_bssid, wpa_ssid->bssid, ETH_ALEN);
930 // Zero'ed array is used to clear out the BSSID value.
931 if (os_memcmp(bssid.data(), kZeroBssid, ETH_ALEN) == 0) {
932 wpa_ssid->bssid_set = 0;
933 wpa_printf(MSG_MSGDUMP, "BSSID any");
934 } else {
935 os_memcpy(wpa_ssid->bssid, bssid.data(), ETH_ALEN);
936 wpa_ssid->bssid_set = 1;
937 wpa_hexdump(MSG_MSGDUMP, "BSSID", wpa_ssid->bssid, ETH_ALEN);
938 }
939 struct wpa_supplicant *wpa_s = retrieveIfacePtr();
940 if ((wpa_ssid->bssid_set != prev_bssid_set ||
941 os_memcmp(wpa_ssid->bssid, prev_bssid, ETH_ALEN) != 0)) {
942 wpas_notify_network_bssid_set_changed(wpa_s, wpa_ssid);
943 }
944 return ndk::ScopedAStatus::ok();
945 }
946
setDppKeysInternal(const DppConnectionKeys & keys)947 ndk::ScopedAStatus StaNetwork::setDppKeysInternal(const DppConnectionKeys& keys)
948 {
949 #ifdef CONFIG_DPP
950 if (keys.connector.empty() || keys.cSign.empty() || keys.netAccessKey.empty()) {
951 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
952 }
953
954 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
955 std::string connector_str(keys.connector.begin(), keys.connector.end());
956
957 if (setStringFieldAndResetState(
958 connector_str.c_str(), &(wpa_ssid->dpp_connector), "dpp_connector")) {
959 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
960 }
961
962 if (setByteArrayFieldAndResetState(
963 keys.cSign.data(), keys.cSign.size(), &(wpa_ssid->dpp_csign),
964 &(wpa_ssid->dpp_csign_len), "dpp csign")) {
965 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
966 }
967
968 if (setByteArrayFieldAndResetState(
969 keys.netAccessKey.data(), keys.netAccessKey.size(), &(wpa_ssid->dpp_netaccesskey),
970 &(wpa_ssid->dpp_netaccesskey_len), "dpp netAccessKey")) {
971 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
972 }
973
974 return ndk::ScopedAStatus::ok();
975 #else
976 return createStatus(SupplicantStatusCode::FAILURE_UNSUPPORTED);
977 #endif
978 }
979
setScanSsidInternal(bool enable)980 ndk::ScopedAStatus StaNetwork::setScanSsidInternal(bool enable)
981 {
982 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
983 wpa_ssid->scan_ssid = enable ? 1 : 0;
984 resetInternalStateAfterParamsUpdate();
985 return ndk::ScopedAStatus::ok();
986 }
987
setAuthAlgInternal(AuthAlgMask mask)988 ndk::ScopedAStatus StaNetwork::setAuthAlgInternal(
989 AuthAlgMask mask)
990 {
991 uint32_t auth_alg_mask = static_cast<uint32_t>(mask);
992 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
993 if (auth_alg_mask & ~kAllowedAuthAlgMask) {
994 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
995 }
996 wpa_ssid->auth_alg = auth_alg_mask;
997 wpa_printf(MSG_MSGDUMP, "auth_alg: 0x%x", wpa_ssid->auth_alg);
998 resetInternalStateAfterParamsUpdate();
999 return ndk::ScopedAStatus::ok();
1000 }
1001
setEdmgInternal(bool enable)1002 ndk::ScopedAStatus StaNetwork::setEdmgInternal(bool enable)
1003 {
1004 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1005 wpa_ssid->enable_edmg = enable ? 1 : 0;
1006 resetInternalStateAfterParamsUpdate();
1007 return ndk::ScopedAStatus::ok();
1008 }
1009
setPskPassphraseInternal(const std::string & rawPsk)1010 ndk::ScopedAStatus StaNetwork::setPskPassphraseInternal(const std::string &rawPsk)
1011 {
1012 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1013 std::string psk = rawPsk;
1014 #ifdef CONFIG_WAPI_INTERFACE
1015 if (wpa_ssid->key_mgmt & WPA_KEY_MGMT_WAPI_PSK) {
1016 if (rawPsk.size() > 2 && rawPsk.front()== '"' && rawPsk.back() == '"') {
1017 psk = rawPsk.substr(1, rawPsk.size() - 2);
1018 } else {
1019 if ((rawPsk.size() & 1)) {
1020 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
1021 }
1022 size_t len = psk.size() / 2;
1023 uint8_t *buf = (uint8_t *) os_malloc(len);
1024 if (hexstr2bin(psk.c_str(), buf, len) < 0) {
1025 os_free(buf);
1026 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
1027 }
1028 std::vector<uint8_t> bytes(buf, buf + len);
1029 os_free(buf);
1030 return setWapiPskInternal(bytes);
1031 }
1032 }
1033 #endif
1034 if (isPskPassphraseValid(psk)) {
1035 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
1036 }
1037 if (wpa_ssid->passphrase &&
1038 os_strlen(wpa_ssid->passphrase) == psk.size() &&
1039 os_memcmp(wpa_ssid->passphrase, psk.c_str(), psk.size()) == 0) {
1040 return ndk::ScopedAStatus::ok();
1041 }
1042 // Flag to indicate if raw psk is calculated or not using
1043 // |wpa_config_update_psk|. Deferred if ssid not already set.
1044 wpa_ssid->psk_set = 0;
1045 if (setStringKeyFieldAndResetState(
1046 psk.c_str(), &(wpa_ssid->passphrase), "psk passphrase")) {
1047 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1048 }
1049 if (wpa_ssid->ssid_len) {
1050 wpa_config_update_psk(wpa_ssid);
1051 }
1052 return ndk::ScopedAStatus::ok();
1053 }
1054
setPskInternal(const std::vector<uint8_t> & psk)1055 ndk::ScopedAStatus StaNetwork::setPskInternal(const std::vector<uint8_t> &psk)
1056 {
1057 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1058 WPA_ASSERT(psk.size() == sizeof(wpa_ssid->psk));
1059 str_clear_free(wpa_ssid->passphrase);
1060 wpa_ssid->passphrase = nullptr;
1061 os_memcpy(wpa_ssid->psk, psk.data(), sizeof(wpa_ssid->psk));
1062 wpa_ssid->psk_set = 1;
1063 resetInternalStateAfterParamsUpdate();
1064 return ndk::ScopedAStatus::ok();
1065 }
1066
setWepKeyInternal(uint32_t key_idx,const std::vector<uint8_t> & wep_key)1067 ndk::ScopedAStatus StaNetwork::setWepKeyInternal(
1068 uint32_t key_idx, const std::vector<uint8_t> &wep_key)
1069 {
1070 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1071 if (key_idx >=
1072 static_cast<uint32_t>(
1073 ISupplicantStaNetwork::WEP_KEYS_MAX_NUM)) {
1074 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
1075 }
1076 if (wep_key.size() !=
1077 static_cast<uint32_t>(ISupplicantStaNetwork::
1078 WEP40_KEY_LEN_IN_BYTES) &&
1079 wep_key.size() !=
1080 static_cast<uint32_t>(ISupplicantStaNetwork::
1081 WEP104_KEY_LEN_IN_BYTES)) {
1082 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
1083 }
1084 os_memcpy(wpa_ssid->wep_key[key_idx], wep_key.data(), wep_key.size());
1085 wpa_ssid->wep_key_len[key_idx] = wep_key.size();
1086 std::string msg_dump_title("wep_key" + std::to_string(key_idx));
1087 wpa_hexdump_key(
1088 MSG_MSGDUMP, msg_dump_title.c_str(), wpa_ssid->wep_key[key_idx],
1089 wpa_ssid->wep_key_len[key_idx]);
1090 resetInternalStateAfterParamsUpdate();
1091 return ndk::ScopedAStatus::ok();
1092 }
1093
setWepTxKeyIdxInternal(uint32_t key_idx)1094 ndk::ScopedAStatus StaNetwork::setWepTxKeyIdxInternal(uint32_t key_idx)
1095 {
1096 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1097 if (key_idx >=
1098 static_cast<uint32_t>(
1099 ISupplicantStaNetwork::WEP_KEYS_MAX_NUM)) {
1100 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
1101 }
1102 wpa_ssid->wep_tx_keyidx = key_idx;
1103 resetInternalStateAfterParamsUpdate();
1104 return ndk::ScopedAStatus::ok();
1105 }
1106
setRequirePmfInternal(bool enable)1107 ndk::ScopedAStatus StaNetwork::setRequirePmfInternal(bool enable)
1108 {
1109 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1110 if (enable) {
1111 wpa_ssid->ieee80211w = MGMT_FRAME_PROTECTION_REQUIRED;
1112 }
1113 resetInternalStateAfterParamsUpdate();
1114 return ndk::ScopedAStatus::ok();
1115 }
1116
setEapMethodInternal(EapMethod method)1117 ndk::ScopedAStatus StaNetwork::setEapMethodInternal(
1118 EapMethod method)
1119 {
1120 uint32_t eap_method_idx = static_cast<
1121 std::underlying_type<EapMethod>::type>(
1122 method);
1123 if (eap_method_idx >= kEapMethodMax) {
1124 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
1125 }
1126
1127 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1128 int retrieved_vendor, retrieved_method;
1129 const char *method_str = kEapMethodStrings[eap_method_idx];
1130 // This string lookup is needed to check if the device supports the
1131 // corresponding EAP type.
1132 retrieved_method = eap_peer_get_type(method_str, &retrieved_vendor);
1133 if (retrieved_vendor == EAP_VENDOR_IETF &&
1134 retrieved_method == EAP_TYPE_NONE) {
1135 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1136 }
1137 if (wpa_ssid->eap.eap_methods) {
1138 os_free(wpa_ssid->eap.eap_methods);
1139 }
1140 // wpa_supplicant can support setting multiple eap methods for each
1141 // network. But, this is not really used by Android. So, just adding
1142 // support for setting one EAP method for each network. The additional
1143 // |eap_method_type| member in the array is used to indicate the end
1144 // of list.
1145 wpa_ssid->eap.eap_methods =
1146 (eap_method_type *)os_malloc(sizeof(eap_method_type) * 2);
1147 if (!wpa_ssid->eap.eap_methods) {
1148 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1149 }
1150 wpa_ssid->eap.eap_methods[0].vendor = retrieved_vendor;
1151 wpa_ssid->eap.eap_methods[0].method = retrieved_method;
1152 wpa_ssid->eap.eap_methods[1].vendor = EAP_VENDOR_IETF;
1153 wpa_ssid->eap.eap_methods[1].method = EAP_TYPE_NONE;
1154
1155 wpa_ssid->leap = 0;
1156 wpa_ssid->non_leap = 0;
1157 if (retrieved_vendor == EAP_VENDOR_IETF &&
1158 retrieved_method == EAP_TYPE_LEAP) {
1159 wpa_ssid->leap++;
1160 } else {
1161 wpa_ssid->non_leap++;
1162 }
1163 wpa_hexdump(
1164 MSG_MSGDUMP, "eap methods", (u8 *)wpa_ssid->eap.eap_methods,
1165 sizeof(eap_method_type) * 2);
1166 resetInternalStateAfterParamsUpdate();
1167 return ndk::ScopedAStatus::ok();
1168 }
1169
setEapPhase2MethodInternal(EapPhase2Method method)1170 ndk::ScopedAStatus StaNetwork::setEapPhase2MethodInternal(
1171 EapPhase2Method method)
1172 {
1173 uint32_t eap_phase2_method_idx = static_cast<
1174 std::underlying_type<EapPhase2Method>::type>(
1175 method);
1176 if (eap_phase2_method_idx >= kEapPhase2MethodMax) {
1177 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
1178 }
1179
1180 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1181 // EAP method needs to be set for us to construct the eap
1182 // phase 2 method string.
1183 ndk::ScopedAStatus status;
1184 EapMethod eap_method;
1185 std::tie(eap_method, status) = getEapMethodInternal();
1186 if (!status.isOk()) {
1187 return createStatusWithMsg(SupplicantStatusCode::FAILURE_UNKNOWN,
1188 "EAP method not set");
1189 }
1190 std::string eap_phase2_str;
1191 if (method == EapPhase2Method::NONE) {
1192 eap_phase2_str = "";
1193 } else if (
1194 eap_method == EapMethod::TTLS &&
1195 method == EapPhase2Method::GTC) {
1196 eap_phase2_str = kEapPhase2AuthEapPrefix;
1197 } else {
1198 eap_phase2_str = kEapPhase2AuthPrefix;
1199 }
1200 eap_phase2_str += kEapPhase2MethodStrings[eap_phase2_method_idx];
1201 if (setStringFieldAndResetState(
1202 eap_phase2_str.c_str(), &(wpa_ssid->eap.phase2),
1203 "eap phase2")) {
1204 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1205 }
1206 return ndk::ScopedAStatus::ok();
1207 }
1208
setEapIdentityInternal(const std::vector<uint8_t> & identity)1209 ndk::ScopedAStatus StaNetwork::setEapIdentityInternal(
1210 const std::vector<uint8_t> &identity)
1211 {
1212 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1213 if (setByteArrayFieldAndResetState(
1214 identity.data(), identity.size(), &(wpa_ssid->eap.identity),
1215 &(wpa_ssid->eap.identity_len), "eap identity")) {
1216 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1217 }
1218 // plain IMSI identity
1219 if (setByteArrayFieldAndResetState(
1220 identity.data(), identity.size(),
1221 &(wpa_ssid->eap.imsi_identity),
1222 &(wpa_ssid->eap.imsi_identity_len), "eap imsi identity")) {
1223 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1224 }
1225 return ndk::ScopedAStatus::ok();
1226 }
1227
setEapEncryptedImsiIdentityInternal(const std::vector<uint8_t> & identity)1228 ndk::ScopedAStatus StaNetwork::setEapEncryptedImsiIdentityInternal(
1229 const std::vector<uint8_t> &identity)
1230 {
1231 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1232 // encrypted IMSI identity
1233 if (setByteArrayFieldAndResetState(
1234 identity.data(), identity.size(), &(wpa_ssid->eap.identity),
1235 &(wpa_ssid->eap.identity_len), "eap encrypted imsi identity")) {
1236 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1237 }
1238 return ndk::ScopedAStatus::ok();
1239 }
1240
setEapAnonymousIdentityInternal(const std::vector<uint8_t> & identity)1241 ndk::ScopedAStatus StaNetwork::setEapAnonymousIdentityInternal(
1242 const std::vector<uint8_t> &identity)
1243 {
1244 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1245 // If current supplicant pseudonym is the prefix of new pseudonym,
1246 // the credential is not changed, just update the decoration.
1247 // As a result, no need to reset the state.
1248 // The decorated identity will have a postfix like
1249 // @mncXXX.mccYYY.3gppnetwork.org, so the length will be always
1250 // greater than the current one.
1251 bool resetState = wpa_ssid->eap.anonymous_identity == NULL
1252 || wpa_ssid->eap.anonymous_identity_len == 0
1253 || identity.size() == 0
1254 || wpa_ssid->eap.anonymous_identity_len >= identity.size()
1255 || os_strncmp((char *) identity.data(),
1256 (char *) wpa_ssid->eap.anonymous_identity,
1257 wpa_ssid->eap.anonymous_identity_len) != 0;
1258 if (setByteArrayField(
1259 identity.data(), identity.size(),
1260 &(wpa_ssid->eap.anonymous_identity),
1261 &(wpa_ssid->eap.anonymous_identity_len),
1262 "eap anonymous_identity", resetState)) {
1263 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1264 }
1265 return ndk::ScopedAStatus::ok();
1266 }
1267
setEapPasswordInternal(const std::vector<uint8_t> & password)1268 ndk::ScopedAStatus StaNetwork::setEapPasswordInternal(
1269 const std::vector<uint8_t> &password)
1270 {
1271 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1272 if (setByteArrayKeyFieldAndResetState(
1273 password.data(), password.size(), &(wpa_ssid->eap.password),
1274 &(wpa_ssid->eap.password_len), "eap password")) {
1275 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1276 }
1277 wpa_ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
1278 wpa_ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
1279 return ndk::ScopedAStatus::ok();
1280 }
1281
setEapCACertInternal(const std::string & path)1282 ndk::ScopedAStatus StaNetwork::setEapCACertInternal(const std::string &path)
1283 {
1284 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1285 if (setStringFieldAndResetState(
1286 path.c_str(), &(wpa_ssid->eap.cert.ca_cert), "eap ca_cert")) {
1287 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1288 }
1289 return ndk::ScopedAStatus::ok();
1290 }
1291
setEapCAPathInternal(const std::string & path)1292 ndk::ScopedAStatus StaNetwork::setEapCAPathInternal(const std::string &path)
1293 {
1294 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1295 if (setStringFieldAndResetState(
1296 path.c_str(), &(wpa_ssid->eap.cert.ca_path), "eap ca_path")) {
1297 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1298 }
1299 return ndk::ScopedAStatus::ok();
1300 }
1301
setEapClientCertInternal(const std::string & path)1302 ndk::ScopedAStatus StaNetwork::setEapClientCertInternal(const std::string &path)
1303 {
1304 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1305 if (setStringFieldAndResetState(
1306 path.c_str(), &(wpa_ssid->eap.cert.client_cert),
1307 "eap client_cert")) {
1308 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1309 }
1310 return ndk::ScopedAStatus::ok();
1311 }
1312
setEapPrivateKeyIdInternal(const std::string & id)1313 ndk::ScopedAStatus StaNetwork::setEapPrivateKeyIdInternal(const std::string &id)
1314 {
1315 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1316 if (setStringFieldAndResetState(
1317 id.c_str(), &(wpa_ssid->eap.cert.key_id), "eap key_id")) {
1318 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1319 }
1320 return ndk::ScopedAStatus::ok();
1321 }
1322
setEapSubjectMatchInternal(const std::string & match)1323 ndk::ScopedAStatus StaNetwork::setEapSubjectMatchInternal(
1324 const std::string &match)
1325 {
1326 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1327 if (setStringFieldAndResetState(
1328 match.c_str(), &(wpa_ssid->eap.cert.subject_match),
1329 "eap subject_match")) {
1330 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1331 }
1332 return ndk::ScopedAStatus::ok();
1333 }
1334
setEapAltSubjectMatchInternal(const std::string & match)1335 ndk::ScopedAStatus StaNetwork::setEapAltSubjectMatchInternal(
1336 const std::string &match)
1337 {
1338 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1339 if (setStringFieldAndResetState(
1340 match.c_str(), &(wpa_ssid->eap.cert.altsubject_match),
1341 "eap altsubject_match")) {
1342 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1343 }
1344 return ndk::ScopedAStatus::ok();
1345 }
1346
setEapEngineInternal(bool enable)1347 ndk::ScopedAStatus StaNetwork::setEapEngineInternal(bool enable)
1348 {
1349 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1350 wpa_ssid->eap.cert.engine = enable ? 1 : 0;
1351 return ndk::ScopedAStatus::ok();
1352 }
1353
setEapEngineIDInternal(const std::string & id)1354 ndk::ScopedAStatus StaNetwork::setEapEngineIDInternal(const std::string &id)
1355 {
1356 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1357 if (setStringFieldAndResetState(
1358 id.c_str(), &(wpa_ssid->eap.cert.engine_id), "eap engine_id")) {
1359 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1360 }
1361 return ndk::ScopedAStatus::ok();
1362 }
1363
setEapDomainSuffixMatchInternal(const std::string & match)1364 ndk::ScopedAStatus StaNetwork::setEapDomainSuffixMatchInternal(
1365 const std::string &match)
1366 {
1367 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1368 if (setStringFieldAndResetState(
1369 match.c_str(), &(wpa_ssid->eap.cert.domain_suffix_match),
1370 "eap domain_suffix_match")) {
1371 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1372 }
1373 return ndk::ScopedAStatus::ok();
1374 }
1375
setProactiveKeyCachingInternal(bool enable)1376 ndk::ScopedAStatus StaNetwork::setProactiveKeyCachingInternal(bool enable)
1377 {
1378 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1379 wpa_ssid->proactive_key_caching = enable ? 1 : 0;
1380 resetInternalStateAfterParamsUpdate();
1381 return ndk::ScopedAStatus::ok();
1382 }
1383
setIdStrInternal(const std::string & id_str)1384 ndk::ScopedAStatus StaNetwork::setIdStrInternal(const std::string &id_str)
1385 {
1386 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1387 if (setStringFieldAndResetState(
1388 id_str.c_str(), &(wpa_ssid->id_str), "id_str")) {
1389 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1390 }
1391 return ndk::ScopedAStatus::ok();
1392 }
1393
setUpdateIdentifierInternal(uint32_t id)1394 ndk::ScopedAStatus StaNetwork::setUpdateIdentifierInternal(uint32_t id)
1395 {
1396 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1397 wpa_ssid->update_identifier = id;
1398 wpa_printf(
1399 MSG_MSGDUMP, "update_identifier: %d", wpa_ssid->update_identifier);
1400 resetInternalStateAfterParamsUpdate();
1401 return ndk::ScopedAStatus::ok();
1402 }
1403
setWapiCertSuiteInternal(const std::string & suite)1404 ndk::ScopedAStatus StaNetwork::setWapiCertSuiteInternal(const std::string &suite)
1405 {
1406 #ifdef CONFIG_WAPI_INTERFACE
1407 // Dummy implementation
1408 dummyWapiCertSuite = suite;
1409 return ndk::ScopedAStatus::ok();
1410 #else
1411 return createStatusWithMsg(SupplicantStatusCode::FAILURE_UNKNOWN, "Not implemented");
1412 #endif
1413 }
1414
setWapiPskInternal(const std::vector<uint8_t> & psk)1415 ndk::ScopedAStatus StaNetwork::setWapiPskInternal(const std::vector<uint8_t> &psk)
1416 {
1417 #ifdef CONFIG_WAPI_INTERFACE
1418 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1419 str_clear_free(wpa_ssid->passphrase);
1420 wpa_ssid->passphrase = nullptr;
1421
1422 // Dummy implementation
1423 dummyWapiPsk = psk;
1424
1425 wpa_ssid->psk_set = 1;
1426 resetInternalStateAfterParamsUpdate();
1427 return ndk::ScopedAStatus::ok();
1428 #else
1429 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1430 #endif
1431 }
1432
getSsidInternal()1433 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> StaNetwork::getSsidInternal()
1434 {
1435 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1436 std::vector<uint8_t> ssid(
1437 wpa_ssid->ssid,
1438 wpa_ssid->ssid + wpa_ssid->ssid_len);
1439 return {std::move(ssid), ndk::ScopedAStatus::ok()};
1440 }
1441
1442 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
getBssidInternal()1443 StaNetwork::getBssidInternal()
1444 {
1445 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1446 std::vector<uint8_t> bssid(kZeroBssid, kZeroBssid + ETH_ALEN);
1447 if (wpa_ssid->bssid_set) {
1448 bssid.assign(wpa_ssid->bssid, wpa_ssid->bssid + ETH_ALEN);
1449 }
1450 return {std::move(bssid), ndk::ScopedAStatus::ok()};
1451 }
1452
getScanSsidInternal()1453 std::pair<bool, ndk::ScopedAStatus> StaNetwork::getScanSsidInternal()
1454 {
1455 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1456 return {(wpa_ssid->scan_ssid == 1), ndk::ScopedAStatus::ok()};
1457 }
1458
1459 std::pair<AuthAlgMask, ndk::ScopedAStatus>
getAuthAlgInternal()1460 StaNetwork::getAuthAlgInternal()
1461 {
1462 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1463 uint32_t auth_alg_mask = wpa_ssid->auth_alg & kAllowedAuthAlgMask;
1464 return {static_cast<AuthAlgMask>(auth_alg_mask), ndk::ScopedAStatus::ok()};
1465 }
1466
getPskPassphraseInternal()1467 std::pair<std::string, ndk::ScopedAStatus> StaNetwork::getPskPassphraseInternal()
1468 {
1469 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1470 #ifdef CONFIG_WAPI_INTERFACE
1471 if (wpa_ssid->key_mgmt & WPA_KEY_MGMT_WAPI_PSK) {
1472 if (wpa_ssid->psk_set) {
1473 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> ret = getWapiPskInternal();
1474 std::string psk;
1475 char buf[3] = {0};
1476 for (int i = 0; i < ret.second.size(); i++) {
1477 snprintf(buf, sizeof(buf), "%02x", ret.second[i]);
1478 psk.append(buf);
1479 }
1480 return {psk, ndk::ScopedAStatus::ok()};
1481 } else {
1482 if (!wpa_ssid->passphrase) {
1483 return {"", createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1484 }
1485 std::string passphrase;
1486 passphrase.append("\"");
1487 passphrase.append(wpa_ssid->passphrase);
1488 passphrase.append("\"");
1489 return {passphrase, ndk::ScopedAStatus::ok()};
1490 }
1491 }
1492 #endif
1493 if (!wpa_ssid->passphrase) {
1494 return {"", createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1495 }
1496 return {wpa_ssid->passphrase, ndk::ScopedAStatus::ok()};
1497 }
1498
1499 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
getPskInternal()1500 StaNetwork::getPskInternal()
1501 {
1502 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1503 WPA_ASSERT(psk.size() == sizeof(wpa_ssid->psk));
1504 if (!wpa_ssid->psk_set) {
1505 return {std::vector<uint8_t>(),
1506 createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1507 }
1508 std::vector<uint8_t> psk(wpa_ssid->psk, wpa_ssid->psk + 32);
1509 return {psk, ndk::ScopedAStatus::ok()};
1510 }
1511
getSaePasswordInternal()1512 std::pair<std::string, ndk::ScopedAStatus> StaNetwork::getSaePasswordInternal()
1513 {
1514 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1515 if (!wpa_ssid->sae_password) {
1516 return {"", createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1517 }
1518 return {misc_utils::charBufToString(wpa_ssid->sae_password),
1519 ndk::ScopedAStatus::ok()};
1520 }
1521
getSaePasswordIdInternal()1522 std::pair<std::string, ndk::ScopedAStatus> StaNetwork::getSaePasswordIdInternal()
1523 {
1524 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1525 if (!wpa_ssid->sae_password_id) {
1526 return {"", createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1527 }
1528 return {misc_utils::charBufToString(wpa_ssid->sae_password_id),
1529 ndk::ScopedAStatus::ok()};
1530 }
1531
getWepKeyInternal(uint32_t key_idx)1532 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> StaNetwork::getWepKeyInternal(
1533 uint32_t key_idx)
1534 {
1535 std::vector<uint8_t> wep_key;
1536 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1537 if (key_idx >=
1538 static_cast<uint32_t>(
1539 ISupplicantStaNetwork::WEP_KEYS_MAX_NUM)) {
1540 return {wep_key,
1541 createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID)};
1542 }
1543 wep_key.assign(
1544 wpa_ssid->wep_key[key_idx],
1545 wpa_ssid->wep_key[key_idx] + wpa_ssid->wep_key_len[key_idx]);
1546 return {std::move(wep_key), ndk::ScopedAStatus::ok()};
1547 }
1548
getWepTxKeyIdxInternal()1549 std::pair<uint32_t, ndk::ScopedAStatus> StaNetwork::getWepTxKeyIdxInternal()
1550 {
1551 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1552 return {wpa_ssid->wep_tx_keyidx, ndk::ScopedAStatus::ok()};
1553 }
1554
getRequirePmfInternal()1555 std::pair<bool, ndk::ScopedAStatus> StaNetwork::getRequirePmfInternal()
1556 {
1557 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1558 return {(wpa_ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED),
1559 ndk::ScopedAStatus::ok()};
1560 }
1561
1562 std::pair<EapMethod, ndk::ScopedAStatus>
getEapMethodInternal()1563 StaNetwork::getEapMethodInternal()
1564 {
1565 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1566 if (!wpa_ssid->eap.eap_methods) {
1567 return {static_cast<EapMethod>(0),
1568 createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1569 }
1570 // wpa_supplicant can support setting multiple eap methods for each
1571 // network. But, this is not really used by Android. So, just reading
1572 // the first EAP method for each network.
1573 const std::string eap_method_str = eap_get_name(
1574 wpa_ssid->eap.eap_methods[0].vendor,
1575 static_cast<enum eap_type>(wpa_ssid->eap.eap_methods[0].method));
1576 size_t eap_method_idx =
1577 std::find(
1578 std::begin(kEapMethodStrings), std::end(kEapMethodStrings),
1579 eap_method_str) -
1580 std::begin(kEapMethodStrings);
1581 if (eap_method_idx >= kEapMethodMax) {
1582 return {static_cast<EapMethod>(0),
1583 createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1584 }
1585 return {static_cast<EapMethod>(eap_method_idx), ndk::ScopedAStatus::ok()};
1586 }
1587
1588 std::pair<EapPhase2Method, ndk::ScopedAStatus>
getEapPhase2MethodInternal()1589 StaNetwork::getEapPhase2MethodInternal()
1590 {
1591 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1592 if (!wpa_ssid->eap.phase2) {
1593 return {static_cast<EapPhase2Method>(0),
1594 createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1595 }
1596 const std::string eap_phase2_method_str_with_prefix =
1597 wpa_ssid->eap.phase2;
1598 std::string eap_phase2_method_str;
1599 // Strip out the phase 2 method prefix before doing a reverse lookup
1600 // of phase 2 string to the Eap Phase 2 type.
1601 if (eap_phase2_method_str_with_prefix.find(kEapPhase2AuthPrefix) == 0) {
1602 eap_phase2_method_str =
1603 eap_phase2_method_str_with_prefix.substr(
1604 strlen(kEapPhase2AuthPrefix),
1605 eap_phase2_method_str_with_prefix.size());
1606 } else if (
1607 eap_phase2_method_str_with_prefix.find(kEapPhase2AuthEapPrefix) ==
1608 0) {
1609 eap_phase2_method_str =
1610 eap_phase2_method_str_with_prefix.substr(
1611 strlen(kEapPhase2AuthEapPrefix),
1612 eap_phase2_method_str_with_prefix.size());
1613 }
1614 size_t eap_phase2_method_idx =
1615 std::find(
1616 std::begin(kEapPhase2MethodStrings),
1617 std::end(kEapPhase2MethodStrings), eap_phase2_method_str) -
1618 std::begin(kEapPhase2MethodStrings);
1619 if (eap_phase2_method_idx >= kEapPhase2MethodMax) {
1620 return {static_cast<EapPhase2Method>(0),
1621 createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1622 }
1623 return {static_cast<EapPhase2Method>(eap_phase2_method_idx),
1624 ndk::ScopedAStatus::ok()};
1625 }
1626
1627 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
getEapIdentityInternal()1628 StaNetwork::getEapIdentityInternal()
1629 {
1630 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1631 if (!wpa_ssid->eap.identity) {
1632 return {std::vector<uint8_t>(),
1633 createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1634 }
1635 return {std::vector<uint8_t>(
1636 wpa_ssid->eap.identity,
1637 wpa_ssid->eap.identity + wpa_ssid->eap.identity_len),
1638 ndk::ScopedAStatus::ok()};
1639 }
1640
1641 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
getEapAnonymousIdentityInternal()1642 StaNetwork::getEapAnonymousIdentityInternal()
1643 {
1644 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1645 if (!wpa_ssid->eap.anonymous_identity) {
1646 return {std::vector<uint8_t>(),
1647 createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1648 }
1649 return {std::vector<uint8_t>(
1650 wpa_ssid->eap.anonymous_identity,
1651 wpa_ssid->eap.anonymous_identity +
1652 wpa_ssid->eap.anonymous_identity_len),
1653 ndk::ScopedAStatus::ok()};
1654 }
1655
1656 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
getEapPasswordInternal()1657 StaNetwork::getEapPasswordInternal()
1658 {
1659 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1660 if (!wpa_ssid->eap.password) {
1661 return {std::vector<uint8_t>(), createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1662 }
1663 return {std::vector<uint8_t>(
1664 wpa_ssid->eap.password,
1665 wpa_ssid->eap.password + wpa_ssid->eap.password_len),
1666 ndk::ScopedAStatus::ok()};
1667 }
1668
getEapCACertInternal()1669 std::pair<std::string, ndk::ScopedAStatus> StaNetwork::getEapCACertInternal()
1670 {
1671 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1672 if (!wpa_ssid->eap.cert.ca_cert) {
1673 return {"", createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1674 }
1675 return {misc_utils::charBufToString(wpa_ssid->eap.cert.ca_cert),
1676 ndk::ScopedAStatus::ok()};
1677 }
1678
getEapCAPathInternal()1679 std::pair<std::string, ndk::ScopedAStatus> StaNetwork::getEapCAPathInternal()
1680 {
1681 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1682 if (!wpa_ssid->eap.cert.ca_path) {
1683 return {"", createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1684 }
1685 return {misc_utils::charBufToString(wpa_ssid->eap.cert.ca_path),
1686 ndk::ScopedAStatus::ok()};
1687 }
1688
getEapClientCertInternal()1689 std::pair<std::string, ndk::ScopedAStatus> StaNetwork::getEapClientCertInternal()
1690 {
1691 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1692 if (!wpa_ssid->eap.cert.client_cert) {
1693 return {"", createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1694 }
1695 return {misc_utils::charBufToString(wpa_ssid->eap.cert.client_cert),
1696 ndk::ScopedAStatus::ok()};
1697 }
1698
1699 std::pair<std::string, ndk::ScopedAStatus>
getEapPrivateKeyIdInternal()1700 StaNetwork::getEapPrivateKeyIdInternal()
1701 {
1702 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1703 if (!wpa_ssid->eap.cert.key_id) {
1704 return {"", createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1705 }
1706 return {misc_utils::charBufToString(reinterpret_cast<char *>(wpa_ssid->eap.cert.key_id)),
1707 ndk::ScopedAStatus::ok()};
1708 }
1709
1710 std::pair<std::string, ndk::ScopedAStatus>
getEapSubjectMatchInternal()1711 StaNetwork::getEapSubjectMatchInternal()
1712 {
1713 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1714 if (!wpa_ssid->eap.cert.subject_match) {
1715 return {"", createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1716 }
1717 return {misc_utils::charBufToString(wpa_ssid->eap.cert.subject_match),
1718 ndk::ScopedAStatus::ok()};
1719 }
1720
1721 std::pair<std::string, ndk::ScopedAStatus>
getEapAltSubjectMatchInternal()1722 StaNetwork::getEapAltSubjectMatchInternal()
1723 {
1724 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1725 if (!wpa_ssid->eap.cert.altsubject_match) {
1726 return {"", createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1727 }
1728 return {misc_utils::charBufToString(wpa_ssid->eap.cert.altsubject_match),
1729 ndk::ScopedAStatus::ok()};
1730 }
1731
getEapEngineInternal()1732 std::pair<bool, ndk::ScopedAStatus> StaNetwork::getEapEngineInternal()
1733 {
1734 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1735 return {wpa_ssid->eap.cert.engine == 1, ndk::ScopedAStatus::ok()};
1736 }
1737
getEapEngineIdInternal()1738 std::pair<std::string, ndk::ScopedAStatus> StaNetwork::getEapEngineIdInternal()
1739 {
1740 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1741 if (!wpa_ssid->eap.cert.engine_id) {
1742 return {"", createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1743 }
1744 return {misc_utils::charBufToString(wpa_ssid->eap.cert.engine_id),
1745 ndk::ScopedAStatus::ok()};
1746 }
1747
1748 std::pair<std::string, ndk::ScopedAStatus>
getEapDomainSuffixMatchInternal()1749 StaNetwork::getEapDomainSuffixMatchInternal()
1750 {
1751 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1752 if (!wpa_ssid->eap.cert.domain_suffix_match) {
1753 return {"", createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1754 }
1755 return {misc_utils::charBufToString(wpa_ssid->eap.cert.domain_suffix_match),
1756 ndk::ScopedAStatus::ok()};
1757 }
1758
getIdStrInternal()1759 std::pair<std::string, ndk::ScopedAStatus> StaNetwork::getIdStrInternal()
1760 {
1761 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1762 if (!wpa_ssid->id_str) {
1763 return {"", createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1764 }
1765 return {misc_utils::charBufToString(wpa_ssid->id_str),
1766 ndk::ScopedAStatus::ok()};
1767 }
1768
getEdmgInternal()1769 std::pair<bool, ndk::ScopedAStatus> StaNetwork::getEdmgInternal()
1770 {
1771 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1772 return {(wpa_ssid->enable_edmg == 1), ndk::ScopedAStatus::ok()};
1773 }
1774
1775 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
getWpsNfcConfigurationTokenInternal()1776 StaNetwork::getWpsNfcConfigurationTokenInternal()
1777 {
1778 struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1779 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1780 auto token_buf = misc_utils::createWpaBufUniquePtr(
1781 wpas_wps_network_config_token(wpa_s, 0, wpa_ssid));
1782 if (!token_buf) {
1783 return {std::vector<uint8_t>(),
1784 createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1785 }
1786 return {misc_utils::convertWpaBufToVector(token_buf.get()),
1787 ndk::ScopedAStatus::ok()};
1788 }
1789
getWapiCertSuiteInternal()1790 std::pair<std::string, ndk::ScopedAStatus> StaNetwork::getWapiCertSuiteInternal()
1791 {
1792 #ifdef CONFIG_WAPI_INTERFACE
1793 // Dummy implementation
1794 return {dummyWapiCertSuite, ndk::ScopedAStatus::ok()};
1795 #else
1796 return {"", createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1797 #endif
1798 }
1799
getWapiPskInternal()1800 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> StaNetwork::getWapiPskInternal()
1801 {
1802 #ifdef CONFIG_WAPI_INTERFACE
1803 // Dummy implementation
1804 return {dummyWapiPsk, ndk::ScopedAStatus::ok()};
1805 #else
1806 return {std::vector<uint8_t>(),
1807 createStatus(SupplicantStatusCode::FAILURE_UNKNOWN)};
1808 #endif
1809 }
1810
enableInternal(bool no_connect)1811 ndk::ScopedAStatus StaNetwork::enableInternal(bool no_connect)
1812 {
1813 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1814 if (wpa_ssid->disabled == 2) {
1815 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1816 }
1817 struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1818 if (no_connect) {
1819 wpa_ssid->disabled = 0;
1820 } else {
1821 wpa_s->scan_min_time.sec = 0;
1822 wpa_s->scan_min_time.usec = 0;
1823 wpa_supplicant_enable_network(wpa_s, wpa_ssid);
1824 }
1825 return ndk::ScopedAStatus::ok();
1826 }
1827
disableInternal()1828 ndk::ScopedAStatus StaNetwork::disableInternal()
1829 {
1830 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1831 if (wpa_ssid->disabled == 2) {
1832 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1833 }
1834 struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1835 wpa_supplicant_disable_network(wpa_s, wpa_ssid);
1836 return ndk::ScopedAStatus::ok();
1837 }
1838
selectInternal()1839 ndk::ScopedAStatus StaNetwork::selectInternal()
1840 {
1841 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1842 if (wpa_ssid->disabled == 2) {
1843 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1844 }
1845 struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1846 wpa_s->scan_min_time.sec = 0;
1847 wpa_s->scan_min_time.usec = 0;
1848 wpa_supplicant_select_network(wpa_s, wpa_ssid);
1849 return ndk::ScopedAStatus::ok();
1850 }
1851
sendNetworkEapSimGsmAuthResponseInternal(const std::vector<NetworkResponseEapSimGsmAuthParams> & vec_params)1852 ndk::ScopedAStatus StaNetwork::sendNetworkEapSimGsmAuthResponseInternal(
1853 const std::vector<NetworkResponseEapSimGsmAuthParams>
1854 &vec_params)
1855 {
1856 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1857 // Convert the incoming parameters to a string to pass to
1858 // wpa_supplicant.
1859 std::string ctrl_rsp_param = std::string(kNetworkEapSimGsmAuthResponse);
1860 for (const auto ¶ms : vec_params) {
1861 uint32_t kc_hex_len = params.kc.size() * 2 + 1;
1862 std::vector<char> kc_hex(kc_hex_len);
1863 uint32_t sres_hex_len = params.sres.size() * 2 + 1;
1864 std::vector<char> sres_hex(sres_hex_len);
1865 wpa_snprintf_hex(
1866 kc_hex.data(), kc_hex.size(), params.kc.data(),
1867 params.kc.size());
1868 wpa_snprintf_hex(
1869 sres_hex.data(), sres_hex.size(), params.sres.data(),
1870 params.sres.size());
1871 ctrl_rsp_param += ":" + std::string(kc_hex.data()) + ":" +
1872 std::string(sres_hex.data());
1873 }
1874 enum wpa_ctrl_req_type rtype = WPA_CTRL_REQ_SIM;
1875 struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1876 if (wpa_supplicant_ctrl_rsp_handle(
1877 wpa_s, wpa_ssid, rtype, ctrl_rsp_param.c_str(),
1878 ctrl_rsp_param.size())) {
1879 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1880 }
1881 eapol_sm_notify_ctrl_response(wpa_s->eapol);
1882 wpa_hexdump_ascii_key(
1883 MSG_DEBUG, "network sim gsm auth response param",
1884 (const u8 *)ctrl_rsp_param.c_str(), ctrl_rsp_param.size());
1885 return ndk::ScopedAStatus::ok();
1886 }
1887
sendNetworkEapSimGsmAuthFailureInternal()1888 ndk::ScopedAStatus StaNetwork::sendNetworkEapSimGsmAuthFailureInternal()
1889 {
1890 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1891 struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1892 enum wpa_ctrl_req_type rtype = WPA_CTRL_REQ_SIM;
1893 if (wpa_supplicant_ctrl_rsp_handle(
1894 wpa_s, wpa_ssid, rtype, kNetworkEapSimGsmAuthFailure,
1895 strlen(kNetworkEapSimGsmAuthFailure))) {
1896 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1897 }
1898 eapol_sm_notify_ctrl_response(wpa_s->eapol);
1899 return ndk::ScopedAStatus::ok();
1900 }
1901
sendNetworkEapSimUmtsAuthResponseInternal(const NetworkResponseEapSimUmtsAuthParams & params)1902 ndk::ScopedAStatus StaNetwork::sendNetworkEapSimUmtsAuthResponseInternal(
1903 const NetworkResponseEapSimUmtsAuthParams ¶ms)
1904 {
1905 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1906 // Convert the incoming parameters to a string to pass to
1907 // wpa_supplicant.
1908 uint32_t ik_hex_len = params.ik.size() * 2 + 1;
1909 std::vector<char> ik_hex(ik_hex_len);
1910 uint32_t ck_hex_len = params.ck.size() * 2 + 1;
1911 std::vector<char> ck_hex(ck_hex_len);
1912 uint32_t res_hex_len = params.res.size() * 2 + 1;
1913 std::vector<char> res_hex(res_hex_len);
1914 wpa_snprintf_hex(
1915 ik_hex.data(), ik_hex.size(), params.ik.data(), params.ik.size());
1916 wpa_snprintf_hex(
1917 ck_hex.data(), ck_hex.size(), params.ck.data(), params.ck.size());
1918 wpa_snprintf_hex(
1919 res_hex.data(), res_hex.size(), params.res.data(),
1920 params.res.size());
1921 std::string ctrl_rsp_param =
1922 std::string(kNetworkEapSimUmtsAuthResponse) + ":" +
1923 std::string(ik_hex.data()) + ":" + std::string(ck_hex.data()) +
1924 ":" + std::string(res_hex.data());
1925 enum wpa_ctrl_req_type rtype = WPA_CTRL_REQ_SIM;
1926 struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1927 if (wpa_supplicant_ctrl_rsp_handle(
1928 wpa_s, wpa_ssid, rtype, ctrl_rsp_param.c_str(),
1929 ctrl_rsp_param.size())) {
1930 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1931 }
1932 eapol_sm_notify_ctrl_response(wpa_s->eapol);
1933 wpa_hexdump_ascii_key(
1934 MSG_DEBUG, "network sim umts auth response param",
1935 (const u8 *)ctrl_rsp_param.c_str(), ctrl_rsp_param.size());
1936 return ndk::ScopedAStatus::ok();
1937 }
1938
sendNetworkEapSimUmtsAutsResponseInternal(const std::vector<uint8_t> & auts)1939 ndk::ScopedAStatus StaNetwork::sendNetworkEapSimUmtsAutsResponseInternal(
1940 const std::vector<uint8_t> &auts)
1941 {
1942 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1943 uint32_t auts_hex_len = auts.size() * 2 + 1;
1944 std::vector<char> auts_hex(auts_hex_len);
1945 wpa_snprintf_hex(
1946 auts_hex.data(), auts_hex.size(), auts.data(), auts.size());
1947 std::string ctrl_rsp_param =
1948 std::string(kNetworkEapSimUmtsAutsResponse) + ":" +
1949 std::string(auts_hex.data());
1950 enum wpa_ctrl_req_type rtype = WPA_CTRL_REQ_SIM;
1951 struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1952 if (wpa_supplicant_ctrl_rsp_handle(
1953 wpa_s, wpa_ssid, rtype, ctrl_rsp_param.c_str(),
1954 ctrl_rsp_param.size())) {
1955 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1956 }
1957 eapol_sm_notify_ctrl_response(wpa_s->eapol);
1958 wpa_hexdump_ascii_key(
1959 MSG_DEBUG, "network sim umts auts response param",
1960 (const u8 *)ctrl_rsp_param.c_str(), ctrl_rsp_param.size());
1961 return ndk::ScopedAStatus::ok();
1962 }
1963
sendNetworkEapSimUmtsAuthFailureInternal()1964 ndk::ScopedAStatus StaNetwork::sendNetworkEapSimUmtsAuthFailureInternal()
1965 {
1966 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1967 struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1968 enum wpa_ctrl_req_type rtype = WPA_CTRL_REQ_SIM;
1969 if (wpa_supplicant_ctrl_rsp_handle(
1970 wpa_s, wpa_ssid, rtype, kNetworkEapSimUmtsAuthFailure,
1971 strlen(kNetworkEapSimUmtsAuthFailure))) {
1972 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1973 }
1974 eapol_sm_notify_ctrl_response(wpa_s->eapol);
1975 return ndk::ScopedAStatus::ok();
1976 }
1977
sendNetworkEapIdentityResponseInternal(const std::vector<uint8_t> & identity,const std::vector<uint8_t> & encrypted_imsi_identity)1978 ndk::ScopedAStatus StaNetwork::sendNetworkEapIdentityResponseInternal(
1979 const std::vector<uint8_t> &identity,
1980 const std::vector<uint8_t> &encrypted_imsi_identity)
1981 {
1982 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
1983 std::string ctrl_rsp_param(identity.begin(), identity.end());
1984 // If encrypted identity is included, format is:
1985 // plain identity + ":" + encrypted_identity
1986 if (encrypted_imsi_identity.size() != 0) {
1987 ctrl_rsp_param += ":" + std::string(
1988 encrypted_imsi_identity.begin(), encrypted_imsi_identity.end());
1989 }
1990 enum wpa_ctrl_req_type rtype = WPA_CTRL_REQ_EAP_IDENTITY;
1991 struct wpa_supplicant *wpa_s = retrieveIfacePtr();
1992 if (wpa_supplicant_ctrl_rsp_handle(
1993 wpa_s, wpa_ssid, rtype, ctrl_rsp_param.c_str(),
1994 ctrl_rsp_param.size())) {
1995 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
1996 }
1997 eapol_sm_notify_ctrl_response(wpa_s->eapol);
1998 wpa_hexdump_ascii_key(
1999 MSG_DEBUG, "network identity response param",
2000 (const u8 *)ctrl_rsp_param.c_str(), ctrl_rsp_param.size());
2001 return ndk::ScopedAStatus::ok();
2002 }
2003
enableTlsSuiteBEapPhase1ParamInternal(bool enable)2004 ndk::ScopedAStatus StaNetwork::enableTlsSuiteBEapPhase1ParamInternal(bool enable)
2005 {
2006 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2007 int val = enable == true ? 1 : 0;
2008 std::string suiteb_phase1("tls_suiteb=" + std::to_string(val));
2009
2010 if (setStringKeyFieldAndResetState(
2011 suiteb_phase1.c_str(), &(wpa_ssid->eap.phase1), "phase1")) {
2012 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
2013 }
2014 return ndk::ScopedAStatus::ok();
2015 }
2016
enableSuiteBEapOpenSslCiphersInternal()2017 ndk::ScopedAStatus StaNetwork::enableSuiteBEapOpenSslCiphersInternal()
2018 {
2019 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2020 const char openssl_suiteb_cipher[] = "SUITEB192";
2021
2022 if (setStringKeyFieldAndResetState(
2023 openssl_suiteb_cipher, &(wpa_ssid->eap.openssl_ciphers),
2024 "openssl_ciphers")) {
2025 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
2026 }
2027 return ndk::ScopedAStatus::ok();
2028 }
2029
setSaePasswordInternal(const std::string & sae_password)2030 ndk::ScopedAStatus StaNetwork::setSaePasswordInternal(
2031 const std::string &sae_password)
2032 {
2033 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2034 if (sae_password.length() < 1) {
2035 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
2036 }
2037 if (wpa_ssid->sae_password &&
2038 os_strlen(wpa_ssid->sae_password) == sae_password.length() &&
2039 os_memcmp(
2040 wpa_ssid->sae_password, sae_password.c_str(),
2041 sae_password.length()) == 0) {
2042 return ndk::ScopedAStatus::ok();
2043 }
2044 wpa_ssid->psk_set = 1;
2045 if (setStringKeyFieldAndResetState(
2046 sae_password.c_str(), &(wpa_ssid->sae_password),
2047 "sae password")) {
2048 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
2049 }
2050 return ndk::ScopedAStatus::ok();
2051 }
2052
setSaePasswordIdInternal(const std::string & sae_password_id)2053 ndk::ScopedAStatus StaNetwork::setSaePasswordIdInternal(
2054 const std::string &sae_password_id)
2055 {
2056 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2057 if (sae_password_id.length() < 1) {
2058 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
2059 }
2060 if (wpa_ssid->sae_password_id &&
2061 os_strlen(wpa_ssid->sae_password_id) == sae_password_id.length() &&
2062 os_memcmp(
2063 wpa_ssid->sae_password_id, sae_password_id.c_str(),
2064 sae_password_id.length()) == 0) {
2065 return ndk::ScopedAStatus::ok();
2066 }
2067 wpa_ssid->psk_set = 1;
2068 if (setStringKeyFieldAndResetState(
2069 sae_password_id.c_str(), &(wpa_ssid->sae_password_id),
2070 "sae password id")) {
2071 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
2072 }
2073 return ndk::ScopedAStatus::ok();
2074 }
2075
setGroupMgmtCipherInternal(GroupMgmtCipherMask mask)2076 ndk::ScopedAStatus StaNetwork::setGroupMgmtCipherInternal(
2077 GroupMgmtCipherMask mask)
2078 {
2079 uint32_t group_mgmt_cipher_mask = static_cast<uint32_t>(mask);
2080 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2081 if (group_mgmt_cipher_mask & ~kAllowedGroupMgmtCipherMask) {
2082 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
2083 }
2084 wpa_ssid->group_mgmt_cipher = group_mgmt_cipher_mask;
2085 wpa_printf(MSG_MSGDUMP, "group_mgmt_cipher: 0x%x",
2086 wpa_ssid->group_mgmt_cipher);
2087 resetInternalStateAfterParamsUpdate();
2088 return ndk::ScopedAStatus::ok();
2089 }
2090
2091 std::pair<GroupMgmtCipherMask, ndk::ScopedAStatus>
getGroupMgmtCipherInternal()2092 StaNetwork::getGroupMgmtCipherInternal()
2093 {
2094 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2095 uint32_t group_mgmt_cipher_mask =
2096 wpa_ssid->group_mgmt_cipher & kAllowedGroupMgmtCipherMask;
2097 return {static_cast<GroupMgmtCipherMask>(group_mgmt_cipher_mask),
2098 ndk::ScopedAStatus::ok()};
2099 }
2100
setOcspInternal(OcspType ocspType)2101 ndk::ScopedAStatus StaNetwork::setOcspInternal(OcspType ocspType) {
2102 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2103 if (ocspType < OcspType::NONE || ocspType > OcspType::REQUIRE_ALL_CERTS_STATUS) {
2104 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
2105 }
2106 wpa_ssid->eap.cert.ocsp = (int) ocspType;
2107 wpa_printf(
2108 MSG_MSGDUMP, "ocsp: %d", wpa_ssid->eap.cert.ocsp);
2109 resetInternalStateAfterParamsUpdate();
2110 return ndk::ScopedAStatus::ok();
2111 }
2112
getOcspInternal()2113 std::pair<OcspType, ndk::ScopedAStatus> StaNetwork::getOcspInternal()
2114 {
2115 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2116 return {static_cast<OcspType>(wpa_ssid->eap.cert.ocsp),
2117 ndk::ScopedAStatus::ok()};
2118 }
2119
setPmkCacheInternal(const std::vector<uint8_t> & serializedEntry)2120 ndk::ScopedAStatus StaNetwork::setPmkCacheInternal(const std::vector<uint8_t>& serializedEntry) {
2121 struct wpa_supplicant *wpa_s = retrieveIfacePtr();
2122 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2123 struct rsn_pmksa_cache_entry *new_entry = NULL;
2124
2125 new_entry = (struct rsn_pmksa_cache_entry *) os_zalloc(sizeof(*new_entry));
2126 if (!new_entry) {
2127 return createStatusWithMsg(SupplicantStatusCode::FAILURE_UNKNOWN,
2128 "Allocating memory failed");
2129 }
2130
2131 std::stringstream ss(
2132 std::stringstream::in | std::stringstream::out | std::stringstream::binary);
2133 ss.write((char *) serializedEntry.data(), std::streamsize(serializedEntry.size()));
2134 misc_utils::deserializePmkCacheEntry(ss, new_entry);
2135 new_entry->network_ctx = wpa_ssid;
2136
2137 // If there is an entry has a later expiration, ignore this one.
2138 struct rsn_pmksa_cache_entry *existing_entry = wpa_sm_pmksa_cache_get(
2139 wpa_s->wpa, new_entry->aa, NULL, NULL, new_entry->akmp);
2140 if (NULL != existing_entry &&
2141 existing_entry->expiration >= new_entry->expiration) {
2142 return ndk::ScopedAStatus::ok();
2143 }
2144
2145 new_entry->external = true;
2146 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, new_entry);
2147
2148 return ndk::ScopedAStatus::ok();
2149 }
2150
setKeyMgmtInternal(KeyMgmtMask mask)2151 ndk::ScopedAStatus StaNetwork::setKeyMgmtInternal(
2152 KeyMgmtMask mask)
2153 {
2154 uint32_t key_mgmt_mask = static_cast<uint32_t>(mask);
2155 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2156 if (key_mgmt_mask & ~kAllowedKeyMgmtMask) {
2157 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
2158 }
2159 setFastTransitionKeyMgmt(key_mgmt_mask);
2160
2161 if (key_mgmt_mask & WPA_KEY_MGMT_OWE) {
2162 // Do not allow to connect to Open network when OWE is selected
2163 wpa_ssid->owe_only = 1;
2164 wpa_ssid->owe_ptk_workaround = 1;
2165 }
2166 wpa_ssid->key_mgmt = key_mgmt_mask;
2167 wpa_printf(MSG_MSGDUMP, "key_mgmt: 0x%x", wpa_ssid->key_mgmt);
2168 resetInternalStateAfterParamsUpdate();
2169 return ndk::ScopedAStatus::ok();
2170 }
2171
2172 std::pair<KeyMgmtMask, ndk::ScopedAStatus>
getKeyMgmtInternal()2173 StaNetwork::getKeyMgmtInternal()
2174 {
2175 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2176 uint32_t key_mgmt_mask = wpa_ssid->key_mgmt & kAllowedKeyMgmtMask;
2177
2178 resetFastTransitionKeyMgmt(key_mgmt_mask);
2179 return {static_cast<KeyMgmtMask>(key_mgmt_mask),
2180 ndk::ScopedAStatus::ok()};
2181 }
2182
setProtoInternal(ProtoMask mask)2183 ndk::ScopedAStatus StaNetwork::setProtoInternal(
2184 ProtoMask mask)
2185 {
2186 uint32_t proto_mask = static_cast<uint32_t>(mask);
2187 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2188 if (proto_mask & ~kAllowedProtoMask) {
2189 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
2190 }
2191 wpa_ssid->proto = proto_mask;
2192 wpa_printf(MSG_MSGDUMP, "proto: 0x%x", wpa_ssid->proto);
2193 resetInternalStateAfterParamsUpdate();
2194 return ndk::ScopedAStatus::ok();
2195 }
2196
2197 std::pair<ProtoMask, ndk::ScopedAStatus>
getProtoInternal()2198 StaNetwork::getProtoInternal()
2199 {
2200 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2201 uint32_t proto_mask = wpa_ssid->proto & kAllowedProtoMask;
2202 return {static_cast<ProtoMask>(proto_mask), ndk::ScopedAStatus::ok()};
2203 }
2204
setGroupCipherInternal(GroupCipherMask mask)2205 ndk::ScopedAStatus StaNetwork::setGroupCipherInternal(
2206 GroupCipherMask mask)
2207 {
2208 uint32_t group_cipher_mask = static_cast<uint32_t>(mask);
2209 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2210 if (group_cipher_mask & ~kAllowedGroupCipherMask) {
2211 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
2212 }
2213 wpa_ssid->group_cipher = group_cipher_mask;
2214 wpa_printf(MSG_MSGDUMP, "group_cipher: 0x%x", wpa_ssid->group_cipher);
2215 resetInternalStateAfterParamsUpdate();
2216 return ndk::ScopedAStatus::ok();
2217 }
2218
2219 std::pair<GroupCipherMask, ndk::ScopedAStatus>
getGroupCipherInternal()2220 StaNetwork::getGroupCipherInternal()
2221 {
2222 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2223 uint32_t group_cipher_mask = wpa_ssid->group_cipher & kAllowedGroupCipherMask;
2224 return {static_cast<GroupCipherMask>(group_cipher_mask),
2225 ndk::ScopedAStatus::ok()};
2226 }
2227
setPairwiseCipherInternal(PairwiseCipherMask mask)2228 ndk::ScopedAStatus StaNetwork::setPairwiseCipherInternal(
2229 PairwiseCipherMask mask)
2230 {
2231 uint32_t pairwise_cipher_mask = static_cast<uint32_t>(mask);
2232 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2233 if (pairwise_cipher_mask & ~kAllowedPairwisewCipherMask) {
2234 return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
2235 }
2236 wpa_ssid->pairwise_cipher = pairwise_cipher_mask;
2237 wpa_printf(
2238 MSG_MSGDUMP, "pairwise_cipher: 0x%x", wpa_ssid->pairwise_cipher);
2239 resetInternalStateAfterParamsUpdate();
2240 return ndk::ScopedAStatus::ok();
2241 }
2242
2243 std::pair<PairwiseCipherMask, ndk::ScopedAStatus>
getPairwiseCipherInternal()2244 StaNetwork::getPairwiseCipherInternal()
2245 {
2246 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2247 uint32_t pairwise_cipher_mask = wpa_ssid->pairwise_cipher & kAllowedPairwisewCipherMask;
2248 return {static_cast<PairwiseCipherMask>(pairwise_cipher_mask),
2249 ndk::ScopedAStatus::ok()};
2250 }
2251
setRoamingConsortiumSelectionInternal(const std::vector<uint8_t> & selectedRcoi)2252 ndk::ScopedAStatus StaNetwork::setRoamingConsortiumSelectionInternal(
2253 const std::vector<uint8_t> &selectedRcoi)
2254 {
2255 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2256 if (wpa_ssid == NULL) {
2257 return createStatus(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
2258 }
2259
2260 if (setByteArrayFieldAndResetState(
2261 selectedRcoi.data(), selectedRcoi.size(),
2262 &(wpa_ssid->roaming_consortium_selection),
2263 &(wpa_ssid->roaming_consortium_selection_len),
2264 "roaming_consortium_selection")) {
2265 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
2266 }
2267
2268 resetInternalStateAfterParamsUpdate();
2269 return ndk::ScopedAStatus::ok();
2270 }
2271
2272 /**
2273 * Retrieve the underlying |wpa_ssid| struct pointer for
2274 * this network.
2275 * If the underlying network is removed or the interface
2276 * this network belong to
2277 * is removed, all RPC method calls on this object will
2278 * return failure.
2279 */
retrieveNetworkPtr()2280 struct wpa_ssid *StaNetwork::retrieveNetworkPtr()
2281 {
2282 wpa_supplicant *wpa_s = retrieveIfacePtr();
2283 if (!wpa_s)
2284 return nullptr;
2285 return wpa_config_get_network(wpa_s->conf, network_id_);
2286 }
2287
2288 /**
2289 * Retrieve the underlying |wpa_supplicant| struct
2290 * pointer for
2291 * this network.
2292 */
retrieveIfacePtr()2293 struct wpa_supplicant *StaNetwork::retrieveIfacePtr()
2294 {
2295 return wpa_supplicant_get_iface(wpa_global_, ifname_.c_str());
2296 }
2297
2298 /**
2299 * Check if the provided psk passhrase is valid or not.
2300 *
2301 * Returns 0 if valid, 1 otherwise.
2302 */
isPskPassphraseValid(const std::string & psk)2303 int StaNetwork::isPskPassphraseValid(const std::string &psk)
2304 {
2305 if (psk.size() <
2306 static_cast<uint32_t>(ISupplicantStaNetwork::
2307 PSK_PASSPHRASE_MIN_LEN_IN_BYTES) ||
2308 psk.size() >
2309 static_cast<uint32_t>(ISupplicantStaNetwork::
2310 PSK_PASSPHRASE_MAX_LEN_IN_BYTES)) {
2311 return 1;
2312 }
2313 if (has_ctrl_char((u8 *)psk.c_str(), psk.size())) {
2314 return 1;
2315 }
2316 return 0;
2317 }
2318
2319 /**
2320 * Reset internal wpa_supplicant state machine state
2321 * after params update (except
2322 * bssid).
2323 */
resetInternalStateAfterParamsUpdate()2324 void StaNetwork::resetInternalStateAfterParamsUpdate()
2325 {
2326 struct wpa_supplicant *wpa_s = retrieveIfacePtr();
2327 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2328
2329 wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_ssid);
2330
2331 if (wpa_s->current_ssid == wpa_ssid || wpa_s->current_ssid == NULL) {
2332 /*
2333 * Invalidate the EAP session cache if
2334 * anything in the
2335 * current or previously used
2336 * configuration changes.
2337 */
2338 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2339 }
2340 }
2341
2342 /**
2343 * Helper function to set value in a string field in |wpa_ssid| structue
2344 * instance for this network.
2345 * This function frees any existing data in these fields.
2346 */
setStringFieldAndResetState(const char * value,uint8_t ** to_update_field,const char * hexdump_prefix)2347 int StaNetwork::setStringFieldAndResetState(
2348 const char *value, uint8_t **to_update_field, const char *hexdump_prefix)
2349 {
2350 return setStringFieldAndResetState(
2351 value, (char **)to_update_field, hexdump_prefix);
2352 }
2353
2354 /**
2355 * Helper function to set value in a string field in |wpa_ssid| structue
2356 * instance for this network.
2357 * This function frees any existing data in these fields.
2358 */
setStringFieldAndResetState(const char * value,char ** to_update_field,const char * hexdump_prefix)2359 int StaNetwork::setStringFieldAndResetState(
2360 const char *value, char **to_update_field, const char *hexdump_prefix)
2361 {
2362 int value_len = strlen(value);
2363 if (*to_update_field) {
2364 os_free(*to_update_field);
2365 }
2366 *to_update_field = dup_binstr(value, value_len);
2367 if (!(*to_update_field)) {
2368 return 1;
2369 }
2370 wpa_hexdump_ascii(
2371 MSG_MSGDUMP, hexdump_prefix, *to_update_field, value_len);
2372 resetInternalStateAfterParamsUpdate();
2373 return 0;
2374 }
2375
2376 /**
2377 * Helper function to set value in a string key field in |wpa_ssid| structue
2378 * instance for this network.
2379 * This function frees any existing data in these fields.
2380 */
setStringKeyFieldAndResetState(const char * value,char ** to_update_field,const char * hexdump_prefix)2381 int StaNetwork::setStringKeyFieldAndResetState(
2382 const char *value, char **to_update_field, const char *hexdump_prefix)
2383 {
2384 int value_len = strlen(value);
2385 if (*to_update_field) {
2386 str_clear_free(*to_update_field);
2387 }
2388 *to_update_field = dup_binstr(value, value_len);
2389 if (!(*to_update_field)) {
2390 return 1;
2391 }
2392 wpa_hexdump_ascii_key(
2393 MSG_MSGDUMP, hexdump_prefix, *to_update_field, value_len);
2394 resetInternalStateAfterParamsUpdate();
2395 return 0;
2396 }
2397
2398 /**
2399 * Helper function to set value in a string field with a corresponding length
2400 * field in |wpa_ssid| structure instance for this network.
2401 * This function frees any existing data in these fields.
2402 */
setByteArrayField(const uint8_t * value,const size_t value_len,uint8_t ** to_update_field,size_t * to_update_field_len,const char * hexdump_prefix,bool resetState)2403 int StaNetwork::setByteArrayField(
2404 const uint8_t *value, const size_t value_len, uint8_t **to_update_field,
2405 size_t *to_update_field_len, const char *hexdump_prefix, bool resetState)
2406 {
2407 if (*to_update_field) {
2408 os_free(*to_update_field);
2409 }
2410 *to_update_field = (uint8_t *)os_malloc(value_len);
2411 if (!(*to_update_field)) {
2412 return 1;
2413 }
2414 os_memcpy(*to_update_field, value, value_len);
2415 *to_update_field_len = value_len;
2416
2417 wpa_hexdump_ascii(
2418 MSG_MSGDUMP, hexdump_prefix, *to_update_field,
2419 *to_update_field_len);
2420
2421 if (resetState) {
2422 resetInternalStateAfterParamsUpdate();
2423 }
2424 return 0;
2425 }
2426
2427 /**
2428 * Helper function to set value in a string field with a corresponding length
2429 * field in |wpa_ssid| structure instance for this network.
2430 * This function frees any existing data in these fields.
2431 */
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)2432 int StaNetwork::setByteArrayFieldAndResetState(
2433 const uint8_t *value, const size_t value_len, uint8_t **to_update_field,
2434 size_t *to_update_field_len, const char *hexdump_prefix)
2435 {
2436 return setByteArrayField(value, value_len, to_update_field,
2437 to_update_field_len, hexdump_prefix, true);
2438 }
2439
2440 /**
2441 * Helper function to set value in a string key field with a corresponding
2442 * length field in |wpa_ssid| structue instance for this network.
2443 * This function frees any existing data in these fields.
2444 */
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)2445 int StaNetwork::setByteArrayKeyFieldAndResetState(
2446 const uint8_t *value, const size_t value_len, uint8_t **to_update_field,
2447 size_t *to_update_field_len, const char *hexdump_prefix)
2448 {
2449 if (*to_update_field) {
2450 bin_clear_free(*to_update_field, *to_update_field_len);
2451 }
2452 *to_update_field = (uint8_t *)os_malloc(value_len);
2453 if (!(*to_update_field)) {
2454 return 1;
2455 }
2456 os_memcpy(*to_update_field, value, value_len);
2457 *to_update_field_len = value_len;
2458
2459 wpa_hexdump_ascii_key(
2460 MSG_MSGDUMP, hexdump_prefix, *to_update_field,
2461 *to_update_field_len);
2462 resetInternalStateAfterParamsUpdate();
2463 return 0;
2464 }
2465
2466 /**
2467 * Helper function to set the fast transition bits in the key management
2468 * bitmask, to allow FT support when possible.
2469 */
setFastTransitionKeyMgmt(uint32_t & key_mgmt_mask)2470 void StaNetwork::setFastTransitionKeyMgmt(uint32_t &key_mgmt_mask)
2471 {
2472 struct wpa_supplicant *wpa_s = retrieveIfacePtr();
2473 int res;
2474 struct wpa_driver_capa capa;
2475
2476 if (key_mgmt_mask & WPA_KEY_MGMT_PSK) {
2477 key_mgmt_mask |= WPA_KEY_MGMT_FT_PSK;
2478 }
2479
2480 if (key_mgmt_mask & WPA_KEY_MGMT_IEEE8021X) {
2481 key_mgmt_mask |= WPA_KEY_MGMT_FT_IEEE8021X;
2482 }
2483
2484 res = wpa_drv_get_capa(wpa_s, &capa);
2485 if (res == 0) {
2486 #ifdef CONFIG_IEEE80211R
2487 #ifdef CONFIG_SAE
2488 if ((key_mgmt_mask & WPA_KEY_MGMT_SAE) &&
2489 (capa.key_mgmt_iftype[WPA_IF_STATION] & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE)) {
2490 key_mgmt_mask |= WPA_KEY_MGMT_FT_SAE;
2491 }
2492 #endif
2493 #ifdef CONFIG_FILS
2494 if ((key_mgmt_mask & WPA_KEY_MGMT_FILS_SHA256) &&
2495 (capa.key_mgmt_iftype[WPA_IF_STATION] &
2496 WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256)) {
2497 key_mgmt_mask |= WPA_KEY_MGMT_FT_FILS_SHA256;
2498 }
2499
2500 if ((key_mgmt_mask & WPA_KEY_MGMT_FILS_SHA384) &&
2501 (capa.key_mgmt_iftype[WPA_IF_STATION] &
2502 WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384)) {
2503 key_mgmt_mask |= WPA_KEY_MGMT_FT_FILS_SHA384;
2504 }
2505 #endif
2506 #ifdef CONFIG_SUITEB192
2507 if ((key_mgmt_mask & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) &&
2508 (capa.key_mgmt_iftype[WPA_IF_STATION] &
2509 WPA_DRIVER_CAPA_KEY_MGMT_FT_802_1X_SHA384)) {
2510 key_mgmt_mask |= WPA_KEY_MGMT_FT_IEEE8021X_SHA384;
2511 }
2512 #endif
2513 #endif
2514 }
2515
2516 }
2517
2518 /**
2519 * Helper function to reset the fast transition bits in the key management
2520 * bitmask.
2521 */
resetFastTransitionKeyMgmt(uint32_t & key_mgmt_mask)2522 void StaNetwork::resetFastTransitionKeyMgmt(uint32_t &key_mgmt_mask)
2523 {
2524 if (key_mgmt_mask & WPA_KEY_MGMT_PSK) {
2525 key_mgmt_mask &= ~WPA_KEY_MGMT_FT_PSK;
2526 }
2527
2528 if (key_mgmt_mask & WPA_KEY_MGMT_IEEE8021X) {
2529 key_mgmt_mask &= ~WPA_KEY_MGMT_FT_IEEE8021X;
2530 }
2531 #ifdef CONFIG_IEEE80211R
2532 #ifdef CONFIG_SAE
2533 if (key_mgmt_mask & WPA_KEY_MGMT_SAE) {
2534 key_mgmt_mask &= ~WPA_KEY_MGMT_FT_SAE;
2535 }
2536 #endif
2537 #ifdef CONFIG_FILS
2538 if (key_mgmt_mask & WPA_KEY_MGMT_FILS_SHA256) {
2539 key_mgmt_mask &= ~WPA_KEY_MGMT_FT_FILS_SHA256;
2540 }
2541
2542 if (key_mgmt_mask & WPA_KEY_MGMT_FILS_SHA384) {
2543 key_mgmt_mask &= ~WPA_KEY_MGMT_FT_FILS_SHA384;
2544 }
2545 #endif
2546 #ifdef CONFIG_SUITEB192
2547 if (key_mgmt_mask & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
2548 key_mgmt_mask &= ~WPA_KEY_MGMT_FT_IEEE8021X_SHA384;
2549 }
2550 #endif
2551 #endif
2552 }
2553
2554 /**
2555 * Helper function to enable erp keys generation while connecting to FILS
2556 * enabled APs.
2557 */
setEapErpInternal(bool enable)2558 ndk::ScopedAStatus StaNetwork::setEapErpInternal(bool enable)
2559 {
2560 #ifdef CONFIG_FILS
2561 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2562 wpa_ssid->eap.erp = enable ? 1 : 0;
2563 return ndk::ScopedAStatus::ok();
2564 #else /* CONFIG_FILS */
2565 return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
2566 #endif /* CONFIG_FILS */
2567 }
2568
setSaeH2eModeInternal(SaeH2eMode mode)2569 ndk::ScopedAStatus StaNetwork::setSaeH2eModeInternal(
2570 SaeH2eMode mode)
2571 {
2572 struct wpa_supplicant *wpa_s = retrieveIfacePtr();
2573 switch (mode) {
2574 case SaeH2eMode::DISABLED:
2575 wpa_s->conf->sae_pwe = 0;
2576 break;
2577 case SaeH2eMode::H2E_MANDATORY:
2578 wpa_s->conf->sae_pwe = 1;
2579 break;
2580 case SaeH2eMode::H2E_OPTIONAL:
2581 wpa_s->conf->sae_pwe = 2;
2582 break;
2583 }
2584 resetInternalStateAfterParamsUpdate();
2585 return ndk::ScopedAStatus::ok();
2586 }
2587
enableSaePkOnlyModeInternal(bool enable)2588 ndk::ScopedAStatus StaNetwork::enableSaePkOnlyModeInternal(bool enable)
2589 {
2590 #ifdef CONFIG_SAE_PK
2591 struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
2592 wpa_ssid->sae_pk = enable ? SAE_PK_MODE_ONLY : SAE_PK_MODE_AUTOMATIC;
2593 resetInternalStateAfterParamsUpdate();
2594 return ndk::ScopedAStatus::ok();
2595 #else
2596 return createStatus(SupplicantStatusCode::FAILURE_UNSUPPORTED);
2597 #endif
2598 }
2599
2600 } // namespace supplicant
2601 } // namespace wifi
2602 } // namespace hardware
2603 } // namespace android
2604 } // namespace aidl
2605