test_rrm.py 53 KB

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