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
5AUTHOR = 'pstew, quiche'
6NAME = 'network_WiFi_RegDomain'
7TIME = 'MEDIUM'
8TEST_TYPE = 'Server'
9ATTRIBUTES = "suite:wifi_matfunc_bcm4356"
10DEPENDENCIES = 'wificell'
11
12DOC = """
13This test verifies that a DUT can, or cannot, connect on given
14channels, in given regions.
15
16This test exercises:
17- parsing of VPD data
18- mapping of VPD data to ISO country code
19- communication of country code from user-space to kernel
20- communication of country code / rules from kernel to driver
21- communication of country code / rules from driver to firmware
22
23This test is an aid to identify changes in behavior. It does not
24provide advice on regulatory requirements.
25"""
26
27import logging
28
29from autotest_lib.client.common_lib import error
30from autotest_lib.client.common_lib.cros.network import interface
31
32
33# When adding a negative rule ('expect': 'no-connect'), be sure to add
34# a case with a positive rule ('expect': 'connect', or 'expect':
35# 'passive-scan'). Otherwise, we haven't ruled out the possibility
36# that the test itself prevents the DUT from connecting.
37#
38# Note:
39# - 'passive-scan' implies 'connect'
40# - 'no-connect' implies no probes
41DEVTYPE_TO_REGION_INFOS = {
42    # TODO(quiche): Add ath9k expectations for channels 52 and 120.
43    'ath9k':
44        [
45         # This first set of expectations is based on
46         # ath_world_regdom_63_65 in ath/regd.c. We may need to change
47         # or remove these, if it turns out that some DUTs have other
48         # ath9k SKUs.
49         {'region_name': '',
50          'country_code': '00',
51          'channel_infos': [
52              {'chnum': 13, 'expect': 'passive-scan'},
53              {'chnum': 36, 'expect': 'passive-scan'},
54              {'chnum': 149, 'expect': 'passive-scan'}]},
55         # Many of the 'passive-scan' expectations for the remaining
56         # regions seem to arise from ath_world_regdom_63_65. (Or, at
57         # least, not all of the passive scanning expectations can be
58         # attributed to data in wireless-regdb.)
59         {'region_name': 'ar',
60          'country_code': 'AR',
61          'channel_infos': [
62              {'chnum': 13, 'expect': 'passive-scan'},
63              {'chnum': 36, 'expect': 'passive-scan'},
64              {'chnum': 149, 'expect': 'passive-scan'}]},
65         {'region_name': 'id',
66          'country_code': 'ID',
67          'channel_infos': [
68              {'chnum': 13, 'expect': 'passive-scan'},
69              {'chnum': 36, 'expect': 'no-connect'},
70              {'chnum': 149, 'expect': 'passive-scan'}]},
71         {'region_name': 'ru',
72          'country_code': 'RU',
73          'channel_infos': [
74              {'chnum': 13, 'expect': 'passive-scan'},
75              {'chnum': 36, 'expect': 'passive-scan'},
76              {'chnum': 149, 'expect': 'passive-scan'}]},
77         {'region_name': 'us',
78          'country_code': 'US',
79          'channel_infos': [
80              {'chnum': 13, 'expect': 'no-connect'},
81              {'chnum': 36, 'expect': 'passive-scan'},
82              {'chnum': 149, 'expect': 'passive-scan'}]}],
83    'bcm435x':
84        [{'region_name': 'ca.hybrid',  # <country code>.<extra>
85          'country_code': 'CA',
86          'channel_infos': [
87              {'chnum': 13, 'expect': 'no-connect'},
88              {'chnum': 36, 'expect': 'connect'},
89              {'chnum': 52, 'expect': 'passive-scan'},
90              {'chnum': 120, 'expect': 'passive-scan'},
91              {'chnum': 149, 'expect': 'connect'},
92              {'chnum': 165, 'expect': 'connect'}]},
93         {'region_name': 'nordic',  # virtual set
94          'country_code': 'SE',
95          'channel_infos': [
96              {'chnum': 13, 'expect': 'connect'},
97              {'chnum': 36, 'expect': 'connect'},
98              {'chnum': 52, 'expect': 'passive-scan'},
99              {'chnum': 120, 'expect': 'passive-scan'},
100              {'chnum': 149, 'expect': 'no-connect'},
101              {'chnum': 165, 'expect': 'no-connect'}]},
102         {'region_name': 'us',
103          'country_code': 'US',
104          'channel_infos': [
105              {'chnum': 13, 'expect': 'no-connect'},
106              {'chnum': 36, 'expect': 'connect'},
107              {'chnum': 52, 'expect': 'passive-scan'},
108              {'chnum': 120, 'expect': 'no-connect'},
109              {'chnum': 149, 'expect': 'connect'},
110              {'chnum': 165, 'expect': 'connect'}]}],
111    'intel_wp2':
112    # TODO(quiche): Add wp2 expectations for channels 52 and 120. If
113    # those expectations match the (to-be-added) expectations for
114    # ath9k, then collapse both configs into a 'cfg80211' config.
115        [
116         {'region_name': '',
117          'country_code': '00',
118          'channel_infos': [
119              {'chnum': 13, 'expect': 'passive-scan'},
120              {'chnum': 36, 'expect': 'passive-scan'},
121              {'chnum': 149, 'expect': 'passive-scan'}]},
122         # Many of the 'passive-scan' expectations seem to follow from
123         # the initial world rules above. (Or, at least, not all of
124         # the passive scanning expectations can be attributed to
125         # country-speific data in wireless-regdb. We haven't
126         # investigated if the 'passive-scan' expectations are due to
127         # rules in the driver.)
128         {'region_name': 'ar',
129          'country_code': 'AR',
130          'channel_infos': [
131              {'chnum': 13, 'expect': 'passive-scan'},
132              {'chnum': 36, 'expect': 'passive-scan'},
133              {'chnum': 149, 'expect': 'passive-scan'}]},
134         {'region_name': 'id',
135          'country_code': 'ID',
136          'channel_infos': [
137              {'chnum': 13, 'expect': 'passive-scan'},
138              {'chnum': 36, 'expect': 'no-connect'},
139              {'chnum': 149, 'expect': 'passive-scan'}]},
140         {'region_name': 'ru',
141          'country_code': 'RU',
142          'channel_infos': [
143              {'chnum': 13, 'expect': 'passive-scan'},
144              {'chnum': 36, 'expect': 'passive-scan'},
145              {'chnum': 149, 'expect': 'passive-scan'}]},
146         {'region_name': 'us',
147          'country_code': 'US',
148          'channel_infos': [
149              {'chnum': 13, 'expect': 'no-connect'},
150              {'chnum': 36, 'expect': 'passive-scan'},
151              {'chnum': 149, 'expect': 'passive-scan'}]}]}
152WLAN_DEV = 'wlan0'
153
154
155def run(machine):
156    host = hosts.create_host(machine)
157    wlan_info = interface.Interface(WLAN_DEV, host=host).device_description
158    if not wlan_info:
159        raise error.TestFail('Couldn\'t find the WiFi device.')
160    if wlan_info.name in (
161        interface.NAME_ATHEROS_AR9280,
162        interface.NAME_ATHEROS_AR9382,
163        interface.NAME_ATHEROS_AR9462):
164            devtype = 'ath9k'
165    elif wlan_info.name in (
166        interface.NAME_BROADCOM_BCM4354_SDIO,
167        interface.NAME_BROADCOM_BCM4356_PCIE):
168            devtype = 'bcm435x'
169    elif wlan_info.name in (
170        interface.NAME_INTEL_7260,
171        interface.NAME_INTEL_7265):
172            devtype = 'intel_wp2'
173    else:
174        raise error.TestNAError(
175            'Unrecognized WiFi chip |%s|.' % wlan_info.name)
176
177    logging.debug('Running test with devtype=%s', devtype)
178    for region_info in DEVTYPE_TO_REGION_INFOS[devtype]:
179        # Use a fresh |host| every time, as WiFiTestContextManager
180        # cleans up |host| on context exit.
181        host = hosts.create_host(machine)
182        job.run_test(
183            'network_WiFi_RegDomain',
184            tag=region_info['region_name'] or 'default',
185            host=host,
186            raw_cmdline_args=args,
187            additional_params=region_info)
188
189
190parallel_simple(run, machines)
191