Loading wifi/java/android/net/wifi/ScanResult.java +2 −0 Original line number Original line Diff line number Diff line Loading @@ -402,12 +402,14 @@ public class ScanResult implements Parcelable { public static final int EID_TIM = 5; public static final int EID_TIM = 5; public static final int EID_BSS_LOAD = 11; public static final int EID_BSS_LOAD = 11; public static final int EID_ERP = 42; public static final int EID_ERP = 42; public static final int EID_HT_CAPABILITIES = 45; public static final int EID_RSN = 48; public static final int EID_RSN = 48; public static final int EID_EXTENDED_SUPPORTED_RATES = 50; public static final int EID_EXTENDED_SUPPORTED_RATES = 50; public static final int EID_HT_OPERATION = 61; public static final int EID_HT_OPERATION = 61; public static final int EID_INTERWORKING = 107; public static final int EID_INTERWORKING = 107; public static final int EID_ROAMING_CONSORTIUM = 111; public static final int EID_ROAMING_CONSORTIUM = 111; public static final int EID_EXTENDED_CAPS = 127; public static final int EID_EXTENDED_CAPS = 127; public static final int EID_VHT_CAPABILITIES = 191; public static final int EID_VHT_OPERATION = 192; public static final int EID_VHT_OPERATION = 192; public static final int EID_VSA = 221; public static final int EID_VSA = 221; Loading wifi/java/android/net/wifi/rtt/ResponderConfig.java +28 −4 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,9 @@ package android.net.wifi.rtt; package android.net.wifi.rtt; import static android.net.wifi.ScanResult.InformationElement.EID_HT_CAPABILITIES; import static android.net.wifi.ScanResult.InformationElement.EID_VHT_CAPABILITIES; import android.annotation.IntDef; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.NonNull; import android.annotation.SystemApi; import android.annotation.SystemApi; Loading @@ -24,6 +27,7 @@ import android.net.wifi.ScanResult; import android.net.wifi.aware.PeerHandle; import android.net.wifi.aware.PeerHandle; import android.os.Parcel; import android.os.Parcel; import android.os.Parcelable; import android.os.Parcelable; import android.util.Log; import java.lang.annotation.Retention; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy; Loading @@ -40,6 +44,7 @@ import java.util.Objects; */ */ @SystemApi @SystemApi public final class ResponderConfig implements Parcelable { public final class ResponderConfig implements Parcelable { private static final String TAG = "ResponderConfig"; private static final int AWARE_BAND_2_DISCOVERY_CHANNEL = 2437; private static final int AWARE_BAND_2_DISCOVERY_CHANNEL = 2437; /** @hide */ /** @hide */ Loading Loading @@ -297,13 +302,32 @@ public final class ResponderConfig implements Parcelable { int centerFreq0 = scanResult.centerFreq0; int centerFreq0 = scanResult.centerFreq0; int centerFreq1 = scanResult.centerFreq1; int centerFreq1 = scanResult.centerFreq1; // TODO: b/68936111 - extract preamble info from IE int preamble; int preamble; if (scanResult.informationElements != null && scanResult.informationElements.length != 0) { boolean htCapabilitiesPresent = false; boolean vhtCapabilitiesPresent = false; for (ScanResult.InformationElement ie : scanResult.informationElements) { if (ie.id == EID_HT_CAPABILITIES) { htCapabilitiesPresent = true; } else if (ie.id == EID_VHT_CAPABILITIES) { vhtCapabilitiesPresent = true; } } if (vhtCapabilitiesPresent) { preamble = PREAMBLE_VHT; } else if (htCapabilitiesPresent) { preamble = PREAMBLE_HT; } else { preamble = PREAMBLE_LEGACY; } } else { Log.e(TAG, "Scan Results do not contain IEs - using backup method to select preamble"); if (channelWidth == CHANNEL_WIDTH_80MHZ || channelWidth == CHANNEL_WIDTH_160MHZ) { if (channelWidth == CHANNEL_WIDTH_80MHZ || channelWidth == CHANNEL_WIDTH_160MHZ) { preamble = PREAMBLE_VHT; preamble = PREAMBLE_VHT; } else { } else { preamble = PREAMBLE_HT; preamble = PREAMBLE_HT; } } } return new ResponderConfig(macAddress, responderType, supports80211mc, channelWidth, return new ResponderConfig(macAddress, responderType, supports80211mc, channelWidth, frequency, centerFreq0, centerFreq1, preamble); frequency, centerFreq0, centerFreq1, preamble); Loading wifi/tests/src/android/net/wifi/rtt/WifiRttManagerTest.java +92 −0 Original line number Original line Diff line number Diff line Loading @@ -295,4 +295,96 @@ public class WifiRttManagerTest { assertEquals(rr1, rr2); assertEquals(rr1, rr2); } } /** * Validate that ResponderConfig parcel works (produces same object on write/read). */ @Test public void testResponderConfigParcel() { // ResponderConfig constructed with a MAC address ResponderConfig config = new ResponderConfig(MacAddress.fromString("00:01:02:03:04:05"), ResponderConfig.RESPONDER_AP, true, ResponderConfig.CHANNEL_WIDTH_80MHZ, 2134, 2345, 2555, ResponderConfig.PREAMBLE_LEGACY); Parcel parcelW = Parcel.obtain(); config.writeToParcel(parcelW, 0); byte[] bytes = parcelW.marshall(); parcelW.recycle(); Parcel parcelR = Parcel.obtain(); parcelR.unmarshall(bytes, 0, bytes.length); parcelR.setDataPosition(0); ResponderConfig rereadConfig = ResponderConfig.CREATOR.createFromParcel(parcelR); assertEquals(config, rereadConfig); // ResponderConfig constructed with a PeerHandle config = new ResponderConfig(new PeerHandle(10), ResponderConfig.RESPONDER_AWARE, false, ResponderConfig.CHANNEL_WIDTH_80MHZ_PLUS_MHZ, 5555, 6666, 7777, ResponderConfig.PREAMBLE_VHT); parcelW = Parcel.obtain(); config.writeToParcel(parcelW, 0); bytes = parcelW.marshall(); parcelW.recycle(); parcelR = Parcel.obtain(); parcelR.unmarshall(bytes, 0, bytes.length); parcelR.setDataPosition(0); rereadConfig = ResponderConfig.CREATOR.createFromParcel(parcelR); assertEquals(config, rereadConfig); } /** * Validate preamble selection from ScanResults. */ @Test public void testResponderPreambleSelection() { ScanResult.InformationElement htCap = new ScanResult.InformationElement(); htCap.id = ScanResult.InformationElement.EID_HT_CAPABILITIES; ScanResult.InformationElement vhtCap = new ScanResult.InformationElement(); vhtCap.id = ScanResult.InformationElement.EID_VHT_CAPABILITIES; ScanResult.InformationElement vsa = new ScanResult.InformationElement(); vsa.id = ScanResult.InformationElement.EID_VSA; // no IE ScanResult scan = new ScanResult(); scan.BSSID = "00:01:02:03:04:05"; scan.informationElements = null; scan.channelWidth = ResponderConfig.CHANNEL_WIDTH_80MHZ; ResponderConfig config = ResponderConfig.fromScanResult(scan); assertEquals(ResponderConfig.PREAMBLE_VHT, config.preamble); // IE with HT & VHT scan.channelWidth = ResponderConfig.CHANNEL_WIDTH_40MHZ; scan.informationElements = new ScanResult.InformationElement[2]; scan.informationElements[0] = htCap; scan.informationElements[1] = vhtCap; config = ResponderConfig.fromScanResult(scan); assertEquals(ResponderConfig.PREAMBLE_VHT, config.preamble); // IE with some entries but no HT or VHT scan.informationElements[0] = vsa; scan.informationElements[1] = vsa; config = ResponderConfig.fromScanResult(scan); assertEquals(ResponderConfig.PREAMBLE_LEGACY, config.preamble); // IE with HT scan.informationElements[0] = vsa; scan.informationElements[1] = htCap; config = ResponderConfig.fromScanResult(scan); assertEquals(ResponderConfig.PREAMBLE_HT, config.preamble); } } } Loading
wifi/java/android/net/wifi/ScanResult.java +2 −0 Original line number Original line Diff line number Diff line Loading @@ -402,12 +402,14 @@ public class ScanResult implements Parcelable { public static final int EID_TIM = 5; public static final int EID_TIM = 5; public static final int EID_BSS_LOAD = 11; public static final int EID_BSS_LOAD = 11; public static final int EID_ERP = 42; public static final int EID_ERP = 42; public static final int EID_HT_CAPABILITIES = 45; public static final int EID_RSN = 48; public static final int EID_RSN = 48; public static final int EID_EXTENDED_SUPPORTED_RATES = 50; public static final int EID_EXTENDED_SUPPORTED_RATES = 50; public static final int EID_HT_OPERATION = 61; public static final int EID_HT_OPERATION = 61; public static final int EID_INTERWORKING = 107; public static final int EID_INTERWORKING = 107; public static final int EID_ROAMING_CONSORTIUM = 111; public static final int EID_ROAMING_CONSORTIUM = 111; public static final int EID_EXTENDED_CAPS = 127; public static final int EID_EXTENDED_CAPS = 127; public static final int EID_VHT_CAPABILITIES = 191; public static final int EID_VHT_OPERATION = 192; public static final int EID_VHT_OPERATION = 192; public static final int EID_VSA = 221; public static final int EID_VSA = 221; Loading
wifi/java/android/net/wifi/rtt/ResponderConfig.java +28 −4 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,9 @@ package android.net.wifi.rtt; package android.net.wifi.rtt; import static android.net.wifi.ScanResult.InformationElement.EID_HT_CAPABILITIES; import static android.net.wifi.ScanResult.InformationElement.EID_VHT_CAPABILITIES; import android.annotation.IntDef; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.NonNull; import android.annotation.SystemApi; import android.annotation.SystemApi; Loading @@ -24,6 +27,7 @@ import android.net.wifi.ScanResult; import android.net.wifi.aware.PeerHandle; import android.net.wifi.aware.PeerHandle; import android.os.Parcel; import android.os.Parcel; import android.os.Parcelable; import android.os.Parcelable; import android.util.Log; import java.lang.annotation.Retention; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy; Loading @@ -40,6 +44,7 @@ import java.util.Objects; */ */ @SystemApi @SystemApi public final class ResponderConfig implements Parcelable { public final class ResponderConfig implements Parcelable { private static final String TAG = "ResponderConfig"; private static final int AWARE_BAND_2_DISCOVERY_CHANNEL = 2437; private static final int AWARE_BAND_2_DISCOVERY_CHANNEL = 2437; /** @hide */ /** @hide */ Loading Loading @@ -297,13 +302,32 @@ public final class ResponderConfig implements Parcelable { int centerFreq0 = scanResult.centerFreq0; int centerFreq0 = scanResult.centerFreq0; int centerFreq1 = scanResult.centerFreq1; int centerFreq1 = scanResult.centerFreq1; // TODO: b/68936111 - extract preamble info from IE int preamble; int preamble; if (scanResult.informationElements != null && scanResult.informationElements.length != 0) { boolean htCapabilitiesPresent = false; boolean vhtCapabilitiesPresent = false; for (ScanResult.InformationElement ie : scanResult.informationElements) { if (ie.id == EID_HT_CAPABILITIES) { htCapabilitiesPresent = true; } else if (ie.id == EID_VHT_CAPABILITIES) { vhtCapabilitiesPresent = true; } } if (vhtCapabilitiesPresent) { preamble = PREAMBLE_VHT; } else if (htCapabilitiesPresent) { preamble = PREAMBLE_HT; } else { preamble = PREAMBLE_LEGACY; } } else { Log.e(TAG, "Scan Results do not contain IEs - using backup method to select preamble"); if (channelWidth == CHANNEL_WIDTH_80MHZ || channelWidth == CHANNEL_WIDTH_160MHZ) { if (channelWidth == CHANNEL_WIDTH_80MHZ || channelWidth == CHANNEL_WIDTH_160MHZ) { preamble = PREAMBLE_VHT; preamble = PREAMBLE_VHT; } else { } else { preamble = PREAMBLE_HT; preamble = PREAMBLE_HT; } } } return new ResponderConfig(macAddress, responderType, supports80211mc, channelWidth, return new ResponderConfig(macAddress, responderType, supports80211mc, channelWidth, frequency, centerFreq0, centerFreq1, preamble); frequency, centerFreq0, centerFreq1, preamble); Loading
wifi/tests/src/android/net/wifi/rtt/WifiRttManagerTest.java +92 −0 Original line number Original line Diff line number Diff line Loading @@ -295,4 +295,96 @@ public class WifiRttManagerTest { assertEquals(rr1, rr2); assertEquals(rr1, rr2); } } /** * Validate that ResponderConfig parcel works (produces same object on write/read). */ @Test public void testResponderConfigParcel() { // ResponderConfig constructed with a MAC address ResponderConfig config = new ResponderConfig(MacAddress.fromString("00:01:02:03:04:05"), ResponderConfig.RESPONDER_AP, true, ResponderConfig.CHANNEL_WIDTH_80MHZ, 2134, 2345, 2555, ResponderConfig.PREAMBLE_LEGACY); Parcel parcelW = Parcel.obtain(); config.writeToParcel(parcelW, 0); byte[] bytes = parcelW.marshall(); parcelW.recycle(); Parcel parcelR = Parcel.obtain(); parcelR.unmarshall(bytes, 0, bytes.length); parcelR.setDataPosition(0); ResponderConfig rereadConfig = ResponderConfig.CREATOR.createFromParcel(parcelR); assertEquals(config, rereadConfig); // ResponderConfig constructed with a PeerHandle config = new ResponderConfig(new PeerHandle(10), ResponderConfig.RESPONDER_AWARE, false, ResponderConfig.CHANNEL_WIDTH_80MHZ_PLUS_MHZ, 5555, 6666, 7777, ResponderConfig.PREAMBLE_VHT); parcelW = Parcel.obtain(); config.writeToParcel(parcelW, 0); bytes = parcelW.marshall(); parcelW.recycle(); parcelR = Parcel.obtain(); parcelR.unmarshall(bytes, 0, bytes.length); parcelR.setDataPosition(0); rereadConfig = ResponderConfig.CREATOR.createFromParcel(parcelR); assertEquals(config, rereadConfig); } /** * Validate preamble selection from ScanResults. */ @Test public void testResponderPreambleSelection() { ScanResult.InformationElement htCap = new ScanResult.InformationElement(); htCap.id = ScanResult.InformationElement.EID_HT_CAPABILITIES; ScanResult.InformationElement vhtCap = new ScanResult.InformationElement(); vhtCap.id = ScanResult.InformationElement.EID_VHT_CAPABILITIES; ScanResult.InformationElement vsa = new ScanResult.InformationElement(); vsa.id = ScanResult.InformationElement.EID_VSA; // no IE ScanResult scan = new ScanResult(); scan.BSSID = "00:01:02:03:04:05"; scan.informationElements = null; scan.channelWidth = ResponderConfig.CHANNEL_WIDTH_80MHZ; ResponderConfig config = ResponderConfig.fromScanResult(scan); assertEquals(ResponderConfig.PREAMBLE_VHT, config.preamble); // IE with HT & VHT scan.channelWidth = ResponderConfig.CHANNEL_WIDTH_40MHZ; scan.informationElements = new ScanResult.InformationElement[2]; scan.informationElements[0] = htCap; scan.informationElements[1] = vhtCap; config = ResponderConfig.fromScanResult(scan); assertEquals(ResponderConfig.PREAMBLE_VHT, config.preamble); // IE with some entries but no HT or VHT scan.informationElements[0] = vsa; scan.informationElements[1] = vsa; config = ResponderConfig.fromScanResult(scan); assertEquals(ResponderConfig.PREAMBLE_LEGACY, config.preamble); // IE with HT scan.informationElements[0] = vsa; scan.informationElements[1] = htCap; config = ResponderConfig.fromScanResult(scan); assertEquals(ResponderConfig.PREAMBLE_HT, config.preamble); } } }