diff options
3 files changed, 43 insertions, 6 deletions
diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackV1_3Impl.java b/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackV1_3Impl.java index 463881bbd..5af65d0a5 100644 --- a/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackV1_3Impl.java +++ b/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackV1_3Impl.java @@ -19,6 +19,7 @@ import android.annotation.NonNull; import android.hardware.wifi.supplicant.V1_0.ISupplicantStaIfaceCallback; import android.hardware.wifi.supplicant.V1_3.ISupplicantStaIfaceCallback.BssTmData; import android.net.wifi.SupplicantState; +import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.net.wifi.WifiSsid; import android.util.Log; @@ -192,10 +193,15 @@ abstract class SupplicantStaIfaceCallbackV1_3Impl extends @Override public void onPmkCacheAdded(long expirationTimeInSec, ArrayList<Byte> serializedEntry) { - int curNetworkId = mStaIfaceHal.getCurrentNetworkId(mIfaceName); - mStaIfaceHal.addPmkCacheEntry(curNetworkId, expirationTimeInSec, serializedEntry); + WifiConfiguration curConfig = mStaIfaceHal.getCurrentNetworkLocalConfig(mIfaceName); + + if (curConfig == null) return; + + if (WifiConfigurationUtil.isConfigForPskNetwork(curConfig)) return; + + mStaIfaceHal.addPmkCacheEntry(curConfig.networkId, expirationTimeInSec, serializedEntry); mStaIfaceHal.logCallback( - "onPmkCacheAdded: update pmk cache for config id " + curNetworkId); + "onPmkCacheAdded: update pmk cache for config id " + curConfig.networkId); } @Override diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java index 9d8f4eecd..4380f6ab4 100644 --- a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java +++ b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java @@ -987,6 +987,7 @@ public class SupplicantStaIfaceHal { PmkCacheStoreData pmkData = mPmkCacheEntries.get(config.networkId); if (pmkData != null + && !WifiConfigurationUtil.isConfigForPskNetwork(config) && pmkData.expirationTimeInSec > mClock.getElapsedSinceBootMillis() / 1000) { logi("Set PMK cache for config id " + config.networkId); if (networkHandle.setPmkCache(pmkData.data)) { diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java index ad2eac8a8..843a63c17 100644 --- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java @@ -1736,7 +1736,7 @@ public class SupplicantStaIfaceHalTest extends WifiBaseTest { long testStartSeconds = PMK_CACHE_EXPIRATION_IN_SEC / 2; WifiConfiguration config = new WifiConfiguration(); config.networkId = testFrameworkNetworkId; - config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); + config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP); PmkCacheStoreData pmkCacheData = new PmkCacheStoreData(PMK_CACHE_EXPIRATION_IN_SEC, new ArrayList<Byte>()); mDut.mPmkCacheEntries.put(testFrameworkNetworkId, pmkCacheData); @@ -1770,7 +1770,37 @@ public class SupplicantStaIfaceHalTest extends WifiBaseTest { long testStartSeconds = PMK_CACHE_EXPIRATION_IN_SEC / 2; WifiConfiguration config = new WifiConfiguration(); config.networkId = testFrameworkNetworkId; + config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP); + when(mClock.getElapsedSinceBootMillis()).thenReturn(testStartSeconds * 1000L); + + setupMocksForHalV1_3(); + setupMocksForPmkCache(); + setupMocksForConnectSequence(false); + executeAndValidateInitializationSequenceV1_3(); + assertTrue(mDut.connectToNetwork(WLAN0_IFACE_NAME, config)); + + verify(mSupplicantStaNetworkMock, never()).setPmkCache(any(ArrayList.class)); + verify(mISupplicantStaIfaceCallbackV13, never()).onPmkCacheAdded( + anyLong(), any(ArrayList.class)); + verify(mHandler, never()).postDelayed( + /* private listener */ any(), + eq(SupplicantStaIfaceHal.PMK_CACHE_EXPIRATION_ALARM_TAG), + anyLong()); + } + + /** + * Test adding PMK cache entry returns faliure if this is a psk network. + */ + @Test + public void testAddPmkEntryIsOmittedWithPskNetwork() throws Exception { + int testFrameworkNetworkId = 9; + long testStartSeconds = PMK_CACHE_EXPIRATION_IN_SEC / 2; + WifiConfiguration config = new WifiConfiguration(); + config.networkId = testFrameworkNetworkId; config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); + PmkCacheStoreData pmkCacheData = + new PmkCacheStoreData(PMK_CACHE_EXPIRATION_IN_SEC, new ArrayList<Byte>()); + mDut.mPmkCacheEntries.put(testFrameworkNetworkId, pmkCacheData); when(mClock.getElapsedSinceBootMillis()).thenReturn(testStartSeconds * 1000L); setupMocksForHalV1_3(); @@ -1797,7 +1827,7 @@ public class SupplicantStaIfaceHalTest extends WifiBaseTest { long testStartSeconds = PMK_CACHE_EXPIRATION_IN_SEC / 2; WifiConfiguration config = new WifiConfiguration(); config.networkId = testFrameworkNetworkId; - config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); + config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP); PmkCacheStoreData pmkCacheData = new PmkCacheStoreData(PMK_CACHE_EXPIRATION_IN_SEC, new ArrayList<Byte>()); mDut.mPmkCacheEntries.put(testFrameworkNetworkId, pmkCacheData); @@ -1824,7 +1854,7 @@ public class SupplicantStaIfaceHalTest extends WifiBaseTest { long testStartSeconds = PMK_CACHE_EXPIRATION_IN_SEC / 2; WifiConfiguration config = new WifiConfiguration(); config.networkId = testFrameworkNetworkId; - config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); + config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP); PmkCacheStoreData pmkCacheData = new PmkCacheStoreData(PMK_CACHE_EXPIRATION_IN_SEC, new ArrayList<Byte>()); mDut.mPmkCacheEntries.put(testFrameworkNetworkId, pmkCacheData); |