]>
Commit | Line | Data |
---|---|---|
302b7a1b | 1 | # WPS tests |
8674c022 | 2 | # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi> |
302b7a1b JM |
3 | # |
4 | # This software may be distributed under the terms of the BSD license. | |
5 | # See README for more details. | |
6 | ||
2035b170 | 7 | import os |
302b7a1b JM |
8 | import time |
9 | import subprocess | |
10 | import logging | |
c9aa4308 | 11 | logger = logging.getLogger() |
1013a576 | 12 | import re |
44ff0400 | 13 | import socket |
47c549fd JM |
14 | import httplib |
15 | import urlparse | |
16 | import urllib | |
17 | import xml.etree.ElementTree as ET | |
18 | import StringIO | |
302b7a1b JM |
19 | |
20 | import hwsim_utils | |
21 | import hostapd | |
1531402e | 22 | from wpasupplicant import WpaSupplicant |
302b7a1b | 23 | |
ae3ad328 | 24 | def test_ap_wps_init(dev, apdev): |
302b7a1b JM |
25 | """Initial AP configuration with first WPS Enrollee""" |
26 | ssid = "test-wps" | |
ae3ad328 | 27 | hostapd.add_ap(apdev[0]['ifname'], |
302b7a1b | 28 | { "ssid": ssid, "eap_server": "1", "wps_state": "1" }) |
ae3ad328 | 29 | hapd = hostapd.Hostapd(apdev[0]['ifname']) |
302b7a1b JM |
30 | logger.info("WPS provisioning step") |
31 | hapd.request("WPS_PBC") | |
d671a420 JM |
32 | if "PBC Status: Active" not in hapd.request("WPS_GET_STATUS"): |
33 | raise Exception("PBC status not shown correctly") | |
b9018833 JM |
34 | |
35 | id = dev[0].add_network() | |
36 | dev[0].set_network_quoted(id, "ssid", "home") | |
37 | dev[0].set_network_quoted(id, "psk", "12345678") | |
38 | dev[0].request("ENABLE_NETWORK %s no-connect" % id) | |
39 | ||
40 | id = dev[0].add_network() | |
41 | dev[0].set_network_quoted(id, "ssid", "home2") | |
42 | dev[0].set_network(id, "bssid", "00:11:22:33:44:55") | |
43 | dev[0].set_network(id, "key_mgmt", "NONE") | |
44 | dev[0].request("ENABLE_NETWORK %s no-connect" % id) | |
45 | ||
302b7a1b | 46 | dev[0].request("WPS_PBC") |
5f35a5e2 | 47 | dev[0].wait_connected(timeout=30) |
302b7a1b | 48 | status = dev[0].get_status() |
ae3ad328 | 49 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: |
302b7a1b JM |
50 | raise Exception("Not fully connected") |
51 | if status['ssid'] != ssid: | |
52 | raise Exception("Unexpected SSID") | |
53 | if status['pairwise_cipher'] != 'CCMP': | |
54 | raise Exception("Unexpected encryption configuration") | |
55 | if status['key_mgmt'] != 'WPA2-PSK': | |
56 | raise Exception("Unexpected key_mgmt") | |
57 | ||
d671a420 JM |
58 | status = hapd.request("WPS_GET_STATUS") |
59 | if "PBC Status: Disabled" not in status: | |
60 | raise Exception("PBC status not shown correctly") | |
61 | if "Last WPS result: Success" not in status: | |
62 | raise Exception("Last WPS result not shown correctly") | |
63 | if "Peer Address: " + dev[0].p2p_interface_addr() not in status: | |
64 | raise Exception("Peer address not shown correctly") | |
75b25ece JM |
65 | conf = hapd.request("GET_CONFIG") |
66 | if "wps_state=configured" not in conf: | |
67 | raise Exception("AP not in WPS configured state") | |
68 | if "rsn_pairwise_cipher=CCMP TKIP" not in conf: | |
69 | raise Exception("Unexpected rsn_pairwise_cipher") | |
70 | if "wpa_pairwise_cipher=CCMP TKIP" not in conf: | |
71 | raise Exception("Unexpected wpa_pairwise_cipher") | |
72 | if "group_cipher=TKIP" not in conf: | |
73 | raise Exception("Unexpected group_cipher") | |
d671a420 | 74 | |
b9018833 JM |
75 | if len(dev[0].list_networks()) != 3: |
76 | raise Exception("Unexpected number of network blocks") | |
77 | ||
18030dc0 JM |
78 | def test_ap_wps_init_2ap_pbc(dev, apdev): |
79 | """Initial two-radio AP configuration with first WPS PBC Enrollee""" | |
80 | ssid = "test-wps" | |
81 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "1" } | |
82 | hostapd.add_ap(apdev[0]['ifname'], params) | |
83 | hostapd.add_ap(apdev[1]['ifname'], params) | |
84 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
85 | logger.info("WPS provisioning step") | |
86 | hapd.request("WPS_PBC") | |
84a40841 JM |
87 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True) |
88 | dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412") | |
18030dc0 JM |
89 | bss = dev[0].get_bss(apdev[0]['bssid']) |
90 | if "[WPS-PBC]" not in bss['flags']: | |
91 | raise Exception("WPS-PBC flag missing from AP1") | |
92 | bss = dev[0].get_bss(apdev[1]['bssid']) | |
93 | if "[WPS-PBC]" not in bss['flags']: | |
94 | raise Exception("WPS-PBC flag missing from AP2") | |
95 | dev[0].dump_monitor() | |
f19d87f1 | 96 | dev[0].request("SET wps_cred_processing 2") |
18030dc0 | 97 | dev[0].request("WPS_PBC") |
f19d87f1 JM |
98 | ev = dev[0].wait_event(["WPS-CRED-RECEIVED"], timeout=30) |
99 | dev[0].request("SET wps_cred_processing 0") | |
100 | if ev is None: | |
101 | raise Exception("WPS cred event not seen") | |
102 | if "100e" not in ev: | |
103 | raise Exception("WPS attributes not included in the cred event") | |
5f35a5e2 | 104 | dev[0].wait_connected(timeout=30) |
18030dc0 | 105 | |
84a40841 JM |
106 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True) |
107 | dev[1].scan_for_bss(apdev[1]['bssid'], freq="2412") | |
18030dc0 JM |
108 | bss = dev[1].get_bss(apdev[0]['bssid']) |
109 | if "[WPS-PBC]" in bss['flags']: | |
110 | raise Exception("WPS-PBC flag not cleared from AP1") | |
111 | bss = dev[1].get_bss(apdev[1]['bssid']) | |
112 | if "[WPS-PBC]" in bss['flags']: | |
0bde923c | 113 | raise Exception("WPS-PBC flag not cleared from AP2") |
18030dc0 JM |
114 | |
115 | def test_ap_wps_init_2ap_pin(dev, apdev): | |
116 | """Initial two-radio AP configuration with first WPS PIN Enrollee""" | |
117 | ssid = "test-wps" | |
118 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "1" } | |
119 | hostapd.add_ap(apdev[0]['ifname'], params) | |
120 | hostapd.add_ap(apdev[1]['ifname'], params) | |
121 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
122 | logger.info("WPS provisioning step") | |
123 | pin = dev[0].wps_read_pin() | |
124 | hapd.request("WPS_PIN any " + pin) | |
84a40841 JM |
125 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True) |
126 | dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412") | |
18030dc0 JM |
127 | bss = dev[0].get_bss(apdev[0]['bssid']) |
128 | if "[WPS-AUTH]" not in bss['flags']: | |
129 | raise Exception("WPS-AUTH flag missing from AP1") | |
130 | bss = dev[0].get_bss(apdev[1]['bssid']) | |
131 | if "[WPS-AUTH]" not in bss['flags']: | |
132 | raise Exception("WPS-AUTH flag missing from AP2") | |
133 | dev[0].dump_monitor() | |
134 | dev[0].request("WPS_PIN any " + pin) | |
5f35a5e2 | 135 | dev[0].wait_connected(timeout=30) |
18030dc0 | 136 | |
84a40841 JM |
137 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True) |
138 | dev[1].scan_for_bss(apdev[1]['bssid'], freq="2412") | |
18030dc0 JM |
139 | bss = dev[1].get_bss(apdev[0]['bssid']) |
140 | if "[WPS-AUTH]" in bss['flags']: | |
141 | raise Exception("WPS-AUTH flag not cleared from AP1") | |
142 | bss = dev[1].get_bss(apdev[1]['bssid']) | |
143 | if "[WPS-AUTH]" in bss['flags']: | |
0bde923c | 144 | raise Exception("WPS-AUTH flag not cleared from AP2") |
18030dc0 | 145 | |
35831e94 JM |
146 | def test_ap_wps_init_through_wps_config(dev, apdev): |
147 | """Initial AP configuration using wps_config command""" | |
148 | ssid = "test-wps-init-config" | |
149 | hostapd.add_ap(apdev[0]['ifname'], | |
150 | { "ssid": ssid, "eap_server": "1", "wps_state": "1" }) | |
151 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
152 | if "FAIL" in hapd.request("WPS_CONFIG " + ssid.encode("hex") + " WPA2PSK CCMP " + "12345678".encode("hex")): | |
153 | raise Exception("WPS_CONFIG command failed") | |
180cd73d JM |
154 | ev = hapd.wait_event(["WPS-NEW-AP-SETTINGS"], timeout=5) |
155 | if ev is None: | |
156 | raise Exception("Timeout on WPS-NEW-AP-SETTINGS events") | |
157 | # It takes some time for the AP to update Beacon and Probe Response frames, | |
158 | # so wait here before requesting the scan to be started to avoid adding | |
159 | # extra five second wait to the test due to fetching obsolete scan results. | |
160 | hapd.ping() | |
161 | time.sleep(0.2) | |
35831e94 JM |
162 | dev[0].connect(ssid, psk="12345678", scan_freq="2412", proto="WPA2", |
163 | pairwise="CCMP", group="CCMP") | |
164 | ||
ae3ad328 | 165 | def test_ap_wps_conf(dev, apdev): |
302b7a1b JM |
166 | """WPS PBC provisioning with configured AP""" |
167 | ssid = "test-wps-conf" | |
ae3ad328 | 168 | hostapd.add_ap(apdev[0]['ifname'], |
302b7a1b JM |
169 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
170 | "wpa_passphrase": "12345678", "wpa": "2", | |
171 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
ae3ad328 | 172 | hapd = hostapd.Hostapd(apdev[0]['ifname']) |
302b7a1b JM |
173 | logger.info("WPS provisioning step") |
174 | hapd.request("WPS_PBC") | |
33d0b157 | 175 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
302b7a1b | 176 | dev[0].dump_monitor() |
33d0b157 | 177 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 178 | dev[0].wait_connected(timeout=30) |
302b7a1b | 179 | status = dev[0].get_status() |
ae3ad328 | 180 | if status['wpa_state'] != 'COMPLETED': |
302b7a1b | 181 | raise Exception("Not fully connected") |
ae3ad328 JM |
182 | if status['bssid'] != apdev[0]['bssid']: |
183 | raise Exception("Unexpected BSSID") | |
302b7a1b JM |
184 | if status['ssid'] != ssid: |
185 | raise Exception("Unexpected SSID") | |
186 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP': | |
187 | raise Exception("Unexpected encryption configuration") | |
188 | if status['key_mgmt'] != 'WPA2-PSK': | |
189 | raise Exception("Unexpected key_mgmt") | |
190 | ||
097cd9cd JM |
191 | sta = hapd.get_sta(dev[0].p2p_interface_addr()) |
192 | if 'wpsDeviceName' not in sta or sta['wpsDeviceName'] != "Device A": | |
193 | raise Exception("Device name not available in STA command") | |
194 | ||
daad14cc JM |
195 | def test_ap_wps_conf_5ghz(dev, apdev): |
196 | """WPS PBC provisioning with configured AP on 5 GHz band""" | |
197 | try: | |
9d7fdac5 | 198 | hapd = None |
daad14cc JM |
199 | ssid = "test-wps-conf" |
200 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
201 | "wpa_passphrase": "12345678", "wpa": "2", | |
202 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
203 | "country_code": "FI", "hw_mode": "a", "channel": "36" } | |
204 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
205 | logger.info("WPS provisioning step") | |
206 | hapd.request("WPS_PBC") | |
33d0b157 JM |
207 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="5180") |
208 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 209 | dev[0].wait_connected(timeout=30) |
daad14cc JM |
210 | |
211 | sta = hapd.get_sta(dev[0].p2p_interface_addr()) | |
212 | if 'wpsDeviceName' not in sta or sta['wpsDeviceName'] != "Device A": | |
213 | raise Exception("Device name not available in STA command") | |
214 | finally: | |
9d7fdac5 JM |
215 | dev[0].request("DISCONNECT") |
216 | if hapd: | |
217 | hapd.request("DISABLE") | |
daad14cc | 218 | subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) |
9d7fdac5 | 219 | dev[0].flush_scan_cache() |
daad14cc JM |
220 | |
221 | def test_ap_wps_conf_chan14(dev, apdev): | |
222 | """WPS PBC provisioning with configured AP on channel 14""" | |
223 | try: | |
9d7fdac5 | 224 | hapd = None |
daad14cc JM |
225 | ssid = "test-wps-conf" |
226 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
227 | "wpa_passphrase": "12345678", "wpa": "2", | |
228 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
229 | "country_code": "JP", "hw_mode": "b", "channel": "14" } | |
230 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
231 | logger.info("WPS provisioning step") | |
232 | hapd.request("WPS_PBC") | |
233 | dev[0].request("WPS_PBC") | |
5f35a5e2 | 234 | dev[0].wait_connected(timeout=30) |
daad14cc JM |
235 | |
236 | sta = hapd.get_sta(dev[0].p2p_interface_addr()) | |
237 | if 'wpsDeviceName' not in sta or sta['wpsDeviceName'] != "Device A": | |
238 | raise Exception("Device name not available in STA command") | |
239 | finally: | |
9d7fdac5 JM |
240 | dev[0].request("DISCONNECT") |
241 | if hapd: | |
242 | hapd.request("DISABLE") | |
daad14cc | 243 | subprocess.call(['sudo', 'iw', 'reg', 'set', '00']) |
9d7fdac5 | 244 | dev[0].flush_scan_cache() |
daad14cc | 245 | |
04e62788 JM |
246 | def test_ap_wps_twice(dev, apdev): |
247 | """WPS provisioning with twice to change passphrase""" | |
248 | ssid = "test-wps-twice" | |
249 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
250 | "wpa_passphrase": "12345678", "wpa": "2", | |
251 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" } | |
252 | hostapd.add_ap(apdev[0]['ifname'], params) | |
253 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
254 | logger.info("WPS provisioning step") | |
255 | hapd.request("WPS_PBC") | |
33d0b157 | 256 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
04e62788 | 257 | dev[0].dump_monitor() |
33d0b157 | 258 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 259 | dev[0].wait_connected(timeout=30) |
04e62788 JM |
260 | dev[0].request("DISCONNECT") |
261 | ||
262 | logger.info("Restart AP with different passphrase and re-run WPS") | |
263 | hapd_global = hostapd.HostapdGlobal() | |
264 | hapd_global.remove(apdev[0]['ifname']) | |
265 | params['wpa_passphrase'] = 'another passphrase' | |
266 | hostapd.add_ap(apdev[0]['ifname'], params) | |
267 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
268 | logger.info("WPS provisioning step") | |
269 | hapd.request("WPS_PBC") | |
270 | dev[0].dump_monitor() | |
33d0b157 | 271 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 272 | dev[0].wait_connected(timeout=30) |
04e62788 JM |
273 | networks = dev[0].list_networks() |
274 | if len(networks) > 1: | |
275 | raise Exception("Unexpected duplicated network block present") | |
276 | ||
d658205a JM |
277 | def test_ap_wps_incorrect_pin(dev, apdev): |
278 | """WPS PIN provisioning with incorrect PIN""" | |
279 | ssid = "test-wps-incorrect-pin" | |
280 | hostapd.add_ap(apdev[0]['ifname'], | |
281 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
282 | "wpa_passphrase": "12345678", "wpa": "2", | |
283 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
284 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
285 | ||
286 | logger.info("WPS provisioning attempt 1") | |
287 | hapd.request("WPS_PIN any 12345670") | |
33d0b157 | 288 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
d658205a | 289 | dev[0].dump_monitor() |
33d0b157 | 290 | dev[0].request("WPS_PIN %s 55554444" % apdev[0]['bssid']) |
d658205a JM |
291 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=30) |
292 | if ev is None: | |
293 | raise Exception("WPS operation timed out") | |
294 | if "config_error=18" not in ev: | |
295 | raise Exception("Incorrect config_error reported") | |
296 | if "msg=8" not in ev: | |
297 | raise Exception("PIN error detected on incorrect message") | |
5f35a5e2 | 298 | dev[0].wait_disconnected(timeout=10) |
d658205a JM |
299 | dev[0].request("WPS_CANCEL") |
300 | # if a scan was in progress, wait for it to complete before trying WPS again | |
301 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) | |
302 | ||
d671a420 JM |
303 | status = hapd.request("WPS_GET_STATUS") |
304 | if "Last WPS result: Failed" not in status: | |
305 | raise Exception("WPS failure result not shown correctly") | |
306 | ||
d658205a JM |
307 | logger.info("WPS provisioning attempt 2") |
308 | hapd.request("WPS_PIN any 12345670") | |
309 | dev[0].dump_monitor() | |
33d0b157 | 310 | dev[0].request("WPS_PIN %s 12344444" % apdev[0]['bssid']) |
d658205a JM |
311 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=30) |
312 | if ev is None: | |
313 | raise Exception("WPS operation timed out") | |
314 | if "config_error=18" not in ev: | |
315 | raise Exception("Incorrect config_error reported") | |
316 | if "msg=10" not in ev: | |
317 | raise Exception("PIN error detected on incorrect message") | |
5f35a5e2 | 318 | dev[0].wait_disconnected(timeout=10) |
d658205a | 319 | |
ae3ad328 | 320 | def test_ap_wps_conf_pin(dev, apdev): |
302b7a1b JM |
321 | """WPS PIN provisioning with configured AP""" |
322 | ssid = "test-wps-conf-pin" | |
ae3ad328 | 323 | hostapd.add_ap(apdev[0]['ifname'], |
302b7a1b JM |
324 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
325 | "wpa_passphrase": "12345678", "wpa": "2", | |
326 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
ae3ad328 | 327 | hapd = hostapd.Hostapd(apdev[0]['ifname']) |
302b7a1b JM |
328 | logger.info("WPS provisioning step") |
329 | pin = dev[0].wps_read_pin() | |
330 | hapd.request("WPS_PIN any " + pin) | |
33d0b157 | 331 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
302b7a1b | 332 | dev[0].dump_monitor() |
33d0b157 | 333 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
5f35a5e2 | 334 | dev[0].wait_connected(timeout=30) |
302b7a1b | 335 | status = dev[0].get_status() |
ae3ad328 | 336 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: |
302b7a1b JM |
337 | raise Exception("Not fully connected") |
338 | if status['ssid'] != ssid: | |
339 | raise Exception("Unexpected SSID") | |
340 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP': | |
341 | raise Exception("Unexpected encryption configuration") | |
342 | if status['key_mgmt'] != 'WPA2-PSK': | |
343 | raise Exception("Unexpected key_mgmt") | |
344 | ||
84a40841 | 345 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True) |
362ba6de JM |
346 | bss = dev[1].get_bss(apdev[0]['bssid']) |
347 | if "[WPS-AUTH]" in bss['flags']: | |
348 | raise Exception("WPS-AUTH flag not cleared") | |
a60a6d6b | 349 | logger.info("Try to connect from another station using the same PIN") |
33d0b157 | 350 | pin = dev[1].request("WPS_PIN " + apdev[0]['bssid']) |
a60a6d6b JM |
351 | ev = dev[1].wait_event(["WPS-M2D","CTRL-EVENT-CONNECTED"], timeout=30) |
352 | if ev is None: | |
353 | raise Exception("Operation timed out") | |
354 | if "WPS-M2D" not in ev: | |
355 | raise Exception("Unexpected WPS operation started") | |
6e12eaa4 | 356 | hapd.request("WPS_PIN any " + pin) |
5f35a5e2 | 357 | dev[1].wait_connected(timeout=30) |
362ba6de | 358 | |
6257f9c0 JM |
359 | def test_ap_wps_conf_pin_v1(dev, apdev): |
360 | """WPS PIN provisioning with configured WPS v1.0 AP""" | |
361 | ssid = "test-wps-conf-pin-v1" | |
362 | hostapd.add_ap(apdev[0]['ifname'], | |
363 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
364 | "wpa_passphrase": "12345678", "wpa": "2", | |
365 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
366 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
367 | logger.info("WPS provisioning step") | |
368 | pin = dev[0].wps_read_pin() | |
369 | hapd.request("SET wps_version_number 0x10") | |
370 | hapd.request("WPS_PIN any " + pin) | |
371 | found = False | |
372 | for i in range(0, 10): | |
373 | dev[0].scan(freq="2412") | |
374 | if "[WPS-PIN]" in dev[0].request("SCAN_RESULTS"): | |
375 | found = True | |
376 | break | |
377 | if not found: | |
378 | hapd.request("SET wps_version_number 0x20") | |
379 | raise Exception("WPS-PIN flag not seen in scan results") | |
380 | dev[0].dump_monitor() | |
33d0b157 | 381 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
5f35a5e2 | 382 | dev[0].wait_connected(timeout=30) |
6257f9c0 | 383 | hapd.request("SET wps_version_number 0x20") |
6257f9c0 | 384 | |
e9129860 JM |
385 | def test_ap_wps_conf_pin_2sta(dev, apdev): |
386 | """Two stations trying to use WPS PIN at the same time""" | |
387 | ssid = "test-wps-conf-pin2" | |
388 | hostapd.add_ap(apdev[0]['ifname'], | |
389 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
390 | "wpa_passphrase": "12345678", "wpa": "2", | |
391 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
392 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
393 | logger.info("WPS provisioning step") | |
394 | pin = "12345670" | |
395 | pin2 = "55554444" | |
396 | hapd.request("WPS_PIN " + dev[0].get_status_field("uuid") + " " + pin) | |
397 | hapd.request("WPS_PIN " + dev[1].get_status_field("uuid") + " " + pin) | |
e9129860 | 398 | dev[0].dump_monitor() |
e9129860 | 399 | dev[1].dump_monitor() |
33d0b157 JM |
400 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
401 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
402 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
403 | dev[1].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
5f35a5e2 JM |
404 | dev[0].wait_connected(timeout=30) |
405 | dev[1].wait_connected(timeout=30) | |
0489e880 JM |
406 | |
407 | def test_ap_wps_conf_pin_timeout(dev, apdev): | |
408 | """WPS PIN provisioning with configured AP timing out PIN""" | |
409 | ssid = "test-wps-conf-pin" | |
410 | hostapd.add_ap(apdev[0]['ifname'], | |
411 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
412 | "wpa_passphrase": "12345678", "wpa": "2", | |
413 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
414 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
415 | addr = dev[0].p2p_interface_addr() | |
416 | pin = dev[0].wps_read_pin() | |
417 | if "FAIL" not in hapd.request("WPS_PIN "): | |
418 | raise Exception("Unexpected success on invalid WPS_PIN") | |
419 | hapd.request("WPS_PIN any " + pin + " 1") | |
33d0b157 | 420 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
0489e880 | 421 | time.sleep(1.1) |
33d0b157 | 422 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
0489e880 JM |
423 | ev = hapd.wait_event(["WPS-PIN-NEEDED"], timeout=20) |
424 | if ev is None: | |
425 | raise Exception("WPS-PIN-NEEDED event timed out") | |
426 | ev = dev[0].wait_event(["WPS-M2D"]) | |
427 | if ev is None: | |
428 | raise Exception("M2D not reported") | |
429 | dev[0].request("WPS_CANCEL") | |
430 | ||
431 | hapd.request("WPS_PIN any " + pin + " 20 " + addr) | |
33d0b157 | 432 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
5f35a5e2 | 433 | dev[0].wait_connected(timeout=30) |
e9129860 | 434 | |
ae3ad328 | 435 | def test_ap_wps_reg_connect(dev, apdev): |
302b7a1b | 436 | """WPS registrar using AP PIN to connect""" |
803edd1c | 437 | ssid = "test-wps-reg-ap-pin" |
302b7a1b | 438 | appin = "12345670" |
ae3ad328 | 439 | hostapd.add_ap(apdev[0]['ifname'], |
302b7a1b JM |
440 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
441 | "wpa_passphrase": "12345678", "wpa": "2", | |
442 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
443 | "ap_pin": appin}) | |
444 | logger.info("WPS provisioning step") | |
302b7a1b | 445 | dev[0].dump_monitor() |
33d0b157 | 446 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
6edaee9c | 447 | dev[0].wps_reg(apdev[0]['bssid'], appin) |
302b7a1b | 448 | status = dev[0].get_status() |
ae3ad328 | 449 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: |
302b7a1b JM |
450 | raise Exception("Not fully connected") |
451 | if status['ssid'] != ssid: | |
452 | raise Exception("Unexpected SSID") | |
453 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP': | |
454 | raise Exception("Unexpected encryption configuration") | |
455 | if status['key_mgmt'] != 'WPA2-PSK': | |
456 | raise Exception("Unexpected key_mgmt") | |
457 | ||
9488858f JM |
458 | def check_wps_reg_failure(dev, ap, appin): |
459 | dev.request("WPS_REG " + ap['bssid'] + " " + appin) | |
460 | ev = dev.wait_event(["WPS-SUCCESS", "WPS-FAIL"], timeout=15) | |
461 | if ev is None: | |
462 | raise Exception("WPS operation timed out") | |
463 | if "WPS-SUCCESS" in ev: | |
464 | raise Exception("WPS operation succeeded unexpectedly") | |
465 | if "config_error=15" not in ev: | |
466 | raise Exception("WPS setup locked state was not reported correctly") | |
467 | ||
e4357b19 JM |
468 | def test_ap_wps_random_ap_pin(dev, apdev): |
469 | """WPS registrar using random AP PIN""" | |
470 | ssid = "test-wps-reg-random-ap-pin" | |
471 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
472 | hostapd.add_ap(apdev[0]['ifname'], | |
473 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
474 | "wpa_passphrase": "12345678", "wpa": "2", | |
475 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
476 | "device_name": "Wireless AP", "manufacturer": "Company", | |
477 | "model_name": "WAP", "model_number": "123", | |
478 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
479 | "os_version": "01020300", | |
480 | "config_methods": "label push_button", | |
481 | "uuid": ap_uuid, "upnp_iface": "lo" }) | |
482 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
483 | appin = hapd.request("WPS_AP_PIN random") | |
484 | if "FAIL" in appin: | |
485 | raise Exception("Could not generate random AP PIN") | |
486 | if appin not in hapd.request("WPS_AP_PIN get"): | |
487 | raise Exception("Could not fetch current AP PIN") | |
488 | logger.info("WPS provisioning step") | |
33d0b157 | 489 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
e4357b19 JM |
490 | dev[0].wps_reg(apdev[0]['bssid'], appin) |
491 | ||
492 | hapd.request("WPS_AP_PIN disable") | |
493 | logger.info("WPS provisioning step with AP PIN disabled") | |
33d0b157 | 494 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) |
9488858f JM |
495 | check_wps_reg_failure(dev[1], apdev[0], appin) |
496 | ||
497 | logger.info("WPS provisioning step with AP PIN reset") | |
498 | appin = "12345670" | |
499 | hapd.request("WPS_AP_PIN set " + appin) | |
500 | dev[1].wps_reg(apdev[0]['bssid'], appin) | |
501 | dev[0].request("REMOVE_NETWORK all") | |
502 | dev[1].request("REMOVE_NETWORK all") | |
5f35a5e2 JM |
503 | dev[0].wait_disconnected(timeout=10) |
504 | dev[1].wait_disconnected(timeout=10) | |
9488858f JM |
505 | |
506 | logger.info("WPS provisioning step after AP PIN timeout") | |
507 | hapd.request("WPS_AP_PIN disable") | |
508 | appin = hapd.request("WPS_AP_PIN random 1") | |
509 | time.sleep(1.1) | |
510 | if "FAIL" not in hapd.request("WPS_AP_PIN get"): | |
511 | raise Exception("AP PIN unexpectedly still enabled") | |
512 | check_wps_reg_failure(dev[0], apdev[0], appin) | |
513 | ||
514 | logger.info("WPS provisioning step after AP PIN timeout(2)") | |
515 | hapd.request("WPS_AP_PIN disable") | |
516 | appin = "12345670" | |
517 | hapd.request("WPS_AP_PIN set " + appin + " 1") | |
518 | time.sleep(1.1) | |
519 | if "FAIL" not in hapd.request("WPS_AP_PIN get"): | |
520 | raise Exception("AP PIN unexpectedly still enabled") | |
521 | check_wps_reg_failure(dev[1], apdev[0], appin) | |
e4357b19 | 522 | |
ae3ad328 | 523 | def test_ap_wps_reg_config(dev, apdev): |
4b727c5c | 524 | """WPS registrar configuring an AP using AP PIN""" |
302b7a1b JM |
525 | ssid = "test-wps-init-ap-pin" |
526 | appin = "12345670" | |
ae3ad328 | 527 | hostapd.add_ap(apdev[0]['ifname'], |
302b7a1b JM |
528 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
529 | "ap_pin": appin}) | |
530 | logger.info("WPS configuration step") | |
33d0b157 | 531 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
302b7a1b JM |
532 | dev[0].dump_monitor() |
533 | new_ssid = "wps-new-ssid" | |
534 | new_passphrase = "1234567890" | |
6edaee9c JM |
535 | dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPA2PSK", "CCMP", |
536 | new_passphrase) | |
302b7a1b | 537 | status = dev[0].get_status() |
ae3ad328 | 538 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: |
302b7a1b JM |
539 | raise Exception("Not fully connected") |
540 | if status['ssid'] != new_ssid: | |
541 | raise Exception("Unexpected SSID") | |
542 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP': | |
543 | raise Exception("Unexpected encryption configuration") | |
544 | if status['key_mgmt'] != 'WPA2-PSK': | |
545 | raise Exception("Unexpected key_mgmt") | |
546 | ||
375afd7c JM |
547 | logger.info("Re-configure back to open") |
548 | dev[0].request("REMOVE_NETWORK all") | |
243dcc4a | 549 | dev[0].flush_scan_cache() |
375afd7c JM |
550 | dev[0].dump_monitor() |
551 | dev[0].wps_reg(apdev[0]['bssid'], appin, "wps-open", "OPEN", "NONE", "") | |
552 | status = dev[0].get_status() | |
553 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: | |
554 | raise Exception("Not fully connected") | |
555 | if status['ssid'] != "wps-open": | |
556 | raise Exception("Unexpected SSID") | |
557 | if status['key_mgmt'] != 'NONE': | |
558 | raise Exception("Unexpected key_mgmt") | |
559 | ||
4b727c5c JM |
560 | def test_ap_wps_reg_config_ext_processing(dev, apdev): |
561 | """WPS registrar configuring an AP with external config processing""" | |
562 | ssid = "test-wps-init-ap-pin" | |
563 | appin = "12345670" | |
564 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
565 | "wps_cred_processing": "1", "ap_pin": appin} | |
566 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
33d0b157 | 567 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
4b727c5c JM |
568 | new_ssid = "wps-new-ssid" |
569 | new_passphrase = "1234567890" | |
570 | dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPA2PSK", "CCMP", | |
571 | new_passphrase, no_wait=True) | |
572 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) | |
573 | if ev is None: | |
574 | raise Exception("WPS registrar operation timed out") | |
575 | ev = hapd.wait_event(["WPS-NEW-AP-SETTINGS"], timeout=15) | |
576 | if ev is None: | |
577 | raise Exception("WPS configuration timed out") | |
578 | if "1026" not in ev: | |
579 | raise Exception("AP Settings missing from event") | |
580 | hapd.request("SET wps_cred_processing 0") | |
581 | if "FAIL" in hapd.request("WPS_CONFIG " + new_ssid.encode("hex") + " WPA2PSK CCMP " + new_passphrase.encode("hex")): | |
582 | raise Exception("WPS_CONFIG command failed") | |
5f35a5e2 | 583 | dev[0].wait_connected(timeout=15) |
4b727c5c | 584 | |
eeefe187 JM |
585 | def test_ap_wps_reg_config_tkip(dev, apdev): |
586 | """WPS registrar configuring AP to use TKIP and AP upgrading to TKIP+CCMP""" | |
587 | ssid = "test-wps-init-ap" | |
588 | appin = "12345670" | |
589 | hostapd.add_ap(apdev[0]['ifname'], | |
590 | { "ssid": ssid, "eap_server": "1", "wps_state": "1", | |
591 | "ap_pin": appin}) | |
592 | logger.info("WPS configuration step") | |
eeefe187 | 593 | dev[0].request("SET wps_version_number 0x10") |
33d0b157 | 594 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
eeefe187 JM |
595 | dev[0].dump_monitor() |
596 | new_ssid = "wps-new-ssid-with-tkip" | |
597 | new_passphrase = "1234567890" | |
598 | dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPAPSK", "TKIP", | |
599 | new_passphrase) | |
600 | logger.info("Re-connect to verify WPA2 mixed mode") | |
601 | dev[0].request("DISCONNECT") | |
602 | id = 0 | |
603 | dev[0].set_network(id, "pairwise", "CCMP") | |
604 | dev[0].set_network(id, "proto", "RSN") | |
605 | dev[0].connect_network(id) | |
606 | status = dev[0].get_status() | |
607 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: | |
3c086180 | 608 | raise Exception("Not fully connected: wpa_state={} bssid={}".format(status['wpa_state'], status['bssid'])) |
eeefe187 JM |
609 | if status['ssid'] != new_ssid: |
610 | raise Exception("Unexpected SSID") | |
611 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP': | |
612 | raise Exception("Unexpected encryption configuration") | |
613 | if status['key_mgmt'] != 'WPA2-PSK': | |
614 | raise Exception("Unexpected key_mgmt") | |
615 | ||
6645ff50 JM |
616 | def test_ap_wps_setup_locked(dev, apdev): |
617 | """WPS registrar locking up AP setup on AP PIN failures""" | |
618 | ssid = "test-wps-incorrect-ap-pin" | |
619 | appin = "12345670" | |
620 | hostapd.add_ap(apdev[0]['ifname'], | |
621 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
622 | "wpa_passphrase": "12345678", "wpa": "2", | |
623 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
624 | "ap_pin": appin}) | |
6645ff50 JM |
625 | new_ssid = "wps-new-ssid-test" |
626 | new_passphrase = "1234567890" | |
627 | ||
33d0b157 | 628 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
6645ff50 JM |
629 | ap_setup_locked=False |
630 | for pin in ["55554444", "1234", "12345678", "00000000", "11111111"]: | |
631 | dev[0].dump_monitor() | |
632 | logger.info("Try incorrect AP PIN - attempt " + pin) | |
633 | dev[0].wps_reg(apdev[0]['bssid'], pin, new_ssid, "WPA2PSK", | |
634 | "CCMP", new_passphrase, no_wait=True) | |
635 | ev = dev[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"]) | |
636 | if ev is None: | |
637 | raise Exception("Timeout on receiving WPS operation failure event") | |
638 | if "CTRL-EVENT-CONNECTED" in ev: | |
639 | raise Exception("Unexpected connection") | |
640 | if "config_error=15" in ev: | |
641 | logger.info("AP Setup Locked") | |
642 | ap_setup_locked=True | |
643 | elif "config_error=18" not in ev: | |
644 | raise Exception("config_error=18 not reported") | |
5f35a5e2 | 645 | dev[0].wait_disconnected(timeout=10) |
6645ff50 JM |
646 | time.sleep(0.1) |
647 | if not ap_setup_locked: | |
648 | raise Exception("AP setup was not locked") | |
649 | ||
d671a420 JM |
650 | hapd = hostapd.Hostapd(apdev[0]['ifname']) |
651 | status = hapd.request("WPS_GET_STATUS") | |
652 | if "Last WPS result: Failed" not in status: | |
653 | raise Exception("WPS failure result not shown correctly") | |
654 | if "Peer Address: " + dev[0].p2p_interface_addr() not in status: | |
655 | raise Exception("Peer address not shown correctly") | |
656 | ||
6645ff50 JM |
657 | time.sleep(0.5) |
658 | dev[0].dump_monitor() | |
659 | logger.info("WPS provisioning step") | |
660 | pin = dev[0].wps_read_pin() | |
661 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
662 | hapd.request("WPS_PIN any " + pin) | |
33d0b157 | 663 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
6645ff50 JM |
664 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=30) |
665 | if ev is None: | |
666 | raise Exception("WPS success was not reported") | |
5f35a5e2 | 667 | dev[0].wait_connected(timeout=30) |
6645ff50 | 668 | |
c1cec68b JM |
669 | appin = hapd.request("WPS_AP_PIN random") |
670 | if "FAIL" in appin: | |
671 | raise Exception("Could not generate random AP PIN") | |
672 | ev = hapd.wait_event(["WPS-AP-SETUP-UNLOCKED"], timeout=10) | |
673 | if ev is None: | |
674 | raise Exception("Failed to unlock AP PIN") | |
675 | ||
33c9b8d8 JM |
676 | def test_ap_wps_setup_locked_timeout(dev, apdev): |
677 | """WPS re-enabling AP PIN after timeout""" | |
678 | ssid = "test-wps-incorrect-ap-pin" | |
679 | appin = "12345670" | |
680 | hostapd.add_ap(apdev[0]['ifname'], | |
681 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
682 | "wpa_passphrase": "12345678", "wpa": "2", | |
683 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
684 | "ap_pin": appin}) | |
685 | new_ssid = "wps-new-ssid-test" | |
686 | new_passphrase = "1234567890" | |
687 | ||
33d0b157 | 688 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
33c9b8d8 JM |
689 | ap_setup_locked=False |
690 | for pin in ["55554444", "1234", "12345678", "00000000", "11111111"]: | |
691 | dev[0].dump_monitor() | |
692 | logger.info("Try incorrect AP PIN - attempt " + pin) | |
693 | dev[0].wps_reg(apdev[0]['bssid'], pin, new_ssid, "WPA2PSK", | |
694 | "CCMP", new_passphrase, no_wait=True) | |
9ed53f5e | 695 | ev = dev[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"], timeout=15) |
33c9b8d8 JM |
696 | if ev is None: |
697 | raise Exception("Timeout on receiving WPS operation failure event") | |
698 | if "CTRL-EVENT-CONNECTED" in ev: | |
699 | raise Exception("Unexpected connection") | |
700 | if "config_error=15" in ev: | |
701 | logger.info("AP Setup Locked") | |
702 | ap_setup_locked=True | |
703 | break | |
704 | elif "config_error=18" not in ev: | |
705 | raise Exception("config_error=18 not reported") | |
5f35a5e2 | 706 | dev[0].wait_disconnected(timeout=10) |
33c9b8d8 JM |
707 | time.sleep(0.1) |
708 | if not ap_setup_locked: | |
709 | raise Exception("AP setup was not locked") | |
710 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
711 | ev = hapd.wait_event(["WPS-AP-SETUP-UNLOCKED"], timeout=80) | |
712 | if ev is None: | |
713 | raise Exception("AP PIN did not get unlocked on 60 second timeout") | |
714 | ||
ae3ad328 | 715 | def test_ap_wps_pbc_overlap_2ap(dev, apdev): |
302b7a1b | 716 | """WPS PBC session overlap with two active APs""" |
ae3ad328 | 717 | hostapd.add_ap(apdev[0]['ifname'], |
302b7a1b JM |
718 | { "ssid": "wps1", "eap_server": "1", "wps_state": "2", |
719 | "wpa_passphrase": "12345678", "wpa": "2", | |
720 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
721 | "wps_independent": "1"}) | |
ae3ad328 | 722 | hostapd.add_ap(apdev[1]['ifname'], |
302b7a1b JM |
723 | { "ssid": "wps2", "eap_server": "1", "wps_state": "2", |
724 | "wpa_passphrase": "123456789", "wpa": "2", | |
725 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
726 | "wps_independent": "1"}) | |
ae3ad328 | 727 | hapd = hostapd.Hostapd(apdev[0]['ifname']) |
302b7a1b | 728 | hapd.request("WPS_PBC") |
ae3ad328 | 729 | hapd2 = hostapd.Hostapd(apdev[1]['ifname']) |
302b7a1b JM |
730 | hapd2.request("WPS_PBC") |
731 | logger.info("WPS provisioning step") | |
84a40841 JM |
732 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True) |
733 | dev[0].scan_for_bss(apdev[1]['bssid'], freq="2412") | |
302b7a1b JM |
734 | dev[0].request("WPS_PBC") |
735 | ev = dev[0].wait_event(["WPS-OVERLAP-DETECTED"], timeout=15) | |
736 | if ev is None: | |
737 | raise Exception("PBC session overlap not detected") | |
738 | ||
ae3ad328 | 739 | def test_ap_wps_pbc_overlap_2sta(dev, apdev): |
302b7a1b JM |
740 | """WPS PBC session overlap with two active STAs""" |
741 | ssid = "test-wps-pbc-overlap" | |
ae3ad328 | 742 | hostapd.add_ap(apdev[0]['ifname'], |
302b7a1b JM |
743 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", |
744 | "wpa_passphrase": "12345678", "wpa": "2", | |
745 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
ae3ad328 | 746 | hapd = hostapd.Hostapd(apdev[0]['ifname']) |
302b7a1b JM |
747 | logger.info("WPS provisioning step") |
748 | hapd.request("WPS_PBC") | |
33d0b157 | 749 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
302b7a1b | 750 | dev[0].dump_monitor() |
33d0b157 | 751 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412") |
302b7a1b | 752 | dev[1].dump_monitor() |
33d0b157 JM |
753 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
754 | dev[1].request("WPS_PBC " + apdev[0]['bssid']) | |
302b7a1b JM |
755 | ev = dev[0].wait_event(["WPS-M2D"], timeout=15) |
756 | if ev is None: | |
757 | raise Exception("PBC session overlap not detected (dev0)") | |
758 | if "config_error=12" not in ev: | |
759 | raise Exception("PBC session overlap not correctly reported (dev0)") | |
760 | ev = dev[1].wait_event(["WPS-M2D"], timeout=15) | |
761 | if ev is None: | |
762 | raise Exception("PBC session overlap not detected (dev1)") | |
763 | if "config_error=12" not in ev: | |
764 | raise Exception("PBC session overlap not correctly reported (dev1)") | |
11e7eeba JM |
765 | hapd.request("WPS_CANCEL") |
766 | ret = hapd.request("WPS_PBC") | |
767 | if "FAIL" not in ret: | |
768 | raise Exception("PBC mode allowed to be started while PBC overlap still active") | |
6edaee9c | 769 | |
71afe834 JM |
770 | def test_ap_wps_cancel(dev, apdev): |
771 | """WPS AP cancelling enabled config method""" | |
772 | ssid = "test-wps-ap-cancel" | |
773 | hostapd.add_ap(apdev[0]['ifname'], | |
774 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
775 | "wpa_passphrase": "12345678", "wpa": "2", | |
776 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }) | |
777 | bssid = apdev[0]['bssid'] | |
778 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
779 | ||
780 | logger.info("Verify PBC enable/cancel") | |
781 | hapd.request("WPS_PBC") | |
71afe834 | 782 | dev[0].scan(freq="2412") |
84a40841 | 783 | dev[0].scan(freq="2412") |
71afe834 JM |
784 | bss = dev[0].get_bss(apdev[0]['bssid']) |
785 | if "[WPS-PBC]" not in bss['flags']: | |
786 | raise Exception("WPS-PBC flag missing") | |
787 | if "FAIL" in hapd.request("WPS_CANCEL"): | |
788 | raise Exception("WPS_CANCEL failed") | |
789 | dev[0].scan(freq="2412") | |
84a40841 | 790 | dev[0].scan(freq="2412") |
71afe834 JM |
791 | bss = dev[0].get_bss(apdev[0]['bssid']) |
792 | if "[WPS-PBC]" in bss['flags']: | |
793 | raise Exception("WPS-PBC flag not cleared") | |
794 | ||
795 | logger.info("Verify PIN enable/cancel") | |
796 | hapd.request("WPS_PIN any 12345670") | |
797 | dev[0].scan(freq="2412") | |
84a40841 | 798 | dev[0].scan(freq="2412") |
71afe834 JM |
799 | bss = dev[0].get_bss(apdev[0]['bssid']) |
800 | if "[WPS-AUTH]" not in bss['flags']: | |
801 | raise Exception("WPS-AUTH flag missing") | |
802 | if "FAIL" in hapd.request("WPS_CANCEL"): | |
803 | raise Exception("WPS_CANCEL failed") | |
804 | dev[0].scan(freq="2412") | |
84a40841 | 805 | dev[0].scan(freq="2412") |
71afe834 JM |
806 | bss = dev[0].get_bss(apdev[0]['bssid']) |
807 | if "[WPS-AUTH]" in bss['flags']: | |
808 | raise Exception("WPS-AUTH flag not cleared") | |
809 | ||
6edaee9c JM |
810 | def test_ap_wps_er_add_enrollee(dev, apdev): |
811 | """WPS ER configuring AP and adding a new enrollee using PIN""" | |
be9f1562 JM |
812 | try: |
813 | _test_ap_wps_er_add_enrollee(dev, apdev) | |
814 | finally: | |
815 | dev[0].request("WPS_ER_STOP") | |
816 | ||
817 | def _test_ap_wps_er_add_enrollee(dev, apdev): | |
6edaee9c JM |
818 | ssid = "wps-er-add-enrollee" |
819 | ap_pin = "12345670" | |
820 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
821 | hostapd.add_ap(apdev[0]['ifname'], | |
822 | { "ssid": ssid, "eap_server": "1", "wps_state": "1", | |
823 | "device_name": "Wireless AP", "manufacturer": "Company", | |
824 | "model_name": "WAP", "model_number": "123", | |
825 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
826 | "os_version": "01020300", | |
827 | "config_methods": "label push_button", | |
828 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
829 | logger.info("WPS configuration step") | |
830 | new_passphrase = "1234567890" | |
831 | dev[0].dump_monitor() | |
33d0b157 | 832 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
6edaee9c JM |
833 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin, ssid, "WPA2PSK", "CCMP", |
834 | new_passphrase) | |
835 | status = dev[0].get_status() | |
836 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: | |
837 | raise Exception("Not fully connected") | |
838 | if status['ssid'] != ssid: | |
839 | raise Exception("Unexpected SSID") | |
840 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP': | |
841 | raise Exception("Unexpected encryption configuration") | |
842 | if status['key_mgmt'] != 'WPA2-PSK': | |
843 | raise Exception("Unexpected key_mgmt") | |
844 | ||
845 | logger.info("Start ER") | |
846 | dev[0].request("WPS_ER_START ifname=lo") | |
847 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
848 | if ev is None: | |
849 | raise Exception("AP discovery timed out") | |
850 | if ap_uuid not in ev: | |
851 | raise Exception("Expected AP UUID not found") | |
852 | ||
853 | logger.info("Learn AP configuration through UPnP") | |
854 | dev[0].dump_monitor() | |
855 | dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin) | |
856 | ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15) | |
857 | if ev is None: | |
858 | raise Exception("AP learn timed out") | |
859 | if ap_uuid not in ev: | |
860 | raise Exception("Expected AP UUID not in settings") | |
861 | if "ssid=" + ssid not in ev: | |
862 | raise Exception("Expected SSID not in settings") | |
863 | if "key=" + new_passphrase not in ev: | |
864 | raise Exception("Expected passphrase not in settings") | |
33d0b157 JM |
865 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=15) |
866 | if ev is None: | |
867 | raise Exception("WPS-FAIL after AP learn timed out") | |
868 | time.sleep(0.1) | |
6edaee9c JM |
869 | |
870 | logger.info("Add Enrollee using ER") | |
871 | pin = dev[1].wps_read_pin() | |
872 | dev[0].dump_monitor() | |
873 | dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr()) | |
33d0b157 | 874 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) |
6edaee9c | 875 | dev[1].dump_monitor() |
33d0b157 | 876 | dev[1].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
846be889 | 877 | ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=30) |
6edaee9c JM |
878 | if ev is None: |
879 | raise Exception("Enrollee did not report success") | |
5f35a5e2 | 880 | dev[1].wait_connected(timeout=15) |
6edaee9c JM |
881 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) |
882 | if ev is None: | |
883 | raise Exception("WPS ER did not report success") | |
884 | hwsim_utils.test_connectivity_sta(dev[0], dev[1]) | |
885 | ||
11c26f1b JM |
886 | logger.info("Add a specific Enrollee using ER") |
887 | pin = dev[2].wps_read_pin() | |
888 | addr2 = dev[2].p2p_interface_addr() | |
889 | dev[0].dump_monitor() | |
33d0b157 | 890 | dev[2].scan_for_bss(apdev[0]['bssid'], freq=2412) |
11c26f1b | 891 | dev[2].dump_monitor() |
33d0b157 | 892 | dev[2].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
11c26f1b JM |
893 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=10) |
894 | if ev is None: | |
895 | raise Exception("Enrollee not seen") | |
896 | if addr2 not in ev: | |
897 | raise Exception("Unexpected Enrollee MAC address") | |
898 | dev[0].request("WPS_ER_PIN " + addr2 + " " + pin + " " + addr2) | |
5f35a5e2 | 899 | dev[2].wait_connected(timeout=30) |
11c26f1b JM |
900 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) |
901 | if ev is None: | |
902 | raise Exception("WPS ER did not report success") | |
903 | ||
38ae43de JM |
904 | logger.info("Verify registrar selection behavior") |
905 | dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr()) | |
906 | dev[1].request("DISCONNECT") | |
5f35a5e2 | 907 | dev[1].wait_disconnected(timeout=10) |
84a40841 | 908 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412") |
38ae43de JM |
909 | dev[1].scan(freq="2412") |
910 | bss = dev[1].get_bss(apdev[0]['bssid']) | |
911 | if "[WPS-AUTH]" not in bss['flags']: | |
321c7f60 JM |
912 | # It is possible for scan to miss an update especially when running |
913 | # tests under load with multiple VMs, so allow another attempt. | |
914 | dev[1].scan(freq="2412") | |
915 | bss = dev[1].get_bss(apdev[0]['bssid']) | |
916 | if "[WPS-AUTH]" not in bss['flags']: | |
917 | raise Exception("WPS-AUTH flag missing") | |
38ae43de JM |
918 | |
919 | logger.info("Stop ER") | |
920 | dev[0].dump_monitor() | |
921 | dev[0].request("WPS_ER_STOP") | |
922 | ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"]) | |
923 | if ev is None: | |
924 | raise Exception("WPS ER unsubscription timed out") | |
8697cbc0 | 925 | # It takes some time for the UPnP UNSUBSCRIBE command to go through, so wait |
befd671c | 926 | # a bit before verifying that the scan results have changed. |
8697cbc0 | 927 | time.sleep(0.2) |
38ae43de | 928 | |
befd671c JM |
929 | for i in range(0, 10): |
930 | dev[1].request("BSS_FLUSH 0") | |
931 | dev[1].scan(freq="2412", only_new=True) | |
932 | bss = dev[1].get_bss(apdev[0]['bssid']) | |
933 | if bss and 'flags' in bss and "[WPS-AUTH]" not in bss['flags']: | |
934 | break | |
935 | logger.debug("WPS-AUTH flag was still in place - wait a bit longer") | |
936 | time.sleep(0.1) | |
38ae43de JM |
937 | if "[WPS-AUTH]" in bss['flags']: |
938 | raise Exception("WPS-AUTH flag not removed") | |
939 | ||
6edaee9c JM |
940 | def test_ap_wps_er_add_enrollee_pbc(dev, apdev): |
941 | """WPS ER connected to AP and adding a new enrollee using PBC""" | |
be9f1562 JM |
942 | try: |
943 | _test_ap_wps_er_add_enrollee_pbc(dev, apdev) | |
944 | finally: | |
945 | dev[0].request("WPS_ER_STOP") | |
946 | ||
947 | def _test_ap_wps_er_add_enrollee_pbc(dev, apdev): | |
6edaee9c JM |
948 | ssid = "wps-er-add-enrollee-pbc" |
949 | ap_pin = "12345670" | |
950 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
951 | hostapd.add_ap(apdev[0]['ifname'], | |
952 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
953 | "wpa_passphrase": "12345678", "wpa": "2", | |
954 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
955 | "device_name": "Wireless AP", "manufacturer": "Company", | |
956 | "model_name": "WAP", "model_number": "123", | |
957 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
958 | "os_version": "01020300", | |
959 | "config_methods": "label push_button", | |
960 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
961 | logger.info("Learn AP configuration") | |
33d0b157 | 962 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
6edaee9c | 963 | dev[0].dump_monitor() |
6edaee9c JM |
964 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) |
965 | status = dev[0].get_status() | |
966 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: | |
967 | raise Exception("Not fully connected") | |
968 | ||
969 | logger.info("Start ER") | |
970 | dev[0].request("WPS_ER_START ifname=lo") | |
971 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
972 | if ev is None: | |
973 | raise Exception("AP discovery timed out") | |
974 | if ap_uuid not in ev: | |
975 | raise Exception("Expected AP UUID not found") | |
976 | ||
d6b916c9 JM |
977 | enrollee = dev[1].p2p_interface_addr() |
978 | ||
979 | if "FAIL-UNKNOWN-UUID" not in dev[0].request("WPS_ER_PBC " + enrollee): | |
980 | raise Exception("Unknown UUID not reported") | |
6edaee9c JM |
981 | |
982 | logger.info("Add Enrollee using ER and PBC") | |
983 | dev[0].dump_monitor() | |
6edaee9c JM |
984 | dev[1].dump_monitor() |
985 | dev[1].request("WPS_PBC") | |
986 | ||
8674c022 JM |
987 | for i in range(0, 2): |
988 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=15) | |
989 | if ev is None: | |
990 | raise Exception("Enrollee discovery timed out") | |
991 | if enrollee in ev: | |
992 | break | |
993 | if i == 1: | |
994 | raise Exception("Expected Enrollee not found") | |
d6b916c9 JM |
995 | if "FAIL-NO-AP-SETTINGS" not in dev[0].request("WPS_ER_PBC " + enrollee): |
996 | raise Exception("Unknown UUID not reported") | |
997 | logger.info("Use learned network configuration on ER") | |
998 | dev[0].request("WPS_ER_SET_CONFIG " + ap_uuid + " 0") | |
999 | if "OK" not in dev[0].request("WPS_ER_PBC " + enrollee): | |
1000 | raise Exception("WPS_ER_PBC failed") | |
6edaee9c JM |
1001 | |
1002 | ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=15) | |
1003 | if ev is None: | |
1004 | raise Exception("Enrollee did not report success") | |
5f35a5e2 | 1005 | dev[1].wait_connected(timeout=15) |
6edaee9c JM |
1006 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) |
1007 | if ev is None: | |
1008 | raise Exception("WPS ER did not report success") | |
1009 | hwsim_utils.test_connectivity_sta(dev[0], dev[1]) | |
bff3ac5b | 1010 | |
d6b916c9 JM |
1011 | def test_ap_wps_er_pbc_overlap(dev, apdev): |
1012 | """WPS ER connected to AP and PBC session overlap""" | |
be9f1562 JM |
1013 | try: |
1014 | _test_ap_wps_er_pbc_overlap(dev, apdev) | |
1015 | finally: | |
1016 | dev[0].request("WPS_ER_STOP") | |
1017 | ||
1018 | def _test_ap_wps_er_pbc_overlap(dev, apdev): | |
d6b916c9 JM |
1019 | ssid = "wps-er-add-enrollee-pbc" |
1020 | ap_pin = "12345670" | |
1021 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
1022 | hostapd.add_ap(apdev[0]['ifname'], | |
1023 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1024 | "wpa_passphrase": "12345678", "wpa": "2", | |
1025 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1026 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1027 | "model_name": "WAP", "model_number": "123", | |
1028 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1029 | "os_version": "01020300", | |
1030 | "config_methods": "label push_button", | |
1031 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
1032 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) | |
1033 | dev[0].dump_monitor() | |
1034 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) | |
1035 | ||
1036 | dev[0].dump_monitor() | |
1037 | dev[0].request("WPS_ER_START ifname=lo") | |
1038 | ||
1039 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1040 | if ev is None: | |
1041 | raise Exception("AP discovery timed out") | |
1042 | if ap_uuid not in ev: | |
1043 | raise Exception("Expected AP UUID not found") | |
1044 | ||
800bcf4e JM |
1045 | # verify BSSID selection of the AP instead of UUID |
1046 | if "FAIL" in dev[0].request("WPS_ER_SET_CONFIG " + apdev[0]['bssid'] + " 0"): | |
1047 | raise Exception("Could not select AP based on BSSID") | |
1048 | ||
d6b916c9 JM |
1049 | dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412") |
1050 | dev[2].scan_for_bss(apdev[0]['bssid'], freq="2412") | |
1051 | dev[1].request("WPS_PBC " + apdev[0]['bssid']) | |
1052 | dev[2].request("WPS_PBC " + apdev[0]['bssid']) | |
1053 | ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10) | |
1054 | if ev is None: | |
1055 | raise Exception("PBC scan failed") | |
1056 | ev = dev[2].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10) | |
1057 | if ev is None: | |
1058 | raise Exception("PBC scan failed") | |
1059 | for i in range(0, 2): | |
1060 | ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=15) | |
1061 | if ev is None: | |
1062 | raise Exception("Enrollee discovery timed out") | |
1063 | if dev[0].request("WPS_ER_PBC " + ap_uuid) != "FAIL-PBC-OVERLAP\n": | |
1064 | raise Exception("PBC overlap not reported") | |
1065 | dev[1].request("WPS_CANCEL") | |
1066 | dev[2].request("WPS_CANCEL") | |
1067 | if dev[0].request("WPS_ER_PBC foo") != "FAIL\n": | |
1068 | raise Exception("Invalid WPS_ER_PBC accepted") | |
1069 | ||
1f020f5e JM |
1070 | def test_ap_wps_er_v10_add_enrollee_pin(dev, apdev): |
1071 | """WPS v1.0 ER connected to AP and adding a new enrollee using PIN""" | |
be9f1562 JM |
1072 | try: |
1073 | _test_ap_wps_er_v10_add_enrollee_pin(dev, apdev) | |
1074 | finally: | |
1075 | dev[0].request("WPS_ER_STOP") | |
1076 | ||
1077 | def _test_ap_wps_er_v10_add_enrollee_pin(dev, apdev): | |
1f020f5e JM |
1078 | ssid = "wps-er-add-enrollee-pbc" |
1079 | ap_pin = "12345670" | |
1080 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
1081 | hostapd.add_ap(apdev[0]['ifname'], | |
1082 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1083 | "wpa_passphrase": "12345678", "wpa": "2", | |
1084 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1085 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1086 | "model_name": "WAP", "model_number": "123", | |
1087 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1088 | "os_version": "01020300", | |
1089 | "config_methods": "label push_button", | |
1090 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
1091 | logger.info("Learn AP configuration") | |
1092 | dev[0].request("SET wps_version_number 0x10") | |
33d0b157 | 1093 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1f020f5e JM |
1094 | dev[0].dump_monitor() |
1095 | dev[0].wps_reg(apdev[0]['bssid'], ap_pin) | |
1096 | status = dev[0].get_status() | |
1097 | if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']: | |
1098 | raise Exception("Not fully connected") | |
1099 | ||
1100 | logger.info("Start ER") | |
1101 | dev[0].request("WPS_ER_START ifname=lo") | |
1102 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1103 | if ev is None: | |
1104 | raise Exception("AP discovery timed out") | |
1105 | if ap_uuid not in ev: | |
1106 | raise Exception("Expected AP UUID not found") | |
1107 | ||
1108 | logger.info("Use learned network configuration on ER") | |
1109 | dev[0].request("WPS_ER_SET_CONFIG " + ap_uuid + " 0") | |
1110 | ||
1111 | logger.info("Add Enrollee using ER and PIN") | |
1112 | enrollee = dev[1].p2p_interface_addr() | |
1113 | pin = dev[1].wps_read_pin() | |
1114 | dev[0].dump_monitor() | |
1115 | dev[0].request("WPS_ER_PIN any " + pin + " " + enrollee) | |
33d0b157 | 1116 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1f020f5e | 1117 | dev[1].dump_monitor() |
33d0b157 | 1118 | dev[1].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
5f35a5e2 | 1119 | dev[1].wait_connected(timeout=30) |
1f020f5e JM |
1120 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15) |
1121 | if ev is None: | |
1122 | raise Exception("WPS ER did not report success") | |
1123 | ||
be923570 JM |
1124 | def test_ap_wps_er_config_ap(dev, apdev): |
1125 | """WPS ER configuring AP over UPnP""" | |
be9f1562 JM |
1126 | try: |
1127 | _test_ap_wps_er_config_ap(dev, apdev) | |
1128 | finally: | |
1129 | dev[0].request("WPS_ER_STOP") | |
1130 | ||
1131 | def _test_ap_wps_er_config_ap(dev, apdev): | |
be923570 JM |
1132 | ssid = "wps-er-ap-config" |
1133 | ap_pin = "12345670" | |
1134 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
1135 | hostapd.add_ap(apdev[0]['ifname'], | |
1136 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1137 | "wpa_passphrase": "12345678", "wpa": "2", | |
1138 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1139 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1140 | "model_name": "WAP", "model_number": "123", | |
1141 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1142 | "os_version": "01020300", | |
1143 | "config_methods": "label push_button", | |
1144 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"}) | |
1145 | ||
1146 | logger.info("Connect ER to the AP") | |
1147 | dev[0].connect(ssid, psk="12345678", scan_freq="2412") | |
1148 | ||
1149 | logger.info("WPS configuration step") | |
1150 | dev[0].request("WPS_ER_START ifname=lo") | |
1151 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1152 | if ev is None: | |
1153 | raise Exception("AP discovery timed out") | |
1154 | if ap_uuid not in ev: | |
1155 | raise Exception("Expected AP UUID not found") | |
1156 | new_passphrase = "1234567890" | |
1157 | dev[0].request("WPS_ER_CONFIG " + apdev[0]['bssid'] + " " + ap_pin + " " + | |
1158 | ssid.encode("hex") + " WPA2PSK CCMP " + | |
1159 | new_passphrase.encode("hex")) | |
1160 | ev = dev[0].wait_event(["WPS-SUCCESS"]) | |
1161 | if ev is None: | |
1162 | raise Exception("WPS ER configuration operation timed out") | |
5f35a5e2 | 1163 | dev[0].wait_disconnected(timeout=10) |
be923570 JM |
1164 | dev[0].connect(ssid, psk="1234567890", scan_freq="2412") |
1165 | ||
8f8c2fe8 JM |
1166 | logger.info("WPS ER restart") |
1167 | dev[0].request("WPS_ER_START") | |
1168 | ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15) | |
1169 | if ev is None: | |
1170 | raise Exception("AP discovery timed out on ER restart") | |
1171 | if ap_uuid not in ev: | |
1172 | raise Exception("Expected AP UUID not found on ER restart") | |
1173 | if "OK" not in dev[0].request("WPS_ER_STOP"): | |
1174 | raise Exception("WPS_ER_STOP failed") | |
1175 | if "OK" not in dev[0].request("WPS_ER_STOP"): | |
1176 | raise Exception("WPS_ER_STOP failed") | |
1177 | ||
bff3ac5b JM |
1178 | def test_ap_wps_fragmentation(dev, apdev): |
1179 | """WPS with fragmentation in EAP-WSC and mixed mode WPA+WPA2""" | |
1180 | ssid = "test-wps-fragmentation" | |
9602b355 | 1181 | appin = "12345670" |
bff3ac5b JM |
1182 | hostapd.add_ap(apdev[0]['ifname'], |
1183 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1184 | "wpa_passphrase": "12345678", "wpa": "3", | |
1185 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
9602b355 | 1186 | "wpa_pairwise": "TKIP", "ap_pin": appin, |
bff3ac5b JM |
1187 | "fragment_size": "50" }) |
1188 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
9602b355 | 1189 | logger.info("WPS provisioning step (PBC)") |
bff3ac5b | 1190 | hapd.request("WPS_PBC") |
33d0b157 | 1191 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
bff3ac5b JM |
1192 | dev[0].dump_monitor() |
1193 | dev[0].request("SET wps_fragment_size 50") | |
33d0b157 | 1194 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 1195 | dev[0].wait_connected(timeout=30) |
bff3ac5b JM |
1196 | status = dev[0].get_status() |
1197 | if status['wpa_state'] != 'COMPLETED': | |
9602b355 JM |
1198 | raise Exception("Not fully connected") |
1199 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP': | |
1200 | raise Exception("Unexpected encryption configuration") | |
1201 | if status['key_mgmt'] != 'WPA2-PSK': | |
1202 | raise Exception("Unexpected key_mgmt") | |
1203 | ||
1204 | logger.info("WPS provisioning step (PIN)") | |
1205 | pin = dev[1].wps_read_pin() | |
1206 | hapd.request("WPS_PIN any " + pin) | |
33d0b157 | 1207 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) |
9602b355 | 1208 | dev[1].request("SET wps_fragment_size 50") |
33d0b157 | 1209 | dev[1].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) |
5f35a5e2 | 1210 | dev[1].wait_connected(timeout=30) |
9602b355 JM |
1211 | status = dev[1].get_status() |
1212 | if status['wpa_state'] != 'COMPLETED': | |
1213 | raise Exception("Not fully connected") | |
1214 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP': | |
1215 | raise Exception("Unexpected encryption configuration") | |
1216 | if status['key_mgmt'] != 'WPA2-PSK': | |
1217 | raise Exception("Unexpected key_mgmt") | |
1218 | ||
1219 | logger.info("WPS connection as registrar") | |
33d0b157 | 1220 | dev[2].scan_for_bss(apdev[0]['bssid'], freq=2412) |
9602b355 JM |
1221 | dev[2].request("SET wps_fragment_size 50") |
1222 | dev[2].wps_reg(apdev[0]['bssid'], appin) | |
1223 | status = dev[2].get_status() | |
1224 | if status['wpa_state'] != 'COMPLETED': | |
bff3ac5b JM |
1225 | raise Exception("Not fully connected") |
1226 | if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP': | |
1227 | raise Exception("Unexpected encryption configuration") | |
1228 | if status['key_mgmt'] != 'WPA2-PSK': | |
1229 | raise Exception("Unexpected key_mgmt") | |
10ea6848 JM |
1230 | |
1231 | def test_ap_wps_new_version_sta(dev, apdev): | |
1232 | """WPS compatibility with new version number on the station""" | |
1233 | ssid = "test-wps-ver" | |
1234 | hostapd.add_ap(apdev[0]['ifname'], | |
1235 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1236 | "wpa_passphrase": "12345678", "wpa": "2", | |
1237 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }) | |
1238 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
1239 | logger.info("WPS provisioning step") | |
1240 | hapd.request("WPS_PBC") | |
33d0b157 | 1241 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
10ea6848 JM |
1242 | dev[0].dump_monitor() |
1243 | dev[0].request("SET wps_version_number 0x43") | |
dccafedb | 1244 | dev[0].request("SET wps_vendor_ext_m1 000137100100020001") |
33d0b157 | 1245 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 1246 | dev[0].wait_connected(timeout=30) |
10ea6848 JM |
1247 | |
1248 | def test_ap_wps_new_version_ap(dev, apdev): | |
1249 | """WPS compatibility with new version number on the AP""" | |
1250 | ssid = "test-wps-ver" | |
1251 | hostapd.add_ap(apdev[0]['ifname'], | |
1252 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1253 | "wpa_passphrase": "12345678", "wpa": "2", | |
1254 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }) | |
1255 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
1256 | logger.info("WPS provisioning step") | |
1257 | if "FAIL" in hapd.request("SET wps_version_number 0x43"): | |
1258 | raise Exception("Failed to enable test functionality") | |
1259 | hapd.request("WPS_PBC") | |
33d0b157 | 1260 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
10ea6848 | 1261 | dev[0].dump_monitor() |
33d0b157 | 1262 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 1263 | dev[0].wait_connected(timeout=30) |
10ea6848 | 1264 | hapd.request("SET wps_version_number 0x20") |
3bdf7d7f JM |
1265 | |
1266 | def test_ap_wps_check_pin(dev, apdev): | |
1267 | """Verify PIN checking through control interface""" | |
1268 | hostapd.add_ap(apdev[0]['ifname'], | |
1269 | { "ssid": "wps", "eap_server": "1", "wps_state": "2", | |
1270 | "wpa_passphrase": "12345678", "wpa": "2", | |
1271 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }) | |
1272 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
1273 | for t in [ ("12345670", "12345670"), | |
1274 | ("12345678", "FAIL-CHECKSUM"), | |
df58939c | 1275 | ("12345", "FAIL"), |
6e12eaa4 | 1276 | ("123456789", "FAIL"), |
3bdf7d7f JM |
1277 | ("1234-5670", "12345670"), |
1278 | ("1234 5670", "12345670"), | |
1279 | ("1-2.3:4 5670", "12345670") ]: | |
1280 | res = hapd.request("WPS_CHECK_PIN " + t[0]).rstrip('\n') | |
1281 | res2 = dev[0].request("WPS_CHECK_PIN " + t[0]).rstrip('\n') | |
1282 | if res != res2: | |
1283 | raise Exception("Unexpected difference in WPS_CHECK_PIN responses") | |
1284 | if res != t[1]: | |
1285 | raise Exception("Incorrect WPS_CHECK_PIN response {} (expected {})".format(res, t[1])) | |
9ba1fcb0 | 1286 | |
ac786d67 JM |
1287 | if "FAIL" not in hapd.request("WPS_CHECK_PIN 12345"): |
1288 | raise Exception("Unexpected WPS_CHECK_PIN success") | |
1289 | if "FAIL" not in hapd.request("WPS_CHECK_PIN 123456789"): | |
1290 | raise Exception("Unexpected WPS_CHECK_PIN success") | |
1291 | ||
acd9b45a JM |
1292 | for i in range(0, 10): |
1293 | pin = dev[0].request("WPS_PIN get") | |
1294 | rpin = dev[0].request("WPS_CHECK_PIN " + pin).rstrip('\n') | |
1295 | if pin != rpin: | |
1296 | raise Exception("Random PIN validation failed for " + pin) | |
1297 | ||
9ba1fcb0 JM |
1298 | def test_ap_wps_wep_config(dev, apdev): |
1299 | """WPS 2.0 AP rejecting WEP configuration""" | |
1300 | ssid = "test-wps-config" | |
1301 | appin = "12345670" | |
1302 | hostapd.add_ap(apdev[0]['ifname'], | |
1303 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1304 | "ap_pin": appin}) | |
1305 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
33d0b157 | 1306 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
9ba1fcb0 JM |
1307 | dev[0].wps_reg(apdev[0]['bssid'], appin, "wps-new-ssid-wep", "OPEN", "WEP", |
1308 | "hello", no_wait=True) | |
1309 | ev = hapd.wait_event(["WPS-FAIL"], timeout=15) | |
1310 | if ev is None: | |
1311 | raise Exception("WPS-FAIL timed out") | |
1312 | if "reason=2" not in ev: | |
1313 | raise Exception("Unexpected reason code in WPS-FAIL") | |
1314 | status = hapd.request("WPS_GET_STATUS") | |
1315 | if "Last WPS result: Failed" not in status: | |
1316 | raise Exception("WPS failure result not shown correctly") | |
1317 | if "Failure Reason: WEP Prohibited" not in status: | |
1318 | raise Exception("Failure reason not reported correctly") | |
1319 | if "Peer Address: " + dev[0].p2p_interface_addr() not in status: | |
1320 | raise Exception("Peer address not shown correctly") | |
1013a576 | 1321 | |
11d78bb1 JM |
1322 | def test_ap_wps_wep_enroll(dev, apdev): |
1323 | """WPS 2.0 STA rejecting WEP configuration""" | |
1324 | ssid = "test-wps-wep" | |
1325 | hostapd.add_ap(apdev[0]['ifname'], | |
1326 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1327 | "skip_cred_build": "1", "extra_cred": "wps-wep-cred" }) | |
1328 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
1329 | hapd.request("WPS_PBC") | |
33d0b157 JM |
1330 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1331 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
11d78bb1 JM |
1332 | ev = dev[0].wait_event(["WPS-FAIL"], timeout=15) |
1333 | if ev is None: | |
1334 | raise Exception("WPS-FAIL event timed out") | |
1335 | if "msg=12" not in ev or "reason=2 (WEP Prohibited)" not in ev: | |
1336 | raise Exception("Unexpected WPS-FAIL event: " + ev) | |
1337 | ||
1013a576 JM |
1338 | def test_ap_wps_ie_fragmentation(dev, apdev): |
1339 | """WPS AP using fragmented WPS IE""" | |
1340 | ssid = "test-wps-ie-fragmentation" | |
1341 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1342 | "wpa_passphrase": "12345678", "wpa": "2", | |
1343 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1344 | "device_name": "1234567890abcdef1234567890abcdef", | |
1345 | "manufacturer": "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", | |
1346 | "model_name": "1234567890abcdef1234567890abcdef", | |
1347 | "model_number": "1234567890abcdef1234567890abcdef", | |
1348 | "serial_number": "1234567890abcdef1234567890abcdef" } | |
1349 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1350 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
1351 | hapd.request("WPS_PBC") | |
33d0b157 JM |
1352 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
1353 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 1354 | dev[0].wait_connected(timeout=30) |
1013a576 JM |
1355 | bss = dev[0].get_bss(apdev[0]['bssid']) |
1356 | if "wps_device_name" not in bss or bss['wps_device_name'] != "1234567890abcdef1234567890abcdef": | |
cf3f0ec8 | 1357 | logger.info("Device Name not received correctly") |
d7a68ad6 | 1358 | logger.info(bss) |
cf3f0ec8 JM |
1359 | # This can fail if Probe Response frame is missed and Beacon frame was |
1360 | # used to fill in the BSS entry. This can happen, e.g., during heavy | |
1361 | # load every now and then and is not really an error, so try to | |
1362 | # workaround by runnign another scan. | |
1363 | dev[0].scan(freq="2412", only_new=True) | |
1364 | bss = dev[0].get_bss(apdev[0]['bssid']) | |
84a40841 | 1365 | if not bss or "wps_device_name" not in bss or bss['wps_device_name'] != "1234567890abcdef1234567890abcdef": |
cf3f0ec8 JM |
1366 | logger.info(bss) |
1367 | raise Exception("Device Name not received correctly") | |
1013a576 JM |
1368 | if len(re.findall("dd..0050f204", bss['ie'])) != 2: |
1369 | raise Exception("Unexpected number of WPS IEs") | |
44ff0400 | 1370 | |
2035b170 JM |
1371 | def get_psk(pskfile): |
1372 | psks = {} | |
1373 | with open(pskfile, "r") as f: | |
1374 | lines = f.read().splitlines() | |
1375 | for l in lines: | |
1376 | if l == "# WPA PSKs": | |
1377 | continue | |
1378 | (addr,psk) = l.split(' ') | |
1379 | psks[addr] = psk | |
1380 | return psks | |
1381 | ||
1382 | def test_ap_wps_per_station_psk(dev, apdev): | |
1383 | """WPS PBC provisioning with per-station PSK""" | |
1384 | addr0 = dev[0].p2p_dev_addr() | |
1385 | addr1 = dev[1].p2p_dev_addr() | |
1386 | addr2 = dev[2].p2p_dev_addr() | |
1387 | ssid = "wps" | |
1388 | appin = "12345670" | |
1389 | pskfile = "/tmp/ap_wps_per_enrollee_psk.psk_file" | |
1390 | try: | |
1391 | os.remove(pskfile) | |
1392 | except: | |
1393 | pass | |
1394 | ||
1395 | try: | |
1396 | with open(pskfile, "w") as f: | |
1397 | f.write("# WPA PSKs\n") | |
1398 | ||
1399 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1400 | "wpa": "2", "wpa_key_mgmt": "WPA-PSK", | |
1401 | "rsn_pairwise": "CCMP", "ap_pin": appin, | |
1402 | "wpa_psk_file": pskfile } | |
1403 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1404 | ||
1405 | logger.info("First enrollee") | |
1406 | hapd.request("WPS_PBC") | |
33d0b157 JM |
1407 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1408 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 1409 | dev[0].wait_connected(timeout=30) |
2035b170 JM |
1410 | |
1411 | logger.info("Second enrollee") | |
1412 | hapd.request("WPS_PBC") | |
33d0b157 JM |
1413 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1414 | dev[1].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 1415 | dev[1].wait_connected(timeout=30) |
2035b170 JM |
1416 | |
1417 | logger.info("External registrar") | |
33d0b157 | 1418 | dev[2].scan_for_bss(apdev[0]['bssid'], freq=2412) |
2035b170 JM |
1419 | dev[2].wps_reg(apdev[0]['bssid'], appin) |
1420 | ||
1421 | logger.info("Verifying PSK results") | |
1422 | psks = get_psk(pskfile) | |
1423 | if addr0 not in psks: | |
1424 | raise Exception("No PSK recorded for sta0") | |
1425 | if addr1 not in psks: | |
1426 | raise Exception("No PSK recorded for sta1") | |
1427 | if addr2 not in psks: | |
1428 | raise Exception("No PSK recorded for sta2") | |
1429 | if psks[addr0] == psks[addr1]: | |
1430 | raise Exception("Same PSK recorded for sta0 and sta1") | |
1431 | if psks[addr0] == psks[addr2]: | |
1432 | raise Exception("Same PSK recorded for sta0 and sta2") | |
1433 | if psks[addr1] == psks[addr2]: | |
1434 | raise Exception("Same PSK recorded for sta1 and sta2") | |
1435 | ||
1436 | dev[0].request("REMOVE_NETWORK all") | |
1437 | logger.info("Second external registrar") | |
33d0b157 | 1438 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
2035b170 JM |
1439 | dev[0].wps_reg(apdev[0]['bssid'], appin) |
1440 | psks2 = get_psk(pskfile) | |
1441 | if addr0 not in psks2: | |
1442 | raise Exception("No PSK recorded for sta0(reg)") | |
1443 | if psks[addr0] == psks2[addr0]: | |
1444 | raise Exception("Same PSK recorded for sta0(enrollee) and sta0(reg)") | |
1445 | finally: | |
1446 | os.remove(pskfile) | |
1447 | ||
373cce55 JM |
1448 | def test_ap_wps_per_station_psk_failure(dev, apdev): |
1449 | """WPS PBC provisioning with per-station PSK (file not writable)""" | |
1450 | addr0 = dev[0].p2p_dev_addr() | |
1451 | addr1 = dev[1].p2p_dev_addr() | |
1452 | addr2 = dev[2].p2p_dev_addr() | |
1453 | ssid = "wps" | |
1454 | appin = "12345670" | |
1455 | pskfile = "/tmp/ap_wps_per_enrollee_psk.psk_file" | |
1456 | try: | |
1457 | os.remove(pskfile) | |
1458 | except: | |
1459 | pass | |
1460 | ||
1461 | try: | |
1462 | with open(pskfile, "w") as f: | |
1463 | f.write("# WPA PSKs\n") | |
1464 | ||
1465 | params = { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1466 | "wpa": "2", "wpa_key_mgmt": "WPA-PSK", | |
1467 | "rsn_pairwise": "CCMP", "ap_pin": appin, | |
1468 | "wpa_psk_file": pskfile } | |
1469 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1470 | if "FAIL" in hapd.request("SET wpa_psk_file /tmp/does/not/exists/ap_wps_per_enrollee_psk_failure.psk_file"): | |
1471 | raise Exception("Failed to set wpa_psk_file") | |
1472 | ||
1473 | logger.info("First enrollee") | |
1474 | hapd.request("WPS_PBC") | |
33d0b157 JM |
1475 | dev[0].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1476 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 1477 | dev[0].wait_connected(timeout=30) |
373cce55 JM |
1478 | |
1479 | logger.info("Second enrollee") | |
1480 | hapd.request("WPS_PBC") | |
33d0b157 JM |
1481 | dev[1].scan_for_bss(apdev[0]['bssid'], freq=2412) |
1482 | dev[1].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 1483 | dev[1].wait_connected(timeout=30) |
373cce55 JM |
1484 | |
1485 | logger.info("External registrar") | |
33d0b157 | 1486 | dev[2].scan_for_bss(apdev[0]['bssid'], freq=2412) |
373cce55 JM |
1487 | dev[2].wps_reg(apdev[0]['bssid'], appin) |
1488 | ||
1489 | logger.info("Verifying PSK results") | |
1490 | psks = get_psk(pskfile) | |
1491 | if len(psks) > 0: | |
1492 | raise Exception("PSK recorded unexpectedly") | |
1493 | finally: | |
1494 | os.remove(pskfile) | |
1495 | ||
e8518757 JM |
1496 | def test_ap_wps_pin_request_file(dev, apdev): |
1497 | """WPS PIN provisioning with configured AP""" | |
1498 | ssid = "wps" | |
1499 | pinfile = "/tmp/ap_wps_pin_request_file.log" | |
1500 | if os.path.exists(pinfile): | |
1501 | subprocess.call(['sudo', 'rm', pinfile]) | |
1502 | hostapd.add_ap(apdev[0]['ifname'], | |
1503 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1504 | "wps_pin_requests": pinfile, | |
1505 | "wpa_passphrase": "12345678", "wpa": "2", | |
1506 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
1507 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
1508 | uuid = dev[0].get_status_field("uuid") | |
1509 | pin = dev[0].wps_read_pin() | |
1510 | try: | |
33d0b157 JM |
1511 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
1512 | dev[0].request("WPS_PIN %s %s" % (apdev[0]['bssid'], pin)) | |
e8518757 JM |
1513 | ev = hapd.wait_event(["WPS-PIN-NEEDED"], timeout=15) |
1514 | if ev is None: | |
1515 | raise Exception("PIN needed event not shown") | |
1516 | if uuid not in ev: | |
1517 | raise Exception("UUID mismatch") | |
1518 | dev[0].request("WPS_CANCEL") | |
1519 | success = False | |
1520 | with open(pinfile, "r") as f: | |
1521 | lines = f.readlines() | |
1522 | for l in lines: | |
1523 | if uuid in l: | |
1524 | success = True | |
1525 | break | |
1526 | if not success: | |
1527 | raise Exception("PIN request entry not in the log file") | |
1528 | finally: | |
1529 | subprocess.call(['sudo', 'rm', pinfile]) | |
1530 | ||
56887c35 JM |
1531 | def test_ap_wps_auto_setup_with_config_file(dev, apdev): |
1532 | """WPS auto-setup with configuration file""" | |
1533 | conffile = "/tmp/ap_wps_auto_setup_with_config_file.conf" | |
1534 | ifname = apdev[0]['ifname'] | |
1535 | try: | |
1536 | with open(conffile, "w") as f: | |
1537 | f.write("driver=nl80211\n") | |
1538 | f.write("hw_mode=g\n") | |
1539 | f.write("channel=1\n") | |
1540 | f.write("ieee80211n=1\n") | |
1541 | f.write("interface=%s\n" % ifname) | |
1542 | f.write("ctrl_interface=/var/run/hostapd\n") | |
1543 | f.write("ssid=wps\n") | |
1544 | f.write("eap_server=1\n") | |
1545 | f.write("wps_state=1\n") | |
1546 | hostapd.add_bss('phy3', ifname, conffile) | |
1547 | hapd = hostapd.Hostapd(ifname) | |
1548 | hapd.request("WPS_PBC") | |
33d0b157 JM |
1549 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
1550 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
5f35a5e2 | 1551 | dev[0].wait_connected(timeout=30) |
56887c35 JM |
1552 | with open(conffile, "r") as f: |
1553 | lines = f.read().splitlines() | |
1554 | vals = dict() | |
1555 | for l in lines: | |
1556 | try: | |
1557 | [name,value] = l.split('=', 1) | |
1558 | vals[name] = value | |
1559 | except ValueError, e: | |
1560 | if "# WPS configuration" in l: | |
1561 | pass | |
1562 | else: | |
1563 | raise Exception("Unexpected configuration line: " + l) | |
1564 | if vals['ieee80211n'] != '1' or vals['wps_state'] != '2' or "WPA-PSK" not in vals['wpa_key_mgmt']: | |
1565 | raise Exception("Incorrect configuration: " + str(vals)) | |
1566 | finally: | |
1567 | subprocess.call(['sudo', 'rm', conffile]) | |
1568 | ||
91f3cf69 JM |
1569 | def test_ap_wps_pbc_timeout(dev, apdev, params): |
1570 | """wpa_supplicant PBC walk time [long]""" | |
1571 | if not params['long']: | |
1572 | logger.info("Skip test case with long duration due to --long not specified") | |
1573 | return "skip" | |
1574 | ssid = "test-wps" | |
1575 | hostapd.add_ap(apdev[0]['ifname'], | |
1576 | { "ssid": ssid, "eap_server": "1", "wps_state": "1" }) | |
1577 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
1578 | logger.info("Start WPS_PBC and wait for PBC walk time expiration") | |
1579 | if "OK" not in dev[0].request("WPS_PBC"): | |
1580 | raise Exception("WPS_PBC failed") | |
1581 | ev = dev[0].wait_event(["WPS-TIMEOUT"], timeout=150) | |
1582 | if ev is None: | |
1583 | raise Exception("WPS-TIMEOUT not reported") | |
1584 | ||
44ff0400 JM |
1585 | def add_ssdp_ap(ifname, ap_uuid): |
1586 | ssid = "wps-ssdp" | |
1587 | ap_pin = "12345670" | |
1588 | hostapd.add_ap(ifname, | |
1589 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
1590 | "wpa_passphrase": "12345678", "wpa": "2", | |
1591 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP", | |
1592 | "device_name": "Wireless AP", "manufacturer": "Company", | |
1593 | "model_name": "WAP", "model_number": "123", | |
1594 | "serial_number": "12345", "device_type": "6-0050F204-1", | |
1595 | "os_version": "01020300", | |
1596 | "config_methods": "label push_button", | |
1597 | "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo", | |
1598 | "friendly_name": "WPS Access Point", | |
1599 | "manufacturer_url": "http://www.example.com/", | |
1600 | "model_description": "Wireless Access Point", | |
1601 | "model_url": "http://www.example.com/model/", | |
1602 | "upc": "123456789012" }) | |
1603 | ||
1604 | def ssdp_send(msg, no_recv=False): | |
1605 | socket.setdefaulttimeout(1) | |
1606 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
1607 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
1608 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) | |
1609 | sock.bind(("127.0.0.1", 0)) | |
1610 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
1611 | if no_recv: | |
1612 | return None | |
1613 | return sock.recv(1000) | |
1614 | ||
1615 | def ssdp_send_msearch(st): | |
1616 | msg = '\r\n'.join([ | |
1617 | 'M-SEARCH * HTTP/1.1', | |
1618 | 'HOST: 239.255.255.250:1900', | |
1619 | 'MX: 1', | |
1620 | 'MAN: "ssdp:discover"', | |
1621 | 'ST: ' + st, | |
1622 | '', '']) | |
47c549fd | 1623 | return ssdp_send(msg) |
44ff0400 JM |
1624 | |
1625 | def test_ap_wps_ssdp_msearch(dev, apdev): | |
1626 | """WPS AP and SSDP M-SEARCH messages""" | |
1627 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
1628 | add_ssdp_ap(apdev[0]['ifname'], ap_uuid) | |
1629 | ||
1630 | msg = '\r\n'.join([ | |
1631 | 'M-SEARCH * HTTP/1.1', | |
1632 | 'Host: 239.255.255.250:1900', | |
1633 | 'Mx: 1', | |
1634 | 'Man: "ssdp:discover"', | |
1635 | 'St: urn:schemas-wifialliance-org:device:WFADevice:1', | |
1636 | '', '']) | |
1637 | ssdp_send(msg) | |
1638 | ||
1639 | msg = '\r\n'.join([ | |
1640 | 'M-SEARCH * HTTP/1.1', | |
1641 | 'host:\t239.255.255.250:1900\t\t\t\t \t\t', | |
1642 | 'mx: \t1\t\t ', | |
1643 | 'man: \t \t "ssdp:discover" ', | |
1644 | 'st: urn:schemas-wifialliance-org:device:WFADevice:1\t\t', | |
1645 | '', '']) | |
1646 | ssdp_send(msg) | |
1647 | ||
1648 | ssdp_send_msearch("ssdp:all") | |
1649 | ssdp_send_msearch("upnp:rootdevice") | |
1650 | ssdp_send_msearch("uuid:" + ap_uuid) | |
1651 | ssdp_send_msearch("urn:schemas-wifialliance-org:service:WFAWLANConfig:1") | |
1652 | ssdp_send_msearch("urn:schemas-wifialliance-org:device:WFADevice:1"); | |
1653 | ||
1654 | msg = '\r\n'.join([ | |
1655 | 'M-SEARCH * HTTP/1.1', | |
1656 | 'HOST:\t239.255.255.250:1900', | |
1657 | 'MAN: "ssdp:discover"', | |
1658 | 'MX: 130', | |
1659 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
1660 | '', '']) | |
1661 | ssdp_send(msg, no_recv=True) | |
1662 | ||
1663 | def test_ap_wps_ssdp_invalid_msearch(dev, apdev): | |
1664 | """WPS AP and invalid SSDP M-SEARCH messages""" | |
1665 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
1666 | add_ssdp_ap(apdev[0]['ifname'], ap_uuid) | |
1667 | ||
1668 | socket.setdefaulttimeout(1) | |
1669 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
1670 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
1671 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) | |
1672 | sock.bind(("127.0.0.1", 0)) | |
1673 | ||
1674 | logger.debug("Missing MX") | |
1675 | msg = '\r\n'.join([ | |
1676 | 'M-SEARCH * HTTP/1.1', | |
1677 | 'HOST: 239.255.255.250:1900', | |
1678 | 'MAN: "ssdp:discover"', | |
1679 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
1680 | '', '']) | |
1681 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
1682 | ||
1683 | logger.debug("Negative MX") | |
1684 | msg = '\r\n'.join([ | |
1685 | 'M-SEARCH * HTTP/1.1', | |
1686 | 'HOST: 239.255.255.250:1900', | |
1687 | 'MX: -1', | |
1688 | 'MAN: "ssdp:discover"', | |
1689 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
1690 | '', '']) | |
1691 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
1692 | ||
1693 | logger.debug("Invalid MX") | |
1694 | msg = '\r\n'.join([ | |
1695 | 'M-SEARCH * HTTP/1.1', | |
1696 | 'HOST: 239.255.255.250:1900', | |
1697 | 'MX; 1', | |
1698 | 'MAN: "ssdp:discover"', | |
1699 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
1700 | '', '']) | |
1701 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
1702 | ||
1703 | logger.debug("Missing MAN") | |
1704 | msg = '\r\n'.join([ | |
1705 | 'M-SEARCH * HTTP/1.1', | |
1706 | 'HOST: 239.255.255.250:1900', | |
1707 | 'MX: 1', | |
1708 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
1709 | '', '']) | |
1710 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
1711 | ||
1712 | logger.debug("Invalid MAN") | |
1713 | msg = '\r\n'.join([ | |
1714 | 'M-SEARCH * HTTP/1.1', | |
1715 | 'HOST: 239.255.255.250:1900', | |
1716 | 'MX: 1', | |
1717 | 'MAN: foo', | |
1718 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
1719 | '', '']) | |
1720 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
1721 | msg = '\r\n'.join([ | |
1722 | 'M-SEARCH * HTTP/1.1', | |
1723 | 'HOST: 239.255.255.250:1900', | |
1724 | 'MX: 1', | |
1725 | 'MAN; "ssdp:discover"', | |
1726 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
1727 | '', '']) | |
1728 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
1729 | ||
1730 | logger.debug("Missing HOST") | |
1731 | msg = '\r\n'.join([ | |
1732 | 'M-SEARCH * HTTP/1.1', | |
1733 | 'MAN: "ssdp:discover"', | |
1734 | 'MX: 1', | |
1735 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
1736 | '', '']) | |
1737 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
1738 | ||
1739 | logger.debug("Missing ST") | |
1740 | msg = '\r\n'.join([ | |
1741 | 'M-SEARCH * HTTP/1.1', | |
1742 | 'HOST: 239.255.255.250:1900', | |
1743 | 'MAN: "ssdp:discover"', | |
1744 | 'MX: 1', | |
1745 | '', '']) | |
1746 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
1747 | ||
1748 | logger.debug("Mismatching ST") | |
1749 | msg = '\r\n'.join([ | |
1750 | 'M-SEARCH * HTTP/1.1', | |
1751 | 'HOST: 239.255.255.250:1900', | |
1752 | 'MAN: "ssdp:discover"', | |
1753 | 'MX: 1', | |
1754 | 'ST: uuid:16d5f8a9-4ee4-4f5e-81f9-cc6e2f47f42d', | |
1755 | '', '']) | |
1756 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
1757 | msg = '\r\n'.join([ | |
1758 | 'M-SEARCH * HTTP/1.1', | |
1759 | 'HOST: 239.255.255.250:1900', | |
1760 | 'MAN: "ssdp:discover"', | |
1761 | 'MX: 1', | |
1762 | 'ST: foo:bar', | |
1763 | '', '']) | |
1764 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
1765 | msg = '\r\n'.join([ | |
1766 | 'M-SEARCH * HTTP/1.1', | |
1767 | 'HOST: 239.255.255.250:1900', | |
1768 | 'MAN: "ssdp:discover"', | |
1769 | 'MX: 1', | |
1770 | 'ST: foobar', | |
1771 | '', '']) | |
1772 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
1773 | ||
1774 | logger.debug("Invalid ST") | |
1775 | msg = '\r\n'.join([ | |
1776 | 'M-SEARCH * HTTP/1.1', | |
1777 | 'HOST: 239.255.255.250:1900', | |
1778 | 'MAN: "ssdp:discover"', | |
1779 | 'MX: 1', | |
1780 | 'ST; urn:schemas-wifialliance-org:device:WFADevice:1', | |
1781 | '', '']) | |
1782 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
1783 | ||
1784 | logger.debug("Invalid M-SEARCH") | |
1785 | msg = '\r\n'.join([ | |
1786 | 'M+SEARCH * HTTP/1.1', | |
1787 | 'HOST: 239.255.255.250:1900', | |
1788 | 'MAN: "ssdp:discover"', | |
1789 | 'MX: 1', | |
1790 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
1791 | '', '']) | |
1792 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
1793 | msg = '\r\n'.join([ | |
1794 | 'M-SEARCH-* HTTP/1.1', | |
1795 | 'HOST: 239.255.255.250:1900', | |
1796 | 'MAN: "ssdp:discover"', | |
1797 | 'MX: 1', | |
1798 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
1799 | '', '']) | |
1800 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
1801 | ||
1802 | logger.debug("Invalid message format") | |
1803 | sock.sendto("NOTIFY * HTTP/1.1", ("239.255.255.250", 1900)) | |
1804 | msg = '\r'.join([ | |
1805 | 'M-SEARCH * HTTP/1.1', | |
1806 | 'HOST: 239.255.255.250:1900', | |
1807 | 'MAN: "ssdp:discover"', | |
1808 | 'MX: 1', | |
1809 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
1810 | '', '']) | |
1811 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
1812 | ||
1813 | try: | |
1814 | r = sock.recv(1000) | |
1815 | raise Exception("Unexpected M-SEARCH response: " + r) | |
1816 | except socket.timeout: | |
1817 | pass | |
1818 | ||
1819 | logger.debug("Valid M-SEARCH") | |
1820 | msg = '\r\n'.join([ | |
1821 | 'M-SEARCH * HTTP/1.1', | |
1822 | 'HOST: 239.255.255.250:1900', | |
1823 | 'MAN: "ssdp:discover"', | |
1824 | 'MX: 1', | |
1825 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
1826 | '', '']) | |
1827 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
1828 | ||
1829 | try: | |
1830 | r = sock.recv(1000) | |
1831 | pass | |
1832 | except socket.timeout: | |
1833 | raise Exception("No SSDP response") | |
1834 | ||
1835 | def test_ap_wps_ssdp_burst(dev, apdev): | |
1836 | """WPS AP and SSDP burst""" | |
1837 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
1838 | add_ssdp_ap(apdev[0]['ifname'], ap_uuid) | |
1839 | ||
1840 | msg = '\r\n'.join([ | |
1841 | 'M-SEARCH * HTTP/1.1', | |
1842 | 'HOST: 239.255.255.250:1900', | |
1843 | 'MAN: "ssdp:discover"', | |
1844 | 'MX: 1', | |
1845 | 'ST: urn:schemas-wifialliance-org:device:WFADevice:1', | |
1846 | '', '']) | |
1847 | socket.setdefaulttimeout(1) | |
1848 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
1849 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
1850 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) | |
1851 | sock.bind(("127.0.0.1", 0)) | |
1852 | for i in range(0, 25): | |
1853 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
1854 | resp = 0 | |
1855 | while True: | |
1856 | try: | |
1857 | r = sock.recv(1000) | |
1858 | if not r.startswith("HTTP/1.1 200 OK\r\n"): | |
1859 | raise Exception("Unexpected message: " + r) | |
1860 | resp += 1 | |
1861 | except socket.timeout: | |
1862 | break | |
1863 | if resp < 20: | |
1864 | raise Exception("Too few SSDP responses") | |
1865 | ||
1866 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
1867 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
1868 | sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) | |
1869 | sock.bind(("127.0.0.1", 0)) | |
1870 | for i in range(0, 25): | |
1871 | sock.sendto(msg, ("239.255.255.250", 1900)) | |
1872 | while True: | |
1873 | try: | |
1874 | r = sock.recv(1000) | |
1875 | if ap_uuid in r: | |
1876 | break | |
1877 | except socket.timeout: | |
1878 | raise Exception("No SSDP response") | |
47c549fd JM |
1879 | |
1880 | def ssdp_get_location(uuid): | |
1881 | res = ssdp_send_msearch("uuid:" + uuid) | |
1882 | location = None | |
1883 | for l in res.splitlines(): | |
1884 | if l.lower().startswith("location:"): | |
1885 | location = l.split(':', 1)[1].strip() | |
1886 | break | |
1887 | if location is None: | |
1888 | raise Exception("No UPnP location found") | |
1889 | return location | |
1890 | ||
1891 | def upnp_get_urls(location): | |
1892 | conn = urllib.urlopen(location) | |
1893 | tree = ET.parse(conn) | |
1894 | root = tree.getroot() | |
1895 | urn = '{urn:schemas-upnp-org:device-1-0}' | |
1896 | service = root.find("./" + urn + "device/" + urn + "serviceList/" + urn + "service") | |
1897 | res = {} | |
1898 | res['scpd_url'] = urlparse.urljoin(location, service.find(urn + 'SCPDURL').text) | |
1899 | res['control_url'] = urlparse.urljoin(location, service.find(urn + 'controlURL').text) | |
1900 | res['event_sub_url'] = urlparse.urljoin(location, service.find(urn + 'eventSubURL').text) | |
1901 | return res | |
1902 | ||
1903 | def upnp_soap_action(conn, path, action, include_soap_action=True, soap_action_override=None): | |
1904 | soapns = 'http://schemas.xmlsoap.org/soap/envelope/' | |
1905 | wpsns = 'urn:schemas-wifialliance-org:service:WFAWLANConfig:1' | |
1906 | ET.register_namespace('soapenv', soapns) | |
1907 | ET.register_namespace('wfa', wpsns) | |
1908 | attrib = {} | |
1909 | attrib['{%s}encodingStyle' % soapns] = 'http://schemas.xmlsoap.org/soap/encoding/' | |
1910 | root = ET.Element("{%s}Envelope" % soapns, attrib=attrib) | |
1911 | body = ET.SubElement(root, "{%s}Body" % soapns) | |
1912 | act = ET.SubElement(body, "{%s}%s" % (wpsns, action)) | |
1913 | tree = ET.ElementTree(root) | |
1914 | soap = StringIO.StringIO() | |
1915 | tree.write(soap, xml_declaration=True, encoding='utf-8') | |
1916 | ||
1917 | headers = { "Content-type": 'text/xml; charset="utf-8"' } | |
1918 | if include_soap_action: | |
1919 | headers["SOAPAction"] = '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#%s"' % action | |
1920 | elif soap_action_override: | |
1921 | headers["SOAPAction"] = soap_action_override | |
1922 | conn.request("POST", path, soap.getvalue(), headers) | |
1923 | return conn.getresponse() | |
1924 | ||
1925 | def test_ap_wps_upnp(dev, apdev): | |
1926 | """WPS AP and UPnP operations""" | |
1927 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
1928 | add_ssdp_ap(apdev[0]['ifname'], ap_uuid) | |
1929 | ||
1930 | location = ssdp_get_location(ap_uuid) | |
1931 | urls = upnp_get_urls(location) | |
1932 | ||
1933 | conn = urllib.urlopen(urls['scpd_url']) | |
1934 | scpd = conn.read() | |
1935 | ||
1936 | conn = urllib.urlopen(urlparse.urljoin(location, "unknown.html")) | |
1937 | if conn.getcode() != 404: | |
1938 | raise Exception("Unexpected HTTP response to GET unknown URL") | |
1939 | ||
1940 | url = urlparse.urlparse(location) | |
1941 | conn = httplib.HTTPConnection(url.netloc) | |
1942 | #conn.set_debuglevel(1) | |
1943 | headers = { "Content-type": 'text/xml; charset="utf-8"', | |
1944 | "SOAPAction": '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#GetDeviceInfo"' } | |
1945 | conn.request("POST", "hello", "\r\n\r\n", headers) | |
1946 | resp = conn.getresponse() | |
1947 | if resp.status != 404: | |
1948 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
1949 | ||
1950 | conn.request("UNKNOWN", "hello", "\r\n\r\n", headers) | |
1951 | resp = conn.getresponse() | |
1952 | if resp.status != 501: | |
1953 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
1954 | ||
1955 | headers = { "Content-type": 'text/xml; charset="utf-8"', | |
1956 | "SOAPAction": '"urn:some-unknown-action#GetDeviceInfo"' } | |
1957 | ctrlurl = urlparse.urlparse(urls['control_url']) | |
1958 | conn.request("POST", ctrlurl.path, "\r\n\r\n", headers) | |
1959 | resp = conn.getresponse() | |
1960 | if resp.status != 401: | |
1961 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
1962 | ||
1963 | logger.debug("GetDeviceInfo without SOAPAction header") | |
1964 | resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo", | |
1965 | include_soap_action=False) | |
1966 | if resp.status != 401: | |
1967 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
1968 | ||
1969 | logger.debug("GetDeviceInfo with invalid SOAPAction header") | |
1970 | for act in [ "foo", | |
1971 | "urn:schemas-wifialliance-org:service:WFAWLANConfig:1#GetDeviceInfo", | |
1972 | '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1"', | |
1973 | '"urn:schemas-wifialliance-org:service:WFAWLANConfig:123#GetDevice']: | |
1974 | resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo", | |
1975 | include_soap_action=False, | |
1976 | soap_action_override=act) | |
1977 | if resp.status != 401: | |
1978 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
1979 | ||
1980 | resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo") | |
1981 | if resp.status != 200: | |
1982 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
1983 | dev = resp.read() | |
1984 | if "NewDeviceInfo" not in dev: | |
1985 | raise Exception("Unexpected GetDeviceInfo response") | |
1986 | ||
1987 | logger.debug("PutMessage without required parameters") | |
1988 | resp = upnp_soap_action(conn, ctrlurl.path, "PutMessage") | |
1989 | if resp.status != 600: | |
1990 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
1991 | ||
1992 | logger.debug("PutWLANResponse without required parameters") | |
1993 | resp = upnp_soap_action(conn, ctrlurl.path, "PutWLANResponse") | |
1994 | if resp.status != 600: | |
1995 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
1996 | ||
1997 | logger.debug("SetSelectedRegistrar from unregistered ER") | |
1998 | resp = upnp_soap_action(conn, ctrlurl.path, "SetSelectedRegistrar") | |
1999 | if resp.status != 501: | |
2000 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2001 | ||
2002 | logger.debug("Unknown action") | |
2003 | resp = upnp_soap_action(conn, ctrlurl.path, "Unknown") | |
2004 | if resp.status != 401: | |
2005 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2006 | ||
2007 | def test_ap_wps_upnp_subscribe(dev, apdev): | |
2008 | """WPS AP and UPnP event subscription""" | |
2009 | ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e" | |
2010 | add_ssdp_ap(apdev[0]['ifname'], ap_uuid) | |
2011 | ||
2012 | location = ssdp_get_location(ap_uuid) | |
2013 | urls = upnp_get_urls(location) | |
2014 | eventurl = urlparse.urlparse(urls['event_sub_url']) | |
2015 | ||
2016 | url = urlparse.urlparse(location) | |
2017 | conn = httplib.HTTPConnection(url.netloc) | |
2018 | #conn.set_debuglevel(1) | |
2019 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
2020 | "timeout": "Second-1234" } | |
2021 | conn.request("SUBSCRIBE", "hello", "\r\n\r\n", headers) | |
2022 | resp = conn.getresponse() | |
2023 | if resp.status != 412: | |
2024 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2025 | ||
2026 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2027 | resp = conn.getresponse() | |
2028 | if resp.status != 412: | |
2029 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2030 | ||
2031 | headers = { "NT": "upnp:event", | |
2032 | "timeout": "Second-1234" } | |
2033 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2034 | resp = conn.getresponse() | |
2035 | if resp.status != 412: | |
2036 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2037 | ||
2038 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
2039 | "NT": "upnp:foobar", | |
2040 | "timeout": "Second-1234" } | |
2041 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2042 | resp = conn.getresponse() | |
2043 | if resp.status != 400: | |
2044 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2045 | ||
2046 | logger.debug("Valid subscription") | |
2047 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
2048 | "NT": "upnp:event", | |
2049 | "timeout": "Second-1234" } | |
2050 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2051 | resp = conn.getresponse() | |
2052 | if resp.status != 200: | |
2053 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2054 | sid = resp.getheader("sid") | |
2055 | logger.debug("Subscription SID " + sid) | |
2056 | ||
2057 | logger.debug("Invalid re-subscription") | |
2058 | headers = { "NT": "upnp:event", | |
2059 | "sid": "123456734567854", | |
2060 | "timeout": "Second-1234" } | |
2061 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2062 | resp = conn.getresponse() | |
2063 | if resp.status != 400: | |
2064 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2065 | ||
2066 | logger.debug("Invalid re-subscription") | |
2067 | headers = { "NT": "upnp:event", | |
2068 | "sid": "uuid:123456734567854", | |
2069 | "timeout": "Second-1234" } | |
2070 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2071 | resp = conn.getresponse() | |
2072 | if resp.status != 400: | |
2073 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2074 | ||
2075 | logger.debug("Invalid re-subscription") | |
2076 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
2077 | "NT": "upnp:event", | |
2078 | "sid": sid, | |
2079 | "timeout": "Second-1234" } | |
2080 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2081 | resp = conn.getresponse() | |
2082 | if resp.status != 400: | |
2083 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2084 | ||
2085 | logger.debug("SID mismatch in re-subscription") | |
2086 | headers = { "NT": "upnp:event", | |
2087 | "sid": "uuid:4c2bca79-1ff4-4e43-85d4-952a2b8a51fb", | |
2088 | "timeout": "Second-1234" } | |
2089 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2090 | resp = conn.getresponse() | |
2091 | if resp.status != 412: | |
2092 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2093 | ||
2094 | logger.debug("Valid re-subscription") | |
2095 | headers = { "NT": "upnp:event", | |
2096 | "sid": sid, | |
2097 | "timeout": "Second-1234" } | |
2098 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2099 | resp = conn.getresponse() | |
2100 | if resp.status != 200: | |
2101 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2102 | sid2 = resp.getheader("sid") | |
2103 | logger.debug("Subscription SID " + sid2) | |
2104 | ||
2105 | if sid != sid2: | |
2106 | raise Exception("Unexpected SID change") | |
2107 | ||
2108 | logger.debug("Valid re-subscription") | |
2109 | headers = { "NT": "upnp:event", | |
2110 | "sid": "uuid: \t \t" + sid.split(':')[1], | |
2111 | "timeout": "Second-1234" } | |
2112 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2113 | resp = conn.getresponse() | |
2114 | if resp.status != 200: | |
2115 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2116 | ||
2117 | logger.debug("Invalid unsubscription") | |
2118 | headers = { "sid": sid } | |
2119 | conn.request("UNSUBSCRIBE", "/hello", "\r\n\r\n", headers) | |
2120 | resp = conn.getresponse() | |
2121 | if resp.status != 412: | |
2122 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2123 | headers = { "foo": "bar" } | |
2124 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2125 | resp = conn.getresponse() | |
2126 | if resp.status != 412: | |
2127 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2128 | ||
2129 | logger.debug("Valid unsubscription") | |
2130 | headers = { "sid": sid } | |
2131 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2132 | resp = conn.getresponse() | |
2133 | if resp.status != 200: | |
2134 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2135 | ||
2136 | logger.debug("Unsubscription for not existing SID") | |
2137 | headers = { "sid": sid } | |
2138 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2139 | resp = conn.getresponse() | |
2140 | if resp.status != 412: | |
2141 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2142 | ||
2143 | logger.debug("Invalid unsubscription") | |
2144 | headers = { "sid": " \t \tfoo" } | |
2145 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2146 | resp = conn.getresponse() | |
2147 | if resp.status != 400: | |
2148 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2149 | ||
2150 | logger.debug("Invalid unsubscription") | |
2151 | headers = { "sid": "uuid:\t \tfoo" } | |
2152 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2153 | resp = conn.getresponse() | |
2154 | if resp.status != 400: | |
2155 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2156 | ||
2157 | logger.debug("Invalid unsubscription") | |
2158 | headers = { "NT": "upnp:event", | |
2159 | "sid": sid } | |
2160 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2161 | resp = conn.getresponse() | |
2162 | if resp.status != 400: | |
2163 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2164 | headers = { "callback": '<http://127.0.0.1:12345/event>', | |
2165 | "sid": sid } | |
2166 | conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2167 | resp = conn.getresponse() | |
2168 | if resp.status != 400: | |
2169 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2170 | ||
2171 | logger.debug("Valid subscription with multiple callbacks") | |
2172 | headers = { "callback": '<http://127.0.0.1:12345/event> <http://127.0.0.1:12345/event>\t<http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event><http://127.0.0.1:12345/event>', | |
2173 | "NT": "upnp:event", | |
2174 | "timeout": "Second-1234" } | |
2175 | conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers) | |
2176 | resp = conn.getresponse() | |
2177 | if resp.status != 200: | |
2178 | raise Exception("Unexpected HTTP response: %s" % resp.status) | |
2179 | sid = resp.getheader("sid") | |
2180 | logger.debug("Subscription SID " + sid) | |
d352c407 JM |
2181 | |
2182 | def test_ap_wps_disabled(dev, apdev): | |
2183 | """WPS operations while WPS is disabled""" | |
2184 | ssid = "test-wps-disabled" | |
2185 | hostapd.add_ap(apdev[0]['ifname'], { "ssid": ssid }) | |
2186 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
2187 | if "FAIL" not in hapd.request("WPS_PBC"): | |
2188 | raise Exception("WPS_PBC succeeded unexpectedly") | |
2189 | if "FAIL" not in hapd.request("WPS_CANCEL"): | |
2190 | raise Exception("WPS_CANCEL succeeded unexpectedly") | |
a0fd2ae6 JM |
2191 | |
2192 | def test_ap_wps_mixed_cred(dev, apdev): | |
2193 | """WPS 2.0 STA merging mixed mode WPA/WPA2 credentials""" | |
2194 | ssid = "test-wps-wep" | |
2195 | hostapd.add_ap(apdev[0]['ifname'], | |
2196 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
2197 | "skip_cred_build": "1", "extra_cred": "wps-mixed-cred" }) | |
2198 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
2199 | hapd.request("WPS_PBC") | |
33d0b157 JM |
2200 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
2201 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
9ed53f5e | 2202 | ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=30) |
a0fd2ae6 JM |
2203 | if ev is None: |
2204 | raise Exception("WPS-SUCCESS event timed out") | |
2205 | nets = dev[0].list_networks() | |
2206 | if len(nets) != 1: | |
2207 | raise Exception("Unexpected number of network blocks") | |
2208 | id = nets[0]['id'] | |
2209 | proto = dev[0].get_network(id, "proto") | |
2210 | if proto != "WPA RSN": | |
2211 | raise Exception("Unexpected merged proto field value: " + proto) | |
2212 | pairwise = dev[0].get_network(id, "pairwise") | |
72a8e30b | 2213 | if pairwise != "CCMP TKIP" and pairwise != "CCMP GCMP TKIP": |
a0fd2ae6 | 2214 | raise Exception("Unexpected merged pairwise field value: " + pairwise) |
e5a79e3f JM |
2215 | |
2216 | def test_ap_wps_while_connected(dev, apdev): | |
2217 | """WPS PBC provisioning while connected to another AP""" | |
2218 | ssid = "test-wps-conf" | |
2219 | hostapd.add_ap(apdev[0]['ifname'], | |
2220 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
2221 | "wpa_passphrase": "12345678", "wpa": "2", | |
2222 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
2223 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
2224 | ||
2225 | hostapd.add_ap(apdev[1]['ifname'], { "ssid": "open" }) | |
2226 | dev[0].connect("open", key_mgmt="NONE", scan_freq="2412") | |
2227 | ||
2228 | logger.info("WPS provisioning step") | |
2229 | hapd.request("WPS_PBC") | |
2230 | dev[0].dump_monitor() | |
33d0b157 | 2231 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 2232 | dev[0].wait_connected(timeout=30) |
e5a79e3f JM |
2233 | status = dev[0].get_status() |
2234 | if status['bssid'] != apdev[0]['bssid']: | |
2235 | raise Exception("Unexpected BSSID") | |
2236 | ||
2237 | def test_ap_wps_while_connected_no_autoconnect(dev, apdev): | |
2238 | """WPS PBC provisioning while connected to another AP and STA_AUTOCONNECT disabled""" | |
2239 | ssid = "test-wps-conf" | |
2240 | hostapd.add_ap(apdev[0]['ifname'], | |
2241 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
2242 | "wpa_passphrase": "12345678", "wpa": "2", | |
2243 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
2244 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
2245 | ||
2246 | hostapd.add_ap(apdev[1]['ifname'], { "ssid": "open" }) | |
2247 | ||
2248 | try: | |
2249 | dev[0].request("STA_AUTOCONNECT 0") | |
2250 | dev[0].connect("open", key_mgmt="NONE", scan_freq="2412") | |
2251 | ||
2252 | logger.info("WPS provisioning step") | |
2253 | hapd.request("WPS_PBC") | |
2254 | dev[0].dump_monitor() | |
33d0b157 | 2255 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) |
5f35a5e2 | 2256 | dev[0].wait_connected(timeout=30) |
e5a79e3f JM |
2257 | status = dev[0].get_status() |
2258 | if status['bssid'] != apdev[0]['bssid']: | |
2259 | raise Exception("Unexpected BSSID") | |
2260 | finally: | |
2261 | dev[0].request("STA_AUTOCONNECT 1") | |
3f08d1cd JM |
2262 | |
2263 | def test_ap_wps_from_event(dev, apdev): | |
2264 | """WPS PBC event on AP to enable PBC""" | |
2265 | ssid = "test-wps-conf" | |
2266 | hapd = hostapd.add_ap(apdev[0]['ifname'], | |
2267 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
2268 | "wpa_passphrase": "12345678", "wpa": "2", | |
2269 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
33d0b157 | 2270 | dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412") |
3f08d1cd | 2271 | dev[0].dump_monitor() |
33d0b157 JM |
2272 | hapd.dump_monitor() |
2273 | dev[0].request("WPS_PBC " + apdev[0]['bssid']) | |
3f08d1cd JM |
2274 | |
2275 | ev = hapd.wait_event(['WPS-ENROLLEE-SEEN'], timeout=15) | |
2276 | if ev is None: | |
2277 | raise Exception("No WPS-ENROLLEE-SEEN event on AP") | |
2278 | vals = ev.split(' ') | |
2279 | if vals[1] != dev[0].p2p_interface_addr(): | |
2280 | raise Exception("Unexpected enrollee address: " + vals[1]) | |
2281 | if vals[5] != '4': | |
2282 | raise Exception("Unexpected Device Password Id: " + vals[5]) | |
2283 | hapd.request("WPS_PBC") | |
5f35a5e2 | 2284 | dev[0].wait_connected(timeout=30) |
1531402e JM |
2285 | |
2286 | def test_ap_wps_ap_scan_2(dev, apdev): | |
2287 | """AP_SCAN 2 for WPS""" | |
2288 | ssid = "test-wps-conf" | |
2289 | hapd = hostapd.add_ap(apdev[0]['ifname'], | |
2290 | { "ssid": ssid, "eap_server": "1", "wps_state": "2", | |
2291 | "wpa_passphrase": "12345678", "wpa": "2", | |
2292 | "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}) | |
2293 | hapd.request("WPS_PBC") | |
2294 | ||
2295 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
2296 | wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") | |
2297 | ||
2298 | if "OK" not in wpas.request("AP_SCAN 2"): | |
2299 | raise Exception("Failed to set AP_SCAN 2") | |
2300 | ||
33d0b157 JM |
2301 | wpas.scan_for_bss(apdev[0]['bssid'], freq="2412") |
2302 | wpas.request("WPS_PBC " + apdev[0]['bssid']) | |
1531402e JM |
2303 | ev = wpas.wait_event(["WPS-SUCCESS"], timeout=15) |
2304 | if ev is None: | |
2305 | raise Exception("WPS-SUCCESS event timed out") | |
5f35a5e2 | 2306 | wpas.wait_connected(timeout=30) |
1531402e JM |
2307 | wpas.request("DISCONNECT") |
2308 | wpas.request("BSS_FLUSH 0") | |
2309 | wpas.dump_monitor() | |
2310 | wpas.request("REASSOCIATE") | |
5f35a5e2 | 2311 | wpas.wait_connected(timeout=30) |