2013-10-29 16:14:02 +01:00
|
|
|
# Test cases for dynamic BSS changes with hostapd
|
|
|
|
# Copyright (c) 2013, Qualcomm Atheros, Inc.
|
|
|
|
#
|
|
|
|
# This software may be distributed under the terms of the BSD license.
|
|
|
|
# See README for more details.
|
|
|
|
|
2016-06-23 19:16:36 +02:00
|
|
|
from remotehost import remote_compatible
|
2013-10-29 16:14:02 +01:00
|
|
|
import time
|
|
|
|
import subprocess
|
|
|
|
import logging
|
2013-10-31 11:46:42 +01:00
|
|
|
logger = logging.getLogger()
|
2014-12-20 16:13:00 +01:00
|
|
|
import os
|
2013-10-29 16:14:02 +01:00
|
|
|
|
|
|
|
import hwsim_utils
|
|
|
|
import hostapd
|
2020-04-18 10:00:49 +02:00
|
|
|
from utils import *
|
2015-03-06 22:22:53 +01:00
|
|
|
from test_ap_acs import force_prev_ap_on_24g
|
2013-10-29 16:14:02 +01:00
|
|
|
|
2016-06-23 19:16:36 +02:00
|
|
|
@remote_compatible
|
2013-10-29 16:14:02 +01:00
|
|
|
def test_ap_change_ssid(dev, apdev):
|
|
|
|
"""Dynamic SSID change with hostapd and WPA2-PSK"""
|
|
|
|
params = hostapd.wpa2_params(ssid="test-wpa2-psk-start",
|
|
|
|
passphrase="12345678")
|
2016-04-07 07:38:07 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
2013-11-02 10:22:16 +01:00
|
|
|
id = dev[0].connect("test-wpa2-psk-start", psk="12345678",
|
|
|
|
scan_freq="2412")
|
2013-10-29 16:14:02 +01:00
|
|
|
dev[0].request("DISCONNECT")
|
|
|
|
|
|
|
|
logger.info("Change SSID dynamically")
|
|
|
|
res = hapd.request("SET ssid test-wpa2-psk-new")
|
|
|
|
if "OK" not in res:
|
|
|
|
raise Exception("SET command failed")
|
|
|
|
res = hapd.request("RELOAD")
|
|
|
|
if "OK" not in res:
|
|
|
|
raise Exception("RELOAD command failed")
|
|
|
|
|
|
|
|
dev[0].set_network_quoted(id, "ssid", "test-wpa2-psk-new")
|
|
|
|
dev[0].connect_network(id)
|
2013-10-31 16:28:43 +01:00
|
|
|
|
2020-12-18 11:50:28 +01:00
|
|
|
def test_ap_change_ssid_wps(dev, apdev):
|
|
|
|
"""Dynamic SSID change with hostapd and WPA2-PSK using WPS"""
|
|
|
|
params = hostapd.wpa2_params(ssid="test-wpa2-psk-start",
|
|
|
|
passphrase="12345678")
|
|
|
|
# Use a PSK and not the passphrase, because the PSK will have to be computed
|
|
|
|
# again if we use a passphrase.
|
|
|
|
del params["wpa_passphrase"]
|
|
|
|
params["wpa_psk"] = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
|
|
|
|
|
|
|
|
params.update({"wps_state": "2", "eap_server": "1"})
|
|
|
|
bssid = apdev[0]['bssid']
|
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
|
|
|
|
|
|
|
new_ssid = "test-wpa2-psk-new"
|
|
|
|
logger.info("Change SSID dynamically (WPS)")
|
|
|
|
res = hapd.request("SET ssid " + new_ssid)
|
|
|
|
if "OK" not in res:
|
|
|
|
raise Exception("SET command failed")
|
|
|
|
res = hapd.request("RELOAD")
|
|
|
|
if "OK" not in res:
|
|
|
|
raise Exception("RELOAD command failed")
|
|
|
|
|
|
|
|
# Connect to the new ssid using wps:
|
|
|
|
hapd.request("WPS_PBC")
|
|
|
|
if "PBC Status: Active" not in hapd.request("WPS_GET_STATUS"):
|
|
|
|
raise Exception("PBC status not shown correctly")
|
|
|
|
|
|
|
|
dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True)
|
|
|
|
dev[0].request("WPS_PBC")
|
|
|
|
dev[0].wait_connected(timeout=20)
|
|
|
|
status = dev[0].get_status()
|
|
|
|
if status['wpa_state'] != 'COMPLETED' or status['bssid'] != bssid:
|
|
|
|
raise Exception("Not fully connected")
|
|
|
|
if status['ssid'] != new_ssid:
|
|
|
|
raise Exception("Unexpected SSID %s != %s" % (status['ssid'], new_ssid))
|
|
|
|
dev[0].request("DISCONNECT")
|
|
|
|
dev[0].wait_disconnected()
|
|
|
|
|
2021-03-01 10:13:46 +01:00
|
|
|
def test_ap_reload_invalid(dev, apdev):
|
|
|
|
"""hostapd RELOAD with invalid configuration"""
|
|
|
|
params = hostapd.wpa2_params(ssid="test-wpa2-psk-start",
|
|
|
|
passphrase="12345678")
|
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
|
|
|
# Enable IEEE 802.11d without specifying country code
|
|
|
|
hapd.set("ieee80211d", "1")
|
|
|
|
if "FAIL" not in hapd.request("RELOAD"):
|
|
|
|
raise Exception("RELOAD command succeeded")
|
|
|
|
dev[0].connect("test-wpa2-psk-start", psk="12345678", scan_freq="2412")
|
|
|
|
|
2020-01-12 23:02:25 +01:00
|
|
|
def multi_check(apdev, dev, check, scan_opt=True):
|
2013-11-02 12:53:23 +01:00
|
|
|
id = []
|
2013-11-06 14:52:40 +01:00
|
|
|
num_bss = len(check)
|
|
|
|
for i in range(0, num_bss):
|
2013-11-02 12:53:23 +01:00
|
|
|
dev[i].request("BSS_FLUSH 0")
|
|
|
|
dev[i].dump_monitor()
|
2013-11-06 14:52:40 +01:00
|
|
|
for i in range(0, num_bss):
|
2014-12-23 16:20:18 +01:00
|
|
|
if check[i]:
|
|
|
|
continue
|
|
|
|
id.append(dev[i].connect("bss-" + str(i + 1), key_mgmt="NONE",
|
|
|
|
scan_freq="2412", wait_connect=False))
|
|
|
|
for i in range(num_bss):
|
2013-11-02 12:53:23 +01:00
|
|
|
if not check[i]:
|
2014-12-23 16:20:18 +01:00
|
|
|
continue
|
2020-01-12 23:02:25 +01:00
|
|
|
bssid = hostapd.bssid_inc(apdev, i)
|
2015-01-22 21:38:38 +01:00
|
|
|
if scan_opt:
|
|
|
|
dev[i].scan_for_bss(bssid, freq=2412)
|
2014-12-23 16:20:18 +01:00
|
|
|
id.append(dev[i].connect("bss-" + str(i + 1), key_mgmt="NONE",
|
|
|
|
scan_freq="2412", wait_connect=True))
|
|
|
|
first = True
|
|
|
|
for i in range(num_bss):
|
|
|
|
if not check[i]:
|
2019-03-15 11:10:37 +01:00
|
|
|
timeout = 0.2 if first else 0.01
|
2014-12-23 16:20:18 +01:00
|
|
|
first = False
|
|
|
|
ev = dev[i].wait_event(["CTRL-EVENT-CONNECTED"], timeout=timeout)
|
2013-11-02 12:53:23 +01:00
|
|
|
if ev:
|
|
|
|
raise Exception("Unexpected connection")
|
|
|
|
|
2013-11-06 14:52:40 +01:00
|
|
|
for i in range(0, num_bss):
|
2013-11-02 12:53:23 +01:00
|
|
|
dev[i].remove_network(id[i])
|
2014-12-23 16:20:18 +01:00
|
|
|
for i in range(num_bss):
|
|
|
|
if check[i]:
|
|
|
|
dev[i].wait_disconnected(timeout=5)
|
2013-10-31 16:28:43 +01:00
|
|
|
|
2013-11-02 12:53:23 +01:00
|
|
|
res = ''
|
2013-11-06 14:52:40 +01:00
|
|
|
for i in range(0, num_bss):
|
2013-11-02 12:53:23 +01:00
|
|
|
res = res + dev[i].request("BSS RANGE=ALL MASK=0x2")
|
2013-10-31 16:28:43 +01:00
|
|
|
|
2013-11-06 14:52:40 +01:00
|
|
|
for i in range(0, num_bss):
|
2013-11-02 12:53:23 +01:00
|
|
|
if not check[i]:
|
|
|
|
bssid = '02:00:00:00:03:0' + str(i)
|
|
|
|
if bssid in res:
|
|
|
|
raise Exception("Unexpected BSS" + str(i) + " in scan results")
|
2013-10-31 16:28:43 +01:00
|
|
|
|
|
|
|
def test_ap_bss_add_remove(dev, apdev):
|
|
|
|
"""Dynamic BSS add/remove operations with hostapd"""
|
2015-01-22 21:38:38 +01:00
|
|
|
try:
|
|
|
|
_test_ap_bss_add_remove(dev, apdev)
|
|
|
|
finally:
|
|
|
|
for i in range(3):
|
|
|
|
dev[i].request("SCAN_INTERVAL 5")
|
|
|
|
|
|
|
|
def _test_ap_bss_add_remove(dev, apdev):
|
|
|
|
for i in range(3):
|
2015-12-04 20:03:43 +01:00
|
|
|
dev[i].flush_scan_cache()
|
2015-01-22 21:38:38 +01:00
|
|
|
dev[i].request("SCAN_INTERVAL 1")
|
2013-10-31 16:28:43 +01:00
|
|
|
ifname1 = apdev[0]['ifname']
|
|
|
|
ifname2 = apdev[0]['ifname'] + '-2'
|
|
|
|
ifname3 = apdev[0]['ifname'] + '-3'
|
|
|
|
logger.info("Set up three BSSes one by one")
|
2016-04-07 07:38:02 +02:00
|
|
|
hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, False, False])
|
2016-04-07 07:38:02 +02:00
|
|
|
hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, True, False])
|
2016-04-07 07:38:02 +02:00
|
|
|
hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf')
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, True, True])
|
2013-10-31 16:28:43 +01:00
|
|
|
|
|
|
|
logger.info("Remove the last BSS and re-add it")
|
2016-04-07 07:37:59 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname3)
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, True, False])
|
2016-04-07 07:38:02 +02:00
|
|
|
hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf')
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, True, True])
|
2013-10-31 16:28:43 +01:00
|
|
|
|
|
|
|
logger.info("Remove the middle BSS and re-add it")
|
2016-04-07 07:37:59 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname2)
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, False, True])
|
2016-04-07 07:38:02 +02:00
|
|
|
hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, True, True])
|
2013-10-31 16:28:43 +01:00
|
|
|
|
2013-11-06 00:08:54 +01:00
|
|
|
logger.info("Remove the first BSS and re-add it and other BSSs")
|
2016-04-07 07:37:59 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname1)
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [False, False, False])
|
2016-04-07 07:38:02 +02:00
|
|
|
hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
|
|
|
|
hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
|
|
|
|
hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf')
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, True, True])
|
2013-10-31 16:28:43 +01:00
|
|
|
|
2013-11-06 00:08:54 +01:00
|
|
|
logger.info("Remove two BSSes and re-add them")
|
2016-04-07 07:37:59 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname2)
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, False, True])
|
2016-04-07 07:37:59 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname3)
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, False, False])
|
2016-04-07 07:38:02 +02:00
|
|
|
hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, True, False])
|
2016-04-07 07:38:02 +02:00
|
|
|
hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf')
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, True, True])
|
2013-10-31 16:28:43 +01:00
|
|
|
|
2013-11-06 00:08:54 +01:00
|
|
|
logger.info("Remove three BSSes in and re-add them")
|
2016-04-07 07:37:59 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname3)
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, True, False])
|
2016-04-07 07:37:59 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname2)
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, False, False])
|
2016-04-07 07:37:59 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname1)
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [False, False, False])
|
2016-04-07 07:38:02 +02:00
|
|
|
hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, False, False])
|
2016-04-07 07:38:02 +02:00
|
|
|
hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, True, False])
|
2016-04-07 07:38:02 +02:00
|
|
|
hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf')
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, True, True])
|
2013-10-31 16:28:43 +01:00
|
|
|
|
|
|
|
logger.info("Test error handling if a duplicate ifname is tried")
|
2016-04-07 07:38:02 +02:00
|
|
|
hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf', ignore_error=True)
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, True, True])
|
2013-11-02 18:57:35 +01:00
|
|
|
|
2013-11-06 14:52:40 +01:00
|
|
|
def test_ap_bss_add_remove_during_ht_scan(dev, apdev):
|
|
|
|
"""Dynamic BSS add during HT40 co-ex scan"""
|
2015-12-04 20:03:43 +01:00
|
|
|
for i in range(3):
|
|
|
|
dev[i].flush_scan_cache()
|
2013-11-06 14:52:40 +01:00
|
|
|
ifname1 = apdev[0]['ifname']
|
|
|
|
ifname2 = apdev[0]['ifname'] + '-2'
|
2020-02-23 16:13:04 +01:00
|
|
|
confname1 = hostapd.cfg_file(apdev[0], "bss-ht40-1.conf")
|
|
|
|
confname2 = hostapd.cfg_file(apdev[0], "bss-ht40-2.conf")
|
|
|
|
hapd_global = hostapd.HostapdGlobal(apdev)
|
|
|
|
hapd_global.send_file(confname1, confname1)
|
|
|
|
hapd_global.send_file(confname2, confname2)
|
|
|
|
hostapd.add_bss(apdev[0], ifname1, confname1)
|
|
|
|
hostapd.add_bss(apdev[0], ifname2, confname2)
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, True], scan_opt=False)
|
2016-04-07 07:37:59 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname2)
|
|
|
|
hostapd.remove_bss(apdev[0], ifname1)
|
2013-11-06 14:52:40 +01:00
|
|
|
|
2020-02-23 16:13:04 +01:00
|
|
|
hostapd.add_bss(apdev[0], ifname1, confname1)
|
|
|
|
hostapd.add_bss(apdev[0], ifname2, confname2)
|
2016-04-07 07:37:59 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname2)
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, False], scan_opt=False)
|
2016-04-07 07:37:59 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname1)
|
2013-11-06 14:52:40 +01:00
|
|
|
|
2020-02-23 16:13:04 +01:00
|
|
|
hostapd.add_bss(apdev[0], ifname1, confname1)
|
|
|
|
hostapd.add_bss(apdev[0], ifname2, confname2)
|
2016-04-07 07:37:59 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname1)
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [False, False])
|
2013-11-06 14:52:40 +01:00
|
|
|
|
2013-11-03 19:20:50 +01:00
|
|
|
def test_ap_multi_bss_config(dev, apdev):
|
|
|
|
"""hostapd start with a multi-BSS configuration file"""
|
2015-12-04 20:03:43 +01:00
|
|
|
for i in range(3):
|
|
|
|
dev[i].flush_scan_cache()
|
2013-11-03 19:20:50 +01:00
|
|
|
ifname1 = apdev[0]['ifname']
|
|
|
|
ifname2 = apdev[0]['ifname'] + '-2'
|
|
|
|
ifname3 = apdev[0]['ifname'] + '-3'
|
|
|
|
logger.info("Set up three BSSes with one configuration file")
|
2016-04-07 07:38:06 +02:00
|
|
|
hapd = hostapd.add_iface(apdev[0], 'multi-bss.conf')
|
2013-11-03 19:20:50 +01:00
|
|
|
hapd.enable()
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, True, True])
|
2016-04-07 07:37:59 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname2)
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, False, True])
|
2016-04-07 07:37:59 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname3)
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, False, False])
|
2016-04-07 07:37:59 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname1)
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [False, False, False])
|
2013-11-06 00:08:54 +01:00
|
|
|
|
2016-04-07 07:38:06 +02:00
|
|
|
hapd = hostapd.add_iface(apdev[0], 'multi-bss.conf')
|
2013-11-06 00:08:54 +01:00
|
|
|
hapd.enable()
|
2016-04-07 07:37:59 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname1)
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [False, False, False])
|
2013-11-03 19:20:50 +01:00
|
|
|
|
2016-04-07 07:38:05 +02:00
|
|
|
def invalid_ap(ap):
|
|
|
|
logger.info("Trying to start AP " + ap['ifname'] + " with invalid configuration")
|
|
|
|
hapd = hostapd.add_ap(ap, {}, no_enable=True)
|
2013-11-02 18:57:35 +01:00
|
|
|
hapd.set("ssid", "invalid-config")
|
|
|
|
hapd.set("channel", "12345")
|
|
|
|
try:
|
|
|
|
hapd.enable()
|
|
|
|
started = True
|
2019-01-24 08:45:41 +01:00
|
|
|
except Exception as e:
|
2013-11-02 18:57:35 +01:00
|
|
|
started = False
|
|
|
|
if started:
|
|
|
|
raise Exception("ENABLE command succeeded unexpectedly")
|
|
|
|
return hapd
|
|
|
|
|
2016-06-23 19:16:36 +02:00
|
|
|
@remote_compatible
|
2013-11-02 18:57:35 +01:00
|
|
|
def test_ap_invalid_config(dev, apdev):
|
|
|
|
"""Try to start AP with invalid configuration and fix configuration"""
|
2016-04-07 07:38:05 +02:00
|
|
|
hapd = invalid_ap(apdev[0])
|
2013-11-02 18:57:35 +01:00
|
|
|
|
|
|
|
logger.info("Fix configuration and start AP again")
|
|
|
|
hapd.set("channel", "1")
|
|
|
|
hapd.enable()
|
|
|
|
dev[0].connect("invalid-config", key_mgmt="NONE", scan_freq="2412")
|
|
|
|
|
2016-06-23 19:16:36 +02:00
|
|
|
@remote_compatible
|
2013-11-02 18:57:35 +01:00
|
|
|
def test_ap_invalid_config2(dev, apdev):
|
|
|
|
"""Try to start AP with invalid configuration and remove interface"""
|
2016-04-07 07:38:05 +02:00
|
|
|
hapd = invalid_ap(apdev[0])
|
2013-11-02 18:57:35 +01:00
|
|
|
logger.info("Remove interface with failed configuration")
|
2016-04-07 07:38:05 +02:00
|
|
|
hostapd.remove_bss(apdev[0])
|
2013-11-06 00:11:25 +01:00
|
|
|
|
|
|
|
def test_ap_remove_during_acs(dev, apdev):
|
|
|
|
"""Remove interface during ACS"""
|
2015-03-06 22:22:53 +01:00
|
|
|
force_prev_ap_on_24g(apdev[0])
|
2013-11-06 00:11:25 +01:00
|
|
|
params = hostapd.wpa2_params(ssid="test-acs-remove", passphrase="12345678")
|
|
|
|
params['channel'] = '0'
|
2016-03-30 10:55:56 +02:00
|
|
|
hostapd.add_ap(apdev[0], params)
|
2016-04-07 07:38:05 +02:00
|
|
|
hostapd.remove_bss(apdev[0])
|
2013-11-06 00:11:25 +01:00
|
|
|
|
|
|
|
def test_ap_remove_during_acs2(dev, apdev):
|
|
|
|
"""Remove BSS during ACS in multi-BSS configuration"""
|
2015-03-06 22:22:53 +01:00
|
|
|
force_prev_ap_on_24g(apdev[0])
|
2013-11-06 00:11:25 +01:00
|
|
|
ifname = apdev[0]['ifname']
|
|
|
|
ifname2 = ifname + "-2"
|
2016-04-07 07:38:05 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], {}, no_enable=True)
|
2013-11-06 00:11:25 +01:00
|
|
|
hapd.set("ssid", "test-acs-remove")
|
|
|
|
hapd.set("channel", "0")
|
|
|
|
hapd.set("bss", ifname2)
|
|
|
|
hapd.set("ssid", "test-acs-remove2")
|
|
|
|
hapd.enable()
|
2016-04-07 07:38:05 +02:00
|
|
|
hostapd.remove_bss(apdev[0])
|
2013-11-06 00:11:25 +01:00
|
|
|
|
|
|
|
def test_ap_remove_during_acs3(dev, apdev):
|
|
|
|
"""Remove second BSS during ACS in multi-BSS configuration"""
|
2015-03-06 22:22:53 +01:00
|
|
|
force_prev_ap_on_24g(apdev[0])
|
2013-11-06 00:11:25 +01:00
|
|
|
ifname = apdev[0]['ifname']
|
|
|
|
ifname2 = ifname + "-2"
|
2016-04-07 07:38:05 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], {}, no_enable=True)
|
2013-11-06 00:11:25 +01:00
|
|
|
hapd.set("ssid", "test-acs-remove")
|
|
|
|
hapd.set("channel", "0")
|
|
|
|
hapd.set("bss", ifname2)
|
|
|
|
hapd.set("ssid", "test-acs-remove2")
|
|
|
|
hapd.enable()
|
2016-04-07 07:38:05 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname2)
|
2013-11-06 00:11:25 +01:00
|
|
|
|
2016-06-23 19:16:36 +02:00
|
|
|
@remote_compatible
|
2013-11-06 00:11:25 +01:00
|
|
|
def test_ap_remove_during_ht_coex_scan(dev, apdev):
|
|
|
|
"""Remove interface during HT co-ex scan"""
|
|
|
|
params = hostapd.wpa2_params(ssid="test-ht-remove", passphrase="12345678")
|
|
|
|
params['channel'] = '1'
|
|
|
|
params['ht_capab'] = "[HT40+]"
|
|
|
|
ifname = apdev[0]['ifname']
|
2016-03-30 10:55:56 +02:00
|
|
|
hostapd.add_ap(apdev[0], params)
|
2016-04-07 07:38:05 +02:00
|
|
|
hostapd.remove_bss(apdev[0])
|
2013-11-06 00:11:25 +01:00
|
|
|
|
|
|
|
def test_ap_remove_during_ht_coex_scan2(dev, apdev):
|
|
|
|
"""Remove BSS during HT co-ex scan in multi-BSS configuration"""
|
|
|
|
ifname = apdev[0]['ifname']
|
|
|
|
ifname2 = ifname + "-2"
|
2016-04-07 07:38:05 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], {}, no_enable=True)
|
2013-11-06 00:11:25 +01:00
|
|
|
hapd.set("ssid", "test-ht-remove")
|
|
|
|
hapd.set("channel", "1")
|
|
|
|
hapd.set("ht_capab", "[HT40+]")
|
|
|
|
hapd.set("bss", ifname2)
|
|
|
|
hapd.set("ssid", "test-ht-remove2")
|
|
|
|
hapd.enable()
|
2016-04-07 07:38:05 +02:00
|
|
|
hostapd.remove_bss(apdev[0])
|
2013-11-06 00:11:25 +01:00
|
|
|
|
|
|
|
def test_ap_remove_during_ht_coex_scan3(dev, apdev):
|
|
|
|
"""Remove second BSS during HT co-ex scan in multi-BSS configuration"""
|
|
|
|
ifname = apdev[0]['ifname']
|
|
|
|
ifname2 = ifname + "-2"
|
2016-04-07 07:38:05 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], {}, no_enable=True)
|
2013-11-06 00:11:25 +01:00
|
|
|
hapd.set("ssid", "test-ht-remove")
|
|
|
|
hapd.set("channel", "1")
|
|
|
|
hapd.set("ht_capab", "[HT40+]")
|
|
|
|
hapd.set("bss", ifname2)
|
|
|
|
hapd.set("ssid", "test-ht-remove2")
|
|
|
|
hapd.enable()
|
2016-04-07 07:38:05 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname2)
|
2014-03-13 19:41:54 +01:00
|
|
|
|
2016-06-23 19:16:36 +02:00
|
|
|
@remote_compatible
|
2014-03-13 19:41:54 +01:00
|
|
|
def test_ap_enable_disable_reenable(dev, apdev):
|
|
|
|
"""Enable, disable, re-enable AP"""
|
2016-04-07 07:38:05 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], {}, no_enable=True)
|
2014-03-13 19:41:54 +01:00
|
|
|
hapd.set("ssid", "dynamic")
|
|
|
|
hapd.enable()
|
|
|
|
ev = hapd.wait_event(["AP-ENABLED"], timeout=30)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("AP startup timed out")
|
|
|
|
dev[0].connect("dynamic", key_mgmt="NONE", scan_freq="2412")
|
|
|
|
hapd.disable()
|
|
|
|
ev = hapd.wait_event(["AP-DISABLED"], timeout=30)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("AP disabling timed out")
|
2014-12-20 10:51:30 +01:00
|
|
|
dev[0].wait_disconnected(timeout=10)
|
2014-03-13 19:41:54 +01:00
|
|
|
hapd.enable()
|
|
|
|
ev = hapd.wait_event(["AP-ENABLED"], timeout=30)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("AP startup timed out")
|
|
|
|
dev[1].connect("dynamic", key_mgmt="NONE", scan_freq="2412")
|
2014-12-20 10:51:30 +01:00
|
|
|
dev[0].wait_connected(timeout=10)
|
2014-05-31 16:15:41 +02:00
|
|
|
|
|
|
|
def test_ap_double_disable(dev, apdev):
|
|
|
|
"""Double DISABLE regression test"""
|
2016-04-07 07:38:07 +02:00
|
|
|
hapd = hostapd.add_bss(apdev[0], apdev[0]['ifname'], 'bss-1.conf')
|
2016-04-07 07:38:02 +02:00
|
|
|
hostapd.add_bss(apdev[0], apdev[0]['ifname'] + '-2', 'bss-2.conf')
|
2014-05-31 16:15:41 +02:00
|
|
|
hapd.disable()
|
|
|
|
if "FAIL" not in hapd.request("DISABLE"):
|
|
|
|
raise Exception("Second DISABLE accepted unexpectedly")
|
|
|
|
hapd.enable()
|
|
|
|
hapd.disable()
|
|
|
|
if "FAIL" not in hapd.request("DISABLE"):
|
|
|
|
raise Exception("Second DISABLE accepted unexpectedly")
|
2014-12-20 16:13:00 +01:00
|
|
|
|
|
|
|
def test_ap_bss_add_many(dev, apdev):
|
|
|
|
"""Large number of BSS add operations with hostapd"""
|
|
|
|
try:
|
|
|
|
_test_ap_bss_add_many(dev, apdev)
|
|
|
|
finally:
|
|
|
|
dev[0].request("SCAN_INTERVAL 5")
|
|
|
|
ifname = apdev[0]['ifname']
|
2016-04-07 07:38:05 +02:00
|
|
|
hapd = hostapd.HostapdGlobal(apdev[0])
|
2014-12-20 16:13:00 +01:00
|
|
|
hapd.flush()
|
|
|
|
for i in range(16):
|
|
|
|
ifname2 = ifname + '-' + str(i)
|
|
|
|
hapd.remove(ifname2)
|
|
|
|
try:
|
|
|
|
os.remove('/tmp/hwsim-bss.conf')
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def _test_ap_bss_add_many(dev, apdev):
|
|
|
|
ifname = apdev[0]['ifname']
|
2016-04-07 07:38:02 +02:00
|
|
|
hostapd.add_bss(apdev[0], ifname, 'bss-1.conf')
|
2014-12-20 16:13:00 +01:00
|
|
|
fname = '/tmp/hwsim-bss.conf'
|
|
|
|
for i in range(16):
|
|
|
|
ifname2 = ifname + '-' + str(i)
|
|
|
|
with open(fname, 'w') as f:
|
|
|
|
f.write("driver=nl80211\n")
|
|
|
|
f.write("hw_mode=g\n")
|
|
|
|
f.write("channel=1\n")
|
|
|
|
f.write("ieee80211n=1\n")
|
|
|
|
f.write("interface=%s\n" % ifname2)
|
|
|
|
f.write("bssid=02:00:00:00:03:%02x\n" % (i + 1))
|
|
|
|
f.write("ctrl_interface=/var/run/hostapd\n")
|
|
|
|
f.write("ssid=test-%d\n" % i)
|
2016-04-07 07:38:02 +02:00
|
|
|
hostapd.add_bss(apdev[0], ifname2, fname)
|
2014-12-20 16:13:00 +01:00
|
|
|
os.remove(fname)
|
|
|
|
|
|
|
|
dev[0].request("SCAN_INTERVAL 1")
|
|
|
|
dev[0].connect("bss-1", key_mgmt="NONE", scan_freq="2412")
|
|
|
|
dev[0].request("DISCONNECT")
|
|
|
|
dev[0].wait_disconnected(timeout=5)
|
|
|
|
for i in range(16):
|
|
|
|
dev[0].connect("test-%d" % i, key_mgmt="NONE", scan_freq="2412")
|
|
|
|
dev[0].request("DISCONNECT")
|
|
|
|
dev[0].wait_disconnected(timeout=5)
|
|
|
|
ifname2 = ifname + '-' + str(i)
|
2016-04-07 07:38:05 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname2)
|
2014-12-20 18:04:18 +01:00
|
|
|
|
|
|
|
def test_ap_bss_add_reuse_existing(dev, apdev):
|
|
|
|
"""Dynamic BSS add operation reusing existing interface"""
|
|
|
|
ifname1 = apdev[0]['ifname']
|
|
|
|
ifname2 = apdev[0]['ifname'] + '-2'
|
2016-04-07 07:38:02 +02:00
|
|
|
hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
|
2014-12-20 18:04:18 +01:00
|
|
|
subprocess.check_call(["iw", "dev", ifname1, "interface", "add", ifname2,
|
|
|
|
"type", "__ap"])
|
2016-04-07 07:38:02 +02:00
|
|
|
hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
|
2016-04-07 07:37:59 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname2)
|
2014-12-20 18:04:18 +01:00
|
|
|
subprocess.check_call(["iw", "dev", ifname2, "del"])
|
2015-01-06 01:38:26 +01:00
|
|
|
|
|
|
|
def hapd_bss_out_of_mem(hapd, phy, confname, count, func):
|
|
|
|
with alloc_fail(hapd, count, func):
|
|
|
|
hapd_global = hostapd.HostapdGlobal()
|
|
|
|
res = hapd_global.ctrl.request("ADD bss_config=" + phy + ":" + confname)
|
|
|
|
if "OK" in res:
|
|
|
|
raise Exception("add_bss succeeded")
|
|
|
|
|
|
|
|
def test_ap_bss_add_out_of_memory(dev, apdev):
|
|
|
|
"""Running out of memory while adding a BSS"""
|
2019-03-15 11:10:37 +01:00
|
|
|
hapd2 = hostapd.add_ap(apdev[1], {"ssid": "open"})
|
2015-01-06 01:38:26 +01:00
|
|
|
|
|
|
|
ifname1 = apdev[0]['ifname']
|
|
|
|
ifname2 = apdev[0]['ifname'] + '-2'
|
|
|
|
|
2020-02-23 16:05:43 +01:00
|
|
|
confname1 = hostapd.cfg_file(apdev[0], "bss-1.conf")
|
|
|
|
confname2 = hostapd.cfg_file(apdev[0], "bss-2.conf")
|
|
|
|
hapd_bss_out_of_mem(hapd2, 'phy3', confname1, 1, 'hostapd_add_iface')
|
2015-01-06 01:38:26 +01:00
|
|
|
for i in range(1, 3):
|
2020-02-23 16:05:43 +01:00
|
|
|
hapd_bss_out_of_mem(hapd2, 'phy3', confname1,
|
2015-01-06 01:38:26 +01:00
|
|
|
i, 'hostapd_interface_init_bss')
|
2020-02-23 16:05:43 +01:00
|
|
|
hapd_bss_out_of_mem(hapd2, 'phy3', confname1,
|
2015-01-06 01:38:26 +01:00
|
|
|
1, 'ieee802_11_build_ap_params')
|
|
|
|
|
2020-02-23 16:05:43 +01:00
|
|
|
hostapd.add_bss(apdev[0], ifname1, confname1)
|
2015-01-06 01:38:26 +01:00
|
|
|
|
2020-02-23 16:05:43 +01:00
|
|
|
hapd_bss_out_of_mem(hapd2, 'phy3', confname2,
|
2015-01-06 01:38:26 +01:00
|
|
|
1, 'hostapd_interface_init_bss')
|
2020-02-23 16:05:43 +01:00
|
|
|
hapd_bss_out_of_mem(hapd2, 'phy3', confname2,
|
2015-01-06 01:38:26 +01:00
|
|
|
1, 'ieee802_11_build_ap_params')
|
|
|
|
|
2020-02-23 16:05:43 +01:00
|
|
|
hostapd.add_bss(apdev[0], ifname2, confname2)
|
2016-04-07 07:37:59 +02:00
|
|
|
hostapd.remove_bss(apdev[0], ifname2)
|
|
|
|
hostapd.remove_bss(apdev[0], ifname1)
|
2015-03-01 18:15:19 +01:00
|
|
|
|
|
|
|
def test_ap_multi_bss(dev, apdev):
|
|
|
|
"""Multiple BSSes with hostapd"""
|
|
|
|
ifname1 = apdev[0]['ifname']
|
|
|
|
ifname2 = apdev[0]['ifname'] + '-2'
|
2016-04-07 07:38:07 +02:00
|
|
|
hapd1 = hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
|
|
|
|
hapd2 = hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
|
2015-03-01 18:15:19 +01:00
|
|
|
dev[0].connect("bss-1", key_mgmt="NONE", scan_freq="2412")
|
|
|
|
dev[1].connect("bss-2", key_mgmt="NONE", scan_freq="2412")
|
|
|
|
|
|
|
|
hwsim_utils.test_connectivity(dev[0], hapd1)
|
|
|
|
hwsim_utils.test_connectivity(dev[1], hapd2)
|
|
|
|
|
|
|
|
sta0 = hapd1.get_sta(dev[0].own_addr())
|
|
|
|
sta1 = hapd2.get_sta(dev[1].own_addr())
|
|
|
|
if 'rx_packets' not in sta0 or int(sta0['rx_packets']) < 1:
|
|
|
|
raise Exception("sta0 did not report receiving packets")
|
|
|
|
if 'rx_packets' not in sta1 or int(sta1['rx_packets']) < 1:
|
|
|
|
raise Exception("sta1 did not report receiving packets")
|
2015-07-17 22:57:04 +02:00
|
|
|
|
2016-06-23 19:16:36 +02:00
|
|
|
@remote_compatible
|
2015-07-17 22:57:04 +02:00
|
|
|
def test_ap_add_with_driver(dev, apdev):
|
|
|
|
"""Add hostapd interface with driver specified"""
|
|
|
|
ifname = apdev[0]['ifname']
|
2016-04-07 07:38:07 +02:00
|
|
|
try:
|
|
|
|
hostname = apdev[0]['hostname']
|
|
|
|
except:
|
|
|
|
hostname = None
|
|
|
|
hapd_global = hostapd.HostapdGlobal(apdev[0])
|
2015-07-17 22:57:04 +02:00
|
|
|
hapd_global.add(ifname, driver="nl80211")
|
2016-04-07 07:38:07 +02:00
|
|
|
port = hapd_global.get_ctrl_iface_port(ifname)
|
|
|
|
hapd = hostapd.Hostapd(ifname, hostname, port)
|
2015-07-17 22:57:04 +02:00
|
|
|
hapd.set_defaults()
|
|
|
|
hapd.set("ssid", "dynamic")
|
|
|
|
hapd.enable()
|
|
|
|
ev = hapd.wait_event(["AP-ENABLED"], timeout=30)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("AP startup timed out")
|
|
|
|
dev[0].connect("dynamic", key_mgmt="NONE", scan_freq="2412")
|
|
|
|
dev[0].request("DISCONNECT")
|
|
|
|
dev[0].wait_disconnected()
|
|
|
|
hapd.disable()
|
2016-08-18 19:06:09 +02:00
|
|
|
|
2016-12-26 20:54:57 +01:00
|
|
|
def test_ap_duplicate_bssid(dev, apdev):
|
|
|
|
"""Duplicate BSSID"""
|
2019-03-15 11:10:37 +01:00
|
|
|
params = {"ssid": "test"}
|
2016-12-26 20:54:57 +01:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
|
|
|
|
hapd.enable()
|
|
|
|
ifname2 = apdev[0]['ifname'] + '-2'
|
|
|
|
ifname3 = apdev[0]['ifname'] + '-3'
|
|
|
|
# "BSS 'wlan3-2' may not have BSSID set to the MAC address of the radio"
|
|
|
|
try:
|
|
|
|
hostapd.add_bss(apdev[0], ifname2, 'bss-2-dup.conf')
|
|
|
|
raise Exception("BSS add succeeded unexpectedly")
|
2019-01-24 08:45:41 +01:00
|
|
|
except Exception as e:
|
2016-12-26 20:54:57 +01:00
|
|
|
if "Could not add hostapd BSS" in str(e):
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
raise
|
|
|
|
|
|
|
|
hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf')
|
|
|
|
|
|
|
|
dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
|
|
|
|
dev[0].request("DISCONNECT")
|
|
|
|
dev[0].wait_disconnected()
|
|
|
|
|
|
|
|
hapd.set("bssid", "02:00:00:00:03:02")
|
|
|
|
hapd.disable()
|
|
|
|
# "Duplicate BSSID 02:00:00:00:03:02 on interface 'wlan3-3' and 'wlan3'."
|
|
|
|
if "FAIL" not in hapd.request("ENABLE"):
|
|
|
|
raise Exception("ENABLE with duplicate BSSID succeeded unexpectedly")
|
2016-12-27 13:50:56 +01:00
|
|
|
|
|
|
|
def test_ap_bss_config_file(dev, apdev, params):
|
|
|
|
"""hostapd BSS config file"""
|
2020-05-17 15:03:29 +02:00
|
|
|
pidfile = params['prefix'] + ".hostapd.pid"
|
|
|
|
logfile = params['prefix'] + ".hostapd-log"
|
2016-12-27 13:50:56 +01:00
|
|
|
prg = os.path.join(params['logdir'], 'alt-hostapd/hostapd/hostapd')
|
|
|
|
if not os.path.exists(prg):
|
|
|
|
prg = '../../hostapd/hostapd'
|
|
|
|
phy = get_phy(apdev[0])
|
2020-02-23 15:58:43 +01:00
|
|
|
confname1 = hostapd.cfg_file(apdev[0], "bss-1.conf")
|
|
|
|
confname2 = hostapd.cfg_file(apdev[0], "bss-2.conf")
|
|
|
|
confname3 = hostapd.cfg_file(apdev[0], "bss-3.conf")
|
|
|
|
|
2019-03-15 11:10:37 +01:00
|
|
|
cmd = [prg, '-B', '-dddt', '-P', pidfile, '-f', logfile, '-S', '-T',
|
2020-02-23 15:58:43 +01:00
|
|
|
'-b', phy + ':' + confname1, '-b', phy + ':' + confname2,
|
|
|
|
'-b', phy + ':' + confname3]
|
2016-12-27 13:50:56 +01:00
|
|
|
res = subprocess.check_call(cmd)
|
|
|
|
if res != 0:
|
|
|
|
raise Exception("Could not start hostapd: %s" % str(res))
|
2020-01-12 23:02:25 +01:00
|
|
|
multi_check(apdev[0], dev, [True, True, True])
|
2016-12-27 13:50:56 +01:00
|
|
|
for i in range(0, 3):
|
|
|
|
dev[i].request("DISCONNECT")
|
|
|
|
|
|
|
|
hapd = hostapd.Hostapd(apdev[0]['ifname'])
|
|
|
|
hapd.ping()
|
|
|
|
if "OK" not in hapd.request("TERMINATE"):
|
|
|
|
raise Exception("Failed to terminate hostapd process")
|
2017-01-29 11:31:04 +01:00
|
|
|
ev = hapd.wait_event(["CTRL-EVENT-TERMINATING"], timeout=15)
|
2016-12-27 13:50:56 +01:00
|
|
|
if ev is None:
|
|
|
|
raise Exception("CTRL-EVENT-TERMINATING not seen")
|
|
|
|
for i in range(30):
|
|
|
|
time.sleep(0.1)
|
|
|
|
if not os.path.exists(pidfile):
|
|
|
|
break
|
|
|
|
if os.path.exists(pidfile):
|
|
|
|
raise Exception("PID file exits after process termination")
|
2022-08-01 13:08:27 +02:00
|
|
|
|
|
|
|
def test_ap_reload_bss_only(dev, apdev, params):
|
|
|
|
"""Dynamic SSID change on only one BSS using RELOAD_BSS"""
|
|
|
|
ifname1 = apdev[0]['ifname']
|
|
|
|
ifname2 = apdev[0]['ifname'] + '-2'
|
|
|
|
hapd1 = hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
|
|
|
|
hapd2 = hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
|
|
|
|
id = dev[0].connect("bss-1", key_mgmt="NONE", scan_freq="2412")
|
|
|
|
dev[1].connect("bss-2", key_mgmt="NONE", scan_freq="2412")
|
|
|
|
|
|
|
|
res = hapd1.request("SET ssid test-new-ssid")
|
|
|
|
if "OK" not in res:
|
|
|
|
raise Exception("SET command failed")
|
|
|
|
res = hapd1.request("RELOAD_BSS")
|
|
|
|
if "OK" not in res:
|
|
|
|
raise Exception("RELOAD_BSS command failed")
|
|
|
|
|
|
|
|
ev = dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1)
|
|
|
|
if ev is not None:
|
|
|
|
raise Exception("Unexpected disconnection when RELOAD_BSS was sent on another BSS.")
|
|
|
|
|
|
|
|
dev[0].set_network_quoted(id, "ssid", "test-new-ssid")
|
|
|
|
dev[0].connect_network(id)
|