]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Convert sigma_dut control to a context manager class
authorJouni Malinen <j@w1.fi>
Sat, 23 Mar 2024 22:24:07 +0000 (00:24 +0200)
committerJouni Malinen <j@w1.fi>
Sat, 23 Mar 2024 22:24:07 +0000 (00:24 +0200)
This cleans up the implementation and makes stopping of sigma_dut (and
cleanup after some parameters it might leave behind) more robust.

Signed-off-by: Jouni Malinen <j@w1.fi>
tests/hwsim/test_sigma_dut.py

index 2a35bd4b4e1f59e745ba860c3bc00d9f0563c7a3..c007d213dce5abe631a6a760cdf257ce2f5bd1bc 100644 (file)
@@ -41,36 +41,80 @@ def to_hex(s):
 def from_hex(s):
     return binascii.unhexlify(s).decode()
 
-def sigma_log_output(cmd):
-    try:
-        out = cmd.stdout.read()
-        if out:
-            logger.debug("sigma_dut stdout: " + str(out.decode()))
-    except IOError as e:
-        if e.errno != errno.EAGAIN:
-            raise
-    try:
-        out = cmd.stderr.read()
-        if out:
-            logger.debug("sigma_dut stderr: " + str(out.decode()))
-    except IOError as e:
-        if e.errno != errno.EAGAIN:
-            raise
-
-sigma_prog = None
-
-def sigma_dut_cmd(cmd, port=9000, timeout=2, dump_dev=None):
-    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
-                         socket.IPPROTO_TCP)
-    sock.settimeout(1 if dump_dev else timeout)
-    addr = ('127.0.0.1', port)
-    sock.connect(addr)
-    sock.send(cmd.encode() + b"\r\n")
-    running = False
-    done = False
-    if dump_dev:
-        for i in range(timeout):
-            dump_dev.dump_monitor()
+class SigmaDut:
+    def __init__(self, ifname=None, hostapd_logdir=None, cert_path=None,
+                 bridge=None, sae_h2e=False, owe_ptk_workaround=False,
+                 dev=None):
+        if ifname:
+            self.ifname = ifname
+        elif dev:
+            self.ifname = dev.ifname
+        else:
+            raise Exception("SigmaDut.__init__() did not receive ifname")
+        self.ap = False
+        self.dev = dev
+        self.start(hostapd_logdir, cert_path, bridge, sae_h2e,
+                   owe_ptk_workaround)
+
+    def __enter__(self):
+        return self
+
+    def __exit__(self, type, value, traceback):
+        if self.ap:
+            self.cmd_check('ap_reset_default')
+
+        if self.dev:
+            self.dev.set("dpp_config_processing", "0", allow_fail=True)
+            self.dev.set("dpp_connector_privacy_default", "0", allow_fail=True)
+            self.dev.set("sae_pwe", "0", allow_fail=True)
+            self.dev.request("VENDOR_ELEM_REMOVE 14 *")
+
+        self.stop()
+
+    def log_output(self):
+        try:
+            out = self.sigma.stdout.read()
+            if out:
+                logger.debug("sigma_dut stdout: " + str(out.decode()))
+        except IOError as e:
+            if e.errno != errno.EAGAIN:
+                raise
+        try:
+            out = self.sigma.stderr.read()
+            if out:
+                logger.debug("sigma_dut stderr: " + str(out.decode()))
+        except IOError as e:
+            if e.errno != errno.EAGAIN:
+                raise
+
+    def run_cmd(self, cmd, port=9000, timeout=2, dump_dev=None):
+        if cmd.startswith('ap_config_commit'):
+            self.ap = True
+        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
+                             socket.IPPROTO_TCP)
+        sock.settimeout(1 if dump_dev else timeout)
+        addr = ('127.0.0.1', port)
+        sock.connect(addr)
+        sock.send(cmd.encode() + b"\r\n")
+        running = False
+        done = False
+        if dump_dev:
+            for i in range(timeout):
+                dump_dev.dump_monitor()
+                try:
+                    res = sock.recv(1000).decode()
+                    for line in res.splitlines():
+                        if line.startswith("status,RUNNING"):
+                            running = True
+                        elif line.startswith("status,INVALID") or \
+                             line.startswith("status,ERROR") or \
+                             line.startswith("status,COMPLETE"):
+                            done = True
+                            res = line
+                            break
+                except socket.timeout as e:
+                    pass
+        if (not dump_dev) or (running and not done):
             try:
                 res = sock.recv(1000).decode()
                 for line in res.splitlines():
@@ -82,175 +126,145 @@ def sigma_dut_cmd(cmd, port=9000, timeout=2, dump_dev=None):
                         done = True
                         res = line
                         break
-            except socket.timeout as e:
+                if running and not done:
+                    # Read the actual response
+                    res = sock.recv(1000).decode()
+            except:
+                res = ''
                 pass
-    if (not dump_dev) or (running and not done):
-        try:
-            res = sock.recv(1000).decode()
-            for line in res.splitlines():
-                if line.startswith("status,RUNNING"):
-                    running = True
-                elif line.startswith("status,INVALID") or \
-                     line.startswith("status,ERROR") or \
-                     line.startswith("status,COMPLETE"):
-                    done = True
-                    res = line
-                    break
-            if running and not done:
-                # Read the actual response
-                res = sock.recv(1000).decode()
-        except:
-            res = ''
-            pass
-    sock.close()
-    res = res.rstrip()
-    logger.debug("sigma_dut: '%s' --> '%s'" % (cmd, res))
-    global sigma_prog
-    if sigma_prog:
-        sigma_log_output(sigma_prog)
-    return res
-
-def sigma_dut_cmd_check(cmd, port=9000, timeout=2):
-    res = sigma_dut_cmd(cmd, port=port, timeout=timeout)
-    if "COMPLETE" not in res:
-        raise Exception("sigma_dut command failed: " + cmd)
-    return res
-
-def start_sigma_dut(ifname, hostapd_logdir=None, cert_path=None,
-                    bridge=None, sae_h2e=False, owe_ptk_workaround=False):
-    check_sigma_dut()
-    cmd = ['./sigma_dut',
-           '-d',
-           '-M', ifname,
-           '-S', ifname,
-           '-F', '../../hostapd/hostapd',
-           '-G',
-           '-w', '/var/run/wpa_supplicant/',
-           '-j', ifname]
-    if hostapd_logdir:
-        cmd += ['-H', hostapd_logdir]
-    if cert_path:
-        cmd += ['-C', cert_path]
-    if bridge:
-        cmd += ['-b', bridge]
-    if sae_h2e:
-        cmd += ['-2']
-    if owe_ptk_workaround:
-        cmd += ['-3']
-    sigma = subprocess.Popen(cmd, stdout=subprocess.PIPE,
-                             stderr=subprocess.PIPE)
-    for stream in [sigma.stdout, sigma.stderr]:
-        fd = stream.fileno()
-        fl = fcntl.fcntl(fd, fcntl.F_GETFL)
-        fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
-
-    global sigma_prog
-    sigma_prog = sigma
-    res = None
-    for i in range(20):
+        sock.close()
+        res = res.rstrip()
+        logger.debug("sigma_dut: '%s' --> '%s'" % (cmd, res))
+        self.log_output()
+        return res
+
+    def cmd_check(self, cmd, port=9000, timeout=2):
+        res = self.run_cmd(cmd, port=port, timeout=timeout)
+        if "COMPLETE" not in res:
+            raise Exception("sigma_dut command failed: " + cmd)
+        return res
+
+    def start(self, hostapd_logdir=None, cert_path=None,
+              bridge=None, sae_h2e=False, owe_ptk_workaround=False):
+        ifname = self.ifname
+        check_sigma_dut()
+        cmd = ['./sigma_dut',
+               '-d',
+               '-M', ifname,
+               '-S', ifname,
+               '-F', '../../hostapd/hostapd',
+               '-G',
+               '-w', '/var/run/wpa_supplicant/',
+               '-j', ifname]
+        if hostapd_logdir:
+            cmd += ['-H', hostapd_logdir]
+        if cert_path:
+            cmd += ['-C', cert_path]
+        if bridge:
+            cmd += ['-b', bridge]
+        if sae_h2e:
+            cmd += ['-2']
+        if owe_ptk_workaround:
+            cmd += ['-3']
+        self.sigma = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+                                      stderr=subprocess.PIPE)
+        for stream in [self.sigma.stdout, self.sigma.stderr]:
+            fd = stream.fileno()
+            fl = fcntl.fcntl(fd, fcntl.F_GETFL)
+            fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
+
+        res = None
+        for i in range(20):
+            try:
+                res = self.run_cmd("HELLO")
+                break
+            except IOError as e:
+                if e.errno != errno.ECONNREFUSED:
+                    raise
+                time.sleep(0.05)
+        if res is None or "errorCode,Unknown command" not in res:
+            raise Exception("Failed to start sigma_dut")
+
+    def stop(self):
+        self.log_output()
+        logger.debug("Terminating sigma_dut process")
+        self.sigma.terminate()
         try:
-            res = sigma_dut_cmd("HELLO")
-            break
-        except:
-            time.sleep(0.05)
-    if res is None or "errorCode,Unknown command" not in res:
-        raise Exception("Failed to start sigma_dut")
-    return {'cmd': sigma, 'ifname': ifname}
-
-def stop_sigma_dut(sigma):
-    global sigma_prog
-    sigma_prog = None
-    cmd = sigma['cmd']
-    sigma_log_output(cmd)
-    logger.debug("Terminating sigma_dut process")
-    cmd.terminate()
-    try:
-        out, err = cmd.communicate(timeout=200)
-        logger.debug("sigma_dut stdout: " + str(out.decode()))
-        logger.debug("sigma_dut stderr: " + str(err.decode()))
-    except subprocess.TimeoutExpired:
-        logger.debug("sigma_dut termination timed out")
-        cmd.kill()
-        out, err = cmd.communicate()
-        logger.debug("sigma_dut stdout: " + str(out.decode()))
-        logger.debug("sigma_dut stderr: " + str(err.decode()))
-
-    subprocess.call(["ip", "addr", "del", "dev", sigma['ifname'],
-                     "127.0.0.11/24"],
-                    stderr=open('/dev/null', 'w'))
-
-def sigma_dut_wait_connected(ifname):
-    for i in range(50):
-        res = sigma_dut_cmd("sta_is_connected,interface," + ifname)
-        if "connected,1" in res:
-            break
-        time.sleep(0.2)
-        if i == 49:
+            out, err = self.sigma.communicate(timeout=200)
+            logger.debug("sigma_dut stdout: " + str(out.decode()))
+            logger.debug("sigma_dut stderr: " + str(err.decode()))
+        except subprocess.TimeoutExpired:
+            logger.debug("sigma_dut termination timed out")
+            self.sigma.kill()
+            out, err = self.sigma.communicate()
+            logger.debug("sigma_dut stdout: " + str(out.decode()))
+            logger.debug("sigma_dut stderr: " + str(err.decode()))
+
+        subprocess.call(["ip", "addr", "del", "dev", self.ifname,
+                         "127.0.0.11/24"],
+                        stderr=open('/dev/null', 'w'))
+
+    def wait_connected(self):
+        for i in range(50):
+            res = self.run_cmd("sta_is_connected,interface," + self.ifname)
+            if "connected,1" in res:
+                break
+            time.sleep(0.2)
+        else:
             raise Exception("Connection did not complete")
 
 def test_sigma_dut_basic(dev, apdev):
     """sigma_dut basic functionality"""
-    sigma = start_sigma_dut(dev[0].ifname)
-
     tests = [("ca_get_version", "status,COMPLETE,version,1.0"),
              ("device_get_info", "status,COMPLETE,vendor"),
              ("device_list_interfaces,interfaceType,foo", "status,ERROR"),
              ("device_list_interfaces,interfaceType,802.11",
               "status,COMPLETE,interfaceType,802.11,interfaceID," + dev[0].ifname)]
-    try:
-        res = sigma_dut_cmd("UNKNOWN")
+
+    with SigmaDut(dev[0].ifname) as dut:
+        res = dut.run_cmd("UNKNOWN")
         if "status,INVALID,errorCode,Unknown command" not in res:
             raise Exception("Unexpected sigma_dut response to unknown command")
 
         for cmd, response in tests:
-            res = sigma_dut_cmd(cmd)
+            res = dut.run_cmd(cmd)
             if response not in res:
                 raise Exception("Unexpected %s response: %s" % (cmd, res))
-    finally:
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_open(dev, apdev):
     """sigma_dut controlled open network association"""
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
+    with SigmaDut(ifname) as dut:
         hapd = hostapd.add_ap(apdev[0], {"ssid": "open"})
 
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_encryption,interface,%s,ssid,%s,encpType,none" % (ifname, "open"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s" % (ifname, "open"),
-                            timeout=10)
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_encryption,interface,%s,ssid,%s,encpType,none" % (ifname, "open"))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s" % (ifname, "open"),
+                      timeout=10)
+        dut.wait_connected()
+        dut.cmd_check("sta_get_ip_config,interface," + ifname)
+        dut.cmd_check("sta_disconnect,interface," + ifname)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_psk_pmf(dev, apdev):
     """sigma_dut controlled PSK+PMF association"""
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
+    with SigmaDut(ifname) as dut:
         ssid = "test-pmf-required"
         params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
         params["wpa_key_mgmt"] = "WPA-PSK-SHA256"
         params["ieee80211w"] = "2"
         hapd = hostapd.add_ap(apdev[0], params)
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_psk,interface,%s,ssid,%s,passphrase,%s,encpType,aes-ccmp,keymgmttype,wpa2,PMF,Required" % (ifname, "test-pmf-required", "12345678"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-pmf-required"),
-                            timeout=10)
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_psk,interface,%s,ssid,%s,passphrase,%s,encpType,aes-ccmp,keymgmttype,wpa2,PMF,Required" % (ifname, "test-pmf-required", "12345678"))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-pmf-required"),
+                      timeout=10)
+        dut.wait_connected()
+        dut.cmd_check("sta_get_ip_config,interface," + ifname)
+        dut.cmd_check("sta_disconnect,interface," + ifname)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_psk_pmf_bip_cmac_128(dev, apdev):
     """sigma_dut controlled PSK+PMF association with BIP-CMAC-128"""
@@ -276,9 +290,7 @@ def test_sigma_dut_psk_pmf_bip_gmac_256_mismatch(dev, apdev):
 def run_sigma_dut_psk_pmf_cipher(dev, apdev, sigma_cipher, hostapd_cipher,
                                  failure=False):
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
+    with SigmaDut(ifname) as dut:
         ssid = "test-pmf-required"
         params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
         params["wpa_key_mgmt"] = "WPA-PSK-SHA256"
@@ -286,10 +298,10 @@ def run_sigma_dut_psk_pmf_cipher(dev, apdev, sigma_cipher, hostapd_cipher,
         params["group_mgmt_cipher"] = hostapd_cipher
         hapd = hostapd.add_ap(apdev[0], params)
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_psk,interface,%s,ssid,%s,passphrase,%s,encpType,aes-ccmp,keymgmttype,wpa2,PMF,Required,GroupMgntCipher,%s" % (ifname, "test-pmf-required", "12345678", sigma_cipher))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-pmf-required"),
+        dut.cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_psk,interface,%s,ssid,%s,passphrase,%s,encpType,aes-ccmp,keymgmttype,wpa2,PMF,Required,GroupMgntCipher,%s" % (ifname, "test-pmf-required", "12345678", sigma_cipher))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-pmf-required"),
                             timeout=2 if failure else 10)
         if failure:
             ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND",
@@ -298,26 +310,22 @@ def run_sigma_dut_psk_pmf_cipher(dev, apdev, sigma_cipher, hostapd_cipher,
                 raise Exception("Network selection result not indicated")
             if "CTRL-EVENT-CONNECTED" in ev:
                 raise Exception("Unexpected connection")
-            res = sigma_dut_cmd("sta_is_connected,interface," + ifname)
+            res = dut.run_cmd("sta_is_connected,interface," + ifname)
             if "connected,1" in res:
                 raise Exception("Connection reported")
         else:
-            sigma_dut_wait_connected(ifname)
-            sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
+            dut.wait_connected()
+            dut.cmd_check("sta_get_ip_config,interface," + ifname)
 
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.cmd_check("sta_disconnect,interface," + ifname)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_sae(dev, apdev):
     """sigma_dut controlled SAE association"""
     check_sae_capab(dev[0])
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
+    with SigmaDut(ifname) as dut:
         ssid = "test-sae"
         params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
         params['wpa_key_mgmt'] = 'SAE'
@@ -325,46 +333,42 @@ def test_sigma_dut_sae(dev, apdev):
         params['sae_groups'] = '19 20 21'
         hapd = hostapd.add_ap(apdev[0], params)
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, "test-sae", "12345678"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
-                            timeout=10)
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
+        dut.cmd_check("sta_reset_default,interface,%s" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, "test-sae", "12345678"))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
+                      timeout=10)
+        dut.wait_connected()
+        dut.cmd_check("sta_get_ip_config,interface," + ifname)
         if dev[0].get_status_field('sae_group') != '19':
             raise Exception("Expected default SAE group not used")
-        res = sigma_dut_cmd_check("sta_get_parameter,interface,%s,Parameter,PMK" % ifname)
+        res = dut.cmd_check("sta_get_parameter,interface,%s,Parameter,PMK" % ifname)
         logger.info("Reported PMK: " + res)
         if ",PMK," not in res:
             raise Exception("PMK not reported");
         if hapd.request("GET_PMK " + dev[0].own_addr()) != res.split(',')[3]:
             raise Exception("Mismatch in reported PMK")
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
+        dut.cmd_check("sta_disconnect,interface," + ifname)
 
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2,ECGroupID,20" % (ifname, "test-sae", "12345678"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
-                            timeout=10)
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2,ECGroupID,20" % (ifname, "test-sae", "12345678"))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
+                      timeout=10)
+        dut.wait_connected()
+        dut.cmd_check("sta_get_ip_config,interface," + ifname)
         if dev[0].get_status_field('sae_group') != '20':
             raise Exception("Expected SAE group not used")
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.cmd_check("sta_disconnect,interface," + ifname)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_sae_groups(dev, apdev):
     """sigma_dut controlled SAE association with group negotiation"""
     check_sae_capab(dev[0])
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
+    with SigmaDut(ifname) as dut:
         ssid = "test-sae"
         params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
         params['wpa_key_mgmt'] = 'SAE'
@@ -372,29 +376,25 @@ def test_sigma_dut_sae_groups(dev, apdev):
         params['sae_groups'] = '19'
         hapd = hostapd.add_ap(apdev[0], params)
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2,ECGroupID,21 20 19" % (ifname, "test-sae", "12345678"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
-                            timeout=10)
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
+        dut.cmd_check("sta_reset_default,interface,%s" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2,ECGroupID,21 20 19" % (ifname, "test-sae", "12345678"))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
+                      timeout=10)
+        dut.wait_connected()
+        dut.cmd_check("sta_get_ip_config,interface," + ifname)
         if dev[0].get_status_field('sae_group') != '19':
             raise Exception("Expected default SAE group not used")
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
+        dut.cmd_check("sta_disconnect,interface," + ifname)
 
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_sae_pmkid_include(dev, apdev):
     """sigma_dut controlled SAE association with PMKID"""
     check_sae_capab(dev[0])
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
+    with SigmaDut(ifname) as dut:
         ssid = "test-sae"
         params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
         params['wpa_key_mgmt'] = 'SAE'
@@ -402,24 +402,20 @@ def test_sigma_dut_sae_pmkid_include(dev, apdev):
         params["sae_confirm_immediate"] = "1"
         hapd = hostapd.add_ap(apdev[0], params)
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2,PMKID_Include,enable" % (ifname, "test-sae", "12345678"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
-                            timeout=10)
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.cmd_check("sta_reset_default,interface,%s" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2,PMKID_Include,enable" % (ifname, "test-sae", "12345678"))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
+                      timeout=10)
+        dut.wait_connected()
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_sae_password(dev, apdev):
     """sigma_dut controlled SAE association and long password"""
     check_sae_capab(dev[0])
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
+    with SigmaDut(ifname) as dut:
         ssid = "test-sae"
         params = hostapd.wpa2_params(ssid=ssid)
         params['sae_password'] = 100*'B'
@@ -427,26 +423,22 @@ def test_sigma_dut_sae_password(dev, apdev):
         params["ieee80211w"] = "2"
         hapd = hostapd.add_ap(apdev[0], params)
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, "test-sae", 100*'B'))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
-                            timeout=10)
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.cmd_check("sta_reset_default,interface,%s" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, "test-sae", 100*'B'))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
+                      timeout=10)
+        dut.wait_connected()
+        dut.cmd_check("sta_get_ip_config,interface," + ifname)
+        dut.cmd_check("sta_disconnect,interface," + ifname)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_sae_pw_id(dev, apdev):
     """sigma_dut controlled SAE association with Password Identifier"""
     check_sae_capab(dev[0])
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
+    with SigmaDut(ifname) as dut:
         ssid = "test-sae"
         params = hostapd.wpa2_params(ssid=ssid)
         params['wpa_key_mgmt'] = 'SAE'
@@ -455,25 +447,21 @@ def test_sigma_dut_sae_pw_id(dev, apdev):
         params['sae_groups'] = '19'
         hapd = hostapd.add_ap(apdev[0], params)
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,AKMSuiteType,8;9,PasswordID,pw id" % (ifname, "test-sae", "secret"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
-                            timeout=10)
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.cmd_check("sta_reset_default,interface,%s" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,AKMSuiteType,8;9,PasswordID,pw id" % (ifname, "test-sae", "secret"))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
+                      timeout=10)
+        dut.wait_connected()
+        dut.cmd_check("sta_disconnect,interface," + ifname)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_sae_pw_id_pwe_loop(dev, apdev):
     """sigma_dut controlled SAE association with Password Identifier and forced PWE looping"""
     check_sae_capab(dev[0])
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         ssid = "test-sae"
         params = hostapd.wpa2_params(ssid=ssid)
         params['wpa_key_mgmt'] = 'SAE'
@@ -482,11 +470,11 @@ def test_sigma_dut_sae_pw_id_pwe_loop(dev, apdev):
         params['sae_groups'] = '19'
         hapd = hostapd.add_ap(apdev[0], params)
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,AKMSuiteType,8;9,PasswordID,pw id,sae_pwe,looping" % (ifname, "test-sae", "secret"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
-                            timeout=10)
+        dut.cmd_check("sta_reset_default,interface,%s" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,AKMSuiteType,8;9,PasswordID,pw id,sae_pwe,looping" % (ifname, "test-sae", "secret"))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
+                      timeout=10)
         for i in range(3):
             ev = dev[0].wait_event(["SME: Trying to authenticate",
                                     "CTRL-EVENT-CONNECTED"], timeout=10)
@@ -494,13 +482,10 @@ def test_sigma_dut_sae_pw_id_pwe_loop(dev, apdev):
                 raise Exception("Network selection result not indicated")
             if "CTRL-EVENT-CONNECTED" in ev:
                 raise Exception("Unexpected connection")
-        res = sigma_dut_cmd("sta_is_connected,interface," + ifname)
+        res = dut.run_cmd("sta_is_connected,interface," + ifname)
         if "connected,1" in res:
             raise Exception("Connection reported")
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
-        dev[0].set("sae_pwe", "0")
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_sae_pw_id_ft(dev, apdev):
     """sigma_dut controlled SAE association with Password Identifier and FT"""
@@ -514,9 +499,7 @@ def run_sigma_dut_sae_pw_id_ft(dev, apdev, over_ds=False):
     check_sae_capab(dev[0])
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
+    with SigmaDut(ifname) as dut:
         ssid = "test-sae"
         params = hostapd.wpa2_params(ssid=ssid)
         params['wpa_key_mgmt'] = 'SAE FT-SAE'
@@ -532,56 +515,52 @@ def run_sigma_dut_sae_pw_id_ft(dev, apdev, over_ds=False):
         params['r1kh'] = '00:00:00:00:00:00 00:00:00:00:00:00 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff'
         hapd = hostapd.add_ap(apdev[0], params)
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname)
+        dut.cmd_check("sta_reset_default,interface,%s" % ifname)
         if over_ds:
-            sigma_dut_cmd_check("sta_preset_testparameters,interface,%s,FT_DS,Enable" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,AKMSuiteType,8;9,PasswordID,id2" % (ifname, "test-sae", "pw2"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
-                            timeout=10)
-        sigma_dut_wait_connected(ifname)
+            dut.cmd_check("sta_preset_testparameters,interface,%s,FT_DS,Enable" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,AKMSuiteType,8;9,PasswordID,id2" % (ifname, "test-sae", "pw2"))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
+                      timeout=10)
+        dut.wait_connected()
 
         bssid = apdev[1]['bssid'].replace(':', '')
         params['nas_identifier'] = bssid + '.nas.example.com'
         params['r1_key_holder'] = bssid
         hapd2 = hostapd.add_ap(apdev[1], params)
         bssid = hapd2.own_addr()
-        sigma_dut_cmd_check("sta_reassoc,interface,%s,Channel,1,bssid,%s" % (ifname, bssid),
-                            timeout=20)
+        dut.cmd_check("sta_reassoc,interface,%s,Channel,1,bssid,%s" % (ifname, bssid),
+                      timeout=20)
         dev[0].wait_connected()
 
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.cmd_check("sta_disconnect,interface," + ifname)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_sta_override_rsne(dev, apdev):
     """sigma_dut and RSNE override on STA"""
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
+    with SigmaDut(ifname) as dut:
         ssid = "test-psk"
         params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
         hapd = hostapd.add_ap(apdev[0], params)
 
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
 
         tests = ["30120100000fac040100000fac040100000fac02",
                  "30140100000fac040100000fac040100000fac02ffff"]
         for test in tests:
-            sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,type,PSK,passphrase,%s,EncpType,aes-ccmp,KeyMgmtType,wpa2" % (ifname, "test-psk", "12345678"))
-            sigma_dut_cmd_check("dev_configure_ie,interface,%s,IE_Name,RSNE,Contents,%s" % (ifname, test))
-            sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-psk"),
-                                timeout=10)
-            sigma_dut_wait_connected(ifname)
-            sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
+            dut.cmd_check("sta_set_security,interface,%s,ssid,%s,type,PSK,passphrase,%s,EncpType,aes-ccmp,KeyMgmtType,wpa2" % (ifname, "test-psk", "12345678"))
+            dut.cmd_check("dev_configure_ie,interface,%s,IE_Name,RSNE,Contents,%s" % (ifname, test))
+            dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-psk"),
+                          timeout=10)
+            dut.wait_connected()
+            dut.cmd_check("sta_disconnect,interface," + ifname)
             dev[0].dump_monitor()
 
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,type,PSK,passphrase,%s,EncpType,aes-ccmp,KeyMgmtType,wpa2" % (ifname, "test-psk", "12345678"))
-        sigma_dut_cmd_check("dev_configure_ie,interface,%s,IE_Name,RSNE,Contents,300101" % ifname)
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-psk"),
-                            timeout=10)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,%s,type,PSK,passphrase,%s,EncpType,aes-ccmp,KeyMgmtType,wpa2" % (ifname, "test-psk", "12345678"))
+        dut.cmd_check("dev_configure_ie,interface,%s,IE_Name,RSNE,Contents,300101" % ifname)
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-psk"),
+                      timeout=10)
 
         ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
         if ev is None:
@@ -589,97 +568,74 @@ def test_sigma_dut_sta_override_rsne(dev, apdev):
         if "status_code=40" not in ev:
             raise Exception("Unexpected status code: " + ev)
 
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_ap_psk(dev, apdev):
     """sigma_dut controlled AP"""
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            dev[0].connect("test-psk", psk="12345678", scan_freq="2412")
+    with HWSimRadio() as (radio, iface), SigmaDut(iface) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678")
+        dut.cmd_check("ap_config_commit,NAME,AP")
 
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+        dev[0].connect("test-psk", psk="12345678", scan_freq="2412")
 
 def test_sigma_dut_ap_pskhex(dev, apdev, params):
     """sigma_dut controlled AP and PSKHEX"""
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_pskhex.sigma-hostapd")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            psk = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSKHEX," + psk)
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            dev[0].connect("test-psk", raw_psk=psk, scan_freq="2412")
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        psk = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSKHEX," + psk)
+        dut.cmd_check("ap_config_commit,NAME,AP")
 
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+        dev[0].connect("test-psk", raw_psk=psk, scan_freq="2412")
 
 def test_sigma_dut_ap_psk_sha256(dev, apdev, params):
     """sigma_dut controlled AP PSK SHA256"""
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_psk_sha256.sigma-hostapd")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK-256,PSK,12345678")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            dev[0].connect("test-psk", key_mgmt="WPA-PSK-SHA256",
-                           psk="12345678", scan_freq="2412")
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK-256,PSK,12345678")
+        dut.cmd_check("ap_config_commit,NAME,AP")
 
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+        dev[0].connect("test-psk", key_mgmt="WPA-PSK-SHA256",
+                       psk="12345678", scan_freq="2412")
 
 def test_sigma_dut_ap_psk_deauth(dev, apdev, params):
     """sigma_dut controlled AP and deauth commands"""
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_psk_deauth.sigma-hostapd")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678,PMF,Required")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            dev[0].connect("test-psk", key_mgmt="WPA-PSK-SHA256",
-                           psk="12345678", ieee80211w="2", scan_freq="2412")
-            addr = dev[0].own_addr()
-            dev[0].dump_monitor()
-
-            sigma_dut_cmd_check("ap_deauth_sta,NAME,AP,sta_mac_address," + addr)
-            ev = dev[0].wait_disconnected()
-            dev[0].dump_monitor()
-            if "locally_generated=1" in ev:
-                raise Exception("Unexpected disconnection reason")
-            dev[0].wait_connected()
-            dev[0].dump_monitor()
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678,PMF,Required")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        dev[0].connect("test-psk", key_mgmt="WPA-PSK-SHA256",
+                       psk="12345678", ieee80211w="2", scan_freq="2412")
+        addr = dev[0].own_addr()
+        dev[0].dump_monitor()
 
