// Adding a WEP network private int changeNetworkWEP(NetworkSetting input) { WifiConfiguration config = changeNetworkCommon(input); String pass = input.getPassword(); if (NetworkUtil.isHexWepKey(pass)) { config.wepKeys[0] = pass; } else { config.wepKeys[0] = NetworkUtil.convertToQuotedString(pass); } config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104); config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); config.wepTxKeyIndex = 0; return requestNetworkChange(config); }
// Adding a WPA or WPA2 network private int changeNetworkWPA(NetworkSetting input) { WifiConfiguration config = changeNetworkCommon(input); String pass = input.getPassword(); // Hex passwords that are 64 bits long are not to be quoted. if (HEX_DIGITS_64.matcher(pass).matches()) { Log.d(TAG, "A 64 bit hex password entered."); config.preSharedKey = pass; } else { Log.d(TAG, "A normal password entered: I am quoting it."); config.preSharedKey = NetworkUtil.convertToQuotedString(pass); } config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); // For WPA config.allowedProtocols.set(WifiConfiguration.Protocol.WPA); // For WPA2 config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); config.allowedProtocols.set(WifiConfiguration.Protocol.RSN); return requestNetworkChange(config); }
private WifiConfiguration changeNetworkCommon(NetworkSetting input) { statusView.setText(R.string.wifi_creating_network); Log.d( TAG, "Adding new configuration: \nSSID: " + input.getSsid() + "\nType: " + input.getNetworkType()); WifiConfiguration config = new WifiConfiguration(); config.allowedAuthAlgorithms.clear(); config.allowedGroupCiphers.clear(); config.allowedKeyManagement.clear(); config.allowedPairwiseCiphers.clear(); config.allowedProtocols.clear(); // Android API insists that an ascii SSID must be quoted to be correctly handled. config.SSID = NetworkUtil.convertToQuotedString(input.getSsid()); config.hiddenSSID = true; return config; }