コード例 #1
0
    def test_usb_tethering_over_wifi(self):
        """Tests USB tethering over wifi.

    Steps:
    1. Connects to a wifi network
    2. Enables USB tethering
    3. Verifies wifi is preferred upstream over data connection
    """

        wutils.start_wifi_connection_scan_and_ensure_network_found(
            self.dut, self.wifi_network[SSID])
        wutils.wifi_connect(self.dut, self.wifi_network)
        wifi_network = self.dut.droid.connectivityGetActiveNetwork()
        self.log.info("wifi network %s" % wifi_network)

        iflist_before = get_if_list()
        nutils.start_usb_tethering(self.dut)
        self.USB_TETHERED = True
        self.iface = nutils.wait_for_new_iface(iflist_before)
        self.real_hwaddr = get_if_raw_hwaddr(self.iface)

        output = self.dut.adb.shell(DUMSYS_CMD)
        for line in output.split("\n"):
            if UPSTREAM_WANTED_STRING in line:
                asserts.assert_true("true" in line,
                                    "Upstream interface is not active")
                self.log.info("Upstream interface is active")
            if CURRENT_UPSTREAM_STRING in line:
                asserts.assert_true("wlan" in line, "WiFi is not the upstream "
                                    "interface")
                self.log.info("WiFi is the upstream interface")
コード例 #2
0
    def setup_class(self):
        """ Setup wi-fi connection and unpack params
        """
        self.dut = self.android_devices[0]
        required_params = dir(VPN_PARAMS)
        required_params = [
            x for x in required_params if not x.startswith('__')
        ] + ["wifi_network"]
        self.unpack_userparams(req_param_names=required_params)

        wutils.wifi_test_device_init(self.dut)
        wutils.wifi_toggle_state(self.dut, True)
        wutils.start_wifi_connection_scan_and_ensure_network_found(
            self.dut, self.wifi_network["SSID"])
        wutils.wifi_connect(self.dut, self.wifi_network)
        time.sleep(3)

        self.vpn_params = {
            'vpn_username': self.vpn_username,
            'vpn_password': self.vpn_password,
            'psk_secret': self.psk_secret,
            'client_pkcs_file_name': self.client_pkcs_file_name,
            'cert_path_vpnserver': self.cert_path_vpnserver,
            'cert_password': self.cert_password
        }
コード例 #3
0
    def setup_class(self):
        """Setup devices for tests and unpack params."""

        self.dut = self.android_devices[1]
        # remote_server_2 is the host machine to test OnDataCallback and Error
        # callbacks. The server program sends data to the DUT while keepalive
        # is enabled. It also closes the server socket to verify Error callback
        # 'test_tcp_socket_keepalive_on_data_received_wifi' requires this.
        # remote_server is the host machine to test all other test cases.
        # This host listens, accepts connections and verifies the keepalive
        # intervals.
        req_params = ("wifi_network", "remote_server", "remote_server_2")
        self.unpack_userparams(req_params)
        nutils.verify_lte_data_and_tethering_supported(self.dut)
        self.max_ka_net = self.dut.droid.getSupportedKeepalivesForNetwork()
        self.log.info("Max Keepalives for mobile network: %s" % self.max_ka_net)
        wutils.start_wifi_connection_scan_and_ensure_network_found(
            self.dut, self.wifi_network["SSID"])
        wutils.wifi_connect(self.dut, self.wifi_network)
        self.max_ka_wifi = self.dut.droid.getSupportedKeepalivesForNetwork()
        self.log.info("Max Keepalives on wifi network: %s" % self.max_ka_wifi)
        self.kernel_version = self._get_kernel_version(self.dut)
        self.log.info("Kernel version: %s" % self.kernel_version)

        self.host_ip = self.remote_server["ip_addr"]
        self.tcpdump_pid = None
        self.tcp_sockets = []
        self.socket_keepalives = []
        self.gce_tcpdump_pid = None
        self.udp_encap = None
