Updated to hostap_2_6
[mech_eap.git] / libeap / tests / hwsim / test_nfc_wps.py
index 22d599b..0b6cd11 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 time
 import subprocess
 import logging
@@ -34,12 +35,12 @@ def ap_wps_params(ssid):
              "wpa_passphrase": "12345678", "wpa": "2",
              "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}
 
+@remote_compatible
 def test_nfc_wps_password_token_sta(dev, apdev):
     """NFC tag with password token on the station/Enrollee"""
     ssid = "test-wps-nfc-pw-token-conf"
     params = ap_wps_params(ssid)
-    hostapd.add_ap(apdev[0]['ifname'], params)
-    hapd = hostapd.Hostapd(apdev[0]['ifname'])
+    hapd = hostapd.add_ap(apdev[0], params)
     logger.info("WPS provisioning step using password token from station")
     wps = dev[0].request("WPS_NFC_TOKEN WPS").rstrip()
     if "FAIL" in wps:
@@ -61,8 +62,7 @@ def test_nfc_wps_config_token(dev, apdev):
     """NFC tag with configuration token from AP"""
     ssid = "test-wps-nfc-conf-token"
     params = ap_wps_params(ssid)
-    hostapd.add_ap(apdev[0]['ifname'], params)
-    hapd = hostapd.Hostapd(apdev[0]['ifname'])
+    hapd = hostapd.add_ap(apdev[0], params)
     logger.info("NFC configuration token from AP to station")
     conf = hapd.request("WPS_NFC_CONFIG_TOKEN NDEF").rstrip()
     if "FAIL" in conf:
@@ -82,9 +82,8 @@ def test_nfc_wps_config_token(dev, apdev):
 def test_nfc_wps_config_token_init(dev, apdev):
     """NFC tag with configuration token from AP with auto configuration"""
     ssid = "test-wps-nfc-conf-token-init"
