Home | History | Annotate | Download | only in network_WiFi_VisibleScan
      1 # Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 from autotest_lib.client.common_lib import error
      6 from autotest_lib.client.common_lib.cros.network import tcpdump_analyzer
      7 from autotest_lib.client.common_lib.cros.network import xmlrpc_datatypes
      8 from autotest_lib.server.cros.network import hostap_config
      9 from autotest_lib.server.cros.network import packet_capturer
     10 from autotest_lib.server.cros.network import wifi_cell_test_base
     11 
     12 
     13 class network_WiFi_VisibleScan(wifi_cell_test_base.WiFiCellTestBase):
     14     """Test scanning behavior when no hidden SSIDs are configured."""
     15 
     16     version = 1
     17 
     18     BROADCAST_SSID = ''
     19 
     20     def parse_additional_arguments(self, commandline_args, additional_params):
     21         """
     22         Hook into super class to take control files parameters.
     23 
     24         @param commandline_args: dict of parsed parameters from the autotest.
     25         @param additional_params: list of HostapConfig objects.
     26 
     27         """
     28         self._ap_configs = additional_params
     29 
     30 
     31     def run_once(self):
     32         """Test body."""
     33         ap_config = hostap_config.HostapConfig(channel=1)
     34 
     35         # Start capture before starting anything else.
     36         self.context.capture_host.start_capture(
     37                     ap_config.frequency,
     38                     ht_type=ap_config.ht_packet_capture_mode,
     39                     snaplen=packet_capturer.SNAPLEN_WIFI_PROBE_REQUEST)
     40 
     41         # We're looking for the MAC address, so disable randomization.
     42         with self.context.client.mac_address_randomization(False):
     43             # Set up the router and associate the client with it.
     44             self.context.configure(ap_config)
     45             assoc_params = xmlrpc_datatypes.AssociationParameters(
     46                 ssid=self.context.router.get_ssid())
     47 
     48             self.context.assert_connect_wifi(assoc_params)
     49             results = self.context.capture_host.stop_capture()
     50 
     51         if len(results) != 1:
     52             raise error.TestError('Expected to generate one packet '
     53                                   'capture but got %d instead.' %
     54                                   len(results))
     55         probe_ssids = tcpdump_analyzer.get_probe_ssids(
     56                 results[0].local_pcap_path,
     57                 probe_sender=self.context.client.wifi_mac)
     58         # We expect a broadcast probe, but it's not guaranteed.
     59         expected_ssids = frozenset([self.BROADCAST_SSID])
     60         permitted_ssids = (expected_ssids |
     61                 frozenset([self.context.router.get_ssid()]))
     62         # Verify probe result does not contain any unpermitted ssids
     63         if probe_ssids - permitted_ssids:
     64             raise error.TestError('Permitted SSIDs %s, but got %s' %
     65                                   (permitted_ssids, probe_ssids))
     66