-            sigma_dut_cmd_check("ap_deauth_sta,NAME,AP,sta_mac_address," + addr + ",disconnect,silent")
-            ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5)
-            if ev and "locally_generated=1" not in ev:
-                raise Exception("Unexpected disconnection")
+        dut.cmd_check("ap_deauth_sta,NAME,AP,sta_mac_address," + addr)
+        ev = dev[0].wait_disconnected()
+        dev[0].dump_monitor()
+        if "locally_generated=1" in ev:
+            raise Exception("Unexpected disconnection reason")
+        dev[0].wait_connected()
+        dev[0].dump_monitor()
 
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+        dut.cmd_check("ap_deauth_sta,NAME,AP,sta_mac_address," + addr + ",disconnect,silent")
+        ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5)
+        if ev and "locally_generated=1" not in ev:
+            raise Exception("Unexpected disconnection")
 
 def test_sigma_dut_eap_ttls(dev, apdev, params):
     """sigma_dut controlled STA and EAP-TTLS parameters"""
@@ -711,63 +667,59 @@ def test_sigma_dut_eap_ttls(dev, apdev, params):
     hapd = hostapd.add_ap(apdev[0], params)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname, cert_path=logdir)
-
-    cmd = "sta_set_security,type,eapttls,interface,%s,ssid,%s,keymgmttype,wpa2,encType,AES-CCMP,PairwiseCipher,AES-CCMP-128,trustedRootCA,sigma_dut_eap_ttls.ca.pem,username,DOMAIN\mschapv2 user,password,password" % (ifname, ssid)
+    with SigmaDut(ifname, cert_path=logdir) as dut:
+        cmd = "sta_set_security,type,eapttls,interface,%s,ssid,%s,keymgmttype,wpa2,encType,AES-CCMP,PairwiseCipher,AES-CCMP-128,trustedRootCA,sigma_dut_eap_ttls.ca.pem,username,DOMAIN\mschapv2 user,password,password" % (ifname, ssid)
 
-    try:
         tests = ["",
                  ",Domain,server.w1.fi",
                  ",DomainSuffix,w1.fi",
                  ",DomainSuffix,server.w1.fi",
                  ",ServerCert,sigma_dut_eap_ttls.server.pem"]
         for extra in tests:
-            sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
-            sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-            sigma_dut_cmd_check(cmd + extra)
-            sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, ssid),
+            dut.cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
+            dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+            dut.cmd_check(cmd + extra)
+            dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, ssid),
                                 timeout=10)
-            sigma_dut_wait_connected(ifname)
-            sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
-            sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
-            sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
+            dut.wait_connected()
+            dut.cmd_check("sta_get_ip_config,interface," + ifname)
+            dut.cmd_check("sta_disconnect,interface," + ifname)
+            dut.cmd_check("sta_reset_default,interface," + ifname)
             dev[0].dump_monitor()
 
         tests = [",Domain,w1.fi",
                  ",DomainSuffix,example.com",
                  ",ServerCert,sigma_dut_eap_ttls.incorrect.pem"]
         for extra in tests:
-            sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
-            sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-            sigma_dut_cmd_check(cmd + extra)
-            sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, ssid),
+            dut.cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
+            dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+            dut.cmd_check(cmd + extra)
+            dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, ssid),
                                 timeout=10)
             ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=10)
             if ev is None:
                 raise Exception("Server certificate error not reported")
-            res = sigma_dut_cmd("sta_is_connected,interface," + ifname)
+            res = dut.run_cmd("sta_is_connected,interface," + ifname)
             if "connected,1" in res:
                 raise Exception("Unexpected connection reported")
-            sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
-            sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
+            dut.cmd_check("sta_disconnect,interface," + ifname)
+            dut.cmd_check("sta_reset_default,interface," + ifname)
             dev[0].dump_monitor()
-    finally:
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_suite_b(dev, apdev, params):
     """sigma_dut controlled STA Suite B"""
     check_suite_b_192_capa(dev)
     logdir = params['logdir']
 
-    with open("auth_serv/ec2-ca.pem", "r") as f:
-        with open(os.path.join(logdir, "suite_b_ca.pem"), "w") as f2:
-            f2.write(f.read())
+    with open("auth_serv/ec2-ca.pem", "r") as f, \
+         open(os.path.join(logdir, "suite_b_ca.pem"), "w") as f2:
+        f2.write(f.read())
 
-    with open("auth_serv/ec2-user.pem", "r") as f:
-        with open("auth_serv/ec2-user.key", "r") as f2:
-            with open(os.path.join(logdir, "suite_b.pem"), "w") as f3:
-                f3.write(f.read())
-                f3.write(f2.read())
+    with open("auth_serv/ec2-user.pem", "r") as f, \
+         open("auth_serv/ec2-user.key", "r") as f2, \
+         open(os.path.join(logdir, "suite_b.pem"), "w") as f3:
+        f3.write(f.read())
+        f3.write(f2.read())
 
     dev[0].flush_scan_cache()
     params = suite_b_as_params()
@@ -791,63 +743,55 @@ def test_sigma_dut_suite_b(dev, apdev, params):
     hapd = hostapd.add_ap(apdev[0], params)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname, cert_path=logdir)
-
-    try:
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_security,type,eaptls,interface,%s,ssid,%s,PairwiseCipher,AES-GCMP-256,GroupCipher,AES-GCMP-256,GroupMgntCipher,BIP-GMAC-256,keymgmttype,SuiteB,clientCertificate,suite_b.pem,trustedRootCA,suite_b_ca.pem,CertType,ECC" % (ifname, "test-suite-b"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-suite-b"),
+    with SigmaDut(ifname, cert_path=logdir) as dut:
+        dut.cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_security,type,eaptls,interface,%s,ssid,%s,PairwiseCipher,AES-GCMP-256,GroupCipher,AES-GCMP-256,GroupMgntCipher,BIP-GMAC-256,keymgmttype,SuiteB,clientCertificate,suite_b.pem,trustedRootCA,suite_b_ca.pem,CertType,ECC" % (ifname, "test-suite-b"))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-suite-b"),
                             timeout=10)
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.wait_connected()
+        dut.cmd_check("sta_get_ip_config,interface," + ifname)
+        dut.cmd_check("sta_disconnect,interface," + ifname)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_suite_b_rsa(dev, apdev, params):
     """sigma_dut controlled STA Suite B (RSA)"""
     check_suite_b_192_capa(dev)
     logdir = params['logdir']
 
-    with open("auth_serv/rsa3072-ca.pem", "r") as f:
-        with open(os.path.join(logdir, "suite_b_ca_rsa.pem"), "w") as f2:
-            f2.write(f.read())
+    with open("auth_serv/rsa3072-ca.pem", "r") as f, \
+         open(os.path.join(logdir, "suite_b_ca_rsa.pem"), "w") as f2:
+        f2.write(f.read())
 
-    with open("auth_serv/rsa3072-user.pem", "r") as f:
-        with open("auth_serv/rsa3072-user.key", "r") as f2:
-            with open(os.path.join(logdir, "suite_b_rsa.pem"), "w") as f3:
-                f3.write(f.read())
-                f3.write(f2.read())
+    with open("auth_serv/rsa3072-user.pem", "r") as f, \
+         open("auth_serv/rsa3072-user.key", "r") as f2, \
+         open(os.path.join(logdir, "suite_b_rsa.pem"), "w") as f3:
+        f3.write(f.read())
+        f3.write(f2.read())
 
     dev[0].flush_scan_cache()
     params = suite_b_192_rsa_ap_params()
     hapd = hostapd.add_ap(apdev[0], params)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname, cert_path=logdir)
-
-    cmd = "sta_set_security,type,eaptls,interface,%s,ssid,%s,PairwiseCipher,AES-GCMP-256,GroupCipher,AES-GCMP-256,GroupMgntCipher,BIP-GMAC-256,keymgmttype,SuiteB,clientCertificate,suite_b_rsa.pem,trustedRootCA,suite_b_ca_rsa.pem,CertType,RSA" % (ifname, "test-suite-b")
+    with SigmaDut(ifname, cert_path=logdir) as dut:
+        cmd = "sta_set_security,type,eaptls,interface,%s,ssid,%s,PairwiseCipher,AES-GCMP-256,GroupCipher,AES-GCMP-256,GroupMgntCipher,BIP-GMAC-256,keymgmttype,SuiteB,clientCertificate,suite_b_rsa.pem,trustedRootCA,suite_b_ca_rsa.pem,CertType,RSA" % (ifname, "test-suite-b")
 
-    try:
         tests = ["",
                  ",TLSCipher,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"]
         tls = dev[0].request("GET tls_library")
         if "run=BoringSSL" not in tls:
             tests += [",TLSCipher,TLS_DHE_RSA_WITH_AES_256_GCM_SHA384"]
         for extra in tests:
-            sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
-            sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-            sigma_dut_cmd_check(cmd + extra)
-            sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-suite-b"),
+            dut.cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
+            dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+            dut.cmd_check(cmd + extra)
+            dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-suite-b"),
                                 timeout=10)
-            sigma_dut_wait_connected(ifname)
-            sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
-            sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
-            sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+            dut.wait_connected()
+            dut.cmd_check("sta_get_ip_config,interface," + ifname)
+            dut.cmd_check("sta_disconnect,interface," + ifname)
+            dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_ap_suite_b(dev, apdev, params):
     """sigma_dut controlled AP Suite B"""
@@ -860,28 +804,23 @@ def test_sigma_dut_ap_suite_b(dev, apdev, params):
     params['private_key'] = 'auth_serv/ec2-server.key'
     params['openssl_ciphers'] = 'SUITEB192'
     hostapd.add_ap(apdev[1], params)
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-suite-b,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,18129,PASSWORD,radius")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,SuiteB")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192",
-                           ieee80211w="2",
-                           openssl_ciphers="SUITEB192",
-                           eap="TLS", identity="tls user",
-                           ca_cert="auth_serv/ec2-ca.pem",
-                           client_cert="auth_serv/ec2-user.pem",
-                           private_key="auth_serv/ec2-user.key",
-                           pairwise="GCMP-256", group="GCMP-256",
-                           scan_freq="2412")
-
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-suite-b,MODE,11ng")
+        dut.cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,18129,PASSWORD,radius")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,SuiteB")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192",
+                       ieee80211w="2",
+                       openssl_ciphers="SUITEB192",
+                       eap="TLS", identity="tls user",
+                       ca_cert="auth_serv/ec2-ca.pem",
+                       client_cert="auth_serv/ec2-user.pem",
+                       private_key="auth_serv/ec2-user.key",
+                       pairwise="GCMP-256", group="GCMP-256",
+                       scan_freq="2412")
 
 def test_sigma_dut_ap_cipher_gcmp_128(dev, apdev, params):
     """sigma_dut controlled AP with GCMP-128/BIP-GMAC-128 cipher"""
@@ -929,126 +868,102 @@ def run_sigma_dut_ap_cipher(dev, apdev, params, ap_pairwise, ap_group_mgmt,
     params['private_key'] = 'auth_serv/ec2-server.key'
     params['openssl_ciphers'] = 'SUITEB192'
     hostapd.add_ap(apdev[1], params)
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-suite-b,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,18129,PASSWORD,radius")
-            cmd = "ap_set_security,NAME,AP,KEYMGNT,SuiteB,PMF,Required,PairwiseCipher,%s,GroupMgntCipher,%s" % (ap_pairwise, ap_group_mgmt)
-            if ap_group:
-                cmd += ",GroupCipher,%s" % ap_group
-            sigma_dut_cmd_check(cmd)
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            if sta_cipher_group is None:
-                sta_cipher_group = sta_cipher
-            dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192",
-                           ieee80211w="2",
-                           openssl_ciphers="SUITEB192",
-                           eap="TLS", identity="tls user",
-                           ca_cert="auth_serv/ec2-ca.pem",
-                           client_cert="auth_serv/ec2-user.pem",
-                           private_key="auth_serv/ec2-user.key",
-                           pairwise=sta_cipher, group=sta_cipher_group,
-                           scan_freq="2412")
-
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
-
-def test_sigma_dut_ap_override_rsne(dev, apdev):
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-suite-b,MODE,11ng")
+        dut.cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,18129,PASSWORD,radius")
+        cmd = "ap_set_security,NAME,AP,KEYMGNT,SuiteB,PMF,Required,PairwiseCipher,%s,GroupMgntCipher,%s" % (ap_pairwise, ap_group_mgmt)
+        if ap_group:
+            cmd += ",GroupCipher,%s" % ap_group
+        dut.cmd_check(cmd)
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        if sta_cipher_group is None:
+            sta_cipher_group = sta_cipher
+        dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192",
+                       ieee80211w="2",
+                       openssl_ciphers="SUITEB192",
+                       eap="TLS", identity="tls user",
+                       ca_cert="auth_serv/ec2-ca.pem",
+                       client_cert="auth_serv/ec2-user.pem",
+                       private_key="auth_serv/ec2-user.key",
+                       pairwise=sta_cipher, group=sta_cipher_group,
+                       scan_freq="2412")
+
+def test_sigma_dut_ap_override_rsne(dev, apdev, params):
     """sigma_dut controlled AP overriding RSNE"""
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678")
-            sigma_dut_cmd_check("dev_configure_ie,NAME,AP,interface,%s,IE_Name,RSNE,Contents,30180100000fac040200ffffffff000fac040100000fac020c00" % iface)
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            dev[0].connect("test-psk", psk="12345678", scan_freq="2412")
+    logdir = params['prefix'] + ".sigma-hostapd"
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678")
+        dut.cmd_check("dev_configure_ie,NAME,AP,interface,%s,IE_Name,RSNE,Contents,30180100000fac040200ffffffff000fac040100000fac020c00" % iface)
+        dut.cmd_check("ap_config_commit,NAME,AP")
 
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+        dev[0].connect("test-psk", psk="12345678", scan_freq="2412")
 
 def test_sigma_dut_ap_sae(dev, apdev, params):
     """sigma_dut controlled AP with SAE"""
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_sae.sigma-hostapd")
     check_sae_capab(dev[0])
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        dev[0].request("SET sae_groups ")
+        id = dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
+                            ieee80211w="2", scan_freq="2412")
+        if dev[0].get_status_field('sae_group') != '19':
+            raise Exception("Expected default SAE group not used")
 
-            dev[0].request("SET sae_groups ")
-            id = dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
-                                ieee80211w="2", scan_freq="2412")
-            if dev[0].get_status_field('sae_group') != '19':
-                raise Exception("Expected default SAE group not used")
-
-            res = sigma_dut_cmd_check("ap_get_parameter,name,AP,STA_MAC_Address,%s,Parameter,PMK" % dev[0].own_addr())
-            logger.info("Reported PMK: " + res)
-            if ",PMK," not in res:
-                raise Exception("PMK not reported");
-            if dev[0].get_pmk(id) != res.split(',')[3]:
-                raise Exception("Mismatch in reported PMK")
-
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+        res = dut.cmd_check("ap_get_parameter,name,AP,STA_MAC_Address,%s,Parameter,PMK" % dev[0].own_addr())
+        logger.info("Reported PMK: " + res)
+        if ",PMK," not in res:
+            raise Exception("PMK not reported");
+        if dev[0].get_pmk(id) != res.split(',')[3]:
+            raise Exception("Mismatch in reported PMK")
 
 def test_sigma_dut_ap_sae_confirm_immediate(dev, apdev, params):
     """sigma_dut controlled AP with SAE Confirm immediate"""
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_sae_confirm_immediate.sigma-hostapd")
     check_sae_capab(dev[0])
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,SAE_Confirm_Immediate,enable")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            dev[0].request("SET sae_groups ")
-            dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
-                           ieee80211w="2", scan_freq="2412")
-            if dev[0].get_status_field('sae_group') != '19':
-                raise Exception("Expected default SAE group not used")
-
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,SAE_Confirm_Immediate,enable")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        dev[0].request("SET sae_groups ")
+        dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
+                       ieee80211w="2", scan_freq="2412")
+        if dev[0].get_status_field('sae_group') != '19':
+            raise Exception("Expected default SAE group not used")
 
 def test_sigma_dut_ap_sae_password(dev, apdev, params):
     """sigma_dut controlled AP with SAE and long password"""
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_sae_password.sigma-hostapd")
     check_sae_capab(dev[0])
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK," + 100*'C')
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            dev[0].request("SET sae_groups ")
-            dev[0].connect("test-sae", key_mgmt="SAE", sae_password=100*'C',
-                           ieee80211w="2", scan_freq="2412")
-            if dev[0].get_status_field('sae_group') != '19':
-                raise Exception("Expected default SAE group not used")
-
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK," + 100*'C')
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        dev[0].request("SET sae_groups ")
+        dev[0].connect("test-sae", key_mgmt="SAE", sae_password=100*'C',
+                       ieee80211w="2", scan_freq="2412")
+        if dev[0].get_status_field('sae_group') != '19':
+            raise Exception("Expected default SAE group not used")
 
 def test_sigma_dut_ap_sae_pw_id(dev, apdev, params):
     """sigma_dut controlled AP with SAE Password Identifier"""
@@ -1057,39 +972,34 @@ def test_sigma_dut_ap_sae_pw_id(dev, apdev, params):
     conffile = os.path.join(params['logdir'],
                             "sigma_dut_ap_sae_pw_id.sigma-conf")
     check_sae_capab(dev[0])
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,AKMSuiteType,8,SAEPasswords,pw1:id1;pw2:id2;pw3;pw4:id4,PMF,Required")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            with open("/tmp/sigma_dut-ap.conf", "rb") as f:
-                with open(conffile, "wb") as f2:
-                    f2.write(f.read())
-
-            dev[0].request("SET sae_groups ")
-            tests = [("pw1", "id1"),
-                     ("pw2", "id2"),
-                     ("pw3", None),
-                     ("pw4", "id4")]
-            for pw, pw_id in tests:
-                dev[0].connect("test-sae", key_mgmt="SAE", sae_password=pw,
-                               sae_password_id=pw_id,
-                               ieee80211w="2", scan_freq="2412")
-                # Allow some time for AP to complete handling of connection
-                # before disconnecting.
-                time.sleep(0.1)
-                dev[0].request("REMOVE_NETWORK all")
-                dev[0].wait_disconnected()
-                # Allow some time for AP to complete handling of disconnection
-                # before trying SAE again.
-                time.sleep(0.1)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,AKMSuiteType,8,SAEPasswords,pw1:id1;pw2:id2;pw3;pw4:id4,PMF,Required")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        with open("/tmp/sigma_dut-ap.conf", "rb") as f, \
+             open(conffile, "wb") as f2:
+            f2.write(f.read())
 
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+        dev[0].request("SET sae_groups ")
+        tests = [("pw1", "id1"),
+                 ("pw2", "id2"),
+                 ("pw3", None),
+                 ("pw4", "id4")]
+        for pw, pw_id in tests:
+            dev[0].connect("test-sae", key_mgmt="SAE", sae_password=pw,
+                           sae_password_id=pw_id,
+                           ieee80211w="2", scan_freq="2412")
+            # Allow some time for AP to complete handling of connection
+            # before disconnecting.
+            time.sleep(0.1)
+            dev[0].request("REMOVE_NETWORK all")
+            dev[0].wait_disconnected()
+            # Allow some time for AP to complete handling of disconnection
+            # before trying SAE again.
+            time.sleep(0.1)
 
 def test_sigma_dut_ap_sae_pw_id_pwe_loop(dev, apdev, params):
     """sigma_dut controlled AP with SAE Password Identifier and forced PWE looping"""
@@ -1098,33 +1008,28 @@ def test_sigma_dut_ap_sae_pw_id_pwe_loop(dev, apdev, params):
     conffile = os.path.join(params['logdir'],
                             "sigma_dut_ap_sae_pw_id_pwe_loop.sigma-conf")
     check_sae_capab(dev[0])
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,AKMSuiteType,8,SAEPasswords,12345678:pwid,PMF,Required,sae_pwe,looping")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            with open("/tmp/sigma_dut-ap.conf", "rb") as f:
-                with open(conffile, "wb") as f2:
-                    f2.write(f.read())
-
-            dev[0].set("sae_groups", "")
-            dev[0].connect("test-sae", key_mgmt="SAE", sae_password="12345678",
-                           sae_password_id="pwid",
-                           ieee80211w="2", scan_freq="2412", wait_connect=False)
-            ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND",
-                                    "CTRL-EVENT-CONNECTED"], timeout=10)
-            if ev is None:
-                raise Exception("Network selection result not indicated")
-            if "CTRL-EVENT-CONNECTED" in ev:
-                raise Exception("Unexpected connection")
-            dev[0].request("REMOVE_NETWORK all")
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,AKMSuiteType,8,SAEPasswords,12345678:pwid,PMF,Required,sae_pwe,looping")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        with open("/tmp/sigma_dut-ap.conf", "rb") as f, \
+             open(conffile, "wb") as f2:
+            f2.write(f.read())
 
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+        dev[0].set("sae_groups", "")
+        dev[0].connect("test-sae", key_mgmt="SAE", sae_password="12345678",
+                       sae_password_id="pwid",
+                       ieee80211w="2", scan_freq="2412", wait_connect=False)
+        ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND",
+                                "CTRL-EVENT-CONNECTED"], timeout=10)
+        if ev is None:
+            raise Exception("Network selection result not indicated")
+        if "CTRL-EVENT-CONNECTED" in ev:
+            raise Exception("Unexpected connection")
+        dev[0].request("REMOVE_NETWORK all")
 
 def test_sigma_dut_ap_sae_pw_id_ft(dev, apdev, params):
     """sigma_dut controlled AP with SAE Password Identifier and FT"""
@@ -1133,92 +1038,77 @@ def test_sigma_dut_ap_sae_pw_id_ft(dev, apdev, params):
     conffile = os.path.join(params['logdir'],
                             "sigma_dut_ap_sae_pw_id_ft.sigma-conf")
     check_sae_capab(dev[0])
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng,DOMAIN,aabb")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,AKMSuiteType,8;9,SAEPasswords,pw1:id1;pw2:id2;pw3;pw4:id4,PMF,Required")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            with open("/tmp/sigma_dut-ap.conf", "rb") as f:
-                with open(conffile, "wb") as f2:
-                    f2.write(f.read())
-
-            dev[0].request("SET sae_groups ")
-            tests = [("pw1", "id1", "SAE"),
-                     ("pw2", "id2", "FT-SAE"),
-                     ("pw3", None, "FT-SAE"),
-                     ("pw4", "id4", "SAE")]
-            for pw, pw_id, key_mgmt in tests:
-                dev[0].connect("test-sae", key_mgmt=key_mgmt, sae_password=pw,
-                               sae_password_id=pw_id,
-                               ieee80211w="2", scan_freq="2412")
-                # Allow some time for AP to complete handling of connection
-                # before disconnecting.
-                time.sleep(0.1)
-                dev[0].request("REMOVE_NETWORK all")
-                dev[0].wait_disconnected()
-                # Allow some time for AP to complete handling of disconnection
-                # before trying SAE again.
-                time.sleep(0.1)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng,DOMAIN,aabb")
+        dut.cmd_check("ap_set_security,NAME,AP,AKMSuiteType,8;9,SAEPasswords,pw1:id1;pw2:id2;pw3;pw4:id4,PMF,Required")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        with open("/tmp/sigma_dut-ap.conf", "rb") as f, \
+             open(conffile, "wb") as f2:
+            f2.write(f.read())
 
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+        dev[0].request("SET sae_groups ")
+        tests = [("pw1", "id1", "SAE"),
+                 ("pw2", "id2", "FT-SAE"),
+                 ("pw3", None, "FT-SAE"),
+                 ("pw4", "id4", "SAE")]
+        for pw, pw_id, key_mgmt in tests:
+            dev[0].connect("test-sae", key_mgmt=key_mgmt, sae_password=pw,
+                           sae_password_id=pw_id,
+                           ieee80211w="2", scan_freq="2412")
+            # Allow some time for AP to complete handling of connection
+            # before disconnecting.
+            time.sleep(0.1)
+            dev[0].request("REMOVE_NETWORK all")
+            dev[0].wait_disconnected()
+            # Allow some time for AP to complete handling of disconnection
+            # before trying SAE again.
+            time.sleep(0.1)
 
 def test_sigma_dut_ap_sae_group(dev, apdev, params):
     """sigma_dut controlled AP with SAE and specific group"""
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_sae_group.sigma-hostapd")
     check_sae_capab(dev[0])
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,ECGroupID,20")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            dev[0].request("SET sae_groups ")
-            dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
-                           ieee80211w="2", scan_freq="2412")
-            if dev[0].get_status_field('sae_group') != '20':
-                raise Exception("Expected SAE group not used")
-
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,ECGroupID,20")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        dev[0].request("SET sae_groups ")
+        dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
+                       ieee80211w="2", scan_freq="2412")
+        if dev[0].get_status_field('sae_group') != '20':
+            raise Exception("Expected SAE group not used")
 
 def test_sigma_dut_ap_psk_sae(dev, apdev, params):
     """sigma_dut controlled AP with PSK+SAE"""
     check_sae_capab(dev[0])
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_psk_sae.sigma-hostapd")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK-SAE,PSK,12345678")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            dev[2].request("SET sae_groups ")
-            dev[2].connect("test-sae", key_mgmt="SAE", psk="12345678",
-                           scan_freq="2412", ieee80211w="0", wait_connect=False)
-            dev[0].request("SET sae_groups ")
-            dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
-                           scan_freq="2412", ieee80211w="2")
-            dev[1].connect("test-sae", psk="12345678", scan_freq="2412")
-
-            ev = dev[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.1)
-            dev[2].request("DISCONNECT")
-            if ev is not None:
-                raise Exception("Unexpected connection without PMF")
-
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK-SAE,PSK,12345678")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        dev[2].request("SET sae_groups ")
+        dev[2].connect("test-sae", key_mgmt="SAE", psk="12345678",
+                       scan_freq="2412", ieee80211w="0", wait_connect=False)
+        dev[0].request("SET sae_groups ")
+        dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
+                       scan_freq="2412", ieee80211w="2")
+        dev[1].connect("test-sae", psk="12345678", scan_freq="2412")
+
+        ev = dev[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.1)
+        dev[2].request("DISCONNECT")
+        if ev is not None:
+            raise Exception("Unexpected connection without PMF")
 
 def test_sigma_dut_ap_psk_sae_ft(dev, apdev, params):
     """sigma_dut controlled AP with PSK, SAE, FT"""
@@ -1227,31 +1117,26 @@ def test_sigma_dut_ap_psk_sae_ft(dev, apdev, params):
     conffile = os.path.join(params['logdir'],
                             "sigma_dut_ap_psk_sae_ft.sigma-conf")
     check_sae_capab(dev[0])
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae-psk,MODE,11ng,DOMAIN,aabb")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,AKMSuiteType,2;4;6;8;9,PSK,12345678,PairwiseCipher,AES-CCMP-128,GroupCipher,AES-CCMP-128")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,DOMAIN,0101,FT_OA,Enable")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,FT_BSS_LIST," + apdev[1]['bssid'])
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae-psk,MODE,11ng,DOMAIN,aabb")
+        dut.cmd_check("ap_set_security,NAME,AP,AKMSuiteType,2;4;6;8;9,PSK,12345678,PairwiseCipher,AES-CCMP-128,GroupCipher,AES-CCMP-128")
+        dut.cmd_check("ap_set_wireless,NAME,AP,DOMAIN,0101,FT_OA,Enable")
+        dut.cmd_check("ap_set_wireless,NAME,AP,FT_BSS_LIST," + apdev[1]['bssid'])
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        with open("/tmp/sigma_dut-ap.conf", "rb") as f, \
+             open(conffile, "wb") as f2:
+            f2.write(f.read())
 
-            with open("/tmp/sigma_dut-ap.conf", "rb") as f:
-                with open(conffile, "wb") as f2:
-                    f2.write(f.read())
-
-            dev[0].request("SET sae_groups ")
-            dev[0].connect("test-sae-psk", key_mgmt="SAE FT-SAE",
-                           sae_password="12345678", scan_freq="2412")
-            dev[1].connect("test-sae-psk", key_mgmt="WPA-PSK FT-PSK",
-                           psk="12345678", scan_freq="2412")
-            dev[2].connect("test-sae-psk", key_mgmt="WPA-PSK",
-                           psk="12345678", scan_freq="2412")
-
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+        dev[0].request("SET sae_groups ")
+        dev[0].connect("test-sae-psk", key_mgmt="SAE FT-SAE",
+                       sae_password="12345678", scan_freq="2412")
+        dev[1].connect("test-sae-psk", key_mgmt="WPA-PSK FT-PSK",
+                       psk="12345678", scan_freq="2412")
+        dev[2].connect("test-sae-psk", key_mgmt="WPA-PSK",
+                       psk="12345678", scan_freq="2412")
 
 def test_sigma_dut_owe(dev, apdev):
     """sigma_dut controlled OWE station"""
