• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2#   Copyright 2016 - The Android Open Source Project
3#
4#   Licensed under the Apache License, Version 2.0 (the "License");
5#   you may not use this file except in compliance with the License.
6#   You may obtain a copy of the License at
7#
8#       http://www.apache.org/licenses/LICENSE-2.0
9#
10#   Unless required by applicable law or agreed to in writing, software
11#   distributed under the License is distributed on an "AS IS" BASIS,
12#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13#   See the License for the specific language governing permissions and
14#   limitations under the License.
15
16import pprint
17import random
18import time
19
20from acts import asserts
21from acts import signals
22from acts.test_decorators import test_tracker_info
23from acts.test_utils.wifi import wifi_test_utils as wutils
24from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest
25
26WifiEnums = wutils.WifiEnums
27
28# EAP Macros
29EAP = WifiEnums.Eap
30EapPhase2 = WifiEnums.EapPhase2
31
32# Enterprise Config Macros
33Ent = WifiEnums.Enterprise
34
35
36class WifiEnterpriseRoamingTest(WifiBaseTest):
37    def __init__(self, controllers):
38        WifiBaseTest.__init__(self, controllers)
39
40    def setup_class(self):
41        self.dut = self.android_devices[0]
42        wutils.wifi_test_device_init(self.dut)
43        req_params = (
44            "attn_vals",
45            # Expected time within which roaming should finish, in seconds.
46            "roam_interval",
47            "ca_cert",
48            "client_cert",
49            "client_key",
50            "eap_identity",
51            "eap_password",
52            "device_password",
53            "radius_conf_2g",
54            "radius_conf_5g")
55        self.unpack_userparams(req_params)
56        if "AccessPoint" in self.user_params:
57            self.legacy_configure_ap_and_start(
58                mirror_ap=True,
59                ent_network=True,
60                ap_count=2,
61                radius_conf_2g=self.radius_conf_2g,
62                radius_conf_5g=self.radius_conf_5g,)
63        self.ent_network_2g_a = self.ent_networks[0]["2g"]
64        self.ent_network_2g_b = self.ent_networks[1]["2g"]
65        self.bssid_2g_a = self.ent_network_2g_a[WifiEnums.BSSID_KEY.lower()]
66        self.bssid_2g_b = self.ent_network_2g_b[WifiEnums.BSSID_KEY.lower()]
67        self.ent_roaming_ssid = self.ent_network_2g_a[WifiEnums.SSID_KEY]
68        self.bssid_a = self.bssid_2g_a
69        self.bssid_b = self.bssid_2g_b
70
71        self.config_peap = {
72            Ent.EAP: int(EAP.PEAP),
73            Ent.CA_CERT: self.ca_cert,
74            Ent.IDENTITY: self.eap_identity,
75            Ent.PASSWORD: self.eap_password,
76            Ent.PHASE2: int(EapPhase2.MSCHAPV2),
77            WifiEnums.SSID_KEY: self.ent_roaming_ssid
78        }
79        self.config_tls = {
80            Ent.EAP: int(EAP.TLS),
81            Ent.CA_CERT: self.ca_cert,
82            WifiEnums.SSID_KEY: self.ent_roaming_ssid,
83            Ent.CLIENT_CERT: self.client_cert,
84            Ent.PRIVATE_KEY_ID: self.client_key,
85            Ent.IDENTITY: self.eap_identity,
86        }
87        self.config_ttls = {
88            Ent.EAP: int(EAP.TTLS),
89            Ent.CA_CERT: self.ca_cert,
90            Ent.IDENTITY: self.eap_identity,
91            Ent.PASSWORD: self.eap_password,
92            Ent.PHASE2: int(EapPhase2.MSCHAPV2),
93            WifiEnums.SSID_KEY: self.ent_roaming_ssid
94        }
95        self.config_sim = {
96            Ent.EAP: int(EAP.SIM),
97            WifiEnums.SSID_KEY: self.ent_roaming_ssid,
98        }
99        self.attn_a = self.attenuators[0]
100        self.attn_b = self.attenuators[2]
101        # Set screen lock password so ConfigStore is unlocked.
102        self.dut.droid.setDevicePassword(self.device_password)
103        self.set_attns("default")
104
105    def teardown_class(self):
106        wutils.reset_wifi(self.dut)
107        self.dut.droid.disableDevicePassword(self.device_password)
108        self.dut.ed.clear_all_events()
109        self.set_attns("default")
110
111    def setup_test(self):
112        self.dut.droid.wifiStartTrackingStateChange()
113        self.dut.droid.wakeLockAcquireBright()
114        self.dut.droid.wakeUpNow()
115        wutils.reset_wifi(self.dut)
116        self.dut.ed.clear_all_events()
117
118    def teardown_test(self):
119        self.dut.droid.wakeLockRelease()
120        self.dut.droid.goToSleepNow()
121        self.dut.droid.wifiStopTrackingStateChange()
122        self.set_attns("default")
123
124    def on_fail(self, test_name, begin_time):
125        self.dut.cat_adb_log(test_name, begin_time)
126
127    def set_attns(self, attn_val_name):
128        """Sets attenuation values on attenuators used in this test.
129
130        Args:
131            attn_val_name: Name of the attenuation value pair to use.
132        """
133        self.log.info("Set attenuation values to %s",
134                      self.attn_vals[attn_val_name])
135        try:
136            self.attn_a.set_atten(self.attn_vals[attn_val_name][0])
137            self.attn_b.set_atten(self.attn_vals[attn_val_name][1])
138        except:
139            self.log.exception("Failed to set attenuation values %s.",
140                           attn_val_name)
141            raise
142
143    def trigger_roaming_and_validate(self, attn_val_name, expected_con):
144        """Sets attenuators to trigger roaming and validate the DUT connected
145        to the BSSID expected.
146
147        Args:
148            attn_val_name: Name of the attenuation value pair to use.
149            expected_con: The expected info of the network to we expect the DUT
150                to roam to.
151        """
152        self.set_attns(attn_val_name)
153        self.log.info("Wait %ss for roaming to finish.", self.roam_interval)
154        time.sleep(self.roam_interval)
155        try:
156            self.dut.droid.wakeLockAcquireBright()
157            self.dut.droid.wakeUpNow()
158            wutils.verify_wifi_connection_info(self.dut, expected_con)
159            expected_bssid = expected_con[WifiEnums.BSSID_KEY]
160            self.log.info("Roamed to %s successfully", expected_bssid)
161        finally:
162            self.dut.droid.wifiLockRelease()
163            self.dut.droid.goToSleepNow()
164
165    def roaming_between_a_and_b_logic(self, config):
166        """Test roaming between two enterprise APs.
167
168        Steps:
169        1. Make bssid_a visible, bssid_b not visible.
170        2. Connect to ent_roaming_ssid. Expect DUT to connect to bssid_a.
171        3. Make bssid_a not visible, bssid_b visible.
172        4. Expect DUT to roam to bssid_b.
173        5. Make bssid_a visible, bssid_b not visible.
174        6. Expect DUT to roam back to bssid_a.
175        """
176        expected_con_to_a = {
177            WifiEnums.SSID_KEY: self.ent_roaming_ssid,
178            WifiEnums.BSSID_KEY: self.bssid_a,
179        }
180        expected_con_to_b = {
181            WifiEnums.SSID_KEY: self.ent_roaming_ssid,
182            WifiEnums.BSSID_KEY: self.bssid_b,
183        }
184        self.set_attns("a_on_b_off")
185        wutils.wifi_connect(self.dut, config)
186        wutils.verify_wifi_connection_info(self.dut, expected_con_to_a)
187        self.log.info("Roaming from %s to %s", self.bssid_a, self.bssid_b)
188        self.trigger_roaming_and_validate("b_on_a_off", expected_con_to_b)
189        self.log.info("Roaming from %s to %s", self.bssid_b, self.bssid_a)
190        self.trigger_roaming_and_validate("a_on_b_off", expected_con_to_a)
191
192    """ Tests Begin """
193
194    @test_tracker_info(uuid="b15e4b3f-841d-428d-87ac-272f29f06e14")
195    def test_roaming_with_config_tls(self):
196        self.roaming_between_a_and_b_logic(self.config_tls)
197
198    @test_tracker_info(uuid="d349cfec-b4af-48b2-88b7-744f5de25d43")
199    def test_roaming_with_config_ttls_none(self):
200        config = dict(self.config_ttls)
201        config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.NONE.value
202        self.roaming_between_a_and_b_logic(config)
203
204    @test_tracker_info(uuid="89b8161c-754e-4138-831d-5fe40f521ce4")
205    def test_roaming_with_config_ttls_pap(self):
206        config = dict(self.config_ttls)
207        config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.PAP.value
208        self.roaming_between_a_and_b_logic(config)
209
210    @test_tracker_info(uuid="d4925470-924b-4d03-8437-83e26b5f2df3")
211    def test_roaming_with_config_ttls_mschap(self):
212        config = dict(self.config_ttls)
213        config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.MSCHAP.value
214        self.roaming_between_a_and_b_logic(config)
215
216    @test_tracker_info(uuid="206b1327-dd9c-4742-8717-e7bf2a04eed6")
217    def test_roaming_with_config_ttls_mschapv2(self):
218        config = dict(self.config_ttls)
219        config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.MSCHAPV2.value
220        self.roaming_between_a_and_b_logic(config)
221
222    @test_tracker_info(uuid="c2c0168b-2933-4954-af62-fb41f42dc45a")
223    def test_roaming_with_config_ttls_gtc(self):
224        config = dict(self.config_ttls)
225        config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.GTC.value
226        self.roaming_between_a_and_b_logic(config)
227
228    @test_tracker_info(uuid="481c4102-8f5b-4fcd-95cc-5e3285f47985")
229    def test_roaming_with_config_peap_mschapv2(self):
230        config = dict(self.config_peap)
231        config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.MSCHAPV2.value
232        self.roaming_between_a_and_b_logic(config)
233
234    @test_tracker_info(uuid="404155d4-33a7-42b3-b369-5f2d63d19f16")
235    def test_roaming_with_config_peap_gtc(self):
236        config = dict(self.config_peap)
237        config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.GTC.value
238        self.roaming_between_a_and_b_logic(config)
239
240    """ Tests End """
241