summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinit Deshapnde <vinitd@google.com>2013-07-12 00:58:07 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-07-12 00:58:07 +0000
commite08842840064801e32f33798c8ed6185c7d7650b (patch)
tree486ba8ebc0fd99c86b5a909491f4ffecd5af3f4a
parent171699fbdd366d7cba6cfd224f988bf0592272b7 (diff)
parent64f0d5ba158e9135bcd48d64a1c0db282a4628ba (diff)
downloadframeworks_base-e08842840064801e32f33798c8ed6185c7d7650b.zip
frameworks_base-e08842840064801e32f33798c8ed6185c7d7650b.tar.gz
frameworks_base-e08842840064801e32f33798c8ed6185c7d7650b.tar.bz2
Merge "Allow enabling TDLS on specific routes"
-rw-r--r--services/java/com/android/server/wifi/WifiService.java93
-rw-r--r--wifi/java/android/net/wifi/IWifiManager.aidl4
-rw-r--r--wifi/java/android/net/wifi/WifiManager.java38
-rw-r--r--wifi/java/android/net/wifi/WifiNative.java7
-rw-r--r--wifi/java/android/net/wifi/WifiStateMachine.java17
5 files changed, 159 insertions, 0 deletions
diff --git a/services/java/com/android/server/wifi/WifiService.java b/services/java/com/android/server/wifi/WifiService.java
index a70978e..6118503 100644
--- a/services/java/com/android/server/wifi/WifiService.java
+++ b/services/java/com/android/server/wifi/WifiService.java
@@ -48,16 +48,23 @@ import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.WorkSource;
+import android.os.AsyncTask;
import android.provider.Settings;
import android.util.Log;
import android.util.Slog;
+import java.io.FileNotFoundException;
+import java.io.BufferedReader;
import java.io.FileDescriptor;
+import java.io.FileReader;
+import java.io.IOException;
import java.io.PrintWriter;
+
import java.net.InetAddress;
import java.net.Inet4Address;
import java.util.ArrayList;
import java.util.List;
+
import java.util.concurrent.atomic.AtomicBoolean;
import com.android.internal.R;
@@ -749,6 +756,92 @@ public final class WifiService extends IWifiManager.Stub {
}
/**
+ * enable TDLS for the local NIC to remote NIC
+ * The APPs don't know the remote MAC address to identify NIC though,
+ * so we need to do additional work to find it from remote IP address
+ */
+
+ class TdlsTaskParams {
+ public String remoteIpAddress;
+ public boolean enable;
+ }
+
+ class TdlsTask extends AsyncTask<TdlsTaskParams, Integer, Integer> {
+ @Override
+ protected Integer doInBackground(TdlsTaskParams... params) {
+
+ // Retrieve parameters for the call
+ TdlsTaskParams param = params[0];
+ String remoteIpAddress = param.remoteIpAddress.trim();
+ boolean enable = param.enable;
+
+ // Get MAC address of Remote IP
+ String macAddress = null;
+
+ BufferedReader reader = null;
+
+ try {
+ reader = new BufferedReader(new FileReader("/proc/net/arp"));
+
+ // Skip over the line bearing colum titles
+ String line = reader.readLine();
+
+ while ((line = reader.readLine()) != null) {
+ String[] tokens = line.split("[ ]+");
+ if (tokens.length < 6) {
+ continue;
+ }
+
+ // ARP column format is
+ // Address HWType HWAddress Flags Mask IFace
+ String ip = tokens[0];
+ String mac = tokens[3];
+
+ if (remoteIpAddress.equals(ip)) {
+ macAddress = mac;
+ break;
+ }
+ }
+
+ if (macAddress == null) {
+ Slog.w(TAG, "Did not find remoteAddress {" + remoteIpAddress + "} in " +
+ "/proc/net/arp");
+ } else {
+ enableTdlsWithMacAddress(macAddress, enable);
+ }
+
+ } catch (FileNotFoundException e) {
+ Slog.e(TAG, "Could not open /proc/net/arp to lookup mac address");
+ } catch (IOException e) {
+ Slog.e(TAG, "Could not read /proc/net/arp to lookup mac address");
+ } finally {
+ try {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ catch (IOException e) {
+ // Do nothing
+ }
+ }
+
+ return 0;
+ }
+ }
+
+ public void enableTdls(String remoteAddress, boolean enable) {
+ TdlsTaskParams params = new TdlsTaskParams();
+ params.remoteIpAddress = remoteAddress;
+ params.enable = enable;
+ new TdlsTask().execute(params);
+ }
+
+
+ public void enableTdlsWithMacAddress(String remoteMacAddress, boolean enable) {
+ mWifiStateMachine.enableTdls(remoteMacAddress, enable);
+ }
+
+ /**
* Get a reference to handler. This is used by a client to establish
* an AsyncChannel communication with WifiService
*/
diff --git a/wifi/java/android/net/wifi/IWifiManager.aidl b/wifi/java/android/net/wifi/IWifiManager.aidl
index 547ae95..6a4bd45 100644
--- a/wifi/java/android/net/wifi/IWifiManager.aidl
+++ b/wifi/java/android/net/wifi/IWifiManager.aidl
@@ -110,5 +110,9 @@ interface IWifiManager
String getConfigFile();
void captivePortalCheckComplete();
+
+ void enableTdls(String remoteIPAddress, boolean enable);
+
+ void enableTdlsWithMacAddress(String remoteMacAddress, boolean enable);
}
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index a3c172a..86ca4a7 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -32,6 +32,7 @@ import android.os.Messenger;
import android.util.Log;
import android.util.SparseArray;
+import java.net.InetAddress;
import java.util.concurrent.CountDownLatch;
import com.android.internal.util.AsyncChannel;
@@ -1132,6 +1133,43 @@ public class WifiManager {
}
}
+
+ /**
+ * Enable TDLS on a specific local route
+ *
+ * This API is used by WiFi display, but eventually it can be made public,
+ * just depends on how popular TDLS gets
+ *
+ * @param remoteIPAddress IP address of the endpoint to setup TDLS with
+ * @param enable true = setup and false = tear down TDLS
+ * @hide
+ */
+ public void enableTdls(InetAddress remoteIPAddress, boolean enable) {
+ try {
+ mService.enableTdls(remoteIPAddress.getHostAddress(), enable);
+ } catch (RemoteException e) {
+ // Just ignore the exception
+ }
+ }
+
+ /**
+ * Enable TDLS on a specific local route
+ *
+ * This API is used by WiFi display, but eventually it can be made public,
+ * just depends on how popular TDLS gets
+ *
+ * @param remoteMacAddress MAC address of the remote endpoint such as 00:00:0c:9f:f2:ab
+ * @param enable true = setup and false = tear down TDLS
+ * @hide
+ */
+ public void enableTdlsWithMacAddress(String remoteMacAddress, boolean enable) {
+ try {
+ mService.enableTdlsWithMacAddress(remoteMacAddress, enable);
+ } catch (RemoteException e) {
+ // Just ignore the exception
+ }
+ }
+
/* TODO: deprecate synchronous API and open up the following API */
private static final int BASE = Protocol.BASE_WIFI_MANAGER;
diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java
index ae41c9a..7ee7085 100644
--- a/wifi/java/android/net/wifi/WifiNative.java
+++ b/wifi/java/android/net/wifi/WifiNative.java
@@ -370,6 +370,13 @@ public class WifiNative {
doBooleanCommand("SCAN_INTERVAL " + scanInterval);
}
+ public void startTdls(String macAddr, boolean enable) {
+ if (enable)
+ doBooleanCommand("TDLS_SETUP " + macAddr);
+ else
+ doBooleanCommand("TDLS_TEARDOWN " + macAddr);
+ }
+
/** Example output:
* RSSI=-65
* LINKSPEED=48
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index 8b9fe55..858fbcc 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -337,6 +337,8 @@ public class WifiStateMachine extends StateMachine {
static final int CMD_SET_FREQUENCY_BAND = BASE + 90;
/* Enable background scan for configured networks */
static final int CMD_ENABLE_BACKGROUND_SCAN = BASE + 91;
+ /* Enable TDLS on a specific MAC address */
+ static final int CMD_ENABLE_TDLS = BASE + 92;
/* Commands from/to the SupplicantStateTracker */
/* Reset the supplicant state tracker */
@@ -1074,6 +1076,14 @@ public class WifiStateMachine extends StateMachine {
}
/**
+ * Enable TDLS for a specific MAC address
+ */
+ public void enableTdls(String remoteMacAddress, boolean enable) {
+ int enabler = enable ? 1 : 0;
+ sendMessage(CMD_ENABLE_TDLS, enabler, 0, remoteMacAddress);
+ }
+
+ /**
* Returns the operational frequency band
*/
public int getFrequencyBand() {
@@ -2605,6 +2615,13 @@ public class WifiStateMachine extends StateMachine {
setSuspendOptimizationsNative(SUSPEND_DUE_TO_HIGH_PERF, true);
}
break;
+ case CMD_ENABLE_TDLS:
+ if (message.obj != null) {
+ String remoteAddress = (String) message.obj;
+ boolean enable = (message.arg1 == 1);
+ mWifiNative.startTdls(remoteAddress, enable);
+ }
+ break;
default:
return NOT_HANDLED;
}