Bindu Mahadev | 3672533 | 2019-01-29 12:23:21 -0800 | [diff] [blame] | 1 | #!/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 | |
| 17 | import itertools |
| 18 | import pprint |
| 19 | import queue |
xshu | 5ab5ef6 | 2019-04-16 17:32:38 -0700 | [diff] [blame^] | 20 | import re |
Bindu Mahadev | 3672533 | 2019-01-29 12:23:21 -0800 | [diff] [blame] | 21 | import time |
| 22 | |
| 23 | import acts.base_test |
| 24 | import acts.signals as signals |
| 25 | import acts.test_utils.wifi.wifi_test_utils as wutils |
| 26 | import acts.utils |
| 27 | |
| 28 | from acts import asserts |
| 29 | from acts.test_decorators import test_tracker_info |
| 30 | from acts.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_2G |
| 31 | from acts.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_5G |
| 32 | from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest |
Bindu Mahadev | 2941f48 | 2019-03-18 16:46:08 -0700 | [diff] [blame] | 33 | from scapy.all import * |
xshu | 5ab5ef6 | 2019-04-16 17:32:38 -0700 | [diff] [blame^] | 34 | from acts.controllers.ap_lib import hostapd_constants |
Bindu Mahadev | 3672533 | 2019-01-29 12:23:21 -0800 | [diff] [blame] | 35 | |
| 36 | WifiEnums = wutils.WifiEnums |
| 37 | |
| 38 | # Default timeout used for reboot, toggle WiFi and Airplane mode, |
| 39 | # for the system to settle down after the operation. |
| 40 | DEFAULT_TIMEOUT = 10 |
Bindu Mahadev | 2941f48 | 2019-03-18 16:46:08 -0700 | [diff] [blame] | 41 | SHORT_TIMEOUT = 5 |
Bindu Mahadev | 3672533 | 2019-01-29 12:23:21 -0800 | [diff] [blame] | 42 | |
| 43 | # Constants for WiFi state change operations. |
| 44 | FORGET = 1 |
| 45 | TOGGLE = 2 |
| 46 | REBOOT_DUT = 3 |
| 47 | REBOOT_AP = 4 |
| 48 | |
| 49 | # MAC Randomization setting constants. |
| 50 | RANDOMIZATION_NONE = 0 |
| 51 | RANDOMIZATION_PERSISTENT = 1 |
| 52 | |
| 53 | |
| 54 | class 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 | |
| 62 | def __init__(self, controllers): |
| 63 | WifiBaseTest.__init__(self, controllers) |
| 64 | |
| 65 | def setup_class(self): |
| 66 | self.dut = self.android_devices[0] |
| 67 | self.dut_client = self.android_devices[1] |
| 68 | wutils.wifi_test_device_init(self.dut) |
| 69 | wutils.wifi_test_device_init(self.dut_client) |
xshu | 5ab5ef6 | 2019-04-16 17:32:38 -0700 | [diff] [blame^] | 70 | req_params = ["dbs_supported_models"] |
Bindu Mahadev | 3672533 | 2019-01-29 12:23:21 -0800 | [diff] [blame] | 71 | opt_param = [ |
| 72 | "open_network", "reference_networks", "wep_networks" |
| 73 | ] |
| 74 | self.unpack_userparams( |
| 75 | req_param_names=req_params, opt_param_names=opt_param) |
| 76 | |
xshu | 5ab5ef6 | 2019-04-16 17:32:38 -0700 | [diff] [blame^] | 77 | if not hasattr(self, 'packet_capture'): |
| 78 | raise signals.TestFailure("Needs packet_capture attribute to " |
| 79 | "support sniffing.") |
| 80 | self.configure_packet_capture() |
Bindu Mahadev | fcdac50 | 2019-04-16 18:43:23 -0700 | [diff] [blame] | 81 | |
Bindu Mahadev | 3672533 | 2019-01-29 12:23:21 -0800 | [diff] [blame] | 82 | if "AccessPoint" in self.user_params: |
| 83 | if "AccessPoint" in self.user_params: |
| 84 | self.legacy_configure_ap_and_start(wep_network=True, ap_count=2) |
| 85 | |
| 86 | asserts.assert_true( |
| 87 | len(self.reference_networks) > 0, |
| 88 | "Need at least one reference network with psk.") |
| 89 | |
xshu | 5ab5ef6 | 2019-04-16 17:32:38 -0700 | [diff] [blame^] | 90 | # Reboot device to reset factory MAC of wlan1 |
| 91 | self.dut.reboot() |
| 92 | self.dut_client.reboot() |
| 93 | time.sleep(DEFAULT_TIMEOUT) |
Bindu Mahadev | 3672533 | 2019-01-29 12:23:21 -0800 | [diff] [blame] | 94 | wutils.wifi_toggle_state(self.dut, True) |
| 95 | wutils.wifi_toggle_state(self.dut_client, True) |
xshu | 5ab5ef6 | 2019-04-16 17:32:38 -0700 | [diff] [blame^] | 96 | self.soft_ap_factory_mac = self.get_soft_ap_mac_address() |
| 97 | self.sta_factory_mac = self.dut.droid.wifigetFactorymacAddresses()[0] |
| 98 | |
Bindu Mahadev | 3672533 | 2019-01-29 12:23:21 -0800 | [diff] [blame] | 99 | self.wpapsk_2g = self.reference_networks[0]["2g"] |
| 100 | self.wpapsk_5g = self.reference_networks[0]["5g"] |
| 101 | self.wep_2g = self.wep_networks[0]["2g"] |
| 102 | self.wep_5g = self.wep_networks[0]["5g"] |
| 103 | self.open_2g = self.open_network[0]["2g"] |
| 104 | self.open_5g = self.open_network[0]["5g"] |
| 105 | |
| 106 | def setup_test(self): |
| 107 | for ad in self.android_devices: |
| 108 | ad.droid.wakeLockAcquireBright() |
| 109 | ad.droid.wakeUpNow() |
| 110 | wutils.wifi_toggle_state(ad, True) |
| 111 | |
| 112 | def teardown_test(self): |
| 113 | for ad in self.android_devices: |
| 114 | ad.droid.wakeLockRelease() |
| 115 | ad.droid.goToSleepNow() |
| 116 | wutils.reset_wifi(self.dut) |
| 117 | wutils.reset_wifi(self.dut_client) |
| 118 | |
| 119 | def on_fail(self, test_name, begin_time): |
Bindu Mahadev | a6a199a | 2019-03-07 14:11:48 -0800 | [diff] [blame] | 120 | self.dut.cat_adb_log(test_name, begin_time) |
| 121 | self.dut.take_bug_report(test_name, begin_time) |
Bindu Mahadev | 3672533 | 2019-01-29 12:23:21 -0800 | [diff] [blame] | 122 | |
| 123 | def teardown_class(self): |
| 124 | if "AccessPoint" in self.user_params: |
| 125 | del self.user_params["reference_networks"] |
| 126 | del self.user_params["open_network"] |
| 127 | del self.user_params["wep_networks"] |
| 128 | |
| 129 | |
| 130 | """Helper Functions""" |
| 131 | |
| 132 | |
| 133 | def get_randomized_mac(self, network): |
| 134 | """Get the randomized MAC address. |
| 135 | |
| 136 | Args: |
| 137 | network: dict, network information. |
| 138 | |
| 139 | Returns: |
| 140 | The randomized MAC address string for the network. |
| 141 | |
| 142 | """ |
| 143 | return self.dut.droid.wifigetRandomizedMacAddress(network) |
| 144 | |
| 145 | def connect_to_network_and_verify_mac_randomization(self, network, |
| 146 | status=RANDOMIZATION_PERSISTENT): |
| 147 | """Connect to the given network and verify MAC. |
| 148 | |
| 149 | Args: |
| 150 | network: dict, the network information. |
| 151 | status: int, MAC randomization level. |
| 152 | |
| 153 | Returns: |
| 154 | The randomized MAC addresss string. |
| 155 | |
| 156 | """ |
| 157 | wutils.connect_to_wifi_network(self.dut, network) |
| 158 | return self.verify_mac_randomization(network, status=status) |
| 159 | |
| 160 | def verify_mac_randomization_and_add_to_list(self, network, mac_list): |
| 161 | """Connect to a network and populate it's MAC in a reference list, |
| 162 | that will be used to verify any repeated MAC addresses. |
| 163 | |
| 164 | Args: |
| 165 | network: dict, the network information. |
| 166 | mac_list: list of MAC addresss strings. |
| 167 | |
| 168 | """ |
| 169 | rand_mac = self.connect_to_network_and_verify_mac_randomization( |
| 170 | network) |
| 171 | if rand_mac in mac_list: |
| 172 | raise signals.TestFailure('A new Randomized MAC was not generated ' |
| 173 | ' for this network %s.' % network) |
| 174 | mac_list.append(rand_mac) |
| 175 | |
| 176 | def verify_mac_randomization(self, network, status=RANDOMIZATION_PERSISTENT): |
| 177 | """Get the various types of MAC addresses for the device and verify. |
| 178 | |
| 179 | Args: |
| 180 | network: dict, the network information. |
| 181 | status: int, MAC randomization level. |
| 182 | |
| 183 | Returns: |
| 184 | The randomized MAC address string for the network. |
| 185 | |
| 186 | """ |
Bindu Mahadev | 3672533 | 2019-01-29 12:23:21 -0800 | [diff] [blame] | 187 | randomized_mac = self.get_randomized_mac(network) |
xshu | 5ab5ef6 | 2019-04-16 17:32:38 -0700 | [diff] [blame^] | 188 | default_mac = self.get_sta_mac_address() |
Bindu Mahadev | 3672533 | 2019-01-29 12:23:21 -0800 | [diff] [blame] | 189 | self.log.info("Factory MAC = %s\nRandomized MAC = %s\nDefault MAC = %s" % |
xshu | 5ab5ef6 | 2019-04-16 17:32:38 -0700 | [diff] [blame^] | 190 | (self.sta_factory_mac, randomized_mac, default_mac)) |
Bindu Mahadev | 3672533 | 2019-01-29 12:23:21 -0800 | [diff] [blame] | 191 | message = ('Randomized MAC and Factory MAC are the same. ' |
xshu | 5ab5ef6 | 2019-04-16 17:32:38 -0700 | [diff] [blame^] | 192 | 'Randomized MAC = %s, Factory MAC = %s' % (randomized_mac, self.sta_factory_mac)) |
| 193 | asserts.assert_true(randomized_mac != self.sta_factory_mac, message) |
| 194 | if status == RANDOMIZATION_NONE: |
| 195 | asserts.assert_true(default_mac == self.sta_factory_mac, "Connection is not " |
| 196 | "using Factory MAC as the default MAC.") |
| 197 | else: |
| 198 | message = ('Connection is not using randomized MAC as the default MAC. ' |
| 199 | 'Randomized MAC = %s, Deafult MAC = %s' % (randomized_mac, default_mac)) |
| 200 | asserts.assert_true(default_mac == randomized_mac, message) |
Bindu Mahadev | 3672533 | 2019-01-29 12:23:21 -0800 | [diff] [blame] | 201 | return randomized_mac |
| 202 | |
| 203 | def check_mac_persistence(self, network, condition): |
| 204 | """Check if the MAC is persistent after carrying out specific operations |
| 205 | like forget WiFi, toggle WiFi, reboot device and AP. |
| 206 | |
| 207 | Args: |
| 208 | network: dict, The network information. |
| 209 | condition: int, value to trigger certain operation on the device. |
| 210 | |
| 211 | Raises: |
| 212 | TestFaikure is the MAC is not persistent. |
| 213 | |
| 214 | """ |
| 215 | rand_mac1 = self.connect_to_network_and_verify_mac_randomization(network) |
| 216 | |
| 217 | if condition == FORGET: |
| 218 | wutils.wifi_forget_network(self.dut, network['SSID']) |
| 219 | |
| 220 | elif condition == TOGGLE: |
| 221 | wutils.wifi_toggle_state(self.dut, False) |
| 222 | wutils.wifi_toggle_state(self.dut, True) |
| 223 | |
| 224 | elif condition == REBOOT_DUT: |
| 225 | self.dut.reboot() |
| 226 | time.sleep(DEFAULT_TIMEOUT) |
| 227 | |
| 228 | elif condition == REBOOT_AP: |
| 229 | wutils.turn_ap_off(self, 1) |
| 230 | time.sleep(DEFAULT_TIMEOUT) |
| 231 | wutils.turn_ap_on(self, 1) |
| 232 | time.sleep(DEFAULT_TIMEOUT) |
| 233 | |
| 234 | rand_mac2 = self.connect_to_network_and_verify_mac_randomization(network) |
| 235 | |
| 236 | if rand_mac1 != rand_mac2: |
| 237 | raise signals.TestFailure('Randomized MAC is not persistent after ' |
| 238 | 'forgetting networ. Old MAC = %s New MAC' |
| 239 | ' = %s' % (rand_mac1, rand_mac2)) |
| 240 | |
xshu | 5ab5ef6 | 2019-04-16 17:32:38 -0700 | [diff] [blame^] | 241 | def verify_mac_not_found_in_pcap(self, mac, packets): |
| 242 | for pkt in packets: |
| 243 | self.log.debug("Packet Summary = %s" % pkt.summary()) |
| 244 | if mac in pkt.summary(): |
| 245 | raise signals.TestFailure("Caught Factory MAC in packet sniffer." |
| 246 | "Packet = %s" % pkt.show()) |
| 247 | |
| 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." |
| 254 | % mac) |
| 255 | |
| 256 | def get_sta_mac_address(self): |
| 257 | 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): |
| 262 | if self.dut.model in self.dbs_supported_models: |
| 263 | out = self.dut.adb.shell("ifconfig wlan1") |
| 264 | return re.match(".* HWaddr (\S+).*", out, re.S).group(1) |
| 265 | else: |
| 266 | return self.get_sta_mac_address() |
Bindu Mahadev | 3672533 | 2019-01-29 12:23:21 -0800 | [diff] [blame] | 267 | """Tests""" |
| 268 | |
| 269 | |
| 270 | @test_tracker_info(uuid="2dd0a05e-a318-45a6-81cd-962e098fa242") |
| 271 | def test_set_mac_randomization_to_none(self): |
xshu | 5ab5ef6 | 2019-04-16 17:32:38 -0700 | [diff] [blame^] | 272 | self.pcap_procs = wutils.start_pcap( |
| 273 | self.packet_capture, 'dual', self.log_path, self.test_name) |
Bindu Mahadev | 3672533 | 2019-01-29 12:23:21 -0800 | [diff] [blame] | 274 | network = self.wpapsk_2g |
| 275 | # Set macRandomizationSetting to RANDOMIZATION_NONE. |
| 276 | network["macRand"] = RANDOMIZATION_NONE |
| 277 | self.connect_to_network_and_verify_mac_randomization(network, |
| 278 | status=RANDOMIZATION_NONE) |
xshu | 5ab5ef6 | 2019-04-16 17:32:38 -0700 | [diff] [blame^] | 279 | pcap_fname = os.path.join(self.log_path, self.test_name, |
| 280 | (self.test_name + '_2G.pcap')) |
| 281 | time.sleep(SHORT_TIMEOUT) |
| 282 | wutils.stop_pcap(self.packet_capture, self.pcap_procs, False) |
| 283 | packets = rdpcap(pcap_fname) |
| 284 | self.verify_mac_is_found_in_pcap(self.sta_factory_mac, packets) |
Bindu Mahadev | 3672533 | 2019-01-29 12:23:21 -0800 | [diff] [blame] | 285 | |
| 286 | @test_tracker_info(uuid="d9e64202-02d5-421a-967c-42e45f1f7f91") |
| 287 | def test_mac_randomization_wpapsk(self): |
| 288 | """Verify MAC randomization for a WPA network. |
| 289 | |
| 290 | Steps: |
| 291 | 1. Connect to WPA network. |
| 292 | 2. Get the Factory, Randomized and Default MACs. |
| 293 | 3. Verify randomized MAC is the default MAC for the device. |
| 294 | |
| 295 | """ |
| 296 | self.connect_to_network_and_verify_mac_randomization(self.wpapsk_2g) |
| 297 | |
| 298 | @test_tracker_info(uuid="b5be7c53-2edf-449e-ba70-a1fb7acf735e") |
| 299 | def test_mac_randomization_wep(self): |
| 300 | """Verify MAC randomization for a WEP network. |
| 301 | |
| 302 | Steps: |
| 303 | 1. Connect to WEP network. |
| 304 | 2. Get the Factory, Randomized and Default MACs. |
| 305 | 3. Verify randomized MAC is the default MAC for the device. |
| 306 | |
| 307 | """ |
| 308 | self.connect_to_network_and_verify_mac_randomization(self.wep_2g) |
| 309 | |
| 310 | @test_tracker_info(uuid="f5347ac0-68d5-4882-a58d-1bd0d575503c") |
| 311 | def test_mac_randomization_open(self): |
| 312 | """Verify MAC randomization for a open network. |
| 313 | |
| 314 | Steps: |
| 315 | 1. Connect to open network. |
| 316 | 2. Get the Factory, Randomized and Default MACs. |
| 317 | 3. Verify randomized MAC is the default MAC for the device. |
| 318 | |
| 319 | """ |
| 320 | self.connect_to_network_and_verify_mac_randomization(self.open_2g) |
| 321 | |
| 322 | @test_tracker_info(uuid="5d260421-2adf-4ace-b281-3d15aec39b2a") |
| 323 | def test_persistent_mac_after_forget(self): |
| 324 | """Check if MAC is persistent after forgetting/adding a network. |
| 325 | |
| 326 | Steps: |
| 327 | 1. Connect to WPA network and get the randomized MAC. |
| 328 | 2. Forget the network. |
| 329 | 3. Connect to the same network again. |
| 330 | 4. Verify randomized MAC has not changed. |
| 331 | |
| 332 | """ |
| 333 | self.check_mac_persistence(self.wpapsk_2g, FORGET) |
| 334 | |
| 335 | @test_tracker_info(uuid="09d40a93-ead2-45ca-9905-14b05fd79f34") |
| 336 | def test_persistent_mac_after_toggle(self): |
| 337 | """Check if MAC is persistent after toggling WiFi network. |
| 338 | |
| 339 | Steps: |
| 340 | 1. Connect to WPA network and get the randomized MAC. |
| 341 | 2. Turn WiFi ON/OFF. |
| 342 | 3. Connect to the same network again. |
| 343 | 4. Verify randomized MAC has not changed. |
| 344 | |
| 345 | """ |
| 346 | self.check_mac_persistence(self.wpapsk_2g, TOGGLE) |
| 347 | |
| 348 | @test_tracker_info(uuid="a514f-8562-44e8-bfe0-4ecab9af165b") |
| 349 | def test_persistent_mac_after_device_reboot(self): |
| 350 | """Check if MAC is persistent after a device reboot. |
| 351 | |
| 352 | Steps: |
| 353 | 1. Connect to WPA network and get the randomized MAC. |
| 354 | 2. Reboot DUT. |
| 355 | 3. Connect to the same network again. |
| 356 | 4. Verify randomized MAC has not changed. |
| 357 | |
| 358 | """ |
| 359 | self.check_mac_persistence(self.wpapsk_2g, REBOOT_DUT) |
| 360 | |
Bindu Mahadev | b231268 | 2019-03-13 15:44:14 -0700 | [diff] [blame] | 361 | # Disable reboot test for debugging purpose. |
| 362 | #@test_tracker_info(uuid="82d691a0-22e4-4a3d-9596-e150531fcd34") |
| 363 | def persistent_mac_after_ap_reboot(self): |
Bindu Mahadev | 3672533 | 2019-01-29 12:23:21 -0800 | [diff] [blame] | 364 | """Check if MAC is persistent after AP reboots itself. |
| 365 | |
| 366 | Steps: |
| 367 | 1. Connect to WPA network and get the randomized MAC. |
| 368 | 2. Reboot AP(basically restart hostapd in our case). |
| 369 | 3. Connect to the same network again. |
| 370 | 4. Verify randomized MAC has not changed. |
| 371 | |
| 372 | """ |
| 373 | self.check_mac_persistence(self.wpapsk_2g, REBOOT_AP) |
| 374 | |
| 375 | @test_tracker_info(uuid="e1f33dbc-808c-4e61-8a4a-3a72c1f63c7e") |
| 376 | def test_mac_randomization_multiple_networks(self): |
| 377 | """Connect to multiple networks and verify same MAC. |
| 378 | |
| 379 | Steps: |
| 380 | 1. Connect to network A, get randomizd MAC. |
| 381 | 2. Conenct to network B, get randomized MAC. |
| 382 | 3. Connect back to network A and verify same MAC. |
| 383 | 4. Connect back to network B and verify same MAC. |
| 384 | |
| 385 | """ |
| 386 | mac_list = list() |
| 387 | |
| 388 | # Connect to two different networks and get randomized MAC addresses. |
| 389 | self.verify_mac_randomization_and_add_to_list(self.wpapsk_2g, mac_list) |
| 390 | self.verify_mac_randomization_and_add_to_list(self.open_2g, mac_list) |
| 391 | |
| 392 | # Connect to the previous network and check MAC is persistent. |
| 393 | mac_wpapsk = self.connect_to_network_and_verify_mac_randomization( |
| 394 | self.wpapsk_2g) |
| 395 | msg = ('Randomized MAC is not persistent for this network %s. Old MAC = ' |
| 396 | '%s \nNew MAC = %s') |
| 397 | if mac_wpapsk != mac_list[0]: |
| 398 | raise signals.TestFailure(msg % (self.wpapsk_5g, mac_list[0], mac_wpapsk)) |
| 399 | mac_open = self.connect_to_network_and_verify_mac_randomization( |
| 400 | self.open_2g) |
| 401 | if mac_open != mac_list[1]: |
| 402 | raise signals.TestFailure(msg %(self.open_5g, mac_list[1], mac_open)) |
| 403 | |
| 404 | @test_tracker_info(uuid="edb5a0e5-7f3b-4147-b1d3-48ad7ad9799e") |
| 405 | def test_mac_randomization_differnet_APs(self): |
| 406 | """Verify randomization using two different APs. |
| 407 | |
| 408 | Steps: |
| 409 | 1. Connect to network A on AP1, get the randomized MAC. |
| 410 | 2. Connect to network B on AP2, get the randomized MAC. |
| 411 | 3. Veirfy the two MACs are different. |
| 412 | |
| 413 | """ |
| 414 | ap1 = self.wpapsk_2g |
| 415 | ap2 = self.reference_networks[1]["5g"] |
| 416 | mac_ap1 = self.connect_to_network_and_verify_mac_randomization(ap1) |
| 417 | mac_ap2 = self.connect_to_network_and_verify_mac_randomization(ap2) |
| 418 | if ap1 == ap2: |
| 419 | raise signals.TestFailure("Same MAC address was generated for both " |
| 420 | "APs: %s" % mac_ap1) |
| 421 | |
| 422 | @test_tracker_info(uuid="b815e9ce-bccd-4fc3-9774-1e1bc123a2a8") |
| 423 | def test_mac_randomization_ap_sta(self): |
| 424 | """Bring up STA and softAP and verify MAC randomization. |
| 425 | |
| 426 | Steps: |
| 427 | 1. Connect to a network and get randomized MAC. |
| 428 | 2. Bring up softAP on the DUT. |
| 429 | 3. Connect to softAP network on the client and get MAC. |
| 430 | 4. Verify AP and STA use different randomized MACs. |
xshu | 5ab5ef6 | 2019-04-16 17:32:38 -0700 | [diff] [blame^] | 431 | 5. Find the channel of the SoftAp network. |
| 432 | 6. Configure sniffer on that channel. |
| 433 | 7. Verify the factory MAC is not leaked. |
Bindu Mahadev | 3672533 | 2019-01-29 12:23:21 -0800 | [diff] [blame] | 434 | |
| 435 | """ |
| 436 | self.dut.droid.wifiSetCountryCode(wutils.WifiEnums.CountryCode.US) |
| 437 | self.dut_client.droid.wifiSetCountryCode(wutils.WifiEnums.CountryCode.US) |
| 438 | mac_sta = self.connect_to_network_and_verify_mac_randomization( |
| 439 | self.wpapsk_2g) |
| 440 | softap = wutils.start_softap_and_verify(self, WIFI_CONFIG_APBAND_2G) |
| 441 | wutils.connect_to_wifi_network(self.dut_client, softap) |
| 442 | softap_info = self.dut_client.droid.wifiGetConnectionInfo() |
| 443 | mac_ap = softap_info['mac_address'] |
| 444 | if mac_sta == mac_ap: |
| 445 | raise signals.TestFailure("Same MAC address was used for both " |
| 446 | "AP and STA: %s" % mac_sta) |
| 447 | |
xshu | 5ab5ef6 | 2019-04-16 17:32:38 -0700 | [diff] [blame^] | 448 | # Verify SoftAp MAC is randomized |
| 449 | softap_mac = self.get_soft_ap_mac_address() |
| 450 | message = ('Randomized SoftAp MAC and Factory SoftAp MAC are the same. ' |
| 451 | 'Randomized SoftAp MAC = %s, Factory SoftAp MAC = %s' |
| 452 | % (softap_mac, self.soft_ap_factory_mac)) |
| 453 | asserts.assert_true(softap_mac != self.soft_ap_factory_mac, message) |
| 454 | |
| 455 | softap_channel = hostapd_constants.CHANNEL_MAP[softap_info['frequency']] |
| 456 | self.log.info("softap_channel = %s\n" % (softap_channel)) |
| 457 | result = self.packet_capture.configure_monitor_mode( |
| 458 | hostapd_constants.BAND_2G, softap_channel) |
| 459 | if not result: |
| 460 | raise ValueError("Failed to configure channel for 2G band") |
| 461 | self.pcap_procs = wutils.start_pcap( |
| 462 | self.packet_capture, 'dual', self.log_path, self.test_name) |
| 463 | # re-connect to the softAp network after sniffer is started |
| 464 | wutils.connect_to_wifi_network(self.dut_client, self.wpapsk_2g) |
| 465 | wutils.connect_to_wifi_network(self.dut_client, softap) |
| 466 | time.sleep(SHORT_TIMEOUT) |
| 467 | wutils.stop_pcap(self.packet_capture, self.pcap_procs, False) |
| 468 | pcap_fname = os.path.join(self.log_path, self.test_name, |
| 469 | (self.test_name + '_2G.pcap')) |
| 470 | packets = rdpcap(pcap_fname) |
| 471 | self.verify_mac_not_found_in_pcap(self.soft_ap_factory_mac, packets) |
| 472 | self.verify_mac_not_found_in_pcap(self.sta_factory_mac, packets) |
| 473 | self.verify_mac_is_found_in_pcap(softap_mac, packets) |
| 474 | self.verify_mac_is_found_in_pcap(self.get_sta_mac_address(), packets) |
| 475 | |
Bindu Mahadev | 3672533 | 2019-01-29 12:23:21 -0800 | [diff] [blame] | 476 | @test_tracker_info(uuid="3ca3f911-29f1-41fb-b836-4d25eac1669f") |
| 477 | def test_roaming_mac_randomization(self): |
| 478 | """test MAC randomization in the roaming scenario. |
| 479 | |
| 480 | Steps: |
| 481 | 1. Connect to network A on AP1, get randomized MAC. |
| 482 | 2. Set AP1 to MAX attenuation so that we roam to AP2. |
| 483 | 3. Wait for device to roam to AP2 and get randomized MAC. |
| 484 | 4. Veirfy that the device uses same AMC for both APs. |
| 485 | |
| 486 | """ |
| 487 | AP1_network = self.reference_networks[0]["5g"] |
| 488 | AP2_network = self.reference_networks[1]["5g"] |
| 489 | wutils.set_attns(self.attenuators, "AP1_on_AP2_off") |
| 490 | mac_before_roam = self.connect_to_network_and_verify_mac_randomization( |
| 491 | AP1_network) |
| 492 | wutils.trigger_roaming_and_validate(self.dut, self.attenuators, |
| 493 | "AP1_off_AP2_on", AP2_network) |
| 494 | mac_after_roam = self.get_randomized_mac(AP2_network) |
| 495 | if mac_after_roam != mac_before_roam: |
| 496 | raise signals.TestFailure("Randomized MAC address changed after " |
| 497 | "roaming from AP1 to AP2.\nMAC before roam = %s\nMAC after " |
| 498 | "roam = %s" %(mac_before_roam, mac_after_roam)) |
| 499 | wutils.trigger_roaming_and_validate(self.dut, self.attenuators, |
| 500 | "AP1_on_AP2_off", AP1_network) |
| 501 | mac_after_roam = self.get_randomized_mac(AP1_network) |
| 502 | if mac_after_roam != mac_before_roam: |
| 503 | raise signals.TestFailure("Randomized MAC address changed after " |
| 504 | "roaming from AP1 to AP2.\nMAC before roam = %s\nMAC after " |
| 505 | "roam = %s" %(mac_before_roam, mac_after_roam)) |
Bindu Mahadev | 2941f48 | 2019-03-18 16:46:08 -0700 | [diff] [blame] | 506 | |
| 507 | @test_tracker_info(uuid="17b12f1a-7c62-4188-b5a5-52d7a0bb7849") |
| 508 | def test_check_mac_in_sniffer(self): |
| 509 | """Test to ensure Factory MAC is not exposed, using sniffer data. |
| 510 | |
| 511 | Steps: |
| 512 | 1. Configure and start the sniffer on 5GHz band. |
| 513 | 2. Connect to 5GHz network, ping, get the Factory MAC. |
| 514 | 3. Stop the sniffer. |
| 515 | 4. Invoke scapy to read the .pcap file. |
xshu | 5ab5ef6 | 2019-04-16 17:32:38 -0700 | [diff] [blame^] | 516 | 5. Read each packet summary and make sure Factory MAC is not used. |
Bindu Mahadev | 2941f48 | 2019-03-18 16:46:08 -0700 | [diff] [blame] | 517 | |
| 518 | """ |
xshu | 5ab5ef6 | 2019-04-16 17:32:38 -0700 | [diff] [blame^] | 519 | self.pcap_procs = wutils.start_pcap( |
| 520 | self.packet_capture, 'dual', self.log_path, self.test_name) |
Bindu Mahadev | 2941f48 | 2019-03-18 16:46:08 -0700 | [diff] [blame] | 521 | time.sleep(SHORT_TIMEOUT) |
| 522 | network = self.wpapsk_5g |
| 523 | rand_mac = self.connect_to_network_and_verify_mac_randomization(network) |
| 524 | pcap_fname = os.path.join(self.log_path, self.test_name, |
| 525 | (self.test_name + '_5G.pcap')) |
Bindu Mahadev | c023270 | 2019-04-04 15:23:28 -0700 | [diff] [blame] | 526 | wutils.stop_pcap(self.packet_capture, self.pcap_procs, False) |
Bindu Mahadev | 2941f48 | 2019-03-18 16:46:08 -0700 | [diff] [blame] | 527 | time.sleep(SHORT_TIMEOUT) |
| 528 | packets = rdpcap(pcap_fname) |
xshu | 5ab5ef6 | 2019-04-16 17:32:38 -0700 | [diff] [blame^] | 529 | self.verify_mac_not_found_in_pcap(self.sta_factory_mac, packets) |
| 530 | self.verify_mac_is_found_in_pcap(self.get_sta_mac_address(), packets) |
| 531 | |
| 532 | @test_tracker_info(uuid="1c2cc0fd-a340-40c4-b679-6acc5f526451") |
| 533 | def test_check_mac_in_wifi_scan(self): |
| 534 | """Test to ensure Factory MAC is not exposed, in Wi-Fi scans |
| 535 | |
| 536 | Steps: |
| 537 | 1. Configure and start the sniffer on both bands. |
| 538 | 2. Perform a full scan. |
| 539 | 3. Stop the sniffer. |
| 540 | 4. Invoke scapy to read the .pcap file. |
| 541 | 5. Read each packet summary and make sure Factory MAC is not used. |
| 542 | |
| 543 | """ |
| 544 | self.pcap_procs = wutils.start_pcap( |
| 545 | self.packet_capture, 'dual', self.log_path, self.test_name) |
| 546 | wutils.start_wifi_connection_scan(self.dut) |
| 547 | time.sleep(SHORT_TIMEOUT) |
| 548 | wutils.stop_pcap(self.packet_capture, self.pcap_procs, False) |
| 549 | pcap_fname = os.path.join(self.log_path, self.test_name, |
| 550 | (self.test_name + '_2G.pcap')) |
| 551 | packets = rdpcap(pcap_fname) |
| 552 | self.verify_mac_not_found_in_pcap(self.sta_factory_mac, packets) |