test_wnm.py 19 KB

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