tests: Scanning in AP mode

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2020-03-15 21:22:18 +02:00
parent 9e30180a30
commit e9d2cd71af
2 changed files with 95 additions and 0 deletions

View File

@ -5490,6 +5490,67 @@ def test_dbus_ap(dev, apdev):
if not t.success():
raise Exception("Expected signals not seen")
def test_dbus_ap_scan(dev, apdev):
"""D-Bus AddNetwork for AP mode and scan"""
(bus, wpas_obj, path, if_obj) = prepare_dbus(dev[0])
iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
ssid = "test-wpa2-psk"
passphrase = 'qwertyuiop'
hapd = hostapd.add_ap(apdev[0], {"ssid": "open"})
bssid = hapd.own_addr()
class TestDbusConnect(TestDbus):
def __init__(self, bus):
TestDbus.__init__(self, bus)
self.started = False
self.scan_completed = False
def __enter__(self):
gobject.timeout_add(1, self.run_connect)
gobject.timeout_add(15000, self.timeout)
self.add_signal(self.propertiesChanged, WPAS_DBUS_IFACE,
"PropertiesChanged")
self.add_signal(self.scanDone, WPAS_DBUS_IFACE, "ScanDone")
self.loop.run()
return self
def propertiesChanged(self, properties):
logger.debug("propertiesChanged: %s" % str(properties))
if 'State' in properties and properties['State'] == "completed":
self.started = True
logger.info("Try to scan in AP mode")
iface.Scan({'Type': 'active',
'Channels': [(dbus.UInt32(2412), dbus.UInt32(20))]})
logger.info("Scan() returned")
def scanDone(self, success):
logger.debug("scanDone: success=%s" % success)
if self.started:
self.scan_completed = True
self.loop.quit()
def run_connect(self, *args):
logger.debug("run_connect")
args = dbus.Dictionary({'ssid': ssid,
'key_mgmt': 'WPA-PSK',
'psk': passphrase,
'mode': 2,
'frequency': 2412,
'scan_freq': 2412},
signature='sv')
self.netw = iface.AddNetwork(args)
iface.SelectNetwork(self.netw)
return False
def success(self):
return self.started and self.scan_completed
with TestDbusConnect(bus) as t:
if not t.success():
raise Exception("Expected signals not seen")
def test_dbus_connect_wpa_eap(dev, apdev):
"""D-Bus AddNetwork and connection with WPA+WPA2-Enterprise AP"""
(bus, wpas_obj, path, if_obj) = prepare_dbus(dev[0])

View File

@ -4,6 +4,7 @@
# This software may be distributed under the terms of the BSD license.
# See README for more details.
import hostapd
from remotehost import remote_compatible
import time
import logging
@ -815,3 +816,36 @@ def run_wpas_ap_sae(dev, sae_password, sae_password_id=False):
dev[1].request("SET sae_groups ")
dev[1].connect("wpas-ap-sae", key_mgmt="SAE", sae_password="12345678",
sae_password_id=pw_id, scan_freq="2412")
def test_wpas_ap_scan(dev, apdev):
"""wpa_supplicant AP mode and scanning"""
dev[0].flush_scan_cache()
hapd = hostapd.add_ap(apdev[0], {"ssid": "open"})
bssid = hapd.own_addr()
id = dev[0].add_network()
dev[0].set_network(id, "mode", "2")
dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
dev[0].set_network(id, "key_mgmt", "NONE")
dev[0].set_network(id, "frequency", "2412")
dev[0].set_network(id, "scan_freq", "2412")
dev[0].select_network(id)
wait_ap_ready(dev[0])
dev[0].dump_monitor()
if "OK" not in dev[0].request("SCAN freq=2412"):
raise Exception("SCAN command not accepted")
ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS",
"CTRL-EVENT-SCAN-FAILED"], 15)
if ev is None:
raise Exception("Scan result timed out")
if "CTRL-EVENT-SCAN-FAILED ret=-95" in ev:
# Scanning in AP mode not supported
return
if "CTRL-EVENT-SCAN-FAILED" in ev:
raise Exception("Unexpected scan failure reason: " + ev)
if "CTRL-EVENT-SCAN-RESULTS" in ev:
bss = dev[0].get_bss(bssid)
if not bss:
raise Exception("AP not found in scan")