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