コード例 #4
0
    def test_dns_over_tls_no_reset_packets(self):
        """ Verify there are no TCP packets with RST flags

        Steps:
            1. Enable opportunistic or strict mode
            2. Ping hosts and verify that there are TCP pkts with RST flags
        """
        # start tcpdump on device
        self._start_tcp_dump(self.dut)

        # set private DNS to opportunistic mode
        cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC)

        # connect DUT to wifi network
        wutils.start_wifi_connection_scan_and_ensure_network_found(
            self.dut, self.ipv4_ipv6_network[SSID])
        wutils.wifi_connect(self.dut, self.ipv4_ipv6_network)
        for host in self.ping_hosts:
            wutils.validate_connection(self.dut, host)

        # stop tcpdump on device
        pcap_file = self._stop_tcp_dump(self.dut)

        # check that there no RST TCP packets
        self._verify_rst_packets(pcap_file)
コード例 #5
0
 def test_scan_with_wifi_off_and_location_scan_on(self):
     """Put wifi in scan only mode"""
     self.turn_location_on_and_scan_toggle_on()
     wutils.wifi_toggle_state(self.dut, False)
     """Test wifi connection scan can start and find expected networks."""
     ssid = self.open_network[WifiEnums.SSID_KEY]
     wutils.start_wifi_connection_scan_and_ensure_network_found(
         self.dut, ssid)
 def test_scan(self):
     """Test wifi connection scan can start and find expected networks."""
     ssid = self.open_network_2g[WifiEnums.SSID_KEY]
     wutils.start_wifi_connection_scan_and_ensure_network_found(
         self.dut, ssid)
     ssid = self.open_network_5g[WifiEnums.SSID_KEY]
     wutils.start_wifi_connection_scan_and_ensure_network_found(
         self.dut, ssid)
    def confirm_softap_in_scan_results(self, ap_ssid):
        """Confirm the ap started by wifi tethering is seen in scan results.

        Args:
            ap_ssid: SSID of the ap we are looking for.
        """
        wutils.start_wifi_connection_scan_and_ensure_network_found(
            self.dut_client, ap_ssid)
コード例 #8
0
    def scan_and_connect_by_ssid(self, ad, network):
        """Scan for network and connect using network information.

        Args:
            network: A dictionary representing the network to connect to.

        """
        ssid = network[WifiEnums.SSID_KEY]
        wutils.start_wifi_connection_scan_and_ensure_network_found(ad, ssid)
        wutils.wifi_connect(ad, network, num_of_tries=3)
コード例 #9
0
 def test_softap_5G_wifi_connection_2G_with_location_scan_on(self):
     """Test SoftAp on 5G, connection to 2G network with location scan on."""
     self.configure_ap(channel_2g=WIFI_NETWORK_AP_CHANNEL_2G)
     self.turn_location_on_and_scan_toggle_on()
     self.start_softap_and_connect_to_wifi_network(self.open_2g,
                                                   WIFI_CONFIG_APBAND_5G)
     # Now toggle wifi off & ensure we can still scan.
     wutils.wifi_toggle_state(self.dut, False)
     wutils.start_wifi_connection_scan_and_ensure_network_found(
         self.dut, self.open_2g[WifiEnums.SSID_KEY])
    def scan_and_connect_by_id(self, network, net_id):
        """Scan for network and connect using network id.

        Args:
            net_id: Integer specifying the network id of the network.

        """
        ssid = network[WifiEnums.SSID_KEY]
        wutils.start_wifi_connection_scan_and_ensure_network_found(
            self.dut, ssid)
        wutils.wifi_connect_by_id(self.dut, net_id)
コード例 #11
0
    def connect_to_wifi_network(self, params):
        """Connection logic for open and psk wifi networks.

        Args:
            params: A tuple of network info and AndroidDevice object.
        """
        network, ad = params
        droid = ad.droid
        ed = ad.ed
        SSID = network[WifiEnums.SSID_KEY]
        wutils.start_wifi_connection_scan_and_ensure_network_found(ad, SSID)
        wutils.wifi_connect(ad, network, num_of_tries=3)
