blob: 47554bf6da6780bc8a7693d7bb5f82d0649f4a92 [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)
Jaineel95887fd2019-10-16 16:19:01 -0700287 self.verify_mac_is_found_in_pcap(self.dut, self.sta_factory_mac,
288 packets)
Bindu Mahadev36725332019-01-29 12:23:21 -0800289
290 @test_tracker_info(uuid="d9e64202-02d5-421a-967c-42e45f1f7f91")
291 def test_mac_randomization_wpapsk(self):
292 """Verify MAC randomization for a WPA network.
293
294 Steps:
295 1. Connect to WPA network.
296 2. Get the Factory, Randomized and Default MACs.
297 3. Verify randomized MAC is the default MAC for the device.
298
299 """
300 self.connect_to_network_and_verify_mac_randomization(self.wpapsk_2g)
301
302 @test_tracker_info(uuid="b5be7c53-2edf-449e-ba70-a1fb7acf735e")
303 def test_mac_randomization_wep(self):
304 """Verify MAC randomization for a WEP network.
305
306 Steps:
307 1. Connect to WEP network.
308 2. Get the Factory, Randomized and Default MACs.
309 3. Verify randomized MAC is the default MAC for the device.
310
311 """
312 self.connect_to_network_and_verify_mac_randomization(self.wep_2g)
313
314 @test_tracker_info(uuid="f5347ac0-68d5-4882-a58d-1bd0d575503c")
315 def test_mac_randomization_open(self):
316 """Verify MAC randomization for a open network.
317
318 Steps:
319 1. Connect to open network.
320 2. Get the Factory, Randomized and Default MACs.
321 3. Verify randomized MAC is the default MAC for the device.
322
323 """
324 self.connect_to_network_and_verify_mac_randomization(self.open_2g)
325
326 @test_tracker_info(uuid="5d260421-2adf-4ace-b281-3d15aec39b2a")
327 def test_persistent_mac_after_forget(self):
328 """Check if MAC is persistent after forgetting/adding a network.
329
330 Steps:
331 1. Connect to WPA network and get the randomized MAC.
332 2. Forget the network.
333 3. Connect to the same network again.
334 4. Verify randomized MAC has not changed.
335
336 """
337 self.check_mac_persistence(self.wpapsk_2g, FORGET)
338
339 @test_tracker_info(uuid="09d40a93-ead2-45ca-9905-14b05fd79f34")
340 def test_persistent_mac_after_toggle(self):
341 """Check if MAC is persistent after toggling WiFi network.
342
343 Steps:
344 1. Connect to WPA network and get the randomized MAC.
345 2. Turn WiFi ON/OFF.
346 3. Connect to the same network again.
347 4. Verify randomized MAC has not changed.
348
349 """
350 self.check_mac_persistence(self.wpapsk_2g, TOGGLE)
351
352 @test_tracker_info(uuid="a514f-8562-44e8-bfe0-4ecab9af165b")
353 def test_persistent_mac_after_device_reboot(self):
354 """Check if MAC is persistent after a device reboot.
355
356 Steps:
357 1. Connect to WPA network and get the randomized MAC.
358 2. Reboot DUT.
359 3. Connect to the same network again.
360 4. Verify randomized MAC has not changed.
361
362 """
363 self.check_mac_persistence(self.wpapsk_2g, REBOOT_DUT)
364
Bindu Mahadevb2312682019-03-13 15:44:14 -0700365 # Disable reboot test for debugging purpose.
366 #@test_tracker_info(uuid="82d691a0-22e4-4a3d-9596-e150531fcd34")
367 def persistent_mac_after_ap_reboot(self):
Bindu Mahadev36725332019-01-29 12:23:21 -0800368 """Check if MAC is persistent after AP reboots itself.
369
370 Steps:
371 1. Connect to WPA network and get the randomized MAC.
372 2. Reboot AP(basically restart hostapd in our case).
373 3. Connect to the same network again.
374 4. Verify randomized MAC has not changed.
375
376 """
377 self.check_mac_persistence(self.wpapsk_2g, REBOOT_AP)
378
379 @test_tracker_info(uuid="e1f33dbc-808c-4e61-8a4a-3a72c1f63c7e")
380 def test_mac_randomization_multiple_networks(self):
381 """Connect to multiple networks and verify same MAC.
382
383 Steps:
384 1. Connect to network A, get randomizd MAC.
385 2. Conenct to network B, get randomized MAC.
386 3. Connect back to network A and verify same MAC.
387 4. Connect back to network B and verify same MAC.
388
389 """
390 mac_list = list()
391
392 # Connect to two different networks and get randomized MAC addresses.
393 self.verify_mac_randomization_and_add_to_list(self.wpapsk_2g, mac_list)
394 self.verify_mac_randomization_and_add_to_list(self.open_2g, mac_list)
395
396 # Connect to the previous network and check MAC is persistent.
397 mac_wpapsk = self.connect_to_network_and_verify_mac_randomization(
398 self.wpapsk_2g)
399 msg = ('Randomized MAC is not persistent for this network %s. Old MAC = '
400 '%s \nNew MAC = %s')
401 if mac_wpapsk != mac_list[0]:
402 raise signals.TestFailure(msg % (self.wpapsk_5g, mac_list[0], mac_wpapsk))
403 mac_open = self.connect_to_network_and_verify_mac_randomization(
404 self.open_2g)
405 if mac_open != mac_list[1]:
406 raise signals.TestFailure(msg %(self.open_5g, mac_list[1], mac_open))
407
408 @test_tracker_info(uuid="edb5a0e5-7f3b-4147-b1d3-48ad7ad9799e")
409 def test_mac_randomization_differnet_APs(self):
410 """Verify randomization using two different APs.
411
412 Steps:
413 1. Connect to network A on AP1, get the randomized MAC.
414 2. Connect to network B on AP2, get the randomized MAC.
415 3. Veirfy the two MACs are different.
416
417 """
418 ap1 = self.wpapsk_2g
419 ap2 = self.reference_networks[1]["5g"]
420 mac_ap1 = self.connect_to_network_and_verify_mac_randomization(ap1)
421 mac_ap2 = self.connect_to_network_and_verify_mac_randomization(ap2)
xshu233592c2019-05-29 15:23:47 -0700422 if mac_ap1 == mac_ap2:
Bindu Mahadev36725332019-01-29 12:23:21 -0800423 raise signals.TestFailure("Same MAC address was generated for both "
424 "APs: %s" % mac_ap1)
425
426 @test_tracker_info(uuid="b815e9ce-bccd-4fc3-9774-1e1bc123a2a8")
427 def test_mac_randomization_ap_sta(self):
428 """Bring up STA and softAP and verify MAC randomization.
429
430 Steps:
431 1. Connect to a network and get randomized MAC.
432 2. Bring up softAP on the DUT.
433 3. Connect to softAP network on the client and get MAC.
434 4. Verify AP and STA use different randomized MACs.
xshu5ab5ef62019-04-16 17:32:38 -0700435 5. Find the channel of the SoftAp network.
436 6. Configure sniffer on that channel.
437 7. Verify the factory MAC is not leaked.
Bindu Mahadev36725332019-01-29 12:23:21 -0800438
439 """
Roshan Pius48df08c2019-09-13 08:07:30 -0700440 wutils.set_wifi_country_code(self.dut, wutils.WifiEnums.CountryCode.US)
441 wutils.set_wifi_country_code(self.dut_client, wutils.WifiEnums.CountryCode.US)
Bindu Mahadev36725332019-01-29 12:23:21 -0800442 mac_sta = self.connect_to_network_and_verify_mac_randomization(
443 self.wpapsk_2g)
444 softap = wutils.start_softap_and_verify(self, WIFI_CONFIG_APBAND_2G)
445 wutils.connect_to_wifi_network(self.dut_client, softap)
446 softap_info = self.dut_client.droid.wifiGetConnectionInfo()
447 mac_ap = softap_info['mac_address']
448 if mac_sta == mac_ap:
449 raise signals.TestFailure("Same MAC address was used for both "
450 "AP and STA: %s" % mac_sta)
451
xshu5ab5ef62019-04-16 17:32:38 -0700452 # Verify SoftAp MAC is randomized
453 softap_mac = self.get_soft_ap_mac_address()
454 message = ('Randomized SoftAp MAC and Factory SoftAp MAC are the same. '
455 'Randomized SoftAp MAC = %s, Factory SoftAp MAC = %s'
456 % (softap_mac, self.soft_ap_factory_mac))
457 asserts.assert_true(softap_mac != self.soft_ap_factory_mac, message)
458
459 softap_channel = hostapd_constants.CHANNEL_MAP[softap_info['frequency']]
460 self.log.info("softap_channel = %s\n" % (softap_channel))
461 result = self.packet_capture.configure_monitor_mode(
462 hostapd_constants.BAND_2G, softap_channel)
463 if not result:
464 raise ValueError("Failed to configure channel for 2G band")
465 self.pcap_procs = wutils.start_pcap(
Girish Moturua3ca6702019-07-24 13:23:14 -0700466 self.packet_capture, 'dual', self.test_name)
xshu5ab5ef62019-04-16 17:32:38 -0700467 # re-connect to the softAp network after sniffer is started
468 wutils.connect_to_wifi_network(self.dut_client, self.wpapsk_2g)
469 wutils.connect_to_wifi_network(self.dut_client, softap)
470 time.sleep(SHORT_TIMEOUT)
471 wutils.stop_pcap(self.packet_capture, self.pcap_procs, False)
Girish Moturua3ca6702019-07-24 13:23:14 -0700472 pcap_fname = '%s_%s.pcap' % \
473 (self.pcap_procs[hostapd_constants.BAND_2G][1],
474 hostapd_constants.BAND_2G.upper())
xshu5ab5ef62019-04-16 17:32:38 -0700475 packets = rdpcap(pcap_fname)
476 self.verify_mac_not_found_in_pcap(self.soft_ap_factory_mac, packets)
477 self.verify_mac_not_found_in_pcap(self.sta_factory_mac, packets)
478 self.verify_mac_is_found_in_pcap(softap_mac, packets)
479 self.verify_mac_is_found_in_pcap(self.get_sta_mac_address(), packets)
480
Bindu Mahadev36725332019-01-29 12:23:21 -0800481 @test_tracker_info(uuid="3ca3f911-29f1-41fb-b836-4d25eac1669f")
482 def test_roaming_mac_randomization(self):
483 """test MAC randomization in the roaming scenario.
484
485 Steps:
486 1. Connect to network A on AP1, get randomized MAC.
487 2. Set AP1 to MAX attenuation so that we roam to AP2.
488 3. Wait for device to roam to AP2 and get randomized MAC.
489 4. Veirfy that the device uses same AMC for both APs.
490
491 """
492 AP1_network = self.reference_networks[0]["5g"]
493 AP2_network = self.reference_networks[1]["5g"]
494 wutils.set_attns(self.attenuators, "AP1_on_AP2_off")
495 mac_before_roam = self.connect_to_network_and_verify_mac_randomization(
496 AP1_network)
497 wutils.trigger_roaming_and_validate(self.dut, self.attenuators,
498 "AP1_off_AP2_on", AP2_network)
499 mac_after_roam = self.get_randomized_mac(AP2_network)
500 if mac_after_roam != mac_before_roam:
501 raise signals.TestFailure("Randomized MAC address changed after "
502 "roaming from AP1 to AP2.\nMAC before roam = %s\nMAC after "
503 "roam = %s" %(mac_before_roam, mac_after_roam))
504 wutils.trigger_roaming_and_validate(self.dut, self.attenuators,
505 "AP1_on_AP2_off", AP1_network)
506 mac_after_roam = self.get_randomized_mac(AP1_network)
507 if mac_after_roam != mac_before_roam:
508 raise signals.TestFailure("Randomized MAC address changed after "
509 "roaming from AP1 to AP2.\nMAC before roam = %s\nMAC after "
510 "roam = %s" %(mac_before_roam, mac_after_roam))
Bindu Mahadev2941f482019-03-18 16:46:08 -0700511
512 @test_tracker_info(uuid="17b12f1a-7c62-4188-b5a5-52d7a0bb7849")
xshu1abc5f22019-05-03 14:27:59 -0700513 def test_check_mac_sta_with_link_probe(self):
Bindu Mahadev2941f482019-03-18 16:46:08 -0700514 """Test to ensure Factory MAC is not exposed, using sniffer data.
515
516 Steps:
517 1. Configure and start the sniffer on 5GHz band.
xshu1abc5f22019-05-03 14:27:59 -0700518 2. Connect to 5GHz network.
519 3. Send link probes.
520 4. Stop the sniffer.
521 5. Invoke scapy to read the .pcap file.
522 6. Read each packet summary and make sure Factory MAC is not used.
Bindu Mahadev2941f482019-03-18 16:46:08 -0700523
524 """
xshu5ab5ef62019-04-16 17:32:38 -0700525 self.pcap_procs = wutils.start_pcap(
Girish Moturua3ca6702019-07-24 13:23:14 -0700526 self.packet_capture, 'dual', self.test_name)
Bindu Mahadev2941f482019-03-18 16:46:08 -0700527 time.sleep(SHORT_TIMEOUT)
528 network = self.wpapsk_5g
529 rand_mac = self.connect_to_network_and_verify_mac_randomization(network)
xshu1abc5f22019-05-03 14:27:59 -0700530 wutils.send_link_probes(self.dut, 3, 3)
Girish Moturua3ca6702019-07-24 13:23:14 -0700531 pcap_fname = '%s_%s.pcap' % \
532 (self.pcap_procs[hostapd_constants.BAND_5G][1],
533 hostapd_constants.BAND_5G.upper())
Bindu Mahadevc0232702019-04-04 15:23:28 -0700534 wutils.stop_pcap(self.packet_capture, self.pcap_procs, False)
Bindu Mahadev2941f482019-03-18 16:46:08 -0700535 time.sleep(SHORT_TIMEOUT)
536 packets = rdpcap(pcap_fname)
xshu5ab5ef62019-04-16 17:32:38 -0700537 self.verify_mac_not_found_in_pcap(self.sta_factory_mac, packets)
538 self.verify_mac_is_found_in_pcap(self.get_sta_mac_address(), packets)
539
540 @test_tracker_info(uuid="1c2cc0fd-a340-40c4-b679-6acc5f526451")
541 def test_check_mac_in_wifi_scan(self):
542 """Test to ensure Factory MAC is not exposed, in Wi-Fi scans
543
544 Steps:
545 1. Configure and start the sniffer on both bands.
546 2. Perform a full scan.
547 3. Stop the sniffer.
548 4. Invoke scapy to read the .pcap file.
549 5. Read each packet summary and make sure Factory MAC is not used.
550
551 """
552 self.pcap_procs = wutils.start_pcap(
Girish Moturua3ca6702019-07-24 13:23:14 -0700553 self.packet_capture, 'dual', self.test_name)
xshu5ab5ef62019-04-16 17:32:38 -0700554 wutils.start_wifi_connection_scan(self.dut)
555 time.sleep(SHORT_TIMEOUT)
556 wutils.stop_pcap(self.packet_capture, self.pcap_procs, False)
Girish Moturua3ca6702019-07-24 13:23:14 -0700557 pcap_fname = '%s_%s.pcap' % \
558 (self.pcap_procs[hostapd_constants.BAND_2G][1],
559 hostapd_constants.BAND_2G.upper())
xshu5ab5ef62019-04-16 17:32:38 -0700560 packets = rdpcap(pcap_fname)
561 self.verify_mac_not_found_in_pcap(self.sta_factory_mac, packets)