blob: d41b05fcbe942ad38d483d4be21c5bdb2483eef1 [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
25import acts.test_utils.wifi.wifi_test_utils as wutils
26import acts.utils
27
28from acts import asserts
29from acts.test_decorators import test_tracker_info
30from acts.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_2G
31from acts.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_5G
32from acts.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)
xshu5ab5ef62019-04-16 17:32:38 -070069 req_params = ["dbs_supported_models"]
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:
82 if "AccessPoint" in self.user_params:
83 self.legacy_configure_ap_and_start(wep_network=True, ap_count=2)
84
85 asserts.assert_true(
86 len(self.reference_networks) > 0,
87 "Need at least one reference network with psk.")
88
xshu5ab5ef62019-04-16 17:32:38 -070089 # Reboot device to reset factory MAC of wlan1
90 self.dut.reboot()
91 self.dut_client.reboot()
92 time.sleep(DEFAULT_TIMEOUT)
Bindu Mahadev36725332019-01-29 12:23:21 -080093 wutils.wifi_toggle_state(self.dut, True)
94 wutils.wifi_toggle_state(self.dut_client, True)
xshu5ab5ef62019-04-16 17:32:38 -070095 self.soft_ap_factory_mac = self.get_soft_ap_mac_address()
96 self.sta_factory_mac = self.dut.droid.wifigetFactorymacAddresses()[0]
97
Bindu Mahadev36725332019-01-29 12:23:21 -080098 self.wpapsk_2g = self.reference_networks[0]["2g"]
99 self.wpapsk_5g = self.reference_networks[0]["5g"]
100 self.wep_2g = self.wep_networks[0]["2g"]
101 self.wep_5g = self.wep_networks[0]["5g"]
102 self.open_2g = self.open_network[0]["2g"]
103 self.open_5g = self.open_network[0]["5g"]
104
105 def setup_test(self):
106 for ad in self.android_devices:
107 ad.droid.wakeLockAcquireBright()
108 ad.droid.wakeUpNow()
109 wutils.wifi_toggle_state(ad, True)
110
111 def teardown_test(self):
112 for ad in self.android_devices:
113 ad.droid.wakeLockRelease()
114 ad.droid.goToSleepNow()
115 wutils.reset_wifi(self.dut)
116 wutils.reset_wifi(self.dut_client)
117
118 def on_fail(self, test_name, begin_time):
Bindu Mahadeva6a199a2019-03-07 14:11:48 -0800119 self.dut.cat_adb_log(test_name, begin_time)
120 self.dut.take_bug_report(test_name, begin_time)
Bindu Mahadev36725332019-01-29 12:23:21 -0800121
122 def teardown_class(self):
123 if "AccessPoint" in self.user_params:
124 del self.user_params["reference_networks"]
125 del self.user_params["open_network"]
126 del self.user_params["wep_networks"]
127
128
129 """Helper Functions"""
130
131
132 def get_randomized_mac(self, network):
133 """Get the randomized MAC address.
134
135 Args:
136 network: dict, network information.
137
138 Returns:
139 The randomized MAC address string for the network.
140
141 """
142 return self.dut.droid.wifigetRandomizedMacAddress(network)
143
144 def connect_to_network_and_verify_mac_randomization(self, network,
145 status=RANDOMIZATION_PERSISTENT):
146 """Connect to the given network and verify MAC.
147
148 Args:
149 network: dict, the network information.
150 status: int, MAC randomization level.
151
152 Returns:
153 The randomized MAC addresss string.
154
155 """
156 wutils.connect_to_wifi_network(self.dut, network)
157 return self.verify_mac_randomization(network, status=status)
158
159 def verify_mac_randomization_and_add_to_list(self, network, mac_list):
160 """Connect to a network and populate it's MAC in a reference list,
161 that will be used to verify any repeated MAC addresses.
162
163 Args:
164 network: dict, the network information.
165 mac_list: list of MAC addresss strings.
166
167 """
168 rand_mac = self.connect_to_network_and_verify_mac_randomization(
169 network)
170 if rand_mac in mac_list:
171 raise signals.TestFailure('A new Randomized MAC was not generated '
172 ' for this network %s.' % network)
173 mac_list.append(rand_mac)
174
175 def verify_mac_randomization(self, network, status=RANDOMIZATION_PERSISTENT):
176 """Get the various types of MAC addresses for the device and verify.
177
178 Args:
179 network: dict, the network information.
180 status: int, MAC randomization level.
181
182 Returns:
183 The randomized MAC address string for the network.
184
185 """
Bindu Mahadev36725332019-01-29 12:23:21 -0800186 randomized_mac = self.get_randomized_mac(network)
xshu5ab5ef62019-04-16 17:32:38 -0700187 default_mac = self.get_sta_mac_address()
Bindu Mahadev36725332019-01-29 12:23:21 -0800188 self.log.info("Factory MAC = %s\nRandomized MAC = %s\nDefault MAC = %s" %
xshu5ab5ef62019-04-16 17:32:38 -0700189 (self.sta_factory_mac, randomized_mac, default_mac))
Bindu Mahadev36725332019-01-29 12:23:21 -0800190 message = ('Randomized MAC and Factory MAC are the same. '
xshu5ab5ef62019-04-16 17:32:38 -0700191 'Randomized MAC = %s, Factory MAC = %s' % (randomized_mac, self.sta_factory_mac))
192 asserts.assert_true(randomized_mac != self.sta_factory_mac, message)
193 if status == RANDOMIZATION_NONE:
194 asserts.assert_true(default_mac == self.sta_factory_mac, "Connection is not "
195 "using Factory MAC as the default MAC.")
196 else:
197 message = ('Connection is not using randomized MAC as the default MAC. '
198 'Randomized MAC = %s, Deafult MAC = %s' % (randomized_mac, default_mac))
199 asserts.assert_true(default_mac == randomized_mac, message)
Bindu Mahadev36725332019-01-29 12:23:21 -0800200 return randomized_mac
201
202 def check_mac_persistence(self, network, condition):
203 """Check if the MAC is persistent after carrying out specific operations
204 like forget WiFi, toggle WiFi, reboot device and AP.
205
206 Args:
207 network: dict, The network information.
208 condition: int, value to trigger certain operation on the device.
209
210 Raises:
211 TestFaikure is the MAC is not persistent.
212
213 """
214 rand_mac1 = self.connect_to_network_and_verify_mac_randomization(network)
215
216 if condition == FORGET:
217 wutils.wifi_forget_network(self.dut, network['SSID'])
218
219 elif condition == TOGGLE:
220 wutils.wifi_toggle_state(self.dut, False)
221 wutils.wifi_toggle_state(self.dut, True)
222
223 elif condition == REBOOT_DUT:
224 self.dut.reboot()
225 time.sleep(DEFAULT_TIMEOUT)
226
227 elif condition == REBOOT_AP:
228 wutils.turn_ap_off(self, 1)
229 time.sleep(DEFAULT_TIMEOUT)
230 wutils.turn_ap_on(self, 1)
231 time.sleep(DEFAULT_TIMEOUT)
232
233 rand_mac2 = self.connect_to_network_and_verify_mac_randomization(network)
234
235 if rand_mac1 != rand_mac2:
236 raise signals.TestFailure('Randomized MAC is not persistent after '
237 'forgetting networ. Old MAC = %s New MAC'
238 ' = %s' % (rand_mac1, rand_mac2))
239
xshu5ab5ef62019-04-16 17:32:38 -0700240 def verify_mac_not_found_in_pcap(self, mac, packets):
241 for pkt in packets:
242 self.log.debug("Packet Summary = %s" % pkt.summary())
243 if mac in pkt.summary():
Jaineel95887fd2019-10-16 16:19:01 -0700244 raise signals.TestFailure("Caught Factory MAC in packet sniffer"
245 "Packet = %s Device = %s"
246 % (pkt.show(), self.dut))
xshu5ab5ef62019-04-16 17:32:38 -0700247
248 def verify_mac_is_found_in_pcap(self, mac, packets):
249 for pkt in packets:
250 self.log.debug("Packet Summary = %s" % pkt.summary())
251 if mac in pkt.summary():
252 return
253 raise signals.TestFailure("Did not find MAC = %s in packet sniffer."
Jaineel95887fd2019-10-16 16:19:01 -0700254 "for device %s" % (mac, self.dut))
xshu5ab5ef62019-04-16 17:32:38 -0700255
256 def get_sta_mac_address(self):
xshu1abc5f22019-05-03 14:27:59 -0700257 """Gets the current MAC address being used for client mode."""
xshu5ab5ef62019-04-16 17:32:38 -0700258 out = self.dut.adb.shell("ifconfig wlan0")
259 res = re.match(".* HWaddr (\S+).*", out, re.S)
260 return res.group(1)
261
262 def get_soft_ap_mac_address(self):
xshu1abc5f22019-05-03 14:27:59 -0700263 """Gets the current MAC address being used for SoftAp."""
xshu5ab5ef62019-04-16 17:32:38 -0700264 if self.dut.model in self.dbs_supported_models:
265 out = self.dut.adb.shell("ifconfig wlan1")
266 return re.match(".* HWaddr (\S+).*", out, re.S).group(1)
267 else:
268 return self.get_sta_mac_address()
Bindu Mahadev36725332019-01-29 12:23:21 -0800269 """Tests"""
270
271
272 @test_tracker_info(uuid="2dd0a05e-a318-45a6-81cd-962e098fa242")
273 def test_set_mac_randomization_to_none(self):
xshu5ab5ef62019-04-16 17:32:38 -0700274 self.pcap_procs = wutils.start_pcap(
Girish Moturua3ca6702019-07-24 13:23:14 -0700275 self.packet_capture, 'dual', self.test_name)
Bindu Mahadev36725332019-01-29 12:23:21 -0800276 network = self.wpapsk_2g
277 # Set macRandomizationSetting to RANDOMIZATION_NONE.
278 network["macRand"] = RANDOMIZATION_NONE
279 self.connect_to_network_and_verify_mac_randomization(network,
280 status=RANDOMIZATION_NONE)
Girish Moturua3ca6702019-07-24 13:23:14 -0700281 pcap_fname = '%s_%s.pcap' % \
282 (self.pcap_procs[hostapd_constants.BAND_2G][1],
283 hostapd_constants.BAND_2G.upper())
xshu5ab5ef62019-04-16 17:32:38 -0700284 time.sleep(SHORT_TIMEOUT)
285 wutils.stop_pcap(self.packet_capture, self.pcap_procs, False)
286 packets = rdpcap(pcap_fname)
Girish Moturu54d6dbc2019-11-04 10:00:05 -0800287 self.verify_mac_is_found_in_pcap(self.sta_factory_mac, packets)
Bindu Mahadev36725332019-01-29 12:23:21 -0800288
289 @test_tracker_info(uuid="d9e64202-02d5-421a-967c-42e45f1f7f91")
290 def test_mac_randomization_wpapsk(self):
291 """Verify MAC randomization for a WPA network.
292
293 Steps:
294 1. Connect to WPA network.
295 2. Get the Factory, Randomized and Default MACs.
296 3. Verify randomized MAC is the default MAC for the device.
297
298 """
299 self.connect_to_network_and_verify_mac_randomization(self.wpapsk_2g)
300
301 @test_tracker_info(uuid="b5be7c53-2edf-449e-ba70-a1fb7acf735e")
302 def test_mac_randomization_wep(self):
303 """Verify MAC randomization for a WEP network.
304
305 Steps:
306 1. Connect to WEP network.
307 2. Get the Factory, Randomized and Default MACs.
308 3. Verify randomized MAC is the default MAC for the device.
309
310 """
311 self.connect_to_network_and_verify_mac_randomization(self.wep_2g)
312
313 @test_tracker_info(uuid="f5347ac0-68d5-4882-a58d-1bd0d575503c")
314 def test_mac_randomization_open(self):
315 """Verify MAC randomization for a open network.
316
317 Steps:
318 1. Connect to open network.
319 2. Get the Factory, Randomized and Default MACs.
320 3. Verify randomized MAC is the default MAC for the device.
321
322 """
323 self.connect_to_network_and_verify_mac_randomization(self.open_2g)
324
325 @test_tracker_info(uuid="5d260421-2adf-4ace-b281-3d15aec39b2a")
326 def test_persistent_mac_after_forget(self):
327 """Check if MAC is persistent after forgetting/adding a network.
328
329 Steps:
330 1. Connect to WPA network and get the randomized MAC.
331 2. Forget the network.
332 3. Connect to the same network again.
333 4. Verify randomized MAC has not changed.
334
335 """
336 self.check_mac_persistence(self.wpapsk_2g, FORGET)
337
338 @test_tracker_info(uuid="09d40a93-ead2-45ca-9905-14b05fd79f34")
339 def test_persistent_mac_after_toggle(self):
340 """Check if MAC is persistent after toggling WiFi network.
341
342 Steps:
343 1. Connect to WPA network and get the randomized MAC.
344 2. Turn WiFi ON/OFF.
345 3. Connect to the same network again.
346 4. Verify randomized MAC has not changed.
347
348 """
349 self.check_mac_persistence(self.wpapsk_2g, TOGGLE)
350
351 @test_tracker_info(uuid="a514f-8562-44e8-bfe0-4ecab9af165b")
352 def test_persistent_mac_after_device_reboot(self):
353 """Check if MAC is persistent after a device reboot.
354
355 Steps:
356 1. Connect to WPA network and get the randomized MAC.
357 2. Reboot DUT.
358 3. Connect to the same network again.
359 4. Verify randomized MAC has not changed.
360
361 """
362 self.check_mac_persistence(self.wpapsk_2g, REBOOT_DUT)
363
Bindu Mahadevb2312682019-03-13 15:44:14 -0700364 # Disable reboot test for debugging purpose.
365 #@test_tracker_info(uuid="82d691a0-22e4-4a3d-9596-e150531fcd34")
366 def persistent_mac_after_ap_reboot(self):
Bindu Mahadev36725332019-01-29 12:23:21 -0800367 """Check if MAC is persistent after AP reboots itself.
368
369 Steps:
370 1. Connect to WPA network and get the randomized MAC.
371 2. Reboot AP(basically restart hostapd in our case).
372 3. Connect to the same network again.
373 4. Verify randomized MAC has not changed.
374
375 """
376 self.check_mac_persistence(self.wpapsk_2g, REBOOT_AP)
377
378 @test_tracker_info(uuid="e1f33dbc-808c-4e61-8a4a-3a72c1f63c7e")
379 def test_mac_randomization_multiple_networks(self):
380 """Connect to multiple networks and verify same MAC.
381
382 Steps:
383 1. Connect to network A, get randomizd MAC.
384 2. Conenct to network B, get randomized MAC.
385 3. Connect back to network A and verify same MAC.
386 4. Connect back to network B and verify same MAC.
387
388 """
389 mac_list = list()
390
391 # Connect to two different networks and get randomized MAC addresses.
392 self.verify_mac_randomization_and_add_to_list(self.wpapsk_2g, mac_list)
393 self.verify_mac_randomization_and_add_to_list(self.open_2g, mac_list)
394
395 # Connect to the previous network and check MAC is persistent.
396 mac_wpapsk = self.connect_to_network_and_verify_mac_randomization(
397 self.wpapsk_2g)
398 msg = ('Randomized MAC is not persistent for this network %s. Old MAC = '
399 '%s \nNew MAC = %s')
400 if mac_wpapsk != mac_list[0]:
401 raise signals.TestFailure(msg % (self.wpapsk_5g, mac_list[0], mac_wpapsk))
402 mac_open = self.connect_to_network_and_verify_mac_randomization(
403 self.open_2g)
404 if mac_open != mac_list[1]:
405 raise signals.TestFailure(msg %(self.open_5g, mac_list[1], mac_open))
406
407 @test_tracker_info(uuid="edb5a0e5-7f3b-4147-b1d3-48ad7ad9799e")
408 def test_mac_randomization_differnet_APs(self):
409 """Verify randomization using two different APs.
410
411 Steps:
412 1. Connect to network A on AP1, get the randomized MAC.
413 2. Connect to network B on AP2, get the randomized MAC.
414 3. Veirfy the two MACs are different.
415
416 """
417 ap1 = self.wpapsk_2g
418 ap2 = self.reference_networks[1]["5g"]
419 mac_ap1 = self.connect_to_network_and_verify_mac_randomization(ap1)
420 mac_ap2 = self.connect_to_network_and_verify_mac_randomization(ap2)
xshu233592c2019-05-29 15:23:47 -0700421 if mac_ap1 == mac_ap2:
Bindu Mahadev36725332019-01-29 12:23:21 -0800422 raise signals.TestFailure("Same MAC address was generated for both "
423 "APs: %s" % mac_ap1)
424
425 @test_tracker_info(uuid="b815e9ce-bccd-4fc3-9774-1e1bc123a2a8")
426 def test_mac_randomization_ap_sta(self):
427 """Bring up STA and softAP and verify MAC randomization.
428
429 Steps:
430 1. Connect to a network and get randomized MAC.
431 2. Bring up softAP on the DUT.
432 3. Connect to softAP network on the client and get MAC.
433 4. Verify AP and STA use different randomized MACs.
xshu5ab5ef62019-04-16 17:32:38 -0700434 5. Find the channel of the SoftAp network.
435 6. Configure sniffer on that channel.
436 7. Verify the factory MAC is not leaked.
Bindu Mahadev36725332019-01-29 12:23:21 -0800437
438 """
Roshan Pius48df08c2019-09-13 08:07:30 -0700439 wutils.set_wifi_country_code(self.dut, wutils.WifiEnums.CountryCode.US)
440 wutils.set_wifi_country_code(self.dut_client, wutils.WifiEnums.CountryCode.US)
Bindu Mahadev36725332019-01-29 12:23:21 -0800441 mac_sta = self.connect_to_network_and_verify_mac_randomization(
442 self.wpapsk_2g)
443 softap = wutils.start_softap_and_verify(self, WIFI_CONFIG_APBAND_2G)
444 wutils.connect_to_wifi_network(self.dut_client, softap)
445 softap_info = self.dut_client.droid.wifiGetConnectionInfo()
446 mac_ap = softap_info['mac_address']
447 if mac_sta == mac_ap:
448 raise signals.TestFailure("Same MAC address was used for both "
449 "AP and STA: %s" % mac_sta)
450
xshu5ab5ef62019-04-16 17:32:38 -0700451 # Verify SoftAp MAC is randomized
452 softap_mac = self.get_soft_ap_mac_address()
453 message = ('Randomized SoftAp MAC and Factory SoftAp MAC are the same. '
454 'Randomized SoftAp MAC = %s, Factory SoftAp MAC = %s'
455 % (softap_mac, self.soft_ap_factory_mac))
456 asserts.assert_true(softap_mac != self.soft_ap_factory_mac, message)
457
458 softap_channel = hostapd_constants.CHANNEL_MAP[softap_info['frequency']]
459 self.log.info("softap_channel = %s\n" % (softap_channel))
460 result = self.packet_capture.configure_monitor_mode(
461 hostapd_constants.BAND_2G, softap_channel)
462 if not result:
463 raise ValueError("Failed to configure channel for 2G band")
464 self.pcap_procs = wutils.start_pcap(
Girish Moturua3ca6702019-07-24 13:23:14 -0700465 self.packet_capture, 'dual', self.test_name)
xshu5ab5ef62019-04-16 17:32:38 -0700466 # re-connect to the softAp network after sniffer is started
467 wutils.connect_to_wifi_network(self.dut_client, self.wpapsk_2g)
468 wutils.connect_to_wifi_network(self.dut_client, softap)
469 time.sleep(SHORT_TIMEOUT)
470 wutils.stop_pcap(self.packet_capture, self.pcap_procs, False)
Girish Moturua3ca6702019-07-24 13:23:14 -0700471 pcap_fname = '%s_%s.pcap' % \
472 (self.pcap_procs[hostapd_constants.BAND_2G][1],
473 hostapd_constants.BAND_2G.upper())
xshu5ab5ef62019-04-16 17:32:38 -0700474 packets = rdpcap(pcap_fname)
475 self.verify_mac_not_found_in_pcap(self.soft_ap_factory_mac, packets)
476 self.verify_mac_not_found_in_pcap(self.sta_factory_mac, packets)
477 self.verify_mac_is_found_in_pcap(softap_mac, packets)
478 self.verify_mac_is_found_in_pcap(self.get_sta_mac_address(), packets)
479
Bindu Mahadev36725332019-01-29 12:23:21 -0800480 @test_tracker_info(uuid="3ca3f911-29f1-41fb-b836-4d25eac1669f")
481 def test_roaming_mac_randomization(self):
482 """test MAC randomization in the roaming scenario.
483
484 Steps:
485 1. Connect to network A on AP1, get randomized MAC.
486 2. Set AP1 to MAX attenuation so that we roam to AP2.
487 3. Wait for device to roam to AP2 and get randomized MAC.
488 4. Veirfy that the device uses same AMC for both APs.
489
490 """
491 AP1_network = self.reference_networks[0]["5g"]
492 AP2_network = self.reference_networks[1]["5g"]
493 wutils.set_attns(self.attenuators, "AP1_on_AP2_off")
494 mac_before_roam = self.connect_to_network_and_verify_mac_randomization(
495 AP1_network)
496 wutils.trigger_roaming_and_validate(self.dut, self.attenuators,
497 "AP1_off_AP2_on", AP2_network)
498 mac_after_roam = self.get_randomized_mac(AP2_network)
499 if mac_after_roam != mac_before_roam:
500 raise signals.TestFailure("Randomized MAC address changed after "
501 "roaming from AP1 to AP2.\nMAC before roam = %s\nMAC after "
502 "roam = %s" %(mac_before_roam, mac_after_roam))
503 wutils.trigger_roaming_and_validate(self.dut, self.attenuators,
504 "AP1_on_AP2_off", AP1_network)
505 mac_after_roam = self.get_randomized_mac(AP1_network)
506 if mac_after_roam != mac_before_roam:
507 raise signals.TestFailure("Randomized MAC address changed after "
508 "roaming from AP1 to AP2.\nMAC before roam = %s\nMAC after "
509 "roam = %s" %(mac_before_roam, mac_after_roam))
Bindu Mahadev2941f482019-03-18 16:46:08 -0700510
511 @test_tracker_info(uuid="17b12f1a-7c62-4188-b5a5-52d7a0bb7849")
xshu1abc5f22019-05-03 14:27:59 -0700512 def test_check_mac_sta_with_link_probe(self):
Bindu Mahadev2941f482019-03-18 16:46:08 -0700513 """Test to ensure Factory MAC is not exposed, using sniffer data.
514
515 Steps:
516 1. Configure and start the sniffer on 5GHz band.
xshu1abc5f22019-05-03 14:27:59 -0700517 2. Connect to 5GHz network.
518 3. Send link probes.
519 4. Stop the sniffer.
520 5. Invoke scapy to read the .pcap file.
521 6. Read each packet summary and make sure Factory MAC is not used.
Bindu Mahadev2941f482019-03-18 16:46:08 -0700522
523 """
xshu5ab5ef62019-04-16 17:32:38 -0700524 self.pcap_procs = wutils.start_pcap(
Girish Moturua3ca6702019-07-24 13:23:14 -0700525 self.packet_capture, 'dual', self.test_name)
Bindu Mahadev2941f482019-03-18 16:46:08 -0700526 time.sleep(SHORT_TIMEOUT)
527 network = self.wpapsk_5g
528 rand_mac = self.connect_to_network_and_verify_mac_randomization(network)
xshu1abc5f22019-05-03 14:27:59 -0700529 wutils.send_link_probes(self.dut, 3, 3)
Girish Moturua3ca6702019-07-24 13:23:14 -0700530 pcap_fname = '%s_%s.pcap' % \
531 (self.pcap_procs[hostapd_constants.BAND_5G][1],
532 hostapd_constants.BAND_5G.upper())
Bindu Mahadevc0232702019-04-04 15:23:28 -0700533 wutils.stop_pcap(self.packet_capture, self.pcap_procs, False)
Bindu Mahadev2941f482019-03-18 16:46:08 -0700534 time.sleep(SHORT_TIMEOUT)
535 packets = rdpcap(pcap_fname)
xshu5ab5ef62019-04-16 17:32:38 -0700536 self.verify_mac_not_found_in_pcap(self.sta_factory_mac, packets)
537 self.verify_mac_is_found_in_pcap(self.get_sta_mac_address(), packets)
538
539 @test_tracker_info(uuid="1c2cc0fd-a340-40c4-b679-6acc5f526451")
540 def test_check_mac_in_wifi_scan(self):
541 """Test to ensure Factory MAC is not exposed, in Wi-Fi scans
542
543 Steps:
544 1. Configure and start the sniffer on both bands.
545 2. Perform a full scan.
546 3. Stop the sniffer.
547 4. Invoke scapy to read the .pcap file.
548 5. Read each packet summary and make sure Factory MAC is not used.
549
550 """
551 self.pcap_procs = wutils.start_pcap(
Girish Moturua3ca6702019-07-24 13:23:14 -0700552 self.packet_capture, 'dual', self.test_name)
xshu5ab5ef62019-04-16 17:32:38 -0700553 wutils.start_wifi_connection_scan(self.dut)
554 time.sleep(SHORT_TIMEOUT)
555 wutils.stop_pcap(self.packet_capture, self.pcap_procs, False)
Girish Moturua3ca6702019-07-24 13:23:14 -0700556 pcap_fname = '%s_%s.pcap' % \
557 (self.pcap_procs[hostapd_constants.BAND_2G][1],
558 hostapd_constants.BAND_2G.upper())
xshu5ab5ef62019-04-16 17:32:38 -0700559 packets = rdpcap(pcap_fname)
560 self.verify_mac_not_found_in_pcap(self.sta_factory_mac, packets)