test_gas.py 40 KB

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