test_rrm.py 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  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. rrm = int(dev[0].get_driver_status_field("capa.rrm_flags"), 16)
  264. if rrm & 0x5 != 0x5 and rrm & 0x10 != 0x10:
  265. raise HwsimSkip("Required RRM capabilities are not supported")
  266. dev[0].connect("test2", key_mgmt="NONE", scan_freq="2412")
  267. hapd.set("ext_mgmt_frame_handling", "1")
  268. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  269. raise Exception("Request failed")
  270. msg = hapd.mgmt_rx()
  271. if msg is None:
  272. raise Exception("Neighbor report request not seen")
  273. check_nr_results(dev[0])
  274. def test_rrm_neighbor_rep_req_oom(dev, apdev):
  275. """wpa_supplicant ctrl_iface NEIGHBOR_REP_REQUEST OOM"""
  276. params = { "ssid": "test2", "rrm_neighbor_report": "1",
  277. "stationary_ap": "1", "lci": lci, "civic": civic }
  278. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  279. rrm = int(dev[0].get_driver_status_field("capa.rrm_flags"), 16)
  280. if rrm & 0x5 != 0x5 and rrm & 0x10 != 0x10:
  281. raise HwsimSkip("Required RRM capabilities are not supported")
  282. dev[0].connect("test2", key_mgmt="NONE", scan_freq="2412")
  283. with alloc_fail(dev[0], 1, "wpabuf_alloc;wpas_rrm_process_neighbor_rep"):
  284. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  285. raise Exception("Request failed")
  286. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  287. with fail_test(dev[0], 1,
  288. "wpa_driver_nl80211_send_action;wpas_rrm_send_neighbor_rep_request"):
  289. if "FAIL" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  290. raise Exception("Request succeeded unexpectedly")
  291. with alloc_fail(dev[0], 1,
  292. "wpabuf_alloc;wpas_rrm_send_neighbor_rep_request"):
  293. if "FAIL" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  294. raise Exception("Request succeeded unexpectedly")
  295. def test_rrm_neighbor_rep_req_disconnect(dev, apdev):
  296. """wpa_supplicant behavior on disconnection during NEIGHBOR_REP_REQUEST"""
  297. params = { "ssid": "test2", "rrm_neighbor_report": "1",
  298. "stationary_ap": "1", "lci": lci, "civic": civic }
  299. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  300. rrm = int(dev[0].get_driver_status_field("capa.rrm_flags"), 16)
  301. if rrm & 0x5 != 0x5 and rrm & 0x10 != 0x10:
  302. raise HwsimSkip("Required RRM capabilities are not supported")
  303. if "FAIL" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  304. raise Exception("Request accepted while disconnected")
  305. dev[0].connect("test2", key_mgmt="NONE", scan_freq="2412")
  306. hapd.set("ext_mgmt_frame_handling", "1")
  307. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  308. raise Exception("Request failed")
  309. msg = hapd.mgmt_rx()
  310. if msg is None:
  311. raise Exception("Neighbor report request not seen")
  312. dev[0].request("DISCONNECT")
  313. check_nr_results(dev[0])
  314. def test_rrm_neighbor_rep_req_not_supported(dev, apdev):
  315. """NEIGHBOR_REP_REQUEST for AP not supporting neighbor report"""
  316. params = { "ssid": "test2", "rrm_beacon_report": "1" }
  317. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  318. rrm = int(dev[0].get_driver_status_field("capa.rrm_flags"), 16)
  319. if rrm & 0x5 != 0x5 and rrm & 0x10 != 0x10:
  320. raise HwsimSkip("Required RRM capabilities are not supported")
  321. dev[0].connect("test2", key_mgmt="NONE", scan_freq="2412")
  322. if "FAIL" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  323. raise Exception("Request accepted unexpectedly")
  324. def test_rrm_neighbor_rep_req_busy(dev, apdev):
  325. """wpa_supplicant and concurrent NEIGHBOR_REP_REQUEST commands"""
  326. params = { "ssid": "test2", "rrm_neighbor_report": "1",
  327. "stationary_ap": "1", "lci": lci, "civic": civic }
  328. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  329. rrm = int(dev[0].get_driver_status_field("capa.rrm_flags"), 16)
  330. if rrm & 0x5 != 0x5 and rrm & 0x10 != 0x10:
  331. raise HwsimSkip("Required RRM capabilities are not supported")
  332. dev[0].connect("test2", key_mgmt="NONE", scan_freq="2412")
  333. hapd.set("ext_mgmt_frame_handling", "1")
  334. if "OK" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  335. raise Exception("Request failed")
  336. msg = hapd.mgmt_rx()
  337. if msg is None:
  338. raise Exception("Neighbor report request not seen")
  339. if "FAIL" not in dev[0].request("NEIGHBOR_REP_REQUEST"):
  340. raise Exception("Request accepted while disconnected")
  341. def test_rrm_ftm_range_req(dev, apdev):
  342. """hostapd FTM range request command"""
  343. rrm = int(dev[0].get_driver_status_field("capa.rrm_flags"), 16)
  344. if rrm & 0x5 != 0x5 and rrm & 0x10 != 0x10:
  345. raise HwsimSkip("Required RRM capabilities are not supported")
  346. params = { "ssid": "rrm", "rrm_neighbor_report": "1" }
  347. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  348. # station not specified
  349. if "FAIL" not in hapd.request("REQ_RANGE "):
  350. raise Exception("REQ_RANGE with no station succeeded unexpectedly")
  351. # station that is not connected specified
  352. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr()):
  353. raise Exception("REQ_RANGE succeeded unexpectedly (station not connected)")
  354. # No responders specified
  355. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 10 10"):
  356. raise Exception("REQ_RANGE succeeded unexpectedly (no responder)")
  357. # Bad responder address
  358. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 10 10 00:11:22:33:44:"):
  359. raise Exception("REQ_RANGE succeeded unexpectedly (bad responder address)")
  360. # Bad responder address
  361. 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"):
  362. raise Exception("REQ_RANGE succeeded unexpectedly (bad responder address 2)")
  363. # Bad min_ap value
  364. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 10 300 00:11:22:33:44:55"):
  365. raise Exception("REQ_RANGE succeeded unexpectedly (invalid min_ap value)")
  366. # Bad rand value
  367. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " -1 10 00:11:22:33:44:55"):
  368. raise Exception("REQ_RANGE succeeded unexpectedly (invalid rand value)")
  369. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 65536 10 00:11:22:33:44:55"):
  370. raise Exception("REQ_RANGE succeeded unexpectedly (invalid rand value)")
  371. # Missing min_ap value
  372. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 10"):
  373. raise Exception("REQ_RANGE succeeded unexpectedly (missing min_ap value)")
  374. # Too many responders
  375. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 10 10" + 20*" 00:11:22:33:44:55"):
  376. raise Exception("REQ_RANGE succeeded unexpectedly (too many responders)")
  377. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  378. # Responder not in database
  379. # Note: this check would pass since the station does not support FTM range
  380. # request and not because the responder is not in the database.
  381. if "FAIL" not in hapd.request("REQ_RANGE " + dev[0].own_addr() + " 10 10 00:11:22:33:44:55"):
  382. raise Exception("REQ_RANGE succeeded unexpectedly (responder not in database)")
  383. def test_rrm_ftm_capa_indication(dev, apdev):
  384. """FTM capability indication"""
  385. try:
  386. _test_rrm_ftm_capa_indication(dev, apdev)
  387. finally:
  388. dev[0].request("SET ftm_initiator 0")
  389. dev[0].request("SET ftm_responder 0")
  390. def _test_rrm_ftm_capa_indication(dev, apdev):
  391. params = { "ssid": "ftm",
  392. "ftm_responder": "1",
  393. "ftm_initiator": "1", }
  394. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  395. if "OK" not in dev[0].request("SET ftm_initiator 1"):
  396. raise Exception("could not set ftm_initiator")
  397. if "OK" not in dev[0].request("SET ftm_responder 1"):
  398. raise Exception("could not set ftm_responder")
  399. dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412, force_scan=True)
  400. class BeaconReport:
  401. def __init__(self, report):
  402. self.opclass, self.channel, self.start, self.duration, self.frame_info, self.rcpi, self.rsni = struct.unpack("<BBQHBBB", report[0:15])
  403. report = report[15:]
  404. self.bssid = report[0:6]
  405. self.bssid_str = "%02x:%02x:%02x:%02x:%02x:%02x" % (struct.unpack('6B', self.bssid))
  406. report = report[6:]
  407. self.antenna_id, self.parent_tsf = struct.unpack("<BI", report[0:5])
  408. report = report[5:]
  409. self.subelems = report
  410. self.frame_body = None
  411. while len(report) >= 2:
  412. eid,elen = struct.unpack('BB', report[0:2])
  413. report = report[2:]
  414. if len(report) < elen:
  415. raise Exception("Invalid subelement in beacon report")
  416. if eid == 1:
  417. # Reported Frame Body
  418. # Contents depends on the reporting detail request:
  419. # 0 = no Reported Frame Body subelement
  420. # 1 = all fixed fields and any elements identified in Request
  421. # element
  422. # 2 = all fixed fields and all elements
  423. # Fixed fields: Timestamp[8] BeaconInt[2] CapabInfo[2]
  424. self.frame_body = report[0:elen]
  425. report = report[elen:]
  426. def __str__(self):
  427. 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)
  428. if self.frame_body:
  429. txt += " frame_body=" + binascii.hexlify(self.frame_body)
  430. return txt
  431. def run_req_beacon(hapd, addr, request):
  432. token = hapd.request("REQ_BEACON " + addr + " " + request)
  433. if "FAIL" in token:
  434. raise Exception("REQ_BEACON failed")
  435. ev = hapd.wait_event(["BEACON-REQ-TX-STATUS"], timeout=5)
  436. if ev is None:
  437. raise Exception("No TX status event for beacon request received")
  438. fields = ev.split(' ')
  439. if fields[1] != addr:
  440. raise Exception("Unexpected STA address in TX status: " + fields[1])
  441. if fields[2] != token:
  442. raise Exception("Unexpected dialog token in TX status: " + fields[2] + " (expected " + token + ")")
  443. if fields[3] != "ack=1":
  444. raise Exception("Unexected ACK status in TX status: " + fields[3])
  445. return token
  446. def test_rrm_beacon_req_table(dev, apdev):
  447. """Beacon request - beacon table mode"""
  448. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  449. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  450. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another" })
  451. tests = [ "REQ_BEACON ",
  452. "REQ_BEACON q",
  453. "REQ_BEACON 11:22:33:44:55:66 1",
  454. "REQ_BEACON 11:22:33:44:55:66 1q",
  455. "REQ_BEACON 11:22:33:44:55:66 11223344556677889900aabbccddeeff" ]
  456. for t in tests:
  457. if "FAIL" not in hapd.request(t):
  458. raise Exception("Invalid command accepted: " + t)
  459. dev[0].scan_for_bss(apdev[1]['bssid'], freq=2412)
  460. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  461. addr = dev[0].own_addr()
  462. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff")
  463. for i in range(1, 3):
  464. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  465. if ev is None:
  466. raise Exception("Beacon report %d response not received" % i)
  467. fields = ev.split(' ')
  468. if fields[1] != addr:
  469. raise Exception("Unexpected STA address in beacon report response: " + fields[1])
  470. if fields[2] != token:
  471. raise Exception("Unexpected dialog token in beacon report response: " + fields[2] + " (expected " + token + ")")
  472. if fields[3] != "00":
  473. raise Exception("Unexpected measurement report mode")
  474. report = BeaconReport(binascii.unhexlify(fields[4]))
  475. logger.info("Received beacon report: " + str(report))
  476. # Default reporting detail is 2, i.e., all fixed fields and elements.
  477. if not report.frame_body:
  478. raise Exception("Reported Frame Body subelement missing")
  479. if len(report.frame_body) <= 12:
  480. raise Exception("Too short Reported Frame Body subelement")
  481. def test_rrm_beacon_req_table_detail(dev, apdev):
  482. """Beacon request - beacon table mode - reporting detail"""
  483. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  484. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  485. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  486. addr = dev[0].own_addr()
  487. logger.info("Reporting Detail 0")
  488. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020100")
  489. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  490. if ev is None:
  491. raise Exception("Beacon report response not received")
  492. fields = ev.split(' ')
  493. report = BeaconReport(binascii.unhexlify(fields[4]))
  494. logger.info("Received beacon report: " + str(report))
  495. if report.frame_body:
  496. raise Exception("Reported Frame Body subelement included with Reporting Detail 0")
  497. hapd.dump_monitor()
  498. logger.info("Reporting Detail 1")
  499. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101")
  500. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  501. if ev is None:
  502. raise Exception("Beacon report response not received")
  503. fields = ev.split(' ')
  504. report = BeaconReport(binascii.unhexlify(fields[4]))
  505. logger.info("Received beacon report: " + str(report))
  506. if not report.frame_body:
  507. raise Exception("Reported Frame Body subelement missing")
  508. if len(report.frame_body) != 12:
  509. raise Exception("Unexpected Reported Frame Body subelement length with Reporting Detail 1")
  510. hapd.dump_monitor()
  511. logger.info("Reporting Detail 2")
  512. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020102")
  513. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  514. if ev is None:
  515. raise Exception("Beacon report response not received")
  516. fields = ev.split(' ')
  517. report = BeaconReport(binascii.unhexlify(fields[4]))
  518. logger.info("Received beacon report: " + str(report))
  519. if not report.frame_body:
  520. raise Exception("Reported Frame Body subelement missing")
  521. if len(report.frame_body) <= 12:
  522. raise Exception("Unexpected Reported Frame Body subelement length with Reporting Detail 2")
  523. hapd.dump_monitor()
  524. logger.info("Reporting Detail 3 (invalid)")
  525. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020103")
  526. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  527. if ev is not None:
  528. raise Exception("Unexpected beacon report response to invalid reporting detail 3")
  529. hapd.dump_monitor()
  530. logger.info("Reporting Detail (too short)")
  531. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "0200")
  532. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  533. if ev is not None:
  534. raise Exception("Unexpected beacon report response to invalid reporting detail")
  535. hapd.dump_monitor()
  536. def test_rrm_beacon_req_table_request(dev, apdev):
  537. """Beacon request - beacon table mode - request element"""
  538. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  539. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  540. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  541. addr = dev[0].own_addr()
  542. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a03000106")
  543. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  544. if ev is None:
  545. raise Exception("Beacon report response not received")
  546. fields = ev.split(' ')
  547. report = BeaconReport(binascii.unhexlify(fields[4]))
  548. logger.info("Received beacon report: " + str(report))
  549. if not report.frame_body:
  550. raise Exception("Reported Frame Body subelement missing")
  551. if len(report.frame_body) != 12 + 5 + 10:
  552. raise Exception("Unexpected Reported Frame Body subelement length with Reporting Detail 1 and requested elements SSID + SuppRates")
  553. hapd.dump_monitor()
  554. logger.info("Incorrect reporting detail with request subelement")
  555. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020102" + "0a03000106")
  556. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  557. if ev is not None:
  558. raise Exception("Unexpected beacon report response (invalid reporting detail)")
  559. hapd.dump_monitor()
  560. logger.info("Invalid request subelement length")
  561. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a00")
  562. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  563. if ev is not None:
  564. raise Exception("Unexpected beacon report response (invalid request subelement length)")
  565. hapd.dump_monitor()
  566. logger.info("Multiple request subelements")
  567. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a0100" + "0a0101")
  568. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  569. if ev is not None:
  570. raise Exception("Unexpected beacon report response (multiple request subelements)")
  571. hapd.dump_monitor()
  572. def test_rrm_beacon_req_table_request_oom(dev, apdev):
  573. """Beacon request - beacon table mode - request element OOM"""
  574. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  575. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  576. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  577. addr = dev[0].own_addr()
  578. with alloc_fail(dev[0], 1,
  579. "bitfield_alloc;wpas_rm_handle_beacon_req_subelem"):
  580. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a03000106")
  581. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  582. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.1)
  583. if ev is not None:
  584. raise Exception("Unexpected beacon report response received (OOM)")
  585. with alloc_fail(dev[0], 1,
  586. "wpabuf_alloc;wpas_rrm_send_msr_report_mpdu"):
  587. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a03000106")
  588. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  589. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.1)
  590. if ev is not None:
  591. raise Exception("Unexpected beacon report response received (OOM)")
  592. with fail_test(dev[0], 1,
  593. "wpa_driver_nl80211_send_action;wpas_rrm_send_msr_report_mpdu"):
  594. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a03000106")
  595. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  596. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.1)
  597. if ev is not None:
  598. raise Exception("Unexpected beacon report response received (OOM)")
  599. with alloc_fail(dev[0], 1,
  600. "wpabuf_resize;wpas_add_beacon_rep"):
  601. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a03000106")
  602. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  603. if ev is None:
  604. raise Exception("Beacon report response not received (OOM -> empty report)")
  605. fields = ev.split(' ')
  606. if len(fields[4]) > 0:
  607. raise Exception("Unexpected beacon report received")
  608. def test_rrm_beacon_req_table_bssid(dev, apdev):
  609. """Beacon request - beacon table mode - specific BSSID"""
  610. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  611. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  612. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another" })
  613. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  614. addr = dev[0].own_addr()
  615. bssid2 = hapd2.own_addr()
  616. token = run_req_beacon(hapd, addr, "51000000000002" + bssid2.replace(':', ''))
  617. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  618. if ev is None:
  619. raise Exception("Beacon report response not received")
  620. fields = ev.split(' ')
  621. report = BeaconReport(binascii.unhexlify(fields[4]))
  622. logger.info("Received beacon report: " + str(report))
  623. if "bssid=" + bssid2 not in str(report):
  624. raise Exception("Report for unexpect BSS")
  625. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.1)
  626. if ev is not None:
  627. raise Exception("Unexpected beacon report response")
  628. def test_rrm_beacon_req_table_ssid(dev, apdev):
  629. """Beacon request - beacon table mode - specific SSID"""
  630. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  631. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  632. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another" })
  633. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  634. addr = dev[0].own_addr()
  635. bssid2 = hapd2.own_addr()
  636. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "0007" + "another".encode('hex'))
  637. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  638. if ev is None:
  639. raise Exception("Beacon report response not received")
  640. fields = ev.split(' ')
  641. report = BeaconReport(binascii.unhexlify(fields[4]))
  642. logger.info("Received beacon report: " + str(report))
  643. if "bssid=" + bssid2 not in str(report):
  644. raise Exception("Report for unexpect BSS")
  645. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.1)
  646. if ev is not None:
  647. raise Exception("Unexpected beacon report response")
  648. hapd.dump_monitor()
  649. logger.info("Wildcard SSID")
  650. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "0000")
  651. for i in range(2):
  652. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  653. if ev is None:
  654. raise Exception("Beacon report response not received")
  655. fields = ev.split(' ')
  656. report = BeaconReport(binascii.unhexlify(fields[4]))
  657. logger.info("Received beacon report: " + str(report))
  658. hapd.dump_monitor()
  659. logger.info("Too long SSID")
  660. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "0021" + 33*"00")
  661. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  662. if ev is not None:
  663. raise Exception("Unexpected beacon report response (invalid SSID subelement in request)")
  664. hapd.dump_monitor()
  665. def test_rrm_beacon_req_table_info(dev, apdev):
  666. """Beacon request - beacon table mode - Reporting Information subelement"""
  667. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  668. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  669. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  670. addr = dev[0].own_addr()
  671. logger.info("Unsupported reporting information 1")
  672. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "01020100")
  673. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  674. if ev is not None:
  675. raise Exception("Unexpected beacon report response (unsupported reporting information 1)")
  676. hapd.dump_monitor()
  677. logger.info("Invalid reporting information length")
  678. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "010100")
  679. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  680. if ev is not None:
  681. raise Exception("Unexpected beacon report response (invalid reporting information length)")
  682. hapd.dump_monitor()
  683. def test_rrm_beacon_req_table_unknown_subelem(dev, apdev):
  684. """Beacon request - beacon table mode - unknown subelement"""
  685. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  686. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  687. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  688. addr = dev[0].own_addr()
  689. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "330101" + "fe00")
  690. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  691. if ev is None:
  692. raise Exception("Beacon report response not received")
  693. fields = ev.split(' ')
  694. report = BeaconReport(binascii.unhexlify(fields[4]))
  695. logger.info("Received beacon report: " + str(report))
  696. def test_rrm_beacon_req_table_truncated_subelem(dev, apdev):
  697. """Beacon request - beacon table mode - Truncated subelement"""
  698. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  699. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  700. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  701. addr = dev[0].own_addr()
  702. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "0001")
  703. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  704. if ev is not None:
  705. raise Exception("Unexpected beacon report response (truncated subelement)")
  706. hapd.dump_monitor()
  707. def test_rrm_beacon_req_table_rsne(dev, apdev):
  708. """Beacon request - beacon table mode - RSNE truncation"""
  709. params = hostapd.wpa2_params(ssid="rrm-rsn", passphrase="12345678")
  710. params["rrm_beacon_report"] = "1"
  711. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  712. dev[0].connect("rrm-rsn", psk="12345678", scan_freq="2412")
  713. addr = dev[0].own_addr()
  714. token = run_req_beacon(hapd, addr, "51000000000002ffffffffffff" + "020101" + "0a0130")
  715. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  716. if ev is None:
  717. raise Exception("Beacon report response not received")
  718. fields = ev.split(' ')
  719. report = BeaconReport(binascii.unhexlify(fields[4]))
  720. logger.info("Received beacon report: " + str(report))
  721. if not report.frame_body:
  722. raise Exception("Reported Frame Body subelement missing")
  723. if len(report.frame_body) != 12 + 6:
  724. raise Exception("Unexpected Reported Frame Body subelement length with Reporting Detail 1 and requested element RSNE")
  725. if binascii.unhexlify("30040100000f") not in report.frame_body:
  726. raise Exception("Truncated RSNE not found")
  727. def test_rrm_beacon_req_table_vht(dev, apdev):
  728. """Beacon request - beacon table mode - VHT"""
  729. clear_scan_cache(apdev[0])
  730. try:
  731. hapd = None
  732. params = { "ssid": "rrm-vht",
  733. "country_code": "FI",
  734. "hw_mode": "a",
  735. "channel": "36",
  736. "ht_capab": "[HT40+]",
  737. "ieee80211n": "1",
  738. "ieee80211ac": "1",
  739. "vht_oper_chwidth": "1",
  740. "vht_oper_centr_freq_seg0_idx": "42",
  741. "rrm_beacon_report": "1" }
  742. hapd = hostapd.add_ap(apdev[0], params)
  743. params = { "ssid": "test-vht40",
  744. "country_code": "FI",
  745. "hw_mode": "a",
  746. "channel": "48",
  747. "ieee80211n": "1",
  748. "ieee80211ac": "1",
  749. "ht_capab": "[HT40-]",
  750. "vht_capab": "",
  751. "vht_oper_chwidth": "0",
  752. "vht_oper_centr_freq_seg0_idx": "0",
  753. }
  754. hapd2 = hostapd.add_ap(apdev[1], params)
  755. dev[0].scan_for_bss(apdev[1]['bssid'], freq=5240)
  756. dev[0].connect("rrm-vht", key_mgmt="NONE", scan_freq="5180")
  757. addr = dev[0].own_addr()
  758. token = run_req_beacon(hapd, addr, "f0000000000002ffffffffffff")
  759. for i in range(2):
  760. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  761. if ev is None:
  762. raise Exception("Beacon report %d response not received" % i)
  763. fields = ev.split(' ')
  764. report = BeaconReport(binascii.unhexlify(fields[4]))
  765. logger.info("Received beacon report: " + str(report))
  766. if report.bssid_str == apdev[0]['bssid']:
  767. if report.opclass != 128 or report.channel != 36:
  768. raise Exception("Incorrect opclass/channel for AP0")
  769. elif report.bssid_str == apdev[1]['bssid']:
  770. if report.opclass != 117 or report.channel != 48:
  771. raise Exception("Incorrect opclass/channel for AP1")
  772. except Exception, e:
  773. if isinstance(e, Exception) and str(e) == "AP startup failed":
  774. if not vht_supported():
  775. raise HwsimSkip("80 MHz channel not supported in regulatory information")
  776. raise
  777. finally:
  778. dev[0].request("DISCONNECT")
  779. if hapd:
  780. hapd.request("DISABLE")
  781. subprocess.call(['iw', 'reg', 'set', '00'])
  782. dev[0].flush_scan_cache()
  783. def test_rrm_beacon_req_active(dev, apdev):
  784. """Beacon request - active scan mode"""
  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, "51000000640001ffffffffffff")
  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_ignore_old_result(dev, apdev):
  806. """Beacon request - active scan mode and old scan result"""
  807. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another" })
  808. dev[0].scan_for_bss(apdev[1]['bssid'], freq=2412)
  809. hapd2.disable()
  810. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  811. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  812. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  813. addr = dev[0].own_addr()
  814. token = run_req_beacon(hapd, addr, "51010000640001ffffffffffff")
  815. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  816. if ev is None:
  817. raise Exception("Beacon report response not received")
  818. fields = ev.split(' ')
  819. report = BeaconReport(binascii.unhexlify(fields[4]))
  820. logger.info("Received beacon report: " + str(report))
  821. if report.bssid_str == apdev[1]['bssid']:
  822. raise Exception("Old BSS reported")
  823. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  824. if ev is not None:
  825. raise Exception("Unexpected beacon report response")
  826. def start_ap(dev):
  827. id = dev.add_network()
  828. dev.set_network(id, "mode", "2")
  829. dev.set_network_quoted(id, "ssid", 32*'A')
  830. dev.set_network_quoted(id, "psk", "1234567890")
  831. dev.set_network(id, "frequency", "2412")
  832. dev.set_network(id, "scan_freq", "2412")
  833. dev.select_network(id)
  834. dev.wait_connected()
  835. def test_rrm_beacon_req_active_many(dev, apdev):
  836. """Beacon request - active scan mode and many BSSs"""
  837. for i in range(1, 7):
  838. ifname = apdev[0]['ifname'] if i == 1 else apdev[0]['ifname'] + "-%d" % i
  839. hapd1 = hostapd.add_bss(apdev[0], ifname, 'bss-%i.conf' % i)
  840. hapd1.set('vendor_elements', "dd50" + 80*'bb')
  841. hapd1.request("UPDATE_BEACON")
  842. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  843. wpas.interface_add("wlan5")
  844. wpas.request("SET device_name " + 20*'a')
  845. start_ap(wpas)
  846. start_ap(dev[1])
  847. start_ap(dev[2])
  848. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  849. params['vendor_elements'] = "dd50" + 80*'aa'
  850. hapd = hostapd.add_ap(apdev[1]['ifname'], params)
  851. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  852. addr = dev[0].own_addr()
  853. ok = False
  854. for j in range(3):
  855. token = run_req_beacon(hapd, addr, "51010000640001ffffffffffff")
  856. for i in range(10):
  857. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  858. if ev is None:
  859. raise Exception("Beacon report %d response not received" % i)
  860. fields = ev.split(' ')
  861. if len(fields[4]) == 0:
  862. break
  863. report = BeaconReport(binascii.unhexlify(fields[4]))
  864. logger.info("Received beacon report: " + str(report))
  865. if i == 9:
  866. ok = True
  867. if ok:
  868. break
  869. def test_rrm_beacon_req_active_ap_channels(dev, apdev):
  870. """Beacon request - active scan mode with AP Channel Report subelement"""
  871. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  872. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  873. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  874. "channel": "11" })
  875. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  876. addr = dev[0].own_addr()
  877. token = run_req_beacon(hapd, addr, "51ff0000640001ffffffffffff" + "dd0111" + "330351010b" + "dd0111")
  878. for i in range(1, 3):
  879. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  880. if ev is None:
  881. raise Exception("Beacon report %d response not received" % i)
  882. fields = ev.split(' ')
  883. report = BeaconReport(binascii.unhexlify(fields[4]))
  884. logger.info("Received beacon report: " + str(report))
  885. if report.bssid_str == apdev[0]['bssid']:
  886. if report.opclass != 81 or report.channel != 1:
  887. raise Exception("Incorrect opclass/channel for AP0")
  888. elif report.bssid_str == apdev[1]['bssid']:
  889. if report.opclass != 81 or report.channel != 11:
  890. raise Exception("Incorrect opclass/channel for AP1")
  891. def test_rrm_beacon_req_passive_ap_channels(dev, apdev):
  892. """Beacon request - passive scan mode with AP Channel Report subelement"""
  893. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  894. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  895. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  896. "channel": "11" })
  897. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  898. addr = dev[0].own_addr()
  899. token = run_req_beacon(hapd, addr, "51ff0000640001ffffffffffff" + "330351010b" + "3300" + "dd00")
  900. for i in range(1, 3):
  901. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  902. if ev is None:
  903. raise Exception("Beacon report %d response not received" % i)
  904. fields = ev.split(' ')
  905. report = BeaconReport(binascii.unhexlify(fields[4]))
  906. logger.info("Received beacon report: " + str(report))
  907. if report.bssid_str == apdev[0]['bssid']:
  908. if report.opclass != 81 or report.channel != 1:
  909. raise Exception("Incorrect opclass/channel for AP0")
  910. elif report.bssid_str == apdev[1]['bssid']:
  911. if report.opclass != 81 or report.channel != 11:
  912. raise Exception("Incorrect opclass/channel for AP1")
  913. def test_rrm_beacon_req_active_single_channel(dev, apdev):
  914. """Beacon request - active scan mode with single channel"""
  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, "510b0000640001ffffffffffff")
  922. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  923. if ev is None:
  924. raise Exception("Beacon report response not received")
  925. fields = ev.split(' ')
  926. report = BeaconReport(binascii.unhexlify(fields[4]))
  927. logger.info("Received beacon report: " + str(report))
  928. def test_rrm_beacon_req_active_ap_channels_unknown_opclass(dev, apdev):
  929. """Beacon request - active scan mode with AP Channel Report subelement and unknown opclass"""
  930. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  931. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  932. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  933. "channel": "11" })
  934. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  935. addr = dev[0].own_addr()
  936. token = run_req_beacon(hapd, addr, "51ff0000640001ffffffffffff" + "3303ff010b")
  937. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  938. if ev is not None:
  939. raise Exception("Unexpected Beacon report")
  940. def test_rrm_beacon_req_active_ap_channel_oom(dev, apdev):
  941. """Beacon request - AP Channel Report subelement and OOM"""
  942. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  943. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  944. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  945. "channel": "11" })
  946. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  947. addr = dev[0].own_addr()
  948. with alloc_fail(dev[0], 1, "wpas_add_channels"):
  949. token = run_req_beacon(hapd, addr, "51ff0000640001ffffffffffff" + "330351010b")
  950. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  951. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.1)
  952. if ev is not None:
  953. raise Exception("Unexpected Beacon report during OOM")
  954. def test_rrm_beacon_req_active_scan_fail(dev, apdev):
  955. """Beacon request - Active scan failure"""
  956. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  957. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  958. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  959. addr = dev[0].own_addr()
  960. with alloc_fail(dev[0], 1, "wpa_supplicant_trigger_scan"):
  961. token = run_req_beacon(hapd, addr, "51ff0000640001ffffffffffff" + "330351010b")
  962. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  963. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  964. if ev is None:
  965. raise Exception("No Beacon report")
  966. fields = ev.split(' ')
  967. if fields[3] != "04":
  968. raise Exception("Unexpected Beacon report contents: " + ev)
  969. def test_rrm_beacon_req_active_zero_duration(dev, apdev):
  970. """Beacon request - Action scan and zero duration"""
  971. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  972. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  973. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  974. "channel": "11" })
  975. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  976. addr = dev[0].own_addr()
  977. token = run_req_beacon(hapd, addr, "51000000000001ffffffffffff")
  978. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  979. if ev is not None:
  980. raise Exception("Unexpected Beacon report")
  981. def test_rrm_beacon_req_passive(dev, apdev):
  982. """Beacon request - passive scan mode"""
  983. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  984. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  985. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "another",
  986. "channel": "11" })
  987. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  988. addr = dev[0].own_addr()
  989. token = run_req_beacon(hapd, addr, "51000000640000ffffffffffff")
  990. for i in range(1, 3):
  991. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  992. if ev is None:
  993. raise Exception("Beacon report %d response not received" % i)
  994. fields = ev.split(' ')
  995. report = BeaconReport(binascii.unhexlify(fields[4]))
  996. logger.info("Received beacon report: " + str(report))
  997. if report.bssid_str == apdev[0]['bssid']:
  998. if report.opclass != 81 or report.channel != 1:
  999. raise Exception("Incorrect opclass/channel for AP0")
  1000. elif report.bssid_str == apdev[1]['bssid']:
  1001. if report.opclass != 81 or report.channel != 11:
  1002. raise Exception("Incorrect opclass/channel for AP1")
  1003. def test_rrm_beacon_req_passive_no_match(dev, apdev):
  1004. """Beacon request - passive scan mode and no matching BSS"""
  1005. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  1006. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1007. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  1008. addr = dev[0].own_addr()
  1009. token = run_req_beacon(hapd, addr, "51010000640000021122334455")
  1010. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  1011. if ev is None:
  1012. raise Exception("Beacon report %d response not received" % i)
  1013. fields = ev.split(' ')
  1014. if len(fields[4]) > 0:
  1015. raise Exception("Unexpected beacon report BSS")
  1016. def test_rrm_beacon_req_passive_no_match_oom(dev, apdev):
  1017. """Beacon request - passive scan mode and no matching BSS (OOM)"""
  1018. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  1019. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1020. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  1021. addr = dev[0].own_addr()
  1022. with alloc_fail(dev[0], 1, "wpabuf_resize;wpas_beacon_rep_scan_process"):
  1023. token = run_req_beacon(hapd, addr, "51010000640000021122334455")
  1024. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  1025. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=0.2)
  1026. if ev is not None:
  1027. raise Exception("Unexpected Beacon report response during OOM")
  1028. # verify reporting is still functional
  1029. token = run_req_beacon(hapd, addr, "51010000640000021122334455")
  1030. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  1031. if ev is None:
  1032. raise Exception("Beacon report %d response not received" % i)
  1033. fields = ev.split(' ')
  1034. if len(fields[4]) > 0:
  1035. raise Exception("Unexpected beacon report BSS")
  1036. def test_rrm_beacon_req_active_duration_mandatory(dev, apdev):
  1037. """Beacon request - Action scan and duration mandatory"""
  1038. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  1039. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1040. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  1041. addr = dev[0].own_addr()
  1042. token = run_req_beacon(hapd, addr, "req_mode=10 51000000640001ffffffffffff")
  1043. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  1044. if ev is None:
  1045. raise Exception("No Beacon report response")
  1046. fields = ev.split(' ')
  1047. rrm = int(dev[0].get_driver_status_field("capa.rrm_flags"), 16)
  1048. if rrm & 0x20 == 0x20:
  1049. report = BeaconReport(binascii.unhexlify(fields[4]))
  1050. logger.info("Received beacon report: " + str(report))
  1051. else:
  1052. # Driver does not support scan dwell time setting, so wpa_supplicant
  1053. # rejects the measurement request due to the mandatory duration using
  1054. # Measurement Report Mode field Incapable=1.
  1055. if fields[3] != '02':
  1056. raise Exception("Unexpected Measurement Report Mode: " + fields[3])
  1057. if len(fields[4]) > 0:
  1058. raise Exception("Unexpected beacon report received")
  1059. def test_rrm_beacon_req_passive_scan_vht(dev, apdev):
  1060. """Beacon request - passive scan mode - VHT"""
  1061. clear_scan_cache(apdev[0])
  1062. try:
  1063. hapd = None
  1064. params = { "ssid": "rrm-vht",
  1065. "country_code": "FI",
  1066. 'ieee80211d': '1',
  1067. "hw_mode": "a",
  1068. "channel": "36",
  1069. "ht_capab": "[HT40+]",
  1070. "ieee80211n": "1",
  1071. "ieee80211ac": "1",
  1072. "vht_oper_chwidth": "1",
  1073. "vht_oper_centr_freq_seg0_idx": "42",
  1074. "rrm_beacon_report": "1" }
  1075. hapd = hostapd.add_ap(apdev[0], params)
  1076. dev[0].scan_for_bss(apdev[0]['bssid'], freq=5180)
  1077. dev[0].connect("rrm-vht", key_mgmt="NONE", scan_freq="5180")
  1078. addr = dev[0].own_addr()
  1079. token = run_req_beacon(hapd, addr, "80000000640000ffffffffffff")
  1080. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  1081. if ev is None:
  1082. raise Exception("Beacon report response not received")
  1083. fields = ev.split(' ')
  1084. report = BeaconReport(binascii.unhexlify(fields[4]))
  1085. logger.info("Received beacon report: " + str(report))
  1086. if report.opclass != 128 or report.channel != 36:
  1087. raise Exception("Incorrect opclass/channel for AP")
  1088. token = run_req_beacon(hapd, addr, "82000000640000ffffffffffff")
  1089. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  1090. if ev is None:
  1091. raise Exception("Beacon report response not received")
  1092. fields = ev.split(' ')
  1093. report = BeaconReport(binascii.unhexlify(fields[4]))
  1094. logger.info("Received beacon report: " + str(report))
  1095. if report.opclass != 128 or report.channel != 36:
  1096. raise Exception("Incorrect opclass/channel for AP")
  1097. except Exception, e:
  1098. if isinstance(e, Exception) and str(e) == "AP startup failed":
  1099. if not vht_supported():
  1100. raise HwsimSkip("80 MHz channel not supported in regulatory information")
  1101. raise
  1102. finally:
  1103. dev[0].request("DISCONNECT")
  1104. if hapd:
  1105. hapd.request("DISABLE")
  1106. subprocess.call(['iw', 'reg', 'set', '00'])
  1107. dev[0].flush_scan_cache()
  1108. def test_rrm_beacon_req_passive_scan_vht160(dev, apdev):
  1109. """Beacon request - passive scan mode - VHT160"""
  1110. clear_scan_cache(apdev[0])
  1111. try:
  1112. hapd = None
  1113. params = { "ssid": "rrm-vht",
  1114. "country_code": "ZA",
  1115. 'ieee80211d': '1',
  1116. "hw_mode": "a",
  1117. "channel": "104",
  1118. "ht_capab": "[HT40-]",
  1119. "ieee80211n": "1",
  1120. "ieee80211ac": "1",
  1121. "vht_oper_chwidth": "2",
  1122. "vht_oper_centr_freq_seg0_idx": "114",
  1123. "rrm_beacon_report": "1" }
  1124. hapd = hostapd.add_ap(apdev[0], params)
  1125. dev[0].scan_for_bss(apdev[0]['bssid'], freq=5520)
  1126. dev[0].connect("rrm-vht", key_mgmt="NONE", scan_freq="5520")
  1127. sig = dev[0].request("SIGNAL_POLL").splitlines()
  1128. if "WIDTH=160 MHz" not in sig:
  1129. raise Exception("Unexpected SIGNAL_POLL value: " + str(sig))
  1130. addr = dev[0].own_addr()
  1131. token = run_req_beacon(hapd, addr, "81000000640000ffffffffffff")
  1132. ev = hapd.wait_event(["BEACON-RESP-RX"], timeout=10)
  1133. if ev is None:
  1134. raise Exception("Beacon report response not received")
  1135. fields = ev.split(' ')
  1136. report = BeaconReport(binascii.unhexlify(fields[4]))
  1137. logger.info("Received beacon report: " + str(report))
  1138. if report.opclass != 129 or report.channel != 104:
  1139. raise Exception("Incorrect opclass/channel for AP")
  1140. except Exception, e:
  1141. if isinstance(e, Exception) and str(e) == "AP startup failed":
  1142. raise HwsimSkip("ZA regulatory rule likely did not have DFS requirement removed")
  1143. raise
  1144. finally:
  1145. dev[0].request("DISCONNECT")
  1146. if hapd:
  1147. hapd.request("DISABLE")
  1148. subprocess.call(['iw', 'reg', 'set', '00'])
  1149. dev[0].flush_scan_cache()
  1150. def test_rrm_req_proto(dev, apdev):
  1151. """Radio measurement request - protocol testing"""
  1152. params = { "ssid": "rrm", "rrm_beacon_report": "1" }
  1153. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1154. bssid = hapd.own_addr()
  1155. dev[0].request("SET LCI ")
  1156. dev[0].connect("rrm", key_mgmt="NONE", scan_freq="2412")
  1157. addr = dev[0].own_addr()
  1158. hdr = "d0003a01" + addr.replace(':', '') + 2*bssid.replace(':', '') + "1000"
  1159. hapd.set("ext_mgmt_frame_handling", "1")
  1160. dev[0].request("SET ext_mgmt_frame_handling 1")
  1161. tests = []
  1162. # "RRM: Ignoring too short radio measurement request"
  1163. tests += [ "0500", "050001", "05000100" ]
  1164. # No measurement request element at all
  1165. tests += [ "0500010000" ]
  1166. # "RRM: Truncated element"
  1167. tests += [ "050001000026" ]
  1168. # "RRM: Element length too short"
  1169. tests += [ "05000100002600", "0500010000260111", "050001000026021122" ]
  1170. # "RRM: Element length too long"
  1171. tests += [ "05000100002603", "0500010000260311", "050001000026031122" ]
  1172. # "RRM: Enable bit not supported, ignore"
  1173. tests += [ "05000100002603010200" ]
  1174. # "RRM: Measurement report failed. TX power insertion not supported"
  1175. # OR
  1176. # "RRM: Link measurement report failed. Request too short"
  1177. tests += [ "0502" ]
  1178. # Too short LCI request
  1179. tests += [ "05000100002603010008" ]
  1180. # Too short neighbor report response
  1181. tests += [ "0505" ]
  1182. # Unexpected neighbor report response
  1183. tests += [ "050500", "050501", "050502", "050503", "050504", "050505" ]
  1184. # Too short beacon request
  1185. tests += [ "05000100002603010005",
  1186. "0500010000260f010005112233445566778899aabbcc" ]
  1187. # Unknown beacon report mode
  1188. tests += [ "05000100002610010005112233445566778899aabbccdd" ]
  1189. # Beacon report info subelement; no valid channels
  1190. tests += [ "05000100002614010005112233445566008899aabbccdd01020000" ]
  1191. # "RRM: Expected Measurement Request element, but EID is 0"
  1192. tests += [ "05000100000000" ]
  1193. for t in tests:
  1194. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + t):
  1195. raise Exception("MGMT_RX_PROCESS failed")
  1196. ev = hapd.wait_event(["MGMT-RX"], timeout=0.2)
  1197. if ev is not None:
  1198. raise Exception("Unexpected response seen at the AP: " + ev)
  1199. tests = []
  1200. # "RRM: Parallel measurements are not supported, reject"
  1201. tests += [ "05000100002603010105" ]
  1202. # "RRM: Unsupported radio measurement type 254"
  1203. tests += [ "050001000026030100fe" ]
  1204. # Reject LCI request
  1205. tests += [ "0500010000260701000811223344" ]
  1206. for t in tests:
  1207. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + t):
  1208. raise Exception("MGMT_RX_PROCESS failed")
  1209. ev = hapd.wait_event(["MGMT-RX"], timeout=5)
  1210. if ev is None:
  1211. raise Exception("No response seen at the AP")
  1212. hapd.dump_monitor()
  1213. dev[0].request("SET LCI " + lci)
  1214. tests = []
  1215. # "Not building LCI report - bad location subject"
  1216. tests += [ "0500010000260701000811223344" ]
  1217. for t in tests:
  1218. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + t):
  1219. raise Exception("MGMT_RX_PROCESS failed")
  1220. ev = hapd.wait_event(["MGMT-RX"], timeout=0.2)
  1221. if ev is not None:
  1222. raise Exception("Unexpected response seen at the AP: " + ev)
  1223. tests = []
  1224. # LCI report or reject
  1225. tests += [ "0500010000260701000801223344",
  1226. "05000100002607010008010402ff",
  1227. "05000100002608010008010402ffff" ]
  1228. for t in tests:
  1229. if "OK" not in dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + t):
  1230. raise Exception("MGMT_RX_PROCESS failed")
  1231. ev = hapd.wait_event(["MGMT-RX"], timeout=5)
  1232. if ev is None:
  1233. raise Exception("No response seen at the AP")
  1234. hapd.dump_monitor()
  1235. hapd.set("ext_mgmt_frame_handling", "0")
  1236. dev[0].request("SET ext_mgmt_frame_handling 0")
  1237. dev[0].request("SET LCI ")