test_rrm.py 68 KB

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