blob: d779529765e32c0cad375670b976bc72c72b2078 [file] [log] [blame]
Bindu Mahadev36725332019-01-29 12:23:21 -08001#!/usr/bin/env python3.4
2#
3# Copyright 2019 - 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
17import itertools
18import pprint
19import queue
xshu5ab5ef62019-04-16 17:32:38 -070020import re
Bindu Mahadev36725332019-01-29 12:23:21 -080021import time
22
23import acts.base_test
24import acts.signals as signals
Xianyuan Jia63751fb2020-11-17 00:07:40 +000025import acts_contrib.test_utils.wifi.wifi_test_utils as wutils
Bindu Mahadev36725332019-01-29 12:23:21 -080026import acts.utils
27
28from acts import asserts
29from acts.test_decorators import test_tracker_info
Xianyuan Jia63751fb2020-11-17 00:07:40 +000030from 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.wifi.WifiBaseTest import WifiBaseTest
Bindu Mahadev2941f482019-03-18 16:46:08 -070033from scapy.all import *
xshu5ab5ef62019-04-16 17:32:38 -070034from acts.controllers.ap_lib import hostapd_constants
Bindu Mahadev36725332019-01-29 12:23:21 -080035
36WifiEnums = wutils.WifiEnums
37
38# Default timeout used for reboot, toggle WiFi and Airplane mode,
39# for the system to settle down after the operation.
40DEFAULT_TIMEOUT = 10
Bindu Mahadev2941f482019-03-18 16:46:08 -070041SHORT_TIMEOUT = 5
Bindu Mahadev36725332019-01-29 12:23:21 -080042
43# Constants for WiFi state change operations.
44FORGET = 1
45TOGGLE = 2
46REBOOT_DUT = 3
47REBOOT_AP = 4
48
49# MAC Randomization setting constants.
50RANDOMIZATION_NONE = 0
51RANDOMIZATION_PERSISTENT = 1
52
53
54class WifiMacRandomizationTest(WifiBaseTest):
55 """Tests for APIs in Android's WifiManager class.
56
57 Test Bed Requirement:
58 * Atleast one Android device and atleast two Access Points.
59 * Several Wi-Fi networks visible to the device.
60 """
61
Bindu Mahadev36725332019-01-29 12:23:21 -080062 def setup_class(self):
Xianyuan Jia168103b2019-09-06 12:22:52 -070063 super().setup_class()
64
Bindu Mahadev36725332019-01-29 12:23:21 -080065 self.dut = self.android_devices[0]
66 self.dut_client = self.android_devices[1]
67 wutils.wifi_test_device_init(self.dut)
68 wutils.wifi_test_device_init(self.dut_client)
Girish Moturu36348a32019-12-10 08:41:54 -080069 req_params = ["dbs_supported_models", "roaming_attn"]
Bindu Mahadev36725332019-01-29 12:23:21 -080070 opt_param = [
71 "open_network", "reference_networks", "wep_networks"
72 ]
73 self.unpack_userparams(
74 req_param_names=req_params, opt_param_names=opt_param)
75
xshu5ab5ef62019-04-16 17:32:38 -070076 if not hasattr(self, 'packet_capture'):
77 raise signals.TestFailure("Needs packet_capture attribute to "
78 "support sniffing.")
79 self.configure_packet_capture()
Bindu Mahadevfcdac502019-04-16 18:43:23 -070080
Bindu Mahadev36725332019-01-29 12:23:21 -080081 if "AccessPoint" in self.user_params:
Girish Moturu11d74442020-11-06 13:20:20 -080082 self.legacy_configure_ap_and_start(wep_network=True,
83 ap_count=2)
84 elif "OpenWrtAP" in self.user_params:
85 self.configure_openwrt_ap_and_start(open_network=True,
86 wpa_network=True,
87 wep_network=True,
88 mirror_ap=True,
89 ap_count=2)
Bindu Mahadev36725332019-01-29 12:23:21 -080090
91 asserts.assert_true(
92 len(self.reference_networks) > 0,
93 "Need at least one reference network with psk.")
94
xshu5ab5ef62019-04-16 17:32:38 -070095 # Reboot device to reset factory MAC of wlan1
96 self.dut.reboot()
97 self.dut_client.reboot()
98 time.sleep(DEFAULT_TIMEOUT)
Bindu Mahadev36725332019-01-29 12:23:21 -080099 wutils.wifi_toggle_state(self.dut, True)
100 wutils.wifi_toggle_state(self.dut_client, True)
xshu5ab5ef62019-04-16 17:32:38 -0700101 self.soft_ap_factory_mac = self.get_soft_ap_mac_address()
102 self.sta_factory_mac = self.dut.droid.wifigetFactorymacAddresses()[0]
103
Bindu Mahadev36725332019-01-29 12:23:21 -0800104 self.wpapsk_2g = self.reference_networks[0]["2g"]
105 self.wpapsk_5g = self.reference_networks[0]["5g"]
106 self.wep_2g = self.wep_networks[0]["2g"]
107 self.wep_5g = self.wep_networks[0]["5g"]
108 self.open_2g = self.open_network[0]["2g"]
109 self.open_5g = self.open_network[0]["5g"]
110
111 def setup_test(self):
Xianyuan Jia97a865e2020-11-10 02:09:40 +0000112 super().setup_test()
Bindu Mahadev36725332019-01-29 12:23:21 -0800113 for ad in self.android_devices:
114 ad.droid.wakeLockAcquireBright()
115 ad.droid.wakeUpNow()
116 wutils.wifi_toggle_state(ad, True)
117
118 def teardown_test(self):
Xianyuan Jia97a865e2020-11-10 02:09:40 +0000119 super().teardown_test()
Bindu Mahadev36725332019-01-29 12:23:21 -0800120 for ad in self.android_devices:
121 ad.droid.wakeLockRelease()
122 ad.droid.goToSleepNow()
Xianyuan Jia97a865e2020-11-10 02:09:40 +0000123 self.dut.droid.wifiRemoveNetworkSuggestions([])
Bindu Mahadev36725332019-01-29 12:23:21 -0800124 wutils.reset_wifi(self.dut)
125 wutils.reset_wifi(self.dut_client)
126
Bindu Mahadev36725332019-01-29 12:23:21 -0800127 def teardown_class(self):
128 if "AccessPoint" in self.user_params:
129 del self.user_params["reference_networks"]
130 del self.user_params["open_network"]
131 del self.user_params["wep_networks"]
132
133
134 """Helper Functions"""
135
136
137 def get_randomized_mac(self, network):
138 """Get the randomized MAC address.
139
140 Args:
141 network: dict, network information.
142
143 Returns:
144 The randomized MAC address string for the network.
145
146 """
147 return self.dut.droid.wifigetRandomizedMacAddress(network)
148
149 def connect_to_network_and_verify_mac_randomization(self, network,
150 status=RANDOMIZATION_PERSISTENT):
151 """Connect to the given network and verify MAC.
152
153 Args:
154 network: dict, the network information.
155 status: int, MAC randomization level.
156
157 Returns:
158 The randomized MAC addresss string.
159
160 """
161 wutils.connect_to_wifi_network(self.dut, network)
162 return self.verify_mac_randomization(network, status=status)
163
164 def verify_mac_randomization_and_add_to_list(self, network, mac_list):
165 """Connect to a network and populate it's MAC in a reference list,
166 that will be used to verify any repeated MAC addresses.
167
168 Args:
169 network: dict, the network information.
170 mac_list: list of MAC addresss strings.
171
172 """
173 rand_mac = self.connect_to_network_and_verify_mac_randomization(
174 network)
175 if rand_mac in mac_list:
176 raise signals.TestFailure('A new Randomized MAC was not generated '
177 ' for this network %s.' % network)
178 mac_list.append(rand_mac)
179
180 def verify_mac_randomization(self, network, status=RANDOMIZATION_PERSISTENT):
181 """Get the various types of MAC addresses for the device and verify.
182
183 Args:
184 network: dict, the network information.
185 status: int, MAC randomization level.
186
187 Returns:
188 The randomized MAC address string for the network.
189
190 """
Bindu Mahadev36725332019-01-29 12:23:21 -0800191 randomized_mac = self.get_randomized_mac(network)
xshu5ab5ef62019-04-16 17:32:38 -0700192 default_mac = self.get_sta_mac_address()
Bindu Mahadev36725332019-01-29 12:23:21 -0800193 self.log.info("Factory MAC = %s\nRandomized MAC = %s\nDefault MAC = %s" %
xshu5ab5ef62019-04-16 17:32:38 -0700194 (self.sta_factory_mac, randomized_mac, default_mac))
Bindu Mahadev36725332019-01-29 12:23:21 -0800195 message = ('Randomized MAC and Factory MAC are the same. '
xshu5ab5ef62019-04-16 17:32:38 -0700196 'Randomized MAC = %s, Factory MAC = %s' % (randomized_mac, self.sta_factory_mac))
197 asserts.assert_true(randomized_mac != self.sta_factory_mac, message)
198 if status == RANDOMIZATION_NONE:
199 asserts.assert_true(default_mac == self.sta_factory_mac, "Connection is not "
200 "using Factory MAC as the default MAC.")
201 else:
202 message = ('Connection is not using randomized MAC as the default MAC. '
203 'Randomized MAC = %s, Deafult MAC = %s' % (randomized_mac, default_mac))
204 asserts.assert_true(default_mac == randomized_mac, message)
Bindu Mahadev36725332019-01-29 12:23:21 -0800205 return randomized_mac
206
207 def check_mac_persistence(self, network, condition):
208 """Check if the MAC is persistent after carrying out specific operations
209 like forget WiFi, toggle WiFi, reboot device and AP.
210
211 Args:
212 network: dict, The network information.
213 condition: int, value to trigger certain operation on the device.
214
215 Raises:
216 TestFaikure is the MAC is not persistent.
217
218 """
219 rand_mac1 = self.connect_to_network_and_verify_mac_randomization(network)
220
221 if condition == FORGET:
222 wutils.wifi_forget_network(self.dut, network['SSID'])
223
224 elif condition == TOGGLE:
225 wutils.wifi_toggle_state(self.dut, False)
226 wutils.wifi_toggle_state(self.dut, True)
227
228 elif condition == REBOOT_DUT:
229 self.dut.reboot()
230 time.sleep(DEFAULT_TIMEOUT)
231
232 elif condition == REBOOT_AP:
233 wutils.turn_ap_off(self, 1)
234 time.sleep(DEFAULT_TIMEOUT)
235 wutils.turn_ap_on(self, 1)
236 time.sleep(DEFAULT_TIMEOUT)
237
238 rand_mac2 = self.connect_to_network_and_verify_mac_randomization(network)
239
240 if rand_mac1 != rand_mac2:
241 raise signals.TestFailure('Randomized MAC is not persistent after '
242 'forgetting networ. Old MAC = %s New MAC'
243 ' = %s' % (rand_mac1, rand_mac2))
244
xshu5ab5ef62019-04-16 17:32:38 -0700245 def verify_mac_not_found_in_pcap(self, mac, packets):
246 for pkt in packets:
247 self.log.debug("Packet Summary = %s" % pkt.summary())
248 if mac in pkt.summary():
Jaineel95887fd2019-10-16 16:19:01 -0700249 raise signals.TestFailure("Caught Factory MAC in packet sniffer"
250 "Packet = %s Device = %s"
251 % (pkt.show(), self.dut))
xshu5ab5ef62019-04-16 17:32:38 -0700252
253 def verify_mac_is_found_in_pcap(self, mac, packets):
254 for pkt in packets:
255 self.log.debug("Packet Summary = %s" % pkt.summary())
256 if mac in pkt.summary():
257 return
258 raise signals.TestFailure("Did not find MAC = %s in packet sniffer."
Jaineel95887fd2019-10-16 16:19:01 -0700259 "for device %s" % (mac, self.dut))
xshu5ab5ef62019-04-16 17:32:38 -0700260
261 def get_sta_mac_address(self):
xshu1abc5f22019-05-03 14:27:59 -0700262 """Gets the current MAC address being used for client mode."""
xshu5ab5ef62019-04-16 17:32:38 -0700263 out = self.dut.adb.shell("ifconfig wlan0")
264 res = re.match(".* HWaddr (\S+).*", out, re.S)
265 return res.group(1)
266
267 def get_soft_ap_mac_address(self):
xshu1abc5f22019-05-03 14:27:59 -0700268 """Gets the current MAC address being used for SoftAp."""
xshu5ab5ef62019-04-16 17:32:38 -0700269 if self.dut.model in self.dbs_supported_models:
270 out = self.dut.adb.shell("ifconfig wlan1")
271 return re.match(".* HWaddr (\S+).*", out, re.S).group(1)
272 else:
273 return self.get_sta_mac_address()
Xianyuan Jia97a865e2020-11-10 02:09:40 +0000274
275 def _add_suggestion_and_verify_mac_randomization(self, network_suggestion):
276 """Add wifi network suggestion and verify MAC randomization.
277
278 Args:
279 network_suggestion: network suggestion to add.
280
281 Returns:
282 Randomized MAC address.
283 """
284 self.log.info("Adding network suggestion")
285 asserts.assert_true(
286 self.dut.droid.wifiAddNetworkSuggestions([network_suggestion]),
287 "Failed to add suggestions")
288 wutils.start_wifi_connection_scan_and_ensure_network_found(
289 self.dut, network_suggestion[WifiEnums.SSID_KEY])
290 wutils.wait_for_connect(self.dut, network_suggestion[WifiEnums.SSID_KEY])
291 default_mac = self.get_sta_mac_address()
292 randomized_mac = self.dut.droid.wifiGetConnectionInfo()["mac_address"]
293 self.log.info("Factory MAC = %s\nRandomized MAC = %s\nDefault MAC = %s" %
294 (self.sta_factory_mac, randomized_mac, default_mac))
295 asserts.assert_true(
296 default_mac == randomized_mac,
297 "Connection is not using randomized MAC as the default MAC.")
298 return randomized_mac
299
300 def _remove_suggestion_and_verify_disconnect(self, network_suggestion):
301 """Remove wifi network suggestion and verify device disconnects.
302
303 Args:
304 network_suggestion: network suggestion to remove.
305 """
306 self.dut.log.info("Removing network suggestions")
307 asserts.assert_true(
308 self.dut.droid.wifiRemoveNetworkSuggestions([network_suggestion]),
309 "Failed to remove suggestions")
310 wutils.wait_for_disconnect(self.dut)
311 self.dut.ed.clear_all_events()
312 asserts.assert_false(
313 wutils.wait_for_connect(
314 self.dut,
315 network_suggestion[WifiEnums.SSID_KEY],
316 assert_on_fail=False),
317 "Device should not connect back")
318
Bindu Mahadev36725332019-01-29 12:23:21 -0800319 """Tests"""
320
321
322 @test_tracker_info(uuid="2dd0a05e-a318-45a6-81cd-962e098fa242")
323 def test_set_mac_randomization_to_none(self):
xshu5ab5ef62019-04-16 17:32:38 -0700324 self.pcap_procs = wutils.start_pcap(
Girish Moturua3ca6702019-07-24 13:23:14 -0700325 self.packet_capture, 'dual', self.test_name)
Bindu Mahadev36725332019-01-29 12:23:21 -0800326 network = self.wpapsk_2g
327 # Set macRandomizationSetting to RANDOMIZATION_NONE.
328 network["macRand"] = RANDOMIZATION_NONE
329 self.connect_to_network_and_verify_mac_randomization(network,
330 status=RANDOMIZATION_NONE)
Girish Moturua3ca6702019-07-24 13:23:14 -0700331 pcap_fname = '%s_%s.pcap' % \
332 (self.pcap_procs[hostapd_constants.BAND_2G][1],
333 hostapd_constants.BAND_2G.upper())
xshu5ab5ef62019-04-16 17:32:38 -0700334 time.sleep(SHORT_TIMEOUT)
335 wutils.stop_pcap(self.packet_capture, self.pcap_procs, False)
336 packets = rdpcap(pcap_fname)
Girish Moturu54d6dbc2019-11-04 10:00:05 -0800337 self.verify_mac_is_found_in_pcap(self.sta_factory_mac, packets)
Bindu Mahadev36725332019-01-29 12:23:21 -0800338
339 @test_tracker_info(uuid="d9e64202-02d5-421a-967c-42e45f1f7f91")
340 def test_mac_randomization_wpapsk(self):
341 """Verify MAC randomization for a WPA network.
342
343 Steps:
344 1. Connect to WPA network.
345 2. Get the Factory, Randomized and Default MACs.
346 3. Verify randomized MAC is the default MAC for the device.
347
348 """
349 self.connect_to_network_and_verify_mac_randomization(self.wpapsk_2g)
350
351 @test_tracker_info(uuid="b5be7c53-2edf-449e-ba70-a1fb7acf735e")
352 def test_mac_randomization_wep(self):
353 """Verify MAC randomization for a WEP network.
354
355 Steps:
356 1. Connect to WEP network.
357 2. Get the Factory, Randomized and Default MACs.
358 3. Verify randomized MAC is the default MAC for the device.
359
360 """
361 self.connect_to_network_and_verify_mac_randomization(self.wep_2g)
362
363 @test_tracker_info(uuid="f5347ac0-68d5-4882-a58d-1bd0d575503c")
364 def test_mac_randomization_open(self):
365 """Verify MAC randomization for a open network.
366
367 Steps:
368 1. Connect to open network.
369 2. Get the Factory, Randomized and Default MACs.
370 3. Verify randomized MAC is the default MAC for the device.
371
372 """
373 self.connect_to_network_and_verify_mac_randomization(self.open_2g)
374
375 @test_tracker_info(uuid="5d260421-2adf-4ace-b281-3d15aec39b2a")
376 def test_persistent_mac_after_forget(self):
377 """Check if MAC is persistent after forgetting/adding a network.
378
379 Steps:
380 1. Connect to WPA network and get the randomized MAC.
381 2. Forget the network.
382 3. Connect to the same network again.
383 4. Verify randomized MAC has not changed.
384
385 """
386 self.check_mac_persistence(self.wpapsk_2g, FORGET)
387
388 @test_tracker_info(uuid="09d40a93-ead2-45ca-9905-14b05fd79f34")
389 def test_persistent_mac_after_toggle(self):
390 """Check if MAC is persistent after toggling WiFi network.
391
392 Steps:
393 1. Connect to WPA network and get the randomized MAC.
394 2. Turn WiFi ON/OFF.
395 3. Connect to the same network again.
396 4. Verify randomized MAC has not changed.
397
398 """
399 self.check_mac_persistence(self.wpapsk_2g, TOGGLE)
400
Girish Moturu5ee257f2020-05-21 10:26:37 -0700401 @test_tracker_info(uuid="b3aa514f-8562-44e8-bfe0-4ecab9af165b")
Bindu Mahadev36725332019-01-29 12:23:21 -0800402 def test_persistent_mac_after_device_reboot(self):
403 """Check if MAC is persistent after a device reboot.
404
405 Steps:
406 1. Connect to WPA network and get the randomized MAC.
407 2. Reboot DUT.
408 3. Connect to the same network again.
409 4. Verify randomized MAC has not changed.
410
411 """
412 self.check_mac_persistence(self.wpapsk_2g, REBOOT_DUT)
413
Bindu Mahadevb2312682019-03-13 15:44:14 -0700414 # Disable reboot test for debugging purpose.
415 #@test_tracker_info(uuid="82d691a0-22e4-4a3d-9596-e150531fcd34")
416 def persistent_mac_after_ap_reboot(self):
Bindu Mahadev36725332019-01-29 12:23:21 -0800417 """Check if MAC is persistent after AP reboots itself.
418
419 Steps:
420 1. Connect to WPA network and get the randomized MAC.
421 2. Reboot AP(basically restart hostapd in our case).
422 3. Connect to the same network again.
423 4. Verify randomized MAC has not changed.
424
425 """
426 self.check_mac_persistence(self.wpapsk_2g, REBOOT_AP)
427
428 @test_tracker_info(uuid="e1f33dbc-808c-4e61-8a4a-3a72c1f63c7e")
429 def test_mac_randomization_multiple_networks(self):
430 """Connect to multiple networks and verify same MAC.
431
432 Steps:
433 1. Connect to network A, get randomizd MAC.
434 2. Conenct to network B, get randomized MAC.
435 3. Connect back to network A and verify same MAC.
436 4. Connect back to network B and verify same MAC.
437
438 """
439 mac_list = list()
440
441 # Connect to two different networks and get randomized MAC addresses.
442 self.verify_mac_randomization_and_add_to_list(self.wpapsk_2g, mac_list)
443 self.verify_mac_randomization_and_add_to_list(self.open_2g, mac_list)
444
445 # Connect to the previous network and check MAC is persistent.
446 mac_wpapsk = self.connect_to_network_and_verify_mac_randomization(
447 self.wpapsk_2g)
448 msg = ('Randomized MAC is not persistent for this network %s. Old MAC = '
449 '%s \nNew MAC = %s')
450 if mac_wpapsk != mac_list[0]:
451 raise signals.TestFailure(msg % (self.wpapsk_5g, mac_list[0], mac_wpapsk))
452 mac_open = self.connect_to_network_and_verify_mac_randomization(
453 self.open_2g)
454 if mac_open != mac_list[1]:
455 raise signals.TestFailure(msg %(self.open_5g, mac_list[1], mac_open))
456
457 @test_tracker_info(uuid="edb5a0e5-7f3b-4147-b1d3-48ad7ad9799e")
Girish Moturu11d74442020-11-06 13:20:20 -0800458 def test_mac_randomization_different_APs(self):
Bindu Mahadev36725332019-01-29 12:23:21 -0800459 """Verify randomization using two different APs.
460
461 Steps:
462 1. Connect to network A on AP1, get the randomized MAC.
463 2. Connect to network B on AP2, get the randomized MAC.
464 3. Veirfy the two MACs are different.
465
466 """
467 ap1 = self.wpapsk_2g
468 ap2 = self.reference_networks[1]["5g"]
469 mac_ap1 = self.connect_to_network_and_verify_mac_randomization(ap1)
470 mac_ap2 = self.connect_to_network_and_verify_mac_randomization(ap2)
xshu233592c2019-05-29 15:23:47 -0700471 if mac_ap1 == mac_ap2:
Bindu Mahadev36725332019-01-29 12:23:21 -0800472 raise signals.TestFailure("Same MAC address was generated for both "
473 "APs: %s" % mac_ap1)
474
475 @test_tracker_info(uuid="b815e9ce-bccd-4fc3-9774-1e1bc123a2a8")
476 def test_mac_randomization_ap_sta(self):
477 """Bring up STA and softAP and verify MAC randomization.
478
479 Steps:
480 1. Connect to a network and get randomized MAC.
481 2. Bring up softAP on the DUT.
482 3. Connect to softAP network on the client and get MAC.
483 4. Verify AP and STA use different randomized MACs.
xshu5ab5ef62019-04-16 17:32:38 -0700484 5. Find the channel of the SoftAp network.
485 6. Configure sniffer on that channel.
486 7. Verify the factory MAC is not leaked.
Bindu Mahadev36725332019-01-29 12:23:21 -0800487
488 """
Roshan Pius48df08c2019-09-13 08:07:30 -0700489 wutils.set_wifi_country_code(self.dut, wutils.WifiEnums.CountryCode.US)
490 wutils.set_wifi_country_code(self.dut_client, wutils.WifiEnums.CountryCode.US)
Bindu Mahadev36725332019-01-29 12:23:21 -0800491 mac_sta = self.connect_to_network_and_verify_mac_randomization(
492 self.wpapsk_2g)
493 softap = wutils.start_softap_and_verify(self, WIFI_CONFIG_APBAND_2G)
494 wutils.connect_to_wifi_network(self.dut_client, softap)
495 softap_info = self.dut_client.droid.wifiGetConnectionInfo()
496 mac_ap = softap_info['mac_address']
497 if mac_sta == mac_ap:
498 raise signals.TestFailure("Same MAC address was used for both "
499 "AP and STA: %s" % mac_sta)
500
xshu5ab5ef62019-04-16 17:32:38 -0700501 # Verify SoftAp MAC is randomized
502 softap_mac = self.get_soft_ap_mac_address()
503 message = ('Randomized SoftAp MAC and Factory SoftAp MAC are the same. '
504 'Randomized SoftAp MAC = %s, Factory SoftAp MAC = %s'
505 % (softap_mac, self.soft_ap_factory_mac))
506 asserts.assert_true(softap_mac != self.soft_ap_factory_mac, message)
507
508 softap_channel = hostapd_constants.CHANNEL_MAP[softap_info['frequency']]
509 self.log.info("softap_channel = %s\n" % (softap_channel))
510 result = self.packet_capture.configure_monitor_mode(
511 hostapd_constants.BAND_2G, softap_channel)
512 if not result:
513 raise ValueError("Failed to configure channel for 2G band")
514 self.pcap_procs = wutils.start_pcap(
Girish Moturua3ca6702019-07-24 13:23:14 -0700515 self.packet_capture, 'dual', self.test_name)
xshu5ab5ef62019-04-16 17:32:38 -0700516 # re-connect to the softAp network after sniffer is started
517 wutils.connect_to_wifi_network(self.dut_client, self.wpapsk_2g)
518 wutils.connect_to_wifi_network(self.dut_client, softap)
519 time.sleep(SHORT_TIMEOUT)
520 wutils.stop_pcap(self.packet_capture, self.pcap_procs, False)
Girish Moturua3ca6702019-07-24 13:23:14 -0700521 pcap_fname = '%s_%s.pcap' % \
522 (self.pcap_procs[hostapd_constants.BAND_2G][1],
523 hostapd_constants.BAND_2G.upper())
xshu5ab5ef62019-04-16 17:32:38 -0700524 packets = rdpcap(pcap_fname)
525 self.verify_mac_not_found_in_pcap(self.soft_ap_factory_mac, packets)
526 self.verify_mac_not_found_in_pcap(self.sta_factory_mac, packets)
527 self.verify_mac_is_found_in_pcap(softap_mac, packets)
528 self.verify_mac_is_found_in_pcap(self.get_sta_mac_address(), packets)
529
Bindu Mahadev36725332019-01-29 12:23:21 -0800530 @test_tracker_info(uuid="3ca3f911-29f1-41fb-b836-4d25eac1669f")
531 def test_roaming_mac_randomization(self):
532 """test MAC randomization in the roaming scenario.
533
534 Steps:
535 1. Connect to network A on AP1, get randomized MAC.
536 2. Set AP1 to MAX attenuation so that we roam to AP2.
537 3. Wait for device to roam to AP2 and get randomized MAC.
538 4. Veirfy that the device uses same AMC for both APs.
539
540 """
541 AP1_network = self.reference_networks[0]["5g"]
542 AP2_network = self.reference_networks[1]["5g"]
Girish Moturu11d74442020-11-06 13:20:20 -0800543 if "OpenWrtAP" in self.user_params:
544 AP1_network["bssid"] = self.bssid_map[0]["5g"][AP1_network["SSID"]]
545 AP2_network["bssid"] = self.bssid_map[1]["5g"][AP2_network["SSID"]]
Girish Moturu36348a32019-12-10 08:41:54 -0800546 wutils.set_attns(self.attenuators, "AP1_on_AP2_off", self.roaming_attn)
Bindu Mahadev36725332019-01-29 12:23:21 -0800547 mac_before_roam = self.connect_to_network_and_verify_mac_randomization(
548 AP1_network)
549 wutils.trigger_roaming_and_validate(self.dut, self.attenuators,
Girish Moturu36348a32019-12-10 08:41:54 -0800550 "AP1_off_AP2_on", AP2_network, self.roaming_attn)
Bindu Mahadev36725332019-01-29 12:23:21 -0800551 mac_after_roam = self.get_randomized_mac(AP2_network)
552 if mac_after_roam != mac_before_roam:
553 raise signals.TestFailure("Randomized MAC address changed after "
554 "roaming from AP1 to AP2.\nMAC before roam = %s\nMAC after "
555 "roam = %s" %(mac_before_roam, mac_after_roam))
556 wutils.trigger_roaming_and_validate(self.dut, self.attenuators,
Girish Moturu36348a32019-12-10 08:41:54 -0800557 "AP1_on_AP2_off", AP1_network, self.roaming_attn)
Bindu Mahadev36725332019-01-29 12:23:21 -0800558 mac_after_roam = self.get_randomized_mac(AP1_network)
559 if mac_after_roam != mac_before_roam:
560 raise signals.TestFailure("Randomized MAC address changed after "
561 "roaming from AP1 to AP2.\nMAC before roam = %s\nMAC after "
562 "roam = %s" %(mac_before_roam, mac_after_roam))
Bindu Mahadev2941f482019-03-18 16:46:08 -0700563
564 @test_tracker_info(uuid="17b12f1a-7c62-4188-b5a5-52d7a0bb7849")
xshu1abc5f22019-05-03 14:27:59 -0700565 def test_check_mac_sta_with_link_probe(self):
Bindu Mahadev2941f482019-03-18 16:46:08 -0700566 """Test to ensure Factory MAC is not exposed, using sniffer data.
567
568 Steps:
569 1. Configure and start the sniffer on 5GHz band.
xshu1abc5f22019-05-03 14:27:59 -0700570 2. Connect to 5GHz network.
571 3. Send link probes.
572 4. Stop the sniffer.
573 5. Invoke scapy to read the .pcap file.
574 6. Read each packet summary and make sure Factory MAC is not used.
Bindu Mahadev2941f482019-03-18 16:46:08 -0700575
576 """
xshu5ab5ef62019-04-16 17:32:38 -0700577 self.pcap_procs = wutils.start_pcap(
Girish Moturua3ca6702019-07-24 13:23:14 -0700578 self.packet_capture, 'dual', self.test_name)
Bindu Mahadev2941f482019-03-18 16:46:08 -0700579 time.sleep(SHORT_TIMEOUT)
580 network = self.wpapsk_5g
581 rand_mac = self.connect_to_network_and_verify_mac_randomization(network)
xshu1abc5f22019-05-03 14:27:59 -0700582 wutils.send_link_probes(self.dut, 3, 3)
Girish Moturua3ca6702019-07-24 13:23:14 -0700583 pcap_fname = '%s_%s.pcap' % \
584 (self.pcap_procs[hostapd_constants.BAND_5G][1],
585 hostapd_constants.BAND_5G.upper())
Bindu Mahadevc0232702019-04-04 15:23:28 -0700586 wutils.stop_pcap(self.packet_capture, self.pcap_procs, False)
Bindu Mahadev2941f482019-03-18 16:46:08 -0700587 time.sleep(SHORT_TIMEOUT)
588 packets = rdpcap(pcap_fname)
xshu5ab5ef62019-04-16 17:32:38 -0700589 self.verify_mac_not_found_in_pcap(self.sta_factory_mac, packets)
590 self.verify_mac_is_found_in_pcap(self.get_sta_mac_address(), packets)
591
592 @test_tracker_info(uuid="1c2cc0fd-a340-40c4-b679-6acc5f526451")
593 def test_check_mac_in_wifi_scan(self):
594 """Test to ensure Factory MAC is not exposed, in Wi-Fi scans
595
596 Steps:
597 1. Configure and start the sniffer on both bands.
598 2. Perform a full scan.
599 3. Stop the sniffer.
600 4. Invoke scapy to read the .pcap file.
601 5. Read each packet summary and make sure Factory MAC is not used.
602
603 """
604 self.pcap_procs = wutils.start_pcap(
Girish Moturua3ca6702019-07-24 13:23:14 -0700605 self.packet_capture, 'dual', self.test_name)
xshu5ab5ef62019-04-16 17:32:38 -0700606 wutils.start_wifi_connection_scan(self.dut)
607 time.sleep(SHORT_TIMEOUT)
608 wutils.stop_pcap(self.packet_capture, self.pcap_procs, False)
Girish Moturua3ca6702019-07-24 13:23:14 -0700609 pcap_fname = '%s_%s.pcap' % \
610 (self.pcap_procs[hostapd_constants.BAND_2G][1],
611 hostapd_constants.BAND_2G.upper())
xshu5ab5ef62019-04-16 17:32:38 -0700612 packets = rdpcap(pcap_fname)
613 self.verify_mac_not_found_in_pcap(self.sta_factory_mac, packets)
Xianyuan Jia97a865e2020-11-10 02:09:40 +0000614
615 @test_tracker_info(uuid="7714d31f-bb08-4f29-b246-0ce1398a3c03")
616 def test_mac_randomization_for_network_suggestion(self):
617 """Add network suggestion and verify MAC randomization.
618
619 Steps:
620 1. Add a network suggestion and verify device connects to it.
621 2. Verify the device uses randomized MAC address for this network.
622 """
623 network_suggestion = self.reference_networks[0]["5g"]
624 self._add_suggestion_and_verify_mac_randomization(network_suggestion)
625
626 @test_tracker_info(uuid="144ad0b4-b79d-4b1d-a8a9-3c612a76c32c")
627 def test_enhanced_mac_randomization_for_network_suggestion(self):
628 """Test enhanced MAC randomization.
629
630 Steps:
631 1. Add a network suggestion with enhanced mac randomization enabled.
632 2. Connect to the network and verify the MAC address is random.
633 3. Remove the suggestion network and add it back.
634 4. Connect to the network. Verify the MAC address is random and
635 different from the randomized MAC observed in step 2.
636 """
637 network_suggestion = self.reference_networks[0]["5g"]
638 network_suggestion["enhancedMacRandomizationEnabled"] = True
639
640 # add network suggestion with enhanced mac randomization
641 randomized_mac1 = self._add_suggestion_and_verify_mac_randomization(
642 network_suggestion)
643
644 # remove network suggestion and verify no connection
645 self._remove_suggestion_and_verify_disconnect(network_suggestion)
646
647 # add network suggestion and verify device connects back
648 randomized_mac2 = self._add_suggestion_and_verify_mac_randomization(
649 network_suggestion)
650
651 # verify both randomized mac addrs are different
652 asserts.assert_true(randomized_mac1 != randomized_mac2,
653 "Randomized MAC addresses are same.")
654