test_rrm.py 80 KB

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