From 66e9f4ab597136cbf4accadb8e009fc68ff071a7 Mon Sep 17 00:00:00 2001 From: Glen Kuhne Date: Fri, 3 Feb 2017 13:36:11 -0800 Subject: 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 --- .../android/server/wifi/SupplicantStaIfaceHal.java | 95 +++++++++++++++++++++- 1 file changed, 93 insertions(+), 2 deletions(-) (limited to 'service/java/com/android/server/wifi/SupplicantStaIfaceHal.java') 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 @@ -215,6 +217,83 @@ public class SupplicantStaIfaceHal { return ISupplicantStaIface.asInterface(iface.asBinder()); } + /** + * 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 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 */ @@ -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); + } } -- cgit v1.2.3