test_wnm.py 78 KB

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