Updated to hostap_2_6
[mech_eap.git] / libeap / tests / hwsim / test_wpas_wmm_ac.py
1 # Test cases for wpa_supplicant WMM-AC operations
2 # Copyright (c) 2014, Intel Corporation
3 #
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
6
7 from remotehost import remote_compatible
8 import logging
9 logger = logging.getLogger()
10 import struct
11
12 import hwsim_utils
13 import hostapd
14
15 def add_wmm_ap(apdev, acm_list):
16     params = { "ssid": "wmm_ac",
17                "hw_mode": "g",
18                "channel": "11",
19                "wmm_enabled" : "1"}
20
21     for ac in acm_list:
22         params["wmm_ac_%s_acm" % (ac.lower())] = "1"
23
24     return hostapd.add_ap(apdev, params)
25
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")
35     if "TSID" in status:
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)
45
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")
49     # no direction
50     if "FAIL" not in dev[0].request("WMM_AC_ADDTS tsid=5"):
51         raise Exception("Invalid WMM_AC_ADDTS accepted")
52     # param out of range
53     if "FAIL" not in dev[0].request("WMM_AC_ADDTS tsid=5 downlink"):
54         raise Exception("Invalid WMM_AC_ADDTS accepted")
55
56     tsid = 5
57
58     # make sure we fail when the ac is not configured for acm
59     try:
60         dev[0].add_ts(tsid, 3)
61         raise Exception("ADDTS succeeded although it should have failed")
62     except Exception, e:
63         if not str(e).startswith("ADDTS failed"):
64             raise
65     status = dev[0].request("WMM_AC_STATUS")
66     if "TSID" in status:
67         raise Exception("Unexpected TSID info")
68
69     # add tspec for UP=6
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")
74
75     # using the same tsid for a different ac is invalid
76     try:
77         dev[0].add_ts(tsid, 5)
78         raise Exception("ADDTS succeeded although it should have failed")
79     except Exception, e:
80         if not str(e).startswith("ADDTS failed"):
81             raise
82
83     # update the tspec for a different UP of the same ac
84     dev[0].add_ts(tsid, 7, extra="fixed_nominal_msdu")
85     dev[0].del_ts(tsid)
86     status = dev[0].request("WMM_AC_STATUS")
87     if "TSID" in status:
88         raise Exception("Unexpected TSID info")
89
90     # verify failure on uplink/bidi without driver support
91     tsid = 6
92     try:
93         dev[0].add_ts(tsid, 7, direction="uplink")
94         raise Exception("ADDTS succeeded although it should have failed")
95     except Exception, e:
96         if not str(e).startswith("ADDTS failed"):
97             raise
98     try:
99         dev[0].add_ts(tsid, 7, direction="bidi")
100         raise Exception("ADDTS succeeded although it should have failed")
101     except Exception, e:
102         if not str(e).startswith("ADDTS failed"):
103             raise
104
105     # attempt to delete non-existing tsid
106     try:
107         dev[0].del_ts(tsid)
108         raise Exception("DELTS succeeded although it should have failed")
109     except Exception, e:
110         if not str(e).startswith("DELTS failed"):
111             raise
112
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")
118
119     dev[0].dump_monitor()
120     hapd.set("ext_mgmt_frame_handling", "1")
121
122     tsid = 6
123
124     # timeout on ADDTS response
125     dev[0].add_ts(tsid, 7, expect_failure=True)
126
127     hapd.dump_monitor()
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")
134     msg = hapd.mgmt_rx()
135     payload = msg['payload']
136     (categ, action, dialog, status) = struct.unpack('BBBB', payload[0:4])
137     if action != 0:
138         raise Exception("Unexpected Action code: %d" % action)
139
140     msg['da'] = msg['sa']
141     msg['sa'] = apdev[0]['bssid']
142
143     # unexpected dialog token
144     msg['payload'] = struct.pack('BBBB', 17, 1, (dialog + 1) & 0xff, 0) + payload[4:]
145     hapd.mgmt_tx(msg)
146
147     # valid response
148     msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0) + payload[4:]
149     hapd.mgmt_tx(msg)
150     ev = dev[0].wait_event(["TSPEC-ADDED"], timeout=10)
151     if ev is None:
152         raise Exception("Timeout on TSPEC-ADDED")
153     if "tsid=%d" % tsid not in ev:
154         raise Exception("Unexpected TSPEC-ADDED contents: " + ev)
155
156     # duplicated response
157     msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0) + payload[4:]
158     hapd.mgmt_tx(msg)
159
160     # too short ADDTS
161     msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0)
162     hapd.mgmt_tx(msg)
163
164     # invalid IE
165     msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 0) + payload[4:] + struct.pack('BB', 0xdd, 100)
166     hapd.mgmt_tx(msg)
167
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'
170     hapd.mgmt_tx(msg)
171
172     # DELTS
173     dev[0].dump_monitor()
174     msg['payload'] = struct.pack('BBBB', 17, 2, 0, 0) + payload[4:]
175     hapd.mgmt_tx(msg)
176     ev = dev[0].wait_event(['TSPEC-REMOVED'], timeout=6)
177     if ev is None:
178         raise Exception("Timeout on TSPEC-REMOVED event")
179     if "tsid=%d" % tsid not in ev:
180         raise Exception("Unexpected TSPEC-REMOVED contents: " + ev)
181     # DELTS duplicated
182     msg['payload'] = struct.pack('BBBB', 17, 2, 0, 0) + payload[4:]
183     hapd.mgmt_tx(msg)
184
185     # start a new request
186     hapd.dump_monitor()
187     if "OK" not in dev[0].request(req):
188         raise Exception("WMM_AC_ADDTS failed")
189     msg = hapd.mgmt_rx()
190     payload = msg['payload']
191     (categ, action, dialog, status) = struct.unpack('BBBB', payload[0:4])
192     if action != 0:
193         raise Exception("Unexpected Action code: %d" % action)
194
195     msg['da'] = msg['sa']
196     msg['sa'] = apdev[0]['bssid']
197
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:]
200     hapd.mgmt_tx(msg)
201
202     # reject request
203     msg['payload'] = struct.pack('BBBB', 17, 1, dialog, 1) + payload[4:]
204     hapd.mgmt_tx(msg)
205     ev = dev[0].wait_event(["TSPEC-REQ-FAILED"], timeout=10)
206     if ev is None:
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)
210
211     hapd.set("ext_mgmt_frame_handling", "0")
212
213 @remote_compatible
214 def test_tspec_not_enabled(dev, apdev):
215     """addts failing if AP does not support WMM"""
216     params = { "ssid": "wmm_no_ac",
217                "hw_mode": "g",
218                "channel": "11",
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)
225
226     try:
227         dev[0].add_ts(5, 6)
228         raise Exception("ADDTS succeeded although it should have failed")
229     except Exception, e:
230         if not str(e).startswith("ADDTS failed"):
231             raise
232
233     # attempt to delete non-existing tsid
234     try:
235         dev[0].del_ts(5)
236         raise Exception("DELTS succeeded although it should have failed")
237     except Exception, e:
238         if not str(e).startswith("DELTS failed"):
239             raise
240
241     # unexpected Action frame when WMM is disabled
242     MGMT_SUBTYPE_ACTION = 13
243     msg = {}
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)
249     hapd.mgmt_tx(msg)
250
251 @remote_compatible
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)
257     dev[0].add_ts(5, 6)
258
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)
263     if dev[0].tspecs():
264         raise Exception("TSPECs weren't deleted on roaming")
265
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)
269
270 @remote_compatible
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)
276     dev[0].add_ts(5, 6)
277     last_tspecs = dev[0].tspecs()
278
279     dev[0].request("REASSOCIATE")
280     dev[0].wait_connected()
281
282     hwsim_utils.test_connectivity(dev[0], hapd0)
283     if dev[0].tspecs() != last_tspecs:
284         raise Exception("TSPECs weren't saved on reassociation")