@@ -1259,9 +1144,7 @@ def test_sigma_dut_owe(dev, apdev):
         raise HwsimSkip("OWE not supported")
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
+    with SigmaDut(ifname) as dut:
         params = {"ssid": "owe",
                   "wpa": "2",
                   "wpa_key_mgmt": "OWE",
@@ -1270,14 +1153,14 @@ def test_sigma_dut_owe(dev, apdev):
         hapd = hostapd.add_ap(apdev[0], params)
         bssid = hapd.own_addr()
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE" % ifname)
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname,
+        dut.cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE" % ifname)
+        dut.cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname,
                             timeout=10)
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
-        res = sigma_dut_cmd_check("sta_get_parameter,interface,%s,Parameter,PMK" % ifname)
+        dut.wait_connected()
+        dut.cmd_check("sta_get_ip_config,interface," + ifname)
+        res = dut.cmd_check("sta_get_parameter,interface,%s,Parameter,PMK" % ifname)
         logger.info("Reported PMK: " + res)
         if ",PMK," not in res:
             raise Exception("PMK not reported");
@@ -1285,38 +1168,36 @@ def test_sigma_dut_owe(dev, apdev):
             raise Exception("Mismatch in reported PMK")
 
         dev[0].dump_monitor()
-        sigma_dut_cmd("sta_reassoc,interface,%s,Channel,1,bssid,%s" % (ifname, bssid))
+        dut.run_cmd("sta_reassoc,interface,%s,Channel,1,bssid,%s" % (ifname, bssid))
         dev[0].wait_connected()
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
+        dut.cmd_check("sta_disconnect,interface," + ifname)
         dev[0].wait_disconnected()
         dev[0].dump_monitor()
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,20" % ifname)
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname,
+        dut.cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,20" % ifname)
+        dut.cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname,
                             timeout=10)
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
+        dut.wait_connected()
+        dut.cmd_check("sta_get_ip_config,interface," + ifname)
+        dut.cmd_check("sta_disconnect,interface," + ifname)
         dev[0].wait_disconnected()
         dev[0].dump_monitor()
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,0" % ifname)
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname,
+        dut.cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,0" % ifname)
+        dut.cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname,
                             timeout=10)
         ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
+        dut.cmd_check("sta_disconnect,interface," + ifname)
         if ev is None:
             raise Exception("Association not rejected")
         if "status_code=77" not in ev:
             raise Exception("Unexpected rejection reason: " + ev)
 
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_owe_ptk_workaround(dev, apdev):
     """sigma_dut controlled OWE station with PTK workaround"""
@@ -1333,18 +1214,14 @@ def test_sigma_dut_owe_ptk_workaround(dev, apdev):
     hapd = hostapd.add_ap(apdev[0], params)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname, owe_ptk_workaround=True)
-
-    try:
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,20" % ifname)
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname,
-                            timeout=10)
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+    with SigmaDut(ifname, owe_ptk_workaround=True) as dut:
+        dut.cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,20" % ifname)
+        dut.cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname,
+                      timeout=10)
+        dut.wait_connected()
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_ap_owe(dev, apdev, params):
     """sigma_dut controlled AP with OWE"""
@@ -1352,82 +1229,70 @@ def test_sigma_dut_ap_owe(dev, apdev, params):
                           "sigma_dut_ap_owe.sigma-hostapd")
     if "OWE" not in dev[0].get_capability("key_mgmt"):
         raise HwsimSkip("OWE not supported")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            id = dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
-                                scan_freq="2412")
-
-            res = sigma_dut_cmd_check("ap_get_parameter,name,AP,STA_MAC_Address,%s,Parameter,PMK" % dev[0].own_addr())
-            logger.info("Reported PMK: " + res)
-            if ",PMK," not in res:
-                raise Exception("PMK not reported");
-            if dev[0].get_pmk(id) != res.split(',')[3]:
-                raise Exception("Mismatch in reported PMK")
-
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        id = dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
+                            scan_freq="2412")
+
+        res = dut.cmd_check("ap_get_parameter,name,AP,STA_MAC_Address,%s,Parameter,PMK" % dev[0].own_addr())
+        logger.info("Reported PMK: " + res)
+        if ",PMK," not in res:
+            raise Exception("PMK not reported");
+        if dev[0].get_pmk(id) != res.split(',')[3]:
+            raise Exception("Mismatch in reported PMK")
 
-def test_sigma_dut_ap_owe_ecgroupid(dev, apdev):
+def test_sigma_dut_ap_owe_ecgroupid(dev, apdev, params):
     """sigma_dut controlled AP with OWE and ECGroupID"""
     if "OWE" not in dev[0].get_capability("key_mgmt"):
         raise HwsimSkip("OWE not supported")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface)
-        try:
-            sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE,ECGroupID,20 21,PMF,Required")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
-                           owe_group="20", scan_freq="2412")
-            dev[0].request("REMOVE_NETWORK all")
-            dev[0].wait_disconnected()
-
-            dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
-                           owe_group="21", scan_freq="2412")
-            dev[0].request("REMOVE_NETWORK all")
-            dev[0].wait_disconnected()
+    logdir = params['prefix'] + ".sigma-hostapd"
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE,ECGroupID,20 21,PMF,Required")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
+                       owe_group="20", scan_freq="2412")
+        dev[0].request("REMOVE_NETWORK all")
+        dev[0].wait_disconnected()
 
-            dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
-                           owe_group="19", scan_freq="2412", wait_connect=False)
-            ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
-            dev[0].request("DISCONNECT")
-            if ev is None:
-                raise Exception("Association not rejected")
-            if "status_code=77" not in ev:
-                raise Exception("Unexpected rejection reason: " + ev)
-            dev[0].dump_monitor()
+        dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
+                       owe_group="21", scan_freq="2412")
+        dev[0].request("REMOVE_NETWORK all")
+        dev[0].wait_disconnected()
 
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+        dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
+                       owe_group="19", scan_freq="2412", wait_connect=False)
+        ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
+        dev[0].request("DISCONNECT")
+        if ev is None:
+            raise Exception("Association not rejected")
+        if "status_code=77" not in ev:
+            raise Exception("Unexpected rejection reason: " + ev)
+        dev[0].dump_monitor()
 
-def test_sigma_dut_ap_owe_ptk_workaround(dev, apdev):
+def test_sigma_dut_ap_owe_ptk_workaround(dev, apdev, params):
     """sigma_dut controlled AP with OWE PTK workaround"""
     if "OWE" not in dev[0].get_capability("key_mgmt"):
         raise HwsimSkip("OWE not supported")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, owe_ptk_workaround=True)
-        try:
-            sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE,ECGroupID,20,PMF,Required")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
+    logdir = params['prefix'] + ".sigma-hostapd"
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, owe_ptk_workaround=True, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE,ECGroupID,20,PMF,Required")
+        dut.cmd_check("ap_config_commit,NAME,AP")
 
-            dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
-                           owe_group="20", owe_ptk_workaround="1",
-                           scan_freq="2412")
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+        dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
+                       owe_group="20", owe_ptk_workaround="1",
+                       scan_freq="2412")
 
 def test_sigma_dut_ap_owe_transition_mode(dev, apdev, params):
     """sigma_dut controlled AP with OWE and transition mode"""
@@ -1435,30 +1300,25 @@ def test_sigma_dut_ap_owe_transition_mode(dev, apdev, params):
         raise HwsimSkip("OWE not supported")
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_owe_transition_mode.sigma-hostapd")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,1,CHANNEL,1,SSID,owe,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,1,KEYMGNT,OWE")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,2,CHANNEL,1,SSID,owe,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,2,KEYMGNT,NONE")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            res1 = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,1,Interface,24G")
-            res2 = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,2,Interface,24G")
-
-            dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
-                           scan_freq="2412")
-            dev[1].connect("owe", key_mgmt="NONE", scan_freq="2412")
-            if dev[0].get_status_field('bssid') not in res1:
-                raise Exception("Unexpected ap_get_mac_address WLAN_TAG,1: " + res1)
-            if dev[1].get_status_field('bssid') not in res2:
-                raise Exception("Unexpected ap_get_mac_address WLAN_TAG,2: " + res2)
-
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
+        dut.cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,1,CHANNEL,1,SSID,owe,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,WLAN_TAG,1,KEYMGNT,OWE")
+        dut.cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,2,CHANNEL,1,SSID,owe,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,WLAN_TAG,2,KEYMGNT,NONE")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        res1 = dut.cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,1,Interface,24G")
+        res2 = dut.cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,2,Interface,24G")
+
+        dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
+                       scan_freq="2412")
+        dev[1].connect("owe", key_mgmt="NONE", scan_freq="2412")
+        if dev[0].get_status_field('bssid') not in res1:
+            raise Exception("Unexpected ap_get_mac_address WLAN_TAG,1: " + res1)
+        if dev[1].get_status_field('bssid') not in res2:
+            raise Exception("Unexpected ap_get_mac_address WLAN_TAG,2: " + res2)
 
 def test_sigma_dut_ap_owe_transition_mode_2(dev, apdev, params):
     """sigma_dut controlled AP with OWE and transition mode (2)"""
@@ -1466,30 +1326,25 @@ def test_sigma_dut_ap_owe_transition_mode_2(dev, apdev, params):
         raise HwsimSkip("OWE not supported")
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_owe_transition_mode_2.sigma-hostapd")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,1,CHANNEL,1,SSID,owe,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,1,KEYMGNT,NONE")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,2,CHANNEL,1,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,2,KEYMGNT,OWE")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            res1 = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,1,Interface,24G")
-            res2 = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,2,Interface,24G")
-
-            dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
-                           scan_freq="2412")
-            dev[1].connect("owe", key_mgmt="NONE", scan_freq="2412")
-            if dev[0].get_status_field('bssid') not in res2:
-                raise Exception("Unexpected ap_get_mac_address WLAN_TAG,2: " + res1)
-            if dev[1].get_status_field('bssid') not in res1:
-                raise Exception("Unexpected ap_get_mac_address WLAN_TAG,1: " + res2)
-
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
+        dut.cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,1,CHANNEL,1,SSID,owe,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,WLAN_TAG,1,KEYMGNT,NONE")
+        dut.cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,2,CHANNEL,1,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,WLAN_TAG,2,KEYMGNT,OWE")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        res1 = dut.cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,1,Interface,24G")
+        res2 = dut.cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,2,Interface,24G")
+
+        dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
+                       scan_freq="2412")
+        dev[1].connect("owe", key_mgmt="NONE", scan_freq="2412")
+        if dev[0].get_status_field('bssid') not in res2:
+            raise Exception("Unexpected ap_get_mac_address WLAN_TAG,2: " + res1)
+        if dev[1].get_status_field('bssid') not in res1:
+            raise Exception("Unexpected ap_get_mac_address WLAN_TAG,1: " + res2)
 
 def dpp_init_enrollee(dev, id1, enrollee_role):
     logger.info("Starting DPP initiator/enrollee in a thread")
@@ -1594,12 +1449,11 @@ def run_sigma_dut_dpp_qr_resp(dev, apdev, conf_idx, chan_list=None,
     min_ver = 3 if net_access_key_curve else 1
     check_dpp_capab(dev[0], min_ver=min_ver)
     check_dpp_capab(dev[1], min_ver=min_ver)
-    sigma = start_sigma_dut(dev[0].ifname, cert_path=cert_path)
-    try:
+    with SigmaDut(dev[0].ifname, cert_path=cert_path) as dut:
         cmd = "dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR"
         if chan_list:
             cmd += ",DPPChannelList," + chan_list
-        res = sigma_dut_cmd(cmd)
+        res = dut.run_cmd(cmd)
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
         hex = res.split(',')[3]
@@ -1620,14 +1474,12 @@ def run_sigma_dut_dpp_qr_resp(dev, apdev, conf_idx, chan_list=None,
             cmd += ",DPPStatusQuery,Yes"
         if net_access_key_curve:
             cmd += ",DPPNAKECC," + net_access_key_curve
-        res = sigma_dut_cmd(cmd, timeout=10)
+        res = dut.run_cmd(cmd, timeout=10)
         t.join()
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
         if status_query and "StatusResult,0" not in res:
             raise Exception("Status query did not succeed: " + res)
-    finally:
-        stop_sigma_dut(sigma)
 
 csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
 csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
@@ -1654,8 +1506,7 @@ def test_sigma_dut_dpp_qr_init_enrollee(dev, apdev):
     check_dpp_capab(dev[0])
     check_dpp_capab(dev[1])
     hapd = start_dpp_ap(apdev[0])
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev[0].ifname, dev=dev[0]) as dut:
         dev[0].set("dpp_config_processing", "2")
 
         cmd = "DPP_CONFIGURATOR_ADD key=" + csign
@@ -1673,24 +1524,20 @@ def test_sigma_dut_dpp_qr_init_enrollee(dev, apdev):
         if "OK" not in dev[1].request(cmd):
             raise Exception("Failed to start listen operation")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri0))
+        res = dut.run_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)
+        res = dut.run_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)
-    finally:
-        dev[0].set("dpp_config_processing", "0")
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_qr_init_enrollee_configurator(dev, apdev):
     """sigma_dut DPP/QR initiator as Enrollee (to become Configurator)"""
     check_dpp_capab(dev[0])
     check_dpp_capab(dev[1])
 
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev[0].ifname, dev=dev[0]) as dut:
         cmd = "DPP_CONFIGURATOR_ADD"
         res = dev[1].request(cmd)
         if "FAIL" in res:
@@ -1706,16 +1553,13 @@ def test_sigma_dut_dpp_qr_init_enrollee_configurator(dev, apdev):
         if "OK" not in dev[1].request(cmd):
             raise Exception("Failed to start listen operation")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri0))
+        res = dut.run_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,DPPNetworkRole,Configurator,DPPBS,QR,DPPTimeout,6", timeout=10)
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPNetworkRole,Configurator,DPPBS,QR,DPPTimeout,6", timeout=10)
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        dev[0].set("dpp_config_processing", "0")
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev):
     """sigma_dut DPP/QR (mutual) initiator as Enrollee"""
@@ -1737,9 +1581,8 @@ def run_sigma_dut_dpp_qr_mutual_init_enrollee_check(dev, apdev, extra='',
     check_dpp_capab(dev[1])
     hapd = start_dpp_ap(apdev[0])
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-    try:
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
+    with SigmaDut(ifname, dev=dev[0]) as dut:
+        dut.cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
 
         cmd = "DPP_CONFIGURATOR_ADD key=" + csign
         res = dev[1].request(cmd)
@@ -1756,7 +1599,7 @@ def run_sigma_dut_dpp_qr_mutual_init_enrollee_check(dev, apdev, extra='',
         if "OK" not in dev[1].request(cmd):
             raise Exception("Failed to start listen operation")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
         hex = res.split(',')[3]
@@ -1765,15 +1608,15 @@ def run_sigma_dut_dpp_qr_mutual_init_enrollee_check(dev, apdev, extra='',
 
         id1 = dev[1].dpp_qr_code(uri)
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri0))
+        res = dut.run_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)
 
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,%sDPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6,DPPWaitForConnect,Yes" % extra
         if mud_url:
             cmd += ",MUDURL," + mud_url
-        res = sigma_dut_cmd_check(cmd, timeout=10)
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
+        res = dut.cmd_check(cmd, timeout=10)
+        dut.cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
 
@@ -1783,9 +1626,6 @@ def run_sigma_dut_dpp_qr_mutual_init_enrollee_check(dev, apdev, extra='',
                 raise Exception("DPP MUD URL not reported")
             if ev.split(' ')[1] != mud_url:
                 raise Exception("Unexpected MUD URL value: " + ev)
-    finally:
-        dev[0].set("dpp_config_processing", "0")
-        stop_sigma_dut(sigma)
 
 def dpp_init_conf_mutual(dev, id1, conf_id, own_id=None):
     time.sleep(1)
@@ -1822,8 +1662,7 @@ def run_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev, extra=None):
     check_dpp_capab(dev[0])
     check_dpp_capab(dev[1])
     hapd = start_dpp_ap(apdev[0])
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev[0].ifname, dev=dev[0]) as dut:
         dev[0].set("dpp_config_processing", "2")
 
         cmd = "DPP_CONFIGURATOR_ADD key=" + csign
@@ -1835,7 +1674,7 @@ def run_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev, extra=None):
         id0 = dev[1].dpp_bootstrap_gen(chan="81/6", mac=True)
         uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
         hex = res.split(',')[3]
@@ -1844,7 +1683,7 @@ def run_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev, extra=None):
 
         id1 = dev[1].dpp_qr_code(uri)
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri0))
+        res = dut.run_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)
 
@@ -1855,25 +1694,21 @@ def run_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev, extra=None):
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Mutual,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,20,DPPWaitForConnect,Yes"
         if extra:
             cmd += extra
-        res = sigma_dut_cmd(cmd, timeout=25)
+        res = dut.run_cmd(cmd, timeout=25)
         t.join()
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        dev[0].set("dpp_config_processing", "0")
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_qr_mutual_resp_configurator(dev, apdev):
     """sigma_dut DPP/QR (mutual) responder as Configurator (NAK from URI)"""
     check_dpp_capab(dev[0], min_ver=3)
     check_dpp_capab(dev[1], min_ver=3)
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev[0].ifname) as dut:
         id0 = dev[1].dpp_bootstrap_gen(chan="81/6", mac=True,
                                        supported_curves="P-256:P-384:P-521")
         uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
         hex = res.split(',')[3]
@@ -1882,7 +1717,7 @@ def test_sigma_dut_dpp_qr_mutual_resp_configurator(dev, apdev):
 
         id1 = dev[1].dpp_qr_code(uri)
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri0))
+        res = dut.run_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)
 
@@ -1891,12 +1726,10 @@ def test_sigma_dut_dpp_qr_mutual_resp_configurator(dev, apdev):
         t.start()
 
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Mutual,DPPProvisioningRole,Configurator,DPPConfEnrolleeRole,STA,DPPConfIndex,1,DPPNAKECC,URI,DPPBS,QR,DPPTimeout,20"
-        res = sigma_dut_cmd(cmd, timeout=25)
+        res = dut.run_cmd(cmd, timeout=25)
         t.join()
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        stop_sigma_dut(sigma)
 
 def dpp_resp_conf_mutual(dev, conf_id, uri):
     logger.info("Starting DPP responder/configurator in a thread")
@@ -1932,8 +1765,7 @@ def run_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev, resp_pending):
     check_dpp_capab(dev[0])
     check_dpp_capab(dev[1])
     hapd = start_dpp_ap(apdev[0])
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev[0].ifname, dev=dev[0]) as dut:
         dev[0].set("dpp_config_processing", "2")
 
         cmd = "DPP_CONFIGURATOR_ADD key=" + csign
@@ -1945,7 +1777,7 @@ def run_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev, resp_pending):
         id0 = dev[1].dpp_bootstrap_gen(chan="81/6", mac=True)
         uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
         hex = res.split(',')[3]
@@ -1956,7 +1788,7 @@ def run_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev, resp_pending):
             dev[1].dpp_qr_code(uri)
             uri = None
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri0))
+        res = dut.run_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)
 
@@ -1966,13 +1798,10 @@ def run_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev, resp_pending):
 
         time.sleep(1)
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,10,DPPWaitForConnect,Yes"
-        res = sigma_dut_cmd(cmd, timeout=15)
+        res = dut.run_cmd(cmd, timeout=15)
         t.join()
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        dev[0].set("dpp_config_processing", "0")
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_qr_init_enrollee_psk(dev, apdev):
     """sigma_dut DPP/QR initiator as Enrollee (PSK)"""
@@ -1983,8 +1812,7 @@ def test_sigma_dut_dpp_qr_init_enrollee_psk(dev, apdev):
                                  passphrase="ThisIsDppPassphrase")
     hapd = hostapd.add_ap(apdev[0], params)
 
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         dev[0].set("dpp_config_processing", "2")
 
         cmd = "DPP_CONFIGURATOR_ADD"
@@ -2002,16 +1830,13 @@ def test_sigma_dut_dpp_qr_init_enrollee_psk(dev, apdev):
         if "OK" not in dev[1].request(cmd):
             raise Exception("Failed to start listen operation")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri0))
+        res = dut.run_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)
+        res = dut.run_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,NetworkConnectResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        dev[0].set("dpp_config_processing", "0")
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_qr_init_enrollee_sae(dev, apdev):
     """sigma_dut DPP/QR initiator as Enrollee (SAE)"""
@@ -2025,8 +1850,7 @@ def test_sigma_dut_dpp_qr_init_enrollee_sae(dev, apdev):
     params["ieee80211w"] = "2"
     hapd = hostapd.add_ap(apdev[0], params)
 
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         dev[0].set("dpp_config_processing", "2")
         dev[0].set("sae_groups", "")
 
@@ -2045,16 +1869,13 @@ def test_sigma_dut_dpp_qr_init_enrollee_sae(dev, apdev):
         if "OK" not in dev[1].request(cmd):
             raise Exception("Failed to start listen operation")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri0))
+        res = dut.run_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)
+        res = dut.run_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,NetworkConnectResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        dev[0].set("dpp_config_processing", "0")
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_qr_init_configurator_1(dev, apdev):
     """sigma_dut DPP/QR initiator as Configurator (conf index 1)"""
@@ -2131,8 +1952,7 @@ def run_sigma_dut_dpp_qr_init_configurator(dev, apdev, conf_idx,
     min_ver = 3 if net_access_key_curve else 1
     check_dpp_capab(dev[0], min_ver=min_ver)
     check_dpp_capab(dev[1], min_ver=min_ver)
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         supported_curves = None
         sign_curve = "P-256"
 
@@ -2152,7 +1972,7 @@ def run_sigma_dut_dpp_qr_init_configurator(dev, apdev, conf_idx,
         if "OK" not in dev[1].request(cmd):
             raise Exception("Failed to start listen operation")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri0))
+        res = dut.run_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)
 
@@ -2161,22 +1981,20 @@ def run_sigma_dut_dpp_qr_init_configurator(dev, apdev, conf_idx,
             cmd += ",DPPNAKECC," + net_access_key_curve
         if extra:
             cmd += "," + extra
-        res = sigma_dut_cmd(cmd)
+        res = dut.run_cmd(cmd)
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
         if mud_url and ",MUDURL," + mud_url not in res:
             raise Exception("Unexpected result (missing MUD URL): " + res)
-    finally:
-        dev[1].set("dpp_mud_url", "")
-        stop_sigma_dut(sigma)
+
+    dev[1].set("dpp_mud_url", "")
 
 def test_sigma_dut_dpp_incompatible_roles_init(dev, apdev):
     """sigma_dut DPP roles incompatible (Initiator)"""
     check_dpp_capab(dev[0])
     check_dpp_capab(dev[1])
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
+    with SigmaDut(dev=dev[0]) as dut:
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
         hex = res.split(',')[3]
@@ -2192,23 +2010,20 @@ def test_sigma_dut_dpp_incompatible_roles_init(dev, apdev):
         if "OK" not in dev[1].request(cmd):
             raise Exception("Failed to start listen operation")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri0))
+        res = dut.run_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)
 
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Mutual,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6"
-        res = sigma_dut_cmd(cmd)
+        res = dut.run_cmd(cmd)
         if "BootstrapResult,OK,AuthResult,ROLES_NOT_COMPATIBLE" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_curves_list(dev, apdev):
     """sigma_dut DPP URI curves list override"""
     check_dpp_capab(dev[0], min_ver=3)
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR,DPPURICurves,P-256:P-384:BP-384")
+    with SigmaDut(dev=dev[0]) as dut:
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR,DPPURICurves,P-256:P-384:BP-384")
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
         hex = res.split(',')[3]
@@ -2216,26 +2031,23 @@ def test_sigma_dut_dpp_curves_list(dev, apdev):
         logger.info("URI from sigma_dut: " + uri)
         if ";B:31" not in uri:
             raise Exception("Supported curves override did not work correctly")
-    finally:
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_enrollee_does_not_support_signing_curve(dev, apdev):
     """sigma_dut DPP and Enrollee URI curves list does not include the curve for C-sign-key"""
     check_dpp_capab(dev[0], min_ver=3)
     check_dpp_capab(dev[1], min_ver=3)
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         id1 = dev[1].dpp_bootstrap_gen(chan="81/6", mac=True,
                                        supported_curves="P-256:P-384")
         uri = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
         dev[1].dpp_listen(2437)
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri))
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri))
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
 
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-521,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6"
-        res = sigma_dut_cmd(cmd, timeout=10)
+        res = dut.run_cmd(cmd, timeout=10)
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,FAILED" not in res:
@@ -2246,26 +2058,23 @@ def test_sigma_dut_dpp_enrollee_does_not_support_signing_curve(dev, apdev):
             raise Exception("Enrollee did not report configuration result")
         if "DPP-CONF-RECEIVED" in ev:
             raise Exception("Enrollee reported configuration success")
-    finally:
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_enrollee_does_not_support_nak_curve(dev, apdev):
     """sigma_dut DPP and Enrollee URI curves list does not include the curve for C-sign-key"""
     check_dpp_capab(dev[0], min_ver=3)
     check_dpp_capab(dev[1], min_ver=3)
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         id1 = dev[1].dpp_bootstrap_gen(chan="81/6", mac=True,
                                        supported_curves="P-256:P-384")
         uri = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
         dev[1].dpp_listen(2437)
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri))
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri))
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
 
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPNAKECC,P-521,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6"
-        res = sigma_dut_cmd(cmd, timeout=10)
+        res = dut.run_cmd(cmd, timeout=10)
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
         ev = dev[1].wait_event(["DPP-CONF-RECEIVED", "DPP-CONF-FAILED"],
@@ -2274,8 +2083,6 @@ def test_sigma_dut_dpp_enrollee_does_not_support_nak_curve(dev, apdev):
             raise Exception("Enrollee did not report configuration result")
         if "DPP-CONF-RECEIVED" in ev:
             raise Exception("Enrollee reported configuration success")
-    finally:
-        stop_sigma_dut(sigma)
 
 def dpp_init_enrollee_mutual(dev, id1, own_id):
     logger.info("Starting DPP initiator/enrollee in a thread")
@@ -2293,10 +2100,9 @@ def test_sigma_dut_dpp_incompatible_roles_resp(dev, apdev):
     """sigma_dut DPP roles incompatible (Responder)"""
     check_dpp_capab(dev[0])
     check_dpp_capab(dev[1])
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         cmd = "dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR"
-        res = sigma_dut_cmd(cmd)
+        res = dut.run_cmd(cmd)
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
         hex = res.split(',')[3]
@@ -2308,19 +2114,17 @@ def test_sigma_dut_dpp_incompatible_roles_resp(dev, apdev):
         id0 = dev[1].dpp_bootstrap_gen(chan="81/6", mac=True)
         uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri0))
+        res = dut.run_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)
 
         t = threading.Thread(target=dpp_init_enrollee_mutual, args=(dev[1], id1, id0))
         t.start()
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Mutual,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6"
-        res = sigma_dut_cmd(cmd, timeout=10)
+        res = dut.run_cmd(cmd, timeout=10)
         t.join()
         if "BootstrapResult,OK,AuthResult,ROLES_NOT_COMPATIBLE" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_qr_enrollee_chirp(dev, apdev):
     """sigma_dut DPP/QR as chirping Enrollee"""
@@ -2335,11 +2139,10 @@ def run_sigma_dut_dpp_qr_enrollee_chirp(dev, apdev, extra=None):
     check_dpp_capab(dev[1])
     hapd = start_dpp_ap(apdev[0])
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-    try:
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
+    with SigmaDut(dev=dev[0]) as dut:
+        dut.cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
         cmd = "dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR"
-        res = sigma_dut_cmd_check(cmd)
+        res = dut.cmd_check(cmd)
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
         hex = res.split(',')[3]
@@ -2355,13 +2158,10 @@ def run_sigma_dut_dpp_qr_enrollee_chirp(dev, apdev, extra=None):
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,16,DPPWaitForConnect,Yes,DPPChirp,Enable"
         if extra:
             cmd += "," + extra
-        res = sigma_dut_cmd_check(cmd, timeout=20)
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
+        res = dut.cmd_check(cmd, timeout=20)
+        dut.cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        dev[0].set("dpp_config_processing", "0")
-        stop_sigma_dut(sigma)
 
 def dpp_enrollee_chirp(dev, id1):
     logger.info("Starting chirping Enrollee in a thread")
@@ -2379,39 +2179,35 @@ def test_sigma_dut_dpp_qr_configurator_chirp(dev, apdev):
     check_dpp_capab(dev[0])
     check_dpp_capab(dev[1])
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-    try:
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
+    with SigmaDut(dev=dev[0]) as dut:
+        dut.cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
 
         id1 = dev[1].dpp_bootstrap_gen(chan="81/1")
         uri = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
 
-        res = sigma_dut_cmd_check("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri))
+        res = dut.cmd_check("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri))
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
 
         t = threading.Thread(target=dpp_enrollee_chirp, args=(dev[1], id1))
         t.start()
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,16,DPPChirp,Enable,DPPChirpChannel,6", timeout=20)
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,16,DPPChirp,Enable,DPPChirpChannel,6", timeout=20)
         t.join()
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
+        dut.cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        dev[0].set("dpp_config_processing", "0")
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_ap_dpp_qr_enrollee_chirp(dev, apdev, params):
     """sigma_dut DPP/QR AP as chirping Enrollee"""
     check_dpp_capab(dev[0], min_ver=2)
     check_dpp_capab(dev[1])
     logdir = params['prefix'] + ".sigma-hostapd"
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
         try:
-            sigma_dut_cmd_check("ap_reset_default,program,DPP")
+            dut.cmd_check("ap_reset_default,program,DPP")
             cmd = "dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR"
-            res = sigma_dut_cmd_check(cmd)
+            res = dut.cmd_check(cmd)
             if "status,COMPLETE" not in res:
                 raise Exception("dev_exec_action did not succeed: " + res)
             hex = res.split(',')[3]
@@ -2424,7 +2220,7 @@ def test_sigma_dut_ap_dpp_qr_enrollee_chirp(dev, apdev, params):
                                  ssid="DPPNET01")
             dev[0].dpp_listen(2437)
 
-            res = sigma_dut_cmd_check("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,16,DPPChirp,Enable", timeout=20)
+            res = dut.cmd_check("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,16,DPPChirp,Enable", timeout=20)
             if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
                 raise Exception("Unexpected result: " + res)
 
@@ -2435,18 +2231,14 @@ def test_sigma_dut_ap_dpp_qr_enrollee_chirp(dev, apdev, params):
             dev[0].dpp_auth_init(uri=uri, conf="sta-dpp", ssid="DPPNET01",
                                  configurator=conf_id)
             dev[1].wait_connected(timeout=20)
-
-            sigma_dut_cmd_check("ap_reset_default,program,DPP")
         finally:
             dev[1].set("dpp_config_processing", "0", allow_fail=True)
-            stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_pkex_init_configurator(dev, apdev):
     """sigma_dut DPP/PKEX initiator as Configurator"""
     check_dpp_capab(dev[0])
     check_dpp_capab(dev[1])
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         id1 = dev[1].dpp_bootstrap_gen(type="pkex")
         cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id1)
         res = dev[1].request(cmd)
