diff options
author | Jimmy Chen <jimmycmchen@google.com> | 2020-04-24 08:56:48 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-04-24 08:56:48 +0000 |
commit | 7764185888c880ead19f49c03ab094d7e950b8ce (patch) | |
tree | 277906e4ec9742868c2687f6dad2c0741fe545b1 /service | |
parent | d57dc43d5ec11c2e383cf0bf353a628963f6ae34 (diff) | |
parent | 0ad0249a627c5a0a65dfd1865d762097d90daed2 (diff) |
Merge changes Ia4c555de,I22fe4d31 into rvc-dev am: 4564b7cda1 am: 0ad0249a62
Change-Id: Id79f41096d32e7d2733c8a55a2ea75ea95f08c72
Diffstat (limited to 'service')
4 files changed, 84 insertions, 6 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java index cf8acb4f0..7314bb853 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -2985,6 +2985,31 @@ public class ClientModeImpl extends StateMachine { handleConnectionAttemptEndForDiagnostics(level2FailureCode); } + /* If this connection attempt fails after 802.1x stage, clear intermediate cached data. */ + void clearNetworkCachedDataIfNeeded(WifiConfiguration config, int reason) { + if (config == null) return; + + switch(reason) { + case 14: // MICHAEL_MIC_FAILURE + case 15: // 4WAY_HANDSHAKE_TIMEOUT + case 16: // GROUP_KEY_UPDATE_TIMEOUT + case 17: // IE_IN_4WAY_DIFFERS + case 18: // GROUP_CIPHER_NOT_VALID + case 19: // PAIRWISE_CIPHER_NOT_VALID + case 20: // AKMP_NOT_VALID + case 23: // IEEE_802_1X_AUTH_FAILED + case 24: // CIPHER_SUITE_REJECTED + case 29: // BAD_CIPHER_OR_AKM + case 45: // PEERKEY_MISMATCH + case 49: // INVALID_PMKID + mWifiNative.removeNetworkCachedData(config.networkId); + break; + default: + logi("Keep PMK cache for network disconnection reason " + reason); + break; + } + } + /** * Returns the sufficient RSSI for the frequency that this network is last seen on. */ @@ -3247,6 +3272,9 @@ public class ClientModeImpl extends StateMachine { mWifiMetrics.logStaEvent(StaEvent.TYPE_MAC_CHANGE, config); boolean setMacSuccess = mWifiNative.setMacAddress(mInterfaceName, newMac); + if (setMacSuccess) { + mWifiNative.removeNetworkCachedDataIfNeeded(config.networkId, newMac); + } Log.d(TAG, "ConnectedMacRandomization SSID(" + config.getPrintableSsid() + "). setMacAddress(" + newMac.toString() + ") from " + currentMacString + " = " + setMacSuccess); @@ -3265,6 +3293,7 @@ public class ClientModeImpl extends StateMachine { String currentMacStr = mWifiNative.getMacAddress(mInterfaceName); if (!TextUtils.equals(currentMacStr, factoryMac.toString())) { if (mWifiNative.setMacAddress(mInterfaceName, factoryMac)) { + mWifiNative.removeNetworkCachedDataIfNeeded(config.networkId, factoryMac); mWifiMetrics.logStaEvent(StaEvent.TYPE_MAC_CHANGE, config); } else { Log.e(TAG, "Failed to set MAC address to " + "'" + factoryMac.toString() + "'"); @@ -4213,6 +4242,7 @@ public class ClientModeImpl extends StateMachine { // idempotent commands are executed twice (stopping Dhcp, enabling the SPS mode // at the chip etc... if (mVerboseLoggingEnabled) log("ConnectModeState: Network connection lost "); + clearNetworkCachedDataIfNeeded(getTargetWifiConfiguration(), message.arg2); handleNetworkDisconnect(); transitionTo(mDisconnectedState); break; @@ -5242,6 +5272,7 @@ public class ClientModeImpl extends StateMachine { + " BSSID=" + bssid + " target=" + target); } + clearNetworkCachedDataIfNeeded(getTargetWifiConfiguration(), message.arg2); if (bssid != null && bssid.equals(mTargetBssid)) { handleNetworkDisconnect(); transitionTo(mDisconnectedState); @@ -5397,6 +5428,7 @@ public class ClientModeImpl extends StateMachine { mWifiDiagnostics.captureBugReportData( WifiDiagnostics.REPORT_REASON_UNEXPECTED_DISCONNECT); } + boolean localGen = message.arg1 == 1; if (!localGen) { // ignore disconnects initiated by wpa_supplicant. mWifiScoreCard.noteNonlocalDisconnect(message.arg2); @@ -5600,6 +5632,7 @@ public class ClientModeImpl extends StateMachine { getTargetSsid(), bssid, WifiLastResortWatchdog.FAILURE_CODE_AUTHENTICATION); } + clearNetworkCachedDataIfNeeded(getTargetWifiConfiguration(), message.arg2); break; case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT: StateChangeResult stateChangeResult = (StateChangeResult) message.obj; diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackV1_3Impl.java b/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackV1_3Impl.java index 5af65d0a5..cac84b543 100644 --- a/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackV1_3Impl.java +++ b/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackV1_3Impl.java @@ -199,9 +199,13 @@ abstract class SupplicantStaIfaceCallbackV1_3Impl extends if (WifiConfigurationUtil.isConfigForPskNetwork(curConfig)) return; - mStaIfaceHal.addPmkCacheEntry(curConfig.networkId, expirationTimeInSec, serializedEntry); + mStaIfaceHal.addPmkCacheEntry(mIfaceName, + curConfig.networkId, expirationTimeInSec, serializedEntry); mStaIfaceHal.logCallback( - "onPmkCacheAdded: update pmk cache for config id " + curConfig.networkId); + "onPmkCacheAdded: update pmk cache for config id " + + curConfig.networkId + + " on " + + mIfaceName); } @Override diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java index 4380f6ab4..657b081dd 100644 --- a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java +++ b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java @@ -43,6 +43,7 @@ import android.hardware.wifi.supplicant.V1_3.WifiTechnology; import android.hardware.wifi.supplicant.V1_3.WpaDriverCapabilitiesMask; import android.hidl.manager.V1_0.IServiceManager; import android.hidl.manager.V1_0.IServiceNotification; +import android.net.MacAddress; import android.net.wifi.ScanResult; import android.net.wifi.WifiAnnotations.WifiStandard; import android.net.wifi.WifiConfiguration; @@ -170,10 +171,12 @@ public class SupplicantStaIfaceHal { static class PmkCacheStoreData { public long expirationTimeInSec; public ArrayList<Byte> data; + public MacAddress macAddress; - PmkCacheStoreData(long timeInSec, ArrayList<Byte> serializedData) { + PmkCacheStoreData(long timeInSec, ArrayList<Byte> serializedData, MacAddress macAddress) { expirationTimeInSec = timeInSec; data = serializedData; + this.macAddress = macAddress; } } @@ -1053,6 +1056,24 @@ public class SupplicantStaIfaceHal { } /** + * Clear HAL cached data if MAC address is changed. + * + * @param networkId network id of the network to be checked. + * @param curMacAddress current MAC address + */ + public void removeNetworkCachedDataIfNeeded(int networkId, MacAddress curMacAddress) { + synchronized (mLock) { + PmkCacheStoreData pmkData = mPmkCacheEntries.get(networkId); + + if (pmkData == null) return; + + if (curMacAddress.equals(pmkData.macAddress)) return; + + removeNetworkCachedData(networkId); + } + } + + /** * Remove all networks from supplicant * * @param ifaceName Name of the interface. @@ -2636,10 +2657,21 @@ public class SupplicantStaIfaceHal { } protected void addPmkCacheEntry( + String ifaceName, int networkId, long expirationTimeInSec, ArrayList<Byte> serializedEntry) { - mPmkCacheEntries.put(networkId, - new PmkCacheStoreData(expirationTimeInSec, serializedEntry)); - updatePmkCacheExpiration(); + String macAddressStr = getMacAddress(ifaceName); + if (macAddressStr == null) { + Log.w(TAG, "Omit PMK cache due to no valid MAC address on " + ifaceName); + return; + } + try { + MacAddress macAddress = MacAddress.fromString(macAddressStr); + mPmkCacheEntries.put(networkId, + new PmkCacheStoreData(expirationTimeInSec, serializedEntry, macAddress)); + updatePmkCacheExpiration(); + } catch (IllegalArgumentException ex) { + Log.w(TAG, "Invalid MAC address string " + macAddressStr); + } } protected void removePmkCacheEntry(int networkId) { diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index 08abafa61..d0f2753a5 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -2416,6 +2416,15 @@ public class WifiNative { mSupplicantStaIfaceHal.removeNetworkCachedData(networkId); } + /** Clear HAL cached data for |networkId| if MAC address is changed. + * + * @param networkId network id of the network to be checked. + * @param curMacAddress current MAC address + */ + public void removeNetworkCachedDataIfNeeded(int networkId, MacAddress curMacAddress) { + mSupplicantStaIfaceHal.removeNetworkCachedDataIfNeeded(networkId, curMacAddress); + } + /* * DPP */ |