test_rrm.py 64 KB

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