@@ -2456,18 +2248,15 @@ def test_sigma_dut_dpp_pkex_init_configurator(dev, apdev):
         if "OK" not in dev[1].request(cmd):
             raise Exception("Failed to start listen operation")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6")
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6")
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_pkex_init_configurator_tcp(dev, apdev):
     """sigma_dut DPP/PKEX initiator as Configurator (TCP)"""
     check_dpp_capab(dev[0], min_ver=3)
     check_dpp_capab(dev[1], min_ver=3)
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         cmd = "DPP_CONTROLLER_START"
         res = dev[1].request(cmd)
         if "FAIL" in res:
@@ -2478,11 +2267,9 @@ def test_sigma_dut_dpp_pkex_init_configurator_tcp(dev, apdev):
         if "FAIL" in res:
             raise Exception("Failed to set PKEX data (responder)")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6,DPPOverTCP,127.0.0.1")
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6,DPPOverTCP,127.0.0.1")
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_pkex_init_configurator_tcp_through_relay(dev, apdev):
     """sigma_dut DPP/PKEX initiator as Configurator (TCP) through Relay"""
@@ -2492,8 +2279,7 @@ def test_sigma_dut_dpp_pkex_init_configurator_tcp_through_relay(dev, apdev):
     hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured", "channel": "6"})
     check_dpp_capab(hapd)
 
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         # PKEX init (AP Enrollee) over air
         id1 = hapd.dpp_bootstrap_gen(type="pkex")
         cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id1)
@@ -2501,7 +2287,7 @@ def test_sigma_dut_dpp_pkex_init_configurator_tcp_through_relay(dev, apdev):
         if "FAIL" in res:
             raise Exception("Failed to set PKEX data (responder AP)")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,AP,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6")
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,AP,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6")
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
         update_hapd_config(hapd)
@@ -2525,7 +2311,7 @@ def test_sigma_dut_dpp_pkex_init_configurator_tcp_through_relay(dev, apdev):
         if "FAIL" in res:
             raise Exception("Failed to set PKEX data (responder)")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6,DPPOverTCP,127.0.0.1 tcp_port=8909")
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6,DPPOverTCP,127.0.0.1 tcp_port=8909")
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
 
@@ -2541,7 +2327,7 @@ def test_sigma_dut_dpp_pkex_init_configurator_tcp_through_relay(dev, apdev):
         if "OK" not in dev[1].request("DPP_RECONFIG %s" % network):
             raise Exception("Failed to start reconfiguration")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,DPPReconfigure,DPPCryptoIdentifier,P-256,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPConfEnrolleeRole,STA,DPPTimeout,6,DPPSigningKeyECC,P-256,DPPOverTCP,yes", timeout=10)
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,DPPReconfigure,DPPCryptoIdentifier,P-256,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPConfEnrolleeRole,STA,DPPTimeout,6,DPPSigningKeyECC,P-256,DPPOverTCP,yes", timeout=10)
         if "ReconfigAuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected reconfiguration result: " + res)
 
@@ -2552,9 +2338,8 @@ def test_sigma_dut_dpp_pkex_init_configurator_tcp_through_relay(dev, apdev):
         if network == network2:
             raise Exception("Network ID did not change")
         dev[1].wait_connected()
-    finally:
-        stop_sigma_dut(sigma)
-        dev[1].set("dpp_config_processing", "0", allow_fail=True)
+
+    dev[1].set("dpp_config_processing", "0", allow_fail=True)
 
 def test_sigma_dut_dpp_pkex_init_configurator_tcp_and_wifi(dev, apdev):
     """sigma_dut DPP/PKEX initiator as Configurator over TCP and Wi-Fi"""
@@ -2564,8 +2349,7 @@ def test_sigma_dut_dpp_pkex_init_configurator_tcp_and_wifi(dev, apdev):
     hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured", "channel": "6"})
     check_dpp_capab(hapd)
 
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         # PKEX init (AP Enrollee) over air
         id1 = hapd.dpp_bootstrap_gen(type="pkex")
         cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id1)
@@ -2573,7 +2357,7 @@ def test_sigma_dut_dpp_pkex_init_configurator_tcp_and_wifi(dev, apdev):
         if "FAIL" in res:
             raise Exception("Failed to set PKEX data (responder AP)")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,AP,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6")
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,AP,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6")
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
         ev = hapd.wait_event(["DPP-CONF-RECEIVED"], timeout=1)
@@ -2598,7 +2382,7 @@ def test_sigma_dut_dpp_pkex_init_configurator_tcp_and_wifi(dev, apdev):
         if "FAIL" in res:
             raise Exception("Failed to set PKEX data (responder)")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6,DPPOverTCP,127.0.0.1")
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6,DPPOverTCP,127.0.0.1")
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
 
@@ -2616,7 +2400,7 @@ def test_sigma_dut_dpp_pkex_init_configurator_tcp_and_wifi(dev, apdev):
         if "FAIL" in res:
             raise Exception("Failed to set PKEX data (responder)")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6")
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6")
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
 
@@ -2638,7 +2422,7 @@ def test_sigma_dut_dpp_pkex_init_configurator_tcp_and_wifi(dev, apdev):
         # the Controller over the air.
         dev[0].dpp_listen(2437)
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6,DPPOverTCP,127.0.0.1")
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6,DPPOverTCP,127.0.0.1")
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
 
@@ -2647,8 +2431,6 @@ def test_sigma_dut_dpp_pkex_init_configurator_tcp_and_wifi(dev, apdev):
             raise Exception("STA(3) Enrollee did not report success")
         dev[1].request("DPP_STOP_LISTEN")
         dev[1].dump_monitor()
-    finally:
-        stop_sigma_dut(sigma)
 
 def dpp_pkex_resp_start_on_v1(dev):
     while True:
@@ -2667,28 +2449,24 @@ def dpp_pkex_resp_start_on_v1(dev):
 def test_sigma_dut_dpp_pkexv2_init_fallback_to_v1(dev, apdev):
     """sigma_dut DPP/PKEXv2 initiator and fallback to v1"""
     check_dpp_capab(dev[0], min_ver=3)
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         cmd = "DPP_LISTEN 2437 role=enrollee"
         if "OK" not in dev[1].request(cmd):
             raise Exception("Failed to start listen operation")
         t = threading.Thread(target=dpp_pkex_resp_start_on_v1, args=(dev[1],))
         t.start()
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,30",
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,30",
                             timeout=31)
         t.join()
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_pkex_v1_only(dev, apdev):
     """sigma_dut DPP/PKEX as v1 only initiator"""
     check_dpp_capab(dev[0])
     check_dpp_capab(dev[1])
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         id1 = dev[1].dpp_bootstrap_gen(type="pkex")
         cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id1)
         res = dev[1].request(cmd)
@@ -2698,11 +2476,9 @@ def test_sigma_dut_dpp_pkex_v1_only(dev, apdev):
         if "OK" not in dev[1].request(cmd):
             raise Exception("Failed to start listen operation")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEXv1,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6")
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEXv1,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6")
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_pkex_v1_only_responder(dev, apdev):
     """sigma_dut DPP/PKEX as v1 only responder"""
@@ -2728,19 +2504,16 @@ def dpp_init_enrollee_pkex(dev):
 def run_sigma_dut_dpp_pkex_responder(dev, apdev, v1=False):
     check_dpp_capab(dev[0])
     check_dpp_capab(dev[1])
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,DPP" %
+    with SigmaDut(dev=dev[0]) as dut:
+        dut.cmd_check("sta_reset_default,interface,%s,prog,DPP" %
                             dev[0].ifname)
         t = threading.Thread(target=dpp_init_enrollee_pkex, args=(dev[1],))
         t.start()
         dppbs = "PKEXv1" if v1 else "PKEX"
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,%s,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,16" % dppbs, timeout=20)
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,%s,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,16" % dppbs, timeout=20)
         t.join()
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        stop_sigma_dut(sigma)
 
 def dpp_init_conf(dev, id1, conf, conf_id, extra):
     time.sleep(1)
@@ -2793,11 +2566,11 @@ def run_sigma_dut_ap_dpp_qr(dev, apdev, params, ap_conf, sta_conf, extra="",
     if "sae" in sta_conf:
         check_sae_capab(dev[1])
     logdir = params['prefix'] + ".sigma-hostapd"
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
         try:
-            sigma_dut_cmd_check("ap_reset_default,program,DPP")
-            res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
+            dut.cmd_check("ap_reset_default,program,DPP")
+            res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
             if "status,COMPLETE" not in res:
                 raise Exception("dev_exec_action did not succeed: " + res)
             hex = res.split(',')[3]
@@ -2818,7 +2591,7 @@ def run_sigma_dut_ap_dpp_qr(dev, apdev, params, ap_conf, sta_conf, extra="",
             cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6"
             if mud_url:
                 cmd += ",MUDURL,https://example.com/mud"
-            res = sigma_dut_cmd(cmd)
+            res = dut.run_cmd(cmd)
             t.join()
             if "ConfResult,OK" not in res:
                 raise Exception("Unexpected result: " + res)
@@ -2837,22 +2610,19 @@ def run_sigma_dut_ap_dpp_qr(dev, apdev, params, ap_conf, sta_conf, extra="",
             if "OK" not in dev[0].request(cmd):
                 raise Exception("Failed to initiate DPP Authentication")
             dev[1].wait_connected(timeout=20)
-
-            sigma_dut_cmd_check("ap_reset_default")
         finally:
             dev[1].set("dpp_config_processing", "0")
-            stop_sigma_dut(sigma)
 
 def test_sigma_dut_ap_dpp_offchannel(dev, apdev, params):
     """sigma_dut controlled AP doing DPP on offchannel"""
     check_dpp_capab(dev[0])
     logdir = params['prefix'] + ".sigma-hostapd"
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
         try:
-            sigma_dut_cmd_check("ap_reset_default,program,DPP")
-            sigma_dut_cmd_check("ap_preset_testparameters,Program,DPP,Oper_Chn,3")
-            res = sigma_dut_cmd_check("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
+            dut.cmd_check("ap_reset_default,program,DPP")
+            dut.cmd_check("ap_preset_testparameters,Program,DPP,Oper_Chn,3")
+            res = dut.cmd_check("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
             hex = res.split(',')[3]
             uri = from_hex(hex)
             logger.info("URI from sigma_dut: " + uri)
@@ -2871,11 +2641,11 @@ def test_sigma_dut_ap_dpp_offchannel(dev, apdev, params):
                        "conf=ap-dpp ssid=%s configurator=%d" % (to_hex("DPPNET01"), conf_id))
             dev[0].dpp_listen(2442)
 
-            res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri0))
+            res = dut.run_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")
+            res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6")
             if "ConfResult,OK" not in res:
                 raise Exception("Unexpected result: " + res)
 
@@ -2892,18 +2662,15 @@ def test_sigma_dut_ap_dpp_offchannel(dev, apdev, params):
             if "OK" not in dev[0].request(cmd):
                 raise Exception("Failed to initiate DPP Authentication")
             dev[1].wait_connected(timeout=20)
-
-            sigma_dut_cmd_check("ap_reset_default")
         finally:
             dev[1].set("dpp_config_processing", "0")
-            stop_sigma_dut(sigma)
 
 def test_sigma_dut_ap_dpp_init_mud_url(dev, apdev, params):
     """sigma_dut controlled AP doing DPP init with MUD URL"""
     check_dpp_capab(dev[0])
     logdir = params['prefix'] + ".sigma-hostapd"
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
         try:
             cmd = "DPP_CONFIGURATOR_ADD"
             res = dev[0].request(cmd)
@@ -2917,15 +2684,15 @@ def test_sigma_dut_ap_dpp_init_mud_url(dev, apdev, params):
                        "conf=ap-dpp ssid=%s configurator=%d" % (to_hex("DPPNET01"), conf_id))
             dev[0].dpp_listen(2442)
 
-            sigma_dut_cmd_check("ap_reset_default,program,DPP")
-            res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri0))
+            dut.cmd_check("ap_reset_default,program,DPP")
+            res = dut.run_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)
 
             cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6"
             mud_url = "https://example.com/mud"
             cmd += ",MUDURL," + mud_url
-            res = sigma_dut_cmd(cmd)
+            res = dut.run_cmd(cmd)
             if "ConfResult,OK" not in res:
                 raise Exception("Unexpected result: " + res)
             ev = dev[0].wait_event(["DPP-MUD-URL"], timeout=10)
@@ -2947,34 +2714,25 @@ def test_sigma_dut_ap_dpp_init_mud_url(dev, apdev, params):
             if "OK" not in dev[0].request(cmd):
                 raise Exception("Failed to initiate DPP Authentication")
             dev[1].wait_connected(timeout=20)
-
-            sigma_dut_cmd_check("ap_reset_default")
         finally:
             dev[1].set("dpp_config_processing", "0")
-            stop_sigma_dut(sigma)
 
 def test_sigma_dut_ap_dpp_pkex_responder(dev, apdev, params):
     """sigma_dut controlled AP as DPP PKEX responder"""
     check_dpp_capab(dev[0])
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_dpp_pkex_responder.sigma-hostapd")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            run_sigma_dut_ap_dpp_pkex_responder(dev, apdev)
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        run_sigma_dut_ap_dpp_pkex_responder(dut, dev, apdev)
 
 def test_sigma_dut_ap_dpp_pkex_v1_responder(dev, apdev, params):
     """sigma_dut controlled AP as DPP PKEXv1 responder"""
     check_dpp_capab(dev[0])
     logdir = params['prefix'] + ".sigma-hostapd"
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            run_sigma_dut_ap_dpp_pkex_responder(dev, apdev, v1=True)
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        run_sigma_dut_ap_dpp_pkex_responder(dut, dev, apdev, v1=True)
 
 def dpp_init_conf_pkex(dev, conf_id, check_config=True):
     logger.info("Starting DPP PKEX initiator/configurator in a thread")
@@ -2991,8 +2749,8 @@ def dpp_init_conf_pkex(dev, conf_id, check_config=True):
         raise Exception("DPP configuration not completed (Configurator)")
     logger.info("DPP initiator/configurator done")
 
-def run_sigma_dut_ap_dpp_pkex_responder(dev, apdev, v1=False):
-    sigma_dut_cmd_check("ap_reset_default,program,DPP")
+def run_sigma_dut_ap_dpp_pkex_responder(dut, dev, apdev, v1=False):
+    dut.cmd_check("ap_reset_default,program,DPP")
 
     cmd = "DPP_CONFIGURATOR_ADD"
     res = dev[0].request(cmd)
@@ -3003,24 +2761,19 @@ def run_sigma_dut_ap_dpp_pkex_responder(dev, apdev, v1=False):
     t = threading.Thread(target=dpp_init_conf_pkex, args=(dev[0], conf_id))
     t.start()
     dppbs = "PKEXv1" if v1 else "PKEX"
-    res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Mutual,DPPProvisioningRole,Enrollee,DPPBS,%s,DPPPKEXCode,password,DPPTimeout,16,DPPWaitForConnect,No" % dppbs,
-                        timeout=20)
+    res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Mutual,DPPProvisioningRole,Enrollee,DPPBS,%s,DPPPKEXCode,password,DPPTimeout,16,DPPWaitForConnect,No" % dppbs,
+                      timeout=20)
     t.join()
     if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
         raise Exception("Unexpected result: " + res)
 
-    sigma_dut_cmd_check("ap_reset_default")
-
 def test_sigma_dut_ap_dpp_pkex_responder_tcp(dev, apdev, params):
     """sigma_dut controlled AP as DPP PKEX responder (TCP)"""
     check_dpp_capab(dev[0], min_ver=3)
     logdir = params['prefix'] + ".sigma-hostapd"
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            run_sigma_dut_ap_dpp_pkex_responder_tcp(dev, apdev)
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        run_sigma_dut_ap_dpp_pkex_responder_tcp(dut, dev, apdev)
 
 def dpp_init_conf_pkex_tcp(dev, conf_id, check_config=True):
     logger.info("Starting DPP PKEX initiator/configurator in a thread")
@@ -3037,8 +2790,8 @@ def dpp_init_conf_pkex_tcp(dev, conf_id, check_config=True):
         raise Exception("DPP configuration not completed (Configurator)")
     logger.info("DPP initiator/configurator done")
 
-def run_sigma_dut_ap_dpp_pkex_responder_tcp(dev, apdev):
-    sigma_dut_cmd_check("ap_reset_default,program,DPP")
+def run_sigma_dut_ap_dpp_pkex_responder_tcp(dut, dev, apdev):
+    dut.cmd_check("ap_reset_default,program,DPP")
 
     cmd = "DPP_CONFIGURATOR_ADD"
     res = dev[0].request(cmd)
@@ -3048,23 +2801,18 @@ def run_sigma_dut_ap_dpp_pkex_responder_tcp(dev, apdev):
 
     t = threading.Thread(target=dpp_init_conf_pkex_tcp, args=(dev[0], conf_id))
     t.start()
-    res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPProvisioningRole,Enrollee,DPPBS,PKEX,DPPPKEXCode,password,DPPOverTCP,yes,DPPTimeout,6,DPPWaitForConnect,No", timeout=10)
+    res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPProvisioningRole,Enrollee,DPPBS,PKEX,DPPPKEXCode,password,DPPOverTCP,yes,DPPTimeout,6,DPPWaitForConnect,No", timeout=10)
     t.join()
     if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
         raise Exception("Unexpected result: " + res)
 
-    sigma_dut_cmd_check("ap_reset_default")
-
 def test_sigma_dut_dpp_pkex_responder_proto(dev, apdev):
     """sigma_dut controlled STA as DPP PKEX responder and error case"""
     check_dpp_capab(dev[0])
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
-        run_sigma_dut_dpp_pkex_responder_proto(dev, apdev)
-    finally:
-        stop_sigma_dut(sigma)
+    with SigmaDut(dev=dev[0]) as dut:
+        run_sigma_dut_dpp_pkex_responder_proto(dut, dev, apdev)
 
-def run_sigma_dut_dpp_pkex_responder_proto(dev, apdev):
+def run_sigma_dut_dpp_pkex_responder_proto(dut, dev, apdev):
     cmd = "DPP_CONFIGURATOR_ADD"
     res = dev[1].request(cmd)
     if "FAIL" in res:
@@ -3076,7 +2824,7 @@ def run_sigma_dut_dpp_pkex_responder_proto(dev, apdev):
     t = threading.Thread(target=dpp_init_conf_pkex, args=(dev[1], conf_id,
                                                           False))
     t.start()
-    res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPProvisioningRole,Enrollee,DPPBS,PKEX,DPPPKEXCode,password,DPPTimeout,6", timeout=10)
+    res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPProvisioningRole,Enrollee,DPPBS,PKEX,DPPPKEXCode,password,DPPTimeout,6", timeout=10)
     t.join()
     if "BootstrapResult,Timeout" not in res:
         raise Exception("Unexpected result: " + res)
@@ -3116,14 +2864,12 @@ def test_sigma_dut_dpp_proto_initiator(dev, apdev):
     for step, frame, attr, result, fail in tests:
         dev[0].request("FLUSH")
         dev[1].request("FLUSH")
-        sigma = start_sigma_dut(dev[0].ifname)
-        try:
-            run_sigma_dut_dpp_proto_initiator(dev, step, frame, attr, result,
-                                              fail)
-        finally:
-            stop_sigma_dut(sigma)
+        with SigmaDut(dev=dev[0]) as dut:
+            run_sigma_dut_dpp_proto_initiator(dut, dev, step, frame, attr,
+                                              result, fail)
 
-def run_sigma_dut_dpp_proto_initiator(dev, step, frame, attr, result, fail):
+def run_sigma_dut_dpp_proto_initiator(dut, dev, step, frame, attr, result,
+                                      fail):
     id0 = dev[1].dpp_bootstrap_gen(chan="81/6", mac=True)
     uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
 
@@ -3131,11 +2877,11 @@ def run_sigma_dut_dpp_proto_initiator(dev, step, frame, attr, result, fail):
     if "OK" not in dev[1].request(cmd):
         raise Exception("Failed to start listen operation")
 
-    res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri0))
+    res = dut.run_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,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6,DPPStep,%s,DPPFrameType,%s,DPPIEAttribute,%s" % (step, frame, attr),
+    res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6,DPPStep,%s,DPPFrameType,%s,DPPIEAttribute,%s" % (step, frame, attr),
                         timeout=10)
     if result not in res:
         raise Exception("Unexpected result: " + res)
@@ -3161,15 +2907,13 @@ def test_sigma_dut_dpp_proto_responder(dev, apdev):
     for step, frame, attr, result, fail in tests:
         dev[0].request("FLUSH")
         dev[1].request("FLUSH")
-        sigma = start_sigma_dut(dev[0].ifname)
-        try:
-            run_sigma_dut_dpp_proto_responder(dev, step, frame, attr, result,
-                                              fail)
-        finally:
-            stop_sigma_dut(sigma)
+        with SigmaDut(dev=dev[0]) as dut:
+            run_sigma_dut_dpp_proto_responder(dut, dev, step, frame, attr,
+                                              result, fail)
 
-def run_sigma_dut_dpp_proto_responder(dev, step, frame, attr, result, fail):
-    res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
+def run_sigma_dut_dpp_proto_responder(dut, dev, step, frame, attr, result,
+                                      fail):
+    res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
     if "status,COMPLETE" not in res:
         raise Exception("dev_exec_action did not succeed: " + res)
     hex = res.split(',')[3]
@@ -3180,7 +2924,7 @@ def run_sigma_dut_dpp_proto_responder(dev, step, frame, attr, result, fail):
 
     t = threading.Thread(target=dpp_proto_init, args=(dev[1], id1))
     t.start()
-    res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6,DPPStep,%s,DPPFrameType,%s,DPPIEAttribute,%s" % (step, frame, attr), timeout=10)
+    res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6,DPPStep,%s,DPPFrameType,%s,DPPIEAttribute,%s" % (step, frame, attr), timeout=10)
     t.join()
     if result not in res:
         raise Exception("Unexpected result: " + res)
@@ -3206,13 +2950,11 @@ def test_sigma_dut_dpp_proto_stop_at_initiator(dev, apdev):
     for frame, result, fail in tests:
         dev[0].request("FLUSH")
         dev[1].request("FLUSH")
-        sigma = start_sigma_dut(dev[0].ifname)
-        try:
-            run_sigma_dut_dpp_proto_stop_at_initiator(dev, frame, result, fail)
-        finally:
-            stop_sigma_dut(sigma)
+        with SigmaDut(dev=dev[0]) as dut:
+            run_sigma_dut_dpp_proto_stop_at_initiator(dut, dev, frame, result,
+                                                      fail)
 
-def run_sigma_dut_dpp_proto_stop_at_initiator(dev, frame, result, fail):
+def run_sigma_dut_dpp_proto_stop_at_initiator(dut, dev, frame, result, fail):
     id0 = dev[1].dpp_bootstrap_gen(chan="81/6", mac=True)
     uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
 
@@ -3220,11 +2962,11 @@ def run_sigma_dut_dpp_proto_stop_at_initiator(dev, frame, result, fail):
     if "OK" not in dev[1].request(cmd):
         raise Exception("Failed to start listen operation")
 
-    res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri0))
+    res = dut.run_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,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6,DPPStep,Timeout,DPPFrameType,%s" % (frame))
+    res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6,DPPStep,Timeout,DPPFrameType,%s" % (frame))
     if result not in res:
         raise Exception("Unexpected result: " + res)
     if fail:
@@ -3246,14 +2988,11 @@ def test_sigma_dut_dpp_proto_stop_at_initiator_enrollee(dev, apdev):
     for frame, result, fail in tests:
         dev[0].request("FLUSH")
         dev[1].request("FLUSH")
-        sigma = start_sigma_dut(dev[0].ifname)
-        try:
-            run_sigma_dut_dpp_proto_stop_at_initiator_enrollee(dev, frame,
+        with SigmaDut(dev=dev[0]) as dut:
+            run_sigma_dut_dpp_proto_stop_at_initiator_enrollee(dut, dev, frame,
                                                                result, fail)
-        finally:
-            stop_sigma_dut(sigma)
 
-def run_sigma_dut_dpp_proto_stop_at_initiator_enrollee(dev, frame, result,
+def run_sigma_dut_dpp_proto_stop_at_initiator_enrollee(dut, dev, frame, result,
                                                        fail):
     id0 = dev[1].dpp_bootstrap_gen(chan="81/6", mac=True)
     uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
@@ -3262,11 +3001,11 @@ def run_sigma_dut_dpp_proto_stop_at_initiator_enrollee(dev, frame, result,
     if "OK" not in dev[1].request(cmd):
         raise Exception("Failed to start listen operation")
 
-    res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri0))
+    res = dut.run_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,DPPStep,Timeout,DPPFrameType,%s" % (frame), timeout=10)
+    res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6,DPPStep,Timeout,DPPFrameType,%s" % (frame), timeout=10)
     if result not in res:
         raise Exception("Unexpected result: " + res)
     if fail:
@@ -3291,14 +3030,12 @@ def test_sigma_dut_dpp_proto_stop_at_responder(dev, apdev):
     for frame, result, fail in tests:
         dev[0].request("FLUSH")
         dev[1].request("FLUSH")
-        sigma = start_sigma_dut(dev[0].ifname)
-        try:
-            run_sigma_dut_dpp_proto_stop_at_responder(dev, frame, result, fail)
-        finally:
-            stop_sigma_dut(sigma)
+        with SigmaDut(dev=dev[0]) as dut:
+            run_sigma_dut_dpp_proto_stop_at_responder(dut, dev, frame, result,
+                                                      fail)
 
-def run_sigma_dut_dpp_proto_stop_at_responder(dev, frame, result, fail):
-    res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
+def run_sigma_dut_dpp_proto_stop_at_responder(dut, dev, frame, result, fail):
+    res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
     if "status,COMPLETE" not in res:
         raise Exception("dev_exec_action did not succeed: " + res)
     hex = res.split(',')[3]
@@ -3309,7 +3046,7 @@ def run_sigma_dut_dpp_proto_stop_at_responder(dev, frame, result, fail):
 
     t = threading.Thread(target=dpp_proto_init, args=(dev[1], id1))
     t.start()
-    res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6,DPPStep,Timeout,DPPFrameType,%s" % (frame), timeout=10)
+    res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6,DPPStep,Timeout,DPPFrameType,%s" % (frame), timeout=10)
     t.join()
     if result not in res:
         raise Exception("Unexpected result: " + res)
@@ -3353,14 +3090,12 @@ def test_sigma_dut_dpp_proto_initiator_pkex(dev, apdev):
     for step, frame, attr, result, fail in tests:
         dev[0].request("FLUSH")
         dev[1].request("FLUSH")
-        sigma = start_sigma_dut(dev[0].ifname)
-        try:
-            run_sigma_dut_dpp_proto_initiator_pkex(dev, step, frame, attr,
+        with SigmaDut(dev=dev[0]) as dut:
+            run_sigma_dut_dpp_proto_initiator_pkex(dut, dev, step, frame, attr,
                                                    result, fail)
-        finally:
-            stop_sigma_dut(sigma)
 
-def run_sigma_dut_dpp_proto_initiator_pkex(dev, step, frame, attr, result, fail):
+def run_sigma_dut_dpp_proto_initiator_pkex(dut, dev, step, frame, attr, result,
+                                           fail):
     id1 = dev[1].dpp_bootstrap_gen(type="pkex")
 
     cmd = "DPP_PKEX_ADD own=%d code=secret" % (id1)
@@ -3372,7 +3107,7 @@ def run_sigma_dut_dpp_proto_initiator_pkex(dev, step, frame, attr, result, fail)
     if "OK" not in dev[1].request(cmd):
         raise Exception("Failed to start listen operation")
 
-    res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCode,secret,DPPTimeout,6,DPPStep,%s,DPPFrameType,%s,DPPIEAttribute,%s" % (step, frame, attr))
+    res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCode,secret,DPPTimeout,6,DPPStep,%s,DPPFrameType,%s,DPPIEAttribute,%s" % (step, frame, attr))
     if result not in res:
         raise Exception("Unexpected result: " + res)
     if fail:
@@ -3400,17 +3135,15 @@ def test_sigma_dut_dpp_proto_responder_pkex(dev, apdev):
     for step, frame, attr, result, fail in tests:
         dev[0].request("FLUSH")
         dev[1].request("FLUSH")
-        sigma = start_sigma_dut(dev[0].ifname)
-        try:
-            run_sigma_dut_dpp_proto_responder_pkex(dev, step, frame, attr,
+        with SigmaDut(dev=dev[0]) as dut:
+            run_sigma_dut_dpp_proto_responder_pkex(dut, dev, step, frame, attr,
                                                    result, fail)
-        finally:
-            stop_sigma_dut(sigma)
 
-def run_sigma_dut_dpp_proto_responder_pkex(dev, step, frame, attr, result, fail):
+def run_sigma_dut_dpp_proto_responder_pkex(dut, dev, step, frame, attr, result,
+                                           fail):
     t = threading.Thread(target=dpp_proto_init_pkex, args=(dev[1],))
     t.start()
-    res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCode,secret,DPPTimeout,6,DPPStep,%s,DPPFrameType,%s,DPPIEAttribute,%s" % (step, frame, attr), timeout=10)
+    res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCode,secret,DPPTimeout,6,DPPStep,%s,DPPFrameType,%s,DPPIEAttribute,%s" % (step, frame, attr), timeout=10)
     t.join()
     if result not in res:
         raise Exception("Unexpected result: " + res)
@@ -3423,7 +3156,7 @@ def run_sigma_dut_dpp_proto_responder_pkex(dev, step, frame, attr, result, fail)
     dev[0].dump_monitor()
     dev[1].dump_monitor()
 
-def init_sigma_dut_dpp_proto_peer_disc_req(dev, apdev):
+def init_sigma_dut_dpp_proto_peer_disc_req(dut, dev, apdev):
     check_dpp_capab(dev[0])
     check_dpp_capab(dev[1])
     hapd = start_dpp_ap(apdev[0])
@@ -3445,21 +3178,17 @@ def init_sigma_dut_dpp_proto_peer_disc_req(dev, apdev):
     if "OK" not in dev[1].request(cmd):
         raise Exception("Failed to start listen operation")
 
-    res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri0))
+    res = dut.run_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)
 
 def run_sigma_dut_dpp_proto_peer_disc_req(dev, apdev, args):
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
-        init_sigma_dut_dpp_proto_peer_disc_req(dev, apdev)
+    with SigmaDut(dev=dev[0]) as dut:
+        init_sigma_dut_dpp_proto_peer_disc_req(dut, dev, apdev)
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6,DPPWaitForConnect,Yes,DPPFrameType,PeerDiscoveryRequest," + args, timeout=10)
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6,DPPWaitForConnect,Yes,DPPFrameType,PeerDiscoveryRequest," + args, timeout=10)
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,Errorsent" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        dev[0].set("dpp_config_processing", "0", allow_fail=True)
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_proto_peer_disc_req(dev, apdev):
     """sigma_dut DPP protocol testing - Peer Discovery Request"""
