2 # Copyright (c) 2014, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
9 logger = logging.getLogger()
12 from wpasupplicant import WpaSupplicant
14 def test_ext_radio_work(dev, apdev):
15 """External radio work item"""
16 id = dev[0].request("RADIO_WORK add test-work-a")
18 raise Exception("Failed to add radio work")
19 id2 = dev[0].request("RADIO_WORK add test-work-b freq=2417")
21 raise Exception("Failed to add radio work")
22 id3 = dev[0].request("RADIO_WORK add test-work-c")
24 raise Exception("Failed to add radio work")
26 ev = dev[0].wait_event(["EXT-RADIO-WORK-START"])
28 raise Exception("Timeout while waiting radio work to start")
29 if "EXT-RADIO-WORK-START " + id not in ev:
30 raise Exception("Unexpected radio work start id")
32 items = dev[0].request("RADIO_WORK show")
33 if "ext:test-work-a@wlan0:0:1:" not in items:
34 logger.info("Pending radio work items:\n" + items)
35 raise Exception("Radio work item(a) missing from the list")
36 if "ext:test-work-b@wlan0:2417:0:" not in items:
37 logger.info("Pending radio work items:\n" + items)
38 raise Exception("Radio work item(b) missing from the list")
39 if "ext:test-work-c@wlan0:0:0:" not in items:
40 logger.info("Pending radio work items:\n" + items)
41 raise Exception("Radio work item(c) missing from the list")
43 dev[0].request("RADIO_WORK done " + id2)
44 dev[0].request("RADIO_WORK done " + id)
46 ev = dev[0].wait_event(["EXT-RADIO-WORK-START"])
48 raise Exception("Timeout while waiting radio work to start")
49 if "EXT-RADIO-WORK-START " + id3 not in ev:
50 raise Exception("Unexpected radio work start id")
51 dev[0].request("RADIO_WORK done " + id3)
52 items = dev[0].request("RADIO_WORK show")
54 logger.info("Pending radio work items:\n" + items)
55 raise Exception("Unexpected remaining radio work item")
57 id = dev[0].request("RADIO_WORK add test-work timeout=1")
58 ev = dev[0].wait_event(["EXT-RADIO-WORK-START"])
60 raise Exception("Timeout while waiting radio work to start")
61 ev = dev[0].wait_event(["EXT-RADIO-WORK-TIMEOUT"], timeout=2)
63 raise Exception("Timeout while waiting radio work to time out")
65 raise Exception("Radio work id mismatch")
68 dev[0].request(("RADIO_WORK add test-work-%d-" % i) + 100*'a')
69 ev = dev[0].wait_event(["EXT-RADIO-WORK-START"])
71 raise Exception("Timeout while waiting radio work to start")
72 if "FAIL" not in dev[0].request("RADIO_WORK done 12345678"):
73 raise Exception("Invalid RADIO_WORK done accepted")
74 if "FAIL" not in dev[0].request("RADIO_WORK foo"):
75 raise Exception("Invalid RADIO_WORK accepted")
76 dev[0].request("FLUSH")
77 items = dev[0].request("RADIO_WORK show")
79 raise Exception("Unexpected radio work remaining after FLUSH: " + items)
81 def test_radio_work_cancel(dev, apdev):
82 """Radio work items cancelled on interface removal"""
83 params = hostapd.wpa2_params(ssid="radio", passphrase="12345678")
84 hostapd.add_ap(apdev[0], params)
85 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
86 wpas.interface_add("wlan5")
87 wpas.scan(freq="2412")
89 id = wpas.request("RADIO_WORK add test-work-a")
91 raise Exception("Failed to add radio work")
92 ev = wpas.wait_event(["EXT-RADIO-WORK-START"])
94 raise Exception("Timeout while waiting radio work to start")
95 if "EXT-RADIO-WORK-START " + id not in ev:
96 raise Exception("Unexpected radio work start id")
98 wpas.connect("radio", psk="12345678", scan_freq="2412",
101 wpas.interface_remove("wlan5")
102 # add to allow log file renaming
103 wpas.interface_add("wlan5")