Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
Vinit Deshapnde | ffadfb9 | 2013-12-06 15:12:41 -0800 | [diff] [blame] | 17 | package com.android.server.wifi; |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 18 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 19 | import com.android.internal.util.State; |
| 20 | import com.android.internal.util.StateMachine; |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 21 | |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
Vinit Deshapnde | ffadfb9 | 2013-12-06 15:12:41 -0800 | [diff] [blame] | 24 | import android.net.wifi.SupplicantState; |
| 25 | import android.net.wifi.WifiConfiguration; |
| 26 | import android.net.wifi.WifiManager; |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 27 | import android.os.Handler; |
| 28 | import android.os.Message; |
| 29 | import android.os.Parcelable; |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 30 | import android.os.UserHandle; |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 31 | import android.util.Log; |
| 32 | |
Irfan Sheriff | f0afe41 | 2012-11-30 14:07:44 -0800 | [diff] [blame] | 33 | import java.io.FileDescriptor; |
| 34 | import java.io.PrintWriter; |
| 35 | |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 36 | /** |
| 37 | * Tracks the state changes in supplicant and provides functionality |
| 38 | * that is based on these state changes: |
| 39 | * - detect a failed WPA handshake that loops indefinitely |
Irfan Sheriff | b98d878 | 2011-01-19 15:09:14 -0800 | [diff] [blame] | 40 | * - authentication failure handling |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 41 | */ |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 42 | class SupplicantStateTracker extends StateMachine { |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 43 | |
| 44 | private static final String TAG = "SupplicantStateTracker"; |
| 45 | private static final boolean DBG = false; |
| 46 | |
| 47 | private WifiStateMachine mWifiStateMachine; |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 48 | private WifiConfigStore mWifiConfigStore; |
Irfan Sheriff | b98d878 | 2011-01-19 15:09:14 -0800 | [diff] [blame] | 49 | private int mAuthenticationFailuresCount = 0; |
Deepthi Gowri | c1b631e | 2013-04-30 18:23:57 +0530 | [diff] [blame] | 50 | private int mAssociationRejectCount = 0; |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 51 | /* Indicates authentication failure in supplicant broadcast. |
| 52 | * TODO: enhance auth failure reporting to include notification |
| 53 | * for all type of failures: EAP, WPS & WPA networks */ |
| 54 | private boolean mAuthFailureInSupplicantBroadcast = false; |
| 55 | |
Irfan Sheriff | b98d878 | 2011-01-19 15:09:14 -0800 | [diff] [blame] | 56 | /* Maximum retries on a authentication failure notification */ |
| 57 | private static final int MAX_RETRIES_ON_AUTHENTICATION_FAILURE = 2; |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 58 | |
Deepthi Gowri | c1b631e | 2013-04-30 18:23:57 +0530 | [diff] [blame] | 59 | /* Maximum retries on assoc rejection events */ |
Vinit Deshapnde | 8fa06ee | 2013-11-13 15:48:11 -0800 | [diff] [blame] | 60 | private static final int MAX_RETRIES_ON_ASSOCIATION_REJECT = 16; |
Deepthi Gowri | c1b631e | 2013-04-30 18:23:57 +0530 | [diff] [blame] | 61 | |
Irfan Sheriff | 8e86b89 | 2010-12-22 11:02:20 -0800 | [diff] [blame] | 62 | /* Tracks if networks have been disabled during a connection */ |
| 63 | private boolean mNetworksDisabledDuringConnect = false; |
| 64 | |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 65 | private Context mContext; |
| 66 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 67 | private State mUninitializedState = new UninitializedState(); |
| 68 | private State mDefaultState = new DefaultState(); |
| 69 | private State mInactiveState = new InactiveState(); |
| 70 | private State mDisconnectState = new DisconnectedState(); |
| 71 | private State mScanState = new ScanState(); |
| 72 | private State mHandshakeState = new HandshakeState(); |
| 73 | private State mCompletedState = new CompletedState(); |
| 74 | private State mDormantState = new DormantState(); |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 75 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 76 | public SupplicantStateTracker(Context c, WifiStateMachine wsm, WifiConfigStore wcs, Handler t) { |
| 77 | super(TAG, t.getLooper()); |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 78 | |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 79 | mContext = c; |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 80 | mWifiStateMachine = wsm; |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 81 | mWifiConfigStore = wcs; |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 82 | addState(mDefaultState); |
| 83 | addState(mUninitializedState, mDefaultState); |
| 84 | addState(mInactiveState, mDefaultState); |
| 85 | addState(mDisconnectState, mDefaultState); |
| 86 | addState(mScanState, mDefaultState); |
| 87 | addState(mHandshakeState, mDefaultState); |
| 88 | addState(mCompletedState, mDefaultState); |
| 89 | addState(mDormantState, mDefaultState); |
| 90 | |
| 91 | setInitialState(mUninitializedState); |
Irfan Sheriff | f0afe41 | 2012-11-30 14:07:44 -0800 | [diff] [blame] | 92 | setLogRecSize(50); |
| 93 | setLogOnlyTransitions(true); |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 94 | //start the state machine |
| 95 | start(); |
| 96 | } |
| 97 | |
Deepthi Gowri | c1b631e | 2013-04-30 18:23:57 +0530 | [diff] [blame] | 98 | private void handleNetworkConnectionFailure(int netId, int disableReason) { |
Irfan Sheriff | 8e86b89 | 2010-12-22 11:02:20 -0800 | [diff] [blame] | 99 | /* If other networks disabled during connection, enable them */ |
| 100 | if (mNetworksDisabledDuringConnect) { |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 101 | mWifiConfigStore.enableAllNetworks(); |
Irfan Sheriff | 8e86b89 | 2010-12-22 11:02:20 -0800 | [diff] [blame] | 102 | mNetworksDisabledDuringConnect = false; |
| 103 | } |
| 104 | /* Disable failed network */ |
Deepthi Gowri | c1b631e | 2013-04-30 18:23:57 +0530 | [diff] [blame] | 105 | mWifiConfigStore.disableNetwork(netId, disableReason); |
Irfan Sheriff | 8e86b89 | 2010-12-22 11:02:20 -0800 | [diff] [blame] | 106 | } |
| 107 | |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 108 | private void transitionOnSupplicantStateChange(StateChangeResult stateChangeResult) { |
| 109 | SupplicantState supState = (SupplicantState) stateChangeResult.state; |
| 110 | |
| 111 | if (DBG) Log.d(TAG, "Supplicant state: " + supState.toString() + "\n"); |
| 112 | |
| 113 | switch (supState) { |
Irfan Sheriff | 319da8c | 2011-05-27 12:10:55 -0700 | [diff] [blame] | 114 | case DISCONNECTED: |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 115 | transitionTo(mDisconnectState); |
| 116 | break; |
Irfan Sheriff | 319da8c | 2011-05-27 12:10:55 -0700 | [diff] [blame] | 117 | case INTERFACE_DISABLED: |
| 118 | //we should have received a disconnection already, do nothing |
| 119 | break; |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 120 | case SCANNING: |
| 121 | transitionTo(mScanState); |
| 122 | break; |
Irfan Sheriff | 319da8c | 2011-05-27 12:10:55 -0700 | [diff] [blame] | 123 | case AUTHENTICATING: |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 124 | case ASSOCIATING: |
| 125 | case ASSOCIATED: |
| 126 | case FOUR_WAY_HANDSHAKE: |
| 127 | case GROUP_HANDSHAKE: |
| 128 | transitionTo(mHandshakeState); |
| 129 | break; |
| 130 | case COMPLETED: |
| 131 | transitionTo(mCompletedState); |
| 132 | break; |
| 133 | case DORMANT: |
| 134 | transitionTo(mDormantState); |
| 135 | break; |
| 136 | case INACTIVE: |
| 137 | transitionTo(mInactiveState); |
| 138 | break; |
| 139 | case UNINITIALIZED: |
| 140 | case INVALID: |
| 141 | transitionTo(mUninitializedState); |
| 142 | break; |
| 143 | default: |
| 144 | Log.e(TAG, "Unknown supplicant state " + supState); |
| 145 | break; |
| 146 | } |
| 147 | } |
| 148 | |
Irfan Sheriff | b45e726 | 2010-12-21 09:44:15 -0800 | [diff] [blame] | 149 | private void sendSupplicantStateChangedBroadcast(SupplicantState state, boolean failedAuth) { |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 150 | Intent intent = new Intent(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION); |
| 151 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT |
| 152 | | Intent.FLAG_RECEIVER_REPLACE_PENDING); |
Irfan Sheriff | b45e726 | 2010-12-21 09:44:15 -0800 | [diff] [blame] | 153 | intent.putExtra(WifiManager.EXTRA_NEW_STATE, (Parcelable) state); |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 154 | if (failedAuth) { |
| 155 | intent.putExtra( |
| 156 | WifiManager.EXTRA_SUPPLICANT_ERROR, |
| 157 | WifiManager.ERROR_AUTHENTICATING); |
| 158 | } |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 159 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | /******************************************************** |
| 163 | * HSM states |
| 164 | *******************************************************/ |
| 165 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 166 | class DefaultState extends State { |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 167 | @Override |
| 168 | public void enter() { |
| 169 | if (DBG) Log.d(TAG, getName() + "\n"); |
| 170 | } |
| 171 | @Override |
| 172 | public boolean processMessage(Message message) { |
| 173 | if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); |
| 174 | switch (message.what) { |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 175 | case WifiMonitor.AUTHENTICATION_FAILURE_EVENT: |
Irfan Sheriff | b98d878 | 2011-01-19 15:09:14 -0800 | [diff] [blame] | 176 | mAuthenticationFailuresCount++; |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 177 | mAuthFailureInSupplicantBroadcast = true; |
| 178 | break; |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 179 | case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT: |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 180 | StateChangeResult stateChangeResult = (StateChangeResult) message.obj; |
Irfan Sheriff | b45e726 | 2010-12-21 09:44:15 -0800 | [diff] [blame] | 181 | SupplicantState state = stateChangeResult.state; |
| 182 | sendSupplicantStateChangedBroadcast(state, mAuthFailureInSupplicantBroadcast); |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 183 | mAuthFailureInSupplicantBroadcast = false; |
| 184 | transitionOnSupplicantStateChange(stateChangeResult); |
| 185 | break; |
Irfan Sheriff | b45e726 | 2010-12-21 09:44:15 -0800 | [diff] [blame] | 186 | case WifiStateMachine.CMD_RESET_SUPPLICANT_STATE: |
| 187 | transitionTo(mUninitializedState); |
| 188 | break; |
Irfan Sheriff | d3975a9 | 2012-02-24 10:54:13 -0800 | [diff] [blame] | 189 | case WifiManager.CONNECT_NETWORK: |
Irfan Sheriff | 8e86b89 | 2010-12-22 11:02:20 -0800 | [diff] [blame] | 190 | mNetworksDisabledDuringConnect = true; |
Deepthi Gowri | c1b631e | 2013-04-30 18:23:57 +0530 | [diff] [blame] | 191 | mAssociationRejectCount = 0; |
| 192 | break; |
| 193 | case WifiMonitor.ASSOCIATION_REJECTION_EVENT: |
| 194 | mAssociationRejectCount++; |
Irfan Sheriff | 8e86b89 | 2010-12-22 11:02:20 -0800 | [diff] [blame] | 195 | break; |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 196 | default: |
| 197 | Log.e(TAG, "Ignoring " + message); |
| 198 | break; |
| 199 | } |
| 200 | return HANDLED; |
| 201 | } |
| 202 | } |
| 203 | |
Irfan Sheriff | b45e726 | 2010-12-21 09:44:15 -0800 | [diff] [blame] | 204 | /* |
| 205 | * This indicates that the supplicant state as seen |
| 206 | * by the framework is not initialized yet. We are |
| 207 | * in this state right after establishing a control |
| 208 | * channel connection before any supplicant events |
| 209 | * or after we have lost the control channel |
| 210 | * connection to the supplicant |
| 211 | */ |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 212 | class UninitializedState extends State { |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 213 | @Override |
| 214 | public void enter() { |
| 215 | if (DBG) Log.d(TAG, getName() + "\n"); |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 216 | } |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 219 | class InactiveState extends State { |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 220 | @Override |
| 221 | public void enter() { |
| 222 | if (DBG) Log.d(TAG, getName() + "\n"); |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 223 | } |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 224 | } |
| 225 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 226 | class DisconnectedState extends State { |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 227 | @Override |
| 228 | public void enter() { |
| 229 | if (DBG) Log.d(TAG, getName() + "\n"); |
Irfan Sheriff | b98d878 | 2011-01-19 15:09:14 -0800 | [diff] [blame] | 230 | /* If a disconnect event happens after authentication failure |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 231 | * exceeds maximum retries, disable the network |
| 232 | */ |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 233 | Message message = getCurrentMessage(); |
| 234 | StateChangeResult stateChangeResult = (StateChangeResult) message.obj; |
| 235 | |
Irfan Sheriff | b98d878 | 2011-01-19 15:09:14 -0800 | [diff] [blame] | 236 | if (mAuthenticationFailuresCount >= MAX_RETRIES_ON_AUTHENTICATION_FAILURE) { |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 237 | Log.d(TAG, "Failed to authenticate, disabling network " + |
| 238 | stateChangeResult.networkId); |
Deepthi Gowri | c1b631e | 2013-04-30 18:23:57 +0530 | [diff] [blame] | 239 | handleNetworkConnectionFailure(stateChangeResult.networkId, |
| 240 | WifiConfiguration.DISABLED_AUTH_FAILURE); |
Irfan Sheriff | b98d878 | 2011-01-19 15:09:14 -0800 | [diff] [blame] | 241 | mAuthenticationFailuresCount = 0; |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 242 | } |
Deepthi Gowri | c1b631e | 2013-04-30 18:23:57 +0530 | [diff] [blame] | 243 | else if (mAssociationRejectCount >= MAX_RETRIES_ON_ASSOCIATION_REJECT) { |
| 244 | Log.d(TAG, "Association getting rejected, disabling network " + |
| 245 | stateChangeResult.networkId); |
| 246 | handleNetworkConnectionFailure(stateChangeResult.networkId, |
| 247 | WifiConfiguration.DISABLED_ASSOCIATION_REJECT); |
| 248 | mAssociationRejectCount = 0; |
| 249 | } |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 253 | class ScanState extends State { |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 254 | @Override |
| 255 | public void enter() { |
| 256 | if (DBG) Log.d(TAG, getName() + "\n"); |
| 257 | } |
| 258 | } |
| 259 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 260 | class HandshakeState extends State { |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 261 | /** |
| 262 | * The max number of the WPA supplicant loop iterations before we |
| 263 | * decide that the loop should be terminated: |
| 264 | */ |
| 265 | private static final int MAX_SUPPLICANT_LOOP_ITERATIONS = 4; |
| 266 | private int mLoopDetectIndex; |
| 267 | private int mLoopDetectCount; |
| 268 | |
| 269 | @Override |
| 270 | public void enter() { |
| 271 | if (DBG) Log.d(TAG, getName() + "\n"); |
| 272 | mLoopDetectIndex = 0; |
| 273 | mLoopDetectCount = 0; |
| 274 | } |
| 275 | @Override |
| 276 | public boolean processMessage(Message message) { |
| 277 | if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); |
| 278 | switch (message.what) { |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 279 | case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT: |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 280 | StateChangeResult stateChangeResult = (StateChangeResult) message.obj; |
Irfan Sheriff | b45e726 | 2010-12-21 09:44:15 -0800 | [diff] [blame] | 281 | SupplicantState state = stateChangeResult.state; |
Irfan Sheriff | 319da8c | 2011-05-27 12:10:55 -0700 | [diff] [blame] | 282 | if (SupplicantState.isHandshakeState(state)) { |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 283 | if (mLoopDetectIndex > state.ordinal()) { |
| 284 | mLoopDetectCount++; |
| 285 | } |
| 286 | if (mLoopDetectCount > MAX_SUPPLICANT_LOOP_ITERATIONS) { |
| 287 | Log.d(TAG, "Supplicant loop detected, disabling network " + |
| 288 | stateChangeResult.networkId); |
Deepthi Gowri | c1b631e | 2013-04-30 18:23:57 +0530 | [diff] [blame] | 289 | handleNetworkConnectionFailure(stateChangeResult.networkId, |
| 290 | WifiConfiguration.DISABLED_AUTH_FAILURE); |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 291 | } |
| 292 | mLoopDetectIndex = state.ordinal(); |
Irfan Sheriff | b45e726 | 2010-12-21 09:44:15 -0800 | [diff] [blame] | 293 | sendSupplicantStateChangedBroadcast(state, |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 294 | mAuthFailureInSupplicantBroadcast); |
| 295 | } else { |
| 296 | //Have the DefaultState handle the transition |
| 297 | return NOT_HANDLED; |
| 298 | } |
| 299 | break; |
| 300 | default: |
| 301 | return NOT_HANDLED; |
| 302 | } |
| 303 | return HANDLED; |
| 304 | } |
| 305 | } |
| 306 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 307 | class CompletedState extends State { |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 308 | @Override |
| 309 | public void enter() { |
| 310 | if (DBG) Log.d(TAG, getName() + "\n"); |
Irfan Sheriff | b98d878 | 2011-01-19 15:09:14 -0800 | [diff] [blame] | 311 | /* Reset authentication failure count */ |
| 312 | mAuthenticationFailuresCount = 0; |
Deepthi Gowri | c1b631e | 2013-04-30 18:23:57 +0530 | [diff] [blame] | 313 | mAssociationRejectCount = 0; |
Irfan Sheriff | 8e86b89 | 2010-12-22 11:02:20 -0800 | [diff] [blame] | 314 | if (mNetworksDisabledDuringConnect) { |
Irfan Sheriff | fc7f95a | 2012-01-04 14:50:09 -0800 | [diff] [blame] | 315 | mWifiConfigStore.enableAllNetworks(); |
Irfan Sheriff | 8e86b89 | 2010-12-22 11:02:20 -0800 | [diff] [blame] | 316 | mNetworksDisabledDuringConnect = false; |
| 317 | } |
| 318 | } |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 319 | @Override |
| 320 | public boolean processMessage(Message message) { |
| 321 | if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); |
| 322 | switch(message.what) { |
repo sync | 55bc5f3 | 2011-06-24 14:23:07 -0700 | [diff] [blame] | 323 | case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT: |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 324 | StateChangeResult stateChangeResult = (StateChangeResult) message.obj; |
Irfan Sheriff | b45e726 | 2010-12-21 09:44:15 -0800 | [diff] [blame] | 325 | SupplicantState state = stateChangeResult.state; |
| 326 | sendSupplicantStateChangedBroadcast(state, mAuthFailureInSupplicantBroadcast); |
Irfan Sheriff | 319da8c | 2011-05-27 12:10:55 -0700 | [diff] [blame] | 327 | /* Ignore any connecting state in completed state. Group re-keying |
| 328 | * events and other auth events that do not affect connectivity are |
| 329 | * ignored |
| 330 | */ |
| 331 | if (SupplicantState.isConnecting(state)) { |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 332 | break; |
| 333 | } |
| 334 | transitionOnSupplicantStateChange(stateChangeResult); |
| 335 | break; |
Irfan Sheriff | b45e726 | 2010-12-21 09:44:15 -0800 | [diff] [blame] | 336 | case WifiStateMachine.CMD_RESET_SUPPLICANT_STATE: |
| 337 | sendSupplicantStateChangedBroadcast(SupplicantState.DISCONNECTED, false); |
| 338 | transitionTo(mUninitializedState); |
| 339 | break; |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 340 | default: |
| 341 | return NOT_HANDLED; |
| 342 | } |
| 343 | return HANDLED; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | //TODO: remove after getting rid of the state in supplicant |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 348 | class DormantState extends State { |
Irfan Sheriff | 19d245b79 | 2010-11-11 16:40:06 -0800 | [diff] [blame] | 349 | @Override |
| 350 | public void enter() { |
| 351 | if (DBG) Log.d(TAG, getName() + "\n"); |
| 352 | } |
| 353 | } |
Irfan Sheriff | f0afe41 | 2012-11-30 14:07:44 -0800 | [diff] [blame] | 354 | |
| 355 | @Override |
| 356 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 357 | super.dump(fd, pw, args); |
| 358 | pw.println("mAuthenticationFailuresCount " + mAuthenticationFailuresCount); |
| 359 | pw.println("mAuthFailureInSupplicantBroadcast " + mAuthFailureInSupplicantBroadcast); |
| 360 | pw.println("mNetworksDisabledDuringConnect " + mNetworksDisabledDuringConnect); |
| 361 | pw.println(); |
| 362 | } |
Irfan Sheriff | 6bb7652 | 2011-01-11 11:17:14 -0800 | [diff] [blame] | 363 | } |