Home | History | Annotate | Download | only in network_WiFi_DisconnectReason
      1 # Copyright (c) 2015 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 import logging
      6 import time
      7 
      8 from autotest_lib.client.common_lib import error
      9 from autotest_lib.client.common_lib.cros.network import xmlrpc_datatypes
     10 from autotest_lib.server import site_linux_system
     11 from autotest_lib.server.cros.network import hostap_config
     12 from autotest_lib.server.cros.network import wifi_cell_test_base
     13 from autotest_lib.server.cros.network import wifi_client
     14 
     15 
     16 class network_WiFi_DisconnectReason(wifi_cell_test_base.WiFiCellTestBase):
     17     """Verify the client disconnects from an AP and read (but not verify)
     18     the supplicant DisconnectReason for various scenarios."""
     19     version = 1
     20 
     21     INITIAL_CHANNEL = 64
     22     ALT_CHANNEL = 6
     23     CHANNEL_SWITCH_ATTEMPTS = 5
     24     CHANNEL_SWITCH_WAIT_TIME_SEC = 3
     25 
     26     def run_once(self, disconnect_trigger, req_caps=None):
     27         """Sets up a router, connects to it, pings it and disables it to trigger
     28         disconnect."""
     29         configuration = hostap_config.HostapConfig(
     30                 channel=self.INITIAL_CHANNEL,
     31                 mode=hostap_config.HostapConfig.MODE_11A,
     32                 spectrum_mgmt_required=True)
     33         if req_caps is None:
     34             req_caps = []
     35         self.context.router.require_capabilities(req_caps)
     36         self.context.configure(configuration)
     37 
     38         if site_linux_system.LinuxSystem.CAPABILITY_MULTI_AP in req_caps:
     39             # prep alternate Access Point
     40             alt_ap_config = hostap_config.HostapConfig(
     41                     channel=self.ALT_CHANNEL,
     42                     mode=hostap_config.HostapConfig.MODE_11N_MIXED)
     43             self.context.configure(alt_ap_config, multi_interface=True)
     44             alt_assoc_params = xmlrpc_datatypes.AssociationParameters()
     45             alt_assoc_params.ssid = self.context.router.get_ssid(instance=1)
     46 
     47         assoc_params = xmlrpc_datatypes.AssociationParameters()
     48         assoc_params.ssid = self.context.router.get_ssid(instance=0)
     49         self.context.assert_connect_wifi(assoc_params)
     50         self.context.assert_ping_from_dut()
     51 
     52         with self.context.client.assert_disconnect_event():
     53             if disconnect_trigger == 'AP gone':
     54                 self.context.router.deconfig()
     55             elif disconnect_trigger == 'deauth client':
     56                 self.context.router.deauth_client(self.context.client.wifi_mac)
     57             elif disconnect_trigger == 'AP send channel switch':
     58                 for _ in range(self.CHANNEL_SWITCH_ATTEMPTS):
     59                     self.context.router.send_management_frame_on_ap(
     60                             'channel_switch',
     61                             self.ALT_CHANNEL)
     62                     time.sleep(self.CHANNEL_SWITCH_WAIT_TIME_SEC)
     63             elif disconnect_trigger == 'switch AP':
     64                 self.context.assert_connect_wifi(alt_assoc_params)
     65             elif disconnect_trigger == 'disable client wifi':
     66                 self.context.client.set_device_enabled(
     67                         self.context.client.wifi_if, False)
     68             else:
     69                 raise error.TestError('unknown test mode: %s' %
     70                                       disconnect_trigger)
     71             time.sleep(wifi_client.DISCONNECT_WAIT_TIME_SECONDS)
     72 
     73         disconnect_reasons = self.context.client.get_disconnect_reasons()
     74         if disconnect_reasons is None or len(disconnect_reasons) == 0:
     75             raise error.TestFail('supplicant DisconnectReason not logged')
     76         for entry in disconnect_reasons:
     77             logging.info("DisconnectReason: %s", entry);
     78