test_wnm.py 56 KB

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