diff options
author | Jimmy Chen <jimmycmchen@google.com> | 2020-04-22 10:18:32 +0800 |
---|---|---|
committer | Jimmy Chen <jimmycmchen@google.com> | 2020-04-24 11:03:15 +0800 |
commit | 88033a33dcead214184dd0c368ba69e0452a39f8 (patch) | |
tree | 9fa35c675155139f85c1765acd902be5bda33800 /service | |
parent | 58110bf7d3067f43784127e0bc125552374dfc99 (diff) |
Wifi: remove PMK cache if MAC is changed
Bug: 152931766
Test: atest FrameworksWifiTests
Change-Id: Ia4c555de7391d009359d68bbf6711c5922c415ab
Diffstat (limited to 'service')
4 files changed, 55 insertions, 6 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java index 2887081c9..c1d2518b9 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -3265,6 +3265,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); @@ -3283,6 +3286,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() + "'"); 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 20701ca6a..db2c3ce17 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -2417,6 +2417,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 */ |