test_gas.py 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  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. import time
  8. import binascii
  9. import logging
  10. logger = logging.getLogger()
  11. import re
  12. import struct
  13. import hostapd
  14. from wpasupplicant import WpaSupplicant
  15. from utils import alloc_fail, skip_with_fips
  16. def hs20_ap_params():
  17. params = hostapd.wpa2_params(ssid="test-gas")
  18. params['wpa_key_mgmt'] = "WPA-EAP"
  19. params['ieee80211w'] = "1"
  20. params['ieee8021x'] = "1"
  21. params['auth_server_addr'] = "127.0.0.1"
  22. params['auth_server_port'] = "1812"
  23. params['auth_server_shared_secret'] = "radius"
  24. params['interworking'] = "1"
  25. params['access_network_type'] = "14"
  26. params['internet'] = "1"
  27. params['asra'] = "0"
  28. params['esr'] = "0"
  29. params['uesa'] = "0"
  30. params['venue_group'] = "7"
  31. params['venue_type'] = "1"
  32. params['venue_name'] = [ "eng:Example venue", "fin:Esimerkkipaikka" ]
  33. params['roaming_consortium'] = [ "112233", "1020304050", "010203040506",
  34. "fedcba" ]
  35. params['domain_name'] = "example.com,another.example.com"
  36. params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]",
  37. "0,another.example.com" ]
  38. params['anqp_3gpp_cell_net'] = "244,91"
  39. params['network_auth_type'] = "02http://www.example.com/redirect/me/here/"
  40. params['ipaddr_type_availability'] = "14"
  41. params['hs20'] = "1"
  42. params['hs20_oper_friendly_name'] = [ "eng:Example operator", "fin:Esimerkkioperaattori" ]
  43. params['hs20_wan_metrics'] = "01:8000:1000:80:240:3000"
  44. params['hs20_conn_capab'] = [ "1:0:2", "6:22:1", "17:5060:0" ]
  45. params['hs20_operating_class'] = "5173"
  46. return params
  47. def start_ap(ap):
  48. params = hs20_ap_params()
  49. params['hessid'] = ap['bssid']
  50. hostapd.add_ap(ap['ifname'], params)
  51. return hostapd.Hostapd(ap['ifname'])
  52. def get_gas_response(dev, bssid, info, allow_fetch_failure=False,
  53. extra_test=False):
  54. exp = r'<.>(GAS-RESPONSE-INFO) addr=([0-9a-f:]*) dialog_token=([0-9]*) status_code=([0-9]*) resp_len=([\-0-9]*)'
  55. res = re.split(exp, info)
  56. if len(res) < 6:
  57. raise Exception("Could not parse GAS-RESPONSE-INFO")
  58. if res[2] != bssid:
  59. raise Exception("Unexpected BSSID in response")
  60. token = res[3]
  61. status = res[4]
  62. if status != "0":
  63. raise Exception("GAS query failed")
  64. resp_len = res[5]
  65. if resp_len == "-1":
  66. raise Exception("GAS query reported invalid response length")
  67. if int(resp_len) > 2000:
  68. raise Exception("Unexpected long GAS response")
  69. if extra_test:
  70. if "FAIL" not in dev.request("GAS_RESPONSE_GET " + bssid + " 123456"):
  71. raise Exception("Invalid dialog token accepted")
  72. if "FAIL-Invalid range" not in dev.request("GAS_RESPONSE_GET " + bssid + " " + token + " 10000,10001"):
  73. raise Exception("Invalid range accepted")
  74. if "FAIL-Invalid range" not in dev.request("GAS_RESPONSE_GET " + bssid + " " + token + " 0,10000"):
  75. raise Exception("Invalid range accepted")
  76. if "FAIL" not in dev.request("GAS_RESPONSE_GET " + bssid + " " + token + " 0"):
  77. raise Exception("Invalid GAS_RESPONSE_GET accepted")
  78. res1_2 = dev.request("GAS_RESPONSE_GET " + bssid + " " + token + " 1,2")
  79. res5_3 = dev.request("GAS_RESPONSE_GET " + bssid + " " + token + " 5,3")
  80. resp = dev.request("GAS_RESPONSE_GET " + bssid + " " + token)
  81. if "FAIL" in resp:
  82. if allow_fetch_failure:
  83. logger.debug("GAS response was not available anymore")
  84. return
  85. raise Exception("Could not fetch GAS response")
  86. if len(resp) != int(resp_len) * 2:
  87. raise Exception("Unexpected GAS response length")
  88. logger.debug("GAS response: " + resp)
  89. if extra_test:
  90. if resp[2:6] != res1_2:
  91. raise Exception("Unexpected response substring res1_2: " + res1_2)
  92. if resp[10:16] != res5_3:
  93. raise Exception("Unexpected response substring res5_3: " + res5_3)
  94. def test_gas_generic(dev, apdev):
  95. """Generic GAS query"""
  96. bssid = apdev[0]['bssid']
  97. params = hs20_ap_params()
  98. params['hessid'] = bssid
  99. hostapd.add_ap(apdev[0]['ifname'], params)
  100. cmds = [ "foo",
  101. "00:11:22:33:44:55",
  102. "00:11:22:33:44:55 ",
  103. "00:11:22:33:44:55 ",
  104. "00:11:22:33:44:55 1",
  105. "00:11:22:33:44:55 1 1234",
  106. "00:11:22:33:44:55 qq",
  107. "00:11:22:33:44:55 qq 1234",
  108. "00:11:22:33:44:55 00 1",
  109. "00:11:22:33:44:55 00 123",
  110. "00:11:22:33:44:55 00 ",
  111. "00:11:22:33:44:55 00 qq" ]
  112. for cmd in cmds:
  113. if "FAIL" not in dev[0].request("GAS_REQUEST " + cmd):
  114. raise Exception("Invalid GAS_REQUEST accepted: " + cmd)
  115. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  116. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000101")
  117. if "FAIL" in req:
  118. raise Exception("GAS query request rejected")
  119. ev = dev[0].wait_event(["GAS-RESPONSE-INFO"], timeout=10)
  120. if ev is None:
  121. raise Exception("GAS query timed out")
  122. get_gas_response(dev[0], bssid, ev, extra_test=True)
  123. if "FAIL" not in dev[0].request("GAS_RESPONSE_GET ff"):
  124. raise Exception("Invalid GAS_RESPONSE_GET accepted")
  125. def test_gas_concurrent_scan(dev, apdev):
  126. """Generic GAS queries with concurrent scan operation"""
  127. bssid = apdev[0]['bssid']
  128. params = hs20_ap_params()
  129. params['hessid'] = bssid
  130. hostapd.add_ap(apdev[0]['ifname'], params)
  131. # get BSS entry available to allow GAS query
  132. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  133. logger.info("Request concurrent operations")
  134. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000101")
  135. if "FAIL" in req:
  136. raise Exception("GAS query request rejected")
  137. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000801")
  138. if "FAIL" in req:
  139. raise Exception("GAS query request rejected")
  140. dev[0].scan(no_wait=True)
  141. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000201")
  142. if "FAIL" in req:
  143. raise Exception("GAS query request rejected")
  144. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000501")
  145. if "FAIL" in req:
  146. raise Exception("GAS query request rejected")
  147. responses = 0
  148. for i in range(0, 5):
  149. ev = dev[0].wait_event(["GAS-RESPONSE-INFO", "CTRL-EVENT-SCAN-RESULTS"],
  150. timeout=10)
  151. if ev is None:
  152. raise Exception("Operation timed out")
  153. if "GAS-RESPONSE-INFO" in ev:
  154. responses = responses + 1
  155. get_gas_response(dev[0], bssid, ev, allow_fetch_failure=True)
  156. if responses != 4:
  157. raise Exception("Unexpected number of GAS responses")
  158. def test_gas_concurrent_connect(dev, apdev):
  159. """Generic GAS queries with concurrent connection operation"""
  160. skip_with_fips(dev[0])
  161. bssid = apdev[0]['bssid']
  162. params = hs20_ap_params()
  163. params['hessid'] = bssid
  164. hostapd.add_ap(apdev[0]['ifname'], params)
  165. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  166. logger.debug("Start concurrent connect and GAS request")
  167. dev[0].connect("test-gas", key_mgmt="WPA-EAP", eap="TTLS",
  168. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  169. password="password", phase2="auth=MSCHAPV2",
  170. ca_cert="auth_serv/ca.pem", wait_connect=False,
  171. scan_freq="2412")
  172. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000101")
  173. if "FAIL" in req:
  174. raise Exception("GAS query request rejected")
  175. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", "GAS-RESPONSE-INFO"],
  176. timeout=20)
  177. if ev is None:
  178. raise Exception("Operation timed out")
  179. if "CTRL-EVENT-CONNECTED" not in ev:
  180. raise Exception("Unexpected operation order")
  181. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", "GAS-RESPONSE-INFO"],
  182. timeout=20)
  183. if ev is None:
  184. raise Exception("Operation timed out")
  185. if "GAS-RESPONSE-INFO" not in ev:
  186. raise Exception("Unexpected operation order")
  187. get_gas_response(dev[0], bssid, ev)
  188. dev[0].request("DISCONNECT")
  189. dev[0].wait_disconnected(timeout=5)
  190. logger.debug("Wait six seconds for expiration of connect-without-scan")
  191. time.sleep(6)
  192. dev[0].dump_monitor()
  193. logger.debug("Start concurrent GAS request and connect")
  194. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000101")
  195. if "FAIL" in req:
  196. raise Exception("GAS query request rejected")
  197. dev[0].request("RECONNECT")
  198. ev = dev[0].wait_event(["GAS-RESPONSE-INFO"], timeout=10)
  199. if ev is None:
  200. raise Exception("Operation timed out")
  201. get_gas_response(dev[0], bssid, ev)
  202. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=20)
  203. if ev is None:
  204. raise Exception("No new scan results reported")
  205. ev = dev[0].wait_connected(timeout=20, error="Operation tiemd out")
  206. if "CTRL-EVENT-CONNECTED" not in ev:
  207. raise Exception("Unexpected operation order")
  208. def test_gas_fragment(dev, apdev):
  209. """GAS fragmentation"""
  210. hapd = start_ap(apdev[0])
  211. hapd.set("gas_frag_limit", "50")
  212. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True)
  213. dev[0].request("FETCH_ANQP")
  214. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=1)
  215. if ev is None:
  216. raise Exception("No GAS-QUERY-DONE event")
  217. if "result=SUCCESS" not in ev:
  218. raise Exception("Unexpected GAS result: " + ev)
  219. for i in range(0, 13):
  220. ev = dev[0].wait_event(["RX-ANQP", "RX-HS20-ANQP"], timeout=5)
  221. if ev is None:
  222. raise Exception("Operation timed out")
  223. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=1)
  224. if ev is None:
  225. raise Exception("No ANQP-QUERY-DONE event")
  226. if "result=SUCCESS" not in ev:
  227. raise Exception("Unexpected ANQP result: " + ev)
  228. def test_gas_comeback_delay(dev, apdev):
  229. """GAS comeback delay"""
  230. hapd = start_ap(apdev[0])
  231. hapd.set("gas_comeback_delay", "500")
  232. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True)
  233. dev[0].request("FETCH_ANQP")
  234. if "FAIL-BUSY" not in dev[0].request("SCAN"):
  235. raise Exception("SCAN accepted during FETCH_ANQP")
  236. for i in range(0, 6):
  237. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  238. if ev is None:
  239. raise Exception("Operation timed out")
  240. def test_gas_stop_fetch_anqp(dev, apdev):
  241. """Stop FETCH_ANQP operation"""
  242. hapd = start_ap(apdev[0])
  243. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True)
  244. hapd.set("ext_mgmt_frame_handling", "1")
  245. dev[0].request("FETCH_ANQP")
  246. dev[0].request("STOP_FETCH_ANQP")
  247. hapd.set("ext_mgmt_frame_handling", "0")
  248. ev = dev[0].wait_event(["RX-ANQP", "GAS-QUERY-DONE"], timeout=10)
  249. if ev is None:
  250. raise Exception("GAS-QUERY-DONE timed out")
  251. if "RX-ANQP" in ev:
  252. raise Exception("Unexpected ANQP response received")
  253. def test_gas_anqp_get(dev, apdev):
  254. """GAS/ANQP query for both IEEE 802.11 and Hotspot 2.0 elements"""
  255. hapd = start_ap(apdev[0])
  256. bssid = apdev[0]['bssid']
  257. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  258. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258,268,hs20:3,hs20:4"):
  259. raise Exception("ANQP_GET command failed")
  260. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  261. if ev is None:
  262. raise Exception("GAS query start timed out")
  263. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  264. if ev is None:
  265. raise Exception("GAS query timed out")
  266. ev = dev[0].wait_event(["RX-ANQP"], timeout=1)
  267. if ev is None or "Venue Name" not in ev:
  268. raise Exception("Did not receive Venue Name")
  269. ev = dev[0].wait_event(["RX-ANQP"], timeout=1)
  270. if ev is None or "Domain Name list" not in ev:
  271. raise Exception("Did not receive Domain Name list")
  272. ev = dev[0].wait_event(["RX-HS20-ANQP"], timeout=1)
  273. if ev is None or "Operator Friendly Name" not in ev:
  274. raise Exception("Did not receive Operator Friendly Name")
  275. ev = dev[0].wait_event(["RX-HS20-ANQP"], timeout=1)
  276. if ev is None or "WAN Metrics" not in ev:
  277. raise Exception("Did not receive WAN Metrics")
  278. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=10)
  279. if ev is None:
  280. raise Exception("ANQP-QUERY-DONE event not seen")
  281. if "result=SUCCESS" not in ev:
  282. raise Exception("Unexpected result: " + ev)
  283. if "OK" not in dev[0].request("HS20_ANQP_GET " + bssid + " 3,4"):
  284. raise Exception("ANQP_GET command failed")
  285. ev = dev[0].wait_event(["RX-HS20-ANQP"], timeout=1)
  286. if ev is None or "Operator Friendly Name" not in ev:
  287. raise Exception("Did not receive Operator Friendly Name")
  288. ev = dev[0].wait_event(["RX-HS20-ANQP"], timeout=1)
  289. if ev is None or "WAN Metrics" not in ev:
  290. raise Exception("Did not receive WAN Metrics")
  291. cmds = [ "",
  292. "foo",
  293. "00:11:22:33:44:55 258,hs20:-1",
  294. "00:11:22:33:44:55 258,hs20:0",
  295. "00:11:22:33:44:55 258,hs20:32",
  296. "00:11:22:33:44:55 hs20:-1",
  297. "00:11:22:33:44:55 hs20:0",
  298. "00:11:22:33:44:55 hs20:32",
  299. "00:11:22:33:44:55",
  300. "00:11:22:33:44:55 ",
  301. "00:11:22:33:44:55 0" ]
  302. for cmd in cmds:
  303. if "FAIL" not in dev[0].request("ANQP_GET " + cmd):
  304. raise Exception("Invalid ANQP_GET accepted")
  305. cmds = [ "",
  306. "foo",
  307. "00:11:22:33:44:55 -1",
  308. "00:11:22:33:44:55 0",
  309. "00:11:22:33:44:55 32",
  310. "00:11:22:33:44:55",
  311. "00:11:22:33:44:55 ",
  312. "00:11:22:33:44:55 0" ]
  313. for cmd in cmds:
  314. if "FAIL" not in dev[0].request("HS20_ANQP_GET " + cmd):
  315. raise Exception("Invalid HS20_ANQP_GET accepted")
  316. def expect_gas_result(dev, result, status=None):
  317. ev = dev.wait_event(["GAS-QUERY-DONE"], timeout=10)
  318. if ev is None:
  319. raise Exception("GAS query timed out")
  320. if "result=" + result not in ev:
  321. raise Exception("Unexpected GAS query result")
  322. if status and "status_code=" + str(status) + ' ' not in ev:
  323. raise Exception("Unexpected GAS status code")
  324. def anqp_get(dev, bssid, id):
  325. if "OK" not in dev.request("ANQP_GET " + bssid + " " + str(id)):
  326. raise Exception("ANQP_GET command failed")
  327. ev = dev.wait_event(["GAS-QUERY-START"], timeout=5)
  328. if ev is None:
  329. raise Exception("GAS query start timed out")
  330. def test_gas_timeout(dev, apdev):
  331. """GAS timeout"""
  332. hapd = start_ap(apdev[0])
  333. bssid = apdev[0]['bssid']
  334. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  335. hapd.set("ext_mgmt_frame_handling", "1")
  336. anqp_get(dev[0], bssid, 263)
  337. ev = hapd.wait_event(["MGMT-RX"], timeout=5)
  338. if ev is None:
  339. raise Exception("MGMT RX wait timed out")
  340. expect_gas_result(dev[0], "TIMEOUT")
  341. MGMT_SUBTYPE_ACTION = 13
  342. ACTION_CATEG_PUBLIC = 4
  343. GAS_INITIAL_REQUEST = 10
  344. GAS_INITIAL_RESPONSE = 11
  345. GAS_COMEBACK_REQUEST = 12
  346. GAS_COMEBACK_RESPONSE = 13
  347. GAS_ACTIONS = [ GAS_INITIAL_REQUEST, GAS_INITIAL_RESPONSE,
  348. GAS_COMEBACK_REQUEST, GAS_COMEBACK_RESPONSE ]
  349. def anqp_adv_proto():
  350. return struct.pack('BBBB', 108, 2, 127, 0)
  351. def anqp_initial_resp(dialog_token, status_code, comeback_delay=0):
  352. return struct.pack('<BBBHH', ACTION_CATEG_PUBLIC, GAS_INITIAL_RESPONSE,
  353. dialog_token, status_code, comeback_delay) + anqp_adv_proto()
  354. def anqp_comeback_resp(dialog_token, status_code=0, id=0, more=False, comeback_delay=0, bogus_adv_proto=False):
  355. if more:
  356. id |= 0x80
  357. if bogus_adv_proto:
  358. adv = struct.pack('BBBB', 108, 2, 127, 1)
  359. else:
  360. adv = anqp_adv_proto()
  361. return struct.pack('<BBBHBH', ACTION_CATEG_PUBLIC, GAS_COMEBACK_RESPONSE,
  362. dialog_token, status_code, id, comeback_delay) + adv
  363. def gas_rx(hapd):
  364. count = 0
  365. while count < 30:
  366. count = count + 1
  367. query = hapd.mgmt_rx()
  368. if query is None:
  369. raise Exception("Action frame not received")
  370. if query['subtype'] != MGMT_SUBTYPE_ACTION:
  371. continue
  372. payload = query['payload']
  373. if len(payload) < 2:
  374. continue
  375. (category, action) = struct.unpack('BB', payload[0:2])
  376. if category != ACTION_CATEG_PUBLIC or action not in GAS_ACTIONS:
  377. continue
  378. return query
  379. raise Exception("No Action frame received")
  380. def parse_gas(payload):
  381. pos = payload
  382. (category, action, dialog_token) = struct.unpack('BBB', pos[0:3])
  383. if category != ACTION_CATEG_PUBLIC:
  384. return None
  385. if action not in GAS_ACTIONS:
  386. return None
  387. gas = {}
  388. gas['action'] = action
  389. pos = pos[3:]
  390. if len(pos) < 1 and action != GAS_COMEBACK_REQUEST:
  391. return None
  392. gas['dialog_token'] = dialog_token
  393. if action == GAS_INITIAL_RESPONSE:
  394. if len(pos) < 4:
  395. return None
  396. (status_code, comeback_delay) = struct.unpack('<HH', pos[0:4])
  397. gas['status_code'] = status_code
  398. gas['comeback_delay'] = comeback_delay
  399. if action == GAS_COMEBACK_RESPONSE:
  400. if len(pos) < 5:
  401. return None
  402. (status_code, frag, comeback_delay) = struct.unpack('<HBH', pos[0:5])
  403. gas['status_code'] = status_code
  404. gas['frag'] = frag
  405. gas['comeback_delay'] = comeback_delay
  406. return gas
  407. def action_response(req):
  408. resp = {}
  409. resp['fc'] = req['fc']
  410. resp['da'] = req['sa']
  411. resp['sa'] = req['da']
  412. resp['bssid'] = req['bssid']
  413. return resp
  414. def send_gas_resp(hapd, resp):
  415. hapd.mgmt_tx(resp)
  416. ev = hapd.wait_event(["MGMT-TX-STATUS"], timeout=5)
  417. if ev is None:
  418. raise Exception("Missing TX status for GAS response")
  419. if "ok=1" not in ev:
  420. raise Exception("GAS response not acknowledged")
  421. def test_gas_invalid_response_type(dev, apdev):
  422. """GAS invalid response type"""
  423. hapd = start_ap(apdev[0])
  424. bssid = apdev[0]['bssid']
  425. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  426. hapd.set("ext_mgmt_frame_handling", "1")
  427. anqp_get(dev[0], bssid, 263)
  428. query = gas_rx(hapd)
  429. gas = parse_gas(query['payload'])
  430. resp = action_response(query)
  431. # GAS Comeback Response instead of GAS Initial Response
  432. resp['payload'] = anqp_comeback_resp(gas['dialog_token']) + struct.pack('<H', 0)
  433. send_gas_resp(hapd, resp)
  434. # station drops the invalid frame, so this needs to result in GAS timeout
  435. expect_gas_result(dev[0], "TIMEOUT")
  436. def test_gas_failure_status_code(dev, apdev):
  437. """GAS failure status code"""
  438. hapd = start_ap(apdev[0])
  439. bssid = apdev[0]['bssid']
  440. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  441. hapd.set("ext_mgmt_frame_handling", "1")
  442. anqp_get(dev[0], bssid, 263)
  443. query = gas_rx(hapd)
  444. gas = parse_gas(query['payload'])
  445. resp = action_response(query)
  446. resp['payload'] = anqp_initial_resp(gas['dialog_token'], 61) + struct.pack('<H', 0)
  447. send_gas_resp(hapd, resp)
  448. expect_gas_result(dev[0], "FAILURE")
  449. def test_gas_malformed(dev, apdev):
  450. """GAS malformed response frames"""
  451. hapd = start_ap(apdev[0])
  452. bssid = apdev[0]['bssid']
  453. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  454. hapd.set("ext_mgmt_frame_handling", "1")
  455. anqp_get(dev[0], bssid, 263)
  456. query = gas_rx(hapd)
  457. gas = parse_gas(query['payload'])
  458. resp = action_response(query)
  459. resp['payload'] = struct.pack('<BBBH', ACTION_CATEG_PUBLIC,
  460. GAS_COMEBACK_RESPONSE,
  461. gas['dialog_token'], 0)
  462. hapd.mgmt_tx(resp)
  463. resp['payload'] = struct.pack('<BBBHB', ACTION_CATEG_PUBLIC,
  464. GAS_COMEBACK_RESPONSE,
  465. gas['dialog_token'], 0, 0)
  466. hapd.mgmt_tx(resp)
  467. hdr = struct.pack('<BBBHH', ACTION_CATEG_PUBLIC, GAS_INITIAL_RESPONSE,
  468. gas['dialog_token'], 0, 0)
  469. resp['payload'] = hdr + struct.pack('B', 108)
  470. hapd.mgmt_tx(resp)
  471. resp['payload'] = hdr + struct.pack('BB', 108, 0)
  472. hapd.mgmt_tx(resp)
  473. resp['payload'] = hdr + struct.pack('BB', 108, 1)
  474. hapd.mgmt_tx(resp)
  475. resp['payload'] = hdr + struct.pack('BB', 108, 255)
  476. hapd.mgmt_tx(resp)
  477. resp['payload'] = hdr + struct.pack('BBB', 108, 1, 127)
  478. hapd.mgmt_tx(resp)
  479. resp['payload'] = hdr + struct.pack('BBB', 108, 2, 127)
  480. hapd.mgmt_tx(resp)
  481. resp['payload'] = hdr + struct.pack('BBBB', 0, 2, 127, 0)
  482. hapd.mgmt_tx(resp)
  483. resp['payload'] = anqp_initial_resp(gas['dialog_token'], 0) + struct.pack('<H', 1)
  484. hapd.mgmt_tx(resp)
  485. resp['payload'] = anqp_initial_resp(gas['dialog_token'], 0) + struct.pack('<HB', 2, 0)
  486. hapd.mgmt_tx(resp)
  487. resp['payload'] = anqp_initial_resp(gas['dialog_token'], 0) + struct.pack('<H', 65535)
  488. hapd.mgmt_tx(resp)
  489. resp['payload'] = anqp_initial_resp(gas['dialog_token'], 0) + struct.pack('<HBB', 1, 0, 0)
  490. hapd.mgmt_tx(resp)
  491. # Station drops invalid frames, but the last of the responses is valid from
  492. # GAS view point even though it has an extra octet in the end and the ANQP
  493. # part of the response is not valid. This is reported as successfully
  494. # completed GAS exchange.
  495. expect_gas_result(dev[0], "SUCCESS")
  496. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=5)
  497. if ev is None:
  498. raise Exception("ANQP-QUERY-DONE not reported")
  499. if "result=INVALID_FRAME" not in ev:
  500. raise Exception("Unexpected result: " + ev)
  501. def init_gas(hapd, bssid, dev):
  502. anqp_get(dev, bssid, 263)
  503. query = gas_rx(hapd)
  504. gas = parse_gas(query['payload'])
  505. dialog_token = gas['dialog_token']
  506. resp = action_response(query)
  507. resp['payload'] = anqp_initial_resp(dialog_token, 0, comeback_delay=1) + struct.pack('<H', 0)
  508. send_gas_resp(hapd, resp)
  509. query = gas_rx(hapd)
  510. gas = parse_gas(query['payload'])
  511. if gas['action'] != GAS_COMEBACK_REQUEST:
  512. raise Exception("Unexpected request action")
  513. if gas['dialog_token'] != dialog_token:
  514. raise Exception("Unexpected dialog token change")
  515. return query, dialog_token
  516. def test_gas_malformed_comeback_resp(dev, apdev):
  517. """GAS malformed comeback response frames"""
  518. hapd = start_ap(apdev[0])
  519. bssid = apdev[0]['bssid']
  520. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  521. hapd.set("ext_mgmt_frame_handling", "1")
  522. logger.debug("Non-zero status code in comeback response")
  523. query, dialog_token = init_gas(hapd, bssid, dev[0])
  524. resp = action_response(query)
  525. resp['payload'] = anqp_comeback_resp(dialog_token, status_code=2) + struct.pack('<H', 0)
  526. send_gas_resp(hapd, resp)
  527. expect_gas_result(dev[0], "FAILURE", status=2)
  528. logger.debug("Different advertisement protocol in comeback response")
  529. query, dialog_token = init_gas(hapd, bssid, dev[0])
  530. resp = action_response(query)
  531. resp['payload'] = anqp_comeback_resp(dialog_token, bogus_adv_proto=True) + struct.pack('<H', 0)
  532. send_gas_resp(hapd, resp)
  533. expect_gas_result(dev[0], "PEER_ERROR")
  534. logger.debug("Non-zero frag id and comeback delay in comeback response")
  535. query, dialog_token = init_gas(hapd, bssid, dev[0])
  536. resp = action_response(query)
  537. resp['payload'] = anqp_comeback_resp(dialog_token, id=1, comeback_delay=1) + struct.pack('<H', 0)
  538. send_gas_resp(hapd, resp)
  539. expect_gas_result(dev[0], "PEER_ERROR")
  540. logger.debug("Unexpected frag id in comeback response")
  541. query, dialog_token = init_gas(hapd, bssid, dev[0])
  542. resp = action_response(query)
  543. resp['payload'] = anqp_comeback_resp(dialog_token, id=1) + struct.pack('<H', 0)
  544. send_gas_resp(hapd, resp)
  545. expect_gas_result(dev[0], "PEER_ERROR")
  546. logger.debug("Empty fragment and replay in comeback response")
  547. query, dialog_token = init_gas(hapd, bssid, dev[0])
  548. resp = action_response(query)
  549. resp['payload'] = anqp_comeback_resp(dialog_token, more=True) + struct.pack('<H', 0)
  550. send_gas_resp(hapd, resp)
  551. query = gas_rx(hapd)
  552. gas = parse_gas(query['payload'])
  553. if gas['action'] != GAS_COMEBACK_REQUEST:
  554. raise Exception("Unexpected request action")
  555. if gas['dialog_token'] != dialog_token:
  556. raise Exception("Unexpected dialog token change")
  557. resp = action_response(query)
  558. resp['payload'] = anqp_comeback_resp(dialog_token) + struct.pack('<H', 0)
  559. send_gas_resp(hapd, resp)
  560. resp['payload'] = anqp_comeback_resp(dialog_token, id=1) + struct.pack('<H', 0)
  561. send_gas_resp(hapd, resp)
  562. expect_gas_result(dev[0], "SUCCESS")
  563. logger.debug("Unexpected initial response when waiting for comeback response")
  564. query, dialog_token = init_gas(hapd, bssid, dev[0])
  565. resp = action_response(query)
  566. resp['payload'] = anqp_initial_resp(dialog_token, 0) + struct.pack('<H', 0)
  567. send_gas_resp(hapd, resp)
  568. ev = hapd.wait_event(["MGMT-RX"], timeout=1)
  569. if ev is not None:
  570. raise Exception("Unexpected management frame")
  571. expect_gas_result(dev[0], "TIMEOUT")
  572. logger.debug("Too short comeback response")
  573. query, dialog_token = init_gas(hapd, bssid, dev[0])
  574. resp = action_response(query)
  575. resp['payload'] = struct.pack('<BBBH', ACTION_CATEG_PUBLIC,
  576. GAS_COMEBACK_RESPONSE, dialog_token, 0)
  577. send_gas_resp(hapd, resp)
  578. ev = hapd.wait_event(["MGMT-RX"], timeout=1)
  579. if ev is not None:
  580. raise Exception("Unexpected management frame")
  581. expect_gas_result(dev[0], "TIMEOUT")
  582. logger.debug("Too short comeback response(2)")
  583. query, dialog_token = init_gas(hapd, bssid, dev[0])
  584. resp = action_response(query)
  585. resp['payload'] = struct.pack('<BBBHBB', ACTION_CATEG_PUBLIC,
  586. GAS_COMEBACK_RESPONSE, dialog_token, 0, 0x80,
  587. 0)
  588. send_gas_resp(hapd, resp)
  589. ev = hapd.wait_event(["MGMT-RX"], timeout=1)
  590. if ev is not None:
  591. raise Exception("Unexpected management frame")
  592. expect_gas_result(dev[0], "TIMEOUT")
  593. logger.debug("Maximum comeback response fragment claiming more fragments")
  594. query, dialog_token = init_gas(hapd, bssid, dev[0])
  595. resp = action_response(query)
  596. resp['payload'] = anqp_comeback_resp(dialog_token, more=True) + struct.pack('<H', 0)
  597. send_gas_resp(hapd, resp)
  598. for i in range(1, 129):
  599. query = gas_rx(hapd)
  600. gas = parse_gas(query['payload'])
  601. if gas['action'] != GAS_COMEBACK_REQUEST:
  602. raise Exception("Unexpected request action")
  603. if gas['dialog_token'] != dialog_token:
  604. raise Exception("Unexpected dialog token change")
  605. resp = action_response(query)
  606. resp['payload'] = anqp_comeback_resp(dialog_token, id=i, more=True) + struct.pack('<H', 0)
  607. send_gas_resp(hapd, resp)
  608. expect_gas_result(dev[0], "PEER_ERROR")
  609. def test_gas_comeback_resp_additional_delay(dev, apdev):
  610. """GAS comeback response requesting additional delay"""
  611. hapd = start_ap(apdev[0])
  612. bssid = apdev[0]['bssid']
  613. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  614. hapd.set("ext_mgmt_frame_handling", "1")
  615. query, dialog_token = init_gas(hapd, bssid, dev[0])
  616. for i in range(0, 2):
  617. resp = action_response(query)
  618. resp['payload'] = anqp_comeback_resp(dialog_token, status_code=95, comeback_delay=50) + struct.pack('<H', 0)
  619. send_gas_resp(hapd, resp)
  620. query = gas_rx(hapd)
  621. gas = parse_gas(query['payload'])
  622. if gas['action'] != GAS_COMEBACK_REQUEST:
  623. raise Exception("Unexpected request action")
  624. if gas['dialog_token'] != dialog_token:
  625. raise Exception("Unexpected dialog token change")
  626. resp = action_response(query)
  627. resp['payload'] = anqp_comeback_resp(dialog_token, status_code=0) + struct.pack('<H', 0)
  628. send_gas_resp(hapd, resp)
  629. expect_gas_result(dev[0], "SUCCESS")
  630. def test_gas_unknown_adv_proto(dev, apdev):
  631. """Unknown advertisement protocol id"""
  632. bssid = apdev[0]['bssid']
  633. params = hs20_ap_params()
  634. params['hessid'] = bssid
  635. hostapd.add_ap(apdev[0]['ifname'], params)
  636. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  637. req = dev[0].request("GAS_REQUEST " + bssid + " 42 000102000101")
  638. if "FAIL" in req:
  639. raise Exception("GAS query request rejected")
  640. expect_gas_result(dev[0], "FAILURE", "59")
  641. ev = dev[0].wait_event(["GAS-RESPONSE-INFO"], timeout=10)
  642. if ev is None:
  643. raise Exception("GAS query timed out")
  644. exp = r'<.>(GAS-RESPONSE-INFO) addr=([0-9a-f:]*) dialog_token=([0-9]*) status_code=([0-9]*) resp_len=([\-0-9]*)'
  645. res = re.split(exp, ev)
  646. if len(res) < 6:
  647. raise Exception("Could not parse GAS-RESPONSE-INFO")
  648. if res[2] != bssid:
  649. raise Exception("Unexpected BSSID in response")
  650. status = res[4]
  651. if status != "59":
  652. raise Exception("Unexpected GAS-RESPONSE-INFO status")
  653. def test_gas_max_pending(dev, apdev):
  654. """GAS and maximum pending query limit"""
  655. hapd = start_ap(apdev[0])
  656. hapd.set("gas_frag_limit", "50")
  657. bssid = apdev[0]['bssid']
  658. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  659. wpas.interface_add("wlan5")
  660. if "OK" not in wpas.request("P2P_SET listen_channel 1"):
  661. raise Exception("Failed to set listen channel")
  662. if "OK" not in wpas.p2p_listen():
  663. raise Exception("Failed to start listen state")
  664. if "FAIL" in wpas.request("SET ext_mgmt_frame_handling 1"):
  665. raise Exception("Failed to enable external management frame handling")
  666. anqp_query = struct.pack('<HHHHHHHHHH', 256, 16, 257, 258, 260, 261, 262, 263, 264, 268)
  667. gas = struct.pack('<H', len(anqp_query)) + anqp_query
  668. for dialog_token in range(1, 10):
  669. msg = struct.pack('<BBB', ACTION_CATEG_PUBLIC, GAS_INITIAL_REQUEST,
  670. dialog_token) + anqp_adv_proto() + gas
  671. req = "MGMT_TX {} {} freq=2412 wait_time=10 action={}".format(bssid, bssid, binascii.hexlify(msg))
  672. if "OK" not in wpas.request(req):
  673. raise Exception("Could not send management frame")
  674. resp = wpas.mgmt_rx()
  675. if resp is None:
  676. raise Exception("MGMT-RX timeout")
  677. if 'payload' not in resp:
  678. raise Exception("Missing payload")
  679. gresp = parse_gas(resp['payload'])
  680. if gresp['dialog_token'] != dialog_token:
  681. raise Exception("Dialog token mismatch")
  682. status_code = gresp['status_code']
  683. if dialog_token < 9 and status_code != 0:
  684. raise Exception("Unexpected failure status code {} for dialog token {}".format(status_code, dialog_token))
  685. if dialog_token > 8 and status_code == 0:
  686. raise Exception("Unexpected success status code {} for dialog token {}".format(status_code, dialog_token))
  687. def test_gas_no_pending(dev, apdev):
  688. """GAS and no pending query for comeback request"""
  689. hapd = start_ap(apdev[0])
  690. bssid = apdev[0]['bssid']
  691. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  692. wpas.interface_add("wlan5")
  693. if "OK" not in wpas.request("P2P_SET listen_channel 1"):
  694. raise Exception("Failed to set listen channel")
  695. if "OK" not in wpas.p2p_listen():
  696. raise Exception("Failed to start listen state")
  697. if "FAIL" in wpas.request("SET ext_mgmt_frame_handling 1"):
  698. raise Exception("Failed to enable external management frame handling")
  699. msg = struct.pack('<BBB', ACTION_CATEG_PUBLIC, GAS_COMEBACK_REQUEST, 1)
  700. req = "MGMT_TX {} {} freq=2412 wait_time=10 action={}".format(bssid, bssid, binascii.hexlify(msg))
  701. if "OK" not in wpas.request(req):
  702. raise Exception("Could not send management frame")
  703. resp = wpas.mgmt_rx()
  704. if resp is None:
  705. raise Exception("MGMT-RX timeout")
  706. if 'payload' not in resp:
  707. raise Exception("Missing payload")
  708. gresp = parse_gas(resp['payload'])
  709. status_code = gresp['status_code']
  710. if status_code != 60:
  711. raise Exception("Unexpected status code {} (expected 60)".format(status_code))
  712. def test_gas_missing_payload(dev, apdev):
  713. """No action code in the query frame"""
  714. bssid = apdev[0]['bssid']
  715. params = hs20_ap_params()
  716. params['hessid'] = bssid
  717. hostapd.add_ap(apdev[0]['ifname'], params)
  718. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  719. cmd = "MGMT_TX {} {} freq=2412 action=040A".format(bssid, bssid)
  720. if "FAIL" in dev[0].request(cmd):
  721. raise Exception("Could not send test Action frame")
  722. ev = dev[0].wait_event(["MGMT-TX-STATUS"], timeout=10)
  723. if ev is None:
  724. raise Exception("Timeout on MGMT-TX-STATUS")
  725. if "result=SUCCESS" not in ev:
  726. raise Exception("AP did not ack Action frame")
  727. cmd = "MGMT_TX {} {} freq=2412 action=04".format(bssid, bssid)
  728. if "FAIL" in dev[0].request(cmd):
  729. raise Exception("Could not send test Action frame")
  730. ev = dev[0].wait_event(["MGMT-TX-STATUS"], timeout=10)
  731. if ev is None:
  732. raise Exception("Timeout on MGMT-TX-STATUS")
  733. if "result=SUCCESS" not in ev:
  734. raise Exception("AP did not ack Action frame")
  735. def test_gas_query_deinit(dev, apdev):
  736. """Pending GAS/ANQP query during deinit"""
  737. hapd = start_ap(apdev[0])
  738. bssid = apdev[0]['bssid']
  739. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  740. wpas.interface_add("wlan5")
  741. wpas.scan_for_bss(bssid, freq="2412", force_scan=True)
  742. id = wpas.request("RADIO_WORK add block-work")
  743. if "OK" not in wpas.request("ANQP_GET " + bssid + " 258"):
  744. raise Exception("ANQP_GET command failed")
  745. ev = wpas.wait_event(["GAS-QUERY-START", "EXT-RADIO-WORK-START"], timeout=5)
  746. if ev is None:
  747. raise Exception("Timeout while waiting radio work to start")
  748. ev = wpas.wait_event(["GAS-QUERY-START", "EXT-RADIO-WORK-START"], timeout=5)
  749. if ev is None:
  750. raise Exception("Timeout while waiting radio work to start (2)")
  751. # Remove the interface while the gas-query radio work is still pending and
  752. # GAS query has not yet been started.
  753. wpas.interface_remove("wlan5")
  754. def test_gas_anqp_oom_wpas(dev, apdev):
  755. """GAS/ANQP query and OOM in wpa_supplicant"""
  756. hapd = start_ap(apdev[0])
  757. bssid = apdev[0]['bssid']
  758. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  759. with alloc_fail(dev[0], 1, "gas_build_req"):
  760. if "FAIL" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  761. raise Exception("Unexpected ANQP_GET command success (OOM)")
  762. def test_gas_anqp_oom_hapd(dev, apdev):
  763. """GAS/ANQP query and OOM in hostapd"""
  764. hapd = start_ap(apdev[0])
  765. bssid = apdev[0]['bssid']
  766. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  767. with alloc_fail(hapd, 1, "gas_build_resp"):
  768. # This query will time out due to the AP not sending a response (OOM).
  769. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  770. raise Exception("ANQP_GET command failed")
  771. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  772. if ev is None:
  773. raise Exception("GAS query start timed out")
  774. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  775. if ev is None:
  776. raise Exception("GAS query timed out")
  777. if "result=TIMEOUT" not in ev:
  778. raise Exception("Unexpected result: " + ev)
  779. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=10)
  780. if ev is None:
  781. raise Exception("ANQP-QUERY-DONE event not seen")
  782. if "result=FAILURE" not in ev:
  783. raise Exception("Unexpected result: " + ev)
  784. with alloc_fail(hapd, 1, "gas_anqp_build_comeback_resp"):
  785. hapd.set("gas_frag_limit", "50")
  786. # This query will time out due to the AP not sending a response (OOM).
  787. dev[0].request("FETCH_ANQP")
  788. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  789. if ev is None:
  790. raise Exception("GAS query start timed out")
  791. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  792. if ev is None:
  793. raise Exception("GAS query timed out")
  794. if "result=TIMEOUT" not in ev:
  795. raise Exception("Unexpected result: " + ev)
  796. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=10)
  797. if ev is None:
  798. raise Exception("ANQP-QUERY-DONE event not seen")
  799. if "result=FAILURE" not in ev:
  800. raise Exception("Unexpected result: " + ev)
  801. def test_gas_anqp_extra_elements(dev, apdev):
  802. """GAS/ANQP and extra ANQP elements"""
  803. geo_loc = "001052834d12efd2b08b9b4bf1cc2c00004104050000000000060100"
  804. civic_loc = "0000f9555302f50102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5"
  805. params = { "ssid": "gas/anqp",
  806. "interworking": "1",
  807. "anqp_elem": [ "265:" + geo_loc,
  808. "266:" + civic_loc,
  809. "262:1122334455",
  810. "275:01020304",
  811. "60000:01",
  812. "299:0102" ] }
  813. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  814. bssid = apdev[0]['bssid']
  815. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  816. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 265,266"):
  817. raise Exception("ANQP_GET command failed")
  818. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  819. if ev is None:
  820. raise Exception("GAS query timed out")
  821. bss = dev[0].get_bss(bssid)
  822. if 'anqp[265]' not in bss:
  823. raise Exception("AP Geospatial Location ANQP-element not seen")
  824. if bss['anqp[265]'] != geo_loc:
  825. raise Exception("Unexpected AP Geospatial Location ANQP-element value: " + bss['anqp[265]'])
  826. if 'anqp[266]' not in bss:
  827. raise Exception("AP Civic Location ANQP-element not seen")
  828. if bss['anqp[266]'] != civic_loc:
  829. raise Exception("Unexpected AP Civic Location ANQP-element value: " + bss['anqp[266]'])
  830. dev[1].scan_for_bss(bssid, freq="2412", force_scan=True)
  831. 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"):
  832. raise Exception("ANQP_GET command failed")
  833. ev = dev[1].wait_event(["GAS-QUERY-DONE"], timeout=10)
  834. if ev is None:
  835. raise Exception("GAS query timed out")
  836. bss = dev[1].get_bss(bssid)
  837. if 'anqp[265]' not in bss:
  838. raise Exception("AP Geospatial Location ANQP-element not seen")
  839. if bss['anqp[265]'] != geo_loc:
  840. raise Exception("Unexpected AP Geospatial Location ANQP-element value: " + bss['anqp[265]'])
  841. if 'anqp[266]' in bss:
  842. raise Exception("AP Civic Location ANQP-element unexpectedly seen")
  843. if 'anqp[275]' not in bss:
  844. raise Exception("ANQP-element Info ID 275 not seen")
  845. if bss['anqp[275]'] != "01020304":
  846. raise Exception("Unexpected AP ANQP-element Info ID 299 value: " + bss['anqp[299]'])
  847. if 'anqp[299]' not in bss:
  848. raise Exception("ANQP-element Info ID 299 not seen")
  849. if bss['anqp[299]'] != "0102":
  850. raise Exception("Unexpected AP ANQP-element Info ID 299 value: " + bss['anqp[299]'])
  851. if 'anqp_ip_addr_type_availability' not in bss:
  852. raise Exception("ANQP-element Info ID 292 not seen")
  853. if bss['anqp_ip_addr_type_availability'] != "1122334455":
  854. raise Exception("Unexpected AP ANQP-element Info ID 262 value: " + bss['anqp_ip_addr_type_availability'])