test_rrm.py 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537
  1. # Radio measurement
  2. # Copyright(c) 2013 - 2016 Intel Mobile Communications GmbH.
  3. # Copyright(c) 2011 - 2016 Intel Corporation. All rights reserved.
  4. # Copyright (c) 2017, Jouni Malinen <j@w1.fi>
  5. #
  6. # This software may be distributed under the terms of the BSD license.
  7. # See README for more details.
  8. import binascii
  9. import re
  10. import logging
  11. logger = logging.getLogger()
  12. import struct
  13. import subprocess
  14. import hostapd
  15. from wpasupplicant import WpaSupplicant
  16. from utils import HwsimSkip, alloc_fail, fail_test, wait_fail_trigger
  17. from test_ap_ht import clear_scan_cache
  18. def check_rrm_support(dev):
  19. rrm = int(dev.get_driver_status_field("capa.rrm_flags"), 16)
  20. if rrm & 0x5 != 0x5 and rrm & 0x10 != 0x10:
  21. raise HwsimSkip("Required RRM capabilities are not supported")
  22. nr="00112233445500000000510107"
  23. lci="01000800101298c0b512926666f6c2f1001c00004104050000c00012"
  24. civic="01000b0011223344556677889900998877665544332211aabbccddeeff"
  25. def check_nr_results(dev, bssids=None, lci=False, civic=False):
  26. if bssids is None:
  27. ev = dev.wait_event(["RRM-NEIGHBOR-REP-REQUEST-FAILED" ], timeout=10)
  28. if ev is None:
  29. raise Exception("RRM neighbor report failure not received")
  30. return
  31. received = []
  32. for bssid in bssids:
  33. ev = dev.wait_event(["RRM-NEIGHBOR-REP-RECEIVED"], timeout=10)
  34. if ev is None:
  35. raise Exception("RRM report result not indicated")
  36. received.append(ev)
  37. for bssid in bssids:
  38. found = False
  39. for r in received:
  40. if "RRM-NEIGHBOR-REP-RECEIVED bssid=" + bssid in r:
  41. if lci and "lci=" not in r:
  42. raise Exception("LCI data not reported for %s" % bssid)
  43. if civic and "civic=" not in r:
  44. raise Exception("civic data not reported for %s" % bssid)
  45. received.remove(r)
  46. found = True
  47. break
  48. if not found:
  49. raise Exception("RRM report result for %s not indicated" % bssid)
  50. def test_rrm_neighbor_db(dev, apdev):
  51. """hostapd ctrl_iface SET_NEIGHBOR"""
  52. params = { "ssid": "test", "rrm_neighbor_report": "1" }
  53. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  54. # Bad BSSID
  55. if "FAIL" not in hapd.request("SET_NEIGHBOR 00:11:22:33:44:gg ssid=\"test1\" nr=" + nr):
  56. raise Exception("Set neighbor succeeded unexpectedly")
  57. # Bad SSID
  58. if "FAIL" not in hapd.request("SET_NEIGHBOR 00:11:22:33:44:55 ssid=test1 nr=" + nr):
  59. raise Exception("Set neighbor succeeded unexpectedly")
  60. # No SSID
  61. if "FAIL" not in hapd.request("SET_NEIGHBOR 00:11:22:33:44:55 nr=" + nr):
  62. raise Exception("Set neighbor succeeded unexpectedly")
  63. # No NR
  64. if "FAIL" not in hapd.request("SET_NEIGHBOR 00:11:22:33:44:55 ssid=\"test1\""):
  65. raise Exception("Set neighbor succeeded unexpectedly")
  66. # Odd length of NR
  67. if "FAIL" not in hapd.request("SET_NEIGHBOR 00:11:22:33:44:55 ssid=\"test1\" nr=" + nr[:-1]):
  68. raise Exception("Set neighbor succeeded unexpectedly")
  69. # Invalid lci
  70. if "FAIL" not in hapd.request("SET_NEIGHBOR 00:11:22:33:44:55 ssid=\"test1\" nr=" + nr + " lci=1"):
  71. raise Exception("Set neighbor succeeded unexpectedly")
  72. # Invalid civic
  73. if "FAIL" not in hapd.request("SET_NEIGHBOR 00:11:22:33:44:55 ssid=\"test1\" nr=" + nr + " civic=1"):
  74. raise Exception("Set neighbor succeeded unexpectedly")
  75. # No entry yet in database
  76. if "FAIL" not in hapd.request("REMOVE_NEIGHBOR 00:11:22:33:44:55 ssid=\"test1\""):
  77. raise Exception("Remove neighbor succeeded unexpectedly")
  78. # Add a neighbor entry
  79. if "OK" not in hapd.request("SET_NEIGHBOR 00:11:22:33:44:55 ssid=\"test1\" nr=" + nr + " lci=" + lci + " civic=" + civic):
  80. raise Exception("Set neighbor failed")
  81. # Another BSSID with the same SSID
  82. if "OK" not in hapd.request("SET_NEIGHBOR 00:11:22:33:44:56 ssid=\"test1\" nr=" + nr + " lci=" + lci + " civic=" + civic):
  83. raise Exception("Set neighbor failed")
  84. # Fewer parameters
  85. if "OK" not in hapd.request("SET_NEIGHBOR 00:11:22:33:44:55 ssid=\"test1\" nr=" + nr):
  86. raise Exception("Set neighbor failed")
  87. # SSID in hex format
  88. if "OK" not in hapd.request("SET_NEIGHBOR 00:11:22:33:44:55 ssid=7465737431 nr=" + nr):
  89. raise Exception("Set neighbor failed")
  90. # With more parameters
  91. if "OK" not in hapd.request("SET_NEIGHBOR 00:11:22:33:44:55 ssid=\"test1\" nr=" + nr + " civic=" + civic):
  92. raise Exception("Set neighbor failed")
  93. # With all parameters
  94. if "OK" not in hapd.request("SET_NEIGHBOR 00:11:22:33:44:55 ssid=\"test1\" nr=" + nr + " lci=" + lci + " civic=" + civic):
  95. raise Exception("Set neighbor failed")
  96. # Another SSID on the same BSSID
  97. if "OK" not in hapd.request("SET_NEIGHBOR 00:11:22:33:44:55 ssid=\"test2\" nr=" + nr + " lci=" + lci):
  98. raise Exception("Set neighbor failed")
  99. if "OK" not in hapd.request("REMOVE_NEIGHBOR 00:11:22:33:44:55 ssid=\"test1\""):
  100. raise Exception("Remove neighbor failed")
  101. if "OK" not in hapd.request("REMOVE_NEIGHBOR 00:11:22:33:44:56 ssid=\"test1\""):
  102. raise Exception("Remove neighbor failed")
  103. if "OK" not in hapd.request("REMOVE_NEIGHBOR 00:11:22:33:44:55 ssid=\"test2\""):
  104. raise Exception("Remove neighbor failed")
  105. # Double remove
  106. if "FAIL" not in hapd.request("REMOVE_NEIGHBOR 00:11:22:33:44:55 ssid=\"test1\""):
  107. raise Exception("Remove neighbor succeeded unexpectedly")
  108. # Stationary AP
  109. if "OK" not in hapd.request("SET_NEIGHBOR 00:11:22:33:44:55 ssid=\"test3\" nr=" + nr + " lci=" + lci + " civic=" + civic + " stat"):
  110. raise Exception("Set neighbor failed")
  111. if "OK" not in hapd.request("REMOVE_NEIGHBOR 00:11:22:33:44:55 ssid=\"test3\""):
  112. raise Exception("Remove neighbor failed")
  113. # Invalid remove - bad BSSID
  114. if "FAIL" not in hapd.request("REMOVE_NEIGHBOR 00:11:22:33:44:5 ssid=\"test1\""):
  115. raise Exception("Remove neighbor succeeded unexpectedly")
  116. # Invalid remove - bad SSID
  117. if "FAIL" not in hapd.request("REMOVE_NEIGHBOR 00:11:22:33:44:55 ssid=\"test1"):
  118. raise Exception("Remove neighbor succeeded unexpectedly")
  119. # Invalid remove - missing SSID
  120. if "FAIL" not in hapd.request("REMOVE_NEIGHBOR 00:11:22:33:44:55"):
  121. raise Exception("Remove neighbor succeeded unexpectedly")
  122. def test_rrm_neighbor_rep_req(dev, apdev):
  123. """wpa_supplicant ctrl_iface NEIGHBOR_REP_REQUEST"""
  124. check_rrm_support(dev[0])
  125. nr1="00112233445500000000510107"
  126. nr2="00112233445600000000510107"
  127. nr3="dd112233445500000000510107"
  128. params = { "ssid": "test" }
  129. hostapd.add_ap(apdev[0]['ifname'], params)
  130. params = { "ssid": "test2", "rrm_neighbor_report": "1" }
  131. hapd = hostapd.add_ap(apdev[1]['ifname'], params)
  132. bssid1 = apdev[1]['bssid']
  133. dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
  134. if "FAIL" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  135. raise Exception("Request succeeded unexpectedly (AP without RRM)")
  136. if "FAIL" not in dev[0].request("NEIGHBOR_REP_REQUEST ssid=\"abcdef\""):
  137. raise Exception("Request succeeded unexpectedly (AP without RRM 2)")
  138. dev[0].request("DISCONNECT")
  139. dev[0].connect("test2", key_mgmt="NONE", scan_freq="2412")
  140. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  141. raise Exception("Request failed")
  142. check_nr_results(dev[0], [bssid1])
  143. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST lci"):
  144. raise Exception("Request failed")
  145. check_nr_results(dev[0], [bssid1])
  146. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST lci civic"):
  147. raise Exception("Request failed")
  148. check_nr_results(dev[0], [bssid1])
  149. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST ssid=\"test3\""):
  150. raise Exception("Request failed")
  151. check_nr_results(dev[0])
  152. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST ssid=\"test3\" lci civic"):
  153. raise Exception("Request failed")
  154. check_nr_results(dev[0])
  155. if "OK" not in hapd.request("SET_NEIGHBOR 00:11:22:33:44:55 ssid=\"test3\" nr=" + nr1 + " lci=" + lci + " civic=" + civic):
  156. raise Exception("Set neighbor failed")
  157. if "OK" not in hapd.request("SET_NEIGHBOR 00:11:22:33:44:56 ssid=\"test3\" nr=" + nr2 + " lci=" + lci + " civic=" + civic):
  158. raise Exception("Set neighbor failed")
  159. if "OK" not in hapd.request("SET_NEIGHBOR 00:11:22:33:44:56 ssid=\"test4\" nr=" + nr2 + " lci=" + lci + " civic=" + civic):
  160. raise Exception("Set neighbor failed")
  161. if "OK" not in hapd.request("SET_NEIGHBOR dd:11:22:33:44:55 ssid=\"test5\" nr=" + nr3 + " lci=" + lci):
  162. raise Exception("Set neighbor failed")
  163. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST ssid=\"test3\""):
  164. raise Exception("Request failed")
  165. check_nr_results(dev[0], ["00:11:22:33:44:55", "00:11:22:33:44:56"])
  166. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST ssid=\"test3\" lci"):
  167. raise Exception("Request failed")
  168. check_nr_results(dev[0], ["00:11:22:33:44:55", "00:11:22:33:44:56"],
  169. lci=True)
  170. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST ssid=\"test3\" civic"):
  171. raise Exception("Request failed")
  172. check_nr_results(dev[0], ["00:11:22:33:44:55", "00:11:22:33:44:56"],
  173. civic=True)
  174. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST ssid=\"test3\" lci civic"):
  175. raise Exception("Request failed")
  176. check_nr_results(dev[0], ["00:11:22:33:44:55", "00:11:22:33:44:56"],
  177. lci=True, civic=True)
  178. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST ssid=\"test4\""):
  179. raise Exception("Request failed")
  180. check_nr_results(dev[0], ["00:11:22:33:44:56"])
  181. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST ssid=\"test4\" lci"):
  182. raise Exception("Request failed")
  183. check_nr_results(dev[0], ["00:11:22:33:44:56"], lci=True)
  184. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST ssid=\"test4\" civic"):
  185. raise Exception("Request failed")
  186. check_nr_results(dev[0], ["00:11:22:33:44:56"], civic=True)
  187. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST ssid=\"test4\" lci civic"):
  188. raise Exception("Request failed")
  189. check_nr_results(dev[0], ["00:11:22:33:44:56"], lci=True, civic=True)
  190. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST ssid=\"test5\""):
  191. raise Exception("Request failed")
  192. check_nr_results(dev[0], ["dd:11:22:33:44:55"])
  193. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST ssid=\"test5\" lci"):
  194. raise Exception("Request failed")
  195. check_nr_results(dev[0], ["dd:11:22:33:44:55"], lci=True)
  196. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST ssid=\"test5\" civic"):
  197. raise Exception("Request failed")
  198. check_nr_results(dev[0], ["dd:11:22:33:44:55"])
  199. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST ssid=\"test5\" lci civic"):
  200. raise Exception("Request failed")
  201. check_nr_results(dev[0], ["dd:11:22:33:44:55"], lci=True)
  202. def test_rrm_lci_req(dev, apdev):
  203. """hostapd lci request"""
  204. check_rrm_support(dev[0])
  205. params = { "ssid": "rrm", "rrm_neighbor_report": "1" }
  206. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  207. # station not specified
  208. if "FAIL" not in hapd.request("REQ_LCI "):
  209. raise Exception("REQ_LCI with no station succeeded unexpectedly")
  210. # station that is not connected specified
  211. if "FAIL" not in hapd.request("REQ_LCI " + dev[0].own_addr()):
  212. raise Exception("REQ_LCI succeeded unexpectedly (station not connected)")
  213. dev[0].request("SET LCI ")
  214. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  215. # station connected without LCI
  216. if "FAIL" not in hapd.request("REQ_LCI " + dev[0].own_addr()):
  217. raise Exception("REQ_LCI succeeded unexpectedly (station without lci)")
  218. dev[0].request("DISCONNECT")
  219. dev[0].wait_disconnected(timeout=2)
  220. dev[0].request("SET LCI " + lci)
  221. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  222. # station connected with LCI
  223. if "OK" not in hapd.request("REQ_LCI " + dev[0].own_addr()):
  224. raise Exception("REQ_LCI failed unexpectedly")
  225. def test_rrm_lci_req_oom(dev, apdev):
  226. """LCI report generation OOM"""
  227. check_rrm_support(dev[0])
  228. params = { "ssid": "rrm", "rrm_neighbor_report": "1" }
  229. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  230. dev[0].request("SET LCI " + lci)
  231. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  232. with alloc_fail(dev[0], 1, "wpabuf_resize;wpas_rrm_build_lci_report"):
  233. if "OK" not in hapd.request("REQ_LCI " + dev[0].own_addr()):
  234. raise Exception("REQ_LCI failed unexpectedly")
  235. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  236. dev[0].request("SET LCI ")
  237. # This in in wpas_rrm_build_lci_report(), but backtrace may not always work
  238. # for the "reject" label there.
  239. with alloc_fail(dev[0], 1, "wpabuf_resize;wpas_rrm_handle_msr_req_element"):
  240. if "OK" not in hapd.request("REQ_LCI " + dev[0].own_addr()):
  241. raise Exception("REQ_LCI failed unexpectedly")
  242. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  243. def test_rrm_neighbor_rep_req_from_conf(dev, apdev):
  244. """wpa_supplicant ctrl_iface NEIGHBOR_REP_REQUEST and hostapd config"""
  245. check_rrm_support(dev[0])
  246. params = { "ssid": "test2", "rrm_neighbor_report": "1",
  247. "stationary_ap": "1", "lci": lci, "civic": civic }
  248. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  249. bssid = apdev[0]['bssid']
  250. dev[0].connect("test2", key_mgmt="NONE", scan_freq="2412")
  251. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  252. raise Exception("Request failed")
  253. check_nr_results(dev[0], [bssid])
  254. def test_rrm_neighbor_rep_req_timeout(dev, apdev):
  255. """wpa_supplicant behavior on NEIGHBOR_REP_REQUEST response timeout"""
  256. check_rrm_support(dev[0])
  257. params = { "ssid": "test2", "rrm_neighbor_report": "1",
  258. "stationary_ap": "1", "lci": lci, "civic": civic }
  259. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  260. dev[0].connect("test2", key_mgmt="NONE", scan_freq="2412")
  261. hapd.set("ext_mgmt_frame_handling", "1")
  262. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  263. raise Exception("Request failed")
  264. msg = hapd.mgmt_rx()
  265. if msg is None:
  266. raise Exception("Neighbor report request not seen")
  267. check_nr_results(dev[0])
  268. def test_rrm_neighbor_rep_req_oom(dev, apdev):
  269. """wpa_supplicant ctrl_iface NEIGHBOR_REP_REQUEST OOM"""
  270. check_rrm_support(dev[0])
  271. params = { "ssid": "test2", "rrm_neighbor_report": "1",
  272. "stationary_ap": "1", "lci": lci, "civic": civic }
  273. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  274. dev[0].connect("test2", key_mgmt="NONE", scan_freq="2412")
  275. with alloc_fail(dev[0], 1, "wpabuf_alloc;wpas_rrm_process_neighbor_rep"):
  276. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  277. raise Exception("Request failed")
  278. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  279. with fail_test(dev[0], 1,
  280. "wpa_driver_nl80211_send_action;wpas_rrm_send_neighbor_rep_request"):
  281. if "FAIL" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  282. raise Exception("Request succeeded unexpectedly")
  283. with alloc_fail(dev[0], 1,
  284. "wpabuf_alloc;wpas_rrm_send_neighbor_rep_request"):
  285. if "FAIL" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  286. raise Exception("Request succeeded unexpectedly")
  287. def test_rrm_neighbor_rep_req_disconnect(dev, apdev):
  288. """wpa_supplicant behavior on disconnection during NEIGHBOR_REP_REQUEST"""
  289. check_rrm_support(dev[0])
  290. params = { "ssid": "test2", "rrm_neighbor_report": "1",
  291. "stationary_ap": "1", "lci": lci, "civic": civic }
  292. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  293. if "FAIL" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  294. raise Exception("Request accepted while disconnected")
  295. dev[0].connect("test2", key_mgmt="NONE", scan_freq="2412")
  296. hapd.set("ext_mgmt_frame_handling", "1")
  297. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  298. raise Exception("Request failed")
  299. msg = hapd.mgmt_rx()
  300. if msg is None:
  301. raise Exception("Neighbor report request not seen")
  302. dev[0].request("DISCONNECT")
  303. check_nr_results(dev[0])
  304. def test_rrm_neighbor_rep_req_not_supported(dev, apdev):
  305. """NEIGHBOR_REP_REQUEST for AP not supporting neighbor report"""
  306. check_rrm_support(dev[0])
  307. params = { "ssid": "test2", "rrm_beacon_report": "1" }
  308. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  309. dev[0].connect("test2", key_mgmt="NONE", scan_freq="2412")
  310. if "FAIL" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  311. raise Exception("Request accepted unexpectedly")
  312. def test_rrm_neighbor_rep_req_busy(dev, apdev):
  313. """wpa_supplicant and concurrent NEIGHBOR_REP_REQUEST commands"""
  314. check_rrm_support(dev[0])
  315. params = { "ssid": "test2", "rrm_neighbor_report": "1",
  316. "stationary_ap": "1", "lci": lci, "civic": civic }
  317. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  318. dev[0].connect("test2", key_mgmt="NONE", scan_freq="2412")
  319. hapd.set("ext_mgmt_frame_handling", "1")
  320. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  321. raise Exception("Request failed")
  322. msg = hapd.mgmt_rx()
  323. if msg is None:
  324. raise Exception("Neighbor report request not seen")
  325. if "FAIL" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  326. raise Exception("Request accepted while disconnected")
  327. def test_rrm_ftm_range_req(dev, apdev):
  328. """hostapd FTM range request command"""
  329. check_rrm_support(dev[0])
  330. params = { "ssid": "rrm", "rrm_neighbor_report": "1" }
  331. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  332. # station not specified
  333. if "FAIL" not in hapd.request("REQ_RANGE "):
  334. raise Exception("REQ_RANGE with no station succeeded unexpectedly")
  335. # station that is not connected specified
  336. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr()):
  337. raise Exception("REQ_RANGE succeeded unexpectedly (station not connected)")
  338. # No responders specified
  339. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 10 10"):
  340. raise Exception("REQ_RANGE succeeded unexpectedly (no responder)")
  341. # Bad responder address
  342. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 10 10 00:11:22:33:44:"):
  343. raise Exception("REQ_RANGE succeeded unexpectedly (bad responder address)")
  344. # Bad responder address
  345. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 10 10 00:11:22:33:44:55 00:11:22:33:44"):
  346. raise Exception("REQ_RANGE succeeded unexpectedly (bad responder address 2)")
  347. # Bad min_ap value
  348. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 10 300 00:11:22:33:44:55"):
  349. raise Exception("REQ_RANGE succeeded unexpectedly (invalid min_ap value)")
  350. # Bad rand value
  351. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " -1 10 00:11:22:33:44:55"):
  352. raise Exception("REQ_RANGE succeeded unexpectedly (invalid rand value)")
  353. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 65536 10 00:11:22:33:44:55"):
  354. raise Exception("REQ_RANGE succeeded unexpectedly (invalid rand value)")
  355. # Missing min_ap value
  356. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 10"):
  357. raise Exception("REQ_RANGE succeeded unexpectedly (missing min_ap value)")
  358. # Too many responders
  359. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 10 10" + 20*" 00:11:22:33:44:55"):
  360. raise Exception("REQ_RANGE succeeded unexpectedly (too many responders)")
  361. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  362. # Responder not in database
  363. # Note: this check would pass since the station does not support FTM range
  364. # request and not because the responder is not in the database.
  365. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 10 10 00:11:22:33:44:55"):
  366. raise Exception("REQ_RANGE succeeded unexpectedly (responder not in database)")
  367. def test_rrm_ftm_capa_indication(dev, apdev):
  368. """FTM capability indication"""
  369. try:
  370. _test_rrm_ftm_capa_indication(dev, apdev)
  371. finally:
  372. dev[0].request("SET ftm_initiator 0")
  373. dev[0].request("SET ftm_responder 0")
  374. def _test_rrm_ftm_capa_indication(dev, apdev):
  375. params = { "ssid": "ftm",
  376. "ftm_responder": "1",
  377. "ftm_initiator": "1", }
  378. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  379. if "OK" not in dev[0].request("SET ftm_initiator 1"):
  380. raise Exception("could not set ftm_initiator")
  381. if "OK" not in dev[0].request("SET ftm_responder 1"):
  382. raise Exception("could not set ftm_responder")
  383. dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412, force_scan=True)
  384. class BeaconReport:
  385. def __init__(self, report):
  386. self.opclass, self.channel, self.start, self.duration, self.frame_info, self.rcpi, self.rsni = struct.unpack("<BBQHBBB", report[0:15])
  387. report = report[15:]
  388. self.bssid = report[0:6]
  389. self.bssid_str = "%02x:%02x:%02x:%02x:%02x:%02x" % (struct.unpack('6B', self.bssid))
  390. report = report[6:]
  391. self.antenna_id, self.parent_tsf = struct.unpack("<BI", report[0:5])
  392. report = report[5:]
  393. self.subelems = report
  394. self.frame_body = None
  395. while len(report) >= 2:
  396. eid,elen = struct.unpack('BB', report[0:2])
  397. report = report[2:]
  398. if len(report) < elen:
  399. raise Exception("Invalid subelement in beacon report")
  400. if eid == 1:
  401. # Reported Frame Body
  402. # Contents depends on the reporting detail request:
  403. # 0 = no Reported Frame Body subelement
  404. # 1 = all fixed fields and any elements identified in Request
  405. # element
  406. # 2 = all fixed fields and all elements
  407. # Fixed fields: Timestamp[8] BeaconInt[2] CapabInfo[2]
  408. self.frame_body = report[0:elen]
  409. report = report[elen:]
  410. def __str__(self):
  411. txt = "opclass={} channel={} start={} duration={} frame_info={} rcpi={} rsni={} bssid={} antenna_id={} parent_tsf={}".format(self.opclass, self.channel, self.start, self.duration, self.frame_info, self.rcpi, self.rsni, self.bssid_str, self.antenna_id, self.parent_tsf)
  412. if self.frame_body:
  413. txt += " frame_body=" + binascii.hexlify(self.frame_body)
  414. return txt
  415. def run_req_beacon(hapd, addr, request):
  416. token = hapd.request("REQ_BEACON " + addr + " " + request)
  417. if "FAIL" in token:
  418. raise Exception("REQ_BEACON failed")
  419. ev = hapd.wait_event(["BEACON-REQ-TX-STATUS"], timeout=5)
  420. if ev is None:
  421. raise Exception("No TX status event for beacon request received")
  422. fields = ev.split(' ')
  423. if fields[1] != addr:
  424. raise Exception("Unexpected STA address in TX status: " + fields[1])
  425. if fields[2] != token:
  426. raise Exception("Unexpected dialog token in TX status: " + fields[2] + " (expected " + token + ")")
  427. if fields[3] != "ack=1":
  428. raise Exception("Unexected ACK status in TX status: " + fields[3])
  429. return token
  430. def test_rrm_beacon_req_table(dev, apdev):
  431. """Beacon request - beacon table mode"""
  432. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  433. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  434. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another" })
  435. tests = [ "REQ_BEACON ",
  436. "REQ_BEACON q",
  437. "REQ_BEACON 11:22:33:44:55:66 1",
  438. "REQ_BEACON 11:22:33:44:55:66 1q",
  439. "REQ_BEACON 11:22:33:44:55:66 11223344556677889900aabbccddeeff" ]
  440. for t in tests:
  441. if "FAIL" not in hapd.request(t):
  442. raise Exception("Invalid command accepted: " + t)
  443. dev[0].scan_for_bss(apdev[1]['bssid'], freq=2412)
  444. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  445. addr = dev[0].own_addr()
  446. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff")
  447. for i in range(1, 3):
  448. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  449. if ev is None:
  450. raise Exception("Beacon report %d response not received" % i)
  451. fields = ev.split(' ')
  452. if fields[1] != addr:
  453. raise Exception("Unexpected STA address in beacon report response: " + fields[1])
  454. if fields[2] != token:
  455. raise Exception("Unexpected dialog token in beacon report response: " + fields[2] + " (expected " + token + ")")
  456. if fields[3] != "00":
  457. raise Exception("Unexpected measurement report mode")
  458. report = BeaconReport(binascii.unhexlify(fields[4]))
  459. logger.info("Received beacon report: " + str(report))
  460. # Default reporting detail is 2, i.e., all fixed fields and elements.
  461. if not report.frame_body:
  462. raise Exception("Reported Frame Body subelement missing")
  463. if len(report.frame_body) <= 12:
  464. raise Exception("Too short Reported Frame Body subelement")
  465. def test_rrm_beacon_req_table_detail(dev, apdev):
  466. """Beacon request - beacon table mode - reporting detail"""
  467. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  468. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  469. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  470. addr = dev[0].own_addr()
  471. logger.info("Reporting Detail 0")
  472. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020100")
  473. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  474. if ev is None:
  475. raise Exception("Beacon report response not received")
  476. fields = ev.split(' ')
  477. report = BeaconReport(binascii.unhexlify(fields[4]))
  478. logger.info("Received beacon report: " + str(report))
  479. if report.frame_body:
  480. raise Exception("Reported Frame Body subelement included with Reporting Detail 0")
  481. hapd.dump_monitor()
  482. logger.info("Reporting Detail 1")
  483. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101")
  484. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  485. if ev is None:
  486. raise Exception("Beacon report response not received")
  487. fields = ev.split(' ')
  488. report = BeaconReport(binascii.unhexlify(fields[4]))
  489. logger.info("Received beacon report: " + str(report))
  490. if not report.frame_body:
  491. raise Exception("Reported Frame Body subelement missing")
  492. if len(report.frame_body) != 12:
  493. raise Exception("Unexpected Reported Frame Body subelement length with Reporting Detail 1")
  494. hapd.dump_monitor()
  495. logger.info("Reporting Detail 2")
  496. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020102")
  497. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  498. if ev is None:
  499. raise Exception("Beacon report response not received")
  500. fields = ev.split(' ')
  501. report = BeaconReport(binascii.unhexlify(fields[4]))
  502. logger.info("Received beacon report: " + str(report))
  503. if not report.frame_body:
  504. raise Exception("Reported Frame Body subelement missing")
  505. if len(report.frame_body) <= 12:
  506. raise Exception("Unexpected Reported Frame Body subelement length with Reporting Detail 2")
  507. hapd.dump_monitor()
  508. logger.info("Reporting Detail 3 (invalid)")
  509. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020103")
  510. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  511. if ev is not None:
  512. raise Exception("Unexpected beacon report response to invalid reporting detail 3")
  513. hapd.dump_monitor()
  514. logger.info("Reporting Detail (too short)")
  515. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "0200")
  516. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  517. if ev is not None:
  518. raise Exception("Unexpected beacon report response to invalid reporting detail")
  519. hapd.dump_monitor()
  520. def test_rrm_beacon_req_table_request(dev, apdev):
  521. """Beacon request - beacon table mode - request element"""
  522. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  523. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  524. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  525. addr = dev[0].own_addr()
  526. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a03000106")
  527. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  528. if ev is None:
  529. raise Exception("Beacon report response not received")
  530. fields = ev.split(' ')
  531. report = BeaconReport(binascii.unhexlify(fields[4]))
  532. logger.info("Received beacon report: " + str(report))
  533. if not report.frame_body:
  534. raise Exception("Reported Frame Body subelement missing")
  535. if len(report.frame_body) != 12 + 5 + 10:
  536. raise Exception("Unexpected Reported Frame Body subelement length with Reporting Detail 1 and requested elements SSID + SuppRates")
  537. hapd.dump_monitor()
  538. logger.info("Incorrect reporting detail with request subelement")
  539. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020102" + "0a03000106")
  540. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  541. if ev is not None:
  542. raise Exception("Unexpected beacon report response (invalid reporting detail)")
  543. hapd.dump_monitor()
  544. logger.info("Invalid request subelement length")
  545. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a00")
  546. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  547. if ev is not None:
  548. raise Exception("Unexpected beacon report response (invalid request subelement length)")
  549. hapd.dump_monitor()
  550. logger.info("Multiple request subelements")
  551. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a0100" + "0a0101")
  552. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  553. if ev is not None:
  554. raise Exception("Unexpected beacon report response (multiple request subelements)")
  555. hapd.dump_monitor()
  556. def test_rrm_beacon_req_table_request_oom(dev, apdev):
  557. """Beacon request - beacon table mode - request element OOM"""
  558. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  559. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  560. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  561. addr = dev[0].own_addr()
  562. with alloc_fail(dev[0], 1,
  563. "bitfield_alloc;wpas_rm_handle_beacon_req_subelem"):
  564. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a03000106")
  565. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  566. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.1)
  567. if ev is not None:
  568. raise Exception("Unexpected beacon report response received (OOM)")
  569. with alloc_fail(dev[0], 1,
  570. "wpabuf_alloc;wpas_rrm_send_msr_report_mpdu"):
  571. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a03000106")
  572. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  573. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.1)
  574. if ev is not None:
  575. raise Exception("Unexpected beacon report response received (OOM)")
  576. with fail_test(dev[0], 1,
  577. "wpa_driver_nl80211_send_action;wpas_rrm_send_msr_report_mpdu"):
  578. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a03000106")
  579. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  580. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.1)
  581. if ev is not None:
  582. raise Exception("Unexpected beacon report response received (OOM)")
  583. with alloc_fail(dev[0], 1,
  584. "wpabuf_resize;wpas_add_beacon_rep"):
  585. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a03000106")
  586. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  587. if ev is None:
  588. raise Exception("Beacon report response not received (OOM -> empty report)")
  589. fields = ev.split(' ')
  590. if len(fields[4]) > 0:
  591. raise Exception("Unexpected beacon report received")
  592. def test_rrm_beacon_req_table_bssid(dev, apdev):
  593. """Beacon request - beacon table mode - specific BSSID"""
  594. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  595. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  596. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another" })
  597. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  598. addr = dev[0].own_addr()
  599. bssid2 = hapd2.own_addr()
  600. token = run_req_beacon(hapd, addr, "51000000000002" + bssid2.replace(':', ''))
  601. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  602. if ev is None:
  603. raise Exception("Beacon report response not received")
  604. fields = ev.split(' ')
  605. report = BeaconReport(binascii.unhexlify(fields[4]))
  606. logger.info("Received beacon report: " + str(report))
  607. if "bssid=" + bssid2 not in str(report):
  608. raise Exception("Report for unexpect BSS")
  609. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.1)
  610. if ev is not None:
  611. raise Exception("Unexpected beacon report response")
  612. def test_rrm_beacon_req_table_ssid(dev, apdev):
  613. """Beacon request - beacon table mode - specific SSID"""
  614. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  615. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  616. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another" })
  617. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  618. addr = dev[0].own_addr()
  619. bssid2 = hapd2.own_addr()
  620. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "0007" + "another".encode('hex'))
  621. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  622. if ev is None:
  623. raise Exception("Beacon report response not received")
  624. fields = ev.split(' ')
  625. report = BeaconReport(binascii.unhexlify(fields[4]))
  626. logger.info("Received beacon report: " + str(report))
  627. if "bssid=" + bssid2 not in str(report):
  628. raise Exception("Report for unexpect BSS")
  629. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.1)
  630. if ev is not None:
  631. raise Exception("Unexpected beacon report response")
  632. hapd.dump_monitor()
  633. logger.info("Wildcard SSID")
  634. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "0000")
  635. for i in range(2):
  636. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  637. if ev is None:
  638. raise Exception("Beacon report response not received")
  639. fields = ev.split(' ')
  640. report = BeaconReport(binascii.unhexlify(fields[4]))
  641. logger.info("Received beacon report: " + str(report))
  642. hapd.dump_monitor()
  643. logger.info("Too long SSID")
  644. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "0021" + 33*"00")
  645. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  646. if ev is not None:
  647. raise Exception("Unexpected beacon report response (invalid SSID subelement in request)")
  648. hapd.dump_monitor()
  649. def test_rrm_beacon_req_table_info(dev, apdev):
  650. """Beacon request - beacon table mode - Reporting Information subelement"""
  651. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  652. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  653. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  654. addr = dev[0].own_addr()
  655. logger.info("Unsupported reporting information 1")
  656. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "01020100")
  657. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  658. if ev is not None:
  659. raise Exception("Unexpected beacon report response (unsupported reporting information 1)")
  660. hapd.dump_monitor()
  661. logger.info("Invalid reporting information length")
  662. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "010100")
  663. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  664. if ev is not None:
  665. raise Exception("Unexpected beacon report response (invalid reporting information length)")
  666. hapd.dump_monitor()
  667. def test_rrm_beacon_req_table_unknown_subelem(dev, apdev):
  668. """Beacon request - beacon table mode - unknown subelement"""
  669. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  670. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  671. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  672. addr = dev[0].own_addr()
  673. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "330101" + "fe00")
  674. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  675. if ev is None:
  676. raise Exception("Beacon report response not received")
  677. fields = ev.split(' ')
  678. report = BeaconReport(binascii.unhexlify(fields[4]))
  679. logger.info("Received beacon report: " + str(report))
  680. def test_rrm_beacon_req_table_truncated_subelem(dev, apdev):
  681. """Beacon request - beacon table mode - Truncated subelement"""
  682. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  683. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  684. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  685. addr = dev[0].own_addr()
  686. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "0001")
  687. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  688. if ev is not None:
  689. raise Exception("Unexpected beacon report response (truncated subelement)")
  690. hapd.dump_monitor()
  691. def test_rrm_beacon_req_table_rsne(dev, apdev):
  692. """Beacon request - beacon table mode - RSNE truncation"""
  693. params = hostapd.wpa2_params(ssid="rrm-rsn", passphrase="12345678")
  694. params["rrm_beacon_report"] = "1"
  695. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  696. dev[0].connect("rrm-rsn", psk="12345678", scan_freq="2412")
  697. addr = dev[0].own_addr()
  698. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a0130")
  699. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  700. if ev is None:
  701. raise Exception("Beacon report response not received")
  702. fields = ev.split(' ')
  703. report = BeaconReport(binascii.unhexlify(fields[4]))
  704. logger.info("Received beacon report: " + str(report))
  705. if not report.frame_body:
  706. raise Exception("Reported Frame Body subelement missing")
  707. if len(report.frame_body) != 12 + 6:
  708. raise Exception("Unexpected Reported Frame Body subelement length with Reporting Detail 1 and requested element RSNE")
  709. if binascii.unhexlify("30040100000f") not in report.frame_body:
  710. raise Exception("Truncated RSNE not found")
  711. def test_rrm_beacon_req_table_vht(dev, apdev):
  712. """Beacon request - beacon table mode - VHT"""
  713. clear_scan_cache(apdev[0])
  714. try:
  715. hapd = None
  716. params = { "ssid": "rrm-vht",
  717. "country_code": "FI",
  718. "hw_mode": "a",
  719. "channel": "36",
  720. "ht_capab": "[HT40+]",
  721. "ieee80211n": "1",
  722. "ieee80211ac": "1",
  723. "vht_oper_chwidth": "1",
  724. "vht_oper_centr_freq_seg0_idx": "42",
  725. "rrm_beacon_report": "1" }
  726. hapd = hostapd.add_ap(apdev[0], params)
  727. params = { "ssid": "test-vht40",
  728. "country_code": "FI",
  729. "hw_mode": "a",
  730. "channel": "48",
  731. "ieee80211n": "1",
  732. "ieee80211ac": "1",
  733. "ht_capab": "[HT40-]",
  734. "vht_capab": "",
  735. "vht_oper_chwidth": "0",
  736. "vht_oper_centr_freq_seg0_idx": "0",
  737. }
  738. hapd2 = hostapd.add_ap(apdev[1], params)
  739. dev[0].scan_for_bss(apdev[1]['bssid'], freq=5240)
  740. dev[0].connect("rrm-vht", key_mgmt="NONE", scan_freq="5180")
  741. addr = dev[0].own_addr()
  742. token = run_req_beacon(hapd, addr, "f0000000000002ffffffffffff")
  743. for i in range(2):
  744. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  745. if ev is None:
  746. raise Exception("Beacon report %d response not received" % i)
  747. fields = ev.split(' ')
  748. report = BeaconReport(binascii.unhexlify(fields[4]))
  749. logger.info("Received beacon report: " + str(report))
  750. if report.bssid_str == apdev[0]['bssid']:
  751. if report.opclass != 128 or report.channel != 36:
  752. raise Exception("Incorrect opclass/channel for AP0")
  753. elif report.bssid_str == apdev[1]['bssid']:
  754. if report.opclass != 117 or report.channel != 48:
  755. raise Exception("Incorrect opclass/channel for AP1")
  756. except Exception, e:
  757. if isinstance(e, Exception) and str(e) == "AP startup failed":
  758. if not vht_supported():
  759. raise HwsimSkip("80 MHz channel not supported in regulatory information")
  760. raise
  761. finally:
  762. dev[0].request("DISCONNECT")
  763. if hapd:
  764. hapd.request("DISABLE")
  765. subprocess.call(['iw', 'reg', 'set', '00'])
  766. dev[0].flush_scan_cache()
  767. def test_rrm_beacon_req_active(dev, apdev):
  768. """Beacon request - active scan mode"""
  769. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  770. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  771. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  772. "channel": "11" })
  773. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  774. addr = dev[0].own_addr()
  775. token = run_req_beacon(hapd, addr, "51000000640001ffffffffffff")
  776. for i in range(1, 3):
  777. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  778. if ev is None:
  779. raise Exception("Beacon report %d response not received" % i)
  780. fields = ev.split(' ')
  781. report = BeaconReport(binascii.unhexlify(fields[4]))
  782. logger.info("Received beacon report: " + str(report))
  783. if report.bssid_str == apdev[0]['bssid']:
  784. if report.opclass != 81 or report.channel != 1:
  785. raise Exception("Incorrect opclass/channel for AP0")
  786. elif report.bssid_str == apdev[1]['bssid']:
  787. if report.opclass != 81 or report.channel != 11:
  788. raise Exception("Incorrect opclass/channel for AP1")
  789. def test_rrm_beacon_req_active_ignore_old_result(dev, apdev):
  790. """Beacon request - active scan mode and old scan result"""
  791. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another" })
  792. dev[0].scan_for_bss(apdev[1]['bssid'], freq=2412)
  793. hapd2.disable()
  794. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  795. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  796. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  797. addr = dev[0].own_addr()
  798. token = run_req_beacon(hapd, addr, "51010000640001ffffffffffff")
  799. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  800. if ev is None:
  801. raise Exception("Beacon report response not received")
  802. fields = ev.split(' ')
  803. report = BeaconReport(binascii.unhexlify(fields[4]))
  804. logger.info("Received beacon report: " + str(report))
  805. if report.bssid_str == apdev[1]['bssid']:
  806. raise Exception("Old BSS reported")
  807. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  808. if ev is not None:
  809. raise Exception("Unexpected beacon report response")
  810. def start_ap(dev):
  811. id = dev.add_network()
  812. dev.set_network(id, "mode", "2")
  813. dev.set_network_quoted(id, "ssid", 32*'A')
  814. dev.set_network_quoted(id, "psk", "1234567890")
  815. dev.set_network(id, "frequency", "2412")
  816. dev.set_network(id, "scan_freq", "2412")
  817. dev.select_network(id)
  818. dev.wait_connected()
  819. def test_rrm_beacon_req_active_many(dev, apdev):
  820. """Beacon request - active scan mode and many BSSs"""
  821. for i in range(1, 7):
  822. ifname = apdev[0]['ifname'] if i == 1 else apdev[0]['ifname'] + "-%d" % i
  823. hapd1 = hostapd.add_bss(apdev[0], ifname, 'bss-%i.conf' % i)
  824. hapd1.set('vendor_elements', "dd50" + 80*'bb')
  825. hapd1.request("UPDATE_BEACON")
  826. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  827. wpas.interface_add("wlan5")
  828. wpas.request("SET device_name " + 20*'a')
  829. start_ap(wpas)
  830. start_ap(dev[1])
  831. start_ap(dev[2])
  832. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  833. params['vendor_elements'] = "dd50" + 80*'aa'
  834. hapd = hostapd.add_ap(apdev[1]['ifname'], params)
  835. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  836. addr = dev[0].own_addr()
  837. ok = False
  838. for j in range(3):
  839. token = run_req_beacon(hapd, addr, "51010000640001ffffffffffff")
  840. for i in range(10):
  841. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  842. if ev is None:
  843. raise Exception("Beacon report %d response not received" % i)
  844. fields = ev.split(' ')
  845. if len(fields[4]) == 0:
  846. break
  847. report = BeaconReport(binascii.unhexlify(fields[4]))
  848. logger.info("Received beacon report: " + str(report))
  849. if i == 9:
  850. ok = True
  851. if ok:
  852. break
  853. def test_rrm_beacon_req_active_ap_channels(dev, apdev):
  854. """Beacon request - active scan mode with AP Channel Report subelement"""
  855. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  856. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  857. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  858. "channel": "11" })
  859. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  860. addr = dev[0].own_addr()
  861. token = run_req_beacon(hapd, addr, "51ff0000640001ffffffffffff" + "dd0111" + "330351010b" + "dd0111")
  862. for i in range(1, 3):
  863. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  864. if ev is None:
  865. raise Exception("Beacon report %d response not received" % i)
  866. fields = ev.split(' ')
  867. report = BeaconReport(binascii.unhexlify(fields[4]))
  868. logger.info("Received beacon report: " + str(report))
  869. if report.bssid_str == apdev[0]['bssid']:
  870. if report.opclass != 81 or report.channel != 1:
  871. raise Exception("Incorrect opclass/channel for AP0")
  872. elif report.bssid_str == apdev[1]['bssid']:
  873. if report.opclass != 81 or report.channel != 11:
  874. raise Exception("Incorrect opclass/channel for AP1")
  875. def test_rrm_beacon_req_passive_ap_channels(dev, apdev):
  876. """Beacon request - passive scan mode with AP Channel Report subelement"""
  877. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  878. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  879. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  880. "channel": "11" })
  881. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  882. addr = dev[0].own_addr()
  883. token = run_req_beacon(hapd, addr, "51ff0000640000ffffffffffff" + "330351010b" + "3300" + "dd00")
  884. for i in range(1, 3):
  885. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  886. if ev is None:
  887. raise Exception("Beacon report %d response not received" % i)
  888. fields = ev.split(' ')
  889. report = BeaconReport(binascii.unhexlify(fields[4]))
  890. logger.info("Received beacon report: " + str(report))
  891. if report.bssid_str == apdev[0]['bssid']:
  892. if report.opclass != 81 or report.channel != 1:
  893. raise Exception("Incorrect opclass/channel for AP0")
  894. elif report.bssid_str == apdev[1]['bssid']:
  895. if report.opclass != 81 or report.channel != 11:
  896. raise Exception("Incorrect opclass/channel for AP1")
  897. def test_rrm_beacon_req_active_single_channel(dev, apdev):
  898. """Beacon request - active scan mode with single channel"""
  899. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  900. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  901. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  902. "channel": "11" })
  903. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  904. addr = dev[0].own_addr()
  905. token = run_req_beacon(hapd, addr, "510b0000640001ffffffffffff")
  906. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  907. if ev is None:
  908. raise Exception("Beacon report response not received")
  909. fields = ev.split(' ')
  910. report = BeaconReport(binascii.unhexlify(fields[4]))
  911. logger.info("Received beacon report: " + str(report))
  912. def test_rrm_beacon_req_active_ap_channels_unknown_opclass(dev, apdev):
  913. """Beacon request - active scan mode with AP Channel Report subelement and unknown opclass"""
  914. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  915. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  916. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  917. "channel": "11" })
  918. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  919. addr = dev[0].own_addr()
  920. token = run_req_beacon(hapd, addr, "51ff0000640001ffffffffffff" + "3303ff010b")
  921. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  922. if ev is not None:
  923. raise Exception("Unexpected Beacon report")
  924. def test_rrm_beacon_req_active_ap_channel_oom(dev, apdev):
  925. """Beacon request - AP Channel Report subelement and OOM"""
  926. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  927. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  928. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  929. "channel": "11" })
  930. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  931. addr = dev[0].own_addr()
  932. with alloc_fail(dev[0], 1, "wpas_add_channels"):
  933. token = run_req_beacon(hapd, addr, "51ff0000640001ffffffffffff" + "330351010b")
  934. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  935. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.1)
  936. if ev is not None:
  937. raise Exception("Unexpected Beacon report during OOM")
  938. def test_rrm_beacon_req_active_scan_fail(dev, apdev):
  939. """Beacon request - Active scan failure"""
  940. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  941. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  942. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  943. addr = dev[0].own_addr()
  944. with alloc_fail(dev[0], 1, "wpa_supplicant_trigger_scan"):
  945. token = run_req_beacon(hapd, addr, "51ff0000640001ffffffffffff" + "330351010b")
  946. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  947. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  948. if ev is None:
  949. raise Exception("No Beacon report")
  950. fields = ev.split(' ')
  951. if fields[3] != "04":
  952. raise Exception("Unexpected Beacon report contents: " + ev)
  953. def test_rrm_beacon_req_active_zero_duration(dev, apdev):
  954. """Beacon request - Action scan and zero duration"""
  955. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  956. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  957. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  958. "channel": "11" })
  959. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  960. addr = dev[0].own_addr()
  961. token = run_req_beacon(hapd, addr, "51000000000001ffffffffffff")
  962. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  963. if ev is not None:
  964. raise Exception("Unexpected Beacon report")
  965. def test_rrm_beacon_req_active_fail_random(dev, apdev):
  966. """Beacon request - active scan mode os_get_random failure"""
  967. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  968. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  969. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  970. addr = dev[0].own_addr()
  971. with fail_test(dev[0], 1, "os_get_random;wpas_rm_handle_beacon_req"):
  972. token = run_req_beacon(hapd, addr, "51000000640001ffffffffffff")
  973. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  974. if ev is None:
  975. raise Exception("Beacon report response not received")
  976. fields = ev.split(' ')
  977. report = BeaconReport(binascii.unhexlify(fields[4]))
  978. logger.info("Received beacon report: " + str(report))
  979. def test_rrm_beacon_req_passive(dev, apdev):
  980. """Beacon request - passive scan mode"""
  981. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  982. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  983. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  984. "channel": "11" })
  985. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  986. addr = dev[0].own_addr()
  987. token = run_req_beacon(hapd, addr, "51000000640000ffffffffffff")
  988. for i in range(1, 3):
  989. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  990. if ev is None:
  991. raise Exception("Beacon report %d response not received" % i)
  992. fields = ev.split(' ')
  993. report = BeaconReport(binascii.unhexlify(fields[4]))
  994. logger.info("Received beacon report: " + str(report))
  995. if report.bssid_str == apdev[0]['bssid']:
  996. if report.opclass != 81 or report.channel != 1:
  997. raise Exception("Incorrect opclass/channel for AP0")
  998. elif report.bssid_str == apdev[1]['bssid']:
  999. if report.opclass != 81 or report.channel != 11:
  1000. raise Exception("Incorrect opclass/channel for AP1")
  1001. def test_rrm_beacon_req_passive_no_match(dev, apdev):
  1002. """Beacon request - passive scan mode and no matching BSS"""
  1003. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  1004. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1005. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  1006. addr = dev[0].own_addr()
  1007. token = run_req_beacon(hapd, addr, "51010000640000021122334455")
  1008. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  1009. if ev is None:
  1010. raise Exception("Beacon report %d response not received" % i)
  1011. fields = ev.split(' ')
  1012. if len(fields[4]) > 0:
  1013. raise Exception("Unexpected beacon report BSS")
  1014. def test_rrm_beacon_req_passive_no_match_oom(dev, apdev):
  1015. """Beacon request - passive scan mode and no matching BSS (OOM)"""
  1016. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  1017. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1018. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  1019. addr = dev[0].own_addr()
  1020. with alloc_fail(dev[0], 1, "wpabuf_resize;wpas_beacon_rep_scan_process"):
  1021. token = run_req_beacon(hapd, addr, "51010000640000021122334455")
  1022. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  1023. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  1024. if ev is not None:
  1025. raise Exception("Unexpected Beacon report response during OOM")
  1026. # verify reporting is still functional
  1027. token = run_req_beacon(hapd, addr, "51010000640000021122334455")
  1028. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  1029. if ev is None:
  1030. raise Exception("Beacon report %d response not received" % i)
  1031. fields = ev.split(' ')
  1032. if len(fields[4]) > 0:
  1033. raise Exception("Unexpected beacon report BSS")
  1034. def test_rrm_beacon_req_active_duration_mandatory(dev, apdev):
  1035. """Beacon request - Action scan and duration mandatory"""
  1036. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  1037. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1038. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  1039. addr = dev[0].own_addr()
  1040. token = run_req_beacon(hapd, addr, "req_mode=10 51000000640001ffffffffffff")
  1041. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  1042. if ev is None:
  1043. raise Exception("No Beacon report response")
  1044. fields = ev.split(' ')
  1045. rrm = int(dev[0].get_driver_status_field("capa.rrm_flags"), 16)
  1046. if rrm & 0x20 == 0x20:
  1047. report = BeaconReport(binascii.unhexlify(fields[4]))
  1048. logger.info("Received beacon report: " + str(report))
  1049. else:
  1050. # Driver does not support scan dwell time setting, so wpa_supplicant
  1051. # rejects the measurement request due to the mandatory duration using
  1052. # Measurement Report Mode field Incapable=1.
  1053. if fields[3] != '02':
  1054. raise Exception("Unexpected Measurement Report Mode: " + fields[3])
  1055. if len(fields[4]) > 0:
  1056. raise Exception("Unexpected beacon report received")
  1057. def test_rrm_beacon_req_passive_scan_vht(dev, apdev):
  1058. """Beacon request - passive scan mode - VHT"""
  1059. clear_scan_cache(apdev[0])
  1060. try:
  1061. hapd = None
  1062. params = { "ssid": "rrm-vht",
  1063. "country_code": "FI",
  1064. 'ieee80211d': '1',
  1065. "hw_mode": "a",
  1066. "channel": "36",
  1067. "ht_capab": "[HT40+]",
  1068. "ieee80211n": "1",
  1069. "ieee80211ac": "1",
  1070. "vht_oper_chwidth": "1",
  1071. "vht_oper_centr_freq_seg0_idx": "42",
  1072. "rrm_beacon_report": "1" }
  1073. hapd = hostapd.add_ap(apdev[0], params)
  1074. dev[0].scan_for_bss(apdev[0]['bssid'], freq=5180)
  1075. dev[0].connect("rrm-vht", key_mgmt="NONE", scan_freq="5180")
  1076. addr = dev[0].own_addr()
  1077. token = run_req_beacon(hapd, addr, "80000000640000ffffffffffff")
  1078. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  1079. if ev is None:
  1080. raise Exception("Beacon report response not received")
  1081. fields = ev.split(' ')
  1082. report = BeaconReport(binascii.unhexlify(fields[4]))
  1083. logger.info("Received beacon report: " + str(report))
  1084. if report.opclass != 128 or report.channel != 36:
  1085. raise Exception("Incorrect opclass/channel for AP")
  1086. token = run_req_beacon(hapd, addr, "82000000640000ffffffffffff")
  1087. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  1088. if ev is None:
  1089. raise Exception("Beacon report response not received")
  1090. fields = ev.split(' ')
  1091. report = BeaconReport(binascii.unhexlify(fields[4]))
  1092. logger.info("Received beacon report: " + str(report))
  1093. if report.opclass != 128 or report.channel != 36:
  1094. raise Exception("Incorrect opclass/channel for AP")
  1095. except Exception, e:
  1096. if isinstance(e, Exception) and str(e) == "AP startup failed":
  1097. if not vht_supported():
  1098. raise HwsimSkip("80 MHz channel not supported in regulatory information")
  1099. raise
  1100. finally:
  1101. dev[0].request("DISCONNECT")
  1102. if hapd:
  1103. hapd.request("DISABLE")
  1104. subprocess.call(['iw', 'reg', 'set', '00'])
  1105. dev[0].flush_scan_cache()
  1106. def test_rrm_beacon_req_passive_scan_vht160(dev, apdev):
  1107. """Beacon request - passive scan mode - VHT160"""
  1108. clear_scan_cache(apdev[0])
  1109. try:
  1110. hapd = None
  1111. params = { "ssid": "rrm-vht",
  1112. "country_code": "ZA",
  1113. 'ieee80211d': '1',
  1114. "hw_mode": "a",
  1115. "channel": "104",
  1116. "ht_capab": "[HT40-]",
  1117. "ieee80211n": "1",
  1118. "ieee80211ac": "1",
  1119. "vht_oper_chwidth": "2",
  1120. "vht_oper_centr_freq_seg0_idx": "114",
  1121. "rrm_beacon_report": "1" }
  1122. hapd = hostapd.add_ap(apdev[0], params)
  1123. dev[0].scan_for_bss(apdev[0]['bssid'], freq=5520)
  1124. dev[0].connect("rrm-vht", key_mgmt="NONE", scan_freq="5520")
  1125. sig = dev[0].request("SIGNAL_POLL").splitlines()
  1126. if "WIDTH=160 MHz" not in sig:
  1127. raise Exception("Unexpected SIGNAL_POLL value: " + str(sig))
  1128. addr = dev[0].own_addr()
  1129. token = run_req_beacon(hapd, addr, "81000000640000ffffffffffff")
  1130. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  1131. if ev is None:
  1132. raise Exception("Beacon report response not received")
  1133. fields = ev.split(' ')
  1134. report = BeaconReport(binascii.unhexlify(fields[4]))
  1135. logger.info("Received beacon report: " + str(report))
  1136. if report.opclass != 129 or report.channel != 104:
  1137. raise Exception("Incorrect opclass/channel for AP")
  1138. except Exception, e:
  1139. if isinstance(e, Exception) and str(e) == "AP startup failed":
  1140. raise HwsimSkip("ZA regulatory rule likely did not have DFS requirement removed")
  1141. raise
  1142. finally:
  1143. dev[0].request("DISCONNECT")
  1144. if hapd:
  1145. hapd.request("DISABLE")
  1146. subprocess.call(['iw', 'reg', 'set', '00'])
  1147. dev[0].flush_scan_cache()
  1148. def test_rrm_req_reject_oom(dev, apdev):
  1149. """Radio measurement request - OOM while rejecting a request"""
  1150. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  1151. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1152. bssid = hapd.own_addr()
  1153. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  1154. addr = dev[0].own_addr()
  1155. hdr = "d0003a01" + addr.replace(':', '') + 2*bssid.replace(':', '') + "1000"
  1156. hapd.set("ext_mgmt_frame_handling", "1")
  1157. dev[0].request("SET ext_mgmt_frame_handling 1")
  1158. with alloc_fail(dev[0], 1, "wpabuf_resize;wpas_rrm_handle_msr_req_element"):
  1159. # "RRM: Parallel measurements are not supported, reject"
  1160. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + "05000100002603010105"):
  1161. raise Exception("MGMT_RX_PROCESS failed")
  1162. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  1163. ev = hapd.wait_event(["MGMT-RX"], timeout=0.2)
  1164. if ev is not None:
  1165. raise Exception("Unexpected beacon report response during OOM")
  1166. def test_rrm_req_when_rrm_not_used(dev, apdev):
  1167. """Radio/link measurement request for non-RRM association"""
  1168. params = { "ssid": "rrm" }
  1169. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1170. bssid = hapd.own_addr()
  1171. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  1172. addr = dev[0].own_addr()
  1173. hdr = "d0003a01" + addr.replace(':', '') + 2*bssid.replace(':', '') + "1000"
  1174. hapd.set("ext_mgmt_frame_handling", "1")
  1175. dev[0].request("SET ext_mgmt_frame_handling 1")
  1176. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + "050001000026030100fe"):
  1177. raise Exception("MGMT_RX_PROCESS failed")
  1178. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + "0502000000"):
  1179. raise Exception("MGMT_RX_PROCESS failed")
  1180. ev = hapd.wait_event(["MGMT-RX"], timeout=0.2)
  1181. if ev is not None:
  1182. raise Exception("Unexpected beacon report response when RRM is disabled")
  1183. dev[0].request("REMOVE_NETWORK all")
  1184. dev[0].wait_disconnected()
  1185. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + "050001000026030100fe"):
  1186. raise Exception("MGMT_RX_PROCESS failed")
  1187. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + "0502000000"):
  1188. raise Exception("MGMT_RX_PROCESS failed")
  1189. def test_rrm_req_proto(dev, apdev):
  1190. """Radio measurement request - protocol testing"""
  1191. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  1192. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1193. bssid = hapd.own_addr()
  1194. dev[0].request("SET LCI ")
  1195. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  1196. addr = dev[0].own_addr()
  1197. hdr = "d0003a01" + addr.replace(':', '') + 2*bssid.replace(':', '') + "1000"
  1198. hapd.set("ext_mgmt_frame_handling", "1")
  1199. dev[0].request("SET ext_mgmt_frame_handling 1")
  1200. tests = []
  1201. # "RRM: Ignoring too short radio measurement request"
  1202. tests += [ "0500", "050001", "05000100" ]
  1203. # No measurement request element at all
  1204. tests += [ "0500010000" ]
  1205. # "RRM: Truncated element"
  1206. tests += [ "050001000026" ]
  1207. # "RRM: Element length too short"
  1208. tests += [ "05000100002600", "0500010000260111", "050001000026021122" ]
  1209. # "RRM: Element length too long"
  1210. tests += [ "05000100002603", "0500010000260311", "050001000026031122" ]
  1211. # "RRM: Enable bit not supported, ignore"
  1212. tests += [ "05000100002603010200" ]
  1213. # "RRM: Measurement report failed. TX power insertion not supported"
  1214. # OR
  1215. # "RRM: Link measurement report failed. Request too short"
  1216. tests += [ "0502" ]
  1217. # Too short LCI request
  1218. tests += [ "05000100002603010008" ]
  1219. # Too short neighbor report response
  1220. tests += [ "0505" ]
  1221. # Unexpected neighbor report response
  1222. tests += [ "050500", "050501", "050502", "050503", "050504", "050505" ]
  1223. # Too short beacon request
  1224. tests += [ "05000100002603010005",
  1225. "0500010000260f010005112233445566778899aabbcc" ]
  1226. # Unknown beacon report mode
  1227. tests += [ "05000100002610010005112233445566778899aabbccdd" ]
  1228. # Beacon report info subelement; no valid channels
  1229. tests += [ "05000100002614010005112233445566008899aabbccdd01020000" ]
  1230. # "RRM: Expected Measurement Request element, but EID is 0"
  1231. tests += [ "05000100000000" ]
  1232. for t in tests:
  1233. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + t):
  1234. raise Exception("MGMT_RX_PROCESS failed")
  1235. ev = hapd.wait_event(["MGMT-RX"], timeout=0.2)
  1236. if ev is not None:
  1237. raise Exception("Unexpected response seen at the AP: " + ev)
  1238. tests = []
  1239. # "RRM: Parallel measurements are not supported, reject"
  1240. tests += [ "05000100002603010105" ]
  1241. # "RRM: Unsupported radio measurement type 254"
  1242. tests += [ "050001000026030100fe" ]
  1243. # Reject LCI request
  1244. tests += [ "0500010000260701000811223344" ]
  1245. for t in tests:
  1246. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + t):
  1247. raise Exception("MGMT_RX_PROCESS failed")
  1248. ev = hapd.wait_event(["MGMT-RX"], timeout=5)
  1249. if ev is None:
  1250. raise Exception("No response seen at the AP")
  1251. hapd.dump_monitor()
  1252. dev[0].request("SET LCI " + lci)
  1253. tests = []
  1254. # "Not building LCI report - bad location subject"
  1255. tests += [ "0500010000260701000811223344" ]
  1256. for t in tests:
  1257. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + t):
  1258. raise Exception("MGMT_RX_PROCESS failed")
  1259. ev = hapd.wait_event(["MGMT-RX"], timeout=0.2)
  1260. if ev is not None:
  1261. raise Exception("Unexpected response seen at the AP: " + ev)
  1262. tests = []
  1263. # LCI report or reject
  1264. tests += [ "0500010000260701000801223344",
  1265. "05000100002607010008010402ff",
  1266. "05000100002608010008010402ffff" ]
  1267. for t in tests:
  1268. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + t):
  1269. raise Exception("MGMT_RX_PROCESS failed")
  1270. ev = hapd.wait_event(["MGMT-RX"], timeout=5)
  1271. if ev is None:
  1272. raise Exception("No response seen at the AP")
  1273. hapd.dump_monitor()
  1274. hapd.set("ext_mgmt_frame_handling", "0")
  1275. dev[0].request("SET ext_mgmt_frame_handling 0")
  1276. dev[0].request("SET LCI ")