-    hostapd.add_ap(apdev[0]['ifname'],
-                   { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
-    hapd = hostapd.Hostapd(apdev[0]['ifname'])
+    hapd = hostapd.add_ap(apdev[0],
+                          { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
     logger.info("NFC configuration token from AP to station")
     conf = hapd.request("WPS_NFC_CONFIG_TOKEN NDEF").rstrip()
     if "FAIL" in conf:
@@ -96,12 +95,12 @@ def test_nfc_wps_config_token_init(dev, apdev):
     dev[0].wait_connected(timeout=15)
     check_wpa2_connection(dev[0], apdev[0], hapd, ssid, mixed=True)
 
+@remote_compatible
 def test_nfc_wps_password_token_sta_init(dev, apdev):
     """Initial AP configuration with first WPS NFC Enrollee"""
     ssid = "test-wps-nfc-pw-token-init"
-    hostapd.add_ap(apdev[0]['ifname'],
-                   { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
-    hapd = hostapd.Hostapd(apdev[0]['ifname'])
+    hapd = hostapd.add_ap(apdev[0],
+                          { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
     logger.info("WPS provisioning step using password token from station")
     pw = dev[0].request("WPS_NFC_TOKEN NDEF").rstrip()
     if "FAIL" in pw:
@@ -116,12 +115,12 @@ def test_nfc_wps_password_token_sta_init(dev, apdev):
     dev[0].wait_connected(timeout=30)
     check_wpa2_connection(dev[0], apdev[0], hapd, ssid, mixed=True)
 
+@remote_compatible
 def test_nfc_wps_password_token_ap(dev, apdev):
     """WPS registrar configuring an AP using AP password token"""
     ssid = "test-wps-nfc-pw-token-init"
-    hostapd.add_ap(apdev[0]['ifname'],
-                   { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
-    hapd = hostapd.Hostapd(apdev[0]['ifname'])
+    hapd = hostapd.add_ap(apdev[0],
+                          { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
     logger.info("WPS configuration step")
     pw = hapd.request("WPS_NFC_TOKEN NDEF").rstrip()
     if "FAIL" in pw:
@@ -154,11 +153,16 @@ def test_nfc_wps_password_token_ap(dev, apdev):
 
 def test_nfc_wps_handover_init(dev, apdev):
     """Connect to WPS AP with NFC connection handover and move to configured state"""
+    try:
+        _test_nfc_wps_handover_init(dev, apdev)
+    finally:
+        dev[0].request("SET ignore_old_scan_res 0")
+
+def _test_nfc_wps_handover_init(dev, apdev):
     dev[0].request("SET ignore_old_scan_res 1")
     ssid = "test-wps-nfc-handover-init"
-    hostapd.add_ap(apdev[0]['ifname'],
-                   { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
-    hapd = hostapd.Hostapd(apdev[0]['ifname'])
+    hapd = hostapd.add_ap(apdev[0],
+                          { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
     logger.info("NFC connection handover")
     req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
     if "FAIL" in req:
@@ -180,12 +184,12 @@ def test_nfc_wps_handover_init(dev, apdev):
         if "FAIL" not in hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR"):
             raise Exception("Unexpected NFC_GET_HANDOVER_SEL success during OOM")
 
+@remote_compatible
 def test_nfc_wps_handover_errors(dev, apdev):
     """WPS AP NFC handover report error cases"""
     ssid = "test-wps-nfc-handover"
-    hostapd.add_ap(apdev[0]['ifname'],
-                   { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
-    hapd = hostapd.Hostapd(apdev[0]['ifname'])
+    hapd = hostapd.add_ap(apdev[0],
+                          { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
     sel = hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
     if "FAIL" in sel:
         raise Exception("Failed to generate NFC connection handover select")
@@ -214,8 +218,7 @@ def test_nfc_wps_handover(dev, apdev):
     """Connect to WPS AP with NFC connection handover"""
     ssid = "test-wps-nfc-handover"
     params = ap_wps_params(ssid)
-    hostapd.add_ap(apdev[0]['ifname'], params)
-    hapd = hostapd.Hostapd(apdev[0]['ifname'])
+    hapd = hostapd.add_ap(apdev[0], params)
     logger.info("NFC connection handover")
     req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
     if "FAIL" in req:
@@ -235,13 +238,14 @@ def test_nfc_wps_handover(dev, apdev):
 
 def test_nfc_wps_handover_5ghz(dev, apdev):
     """Connect to WPS AP with NFC connection handover on 5 GHz band"""
+    hapd = None
     try:
         ssid = "test-wps-nfc-handover"
         params = ap_wps_params(ssid)
         params["country_code"] = "FI"
         params["hw_mode"] = "a"
         params["channel"] = "36"
-        hapd = hostapd.add_ap(apdev[0]['ifname'], params)
+        hapd = hostapd.add_ap(apdev[0], params)
         logger.info("NFC connection handover")
         req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
         if "FAIL" in req:
@@ -267,13 +271,14 @@ def test_nfc_wps_handover_5ghz(dev, apdev):
 
 def test_nfc_wps_handover_chan14(dev, apdev):
     """Connect to WPS AP with NFC connection handover on channel 14"""
+    hapd = None
     try:
         ssid = "test-wps-nfc-handover"
         params = ap_wps_params(ssid)
         params["country_code"] = "JP"
         params["hw_mode"] = "b"
         params["channel"] = "14"
-        hapd = hostapd.add_ap(apdev[0]['ifname'], params)
+        hapd = hostapd.add_ap(apdev[0], params)
         logger.info("NFC connection handover")
         req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
         if "FAIL" in req:
@@ -301,8 +306,7 @@ def test_nfc_wps_handover_with_pw_token_set(dev, apdev):
     """Connect to WPS AP with NFC connection handover (wps_nfc_* set)"""
     ssid = "test-wps-nfc-handover2"
     params = ap_wps_params(ssid)
-    hostapd.add_ap(apdev[0]['ifname'], params)
-    hapd = hostapd.Hostapd(apdev[0]['ifname'])
+    hapd = hostapd.add_ap(apdev[0], params)
     # enable a password token (which won't be used in this test case)
     pw = hapd.request("WPS_NFC_TOKEN NDEF").rstrip()
     if "FAIL" in pw:
@@ -333,8 +337,7 @@ def test_nfc_wps_handover_pk_hash_mismatch_sta(dev, apdev):
     if "FAIL" in dev[0].request("SET wps_corrupt_pkhash 1"):
         raise Exception("Could not enable wps_corrupt_pkhash")
     params = ap_wps_params(ssid)
-    hostapd.add_ap(apdev[0]['ifname'], params)
-    hapd = hostapd.Hostapd(apdev[0]['ifname'])
+    hapd = hostapd.add_ap(apdev[0], params)
     logger.info("NFC connection handover")
     req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
     if "FAIL" in req:
@@ -359,8 +362,7 @@ def test_nfc_wps_handover_pk_hash_mismatch_ap(dev, apdev):
     """WPS NFC connection handover with invalid pkhash from AP (negative)"""
     ssid = "wps-nfc-handover-pkhash-ap"
     params = ap_wps_params(ssid)
-    hostapd.add_ap(apdev[0]['ifname'], params)
-    hapd = hostapd.Hostapd(apdev[0]['ifname'])
+    hapd = hostapd.add_ap(apdev[0], params)
     if "FAIL" in hapd.request("SET wps_corrupt_pkhash 1"):
         raise Exception("Could not enable wps_corrupt_pkhash")
     logger.info("NFC connection handover")
@@ -386,20 +388,23 @@ def test_nfc_wps_handover_pk_hash_mismatch_ap(dev, apdev):
 def start_ap_er(er, ap, ssid):
     ap_pin = "12345670"
     ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
-    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",
-                     "device_name": "Wireless AP", "manufacturer": "Company",
-                     "model_name": "WAP", "model_number": "123",
-                     "serial_number": "12345", "device_type": "6-0050F204-1",
-                     "os_version": "01020300",
-                     "config_methods": "label push_button",
-                     "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
+    params = { "ssid": ssid, "eap_server": "1", "wps_state": "2",
+               "wpa_passphrase": "12345678", "wpa": "2",
+               "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
+               "device_name": "Wireless AP", "manufacturer": "Company",
+               "model_name": "WAP", "model_number": "123",
+               "serial_number": "12345", "device_type": "6-0050F204-1",
+               "os_version": "01020300",
+               "config_methods": "label push_button",
+               "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}
+    hapd = hostapd.add_ap(ap, params)
     logger.info("Learn AP configuration")
     er.dump_monitor()
-    er.request("SET ignore_old_scan_res 1")
-    er.wps_reg(ap['bssid'], ap_pin)
+    try:
+        er.request("SET ignore_old_scan_res 1")
+        er.wps_reg(ap['bssid'], ap_pin)
+    finally:
+        er.request("SET ignore_old_scan_res 0")
 
     logger.info("Start ER")
     er.request("WPS_ER_STOP")
@@ -413,18 +418,20 @@ def start_ap_er(er, ap, ssid):
 
     logger.info("Use learned network configuration on ER")
     er.request("WPS_ER_SET_CONFIG " + ap_uuid + " 0")
+    return hapd
 
+@remote_compatible
 def test_nfc_wps_er_pw_token(dev, apdev):
     """WPS NFC password token from Enrollee to ER"""
     try:
         _test_nfc_wps_er_pw_token(dev, apdev)
     finally:
         dev[0].request("WPS_ER_STOP")
+        dev[1].request("SET ignore_old_scan_res 0")
 
 def _test_nfc_wps_er_pw_token(dev, apdev):
     ssid = "wps-nfc-er-pw-token"
-    start_ap_er(dev[0], apdev[0], ssid)
-    hapd = hostapd.Hostapd(apdev[0]['ifname'])
+    hapd = start_ap_er(dev[0], apdev[0], ssid)
     logger.info("WPS provisioning step using password token from station")
     dev[1].request("SET ignore_old_scan_res 1")
     pw = dev[1].request("WPS_NFC_TOKEN NDEF").rstrip()
@@ -443,17 +450,18 @@ def _test_nfc_wps_er_pw_token(dev, apdev):
     dev[1].wait_connected(timeout=15)
     check_wpa2_connection(dev[1], apdev[0], hapd, ssid)
 
+@remote_compatible
 def test_nfc_wps_er_config_token(dev, apdev):
     """WPS NFC configuration token from ER to Enrollee"""
     try:
         _test_nfc_wps_er_config_token(dev, apdev)
     finally:
         dev[0].request("WPS_ER_STOP")
+        dev[1].request("SET ignore_old_scan_res 0")
 
 def _test_nfc_wps_er_config_token(dev, apdev):
     ssid = "wps-nfc-er-config-token"
-    start_ap_er(dev[0], apdev[0], ssid)
-    hapd = hostapd.Hostapd(apdev[0]['ifname'])
+    hapd = start_ap_er(dev[0], apdev[0], ssid)
     logger.info("WPS provisioning step using configuration token from ER")
     wps = dev[0].request("WPS_ER_NFC_CONFIG_TOKEN WPS " + apdev[0]['bssid']).rstrip()
     if "FAIL" in wps:
@@ -477,8 +485,7 @@ def test_nfc_wps_er_handover(dev, apdev):
 
 def _test_nfc_wps_er_handover(dev, apdev):
     ssid = "wps-nfc-er-handover"
-    start_ap_er(dev[0], apdev[0], ssid)
-    hapd = hostapd.Hostapd(apdev[0]['ifname'])
+    hapd = start_ap_er(dev[0], apdev[0], ssid)
     logger.info("WPS provisioning step using connection handover")
     req = dev[1].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
     if "FAIL" in req:
@@ -502,11 +509,11 @@ def test_nfc_wps_er_handover_pk_hash_mismatch_sta(dev, apdev):
         _test_nfc_wps_er_handover_pk_hash_mismatch_sta(dev, apdev)
     finally:
         dev[0].request("WPS_ER_STOP")
+        dev[1].request("SET ignore_old_scan_res 0")
 
 def _test_nfc_wps_er_handover_pk_hash_mismatch_sta(dev, apdev):
     ssid = "wps-nfc-er-handover-pkhash-sta"
-    start_ap_er(dev[0], apdev[0], ssid)
-    hapd = hostapd.Hostapd(apdev[0]['ifname'])
+    hapd = start_ap_er(dev[0], apdev[0], ssid)
     logger.info("WPS provisioning step using connection handover")
     if "FAIL" in dev[1].request("SET wps_corrupt_pkhash 1"):
         raise Exception("Could not enable wps_corrupt_pkhash")
@@ -536,11 +543,11 @@ def test_nfc_wps_er_handover_pk_hash_mismatch_er(dev, apdev):
         _test_nfc_wps_er_handover_pk_hash_mismatch_er(dev, apdev)
     finally:
         dev[0].request("WPS_ER_STOP")
+        dev[1].request("SET ignore_old_scan_res 0")
 
 def _test_nfc_wps_er_handover_pk_hash_mismatch_er(dev, apdev):
     ssid = "wps-nfc-er-handover-pkhash-er"
-    start_ap_er(dev[0], apdev[0], ssid)
-    hapd = hostapd.Hostapd(apdev[0]['ifname'])
+    hapd = start_ap_er(dev[0], apdev[0], ssid)
     logger.info("WPS provisioning step using connection handover")
     if "FAIL" in dev[0].request("SET wps_corrupt_pkhash 1"):
         raise Exception("Could not enable wps_corrupt_pkhash")
@@ -564,6 +571,7 @@ def _test_nfc_wps_er_handover_pk_hash_mismatch_er(dev, apdev):
     if "WPS-FAIL" not in ev:
         raise Exception("Public key hash mismatch not detected")
 
+@remote_compatible
 def test_nfc_invalid_ndef_record(dev, apdev):
     """Invalid NFC NDEF record handling"""
     tests = [ "11223344",