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.
7 from remotehost import remote_compatible
9 logger = logging.getLogger()
15 def add_wmm_ap(apdev, acm_list):
16 params = { "ssid": "wmm_ac",
22 params["wmm_ac_%s_acm" % (ac.lower())] = "1"
24 return hostapd.add_ap(apdev, params)
26 def test_tspec(dev, apdev):
27 """Basic addts/delts tests"""
28 # configure ap with VO and VI requiring admission-control
29 hapd = add_wmm_ap(apdev[0], ["VO", "VI"])
30 dev[0].connect("wmm_ac", key_mgmt="NONE", scan_freq="2462")
31 hwsim_utils.test_connectivity(dev[0], hapd)
32 status = dev[0].request("WMM_AC_STATUS")
33 if "WMM AC is Enabled" not in status:
34 raise Exception("WMM-AC not enabled")
36 raise Exception("Unexpected TSID info")
37 if "BK: acm=0 uapsd=0" not in status:
38 raise Exception("Unexpected BK info" + status)
39 if "BE: acm=0 uapsd=0" not in status:
40 raise Exception("Unexpected BE info" + status)
41 if "VI: acm=1 uapsd=0" not in status:
42 raise Exception("Unexpected VI info" + status)
43 if "VO: acm=1 uapsd=0" not in status:
44 raise Exception("Unexpected VO info" + status)
46 # no tsid --> tsid out of range
47 if "FAIL" not in dev[0].request("WMM_AC_ADDTS downlink"):
48 raise Exception("Invalid WMM_AC_ADDTS accepted")
50 if "FAIL" not in dev[0].request("WMM_AC_ADDTS tsid=5"):
51 raise Exception("Invalid WMM_AC_ADDTS accepted")
53 if "FAIL" not in dev[0].request("WMM_AC_ADDTS tsid=5 downlink"):
54 raise Exception("Invalid WMM_AC_ADDTS accepted")
58 # make sure we fail when the ac is not configured for acm
60 dev[0].add_ts(tsid, 3)
61 raise Exception("ADDTS succeeded although it should have failed")
63 if not str(e).startswith("ADDTS failed"):
65 status = dev[0].request("WMM_AC_STATUS")
67 raise Exception("Unexpected TSID info")
70 dev[0].add_ts(tsid, 6)
71 status = dev[0].request("WMM_AC_STATUS")
72 if "TSID" not in status:
73 raise Exception("Missing TSID info")
75 # using the same tsid for a different ac is invalid
77 dev[0].add_ts(tsid, 5)
78 raise Exception("ADDTS succeeded although it should have failed")
80 if not str(e).startswith("ADDTS failed"):
83 # update the tspec for a different UP of the same ac
84 dev[0].add_ts(tsid, 7, extra="fixed_nominal_msdu")
86 status = dev[0].request("WMM_AC_STATUS")
88 raise Exception("Unexpected TSID info")
90 # verify failure on uplink/bidi without driver support
93 dev[0].add_ts(tsid, 7, direction="uplink")
94 raise Exception("ADDTS succeeded although it should have failed")
96 if not str(e).startswith("ADDTS failed"):
99 dev[0].add_ts(tsid, 7, direction="bidi")
100 raise Exception("ADDTS succeeded although it should have failed")
102 if not str(e).startswith("ADDTS failed"):
105 # attempt to delete non-existing tsid
108 raise Exception("DELTS succeeded although it should have failed")
110 if not str(e).startswith("DELTS failed"):
113 def test_tspec_protocol(dev, apdev):
114 """Protocol tests for addts/delts"""
115 # configure ap with VO and VI requiring admission-control
116 hapd = add_wmm_ap(apdev[0], ["VO", "VI"])
117 dev[0].connect("wmm_ac", key_mgmt="NONE", scan_freq="2462")
119 dev[0].dump_monitor()
120 hapd.set("ext_mgmt_frame_handling", "1")
124 # timeout on ADDTS response
125 dev[0].add_ts(tsid, 7, expect_failure=True)
128 req = "WMM_AC_ADDTS downlink tsid=6 up=7 nominal_msdu_size=1500 sba=9000 mean_data_rate=1500 min_phy_rate=6000000"
129 if "OK" not in dev[0].request(req):
130 raise Exception("WMM_AC_ADDTS failed")
131 # a new request while previous is still pending
132 if "FAIL" not in dev[0].request(req):
133 raise Exception("WMM_AC_ADDTS accepted while oen was still pending")
135 payload = msg['payload']
136 (categ, action, dialog, status) = struct.unpack('BBBB', payload[0:4])
138 raise Exception("Unexpected Action code: %d" % action)
140 msg['da'] = msg['sa']
141 msg['sa'] = apdev[0]['bssid']
143 # unexpected dialog token
144 msg['payload'] = struct.pack('BBBB', 17, 1, (dialog + 1) & 0xff, 0) + payload[4:]
148 msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0) + payload[4:]
150 ev = dev[0].wait_event(["TSPEC-ADDED"], timeout=10)
152 raise Exception("Timeout on TSPEC-ADDED")
153 if "tsid=%d" % tsid not in ev:
154 raise Exception("Unexpected TSPEC-ADDED contents: " + ev)
156 # duplicated response
157 msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0) + payload[4:]
161 msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0)
165 msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0) + payload[4:] + struct.pack('BB', 0xdd, 100)
168 # too short WMM element
169 msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0) + payload[4:] + '\xdd\x06\x00\x50\xf2\x02\x02\x01'
173 dev[0].dump_monitor()
174 msg['payload'] = struct.pack('BBBB', 17, 2, 0, 0) + payload[4:]
176 ev = dev[0].wait_event(['TSPEC-REMOVED'], timeout=6)
178 raise Exception("Timeout on TSPEC-REMOVED event")
179 if "tsid=%d" % tsid not in ev:
180 raise Exception("Unexpected TSPEC-REMOVED contents: " + ev)
182 msg['payload'] = struct.pack('BBBB', 17, 2, 0, 0) + payload[4:]
185 # start a new request
187 if "OK" not in dev[0].request(req):
188 raise Exception("WMM_AC_ADDTS failed")
190 payload = msg['payload']
191 (categ, action, dialog, status) = struct.unpack('BBBB', payload[0:4])
193 raise Exception("Unexpected Action code: %d" % action)
195 msg['da'] = msg['sa']
196 msg['sa'] = apdev[0]['bssid']
198 # modified parameters
199 msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 1) + payload[4:12] + struct.pack('B', ord(payload[12]) & ~0x60) + payload[13:]
203 msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 1) + payload[4:]
205 ev = dev[0].wait_event(["TSPEC-REQ-FAILED"], timeout=10)
207 raise Exception("Timeout on TSPEC-REQ-FAILED")
208 if "tsid=%d" % tsid not in ev:
209 raise Exception("Unexpected TSPEC-REQ-FAILED contents: " + ev)
211 hapd.set("ext_mgmt_frame_handling", "0")
214 def test_tspec_not_enabled(dev, apdev):
215 """addts failing if AP does not support WMM"""
216 params = { "ssid": "wmm_no_ac",
219 "wmm_enabled" : "0" }
220 hapd = hostapd.add_ap(apdev[0], params)
221 dev[0].connect("wmm_no_ac", key_mgmt="NONE", scan_freq="2462")
222 status = dev[0].request("WMM_AC_STATUS")
223 if "Not associated to a WMM AP, WMM AC is Disabled" not in status:
224 raise Exception("Unexpected WMM_AC_STATUS: " + status)
228 raise Exception("ADDTS succeeded although it should have failed")
230 if not str(e).startswith("ADDTS failed"):
233 # attempt to delete non-existing tsid
236 raise Exception("DELTS succeeded although it should have failed")
238 if not str(e).startswith("DELTS failed"):
241 # unexpected Action frame when WMM is disabled
242 MGMT_SUBTYPE_ACTION = 13
244 msg['fc'] = MGMT_SUBTYPE_ACTION << 4
245 msg['da'] = dev[0].p2p_interface_addr()
246 msg['sa'] = apdev[0]['bssid']
247 msg['bssid'] = apdev[0]['bssid']
248 msg['payload'] = struct.pack('BBBB', 17, 2, 0, 0)
252 def test_tspec_ap_roam_open(dev, apdev):
253 """Roam between two open APs while having tspecs"""
254 hapd0 = add_wmm_ap(apdev[0], ["VO", "VI"])
255 dev[0].connect("wmm_ac", key_mgmt="NONE")
256 hwsim_utils.test_connectivity(dev[0], hapd0)
259 hapd1 = add_wmm_ap(apdev[1], ["VO", "VI"])
260 dev[0].scan_for_bss(apdev[1]['bssid'], freq=2462)
261 dev[0].roam(apdev[1]['bssid'])
262 hwsim_utils.test_connectivity(dev[0], hapd1)
264 raise Exception("TSPECs weren't deleted on roaming")
266 dev[0].scan_for_bss(apdev[0]['bssid'], freq=2462)
267 dev[0].roam(apdev[0]['bssid'])
268 hwsim_utils.test_connectivity(dev[0], hapd0)
271 def test_tspec_reassoc(dev, apdev):
272 """Reassociation to same BSS while having tspecs"""
273 hapd0 = add_wmm_ap(apdev[0], ["VO", "VI"])
274 dev[0].connect("wmm_ac", key_mgmt="NONE")
275 hwsim_utils.test_connectivity(dev[0], hapd0)
277 last_tspecs = dev[0].tspecs()
279 dev[0].request("REASSOCIATE")
280 dev[0].wait_connected()
282 hwsim_utils.test_connectivity(dev[0], hapd0)
283 if dev[0].tspecs() != last_tspecs:
284 raise Exception("TSPECs weren't saved on reassociation")