2014-06-01 15:17:33 +02:00
|
|
|
# rfkill tests
|
|
|
|
# Copyright (c) 2014, Jouni Malinen <j@w1.fi>
|
|
|
|
#
|
|
|
|
# This software may be distributed under the terms of the BSD license.
|
|
|
|
# See README for more details.
|
|
|
|
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger()
|
|
|
|
import time
|
|
|
|
|
|
|
|
import hostapd
|
2014-10-26 09:53:37 +01:00
|
|
|
from hostapd import HostapdGlobal
|
2014-06-01 15:17:33 +02:00
|
|
|
import hwsim_utils
|
2014-12-20 15:46:39 +01:00
|
|
|
from wpasupplicant import WpaSupplicant
|
2015-01-08 14:59:16 +01:00
|
|
|
from rfkill import RFKill
|
2015-01-07 13:19:30 +01:00
|
|
|
from utils import HwsimSkip
|
2015-12-17 14:54:12 +01:00
|
|
|
from hwsim import HWSimRadio
|
2014-06-01 15:17:33 +02:00
|
|
|
|
2015-01-08 14:59:16 +01:00
|
|
|
def get_rfkill(dev):
|
|
|
|
phy = dev.get_driver_status_field("phyname")
|
2014-06-01 15:17:33 +02:00
|
|
|
try:
|
2015-01-08 14:59:16 +01:00
|
|
|
for r, s, h in RFKill.list():
|
|
|
|
if r.name == phy:
|
|
|
|
return r
|
2019-01-24 08:45:41 +01:00
|
|
|
except Exception as e:
|
2015-01-07 13:19:30 +01:00
|
|
|
raise HwsimSkip("No rfkill available: " + str(e))
|
|
|
|
raise HwsimSkip("No rfkill match found for the interface")
|
2014-06-01 15:17:33 +02:00
|
|
|
|
|
|
|
def test_rfkill_open(dev, apdev):
|
|
|
|
"""rfkill block/unblock during open mode connection"""
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk = get_rfkill(dev[0])
|
2014-06-01 15:17:33 +02:00
|
|
|
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
|
2014-06-01 15:17:33 +02:00
|
|
|
dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
|
|
|
|
try:
|
|
|
|
logger.info("rfkill block")
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk.block()
|
2014-12-20 10:51:30 +01:00
|
|
|
dev[0].wait_disconnected(timeout=10,
|
|
|
|
error="Missing disconnection event on rfkill block")
|
2014-06-01 15:17:33 +02:00
|
|
|
|
2014-12-13 18:30:21 +01:00
|
|
|
if "FAIL" not in dev[0].request("REASSOCIATE"):
|
|
|
|
raise Exception("REASSOCIATE accepted while disabled")
|
|
|
|
if "FAIL" not in dev[0].request("REATTACH"):
|
|
|
|
raise Exception("REATTACH accepted while disabled")
|
|
|
|
if "FAIL" not in dev[0].request("RECONNECT"):
|
|
|
|
raise Exception("RECONNECT accepted while disabled")
|
2014-12-14 01:15:30 +01:00
|
|
|
if "FAIL" not in dev[0].request("FETCH_OSU"):
|
|
|
|
raise Exception("FETCH_OSU accepted while disabled")
|
2014-12-13 18:30:21 +01:00
|
|
|
|
2014-06-01 15:17:33 +02:00
|
|
|
logger.info("rfkill unblock")
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk.unblock()
|
2014-12-20 10:51:30 +01:00
|
|
|
dev[0].wait_connected(timeout=10,
|
|
|
|
error="Missing connection event on rfkill unblock")
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0], hapd)
|
2014-06-01 15:17:33 +02:00
|
|
|
finally:
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk.unblock()
|
2014-06-01 15:17:33 +02:00
|
|
|
|
|
|
|
def test_rfkill_wpa2_psk(dev, apdev):
|
|
|
|
"""rfkill block/unblock during WPA2-PSK connection"""
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk = get_rfkill(dev[0])
|
2014-06-01 15:17:33 +02:00
|
|
|
|
|
|
|
ssid = "test-wpa2-psk"
|
|
|
|
passphrase = 'qwertyuiop'
|
|
|
|
params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
2014-06-01 15:17:33 +02:00
|
|
|
dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
|
|
|
|
try:
|
|
|
|
logger.info("rfkill block")
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk.block()
|
2014-12-20 10:51:30 +01:00
|
|
|
dev[0].wait_disconnected(timeout=10,
|
|
|
|
error="Missing disconnection event on rfkill block")
|
2014-06-01 15:17:33 +02:00
|
|
|
|
|
|
|
logger.info("rfkill unblock")
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk.unblock()
|
2014-12-20 10:51:30 +01:00
|
|
|
dev[0].wait_connected(timeout=10,
|
|
|
|
error="Missing connection event on rfkill unblock")
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0], hapd)
|
2014-06-01 15:17:33 +02:00
|
|
|
finally:
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk.unblock()
|
2014-06-01 15:17:33 +02:00
|
|
|
|
|
|
|
def test_rfkill_autogo(dev, apdev):
|
|
|
|
"""rfkill block/unblock for autonomous P2P GO"""
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk0 = get_rfkill(dev[0])
|
|
|
|
rfk1 = get_rfkill(dev[1])
|
2014-06-01 15:17:33 +02:00
|
|
|
|
|
|
|
dev[0].p2p_start_go()
|
|
|
|
dev[1].request("SET p2p_no_group_iface 0")
|
|
|
|
dev[1].p2p_start_go()
|
|
|
|
|
|
|
|
try:
|
|
|
|
logger.info("rfkill block 0")
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk0.block()
|
2014-06-01 15:17:33 +02:00
|
|
|
ev = dev[0].wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Group removal not reported")
|
|
|
|
if "reason=UNAVAILABLE" not in ev:
|
|
|
|
raise Exception("Unexpected group removal reason: " + ev)
|
2014-12-08 17:25:05 +01:00
|
|
|
if "FAIL" not in dev[0].request("P2P_LISTEN 1"):
|
|
|
|
raise Exception("P2P_LISTEN accepted unexpectedly")
|
|
|
|
if "FAIL" not in dev[0].request("P2P_LISTEN"):
|
|
|
|
raise Exception("P2P_LISTEN accepted unexpectedly")
|
2014-06-01 15:17:33 +02:00
|
|
|
|
|
|
|
logger.info("rfkill block 1")
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk1.block()
|
2014-06-01 15:17:33 +02:00
|
|
|
ev = dev[1].wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Group removal not reported")
|
|
|
|
if "reason=UNAVAILABLE" not in ev:
|
|
|
|
raise Exception("Unexpected group removal reason: " + ev)
|
|
|
|
|
|
|
|
logger.info("rfkill unblock 0")
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk0.unblock()
|
2014-06-01 15:17:33 +02:00
|
|
|
logger.info("rfkill unblock 1")
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk1.unblock()
|
2014-06-01 15:17:33 +02:00
|
|
|
time.sleep(1)
|
|
|
|
finally:
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk0.unblock()
|
|
|
|
rfk1.unblock()
|
2014-10-26 09:53:37 +01:00
|
|
|
|
2015-12-17 14:54:12 +01:00
|
|
|
def _test_rfkill_p2p_discovery(dev0, dev1):
|
|
|
|
"""rfkill block/unblock P2P Discovery"""
|
|
|
|
rfk0 = get_rfkill(dev0)
|
|
|
|
rfk1 = get_rfkill(dev1)
|
|
|
|
|
|
|
|
try:
|
|
|
|
addr0 = dev0.p2p_dev_addr()
|
|
|
|
|
|
|
|
logger.info("rfkill block 0")
|
|
|
|
rfk0.block()
|
|
|
|
logger.info("rfkill block 1")
|
|
|
|
rfk1.block()
|
|
|
|
|
|
|
|
for i in range(10):
|
|
|
|
time.sleep(0.1)
|
|
|
|
if dev0.get_status_field("wpa_state") == "INTERFACE_DISABLED" and dev1.get_status_field("wpa_state") == "INTERFACE_DISABLED":
|
|
|
|
break
|
|
|
|
|
2016-04-24 23:19:40 +02:00
|
|
|
if "OK" in dev0.p2p_listen():
|
|
|
|
raise Exception("P2P Listen success although in rfkill")
|
2015-12-17 14:54:12 +01:00
|
|
|
|
2016-04-24 23:19:40 +02:00
|
|
|
if "OK" in dev1.p2p_find():
|
|
|
|
raise Exception("P2P Find success although in rfkill")
|
2015-12-17 14:54:12 +01:00
|
|
|
|
|
|
|
dev0.dump_monitor()
|
|
|
|
dev1.dump_monitor()
|
|
|
|
|
|
|
|
logger.info("rfkill unblock 0")
|
|
|
|
rfk0.unblock()
|
|
|
|
logger.info("rfkill unblock 1")
|
|
|
|
rfk1.unblock()
|
|
|
|
|
|
|
|
for i in range(10):
|
|
|
|
time.sleep(0.1)
|
|
|
|
if dev0.get_status_field("wpa_state") != "INTERFACE_DISABLED" and dev1.get_status_field("wpa_state") != "INTERFACE_DISABLED":
|
|
|
|
break
|
|
|
|
|
2019-03-15 10:34:32 +01:00
|
|
|
if "OK" not in dev0.p2p_listen():
|
2016-04-24 23:19:40 +02:00
|
|
|
raise Exception("P2P Listen failed after unblocking rfkill")
|
2015-12-17 14:54:12 +01:00
|
|
|
|
2016-04-24 23:19:40 +02:00
|
|
|
if not dev1.discover_peer(addr0, social=True):
|
|
|
|
raise Exception("Failed to discover peer after unblocking rfkill")
|
2015-12-17 14:54:12 +01:00
|
|
|
|
|
|
|
finally:
|
|
|
|
rfk0.unblock()
|
|
|
|
rfk1.unblock()
|
|
|
|
dev0.p2p_stop_find()
|
|
|
|
dev1.p2p_stop_find()
|
|
|
|
dev0.dump_monitor()
|
|
|
|
dev1.dump_monitor()
|
|
|
|
|
|
|
|
def test_rfkill_p2p_discovery(dev, apdev):
|
|
|
|
"""rfkill block/unblock P2P Discovery"""
|
|
|
|
_test_rfkill_p2p_discovery(dev[0], dev[1])
|
|
|
|
|
|
|
|
def test_rfkill_p2p_discovery_p2p_dev(dev, apdev):
|
|
|
|
"""rfkill block/unblock P2P Discovery with P2P Device"""
|
|
|
|
with HWSimRadio(use_p2p_device=True) as (radio, iface):
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add(iface)
|
2016-04-24 23:19:40 +02:00
|
|
|
_test_rfkill_p2p_discovery(dev[0], wpas)
|
|
|
|
_test_rfkill_p2p_discovery(wpas, dev[1])
|
2015-12-17 14:54:12 +01:00
|
|
|
|
2014-10-26 09:53:37 +01:00
|
|
|
def test_rfkill_hostapd(dev, apdev):
|
|
|
|
"""rfkill block/unblock during and prior to hostapd operations"""
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
|
2014-10-26 09:53:37 +01:00
|
|
|
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk = get_rfkill(hapd)
|
2014-10-26 09:53:37 +01:00
|
|
|
|
|
|
|
try:
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk.block()
|
2014-10-26 09:53:37 +01:00
|
|
|
ev = hapd.wait_event(["INTERFACE-DISABLED"], timeout=5)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("INTERFACE-DISABLED event not seen")
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk.unblock()
|
2014-10-26 09:53:37 +01:00
|
|
|
ev = hapd.wait_event(["INTERFACE-ENABLED"], timeout=5)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("INTERFACE-ENABLED event not seen")
|
|
|
|
# hostapd does not current re-enable beaconing automatically
|
|
|
|
hapd.disable()
|
|
|
|
hapd.enable()
|
|
|
|
dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk.block()
|
2014-10-26 09:53:37 +01:00
|
|
|
ev = hapd.wait_event(["INTERFACE-DISABLED"], timeout=5)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("INTERFACE-DISABLED event not seen")
|
2014-12-20 10:51:30 +01:00
|
|
|
dev[0].wait_disconnected(timeout=10)
|
2014-10-26 09:53:37 +01:00
|
|
|
dev[0].request("DISCONNECT")
|
|
|
|
hapd.disable()
|
|
|
|
|
2016-04-07 07:38:05 +02:00
|
|
|
hglobal = HostapdGlobal(apdev[0])
|
2014-10-26 09:53:37 +01:00
|
|
|
hglobal.flush()
|
|
|
|
hglobal.remove(apdev[0]['ifname'])
|
|
|
|
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], { "ssid": "open2" },
|
2014-10-26 09:53:37 +01:00
|
|
|
no_enable=True)
|
|
|
|
if "FAIL" not in hapd.request("ENABLE"):
|
|
|
|
raise Exception("ENABLE succeeded unexpectedly (rfkill)")
|
|
|
|
finally:
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk.unblock()
|
2014-12-20 15:46:39 +01:00
|
|
|
|
|
|
|
def test_rfkill_wpas(dev, apdev):
|
|
|
|
"""rfkill block prior to wpa_supplicant start"""
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5")
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk = get_rfkill(wpas)
|
2014-12-20 15:46:39 +01:00
|
|
|
wpas.interface_remove("wlan5")
|
|
|
|
try:
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk.block()
|
2014-12-20 15:46:39 +01:00
|
|
|
wpas.interface_add("wlan5")
|
|
|
|
time.sleep(0.5)
|
|
|
|
state = wpas.get_status_field("wpa_state")
|
|
|
|
if state != "INTERFACE_DISABLED":
|
|
|
|
raise Exception("Unexpected state with rfkill blocked: " + state)
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk.unblock()
|
2014-12-20 15:46:39 +01:00
|
|
|
time.sleep(0.5)
|
|
|
|
state = wpas.get_status_field("wpa_state")
|
|
|
|
if state == "INTERFACE_DISABLED":
|
|
|
|
raise Exception("Unexpected state with rfkill unblocked: " + state)
|
|
|
|
finally:
|
2015-01-08 14:59:16 +01:00
|
|
|
rfk.unblock()
|