test_rrm.py 80 KB

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