blob: 88736f8aa0d5c653a2068e96bd38a523b36d2788 [file] [log] [blame]
Bindu Mahadev1c895c22018-01-18 18:20:43 -08001#!/usr/bin/env python3.4
2#
3# Copyright 2018 - 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
Bindu Mahadev1c895c22018-01-18 18:20:43 -080017import acts.signals
Xianyuan Jia63751fb2020-11-17 00:07:40 +000018import acts_contrib.test_utils.wifi.wifi_test_utils as wutils
Bindu Mahadev1c895c22018-01-18 18:20:43 -080019
Bindu Mahadev1c895c22018-01-18 18:20:43 -080020from acts.test_decorators import test_tracker_info
Xianyuan Jia63751fb2020-11-17 00:07:40 +000021from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest
Bindu Mahadev1c895c22018-01-18 18:20:43 -080022
23
24class WifiHiddenSSIDTest(WifiBaseTest):
25 """Tests for APIs in Android's WifiManager class.
26
27 Test Bed Requirement:
28 * One Android device
29 * Several Wi-Fi networks visible to the device, including an open Wi-Fi
30 network.
31 """
Xianyuan Jia97a865e2020-11-10 02:09:40 +000032 def __init__(self, configs):
33 super().__init__(configs)
34 self.enable_packet_log = True
Bindu Mahadev1c895c22018-01-18 18:20:43 -080035
Bindu Mahadev1c895c22018-01-18 18:20:43 -080036 def setup_class(self):
Xianyuan Jia168103b2019-09-06 12:22:52 -070037 super().setup_class()
38
Bindu Mahadev1c895c22018-01-18 18:20:43 -080039 self.dut = self.android_devices[0]
40 wutils.wifi_test_device_init(self.dut)
Bindu Mahadev1c895c22018-01-18 18:20:43 -080041
42 if "AccessPoint" in self.user_params:
43 self.legacy_configure_ap_and_start(hidden=True)
Xianyuan Jia97a865e2020-11-10 02:09:40 +000044 elif "OpenWrtAP" in self.user_params:
45 self.configure_openwrt_ap_and_start(open_network=True,
46 wpa_network=True,
47 owe_network=True,
48 sae_network=True,
49 hidden=True)
Bindu Mahadev1c895c22018-01-18 18:20:43 -080050
Bindu Mahadev1c895c22018-01-18 18:20:43 -080051 self.open_hidden_2g = self.open_network[0]["2g"]
52 self.open_hidden_5g = self.open_network[0]["5g"]
53 self.wpa_hidden_2g = self.reference_networks[0]["2g"]
54 self.wpa_hidden_5g = self.reference_networks[0]["5g"]
55
56 def setup_test(self):
Xianyuan Jia97a865e2020-11-10 02:09:40 +000057 super().setup_test()
Bindu Mahadev1c895c22018-01-18 18:20:43 -080058 self.dut.droid.wakeLockAcquireBright()
59 self.dut.droid.wakeUpNow()
60
61 def teardown_test(self):
Xianyuan Jia97a865e2020-11-10 02:09:40 +000062 super().teardown_test()
Bindu Mahadev1c895c22018-01-18 18:20:43 -080063 self.dut.droid.wakeLockRelease()
64 self.dut.droid.goToSleepNow()
65
Bindu Mahadev1c895c22018-01-18 18:20:43 -080066 def teardown_class(self):
67 wutils.reset_wifi(self.dut)
68 if "AccessPoint" in self.user_params:
69 del self.user_params["reference_networks"]
70 del self.user_params["open_network"]
71
72 """Helper Functions"""
73
74 def check_hiddenSSID_in_scan(self, ap_ssid, max_tries=2):
75 """Check if the ap started by wifi tethering is seen in scan results.
76
77 Args:
78 ap_ssid: SSID of the ap we are looking for.
79 max_tries: Number of scans to try.
80 Returns:
81 True: if ap_ssid is found in scan results.
82 False: if ap_ssid is not found in scan results.
83 """
84 for num_tries in range(max_tries):
85 wutils.start_wifi_connection_scan(self.dut)
86 scan_results = self.dut.droid.wifiGetScanResults()
87 match_results = wutils.match_networks(
88 {wutils.WifiEnums.SSID_KEY: ap_ssid}, scan_results)
89 if len(match_results) > 0:
90 return True
91 return False
92
93 def add_hiddenSSID_and_connect(self, hidden_network):
94 """Add the hidden network and connect to it.
95
96 Args:
97 hidden_network: The hidden network config to connect to.
98
99 """
Hsiu-Chang Chence489dd2019-06-12 15:37:19 +0800100 wutils.connect_to_wifi_network(self.dut, hidden_network, hidden=True)
Bindu Mahadev1c895c22018-01-18 18:20:43 -0800101 if not wutils.validate_connection(self.dut):
102 raise signals.TestFailure("Fail to connect to internet on %s" %
103 hidden_network)
104
105 """Tests"""
106
107 @test_tracker_info(uuid="d0871f98-6049-4937-a288-ec4a2746c771")
108 def test_connect_to_wpa_hidden_2g(self):
109 """Connect to a WPA, 2G network.
110
111 Steps:
112 1. Add a WPA, 2G hidden network.
113 2. Ensure the network is visible in scan.
114 3. Connect and run ping.
115
116 """
117 self.add_hiddenSSID_and_connect(self.wpa_hidden_2g)
118
119 @test_tracker_info(uuid="c558b31a-549a-4012-9052-275623992187")
120 def test_connect_to_wpa_hidden_5g(self):
121 """Connect to a WPA, 5G hidden network.
122
123 Steps:
124 1. Add a WPA, 5G hidden network.
125 2. Ensure the network is visible in scan.
126 3. Connect and run ping.
127
128 """
129 self.add_hiddenSSID_and_connect(self.wpa_hidden_5g)
130
131 @test_tracker_info(uuid="cdfce76f-6374-439d-aa1d-e920508269d2")
132 def test_connect_to_open_hidden_2g(self):
133 """Connect to a Open, 2G hidden network.
134
135 Steps:
136 1. Add a Open, 2G hidden network.
137 2. Ensure the network is visible in scan.
138 3. Connect and run ping.
139
140 """
141 self.add_hiddenSSID_and_connect(self.open_hidden_2g)
142
143 @test_tracker_info(uuid="29ccbae4-4382-4df8-8fc5-00e3104230d0")
144 def test_connect_to_open_hidden_5g(self):
145 """Connect to a Open, 5G hidden network.
146
147 Steps:
148 1. Add a Open, 5G hidden network.
149 2. Ensure the network is visible in scan.
150 3. Connect and run ping.
151
152 """
153 self.add_hiddenSSID_and_connect(self.open_hidden_5g)
Xianyuan Jia97a865e2020-11-10 02:09:40 +0000154
155 @test_tracker_info(uuid="62b664df-6397-4360-97bf-a8095c23a878")
156 def test_connect_to_wpa3_owe_hidden_2g(self):
157 """Connect to WPA3 OWE 2G hidden wifi network."""
158 self.add_hiddenSSID_and_connect(self.owe_networks[0]["2g"])
159
160 @test_tracker_info(uuid="dd7b029d-c008-4288-a91c-0820b0b3f29d")
161 def test_connect_to_wpa3_owe_hidden_5g(self):
162 """Connect to WPA3 OWE 5G hidden wifi network."""
163 self.add_hiddenSSID_and_connect(self.owe_networks[0]["5g"])
164
165 @test_tracker_info(uuid="1a9f3ee8-3db0-4f07-a604-66c14a897f94")
166 def test_connect_to_wpa3_sae_hidden_2g(self):
167 """Connect to WPA3 SAE 2G hidden wifi network."""
168 self.add_hiddenSSID_and_connect(self.sae_networks[0]["2g"])
169
170 @test_tracker_info(uuid="6c75618b-9c9b-4eb6-a922-ef1719704a9c")
171 def test_connect_to_wpa3_sae_hidden_5g(self):
172 """Connect to WPA3 SAE 5G hidden wifi network."""
173 self.add_hiddenSSID_and_connect(self.sae_networks[0]["5g"])