summaryrefslogtreecommitdiffstats
path: root/wifi
diff options
context:
space:
mode:
authorIrfan Sheriff <isheriff@google.com>2011-06-22 07:27:39 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-06-22 07:27:39 -0700
commit5d5b73be515d839d72e1cf7aeffdfdfb56d66045 (patch)
tree41d8ccbcf4723f3c6cd25dbd92f5bf446df0d36e /wifi
parent4d9261fad3e3bdfa056f377c10f2af0a6db62542 (diff)
parentc74eacde3028551864d8a9f8822803a835785c3a (diff)
downloadframeworks_base-5d5b73be515d839d72e1cf7aeffdfdfb56d66045.zip
frameworks_base-5d5b73be515d839d72e1cf7aeffdfdfb56d66045.tar.gz
frameworks_base-5d5b73be515d839d72e1cf7aeffdfdfb56d66045.tar.bz2
Merge "resolved conflicts for merge of 267a6181 to honeycomb-LTE" into honeycomb-LTE
Diffstat (limited to 'wifi')
-rw-r--r--wifi/java/android/net/wifi/WifiStateMachine.java281
1 files changed, 131 insertions, 150 deletions
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index d10a5d8..ce441aa 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -48,7 +48,6 @@ import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.DhcpInfo;
import android.net.DhcpInfoInternal;
-import android.net.DhcpStateMachine;
import android.net.InterfaceConfiguration;
import android.net.LinkAddress;
import android.net.LinkProperties;
@@ -153,7 +152,6 @@ public class WifiStateMachine extends StateMachine {
private NetworkInfo mNetworkInfo;
private SupplicantStateTracker mSupplicantStateTracker;
private WpsStateMachine mWpsStateMachine;
- private DhcpStateMachine mDhcpStateMachine;
private AlarmManager mAlarmManager;
private PendingIntent mScanIntent;
@@ -191,10 +189,10 @@ public class WifiStateMachine extends StateMachine {
static final int CMD_START_DRIVER = BASE + 13;
/* Start the driver */
static final int CMD_STOP_DRIVER = BASE + 14;
- /* Indicates Static IP succeded */
- static final int CMD_STATIC_IP_SUCCESS = BASE + 15;
- /* Indicates Static IP failed */
- static final int CMD_STATIC_IP_FAILURE = BASE + 16;
+ /* Indicates DHCP succeded */
+ static final int CMD_IP_CONFIG_SUCCESS = BASE + 15;
+ /* Indicates DHCP failed */
+ static final int CMD_IP_CONFIG_FAILURE = BASE + 16;
/* Start the soft access point */
static final int CMD_START_AP = BASE + 21;
@@ -344,11 +342,8 @@ public class WifiStateMachine extends StateMachine {
*/
private static final int DEFAULT_MAX_DHCP_RETRIES = 9;
- static final int POWER_MODE_ACTIVE = 1;
- static final int POWER_MODE_AUTO = 0;
-
- /* Tracks the power mode for restoration after a DHCP request/renewal goes through */
- private int mPowerMode = POWER_MODE_AUTO;
+ private static final int POWER_MODE_ACTIVE = 1;
+ private static final int POWER_MODE_AUTO = 0;
/**
* See {@link Settings.Secure#WIFI_SCAN_INTERVAL_MS}. This is the default value if a
@@ -1415,10 +1410,10 @@ public class WifiStateMachine extends StateMachine {
/*
* stop DHCP
*/
- if (mDhcpStateMachine != null) {
- mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_STOP_DHCP);
- mDhcpStateMachine.quit();
- mDhcpStateMachine = null;
+ NetworkUtils.resetConnections(mInterfaceName);
+
+ if (!NetworkUtils.stopDhcp(mInterfaceName)) {
+ Log.e(TAG, "Could not stop DHCP");
}
/* Disable interface */
@@ -1447,99 +1442,7 @@ public class WifiStateMachine extends StateMachine {
mLastNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
}
- void handlePreDhcpSetup() {
- if (!mBluetoothConnectionActive) {
- /*
- * There are problems setting the Wi-Fi driver's power
- * mode to active when bluetooth coexistence mode is
- * enabled or sense.
- * <p>
- * We set Wi-Fi to active mode when
- * obtaining an IP address because we've found
- * compatibility issues with some routers with low power
- * mode.
- * <p>
- * In order for this active power mode to properly be set,
- * we disable coexistence mode until we're done with
- * obtaining an IP address. One exception is if we
- * are currently connected to a headset, since disabling
- * coexistence would interrupt that connection.
- */
- // Disable the coexistence mode
- WifiNative.setBluetoothCoexistenceModeCommand(
- WifiNative.BLUETOOTH_COEXISTENCE_MODE_DISABLED);
- }
-
- mPowerMode = WifiNative.getPowerModeCommand();
- if (mPowerMode < 0) {
- // Handle the case where supplicant driver does not support
- // getPowerModeCommand.
- mPowerMode = WifiStateMachine.POWER_MODE_AUTO;
- }
- if (mPowerMode != WifiStateMachine.POWER_MODE_ACTIVE) {
- WifiNative.setPowerModeCommand(WifiStateMachine.POWER_MODE_ACTIVE);
- }
- }
-
-
- void handlePostDhcpSetup() {
- /* restore power mode */
- WifiNative.setPowerModeCommand(mPowerMode);
-
- // Set the coexistence mode back to its default value
- WifiNative.setBluetoothCoexistenceModeCommand(
- WifiNative.BLUETOOTH_COEXISTENCE_MODE_SENSE);
- }
-
- private void handleSuccessfulIpConfiguration(DhcpInfoInternal dhcpInfoInternal) {
- synchronized (mDhcpInfoInternal) {
- mDhcpInfoInternal = dhcpInfoInternal;
- }
- mLastSignalLevel = -1; // force update of signal strength
- WifiConfigStore.setIpConfiguration(mLastNetworkId, dhcpInfoInternal);
- InetAddress addr = NetworkUtils.numericToInetAddress(dhcpInfoInternal.ipAddress);
- mWifiInfo.setInetAddress(addr);
- if (getNetworkDetailedState() == DetailedState.CONNECTED) {
- //DHCP renewal in connected state
- LinkProperties linkProperties = dhcpInfoInternal.makeLinkProperties();
- linkProperties.setHttpProxy(WifiConfigStore.getProxyProperties(mLastNetworkId));
- linkProperties.setInterfaceName(mInterfaceName);
- if (!linkProperties.equals(mLinkProperties)) {
- Log.d(TAG, "Link configuration changed for netId: " + mLastNetworkId
- + " old: " + mLinkProperties + "new: " + linkProperties);
- mLinkProperties = linkProperties;
- sendLinkConfigurationChangedBroadcast();
- }
- } else {
- configureLinkProperties();
- setNetworkDetailedState(DetailedState.CONNECTED);
- sendNetworkStateChangeBroadcast(mLastBssid);
- }
- }
-
- private void handleFailedIpConfiguration() {
- Log.e(TAG, "IP configuration failed");
-
- mWifiInfo.setInetAddress(null);
- /**
- * If we've exceeded the maximum number of retries for DHCP
- * to a given network, disable the network
- */
- if (++mReconnectCount > getMaxDhcpRetries()) {
- Log.e(TAG, "Failed " +
- mReconnectCount + " times, Disabling " + mLastNetworkId);
- WifiConfigStore.disableNetwork(mLastNetworkId);
- mReconnectCount = 0;
- }
-
- /* DHCP times out after about 30 seconds, we do a
- * disconnect and an immediate reconnect to try again
- */
- WifiNative.disconnectCommand();
- WifiNative.reconnectCommand();
- }
-
- private boolean startSoftApWithConfig(WifiConfiguration config, int currentStatus) {
+ private boolean startSoftApWithConfig(WifiConfiguration config, int currentStatus) {
if (config == null) {
config = WifiApConfigStore.getApConfiguration();
} else {
@@ -1564,7 +1467,6 @@ public class WifiStateMachine extends StateMachine {
return true;
}
-
/*********************************************************
* Notifications from WifiMonitor
********************************************************/
@@ -1742,8 +1644,6 @@ public class WifiStateMachine extends StateMachine {
case CMD_FORGET_NETWORK:
case CMD_RSSI_POLL:
case CMD_ENABLE_ALL_NETWORKS:
- case DhcpStateMachine.CMD_PRE_DHCP_ACTION:
- case DhcpStateMachine.CMD_POST_DHCP_ACTION:
break;
case CMD_START_WPS:
/* Return failure when the state machine cannot handle WPS initiation*/
@@ -2609,18 +2509,74 @@ public class WifiStateMachine extends StateMachine {
}
class ConnectingState extends State {
+ boolean mModifiedBluetoothCoexistenceMode;
+ int mPowerMode;
+ boolean mUseStaticIp;
+ Thread mDhcpThread;
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
+ mUseStaticIp = WifiConfigStore.isUsingStaticIp(mLastNetworkId);
+ if (!mUseStaticIp) {
+ mDhcpThread = null;
+ mModifiedBluetoothCoexistenceMode = false;
+ mPowerMode = POWER_MODE_AUTO;
+
+ if (!mBluetoothConnectionActive) {
+ /*
+ * There are problems setting the Wi-Fi driver's power
+ * mode to active when bluetooth coexistence mode is
+ * enabled or sense.
+ * <p>
+ * We set Wi-Fi to active mode when
+ * obtaining an IP address because we've found
+ * compatibility issues with some routers with low power
+ * mode.
+ * <p>
+ * In order for this active power mode to properly be set,
+ * we disable coexistence mode until we're done with
+ * obtaining an IP address. One exception is if we
+ * are currently connected to a headset, since disabling
+ * coexistence would interrupt that connection.
+ */
+ mModifiedBluetoothCoexistenceMode = true;
+
+ // Disable the coexistence mode
+ WifiNative.setBluetoothCoexistenceModeCommand(
+ WifiNative.BLUETOOTH_COEXISTENCE_MODE_DISABLED);
+ }
- if (!WifiConfigStore.isUsingStaticIp(mLastNetworkId)) {
- //start DHCP
- mDhcpStateMachine = DhcpStateMachine.makeDhcpStateMachine(
- mContext, WifiStateMachine.this, mInterfaceName);
- mDhcpStateMachine.registerForPreDhcpNotification();
- mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_START_DHCP);
+ mPowerMode = WifiNative.getPowerModeCommand();
+ if (mPowerMode < 0) {
+ // Handle the case where supplicant driver does not support
+ // getPowerModeCommand.
+ mPowerMode = POWER_MODE_AUTO;
+ }
+ if (mPowerMode != POWER_MODE_ACTIVE) {
+ WifiNative.setPowerModeCommand(POWER_MODE_ACTIVE);
+ }
+
+ Log.d(TAG, "DHCP request started");
+ mDhcpThread = new Thread(new Runnable() {
+ public void run() {
+ DhcpInfoInternal dhcpInfoInternal = new DhcpInfoInternal();
+ if (NetworkUtils.runDhcp(mInterfaceName, dhcpInfoInternal)) {
+ Log.d(TAG, "DHCP request succeeded");
+ synchronized (mDhcpInfoInternal) {
+ mDhcpInfoInternal = dhcpInfoInternal;
+ }
+ WifiConfigStore.setIpConfiguration(mLastNetworkId, dhcpInfoInternal);
+ sendMessage(CMD_IP_CONFIG_SUCCESS);
+ } else {
+ Log.d(TAG, "DHCP request failed: " +
+ NetworkUtils.getDhcpError());
+ sendMessage(CMD_IP_CONFIG_FAILURE);
+ }
+ }
+ });
+ mDhcpThread.start();
} else {
DhcpInfoInternal dhcpInfoInternal = WifiConfigStore.getIpConfiguration(
mLastNetworkId);
@@ -2632,13 +2588,16 @@ public class WifiStateMachine extends StateMachine {
try {
netd.setInterfaceConfig(mInterfaceName, ifcg);
Log.v(TAG, "Static IP configuration succeeded");
- sendMessage(CMD_STATIC_IP_SUCCESS, dhcpInfoInternal);
+ synchronized (mDhcpInfoInternal) {
+ mDhcpInfoInternal = dhcpInfoInternal;
+ }
+ sendMessage(CMD_IP_CONFIG_SUCCESS);
} catch (RemoteException re) {
Log.v(TAG, "Static IP configuration failed: " + re);
- sendMessage(CMD_STATIC_IP_FAILURE);
+ sendMessage(CMD_IP_CONFIG_FAILURE);
} catch (IllegalStateException e) {
Log.v(TAG, "Static IP configuration failed: " + e);
- sendMessage(CMD_STATIC_IP_FAILURE);
+ sendMessage(CMD_IP_CONFIG_FAILURE);
}
}
}
@@ -2647,26 +2606,44 @@ public class WifiStateMachine extends StateMachine {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
switch(message.what) {
- case DhcpStateMachine.CMD_PRE_DHCP_ACTION:
- handlePreDhcpSetup();
- mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_PRE_DHCP_ACTION_COMPLETE);
- break;
- case DhcpStateMachine.CMD_POST_DHCP_ACTION:
- handlePostDhcpSetup();
- if (message.arg1 == DhcpStateMachine.DHCP_SUCCESS) {
- handleSuccessfulIpConfiguration((DhcpInfoInternal) message.obj);
- transitionTo(mConnectedState);
- } else if (message.arg1 == DhcpStateMachine.DHCP_FAILURE) {
- handleFailedIpConfiguration();
- transitionTo(mDisconnectingState);
+ case CMD_IP_CONFIG_SUCCESS:
+ mLastSignalLevel = -1; // force update of signal strength
+ InetAddress addr;
+ synchronized (mDhcpInfoInternal) {
+ addr = NetworkUtils.numericToInetAddress(mDhcpInfoInternal.ipAddress);
}
- break;
- case CMD_STATIC_IP_SUCCESS:
- handleSuccessfulIpConfiguration((DhcpInfoInternal) message.obj);
+ mWifiInfo.setInetAddress(addr);
+ configureLinkProperties();
+ if (getNetworkDetailedState() == DetailedState.CONNECTED) {
+ sendLinkConfigurationChangedBroadcast();
+ } else {
+ setNetworkDetailedState(DetailedState.CONNECTED);
+ sendNetworkStateChangeBroadcast(mLastBssid);
+ }
+ //TODO: The framework is not detecting a DHCP renewal and a possible
+ //IP change. we should detect this and send out a config change broadcast
transitionTo(mConnectedState);
break;
- case CMD_STATIC_IP_FAILURE:
- handleFailedIpConfiguration();
+ case CMD_IP_CONFIG_FAILURE:
+ mWifiInfo.setInetAddress(null);
+
+ Log.e(TAG, "IP configuration failed");
+ /**
+ * If we've exceeded the maximum number of retries for DHCP
+ * to a given network, disable the network
+ */
+ if (++mReconnectCount > getMaxDhcpRetries()) {
+ Log.e(TAG, "Failed " +
+ mReconnectCount + " times, Disabling " + mLastNetworkId);
+ WifiConfigStore.disableNetwork(mLastNetworkId);
+ mReconnectCount = 0;
+ }
+
+ /* DHCP times out after about 30 seconds, we do a
+ * disconnect and an immediate reconnect to try again
+ */
+ WifiNative.disconnectCommand();
+ WifiNative.reconnectCommand();
transitionTo(mDisconnectingState);
break;
case CMD_DISCONNECT:
@@ -2710,6 +2687,23 @@ public class WifiStateMachine extends StateMachine {
EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
return HANDLED;
}
+
+ @Override
+ public void exit() {
+ /* reset power state & bluetooth coexistence if on DHCP */
+ if (!mUseStaticIp) {
+ if (mPowerMode != POWER_MODE_ACTIVE) {
+ WifiNative.setPowerModeCommand(mPowerMode);
+ }
+
+ if (mModifiedBluetoothCoexistenceMode) {
+ // Set the coexistence mode back to its default value
+ WifiNative.setBluetoothCoexistenceModeCommand(
+ WifiNative.BLUETOOTH_COEXISTENCE_MODE_SENSE);
+ }
+ }
+
+ }
}
class ConnectedState extends State {
@@ -2727,19 +2721,6 @@ public class WifiStateMachine extends StateMachine {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
boolean eventLoggingEnabled = true;
switch (message.what) {
- case DhcpStateMachine.CMD_PRE_DHCP_ACTION:
- handlePreDhcpSetup();
- mDhcpStateMachine.sendMessage(DhcpStateMachine.CMD_PRE_DHCP_ACTION_COMPLETE);
- break;
- case DhcpStateMachine.CMD_POST_DHCP_ACTION:
- handlePostDhcpSetup();
- if (message.arg1 == DhcpStateMachine.DHCP_SUCCESS) {
- handleSuccessfulIpConfiguration((DhcpInfoInternal) message.obj);
- } else if (message.arg1 == DhcpStateMachine.DHCP_FAILURE) {
- handleFailedIpConfiguration();
- transitionTo(mDisconnectingState);
- }
- break;
case CMD_DISCONNECT:
WifiNative.disconnectCommand();
transitionTo(mDisconnectingState);