Updated to hostap_2_6
[mech_eap.git] / libeap / tests / hwsim / test_dfs.py
index 592736e..75a3c25 100644 (file)
@@ -4,6 +4,7 @@
 # This software may be distributed under the terms of the BSD license.
 # See README for more details.
 
+from remotehost import remote_compatible
 import os
 import subprocess
 import time
@@ -26,16 +27,11 @@ def wait_dfs_event(hapd, event, timeout):
     return ev
 
 def start_dfs_ap(ap, allow_failure=False, ssid="dfs", ht=True, ht40=False,
-                 ht40minus=False, vht80=False, vht20=False, chanlist=None):
+                 ht40minus=False, vht80=False, vht20=False, chanlist=None,
+                 channel=None):
     ifname = ap['ifname']
     logger.info("Starting AP " + ifname + " on DFS channel")
-    hapd_global = hostapd.HostapdGlobal()
-    hapd_global.remove(ifname)
-    hapd_global.add(ifname)
-    hapd = hostapd.Hostapd(ifname)
-    if not hapd.ping():
-        raise Exception("Could not ping hostapd")
-    hapd.set_defaults()
+    hapd = hostapd.add_ap(ap, {}, no_enable=True)
     hapd.set("ssid", ssid)
     hapd.set("country_code", "FI")
     hapd.set("ieee80211d", "1")
@@ -59,6 +55,8 @@ def start_dfs_ap(ap, allow_failure=False, ssid="dfs", ht=True, ht40=False,
         hapd.set("vht_oper_centr_freq_seg0_idx", "0")
     if chanlist:
         hapd.set("chanlist", chanlist)
+    if channel:
+        hapd.set("channel", str(channel))
     hapd.enable()
 
     ev = wait_dfs_event(hapd, "DFS-CAC-START", 5)
@@ -115,18 +113,18 @@ def test_dfs(dev, apdev):
         if ev is None:
             raise Exception("DFS-RADAR-DETECTED event not reported")
         if "freq=5260" not in ev:
-            raise Exception("Incorrect frequency in radar detected event: " + ev);
+            raise Exception("Incorrect frequency in radar detected event: " + ev)
         ev = hapd.wait_event(["DFS-NEW-CHANNEL"], timeout=70)
         if ev is None:
             raise Exception("DFS-NEW-CHANNEL event not reported")
         if "freq=5260" in ev:
-            raise Exception("Channel did not change after radar was detected");
+            raise Exception("Channel did not change after radar was detected")
 
         ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=70)
         if ev is None:
             raise Exception("AP-CSA-FINISHED event not reported")
         if "freq=5260" in ev:
-            raise Exception("Channel did not change after radar was detected(2)");
+            raise Exception("Channel did not change after radar was detected(2)")
         time.sleep(1)
         hwsim_utils.test_connectivity(dev[0], hapd)
     finally:
@@ -216,10 +214,11 @@ def test_dfs_radar(dev, apdev):
         subprocess.call(['iw', 'reg', 'set', '00'])
         dev[0].flush_scan_cache()
 
+@remote_compatible
 def test_dfs_radar_on_non_dfs_channel(dev, apdev):
     """DFS radar detection test code on non-DFS channel"""
     params = { "ssid": "radar" }
-    hapd = hostapd.add_ap(apdev[0]['ifname'], params)
+    hapd = hostapd.add_ap(apdev[0], params)
 
     hapd.request("RADAR DETECTED freq=5260 ht_enabled=1 chan_width=1")
     hapd.request("RADAR DETECTED freq=2412 ht_enabled=1 chan_width=1")
@@ -400,3 +399,39 @@ def test_dfs_radar_ht40minus(dev, apdev):
             hapd.request("DISABLE")
         subprocess.call(['iw', 'reg', 'set', '00'])
         dev[0].flush_scan_cache()
+
+def test_dfs_ht40_minus(dev, apdev, params):
+    """DFS CAC functionality on channel 104 HT40- [long]"""
+    if not params['long']:
+        raise HwsimSkip("Skip test case with long duration due to --long not specified")
+    try:
+        hapd = None
+        hapd = start_dfs_ap(apdev[0], allow_failure=True, ht40minus=True,
+                            channel=104)
+
+        ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70)
+        if "success=1" not in ev:
+            raise Exception("CAC failed")
+        if "freq=5520" not in ev:
+            raise Exception("Unexpected DFS freq result")
+
+        ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
+        if not ev:
+            raise Exception("AP setup timed out")
+
+        state = hapd.get_status_field("state")
+        if state != "ENABLED":
+            raise Exception("Unexpected interface state")
+
+        freq = hapd.get_status_field("freq")
+        if freq != "5520":
+            raise Exception("Unexpected frequency")
+
+        dev[0].connect("dfs", key_mgmt="NONE", scan_freq="5520")
+        hwsim_utils.test_connectivity(dev[0], hapd)
+    finally:
+        dev[0].request("DISCONNECT")
+        if hapd:
+            hapd.request("DISABLE")
+        subprocess.call(['iw', 'reg', 'set', '00'])
+        dev[0].flush_scan_cache()