]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_ap_wps.py
tests: Use longer timeout in test_ap_wps_er_add_enrollee
[thirdparty/hostap.git] / tests / hwsim / test_ap_wps.py
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
9 import time
10 import subprocess
11 import logging
12 logger = logging.getLogger(__name__)
13
14 import hwsim_utils
15 import hostapd
16
17 def test_ap_wps_init(dev, apdev):
18 """Initial AP configuration with first WPS Enrollee"""
19 ssid = "test-wps"
20 hostapd.add_ap(apdev[0]['ifname'],
21 { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
22 hapd = hostapd.Hostapd(apdev[0]['ifname'])
23 logger.info("WPS provisioning step")
24 hapd.request("WPS_PBC")
25 dev[0].request("SET ignore_old_scan_res 1")
26 dev[0].dump_monitor()
27 dev[0].request("WPS_PBC")
28 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
29 if ev is None:
30 raise Exception("Association with the AP timed out")
31 status = dev[0].get_status()
32 if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
33 raise Exception("Not fully connected")
34 if status['ssid'] != ssid:
35 raise Exception("Unexpected SSID")
36 if status['pairwise_cipher'] != 'CCMP':
37 raise Exception("Unexpected encryption configuration")
38 if status['key_mgmt'] != 'WPA2-PSK':
39 raise Exception("Unexpected key_mgmt")
40
41 def test_ap_wps_conf(dev, apdev):
42 """WPS PBC provisioning with configured AP"""
43 ssid = "test-wps-conf"
44 hostapd.add_ap(apdev[0]['ifname'],
45 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
46 "wpa_passphrase": "12345678", "wpa": "2",
47 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
48 hapd = hostapd.Hostapd(apdev[0]['ifname'])
49 logger.info("WPS provisioning step")
50 hapd.request("WPS_PBC")
51 dev[0].dump_monitor()
52 dev[0].request("WPS_PBC")
53 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
54 if ev is None:
55 raise Exception("Association with the AP timed out")
56 status = dev[0].get_status()
57 if status['wpa_state'] != 'COMPLETED':
58 raise Exception("Not fully connected")
59 if status['bssid'] != apdev[0]['bssid']:
60 raise Exception("Unexpected BSSID")
61 if status['ssid'] != ssid:
62 raise Exception("Unexpected SSID")
63 if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
64 raise Exception("Unexpected encryption configuration")
65 if status['key_mgmt'] != 'WPA2-PSK':
66 raise Exception("Unexpected key_mgmt")
67
68 def test_ap_wps_conf_pin(dev, apdev):
69 """WPS PIN provisioning with configured AP"""
70 ssid = "test-wps-conf-pin"
71 hostapd.add_ap(apdev[0]['ifname'],
72 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
73 "wpa_passphrase": "12345678", "wpa": "2",
74 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
75 hapd = hostapd.Hostapd(apdev[0]['ifname'])
76 logger.info("WPS provisioning step")
77 pin = dev[0].wps_read_pin()
78 hapd.request("WPS_PIN any " + pin)
79 dev[0].request("SET ignore_old_scan_res 1")
80 dev[0].dump_monitor()
81 dev[0].request("WPS_PIN any " + pin)
82 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
83 if ev is None:
84 raise Exception("Association with the AP timed out")
85 status = dev[0].get_status()
86 if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
87 raise Exception("Not fully connected")
88 if status['ssid'] != ssid:
89 raise Exception("Unexpected SSID")
90 if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
91 raise Exception("Unexpected encryption configuration")
92 if status['key_mgmt'] != 'WPA2-PSK':
93 raise Exception("Unexpected key_mgmt")
94
95 def test_ap_wps_reg_connect(dev, apdev):
96 """WPS registrar using AP PIN to connect"""
97 ssid = "test-wps-reg-ap-pin"
98 appin = "12345670"
99 hostapd.add_ap(apdev[0]['ifname'],
100 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
101 "wpa_passphrase": "12345678", "wpa": "2",
102 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
103 "ap_pin": appin})
104 logger.info("WPS provisioning step")
105 dev[0].request("SET ignore_old_scan_res 1")
106 dev[0].dump_monitor()
107 dev[0].wps_reg(apdev[0]['bssid'], appin)
108 status = dev[0].get_status()
109 if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
110 raise Exception("Not fully connected")
111 if status['ssid'] != ssid:
112 raise Exception("Unexpected SSID")
113 if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
114 raise Exception("Unexpected encryption configuration")
115 if status['key_mgmt'] != 'WPA2-PSK':
116 raise Exception("Unexpected key_mgmt")
117
118 def test_ap_wps_reg_config(dev, apdev):
119 """WPS registrar configuring and AP using AP PIN"""
120 ssid = "test-wps-init-ap-pin"
121 appin = "12345670"
122 hostapd.add_ap(apdev[0]['ifname'],
123 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
124 "ap_pin": appin})
125 logger.info("WPS configuration step")
126 dev[0].request("SET ignore_old_scan_res 1")
127 dev[0].dump_monitor()
128 new_ssid = "wps-new-ssid"
129 new_passphrase = "1234567890"
130 dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPA2PSK", "CCMP",
131 new_passphrase)
132 status = dev[0].get_status()
133 if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
134 raise Exception("Not fully connected")
135 if status['ssid'] != new_ssid:
136 raise Exception("Unexpected SSID")
137 if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
138 raise Exception("Unexpected encryption configuration")
139 if status['key_mgmt'] != 'WPA2-PSK':
140 raise Exception("Unexpected key_mgmt")
141
142 def test_ap_wps_pbc_overlap_2ap(dev, apdev):
143 """WPS PBC session overlap with two active APs"""
144 hostapd.add_ap(apdev[0]['ifname'],
145 { "ssid": "wps1", "eap_server": "1", "wps_state": "2",
146 "wpa_passphrase": "12345678", "wpa": "2",
147 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
148 "wps_independent": "1"})
149 hostapd.add_ap(apdev[1]['ifname'],
150 { "ssid": "wps2", "eap_server": "1", "wps_state": "2",
151 "wpa_passphrase": "123456789", "wpa": "2",
152 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
153 "wps_independent": "1"})
154 hapd = hostapd.Hostapd(apdev[0]['ifname'])
155 hapd.request("WPS_PBC")
156 hapd2 = hostapd.Hostapd(apdev[1]['ifname'])
157 hapd2.request("WPS_PBC")
158 logger.info("WPS provisioning step")
159 dev[0].dump_monitor()
160 dev[0].request("WPS_PBC")
161 ev = dev[0].wait_event(["WPS-OVERLAP-DETECTED"], timeout=15)
162 if ev is None:
163 raise Exception("PBC session overlap not detected")
164
165 def test_ap_wps_pbc_overlap_2sta(dev, apdev):
166 """WPS PBC session overlap with two active STAs"""
167 ssid = "test-wps-pbc-overlap"
168 hostapd.add_ap(apdev[0]['ifname'],
169 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
170 "wpa_passphrase": "12345678", "wpa": "2",
171 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
172 hapd = hostapd.Hostapd(apdev[0]['ifname'])
173 logger.info("WPS provisioning step")
174 hapd.request("WPS_PBC")
175 dev[0].request("SET ignore_old_scan_res 1")
176 dev[1].request("SET ignore_old_scan_res 1")
177 dev[0].dump_monitor()
178 dev[1].dump_monitor()
179 dev[0].request("WPS_PBC")
180 dev[1].request("WPS_PBC")
181 ev = dev[0].wait_event(["WPS-M2D"], timeout=15)
182 if ev is None:
183 raise Exception("PBC session overlap not detected (dev0)")
184 if "config_error=12" not in ev:
185 raise Exception("PBC session overlap not correctly reported (dev0)")
186 ev = dev[1].wait_event(["WPS-M2D"], timeout=15)
187 if ev is None:
188 raise Exception("PBC session overlap not detected (dev1)")
189 if "config_error=12" not in ev:
190 raise Exception("PBC session overlap not correctly reported (dev1)")
191
192 def test_ap_wps_er_add_enrollee(dev, apdev):
193 """WPS ER configuring AP and adding a new enrollee using PIN"""
194 ssid = "wps-er-add-enrollee"
195 ap_pin = "12345670"
196 ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
197 hostapd.add_ap(apdev[0]['ifname'],
198 { "ssid": ssid, "eap_server": "1", "wps_state": "1",
199 "device_name": "Wireless AP", "manufacturer": "Company",
200 "model_name": "WAP", "model_number": "123",
201 "serial_number": "12345", "device_type": "6-0050F204-1",
202 "os_version": "01020300",
203 "config_methods": "label push_button",
204 "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
205 logger.info("WPS configuration step")
206 new_passphrase = "1234567890"
207 dev[0].dump_monitor()
208 dev[0].request("SET ignore_old_scan_res 1")
209 dev[0].wps_reg(apdev[0]['bssid'], ap_pin, ssid, "WPA2PSK", "CCMP",
210 new_passphrase)
211 status = dev[0].get_status()
212 if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
213 raise Exception("Not fully connected")
214 if status['ssid'] != ssid:
215 raise Exception("Unexpected SSID")
216 if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
217 raise Exception("Unexpected encryption configuration")
218 if status['key_mgmt'] != 'WPA2-PSK':
219 raise Exception("Unexpected key_mgmt")
220
221 logger.info("Start ER")
222 dev[0].request("WPS_ER_START ifname=lo")
223 ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
224 if ev is None:
225 raise Exception("AP discovery timed out")
226 if ap_uuid not in ev:
227 raise Exception("Expected AP UUID not found")
228
229 logger.info("Learn AP configuration through UPnP")
230 dev[0].dump_monitor()
231 dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin)
232 ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15)
233 if ev is None:
234 raise Exception("AP learn timed out")
235 if ap_uuid not in ev:
236 raise Exception("Expected AP UUID not in settings")
237 if "ssid=" + ssid not in ev:
238 raise Exception("Expected SSID not in settings")
239 if "key=" + new_passphrase not in ev:
240 raise Exception("Expected passphrase not in settings")
241
242 logger.info("Add Enrollee using ER")
243 pin = dev[1].wps_read_pin()
244 dev[0].dump_monitor()
245 dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr())
246 dev[1].request("SET ignore_old_scan_res 1")
247 dev[1].dump_monitor()
248 dev[1].request("WPS_PIN any " + pin)
249 ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=30)
250 if ev is None:
251 raise Exception("Enrollee did not report success")
252 ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
253 if ev is None:
254 raise Exception("Association with the AP timed out")
255 ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
256 if ev is None:
257 raise Exception("WPS ER did not report success")
258 hwsim_utils.test_connectivity_sta(dev[0], dev[1])
259
260 def test_ap_wps_er_add_enrollee_pbc(dev, apdev):
261 """WPS ER connected to AP and adding a new enrollee using PBC"""
262 ssid = "wps-er-add-enrollee-pbc"
263 ap_pin = "12345670"
264 ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
265 hostapd.add_ap(apdev[0]['ifname'],
266 { "ssid": ssid, "eap_server": "1", "wps_state": "2",
267 "wpa_passphrase": "12345678", "wpa": "2",
268 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
269 "device_name": "Wireless AP", "manufacturer": "Company",
270 "model_name": "WAP", "model_number": "123",
271 "serial_number": "12345", "device_type": "6-0050F204-1",
272 "os_version": "01020300",
273 "config_methods": "label push_button",
274 "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
275 logger.info("Learn AP configuration")
276 dev[0].dump_monitor()
277 dev[0].request("SET ignore_old_scan_res 1")
278 dev[0].wps_reg(apdev[0]['bssid'], ap_pin)
279 status = dev[0].get_status()
280 if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
281 raise Exception("Not fully connected")
282
283 logger.info("Start ER")
284 dev[0].request("WPS_ER_START ifname=lo")
285 ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
286 if ev is None:
287 raise Exception("AP discovery timed out")
288 if ap_uuid not in ev:
289 raise Exception("Expected AP UUID not found")
290
291 logger.info("Use learned network configuration on ER")
292 dev[0].request("WPS_ER_SET_CONFIG " + ap_uuid + " 0")
293
294 logger.info("Add Enrollee using ER and PBC")
295 dev[0].dump_monitor()
296 enrollee = dev[1].p2p_interface_addr()
297 dev[1].request("SET ignore_old_scan_res 1")
298 dev[1].dump_monitor()
299 dev[1].request("WPS_PBC")
300
301 ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=15)
302 if ev is None:
303 raise Exception("Enrollee discovery timed out")
304 if enrollee not in ev:
305 raise Exception("Expected Enrollee not found")
306 dev[0].request("WPS_ER_PBC " + enrollee)
307
308 ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=15)
309 if ev is None:
310 raise Exception("Enrollee did not report success")
311 ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
312 if ev is None:
313 raise Exception("Association with the AP timed out")
314 ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
315 if ev is None:
316 raise Exception("WPS ER did not report success")
317 hwsim_utils.test_connectivity_sta(dev[0], dev[1])