diff mbox

[RFC,v1,3/3] tests: add remote_test.py script

Message ID 1453899551-19482-4-git-send-email-janusz.dziedzic@tieto.com
State RFC
Headers show

Commit Message

Janusz.Dziedzic@tieto.com Jan. 27, 2016, 12:59 p.m. UTC
This is demo how we can use wpaspy/WpaSupplicant/Hostapd
with remote clients (UDP CTRL path).
I just copy/paste three hwsim test cases here and tested
this with my two ATH9K cards.

Signed-off-by: Janusz Dziedzic <janusz.dziedzic@tieto.com>
---
 tests/hwsim/remote_test.py | 98 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 98 insertions(+)
 create mode 100755 tests/hwsim/remote_test.py
diff mbox

Patch

diff --git a/tests/hwsim/remote_test.py b/tests/hwsim/remote_test.py
new file mode 100755
index 0000000..b657364
--- /dev/null
+++ b/tests/hwsim/remote_test.py
@@ -0,0 +1,98 @@ 
+#!/usr/bin/python
+#
+# This software may be distributed under the terms of the BSD license.
+# See README for more details.
+
+import os
+import sys
+import time
+
+scriptsdir = os.path.dirname(os.path.realpath(sys.modules[__name__].__file__))
+sys.path.append(os.path.join(scriptsdir, '..', '..', 'wpaspy'))
+
+from wpasupplicant import WpaSupplicant
+from hostapd import HostapdGlobal
+import hostapd
+from wpaspy import Host
+
+def _test_ap_open(dev, apdev):
+    hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" }, hostname=apdev[0]['hostname'])
+    dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
+                   bg_scan_period="0")
+    ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
+    if ev is None:
+        raise Exception("No connection event received from hostapd")
+
+    dev[0].request("DISCONNECT")
+    ev = hapd.wait_event([ "AP-STA-DISCONNECTED" ], timeout=5)
+    if ev is None:
+        raise Exception("No disconnection event received from hostapd")
+
+def test_ap_open_reconnect_on_inactivity_disconnect(dev, apdev):
+    """Reconnect to open mode AP after inactivity related disconnection"""
+    hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" }, hostname=apdev[0]['hostname'])
+    dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
+    hapd.request("DEAUTHENTICATE " + dev[0].p2p_interface_addr() + " reason=4")
+    dev[0].wait_disconnected(timeout=5)
+    dev[0].wait_connected(timeout=2, error="Timeout on reconnection")
+
+def test_ap_wps_conf(dev, apdev):
+    """WPS PBC provisioning with configured AP"""
+    ssid = "test-wps-conf"
+    hostapd.add_ap(apdev[0]['ifname'],
+                   { "ssid": ssid, "eap_server": "1", "wps_state": "2",
+                     "wpa_passphrase": "12345678", "wpa": "2",
+                     "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"},
+                   hostname=apdev[0]['hostname'])
+    hapd = hostapd.Hostapd(apdev[0]['ifname'], hostname=apdev[0]['hostname'])
+    hapd.request("WPS_PBC")
+    dev[0].request("SET device_name Device A")
+    dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
+    dev[0].dump_monitor()
+    dev[0].request("WPS_PBC " + apdev[0]['bssid'])
+    dev[0].wait_connected(timeout=30)
+    status = dev[0].get_status()
+    if status['wpa_state'] != 'COMPLETED':
+        raise Exception("Not fully connected")
+    if status['bssid'] != apdev[0]['bssid']:
+        raise Exception("Unexpected BSSID")
+    if status['ssid'] != ssid:
+        raise Exception("Unexpected SSID")
+    if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
+        raise Exception("Unexpected encryption configuration")
+    if status['key_mgmt'] != 'WPA2-PSK':
+        raise Exception("Unexpected key_mgmt")
+
+    sta = hapd.get_sta(dev[0].p2p_interface_addr())
+    if 'wpsDeviceName' not in sta or sta['wpsDeviceName'] != "Device A":
+        raise Exception("Device name not available in STA command")
+
+
+def main():
+
+    c = Host(host = "192.168.254.58", iface = "wlan0", port=9877)
+    s = Host(host = "192.168.254.50", iface = "wlan0", port=8878)
+
+    c.execute("killall wpa_supplicant")
+    s.execute("killall hostapd")
+    status, buf = c.execute("./tests/wpa_supplicant -B -i wlan0 -c ./tests/wpa_supplicant.conf")
+    if status != 0:
+        raise
+
+    status, buf = s.execute("./tests/hostapd -B -g /tmp/global9877")
+    if status != 0:
+        raise
+
+    time.sleep(3)
+
+    client=WpaSupplicant(hostname=c.host, ifname=c.iface, port=c.port)
+    dev = [client]
+    apdev = [ ]
+    apdev.append({"ifname": s.iface, "bssid": "00:6b:9e:01:ff:eb", "hostname": s.host, "port": s.port})
+
+    _test_ap_open(dev, apdev)
+    test_ap_open_reconnect_on_inactivity_disconnect(dev, apdev)
+    test_ap_wps_conf(dev, apdev)
+
+if __name__ == "__main__":
+        main()