test_rrm.py 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  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_ftm_range_req(dev, apdev):
  238. """hostapd FTM range request command"""
  239. rrm = int(dev[0].get_driver_status_field("capa.rrm_flags"), 16)
  240. if rrm & 0x5 != 0x5 and rrm & 0x10 != 0x10:
  241. raise HwsimSkip("Required RRM capabilities are not supported")
  242. params = { "ssid": "rrm", "rrm_neighbor_report": "1" }
  243. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  244. # station not specified
  245. if "FAIL" not in hapd.request("REQ_RANGE "):
  246. raise Exception("REQ_RANGE with no station succeeded unexpectedly")
  247. # station that is not connected specified
  248. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr()):
  249. raise Exception("REQ_RANGE succeeded unexpectedly (station not connected)")
  250. # No responders specified
  251. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 10 10"):
  252. raise Exception("REQ_RANGE succeeded unexpectedly (no responder)")
  253. # Bad responder address
  254. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 10 10 00:11:22:33:44:"):
  255. raise Exception("REQ_RANGE succeeded unexpectedly (bad responder address)")
  256. # Bad responder address
  257. 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"):
  258. raise Exception("REQ_RANGE succeeded unexpectedly (bad responder address 2)")
  259. # Bad min_ap value
  260. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 10 300 00:11:22:33:44:55"):
  261. raise Exception("REQ_RANGE succeeded unexpectedly (invalid min_ap value)")
  262. # Bad rand value
  263. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " -1 10 00:11:22:33:44:55"):
  264. raise Exception("REQ_RANGE succeeded unexpectedly (invalid rand value)")
  265. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 65536 10 00:11:22:33:44:55"):
  266. raise Exception("REQ_RANGE succeeded unexpectedly (invalid rand value)")
  267. # Missing min_ap value
  268. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 10"):
  269. raise Exception("REQ_RANGE succeeded unexpectedly (missing min_ap value)")
  270. # Too many responders
  271. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 10 10" + 20*" 00:11:22:33:44:55"):
  272. raise Exception("REQ_RANGE succeeded unexpectedly (too many responders)")
  273. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  274. # Responder not in database
  275. # Note: this check would pass since the station does not support FTM range
  276. # request and not because the responder is not in the database.
  277. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 10 10 00:11:22:33:44:55"):
  278. raise Exception("REQ_RANGE succeeded unexpectedly (responder not in database)")
  279. def test_rrm_ftm_capa_indication(dev, apdev):
  280. """FTM capability indication"""
  281. try:
  282. _test_rrm_ftm_capa_indication(dev, apdev)
  283. finally:
  284. dev[0].request("SET ftm_initiator 0")
  285. dev[0].request("SET ftm_responder 0")
  286. def _test_rrm_ftm_capa_indication(dev, apdev):
  287. params = { "ssid": "ftm",
  288. "ftm_responder": "1",
  289. "ftm_initiator": "1", }
  290. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  291. if "OK" not in dev[0].request("SET ftm_initiator 1"):
  292. raise Exception("could not set ftm_initiator")
  293. if "OK" not in dev[0].request("SET ftm_responder 1"):
  294. raise Exception("could not set ftm_responder")
  295. dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412, force_scan=True)
  296. class BeaconReport:
  297. def __init__(self, report):
  298. self.opclass, self.channel, self.start, self.duration, self.frame_info, self.rcpi, self.rsni = struct.unpack("<BBQHBBB", report[0:15])
  299. report = report[15:]
  300. self.bssid = report[0:6]
  301. self.bssid_str = "%02x:%02x:%02x:%02x:%02x:%02x" % (struct.unpack('6B', self.bssid))
  302. report = report[6:]
  303. self.antenna_id, self.parent_tsf = struct.unpack("<BI", report[0:5])
  304. report = report[5:]
  305. self.subelems = report
  306. self.frame_body = None
  307. while len(report) >= 2:
  308. eid,elen = struct.unpack('BB', report[0:2])
  309. report = report[2:]
  310. if len(report) < elen:
  311. raise Exception("Invalid subelement in beacon report")
  312. if eid == 1:
  313. # Reported Frame Body
  314. # Contents depends on the reporting detail request:
  315. # 0 = no Reported Frame Body subelement
  316. # 1 = all fixed fields and any elements identified in Request
  317. # element
  318. # 2 = all fixed fields and all elements
  319. # Fixed fields: Timestamp[8] BeaconInt[2] CapabInfo[2]
  320. self.frame_body = report[0:elen]
  321. report = report[elen:]
  322. def __str__(self):
  323. 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)
  324. if self.frame_body:
  325. txt += " frame_body=" + binascii.hexlify(self.frame_body)
  326. return txt
  327. def run_req_beacon(hapd, addr, request):
  328. token = hapd.request("REQ_BEACON " + addr + " " + request)
  329. if "FAIL" in token:
  330. raise Exception("REQ_BEACON failed")
  331. ev = hapd.wait_event(["BEACON-REQ-TX-STATUS"], timeout=5)
  332. if ev is None:
  333. raise Exception("No TX status event for beacon request received")
  334. fields = ev.split(' ')
  335. if fields[1] != addr:
  336. raise Exception("Unexpected STA address in TX status: " + fields[1])
  337. if fields[2] != token:
  338. raise Exception("Unexpected dialog token in TX status: " + fields[2] + " (expected " + token + ")")
  339. if fields[3] != "ack=1":
  340. raise Exception("Unexected ACK status in TX status: " + fields[3])
  341. return token
  342. def test_rrm_beacon_req_table(dev, apdev):
  343. """Beacon request - beacon table mode"""
  344. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  345. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  346. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another" })
  347. tests = [ "REQ_BEACON ",
  348. "REQ_BEACON q",
  349. "REQ_BEACON 11:22:33:44:55:66 1",
  350. "REQ_BEACON 11:22:33:44:55:66 1q",
  351. "REQ_BEACON 11:22:33:44:55:66 11223344556677889900aabbccddeeff" ]
  352. for t in tests:
  353. if "FAIL" not in hapd.request(t):
  354. raise Exception("Invalid command accepted: " + t)
  355. dev[0].scan_for_bss(apdev[1]['bssid'], freq=2412)
  356. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  357. addr = dev[0].own_addr()
  358. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff")
  359. for i in range(1, 3):
  360. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  361. if ev is None:
  362. raise Exception("Beacon report %d response not received" % i)
  363. fields = ev.split(' ')
  364. if fields[1] != addr:
  365. raise Exception("Unexpected STA address in beacon report response: " + fields[1])
  366. if fields[2] != token:
  367. raise Exception("Unexpected dialog token in beacon report response: " + fields[2] + " (expected " + token + ")")
  368. if fields[3] != "00":
  369. raise Exception("Unexpected measurement report mode")
  370. report = BeaconReport(binascii.unhexlify(fields[4]))
  371. logger.info("Received beacon report: " + str(report))
  372. # Default reporting detail is 2, i.e., all fixed fields and elements.
  373. if not report.frame_body:
  374. raise Exception("Reported Frame Body subelement missing")
  375. if len(report.frame_body) <= 12:
  376. raise Exception("Too short Reported Frame Body subelement")
  377. def test_rrm_beacon_req_table_detail(dev, apdev):
  378. """Beacon request - beacon table mode - reporting detail"""
  379. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  380. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  381. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  382. addr = dev[0].own_addr()
  383. logger.info("Reporting Detail 0")
  384. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020100")
  385. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  386. if ev is None:
  387. raise Exception("Beacon report response not received")
  388. fields = ev.split(' ')
  389. report = BeaconReport(binascii.unhexlify(fields[4]))
  390. logger.info("Received beacon report: " + str(report))
  391. if report.frame_body:
  392. raise Exception("Reported Frame Body subelement included with Reporting Detail 0")
  393. hapd.dump_monitor()
  394. logger.info("Reporting Detail 1")
  395. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101")
  396. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  397. if ev is None:
  398. raise Exception("Beacon report response not received")
  399. fields = ev.split(' ')
  400. report = BeaconReport(binascii.unhexlify(fields[4]))
  401. logger.info("Received beacon report: " + str(report))
  402. if not report.frame_body:
  403. raise Exception("Reported Frame Body subelement missing")
  404. if len(report.frame_body) != 12:
  405. raise Exception("Unexpected Reported Frame Body subelement length with Reporting Detail 1")
  406. hapd.dump_monitor()
  407. logger.info("Reporting Detail 2")
  408. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020102")
  409. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  410. if ev is None:
  411. raise Exception("Beacon report response not received")
  412. fields = ev.split(' ')
  413. report = BeaconReport(binascii.unhexlify(fields[4]))
  414. logger.info("Received beacon report: " + str(report))
  415. if not report.frame_body:
  416. raise Exception("Reported Frame Body subelement missing")
  417. if len(report.frame_body) <= 12:
  418. raise Exception("Unexpected Reported Frame Body subelement length with Reporting Detail 2")
  419. hapd.dump_monitor()
  420. logger.info("Reporting Detail 3 (invalid)")
  421. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020103")
  422. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  423. if ev is not None:
  424. raise Exception("Unexpected beacon report response to invalid reporting detail 3")
  425. hapd.dump_monitor()
  426. logger.info("Reporting Detail (too short)")
  427. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "0200")
  428. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  429. if ev is not None:
  430. raise Exception("Unexpected beacon report response to invalid reporting detail")
  431. hapd.dump_monitor()
  432. def test_rrm_beacon_req_table_request(dev, apdev):
  433. """Beacon request - beacon table mode - request element"""
  434. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  435. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  436. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  437. addr = dev[0].own_addr()
  438. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a03000106")
  439. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  440. if ev is None:
  441. raise Exception("Beacon report response not received")
  442. fields = ev.split(' ')
  443. report = BeaconReport(binascii.unhexlify(fields[4]))
  444. logger.info("Received beacon report: " + str(report))
  445. if not report.frame_body:
  446. raise Exception("Reported Frame Body subelement missing")
  447. if len(report.frame_body) != 12 + 5 + 10:
  448. raise Exception("Unexpected Reported Frame Body subelement length with Reporting Detail 1 and requested elements SSID + SuppRates")
  449. hapd.dump_monitor()
  450. logger.info("Incorrect reporting detail with request subelement")
  451. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020102" + "0a03000106")
  452. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  453. if ev is not None:
  454. raise Exception("Unexpected beacon report response (invalid reporting detail)")
  455. hapd.dump_monitor()
  456. logger.info("Invalid request subelement length")
  457. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a00")
  458. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  459. if ev is not None:
  460. raise Exception("Unexpected beacon report response (invalid request subelement length)")
  461. hapd.dump_monitor()
  462. logger.info("Multiple request subelements")
  463. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a0100" + "0a0101")
  464. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  465. if ev is not None:
  466. raise Exception("Unexpected beacon report response (multiple request subelements)")
  467. hapd.dump_monitor()
  468. def test_rrm_beacon_req_table_request_oom(dev, apdev):
  469. """Beacon request - beacon table mode - request element OOM"""
  470. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  471. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  472. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  473. addr = dev[0].own_addr()
  474. with alloc_fail(dev[0], 1,
  475. "bitfield_alloc;wpas_rm_handle_beacon_req_subelem"):
  476. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a03000106")
  477. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  478. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.1)
  479. if ev is not None:
  480. raise Exception("Unexpected beacon report response received (OOM)")
  481. with alloc_fail(dev[0], 1,
  482. "wpabuf_alloc;wpas_rrm_send_msr_report_mpdu"):
  483. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a03000106")
  484. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  485. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.1)
  486. if ev is not None:
  487. raise Exception("Unexpected beacon report response received (OOM)")
  488. with fail_test(dev[0], 1,
  489. "wpa_driver_nl80211_send_action;wpas_rrm_send_msr_report_mpdu"):
  490. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a03000106")
  491. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  492. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.1)
  493. if ev is not None:
  494. raise Exception("Unexpected beacon report response received (OOM)")
  495. with alloc_fail(dev[0], 1,
  496. "wpabuf_resize;wpas_add_beacon_rep"):
  497. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a03000106")
  498. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  499. if ev is None:
  500. raise Exception("Beacon report response not received (OOM -> empty report)")
  501. fields = ev.split(' ')
  502. if len(fields[4]) > 0:
  503. raise Exception("Unexpected beacon report received")
  504. def test_rrm_beacon_req_table_bssid(dev, apdev):
  505. """Beacon request - beacon table mode - specific BSSID"""
  506. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  507. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  508. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another" })
  509. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  510. addr = dev[0].own_addr()
  511. bssid2 = hapd2.own_addr()
  512. token = run_req_beacon(hapd, addr, "51000000000002" + bssid2.replace(':', ''))
  513. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  514. if ev is None:
  515. raise Exception("Beacon report response not received")
  516. fields = ev.split(' ')
  517. report = BeaconReport(binascii.unhexlify(fields[4]))
  518. logger.info("Received beacon report: " + str(report))
  519. if "bssid=" + bssid2 not in str(report):
  520. raise Exception("Report for unexpect BSS")
  521. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.1)
  522. if ev is not None:
  523. raise Exception("Unexpected beacon report response")
  524. def test_rrm_beacon_req_table_ssid(dev, apdev):
  525. """Beacon request - beacon table mode - specific SSID"""
  526. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  527. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  528. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another" })
  529. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  530. addr = dev[0].own_addr()
  531. bssid2 = hapd2.own_addr()
  532. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "0007" + "another".encode('hex'))
  533. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  534. if ev is None:
  535. raise Exception("Beacon report response not received")
  536. fields = ev.split(' ')
  537. report = BeaconReport(binascii.unhexlify(fields[4]))
  538. logger.info("Received beacon report: " + str(report))
  539. if "bssid=" + bssid2 not in str(report):
  540. raise Exception("Report for unexpect BSS")
  541. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.1)
  542. if ev is not None:
  543. raise Exception("Unexpected beacon report response")
  544. hapd.dump_monitor()
  545. logger.info("Wildcard SSID")
  546. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "0000")
  547. for i in range(2):
  548. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  549. if ev is None:
  550. raise Exception("Beacon report response not received")
  551. fields = ev.split(' ')
  552. report = BeaconReport(binascii.unhexlify(fields[4]))
  553. logger.info("Received beacon report: " + str(report))
  554. hapd.dump_monitor()
  555. logger.info("Too long SSID")
  556. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "0021" + 33*"00")
  557. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  558. if ev is not None:
  559. raise Exception("Unexpected beacon report response (invalid SSID subelement in request)")
  560. hapd.dump_monitor()
  561. def test_rrm_beacon_req_table_info(dev, apdev):
  562. """Beacon request - beacon table mode - Reporting Information subelement"""
  563. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  564. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  565. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  566. addr = dev[0].own_addr()
  567. logger.info("Unsupported reporting information 1")
  568. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "01020100")
  569. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  570. if ev is not None:
  571. raise Exception("Unexpected beacon report response (unsupported reporting information 1)")
  572. hapd.dump_monitor()
  573. logger.info("Invalid reporting information length")
  574. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "010100")
  575. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  576. if ev is not None:
  577. raise Exception("Unexpected beacon report response (invalid reporting information length)")
  578. hapd.dump_monitor()
  579. def test_rrm_beacon_req_table_unknown_subelem(dev, apdev):
  580. """Beacon request - beacon table mode - unknown subelement"""
  581. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  582. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  583. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  584. addr = dev[0].own_addr()
  585. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "330101" + "fe00")
  586. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  587. if ev is None:
  588. raise Exception("Beacon report response not received")
  589. fields = ev.split(' ')
  590. report = BeaconReport(binascii.unhexlify(fields[4]))
  591. logger.info("Received beacon report: " + str(report))
  592. def test_rrm_beacon_req_table_truncated_subelem(dev, apdev):
  593. """Beacon request - beacon table mode - Truncated subelement"""
  594. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  595. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  596. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  597. addr = dev[0].own_addr()
  598. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "0001")
  599. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  600. if ev is not None:
  601. raise Exception("Unexpected beacon report response (truncated subelement)")
  602. hapd.dump_monitor()
  603. def test_rrm_beacon_req_table_rsne(dev, apdev):
  604. """Beacon request - beacon table mode - RSNE truncation"""
  605. params = hostapd.wpa2_params(ssid="rrm-rsn", passphrase="12345678")
  606. params["rrm_beacon_report"] = "1"
  607. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  608. dev[0].connect("rrm-rsn", psk="12345678", scan_freq="2412")
  609. addr = dev[0].own_addr()
  610. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a0130")
  611. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  612. if ev is None:
  613. raise Exception("Beacon report response not received")
  614. fields = ev.split(' ')
  615. report = BeaconReport(binascii.unhexlify(fields[4]))
  616. logger.info("Received beacon report: " + str(report))
  617. if not report.frame_body:
  618. raise Exception("Reported Frame Body subelement missing")
  619. if len(report.frame_body) != 12 + 6:
  620. raise Exception("Unexpected Reported Frame Body subelement length with Reporting Detail 1 and requested element RSNE")
  621. if binascii.unhexlify("30040100000f") not in report.frame_body:
  622. raise Exception("Truncated RSNE not found")
  623. def test_rrm_beacon_req_table_vht(dev, apdev):
  624. """Beacon request - beacon table mode - VHT"""
  625. clear_scan_cache(apdev[0])
  626. try:
  627. hapd = None
  628. params = { "ssid": "rrm-vht",
  629. "country_code": "FI",
  630. "hw_mode": "a",
  631. "channel": "36",
  632. "ht_capab": "[HT40+]",
  633. "ieee80211n": "1",
  634. "ieee80211ac": "1",
  635. "vht_oper_chwidth": "1",
  636. "vht_oper_centr_freq_seg0_idx": "42",
  637. "rrm_beacon_report": "1" }
  638. hapd = hostapd.add_ap(apdev[0], params)
  639. bssid = apdev[0]['bssid']
  640. params = { "ssid": "test-vht40",
  641. "country_code": "FI",
  642. "hw_mode": "a",
  643. "channel": "48",
  644. "ieee80211n": "1",
  645. "ieee80211ac": "1",
  646. "ht_capab": "[HT40-]",
  647. "vht_capab": "",
  648. "vht_oper_chwidth": "0",
  649. "vht_oper_centr_freq_seg0_idx": "0",
  650. }
  651. hapd2 = hostapd.add_ap(apdev[1], params)
  652. dev[0].scan_for_bss(apdev[1]['bssid'], freq=5240)
  653. dev[0].connect("rrm-vht", key_mgmt="NONE", scan_freq="5180")
  654. addr = dev[0].own_addr()
  655. token = run_req_beacon(hapd, addr, "f0000000000002ffffffffffff")
  656. for i in range(2):
  657. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  658. if ev is None:
  659. raise Exception("Beacon report %d response not received" % i)
  660. fields = ev.split(' ')
  661. report = BeaconReport(binascii.unhexlify(fields[4]))
  662. logger.info("Received beacon report: " + str(report))
  663. if report.bssid_str == apdev[0]['bssid']:
  664. if report.opclass != 128 or report.channel != 36:
  665. raise Exception("Incorrect opclass/channel for AP0")
  666. elif report.bssid_str == apdev[1]['bssid']:
  667. if report.opclass != 117 or report.channel != 48:
  668. raise Exception("Incorrect opclass/channel for AP1")
  669. except Exception, e:
  670. if isinstance(e, Exception) and str(e) == "AP startup failed":
  671. if not vht_supported():
  672. raise HwsimSkip("80 MHz channel not supported in regulatory information")
  673. raise
  674. finally:
  675. dev[0].request("DISCONNECT")
  676. if hapd:
  677. hapd.request("DISABLE")
  678. subprocess.call(['iw', 'reg', 'set', '00'])
  679. dev[0].flush_scan_cache()
  680. def test_rrm_beacon_req_active(dev, apdev):
  681. """Beacon request - active scan mode"""
  682. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  683. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  684. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  685. "channel": "11" })
  686. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  687. addr = dev[0].own_addr()
  688. token = run_req_beacon(hapd, addr, "51000000640001ffffffffffff")
  689. for i in range(1, 3):
  690. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  691. if ev is None:
  692. raise Exception("Beacon report %d response not received" % i)
  693. fields = ev.split(' ')
  694. report = BeaconReport(binascii.unhexlify(fields[4]))
  695. logger.info("Received beacon report: " + str(report))
  696. if report.bssid_str == apdev[0]['bssid']:
  697. if report.opclass != 81 or report.channel != 1:
  698. raise Exception("Incorrect opclass/channel for AP0")
  699. elif report.bssid_str == apdev[1]['bssid']:
  700. if report.opclass != 81 or report.channel != 11:
  701. raise Exception("Incorrect opclass/channel for AP1")
  702. def test_rrm_beacon_req_active_ap_channels(dev, apdev):
  703. """Beacon request - active scan mode with AP Channel Report subelement"""
  704. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  705. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  706. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  707. "channel": "11" })
  708. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  709. addr = dev[0].own_addr()
  710. token = run_req_beacon(hapd, addr, "51ff0000640001ffffffffffff" + "dd0111" + "330351010b" + "dd0111")
  711. for i in range(1, 3):
  712. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  713. if ev is None:
  714. raise Exception("Beacon report %d response not received" % i)
  715. fields = ev.split(' ')
  716. report = BeaconReport(binascii.unhexlify(fields[4]))
  717. logger.info("Received beacon report: " + str(report))
  718. if report.bssid_str == apdev[0]['bssid']:
  719. if report.opclass != 81 or report.channel != 1:
  720. raise Exception("Incorrect opclass/channel for AP0")
  721. elif report.bssid_str == apdev[1]['bssid']:
  722. if report.opclass != 81 or report.channel != 11:
  723. raise Exception("Incorrect opclass/channel for AP1")
  724. def test_rrm_beacon_req_passive_ap_channels(dev, apdev):
  725. """Beacon request - passive scan mode with AP Channel Report subelement"""
  726. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  727. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  728. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  729. "channel": "11" })
  730. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  731. addr = dev[0].own_addr()
  732. token = run_req_beacon(hapd, addr, "51ff0000640001ffffffffffff" + "330351010b" + "3300" + "dd00")
  733. for i in range(1, 3):
  734. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  735. if ev is None:
  736. raise Exception("Beacon report %d response not received" % i)
  737. fields = ev.split(' ')
  738. report = BeaconReport(binascii.unhexlify(fields[4]))
  739. logger.info("Received beacon report: " + str(report))
  740. if report.bssid_str == apdev[0]['bssid']:
  741. if report.opclass != 81 or report.channel != 1:
  742. raise Exception("Incorrect opclass/channel for AP0")
  743. elif report.bssid_str == apdev[1]['bssid']:
  744. if report.opclass != 81 or report.channel != 11:
  745. raise Exception("Incorrect opclass/channel for AP1")
  746. def test_rrm_beacon_req_active_single_channel(dev, apdev):
  747. """Beacon request - active scan mode with single channel"""
  748. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  749. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  750. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  751. "channel": "11" })
  752. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  753. addr = dev[0].own_addr()
  754. token = run_req_beacon(hapd, addr, "510b0000640001ffffffffffff")
  755. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  756. if ev is None:
  757. raise Exception("Beacon report response not received")
  758. fields = ev.split(' ')
  759. report = BeaconReport(binascii.unhexlify(fields[4]))
  760. logger.info("Received beacon report: " + str(report))
  761. def test_rrm_beacon_req_active_ap_channels_unknown_opclass(dev, apdev):
  762. """Beacon request - active scan mode with AP Channel Report subelement and unknown opclass"""
  763. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  764. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  765. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  766. "channel": "11" })
  767. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  768. addr = dev[0].own_addr()
  769. token = run_req_beacon(hapd, addr, "51ff0000640001ffffffffffff" + "3303ff010b")
  770. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  771. if ev is not None:
  772. raise Exception("Unexpected Beacon report")
  773. def test_rrm_beacon_req_active_ap_channel_oom(dev, apdev):
  774. """Beacon request - AP Channel Report subelement and OOM"""
  775. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  776. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  777. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  778. "channel": "11" })
  779. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  780. addr = dev[0].own_addr()
  781. with alloc_fail(dev[0], 1, "wpas_add_channels"):
  782. token = run_req_beacon(hapd, addr, "51ff0000640001ffffffffffff" + "330351010b")
  783. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  784. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.1)
  785. if ev is not None:
  786. raise Exception("Unexpected Beacon report during OOM")
  787. def test_rrm_beacon_req_active_scan_fail(dev, apdev):
  788. """Beacon request - Active scan failure"""
  789. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  790. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  791. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  792. addr = dev[0].own_addr()
  793. with alloc_fail(dev[0], 1, "wpa_supplicant_trigger_scan"):
  794. token = run_req_beacon(hapd, addr, "51ff0000640001ffffffffffff" + "330351010b")
  795. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  796. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  797. if ev is None:
  798. raise Exception("No Beacon report")
  799. fields = ev.split(' ')
  800. if fields[3] != "04":
  801. raise Exception("Unexpected Beacon report contents: " + ev)
  802. def test_rrm_beacon_req_active_zero_duration(dev, apdev):
  803. """Beacon request - Action scan and zero duration"""
  804. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  805. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  806. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  807. "channel": "11" })
  808. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  809. addr = dev[0].own_addr()
  810. token = run_req_beacon(hapd, addr, "51000000000001ffffffffffff")
  811. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  812. if ev is not None:
  813. raise Exception("Unexpected Beacon report")
  814. def test_rrm_beacon_req_passive(dev, apdev):
  815. """Beacon request - passive scan mode"""
  816. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  817. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  818. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  819. "channel": "11" })
  820. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  821. addr = dev[0].own_addr()
  822. token = run_req_beacon(hapd, addr, "51000000640000ffffffffffff")
  823. for i in range(1, 3):
  824. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  825. if ev is None:
  826. raise Exception("Beacon report %d response not received" % i)
  827. fields = ev.split(' ')
  828. report = BeaconReport(binascii.unhexlify(fields[4]))
  829. logger.info("Received beacon report: " + str(report))
  830. if report.bssid_str == apdev[0]['bssid']:
  831. if report.opclass != 81 or report.channel != 1:
  832. raise Exception("Incorrect opclass/channel for AP0")
  833. elif report.bssid_str == apdev[1]['bssid']:
  834. if report.opclass != 81 or report.channel != 11:
  835. raise Exception("Incorrect opclass/channel for AP1")
  836. def test_rrm_beacon_req_active_duration_mandatory(dev, apdev):
  837. """Beacon request - Action scan and duration mandatory"""
  838. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  839. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  840. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  841. addr = dev[0].own_addr()
  842. token = run_req_beacon(hapd, addr, "req_mode=10 51000000640001ffffffffffff")
  843. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  844. if ev is None:
  845. raise Exception("No Beacon report response")
  846. fields = ev.split(' ')
  847. rrm = int(dev[0].get_driver_status_field("capa.rrm_flags"), 16)
  848. if rrm & 0x20 == 0x20:
  849. report = BeaconReport(binascii.unhexlify(fields[4]))
  850. logger.info("Received beacon report: " + str(report))
  851. else:
  852. # Driver does not support scan dwell time setting, so wpa_supplicant
  853. # rejects the measurement request due to the mandatory duration using
  854. # Measurement Report Mode field Incapable=1.
  855. if fields[3] != '02':
  856. raise Exception("Unexpected Measurement Report Mode: " + fields[3])
  857. if len(fields[4]) > 0:
  858. raise Exception("Unexpected beacon report received")
  859. def test_rrm_req_proto(dev, apdev):
  860. """Radio measurement request - protocol testing"""
  861. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  862. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  863. bssid = hapd.own_addr()
  864. dev[0].request("SET LCI ")
  865. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  866. addr = dev[0].own_addr()
  867. hdr = "d0003a01" + addr.replace(':', '') + 2*bssid.replace(':', '') + "1000"
  868. hapd.set("ext_mgmt_frame_handling", "1")
  869. dev[0].request("SET ext_mgmt_frame_handling 1")
  870. tests = []
  871. # "RRM: Ignoring too short radio measurement request"
  872. tests += [ "0500", "050001", "05000100" ]
  873. # No measurement request element at all
  874. tests += [ "0500010000" ]
  875. # "RRM: Truncated element"
  876. tests += [ "050001000026" ]
  877. # "RRM: Element length too short"
  878. tests += [ "05000100002600", "0500010000260111", "050001000026021122" ]
  879. # "RRM: Element length too long"
  880. tests += [ "05000100002603", "0500010000260311", "050001000026031122" ]
  881. # "RRM: Enable bit not supported, ignore"
  882. tests += [ "05000100002603010200" ]
  883. # "RRM: Measurement report failed. TX power insertion not supported"
  884. # OR
  885. # "RRM: Link measurement report failed. Request too short"
  886. tests += [ "0502" ]
  887. # Too short LCI request
  888. tests += [ "05000100002603010008" ]
  889. # Too short neighbor report response
  890. tests += [ "0505" ]
  891. # Unexpected neighbor report response
  892. tests += [ "050500", "050501", "050502", "050503", "050504", "050505" ]
  893. # Too short beacon request
  894. tests += [ "05000100002603010005",
  895. "0500010000260f010005112233445566778899aabbcc" ]
  896. # Unknown beacon report mode
  897. tests += [ "05000100002610010005112233445566778899aabbccdd" ]
  898. # Beacon report info subelement; no valid channels
  899. tests += [ "05000100002614010005112233445566008899aabbccdd01020000" ]
  900. # "RRM: Expected Measurement Request element, but EID is 0"
  901. tests += [ "05000100000000" ]
  902. for t in tests:
  903. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + t):
  904. raise Exception("MGMT_RX_PROCESS failed")
  905. ev = hapd.wait_event(["MGMT-RX"], timeout=0.2)
  906. if ev is not None:
  907. raise Exception("Unexpected response seen at the AP: " + ev)
  908. tests = []
  909. # "RRM: Parallel measurements are not supported, reject"
  910. tests += [ "05000100002603010105" ]
  911. # "RRM: Unsupported radio measurement type 254"
  912. tests += [ "050001000026030100fe" ]
  913. # Reject LCI request
  914. tests += [ "0500010000260701000811223344" ]
  915. for t in tests:
  916. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + t):
  917. raise Exception("MGMT_RX_PROCESS failed")
  918. ev = hapd.wait_event(["MGMT-RX"], timeout=5)
  919. if ev is None:
  920. raise Exception("No response seen at the AP")
  921. hapd.dump_monitor()
  922. dev[0].request("SET LCI " + lci)
  923. tests = []
  924. # "Not building LCI report - bad location subject"
  925. tests += [ "0500010000260701000811223344" ]
  926. for t in tests:
  927. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + t):
  928. raise Exception("MGMT_RX_PROCESS failed")
  929. ev = hapd.wait_event(["MGMT-RX"], timeout=0.2)
  930. if ev is not None:
  931. raise Exception("Unexpected response seen at the AP: " + ev)
  932. tests = []
  933. # LCI report or reject
  934. tests += [ "0500010000260701000801223344",
  935. "05000100002607010008010402ff",
  936. "05000100002608010008010402ffff" ]
  937. for t in tests:
  938. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + t):
  939. raise Exception("MGMT_RX_PROCESS failed")
  940. ev = hapd.wait_event(["MGMT-RX"], timeout=5)
  941. if ev is None:
  942. raise Exception("No response seen at the AP")
  943. hapd.dump_monitor()
  944. hapd.set("ext_mgmt_frame_handling", "0")
  945. dev[0].request("SET ext_mgmt_frame_handling 0")
  946. dev[0].request("SET LCI ")