@@ -3482,61 +3211,48 @@ def test_sigma_dut_dpp_self_config(dev, apdev):
     hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured"})
     check_dpp_capab(hapd)
 
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         dev[0].set("dpp_config_processing", "2")
         id = hapd.dpp_bootstrap_gen(chan="81/1", mac=True)
         uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id)
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri))
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri))
         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,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,AP,DPPBS,QR,DPPTimeout,6")
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,AP,DPPBS,QR,DPPTimeout,6")
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
         update_hapd_config(hapd)
 
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPCryptoIdentifier,P-256,DPPBS,QR,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPAuthDirection,Single,DPPConfIndex,1,DPPTimeout,6,DPPWaitForConnect,Yes,DPPSelfConfigure,Yes"
-        res = sigma_dut_cmd(cmd, timeout=10)
+        res = dut.run_cmd(cmd, timeout=10)
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        stop_sigma_dut(sigma)
-        dev[0].set("dpp_config_processing", "0")
 
 def test_sigma_dut_ap_dpp_self_config(dev, apdev, params):
     """sigma_dut DPP AP Configurator using self-configuration"""
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_dpp_self_config.sigma-hostapd")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            run_sigma_dut_ap_dpp_self_config(dev, apdev)
-        finally:
-            stop_sigma_dut(sigma)
-            dev[0].set("dpp_config_processing", "0", allow_fail=True)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        run_sigma_dut_ap_dpp_self_config(dut, dev, apdev)
 
 def test_sigma_dut_ap_dpp_self_config_connector_privacy(dev, apdev, params):
     """sigma_dut DPP AP Configurator using self-configuration (Connector privacy)"""
     check_dpp_capab(dev[0], min_ver=3)
     logdir = params['prefix'] + ".sigma-hostapd"
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            dev[0].set("dpp_connector_privacy_default", "1")
-            run_sigma_dut_ap_dpp_self_config(dev, apdev)
-        finally:
-            stop_sigma_dut(sigma)
-            dev[0].set("dpp_config_processing", "0", allow_fail=True)
-            dev[0].set("dpp_connector_privacy_default", "0", allow_fail=True)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dev[0].set("dpp_connector_privacy_default", "1")
+        run_sigma_dut_ap_dpp_self_config(dut, dev, apdev)
 
-def run_sigma_dut_ap_dpp_self_config(dev, apdev):
+def run_sigma_dut_ap_dpp_self_config(dut, dev, apdev):
     check_dpp_capab(dev[0])
 
-    sigma_dut_cmd_check("ap_reset_default,program,DPP")
+    dut.cmd_check("ap_reset_default,program,DPP")
 
-    res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfEnrolleeRole,AP,DPPBS,QR,DPPConfIndex,1,DPPSelfConfigure,Yes,DPPTimeout,6", timeout=10)
+    res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfEnrolleeRole,AP,DPPBS,QR,DPPConfIndex,1,DPPSelfConfigure,Yes,DPPTimeout,6", timeout=10)
     if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
 
@@ -3548,32 +3264,29 @@ def run_sigma_dut_ap_dpp_self_config(dev, apdev):
     if "OK" not in dev[0].request(cmd):
         raise Exception("Failed to start listen operation")
 
-    res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri))
+    res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri))
     if "status,COMPLETE" not in res:
         raise Exception("dev_exec_action did not succeed: " + res)
     cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6"
-    res = sigma_dut_cmd(cmd)
+    res = dut.run_cmd(cmd)
     if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
         raise Exception("Unexpected result: " + res)
     dev[0].wait_connected(timeout=20)
     dev[0].request("DISCONNECT")
     dev[0].wait_disconnected()
-    sigma_dut_cmd_check("ap_reset_default")
-
 
 def test_sigma_dut_ap_dpp_relay(dev, apdev, params):
     """sigma_dut DPP AP as Relay to Controller"""
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_dpp_relay.sigma-hostapd")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
         try:
-            run_sigma_dut_ap_dpp_relay(dev, apdev)
+            run_sigma_dut_ap_dpp_relay(dut, dev, apdev)
         finally:
-            stop_sigma_dut(sigma)
             dev[1].request("DPP_CONTROLLER_STOP")
 
-def run_sigma_dut_ap_dpp_relay(dev, apdev):
+def run_sigma_dut_ap_dpp_relay(dut, dev, apdev):
     check_dpp_capab(dev[0])
     check_dpp_capab(dev[1])
 
@@ -3595,16 +3308,14 @@ def run_sigma_dut_ap_dpp_relay(dev, apdev):
     if "OK" not in dev[1].request("DPP_CONTROLLER_START"):
         raise Exception("Failed to start Controller")
 
-    sigma_dut_cmd_check("ap_reset_default,program,DPP")
-    sigma_dut_cmd_check("ap_preset_testparameters,program,DPP,DPPConfiguratorAddress,127.0.0.1,DPPConfiguratorPKHash," + pkhash)
-    res = sigma_dut_cmd_check("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
+    dut.cmd_check("ap_reset_default,program,DPP")
+    dut.cmd_check("ap_preset_testparameters,program,DPP,DPPConfiguratorAddress,127.0.0.1,DPPConfiguratorPKHash," + pkhash)
+    res = dut.cmd_check("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
 
     dev[0].dpp_auth_init(uri=uri_c, role="enrollee")
     wait_auth_success(dev[1], dev[0], configurator=dev[1], enrollee=dev[0],
                       timeout=10)
 
-    sigma_dut_cmd_check("ap_reset_default")
-
 def dpp_init_tcp_enrollee(dev, id1):
     logger.info("Starting DPP initiator/enrollee (TCP) in a thread")
     time.sleep(1)
@@ -3623,10 +3334,9 @@ def test_sigma_dut_dpp_tcp_conf_resp(dev, apdev):
 def run_sigma_dut_dpp_tcp_conf_resp(dev, status_query=False):
     check_dpp_capab(dev[0])
     check_dpp_capab(dev[1])
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         cmd = "dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR"
-        res = sigma_dut_cmd(cmd)
+        res = dut.run_cmd(cmd)
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
         hex = res.split(',')[3]
@@ -3640,14 +3350,12 @@ def run_sigma_dut_dpp_tcp_conf_resp(dev, status_query=False):
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPConfIndex,1,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfEnrolleeRole,STA,DPPSigningKeyECC,P-256,DPPBS,QR,DPPOverTCP,yes,DPPTimeout,6"
         if status_query:
             cmd += ",DPPStatusQuery,Yes"
-        res = sigma_dut_cmd(cmd, timeout=10)
+        res = dut.run_cmd(cmd, timeout=10)
         t.join()
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
         if status_query and "StatusResult,0" not in res:
             raise Exception("Status query did not succeed: " + res)
-    finally:
-        stop_sigma_dut(sigma)
 
 def dpp_init_tcp_configurator(dev, id1, conf_id):
     logger.info("Starting DPP initiator/configurator (TCP) in a thread")
@@ -3667,10 +3375,9 @@ def test_sigma_dut_dpp_tcp_enrollee_resp(dev, apdev):
 def run_sigma_dut_dpp_tcp_enrollee_resp(dev, status_query=False):
     check_dpp_capab(dev[0])
     check_dpp_capab(dev[1])
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         cmd = "dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR"
-        res = sigma_dut_cmd(cmd)
+        res = dut.run_cmd(cmd)
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
         hex = res.split(',')[3]
@@ -3690,21 +3397,18 @@ def run_sigma_dut_dpp_tcp_enrollee_resp(dev, status_query=False):
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPSigningKeyECC,P-256,DPPBS,QR,DPPOverTCP,yes,DPPTimeout,6"
         if status_query:
             cmd += ",DPPStatusQuery,Yes"
-        res = sigma_dut_cmd(cmd, timeout=10)
+        res = dut.run_cmd(cmd, timeout=10)
         t.join()
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
         if status_query and "StatusResult,0" not in res:
             raise Exception("Status query did not succeed: " + res)
-    finally:
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_tcp_enrollee_init(dev, apdev):
     """sigma_dut DPP TCP Enrollee as initiator"""
     check_dpp_capab(dev[0])
     check_dpp_capab(dev[1])
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         # Controller
         conf_id = dev[1].dpp_configurator_add()
         dev[1].set("dpp_configurator_params",
@@ -3714,30 +3418,28 @@ def test_sigma_dut_dpp_tcp_enrollee_init(dev, apdev):
         if "OK" not in dev[1].request("DPP_CONTROLLER_START"):
             raise Exception("Failed to start Controller")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri_c))
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri_c))
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
 
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPOverTCP,127.0.0.1,DPPTimeout,6"
-        res = sigma_dut_cmd(cmd, timeout=10)
+        res = dut.run_cmd(cmd, timeout=10)
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        stop_sigma_dut(sigma)
-        dev[1].request("DPP_CONTROLLER_STOP")
+
+    dev[1].request("DPP_CONTROLLER_STOP")
 
 def test_sigma_dut_ap_dpp_tcp_enrollee_init(dev, apdev, params):
     """sigma_dut DPP AP as TCP Enrollee/initiator"""
     logdir = params['prefix'] + ".sigma-hostapd"
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
         try:
-            run_sigma_dut_ap_dpp_tcp_enrollee_init(dev, apdev)
+            run_sigma_dut_ap_dpp_tcp_enrollee_init(dut, dev, apdev)
         finally:
-            stop_sigma_dut(sigma)
             dev[1].request("DPP_CONTROLLER_STOP")
 
-def run_sigma_dut_ap_dpp_tcp_enrollee_init(dev, apdev):
+def run_sigma_dut_ap_dpp_tcp_enrollee_init(dut, dev, apdev):
     check_dpp_capab(dev[1])
     # Controller
     conf_id = dev[1].dpp_configurator_add()
@@ -3748,22 +3450,20 @@ def run_sigma_dut_ap_dpp_tcp_enrollee_init(dev, apdev):
     if "OK" not in dev[1].request("DPP_CONTROLLER_START"):
         raise Exception("Failed to start Controller")
 
-    sigma_dut_cmd_check("ap_reset_default,program,DPP")
-    sigma_dut_cmd_check("ap_preset_testparameters,Program,DPP,NAME,AP,oper_chn,6")
-    sigma_dut_cmd_check("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri_c))
+    dut.cmd_check("ap_reset_default,program,DPP")
+    dut.cmd_check("ap_preset_testparameters,Program,DPP,NAME,AP,oper_chn,6")
+    dut.cmd_check("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri_c))
 
     cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPOverTCP,127.0.0.1,DPPTimeout,6"
-    res = sigma_dut_cmd(cmd, timeout=10)
+    res = dut.run_cmd(cmd, timeout=10)
     if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
         raise Exception("Unexpected result: " + res)
-    sigma_dut_cmd_check("ap_reset_default")
 
 def test_sigma_dut_dpp_tcp_enrollee_init_mutual(dev, apdev):
     """sigma_dut DPP TCP Enrollee as initiator with mutual authentication"""
     check_dpp_capab(dev[0], min_ver=2)
     check_dpp_capab(dev[1], min_ver=2)
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         # Controller
         conf_id = dev[1].dpp_configurator_add()
         dev[1].set("dpp_configurator_params",
@@ -3773,79 +3473,75 @@ def test_sigma_dut_dpp_tcp_enrollee_init_mutual(dev, apdev):
         if "OK" not in dev[1].request("DPP_CONTROLLER_START"):
             raise Exception("Failed to start Controller")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri_c))
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri_c))
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
 
         cmd = "dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR"
-        res = sigma_dut_cmd_check(cmd)
+        res = dut.cmd_check(cmd)
         hex = res.split(',')[3]
         uri = from_hex(hex)
         logger.info("URI from sigma_dut: " + uri)
         id1 = dev[1].dpp_qr_code(uri)
 
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Mutual,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPOverTCP,127.0.0.1,DPPTimeout,6"
-        res = sigma_dut_cmd(cmd, timeout=10)
+        res = dut.run_cmd(cmd, timeout=10)
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        stop_sigma_dut(sigma)
-        dev[1].request("DPP_CONTROLLER_STOP")
+
+    dev[1].request("DPP_CONTROLLER_STOP")
 
 def test_sigma_dut_dpp_tcp_configurator_init_mutual(dev, apdev):
     """sigma_dut DPP TCP Configurator as initiator with mutual authentication"""
     check_dpp_capab(dev[0], min_ver=2)
     check_dpp_capab(dev[1], min_ver=2)
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         id_c = dev[1].dpp_bootstrap_gen()
         uri_c = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id_c)
         if "OK" not in dev[1].request("DPP_CONTROLLER_START role=enrollee"):
             raise Exception("Failed to start Controller")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri_c))
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri_c))
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
 
         cmd = "dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR"
-        res = sigma_dut_cmd_check(cmd)
+        res = dut.cmd_check(cmd)
         hex = res.split(',')[3]
         uri = from_hex(hex)
         logger.info("URI from sigma_dut: " + uri)
         id1 = dev[1].dpp_qr_code(uri)
 
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Mutual,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPOverTCP,127.0.0.1,DPPTimeout,6"
-        res = sigma_dut_cmd(cmd, timeout=10)
+        res = dut.run_cmd(cmd, timeout=10)
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        stop_sigma_dut(sigma)
-        dev[1].request("DPP_CONTROLLER_STOP")
+
+    dev[1].request("DPP_CONTROLLER_STOP")
 
 def test_sigma_dut_dpp_tcp_configurator_init_mutual_unsupported_curve(dev, apdev):
     """sigma_dut DPP TCP Configurator as initiator with mutual authentication (unsupported curve)"""
     check_dpp_capab(dev[0], min_ver=3)
     check_dpp_capab(dev[1], min_ver=3)
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         id_c = dev[1].dpp_bootstrap_gen(supported_curves="P-256:P-384")
         uri_c = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id_c)
         if "OK" not in dev[1].request("DPP_CONTROLLER_START role=enrollee"):
             raise Exception("Failed to start Controller")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri_c))
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri_c))
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
 
         cmd = "dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR"
-        res = sigma_dut_cmd_check(cmd)
+        res = dut.cmd_check(cmd)
         hex = res.split(',')[3]
         uri = from_hex(hex)
         logger.info("URI from sigma_dut: " + uri)
         id1 = dev[1].dpp_qr_code(uri)
 
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Mutual,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPNAKECC,P-521,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPOverTCP,127.0.0.1,DPPTimeout,6"
-        res = sigma_dut_cmd(cmd, timeout=10)
+        res = dut.run_cmd(cmd, timeout=10)
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,FAILED" not in res:
             raise Exception("Unexpected result: " + res)
         ev = dev[1].wait_event(["DPP-FAIL"], timeout=20)
@@ -3853,40 +3549,36 @@ def test_sigma_dut_dpp_tcp_configurator_init_mutual_unsupported_curve(dev, apdev
             raise Exception("Enrollee did not report configuration result")
         if "Configurator rejected configuration" not in ev:
             raise Exception("Enrollee did not report configuration rejection")
-    finally:
-        stop_sigma_dut(sigma)
-        dev[1].request("DPP_CONTROLLER_STOP")
+
+    dev[1].request("DPP_CONTROLLER_STOP")
 
 def test_sigma_dut_dpp_tcp_configurator_init_from_uri(dev, apdev):
     """sigma_dut DPP TCP Configurator as initiator with addr from URI"""
     check_dpp_capab(dev[0], min_ver=2)
     check_dpp_capab(dev[1], min_ver=2)
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         id_c = dev[1].dpp_bootstrap_gen(host="127.0.0.1")
         uri_c = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id_c)
         if "OK" not in dev[1].request("DPP_CONTROLLER_START role=enrollee"):
             raise Exception("Failed to start Controller")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri_c))
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % to_hex(uri_c))
         if "status,COMPLETE" not in res:
             raise Exception("dev_exec_action did not succeed: " + res)
 
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPOverTCP,from-uri,DPPTimeout,6"
-        res = sigma_dut_cmd(cmd, timeout=10)
+        res = dut.run_cmd(cmd, timeout=10)
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        stop_sigma_dut(sigma)
-        dev[1].request("DPP_CONTROLLER_STOP")
+
+    dev[1].request("DPP_CONTROLLER_STOP")
 
 def test_sigma_dut_dpp_nfc_handover_requestor_enrollee(dev, apdev):
     """sigma_dut DPP/NFC handover requestor as 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:
+    with SigmaDut(dev=dev[0]) as dut:
         dev[0].set("dpp_config_processing", "2")
 
         cmd = "DPP_CONFIGURATOR_ADD key=" + csign
@@ -3901,12 +3593,12 @@ def test_sigma_dut_dpp_nfc_handover_requestor_enrollee(dev, apdev):
                                           mac=True)
         uri_own = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id_own)
 
-        res = sigma_dut_cmd_check("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPBS,NFC")
+        res = dut.cmd_check("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPBS,NFC")
         hex = res.split(',')[3]
         uri_peer = from_hex(hex)
         logger.info("URI from sigma_dut: " + uri_peer)
 
-        sigma_dut_cmd_check("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,NFC" % to_hex(uri_own))
+        dut.cmd_check("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,NFC" % to_hex(uri_own))
 
         res = dev[1].request("DPP_NFC_HANDOVER_REQ own=%d uri=%s" % (id_own,
                                                                      uri_peer))
@@ -3924,20 +3616,16 @@ def test_sigma_dut_dpp_nfc_handover_requestor_enrollee(dev, apdev):
         logger.info("Updated URI[1]: " + uri1)
         dev[1].dpp_listen(freq, role="configurator")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Enrollee,DPPBS,NFC,DPPNFCHandover,Negotiated_Requestor,DPPTimeout,6,DPPWaitForConnect,Yes", timeout=10)
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Enrollee,DPPBS,NFC,DPPNFCHandover,Negotiated_Requestor,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)
-    finally:
-        dev[0].set("dpp_config_processing", "0")
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_nfc_handover_selector_enrollee(dev, apdev):
     """sigma_dut DPP/NFC handover selector as 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:
+    with SigmaDut(dev=dev[0]) as dut:
         dev[0].set("dpp_config_processing", "2")
 
         cmd = "DPP_CONFIGURATOR_ADD key=" + csign
@@ -3952,12 +3640,12 @@ def test_sigma_dut_dpp_nfc_handover_selector_enrollee(dev, apdev):
                                           mac=True)
         uri_own = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id_own)
 
-        res = sigma_dut_cmd_check("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPBS,NFC")
+        res = dut.cmd_check("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPBS,NFC")
         hex = res.split(',')[3]
         uri_peer = from_hex(hex)
         logger.info("URI from sigma_dut: " + uri_peer)
 
-        sigma_dut_cmd_check("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,NFC" % to_hex(uri_own))
+        dut.cmd_check("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,NFC" % to_hex(uri_own))
 
         res = dev[1].request("DPP_NFC_HANDOVER_SEL own=%d uri=%s" % (id_own,
                                                                      uri_peer))
@@ -3967,20 +3655,16 @@ def test_sigma_dut_dpp_nfc_handover_selector_enrollee(dev, apdev):
         dev[1].dpp_auth_init(peer=peer, own=id_own, configurator=conf_id,
                              conf="sta-dpp", ssid="DPPNET01")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Enrollee,DPPBS,NFC,DPPNFCHandover,Negotiated_Selector,DPPTimeout,6,DPPWaitForConnect,Yes", timeout=10)
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Enrollee,DPPBS,NFC,DPPNFCHandover,Negotiated_Selector,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)
-    finally:
-        dev[0].set("dpp_config_processing", "0")
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_nfc_static_read_enrollee(dev, apdev):
     """sigma_dut DPP/NFC read tag as 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:
+    with SigmaDut(dev=dev[0]) as dut:
         dev[0].set("dpp_config_processing", "2")
 
         cmd = "DPP_CONFIGURATOR_ADD key=" + csign
@@ -3994,23 +3678,19 @@ def test_sigma_dut_dpp_nfc_static_read_enrollee(dev, apdev):
         id_own = dev[1].dpp_bootstrap_gen(type="nfc-uri", chan="81/6", mac=True)
         uri_own = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id_own)
 
-        sigma_dut_cmd_check("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,NFC" % to_hex(uri_own))
+        dut.cmd_check("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,NFC" % to_hex(uri_own))
         dev[1].dpp_listen(2437, role="configurator")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Enrollee,DPPBS,NFC,DPPNFCHandover,Static,DPPTimeout,6,DPPWaitForConnect,Yes", timeout=10)
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Enrollee,DPPBS,NFC,DPPNFCHandover,Static,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)
-    finally:
-        dev[0].set("dpp_config_processing", "0")
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_nfc_static_write_enrollee(dev, apdev):
     """sigma_dut DPP/NFC write tag as 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:
+    with SigmaDut(dev=dev[0]) as dut:
         dev[0].set("dpp_config_processing", "2")
 
         cmd = "DPP_CONFIGURATOR_ADD key=" + csign
@@ -4021,7 +3701,7 @@ def test_sigma_dut_dpp_nfc_static_write_enrollee(dev, apdev):
         dev[1].set("dpp_configurator_params",
                    " conf=sta-dpp ssid=%s configurator=%d" % (to_hex("DPPNET01"), conf_id))
 
-        res = sigma_dut_cmd_check("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPBS,NFC")
+        res = dut.cmd_check("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPBS,NFC")
         hex = res.split(',')[3]
         uri_peer = from_hex(hex)
         logger.info("URI from sigma_dut: " + uri_peer)
@@ -4029,20 +3709,16 @@ def test_sigma_dut_dpp_nfc_static_write_enrollee(dev, apdev):
         dev[1].dpp_auth_init(nfc_uri=uri_peer, configurator=conf_id,
                              conf="sta-dpp", ssid="DPPNET01")
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPProvisioningRole,Enrollee,DPPBS,NFC,DPPNFCHandover,Static,DPPTimeout,6,DPPWaitForConnect,Yes", timeout=10)
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPProvisioningRole,Enrollee,DPPBS,NFC,DPPNFCHandover,Static,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)
-    finally:
-        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:
+    with SigmaDut(dev=dev[0]) as dut:
         cmd = "DPP_CONFIGURATOR_ADD key=" + csign
         res = dev[1].request(cmd)
         if "FAIL" in res:
@@ -4059,13 +3735,13 @@ def test_sigma_dut_dpp_reconfig_enrollee(dev, apdev):
             raise Exception("Failed to start listen operation")
 
         ifname = dev[0].ifname
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
+        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))
+        res = dut.run_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)
+        res = dut.run_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)
 
@@ -4084,7 +3760,7 @@ def test_sigma_dut_dpp_reconfig_enrollee(dev, apdev):
             raise Exception("Failed to start listen operation")
         dev[1].dump_monitor()
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,DPPReconfigure,DPPTimeout,16,DPPWaitForConnect,Yes", timeout=20)
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,DPPReconfigure,DPPTimeout,16,DPPWaitForConnect,Yes", timeout=20)
         if "status,COMPLETE,ReconfigAuthResult,OK,ConfResult,OK,NetworkConnectResult,OK" not in res:
             raise Exception("Unexpected reconfiguration result: " + res)
 
@@ -4106,7 +3782,7 @@ def test_sigma_dut_dpp_reconfig_enrollee(dev, apdev):
         dev[0].dump_monitor()
         dev[1].dump_monitor()
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,DPPReconfigure,DPPTimeout,16,DPPWaitForConnect,Yes", timeout=30)
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,DPPReconfigure,DPPTimeout,16,DPPWaitForConnect,Yes", timeout=30)
         if "status,COMPLETE,ReconfigAuthResult,OK,ConfResult,OK,NetworkConnectResult,OK" not in res:
             raise Exception("Unexpected reconfiguration [2] result: " + res)
 
@@ -4115,9 +3791,6 @@ def test_sigma_dut_dpp_reconfig_enrollee(dev, apdev):
             raise Exception("DPP Config Response (reconfig) not transmitted [2]")
 
         dev[0].wait_connected(timeout=20)
-    finally:
-        dev[0].set("dpp_config_processing", "0")
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_reconfig_enrollee_sae(dev, apdev):
     """sigma_dut DPP reconfiguration using SAE (Enrollee)"""
@@ -4125,8 +3798,7 @@ def test_sigma_dut_dpp_reconfig_enrollee_sae(dev, apdev):
     check_dpp_capab(dev[1])
     check_sae_capab(dev[0])
     hapd = start_dpp_ap(apdev[0])
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         cmd = "DPP_CONFIGURATOR_ADD key=" + csign
         res = dev[1].request(cmd)
         if "FAIL" in res:
@@ -4143,13 +3815,13 @@ def test_sigma_dut_dpp_reconfig_enrollee_sae(dev, apdev):
             raise Exception("Failed to start listen operation")
 
         ifname = dev[0].ifname
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
+        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))
+        res = dut.run_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)
+        res = dut.run_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)
 
@@ -4165,7 +3837,7 @@ def test_sigma_dut_dpp_reconfig_enrollee_sae(dev, apdev):
             raise Exception("Failed to start listen operation")
         dev[1].dump_monitor()
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,DPPReconfigure,DPPTimeout,16,DPPWaitForConnect,Yes", timeout=20)
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,DPPReconfigure,DPPTimeout,16,DPPWaitForConnect,Yes", timeout=20)
         if "status,COMPLETE,ReconfigAuthResult,OK,ConfResult,OK,NetworkConnectResult,OK" not in res:
             raise Exception("Unexpected reconfiguration result: " + res)
 
@@ -4187,7 +3859,7 @@ def test_sigma_dut_dpp_reconfig_enrollee_sae(dev, apdev):
         dev[0].dump_monitor()
         dev[1].dump_monitor()
 
-        res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,DPPReconfigure,DPPTimeout,16,DPPWaitForConnect,Yes", timeout=30)
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,DPPReconfigure,DPPTimeout,16,DPPWaitForConnect,Yes", timeout=30)
         if "status,COMPLETE,ReconfigAuthResult,OK,ConfResult,OK,NetworkConnectResult,OK" not in res:
             raise Exception("Unexpected reconfiguration [2] result: " + res)
 
@@ -4196,16 +3868,12 @@ def test_sigma_dut_dpp_reconfig_enrollee_sae(dev, apdev):
             raise Exception("DPP Config Response (reconfig) not transmitted [2]")
 
         dev[0].wait_connected(timeout=20)
-    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:
+    with SigmaDut(dev=dev[0]) as dut:
         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)
@@ -4214,13 +3882,13 @@ def test_sigma_dut_dpp_reconfig_configurator(dev, apdev):
             raise Exception("Failed to start listen operation")
 
         ifname = dev[0].ifname
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
+        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))
+        res = dut.run_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)
+        res = dut.run_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)
 
@@ -4239,17 +3907,15 @@ def test_sigma_dut_dpp_reconfig_configurator(dev, apdev):
         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,16", timeout=20)
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,DPPReconfigure,DPPProvisioningRole,Configurator,DPPConfEnrolleeRole,STA,DPPSigningKeyECC,P-256,DPPConfIndex,2,DPPListenChannel,6,DPPTimeout,16", timeout=20)
         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)
+
+    dev[1].set("dpp_config_processing", "0")
 
 def test_sigma_dut_dpp_reconfig_no_proto_ver(dev, apdev):
     """sigma_dut DPP reconfiguration (Configurator) - missing Protocol Version"""
