def test_autojoin_out_of_range(self):
        """Test wifi auto join functionality move to low range.

         1. Attenuate the signal to out of range.
         2. Wake up the device.
         3. Start the scan.
         4. Check that device is not connected to any network.
        """
        self.attenuators[0].set_atten(90)
        self.attenuators[1].set_atten(90)
        self.attenuators[2].set_atten(90)
        self.dut.droid.wakeLockAcquireBright()
        self.dut.droid.wakeUpNow()
        try:
            wutils.start_wifi_connection_scan(self.dut)
            wifi_results = self.dut.droid.wifiGetScanResults()
            self.log.debug("Scan result {}".format(wifi_results))
            time.sleep(20)
            current_network = self.dut.droid.wifiGetConnectionInfo()
            self.log.info("Current network: {}".format(current_network))
            asserts.assert_true(
                ('network_id' in current_network
                 and current_network['network_id'] == -1),
                "Device is connected to network {}".format(current_network))
        finally:
            self.dut.droid.wifiLockRelease()
            self.dut.droid.goToSleepNow()
Exemplo n.º 2
0
    def check_passpoint_connection(self, passpoint_network):
        """Verify the device is automatically able to connect to the Passpoint
           network.

           Args:
               passpoint_network: SSID of the Passpoint network.

        """
        ad = self.dut
        ad.ed.clear_all_events()
        wutils.start_wifi_connection_scan(ad)
        scan_results = ad.droid.wifiGetScanResults()
        # Wait for scan to complete.
        time.sleep(5)
        ssid = passpoint_network
        wutils.assert_network_in_list({WifiEnums.SSID_KEY: ssid}, scan_results)
        # Passpoint network takes longer time to connect than normal networks.
        # Every try comes with a timeout of 30s. Setting total timeout to 120s.
        wutils.wifi_passpoint_connect(self.dut,
                                      passpoint_network,
                                      num_of_tries=4)
        # Re-verify we are connected to the correct network.
        network_info = self.dut.droid.wifiGetConnectionInfo()
        if network_info[WifiEnums.SSID_KEY] != passpoint_network:
            raise signals.TestFailure("Device did not connect to the passpoint"
                                      " network.")
    def connect_and_verify_connected_bssid(self, expected_bssid):
        """Start a scan to get the DUT connected to an AP and verify the DUT
        is connected to the correct BSSID.

        Args:
            expected_bssid: Network bssid to which connection.

        Returns:
            True if connection to given network happen, else return False.
        """
        #wait for the attenuator to stablize
        time.sleep(10)
        #force start a single scan so we don't have to wait for the
        #WCM scheduled scan.
        wutils.start_wifi_connection_scan(self.dut)
        #wait for connection
        time.sleep(20)
        #verify connection
        actual_network = self.dut.droid.wifiGetConnectionInfo()
        logging.info("Actual network: %s", actual_network)
        try:
            asserts.assert_equal(expected_bssid,
                                 actual_network[WifiEnums.BSSID_KEY])
        except:
           msg = "Device did not connect to any network."
           raise signals.TestFailure(msg)
    def test_autojoin_in_blacklist_AP(self):
        """Test wifi auto join functionality in high range of blacklist BSSID.

         1. Attenuate the signal to out of range of AP1 and full range of AP3.
         2. Wake up the device.
         3. Check that device is disconnected form all AP.
        """
        attn0, attn1, attn2 = self.atten_val["In_blacklist"]
        self.attenuators[0].set_atten(attn0)
        self.attenuators[1].set_atten(attn1)
        self.attenuators[2].set_atten(attn2)
        self.dut.droid.wakeLockAcquireBright()
        self.dut.droid.wakeUpNow()
        try:
            wutils.start_wifi_connection_scan(self.dut)
            wifi_results = self.dut.droid.wifiGetScanResults()
            self.log.debug("Scan result {}".format(wifi_results))
            time.sleep(20)
            current_network = self.dut.droid.wifiGetConnectionInfo()
            self.log.info("Current network: {}".format(current_network))
            asserts.assert_true(
                ('network_id' in current_network
                 and current_network['network_id'] == -1),
                "Device is still connected to blacklisted network {}".format(
                    current_network))
        finally:
            self.dut.droid.wifiLockRelease()
            self.dut.droid.goToSleepNow()
