Browse Source

tests: Add test cases for WPS operations

Signed-hostap: Jouni Malinen <j@w1.fi>
Jouni Malinen 12 years ago
parent
commit
302b7a1b09
3 changed files with 218 additions and 9 deletions
  1. 2 1
      tests/hwsim/hostapd.py
  2. 196 0
      tests/hwsim/test_ap_wps.py
  3. 20 8
      tests/hwsim/wpasupplicant.py

+ 2 - 1
tests/hwsim/hostapd.py

@@ -103,7 +103,8 @@ def add_ap(ifname, params):
             raise Exception("Could not ping hostapd")
         hapd.set_defaults()
         fields = [ "ssid", "wpa_passphrase", "wpa", "wpa_key_mgmt",
-                   "wpa_pairwise", "rsn_pairwise", "ieee80211w", "wep_key0" ]
+                   "wpa_pairwise", "rsn_pairwise", "ieee80211w", "wep_key0",
+                   "eap_server", "wps_state", "ap_pin", "wps_independent" ]
         for field in fields:
             if field in params:
                 hapd.set(field, params[field])

+ 196 - 0
tests/hwsim/test_ap_wps.py

@@ -0,0 +1,196 @@
+#!/usr/bin/python
+#
+# WPS tests
+# Copyright (c) 2013, Jouni Malinen <j@w1.fi>
+#
+# This software may be distributed under the terms of the BSD license.
+# See README for more details.
+
+import time
+import subprocess
+import logging
+logger = logging.getLogger(__name__)
+
+import hwsim_utils
+import hostapd
+
+ap_ifname = 'wlan2'
+bssid = "02:00:00:00:02:00"
+ap2_ifname = 'wlan3'
+bssid2 = "02:00:00:00:03:00"
+
+def test_ap_wps_init(dev):
+    """Initial AP configuration with first WPS Enrollee"""
+    ssid = "test-wps"
+    hostapd.add_ap(ap_ifname,
+                   { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
+    hapd = hostapd.Hostapd(ap_ifname)
+    logger.info("WPS provisioning step")
+    hapd.request("WPS_PBC")
+    dev[0].dump_monitor()
+    dev[0].request("WPS_PBC")
+    ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
+    if ev is None:
+        raise Exception("Association with the AP timed out")
+    status = dev[0].get_status()
+    if status['wpa_state'] != 'COMPLETED' or status['bssid'] != bssid:
+        raise Exception("Not fully connected")
+    if status['ssid'] != ssid:
+        raise Exception("Unexpected SSID")
+    if status['pairwise_cipher'] != 'CCMP':
+        raise Exception("Unexpected encryption configuration")
+    if status['key_mgmt'] != 'WPA2-PSK':
+        raise Exception("Unexpected key_mgmt")
+
+def test_ap_wps_conf(dev):
+    """WPS PBC provisioning with configured AP"""
+    ssid = "test-wps-conf"
+    hostapd.add_ap(ap_ifname,
+                   { "ssid": ssid, "eap_server": "1", "wps_state": "2",
+                     "wpa_passphrase": "12345678", "wpa": "2",
+                     "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
+    hapd = hostapd.Hostapd(ap_ifname)
+    logger.info("WPS provisioning step")
+    hapd.request("WPS_PBC")
+    dev[0].dump_monitor()
+    dev[0].request("WPS_PBC")
+    ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
+    if ev is None:
+        raise Exception("Association with the AP timed out")
+    status = dev[0].get_status()
+    if status['wpa_state'] != 'COMPLETED' or status['bssid'] != bssid:
+        raise Exception("Not fully connected")
+    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")
+
+def test_ap_wps_conf_pin(dev):
+    """WPS PIN provisioning with configured AP"""
+    ssid = "test-wps-conf-pin"
+    hostapd.add_ap(ap_ifname,
+                   { "ssid": ssid, "eap_server": "1", "wps_state": "2",
+                     "wpa_passphrase": "12345678", "wpa": "2",
+                     "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
+    hapd = hostapd.Hostapd(ap_ifname)
+    logger.info("WPS provisioning step")
+    pin = dev[0].wps_read_pin()
+    hapd.request("WPS_PIN any " + pin)
+    dev[0].dump_monitor()
+    dev[0].request("WPS_PIN any " + pin)
+    ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
+    if ev is None:
+        raise Exception("Association with the AP timed out")
+    status = dev[0].get_status()
+    if status['wpa_state'] != 'COMPLETED' or status['bssid'] != bssid:
+        raise Exception("Not fully connected")
+    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")
+
+def test_ap_wps_reg_connect(dev):
+    """WPS registrar using AP PIN to connect"""
+    ssid = "test-wps-conf-ap-pin"
+    appin = "12345670"
+    hostapd.add_ap(ap_ifname,
+                   { "ssid": ssid, "eap_server": "1", "wps_state": "2",
+                     "wpa_passphrase": "12345678", "wpa": "2",
+                     "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
+                     "ap_pin": appin})
+    logger.info("WPS provisioning step")
+    dev[0].request("BSS_FLUSH")
+    dev[0].dump_monitor()
+    dev[0].request("WPS_REG " + bssid + " " + appin)
+    ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
+    if ev is None:
+        raise Exception("Association with the AP timed out")
+    status = dev[0].get_status()
+    if status['wpa_state'] != 'COMPLETED' or status['bssid'] != bssid:
+        raise Exception("Not fully connected")
+    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")
+
+def test_ap_wps_reg_config(dev):
+    """WPS registrar configuring and AP using AP PIN"""
+    ssid = "test-wps-init-ap-pin"
+    appin = "12345670"
+    hostapd.add_ap(ap_ifname,
+                   { "ssid": ssid, "eap_server": "1", "wps_state": "2",
+                     "ap_pin": appin})
+    logger.info("WPS configuration step")
+    dev[0].request("BSS_FLUSH")
+    dev[0].dump_monitor()
+    new_ssid = "wps-new-ssid"
+    new_passphrase = "1234567890"
+    dev[0].request("WPS_REG " + bssid + " " + appin + " " + new_ssid.encode("hex") + " WPA2PSK CCMP " + new_passphrase.encode("hex"))
+    ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
+    if ev is None:
+        raise Exception("Association with the AP timed out")
+    status = dev[0].get_status()
+    if status['wpa_state'] != 'COMPLETED' or status['bssid'] != bssid:
+        raise Exception("Not fully connected")
+    if status['ssid'] != new_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")
+
+def test_ap_wps_pbc_overlap_2ap(dev):
+    """WPS PBC session overlap with two active APs"""
+    hostapd.add_ap(ap_ifname,
+                   { "ssid": "wps1", "eap_server": "1", "wps_state": "2",
+                     "wpa_passphrase": "12345678", "wpa": "2",
+                     "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
+                     "wps_independent": "1"})
+    hostapd.add_ap(ap2_ifname,
+                   { "ssid": "wps2", "eap_server": "1", "wps_state": "2",
+                     "wpa_passphrase": "123456789", "wpa": "2",
+                     "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
+                     "wps_independent": "1"})
+    hapd = hostapd.Hostapd(ap_ifname)
+    hapd.request("WPS_PBC")
+    hapd2 = hostapd.Hostapd(ap2_ifname)
+    hapd2.request("WPS_PBC")
+    logger.info("WPS provisioning step")
+    dev[0].dump_monitor()
+    dev[0].request("WPS_PBC")
+    ev = dev[0].wait_event(["WPS-OVERLAP-DETECTED"], timeout=15)
+    if ev is None:
+        raise Exception("PBC session overlap not detected")
+
+def test_ap_wps_pbc_overlap_2sta(dev):
+    """WPS PBC session overlap with two active STAs"""
+    ssid = "test-wps-pbc-overlap"
+    hostapd.add_ap(ap_ifname,
+                   { "ssid": ssid, "eap_server": "1", "wps_state": "2",
+                     "wpa_passphrase": "12345678", "wpa": "2",
+                     "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
+    hapd = hostapd.Hostapd(ap_ifname)
+    logger.info("WPS provisioning step")
+    hapd.request("WPS_PBC")
+    dev[0].request("BSS_FLUSH")
+    dev[1].request("BSS_FLUSH")
+    dev[0].dump_monitor()
+    dev[1].dump_monitor()
+    dev[0].request("WPS_PBC")
+    dev[1].request("WPS_PBC")
+    ev = dev[0].wait_event(["WPS-M2D"], timeout=15)
+    if ev is None:
+        raise Exception("PBC session overlap not detected (dev0)")
+    if "config_error=12" not in ev:
+        raise Exception("PBC session overlap not correctly reported (dev0)")
+    ev = dev[1].wait_event(["WPS-M2D"], timeout=15)
+    if ev is None:
+        raise Exception("PBC session overlap not detected (dev1)")
+    if "config_error=12" not in ev:
+        raise Exception("PBC session overlap not correctly reported (dev1)")

+ 20 - 8
tests/hwsim/wpasupplicant.py

@@ -85,29 +85,41 @@ class WpaSupplicant:
             raise Exception("Association with the AP timed out")
         self.dump_monitor()
 
-    def get_status(self, field):
+    def get_status(self):
         res = self.request("STATUS")
         lines = res.splitlines()
+        vals = dict()
         for l in lines:
             [name,value] = l.split('=', 1)
-            if name == field:
-                return value
+            vals[name] = value
+        return vals
+
+    def get_status_field(self, field):
+        vals = self.get_status()
+        if field in vals:
+            return vals[field]
         return None
 
-    def get_group_status(self, field):
+    def get_group_status(self):
         res = self.group_request("STATUS")
         lines = res.splitlines()
+        vals = dict()
         for l in lines:
             [name,value] = l.split('=', 1)
-            if name == field:
-                return value
+            vals[name] = value
+        return vals
+
+    def get_group_status_field(self, field):
+        vals = self.get_group_status()
+        if field in vals:
+            return vals[field]
         return None
 
     def p2p_dev_addr(self):
-        return self.get_status("p2p_device_address")
+        return self.get_status_field("p2p_device_address")
 
     def p2p_interface_addr(self):
-        return self.get_group_status("address")
+        return self.get_group_status_field("address")
 
     def p2p_listen(self):
         return self.request("P2P_LISTEN")