test_wnm.py 60 KB

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