コード例 #12
0
 def setup_class(self):
     """ Setup devices for tests and unpack params """
     self.dut = self.android_devices[0]
     req_params = ("proxy_pac", "proxy_server", "proxy_port", "bypass_host",
                   "non_bypass_host", "wifi_network")
     self.unpack_userparams(req_param_names=req_params, )
     wutils.wifi_test_device_init(self.dut)
     wutils.wifi_toggle_state(self.dut, True)
     wutils.start_wifi_connection_scan_and_ensure_network_found(
         self.dut, self.wifi_network["SSID"])
     wutils.wifi_connect(self.dut, self.wifi_network)
     self.tcpdump_pid = None
     self.proxy_port = int(self.proxy_port)
    def test_fail_to_connect_to_wpa_psk_5g_when_not_approved(self):
        """
        Adds a network suggestion and ensure that the device does not
        connect to it until we approve the app.

        Steps:
        1. Send a network suggestion to the device with the app not approved.
        2. Ensure the network is present in scan results, but we don't connect
           to it.
        3. Now approve the app.
        4. Wait for the device to connect to it.
        """
        self.dut.log.info("Adding network suggestions");
        asserts.assert_true(
            self.dut.droid.wifiAddNetworkSuggestions([self.wpa_psk_5g]),
            "Failed to add suggestions")

        # Disable suggestions by the app.
        self.set_approved(False)

        # Ensure the app is not approved.
        asserts.assert_false(
            self.is_approved(),
            "Suggestions should be disabled")

        # Start a new scan to trigger auto-join.
        wutils.start_wifi_connection_scan_and_ensure_network_found(
            self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])

        # Ensure we don't connect to the network.
        asserts.assert_false(
            wutils.wait_for_connect(
                self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY], assert_on_fail=False),
            "Should not connect to network suggestions from unapproved app")

        self.dut.log.info("Enabling suggestions from test");
        # Now Enable suggestions by the app & ensure we connect to the network.
        self.set_approved(True)

        # Ensure the app is approved.
        asserts.assert_true(
            self.is_approved(),
            "Suggestions should be enabled")

        # Start a new scan to trigger auto-join.
        wutils.start_wifi_connection_scan_and_ensure_network_found(
            self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])

        wutils.wait_for_connect(self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
コード例 #14
0
    def start_softap_and_verify(self, band):
        """Bring-up softap and verify AP mode and in scan results.

        Args:
            band: The band to use for softAP.

        """
        config = wutils.create_softap_config()
        wutils.start_wifi_tethering(self.dut,
                                    config[wutils.WifiEnums.SSID_KEY],
                                    config[wutils.WifiEnums.PWD_KEY], band=band)
        asserts.assert_true(self.dut.droid.wifiIsApEnabled(),
                             "SoftAp is not reported as running")
        wutils.start_wifi_connection_scan_and_ensure_network_found(
            self.dut_client, config[wutils.WifiEnums.SSID_KEY])
        return config
コード例 #15
0
    def test_dns_server_link_properties_strict_mode(self):
        """ Verify DNS server in the link properties when set in strict mode

        Steps:
            1. Set DNS server hostname in Private DNS settings (stict mode)
            2. Verify that DNS server set in settings is in link properties
            3. Verify for WiFi as well as LTE
        """
        # start tcpdump on device
        self._start_tcp_dump(self.dut)

        # set private DNS to strict mode
        cutils.set_private_dns(
            self.dut, cconst.PRIVATE_DNS_MODE_STRICT, cconst.DNS_GOOGLE)

        # connect DUT to wifi network
        wutils.start_wifi_connection_scan_and_ensure_network_found(
            self.dut, self.ipv4_ipv6_network[SSID])
        wutils.wifi_connect(self.dut, self.ipv4_ipv6_network)
        for host in self.ping_hosts:
            wutils.validate_connection(self.dut, host)

        # DNS server in link properties for wifi network
        link_prop = self.dut.droid.connectivityGetActiveLinkProperties()
        wifi_dns_servers = link_prop['PrivateDnsServerName']
        self.log.info("Link prop: %s" % wifi_dns_servers)

        # DUT is on LTE data
        wutils.reset_wifi(self.dut)
        time.sleep(1) # wait till lte network becomes active
        for host in self.ping_hosts:
            wutils.validate_connection(self.dut, host)

        # DNS server in link properties for cell network
        link_prop = self.dut.droid.connectivityGetActiveLinkProperties()
        lte_dns_servers = link_prop['PrivateDnsServerName']
        self.log.info("Link prop: %s" % lte_dns_servers)

        # stop tcpdump on device
        pcap_file = self._stop_tcp_dump(self.dut)

        # Verify DNS server in link properties
        asserts.assert_true(cconst.DNS_GOOGLE in wifi_dns_servers,
                            "Hostname not in link properties - wifi network")
        asserts.assert_true(cconst.DNS_GOOGLE in lte_dns_servers,
                            "Hostname not in link properites - cell network")
コード例 #16
0
    def test_stress_softAP_startup_and_stop_5g(self):
        """Test to bring up softAP and down for N times.

        Steps:
            1. Bring up softAP on 5G.
            2. Check for softAP on teh client device.
            3. Turn ON WiFi.
            4. Verify softAP is turned down and WiFi is up.

        """
        ap_ssid = "softap_" + utils.rand_ascii_str(8)
        ap_password = utils.rand_ascii_str(8)
        self.dut.log.info("softap setup: %s %s", ap_ssid, ap_password)
        config = {wutils.WifiEnums.SSID_KEY: ap_ssid}
        config[wutils.WifiEnums.PWD_KEY] = ap_password
        # Set country code explicitly to "US".
        wutils.set_wifi_country_code(self.dut, wutils.WifiEnums.CountryCode.US)
        wutils.set_wifi_country_code(self.dut_client,
                                     wutils.WifiEnums.CountryCode.US)
        for count in range(self.stress_count):
            initial_wifi_state = self.dut.droid.wifiCheckState()
            wutils.start_wifi_tethering(self.dut, ap_ssid, ap_password,
                                        WifiEnums.WIFI_CONFIG_APBAND_5G)
            wutils.start_wifi_connection_scan_and_ensure_network_found(
                self.dut_client, ap_ssid)
            wutils.stop_wifi_tethering(self.dut)
            asserts.assert_false(self.dut.droid.wifiIsApEnabled(),
                                 "SoftAp failed to shutdown!")
            # Give some time for WiFi to come back to previous state.
            time.sleep(2)
            cur_wifi_state = self.dut.droid.wifiCheckState()
            if initial_wifi_state != cur_wifi_state:
                raise signals.TestFailure(
                    "Wifi state was %d before softAP and %d now!" %
                    (initial_wifi_state, cur_wifi_state),
                    extras={
                        "Iterations": "%d" % self.stress_count,
                        "Pass": "******" % count
                    })
        raise signals.TestPass(details="",
                               extras={
                                   "Iterations": "%d" % self.stress_count,
                                   "Pass": "******" % (count + 1)
                               })
    def connect_to_wifi_network_with_id(self, network_id, network_ssid):
        """Connect to the given network using network id and verify SSID.

        Args:
            network_id: int Network Id of the network.
            network_ssid: string SSID of the network.

        Returns: True if connect using network id was successful;
                 False otherwise.

        """
        wutils.start_wifi_connection_scan_and_ensure_network_found(
            self.dut, network_ssid);
        wutils.wifi_connect_by_id(self.dut, network_id)
        connect_data = self.dut.droid.wifiGetConnectionInfo()
        connect_ssid = connect_data[WifiEnums.SSID_KEY]
        self.log.debug("Expected SSID = %s Connected SSID = %s" %
                       (network_ssid, connect_ssid))
        if connect_ssid != network_ssid:
            return False
        return True
コード例 #18
0
    def _test_private_dns_mode(self, ad, net, dns_mode, use_tls, hostname=None):
        """ Test private DNS mode

        Args:
            1. ad: android device object
            2. net: wifi network to connect to, LTE network if None
            3. dns_mode: private DNS mode
            4. use_tls: if True, the DNS packets should be encrypted
            5. hostname: private DNS hostname to set to
        """

        # set private dns mode
        if dns_mode:
            cutils.set_private_dns(self.dut, dns_mode, hostname)

        # connect to wifi
        if net:
            wutils.start_wifi_connection_scan_and_ensure_network_found(
                self.dut, net[SSID])
            wutils.wifi_connect(self.dut, net)

        # start tcpdump on the device
        self._start_tcp_dump(self.dut)

        # ping hosts should pass
        for host in self.ping_hosts:
            self.log.info("Pinging %s" % host)
            status = wutils.validate_connection(self.dut, host)
            asserts.assert_true(status, "Failed to ping host %s" % host)
            self.log.info("Ping successful")

        # stop tcpdump
        pcap_file = self._stop_tcp_dump(self.dut)

        # verify DNS queries
        self._verify_dns_queries_over_tls(pcap_file, use_tls)

        # reset wifi
        wutils.reset_wifi(self.dut)
コード例 #19
0
    def test_stress_softAP_startup_and_stop_5g(self):
        """Test to bring up softAP and down for N times.

        Steps:
            1. Bring up softAP on 5G.
            2. Check for softAP on teh client device.
            3. Turn ON WiFi.
            4. Verify softAP is turned down and WiFi is up.

        """
        ap_ssid = "softap_" + utils.rand_ascii_str(8)
        ap_password = utils.rand_ascii_str(8)
        self.dut.log.info("softap setup: %s %s", ap_ssid, ap_password)
        config = {wutils.WifiEnums.SSID_KEY: ap_ssid}
        config[wutils.WifiEnums.PWD_KEY] = ap_password
        # Set country code explicitly to "US".
        self.dut.droid.wifiSetCountryCode(wutils.WifiEnums.CountryCode.US)
        self.dut_client.droid.wifiSetCountryCode(
            wutils.WifiEnums.CountryCode.US)
        for count in range(self.stress_count):
            initial_wifi_state = self.dut.droid.wifiCheckState()
            wutils.start_wifi_tethering(self.dut, ap_ssid, ap_password,
                                        WifiEnums.WIFI_CONFIG_APBAND_5G)
            wutils.start_wifi_connection_scan_and_ensure_network_found(
                self.dut_client, ap_ssid)
            # Toggle WiFi ON, which inturn calls softAP teardown.
            wutils.wifi_toggle_state(self.dut, True)
            time.sleep(TIMEOUT)
            asserts.assert_false(self.dut.droid.wifiIsApEnabled(),
                                 "SoftAp failed to shutdown!")
            time.sleep(TIMEOUT)
            cur_wifi_state = self.dut.droid.wifiCheckState()
            if initial_wifi_state != cur_wifi_state:
                raise signals.TestFailure(
                    "Wifi state was %d before softAP and %d now!" %
                    (initial_wifi_state, cur_wifi_state))
    def _test_data_usage_downlink(self,
                                  dut_a,
                                  dut_b,
                                  file_link,
                                  data_usage,
                                  tethering=False,
                                  connect_wifi=False,
                                  app_inc=True):
        """Verify data usage.

        Steps:
            1. Get the current data usage of ConnUIDTest and Android OS apps
            2. DUT is on LTE data (on wifi if connect_wifi is True)
            3. Download file of size xMB through ConnUIDTest app
            4. Verify that data usage of Android OS app did not change
            5. Verify that data usage of ConnUIDTest app increased by ~xMB
            6. Verify that data usage of device also increased by ~xMB

        Args:
            dut_a: DUT on which data usage need to be verified
            dut_b: DUT on which data is downloaded
            file_link: Link used to download data
            data_usage: specifies if MOBILE or WIFI data is calculated
            tethering: if True, enable hotspot on dut_a and connect dut_b to it
            connect_wifi: if True, connect dut_a to a wifi network
            app_inc: if True, verify app data usage on dut_a is increased
        """
        if connect_wifi:
            dut_a.droid.telephonyToggleDataConnection(False)
            wutils.start_wifi_connection_scan_and_ensure_network_found(
                dut_a, self.wifi_network["SSID"])
            wutils.wifi_connect(dut_a, self.wifi_network)
            # sleep for some time after connecting to wifi. some apps use wifi
            # data when connected initially. waiting after connecting to wifi
            # ensures correct wifi data usage calculation
            time.sleep(WIFI_SLEEP)

        if tethering:
            ssid = "hs_%s" % utils.rand_ascii_str(AP_SSID_LENGTH_2G)
            pwd = utils.rand_ascii_str(AP_PASSPHRASE_LENGTH_2G)
            network = {wutils.WifiEnums.SSID_KEY: ssid,
                       wutils.WifiEnums.PWD_KEY: pwd}
            dut_b.droid.telephonyToggleDataConnection(False)
            wutils.start_wifi_tethering(dut_a,
                                        network[wutils.WifiEnums.SSID_KEY],
                                        network[wutils.WifiEnums.PWD_KEY])
            self.hs_enabled.append(dut_a)
            wutils.start_wifi_connection_scan_and_ensure_network_found(
                dut_b, network[wutils.WifiEnums.SSID_KEY])
            wutils.wifi_connect(dut_b, network)
            # sleep for some time after connecting to wifi. though wifi hotspot
            # is metered, some apps would still use wifi data when connected
            # initially. this ensures correct wifi data usage calculation
            time.sleep(WIFI_SLEEP)

        # get pre data usage
        (aos_pre, app_pre, total_pre) = self._get_data_usage(dut_a, data_usage)

        # download file through app
        status = self._download_data_through_app(dut_b, file_link)
        asserts.assert_true(status, "Failed to download file: %s" % file_link)

        # get new data usage
        aos_exp = DATA_ERR
        app_exp = self.file_size + DATA_USG_ERR
        file_size = self.file_size
        if not app_inc:
            app_exp = DATA_ERR
            file_size = 0
        total_exp = self.file_size + DATA_USG_ERR

        # somtimes data usage is not increased immediately.
        # re-tries until the data usage is closed to expected value.
        curr_time = time.time()
        while time.time() < curr_time + TIMEOUT:
            (aos_pst, app_pst, total_pst) = self._get_data_usage(dut_a,
                                                                 data_usage)
            if total_pst - total_pre >= self.file_size and \
                app_pst - app_pre >= file_size:
                  # wait for some time to verify that data doesn't increase
                  time.sleep(RETRY_SLEEP*2)
                  break
            time.sleep(RETRY_SLEEP)  # wait before retry
        (aos_pst, app_pst, total_pst) = self._get_data_usage(dut_a, data_usage)

        # verify data usage
        aos_diff = aos_pst - aos_pre
        app_diff = app_pst - app_pre
        total_diff = total_pst - total_pre
        self.log.info("Usage of Android OS increased: %sMB, expected: %sMB" % \
                      (aos_diff, aos_exp))
        self.log.info("Usage of ConnUID app increased: %sMB, expected: %sMB" % \
                      (app_diff, app_exp))
        self.log.info("Usage on the device increased: %sMB, expected: %sMB" % \
                      (total_diff, total_exp))

        asserts.assert_true(
            (aos_diff < aos_exp) and (file_size <= app_diff < app_exp) and \
                (self.file_size <= total_diff < total_exp),
            "Incorrect data usage count")
 def test_connect_to_wpa3_personal_5g(self):
     wutils.start_wifi_connection_scan_and_ensure_network_found(
         self.dut, self.wpa3_personal_5g[WifiEnums.SSID_KEY])
     wutils.connect_to_wifi_network(self.dut, self.owe_5g)
    def test_rtt_to_soft_ap(self):
        """Set up a Soft AP on one device and try performing an RTT ranging to it
    from another device. The attempt must fail - RTT on Soft AP must be
    disabled."""
        sap = self.android_devices[0]
        sap.pretty_name = "SoftAP"
        client = self.android_devices[1]
        client.pretty_name = "Client"

        # start Soft AP
        wutils.start_wifi_tethering(sap,
                                    self.SOFT_AP_SSID,
                                    self.SOFT_AP_PASSWORD,
                                    band=WIFI_CONFIG_APBAND_5G,
                                    hidden=False)

        try:
            # start scanning on the client
            wutils.start_wifi_connection_scan_and_ensure_network_found(
                client, self.SOFT_AP_SSID)
            scans = client.droid.wifiGetScanResults()
            scanned_softap = None
            for scanned_ap in scans:
                if scanned_ap[wutils.WifiEnums.SSID_KEY] == self.SOFT_AP_SSID:
                    scanned_softap = scanned_ap
                    break

            asserts.assert_false(scanned_softap == None,
                                 "Soft AP not found in scan!",
                                 extras=scans)

            # validate that Soft AP does not advertise 802.11mc support
            asserts.assert_false(
                rconsts.SCAN_RESULT_KEY_RTT_RESPONDER in scanned_softap
                and scanned_softap[rconsts.SCAN_RESULT_KEY_RTT_RESPONDER],
                "Soft AP advertises itself as supporting 802.11mc!",
                extras=scanned_softap)

            # falsify the SoftAP's support for IEEE 802.11 so we try a 2-sided RTT
            scanned_softap[
                rconsts.SCAN_RESULT_KEY_RTT_RESPONDER] = True  # falsify

            # actually try ranging to the Soft AP
            events = rutils.run_ranging(client, [scanned_softap],
                                        self.NUM_ITER, 0)
            stats = rutils.analyze_results(
                events, self.rtt_reference_distance_mm,
                self.rtt_reference_distance_margin_mm,
                self.rtt_min_expected_rssi_dbm, self.lci_reference,
                self.lcr_reference)

            asserts.assert_equal(
                stats[scanned_ap[wutils.WifiEnums.BSSID_KEY]]['num_failures'],
                self.NUM_ITER,
                "Some RTT operations to Soft AP succeed!?",
                extras=stats)

            asserts.explicit_pass("SoftAP + RTT validation done",
                                  extras=events)
        finally:
            wutils.stop_wifi_tethering(sap)
    def _test_data_usage_limit_downlink(self,
                                        dut_a,
                                        dut_b,
                                        file_link,
                                        data_usage,
                                        tethering=False):
        """Verify data usage limit reached.

        Steps:
            1. Set the data usage limit to current data usage + 10MB
            2. If tested for tethered device, start wifi hotspot and
               connect DUT to it.
            3. If tested for tethered device, download 20MB data from
               tethered device else download on the same DUT
            4. Verify file download stops and data limit reached

        Args:
            dut_a: DUT on which data usage limit needs to be verified
            dut_b: DUT on which data needs to be downloaded
            file_link: specifies if the link is IPv4 or IPv6
            data_usage: specifies if MOBILE or WIFI data usage
            tethering: if wifi hotspot should be enabled on dut_a
        """
        sub_id = str(dut_a.droid.telephonyGetSubscriberId())

        # enable hotspot and connect dut_b to it.
        if tethering:
            ssid = "hs_%s" % utils.rand_ascii_str(AP_SSID_LENGTH_2G)
            pwd = utils.rand_ascii_str(AP_PASSPHRASE_LENGTH_2G)
            network = {wutils.WifiEnums.SSID_KEY: ssid,
                       wutils.WifiEnums.PWD_KEY: pwd}
            dut_b.droid.telephonyToggleDataConnection(False)
            wutils.start_wifi_tethering(dut_a,
                                        network[wutils.WifiEnums.SSID_KEY],
                                        network[wutils.WifiEnums.PWD_KEY])
            self.hs_enabled.append(dut_a)
            wutils.start_wifi_connection_scan_and_ensure_network_found(
                dut_b, network[wutils.WifiEnums.SSID_KEY])
            wutils.wifi_connect(dut_b, network)

        # get pre mobile data usage
        total_pre = self._get_total_data_usage_for_device(dut_a, data_usage)

        # set data usage limit to current usage limit + 10MB
        self.log.info("Set data usage limit to %sMB" % (total_pre + INC_DATA))
        dut_a.droid.connectivitySetDataUsageLimit(
            sub_id, int((total_pre + INC_DATA) * BYTE_TO_MB_ANDROID))

        # download file on dut_b and look for BlockedStatusChanged callback
        q = queue.Queue()
        t = threading.Thread(target=self._listen_for_network_callback,
                             args=(dut_a, "BlockedStatusChanged", q))
        t.daemon = True
        t.start()
        status = http_file_download_by_chrome(
            dut_b, file_link, self.file_size, True, TIMEOUT)
        t.join()
        cb_res = q.get()

        # verify file download fails and expected callback is recevied
        asserts.assert_true(cb_res,
                            "Failed to verify blocked status network callback")
        asserts.assert_true(not status,
                            "File download successful. Expected to fail")