test_gas.py 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965
  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, HwsimSkip
  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_rand_ta(dev, apdev, params):
  129. """Generic GAS query with random TA"""
  130. flags = int(dev[0].get_driver_status_field('capa.flags'), 16)
  131. if flags & 0x0000400000000000 == 0:
  132. raise HwsimSkip("Driver does not support random GAS TA")
  133. try:
  134. _test_gas_rand_ta(dev, apdev, params['logdir'])
  135. finally:
  136. dev[0].request("SET gas_rand_mac_addr 0")
  137. def _test_gas_rand_ta(dev, apdev, logdir):
  138. bssid = apdev[0]['bssid']
  139. params = hs20_ap_params()
  140. params['hessid'] = bssid
  141. hostapd.add_ap(apdev[0], params)
  142. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  143. req = dev[0].request("SET gas_rand_mac_addr 1")
  144. if "FAIL" in req:
  145. raise Exception("Failed to set gas_rand_mac_addr")
  146. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  147. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000101")
  148. if "FAIL" in req:
  149. raise Exception("GAS query request rejected")
  150. ev = dev[0].wait_event(["GAS-RESPONSE-INFO"], timeout=10)
  151. if ev is None:
  152. raise Exception("GAS query timed out")
  153. get_gas_response(dev[0], bssid, ev, extra_test=True)
  154. out = run_tshark(os.path.join(logdir, "hwsim0.pcapng"),
  155. "wlan_mgt.fixed.category_code == 4 && (wlan_mgt.fixed.publicact == 0x0a || wlan_mgt.fixed.publicact == 0x0b)",
  156. display=["wlan.ta", "wlan.ra"])
  157. res = out.splitlines()
  158. if len(res) != 2:
  159. raise Exception("Unexpected number of GAS frames")
  160. req_ta = res[0].split('\t')[0]
  161. resp_ra = res[1].split('\t')[1]
  162. logger.info("Request TA: %s, Response RA: %s" % (req_ta, resp_ra))
  163. if req_ta != resp_ra:
  164. raise Exception("Request TA does not match response RA")
  165. if req_ta == dev[0].own_addr():
  166. raise Exception("Request TA was own permanent MAC address, not random")
  167. def test_gas_concurrent_scan(dev, apdev):
  168. """Generic GAS queries with concurrent scan operation"""
  169. bssid = apdev[0]['bssid']
  170. params = hs20_ap_params()
  171. params['hessid'] = bssid
  172. hostapd.add_ap(apdev[0], params)
  173. # get BSS entry available to allow GAS query
  174. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  175. logger.info("Request concurrent operations")
  176. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000101")
  177. if "FAIL" in req:
  178. raise Exception("GAS query request rejected")
  179. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000801")
  180. if "FAIL" in req:
  181. raise Exception("GAS query request rejected")
  182. dev[0].scan(no_wait=True)
  183. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000201")
  184. if "FAIL" in req:
  185. raise Exception("GAS query request rejected")
  186. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000501")
  187. if "FAIL" in req:
  188. raise Exception("GAS query request rejected")
  189. responses = 0
  190. for i in range(0, 5):
  191. ev = dev[0].wait_event(["GAS-RESPONSE-INFO", "CTRL-EVENT-SCAN-RESULTS"],
  192. timeout=10)
  193. if ev is None:
  194. raise Exception("Operation timed out")
  195. if "GAS-RESPONSE-INFO" in ev:
  196. responses = responses + 1
  197. get_gas_response(dev[0], bssid, ev, allow_fetch_failure=True)
  198. if responses != 4:
  199. raise Exception("Unexpected number of GAS responses")
  200. def test_gas_concurrent_connect(dev, apdev):
  201. """Generic GAS queries with concurrent connection operation"""
  202. skip_with_fips(dev[0])
  203. bssid = apdev[0]['bssid']
  204. params = hs20_ap_params()
  205. params['hessid'] = bssid
  206. hostapd.add_ap(apdev[0], params)
  207. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  208. logger.debug("Start concurrent connect and GAS request")
  209. dev[0].connect("test-gas", key_mgmt="WPA-EAP", eap="TTLS",
  210. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  211. password="password", phase2="auth=MSCHAPV2",
  212. ca_cert="auth_serv/ca.pem", wait_connect=False,
  213. scan_freq="2412")
  214. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000101")
  215. if "FAIL" in req:
  216. raise Exception("GAS query request rejected")
  217. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", "GAS-RESPONSE-INFO"],
  218. timeout=20)
  219. if ev is None:
  220. raise Exception("Operation timed out")
  221. if "CTRL-EVENT-CONNECTED" not in ev:
  222. raise Exception("Unexpected operation order")
  223. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", "GAS-RESPONSE-INFO"],
  224. timeout=20)
  225. if ev is None:
  226. raise Exception("Operation timed out")
  227. if "GAS-RESPONSE-INFO" not in ev:
  228. raise Exception("Unexpected operation order")
  229. get_gas_response(dev[0], bssid, ev)
  230. dev[0].request("DISCONNECT")
  231. dev[0].wait_disconnected(timeout=5)
  232. logger.debug("Wait six seconds for expiration of connect-without-scan")
  233. time.sleep(6)
  234. dev[0].dump_monitor()
  235. logger.debug("Start concurrent GAS request and connect")
  236. req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000101")
  237. if "FAIL" in req:
  238. raise Exception("GAS query request rejected")
  239. dev[0].request("RECONNECT")
  240. ev = dev[0].wait_event(["GAS-RESPONSE-INFO"], timeout=10)
  241. if ev is None:
  242. raise Exception("Operation timed out")
  243. get_gas_response(dev[0], bssid, ev)
  244. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=20)
  245. if ev is None:
  246. raise Exception("No new scan results reported")
  247. ev = dev[0].wait_connected(timeout=20, error="Operation tiemd out")
  248. if "CTRL-EVENT-CONNECTED" not in ev:
  249. raise Exception("Unexpected operation order")
  250. def gas_fragment_and_comeback(dev, apdev, frag_limit=0, comeback_delay=0):
  251. hapd = start_ap(apdev)
  252. if frag_limit:
  253. hapd.set("gas_frag_limit", str(frag_limit))
  254. if comeback_delay:
  255. hapd.set("gas_comeback_delay", str(comeback_delay))
  256. dev.scan_for_bss(apdev['bssid'], freq="2412", force_scan=True)
  257. dev.request("FETCH_ANQP")
  258. ev = dev.wait_event(["GAS-QUERY-DONE"], timeout=5)
  259. if ev is None:
  260. raise Exception("No GAS-QUERY-DONE event")
  261. if "result=SUCCESS" not in ev:
  262. raise Exception("Unexpected GAS result: " + ev)
  263. for i in range(0, 13):
  264. ev = dev.wait_event(["RX-ANQP", "RX-HS20-ANQP"], timeout=5)
  265. if ev is None:
  266. raise Exception("Operation timed out")
  267. ev = dev.wait_event(["ANQP-QUERY-DONE"], timeout=1)
  268. if ev is None:
  269. raise Exception("No ANQP-QUERY-DONE event")
  270. if "result=SUCCESS" not in ev:
  271. raise Exception("Unexpected ANQP result: " + ev)
  272. def test_gas_fragment(dev, apdev):
  273. """GAS fragmentation"""
  274. gas_fragment_and_comeback(dev[0], apdev[0], frag_limit=50)
  275. def test_gas_fragment_mcc(dev, apdev):
  276. """GAS fragmentation with mac80211_hwsim MCC enabled"""
  277. with HWSimRadio(n_channels=2) as (radio, iface):
  278. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  279. wpas.interface_add(iface)
  280. gas_fragment_and_comeback(wpas, apdev[0], frag_limit=50)
  281. def test_gas_fragment_with_comeback_delay(dev, apdev):
  282. """GAS fragmentation and comeback delay"""
  283. gas_fragment_and_comeback(dev[0], apdev[0], frag_limit=50,
  284. comeback_delay=500)
  285. def test_gas_fragment_with_comeback_delay_mcc(dev, apdev):
  286. """GAS fragmentation and comeback delay with mac80211_hwsim MCC enabled"""
  287. with HWSimRadio(n_channels=2) as (radio, iface):
  288. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  289. wpas.interface_add(iface)
  290. gas_fragment_and_comeback(wpas, apdev[0], frag_limit=50,
  291. comeback_delay=500)
  292. def test_gas_comeback_delay(dev, apdev):
  293. """GAS comeback delay"""
  294. run_gas_comeback_delay(dev, apdev, 500)
  295. def test_gas_comeback_delay_long(dev, apdev):
  296. """GAS long comeback delay"""
  297. run_gas_comeback_delay(dev, apdev, 2500)
  298. def test_gas_comeback_delay_long2(dev, apdev):
  299. """GAS long comeback delay over default STA timeout"""
  300. run_gas_comeback_delay(dev, apdev, 6000)
  301. def run_gas_comeback_delay(dev, apdev, delay):
  302. hapd = start_ap(apdev[0])
  303. hapd.set("gas_comeback_delay", str(delay))
  304. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True)
  305. dev[0].request("FETCH_ANQP")
  306. if "FAIL-BUSY" not in dev[0].request("SCAN"):
  307. raise Exception("SCAN accepted during FETCH_ANQP")
  308. for i in range(0, 6):
  309. ev = dev[0].wait_event(["RX-ANQP"], timeout=10)
  310. if ev is None:
  311. raise Exception("Operation timed out")
  312. @remote_compatible
  313. def test_gas_stop_fetch_anqp(dev, apdev):
  314. """Stop FETCH_ANQP operation"""
  315. hapd = start_ap(apdev[0])
  316. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True)
  317. hapd.set("ext_mgmt_frame_handling", "1")
  318. dev[0].request("FETCH_ANQP")
  319. dev[0].request("STOP_FETCH_ANQP")
  320. hapd.set("ext_mgmt_frame_handling", "0")
  321. ev = dev[0].wait_event(["RX-ANQP", "GAS-QUERY-DONE"], timeout=10)
  322. if ev is None:
  323. raise Exception("GAS-QUERY-DONE timed out")
  324. if "RX-ANQP" in ev:
  325. raise Exception("Unexpected ANQP response received")
  326. def test_gas_anqp_get(dev, apdev):
  327. """GAS/ANQP query for both IEEE 802.11 and Hotspot 2.0 elements"""
  328. hapd = start_ap(apdev[0])
  329. bssid = apdev[0]['bssid']
  330. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  331. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258,268,hs20:3,hs20:4"):
  332. raise Exception("ANQP_GET command failed")
  333. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  334. if ev is None:
  335. raise Exception("GAS query start timed out")
  336. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  337. if ev is None:
  338. raise Exception("GAS query timed out")
  339. ev = dev[0].wait_event(["RX-ANQP"], timeout=1)
  340. if ev is None or "Venue Name" not in ev:
  341. raise Exception("Did not receive Venue Name")
  342. ev = dev[0].wait_event(["RX-ANQP"], timeout=1)
  343. if ev is None or "Domain Name list" not in ev:
  344. raise Exception("Did not receive Domain Name list")
  345. ev = dev[0].wait_event(["RX-HS20-ANQP"], timeout=1)
  346. if ev is None or "Operator Friendly Name" not in ev:
  347. raise Exception("Did not receive Operator Friendly Name")
  348. ev = dev[0].wait_event(["RX-HS20-ANQP"], timeout=1)
  349. if ev is None or "WAN Metrics" not in ev:
  350. raise Exception("Did not receive WAN Metrics")
  351. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=10)
  352. if ev is None:
  353. raise Exception("ANQP-QUERY-DONE event not seen")
  354. if "result=SUCCESS" not in ev:
  355. raise Exception("Unexpected result: " + ev)
  356. if "OK" not in dev[0].request("ANQP_GET " + bssid + " hs20:3"):
  357. raise Exception("ANQP_GET command failed")
  358. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  359. if ev is None:
  360. raise Exception("GAS query start timed out")
  361. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  362. if ev is None:
  363. raise Exception("GAS query timed out")
  364. ev = dev[0].wait_event(["RX-HS20-ANQP"], timeout=1)
  365. if ev is None or "Operator Friendly Name" not in ev:
  366. raise Exception("Did not receive Operator Friendly Name")
  367. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=10)
  368. if ev is None:
  369. raise Exception("ANQP-QUERY-DONE event not seen")
  370. if "result=SUCCESS" not in ev:
  371. raise Exception("Unexpected result: " + ev)
  372. if "OK" not in dev[0].request("HS20_ANQP_GET " + bssid + " 3,4"):
  373. raise Exception("ANQP_GET command failed")
  374. ev = dev[0].wait_event(["RX-HS20-ANQP"], timeout=1)
  375. if ev is None or "Operator Friendly Name" not in ev:
  376. raise Exception("Did not receive Operator Friendly Name")
  377. ev = dev[0].wait_event(["RX-HS20-ANQP"], timeout=1)
  378. if ev is None or "WAN Metrics" not in ev:
  379. raise Exception("Did not receive WAN Metrics")
  380. logger.info("Attempt an MBO request with an AP that does not support MBO")
  381. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 272,mbo:2"):
  382. raise Exception("ANQP_GET command failed (2)")
  383. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  384. if ev is None:
  385. raise Exception("GAS query start timed out (2)")
  386. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  387. if ev is None:
  388. raise Exception("GAS query timed out (2)")
  389. cmds = [ "",
  390. "foo",
  391. "00:11:22:33:44:55 258,hs20:-1",
  392. "00:11:22:33:44:55 258,hs20:0",
  393. "00:11:22:33:44:55 258,hs20:32",
  394. "00:11:22:33:44:55 hs20:-1",
  395. "00:11:22:33:44:55 hs20:0",
  396. "00:11:22:33:44:55 hs20:32",
  397. "00:11:22:33:44:55 mbo:-1",
  398. "00:11:22:33:44:55 mbo:0",
  399. "00:11:22:33:44:55 mbo:999",
  400. "00:11:22:33:44:55 mbo:1,258,mbo:2,mbo:3,259",
  401. "00:11:22:33:44:55",
  402. "00:11:22:33:44:55 ",
  403. "00:11:22:33:44:55 0",
  404. "00:11:22:33:44:55 1" ]
  405. for cmd in cmds:
  406. if "FAIL" not in dev[0].request("ANQP_GET " + cmd):
  407. raise Exception("Invalid ANQP_GET accepted")
  408. cmds = [ "",
  409. "foo",
  410. "00:11:22:33:44:55 -1",
  411. "00:11:22:33:44:55 0",
  412. "00:11:22:33:44:55 32",
  413. "00:11:22:33:44:55",
  414. "00:11:22:33:44:55 ",
  415. "00:11:22:33:44:55 0",
  416. "00:11:22:33:44:55 1" ]
  417. for cmd in cmds:
  418. if "FAIL" not in dev[0].request("HS20_ANQP_GET " + cmd):
  419. raise Exception("Invalid HS20_ANQP_GET accepted")
  420. def test_gas_anqp_get_oom(dev, apdev):
  421. """GAS/ANQP query OOM"""
  422. hapd = start_ap(apdev[0])
  423. bssid = apdev[0]['bssid']
  424. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  425. with alloc_fail(dev[0], 1, "wpabuf_alloc;anqp_send_req"):
  426. if "FAIL" not in dev[0].request("ANQP_GET " + bssid + " 258,268,hs20:3,hs20:4"):
  427. raise Exception("ANQP_GET command accepted during OOM")
  428. with alloc_fail(dev[0], 1, "hs20_build_anqp_req;hs20_anqp_send_req"):
  429. if "FAIL" not in dev[0].request("HS20_ANQP_GET " + bssid + " 1"):
  430. raise Exception("HS20_ANQP_GET command accepted during OOM")
  431. with alloc_fail(dev[0], 1, "gas_query_req;hs20_anqp_send_req"):
  432. if "FAIL" not in dev[0].request("HS20_ANQP_GET " + bssid + " 1"):
  433. raise Exception("HS20_ANQP_GET command accepted during OOM")
  434. with alloc_fail(dev[0], 1, "=hs20_anqp_send_req"):
  435. if "FAIL" not in dev[0].request("REQ_HS20_ICON " + bssid + " w1fi_logo"):
  436. raise Exception("REQ_HS20_ICON command accepted during OOM")
  437. with alloc_fail(dev[0], 2, "=hs20_anqp_send_req"):
  438. if "FAIL" not in dev[0].request("REQ_HS20_ICON " + bssid + " w1fi_logo"):
  439. raise Exception("REQ_HS20_ICON command accepted during OOM")
  440. def test_gas_anqp_icon_binary_proto(dev, apdev):
  441. """GAS/ANQP and icon binary protocol testing"""
  442. hapd = start_ap(apdev[0])
  443. bssid = apdev[0]['bssid']
  444. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  445. hapd.set("ext_mgmt_frame_handling", "1")
  446. tests = [ '010000', '01000000', '00000000', '00030000', '00020000',
  447. '00000100', '0001ff0100ee', '0001ff0200ee' ]
  448. for test in tests:
  449. dev[0].request("HS20_ICON_REQUEST " + bssid + " w1fi_logo")
  450. query = gas_rx(hapd)
  451. gas = parse_gas(query['payload'])
  452. resp = action_response(query)
  453. data = binascii.unhexlify(test)
  454. data = binascii.unhexlify('506f9a110b00') + data
  455. data = struct.pack('<HHH', len(data) + 4, 0xdddd, len(data)) + data
  456. resp['payload'] = anqp_initial_resp(gas['dialog_token'], 0) + data
  457. send_gas_resp(hapd, resp)
  458. expect_gas_result(dev[0], "SUCCESS")
  459. def test_gas_anqp_hs20_proto(dev, apdev):
  460. """GAS/ANQP and Hotspot 2.0 element protocol testing"""
  461. hapd = start_ap(apdev[0])
  462. bssid = apdev[0]['bssid']
  463. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  464. hapd.set("ext_mgmt_frame_handling", "1")
  465. tests = [ '00', '0100', '0201', '0300', '0400', '0500', '0600', '0700',
  466. '0800', '0900', '0a00', '0b0000000000' ]
  467. for test in tests:
  468. dev[0].request("HS20_ANQP_GET " + bssid + " 3,4")
  469. query = gas_rx(hapd)
  470. gas = parse_gas(query['payload'])
  471. resp = action_response(query)
  472. data = binascii.unhexlify(test)
  473. data = binascii.unhexlify('506f9a11') + data
  474. data = struct.pack('<HHH', len(data) + 4, 0xdddd, len(data)) + data
  475. resp['payload'] = anqp_initial_resp(gas['dialog_token'], 0) + data
  476. send_gas_resp(hapd, resp)
  477. expect_gas_result(dev[0], "SUCCESS")
  478. def expect_gas_result(dev, result, status=None):
  479. ev = dev.wait_event(["GAS-QUERY-DONE"], timeout=10)
  480. if ev is None:
  481. raise Exception("GAS query timed out")
  482. if "result=" + result not in ev:
  483. raise Exception("Unexpected GAS query result")
  484. if status and "status_code=" + str(status) + ' ' not in ev:
  485. raise Exception("Unexpected GAS status code")
  486. def anqp_get(dev, bssid, id):
  487. if "OK" not in dev.request("ANQP_GET " + bssid + " " + str(id)):
  488. raise Exception("ANQP_GET command failed")
  489. ev = dev.wait_event(["GAS-QUERY-START"], timeout=5)
  490. if ev is None:
  491. raise Exception("GAS query start timed out")
  492. def test_gas_timeout(dev, apdev):
  493. """GAS timeout"""
  494. hapd = start_ap(apdev[0])
  495. bssid = apdev[0]['bssid']
  496. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  497. hapd.set("ext_mgmt_frame_handling", "1")
  498. anqp_get(dev[0], bssid, 263)
  499. ev = hapd.wait_event(["MGMT-RX"], timeout=5)
  500. if ev is None:
  501. raise Exception("MGMT RX wait timed out")
  502. expect_gas_result(dev[0], "TIMEOUT")
  503. MGMT_SUBTYPE_ACTION = 13
  504. ACTION_CATEG_PUBLIC = 4
  505. GAS_INITIAL_REQUEST = 10
  506. GAS_INITIAL_RESPONSE = 11
  507. GAS_COMEBACK_REQUEST = 12
  508. GAS_COMEBACK_RESPONSE = 13
  509. GAS_ACTIONS = [ GAS_INITIAL_REQUEST, GAS_INITIAL_RESPONSE,
  510. GAS_COMEBACK_REQUEST, GAS_COMEBACK_RESPONSE ]
  511. def anqp_adv_proto():
  512. return struct.pack('BBBB', 108, 2, 127, 0)
  513. def anqp_initial_resp(dialog_token, status_code, comeback_delay=0):
  514. return struct.pack('<BBBHH', ACTION_CATEG_PUBLIC, GAS_INITIAL_RESPONSE,
  515. dialog_token, status_code, comeback_delay) + anqp_adv_proto()
  516. def anqp_comeback_resp(dialog_token, status_code=0, id=0, more=False, comeback_delay=0, bogus_adv_proto=False):
  517. if more:
  518. id |= 0x80
  519. if bogus_adv_proto:
  520. adv = struct.pack('BBBB', 108, 2, 127, 1)
  521. else:
  522. adv = anqp_adv_proto()
  523. return struct.pack('<BBBHBH', ACTION_CATEG_PUBLIC, GAS_COMEBACK_RESPONSE,
  524. dialog_token, status_code, id, comeback_delay) + adv
  525. def gas_rx(hapd):
  526. count = 0
  527. while count < 30:
  528. count = count + 1
  529. query = hapd.mgmt_rx()
  530. if query is None:
  531. raise Exception("Action frame not received")
  532. if query['subtype'] != MGMT_SUBTYPE_ACTION:
  533. continue
  534. payload = query['payload']
  535. if len(payload) < 2:
  536. continue
  537. (category, action) = struct.unpack('BB', payload[0:2])
  538. if category != ACTION_CATEG_PUBLIC or action not in GAS_ACTIONS:
  539. continue
  540. return query
  541. raise Exception("No Action frame received")
  542. def parse_gas(payload):
  543. pos = payload
  544. (category, action, dialog_token) = struct.unpack('BBB', pos[0:3])
  545. if category != ACTION_CATEG_PUBLIC:
  546. return None
  547. if action not in GAS_ACTIONS:
  548. return None
  549. gas = {}
  550. gas['action'] = action
  551. pos = pos[3:]
  552. if len(pos) < 1 and action != GAS_COMEBACK_REQUEST:
  553. return None
  554. gas['dialog_token'] = dialog_token
  555. if action == GAS_INITIAL_RESPONSE:
  556. if len(pos) < 4:
  557. return None
  558. (status_code, comeback_delay) = struct.unpack('<HH', pos[0:4])
  559. gas['status_code'] = status_code
  560. gas['comeback_delay'] = comeback_delay
  561. if action == GAS_COMEBACK_RESPONSE:
  562. if len(pos) < 5:
  563. return None
  564. (status_code, frag, comeback_delay) = struct.unpack('<HBH', pos[0:5])
  565. gas['status_code'] = status_code
  566. gas['frag'] = frag
  567. gas['comeback_delay'] = comeback_delay
  568. return gas
  569. def action_response(req):
  570. resp = {}
  571. resp['fc'] = req['fc']
  572. resp['da'] = req['sa']
  573. resp['sa'] = req['da']
  574. resp['bssid'] = req['bssid']
  575. return resp
  576. def send_gas_resp(hapd, resp):
  577. hapd.mgmt_tx(resp)
  578. ev = hapd.wait_event(["MGMT-TX-STATUS"], timeout=5)
  579. if ev is None:
  580. raise Exception("Missing TX status for GAS response")
  581. if "ok=1" not in ev:
  582. raise Exception("GAS response not acknowledged")
  583. def test_gas_invalid_response_type(dev, apdev):
  584. """GAS invalid response type"""
  585. hapd = start_ap(apdev[0])
  586. bssid = apdev[0]['bssid']
  587. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  588. hapd.set("ext_mgmt_frame_handling", "1")
  589. anqp_get(dev[0], bssid, 263)
  590. query = gas_rx(hapd)
  591. gas = parse_gas(query['payload'])
  592. resp = action_response(query)
  593. # GAS Comeback Response instead of GAS Initial Response
  594. resp['payload'] = anqp_comeback_resp(gas['dialog_token']) + struct.pack('<H', 0)
  595. send_gas_resp(hapd, resp)
  596. # station drops the invalid frame, so this needs to result in GAS timeout
  597. expect_gas_result(dev[0], "TIMEOUT")
  598. def test_gas_failure_status_code(dev, apdev):
  599. """GAS failure status code"""
  600. hapd = start_ap(apdev[0])
  601. bssid = apdev[0]['bssid']
  602. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  603. hapd.set("ext_mgmt_frame_handling", "1")
  604. anqp_get(dev[0], bssid, 263)
  605. query = gas_rx(hapd)
  606. gas = parse_gas(query['payload'])
  607. resp = action_response(query)
  608. resp['payload'] = anqp_initial_resp(gas['dialog_token'], 61) + struct.pack('<H', 0)
  609. send_gas_resp(hapd, resp)
  610. expect_gas_result(dev[0], "FAILURE")
  611. def test_gas_malformed(dev, apdev):
  612. """GAS malformed response frames"""
  613. hapd = start_ap(apdev[0])
  614. bssid = apdev[0]['bssid']
  615. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  616. hapd.set("ext_mgmt_frame_handling", "1")
  617. anqp_get(dev[0], bssid, 263)
  618. query = gas_rx(hapd)
  619. gas = parse_gas(query['payload'])
  620. resp = action_response(query)
  621. resp['payload'] = struct.pack('<BBBH', ACTION_CATEG_PUBLIC,
  622. GAS_COMEBACK_RESPONSE,
  623. gas['dialog_token'], 0)
  624. hapd.mgmt_tx(resp)
  625. resp['payload'] = struct.pack('<BBBHB', ACTION_CATEG_PUBLIC,
  626. GAS_COMEBACK_RESPONSE,
  627. gas['dialog_token'], 0, 0)
  628. hapd.mgmt_tx(resp)
  629. hdr = struct.pack('<BBBHH', ACTION_CATEG_PUBLIC, GAS_INITIAL_RESPONSE,
  630. gas['dialog_token'], 0, 0)
  631. resp['payload'] = hdr + struct.pack('B', 108)
  632. hapd.mgmt_tx(resp)
  633. resp['payload'] = hdr + struct.pack('BB', 108, 0)
  634. hapd.mgmt_tx(resp)
  635. resp['payload'] = hdr + struct.pack('BB', 108, 1)
  636. hapd.mgmt_tx(resp)
  637. resp['payload'] = hdr + struct.pack('BB', 108, 255)
  638. hapd.mgmt_tx(resp)
  639. resp['payload'] = hdr + struct.pack('BBB', 108, 1, 127)
  640. hapd.mgmt_tx(resp)
  641. resp['payload'] = hdr + struct.pack('BBB', 108, 2, 127)
  642. hapd.mgmt_tx(resp)
  643. resp['payload'] = hdr + struct.pack('BBBB', 0, 2, 127, 0)
  644. hapd.mgmt_tx(resp)
  645. resp['payload'] = anqp_initial_resp(gas['dialog_token'], 0) + struct.pack('<H', 1)
  646. hapd.mgmt_tx(resp)
  647. resp['payload'] = anqp_initial_resp(gas['dialog_token'], 0) + struct.pack('<HB', 2, 0)
  648. hapd.mgmt_tx(resp)
  649. resp['payload'] = anqp_initial_resp(gas['dialog_token'], 0) + struct.pack('<H', 65535)
  650. hapd.mgmt_tx(resp)
  651. resp['payload'] = anqp_initial_resp(gas['dialog_token'], 0) + struct.pack('<HBB', 1, 0, 0)
  652. hapd.mgmt_tx(resp)
  653. # Station drops invalid frames, but the last of the responses is valid from
  654. # GAS view point even though it has an extra octet in the end and the ANQP
  655. # part of the response is not valid. This is reported as successfully
  656. # completed GAS exchange.
  657. expect_gas_result(dev[0], "SUCCESS")
  658. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=5)
  659. if ev is None:
  660. raise Exception("ANQP-QUERY-DONE not reported")
  661. if "result=INVALID_FRAME" not in ev:
  662. raise Exception("Unexpected result: " + ev)
  663. def init_gas(hapd, bssid, dev):
  664. anqp_get(dev, bssid, 263)
  665. query = gas_rx(hapd)
  666. gas = parse_gas(query['payload'])
  667. dialog_token = gas['dialog_token']
  668. resp = action_response(query)
  669. resp['payload'] = anqp_initial_resp(dialog_token, 0, comeback_delay=1) + struct.pack('<H', 0)
  670. send_gas_resp(hapd, resp)
  671. query = gas_rx(hapd)
  672. gas = parse_gas(query['payload'])
  673. if gas['action'] != GAS_COMEBACK_REQUEST:
  674. raise Exception("Unexpected request action")
  675. if gas['dialog_token'] != dialog_token:
  676. raise Exception("Unexpected dialog token change")
  677. return query, dialog_token
  678. def allow_gas_initial_req(hapd, dialog_token):
  679. msg = hapd.mgmt_rx(timeout=1)
  680. if msg is not None:
  681. gas = parse_gas(msg['payload'])
  682. if gas['action'] != GAS_INITIAL_REQUEST or dialog_token == gas['dialog_token']:
  683. raise Exception("Unexpected management frame")
  684. def test_gas_malformed_comeback_resp(dev, apdev):
  685. """GAS malformed comeback response frames"""
  686. hapd = start_ap(apdev[0])
  687. bssid = apdev[0]['bssid']
  688. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  689. hapd.set("ext_mgmt_frame_handling", "1")
  690. logger.debug("Non-zero status code in comeback response")
  691. query, dialog_token = init_gas(hapd, bssid, dev[0])
  692. resp = action_response(query)
  693. resp['payload'] = anqp_comeback_resp(dialog_token, status_code=2) + struct.pack('<H', 0)
  694. send_gas_resp(hapd, resp)
  695. expect_gas_result(dev[0], "FAILURE", status=2)
  696. logger.debug("Different advertisement protocol in comeback response")
  697. query, dialog_token = init_gas(hapd, bssid, dev[0])
  698. resp = action_response(query)
  699. resp['payload'] = anqp_comeback_resp(dialog_token, bogus_adv_proto=True) + struct.pack('<H', 0)
  700. send_gas_resp(hapd, resp)
  701. expect_gas_result(dev[0], "PEER_ERROR")
  702. logger.debug("Non-zero frag id and comeback delay in comeback response")
  703. query, dialog_token = init_gas(hapd, bssid, dev[0])
  704. resp = action_response(query)
  705. resp['payload'] = anqp_comeback_resp(dialog_token, id=1, comeback_delay=1) + struct.pack('<H', 0)
  706. send_gas_resp(hapd, resp)
  707. expect_gas_result(dev[0], "PEER_ERROR")
  708. logger.debug("Unexpected frag id in comeback response")
  709. query, dialog_token = init_gas(hapd, bssid, dev[0])
  710. resp = action_response(query)
  711. resp['payload'] = anqp_comeback_resp(dialog_token, id=1) + struct.pack('<H', 0)
  712. send_gas_resp(hapd, resp)
  713. expect_gas_result(dev[0], "PEER_ERROR")
  714. logger.debug("Empty fragment and replay in comeback response")
  715. query, dialog_token = init_gas(hapd, bssid, dev[0])
  716. resp = action_response(query)
  717. resp['payload'] = anqp_comeback_resp(dialog_token, more=True) + struct.pack('<H', 0)
  718. send_gas_resp(hapd, resp)
  719. query = gas_rx(hapd)
  720. gas = parse_gas(query['payload'])
  721. if gas['action'] != GAS_COMEBACK_REQUEST:
  722. raise Exception("Unexpected request action")
  723. if gas['dialog_token'] != dialog_token:
  724. raise Exception("Unexpected dialog token change")
  725. resp = action_response(query)
  726. resp['payload'] = anqp_comeback_resp(dialog_token) + struct.pack('<H', 0)
  727. send_gas_resp(hapd, resp)
  728. resp['payload'] = anqp_comeback_resp(dialog_token, id=1) + struct.pack('<H', 0)
  729. send_gas_resp(hapd, resp)
  730. expect_gas_result(dev[0], "SUCCESS")
  731. logger.debug("Unexpected initial response when waiting for comeback response")
  732. query, dialog_token = init_gas(hapd, bssid, dev[0])
  733. resp = action_response(query)
  734. resp['payload'] = anqp_initial_resp(dialog_token, 0) + struct.pack('<H', 0)
  735. send_gas_resp(hapd, resp)
  736. allow_gas_initial_req(hapd, dialog_token)
  737. expect_gas_result(dev[0], "TIMEOUT")
  738. logger.debug("Too short comeback response")
  739. query, dialog_token = init_gas(hapd, bssid, dev[0])
  740. resp = action_response(query)
  741. resp['payload'] = struct.pack('<BBBH', ACTION_CATEG_PUBLIC,
  742. GAS_COMEBACK_RESPONSE, dialog_token, 0)
  743. send_gas_resp(hapd, resp)
  744. allow_gas_initial_req(hapd, dialog_token)
  745. expect_gas_result(dev[0], "TIMEOUT")
  746. logger.debug("Too short comeback response(2)")
  747. query, dialog_token = init_gas(hapd, bssid, dev[0])
  748. resp = action_response(query)
  749. resp['payload'] = struct.pack('<BBBHBB', ACTION_CATEG_PUBLIC,
  750. GAS_COMEBACK_RESPONSE, dialog_token, 0, 0x80,
  751. 0)
  752. send_gas_resp(hapd, resp)
  753. allow_gas_initial_req(hapd, dialog_token)
  754. expect_gas_result(dev[0], "TIMEOUT")
  755. logger.debug("Maximum comeback response fragment claiming more fragments")
  756. query, dialog_token = init_gas(hapd, bssid, dev[0])
  757. resp = action_response(query)
  758. resp['payload'] = anqp_comeback_resp(dialog_token, more=True) + struct.pack('<H', 0)
  759. send_gas_resp(hapd, resp)
  760. for i in range(1, 129):
  761. query = gas_rx(hapd)
  762. gas = parse_gas(query['payload'])
  763. if gas['action'] != GAS_COMEBACK_REQUEST:
  764. raise Exception("Unexpected request action")
  765. if gas['dialog_token'] != dialog_token:
  766. raise Exception("Unexpected dialog token change")
  767. resp = action_response(query)
  768. resp['payload'] = anqp_comeback_resp(dialog_token, id=i, more=True) + struct.pack('<H', 0)
  769. send_gas_resp(hapd, resp)
  770. expect_gas_result(dev[0], "PEER_ERROR")
  771. def test_gas_comeback_resp_additional_delay(dev, apdev):
  772. """GAS comeback response requesting additional delay"""
  773. hapd = start_ap(apdev[0])
  774. bssid = apdev[0]['bssid']
  775. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  776. hapd.set("ext_mgmt_frame_handling", "1")
  777. query, dialog_token = init_gas(hapd, bssid, dev[0])
  778. for i in range(0, 2):
  779. resp = action_response(query)
  780. resp['payload'] = anqp_comeback_resp(dialog_token, status_code=95, comeback_delay=50) + struct.pack('<H', 0)
  781. send_gas_resp(hapd, resp)
  782. query = gas_rx(hapd)
  783. gas = parse_gas(query['payload'])
  784. if gas['action'] != GAS_COMEBACK_REQUEST:
  785. raise Exception("Unexpected request action")
  786. if gas['dialog_token'] != dialog_token:
  787. raise Exception("Unexpected dialog token change")
  788. resp = action_response(query)
  789. resp['payload'] = anqp_comeback_resp(dialog_token, status_code=0) + struct.pack('<H', 0)
  790. send_gas_resp(hapd, resp)
  791. expect_gas_result(dev[0], "SUCCESS")
  792. def test_gas_unknown_adv_proto(dev, apdev):
  793. """Unknown advertisement protocol id"""
  794. bssid = apdev[0]['bssid']
  795. params = hs20_ap_params()
  796. params['hessid'] = bssid
  797. hostapd.add_ap(apdev[0], params)
  798. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  799. req = dev[0].request("GAS_REQUEST " + bssid + " 42 000102000101")
  800. if "FAIL" in req:
  801. raise Exception("GAS query request rejected")
  802. expect_gas_result(dev[0], "FAILURE", "59")
  803. ev = dev[0].wait_event(["GAS-RESPONSE-INFO"], timeout=10)
  804. if ev is None:
  805. raise Exception("GAS query timed out")
  806. exp = r'<.>(GAS-RESPONSE-INFO) addr=([0-9a-f:]*) dialog_token=([0-9]*) status_code=([0-9]*) resp_len=([\-0-9]*)'
  807. res = re.split(exp, ev)
  808. if len(res) < 6:
  809. raise Exception("Could not parse GAS-RESPONSE-INFO")
  810. if res[2] != bssid:
  811. raise Exception("Unexpected BSSID in response")
  812. status = res[4]
  813. if status != "59":
  814. raise Exception("Unexpected GAS-RESPONSE-INFO status")
  815. def test_gas_request_oom(dev, apdev):
  816. """GAS_REQUEST OOM"""
  817. bssid = apdev[0]['bssid']
  818. params = hs20_ap_params()
  819. params['hessid'] = bssid
  820. hostapd.add_ap(apdev[0], params)
  821. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  822. with alloc_fail(dev[0], 1, "gas_build_req;gas_send_request"):
  823. if "FAIL" not in dev[0].request("GAS_REQUEST " + bssid + " 42"):
  824. raise Exception("GAS query request rejected")
  825. with alloc_fail(dev[0], 1, "gas_query_req;gas_send_request"):
  826. if "FAIL" not in dev[0].request("GAS_REQUEST " + bssid + " 42"):
  827. raise Exception("GAS query request rejected")
  828. with alloc_fail(dev[0], 1, "wpabuf_dup;gas_resp_cb"):
  829. if "OK" not in dev[0].request("GAS_REQUEST " + bssid + " 00 000102000101"):
  830. raise Exception("GAS query request rejected")
  831. ev = dev[0].wait_event(["GAS-RESPONSE-INFO"], timeout=10)
  832. if ev is None:
  833. raise Exception("No GAS response")
  834. if "status_code=0" not in ev:
  835. raise Exception("GAS response indicated a failure")
  836. def test_gas_max_pending(dev, apdev):
  837. """GAS and maximum pending query limit"""
  838. hapd = start_ap(apdev[0])
  839. hapd.set("gas_frag_limit", "50")
  840. bssid = apdev[0]['bssid']
  841. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  842. wpas.interface_add("wlan5")
  843. if "OK" not in wpas.request("P2P_SET listen_channel 1"):
  844. raise Exception("Failed to set listen channel")
  845. if "OK" not in wpas.p2p_listen():
  846. raise Exception("Failed to start listen state")
  847. if "FAIL" in wpas.request("SET ext_mgmt_frame_handling 1"):
  848. raise Exception("Failed to enable external management frame handling")
  849. anqp_query = struct.pack('<HHHHHHHHHH', 256, 16, 257, 258, 260, 261, 262, 263, 264, 268)
  850. gas = struct.pack('<H', len(anqp_query)) + anqp_query
  851. for dialog_token in range(1, 10):
  852. msg = struct.pack('<BBB', ACTION_CATEG_PUBLIC, GAS_INITIAL_REQUEST,
  853. dialog_token) + anqp_adv_proto() + gas
  854. req = "MGMT_TX {} {} freq=2412 wait_time=10 action={}".format(bssid, bssid, binascii.hexlify(msg))
  855. if "OK" not in wpas.request(req):
  856. raise Exception("Could not send management frame")
  857. resp = wpas.mgmt_rx()
  858. if resp is None:
  859. raise Exception("MGMT-RX timeout")
  860. if 'payload' not in resp:
  861. raise Exception("Missing payload")
  862. gresp = parse_gas(resp['payload'])
  863. if gresp['dialog_token'] != dialog_token:
  864. raise Exception("Dialog token mismatch")
  865. status_code = gresp['status_code']
  866. if dialog_token < 9 and status_code != 0:
  867. raise Exception("Unexpected failure status code {} for dialog token {}".format(status_code, dialog_token))
  868. if dialog_token > 8 and status_code == 0:
  869. raise Exception("Unexpected success status code {} for dialog token {}".format(status_code, dialog_token))
  870. def test_gas_no_pending(dev, apdev):
  871. """GAS and no pending query for comeback request"""
  872. hapd = start_ap(apdev[0])
  873. bssid = apdev[0]['bssid']
  874. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  875. wpas.interface_add("wlan5")
  876. if "OK" not in wpas.request("P2P_SET listen_channel 1"):
  877. raise Exception("Failed to set listen channel")
  878. if "OK" not in wpas.p2p_listen():
  879. raise Exception("Failed to start listen state")
  880. if "FAIL" in wpas.request("SET ext_mgmt_frame_handling 1"):
  881. raise Exception("Failed to enable external management frame handling")
  882. msg = struct.pack('<BBB', ACTION_CATEG_PUBLIC, GAS_COMEBACK_REQUEST, 1)
  883. req = "MGMT_TX {} {} freq=2412 wait_time=10 action={}".format(bssid, bssid, binascii.hexlify(msg))
  884. if "OK" not in wpas.request(req):
  885. raise Exception("Could not send management frame")
  886. resp = wpas.mgmt_rx()
  887. if resp is None:
  888. raise Exception("MGMT-RX timeout")
  889. if 'payload' not in resp:
  890. raise Exception("Missing payload")
  891. gresp = parse_gas(resp['payload'])
  892. status_code = gresp['status_code']
  893. if status_code != 60:
  894. raise Exception("Unexpected status code {} (expected 60)".format(status_code))
  895. def test_gas_delete_at_deinit(dev, apdev):
  896. """GAS query deleted at deinit"""
  897. hapd = start_ap(apdev[0])
  898. hapd.set("gas_comeback_delay", "1000")
  899. bssid = apdev[0]['bssid']
  900. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  901. wpas.interface_add("wlan5")
  902. wpas.scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True)
  903. wpas.request("ANQP_GET " + bssid + " 258")
  904. wpas.global_request("INTERFACE_REMOVE " + wpas.ifname)
  905. ev = wpas.wait_event(["GAS-QUERY-DONE"], timeout=2)
  906. del wpas
  907. if ev is None:
  908. raise Exception("GAS-QUERY-DONE not seen")
  909. if "result=DELETED_AT_DEINIT" not in ev:
  910. raise Exception("Unexpected result code: " + ev)
  911. def test_gas_missing_payload(dev, apdev):
  912. """No action code in the query frame"""
  913. bssid = apdev[0]['bssid']
  914. params = hs20_ap_params()
  915. params['hessid'] = bssid
  916. hostapd.add_ap(apdev[0], params)
  917. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  918. cmd = "MGMT_TX {} {} freq=2412 action=040A".format(bssid, bssid)
  919. if "FAIL" in dev[0].request(cmd):
  920. raise Exception("Could not send test Action frame")
  921. ev = dev[0].wait_event(["MGMT-TX-STATUS"], timeout=10)
  922. if ev is None:
  923. raise Exception("Timeout on MGMT-TX-STATUS")
  924. if "result=SUCCESS" not in ev:
  925. raise Exception("AP did not ack Action frame")
  926. cmd = "MGMT_TX {} {} freq=2412 action=04".format(bssid, bssid)
  927. if "FAIL" in dev[0].request(cmd):
  928. raise Exception("Could not send test Action frame")
  929. ev = dev[0].wait_event(["MGMT-TX-STATUS"], timeout=10)
  930. if ev is None:
  931. raise Exception("Timeout on MGMT-TX-STATUS")
  932. if "result=SUCCESS" not in ev:
  933. raise Exception("AP did not ack Action frame")
  934. def test_gas_query_deinit(dev, apdev):
  935. """Pending GAS/ANQP query during deinit"""
  936. hapd = start_ap(apdev[0])
  937. bssid = apdev[0]['bssid']
  938. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  939. wpas.interface_add("wlan5")
  940. wpas.scan_for_bss(bssid, freq="2412", force_scan=True)
  941. id = wpas.request("RADIO_WORK add block-work")
  942. if "OK" not in wpas.request("ANQP_GET " + bssid + " 258"):
  943. raise Exception("ANQP_GET command failed")
  944. ev = wpas.wait_event(["GAS-QUERY-START", "EXT-RADIO-WORK-START"], timeout=5)
  945. if ev is None:
  946. raise Exception("Timeout while waiting radio work to start")
  947. ev = wpas.wait_event(["GAS-QUERY-START", "EXT-RADIO-WORK-START"], timeout=5)
  948. if ev is None:
  949. raise Exception("Timeout while waiting radio work to start (2)")
  950. # Remove the interface while the gas-query radio work is still pending and
  951. # GAS query has not yet been started.
  952. wpas.interface_remove("wlan5")
  953. @remote_compatible
  954. def test_gas_anqp_oom_wpas(dev, apdev):
  955. """GAS/ANQP query and OOM in wpa_supplicant"""
  956. hapd = start_ap(apdev[0])
  957. bssid = apdev[0]['bssid']
  958. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  959. with alloc_fail(dev[0], 1, "wpa_bss_anqp_alloc"):
  960. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  961. raise Exception("ANQP_GET command failed")
  962. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=5)
  963. if ev is None:
  964. raise Exception("ANQP query did not complete")
  965. with alloc_fail(dev[0], 1, "gas_build_req"):
  966. if "FAIL" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  967. raise Exception("Unexpected ANQP_GET command success (OOM)")
  968. def test_gas_anqp_oom_hapd(dev, apdev):
  969. """GAS/ANQP query and OOM in hostapd"""
  970. hapd = start_ap(apdev[0])
  971. bssid = apdev[0]['bssid']
  972. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  973. with alloc_fail(hapd, 1, "gas_build_resp"):
  974. # This query will time out due to the AP not sending a response (OOM).
  975. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  976. raise Exception("ANQP_GET command failed")
  977. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  978. if ev is None:
  979. raise Exception("GAS query start timed out")
  980. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  981. if ev is None:
  982. raise Exception("GAS query timed out")
  983. if "result=TIMEOUT" not in ev:
  984. raise Exception("Unexpected result: " + ev)
  985. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=10)
  986. if ev is None:
  987. raise Exception("ANQP-QUERY-DONE event not seen")
  988. if "result=FAILURE" not in ev:
  989. raise Exception("Unexpected result: " + ev)
  990. with alloc_fail(hapd, 1, "gas_anqp_build_comeback_resp"):
  991. hapd.set("gas_frag_limit", "50")
  992. # The first attempt of this query will time out due to the AP not
  993. # sending a response (OOM), but the retry succeeds.
  994. dev[0].request("FETCH_ANQP")
  995. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  996. if ev is None:
  997. raise Exception("GAS query start timed out")
  998. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  999. if ev is None:
  1000. raise Exception("GAS query timed out")
  1001. if "result=SUCCESS" not in ev:
  1002. raise Exception("Unexpected result: " + ev)
  1003. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=10)
  1004. if ev is None:
  1005. raise Exception("ANQP-QUERY-DONE event not seen")
  1006. if "result=SUCCESS" not in ev:
  1007. raise Exception("Unexpected result: " + ev)
  1008. def test_gas_anqp_extra_elements(dev, apdev):
  1009. """GAS/ANQP and extra ANQP elements"""
  1010. geo_loc = "001052834d12efd2b08b9b4bf1cc2c00004104050000000000060100"
  1011. civic_loc = "0000f9555302f50102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5"
  1012. held_uri = "https://held.example.com/location"
  1013. held = struct.pack('BBB', 0, 1 + len(held_uri), 1) + held_uri
  1014. supl_fqdn = "supl.example.com"
  1015. supl = struct.pack('BBB', 0, 1 + len(supl_fqdn), 1) + supl_fqdn
  1016. public_id = binascii.hexlify(held + supl)
  1017. params = { "ssid": "gas/anqp",
  1018. "interworking": "1",
  1019. "anqp_elem": [ "265:" + geo_loc,
  1020. "266:" + civic_loc,
  1021. "262:1122334455",
  1022. "267:" + public_id,
  1023. "279:01020304",
  1024. "60000:01",
  1025. "299:0102" ] }
  1026. hapd = hostapd.add_ap(apdev[0], params)
  1027. bssid = apdev[0]['bssid']
  1028. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  1029. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 265,266"):
  1030. raise Exception("ANQP_GET command failed")
  1031. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  1032. if ev is None:
  1033. raise Exception("GAS query timed out")
  1034. bss = dev[0].get_bss(bssid)
  1035. if 'anqp[265]' not in bss:
  1036. raise Exception("AP Geospatial Location ANQP-element not seen")
  1037. if bss['anqp[265]'] != geo_loc:
  1038. raise Exception("Unexpected AP Geospatial Location ANQP-element value: " + bss['anqp[265]'])
  1039. if 'anqp[266]' not in bss:
  1040. raise Exception("AP Civic Location ANQP-element not seen")
  1041. if bss['anqp[266]'] != civic_loc:
  1042. raise Exception("Unexpected AP Civic Location ANQP-element value: " + bss['anqp[266]'])
  1043. dev[1].scan_for_bss(bssid, freq="2412", force_scan=True)
  1044. 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"):
  1045. raise Exception("ANQP_GET command failed")
  1046. ev = dev[1].wait_event(["GAS-QUERY-DONE"], timeout=10)
  1047. if ev is None:
  1048. raise Exception("GAS query timed out")
  1049. bss = dev[1].get_bss(bssid)
  1050. if 'anqp[265]' not in bss:
  1051. raise Exception("AP Geospatial Location ANQP-element not seen")
  1052. if bss['anqp[265]'] != geo_loc:
  1053. raise Exception("Unexpected AP Geospatial Location ANQP-element value: " + bss['anqp[265]'])
  1054. if 'anqp[266]' in bss:
  1055. raise Exception("AP Civic Location ANQP-element unexpectedly seen")
  1056. if 'anqp[267]' not in bss:
  1057. raise Exception("AP Location Public Identifier ANQP-element not seen")
  1058. if bss['anqp[267]'] != public_id:
  1059. raise Exception("Unexpected AP Location Public Identifier ANQP-element value: " + bss['anqp[267]'])
  1060. if 'anqp[279]' not in bss:
  1061. raise Exception("ANQP-element Info ID 279 not seen")
  1062. if bss['anqp[279]'] != "01020304":
  1063. raise Exception("Unexpected AP ANQP-element Info ID 279 value: " + bss['anqp[279]'])
  1064. if 'anqp[299]' not in bss:
  1065. raise Exception("ANQP-element Info ID 299 not seen")
  1066. if bss['anqp[299]'] != "0102":
  1067. raise Exception("Unexpected AP ANQP-element Info ID 299 value: " + bss['anqp[299]'])
  1068. if 'anqp_ip_addr_type_availability' not in bss:
  1069. raise Exception("ANQP-element Info ID 292 not seen")
  1070. if bss['anqp_ip_addr_type_availability'] != "1122334455":
  1071. raise Exception("Unexpected AP ANQP-element Info ID 262 value: " + bss['anqp_ip_addr_type_availability'])
  1072. def test_gas_anqp_address3_not_assoc(dev, apdev, params):
  1073. """GAS/ANQP query using IEEE 802.11 compliant Address 3 value when not associated"""
  1074. try:
  1075. _test_gas_anqp_address3_not_assoc(dev, apdev, params)
  1076. finally:
  1077. dev[0].request("SET gas_address3 0")
  1078. def _test_gas_anqp_address3_not_assoc(dev, apdev, params):
  1079. hapd = start_ap(apdev[0])
  1080. bssid = apdev[0]['bssid']
  1081. if "OK" not in dev[0].request("SET gas_address3 1"):
  1082. raise Exception("Failed to set gas_address3")
  1083. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  1084. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  1085. raise Exception("ANQP_GET command failed")
  1086. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  1087. if ev is None:
  1088. raise Exception("GAS query start timed out")
  1089. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  1090. if ev is None:
  1091. raise Exception("GAS query timed out")
  1092. ev = dev[0].wait_event(["RX-ANQP"], timeout=1)
  1093. if ev is None or "Venue Name" not in ev:
  1094. raise Exception("Did not receive Venue Name")
  1095. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=10)
  1096. if ev is None:
  1097. raise Exception("ANQP-QUERY-DONE event not seen")
  1098. if "result=SUCCESS" not in ev:
  1099. raise Exception("Unexpected result: " + ev)
  1100. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  1101. "wlan_mgt.fixed.category_code == 4 && (wlan_mgt.fixed.publicact == 0x0a || wlan_mgt.fixed.publicact == 0x0b)",
  1102. display=["wlan.bssid"])
  1103. res = out.splitlines()
  1104. if len(res) != 2:
  1105. raise Exception("Unexpected number of GAS frames")
  1106. if res[0] != 'ff:ff:ff:ff:ff:ff':
  1107. raise Exception("GAS request used unexpected Address3 field value: " + res[0])
  1108. if res[1] != 'ff:ff:ff:ff:ff:ff':
  1109. raise Exception("GAS response used unexpected Address3 field value: " + res[1])
  1110. def test_gas_anqp_address3_assoc(dev, apdev, params):
  1111. """GAS/ANQP query using IEEE 802.11 compliant Address 3 value when associated"""
  1112. try:
  1113. _test_gas_anqp_address3_assoc(dev, apdev, params)
  1114. finally:
  1115. dev[0].request("SET gas_address3 0")
  1116. def _test_gas_anqp_address3_assoc(dev, apdev, params):
  1117. hapd = start_ap(apdev[0])
  1118. bssid = apdev[0]['bssid']
  1119. if "OK" not in dev[0].request("SET gas_address3 1"):
  1120. raise Exception("Failed to set gas_address3")
  1121. dev[0].scan_for_bss(bssid, freq="2412")
  1122. dev[0].connect("test-gas", key_mgmt="WPA-EAP", eap="TTLS",
  1123. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1124. password="password", phase2="auth=MSCHAPV2",
  1125. ca_cert="auth_serv/ca.pem", scan_freq="2412")
  1126. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  1127. raise Exception("ANQP_GET command failed")
  1128. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  1129. if ev is None:
  1130. raise Exception("GAS query start timed out")
  1131. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  1132. if ev is None:
  1133. raise Exception("GAS query timed out")
  1134. ev = dev[0].wait_event(["RX-ANQP"], timeout=1)
  1135. if ev is None or "Venue Name" not in ev:
  1136. raise Exception("Did not receive Venue Name")
  1137. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=10)
  1138. if ev is None:
  1139. raise Exception("ANQP-QUERY-DONE event not seen")
  1140. if "result=SUCCESS" not in ev:
  1141. raise Exception("Unexpected result: " + ev)
  1142. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  1143. "wlan_mgt.fixed.category_code == 4 && (wlan_mgt.fixed.publicact == 0x0a || wlan_mgt.fixed.publicact == 0x0b)",
  1144. display=["wlan.bssid"])
  1145. res = out.splitlines()
  1146. if len(res) != 2:
  1147. raise Exception("Unexpected number of GAS frames")
  1148. if res[0] != bssid:
  1149. raise Exception("GAS request used unexpected Address3 field value: " + res[0])
  1150. if res[1] != bssid:
  1151. raise Exception("GAS response used unexpected Address3 field value: " + res[1])
  1152. def test_gas_anqp_address3_ap_forced(dev, apdev, params):
  1153. """GAS/ANQP query using IEEE 802.11 compliant Address 3 value on AP"""
  1154. hapd = start_ap(apdev[0])
  1155. bssid = apdev[0]['bssid']
  1156. hapd.set("gas_address3", "1")
  1157. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  1158. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  1159. raise Exception("ANQP_GET command failed")
  1160. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  1161. if ev is None:
  1162. raise Exception("GAS query start timed out")
  1163. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  1164. if ev is None:
  1165. raise Exception("GAS query timed out")
  1166. ev = dev[0].wait_event(["RX-ANQP"], timeout=1)
  1167. if ev is None or "Venue Name" not in ev:
  1168. raise Exception("Did not receive Venue Name")
  1169. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=10)
  1170. if ev is None:
  1171. raise Exception("ANQP-QUERY-DONE event not seen")
  1172. if "result=SUCCESS" not in ev:
  1173. raise Exception("Unexpected result: " + ev)
  1174. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  1175. "wlan_mgt.fixed.category_code == 4 && (wlan_mgt.fixed.publicact == 0x0a || wlan_mgt.fixed.publicact == 0x0b)",
  1176. display=["wlan.bssid"])
  1177. res = out.splitlines()
  1178. if len(res) != 2:
  1179. raise Exception("Unexpected number of GAS frames")
  1180. if res[0] != bssid:
  1181. raise Exception("GAS request used unexpected Address3 field value: " + res[0])
  1182. if res[1] != 'ff:ff:ff:ff:ff:ff':
  1183. raise Exception("GAS response used unexpected Address3 field value: " + res[1])
  1184. def test_gas_anqp_address3_ap_non_compliant(dev, apdev, params):
  1185. """GAS/ANQP query using IEEE 802.11 non-compliant Address 3 (AP)"""
  1186. try:
  1187. _test_gas_anqp_address3_ap_non_compliant(dev, apdev, params)
  1188. finally:
  1189. dev[0].request("SET gas_address3 0")
  1190. def _test_gas_anqp_address3_ap_non_compliant(dev, apdev, params):
  1191. hapd = start_ap(apdev[0])
  1192. bssid = apdev[0]['bssid']
  1193. hapd.set("gas_address3", "2")
  1194. if "OK" not in dev[0].request("SET gas_address3 1"):
  1195. raise Exception("Failed to set gas_address3")
  1196. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  1197. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  1198. raise Exception("ANQP_GET command failed")
  1199. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  1200. if ev is None:
  1201. raise Exception("GAS query start timed out")
  1202. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  1203. if ev is None:
  1204. raise Exception("GAS query timed out")
  1205. ev = dev[0].wait_event(["RX-ANQP"], timeout=1)
  1206. if ev is None or "Venue Name" not in ev:
  1207. raise Exception("Did not receive Venue Name")
  1208. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=10)
  1209. if ev is None:
  1210. raise Exception("ANQP-QUERY-DONE event not seen")
  1211. if "result=SUCCESS" not in ev:
  1212. raise Exception("Unexpected result: " + ev)
  1213. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  1214. "wlan_mgt.fixed.category_code == 4 && (wlan_mgt.fixed.publicact == 0x0a || wlan_mgt.fixed.publicact == 0x0b)",
  1215. display=["wlan.bssid"])
  1216. res = out.splitlines()
  1217. if len(res) != 2:
  1218. raise Exception("Unexpected number of GAS frames")
  1219. if res[0] != 'ff:ff:ff:ff:ff:ff':
  1220. raise Exception("GAS request used unexpected Address3 field value: " + res[0])
  1221. if res[1] != bssid:
  1222. raise Exception("GAS response used unexpected Address3 field value: " + res[1])
  1223. def test_gas_anqp_address3_pmf(dev, apdev):
  1224. """GAS/ANQP query using IEEE 802.11 compliant Address 3 value with PMF"""
  1225. try:
  1226. _test_gas_anqp_address3_pmf(dev, apdev)
  1227. finally:
  1228. dev[0].request("SET gas_address3 0")
  1229. def _test_gas_anqp_address3_pmf(dev, apdev):
  1230. hapd = start_ap(apdev[0])
  1231. bssid = apdev[0]['bssid']
  1232. hapd.set("gas_comeback_delay", "2")
  1233. hapd.set("gas_address3", "1")
  1234. if "OK" not in dev[0].request("SET gas_address3 1"):
  1235. raise Exception("Failed to set gas_address3")
  1236. dev[0].scan_for_bss(bssid, freq="2412")
  1237. dev[0].connect("test-gas", key_mgmt="WPA-EAP", eap="TTLS",
  1238. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1239. password="password", phase2="auth=MSCHAPV2",
  1240. ca_cert="auth_serv/ca.pem", scan_freq="2412",
  1241. ieee80211w="2")
  1242. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  1243. raise Exception("ANQP_GET command failed")
  1244. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  1245. if ev is None:
  1246. raise Exception("GAS query start timed out")
  1247. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  1248. if ev is None:
  1249. raise Exception("GAS query timed out")
  1250. ev = dev[0].wait_event(["RX-ANQP"], timeout=1)
  1251. if ev is None or "Venue Name" not in ev:
  1252. raise Exception("Did not receive Venue Name")
  1253. ev = dev[0].wait_event(["ANQP-QUERY-DONE"], timeout=10)
  1254. if ev is None:
  1255. raise Exception("ANQP-QUERY-DONE event not seen")
  1256. if "result=SUCCESS" not in ev:
  1257. raise Exception("Unexpected result: " + ev)
  1258. req = dev[0].request("GAS_REQUEST " + bssid + " 42 000102000101")
  1259. if "FAIL" in req:
  1260. raise Exception("GAS query request rejected")
  1261. expect_gas_result(dev[0], "FAILURE", "59")
  1262. def test_gas_prot_vs_not_prot(dev, apdev, params):
  1263. """GAS/ANQP query protected vs. not protected"""
  1264. hapd = start_ap(apdev[0])
  1265. bssid = apdev[0]['bssid']
  1266. dev[0].scan_for_bss(bssid, freq="2412")
  1267. dev[0].connect("test-gas", key_mgmt="WPA-EAP", eap="TTLS",
  1268. identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
  1269. password="password", phase2="auth=MSCHAPV2",
  1270. ca_cert="auth_serv/ca.pem", scan_freq="2412",
  1271. ieee80211w="2")
  1272. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  1273. raise Exception("ANQP_GET command failed")
  1274. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=5)
  1275. if ev is None:
  1276. raise Exception("No GAS-QUERY-DONE event")
  1277. if "result=SUCCESS" not in ev:
  1278. raise Exception("Unexpected GAS result: " + ev)
  1279. # GAS: Drop unexpected unprotected GAS frame when PMF is enabled
  1280. dev[0].request("SET ext_mgmt_frame_handling 1")
  1281. res = dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=d0003a010200000000000200000003000200000003001000040b00000005006c027f000000")
  1282. dev[0].request("SET ext_mgmt_frame_handling 0")
  1283. if "OK" not in res:
  1284. raise Exception("MGMT_RX_PROCESS failed")
  1285. dev[0].request("DISCONNECT")
  1286. dev[0].wait_disconnected()
  1287. # GAS: No pending query found for 02:00:00:00:03:00 dialog token 0
  1288. dev[0].request("SET ext_mgmt_frame_handling 1")
  1289. res = dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=d0003a010200000000000200000003000200000003001000040b00000005006c027f000000")
  1290. dev[0].request("SET ext_mgmt_frame_handling 0")
  1291. if "OK" not in res:
  1292. raise Exception("MGMT_RX_PROCESS failed")
  1293. # GAS: Drop unexpected protected GAS frame when PMF is disabled
  1294. dev[0].request("SET ext_mgmt_frame_handling 1")
  1295. res = dev[0].request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=d0003a010200000000000200000003000200000003001000090b00000005006c027f000000")
  1296. dev[0].request("SET ext_mgmt_frame_handling 0")
  1297. if "OK" not in res:
  1298. raise Exception("MGMT_RX_PROCESS failed")
  1299. def test_gas_failures(dev, apdev):
  1300. """GAS failure cases"""
  1301. hapd = start_ap(apdev[0])
  1302. hapd.set("gas_comeback_delay", "5")
  1303. bssid = apdev[0]['bssid']
  1304. hapd2 = start_ap(apdev[1])
  1305. bssid2 = apdev[1]['bssid']
  1306. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  1307. dev[0].scan_for_bss(bssid2, freq="2412")
  1308. tests = [ (bssid, "gas_build_req;gas_query_tx_comeback_req"),
  1309. (bssid, "gas_query_tx;gas_query_tx_comeback_req"),
  1310. (bssid, "gas_query_append;gas_query_rx_comeback"),
  1311. (bssid2, "gas_query_append;gas_query_rx_initial"),
  1312. (bssid2, "wpabuf_alloc_copy;gas_query_rx_initial"),
  1313. (bssid, "gas_query_tx;gas_query_tx_initial_req") ]
  1314. for addr,func in tests:
  1315. with alloc_fail(dev[0], 1, func):
  1316. dev[0].request("ANQP_GET " + addr + " 258")
  1317. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=5)
  1318. if ev is None:
  1319. raise Exception("No GAS-QUERY-DONE seen")
  1320. if "result=INTERNAL_ERROR" not in ev:
  1321. raise Exception("Unexpected result code: " + ev)
  1322. dev[0].dump_monitor()
  1323. tests = [ "=gas_query_req", "radio_add_work;gas_query_req" ]
  1324. for func in tests:
  1325. with alloc_fail(dev[0], 1, func):
  1326. if "FAIL" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  1327. raise Exception("ANQP_GET succeeded unexpectedly during OOM")
  1328. dev[0].dump_monitor()
  1329. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  1330. wpas.interface_add("wlan5")
  1331. wpas.scan_for_bss(bssid2, freq="2412")
  1332. wpas.request("SET preassoc_mac_addr 1111")
  1333. wpas.request("ANQP_GET " + bssid2 + " 258")
  1334. ev = wpas.wait_event(["Failed to assign random MAC address for GAS"],
  1335. timeout=5)
  1336. wpas.request("SET preassoc_mac_addr 0")
  1337. if ev is None:
  1338. raise Exception("No random MAC address error seen")
  1339. def test_gas_anqp_venue_url(dev, apdev):
  1340. """GAS/ANQP and Venue URL"""
  1341. venue_group = 1
  1342. venue_type = 13
  1343. venue_info = struct.pack('BB', venue_group, venue_type)
  1344. lang1 = "eng"
  1345. name1= "Example venue"
  1346. lang2 = "fin"
  1347. name2 = "Esimerkkipaikka"
  1348. venue1 = struct.pack('B', len(lang1 + name1)) + lang1 + name1
  1349. venue2 = struct.pack('B', len(lang2 + name2)) + lang2 + name2
  1350. venue_name = binascii.hexlify(venue_info + venue1 + venue2)
  1351. url1 = "http://example.com/venue"
  1352. url2 = "https://example.org/venue-info/"
  1353. duple1 = struct.pack('BB', 1 + len(url1), 1) + url1
  1354. duple2 = struct.pack('BB', 1 + len(url2), 2) + url2
  1355. venue_url = binascii.hexlify(duple1 + duple2)
  1356. params = { "ssid": "gas/anqp",
  1357. "interworking": "1",
  1358. "venue_group": str(venue_group),
  1359. "venue_type": str(venue_type),
  1360. "venue_name": [ lang1 + ":" + name1, lang2 + ":" + name2 ],
  1361. "anqp_elem": [ "277:" + venue_url ] }
  1362. hapd = hostapd.add_ap(apdev[0], params)
  1363. bssid = apdev[0]['bssid']
  1364. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  1365. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 257,258,277"):
  1366. raise Exception("ANQP_GET command failed")
  1367. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  1368. if ev is None:
  1369. raise Exception("GAS query timed out")
  1370. bss = dev[0].get_bss(bssid)
  1371. if 'anqp_venue_name' not in bss:
  1372. raise Exception("Venue Name ANQP-element not seen")
  1373. if bss['anqp_venue_name'] != venue_name:
  1374. raise Exception("Unexpected Venue Name ANQP-element value: " + bss['anqp_venue_name'])
  1375. if 'anqp[277]' not in bss:
  1376. raise Exception("Venue URL ANQP-element not seen")
  1377. if bss['anqp[277]'] != venue_url:
  1378. raise Exception("Unexpected Venue URL ANQP-element value: " + bss['anqp[277]'])
  1379. if 'anqp_capability_list' not in bss:
  1380. raise Exception("Capability List ANQP-element not seen")
  1381. ids = struct.pack('<HHH', 257, 258, 277)
  1382. if not bss['anqp_capability_list'].startswith(binascii.hexlify(ids)):
  1383. raise Exception("Unexpected Capability List ANQP-element value: " + bss['anqp_capability_list'])
  1384. def test_gas_anqp_venue_url2(dev, apdev):
  1385. """GAS/ANQP and Venue URL (hostapd venue_url)"""
  1386. venue_group = 1
  1387. venue_type = 13
  1388. venue_info = struct.pack('BB', venue_group, venue_type)
  1389. lang1 = "eng"
  1390. name1= "Example venue"
  1391. lang2 = "fin"
  1392. name2 = "Esimerkkipaikka"
  1393. venue1 = struct.pack('B', len(lang1 + name1)) + lang1 + name1
  1394. venue2 = struct.pack('B', len(lang2 + name2)) + lang2 + name2
  1395. venue_name = binascii.hexlify(venue_info + venue1 + venue2)
  1396. url1 = "http://example.com/venue"
  1397. url2 = "https://example.org/venue-info/"
  1398. duple1 = struct.pack('BB', 1 + len(url1), 1) + url1
  1399. duple2 = struct.pack('BB', 1 + len(url2), 2) + url2
  1400. venue_url = binascii.hexlify(duple1 + duple2)
  1401. params = { "ssid": "gas/anqp",
  1402. "interworking": "1",
  1403. "venue_group": str(venue_group),
  1404. "venue_type": str(venue_type),
  1405. "venue_name": [ lang1 + ":" + name1, lang2 + ":" + name2 ],
  1406. "venue_url": [ "1:" + url1, "2:" + url2 ] }
  1407. hapd = hostapd.add_ap(apdev[0], params)
  1408. bssid = apdev[0]['bssid']
  1409. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  1410. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 257,258,277"):
  1411. raise Exception("ANQP_GET command failed")
  1412. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  1413. if ev is None:
  1414. raise Exception("GAS query timed out")
  1415. bss = dev[0].get_bss(bssid)
  1416. if 'anqp_venue_name' not in bss:
  1417. raise Exception("Venue Name ANQP-element not seen")
  1418. if bss['anqp_venue_name'] != venue_name:
  1419. raise Exception("Unexpected Venue Name ANQP-element value: " + bss['anqp_venue_name'])
  1420. if 'anqp[277]' not in bss:
  1421. raise Exception("Venue URL ANQP-element not seen")
  1422. if bss['anqp[277]'] != venue_url:
  1423. print venue_url
  1424. raise Exception("Unexpected Venue URL ANQP-element value: " + bss['anqp[277]'])
  1425. if 'anqp_capability_list' not in bss:
  1426. raise Exception("Capability List ANQP-element not seen")
  1427. ids = struct.pack('<HHH', 257, 258, 277)
  1428. if not bss['anqp_capability_list'].startswith(binascii.hexlify(ids)):
  1429. raise Exception("Unexpected Capability List ANQP-element value: " + bss['anqp_capability_list'])
  1430. def test_gas_anqp_capab_list(dev, apdev):
  1431. """GAS/ANQP and Capability List ANQP-element"""
  1432. params = { "ssid": "gas/anqp",
  1433. "interworking": "1" }
  1434. params["anqp_elem"] = []
  1435. for i in range(0, 400):
  1436. if i not in [ 257 ]:
  1437. params["anqp_elem"] += [ "%d:010203" % i ]
  1438. hapd = hostapd.add_ap(apdev[0], params)
  1439. bssid = apdev[0]['bssid']
  1440. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  1441. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 257"):
  1442. raise Exception("ANQP_GET command failed")
  1443. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  1444. if ev is None:
  1445. raise Exception("GAS query timed out")
  1446. bss = dev[0].get_bss(bssid)
  1447. if 'anqp_capability_list' not in bss:
  1448. raise Exception("Capability List ANQP-element not seen")
  1449. val = bss['anqp_capability_list']
  1450. logger.info("anqp_capability_list: " + val)
  1451. ids = []
  1452. while len(val) >= 4:
  1453. id_bin = binascii.unhexlify(val[0:4])
  1454. id = struct.unpack('<H', id_bin)[0]
  1455. if id == 0xdddd:
  1456. break
  1457. ids.append(id)
  1458. val = val[4:]
  1459. logger.info("InfoIDs: " + str(ids))
  1460. for i in range(257, 300):
  1461. if i in [ 273, 274 ]:
  1462. continue
  1463. if i not in ids:
  1464. raise Exception("Unexpected Capability List ANQP-element value (missing %d): %s" % (i, bss['anqp_capability_list']))
  1465. def test_gas_server_oom(dev, apdev):
  1466. """GAS server OOM"""
  1467. bssid = apdev[0]['bssid']
  1468. params = hs20_ap_params()
  1469. params['hessid'] = bssid
  1470. params['gas_comeback_delay'] = "5"
  1471. hapd = hostapd.add_ap(apdev[0], params)
  1472. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  1473. tests = [ "ap_sta_add;gas_dialog_create",
  1474. "=gas_dialog_create",
  1475. "wpabuf_alloc_copy;gas_serv_rx_gas_comeback_req" ]
  1476. for t in tests:
  1477. with alloc_fail(hapd, 1, t):
  1478. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  1479. raise Exception("ANQP_GET command failed")
  1480. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=5)
  1481. if ev is None:
  1482. raise Exception("No GAS-QUERY-DONE seen")
  1483. dev[0].dump_monitor()
  1484. hapd.set("gas_comeback_delay", "0")
  1485. tests = [ "gas_serv_build_gas_resp_payload" ]
  1486. for t in tests:
  1487. with alloc_fail(hapd, 1, t):
  1488. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258"):
  1489. raise Exception("ANQP_GET command failed")
  1490. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=5)
  1491. if ev is None:
  1492. raise Exception("No GAS-QUERY-DONE seen")
  1493. dev[0].dump_monitor()
  1494. with alloc_fail(hapd, 1,
  1495. "gas_build_initial_resp;gas_serv_rx_gas_initial_req"):
  1496. req = dev[0].request("GAS_REQUEST " + bssid + " 42 000102000101")
  1497. if "FAIL" in req:
  1498. raise Exception("GAS query request rejected")
  1499. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=5)
  1500. if ev is None:
  1501. raise Exception("No GAS-QUERY-DONE seen")
  1502. dev[0].dump_monitor()
  1503. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  1504. wpas.interface_add("wlan5")
  1505. if "OK" not in wpas.request("P2P_SET listen_channel 1"):
  1506. raise Exception("Failed to set listen channel")
  1507. if "OK" not in wpas.p2p_listen():
  1508. raise Exception("Failed to start listen state")
  1509. if "FAIL" in wpas.request("SET ext_mgmt_frame_handling 1"):
  1510. raise Exception("Failed to enable external management frame handling")
  1511. msg = struct.pack('<BBB', ACTION_CATEG_PUBLIC, GAS_COMEBACK_REQUEST, 1)
  1512. req = "MGMT_TX {} {} freq=2412 wait_time=10 action={}".format(bssid, bssid, binascii.hexlify(msg))
  1513. with alloc_fail(hapd, 1,
  1514. "gas_anqp_build_comeback_resp_buf;gas_serv_rx_gas_comeback_req"):
  1515. if "OK" not in wpas.request(req):
  1516. raise Exception("Could not send management frame")
  1517. wait_fail_trigger(hapd, "GET_ALLOC_FAIL")
  1518. def test_gas_anqp_overrides(dev, apdev):
  1519. """GAS and ANQP overrides"""
  1520. params = { "ssid": "gas/anqp",
  1521. "interworking": "1",
  1522. "anqp_elem": [ "257:111111",
  1523. "258:222222",
  1524. "260:333333",
  1525. "261:444444",
  1526. "262:555555",
  1527. "263:666666",
  1528. "264:777777",
  1529. "268:888888",
  1530. "275:999999" ] }
  1531. hapd = hostapd.add_ap(apdev[0], params)
  1532. bssid = apdev[0]['bssid']
  1533. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  1534. if "OK" not in dev[0].request("ANQP_GET " + bssid + " 257,258,260,261,262,263,264,268,275"):
  1535. raise Exception("ANQP_GET command failed")
  1536. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
  1537. if ev is None:
  1538. raise Exception("GAS query timed out")
  1539. elems = 9
  1540. capa = dev[0].get_capability("fils")
  1541. if capa is None or "FILS" not in capa:
  1542. # FILS Realm Info not supported in the build
  1543. elems -= 1
  1544. for i in range(elems):
  1545. ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
  1546. if ev is None:
  1547. raise Exception("ANQP response not seen")
  1548. def test_gas_no_dialog_token_match(dev, apdev):
  1549. """GAS and no dialog token match for comeback request"""
  1550. hapd = start_ap(apdev[0])
  1551. hapd.set("gas_frag_limit", "50")
  1552. bssid = apdev[0]['bssid']
  1553. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  1554. wpas.interface_add("wlan5")
  1555. if "OK" not in wpas.request("P2P_SET listen_channel 1"):
  1556. raise Exception("Failed to set listen channel")
  1557. if "OK" not in wpas.p2p_listen():
  1558. raise Exception("Failed to start listen state")
  1559. if "FAIL" in wpas.request("SET ext_mgmt_frame_handling 1"):
  1560. raise Exception("Failed to enable external management frame handling")
  1561. anqp_query = struct.pack('<HHHHHHHHHH', 256, 16, 257, 258, 260, 261, 262, 263, 264, 268)
  1562. gas = struct.pack('<H', len(anqp_query)) + anqp_query
  1563. dialog_token = 100
  1564. msg = struct.pack('<BBB', ACTION_CATEG_PUBLIC, GAS_INITIAL_REQUEST,
  1565. dialog_token) + anqp_adv_proto() + gas
  1566. req = "MGMT_TX {} {} freq=2412 wait_time=10 action={}".format(bssid, bssid, binascii.hexlify(msg))
  1567. if "OK" not in wpas.request(req):
  1568. raise Exception("Could not send management frame")
  1569. resp = wpas.mgmt_rx()
  1570. if resp is None:
  1571. raise Exception("MGMT-RX timeout")
  1572. if 'payload' not in resp:
  1573. raise Exception("Missing payload")
  1574. gresp = parse_gas(resp['payload'])
  1575. if gresp['dialog_token'] != dialog_token:
  1576. raise Exception("Dialog token mismatch")
  1577. status_code = gresp['status_code']
  1578. if status_code != 0:
  1579. raise Exception("Unexpected status code {}".format(status_code))
  1580. msg = struct.pack('<BBB', ACTION_CATEG_PUBLIC, GAS_COMEBACK_REQUEST,
  1581. dialog_token + 1)
  1582. req = "MGMT_TX {} {} freq=2412 wait_time=10 action={}".format(bssid, bssid, binascii.hexlify(msg))
  1583. if "OK" not in wpas.request(req):
  1584. raise Exception("Could not send management frame")
  1585. resp = wpas.mgmt_rx()
  1586. if resp is None:
  1587. raise Exception("MGMT-RX timeout")
  1588. if 'payload' not in resp:
  1589. raise Exception("Missing payload")
  1590. gresp = parse_gas(resp['payload'])
  1591. status_code = gresp['status_code']
  1592. if status_code != 60:
  1593. raise Exception("Unexpected failure status code {}".format(status_code))
  1594. def test_gas_vendor_spec_errors(dev, apdev):
  1595. """GAS and vendor specific request error cases"""
  1596. bssid = apdev[0]['bssid']
  1597. params = hs20_ap_params()
  1598. params['hessid'] = bssid
  1599. params['osu_server_uri'] = "uri"
  1600. params['hs20_icon'] = "32:32:eng:image/png:icon32:/tmp/icon32.png"
  1601. del params['nai_realm']
  1602. hapd = hostapd.add_ap(apdev[0], params)
  1603. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  1604. tests = [ "00 12340000",
  1605. "00 dddd0300506fff",
  1606. "00 dddd0400506fffff",
  1607. "00 dddd0400506f9aff",
  1608. "00 dddd0400506f9a11",
  1609. "00 dddd0600506f9a11ff00",
  1610. "00 dddd0600506f9a110600",
  1611. "00 dddd0600506f9a110600",
  1612. "00 dddd0700506f9a11060000",
  1613. "00 dddd0700506f9a110600ff",
  1614. "00 dddd0800506f9a110600ff00",
  1615. "00 dddd0900506f9a110600ff0000",
  1616. "00 dddd0900506f9a110600ff0001",
  1617. "00 dddd0900506f9a110600ffff00",
  1618. "00 dddd0a00506f9a110600ff00013b",
  1619. "00 dddd0700506f9a110100ff",
  1620. "00 dddd0700506f9a11010008",
  1621. "00 dddd14",
  1622. "00 dddd1400506f9a11" ]
  1623. for t in tests:
  1624. req = dev[0].request("GAS_REQUEST " + bssid + " " + t)
  1625. if "FAIL" in req:
  1626. raise Exception("GAS query request rejected")
  1627. ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
  1628. if ev is None:
  1629. raise Exception("GAS query did not start")
  1630. ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=5)
  1631. if ev is None:
  1632. raise Exception("GAS query did not complete")
  1633. if t == "00 dddd0600506f9a110600":
  1634. hapd.set("nai_realm", "0,another.example.com")
  1635. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  1636. wpas.interface_add("wlan5")
  1637. if "OK" not in wpas.request("P2P_SET listen_channel 1"):
  1638. raise Exception("Failed to set listen channel")
  1639. if "OK" not in wpas.p2p_listen():
  1640. raise Exception("Failed to start listen state")
  1641. if "FAIL" in wpas.request("SET ext_mgmt_frame_handling 1"):
  1642. raise Exception("Failed to enable external management frame handling")
  1643. anqp_query = struct.pack('<HHHHHHHHHH', 256, 16, 257, 258, 260, 261, 262, 263, 264, 268)
  1644. gas = struct.pack('<H', len(anqp_query)) + anqp_query
  1645. dialog_token = 100
  1646. adv = struct.pack('BBBB', 109, 2, 0, 0)
  1647. adv2 = struct.pack('BBB', 108, 1, 0)
  1648. adv3 = struct.pack('BBBB', 108, 3, 0, 0)
  1649. msg = struct.pack('<BBB', ACTION_CATEG_PUBLIC, GAS_INITIAL_REQUEST,
  1650. dialog_token) + adv + gas
  1651. msg2 = struct.pack('<BBB', ACTION_CATEG_PUBLIC, GAS_INITIAL_REQUEST,
  1652. dialog_token) + adv2 + gas
  1653. msg3 = struct.pack('<BBB', ACTION_CATEG_PUBLIC, GAS_INITIAL_REQUEST,
  1654. dialog_token) + adv3
  1655. msg4 = struct.pack('<BBB', ACTION_CATEG_PUBLIC, GAS_INITIAL_REQUEST,
  1656. dialog_token) + anqp_adv_proto()
  1657. msg5 = struct.pack('<BBB', ACTION_CATEG_PUBLIC, GAS_INITIAL_REQUEST,
  1658. dialog_token) + anqp_adv_proto() + struct.pack('<H', 1)
  1659. msg6 = struct.pack('<BB', ACTION_CATEG_PUBLIC, GAS_COMEBACK_REQUEST)
  1660. tests = [ msg, msg2, msg3, msg4, msg5, msg6 ]
  1661. for t in tests:
  1662. req = "MGMT_TX {} {} freq=2412 wait_time=10 action={}".format(bssid, bssid, binascii.hexlify(t))
  1663. if "OK" not in wpas.request(req):
  1664. raise Exception("Could not send management frame")
  1665. ev = wpas.wait_event(["MGMT-TX-STATUS"], timeout=5)
  1666. if ev is None:
  1667. raise Exception("No ACK frame seen")