1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.server.wifi; 17 18 import android.content.Context; 19 import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetwork; 20 import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetworkCallback; 21 import android.hardware.wifi.supplicant.V1_0.SupplicantStatus; 22 import android.hardware.wifi.supplicant.V1_0.SupplicantStatusCode; 23 import android.net.wifi.SecurityParams; 24 import android.net.wifi.WifiConfiguration; 25 import android.net.wifi.WifiEnterpriseConfig; 26 import android.net.wifi.WifiEnterpriseConfig.Ocsp; 27 import android.net.wifi.WifiManager; 28 import android.os.RemoteException; 29 import android.text.TextUtils; 30 import android.util.Log; 31 32 import com.android.internal.annotations.VisibleForTesting; 33 import com.android.server.wifi.util.ArrayUtils; 34 import com.android.server.wifi.util.GeneralUtil.Mutable; 35 import com.android.server.wifi.util.NativeUtil; 36 import com.android.wifi.resources.R; 37 38 import org.json.JSONException; 39 import org.json.JSONObject; 40 41 import java.io.UnsupportedEncodingException; 42 import java.net.URLDecoder; 43 import java.net.URLEncoder; 44 import java.util.ArrayList; 45 import java.util.BitSet; 46 import java.util.HashMap; 47 import java.util.Iterator; 48 import java.util.Map; 49 import java.util.regex.Matcher; 50 import java.util.regex.Pattern; 51 52 import javax.annotation.concurrent.ThreadSafe; 53 54 55 /** 56 * Wrapper class for ISupplicantStaNetwork HAL calls. Gets and sets supplicant sta network variables 57 * and interacts with networks. 58 * Public fields should be treated as invalid until their 'get' method is called, which will set the 59 * value if it returns true 60 * To maintain thread-safety, the locking protocol is that every non-static method (regardless of 61 * access level) acquires mLock. 62 */ 63 @ThreadSafe 64 public class SupplicantStaNetworkHal { 65 private static final String TAG = "SupplicantStaNetworkHal"; 66 @VisibleForTesting 67 public static final String ID_STRING_KEY_FQDN = "fqdn"; 68 @VisibleForTesting 69 public static final String ID_STRING_KEY_CREATOR_UID = "creatorUid"; 70 @VisibleForTesting 71 public static final String ID_STRING_KEY_CONFIG_KEY = "configKey"; 72 73 /** 74 * Regex pattern for extracting the GSM sim authentication response params from a string. 75 * Matches a strings like the following: "[:<kc_value>:<sres_value>]"; 76 */ 77 private static final Pattern GSM_AUTH_RESPONSE_PARAMS_PATTERN = 78 Pattern.compile(":([0-9a-fA-F]+):([0-9a-fA-F]+)"); 79 /** 80 * Regex pattern for extracting the UMTS sim authentication response params from a string. 81 * Matches a strings like the following: ":<ik_value>:<ck_value>:<res_value>"; 82 */ 83 private static final Pattern UMTS_AUTH_RESPONSE_PARAMS_PATTERN = 84 Pattern.compile("^:([0-9a-fA-F]+):([0-9a-fA-F]+):([0-9a-fA-F]+)$"); 85 /** 86 * Regex pattern for extracting the UMTS sim auts response params from a string. 87 * Matches a strings like the following: ":<auts_value>"; 88 */ 89 private static final Pattern UMTS_AUTS_RESPONSE_PARAMS_PATTERN = 90 Pattern.compile("^:([0-9a-fA-F]+)$"); 91 92 private final Object mLock = new Object(); 93 private final Context mContext; 94 private final String mIfaceName; 95 private final WifiMonitor mWifiMonitor; 96 private final WifiGlobals mWifiGlobals; 97 private ISupplicantStaNetwork mISupplicantStaNetwork; 98 private ISupplicantStaNetworkCallback mISupplicantStaNetworkCallback; 99 100 private boolean mVerboseLoggingEnabled = false; 101 // Network variables read from wpa_supplicant. 102 private int mNetworkId; 103 private ArrayList<Byte> mSsid; 104 private byte[/* 6 */] mBssid; 105 private boolean mScanSsid; 106 private int mKeyMgmtMask; 107 private int mProtoMask; 108 private int mAuthAlgMask; 109 private int mGroupCipherMask; 110 private int mPairwiseCipherMask; 111 private int mGroupMgmtCipherMask; 112 private String mPskPassphrase; 113 private String mSaePassword; 114 private String mSaePasswordId; 115 private byte[] mPsk; 116 private ArrayList<Byte> mWepKey; 117 private int mWepTxKeyIdx; 118 private boolean mRequirePmf; 119 private String mIdStr; 120 private int mEapMethod; 121 private int mEapPhase2Method; 122 private ArrayList<Byte> mEapIdentity; 123 private ArrayList<Byte> mEapAnonymousIdentity; 124 private ArrayList<Byte> mEapPassword; 125 private String mEapCACert; 126 private String mEapCAPath; 127 private String mEapClientCert; 128 private String mEapPrivateKeyId; 129 private String mEapSubjectMatch; 130 private String mEapAltSubjectMatch; 131 private boolean mEapEngine; 132 private String mEapEngineID; 133 private String mEapDomainSuffixMatch; 134 private @Ocsp int mOcsp; 135 private String mWapiCertSuite; 136 private long mAdvanceKeyMgmtFeatures; 137 SupplicantStaNetworkHal(ISupplicantStaNetwork iSupplicantStaNetwork, String ifaceName, Context context, WifiMonitor monitor, WifiGlobals wifiGlobals, long advanceKeyMgmtFeature)138 SupplicantStaNetworkHal(ISupplicantStaNetwork iSupplicantStaNetwork, String ifaceName, 139 Context context, WifiMonitor monitor, WifiGlobals wifiGlobals, 140 long advanceKeyMgmtFeature) { 141 mISupplicantStaNetwork = iSupplicantStaNetwork; 142 mContext = context; 143 mIfaceName = ifaceName; 144 mWifiMonitor = monitor; 145 mWifiGlobals = wifiGlobals; 146 mAdvanceKeyMgmtFeatures = advanceKeyMgmtFeature; 147 } 148 149 /** 150 * Enable/Disable verbose logging. 151 * 152 * @param enable true to enable, false to disable. 153 */ enableVerboseLogging(boolean enable)154 void enableVerboseLogging(boolean enable) { 155 synchronized (mLock) { 156 mVerboseLoggingEnabled = enable; 157 } 158 } 159 160 /** 161 * Read network variables from wpa_supplicant into the provided WifiConfiguration object. 162 * 163 * @param config WifiConfiguration object to be populated. 164 * @param networkExtras Map of network extras parsed from wpa_supplicant. 165 * @return true if succeeds, false otherwise. 166 * @throws IllegalArgumentException on malformed configuration params. 167 */ 168 @VisibleForTesting loadWifiConfiguration(WifiConfiguration config, Map<String, String> networkExtras)169 public boolean loadWifiConfiguration(WifiConfiguration config, 170 Map<String, String> networkExtras) { 171 synchronized (mLock) { 172 if (config == null) return false; 173 /** SSID */ 174 config.SSID = null; 175 if (getSsid() && !ArrayUtils.isEmpty(mSsid)) { 176 config.SSID = NativeUtil.encodeSsid(mSsid); 177 } else { 178 Log.e(TAG, "failed to read ssid"); 179 return false; 180 } 181 /** Network Id */ 182 config.networkId = -1; 183 if (getId()) { 184 config.networkId = mNetworkId; 185 } else { 186 Log.e(TAG, "getId failed"); 187 return false; 188 } 189 /** BSSID */ 190 config.getNetworkSelectionStatus().setNetworkSelectionBSSID(null); 191 if (getBssid() && !ArrayUtils.isEmpty(mBssid)) { 192 config.getNetworkSelectionStatus().setNetworkSelectionBSSID( 193 NativeUtil.macAddressFromByteArray(mBssid)); 194 } 195 /** Scan SSID (Is Hidden Network?) */ 196 config.hiddenSSID = false; 197 if (getScanSsid()) { 198 config.hiddenSSID = mScanSsid; 199 } 200 /** Require PMF*/ 201 config.requirePmf = false; 202 if (getRequirePmf()) { 203 config.requirePmf = mRequirePmf; 204 } 205 /** WEP keys **/ 206 config.wepTxKeyIndex = -1; 207 if (getWepTxKeyIdx()) { 208 config.wepTxKeyIndex = mWepTxKeyIdx; 209 } 210 for (int i = 0; i < 4; i++) { 211 config.wepKeys[i] = null; 212 if (getWepKey(i) && !ArrayUtils.isEmpty(mWepKey)) { 213 config.wepKeys[i] = NativeUtil.bytesToHexOrQuotedString(mWepKey); 214 } 215 } 216 217 /** allowedKeyManagement */ 218 if (getKeyMgmt()) { 219 BitSet keyMgmtMask = supplicantToWifiConfigurationKeyMgmtMask(mKeyMgmtMask); 220 keyMgmtMask = removeFastTransitionFlags(keyMgmtMask); 221 keyMgmtMask = removeSha256KeyMgmtFlags(keyMgmtMask); 222 keyMgmtMask = removePskSaeUpgradableTypeFlags(keyMgmtMask); 223 config.setSecurityParams(keyMgmtMask); 224 config.enableFils( 225 keyMgmtMask.get(WifiConfiguration.KeyMgmt.FILS_SHA256), 226 keyMgmtMask.get(WifiConfiguration.KeyMgmt.FILS_SHA384)); 227 } 228 229 // supplicant only have one valid security type, it won't be a disbled params. 230 SecurityParams securityParams = config.getDefaultSecurityParams(); 231 232 /** PSK pass phrase */ 233 config.preSharedKey = null; 234 if (getPskPassphrase() && !TextUtils.isEmpty(mPskPassphrase)) { 235 if (securityParams.isSecurityType(WifiConfiguration.SECURITY_TYPE_WAPI_PSK)) { 236 config.preSharedKey = mPskPassphrase; 237 } else { 238 config.preSharedKey = NativeUtil.addEnclosingQuotes(mPskPassphrase); 239 } 240 } else if (getPsk() && !ArrayUtils.isEmpty(mPsk)) { 241 config.preSharedKey = NativeUtil.hexStringFromByteArray(mPsk); 242 } /* Do not read SAE password */ 243 244 /** metadata: idstr */ 245 if (getIdStr() && !TextUtils.isEmpty(mIdStr)) { 246 Map<String, String> metadata = parseNetworkExtra(mIdStr); 247 networkExtras.putAll(metadata); 248 } else { 249 Log.w(TAG, "getIdStr failed or empty"); 250 } 251 252 /** WAPI Cert Suite */ 253 if (securityParams.isSecurityType(WifiConfiguration.SECURITY_TYPE_WAPI_CERT)) { 254 if (config.enterpriseConfig == null) { 255 return false; 256 } 257 config.enterpriseConfig.setEapMethod( 258 WifiEnterpriseConfig.Eap.WAPI_CERT); 259 /** WAPI Certificate Suite. */ 260 if (getWapiCertSuite() && !TextUtils.isEmpty(mWapiCertSuite)) { 261 config.enterpriseConfig.setWapiCertSuite(mWapiCertSuite); 262 } 263 return true; 264 } 265 return loadWifiEnterpriseConfig(config.SSID, config.enterpriseConfig); 266 } 267 } 268 269 /** 270 * Save an entire WifiConfiguration to wpa_supplicant via HIDL. 271 * 272 * @param config WifiConfiguration object to be saved. 273 * @return true if succeeds, false otherwise. 274 * @throws IllegalArgumentException on malformed configuration params. 275 */ saveWifiConfiguration(WifiConfiguration config)276 public boolean saveWifiConfiguration(WifiConfiguration config) { 277 synchronized (mLock) { 278 if (config == null) return false; 279 /** SSID */ 280 if (config.SSID != null) { 281 if (!setSsid(NativeUtil.decodeSsid(config.SSID))) { 282 Log.e(TAG, "failed to set SSID: " + config.SSID); 283 return false; 284 } 285 } 286 /** BSSID */ 287 String bssidStr = config.getNetworkSelectionStatus().getNetworkSelectionBSSID(); 288 if (bssidStr != null) { 289 byte[] bssid = NativeUtil.macAddressToByteArray(bssidStr); 290 if (!setBssid(bssid)) { 291 Log.e(TAG, "failed to set BSSID: " + bssidStr); 292 return false; 293 } 294 } 295 /** HiddenSSID */ 296 if (!setScanSsid(config.hiddenSSID)) { 297 Log.e(TAG, config.SSID + ": failed to set hiddenSSID: " + config.hiddenSSID); 298 return false; 299 } 300 301 SecurityParams securityParams = config.getNetworkSelectionStatus() 302 .getCandidateSecurityParams(); 303 if (null == securityParams) { 304 Log.wtf(TAG, "No available security params."); 305 return false; 306 } 307 Log.d(TAG, "The target security params: " + securityParams); 308 309 /** RequirePMF */ 310 if (!setRequirePmf(securityParams.isRequirePmf())) { 311 Log.e(TAG, config.SSID + ": failed to set requirePMF: " + config.requirePmf); 312 return false; 313 } 314 /** Key Management Scheme */ 315 BitSet allowedKeyManagement = securityParams.getAllowedKeyManagement(); 316 if (allowedKeyManagement.cardinality() != 0) { 317 // Add FT flags if supported. 318 BitSet keyMgmtMask = addFastTransitionFlags(allowedKeyManagement); 319 // Add SHA256 key management flags. 320 keyMgmtMask = addSha256KeyMgmtFlags(keyMgmtMask); 321 // Add upgradable type key management flags for PSK/SAE. 322 keyMgmtMask = addPskSaeUpgradableTypeFlagsIfSupported( 323 config, keyMgmtMask); 324 if (!setKeyMgmt(wifiConfigurationToSupplicantKeyMgmtMask(keyMgmtMask))) { 325 Log.e(TAG, "failed to set Key Management"); 326 return false; 327 } 328 // Check and set SuiteB configurations. 329 if (keyMgmtMask.get(WifiConfiguration.KeyMgmt.SUITE_B_192) 330 && !saveSuiteBConfig(config)) { 331 Log.e(TAG, "Failed to set Suite-B-192 configuration"); 332 return false; 333 } 334 } 335 /** Security Protocol */ 336 BitSet allowedProtocols = securityParams.getAllowedProtocols(); 337 if (allowedProtocols.cardinality() != 0 338 && !setProto(wifiConfigurationToSupplicantProtoMask(allowedProtocols))) { 339 Log.e(TAG, "failed to set Security Protocol"); 340 return false; 341 } 342 /** Auth Algorithm */ 343 BitSet allowedAuthAlgorithms = securityParams.getAllowedAuthAlgorithms(); 344 if (allowedAuthAlgorithms.cardinality() != 0 345 && !setAuthAlg(wifiConfigurationToSupplicantAuthAlgMask( 346 allowedAuthAlgorithms))) { 347 Log.e(TAG, "failed to set AuthAlgorithm"); 348 return false; 349 } 350 /** Group Cipher */ 351 BitSet allowedGroupCiphers = securityParams.getAllowedGroupCiphers(); 352 if (allowedGroupCiphers.cardinality() != 0 353 && (!setGroupCipher(wifiConfigurationToSupplicantGroupCipherMask( 354 allowedGroupCiphers)))) { 355 Log.e(TAG, "failed to set Group Cipher"); 356 return false; 357 } 358 /** Pairwise Cipher*/ 359 BitSet allowedPairwiseCiphers = securityParams.getAllowedPairwiseCiphers(); 360 if (allowedPairwiseCiphers.cardinality() != 0 361 && !setPairwiseCipher(wifiConfigurationToSupplicantPairwiseCipherMask( 362 allowedPairwiseCiphers))) { 363 Log.e(TAG, "failed to set PairwiseCipher"); 364 return false; 365 } 366 /** Pre Shared Key */ 367 // For PSK, this can either be quoted ASCII passphrase or hex string for raw psk. 368 // For SAE, password must be a quoted ASCII string 369 if (config.preSharedKey != null) { 370 if (securityParams.isSecurityType(WifiConfiguration.SECURITY_TYPE_WAPI_PSK)) { 371 if (!setPskPassphrase(config.preSharedKey)) { 372 Log.e(TAG, "failed to set wapi psk passphrase"); 373 return false; 374 } 375 } else if (config.preSharedKey.startsWith("\"")) { 376 if (securityParams.isSecurityType(WifiConfiguration.SECURITY_TYPE_SAE)) { 377 /* WPA3 case, field is SAE Password */ 378 if (!setSaePassword( 379 NativeUtil.removeEnclosingQuotes(config.preSharedKey))) { 380 Log.e(TAG, "failed to set sae password"); 381 return false; 382 } 383 } else { 384 if (!setPskPassphrase( 385 NativeUtil.removeEnclosingQuotes(config.preSharedKey))) { 386 Log.e(TAG, "failed to set psk passphrase"); 387 return false; 388 } 389 } 390 } else { 391 if (securityParams.isSecurityType(WifiConfiguration.SECURITY_TYPE_SAE)) { 392 return false; 393 } 394 if (!setPsk(NativeUtil.hexStringToByteArray(config.preSharedKey))) { 395 Log.e(TAG, "failed to set psk"); 396 return false; 397 } 398 } 399 } 400 /** Wep Keys */ 401 boolean hasSetKey = false; 402 if (config.wepKeys != null) { 403 for (int i = 0; i < config.wepKeys.length; i++) { 404 if (config.wepKeys[i] != null) { 405 if (!setWepKey( 406 i, NativeUtil.hexOrQuotedStringToBytes(config.wepKeys[i]))) { 407 Log.e(TAG, "failed to set wep_key " + i); 408 return false; 409 } 410 hasSetKey = true; 411 } 412 } 413 } 414 /** Wep Tx Key Idx */ 415 if (hasSetKey) { 416 if (!setWepTxKeyIdx(config.wepTxKeyIndex)) { 417 Log.e(TAG, "failed to set wep_tx_keyidx: " + config.wepTxKeyIndex); 418 return false; 419 } 420 } 421 /** metadata: FQDN + ConfigKey + CreatorUid */ 422 final Map<String, String> metadata = new HashMap<String, String>(); 423 if (config.isPasspoint()) { 424 metadata.put(ID_STRING_KEY_FQDN, config.FQDN); 425 } 426 metadata.put(ID_STRING_KEY_CONFIG_KEY, config.getProfileKey()); 427 metadata.put(ID_STRING_KEY_CREATOR_UID, Integer.toString(config.creatorUid)); 428 if (!setIdStr(createNetworkExtra(metadata))) { 429 Log.e(TAG, "failed to set id string"); 430 return false; 431 } 432 /** UpdateIdentifier */ 433 if (config.updateIdentifier != null 434 && !setUpdateIdentifier(Integer.parseInt(config.updateIdentifier))) { 435 Log.e(TAG, "failed to set update identifier"); 436 return false; 437 } 438 /** SAE configuration */ 439 if (securityParams.isSecurityType(WifiConfiguration.SECURITY_TYPE_SAE) 440 && getV1_4StaNetwork() != null) { 441 /** 442 * Hash-to-Element preference. 443 * For devices that don't support H2E, H2E mode will be permanently disabled. 444 * Devices that support H2E will enable both legacy and H2E mode by default, 445 * and will connect to SAE networks with H2E if possible, unless H2E only 446 * mode is enabled, and then the device will not connect to SAE networks in 447 * legacy mode. 448 */ 449 if (!mWifiGlobals.isWpa3SaeH2eSupported() && securityParams.isSaeH2eOnlyMode()) { 450 Log.e(TAG, "This device does not support SAE H2E."); 451 return false; 452 } 453 byte mode = mWifiGlobals.isWpa3SaeH2eSupported() 454 ? android.hardware.wifi.supplicant.V1_4 455 .ISupplicantStaNetwork.SaeH2eMode.H2E_OPTIONAL 456 : android.hardware.wifi.supplicant.V1_4 457 .ISupplicantStaNetwork.SaeH2eMode.DISABLED; 458 if (securityParams.isSaeH2eOnlyMode()) { 459 mode = android.hardware.wifi.supplicant.V1_4 460 .ISupplicantStaNetwork.SaeH2eMode.H2E_MANDATORY; 461 } 462 if (!setSaeH2eMode(mode)) { 463 Log.e(TAG, "failed to set H2E preference."); 464 return false; 465 } 466 } 467 // Finish here if no EAP config to set 468 if (config.enterpriseConfig != null 469 && config.enterpriseConfig.getEapMethod() != WifiEnterpriseConfig.Eap.NONE) { 470 if (config.enterpriseConfig.getEapMethod() == WifiEnterpriseConfig.Eap.WAPI_CERT) { 471 /** WAPI certificate suite name*/ 472 String param = config.enterpriseConfig 473 .getFieldValue(WifiEnterpriseConfig.WAPI_CERT_SUITE_KEY); 474 if (!TextUtils.isEmpty(param) && !setWapiCertSuite(param)) { 475 Log.e(TAG, config.SSID + ": failed to set WAPI certificate suite: " 476 + param); 477 return false; 478 } 479 return true; 480 } else if (!saveWifiEnterpriseConfig(config.SSID, config.enterpriseConfig)) { 481 return false; 482 } 483 } 484 485 // Now that the network is configured fully, start listening for callback events. 486 return tryRegisterCallback(config.networkId, config.SSID); 487 } 488 } 489 tryRegisterCallback_1_4(int networkId, String ssid)490 private boolean tryRegisterCallback_1_4(int networkId, String ssid) { 491 if (getV1_4StaNetwork() == null) return false; 492 493 SupplicantStaNetworkHalCallbackV1_4 callback = 494 new SupplicantStaNetworkHalCallbackV1_4(networkId, ssid); 495 if (!registerCallback_1_4(callback)) { 496 Log.e(TAG, "Failed to register V1.4 callback"); 497 return false; 498 } 499 mISupplicantStaNetworkCallback = callback; 500 return true; 501 } 502 tryRegisterCallback(int networkId, String ssid)503 private boolean tryRegisterCallback(int networkId, String ssid) { 504 /* try newer version fist. */ 505 if (getV1_4StaNetwork() != null) { 506 return tryRegisterCallback_1_4(networkId, ssid); 507 } 508 509 mISupplicantStaNetworkCallback = 510 new SupplicantStaNetworkHalCallback(networkId, ssid); 511 if (!registerCallback(mISupplicantStaNetworkCallback)) { 512 Log.e(TAG, "Failed to register callback"); 513 return false; 514 } 515 return true; 516 } 517 518 /** 519 * Read network variables from wpa_supplicant into the provided WifiEnterpriseConfig object. 520 * 521 * @param ssid SSID of the network. (Used for logging purposes only) 522 * @param eapConfig WifiEnterpriseConfig object to be populated. 523 * @return true if succeeds, false otherwise. 524 */ loadWifiEnterpriseConfig(String ssid, WifiEnterpriseConfig eapConfig)525 private boolean loadWifiEnterpriseConfig(String ssid, WifiEnterpriseConfig eapConfig) { 526 synchronized (mLock) { 527 if (eapConfig == null) return false; 528 /** EAP method */ 529 if (getEapMethod()) { 530 eapConfig.setEapMethod(supplicantToWifiConfigurationEapMethod(mEapMethod)); 531 } else { 532 // Invalid eap method could be because it's not an enterprise config. 533 Log.e(TAG, "failed to get eap method. Assumimg not an enterprise network"); 534 return true; 535 } 536 /** EAP Phase 2 method */ 537 if (getEapPhase2Method()) { 538 eapConfig.setPhase2Method( 539 supplicantToWifiConfigurationEapPhase2Method(mEapPhase2Method)); 540 } else { 541 // We cannot have an invalid eap phase 2 method. Return failure. 542 Log.e(TAG, "failed to get eap phase2 method"); 543 return false; 544 } 545 /** EAP Identity */ 546 if (getEapIdentity() && !ArrayUtils.isEmpty(mEapIdentity)) { 547 eapConfig.setFieldValue( 548 WifiEnterpriseConfig.IDENTITY_KEY, 549 NativeUtil.stringFromByteArrayList(mEapIdentity)); 550 } 551 /** EAP Anonymous Identity */ 552 if (getEapAnonymousIdentity() && !ArrayUtils.isEmpty(mEapAnonymousIdentity)) { 553 eapConfig.setFieldValue( 554 WifiEnterpriseConfig.ANON_IDENTITY_KEY, 555 NativeUtil.stringFromByteArrayList(mEapAnonymousIdentity)); 556 } 557 /** EAP Password */ 558 if (getEapPassword() && !ArrayUtils.isEmpty(mEapPassword)) { 559 eapConfig.setFieldValue( 560 WifiEnterpriseConfig.PASSWORD_KEY, 561 NativeUtil.stringFromByteArrayList(mEapPassword)); 562 } 563 /** EAP Client Cert */ 564 if (getEapClientCert() && !TextUtils.isEmpty(mEapClientCert)) { 565 eapConfig.setFieldValue(WifiEnterpriseConfig.CLIENT_CERT_KEY, mEapClientCert); 566 } 567 /** EAP CA Cert */ 568 if (getEapCACert() && !TextUtils.isEmpty(mEapCACert)) { 569 eapConfig.setFieldValue(WifiEnterpriseConfig.CA_CERT_KEY, mEapCACert); 570 } 571 /** EAP OCSP type */ 572 if (getOcsp()) { 573 eapConfig.setOcsp(mOcsp); 574 } 575 /** EAP Subject Match */ 576 if (getEapSubjectMatch() && !TextUtils.isEmpty(mEapSubjectMatch)) { 577 eapConfig.setFieldValue(WifiEnterpriseConfig.SUBJECT_MATCH_KEY, mEapSubjectMatch); 578 } 579 /** EAP Engine ID */ 580 if (getEapEngineID() && !TextUtils.isEmpty(mEapEngineID)) { 581 eapConfig.setFieldValue(WifiEnterpriseConfig.ENGINE_ID_KEY, mEapEngineID); 582 } 583 /** EAP Engine. Set this only if the engine id is non null. */ 584 if (getEapEngine() && !TextUtils.isEmpty(mEapEngineID)) { 585 eapConfig.setFieldValue( 586 WifiEnterpriseConfig.ENGINE_KEY, 587 mEapEngine 588 ? WifiEnterpriseConfig.ENGINE_ENABLE 589 : WifiEnterpriseConfig.ENGINE_DISABLE); 590 } 591 /** EAP Private Key */ 592 if (getEapPrivateKeyId() && !TextUtils.isEmpty(mEapPrivateKeyId)) { 593 eapConfig.setFieldValue(WifiEnterpriseConfig.PRIVATE_KEY_ID_KEY, mEapPrivateKeyId); 594 } 595 /** EAP Alt Subject Match */ 596 if (getEapAltSubjectMatch() && !TextUtils.isEmpty(mEapAltSubjectMatch)) { 597 eapConfig.setFieldValue( 598 WifiEnterpriseConfig.ALTSUBJECT_MATCH_KEY, mEapAltSubjectMatch); 599 } 600 /** EAP Domain Suffix Match */ 601 if (getEapDomainSuffixMatch() && !TextUtils.isEmpty(mEapDomainSuffixMatch)) { 602 eapConfig.setFieldValue( 603 WifiEnterpriseConfig.DOM_SUFFIX_MATCH_KEY, mEapDomainSuffixMatch); 604 } 605 /** EAP CA Path*/ 606 if (getEapCAPath() && !TextUtils.isEmpty(mEapCAPath)) { 607 eapConfig.setFieldValue(WifiEnterpriseConfig.CA_PATH_KEY, mEapCAPath); 608 } 609 return true; 610 } 611 } 612 613 /** 614 * Save network variables from the provided SuiteB configuration to wpa_supplicant. 615 * 616 * @param config WifiConfiguration object to be saved 617 * @return true if succeeds, false otherwise. 618 */ saveSuiteBConfig(WifiConfiguration config)619 private boolean saveSuiteBConfig(WifiConfiguration config) { 620 SecurityParams securityParams = config.getNetworkSelectionStatus() 621 .getCandidateSecurityParams(); 622 if (null == securityParams) { 623 Log.wtf(TAG, "No available security params."); 624 return false; 625 } 626 627 /** Group Cipher **/ 628 BitSet allowedGroupCiphers = securityParams.getAllowedGroupCiphers(); 629 if (allowedGroupCiphers.cardinality() != 0 630 && !setGroupCipher(wifiConfigurationToSupplicantGroupCipherMask( 631 allowedGroupCiphers))) { 632 Log.e(TAG, "failed to set Group Cipher"); 633 return false; 634 } 635 /** Pairwise Cipher*/ 636 BitSet allowedPairwiseCiphers = securityParams.getAllowedPairwiseCiphers(); 637 if (allowedPairwiseCiphers.cardinality() != 0 638 && !setPairwiseCipher(wifiConfigurationToSupplicantPairwiseCipherMask( 639 allowedPairwiseCiphers))) { 640 Log.e(TAG, "failed to set PairwiseCipher"); 641 return false; 642 } 643 /** GroupMgmt Cipher */ 644 BitSet allowedGroupManagementCiphers = securityParams.getAllowedGroupManagementCiphers(); 645 if (allowedGroupManagementCiphers.cardinality() != 0 646 && !setGroupMgmtCipher(wifiConfigurationToSupplicantGroupMgmtCipherMask( 647 allowedGroupManagementCiphers))) { 648 Log.e(TAG, "failed to set GroupMgmtCipher"); 649 return false; 650 } 651 652 BitSet allowedSuiteBCiphers = securityParams.getAllowedSuiteBCiphers(); 653 if (allowedSuiteBCiphers.get(WifiConfiguration.SuiteBCipher.ECDHE_RSA)) { 654 if (!enableTlsSuiteBEapPhase1Param(true)) { 655 Log.e(TAG, "failed to set TLSSuiteB"); 656 return false; 657 } 658 } else if (allowedSuiteBCiphers.get(WifiConfiguration.SuiteBCipher.ECDHE_ECDSA)) { 659 if (!enableSuiteBEapOpenSslCiphers()) { 660 Log.e(TAG, "failed to set OpensslCipher"); 661 return false; 662 } 663 } 664 665 return true; 666 } 667 668 /** 669 * Save network variables from the provided WifiEnterpriseConfig object to wpa_supplicant. 670 * 671 * @param ssid SSID of the network. (Used for logging purposes only) 672 * @param eapConfig WifiEnterpriseConfig object to be saved. 673 * @return true if succeeds, false otherwise. 674 */ saveWifiEnterpriseConfig(String ssid, WifiEnterpriseConfig eapConfig)675 private boolean saveWifiEnterpriseConfig(String ssid, WifiEnterpriseConfig eapConfig) { 676 synchronized (mLock) { 677 if (eapConfig == null) return false; 678 /** EAP method */ 679 if (!setEapMethod(wifiConfigurationToSupplicantEapMethod(eapConfig.getEapMethod()))) { 680 Log.e(TAG, ssid + ": failed to set eap method: " + eapConfig.getEapMethod()); 681 return false; 682 } 683 /** EAP Phase 2 method */ 684 if (!setEapPhase2Method(wifiConfigurationToSupplicantEapPhase2Method( 685 eapConfig.getPhase2Method()))) { 686 Log.e(TAG, ssid + ": failed to set eap phase 2 method: " 687 + eapConfig.getPhase2Method()); 688 return false; 689 } 690 String eapParam = null; 691 /** EAP Identity */ 692 eapParam = eapConfig.getFieldValue(WifiEnterpriseConfig.IDENTITY_KEY); 693 if (!TextUtils.isEmpty(eapParam) 694 && !setEapIdentity(NativeUtil.stringToByteArrayList(eapParam))) { 695 Log.e(TAG, ssid + ": failed to set eap identity: " + eapParam); 696 return false; 697 } 698 /** EAP Anonymous Identity */ 699 eapParam = eapConfig.getFieldValue(WifiEnterpriseConfig.ANON_IDENTITY_KEY); 700 if (!TextUtils.isEmpty(eapParam)) { 701 if (null != getV1_4StaNetwork()) { 702 String decoratedUsernamePrefix = 703 eapConfig.getFieldValue( 704 WifiEnterpriseConfig.DECORATED_IDENTITY_PREFIX_KEY); 705 if (!TextUtils.isEmpty(decoratedUsernamePrefix)) { 706 eapParam = decoratedUsernamePrefix + eapParam; 707 } 708 } 709 if (!setEapAnonymousIdentity(NativeUtil.stringToByteArrayList(eapParam))) { 710 Log.e(TAG, ssid + ": failed to set eap anonymous identity: " + eapParam); 711 return false; 712 } 713 } 714 /** EAP Password */ 715 eapParam = eapConfig.getFieldValue(WifiEnterpriseConfig.PASSWORD_KEY); 716 if (!TextUtils.isEmpty(eapParam) 717 && !setEapPassword(NativeUtil.stringToByteArrayList(eapParam))) { 718 Log.e(TAG, ssid + ": failed to set eap password"); 719 return false; 720 } 721 /** EAP Client Cert */ 722 eapParam = eapConfig.getFieldValue(WifiEnterpriseConfig.CLIENT_CERT_KEY); 723 if (!TextUtils.isEmpty(eapParam) && !setEapClientCert(eapParam)) { 724 Log.e(TAG, ssid + ": failed to set eap client cert: " + eapParam); 725 return false; 726 } 727 /** EAP CA Cert */ 728 eapParam = eapConfig.getFieldValue(WifiEnterpriseConfig.CA_CERT_KEY); 729 if (!TextUtils.isEmpty(eapParam) && !setEapCACert(eapParam)) { 730 Log.e(TAG, ssid + ": failed to set eap ca cert: " + eapParam); 731 return false; 732 } 733 /** EAP Subject Match */ 734 eapParam = eapConfig.getFieldValue(WifiEnterpriseConfig.SUBJECT_MATCH_KEY); 735 if (!TextUtils.isEmpty(eapParam) && !setEapSubjectMatch(eapParam)) { 736 Log.e(TAG, ssid + ": failed to set eap subject match: " + eapParam); 737 return false; 738 } 739 /** EAP Engine ID */ 740 eapParam = eapConfig.getFieldValue(WifiEnterpriseConfig.ENGINE_ID_KEY); 741 if (!TextUtils.isEmpty(eapParam) && !setEapEngineID(eapParam)) { 742 Log.e(TAG, ssid + ": failed to set eap engine id: " + eapParam); 743 return false; 744 } 745 /** EAP Engine */ 746 eapParam = eapConfig.getFieldValue(WifiEnterpriseConfig.ENGINE_KEY); 747 if (!TextUtils.isEmpty(eapParam) && !setEapEngine( 748 eapParam.equals(WifiEnterpriseConfig.ENGINE_ENABLE) ? true : false)) { 749 Log.e(TAG, ssid + ": failed to set eap engine: " + eapParam); 750 return false; 751 } 752 /** EAP Private Key */ 753 eapParam = eapConfig.getFieldValue(WifiEnterpriseConfig.PRIVATE_KEY_ID_KEY); 754 if (!TextUtils.isEmpty(eapParam) && !setEapPrivateKeyId(eapParam)) { 755 Log.e(TAG, ssid + ": failed to set eap private key: " + eapParam); 756 return false; 757 } 758 /** EAP Alt Subject Match */ 759 eapParam = eapConfig.getFieldValue(WifiEnterpriseConfig.ALTSUBJECT_MATCH_KEY); 760 if (!TextUtils.isEmpty(eapParam) && !setEapAltSubjectMatch(eapParam)) { 761 Log.e(TAG, ssid + ": failed to set eap alt subject match: " + eapParam); 762 return false; 763 } 764 /** EAP Domain Suffix Match */ 765 eapParam = eapConfig.getFieldValue(WifiEnterpriseConfig.DOM_SUFFIX_MATCH_KEY); 766 if (!TextUtils.isEmpty(eapParam) && !setEapDomainSuffixMatch(eapParam)) { 767 Log.e(TAG, ssid + ": failed to set eap domain suffix match: " + eapParam); 768 return false; 769 } 770 /** EAP CA Path*/ 771 eapParam = eapConfig.getFieldValue(WifiEnterpriseConfig.CA_PATH_KEY); 772 if (!TextUtils.isEmpty(eapParam) && !setEapCAPath(eapParam)) { 773 Log.e(TAG, ssid + ": failed to set eap ca path: " + eapParam); 774 return false; 775 } 776 777 /** EAP Proactive Key Caching */ 778 eapParam = eapConfig.getFieldValue(WifiEnterpriseConfig.OPP_KEY_CACHING); 779 if (!TextUtils.isEmpty(eapParam) 780 && !setEapProactiveKeyCaching(eapParam.equals("1") ? true : false)) { 781 Log.e(TAG, ssid + ": failed to set proactive key caching: " + eapParam); 782 return false; 783 } 784 785 /** 786 * OCSP (Online Certificate Status Protocol) 787 * For older HAL compatibility, omit this step to avoid breaking 788 * connection flow. 789 */ 790 if (getV1_3StaNetwork() != null && !setOcsp(eapConfig.getOcsp())) { 791 Log.e(TAG, "failed to set ocsp"); 792 return false; 793 } 794 /** EAP ERP */ 795 eapParam = eapConfig.getFieldValue(WifiEnterpriseConfig.EAP_ERP); 796 if (!TextUtils.isEmpty(eapParam) && eapParam.equals("1")) { 797 if (!setEapErp(true)) { 798 Log.e(TAG, ssid + ": failed to set eap erp"); 799 return false; 800 } 801 } 802 803 804 return true; 805 } 806 } 807 getV1_2StaNetwork()808 private android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork getV1_2StaNetwork() { 809 synchronized (mLock) { 810 return getSupplicantStaNetworkForV1_2Mockable(); 811 } 812 } 813 getV1_3StaNetwork()814 private android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork getV1_3StaNetwork() { 815 synchronized (mLock) { 816 return getSupplicantStaNetworkForV1_3Mockable(); 817 } 818 } 819 getV1_4StaNetwork()820 private android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetwork getV1_4StaNetwork() { 821 synchronized (mLock) { 822 return getSupplicantStaNetworkForV1_4Mockable(); 823 } 824 } 825 826 /** 827 * Maps WifiConfiguration Key Management BitSet to Supplicant HIDL bitmask int 828 * TODO(b/32571829): Update mapping when fast transition keys are added 829 * 830 * @return bitmask int describing the allowed Key Management schemes, readable by the Supplicant 831 * HIDL hal 832 */ wifiConfigurationToSupplicantKeyMgmtMask(BitSet keyMgmt)833 private static int wifiConfigurationToSupplicantKeyMgmtMask(BitSet keyMgmt) { 834 int mask = 0; 835 for (int bit = keyMgmt.nextSetBit(0); bit != -1; 836 bit = keyMgmt.nextSetBit(bit + 1)) { 837 switch (bit) { 838 case WifiConfiguration.KeyMgmt.NONE: 839 mask |= ISupplicantStaNetwork.KeyMgmtMask.NONE; 840 break; 841 case WifiConfiguration.KeyMgmt.WPA_PSK: 842 mask |= ISupplicantStaNetwork.KeyMgmtMask.WPA_PSK; 843 break; 844 case WifiConfiguration.KeyMgmt.WPA_EAP: 845 mask |= ISupplicantStaNetwork.KeyMgmtMask.WPA_EAP; 846 break; 847 case WifiConfiguration.KeyMgmt.IEEE8021X: 848 mask |= ISupplicantStaNetwork.KeyMgmtMask.IEEE8021X; 849 break; 850 case WifiConfiguration.KeyMgmt.OSEN: 851 mask |= ISupplicantStaNetwork.KeyMgmtMask.OSEN; 852 break; 853 case WifiConfiguration.KeyMgmt.FT_PSK: 854 mask |= ISupplicantStaNetwork.KeyMgmtMask.FT_PSK; 855 break; 856 case WifiConfiguration.KeyMgmt.FT_EAP: 857 mask |= ISupplicantStaNetwork.KeyMgmtMask.FT_EAP; 858 break; 859 case WifiConfiguration.KeyMgmt.OWE: 860 mask |= android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork.KeyMgmtMask 861 .OWE; 862 break; 863 case WifiConfiguration.KeyMgmt.SAE: 864 mask |= android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork.KeyMgmtMask 865 .SAE; 866 break; 867 case WifiConfiguration.KeyMgmt.SUITE_B_192: 868 mask |= android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork.KeyMgmtMask 869 .SUITE_B_192; 870 break; 871 case WifiConfiguration.KeyMgmt.WPA_PSK_SHA256: 872 mask |= android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork.KeyMgmtMask 873 .WPA_PSK_SHA256; 874 break; 875 case WifiConfiguration.KeyMgmt.WPA_EAP_SHA256: 876 mask |= android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork.KeyMgmtMask 877 .WPA_EAP_SHA256; 878 break; 879 case WifiConfiguration.KeyMgmt.WAPI_PSK: 880 mask |= android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork.KeyMgmtMask 881 .WAPI_PSK; 882 break; 883 case WifiConfiguration.KeyMgmt.WAPI_CERT: 884 mask |= android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork.KeyMgmtMask 885 .WAPI_CERT; 886 break; 887 case WifiConfiguration.KeyMgmt.FILS_SHA256: 888 mask |= android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork.KeyMgmtMask 889 .FILS_SHA256; 890 break; 891 case WifiConfiguration.KeyMgmt.FILS_SHA384: 892 mask |= android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork.KeyMgmtMask 893 .FILS_SHA384; 894 break; 895 case WifiConfiguration.KeyMgmt.WPA2_PSK: // This should never happen 896 default: 897 throw new IllegalArgumentException( 898 "Invalid protoMask bit in keyMgmt: " + bit); 899 } 900 } 901 return mask; 902 } 903 wifiConfigurationToSupplicantProtoMask(BitSet protoMask)904 private static int wifiConfigurationToSupplicantProtoMask(BitSet protoMask) { 905 int mask = 0; 906 for (int bit = protoMask.nextSetBit(0); bit != -1; 907 bit = protoMask.nextSetBit(bit + 1)) { 908 switch (bit) { 909 case WifiConfiguration.Protocol.WPA: 910 mask |= ISupplicantStaNetwork.ProtoMask.WPA; 911 break; 912 case WifiConfiguration.Protocol.RSN: 913 mask |= ISupplicantStaNetwork.ProtoMask.RSN; 914 break; 915 case WifiConfiguration.Protocol.OSEN: 916 mask |= ISupplicantStaNetwork.ProtoMask.OSEN; 917 break; 918 case WifiConfiguration.Protocol.WAPI: 919 mask |= android.hardware.wifi.supplicant.V1_3 920 .ISupplicantStaNetwork.ProtoMask.WAPI; 921 break; 922 default: 923 throw new IllegalArgumentException( 924 "Invalid protoMask bit in wificonfig: " + bit); 925 } 926 } 927 return mask; 928 } 929 wifiConfigurationToSupplicantAuthAlgMask(BitSet authAlgMask)930 private static int wifiConfigurationToSupplicantAuthAlgMask(BitSet authAlgMask) { 931 int mask = 0; 932 for (int bit = authAlgMask.nextSetBit(0); bit != -1; 933 bit = authAlgMask.nextSetBit(bit + 1)) { 934 switch (bit) { 935 case WifiConfiguration.AuthAlgorithm.OPEN: 936 mask |= ISupplicantStaNetwork.AuthAlgMask.OPEN; 937 break; 938 case WifiConfiguration.AuthAlgorithm.SHARED: 939 mask |= ISupplicantStaNetwork.AuthAlgMask.SHARED; 940 break; 941 case WifiConfiguration.AuthAlgorithm.LEAP: 942 mask |= ISupplicantStaNetwork.AuthAlgMask.LEAP; 943 break; 944 case WifiConfiguration.AuthAlgorithm.SAE: 945 mask |= android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork.AuthAlgMask 946 .SAE; 947 break; 948 default: 949 throw new IllegalArgumentException( 950 "Invalid authAlgMask bit in wificonfig: " + bit); 951 } 952 } 953 return mask; 954 } 955 wifiConfigurationToSupplicantGroupCipherMask(BitSet groupCipherMask)956 private int wifiConfigurationToSupplicantGroupCipherMask(BitSet groupCipherMask) { 957 int mask = 0; 958 for (int bit = groupCipherMask.nextSetBit(0); bit != -1; bit = 959 groupCipherMask.nextSetBit(bit + 1)) { 960 switch (bit) { 961 case WifiConfiguration.GroupCipher.WEP40: 962 mask |= ISupplicantStaNetwork.GroupCipherMask.WEP40; 963 break; 964 case WifiConfiguration.GroupCipher.WEP104: 965 mask |= ISupplicantStaNetwork.GroupCipherMask.WEP104; 966 break; 967 case WifiConfiguration.GroupCipher.TKIP: 968 mask |= ISupplicantStaNetwork.GroupCipherMask.TKIP; 969 break; 970 case WifiConfiguration.GroupCipher.CCMP: 971 mask |= ISupplicantStaNetwork.GroupCipherMask.CCMP; 972 break; 973 case WifiConfiguration.GroupCipher.GTK_NOT_USED: 974 mask |= ISupplicantStaNetwork.GroupCipherMask.GTK_NOT_USED; 975 break; 976 case WifiConfiguration.GroupCipher.GCMP_256: 977 if (null == getV1_2StaNetwork()) { 978 Log.d(TAG, "Ignore GCMP_256 cipher for the HAL older than 1.2."); 979 break; 980 } 981 if (0 == (mAdvanceKeyMgmtFeatures & WifiManager.WIFI_FEATURE_WPA3_SUITE_B)) { 982 Log.d(TAG, "Ignore unsupporting GCMP_256 cipher."); 983 break; 984 } 985 mask |= android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 986 .GroupCipherMask.GCMP_256; 987 break; 988 case WifiConfiguration.GroupCipher.SMS4: 989 if (null != getV1_3StaNetwork()) { 990 mask |= android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 991 .GroupCipherMask.SMS4; 992 } else { 993 Log.d(TAG, "Ignore SMS4 cipher for the HAL older than 1.3."); 994 } 995 break; 996 case WifiConfiguration.GroupCipher.GCMP_128: 997 if (null != getV1_4StaNetwork()) { 998 mask |= android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetwork 999 .GroupCipherMask.GCMP_128; 1000 } else { 1001 Log.d(TAG, "Ignore GCMP_128 cipher for the HAL older than 1.4."); 1002 } 1003 break; 1004 default: 1005 throw new IllegalArgumentException( 1006 "Invalid GroupCipherMask bit in wificonfig: " + bit); 1007 } 1008 } 1009 return mask; 1010 } 1011 wifiConfigurationToSupplicantGroupMgmtCipherMask(BitSet groupMgmtCipherMask)1012 private static int wifiConfigurationToSupplicantGroupMgmtCipherMask(BitSet 1013 groupMgmtCipherMask) { 1014 int mask = 0; 1015 1016 for (int bit = groupMgmtCipherMask.nextSetBit(0); bit != -1; bit = 1017 groupMgmtCipherMask.nextSetBit(bit + 1)) { 1018 switch (bit) { 1019 case WifiConfiguration.GroupMgmtCipher.BIP_CMAC_256: 1020 mask |= android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1021 .GroupMgmtCipherMask.BIP_CMAC_256; 1022 break; 1023 case WifiConfiguration.GroupMgmtCipher.BIP_GMAC_128: 1024 mask |= android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1025 .GroupMgmtCipherMask.BIP_GMAC_128; 1026 break; 1027 case WifiConfiguration.GroupMgmtCipher.BIP_GMAC_256: 1028 mask |= android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1029 .GroupMgmtCipherMask.BIP_GMAC_256; 1030 break; 1031 default: 1032 throw new IllegalArgumentException( 1033 "Invalid GroupMgmtCipherMask bit in wificonfig: " + bit); 1034 } 1035 } 1036 return mask; 1037 } 1038 wifiConfigurationToSupplicantPairwiseCipherMask(BitSet pairwiseCipherMask)1039 private int wifiConfigurationToSupplicantPairwiseCipherMask(BitSet pairwiseCipherMask) { 1040 int mask = 0; 1041 for (int bit = pairwiseCipherMask.nextSetBit(0); bit != -1; 1042 bit = pairwiseCipherMask.nextSetBit(bit + 1)) { 1043 switch (bit) { 1044 case WifiConfiguration.PairwiseCipher.NONE: 1045 mask |= ISupplicantStaNetwork.PairwiseCipherMask.NONE; 1046 break; 1047 case WifiConfiguration.PairwiseCipher.TKIP: 1048 mask |= ISupplicantStaNetwork.PairwiseCipherMask.TKIP; 1049 break; 1050 case WifiConfiguration.PairwiseCipher.CCMP: 1051 mask |= ISupplicantStaNetwork.PairwiseCipherMask.CCMP; 1052 break; 1053 case WifiConfiguration.PairwiseCipher.GCMP_256: 1054 if (null == getV1_2StaNetwork()) { 1055 Log.d(TAG, "Ignore GCMP_256 cipher for the HAL older than 1.2."); 1056 break; 1057 } 1058 if (0 == (mAdvanceKeyMgmtFeatures & WifiManager.WIFI_FEATURE_WPA3_SUITE_B)) { 1059 Log.d(TAG, "Ignore unsupporting GCMP_256 cipher."); 1060 break; 1061 } 1062 mask |= android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1063 .PairwiseCipherMask.GCMP_256; 1064 break; 1065 case WifiConfiguration.PairwiseCipher.SMS4: 1066 if (null != getV1_3StaNetwork()) { 1067 mask |= android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 1068 .PairwiseCipherMask.SMS4; 1069 } else { 1070 Log.d(TAG, "Ignore SMS4 cipher for the HAL older than 1.3."); 1071 } 1072 break; 1073 case WifiConfiguration.PairwiseCipher.GCMP_128: 1074 if (null != getV1_4StaNetwork()) { 1075 mask |= android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetwork 1076 .PairwiseCipherMask.GCMP_128; 1077 } else { 1078 Log.d(TAG, "Ignore GCMP_128 cipher for the HAL older than 1.4."); 1079 } 1080 break; 1081 default: 1082 throw new IllegalArgumentException( 1083 "Invalid pairwiseCipherMask bit in wificonfig: " + bit); 1084 } 1085 } 1086 return mask; 1087 } 1088 supplicantToWifiConfigurationEapMethod(int value)1089 private static int supplicantToWifiConfigurationEapMethod(int value) { 1090 switch (value) { 1091 case ISupplicantStaNetwork.EapMethod.PEAP: 1092 return WifiEnterpriseConfig.Eap.PEAP; 1093 case ISupplicantStaNetwork.EapMethod.TLS: 1094 return WifiEnterpriseConfig.Eap.TLS; 1095 case ISupplicantStaNetwork.EapMethod.TTLS: 1096 return WifiEnterpriseConfig.Eap.TTLS; 1097 case ISupplicantStaNetwork.EapMethod.PWD: 1098 return WifiEnterpriseConfig.Eap.PWD; 1099 case ISupplicantStaNetwork.EapMethod.SIM: 1100 return WifiEnterpriseConfig.Eap.SIM; 1101 case ISupplicantStaNetwork.EapMethod.AKA: 1102 return WifiEnterpriseConfig.Eap.AKA; 1103 case ISupplicantStaNetwork.EapMethod.AKA_PRIME: 1104 return WifiEnterpriseConfig.Eap.AKA_PRIME; 1105 case ISupplicantStaNetwork.EapMethod.WFA_UNAUTH_TLS: 1106 return WifiEnterpriseConfig.Eap.UNAUTH_TLS; 1107 // WifiEnterpriseConfig.Eap.NONE: 1108 default: 1109 Log.e(TAG, "invalid eap method value from supplicant: " + value); 1110 return -1; 1111 } 1112 } 1113 supplicantToWifiConfigurationEapPhase2Method(int value)1114 private static int supplicantToWifiConfigurationEapPhase2Method(int value) { 1115 switch (value) { 1116 case ISupplicantStaNetwork.EapPhase2Method.NONE: 1117 return WifiEnterpriseConfig.Phase2.NONE; 1118 case ISupplicantStaNetwork.EapPhase2Method.PAP: 1119 return WifiEnterpriseConfig.Phase2.PAP; 1120 case ISupplicantStaNetwork.EapPhase2Method.MSPAP: 1121 return WifiEnterpriseConfig.Phase2.MSCHAP; 1122 case ISupplicantStaNetwork.EapPhase2Method.MSPAPV2: 1123 return WifiEnterpriseConfig.Phase2.MSCHAPV2; 1124 case ISupplicantStaNetwork.EapPhase2Method.GTC: 1125 return WifiEnterpriseConfig.Phase2.GTC; 1126 case ISupplicantStaNetwork.EapPhase2Method.SIM: 1127 return WifiEnterpriseConfig.Phase2.SIM; 1128 case ISupplicantStaNetwork.EapPhase2Method.AKA: 1129 return WifiEnterpriseConfig.Phase2.AKA; 1130 case ISupplicantStaNetwork.EapPhase2Method.AKA_PRIME: 1131 return WifiEnterpriseConfig.Phase2.AKA_PRIME; 1132 default: 1133 Log.e(TAG, "invalid eap phase2 method value from supplicant: " + value); 1134 return -1; 1135 } 1136 } 1137 supplicantMaskValueToWifiConfigurationBitSet(int supplicantMask, int supplicantValue, BitSet bitset, int bitSetPosition)1138 private static int supplicantMaskValueToWifiConfigurationBitSet(int supplicantMask, 1139 int supplicantValue, BitSet bitset, 1140 int bitSetPosition) { 1141 bitset.set(bitSetPosition, (supplicantMask & supplicantValue) == supplicantValue); 1142 int modifiedSupplicantMask = supplicantMask & ~supplicantValue; 1143 return modifiedSupplicantMask; 1144 } 1145 supplicantToWifiConfigurationKeyMgmtMask(int mask)1146 private static BitSet supplicantToWifiConfigurationKeyMgmtMask(int mask) { 1147 BitSet bitset = new BitSet(); 1148 mask = supplicantMaskValueToWifiConfigurationBitSet( 1149 mask, ISupplicantStaNetwork.KeyMgmtMask.NONE, bitset, 1150 WifiConfiguration.KeyMgmt.NONE); 1151 mask = supplicantMaskValueToWifiConfigurationBitSet( 1152 mask, ISupplicantStaNetwork.KeyMgmtMask.WPA_PSK, bitset, 1153 WifiConfiguration.KeyMgmt.WPA_PSK); 1154 mask = supplicantMaskValueToWifiConfigurationBitSet( 1155 mask, ISupplicantStaNetwork.KeyMgmtMask.WPA_EAP, bitset, 1156 WifiConfiguration.KeyMgmt.WPA_EAP); 1157 mask = supplicantMaskValueToWifiConfigurationBitSet( 1158 mask, ISupplicantStaNetwork.KeyMgmtMask.IEEE8021X, bitset, 1159 WifiConfiguration.KeyMgmt.IEEE8021X); 1160 mask = supplicantMaskValueToWifiConfigurationBitSet( 1161 mask, ISupplicantStaNetwork.KeyMgmtMask.OSEN, bitset, 1162 WifiConfiguration.KeyMgmt.OSEN); 1163 mask = supplicantMaskValueToWifiConfigurationBitSet( 1164 mask, ISupplicantStaNetwork.KeyMgmtMask.FT_PSK, bitset, 1165 WifiConfiguration.KeyMgmt.FT_PSK); 1166 mask = supplicantMaskValueToWifiConfigurationBitSet( 1167 mask, ISupplicantStaNetwork.KeyMgmtMask.FT_EAP, bitset, 1168 WifiConfiguration.KeyMgmt.FT_EAP); 1169 mask = supplicantMaskValueToWifiConfigurationBitSet( 1170 mask, android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork.KeyMgmtMask.SAE, 1171 bitset, WifiConfiguration.KeyMgmt.SAE); 1172 mask = supplicantMaskValueToWifiConfigurationBitSet( 1173 mask, android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork.KeyMgmtMask.OWE, 1174 bitset, WifiConfiguration.KeyMgmt.OWE); 1175 mask = supplicantMaskValueToWifiConfigurationBitSet( 1176 mask, android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork.KeyMgmtMask 1177 .SUITE_B_192, bitset, WifiConfiguration.KeyMgmt.SUITE_B_192); 1178 mask = supplicantMaskValueToWifiConfigurationBitSet( 1179 mask, android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork.KeyMgmtMask 1180 .WPA_PSK_SHA256, bitset, WifiConfiguration.KeyMgmt.WPA_PSK_SHA256); 1181 mask = supplicantMaskValueToWifiConfigurationBitSet( 1182 mask, android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork.KeyMgmtMask 1183 .WPA_EAP_SHA256, bitset, WifiConfiguration.KeyMgmt.WPA_EAP_SHA256); 1184 mask = supplicantMaskValueToWifiConfigurationBitSet( 1185 mask, android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork.KeyMgmtMask 1186 .WAPI_PSK, bitset, WifiConfiguration.KeyMgmt.WAPI_PSK); 1187 mask = supplicantMaskValueToWifiConfigurationBitSet( 1188 mask, android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork.KeyMgmtMask 1189 .WAPI_CERT, bitset, WifiConfiguration.KeyMgmt.WAPI_CERT); 1190 mask = supplicantMaskValueToWifiConfigurationBitSet( 1191 mask, android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork.KeyMgmtMask 1192 .FILS_SHA256, bitset, WifiConfiguration.KeyMgmt.FILS_SHA256); 1193 mask = supplicantMaskValueToWifiConfigurationBitSet( 1194 mask, android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork.KeyMgmtMask 1195 .FILS_SHA384, bitset, WifiConfiguration.KeyMgmt.FILS_SHA384); 1196 if (mask != 0) { 1197 throw new IllegalArgumentException( 1198 "invalid key mgmt mask from supplicant: " + mask); 1199 } 1200 return bitset; 1201 } 1202 supplicantToWifiConfigurationProtoMask(int mask)1203 private static BitSet supplicantToWifiConfigurationProtoMask(int mask) { 1204 BitSet bitset = new BitSet(); 1205 mask = supplicantMaskValueToWifiConfigurationBitSet( 1206 mask, ISupplicantStaNetwork.ProtoMask.WPA, bitset, 1207 WifiConfiguration.Protocol.WPA); 1208 mask = supplicantMaskValueToWifiConfigurationBitSet( 1209 mask, ISupplicantStaNetwork.ProtoMask.RSN, bitset, 1210 WifiConfiguration.Protocol.RSN); 1211 mask = supplicantMaskValueToWifiConfigurationBitSet( 1212 mask, ISupplicantStaNetwork.ProtoMask.OSEN, bitset, 1213 WifiConfiguration.Protocol.OSEN); 1214 mask = supplicantMaskValueToWifiConfigurationBitSet( 1215 mask, android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork.ProtoMask.WAPI, 1216 bitset, WifiConfiguration.Protocol.WAPI); 1217 if (mask != 0) { 1218 throw new IllegalArgumentException( 1219 "invalid proto mask from supplicant: " + mask); 1220 } 1221 return bitset; 1222 } 1223 supplicantToWifiConfigurationAuthAlgMask(int mask)1224 private static BitSet supplicantToWifiConfigurationAuthAlgMask(int mask) { 1225 BitSet bitset = new BitSet(); 1226 mask = supplicantMaskValueToWifiConfigurationBitSet( 1227 mask, ISupplicantStaNetwork.AuthAlgMask.OPEN, bitset, 1228 WifiConfiguration.AuthAlgorithm.OPEN); 1229 mask = supplicantMaskValueToWifiConfigurationBitSet( 1230 mask, ISupplicantStaNetwork.AuthAlgMask.SHARED, bitset, 1231 WifiConfiguration.AuthAlgorithm.SHARED); 1232 mask = supplicantMaskValueToWifiConfigurationBitSet( 1233 mask, ISupplicantStaNetwork.AuthAlgMask.LEAP, bitset, 1234 WifiConfiguration.AuthAlgorithm.LEAP); 1235 mask = supplicantMaskValueToWifiConfigurationBitSet(mask, 1236 android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork.AuthAlgMask 1237 .SAE, bitset, WifiConfiguration.AuthAlgorithm.SAE); 1238 if (mask != 0) { 1239 throw new IllegalArgumentException( 1240 "invalid auth alg mask from supplicant: " + mask); 1241 } 1242 return bitset; 1243 } 1244 supplicantToWifiConfigurationGroupCipherMask(int mask)1245 private static BitSet supplicantToWifiConfigurationGroupCipherMask(int mask) { 1246 BitSet bitset = new BitSet(); 1247 mask = supplicantMaskValueToWifiConfigurationBitSet( 1248 mask, ISupplicantStaNetwork.GroupCipherMask.WEP40, bitset, 1249 WifiConfiguration.GroupCipher.WEP40); 1250 mask = supplicantMaskValueToWifiConfigurationBitSet( 1251 mask, ISupplicantStaNetwork.GroupCipherMask.WEP104, bitset, 1252 WifiConfiguration.GroupCipher.WEP104); 1253 mask = supplicantMaskValueToWifiConfigurationBitSet( 1254 mask, ISupplicantStaNetwork.GroupCipherMask.TKIP, bitset, 1255 WifiConfiguration.GroupCipher.TKIP); 1256 mask = supplicantMaskValueToWifiConfigurationBitSet( 1257 mask, ISupplicantStaNetwork.GroupCipherMask.CCMP, bitset, 1258 WifiConfiguration.GroupCipher.CCMP); 1259 mask = supplicantMaskValueToWifiConfigurationBitSet(mask, 1260 android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1261 .GroupCipherMask.GCMP_256, bitset, WifiConfiguration.GroupCipher.GCMP_256); 1262 mask = supplicantMaskValueToWifiConfigurationBitSet( 1263 mask, ISupplicantStaNetwork.GroupCipherMask.GTK_NOT_USED, bitset, 1264 WifiConfiguration.GroupCipher.GTK_NOT_USED); 1265 mask = supplicantMaskValueToWifiConfigurationBitSet(mask, 1266 android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork.GroupCipherMask 1267 .SMS4, bitset, WifiConfiguration.GroupCipher.SMS4); 1268 mask = supplicantMaskValueToWifiConfigurationBitSet(mask, 1269 android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetwork.GroupCipherMask 1270 .GCMP_128, bitset, WifiConfiguration.GroupCipher.GCMP_128); 1271 if (mask != 0) { 1272 throw new IllegalArgumentException( 1273 "invalid group cipher mask from supplicant: " + mask); 1274 } 1275 return bitset; 1276 } 1277 supplicantToWifiConfigurationGroupMgmtCipherMask(int mask)1278 private static BitSet supplicantToWifiConfigurationGroupMgmtCipherMask(int mask) { 1279 BitSet bitset = new BitSet(); 1280 mask = supplicantMaskValueToWifiConfigurationBitSet( 1281 mask, android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1282 .GroupMgmtCipherMask.BIP_GMAC_128, bitset, 1283 WifiConfiguration.GroupMgmtCipher.BIP_GMAC_128); 1284 mask = supplicantMaskValueToWifiConfigurationBitSet( 1285 mask, android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1286 .GroupMgmtCipherMask.BIP_GMAC_256, bitset, 1287 WifiConfiguration.GroupMgmtCipher.BIP_GMAC_256); 1288 mask = supplicantMaskValueToWifiConfigurationBitSet( 1289 mask, android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1290 .GroupMgmtCipherMask.BIP_CMAC_256, bitset, 1291 WifiConfiguration.GroupMgmtCipher.BIP_CMAC_256); 1292 if (mask != 0) { 1293 throw new IllegalArgumentException( 1294 "invalid group mgmt cipher mask from supplicant: " + mask); 1295 } 1296 return bitset; 1297 } 1298 supplicantToWifiConfigurationPairwiseCipherMask(int mask)1299 private static BitSet supplicantToWifiConfigurationPairwiseCipherMask(int mask) { 1300 BitSet bitset = new BitSet(); 1301 mask = supplicantMaskValueToWifiConfigurationBitSet( 1302 mask, ISupplicantStaNetwork.PairwiseCipherMask.NONE, bitset, 1303 WifiConfiguration.PairwiseCipher.NONE); 1304 mask = supplicantMaskValueToWifiConfigurationBitSet( 1305 mask, ISupplicantStaNetwork.PairwiseCipherMask.TKIP, bitset, 1306 WifiConfiguration.PairwiseCipher.TKIP); 1307 mask = supplicantMaskValueToWifiConfigurationBitSet( 1308 mask, ISupplicantStaNetwork.PairwiseCipherMask.CCMP, bitset, 1309 WifiConfiguration.PairwiseCipher.CCMP); 1310 mask = supplicantMaskValueToWifiConfigurationBitSet(mask, 1311 android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork.PairwiseCipherMask 1312 .GCMP_256, bitset, 1313 WifiConfiguration.PairwiseCipher.GCMP_256); 1314 mask = supplicantMaskValueToWifiConfigurationBitSet(mask, 1315 android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork.PairwiseCipherMask 1316 .SMS4, bitset, 1317 WifiConfiguration.PairwiseCipher.SMS4); 1318 mask = supplicantMaskValueToWifiConfigurationBitSet(mask, 1319 android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetwork.PairwiseCipherMask 1320 .GCMP_128, bitset, 1321 WifiConfiguration.PairwiseCipher.GCMP_128); 1322 if (mask != 0) { 1323 throw new IllegalArgumentException( 1324 "invalid pairwise cipher mask from supplicant: " + mask); 1325 } 1326 return bitset; 1327 } 1328 wifiConfigurationToSupplicantEapMethod(int value)1329 private static int wifiConfigurationToSupplicantEapMethod(int value) { 1330 switch (value) { 1331 case WifiEnterpriseConfig.Eap.PEAP: 1332 return ISupplicantStaNetwork.EapMethod.PEAP; 1333 case WifiEnterpriseConfig.Eap.TLS: 1334 return ISupplicantStaNetwork.EapMethod.TLS; 1335 case WifiEnterpriseConfig.Eap.TTLS: 1336 return ISupplicantStaNetwork.EapMethod.TTLS; 1337 case WifiEnterpriseConfig.Eap.PWD: 1338 return ISupplicantStaNetwork.EapMethod.PWD; 1339 case WifiEnterpriseConfig.Eap.SIM: 1340 return ISupplicantStaNetwork.EapMethod.SIM; 1341 case WifiEnterpriseConfig.Eap.AKA: 1342 return ISupplicantStaNetwork.EapMethod.AKA; 1343 case WifiEnterpriseConfig.Eap.AKA_PRIME: 1344 return ISupplicantStaNetwork.EapMethod.AKA_PRIME; 1345 case WifiEnterpriseConfig.Eap.UNAUTH_TLS: 1346 return ISupplicantStaNetwork.EapMethod.WFA_UNAUTH_TLS; 1347 // WifiEnterpriseConfig.Eap.NONE: 1348 default: 1349 Log.e(TAG, "invalid eap method value from WifiConfiguration: " + value); 1350 return -1; 1351 } 1352 } 1353 wifiConfigurationToSupplicantEapPhase2Method(int value)1354 private static int wifiConfigurationToSupplicantEapPhase2Method(int value) { 1355 switch (value) { 1356 case WifiEnterpriseConfig.Phase2.NONE: 1357 return ISupplicantStaNetwork.EapPhase2Method.NONE; 1358 case WifiEnterpriseConfig.Phase2.PAP: 1359 return ISupplicantStaNetwork.EapPhase2Method.PAP; 1360 case WifiEnterpriseConfig.Phase2.MSCHAP: 1361 return ISupplicantStaNetwork.EapPhase2Method.MSPAP; 1362 case WifiEnterpriseConfig.Phase2.MSCHAPV2: 1363 return ISupplicantStaNetwork.EapPhase2Method.MSPAPV2; 1364 case WifiEnterpriseConfig.Phase2.GTC: 1365 return ISupplicantStaNetwork.EapPhase2Method.GTC; 1366 case WifiEnterpriseConfig.Phase2.SIM: 1367 return ISupplicantStaNetwork.EapPhase2Method.SIM; 1368 case WifiEnterpriseConfig.Phase2.AKA: 1369 return ISupplicantStaNetwork.EapPhase2Method.AKA; 1370 case WifiEnterpriseConfig.Phase2.AKA_PRIME: 1371 return ISupplicantStaNetwork.EapPhase2Method.AKA_PRIME; 1372 default: 1373 Log.e(TAG, "invalid eap phase2 method value from WifiConfiguration: " + value); 1374 return -1; 1375 } 1376 } 1377 1378 /** See ISupplicantNetwork.hal for documentation */ getId()1379 private boolean getId() { 1380 synchronized (mLock) { 1381 final String methodStr = "getId"; 1382 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1383 try { 1384 Mutable<Boolean> statusOk = new Mutable<>(false); 1385 mISupplicantStaNetwork.getId((SupplicantStatus status, int idValue) -> { 1386 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 1387 if (statusOk.value) { 1388 this.mNetworkId = idValue; 1389 } else { 1390 checkStatusAndLogFailure(status, methodStr); 1391 } 1392 }); 1393 return statusOk.value; 1394 } catch (RemoteException e) { 1395 handleRemoteException(e, methodStr); 1396 return false; 1397 } 1398 } 1399 } 1400 1401 /** get current network id */ getNetworkId()1402 public int getNetworkId() { 1403 if (!getId()) { 1404 return -1; 1405 } 1406 return mNetworkId; 1407 } 1408 1409 /** See ISupplicantStaNetwork.hal for documentation */ registerCallback(ISupplicantStaNetworkCallback callback)1410 private boolean registerCallback(ISupplicantStaNetworkCallback callback) { 1411 synchronized (mLock) { 1412 final String methodStr = "registerCallback"; 1413 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1414 try { 1415 SupplicantStatus status = mISupplicantStaNetwork.registerCallback(callback); 1416 return checkStatusAndLogFailure(status, methodStr); 1417 } catch (RemoteException e) { 1418 handleRemoteException(e, methodStr); 1419 return false; 1420 } 1421 } 1422 } 1423 1424 /** See ISupplicantStaNetwork.hal for documentation */ registerCallback_1_4( android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetworkCallback callback)1425 private boolean registerCallback_1_4( 1426 android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetworkCallback callback) { 1427 synchronized (mLock) { 1428 final String methodStr = "registerCallback_1_4"; 1429 android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetwork 1430 iSupplicantStaNetworkV14 = getV1_4StaNetwork(); 1431 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1432 if (iSupplicantStaNetworkV14 == null) return false; 1433 try { 1434 android.hardware.wifi.supplicant.V1_4.SupplicantStatus status = 1435 iSupplicantStaNetworkV14.registerCallback_1_4(callback); 1436 return checkStatusAndLogFailure(status, methodStr); 1437 } catch (RemoteException e) { 1438 handleRemoteException(e, methodStr); 1439 return false; 1440 } 1441 } 1442 } 1443 1444 /** See ISupplicantStaNetwork.hal for documentation */ setSsid(java.util.ArrayList<Byte> ssid)1445 private boolean setSsid(java.util.ArrayList<Byte> ssid) { 1446 synchronized (mLock) { 1447 final String methodStr = "setSsid"; 1448 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1449 try { 1450 SupplicantStatus status = mISupplicantStaNetwork.setSsid(ssid); 1451 return checkStatusAndLogFailure(status, methodStr); 1452 } catch (RemoteException e) { 1453 handleRemoteException(e, methodStr); 1454 return false; 1455 } 1456 } 1457 } 1458 1459 /** 1460 * Set the BSSID for this network. 1461 * 1462 * @param bssidStr MAC address in "XX:XX:XX:XX:XX:XX" form or "any" to reset the mac address. 1463 * @return true if it succeeds, false otherwise. 1464 */ setBssid(String bssidStr)1465 public boolean setBssid(String bssidStr) { 1466 synchronized (mLock) { 1467 try { 1468 return setBssid(NativeUtil.macAddressToByteArray(bssidStr)); 1469 } catch (IllegalArgumentException e) { 1470 Log.e(TAG, "Illegal argument " + bssidStr, e); 1471 return false; 1472 } 1473 } 1474 } 1475 1476 /** See ISupplicantStaNetwork.hal for documentation */ setBssid(byte[ ] bssid)1477 private boolean setBssid(byte[/* 6 */] bssid) { 1478 synchronized (mLock) { 1479 final String methodStr = "setBssid"; 1480 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1481 try { 1482 SupplicantStatus status = mISupplicantStaNetwork.setBssid(bssid); 1483 return checkStatusAndLogFailure(status, methodStr); 1484 } catch (RemoteException e) { 1485 handleRemoteException(e, methodStr); 1486 return false; 1487 } 1488 } 1489 } 1490 1491 /** See ISupplicantStaNetwork.hal for documentation */ setScanSsid(boolean enable)1492 private boolean setScanSsid(boolean enable) { 1493 synchronized (mLock) { 1494 final String methodStr = "setScanSsid"; 1495 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1496 try { 1497 SupplicantStatus status = mISupplicantStaNetwork.setScanSsid(enable); 1498 return checkStatusAndLogFailure(status, methodStr); 1499 } catch (RemoteException e) { 1500 handleRemoteException(e, methodStr); 1501 return false; 1502 } 1503 } 1504 } 1505 1506 /** See ISupplicantStaNetwork.hal for documentation */ setKeyMgmt(int keyMgmtMask)1507 private boolean setKeyMgmt(int keyMgmtMask) { 1508 synchronized (mLock) { 1509 final String methodStr = "setKeyMgmt"; 1510 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1511 try { 1512 SupplicantStatus status; 1513 android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1514 iSupplicantStaNetworkV12 = getV1_2StaNetwork(); 1515 android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 1516 iSupplicantStaNetworkV13 = getV1_3StaNetwork(); 1517 if (null != iSupplicantStaNetworkV13) { 1518 /* Support for new key management types: 1519 * WAPI_PSK, WAPI_CERT 1520 * Requires HAL v1.3 or higher */ 1521 status = iSupplicantStaNetworkV13.setKeyMgmt_1_3(keyMgmtMask); 1522 } else if (iSupplicantStaNetworkV12 != null) { 1523 /* Support for new key management types; 1524 * SAE, OWE, WPA_PSK_SHA256, WPA_EAP_SHA256 1525 * Requires HAL v1.2 or higher */ 1526 status = iSupplicantStaNetworkV12.setKeyMgmt_1_2(keyMgmtMask); 1527 } else { 1528 status = mISupplicantStaNetwork.setKeyMgmt(keyMgmtMask); 1529 } 1530 return checkStatusAndLogFailure(status, methodStr); 1531 } catch (RemoteException e) { 1532 handleRemoteException(e, methodStr); 1533 return false; 1534 } 1535 } 1536 } 1537 1538 /** See ISupplicantStaNetwork.hal for documentation */ setProto(int protoMask)1539 private boolean setProto(int protoMask) { 1540 synchronized (mLock) { 1541 final String methodStr = "setProto"; 1542 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1543 try { 1544 android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 1545 iSupplicantStaNetworkV13 = getV1_3StaNetwork(); 1546 SupplicantStatus status; 1547 if (null != iSupplicantStaNetworkV13) { 1548 /* Support for new proto types: WAPI 1549 * Requires HAL v1.3 or higher 1550 */ 1551 status = iSupplicantStaNetworkV13.setProto_1_3(protoMask); 1552 } else { 1553 status = mISupplicantStaNetwork.setProto(protoMask); 1554 } 1555 return checkStatusAndLogFailure(status, methodStr); 1556 } catch (RemoteException e) { 1557 handleRemoteException(e, methodStr); 1558 return false; 1559 } 1560 } 1561 } 1562 1563 /** See ISupplicantStaNetwork.hal for documentation */ setAuthAlg(int authAlgMask)1564 private boolean setAuthAlg(int authAlgMask) { 1565 synchronized (mLock) { 1566 final String methodStr = "setAuthAlg"; 1567 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1568 try { 1569 android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 1570 iSupplicantStaNetworkV13 = getV1_3StaNetwork(); 1571 SupplicantStatus status; 1572 if (null != iSupplicantStaNetworkV13) { 1573 /* Support for SAE Authentication algorithm requires HAL v1.3 or higher */ 1574 status = iSupplicantStaNetworkV13.setAuthAlg_1_3(authAlgMask); 1575 } else { 1576 status = mISupplicantStaNetwork.setAuthAlg(authAlgMask); 1577 } 1578 return checkStatusAndLogFailure(status, methodStr); 1579 } catch (RemoteException e) { 1580 handleRemoteException(e, methodStr); 1581 return false; 1582 } 1583 } 1584 } 1585 1586 /** See ISupplicantStaNetwork.hal for documentation */ setGroupCipher_1_4(int groupCipherMask)1587 private boolean setGroupCipher_1_4(int groupCipherMask) { 1588 synchronized (mLock) { 1589 final String methodStr = "setGroupCipher_1_4"; 1590 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1591 android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetwork 1592 iSupplicantStaNetworkV14 = getV1_4StaNetwork(); 1593 if (null == iSupplicantStaNetworkV14) return false; 1594 try { 1595 return checkStatusAndLogFailure( 1596 iSupplicantStaNetworkV14.setGroupCipher_1_4(groupCipherMask), 1597 methodStr); 1598 } catch (RemoteException e) { 1599 handleRemoteException(e, methodStr); 1600 return false; 1601 } 1602 } 1603 } 1604 /** See ISupplicantStaNetwork.hal for documentation */ setGroupCipher(int groupCipherMask)1605 private boolean setGroupCipher(int groupCipherMask) { 1606 synchronized (mLock) { 1607 final String methodStr = "setGroupCipher"; 1608 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1609 try { 1610 SupplicantStatus status; 1611 android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1612 iSupplicantStaNetworkV12 = getV1_2StaNetwork(); 1613 android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 1614 iSupplicantStaNetworkV13 = getV1_3StaNetwork(); 1615 if (null != getV1_4StaNetwork()) { 1616 /* Support for new key group cipher types for GCMP_128 1617 * Requires HAL v1.4 or higher */ 1618 return setGroupCipher_1_4(groupCipherMask); 1619 } else if (null != iSupplicantStaNetworkV13) { 1620 /* Support for new key group cipher types for SMS4 1621 * Requires HAL v1.3 or higher */ 1622 status = iSupplicantStaNetworkV13.setGroupCipher_1_3(groupCipherMask); 1623 } else if (iSupplicantStaNetworkV12 != null) { 1624 /* Support for new key group cipher types for SuiteB 1625 * Requires HAL v1.2 or higher */ 1626 status = iSupplicantStaNetworkV12.setGroupCipher_1_2(groupCipherMask); 1627 } else { 1628 status = mISupplicantStaNetwork.setGroupCipher( 1629 groupCipherMask); 1630 } 1631 return checkStatusAndLogFailure(status, methodStr); 1632 } catch (RemoteException e) { 1633 handleRemoteException(e, methodStr); 1634 return false; 1635 } 1636 } 1637 } 1638 1639 /** See ISupplicantStaNetwork.hal for documentation */ enableTlsSuiteBEapPhase1Param(boolean enable)1640 private boolean enableTlsSuiteBEapPhase1Param(boolean enable) { 1641 synchronized (mLock) { 1642 final String methodStr = "setEapPhase1Params"; 1643 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1644 try { 1645 android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1646 iSupplicantStaNetworkV12; 1647 1648 iSupplicantStaNetworkV12 = getV1_2StaNetwork(); 1649 if (iSupplicantStaNetworkV12 != null) { 1650 /* Support for for SuiteB 1651 * Requires HAL v1.2 or higher */ 1652 SupplicantStatus status = iSupplicantStaNetworkV12 1653 .enableTlsSuiteBEapPhase1Param(enable); 1654 return checkStatusAndLogFailure(status, methodStr); 1655 } else { 1656 Log.e(TAG, "Supplicant HAL version does not support " + methodStr); 1657 return false; 1658 } 1659 } catch (RemoteException e) { 1660 handleRemoteException(e, methodStr); 1661 return false; 1662 } 1663 } 1664 } 1665 1666 /** See ISupplicantStaNetwork.hal for documentation */ enableSuiteBEapOpenSslCiphers()1667 private boolean enableSuiteBEapOpenSslCiphers() { 1668 synchronized (mLock) { 1669 final String methodStr = "setEapOpenSslCiphers"; 1670 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1671 try { 1672 android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1673 iSupplicantStaNetworkV12; 1674 1675 iSupplicantStaNetworkV12 = getV1_2StaNetwork(); 1676 if (iSupplicantStaNetworkV12 != null) { 1677 /* Support for for SuiteB 1678 * Requires HAL v1.2 or higher */ 1679 SupplicantStatus status = iSupplicantStaNetworkV12 1680 .enableSuiteBEapOpenSslCiphers(); 1681 return checkStatusAndLogFailure(status, methodStr); 1682 } else { 1683 Log.e(TAG, "Supplicant HAL version does not support " + methodStr); 1684 return false; 1685 } 1686 } catch (RemoteException e) { 1687 handleRemoteException(e, methodStr); 1688 return false; 1689 } 1690 } 1691 } 1692 1693 /** See ISupplicantStaNetwork.hal for documentation */ setPairwiseCipher_1_4(int pairwiseCipherMask)1694 private boolean setPairwiseCipher_1_4(int pairwiseCipherMask) { 1695 synchronized (mLock) { 1696 final String methodStr = "setPairwiseCipher_1_4"; 1697 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1698 android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetwork 1699 iSupplicantStaNetworkV14 = getV1_4StaNetwork(); 1700 if (null == iSupplicantStaNetworkV14) return false; 1701 try { 1702 return checkStatusAndLogFailure( 1703 iSupplicantStaNetworkV14.setPairwiseCipher_1_4(pairwiseCipherMask), 1704 methodStr); 1705 } catch (RemoteException e) { 1706 handleRemoteException(e, methodStr); 1707 return false; 1708 } 1709 } 1710 } 1711 1712 /** See ISupplicantStaNetwork.hal for documentation */ setPairwiseCipher(int pairwiseCipherMask)1713 private boolean setPairwiseCipher(int pairwiseCipherMask) { 1714 synchronized (mLock) { 1715 final String methodStr = "setPairwiseCipher"; 1716 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1717 try { 1718 SupplicantStatus status; 1719 android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1720 iSupplicantStaNetworkV12 = getV1_2StaNetwork(); 1721 android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 1722 iSupplicantStaNetworkV13 = getV1_3StaNetwork(); 1723 if (null != getV1_4StaNetwork()) { 1724 /* Support for new key pairwise cipher types for GCMP_128 1725 * Requires HAL v1.4 or higher */ 1726 return setPairwiseCipher_1_4(pairwiseCipherMask); 1727 } else if (null != iSupplicantStaNetworkV13) { 1728 /* Support for new key pairwise cipher types for SMS4 1729 * Requires HAL v1.3 or higher */ 1730 status = iSupplicantStaNetworkV13.setPairwiseCipher_1_3(pairwiseCipherMask); 1731 } else if (iSupplicantStaNetworkV12 != null) { 1732 /* Support for new key pairwise cipher types for SuiteB 1733 * Requires HAL v1.2 or higher */ 1734 status = iSupplicantStaNetworkV12.setPairwiseCipher_1_2(pairwiseCipherMask); 1735 } else { 1736 status = 1737 mISupplicantStaNetwork.setPairwiseCipher(pairwiseCipherMask); 1738 } 1739 return checkStatusAndLogFailure(status, methodStr); 1740 } catch (RemoteException e) { 1741 handleRemoteException(e, methodStr); 1742 return false; 1743 } 1744 } 1745 } 1746 1747 /** See ISupplicantStaNetwork.hal for documentation */ setGroupMgmtCipher(int groupMgmtCipherMask)1748 private boolean setGroupMgmtCipher(int groupMgmtCipherMask) { 1749 synchronized (mLock) { 1750 final String methodStr = "setGroupMgmtCipher"; 1751 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1752 try { 1753 android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1754 iSupplicantStaNetworkV12; 1755 1756 iSupplicantStaNetworkV12 = getV1_2StaNetwork(); 1757 if (iSupplicantStaNetworkV12 != null) { 1758 /* Support for new key pairwise cipher types for SuiteB 1759 * Requires HAL v1.2 or higher */ 1760 SupplicantStatus status = iSupplicantStaNetworkV12 1761 .setGroupMgmtCipher(groupMgmtCipherMask); 1762 return checkStatusAndLogFailure(status, methodStr); 1763 } else { 1764 return false; 1765 } 1766 } catch (RemoteException e) { 1767 handleRemoteException(e, methodStr); 1768 return false; 1769 } 1770 } 1771 } 1772 1773 /** See ISupplicantStaNetwork.hal for documentation */ setPskPassphrase(String psk)1774 private boolean setPskPassphrase(String psk) { 1775 synchronized (mLock) { 1776 final String methodStr = "setPskPassphrase"; 1777 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1778 try { 1779 SupplicantStatus status = mISupplicantStaNetwork.setPskPassphrase(psk); 1780 return checkStatusAndLogFailure(status, methodStr); 1781 } catch (RemoteException e) { 1782 handleRemoteException(e, methodStr); 1783 return false; 1784 } 1785 } 1786 } 1787 1788 /** See ISupplicantStaNetwork.hal for documentation */ setPsk(byte[] psk)1789 private boolean setPsk(byte[] psk) { 1790 synchronized (mLock) { 1791 final String methodStr = "setPsk"; 1792 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1793 try { 1794 SupplicantStatus status = mISupplicantStaNetwork.setPsk(psk); 1795 return checkStatusAndLogFailure(status, methodStr); 1796 } catch (RemoteException e) { 1797 handleRemoteException(e, methodStr); 1798 return false; 1799 } catch (ArrayIndexOutOfBoundsException e) { 1800 Log.e(TAG, "ISupplicantStaNetwork." + methodStr + " failed: " + e); 1801 return false; 1802 } 1803 } 1804 } 1805 1806 /** See ISupplicantStaNetwork.hal for documentation */ setWepKey(int keyIdx, java.util.ArrayList<Byte> wepKey)1807 private boolean setWepKey(int keyIdx, java.util.ArrayList<Byte> wepKey) { 1808 synchronized (mLock) { 1809 final String methodStr = "setWepKey"; 1810 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1811 try { 1812 SupplicantStatus status = mISupplicantStaNetwork.setWepKey(keyIdx, wepKey); 1813 return checkStatusAndLogFailure(status, methodStr); 1814 } catch (RemoteException e) { 1815 handleRemoteException(e, methodStr); 1816 return false; 1817 } 1818 } 1819 } 1820 1821 /** See ISupplicantStaNetwork.hal for documentation */ setWepTxKeyIdx(int keyIdx)1822 private boolean setWepTxKeyIdx(int keyIdx) { 1823 synchronized (mLock) { 1824 final String methodStr = "setWepTxKeyIdx"; 1825 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1826 try { 1827 SupplicantStatus status = mISupplicantStaNetwork.setWepTxKeyIdx(keyIdx); 1828 return checkStatusAndLogFailure(status, methodStr); 1829 } catch (RemoteException e) { 1830 handleRemoteException(e, methodStr); 1831 return false; 1832 } 1833 } 1834 } 1835 1836 /** See ISupplicantStaNetwork.hal for documentation */ setRequirePmf(boolean enable)1837 private boolean setRequirePmf(boolean enable) { 1838 synchronized (mLock) { 1839 final String methodStr = "setRequirePmf"; 1840 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1841 try { 1842 SupplicantStatus status = mISupplicantStaNetwork.setRequirePmf(enable); 1843 return checkStatusAndLogFailure(status, methodStr); 1844 } catch (RemoteException e) { 1845 handleRemoteException(e, methodStr); 1846 return false; 1847 } 1848 } 1849 } 1850 1851 /** See ISupplicantStaNetwork.hal for documentation */ setUpdateIdentifier(int identifier)1852 private boolean setUpdateIdentifier(int identifier) { 1853 synchronized (mLock) { 1854 final String methodStr = "setUpdateIdentifier"; 1855 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1856 try { 1857 SupplicantStatus status = mISupplicantStaNetwork.setUpdateIdentifier(identifier); 1858 return checkStatusAndLogFailure(status, methodStr); 1859 } catch (RemoteException e) { 1860 handleRemoteException(e, methodStr); 1861 return false; 1862 } 1863 } 1864 } 1865 1866 /** See ISupplicantStaNetwork.hal for documentation */ setWapiCertSuite(String certSuite)1867 private boolean setWapiCertSuite(String certSuite) { 1868 synchronized (mLock) { 1869 final String methodStr = "setWapiCertSuite"; 1870 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1871 try { 1872 android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 1873 iSupplicantStaNetworkV13 = getV1_3StaNetwork(); 1874 if (null != iSupplicantStaNetworkV13) { 1875 /* Requires HAL v1.3 or higher */ 1876 SupplicantStatus status = iSupplicantStaNetworkV13.setWapiCertSuite(certSuite); 1877 return checkStatusAndLogFailure(status, methodStr); 1878 } else { 1879 Log.e(TAG, "Cannot get ISupplicantStaNetwork V1.3"); 1880 return false; 1881 } 1882 } catch (RemoteException e) { 1883 handleRemoteException(e, methodStr); 1884 return false; 1885 } 1886 } 1887 } 1888 1889 /** See ISupplicantStaNetwork.hal for documentation */ setEapMethod(int method)1890 private boolean setEapMethod(int method) { 1891 synchronized (mLock) { 1892 final String methodStr = "setEapMethod"; 1893 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1894 try { 1895 SupplicantStatus status = mISupplicantStaNetwork.setEapMethod(method); 1896 return checkStatusAndLogFailure(status, methodStr); 1897 } catch (RemoteException e) { 1898 handleRemoteException(e, methodStr); 1899 return false; 1900 } 1901 } 1902 } 1903 1904 /** See ISupplicantStaNetwork.hal for documentation */ setEapPhase2Method(int method)1905 private boolean setEapPhase2Method(int method) { 1906 synchronized (mLock) { 1907 final String methodStr = "setEapPhase2Method"; 1908 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1909 try { 1910 SupplicantStatus status = mISupplicantStaNetwork.setEapPhase2Method(method); 1911 return checkStatusAndLogFailure(status, methodStr); 1912 } catch (RemoteException e) { 1913 handleRemoteException(e, methodStr); 1914 return false; 1915 } 1916 } 1917 } 1918 1919 /** See ISupplicantStaNetwork.hal for documentation */ setEapIdentity(java.util.ArrayList<Byte> identity)1920 private boolean setEapIdentity(java.util.ArrayList<Byte> identity) { 1921 synchronized (mLock) { 1922 final String methodStr = "setEapIdentity"; 1923 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1924 try { 1925 SupplicantStatus status = mISupplicantStaNetwork.setEapIdentity(identity); 1926 return checkStatusAndLogFailure(status, methodStr); 1927 } catch (RemoteException e) { 1928 handleRemoteException(e, methodStr); 1929 return false; 1930 } 1931 } 1932 } 1933 1934 /** See ISupplicantStaNetwork.hal for documentation */ setEapAnonymousIdentity(java.util.ArrayList<Byte> identity)1935 private boolean setEapAnonymousIdentity(java.util.ArrayList<Byte> identity) { 1936 synchronized (mLock) { 1937 final String methodStr = "setEapAnonymousIdentity"; 1938 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1939 try { 1940 SupplicantStatus status = mISupplicantStaNetwork.setEapAnonymousIdentity(identity); 1941 return checkStatusAndLogFailure(status, methodStr); 1942 } catch (RemoteException e) { 1943 handleRemoteException(e, methodStr); 1944 return false; 1945 } 1946 } 1947 } 1948 1949 /** See ISupplicantStaNetwork.hal for documentation */ setEapPassword(java.util.ArrayList<Byte> password)1950 private boolean setEapPassword(java.util.ArrayList<Byte> password) { 1951 synchronized (mLock) { 1952 final String methodStr = "setEapPassword"; 1953 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1954 try { 1955 SupplicantStatus status = mISupplicantStaNetwork.setEapPassword(password); 1956 return checkStatusAndLogFailure(status, methodStr); 1957 } catch (RemoteException e) { 1958 handleRemoteException(e, methodStr); 1959 return false; 1960 } 1961 } 1962 } 1963 1964 /** See ISupplicantStaNetwork.hal for documentation */ setEapCACert(String path)1965 private boolean setEapCACert(String path) { 1966 synchronized (mLock) { 1967 final String methodStr = "setEapCACert"; 1968 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1969 try { 1970 SupplicantStatus status = mISupplicantStaNetwork.setEapCACert(path); 1971 return checkStatusAndLogFailure(status, methodStr); 1972 } catch (RemoteException e) { 1973 handleRemoteException(e, methodStr); 1974 return false; 1975 } 1976 } 1977 } 1978 1979 /** See ISupplicantStaNetwork.hal for documentation */ setEapCAPath(String path)1980 private boolean setEapCAPath(String path) { 1981 synchronized (mLock) { 1982 final String methodStr = "setEapCAPath"; 1983 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1984 try { 1985 SupplicantStatus status = mISupplicantStaNetwork.setEapCAPath(path); 1986 return checkStatusAndLogFailure(status, methodStr); 1987 } catch (RemoteException e) { 1988 handleRemoteException(e, methodStr); 1989 return false; 1990 } 1991 } 1992 } 1993 1994 /** See ISupplicantStaNetwork.hal for documentation */ setEapClientCert(String path)1995 private boolean setEapClientCert(String path) { 1996 synchronized (mLock) { 1997 final String methodStr = "setEapClientCert"; 1998 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 1999 try { 2000 SupplicantStatus status = mISupplicantStaNetwork.setEapClientCert(path); 2001 return checkStatusAndLogFailure(status, methodStr); 2002 } catch (RemoteException e) { 2003 handleRemoteException(e, methodStr); 2004 return false; 2005 } 2006 } 2007 } 2008 2009 /** See ISupplicantStaNetwork.hal for documentation */ setEapPrivateKeyId(String id)2010 private boolean setEapPrivateKeyId(String id) { 2011 synchronized (mLock) { 2012 final String methodStr = "setEapPrivateKeyId"; 2013 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2014 try { 2015 SupplicantStatus status = mISupplicantStaNetwork.setEapPrivateKeyId(id); 2016 return checkStatusAndLogFailure(status, methodStr); 2017 } catch (RemoteException e) { 2018 handleRemoteException(e, methodStr); 2019 return false; 2020 } 2021 } 2022 } 2023 2024 /** See ISupplicantStaNetwork.hal for documentation */ setEapSubjectMatch(String match)2025 private boolean setEapSubjectMatch(String match) { 2026 synchronized (mLock) { 2027 final String methodStr = "setEapSubjectMatch"; 2028 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2029 try { 2030 SupplicantStatus status = mISupplicantStaNetwork.setEapSubjectMatch(match); 2031 return checkStatusAndLogFailure(status, methodStr); 2032 } catch (RemoteException e) { 2033 handleRemoteException(e, methodStr); 2034 return false; 2035 } 2036 } 2037 } 2038 2039 /** See ISupplicantStaNetwork.hal for documentation */ setEapAltSubjectMatch(String match)2040 private boolean setEapAltSubjectMatch(String match) { 2041 synchronized (mLock) { 2042 final String methodStr = "setEapAltSubjectMatch"; 2043 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2044 try { 2045 SupplicantStatus status = mISupplicantStaNetwork.setEapAltSubjectMatch(match); 2046 return checkStatusAndLogFailure(status, methodStr); 2047 } catch (RemoteException e) { 2048 handleRemoteException(e, methodStr); 2049 return false; 2050 } 2051 } 2052 } 2053 2054 /** See ISupplicantStaNetwork.hal for documentation */ setEapEngine(boolean enable)2055 private boolean setEapEngine(boolean enable) { 2056 synchronized (mLock) { 2057 final String methodStr = "setEapEngine"; 2058 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2059 try { 2060 SupplicantStatus status = mISupplicantStaNetwork.setEapEngine(enable); 2061 return checkStatusAndLogFailure(status, methodStr); 2062 } catch (RemoteException e) { 2063 handleRemoteException(e, methodStr); 2064 return false; 2065 } 2066 } 2067 } 2068 2069 /** See ISupplicantStaNetwork.hal for documentation */ setEapEngineID(String id)2070 private boolean setEapEngineID(String id) { 2071 synchronized (mLock) { 2072 final String methodStr = "setEapEngineID"; 2073 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2074 try { 2075 SupplicantStatus status = mISupplicantStaNetwork.setEapEngineID(id); 2076 return checkStatusAndLogFailure(status, methodStr); 2077 } catch (RemoteException e) { 2078 handleRemoteException(e, methodStr); 2079 return false; 2080 } 2081 } 2082 } 2083 2084 /** See ISupplicantStaNetwork.hal for documentation */ setEapDomainSuffixMatch(String match)2085 private boolean setEapDomainSuffixMatch(String match) { 2086 synchronized (mLock) { 2087 final String methodStr = "setEapDomainSuffixMatch"; 2088 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2089 try { 2090 SupplicantStatus status = mISupplicantStaNetwork.setEapDomainSuffixMatch(match); 2091 return checkStatusAndLogFailure(status, methodStr); 2092 } catch (RemoteException e) { 2093 handleRemoteException(e, methodStr); 2094 return false; 2095 } 2096 } 2097 } 2098 2099 /** See ISupplicantStaNetwork.hal for documentation */ setEapProactiveKeyCaching(boolean enable)2100 private boolean setEapProactiveKeyCaching(boolean enable) { 2101 synchronized (mLock) { 2102 final String methodStr = "setEapProactiveKeyCaching"; 2103 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2104 try { 2105 SupplicantStatus status = mISupplicantStaNetwork.setProactiveKeyCaching(enable); 2106 return checkStatusAndLogFailure(status, methodStr); 2107 } catch (RemoteException e) { 2108 handleRemoteException(e, methodStr); 2109 return false; 2110 } 2111 } 2112 } 2113 2114 /** See ISupplicantStaNetwork.hal for documentation */ setIdStr(String idString)2115 private boolean setIdStr(String idString) { 2116 synchronized (mLock) { 2117 final String methodStr = "setIdStr"; 2118 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2119 try { 2120 SupplicantStatus status = mISupplicantStaNetwork.setIdStr(idString); 2121 return checkStatusAndLogFailure(status, methodStr); 2122 } catch (RemoteException e) { 2123 handleRemoteException(e, methodStr); 2124 return false; 2125 } 2126 } 2127 } 2128 2129 /** See ISupplicantStaNetwork.hal for documentation */ setSaePassword(String saePassword)2130 private boolean setSaePassword(String saePassword) { 2131 synchronized (mLock) { 2132 final String methodStr = "setSaePassword"; 2133 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2134 try { 2135 android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 2136 iSupplicantStaNetworkV12; 2137 2138 iSupplicantStaNetworkV12 = getV1_2StaNetwork(); 2139 if (iSupplicantStaNetworkV12 != null) { 2140 /* Support for SAE Requires HAL v1.2 or higher */ 2141 SupplicantStatus status = iSupplicantStaNetworkV12.setSaePassword(saePassword); 2142 return checkStatusAndLogFailure(status, methodStr); 2143 } else { 2144 return false; 2145 } 2146 } catch (RemoteException e) { 2147 handleRemoteException(e, methodStr); 2148 return false; 2149 } 2150 } 2151 } 2152 2153 /** See ISupplicantStaNetwork.hal for documentation */ setEapErp(boolean enable)2154 private boolean setEapErp(boolean enable) { 2155 synchronized (mLock) { 2156 final String methodStr = "setEapErp"; 2157 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2158 try { 2159 android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 2160 iSupplicantStaNetworkV13; 2161 2162 iSupplicantStaNetworkV13 = getV1_3StaNetwork(); 2163 if (iSupplicantStaNetworkV13 != null) { 2164 /* Support for set ERP Requires HAL v1.3 or higher */ 2165 SupplicantStatus status = iSupplicantStaNetworkV13.setEapErp(enable); 2166 return checkStatusAndLogFailure(status, methodStr); 2167 } else { 2168 return false; 2169 } 2170 } catch (RemoteException e) { 2171 handleRemoteException(e, methodStr); 2172 return false; 2173 } 2174 } 2175 } 2176 2177 /** See ISupplicantStaNetwork.hal for documentation */ getSsid()2178 private boolean getSsid() { 2179 synchronized (mLock) { 2180 final String methodStr = "getSsid"; 2181 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2182 try { 2183 Mutable<Boolean> statusOk = new Mutable<>(false); 2184 mISupplicantStaNetwork.getSsid((SupplicantStatus status, 2185 java.util.ArrayList<Byte> ssidValue) -> { 2186 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2187 if (statusOk.value) { 2188 this.mSsid = ssidValue; 2189 } else { 2190 checkStatusAndLogFailure(status, methodStr); 2191 } 2192 }); 2193 return statusOk.value; 2194 } catch (RemoteException e) { 2195 handleRemoteException(e, methodStr); 2196 return false; 2197 } 2198 } 2199 } 2200 2201 /** See ISupplicantStaNetwork.hal for documentation */ getBssid()2202 private boolean getBssid() { 2203 synchronized (mLock) { 2204 final String methodStr = "getBssid"; 2205 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2206 try { 2207 Mutable<Boolean> statusOk = new Mutable<>(false); 2208 mISupplicantStaNetwork.getBssid((SupplicantStatus status, 2209 byte[/* 6 */] bssidValue) -> { 2210 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2211 if (statusOk.value) { 2212 this.mBssid = bssidValue; 2213 } else { 2214 checkStatusAndLogFailure(status, methodStr); 2215 } 2216 }); 2217 return statusOk.value; 2218 } catch (RemoteException e) { 2219 handleRemoteException(e, methodStr); 2220 return false; 2221 } 2222 } 2223 } 2224 2225 /** See ISupplicantStaNetwork.hal for documentation */ getScanSsid()2226 private boolean getScanSsid() { 2227 synchronized (mLock) { 2228 final String methodStr = "getScanSsid"; 2229 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2230 try { 2231 Mutable<Boolean> statusOk = new Mutable<>(false); 2232 mISupplicantStaNetwork.getScanSsid((SupplicantStatus status, 2233 boolean enabledValue) -> { 2234 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2235 if (statusOk.value) { 2236 this.mScanSsid = enabledValue; 2237 } else { 2238 checkStatusAndLogFailure(status, methodStr); 2239 } 2240 }); 2241 return statusOk.value; 2242 } catch (RemoteException e) { 2243 handleRemoteException(e, methodStr); 2244 return false; 2245 } 2246 } 2247 } 2248 2249 /** See ISupplicantStaNetwork.hal for documentation */ getKeyMgmt()2250 private boolean getKeyMgmt() { 2251 synchronized (mLock) { 2252 final String methodStr = "getKeyMgmt"; 2253 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2254 if (getV1_3StaNetwork() != null) { 2255 return getKeyMgmt_1_3(); 2256 } else { 2257 try { 2258 Mutable<Boolean> statusOk = new Mutable<>(false); 2259 mISupplicantStaNetwork.getKeyMgmt((SupplicantStatus status, 2260 int keyMgmtMaskValue) -> { 2261 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2262 if (statusOk.value) { 2263 this.mKeyMgmtMask = keyMgmtMaskValue; 2264 } else { 2265 checkStatusAndLogFailure(status, methodStr); 2266 } 2267 }); 2268 return statusOk.value; 2269 } catch (RemoteException e) { 2270 handleRemoteException(e, methodStr); 2271 return false; 2272 } 2273 } 2274 } 2275 } 2276 getKeyMgmt_1_3()2277 private boolean getKeyMgmt_1_3() { 2278 synchronized (mLock) { 2279 final String methodStr = "getKeyMgmt_1_3"; 2280 try { 2281 android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 2282 iSupplicantStaNetworkV13 = getV1_3StaNetwork(); 2283 if (null == iSupplicantStaNetworkV13) return false; 2284 Mutable<Boolean> statusOk = new Mutable<>(false); 2285 iSupplicantStaNetworkV13.getKeyMgmt_1_3((SupplicantStatus status, 2286 int keyMgmtMaskValue) -> { 2287 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2288 if (statusOk.value) { 2289 this.mKeyMgmtMask = keyMgmtMaskValue; 2290 } else { 2291 checkStatusAndLogFailure(status, methodStr); 2292 } 2293 }); 2294 return statusOk.value; 2295 } catch (RemoteException e) { 2296 handleRemoteException(e, methodStr); 2297 return false; 2298 } 2299 } 2300 } 2301 2302 /** See ISupplicantStaNetwork.hal for documentation */ getProto()2303 private boolean getProto() { 2304 synchronized (mLock) { 2305 final String methodStr = "getProto"; 2306 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2307 if (getV1_3StaNetwork() != null) { 2308 return getProto_1_3(); 2309 } else { 2310 try { 2311 Mutable<Boolean> statusOk = new Mutable<>(false); 2312 mISupplicantStaNetwork.getProto( 2313 (SupplicantStatus status, int protoMaskValue) -> { 2314 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2315 if (statusOk.value) { 2316 this.mProtoMask = protoMaskValue; 2317 } else { 2318 checkStatusAndLogFailure(status, methodStr); 2319 } 2320 }); 2321 return statusOk.value; 2322 } catch (RemoteException e) { 2323 handleRemoteException(e, methodStr); 2324 return false; 2325 } 2326 } 2327 } 2328 } 2329 getProto_1_3()2330 private boolean getProto_1_3() { 2331 synchronized (mLock) { 2332 final String methodStr = "getProto_1_3"; 2333 try { 2334 android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 2335 iSupplicantStaNetworkV13 = getV1_3StaNetwork(); 2336 if (null == iSupplicantStaNetworkV13) return false; 2337 Mutable<Boolean> statusOk = new Mutable<>(false); 2338 iSupplicantStaNetworkV13.getProto_1_3( 2339 (SupplicantStatus status, int protoMaskValue) -> { 2340 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2341 if (statusOk.value) { 2342 this.mProtoMask = protoMaskValue; 2343 } else { 2344 checkStatusAndLogFailure(status, methodStr); 2345 } 2346 }); 2347 return statusOk.value; 2348 } catch (RemoteException e) { 2349 handleRemoteException(e, methodStr); 2350 return false; 2351 } 2352 } 2353 } 2354 2355 /** See ISupplicantStaNetwork.hal for documentation */ getAuthAlg()2356 private boolean getAuthAlg() { 2357 synchronized (mLock) { 2358 final String methodStr = "getAuthAlg"; 2359 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2360 if (getV1_3StaNetwork() != null) { 2361 return getAuthAlg_1_3(); 2362 } 2363 try { 2364 Mutable<Boolean> statusOk = new Mutable<>(false); 2365 mISupplicantStaNetwork.getAuthAlg((SupplicantStatus status, 2366 int authAlgMaskValue) -> { 2367 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2368 if (statusOk.value) { 2369 this.mAuthAlgMask = authAlgMaskValue; 2370 } else { 2371 checkStatusAndLogFailure(status, methodStr); 2372 } 2373 }); 2374 return statusOk.value; 2375 } catch (RemoteException e) { 2376 handleRemoteException(e, methodStr); 2377 return false; 2378 } 2379 } 2380 } 2381 getAuthAlg_1_3()2382 private boolean getAuthAlg_1_3() { 2383 final String methodStr = "getAuthAlg_1_3"; 2384 try { 2385 android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 2386 iSupplicantStaNetworkV13 = getV1_3StaNetwork(); 2387 if (null == iSupplicantStaNetworkV13) return false; 2388 Mutable<Boolean> statusOk = new Mutable<>(false); 2389 iSupplicantStaNetworkV13.getAuthAlg_1_3((SupplicantStatus status, 2390 int authAlgMaskValue) -> { 2391 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2392 if (statusOk.value) { 2393 this.mAuthAlgMask = authAlgMaskValue; 2394 } else { 2395 checkStatusAndLogFailure(status, methodStr); 2396 } 2397 }); 2398 return statusOk.value; 2399 } catch (RemoteException e) { 2400 handleRemoteException(e, methodStr); 2401 return false; 2402 } 2403 } 2404 2405 /** See ISupplicantStaNetwork.hal for documentation */ getGroupCipher()2406 private boolean getGroupCipher() { 2407 synchronized (mLock) { 2408 final String methodStr = "getGroupCipher"; 2409 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2410 if (getV1_4StaNetwork() != null) { 2411 return getGroupCipher_1_4(); 2412 } else if (getV1_3StaNetwork() != null) { 2413 return getGroupCipher_1_3(); 2414 } else { 2415 try { 2416 Mutable<Boolean> statusOk = new Mutable<>(false); 2417 mISupplicantStaNetwork.getGroupCipher((SupplicantStatus status, 2418 int groupCipherMaskValue) -> { 2419 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2420 if (statusOk.value) { 2421 this.mGroupCipherMask = groupCipherMaskValue; 2422 } else { 2423 checkStatusAndLogFailure(status, methodStr); 2424 } 2425 }); 2426 return statusOk.value; 2427 } catch (RemoteException e) { 2428 handleRemoteException(e, methodStr); 2429 return false; 2430 } 2431 } 2432 } 2433 } 2434 getGroupCipher_1_3()2435 private boolean getGroupCipher_1_3() { 2436 synchronized (mLock) { 2437 final String methodStr = "getGroupCipher_1_3"; 2438 try { 2439 android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 2440 iSupplicantStaNetworkV13 = getV1_3StaNetwork(); 2441 if (null == iSupplicantStaNetworkV13) return false; 2442 Mutable<Boolean> statusOk = new Mutable<>(false); 2443 iSupplicantStaNetworkV13.getGroupCipher_1_3((SupplicantStatus status, 2444 int groupCipherMaskValue) -> { 2445 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2446 if (statusOk.value) { 2447 this.mGroupCipherMask = groupCipherMaskValue; 2448 } else { 2449 checkStatusAndLogFailure(status, methodStr); 2450 } 2451 }); 2452 return statusOk.value; 2453 } catch (RemoteException e) { 2454 handleRemoteException(e, methodStr); 2455 return false; 2456 } 2457 } 2458 } 2459 getGroupCipher_1_4()2460 private boolean getGroupCipher_1_4() { 2461 synchronized (mLock) { 2462 final String methodStr = "getGroupCipher_1_4"; 2463 try { 2464 android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetwork 2465 iSupplicantStaNetworkV14 = getV1_4StaNetwork(); 2466 if (null == iSupplicantStaNetworkV14) return false; 2467 Mutable<Boolean> statusOk = new Mutable<>(false); 2468 iSupplicantStaNetworkV14.getGroupCipher_1_4(( 2469 android.hardware.wifi.supplicant.V1_4.SupplicantStatus status, 2470 int groupCipherMaskValue) -> { 2471 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2472 if (statusOk.value) { 2473 this.mGroupCipherMask = groupCipherMaskValue; 2474 } else { 2475 checkStatusAndLogFailure(status, methodStr); 2476 } 2477 }); 2478 return statusOk.value; 2479 } catch (RemoteException e) { 2480 handleRemoteException(e, methodStr); 2481 return false; 2482 } 2483 } 2484 } 2485 2486 /** See ISupplicantStaNetwork.hal for documentation */ getPairwiseCipher()2487 private boolean getPairwiseCipher() { 2488 synchronized (mLock) { 2489 final String methodStr = "getPairwiseCipher"; 2490 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2491 if (getV1_4StaNetwork() != null) { 2492 return getPairwiseCipher_1_4(); 2493 } else if (getV1_3StaNetwork() != null) { 2494 return getPairwiseCipher_1_3(); 2495 } else { 2496 try { 2497 Mutable<Boolean> statusOk = new Mutable<>(false); 2498 mISupplicantStaNetwork.getPairwiseCipher((SupplicantStatus status, 2499 int pairwiseCipherMaskValue) -> { 2500 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2501 if (statusOk.value) { 2502 this.mPairwiseCipherMask = pairwiseCipherMaskValue; 2503 } else { 2504 checkStatusAndLogFailure(status, methodStr); 2505 } 2506 }); 2507 return statusOk.value; 2508 } catch (RemoteException e) { 2509 handleRemoteException(e, methodStr); 2510 return false; 2511 } 2512 } 2513 } 2514 } 2515 getPairwiseCipher_1_3()2516 private boolean getPairwiseCipher_1_3() { 2517 synchronized (mLock) { 2518 final String methodStr = "getPairwiseCipher_1_3"; 2519 try { 2520 android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 2521 iSupplicantStaNetworkV13 = getV1_3StaNetwork(); 2522 if (null == iSupplicantStaNetworkV13) return false; 2523 Mutable<Boolean> statusOk = new Mutable<>(false); 2524 iSupplicantStaNetworkV13.getPairwiseCipher_1_3((SupplicantStatus status, 2525 int pairwiseCipherMaskValue) -> { 2526 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2527 if (statusOk.value) { 2528 this.mPairwiseCipherMask = pairwiseCipherMaskValue; 2529 } else { 2530 checkStatusAndLogFailure(status, methodStr); 2531 } 2532 }); 2533 return statusOk.value; 2534 } catch (RemoteException e) { 2535 handleRemoteException(e, methodStr); 2536 return false; 2537 } 2538 } 2539 } 2540 getPairwiseCipher_1_4()2541 private boolean getPairwiseCipher_1_4() { 2542 synchronized (mLock) { 2543 final String methodStr = "getPairwiseCipher_1_4"; 2544 try { 2545 android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetwork 2546 iSupplicantStaNetworkV14 = getV1_4StaNetwork(); 2547 if (null == iSupplicantStaNetworkV14) return false; 2548 Mutable<Boolean> statusOk = new Mutable<>(false); 2549 iSupplicantStaNetworkV14.getPairwiseCipher_1_4(( 2550 android.hardware.wifi.supplicant.V1_4.SupplicantStatus status, 2551 int pairwiseCipherMaskValue) -> { 2552 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2553 if (statusOk.value) { 2554 this.mPairwiseCipherMask = pairwiseCipherMaskValue; 2555 } else { 2556 checkStatusAndLogFailure(status, methodStr); 2557 } 2558 }); 2559 return statusOk.value; 2560 } catch (RemoteException e) { 2561 handleRemoteException(e, methodStr); 2562 return false; 2563 } 2564 } 2565 } 2566 2567 /** See ISupplicantStaNetwork.hal for documentation */ getGroupMgmtCipher()2568 private boolean getGroupMgmtCipher() { 2569 synchronized (mLock) { 2570 final String methodStr = "getGroupMgmtCipher"; 2571 android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 2572 iSupplicantStaNetworkV12; 2573 2574 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2575 try { 2576 iSupplicantStaNetworkV12 = getV1_2StaNetwork(); 2577 if (iSupplicantStaNetworkV12 != null) { 2578 Mutable<Boolean> statusOk = new Mutable<>(false); 2579 iSupplicantStaNetworkV12.getGroupMgmtCipher((SupplicantStatus status, 2580 int groupMgmtCipherMaskValue) -> { 2581 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2582 if (statusOk.value) { 2583 this.mGroupMgmtCipherMask = groupMgmtCipherMaskValue; 2584 } 2585 checkStatusAndLogFailure(status, methodStr); 2586 }); 2587 return statusOk.value; 2588 } else { 2589 return false; 2590 } 2591 } catch (RemoteException e) { 2592 handleRemoteException(e, methodStr); 2593 return false; 2594 } 2595 } 2596 } 2597 2598 /** See ISupplicantStaNetwork.hal for documentation */ getPskPassphrase()2599 private boolean getPskPassphrase() { 2600 synchronized (mLock) { 2601 final String methodStr = "getPskPassphrase"; 2602 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2603 try { 2604 Mutable<Boolean> statusOk = new Mutable<>(false); 2605 mISupplicantStaNetwork.getPskPassphrase((SupplicantStatus status, 2606 String pskValue) -> { 2607 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2608 if (statusOk.value) { 2609 this.mPskPassphrase = pskValue; 2610 } else { 2611 checkStatusAndLogFailure(status, methodStr); 2612 } 2613 }); 2614 return statusOk.value; 2615 } catch (RemoteException e) { 2616 handleRemoteException(e, methodStr); 2617 return false; 2618 } 2619 } 2620 } 2621 2622 /** See ISupplicantStaNetwork.hal for documentation */ getSaePassword()2623 private boolean getSaePassword() { 2624 synchronized (mLock) { 2625 final String methodStr = "getSaePassword"; 2626 android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 2627 iSupplicantStaNetworkV12; 2628 2629 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2630 try { 2631 iSupplicantStaNetworkV12 = getV1_2StaNetwork(); 2632 if (iSupplicantStaNetworkV12 != null) { 2633 Mutable<Boolean> statusOk = new Mutable<>(false); 2634 iSupplicantStaNetworkV12.getSaePassword((SupplicantStatus status, 2635 String saePassword) -> { 2636 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2637 if (statusOk.value) { 2638 this.mSaePassword = saePassword; 2639 } 2640 checkStatusAndLogFailure(status, methodStr); 2641 }); 2642 return statusOk.value; 2643 } else { 2644 return false; 2645 } 2646 } catch (RemoteException e) { 2647 handleRemoteException(e, methodStr); 2648 return false; 2649 } 2650 } 2651 } 2652 2653 /** See ISupplicantStaNetwork.hal for documentation */ getPsk()2654 private boolean getPsk() { 2655 synchronized (mLock) { 2656 final String methodStr = "getPsk"; 2657 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2658 try { 2659 Mutable<Boolean> statusOk = new Mutable<>(false); 2660 mISupplicantStaNetwork.getPsk((SupplicantStatus status, byte[] pskValue) -> { 2661 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2662 if (statusOk.value) { 2663 this.mPsk = pskValue; 2664 } else { 2665 checkStatusAndLogFailure(status, methodStr); 2666 } 2667 }); 2668 return statusOk.value; 2669 } catch (RemoteException e) { 2670 handleRemoteException(e, methodStr); 2671 return false; 2672 } 2673 } 2674 } 2675 2676 /** See ISupplicantStaNetwork.hal for documentation */ getWepKey(int keyIdx)2677 private boolean getWepKey(int keyIdx) { 2678 synchronized (mLock) { 2679 final String methodStr = "keyIdx"; 2680 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2681 try { 2682 Mutable<Boolean> statusOk = new Mutable<>(false); 2683 mISupplicantStaNetwork.getWepKey(keyIdx, (SupplicantStatus status, 2684 java.util.ArrayList<Byte> wepKeyValue) -> { 2685 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2686 if (statusOk.value) { 2687 this.mWepKey = wepKeyValue; 2688 } else { 2689 Log.e(TAG, methodStr + ", failed: " + status.debugMessage); 2690 } 2691 }); 2692 return statusOk.value; 2693 } catch (RemoteException e) { 2694 handleRemoteException(e, methodStr); 2695 return false; 2696 } 2697 } 2698 } 2699 2700 /** See ISupplicantStaNetwork.hal for documentation */ getWepTxKeyIdx()2701 private boolean getWepTxKeyIdx() { 2702 synchronized (mLock) { 2703 final String methodStr = "getWepTxKeyIdx"; 2704 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2705 try { 2706 Mutable<Boolean> statusOk = new Mutable<>(false); 2707 mISupplicantStaNetwork.getWepTxKeyIdx((SupplicantStatus status, 2708 int keyIdxValue) -> { 2709 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2710 if (statusOk.value) { 2711 this.mWepTxKeyIdx = keyIdxValue; 2712 } else { 2713 checkStatusAndLogFailure(status, methodStr); 2714 } 2715 }); 2716 return statusOk.value; 2717 } catch (RemoteException e) { 2718 handleRemoteException(e, methodStr); 2719 return false; 2720 } 2721 } 2722 } 2723 2724 /** See ISupplicantStaNetwork.hal for documentation */ getRequirePmf()2725 private boolean getRequirePmf() { 2726 synchronized (mLock) { 2727 final String methodStr = "getRequirePmf"; 2728 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2729 try { 2730 Mutable<Boolean> statusOk = new Mutable<>(false); 2731 mISupplicantStaNetwork.getRequirePmf((SupplicantStatus status, 2732 boolean enabledValue) -> { 2733 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2734 if (statusOk.value) { 2735 this.mRequirePmf = enabledValue; 2736 } else { 2737 checkStatusAndLogFailure(status, methodStr); 2738 } 2739 }); 2740 return statusOk.value; 2741 } catch (RemoteException e) { 2742 handleRemoteException(e, methodStr); 2743 return false; 2744 } 2745 } 2746 } 2747 2748 /** See ISupplicantStaNetwork.hal for documentation */ getWapiCertSuite()2749 private boolean getWapiCertSuite() { 2750 synchronized (mLock) { 2751 final String methodStr = "getWapiCertSuite"; 2752 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2753 try { 2754 android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 2755 iSupplicantStaNetworkV13; 2756 iSupplicantStaNetworkV13 = getV1_3StaNetwork(); 2757 if (iSupplicantStaNetworkV13 != null) { 2758 Mutable<Boolean> statusOk = new Mutable<>(false); 2759 iSupplicantStaNetworkV13.getWapiCertSuite((SupplicantStatus status, 2760 String suiteValue) -> { 2761 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2762 if (statusOk.value) { 2763 mWapiCertSuite = suiteValue; 2764 } else { 2765 checkStatusAndLogFailure(status, methodStr); 2766 } 2767 }); 2768 return statusOk.value; 2769 } else { 2770 Log.e(TAG, "Cannot get ISupplicantStaNetwork V1.3"); 2771 return false; 2772 } 2773 } catch (RemoteException e) { 2774 handleRemoteException(e, methodStr); 2775 return false; 2776 } 2777 } 2778 } 2779 2780 /** See ISupplicantStaNetwork.hal for documentation */ getEapMethod()2781 private boolean getEapMethod() { 2782 synchronized (mLock) { 2783 final String methodStr = "getEapMethod"; 2784 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2785 try { 2786 Mutable<Boolean> statusOk = new Mutable<>(false); 2787 mISupplicantStaNetwork.getEapMethod((SupplicantStatus status, 2788 int methodValue) -> { 2789 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2790 if (statusOk.value) { 2791 this.mEapMethod = methodValue; 2792 } else { 2793 checkStatusAndLogFailure(status, methodStr); 2794 } 2795 }); 2796 return statusOk.value; 2797 } catch (RemoteException e) { 2798 handleRemoteException(e, methodStr); 2799 return false; 2800 } 2801 } 2802 } 2803 2804 /** See ISupplicantStaNetwork.hal for documentation */ getEapPhase2Method()2805 private boolean getEapPhase2Method() { 2806 synchronized (mLock) { 2807 final String methodStr = "getEapPhase2Method"; 2808 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2809 try { 2810 Mutable<Boolean> statusOk = new Mutable<>(false); 2811 mISupplicantStaNetwork.getEapPhase2Method((SupplicantStatus status, 2812 int methodValue) -> { 2813 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2814 if (statusOk.value) { 2815 this.mEapPhase2Method = methodValue; 2816 } else { 2817 checkStatusAndLogFailure(status, methodStr); 2818 } 2819 }); 2820 return statusOk.value; 2821 } catch (RemoteException e) { 2822 handleRemoteException(e, methodStr); 2823 return false; 2824 } 2825 } 2826 } 2827 2828 /** See ISupplicantStaNetwork.hal for documentation */ getEapIdentity()2829 private boolean getEapIdentity() { 2830 synchronized (mLock) { 2831 final String methodStr = "getEapIdentity"; 2832 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2833 try { 2834 Mutable<Boolean> statusOk = new Mutable<>(false); 2835 mISupplicantStaNetwork.getEapIdentity((SupplicantStatus status, 2836 ArrayList<Byte> identityValue) -> { 2837 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2838 if (statusOk.value) { 2839 this.mEapIdentity = identityValue; 2840 } else { 2841 checkStatusAndLogFailure(status, methodStr); 2842 } 2843 }); 2844 return statusOk.value; 2845 } catch (RemoteException e) { 2846 handleRemoteException(e, methodStr); 2847 return false; 2848 } 2849 } 2850 } 2851 2852 /** See ISupplicantStaNetwork.hal for documentation */ getEapAnonymousIdentity()2853 private boolean getEapAnonymousIdentity() { 2854 synchronized (mLock) { 2855 final String methodStr = "getEapAnonymousIdentity"; 2856 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2857 try { 2858 Mutable<Boolean> statusOk = new Mutable<>(false); 2859 mISupplicantStaNetwork.getEapAnonymousIdentity((SupplicantStatus status, 2860 ArrayList<Byte> identityValue) -> { 2861 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2862 if (statusOk.value) { 2863 this.mEapAnonymousIdentity = identityValue; 2864 } else { 2865 checkStatusAndLogFailure(status, methodStr); 2866 } 2867 }); 2868 return statusOk.value; 2869 } catch (RemoteException e) { 2870 handleRemoteException(e, methodStr); 2871 return false; 2872 } 2873 } 2874 } 2875 2876 /** 2877 * A wrapping method for getEapAnonymousIdentity(). 2878 * This get anonymous identity from supplicant and returns it as a string. 2879 * 2880 * @return anonymous identity string if succeeds, null otherwise. 2881 */ fetchEapAnonymousIdentity()2882 public String fetchEapAnonymousIdentity() { 2883 synchronized (mLock) { 2884 if (!getEapAnonymousIdentity()) { 2885 return null; 2886 } 2887 return NativeUtil.stringFromByteArrayList(mEapAnonymousIdentity); 2888 } 2889 } 2890 2891 /** See ISupplicantStaNetwork.hal for documentation */ getEapPassword()2892 private boolean getEapPassword() { 2893 synchronized (mLock) { 2894 final String methodStr = "getEapPassword"; 2895 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2896 try { 2897 Mutable<Boolean> statusOk = new Mutable<>(false); 2898 mISupplicantStaNetwork.getEapPassword((SupplicantStatus status, 2899 ArrayList<Byte> passwordValue) -> { 2900 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2901 if (statusOk.value) { 2902 this.mEapPassword = passwordValue; 2903 } else { 2904 checkStatusAndLogFailure(status, methodStr); 2905 } 2906 }); 2907 return statusOk.value; 2908 } catch (RemoteException e) { 2909 handleRemoteException(e, methodStr); 2910 return false; 2911 } 2912 } 2913 } 2914 2915 /** See ISupplicantStaNetwork.hal for documentation */ getEapCACert()2916 private boolean getEapCACert() { 2917 synchronized (mLock) { 2918 final String methodStr = "getEapCACert"; 2919 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2920 try { 2921 Mutable<Boolean> statusOk = new Mutable<>(false); 2922 mISupplicantStaNetwork.getEapCACert((SupplicantStatus status, String pathValue) -> { 2923 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2924 if (statusOk.value) { 2925 this.mEapCACert = pathValue; 2926 } else { 2927 checkStatusAndLogFailure(status, methodStr); 2928 } 2929 }); 2930 return statusOk.value; 2931 } catch (RemoteException e) { 2932 handleRemoteException(e, methodStr); 2933 return false; 2934 } 2935 } 2936 } 2937 2938 /** See ISupplicantStaNetwork.hal for documentation */ getEapCAPath()2939 private boolean getEapCAPath() { 2940 synchronized (mLock) { 2941 final String methodStr = "getEapCAPath"; 2942 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2943 try { 2944 Mutable<Boolean> statusOk = new Mutable<>(false); 2945 mISupplicantStaNetwork.getEapCAPath((SupplicantStatus status, String pathValue) -> { 2946 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2947 if (statusOk.value) { 2948 this.mEapCAPath = pathValue; 2949 } else { 2950 checkStatusAndLogFailure(status, methodStr); 2951 } 2952 }); 2953 return statusOk.value; 2954 } catch (RemoteException e) { 2955 handleRemoteException(e, methodStr); 2956 return false; 2957 } 2958 } 2959 } 2960 2961 /** See ISupplicantStaNetwork.hal for documentation */ getEapClientCert()2962 private boolean getEapClientCert() { 2963 synchronized (mLock) { 2964 final String methodStr = "getEapClientCert"; 2965 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2966 try { 2967 Mutable<Boolean> statusOk = new Mutable<>(false); 2968 mISupplicantStaNetwork.getEapClientCert((SupplicantStatus status, 2969 String pathValue) -> { 2970 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2971 if (statusOk.value) { 2972 this.mEapClientCert = pathValue; 2973 } else { 2974 checkStatusAndLogFailure(status, methodStr); 2975 } 2976 }); 2977 return statusOk.value; 2978 } catch (RemoteException e) { 2979 handleRemoteException(e, methodStr); 2980 return false; 2981 } 2982 } 2983 } 2984 2985 /** See ISupplicantStaNetwork.hal for documentation */ getEapPrivateKeyId()2986 private boolean getEapPrivateKeyId() { 2987 synchronized (mLock) { 2988 final String methodStr = "getEapPrivateKeyId"; 2989 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 2990 try { 2991 Mutable<Boolean> statusOk = new Mutable<>(false); 2992 mISupplicantStaNetwork.getEapPrivateKeyId((SupplicantStatus status, 2993 String idValue) -> { 2994 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 2995 if (statusOk.value) { 2996 this.mEapPrivateKeyId = idValue; 2997 } else { 2998 checkStatusAndLogFailure(status, methodStr); 2999 } 3000 }); 3001 return statusOk.value; 3002 } catch (RemoteException e) { 3003 handleRemoteException(e, methodStr); 3004 return false; 3005 } 3006 } 3007 } 3008 3009 /** See ISupplicantStaNetwork.hal for documentation */ getEapSubjectMatch()3010 private boolean getEapSubjectMatch() { 3011 synchronized (mLock) { 3012 final String methodStr = "getEapSubjectMatch"; 3013 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 3014 try { 3015 Mutable<Boolean> statusOk = new Mutable<>(false); 3016 mISupplicantStaNetwork.getEapSubjectMatch((SupplicantStatus status, 3017 String matchValue) -> { 3018 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 3019 if (statusOk.value) { 3020 this.mEapSubjectMatch = matchValue; 3021 } else { 3022 checkStatusAndLogFailure(status, methodStr); 3023 } 3024 }); 3025 return statusOk.value; 3026 } catch (RemoteException e) { 3027 handleRemoteException(e, methodStr); 3028 return false; 3029 } 3030 } 3031 } 3032 3033 /** See ISupplicantStaNetwork.hal for documentation */ getEapAltSubjectMatch()3034 private boolean getEapAltSubjectMatch() { 3035 synchronized (mLock) { 3036 final String methodStr = "getEapAltSubjectMatch"; 3037 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 3038 try { 3039 Mutable<Boolean> statusOk = new Mutable<>(false); 3040 mISupplicantStaNetwork.getEapAltSubjectMatch((SupplicantStatus status, 3041 String matchValue) -> { 3042 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 3043 if (statusOk.value) { 3044 this.mEapAltSubjectMatch = matchValue; 3045 } else { 3046 checkStatusAndLogFailure(status, methodStr); 3047 } 3048 }); 3049 return statusOk.value; 3050 } catch (RemoteException e) { 3051 handleRemoteException(e, methodStr); 3052 return false; 3053 } 3054 } 3055 } 3056 3057 /** See ISupplicantStaNetwork.hal for documentation */ getEapEngine()3058 private boolean getEapEngine() { 3059 synchronized (mLock) { 3060 final String methodStr = "getEapEngine"; 3061 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 3062 try { 3063 Mutable<Boolean> statusOk = new Mutable<>(false); 3064 mISupplicantStaNetwork.getEapEngine((SupplicantStatus status, 3065 boolean enabledValue) -> { 3066 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 3067 if (statusOk.value) { 3068 this.mEapEngine = enabledValue; 3069 } else { 3070 checkStatusAndLogFailure(status, methodStr); 3071 } 3072 }); 3073 return statusOk.value; 3074 } catch (RemoteException e) { 3075 handleRemoteException(e, methodStr); 3076 return false; 3077 } 3078 } 3079 } 3080 3081 /** See ISupplicantStaNetwork.hal for documentation */ getEapEngineID()3082 private boolean getEapEngineID() { 3083 synchronized (mLock) { 3084 final String methodStr = "getEapEngineID"; 3085 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 3086 try { 3087 Mutable<Boolean> statusOk = new Mutable<>(false); 3088 mISupplicantStaNetwork.getEapEngineID((SupplicantStatus status, String idValue) -> { 3089 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 3090 if (statusOk.value) { 3091 this.mEapEngineID = idValue; 3092 } else { 3093 checkStatusAndLogFailure(status, methodStr); 3094 } 3095 }); 3096 return statusOk.value; 3097 } catch (RemoteException e) { 3098 handleRemoteException(e, methodStr); 3099 return false; 3100 } 3101 } 3102 } 3103 3104 /** See ISupplicantStaNetwork.hal for documentation */ getEapDomainSuffixMatch()3105 private boolean getEapDomainSuffixMatch() { 3106 synchronized (mLock) { 3107 final String methodStr = "getEapDomainSuffixMatch"; 3108 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 3109 try { 3110 Mutable<Boolean> statusOk = new Mutable<>(false); 3111 mISupplicantStaNetwork.getEapDomainSuffixMatch((SupplicantStatus status, 3112 String matchValue) -> { 3113 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 3114 if (statusOk.value) { 3115 this.mEapDomainSuffixMatch = matchValue; 3116 } else { 3117 checkStatusAndLogFailure(status, methodStr); 3118 } 3119 }); 3120 return statusOk.value; 3121 } catch (RemoteException e) { 3122 handleRemoteException(e, methodStr); 3123 return false; 3124 } 3125 } 3126 } 3127 3128 /** See ISupplicantStaNetwork.hal for documentation */ getIdStr()3129 private boolean getIdStr() { 3130 synchronized (mLock) { 3131 final String methodStr = "getIdStr"; 3132 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 3133 try { 3134 Mutable<Boolean> statusOk = new Mutable<>(false); 3135 mISupplicantStaNetwork.getIdStr((SupplicantStatus status, String idString) -> { 3136 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 3137 if (statusOk.value) { 3138 this.mIdStr = idString; 3139 } else { 3140 checkStatusAndLogFailure(status, methodStr); 3141 } 3142 }); 3143 return statusOk.value; 3144 } catch (RemoteException e) { 3145 handleRemoteException(e, methodStr); 3146 return false; 3147 } 3148 } 3149 } 3150 3151 /** See ISupplicantStaNetwork.hal for documentation */ enable(boolean noConnect)3152 public boolean enable(boolean noConnect) { 3153 synchronized (mLock) { 3154 final String methodStr = "enable"; 3155 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 3156 try { 3157 SupplicantStatus status = mISupplicantStaNetwork.enable(noConnect); 3158 return checkStatusAndLogFailure(status, methodStr); 3159 } catch (RemoteException e) { 3160 handleRemoteException(e, methodStr); 3161 return false; 3162 } 3163 } 3164 } 3165 3166 /** See ISupplicantStaNetwork.hal for documentation */ disable()3167 public boolean disable() { 3168 synchronized (mLock) { 3169 final String methodStr = "disable"; 3170 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 3171 try { 3172 SupplicantStatus status = mISupplicantStaNetwork.disable(); 3173 return checkStatusAndLogFailure(status, methodStr); 3174 } catch (RemoteException e) { 3175 handleRemoteException(e, methodStr); 3176 return false; 3177 } 3178 } 3179 } 3180 3181 /** 3182 * Trigger a connection to this network. 3183 * 3184 * @return true if it succeeds, false otherwise. 3185 */ select()3186 public boolean select() { 3187 synchronized (mLock) { 3188 final String methodStr = "select"; 3189 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 3190 try { 3191 SupplicantStatus status = mISupplicantStaNetwork.select(); 3192 return checkStatusAndLogFailure(status, methodStr); 3193 } catch (RemoteException e) { 3194 handleRemoteException(e, methodStr); 3195 return false; 3196 } 3197 } 3198 } 3199 3200 /** 3201 * Send GSM auth response. 3202 * 3203 * @param paramsStr Response params as a string. 3204 * @return true if succeeds, false otherwise. 3205 */ sendNetworkEapSimGsmAuthResponse(String paramsStr)3206 public boolean sendNetworkEapSimGsmAuthResponse(String paramsStr) { 3207 synchronized (mLock) { 3208 try { 3209 Matcher match = GSM_AUTH_RESPONSE_PARAMS_PATTERN.matcher(paramsStr); 3210 ArrayList<ISupplicantStaNetwork.NetworkResponseEapSimGsmAuthParams> params = 3211 new ArrayList<>(); 3212 while (match.find()) { 3213 if (match.groupCount() != 2) { 3214 Log.e(TAG, "Malformed gsm auth response params: " + paramsStr); 3215 return false; 3216 } 3217 ISupplicantStaNetwork.NetworkResponseEapSimGsmAuthParams param = 3218 new ISupplicantStaNetwork.NetworkResponseEapSimGsmAuthParams(); 3219 byte[] kc = NativeUtil.hexStringToByteArray(match.group(1)); 3220 if (kc == null || kc.length != param.kc.length) { 3221 Log.e(TAG, "Invalid kc value: " + match.group(1)); 3222 return false; 3223 } 3224 byte[] sres = NativeUtil.hexStringToByteArray(match.group(2)); 3225 if (sres == null || sres.length != param.sres.length) { 3226 Log.e(TAG, "Invalid sres value: " + match.group(2)); 3227 return false; 3228 } 3229 System.arraycopy(kc, 0, param.kc, 0, param.kc.length); 3230 System.arraycopy(sres, 0, param.sres, 0, param.sres.length); 3231 params.add(param); 3232 } 3233 // The number of kc/sres pairs can either be 2 or 3 depending on the request. 3234 if (params.size() > 3 || params.size() < 2) { 3235 Log.e(TAG, "Malformed gsm auth response params: " + paramsStr); 3236 return false; 3237 } 3238 return sendNetworkEapSimGsmAuthResponse(params); 3239 } catch (IllegalArgumentException e) { 3240 Log.e(TAG, "Illegal argument " + paramsStr, e); 3241 return false; 3242 } 3243 } 3244 } 3245 3246 /** See ISupplicantStaNetwork.hal for documentation */ sendNetworkEapSimGsmAuthResponse( ArrayList<ISupplicantStaNetwork.NetworkResponseEapSimGsmAuthParams> params)3247 private boolean sendNetworkEapSimGsmAuthResponse( 3248 ArrayList<ISupplicantStaNetwork.NetworkResponseEapSimGsmAuthParams> params) { 3249 synchronized (mLock) { 3250 final String methodStr = "sendNetworkEapSimGsmAuthResponse"; 3251 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 3252 try { 3253 SupplicantStatus status = 3254 mISupplicantStaNetwork.sendNetworkEapSimGsmAuthResponse(params); 3255 return checkStatusAndLogFailure(status, methodStr); 3256 } catch (RemoteException e) { 3257 handleRemoteException(e, methodStr); 3258 return false; 3259 } 3260 } 3261 } 3262 3263 /** See ISupplicantStaNetwork.hal for documentation */ sendNetworkEapSimGsmAuthFailure()3264 public boolean sendNetworkEapSimGsmAuthFailure() { 3265 synchronized (mLock) { 3266 final String methodStr = "sendNetworkEapSimGsmAuthFailure"; 3267 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 3268 try { 3269 SupplicantStatus status = mISupplicantStaNetwork.sendNetworkEapSimGsmAuthFailure(); 3270 return checkStatusAndLogFailure(status, methodStr); 3271 } catch (RemoteException e) { 3272 handleRemoteException(e, methodStr); 3273 return false; 3274 } 3275 } 3276 } 3277 3278 /** 3279 * Send UMTS auth response. 3280 * 3281 * @param paramsStr Response params as a string. 3282 * @return true if succeeds, false otherwise. 3283 */ sendNetworkEapSimUmtsAuthResponse(String paramsStr)3284 public boolean sendNetworkEapSimUmtsAuthResponse(String paramsStr) { 3285 synchronized (mLock) { 3286 try { 3287 Matcher match = UMTS_AUTH_RESPONSE_PARAMS_PATTERN.matcher(paramsStr); 3288 if (!match.find() || match.groupCount() != 3) { 3289 Log.e(TAG, "Malformed umts auth response params: " + paramsStr); 3290 return false; 3291 } 3292 ISupplicantStaNetwork.NetworkResponseEapSimUmtsAuthParams params = 3293 new ISupplicantStaNetwork.NetworkResponseEapSimUmtsAuthParams(); 3294 byte[] ik = NativeUtil.hexStringToByteArray(match.group(1)); 3295 if (ik == null || ik.length != params.ik.length) { 3296 Log.e(TAG, "Invalid ik value: " + match.group(1)); 3297 return false; 3298 } 3299 byte[] ck = NativeUtil.hexStringToByteArray(match.group(2)); 3300 if (ck == null || ck.length != params.ck.length) { 3301 Log.e(TAG, "Invalid ck value: " + match.group(2)); 3302 return false; 3303 } 3304 byte[] res = NativeUtil.hexStringToByteArray(match.group(3)); 3305 if (res == null || res.length == 0) { 3306 Log.e(TAG, "Invalid res value: " + match.group(3)); 3307 return false; 3308 } 3309 System.arraycopy(ik, 0, params.ik, 0, params.ik.length); 3310 System.arraycopy(ck, 0, params.ck, 0, params.ck.length); 3311 for (byte b : res) { 3312 params.res.add(b); 3313 } 3314 return sendNetworkEapSimUmtsAuthResponse(params); 3315 } catch (IllegalArgumentException e) { 3316 Log.e(TAG, "Illegal argument " + paramsStr, e); 3317 return false; 3318 } 3319 } 3320 } 3321 3322 /** See ISupplicantStaNetwork.hal for documentation */ sendNetworkEapSimUmtsAuthResponse( ISupplicantStaNetwork.NetworkResponseEapSimUmtsAuthParams params)3323 private boolean sendNetworkEapSimUmtsAuthResponse( 3324 ISupplicantStaNetwork.NetworkResponseEapSimUmtsAuthParams params) { 3325 synchronized (mLock) { 3326 final String methodStr = "sendNetworkEapSimUmtsAuthResponse"; 3327 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 3328 try { 3329 SupplicantStatus status = 3330 mISupplicantStaNetwork.sendNetworkEapSimUmtsAuthResponse(params); 3331 return checkStatusAndLogFailure(status, methodStr); 3332 } catch (RemoteException e) { 3333 handleRemoteException(e, methodStr); 3334 return false; 3335 } 3336 } 3337 } 3338 3339 /** 3340 * Send UMTS auts response. 3341 * 3342 * @param paramsStr Response params as a string. 3343 * @return true if succeeds, false otherwise. 3344 */ sendNetworkEapSimUmtsAutsResponse(String paramsStr)3345 public boolean sendNetworkEapSimUmtsAutsResponse(String paramsStr) { 3346 synchronized (mLock) { 3347 try { 3348 Matcher match = UMTS_AUTS_RESPONSE_PARAMS_PATTERN.matcher(paramsStr); 3349 if (!match.find() || match.groupCount() != 1) { 3350 Log.e(TAG, "Malformed umts auts response params: " + paramsStr); 3351 return false; 3352 } 3353 byte[] auts = NativeUtil.hexStringToByteArray(match.group(1)); 3354 if (auts == null || auts.length != 14) { 3355 Log.e(TAG, "Invalid auts value: " + match.group(1)); 3356 return false; 3357 } 3358 return sendNetworkEapSimUmtsAutsResponse(auts); 3359 } catch (IllegalArgumentException e) { 3360 Log.e(TAG, "Illegal argument " + paramsStr, e); 3361 return false; 3362 } 3363 } 3364 } 3365 3366 /** See ISupplicantStaNetwork.hal for documentation */ sendNetworkEapSimUmtsAutsResponse(byte[ ] auts)3367 private boolean sendNetworkEapSimUmtsAutsResponse(byte[/* 14 */] auts) { 3368 synchronized (mLock) { 3369 final String methodStr = "sendNetworkEapSimUmtsAutsResponse"; 3370 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 3371 try { 3372 SupplicantStatus status = 3373 mISupplicantStaNetwork.sendNetworkEapSimUmtsAutsResponse(auts); 3374 return checkStatusAndLogFailure(status, methodStr); 3375 } catch (RemoteException e) { 3376 handleRemoteException(e, methodStr); 3377 return false; 3378 } 3379 } 3380 } 3381 3382 /** See ISupplicantStaNetwork.hal for documentation */ sendNetworkEapSimUmtsAuthFailure()3383 public boolean sendNetworkEapSimUmtsAuthFailure() { 3384 synchronized (mLock) { 3385 final String methodStr = "sendNetworkEapSimUmtsAuthFailure"; 3386 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 3387 try { 3388 SupplicantStatus status = mISupplicantStaNetwork.sendNetworkEapSimUmtsAuthFailure(); 3389 return checkStatusAndLogFailure(status, methodStr); 3390 } catch (RemoteException e) { 3391 handleRemoteException(e, methodStr); 3392 return false; 3393 } 3394 } 3395 } 3396 3397 /** 3398 * Method to mock out the V1_1 ISupplicantStaNetwork retrieval in unit tests. 3399 * 3400 * @return 1.1 ISupplicantStaNetwork object if the device is running the 1.1 supplicant hal 3401 * service, null otherwise. 3402 */ 3403 protected android.hardware.wifi.supplicant.V1_1.ISupplicantStaNetwork getSupplicantStaNetworkForV1_1Mockable()3404 getSupplicantStaNetworkForV1_1Mockable() { 3405 if (mISupplicantStaNetwork == null) return null; 3406 return android.hardware.wifi.supplicant.V1_1.ISupplicantStaNetwork.castFrom( 3407 mISupplicantStaNetwork); 3408 } 3409 3410 /** 3411 * Method to mock out the V1_2 ISupplicantStaNetwork retrieval in unit tests. 3412 * 3413 * @return 1.2 ISupplicantStaNetwork object if the device is running the 1.2 supplicant hal 3414 * service, null otherwise. 3415 */ 3416 protected android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork getSupplicantStaNetworkForV1_2Mockable()3417 getSupplicantStaNetworkForV1_2Mockable() { 3418 if (mISupplicantStaNetwork == null) return null; 3419 return android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork.castFrom( 3420 mISupplicantStaNetwork); 3421 } 3422 3423 /** 3424 * Method to mock out the V1_3 ISupplicantStaNetwork retrieval in unit tests. 3425 * 3426 * @return 1.3 ISupplicantStaNetwork object if the device is running the 1.3 supplicant hal 3427 * service, null otherwise. 3428 */ 3429 protected android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork getSupplicantStaNetworkForV1_3Mockable()3430 getSupplicantStaNetworkForV1_3Mockable() { 3431 if (mISupplicantStaNetwork == null) return null; 3432 return android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork.castFrom( 3433 mISupplicantStaNetwork); 3434 } 3435 3436 /** 3437 * Method to mock out the V1_4 ISupplicantStaNetwork retrieval in unit tests. 3438 * 3439 * @return 1.4 ISupplicantStaNetwork object if the device is running the 1.4 supplicant hal 3440 * service, null otherwise. 3441 */ 3442 protected android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetwork getSupplicantStaNetworkForV1_4Mockable()3443 getSupplicantStaNetworkForV1_4Mockable() { 3444 if (mISupplicantStaNetwork == null) return null; 3445 return android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetwork.castFrom( 3446 mISupplicantStaNetwork); 3447 } 3448 3449 /** 3450 * Send eap identity response. 3451 * 3452 * @param identityStr identity used for EAP-Identity 3453 * @param encryptedIdentityStr encrypted identity used for EAP-AKA/EAP-SIM 3454 * @return true if succeeds, false otherwise. 3455 */ sendNetworkEapIdentityResponse(String identityStr, String encryptedIdentityStr)3456 public boolean sendNetworkEapIdentityResponse(String identityStr, 3457 String encryptedIdentityStr) { 3458 synchronized (mLock) { 3459 try { 3460 ArrayList<Byte> unencryptedIdentity = 3461 NativeUtil.stringToByteArrayList(identityStr); 3462 ArrayList<Byte> encryptedIdentity = null; 3463 if (!TextUtils.isEmpty(encryptedIdentityStr)) { 3464 encryptedIdentity = NativeUtil.stringToByteArrayList(encryptedIdentityStr); 3465 } 3466 return sendNetworkEapIdentityResponse(unencryptedIdentity, encryptedIdentity); 3467 } catch (IllegalArgumentException e) { 3468 Log.e(TAG, "Illegal argument " + identityStr + "," + encryptedIdentityStr, e); 3469 return false; 3470 } 3471 } 3472 } 3473 3474 /** See ISupplicantStaNetwork.hal for documentation */ sendNetworkEapIdentityResponse(ArrayList<Byte> unencryptedIdentity, ArrayList<Byte> encryptedIdentity)3475 private boolean sendNetworkEapIdentityResponse(ArrayList<Byte> unencryptedIdentity, 3476 ArrayList<Byte> encryptedIdentity) { 3477 synchronized (mLock) { 3478 final String methodStr = "sendNetworkEapIdentityResponse"; 3479 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 3480 try { 3481 SupplicantStatus status; 3482 android.hardware.wifi.supplicant.V1_1.ISupplicantStaNetwork 3483 iSupplicantStaNetworkV11 = 3484 getSupplicantStaNetworkForV1_1Mockable(); 3485 3486 if (iSupplicantStaNetworkV11 != null && encryptedIdentity != null) { 3487 status = iSupplicantStaNetworkV11.sendNetworkEapIdentityResponse_1_1( 3488 unencryptedIdentity, encryptedIdentity); 3489 } else { 3490 status = mISupplicantStaNetwork.sendNetworkEapIdentityResponse( 3491 unencryptedIdentity); 3492 } 3493 3494 return checkStatusAndLogFailure(status, methodStr); 3495 } catch (RemoteException e) { 3496 handleRemoteException(e, methodStr); 3497 return false; 3498 } 3499 } 3500 } 3501 3502 /** See ISupplicantStaNetwork.hal for documentation */ setOcsp(@csp int ocsp)3503 private boolean setOcsp(@Ocsp int ocsp) { 3504 synchronized (mLock) { 3505 final String methodStr = "setOcsp"; 3506 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 3507 3508 int halOcspValue = android.hardware.wifi.supplicant.V1_3.OcspType.NONE; 3509 switch (ocsp) { 3510 case WifiEnterpriseConfig.OCSP_REQUEST_CERT_STATUS: 3511 halOcspValue = android.hardware.wifi.supplicant.V1_3 3512 .OcspType.REQUEST_CERT_STATUS; 3513 break; 3514 case WifiEnterpriseConfig.OCSP_REQUIRE_CERT_STATUS: 3515 halOcspValue = android.hardware.wifi.supplicant.V1_3 3516 .OcspType.REQUIRE_CERT_STATUS; 3517 break; 3518 case WifiEnterpriseConfig.OCSP_REQUIRE_ALL_NON_TRUSTED_CERTS_STATUS: 3519 halOcspValue = android.hardware.wifi.supplicant.V1_3 3520 .OcspType.REQUIRE_ALL_CERTS_STATUS; 3521 break; 3522 } 3523 try { 3524 android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 3525 iSupplicantStaNetworkV13; 3526 3527 iSupplicantStaNetworkV13 = getV1_3StaNetwork(); 3528 if (iSupplicantStaNetworkV13 != null) { 3529 /* Support for OCSP Requires HAL v1.3 or higher */ 3530 SupplicantStatus status = iSupplicantStaNetworkV13 3531 .setOcsp(halOcspValue); 3532 return checkStatusAndLogFailure(status, methodStr); 3533 } else { 3534 Log.e(TAG, "Cannot get ISupplicantStaNetwork V1.3"); 3535 return false; 3536 } 3537 } catch (RemoteException e) { 3538 handleRemoteException(e, methodStr); 3539 return false; 3540 } 3541 } 3542 } 3543 3544 /** See ISupplicantStaNetwork.hal for documentation */ getOcsp()3545 private boolean getOcsp() { 3546 synchronized (mLock) { 3547 final String methodStr = "getOcsp"; 3548 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 3549 3550 try { 3551 android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 3552 iSupplicantStaNetworkV13; 3553 iSupplicantStaNetworkV13 = getV1_3StaNetwork(); 3554 if (iSupplicantStaNetworkV13 != null) { 3555 Mutable<Boolean> statusOk = new Mutable<>(false); 3556 iSupplicantStaNetworkV13.getOcsp((SupplicantStatus status, 3557 int halOcspValue) -> { 3558 statusOk.value = status.code == SupplicantStatusCode.SUCCESS; 3559 if (statusOk.value) { 3560 mOcsp = WifiEnterpriseConfig.OCSP_NONE; 3561 switch (halOcspValue) { 3562 case android.hardware.wifi.supplicant.V1_3 3563 .OcspType.REQUEST_CERT_STATUS: 3564 mOcsp = WifiEnterpriseConfig.OCSP_REQUEST_CERT_STATUS; 3565 break; 3566 case android.hardware.wifi.supplicant.V1_3 3567 .OcspType.REQUIRE_CERT_STATUS: 3568 mOcsp = WifiEnterpriseConfig.OCSP_REQUIRE_CERT_STATUS; 3569 break; 3570 case android.hardware.wifi.supplicant.V1_3 3571 .OcspType.REQUIRE_ALL_CERTS_STATUS: 3572 mOcsp = WifiEnterpriseConfig 3573 .OCSP_REQUIRE_ALL_NON_TRUSTED_CERTS_STATUS; 3574 break; 3575 default: 3576 Log.e(TAG, "Invalid HAL OCSP value " + halOcspValue); 3577 break; 3578 } 3579 } else { 3580 checkStatusAndLogFailure(status, methodStr); 3581 } 3582 }); 3583 return statusOk.value; 3584 } else { 3585 Log.e(TAG, "Cannot get ISupplicantStaNetwork V1.3"); 3586 return false; 3587 } 3588 } catch (RemoteException e) { 3589 handleRemoteException(e, methodStr); 3590 return false; 3591 } 3592 } 3593 } 3594 3595 /** See ISupplicantStaNetwork.hal for documentation */ setPmkCache(ArrayList<Byte> serializedEntry)3596 public boolean setPmkCache(ArrayList<Byte> serializedEntry) { 3597 synchronized (mLock) { 3598 final String methodStr = "setPmkCache"; 3599 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 3600 3601 try { 3602 android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 3603 iSupplicantStaNetworkV13; 3604 3605 iSupplicantStaNetworkV13 = getV1_3StaNetwork(); 3606 if (iSupplicantStaNetworkV13 != null) { 3607 SupplicantStatus status = iSupplicantStaNetworkV13 3608 .setPmkCache(serializedEntry); 3609 return checkStatusAndLogFailure(status, methodStr); 3610 } else { 3611 Log.e(TAG, "Cannot get ISupplicantStaNetwork V1.3"); 3612 return false; 3613 } 3614 } catch (RemoteException e) { 3615 handleRemoteException(e, methodStr); 3616 return false; 3617 } 3618 } 3619 } 3620 3621 /** See ISupplicantStaNetwork.hal for documentation */ setSaeH2eMode(byte mode)3622 private boolean setSaeH2eMode(byte mode) { 3623 synchronized (mLock) { 3624 final String methodStr = "setSaeH2eMode"; 3625 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false; 3626 3627 try { 3628 android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetwork 3629 iSupplicantStaNetworkV14 = getV1_4StaNetwork(); 3630 if (iSupplicantStaNetworkV14 != null) { 3631 android.hardware.wifi.supplicant.V1_4.SupplicantStatus status = 3632 iSupplicantStaNetworkV14.setSaeH2eMode(mode); 3633 return checkStatusAndLogFailure(status, methodStr); 3634 } else { 3635 Log.e(TAG, "Cannot get ISupplicantStaNetwork V1.4"); 3636 return false; 3637 } 3638 } catch (RemoteException e) { 3639 handleRemoteException(e, methodStr); 3640 return false; 3641 } 3642 } 3643 } 3644 3645 /** 3646 * Retrieve the NFC token for this network. 3647 * 3648 * @return Hex string corresponding to the NFC token or null for failure. 3649 */ getWpsNfcConfigurationToken()3650 public String getWpsNfcConfigurationToken() { 3651 synchronized (mLock) { 3652 ArrayList<Byte> token = getWpsNfcConfigurationTokenInternal(); 3653 if (token == null) { 3654 return null; 3655 } 3656 return NativeUtil.hexStringFromByteArray(NativeUtil.byteArrayFromArrayList(token)); 3657 } 3658 } 3659 3660 /** See ISupplicantStaNetwork.hal for documentation */ getWpsNfcConfigurationTokenInternal()3661 private ArrayList<Byte> getWpsNfcConfigurationTokenInternal() { 3662 synchronized (mLock) { 3663 final String methodStr = "getWpsNfcConfigurationToken"; 3664 if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return null; 3665 final Mutable<ArrayList<Byte>> gotToken = new Mutable<>(); 3666 try { 3667 mISupplicantStaNetwork.getWpsNfcConfigurationToken( 3668 (SupplicantStatus status, ArrayList<Byte> token) -> { 3669 if (checkStatusAndLogFailure(status, methodStr)) { 3670 gotToken.value = token; 3671 } 3672 }); 3673 } catch (RemoteException e) { 3674 handleRemoteException(e, methodStr); 3675 } 3676 return gotToken.value; 3677 } 3678 } 3679 getTag()3680 private String getTag() { 3681 return TAG + "[" + mIfaceName + "]"; 3682 } 3683 3684 /** 3685 * Returns true if provided status code is SUCCESS, logs debug message and returns false 3686 * otherwise 3687 */ checkStatusAndLogFailure(SupplicantStatus status, final String methodStr)3688 private boolean checkStatusAndLogFailure(SupplicantStatus status, final String methodStr) { 3689 synchronized (mLock) { 3690 if (status.code != SupplicantStatusCode.SUCCESS) { 3691 Log.e(getTag(), "ISupplicantStaNetwork." + methodStr + " failed: " + status); 3692 return false; 3693 } else { 3694 if (mVerboseLoggingEnabled) { 3695 Log.d(getTag(), "ISupplicantStaNetwork." + methodStr + " succeeded"); 3696 } 3697 return true; 3698 } 3699 } 3700 } 3701 3702 /** 3703 * Returns true if provided status code is SUCCESS, logs debug message and returns false 3704 * otherwise 3705 */ checkStatusAndLogFailure( android.hardware.wifi.supplicant.V1_4.SupplicantStatus status, final String methodStr)3706 private boolean checkStatusAndLogFailure( 3707 android.hardware.wifi.supplicant.V1_4.SupplicantStatus status, 3708 final String methodStr) { 3709 synchronized (mLock) { 3710 if (status.code 3711 != android.hardware.wifi.supplicant.V1_4.SupplicantStatusCode.SUCCESS) { 3712 Log.e(TAG, "ISupplicantStaNetwork." + methodStr + " failed: " + status); 3713 return false; 3714 } else { 3715 if (mVerboseLoggingEnabled) { 3716 Log.d(TAG, "ISupplicantStaNetwork." + methodStr + " succeeded"); 3717 } 3718 return true; 3719 } 3720 } 3721 } 3722 3723 /** 3724 * Helper function to log callbacks. 3725 */ logCallback(final String methodStr)3726 protected void logCallback(final String methodStr) { 3727 synchronized (mLock) { 3728 if (mVerboseLoggingEnabled) { 3729 Log.d(TAG, "ISupplicantStaNetworkCallback." + methodStr + " received"); 3730 } 3731 } 3732 } 3733 3734 /** 3735 * Returns false if ISupplicantStaNetwork is null, and logs failure of methodStr 3736 */ checkISupplicantStaNetworkAndLogFailure(final String methodStr)3737 private boolean checkISupplicantStaNetworkAndLogFailure(final String methodStr) { 3738 synchronized (mLock) { 3739 if (mISupplicantStaNetwork == null) { 3740 Log.e(TAG, "Can't call " + methodStr + ", ISupplicantStaNetwork is null"); 3741 return false; 3742 } 3743 return true; 3744 } 3745 } 3746 handleRemoteException(RemoteException e, String methodStr)3747 private void handleRemoteException(RemoteException e, String methodStr) { 3748 synchronized (mLock) { 3749 mISupplicantStaNetwork = null; 3750 Log.e(TAG, "ISupplicantStaNetwork." + methodStr + " failed with exception", e); 3751 } 3752 } 3753 3754 /** 3755 * Adds FT flags for networks if the device supports it. 3756 */ addFastTransitionFlags(BitSet keyManagementFlags)3757 private BitSet addFastTransitionFlags(BitSet keyManagementFlags) { 3758 synchronized (mLock) { 3759 if (!mContext.getResources().getBoolean( 3760 R.bool.config_wifi_fast_bss_transition_enabled)) { 3761 return keyManagementFlags; 3762 } 3763 BitSet modifiedFlags = (BitSet) keyManagementFlags.clone(); 3764 if (keyManagementFlags.get(WifiConfiguration.KeyMgmt.WPA_PSK)) { 3765 modifiedFlags.set(WifiConfiguration.KeyMgmt.FT_PSK); 3766 } 3767 if (keyManagementFlags.get(WifiConfiguration.KeyMgmt.WPA_EAP)) { 3768 modifiedFlags.set(WifiConfiguration.KeyMgmt.FT_EAP); 3769 } 3770 return modifiedFlags; 3771 } 3772 } 3773 3774 /** 3775 * Removes FT flags for networks if the device supports it. 3776 */ removeFastTransitionFlags(BitSet keyManagementFlags)3777 private BitSet removeFastTransitionFlags(BitSet keyManagementFlags) { 3778 synchronized (mLock) { 3779 BitSet modifiedFlags = (BitSet) keyManagementFlags.clone(); 3780 modifiedFlags.clear(WifiConfiguration.KeyMgmt.FT_PSK); 3781 modifiedFlags.clear(WifiConfiguration.KeyMgmt.FT_EAP); 3782 return modifiedFlags; 3783 } 3784 } 3785 3786 /** 3787 * Adds SHA256 key management flags for networks. 3788 */ addSha256KeyMgmtFlags(BitSet keyManagementFlags)3789 private BitSet addSha256KeyMgmtFlags(BitSet keyManagementFlags) { 3790 synchronized (mLock) { 3791 BitSet modifiedFlags = (BitSet) keyManagementFlags.clone(); 3792 android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 3793 iSupplicantStaNetworkV12; 3794 iSupplicantStaNetworkV12 = getV1_2StaNetwork(); 3795 if (iSupplicantStaNetworkV12 == null) { 3796 // SHA256 key management requires HALv1.2 or higher 3797 return modifiedFlags; 3798 } 3799 3800 if (keyManagementFlags.get(WifiConfiguration.KeyMgmt.WPA_PSK)) { 3801 modifiedFlags.set(WifiConfiguration.KeyMgmt.WPA_PSK_SHA256); 3802 } 3803 if (keyManagementFlags.get(WifiConfiguration.KeyMgmt.WPA_EAP)) { 3804 modifiedFlags.set(WifiConfiguration.KeyMgmt.WPA_EAP_SHA256); 3805 } 3806 return modifiedFlags; 3807 } 3808 } 3809 3810 /** 3811 * Removes SHA256 key management flags for networks. 3812 */ removeSha256KeyMgmtFlags(BitSet keyManagementFlags)3813 private BitSet removeSha256KeyMgmtFlags(BitSet keyManagementFlags) { 3814 synchronized (mLock) { 3815 BitSet modifiedFlags = (BitSet) keyManagementFlags.clone(); 3816 modifiedFlags.clear(WifiConfiguration.KeyMgmt.WPA_PSK_SHA256); 3817 modifiedFlags.clear(WifiConfiguration.KeyMgmt.WPA_EAP_SHA256); 3818 return modifiedFlags; 3819 } 3820 } 3821 3822 /** 3823 * Adds both PSK and SAE AKM if auto-upgrade offload is supported. 3824 */ addPskSaeUpgradableTypeFlagsIfSupported( WifiConfiguration config, BitSet keyManagementFlags)3825 private BitSet addPskSaeUpgradableTypeFlagsIfSupported( 3826 WifiConfiguration config, 3827 BitSet keyManagementFlags) { 3828 synchronized (mLock) { 3829 if (!config.isSecurityType(WifiConfiguration.SECURITY_TYPE_PSK) 3830 || !config.getSecurityParams(WifiConfiguration.SECURITY_TYPE_PSK).isEnabled() 3831 || !mWifiGlobals.isWpa3SaeUpgradeOffloadEnabled()) { 3832 return keyManagementFlags; 3833 } 3834 3835 BitSet modifiedFlags = (BitSet) keyManagementFlags.clone(); 3836 modifiedFlags.set(WifiConfiguration.KeyMgmt.WPA_PSK); 3837 modifiedFlags.set(WifiConfiguration.KeyMgmt.SAE); 3838 return modifiedFlags; 3839 } 3840 } 3841 3842 /** 3843 * Removes SAE AKM when PSK and SAE AKM are both set, it only happens when 3844 * auto-upgrade offload is supported. 3845 */ removePskSaeUpgradableTypeFlags(BitSet keyManagementFlags)3846 private BitSet removePskSaeUpgradableTypeFlags(BitSet keyManagementFlags) { 3847 if (!keyManagementFlags.get(WifiConfiguration.KeyMgmt.WPA_PSK) 3848 || !keyManagementFlags.get(WifiConfiguration.KeyMgmt.SAE)) { 3849 return keyManagementFlags; 3850 } 3851 BitSet modifiedFlags = (BitSet) keyManagementFlags.clone(); 3852 modifiedFlags.clear(WifiConfiguration.KeyMgmt.SAE); 3853 return modifiedFlags; 3854 } 3855 3856 /** 3857 * Creates the JSON encoded network extra using the map of string key, value pairs. 3858 */ createNetworkExtra(Map<String, String> values)3859 public static String createNetworkExtra(Map<String, String> values) { 3860 final String encoded; 3861 try { 3862 encoded = URLEncoder.encode(new JSONObject(values).toString(), "UTF-8"); 3863 } catch (NullPointerException e) { 3864 Log.e(TAG, "Unable to serialize networkExtra: " + e.toString()); 3865 return null; 3866 } catch (UnsupportedEncodingException e) { 3867 Log.e(TAG, "Unable to serialize networkExtra: " + e.toString()); 3868 return null; 3869 } 3870 return encoded; 3871 } 3872 3873 /** 3874 * Parse the network extra JSON encoded string to a map of string key, value pairs. 3875 */ parseNetworkExtra(String encoded)3876 public static Map<String, String> parseNetworkExtra(String encoded) { 3877 if (TextUtils.isEmpty(encoded)) { 3878 return null; 3879 } 3880 try { 3881 // This method reads a JSON dictionary that was written by setNetworkExtra(). However, 3882 // on devices that upgraded from Marshmallow, it may encounter a legacy value instead - 3883 // an FQDN stored as a plain string. If such a value is encountered, the JSONObject 3884 // constructor will thrown a JSONException and the method will return null. 3885 final JSONObject json = new JSONObject(URLDecoder.decode(encoded, "UTF-8")); 3886 final Map<String, String> values = new HashMap<>(); 3887 final Iterator<?> it = json.keys(); 3888 while (it.hasNext()) { 3889 final String key = (String) it.next(); 3890 final Object value = json.get(key); 3891 if (value instanceof String) { 3892 values.put(key, (String) value); 3893 } 3894 } 3895 return values; 3896 } catch (UnsupportedEncodingException e) { 3897 Log.e(TAG, "Unable to deserialize networkExtra: " + e.toString()); 3898 return null; 3899 } catch (JSONException e) { 3900 // This is not necessarily an error. This exception will also occur if we encounter a 3901 // legacy FQDN stored as a plain string. We want to return null in this case as no JSON 3902 // dictionary of extras was found. 3903 return null; 3904 } 3905 } 3906 3907 protected class SupplicantStaNetworkHalCallbackV1_4 3908 extends SupplicantStaNetworkCallbackV1_4Impl { SupplicantStaNetworkHalCallbackV1_4(int frameworkNetworkId, String ssid)3909 SupplicantStaNetworkHalCallbackV1_4(int frameworkNetworkId, String ssid) { 3910 super(SupplicantStaNetworkHal.this, 3911 frameworkNetworkId, ssid, 3912 mIfaceName, mLock, mWifiMonitor); 3913 } 3914 } 3915 3916 protected class SupplicantStaNetworkHalCallback extends SupplicantStaNetworkCallbackImpl { SupplicantStaNetworkHalCallback(int frameworkNetworkId, String ssid)3917 SupplicantStaNetworkHalCallback(int frameworkNetworkId, String ssid) { 3918 super(SupplicantStaNetworkHal.this, 3919 frameworkNetworkId, ssid, 3920 mIfaceName, mLock, mWifiMonitor); 3921 } 3922 } 3923 } 3924