diff --git a/tests/hwsim/test_dpp.py b/tests/hwsim/test_dpp.py index f96e378e3..b19e3a328 100644 --- a/tests/hwsim/test_dpp.py +++ b/tests/hwsim/test_dpp.py @@ -2682,16 +2682,306 @@ def test_dpp_hostapd_enrollee_gas_timeout(dev, apdev): dev[0].set("ext_mgmt_frame_handling", "1") dev[0].dpp_listen(2437, role="configurator") hapd.dpp_auth_init(uri=uri0, role="enrollee") - - for i in range(3): - msg = dev[0].mgmt_rx() - cmd = "MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg['freq'], msg['datarate'], msg['ssi_signal'], binascii.hexlify(msg['frame']).decode()) - if "OK" not in dev[0].request(cmd): - raise Exception("MGMT_RX_PROCESS failed") + process_dpp_frames(dev[0]) ev = hapd.wait_event(["GAS-QUERY-DONE"], timeout=10) if "result=TIMEOUT" not in ev: raise Exception("GAS timeout not reported") +def test_dpp_hostapd_enrollee_gas_timeout_comeback(dev, apdev): + """DPP and hostapd as Enrollee with GAS timeout during comeback""" + check_dpp_capab(dev[0]) + hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured", + "channel": "6"}) + check_dpp_capab(hapd) + conf_id = dev[0].dpp_configurator_add() + id0 = dev[0].dpp_bootstrap_gen(chan="81/6", mac=True) + uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0) + conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}' + 3000*' ' + dev[0].set("dpp_config_obj_override", conf) + dev[0].set("dpp_configurator_params", + "conf=ap-dpp configurator=%d" % conf_id) + dev[0].set("ext_mgmt_frame_handling", "1") + dev[0].dpp_listen(2437, role="configurator") + hapd.dpp_auth_init(uri=uri0, role="enrollee") + process_dpp_frames(dev[0], count=4) + ev = hapd.wait_event(["GAS-QUERY-DONE"], timeout=10) + if "result=TIMEOUT" not in ev: + raise Exception("GAS timeout not reported") + +def process_dpp_frames(dev, count=3): + for i in range(count): + msg = dev.mgmt_rx() + cmd = "MGMT_RX_PROCESS freq={} datarate={} ssi_signal={} frame={}".format(msg['freq'], msg['datarate'], msg['ssi_signal'], binascii.hexlify(msg['frame']).decode()) + if "OK" not in dev.request(cmd): + raise Exception("MGMT_RX_PROCESS failed") + +def test_dpp_hostapd_enrollee_gas_errors(dev, apdev): + """DPP and hostapd as Enrollee with GAS query local errors""" + check_dpp_capab(dev[0]) + hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured", + "channel": "6"}) + check_dpp_capab(hapd) + conf_id = dev[0].dpp_configurator_add() + id0 = dev[0].dpp_bootstrap_gen(chan="81/6", mac=True) + uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0) + dev[0].set("dpp_configurator_params", + "conf=ap-dpp configurator=%d" % conf_id) + dev[0].set("ext_mgmt_frame_handling", "1") + + # GAS without comeback + tests = [(1, "gas_query_append;gas_query_rx_initial", 3, True), + (1, "gas_query_rx_initial", 3, True), + (1, "gas_query_tx_initial_req", 2, True), + (1, "gas_query_ap_req", 2, False)] + for count, func, frame_count, wait_ev in tests: + dev[0].request("DPP_STOP_LISTEN") + dev[0].dpp_listen(2437, role="configurator") + dev[0].dump_monitor() + hapd.dump_monitor() + with alloc_fail(hapd, count, func): + hapd.dpp_auth_init(uri=uri0, role="enrollee") + process_dpp_frames(dev[0], count=frame_count) + if wait_ev: + ev = hapd.wait_event(["GAS-QUERY-DONE"], timeout=10) + if not ev or "result=INTERNAL_ERROR" not in ev: + raise Exception("Unexpect GAS query result: " + str(ev)) + + # GAS with comeback + conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}' + 3000*' ' + dev[0].set("dpp_config_obj_override", conf) + + tests = [(1, "gas_query_append;gas_query_rx_comeback", 4), + (1, "wpabuf_alloc;gas_query_tx_comeback_req", 3), + (1, "hostapd_drv_send_action;gas_query_tx_comeback_req", 3)] + for count, func, frame_count in tests: + dev[0].request("DPP_STOP_LISTEN") + dev[0].dpp_listen(2437, role="configurator") + dev[0].dump_monitor() + hapd.dump_monitor() + with alloc_fail(hapd, count, func): + hapd.dpp_auth_init(uri=uri0, role="enrollee") + process_dpp_frames(dev[0], count=frame_count) + ev = hapd.wait_event(["GAS-QUERY-DONE"], timeout=10) + if not ev or "result=INTERNAL_ERROR" not in ev: + raise Exception("Unexpect GAS query result: " + str(ev)) + +def test_dpp_hostapd_enrollee_gas_proto(dev, apdev): + """DPP and hostapd as Enrollee with GAS query protocol testing""" + check_dpp_capab(dev[0]) + hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured", + "channel": "6"}) + check_dpp_capab(hapd) + bssid = hapd.own_addr() + conf_id = dev[0].dpp_configurator_add() + id0 = dev[0].dpp_bootstrap_gen(chan="81/6", mac=True) + uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0) + dev[0].set("dpp_configurator_params", + "conf=ap-dpp configurator=%d" % conf_id) + conf = '{"wi-fi_tech":"infra", "discovery":{"ssid":"test"},"cred":{"akm":"psk","pass":"secret passphrase"}}' + 3000*' ' + dev[0].set("dpp_config_obj_override", conf) + dev[0].set("ext_mgmt_frame_handling", "1") + dev[0].dpp_listen(2437, role="configurator") + hapd.dpp_auth_init(uri=uri0, role="enrollee") + process_dpp_frames(dev[0], count=3) + msg = dev[0].mgmt_rx() + payload = msg['payload'] + dialog_token, = struct.unpack('B', payload[2:3]) + hdr = struct.pack('