@@ -4262,8 +3928,7 @@ def test_sigma_dut_dpp_reconfig_invalid_proto_ver(dev, apdev):
 def run_sigma_dut_dpp_reconfig_proto(dev, apdev, dpp_step):
     check_dpp_capab(dev[0])
     check_dpp_capab(dev[1])
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         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)
@@ -4272,13 +3937,13 @@ def run_sigma_dut_dpp_reconfig_proto(dev, apdev, dpp_step):
             raise Exception("Failed to start listen operation")
 
         ifname = dev[0].ifname
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
+        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))
+        res = dut.run_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)
+        res = dut.run_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)
 
@@ -4297,17 +3962,15 @@ def run_sigma_dut_dpp_reconfig_proto(dev, apdev, dpp_step):
         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,DPPStep,%s,DPPFrameType,ReconfigAuthRequest,DPPIEAttribute,ProtocolVersion,DPPListenChannel,6,DPPTimeout,16" % dpp_step, timeout=20)
+        res = dut.run_cmd("dev_exec_action,program,DPP,DPPActionType,DPPReconfigure,DPPProvisioningRole,Configurator,DPPConfEnrolleeRole,STA,DPPSigningKeyECC,P-256,DPPConfIndex,2,DPPStep,%s,DPPFrameType,ReconfigAuthRequest,DPPIEAttribute,ProtocolVersion,DPPListenChannel,6,DPPTimeout,16" % dpp_step, timeout=20)
         if "status,COMPLETE,ReconfigAuthResult,Errorsent" not in res:
             raise Exception("Unexpected reconfiguration result: " + res)
 
         ev = dev[1].wait_event(["DPP-CONF-RECEIVED"], timeout=5)
         if ev is not None:
             raise Exception("DPP Config Response (reconfig) received unexpectedly")
-    finally:
-        dev[0].set("dpp_config_processing", "0")
-        dev[1].set("dpp_config_processing", "0")
-        stop_sigma_dut(sigma)
+
+    dev[1].set("dpp_config_processing", "0")
 
 def test_sigma_dut_dpp_pb_sta(dev, apdev):
     """sigma_dut DPP/PB station"""
@@ -4324,23 +3987,19 @@ def test_sigma_dut_dpp_pb_sta(dev, apdev):
     hapd = hostapd.add_ap(apdev[0], params)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         if "OK" not in hapd.request("DPP_PUSH_BUTTON"):
             raise Exception("Failed to press push button on the AP")
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
+        dut.cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
 
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPProvisioningRole,Enrollee,DPPBS,PBBS,DPPTimeout,50,DPPWaitForConnect,Yes"
-        res = sigma_dut_cmd(cmd, timeout=60)
+        res = dut.run_cmd(cmd, timeout=60)
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkConnectResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
         ev = hapd.wait_event(["DPP-PB-RESULT"], timeout=1)
         if ev is None or "success" not in ev:
             raise Exception("Push button bootstrapping did not succeed on AP")
-    finally:
-        stop_sigma_dut(sigma)
-        dev[0].set("dpp_config_processing", "0")
 
 def dpp_ap_pb_delayed_start(hapd):
     time.sleep(10)
@@ -4362,24 +4021,20 @@ def test_sigma_dut_dpp_pb_sta_first(dev, apdev):
     hapd = hostapd.add_ap(apdev[0], params)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         t = threading.Thread(target=dpp_ap_pb_delayed_start, args=(hapd,))
         t.start()
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
+        dut.cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
 
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPProvisioningRole,Enrollee,DPPBS,PBBS,DPPTimeout,50,DPPWaitForConnect,Yes"
-        res = sigma_dut_cmd(cmd, timeout=60, dump_dev=dev[0])
+        res = dut.run_cmd(cmd, timeout=60, dump_dev=dev[0])
         t.join()
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkConnectResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
         ev = hapd.wait_event(["DPP-PB-RESULT"], timeout=1)
         if ev is None or "success" not in ev:
             raise Exception("Push button bootstrapping did not succeed on AP")
-    finally:
-        stop_sigma_dut(sigma)
-        dev[0].set("dpp_config_processing", "0")
 
 def dpp_ap_pb_overlap(hapd, hapd2, dev0):
     if "OK" not in hapd.request("DPP_PUSH_BUTTON"):
@@ -4417,21 +4072,17 @@ def test_sigma_dut_dpp_pb_sta_session_overlap(dev, apdev):
     hapd2 = hostapd.add_ap(apdev[1], params)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-    try:
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
+    with SigmaDut(dev=dev[0]) as dut:
+        dut.cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
 
         t = threading.Thread(target=dpp_ap_pb_overlap,
                              args=(hapd, hapd2, dev[0]))
         t.start()
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPProvisioningRole,Enrollee,DPPBS,PBBS,DPPTimeout,50,DPPWaitForConnect,Yes"
-        res = sigma_dut_cmd(cmd, timeout=60)
+        res = dut.run_cmd(cmd, timeout=60)
         t.join()
         if "BootstrapResult,Failed" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        stop_sigma_dut(sigma)
-        dev[0].set("dpp_config_processing", "0")
 
 def test_sigma_dut_dpp_pb_configurator(dev, apdev):
     """sigma_dut DPP/PB Configurator"""
@@ -4439,22 +4090,19 @@ def test_sigma_dut_dpp_pb_configurator(dev, apdev):
     check_dpp_capab(dev[1], min_ver=3)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-    try:
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
+    with SigmaDut(dev=dev[0]) as dut:
+        dut.cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
 
         if "OK" not in dev[1].request("DPP_PUSH_BUTTON"):
             raise Exception("Failed to press push button on the STA/Enrollee")
 
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPBS,PBBS,DPPConfEnrolleeRole,STA,DPPConfIndex,1,DPPTimeout,50"
-        res = sigma_dut_cmd(cmd, timeout=60)
+        res = dut.run_cmd(cmd, timeout=60)
         if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
             raise Exception("Unexpected result: " + res)
         ev = dev[1].wait_event(["DPP-PB-RESULT"], timeout=1)
         if ev is None or "success" not in ev:
             raise Exception("Push button bootstrapping did not succeed on STA/Enrollee")
-    finally:
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_pb_configurator_session_overlap(dev, apdev):
     """sigma_dut DPP/PB Configurator session overlap"""
@@ -4463,9 +4111,8 @@ def test_sigma_dut_dpp_pb_configurator_session_overlap(dev, apdev):
     check_dpp_capab(dev[2], min_ver=3)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-    try:
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
+    with SigmaDut(dev=dev[0]) as dut:
+        dut.cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
 
         if "OK" not in dev[1].request("DPP_PUSH_BUTTON"):
             raise Exception("Failed to press push button on the STA/Enrollee")
@@ -4473,11 +4120,9 @@ def test_sigma_dut_dpp_pb_configurator_session_overlap(dev, apdev):
             raise Exception("Failed to press push button on the STA2/Enrollee")
 
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPBS,PBBS,DPPConfEnrolleeRole,STA,DPPConfIndex,1,DPPTimeout,50"
-        res = sigma_dut_cmd(cmd, timeout=60)
+        res = dut.run_cmd(cmd, timeout=60)
         if "BootstrapResult,Failed" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_dpp_pb_sta_misbehavior(dev, apdev):
     """sigma_dut DPP/PB station misbehavior"""
@@ -4494,24 +4139,20 @@ def test_sigma_dut_dpp_pb_sta_misbehavior(dev, apdev):
     hapd = hostapd.add_ap(apdev[0], params)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         if "OK" not in hapd.request("DPP_PUSH_BUTTON"):
             raise Exception("Failed to press push button on the AP")
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
+        dut.cmd_check("sta_reset_default,interface,%s,prog,DPP" % ifname)
 
         cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPProvisioningRole,Enrollee,DPPBS,PBBS,DPPTimeout,50,DPPWaitForConnect,Yes"
         cmd += ",DPPStep,InvalidValue,DPPFrameType,PBPresAnnc,DPPIEAttribute,RespBSKeyHash"
-        res = sigma_dut_cmd(cmd, timeout=60)
+        res = dut.run_cmd(cmd, timeout=60)
         if "BootstrapResult,OK,AuthResult,Timeout" not in res:
             raise Exception("Unexpected result: " + res)
         ev = hapd.wait_event(["DPP-PB-RESULT"], timeout=1)
         if ev is None or "failed" not in ev:
             raise Exception("Push button bootstrapping did not fail on AP")
-    finally:
-        stop_sigma_dut(sigma)
-        dev[0].set("dpp_config_processing", "0")
 
 def test_sigma_dut_dpp_pb_ap(dev, apdev, params):
     """sigma_dut DPP/PB AP (own config)"""
@@ -4519,31 +4160,26 @@ def test_sigma_dut_dpp_pb_ap(dev, apdev, params):
     check_sae_capab(dev[0])
 
     logdir = params['prefix'] + ".sigma-hostapd"
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default,program,DPP")
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default,program,DPP")
 
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,6,SSID,test-sae,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,6,SSID,test-sae,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678")
+        dut.cmd_check("ap_config_commit,NAME,AP")
 
-            dev[0].set("dpp_config_processing", "2")
-            if "OK" not in dev[0].request("DPP_PUSH_BUTTON"):
-                raise Exception("Failed to press push button on the STA")
+        dev[0].set("dpp_config_processing", "2")
+        if "OK" not in dev[0].request("DPP_PUSH_BUTTON"):
+            raise Exception("Failed to press push button on the STA")
 
-            cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPBS,PBBS,DPPTimeout,50"
-            res = sigma_dut_cmd(cmd, timeout=60)
-            if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
-                raise Exception("Unexpected result: " + res)
-            ev = dev[0].wait_event(["DPP-PB-RESULT"], timeout=1)
-            if ev is None or "success" not in ev:
-                raise Exception("Push button bootstrapping did not succeed on STA")
-            dev[0].wait_connected()
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
-            dev[0].set("dpp_config_processing", "0", allow_fail=True)
+        cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPBS,PBBS,DPPTimeout,50"
+        res = dut.run_cmd(cmd, timeout=60)
+        if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
+            raise Exception("Unexpected result: " + res)
+        ev = dev[0].wait_event(["DPP-PB-RESULT"], timeout=1)
+        if ev is None or "success" not in ev:
+            raise Exception("Push button bootstrapping did not succeed on STA")
+        dev[0].wait_connected()
 
 def test_sigma_dut_dpp_pb_ap2(dev, apdev, params):
     """sigma_dut DPP/PB AP (DPPConfigIndex)"""
@@ -4551,24 +4187,20 @@ def test_sigma_dut_dpp_pb_ap2(dev, apdev, params):
     check_sae_capab(dev[0])
 
     logdir = params['prefix'] + ".sigma-hostapd"
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default,program,DPP")
-            if "OK" not in dev[0].request("DPP_PUSH_BUTTON"):
-                raise Exception("Failed to press push button on the STA")
-
-            cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPBS,PBBS,DPPTimeout,50"
-            cmd += ",DPPConfEnrolleeRole,STA,DPPConfIndex,1"
-            res = sigma_dut_cmd(cmd, timeout=60)
-            if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
-                raise Exception("Unexpected result: " + res)
-            ev = dev[0].wait_event(["DPP-PB-RESULT"], timeout=1)
-            if ev is None or "success" not in ev:
-                raise Exception("Push button bootstrapping did not succeed on STA")
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default,program,DPP")
+        if "OK" not in dev[0].request("DPP_PUSH_BUTTON"):
+            raise Exception("Failed to press push button on the STA")
+
+        cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPBS,PBBS,DPPTimeout,50"
+        cmd += ",DPPConfEnrolleeRole,STA,DPPConfIndex,1"
+        res = dut.run_cmd(cmd, timeout=60)
+        if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
+            raise Exception("Unexpected result: " + res)
+        ev = dev[0].wait_event(["DPP-PB-RESULT"], timeout=1)
+        if ev is None or "success" not in ev:
+            raise Exception("Push button bootstrapping did not succeed on STA")
 
 def test_sigma_dut_dpp_pb_ap_misbehavior(dev, apdev, params):
     """sigma_dut DPP/PB AP misbehavior)"""
@@ -4576,46 +4208,38 @@ def test_sigma_dut_dpp_pb_ap_misbehavior(dev, apdev, params):
     check_sae_capab(dev[0])
 
     logdir = params['prefix'] + ".sigma-hostapd"
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default,program,DPP")
-            if "OK" not in dev[0].request("DPP_PUSH_BUTTON"):
-                raise Exception("Failed to press push button on the STA")
-
-            cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPBS,PBBS,DPPTimeout,50"
-            cmd += ",DPPConfEnrolleeRole,STA,DPPConfIndex,1"
-            cmd += ",DPPStep,InvalidValue,DPPFrameType,PBPAResponse,DPPIEAttribute,InitBSKeyHash"
-            res = sigma_dut_cmd(cmd, timeout=60)
-            if "BootstrapResult,OK,AuthResult,Timeout" not in res:
-                raise Exception("Unexpected result: " + res)
-            ev = dev[0].wait_event(["DPP-PB-RESULT"], timeout=1)
-            if ev is None or "failed" not in ev:
-                raise Exception("Push button bootstrapping did not fail on STA")
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default,program,DPP")
+        if "OK" not in dev[0].request("DPP_PUSH_BUTTON"):
+            raise Exception("Failed to press push button on the STA")
+
+        cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPBS,PBBS,DPPTimeout,50"
+        cmd += ",DPPConfEnrolleeRole,STA,DPPConfIndex,1"
+        cmd += ",DPPStep,InvalidValue,DPPFrameType,PBPAResponse,DPPIEAttribute,InitBSKeyHash"
+        res = dut.run_cmd(cmd, timeout=60)
+        if "BootstrapResult,OK,AuthResult,Timeout" not in res:
+            raise Exception("Unexpected result: " + res)
+        ev = dev[0].wait_event(["DPP-PB-RESULT"], timeout=1)
+        if ev is None or "failed" not in ev:
+            raise Exception("Push button bootstrapping did not fail on STA")
 
 def test_sigma_dut_preconfigured_profile(dev, apdev):
     """sigma_dut controlled connection using preconfigured profile"""
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         params = hostapd.wpa2_params(ssid="test-psk", passphrase="12345678")
         hapd = hostapd.add_ap(apdev[0], params)
         dev[0].connect("test-psk", psk="12345678", scan_freq="2412",
                        only_add_network=True)
 
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s" % (ifname, "test-psk"),
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s" % (ifname, "test-psk"),
                             timeout=10)
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.wait_connected()
+        dut.cmd_check("sta_get_ip_config,interface," + ifname)
+        dut.cmd_check("sta_disconnect,interface," + ifname)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_wps_pbc(dev, apdev):
     """sigma_dut and WPS PBC Enrollee"""
@@ -4627,46 +4251,37 @@ def test_sigma_dut_wps_pbc(dev, apdev):
     hapd.request("WPS_PBC")
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         cmd = "start_wps_registration,interface,%s" % ifname
         cmd += ",WpsRole,Enrollee"
         cmd += ",WpsConfigMethod,PBC"
-        sigma_dut_cmd_check(cmd, timeout=15)
+        dut.cmd_check(cmd, timeout=15)
 
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
+        dut.cmd_check("sta_disconnect,interface," + ifname)
         hapd.disable()
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
+
     dev[0].flush_scan_cache()
 
 def test_sigma_dut_sta_scan_bss(dev, apdev):
     """sigma_dut sta_scan_bss"""
     hapd = hostapd.add_ap(apdev[0], {"ssid": "test"})
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         cmd = "sta_scan_bss,Interface,%s,BSSID,%s" % (dev[0].ifname, \
                                                       hapd.own_addr())
-        res = sigma_dut_cmd(cmd, timeout=10)
+        res = dut.run_cmd(cmd, timeout=10)
         if "ssid,test,bsschannel,1" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_sta_scan_ssid_bssid(dev, apdev):
     """sigma_dut sta_scan GetParameter,SSID_BSSID"""
     hostapd.add_ap(apdev[0], {"ssid": "abcdef"})
     hostapd.add_ap(apdev[1], {"ssid": "qwerty"})
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         cmd = "sta_scan,Interface,%s,GetParameter,SSID_BSSID" % dev[0].ifname
-        res = sigma_dut_cmd(cmd, timeout=10)
+        res = dut.run_cmd(cmd, timeout=10)
         if "abcdef" not in res or "qwerty" not in res:
             raise Exception("Unexpected result: " + res)
-    finally:
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_sta_scan_short_ssid(dev, apdev):
     """sigma_dut sta_scan ShortSSID"""
@@ -4677,69 +4292,57 @@ def test_sigma_dut_sta_scan_short_ssid(dev, apdev):
     bssid = apdev[0]['bssid']
     payload = struct.pack('>L', binascii.crc32(ssid.encode()))
     val = binascii.hexlify(payload).decode()
-    sigma = start_sigma_dut(dev[0].ifname)
-    found = False
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
+        found = False
         cmd = "sta_scan,Interface,%s,ChnlFreq,2412,ShortSSID,%s" % (dev[0].ifname, val)
         for i in range(10):
-            sigma_dut_cmd_check(cmd, timeout=5)
+            dut.cmd_check(cmd, timeout=5)
             ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
             if ev is None:
                 raise Exception("Scan did not complete")
             if bssid in dev[0].request("SCAN_RESULTS"):
                 found = True
                 break
-    finally:
-        stop_sigma_dut(sigma)
-        dev[0].request("VENDOR_ELEM_REMOVE 14 *")
 
     if not found:
         raise Exception("AP not found in scan results")
 
 def test_sigma_dut_sta_scan_wait_completion(dev, apdev):
     """sigma_dut sta_scan WaitCompletion,1"""
-    sigma = start_sigma_dut(dev[0].ifname)
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         cmd = "sta_scan,Interface,%s,ChnlFreq,2412,WaitCompletion,1" % dev[0].ifname
-        res = sigma_dut_cmd(cmd, timeout=10)
-    finally:
-        stop_sigma_dut(sigma)
+        res = dut.run_cmd(cmd, timeout=10)
 
 def test_sigma_dut_ap_osen(dev, apdev, params):
     """sigma_dut controlled AP with OSEN"""
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_osen.sigma-hostapd")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-hs20,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,1812,PASSWORD,radius")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,OSEN,PMF,Optional")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            # RSN-OSEN (for OSU)
-            dev[0].connect("test-hs20", proto="OSEN", key_mgmt="OSEN",
-                           pairwise="CCMP", group="GTK_NOT_USED",
-                           eap="WFA-UNAUTH-TLS", identity="osen@example.com",
-                           ca_cert="auth_serv/ca.pem", scan_freq="2412")
-
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-hs20,MODE,11ng")
+        dut.cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,1812,PASSWORD,radius")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,OSEN,PMF,Optional")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        # RSN-OSEN (for OSU)
+        dev[0].connect("test-hs20", proto="OSEN", key_mgmt="OSEN",
+                       pairwise="CCMP", group="GTK_NOT_USED",
+                       eap="WFA-UNAUTH-TLS", identity="osen@example.com",
+                       ca_cert="auth_serv/ca.pem", scan_freq="2412")
 
 def test_sigma_dut_ap_eap_osen(dev, apdev, params):
     """sigma_dut controlled AP with EAP+OSEN"""
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_eap_osen.sigma-hostapd")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, bridge="ap-br0", hostapd_logdir=logdir)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, bridge="ap-br0", hostapd_logdir=logdir) as dut:
         try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-hs20,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,1812,PASSWORD,radius")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-ENT-OSEN,PMF,Optional")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
+            dut.cmd_check("ap_reset_default")
+            dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-hs20,MODE,11ng")
+            dut.cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,1812,PASSWORD,radius")
+            dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-ENT-OSEN,PMF,Optional")
+            dut.cmd_check("ap_config_commit,NAME,AP")
 
             subprocess.call(['brctl', 'setfd', 'ap-br0', '0'])
             subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
@@ -4759,9 +4362,7 @@ def test_sigma_dut_ap_eap_osen(dev, apdev, params):
             hwsim_utils.test_connectivity(dev[0], dev[1], broadcast=False,
                                           success_expected=False, timeout=1)
 
-            sigma_dut_cmd_check("ap_reset_default")
         finally:
-            stop_sigma_dut(sigma)
             subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'],
                             stderr=open('/dev/null', 'w'))
             subprocess.call(['brctl', 'delbr', 'ap-br0'],
@@ -4770,84 +4371,64 @@ def test_sigma_dut_ap_eap_osen(dev, apdev, params):
 def test_sigma_dut_ap_eap(dev, apdev, params):
     """sigma_dut controlled AP WPA2-Enterprise"""
     logdir = os.path.join(params['logdir'], "sigma_dut_ap_eap.sigma-hostapd")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-eap,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,1812,PASSWORD,radius")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-ENT")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            dev[0].connect("test-eap", key_mgmt="WPA-EAP", eap="GPSK",
-                           identity="gpsk user",
-                           password="abcdefghijklmnop0123456789abcdef",
-                           scan_freq="2412")
-
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-eap,MODE,11ng")
+        dut.cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,1812,PASSWORD,radius")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-ENT")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        dev[0].connect("test-eap", key_mgmt="WPA-EAP", eap="GPSK",
+                       identity="gpsk user",
+                       password="abcdefghijklmnop0123456789abcdef",
+                       scan_freq="2412")
 
 def test_sigma_dut_ap_eap_sha256(dev, apdev, params):
     """sigma_dut controlled AP WPA2-Enterprise SHA256"""
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_eap_sha256.sigma-hostapd")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-eap,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,1812,PASSWORD,radius")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-ENT-256")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            dev[0].connect("test-eap", key_mgmt="WPA-EAP-SHA256", eap="GPSK",
-                           identity="gpsk user",
-                           password="abcdefghijklmnop0123456789abcdef",
-                           scan_freq="2412")
-
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-eap,MODE,11ng")
+        dut.cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,1812,PASSWORD,radius")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-ENT-256")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        dev[0].connect("test-eap", key_mgmt="WPA-EAP-SHA256", eap="GPSK",
+                       identity="gpsk user",
+                       password="abcdefghijklmnop0123456789abcdef",
+                       scan_freq="2412")
 
 def test_sigma_dut_ap_ft_eap(dev, apdev, params):
     """sigma_dut controlled AP FT-EAP"""
     logdir = os.path.join(params['logdir'], "sigma_dut_ap_ft_eap.sigma-hostapd")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-ft-eap,MODE,11ng,DOMAIN,0101,FT_OA,Enable")
-            sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,1812,PASSWORD,radius")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,FT-EAP")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            dev[0].connect("test-ft-eap", key_mgmt="FT-EAP", eap="GPSK",
-                           identity="gpsk user",
-                           password="abcdefghijklmnop0123456789abcdef",
-                           scan_freq="2412")
-
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-ft-eap,MODE,11ng,DOMAIN,0101,FT_OA,Enable")
+        dut.cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,1812,PASSWORD,radius")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,FT-EAP")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        dev[0].connect("test-ft-eap", key_mgmt="FT-EAP", eap="GPSK",
+                       identity="gpsk user",
+                       password="abcdefghijklmnop0123456789abcdef",
+                       scan_freq="2412")
 
 def test_sigma_dut_ap_ft_psk(dev, apdev, params):
     """sigma_dut controlled AP FT-PSK"""
     logdir = os.path.join(params['logdir'], "sigma_dut_ap_ft_psk.sigma-hostapd")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-ft-psk,MODE,11ng,DOMAIN,0101,FT_OA,Enable")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,FT-PSK,PSK,12345678")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            dev[0].connect("test-ft-psk", key_mgmt="FT-PSK", psk="12345678",
-                           scan_freq="2412")
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-ft-psk,MODE,11ng,DOMAIN,0101,FT_OA,Enable")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,FT-PSK,PSK,12345678")
+        dut.cmd_check("ap_config_commit,NAME,AP")
 
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+        dev[0].connect("test-ft-psk", key_mgmt="FT-PSK", psk="12345678",
+                       scan_freq="2412")
 
 def test_sigma_dut_ap_ft_over_ds_psk(dev, apdev, params):
     """sigma_dut controlled AP FT-PSK (over-DS)"""
@@ -4855,57 +4436,45 @@ def test_sigma_dut_ap_ft_over_ds_psk(dev, apdev, params):
                           "sigma_dut_ap_ft_over_ds_psk.sigma-hostapd")
     conffile = os.path.join(params['logdir'],
                             "sigma_dut_ap_ft_over_ds_psk.sigma-conf")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-ft-psk,MODE,11ng,DOMAIN,0101,FT_DS,Enable")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,FT-PSK,PSK,12345678")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            with open("/tmp/sigma_dut-ap.conf", "rb") as f:
-                with open(conffile, "wb") as f2:
-                    f2.write(f.read())
-
-            dev[0].connect("test-ft-psk", key_mgmt="FT-PSK", psk="12345678",
-                           scan_freq="2412")
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-ft-psk,MODE,11ng,DOMAIN,0101,FT_DS,Enable")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,FT-PSK,PSK,12345678")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        with open("/tmp/sigma_dut-ap.conf", "rb") as f, \
+             open(conffile, "wb") as f2:
+            f2.write(f.read())
 
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+        dev[0].connect("test-ft-psk", key_mgmt="FT-PSK", psk="12345678",
+                       scan_freq="2412")
 
 def test_sigma_dut_ap_ent_ft_eap(dev, apdev, params):
     """sigma_dut controlled AP WPA-EAP and FT-EAP"""
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_ent_ft_eap.sigma-hostapd")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-ent-ft-eap,MODE,11ng,DOMAIN,0101,FT_OA,Enable")
-            sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,1812,PASSWORD,radius")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-ENT-FT-EAP")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            dev[0].connect("test-ent-ft-eap", key_mgmt="FT-EAP", eap="GPSK",
-                           identity="gpsk user",
-                           password="abcdefghijklmnop0123456789abcdef",
-                           scan_freq="2412")
-            dev[1].connect("test-ent-ft-eap", key_mgmt="WPA-EAP", eap="GPSK",
-                           identity="gpsk user",
-                           password="abcdefghijklmnop0123456789abcdef",
-                           scan_freq="2412")
-
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-ent-ft-eap,MODE,11ng,DOMAIN,0101,FT_OA,Enable")
+        dut.cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,1812,PASSWORD,radius")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-ENT-FT-EAP")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        dev[0].connect("test-ent-ft-eap", key_mgmt="FT-EAP", eap="GPSK",
+                       identity="gpsk user",
+                       password="abcdefghijklmnop0123456789abcdef",
+                       scan_freq="2412")
+        dev[1].connect("test-ent-ft-eap", key_mgmt="WPA-EAP", eap="GPSK",
+                       identity="gpsk user",
+                       password="abcdefghijklmnop0123456789abcdef",
+                       scan_freq="2412")
 
 def test_sigma_dut_venue_url(dev, apdev):
     """sigma_dut controlled Venue URL fetch"""
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         ssid = "venue"
         params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
         params["wpa_key_mgmt"] = "WPA-PSK-SHA256"
@@ -4931,18 +4500,16 @@ def test_sigma_dut_venue_url(dev, apdev):
 
         hapd = hostapd.add_ap(apdev[0], params)
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_psk,interface,%s,ssid,%s,passphrase,%s,encpType,aes-ccmp,keymgmttype,wpa2,PMF,Required" % (ifname, "venue", "12345678"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "venue"),
+        dut.cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_psk,interface,%s,ssid,%s,passphrase,%s,encpType,aes-ccmp,keymgmttype,wpa2,PMF,Required" % (ifname, "venue", "12345678"))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "venue"),
                             timeout=10)
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
-        sigma_dut_cmd_check("sta_hs2_venue_info,interface," + ifname + ",Display,Yes")
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.wait_connected()
+        dut.cmd_check("sta_get_ip_config,interface," + ifname)
+        dut.cmd_check("sta_hs2_venue_info,interface," + ifname + ",Display,Yes")
+        dut.cmd_check("sta_disconnect,interface," + ifname)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_hs20_assoc_24(dev, apdev):
     """sigma_dut controlled Hotspot 2.0 connection (2.4 GHz)"""
