• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#   !/usr/bin/env python3.4
2#
3#   Copyright 2017 - The Android Open Source Project
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16
17from acts.libs.ota import ota_updater
18import acts.signals as signals
19from acts.test_decorators import test_tracker_info
20import acts_contrib.test_utils.wifi.wifi_test_utils as wutils
21from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest
22import acts.utils as utils
23from WifiAutoUpdateTest import WifiAutoUpdateTest
24
25WifiEnums = wutils.WifiEnums
26SSID = WifiEnums.SSID_KEY
27PWD = WifiEnums.PWD_KEY
28NETID = WifiEnums.NETID_KEY
29# Default timeout used for reboot, toggle WiFi and Airplane mode,
30# for the system to settle down after the operation.
31EAP = WifiEnums.Eap
32Ent = WifiEnums.Enterprise
33WPA3_SECURITY = "SUITE_B_192"
34
35
36class WifiWpa3AutoUpdateTest(WifiAutoUpdateTest):
37    """Tests for APIs in Android's WifiManager class.
38
39    Test Bed Requirement:
40    * One Android device
41    * Several Wi-Fi networks visible to the device, including an open Wi-Fi
42      network.
43    """
44
45    def __init__(self, configs):
46        super().__init__(configs)
47        self.tests = ("test_check_wpa3_wifi_state_after_au",
48                      "test_verify_wpa3_networks_after_au",
49                      "test_wpa3_configstore_after_au",
50                      "test_all_wpa3_networks_connectable_after_au",
51                      "test_check_wpa3_wifi_toggling_after_au",
52                      "test_wpa3_connection_to_new_networks",
53                      "test_reset_wpa3_wifi_after_au")
54
55    def setup_class(self):
56        super(WifiBaseTest, self).setup_class()
57        ota_updater.initialize(self.user_params, self.android_devices)
58        self.dut = self.android_devices[0]
59        self.dut_client = self.android_devices[1]
60        wutils.wifi_test_device_init(self.dut)
61        wutils.wifi_toggle_state(self.dut, True)
62
63        # configure APs
64        req_params = [
65            "ec2_ca_cert", "ec2_client_cert", "ec2_client_key",
66            "rsa3072_ca_cert", "rsa3072_client_cert", "rsa3072_client_key",
67            "wpa3_ec2_network", "wpa3_rsa3072_network", "rsa2048_client_cert",
68            "rsa2048_client_key", "rsa3072_client_cert_expired",
69            "rsa3072_client_cert_corrupted", "rsa3072_client_cert_unsigned",
70            "rsa3072_client_key_unsigned", "wpa3_sae_gcmp_128",
71            "wpa3_sae_gcmp_256", "owe_networks", "sae_networks"
72        ]
73        self.unpack_userparams(req_param_names=req_params)
74        self.owe_2g = self.owe_networks[0]["2g"]
75        self.owe_5g = self.owe_networks[0]["5g"]
76        self.wpa3_personal_2g = self.sae_networks[0]["2g"]
77        self.wpa3_personal_5g = self.sae_networks[0]["5g"]
78
79        self.config_rsa3072_tls = {
80            Ent.EAP: int(EAP.TLS),
81            Ent.CA_CERT: self.rsa3072_ca_cert,
82            WifiEnums.SSID_KEY: self.wpa3_rsa3072_network[WifiEnums.SSID_KEY],
83            Ent.CLIENT_CERT: self.rsa3072_client_cert,
84            Ent.PRIVATE_KEY_ID: self.rsa3072_client_key,
85            WifiEnums.SECURITY: WPA3_SECURITY,
86            "identity": self.wpa3_rsa3072_network["identity"],
87            "domain_suffix_match": self.wpa3_rsa3072_network["domain"]
88        }
89
90        # saved & connected networks, network suggestions
91        # and new networks
92        self.saved_networks = [self.wpa3_sae_gcmp_256]
93        self.network_suggestions = [self.owe_2g]
94        self.connected_networks = [
95            self.config_rsa3072_tls, self.wpa3_personal_5g
96        ]
97        self.new_networks = [self.wpa3_personal_2g]
98        # add pre ota upgrade configuration
99        self.wifi_config_list = []
100        self.pre_default_mac = {}
101        self.pre_random_mac = {}
102        self.pst_default_mac = {}
103        self.pst_random_mac = {}
104        self.add_pre_update_configuration()
105
106        # Run OTA below, if ota fails then abort all tests.
107        try:
108            ota_updater.update(self.dut)
109        except Exception as e:
110            raise signals.TestAbortClass(
111                "Failed up apply OTA update. Aborting tests: %s" % e)
112
113    ### Tests
114
115    @test_tracker_info(uuid="4d17a21c-3db6-4336-84ac-f3317e4a7fca")
116    @WifiBaseTest.wifi_test_wrap
117    def test_check_wpa3_wifi_state_after_au(self):
118        """Check if the state of WiFi is enabled after Auto-update."""
119        if not self.dut.droid.wifiCheckState():
120            raise signals.TestFailure("WiFi is disabled after Auto-update!!!")
121
122    @test_tracker_info(uuid="4dd106b0-6390-47d2-9b6d-00f21a0535f1")
123    @WifiBaseTest.wifi_test_wrap
124    def test_verify_wpa3_networks_after_au(self):
125        """Check if the previously added networks are intact.
126
127           Steps:
128               Number of networs should be the same and match each network.
129
130        """
131        self.check_networks_after_autoupdate(self.wifi_config_list)
132
133    @test_tracker_info(uuid="4e5107d1-17cc-4c4d-aee5-38052dec5ddd")
134    @WifiBaseTest.wifi_test_wrap
135    def test_wpa3_configstore_after_au(self):
136        """Verify DUT automatically connects to wifi networks after ota.
137
138           Steps:
139               1. Connect to two wifi networks pre ota.
140               2. Verify DUT automatically connects to 1 after ota.
141               3. Re-connect to the other wifi network.
142        """
143        wifi_info = self.dut.droid.wifiGetConnectionInfo()
144        self.pst_default_mac[wifi_info[SSID]] = self.get_sta_mac_address()
145        self.pst_random_mac[wifi_info[SSID]] = \
146            self.dut.droid.wifigetRandomizedMacAddress(wifi_info)
147        reconnect_to = self.get_enabled_network(self.wifi_config_list[1],
148                                                self.wifi_config_list[2])
149        wutils.start_wifi_connection_scan_and_ensure_network_found(
150            self.dut, reconnect_to[SSID])
151
152        if reconnect_to[SSID] == self.connected_networks[0][SSID]:
153            wutils.wifi_connect(self.dut,
154                                self.connected_networks[0],
155                                num_of_tries=6)
156        else:
157            wutils.wifi_connect(self.dut,
158                                self.connected_networks[1],
159                                num_of_tries=6)
160        connect_data = self.dut.droid.wifiGetConnectionInfo()
161        connect_ssid = connect_data[SSID]
162        self.log.info("Expected SSID = %s" % reconnect_to[SSID])
163        self.log.info("Connected SSID = %s" % connect_ssid)
164        if connect_ssid != reconnect_to[SSID]:
165            raise signals.TestFailure(
166                "Device failed to reconnect to the correct"
167                " network after reboot.")
168        self.pst_default_mac[wifi_info[SSID]] = self.get_sta_mac_address()
169        self.pst_random_mac[wifi_info[SSID]] = \
170            self.dut.droid.wifigetRandomizedMacAddress(wifi_info)
171
172        for network in self.connected_networks:
173            wutils.wifi_forget_network(self.dut, network[SSID])
174
175    @test_tracker_info(uuid="f1b59dde-b019-46c4-84b8-cf20f4afa08a")
176    @WifiBaseTest.wifi_test_wrap
177    def test_wpa3_connection_to_new_networks(self):
178        """Check if we can connect to new networks after Auto-update.
179
180           Steps:
181               1. Connect to a wpa3 network.
182               2. Forget ntworks added in 1.
183        """
184        for network in self.new_networks:
185            wutils.connect_to_wifi_network(self.dut, network)
186        for network in self.new_networks:
187            wutils.wifi_forget_network(self.dut, network[SSID])
188
189    @test_tracker_info(uuid="542a39c3-eea0-445c-89ae-8c74c6afb0bf")
190    @WifiBaseTest.wifi_test_wrap
191    def test_all_wpa3_networks_connectable_after_au(self):
192        """Check if previously added networks are connectable.
193
194           Steps:
195               1. Connect to previously added wpa3 network using network id.
196        """
197        network = self.wifi_config_list[0]
198        if not wutils.connect_to_wifi_network_with_id(self.dut, network[NETID],
199                                                      network[SSID]):
200            raise signals.TestFailure("Failed to connect to %s after OTA" %
201                                      network[SSID])
202        wutils.wifi_forget_network(self.dut, network[SSID])
203
204    @test_tracker_info(uuid="68a34667-aca2-4630-b2fa-c25f1d234a92")
205    @WifiBaseTest.wifi_test_wrap
206    def test_check_wpa3_wifi_toggling_after_au(self):
207        """Check if WiFi can be toggled ON/OFF after auto-update."""
208        self.log.debug("Going from on to off.")
209        wutils.wifi_toggle_state(self.dut, False)
210        self.log.debug("Going from off to on.")
211        wutils.wifi_toggle_state(self.dut, True)
212
213    @test_tracker_info(uuid="39ba98de-cb49-4475-a218-7470122af885")
214    @WifiBaseTest.wifi_test_wrap
215    def test_reset_wpa3_wifi_after_au(self):
216        """"Check if WiFi can be reset after auto-update."""
217        wutils.reset_wifi(self.dut)
218