From ee441073b432aa73b98ccd84de279b5b9d18a685 Mon Sep 17 00:00:00 2001 From: digaus Date: Wed, 17 Apr 2019 12:25:03 +0200 Subject: [PATCH 01/29] Update WifiWizard2.java --- src/android/wifiwizard2/WifiWizard2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/wifiwizard2/WifiWizard2.java b/src/android/wifiwizard2/WifiWizard2.java index 771059f..b731c61 100644 --- a/src/android/wifiwizard2/WifiWizard2.java +++ b/src/android/wifiwizard2/WifiWizard2.java @@ -1214,7 +1214,7 @@ private int ssidToNetworkId(String ssid) { // For each network in the list, compare the SSID with the given one for (WifiConfiguration test : currentNetworks) { if (test.SSID != null && test.SSID.equals(ssid)) { - networkId = test.networkId; + // networkId = test.networkId; } } From 68a21a1cc4c59c2320a15b448b3fd54f18de6094 Mon Sep 17 00:00:00 2001 From: digaus Date: Wed, 17 Apr 2019 12:35:25 +0200 Subject: [PATCH 02/29] Update WifiWizard2.java --- src/android/wifiwizard2/WifiWizard2.java | 43 ++++++++++++++++-------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/android/wifiwizard2/WifiWizard2.java b/src/android/wifiwizard2/WifiWizard2.java index b731c61..7f21647 100644 --- a/src/android/wifiwizard2/WifiWizard2.java +++ b/src/android/wifiwizard2/WifiWizard2.java @@ -393,7 +393,7 @@ private boolean add(CallbackContext callbackContext, JSONArray data) { wifi.allowedProtocols.set(WifiConfiguration.Protocol.RSN); wifi.allowedProtocols.set(WifiConfiguration.Protocol.WPA); - wifi.networkId = ssidToNetworkId(newSSID); + wifi.networkId = ssidToNetworkId(newSSID, authType); } else if (authType.equals("WEP")) { /** @@ -425,7 +425,7 @@ private boolean add(CallbackContext callbackContext, JSONArray data) { wifi.allowedProtocols.set(WifiConfiguration.Protocol.RSN); wifi.allowedProtocols.set(WifiConfiguration.Protocol.WPA); - wifi.networkId = ssidToNetworkId(newSSID); + wifi.networkId = ssidToNetworkId(newSSID, authType); } else if (authType.equals("NONE")) { /** @@ -437,7 +437,7 @@ private boolean add(CallbackContext callbackContext, JSONArray data) { */ wifi.SSID = newSSID; wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); - wifi.networkId = ssidToNetworkId(newSSID); + wifi.networkId = ssidToNetworkId(newSSID, authType); } else { @@ -518,7 +518,7 @@ private void enable(CallbackContext callbackContext, JSONArray data) { return; } - int networkIdToEnable = ssidToNetworkId(ssidToEnable); + int networkIdToEnable = ssidToNetworkId(ssidToEnable, ""); try { @@ -585,7 +585,7 @@ private boolean disable(CallbackContext callbackContext, JSONArray data) { return false; } - int networkIdToDisconnect = ssidToNetworkId(ssidToDisable); + int networkIdToDisconnect = ssidToNetworkId(ssidToDisable, ""); try { @@ -632,7 +632,7 @@ private boolean remove(CallbackContext callbackContext, JSONArray data) { try { String ssidToDisconnect = data.getString(0); - int networkIdToRemove = ssidToNetworkId(ssidToDisconnect); + int networkIdToRemove = ssidToNetworkId(ssidToDisconnect, ""); if (networkIdToRemove > -1) { @@ -690,7 +690,7 @@ private void connect(CallbackContext callbackContext, JSONArray data) { return; } - int networkIdToConnect = ssidToNetworkId(ssidToConnect); + int networkIdToConnect = ssidToNetworkId(ssidToConnect, ""); if (networkIdToConnect > -1) { // We disable the network before connecting, because if this was the last connection before @@ -813,7 +813,7 @@ private boolean disconnectNetwork(CallbackContext callbackContext, JSONArray dat return false; } - int networkIdToDisconnect = ssidToNetworkId(ssidToDisconnect); + int networkIdToDisconnect = ssidToNetworkId(ssidToDisconnect, ""); if (networkIdToDisconnect > 0) { @@ -1089,7 +1089,7 @@ private boolean getSSIDNetworkID(CallbackContext callbackContext, JSONArray data return false; } - int networkIdToConnect = ssidToNetworkId(ssidToGetNetworkID); + int networkIdToConnect = ssidToNetworkId(ssidToGetNetworkID, ""); callbackContext.success(networkIdToConnect); return true; @@ -1198,7 +1198,7 @@ private boolean isWifiEnabled(CallbackContext callbackContext) { * This method takes a given String, searches the current list of configured WiFi networks, and * returns the networkId for the network if the SSID matches. If not, it returns -1. */ - private int ssidToNetworkId(String ssid) { + private int ssidToNetworkId(String ssid, String security) { try { @@ -1213,8 +1213,10 @@ private int ssidToNetworkId(String ssid) { // For each network in the list, compare the SSID with the given one for (WifiConfiguration test : currentNetworks) { - if (test.SSID != null && test.SSID.equals(ssid)) { - // networkId = test.networkId; + String testSecurity = this.getSecurity(test); + if (test.SSID != null && test.SSID.equals(ssid) && (testSecurity.equals(security) || security.length() == 0)) { + networkId = test.networkId; + } } @@ -1222,7 +1224,7 @@ private int ssidToNetworkId(String ssid) { } } - + /** * This method enables or disables the wifi */ @@ -1348,7 +1350,20 @@ private String formatIP(int ip) { (ip >> 24 & 0xff) ); } - + private static String getSecurity(final WifiConfiguration network) { + if(network.allowedGroupCiphers.get(GroupCipher.CCMP)) { + return "WPA2"; + } + else if(network.allowedGroupCiphers.get(GroupCipher.TKIP)) { + return "WPA"; + } + else if(network.allowedGroupCiphers.get(GroupCipher.WEP40) + || network.allowedGroupCiphers.get(GroupCipher.WEP104)) { + return "WEP"; + } + else return "NONE"; + } + /** * Get IPv4 Subnet * @param inetAddress From 660df8223fd8d327f571dd389e2390dab148ee74 Mon Sep 17 00:00:00 2001 From: digaus Date: Wed, 17 Apr 2019 13:11:56 +0200 Subject: [PATCH 03/29] Update WifiWizard2.java --- src/android/wifiwizard2/WifiWizard2.java | 63 ++++++++++++------------ 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/src/android/wifiwizard2/WifiWizard2.java b/src/android/wifiwizard2/WifiWizard2.java index 7f21647..9792d62 100644 --- a/src/android/wifiwizard2/WifiWizard2.java +++ b/src/android/wifiwizard2/WifiWizard2.java @@ -111,6 +111,9 @@ public class WifiWizard2 extends CordovaPlugin { // Store AP, previous, and desired wifi info private AP previous, desired; + private int networkId = -1; + private String ssid; + private final BroadcastReceiver networkChangedReceiver = new NetworkChangedReceiver(); private static final IntentFilter NETWORK_STATE_CHANGED_FILTER = new IntentFilter(); @@ -393,7 +396,7 @@ private boolean add(CallbackContext callbackContext, JSONArray data) { wifi.allowedProtocols.set(WifiConfiguration.Protocol.RSN); wifi.allowedProtocols.set(WifiConfiguration.Protocol.WPA); - wifi.networkId = ssidToNetworkId(newSSID, authType); + wifi.networkId = -1; } else if (authType.equals("WEP")) { /** @@ -425,7 +428,7 @@ private boolean add(CallbackContext callbackContext, JSONArray data) { wifi.allowedProtocols.set(WifiConfiguration.Protocol.RSN); wifi.allowedProtocols.set(WifiConfiguration.Protocol.WPA); - wifi.networkId = ssidToNetworkId(newSSID, authType); + wifi.networkId = -1; } else if (authType.equals("NONE")) { /** @@ -437,7 +440,7 @@ private boolean add(CallbackContext callbackContext, JSONArray data) { */ wifi.SSID = newSSID; wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); - wifi.networkId = ssidToNetworkId(newSSID, authType); + wifi.networkId = -1; } else { @@ -446,20 +449,28 @@ private boolean add(CallbackContext callbackContext, JSONArray data) { return false; } - // Set network to highest priority (deprecated in API >= 26) if( API_VERSION < 26 ){ wifi.priority = getMaxWifiPriority(wifiManager) + 1; } + int networkId = ssidToNetworkId(newSSID); // After processing authentication types, add or update network if (wifi.networkId == -1) { // -1 means SSID configuration does not exist yet int newNetId = wifiManager.addNetwork(wifi); if( newNetId > -1 ){ + this.networkId = newNetId; callbackContext.success( newNetId ); } else { callbackContext.error( "ERROR_ADDING_NETWORK" ); + wifi.networkId = networkId; + int updatedNetID = wifiManager.updateNetwork(wifi); + if( updatedNetID > -1 ){ + callbackContext.success( updatedNetID ); + } else { + callbackContext.error( "ERROR_UPDATING_NETWORK" ); + } } } else { @@ -517,9 +528,12 @@ private void enable(CallbackContext callbackContext, JSONArray data) { Log.d(TAG, e.getMessage()); return; } - - int networkIdToEnable = ssidToNetworkId(ssidToEnable, ""); - + + int networkIdToEnable = ssidToNetworkId(ssidToEnable); + if (this.networkId > -1 && ssidToEnable.equals(this.ssid)) { + networkIdToEnable = this.networkId; + callbackContext.success("NETWORKID FOUND"); + } try { if (networkIdToEnable > -1) { @@ -585,7 +599,7 @@ private boolean disable(CallbackContext callbackContext, JSONArray data) { return false; } - int networkIdToDisconnect = ssidToNetworkId(ssidToDisable, ""); + int networkIdToDisconnect = ssidToNetworkId(ssidToDisable); try { @@ -632,7 +646,7 @@ private boolean remove(CallbackContext callbackContext, JSONArray data) { try { String ssidToDisconnect = data.getString(0); - int networkIdToRemove = ssidToNetworkId(ssidToDisconnect, ""); + int networkIdToRemove = ssidToNetworkId(ssidToDisconnect); if (networkIdToRemove > -1) { @@ -690,7 +704,7 @@ private void connect(CallbackContext callbackContext, JSONArray data) { return; } - int networkIdToConnect = ssidToNetworkId(ssidToConnect, ""); + int networkIdToConnect = ssidToNetworkId(ssidToConnect); if (networkIdToConnect > -1) { // We disable the network before connecting, because if this was the last connection before @@ -813,7 +827,7 @@ private boolean disconnectNetwork(CallbackContext callbackContext, JSONArray dat return false; } - int networkIdToDisconnect = ssidToNetworkId(ssidToDisconnect, ""); + int networkIdToDisconnect = ssidToNetworkId(ssidToDisconnect); if (networkIdToDisconnect > 0) { @@ -1089,7 +1103,7 @@ private boolean getSSIDNetworkID(CallbackContext callbackContext, JSONArray data return false; } - int networkIdToConnect = ssidToNetworkId(ssidToGetNetworkID, ""); + int networkIdToConnect = ssidToNetworkId(ssidToGetNetworkID); callbackContext.success(networkIdToConnect); return true; @@ -1198,7 +1212,7 @@ private boolean isWifiEnabled(CallbackContext callbackContext) { * This method takes a given String, searches the current list of configured WiFi networks, and * returns the networkId for the network if the SSID matches. If not, it returns -1. */ - private int ssidToNetworkId(String ssid, String security) { + private int ssidToNetworkId(String ssid) { try { @@ -1213,10 +1227,8 @@ private int ssidToNetworkId(String ssid, String security) { // For each network in the list, compare the SSID with the given one for (WifiConfiguration test : currentNetworks) { - String testSecurity = this.getSecurity(test); - if (test.SSID != null && test.SSID.equals(ssid) && (testSecurity.equals(security) || security.length() == 0)) { - networkId = test.networkId; - + if (test.SSID != null && test.SSID.equals(ssid)) { + networkId = test.networkId; } } @@ -1224,7 +1236,7 @@ private int ssidToNetworkId(String ssid, String security) { } } - + /** * This method enables or disables the wifi */ @@ -1350,20 +1362,7 @@ private String formatIP(int ip) { (ip >> 24 & 0xff) ); } - private static String getSecurity(final WifiConfiguration network) { - if(network.allowedGroupCiphers.get(GroupCipher.CCMP)) { - return "WPA2"; - } - else if(network.allowedGroupCiphers.get(GroupCipher.TKIP)) { - return "WPA"; - } - else if(network.allowedGroupCiphers.get(GroupCipher.WEP40) - || network.allowedGroupCiphers.get(GroupCipher.WEP104)) { - return "WEP"; - } - else return "NONE"; - } - + /** * Get IPv4 Subnet * @param inetAddress From 4c42cc079c65f2cfa4e1a1e72ee868562f70433e Mon Sep 17 00:00:00 2001 From: digaus Date: Wed, 17 Apr 2019 13:24:04 +0200 Subject: [PATCH 04/29] Update WifiWizard2.js --- www/WifiWizard2.js | 1 + 1 file changed, 1 insertion(+) diff --git a/www/WifiWizard2.js b/www/WifiWizard2.js index e6460ce..85250f8 100644 --- a/www/WifiWizard2.js +++ b/www/WifiWizard2.js @@ -562,6 +562,7 @@ var WifiWizard2 = { wifiConfig.auth = { algorithm: "NONE" }; + wifiConfig.SSID = wifiConfig.SSID + "NONE"; } else if (algorithm === "WPA") { wifiConfig.auth = { algorithm: algorithm, From 31339e82760a00eedc5c9508f82fafa6e7eaa01e Mon Sep 17 00:00:00 2001 From: digaus Date: Wed, 17 Apr 2019 13:32:39 +0200 Subject: [PATCH 05/29] Update WifiWizard2.java --- src/android/wifiwizard2/WifiWizard2.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/android/wifiwizard2/WifiWizard2.java b/src/android/wifiwizard2/WifiWizard2.java index 9792d62..a529179 100644 --- a/src/android/wifiwizard2/WifiWizard2.java +++ b/src/android/wifiwizard2/WifiWizard2.java @@ -457,12 +457,13 @@ private boolean add(CallbackContext callbackContext, JSONArray data) { // After processing authentication types, add or update network if (wifi.networkId == -1) { // -1 means SSID configuration does not exist yet - + Log.d(TAG, "Add Network" + newSSID); int newNetId = wifiManager.addNetwork(wifi); if( newNetId > -1 ){ this.networkId = newNetId; callbackContext.success( newNetId ); } else { + Log.d(TAG, "Add Network Error" + newSSID); callbackContext.error( "ERROR_ADDING_NETWORK" ); wifi.networkId = networkId; int updatedNetID = wifiManager.updateNetwork(wifi); From 20d605edc3621a78ef375e41a3d6066d58f4c74f Mon Sep 17 00:00:00 2001 From: digaus Date: Wed, 17 Apr 2019 15:06:19 +0200 Subject: [PATCH 06/29] Update WifiWizard2.java --- src/android/wifiwizard2/WifiWizard2.java | 99 +++++++++++++++--------- 1 file changed, 63 insertions(+), 36 deletions(-) diff --git a/src/android/wifiwizard2/WifiWizard2.java b/src/android/wifiwizard2/WifiWizard2.java index a529179..22d6e63 100644 --- a/src/android/wifiwizard2/WifiWizard2.java +++ b/src/android/wifiwizard2/WifiWizard2.java @@ -111,9 +111,6 @@ public class WifiWizard2 extends CordovaPlugin { // Store AP, previous, and desired wifi info private AP previous, desired; - private int networkId = -1; - private String ssid; - private final BroadcastReceiver networkChangedReceiver = new NetworkChangedReceiver(); private static final IntentFilter NETWORK_STATE_CHANGED_FILTER = new IntentFilter(); @@ -374,6 +371,8 @@ private boolean add(CallbackContext callbackContext, JSONArray data) { String newPass = data.getString(2); boolean isHiddenSSID = data.getBoolean(3); + Log.d(TAG, "SET SSID: " + newSSID); + wifi.hiddenSSID = isHiddenSSID; if (authType.equals("WPA") || authType.equals("WPA2")) { @@ -396,7 +395,7 @@ private boolean add(CallbackContext callbackContext, JSONArray data) { wifi.allowedProtocols.set(WifiConfiguration.Protocol.RSN); wifi.allowedProtocols.set(WifiConfiguration.Protocol.WPA); - wifi.networkId = -1; + wifi.networkId = ssidToNetworkId(newSSID, authType); } else if (authType.equals("WEP")) { /** @@ -428,7 +427,7 @@ private boolean add(CallbackContext callbackContext, JSONArray data) { wifi.allowedProtocols.set(WifiConfiguration.Protocol.RSN); wifi.allowedProtocols.set(WifiConfiguration.Protocol.WPA); - wifi.networkId = -1; + wifi.networkId = ssidToNetworkId(newSSID, authType); } else if (authType.equals("NONE")) { /** @@ -440,7 +439,7 @@ private boolean add(CallbackContext callbackContext, JSONArray data) { */ wifi.SSID = newSSID; wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); - wifi.networkId = -1; + wifi.networkId = ssidToNetworkId(newSSID, authType); } else { @@ -453,25 +452,15 @@ private boolean add(CallbackContext callbackContext, JSONArray data) { if( API_VERSION < 26 ){ wifi.priority = getMaxWifiPriority(wifiManager) + 1; } - int networkId = ssidToNetworkId(newSSID); // After processing authentication types, add or update network if (wifi.networkId == -1) { // -1 means SSID configuration does not exist yet - Log.d(TAG, "Add Network" + newSSID); + int newNetId = wifiManager.addNetwork(wifi); if( newNetId > -1 ){ - this.networkId = newNetId; callbackContext.success( newNetId ); } else { - Log.d(TAG, "Add Network Error" + newSSID); callbackContext.error( "ERROR_ADDING_NETWORK" ); - wifi.networkId = networkId; - int updatedNetID = wifiManager.updateNetwork(wifi); - if( updatedNetID > -1 ){ - callbackContext.success( updatedNetID ); - } else { - callbackContext.error( "ERROR_UPDATING_NETWORK" ); - } } } else { @@ -519,22 +508,21 @@ private void enable(CallbackContext callbackContext, JSONArray data) { String ssidToEnable = ""; String bindAll = "false"; String waitForConnection = "false"; + String authType = ""; try { ssidToEnable = data.getString(0); bindAll = data.getString(1); waitForConnection = data.getString(2); + authType = data.getString(3); } catch (Exception e) { callbackContext.error(e.getMessage()); Log.d(TAG, e.getMessage()); return; } - - int networkIdToEnable = ssidToNetworkId(ssidToEnable); - if (this.networkId > -1 && ssidToEnable.equals(this.ssid)) { - networkIdToEnable = this.networkId; - callbackContext.success("NETWORKID FOUND"); - } + + int networkIdToEnable = ssidToNetworkId(ssidToEnable, authType); + try { if (networkIdToEnable > -1) { @@ -646,8 +634,9 @@ private boolean remove(CallbackContext callbackContext, JSONArray data) { // TODO: Verify the type of data! try { String ssidToDisconnect = data.getString(0); + String authType = data.getString(1); - int networkIdToRemove = ssidToNetworkId(ssidToDisconnect); + int networkIdToRemove = ssidToNetworkId(ssidToDisconnect, authType); if (networkIdToRemove > -1) { @@ -695,17 +684,19 @@ private void connect(CallbackContext callbackContext, JSONArray data) { String ssidToConnect = ""; String bindAll = "false"; - + String authType = ""; try { ssidToConnect = data.getString(0); bindAll = data.getString(1); + authType = data.getString(2); + } catch (Exception e) { callbackContext.error(e.getMessage()); Log.d(TAG, e.getMessage()); return; } - int networkIdToConnect = ssidToNetworkId(ssidToConnect); + int networkIdToConnect = ssidToNetworkId(ssidToConnect, authType); if (networkIdToConnect > -1) { // We disable the network before connecting, because if this was the last connection before @@ -818,17 +809,19 @@ private boolean disconnectNetwork(CallbackContext callbackContext, JSONArray dat } String ssidToDisconnect = ""; + String authType = ""; // TODO: Verify type of data here! try { ssidToDisconnect = data.getString(0); + authType = data.getString(1); } catch (Exception e) { callbackContext.error(e.getMessage()); Log.d(TAG, e.getMessage()); return false; } - int networkIdToDisconnect = ssidToNetworkId(ssidToDisconnect); + int networkIdToDisconnect = ssidToNetworkId(ssidToDisconnect, authType); if (networkIdToDisconnect > 0) { @@ -1095,16 +1088,18 @@ private boolean getSSIDNetworkID(CallbackContext callbackContext, JSONArray data } String ssidToGetNetworkID = ""; + String authType = ""; try { ssidToGetNetworkID = data.getString(0); + authType = data.getString(1); } catch (Exception e) { callbackContext.error(e.getMessage()); Log.d(TAG, e.getMessage()); return false; } - int networkIdToConnect = ssidToNetworkId(ssidToGetNetworkID); + int networkIdToConnect = ssidToNetworkId(ssidToGetNetworkID, authType); callbackContext.success(networkIdToConnect); return true; @@ -1213,8 +1208,7 @@ private boolean isWifiEnabled(CallbackContext callbackContext) { * This method takes a given String, searches the current list of configured WiFi networks, and * returns the networkId for the network if the SSID matches. If not, it returns -1. */ - private int ssidToNetworkId(String ssid) { - + private int ssidToNetworkId(String ssid, String authType) { try { int maybeNetId = Integer.parseInt(ssid); @@ -1222,22 +1216,55 @@ private int ssidToNetworkId(String ssid) { return maybeNetId; } catch (NumberFormatException e) { - List currentNetworks = wifiManager.getConfiguredNetworks(); int networkId = -1; - // For each network in the list, compare the SSID with the given one for (WifiConfiguration test : currentNetworks) { - if (test.SSID != null && test.SSID.equals(ssid)) { - networkId = test.networkId; + if (test.SSID != null) { + if (authType.length() == 0) { + if(test.SSID.equals(ssid)) { + networkId = test.networkId; + } + } else { + String testSSID = test.SSID + this.getSecurityType(test); + if(testSSID.equals(ssid + authType)) { + networkId = test.networkId; + } + } } } - return networkId; - } } + + public static final int SECURITY_NONE = 0; + public static final int SECURITY_WEP = 1; + public static final int SECURITY_PSK = 2; + public static final int SECURITY_EAP = 3; + + public static String getSecurityType(WifiConfiguration config) { + switch (getSecurity(config)) { + case SECURITY_WEP: + return "WEP"; + case SECURITY_PSK: + if (config.allowedProtocols.get(WifiConfiguration.Protocol.RSN)) + return "WPA2"; + else + return "WPA"; + default: + return "NONE"; + } + } + public static int getSecurity(WifiConfiguration config) { + if (config.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_PSK)) + return SECURITY_PSK; + + if (config.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_EAP) || config.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.IEEE8021X)) + return SECURITY_EAP; + + return (config.wepKeys[0] != null) ? SECURITY_WEP : SECURITY_NONE; + } /** * This method enables or disables the wifi */ From 9f4fc368a1815d4459252996ae4aab11bb73a0e1 Mon Sep 17 00:00:00 2001 From: digaus Date: Wed, 17 Apr 2019 15:13:50 +0200 Subject: [PATCH 07/29] Update WifiWizard2.js --- www/WifiWizard2.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/www/WifiWizard2.js b/www/WifiWizard2.js index 85250f8..7b87405 100644 --- a/www/WifiWizard2.js +++ b/www/WifiWizard2.js @@ -123,11 +123,12 @@ var WifiWizard2 = { /** * Remove wifi network configuration * @param {string|int} [SSID] + * @param {string} [algorithm] * @returns {Promise} */ - remove: function (SSID) { + remove: function (SSID, algorithm) { return new Promise(function (resolve, reject) { - cordova.exec(resolve, reject, "WifiWizard2", "remove", [WifiWizard2.formatWifiString(SSID)]); + cordova.exec(resolve, reject, "WifiWizard2", "remove", [WifiWizard2.formatWifiString(SSID), algorithm || ""]); }); }, @@ -161,7 +162,7 @@ var WifiWizard2 = { WifiWizard2.add(wifiConfig).then(function (newNetID) { // Successfully updated or added wifiConfig - cordova.exec(resolve, reject, "WifiWizard2", "connect", [WifiWizard2.formatWifiString(SSID), bindAll]); + cordova.exec(resolve, reject, "WifiWizard2", "connect", [WifiWizard2.formatWifiString(SSID), bindAll, algorithm || ""]); // Catch error adding/updating network }).catch(function (error) { @@ -172,7 +173,7 @@ var WifiWizard2 = { // This error above should only be returned when the add method was able to pull a network ID (as it tries to update instead of adding) // Lets go ahead and attempt to connect to that SSID (using the existing wifi configuration) - cordova.exec(resolve, reject, "WifiWizard2", "connect", [WifiWizard2.formatWifiString(SSID), bindAll]); + cordova.exec(resolve, reject, "WifiWizard2", "connect", [WifiWizard2.formatWifiString(SSID), bindAll, algorithm]); } else { @@ -192,13 +193,14 @@ var WifiWizard2 = { * call WifiWizard2.disable() instead of disconnect. * * @param {string|int} [SSID=all] + * @param {string} [algorithm] * @returns {Promise} */ - disconnect: function (SSID) { + disconnect: function (SSID, algorithm) { return new Promise(function (resolve, reject) { if (SSID) { - cordova.exec(resolve, reject, "WifiWizard2", "disconnectNetwork", [WifiWizard2.formatWifiString(SSID)]); + cordova.exec(resolve, reject, "WifiWizard2", "disconnectNetwork", [WifiWizard2.formatWifiString(SSID), algorithm || ""]); } else { cordova.exec(resolve, reject, "WifiWizard2", "disconnect", []); } @@ -211,24 +213,26 @@ var WifiWizard2 = { * @param {string|int} [SSID] * @param {boolean} [bindAll=false] Whether or not to bind all network requests to this wifi network * @param {boolean} [waitForConnection=false] Whether or not to wait before resolving promise until connection to wifi is verified + * @param {string} [algorithm] * @returns {Promise} */ enable: function (SSID, bindAll, waitForConnection) { return new Promise(function (resolve, reject) { bindAll = bindAll ? true : false; waitForConnection = waitForConnection ? true : false; - cordova.exec(resolve, reject, "WifiWizard2", "enable", [WifiWizard2.formatWifiString(SSID), bindAll, waitForConnection]); + cordova.exec(resolve, reject, "WifiWizard2", "enable", [WifiWizard2.formatWifiString(SSID), bindAll, waitForConnection, algorithm || ""]); }); }, /** * Disable Network * @param {string|int} [SSID] + * @param {string} [algorithm] * @returns {Promise} */ disable: function (SSID) { return new Promise(function (resolve, reject) { - cordova.exec(resolve, reject, "WifiWizard2", "disable", [WifiWizard2.formatWifiString(SSID)]); + cordova.exec(resolve, reject, "WifiWizard2", "disable", [WifiWizard2.formatWifiString(SSID), algorithm || ""]); }); }, @@ -395,11 +399,12 @@ var WifiWizard2 = { /** * Get Network ID from SSID * @param {string|int} [SSID] + * @param {string} [algorithm] * @returns {Promise} */ getSSIDNetworkID: function (SSID) { return new Promise(function (resolve, reject) { - cordova.exec(resolve, reject, "WifiWizard2", "getSSIDNetworkID", [WifiWizard2.formatWifiString(SSID)]); + cordova.exec(resolve, reject, "WifiWizard2", "getSSIDNetworkID", [WifiWizard2.formatWifiString(SSID), algorithm || ""]); }); }, From fa5295f0e6e097c4eb7170b9bbdb929c457615ca Mon Sep 17 00:00:00 2001 From: digaus Date: Wed, 17 Apr 2019 15:19:25 +0200 Subject: [PATCH 08/29] Update WifiWizard2.java --- src/android/wifiwizard2/WifiWizard2.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/android/wifiwizard2/WifiWizard2.java b/src/android/wifiwizard2/WifiWizard2.java index 22d6e63..886db02 100644 --- a/src/android/wifiwizard2/WifiWizard2.java +++ b/src/android/wifiwizard2/WifiWizard2.java @@ -579,16 +579,18 @@ private boolean disable(CallbackContext callbackContext, JSONArray data) { } String ssidToDisable = ""; + String authType = ""; try { ssidToDisable = data.getString(0); + authType = data.getString(1); } catch (Exception e) { callbackContext.error(e.getMessage()); Log.d(TAG, e.getMessage()); return false; } - int networkIdToDisconnect = ssidToNetworkId(ssidToDisable); + int networkIdToDisconnect = ssidToNetworkId(ssidToDisable, authType); try { From f703c9e4b77a920684f0011d90bdfcf8f17c26ae Mon Sep 17 00:00:00 2001 From: digaus Date: Wed, 17 Apr 2019 15:25:42 +0200 Subject: [PATCH 09/29] Update WifiWizard2.js --- www/WifiWizard2.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/www/WifiWizard2.js b/www/WifiWizard2.js index 7b87405..2d2b44e 100644 --- a/www/WifiWizard2.js +++ b/www/WifiWizard2.js @@ -216,7 +216,7 @@ var WifiWizard2 = { * @param {string} [algorithm] * @returns {Promise} */ - enable: function (SSID, bindAll, waitForConnection) { + enable: function (SSID, bindAll, waitForConnection, algorithm) { return new Promise(function (resolve, reject) { bindAll = bindAll ? true : false; waitForConnection = waitForConnection ? true : false; @@ -230,7 +230,7 @@ var WifiWizard2 = { * @param {string} [algorithm] * @returns {Promise} */ - disable: function (SSID) { + disable: function (SSID, algorithm) { return new Promise(function (resolve, reject) { cordova.exec(resolve, reject, "WifiWizard2", "disable", [WifiWizard2.formatWifiString(SSID), algorithm || ""]); }); @@ -402,7 +402,7 @@ var WifiWizard2 = { * @param {string} [algorithm] * @returns {Promise} */ - getSSIDNetworkID: function (SSID) { + getSSIDNetworkID: function (SSID, algorithm) { return new Promise(function (resolve, reject) { cordova.exec(resolve, reject, "WifiWizard2", "getSSIDNetworkID", [WifiWizard2.formatWifiString(SSID), algorithm || ""]); }); From dd8685103256552f6a0c1ecba89f80612c41e7c1 Mon Sep 17 00:00:00 2001 From: digaus Date: Wed, 17 Apr 2019 15:27:10 +0200 Subject: [PATCH 10/29] Update WifiWizard2.js --- www/WifiWizard2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/WifiWizard2.js b/www/WifiWizard2.js index 2d2b44e..9913b97 100644 --- a/www/WifiWizard2.js +++ b/www/WifiWizard2.js @@ -162,7 +162,7 @@ var WifiWizard2 = { WifiWizard2.add(wifiConfig).then(function (newNetID) { // Successfully updated or added wifiConfig - cordova.exec(resolve, reject, "WifiWizard2", "connect", [WifiWizard2.formatWifiString(SSID), bindAll, algorithm || ""]); + cordova.exec(resolve, reject, "WifiWizard2", "connect", [WifiWizard2.formatWifiString(SSID), bindAll, wifiConfig.auth.algorithm || ""]); // Catch error adding/updating network }).catch(function (error) { From 202d4c9b41df7f0abc286c954e61f49fbb26aa11 Mon Sep 17 00:00:00 2001 From: digaus Date: Wed, 17 Apr 2019 15:31:35 +0200 Subject: [PATCH 11/29] Update WifiWizard2.js --- www/WifiWizard2.js | 1 - 1 file changed, 1 deletion(-) diff --git a/www/WifiWizard2.js b/www/WifiWizard2.js index 9913b97..d25151c 100644 --- a/www/WifiWizard2.js +++ b/www/WifiWizard2.js @@ -567,7 +567,6 @@ var WifiWizard2 = { wifiConfig.auth = { algorithm: "NONE" }; - wifiConfig.SSID = wifiConfig.SSID + "NONE"; } else if (algorithm === "WPA") { wifiConfig.auth = { algorithm: algorithm, From 52b81eb55edba613b54be71c91a0a9baed91346e Mon Sep 17 00:00:00 2001 From: digaus Date: Wed, 17 Apr 2019 16:55:12 +0200 Subject: [PATCH 12/29] Update WifiWizard2.js --- www/WifiWizard2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/WifiWizard2.js b/www/WifiWizard2.js index d25151c..a482aeb 100644 --- a/www/WifiWizard2.js +++ b/www/WifiWizard2.js @@ -173,7 +173,7 @@ var WifiWizard2 = { // This error above should only be returned when the add method was able to pull a network ID (as it tries to update instead of adding) // Lets go ahead and attempt to connect to that SSID (using the existing wifi configuration) - cordova.exec(resolve, reject, "WifiWizard2", "connect", [WifiWizard2.formatWifiString(SSID), bindAll, algorithm]); + cordova.exec(resolve, reject, "WifiWizard2", "connect", [WifiWizard2.formatWifiString(SSID), bindAll, wifiConfig.auth.algorithm || ""]); } else { From f73b7974cfa7ed9482a5af879982445311ef3fbc Mon Sep 17 00:00:00 2001 From: digaus Date: Thu, 18 Apr 2019 01:22:31 +0200 Subject: [PATCH 13/29] Update WifiWizard2.java --- src/android/wifiwizard2/WifiWizard2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/wifiwizard2/WifiWizard2.java b/src/android/wifiwizard2/WifiWizard2.java index 886db02..866b628 100644 --- a/src/android/wifiwizard2/WifiWizard2.java +++ b/src/android/wifiwizard2/WifiWizard2.java @@ -1251,7 +1251,7 @@ public static String getSecurityType(WifiConfiguration config) { return "WEP"; case SECURITY_PSK: if (config.allowedProtocols.get(WifiConfiguration.Protocol.RSN)) - return "WPA2"; + return "WPA"; //Normally WPA2 but since we map everything to WPA it will be WPA else return "WPA"; default: From cb14621368813bcdc37252210676391cde27ac05 Mon Sep 17 00:00:00 2001 From: digaus Date: Thu, 18 Apr 2019 11:10:04 +0200 Subject: [PATCH 14/29] Update WifiWizard2.java --- src/android/wifiwizard2/WifiWizard2.java | 52 ++++++++++++------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/android/wifiwizard2/WifiWizard2.java b/src/android/wifiwizard2/WifiWizard2.java index 866b628..314cf25 100644 --- a/src/android/wifiwizard2/WifiWizard2.java +++ b/src/android/wifiwizard2/WifiWizard2.java @@ -1240,32 +1240,32 @@ private int ssidToNetworkId(String ssid, String authType) { } - public static final int SECURITY_NONE = 0; - public static final int SECURITY_WEP = 1; - public static final int SECURITY_PSK = 2; - public static final int SECURITY_EAP = 3; - - public static String getSecurityType(WifiConfiguration config) { - switch (getSecurity(config)) { - case SECURITY_WEP: - return "WEP"; - case SECURITY_PSK: - if (config.allowedProtocols.get(WifiConfiguration.Protocol.RSN)) - return "WPA"; //Normally WPA2 but since we map everything to WPA it will be WPA - else - return "WPA"; - default: - return "NONE"; - } - } - public static int getSecurity(WifiConfiguration config) { - if (config.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_PSK)) - return SECURITY_PSK; - - if (config.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_EAP) || config.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.IEEE8021X)) - return SECURITY_EAP; - - return (config.wepKeys[0] != null) ? SECURITY_WEP : SECURITY_NONE; + static public String getSecurityType(WifiConfiguration wifiConfig) { + + if (wifiConfig.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.NONE)) { + // If we never set group ciphers, wpa_supplicant puts all of them. + // For open, we don't set group ciphers. + // For WEP, we specifically only set WEP40 and WEP104, so CCMP + // and TKIP should not be there. + if (!wifiConfig.allowedGroupCiphers.get(WifiConfiguration.GroupCipher.CCMP) + && (wifiConfig.allowedGroupCiphers.get(WifiConfiguration.GroupCipher.WEP40) + || wifiConfig.allowedGroupCiphers.get(WifiConfiguration.GroupCipher.WEP104))) { + return "WEP"; + } else { + return "NONE"; + } + } else if (wifiConfig.allowedProtocols.get(WifiConfiguration.Protocol.RSN)) { + return "WPA";//"WPA2"; + } else if (wifiConfig.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_EAP)) { + return "WPA";//"WPA_EAP"; + } else if (wifiConfig.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.IEEE8021X)) { + return "WPA";//"IEEE8021X"; + } else if (wifiConfig.allowedProtocols.get(WifiConfiguration.Protocol.WPA)) { + return "WPA"; + } else { + Log.w(TAG, "Unknown security type from WifiConfiguration, falling back on open."); + return "NONE"; + } } /** * This method enables or disables the wifi From 96bf6e97ce75008aa2a26161fb9b743d6ea087df Mon Sep 17 00:00:00 2001 From: digaus Date: Sun, 12 May 2019 13:10:56 +0200 Subject: [PATCH 15/29] Update WifiWizard2.java --- src/android/wifiwizard2/WifiWizard2.java | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/android/wifiwizard2/WifiWizard2.java b/src/android/wifiwizard2/WifiWizard2.java index 314cf25..97ee469 100644 --- a/src/android/wifiwizard2/WifiWizard2.java +++ b/src/android/wifiwizard2/WifiWizard2.java @@ -375,7 +375,7 @@ private boolean add(CallbackContext callbackContext, JSONArray data) { wifi.hiddenSSID = isHiddenSSID; - if (authType.equals("WPA") || authType.equals("WPA2")) { + if (authType.equals("WPA2")) { /** * WPA Data format: * 0: ssid @@ -397,6 +397,27 @@ private boolean add(CallbackContext callbackContext, JSONArray data) { wifi.networkId = ssidToNetworkId(newSSID, authType); + } else if (authType.equals("WPA")) { + /** + * WPA Data format: + * 0: ssid + * 1: auth + * 2: password + * 3: isHiddenSSID + */ + wifi.SSID = newSSID; + wifi.preSharedKey = newPass; + + wifi.status = WifiConfiguration.Status.ENABLED; + wifi.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); + wifi.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); + wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); + wifi.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); + wifi.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); + wifi.allowedProtocols.set(WifiConfiguration.Protocol.WPA); + + wifi.networkId = ssidToNetworkId(newSSID, authType); + } else if (authType.equals("WEP")) { /** * WEP Data format: From e4eb8a43c65e877296b0d04f1b65ba46265e88cc Mon Sep 17 00:00:00 2001 From: digaus Date: Sun, 12 May 2019 13:12:37 +0200 Subject: [PATCH 16/29] Update WifiWizard2.js --- www/WifiWizard2.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/www/WifiWizard2.js b/www/WifiWizard2.js index a482aeb..025fdb7 100644 --- a/www/WifiWizard2.js +++ b/www/WifiWizard2.js @@ -86,6 +86,10 @@ var WifiWizard2 = { if (typeof wifi.auth == "object") { switch (wifi.auth.algorithm) { + case "WPA2": + networkInformation.push("WPA2"); + networkInformation.push(wifi.auth.password); + break; case "WPA": networkInformation.push("WPA"); networkInformation.push(wifi.auth.password); @@ -567,6 +571,12 @@ var WifiWizard2 = { wifiConfig.auth = { algorithm: "NONE" }; + } else if (algorithm === "WPA2") { + wifiConfig.auth = { + algorithm: algorithm, + password: WifiWizard2.formatWifiString(password) + // Other parameters can be added depending on algorithm. + }; } else if (algorithm === "WPA") { wifiConfig.auth = { algorithm: algorithm, From 75055ef19058f102ac27e44169a2d9e4fe227227 Mon Sep 17 00:00:00 2001 From: digaus Date: Tue, 14 May 2019 07:51:06 +0200 Subject: [PATCH 17/29] Update WifiWizard2.js --- www/WifiWizard2.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/www/WifiWizard2.js b/www/WifiWizard2.js index 025fdb7..621d25f 100644 --- a/www/WifiWizard2.js +++ b/www/WifiWizard2.js @@ -8,7 +8,7 @@ * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express oWPA2r implied. * See the License for the specific language governing permissions and * limitations under the License. */ @@ -86,10 +86,6 @@ var WifiWizard2 = { if (typeof wifi.auth == "object") { switch (wifi.auth.algorithm) { - case "WPA2": - networkInformation.push("WPA2"); - networkInformation.push(wifi.auth.password); - break; case "WPA": networkInformation.push("WPA"); networkInformation.push(wifi.auth.password); @@ -571,12 +567,6 @@ var WifiWizard2 = { wifiConfig.auth = { algorithm: "NONE" }; - } else if (algorithm === "WPA2") { - wifiConfig.auth = { - algorithm: algorithm, - password: WifiWizard2.formatWifiString(password) - // Other parameters can be added depending on algorithm. - }; } else if (algorithm === "WPA") { wifiConfig.auth = { algorithm: algorithm, From 711e293491a8921898a6cc41a2b1473a68769242 Mon Sep 17 00:00:00 2001 From: digaus Date: Tue, 14 May 2019 07:56:11 +0200 Subject: [PATCH 18/29] Update WifiWizard2.java --- src/android/wifiwizard2/WifiWizard2.java | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/src/android/wifiwizard2/WifiWizard2.java b/src/android/wifiwizard2/WifiWizard2.java index 97ee469..8fdd7f9 100644 --- a/src/android/wifiwizard2/WifiWizard2.java +++ b/src/android/wifiwizard2/WifiWizard2.java @@ -375,7 +375,7 @@ private boolean add(CallbackContext callbackContext, JSONArray data) { wifi.hiddenSSID = isHiddenSSID; - if (authType.equals("WPA2")) { + if (authType.equals("WPA")) { /** * WPA Data format: * 0: ssid @@ -397,27 +397,6 @@ private boolean add(CallbackContext callbackContext, JSONArray data) { wifi.networkId = ssidToNetworkId(newSSID, authType); - } else if (authType.equals("WPA")) { - /** - * WPA Data format: - * 0: ssid - * 1: auth - * 2: password - * 3: isHiddenSSID - */ - wifi.SSID = newSSID; - wifi.preSharedKey = newPass; - - wifi.status = WifiConfiguration.Status.ENABLED; - wifi.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); - wifi.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); - wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); - wifi.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); - wifi.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); - wifi.allowedProtocols.set(WifiConfiguration.Protocol.WPA); - - wifi.networkId = ssidToNetworkId(newSSID, authType); - } else if (authType.equals("WEP")) { /** * WEP Data format: From 663d5d19bca22a0c0510b6cb1bfea34ffb566927 Mon Sep 17 00:00:00 2001 From: digaus Date: Sun, 19 May 2019 01:02:23 +0200 Subject: [PATCH 19/29] Update WifiWizard2.java --- src/android/wifiwizard2/WifiWizard2.java | 39 +++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/android/wifiwizard2/WifiWizard2.java b/src/android/wifiwizard2/WifiWizard2.java index 8fdd7f9..7ae4f35 100644 --- a/src/android/wifiwizard2/WifiWizard2.java +++ b/src/android/wifiwizard2/WifiWizard2.java @@ -375,7 +375,7 @@ private boolean add(CallbackContext callbackContext, JSONArray data) { wifi.hiddenSSID = isHiddenSSID; - if (authType.equals("WPA")) { + if (authType.equals("WPA2")) { /** * WPA Data format: * 0: ssid @@ -397,6 +397,27 @@ private boolean add(CallbackContext callbackContext, JSONArray data) { wifi.networkId = ssidToNetworkId(newSSID, authType); + } else if (authType.equals("WPA")) { + /** + * WPA Data format: + * 0: ssid + * 1: auth + * 2: password + * 3: isHiddenSSID + */ + wifi.SSID = newSSID; + wifi.preSharedKey = newPass; + + wifi.status = WifiConfiguration.Status.ENABLED; + wifi.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); + wifi.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); + wifi.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); + wifi.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); + wifi.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); + wifi.allowedProtocols.set(WifiConfiguration.Protocol.WPA); + + wifi.networkId = ssidToNetworkId(newSSID, authType); + } else if (authType.equals("WEP")) { /** * WEP Data format: @@ -1235,6 +1256,22 @@ private int ssidToNetworkId(String ssid, String authType) { } } } + if (networkId == -1 && authType.substring(0,3).equals('WPA')) { + for (WifiConfiguration test : currentNetworks) { + if (test.SSID != null) { + if (authType.length() == 0) { + if(test.SSID.equals(ssid)) { + networkId = test.networkId; + } + } else { + String testSSID = test.SSID + this.getSecurityType(test).substring(0,3); + if(testSSID.equals(ssid + authType)) { + networkId = test.networkId; + } + } + } + } + } return networkId; } } From 70994b6adae71192d516fc0c08c777ef9aded848 Mon Sep 17 00:00:00 2001 From: digaus Date: Sun, 19 May 2019 01:04:01 +0200 Subject: [PATCH 20/29] Update WifiWizard2.js --- www/WifiWizard2.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/www/WifiWizard2.js b/www/WifiWizard2.js index 621d25f..b670484 100644 --- a/www/WifiWizard2.js +++ b/www/WifiWizard2.js @@ -86,6 +86,10 @@ var WifiWizard2 = { if (typeof wifi.auth == "object") { switch (wifi.auth.algorithm) { + case "WPA2": + networkInformation.push("WPA2"); + networkInformation.push(wifi.auth.password); + break; case "WPA": networkInformation.push("WPA"); networkInformation.push(wifi.auth.password); @@ -567,6 +571,12 @@ var WifiWizard2 = { wifiConfig.auth = { algorithm: "NONE" }; + } else if (algorithm === "WPA2") { + wifiConfig.auth = { + algorithm: algorithm, + password: WifiWizard2.formatWifiString(password) + // Other parameters can be added depending on algorithm. + }; } else if (algorithm === "WPA") { wifiConfig.auth = { algorithm: algorithm, From 6ec253b0f5e80c0149fcb322372678808c15aa0f Mon Sep 17 00:00:00 2001 From: digaus Date: Sun, 19 May 2019 01:05:21 +0200 Subject: [PATCH 21/29] Update WifiWizard2.java --- src/android/wifiwizard2/WifiWizard2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/wifiwizard2/WifiWizard2.java b/src/android/wifiwizard2/WifiWizard2.java index 7ae4f35..4e3756b 100644 --- a/src/android/wifiwizard2/WifiWizard2.java +++ b/src/android/wifiwizard2/WifiWizard2.java @@ -1292,7 +1292,7 @@ static public String getSecurityType(WifiConfiguration wifiConfig) { return "NONE"; } } else if (wifiConfig.allowedProtocols.get(WifiConfiguration.Protocol.RSN)) { - return "WPA";//"WPA2"; + return "WPA2"; } else if (wifiConfig.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_EAP)) { return "WPA";//"WPA_EAP"; } else if (wifiConfig.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.IEEE8021X)) { From a59c53abba82d35983a40c4bcd660e3fb4eb4142 Mon Sep 17 00:00:00 2001 From: digaus Date: Sun, 19 May 2019 01:10:32 +0200 Subject: [PATCH 22/29] Update WifiWizard2.java --- src/android/wifiwizard2/WifiWizard2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/wifiwizard2/WifiWizard2.java b/src/android/wifiwizard2/WifiWizard2.java index 4e3756b..5408fa5 100644 --- a/src/android/wifiwizard2/WifiWizard2.java +++ b/src/android/wifiwizard2/WifiWizard2.java @@ -1256,7 +1256,7 @@ private int ssidToNetworkId(String ssid, String authType) { } } } - if (networkId == -1 && authType.substring(0,3).equals('WPA')) { + if (networkId == -1 && authType.substring(0,3).equals("WPA")) { for (WifiConfiguration test : currentNetworks) { if (test.SSID != null) { if (authType.length() == 0) { From 7a1264eab2387037df564746d15afd65e96ace59 Mon Sep 17 00:00:00 2001 From: digaus Date: Sat, 20 Jul 2019 23:11:35 +0200 Subject: [PATCH 23/29] Cleanup --- src/android/wifiwizard2/WifiWizard2.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/android/wifiwizard2/WifiWizard2.java b/src/android/wifiwizard2/WifiWizard2.java index 5408fa5..6c9483f 100644 --- a/src/android/wifiwizard2/WifiWizard2.java +++ b/src/android/wifiwizard2/WifiWizard2.java @@ -377,7 +377,7 @@ private boolean add(CallbackContext callbackContext, JSONArray data) { if (authType.equals("WPA2")) { /** - * WPA Data format: + * WPA2 Data format: * 0: ssid * 1: auth * 2: password @@ -1241,7 +1241,7 @@ private int ssidToNetworkId(String ssid, String authType) { } catch (NumberFormatException e) { List currentNetworks = wifiManager.getConfiguredNetworks(); int networkId = -1; - // For each network in the list, compare the SSID with the given one + // For each network in the list, compare the SSID with the given one and check if authType matches for (WifiConfiguration test : currentNetworks) { if (test.SSID != null) { if (authType.length() == 0) { @@ -1256,6 +1256,7 @@ private int ssidToNetworkId(String ssid, String authType) { } } } + // Fallback to WPA if WPA2 is not found if (networkId == -1 && authType.substring(0,3).equals("WPA")) { for (WifiConfiguration test : currentNetworks) { if (test.SSID != null) { @@ -1276,7 +1277,7 @@ private int ssidToNetworkId(String ssid, String authType) { } } - + // Get the different configured security types static public String getSecurityType(WifiConfiguration wifiConfig) { if (wifiConfig.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.NONE)) { From e4243a0ab56317f20fecd4bffb86779578150bca Mon Sep 17 00:00:00 2001 From: digaus Date: Wed, 27 Nov 2019 00:22:44 +0100 Subject: [PATCH 24/29] Update WifiWizard2.m --- src/ios/WifiWizard2.m | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/ios/WifiWizard2.m b/src/ios/WifiWizard2.m index 675c571..e020660 100644 --- a/src/ios/WifiWizard2.m +++ b/src/ios/WifiWizard2.m @@ -2,9 +2,39 @@ #include #import #import -#import +#import -@implementation WifiWizard2 +- (void)getWifiIP:(CDVInvokedUrlCommand*)command { + CDVPluginResult *pluginResult = nil; + var address: String? + var ifaddr: UnsafeMutablePointer? = nil + if getifaddrs(&ifaddr) == 0 { + var ptr = ifaddr + while ptr != nil { + defer { ptr = ptr?.pointee.ifa_next } + + let interface = ptr?.pointee + let addrFamily = interface?.ifa_addr.pointee.sa_family + if addrFamily == UInt8(AF_INET) || addrFamily == UInt8(AF_INET6) { + + if let name: String = String(cString: (interface?.ifa_name)!), name == "en0" { + var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST)) + getnameinfo(interface?.ifa_addr, socklen_t((interface?.ifa_addr.pointee.sa_len)!), &hostname, socklen_t(hostname.count), nil, socklen_t(0), NI_NUMERICHOST) + address = String(cString: hostname) + } + } + } + freeifaddrs(ifaddr) + } + if (address) { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:address]; + } else { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Not available"]; + } + + [self.commandDelegate sendPluginResult:pluginResult + callbackId:command.callbackId]; +} - (id)fetchSSIDInfo { // see http://stackoverflow.com/a/5198968/907720 From b20e41ea9348e9bfde60287203993434740405b9 Mon Sep 17 00:00:00 2001 From: digaus Date: Wed, 27 Nov 2019 00:23:36 +0100 Subject: [PATCH 25/29] Update WifiWizard2.h --- src/ios/WifiWizard2.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ios/WifiWizard2.h b/src/ios/WifiWizard2.h index 3f2ab83..38b61b9 100644 --- a/src/ios/WifiWizard2.h +++ b/src/ios/WifiWizard2.h @@ -6,6 +6,7 @@ - (void)iOSConnectNetwork:(CDVInvokedUrlCommand *)command; - (void)iOSConnectOpenNetwork:(CDVInvokedUrlCommand *)command; - (void)iOSDisconnectNetwork:(CDVInvokedUrlCommand *)command; +- (void)getWifiIP:(CDVInvokedUrlCommand *)command; - (void)getConnectedSSID:(CDVInvokedUrlCommand *)command; - (void)getConnectedBSSID:(CDVInvokedUrlCommand *)command; - (void)isWifiEnabled:(CDVInvokedUrlCommand *)command; From b94f43616293fb4075f16680fcbe6cc3eed8f0e4 Mon Sep 17 00:00:00 2001 From: digaus Date: Wed, 27 Nov 2019 00:34:00 +0100 Subject: [PATCH 26/29] Update WifiWizard2.m --- src/ios/WifiWizard2.m | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ios/WifiWizard2.m b/src/ios/WifiWizard2.m index e020660..ffc5980 100644 --- a/src/ios/WifiWizard2.m +++ b/src/ios/WifiWizard2.m @@ -4,6 +4,7 @@ #import #import +@implementation WifiWizard2 - (void)getWifiIP:(CDVInvokedUrlCommand*)command { CDVPluginResult *pluginResult = nil; var address: String? From da975d9220e35434980a70b8d6a3c93ed35d92df Mon Sep 17 00:00:00 2001 From: digaus Date: Wed, 27 Nov 2019 01:02:40 +0100 Subject: [PATCH 27/29] Update WifiWizard2.m --- src/ios/WifiWizard2.m | 50 +++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/ios/WifiWizard2.m b/src/ios/WifiWizard2.m index ffc5980..b6af9ff 100644 --- a/src/ios/WifiWizard2.m +++ b/src/ios/WifiWizard2.m @@ -1,32 +1,40 @@ #import "WifiWizard2.h" #include +#include #import #import -#import +#import @implementation WifiWizard2 + - (void)getWifiIP:(CDVInvokedUrlCommand*)command { CDVPluginResult *pluginResult = nil; - var address: String? - var ifaddr: UnsafeMutablePointer? = nil - if getifaddrs(&ifaddr) == 0 { - var ptr = ifaddr - while ptr != nil { - defer { ptr = ptr?.pointee.ifa_next } - - let interface = ptr?.pointee - let addrFamily = interface?.ifa_addr.pointee.sa_family - if addrFamily == UInt8(AF_INET) || addrFamily == UInt8(AF_INET6) { - - if let name: String = String(cString: (interface?.ifa_name)!), name == "en0" { - var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST)) - getnameinfo(interface?.ifa_addr, socklen_t((interface?.ifa_addr.pointee.sa_len)!), &hostname, socklen_t(hostname.count), nil, socklen_t(0), NI_NUMERICHOST) - address = String(cString: hostname) - } - } - } - freeifaddrs(ifaddr) - } + + NSString *address = @"error"; + struct ifaddrs *interfaces = NULL; + struct ifaddrs *temp_addr = NULL; + int success = 0; + // retrieve the current interfaces - returns 0 on success + success = getifaddrs(&interfaces); + if (success == 0) { + // Loop through linked list of interfaces + temp_addr = interfaces; + while(temp_addr != NULL) { + if(temp_addr->ifa_addr->sa_family == AF_INET) { + // Check if interface is en0 which is the wifi connection on the iPhone + if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) { + // Get NSString from C String + address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)]; + + } + + } + + temp_addr = temp_addr->ifa_next; + } + } + // Free memory + freeifaddrs(interfaces); if (address) { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:address]; } else { From 061b681c43129f9abe54e6eaa705930362e1bb55 Mon Sep 17 00:00:00 2001 From: digaus Date: Sun, 22 Dec 2019 14:11:24 +0100 Subject: [PATCH 28/29] Add permission request for iOS 13 --- src/ios/WifiWizard2.m | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/ios/WifiWizard2.m b/src/ios/WifiWizard2.m index b6af9ff..335eade 100644 --- a/src/ios/WifiWizard2.m +++ b/src/ios/WifiWizard2.m @@ -4,6 +4,7 @@ #import #import #import +#import @implementation WifiWizard2 @@ -200,9 +201,8 @@ - (void)iOSDisconnectNetwork:(CDVInvokedUrlCommand*)command { - (void)getConnectedSSID:(CDVInvokedUrlCommand*)command { CDVPluginResult *pluginResult = nil; - NSDictionary *r = [self fetchSSIDInfo]; - NSString *ssid = [r objectForKey:(id)kCNNetworkInfoKeySSID]; //@"SSID" + NSString *ssid = [self getWifiSsid]; //@"SSID" if (ssid && [ssid length]) { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:ssid]; @@ -368,5 +368,41 @@ - (void)canConnectToRouter:(CDVInvokedUrlCommand*)command { callbackId:command.callbackId]; } +- (NSString*) getWifiSsid { + if (@available(iOS 13.0, *)) { + if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) { + NSLog(@"User has explicitly denied authorization for this application, or location services are disabled in Settings."); + //[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; + return nil; + } + CLLocationManager* cllocation = [[CLLocationManager alloc] init]; + if(![CLLocationManager locationServicesEnabled] || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined){ + [cllocation requestWhenInUseAuthorization]; + usleep(500); + return [self getWifiSsid]; + } + } + NSString *wifiName = nil; + CFArrayRef wifiInterfaces = CNCopySupportedInterfaces(); + if (!wifiInterfaces) { + return nil; + } + NSArray *interfaces = (__bridge NSArray *)wifiInterfaces; + for (NSString *interfaceName in interfaces) { + CFDictionaryRef dictRef = CNCopyCurrentNetworkInfo((__bridge CFStringRef)(interfaceName)); + + if (dictRef) { + NSDictionary *networkInfo = (__bridge NSDictionary *)dictRef; + NSLog(@"network info -> %@", networkInfo); + wifiName = [networkInfo objectForKey:(__bridge NSString *)kCNNetworkInfoKeySSID]; + CFRelease(dictRef); + } + } + + CFRelease(wifiInterfaces); + return wifiName; +} + + @end From b84507a05e648ce20c4df1038ee43aecdd3c71e6 Mon Sep 17 00:00:00 2001 From: digaus Date: Mon, 23 Dec 2019 00:38:03 +0100 Subject: [PATCH 29/29] Add prefix connect --- src/ios/WifiWizard2.m | 46 +++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/src/ios/WifiWizard2.m b/src/ios/WifiWizard2.m index 335eade..a78fcbb 100644 --- a/src/ios/WifiWizard2.m +++ b/src/ios/WifiWizard2.m @@ -90,22 +90,31 @@ - (void)iOSConnectNetwork:(CDVInvokedUrlCommand*)command { passwordString = [options objectForKey:@"Password"]; if (@available(iOS 11.0, *)) { - if (ssidString && [ssidString length]) { - NEHotspotConfiguration *configuration = [[NEHotspotConfiguration - alloc] initWithSSID:ssidString - passphrase:passwordString - isWEP:(BOOL)false]; - - configuration.joinOnce = false; - + if (ssidString && [ssidString length]) { + NEHotspotConfiguration *configuration; + + + if (@available(iOS 13.0, *)) { + configuration = [[NEHotspotConfiguration + alloc] initWithSSIDPrefix:ssidString + passphrase:passwordString + isWEP:(BOOL)false]; + } else { + configuration = [[NEHotspotConfiguration + alloc] initWithSSID:ssidString + passphrase:passwordString + isWEP:(BOOL)false]; + } + configuration.joinOnce = false; + [[NEHotspotConfigurationManager sharedManager] applyConfiguration:configuration completionHandler:^(NSError * _Nullable error) { NSDictionary *r = [self fetchSSIDInfo]; NSString *ssid = [r objectForKey:(id)kCNNetworkInfoKeySSID]; //@"SSID" - if ([ssid isEqualToString:ssidString]){ - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:ssidString]; + if ([ssid hasPrefix:ssidString]){ + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:ssid]; }else{ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error.description]; } @@ -113,7 +122,6 @@ - (void)iOSConnectNetwork:(CDVInvokedUrlCommand*)command { callbackId:command.callbackId]; }]; - } else { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"SSID Not provided"]; [self.commandDelegate sendPluginResult:pluginResult @@ -140,8 +148,16 @@ - (void)iOSConnectOpenNetwork:(CDVInvokedUrlCommand*)command { if (@available(iOS 11.0, *)) { if (ssidString && [ssidString length]) { - NEHotspotConfiguration *configuration = [[NEHotspotConfiguration - alloc] initWithSSID:ssidString]; + NEHotspotConfiguration *configuration; + + + if (@available(iOS 13.0, *)) { + configuration = [[NEHotspotConfiguration + alloc] initWithSSIDPrefix:ssidString]; + } else { + configuration = [[NEHotspotConfiguration + alloc] initWithSSID:ssidString]; + } configuration.joinOnce = false; @@ -151,8 +167,8 @@ - (void)iOSConnectOpenNetwork:(CDVInvokedUrlCommand*)command { NSString *ssid = [r objectForKey:(id)kCNNetworkInfoKeySSID]; //@"SSID" - if ([ssid isEqualToString:ssidString]){ - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:ssidString]; + if ([ssid hasPrefix:ssidString]){ + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:ssid]; }else{ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error.description]; }