Fix the missing part for reading enterprise fields in wifi configuration

+ refactor the enterprise fields.
This commit is contained in:
Chung-yih Wang
2009-09-16 14:28:42 +08:00
parent 85628188e7
commit 4337476a66
2 changed files with 72 additions and 204 deletions

View File

@@ -665,6 +665,15 @@ public class WifiService extends IWifiManager.Stub {
} }
} }
} }
for (WifiConfiguration.EnterpriseField field :
config.enterpriseFields) {
value = WifiNative.getNetworkVariableCommand(netId,
field.varName());
if (!TextUtils.isEmpty(value)) {
field.setValue(value);
}
}
} }
/** /**
@@ -877,103 +886,20 @@ public class WifiService extends IWifiManager.Stub {
break setVariables; break setVariables;
} }
if ((config.eap != null) && !WifiNative.setNetworkVariableCommand( for (WifiConfiguration.EnterpriseField field
: config.enterpriseFields) {
String varName = field.varName();
String value = field.value();
if ((value != null) && !WifiNative.setNetworkVariableCommand(
netId, netId,
WifiConfiguration.eapVarName, varName,
config.eap)) { value)) {
if (DBG) { if (DBG) {
Log.d(TAG, config.SSID + ": failed to set eap: "+ Log.d(TAG, config.SSID + ": failed to set " + varName +
config.eap); ": " + value);
}
break setVariables;
} }
break setVariables;
}
if ((config.phase2 != null) && !WifiNative.setNetworkVariableCommand(
netId,
WifiConfiguration.phase2VarName,
config.phase2)) {
if (DBG) {
Log.d(TAG, config.SSID + ": failed to set phase2: "+
config.phase2);
}
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.password != null) && !WifiNative.setNetworkVariableCommand(
netId,
WifiConfiguration.passwordVarName,
config.password)) {
if (DBG) {
Log.d(TAG, config.SSID + ": failed to set password: "+
config.password);
}
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; return netId;

View File

@@ -42,24 +42,50 @@ public class WifiConfiguration implements Parcelable {
public static final String priorityVarName = "priority"; public static final String priorityVarName = "priority";
/** {@hide} */ /** {@hide} */
public static final String hiddenSSIDVarName = "scan_ssid"; public static final String hiddenSSIDVarName = "scan_ssid";
public class EnterpriseField {
private String varName;
private String value;
private EnterpriseField(String varName) {
this.varName = varName;
this.value = null;
}
public void setValue(String value) {
this.value = value;
}
public String varName() {
return varName;
}
public String value() {
return value;
}
}
/** {@hide} */ /** {@hide} */
public static final String eapVarName = "eap"; public EnterpriseField eap = new EnterpriseField("eap");
/** {@hide} */ /** {@hide} */
public static final String phase2VarName = "phase2"; public EnterpriseField phase2 = new EnterpriseField("phase2");
/** {@hide} */ /** {@hide} */
public static final String identityVarName = "identity"; public EnterpriseField identity = new EnterpriseField("anonymous_identity");
/** {@hide} */ /** {@hide} */
public static final String anonymousIdentityVarName = "anonymous_identity"; public EnterpriseField anonymous_identity = new EnterpriseField("anonymous_identity");
/** {@hide} */ /** {@hide} */
public static final String passwordVarName = "password"; public EnterpriseField password = new EnterpriseField("password");
/** {@hide} */ /** {@hide} */
public static final String clientCertVarName = "client_cert"; public EnterpriseField client_cert = new EnterpriseField("client_cert");
/** {@hide} */ /** {@hide} */
public static final String caCertVarName = "ca_cert"; public EnterpriseField private_key = new EnterpriseField("private_key");
/** {@hide} */ /** {@hide} */
public static final String privateKeyVarName = "private_key"; public EnterpriseField ca_cert = new EnterpriseField("ca_cert");
/** {@hide} */ /** {@hide} */
public static final String privateKeyPasswdVarName = "private_key_passwd"; public EnterpriseField[] enterpriseFields = {
eap, phase2, identity, anonymous_identity, password, client_cert,
private_key, ca_cert };
/** /**
* Recognized key management schemes. * Recognized key management schemes.
@@ -267,44 +293,6 @@ public class WifiConfiguration implements Parcelable {
*/ */
public BitSet allowedGroupCiphers; 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 phase2 authenication could be PAP, MSCHAP, MSCHAP2, GTC.
* {@hide}
*/
public String phase2;
/**
* The identity of the user in string,
* which is used for the authentication.
* {@hide}
*/
public String identity;
/** {@hide} */
public String anonymousIdentity;
/** {@hide} */
public String password;
/** 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() { public WifiConfiguration() {
networkId = -1; networkId = -1;
@@ -320,15 +308,9 @@ public class WifiConfiguration implements Parcelable {
wepKeys = new String[4]; wepKeys = new String[4];
for (int i = 0; i < wepKeys.length; i++) for (int i = 0; i < wepKeys.length; i++)
wepKeys[i] = null; wepKeys[i] = null;
eap = null; for (EnterpriseField field : enterpriseFields) {
phase2 = null; field.setValue(null);
identity = null; }
anonymousIdentity = null;
password = null;
clientCert = null;
caCert = null;
privateKey = null;
privateKeyPasswd = null;
} }
public String toString() { public String toString() {
@@ -403,41 +385,11 @@ public class WifiConfiguration implements Parcelable {
if (this.preSharedKey != null) { if (this.preSharedKey != null) {
sbuf.append('*'); sbuf.append('*');
} }
sbuf.append('\n').append(" eap: ");
if (this.eap != null) { for (EnterpriseField field : enterpriseFields) {
sbuf.append(eap); sbuf.append('\n').append(" " + field.varName() + ": ");
} String value = field.value();
sbuf.append('\n').append(" phase2: "); if (value != null) sbuf.append(value);
if (this.phase2 != null) {
sbuf.append(phase2);
}
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(" Password: ");
if (this.password != null) {
sbuf.append(password);
}
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'); sbuf.append('\n');
return sbuf.toString(); return sbuf.toString();
@@ -497,15 +449,10 @@ public class WifiConfiguration implements Parcelable {
writeBitSet(dest, allowedAuthAlgorithms); writeBitSet(dest, allowedAuthAlgorithms);
writeBitSet(dest, allowedPairwiseCiphers); writeBitSet(dest, allowedPairwiseCiphers);
writeBitSet(dest, allowedGroupCiphers); writeBitSet(dest, allowedGroupCiphers);
dest.writeString(eap);
dest.writeString(phase2); for (EnterpriseField field : enterpriseFields) {
dest.writeString(identity); dest.writeString(field.value());
dest.writeString(anonymousIdentity); }
dest.writeString(password);
dest.writeString(clientCert);
dest.writeString(caCert);
dest.writeString(privateKey);
dest.writeString(privateKeyPasswd);
} }
/** Implement the Parcelable interface {@hide} */ /** Implement the Parcelable interface {@hide} */
@@ -528,15 +475,10 @@ public class WifiConfiguration implements Parcelable {
config.allowedAuthAlgorithms = readBitSet(in); config.allowedAuthAlgorithms = readBitSet(in);
config.allowedPairwiseCiphers = readBitSet(in); config.allowedPairwiseCiphers = readBitSet(in);
config.allowedGroupCiphers = readBitSet(in); config.allowedGroupCiphers = readBitSet(in);
config.eap = in.readString();
config.phase2 = in.readString(); for (EnterpriseField field : config.enterpriseFields) {
config.identity = in.readString(); field.setValue(in.readString());
config.anonymousIdentity = in.readString(); }
config.password = in.readString();
config.clientCert = in.readString();
config.caCert = in.readString();
config.privateKey = in.readString();
config.privateKeyPasswd = in.readString();
return config; return config;
} }