test_rrm.py 80 KB

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