]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_ap_wps.py
4 # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
6 # This software may be distributed under the terms of the BSD license.
7 # See README for more details.
12 logger
= logging
.getLogger(__name__
)
17 def test_ap_wps_init(dev
, apdev
):
18 """Initial AP configuration with first WPS Enrollee"""
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")
27 dev
[0].request("WPS_PBC")
28 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
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")
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")
52 dev
[0].request("WPS_PBC")
53 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
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")
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")
81 dev
[0].request("WPS_PIN any " + pin
)
82 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
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")
95 def test_ap_wps_reg_connect(dev
, apdev
):
96 """WPS registrar using AP PIN to connect"""
97 ssid
= "test-wps-reg-ap-pin"
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",
104 logger
.info("WPS provisioning step")
105 dev
[0].request("SET ignore_old_scan_res 1")
106 dev
[0].dump_monitor()
107 dev
[0].request("WPS_REG " + apdev
[0]['bssid'] + " " + appin
)
108 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
110 raise Exception("Association with the AP timed out")
111 status
= dev
[0].get_status()
112 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
113 raise Exception("Not fully connected")
114 if status
['ssid'] != ssid
:
115 raise Exception("Unexpected SSID")
116 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'CCMP':
117 raise Exception("Unexpected encryption configuration")
118 if status
['key_mgmt'] != 'WPA2-PSK':
119 raise Exception("Unexpected key_mgmt")
121 def test_ap_wps_reg_config(dev
, apdev
):
122 """WPS registrar configuring and AP using AP PIN"""
123 ssid
= "test-wps-init-ap-pin"
125 hostapd
.add_ap(apdev
[0]['ifname'],
126 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
128 logger
.info("WPS configuration step")
129 dev
[0].request("SET ignore_old_scan_res 1")
130 dev
[0].dump_monitor()
131 new_ssid
= "wps-new-ssid"
132 new_passphrase
= "1234567890"
133 dev
[0].request("WPS_REG " + apdev
[0]['bssid'] + " " + appin
+ " " + new_ssid
.encode("hex") + " WPA2PSK CCMP " + new_passphrase
.encode("hex"))
134 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
136 raise Exception("Association with the AP timed out")
137 status
= dev
[0].get_status()
138 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
139 raise Exception("Not fully connected")
140 if status
['ssid'] != new_ssid
:
141 raise Exception("Unexpected SSID")
142 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'CCMP':
143 raise Exception("Unexpected encryption configuration")
144 if status
['key_mgmt'] != 'WPA2-PSK':
145 raise Exception("Unexpected key_mgmt")
147 def test_ap_wps_pbc_overlap_2ap(dev
, apdev
):
148 """WPS PBC session overlap with two active APs"""
149 hostapd
.add_ap(apdev
[0]['ifname'],
150 { "ssid": "wps1", "eap_server": "1", "wps_state": "2",
151 "wpa_passphrase": "12345678", "wpa": "2",
152 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
153 "wps_independent": "1"})
154 hostapd
.add_ap(apdev
[1]['ifname'],
155 { "ssid": "wps2", "eap_server": "1", "wps_state": "2",
156 "wpa_passphrase": "123456789", "wpa": "2",
157 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
158 "wps_independent": "1"})
159 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
160 hapd
.request("WPS_PBC")
161 hapd2
= hostapd
.Hostapd(apdev
[1]['ifname'])
162 hapd2
.request("WPS_PBC")
163 logger
.info("WPS provisioning step")
164 dev
[0].dump_monitor()
165 dev
[0].request("WPS_PBC")
166 ev
= dev
[0].wait_event(["WPS-OVERLAP-DETECTED"], timeout
=15)
168 raise Exception("PBC session overlap not detected")
170 def test_ap_wps_pbc_overlap_2sta(dev
, apdev
):
171 """WPS PBC session overlap with two active STAs"""
172 ssid
= "test-wps-pbc-overlap"
173 hostapd
.add_ap(apdev
[0]['ifname'],
174 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
175 "wpa_passphrase": "12345678", "wpa": "2",
176 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
177 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
178 logger
.info("WPS provisioning step")
179 hapd
.request("WPS_PBC")
180 dev
[0].request("SET ignore_old_scan_res 1")
181 dev
[1].request("SET ignore_old_scan_res 1")
182 dev
[0].dump_monitor()
183 dev
[1].dump_monitor()
184 dev
[0].request("WPS_PBC")
185 dev
[1].request("WPS_PBC")
186 ev
= dev
[0].wait_event(["WPS-M2D"], timeout
=15)
188 raise Exception("PBC session overlap not detected (dev0)")
189 if "config_error=12" not in ev
:
190 raise Exception("PBC session overlap not correctly reported (dev0)")
191 ev
= dev
[1].wait_event(["WPS-M2D"], timeout
=15)
193 raise Exception("PBC session overlap not detected (dev1)")
194 if "config_error=12" not in ev
:
195 raise Exception("PBC session overlap not correctly reported (dev1)")