From 58b384f467224a1d43f3f947fd53e08b019cbcd3 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 26 Jun 2020 21:06:12 +0300 Subject: [PATCH] tests: sigma_dut DPP reconfiguration Signed-off-by: Jouni Malinen --- tests/hwsim/test_sigma_dut.py | 112 ++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/tests/hwsim/test_sigma_dut.py b/tests/hwsim/test_sigma_dut.py index 3edeafcba..ec85bcd1b 100644 --- a/tests/hwsim/test_sigma_dut.py +++ b/tests/hwsim/test_sigma_dut.py @@ -3291,6 +3291,118 @@ def test_sigma_dut_dpp_nfc_static_write_enrollee(dev, apdev): dev[0].set("dpp_config_processing", "0") stop_sigma_dut(sigma) +def test_sigma_dut_dpp_reconfig_enrollee(dev, apdev): + """sigma_dut DPP reconfiguration (Enrollee)""" + check_dpp_capab(dev[0]) + check_dpp_capab(dev[1]) + hapd = start_dpp_ap(apdev[0]) + sigma = start_sigma_dut(dev[0].ifname) + try: + cmd = "DPP_CONFIGURATOR_ADD key=" + csign + res = dev[1].request(cmd) + if "FAIL" in res: + raise Exception("Failed to add configurator") + conf_id = int(res) + + id0 = dev[1].dpp_bootstrap_gen(chan="81/6", mac=True) + uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0) + + dev[1].set("dpp_configurator_params", + " conf=sta-dpp ssid=%s configurator=%d" % (to_hex("DPPNET01"), conf_id)) + cmd = "DPP_LISTEN 2437 role=configurator" + if "OK" not in dev[1].request(cmd): + raise Exception("Failed to start listen operation") + + ifname = dev[0].ifname + sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname) + + res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri0)) + if "status,COMPLETE" not in res: + raise Exception("dev_exec_action did not succeed: " + res) + + res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6,DPPWaitForConnect,Yes", timeout=10) + if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res: + raise Exception("Unexpected result: " + res) + + hapd.disable() + dev[0].dump_monitor() + + ssid = "reconfig" + passphrase = "secret passphrase" + params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase) + hapd = hostapd.add_ap(apdev[0], params) + + dev[1].set("dpp_configurator_params", + "conf=sta-psk ssid=%s pass=%s conn_status=1" % (binascii.hexlify(ssid.encode()).decode(), binascii.hexlify(passphrase.encode()).decode())) + cmd = "DPP_LISTEN 2437 role=configurator" + if "OK" not in dev[1].request(cmd): + raise Exception("Failed to start listen operation") + dev[1].dump_monitor() + + res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,DPPReconfigure,DPPTimeout,6,DPPWaitForConnect,Yes", timeout=10) + if "status,COMPLETE,ReconfigAuthResult,OK,ConfResult,OK,NetworkConnectResult,OK" not in res: + raise Exception("Unexpected reconfiguration result: " + res) + + ev = dev[1].wait_event(["DPP-CONF-SENT"], timeout=15) + if ev is None: + raise Exception("DPP Config Response (reconfig) not transmitted") + + dev[0].wait_connected() + finally: + dev[0].set("dpp_config_processing", "0") + stop_sigma_dut(sigma) + +def test_sigma_dut_dpp_reconfig_configurator(dev, apdev): + """sigma_dut DPP reconfiguration (Configurator)""" + check_dpp_capab(dev[0]) + check_dpp_capab(dev[1]) + sigma = start_sigma_dut(dev[0].ifname) + try: + dev[1].set("dpp_config_processing", "1") + id0 = dev[1].dpp_bootstrap_gen(chan="81/6", mac=True) + uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0) + cmd = "DPP_LISTEN 2437" + if "OK" not in dev[1].request(cmd): + raise Exception("Failed to start listen operation") + + ifname = dev[0].ifname + sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname) + + res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri0)) + if "status,COMPLETE" not in res: + raise Exception("dev_exec_action did not succeed: " + res) + + res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfEnrolleeRole,STA,DPPSigningKeyECC,P-256,DPPConfIndex,1,DPPBS,QR,DPPTimeout,6", timeout=10) + if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res: + raise Exception("Unexpected result: " + res) + + dev[0].dump_monitor() + + ev = dev[1].wait_event(["DPP-NETWORK-ID"], timeout=1) + if ev is None: + raise Exception("No network profile created") + id = int(ev.split(' ')[1]) + + ev = dev[1].wait_event(["DPP-TX-STATUS"], timeout=5) + if ev is None: + raise Exception("Configuration Result not sent") + dev[1].dump_monitor() + cmd = "DPP_RECONFIG %d" % id + if "OK" not in dev[1].request(cmd): + raise Exception("Failed to start reconfiguration") + + res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,DPPReconfigure,DPPProvisioningRole,Configurator,DPPConfEnrolleeRole,STA,DPPSigningKeyECC,P-256,DPPConfIndex,2,DPPListenChannel,6,DPPTimeout,6", timeout=10) + if "status,COMPLETE,ReconfigAuthResult,OK,ConfResult,OK" not in res: + raise Exception("Unexpected reconfiguration result: " + res) + + ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=15) + if ev is None: + raise Exception("DPP Config Response (reconfig) not received") + finally: + dev[0].set("dpp_config_processing", "0") + dev[1].set("dpp_config_processing", "0") + stop_sigma_dut(sigma) + @reset_ignore_old_scan_res def test_sigma_dut_preconfigured_profile(dev, apdev): """sigma_dut controlled connection using preconfigured profile"""