tests: WPS ER selecting AP using BSSID instead of UUID
[mech_eap.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()
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_twice(dev, apdev):
69     """WPS provisioning with twice to change passphrase"""
70     ssid = "test-wps-twice"
71     params = { "ssid": ssid, "eap_server": "1", "wps_state": "2",
72                "wpa_passphrase": "12345678", "wpa": "2",
73                "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }
74     hostapd.add_ap(apdev[0]['ifname'], params)
75     hapd = hostapd.Hostapd(apdev[0]['ifname'])
76     logger.info("WPS provisioning step")
77     hapd.request("WPS_PBC")
78     dev[0].request("SET ignore_old_scan_res 1")
79     dev[0].dump_monitor()
80     dev[0].request("WPS_PBC")
81     ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
82     if ev is None:
83         raise Exception("Association with the AP timed out")
84     dev[0].request("DISCONNECT")
85
86     logger.info("Restart AP with different passphrase and re-run WPS")
87     hapd_global = hostapd.HostapdGlobal()
88     hapd_global.remove(apdev[0]['ifname'])
89     params['wpa_passphrase'] = 'another passphrase'
90     hostapd.add_ap(apdev[0]['ifname'], params)
91     hapd = hostapd.Hostapd(apdev[0]['ifname'])
92     logger.info("WPS provisioning step")
93     hapd.request("WPS_PBC")
94     dev[0].dump_monitor()
95     dev[0].request("WPS_PBC")
96     ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
97     if ev is None:
98         raise Exception("Association with the AP timed out")
99     networks = dev[0].list_networks()
100     if len(networks) > 1:
101         raise Exception("Unexpected duplicated network block present")
102
103 def test_ap_wps_incorrect_pin(dev, apdev):
104     """WPS PIN provisioning with incorrect PIN"""
105     ssid = "test-wps-incorrect-pin"
106     hostapd.add_ap(apdev[0]['ifname'],
107                    { "ssid": ssid, "eap_server": "1", "wps_state": "2",
108                      "wpa_passphrase": "12345678", "wpa": "2",
109                      "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
110     hapd = hostapd.Hostapd(apdev[0]['ifname'])
111
112     logger.info("WPS provisioning attempt 1")
113     hapd.request("WPS_PIN any 12345670")
114     dev[0].request("SET ignore_old_scan_res 1")
115     dev[0].dump_monitor()
116     dev[0].request("WPS_PIN any 55554444")
117     ev = dev[0].wait_event(["WPS-FAIL"], timeout=30)
118     if ev is None:
119         raise Exception("WPS operation timed out")
120     if "config_error=18" not in ev:
121         raise Exception("Incorrect config_error reported")
122     if "msg=8" not in ev:
123         raise Exception("PIN error detected on incorrect message")
124     ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
125     if ev is None:
126         raise Exception("Timeout on disconnection event")
127     dev[0].request("WPS_CANCEL")
128     # if a scan was in progress, wait for it to complete before trying WPS again
129     ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
130
131     logger.info("WPS provisioning attempt 2")
132     hapd.request("WPS_PIN any 12345670")
133     dev[0].dump_monitor()
134     dev[0].request("WPS_PIN any 12344444")
135     ev = dev[0].wait_event(["WPS-FAIL"], timeout=30)
136     if ev is None:
137         raise Exception("WPS operation timed out")
138     if "config_error=18" not in ev:
139         raise Exception("Incorrect config_error reported")
140     if "msg=10" not in ev:
141         raise Exception("PIN error detected on incorrect message")
142     ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
143     if ev is None:
144         raise Exception("Timeout on disconnection event")
145
146 def test_ap_wps_conf_pin(dev, apdev):
147     """WPS PIN provisioning with configured AP"""
148     ssid = "test-wps-conf-pin"
149     hostapd.add_ap(apdev[0]['ifname'],
150                    { "ssid": ssid, "eap_server": "1", "wps_state": "2",
151                      "wpa_passphrase": "12345678", "wpa": "2",
152                      "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
153     hapd = hostapd.Hostapd(apdev[0]['ifname'])
154     logger.info("WPS provisioning step")
155     pin = dev[0].wps_read_pin()
156     hapd.request("WPS_PIN any " + pin)
157     dev[0].request("SET ignore_old_scan_res 1")
158     dev[0].dump_monitor()
159     dev[0].request("WPS_PIN any " + pin)
160     ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
161     if ev is None:
162         raise Exception("Association with the AP timed out")
163     status = dev[0].get_status()
164     if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
165         raise Exception("Not fully connected")
166     if status['ssid'] != ssid:
167         raise Exception("Unexpected SSID")
168     if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
169         raise Exception("Unexpected encryption configuration")
170     if status['key_mgmt'] != 'WPA2-PSK':
171         raise Exception("Unexpected key_mgmt")
172
173 def test_ap_wps_reg_connect(dev, apdev):
174     """WPS registrar using AP PIN to connect"""
175     ssid = "test-wps-reg-ap-pin"
176     appin = "12345670"
177     hostapd.add_ap(apdev[0]['ifname'],
178                    { "ssid": ssid, "eap_server": "1", "wps_state": "2",
179                      "wpa_passphrase": "12345678", "wpa": "2",
180                      "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
181                      "ap_pin": appin})
182     logger.info("WPS provisioning step")
183     dev[0].request("SET ignore_old_scan_res 1")
184     dev[0].dump_monitor()
185     dev[0].wps_reg(apdev[0]['bssid'], appin)
186     status = dev[0].get_status()
187     if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
188         raise Exception("Not fully connected")
189     if status['ssid'] != ssid:
190         raise Exception("Unexpected SSID")
191     if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
192         raise Exception("Unexpected encryption configuration")
193     if status['key_mgmt'] != 'WPA2-PSK':
194         raise Exception("Unexpected key_mgmt")
195
196 def test_ap_wps_reg_config(dev, apdev):
197     """WPS registrar configuring and AP using AP PIN"""
198     ssid = "test-wps-init-ap-pin"
199     appin = "12345670"
200     hostapd.add_ap(apdev[0]['ifname'],
201                    { "ssid": ssid, "eap_server": "1", "wps_state": "2",
202                      "ap_pin": appin})
203     logger.info("WPS configuration step")
204     dev[0].request("SET ignore_old_scan_res 1")
205     dev[0].dump_monitor()
206     new_ssid = "wps-new-ssid"
207     new_passphrase = "1234567890"
208     dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPA2PSK", "CCMP",
209                    new_passphrase)
210     status = dev[0].get_status()
211     if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
212         raise Exception("Not fully connected")
213     if status['ssid'] != new_ssid:
214         raise Exception("Unexpected SSID")
215     if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
216         raise Exception("Unexpected encryption configuration")
217     if status['key_mgmt'] != 'WPA2-PSK':
218         raise Exception("Unexpected key_mgmt")
219
220 def test_ap_wps_reg_config_tkip(dev, apdev):
221     """WPS registrar configuring AP to use TKIP and AP upgrading to TKIP+CCMP"""
222     ssid = "test-wps-init-ap"
223     appin = "12345670"
224     hostapd.add_ap(apdev[0]['ifname'],
225                    { "ssid": ssid, "eap_server": "1", "wps_state": "1",
226                      "ap_pin": appin})
227     logger.info("WPS configuration step")
228     dev[0].request("SET ignore_old_scan_res 1")
229     dev[0].request("SET wps_version_number 0x10")
230     dev[0].dump_monitor()
231     new_ssid = "wps-new-ssid-with-tkip"
232     new_passphrase = "1234567890"
233     dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPAPSK", "TKIP",
234                    new_passphrase)
235     logger.info("Re-connect to verify WPA2 mixed mode")
236     dev[0].request("DISCONNECT")
237     id = 0
238     dev[0].set_network(id, "pairwise", "CCMP")
239     dev[0].set_network(id, "proto", "RSN")
240     dev[0].connect_network(id)
241     status = dev[0].get_status()
242     if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
243         raise Exception("Not fully connected")
244     if status['ssid'] != new_ssid:
245         raise Exception("Unexpected SSID")
246     if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP':
247         raise Exception("Unexpected encryption configuration")
248     if status['key_mgmt'] != 'WPA2-PSK':
249         raise Exception("Unexpected key_mgmt")
250
251 def test_ap_wps_setup_locked(dev, apdev):
252     """WPS registrar locking up AP setup on AP PIN failures"""
253     ssid = "test-wps-incorrect-ap-pin"
254     appin = "12345670"
255     hostapd.add_ap(apdev[0]['ifname'],
256                    { "ssid": ssid, "eap_server": "1", "wps_state": "2",
257                      "wpa_passphrase": "12345678", "wpa": "2",
258                      "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
259                      "ap_pin": appin})
260     dev[0].request("SET ignore_old_scan_res 1")
261     new_ssid = "wps-new-ssid-test"
262     new_passphrase = "1234567890"
263
264     ap_setup_locked=False
265     for pin in ["55554444", "1234", "12345678", "00000000", "11111111"]:
266         dev[0].dump_monitor()
267         logger.info("Try incorrect AP PIN - attempt " + pin)
268         dev[0].wps_reg(apdev[0]['bssid'], pin, new_ssid, "WPA2PSK",
269                        "CCMP", new_passphrase, no_wait=True)
270         ev = dev[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"])
271         if ev is None:
272             raise Exception("Timeout on receiving WPS operation failure event")
273         if "CTRL-EVENT-CONNECTED" in ev:
274             raise Exception("Unexpected connection")
275         if "config_error=15" in ev:
276             logger.info("AP Setup Locked")
277             ap_setup_locked=True
278         elif "config_error=18" not in ev:
279             raise Exception("config_error=18 not reported")
280         ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
281         if ev is None:
282             raise Exception("Timeout on disconnection event")
283         time.sleep(0.1)
284     if not ap_setup_locked:
285         raise Exception("AP setup was not locked")
286
287     time.sleep(0.5)
288     dev[0].dump_monitor()
289     logger.info("WPS provisioning step")
290     pin = dev[0].wps_read_pin()
291     hapd = hostapd.Hostapd(apdev[0]['ifname'])
292     hapd.request("WPS_PIN any " + pin)
293     dev[0].request("WPS_PIN any " + pin)
294     ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=30)
295     if ev is None:
296         raise Exception("WPS success was not reported")
297     ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
298     if ev is None:
299         raise Exception("Association with the AP timed out")
300
301 def test_ap_wps_pbc_overlap_2ap(dev, apdev):
302     """WPS PBC session overlap with two active APs"""
303     hostapd.add_ap(apdev[0]['ifname'],
304                    { "ssid": "wps1", "eap_server": "1", "wps_state": "2",
305                      "wpa_passphrase": "12345678", "wpa": "2",
306                      "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
307                      "wps_independent": "1"})
308     hostapd.add_ap(apdev[1]['ifname'],
309                    { "ssid": "wps2", "eap_server": "1", "wps_state": "2",
310                      "wpa_passphrase": "123456789", "wpa": "2",
311                      "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
312                      "wps_independent": "1"})
313     hapd = hostapd.Hostapd(apdev[0]['ifname'])
314     hapd.request("WPS_PBC")
315     hapd2 = hostapd.Hostapd(apdev[1]['ifname'])
316     hapd2.request("WPS_PBC")
317     logger.info("WPS provisioning step")
318     dev[0].dump_monitor()
319     dev[0].request("WPS_PBC")
320     ev = dev[0].wait_event(["WPS-OVERLAP-DETECTED"], timeout=15)
321     if ev is None:
322         raise Exception("PBC session overlap not detected")
323
324 def test_ap_wps_pbc_overlap_2sta(dev, apdev):
325     """WPS PBC session overlap with two active STAs"""
326     ssid = "test-wps-pbc-overlap"
327     hostapd.add_ap(apdev[0]['ifname'],
328                    { "ssid": ssid, "eap_server": "1", "wps_state": "2",
329                      "wpa_passphrase": "12345678", "wpa": "2",
330                      "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
331     hapd = hostapd.Hostapd(apdev[0]['ifname'])
332     logger.info("WPS provisioning step")
333     hapd.request("WPS_PBC")
334     dev[0].request("SET ignore_old_scan_res 1")
335     dev[1].request("SET ignore_old_scan_res 1")
336     dev[0].dump_monitor()
337     dev[1].dump_monitor()
338     dev[0].request("WPS_PBC")
339     dev[1].request("WPS_PBC")
340     ev = dev[0].wait_event(["WPS-M2D"], timeout=15)
341     if ev is None:
342         raise Exception("PBC session overlap not detected (dev0)")
343     if "config_error=12" not in ev:
344         raise Exception("PBC session overlap not correctly reported (dev0)")
345     ev = dev[1].wait_event(["WPS-M2D"], timeout=15)
346     if ev is None:
347         raise Exception("PBC session overlap not detected (dev1)")
348     if "config_error=12" not in ev:
349         raise Exception("PBC session overlap not correctly reported (dev1)")
350
351 def test_ap_wps_er_add_enrollee(dev, apdev):
352     """WPS ER configuring AP and adding a new enrollee using PIN"""
353     ssid = "wps-er-add-enrollee"
354     ap_pin = "12345670"
355     ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
356     hostapd.add_ap(apdev[0]['ifname'],
357                    { "ssid": ssid, "eap_server": "1", "wps_state": "1",
358                      "device_name": "Wireless AP", "manufacturer": "Company",
359                      "model_name": "WAP", "model_number": "123",
360                      "serial_number": "12345", "device_type": "6-0050F204-1",
361                      "os_version": "01020300",
362                      "config_methods": "label push_button",
363                      "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
364     logger.info("WPS configuration step")
365     new_passphrase = "1234567890"
366     dev[0].dump_monitor()
367     dev[0].request("SET ignore_old_scan_res 1")
368     dev[0].wps_reg(apdev[0]['bssid'], ap_pin, ssid, "WPA2PSK", "CCMP",
369                    new_passphrase)
370     status = dev[0].get_status()
371     if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
372         raise Exception("Not fully connected")
373     if status['ssid'] != ssid:
374         raise Exception("Unexpected SSID")
375     if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
376         raise Exception("Unexpected encryption configuration")
377     if status['key_mgmt'] != 'WPA2-PSK':
378         raise Exception("Unexpected key_mgmt")
379
380     logger.info("Start ER")
381     dev[0].request("WPS_ER_START ifname=lo")
382     ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
383     if ev is None:
384         raise Exception("AP discovery timed out")
385     if ap_uuid not in ev:
386         raise Exception("Expected AP UUID not found")
387
388     logger.info("Learn AP configuration through UPnP")
389     dev[0].dump_monitor()
390     dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin)
391     ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15)
392     if ev is None:
393         raise Exception("AP learn timed out")
394     if ap_uuid not in ev:
395         raise Exception("Expected AP UUID not in settings")
396     if "ssid=" + ssid not in ev:
397         raise Exception("Expected SSID not in settings")
398     if "key=" + new_passphrase not in ev:
399         raise Exception("Expected passphrase not in settings")
400
401     logger.info("Add Enrollee using ER")
402     pin = dev[1].wps_read_pin()
403     dev[0].dump_monitor()
404     dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr())
405     dev[1].request("SET ignore_old_scan_res 1")
406     dev[1].dump_monitor()
407     dev[1].request("WPS_PIN any " + pin)
408     ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=30)
409     if ev is None:
410         raise Exception("Enrollee did not report success")
411     ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
412     if ev is None:
413         raise Exception("Association with the AP timed out")
414     ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
415     if ev is None:
416         raise Exception("WPS ER did not report success")
417     hwsim_utils.test_connectivity_sta(dev[0], dev[1])
418
419 def test_ap_wps_er_add_enrollee_pbc(dev, apdev):
420     """WPS ER connected to AP and adding a new enrollee using PBC"""
421     ssid = "wps-er-add-enrollee-pbc"
422     ap_pin = "12345670"
423     ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
424     hostapd.add_ap(apdev[0]['ifname'],
425                    { "ssid": ssid, "eap_server": "1", "wps_state": "2",
426                      "wpa_passphrase": "12345678", "wpa": "2",
427                      "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
428                      "device_name": "Wireless AP", "manufacturer": "Company",
429                      "model_name": "WAP", "model_number": "123",
430                      "serial_number": "12345", "device_type": "6-0050F204-1",
431                      "os_version": "01020300",
432                      "config_methods": "label push_button",
433                      "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
434     logger.info("Learn AP configuration")
435     dev[0].dump_monitor()
436     dev[0].request("SET ignore_old_scan_res 1")
437     dev[0].wps_reg(apdev[0]['bssid'], ap_pin)
438     status = dev[0].get_status()
439     if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
440         raise Exception("Not fully connected")
441
442     logger.info("Start ER")
443     dev[0].request("WPS_ER_START ifname=lo")
444     ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
445     if ev is None:
446         raise Exception("AP discovery timed out")
447     if ap_uuid not in ev:
448         raise Exception("Expected AP UUID not found")
449
450     logger.info("Use learned network configuration on ER")
451     dev[0].request("WPS_ER_SET_CONFIG " + ap_uuid + " 0")
452
453     logger.info("Add Enrollee using ER and PBC")
454     dev[0].dump_monitor()
455     enrollee = dev[1].p2p_interface_addr()
456     dev[1].request("SET ignore_old_scan_res 1")
457     dev[1].dump_monitor()
458     dev[1].request("WPS_PBC")
459
460     ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=15)
461     if ev is None:
462         raise Exception("Enrollee discovery timed out")
463     if enrollee not in ev:
464         raise Exception("Expected Enrollee not found")
465     dev[0].request("WPS_ER_PBC " + enrollee)
466
467     ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=15)
468     if ev is None:
469         raise Exception("Enrollee did not report success")
470     ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
471     if ev is None:
472         raise Exception("Association with the AP timed out")
473     ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
474     if ev is None:
475         raise Exception("WPS ER did not report success")
476     hwsim_utils.test_connectivity_sta(dev[0], dev[1])
477
478     # verify BSSID selection of the AP instead of UUID
479     if "FAIL" in dev[0].request("WPS_ER_SET_CONFIG " + apdev[0]['bssid'] + " 0"):
480         raise Exception("Could not select AP based on BSSID")
481
482 def test_ap_wps_fragmentation(dev, apdev):
483     """WPS with fragmentation in EAP-WSC and mixed mode WPA+WPA2"""
484     ssid = "test-wps-fragmentation"
485     hostapd.add_ap(apdev[0]['ifname'],
486                    { "ssid": ssid, "eap_server": "1", "wps_state": "2",
487                      "wpa_passphrase": "12345678", "wpa": "3",
488                      "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
489                      "wpa_pairwise": "TKIP",
490                      "fragment_size": "50" })
491     hapd = hostapd.Hostapd(apdev[0]['ifname'])
492     logger.info("WPS provisioning step")
493     hapd.request("WPS_PBC")
494     dev[0].request("SET ignore_old_scan_res 1")
495     dev[0].dump_monitor()
496     dev[0].request("SET wps_fragment_size 50")
497     dev[0].request("WPS_PBC")
498     ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
499     if ev is None:
500         raise Exception("Association with the AP timed out")
501     status = dev[0].get_status()
502     if status['wpa_state'] != 'COMPLETED':
503         raise Exception("Not fully connected")
504     if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP':
505         raise Exception("Unexpected encryption configuration")
506     if status['key_mgmt'] != 'WPA2-PSK':
507         raise Exception("Unexpected key_mgmt")
508
509 def test_ap_wps_new_version_sta(dev, apdev):
510     """WPS compatibility with new version number on the station"""
511     ssid = "test-wps-ver"
512     hostapd.add_ap(apdev[0]['ifname'],
513                    { "ssid": ssid, "eap_server": "1", "wps_state": "2",
514                      "wpa_passphrase": "12345678", "wpa": "2",
515                      "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
516     hapd = hostapd.Hostapd(apdev[0]['ifname'])
517     logger.info("WPS provisioning step")
518     hapd.request("WPS_PBC")
519     dev[0].request("SET ignore_old_scan_res 1")
520     dev[0].dump_monitor()
521     dev[0].request("SET wps_version_number 0x43")
522     dev[0].request("WPS_PBC")
523     ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
524     if ev is None:
525         raise Exception("Association with the AP timed out")
526
527 def test_ap_wps_new_version_ap(dev, apdev):
528     """WPS compatibility with new version number on the AP"""
529     ssid = "test-wps-ver"
530     hostapd.add_ap(apdev[0]['ifname'],
531                    { "ssid": ssid, "eap_server": "1", "wps_state": "2",
532                      "wpa_passphrase": "12345678", "wpa": "2",
533                      "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
534     hapd = hostapd.Hostapd(apdev[0]['ifname'])
535     logger.info("WPS provisioning step")
536     if "FAIL" in hapd.request("SET wps_version_number 0x43"):
537         raise Exception("Failed to enable test functionality")
538     hapd.request("WPS_PBC")
539     dev[0].request("SET ignore_old_scan_res 1")
540     dev[0].dump_monitor()
541     dev[0].request("WPS_PBC")
542     ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
543     hapd.request("SET wps_version_number 0x20")
544     if ev is None:
545         raise Exception("Association with the AP timed out")