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