1 # Test cases for wpa_supplicant WMM-AC operations
2 # Copyright (c) 2014, Intel Corporation
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
8 logger = logging.getLogger()
14 def add_wmm_ap(apdev, acm_list):
15 params = { "ssid": "wmm_ac",
21 params["wmm_ac_%s_acm" % (ac.lower())] = "1"
23 return hostapd.add_ap(apdev['ifname'], params)
25 def test_tspec(dev, apdev):
26 """Basic addts/delts tests"""
27 # configure ap with VO and VI requiring admission-control
28 hapd = add_wmm_ap(apdev[0], ["VO", "VI"])
29 dev[0].connect("wmm_ac", key_mgmt="NONE", scan_freq="2462")
30 hwsim_utils.test_connectivity(dev[0], hapd)
31 status = dev[0].request("WMM_AC_STATUS")
32 if "WMM AC is Enabled" not in status:
33 raise Exception("WMM-AC not enabled")
35 raise Exception("Unexpected TSID info")
36 if "BK: acm=0 uapsd=0" not in status:
37 raise Exception("Unexpected BK info" + status)
38 if "BE: acm=0 uapsd=0" not in status:
39 raise Exception("Unexpected BE info" + status)
40 if "VI: acm=1 uapsd=0" not in status:
41 raise Exception("Unexpected VI info" + status)
42 if "VO: acm=1 uapsd=0" not in status:
43 raise Exception("Unexpected VO info" + status)
45 # no tsid --> tsid out of range
46 if "FAIL" not in dev[0].request("WMM_AC_ADDTS downlink"):
47 raise Exception("Invalid WMM_AC_ADDTS accepted")
49 if "FAIL" not in dev[0].request("WMM_AC_ADDTS tsid=5"):
50 raise Exception("Invalid WMM_AC_ADDTS accepted")
52 if "FAIL" not in dev[0].request("WMM_AC_ADDTS tsid=5 downlink"):
53 raise Exception("Invalid WMM_AC_ADDTS accepted")
57 # make sure we fail when the ac is not configured for acm
59 dev[0].add_ts(tsid, 3)
60 raise Exception("ADDTS succeeded although it should have failed")
62 if not str(e).startswith("ADDTS failed"):
64 status = dev[0].request("WMM_AC_STATUS")
66 raise Exception("Unexpected TSID info")
69 dev[0].add_ts(tsid, 6)
70 status = dev[0].request("WMM_AC_STATUS")
71 if "TSID" not in status:
72 raise Exception("Missing TSID info")
74 # using the same tsid for a different ac is invalid
76 dev[0].add_ts(tsid, 5)
77 raise Exception("ADDTS succeeded although it should have failed")
79 if not str(e).startswith("ADDTS failed"):
82 # update the tspec for a different UP of the same ac
83 dev[0].add_ts(tsid, 7, extra="fixed_nominal_msdu")
85 status = dev[0].request("WMM_AC_STATUS")
87 raise Exception("Unexpected TSID info")
89 # verify failure on uplink/bidi without driver support
92 dev[0].add_ts(tsid, 7, direction="uplink")
93 raise Exception("ADDTS succeeded although it should have failed")
95 if not str(e).startswith("ADDTS failed"):
98 dev[0].add_ts(tsid, 7, direction="bidi")
99 raise Exception("ADDTS succeeded although it should have failed")
101 if not str(e).startswith("ADDTS failed"):
104 # attempt to delete non-existing tsid
107 raise Exception("DELTS succeeded although it should have failed")
109 if not str(e).startswith("DELTS failed"):
112 def test_tspec_protocol(dev, apdev):
113 """Protocol tests for addts/delts"""
114 # configure ap with VO and VI requiring admission-control
115 hapd = add_wmm_ap(apdev[0], ["VO", "VI"])
116 dev[0].connect("wmm_ac", key_mgmt="NONE", scan_freq="2462")
118 dev[0].dump_monitor()
119 hapd.set("ext_mgmt_frame_handling", "1")
123 # timeout on ADDTS response
124 dev[0].add_ts(tsid, 7, expect_failure=True)
127 req = "WMM_AC_ADDTS downlink tsid=6 up=7 nominal_msdu_size=1500 sba=9000 mean_data_rate=1500 min_phy_rate=6000000"
128 if "OK" not in dev[0].request(req):
129 raise Exception("WMM_AC_ADDTS failed")
130 # a new request while previous is still pending
131 if "FAIL" not in dev[0].request(req):
132 raise Exception("WMM_AC_ADDTS accepted while oen was still pending")
134 payload = msg['payload']
135 (categ, action, dialog, status) = struct.unpack('BBBB', payload[0:4])
137 raise Exception("Unexpected Action code: %d" % action)
139 msg['da'] = msg['sa']
140 msg['sa'] = apdev[0]['bssid']
142 # unexpected dialog token
143 msg['payload'] = struct.pack('BBBB', 17, 1, (dialog + 1) & 0xff, 0) + payload[4:]
147 msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0) + payload[4:]
149 ev = dev[0].wait_event(["TSPEC-ADDED"], timeout=10)
151 raise Exception("Timeout on TSPEC-ADDED")
152 if "tsid=%d" % tsid not in ev:
153 raise Exception("Unexpected TSPEC-ADDED contents: " + ev)
155 # duplicated response
156 msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0) + payload[4:]
160 msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0)
164 msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0) + payload[4:] + struct.pack('BB', 0xdd, 100)
167 # too short WMM element
168 msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0) + payload[4:] + '\xdd\x06\x00\x50\xf2\x02\x02\x01'
172 dev[0].dump_monitor()
173 msg['payload'] = struct.pack('BBBB', 17, 2, 0, 0) + payload[4:]
175 ev = dev[0].wait_event(['TSPEC-REMOVED'], timeout=6)
177 raise Exception("Timeout on TSPEC-REMOVED event")
178 if "tsid=%d" % tsid not in ev:
179 raise Exception("Unexpected TSPEC-REMOVED contents: " + ev)
181 msg['payload'] = struct.pack('BBBB', 17, 2, 0, 0) + payload[4:]
184 # start a new request
186 if "OK" not in dev[0].request(req):
187 raise Exception("WMM_AC_ADDTS failed")
189 payload = msg['payload']
190 (categ, action, dialog, status) = struct.unpack('BBBB', payload[0:4])
192 raise Exception("Unexpected Action code: %d" % action)
194 msg['da'] = msg['sa']
195 msg['sa'] = apdev[0]['bssid']
197 # modified parameters
198 msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 1) + payload[4:12] + struct.pack('B', ord(payload[12]) & ~0x60) + payload[13:]
202 msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 1) + payload[4:]
204 ev = dev[0].wait_event(["TSPEC-REQ-FAILED"], timeout=10)
206 raise Exception("Timeout on TSPEC-REQ-FAILED")
207 if "tsid=%d" % tsid not in ev:
208 raise Exception("Unexpected TSPEC-REQ-FAILED contents: " + ev)
210 hapd.set("ext_mgmt_frame_handling", "0")
212 def test_tspec_not_enabled(dev, apdev):
213 """addts failing if AP does not support WMM"""
214 params = { "ssid": "wmm_no_ac",
217 "wmm_enabled" : "0" }
218 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
219 dev[0].connect("wmm_no_ac", key_mgmt="NONE", scan_freq="2462")
220 status = dev[0].request("WMM_AC_STATUS")
221 if "Not associated to a WMM AP, WMM AC is Disabled" not in status:
222 raise Exception("Unexpected WMM_AC_STATUS: " + status)
226 raise Exception("ADDTS succeeded although it should have failed")
228 if not str(e).startswith("ADDTS failed"):
231 # attempt to delete non-existing tsid
234 raise Exception("DELTS succeeded although it should have failed")
236 if not str(e).startswith("DELTS failed"):
239 # unexpected Action frame when WMM is disabled
240 MGMT_SUBTYPE_ACTION = 13
242 msg['fc'] = MGMT_SUBTYPE_ACTION << 4
243 msg['da'] = dev[0].p2p_interface_addr()
244 msg['sa'] = apdev[0]['bssid']
245 msg['bssid'] = apdev[0]['bssid']
246 msg['payload'] = struct.pack('BBBB', 17, 2, 0, 0)
249 def test_tspec_ap_roam_open(dev, apdev):
250 """Roam between two open APs while having tspecs"""
251 hapd0 = add_wmm_ap(apdev[0], ["VO", "VI"])
252 dev[0].connect("wmm_ac", key_mgmt="NONE")
253 hwsim_utils.test_connectivity(dev[0], hapd0)
256 hapd1 = add_wmm_ap(apdev[1], ["VO", "VI"])
257 dev[0].scan_for_bss(apdev[1]['bssid'], freq=2462)
258 dev[0].roam(apdev[1]['bssid'])
259 hwsim_utils.test_connectivity(dev[0], hapd1)
261 raise Exception("TSPECs weren't deleted on roaming")
263 dev[0].scan_for_bss(apdev[0]['bssid'], freq=2462)
264 dev[0].roam(apdev[0]['bssid'])
265 hwsim_utils.test_connectivity(dev[0], hapd0)
267 def test_tspec_reassoc(dev, apdev):
268 """Reassociation to same BSS while having tspecs"""
269 hapd0 = add_wmm_ap(apdev[0], ["VO", "VI"])
270 dev[0].connect("wmm_ac", key_mgmt="NONE")
271 hwsim_utils.test_connectivity(dev[0], hapd0)
273 last_tspecs = dev[0].tspecs()
275 dev[0].request("REASSOCIATE")
276 dev[0].wait_connected()
278 hwsim_utils.test_connectivity(dev[0], hapd0)
279 if dev[0].tspecs() != last_tspecs:
280 raise Exception("TSPECs weren't saved on reassociation")