wifi: Check multicast mac address when setting SAP bssid

Bug: 159589542
Test: atest frameworks/base/wifi/tests/
Test: atest FrameworksWifiTests
Change-Id: I53cdd2856b2f013a3d572048301f398086a2c709
This commit is contained in:
lesl
2020-06-24 14:35:21 +08:00
parent 32df476f71
commit a00833349c
2 changed files with 24 additions and 5 deletions

View File

@@ -724,14 +724,17 @@ public final class SoftApConfiguration implements Parcelable {
* @param bssid BSSID, or null to have the BSSID chosen by the framework. The caller is
* responsible for avoiding collisions.
* @return Builder for chaining.
* @throws IllegalArgumentException when the given BSSID is the all-zero or broadcast MAC
* address.
* @throws IllegalArgumentException when the given BSSID is the all-zero
* , multicast or broadcast MAC address.
*/
@NonNull
public Builder setBssid(@Nullable MacAddress bssid) {
if (bssid != null) {
Preconditions.checkArgument(!bssid.equals(WifiManager.ALL_ZEROS_MAC_ADDRESS));
Preconditions.checkArgument(!bssid.equals(MacAddress.BROADCAST_ADDRESS));
if (bssid.getAddressType() != MacAddress.TYPE_UNICAST) {
throw new IllegalArgumentException("bssid doesn't support "
+ "multicast or broadcast mac address");
}
}
mBssid = bssid;
return this;

View File

@@ -35,6 +35,7 @@ import java.util.Random;
@SmallTest
public class SoftApConfigurationTest {
private static final String TEST_CHAR_SET_AS_STRING = "abcdefghijklmnopqrstuvwxyz0123456789";
private static final String TEST_BSSID = "aa:22:33:aa:bb:cc";
private SoftApConfiguration parcelUnparcel(SoftApConfiguration configIn) {
Parcel parcel = Parcel.obtain();
@@ -67,12 +68,13 @@ public class SoftApConfigurationTest {
@Test
public void testBasicSettings() {
MacAddress testBssid = MacAddress.fromString(TEST_BSSID);
SoftApConfiguration original = new SoftApConfiguration.Builder()
.setSsid("ssid")
.setBssid(MacAddress.fromString("11:22:33:44:55:66"))
.setBssid(testBssid)
.build();
assertThat(original.getSsid()).isEqualTo("ssid");
assertThat(original.getBssid()).isEqualTo(MacAddress.fromString("11:22:33:44:55:66"));
assertThat(original.getBssid()).isEqualTo(testBssid);
assertThat(original.getPassphrase()).isNull();
assertThat(original.getSecurityType()).isEqualTo(SoftApConfiguration.SECURITY_TYPE_OPEN);
assertThat(original.getBand()).isEqualTo(SoftApConfiguration.BAND_2GHZ);
@@ -220,6 +222,20 @@ public class SoftApConfigurationTest {
assertThat(copy.hashCode()).isEqualTo(original.hashCode());
}
@Test(expected = IllegalArgumentException.class)
public void testInvalidBroadcastBssid() {
SoftApConfiguration original = new SoftApConfiguration.Builder()
.setBssid(MacAddress.BROADCAST_ADDRESS)
.build();
}
@Test(expected = IllegalArgumentException.class)
public void testInvalidMulticastBssid() {
SoftApConfiguration original = new SoftApConfiguration.Builder()
.setBssid(MacAddress.fromString("01:aa:bb:cc:dd:ee"))
.build();
}
@Test(expected = IllegalArgumentException.class)
public void testInvalidShortPasswordLengthForWpa2() {
SoftApConfiguration original = new SoftApConfiguration.Builder()