blob: 6612faafdbc2e3c89c969846adf5b91685f21cd1 [file] [log] [blame]
Girish Moturuf72690e2017-02-14 15:19:53 -08001#
2# Copyright 2017 - 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 logging
Girish Moturu2c21eb32017-05-25 14:37:55 +053017import random
Girish Moturuf72690e2017-02-14 15:19:53 -080018import socket
Girish Moturu2c21eb32017-05-25 14:37:55 +053019import time
Girish Moturuf72690e2017-02-14 15:19:53 -080020
21from acts import asserts
Girish Moturuf72690e2017-02-14 15:19:53 -080022from acts import test_runner
Girish Moturu8c771892019-11-07 08:33:57 -080023from acts import utils
Girish Moturuf72690e2017-02-14 15:19:53 -080024from acts.controllers import adb
Girish Moturu2c21eb32017-05-25 14:37:55 +053025from acts.test_decorators import test_tracker_info
Xianyuan Jia63751fb2020-11-17 00:07:40 +000026from acts_contrib.test_utils.tel import tel_defines
27from acts_contrib.test_utils.tel.tel_data_utils import wait_for_cell_data_connection
28from acts_contrib.test_utils.tel.tel_test_utils import get_operator_name
29from acts_contrib.test_utils.tel.tel_test_utils import verify_http_connection
30from acts_contrib.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_2G
31from acts_contrib.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_5G
32from acts_contrib.test_utils.net import socket_test_utils as sutils
33from acts_contrib.test_utils.net import arduino_test_utils as dutils
34from acts_contrib.test_utils.net import net_test_utils as nutils
35from acts_contrib.test_utils.wifi import wifi_test_utils as wutils
36from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest
Girish Moturuf72690e2017-02-14 15:19:53 -080037
Girish Moturu8d9741f2019-04-01 08:43:16 -070038WAIT_TIME = 5
Girish Moturuf72690e2017-02-14 15:19:53 -080039
Xianyuan Jia97a865e2020-11-10 02:09:40 +000040class WifiTetheringTest(WifiBaseTest):
Girish Moturuf72690e2017-02-14 15:19:53 -080041 """ Tests for Wifi Tethering """
42
43 def setup_class(self):
44 """ Setup devices for tethering and unpack params """
Xianyuan Jia97a865e2020-11-10 02:09:40 +000045 super().setup_class()
Girish Moturu2c21eb32017-05-25 14:37:55 +053046 self.hotspot_device = self.android_devices[0]
47 self.tethered_devices = self.android_devices[1:]
Girish Moturu8c771892019-11-07 08:33:57 -080048 req_params = ("url", "open_network")
Girish Moturuf72690e2017-02-14 15:19:53 -080049 self.unpack_userparams(req_params)
Girish Moturu8c771892019-11-07 08:33:57 -080050 self.network = {"SSID": "hotspot_%s" % utils.rand_ascii_str(6),
51 "password": "pass_%s" % utils.rand_ascii_str(6)}
Girish Moturuf10ed4c2020-06-13 11:03:43 -070052 self.new_ssid = "hs_%s" % utils.rand_ascii_str(6)
Girish Moturu2c21eb32017-05-25 14:37:55 +053053
Girish Moturu95f2f452018-07-23 15:57:15 -070054 nutils.verify_lte_data_and_tethering_supported(self.hotspot_device)
Girish Moturu2c21eb32017-05-25 14:37:55 +053055 for ad in self.tethered_devices:
56 wutils.wifi_test_device_init(ad)
Girish Moturuf72690e2017-02-14 15:19:53 -080057
jerry05261a22020-01-03 18:18:50 +080058 def setup_test(self):
Xianyuan Jia97a865e2020-11-10 02:09:40 +000059 super().setup_test()
Girish Moturuf10ed4c2020-06-13 11:03:43 -070060 self.tethered_devices[0].droid.telephonyToggleDataConnection(False)
jerry05261a22020-01-03 18:18:50 +080061
lutina8e26ac92019-11-25 18:38:11 +080062 def teardown_test(self):
Xianyuan Jia97a865e2020-11-10 02:09:40 +000063 super().teardown_test()
lutina8e26ac92019-11-25 18:38:11 +080064 if self.hotspot_device.droid.wifiIsApEnabled():
65 wutils.stop_wifi_tethering(self.hotspot_device)
Girish Moturuf10ed4c2020-06-13 11:03:43 -070066 self.tethered_devices[0].droid.telephonyToggleDataConnection(True)
lutina8e26ac92019-11-25 18:38:11 +080067
Girish Moturuf72690e2017-02-14 15:19:53 -080068 def teardown_class(self):
69 """ Reset devices """
Girish Moturu9bd1e9a2017-12-14 10:10:25 -080070 for ad in self.tethered_devices:
Girish Moturu95f2f452018-07-23 15:57:15 -070071 wutils.reset_wifi(ad)
Girish Moturu2c21eb32017-05-25 14:37:55 +053072
Girish Moturuf72690e2017-02-14 15:19:53 -080073 """ Helper functions """
74
Girish Moturu2c21eb32017-05-25 14:37:55 +053075 def _is_ipaddress_ipv6(self, ip_address):
Girish Moturuf72690e2017-02-14 15:19:53 -080076 """ Verify if the given string is a valid IPv6 address
77
78 Args:
79 1. string which contains the IP address
80
81 Returns:
82 True: if valid ipv6 address
83 False: if not
84 """
85 try:
86 socket.inet_pton(socket.AF_INET6, ip_address)
87 return True
88 except socket.error:
89 return False
90
91 def _supports_ipv6_tethering(self, dut):
92 """ Check if provider supports IPv6 tethering.
93 Currently, only Verizon supports IPv6 tethering
94
95 Returns:
96 True: if provider supports IPv6 tethering
97 False: if not
98 """
99 # Currently only Verizon support IPv6 tethering
Girish Moturube552fd2019-08-29 12:58:16 -0700100 carrier_supports_tethering = ["vzw", "tmo", "Far EasTone", "Chunghwa Telecom"]
Girish Moturu2c21eb32017-05-25 14:37:55 +0530101 operator = get_operator_name(self.log, dut)
Girish Moturuf72690e2017-02-14 15:19:53 -0800102 return operator in carrier_supports_tethering
103
Girish Moturu2c21eb32017-05-25 14:37:55 +0530104 def _carrier_supports_ipv6(self,dut):
105 """ Verify if carrier supports ipv6
106 Currently, only verizon and t-mobile supports IPv6
107
108 Returns:
109 True: if carrier supports ipv6
110 False: if not
111 """
sasahuangb5f72c52019-08-23 17:33:22 +0800112 carrier_supports_ipv6 = ["vzw", "tmo", "Far EasTone", "Chunghwa Telecom"]
Girish Moturu2c21eb32017-05-25 14:37:55 +0530113 operator = get_operator_name(self.log, dut)
Girish Moturu7f287522017-09-25 13:33:06 -0700114 self.log.info("Carrier is %s" % operator)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530115 return operator in carrier_supports_ipv6
116
Girish Moturu2c21eb32017-05-25 14:37:55 +0530117 def _verify_ipv6_tethering(self, dut):
Girish Moturuf72690e2017-02-14 15:19:53 -0800118 """ Verify IPv6 tethering """
119 http_response = dut.droid.httpRequestString(self.url)
Girish Moturuf72690e2017-02-14 15:19:53 -0800120 self.log.info("IP address %s " % http_response)
Girish Moturu0fd0b942017-12-12 12:04:56 -0800121 active_link_addrs = dut.droid.connectivityGetAllAddressesOfActiveLink()
Girish Moturu2c21eb32017-05-25 14:37:55 +0530122 if dut==self.hotspot_device and self._carrier_supports_ipv6(dut)\
123 or self._supports_ipv6_tethering(self.hotspot_device):
Girish Moturuf72690e2017-02-14 15:19:53 -0800124 asserts.assert_true(self._is_ipaddress_ipv6(http_response),
125 "The http response did not return IPv6 address")
Girish Moturu0fd0b942017-12-12 12:04:56 -0800126 asserts.assert_true(
127 active_link_addrs and http_response in str(active_link_addrs),
128 "Could not find IPv6 address in link properties")
129 asserts.assert_true(
130 dut.droid.connectivityHasIPv6DefaultRoute(),
131 "Could not find IPv6 default route in link properties")
Girish Moturuf72690e2017-02-14 15:19:53 -0800132 else:
Girish Moturu0fd0b942017-12-12 12:04:56 -0800133 asserts.assert_true(
134 not dut.droid.connectivityHasIPv6DefaultRoute(),
135 "Found IPv6 default route in link properties")
Girish Moturuf72690e2017-02-14 15:19:53 -0800136
Girish Moturu2c21eb32017-05-25 14:37:55 +0530137 def _start_wifi_tethering(self, wifi_band=WIFI_CONFIG_APBAND_2G):
138 """ Start wifi tethering on hotspot device
139
140 Args:
141 1. wifi_band: specifies the wifi band to start the hotspot
142 on. The current options are 2G and 5G
143 """
144 wutils.start_wifi_tethering(self.hotspot_device,
145 self.network[wutils.WifiEnums.SSID_KEY],
146 self.network[wutils.WifiEnums.PWD_KEY],
147 wifi_band)
148
149 def _connect_disconnect_devices(self):
150 """ Randomly connect and disconnect devices from the
151 self.tethered_devices list to hotspot device
152 """
153 device_connected = [ False ] * len(self.tethered_devices)
154 for _ in range(50):
155 dut_id = random.randint(0, len(self.tethered_devices)-1)
156 dut = self.tethered_devices[dut_id]
Girish Moturu7df90e32017-10-16 12:49:56 -0700157 # wait for 1 sec between connect & disconnect stress test
158 time.sleep(1)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530159 if device_connected[dut_id]:
160 wutils.wifi_forget_network(dut, self.network["SSID"])
161 else:
162 wutils.wifi_connect(dut, self.network)
163 device_connected[dut_id] = not device_connected[dut_id]
164
Girish Moturu47366062018-05-23 12:48:11 -0700165 def _connect_disconnect_android_device(self, dut_id, wifi_state):
166 """ Connect or disconnect wifi on android device depending on the
167 current wifi state
168
169 Args:
170 1. dut_id: tethered device to change the wifi state
171 2. wifi_state: current wifi state
172 """
173 ad = self.tethered_devices[dut_id]
174 if wifi_state:
175 self.log.info("Disconnecting wifi on android device")
176 wutils.wifi_forget_network(ad, self.network["SSID"])
177 else:
178 self.log.info("Connecting to wifi on android device")
179 wutils.wifi_connect(ad, self.network)
180
181 def _connect_disconnect_wifi_dongle(self, dut_id, wifi_state):
182 """ Connect or disconnect wifi on wifi dongle depending on the
183 current wifi state
184
185 Args:
186 1. dut_id: wifi dongle to change the wifi state
187 2. wifi_state: current wifi state
188 """
189 wd = self.arduino_wifi_dongles[dut_id]
190 if wifi_state:
191 self.log.info("Disconnecting wifi on dongle")
192 dutils.disconnect_wifi(wd)
193 else:
194 self.log.info("Connecting to wifi on dongle")
195 dutils.connect_wifi(wd, self.network)
196
197 def _connect_disconnect_tethered_devices(self):
198 """ Connect disconnect tethered devices to wifi hotspot """
199 num_android_devices = len(self.tethered_devices)
200 num_wifi_dongles = 0
Girish Moturu95f2f452018-07-23 15:57:15 -0700201 if hasattr(self, 'arduino_wifi_dongles'):
Girish Moturu47366062018-05-23 12:48:11 -0700202 num_wifi_dongles = len(self.arduino_wifi_dongles)
203 total_devices = num_android_devices + num_wifi_dongles
204 device_connected = [False] * total_devices
205 for _ in range(50):
206 dut_id = random.randint(0, total_devices-1)
207 wifi_state = device_connected[dut_id]
208 if dut_id < num_android_devices:
209 self._connect_disconnect_android_device(dut_id, wifi_state)
210 else:
211 self._connect_disconnect_wifi_dongle(dut_id-num_android_devices,
212 wifi_state)
213 device_connected[dut_id] = not device_connected[dut_id]
214
Girish Moturu7f287522017-09-25 13:33:06 -0700215 def _verify_ping(self, dut, ip, isIPv6=False):
Girish Moturu2c21eb32017-05-25 14:37:55 +0530216 """ Verify ping works from the dut to IP/hostname
217
218 Args:
219 1. dut - ad object to check ping from
220 2. ip - ip/hostname to ping (IPv4 and IPv6)
221
222 Returns:
223 True - if ping is successful
224 False - if not
225 """
226 self.log.info("Pinging %s from dut %s" % (ip, dut.serial))
Girish Moturu7f287522017-09-25 13:33:06 -0700227 if isIPv6 or self._is_ipaddress_ipv6(ip):
Girish Moturu2c21eb32017-05-25 14:37:55 +0530228 return dut.droid.pingHost(ip, 5, "ping6")
229 return dut.droid.pingHost(ip)
230
231 def _return_ip_for_interface(self, dut, iface_name):
232 """ Return list of IP addresses for an interface
233
234 Args:
235 1. dut - ad object
236 2. iface_name - interface name
237
238 Returns:
239 List of IPv4 and IPv6 addresses
240 """
241 return dut.droid.connectivityGetIPv4Addresses(iface_name) + \
242 dut.droid.connectivityGetIPv6Addresses(iface_name)
243
Girish Moturu47366062018-05-23 12:48:11 -0700244 def _test_traffic_between_two_tethered_devices(self, ad, wd):
Girish Moturu2c21eb32017-05-25 14:37:55 +0530245 """ Verify pinging interfaces of one DUT from another
246
247 Args:
Girish Moturu47366062018-05-23 12:48:11 -0700248 1. ad - android device
249 2. wd - wifi dongle
Girish Moturu2c21eb32017-05-25 14:37:55 +0530250 """
Girish Moturu47366062018-05-23 12:48:11 -0700251 wutils.wifi_connect(ad, self.network)
252 dutils.connect_wifi(wd, self.network)
253 local_ip = ad.droid.connectivityGetIPv4Addresses('wlan0')[0]
254 remote_ip = wd.ip_address()
255 port = 8888
Girish Moturu2c21eb32017-05-25 14:37:55 +0530256
Girish Moturu47366062018-05-23 12:48:11 -0700257 time.sleep(6) # wait until UDP packets method is invoked
Girish Moturuf5d2b2a2018-05-30 10:07:32 -0700258 socket = sutils.open_datagram_socket(ad, local_ip, port)
259 sutils.send_recv_data_datagram_sockets(
Girish Moturu47366062018-05-23 12:48:11 -0700260 ad, ad, socket, socket, remote_ip, port)
Girish Moturuf5d2b2a2018-05-30 10:07:32 -0700261 sutils.close_datagram_socket(ad, socket)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530262
263 def _ping_hotspot_interfaces_from_tethered_device(self, dut):
264 """ Ping hotspot interfaces from tethered device
265
266 Args:
267 1. dut - tethered device
268
269 Returns:
270 True - if all IP addresses are pingable
271 False - if not
272 """
273 ifaces = self.hotspot_device.droid.connectivityGetNetworkInterfaces()
274 return_result = True
275 for interface in ifaces:
276 iface_name = interface.split()[0].split(':')[1]
277 if iface_name == "lo":
278 continue
279 ip_list = self._return_ip_for_interface(
280 self.hotspot_device, iface_name)
281 for ip in ip_list:
282 ping_result = self._verify_ping(dut, ip)
283 self.log.info("Ping result: %s %s %s" %
284 (iface_name, ip, ping_result))
285 return_result = return_result and ping_result
286
287 return return_result
Girish Moturuf72690e2017-02-14 15:19:53 -0800288
Girish Moturub0768fa2018-02-13 15:24:27 -0800289 def _save_wifi_softap_configuration(self, ad, config):
290 """ Save soft AP configuration
291
292 Args:
293 1. dut - device to save configuration on
294 2. config - soft ap configuration
295 """
296 asserts.assert_true(ad.droid.wifiSetWifiApConfiguration(config),
297 "Failed to set WifiAp Configuration")
298 wifi_ap = ad.droid.wifiGetApConfiguration()
299 asserts.assert_true(wifi_ap[wutils.WifiEnums.SSID_KEY] == config[wutils.WifiEnums.SSID_KEY],
300 "Configured wifi hotspot SSID does not match with the expected SSID")
301
302 def _turn_on_wifi_hotspot(self, ad):
303 """ Turn on wifi hotspot with a config that is already saved
304
305 Args:
306 1. dut - device to turn wifi hotspot on
307 """
308 ad.droid.wifiStartTrackingTetherStateChange()
309 ad.droid.connectivityStartTethering(tel_defines.TETHERING_WIFI, False)
310 try:
311 ad.ed.pop_event("ConnectivityManagerOnTetheringStarted")
312 ad.ed.wait_for_event("TetherStateChanged",
313 lambda x: x["data"]["ACTIVE_TETHER"], 30)
314 except:
315 asserts.fail("Didn't receive wifi tethering starting confirmation")
316 ad.droid.wifiStopTrackingTetherStateChange()
317
Girish Moturuf72690e2017-02-14 15:19:53 -0800318 """ Test Cases """
319
Girish Moturu2c21eb32017-05-25 14:37:55 +0530320 @test_tracker_info(uuid="36d03295-bea3-446e-8342-b9f8f1962a32")
Girish Moturuf72690e2017-02-14 15:19:53 -0800321 def test_ipv6_tethering(self):
322 """ IPv6 tethering test
323
324 Steps:
Girish Moturu2c21eb32017-05-25 14:37:55 +0530325 1. Start wifi tethering on hotspot device
Girish Moturu7df90e32017-10-16 12:49:56 -0700326 2. Verify IPv6 address on hotspot device (VZW & TMO only)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530327 3. Connect tethered device to hotspot device
Girish Moturu7df90e32017-10-16 12:49:56 -0700328 4. Verify IPv6 address on the client's link properties (VZW only)
329 5. Verify ping on client using ping6 which should pass (VZW only)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530330 6. Disable mobile data on provider and verify that link properties
Girish Moturu7df90e32017-10-16 12:49:56 -0700331 does not have IPv6 address and default route (VZW only)
Girish Moturuf72690e2017-02-14 15:19:53 -0800332 """
333 # Start wifi tethering on the hotspot device
Girish Moturu2c21eb32017-05-25 14:37:55 +0530334 wutils.toggle_wifi_off_and_on(self.hotspot_device)
335 self._start_wifi_tethering()
Girish Moturuf72690e2017-02-14 15:19:53 -0800336
337 # Verify link properties on hotspot device
Girish Moturu7f287522017-09-25 13:33:06 -0700338 self.log.info("Check IPv6 properties on the hotspot device. "
339 "Verizon & T-mobile should have IPv6 in link properties")
Girish Moturuf72690e2017-02-14 15:19:53 -0800340 self._verify_ipv6_tethering(self.hotspot_device)
341
342 # Connect the client to the SSID
Girish Moturu2c21eb32017-05-25 14:37:55 +0530343 wutils.wifi_connect(self.tethered_devices[0], self.network)
Girish Moturuf72690e2017-02-14 15:19:53 -0800344
345 # Need to wait atleast 2 seconds for IPv6 address to
346 # show up in the link properties
Girish Moturu7f287522017-09-25 13:33:06 -0700347 time.sleep(WAIT_TIME)
Girish Moturuf72690e2017-02-14 15:19:53 -0800348
349 # Verify link properties on tethered device
Girish Moturu7f287522017-09-25 13:33:06 -0700350 self.log.info("Check IPv6 properties on the tethered device. "
351 "Device should have IPv6 if carrier is Verizon")
Girish Moturu2c21eb32017-05-25 14:37:55 +0530352 self._verify_ipv6_tethering(self.tethered_devices[0])
Girish Moturuf72690e2017-02-14 15:19:53 -0800353
354 # Verify ping6 on tethered device
Girish Moturu2c21eb32017-05-25 14:37:55 +0530355 ping_result = self._verify_ping(self.tethered_devices[0],
Girish Moturu7f287522017-09-25 13:33:06 -0700356 wutils.DEFAULT_PING_ADDR, True)
Girish Moturuf72690e2017-02-14 15:19:53 -0800357 if self._supports_ipv6_tethering(self.hotspot_device):
358 asserts.assert_true(ping_result, "Ping6 failed on the client")
359 else:
360 asserts.assert_true(not ping_result, "Ping6 failed as expected")
361
362 # Disable mobile data on hotspot device
363 # and verify the link properties on tethered device
Girish Moturu2c21eb32017-05-25 14:37:55 +0530364 self.log.info("Disabling mobile data to verify ipv6 default route")
Girish Moturuf72690e2017-02-14 15:19:53 -0800365 self.hotspot_device.droid.telephonyToggleDataConnection(False)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530366 asserts.assert_equal(
367 self.hotspot_device.droid.telephonyGetDataConnectionState(),
368 tel_defines.DATA_STATE_CONNECTED,
369 "Could not disable cell data")
370
Girish Moturu7f287522017-09-25 13:33:06 -0700371 time.sleep(WAIT_TIME) # wait until the IPv6 is removed from link properties
Girish Moturu2c21eb32017-05-25 14:37:55 +0530372
Girish Moturu0fd0b942017-12-12 12:04:56 -0800373 result = self.tethered_devices[0].droid.connectivityHasIPv6DefaultRoute()
Girish Moturu2c21eb32017-05-25 14:37:55 +0530374 self.hotspot_device.droid.telephonyToggleDataConnection(True)
Girish Moturu7df90e32017-10-16 12:49:56 -0700375 if result:
Girish Moturu2c21eb32017-05-25 14:37:55 +0530376 asserts.fail("Found IPv6 default route in link properties:Data off")
Girish Moturu7df90e32017-10-16 12:49:56 -0700377 self.log.info("Did not find IPv6 address in link properties")
Girish Moturu2c21eb32017-05-25 14:37:55 +0530378
379 # Disable wifi tethering
380 wutils.stop_wifi_tethering(self.hotspot_device)
381
382 @test_tracker_info(uuid="110b61d1-8af2-4589-8413-11beac7a3025")
Girish Moturu47366062018-05-23 12:48:11 -0700383 def test_wifi_tethering_2ghz_traffic_between_2tethered_devices(self):
Girish Moturu2c21eb32017-05-25 14:37:55 +0530384 """ Steps:
385
386 1. Start wifi hotspot with 2G band
387 2. Connect 2 tethered devices to the hotspot device
388 3. Ping interfaces between the tethered devices
389 """
Girish Moturu95f2f452018-07-23 15:57:15 -0700390 asserts.skip_if(not hasattr(self, 'arduino_wifi_dongles'),
391 "No wifi dongles connected. Skipping test")
Girish Moturu2c21eb32017-05-25 14:37:55 +0530392 wutils.toggle_wifi_off_and_on(self.hotspot_device)
393 self._start_wifi_tethering(WIFI_CONFIG_APBAND_2G)
394 self._test_traffic_between_two_tethered_devices(self.tethered_devices[0],
Girish Moturu47366062018-05-23 12:48:11 -0700395 self.arduino_wifi_dongles[0])
Girish Moturu2c21eb32017-05-25 14:37:55 +0530396 wutils.stop_wifi_tethering(self.hotspot_device)
397
398 @test_tracker_info(uuid="953f6e2e-27bd-4b73-85a6-d2eaa4e755d5")
Girish Moturu7df90e32017-10-16 12:49:56 -0700399 def wifi_tethering_5ghz_traffic_between_2tethered_devices(self):
Girish Moturu2c21eb32017-05-25 14:37:55 +0530400 """ Steps:
401
402 1. Start wifi hotspot with 5ghz band
403 2. Connect 2 tethered devices to the hotspot device
404 3. Send traffic between the tethered devices
405 """
406 wutils.toggle_wifi_off_and_on(self.hotspot_device)
407 self._start_wifi_tethering(WIFI_CONFIG_APBAND_5G)
408 self._test_traffic_between_two_tethered_devices(self.tethered_devices[0],
Girish Moturu47366062018-05-23 12:48:11 -0700409 self.arduino_wifi_dongles[0])
Girish Moturu2c21eb32017-05-25 14:37:55 +0530410 wutils.stop_wifi_tethering(self.hotspot_device)
411
412 @test_tracker_info(uuid="d7d5aa51-682d-4882-a334-61966d93b68c")
413 def test_wifi_tethering_2ghz_connect_disconnect_devices(self):
414 """ Steps:
415
416 1. Start wifi hotspot with 2ghz band
417 2. Connect and disconnect multiple devices randomly
418 3. Verify the correct functionality
419 """
420 wutils.toggle_wifi_off_and_on(self.hotspot_device)
421 self._start_wifi_tethering(WIFI_CONFIG_APBAND_2G)
Girish Moturu47366062018-05-23 12:48:11 -0700422 self._connect_disconnect_tethered_devices()
Girish Moturu2c21eb32017-05-25 14:37:55 +0530423 wutils.stop_wifi_tethering(self.hotspot_device)
424
425 @test_tracker_info(uuid="34abd6c9-c7f1-4d89-aa2b-a66aeabed9aa")
426 def test_wifi_tethering_5ghz_connect_disconnect_devices(self):
427 """ Steps:
428
429 1. Start wifi hotspot with 5ghz band
430 2. Connect and disconnect multiple devices randomly
431 3. Verify the correct functionality
432 """
433 wutils.toggle_wifi_off_and_on(self.hotspot_device)
434 self._start_wifi_tethering(WIFI_CONFIG_APBAND_5G)
435 self._connect_disconnect_devices()
436 wutils.stop_wifi_tethering(self.hotspot_device)
437
438 @test_tracker_info(uuid="7edfb220-37f8-42ea-8d7c-39712fbe9be5")
Girish Moturuf10ed4c2020-06-13 11:03:43 -0700439 def test_wifi_tethering_wpapsk_network_2g(self):
Girish Moturu2c21eb32017-05-25 14:37:55 +0530440 """ Steps:
441
Girish Moturuf10ed4c2020-06-13 11:03:43 -0700442 1. Start wifi tethering with wpapsk network 2G band
443 2. Connect tethered device to the SSID
444 3. Verify internet connectivity
Girish Moturu2c21eb32017-05-25 14:37:55 +0530445 """
Girish Moturuf10ed4c2020-06-13 11:03:43 -0700446 self._start_wifi_tethering()
447 wutils.connect_to_wifi_network(self.tethered_devices[0],
448 self.network,
449 check_connectivity=True)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530450
451 @test_tracker_info(uuid="17e450f4-795f-4e67-adab-984940dffedc")
Girish Moturuf10ed4c2020-06-13 11:03:43 -0700452 def test_wifi_tethering_wpapsk_network_5g(self):
Girish Moturu2c21eb32017-05-25 14:37:55 +0530453 """ Steps:
454
Girish Moturuf10ed4c2020-06-13 11:03:43 -0700455 1. Start wifi tethering with wpapsk network 5G band
456 2. Connect tethered device to the SSID
457 3. Verify internet connectivity
Girish Moturu2c21eb32017-05-25 14:37:55 +0530458 """
Girish Moturu2c21eb32017-05-25 14:37:55 +0530459 self._start_wifi_tethering(WIFI_CONFIG_APBAND_5G)
Girish Moturuf10ed4c2020-06-13 11:03:43 -0700460 wutils.connect_to_wifi_network(self.tethered_devices[0],
461 self.network,
462 check_connectivity=True)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530463
Girish Moturu2c21eb32017-05-25 14:37:55 +0530464 @test_tracker_info(uuid="2bc344cb-0277-4f06-b6cc-65b3972086ed")
465 def test_change_wifi_hotspot_ssid_when_hotspot_enabled(self):
466 """ Steps:
467
468 1. Start wifi tethering
469 2. Verify wifi Ap configuration
470 3. Change the SSID of the wifi hotspot while hotspot is on
471 4. Verify the new SSID in wifi ap configuration
472 5. Restart tethering and verify that the tethered device is able
473 to connect to the new SSID
474 """
Girish Moturu2c21eb32017-05-25 14:37:55 +0530475 dut = self.hotspot_device
476
477 # start tethering and verify the wifi ap configuration settings
478 self._start_wifi_tethering()
479 wifi_ap = dut.droid.wifiGetApConfiguration()
480 asserts.assert_true(
481 wifi_ap[wutils.WifiEnums.SSID_KEY] == \
482 self.network[wutils.WifiEnums.SSID_KEY],
483 "Configured wifi hotspot SSID did not match with the expected SSID")
Girish Moturuf10ed4c2020-06-13 11:03:43 -0700484 wutils.connect_to_wifi_network(self.tethered_devices[0], self.network)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530485
486 # update the wifi ap configuration with new ssid
487 config = {wutils.WifiEnums.SSID_KEY: self.new_ssid}
488 config[wutils.WifiEnums.PWD_KEY] = self.network[wutils.WifiEnums.PWD_KEY]
lesl6d30a172020-03-05 15:05:22 +0800489 config[wutils.WifiEnums.AP_BAND_KEY] = WIFI_CONFIG_APBAND_2G
Girish Moturub0768fa2018-02-13 15:24:27 -0800490 self._save_wifi_softap_configuration(dut, config)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530491
492 # start wifi tethering with new wifi ap configuration
493 wutils.stop_wifi_tethering(dut)
Girish Moturub0768fa2018-02-13 15:24:27 -0800494 self._turn_on_wifi_hotspot(dut)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530495
496 # verify dut can connect to new wifi ap configuration
497 new_network = {wutils.WifiEnums.SSID_KEY: self.new_ssid,
498 wutils.WifiEnums.PWD_KEY: \
499 self.network[wutils.WifiEnums.PWD_KEY]}
Girish Moturuf10ed4c2020-06-13 11:03:43 -0700500 wutils.connect_to_wifi_network(self.tethered_devices[0], new_network)
Girish Moturub0768fa2018-02-13 15:24:27 -0800501
502 @test_tracker_info(uuid="4cf7ab26-ca2d-46f6-9d3f-a935c7e04c97")
503 def test_wifi_tethering_open_network_2g(self):
504 """ Steps:
505
506 1. Start wifi tethering with open network 2G band
507 (Not allowed manually. b/72412729)
508 2. Connect tethered device to the SSID
509 3. Verify internet connectivity
510 """
Girish Moturuf10ed4c2020-06-13 11:03:43 -0700511 open_network = {
512 wutils.WifiEnums.SSID_KEY: "hs_2g_%s" % utils.rand_ascii_str(6)
513 }
Girish Moturub0768fa2018-02-13 15:24:27 -0800514 wutils.start_wifi_tethering(
Girish Moturuf10ed4c2020-06-13 11:03:43 -0700515 self.hotspot_device,
516 open_network[wutils.WifiEnums.SSID_KEY],
517 None,
518 WIFI_CONFIG_APBAND_2G)
519 wutils.connect_to_wifi_network(self.tethered_devices[0],
520 open_network,
521 check_connectivity=True)
Girish Moturub0768fa2018-02-13 15:24:27 -0800522
523 @test_tracker_info(uuid="f407049b-1324-40ea-a8d1-f90587933310")
524 def test_wifi_tethering_open_network_5g(self):
525 """ Steps:
526
527 1. Start wifi tethering with open network 5G band
528 (Not allowed manually. b/72412729)
529 2. Connect tethered device to the SSID
530 3. Verify internet connectivity
531 """
Girish Moturuf10ed4c2020-06-13 11:03:43 -0700532 open_network = {
533 wutils.WifiEnums.SSID_KEY: "hs_5g_%s" % utils.rand_ascii_str(6)
534 }
Girish Moturub0768fa2018-02-13 15:24:27 -0800535 wutils.start_wifi_tethering(
Girish Moturuf10ed4c2020-06-13 11:03:43 -0700536 self.hotspot_device,
537 open_network[wutils.WifiEnums.SSID_KEY],
538 None,
539 WIFI_CONFIG_APBAND_5G)
540 wutils.connect_to_wifi_network(self.tethered_devices[0],
541 open_network,
542 check_connectivity=True)
Girish Moturub0768fa2018-02-13 15:24:27 -0800543
544 @test_tracker_info(uuid="d964f2e6-0acb-417c-ada9-eb9fc5a470e4")
545 def test_wifi_tethering_open_network_2g_stress(self):
546 """ Steps:
547
548 1. Save wifi hotspot configuration with open network 2G band
549 (Not allowed manually. b/72412729)
550 2. Turn on wifi hotspot
551 3. Connect tethered device and verify internet connectivity
552 4. Turn off wifi hotspot
553 5. Repeat steps 2 to 4
554 """
555 # save open network wifi ap configuration with 2G band
556 config = {wutils.WifiEnums.SSID_KEY:
557 self.open_network[wutils.WifiEnums.SSID_KEY]}
lesl6d30a172020-03-05 15:05:22 +0800558 config[wutils.WifiEnums.AP_BAND_KEY] = WIFI_CONFIG_APBAND_2G
Girish Moturub0768fa2018-02-13 15:24:27 -0800559 self._save_wifi_softap_configuration(self.hotspot_device, config)
560
561 # turn on/off wifi hotspot, connect device
562 for _ in range(9):
563 self._turn_on_wifi_hotspot(self.hotspot_device)
lutina8e26ac92019-11-25 18:38:11 +0800564 wutils.connect_to_wifi_network(self.tethered_devices[0], self.open_network)
Girish Moturub0768fa2018-02-13 15:24:27 -0800565 wutils.stop_wifi_tethering(self.hotspot_device)
566 time.sleep(1) # wait for some time before turning on hotspot
567
568 @test_tracker_info(uuid="c7ef840c-4003-41fc-80e3-755f9057b542")
569 def test_wifi_tethering_open_network_5g_stress(self):
570 """ Steps:
571
572 1. Save wifi hotspot configuration with open network 5G band
573 (Not allowed manually. b/72412729)
574 2. Turn on wifi hotspot
575 3. Connect tethered device and verify internet connectivity
576 4. Turn off wifi hotspot
577 5. Repeat steps 2 to 4
578 """
579 # save open network wifi ap configuration with 5G band
580 config = {wutils.WifiEnums.SSID_KEY:
581 self.open_network[wutils.WifiEnums.SSID_KEY]}
lesl6d30a172020-03-05 15:05:22 +0800582 config[wutils.WifiEnums.AP_BAND_KEY] = WIFI_CONFIG_APBAND_5G
Girish Moturub0768fa2018-02-13 15:24:27 -0800583 self._save_wifi_softap_configuration(self.hotspot_device, config)
584
585 # turn on/off wifi hotspot, connect device
586 for _ in range(9):
587 self._turn_on_wifi_hotspot(self.hotspot_device)
lutina8e26ac92019-11-25 18:38:11 +0800588 wutils.connect_to_wifi_network(self.tethered_devices[0], self.open_network)
Girish Moturub0768fa2018-02-13 15:24:27 -0800589 wutils.stop_wifi_tethering(self.hotspot_device)
590 time.sleep(1) # wait for some time before turning on hotspot