test_rrm.py 53 KB

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