@@ -4986,20 +4553,16 @@ def run_sigma_dut_hs20_assoc_2(dev, apdev, band, expect_bssid):
     dev[0].flush_scan_cache()
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,HS2-R3" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_add_credential,interface,%s,type,uname_pwd,realm,example.com,username,hs20-test,password,password" % ifname)
-        res = sigma_dut_cmd_check("sta_hs2_associate,interface,%s,band,%s" % (ifname, band),
+    with SigmaDut(dev=dev[0]) as dut:
+        dut.cmd_check("sta_reset_default,interface,%s,prog,HS2-R3" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_add_credential,interface,%s,type,uname_pwd,realm,example.com,username,hs20-test,password,password" % ifname)
+        res = dut.cmd_check("sta_hs2_associate,interface,%s,band,%s" % (ifname, band),
                                   timeout=15)
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.wait_connected()
+        dut.cmd_check("sta_get_ip_config,interface," + ifname)
+        dut.cmd_check("sta_disconnect,interface," + ifname)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
     if "BSSID," + expect_bssid not in res:
         raise Exception("Unexpected BSSID: " + res)
@@ -5010,31 +4573,26 @@ def test_sigma_dut_ap_hs20(dev, apdev, params):
                           "sigma_dut_ap_hs20.sigma-hostapd")
     conffile = os.path.join(params['logdir'],
                             "sigma_dut_ap_hs20.sigma-conf")
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default,NAME,AP,program,HS2-R3")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,1,CHANNEL,1,SSID,test-hs20,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_radius,NAME,AP,WLAN_TAG,1,IPADDR,127.0.0.1,PORT,1812,PASSWORD,radius")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,1,KEYMGNT,WPA2-ENT")
-            sigma_dut_cmd_check("ap_set_hs2,NAME,AP,WLAN_TAG,1,HESSID,02:12:34:56:78:9a,NAI_REALM_LIST,1,OPER_NAME,1")
-            sigma_dut_cmd_check("ap_set_hs2,NAME,AP,WLAN_TAG,1,OSU_SERVER_URI,https://example.com/ https://example.org/,OSU_SSID,test-osu,OSU_METHOD,SOAP SOAP,OSU_PROVIDER_LIST,10,OSU_PROVIDER_NAI_LIST,4")
-            sigma_dut_cmd_check("ap_set_hs2,NAME,AP,WLAN_TAG,1,NET_AUTH_TYPE,2")
-            sigma_dut_cmd_check("ap_set_hs2,NAME,AP,WLAN_TAG,1,VENUE_NAME,1")
-            sigma_dut_cmd_check("ap_set_hs2,NAME,AP,WLAN_TAG,1,DOMAIN_LIST,example.com")
-            sigma_dut_cmd_check("ap_set_hs2,NAME,AP,WLAN_TAG,1,OPERATOR_ICON_METADATA,1")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,2,CHANNEL,1,SSID,test-osu,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,2,KEYMGNT,NONE")
-            sigma_dut_cmd_check("ap_set_hs2,NAME,AP,WLAN_TAG,2,OSU,1")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            with open("/tmp/sigma_dut-ap.conf", "rb") as f:
-                with open(conffile, "wb") as f2:
-                    f2.write(f.read())
-
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default,NAME,AP,program,HS2-R3")
+        dut.cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,1,CHANNEL,1,SSID,test-hs20,MODE,11ng")
+        dut.cmd_check("ap_set_radius,NAME,AP,WLAN_TAG,1,IPADDR,127.0.0.1,PORT,1812,PASSWORD,radius")
+        dut.cmd_check("ap_set_security,NAME,AP,WLAN_TAG,1,KEYMGNT,WPA2-ENT")
+        dut.cmd_check("ap_set_hs2,NAME,AP,WLAN_TAG,1,HESSID,02:12:34:56:78:9a,NAI_REALM_LIST,1,OPER_NAME,1")
+        dut.cmd_check("ap_set_hs2,NAME,AP,WLAN_TAG,1,OSU_SERVER_URI,https://example.com/ https://example.org/,OSU_SSID,test-osu,OSU_METHOD,SOAP SOAP,OSU_PROVIDER_LIST,10,OSU_PROVIDER_NAI_LIST,4")
+        dut.cmd_check("ap_set_hs2,NAME,AP,WLAN_TAG,1,NET_AUTH_TYPE,2")
+        dut.cmd_check("ap_set_hs2,NAME,AP,WLAN_TAG,1,VENUE_NAME,1")
+        dut.cmd_check("ap_set_hs2,NAME,AP,WLAN_TAG,1,DOMAIN_LIST,example.com")
+        dut.cmd_check("ap_set_hs2,NAME,AP,WLAN_TAG,1,OPERATOR_ICON_METADATA,1")
+        dut.cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,2,CHANNEL,1,SSID,test-osu,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,WLAN_TAG,2,KEYMGNT,NONE")
+        dut.cmd_check("ap_set_hs2,NAME,AP,WLAN_TAG,2,OSU,1")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        with open("/tmp/sigma_dut-ap.conf", "rb") as f, \
+             open(conffile, "wb") as f2:
+            f2.write(f.read())
 
 def test_sigma_dut_eap_ttls_uosc(dev, apdev, params):
     """sigma_dut controlled STA and EAP-TTLS with UOSC"""
@@ -5066,29 +4624,25 @@ def test_sigma_dut_eap_ttls_uosc(dev, apdev, params):
     hapd = hostapd.add_ap(apdev[0], params)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname, cert_path=logdir)
-
-    try:
+    with SigmaDut(dev=dev[0], cert_path=logdir) as dut:
         cmd = "sta_set_security,type,eapttls,interface,%s,ssid,%s,keymgmttype,wpa2,encType,AES-CCMP,PairwiseCipher,AES-CCMP-128,username,DOMAIN\mschapv2 user,password,password,ServerCert,sigma_dut_eap_ttls_uosc.incorrect.pem" % (ifname, ssid)
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check(cmd)
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, ssid),
+        dut.cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check(cmd)
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, ssid),
                             timeout=10)
         ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=10)
         if ev is None:
             raise Exception("Server certificate error not reported")
 
-        res = sigma_dut_cmd_check("dev_exec_action,program,WPA3,interface,%s,ServerCertTrust,Accept" % ifname)
+        res = dut.cmd_check("dev_exec_action,program,WPA3,interface,%s,ServerCertTrust,Accept" % ifname)
         if "ServerCertTrustResult,Accepted" not in res:
             raise Exception("Server certificate trust was not accepted")
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
+        dut.wait_connected()
+        dut.cmd_check("sta_disconnect,interface," + ifname)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
         dev[0].dump_monitor()
-    finally:
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_eap_ttls_uosc_tod(dev, apdev, params):
     """sigma_dut controlled STA and EAP-TTLS with UOSC/TOD-STRICT"""
@@ -5136,18 +4690,16 @@ def run_sigma_dut_eap_ttls_uosc_tod(dev, apdev, params, tofu):
     hapd = hostapd.add_ap(apdev[0], params)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname, cert_path=logdir)
-
-    try:
+    with SigmaDut(dev=dev[0], cert_path=logdir) as dut:
         cmd = ("sta_set_security,type,eapttls,interface,%s,ssid,%s,keymgmttype,wpa2,encType,AES-CCMP,PairwiseCipher,AES-CCMP-128,trustedRootCA," + name + ".ca.pem,username,DOMAIN\mschapv2 user,password,password,ServerCert," + name + ".server.pem") % (ifname, ssid)
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check(cmd)
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, ssid),
+        dut.cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check(cmd)
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, ssid),
                             timeout=10)
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname + ",maintain_profile,1")
+        dut.wait_connected()
+        dut.cmd_check("sta_get_ip_config,interface," + ifname)
+        dut.cmd_check("sta_disconnect,interface," + ifname + ",maintain_profile,1")
         dev[0].wait_disconnected()
         dev[0].dump_monitor()
 
@@ -5155,19 +4707,17 @@ def run_sigma_dut_eap_ttls_uosc_tod(dev, apdev, params, tofu):
         params = hostapd.wpa2_eap_params(ssid=ssid)
         hapd = hostapd.add_ap(apdev[0], params)
 
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, ssid),
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, ssid),
                             timeout=10)
         ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=10)
         if ev is None:
             raise Exception("Server certificate error not reported")
 
-        res = sigma_dut_cmd_check("dev_exec_action,program,WPA3,interface,%s,ServerCertTrust,Accept" % ifname)
+        res = dut.cmd_check("dev_exec_action,program,WPA3,interface,%s,ServerCertTrust,Accept" % ifname)
         if "ServerCertTrustResult,Accepted" in res:
             raise Exception("Server certificate trust override was accepted unexpectedly")
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
         dev[0].dump_monitor()
-    finally:
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_eap_ttls_uosc_initial_tod_strict(dev, apdev, params):
     """sigma_dut controlled STA and EAP-TTLS with initial UOSC/TOD-STRICT"""
@@ -5212,28 +4762,24 @@ def run_sigma_dut_eap_ttls_uosc_initial_tod(dev, apdev, params, tofu):
     hapd = hostapd.add_ap(apdev[0], params)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname, cert_path=logdir)
-
-    try:
+    with SigmaDut(dev=dev[0], cert_path=logdir) as dut:
         cmd = ("sta_set_security,type,eapttls,interface,%s,ssid,%s,keymgmttype,wpa2,encType,AES-CCMP,PairwiseCipher,AES-CCMP-128,trustedRootCA," + name + ".ca.pem,username,DOMAIN\mschapv2 user,password,password") % (ifname, ssid)
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check(cmd)
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, ssid),
+        dut.cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check(cmd)
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, ssid),
                             timeout=10)
         ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=15)
         if ev is None:
             raise Exception("Server certificate validation failure not reported")
 
-        res = sigma_dut_cmd_check("dev_exec_action,program,WPA3,interface,%s,ServerCertTrust,Accept" % ifname)
+        res = dut.cmd_check("dev_exec_action,program,WPA3,interface,%s,ServerCertTrust,Accept" % ifname)
         if not tofu and "ServerCertTrustResult,Accepted" in res:
             raise Exception("Server certificate trust override was accepted unexpectedly")
         if tofu and "ServerCertTrustResult,Accepted" not in res:
             raise Exception("Server certificate trust override was not accepted")
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
         dev[0].dump_monitor()
-    finally:
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_eap_ttls_uosc_ca_mistrust(dev, apdev, params):
     """sigma_dut controlled STA and EAP-TTLS with UOSC when CA is not trusted"""
@@ -5255,28 +4801,24 @@ def test_sigma_dut_eap_ttls_uosc_ca_mistrust(dev, apdev, params):
     hapd = hostapd.add_ap(apdev[0], params)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname, cert_path=logdir)
-
-    try:
+    with SigmaDut(dev=dev[0], cert_path=logdir) as dut:
         cmd = "sta_set_security,type,eapttls,interface,%s,ssid,%s,keymgmttype,wpa2,encType,AES-CCMP,PairwiseCipher,AES-CCMP-128,trustedRootCA,sigma_dut_eap_ttls_uosc_ca_mistrust.ca.pem,username,DOMAIN\mschapv2 user,password,password,domainSuffix,w1.fi" % (ifname, ssid)
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check(cmd)
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, ssid),
+        dut.cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check(cmd)
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, ssid),
                             timeout=10)
         ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"], timeout=10)
         if ev is None:
             raise Exception("Server certificate error not reported")
 
-        res = sigma_dut_cmd_check("dev_exec_action,program,WPA3,interface,%s,ServerCertTrust,Accept" % ifname)
+        res = dut.cmd_check("dev_exec_action,program,WPA3,interface,%s,ServerCertTrust,Accept" % ifname)
         if "ServerCertTrustResult,Accepted" not in res:
             raise Exception("Server certificate trust was not accepted")
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
+        dut.wait_connected()
+        dut.cmd_check("sta_disconnect,interface," + ifname)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
         dev[0].dump_monitor()
-    finally:
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_eap_aka(dev, apdev, params):
     """sigma_dut controlled STA and EAP-AKA parameters"""
@@ -5293,23 +4835,19 @@ def test_sigma_dut_eap_aka(dev, apdev, params):
     hapd = hostapd.add_ap(apdev[0], params)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname, cert_path=logdir)
-
     identity = "0232010000000000@wlan.mnc232.mcc02.3gppnetwork.org"
     password = "90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123"
     cmd = "sta_set_eapaka,interface,%s,ssid,%s,keymgmttype,wpa2,encpType,AES-CCMP,imsiPrivacyCert,%s,imsiPrivacyCertID,serno=12345,username,%s,password,%s" % (ifname, ssid, cert_file, identity, password)
 
-    try:
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
-        sigma_dut_cmd_check(cmd)
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, ssid),
-                            timeout=10)
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
+    with SigmaDut(dev=dev[0], cert_path=logdir) as dut:
+        dut.cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
+        dut.cmd_check(cmd)
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, ssid),
+                      timeout=10)
+        dut.wait_connected()
+        dut.cmd_check("sta_disconnect,interface," + ifname)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
         dev[0].dump_monitor()
-    finally:
-        stop_sigma_dut(sigma)
 
 def start_sae_pwe_ap(apdev, sae_pwe, ssid="test-sae", password="12345678"):
     params = hostapd.wpa2_params(ssid=ssid, passphrase=password)
@@ -5319,37 +4857,37 @@ def start_sae_pwe_ap(apdev, sae_pwe, ssid="test-sae", password="12345678"):
     params['sae_pwe'] = str(sae_pwe)
     return hostapd.add_ap(apdev, params)
 
-def connect_sae_pwe_sta(dev, ifname, extra=None):
+def connect_sae_pwe_sta(dut, dev, ifname, extra=None):
     dev.dump_monitor()
-    sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname)
-    sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+    dut.cmd_check("sta_reset_default,interface,%s" % ifname)
+    dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
     cmd = "sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, "test-sae", "12345678")
     if extra:
         cmd += "," + extra
-    sigma_dut_cmd_check(cmd)
-    sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
+    dut.cmd_check(cmd)
+    dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
                         timeout=10)
-    sigma_dut_wait_connected(ifname)
-    sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
+    dut.wait_connected()
+    dut.cmd_check("sta_disconnect,interface," + ifname)
     dev.wait_disconnected()
-    sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
+    dut.cmd_check("sta_reset_default,interface," + ifname)
     dev.dump_monitor()
 
-def no_connect_sae_pwe_sta(dev, ifname, extra=None):
+def no_connect_sae_pwe_sta(dut, dev, ifname, extra=None):
     dev.dump_monitor()
-    sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname)
-    sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+    dut.cmd_check("sta_reset_default,interface,%s" % ifname)
+    dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
     cmd = "sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, "test-sae", "12345678")
     if extra:
         cmd += "," + extra
-    sigma_dut_cmd_check(cmd)
-    sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
+    dut.cmd_check(cmd)
+    dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
                         timeout=10)
     ev = dev.wait_event(["CTRL-EVENT-CONNECTED",
                          "CTRL-EVENT-NETWORK-NOT-FOUND"], timeout=10)
     if ev is None or "CTRL-EVENT-CONNECTED" in ev:
         raise Exception("Unexpected connection result")
-    sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
+    dut.cmd_check("sta_reset_default,interface," + ifname)
     dev.dump_monitor()
 
 def test_sigma_dut_sae_h2e(dev, apdev):
@@ -5359,17 +4897,13 @@ def test_sigma_dut_sae_h2e(dev, apdev):
     start_sae_pwe_ap(apdev[0], 2)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname, sae_h2e=True)
-    try:
-        connect_sae_pwe_sta(dev[0], ifname)
-        connect_sae_pwe_sta(dev[0], ifname, extra="sae_pwe,h2e")
-        connect_sae_pwe_sta(dev[0], ifname, extra="sae_pwe,loop")
-        res = sigma_dut_cmd("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2,sae_pwe,unknown" % (ifname, "test-sae", "12345678"))
+    with SigmaDut(dev=dev[0], sae_h2e=True) as dut:
+        connect_sae_pwe_sta(dut, dev[0], ifname)
+        connect_sae_pwe_sta(dut, dev[0], ifname, extra="sae_pwe,h2e")
+        connect_sae_pwe_sta(dut, dev[0], ifname, extra="sae_pwe,loop")
+        res = dut.run_cmd("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2,sae_pwe,unknown" % (ifname, "test-sae", "12345678"))
         if res != "status,ERROR,errorCode,Unsupported sae_pwe value":
             raise Exception("Unexpected error result: " + res)
-    finally:
-        stop_sigma_dut(sigma)
-        dev[0].set("sae_pwe", "0")
 
 def test_sigma_dut_sae_h2e_ap_loop(dev, apdev):
     """sigma_dut controlled SAE H2E association (AP using loop-only)"""
@@ -5378,14 +4912,10 @@ def test_sigma_dut_sae_h2e_ap_loop(dev, apdev):
     start_sae_pwe_ap(apdev[0], 0)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname, sae_h2e=True)
-    try:
-        connect_sae_pwe_sta(dev[0], ifname)
-        connect_sae_pwe_sta(dev[0], ifname, extra="sae_pwe,loop")
-        no_connect_sae_pwe_sta(dev[0], ifname, extra="sae_pwe,h2e")
-    finally:
-        stop_sigma_dut(sigma)
-        dev[0].set("sae_pwe", "0")
+    with SigmaDut(dev=dev[0], sae_h2e=True) as dut:
+        connect_sae_pwe_sta(dut, dev[0], ifname)
+        connect_sae_pwe_sta(dut, dev[0], ifname, extra="sae_pwe,loop")
+        no_connect_sae_pwe_sta(dut, dev[0], ifname, extra="sae_pwe,h2e")
 
 def test_sigma_dut_sae_h2e_ap_h2e(dev, apdev):
     """sigma_dut controlled SAE H2E association (AP using H2E-only)"""
@@ -5394,27 +4924,23 @@ def test_sigma_dut_sae_h2e_ap_h2e(dev, apdev):
     start_sae_pwe_ap(apdev[0], 1)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname, sae_h2e=True)
-    try:
-        connect_sae_pwe_sta(dev[0], ifname)
-        no_connect_sae_pwe_sta(dev[0], ifname, extra="sae_pwe,loop")
-        connect_sae_pwe_sta(dev[0], ifname, extra="sae_pwe,h2e")
-    finally:
-        stop_sigma_dut(sigma)
-        dev[0].set("sae_pwe", "0")
+    with SigmaDut(dev=dev[0], sae_h2e=True) as dut:
+        connect_sae_pwe_sta(dut, dev[0], ifname)
+        no_connect_sae_pwe_sta(dut, dev[0], ifname, extra="sae_pwe,loop")
+        connect_sae_pwe_sta(dut, dev[0], ifname, extra="sae_pwe,h2e")
 
 def test_sigma_dut_ap_sae_h2e(dev, apdev, params):
     """sigma_dut controlled AP with SAE H2E"""
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_sae_h2e.sigma-hostapd")
     check_sae_capab(dev[0])
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, sae_h2e=True, hostapd_logdir=logdir)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, sae_h2e=True, hostapd_logdir=logdir) as dut:
         try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
+            dut.cmd_check("ap_reset_default")
+            dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
+            dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678")
+            dut.cmd_check("ap_config_commit,NAME,AP")
 
             for sae_pwe in [0, 1, 2]:
                 dev[0].request("SET sae_groups ")
@@ -5424,10 +4950,7 @@ def test_sigma_dut_ap_sae_h2e(dev, apdev, params):
                 dev[0].request("REMOVE_NETWORK all")
                 dev[0].wait_disconnected()
                 dev[0].dump_monitor()
-
-            sigma_dut_cmd_check("ap_reset_default")
         finally:
-            stop_sigma_dut(sigma)
             dev[0].set("sae_pwe", "0")
 
 def test_sigma_dut_ap_sae_h2e_only(dev, apdev, params):
@@ -5435,13 +4958,13 @@ def test_sigma_dut_ap_sae_h2e_only(dev, apdev, params):
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_sae_h2e.sigma-hostapd")
     check_sae_capab(dev[0])
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, sae_h2e=True, hostapd_logdir=logdir)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, sae_h2e=True, hostapd_logdir=logdir) as dut:
         try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,sae_pwe,h2e")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
+            dut.cmd_check("ap_reset_default")
+            dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
+            dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,sae_pwe,h2e")
+            dut.cmd_check("ap_config_commit,NAME,AP")
 
             dev[0].request("SET sae_groups ")
             dev[0].set("sae_pwe", "1")
@@ -5459,10 +4982,7 @@ def test_sigma_dut_ap_sae_h2e_only(dev, apdev, params):
             dev[0].request("DISCONNECT")
             if ev is None or "CTRL-EVENT-CONNECTED" in ev:
                 raise Exception("Unexpected connection result")
-
-            sigma_dut_cmd_check("ap_reset_default")
         finally:
-            stop_sigma_dut(sigma)
             dev[0].set("sae_pwe", "0")
 
 def test_sigma_dut_ap_sae_loop_only(dev, apdev, params):
@@ -5470,13 +4990,13 @@ def test_sigma_dut_ap_sae_loop_only(dev, apdev, params):
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_sae_h2e.sigma-hostapd")
     check_sae_capab(dev[0])
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, sae_h2e=True, hostapd_logdir=logdir)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
         try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,sae_pwe,loop")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
+            dut.cmd_check("ap_reset_default")
+            dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
+            dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,sae_pwe,loop")
+            dut.cmd_check("ap_config_commit,NAME,AP")
 
             dev[0].request("SET sae_groups ")
             dev[0].set("sae_pwe", "0")
@@ -5494,10 +5014,7 @@ def test_sigma_dut_ap_sae_loop_only(dev, apdev, params):
             dev[0].request("DISCONNECT")
             if ev is None or "CTRL-EVENT-CONNECTED" in ev:
                 raise Exception("Unexpected connection result")
-
-            sigma_dut_cmd_check("ap_reset_default")
         finally:
-            stop_sigma_dut(sigma)
             dev[0].set("sae_pwe", "0")
 
 def test_sigma_dut_sae_h2e_loop_forcing(dev, apdev):
@@ -5512,12 +5029,11 @@ def test_sigma_dut_sae_h2e_loop_forcing(dev, apdev):
     hapd = hostapd.add_ap(apdev[0], params)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-    try:
-        sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2,IgnoreH2E_RSNXE_BSSMemSel,1" % (ifname, "test-sae", "12345678"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
+    with SigmaDut(dev=dev[0]) as dut:
+        dut.cmd_check("sta_reset_default,interface,%s" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2,IgnoreH2E_RSNXE_BSSMemSel,1" % (ifname, "test-sae", "12345678"))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
                             timeout=10)
         ev = dev[0].wait_event(["SME: Trying to authenticate with"], timeout=10)
         if ev is None:
@@ -5525,8 +5041,6 @@ def test_sigma_dut_sae_h2e_loop_forcing(dev, apdev):
         ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.5)
         if ev is not None:
             raise Exception("Unexpected connection reported")
-    finally:
-        stop_sigma_dut(sigma)
 
 def test_sigma_dut_sae_h2e_enabled_group_rejected(dev, apdev):
     """sigma_dut controlled SAE H2E misbehavior with rejected groups"""
@@ -5541,22 +5055,18 @@ def test_sigma_dut_sae_h2e_enabled_group_rejected(dev, apdev):
     hapd = hostapd.add_ap(apdev[0], params)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname, sae_h2e=True)
-    try:
-        sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2,ECGroupID_RGE,19 123" % (ifname, "test-sae", "12345678"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
-                            timeout=10)
+    with SigmaDut(dev=dev[0], sae_h2e=True) as dut:
+        dut.cmd_check("sta_reset_default,interface,%s" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2,ECGroupID_RGE,19 123" % (ifname, "test-sae", "12345678"))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
+                      timeout=10)
         ev = dev[0].wait_event(["SME: Trying to authenticate with"], timeout=10)
         if ev is None:
             raise Exception("No authentication attempt reported")
         ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.5)
         if ev is not None:
             raise Exception("Unexpected connection reported")
-    finally:
-        stop_sigma_dut(sigma)
-        dev[0].set("sae_pwe", "0")
 
 def test_sigma_dut_sae_h2e_rsnxe_mismatch(dev, apdev):
     """sigma_dut controlled SAE H2E misbehavior with RSNXE"""
@@ -5571,12 +5081,11 @@ def test_sigma_dut_sae_h2e_rsnxe_mismatch(dev, apdev):
     hapd = hostapd.add_ap(apdev[0], params)
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname, sae_h2e=True)
-    try:
-        sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2,RSNXE_Content,EapolM2:F40100" % (ifname, "test-sae", "12345678"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
+    with SigmaDut(dev=dev[0], sae_h2e=True) as dut:
+        dut.cmd_check("sta_reset_default,interface,%s" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2,RSNXE_Content,EapolM2:F40100" % (ifname, "test-sae", "12345678"))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
                             timeout=10)
         ev = dev[0].wait_event(["SME: Trying to authenticate with"], timeout=10)
         if ev is None:
@@ -5584,22 +5093,19 @@ def test_sigma_dut_sae_h2e_rsnxe_mismatch(dev, apdev):
         ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.5)
         if ev is not None:
             raise Exception("Unexpected connection reported")
-    finally:
-        stop_sigma_dut(sigma)
-        dev[0].set("sae_pwe", "0")
 
 def test_sigma_dut_ap_sae_h2e_rsnxe_mismatch(dev, apdev, params):
     """sigma_dut controlled SAE H2E AP misbehavior with RSNXE"""
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_sae_h2e_rsnxe_mismatch.sigma-hostapd")
     check_sae_capab(dev[0])
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, sae_h2e=True, hostapd_logdir=logdir)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
         try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,sae_pwe,h2e,RSNXE_Content,EapolM3:F40100")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
+            dut.cmd_check("ap_reset_default")
+            dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
+            dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,sae_pwe,h2e,RSNXE_Content,EapolM3:F40100")
+            dut.cmd_check("ap_config_commit,NAME,AP")
 
             dev[0].request("SET sae_groups ")
             dev[0].set("sae_pwe", "1")
@@ -5615,10 +5121,7 @@ def test_sigma_dut_ap_sae_h2e_rsnxe_mismatch(dev, apdev, params):
                 raise Exception("No disconnection seen")
             if "CTRL-EVENT-DISCONNECTED" not in ev:
                 raise Exception("Unexpected connection")
-
-            sigma_dut_cmd_check("ap_reset_default")
         finally:
-            stop_sigma_dut(sigma)
             dev[0].set("sae_pwe", "0")
 
 def test_sigma_dut_ap_sae_h2e_group_rejection(dev, apdev, params):
@@ -5626,26 +5129,23 @@ def test_sigma_dut_ap_sae_h2e_group_rejection(dev, apdev, params):
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_sae_h2e_group_rejection.sigma-hostapd")
     check_sae_capab(dev[0])
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, sae_h2e=True, hostapd_logdir=logdir)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
         try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,sae_pwe,h2e")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
+            dut.cmd_check("ap_reset_default")
+            dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
+            dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,sae_pwe,h2e")
+            dut.cmd_check("ap_config_commit,NAME,AP")
 
             dev[0].request("SET sae_groups 21 20 19")
             dev[0].set("sae_pwe", "1")
             dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
                            ieee80211w="2", scan_freq="2412")
             addr = dev[0].own_addr()
-            res = sigma_dut_cmd_check("dev_exec_action,program,WPA3,Dest_MAC,%s,Rejected_DH_Groups,1" % addr)
+            res = dut.cmd_check("dev_exec_action,program,WPA3,Dest_MAC,%s,Rejected_DH_Groups,1" % addr)
             if "DHGroupVerResult,21 20" not in res:
                 raise Exception("Unexpected dev_exec_action response: " + res)
-
-            sigma_dut_cmd_check("ap_reset_default")
         finally:
-            stop_sigma_dut(sigma)
             dev[0].set("sae_pwe", "0")
 
 def test_sigma_dut_ap_sae_h2e_anti_clogging(dev, apdev, params):
@@ -5653,22 +5153,19 @@ def test_sigma_dut_ap_sae_h2e_anti_clogging(dev, apdev, params):
     logdir = os.path.join(params['logdir'],
                           "sigma_dut_ap_sae_h2e_anti_clogging.sigma-hostapd")
     check_sae_capab(dev[0])
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, sae_h2e=True, hostapd_logdir=logdir)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
         try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,SAE,PSK,12345678,AntiCloggingThreshold,0")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
+            dut.cmd_check("ap_reset_default")
+            dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
+            dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,SAE,PSK,12345678,AntiCloggingThreshold,0")
+            dut.cmd_check("ap_config_commit,NAME,AP")
 
             dev[0].set("sae_groups", "")
             dev[0].set("sae_pwe", "2")
             dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
                            ieee80211w="2", scan_freq="2412")
-
-            sigma_dut_cmd_check("ap_reset_default")
         finally:
-            stop_sigma_dut(sigma)
             dev[0].set("sae_pwe", "0")
 
 def test_sigma_dut_ap_5ghz(dev, apdev, params):
@@ -5701,8 +5198,8 @@ def test_sigma_dut_ap_vht80(dev, apdev, params):
 def run_sigma_dut_ap_channel(dev, apdev, params, channel, mode, scan_freq,
                              extra=None, check_signal=None, program=None):
     logdir = params['prefix'] + ".sigma-hostapd"
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
         try:
             subprocess.call(['iw', 'reg', 'set', 'US'])
             for i in range(5):
@@ -5714,13 +5211,13 @@ def run_sigma_dut_ap_channel(dev, apdev, params, channel, mode, scan_freq,
             cmd = "ap_reset_default"
             if program:
                 cmd += ",program," + program
-            sigma_dut_cmd_check(cmd)
+            dut.cmd_check(cmd)
             cmd = "ap_set_wireless,NAME,AP,CHANNEL,%d,SSID,test-psk,MODE,%s" % (channel, mode)
             if extra:
                 cmd += "," + extra
-            sigma_dut_cmd_check(cmd)
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
+            dut.cmd_check(cmd)
+            dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678")
+            dut.cmd_check("ap_config_commit,NAME,AP")
 
             with open("/tmp/sigma_dut-ap.conf", "rb") as f:
                 with open(params['prefix'] + ".sigma-conf", "wb") as f2:
@@ -5732,12 +5229,9 @@ def run_sigma_dut_ap_channel(dev, apdev, params, channel, mode, scan_freq,
             dev[0].request("DISCONNECT")
             dev[0].wait_disconnected()
 
-            sigma_dut_cmd_check("ap_reset_default")
-
             if check_signal and check_signal not in sig:
                 raise Exception("Unexpected SIGNAL_POLL data")
         finally:
-            stop_sigma_dut(sigma)
             subprocess.call(['iw', 'reg', 'set', '00'])
             dev[0].flush_scan_cache()
 
@@ -5756,22 +5250,18 @@ def test_sigma_dut_beacon_prot(dev, apdev):
         raise
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,type,PSK,passphrase,%s,encpType,aes-ccmp,keymgmttype,wpa2,PMF,Required,BeaconProtection,1" % (ifname, "test-pmf-required", "12345678"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-pmf-required"),
+    with SigmaDut(dev=dev[0]) as dut:
+        dut.cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,%s,type,PSK,passphrase,%s,encpType,aes-ccmp,keymgmttype,wpa2,PMF,Required,BeaconProtection,1" % (ifname, "test-pmf-required", "12345678"))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-pmf-required"),
                             timeout=10)
