2 # Copyright (c) 2013, Qualcomm Atheros, Inc.
3 # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi>
5 # This software may be distributed under the terms of the BSD license.
6 # See README for more details.
11 logger = logging.getLogger()
16 from wpasupplicant import WpaSupplicant
19 params = hostapd.wpa2_params(ssid="test-gas")
20 params['wpa_key_mgmt'] = "WPA-EAP"
21 params['ieee80211w'] = "1"
22 params['ieee8021x'] = "1"
23 params['auth_server_addr'] = "127.0.0.1"
24 params['auth_server_port'] = "1812"
25 params['auth_server_shared_secret'] = "radius"
26 params['interworking'] = "1"
27 params['access_network_type'] = "14"
28 params['internet'] = "1"
32 params['venue_group'] = "7"
33 params['venue_type'] = "1"
34 params['venue_name'] = [ "eng:Example venue", "fin:Esimerkkipaikka" ]
35 params['roaming_consortium'] = [ "112233", "1020304050", "010203040506",
37 params['domain_name'] = "example.com,another.example.com"
38 params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]",
39 "0,another.example.com" ]
40 params['anqp_3gpp_cell_net'] = "244,91"
41 params['network_auth_type'] = "02http://www.example.com/redirect/me/here/"
42 params['ipaddr_type_availability'] = "14"
44 params['hs20_oper_friendly_name'] = [ "eng:Example operator", "fin:Esimerkkioperaattori" ]
45 params['hs20_wan_metrics'] = "01:8000:1000:80:240:3000"
46 params['hs20_conn_capab'] = [ "1:0:2", "6:22:1", "17:5060:0" ]
47 params['hs20_operating_class'] = "5173"
51 params = hs20_ap_params()
52 params['hessid'] = ap['bssid']
53 hostapd.add_ap(ap['ifname'], params)
54 return hostapd.Hostapd(ap['ifname'])
56 def get_gas_response(dev, bssid, info, allow_fetch_failure=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)
60 raise Exception("Could not parse GAS-RESPONSE-INFO")
62 raise Exception("Unexpected BSSID in response")
66 raise Exception("GAS query failed")
69 raise Exception("GAS query reported invalid response length")
70 if int(resp_len) > 2000:
71 raise Exception("Unexpected long GAS response")
73 resp = dev.request("GAS_RESPONSE_GET " + bssid + " " + token)
75 if allow_fetch_failure:
76 logger.debug("GAS response was not available anymore")
78 raise Exception("Could not fetch GAS response")
79 if len(resp) != int(resp_len) * 2:
80 raise Exception("Unexpected GAS response length")
81 logger.debug("GAS response: " + resp)
83 def test_gas_generic(dev, apdev):
84 """Generic GAS query"""
85 bssid = apdev[0]['bssid']
86 params = hs20_ap_params()
87 params['hessid'] = bssid
88 hostapd.add_ap(apdev[0]['ifname'], params)
90 dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
91 req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000101")
93 raise Exception("GAS query request rejected")
94 ev = dev[0].wait_event(["GAS-RESPONSE-INFO"], timeout=10)
96 raise Exception("GAS query timed out")
97 get_gas_response(dev[0], bssid, ev)
99 def test_gas_concurrent_scan(dev, apdev):
100 """Generic GAS queries with concurrent scan operation"""
101 bssid = apdev[0]['bssid']
102 params = hs20_ap_params()
103 params['hessid'] = bssid
104 hostapd.add_ap(apdev[0]['ifname'], params)
106 # get BSS entry available to allow GAS query
107 dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
109 logger.info("Request concurrent operations")
110 req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000101")
112 raise Exception("GAS query request rejected")
113 req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000801")
115 raise Exception("GAS query request rejected")
116 dev[0].scan(no_wait=True)
117 req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000201")
119 raise Exception("GAS query request rejected")
120 req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000501")
122 raise Exception("GAS query request rejected")
125 for i in range(0, 5):
126 ev = dev[0].wait_event(["GAS-RESPONSE-INFO", "CTRL-EVENT-SCAN-RESULTS"],
129 raise Exception("Operation timed out")
130 if "GAS-RESPONSE-INFO" in ev:
131 responses = responses + 1
132 get_gas_response(dev[0], bssid, ev, allow_fetch_failure=True)
135 raise Exception("Unexpected number of GAS responses")
137 def test_gas_concurrent_connect(dev, apdev):
138 """Generic GAS queries with concurrent connection operation"""
139 bssid = apdev[0]['bssid']
140 params = hs20_ap_params()
141 params['hessid'] = bssid
142 hostapd.add_ap(apdev[0]['ifname'], params)
144 dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
146 logger.debug("Start concurrent connect and GAS request")
147 dev[0].connect("test-gas", key_mgmt="WPA-EAP", eap="TTLS",
148 identity="DOMAIN\mschapv2 user", anonymous_identity="ttls",
149 password="password", phase2="auth=MSCHAPV2",
150 ca_cert="auth_serv/ca.pem", wait_connect=False,
152 req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000101")
154 raise Exception("GAS query request rejected")
156 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", "GAS-RESPONSE-INFO"],
159 raise Exception("Operation timed out")
160 if "CTRL-EVENT-CONNECTED" not in ev:
161 raise Exception("Unexpected operation order")
163 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", "GAS-RESPONSE-INFO"],
166 raise Exception("Operation timed out")
167 if "GAS-RESPONSE-INFO" not in ev:
168 raise Exception("Unexpected operation order")
169 get_gas_response(dev[0], bssid, ev)
171 dev[0].request("DISCONNECT")
172 ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5)
174 raise Exception("Disconnection timed out")
176 logger.debug("Wait six seconds for expiration of connect-without-scan")
178 dev[0].dump_monitor()
180 logger.debug("Start concurrent GAS request and connect")
181 req = dev[0].request("GAS_REQUEST " + bssid + " 00 000102000101")
183 raise Exception("GAS query request rejected")
184 dev[0].request("RECONNECT")
186 ev = dev[0].wait_event(["GAS-RESPONSE-INFO"], timeout=10)
188 raise Exception("Operation timed out")
189 get_gas_response(dev[0], bssid, ev)
191 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=20)
193 raise Exception("No new scan results reported")
195 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=20)
197 raise Exception("Operation timed out")
198 if "CTRL-EVENT-CONNECTED" not in ev:
199 raise Exception("Unexpected operation order")
201 def test_gas_fragment(dev, apdev):
202 """GAS fragmentation"""
203 hapd = start_ap(apdev[0])
204 hapd.set("gas_frag_limit", "50")
206 dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True)
207 dev[0].request("FETCH_ANQP")
208 for i in range(0, 13):
209 ev = dev[0].wait_event(["RX-ANQP", "RX-HS20-ANQP"], timeout=5)
211 raise Exception("Operation timed out")
213 def test_gas_comeback_delay(dev, apdev):
214 """GAS fragmentation"""
215 hapd = start_ap(apdev[0])
216 hapd.set("gas_comeback_delay", "500")
218 dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True)
219 dev[0].request("FETCH_ANQP")
220 for i in range(0, 6):
221 ev = dev[0].wait_event(["RX-ANQP"], timeout=5)
223 raise Exception("Operation timed out")
225 def test_gas_anqp_get(dev, apdev):
226 """GAS/ANQP query for both IEEE 802.11 and Hotspot 2.0 elements"""
227 hapd = start_ap(apdev[0])
228 bssid = apdev[0]['bssid']
230 dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
231 if "OK" not in dev[0].request("ANQP_GET " + bssid + " 258,268,hs20:3,hs20:4"):
232 raise Exception("ANQP_GET command failed")
234 ev = dev[0].wait_event(["GAS-QUERY-START"], timeout=5)
236 raise Exception("GAS query start timed out")
238 ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10)
240 raise Exception("GAS query timed out")
242 ev = dev[0].wait_event(["RX-ANQP"], timeout=1)
243 if ev is None or "Venue Name" not in ev:
244 raise Exception("Did not receive Venue Name")
246 ev = dev[0].wait_event(["RX-ANQP"], timeout=1)
247 if ev is None or "Domain Name list" not in ev:
248 raise Exception("Did not receive Domain Name list")
250 ev = dev[0].wait_event(["RX-HS20-ANQP"], timeout=1)
251 if ev is None or "Operator Friendly Name" not in ev:
252 raise Exception("Did not receive Operator Friendly Name")
254 ev = dev[0].wait_event(["RX-HS20-ANQP"], timeout=1)
255 if ev is None or "WAN Metrics" not in ev:
256 raise Exception("Did not receive WAN Metrics")
258 if "OK" not in dev[0].request("HS20_ANQP_GET " + bssid + " 3,4"):
259 raise Exception("ANQP_GET command failed")
261 ev = dev[0].wait_event(["RX-HS20-ANQP"], timeout=1)
262 if ev is None or "Operator Friendly Name" not in ev:
263 raise Exception("Did not receive Operator Friendly Name")
265 ev = dev[0].wait_event(["RX-HS20-ANQP"], timeout=1)
266 if ev is None or "WAN Metrics" not in ev:
267 raise Exception("Did not receive WAN Metrics")
269 def expect_gas_result(dev, result, status=None):
270 ev = dev.wait_event(["GAS-QUERY-DONE"], timeout=10)
272 raise Exception("GAS query timed out")
273 if "result=" + result not in ev:
274 raise Exception("Unexpected GAS query result")
275 if status and "status_code=" + str(status) + ' ' not in ev:
276 raise Exception("Unexpected GAS status code")
278 def anqp_get(dev, bssid, id):
279 if "OK" not in dev.request("ANQP_GET " + bssid + " " + str(id)):
280 raise Exception("ANQP_GET command failed")
281 ev = dev.wait_event(["GAS-QUERY-START"], timeout=5)
283 raise Exception("GAS query start timed out")
285 def test_gas_timeout(dev, apdev):
287 hapd = start_ap(apdev[0])
288 bssid = apdev[0]['bssid']
290 dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
291 hapd.set("ext_mgmt_frame_handling", "1")
293 anqp_get(dev[0], bssid, 263)
295 ev = hapd.wait_event(["MGMT-RX"], timeout=5)
297 raise Exception("MGMT RX wait timed out")
299 expect_gas_result(dev[0], "TIMEOUT")
301 MGMT_SUBTYPE_ACTION = 13
302 ACTION_CATEG_PUBLIC = 4
304 GAS_INITIAL_REQUEST = 10
305 GAS_INITIAL_RESPONSE = 11
306 GAS_COMEBACK_REQUEST = 12
307 GAS_COMEBACK_RESPONSE = 13
308 GAS_ACTIONS = [ GAS_INITIAL_REQUEST, GAS_INITIAL_RESPONSE,
309 GAS_COMEBACK_REQUEST, GAS_COMEBACK_RESPONSE ]
311 def anqp_adv_proto():
312 return struct.pack('BBBB', 108, 2, 127, 0)
314 def anqp_initial_resp(dialog_token, status_code, comeback_delay=0):
315 return struct.pack('<BBBHH', ACTION_CATEG_PUBLIC, GAS_INITIAL_RESPONSE,
316 dialog_token, status_code, comeback_delay) + anqp_adv_proto()
318 def anqp_comeback_resp(dialog_token, status_code=0, id=0, more=False, comeback_delay=0, bogus_adv_proto=False):
322 adv = struct.pack('BBBB', 108, 2, 127, 1)
324 adv = anqp_adv_proto()
325 return struct.pack('<BBBHBH', ACTION_CATEG_PUBLIC, GAS_COMEBACK_RESPONSE,
326 dialog_token, status_code, id, comeback_delay) + adv
332 query = hapd.mgmt_rx()
334 raise Exception("Action frame not received")
335 if query['subtype'] != MGMT_SUBTYPE_ACTION:
337 payload = query['payload']
340 (category, action) = struct.unpack('BB', payload[0:2])
341 if category != ACTION_CATEG_PUBLIC or action not in GAS_ACTIONS:
344 raise Exception("No Action frame received")
346 def parse_gas(payload):
348 (category, action, dialog_token) = struct.unpack('BBB', pos[0:3])
349 if category != ACTION_CATEG_PUBLIC:
351 if action not in GAS_ACTIONS:
354 gas['action'] = action
357 if len(pos) < 1 and action != GAS_COMEBACK_REQUEST:
360 gas['dialog_token'] = dialog_token
362 if action == GAS_INITIAL_RESPONSE:
365 (status_code, comeback_delay) = struct.unpack('<HH', pos[0:4])
366 gas['status_code'] = status_code
367 gas['comeback_delay'] = comeback_delay
369 if action == GAS_COMEBACK_RESPONSE:
372 (status_code, frag, comeback_delay) = struct.unpack('<HBH', pos[0:5])
373 gas['status_code'] = status_code
375 gas['comeback_delay'] = comeback_delay
379 def action_response(req):
381 resp['fc'] = req['fc']
382 resp['da'] = req['sa']
383 resp['sa'] = req['da']
384 resp['bssid'] = req['bssid']
387 def send_gas_resp(hapd, resp):
389 ev = hapd.wait_event(["MGMT-TX-STATUS"], timeout=5)
391 raise Exception("Missing TX status for GAS response")
393 raise Exception("GAS response not acknowledged")
395 def test_gas_invalid_response_type(dev, apdev):
396 """GAS invalid response type"""
397 hapd = start_ap(apdev[0])
398 bssid = apdev[0]['bssid']
400 dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
401 hapd.set("ext_mgmt_frame_handling", "1")
403 anqp_get(dev[0], bssid, 263)
406 gas = parse_gas(query['payload'])
408 resp = action_response(query)
409 # GAS Comeback Response instead of GAS Initial Response
410 resp['payload'] = anqp_comeback_resp(gas['dialog_token']) + struct.pack('<H', 0)
411 send_gas_resp(hapd, resp)
413 # station drops the invalid frame, so this needs to result in GAS timeout
414 expect_gas_result(dev[0], "TIMEOUT")
416 def test_gas_failure_status_code(dev, apdev):
417 """GAS failure status code"""
418 hapd = start_ap(apdev[0])
419 bssid = apdev[0]['bssid']
421 dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
422 hapd.set("ext_mgmt_frame_handling", "1")
424 anqp_get(dev[0], bssid, 263)
427 gas = parse_gas(query['payload'])
429 resp = action_response(query)
430 resp['payload'] = anqp_initial_resp(gas['dialog_token'], 61) + struct.pack('<H', 0)
431 send_gas_resp(hapd, resp)
433 expect_gas_result(dev[0], "FAILURE")
435 def test_gas_malformed(dev, apdev):
436 """GAS malformed response frames"""
437 hapd = start_ap(apdev[0])
438 bssid = apdev[0]['bssid']
440 dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
441 hapd.set("ext_mgmt_frame_handling", "1")
443 anqp_get(dev[0], bssid, 263)
446 gas = parse_gas(query['payload'])
448 resp = action_response(query)
450 resp['payload'] = struct.pack('<BBBH', ACTION_CATEG_PUBLIC,
451 GAS_COMEBACK_RESPONSE,
452 gas['dialog_token'], 0)
455 resp['payload'] = struct.pack('<BBBHB', ACTION_CATEG_PUBLIC,
456 GAS_COMEBACK_RESPONSE,
457 gas['dialog_token'], 0, 0)
460 hdr = struct.pack('<BBBHH', ACTION_CATEG_PUBLIC, GAS_INITIAL_RESPONSE,
461 gas['dialog_token'], 0, 0)
462 resp['payload'] = hdr + struct.pack('B', 108)
464 resp['payload'] = hdr + struct.pack('BB', 108, 0)
466 resp['payload'] = hdr + struct.pack('BB', 108, 1)
468 resp['payload'] = hdr + struct.pack('BB', 108, 255)
470 resp['payload'] = hdr + struct.pack('BBB', 108, 1, 127)
472 resp['payload'] = hdr + struct.pack('BBB', 108, 2, 127)
474 resp['payload'] = hdr + struct.pack('BBBB', 0, 2, 127, 0)
477 resp['payload'] = anqp_initial_resp(gas['dialog_token'], 0) + struct.pack('<H', 1)
480 resp['payload'] = anqp_initial_resp(gas['dialog_token'], 0) + struct.pack('<HB', 2, 0)
483 resp['payload'] = anqp_initial_resp(gas['dialog_token'], 0) + struct.pack('<H', 65535)
486 resp['payload'] = anqp_initial_resp(gas['dialog_token'], 0) + struct.pack('<HBB', 1, 0, 0)
489 # Station drops invalid frames, but the last of the responses is valid from
490 # GAS view point even though it has an extra octet in the end and the ANQP
491 # part of the response is not valid. This is reported as successfulyl
492 # completed GAS exchange.
493 expect_gas_result(dev[0], "SUCCESS")
495 def init_gas(hapd, bssid, dev):
496 anqp_get(dev, bssid, 263)
498 gas = parse_gas(query['payload'])
499 dialog_token = gas['dialog_token']
501 resp = action_response(query)
502 resp['payload'] = anqp_initial_resp(dialog_token, 0, comeback_delay=1) + struct.pack('<H', 0)
503 send_gas_resp(hapd, resp)
506 gas = parse_gas(query['payload'])
507 if gas['action'] != GAS_COMEBACK_REQUEST:
508 raise Exception("Unexpected request action")
509 if gas['dialog_token'] != dialog_token:
510 raise Exception("Unexpected dialog token change")
511 return query, dialog_token
513 def test_gas_malformed_comeback_resp(dev, apdev):
514 """GAS malformed comeback response frames"""
515 hapd = start_ap(apdev[0])
516 bssid = apdev[0]['bssid']
518 dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
519 hapd.set("ext_mgmt_frame_handling", "1")
521 logger.debug("Non-zero status code in comeback response")
522 query, dialog_token = init_gas(hapd, bssid, dev[0])
523 resp = action_response(query)
524 resp['payload'] = anqp_comeback_resp(dialog_token, status_code=2) + struct.pack('<H', 0)
525 send_gas_resp(hapd, resp)
526 expect_gas_result(dev[0], "FAILURE", status=2)
528 logger.debug("Different advertisement protocol in comeback response")
529 query, dialog_token = init_gas(hapd, bssid, dev[0])
530 resp = action_response(query)
531 resp['payload'] = anqp_comeback_resp(dialog_token, bogus_adv_proto=True) + struct.pack('<H', 0)
532 send_gas_resp(hapd, resp)
533 expect_gas_result(dev[0], "PEER_ERROR")
535 logger.debug("Non-zero frag id and comeback delay in comeback response")
536 query, dialog_token = init_gas(hapd, bssid, dev[0])
537 resp = action_response(query)
538 resp['payload'] = anqp_comeback_resp(dialog_token, id=1, comeback_delay=1) + struct.pack('<H', 0)
539 send_gas_resp(hapd, resp)
540 expect_gas_result(dev[0], "PEER_ERROR")
542 logger.debug("Unexpected frag id 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, id=1) + struct.pack('<H', 0)
546 send_gas_resp(hapd, resp)
547 expect_gas_result(dev[0], "PEER_ERROR")
549 logger.debug("Empty fragment and replay in comeback response")
550 query, dialog_token = init_gas(hapd, bssid, dev[0])
551 resp = action_response(query)
552 resp['payload'] = anqp_comeback_resp(dialog_token, more=True) + struct.pack('<H', 0)
553 send_gas_resp(hapd, resp)
555 gas = parse_gas(query['payload'])
556 if gas['action'] != GAS_COMEBACK_REQUEST:
557 raise Exception("Unexpected request action")
558 if gas['dialog_token'] != dialog_token:
559 raise Exception("Unexpected dialog token change")
560 resp = action_response(query)
561 resp['payload'] = anqp_comeback_resp(dialog_token) + struct.pack('<H', 0)
562 send_gas_resp(hapd, resp)
563 resp['payload'] = anqp_comeback_resp(dialog_token, id=1) + struct.pack('<H', 0)
564 send_gas_resp(hapd, resp)
565 expect_gas_result(dev[0], "SUCCESS")
567 logger.debug("Unexpected initial response when waiting for comeback response")
568 query, dialog_token = init_gas(hapd, bssid, dev[0])
569 resp = action_response(query)
570 resp['payload'] = anqp_initial_resp(dialog_token, 0) + struct.pack('<H', 0)
571 send_gas_resp(hapd, resp)
572 ev = hapd.wait_event(["MGMT-RX"], timeout=1)
574 raise Exception("Unexpected management frame")
575 expect_gas_result(dev[0], "TIMEOUT")
577 logger.debug("Too short comeback response")
578 query, dialog_token = init_gas(hapd, bssid, dev[0])
579 resp = action_response(query)
580 resp['payload'] = struct.pack('<BBBH', ACTION_CATEG_PUBLIC,
581 GAS_COMEBACK_RESPONSE, dialog_token, 0)
582 send_gas_resp(hapd, resp)
583 ev = hapd.wait_event(["MGMT-RX"], timeout=1)
585 raise Exception("Unexpected management frame")
586 expect_gas_result(dev[0], "TIMEOUT")
588 logger.debug("Too short comeback response(2)")
589 query, dialog_token = init_gas(hapd, bssid, dev[0])
590 resp = action_response(query)
591 resp['payload'] = struct.pack('<BBBHBB', ACTION_CATEG_PUBLIC,
592 GAS_COMEBACK_RESPONSE, dialog_token, 0, 0x80,
594 send_gas_resp(hapd, resp)
595 ev = hapd.wait_event(["MGMT-RX"], timeout=1)
597 raise Exception("Unexpected management frame")
598 expect_gas_result(dev[0], "TIMEOUT")
600 logger.debug("Maximum comeback response fragment claiming more fragments")
601 query, dialog_token = init_gas(hapd, bssid, dev[0])
602 resp = action_response(query)
603 resp['payload'] = anqp_comeback_resp(dialog_token, more=True) + struct.pack('<H', 0)
604 send_gas_resp(hapd, resp)
605 for i in range(1, 129):
607 gas = parse_gas(query['payload'])
608 if gas['action'] != GAS_COMEBACK_REQUEST:
609 raise Exception("Unexpected request action")
610 if gas['dialog_token'] != dialog_token:
611 raise Exception("Unexpected dialog token change")
612 resp = action_response(query)
613 resp['payload'] = anqp_comeback_resp(dialog_token, id=i, more=True) + struct.pack('<H', 0)
614 send_gas_resp(hapd, resp)
615 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']
622 dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
623 hapd.set("ext_mgmt_frame_handling", "1")
625 query, dialog_token = init_gas(hapd, bssid, dev[0])
626 for i in range(0, 2):
627 resp = action_response(query)
628 resp['payload'] = anqp_comeback_resp(dialog_token, status_code=95, comeback_delay=50) + struct.pack('<H', 0)
629 send_gas_resp(hapd, resp)
631 gas = parse_gas(query['payload'])
632 if gas['action'] != GAS_COMEBACK_REQUEST:
633 raise Exception("Unexpected request action")
634 if gas['dialog_token'] != dialog_token:
635 raise Exception("Unexpected dialog token change")
636 resp = action_response(query)
637 resp['payload'] = anqp_comeback_resp(dialog_token, status_code=0) + struct.pack('<H', 0)
638 send_gas_resp(hapd, resp)
639 expect_gas_result(dev[0], "SUCCESS")
641 def test_gas_unknown_adv_proto(dev, apdev):
642 """Unknown advertisement protocol id"""
643 bssid = apdev[0]['bssid']
644 params = hs20_ap_params()
645 params['hessid'] = bssid
646 hostapd.add_ap(apdev[0]['ifname'], params)
648 dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
649 req = dev[0].request("GAS_REQUEST " + bssid + " 42 000102000101")
651 raise Exception("GAS query request rejected")
652 expect_gas_result(dev[0], "FAILURE", "59")
653 ev = dev[0].wait_event(["GAS-RESPONSE-INFO"], timeout=10)
655 raise Exception("GAS query timed out")
656 exp = r'<.>(GAS-RESPONSE-INFO) addr=([0-9a-f:]*) dialog_token=([0-9]*) status_code=([0-9]*) resp_len=([\-0-9]*)'
657 res = re.split(exp, ev)
659 raise Exception("Could not parse GAS-RESPONSE-INFO")
661 raise Exception("Unexpected BSSID in response")
664 raise Exception("Unexpected GAS-RESPONSE-INFO status")
666 def test_gas_max_pending(dev, apdev):
667 """GAS and maximum pending query limit"""
668 hapd = start_ap(apdev[0])
669 hapd.set("gas_frag_limit", "50")
670 bssid = apdev[0]['bssid']
672 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
673 wpas.interface_add("wlan5")
674 if "OK" not in wpas.request("P2P_SET listen_channel 1"):
675 raise Exception("Failed to set listen channel")
676 if "OK" not in wpas.p2p_listen():
677 raise Exception("Failed to start listen state")
678 if "FAIL" in wpas.request("SET ext_mgmt_frame_handling 1"):
679 raise Exception("Failed to enable external management frame handling")
681 anqp_query = struct.pack('<HHHHHHHHHH', 256, 16, 257, 258, 260, 261, 262, 263, 264, 268)
682 gas = struct.pack('<H', len(anqp_query)) + anqp_query
684 for dialog_token in range(1, 10):
685 msg = struct.pack('<BBB', ACTION_CATEG_PUBLIC, GAS_INITIAL_REQUEST,
686 dialog_token) + anqp_adv_proto() + gas
687 req = "MGMT_TX {} {} freq=2412 wait_time=10 action={}".format(bssid, bssid, binascii.hexlify(msg))
688 if "OK" not in wpas.request(req):
689 raise Exception("Could not send management frame")
690 resp = wpas.mgmt_rx()
692 raise Exception("MGMT-RX timeout")
693 if 'payload' not in resp:
694 raise Exception("Missing payload")
695 gresp = parse_gas(resp['payload'])
696 if gresp['dialog_token'] != dialog_token:
697 raise Exception("Dialog token mismatch")
698 status_code = gresp['status_code']
699 if dialog_token < 9 and status_code != 0:
700 raise Exception("Unexpected failure status code {} for dialog token {}".format(status_code, dialog_token))
701 if dialog_token > 8 and status_code == 0:
702 raise Exception("Unexpected success status code {} for dialog token {}".format(status_code, dialog_token))
704 def test_gas_no_pending(dev, apdev):
705 """GAS and no pending query for comeback request"""
706 hapd = start_ap(apdev[0])
707 bssid = apdev[0]['bssid']
709 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
710 wpas.interface_add("wlan5")
711 if "OK" not in wpas.request("P2P_SET listen_channel 1"):
712 raise Exception("Failed to set listen channel")
713 if "OK" not in wpas.p2p_listen():
714 raise Exception("Failed to start listen state")
715 if "FAIL" in wpas.request("SET ext_mgmt_frame_handling 1"):
716 raise Exception("Failed to enable external management frame handling")
718 msg = struct.pack('<BBB', ACTION_CATEG_PUBLIC, GAS_COMEBACK_REQUEST, 1)
719 req = "MGMT_TX {} {} freq=2412 wait_time=10 action={}".format(bssid, bssid, binascii.hexlify(msg))
720 if "OK" not in wpas.request(req):
721 raise Exception("Could not send management frame")
722 resp = wpas.mgmt_rx()
724 raise Exception("MGMT-RX timeout")
725 if 'payload' not in resp:
726 raise Exception("Missing payload")
727 gresp = parse_gas(resp['payload'])
728 status_code = gresp['status_code']
729 if status_code != 60:
730 raise Exception("Unexpected status code {} (expected 60)".format(status_code))