test_rrm.py 57 KB

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