-        sigma_dut_wait_connected(ifname)
+        dut.wait_connected()
 
         time.sleep(1)
         check_mac80211_bigtk(dev[0], hapd)
 
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_ap_beacon_prot(dev, apdev, params):
     """sigma_dut controlled AP and beacon protection"""
@@ -5782,24 +5272,19 @@ def test_sigma_dut_ap_beacon_prot(dev, apdev, params):
     wt.flush()
     wt.add_passphrase("12345678")
 
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678,PMF,Required,BeaconProtection,1")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-            bssid = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP")
-            bssid = bssid.split(',')[3]
-
-            dev[0].connect("test-psk", key_mgmt="WPA-PSK-SHA256",
-                           psk="12345678", scan_freq="2412",
-                           ieee80211w="2", beacon_prot="1")
-            time.sleep(1)
-
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678,PMF,Required,BeaconProtection,1")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+        bssid = dut.cmd_check("ap_get_mac_address,NAME,AP")
+        bssid = bssid.split(',')[3]
+
+        dev[0].connect("test-psk", key_mgmt="WPA-PSK-SHA256",
+                       psk="12345678", scan_freq="2412",
+                       ieee80211w="2", beacon_prot="1")
+        time.sleep(1)
 
     valid_bip = wt.get_bss_counter('valid_bip_mmie', bssid)
     invalid_bip = wt.get_bss_counter('invalid_bip_mmie', bssid)
@@ -5813,69 +5298,57 @@ def test_sigma_dut_ap_transition_disable(dev, apdev, params):
     check_sae_capab(dev[0])
     logdir = params['prefix'] + ".sigma-hostapd"
 
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,PMF,Required,Transition_Disable,1,Transition_Disable_Index,0")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            dev[0].set("sae_groups", "")
-            dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
-                           ieee80211w="2", scan_freq="2412", wait_connect=False)
-            ev = dev[0].wait_event(["TRANSITION-DISABLE"], timeout=15)
-            if ev is None:
-                raise Exception("Transition disable not indicated")
-            if ev.split(' ')[1] != "01":
-                raise Exception("Unexpected transition disable bitmap: " + ev)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,PMF,Required,Transition_Disable,1,Transition_Disable_Index,0")
+        dut.cmd_check("ap_config_commit,NAME,AP")
 
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+        dev[0].set("sae_groups", "")
+        dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
+                       ieee80211w="2", scan_freq="2412", wait_connect=False)
+        ev = dev[0].wait_event(["TRANSITION-DISABLE"], timeout=15)
+        if ev is None:
+            raise Exception("Transition disable not indicated")
+        if ev.split(' ')[1] != "01":
+            raise Exception("Unexpected transition disable bitmap: " + ev)
 
 def test_sigma_dut_ap_transition_disable_change(dev, apdev, params):
     """sigma_dut controlled AP and transition disabled indication change"""
     check_sae_capab(dev[0])
     logdir = params['prefix'] + ".sigma-hostapd"
 
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,PMF,Required")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-            dev[0].set("sae_groups", "")
-            dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
-                           ieee80211w="2", scan_freq="2412", wait_connect=False)
-            ev = dev[0].wait_event(["TRANSITION-DISABLE"], timeout=15)
-            if ev is not None:
-                raise Exception("Unexpected transition disable indication")
-            dev[0].request("DISCONNECT")
-            dev[0].wait_disconnected()
-            dev[0].dump_monitor()
-
-            sigma_dut_cmd_check("ap_set_rfeature,NAME,AP,Transition_Disable,1,Transition_Disable_Index,0")
-            dev[0].request("RECONNECT")
-            ev = dev[0].wait_event(["TRANSITION-DISABLE"], timeout=15)
-            if ev is None:
-                raise Exception("Transition disable not indicated")
-            if ev.split(' ')[1] != "01":
-                raise Exception("Unexpected transition disable bitmap: " + ev)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,PMF,Required")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+        dev[0].set("sae_groups", "")
+        dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
+                       ieee80211w="2", scan_freq="2412", wait_connect=False)
+        ev = dev[0].wait_event(["TRANSITION-DISABLE"], timeout=15)
+        if ev is not None:
+            raise Exception("Unexpected transition disable indication")
+        dev[0].request("DISCONNECT")
+        dev[0].wait_disconnected()
+        dev[0].dump_monitor()
 
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+        dut.cmd_check("ap_set_rfeature,NAME,AP,Transition_Disable,1,Transition_Disable_Index,0")
+        dev[0].request("RECONNECT")
+        ev = dev[0].wait_event(["TRANSITION-DISABLE"], timeout=15)
+        if ev is None:
+            raise Exception("Transition disable not indicated")
+        if ev.split(' ')[1] != "01":
+            raise Exception("Unexpected transition disable bitmap: " + ev)
 
 def test_sigma_dut_ft_rsnxe_used_mismatch(dev, apdev):
     """sigma_dut controlled FT protocol with RSNXE Used mismatch"""
     check_sae_capab(dev[0])
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         ssid = "test-sae"
         params = hostapd.wpa2_params(ssid=ssid)
         params['wpa_key_mgmt'] = 'SAE FT-SAE'
@@ -5892,12 +5365,12 @@ def test_sigma_dut_ft_rsnxe_used_mismatch(dev, apdev):
         hapd = hostapd.add_ap(apdev[0], params)
         bssid = hapd.own_addr()
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,AKMSuiteType,8;9" % (ifname, "test-sae", "hello"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
+        dut.cmd_check("sta_reset_default,interface,%s" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,AKMSuiteType,8;9" % (ifname, "test-sae", "hello"))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
                             timeout=10)
-        sigma_dut_wait_connected(ifname)
+        dut.wait_connected()
         dev[0].dump_monitor()
 
         bssid2 = apdev[1]['bssid'].replace(':', '')
@@ -5906,7 +5379,7 @@ def test_sigma_dut_ft_rsnxe_used_mismatch(dev, apdev):
         hapd2 = hostapd.add_ap(apdev[1], params)
         bssid2 = hapd2.own_addr()
 
-        sigma_dut_cmd_check("sta_reassoc,interface,%s,Channel,1,bssid,%s" % (ifname, bssid2),
+        dut.cmd_check("sta_reassoc,interface,%s,Channel,1,bssid,%s" % (ifname, bssid2),
                             timeout=20)
         count = 0
         for i in range(5):
@@ -5921,8 +5394,8 @@ def test_sigma_dut_ft_rsnxe_used_mismatch(dev, apdev):
         if count != 1:
             raise Exception("Unexpected number of association attempts for the first FT protocol exchange (expecting success)")
 
-        sigma_dut_cmd_check("sta_set_rfeature,interface,%s,prog,WPA3,ReassocReq_RSNXE_Used,1" % ifname)
-        sigma_dut_cmd_check("sta_reassoc,interface,%s,Channel,1,bssid,%s" % (ifname, bssid))
+        dut.cmd_check("sta_set_rfeature,interface,%s,prog,WPA3,ReassocReq_RSNXE_Used,1" % ifname)
+        dut.cmd_check("sta_reassoc,interface,%s,Channel,1,bssid,%s" % (ifname, bssid))
         count = 0
         for i in range(5):
             ev = dev[0].wait_event(["Trying to associate",
@@ -5936,53 +5409,44 @@ def test_sigma_dut_ft_rsnxe_used_mismatch(dev, apdev):
         if count != 2:
             raise Exception("Unexpected number of association attempts for the second FT protocol exchange (expecting failure)")
 
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.cmd_check("sta_disconnect,interface," + ifname)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_ap_ft_rsnxe_used_mismatch(dev, apdev, params):
     """sigma_dut controlled AP with FT and RSNXE Used mismatch"""
     logdir = params['prefix'] + ".sigma-hostapd"
     conffile = params['prefix'] + ".sigma-conf"
     check_sae_capab(dev[0])
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng,DOMAIN,aabb")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,AKMSuiteType,8;9,SAEPasswords,hello,PMF,Required")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            with open("/tmp/sigma_dut-ap.conf", "rb") as f:
-                with open(conffile, "wb") as f2:
-                    f2.write(f.read())
-
-            dev[0].set("sae_groups", "")
-            dev[0].connect("test-sae", key_mgmt="FT-SAE", sae_password="hello",
-                           ieee80211w="2", scan_freq="2412")
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng,DOMAIN,aabb")
+        dut.cmd_check("ap_set_security,NAME,AP,AKMSuiteType,8;9,SAEPasswords,hello,PMF,Required")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+
+        with open("/tmp/sigma_dut-ap.conf", "rb") as f, \
+             open(conffile, "wb") as f2:
+            f2.write(f.read())
 
-            sigma_dut_cmd_check("ap_set_rfeature,NAME,AP,type,WPA3,ReassocResp_RSNXE_Used,1")
-            # This would need to be followed by FT protocol roaming test, but
-            # that is not currently convenient to implement, so for now, this
-            # test is based on manual inspection of hostapd getting configured
-            # properly.
+        dev[0].set("sae_groups", "")
+        dev[0].connect("test-sae", key_mgmt="FT-SAE", sae_password="hello",
+                       ieee80211w="2", scan_freq="2412")
 
-            dev[0].request("REMOVE_NETWORK all")
-            dev[0].wait_disconnected()
+        dut.cmd_check("ap_set_rfeature,NAME,AP,type,WPA3,ReassocResp_RSNXE_Used,1")
+        # This would need to be followed by FT protocol roaming test, but
+        # that is not currently convenient to implement, so for now, this
+        # test is based on manual inspection of hostapd getting configured
+        # properly.
 
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+        dev[0].request("REMOVE_NETWORK all")
+        dev[0].wait_disconnected()
 
 def test_sigma_dut_ocv(dev, apdev):
     """sigma_dut controlled STA using OCV"""
     check_sae_capab(dev[0])
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         ssid = "test-sae"
         params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
         params['wpa_key_mgmt'] = 'SAE'
@@ -5991,20 +5455,20 @@ def test_sigma_dut_ocv(dev, apdev):
         params['ocv'] = '1'
         hapd = hostapd.add_ap(apdev[0], params)
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_wireless,interface,%s,program,WPA3,ocvc,1" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, "test-sae", "12345678"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
+        dut.cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_wireless,interface,%s,program,WPA3,ocvc,1" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, "test-sae", "12345678"))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
                             timeout=10)
-        sigma_dut_wait_connected(ifname)
-
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_wireless,interface,%s,program,WPA3,ocvc,1" % ifname)
-        sigma_dut_cmd_check("sta_set_rfeature,interface,%s,prog,WPA3,OCIFrameType,eapolM2,OCIChannel,11" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, "test-sae", "12345678"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"))
+        dut.wait_connected()
+
+        dut.cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_wireless,interface,%s,program,WPA3,ocvc,1" % ifname)
+        dut.cmd_check("sta_set_rfeature,interface,%s,prog,WPA3,OCIFrameType,eapolM2,OCIChannel,11" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, "test-sae", "12345678"))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"))
         ev = hapd.wait_event(["OCV-FAILURE"], timeout=1)
         if ev is None:
             raise Exception("OCV failure for EAPOL-Key msg 2/4 not reported")
@@ -6015,59 +5479,49 @@ def test_sigma_dut_ocv(dev, apdev):
         if "error=primary channel mismatch" not in ev:
             raise Exception("Unexpected OCV failure error: " + ev)
 
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_ap_ocv(dev, apdev, params):
     """sigma_dut controlled AP using OCV"""
     logdir = params['prefix'] + ".sigma-hostapd"
     conffile = params['prefix'] + ".sigma-conf"
     check_sae_capab(dev[0])
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,ocvc,1")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-            bssid = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP")
-            bssid = bssid.split(',')[3]
-
-            with open("/tmp/sigma_dut-ap.conf", "rb") as f:
-                with open(conffile, "wb") as f2:
-                    f2.write(f.read())
-
-            dev[0].set("sae_groups", "")
-            dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
-                           ieee80211w="2", ocv="1", scan_freq="2412")
-            dev[0].request("REMOVE_NETWORK all")
-            dev[0].wait_disconnected()
-            dev[0].dump_monitor()
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
+        dut.cmd_check("ap_set_wireless,NAME,AP,ocvc,1")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678")
+        dut.cmd_check("ap_config_commit,NAME,AP")
+        bssid = dut.cmd_check("ap_get_mac_address,NAME,AP")
+        bssid = bssid.split(',')[3]
+
+        with open("/tmp/sigma_dut-ap.conf", "rb") as f, \
+             open(conffile, "wb") as f2:
+            f2.write(f.read())
 
-            sigma_dut_cmd_check("ap_set_rfeature,NAME,AP,type,WPA3,OCIFrameType,eapolM3,OCIChannel,3")
-            dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
-                           ieee80211w="2", ocv="1", scan_freq="2412",
-                           wait_connect=False)
-            check_ocv_failure(dev[0], "EAPOL-Key msg 3/4", "eapol-key-m3",
-                              bssid)
-            dev[0].request("REMOVE_NETWORK all")
-            dev[0].wait_disconnected()
-            dev[0].dump_monitor()
+        dev[0].set("sae_groups", "")
+        dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
+                       ieee80211w="2", ocv="1", scan_freq="2412")
+        dev[0].request("REMOVE_NETWORK all")
+        dev[0].wait_disconnected()
+        dev[0].dump_monitor()
 
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+        dut.cmd_check("ap_set_rfeature,NAME,AP,type,WPA3,OCIFrameType,eapolM3,OCIChannel,3")
+        dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
+                       ieee80211w="2", ocv="1", scan_freq="2412",
+                       wait_connect=False)
+        check_ocv_failure(dev[0], "EAPOL-Key msg 3/4", "eapol-key-m3", bssid)
+        dev[0].request("REMOVE_NETWORK all")
+        dev[0].wait_disconnected()
+        dev[0].dump_monitor()
 
 def test_sigma_dut_gtk_rekey(dev, apdev):
     """sigma_dut controlled STA requesting GTK rekeying"""
     check_sae_capab(dev[0])
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         ssid = "test-sae"
         params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
         params['wpa_key_mgmt'] = 'SAE'
@@ -6075,64 +5529,55 @@ def test_sigma_dut_gtk_rekey(dev, apdev):
         params['sae_groups'] = '19'
         hapd = hostapd.add_ap(apdev[0], params)
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_wireless,interface,%s,program,WPA3,ocvc,1" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, "test-sae", "12345678"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
+        dut.cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_wireless,interface,%s,program,WPA3,ocvc,1" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, "test-sae", "12345678"))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
                             timeout=10)
-        sigma_dut_wait_connected(ifname)
+        dut.wait_connected()
 
         dev[0].dump_monitor()
-        sigma_dut_cmd_check("dev_exec_action,interface,%s,program,WPA3,KeyRotation,1" % ifname)
+        dut.cmd_check("dev_exec_action,interface,%s,program,WPA3,KeyRotation,1" % ifname)
         ev = dev[0].wait_event(["RSN: Group rekeying completed"], timeout=5)
         if ev is None:
             raise Exception("GTK rekeying not seen")
 
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
 def test_sigma_dut_ap_gtk_rekey(dev, apdev, params):
     """sigma_dut controlled AP and requested GTK rekeying"""
     logdir = params['prefix'] + ".sigma-hostapd"
     check_sae_capab(dev[0])
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            sigma_dut_cmd_check("ap_reset_default")
-            sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
-            sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678")
-            sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-
-            dev[0].set("sae_groups", "")
-            dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
-                           ieee80211w="2", scan_freq="2412")
-            dev[0].dump_monitor()
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        dut.cmd_check("ap_reset_default")
+        dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
+        dut.cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678")
+        dut.cmd_check("ap_config_commit,NAME,AP")
 
-            sigma_dut_cmd_check("dev_exec_action,name,AP,interface,%s,program,WPA3,KeyRotation,1" % iface)
+        dev[0].set("sae_groups", "")
+        dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
+                       ieee80211w="2", scan_freq="2412")
+        dev[0].dump_monitor()
 
-            ev = dev[0].wait_event(["RSN: Group rekeying completed"], timeout=5)
-            if ev is None:
-                raise Exception("GTK rekeying not seen")
+        dut.cmd_check("dev_exec_action,name,AP,interface,%s,program,WPA3,KeyRotation,1" % iface)
 
-            sigma_dut_cmd_check("ap_reset_default")
-        finally:
-            stop_sigma_dut(sigma)
+        ev = dev[0].wait_event(["RSN: Group rekeying completed"], timeout=5)
+        if ev is None:
+            raise Exception("GTK rekeying not seen")
 
 def test_sigma_dut_sae_pk(dev, apdev):
     """sigma_dut controlled STA using SAE-PK"""
     check_sae_pk_capab(dev[0])
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
     ssid = "SAE-PK test"
     pw = "hbbi-f4xq-b45g"
     m = "d2e5fa27d1be8897f987f2d480d2af6b"
     pk = "MHcCAQEEIAJIGlfnteonDb7rQyP/SGQjwzrZAnfrXIm4280VWajYoAoGCCqGSM49AwEHoUQDQgAEeRkstKQV+FSAMqBayqFknn2nAQsdsh/MhdX6tiHOTAFin/sUMFRMyspPtIu7YvlKdsexhI0jPVhaYZn1jKWhZg=="
 
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
         params['wpa_key_mgmt'] = 'SAE'
         params["ieee80211w"] = "2"
@@ -6140,23 +5585,21 @@ def test_sigma_dut_sae_pk(dev, apdev):
         params['sae_password'] = ['%s|pk=%s:%s' % (pw, m, pk)]
         hapd = hostapd.add_ap(apdev[0], params)
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_wireless,interface,%s,program,WPA3" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2,sae_pk,1" % (ifname, ssid, pw))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, ssid),
-                            timeout=10)
-        sigma_dut_wait_connected(ifname)
+        dut.cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_wireless,interface,%s,program,WPA3" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2,sae_pk,1" % (ifname, ssid, pw))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, ssid),
+                      timeout=10)
+        dut.wait_connected()
         dev[0].dump_monitor()
 
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.cmd_check("sta_reset_default,interface," + ifname)
 
-def run_sigma_dut_ap_sae_pk(conffile, dev, ssid, pw, keypair, m, failure,
+def run_sigma_dut_ap_sae_pk(dut, conffile, dev, ssid, pw, keypair, m, failure,
                             status=None, omit=False, immediate=False, sig=None):
-    sigma_dut_cmd_check("ap_reset_default")
-    sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,%s,MODE,11ng" % ssid)
+    dut.cmd_check("ap_reset_default")
+    dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,%s,MODE,11ng" % ssid)
     cmd = "ap_set_security,NAME,AP,AKMSuiteType,8,PairwiseCipher,AES-CCMP-128,GroupCipher,AES-CCMP-128,GroupMgntCipher,BIP-CMAC-128,PMF,Required,PSK,%s,sae_pk,1,Transition_Disable,1,Transition_Disable_Index,0,SAE_PK_KeyPair,%s,SAE_PK_Modifier,%s" % (pw, keypair, m)
     if status is not None:
         cmd += ",SAE_Commit_StatusCode,%d" % status
@@ -6166,9 +5609,9 @@ def run_sigma_dut_ap_sae_pk(conffile, dev, ssid, pw, keypair, m, failure,
         cmd += ",SAE_Confirm_Immediate,1"
     if sig:
         cmd += ",SAE_PK_KeyPairSigOverride," + sig
-    sigma_dut_cmd_check(cmd)
-    sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-    bssid = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP")
+    dut.cmd_check(cmd)
+    dut.cmd_check("ap_config_commit,NAME,AP")
+    bssid = dut.cmd_check("ap_get_mac_address,NAME,AP")
     bssid = bssid.split(',')[3]
 
     with open("/tmp/sigma_dut-ap.conf", "rb") as f:
@@ -6202,8 +5645,6 @@ def run_sigma_dut_ap_sae_pk(conffile, dev, ssid, pw, keypair, m, failure,
         dev.wait_disconnected()
     dev.dump_monitor()
 
-    sigma_dut_cmd_check("ap_reset_default")
-
 def test_sigma_dut_ap_sae_pk(dev, apdev, params):
     """sigma_dut controlled AP using SAE-PK"""
     logdir = params['prefix'] + ".sigma-hostapd"
@@ -6254,14 +5695,11 @@ def test_sigma_dut_ap_sae_pk(dev, apdev, params):
              ("SAEPK-5.7.3", "4322-ufus-4bhm", "saepk1.pem",
               "21ede99abc46679646693cafe4677d4e", False)]
 
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            for ssid, pw, keypair, m, failure in tests:
-                run_sigma_dut_ap_sae_pk(conffile, dev[0], ssid, pw, keypair, m,
-                                        failure)
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        for ssid, pw, keypair, m, failure in tests:
+            run_sigma_dut_ap_sae_pk(dut, conffile, dev[0], ssid, pw, keypair, m,
+                                    failure)
 
 def test_sigma_dut_ap_sae_pk_misbehavior(dev, apdev, params):
     """sigma_dut controlled AP using SAE-PK misbehavior"""
@@ -6273,27 +5711,25 @@ def test_sigma_dut_ap_sae_pk_misbehavior(dev, apdev, params):
     keypair = "saepk1.pem"
     m = "faa1ef5094bdb4cb2836332ca2c09839"
 
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            run_sigma_dut_ap_sae_pk(conffile, dev[0], ssid, pw, keypair, m,
-                                    True, status=126)
-            run_sigma_dut_ap_sae_pk(conffile, dev[0], ssid, pw, keypair, m,
-                                    True, omit=True)
-            run_sigma_dut_ap_sae_pk(conffile, dev[0], ssid, pw, keypair, m,
-                                    True, status=126, omit=True, immediate=True)
-            run_sigma_dut_ap_sae_pk(conffile, dev[0], ssid, pw, keypair, m,
-                                    True, sig="saepk2.pem")
-        finally:
-            stop_sigma_dut(sigma)
-
-def run_sigma_dut_ap_sae_pk_mixed(conffile, dev, ssid, pw, keypair, m, failure):
-    sigma_dut_cmd_check("ap_reset_default")
-    sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,%s,MODE,11ng" % ssid)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        run_sigma_dut_ap_sae_pk(dut, conffile, dev[0], ssid, pw, keypair, m,
+                                True, status=126)
+        run_sigma_dut_ap_sae_pk(dut, conffile, dev[0], ssid, pw, keypair, m,
+                                True, omit=True)
+        run_sigma_dut_ap_sae_pk(dut, conffile, dev[0], ssid, pw, keypair, m,
+                                True, status=126, omit=True, immediate=True)
+        run_sigma_dut_ap_sae_pk(dut, conffile, dev[0], ssid, pw, keypair, m,
+                                True, sig="saepk2.pem")
+
+def run_sigma_dut_ap_sae_pk_mixed(dut, conffile, dev, ssid, pw, keypair, m,
+                                  failure):
+    dut.cmd_check("ap_reset_default")
+    dut.cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,%s,MODE,11ng" % ssid)
     cmd = "ap_set_security,NAME,AP,AKMSuiteType,2;8,PairwiseCipher,AES-CCMP-128,GroupCipher,AES-CCMP-128,GroupMgntCipher,BIP-CMAC-128,PMF,Required,PSK,%s,sae_pk,0,Transition_Disable,0" % (pw)
-    sigma_dut_cmd_check(cmd)
-    sigma_dut_cmd_check("ap_config_commit,NAME,AP")
-    bssid = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP")
+    dut.cmd_check(cmd)
+    dut.cmd_check("ap_config_commit,NAME,AP")
+    bssid = dut.cmd_check("ap_get_mac_address,NAME,AP")
     bssid = bssid.split(',')[3]
 
     with open("/tmp/sigma_dut-ap.conf", "rb") as f:
@@ -6301,7 +5737,7 @@ def run_sigma_dut_ap_sae_pk_mixed(conffile, dev, ssid, pw, keypair, m, failure):
             f2.write(f.read())
             f2.write('\n'.encode())
 
-    sigma_dut_cmd_check("ap_set_rfeature,NAME,AP,type,WPA3,Transition_Disable,1,Transition_Disable_Index,0")
+    dut.cmd_check("ap_set_rfeature,NAME,AP,type,WPA3,Transition_Disable,1,Transition_Disable_Index,0")
 
     dev[0].set("sae_groups", "")
     dev[0].connect(ssid, key_mgmt="SAE", sae_password=pw, ieee80211w="2",
@@ -6309,8 +5745,6 @@ def run_sigma_dut_ap_sae_pk_mixed(conffile, dev, ssid, pw, keypair, m, failure):
     dev[1].connect(ssid, key_mgmt="WPA-PSK", psk=pw, ieee80211w="2",
                    scan_freq="2412")
 
-    sigma_dut_cmd_check("ap_reset_default")
-
 def test_sigma_dut_ap_sae_pk_mixed(dev, apdev, params):
     """sigma_dut controlled AP using SAE-PK(disabled) and PSK"""
     logdir = params['prefix'] + ".sigma-hostapd"
@@ -6321,13 +5755,10 @@ def test_sigma_dut_ap_sae_pk_mixed(dev, apdev, params):
     keypair = "saepk1.pem"
     m = "21ede99abc46679646693cafe4677d4e"
 
-    with HWSimRadio() as (radio, iface):
-        sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
-        try:
-            run_sigma_dut_ap_sae_pk_mixed(conffile, dev, ssid, pw, keypair,
-                                          m, False)
-        finally:
-            stop_sigma_dut(sigma)
+    with HWSimRadio() as (radio, iface), \
+         SigmaDut(iface, hostapd_logdir=logdir) as dut:
+        run_sigma_dut_ap_sae_pk_mixed(dut, conffile, dev, ssid, pw, keypair,
+                                      m, False)
 
 def test_sigma_dut_client_privacy(dev, apdev, params):
     """sigma_dut client privacy"""
@@ -6339,23 +5770,22 @@ def test_sigma_dut_client_privacy(dev, apdev, params):
 
     ifname = dev[0].ifname
     addr = dev[0].own_addr()
-    sigma = start_sigma_dut(ifname)
     try:
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
-        sigma_dut_cmd_check("sta_set_wireless,interface,%s,program,WPA3,ClientPrivacy,1" % ifname)
-        cmd = "sta_scan,Interface,%s,ChnlFreq,2412,WaitCompletion,1" % dev[0].ifname
-        sigma_dut_cmd_check(cmd, timeout=10)
-        time.sleep(2)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_psk,interface,%s,ssid,%s,passphrase,%s,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, ssid, "12345678"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, ssid),
-                            timeout=10)
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
-        sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
+        with SigmaDut(dev=dev[0]) as dut:
+            dut.cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
+            dut.cmd_check("sta_set_wireless,interface,%s,program,WPA3,ClientPrivacy,1" % ifname)
+            cmd = "sta_scan,Interface,%s,ChnlFreq,2412,WaitCompletion,1" % dev[0].ifname
+            dut.cmd_check(cmd, timeout=10)
+            time.sleep(2)
+            dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+            dut.cmd_check("sta_set_psk,interface,%s,ssid,%s,passphrase,%s,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, ssid, "12345678"))
+            dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, ssid),
+                          timeout=10)
+            dut.wait_connected()
+            dut.cmd_check("sta_get_ip_config,interface," + ifname)
+            dut.cmd_check("sta_disconnect,interface," + ifname)
+            dut.cmd_check("sta_reset_default,interface," + ifname)
     finally:
-        stop_sigma_dut(sigma)
         dev[0].set("mac_addr", "0", allow_fail=True)
         dev[0].set("rand_addr_lifetime", "60", allow_fail=True)
         dev[0].request("MAC_RAND_SCAN enable=0 all")
@@ -6375,9 +5805,7 @@ def test_sigma_dut_wpa3_inject_frame(dev, apdev):
     check_sae_capab(dev[0])
 
     ifname = dev[0].ifname
-    sigma = start_sigma_dut(ifname)
-
-    try:
+    with SigmaDut(dev=dev[0]) as dut:
         ssid = "test-sae"
         params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
         params['wpa_key_mgmt'] = 'SAE'
@@ -6386,17 +5814,15 @@ def test_sigma_dut_wpa3_inject_frame(dev, apdev):
         params['sae_groups'] = '19 20 21'
         hapd = hostapd.add_ap(apdev[0], params)
 
-        sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
-        sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
-        sigma_dut_cmd_check("sta_set_wireless,interface,%s,program,WPA3,ocvc,1" % ifname)
-        sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, "test-sae", "12345678"))
-        sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
-                            timeout=10)
-        sigma_dut_wait_connected(ifname)
-        sigma_dut_cmd("dev_send_frame,interface,%s,program,WPA3,framename,SAQueryReq,OCIChannel,2" % ifname)
-        sigma_dut_cmd("dev_send_frame,interface,%s,program,WPA3,framename,SAQueryReq,OCIChannel,1" % ifname)
-        sigma_dut_cmd("dev_send_frame,interface,%s,program,WPA3,framename,ReassocReq" % ifname)
+        dut.cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
+        dut.cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
+        dut.cmd_check("sta_set_wireless,interface,%s,program,WPA3,ocvc,1" % ifname)
+        dut.cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, "test-sae", "12345678"))
+        dut.cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"),
+                      timeout=10)
+        dut.wait_connected()
+        dut.run_cmd("dev_send_frame,interface,%s,program,WPA3,framename,SAQueryReq,OCIChannel,2" % ifname)
+        dut.run_cmd("dev_send_frame,interface,%s,program,WPA3,framename,SAQueryReq,OCIChannel,1" % ifname)
+        dut.run_cmd("dev_send_frame,interface,%s,program,WPA3,framename,ReassocReq" % ifname)
         hwsim_utils.test_connectivity(dev[0], hapd)
-        sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
-    finally:
-        stop_sigma_dut(sigma)
+        dut.cmd_check("sta_reset_default,interface," + ifname)