test_wnm.py 63 KB

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