11febd6ad71496ac14c022f9156939daa2e1f5d71Christopher Wiley# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
21febd6ad71496ac14c022f9156939daa2e1f5d71Christopher Wiley# Use of this source code is governed by a BSD-style license that can be
31febd6ad71496ac14c022f9156939daa2e1f5d71Christopher Wiley# found in the LICENSE file.
41febd6ad71496ac14c022f9156939daa2e1f5d71Christopher Wiley
51febd6ad71496ac14c022f9156939daa2e1f5d71Christopher Wileyfrom autotest_lib.client.common_lib.cros.network import xmlrpc_datatypes
6061f13879e9e0aca297d0acb7ab6f6992d053528Christopher Wileyfrom autotest_lib.server import site_linux_system
799d42c95fa5c12285fb129b50445a60c9a145dd3Christopher Wileyfrom autotest_lib.server.cros.network import hostap_config
84961e848f54cb64f911c3ce03b3c377d171b35e5Christopher Wileyfrom autotest_lib.server.cros.network import wifi_cell_test_base
91febd6ad71496ac14c022f9156939daa2e1f5d71Christopher Wiley
101febd6ad71496ac14c022f9156939daa2e1f5d71Christopher Wiley
111febd6ad71496ac14c022f9156939daa2e1f5d71Christopher Wileyclass network_WiFi_IBSS(wifi_cell_test_base.WiFiCellTestBase):
121febd6ad71496ac14c022f9156939daa2e1f5d71Christopher Wiley    """Test that we can connect to an IBSS (Adhoc) endpoint."""
131febd6ad71496ac14c022f9156939daa2e1f5d71Christopher Wiley    version = 1
141febd6ad71496ac14c022f9156939daa2e1f5d71Christopher Wiley
151febd6ad71496ac14c022f9156939daa2e1f5d71Christopher Wiley
163e016dfc43799d47b6de12b9c4c98ab83b2a64d4Christopher Wiley    def run_once(self):
171febd6ad71496ac14c022f9156939daa2e1f5d71Christopher Wiley        """Body of the test."""
18061f13879e9e0aca297d0acb7ab6f6992d053528Christopher Wiley        self.context.router.require_capabilities(
19061f13879e9e0aca297d0acb7ab6f6992d053528Christopher Wiley                [site_linux_system.LinuxSystem.CAPABILITY_IBSS])
20522dd1b90d0f7aba8e8112d73c7db03d28ecedc6Christopher Wiley        # In the past, we have seen a bug where a previous association on a
21522dd1b90d0f7aba8e8112d73c7db03d28ecedc6Christopher Wiley        # channel where IBSS was disallowed would prohibit wpa_supplicant
22522dd1b90d0f7aba8e8112d73c7db03d28ecedc6Christopher Wiley        # from setting the interface to adhoc mode (since the kernel refuses
23522dd1b90d0f7aba8e8112d73c7db03d28ecedc6Christopher Wiley        # to allow adhoc mode on the previous channel).
241febd6ad71496ac14c022f9156939daa2e1f5d71Christopher Wiley        configuration = hostap_config.HostapConfig(
25522dd1b90d0f7aba8e8112d73c7db03d28ecedc6Christopher Wiley                channel=52, mode=hostap_config.HostapConfig.MODE_11A)
26522dd1b90d0f7aba8e8112d73c7db03d28ecedc6Christopher Wiley        self.context.configure(configuration)
27522dd1b90d0f7aba8e8112d73c7db03d28ecedc6Christopher Wiley        assoc_params = xmlrpc_datatypes.AssociationParameters(
28522dd1b90d0f7aba8e8112d73c7db03d28ecedc6Christopher Wiley                ssid=self.context.router.get_ssid())
29522dd1b90d0f7aba8e8112d73c7db03d28ecedc6Christopher Wiley        self.context.assert_connect_wifi(assoc_params)
30522dd1b90d0f7aba8e8112d73c7db03d28ecedc6Christopher Wiley        self.context.client.shill.disconnect(assoc_params.ssid)
31522dd1b90d0f7aba8e8112d73c7db03d28ecedc6Christopher Wiley        configuration = hostap_config.HostapConfig(
32522dd1b90d0f7aba8e8112d73c7db03d28ecedc6Christopher Wiley                frequency=2412, mode=hostap_config.HostapConfig.MODE_11B)
331febd6ad71496ac14c022f9156939daa2e1f5d71Christopher Wiley        self.context.configure(configuration, is_ibss=True)
34fae2ea8c59bdc412b1768c48e19edab6d05d5336Christopher Wiley        assoc_params = xmlrpc_datatypes.AssociationParameters(
35fae2ea8c59bdc412b1768c48e19edab6d05d5336Christopher Wiley                ssid=self.context.router.get_ssid(),
36fae2ea8c59bdc412b1768c48e19edab6d05d5336Christopher Wiley                discovery_timeout=30,
372568cd4c35742c86f91d15506eab83507f39b226Christopher Wiley                association_timeout=30,
382568cd4c35742c86f91d15506eab83507f39b226Christopher Wiley                configuration_timeout=30,
39fae2ea8c59bdc412b1768c48e19edab6d05d5336Christopher Wiley                station_type=xmlrpc_datatypes.
40fae2ea8c59bdc412b1768c48e19edab6d05d5336Christopher Wiley                        AssociationParameters.STATION_TYPE_IBSS)
413e016dfc43799d47b6de12b9c4c98ab83b2a64d4Christopher Wiley        self.context.assert_connect_wifi(assoc_params)
423e016dfc43799d47b6de12b9c4c98ab83b2a64d4Christopher Wiley        self.context.assert_ping_from_dut()
431febd6ad71496ac14c022f9156939daa2e1f5d71Christopher Wiley        self.context.client.shill.disconnect(assoc_params.ssid)
442568cd4c35742c86f91d15506eab83507f39b226Christopher Wiley        self.context.router.deconfig_aps()
45