summaryrefslogtreecommitdiffstats
path: root/wifi
diff options
context:
space:
mode:
Diffstat (limited to 'wifi')
-rw-r--r--wifi/java/android/net/wifi/WifiConfigStore.java57
-rw-r--r--wifi/java/android/net/wifi/WifiNative.java110
-rw-r--r--wifi/java/android/net/wifi/WifiStateMachine.java2
3 files changed, 132 insertions, 37 deletions
diff --git a/wifi/java/android/net/wifi/WifiConfigStore.java b/wifi/java/android/net/wifi/WifiConfigStore.java
index 3f6fb6e..4baab1f 100644
--- a/wifi/java/android/net/wifi/WifiConfigStore.java
+++ b/wifi/java/android/net/wifi/WifiConfigStore.java
@@ -31,6 +31,7 @@ import android.net.wifi.WifiConfiguration.Status;
import android.net.wifi.NetworkUpdateResult;
import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID;
import android.os.Environment;
+import android.os.FileObserver;
import android.os.Message;
import android.os.Handler;
import android.os.HandlerThread;
@@ -42,12 +43,16 @@ import android.util.Log;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
+import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
+import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.InetAddress;
@@ -111,6 +116,8 @@ class WifiConfigStore {
private static final String TAG = "WifiConfigStore";
private static final boolean DBG = true;
+ private static final String SUPPLICANT_CONFIG_FILE = "/data/misc/wifi/wpa_supplicant.conf";
+
/* configured networks with network id as the key */
private HashMap<Integer, WifiConfiguration> mConfiguredNetworks =
new HashMap<Integer, WifiConfiguration>();
@@ -147,6 +154,7 @@ class WifiConfigStore {
private static final String EOS = "eos";
private final LocalLog mLocalLog;
+ WpaConfigFileObserver mFileObserver;
private WifiNative mWifiNative;
private final KeyStore mKeyStore = KeyStore.getInstance();
@@ -156,11 +164,28 @@ class WifiConfigStore {
mWifiNative = wn;
if (DBG) {
- mLocalLog = new LocalLog(1024); // takes about 64 K
- mWifiNative.setLocalLog(mLocalLog);
+ mLocalLog = mWifiNative.getLocalLog();
+ mFileObserver = new WpaConfigFileObserver();
+ mFileObserver.startWatching();
+ }
+ }
+
+ class WpaConfigFileObserver extends FileObserver {
+
+ public WpaConfigFileObserver() {
+ super(SUPPLICANT_CONFIG_FILE, CLOSE_WRITE);
+ }
+
+ @Override
+ public void onEvent(int event, String path) {
+ if (event == CLOSE_WRITE) {
+ File file = new File(SUPPLICANT_CONFIG_FILE);
+ localLog("wpa_supplicant.conf changed; new size = " + file.length());
+ }
}
}
+
/**
* Fetch the list of configured networks
* and enable all stored networks in supplicant.
@@ -332,7 +357,7 @@ class WifiConfigStore {
if (result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID) {
sendConfiguredNetworksChangedBroadcast(mConfiguredNetworks.get(result.getNetworkId()),
result.isNewNetwork ? WifiManager.CHANGE_REASON_ADDED :
- WifiManager.CHANGE_REASON_CONFIG_CHANGE);
+ WifiManager.CHANGE_REASON_CONFIG_CHANGE);
}
return result.getNetworkId();
}
@@ -636,6 +661,7 @@ class WifiConfigStore {
try {
config.networkId = Integer.parseInt(result[0]);
} catch(NumberFormatException e) {
+ loge("Failed to read network-id '" + result[0] + "'");
continue;
}
if (result.length > 3) {
@@ -663,6 +689,31 @@ class WifiConfigStore {
sendConfiguredNetworksChangedBroadcast();
localLog("loadConfiguredNetworks loaded " + mNetworkIds.size() + " networks");
+
+ if (mNetworkIds.size() == 0) {
+ // no networks? Lets log if the wpa_supplicant.conf file contents
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new FileReader(SUPPLICANT_CONFIG_FILE));
+ localLog("--- Begin wpa_supplicant.conf Contents ---");
+ for (String line = reader.readLine(); line != null; line = reader.readLine()) {
+ localLog(line);
+ }
+ localLog("--- End wpa_supplicant.conf Contents ---");
+ } catch (FileNotFoundException e) {
+ localLog("Could not open " + SUPPLICANT_CONFIG_FILE + ", " + e);
+ } catch (IOException e) {
+ localLog("Could not read " + SUPPLICANT_CONFIG_FILE + ", " + e);
+ } finally {
+ try {
+ if (reader != null) {
+ reader.close();
+ }
+ } catch (IOException e) {
+ // Just ignore the fact that we couldn't close
+ }
+ }
+ }
}
/* Mark all networks except specified netId as disabled */
diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java
index ea259be..f86a51c9 100644
--- a/wifi/java/android/net/wifi/WifiNative.java
+++ b/wifi/java/android/net/wifi/WifiNative.java
@@ -48,6 +48,10 @@ public class WifiNative {
static final int SCAN_WITHOUT_CONNECTION_SETUP = 1;
static final int SCAN_WITH_CONNECTION_SETUP = 2;
+ // Hold this lock before calling supplicant - it is required to
+ // mutually exclude access from Wifi and P2p state machines
+ static final Object mLock = new Object();
+
public final String mInterfaceName;
public final String mInterfacePrefix;
@@ -92,11 +96,17 @@ public class WifiNative {
}
}
+ private static final LocalLog mLocalLog = new LocalLog(1024);
+
+ // hold mLock before accessing mCmdIdLock
+ private int mCmdId;
- private LocalLog mLocalLog;
+ public LocalLog getLocalLog() {
+ return mLocalLog;
+ }
- public void setLocalLog(LocalLog l) {
- mLocalLog = l;
+ private int getNewCmdIdLocked() {
+ return mCmdId++;
}
private void localLog(String s) {
@@ -105,30 +115,59 @@ public class WifiNative {
}
public boolean connectToSupplicant() {
+ // No synchronization necessary .. it is implemented in WifiMonitor
+ localLog(mInterfacePrefix + "connectToSupplicant");
return connectToSupplicantNative();
}
public void closeSupplicantConnection() {
+ localLog(mInterfacePrefix + "closeSupplicantConnection");
closeSupplicantConnectionNative();
}
public String waitForEvent() {
+ // No synchronization necessary .. it is implemented in WifiMonitor
return waitForEventNative();
}
private boolean doBooleanCommand(String command) {
if (DBG) Log.d(mTAG, "doBoolean: " + command);
- return doBooleanCommandNative(mInterfacePrefix + command);
+ synchronized (mLock) {
+ int cmdId = getNewCmdIdLocked();
+ localLog(cmdId + "->" + mInterfacePrefix + command);
+ boolean result = doBooleanCommandNative(mInterfacePrefix + command);
+ localLog(cmdId + "<-" + result);
+ return result;
+ }
}
private int doIntCommand(String command) {
if (DBG) Log.d(mTAG, "doInt: " + command);
- return doIntCommandNative(mInterfacePrefix + command);
+ synchronized (mLock) {
+ int cmdId = getNewCmdIdLocked();
+ localLog(cmdId + "->" + mInterfacePrefix + command);
+ int result = doIntCommandNative(mInterfacePrefix + command);
+ localLog(cmdId + "<-" + result);
+ return result;
+ }
}
private String doStringCommand(String command) {
if (DBG) Log.d(mTAG, "doString: " + command);
- return doStringCommandNative(mInterfacePrefix + command);
+ synchronized (mLock) {
+ int cmdId = getNewCmdIdLocked();
+ localLog(cmdId + "->" + mInterfacePrefix + command);
+ String result = doStringCommandNative(mInterfacePrefix + command);
+ localLog(cmdId + "<-" + result);
+ return result;
+ }
+ }
+
+ private String doStringCommandWithoutLogging(String command) {
+ if (DBG) Log.d(mTAG, "doString: " + command);
+ synchronized (mLock) {
+ return doStringCommandNative(mInterfacePrefix + command);
+ }
}
public boolean ping() {
@@ -157,48 +196,42 @@ public class WifiNative {
}
public String listNetworks() {
- localLog("LIST_NETWORKS");
return doStringCommand("LIST_NETWORKS");
}
public int addNetwork() {
- localLog("ADD_NETWORK");
return doIntCommand("ADD_NETWORK");
}
public boolean setNetworkVariable(int netId, String name, String value) {
if (TextUtils.isEmpty(name) || TextUtils.isEmpty(value)) return false;
- localLog("SET_NETWORK " + netId + " " + name + "=" + value);
return doBooleanCommand("SET_NETWORK " + netId + " " + name + " " + value);
}
public String getNetworkVariable(int netId, String name) {
if (TextUtils.isEmpty(name)) return null;
- return doStringCommand("GET_NETWORK " + netId + " " + name);
+
+ // GET_NETWORK will likely flood the logs ...
+ return doStringCommandWithoutLogging("GET_NETWORK " + netId + " " + name);
}
public boolean removeNetwork(int netId) {
- localLog("REMOVE_NETWORK " + netId);
return doBooleanCommand("REMOVE_NETWORK " + netId);
}
public boolean enableNetwork(int netId, boolean disableOthers) {
if (disableOthers) {
- localLog("SELECT_NETWORK " + netId);
return doBooleanCommand("SELECT_NETWORK " + netId);
} else {
- localLog("ENABLE_NETWORK " + netId);
return doBooleanCommand("ENABLE_NETWORK " + netId);
}
}
public boolean disableNetwork(int netId) {
- localLog("DISABLE_NETWORK " + netId);
return doBooleanCommand("DISABLE_NETWORK " + netId);
}
public boolean reconnect() {
- localLog("RECONNECT");
return doBooleanCommand("RECONNECT");
}
@@ -242,7 +275,7 @@ public class WifiNative {
* MASK=<N> see wpa_supplicant/src/common/wpa_ctrl.h for details
*/
public String scanResults(int sid) {
- return doStringCommand("BSS RANGE=" + sid + "- MASK=0x21987");
+ return doStringCommandWithoutLogging("BSS RANGE=" + sid + "- MASK=0x21987");
}
/**
@@ -401,7 +434,6 @@ public class WifiNative {
}
public boolean saveConfig() {
- localLog("SAVE_CONFIG");
return doBooleanCommand("SAVE_CONFIG");
}
@@ -456,7 +488,7 @@ public class WifiNative {
* FREQUENCY=0
*/
public String signalPoll() {
- return doStringCommand("SIGNAL_POLL");
+ return doStringCommandWithoutLogging("SIGNAL_POLL");
}
/** Example outout:
@@ -480,10 +512,12 @@ public class WifiNative {
}
public boolean startWpsPbc(String iface, String bssid) {
- if (TextUtils.isEmpty(bssid)) {
- return doBooleanCommandNative("IFNAME=" + iface + " WPS_PBC");
- } else {
- return doBooleanCommandNative("IFNAME=" + iface + " WPS_PBC " + bssid);
+ synchronized (mLock) {
+ if (TextUtils.isEmpty(bssid)) {
+ return doBooleanCommandNative("IFNAME=" + iface + " WPS_PBC");
+ } else {
+ return doBooleanCommandNative("IFNAME=" + iface + " WPS_PBC " + bssid);
+ }
}
}
@@ -494,7 +528,9 @@ public class WifiNative {
public boolean startWpsPinKeypad(String iface, String pin) {
if (TextUtils.isEmpty(pin)) return false;
- return doBooleanCommandNative("IFNAME=" + iface + " WPS_PIN any " + pin);
+ synchronized (mLock) {
+ return doBooleanCommandNative("IFNAME=" + iface + " WPS_PIN any " + pin);
+ }
}
@@ -507,10 +543,12 @@ public class WifiNative {
}
public String startWpsPinDisplay(String iface, String bssid) {
- if (TextUtils.isEmpty(bssid)) {
- return doStringCommandNative("IFNAME=" + iface + " WPS_PIN any");
- } else {
- return doStringCommandNative("IFNAME=" + iface + " WPS_PIN " + bssid);
+ synchronized (mLock) {
+ if (TextUtils.isEmpty(bssid)) {
+ return doStringCommandNative("IFNAME=" + iface + " WPS_PIN any");
+ } else {
+ return doStringCommandNative("IFNAME=" + iface + " WPS_PIN " + bssid);
+ }
}
}
@@ -562,7 +600,9 @@ public class WifiNative {
}
public boolean setP2pGroupIdle(String iface, int time) {
- return doBooleanCommandNative("IFNAME=" + iface + " SET p2p_group_idle " + time);
+ synchronized (mLock) {
+ return doBooleanCommandNative("IFNAME=" + iface + " SET p2p_group_idle " + time);
+ }
}
public void setPowerSave(boolean enabled) {
@@ -574,10 +614,12 @@ public class WifiNative {
}
public boolean setP2pPowerSave(String iface, boolean enabled) {
- if (enabled) {
- return doBooleanCommandNative("IFNAME=" + iface + " P2P_SET ps 1");
- } else {
- return doBooleanCommandNative("IFNAME=" + iface + " P2P_SET ps 0");
+ synchronized (mLock) {
+ if (enabled) {
+ return doBooleanCommandNative("IFNAME=" + iface + " P2P_SET ps 1");
+ } else {
+ return doBooleanCommandNative("IFNAME=" + iface + " P2P_SET ps 0");
+ }
}
}
@@ -746,7 +788,9 @@ public class WifiNative {
public boolean p2pGroupRemove(String iface) {
if (TextUtils.isEmpty(iface)) return false;
- return doBooleanCommandNative("IFNAME=" + iface + " P2P_GROUP_REMOVE " + iface);
+ synchronized (mLock) {
+ return doBooleanCommandNative("IFNAME=" + iface + " P2P_GROUP_REMOVE " + iface);
+ }
}
public boolean p2pReject(String deviceAddress) {
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index 85fbdd8..d4e98c5 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -723,7 +723,7 @@ public class WifiStateMachine extends StateMachine {
setInitialState(mInitialState);
- setLogRecSize(300);
+ setLogRecSize(2000);
setLogOnlyTransitions(false);
if (DBG) setDbg(true);