Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for WEP #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 71 additions & 6 deletions src/android/src/com/pylonproducts/wifiwizard/WifiWizard.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,32 @@ else if(action.equals(GET_CONNECTED_SSID)) {
return false;
}

/**
* WEP has two kinds of password, a hex value that specifies the key or
* a character string used to generate the real hex. This checks what kind of
* password has been supplied. The checks correspond to WEP40, WEP104 & WEP232
* @param s
* @return
*/
private static boolean getHexKey(String s) {
if (s == null) {
return false;
}

int len = s.length();
if (len != 10 && len != 26 && len != 58) {
return false;
}

for (int i = 0; i < len; ++i) {
char c = s.charAt(i);
if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
return false;
}
}
return true;
}

/**
* This methods adds a network to the list of available WiFi networks.
* If the network already exists, then it updates it.
Expand Down Expand Up @@ -160,10 +186,49 @@ private boolean addNetwork(CallbackContext callbackContext, JSONArray data) {
return true;
}
else if (authType.equals("WEP")) {
// TODO: connect/configure for WEP
Log.d(TAG, "WEP unsupported.");
callbackContext.error("WEP unsupported");
return false;
// WEP Data format:
// 0: ssid
// 1: auth
// 2: password
String newSSID = data.getString(0);
wifi.SSID = newSSID;
String newPass = data.getString(2);

if (getHexKey(newPass)) {
wifi.wepKeys[0] = newPass;
}
else {
wifi.wepKeys[0] = "\"" + newPass + "\"";
}
wifi.wepTxKeyIndex = 0;

wifi.status = WifiConfiguration.Status.ENABLED;
wifi.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
wifi.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
wifi.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wifi.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
wifi.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
wifi.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
wifi.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wifi.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wifi.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wifi.allowedProtocols.set(WifiConfiguration.Protocol.WPA);


wifi.networkId = ssidToNetworkId(newSSID);

if ( wifi.networkId == -1 ) {
wifiManager.addNetwork(wifi);
callbackContext.success(newSSID + " successfully added.");
}
else {
wifiManager.updateNetwork(wifi);
callbackContext.success(newSSID + " successfully updated.");
}

wifiManager.saveConfiguration();
return true;
}
else if (authType.equals("NONE")) {
String newSSID = data.getString(0);
Expand Down Expand Up @@ -479,10 +544,10 @@ private boolean getConnectedSSID(CallbackContext callbackContext){
}

String ssid = info.getSSID();
if(ssid.isEmpty()) {
if(ssid == null || ssid.isEmpty()) {
ssid = info.getBSSID();
}
if(ssid.isEmpty()){
if(ssid == null || ssid.isEmpty() || ssid == "0x"){
callbackContext.error("SSID is empty");
return false;
}
Expand Down
11 changes: 11 additions & 0 deletions www/WifiWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ var WifiWizard = {
// Other parameters can be added depending on algorithm.
};
}
else if (algorithm === 'WEP') {
wifiConfig.auth = {
algorithm : algorithm,
password : password
// Other parameters can be added depending on algorithm.
};
}
else if (algorithm === 'New network type') {
wifiConfig.auth = {
algorithm : algorithm
Expand Down Expand Up @@ -124,6 +131,10 @@ var WifiWizard = {
networkInformation.push('WPA');
networkInformation.push(wifi.auth.password);
break;
case 'WEP':
networkInformation.push('WEP');
networkInformation.push(wifi.auth.password);
break;
case 'NONE':
networkInformation.push('NONE');
break;
Expand Down