test_mbo.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. # MBO tests
  2. # Copyright (c) 2016, Intel Deutschland GmbH
  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 logging
  8. logger = logging.getLogger()
  9. import hostapd
  10. import os
  11. import time
  12. import hostapd
  13. from tshark import run_tshark
  14. from utils import alloc_fail, fail_test
  15. def set_reg(country_code, apdev0=None, apdev1=None, dev0=None):
  16. if apdev0:
  17. hostapd.cmd_execute(apdev0, ['iw', 'reg', 'set', country_code])
  18. if apdev1:
  19. hostapd.cmd_execute(apdev1, ['iw', 'reg', 'set', country_code])
  20. if dev0:
  21. dev0.cmd_execute(['iw', 'reg', 'set', country_code])
  22. def run_mbo_supp_oper_classes(dev, apdev, hapd, hapd2, country):
  23. """MBO and supported operating classes"""
  24. addr = dev[0].own_addr()
  25. res2 = None
  26. res5 = None
  27. dev[0].flush_scan_cache()
  28. dev[0].dump_monitor()
  29. logger.info("Country: " + country)
  30. set_reg(country, apdev[0], apdev[1], dev[0])
  31. for j in range(5):
  32. ev = dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  33. if ev is None:
  34. raise Exception("No regdom change event")
  35. if "alpha2=" + country in ev:
  36. break
  37. dev[0].dump_monitor()
  38. dev[1].dump_monitor()
  39. dev[2].dump_monitor()
  40. if hapd:
  41. hapd.set("country_code", country)
  42. hapd.enable()
  43. dev[0].scan_for_bss(hapd.own_addr(), 5180, force_scan=True)
  44. dev[0].connect("test-wnm-mbo", key_mgmt="NONE", scan_freq="5180")
  45. sta = hapd.get_sta(addr)
  46. res5 = sta['supp_op_classes'][2:]
  47. dev[0].request("REMOVE_NETWORK all")
  48. hapd.disable()
  49. dev[0].wait_disconnected()
  50. dev[0].dump_monitor()
  51. hapd2.set("country_code", country)
  52. hapd2.enable()
  53. dev[0].scan_for_bss(hapd2.own_addr(), 2412, force_scan=True)
  54. dev[0].connect("test-wnm-mbo-2", key_mgmt="NONE", scan_freq="2412")
  55. sta = hapd2.get_sta(addr)
  56. res2 = sta['supp_op_classes'][2:]
  57. dev[0].request("REMOVE_NETWORK all")
  58. hapd2.disable()
  59. dev[0].wait_disconnected()
  60. dev[0].dump_monitor()
  61. return res2, res5
  62. def test_mbo_supp_oper_classes(dev, apdev):
  63. """MBO and supported operating classes"""
  64. params = { 'ssid': "test-wnm-mbo",
  65. 'mbo': '1',
  66. "country_code": "US",
  67. 'ieee80211d': '1',
  68. "ieee80211n": "1",
  69. "hw_mode": "a",
  70. "channel": "36" }
  71. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  72. params = { 'ssid': "test-wnm-mbo-2",
  73. 'mbo': '1',
  74. "country_code": "US",
  75. 'ieee80211d': '1',
  76. "ieee80211n": "1",
  77. "hw_mode": "g",
  78. "channel": "1" }
  79. hapd2 = hostapd.add_ap(apdev[1], params, no_enable=True)
  80. try:
  81. za2, za5 = run_mbo_supp_oper_classes(dev, apdev, hapd, hapd2, "ZA")
  82. fi2, fi5 = run_mbo_supp_oper_classes(dev, apdev, hapd, hapd2, "FI")
  83. us2, us5 = run_mbo_supp_oper_classes(dev, apdev, hapd, hapd2, "US")
  84. jp2, jp5 = run_mbo_supp_oper_classes(dev, apdev, hapd, hapd2, "JP")
  85. bd2, bd5 = run_mbo_supp_oper_classes(dev, apdev, None, hapd2, "BD")
  86. kz2, kz5 = run_mbo_supp_oper_classes(dev, apdev, None, hapd2, "KZ")
  87. finally:
  88. dev[0].dump_monitor()
  89. set_reg("00", apdev[0], apdev[1], dev[0])
  90. ev = dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=1)
  91. za = "515354737475767778797a7b808182"
  92. fi = "515354737475767778797a7b808182"
  93. us = "515354737475767778797a7b7c7d7e7f808182"
  94. jp = "51525354737475767778797a7b808182"
  95. bd = "5153547c7d7e7f80"
  96. kz = "515354"
  97. tests = [ ("ZA", za, za2, za5, True),
  98. ("FI", fi, fi2, fi5, True),
  99. ("US", us, us2, us5, True),
  100. ("JP", jp, jp2, jp5, True),
  101. ("BD", bd, bd2, bd5, False),
  102. ("KZ", kz, kz2, kz5, False) ]
  103. for country, expected, res2, res5, inc5 in tests:
  104. # For now, allow operating class 129 to be missing since not all
  105. # installed regdb files include the 160 MHz channels.
  106. expected2 = expected.replace('808182', '8082')
  107. # For now, allow operating classes 121-123 to be missing since not all
  108. # installed regdb files include the related US DFS channels.
  109. expected2 = expected2.replace('78797a7b7c', '787c')
  110. if res2 != expected and res2 != expected2:
  111. raise Exception("Unexpected supp_op_class string (country=%s, 2.4 GHz): %s (expected: %s)" % (country, res2, expected))
  112. if inc5 and res5 != expected and res5 != expected2:
  113. raise Exception("Unexpected supp_op_class string (country=%s, 5 GHz): %s (expected: %s)" % (country, res5, expected))
  114. def test_mbo_assoc_disallow(dev, apdev, params):
  115. """MBO and association disallowed"""
  116. hapd1 = hostapd.add_ap(apdev[0], { "ssid": "MBO", "mbo": "1" })
  117. hapd2 = hostapd.add_ap(apdev[1], { "ssid": "MBO", "mbo": "1" })
  118. logger.debug("Set mbo_assoc_disallow with invalid value")
  119. if "FAIL" not in hapd1.request("SET mbo_assoc_disallow 2"):
  120. raise Exception("Set mbo_assoc_disallow for AP1 succeeded unexpectedly with value 2")
  121. logger.debug("Disallow associations to AP1 and allow association to AP2")
  122. if "OK" not in hapd1.request("SET mbo_assoc_disallow 1"):
  123. raise Exception("Failed to set mbo_assoc_disallow for AP1")
  124. if "OK" not in hapd2.request("SET mbo_assoc_disallow 0"):
  125. raise Exception("Failed to set mbo_assoc_disallow for AP2")
  126. dev[0].connect("MBO", key_mgmt="NONE", scan_freq="2412")
  127. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  128. "wlan.fc.type == 0 && wlan.fc.type_subtype == 0x00",
  129. wait=False)
  130. if "Destination address: " + hapd1.own_addr() in out:
  131. raise Exception("Association request sent to disallowed AP")
  132. timestamp = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  133. "wlan.fc.type_subtype == 0x00",
  134. display=['frame.time'], wait=False)
  135. logger.debug("Allow associations to AP1 and disallow associations to AP2")
  136. if "OK" not in hapd1.request("SET mbo_assoc_disallow 0"):
  137. raise Exception("Failed to set mbo_assoc_disallow for AP1")
  138. if "OK" not in hapd2.request("SET mbo_assoc_disallow 1"):
  139. raise Exception("Failed to set mbo_assoc_disallow for AP2")
  140. dev[0].request("DISCONNECT")
  141. dev[0].wait_disconnected()
  142. # Force new scan, so the assoc_disallowed indication is updated */
  143. dev[0].request("FLUSH")
  144. dev[0].connect("MBO", key_mgmt="NONE", scan_freq="2412")
  145. filter = 'wlan.fc.type == 0 && wlan.fc.type_subtype == 0x00 && frame.time > "' + timestamp.rstrip() + '"'
  146. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  147. filter, wait=False)
  148. if "Destination address: " + hapd2.own_addr() in out:
  149. raise Exception("Association request sent to disallowed AP 2")
  150. def test_mbo_assoc_disallow_ignore(dev, apdev):
  151. """MBO and ignoring disallowed association"""
  152. try:
  153. _test_mbo_assoc_disallow_ignore(dev, apdev)
  154. finally:
  155. dev[0].request("SCAN_INTERVAL 5")
  156. def _test_mbo_assoc_disallow_ignore(dev, apdev):
  157. hapd1 = hostapd.add_ap(apdev[0], { "ssid": "MBO", "mbo": "1" })
  158. if "OK" not in hapd1.request("SET mbo_assoc_disallow 1"):
  159. raise Exception("Failed to set mbo_assoc_disallow for AP1")
  160. if "OK" not in dev[0].request("SCAN_INTERVAL 1"):
  161. raise Exception("Failed to set scan interval")
  162. dev[0].connect("MBO", key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  163. ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout=10)
  164. if ev is None:
  165. raise Exception("CTRL-EVENT-NETWORK-NOT-FOUND not seen")
  166. if "OK" not in dev[0].request("SET ignore_assoc_disallow 1"):
  167. raise Exception("Failed to set ignore_assoc_disallow")
  168. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  169. if ev is None:
  170. raise Exception("CTRL-EVENT-ASSOC-REJECT not seen")
  171. if "status_code=17" not in ev:
  172. raise Exception("Unexpected association reject reason: " + ev)
  173. if "OK" not in hapd1.request("SET mbo_assoc_disallow 0"):
  174. raise Exception("Failed to set mbo_assoc_disallow for AP1")
  175. dev[0].wait_connected()
  176. @remote_compatible
  177. def test_mbo_cell_capa_update(dev, apdev):
  178. """MBO cellular data capability update"""
  179. ssid = "test-wnm-mbo"
  180. params = { 'ssid': ssid, 'mbo': '1' }
  181. hapd = hostapd.add_ap(apdev[0], params)
  182. bssid = apdev[0]['bssid']
  183. if "OK" not in dev[0].request("SET mbo_cell_capa 1"):
  184. raise Exception("Failed to set STA as cellular data capable")
  185. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  186. addr = dev[0].own_addr()
  187. sta = hapd.get_sta(addr)
  188. if 'mbo_cell_capa' not in sta or sta['mbo_cell_capa'] != '1':
  189. raise Exception("mbo_cell_capa missing after association")
  190. if "OK" not in dev[0].request("SET mbo_cell_capa 3"):
  191. raise Exception("Failed to set STA as cellular data not-capable")
  192. # Duplicate update for additional code coverage
  193. if "OK" not in dev[0].request("SET mbo_cell_capa 3"):
  194. raise Exception("Failed to set STA as cellular data not-capable")
  195. time.sleep(0.2)
  196. sta = hapd.get_sta(addr)
  197. if 'mbo_cell_capa' not in sta:
  198. raise Exception("mbo_cell_capa missing after update")
  199. if sta['mbo_cell_capa'] != '3':
  200. raise Exception("mbo_cell_capa not updated properly")
  201. @remote_compatible
  202. def test_mbo_cell_capa_update_pmf(dev, apdev):
  203. """MBO cellular data capability update with PMF required"""
  204. ssid = "test-wnm-mbo"
  205. passphrase = "12345678"
  206. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  207. params["wpa_key_mgmt"] = "WPA-PSK-SHA256"
  208. params["ieee80211w"] = "2"
  209. params['mbo'] = '1'
  210. hapd = hostapd.add_ap(apdev[0], params)
  211. bssid = apdev[0]['bssid']
  212. if "OK" not in dev[0].request("SET mbo_cell_capa 1"):
  213. raise Exception("Failed to set STA as cellular data capable")
  214. dev[0].connect(ssid, psk=passphrase, key_mgmt="WPA-PSK-SHA256",
  215. proto="WPA2", ieee80211w="2", scan_freq="2412")
  216. addr = dev[0].own_addr()
  217. sta = hapd.get_sta(addr)
  218. if 'mbo_cell_capa' not in sta or sta['mbo_cell_capa'] != '1':
  219. raise Exception("mbo_cell_capa missing after association")
  220. if "OK" not in dev[0].request("SET mbo_cell_capa 3"):
  221. raise Exception("Failed to set STA as cellular data not-capable")
  222. time.sleep(0.2)
  223. sta = hapd.get_sta(addr)
  224. if 'mbo_cell_capa' not in sta:
  225. raise Exception("mbo_cell_capa missing after update")
  226. if sta['mbo_cell_capa'] != '3':
  227. raise Exception("mbo_cell_capa not updated properly")
  228. def test_mbo_wnm_token_wrap(dev, apdev):
  229. """MBO WNM token wrap around"""
  230. ssid = "test-wnm-mbo"
  231. params = { 'ssid': ssid, 'mbo': '1' }
  232. hapd = hostapd.add_ap(apdev[0], params)
  233. bssid = apdev[0]['bssid']
  234. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  235. # Trigger transmission of 256 WNM-Notification frames to wrap around the
  236. # 8-bit mbo_wnm_token counter.
  237. for i in range(128):
  238. if "OK" not in dev[0].request("SET mbo_cell_capa 1"):
  239. raise Exception("Failed to set STA as cellular data capable")
  240. if "OK" not in dev[0].request("SET mbo_cell_capa 3"):
  241. raise Exception("Failed to set STA as cellular data not-capable")
  242. @remote_compatible
  243. def test_mbo_non_pref_chan(dev, apdev):
  244. """MBO non-preferred channel list"""
  245. ssid = "test-wnm-mbo"
  246. params = { 'ssid': ssid, 'mbo': '1' }
  247. hapd = hostapd.add_ap(apdev[0], params)
  248. bssid = apdev[0]['bssid']
  249. if "FAIL" not in dev[0].request("SET non_pref_chan 81:7:200:99"):
  250. raise Exception("Invalid non_pref_chan value accepted")
  251. if "FAIL" not in dev[0].request("SET non_pref_chan 81:15:200:3"):
  252. raise Exception("Invalid non_pref_chan value accepted")
  253. if "FAIL" not in dev[0].request("SET non_pref_chan 81:7:200:3 81:7:201:3"):
  254. raise Exception("Invalid non_pref_chan value accepted")
  255. if "OK" not in dev[0].request("SET non_pref_chan 81:7:200:3"):
  256. raise Exception("Failed to set non-preferred channel list")
  257. if "OK" not in dev[0].request("SET non_pref_chan 81:7:200:1 81:9:100:2"):
  258. raise Exception("Failed to set non-preferred channel list")
  259. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  260. addr = dev[0].own_addr()
  261. sta = hapd.get_sta(addr)
  262. logger.debug("STA: " + str(sta))
  263. if 'non_pref_chan[0]' not in sta:
  264. raise Exception("Missing non_pref_chan[0] value (assoc)")
  265. if sta['non_pref_chan[0]'] != '81:200:1:7':
  266. raise Exception("Unexpected non_pref_chan[0] value (assoc)")
  267. if 'non_pref_chan[1]' not in sta:
  268. raise Exception("Missing non_pref_chan[1] value (assoc)")
  269. if sta['non_pref_chan[1]'] != '81:100:2:9':
  270. raise Exception("Unexpected non_pref_chan[1] value (assoc)")
  271. if 'non_pref_chan[2]' in sta:
  272. raise Exception("Unexpected non_pref_chan[2] value (assoc)")
  273. if "OK" not in dev[0].request("SET non_pref_chan 81:9:100:2"):
  274. raise Exception("Failed to update non-preferred channel list")
  275. time.sleep(0.1)
  276. sta = hapd.get_sta(addr)
  277. logger.debug("STA: " + str(sta))
  278. if 'non_pref_chan[0]' not in sta:
  279. raise Exception("Missing non_pref_chan[0] value (update 1)")
  280. if sta['non_pref_chan[0]'] != '81:100:2:9':
  281. raise Exception("Unexpected non_pref_chan[0] value (update 1)")
  282. if 'non_pref_chan[1]' in sta:
  283. raise Exception("Unexpected non_pref_chan[1] value (update 1)")
  284. if "OK" not in dev[0].request("SET non_pref_chan 81:9:100:2 81:10:100:2 81:8:100:2 81:7:100:1 81:5:100:1"):
  285. raise Exception("Failed to update non-preferred channel list")
  286. time.sleep(0.1)
  287. sta = hapd.get_sta(addr)
  288. logger.debug("STA: " + str(sta))
  289. if 'non_pref_chan[0]' not in sta:
  290. raise Exception("Missing non_pref_chan[0] value (update 2)")
  291. if sta['non_pref_chan[0]'] != '81:100:1:7,5':
  292. raise Exception("Unexpected non_pref_chan[0] value (update 2)")
  293. if 'non_pref_chan[1]' not in sta:
  294. raise Exception("Missing non_pref_chan[1] value (update 2)")
  295. if sta['non_pref_chan[1]'] != '81:100:2:9,10,8':
  296. raise Exception("Unexpected non_pref_chan[1] value (update 2)")
  297. if 'non_pref_chan[2]' in sta:
  298. raise Exception("Unexpected non_pref_chan[2] value (update 2)")
  299. if "OK" not in dev[0].request("SET non_pref_chan 81:5:90:2 82:14:91:2"):
  300. raise Exception("Failed to update non-preferred channel list")
  301. time.sleep(0.1)
  302. sta = hapd.get_sta(addr)
  303. logger.debug("STA: " + str(sta))
  304. if 'non_pref_chan[0]' not in sta:
  305. raise Exception("Missing non_pref_chan[0] value (update 3)")
  306. if sta['non_pref_chan[0]'] != '81:90:2:5':
  307. raise Exception("Unexpected non_pref_chan[0] value (update 3)")
  308. if 'non_pref_chan[1]' not in sta:
  309. raise Exception("Missing non_pref_chan[1] value (update 3)")
  310. if sta['non_pref_chan[1]'] != '82:91:2:14':
  311. raise Exception("Unexpected non_pref_chan[1] value (update 3)")
  312. if 'non_pref_chan[2]' in sta:
  313. raise Exception("Unexpected non_pref_chan[2] value (update 3)")
  314. if "OK" not in dev[0].request("SET non_pref_chan "):
  315. raise Exception("Failed to update non-preferred channel list")
  316. time.sleep(0.1)
  317. sta = hapd.get_sta(addr)
  318. logger.debug("STA: " + str(sta))
  319. if 'non_pref_chan[0]' in sta:
  320. raise Exception("Unexpected non_pref_chan[0] value (update 4)")
  321. @remote_compatible
  322. def test_mbo_sta_supp_op_classes(dev, apdev):
  323. """MBO STA supported operating classes"""
  324. ssid = "test-wnm-mbo"
  325. params = { 'ssid': ssid, 'mbo': '1' }
  326. hapd = hostapd.add_ap(apdev[0], params)
  327. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  328. addr = dev[0].own_addr()
  329. sta = hapd.get_sta(addr)
  330. logger.debug("STA: " + str(sta))
  331. if 'supp_op_classes' not in sta:
  332. raise Exception("No supp_op_classes")
  333. supp = bytearray(sta['supp_op_classes'].decode("hex"))
  334. if supp[0] != 81:
  335. raise Exception("Unexpected current operating class %d" % supp[0])
  336. if 115 not in supp:
  337. raise Exception("Operating class 115 missing")
  338. def test_mbo_failures(dev, apdev):
  339. """MBO failure cases"""
  340. ssid = "test-wnm-mbo"
  341. params = { 'ssid': ssid, 'mbo': '1' }
  342. hapd = hostapd.add_ap(apdev[0], params)
  343. with alloc_fail(dev[0], 1, "wpas_mbo_ie"):
  344. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  345. with alloc_fail(dev[0], 1, "wpas_mbo_send_wnm_notification"):
  346. if "OK" not in dev[0].request("SET mbo_cell_capa 1"):
  347. raise Exception("Failed to set STA as cellular data capable")
  348. with fail_test(dev[0], 1, "wpas_mbo_send_wnm_notification"):
  349. if "OK" not in dev[0].request("SET mbo_cell_capa 3"):
  350. raise Exception("Failed to set STA as cellular data not-capable")
  351. with alloc_fail(dev[0], 1, "wpas_mbo_update_non_pref_chan"):
  352. if "FAIL" not in dev[0].request("SET non_pref_chan 81:7:200:3"):
  353. raise Exception("non_pref_chan value accepted during OOM")
  354. with alloc_fail(dev[0], 2, "wpas_mbo_update_non_pref_chan"):
  355. if "FAIL" not in dev[0].request("SET non_pref_chan 81:7:200:3"):
  356. raise Exception("non_pref_chan value accepted during OOM")
  357. def test_mbo_wnm_bss_tm_ie_parsing(dev, apdev):
  358. """MBO BSS transition request MBO IE parsing"""
  359. ssid = "test-wnm-mbo"
  360. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  361. hapd = hostapd.add_ap(apdev[0], params)
  362. bssid = apdev[0]['bssid']
  363. addr = dev[0].own_addr()
  364. dev[0].connect(ssid, psk="12345678", key_mgmt="WPA-PSK",
  365. proto="WPA2", ieee80211w="0", scan_freq="2412")
  366. dev[0].request("SET ext_mgmt_frame_handling 1")
  367. hdr = "d0003a01" + addr.replace(':', '') + bssid.replace(':', '') + bssid.replace(':', '') + "3000"
  368. btm_hdr = "0a070100030001"
  369. tests = [ ("Truncated attribute in MBO IE", "dd06506f9a160101"),
  370. ("Unexpected cell data capa attribute length in MBO IE",
  371. "dd09506f9a160501030500"),
  372. ("Unexpected transition reason attribute length in MBO IE",
  373. "dd06506f9a160600"),
  374. ("Unexpected assoc retry delay attribute length in MBO IE",
  375. "dd0c506f9a160100080200000800"),
  376. ("Unknown attribute id 255 in MBO IE",
  377. "dd06506f9a16ff00") ]
  378. for test, mbo_ie in tests:
  379. logger.info(test)
  380. dev[0].request("NOTE " + test)
  381. frame = hdr + btm_hdr + mbo_ie
  382. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + frame):
  383. raise Exception("MGMT_RX_PROCESS failed")
  384. logger.info("Unexpected association retry delay")
  385. dev[0].request("NOTE Unexpected association retry delay")
  386. btm_hdr = "0a070108030001112233445566778899aabbcc"
  387. mbo_ie = "dd08506f9a1608020000"
  388. frame = hdr + btm_hdr + mbo_ie
  389. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + frame):
  390. raise Exception("MGMT_RX_PROCESS failed")
  391. dev[0].request("SET ext_mgmt_frame_handling 0")
  392. def test_mbo_without_pmf(dev, apdev):
  393. """MBO and WPA2 without PMF"""
  394. ssid = "test-wnm-mbo"
  395. params = { 'ssid': ssid, 'mbo': '1', "wpa": '2',
  396. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  397. "wpa_passphrase": "12345678" }
  398. try:
  399. # "MBO: PMF needs to be enabled whenever using WPA2 with MBO"
  400. hostapd.add_ap(apdev[0], params)
  401. raise Exception("AP setup succeeded unexpectedly")
  402. except Exception, e:
  403. if "Failed to enable hostapd" in str(e):
  404. pass
  405. else:
  406. raise
  407. def check_mbo_anqp(dev, bssid, cell_data_conn_pref):
  408. if "OK" not in dev.request("ANQP_GET " + bssid + " 272,mbo:2"):
  409. raise Exception("ANQP_GET command failed")
  410. ev = dev.wait_event(["GAS-QUERY-START"], timeout=5)
  411. if ev is None:
  412. raise Exception("GAS query start timed out")
  413. ev = dev.wait_event(["GAS-QUERY-DONE"], timeout=10)
  414. if ev is None:
  415. raise Exception("GAS query timed out")
  416. if cell_data_conn_pref is not None:
  417. ev = dev.wait_event(["RX-MBO-ANQP"], timeout=1)
  418. if ev is None or "cell_conn_pref" not in ev:
  419. raise Exception("Did not receive MBO Cellular Data Connection Preference")
  420. if cell_data_conn_pref != int(ev.split('=')[1]):
  421. raise Exception("Unexpected cell_conn_pref value: " + ev)
  422. dev.dump_monitor()
  423. def test_mbo_anqp(dev, apdev):
  424. """MBO ANQP"""
  425. params = { 'ssid': "test-wnm-mbo",
  426. 'mbo': '1',
  427. 'interworking': '1',
  428. 'mbo_cell_data_conn_pref': '1' }
  429. hapd = hostapd.add_ap(apdev[0], params)
  430. bssid = hapd.own_addr()
  431. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  432. check_mbo_anqp(dev[0], bssid, 1)
  433. hapd.set('mbo_cell_data_conn_pref', '255')
  434. check_mbo_anqp(dev[0], bssid, 255)
  435. hapd.set('mbo_cell_data_conn_pref', '-1')
  436. check_mbo_anqp(dev[0], bssid, None)