summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/SupplicantStaIfaceCallbackImpl.java35
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java46
2 files changed, 66 insertions, 15 deletions
diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackImpl.java b/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackImpl.java
index 92ba43b4c..9d69003cf 100644
--- a/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackImpl.java
+++ b/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackImpl.java
@@ -55,7 +55,8 @@ abstract class SupplicantStaIfaceCallbackImpl extends ISupplicantStaIfaceCallbac
private final String mIfaceName;
private final Object mLock;
private final WifiMonitor mWifiMonitor;
- private boolean mStateIsFourway = false; // Used to help check for PSK password mismatch
+ // Used to help check for PSK password mismatch & EAP connection failure.
+ private int mStateBeforeDisconnect = State.INACTIVE;
SupplicantStaIfaceCallbackImpl(@NonNull SupplicantStaIfaceHal staIfaceHal,
@NonNull String ifaceName,
@@ -151,8 +152,8 @@ abstract class SupplicantStaIfaceCallbackImpl extends ISupplicantStaIfaceCallbac
public void onNetworkRemoved(int id) {
synchronized (mLock) {
mStaIfaceHal.logCallback("onNetworkRemoved");
- // Reset 4way handshake state since network has been removed.
- mStateIsFourway = false;
+ // Reset state since network has been removed.
+ mStateBeforeDisconnect = State.INACTIVE;
}
}
@@ -166,8 +167,12 @@ abstract class SupplicantStaIfaceCallbackImpl extends ISupplicantStaIfaceCallbac
WifiSsid wifiSsid =
WifiSsid.createFromByteArray(NativeUtil.byteArrayFromArrayList(ssid));
String bssidStr = NativeUtil.macAddressFromByteArray(bssid);
- mStateIsFourway = (newState == ISupplicantStaIfaceCallback.State.FOURWAY_HANDSHAKE);
- if (newSupplicantState == SupplicantState.COMPLETED) {
+ if (newState != State.DISCONNECTED) {
+ // onStateChanged(DISCONNECTED) may come before onDisconnected(), so add this
+ // cache to track the state before the disconnect.
+ mStateBeforeDisconnect = newState;
+ }
+ if (newState == State.COMPLETED) {
mWifiMonitor.broadcastNetworkConnectionEvent(
mIfaceName, mStaIfaceHal.getCurrentNetworkId(mIfaceName), bssidStr);
}
@@ -239,14 +244,23 @@ abstract class SupplicantStaIfaceCallbackImpl extends ISupplicantStaIfaceCallbac
synchronized (mLock) {
mStaIfaceHal.logCallback("onDisconnected");
if (mStaIfaceHal.isVerboseLoggingEnabled()) {
- Log.e(TAG, "onDisconnected 4way=" + mStateIsFourway
+ Log.e(TAG, "onDisconnected state=" + mStateBeforeDisconnect
+ " locallyGenerated=" + locallyGenerated
+ " reasonCode=" + reasonCode);
}
- if (mStateIsFourway
- && (!locallyGenerated || reasonCode != ReasonCode.IE_IN_4WAY_DIFFERS)) {
- mWifiMonitor.broadcastAuthenticationFailureEvent(
- mIfaceName, WifiManager.ERROR_AUTH_FAILURE_WRONG_PSWD, -1);
+ WifiConfiguration curConfiguration =
+ mStaIfaceHal.getCurrentNetworkLocalConfig(mIfaceName);
+ if (curConfiguration != null) {
+ if (mStateBeforeDisconnect == State.FOURWAY_HANDSHAKE
+ && WifiConfigurationUtil.isConfigForPskNetwork(curConfiguration)
+ && (!locallyGenerated || reasonCode != ReasonCode.IE_IN_4WAY_DIFFERS)) {
+ mWifiMonitor.broadcastAuthenticationFailureEvent(
+ mIfaceName, WifiManager.ERROR_AUTH_FAILURE_WRONG_PSWD, -1);
+ } else if (mStateBeforeDisconnect == State.ASSOCIATED
+ && WifiConfigurationUtil.isConfigForEapNetwork(curConfiguration)) {
+ mWifiMonitor.broadcastAuthenticationFailureEvent(
+ mIfaceName, WifiManager.ERROR_AUTH_FAILURE_EAP_FAILURE, -1);
+ }
}
mWifiMonitor.broadcastNetworkDisconnectionEvent(
mIfaceName, locallyGenerated ? 1 : 0, reasonCode,
@@ -261,7 +275,6 @@ abstract class SupplicantStaIfaceCallbackImpl extends ISupplicantStaIfaceCallbac
boolean isWrongPwd = false;
WifiConfiguration curConfiguration =
mStaIfaceHal.getCurrentNetworkLocalConfig(mIfaceName);
-
if (curConfiguration != null) {
if (!timedOut) {
Log.d(TAG, "flush PMK cache due to association rejection for config id "
diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
index 95f88bbf1..762691184 100644
--- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
@@ -1040,9 +1040,11 @@ public class SupplicantStaIfaceHalTest extends WifiBaseTest {
* Tests the handling of incorrect network passwords.
*/
@Test
- public void testAuthFailurePassword() throws Exception {
+ public void testAuthFailurePasswordOnDisconnect() throws Exception {
executeAndValidateInitializationSequence();
assertNotNull(mISupplicantStaIfaceCallback);
+ executeAndValidateConnectSequenceWithKeyMgmt(
+ 0, false, WifiConfiguration.KeyMgmt.WPA_PSK, null);
int reasonCode = 3;
mISupplicantStaIfaceCallback.onDisconnected(
@@ -1061,13 +1063,49 @@ public class SupplicantStaIfaceHalTest extends WifiBaseTest {
SUPPLICANT_NETWORK_ID,
NativeUtil.decodeSsid(SUPPLICANT_SSID));
mISupplicantStaIfaceCallback.onDisconnected(
+ NativeUtil.macAddressToByteArray(BSSID), false, reasonCode);
+
+ verify(mWifiMonitor).broadcastAuthenticationFailureEvent(
+ eq(WLAN0_IFACE_NAME), eq(WifiManager.ERROR_AUTH_FAILURE_WRONG_PSWD), eq(-1));
+ }
+
+ /**
+ * Tests the handling of EAP failure disconnects.
+ */
+ @Test
+ public void testAuthFailureEapOnDisconnect() throws Exception {
+ executeAndValidateInitializationSequence();
+ assertNotNull(mISupplicantStaIfaceCallback);
+ executeAndValidateConnectSequenceWithKeyMgmt(
+ 0, false, WifiConfiguration.KeyMgmt.WPA_EAP, null);
+
+ int reasonCode = 3;
+ mISupplicantStaIfaceCallback.onDisconnected(
NativeUtil.macAddressToByteArray(BSSID), true, reasonCode);
+ verify(mWifiMonitor, times(0))
+ .broadcastAuthenticationFailureEvent(any(), anyInt(), anyInt());
+
mISupplicantStaIfaceCallback.onDisconnected(
NativeUtil.macAddressToByteArray(BSSID), false, reasonCode);
+ verify(mWifiMonitor, times(0))
+ .broadcastAuthenticationFailureEvent(any(), anyInt(), anyInt());
- verify(mWifiMonitor, times(2))
- .broadcastAuthenticationFailureEvent(eq(WLAN0_IFACE_NAME),
- eq(WifiManager.ERROR_AUTH_FAILURE_WRONG_PSWD), eq(-1));
+ mISupplicantStaIfaceCallback.onStateChanged(
+ ISupplicantStaIfaceCallback.State.ASSOCIATED,
+ NativeUtil.macAddressToByteArray(BSSID),
+ SUPPLICANT_NETWORK_ID,
+ NativeUtil.decodeSsid(SUPPLICANT_SSID));
+ // Ensure we don't lose our prev state with this state changed event.
+ mISupplicantStaIfaceCallback.onStateChanged(
+ ISupplicantStaIfaceCallback.State.DISCONNECTED,
+ NativeUtil.macAddressToByteArray(BSSID),
+ SUPPLICANT_NETWORK_ID,
+ NativeUtil.decodeSsid(SUPPLICANT_SSID));
+ mISupplicantStaIfaceCallback.onDisconnected(
+ NativeUtil.macAddressToByteArray(BSSID), false, reasonCode);
+
+ verify(mWifiMonitor).broadcastAuthenticationFailureEvent(
+ eq(WLAN0_IFACE_NAME), eq(WifiManager.ERROR_AUTH_FAILURE_EAP_FAILURE), eq(-1));
}
/**