Exemplo n.º 5
0
 def test_scan(self):
     """Test wifi connection scan can start and find expected networks."""
     wutils.wifi_toggle_state(self.dut, True)
     self.log.debug("Start regular wifi scan.")
     wutils.start_wifi_connection_scan(self.dut)
     wifi_results = self.dut.droid.wifiGetScanResults()
     self.log.debug("Scan results: %s", wifi_results)
     ssid = self.open_network[WifiEnums.SSID_KEY]
     wutils.assert_network_in_list({WifiEnums.SSID_KEY: ssid}, wifi_results)
Exemplo n.º 6
0
 def test_scan(self):
     """Test wifi connection scan can start and find expected networks."""
     wutils.wifi_toggle_state(self.dut, True)
     self.log.debug("Start regular wifi scan.")
     wutils.start_wifi_connection_scan(self.dut)
     wifi_results = self.dut.droid.wifiGetScanResults()
     self.log.debug("Scan results: %s" % wifi_results)
     ssid = self.open_network[WifiEnums.SSID_KEY]
     condition = {WifiEnums.SSID_KEY: ssid}
     asserts.assert_true(wutils.match_networks(condition, wifi_results),
                         "Can not find expected network %s" % ssid)
Exemplo n.º 7
0
    def connect_to_wifi_network(self, network):
        """Connection logic for open and psk wifi networks.

        Args:
            params: Dictionary with network info.
        """
        SSID = network[WifiEnums.SSID_KEY]
        self.dut.ed.clear_all_events()
        wutils.start_wifi_connection_scan(self.dut)
        scan_results = self.dut.droid.wifiGetScanResults()
        wutils.assert_network_in_list({WifiEnums.SSID_KEY: SSID}, scan_results)
        wutils.wifi_connect(self.dut, network, num_of_tries=3)
Exemplo n.º 8
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]
        ed.clear_all_events()
        wutils.start_wifi_connection_scan(ad)
        scan_results = droid.wifiGetScanResults()
        wutils.assert_network_in_list({WifiEnums.SSID_KEY: SSID}, scan_results)
        wutils.wifi_connect(ad, network, num_of_tries=3)
    def regular_scan_for_rtt_networks(self):
        """Scans for 11mc-capable WiFi networks using regular wifi scan.

        Networks are selected based on self.network_selector.

        Returns:
            A list of networks that have RTTResponders.
        """
        wutils.start_wifi_connection_scan(self.dut)
        networks = self.dut.droid.wifiGetScanResults()
        rtt_networks = []
        for nw in networks:
            if self.network_selector(nw):
                rtt_networks.append(nw)
        return rtt_networks
Exemplo n.º 10
0
    def connect_to_wifi(self, ad, network):
        """Connection logic for open and psk wifi networks.

        Args:
            ad: Android device object.
            network: A JSON dict of the WiFi network configuration.

        """
        ad.ed.clear_all_events()
        wifi_utils.start_wifi_connection_scan(ad)
        scan_results = ad.droid.wifiGetScanResults()
        wifi_utils.assert_network_in_list(
            {WifiEnums.SSID_KEY: self.wifi_network_ssid}, scan_results)
        wifi_utils.wifi_connect(ad, network)
        self.log.debug("Connected to %s network on %s device" %
                       (network[WifiEnums.SSID_KEY], ad.serial))
