diff options
6 files changed, 45 insertions, 15 deletions
diff --git a/service/java/com/android/server/wifi/SupplicantP2pIfaceHal.java b/service/java/com/android/server/wifi/SupplicantP2pIfaceHal.java index 72cce457b..ba7064b4d 100644 --- a/service/java/com/android/server/wifi/SupplicantP2pIfaceHal.java +++ b/service/java/com/android/server/wifi/SupplicantP2pIfaceHal.java @@ -1468,11 +1468,11 @@ public class SupplicantP2pIfaceHal { * AP/Registrar at about the same time (2 minute window). * * @param groupIfName Group interface name to use. - * @param bssid BSSID of the AP. Use zero'ed bssid to indicate wildcard. + * @param bssid BSSID of the AP. Use empty bssid to indicate wildcard. * @return true, if operation was successful. */ public boolean startWpsPbc(String groupIfName, String bssid) { - if (TextUtils.isEmpty(groupIfName) || TextUtils.isEmpty(bssid)) return false; + if (TextUtils.isEmpty(groupIfName)) return false; synchronized (mLock) { if (!checkSupplicantP2pIfaceAndLogFailure("startWpsPbc")) return false; if (groupIfName == null) { @@ -1543,11 +1543,11 @@ public class SupplicantP2pIfaceHal { * Initiate WPS Pin Display setup. * * @param groupIfName Group interface name to use. - * @param bssid BSSID of the AP. Use zero'ed bssid to indicate wildcard. + * @param bssid BSSID of the AP. Use empty bssid to indicate wildcard. * @return generated pin if operation was successful, null otherwise. */ public String startWpsPinDisplay(String groupIfName, String bssid) { - if (TextUtils.isEmpty(groupIfName) || TextUtils.isEmpty(bssid)) return null; + if (TextUtils.isEmpty(groupIfName)) return null; synchronized (mLock) { if (!checkSupplicantP2pIfaceAndLogFailure("startWpsPinDisplay")) return null; if (groupIfName == null) { diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java index 66bda1e64..9d063d247 100644 --- a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java +++ b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java @@ -1334,11 +1334,10 @@ public class SupplicantStaIfaceHal { /** * Start WPS pin display operation with the specified peer. * - * @param bssidStr BSSID of the peer. + * @param bssidStr BSSID of the peer. Use empty bssid to indicate wildcard. * @return true if request is sent successfully, false otherwise. */ public boolean startWpsPbc(String bssidStr) { - if (TextUtils.isEmpty(bssidStr)) return false; return startWpsPbc(NativeUtil.macAddressToByteArray(bssidStr)); } @@ -1381,11 +1380,10 @@ public class SupplicantStaIfaceHal { /** * Start WPS pin display operation with the specified peer. * - * @param bssidStr BSSID of the peer. + * @param bssidStr BSSID of the peer. Use empty bssid to indicate wildcard. * @return new pin generated on success, null otherwise. */ public String startWpsPinDisplay(String bssidStr) { - if (TextUtils.isEmpty(bssidStr)) return null; return startWpsPinDisplay(NativeUtil.macAddressToByteArray(bssidStr)); } diff --git a/service/java/com/android/server/wifi/util/NativeUtil.java b/service/java/com/android/server/wifi/util/NativeUtil.java index 4abb0f4ea..50f32fa4d 100644 --- a/service/java/com/android/server/wifi/util/NativeUtil.java +++ b/service/java/com/android/server/wifi/util/NativeUtil.java @@ -16,6 +16,8 @@ package com.android.server.wifi.util; +import android.text.TextUtils; + import libcore.util.HexEncoding; import java.nio.ByteBuffer; @@ -102,14 +104,11 @@ public class NativeUtil { * * @param macStr string of format: "XX:XX:XX:XX:XX:XX" or "XXXXXXXXXXXX", where X is any * hexadecimal digit. - * Passing "any" is the same as 00:00:00:00:00:00 + * Passing null, empty string or "any" is the same as 00:00:00:00:00:00 * @throws IllegalArgumentException for various malformed inputs. */ public static byte[] macAddressToByteArray(String macStr) { - if (macStr == null) { - throw new IllegalArgumentException("null mac string"); - } - if (ANY_MAC_STR.equals(macStr)) return ANY_MAC_BYTES; + if (TextUtils.isEmpty(macStr) || ANY_MAC_STR.equals(macStr)) return ANY_MAC_BYTES; String cleanMac = macStr.replace(":", ""); if (cleanMac.length() != MAC_LENGTH * 2) { throw new IllegalArgumentException("invalid mac string length: " + cleanMac); diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantP2pIfaceHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantP2pIfaceHalTest.java index 2ea492e60..19dc521fb 100644 --- a/tests/wifitests/src/com/android/server/wifi/SupplicantP2pIfaceHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SupplicantP2pIfaceHalTest.java @@ -90,14 +90,13 @@ public class SupplicantP2pIfaceHalTest { final String mInvalidMacAddress1 = "00:11:22:33:44"; final String mInvalidMacAddress2 = ":::::"; final String mInvalidMacAddress3 = "invalid"; - final String mInvalidMacAddress4 = ""; final byte mInvalidMacAddressBytes1[] = null; final byte mInvalidMacAddressBytes2[] = {}; final byte mInvalidMacAddressBytes3[] = { 0x00, 0x01, 0x02, 0x03, 0x04 }; final byte mInvalidMacAddressBytes4[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }; HashSet<String> mInvalidMacAddresses = new HashSet<String>(Arrays.asList( mInvalidMacAddress1, mInvalidMacAddress2, - mInvalidMacAddress3, mInvalidMacAddress4)); + mInvalidMacAddress3)); HashSet<byte[]> mInvalidMacAddressesBytes = new HashSet<byte[]>(Arrays.asList( mInvalidMacAddressBytes1, mInvalidMacAddressBytes2, mInvalidMacAddressBytes3, mInvalidMacAddressBytes4)); diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java index bb5221730..d7c3b93e3 100644 --- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java @@ -1183,6 +1183,29 @@ public class SupplicantStaIfaceHalTest { verify(mISupplicantStaIfaceMock).startWpsRegistrar(any(byte[].class), anyString()); } + /** + * Tests the start of wps PBC. + */ + @Test + public void testStartWpsPbc() throws Exception { + when(mISupplicantStaIfaceMock.startWpsPbc(any(byte[].class))).thenReturn(mStatusSuccess); + String bssid = "45:23:12:12:12:98"; + byte[] bssidBytes = {0x45, 0x23, 0x12, 0x12, 0x12, (byte) 0x98}; + byte[] anyBssidBytes = {0, 0, 0, 0, 0, 0}; + + // Fail before initialization is performed. + assertFalse(mDut.startWpsPbc(bssid)); + verify(mISupplicantStaIfaceMock, never()).startWpsPbc(any(byte[].class)); + + executeAndValidateInitializationSequence(); + + assertTrue(mDut.startWpsPbc(bssid)); + verify(mISupplicantStaIfaceMock).startWpsPbc(eq(bssidBytes)); + + assertTrue(mDut.startWpsPbc(null)); + verify(mISupplicantStaIfaceMock).startWpsPbc(eq(anyBssidBytes)); + } + private void executeAndValidateHs20DeauthImminentCallback(boolean isEss) throws Exception { executeAndValidateInitializationSequence(); assertNotNull(mISupplicantStaIfaceCallback); diff --git a/tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java index ee48854b1..3f51c5a6a 100644 --- a/tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java +++ b/tests/wifitests/src/com/android/server/wifi/util/NativeUtilTest.java @@ -37,6 +37,17 @@ public class NativeUtilTest { } /** + * Test that parsing an empty MAC address works. + */ + @Test + public void testEmptyMacAddressToByteArray() throws Exception { + assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0}, + NativeUtil.macAddressToByteArray("")); + assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0}, + NativeUtil.macAddressToByteArray(null)); + } + + /** * Test that conversion of byte array of mac address to typical colon-delimited MAC address * works. */ |