summaryrefslogtreecommitdiff
path: root/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
diff options
context:
space:
mode:
authorGlen Kuhne <kuh@google.com>2017-02-03 13:36:11 -0800
committerRoshan Pius <rpius@google.com>2017-02-09 14:26:39 -0800
commit66e9f4ab597136cbf4accadb8e009fc68ff071a7 (patch)
tree6d08fad8debbc7dcaca5d2b7d551f68225219334 /service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
parent7c2c34319905b2122f124134a9f6f2064f1a2ea5 (diff)
downloadwifi-66e9f4ab597136cbf4accadb8e009fc68ff071a7.tar.gz
ISupplicantStaNetwork save & load WifiConfigs
Methods to set/get network variables from wpa_supplicant to WifiConfiguration & vice versa. TODO: Enterprise config params will be added in a further CL. Test: Unit tests Bug: 33383725 Change-Id: Ib002266a93b4738d0634cd1bbc925b61a86c1df7
Diffstat (limited to 'service/java/com/android/server/wifi/SupplicantStaIfaceHal.java')
-rw-r--r--service/java/com/android/server/wifi/SupplicantStaIfaceHal.java95
1 files changed, 93 insertions, 2 deletions
diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
index 18f850c60..08afb3a55 100644
--- a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
+++ b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
@@ -25,6 +25,7 @@ import android.hardware.wifi.supplicant.V1_0.SupplicantStatus;
import android.hardware.wifi.supplicant.V1_0.SupplicantStatusCode;
import android.hidl.manager.V1_0.IServiceManager;
import android.hidl.manager.V1_0.IServiceNotification;
+import android.net.wifi.WifiConfiguration;
import android.os.HandlerThread;
import android.os.RemoteException;
import android.util.Log;
@@ -33,6 +34,7 @@ import android.util.MutableBoolean;
import libcore.util.HexEncoding;
import java.util.ArrayList;
+//import android.net.wifi.WifiEnterpriseConfig;
/**
* Hal calls for bring up/shut down of the supplicant daemon and for
* sending requests to the supplicant daemon
@@ -216,6 +218,83 @@ public class SupplicantStaIfaceHal {
}
/**
+ * Imitation of WifiSupplicantControl.addNetwork()
+ *
+ * Add a network configuration to wpa_supplicant, via HAL
+ * @param config Config corresponding to the network.
+ * @return SupplicantStaNetwork of the added network in wpa_supplicant.
+ */
+ public SupplicantStaNetworkHal addNetwork(WifiConfiguration config) {
+ logi("addSupplicantStaNetwork via HIDL");
+ if (config == null) {
+ loge("Cannot add NULL network!");
+ return null;
+ }
+ SupplicantStaNetworkHal network = addNetwork();
+ if (network == null) {
+ loge("Failed to add a network!");
+ return null;
+ }
+ if (network.saveWifiConfiguration(config)) {
+ return network;
+ } else {
+ loge("Failed to save variables for: " + config.configKey());
+ return null;
+ }
+ }
+
+ /**
+ * Imitation of WifiSupplicantControl.connectToNetwork
+ */
+ public boolean connectToNetwork(WifiConfiguration configuration, boolean shouldDisconnect) {
+ logd("connectToNetwork " + configuration.configKey()
+ + " (shouldDisconnect " + shouldDisconnect + ")");
+ if (shouldDisconnect && !disconnect()) {
+ loge("Failed to trigger disconnect");
+ return false;
+ }
+ if (!removeAllNetworks()) {
+ loge("Failed to remove existing networks");
+ return false;
+ }
+ SupplicantStaNetworkHal network = addNetwork(configuration);
+ if (network == null) {
+ loge("Failed to add/save network configuration: " + configuration.configKey());
+ return false;
+ }
+ if (!network.getId()) {
+ loge("Failed to get network id for configuration: " + configuration.configKey());
+ return false;
+ }
+ if (!network.select()) {
+ loge("Failed to select network configuration: " + configuration.configKey());
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Remove all networks from supplicant
+ * TODO(b/34454675) use ISupplicantIface.removeAllNetworks when it exists
+ */
+ public boolean removeAllNetworks() {
+ synchronized (mLock) {
+ ArrayList<Integer> networks = listNetworks();
+ if (networks == null) {
+ Log.e(TAG, "removeAllNetworks failed, got null networks");
+ return false;
+ }
+ for (int id : networks) {
+ if (!removeNetwork(id)) {
+ Log.e(TAG, "removeAllNetworks failed to remove network: " + id);
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
* @return returns the name of Iface or null if the call fails
*/
private String getName() {
@@ -301,7 +380,7 @@ public class SupplicantStaIfaceHal {
}
if (statusSuccess.value) {
return new SupplicantStaNetworkHal(ISupplicantStaNetwork.asInterface(
- newNetwork.value.asBinder()));
+ newNetwork.value.asBinder()), mHandlerThread);
} else {
return null;
}
@@ -353,7 +432,7 @@ public class SupplicantStaIfaceHal {
}
if (statusSuccess.value) {
return new SupplicantStaNetworkHal(ISupplicantStaNetwork.asInterface(
- gotNetwork.value.asBinder()));
+ gotNetwork.value.asBinder()), mHandlerThread);
} else {
return null;
}
@@ -770,4 +849,16 @@ public class SupplicantStaIfaceHal {
this.value = value;
}
}
+
+ private void logd(String s) {
+ Log.d(TAG, s);
+ }
+
+ private void logi(String s) {
+ Log.i(TAG, s);
+ }
+
+ private void loge(String s) {
+ Log.e(TAG, s);
+ }
}