1# Test cases for dynamic BSS changes with hostapd 2# Copyright (c) 2013, Qualcomm Atheros, Inc. 3# 4# This software may be distributed under the terms of the BSD license. 5# See README for more details. 6 7from remotehost import remote_compatible 8import time 9import subprocess 10import logging 11logger = logging.getLogger() 12import os 13 14import hwsim_utils 15import hostapd 16from utils import * 17from test_ap_acs import force_prev_ap_on_24g 18 19@remote_compatible 20def test_ap_change_ssid(dev, apdev): 21 """Dynamic SSID change with hostapd and WPA2-PSK""" 22 params = hostapd.wpa2_params(ssid="test-wpa2-psk-start", 23 passphrase="12345678") 24 hapd = hostapd.add_ap(apdev[0], params) 25 id = dev[0].connect("test-wpa2-psk-start", psk="12345678", 26 scan_freq="2412") 27 dev[0].request("DISCONNECT") 28 29 logger.info("Change SSID dynamically") 30 res = hapd.request("SET ssid test-wpa2-psk-new") 31 if "OK" not in res: 32 raise Exception("SET command failed") 33 res = hapd.request("RELOAD") 34 if "OK" not in res: 35 raise Exception("RELOAD command failed") 36 37 dev[0].set_network_quoted(id, "ssid", "test-wpa2-psk-new") 38 dev[0].connect_network(id) 39 40def test_ap_change_ssid_wps(dev, apdev): 41 """Dynamic SSID change with hostapd and WPA2-PSK using WPS""" 42 params = hostapd.wpa2_params(ssid="test-wpa2-psk-start", 43 passphrase="12345678") 44 # Use a PSK and not the passphrase, because the PSK will have to be computed 45 # again if we use a passphrase. 46 del params["wpa_passphrase"] 47 params["wpa_psk"] = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 48 49 params.update({"wps_state": "2", "eap_server": "1"}) 50 bssid = apdev[0]['bssid'] 51 hapd = hostapd.add_ap(apdev[0], params) 52 53 new_ssid = "test-wpa2-psk-new" 54 logger.info("Change SSID dynamically (WPS)") 55 res = hapd.request("SET ssid " + new_ssid) 56 if "OK" not in res: 57 raise Exception("SET command failed") 58 res = hapd.request("RELOAD") 59 if "OK" not in res: 60 raise Exception("RELOAD command failed") 61 62 # Connect to the new ssid using wps: 63 hapd.request("WPS_PBC") 64 if "PBC Status: Active" not in hapd.request("WPS_GET_STATUS"): 65 raise Exception("PBC status not shown correctly") 66 67 dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True) 68 dev[0].request("WPS_PBC") 69 dev[0].wait_connected(timeout=20) 70 status = dev[0].get_status() 71 if status['wpa_state'] != 'COMPLETED' or status['bssid'] != bssid: 72 raise Exception("Not fully connected") 73 if status['ssid'] != new_ssid: 74 raise Exception("Unexpected SSID %s != %s" % (status['ssid'], new_ssid)) 75 dev[0].request("DISCONNECT") 76 dev[0].wait_disconnected() 77 78def test_ap_reload_invalid(dev, apdev): 79 """hostapd RELOAD with invalid configuration""" 80 params = hostapd.wpa2_params(ssid="test-wpa2-psk-start", 81 passphrase="12345678") 82 hapd = hostapd.add_ap(apdev[0], params) 83 # Enable IEEE 802.11d without specifying country code 84 hapd.set("ieee80211d", "1") 85 if "FAIL" not in hapd.request("RELOAD"): 86 raise Exception("RELOAD command succeeded") 87 dev[0].connect("test-wpa2-psk-start", psk="12345678", scan_freq="2412") 88 89def multi_check(apdev, dev, check, scan_opt=True): 90 id = [] 91 num_bss = len(check) 92 for i in range(0, num_bss): 93 dev[i].request("BSS_FLUSH 0") 94 dev[i].dump_monitor() 95 for i in range(0, num_bss): 96 if check[i]: 97 continue 98 id.append(dev[i].connect("bss-" + str(i + 1), key_mgmt="NONE", 99 scan_freq="2412", wait_connect=False)) 100 for i in range(num_bss): 101 if not check[i]: 102 continue 103 bssid = hostapd.bssid_inc(apdev, i) 104 if scan_opt: 105 dev[i].scan_for_bss(bssid, freq=2412) 106 id.append(dev[i].connect("bss-" + str(i + 1), key_mgmt="NONE", 107 scan_freq="2412", wait_connect=True)) 108 first = True 109 for i in range(num_bss): 110 if not check[i]: 111 timeout = 0.2 if first else 0.01 112 first = False 113 ev = dev[i].wait_event(["CTRL-EVENT-CONNECTED"], timeout=timeout) 114 if ev: 115 raise Exception("Unexpected connection") 116 117 for i in range(0, num_bss): 118 dev[i].remove_network(id[i]) 119 for i in range(num_bss): 120 if check[i]: 121 dev[i].wait_disconnected(timeout=5) 122 123 res = '' 124 for i in range(0, num_bss): 125 res = res + dev[i].request("BSS RANGE=ALL MASK=0x2") 126 127 for i in range(0, num_bss): 128 if not check[i]: 129 bssid = '02:00:00:00:03:0' + str(i) 130 if bssid in res: 131 raise Exception("Unexpected BSS" + str(i) + " in scan results") 132 133def test_ap_bss_add_remove(dev, apdev): 134 """Dynamic BSS add/remove operations with hostapd""" 135 try: 136 _test_ap_bss_add_remove(dev, apdev) 137 finally: 138 for i in range(3): 139 dev[i].request("SCAN_INTERVAL 5") 140 141def _test_ap_bss_add_remove(dev, apdev): 142 for i in range(3): 143 dev[i].flush_scan_cache() 144 dev[i].request("SCAN_INTERVAL 1") 145 ifname1 = apdev[0]['ifname'] 146 ifname2 = apdev[0]['ifname'] + '-2' 147 ifname3 = apdev[0]['ifname'] + '-3' 148 logger.info("Set up three BSSes one by one") 149 hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf') 150 multi_check(apdev[0], dev, [True, False, False]) 151 hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf') 152 multi_check(apdev[0], dev, [True, True, False]) 153 hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf') 154 multi_check(apdev[0], dev, [True, True, True]) 155 156 logger.info("Remove the last BSS and re-add it") 157 hostapd.remove_bss(apdev[0], ifname3) 158 multi_check(apdev[0], dev, [True, True, False]) 159 hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf') 160 multi_check(apdev[0], dev, [True, True, True]) 161 162 logger.info("Remove the middle BSS and re-add it") 163 hostapd.remove_bss(apdev[0], ifname2) 164 multi_check(apdev[0], dev, [True, False, True]) 165 hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf') 166 multi_check(apdev[0], dev, [True, True, True]) 167 168 logger.info("Remove the first BSS and re-add it and other BSSs") 169 hostapd.remove_bss(apdev[0], ifname1) 170 multi_check(apdev[0], dev, [False, False, False]) 171 hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf') 172 hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf') 173 hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf') 174 multi_check(apdev[0], dev, [True, True, True]) 175 176 logger.info("Remove two BSSes and re-add them") 177 hostapd.remove_bss(apdev[0], ifname2) 178 multi_check(apdev[0], dev, [True, False, True]) 179 hostapd.remove_bss(apdev[0], ifname3) 180 multi_check(apdev[0], dev, [True, False, False]) 181 hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf') 182 multi_check(apdev[0], dev, [True, True, False]) 183 hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf') 184 multi_check(apdev[0], dev, [True, True, True]) 185 186 logger.info("Remove three BSSes in and re-add them") 187 hostapd.remove_bss(apdev[0], ifname3) 188 multi_check(apdev[0], dev, [True, True, False]) 189 hostapd.remove_bss(apdev[0], ifname2) 190 multi_check(apdev[0], dev, [True, False, False]) 191 hostapd.remove_bss(apdev[0], ifname1) 192 multi_check(apdev[0], dev, [False, False, False]) 193 hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf') 194 multi_check(apdev[0], dev, [True, False, False]) 195 hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf') 196 multi_check(apdev[0], dev, [True, True, False]) 197 hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf') 198 multi_check(apdev[0], dev, [True, True, True]) 199 200 logger.info("Test error handling if a duplicate ifname is tried") 201 hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf', ignore_error=True) 202 multi_check(apdev[0], dev, [True, True, True]) 203 204def test_ap_bss_add_remove_during_ht_scan(dev, apdev): 205 """Dynamic BSS add during HT40 co-ex scan""" 206 for i in range(3): 207 dev[i].flush_scan_cache() 208 ifname1 = apdev[0]['ifname'] 209 ifname2 = apdev[0]['ifname'] + '-2' 210 confname1 = hostapd.cfg_file(apdev[0], "bss-ht40-1.conf") 211 confname2 = hostapd.cfg_file(apdev[0], "bss-ht40-2.conf") 212 hapd_global = hostapd.HostapdGlobal(apdev) 213 hapd_global.send_file(confname1, confname1) 214 hapd_global.send_file(confname2, confname2) 215 hostapd.add_bss(apdev[0], ifname1, confname1) 216 hostapd.add_bss(apdev[0], ifname2, confname2) 217 multi_check(apdev[0], dev, [True, True], scan_opt=False) 218 hostapd.remove_bss(apdev[0], ifname2) 219 hostapd.remove_bss(apdev[0], ifname1) 220 221 hostapd.add_bss(apdev[0], ifname1, confname1) 222 hostapd.add_bss(apdev[0], ifname2, confname2) 223 hostapd.remove_bss(apdev[0], ifname2) 224 multi_check(apdev[0], dev, [True, False], scan_opt=False) 225 hostapd.remove_bss(apdev[0], ifname1) 226 227 hostapd.add_bss(apdev[0], ifname1, confname1) 228 hostapd.add_bss(apdev[0], ifname2, confname2) 229 hostapd.remove_bss(apdev[0], ifname1) 230 multi_check(apdev[0], dev, [False, False]) 231 232def test_ap_multi_bss_config(dev, apdev): 233 """hostapd start with a multi-BSS configuration file""" 234 for i in range(3): 235 dev[i].flush_scan_cache() 236 ifname1 = apdev[0]['ifname'] 237 ifname2 = apdev[0]['ifname'] + '-2' 238 ifname3 = apdev[0]['ifname'] + '-3' 239 logger.info("Set up three BSSes with one configuration file") 240 hapd = hostapd.add_iface(apdev[0], 'multi-bss.conf') 241 hapd.enable() 242 multi_check(apdev[0], dev, [True, True, True]) 243 hostapd.remove_bss(apdev[0], ifname2) 244 multi_check(apdev[0], dev, [True, False, True]) 245 hostapd.remove_bss(apdev[0], ifname3) 246 multi_check(apdev[0], dev, [True, False, False]) 247 hostapd.remove_bss(apdev[0], ifname1) 248 multi_check(apdev[0], dev, [False, False, False]) 249 250 hapd = hostapd.add_iface(apdev[0], 'multi-bss.conf') 251 hapd.enable() 252 hostapd.remove_bss(apdev[0], ifname1) 253 multi_check(apdev[0], dev, [False, False, False]) 254 255def invalid_ap(ap): 256 logger.info("Trying to start AP " + ap['ifname'] + " with invalid configuration") 257 hapd = hostapd.add_ap(ap, {}, no_enable=True) 258 hapd.set("ssid", "invalid-config") 259 hapd.set("channel", "12345") 260 try: 261 hapd.enable() 262 started = True 263 except Exception as e: 264 started = False 265 if started: 266 raise Exception("ENABLE command succeeded unexpectedly") 267 return hapd 268 269@remote_compatible 270def test_ap_invalid_config(dev, apdev): 271 """Try to start AP with invalid configuration and fix configuration""" 272 hapd = invalid_ap(apdev[0]) 273 274 logger.info("Fix configuration and start AP again") 275 hapd.set("channel", "1") 276 hapd.enable() 277 dev[0].connect("invalid-config", key_mgmt="NONE", scan_freq="2412") 278 279@remote_compatible 280def test_ap_invalid_config2(dev, apdev): 281 """Try to start AP with invalid configuration and remove interface""" 282 hapd = invalid_ap(apdev[0]) 283 logger.info("Remove interface with failed configuration") 284 hostapd.remove_bss(apdev[0]) 285 286def test_ap_remove_during_acs(dev, apdev): 287 """Remove interface during ACS""" 288 force_prev_ap_on_24g(apdev[0]) 289 params = hostapd.wpa2_params(ssid="test-acs-remove", passphrase="12345678") 290 params['channel'] = '0' 291 hostapd.add_ap(apdev[0], params) 292 hostapd.remove_bss(apdev[0]) 293 294def test_ap_remove_during_acs2(dev, apdev): 295 """Remove BSS during ACS in multi-BSS configuration""" 296 force_prev_ap_on_24g(apdev[0]) 297 ifname = apdev[0]['ifname'] 298 ifname2 = ifname + "-2" 299 hapd = hostapd.add_ap(apdev[0], {}, no_enable=True) 300 hapd.set("ssid", "test-acs-remove") 301 hapd.set("channel", "0") 302 hapd.set("bss", ifname2) 303 hapd.set("ssid", "test-acs-remove2") 304 hapd.enable() 305 hostapd.remove_bss(apdev[0]) 306 307def test_ap_remove_during_acs3(dev, apdev): 308 """Remove second BSS during ACS in multi-BSS configuration""" 309 force_prev_ap_on_24g(apdev[0]) 310 ifname = apdev[0]['ifname'] 311 ifname2 = ifname + "-2" 312 hapd = hostapd.add_ap(apdev[0], {}, no_enable=True) 313 hapd.set("ssid", "test-acs-remove") 314 hapd.set("channel", "0") 315 hapd.set("bss", ifname2) 316 hapd.set("ssid", "test-acs-remove2") 317 hapd.enable() 318 hostapd.remove_bss(apdev[0], ifname2) 319 320@remote_compatible 321def test_ap_remove_during_ht_coex_scan(dev, apdev): 322 """Remove interface during HT co-ex scan""" 323 params = hostapd.wpa2_params(ssid="test-ht-remove", passphrase="12345678") 324 params['channel'] = '1' 325 params['ht_capab'] = "[HT40+]" 326 ifname = apdev[0]['ifname'] 327 hostapd.add_ap(apdev[0], params) 328 hostapd.remove_bss(apdev[0]) 329 330def test_ap_remove_during_ht_coex_scan2(dev, apdev): 331 """Remove BSS during HT co-ex scan in multi-BSS configuration""" 332 ifname = apdev[0]['ifname'] 333 ifname2 = ifname + "-2" 334 hapd = hostapd.add_ap(apdev[0], {}, no_enable=True) 335 hapd.set("ssid", "test-ht-remove") 336 hapd.set("channel", "1") 337 hapd.set("ht_capab", "[HT40+]") 338 hapd.set("bss", ifname2) 339 hapd.set("ssid", "test-ht-remove2") 340 hapd.enable() 341 hostapd.remove_bss(apdev[0]) 342 343def test_ap_remove_during_ht_coex_scan3(dev, apdev): 344 """Remove second BSS during HT co-ex scan in multi-BSS configuration""" 345 ifname = apdev[0]['ifname'] 346 ifname2 = ifname + "-2" 347 hapd = hostapd.add_ap(apdev[0], {}, no_enable=True) 348 hapd.set("ssid", "test-ht-remove") 349 hapd.set("channel", "1") 350 hapd.set("ht_capab", "[HT40+]") 351 hapd.set("bss", ifname2) 352 hapd.set("ssid", "test-ht-remove2") 353 hapd.enable() 354 hostapd.remove_bss(apdev[0], ifname2) 355 356@remote_compatible 357def test_ap_enable_disable_reenable(dev, apdev): 358 """Enable, disable, re-enable AP""" 359 hapd = hostapd.add_ap(apdev[0], {}, no_enable=True) 360 hapd.set("ssid", "dynamic") 361 hapd.enable() 362 ev = hapd.wait_event(["AP-ENABLED"], timeout=30) 363 if ev is None: 364 raise Exception("AP startup timed out") 365 dev[0].connect("dynamic", key_mgmt="NONE", scan_freq="2412") 366 hapd.disable() 367 ev = hapd.wait_event(["AP-DISABLED"], timeout=30) 368 if ev is None: 369 raise Exception("AP disabling timed out") 370 dev[0].wait_disconnected(timeout=10) 371 hapd.enable() 372 ev = hapd.wait_event(["AP-ENABLED"], timeout=30) 373 if ev is None: 374 raise Exception("AP startup timed out") 375 dev[1].connect("dynamic", key_mgmt="NONE", scan_freq="2412") 376 dev[0].wait_connected(timeout=10) 377 378def test_ap_double_disable(dev, apdev): 379 """Double DISABLE regression test""" 380 hapd = hostapd.add_bss(apdev[0], apdev[0]['ifname'], 'bss-1.conf') 381 hostapd.add_bss(apdev[0], apdev[0]['ifname'] + '-2', 'bss-2.conf') 382 hapd.disable() 383 if "FAIL" not in hapd.request("DISABLE"): 384 raise Exception("Second DISABLE accepted unexpectedly") 385 hapd.enable() 386 hapd.disable() 387 if "FAIL" not in hapd.request("DISABLE"): 388 raise Exception("Second DISABLE accepted unexpectedly") 389 390def test_ap_bss_add_many(dev, apdev): 391 """Large number of BSS add operations with hostapd""" 392 try: 393 _test_ap_bss_add_many(dev, apdev) 394 finally: 395 dev[0].request("SCAN_INTERVAL 5") 396 ifname = apdev[0]['ifname'] 397 hapd = hostapd.HostapdGlobal(apdev[0]) 398 hapd.flush() 399 for i in range(16): 400 ifname2 = ifname + '-' + str(i) 401 hapd.remove(ifname2) 402 try: 403 os.remove('/tmp/hwsim-bss.conf') 404 except: 405 pass 406 407def _test_ap_bss_add_many(dev, apdev): 408 ifname = apdev[0]['ifname'] 409 hostapd.add_bss(apdev[0], ifname, 'bss-1.conf') 410 fname = '/tmp/hwsim-bss.conf' 411 for i in range(16): 412 ifname2 = ifname + '-' + str(i) 413 with open(fname, 'w') as f: 414 f.write("driver=nl80211\n") 415 f.write("hw_mode=g\n") 416 f.write("channel=1\n") 417 f.write("ieee80211n=1\n") 418 f.write("interface=%s\n" % ifname2) 419 f.write("bssid=02:00:00:00:03:%02x\n" % (i + 1)) 420 f.write("ctrl_interface=/var/run/hostapd\n") 421 f.write("ssid=test-%d\n" % i) 422 hostapd.add_bss(apdev[0], ifname2, fname) 423 os.remove(fname) 424 425 dev[0].request("SCAN_INTERVAL 1") 426 dev[0].connect("bss-1", key_mgmt="NONE", scan_freq="2412") 427 dev[0].request("DISCONNECT") 428 dev[0].wait_disconnected(timeout=5) 429 for i in range(16): 430 dev[0].connect("test-%d" % i, key_mgmt="NONE", scan_freq="2412") 431 dev[0].request("DISCONNECT") 432 dev[0].wait_disconnected(timeout=5) 433 ifname2 = ifname + '-' + str(i) 434 hostapd.remove_bss(apdev[0], ifname2) 435 436def test_ap_bss_add_reuse_existing(dev, apdev): 437 """Dynamic BSS add operation reusing existing interface""" 438 ifname1 = apdev[0]['ifname'] 439 ifname2 = apdev[0]['ifname'] + '-2' 440 hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf') 441 subprocess.check_call(["iw", "dev", ifname1, "interface", "add", ifname2, 442 "type", "__ap"]) 443 hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf') 444 hostapd.remove_bss(apdev[0], ifname2) 445 subprocess.check_call(["iw", "dev", ifname2, "del"]) 446 447def hapd_bss_out_of_mem(hapd, phy, confname, count, func): 448 with alloc_fail(hapd, count, func): 449 hapd_global = hostapd.HostapdGlobal() 450 res = hapd_global.ctrl.request("ADD bss_config=" + phy + ":" + confname) 451 if "OK" in res: 452 raise Exception("add_bss succeeded") 453 454def test_ap_bss_add_out_of_memory(dev, apdev): 455 """Running out of memory while adding a BSS""" 456 hapd2 = hostapd.add_ap(apdev[1], {"ssid": "open"}) 457 458 ifname1 = apdev[0]['ifname'] 459 ifname2 = apdev[0]['ifname'] + '-2' 460 461 confname1 = hostapd.cfg_file(apdev[0], "bss-1.conf") 462 confname2 = hostapd.cfg_file(apdev[0], "bss-2.conf") 463 hapd_bss_out_of_mem(hapd2, 'phy3', confname1, 1, 'hostapd_add_iface') 464 for i in range(1, 3): 465 hapd_bss_out_of_mem(hapd2, 'phy3', confname1, 466 i, 'hostapd_interface_init_bss') 467 hapd_bss_out_of_mem(hapd2, 'phy3', confname1, 468 1, 'ieee802_11_build_ap_params') 469 470 hostapd.add_bss(apdev[0], ifname1, confname1) 471 472 hapd_bss_out_of_mem(hapd2, 'phy3', confname2, 473 1, 'hostapd_interface_init_bss') 474 hapd_bss_out_of_mem(hapd2, 'phy3', confname2, 475 1, 'ieee802_11_build_ap_params') 476 477 hostapd.add_bss(apdev[0], ifname2, confname2) 478 hostapd.remove_bss(apdev[0], ifname2) 479 hostapd.remove_bss(apdev[0], ifname1) 480 481def test_ap_multi_bss(dev, apdev): 482 """Multiple BSSes with hostapd""" 483 ifname1 = apdev[0]['ifname'] 484 ifname2 = apdev[0]['ifname'] + '-2' 485 hapd1 = hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf') 486 hapd2 = hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf') 487 dev[0].connect("bss-1", key_mgmt="NONE", scan_freq="2412") 488 dev[1].connect("bss-2", key_mgmt="NONE", scan_freq="2412") 489 490 hwsim_utils.test_connectivity(dev[0], hapd1) 491 hwsim_utils.test_connectivity(dev[1], hapd2) 492 493 sta0 = hapd1.get_sta(dev[0].own_addr()) 494 sta1 = hapd2.get_sta(dev[1].own_addr()) 495 if 'rx_packets' not in sta0 or int(sta0['rx_packets']) < 1: 496 raise Exception("sta0 did not report receiving packets") 497 if 'rx_packets' not in sta1 or int(sta1['rx_packets']) < 1: 498 raise Exception("sta1 did not report receiving packets") 499 500@remote_compatible 501def test_ap_add_with_driver(dev, apdev): 502 """Add hostapd interface with driver specified""" 503 ifname = apdev[0]['ifname'] 504 try: 505 hostname = apdev[0]['hostname'] 506 except: 507 hostname = None 508 hapd_global = hostapd.HostapdGlobal(apdev[0]) 509 hapd_global.add(ifname, driver="nl80211") 510 port = hapd_global.get_ctrl_iface_port(ifname) 511 hapd = hostapd.Hostapd(ifname, hostname, port) 512 hapd.set_defaults() 513 hapd.set("ssid", "dynamic") 514 hapd.enable() 515 ev = hapd.wait_event(["AP-ENABLED"], timeout=30) 516 if ev is None: 517 raise Exception("AP startup timed out") 518 dev[0].connect("dynamic", key_mgmt="NONE", scan_freq="2412") 519 dev[0].request("DISCONNECT") 520 dev[0].wait_disconnected() 521 hapd.disable() 522 523def test_ap_duplicate_bssid(dev, apdev): 524 """Duplicate BSSID""" 525 params = {"ssid": "test"} 526 hapd = hostapd.add_ap(apdev[0], params, no_enable=True) 527 hapd.enable() 528 ifname2 = apdev[0]['ifname'] + '-2' 529 ifname3 = apdev[0]['ifname'] + '-3' 530 # "BSS 'wlan3-2' may not have BSSID set to the MAC address of the radio" 531 try: 532 hostapd.add_bss(apdev[0], ifname2, 'bss-2-dup.conf') 533 raise Exception("BSS add succeeded unexpectedly") 534 except Exception as e: 535 if "Could not add hostapd BSS" in str(e): 536 pass 537 else: 538 raise 539 540 hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf') 541 542 dev[0].connect("test", key_mgmt="NONE", scan_freq="2412") 543 dev[0].request("DISCONNECT") 544 dev[0].wait_disconnected() 545 546 hapd.set("bssid", "02:00:00:00:03:02") 547 hapd.disable() 548 # "Duplicate BSSID 02:00:00:00:03:02 on interface 'wlan3-3' and 'wlan3'." 549 if "FAIL" not in hapd.request("ENABLE"): 550 raise Exception("ENABLE with duplicate BSSID succeeded unexpectedly") 551 552def test_ap_bss_config_file(dev, apdev, params): 553 """hostapd BSS config file""" 554 pidfile = params['prefix'] + ".hostapd.pid" 555 logfile = params['prefix'] + ".hostapd-log" 556 prg = os.path.join(params['logdir'], 'alt-hostapd/hostapd/hostapd') 557 if not os.path.exists(prg): 558 prg = '../../hostapd/hostapd' 559 phy = get_phy(apdev[0]) 560 confname1 = hostapd.cfg_file(apdev[0], "bss-1.conf") 561 confname2 = hostapd.cfg_file(apdev[0], "bss-2.conf") 562 confname3 = hostapd.cfg_file(apdev[0], "bss-3.conf") 563 564 cmd = [prg, '-B', '-dddt', '-P', pidfile, '-f', logfile, '-S', '-T', 565 '-b', phy + ':' + confname1, '-b', phy + ':' + confname2, 566 '-b', phy + ':' + confname3] 567 res = subprocess.check_call(cmd) 568 if res != 0: 569 raise Exception("Could not start hostapd: %s" % str(res)) 570 multi_check(apdev[0], dev, [True, True, True]) 571 for i in range(0, 3): 572 dev[i].request("DISCONNECT") 573 574 hapd = hostapd.Hostapd(apdev[0]['ifname']) 575 hapd.ping() 576 if "OK" not in hapd.request("TERMINATE"): 577 raise Exception("Failed to terminate hostapd process") 578 ev = hapd.wait_event(["CTRL-EVENT-TERMINATING"], timeout=15) 579 if ev is None: 580 raise Exception("CTRL-EVENT-TERMINATING not seen") 581 for i in range(30): 582 time.sleep(0.1) 583 if not os.path.exists(pidfile): 584 break 585 if os.path.exists(pidfile): 586 raise Exception("PID file exits after process termination") 587 588def test_ap_reload_bss_only(dev, apdev, params): 589 """Dynamic SSID change on only one BSS using RELOAD_BSS""" 590 ifname1 = apdev[0]['ifname'] 591 ifname2 = apdev[0]['ifname'] + '-2' 592 hapd1 = hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf') 593 hapd2 = hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf') 594 id = dev[0].connect("bss-1", key_mgmt="NONE", scan_freq="2412") 595 dev[1].connect("bss-2", key_mgmt="NONE", scan_freq="2412") 596 597 res = hapd1.request("SET ssid test-new-ssid") 598 if "OK" not in res: 599 raise Exception("SET command failed") 600 res = hapd1.request("RELOAD_BSS") 601 if "OK" not in res: 602 raise Exception("RELOAD_BSS command failed") 603 604 ev = dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1) 605 if ev is not None: 606 raise Exception("Unexpected disconnection when RELOAD_BSS was sent on another BSS.") 607 608 dev[0].set_network_quoted(id, "ssid", "test-new-ssid") 609 dev[0].connect_network(id) 610