summaryrefslogtreecommitdiffstats
path: root/wifi
diff options
context:
space:
mode:
authorIrfan Sheriff <isheriff@google.com>2010-09-16 17:53:34 -0700
committerIrfan Sheriff <isheriff@google.com>2010-09-23 09:13:34 -0700
commit5ee89800bee7c6c755778795a536e0e2f12b85ff (patch)
tree383d40f410fe859f218456e8aa006dd090fadc0b /wifi
parente59c69dc3b1f2fa206aa22698c4aa31498438a5e (diff)
downloadframeworks_base-5ee89800bee7c6c755778795a536e0e2f12b85ff.zip
frameworks_base-5ee89800bee7c6c755778795a536e0e2f12b85ff.tar.gz
frameworks_base-5ee89800bee7c6c755778795a536e0e2f12b85ff.tar.bz2
Add Wifi Protected Setup support
Add WPS PBC and WPS pin method support with pin obtained from AP Bug: 2277571 Change-Id: I6ff8e447ab8c5e59456a55152588fd4d6386c610
Diffstat (limited to 'wifi')
-rw-r--r--wifi/java/android/net/wifi/IWifiManager.aidl4
-rw-r--r--wifi/java/android/net/wifi/WifiConfigStore.java75
-rw-r--r--wifi/java/android/net/wifi/WifiConfiguration.java4
-rw-r--r--wifi/java/android/net/wifi/WifiManager.java26
-rw-r--r--wifi/java/android/net/wifi/WifiNative.java4
-rw-r--r--wifi/java/android/net/wifi/WifiStateMachine.java59
6 files changed, 149 insertions, 23 deletions
diff --git a/wifi/java/android/net/wifi/IWifiManager.aidl b/wifi/java/android/net/wifi/IWifiManager.aidl
index e73bca0..f760d27 100644
--- a/wifi/java/android/net/wifi/IWifiManager.aidl
+++ b/wifi/java/android/net/wifi/IWifiManager.aidl
@@ -105,5 +105,9 @@ interface IWifiManager
void saveNetwork(in WifiConfiguration wifiConfig);
void forgetNetwork(int networkId);
+
+ void startWpsPbc(String bssid);
+
+ void startWpsPin(String bssid, int apPin);
}
diff --git a/wifi/java/android/net/wifi/WifiConfigStore.java b/wifi/java/android/net/wifi/WifiConfigStore.java
index dfa9f75..7ea4872 100644
--- a/wifi/java/android/net/wifi/WifiConfigStore.java
+++ b/wifi/java/android/net/wifi/WifiConfigStore.java
@@ -23,6 +23,7 @@ import android.net.DhcpInfo;
import android.net.wifi.WifiConfiguration.IpAssignment;
import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.net.wifi.WifiConfiguration.Status;
+import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;
@@ -95,9 +96,9 @@ class WifiConfigStore {
* and enable all stored networks in supplicant.
*/
static void initialize(Context context) {
- Log.d(TAG, "Updating config and enabling all networks");
+ Log.d(TAG, "Loading config and enabling all networks");
sContext = context;
- updateConfiguredNetworks();
+ loadConfiguredNetworks();
enableAllNetworks();
}
@@ -150,7 +151,7 @@ class WifiConfigStore {
static void selectNetwork(WifiConfiguration config) {
if (config != null) {
int netId = addOrUpdateNetworkNative(config);
- if (netId != -1) {
+ if (netId != INVALID_NETWORK_ID) {
selectNetwork(netId);
} else {
Log.e(TAG, "Failed to update network " + config);
@@ -174,7 +175,7 @@ class WifiConfigStore {
if (sLastPriority == -1 || sLastPriority > 1000000) {
synchronized (sConfiguredNetworks) {
for(WifiConfiguration config : sConfiguredNetworks.values()) {
- if (config.networkId != -1) {
+ if (config.networkId != INVALID_NETWORK_ID) {
config.priority = 0;
addOrUpdateNetworkNative(config);
}
@@ -204,10 +205,10 @@ class WifiConfigStore {
* @param config WifiConfiguration to be saved
*/
static void saveNetwork(WifiConfiguration config) {
- boolean newNetwork = (config.networkId == -1);
+ boolean newNetwork = (config.networkId == INVALID_NETWORK_ID);
int netId = addOrUpdateNetworkNative(config);
/* enable a new network */
- if (newNetwork && netId >= 0) {
+ if (newNetwork && netId != INVALID_NETWORK_ID) {
WifiNative.enableNetworkCommand(netId, false);
synchronized (sConfiguredNetworks) {
sConfiguredNetworks.get(netId).status = Status.ENABLED;
@@ -288,13 +289,7 @@ class WifiConfigStore {
}
if (disableOthers) {
- synchronized (sConfiguredNetworks) {
- for(WifiConfiguration config : sConfiguredNetworks.values()) {
- if(config != null && config.networkId != netId) {
- config.status = Status.DISABLED;
- }
- }
- }
+ markAllNetworksDisabledExcept(netId);
}
return ret;
}
@@ -321,6 +316,32 @@ class WifiConfigStore {
}
/**
+ * Start WPS pin method configuration
+ */
+ static boolean startWpsPin(String bssid, int apPin) {
+ if (WifiNative.startWpsPinCommand(bssid, apPin)) {
+ /* WPS leaves all networks disabled */
+ markAllNetworksDisabled();
+ return true;
+ }
+ Log.e(TAG, "Failed to start WPS pin method configuration");
+ return false;
+ }
+
+ /**
+ * Start WPS push button configuration
+ */
+ static boolean startWpsPbc(String bssid) {
+ if (WifiNative.startWpsPbcCommand(bssid)) {
+ /* WPS leaves all networks disabled */
+ markAllNetworksDisabled();
+ return true;
+ }
+ Log.e(TAG, "Failed to start WPS push button configuration");
+ return false;
+ }
+
+ /**
* Fetch the IP configuration for a given network id
*/
static DhcpInfo getIpConfiguration(int netId) {
@@ -350,7 +371,7 @@ class WifiConfigStore {
sContext.sendBroadcast(intent);
}
- private static void updateConfiguredNetworks() {
+ static void loadConfiguredNetworks() {
String listStr = WifiNative.listNetworksCommand();
sLastPriority = 0;
@@ -391,6 +412,22 @@ class WifiConfigStore {
}
}
readIpConfigurations();
+ sendConfigChangeBroadcast();
+ }
+
+ /* Mark all networks except specified netId as disabled */
+ private static void markAllNetworksDisabledExcept(int netId) {
+ synchronized (sConfiguredNetworks) {
+ for(WifiConfiguration config : sConfiguredNetworks.values()) {
+ if(config != null && config.networkId != netId) {
+ config.status = Status.DISABLED;
+ }
+ }
+ }
+ }
+
+ private static void markAllNetworksDisabled() {
+ markAllNetworksDisabledExcept(INVALID_NETWORK_ID);
}
private static void writeIpConfigurations() {
@@ -513,20 +550,20 @@ class WifiConfigStore {
private static int addOrUpdateNetworkNative(WifiConfiguration config) {
/*
- * If the supplied networkId is -1, we create a new empty
+ * If the supplied networkId is INVALID_NETWORK_ID, we create a new empty
* network configuration. Otherwise, the networkId should
* refer to an existing configuration.
*/
int netId = config.networkId;
boolean updateFailed = true;
- boolean newNetwork = netId == -1;
- // networkId of -1 means we want to create a new network
+ boolean newNetwork = (netId == INVALID_NETWORK_ID);
+ // networkId of INVALID_NETWORK_ID means we want to create a new network
if (newNetwork) {
netId = WifiNative.addNetworkCommand();
if (netId < 0) {
Log.e(TAG, "Failed to add a network!");
- return -1;
+ return INVALID_NETWORK_ID;
}
}
@@ -700,7 +737,7 @@ class WifiConfigStore {
"Failed to set a network variable, removed network: "
+ netId);
}
- return -1;
+ return INVALID_NETWORK_ID;
}
/* An update of the network variables requires reading them
diff --git a/wifi/java/android/net/wifi/WifiConfiguration.java b/wifi/java/android/net/wifi/WifiConfiguration.java
index 8971bdd..57e9bad 100644
--- a/wifi/java/android/net/wifi/WifiConfiguration.java
+++ b/wifi/java/android/net/wifi/WifiConfiguration.java
@@ -43,6 +43,8 @@ public class WifiConfiguration implements Parcelable {
public static final String priorityVarName = "priority";
/** {@hide} */
public static final String hiddenSSIDVarName = "scan_ssid";
+ /** {@hide} */
+ public static final int INVALID_NETWORK_ID = -1;
/** {@hide} */
public class EnterpriseField {
@@ -313,7 +315,7 @@ public class WifiConfiguration implements Parcelable {
public DhcpInfo ipConfig;
public WifiConfiguration() {
- networkId = -1;
+ networkId = INVALID_NETWORK_ID;
SSID = null;
BSSID = null;
priority = 0;
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index 4435110..0b3a782 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -1037,6 +1037,32 @@ public class WifiManager {
}
/**
+ * Start Wi-fi protected setup push button Configuration
+ *
+ * @param bssid BSSID of the access point
+ * @hide
+ */
+ public void startWpsPbc(String bssid) {
+ try {
+ mService.startWpsPbc(bssid);
+ } catch (RemoteException e) { }
+ }
+
+ /**
+ * Start Wi-fi Protected Setup pin method configuration
+ *
+ * @param bssid BSSID of the access point
+ * @param apPin PIN issued by the access point
+ *
+ * @hide
+ */
+ public void startWpsPin(String bssid, int apPin) {
+ try {
+ mService.startWpsPin(bssid, apPin);
+ } catch (RemoteException e) { }
+ }
+
+ /**
* Allows an application to keep the Wi-Fi radio awake.
* Normally the Wi-Fi radio may turn off when the user has not used the device in a while.
* Acquiring a WifiLock will keep the radio on until the lock is released. Multiple
diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java
index 862a61b..1251a25 100644
--- a/wifi/java/android/net/wifi/WifiNative.java
+++ b/wifi/java/android/net/wifi/WifiNative.java
@@ -151,6 +151,10 @@ public class WifiNative {
public native static boolean clearBlacklistCommand();
+ public native static boolean startWpsPbcCommand(String bssid);
+
+ public native static boolean startWpsPinCommand(String bssid, int apPin);
+
public native static boolean doDhcpRequest(DhcpInfo results);
public native static String getDhcpError();
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index 6fe7529..7e26028 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -151,7 +151,9 @@ public class WifiStateMachine extends HierarchicalStateMachine {
/* Connection to a specific network involves disabling all networks,
* this flag tracks if networks need to be re-enabled */
private boolean mEnableAllNetworks = false;
-
+ /* Track if WPS was started since we need to re-enable networks
+ * and load configuration afterwards */
+ private boolean mWpsStarted = false;
// Event log tags (must be in sync with event-log-tags)
private static final int EVENTLOG_WIFI_STATE_CHANGED = 50021;
@@ -299,7 +301,8 @@ public class WifiStateMachine extends HierarchicalStateMachine {
* supplicant config.
*/
private static final int CMD_FORGET_NETWORK = 92;
-
+ /* Start Wi-Fi protected setup */
+ private static final int CMD_START_WPS = 93;
/**
@@ -406,7 +409,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
* Keep track of whether WIFI is running.
*/
private boolean mIsRunning = false;
-
+
/**
* Keep track of whether we last told the battery stats we had started.
*/
@@ -765,6 +768,14 @@ public class WifiStateMachine extends HierarchicalStateMachine {
sendMessage(obtainMessage(CMD_FORGET_NETWORK, netId, 0));
}
+ public void startWpsPbc(String bssid) {
+ sendMessage(obtainMessage(CMD_START_WPS, bssid));
+ }
+
+ public void startWpsPin(String bssid, int apPin) {
+ sendMessage(obtainMessage(CMD_START_WPS, apPin, 0, bssid));
+ }
+
public void enableRssiPolling(boolean enabled) {
sendMessage(obtainMessage(CMD_ENABLE_RSSI_POLL, enabled ? 1 : 0, 0));
}
@@ -1597,6 +1608,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
case CMD_CONNECT_NETWORK:
case CMD_SAVE_NETWORK:
case CMD_FORGET_NETWORK:
+ case CMD_START_WPS:
break;
default:
Log.e(TAG, "Error! unhandled message" + message);
@@ -2355,6 +2367,33 @@ public class WifiStateMachine extends HierarchicalStateMachine {
/* Expect a disconnection from the old connection */
transitionTo(mDisconnectingState);
break;
+ case CMD_START_WPS:
+ String bssid = (String) message.obj;
+ int apPin = message.arg1;
+ boolean success;
+ if (apPin != 0) {
+ /* WPS pin method configuration */
+ success = WifiConfigStore.startWpsPin(bssid, apPin);
+ } else {
+ /* WPS push button configuration */
+ success = WifiConfigStore.startWpsPbc(bssid);
+ }
+ /* During WPS setup, all other networks are disabled. After
+ * a successful connect a new config is created in the supplicant.
+ *
+ * We need to enable all networks after a successful connection
+ * or when supplicant goes inactive due to failure. Enabling all
+ * networks after a disconnect is observed as done with connectNetwork
+ * does not lead to a successful WPS setup.
+ *
+ * Upon success, the configuration list needs to be reloaded
+ */
+ if (success) {
+ mWpsStarted = true;
+ /* Expect a disconnection from the old connection */
+ transitionTo(mDisconnectingState);
+ }
+ break;
case SCAN_RESULTS_EVENT:
/* Set the scan setting back to "connect" mode */
WifiNative.setScanResultHandlingCommand(CONNECT_MODE);
@@ -2581,6 +2620,12 @@ public class WifiStateMachine extends HierarchicalStateMachine {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
+ /* A successful WPS connection */
+ if (mWpsStarted) {
+ WifiConfigStore.enableAllNetworks();
+ WifiConfigStore.loadConfiguredNetworks();
+ mWpsStarted = false;
+ }
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
}
@Override
@@ -2911,6 +2956,14 @@ public class WifiStateMachine extends HierarchicalStateMachine {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
+
+ /* A failed WPS connection */
+ if (mWpsStarted) {
+ Log.e(TAG, "WPS set up failed, enabling other networks");
+ WifiConfigStore.enableAllNetworks();
+ mWpsStarted = false;
+ }
+
Message message = getCurrentMessage();
StateChangeResult stateChangeResult = (StateChangeResult) message.obj;