blob: 623f9114eaf822e2366d327dac518bde1b855ad3 [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
22from acts import base_test
23from acts import test_runner
Girish Moturu8c771892019-11-07 08:33:57 -080024from acts import utils
Girish Moturuf72690e2017-02-14 15:19:53 -080025from acts.controllers import adb
Girish Moturu2c21eb32017-05-25 14:37:55 +053026from acts.test_decorators import test_tracker_info
Girish Moturuf72690e2017-02-14 15:19:53 -080027from acts.test_utils.tel import tel_defines
Girish Moturu2c21eb32017-05-25 14:37:55 +053028from acts.test_utils.tel.tel_data_utils import wait_for_cell_data_connection
29from acts.test_utils.tel.tel_test_utils import get_operator_name
Girish Moturu2c21eb32017-05-25 14:37:55 +053030from acts.test_utils.tel.tel_test_utils import verify_http_connection
31from acts.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_2G
32from acts.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_5G
Girish Moturuf5d2b2a2018-05-30 10:07:32 -070033from acts.test_utils.net import socket_test_utils as sutils
Girish Moturu47366062018-05-23 12:48:11 -070034from acts.test_utils.net import arduino_test_utils as dutils
Girish Moturu95f2f452018-07-23 15:57:15 -070035from acts.test_utils.net import net_test_utils as nutils
Girish Moturu2c21eb32017-05-25 14:37:55 +053036from acts.test_utils.wifi import wifi_test_utils as wutils
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
40class WifiTetheringTest(base_test.BaseTestClass):
41 """ Tests for Wifi Tethering """
42
43 def setup_class(self):
44 """ Setup devices for tethering and unpack params """
Girish Moturu2c21eb32017-05-25 14:37:55 +053045
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 Moturu666e0972018-01-02 11:20:31 -080052 self.new_ssid = "wifi_tethering_test2"
jerry05261a22020-01-03 18:18:50 +080053 self.tcpdump_pid=[]
Girish Moturu2c21eb32017-05-25 14:37:55 +053054
Girish Moturu95f2f452018-07-23 15:57:15 -070055 nutils.verify_lte_data_and_tethering_supported(self.hotspot_device)
Girish Moturu2c21eb32017-05-25 14:37:55 +053056 for ad in self.tethered_devices:
57 wutils.wifi_test_device_init(ad)
Girish Moturuf72690e2017-02-14 15:19:53 -080058
jerry05261a22020-01-03 18:18:50 +080059 def setup_test(self):
60 for ad in self.android_devices:
61 self.tcpdump_pid.append(nutils.start_tcpdump(ad, self.test_name))
62
lutina8e26ac92019-11-25 18:38:11 +080063 def teardown_test(self):
64 if self.hotspot_device.droid.wifiIsApEnabled():
65 wutils.stop_wifi_tethering(self.hotspot_device)
jerry05261a22020-01-03 18:18:50 +080066 for ad, pid in zip(self.android_devices, self.tcpdump_pid):
67 nutils.stop_tcpdump(ad, pid, self.test_name)
68 self.tcpdump_pid = []
69
lutina8e26ac92019-11-25 18:38:11 +080070
Girish Moturuf72690e2017-02-14 15:19:53 -080071 def teardown_class(self):
72 """ Reset devices """
Girish Moturu9bd1e9a2017-12-14 10:10:25 -080073 for ad in self.tethered_devices:
Girish Moturu95f2f452018-07-23 15:57:15 -070074 wutils.reset_wifi(ad)
Girish Moturu2c21eb32017-05-25 14:37:55 +053075
76 def on_fail(self, test_name, begin_time):
77 """ Collect bug report on failure """
Girish Moturu95f2f452018-07-23 15:57:15 -070078 for ad in self.android_devices:
Girish Moturu7df90e32017-10-16 12:49:56 -070079 ad.take_bug_report(test_name, begin_time)
Girish Moturuf72690e2017-02-14 15:19:53 -080080
81 """ Helper functions """
82
Girish Moturu2c21eb32017-05-25 14:37:55 +053083 def _is_ipaddress_ipv6(self, ip_address):
Girish Moturuf72690e2017-02-14 15:19:53 -080084 """ Verify if the given string is a valid IPv6 address
85
86 Args:
87 1. string which contains the IP address
88
89 Returns:
90 True: if valid ipv6 address
91 False: if not
92 """
93 try:
94 socket.inet_pton(socket.AF_INET6, ip_address)
95 return True
96 except socket.error:
97 return False
98
99 def _supports_ipv6_tethering(self, dut):
100 """ Check if provider supports IPv6 tethering.
101 Currently, only Verizon supports IPv6 tethering
102
103 Returns:
104 True: if provider supports IPv6 tethering
105 False: if not
106 """
107 # Currently only Verizon support IPv6 tethering
Girish Moturube552fd2019-08-29 12:58:16 -0700108 carrier_supports_tethering = ["vzw", "tmo", "Far EasTone", "Chunghwa Telecom"]
Girish Moturu2c21eb32017-05-25 14:37:55 +0530109 operator = get_operator_name(self.log, dut)
Girish Moturuf72690e2017-02-14 15:19:53 -0800110 return operator in carrier_supports_tethering
111
Girish Moturu2c21eb32017-05-25 14:37:55 +0530112 def _carrier_supports_ipv6(self,dut):
113 """ Verify if carrier supports ipv6
114 Currently, only verizon and t-mobile supports IPv6
115
116 Returns:
117 True: if carrier supports ipv6
118 False: if not
119 """
sasahuangb5f72c52019-08-23 17:33:22 +0800120 carrier_supports_ipv6 = ["vzw", "tmo", "Far EasTone", "Chunghwa Telecom"]
Girish Moturu2c21eb32017-05-25 14:37:55 +0530121 operator = get_operator_name(self.log, dut)
Girish Moturu7f287522017-09-25 13:33:06 -0700122 self.log.info("Carrier is %s" % operator)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530123 return operator in carrier_supports_ipv6
124
Girish Moturu2c21eb32017-05-25 14:37:55 +0530125 def _verify_ipv6_tethering(self, dut):
Girish Moturuf72690e2017-02-14 15:19:53 -0800126 """ Verify IPv6 tethering """
127 http_response = dut.droid.httpRequestString(self.url)
Girish Moturuf72690e2017-02-14 15:19:53 -0800128 self.log.info("IP address %s " % http_response)
Girish Moturu0fd0b942017-12-12 12:04:56 -0800129 active_link_addrs = dut.droid.connectivityGetAllAddressesOfActiveLink()
Girish Moturu2c21eb32017-05-25 14:37:55 +0530130 if dut==self.hotspot_device and self._carrier_supports_ipv6(dut)\
131 or self._supports_ipv6_tethering(self.hotspot_device):
Girish Moturuf72690e2017-02-14 15:19:53 -0800132 asserts.assert_true(self._is_ipaddress_ipv6(http_response),
133 "The http response did not return IPv6 address")
Girish Moturu0fd0b942017-12-12 12:04:56 -0800134 asserts.assert_true(
135 active_link_addrs and http_response in str(active_link_addrs),
136 "Could not find IPv6 address in link properties")
137 asserts.assert_true(
138 dut.droid.connectivityHasIPv6DefaultRoute(),
139 "Could not find IPv6 default route in link properties")
Girish Moturuf72690e2017-02-14 15:19:53 -0800140 else:
Girish Moturu0fd0b942017-12-12 12:04:56 -0800141 asserts.assert_true(
142 not dut.droid.connectivityHasIPv6DefaultRoute(),
143 "Found IPv6 default route in link properties")
Girish Moturuf72690e2017-02-14 15:19:53 -0800144
Girish Moturu2c21eb32017-05-25 14:37:55 +0530145 def _start_wifi_tethering(self, wifi_band=WIFI_CONFIG_APBAND_2G):
146 """ Start wifi tethering on hotspot device
147
148 Args:
149 1. wifi_band: specifies the wifi band to start the hotspot
150 on. The current options are 2G and 5G
151 """
152 wutils.start_wifi_tethering(self.hotspot_device,
153 self.network[wutils.WifiEnums.SSID_KEY],
154 self.network[wutils.WifiEnums.PWD_KEY],
155 wifi_band)
156
157 def _connect_disconnect_devices(self):
158 """ Randomly connect and disconnect devices from the
159 self.tethered_devices list to hotspot device
160 """
161 device_connected = [ False ] * len(self.tethered_devices)
162 for _ in range(50):
163 dut_id = random.randint(0, len(self.tethered_devices)-1)
164 dut = self.tethered_devices[dut_id]
Girish Moturu7df90e32017-10-16 12:49:56 -0700165 # wait for 1 sec between connect & disconnect stress test
166 time.sleep(1)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530167 if device_connected[dut_id]:
168 wutils.wifi_forget_network(dut, self.network["SSID"])
169 else:
170 wutils.wifi_connect(dut, self.network)
171 device_connected[dut_id] = not device_connected[dut_id]
172
Girish Moturu47366062018-05-23 12:48:11 -0700173 def _connect_disconnect_android_device(self, dut_id, wifi_state):
174 """ Connect or disconnect wifi on android device depending on the
175 current wifi state
176
177 Args:
178 1. dut_id: tethered device to change the wifi state
179 2. wifi_state: current wifi state
180 """
181 ad = self.tethered_devices[dut_id]
182 if wifi_state:
183 self.log.info("Disconnecting wifi on android device")
184 wutils.wifi_forget_network(ad, self.network["SSID"])
185 else:
186 self.log.info("Connecting to wifi on android device")
187 wutils.wifi_connect(ad, self.network)
188
189 def _connect_disconnect_wifi_dongle(self, dut_id, wifi_state):
190 """ Connect or disconnect wifi on wifi dongle depending on the
191 current wifi state
192
193 Args:
194 1. dut_id: wifi dongle to change the wifi state
195 2. wifi_state: current wifi state
196 """
197 wd = self.arduino_wifi_dongles[dut_id]
198 if wifi_state:
199 self.log.info("Disconnecting wifi on dongle")
200 dutils.disconnect_wifi(wd)
201 else:
202 self.log.info("Connecting to wifi on dongle")
203 dutils.connect_wifi(wd, self.network)
204
205 def _connect_disconnect_tethered_devices(self):
206 """ Connect disconnect tethered devices to wifi hotspot """
207 num_android_devices = len(self.tethered_devices)
208 num_wifi_dongles = 0
Girish Moturu95f2f452018-07-23 15:57:15 -0700209 if hasattr(self, 'arduino_wifi_dongles'):
Girish Moturu47366062018-05-23 12:48:11 -0700210 num_wifi_dongles = len(self.arduino_wifi_dongles)
211 total_devices = num_android_devices + num_wifi_dongles
212 device_connected = [False] * total_devices
213 for _ in range(50):
214 dut_id = random.randint(0, total_devices-1)
215 wifi_state = device_connected[dut_id]
216 if dut_id < num_android_devices:
217 self._connect_disconnect_android_device(dut_id, wifi_state)
218 else:
219 self._connect_disconnect_wifi_dongle(dut_id-num_android_devices,
220 wifi_state)
221 device_connected[dut_id] = not device_connected[dut_id]
222
Girish Moturu7f287522017-09-25 13:33:06 -0700223 def _verify_ping(self, dut, ip, isIPv6=False):
Girish Moturu2c21eb32017-05-25 14:37:55 +0530224 """ Verify ping works from the dut to IP/hostname
225
226 Args:
227 1. dut - ad object to check ping from
228 2. ip - ip/hostname to ping (IPv4 and IPv6)
229
230 Returns:
231 True - if ping is successful
232 False - if not
233 """
234 self.log.info("Pinging %s from dut %s" % (ip, dut.serial))
Girish Moturu7f287522017-09-25 13:33:06 -0700235 if isIPv6 or self._is_ipaddress_ipv6(ip):
Girish Moturu2c21eb32017-05-25 14:37:55 +0530236 return dut.droid.pingHost(ip, 5, "ping6")
237 return dut.droid.pingHost(ip)
238
239 def _return_ip_for_interface(self, dut, iface_name):
240 """ Return list of IP addresses for an interface
241
242 Args:
243 1. dut - ad object
244 2. iface_name - interface name
245
246 Returns:
247 List of IPv4 and IPv6 addresses
248 """
249 return dut.droid.connectivityGetIPv4Addresses(iface_name) + \
250 dut.droid.connectivityGetIPv6Addresses(iface_name)
251
Girish Moturu47366062018-05-23 12:48:11 -0700252 def _test_traffic_between_two_tethered_devices(self, ad, wd):
Girish Moturu2c21eb32017-05-25 14:37:55 +0530253 """ Verify pinging interfaces of one DUT from another
254
255 Args:
Girish Moturu47366062018-05-23 12:48:11 -0700256 1. ad - android device
257 2. wd - wifi dongle
Girish Moturu2c21eb32017-05-25 14:37:55 +0530258 """
Girish Moturu47366062018-05-23 12:48:11 -0700259 wutils.wifi_connect(ad, self.network)
260 dutils.connect_wifi(wd, self.network)
261 local_ip = ad.droid.connectivityGetIPv4Addresses('wlan0')[0]
262 remote_ip = wd.ip_address()
263 port = 8888
Girish Moturu2c21eb32017-05-25 14:37:55 +0530264
Girish Moturu47366062018-05-23 12:48:11 -0700265 time.sleep(6) # wait until UDP packets method is invoked
Girish Moturuf5d2b2a2018-05-30 10:07:32 -0700266 socket = sutils.open_datagram_socket(ad, local_ip, port)
267 sutils.send_recv_data_datagram_sockets(
Girish Moturu47366062018-05-23 12:48:11 -0700268 ad, ad, socket, socket, remote_ip, port)
Girish Moturuf5d2b2a2018-05-30 10:07:32 -0700269 sutils.close_datagram_socket(ad, socket)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530270
271 def _ping_hotspot_interfaces_from_tethered_device(self, dut):
272 """ Ping hotspot interfaces from tethered device
273
274 Args:
275 1. dut - tethered device
276
277 Returns:
278 True - if all IP addresses are pingable
279 False - if not
280 """
281 ifaces = self.hotspot_device.droid.connectivityGetNetworkInterfaces()
282 return_result = True
283 for interface in ifaces:
284 iface_name = interface.split()[0].split(':')[1]
285 if iface_name == "lo":
286 continue
287 ip_list = self._return_ip_for_interface(
288 self.hotspot_device, iface_name)
289 for ip in ip_list:
290 ping_result = self._verify_ping(dut, ip)
291 self.log.info("Ping result: %s %s %s" %
292 (iface_name, ip, ping_result))
293 return_result = return_result and ping_result
294
295 return return_result
Girish Moturuf72690e2017-02-14 15:19:53 -0800296
Girish Moturub0768fa2018-02-13 15:24:27 -0800297 def _save_wifi_softap_configuration(self, ad, config):
298 """ Save soft AP configuration
299
300 Args:
301 1. dut - device to save configuration on
302 2. config - soft ap configuration
303 """
304 asserts.assert_true(ad.droid.wifiSetWifiApConfiguration(config),
305 "Failed to set WifiAp Configuration")
306 wifi_ap = ad.droid.wifiGetApConfiguration()
307 asserts.assert_true(wifi_ap[wutils.WifiEnums.SSID_KEY] == config[wutils.WifiEnums.SSID_KEY],
308 "Configured wifi hotspot SSID does not match with the expected SSID")
309
310 def _turn_on_wifi_hotspot(self, ad):
311 """ Turn on wifi hotspot with a config that is already saved
312
313 Args:
314 1. dut - device to turn wifi hotspot on
315 """
316 ad.droid.wifiStartTrackingTetherStateChange()
317 ad.droid.connectivityStartTethering(tel_defines.TETHERING_WIFI, False)
318 try:
319 ad.ed.pop_event("ConnectivityManagerOnTetheringStarted")
320 ad.ed.wait_for_event("TetherStateChanged",
321 lambda x: x["data"]["ACTIVE_TETHER"], 30)
322 except:
323 asserts.fail("Didn't receive wifi tethering starting confirmation")
324 ad.droid.wifiStopTrackingTetherStateChange()
325
Girish Moturuf72690e2017-02-14 15:19:53 -0800326 """ Test Cases """
327
Girish Moturu2c21eb32017-05-25 14:37:55 +0530328 @test_tracker_info(uuid="36d03295-bea3-446e-8342-b9f8f1962a32")
Girish Moturuf72690e2017-02-14 15:19:53 -0800329 def test_ipv6_tethering(self):
330 """ IPv6 tethering test
331
332 Steps:
Girish Moturu2c21eb32017-05-25 14:37:55 +0530333 1. Start wifi tethering on hotspot device
Girish Moturu7df90e32017-10-16 12:49:56 -0700334 2. Verify IPv6 address on hotspot device (VZW & TMO only)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530335 3. Connect tethered device to hotspot device
Girish Moturu7df90e32017-10-16 12:49:56 -0700336 4. Verify IPv6 address on the client's link properties (VZW only)
337 5. Verify ping on client using ping6 which should pass (VZW only)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530338 6. Disable mobile data on provider and verify that link properties
Girish Moturu7df90e32017-10-16 12:49:56 -0700339 does not have IPv6 address and default route (VZW only)
Girish Moturuf72690e2017-02-14 15:19:53 -0800340 """
341 # Start wifi tethering on the hotspot device
Girish Moturu2c21eb32017-05-25 14:37:55 +0530342 wutils.toggle_wifi_off_and_on(self.hotspot_device)
343 self._start_wifi_tethering()
Girish Moturuf72690e2017-02-14 15:19:53 -0800344
345 # Verify link properties on hotspot device
Girish Moturu7f287522017-09-25 13:33:06 -0700346 self.log.info("Check IPv6 properties on the hotspot device. "
347 "Verizon & T-mobile should have IPv6 in link properties")
Girish Moturuf72690e2017-02-14 15:19:53 -0800348 self._verify_ipv6_tethering(self.hotspot_device)
349
350 # Connect the client to the SSID
Girish Moturu2c21eb32017-05-25 14:37:55 +0530351 wutils.wifi_connect(self.tethered_devices[0], self.network)
Girish Moturuf72690e2017-02-14 15:19:53 -0800352
353 # Need to wait atleast 2 seconds for IPv6 address to
354 # show up in the link properties
Girish Moturu7f287522017-09-25 13:33:06 -0700355 time.sleep(WAIT_TIME)
Girish Moturuf72690e2017-02-14 15:19:53 -0800356
357 # Verify link properties on tethered device
Girish Moturu7f287522017-09-25 13:33:06 -0700358 self.log.info("Check IPv6 properties on the tethered device. "
359 "Device should have IPv6 if carrier is Verizon")
Girish Moturu2c21eb32017-05-25 14:37:55 +0530360 self._verify_ipv6_tethering(self.tethered_devices[0])
Girish Moturuf72690e2017-02-14 15:19:53 -0800361
362 # Verify ping6 on tethered device
Girish Moturu2c21eb32017-05-25 14:37:55 +0530363 ping_result = self._verify_ping(self.tethered_devices[0],
Girish Moturu7f287522017-09-25 13:33:06 -0700364 wutils.DEFAULT_PING_ADDR, True)
Girish Moturuf72690e2017-02-14 15:19:53 -0800365 if self._supports_ipv6_tethering(self.hotspot_device):
366 asserts.assert_true(ping_result, "Ping6 failed on the client")
367 else:
368 asserts.assert_true(not ping_result, "Ping6 failed as expected")
369
370 # Disable mobile data on hotspot device
371 # and verify the link properties on tethered device
Girish Moturu2c21eb32017-05-25 14:37:55 +0530372 self.log.info("Disabling mobile data to verify ipv6 default route")
Girish Moturuf72690e2017-02-14 15:19:53 -0800373 self.hotspot_device.droid.telephonyToggleDataConnection(False)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530374 asserts.assert_equal(
375 self.hotspot_device.droid.telephonyGetDataConnectionState(),
376 tel_defines.DATA_STATE_CONNECTED,
377 "Could not disable cell data")
378
Girish Moturu7f287522017-09-25 13:33:06 -0700379 time.sleep(WAIT_TIME) # wait until the IPv6 is removed from link properties
Girish Moturu2c21eb32017-05-25 14:37:55 +0530380
Girish Moturu0fd0b942017-12-12 12:04:56 -0800381 result = self.tethered_devices[0].droid.connectivityHasIPv6DefaultRoute()
Girish Moturu2c21eb32017-05-25 14:37:55 +0530382 self.hotspot_device.droid.telephonyToggleDataConnection(True)
Girish Moturu7df90e32017-10-16 12:49:56 -0700383 if result:
Girish Moturu2c21eb32017-05-25 14:37:55 +0530384 asserts.fail("Found IPv6 default route in link properties:Data off")
Girish Moturu7df90e32017-10-16 12:49:56 -0700385 self.log.info("Did not find IPv6 address in link properties")
Girish Moturu2c21eb32017-05-25 14:37:55 +0530386
387 # Disable wifi tethering
388 wutils.stop_wifi_tethering(self.hotspot_device)
389
390 @test_tracker_info(uuid="110b61d1-8af2-4589-8413-11beac7a3025")
Girish Moturu47366062018-05-23 12:48:11 -0700391 def test_wifi_tethering_2ghz_traffic_between_2tethered_devices(self):
Girish Moturu2c21eb32017-05-25 14:37:55 +0530392 """ Steps:
393
394 1. Start wifi hotspot with 2G band
395 2. Connect 2 tethered devices to the hotspot device
396 3. Ping interfaces between the tethered devices
397 """
Girish Moturu95f2f452018-07-23 15:57:15 -0700398 asserts.skip_if(not hasattr(self, 'arduino_wifi_dongles'),
399 "No wifi dongles connected. Skipping test")
Girish Moturu2c21eb32017-05-25 14:37:55 +0530400 wutils.toggle_wifi_off_and_on(self.hotspot_device)
401 self._start_wifi_tethering(WIFI_CONFIG_APBAND_2G)
402 self._test_traffic_between_two_tethered_devices(self.tethered_devices[0],
Girish Moturu47366062018-05-23 12:48:11 -0700403 self.arduino_wifi_dongles[0])
Girish Moturu2c21eb32017-05-25 14:37:55 +0530404 wutils.stop_wifi_tethering(self.hotspot_device)
405
406 @test_tracker_info(uuid="953f6e2e-27bd-4b73-85a6-d2eaa4e755d5")
Girish Moturu7df90e32017-10-16 12:49:56 -0700407 def wifi_tethering_5ghz_traffic_between_2tethered_devices(self):
Girish Moturu2c21eb32017-05-25 14:37:55 +0530408 """ Steps:
409
410 1. Start wifi hotspot with 5ghz band
411 2. Connect 2 tethered devices to the hotspot device
412 3. Send traffic between the tethered devices
413 """
414 wutils.toggle_wifi_off_and_on(self.hotspot_device)
415 self._start_wifi_tethering(WIFI_CONFIG_APBAND_5G)
416 self._test_traffic_between_two_tethered_devices(self.tethered_devices[0],
Girish Moturu47366062018-05-23 12:48:11 -0700417 self.arduino_wifi_dongles[0])
Girish Moturu2c21eb32017-05-25 14:37:55 +0530418 wutils.stop_wifi_tethering(self.hotspot_device)
419
420 @test_tracker_info(uuid="d7d5aa51-682d-4882-a334-61966d93b68c")
421 def test_wifi_tethering_2ghz_connect_disconnect_devices(self):
422 """ Steps:
423
424 1. Start wifi hotspot with 2ghz band
425 2. Connect and disconnect multiple devices randomly
426 3. Verify the correct functionality
427 """
428 wutils.toggle_wifi_off_and_on(self.hotspot_device)
429 self._start_wifi_tethering(WIFI_CONFIG_APBAND_2G)
Girish Moturu47366062018-05-23 12:48:11 -0700430 self._connect_disconnect_tethered_devices()
Girish Moturu2c21eb32017-05-25 14:37:55 +0530431 wutils.stop_wifi_tethering(self.hotspot_device)
432
433 @test_tracker_info(uuid="34abd6c9-c7f1-4d89-aa2b-a66aeabed9aa")
434 def test_wifi_tethering_5ghz_connect_disconnect_devices(self):
435 """ Steps:
436
437 1. Start wifi hotspot with 5ghz band
438 2. Connect and disconnect multiple devices randomly
439 3. Verify the correct functionality
440 """
441 wutils.toggle_wifi_off_and_on(self.hotspot_device)
442 self._start_wifi_tethering(WIFI_CONFIG_APBAND_5G)
443 self._connect_disconnect_devices()
444 wutils.stop_wifi_tethering(self.hotspot_device)
445
446 @test_tracker_info(uuid="7edfb220-37f8-42ea-8d7c-39712fbe9be5")
447 def test_wifi_tethering_2ghz_ping_hotspot_interfaces(self):
448 """ Steps:
449
450 1. Start wifi hotspot with 2ghz band
451 2. Connect tethered device to hotspot device
452 3. Ping 'wlan0' and 'rmnet_data' interface's IPv4
453 and IPv6 interfaces on hotspot device from tethered device
454 """
455 wutils.toggle_wifi_off_and_on(self.hotspot_device)
456 self._start_wifi_tethering(WIFI_CONFIG_APBAND_2G)
457 wutils.wifi_connect(self.tethered_devices[0], self.network)
458 result = self._ping_hotspot_interfaces_from_tethered_device(
459 self.tethered_devices[0])
460 wutils.stop_wifi_tethering(self.hotspot_device)
461 return result
462
463 @test_tracker_info(uuid="17e450f4-795f-4e67-adab-984940dffedc")
464 def test_wifi_tethering_5ghz_ping_hotspot_interfaces(self):
465 """ Steps:
466
467 1. Start wifi hotspot with 5ghz band
468 2. Connect tethered device to hotspot device
469 3. Ping 'wlan0' and 'rmnet_data' interface's IPv4
470 and IPv6 interfaces on hotspot device from tethered device
471 """
472 wutils.toggle_wifi_off_and_on(self.hotspot_device)
473 self._start_wifi_tethering(WIFI_CONFIG_APBAND_5G)
474 wutils.wifi_connect(self.tethered_devices[0], self.network)
475 result = self._ping_hotspot_interfaces_from_tethered_device(
476 self.tethered_devices[0])
477 wutils.stop_wifi_tethering(self.hotspot_device)
478 return result
479
Girish Moturu2c21eb32017-05-25 14:37:55 +0530480 @test_tracker_info(uuid="2bc344cb-0277-4f06-b6cc-65b3972086ed")
481 def test_change_wifi_hotspot_ssid_when_hotspot_enabled(self):
482 """ Steps:
483
484 1. Start wifi tethering
485 2. Verify wifi Ap configuration
486 3. Change the SSID of the wifi hotspot while hotspot is on
487 4. Verify the new SSID in wifi ap configuration
488 5. Restart tethering and verify that the tethered device is able
489 to connect to the new SSID
490 """
491 wutils.toggle_wifi_off_and_on(self.hotspot_device)
492 dut = self.hotspot_device
493
494 # start tethering and verify the wifi ap configuration settings
495 self._start_wifi_tethering()
496 wifi_ap = dut.droid.wifiGetApConfiguration()
497 asserts.assert_true(
498 wifi_ap[wutils.WifiEnums.SSID_KEY] == \
499 self.network[wutils.WifiEnums.SSID_KEY],
500 "Configured wifi hotspot SSID did not match with the expected SSID")
501 wutils.wifi_connect(self.tethered_devices[0], self.network)
502
503 # update the wifi ap configuration with new ssid
504 config = {wutils.WifiEnums.SSID_KEY: self.new_ssid}
505 config[wutils.WifiEnums.PWD_KEY] = self.network[wutils.WifiEnums.PWD_KEY]
lesl6d30a172020-03-05 15:05:22 +0800506 config[wutils.WifiEnums.AP_BAND_KEY] = WIFI_CONFIG_APBAND_2G
Girish Moturub0768fa2018-02-13 15:24:27 -0800507 self._save_wifi_softap_configuration(dut, config)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530508
509 # start wifi tethering with new wifi ap configuration
510 wutils.stop_wifi_tethering(dut)
Girish Moturub0768fa2018-02-13 15:24:27 -0800511 self._turn_on_wifi_hotspot(dut)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530512
513 # verify dut can connect to new wifi ap configuration
514 new_network = {wutils.WifiEnums.SSID_KEY: self.new_ssid,
515 wutils.WifiEnums.PWD_KEY: \
516 self.network[wutils.WifiEnums.PWD_KEY]}
517 wutils.wifi_connect(self.tethered_devices[0], new_network)
518 wutils.stop_wifi_tethering(self.hotspot_device)
Girish Moturub0768fa2018-02-13 15:24:27 -0800519
520 @test_tracker_info(uuid="4cf7ab26-ca2d-46f6-9d3f-a935c7e04c97")
521 def test_wifi_tethering_open_network_2g(self):
522 """ Steps:
523
524 1. Start wifi tethering with open network 2G band
525 (Not allowed manually. b/72412729)
526 2. Connect tethered device to the SSID
527 3. Verify internet connectivity
528 """
529 wutils.start_wifi_tethering(
530 self.hotspot_device, self.open_network[wutils.WifiEnums.SSID_KEY],
531 None, WIFI_CONFIG_APBAND_2G)
532 wutils.wifi_connect(self.tethered_devices[0], self.open_network)
533 wutils.stop_wifi_tethering(self.hotspot_device)
534
535 @test_tracker_info(uuid="f407049b-1324-40ea-a8d1-f90587933310")
536 def test_wifi_tethering_open_network_5g(self):
537 """ Steps:
538
539 1. Start wifi tethering with open network 5G band
540 (Not allowed manually. b/72412729)
541 2. Connect tethered device to the SSID
542 3. Verify internet connectivity
543 """
544 wutils.start_wifi_tethering(
545 self.hotspot_device, self.open_network[wutils.WifiEnums.SSID_KEY],
546 None, WIFI_CONFIG_APBAND_5G)
547 wutils.wifi_connect(self.tethered_devices[0], self.open_network)
548 wutils.stop_wifi_tethering(self.hotspot_device)
549
550 @test_tracker_info(uuid="d964f2e6-0acb-417c-ada9-eb9fc5a470e4")
551 def test_wifi_tethering_open_network_2g_stress(self):
552 """ Steps:
553
554 1. Save wifi hotspot configuration with open network 2G band
555 (Not allowed manually. b/72412729)
556 2. Turn on wifi hotspot
557 3. Connect tethered device and verify internet connectivity
558 4. Turn off wifi hotspot
559 5. Repeat steps 2 to 4
560 """
561 # save open network wifi ap configuration with 2G band
562 config = {wutils.WifiEnums.SSID_KEY:
563 self.open_network[wutils.WifiEnums.SSID_KEY]}
lesl6d30a172020-03-05 15:05:22 +0800564 config[wutils.WifiEnums.AP_BAND_KEY] = WIFI_CONFIG_APBAND_2G
Girish Moturub0768fa2018-02-13 15:24:27 -0800565 self._save_wifi_softap_configuration(self.hotspot_device, config)
566
567 # turn on/off wifi hotspot, connect device
568 for _ in range(9):
569 self._turn_on_wifi_hotspot(self.hotspot_device)
lutina8e26ac92019-11-25 18:38:11 +0800570 wutils.connect_to_wifi_network(self.tethered_devices[0], self.open_network)
Girish Moturub0768fa2018-02-13 15:24:27 -0800571 wutils.stop_wifi_tethering(self.hotspot_device)
572 time.sleep(1) # wait for some time before turning on hotspot
573
574 @test_tracker_info(uuid="c7ef840c-4003-41fc-80e3-755f9057b542")
575 def test_wifi_tethering_open_network_5g_stress(self):
576 """ Steps:
577
578 1. Save wifi hotspot configuration with open network 5G band
579 (Not allowed manually. b/72412729)
580 2. Turn on wifi hotspot
581 3. Connect tethered device and verify internet connectivity
582 4. Turn off wifi hotspot
583 5. Repeat steps 2 to 4
584 """
585 # save open network wifi ap configuration with 5G band
586 config = {wutils.WifiEnums.SSID_KEY:
587 self.open_network[wutils.WifiEnums.SSID_KEY]}
lesl6d30a172020-03-05 15:05:22 +0800588 config[wutils.WifiEnums.AP_BAND_KEY] = WIFI_CONFIG_APBAND_5G
Girish Moturub0768fa2018-02-13 15:24:27 -0800589 self._save_wifi_softap_configuration(self.hotspot_device, config)
590
591 # turn on/off wifi hotspot, connect device
592 for _ in range(9):
593 self._turn_on_wifi_hotspot(self.hotspot_device)
lutina8e26ac92019-11-25 18:38:11 +0800594 wutils.connect_to_wifi_network(self.tethered_devices[0], self.open_network)
Girish Moturub0768fa2018-02-13 15:24:27 -0800595 wutils.stop_wifi_tethering(self.hotspot_device)
596 time.sleep(1) # wait for some time before turning on hotspot