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