]> git.ipfire.org Git - thirdparty/hostap.git/blame - tests/hwsim/test_ap_wps.py
tests: Pass AP devices to test cases
[thirdparty/hostap.git] / tests / hwsim / test_ap_wps.py
CommitLineData
302b7a1b
JM
1#!/usr/bin/python
2#
3# WPS tests
4# Copyright (c) 2013, Jouni Malinen <j@w1.fi>
5#
6# This software may be distributed under the terms of the BSD license.
7# See README for more details.
8
9import time
10import subprocess
11import logging
12logger = logging.getLogger(__name__)
13
14import hwsim_utils
15import hostapd
16
ae3ad328 17def test_ap_wps_init(dev, apdev):
302b7a1b
JM
18 """Initial AP configuration with first WPS Enrollee"""
19 ssid = "test-wps"
ae3ad328 20 hostapd.add_ap(apdev[0]['ifname'],
302b7a1b 21 { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
ae3ad328 22 hapd = hostapd.Hostapd(apdev[0]['ifname'])
302b7a1b
JM
23 logger.info("WPS provisioning step")
24 hapd.request("WPS_PBC")
25 dev[0].dump_monitor()
26 dev[0].request("WPS_PBC")
27 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
28 if ev is None:
29 raise Exception("Association with the AP timed out")
30 status = dev[0].get_status()
ae3ad328 31 if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
302b7a1b
JM
32 raise Exception("Not fully connected")
33 if status['ssid'] != ssid:
34 raise Exception("Unexpected SSID")
35 if status['pairwise_cipher'] != 'CCMP':
36 raise Exception("Unexpected encryption configuration")
37 if status['key_mgmt'] != 'WPA2-PSK':
38 raise Exception("Unexpected key_mgmt")
39
ae3ad328 40def test_ap_wps_conf(dev, apdev):
302b7a1b
JM
41 """WPS PBC provisioning with configured AP"""
42 ssid = "test-wps-conf"
ae3ad328 43 hostapd.add_ap(apdev[0]['ifname'],
302b7a1b
JM
44 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
45 "wpa_passphrase": "12345678", "wpa": "2",
46 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
ae3ad328 47 hapd = hostapd.Hostapd(apdev[0]['ifname'])
302b7a1b
JM
48 logger.info("WPS provisioning step")
49 hapd.request("WPS_PBC")
50 dev[0].dump_monitor()
51 dev[0].request("WPS_PBC")
52 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
53 if ev is None:
54 raise Exception("Association with the AP timed out")
55 status = dev[0].get_status()
ae3ad328 56 if status['wpa_state'] != 'COMPLETED':
302b7a1b 57 raise Exception("Not fully connected")
ae3ad328
JM
58 if status['bssid'] != apdev[0]['bssid']:
59 raise Exception("Unexpected BSSID")
302b7a1b
JM
60 if status['ssid'] != ssid:
61 raise Exception("Unexpected SSID")
62 if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
63 raise Exception("Unexpected encryption configuration")
64 if status['key_mgmt'] != 'WPA2-PSK':
65 raise Exception("Unexpected key_mgmt")
66
ae3ad328 67def test_ap_wps_conf_pin(dev, apdev):
302b7a1b
JM
68 """WPS PIN provisioning with configured AP"""
69 ssid = "test-wps-conf-pin"
ae3ad328 70 hostapd.add_ap(apdev[0]['ifname'],
302b7a1b
JM
71 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
72 "wpa_passphrase": "12345678", "wpa": "2",
73 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
ae3ad328 74 hapd = hostapd.Hostapd(apdev[0]['ifname'])
302b7a1b
JM
75 logger.info("WPS provisioning step")
76 pin = dev[0].wps_read_pin()
77 hapd.request("WPS_PIN any " + pin)
78 dev[0].dump_monitor()
79 dev[0].request("WPS_PIN any " + pin)
80 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
81 if ev is None:
82 raise Exception("Association with the AP timed out")
83 status = dev[0].get_status()
ae3ad328 84 if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
302b7a1b
JM
85 raise Exception("Not fully connected")
86 if status['ssid'] != ssid:
87 raise Exception("Unexpected SSID")
88 if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
89 raise Exception("Unexpected encryption configuration")
90 if status['key_mgmt'] != 'WPA2-PSK':
91 raise Exception("Unexpected key_mgmt")
92
ae3ad328 93def test_ap_wps_reg_connect(dev, apdev):
302b7a1b
JM
94 """WPS registrar using AP PIN to connect"""
95 ssid = "test-wps-conf-ap-pin"
96 appin = "12345670"
ae3ad328 97 hostapd.add_ap(apdev[0]['ifname'],
302b7a1b
JM
98 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
99 "wpa_passphrase": "12345678", "wpa": "2",
100 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
101 "ap_pin": appin})
102 logger.info("WPS provisioning step")
103 dev[0].request("BSS_FLUSH")
104 dev[0].dump_monitor()
ae3ad328 105 dev[0].request("WPS_REG " + apdev[0]['bssid'] + " " + appin)
302b7a1b
JM
106 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
107 if ev is None:
108 raise Exception("Association with the AP timed out")
109 status = dev[0].get_status()
ae3ad328 110 if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
302b7a1b
JM
111 raise Exception("Not fully connected")
112 if status['ssid'] != ssid:
113 raise Exception("Unexpected SSID")
114 if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
115 raise Exception("Unexpected encryption configuration")
116 if status['key_mgmt'] != 'WPA2-PSK':
117 raise Exception("Unexpected key_mgmt")
118
ae3ad328 119def test_ap_wps_reg_config(dev, apdev):
302b7a1b
JM
120 """WPS registrar configuring and AP using AP PIN"""
121 ssid = "test-wps-init-ap-pin"
122 appin = "12345670"
ae3ad328 123 hostapd.add_ap(apdev[0]['ifname'],
302b7a1b
JM
124 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
125 "ap_pin": appin})
126 logger.info("WPS configuration step")
127 dev[0].request("BSS_FLUSH")
128 dev[0].dump_monitor()
129 new_ssid = "wps-new-ssid"
130 new_passphrase = "1234567890"
ae3ad328 131 dev[0].request("WPS_REG " + apdev[0]['bssid'] + " " + appin + " " + new_ssid.encode("hex") + " WPA2PSK CCMP " + new_passphrase.encode("hex"))
302b7a1b
JM
132 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
133 if ev is None:
134 raise Exception("Association with the AP timed out")
135 status = dev[0].get_status()
ae3ad328 136 if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
302b7a1b
JM
137 raise Exception("Not fully connected")
138 if status['ssid'] != new_ssid:
139 raise Exception("Unexpected SSID")
140 if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
141 raise Exception("Unexpected encryption configuration")
142 if status['key_mgmt'] != 'WPA2-PSK':
143 raise Exception("Unexpected key_mgmt")
144
ae3ad328 145def test_ap_wps_pbc_overlap_2ap(dev, apdev):
302b7a1b 146 """WPS PBC session overlap with two active APs"""
ae3ad328 147 hostapd.add_ap(apdev[0]['ifname'],
302b7a1b
JM
148 { "ssid": "wps1", "eap_server": "1", "wps_state": "2",
149 "wpa_passphrase": "12345678", "wpa": "2",
150 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
151 "wps_independent": "1"})
ae3ad328 152 hostapd.add_ap(apdev[1]['ifname'],
302b7a1b
JM
153 { "ssid": "wps2", "eap_server": "1", "wps_state": "2",
154 "wpa_passphrase": "123456789", "wpa": "2",
155 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
156 "wps_independent": "1"})
ae3ad328 157 hapd = hostapd.Hostapd(apdev[0]['ifname'])
302b7a1b 158 hapd.request("WPS_PBC")
ae3ad328 159 hapd2 = hostapd.Hostapd(apdev[1]['ifname'])
302b7a1b
JM
160 hapd2.request("WPS_PBC")
161 logger.info("WPS provisioning step")
162 dev[0].dump_monitor()
163 dev[0].request("WPS_PBC")
164 ev = dev[0].wait_event(["WPS-OVERLAP-DETECTED"], timeout=15)
165 if ev is None:
166 raise Exception("PBC session overlap not detected")
167
ae3ad328 168def test_ap_wps_pbc_overlap_2sta(dev, apdev):
302b7a1b
JM
169 """WPS PBC session overlap with two active STAs"""
170 ssid = "test-wps-pbc-overlap"
ae3ad328 171 hostapd.add_ap(apdev[0]['ifname'],
302b7a1b
JM
172 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
173 "wpa_passphrase": "12345678", "wpa": "2",
174 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
ae3ad328 175 hapd = hostapd.Hostapd(apdev[0]['ifname'])
302b7a1b
JM
176 logger.info("WPS provisioning step")
177 hapd.request("WPS_PBC")
178 dev[0].request("BSS_FLUSH")
179 dev[1].request("BSS_FLUSH")
180 dev[0].dump_monitor()
181 dev[1].dump_monitor()
182 dev[0].request("WPS_PBC")
183 dev[1].request("WPS_PBC")
184 ev = dev[0].wait_event(["WPS-M2D"], timeout=15)
185 if ev is None:
186 raise Exception("PBC session overlap not detected (dev0)")
187 if "config_error=12" not in ev:
188 raise Exception("PBC session overlap not correctly reported (dev0)")
189 ev = dev[1].wait_event(["WPS-M2D"], timeout=15)
190 if ev is None:
191 raise Exception("PBC session overlap not detected (dev1)")
192 if "config_error=12" not in ev:
193 raise Exception("PBC session overlap not correctly reported (dev1)")