From 5069cc78497209c035a7019b2f407bd1ed57f64a Mon Sep 17 00:00:00 2001 From: Chung-yih Wang Date: Wed, 3 Jun 2009 17:33:47 +0800 Subject: Add the EAP related fields for WiFi configuration. -- added the EAP/802.1X related fields in WifiConfiguration for supporting EAP/802.1X authentication. -- hid the related fields for now. --- services/java/com/android/server/WifiService.java | 77 +++++++++++++++ wifi/java/android/net/wifi/WifiConfiguration.java | 108 ++++++++++++++++++++-- 2 files changed, 179 insertions(+), 6 deletions(-) diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java index 1528ba3..5df88b2 100644 --- a/services/java/com/android/server/WifiService.java +++ b/services/java/com/android/server/WifiService.java @@ -1060,6 +1060,83 @@ public class WifiService extends IWifiManager.Stub { break setVariables; } + if ((config.eap != null) && !WifiNative.setNetworkVariableCommand( + netId, + WifiConfiguration.eapVarName, + config.eap)) { + if (DBG) { + Log.d(TAG, config.SSID + ": failed to set eap: "+ + config.eap); + } + break setVariables; + } + + if ((config.identity != null) && !WifiNative.setNetworkVariableCommand( + netId, + WifiConfiguration.identityVarName, + config.identity)) { + if (DBG) { + Log.d(TAG, config.SSID + ": failed to set identity: "+ + config.identity); + } + break setVariables; + } + + if ((config.anonymousIdentity != null) && !WifiNative.setNetworkVariableCommand( + netId, + WifiConfiguration.anonymousIdentityVarName, + config.anonymousIdentity)) { + if (DBG) { + Log.d(TAG, config.SSID + ": failed to set anonymousIdentity: "+ + config.anonymousIdentity); + } + break setVariables; + } + + if ((config.clientCert != null) && !WifiNative.setNetworkVariableCommand( + netId, + WifiConfiguration.clientCertVarName, + config.clientCert)) { + if (DBG) { + Log.d(TAG, config.SSID + ": failed to set clientCert: "+ + config.clientCert); + } + break setVariables; + } + + if ((config.caCert != null) && !WifiNative.setNetworkVariableCommand( + netId, + WifiConfiguration.caCertVarName, + config.caCert)) { + if (DBG) { + Log.d(TAG, config.SSID + ": failed to set caCert: "+ + config.caCert); + } + break setVariables; + } + + if ((config.privateKey != null) && !WifiNative.setNetworkVariableCommand( + netId, + WifiConfiguration.privateKeyVarName, + config.privateKey)) { + if (DBG) { + Log.d(TAG, config.SSID + ": failed to set privateKey: "+ + config.privateKey); + } + break setVariables; + } + + if ((config.privateKeyPasswd != null) && !WifiNative.setNetworkVariableCommand( + netId, + WifiConfiguration.privateKeyPasswdVarName, + config.privateKeyPasswd)) { + if (DBG) { + Log.d(TAG, config.SSID + ": failed to set privateKeyPasswd: "+ + config.privateKeyPasswd); + } + break setVariables; + } + return netId; } diff --git a/wifi/java/android/net/wifi/WifiConfiguration.java b/wifi/java/android/net/wifi/WifiConfiguration.java index 3bee3b6..1b7c0cd 100644 --- a/wifi/java/android/net/wifi/WifiConfiguration.java +++ b/wifi/java/android/net/wifi/WifiConfiguration.java @@ -42,13 +42,27 @@ public class WifiConfiguration implements Parcelable { public static final String priorityVarName = "priority"; /** {@hide} */ public static final String hiddenSSIDVarName = "scan_ssid"; + /** {@hide} */ + public static final String eapVarName = "eap"; + /** {@hide} */ + public static final String identityVarName = "identity"; + /** {@hide} */ + public static final String anonymousIdentityVarName = "anonymous_identity"; + /** {@hide} */ + public static final String clientCertVarName = "client_cert"; + /** {@hide} */ + public static final String caCertVarName = "ca_cert"; + /** {@hide} */ + public static final String privateKeyVarName = "private_key"; + /** {@hide} */ + public static final String privateKeyPasswdVarName = "private_key_passwd"; /** * Recognized key management schemes. */ public static class KeyMgmt { private KeyMgmt() { } - + /** WPA is not used; plaintext or static WEP could be used. */ public static final int NONE = 0; /** WPA pre-shared key (requires {@code preSharedKey} to be specified). */ @@ -63,7 +77,7 @@ public class WifiConfiguration implements Parcelable { public static final String[] strings = { "NONE", "WPA_PSK", "WPA_EAP", "IEEE8021X" }; } - + /** * Recognized security protocols. */ @@ -112,7 +126,7 @@ public class WifiConfiguration implements Parcelable { public static final int CCMP = 2; public static final String varName = "pairwise"; - + public static final String[] strings = { "NONE", "TKIP", "CCMP" }; } @@ -202,7 +216,7 @@ public class WifiConfiguration implements Parcelable { * string otherwise. */ public String[] wepKeys; - + /** Default WEP key index, ranging from 0 to 3. */ public int wepTxKeyIndex; @@ -249,6 +263,38 @@ public class WifiConfiguration implements Parcelable { */ public BitSet allowedGroupCiphers; + /* The following fields are used for EAP/IEEE8021X authentication */ + + /** + * The eap mode should be PEAP, TLS or TTLS. + * {@hide} + */ + public String eap; + /** + * The identity of the user in string, + * which is used for the authentication. + * {@hide} + */ + public String identity; + /** {@hide} */ + public String anonymousIdentity; + /** The path of the client certificate file. + * {@hide} + */ + public String clientCert; + /** The path of the CA certificate file. + * {@hide} + */ + public String caCert; + /** The path of the private key file. + * {@hide} + */ + public String privateKey; + /** The password of the private key file if encrypted. + * {@hide} + */ + public String privateKeyPasswd; + public WifiConfiguration() { networkId = -1; SSID = null; @@ -263,6 +309,13 @@ public class WifiConfiguration implements Parcelable { wepKeys = new String[4]; for (int i = 0; i < wepKeys.length; i++) wepKeys[i] = null; + eap = null; + identity = null; + anonymousIdentity = null; + clientCert = null; + caCert = null; + privateKey = null; + privateKeyPasswd = null; } public String toString() { @@ -333,10 +386,39 @@ public class WifiConfiguration implements Parcelable { } } } - sbuf.append('\n'); + sbuf.append('\n').append(" PSK: "); if (this.preSharedKey != null) { - sbuf.append(" PSK: ").append('*'); + sbuf.append('*'); + } + sbuf.append('\n').append(" eap: "); + if (this.eap != null) { + sbuf.append(eap); } + sbuf.append('\n').append(" Identity: "); + if (this.identity != null) { + sbuf.append(identity); + } + sbuf.append('\n').append(" AnonymousIdentity: "); + if (this.anonymousIdentity != null) { + sbuf.append(anonymousIdentity); + } + sbuf.append('\n').append(" ClientCert: "); + if (this.clientCert != null) { + sbuf.append(clientCert); + } + sbuf.append('\n').append(" CaCert: "); + if (this.caCert != null) { + sbuf.append(caCert); + } + sbuf.append('\n').append(" PrivateKey: "); + if (this.privateKey != null) { + sbuf.append(privateKey); + } + sbuf.append('\n').append(" PrivateKeyPasswd: "); + if (this.privateKeyPasswd != null) { + sbuf.append(privateKeyPasswd); + } + sbuf.append('\n'); return sbuf.toString(); } @@ -394,6 +476,13 @@ public class WifiConfiguration implements Parcelable { writeBitSet(dest, allowedAuthAlgorithms); writeBitSet(dest, allowedPairwiseCiphers); writeBitSet(dest, allowedGroupCiphers); + dest.writeString(eap); + dest.writeString(identity); + dest.writeString(anonymousIdentity); + dest.writeString(clientCert); + dest.writeString(caCert); + dest.writeString(privateKey); + dest.writeString(privateKeyPasswd); } /** Implement the Parcelable interface {@hide} */ @@ -416,6 +505,13 @@ public class WifiConfiguration implements Parcelable { config.allowedAuthAlgorithms = readBitSet(in); config.allowedPairwiseCiphers = readBitSet(in); config.allowedGroupCiphers = readBitSet(in); + config.eap = in.readString(); + config.identity = in.readString(); + config.anonymousIdentity = in.readString(); + config.clientCert = in.readString(); + config.caCert = in.readString(); + config.privateKey = in.readString(); + config.privateKeyPasswd = in.readString(); return config; } -- cgit v1.1