]>
Commit | Line | Data |
---|---|---|
6435799b | 1 | # WNM tests |
2de01c9d | 2 | # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi> |
6435799b JM |
3 | # |
4 | # This software may be distributed under the terms of the BSD license. | |
5 | # See README for more details. | |
6 | ||
2de01c9d JM |
7 | import binascii |
8 | import struct | |
6435799b JM |
9 | import time |
10 | import logging | |
11 | logger = logging.getLogger() | |
13f8d51e | 12 | import subprocess |
6435799b JM |
13 | |
14 | import hostapd | |
fb915d50 | 15 | from wpasupplicant import WpaSupplicant |
cd54a3ed | 16 | from utils import alloc_fail, wait_fail_trigger |
b2edaa43 | 17 | from wlantest import Wlantest |
6435799b JM |
18 | |
19 | def test_wnm_bss_transition_mgmt(dev, apdev): | |
20 | """WNM BSS Transition Management""" | |
21 | params = { "ssid": "test-wnm", | |
22 | "time_advertisement": "2", | |
23 | "time_zone": "EST5", | |
24 | "wnm_sleep_mode": "1", | |
25 | "bss_transition": "1" } | |
26 | hostapd.add_ap(apdev[0]['ifname'], params) | |
27 | ||
28 | dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412") | |
29 | dev[0].request("WNM_BSS_QUERY 0") | |
30 | ||
31 | def test_wnm_disassoc_imminent(dev, apdev): | |
32 | """WNM Disassociation Imminent""" | |
33 | params = { "ssid": "test-wnm", | |
34 | "time_advertisement": "2", | |
35 | "time_zone": "EST5", | |
36 | "wnm_sleep_mode": "1", | |
37 | "bss_transition": "1" } | |
38 | hostapd.add_ap(apdev[0]['ifname'], params) | |
39 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
40 | ||
41 | dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412") | |
42 | addr = dev[0].p2p_interface_addr() | |
43 | hapd.request("DISASSOC_IMMINENT " + addr + " 10") | |
44 | ev = dev[0].wait_event(["WNM: Disassociation Imminent"]) | |
45 | if ev is None: | |
46 | raise Exception("Timeout while waiting for disassociation imminent") | |
47 | if "Disassociation Timer 10" not in ev: | |
48 | raise Exception("Unexpected disassociation imminent contents") | |
49 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"]) | |
50 | if ev is None: | |
51 | raise Exception("Timeout while waiting for re-connection scan") | |
52 | ||
53 | def test_wnm_ess_disassoc_imminent(dev, apdev): | |
54 | """WNM ESS Disassociation Imminent""" | |
55 | params = { "ssid": "test-wnm", | |
56 | "time_advertisement": "2", | |
57 | "time_zone": "EST5", | |
58 | "wnm_sleep_mode": "1", | |
59 | "bss_transition": "1" } | |
60 | hostapd.add_ap(apdev[0]['ifname'], params) | |
61 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
62 | ||
63 | dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412") | |
64 | addr = dev[0].p2p_interface_addr() | |
65 | hapd.request("ESS_DISASSOC " + addr + " 10 http://example.com/session-info") | |
66 | ev = dev[0].wait_event(["ESS-DISASSOC-IMMINENT"]) | |
67 | if ev is None: | |
68 | raise Exception("Timeout while waiting for ESS disassociation imminent") | |
69 | if "0 1024 http://example.com/session-info" not in ev: | |
70 | raise Exception("Unexpected ESS disassociation imminent message contents") | |
71 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"]) | |
72 | if ev is None: | |
73 | raise Exception("Timeout while waiting for re-connection scan") | |
74 | ||
75 | def test_wnm_ess_disassoc_imminent_pmf(dev, apdev): | |
76 | """WNM ESS Disassociation Imminent""" | |
77 | params = hostapd.wpa2_params("test-wnm-rsn", "12345678") | |
78 | params["wpa_key_mgmt"] = "WPA-PSK-SHA256"; | |
79 | params["ieee80211w"] = "2"; | |
80 | params["bss_transition"] = "1" | |
81 | hostapd.add_ap(apdev[0]['ifname'], params) | |
82 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
83 | ||
84 | dev[0].connect("test-wnm-rsn", psk="12345678", ieee80211w="2", | |
85 | key_mgmt="WPA-PSK-SHA256", proto="WPA2", scan_freq="2412") | |
86 | addr = dev[0].p2p_interface_addr() | |
87 | hapd.request("ESS_DISASSOC " + addr + " 10 http://example.com/session-info") | |
88 | ev = dev[0].wait_event(["ESS-DISASSOC-IMMINENT"]) | |
89 | if ev is None: | |
90 | raise Exception("Timeout while waiting for ESS disassociation imminent") | |
91 | if "1 1024 http://example.com/session-info" not in ev: | |
92 | raise Exception("Unexpected ESS disassociation imminent message contents") | |
93 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"]) | |
94 | if ev is None: | |
95 | raise Exception("Timeout while waiting for re-connection scan") | |
96 | ||
a27f9f7a | 97 | def check_wnm_sleep_mode_enter_exit(hapd, dev, interval=None, tfs_req=None): |
6435799b JM |
98 | addr = dev.p2p_interface_addr() |
99 | sta = hapd.get_sta(addr) | |
100 | if "[WNM_SLEEP_MODE]" in sta['flags']: | |
101 | raise Exception("Station unexpectedly in WNM-Sleep Mode") | |
7f08b2f9 | 102 | |
6435799b | 103 | logger.info("Going to WNM Sleep Mode") |
a27f9f7a JM |
104 | extra = "" |
105 | if interval is not None: | |
106 | extra += " interval=" + str(interval) | |
107 | if tfs_req: | |
108 | extra += " tfs_req=" + tfs_req | |
109 | if "OK" not in dev.request("WNM_SLEEP enter" + extra): | |
110 | raise Exception("WNM_SLEEP failed") | |
7f08b2f9 JM |
111 | ok = False |
112 | for i in range(20): | |
113 | time.sleep(0.1) | |
114 | sta = hapd.get_sta(addr) | |
115 | if "[WNM_SLEEP_MODE]" in sta['flags']: | |
116 | ok = True | |
117 | break | |
118 | if not ok: | |
6435799b | 119 | raise Exception("Station failed to enter WNM-Sleep Mode") |
7f08b2f9 | 120 | |
6435799b | 121 | logger.info("Waking up from WNM Sleep Mode") |
7f08b2f9 | 122 | ok = False |
6435799b | 123 | dev.request("WNM_SLEEP exit") |
7f08b2f9 JM |
124 | for i in range(20): |
125 | time.sleep(0.1) | |
126 | sta = hapd.get_sta(addr) | |
127 | if "[WNM_SLEEP_MODE]" not in sta['flags']: | |
128 | ok = True | |
129 | break | |
130 | if not ok: | |
6435799b JM |
131 | raise Exception("Station failed to exit WNM-Sleep Mode") |
132 | ||
133 | def test_wnm_sleep_mode_open(dev, apdev): | |
134 | """WNM Sleep Mode - open""" | |
135 | params = { "ssid": "test-wnm", | |
136 | "time_advertisement": "2", | |
137 | "time_zone": "EST5", | |
138 | "wnm_sleep_mode": "1", | |
139 | "bss_transition": "1" } | |
140 | hostapd.add_ap(apdev[0]['ifname'], params) | |
141 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
142 | ||
143 | dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412") | |
7f08b2f9 JM |
144 | ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5) |
145 | if ev is None: | |
146 | raise Exception("No connection event received from hostapd") | |
6435799b | 147 | check_wnm_sleep_mode_enter_exit(hapd, dev[0]) |
a27f9f7a JM |
148 | check_wnm_sleep_mode_enter_exit(hapd, dev[0], interval=100) |
149 | check_wnm_sleep_mode_enter_exit(hapd, dev[0], tfs_req="5b17010001130e110000071122334455661122334455661234") | |
6435799b | 150 | |
f8423317 JM |
151 | cmds = [ "foo", |
152 | "exit tfs_req=123 interval=10", | |
153 | "enter tfs_req=qq interval=10" ] | |
154 | for cmd in cmds: | |
155 | if "FAIL" not in dev[0].request("WNM_SLEEP " + cmd): | |
156 | raise Exception("Invalid WNM_SLEEP accepted") | |
157 | ||
6435799b JM |
158 | def test_wnm_sleep_mode_rsn(dev, apdev): |
159 | """WNM Sleep Mode - RSN""" | |
160 | params = hostapd.wpa2_params("test-wnm-rsn", "12345678") | |
161 | params["time_advertisement"] = "2" | |
162 | params["time_zone"] = "EST5" | |
163 | params["wnm_sleep_mode"] = "1" | |
164 | params["bss_transition"] = "1" | |
165 | hostapd.add_ap(apdev[0]['ifname'], params) | |
166 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
167 | ||
168 | dev[0].connect("test-wnm-rsn", psk="12345678", scan_freq="2412") | |
7f08b2f9 JM |
169 | ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5) |
170 | if ev is None: | |
171 | raise Exception("No connection event received from hostapd") | |
6435799b JM |
172 | check_wnm_sleep_mode_enter_exit(hapd, dev[0]) |
173 | ||
cd54a3ed JM |
174 | def test_wnm_sleep_mode_ap_oom(dev, apdev): |
175 | """WNM Sleep Mode - AP side OOM""" | |
176 | params = { "ssid": "test-wnm", | |
177 | "wnm_sleep_mode": "1" } | |
178 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
179 | ||
180 | dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412") | |
181 | ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5) | |
182 | if ev is None: | |
183 | raise Exception("No connection event received from hostapd") | |
184 | with alloc_fail(hapd, 1, "ieee802_11_send_wnmsleep_resp"): | |
185 | dev[0].request("WNM_SLEEP enter") | |
186 | wait_fail_trigger(hapd, "GET_ALLOC_FAIL") | |
187 | with alloc_fail(hapd, 2, "ieee802_11_send_wnmsleep_resp"): | |
188 | dev[0].request("WNM_SLEEP exit") | |
189 | wait_fail_trigger(hapd, "GET_ALLOC_FAIL") | |
190 | ||
6435799b JM |
191 | def test_wnm_sleep_mode_rsn_pmf(dev, apdev): |
192 | """WNM Sleep Mode - RSN with PMF""" | |
b2edaa43 JM |
193 | wt = Wlantest() |
194 | wt.flush() | |
195 | wt.add_passphrase("12345678") | |
6435799b JM |
196 | params = hostapd.wpa2_params("test-wnm-rsn", "12345678") |
197 | params["wpa_key_mgmt"] = "WPA-PSK-SHA256"; | |
198 | params["ieee80211w"] = "2"; | |
199 | params["time_advertisement"] = "2" | |
200 | params["time_zone"] = "EST5" | |
201 | params["wnm_sleep_mode"] = "1" | |
202 | params["bss_transition"] = "1" | |
203 | hostapd.add_ap(apdev[0]['ifname'], params) | |
204 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
205 | ||
206 | dev[0].connect("test-wnm-rsn", psk="12345678", ieee80211w="2", | |
207 | key_mgmt="WPA-PSK-SHA256", proto="WPA2", scan_freq="2412") | |
7f08b2f9 JM |
208 | ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5) |
209 | if ev is None: | |
210 | raise Exception("No connection event received from hostapd") | |
6435799b | 211 | check_wnm_sleep_mode_enter_exit(hapd, dev[0]) |
2de01c9d JM |
212 | |
213 | MGMT_SUBTYPE_ACTION = 13 | |
214 | ACTION_CATEG_WNM = 10 | |
215 | WNM_ACT_BSS_TM_REQ = 7 | |
216 | WNM_ACT_BSS_TM_RESP = 8 | |
c4082f78 JM |
217 | WNM_ACT_SLEEP_MODE_REQ = 16 |
218 | WNM_ACT_SLEEP_MODE_RESP = 17 | |
219 | WNM_ACT_NOTIFICATION_REQ = 26 | |
220 | WNM_ACT_NOTIFICATION_RESP = 27 | |
221 | WNM_NOTIF_TYPE_FW_UPGRADE = 0 | |
222 | WNM_NOTIF_TYPE_WFA = 1 | |
223 | WLAN_EID_TFS_RESP = 92 | |
224 | WLAN_EID_WNMSLEEP = 93 | |
225 | WNM_SLEEP_MODE_ENTER = 0 | |
226 | WNM_SLEEP_MODE_EXIT = 1 | |
227 | WNM_STATUS_SLEEP_ACCEPT = 0 | |
228 | WNM_STATUS_SLEEP_EXIT_ACCEPT_GTK_UPDATE = 1 | |
229 | WNM_STATUS_DENIED_ACTION = 2 | |
230 | WNM_STATUS_DENIED_TMP = 3 | |
231 | WNM_STATUS_DENIED_KEY = 4 | |
232 | WNM_STATUS_DENIED_OTHER_WNM_SERVICE = 5 | |
233 | WNM_SLEEP_SUBELEM_GTK = 0 | |
234 | WNM_SLEEP_SUBELEM_IGTK = 1 | |
2de01c9d JM |
235 | |
236 | def bss_tm_req(dst, src, dialog_token=1, req_mode=0, disassoc_timer=0, | |
237 | validity_interval=1): | |
238 | msg = {} | |
239 | msg['fc'] = MGMT_SUBTYPE_ACTION << 4 | |
240 | msg['da'] = dst | |
241 | msg['sa'] = src | |
242 | msg['bssid'] = src | |
243 | msg['payload'] = struct.pack("<BBBBHB", | |
244 | ACTION_CATEG_WNM, WNM_ACT_BSS_TM_REQ, | |
245 | dialog_token, req_mode, disassoc_timer, | |
246 | validity_interval) | |
247 | return msg | |
248 | ||
249 | def rx_bss_tm_resp(hapd, expect_dialog=None, expect_status=None): | |
250 | for i in range(0, 100): | |
251 | resp = hapd.mgmt_rx() | |
252 | if resp is None: | |
253 | raise Exception("No BSS TM Response received") | |
254 | if resp['subtype'] == MGMT_SUBTYPE_ACTION: | |
255 | break | |
256 | if i == 99: | |
257 | raise Exception("Not an Action frame") | |
258 | payload = resp['payload'] | |
259 | if len(payload) < 2 + 3: | |
260 | raise Exception("Too short payload") | |
261 | (category, action) = struct.unpack('BB', payload[0:2]) | |
262 | if category != ACTION_CATEG_WNM or action != WNM_ACT_BSS_TM_RESP: | |
263 | raise Exception("Not a BSS TM Response") | |
264 | pos = payload[2:] | |
265 | (dialog, status, bss_term_delay) = struct.unpack('BBB', pos[0:3]) | |
266 | resp['dialog'] = dialog | |
267 | resp['status'] = status | |
268 | resp['bss_term_delay'] = bss_term_delay | |
269 | pos = pos[3:] | |
270 | if len(pos) >= 6 and status == 0: | |
271 | resp['target_bssid'] = binascii.hexlify(pos[0:6]) | |
272 | pos = pos[6:] | |
273 | resp['candidates'] = pos | |
274 | if expect_dialog is not None and dialog != expect_dialog: | |
275 | raise Exception("Unexpected dialog token") | |
276 | if expect_status is not None and status != expect_status: | |
277 | raise Exception("Unexpected status code %d" % status) | |
278 | return resp | |
279 | ||
73360424 | 280 | def expect_ack(hapd): |
2de01c9d JM |
281 | ev = hapd.wait_event(["MGMT-TX-STATUS"], timeout=5) |
282 | if ev is None: | |
283 | raise Exception("Missing TX status") | |
284 | if "ok=1" not in ev: | |
285 | raise Exception("Action frame not acknowledged") | |
286 | ||
287 | def test_wnm_bss_tm_req(dev, apdev): | |
288 | """BSS Transition Management Request""" | |
289 | params = { "ssid": "test-wnm", "bss_transition": "1" } | |
290 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
291 | dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412") | |
292 | hapd2 = hostapd.add_ap(apdev[1]['ifname'], params) | |
293 | ||
294 | hapd.set("ext_mgmt_frame_handling", "1") | |
295 | ||
296 | # truncated BSS TM Request | |
297 | req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'], | |
298 | req_mode=0x08) | |
299 | req['payload'] = struct.pack("<BBBBH", | |
300 | ACTION_CATEG_WNM, WNM_ACT_BSS_TM_REQ, | |
301 | 1, 0, 0) | |
302 | hapd.mgmt_tx(req) | |
73360424 | 303 | expect_ack(hapd) |
2de01c9d JM |
304 | |
305 | # no disassociation and no candidate list | |
306 | req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'], | |
307 | dialog_token=2) | |
308 | hapd.mgmt_tx(req) | |
309 | resp = rx_bss_tm_resp(hapd, expect_dialog=2, expect_status=1) | |
310 | ||
311 | # truncated BSS Termination Duration | |
312 | req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'], | |
313 | req_mode=0x08) | |
314 | hapd.mgmt_tx(req) | |
73360424 | 315 | expect_ack(hapd) |
2de01c9d JM |
316 | |
317 | # BSS Termination Duration with TSF=0 and Duration=10 | |
318 | req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'], | |
319 | req_mode=0x08, dialog_token=3) | |
320 | req['payload'] += struct.pack("<BBQH", 4, 10, 0, 10) | |
321 | hapd.mgmt_tx(req) | |
322 | resp = rx_bss_tm_resp(hapd, expect_dialog=3, expect_status=1) | |
323 | ||
324 | # truncated Session Information URL | |
325 | req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'], | |
326 | req_mode=0x10) | |
327 | hapd.mgmt_tx(req) | |
73360424 | 328 | expect_ack(hapd) |
2de01c9d JM |
329 | req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'], |
330 | req_mode=0x10) | |
331 | req['payload'] += struct.pack("<BBB", 3, 65, 66) | |
332 | hapd.mgmt_tx(req) | |
73360424 | 333 | expect_ack(hapd) |
2de01c9d JM |
334 | |
335 | # Session Information URL | |
336 | req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'], | |
337 | req_mode=0x10, dialog_token=4) | |
338 | req['payload'] += struct.pack("<BBB", 2, 65, 66) | |
339 | hapd.mgmt_tx(req) | |
340 | resp = rx_bss_tm_resp(hapd, expect_dialog=4, expect_status=0) | |
341 | ||
342 | # Preferred Candidate List without any entries | |
343 | req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'], | |
344 | req_mode=0x01, dialog_token=5) | |
345 | hapd.mgmt_tx(req) | |
ab4ee343 | 346 | resp = rx_bss_tm_resp(hapd, expect_dialog=5, expect_status=7) |
2de01c9d JM |
347 | |
348 | # Preferred Candidate List with a truncated entry | |
349 | req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'], | |
350 | req_mode=0x01) | |
351 | req['payload'] += struct.pack("<BB", 52, 1) | |
352 | hapd.mgmt_tx(req) | |
73360424 | 353 | expect_ack(hapd) |
2de01c9d JM |
354 | |
355 | # Preferred Candidate List with a too short entry | |
356 | req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'], | |
357 | req_mode=0x01, dialog_token=6) | |
358 | req['payload'] += struct.pack("<BB", 52, 0) | |
359 | hapd.mgmt_tx(req) | |
ab4ee343 | 360 | resp = rx_bss_tm_resp(hapd, expect_dialog=6, expect_status=7) |
2de01c9d JM |
361 | |
362 | # Preferred Candidate List with a non-matching entry | |
363 | req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'], | |
364 | req_mode=0x01, dialog_token=6) | |
365 | req['payload'] += struct.pack("<BB6BLBBB", 52, 13, | |
366 | 1, 2, 3, 4, 5, 6, | |
367 | 0, 81, 1, 7) | |
368 | hapd.mgmt_tx(req) | |
ab4ee343 | 369 | resp = rx_bss_tm_resp(hapd, expect_dialog=6, expect_status=7) |
d8e0013e JM |
370 | |
371 | # Preferred Candidate List with a truncated subelement | |
372 | req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'], | |
373 | req_mode=0x01, dialog_token=7) | |
374 | req['payload'] += struct.pack("<BB6BLBBBBB", 52, 13 + 2, | |
375 | 1, 2, 3, 4, 5, 6, | |
376 | 0, 81, 1, 7, | |
377 | 1, 1) | |
378 | hapd.mgmt_tx(req) | |
ab4ee343 | 379 | resp = rx_bss_tm_resp(hapd, expect_dialog=7, expect_status=7) |
d8e0013e JM |
380 | |
381 | # Preferred Candidate List with lots of invalid optional subelements | |
382 | req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'], | |
383 | req_mode=0x01, dialog_token=8) | |
384 | subelems = struct.pack("<BBHB", 1, 3, 0, 100) | |
385 | subelems += struct.pack("<BBB", 2, 1, 65) | |
386 | subelems += struct.pack("<BB", 3, 0) | |
387 | subelems += struct.pack("<BBQB", 4, 9, 0, 10) | |
388 | subelems += struct.pack("<BBHLB", 5, 7, 0, 0, 0) | |
389 | subelems += struct.pack("<BB", 66, 0) | |
390 | subelems += struct.pack("<BBBBBB", 70, 4, 0, 0, 0, 0) | |
391 | subelems += struct.pack("<BB", 71, 0) | |
392 | req['payload'] += struct.pack("<BB6BLBBB", 52, 13 + len(subelems), | |
393 | 1, 2, 3, 4, 5, 6, | |
394 | 0, 81, 1, 7) + subelems | |
395 | hapd.mgmt_tx(req) | |
ab4ee343 | 396 | resp = rx_bss_tm_resp(hapd, expect_dialog=8, expect_status=7) |
d8e0013e JM |
397 | |
398 | # Preferred Candidate List with lots of valid optional subelements (twice) | |
399 | req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'], | |
400 | req_mode=0x01, dialog_token=8) | |
401 | # TSF Information | |
402 | subelems = struct.pack("<BBHH", 1, 4, 0, 100) | |
403 | # Condensed Country String | |
404 | subelems += struct.pack("<BBBB", 2, 2, 65, 66) | |
405 | # BSS Transition Candidate Preference | |
406 | subelems += struct.pack("<BBB", 3, 1, 100) | |
407 | # BSS Termination Duration | |
408 | subelems += struct.pack("<BBQH", 4, 10, 0, 10) | |
409 | # Bearing | |
410 | subelems += struct.pack("<BBHLH", 5, 8, 0, 0, 0) | |
411 | # Measurement Pilot Transmission | |
412 | subelems += struct.pack("<BBBBB", 66, 3, 0, 0, 0) | |
413 | # RM Enabled Capabilities | |
414 | subelems += struct.pack("<BBBBBBB", 70, 5, 0, 0, 0, 0, 0) | |
415 | # Multiple BSSID | |
416 | subelems += struct.pack("<BBBB", 71, 2, 0, 0) | |
417 | req['payload'] += struct.pack("<BB6BLBBB", 52, 13 + len(subelems) * 2, | |
418 | 1, 2, 3, 4, 5, 6, | |
419 | 0, 81, 1, 7) + subelems + subelems | |
420 | hapd.mgmt_tx(req) | |
ab4ee343 | 421 | resp = rx_bss_tm_resp(hapd, expect_dialog=8, expect_status=7) |
519c3f70 | 422 | |
f1e26f89 JM |
423 | # Preferred Candidate List followed by vendor element |
424 | req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'], | |
425 | req_mode=0x01, dialog_token=8) | |
426 | subelems = "" | |
427 | req['payload'] += struct.pack("<BB6BLBBB", 52, 13 + len(subelems), | |
428 | 1, 2, 3, 4, 5, 6, | |
429 | 0, 81, 1, 7) + subelems | |
430 | req['payload'] += binascii.unhexlify("DD0411223344") | |
431 | hapd.mgmt_tx(req) | |
432 | resp = rx_bss_tm_resp(hapd, expect_dialog=8, expect_status=7) | |
433 | ||
519c3f70 JM |
434 | def test_wnm_bss_keep_alive(dev, apdev): |
435 | """WNM keep-alive""" | |
436 | params = { "ssid": "test-wnm", | |
437 | "ap_max_inactivity": "1" } | |
e61f9087 | 438 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
519c3f70 | 439 | |
e61f9087 | 440 | addr = dev[0].p2p_interface_addr() |
519c3f70 | 441 | dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412") |
e61f9087 JM |
442 | start = hapd.get_sta(addr) |
443 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=2) | |
444 | if ev is not None: | |
445 | raise Exception("Unexpected disconnection") | |
446 | end = hapd.get_sta(addr) | |
447 | if int(end['rx_packets']) <= int(start['rx_packets']): | |
448 | raise Exception("No keep-alive packets received") | |
449 | try: | |
450 | # Disable client keep-alive so that hostapd will verify connection | |
451 | # with client poll | |
452 | dev[0].request("SET no_keep_alive 1") | |
453 | for i in range(60): | |
454 | sta = hapd.get_sta(addr) | |
455 | logger.info("timeout_next=%s rx_packets=%s tx_packets=%s" % (sta['timeout_next'], sta['rx_packets'], sta['tx_packets'])) | |
456 | if i > 1 and sta['timeout_next'] != "NULLFUNC POLL" and int(sta['tx_packets']) > int(end['tx_packets']): | |
457 | break | |
458 | ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5) | |
459 | if ev is not None: | |
460 | raise Exception("Unexpected disconnection (client poll expected)") | |
461 | finally: | |
462 | dev[0].request("SET no_keep_alive 0") | |
463 | if int(sta['tx_packets']) <= int(end['tx_packets']): | |
464 | raise Exception("No client poll packet seen") | |
13f8d51e JM |
465 | |
466 | def test_wnm_bss_tm(dev, apdev): | |
467 | """WNM BSS Transition Management""" | |
468 | try: | |
9d7fdac5 JM |
469 | hapd = None |
470 | hapd2 = None | |
13f8d51e JM |
471 | params = { "ssid": "test-wnm", |
472 | "country_code": "FI", | |
df4733df | 473 | "ieee80211d": "1", |
13f8d51e JM |
474 | "hw_mode": "g", |
475 | "channel": "1", | |
476 | "bss_transition": "1" } | |
477 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
478 | ||
479 | id = dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412") | |
480 | dev[0].set_network(id, "scan_freq", "") | |
481 | ||
482 | params = { "ssid": "test-wnm", | |
483 | "country_code": "FI", | |
df4733df | 484 | "ieee80211d": "1", |
13f8d51e JM |
485 | "hw_mode": "a", |
486 | "channel": "36", | |
487 | "bss_transition": "1" } | |
488 | hapd2 = hostapd.add_ap(apdev[1]['ifname'], params) | |
489 | ||
490 | addr = dev[0].p2p_interface_addr() | |
491 | dev[0].dump_monitor() | |
492 | ||
493 | logger.info("No neighbor list entries") | |
494 | if "OK" not in hapd.request("BSS_TM_REQ " + addr): | |
495 | raise Exception("BSS_TM_REQ command failed") | |
496 | ev = hapd.wait_event(['BSS-TM-RESP'], timeout=10) | |
497 | if ev is None: | |
498 | raise Exception("No BSS Transition Management Response") | |
499 | if addr not in ev: | |
500 | raise Exception("Unexpected BSS Transition Management Response address") | |
501 | if "status_code=0" in ev: | |
502 | raise Exception("BSS transition accepted unexpectedly") | |
503 | dev[0].dump_monitor() | |
504 | ||
505 | logger.info("Neighbor list entry, but not claimed as Preferred Candidate List") | |
506 | if "OK" not in hapd.request("BSS_TM_REQ " + addr + " neighbor=11:22:33:44:55:66,0x0000,81,3,7"): | |
507 | raise Exception("BSS_TM_REQ command failed") | |
508 | ev = hapd.wait_event(['BSS-TM-RESP'], timeout=10) | |
509 | if ev is None: | |
510 | raise Exception("No BSS Transition Management Response") | |
511 | if "status_code=0" in ev: | |
512 | raise Exception("BSS transition accepted unexpectedly") | |
513 | dev[0].dump_monitor() | |
514 | ||
515 | logger.info("Preferred Candidate List (no matching neighbor) without Disassociation Imminent") | |
df4733df | 516 | if "OK" not in hapd.request("BSS_TM_REQ " + addr + " pref=1 neighbor=11:22:33:44:55:66,0x0000,81,3,7,0301ff neighbor=22:33:44:55:66:77,0x0000,1,36,7 neighbor=00:11:22:33:44:55,0x0000,81,4,7,03010a"): |
13f8d51e JM |
517 | raise Exception("BSS_TM_REQ command failed") |
518 | ev = hapd.wait_event(['BSS-TM-RESP'], timeout=10) | |
519 | if ev is None: | |
520 | raise Exception("No BSS Transition Management Response") | |
521 | if "status_code=0" in ev: | |
522 | raise Exception("BSS transition accepted unexpectedly") | |
523 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5) | |
524 | if ev is None: | |
525 | raise Exception("No scan started") | |
526 | dev[0].dump_monitor() | |
527 | ||
528 | logger.info("Preferred Candidate List (matching neighbor for another BSS) without Disassociation Imminent") | |
529 | if "OK" not in hapd.request("BSS_TM_REQ " + addr + " pref=1 abridged=1 valid_int=255 neighbor=" + apdev[1]['bssid'] + ",0x0000,115,36,7,0301ff"): | |
530 | raise Exception("BSS_TM_REQ command failed") | |
531 | ev = hapd.wait_event(['BSS-TM-RESP'], timeout=10) | |
532 | if ev is None: | |
533 | raise Exception("No BSS Transition Management Response") | |
534 | if "status_code=0" not in ev: | |
535 | raise Exception("BSS transition request was not accepted: " + ev) | |
536 | if "target_bssid=" + apdev[1]['bssid'] not in ev: | |
537 | raise Exception("Unexpected target BSS: " + ev) | |
5f35a5e2 | 538 | dev[0].wait_connected(timeout=15, error="No reassociation seen") |
13f8d51e JM |
539 | if apdev[1]['bssid'] not in ev: |
540 | raise Exception("Unexpected reassociation target: " + ev) | |
541 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=0.1) | |
542 | if ev is not None: | |
543 | raise Exception("Unexpected scan started") | |
544 | dev[0].dump_monitor() | |
545 | ||
546 | logger.info("Preferred Candidate List with two matches, no roam needed") | |
547 | if "OK" not in hapd2.request("BSS_TM_REQ " + addr + " pref=1 abridged=1 valid_int=255 neighbor=" + apdev[0]['bssid'] + ",0x0000,81,1,7,030101 neighbor=" + apdev[1]['bssid'] + ",0x0000,115,36,7,0301ff"): | |
548 | raise Exception("BSS_TM_REQ command failed") | |
549 | ev = hapd2.wait_event(['BSS-TM-RESP'], timeout=10) | |
550 | if ev is None: | |
551 | raise Exception("No BSS Transition Management Response") | |
552 | if "status_code=0" not in ev: | |
553 | raise Exception("BSS transition request was not accepted: " + ev) | |
554 | if "target_bssid=" + apdev[1]['bssid'] not in ev: | |
555 | raise Exception("Unexpected target BSS: " + ev) | |
556 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=0.1) | |
557 | if ev is not None: | |
558 | raise Exception("Unexpected scan started") | |
559 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.5) | |
560 | if ev is not None: | |
561 | raise Exception("Unexpected reassociation"); | |
562 | finally: | |
9d7fdac5 JM |
563 | dev[0].request("DISCONNECT") |
564 | if hapd: | |
565 | hapd.request("DISABLE") | |
566 | if hapd2: | |
567 | hapd2.request("DISABLE") | |
13f8d51e | 568 | subprocess.call(['iw', 'reg', 'set', '00']) |
9d7fdac5 | 569 | dev[0].flush_scan_cache() |
8cc9bc07 | 570 | |
13a17a77 JM |
571 | def test_wnm_bss_tm_scan_not_needed(dev, apdev): |
572 | """WNM BSS Transition Management and scan not needed""" | |
573 | try: | |
574 | hapd = None | |
575 | hapd2 = None | |
576 | params = { "ssid": "test-wnm", | |
577 | "country_code": "FI", | |
578 | "ieee80211d": "1", | |
579 | "hw_mode": "g", | |
580 | "channel": "1", | |
581 | "bss_transition": "1" } | |
582 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
583 | ||
584 | params = { "ssid": "test-wnm", | |
585 | "country_code": "FI", | |
586 | "ieee80211d": "1", | |
587 | "hw_mode": "a", | |
588 | "channel": "36", | |
589 | "bss_transition": "1" } | |
590 | hapd2 = hostapd.add_ap(apdev[1]['ifname'], params) | |
591 | ||
592 | dev[0].scan_for_bss(apdev[1]['bssid'], 5180) | |
593 | ||
594 | id = dev[0].connect("test-wnm", key_mgmt="NONE", | |
595 | bssid=apdev[0]['bssid'], scan_freq="2412") | |
596 | dev[0].set_network(id, "scan_freq", "") | |
597 | dev[0].set_network(id, "bssid", "") | |
598 | ||
599 | addr = dev[0].own_addr() | |
600 | dev[0].dump_monitor() | |
601 | ||
602 | logger.info("Preferred Candidate List (matching neighbor for another BSS) without Disassociation Imminent") | |
603 | if "OK" not in hapd.request("BSS_TM_REQ " + addr + " pref=1 abridged=1 valid_int=255 neighbor=" + apdev[1]['bssid'] + ",0x0000,115,36,7,0301ff"): | |
604 | raise Exception("BSS_TM_REQ command failed") | |
605 | ev = hapd.wait_event(['BSS-TM-RESP'], timeout=10) | |
606 | if ev is None: | |
607 | raise Exception("No BSS Transition Management Response") | |
608 | if "status_code=0" not in ev: | |
609 | raise Exception("BSS transition request was not accepted: " + ev) | |
610 | if "target_bssid=" + apdev[1]['bssid'] not in ev: | |
611 | raise Exception("Unexpected target BSS: " + ev) | |
612 | dev[0].wait_connected(timeout=15, error="No reassociation seen") | |
613 | if apdev[1]['bssid'] not in ev: | |
614 | raise Exception("Unexpected reassociation target: " + ev) | |
615 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=0.1) | |
616 | if ev is not None: | |
617 | raise Exception("Unexpected scan started") | |
618 | dev[0].dump_monitor() | |
619 | finally: | |
620 | dev[0].request("DISCONNECT") | |
621 | if hapd: | |
622 | hapd.request("DISABLE") | |
623 | if hapd2: | |
624 | hapd2.request("DISABLE") | |
625 | subprocess.call(['iw', 'reg', 'set', '00']) | |
626 | dev[0].flush_scan_cache() | |
627 | ||
628 | def test_wnm_bss_tm_scan_needed(dev, apdev): | |
629 | """WNM BSS Transition Management and scan needed""" | |
630 | try: | |
631 | hapd = None | |
632 | hapd2 = None | |
633 | params = { "ssid": "test-wnm", | |
634 | "country_code": "FI", | |
635 | "ieee80211d": "1", | |
636 | "hw_mode": "g", | |
637 | "channel": "1", | |
638 | "bss_transition": "1" } | |
639 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
640 | ||
641 | params = { "ssid": "test-wnm", | |
642 | "country_code": "FI", | |
643 | "ieee80211d": "1", | |
644 | "hw_mode": "a", | |
645 | "channel": "36", | |
646 | "bss_transition": "1" } | |
647 | hapd2 = hostapd.add_ap(apdev[1]['ifname'], params) | |
648 | ||
649 | dev[0].scan_for_bss(apdev[1]['bssid'], 5180) | |
650 | ||
651 | id = dev[0].connect("test-wnm", key_mgmt="NONE", | |
652 | bssid=apdev[0]['bssid'], scan_freq="2412") | |
653 | dev[0].set_network(id, "scan_freq", "") | |
654 | dev[0].set_network(id, "bssid", "") | |
655 | ||
656 | addr = dev[0].own_addr() | |
657 | dev[0].dump_monitor() | |
658 | ||
659 | logger.info("Wait 11 seconds for the last scan result to be too old, but still present in BSS table") | |
660 | time.sleep(11) | |
661 | logger.info("Preferred Candidate List (matching neighbor for another BSS) without Disassociation Imminent") | |
662 | if "OK" not in hapd.request("BSS_TM_REQ " + addr + " pref=1 abridged=1 valid_int=255 neighbor=" + apdev[1]['bssid'] + ",0x0000,115,36,7,0301ff"): | |
663 | raise Exception("BSS_TM_REQ command failed") | |
664 | ev = hapd.wait_event(['BSS-TM-RESP'], timeout=10) | |
665 | if ev is None: | |
666 | raise Exception("No BSS Transition Management Response") | |
667 | if "status_code=0" not in ev: | |
668 | raise Exception("BSS transition request was not accepted: " + ev) | |
669 | if "target_bssid=" + apdev[1]['bssid'] not in ev: | |
670 | raise Exception("Unexpected target BSS: " + ev) | |
671 | dev[0].wait_connected(timeout=15, error="No reassociation seen") | |
672 | if apdev[1]['bssid'] not in ev: | |
673 | raise Exception("Unexpected reassociation target: " + ev) | |
674 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=0.1) | |
675 | if ev is not None: | |
676 | raise Exception("Unexpected scan started") | |
677 | dev[0].dump_monitor() | |
678 | finally: | |
679 | dev[0].request("DISCONNECT") | |
680 | if hapd: | |
681 | hapd.request("DISABLE") | |
682 | if hapd2: | |
683 | hapd2.request("DISABLE") | |
684 | subprocess.call(['iw', 'reg', 'set', '00']) | |
685 | dev[0].flush_scan_cache() | |
686 | ||
8cc9bc07 JM |
687 | def start_wnm_tm(ap, country, dev): |
688 | params = { "ssid": "test-wnm", | |
689 | "country_code": country, | |
690 | "ieee80211d": "1", | |
691 | "hw_mode": "g", | |
692 | "channel": "1", | |
693 | "bss_transition": "1" } | |
694 | hapd = hostapd.add_ap(ap['ifname'], params) | |
695 | id = dev.connect("test-wnm", key_mgmt="NONE", scan_freq="2412") | |
696 | dev.dump_monitor() | |
697 | dev.set_network(id, "scan_freq", "") | |
698 | return hapd, id | |
699 | ||
700 | def stop_wnm_tm(hapd, dev): | |
701 | dev.request("DISCONNECT") | |
702 | try: | |
703 | dev.wait_disconnected() | |
704 | except: | |
705 | pass | |
706 | if hapd: | |
707 | hapd.request("DISABLE") | |
708 | subprocess.call(['iw', 'reg', 'set', '00']) | |
709 | dev.flush_scan_cache() | |
710 | ||
711 | def wnm_bss_tm_check(hapd, dev, data): | |
712 | addr = dev.p2p_interface_addr() | |
713 | if "OK" not in hapd.request("BSS_TM_REQ " + addr + " " + data): | |
714 | raise Exception("BSS_TM_REQ command failed") | |
715 | ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5) | |
716 | if ev is None: | |
717 | raise Exception("No scan started") | |
718 | ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15) | |
719 | if ev is None: | |
720 | raise Exception("Scan did not complete") | |
721 | ||
722 | ev = hapd.wait_event(['BSS-TM-RESP'], timeout=10) | |
723 | if ev is None: | |
724 | raise Exception("No BSS Transition Management Response") | |
725 | if "status_code=7" not in ev: | |
726 | raise Exception("Unexpected response: " + ev) | |
727 | ||
728 | def test_wnm_bss_tm_country_us(dev, apdev): | |
729 | """WNM BSS Transition Management (US)""" | |
730 | try: | |
731 | hapd = None | |
732 | hapd, id = start_wnm_tm(apdev[0], "US", dev[0]) | |
733 | ||
734 | logger.info("Preferred Candidate List (no matching neighbor, known channels)") | |
735 | wnm_bss_tm_check(hapd, dev[0], "pref=1 neighbor=11:22:33:44:55:66,0x0000,12,3,7,0301ff neighbor=00:11:22:33:44:55,0x0000,2,52,7,03010a neighbor=00:11:22:33:44:57,0x0000,4,100,7 neighbor=00:11:22:33:44:59,0x0000,3,149,7 neighbor=00:11:22:33:44:5b,0x0000,34,1,7 neighbor=00:11:22:33:44:5d,0x0000,5,149,7") | |
736 | ||
737 | # Make the test take less time by limiting full scans | |
738 | dev[0].set_network(id, "scan_freq", "2412") | |
739 | logger.info("Preferred Candidate List (no matching neighbor, unknown channels)") | |
740 | wnm_bss_tm_check(hapd, dev[0], "pref=1 neighbor=11:22:33:44:55:66,0x0000,12,0,7,0301ff neighbor=22:33:44:55:66:77,0x0000,12,12,7 neighbor=00:11:22:33:44:55,0x0000,2,35,7,03010a neighbor=00:11:22:33:44:56,0x0000,2,65,7 neighbor=00:11:22:33:44:57,0x0000,4,99,7 neighbor=00:11:22:33:44:58,0x0000,4,145,7") | |
741 | ||
742 | logger.info("Preferred Candidate List (no matching neighbor, unknown channels 2)") | |
743 | wnm_bss_tm_check(hapd, dev[0], "pref=1 neighbor=00:11:22:33:44:59,0x0000,3,148,7 neighbor=00:11:22:33:44:5a,0x0000,3,162,7 neighbor=00:11:22:33:44:5b,0x0000,34,0,7 neighbor=00:11:22:33:44:5c,0x0000,34,4,7 neighbor=00:11:22:33:44:5d,0x0000,5,148,7 neighbor=00:11:22:33:44:5e,0x0000,5,166,7 neighbor=00:11:22:33:44:5f,0x0000,0,0,7") | |
744 | finally: | |
745 | stop_wnm_tm(hapd, dev[0]) | |
746 | ||
747 | def test_wnm_bss_tm_country_fi(dev, apdev): | |
748 | """WNM BSS Transition Management (FI)""" | |
749 | addr = dev[0].p2p_interface_addr() | |
750 | try: | |
751 | hapd = None | |
752 | hapd, id = start_wnm_tm(apdev[0], "FI", dev[0]) | |
753 | ||
754 | logger.info("Preferred Candidate List (no matching neighbor, known channels)") | |
755 | wnm_bss_tm_check(hapd, dev[0], "pref=1 neighbor=11:22:33:44:55:66,0x0000,4,3,7,0301ff neighbor=00:11:22:33:44:55,0x0000,1,36,7,03010a neighbor=00:11:22:33:44:57,0x0000,3,100,7 neighbor=00:11:22:33:44:59,0x0000,17,149,7 neighbor=00:11:22:33:44:5c,0x0000,18,1,7") | |
756 | ||
757 | # Make the test take less time by limiting full scans | |
758 | dev[0].set_network(id, "scan_freq", "2412") | |
759 | logger.info("Preferred Candidate List (no matching neighbor, unknown channels)") | |
760 | wnm_bss_tm_check(hapd, dev[0], "pref=1 neighbor=00:11:22:33:44:00,0x0000,4,0,7 neighbor=00:11:22:33:44:01,0x0000,4,14,7 neighbor=00:11:22:33:44:02,0x0000,1,35,7 neighbor=00:11:22:33:44:03,0x0000,1,65,7 neighbor=00:11:22:33:44:04,0x0000,3,99,7 neighbor=00:11:22:33:44:05,0x0000,3,141,7 neighbor=00:11:22:33:44:06,0x0000,17,148,7 neighbor=00:11:22:33:44:07,0x0000,17,170,7 neighbor=00:11:22:33:44:08,0x0000,18,0,7 neighbor=00:11:22:33:44:09,0x0000,18,5,7") | |
761 | ||
762 | logger.info("Preferred Candidate List (no matching neighbor, unknown channels 2)") | |
763 | wnm_bss_tm_check(hapd, dev[0], "pref=1 neighbor=00:11:22:33:44:00,0x0000,0,0,7") | |
764 | finally: | |
765 | stop_wnm_tm(hapd, dev[0]) | |
766 | ||
767 | def test_wnm_bss_tm_country_jp(dev, apdev): | |
768 | """WNM BSS Transition Management (JP)""" | |
769 | addr = dev[0].p2p_interface_addr() | |
770 | try: | |
771 | hapd = None | |
772 | hapd, id = start_wnm_tm(apdev[0], "JP", dev[0]) | |
773 | ||
774 | logger.info("Preferred Candidate List (no matching neighbor, known channels)") | |
775 | wnm_bss_tm_check(hapd, dev[0], "pref=1 neighbor=11:22:33:44:55:66,0x0000,30,3,7,0301ff neighbor=00:11:22:33:44:55,0x0000,31,14,7,03010a neighbor=00:11:22:33:44:57,0x0000,1,36,7 neighbor=00:11:22:33:44:59,0x0000,34,100,7 neighbor=00:11:22:33:44:5c,0x0000,59,1,7") | |
776 | ||
777 | # Make the test take less time by limiting full scans | |
778 | dev[0].set_network(id, "scan_freq", "2412") | |
779 | logger.info("Preferred Candidate List (no matching neighbor, unknown channels)") | |
780 | wnm_bss_tm_check(hapd, dev[0], "pref=1 neighbor=11:22:33:44:55:66,0x0000,30,0,7,0301ff neighbor=22:33:44:55:66:77,0x0000,30,14,7 neighbor=00:11:22:33:44:56,0x0000,31,13,7 neighbor=00:11:22:33:44:57,0x0000,1,33,7 neighbor=00:11:22:33:44:58,0x0000,1,65,7 neighbor=00:11:22:33:44:5a,0x0000,34,99,7 neighbor=00:11:22:33:44:5b,0x0000,34,141,7 neighbor=00:11:22:33:44:5d,0x0000,59,0,7 neighbor=00:11:22:33:44:5e,0x0000,59,4,7 neighbor=00:11:22:33:44:5f,0x0000,0,0,7") | |
781 | finally: | |
782 | stop_wnm_tm(hapd, dev[0]) | |
783 | ||
784 | def test_wnm_bss_tm_country_cn(dev, apdev): | |
785 | """WNM BSS Transition Management (CN)""" | |
786 | addr = dev[0].p2p_interface_addr() | |
787 | try: | |
788 | hapd = None | |
789 | hapd, id = start_wnm_tm(apdev[0], "CN", dev[0]) | |
790 | ||
791 | logger.info("Preferred Candidate List (no matching neighbor, known channels)") | |
792 | wnm_bss_tm_check(hapd, dev[0], "pref=1 neighbor=11:22:33:44:55:66,0x0000,7,3,7,0301ff neighbor=00:11:22:33:44:55,0x0000,1,36,7,03010a neighbor=00:11:22:33:44:57,0x0000,3,149,7 neighbor=00:11:22:33:44:59,0x0000,6,149,7") | |
793 | ||
794 | # Make the test take less time by limiting full scans | |
795 | dev[0].set_network(id, "scan_freq", "2412") | |
796 | logger.info("Preferred Candidate List (no matching neighbor, unknown channels)") | |
797 | wnm_bss_tm_check(hapd, dev[0], "pref=1 neighbor=11:22:33:44:55:66,0x0000,7,0,7,0301ff neighbor=22:33:44:55:66:77,0x0000,7,14,7 neighbor=00:11:22:33:44:56,0x0000,1,35,7 neighbor=00:11:22:33:44:57,0x0000,1,65,7 neighbor=00:11:22:33:44:58,0x0000,3,148,7 neighbor=00:11:22:33:44:5a,0x0000,3,166,7 neighbor=00:11:22:33:44:5f,0x0000,0,0,7") | |
798 | finally: | |
799 | stop_wnm_tm(hapd, dev[0]) | |
800 | ||
801 | def test_wnm_bss_tm_global(dev, apdev): | |
802 | """WNM BSS Transition Management (global)""" | |
803 | addr = dev[0].p2p_interface_addr() | |
804 | try: | |
805 | hapd = None | |
806 | hapd, id = start_wnm_tm(apdev[0], "XX", dev[0]) | |
807 | ||
808 | logger.info("Preferred Candidate List (no matching neighbor, known channels)") | |
809 | wnm_bss_tm_check(hapd, dev[0], "pref=1 neighbor=11:22:33:44:55:66,0x0000,81,3,7,0301ff neighbor=00:11:22:33:44:55,0x0000,82,14,7,03010a neighbor=00:11:22:33:44:57,0x0000,83,1,7 neighbor=00:11:22:33:44:59,0x0000,115,36,7 neighbor=00:11:22:33:44:5a,0x0000,121,100,7 neighbor=00:11:22:33:44:5c,0x0000,124,149,7 neighbor=00:11:22:33:44:5d,0x0000,125,149,7 neighbor=00:11:22:33:44:5e,0x0000,128,42,7 neighbor=00:11:22:33:44:5f,0x0000,129,50,7 neighbor=00:11:22:33:44:60,0x0000,180,1,7") | |
810 | ||
811 | # Make the test take less time by limiting full scans | |
812 | dev[0].set_network(id, "scan_freq", "2412") | |
813 | logger.info("Preferred Candidate List (no matching neighbor, unknown channels)") | |
814 | wnm_bss_tm_check(hapd, dev[0], "pref=1 neighbor=00:11:22:33:44:00,0x0000,81,0,7 neighbor=00:11:22:33:44:01,0x0000,81,14,7 neighbor=00:11:22:33:44:02,0x0000,82,13,7 neighbor=00:11:22:33:44:03,0x0000,83,0,7 neighbor=00:11:22:33:44:04,0x0000,83,14,7 neighbor=00:11:22:33:44:05,0x0000,115,35,7 neighbor=00:11:22:33:44:06,0x0000,115,65,7 neighbor=00:11:22:33:44:07,0x0000,121,99,7 neighbor=00:11:22:33:44:08,0x0000,121,141,7 neighbor=00:11:22:33:44:09,0x0000,124,148,7") | |
815 | ||
816 | logger.info("Preferred Candidate List (no matching neighbor, unknown channels 2)") | |
817 | wnm_bss_tm_check(hapd, dev[0], "pref=1 neighbor=00:11:22:33:44:00,0x0000,124,162,7 neighbor=00:11:22:33:44:01,0x0000,125,148,7 neighbor=00:11:22:33:44:02,0x0000,125,170,7 neighbor=00:11:22:33:44:03,0x0000,128,35,7 neighbor=00:11:22:33:44:04,0x0000,128,162,7 neighbor=00:11:22:33:44:05,0x0000,129,49,7 neighbor=00:11:22:33:44:06,0x0000,129,115,7 neighbor=00:11:22:33:44:07,0x0000,180,0,7 neighbor=00:11:22:33:44:08,0x0000,180,5,7 neighbor=00:11:22:33:44:09,0x0000,0,0,7") | |
818 | finally: | |
819 | stop_wnm_tm(hapd, dev[0]) | |
c4082f78 | 820 | |
56153620 JM |
821 | def test_wnm_bss_tm_op_class_0(dev, apdev): |
822 | """WNM BSS Transition Management with invalid operating class""" | |
823 | try: | |
824 | hapd = None | |
825 | hapd, id = start_wnm_tm(apdev[0], "US", dev[0]) | |
826 | ||
827 | logger.info("Preferred Candidate List (no matching neighbor, invalid op class specified for channels)") | |
828 | wnm_bss_tm_check(hapd, dev[0], "pref=1 neighbor=00:11:22:33:44:59,0x0000,0,149,7 neighbor=00:11:22:33:44:5b,0x0000,0,1,7") | |
829 | finally: | |
830 | stop_wnm_tm(hapd, dev[0]) | |
831 | ||
c4082f78 JM |
832 | def test_wnm_action_proto(dev, apdev): |
833 | """WNM Action protocol testing""" | |
834 | params = { "ssid": "test-wnm" } | |
8823178c | 835 | params['wnm_sleep_mode'] = '1' |
c4082f78 JM |
836 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
837 | bssid = apdev[0]['bssid'] | |
838 | dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412") | |
8823178c JM |
839 | dev[0].request("WNM_SLEEP enter") |
840 | time.sleep(0.1) | |
c4082f78 JM |
841 | hapd.set("ext_mgmt_frame_handling", "1") |
842 | ||
843 | msg = {} | |
844 | msg['fc'] = MGMT_SUBTYPE_ACTION << 4 | |
845 | msg['da'] = dev[0].own_addr() | |
846 | msg['sa'] = bssid | |
847 | msg['bssid'] = bssid | |
848 | ||
849 | dialog_token = 1 | |
850 | ||
851 | logger.debug("Unexpected WNM-Notification Response") | |
852 | # Note: This is actually not registered for user space processing in | |
853 | # driver_nl80211.c nl80211_mgmt_subscribe_non_ap() and as such, won't make | |
854 | # it to wpa_supplicant. | |
855 | msg['payload'] = struct.pack("<BBBB", | |
856 | ACTION_CATEG_WNM, WNM_ACT_NOTIFICATION_RESP, | |
857 | dialog_token, 0) | |
858 | hapd.mgmt_tx(msg) | |
859 | expect_ack(hapd) | |
860 | ||
861 | logger.debug("Truncated WNM-Notification Request (no Type field)") | |
862 | msg['payload'] = struct.pack("<BBB", | |
863 | ACTION_CATEG_WNM, WNM_ACT_NOTIFICATION_REQ, | |
864 | dialog_token) | |
865 | hapd.mgmt_tx(msg) | |
866 | expect_ack(hapd) | |
867 | ||
868 | logger.debug("WFA WNM-Notification Request with truncated IE (min)") | |
869 | msg['payload'] = struct.pack("<BBBBBB", | |
870 | ACTION_CATEG_WNM, WNM_ACT_NOTIFICATION_REQ, | |
871 | dialog_token, WNM_NOTIF_TYPE_WFA, 0, 1) | |
872 | hapd.mgmt_tx(msg) | |
873 | expect_ack(hapd) | |
874 | ||
875 | logger.debug("WFA WNM-Notification Request with truncated IE (max)") | |
876 | msg['payload'] = struct.pack("<BBBBBB", | |
877 | ACTION_CATEG_WNM, WNM_ACT_NOTIFICATION_REQ, | |
878 | dialog_token, WNM_NOTIF_TYPE_WFA, 0, 255) | |
879 | hapd.mgmt_tx(msg) | |
880 | expect_ack(hapd) | |
881 | ||
882 | logger.debug("WFA WNM-Notification Request with too short IE") | |
883 | msg['payload'] = struct.pack("<BBBBBB", | |
884 | ACTION_CATEG_WNM, WNM_ACT_NOTIFICATION_REQ, | |
885 | dialog_token, WNM_NOTIF_TYPE_WFA, 0, 0) | |
886 | hapd.mgmt_tx(msg) | |
887 | expect_ack(hapd) | |
888 | ||
889 | logger.debug("WFA WNM-Notification Request with truncated Sub Rem URL") | |
890 | msg['payload'] = struct.pack(">BBBBBBLB", | |
891 | ACTION_CATEG_WNM, WNM_ACT_NOTIFICATION_REQ, | |
892 | dialog_token, WNM_NOTIF_TYPE_WFA, 0xdd, 5, | |
893 | 0x506f9a00, 1) | |
894 | hapd.mgmt_tx(msg) | |
895 | expect_ack(hapd) | |
896 | ||
897 | logger.debug("WFA WNM-Notification Request with truncated Sub Rem URL(2)") | |
898 | msg['payload'] = struct.pack(">BBBBBBLBB", | |
899 | ACTION_CATEG_WNM, WNM_ACT_NOTIFICATION_REQ, | |
900 | dialog_token, WNM_NOTIF_TYPE_WFA, 0xdd, 6, | |
901 | 0x506f9a00, 1, 0) | |
902 | hapd.mgmt_tx(msg) | |
903 | expect_ack(hapd) | |
904 | ||
905 | logger.debug("WFA WNM-Notification Request with truncated Sub Rem URL(3)") | |
906 | msg['payload'] = struct.pack(">BBBBBBLB", | |
907 | ACTION_CATEG_WNM, WNM_ACT_NOTIFICATION_REQ, | |
908 | dialog_token, WNM_NOTIF_TYPE_WFA, 0xdd, 5, | |
909 | 0x506f9a00, 0xff) | |
910 | hapd.mgmt_tx(msg) | |
911 | expect_ack(hapd) | |
912 | ||
913 | logger.debug("WFA WNM-Notification Request with truncated Deauth Imminent URL(min)") | |
914 | msg['payload'] = struct.pack(">BBBBBBLBHB", | |
915 | ACTION_CATEG_WNM, WNM_ACT_NOTIFICATION_REQ, | |
916 | dialog_token, WNM_NOTIF_TYPE_WFA, 0xdd, 8, | |
917 | 0x506f9a01, 0, 0, 1) | |
918 | hapd.mgmt_tx(msg) | |
919 | expect_ack(hapd) | |
920 | ||
921 | logger.debug("WFA WNM-Notification Request with truncated Deauth Imminent URL(max)") | |
922 | msg['payload'] = struct.pack(">BBBBBBLBHB", | |
923 | ACTION_CATEG_WNM, WNM_ACT_NOTIFICATION_REQ, | |
924 | dialog_token, WNM_NOTIF_TYPE_WFA, 0xdd, 8, | |
925 | 0x506f9a01, 0, 0, 0xff) | |
926 | hapd.mgmt_tx(msg) | |
927 | expect_ack(hapd) | |
928 | ||
929 | logger.debug("WFA WNM-Notification Request with unsupported IE") | |
930 | msg['payload'] = struct.pack("<BBBBBBL", | |
931 | ACTION_CATEG_WNM, WNM_ACT_NOTIFICATION_REQ, | |
932 | dialog_token, WNM_NOTIF_TYPE_WFA, 0xdd, 4, 0) | |
933 | hapd.mgmt_tx(msg) | |
934 | expect_ack(hapd) | |
935 | ||
936 | logger.debug("WNM-Notification Request with unknown WNM-Notification type 0") | |
937 | msg['payload'] = struct.pack("<BBBB", | |
938 | ACTION_CATEG_WNM, WNM_ACT_NOTIFICATION_REQ, | |
939 | dialog_token, WNM_NOTIF_TYPE_FW_UPGRADE) | |
940 | hapd.mgmt_tx(msg) | |
941 | expect_ack(hapd) | |
942 | ||
943 | logger.debug("Truncated WNM Sleep Mode Response - no Dialog Token") | |
944 | msg['payload'] = struct.pack("<BB", | |
945 | ACTION_CATEG_WNM, WNM_ACT_SLEEP_MODE_RESP) | |
946 | hapd.mgmt_tx(msg) | |
947 | expect_ack(hapd) | |
948 | ||
949 | logger.debug("Truncated WNM Sleep Mode Response - no Key Data Length") | |
950 | msg['payload'] = struct.pack("<BBB", | |
951 | ACTION_CATEG_WNM, WNM_ACT_SLEEP_MODE_RESP, 0) | |
952 | hapd.mgmt_tx(msg) | |
953 | expect_ack(hapd) | |
954 | ||
955 | logger.debug("Truncated WNM Sleep Mode Response - truncated Key Data (min)") | |
956 | msg['payload'] = struct.pack("<BBBH", | |
957 | ACTION_CATEG_WNM, WNM_ACT_SLEEP_MODE_RESP, 0, | |
958 | 1) | |
959 | hapd.mgmt_tx(msg) | |
960 | expect_ack(hapd) | |
961 | ||
962 | logger.debug("Truncated WNM Sleep Mode Response - truncated Key Data (max)") | |
963 | msg['payload'] = struct.pack("<BBBH", | |
964 | ACTION_CATEG_WNM, WNM_ACT_SLEEP_MODE_RESP, 0, | |
965 | 0xffff) | |
966 | hapd.mgmt_tx(msg) | |
967 | expect_ack(hapd) | |
968 | ||
969 | logger.debug("WNM Sleep Mode Response - truncated IE header") | |
970 | msg['payload'] = struct.pack("<BBBHB", | |
971 | ACTION_CATEG_WNM, WNM_ACT_SLEEP_MODE_RESP, 0, | |
972 | 0, 0) | |
973 | hapd.mgmt_tx(msg) | |
974 | expect_ack(hapd) | |
975 | ||
976 | logger.debug("WNM Sleep Mode Response - truncated IE") | |
977 | msg['payload'] = struct.pack("<BBBHBB", | |
978 | ACTION_CATEG_WNM, WNM_ACT_SLEEP_MODE_RESP, 0, | |
979 | 0, 0, 1) | |
980 | hapd.mgmt_tx(msg) | |
981 | expect_ack(hapd) | |
982 | ||
983 | logger.debug("WNM Sleep Mode Response - Empty TFS Response") | |
984 | msg['payload'] = struct.pack("<BBBHBB", | |
985 | ACTION_CATEG_WNM, WNM_ACT_SLEEP_MODE_RESP, 0, | |
986 | 0, WLAN_EID_TFS_RESP, 0) | |
987 | hapd.mgmt_tx(msg) | |
988 | expect_ack(hapd) | |
989 | ||
990 | logger.debug("WNM Sleep Mode Response - EID 0 not recognized") | |
991 | msg['payload'] = struct.pack("<BBBHBB", | |
992 | ACTION_CATEG_WNM, WNM_ACT_SLEEP_MODE_RESP, 0, | |
993 | 0, 0, 0) | |
994 | hapd.mgmt_tx(msg) | |
995 | expect_ack(hapd) | |
996 | ||
997 | logger.debug("WNM Sleep Mode Response - Empty WNM Sleep Mode element and TFS Response element") | |
998 | msg['payload'] = struct.pack("<BBBHBBBB", | |
999 | ACTION_CATEG_WNM, WNM_ACT_SLEEP_MODE_RESP, 0, | |
1000 | 0, WLAN_EID_WNMSLEEP, 0, WLAN_EID_TFS_RESP, 0) | |
1001 | hapd.mgmt_tx(msg) | |
1002 | expect_ack(hapd) | |
1003 | ||
1004 | logger.debug("WNM Sleep Mode Response - WNM Sleep Mode element and empty TFS Response element") | |
1005 | msg['payload'] = struct.pack("<BBBHBBBBHBB", | |
1006 | ACTION_CATEG_WNM, WNM_ACT_SLEEP_MODE_RESP, 0, | |
1007 | 0, WLAN_EID_WNMSLEEP, 4, WNM_SLEEP_MODE_ENTER, | |
1008 | WNM_STATUS_SLEEP_ACCEPT, 0, | |
1009 | WLAN_EID_TFS_RESP, 0) | |
1010 | hapd.mgmt_tx(msg) | |
1011 | expect_ack(hapd) | |
1012 | ||
1013 | logger.debug("WNM Sleep Mode Response - WNM Sleep Mode element(exit, deny key) and empty TFS Response element") | |
1014 | msg['payload'] = struct.pack("<BBBHBBBBHBB", | |
1015 | ACTION_CATEG_WNM, WNM_ACT_SLEEP_MODE_RESP, 0, | |
1016 | 0, WLAN_EID_WNMSLEEP, 4, WNM_SLEEP_MODE_EXIT, | |
1017 | WNM_STATUS_DENIED_KEY, 0, | |
1018 | WLAN_EID_TFS_RESP, 0) | |
1019 | hapd.mgmt_tx(msg) | |
1020 | expect_ack(hapd) | |
1021 | ||
1022 | logger.debug("WNM Sleep Mode Response - WNM Sleep Mode element(enter, deny key) and empty TFS Response element") | |
1023 | msg['payload'] = struct.pack("<BBBHBBBBHBB", | |
1024 | ACTION_CATEG_WNM, WNM_ACT_SLEEP_MODE_RESP, 0, | |
1025 | 0, WLAN_EID_WNMSLEEP, 4, WNM_SLEEP_MODE_ENTER, | |
1026 | WNM_STATUS_DENIED_KEY, 0, | |
1027 | WLAN_EID_TFS_RESP, 0) | |
1028 | hapd.mgmt_tx(msg) | |
1029 | expect_ack(hapd) | |
1030 | ||
1031 | def test_wnm_action_proto_pmf(dev, apdev): | |
1032 | """WNM Action protocol testing (PMF enabled)""" | |
1033 | ssid = "test-wnm-pmf" | |
1034 | params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678") | |
1035 | params["wpa_key_mgmt"] = "WPA-PSK-SHA256" | |
1036 | params["ieee80211w"] = "2" | |
8823178c | 1037 | params['wnm_sleep_mode'] = '1' |
c4082f78 JM |
1038 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
1039 | bssid = apdev[0]['bssid'] | |
1040 | dev[0].connect(ssid, psk="12345678", key_mgmt="WPA-PSK-SHA256", | |
1041 | proto="WPA2", ieee80211w="2", scan_freq="2412") | |
8823178c JM |
1042 | dev[0].request("WNM_SLEEP enter") |
1043 | time.sleep(0.1) | |
c4082f78 JM |
1044 | hapd.set("ext_mgmt_frame_handling", "1") |
1045 | ||
1046 | msg = {} | |
1047 | msg['fc'] = MGMT_SUBTYPE_ACTION << 4 | |
1048 | msg['da'] = dev[0].own_addr() | |
1049 | msg['sa'] = bssid | |
1050 | msg['bssid'] = bssid | |
1051 | ||
1052 | logger.debug("WNM Sleep Mode Response - Invalid Key Data element length") | |
1053 | keydata = struct.pack("<BB", 0, 1) | |
1054 | msg['payload'] = struct.pack("<BBBH", | |
1055 | ACTION_CATEG_WNM, WNM_ACT_SLEEP_MODE_RESP, 0, | |
1056 | len(keydata)) | |
1057 | msg['payload'] += keydata | |
1058 | msg['payload'] += struct.pack("<BBBBHBB", | |
1059 | WLAN_EID_WNMSLEEP, 4, WNM_SLEEP_MODE_EXIT, | |
1060 | WNM_STATUS_SLEEP_ACCEPT, 0, | |
1061 | WLAN_EID_TFS_RESP, 0) | |
1062 | hapd.mgmt_tx(msg) | |
1063 | expect_ack(hapd) | |
1064 | ||
1065 | logger.debug("WNM Sleep Mode Response - Too short GTK subelem") | |
1066 | keydata = struct.pack("<BB", WNM_SLEEP_SUBELEM_GTK, 0) | |
1067 | msg['payload'] = struct.pack("<BBBH", | |
1068 | ACTION_CATEG_WNM, WNM_ACT_SLEEP_MODE_RESP, 0, | |
1069 | len(keydata)) | |
1070 | msg['payload'] += keydata | |
1071 | msg['payload'] += struct.pack("<BBBBHBB", | |
1072 | WLAN_EID_WNMSLEEP, 4, WNM_SLEEP_MODE_EXIT, | |
1073 | WNM_STATUS_SLEEP_ACCEPT, 0, | |
1074 | WLAN_EID_TFS_RESP, 0) | |
1075 | hapd.mgmt_tx(msg) | |
1076 | expect_ack(hapd) | |
1077 | ||
1078 | logger.debug("WNM Sleep Mode Response - Invalid GTK subelem") | |
1079 | keydata = struct.pack("<BBHB2L4L", WNM_SLEEP_SUBELEM_GTK, 11 + 16, | |
1080 | 0, 17, 0, 0, 0, 0, 0, 0) | |
1081 | msg['payload'] = struct.pack("<BBBH", | |
1082 | ACTION_CATEG_WNM, WNM_ACT_SLEEP_MODE_RESP, 0, | |
1083 | len(keydata)) | |
1084 | msg['payload'] += keydata | |
1085 | msg['payload'] += struct.pack("<BBBBHBB", | |
1086 | WLAN_EID_WNMSLEEP, 4, WNM_SLEEP_MODE_EXIT, | |
1087 | WNM_STATUS_SLEEP_ACCEPT, 0, | |
1088 | WLAN_EID_TFS_RESP, 0) | |
1089 | hapd.mgmt_tx(msg) | |
1090 | expect_ack(hapd) | |
1091 | ||
1092 | logger.debug("WNM Sleep Mode Response - Invalid GTK subelem (2)") | |
1093 | keydata = struct.pack("<BBHB2L4L", WNM_SLEEP_SUBELEM_GTK, 11 + 16, | |
1094 | 0, 0, 0, 0, 0, 0, 0, 0) | |
1095 | msg['payload'] = struct.pack("<BBBH", | |
1096 | ACTION_CATEG_WNM, WNM_ACT_SLEEP_MODE_RESP, 0, | |
1097 | len(keydata)) | |
1098 | msg['payload'] += keydata | |
1099 | msg['payload'] += struct.pack("<BBBBHBB", | |
1100 | WLAN_EID_WNMSLEEP, 4, WNM_SLEEP_MODE_EXIT, | |
1101 | WNM_STATUS_SLEEP_ACCEPT, 0, | |
1102 | WLAN_EID_TFS_RESP, 0) | |
1103 | hapd.mgmt_tx(msg) | |
1104 | expect_ack(hapd) | |
1105 | ||
1106 | logger.debug("WNM Sleep Mode Response - GTK subelem and too short IGTK subelem") | |
1107 | keydata = struct.pack("<BBHB", WNM_SLEEP_SUBELEM_GTK, 11 + 16, 0, 16) | |
1108 | keydata += struct.pack(">2L4L", 0x01020304, 0x05060708, | |
1109 | 0x11223344, 0x55667788, 0x9900aabb, 0xccddeeff) | |
1110 | keydata += struct.pack("<BB", WNM_SLEEP_SUBELEM_IGTK, 0) | |
1111 | msg['payload'] = struct.pack("<BBBH", | |
1112 | ACTION_CATEG_WNM, WNM_ACT_SLEEP_MODE_RESP, 0, | |
1113 | len(keydata)) | |
1114 | msg['payload'] += keydata | |
1115 | msg['payload'] += struct.pack("<BBBBHBB", | |
1116 | WLAN_EID_WNMSLEEP, 4, WNM_SLEEP_MODE_EXIT, | |
1117 | WNM_STATUS_SLEEP_ACCEPT, 0, | |
1118 | WLAN_EID_TFS_RESP, 0) | |
1119 | hapd.mgmt_tx(msg) | |
1120 | expect_ack(hapd) | |
1121 | ||
1122 | logger.debug("WNM Sleep Mode Response - Unknown subelem") | |
1123 | keydata = struct.pack("<BB", 255, 0) | |
1124 | msg['payload'] = struct.pack("<BBBH", | |
1125 | ACTION_CATEG_WNM, WNM_ACT_SLEEP_MODE_RESP, 0, | |
1126 | len(keydata)) | |
1127 | msg['payload'] += keydata | |
1128 | msg['payload'] += struct.pack("<BBBBHBB", | |
1129 | WLAN_EID_WNMSLEEP, 4, WNM_SLEEP_MODE_EXIT, | |
1130 | WNM_STATUS_SLEEP_ACCEPT, 0, | |
1131 | WLAN_EID_TFS_RESP, 0) | |
1132 | hapd.mgmt_tx(msg) | |
1133 | expect_ack(hapd) | |
63a19e56 JM |
1134 | |
1135 | def test_wnm_action_proto_no_pmf(dev, apdev): | |
1136 | """WNM Action protocol testing (PMF disabled)""" | |
1137 | ssid = "test-wnm-no-pmf" | |
1138 | params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678") | |
8823178c | 1139 | params['wnm_sleep_mode'] = '1' |
63a19e56 JM |
1140 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
1141 | bssid = apdev[0]['bssid'] | |
1142 | dev[0].connect(ssid, psk="12345678", key_mgmt="WPA-PSK", | |
1143 | proto="WPA2", ieee80211w="0", scan_freq="2412") | |
8823178c JM |
1144 | dev[0].request("WNM_SLEEP enter") |
1145 | time.sleep(0.1) | |
63a19e56 JM |
1146 | hapd.set("ext_mgmt_frame_handling", "1") |
1147 | ||
1148 | msg = {} | |
1149 | msg['fc'] = MGMT_SUBTYPE_ACTION << 4 | |
1150 | msg['da'] = dev[0].own_addr() | |
1151 | msg['sa'] = bssid | |
1152 | msg['bssid'] = bssid | |
1153 | ||
1154 | logger.debug("WNM Sleep Mode Response - GTK subelem and IGTK subelem") | |
1155 | keydata = struct.pack("<BBHB", WNM_SLEEP_SUBELEM_GTK, 11 + 16, 0, 16) | |
1156 | keydata += struct.pack(">2L4L", 0x01020304, 0x05060708, | |
1157 | 0x11223344, 0x55667788, 0x9900aabb, 0xccddeeff) | |
1158 | keydata += struct.pack("<BBHLH4L", WNM_SLEEP_SUBELEM_IGTK, 2 + 6 + 16, 0, | |
1159 | 0x10203040, 0x5060, | |
1160 | 0xf1f2f3f4, 0xf5f6f7f8, 0xf9f0fafb, 0xfcfdfeff) | |
1161 | msg['payload'] = struct.pack("<BBBH", | |
1162 | ACTION_CATEG_WNM, WNM_ACT_SLEEP_MODE_RESP, 0, | |
1163 | len(keydata)) | |
1164 | msg['payload'] += keydata | |
1165 | msg['payload'] += struct.pack("<BBBBHBB", | |
1166 | WLAN_EID_WNMSLEEP, 4, WNM_SLEEP_MODE_EXIT, | |
1167 | WNM_STATUS_SLEEP_ACCEPT, 0, | |
1168 | WLAN_EID_TFS_RESP, 0) | |
1169 | hapd.mgmt_tx(msg) | |
1170 | expect_ack(hapd) | |
1171 | ||
1172 | ev = dev[0].wait_event(["WNM: Ignore Key Data"], timeout=5) | |
1173 | if ev is None: | |
1174 | raise Exception("Key Data not ignored") | |
85cc109e AS |
1175 | |
1176 | def test_wnm_bss_tm_req_with_mbo_ie(dev, apdev): | |
1177 | """WNM BSS transition request with MBO IE and reassociation delay attribute""" | |
1178 | ssid = "test-wnm-mbo" | |
1179 | params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678") | |
1180 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1181 | bssid = apdev[0]['bssid'] | |
1182 | if "OK" not in dev[0].request("SET mbo_cell_capa 1"): | |
1183 | raise Exception("Failed to set STA as cellular data capable") | |
1184 | ||
1185 | dev[0].connect(ssid, psk="12345678", key_mgmt="WPA-PSK", | |
1186 | proto="WPA2", ieee80211w="0", scan_freq="2412") | |
1187 | ||
1188 | logger.debug("BTM request with MBO reassociation delay when disassoc imminent is not set") | |
1189 | if 'FAIL' not in hapd.request("BSS_TM_REQ " + dev[0].own_addr() + " mbo=3:2:1"): | |
1190 | raise Exception("BSS transition management succeeded unexpectedly") | |
1191 | ||
1192 | logger.debug("BTM request with invalid MBO transition reason code") | |
1193 | if 'FAIL' not in hapd.request("BSS_TM_REQ " + dev[0].own_addr() + " mbo=10:2:1"): | |
1194 | raise Exception("BSS transition management succeeded unexpectedly") | |
1195 | ||
1196 | logger.debug("BTM request with MBO reassociation retry delay of 5 seconds") | |
1197 | if 'OK' not in hapd.request("BSS_TM_REQ " + dev[0].own_addr() + " disassoc_imminent=1 disassoc_timer=3 mbo=3:5:1"): | |
1198 | raise Exception("BSS transition management command failed") | |
1199 | ||
1200 | ev = dev[0].wait_event(['MBO-CELL-PREFERENCE'], 1) | |
1201 | if ev is None or "preference=1" not in ev: | |
1202 | raise Exception("Timeout waiting for MBO-CELL-PREFERENCE event") | |
1203 | ||
1204 | ev = dev[0].wait_event(['MBO-TRANSITION-REASON'], 1) | |
1205 | if ev is None or "reason=3" not in ev: | |
1206 | raise Exception("Timeout waiting for MBO-TRANSITION-REASON event") | |
1207 | ||
1208 | ev = hapd.wait_event(['BSS-TM-RESP'], timeout=10) | |
1209 | if ev is None: | |
1210 | raise Exception("No BSS Transition Management Response") | |
1211 | if dev[0].own_addr() not in ev: | |
1212 | raise Exception("Unexpected BSS Transition Management Response address") | |
1213 | ||
1214 | ev = dev[0].wait_event(['CTRL-EVENT-DISCONNECTED'], 5) | |
1215 | if ev is None: | |
1216 | raise Exception("Station did not disconnect although disassoc imminent was set") | |
1217 | ||
1218 | # Set the scan interval to make dev[0] look for connections | |
1219 | if 'OK' not in dev[0].request("SCAN_INTERVAL 1"): | |
1220 | raise Exception("Failed to set scan interval") | |
1221 | ||
1222 | # Make sure no connection is made during the retry delay | |
1223 | ev = dev[0].wait_event(['CTRL-EVENT-CONNECTED'], 5) | |
1224 | if ev is not None: | |
1225 | raise Exception("Station connected before assoc retry delay was over") | |
1226 | ||
1227 | # After the assoc retry delay is over, we can reconnect | |
1228 | ev = dev[0].wait_event(['CTRL-EVENT-CONNECTED'], 5) | |
1229 | if ev is None: | |
1230 | raise Exception("Station did not connect after assoc retry delay is over") | |
1231 | ||
1232 | if "OK" not in dev[0].request("SET mbo_cell_capa 3"): | |
1233 | raise Exception("Failed to set STA as cellular data not-capable") | |
c24c144f JM |
1234 | |
1235 | def test_wnm_bss_transition_mgmt_query(dev, apdev): | |
1236 | """WNM BSS Transition Management query""" | |
1237 | params = { "ssid": "test-wnm", | |
1238 | "bss_transition": "1" } | |
1239 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1240 | params = { "ssid": "another" } | |
1241 | hapd2 = hostapd.add_ap(apdev[1]['ifname'], params) | |
1242 | ||
1243 | dev[0].scan_for_bss(apdev[1]['bssid'], 2412) | |
1244 | dev[0].scan_for_bss(apdev[0]['bssid'], 2412) | |
1245 | ||
1246 | dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412") | |
1247 | dev[0].request("WNM_BSS_QUERY 0 list") | |
1248 | ||
1249 | ev = dev[0].wait_event(["WNM: BSS Transition Management Request"], | |
1250 | timeout=5) | |
1251 | if ev is None: | |
1252 | raise Exception("No BSS Transition Management Request frame seen") | |
1253 | ||
1254 | ev = hapd.wait_event(["BSS-TM-RESP"], timeout=5) | |
1255 | if ev is None: | |
1256 | raise Exception("No BSS Transition Management Response frame seen") | |
b495500f JM |
1257 | |
1258 | def test_wnm_bss_tm_security_mismatch(dev, apdev): | |
1259 | """WNM BSS Transition Management and security mismatch""" | |
1260 | params = { "ssid": "test-wnm", | |
1261 | "wpa": "2", | |
1262 | "wpa_key_mgmt": "WPA-PSK", | |
1263 | "rsn_pairwise": "CCMP", | |
1264 | "wpa_passphrase": "12345678", | |
1265 | "hw_mode": "g", | |
1266 | "channel": "1", | |
1267 | "bss_transition": "1" } | |
1268 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1269 | ||
1270 | params = { "ssid": "test-wnm", | |
1271 | "hw_mode": "g", | |
1272 | "channel": "11", | |
1273 | "bss_transition": "1" } | |
1274 | hapd2 = hostapd.add_ap(apdev[1]['ifname'], params) | |
1275 | ||
1276 | dev[0].scan_for_bss(apdev[1]['bssid'], 2462) | |
1277 | ||
1278 | id = dev[0].connect("test-wnm", psk="12345678", | |
1279 | bssid=apdev[0]['bssid'], scan_freq="2412") | |
1280 | dev[0].set_network(id, "scan_freq", "") | |
1281 | dev[0].set_network(id, "bssid", "") | |
1282 | ||
1283 | addr = dev[0].own_addr() | |
1284 | dev[0].dump_monitor() | |
1285 | ||
1286 | logger.info("Preferred Candidate List (matching neighbor for another BSS) without Disassociation Imminent") | |
1287 | if "OK" not in hapd.request("BSS_TM_REQ " + addr + " pref=1 abridged=1 valid_int=255 neighbor=" + apdev[1]['bssid'] + ",0x0000,115,36,7,0301ff"): | |
1288 | raise Exception("BSS_TM_REQ command failed") | |
1289 | ev = hapd.wait_event(['BSS-TM-RESP'], timeout=10) | |
1290 | if ev is None: | |
1291 | raise Exception("No BSS Transition Management Response") | |
1292 | if "status_code=7" not in ev: | |
1293 | raise Exception("Unexpected BSS transition request response: " + ev) | |
fb915d50 JM |
1294 | |
1295 | def test_wnm_bss_tm_connect_cmd(dev, apdev): | |
1296 | """WNM BSS Transition Management and cfg80211 connect command""" | |
1297 | params = { "ssid": "test-wnm", | |
1298 | "hw_mode": "g", | |
1299 | "channel": "1", | |
1300 | "bss_transition": "1" } | |
1301 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1302 | ||
1303 | params = { "ssid": "test-wnm", | |
1304 | "hw_mode": "g", | |
1305 | "channel": "11", | |
1306 | "bss_transition": "1" } | |
1307 | hapd2 = hostapd.add_ap(apdev[1]['ifname'], params) | |
1308 | ||
1309 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
1310 | wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") | |
1311 | ||
1312 | wpas.scan_for_bss(apdev[1]['bssid'], 2462) | |
1313 | ||
1314 | id = wpas.connect("test-wnm", key_mgmt="NONE", | |
1315 | bssid=apdev[0]['bssid'], scan_freq="2412") | |
1316 | wpas.set_network(id, "scan_freq", "") | |
1317 | wpas.set_network(id, "bssid", "") | |
1318 | ||
1319 | addr = wpas.own_addr() | |
1320 | wpas.dump_monitor() | |
1321 | ||
1322 | logger.info("Preferred Candidate List (matching neighbor for another BSS) without Disassociation Imminent") | |
1323 | if "OK" not in hapd.request("BSS_TM_REQ " + addr + " pref=1 abridged=1 valid_int=255 neighbor=" + apdev[1]['bssid'] + ",0x0000,115,36,7,0301ff"): | |
1324 | raise Exception("BSS_TM_REQ command failed") | |
1325 | ev = hapd.wait_event(['BSS-TM-RESP'], timeout=10) | |
1326 | if ev is None: | |
1327 | raise Exception("No BSS Transition Management Response") | |
1328 | if "status_code=0" not in ev: | |
1329 | raise Exception("BSS transition request was not accepted: " + ev) | |
1330 | if "target_bssid=" + apdev[1]['bssid'] not in ev: | |
1331 | raise Exception("Unexpected target BSS: " + ev) | |
1332 | ev = wpas.wait_event(["CTRL-EVENT-CONNECTED", | |
1333 | "CTRL-EVENT-DISCONNECTED"], timeout=10) | |
1334 | if ev is None: | |
1335 | raise Exception("No reassociation seen") | |
1336 | if "CTRL-EVENT-DISCONNECTED" in ev: | |
1337 | #TODO: Uncomment this once kernel side changes for Connect command | |
1338 | #reassociation are in upstream. | |
1339 | #raise Exception("Unexpected disconnection reported") | |
1340 | logger.info("Unexpected disconnection reported") | |
1341 | ev = wpas.wait_event(["CTRL-EVENT-CONNECTED"], timeout=10) | |
1342 | if ev is None: | |
1343 | raise Exception("No reassociation seen") | |
1344 | if apdev[1]['bssid'] not in ev: | |
1345 | raise Exception("Unexpected reassociation target: " + ev) |