Exemplo n.º 11
0
def scan_networks(dut, max_tries=3):
    """Perform a scan and return scan results.

  Args:
    dut: Device under test.
    max_retries: Retry scan to ensure network is found

  Returns: an array of scan results.
  """
    scan_results = []
    for num_tries in range(max_tries):
        wutils.start_wifi_connection_scan(dut)
        scan_results = dut.droid.wifiGetScanResults()
        if scan_results:
            break
    return scan_results
    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.
        """
        #TODO(silberst): debug and remove the extra scan before submitting this test
        wutils.start_wifi_connection_scan(self.dut_client)
        client_scan_results = self.dut_client.droid.wifiGetScanResults()
        wutils.start_wifi_connection_scan(self.dut_client)
        client_scan_results = self.dut_client.droid.wifiGetScanResults()
        for result in client_scan_results:
            self.log.debug("scan found: %s", result[wutils.WifiEnums.SSID_KEY])

        asserts.assert_true(wutils.match_networks(
                {wutils.WifiEnums.SSID_KEY: ap_ssid}, client_scan_results),
                "Did not find SSID in scan results")
Exemplo n.º 13
0
    def test_energy_info(self):
        """Verify the WiFi energy info reporting feature.

        Steps:
            1. Check that the WiFi energy info reporting support on this device
               is as expected (support or not).
            2. If the device does not support energy info reporting as
               expected, skip the test.
            3. Call API to get WiFi energy info.
            4. Verify the values of "ControllerEnergyUsed" and
               "ControllerIdleTimeMillis" in energy info don't decrease.
            5. Repeat from Step 3 for 10 times.
        """
        # Check if dut supports energy info reporting.
        actual_support = self.dut.droid.wifiIsEnhancedPowerReportingSupported()
        model = self.dut.model
        expected_support = model in self.energy_info_models
        msg = "Expect energy info support to be %s on %s, got %s." % (
            expected_support, model, actual_support)
        asserts.assert_true(actual_support == expected_support, msg)
        if not actual_support:
            asserts.skip(
                ("Device %s does not support energy info reporting as "
                 "expected.") % model)
        # Verify reported values don't decrease.
        self.log.info(("Device %s supports energy info reporting, verify that "
                       "the reported values don't decrease.") % model)
        energy = 0
        idle_time = 0
        for i in range(10):
            info = self.dut.droid.wifiGetControllerActivityEnergyInfo()
            self.log.debug("Iteration %d, got energy info: %s" % (i, info))
            new_energy = info["ControllerEnergyUsed"]
            new_idle_time = info["ControllerIdleTimeMillis"]
            asserts.assert_true(
                new_energy >= energy,
                "Energy value decreased: previous %d, now %d" %
                (energy, new_energy))
            energy = new_energy
            asserts.assert_true(
                new_idle_time >= idle_time,
                "Idle time decreased: previous %d, now %d" %
                (idle_time, new_idle_time))
            idle_time = new_idle_time
            wutils.start_wifi_connection_scan(self.dut)
Exemplo n.º 14
0
    def check_hiddenSSID_in_scan(self, ap_ssid, max_tries=2):
        """Check if the ap started by wifi tethering is seen in scan results.

        Args:
            ap_ssid: SSID of the ap we are looking for.
            max_tries: Number of scans to try.
        Returns:
            True: if ap_ssid is found in scan results.
            False: if ap_ssid is not found in scan results.
        """
        for num_tries in range(max_tries):
            wutils.start_wifi_connection_scan(self.dut)
            scan_results = self.dut.droid.wifiGetScanResults()
            match_results = wutils.match_networks(
                {wutils.WifiEnums.SSID_KEY: ap_ssid}, scan_results)
            if len(match_results) > 0:
                return True
        return False
    def test_discovery(self):
        """Make sure all the expected 11mc BSSIDs are discovered properly, and
        they are all reported as 802.11mc Rtt Responder.

        Procedures:
            1. Scan for wifi networks.

        Expect:
            All the RTT networks show up in scan results and their
            "is80211McRTTResponder" is True.
            All the non-RTT networks show up in scan results and their
            "is80211McRTTResponder" is False.
        """
        wutils.start_wifi_connection_scan(self.dut)
        scan_results = self.dut.droid.wifiGetScanResults()
        self.log.debug(scan_results)
        for n in visible_networks:
            asserts.assert_true(wutils.match_networks(n, scan_results),
                                "Network %s was not discovered properly." % n)
        return True
Exemplo n.º 16
0
    def test_check_mac_in_wifi_scan(self):
        """Test to ensure Factory MAC is not exposed, in Wi-Fi scans

        Steps:
          1. Configure and start the sniffer on both bands.
          2. Perform a full scan.
          3. Stop the sniffer.
          4. Invoke scapy to read the .pcap file.
          5. Read each packet summary and make sure Factory MAC is not used.

        """
        self.pcap_procs = wutils.start_pcap(self.packet_capture, 'dual',
                                            self.test_name)
        wutils.start_wifi_connection_scan(self.dut)
        time.sleep(SHORT_TIMEOUT)
        wutils.stop_pcap(self.packet_capture, self.pcap_procs, False)
        pcap_fname = '%s_%s.pcap' % \
            (self.pcap_procs[hostapd_constants.BAND_2G][1],
             hostapd_constants.BAND_2G.upper())
        packets = rdpcap(pcap_fname)
        self.verify_mac_not_found_in_pcap(self.sta_factory_mac, packets)
Exemplo n.º 17
0
    def connect_to_wifi_network_with_password(self, params):
        """Connection logic for open and psk wifi networks.

        Logic steps are
        1. Connect to the network.
        2. Run iperf traffic.

        Args:
            params: A tuple of network info and AndroidDevice object.

        Returns:
            True if successful, False otherwise.
        """
        result = False
        wait_time = 5
        network, ad = params
        droid = ad.droid
        ed = ad.ed
        SSID = network[WifiEnums.SSID_KEY]
        try:
            ed.clear_all_events()
            wutils.start_wifi_connection_scan(ad)
            droid.wifiStartTrackingStateChange()
            asserts.assert_true(droid.wifiConnect(network),
                                "wifi connect returned false.")
            connect_result = ed.pop_event(WifiEventNames.WIFI_CONNECTED)
            self.log.debug(connect_result)
            result = connect_result['data'][WifiEnums.SSID_KEY] == SSID
            if result:
                self.log.info("Starting iperf traffic through {}".format(SSID))
                time.sleep(wait_time)
                port_arg = "-p {}".format(self.iperf_server.port)
                result, data = ad.run_iperf_client(self.iperf_server_address,
                                                   port_arg)
                self.log.debug(pprint.pformat(data))
        except queue.Empty:
            self.log.exception("Failed to connect to {}".format(SSID))
        finally:
            droid.wifiStopTrackingStateChange()
        return result
 def test_network_selector_blacklist_by_connection_failure(self):
     """
         1. Add two saved secured networks X and Y to DUT. X has stronger
            RSSI than Y. X has wrong password configured.
         2. Move the DUT in range.
         3. Verify the DUT is connected to network Y.
     """
     #add two saved networks to DUT, and one of them is configured with incorrect password
     wrong_passwd_network = self.reference_networks[AP_1]['5g'].copy()
     wrong_passwd_network['password'] += 'haha'
     networks = [wrong_passwd_network, self.reference_networks[AP_2]['5g']]
     self.add_networks(self.dut, networks)
     #make both AP_1 5G and AP_2 5G in range, and AP_1 5G has stronger RSSI than AP_2 5G
     self.attenuators[AP_1_5G_ATTENUATOR].set_atten(0)
     self.attenuators[AP_2_5G_ATTENUATOR].set_atten(10)
     #start 3 scans to get AP_1 5G blacklisted because of the incorrect password
     count = 0
     while count < 3:
         wutils.start_wifi_connection_scan(self.dut)
         time.sleep(NETWORK_SELECTION_TIME_GAP)
         count += 1
     #verify
     self.connect_and_verify_connected_bssid(self.reference_networks[AP_2][
         '5g']['bssid'])
Exemplo n.º 19
0
    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.

        """
        self.dut.ed.clear_all_events()
        wutils.start_wifi_connection_scan(self.dut)
        scan_results = self.dut.droid.wifiGetScanResults()
        wutils.assert_network_in_list({WifiEnums.SSID_KEY: network_ssid},
                                      scan_results)
        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