test_rrm.py 68 KB

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