blob: 7aa955f2f60dd25dd9a318fa4316e331bf40973a [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 Moturu11d74442020-11-06 13:20:20 -080082 self.legacy_configure_ap_and_start(wep_network=True,
83 ap_count=2)
84 elif "OpenWrtAP" in self.user_params:
85 self.configure_openwrt_ap_and_start(open_network=True,
86 wpa_network=True,
87 wep_network=True,
88 mirror_ap=True,
89 ap_count=2)
Bindu Mahadev36725332019-01-29 12:23:21 -080090
91 asserts.assert_true(
92 len(self.reference_networks) > 0,
93 "Need at least one reference network with psk.")
94
xshu5ab5ef62019-04-16 17:32:38 -070095 # Reboot device to reset factory MAC of wlan1
96 self.dut.reboot()
97 self.dut_client.reboot()
98 time.sleep(DEFAULT_TIMEOUT)
Bindu Mahadev36725332019-01-29 12:23:21 -080099 wutils.wifi_toggle_state(self.dut, True)
100 wutils.wifi_toggle_state(self.dut_client, True)
xshu5ab5ef62019-04-16 17:32:38 -0700101 self.soft_ap_factory_mac = self.get_soft_ap_mac_address()
102 self.sta_factory_mac = self.dut.droid.wifigetFactorymacAddresses()[0]
103
Bindu Mahadev36725332019-01-29 12:23:21 -0800104 self.wpapsk_2g = self.reference_networks[0]["2g"]
105 self.wpapsk_5g = self.reference_networks[0]["5g"]
106 self.wep_2g = self.wep_networks[0]["2g"]
107 self.wep_5g = self.wep_networks[0]["5g"]
108 self.open_2g = self.open_network[0]["2g"]
109 self.open_5g = self.open_network[0]["5g"]
110
111 def setup_test(self):
112 for ad in self.android_devices:
113 ad.droid.wakeLockAcquireBright()
114 ad.droid.wakeUpNow()
115 wutils.wifi_toggle_state(ad, True)
116
117 def teardown_test(self):
118 for ad in self.android_devices:
119 ad.droid.wakeLockRelease()
120 ad.droid.goToSleepNow()
121 wutils.reset_wifi(self.dut)
122 wutils.reset_wifi(self.dut_client)
123
124 def on_fail(self, test_name, begin_time):
Bindu Mahadeva6a199a2019-03-07 14:11:48 -0800125 self.dut.cat_adb_log(test_name, begin_time)
126 self.dut.take_bug_report(test_name, begin_time)
James Kacherla06d60c92020-04-03 12:27:45 -0700127 self.dut_client.take_bug_report(test_name, begin_time)
Bindu Mahadev36725332019-01-29 12:23:21 -0800128
129 def teardown_class(self):
130 if "AccessPoint" in self.user_params:
131 del self.user_params["reference_networks"]
132 del self.user_params["open_network"]
133 del self.user_params["wep_networks"]
134
135
136 """Helper Functions"""
137
138
139 def get_randomized_mac(self, network):
140 """Get the randomized MAC address.
141
142 Args:
143 network: dict, network information.
144
145 Returns:
146 The randomized MAC address string for the network.
147
148 """
149 return self.dut.droid.wifigetRandomizedMacAddress(network)
150
151 def connect_to_network_and_verify_mac_randomization(self, network,
152 status=RANDOMIZATION_PERSISTENT):
153 """Connect to the given network and verify MAC.
154
155 Args:
156 network: dict, the network information.
157 status: int, MAC randomization level.
158
159 Returns:
160 The randomized MAC addresss string.
161
162 """
163 wutils.connect_to_wifi_network(self.dut, network)
164 return self.verify_mac_randomization(network, status=status)
165
166 def verify_mac_randomization_and_add_to_list(self, network, mac_list):
167 """Connect to a network and populate it's MAC in a reference list,
168 that will be used to verify any repeated MAC addresses.
169
170 Args:
171 network: dict, the network information.
172 mac_list: list of MAC addresss strings.
173
174 """
175 rand_mac = self.connect_to_network_and_verify_mac_randomization(
176 network)
177 if rand_mac in mac_list:
178 raise signals.TestFailure('A new Randomized MAC was not generated '
179 ' for this network %s.' % network)
180 mac_list.append(rand_mac)
181
182 def verify_mac_randomization(self, network, status=RANDOMIZATION_PERSISTENT):
183 """Get the various types of MAC addresses for the device and verify.
184
185 Args:
186 network: dict, the network information.
187 status: int, MAC randomization level.
188
189 Returns:
190 The randomized MAC address string for the network.
191
192 """
Bindu Mahadev36725332019-01-29 12:23:21 -0800193 randomized_mac = self.get_randomized_mac(network)
xshu5ab5ef62019-04-16 17:32:38 -0700194 default_mac = self.get_sta_mac_address()
Bindu Mahadev36725332019-01-29 12:23:21 -0800195 self.log.info("Factory MAC = %s\nRandomized MAC = %s\nDefault MAC = %s" %
xshu5ab5ef62019-04-16 17:32:38 -0700196 (self.sta_factory_mac, randomized_mac, default_mac))
Bindu Mahadev36725332019-01-29 12:23:21 -0800197 message = ('Randomized MAC and Factory MAC are the same. '
xshu5ab5ef62019-04-16 17:32:38 -0700198 'Randomized MAC = %s, Factory MAC = %s' % (randomized_mac, self.sta_factory_mac))
199 asserts.assert_true(randomized_mac != self.sta_factory_mac, message)
200 if status == RANDOMIZATION_NONE:
201 asserts.assert_true(default_mac == self.sta_factory_mac, "Connection is not "
202 "using Factory MAC as the default MAC.")
203 else:
204 message = ('Connection is not using randomized MAC as the default MAC. '
205 'Randomized MAC = %s, Deafult MAC = %s' % (randomized_mac, default_mac))
206 asserts.assert_true(default_mac == randomized_mac, message)
Bindu Mahadev36725332019-01-29 12:23:21 -0800207 return randomized_mac
208
209 def check_mac_persistence(self, network, condition):
210 """Check if the MAC is persistent after carrying out specific operations
211 like forget WiFi, toggle WiFi, reboot device and AP.
212
213 Args:
214 network: dict, The network information.
215 condition: int, value to trigger certain operation on the device.
216
217 Raises:
218 TestFaikure is the MAC is not persistent.
219
220 """
221 rand_mac1 = self.connect_to_network_and_verify_mac_randomization(network)
222
223 if condition == FORGET:
224 wutils.wifi_forget_network(self.dut, network['SSID'])
225
226 elif condition == TOGGLE:
227 wutils.wifi_toggle_state(self.dut, False)
228 wutils.wifi_toggle_state(self.dut, True)
229
230 elif condition == REBOOT_DUT:
231 self.dut.reboot()
232 time.sleep(DEFAULT_TIMEOUT)
233
234 elif condition == REBOOT_AP:
235 wutils.turn_ap_off(self, 1)
236 time.sleep(DEFAULT_TIMEOUT)
237 wutils.turn_ap_on(self, 1)
238 time.sleep(DEFAULT_TIMEOUT)
239
240 rand_mac2 = self.connect_to_network_and_verify_mac_randomization(network)
241
242 if rand_mac1 != rand_mac2:
243 raise signals.TestFailure('Randomized MAC is not persistent after '
244 'forgetting networ. Old MAC = %s New MAC'
245 ' = %s' % (rand_mac1, rand_mac2))
246
xshu5ab5ef62019-04-16 17:32:38 -0700247 def verify_mac_not_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():
Jaineel95887fd2019-10-16 16:19:01 -0700251 raise signals.TestFailure("Caught Factory MAC in packet sniffer"
252 "Packet = %s Device = %s"
253 % (pkt.show(), self.dut))
xshu5ab5ef62019-04-16 17:32:38 -0700254
255 def verify_mac_is_found_in_pcap(self, mac, packets):
256 for pkt in packets:
257 self.log.debug("Packet Summary = %s" % pkt.summary())
258 if mac in pkt.summary():
259 return
260 raise signals.TestFailure("Did not find MAC = %s in packet sniffer."
Jaineel95887fd2019-10-16 16:19:01 -0700261 "for device %s" % (mac, self.dut))
xshu5ab5ef62019-04-16 17:32:38 -0700262
263 def get_sta_mac_address(self):
xshu1abc5f22019-05-03 14:27:59 -0700264 """Gets the current MAC address being used for client mode."""
xshu5ab5ef62019-04-16 17:32:38 -0700265 out = self.dut.adb.shell("ifconfig wlan0")
266 res = re.match(".* HWaddr (\S+).*", out, re.S)
267 return res.group(1)
268
269 def get_soft_ap_mac_address(self):
xshu1abc5f22019-05-03 14:27:59 -0700270 """Gets the current MAC address being used for SoftAp."""
xshu5ab5ef62019-04-16 17:32:38 -0700271 if self.dut.model in self.dbs_supported_models:
272 out = self.dut.adb.shell("ifconfig wlan1")
273 return re.match(".* HWaddr (\S+).*", out, re.S).group(1)
274 else:
275 return self.get_sta_mac_address()
Bindu Mahadev36725332019-01-29 12:23:21 -0800276 """Tests"""
277
278
279 @test_tracker_info(uuid="2dd0a05e-a318-45a6-81cd-962e098fa242")
280 def test_set_mac_randomization_to_none(self):
xshu5ab5ef62019-04-16 17:32:38 -0700281 self.pcap_procs = wutils.start_pcap(
Girish Moturua3ca6702019-07-24 13:23:14 -0700282 self.packet_capture, 'dual', self.test_name)
Bindu Mahadev36725332019-01-29 12:23:21 -0800283 network = self.wpapsk_2g
284 # Set macRandomizationSetting to RANDOMIZATION_NONE.
285 network["macRand"] = RANDOMIZATION_NONE
286 self.connect_to_network_and_verify_mac_randomization(network,
287 status=RANDOMIZATION_NONE)
Girish Moturua3ca6702019-07-24 13:23:14 -0700288 pcap_fname = '%s_%s.pcap' % \
289 (self.pcap_procs[hostapd_constants.BAND_2G][1],
290 hostapd_constants.BAND_2G.upper())
xshu5ab5ef62019-04-16 17:32:38 -0700291 time.sleep(SHORT_TIMEOUT)
292 wutils.stop_pcap(self.packet_capture, self.pcap_procs, False)
293 packets = rdpcap(pcap_fname)
Girish Moturu54d6dbc2019-11-04 10:00:05 -0800294 self.verify_mac_is_found_in_pcap(self.sta_factory_mac, packets)
Bindu Mahadev36725332019-01-29 12:23:21 -0800295
296 @test_tracker_info(uuid="d9e64202-02d5-421a-967c-42e45f1f7f91")
297 def test_mac_randomization_wpapsk(self):
298 """Verify MAC randomization for a WPA network.
299
300 Steps:
301 1. Connect to WPA network.
302 2. Get the Factory, Randomized and Default MACs.
303 3. Verify randomized MAC is the default MAC for the device.
304
305 """
306 self.connect_to_network_and_verify_mac_randomization(self.wpapsk_2g)
307
308 @test_tracker_info(uuid="b5be7c53-2edf-449e-ba70-a1fb7acf735e")
309 def test_mac_randomization_wep(self):
310 """Verify MAC randomization for a WEP network.
311
312 Steps:
313 1. Connect to WEP network.
314 2. Get the Factory, Randomized and Default MACs.
315 3. Verify randomized MAC is the default MAC for the device.
316
317 """
318 self.connect_to_network_and_verify_mac_randomization(self.wep_2g)
319
320 @test_tracker_info(uuid="f5347ac0-68d5-4882-a58d-1bd0d575503c")
321 def test_mac_randomization_open(self):
322 """Verify MAC randomization for a open network.
323
324 Steps:
325 1. Connect to open network.
326 2. Get the Factory, Randomized and Default MACs.
327 3. Verify randomized MAC is the default MAC for the device.
328
329 """
330 self.connect_to_network_and_verify_mac_randomization(self.open_2g)
331
332 @test_tracker_info(uuid="5d260421-2adf-4ace-b281-3d15aec39b2a")
333 def test_persistent_mac_after_forget(self):
334 """Check if MAC is persistent after forgetting/adding a network.
335
336 Steps:
337 1. Connect to WPA network and get the randomized MAC.
338 2. Forget the network.
339 3. Connect to the same network again.
340 4. Verify randomized MAC has not changed.
341
342 """
343 self.check_mac_persistence(self.wpapsk_2g, FORGET)
344
345 @test_tracker_info(uuid="09d40a93-ead2-45ca-9905-14b05fd79f34")
346 def test_persistent_mac_after_toggle(self):
347 """Check if MAC is persistent after toggling WiFi network.
348
349 Steps:
350 1. Connect to WPA network and get the randomized MAC.
351 2. Turn WiFi ON/OFF.
352 3. Connect to the same network again.
353 4. Verify randomized MAC has not changed.
354
355 """
356 self.check_mac_persistence(self.wpapsk_2g, TOGGLE)
357
Girish Moturu5ee257f2020-05-21 10:26:37 -0700358 @test_tracker_info(uuid="b3aa514f-8562-44e8-bfe0-4ecab9af165b")
Bindu Mahadev36725332019-01-29 12:23:21 -0800359 def test_persistent_mac_after_device_reboot(self):
360 """Check if MAC is persistent after a device reboot.
361
362 Steps:
363 1. Connect to WPA network and get the randomized MAC.
364 2. Reboot DUT.
365 3. Connect to the same network again.
366 4. Verify randomized MAC has not changed.
367
368 """
369 self.check_mac_persistence(self.wpapsk_2g, REBOOT_DUT)
370
Bindu Mahadevb2312682019-03-13 15:44:14 -0700371 # Disable reboot test for debugging purpose.
372 #@test_tracker_info(uuid="82d691a0-22e4-4a3d-9596-e150531fcd34")
373 def persistent_mac_after_ap_reboot(self):
Bindu Mahadev36725332019-01-29 12:23:21 -0800374 """Check if MAC is persistent after AP reboots itself.
375
376 Steps:
377 1. Connect to WPA network and get the randomized MAC.
378 2. Reboot AP(basically restart hostapd in our case).
379 3. Connect to the same network again.
380 4. Verify randomized MAC has not changed.
381
382 """
383 self.check_mac_persistence(self.wpapsk_2g, REBOOT_AP)
384
385 @test_tracker_info(uuid="e1f33dbc-808c-4e61-8a4a-3a72c1f63c7e")
386 def test_mac_randomization_multiple_networks(self):
387 """Connect to multiple networks and verify same MAC.
388
389 Steps:
390 1. Connect to network A, get randomizd MAC.
391 2. Conenct to network B, get randomized MAC.
392 3. Connect back to network A and verify same MAC.
393 4. Connect back to network B and verify same MAC.
394
395 """
396 mac_list = list()
397
398 # Connect to two different networks and get randomized MAC addresses.
399 self.verify_mac_randomization_and_add_to_list(self.wpapsk_2g, mac_list)
400 self.verify_mac_randomization_and_add_to_list(self.open_2g, mac_list)
401
402 # Connect to the previous network and check MAC is persistent.
403 mac_wpapsk = self.connect_to_network_and_verify_mac_randomization(
404 self.wpapsk_2g)
405 msg = ('Randomized MAC is not persistent for this network %s. Old MAC = '
406 '%s \nNew MAC = %s')
407 if mac_wpapsk != mac_list[0]:
408 raise signals.TestFailure(msg % (self.wpapsk_5g, mac_list[0], mac_wpapsk))
409 mac_open = self.connect_to_network_and_verify_mac_randomization(
410 self.open_2g)
411 if mac_open != mac_list[1]:
412 raise signals.TestFailure(msg %(self.open_5g, mac_list[1], mac_open))
413
414 @test_tracker_info(uuid="edb5a0e5-7f3b-4147-b1d3-48ad7ad9799e")
Girish Moturu11d74442020-11-06 13:20:20 -0800415 def test_mac_randomization_different_APs(self):
Bindu Mahadev36725332019-01-29 12:23:21 -0800416 """Verify randomization using two different APs.
417
418 Steps:
419 1. Connect to network A on AP1, get the randomized MAC.
420 2. Connect to network B on AP2, get the randomized MAC.
421 3. Veirfy the two MACs are different.
422
423 """
424 ap1 = self.wpapsk_2g
425 ap2 = self.reference_networks[1]["5g"]
426 mac_ap1 = self.connect_to_network_and_verify_mac_randomization(ap1)
427 mac_ap2 = self.connect_to_network_and_verify_mac_randomization(ap2)
xshu233592c2019-05-29 15:23:47 -0700428 if mac_ap1 == mac_ap2:
Bindu Mahadev36725332019-01-29 12:23:21 -0800429 raise signals.TestFailure("Same MAC address was generated for both "
430 "APs: %s" % mac_ap1)
431
432 @test_tracker_info(uuid="b815e9ce-bccd-4fc3-9774-1e1bc123a2a8")
433 def test_mac_randomization_ap_sta(self):
434 """Bring up STA and softAP and verify MAC randomization.
435
436 Steps:
437 1. Connect to a network and get randomized MAC.
438 2. Bring up softAP on the DUT.
439 3. Connect to softAP network on the client and get MAC.
440 4. Verify AP and STA use different randomized MACs.
xshu5ab5ef62019-04-16 17:32:38 -0700441 5. Find the channel of the SoftAp network.
442 6. Configure sniffer on that channel.
443 7. Verify the factory MAC is not leaked.
Bindu Mahadev36725332019-01-29 12:23:21 -0800444
445 """
Roshan Pius48df08c2019-09-13 08:07:30 -0700446 wutils.set_wifi_country_code(self.dut, wutils.WifiEnums.CountryCode.US)
447 wutils.set_wifi_country_code(self.dut_client, wutils.WifiEnums.CountryCode.US)
Bindu Mahadev36725332019-01-29 12:23:21 -0800448 mac_sta = self.connect_to_network_and_verify_mac_randomization(
449 self.wpapsk_2g)
450 softap = wutils.start_softap_and_verify(self, WIFI_CONFIG_APBAND_2G)
451 wutils.connect_to_wifi_network(self.dut_client, softap)
452 softap_info = self.dut_client.droid.wifiGetConnectionInfo()
453 mac_ap = softap_info['mac_address']
454 if mac_sta == mac_ap:
455 raise signals.TestFailure("Same MAC address was used for both "
456 "AP and STA: %s" % mac_sta)
457
xshu5ab5ef62019-04-16 17:32:38 -0700458 # Verify SoftAp MAC is randomized
459 softap_mac = self.get_soft_ap_mac_address()
460 message = ('Randomized SoftAp MAC and Factory SoftAp MAC are the same. '
461 'Randomized SoftAp MAC = %s, Factory SoftAp MAC = %s'
462 % (softap_mac, self.soft_ap_factory_mac))
463 asserts.assert_true(softap_mac != self.soft_ap_factory_mac, message)
464
465 softap_channel = hostapd_constants.CHANNEL_MAP[softap_info['frequency']]
466 self.log.info("softap_channel = %s\n" % (softap_channel))
467 result = self.packet_capture.configure_monitor_mode(
468 hostapd_constants.BAND_2G, softap_channel)
469 if not result:
470 raise ValueError("Failed to configure channel for 2G band")
471 self.pcap_procs = wutils.start_pcap(
Girish Moturua3ca6702019-07-24 13:23:14 -0700472 self.packet_capture, 'dual', self.test_name)
xshu5ab5ef62019-04-16 17:32:38 -0700473 # re-connect to the softAp network after sniffer is started
474 wutils.connect_to_wifi_network(self.dut_client, self.wpapsk_2g)
475 wutils.connect_to_wifi_network(self.dut_client, softap)
476 time.sleep(SHORT_TIMEOUT)
477 wutils.stop_pcap(self.packet_capture, self.pcap_procs, False)
Girish Moturua3ca6702019-07-24 13:23:14 -0700478 pcap_fname = '%s_%s.pcap' % \
479 (self.pcap_procs[hostapd_constants.BAND_2G][1],
480 hostapd_constants.BAND_2G.upper())
xshu5ab5ef62019-04-16 17:32:38 -0700481 packets = rdpcap(pcap_fname)
482 self.verify_mac_not_found_in_pcap(self.soft_ap_factory_mac, packets)
483 self.verify_mac_not_found_in_pcap(self.sta_factory_mac, packets)
484 self.verify_mac_is_found_in_pcap(softap_mac, packets)
485 self.verify_mac_is_found_in_pcap(self.get_sta_mac_address(), packets)
486
Bindu Mahadev36725332019-01-29 12:23:21 -0800487 @test_tracker_info(uuid="3ca3f911-29f1-41fb-b836-4d25eac1669f")
488 def test_roaming_mac_randomization(self):
489 """test MAC randomization in the roaming scenario.
490
491 Steps:
492 1. Connect to network A on AP1, get randomized MAC.
493 2. Set AP1 to MAX attenuation so that we roam to AP2.
494 3. Wait for device to roam to AP2 and get randomized MAC.
495 4. Veirfy that the device uses same AMC for both APs.
496
497 """
498 AP1_network = self.reference_networks[0]["5g"]
499 AP2_network = self.reference_networks[1]["5g"]
Girish Moturu11d74442020-11-06 13:20:20 -0800500 if "OpenWrtAP" in self.user_params:
501 AP1_network["bssid"] = self.bssid_map[0]["5g"][AP1_network["SSID"]]
502 AP2_network["bssid"] = self.bssid_map[1]["5g"][AP2_network["SSID"]]
Girish Moturu36348a32019-12-10 08:41:54 -0800503 wutils.set_attns(self.attenuators, "AP1_on_AP2_off", self.roaming_attn)
Bindu Mahadev36725332019-01-29 12:23:21 -0800504 mac_before_roam = self.connect_to_network_and_verify_mac_randomization(
505 AP1_network)
506 wutils.trigger_roaming_and_validate(self.dut, self.attenuators,
Girish Moturu36348a32019-12-10 08:41:54 -0800507 "AP1_off_AP2_on", AP2_network, self.roaming_attn)
Bindu Mahadev36725332019-01-29 12:23:21 -0800508 mac_after_roam = self.get_randomized_mac(AP2_network)
509 if mac_after_roam != mac_before_roam:
510 raise signals.TestFailure("Randomized MAC address changed after "
511 "roaming from AP1 to AP2.\nMAC before roam = %s\nMAC after "
512 "roam = %s" %(mac_before_roam, mac_after_roam))
513 wutils.trigger_roaming_and_validate(self.dut, self.attenuators,
Girish Moturu36348a32019-12-10 08:41:54 -0800514 "AP1_on_AP2_off", AP1_network, self.roaming_attn)
Bindu Mahadev36725332019-01-29 12:23:21 -0800515 mac_after_roam = self.get_randomized_mac(AP1_network)
516 if mac_after_roam != mac_before_roam:
517 raise signals.TestFailure("Randomized MAC address changed after "
518 "roaming from AP1 to AP2.\nMAC before roam = %s\nMAC after "
519 "roam = %s" %(mac_before_roam, mac_after_roam))
Bindu Mahadev2941f482019-03-18 16:46:08 -0700520
521 @test_tracker_info(uuid="17b12f1a-7c62-4188-b5a5-52d7a0bb7849")
xshu1abc5f22019-05-03 14:27:59 -0700522 def test_check_mac_sta_with_link_probe(self):
Bindu Mahadev2941f482019-03-18 16:46:08 -0700523 """Test to ensure Factory MAC is not exposed, using sniffer data.
524
525 Steps:
526 1. Configure and start the sniffer on 5GHz band.
xshu1abc5f22019-05-03 14:27:59 -0700527 2. Connect to 5GHz network.
528 3. Send link probes.
529 4. Stop the sniffer.
530 5. Invoke scapy to read the .pcap file.
531 6. Read each packet summary and make sure Factory MAC is not used.
Bindu Mahadev2941f482019-03-18 16:46:08 -0700532
533 """
xshu5ab5ef62019-04-16 17:32:38 -0700534 self.pcap_procs = wutils.start_pcap(
Girish Moturua3ca6702019-07-24 13:23:14 -0700535 self.packet_capture, 'dual', self.test_name)
Bindu Mahadev2941f482019-03-18 16:46:08 -0700536 time.sleep(SHORT_TIMEOUT)
537 network = self.wpapsk_5g
538 rand_mac = self.connect_to_network_and_verify_mac_randomization(network)
xshu1abc5f22019-05-03 14:27:59 -0700539 wutils.send_link_probes(self.dut, 3, 3)
Girish Moturua3ca6702019-07-24 13:23:14 -0700540 pcap_fname = '%s_%s.pcap' % \
541 (self.pcap_procs[hostapd_constants.BAND_5G][1],
542 hostapd_constants.BAND_5G.upper())
Bindu Mahadevc0232702019-04-04 15:23:28 -0700543 wutils.stop_pcap(self.packet_capture, self.pcap_procs, False)
Bindu Mahadev2941f482019-03-18 16:46:08 -0700544 time.sleep(SHORT_TIMEOUT)
545 packets = rdpcap(pcap_fname)
xshu5ab5ef62019-04-16 17:32:38 -0700546 self.verify_mac_not_found_in_pcap(self.sta_factory_mac, packets)
547 self.verify_mac_is_found_in_pcap(self.get_sta_mac_address(), packets)
548
549 @test_tracker_info(uuid="1c2cc0fd-a340-40c4-b679-6acc5f526451")
550 def test_check_mac_in_wifi_scan(self):
551 """Test to ensure Factory MAC is not exposed, in Wi-Fi scans
552
553 Steps:
554 1. Configure and start the sniffer on both bands.
555 2. Perform a full scan.
556 3. Stop the sniffer.
557 4. Invoke scapy to read the .pcap file.
558 5. Read each packet summary and make sure Factory MAC is not used.
559
560 """
561 self.pcap_procs = wutils.start_pcap(
Girish Moturua3ca6702019-07-24 13:23:14 -0700562 self.packet_capture, 'dual', self.test_name)
xshu5ab5ef62019-04-16 17:32:38 -0700563 wutils.start_wifi_connection_scan(self.dut)
564 time.sleep(SHORT_TIMEOUT)
565 wutils.stop_pcap(self.packet_capture, self.pcap_procs, False)
Girish Moturua3ca6702019-07-24 13:23:14 -0700566 pcap_fname = '%s_%s.pcap' % \
567 (self.pcap_procs[hostapd_constants.BAND_2G][1],
568 hostapd_constants.BAND_2G.upper())
xshu5ab5ef62019-04-16 17:32:38 -0700569 packets = rdpcap(pcap_fname)
570 self.verify_mac_not_found_in_pcap(self.sta_factory_mac, packets)