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