Code example for WifiConfiguration

Methods: toString

0
    } 
 
    @LargeTest 
    public void testWifiAssociation() { 
        assertNotNull("no test ssid", mSsid);
        WifiConfiguration config = new WifiConfiguration();
        config.SSID = mSsid;
        SECURITY_TYPE security = SECURITY_TYPE.valueOf(mSecurityType);
        log("Security type is " + security.toString());
        switch (security) {
            // set network configurations 
            case OPEN:
                config.allowedKeyManagement.set(KeyMgmt.NONE);
                break; 
            case WEP64:
                // always use hex pair for WEP-40 
                assertTrue("not a WEP64 security type?", mPassword.length() == 10);
                config.allowedKeyManagement.set(KeyMgmt.NONE);
                config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
                config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
                config.allowedGroupCiphers.set(GroupCipher.WEP40);
                if (mPassword != null) {
                    int length = mPassword.length();
                    // WEP-40 
                    if (mPassword.matches("[0-9A-Fa-f]*")) {
                        config.wepKeys[0] = mPassword;
                    } else { 
                        fail("Please type hex pair for the password");
                    } 
                } 
                break; 
            case WEP128:
                assertNotNull("password is empty", mPassword);
                // always use hex pair for WEP-104 
                assertTrue("not a WEP128 security type?", mPassword.length() == 26);
                config.allowedKeyManagement.set(KeyMgmt.NONE);
                config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
                config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
                config.allowedGroupCiphers.set(GroupCipher.WEP104);
                if (mPassword != null) {
                    int length = mPassword.length();
                    // WEP-40 
                    if (mPassword.matches("[0-9A-Fa-f]*")) {
                        config.wepKeys[0] = mPassword;
                    } else { 
                        fail("Please type hex pair for the password");
                    } 
                } 
                break; 
            case WPA_TKIP:
                assertNotNull("missing password", mPassword);
                config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
                config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
                config.allowedProtocols.set(Protocol.WPA);
                config.allowedPairwiseCiphers.set(PairwiseCipher.TKIP);
                config.allowedGroupCiphers.set(GroupCipher.TKIP);
                if (mPassword.matches("[0-9A-Fa-f]{64}")) {
                    config.preSharedKey = mPassword;
                } else { 
                    config.preSharedKey = '"' + mPassword + '"';
                } 
                break; 
            case WPA2_AES:
                assertNotNull("missing password", mPassword);
                config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
                config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
                config.allowedProtocols.set(Protocol.RSN);
                config.allowedPairwiseCiphers.set(PairwiseCipher.CCMP);
                config.allowedGroupCiphers.set(GroupCipher.CCMP);
                config.allowedProtocols.set(Protocol.RSN);
                if (mPassword.matches("[0-9A-Fa-f]{64}")) {
                    config.preSharedKey = mPassword;
                } else { 
                    config.preSharedKey = '"' + mPassword + '"';
                } 
                break; 
            default: 
                fail("Not a valid security type: " + mSecurityType);
                break; 
        } 
        Log.v(TAG, "network config: " + config.toString());
        connectToWifi(config);
    } 
}