tests: Try to clear scan results after regulatory domain changes
[mech_eap.git] / tests / hwsim / test_wnm.py
1 # WNM tests
2 # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi>
3 #
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
6
7 import binascii
8 import struct
9 import time
10 import logging
11 logger = logging.getLogger()
12 import subprocess
13
14 import hostapd
15 from wlantest import Wlantest
16
17 def test_wnm_bss_transition_mgmt(dev, apdev):
18     """WNM BSS Transition Management"""
19     params = { "ssid": "test-wnm",
20                "time_advertisement": "2",
21                "time_zone": "EST5",
22                "wnm_sleep_mode": "1",
23                "bss_transition": "1" }
24     hostapd.add_ap(apdev[0]['ifname'], params)
25
26     dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412")
27     dev[0].request("WNM_BSS_QUERY 0")
28
29 def test_wnm_disassoc_imminent(dev, apdev):
30     """WNM Disassociation Imminent"""
31     params = { "ssid": "test-wnm",
32                "time_advertisement": "2",
33                "time_zone": "EST5",
34                "wnm_sleep_mode": "1",
35                "bss_transition": "1" }
36     hostapd.add_ap(apdev[0]['ifname'], params)
37     hapd = hostapd.Hostapd(apdev[0]['ifname'])
38
39     dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412")
40     addr = dev[0].p2p_interface_addr()
41     hapd.request("DISASSOC_IMMINENT " + addr + " 10")
42     ev = dev[0].wait_event(["WNM: Disassociation Imminent"])
43     if ev is None:
44         raise Exception("Timeout while waiting for disassociation imminent")
45     if "Disassociation Timer 10" not in ev:
46         raise Exception("Unexpected disassociation imminent contents")
47     ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
48     if ev is None:
49         raise Exception("Timeout while waiting for re-connection scan")
50
51 def test_wnm_ess_disassoc_imminent(dev, apdev):
52     """WNM ESS Disassociation Imminent"""
53     params = { "ssid": "test-wnm",
54                "time_advertisement": "2",
55                "time_zone": "EST5",
56                "wnm_sleep_mode": "1",
57                "bss_transition": "1" }
58     hostapd.add_ap(apdev[0]['ifname'], params)
59     hapd = hostapd.Hostapd(apdev[0]['ifname'])
60
61     dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412")
62     addr = dev[0].p2p_interface_addr()
63     hapd.request("ESS_DISASSOC " + addr + " 10 http://example.com/session-info")
64     ev = dev[0].wait_event(["ESS-DISASSOC-IMMINENT"])
65     if ev is None:
66         raise Exception("Timeout while waiting for ESS disassociation imminent")
67     if "0 1024 http://example.com/session-info" not in ev:
68         raise Exception("Unexpected ESS disassociation imminent message contents")
69     ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
70     if ev is None:
71         raise Exception("Timeout while waiting for re-connection scan")
72
73 def test_wnm_ess_disassoc_imminent_pmf(dev, apdev):
74     """WNM ESS Disassociation Imminent"""
75     params = hostapd.wpa2_params("test-wnm-rsn", "12345678")
76     params["wpa_key_mgmt"] = "WPA-PSK-SHA256";
77     params["ieee80211w"] = "2";
78     params["bss_transition"] = "1"
79     hostapd.add_ap(apdev[0]['ifname'], params)
80     hapd = hostapd.Hostapd(apdev[0]['ifname'])
81
82     dev[0].connect("test-wnm-rsn", psk="12345678", ieee80211w="2",
83                    key_mgmt="WPA-PSK-SHA256", proto="WPA2", scan_freq="2412")
84     addr = dev[0].p2p_interface_addr()
85     hapd.request("ESS_DISASSOC " + addr + " 10 http://example.com/session-info")
86     ev = dev[0].wait_event(["ESS-DISASSOC-IMMINENT"])
87     if ev is None:
88         raise Exception("Timeout while waiting for ESS disassociation imminent")
89     if "1 1024 http://example.com/session-info" not in ev:
90         raise Exception("Unexpected ESS disassociation imminent message contents")
91     ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
92     if ev is None:
93         raise Exception("Timeout while waiting for re-connection scan")
94
95 def check_wnm_sleep_mode_enter_exit(hapd, dev, interval=None, tfs_req=None):
96     addr = dev.p2p_interface_addr()
97     sta = hapd.get_sta(addr)
98     if "[WNM_SLEEP_MODE]" in sta['flags']:
99         raise Exception("Station unexpectedly in WNM-Sleep Mode")
100     logger.info("Going to WNM Sleep Mode")
101     extra = ""
102     if interval is not None:
103         extra += " interval=" + str(interval)
104     if tfs_req:
105         extra += " tfs_req=" + tfs_req
106     if "OK" not in dev.request("WNM_SLEEP enter" + extra):
107         raise Exception("WNM_SLEEP failed")
108     time.sleep(0.5)
109     sta = hapd.get_sta(addr)
110     if "[WNM_SLEEP_MODE]" not in sta['flags']:
111         raise Exception("Station failed to enter WNM-Sleep Mode")
112     logger.info("Waking up from WNM Sleep Mode")
113     dev.request("WNM_SLEEP exit")
114     time.sleep(0.5)
115     sta = hapd.get_sta(addr)
116     if "[WNM_SLEEP_MODE]" in sta['flags']:
117         raise Exception("Station failed to exit WNM-Sleep Mode")
118
119 def test_wnm_sleep_mode_open(dev, apdev):
120     """WNM Sleep Mode - open"""
121     params = { "ssid": "test-wnm",
122                "time_advertisement": "2",
123                "time_zone": "EST5",
124                "wnm_sleep_mode": "1",
125                "bss_transition": "1" }
126     hostapd.add_ap(apdev[0]['ifname'], params)
127     hapd = hostapd.Hostapd(apdev[0]['ifname'])
128
129     dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412")
130     check_wnm_sleep_mode_enter_exit(hapd, dev[0])
131     check_wnm_sleep_mode_enter_exit(hapd, dev[0], interval=100)
132     check_wnm_sleep_mode_enter_exit(hapd, dev[0], tfs_req="5b17010001130e110000071122334455661122334455661234")
133
134     cmds = [ "foo",
135              "exit tfs_req=123 interval=10",
136              "enter tfs_req=qq interval=10" ]
137     for cmd in cmds:
138         if "FAIL" not in dev[0].request("WNM_SLEEP " + cmd):
139             raise Exception("Invalid WNM_SLEEP accepted")
140
141 def test_wnm_sleep_mode_rsn(dev, apdev):
142     """WNM Sleep Mode - RSN"""
143     params = hostapd.wpa2_params("test-wnm-rsn", "12345678")
144     params["time_advertisement"] = "2"
145     params["time_zone"] = "EST5"
146     params["wnm_sleep_mode"] = "1"
147     params["bss_transition"] = "1"
148     hostapd.add_ap(apdev[0]['ifname'], params)
149     hapd = hostapd.Hostapd(apdev[0]['ifname'])
150
151     dev[0].connect("test-wnm-rsn", psk="12345678", scan_freq="2412")
152     check_wnm_sleep_mode_enter_exit(hapd, dev[0])
153
154 def test_wnm_sleep_mode_rsn_pmf(dev, apdev):
155     """WNM Sleep Mode - RSN with PMF"""
156     wt = Wlantest()
157     wt.flush()
158     wt.add_passphrase("12345678")
159     params = hostapd.wpa2_params("test-wnm-rsn", "12345678")
160     params["wpa_key_mgmt"] = "WPA-PSK-SHA256";
161     params["ieee80211w"] = "2";
162     params["time_advertisement"] = "2"
163     params["time_zone"] = "EST5"
164     params["wnm_sleep_mode"] = "1"
165     params["bss_transition"] = "1"
166     hostapd.add_ap(apdev[0]['ifname'], params)
167     hapd = hostapd.Hostapd(apdev[0]['ifname'])
168
169     dev[0].connect("test-wnm-rsn", psk="12345678", ieee80211w="2",
170                    key_mgmt="WPA-PSK-SHA256", proto="WPA2", scan_freq="2412")
171     check_wnm_sleep_mode_enter_exit(hapd, dev[0])
172
173 MGMT_SUBTYPE_ACTION = 13
174 ACTION_CATEG_WNM = 10
175 WNM_ACT_BSS_TM_REQ = 7
176 WNM_ACT_BSS_TM_RESP = 8
177
178 def bss_tm_req(dst, src, dialog_token=1, req_mode=0, disassoc_timer=0,
179                validity_interval=1):
180     msg = {}
181     msg['fc'] = MGMT_SUBTYPE_ACTION << 4
182     msg['da'] = dst
183     msg['sa'] = src
184     msg['bssid'] = src
185     msg['payload'] = struct.pack("<BBBBHB",
186                                  ACTION_CATEG_WNM, WNM_ACT_BSS_TM_REQ,
187                                  dialog_token, req_mode, disassoc_timer,
188                                  validity_interval)
189     return msg
190
191 def rx_bss_tm_resp(hapd, expect_dialog=None, expect_status=None):
192     for i in range(0, 100):
193         resp = hapd.mgmt_rx()
194         if resp is None:
195             raise Exception("No BSS TM Response received")
196         if resp['subtype'] == MGMT_SUBTYPE_ACTION:
197             break
198     if i == 99:
199         raise Exception("Not an Action frame")
200     payload = resp['payload']
201     if len(payload) < 2 + 3:
202         raise Exception("Too short payload")
203     (category, action) = struct.unpack('BB', payload[0:2])
204     if category != ACTION_CATEG_WNM or action != WNM_ACT_BSS_TM_RESP:
205         raise Exception("Not a BSS TM Response")
206     pos = payload[2:]
207     (dialog, status, bss_term_delay) = struct.unpack('BBB', pos[0:3])
208     resp['dialog'] = dialog
209     resp['status'] = status
210     resp['bss_term_delay'] = bss_term_delay
211     pos = pos[3:]
212     if len(pos) >= 6 and status == 0:
213         resp['target_bssid'] = binascii.hexlify(pos[0:6])
214         pos = pos[6:]
215     resp['candidates'] = pos
216     if expect_dialog is not None and dialog != expect_dialog:
217         raise Exception("Unexpected dialog token")
218     if expect_status is not None and status != expect_status:
219         raise Exception("Unexpected status code %d" % status)
220     return resp
221
222 def expect_ack(hapd):
223     ev = hapd.wait_event(["MGMT-TX-STATUS"], timeout=5)
224     if ev is None:
225         raise Exception("Missing TX status")
226     if "ok=1" not in ev:
227         raise Exception("Action frame not acknowledged")
228
229 def test_wnm_bss_tm_req(dev, apdev):
230     """BSS Transition Management Request"""
231     params = { "ssid": "test-wnm", "bss_transition": "1" }
232     hapd = hostapd.add_ap(apdev[0]['ifname'], params)
233     dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412")
234     hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
235
236     hapd.set("ext_mgmt_frame_handling", "1")
237
238     # truncated BSS TM Request
239     req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'],
240                      req_mode=0x08)
241     req['payload'] = struct.pack("<BBBBH",
242                                  ACTION_CATEG_WNM, WNM_ACT_BSS_TM_REQ,
243                                  1, 0, 0)
244     hapd.mgmt_tx(req)
245     expect_ack(hapd)
246
247     # no disassociation and no candidate list
248     req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'],
249                      dialog_token=2)
250     hapd.mgmt_tx(req)
251     resp = rx_bss_tm_resp(hapd, expect_dialog=2, expect_status=1)
252
253     # truncated BSS Termination Duration
254     req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'],
255                      req_mode=0x08)
256     hapd.mgmt_tx(req)
257     expect_ack(hapd)
258
259     # BSS Termination Duration with TSF=0 and Duration=10
260     req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'],
261                      req_mode=0x08, dialog_token=3)
262     req['payload'] += struct.pack("<BBQH", 4, 10, 0, 10)
263     hapd.mgmt_tx(req)
264     resp = rx_bss_tm_resp(hapd, expect_dialog=3, expect_status=1)
265
266     # truncated Session Information URL
267     req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'],
268                      req_mode=0x10)
269     hapd.mgmt_tx(req)
270     expect_ack(hapd)
271     req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'],
272                      req_mode=0x10)
273     req['payload'] += struct.pack("<BBB", 3, 65, 66)
274     hapd.mgmt_tx(req)
275     expect_ack(hapd)
276
277     # Session Information URL
278     req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'],
279                      req_mode=0x10, dialog_token=4)
280     req['payload'] += struct.pack("<BBB", 2, 65, 66)
281     hapd.mgmt_tx(req)
282     resp = rx_bss_tm_resp(hapd, expect_dialog=4, expect_status=0)
283
284     # Preferred Candidate List without any entries
285     req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'],
286                      req_mode=0x01, dialog_token=5)
287     hapd.mgmt_tx(req)
288     resp = rx_bss_tm_resp(hapd, expect_dialog=5, expect_status=7)
289
290     # Preferred Candidate List with a truncated entry
291     req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'],
292                      req_mode=0x01)
293     req['payload'] += struct.pack("<BB", 52, 1)
294     hapd.mgmt_tx(req)
295     expect_ack(hapd)
296
297     # Preferred Candidate List with a too short entry
298     req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'],
299                      req_mode=0x01, dialog_token=6)
300     req['payload'] += struct.pack("<BB", 52, 0)
301     hapd.mgmt_tx(req)
302     resp = rx_bss_tm_resp(hapd, expect_dialog=6, expect_status=7)
303
304     # Preferred Candidate List with a non-matching entry
305     req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'],
306                      req_mode=0x01, dialog_token=6)
307     req['payload'] += struct.pack("<BB6BLBBB", 52, 13,
308                                   1, 2, 3, 4, 5, 6,
309                                   0, 81, 1, 7)
310     hapd.mgmt_tx(req)
311     resp = rx_bss_tm_resp(hapd, expect_dialog=6, expect_status=7)
312
313     # Preferred Candidate List with a truncated subelement
314     req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'],
315                      req_mode=0x01, dialog_token=7)
316     req['payload'] += struct.pack("<BB6BLBBBBB", 52, 13 + 2,
317                                   1, 2, 3, 4, 5, 6,
318                                   0, 81, 1, 7,
319                                   1, 1)
320     hapd.mgmt_tx(req)
321     resp = rx_bss_tm_resp(hapd, expect_dialog=7, expect_status=7)
322
323     # Preferred Candidate List with lots of invalid optional subelements
324     req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'],
325                      req_mode=0x01, dialog_token=8)
326     subelems = struct.pack("<BBHB", 1, 3, 0, 100)
327     subelems += struct.pack("<BBB", 2, 1, 65)
328     subelems += struct.pack("<BB", 3, 0)
329     subelems += struct.pack("<BBQB", 4, 9, 0, 10)
330     subelems += struct.pack("<BBHLB", 5, 7, 0, 0, 0)
331     subelems += struct.pack("<BB", 66, 0)
332     subelems += struct.pack("<BBBBBB", 70, 4, 0, 0, 0, 0)
333     subelems += struct.pack("<BB", 71, 0)
334     req['payload'] += struct.pack("<BB6BLBBB", 52, 13 + len(subelems),
335                                   1, 2, 3, 4, 5, 6,
336                                   0, 81, 1, 7) + subelems
337     hapd.mgmt_tx(req)
338     resp = rx_bss_tm_resp(hapd, expect_dialog=8, expect_status=7)
339
340     # Preferred Candidate List with lots of valid optional subelements (twice)
341     req = bss_tm_req(dev[0].p2p_interface_addr(), apdev[0]['bssid'],
342                      req_mode=0x01, dialog_token=8)
343     # TSF Information
344     subelems = struct.pack("<BBHH", 1, 4, 0, 100)
345     # Condensed Country String
346     subelems += struct.pack("<BBBB", 2, 2, 65, 66)
347     # BSS Transition Candidate Preference
348     subelems += struct.pack("<BBB", 3, 1, 100)
349     # BSS Termination Duration
350     subelems += struct.pack("<BBQH", 4, 10, 0, 10)
351     # Bearing
352     subelems += struct.pack("<BBHLH", 5, 8, 0, 0, 0)
353     # Measurement Pilot Transmission
354     subelems += struct.pack("<BBBBB", 66, 3, 0, 0, 0)
355     # RM Enabled Capabilities
356     subelems += struct.pack("<BBBBBBB", 70, 5, 0, 0, 0, 0, 0)
357     # Multiple BSSID
358     subelems += struct.pack("<BBBB", 71, 2, 0, 0)
359     req['payload'] += struct.pack("<BB6BLBBB", 52, 13 + len(subelems) * 2,
360                                   1, 2, 3, 4, 5, 6,
361                                   0, 81, 1, 7) + subelems + subelems
362     hapd.mgmt_tx(req)
363     resp = rx_bss_tm_resp(hapd, expect_dialog=8, expect_status=7)
364
365 def test_wnm_bss_keep_alive(dev, apdev):
366     """WNM keep-alive"""
367     params = { "ssid": "test-wnm",
368                "ap_max_inactivity": "1" }
369     hapd = hostapd.add_ap(apdev[0]['ifname'], params)
370
371     addr = dev[0].p2p_interface_addr()
372     dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412")
373     start = hapd.get_sta(addr)
374     ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=2)
375     if ev is not None:
376         raise Exception("Unexpected disconnection")
377     end = hapd.get_sta(addr)
378     if int(end['rx_packets']) <= int(start['rx_packets']):
379         raise Exception("No keep-alive packets received")
380     try:
381         # Disable client keep-alive so that hostapd will verify connection
382         # with client poll
383         dev[0].request("SET no_keep_alive 1")
384         for i in range(60):
385             sta = hapd.get_sta(addr)
386             logger.info("timeout_next=%s rx_packets=%s tx_packets=%s" % (sta['timeout_next'], sta['rx_packets'], sta['tx_packets']))
387             if i > 1 and sta['timeout_next'] != "NULLFUNC POLL" and int(sta['tx_packets']) > int(end['tx_packets']):
388                 break
389             ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
390             if ev is not None:
391                 raise Exception("Unexpected disconnection (client poll expected)")
392     finally:
393         dev[0].request("SET no_keep_alive 0")
394     if int(sta['tx_packets']) <= int(end['tx_packets']):
395         raise Exception("No client poll packet seen")
396
397 def test_wnm_bss_tm(dev, apdev):
398     """WNM BSS Transition Management"""
399     try:
400         hapd = None
401         hapd2 = None
402         params = { "ssid": "test-wnm",
403                    "country_code": "FI",
404                    "ieee80211d": "1",
405                    "hw_mode": "g",
406                    "channel": "1",
407                    "bss_transition": "1" }
408         hapd = hostapd.add_ap(apdev[0]['ifname'], params)
409
410         id = dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412")
411         dev[0].set_network(id, "scan_freq", "")
412
413         params = { "ssid": "test-wnm",
414                    "country_code": "FI",
415                    "ieee80211d": "1",
416                    "hw_mode": "a",
417                    "channel": "36",
418                    "bss_transition": "1" }
419         hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
420
421         addr = dev[0].p2p_interface_addr()
422         dev[0].dump_monitor()
423
424         logger.info("No neighbor list entries")
425         if "OK" not in hapd.request("BSS_TM_REQ " + addr):
426             raise Exception("BSS_TM_REQ command failed")
427         ev = hapd.wait_event(['BSS-TM-RESP'], timeout=10)
428         if ev is None:
429             raise Exception("No BSS Transition Management Response")
430         if addr not in ev:
431             raise Exception("Unexpected BSS Transition Management Response address")
432         if "status_code=0" in ev:
433             raise Exception("BSS transition accepted unexpectedly")
434         dev[0].dump_monitor()
435
436         logger.info("Neighbor list entry, but not claimed as Preferred Candidate List")
437         if "OK" not in hapd.request("BSS_TM_REQ " + addr + " neighbor=11:22:33:44:55:66,0x0000,81,3,7"):
438             raise Exception("BSS_TM_REQ command failed")
439         ev = hapd.wait_event(['BSS-TM-RESP'], timeout=10)
440         if ev is None:
441             raise Exception("No BSS Transition Management Response")
442         if "status_code=0" in ev:
443             raise Exception("BSS transition accepted unexpectedly")
444         dev[0].dump_monitor()
445
446         logger.info("Preferred Candidate List (no matching neighbor) without Disassociation Imminent")
447         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"):
448             raise Exception("BSS_TM_REQ command failed")
449         ev = hapd.wait_event(['BSS-TM-RESP'], timeout=10)
450         if ev is None:
451             raise Exception("No BSS Transition Management Response")
452         if "status_code=0" in ev:
453             raise Exception("BSS transition accepted unexpectedly")
454         ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
455         if ev is None:
456             raise Exception("No scan started")
457         dev[0].dump_monitor()
458
459         logger.info("Preferred Candidate List (matching neighbor for another BSS) without Disassociation Imminent")
460         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"):
461             raise Exception("BSS_TM_REQ command failed")
462         ev = hapd.wait_event(['BSS-TM-RESP'], timeout=10)
463         if ev is None:
464             raise Exception("No BSS Transition Management Response")
465         if "status_code=0" not in ev:
466             raise Exception("BSS transition request was not accepted: " + ev)
467         if "target_bssid=" + apdev[1]['bssid'] not in ev:
468             raise Exception("Unexpected target BSS: " + ev)
469         ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
470         if ev is None:
471             raise Exception("No reassociation seen");
472         if apdev[1]['bssid'] not in ev:
473             raise Exception("Unexpected reassociation target: " + ev)
474         ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=0.1)
475         if ev is not None:
476             raise Exception("Unexpected scan started")
477         dev[0].dump_monitor()
478
479         logger.info("Preferred Candidate List with two matches, no roam needed")
480         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"):
481             raise Exception("BSS_TM_REQ command failed")
482         ev = hapd2.wait_event(['BSS-TM-RESP'], timeout=10)
483         if ev is None:
484             raise Exception("No BSS Transition Management Response")
485         if "status_code=0" not in ev:
486             raise Exception("BSS transition request was not accepted: " + ev)
487         if "target_bssid=" + apdev[1]['bssid'] not in ev:
488             raise Exception("Unexpected target BSS: " + ev)
489         ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=0.1)
490         if ev is not None:
491             raise Exception("Unexpected scan started")
492         ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.5)
493         if ev is not None:
494             raise Exception("Unexpected reassociation");
495     finally:
496         dev[0].request("DISCONNECT")
497         if hapd:
498             hapd.request("DISABLE")
499         if hapd2:
500             hapd2.request("DISABLE")
501         subprocess.call(['iw', 'reg', 'set', '00'])
502         dev[0].flush_scan_cache()