test_gas.py 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452
  1. # GAS tests
  2. # Copyright (c) 2013, Qualcomm Atheros, Inc.
  3. # Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi>
  4. #
  5. # This software may be distributed under the terms of the BSD license.
  6. # See README for more details.
  7. from remotehost import remote_compatible
  8. import time
  9. import binascii
  10. import logging
  11. logger = logging.getLogger()
  12. import os
  13. import re
  14. import struct
  15. import hostapd
  16. from wpasupplicant import WpaSupplicant
  17. from tshark import run_tshark
  18. from utils import alloc_fail, wait_fail_trigger, skip_with_fips
  19. from hwsim import HWSimRadio
  20. def hs20_ap_params():
  21. params = hostapd.wpa2_params(ssid="test-gas")
  22. params['wpa_key_mgmt'] = "WPA-EAP"
  23. params['ieee80211w'] = "1"
  24. params['ieee8021x'] = "1"
  25. params['auth_server_addr'] = "127.0.0.1"
  26. params['auth_server_port'] = "1812"
  27. params['auth_server_shared_secret'] = "radius"
  28. params['interworking'] = "1"
  29. params['access_network_type'] = "14"
  30. params['internet'] = "1"
  31. params['asra'] = "0"
  32. params['esr'] = "0"
  33. params['uesa'] = "0"
  34. params['venue_group'] = "7"
  35. params['venue_type'] = "1"
  36. params['venue_name'] = [ "eng:Example venue", "fin:Esimerkkipaikka" ]
  37. params['roaming_consortium'] = [ "112233", "1020304050", "010203040506",
  38. "fedcba" ]
  39. params['domain_name'] = "example.com,another.example.com"
  40. params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]",
  41. "0,another.example.com" ]
  42. params['anqp_3gpp_cell_net'] = "244,91"
  43. params['network_auth_type'] = "02http://www.example.com/redirect/me/here/"
  44. params['ipaddr_type_availability'] = "14"
  45. params['hs20'] = "1"
  46. params['hs20_oper_friendly_name'] = [ "eng:Example operator", "fin:Esimerkkioperaattori" ]
  47. params['hs20_wan_metrics'] = "01:8000:1000:80:240:3000"
  48. params['hs20_conn_capab'] = [ "1:0:2", "6:22:1", "17:5060:0" ]
  49. params['hs20_operating_class'] = "5173"
  50. return params
  51. def start_ap(ap):
  52. params = hs20_ap_params()
  53. params['hessid'] = ap['bssid']
  54. return hostapd.add_ap(ap, params)
  55. def get_gas_response(dev, bssid, info, allow_fetch_failure=False,
  56. extra_test=False):
  57. exp = r'<.>(GAS-RESPONSE-INFO) addr=([0-9a-f:]*) dialog_token=([0-9]*) status_code=([0-9]*) resp_len=([\-0-9]*)'
  58. res = re.split(exp, info)
  59. if len(res) < 6:
  60. raise Exception("Could not parse GAS-RESPONSE-INFO")
  61. if res[2] != bssid:
  62. raise Exception("Unexpected BSSID in response")
  63. token = res[3]
  64. status = res[4]
  65. if status != "0":
  66. raise Exception("GAS query failed")
  67. resp_len = res[5]
  68. if resp_len == "-1":
  69. raise Exception("GAS query reported invalid response length")
  70. if int(resp_len) > 2000:
  71. raise Exception("Unexpected long GAS response")
  72. if extra_test:
  73. if "FAIL" not in dev.request("GAS_RESPONSE_GET " + bssid + " 123456"):
  74. raise Exception("Invalid dialog token accepted")
  75. if "FAIL-Invalid range" not in dev.request("GAS_RESPONSE_GET " + bssid + " " + token + " 10000,10001"):
  76. raise Exception("Invalid range accepted")
  77. if "FAIL-Invalid range" not in dev.request("GAS_RESPONSE_GET " + bssid + " " + token + " 0,10000"):
  78. raise Exception("Invalid range accepted")
  79. if "FAIL" not in dev.request("GAS_RESPONSE_GET " + bssid + " " + token + " 0"):
  80. raise Exception("Invalid GAS_RESPONSE_GET accepted")
  81. res1_2 = dev.request("GAS_RESPONSE_GET " + bssid + " " + token + " 1,2")
  82. res5_3 = dev.request("GAS_RESPONSE_GET " + bssid + " " + token + " 5,3")
  83. resp = dev.request("GAS_RESPONSE_GET " + bssid + " " + token)
  84. if "FAIL" in resp:
  85. if allow_fetch_failure:
  86. logger.debug("GAS response was not available anymore")
  87. return
  88. raise Exception("Could not fetch GAS response")
  89. if len(resp) != int(resp_len) * 2:
  90. raise Exception("Unexpected GAS response length")
  91. logger.debug("GAS response: " + resp)
  92. if extra_test:
  93. if resp[2:6] != res1_2:
  94. raise Exception("Unexpected response substring res1_2: " + res1_2)
  95. if resp[10:16] != res5_3:
  96. raise Exception("Unexpected response substring res5_3: " + res5_3)
  97. def test_gas_generic(dev, apdev):
  98. """Generic GAS query"""
  99. bssid = apdev[0]['bssid']
  100. params = hs20_ap_params()
  101. params['hessid'] = bssid
  102. hostapd.add_ap(apdev[0], params)
  103. cmds = [ "foo",
  104. "00:11:22:33:44:55",
  105. "00:11:22:33:44:55 ",
  106. "00:11:22:33:44:55 ",
  107. "00:11:22:33:44:55 1",
  108. "00:11:22:33:44:55 1 1234",
  109. "00:11:22:33:44:55 qq",
  110. "00:11:22:33:44:55 qq 1234",
  111. "00:11:22:33:44:55 00 1",
  112. "00:11:22:33:44:55 00 123",
  113. "00:11:22:33:44:55 00 ",
  114. "00:11:22:33:44:55 00 qq" ]
  115. for cmd in cmds:
  116. if "FAIL" not in dev[0].request("GAS_REQUEST " + cmd):
  117. raise Exception("Invalid GAS_REQUEST accepted: " + cmd)
  118. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  119. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000101")
  120. if "FAIL" in req:
  121. raise Exception("GAS query request rejected")
  122. ev = dev[0].wait_event(["GAS-RESPONSE-INFO"], timeout=10)
  123. if ev is None:
  124. raise Exception("GAS query timed out")
  125. get_gas_response(dev[0], bssid, ev, extra_test=True)
  126. if "FAIL" not in dev[0].request("GAS_RESPONSE_GET ff"):
  127. raise Exception("Invalid GAS_RESPONSE_GET accepted")
  128. def test_gas_concurrent_scan(dev, apdev):
  129. """Generic GAS queries with concurrent scan operation"""
  130. bssid = apdev[0]['bssid']
  131. params = hs20_ap_params()
  132. params['hessid'] = bssid
  133. hostapd.add_ap(apdev[0], params)
  134. # get BSS entry available to allow GAS query
  135. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  136. logger.info("Request concurrent operations")
  137. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000101")
  138. if "FAIL" in req:
  139. raise Exception("GAS query request rejected")
  140. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000801")
  141. if "FAIL" in req:
  142. raise Exception("GAS query request rejected")
  143. dev[0].scan(no_wait=True)
  144. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000201")
  145. if "FAIL" in req:
  146. raise Exception("GAS query request rejected")
  147. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000501")
  148. if "FAIL" in req:
  149. raise Exception("GAS query request rejected")
  150. responses = 0
  151. for i in range(0, 5):
  152. ev = dev[0].wait_event(["GAS-RESPONSE-INFO", "CTRL-EVENT-SCAN-RESULTS"],
  153. timeout=10)
  154. if ev is None:
  155. raise Exception("Operation timed out")
  156. if "GAS-RESPONSE-INFO" in ev:
  157. responses = responses + 1
  158. get_gas_response(dev[0], bssid, ev, allow_fetch_failure=True)
  159. if responses != 4:
  160. raise Exception("Unexpected number of GAS responses")
  161. def test_gas_concurrent_connect(dev, apdev):
  162. """Generic GAS queries with concurrent connection operation"""
  163. skip_with_fips(dev[0])
  164. bssid = apdev[0]['bssid']
  165. params = hs20_ap_params()
  166. params['hessid'] = bssid
  167. hostapd.add_ap(apdev[0], params)
  168. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  169. logger.debug("Start concurrent connect and GAS request")
  170. dev[0].connect("test-gas", key_mgmt="WPA-EAP", eap="TTLS",
  171. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  172. password="password", phase2="auth=MSCHAPV2",
  173. ca_cert="auth_serv/ca.pem", wait_connect=False,
  174. scan_freq="2412")
  175. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000101")
  176. if "FAIL" in req:
  177. raise Exception("GAS query request rejected")
  178. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", "GAS-RESPONSE-INFO"],
  179. timeout=20)
  180. if ev is None:
  181. raise Exception("Operation timed out")
  182. if "CTRL-EVENT-CONNECTED" not in ev:
  183. raise Exception("Unexpected operation order")
  184. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", "GAS-RESPONSE-INFO"],
  185. timeout=20)
  186. if ev is None:
  187. raise Exception("Operation timed out")
  188. if "GAS-RESPONSE-INFO" not in ev:
  189. raise Exception("Unexpected operation order")
  190. get_gas_response(dev[0], bssid, ev)
  191. dev[0].request("DISCONNECT")
  192. dev[0].wait_disconnected(timeout=5)
  193. logger.debug("Wait six seconds for expiration of connect-without-scan")
  194. time.sleep(6)
  195. dev[0].dump_monitor()
  196. logger.debug("Start concurrent GAS request and connect")
  197. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000101")
  198. if "FAIL" in req:
  199. raise Exception("GAS query request rejected")
  200. dev[0].request("RECONNECT")
  201. ev = dev[0].wait_event(["GAS-RESPONSE-INFO"], timeout=10)
  202. if ev is None:
  203. raise Exception("Operation timed out")
  204. get_gas_response(dev[0], bssid, ev)
  205. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=20)
  206. if ev is None:
  207. raise Exception("No new scan results reported")
  208. ev = dev[0].wait_connected(timeout=20, error="Operation tiemd out")
  209. if "CTRL-EVENT-CONNECTED" not in ev:
  210. raise Exception("Unexpected operation order")
  211. def gas_fragment_and_comeback(dev, apdev, frag_limit=0, comeback_delay=0):
  212. hapd = start_ap(apdev)
  213. if frag_limit:
  214. hapd.set("gas_frag_limit", str(frag_limit))
  215. if comeback_delay:
  216. hapd.set("gas_comeback_delay", str(comeback_delay))
  217. dev.scan_for_bss(apdev['bssid'], freq="2412", force_scan=True)
  218. dev.request("FETCH_ANQP")
  219. ev = dev.wait_event(["GAS-QUERY-DONE"], timeout=5)
  220. if ev is None:
  221. raise Exception("No GAS-QUERY-DONE event")
  222. if "result=SUCCESS" not in ev:
  223. raise Exception("Unexpected GAS result: " + ev)
  224. for i in range(0, 13):
  225. ev = dev.wait_event(["RX-ANQP", "RX-HS20-ANQP"], timeout=5)
  226. if ev is None:
  227. raise Exception("Operation timed out")
  228. ev = dev.wait_event(["ANQP-QUERY-DONE"], timeout=1)
  229. if ev is None:
  230. raise Exception("No ANQP-QUERY-DONE event")
  231. if "result=SUCCESS" not in ev:
  232. raise Exception("Unexpected ANQP result: " + ev)
  233. def test_gas_fragment(dev, apdev):
  234. """GAS fragmentation"""
  235. gas_fragment_and_comeback(dev[0], apdev[0], frag_limit=50)
  236. def test_gas_fragment_mcc(dev, apdev):
  237. """GAS fragmentation with mac80211_hwsim MCC enabled"""
  238. with HWSimRadio(n_channels=2) as (radio, iface):
  239. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  240. wpas.interface_add(iface)
  241. gas_fragment_and_comeback(wpas, apdev[0], frag_limit=50)
  242. def test_gas_fragment_with_comeback_delay(dev, apdev):
  243. """GAS fragmentation and comeback delay"""
  244. gas_fragment_and_comeback(dev[0], apdev[0], frag_limit=50,
  245. comeback_delay=500)
  246. def test_gas_fragment_with_comeback_delay_mcc(dev, apdev):
  247. """GAS fragmentation and comeback delay with mac80211_hwsim MCC enabled"""
  248. with HWSimRadio(n_channels=2) as (radio, iface):
  249. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  250. wpas.interface_add(iface)
  251. gas_fragment_and_comeback(wpas, apdev[0], frag_limit=50,
  252. comeback_delay=500)
  253. def test_gas_comeback_delay(dev, apdev):
  254. """GAS comeback delay"""
  255. hapd = start_ap(apdev[0])
  256. hapd.set("gas_comeback_delay", "500")
  257. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True)
  258. dev[0].request("FETCH_ANQP")
  259. if "FAIL-BUSY" not in dev[0].request("SCAN"):
  260. raise Exception("SCAN accepted during FETCH_ANQP")
  261. for i in range(0, 6):
  262. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  263. if ev is None:
  264. raise Exception("Operation timed out")
  265. @remote_compatible
  266. def test_gas_stop_fetch_anqp(dev, apdev):
  267. """Stop FETCH_ANQP operation"""
  268. hapd = start_ap(apdev[0])
  269. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True)
  270. hapd.set("ext_mgmt_frame_handling", "1")
  271. dev[0].request("FETCH_ANQP")
  272. dev[0].request("STOP_FETCH_ANQP")
  273. hapd.set("ext_mgmt_frame_handling", "0")
  274. ev = dev[0].wait_event(["RX-ANQP", "GAS-QUERY-DONE"], timeout=10)
  275. if ev is None:
  276. raise Exception("GAS-QUERY-DONE timed out")
  277. if "RX-ANQP" in ev:
  278. raise Exception("Unexpected ANQP response received")
  279. def test_gas_anqp_get(dev, apdev):
  280. """GAS/ANQP query for both IEEE 802.11 and Hotspot 2.0 elements"""
  281. hapd = start_ap(apdev[0])
  282. bssid = apdev[0]['bssid']
  283. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  284. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258,268,hs20:3,hs20:4"):
  285. raise Exception("ANQP_GET command failed")
  286. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  287. if ev is None:
  288. raise Exception("GAS query start timed out")
  289. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  290. if ev is None:
  291. raise Exception("GAS query timed out")
  292. ev = dev[0].wait_event(["RX-ANQP"], timeout=1)
  293. if ev is None or "Venue Name" not in ev:
  294. raise Exception("Did not receive Venue Name")
  295. ev = dev[0].wait_event(["RX-ANQP"], timeout=1)
  296. if ev is None or "Domain Name list" not in ev:
  297. raise Exception("Did not receive Domain Name list")
  298. ev = dev[0].wait_event(["RX-HS20-ANQP"], timeout=1)
  299. if ev is None or "Operator Friendly Name" not in ev:
  300. raise Exception("Did not receive Operator Friendly Name")
  301. ev = dev[0].wait_event(["RX-HS20-ANQP"], timeout=1)
  302. if ev is None or "WAN Metrics" not in ev:
  303. raise Exception("Did not receive WAN Metrics")
  304. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=10)
  305. if ev is None:
  306. raise Exception("ANQP-QUERY-DONE event not seen")
  307. if "result=SUCCESS" not in ev:
  308. raise Exception("Unexpected result: " + ev)
  309. if "OK" not in dev[0].request("HS20_ANQP_GET " + bssid + " 3,4"):
  310. raise Exception("ANQP_GET command failed")
  311. ev = dev[0].wait_event(["RX-HS20-ANQP"], timeout=1)
  312. if ev is None or "Operator Friendly Name" not in ev:
  313. raise Exception("Did not receive Operator Friendly Name")
  314. ev = dev[0].wait_event(["RX-HS20-ANQP"], timeout=1)
  315. if ev is None or "WAN Metrics" not in ev:
  316. raise Exception("Did not receive WAN Metrics")
  317. cmds = [ "",
  318. "foo",
  319. "00:11:22:33:44:55 258,hs20:-1",
  320. "00:11:22:33:44:55 258,hs20:0",
  321. "00:11:22:33:44:55 258,hs20:32",
  322. "00:11:22:33:44:55 hs20:-1",
  323. "00:11:22:33:44:55 hs20:0",
  324. "00:11:22:33:44:55 hs20:32",
  325. "00:11:22:33:44:55",
  326. "00:11:22:33:44:55 ",
  327. "00:11:22:33:44:55 0",
  328. "00:11:22:33:44:55 1" ]
  329. for cmd in cmds:
  330. if "FAIL" not in dev[0].request("ANQP_GET " + cmd):
  331. raise Exception("Invalid ANQP_GET accepted")
  332. cmds = [ "",
  333. "foo",
  334. "00:11:22:33:44:55 -1",
  335. "00:11:22:33:44:55 0",
  336. "00:11:22:33:44:55 32",
  337. "00:11:22:33:44:55",
  338. "00:11:22:33:44:55 ",
  339. "00:11:22:33:44:55 0",
  340. "00:11:22:33:44:55 1" ]
  341. for cmd in cmds:
  342. if "FAIL" not in dev[0].request("HS20_ANQP_GET " + cmd):
  343. raise Exception("Invalid HS20_ANQP_GET accepted")
  344. def test_gas_anqp_get_oom(dev, apdev):
  345. """GAS/ANQP query OOM"""
  346. hapd = start_ap(apdev[0])
  347. bssid = apdev[0]['bssid']
  348. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  349. with alloc_fail(dev[0], 1, "wpabuf_alloc;anqp_send_req"):
  350. if "FAIL" not in dev[0].request("ANQP_GET " + bssid + " 258,268,hs20:3,hs20:4"):
  351. raise Exception("ANQP_GET command accepted during OOM")
  352. with alloc_fail(dev[0], 1, "hs20_build_anqp_req;hs20_anqp_send_req"):
  353. if "FAIL" not in dev[0].request("HS20_ANQP_GET " + bssid + " 1"):
  354. raise Exception("HS20_ANQP_GET command accepted during OOM")
  355. with alloc_fail(dev[0], 1, "gas_query_req;hs20_anqp_send_req"):
  356. if "FAIL" not in dev[0].request("HS20_ANQP_GET " + bssid + " 1"):
  357. raise Exception("HS20_ANQP_GET command accepted during OOM")
  358. with alloc_fail(dev[0], 1, "=hs20_anqp_send_req"):
  359. if "FAIL" not in dev[0].request("REQ_HS20_ICON " + bssid + " w1fi_logo"):
  360. raise Exception("REQ_HS20_ICON command accepted during OOM")
  361. with alloc_fail(dev[0], 2, "=hs20_anqp_send_req"):
  362. if "FAIL" not in dev[0].request("REQ_HS20_ICON " + bssid + " w1fi_logo"):
  363. raise Exception("REQ_HS20_ICON command accepted during OOM")
  364. def test_gas_anqp_icon_binary_proto(dev, apdev):
  365. """GAS/ANQP and icon binary protocol testing"""
  366. hapd = start_ap(apdev[0])
  367. bssid = apdev[0]['bssid']
  368. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  369. hapd.set("ext_mgmt_frame_handling", "1")
  370. tests = [ '010000', '01000000', '00000000', '00030000', '00020000',
  371. '00000100', '0001ff0100ee', '0001ff0200ee' ]
  372. for test in tests:
  373. dev[0].request("HS20_ICON_REQUEST " + bssid + " w1fi_logo")
  374. query = gas_rx(hapd)
  375. gas = parse_gas(query['payload'])
  376. resp = action_response(query)
  377. data = binascii.unhexlify(test)
  378. data = binascii.unhexlify('506f9a110b00') + data
  379. data = struct.pack('<HHH', len(data) + 4, 0xdddd, len(data)) + data
  380. resp['payload'] = anqp_initial_resp(gas['dialog_token'], 0) + data
  381. send_gas_resp(hapd, resp)
  382. expect_gas_result(dev[0], "SUCCESS")
  383. def test_gas_anqp_hs20_proto(dev, apdev):
  384. """GAS/ANQP and Hotspot 2.0 element protocol testing"""
  385. hapd = start_ap(apdev[0])
  386. bssid = apdev[0]['bssid']
  387. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  388. hapd.set("ext_mgmt_frame_handling", "1")
  389. tests = [ '00', '0100', '0201', '0300', '0400', '0500', '0600', '0700',
  390. '0800', '0900', '0a00', '0b0000000000' ]
  391. for test in tests:
  392. dev[0].request("HS20_ANQP_GET " + bssid + " 3,4")
  393. query = gas_rx(hapd)
  394. gas = parse_gas(query['payload'])
  395. resp = action_response(query)
  396. data = binascii.unhexlify(test)
  397. data = binascii.unhexlify('506f9a11') + data
  398. data = struct.pack('<HHH', len(data) + 4, 0xdddd, len(data)) + data
  399. resp['payload'] = anqp_initial_resp(gas['dialog_token'], 0) + data
  400. send_gas_resp(hapd, resp)
  401. expect_gas_result(dev[0], "SUCCESS")
  402. def expect_gas_result(dev, result, status=None):
  403. ev = dev.wait_event(["GAS-QUERY-DONE"], timeout=10)
  404. if ev is None:
  405. raise Exception("GAS query timed out")
  406. if "result=" + result not in ev:
  407. raise Exception("Unexpected GAS query result")
  408. if status and "status_code=" + str(status) + ' ' not in ev:
  409. raise Exception("Unexpected GAS status code")
  410. def anqp_get(dev, bssid, id):
  411. if "OK" not in dev.request("ANQP_GET " + bssid + " " + str(id)):
  412. raise Exception("ANQP_GET command failed")
  413. ev = dev.wait_event(["GAS-QUERY-START"], timeout=5)
  414. if ev is None:
  415. raise Exception("GAS query start timed out")
  416. def test_gas_timeout(dev, apdev):
  417. """GAS timeout"""
  418. hapd = start_ap(apdev[0])
  419. bssid = apdev[0]['bssid']
  420. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  421. hapd.set("ext_mgmt_frame_handling", "1")
  422. anqp_get(dev[0], bssid, 263)
  423. ev = hapd.wait_event(["MGMT-RX"], timeout=5)
  424. if ev is None:
  425. raise Exception("MGMT RX wait timed out")
  426. expect_gas_result(dev[0], "TIMEOUT")
  427. MGMT_SUBTYPE_ACTION = 13
  428. ACTION_CATEG_PUBLIC = 4
  429. GAS_INITIAL_REQUEST = 10
  430. GAS_INITIAL_RESPONSE = 11
  431. GAS_COMEBACK_REQUEST = 12
  432. GAS_COMEBACK_RESPONSE = 13
  433. GAS_ACTIONS = [ GAS_INITIAL_REQUEST, GAS_INITIAL_RESPONSE,
  434. GAS_COMEBACK_REQUEST, GAS_COMEBACK_RESPONSE ]
  435. def anqp_adv_proto():
  436. return struct.pack('BBBB', 108, 2, 127, 0)
  437. def anqp_initial_resp(dialog_token, status_code, comeback_delay=0):
  438. return struct.pack('<BBBHH', ACTION_CATEG_PUBLIC, GAS_INITIAL_RESPONSE,
  439. dialog_token, status_code, comeback_delay) + anqp_adv_proto()
  440. def anqp_comeback_resp(dialog_token, status_code=0, id=0, more=False, comeback_delay=0, bogus_adv_proto=False):
  441. if more:
  442. id |= 0x80
  443. if bogus_adv_proto:
  444. adv = struct.pack('BBBB', 108, 2, 127, 1)
  445. else:
  446. adv = anqp_adv_proto()
  447. return struct.pack('<BBBHBH', ACTION_CATEG_PUBLIC, GAS_COMEBACK_RESPONSE,
  448. dialog_token, status_code, id, comeback_delay) + adv
  449. def gas_rx(hapd):
  450. count = 0
  451. while count < 30:
  452. count = count + 1
  453. query = hapd.mgmt_rx()
  454. if query is None:
  455. raise Exception("Action frame not received")
  456. if query['subtype'] != MGMT_SUBTYPE_ACTION:
  457. continue
  458. payload = query['payload']
  459. if len(payload) < 2:
  460. continue
  461. (category, action) = struct.unpack('BB', payload[0:2])
  462. if category != ACTION_CATEG_PUBLIC or action not in GAS_ACTIONS:
  463. continue
  464. return query
  465. raise Exception("No Action frame received")
  466. def parse_gas(payload):
  467. pos = payload
  468. (category, action, dialog_token) = struct.unpack('BBB', pos[0:3])
  469. if category != ACTION_CATEG_PUBLIC:
  470. return None
  471. if action not in GAS_ACTIONS:
  472. return None
  473. gas = {}
  474. gas['action'] = action
  475. pos = pos[3:]
  476. if len(pos) < 1 and action != GAS_COMEBACK_REQUEST:
  477. return None
  478. gas['dialog_token'] = dialog_token
  479. if action == GAS_INITIAL_RESPONSE:
  480. if len(pos) < 4:
  481. return None
  482. (status_code, comeback_delay) = struct.unpack('<HH', pos[0:4])
  483. gas['status_code'] = status_code
  484. gas['comeback_delay'] = comeback_delay
  485. if action == GAS_COMEBACK_RESPONSE:
  486. if len(pos) < 5:
  487. return None
  488. (status_code, frag, comeback_delay) = struct.unpack('<HBH', pos[0:5])
  489. gas['status_code'] = status_code
  490. gas['frag'] = frag
  491. gas['comeback_delay'] = comeback_delay
  492. return gas
  493. def action_response(req):
  494. resp = {}
  495. resp['fc'] = req['fc']
  496. resp['da'] = req['sa']
  497. resp['sa'] = req['da']
  498. resp['bssid'] = req['bssid']
  499. return resp
  500. def send_gas_resp(hapd, resp):
  501. hapd.mgmt_tx(resp)
  502. ev = hapd.wait_event(["MGMT-TX-STATUS"], timeout=5)
  503. if ev is None:
  504. raise Exception("Missing TX status for GAS response")
  505. if "ok=1" not in ev:
  506. raise Exception("GAS response not acknowledged")
  507. def test_gas_invalid_response_type(dev, apdev):
  508. """GAS invalid response type"""
  509. hapd = start_ap(apdev[0])
  510. bssid = apdev[0]['bssid']
  511. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  512. hapd.set("ext_mgmt_frame_handling", "1")
  513. anqp_get(dev[0], bssid, 263)
  514. query = gas_rx(hapd)
  515. gas = parse_gas(query['payload'])
  516. resp = action_response(query)
  517. # GAS Comeback Response instead of GAS Initial Response
  518. resp['payload'] = anqp_comeback_resp(gas['dialog_token']) + struct.pack('<H', 0)
  519. send_gas_resp(hapd, resp)
  520. # station drops the invalid frame, so this needs to result in GAS timeout
  521. expect_gas_result(dev[0], "TIMEOUT")
  522. def test_gas_failure_status_code(dev, apdev):
  523. """GAS failure status code"""
  524. hapd = start_ap(apdev[0])
  525. bssid = apdev[0]['bssid']
  526. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  527. hapd.set("ext_mgmt_frame_handling", "1")
  528. anqp_get(dev[0], bssid, 263)
  529. query = gas_rx(hapd)
  530. gas = parse_gas(query['payload'])
  531. resp = action_response(query)
  532. resp['payload'] = anqp_initial_resp(gas['dialog_token'], 61) + struct.pack('<H', 0)
  533. send_gas_resp(hapd, resp)
  534. expect_gas_result(dev[0], "FAILURE")
  535. def test_gas_malformed(dev, apdev):
  536. """GAS malformed response frames"""
  537. hapd = start_ap(apdev[0])
  538. bssid = apdev[0]['bssid']
  539. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  540. hapd.set("ext_mgmt_frame_handling", "1")
  541. anqp_get(dev[0], bssid, 263)
  542. query = gas_rx(hapd)
  543. gas = parse_gas(query['payload'])
  544. resp = action_response(query)
  545. resp['payload'] = struct.pack('<BBBH', ACTION_CATEG_PUBLIC,
  546. GAS_COMEBACK_RESPONSE,
  547. gas['dialog_token'], 0)
  548. hapd.mgmt_tx(resp)
  549. resp['payload'] = struct.pack('<BBBHB', ACTION_CATEG_PUBLIC,
  550. GAS_COMEBACK_RESPONSE,
  551. gas['dialog_token'], 0, 0)
  552. hapd.mgmt_tx(resp)
  553. hdr = struct.pack('<BBBHH', ACTION_CATEG_PUBLIC, GAS_INITIAL_RESPONSE,
  554. gas['dialog_token'], 0, 0)
  555. resp['payload'] = hdr + struct.pack('B', 108)
  556. hapd.mgmt_tx(resp)
  557. resp['payload'] = hdr + struct.pack('BB', 108, 0)
  558. hapd.mgmt_tx(resp)
  559. resp['payload'] = hdr + struct.pack('BB', 108, 1)
  560. hapd.mgmt_tx(resp)
  561. resp['payload'] = hdr + struct.pack('BB', 108, 255)
  562. hapd.mgmt_tx(resp)
  563. resp['payload'] = hdr + struct.pack('BBB', 108, 1, 127)
  564. hapd.mgmt_tx(resp)
  565. resp['payload'] = hdr + struct.pack('BBB', 108, 2, 127)
  566. hapd.mgmt_tx(resp)
  567. resp['payload'] = hdr + struct.pack('BBBB', 0, 2, 127, 0)
  568. hapd.mgmt_tx(resp)
  569. resp['payload'] = anqp_initial_resp(gas['dialog_token'], 0) + struct.pack('<H', 1)
  570. hapd.mgmt_tx(resp)
  571. resp['payload'] = anqp_initial_resp(gas['dialog_token'], 0) + struct.pack('<HB', 2, 0)
  572. hapd.mgmt_tx(resp)
  573. resp['payload'] = anqp_initial_resp(gas['dialog_token'], 0) + struct.pack('<H', 65535)
  574. hapd.mgmt_tx(resp)
  575. resp['payload'] = anqp_initial_resp(gas['dialog_token'], 0) + struct.pack('<HBB', 1, 0, 0)
  576. hapd.mgmt_tx(resp)
  577. # Station drops invalid frames, but the last of the responses is valid from
  578. # GAS view point even though it has an extra octet in the end and the ANQP
  579. # part of the response is not valid. This is reported as successfully
  580. # completed GAS exchange.
  581. expect_gas_result(dev[0], "SUCCESS")
  582. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=5)
  583. if ev is None:
  584. raise Exception("ANQP-QUERY-DONE not reported")
  585. if "result=INVALID_FRAME" not in ev:
  586. raise Exception("Unexpected result: " + ev)
  587. def init_gas(hapd, bssid, dev):
  588. anqp_get(dev, bssid, 263)
  589. query = gas_rx(hapd)
  590. gas = parse_gas(query['payload'])
  591. dialog_token = gas['dialog_token']
  592. resp = action_response(query)
  593. resp['payload'] = anqp_initial_resp(dialog_token, 0, comeback_delay=1) + struct.pack('<H', 0)
  594. send_gas_resp(hapd, resp)
  595. query = gas_rx(hapd)
  596. gas = parse_gas(query['payload'])
  597. if gas['action'] != GAS_COMEBACK_REQUEST:
  598. raise Exception("Unexpected request action")
  599. if gas['dialog_token'] != dialog_token:
  600. raise Exception("Unexpected dialog token change")
  601. return query, dialog_token
  602. def allow_gas_initial_req(hapd, dialog_token):
  603. msg = hapd.mgmt_rx(timeout=1)
  604. if msg is not None:
  605. gas = parse_gas(msg['payload'])
  606. if gas['action'] != GAS_INITIAL_REQUEST or dialog_token == gas['dialog_token']:
  607. raise Exception("Unexpected management frame")
  608. def test_gas_malformed_comeback_resp(dev, apdev):
  609. """GAS malformed comeback response frames"""
  610. hapd = start_ap(apdev[0])
  611. bssid = apdev[0]['bssid']
  612. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  613. hapd.set("ext_mgmt_frame_handling", "1")
  614. logger.debug("Non-zero status code in comeback response")
  615. query, dialog_token = init_gas(hapd, bssid, dev[0])
  616. resp = action_response(query)
  617. resp['payload'] = anqp_comeback_resp(dialog_token, status_code=2) + struct.pack('<H', 0)
  618. send_gas_resp(hapd, resp)
  619. expect_gas_result(dev[0], "FAILURE", status=2)
  620. logger.debug("Different advertisement protocol in comeback response")
  621. query, dialog_token = init_gas(hapd, bssid, dev[0])
  622. resp = action_response(query)
  623. resp['payload'] = anqp_comeback_resp(dialog_token, bogus_adv_proto=True) + struct.pack('<H', 0)
  624. send_gas_resp(hapd, resp)
  625. expect_gas_result(dev[0], "PEER_ERROR")
  626. logger.debug("Non-zero frag id and comeback delay in comeback response")
  627. query, dialog_token = init_gas(hapd, bssid, dev[0])
  628. resp = action_response(query)
  629. resp['payload'] = anqp_comeback_resp(dialog_token, id=1, comeback_delay=1) + struct.pack('<H', 0)
  630. send_gas_resp(hapd, resp)
  631. expect_gas_result(dev[0], "PEER_ERROR")
  632. logger.debug("Unexpected frag id in comeback response")
  633. query, dialog_token = init_gas(hapd, bssid, dev[0])
  634. resp = action_response(query)
  635. resp['payload'] = anqp_comeback_resp(dialog_token, id=1) + struct.pack('<H', 0)
  636. send_gas_resp(hapd, resp)
  637. expect_gas_result(dev[0], "PEER_ERROR")
  638. logger.debug("Empty fragment and replay in comeback response")
  639. query, dialog_token = init_gas(hapd, bssid, dev[0])
  640. resp = action_response(query)
  641. resp['payload'] = anqp_comeback_resp(dialog_token, more=True) + struct.pack('<H', 0)
  642. send_gas_resp(hapd, resp)
  643. query = gas_rx(hapd)
  644. gas = parse_gas(query['payload'])
  645. if gas['action'] != GAS_COMEBACK_REQUEST:
  646. raise Exception("Unexpected request action")
  647. if gas['dialog_token'] != dialog_token:
  648. raise Exception("Unexpected dialog token change")
  649. resp = action_response(query)
  650. resp['payload'] = anqp_comeback_resp(dialog_token) + struct.pack('<H', 0)
  651. send_gas_resp(hapd, resp)
  652. resp['payload'] = anqp_comeback_resp(dialog_token, id=1) + struct.pack('<H', 0)
  653. send_gas_resp(hapd, resp)
  654. expect_gas_result(dev[0], "SUCCESS")
  655. logger.debug("Unexpected initial response when waiting for comeback response")
  656. query, dialog_token = init_gas(hapd, bssid, dev[0])
  657. resp = action_response(query)
  658. resp['payload'] = anqp_initial_resp(dialog_token, 0) + struct.pack('<H', 0)
  659. send_gas_resp(hapd, resp)
  660. allow_gas_initial_req(hapd, dialog_token)
  661. expect_gas_result(dev[0], "TIMEOUT")
  662. logger.debug("Too short comeback response")
  663. query, dialog_token = init_gas(hapd, bssid, dev[0])
  664. resp = action_response(query)
  665. resp['payload'] = struct.pack('<BBBH', ACTION_CATEG_PUBLIC,
  666. GAS_COMEBACK_RESPONSE, dialog_token, 0)
  667. send_gas_resp(hapd, resp)
  668. allow_gas_initial_req(hapd, dialog_token)
  669. expect_gas_result(dev[0], "TIMEOUT")
  670. logger.debug("Too short comeback response(2)")
  671. query, dialog_token = init_gas(hapd, bssid, dev[0])
  672. resp = action_response(query)
  673. resp['payload'] = struct.pack('<BBBHBB', ACTION_CATEG_PUBLIC,
  674. GAS_COMEBACK_RESPONSE, dialog_token, 0, 0x80,
  675. 0)
  676. send_gas_resp(hapd, resp)
  677. allow_gas_initial_req(hapd, dialog_token)
  678. expect_gas_result(dev[0], "TIMEOUT")
  679. logger.debug("Maximum comeback response fragment claiming more fragments")
  680. query, dialog_token = init_gas(hapd, bssid, dev[0])
  681. resp = action_response(query)
  682. resp['payload'] = anqp_comeback_resp(dialog_token, more=True) + struct.pack('<H', 0)
  683. send_gas_resp(hapd, resp)
  684. for i in range(1, 129):
  685. query = gas_rx(hapd)
  686. gas = parse_gas(query['payload'])
  687. if gas['action'] != GAS_COMEBACK_REQUEST:
  688. raise Exception("Unexpected request action")
  689. if gas['dialog_token'] != dialog_token:
  690. raise Exception("Unexpected dialog token change")
  691. resp = action_response(query)
  692. resp['payload'] = anqp_comeback_resp(dialog_token, id=i, more=True) + struct.pack('<H', 0)
  693. send_gas_resp(hapd, resp)
  694. expect_gas_result(dev[0], "PEER_ERROR")
  695. def test_gas_comeback_resp_additional_delay(dev, apdev):
  696. """GAS comeback response requesting additional delay"""
  697. hapd = start_ap(apdev[0])
  698. bssid = apdev[0]['bssid']
  699. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  700. hapd.set("ext_mgmt_frame_handling", "1")
  701. query, dialog_token = init_gas(hapd, bssid, dev[0])
  702. for i in range(0, 2):
  703. resp = action_response(query)
  704. resp['payload'] = anqp_comeback_resp(dialog_token, status_code=95, comeback_delay=50) + struct.pack('<H', 0)
  705. send_gas_resp(hapd, resp)
  706. query = gas_rx(hapd)
  707. gas = parse_gas(query['payload'])
  708. if gas['action'] != GAS_COMEBACK_REQUEST:
  709. raise Exception("Unexpected request action")
  710. if gas['dialog_token'] != dialog_token:
  711. raise Exception("Unexpected dialog token change")
  712. resp = action_response(query)
  713. resp['payload'] = anqp_comeback_resp(dialog_token, status_code=0) + struct.pack('<H', 0)
  714. send_gas_resp(hapd, resp)
  715. expect_gas_result(dev[0], "SUCCESS")
  716. def test_gas_unknown_adv_proto(dev, apdev):
  717. """Unknown advertisement protocol id"""
  718. bssid = apdev[0]['bssid']
  719. params = hs20_ap_params()
  720. params['hessid'] = bssid
  721. hostapd.add_ap(apdev[0], params)
  722. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  723. req = dev[0].request("GAS_REQUEST " + bssid + " 42 000102000101")
  724. if "FAIL" in req:
  725. raise Exception("GAS query request rejected")
  726. expect_gas_result(dev[0], "FAILURE", "59")
  727. ev = dev[0].wait_event(["GAS-RESPONSE-INFO"], timeout=10)
  728. if ev is None:
  729. raise Exception("GAS query timed out")
  730. exp = r'<.>(GAS-RESPONSE-INFO) addr=([0-9a-f:]*) dialog_token=([0-9]*) status_code=([0-9]*) resp_len=([\-0-9]*)'
  731. res = re.split(exp, ev)
  732. if len(res) < 6:
  733. raise Exception("Could not parse GAS-RESPONSE-INFO")
  734. if res[2] != bssid:
  735. raise Exception("Unexpected BSSID in response")
  736. status = res[4]
  737. if status != "59":
  738. raise Exception("Unexpected GAS-RESPONSE-INFO status")
  739. def test_gas_request_oom(dev, apdev):
  740. """GAS_REQUEST OOM"""
  741. bssid = apdev[0]['bssid']
  742. params = hs20_ap_params()
  743. params['hessid'] = bssid
  744. hostapd.add_ap(apdev[0], params)
  745. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  746. with alloc_fail(dev[0], 1, "gas_build_req;gas_send_request"):
  747. if "FAIL" not in dev[0].request("GAS_REQUEST " + bssid + " 42"):
  748. raise Exception("GAS query request rejected")
  749. with alloc_fail(dev[0], 1, "gas_query_req;gas_send_request"):
  750. if "FAIL" not in dev[0].request("GAS_REQUEST " + bssid + " 42"):
  751. raise Exception("GAS query request rejected")
  752. with alloc_fail(dev[0], 1, "wpabuf_dup;gas_resp_cb"):
  753. if "OK" not in dev[0].request("GAS_REQUEST " + bssid + " 00 000102000101"):
  754. raise Exception("GAS query request rejected")
  755. ev = dev[0].wait_event(["GAS-RESPONSE-INFO"], timeout=10)
  756. if ev is None:
  757. raise Exception("No GAS response")
  758. if "status_code=0" not in ev:
  759. raise Exception("GAS response indicated a failure")
  760. def test_gas_max_pending(dev, apdev):
  761. """GAS and maximum pending query limit"""
  762. hapd = start_ap(apdev[0])
  763. hapd.set("gas_frag_limit", "50")
  764. bssid = apdev[0]['bssid']
  765. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  766. wpas.interface_add("wlan5")
  767. if "OK" not in wpas.request("P2P_SET listen_channel 1"):
  768. raise Exception("Failed to set listen channel")
  769. if "OK" not in wpas.p2p_listen():
  770. raise Exception("Failed to start listen state")
  771. if "FAIL" in wpas.request("SET ext_mgmt_frame_handling 1"):
  772. raise Exception("Failed to enable external management frame handling")
  773. anqp_query = struct.pack('<HHHHHHHHHH', 256, 16, 257, 258, 260, 261, 262, 263, 264, 268)
  774. gas = struct.pack('<H', len(anqp_query)) + anqp_query
  775. for dialog_token in range(1, 10):
  776. msg = struct.pack('<BBB', ACTION_CATEG_PUBLIC, GAS_INITIAL_REQUEST,
  777. dialog_token) + anqp_adv_proto() + gas
  778. req = "MGMT_TX {} {} freq=2412 wait_time=10 action={}".format(bssid, bssid, binascii.hexlify(msg))
  779. if "OK" not in wpas.request(req):
  780. raise Exception("Could not send management frame")
  781. resp = wpas.mgmt_rx()
  782. if resp is None:
  783. raise Exception("MGMT-RX timeout")
  784. if 'payload' not in resp:
  785. raise Exception("Missing payload")
  786. gresp = parse_gas(resp['payload'])
  787. if gresp['dialog_token'] != dialog_token:
  788. raise Exception("Dialog token mismatch")
  789. status_code = gresp['status_code']
  790. if dialog_token < 9 and status_code != 0:
  791. raise Exception("Unexpected failure status code {} for dialog token {}".format(status_code, dialog_token))
  792. if dialog_token > 8 and status_code == 0:
  793. raise Exception("Unexpected success status code {} for dialog token {}".format(status_code, dialog_token))
  794. def test_gas_no_pending(dev, apdev):
  795. """GAS and no pending query for comeback request"""
  796. hapd = start_ap(apdev[0])
  797. bssid = apdev[0]['bssid']
  798. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  799. wpas.interface_add("wlan5")
  800. if "OK" not in wpas.request("P2P_SET listen_channel 1"):
  801. raise Exception("Failed to set listen channel")
  802. if "OK" not in wpas.p2p_listen():
  803. raise Exception("Failed to start listen state")
  804. if "FAIL" in wpas.request("SET ext_mgmt_frame_handling 1"):
  805. raise Exception("Failed to enable external management frame handling")
  806. msg = struct.pack('<BBB', ACTION_CATEG_PUBLIC, GAS_COMEBACK_REQUEST, 1)
  807. req = "MGMT_TX {} {} freq=2412 wait_time=10 action={}".format(bssid, bssid, binascii.hexlify(msg))
  808. if "OK" not in wpas.request(req):
  809. raise Exception("Could not send management frame")
  810. resp = wpas.mgmt_rx()
  811. if resp is None:
  812. raise Exception("MGMT-RX timeout")
  813. if 'payload' not in resp:
  814. raise Exception("Missing payload")
  815. gresp = parse_gas(resp['payload'])
  816. status_code = gresp['status_code']
  817. if status_code != 60:
  818. raise Exception("Unexpected status code {} (expected 60)".format(status_code))
  819. def test_gas_delete_at_deinit(dev, apdev):
  820. """GAS query deleted at deinit"""
  821. hapd = start_ap(apdev[0])
  822. hapd.set("gas_comeback_delay", "1000")
  823. bssid = apdev[0]['bssid']
  824. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  825. wpas.interface_add("wlan5")
  826. wpas.scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True)
  827. wpas.request("ANQP_GET " + bssid + " 258")
  828. wpas.global_request("INTERFACE_REMOVE " + wpas.ifname)
  829. ev = wpas.wait_event(["GAS-QUERY-DONE"], timeout=2)
  830. del wpas
  831. if ev is None:
  832. raise Exception("GAS-QUERY-DONE not seen")
  833. if "result=DELETED_AT_DEINIT" not in ev:
  834. raise Exception("Unexpected result code: " + ev)
  835. def test_gas_missing_payload(dev, apdev):
  836. """No action code in the query frame"""
  837. bssid = apdev[0]['bssid']
  838. params = hs20_ap_params()
  839. params['hessid'] = bssid
  840. hostapd.add_ap(apdev[0], params)
  841. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  842. cmd = "MGMT_TX {} {} freq=2412 action=040A".format(bssid, bssid)
  843. if "FAIL" in dev[0].request(cmd):
  844. raise Exception("Could not send test Action frame")
  845. ev = dev[0].wait_event(["MGMT-TX-STATUS"], timeout=10)
  846. if ev is None:
  847. raise Exception("Timeout on MGMT-TX-STATUS")
  848. if "result=SUCCESS" not in ev:
  849. raise Exception("AP did not ack Action frame")
  850. cmd = "MGMT_TX {} {} freq=2412 action=04".format(bssid, bssid)
  851. if "FAIL" in dev[0].request(cmd):
  852. raise Exception("Could not send test Action frame")
  853. ev = dev[0].wait_event(["MGMT-TX-STATUS"], timeout=10)
  854. if ev is None:
  855. raise Exception("Timeout on MGMT-TX-STATUS")
  856. if "result=SUCCESS" not in ev:
  857. raise Exception("AP did not ack Action frame")
  858. def test_gas_query_deinit(dev, apdev):
  859. """Pending GAS/ANQP query during deinit"""
  860. hapd = start_ap(apdev[0])
  861. bssid = apdev[0]['bssid']
  862. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  863. wpas.interface_add("wlan5")
  864. wpas.scan_for_bss(bssid, freq="2412", force_scan=True)
  865. id = wpas.request("RADIO_WORK add block-work")
  866. if "OK" not in wpas.request("ANQP_GET " + bssid + " 258"):
  867. raise Exception("ANQP_GET command failed")
  868. ev = wpas.wait_event(["GAS-QUERY-START", "EXT-RADIO-WORK-START"], timeout=5)
  869. if ev is None:
  870. raise Exception("Timeout while waiting radio work to start")
  871. ev = wpas.wait_event(["GAS-QUERY-START", "EXT-RADIO-WORK-START"], timeout=5)
  872. if ev is None:
  873. raise Exception("Timeout while waiting radio work to start (2)")
  874. # Remove the interface while the gas-query radio work is still pending and
  875. # GAS query has not yet been started.
  876. wpas.interface_remove("wlan5")
  877. @remote_compatible
  878. def test_gas_anqp_oom_wpas(dev, apdev):
  879. """GAS/ANQP query and OOM in wpa_supplicant"""
  880. hapd = start_ap(apdev[0])
  881. bssid = apdev[0]['bssid']
  882. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  883. with alloc_fail(dev[0], 1, "wpa_bss_anqp_alloc"):
  884. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  885. raise Exception("ANQP_GET command failed")
  886. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=5)
  887. if ev is None:
  888. raise Exception("ANQP query did not complete")
  889. with alloc_fail(dev[0], 1, "gas_build_req"):
  890. if "FAIL" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  891. raise Exception("Unexpected ANQP_GET command success (OOM)")
  892. def test_gas_anqp_oom_hapd(dev, apdev):
  893. """GAS/ANQP query and OOM in hostapd"""
  894. hapd = start_ap(apdev[0])
  895. bssid = apdev[0]['bssid']
  896. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  897. with alloc_fail(hapd, 1, "gas_build_resp"):
  898. # This query will time out due to the AP not sending a response (OOM).
  899. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  900. raise Exception("ANQP_GET command failed")
  901. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  902. if ev is None:
  903. raise Exception("GAS query start timed out")
  904. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  905. if ev is None:
  906. raise Exception("GAS query timed out")
  907. if "result=TIMEOUT" not in ev:
  908. raise Exception("Unexpected result: " + ev)
  909. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=10)
  910. if ev is None:
  911. raise Exception("ANQP-QUERY-DONE event not seen")
  912. if "result=FAILURE" not in ev:
  913. raise Exception("Unexpected result: " + ev)
  914. with alloc_fail(hapd, 1, "gas_anqp_build_comeback_resp"):
  915. hapd.set("gas_frag_limit", "50")
  916. # The first attempt of this query will time out due to the AP not
  917. # sending a response (OOM), but the retry succeeds.
  918. dev[0].request("FETCH_ANQP")
  919. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  920. if ev is None:
  921. raise Exception("GAS query start timed out")
  922. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  923. if ev is None:
  924. raise Exception("GAS query timed out")
  925. if "result=SUCCESS" not in ev:
  926. raise Exception("Unexpected result: " + ev)
  927. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=10)
  928. if ev is None:
  929. raise Exception("ANQP-QUERY-DONE event not seen")
  930. if "result=SUCCESS" not in ev:
  931. raise Exception("Unexpected result: " + ev)
  932. def test_gas_anqp_extra_elements(dev, apdev):
  933. """GAS/ANQP and extra ANQP elements"""
  934. geo_loc = "001052834d12efd2b08b9b4bf1cc2c00004104050000000000060100"
  935. civic_loc = "0000f9555302f50102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5"
  936. held_uri = "https://held.example.com/location"
  937. held = struct.pack('BBB', 0, 1 + len(held_uri), 1) + held_uri
  938. supl_fqdn = "supl.example.com"
  939. supl = struct.pack('BBB', 0, 1 + len(supl_fqdn), 1) + supl_fqdn
  940. public_id = binascii.hexlify(held + supl)
  941. params = { "ssid": "gas/anqp",
  942. "interworking": "1",
  943. "anqp_elem": [ "265:" + geo_loc,
  944. "266:" + civic_loc,
  945. "262:1122334455",
  946. "267:" + public_id,
  947. "275:01020304",
  948. "60000:01",
  949. "299:0102" ] }
  950. hapd = hostapd.add_ap(apdev[0], params)
  951. bssid = apdev[0]['bssid']
  952. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  953. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 265,266"):
  954. raise Exception("ANQP_GET command failed")
  955. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  956. if ev is None:
  957. raise Exception("GAS query timed out")
  958. bss = dev[0].get_bss(bssid)
  959. if 'anqp[265]' not in bss:
  960. raise Exception("AP Geospatial Location ANQP-element not seen")
  961. if bss['anqp[265]'] != geo_loc:
  962. raise Exception("Unexpected AP Geospatial Location ANQP-element value: " + bss['anqp[265]'])
  963. if 'anqp[266]' not in bss:
  964. raise Exception("AP Civic Location ANQP-element not seen")
  965. if bss['anqp[266]'] != civic_loc:
  966. raise Exception("Unexpected AP Civic Location ANQP-element value: " + bss['anqp[266]'])
  967. dev[1].scan_for_bss(bssid, freq="2412", force_scan=True)
  968. if "OK" not in dev[1].request("ANQP_GET " + bssid + " 257,258,259,260,261,262,263,264,265,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299"):
  969. raise Exception("ANQP_GET command failed")
  970. ev = dev[1].wait_event(["GAS-QUERY-DONE"], timeout=10)
  971. if ev is None:
  972. raise Exception("GAS query timed out")
  973. bss = dev[1].get_bss(bssid)
  974. if 'anqp[265]' not in bss:
  975. raise Exception("AP Geospatial Location ANQP-element not seen")
  976. if bss['anqp[265]'] != geo_loc:
  977. raise Exception("Unexpected AP Geospatial Location ANQP-element value: " + bss['anqp[265]'])
  978. if 'anqp[266]' in bss:
  979. raise Exception("AP Civic Location ANQP-element unexpectedly seen")
  980. if 'anqp[267]' not in bss:
  981. raise Exception("AP Location Public Identifier ANQP-element not seen")
  982. if bss['anqp[267]'] != public_id:
  983. raise Exception("Unexpected AP Location Public Identifier ANQP-element value: " + bss['anqp[267]'])
  984. if 'anqp[275]' not in bss:
  985. raise Exception("ANQP-element Info ID 275 not seen")
  986. if bss['anqp[275]'] != "01020304":
  987. raise Exception("Unexpected AP ANQP-element Info ID 299 value: " + bss['anqp[299]'])
  988. if 'anqp[299]' not in bss:
  989. raise Exception("ANQP-element Info ID 299 not seen")
  990. if bss['anqp[299]'] != "0102":
  991. raise Exception("Unexpected AP ANQP-element Info ID 299 value: " + bss['anqp[299]'])
  992. if 'anqp_ip_addr_type_availability' not in bss:
  993. raise Exception("ANQP-element Info ID 292 not seen")
  994. if bss['anqp_ip_addr_type_availability'] != "1122334455":
  995. raise Exception("Unexpected AP ANQP-element Info ID 262 value: " + bss['anqp_ip_addr_type_availability'])
  996. def test_gas_anqp_address3_not_assoc(dev, apdev, params):
  997. """GAS/ANQP query using IEEE 802.11 compliant Address 3 value when not associated"""
  998. try:
  999. _test_gas_anqp_address3_not_assoc(dev, apdev, params)
  1000. finally:
  1001. dev[0].request("SET gas_address3 0")
  1002. def _test_gas_anqp_address3_not_assoc(dev, apdev, params):
  1003. hapd = start_ap(apdev[0])
  1004. bssid = apdev[0]['bssid']
  1005. if "OK" not in dev[0].request("SET gas_address3 1"):
  1006. raise Exception("Failed to set gas_address3")
  1007. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  1008. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  1009. raise Exception("ANQP_GET command failed")
  1010. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  1011. if ev is None:
  1012. raise Exception("GAS query start timed out")
  1013. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  1014. if ev is None:
  1015. raise Exception("GAS query timed out")
  1016. ev = dev[0].wait_event(["RX-ANQP"], timeout=1)
  1017. if ev is None or "Venue Name" not in ev:
  1018. raise Exception("Did not receive Venue Name")
  1019. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=10)
  1020. if ev is None:
  1021. raise Exception("ANQP-QUERY-DONE event not seen")
  1022. if "result=SUCCESS" not in ev:
  1023. raise Exception("Unexpected result: " + ev)
  1024. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  1025. "wlan_mgt.fixed.category_code == 4 && (wlan_mgt.fixed.publicact == 0x0a || wlan_mgt.fixed.publicact == 0x0b)",
  1026. display=["wlan.bssid"])
  1027. res = out.splitlines()
  1028. if len(res) != 2:
  1029. raise Exception("Unexpected number of GAS frames")
  1030. if res[0] != 'ff:ff:ff:ff:ff:ff':
  1031. raise Exception("GAS request used unexpected Address3 field value: " + res[0])
  1032. if res[1] != 'ff:ff:ff:ff:ff:ff':
  1033. raise Exception("GAS response used unexpected Address3 field value: " + res[1])
  1034. def test_gas_anqp_address3_assoc(dev, apdev, params):
  1035. """GAS/ANQP query using IEEE 802.11 compliant Address 3 value when associated"""
  1036. try:
  1037. _test_gas_anqp_address3_assoc(dev, apdev, params)
  1038. finally:
  1039. dev[0].request("SET gas_address3 0")
  1040. def _test_gas_anqp_address3_assoc(dev, apdev, params):
  1041. hapd = start_ap(apdev[0])
  1042. bssid = apdev[0]['bssid']
  1043. if "OK" not in dev[0].request("SET gas_address3 1"):
  1044. raise Exception("Failed to set gas_address3")
  1045. dev[0].scan_for_bss(bssid, freq="2412")
  1046. dev[0].connect("test-gas", key_mgmt="WPA-EAP", eap="TTLS",
  1047. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1048. password="password", phase2="auth=MSCHAPV2",
  1049. ca_cert="auth_serv/ca.pem", scan_freq="2412")
  1050. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  1051. raise Exception("ANQP_GET command failed")
  1052. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  1053. if ev is None:
  1054. raise Exception("GAS query start timed out")
  1055. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  1056. if ev is None:
  1057. raise Exception("GAS query timed out")
  1058. ev = dev[0].wait_event(["RX-ANQP"], timeout=1)
  1059. if ev is None or "Venue Name" not in ev:
  1060. raise Exception("Did not receive Venue Name")
  1061. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=10)
  1062. if ev is None:
  1063. raise Exception("ANQP-QUERY-DONE event not seen")
  1064. if "result=SUCCESS" not in ev:
  1065. raise Exception("Unexpected result: " + ev)
  1066. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  1067. "wlan_mgt.fixed.category_code == 4 && (wlan_mgt.fixed.publicact == 0x0a || wlan_mgt.fixed.publicact == 0x0b)",
  1068. display=["wlan.bssid"])
  1069. res = out.splitlines()
  1070. if len(res) != 2:
  1071. raise Exception("Unexpected number of GAS frames")
  1072. if res[0] != bssid:
  1073. raise Exception("GAS request used unexpected Address3 field value: " + res[0])
  1074. if res[1] != bssid:
  1075. raise Exception("GAS response used unexpected Address3 field value: " + res[1])
  1076. def test_gas_anqp_address3_ap_forced(dev, apdev, params):
  1077. """GAS/ANQP query using IEEE 802.11 compliant Address 3 value on AP"""
  1078. hapd = start_ap(apdev[0])
  1079. bssid = apdev[0]['bssid']
  1080. hapd.set("gas_address3", "1")
  1081. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  1082. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  1083. raise Exception("ANQP_GET command failed")
  1084. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  1085. if ev is None:
  1086. raise Exception("GAS query start timed out")
  1087. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  1088. if ev is None:
  1089. raise Exception("GAS query timed out")
  1090. ev = dev[0].wait_event(["RX-ANQP"], timeout=1)
  1091. if ev is None or "Venue Name" not in ev:
  1092. raise Exception("Did not receive Venue Name")
  1093. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=10)
  1094. if ev is None:
  1095. raise Exception("ANQP-QUERY-DONE event not seen")
  1096. if "result=SUCCESS" not in ev:
  1097. raise Exception("Unexpected result: " + ev)
  1098. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  1099. "wlan_mgt.fixed.category_code == 4 && (wlan_mgt.fixed.publicact == 0x0a || wlan_mgt.fixed.publicact == 0x0b)",
  1100. display=["wlan.bssid"])
  1101. res = out.splitlines()
  1102. if len(res) != 2:
  1103. raise Exception("Unexpected number of GAS frames")
  1104. if res[0] != bssid:
  1105. raise Exception("GAS request used unexpected Address3 field value: " + res[0])
  1106. if res[1] != 'ff:ff:ff:ff:ff:ff':
  1107. raise Exception("GAS response used unexpected Address3 field value: " + res[1])
  1108. def test_gas_anqp_address3_ap_non_compliant(dev, apdev, params):
  1109. """GAS/ANQP query using IEEE 802.11 non-compliant Address 3 (AP)"""
  1110. try:
  1111. _test_gas_anqp_address3_ap_non_compliant(dev, apdev, params)
  1112. finally:
  1113. dev[0].request("SET gas_address3 0")
  1114. def _test_gas_anqp_address3_ap_non_compliant(dev, apdev, params):
  1115. hapd = start_ap(apdev[0])
  1116. bssid = apdev[0]['bssid']
  1117. hapd.set("gas_address3", "2")
  1118. if "OK" not in dev[0].request("SET gas_address3 1"):
  1119. raise Exception("Failed to set gas_address3")
  1120. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  1121. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  1122. raise Exception("ANQP_GET command failed")
  1123. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  1124. if ev is None:
  1125. raise Exception("GAS query start timed out")
  1126. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  1127. if ev is None:
  1128. raise Exception("GAS query timed out")
  1129. ev = dev[0].wait_event(["RX-ANQP"], timeout=1)
  1130. if ev is None or "Venue Name" not in ev:
  1131. raise Exception("Did not receive Venue Name")
  1132. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=10)
  1133. if ev is None:
  1134. raise Exception("ANQP-QUERY-DONE event not seen")
  1135. if "result=SUCCESS" not in ev:
  1136. raise Exception("Unexpected result: " + ev)
  1137. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  1138. "wlan_mgt.fixed.category_code == 4 && (wlan_mgt.fixed.publicact == 0x0a || wlan_mgt.fixed.publicact == 0x0b)",
  1139. display=["wlan.bssid"])
  1140. res = out.splitlines()
  1141. if len(res) != 2:
  1142. raise Exception("Unexpected number of GAS frames")
  1143. if res[0] != 'ff:ff:ff:ff:ff:ff':
  1144. raise Exception("GAS request used unexpected Address3 field value: " + res[0])
  1145. if res[1] != bssid:
  1146. raise Exception("GAS response used unexpected Address3 field value: " + res[1])
  1147. def test_gas_prot_vs_not_prot(dev, apdev, params):
  1148. """GAS/ANQP query protected vs. not protected"""
  1149. hapd = start_ap(apdev[0])
  1150. bssid = apdev[0]['bssid']
  1151. dev[0].scan_for_bss(bssid, freq="2412")
  1152. dev[0].connect("test-gas", key_mgmt="WPA-EAP", eap="TTLS",
  1153. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1154. password="password", phase2="auth=MSCHAPV2",
  1155. ca_cert="auth_serv/ca.pem", scan_freq="2412",
  1156. ieee80211w="2")
  1157. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  1158. raise Exception("ANQP_GET command failed")
  1159. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=5)
  1160. if ev is None:
  1161. raise Exception("No GAS-QUERY-DONE event")
  1162. if "result=SUCCESS" not in ev:
  1163. raise Exception("Unexpected GAS result: " + ev)
  1164. # GAS: Drop unexpected unprotected GAS frame when PMF is enabled
  1165. dev[0].request("SET ext_mgmt_frame_handling 1")
  1166. res = dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=d0003a010200000000000200000003000200000003001000040b00000005006c027f000000")
  1167. dev[0].request("SET ext_mgmt_frame_handling 0")
  1168. if "OK" not in res:
  1169. raise Exception("MGMT_RX_PROCESS failed")
  1170. dev[0].request("DISCONNECT")
  1171. dev[0].wait_disconnected()
  1172. # GAS: No pending query found for 02:00:00:00:03:00 dialog token 0
  1173. dev[0].request("SET ext_mgmt_frame_handling 1")
  1174. res = dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=d0003a010200000000000200000003000200000003001000040b00000005006c027f000000")
  1175. dev[0].request("SET ext_mgmt_frame_handling 0")
  1176. if "OK" not in res:
  1177. raise Exception("MGMT_RX_PROCESS failed")
  1178. # GAS: Drop unexpected protected GAS frame when PMF is disabled
  1179. dev[0].request("SET ext_mgmt_frame_handling 1")
  1180. res = dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=d0003a010200000000000200000003000200000003001000090b00000005006c027f000000")
  1181. dev[0].request("SET ext_mgmt_frame_handling 0")
  1182. if "OK" not in res:
  1183. raise Exception("MGMT_RX_PROCESS failed")
  1184. def test_gas_failures(dev, apdev):
  1185. """GAS failure cases"""
  1186. hapd = start_ap(apdev[0])
  1187. hapd.set("gas_comeback_delay", "5")
  1188. bssid = apdev[0]['bssid']
  1189. hapd2 = start_ap(apdev[1])
  1190. bssid2 = apdev[1]['bssid']
  1191. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  1192. dev[0].scan_for_bss(bssid2, freq="2412")
  1193. tests = [ (bssid, "gas_build_req;gas_query_tx_comeback_req"),
  1194. (bssid, "gas_query_tx;gas_query_tx_comeback_req"),
  1195. (bssid, "gas_query_append;gas_query_rx_comeback"),
  1196. (bssid2, "gas_query_append;gas_query_rx_initial"),
  1197. (bssid2, "wpabuf_alloc_copy;gas_query_rx_initial"),
  1198. (bssid, "gas_query_tx;gas_query_tx_initial_req") ]
  1199. for addr,func in tests:
  1200. with alloc_fail(dev[0], 1, func):
  1201. dev[0].request("ANQP_GET " + addr + " 258")
  1202. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=5)
  1203. if ev is None:
  1204. raise Exception("No GAS-QUERY-DONE seen")
  1205. if "result=INTERNAL_ERROR" not in ev:
  1206. raise Exception("Unexpected result code: " + ev)
  1207. dev[0].dump_monitor()
  1208. tests = [ "=gas_query_req", "radio_add_work;gas_query_req" ]
  1209. for func in tests:
  1210. with alloc_fail(dev[0], 1, func):
  1211. if "FAIL" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  1212. raise Exception("ANQP_GET succeeded unexpectedly during OOM")
  1213. dev[0].dump_monitor()
  1214. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  1215. wpas.interface_add("wlan5")
  1216. wpas.scan_for_bss(bssid2, freq="2412")
  1217. wpas.request("SET preassoc_mac_addr 1111")
  1218. wpas.request("ANQP_GET " + bssid2 + " 258")
  1219. ev = wpas.wait_event(["Failed to assign random MAC address for GAS"],
  1220. timeout=5)
  1221. wpas.request("SET preassoc_mac_addr 0")
  1222. if ev is None:
  1223. raise Exception("No random MAC address error seen")