]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_ap_wps.py
2 # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
11 logger
= logging
.getLogger()
17 import xml
.etree
.ElementTree
as ET
23 def test_ap_wps_init(dev
, apdev
):
24 """Initial AP configuration with first WPS Enrollee"""
26 hostapd
.add_ap(apdev
[0]['ifname'],
27 { "ssid": ssid
, "eap_server": "1", "wps_state": "1" })
28 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
29 logger
.info("WPS provisioning step")
30 hapd
.request("WPS_PBC")
31 if "PBC Status: Active" not in hapd
.request("WPS_GET_STATUS"):
32 raise Exception("PBC status not shown correctly")
34 id = dev
[0].add_network()
35 dev
[0].set_network_quoted(id, "ssid", "home")
36 dev
[0].set_network_quoted(id, "psk", "12345678")
37 dev
[0].request("ENABLE_NETWORK %s no-connect" % id)
39 id = dev
[0].add_network()
40 dev
[0].set_network_quoted(id, "ssid", "home2")
41 dev
[0].set_network(id, "bssid", "00:11:22:33:44:55")
42 dev
[0].set_network(id, "key_mgmt", "NONE")
43 dev
[0].request("ENABLE_NETWORK %s no-connect" % id)
45 dev
[0].request("WPS_PBC")
46 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
48 raise Exception("Association with the AP timed out")
49 status
= dev
[0].get_status()
50 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
51 raise Exception("Not fully connected")
52 if status
['ssid'] != ssid
:
53 raise Exception("Unexpected SSID")
54 if status
['pairwise_cipher'] != 'CCMP':
55 raise Exception("Unexpected encryption configuration")
56 if status
['key_mgmt'] != 'WPA2-PSK':
57 raise Exception("Unexpected key_mgmt")
59 status
= hapd
.request("WPS_GET_STATUS")
60 if "PBC Status: Disabled" not in status
:
61 raise Exception("PBC status not shown correctly")
62 if "Last WPS result: Success" not in status
:
63 raise Exception("Last WPS result not shown correctly")
64 if "Peer Address: " + dev
[0].p2p_interface_addr() not in status
:
65 raise Exception("Peer address not shown correctly")
66 conf
= hapd
.request("GET_CONFIG")
67 if "wps_state=configured" not in conf
:
68 raise Exception("AP not in WPS configured state")
69 if "rsn_pairwise_cipher=CCMP TKIP" not in conf
:
70 raise Exception("Unexpected rsn_pairwise_cipher")
71 if "wpa_pairwise_cipher=CCMP TKIP" not in conf
:
72 raise Exception("Unexpected wpa_pairwise_cipher")
73 if "group_cipher=TKIP" not in conf
:
74 raise Exception("Unexpected group_cipher")
76 if len(dev
[0].list_networks()) != 3:
77 raise Exception("Unexpected number of network blocks")
79 def test_ap_wps_init_2ap_pbc(dev
, apdev
):
80 """Initial two-radio AP configuration with first WPS PBC Enrollee"""
82 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "1" }
83 hostapd
.add_ap(apdev
[0]['ifname'], params
)
84 hostapd
.add_ap(apdev
[1]['ifname'], params
)
85 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
86 logger
.info("WPS provisioning step")
87 hapd
.request("WPS_PBC")
88 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="2412", force_scan
=True)
89 dev
[0].scan_for_bss(apdev
[1]['bssid'], freq
="2412")
90 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
91 if "[WPS-PBC]" not in bss
['flags']:
92 raise Exception("WPS-PBC flag missing from AP1")
93 bss
= dev
[0].get_bss(apdev
[1]['bssid'])
94 if "[WPS-PBC]" not in bss
['flags']:
95 raise Exception("WPS-PBC flag missing from AP2")
97 dev
[0].request("SET wps_cred_processing 2")
98 dev
[0].request("WPS_PBC")
99 ev
= dev
[0].wait_event(["WPS-CRED-RECEIVED"], timeout
=30)
100 dev
[0].request("SET wps_cred_processing 0")
102 raise Exception("WPS cred event not seen")
104 raise Exception("WPS attributes not included in the cred event")
105 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
107 raise Exception("Association with the AP timed out")
109 dev
[1].scan_for_bss(apdev
[0]['bssid'], freq
="2412", force_scan
=True)
110 dev
[1].scan_for_bss(apdev
[1]['bssid'], freq
="2412")
111 bss
= dev
[1].get_bss(apdev
[0]['bssid'])
112 if "[WPS-PBC]" in bss
['flags']:
113 raise Exception("WPS-PBC flag not cleared from AP1")
114 bss
= dev
[1].get_bss(apdev
[1]['bssid'])
115 if "[WPS-PBC]" in bss
['flags']:
116 raise Exception("WPS-PBC flag not cleared from AP2")
118 def test_ap_wps_init_2ap_pin(dev
, apdev
):
119 """Initial two-radio AP configuration with first WPS PIN Enrollee"""
121 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "1" }
122 hostapd
.add_ap(apdev
[0]['ifname'], params
)
123 hostapd
.add_ap(apdev
[1]['ifname'], params
)
124 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
125 logger
.info("WPS provisioning step")
126 pin
= dev
[0].wps_read_pin()
127 hapd
.request("WPS_PIN any " + pin
)
128 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="2412", force_scan
=True)
129 dev
[0].scan_for_bss(apdev
[1]['bssid'], freq
="2412")
130 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
131 if "[WPS-AUTH]" not in bss
['flags']:
132 raise Exception("WPS-AUTH flag missing from AP1")
133 bss
= dev
[0].get_bss(apdev
[1]['bssid'])
134 if "[WPS-AUTH]" not in bss
['flags']:
135 raise Exception("WPS-AUTH flag missing from AP2")
136 dev
[0].dump_monitor()
137 dev
[0].request("WPS_PIN any " + pin
)
138 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
140 raise Exception("Association with the AP timed out")
142 dev
[1].scan_for_bss(apdev
[0]['bssid'], freq
="2412", force_scan
=True)
143 dev
[1].scan_for_bss(apdev
[1]['bssid'], freq
="2412")
144 bss
= dev
[1].get_bss(apdev
[0]['bssid'])
145 if "[WPS-AUTH]" in bss
['flags']:
146 raise Exception("WPS-AUTH flag not cleared from AP1")
147 bss
= dev
[1].get_bss(apdev
[1]['bssid'])
148 if "[WPS-AUTH]" in bss
['flags']:
149 raise Exception("WPS-AUTH flag not cleared from AP2")
151 def test_ap_wps_init_through_wps_config(dev
, apdev
):
152 """Initial AP configuration using wps_config command"""
153 ssid
= "test-wps-init-config"
154 hostapd
.add_ap(apdev
[0]['ifname'],
155 { "ssid": ssid
, "eap_server": "1", "wps_state": "1" })
156 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
157 if "FAIL" in hapd
.request("WPS_CONFIG " + ssid
.encode("hex") + " WPA2PSK CCMP " + "12345678".encode("hex")):
158 raise Exception("WPS_CONFIG command failed")
159 ev
= hapd
.wait_event(["WPS-NEW-AP-SETTINGS"], timeout
=5)
161 raise Exception("Timeout on WPS-NEW-AP-SETTINGS events")
162 # It takes some time for the AP to update Beacon and Probe Response frames,
163 # so wait here before requesting the scan to be started to avoid adding
164 # extra five second wait to the test due to fetching obsolete scan results.
167 dev
[0].connect(ssid
, psk
="12345678", scan_freq
="2412", proto
="WPA2",
168 pairwise
="CCMP", group
="CCMP")
170 def test_ap_wps_conf(dev
, apdev
):
171 """WPS PBC provisioning with configured AP"""
172 ssid
= "test-wps-conf"
173 hostapd
.add_ap(apdev
[0]['ifname'],
174 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
175 "wpa_passphrase": "12345678", "wpa": "2",
176 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
177 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
178 logger
.info("WPS provisioning step")
179 hapd
.request("WPS_PBC")
180 dev
[0].dump_monitor()
181 dev
[0].request("WPS_PBC")
182 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
184 raise Exception("Association with the AP timed out")
185 status
= dev
[0].get_status()
186 if status
['wpa_state'] != 'COMPLETED':
187 raise Exception("Not fully connected")
188 if status
['bssid'] != apdev
[0]['bssid']:
189 raise Exception("Unexpected BSSID")
190 if status
['ssid'] != ssid
:
191 raise Exception("Unexpected SSID")
192 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'CCMP':
193 raise Exception("Unexpected encryption configuration")
194 if status
['key_mgmt'] != 'WPA2-PSK':
195 raise Exception("Unexpected key_mgmt")
197 sta
= hapd
.get_sta(dev
[0].p2p_interface_addr())
198 if 'wpsDeviceName' not in sta
or sta
['wpsDeviceName'] != "Device A":
199 raise Exception("Device name not available in STA command")
201 def test_ap_wps_conf_5ghz(dev
, apdev
):
202 """WPS PBC provisioning with configured AP on 5 GHz band"""
204 ssid
= "test-wps-conf"
205 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
206 "wpa_passphrase": "12345678", "wpa": "2",
207 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
208 "country_code": "FI", "hw_mode": "a", "channel": "36" }
209 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
210 logger
.info("WPS provisioning step")
211 hapd
.request("WPS_PBC")
212 dev
[0].request("WPS_PBC")
213 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
215 raise Exception("Association with the AP timed out")
217 sta
= hapd
.get_sta(dev
[0].p2p_interface_addr())
218 if 'wpsDeviceName' not in sta
or sta
['wpsDeviceName'] != "Device A":
219 raise Exception("Device name not available in STA command")
221 subprocess
.call(['sudo', 'iw', 'reg', 'set', '00'])
223 def test_ap_wps_conf_chan14(dev
, apdev
):
224 """WPS PBC provisioning with configured AP on channel 14"""
226 ssid
= "test-wps-conf"
227 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
228 "wpa_passphrase": "12345678", "wpa": "2",
229 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
230 "country_code": "JP", "hw_mode": "b", "channel": "14" }
231 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
232 logger
.info("WPS provisioning step")
233 hapd
.request("WPS_PBC")
234 dev
[0].request("WPS_PBC")
235 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
237 raise Exception("Association with the AP timed out")
239 sta
= hapd
.get_sta(dev
[0].p2p_interface_addr())
240 if 'wpsDeviceName' not in sta
or sta
['wpsDeviceName'] != "Device A":
241 raise Exception("Device name not available in STA command")
243 subprocess
.call(['sudo', 'iw', 'reg', 'set', '00'])
245 def test_ap_wps_twice(dev
, apdev
):
246 """WPS provisioning with twice to change passphrase"""
247 ssid
= "test-wps-twice"
248 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
249 "wpa_passphrase": "12345678", "wpa": "2",
250 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }
251 hostapd
.add_ap(apdev
[0]['ifname'], params
)
252 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
253 logger
.info("WPS provisioning step")
254 hapd
.request("WPS_PBC")
255 dev
[0].dump_monitor()
256 dev
[0].request("WPS_PBC")
257 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
259 raise Exception("Association with the AP timed out")
260 dev
[0].request("DISCONNECT")
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()
271 dev
[0].request("WPS_PBC any")
272 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
274 raise Exception("Association with the AP timed out")
275 networks
= dev
[0].list_networks()
276 if len(networks
) > 1:
277 raise Exception("Unexpected duplicated network block present")
279 def test_ap_wps_incorrect_pin(dev
, apdev
):
280 """WPS PIN provisioning with incorrect PIN"""
281 ssid
= "test-wps-incorrect-pin"
282 hostapd
.add_ap(apdev
[0]['ifname'],
283 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
284 "wpa_passphrase": "12345678", "wpa": "2",
285 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
286 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
288 logger
.info("WPS provisioning attempt 1")
289 hapd
.request("WPS_PIN any 12345670")
290 dev
[0].dump_monitor()
291 dev
[0].request("WPS_PIN any 55554444")
292 ev
= dev
[0].wait_event(["WPS-FAIL"], timeout
=30)
294 raise Exception("WPS operation timed out")
295 if "config_error=18" not in ev
:
296 raise Exception("Incorrect config_error reported")
297 if "msg=8" not in ev
:
298 raise Exception("PIN error detected on incorrect message")
299 ev
= dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
301 raise Exception("Timeout on disconnection event")
302 dev
[0].request("WPS_CANCEL")
303 # if a scan was in progress, wait for it to complete before trying WPS again
304 ev
= dev
[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
306 status
= hapd
.request("WPS_GET_STATUS")
307 if "Last WPS result: Failed" not in status
:
308 raise Exception("WPS failure result not shown correctly")
310 logger
.info("WPS provisioning attempt 2")
311 hapd
.request("WPS_PIN any 12345670")
312 dev
[0].dump_monitor()
313 dev
[0].request("WPS_PIN any 12344444")
314 ev
= dev
[0].wait_event(["WPS-FAIL"], timeout
=30)
316 raise Exception("WPS operation timed out")
317 if "config_error=18" not in ev
:
318 raise Exception("Incorrect config_error reported")
319 if "msg=10" not in ev
:
320 raise Exception("PIN error detected on incorrect message")
321 ev
= dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
323 raise Exception("Timeout on disconnection event")
325 def test_ap_wps_conf_pin(dev
, apdev
):
326 """WPS PIN provisioning with configured AP"""
327 ssid
= "test-wps-conf-pin"
328 hostapd
.add_ap(apdev
[0]['ifname'],
329 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
330 "wpa_passphrase": "12345678", "wpa": "2",
331 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
332 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
333 logger
.info("WPS provisioning step")
334 pin
= dev
[0].wps_read_pin()
335 hapd
.request("WPS_PIN any " + pin
)
336 dev
[0].dump_monitor()
337 dev
[0].request("WPS_PIN any " + pin
)
338 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
340 raise Exception("Association with the AP timed out")
341 status
= dev
[0].get_status()
342 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
343 raise Exception("Not fully connected")
344 if status
['ssid'] != ssid
:
345 raise Exception("Unexpected SSID")
346 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'CCMP':
347 raise Exception("Unexpected encryption configuration")
348 if status
['key_mgmt'] != 'WPA2-PSK':
349 raise Exception("Unexpected key_mgmt")
351 dev
[1].scan_for_bss(apdev
[0]['bssid'], freq
="2412", force_scan
=True)
352 bss
= dev
[1].get_bss(apdev
[0]['bssid'])
353 if "[WPS-AUTH]" in bss
['flags']:
354 raise Exception("WPS-AUTH flag not cleared")
355 logger
.info("Try to connect from another station using the same PIN")
356 pin
= dev
[1].request("WPS_PIN any")
357 ev
= dev
[1].wait_event(["WPS-M2D","CTRL-EVENT-CONNECTED"], timeout
=30)
359 raise Exception("Operation timed out")
360 if "WPS-M2D" not in ev
:
361 raise Exception("Unexpected WPS operation started")
362 hapd
.request("WPS_PIN any " + pin
)
363 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
365 raise Exception("Association with the AP timed out")
367 def test_ap_wps_conf_pin_v1(dev
, apdev
):
368 """WPS PIN provisioning with configured WPS v1.0 AP"""
369 ssid
= "test-wps-conf-pin-v1"
370 hostapd
.add_ap(apdev
[0]['ifname'],
371 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
372 "wpa_passphrase": "12345678", "wpa": "2",
373 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
374 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
375 logger
.info("WPS provisioning step")
376 pin
= dev
[0].wps_read_pin()
377 hapd
.request("SET wps_version_number 0x10")
378 hapd
.request("WPS_PIN any " + pin
)
380 for i
in range(0, 10):
381 dev
[0].scan(freq
="2412")
382 if "[WPS-PIN]" in dev
[0].request("SCAN_RESULTS"):
386 hapd
.request("SET wps_version_number 0x20")
387 raise Exception("WPS-PIN flag not seen in scan results")
388 dev
[0].dump_monitor()
389 dev
[0].request("WPS_PIN any " + pin
)
390 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
391 hapd
.request("SET wps_version_number 0x20")
393 raise Exception("Association with the AP timed out")
395 def test_ap_wps_conf_pin_2sta(dev
, apdev
):
396 """Two stations trying to use WPS PIN at the same time"""
397 ssid
= "test-wps-conf-pin2"
398 hostapd
.add_ap(apdev
[0]['ifname'],
399 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
400 "wpa_passphrase": "12345678", "wpa": "2",
401 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
402 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
403 logger
.info("WPS provisioning step")
406 hapd
.request("WPS_PIN " + dev
[0].get_status_field("uuid") + " " + pin
)
407 hapd
.request("WPS_PIN " + dev
[1].get_status_field("uuid") + " " + pin
)
408 dev
[0].dump_monitor()
409 dev
[1].dump_monitor()
410 dev
[0].request("WPS_PIN any " + pin
)
411 dev
[1].request("WPS_PIN any " + pin
)
412 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
414 raise Exception("Association with the AP timed out")
415 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
417 raise Exception("Association with the AP timed out")
419 def test_ap_wps_conf_pin_timeout(dev
, apdev
):
420 """WPS PIN provisioning with configured AP timing out PIN"""
421 ssid
= "test-wps-conf-pin"
422 hostapd
.add_ap(apdev
[0]['ifname'],
423 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
424 "wpa_passphrase": "12345678", "wpa": "2",
425 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
426 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
427 addr
= dev
[0].p2p_interface_addr()
428 pin
= dev
[0].wps_read_pin()
429 if "FAIL" not in hapd
.request("WPS_PIN "):
430 raise Exception("Unexpected success on invalid WPS_PIN")
431 hapd
.request("WPS_PIN any " + pin
+ " 1")
433 dev
[0].request("WPS_PIN any " + pin
)
434 ev
= hapd
.wait_event(["WPS-PIN-NEEDED"], timeout
=20)
436 raise Exception("WPS-PIN-NEEDED event timed out")
437 ev
= dev
[0].wait_event(["WPS-M2D"])
439 raise Exception("M2D not reported")
440 dev
[0].request("WPS_CANCEL")
442 hapd
.request("WPS_PIN any " + pin
+ " 20 " + addr
)
443 dev
[0].request("WPS_PIN any " + pin
)
444 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
446 raise Exception("Association with the AP timed out")
448 def test_ap_wps_reg_connect(dev
, apdev
):
449 """WPS registrar using AP PIN to connect"""
450 ssid
= "test-wps-reg-ap-pin"
452 hostapd
.add_ap(apdev
[0]['ifname'],
453 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
454 "wpa_passphrase": "12345678", "wpa": "2",
455 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
457 logger
.info("WPS provisioning step")
458 dev
[0].dump_monitor()
459 dev
[0].wps_reg(apdev
[0]['bssid'], appin
)
460 status
= dev
[0].get_status()
461 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
462 raise Exception("Not fully connected")
463 if status
['ssid'] != ssid
:
464 raise Exception("Unexpected SSID")
465 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'CCMP':
466 raise Exception("Unexpected encryption configuration")
467 if status
['key_mgmt'] != 'WPA2-PSK':
468 raise Exception("Unexpected key_mgmt")
470 def check_wps_reg_failure(dev
, ap
, appin
):
471 dev
.request("WPS_REG " + ap
['bssid'] + " " + appin
)
472 ev
= dev
.wait_event(["WPS-SUCCESS", "WPS-FAIL"], timeout
=15)
474 raise Exception("WPS operation timed out")
475 if "WPS-SUCCESS" in ev
:
476 raise Exception("WPS operation succeeded unexpectedly")
477 if "config_error=15" not in ev
:
478 raise Exception("WPS setup locked state was not reported correctly")
480 def test_ap_wps_random_ap_pin(dev
, apdev
):
481 """WPS registrar using random AP PIN"""
482 ssid
= "test-wps-reg-random-ap-pin"
483 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
484 hostapd
.add_ap(apdev
[0]['ifname'],
485 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
486 "wpa_passphrase": "12345678", "wpa": "2",
487 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
488 "device_name": "Wireless AP", "manufacturer": "Company",
489 "model_name": "WAP", "model_number": "123",
490 "serial_number": "12345", "device_type": "6-0050F204-1",
491 "os_version": "01020300",
492 "config_methods": "label push_button",
493 "uuid": ap_uuid
, "upnp_iface": "lo" })
494 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
495 appin
= hapd
.request("WPS_AP_PIN random")
497 raise Exception("Could not generate random AP PIN")
498 if appin
not in hapd
.request("WPS_AP_PIN get"):
499 raise Exception("Could not fetch current AP PIN")
500 logger
.info("WPS provisioning step")
501 dev
[0].wps_reg(apdev
[0]['bssid'], appin
)
503 hapd
.request("WPS_AP_PIN disable")
504 logger
.info("WPS provisioning step with AP PIN disabled")
505 check_wps_reg_failure(dev
[1], apdev
[0], appin
)
507 logger
.info("WPS provisioning step with AP PIN reset")
509 hapd
.request("WPS_AP_PIN set " + appin
)
510 dev
[1].wps_reg(apdev
[0]['bssid'], appin
)
511 dev
[0].request("REMOVE_NETWORK all")
512 dev
[1].request("REMOVE_NETWORK all")
513 dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
514 dev
[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
516 logger
.info("WPS provisioning step after AP PIN timeout")
517 hapd
.request("WPS_AP_PIN disable")
518 appin
= hapd
.request("WPS_AP_PIN random 1")
520 if "FAIL" not in hapd
.request("WPS_AP_PIN get"):
521 raise Exception("AP PIN unexpectedly still enabled")
522 check_wps_reg_failure(dev
[0], apdev
[0], appin
)
524 logger
.info("WPS provisioning step after AP PIN timeout(2)")
525 hapd
.request("WPS_AP_PIN disable")
527 hapd
.request("WPS_AP_PIN set " + appin
+ " 1")
529 if "FAIL" not in hapd
.request("WPS_AP_PIN get"):
530 raise Exception("AP PIN unexpectedly still enabled")
531 check_wps_reg_failure(dev
[1], apdev
[0], appin
)
533 def test_ap_wps_reg_config(dev
, apdev
):
534 """WPS registrar configuring an AP using AP PIN"""
535 ssid
= "test-wps-init-ap-pin"
537 hostapd
.add_ap(apdev
[0]['ifname'],
538 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
540 logger
.info("WPS configuration step")
541 dev
[0].dump_monitor()
542 new_ssid
= "wps-new-ssid"
543 new_passphrase
= "1234567890"
544 dev
[0].wps_reg(apdev
[0]['bssid'], appin
, new_ssid
, "WPA2PSK", "CCMP",
546 status
= dev
[0].get_status()
547 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
548 raise Exception("Not fully connected")
549 if status
['ssid'] != new_ssid
:
550 raise Exception("Unexpected SSID")
551 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'CCMP':
552 raise Exception("Unexpected encryption configuration")
553 if status
['key_mgmt'] != 'WPA2-PSK':
554 raise Exception("Unexpected key_mgmt")
556 logger
.info("Re-configure back to open")
557 dev
[0].request("REMOVE_NETWORK all")
558 dev
[0].request("BSS_FLUSH 0")
559 dev
[0].request("SCAN freq=2412 only_new=1")
560 ev
= dev
[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15)
562 raise Exception("Scan timed out")
563 dev
[0].dump_monitor()
564 dev
[0].wps_reg(apdev
[0]['bssid'], appin
, "wps-open", "OPEN", "NONE", "")
565 status
= dev
[0].get_status()
566 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
567 raise Exception("Not fully connected")
568 if status
['ssid'] != "wps-open":
569 raise Exception("Unexpected SSID")
570 if status
['key_mgmt'] != 'NONE':
571 raise Exception("Unexpected key_mgmt")
573 def test_ap_wps_reg_config_ext_processing(dev
, apdev
):
574 """WPS registrar configuring an AP with external config processing"""
575 ssid
= "test-wps-init-ap-pin"
577 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
578 "wps_cred_processing": "1", "ap_pin": appin
}
579 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
580 new_ssid
= "wps-new-ssid"
581 new_passphrase
= "1234567890"
582 dev
[0].wps_reg(apdev
[0]['bssid'], appin
, new_ssid
, "WPA2PSK", "CCMP",
583 new_passphrase
, no_wait
=True)
584 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=15)
586 raise Exception("WPS registrar operation timed out")
587 ev
= hapd
.wait_event(["WPS-NEW-AP-SETTINGS"], timeout
=15)
589 raise Exception("WPS configuration timed out")
591 raise Exception("AP Settings missing from event")
592 hapd
.request("SET wps_cred_processing 0")
593 if "FAIL" in hapd
.request("WPS_CONFIG " + new_ssid
.encode("hex") + " WPA2PSK CCMP " + new_passphrase
.encode("hex")):
594 raise Exception("WPS_CONFIG command failed")
595 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
597 raise Exception("Association with the AP timed out")
599 def test_ap_wps_reg_config_tkip(dev
, apdev
):
600 """WPS registrar configuring AP to use TKIP and AP upgrading to TKIP+CCMP"""
601 ssid
= "test-wps-init-ap"
603 hostapd
.add_ap(apdev
[0]['ifname'],
604 { "ssid": ssid
, "eap_server": "1", "wps_state": "1",
606 logger
.info("WPS configuration step")
607 dev
[0].request("SET wps_version_number 0x10")
608 dev
[0].dump_monitor()
609 new_ssid
= "wps-new-ssid-with-tkip"
610 new_passphrase
= "1234567890"
611 dev
[0].wps_reg(apdev
[0]['bssid'], appin
, new_ssid
, "WPAPSK", "TKIP",
613 logger
.info("Re-connect to verify WPA2 mixed mode")
614 dev
[0].request("DISCONNECT")
616 dev
[0].set_network(id, "pairwise", "CCMP")
617 dev
[0].set_network(id, "proto", "RSN")
618 dev
[0].connect_network(id)
619 status
= dev
[0].get_status()
620 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
621 raise Exception("Not fully connected")
622 if status
['ssid'] != new_ssid
:
623 raise Exception("Unexpected SSID")
624 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'TKIP':
625 raise Exception("Unexpected encryption configuration")
626 if status
['key_mgmt'] != 'WPA2-PSK':
627 raise Exception("Unexpected key_mgmt")
629 def test_ap_wps_setup_locked(dev
, apdev
):
630 """WPS registrar locking up AP setup on AP PIN failures"""
631 ssid
= "test-wps-incorrect-ap-pin"
633 hostapd
.add_ap(apdev
[0]['ifname'],
634 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
635 "wpa_passphrase": "12345678", "wpa": "2",
636 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
638 new_ssid
= "wps-new-ssid-test"
639 new_passphrase
= "1234567890"
641 ap_setup_locked
=False
642 for pin
in ["55554444", "1234", "12345678", "00000000", "11111111"]:
643 dev
[0].dump_monitor()
644 logger
.info("Try incorrect AP PIN - attempt " + pin
)
645 dev
[0].wps_reg(apdev
[0]['bssid'], pin
, new_ssid
, "WPA2PSK",
646 "CCMP", new_passphrase
, no_wait
=True)
647 ev
= dev
[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"])
649 raise Exception("Timeout on receiving WPS operation failure event")
650 if "CTRL-EVENT-CONNECTED" in ev
:
651 raise Exception("Unexpected connection")
652 if "config_error=15" in ev
:
653 logger
.info("AP Setup Locked")
655 elif "config_error=18" not in ev
:
656 raise Exception("config_error=18 not reported")
657 ev
= dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
659 raise Exception("Timeout on disconnection event")
661 if not ap_setup_locked
:
662 raise Exception("AP setup was not locked")
664 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
665 status
= hapd
.request("WPS_GET_STATUS")
666 if "Last WPS result: Failed" not in status
:
667 raise Exception("WPS failure result not shown correctly")
668 if "Peer Address: " + dev
[0].p2p_interface_addr() not in status
:
669 raise Exception("Peer address not shown correctly")
672 dev
[0].dump_monitor()
673 logger
.info("WPS provisioning step")
674 pin
= dev
[0].wps_read_pin()
675 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
676 hapd
.request("WPS_PIN any " + pin
)
677 dev
[0].request("WPS_PIN any " + pin
)
678 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=30)
680 raise Exception("WPS success was not reported")
681 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
683 raise Exception("Association with the AP timed out")
685 appin
= hapd
.request("WPS_AP_PIN random")
687 raise Exception("Could not generate random AP PIN")
688 ev
= hapd
.wait_event(["WPS-AP-SETUP-UNLOCKED"], timeout
=10)
690 raise Exception("Failed to unlock AP PIN")
692 def test_ap_wps_setup_locked_timeout(dev
, apdev
):
693 """WPS re-enabling AP PIN after timeout"""
694 ssid
= "test-wps-incorrect-ap-pin"
696 hostapd
.add_ap(apdev
[0]['ifname'],
697 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
698 "wpa_passphrase": "12345678", "wpa": "2",
699 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
701 new_ssid
= "wps-new-ssid-test"
702 new_passphrase
= "1234567890"
704 ap_setup_locked
=False
705 for pin
in ["55554444", "1234", "12345678", "00000000", "11111111"]:
706 dev
[0].dump_monitor()
707 logger
.info("Try incorrect AP PIN - attempt " + pin
)
708 dev
[0].wps_reg(apdev
[0]['bssid'], pin
, new_ssid
, "WPA2PSK",
709 "CCMP", new_passphrase
, no_wait
=True)
710 ev
= dev
[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"])
712 raise Exception("Timeout on receiving WPS operation failure event")
713 if "CTRL-EVENT-CONNECTED" in ev
:
714 raise Exception("Unexpected connection")
715 if "config_error=15" in ev
:
716 logger
.info("AP Setup Locked")
719 elif "config_error=18" not in ev
:
720 raise Exception("config_error=18 not reported")
721 ev
= dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
723 raise Exception("Timeout on disconnection event")
725 if not ap_setup_locked
:
726 raise Exception("AP setup was not locked")
727 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
728 ev
= hapd
.wait_event(["WPS-AP-SETUP-UNLOCKED"], timeout
=80)
730 raise Exception("AP PIN did not get unlocked on 60 second timeout")
732 def test_ap_wps_pbc_overlap_2ap(dev
, apdev
):
733 """WPS PBC session overlap with two active APs"""
734 hostapd
.add_ap(apdev
[0]['ifname'],
735 { "ssid": "wps1", "eap_server": "1", "wps_state": "2",
736 "wpa_passphrase": "12345678", "wpa": "2",
737 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
738 "wps_independent": "1"})
739 hostapd
.add_ap(apdev
[1]['ifname'],
740 { "ssid": "wps2", "eap_server": "1", "wps_state": "2",
741 "wpa_passphrase": "123456789", "wpa": "2",
742 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
743 "wps_independent": "1"})
744 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
745 hapd
.request("WPS_PBC")
746 hapd2
= hostapd
.Hostapd(apdev
[1]['ifname'])
747 hapd2
.request("WPS_PBC")
748 logger
.info("WPS provisioning step")
749 dev
[0].scan_for_bss(apdev
[0]['bssid'], freq
="2412", force_scan
=True)
750 dev
[0].scan_for_bss(apdev
[1]['bssid'], freq
="2412")
751 dev
[0].request("WPS_PBC")
752 ev
= dev
[0].wait_event(["WPS-OVERLAP-DETECTED"], timeout
=15)
754 raise Exception("PBC session overlap not detected")
756 def test_ap_wps_pbc_overlap_2sta(dev
, apdev
):
757 """WPS PBC session overlap with two active STAs"""
758 ssid
= "test-wps-pbc-overlap"
759 hostapd
.add_ap(apdev
[0]['ifname'],
760 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
761 "wpa_passphrase": "12345678", "wpa": "2",
762 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
763 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
764 logger
.info("WPS provisioning step")
765 hapd
.request("WPS_PBC")
766 dev
[0].dump_monitor()
767 dev
[1].dump_monitor()
768 dev
[0].request("WPS_PBC")
769 dev
[1].request("WPS_PBC")
770 ev
= dev
[0].wait_event(["WPS-M2D"], timeout
=15)
772 raise Exception("PBC session overlap not detected (dev0)")
773 if "config_error=12" not in ev
:
774 raise Exception("PBC session overlap not correctly reported (dev0)")
775 ev
= dev
[1].wait_event(["WPS-M2D"], timeout
=15)
777 raise Exception("PBC session overlap not detected (dev1)")
778 if "config_error=12" not in ev
:
779 raise Exception("PBC session overlap not correctly reported (dev1)")
780 hapd
.request("WPS_CANCEL")
781 ret
= hapd
.request("WPS_PBC")
782 if "FAIL" not in ret
:
783 raise Exception("PBC mode allowed to be started while PBC overlap still active")
785 def test_ap_wps_cancel(dev
, apdev
):
786 """WPS AP cancelling enabled config method"""
787 ssid
= "test-wps-ap-cancel"
788 hostapd
.add_ap(apdev
[0]['ifname'],
789 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
790 "wpa_passphrase": "12345678", "wpa": "2",
791 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
792 bssid
= apdev
[0]['bssid']
793 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
795 logger
.info("Verify PBC enable/cancel")
796 hapd
.request("WPS_PBC")
797 dev
[0].scan(freq
="2412")
798 dev
[0].scan(freq
="2412")
799 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
800 if "[WPS-PBC]" not in bss
['flags']:
801 raise Exception("WPS-PBC flag missing")
802 if "FAIL" in hapd
.request("WPS_CANCEL"):
803 raise Exception("WPS_CANCEL failed")
804 dev
[0].scan(freq
="2412")
805 dev
[0].scan(freq
="2412")
806 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
807 if "[WPS-PBC]" in bss
['flags']:
808 raise Exception("WPS-PBC flag not cleared")
810 logger
.info("Verify PIN enable/cancel")
811 hapd
.request("WPS_PIN any 12345670")
812 dev
[0].scan(freq
="2412")
813 dev
[0].scan(freq
="2412")
814 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
815 if "[WPS-AUTH]" not in bss
['flags']:
816 raise Exception("WPS-AUTH flag missing")
817 if "FAIL" in hapd
.request("WPS_CANCEL"):
818 raise Exception("WPS_CANCEL failed")
819 dev
[0].scan(freq
="2412")
820 dev
[0].scan(freq
="2412")
821 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
822 if "[WPS-AUTH]" in bss
['flags']:
823 raise Exception("WPS-AUTH flag not cleared")
825 def test_ap_wps_er_add_enrollee(dev
, apdev
):
826 """WPS ER configuring AP and adding a new enrollee using PIN"""
827 ssid
= "wps-er-add-enrollee"
829 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
830 hostapd
.add_ap(apdev
[0]['ifname'],
831 { "ssid": ssid
, "eap_server": "1", "wps_state": "1",
832 "device_name": "Wireless AP", "manufacturer": "Company",
833 "model_name": "WAP", "model_number": "123",
834 "serial_number": "12345", "device_type": "6-0050F204-1",
835 "os_version": "01020300",
836 "config_methods": "label push_button",
837 "ap_pin": ap_pin
, "uuid": ap_uuid
, "upnp_iface": "lo"})
838 logger
.info("WPS configuration step")
839 new_passphrase
= "1234567890"
840 dev
[0].dump_monitor()
841 dev
[0].wps_reg(apdev
[0]['bssid'], ap_pin
, ssid
, "WPA2PSK", "CCMP",
843 status
= dev
[0].get_status()
844 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
845 raise Exception("Not fully connected")
846 if status
['ssid'] != ssid
:
847 raise Exception("Unexpected SSID")
848 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'CCMP':
849 raise Exception("Unexpected encryption configuration")
850 if status
['key_mgmt'] != 'WPA2-PSK':
851 raise Exception("Unexpected key_mgmt")
853 logger
.info("Start ER")
854 dev
[0].request("WPS_ER_START ifname=lo")
855 ev
= dev
[0].wait_event(["WPS-ER-AP-ADD"], timeout
=15)
857 raise Exception("AP discovery timed out")
858 if ap_uuid
not in ev
:
859 raise Exception("Expected AP UUID not found")
861 logger
.info("Learn AP configuration through UPnP")
862 dev
[0].dump_monitor()
863 dev
[0].request("WPS_ER_LEARN " + ap_uuid
+ " " + ap_pin
)
864 ev
= dev
[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout
=15)
866 raise Exception("AP learn timed out")
867 if ap_uuid
not in ev
:
868 raise Exception("Expected AP UUID not in settings")
869 if "ssid=" + ssid
not in ev
:
870 raise Exception("Expected SSID not in settings")
871 if "key=" + new_passphrase
not in ev
:
872 raise Exception("Expected passphrase not in settings")
874 logger
.info("Add Enrollee using ER")
875 pin
= dev
[1].wps_read_pin()
876 dev
[0].dump_monitor()
877 dev
[0].request("WPS_ER_PIN any " + pin
+ " " + dev
[1].p2p_interface_addr())
878 dev
[1].dump_monitor()
879 dev
[1].request("WPS_PIN any " + pin
)
880 ev
= dev
[1].wait_event(["WPS-SUCCESS"], timeout
=30)
882 raise Exception("Enrollee did not report success")
883 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
885 raise Exception("Association with the AP timed out")
886 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=15)
888 raise Exception("WPS ER did not report success")
889 hwsim_utils
.test_connectivity_sta(dev
[0], dev
[1])
891 logger
.info("Add a specific Enrollee using ER")
892 pin
= dev
[2].wps_read_pin()
893 addr2
= dev
[2].p2p_interface_addr()
894 dev
[0].dump_monitor()
895 dev
[2].dump_monitor()
896 dev
[2].request("WPS_PIN any " + pin
)
897 ev
= dev
[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout
=10)
899 raise Exception("Enrollee not seen")
901 raise Exception("Unexpected Enrollee MAC address")
902 dev
[0].request("WPS_ER_PIN " + addr2
+ " " + pin
+ " " + addr2
)
903 ev
= dev
[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
905 raise Exception("Association with the AP timed out")
906 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=15)
908 raise Exception("WPS ER did not report success")
910 logger
.info("Verify registrar selection behavior")
911 dev
[0].request("WPS_ER_PIN any " + pin
+ " " + dev
[1].p2p_interface_addr())
912 dev
[1].request("DISCONNECT")
913 dev
[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
914 dev
[1].scan_for_bss(apdev
[0]['bssid'], freq
="2412")
915 dev
[1].scan(freq
="2412")
916 bss
= dev
[1].get_bss(apdev
[0]['bssid'])
917 if "[WPS-AUTH]" not in bss
['flags']:
918 raise Exception("WPS-AUTH flag missing")
920 logger
.info("Stop ER")
921 dev
[0].dump_monitor()
922 dev
[0].request("WPS_ER_STOP")
923 ev
= dev
[0].wait_event(["WPS-ER-AP-REMOVE"])
925 raise Exception("WPS ER unsubscription timed out")
926 # It takes some time for the UPnP UNSUBSCRIBE command to go through, so wait
927 # a bit before verifying that the scan results have changed.
930 for i
in range(0, 10):
931 dev
[1].request("BSS_FLUSH 0")
932 dev
[1].scan(freq
="2412", only_new
=True)
933 bss
= dev
[1].get_bss(apdev
[0]['bssid'])
934 if bss
and 'flags' in bss
and "[WPS-AUTH]" not in bss
['flags']:
936 logger
.debug("WPS-AUTH flag was still in place - wait a bit longer")
938 if "[WPS-AUTH]" in bss
['flags']:
939 raise Exception("WPS-AUTH flag not removed")
941 def test_ap_wps_er_add_enrollee_pbc(dev
, apdev
):
942 """WPS ER connected to AP and adding a new enrollee using PBC"""
943 ssid
= "wps-er-add-enrollee-pbc"
945 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
946 hostapd
.add_ap(apdev
[0]['ifname'],
947 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
948 "wpa_passphrase": "12345678", "wpa": "2",
949 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
950 "device_name": "Wireless AP", "manufacturer": "Company",
951 "model_name": "WAP", "model_number": "123",
952 "serial_number": "12345", "device_type": "6-0050F204-1",
953 "os_version": "01020300",
954 "config_methods": "label push_button",
955 "ap_pin": ap_pin
, "uuid": ap_uuid
, "upnp_iface": "lo"})
956 logger
.info("Learn AP configuration")
957 dev
[0].dump_monitor()
958 dev
[0].wps_reg(apdev
[0]['bssid'], ap_pin
)
959 status
= dev
[0].get_status()
960 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
961 raise Exception("Not fully connected")
963 logger
.info("Start ER")
964 dev
[0].request("WPS_ER_START ifname=lo")
965 ev
= dev
[0].wait_event(["WPS-ER-AP-ADD"], timeout
=15)
967 raise Exception("AP discovery timed out")
968 if ap_uuid
not in ev
:
969 raise Exception("Expected AP UUID not found")
971 logger
.info("Use learned network configuration on ER")
972 dev
[0].request("WPS_ER_SET_CONFIG " + ap_uuid
+ " 0")
974 logger
.info("Add Enrollee using ER and PBC")
975 dev
[0].dump_monitor()
976 enrollee
= dev
[1].p2p_interface_addr()
977 dev
[1].dump_monitor()
978 dev
[1].request("WPS_PBC")
980 for i
in range(0, 2):
981 ev
= dev
[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout
=15)
983 raise Exception("Enrollee discovery timed out")
987 raise Exception("Expected Enrollee not found")
988 dev
[0].request("WPS_ER_PBC " + enrollee
)
990 ev
= dev
[1].wait_event(["WPS-SUCCESS"], timeout
=15)
992 raise Exception("Enrollee did not report success")
993 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
995 raise Exception("Association with the AP timed out")
996 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=15)
998 raise Exception("WPS ER did not report success")
999 hwsim_utils
.test_connectivity_sta(dev
[0], dev
[1])
1001 # verify BSSID selection of the AP instead of UUID
1002 if "FAIL" in dev
[0].request("WPS_ER_SET_CONFIG " + apdev
[0]['bssid'] + " 0"):
1003 raise Exception("Could not select AP based on BSSID")
1005 def test_ap_wps_er_v10_add_enrollee_pin(dev
, apdev
):
1006 """WPS v1.0 ER connected to AP and adding a new enrollee using PIN"""
1007 ssid
= "wps-er-add-enrollee-pbc"
1009 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
1010 hostapd
.add_ap(apdev
[0]['ifname'],
1011 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1012 "wpa_passphrase": "12345678", "wpa": "2",
1013 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
1014 "device_name": "Wireless AP", "manufacturer": "Company",
1015 "model_name": "WAP", "model_number": "123",
1016 "serial_number": "12345", "device_type": "6-0050F204-1",
1017 "os_version": "01020300",
1018 "config_methods": "label push_button",
1019 "ap_pin": ap_pin
, "uuid": ap_uuid
, "upnp_iface": "lo"})
1020 logger
.info("Learn AP configuration")
1021 dev
[0].request("SET wps_version_number 0x10")
1022 dev
[0].dump_monitor()
1023 dev
[0].wps_reg(apdev
[0]['bssid'], ap_pin
)
1024 status
= dev
[0].get_status()
1025 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
1026 raise Exception("Not fully connected")
1028 logger
.info("Start ER")
1029 dev
[0].request("WPS_ER_START ifname=lo")
1030 ev
= dev
[0].wait_event(["WPS-ER-AP-ADD"], timeout
=15)
1032 raise Exception("AP discovery timed out")
1033 if ap_uuid
not in ev
:
1034 raise Exception("Expected AP UUID not found")
1036 logger
.info("Use learned network configuration on ER")
1037 dev
[0].request("WPS_ER_SET_CONFIG " + ap_uuid
+ " 0")
1039 logger
.info("Add Enrollee using ER and PIN")
1040 enrollee
= dev
[1].p2p_interface_addr()
1041 pin
= dev
[1].wps_read_pin()
1042 dev
[0].dump_monitor()
1043 dev
[0].request("WPS_ER_PIN any " + pin
+ " " + enrollee
)
1044 dev
[1].dump_monitor()
1045 dev
[1].request("WPS_PIN any " + pin
)
1046 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
1048 raise Exception("Association with the AP timed out")
1049 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=15)
1051 raise Exception("WPS ER did not report success")
1053 def test_ap_wps_er_config_ap(dev
, apdev
):
1054 """WPS ER configuring AP over UPnP"""
1055 ssid
= "wps-er-ap-config"
1057 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
1058 hostapd
.add_ap(apdev
[0]['ifname'],
1059 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1060 "wpa_passphrase": "12345678", "wpa": "2",
1061 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
1062 "device_name": "Wireless AP", "manufacturer": "Company",
1063 "model_name": "WAP", "model_number": "123",
1064 "serial_number": "12345", "device_type": "6-0050F204-1",
1065 "os_version": "01020300",
1066 "config_methods": "label push_button",
1067 "ap_pin": ap_pin
, "uuid": ap_uuid
, "upnp_iface": "lo"})
1069 logger
.info("Connect ER to the AP")
1070 dev
[0].connect(ssid
, psk
="12345678", scan_freq
="2412")
1072 logger
.info("WPS configuration step")
1073 dev
[0].request("WPS_ER_START ifname=lo")
1074 ev
= dev
[0].wait_event(["WPS-ER-AP-ADD"], timeout
=15)
1076 raise Exception("AP discovery timed out")
1077 if ap_uuid
not in ev
:
1078 raise Exception("Expected AP UUID not found")
1079 new_passphrase
= "1234567890"
1080 dev
[0].request("WPS_ER_CONFIG " + apdev
[0]['bssid'] + " " + ap_pin
+ " " +
1081 ssid
.encode("hex") + " WPA2PSK CCMP " +
1082 new_passphrase
.encode("hex"))
1083 ev
= dev
[0].wait_event(["WPS-SUCCESS"])
1085 raise Exception("WPS ER configuration operation timed out")
1086 dev
[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
1087 dev
[0].connect(ssid
, psk
="1234567890", scan_freq
="2412")
1089 def test_ap_wps_fragmentation(dev
, apdev
):
1090 """WPS with fragmentation in EAP-WSC and mixed mode WPA+WPA2"""
1091 ssid
= "test-wps-fragmentation"
1093 hostapd
.add_ap(apdev
[0]['ifname'],
1094 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1095 "wpa_passphrase": "12345678", "wpa": "3",
1096 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
1097 "wpa_pairwise": "TKIP", "ap_pin": appin
,
1098 "fragment_size": "50" })
1099 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1100 logger
.info("WPS provisioning step (PBC)")
1101 hapd
.request("WPS_PBC")
1102 dev
[0].dump_monitor()
1103 dev
[0].request("SET wps_fragment_size 50")
1104 dev
[0].request("WPS_PBC")
1105 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
1107 raise Exception("Association with the AP timed out")
1108 status
= dev
[0].get_status()
1109 if status
['wpa_state'] != 'COMPLETED':
1110 raise Exception("Not fully connected")
1111 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'TKIP':
1112 raise Exception("Unexpected encryption configuration")
1113 if status
['key_mgmt'] != 'WPA2-PSK':
1114 raise Exception("Unexpected key_mgmt")
1116 logger
.info("WPS provisioning step (PIN)")
1117 pin
= dev
[1].wps_read_pin()
1118 hapd
.request("WPS_PIN any " + pin
)
1119 dev
[1].request("SET wps_fragment_size 50")
1120 dev
[1].request("WPS_PIN any " + pin
)
1121 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
1123 raise Exception("Association with the AP timed out")
1124 status
= dev
[1].get_status()
1125 if status
['wpa_state'] != 'COMPLETED':
1126 raise Exception("Not fully connected")
1127 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'TKIP':
1128 raise Exception("Unexpected encryption configuration")
1129 if status
['key_mgmt'] != 'WPA2-PSK':
1130 raise Exception("Unexpected key_mgmt")
1132 logger
.info("WPS connection as registrar")
1133 dev
[2].request("SET wps_fragment_size 50")
1134 dev
[2].wps_reg(apdev
[0]['bssid'], appin
)
1135 status
= dev
[2].get_status()
1136 if status
['wpa_state'] != 'COMPLETED':
1137 raise Exception("Not fully connected")
1138 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'TKIP':
1139 raise Exception("Unexpected encryption configuration")
1140 if status
['key_mgmt'] != 'WPA2-PSK':
1141 raise Exception("Unexpected key_mgmt")
1143 def test_ap_wps_new_version_sta(dev
, apdev
):
1144 """WPS compatibility with new version number on the station"""
1145 ssid
= "test-wps-ver"
1146 hostapd
.add_ap(apdev
[0]['ifname'],
1147 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1148 "wpa_passphrase": "12345678", "wpa": "2",
1149 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
1150 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1151 logger
.info("WPS provisioning step")
1152 hapd
.request("WPS_PBC")
1153 dev
[0].dump_monitor()
1154 dev
[0].request("SET wps_version_number 0x43")
1155 dev
[0].request("SET wps_vendor_ext_m1 000137100100020001")
1156 dev
[0].request("WPS_PBC")
1157 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
1159 raise Exception("Association with the AP timed out")
1161 def test_ap_wps_new_version_ap(dev
, apdev
):
1162 """WPS compatibility with new version number on the AP"""
1163 ssid
= "test-wps-ver"
1164 hostapd
.add_ap(apdev
[0]['ifname'],
1165 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1166 "wpa_passphrase": "12345678", "wpa": "2",
1167 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
1168 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1169 logger
.info("WPS provisioning step")
1170 if "FAIL" in hapd
.request("SET wps_version_number 0x43"):
1171 raise Exception("Failed to enable test functionality")
1172 hapd
.request("WPS_PBC")
1173 dev
[0].dump_monitor()
1174 dev
[0].request("WPS_PBC")
1175 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
1176 hapd
.request("SET wps_version_number 0x20")
1178 raise Exception("Association with the AP timed out")
1180 def test_ap_wps_check_pin(dev
, apdev
):
1181 """Verify PIN checking through control interface"""
1182 hostapd
.add_ap(apdev
[0]['ifname'],
1183 { "ssid": "wps", "eap_server": "1", "wps_state": "2",
1184 "wpa_passphrase": "12345678", "wpa": "2",
1185 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
1186 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1187 for t
in [ ("12345670", "12345670"),
1188 ("12345678", "FAIL-CHECKSUM"),
1190 ("123456789", "FAIL"),
1191 ("1234-5670", "12345670"),
1192 ("1234 5670", "12345670"),
1193 ("1-2.3:4 5670", "12345670") ]:
1194 res
= hapd
.request("WPS_CHECK_PIN " + t
[0]).rstrip('\n')
1195 res2
= dev
[0].request("WPS_CHECK_PIN " + t
[0]).rstrip('\n')
1197 raise Exception("Unexpected difference in WPS_CHECK_PIN responses")
1199 raise Exception("Incorrect WPS_CHECK_PIN response {} (expected {})".format(res
, t
[1]))
1201 if "FAIL" not in hapd
.request("WPS_CHECK_PIN 12345"):
1202 raise Exception("Unexpected WPS_CHECK_PIN success")
1203 if "FAIL" not in hapd
.request("WPS_CHECK_PIN 123456789"):
1204 raise Exception("Unexpected WPS_CHECK_PIN success")
1206 for i
in range(0, 10):
1207 pin
= dev
[0].request("WPS_PIN get")
1208 rpin
= dev
[0].request("WPS_CHECK_PIN " + pin
).rstrip('\n')
1210 raise Exception("Random PIN validation failed for " + pin
)
1212 def test_ap_wps_wep_config(dev
, apdev
):
1213 """WPS 2.0 AP rejecting WEP configuration"""
1214 ssid
= "test-wps-config"
1216 hostapd
.add_ap(apdev
[0]['ifname'],
1217 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1219 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1220 dev
[0].wps_reg(apdev
[0]['bssid'], appin
, "wps-new-ssid-wep", "OPEN", "WEP",
1221 "hello", no_wait
=True)
1222 ev
= hapd
.wait_event(["WPS-FAIL"], timeout
=15)
1224 raise Exception("WPS-FAIL timed out")
1225 if "reason=2" not in ev
:
1226 raise Exception("Unexpected reason code in WPS-FAIL")
1227 status
= hapd
.request("WPS_GET_STATUS")
1228 if "Last WPS result: Failed" not in status
:
1229 raise Exception("WPS failure result not shown correctly")
1230 if "Failure Reason: WEP Prohibited" not in status
:
1231 raise Exception("Failure reason not reported correctly")
1232 if "Peer Address: " + dev
[0].p2p_interface_addr() not in status
:
1233 raise Exception("Peer address not shown correctly")
1235 def test_ap_wps_wep_enroll(dev
, apdev
):
1236 """WPS 2.0 STA rejecting WEP configuration"""
1237 ssid
= "test-wps-wep"
1238 hostapd
.add_ap(apdev
[0]['ifname'],
1239 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1240 "skip_cred_build": "1", "extra_cred": "wps-wep-cred" })
1241 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1242 hapd
.request("WPS_PBC")
1243 dev
[0].request("WPS_PBC")
1244 ev
= dev
[0].wait_event(["WPS-FAIL"], timeout
=15)
1246 raise Exception("WPS-FAIL event timed out")
1247 if "msg=12" not in ev
or "reason=2 (WEP Prohibited)" not in ev
:
1248 raise Exception("Unexpected WPS-FAIL event: " + ev
)
1250 def test_ap_wps_ie_fragmentation(dev
, apdev
):
1251 """WPS AP using fragmented WPS IE"""
1252 ssid
= "test-wps-ie-fragmentation"
1253 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1254 "wpa_passphrase": "12345678", "wpa": "2",
1255 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
1256 "device_name": "1234567890abcdef1234567890abcdef",
1257 "manufacturer": "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
1258 "model_name": "1234567890abcdef1234567890abcdef",
1259 "model_number": "1234567890abcdef1234567890abcdef",
1260 "serial_number": "1234567890abcdef1234567890abcdef" }
1261 hostapd
.add_ap(apdev
[0]['ifname'], params
)
1262 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1263 hapd
.request("WPS_PBC")
1264 dev
[0].request("WPS_PBC")
1265 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
1267 raise Exception("Association with the AP timed out")
1268 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
1269 if "wps_device_name" not in bss
or bss
['wps_device_name'] != "1234567890abcdef1234567890abcdef":
1270 logger
.info("Device Name not received correctly")
1272 # This can fail if Probe Response frame is missed and Beacon frame was
1273 # used to fill in the BSS entry. This can happen, e.g., during heavy
1274 # load every now and then and is not really an error, so try to
1275 # workaround by runnign another scan.
1276 dev
[0].scan(freq
="2412", only_new
=True)
1277 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
1278 if not bss
or "wps_device_name" not in bss
or bss
['wps_device_name'] != "1234567890abcdef1234567890abcdef":
1280 raise Exception("Device Name not received correctly")
1281 if len(re
.findall("dd..0050f204", bss
['ie'])) != 2:
1282 raise Exception("Unexpected number of WPS IEs")
1284 def get_psk(pskfile
):
1286 with
open(pskfile
, "r") as f
:
1287 lines
= f
.read().splitlines()
1289 if l
== "# WPA PSKs":
1291 (addr
,psk
) = l
.split(' ')
1295 def test_ap_wps_per_station_psk(dev
, apdev
):
1296 """WPS PBC provisioning with per-station PSK"""
1297 addr0
= dev
[0].p2p_dev_addr()
1298 addr1
= dev
[1].p2p_dev_addr()
1299 addr2
= dev
[2].p2p_dev_addr()
1302 pskfile
= "/tmp/ap_wps_per_enrollee_psk.psk_file"
1309 with
open(pskfile
, "w") as f
:
1310 f
.write("# WPA PSKs\n")
1312 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1313 "wpa": "2", "wpa_key_mgmt": "WPA-PSK",
1314 "rsn_pairwise": "CCMP", "ap_pin": appin
,
1315 "wpa_psk_file": pskfile
}
1316 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
1318 logger
.info("First enrollee")
1319 hapd
.request("WPS_PBC")
1320 dev
[0].request("WPS_PBC")
1321 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"])
1323 raise Exception("Association with the AP timed out (1)")
1325 logger
.info("Second enrollee")
1326 hapd
.request("WPS_PBC")
1327 dev
[1].request("WPS_PBC")
1328 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"])
1330 raise Exception("Association with the AP timed out (2)")
1332 logger
.info("External registrar")
1333 dev
[2].wps_reg(apdev
[0]['bssid'], appin
)
1335 logger
.info("Verifying PSK results")
1336 psks
= get_psk(pskfile
)
1337 if addr0
not in psks
:
1338 raise Exception("No PSK recorded for sta0")
1339 if addr1
not in psks
:
1340 raise Exception("No PSK recorded for sta1")
1341 if addr2
not in psks
:
1342 raise Exception("No PSK recorded for sta2")
1343 if psks
[addr0
] == psks
[addr1
]:
1344 raise Exception("Same PSK recorded for sta0 and sta1")
1345 if psks
[addr0
] == psks
[addr2
]:
1346 raise Exception("Same PSK recorded for sta0 and sta2")
1347 if psks
[addr1
] == psks
[addr2
]:
1348 raise Exception("Same PSK recorded for sta1 and sta2")
1350 dev
[0].request("REMOVE_NETWORK all")
1351 logger
.info("Second external registrar")
1352 dev
[0].wps_reg(apdev
[0]['bssid'], appin
)
1353 psks2
= get_psk(pskfile
)
1354 if addr0
not in psks2
:
1355 raise Exception("No PSK recorded for sta0(reg)")
1356 if psks
[addr0
] == psks2
[addr0
]:
1357 raise Exception("Same PSK recorded for sta0(enrollee) and sta0(reg)")
1361 def test_ap_wps_per_station_psk_failure(dev
, apdev
):
1362 """WPS PBC provisioning with per-station PSK (file not writable)"""
1363 addr0
= dev
[0].p2p_dev_addr()
1364 addr1
= dev
[1].p2p_dev_addr()
1365 addr2
= dev
[2].p2p_dev_addr()
1368 pskfile
= "/tmp/ap_wps_per_enrollee_psk.psk_file"
1375 with
open(pskfile
, "w") as f
:
1376 f
.write("# WPA PSKs\n")
1378 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1379 "wpa": "2", "wpa_key_mgmt": "WPA-PSK",
1380 "rsn_pairwise": "CCMP", "ap_pin": appin
,
1381 "wpa_psk_file": pskfile
}
1382 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
1383 if "FAIL" in hapd
.request("SET wpa_psk_file /tmp/does/not/exists/ap_wps_per_enrollee_psk_failure.psk_file"):
1384 raise Exception("Failed to set wpa_psk_file")
1386 logger
.info("First enrollee")
1387 hapd
.request("WPS_PBC")
1388 dev
[0].request("WPS_PBC")
1389 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"])
1391 raise Exception("Association with the AP timed out (1)")
1393 logger
.info("Second enrollee")
1394 hapd
.request("WPS_PBC")
1395 dev
[1].request("WPS_PBC")
1396 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"])
1398 raise Exception("Association with the AP timed out (2)")
1400 logger
.info("External registrar")
1401 dev
[2].wps_reg(apdev
[0]['bssid'], appin
)
1403 logger
.info("Verifying PSK results")
1404 psks
= get_psk(pskfile
)
1406 raise Exception("PSK recorded unexpectedly")
1410 def test_ap_wps_pin_request_file(dev
, apdev
):
1411 """WPS PIN provisioning with configured AP"""
1413 pinfile
= "/tmp/ap_wps_pin_request_file.log"
1414 if os
.path
.exists(pinfile
):
1415 subprocess
.call(['sudo', 'rm', pinfile
])
1416 hostapd
.add_ap(apdev
[0]['ifname'],
1417 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1418 "wps_pin_requests": pinfile
,
1419 "wpa_passphrase": "12345678", "wpa": "2",
1420 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
1421 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1422 uuid
= dev
[0].get_status_field("uuid")
1423 pin
= dev
[0].wps_read_pin()
1425 dev
[0].request("WPS_PIN any " + pin
)
1426 ev
= hapd
.wait_event(["WPS-PIN-NEEDED"], timeout
=15)
1428 raise Exception("PIN needed event not shown")
1430 raise Exception("UUID mismatch")
1431 dev
[0].request("WPS_CANCEL")
1433 with
open(pinfile
, "r") as f
:
1434 lines
= f
.readlines()
1440 raise Exception("PIN request entry not in the log file")
1442 subprocess
.call(['sudo', 'rm', pinfile
])
1444 def test_ap_wps_auto_setup_with_config_file(dev
, apdev
):
1445 """WPS auto-setup with configuration file"""
1446 conffile
= "/tmp/ap_wps_auto_setup_with_config_file.conf"
1447 ifname
= apdev
[0]['ifname']
1449 with
open(conffile
, "w") as f
:
1450 f
.write("driver=nl80211\n")
1451 f
.write("hw_mode=g\n")
1452 f
.write("channel=1\n")
1453 f
.write("ieee80211n=1\n")
1454 f
.write("interface=%s\n" % ifname
)
1455 f
.write("ctrl_interface=/var/run/hostapd\n")
1456 f
.write("ssid=wps\n")
1457 f
.write("eap_server=1\n")
1458 f
.write("wps_state=1\n")
1459 hostapd
.add_bss('phy3', ifname
, conffile
)
1460 hapd
= hostapd
.Hostapd(ifname
)
1461 hapd
.request("WPS_PBC")
1462 dev
[0].request("WPS_PBC")
1463 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
1465 raise Exception("Association with the AP timed out")
1466 with
open(conffile
, "r") as f
:
1467 lines
= f
.read().splitlines()
1471 [name
,value
] = l
.split('=', 1)
1473 except ValueError, e
:
1474 if "# WPS configuration" in l
:
1477 raise Exception("Unexpected configuration line: " + l
)
1478 if vals
['ieee80211n'] != '1' or vals
['wps_state'] != '2' or "WPA-PSK" not in vals
['wpa_key_mgmt']:
1479 raise Exception("Incorrect configuration: " + str(vals
))
1481 subprocess
.call(['sudo', 'rm', conffile
])
1483 def test_ap_wps_pbc_timeout(dev
, apdev
, params
):
1484 """wpa_supplicant PBC walk time [long]"""
1485 if not params
['long']:
1486 logger
.info("Skip test case with long duration due to --long not specified")
1489 hostapd
.add_ap(apdev
[0]['ifname'],
1490 { "ssid": ssid
, "eap_server": "1", "wps_state": "1" })
1491 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1492 logger
.info("Start WPS_PBC and wait for PBC walk time expiration")
1493 if "OK" not in dev
[0].request("WPS_PBC"):
1494 raise Exception("WPS_PBC failed")
1495 ev
= dev
[0].wait_event(["WPS-TIMEOUT"], timeout
=150)
1497 raise Exception("WPS-TIMEOUT not reported")
1499 def add_ssdp_ap(ifname
, ap_uuid
):
1502 hostapd
.add_ap(ifname
,
1503 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1504 "wpa_passphrase": "12345678", "wpa": "2",
1505 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
1506 "device_name": "Wireless AP", "manufacturer": "Company",
1507 "model_name": "WAP", "model_number": "123",
1508 "serial_number": "12345", "device_type": "6-0050F204-1",
1509 "os_version": "01020300",
1510 "config_methods": "label push_button",
1511 "ap_pin": ap_pin
, "uuid": ap_uuid
, "upnp_iface": "lo",
1512 "friendly_name": "WPS Access Point",
1513 "manufacturer_url": "http://www.example.com/",
1514 "model_description": "Wireless Access Point",
1515 "model_url": "http://www.example.com/model/",
1516 "upc": "123456789012" })
1518 def ssdp_send(msg
, no_recv
=False):
1519 socket
.setdefaulttimeout(1)
1520 sock
= socket
.socket(socket
.AF_INET
, socket
.SOCK_DGRAM
, socket
.IPPROTO_UDP
)
1521 sock
.setsockopt(socket
.SOL_SOCKET
, socket
.SO_REUSEADDR
, 1)
1522 sock
.setsockopt(socket
.IPPROTO_IP
, socket
.IP_MULTICAST_TTL
, 2)
1523 sock
.bind(("127.0.0.1", 0))
1524 sock
.sendto(msg
, ("239.255.255.250", 1900))
1527 return sock
.recv(1000)
1529 def ssdp_send_msearch(st
):
1531 'M-SEARCH * HTTP/1.1',
1532 'HOST: 239.255.255.250:1900',
1534 'MAN: "ssdp:discover"',
1537 return ssdp_send(msg
)
1539 def test_ap_wps_ssdp_msearch(dev
, apdev
):
1540 """WPS AP and SSDP M-SEARCH messages"""
1541 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
1542 add_ssdp_ap(apdev
[0]['ifname'], ap_uuid
)
1545 'M-SEARCH * HTTP/1.1',
1546 'Host: 239.255.255.250:1900',
1548 'Man: "ssdp:discover"',
1549 'St: urn:schemas-wifialliance-org:device:WFADevice:1',
1554 'M-SEARCH * HTTP/1.1',
1555 'host:\t239.255.255.250:1900\t\t\t\t \t\t',
1557 'man: \t \t "ssdp:discover" ',
1558 'st: urn:schemas-wifialliance-org:device:WFADevice:1\t\t',
1562 ssdp_send_msearch("ssdp:all")
1563 ssdp_send_msearch("upnp:rootdevice")
1564 ssdp_send_msearch("uuid:" + ap_uuid
)
1565 ssdp_send_msearch("urn:schemas-wifialliance-org:service:WFAWLANConfig:1")
1566 ssdp_send_msearch("urn:schemas-wifialliance-org:device:WFADevice:1");
1569 'M-SEARCH * HTTP/1.1',
1570 'HOST:\t239.255.255.250:1900',
1571 'MAN: "ssdp:discover"',
1573 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1575 ssdp_send(msg
, no_recv
=True)
1577 def test_ap_wps_ssdp_invalid_msearch(dev
, apdev
):
1578 """WPS AP and invalid SSDP M-SEARCH messages"""
1579 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
1580 add_ssdp_ap(apdev
[0]['ifname'], ap_uuid
)
1582 socket
.setdefaulttimeout(1)
1583 sock
= socket
.socket(socket
.AF_INET
, socket
.SOCK_DGRAM
, socket
.IPPROTO_UDP
)
1584 sock
.setsockopt(socket
.SOL_SOCKET
, socket
.SO_REUSEADDR
, 1)
1585 sock
.setsockopt(socket
.IPPROTO_IP
, socket
.IP_MULTICAST_TTL
, 2)
1586 sock
.bind(("127.0.0.1", 0))
1588 logger
.debug("Missing MX")
1590 'M-SEARCH * HTTP/1.1',
1591 'HOST: 239.255.255.250:1900',
1592 'MAN: "ssdp:discover"',
1593 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1595 sock
.sendto(msg
, ("239.255.255.250", 1900))
1597 logger
.debug("Negative MX")
1599 'M-SEARCH * HTTP/1.1',
1600 'HOST: 239.255.255.250:1900',
1602 'MAN: "ssdp:discover"',
1603 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1605 sock
.sendto(msg
, ("239.255.255.250", 1900))
1607 logger
.debug("Invalid MX")
1609 'M-SEARCH * HTTP/1.1',
1610 'HOST: 239.255.255.250:1900',
1612 'MAN: "ssdp:discover"',
1613 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1615 sock
.sendto(msg
, ("239.255.255.250", 1900))
1617 logger
.debug("Missing MAN")
1619 'M-SEARCH * HTTP/1.1',
1620 'HOST: 239.255.255.250:1900',
1622 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1624 sock
.sendto(msg
, ("239.255.255.250", 1900))
1626 logger
.debug("Invalid MAN")
1628 'M-SEARCH * HTTP/1.1',
1629 'HOST: 239.255.255.250:1900',
1632 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1634 sock
.sendto(msg
, ("239.255.255.250", 1900))
1636 'M-SEARCH * HTTP/1.1',
1637 'HOST: 239.255.255.250:1900',
1639 'MAN; "ssdp:discover"',
1640 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1642 sock
.sendto(msg
, ("239.255.255.250", 1900))
1644 logger
.debug("Missing HOST")
1646 'M-SEARCH * HTTP/1.1',
1647 'MAN: "ssdp:discover"',
1649 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1651 sock
.sendto(msg
, ("239.255.255.250", 1900))
1653 logger
.debug("Missing ST")
1655 'M-SEARCH * HTTP/1.1',
1656 'HOST: 239.255.255.250:1900',
1657 'MAN: "ssdp:discover"',
1660 sock
.sendto(msg
, ("239.255.255.250", 1900))
1662 logger
.debug("Mismatching ST")
1664 'M-SEARCH * HTTP/1.1',
1665 'HOST: 239.255.255.250:1900',
1666 'MAN: "ssdp:discover"',
1668 'ST: uuid:16d5f8a9-4ee4-4f5e-81f9-cc6e2f47f42d',
1670 sock
.sendto(msg
, ("239.255.255.250", 1900))
1672 'M-SEARCH * HTTP/1.1',
1673 'HOST: 239.255.255.250:1900',
1674 'MAN: "ssdp:discover"',
1678 sock
.sendto(msg
, ("239.255.255.250", 1900))
1680 'M-SEARCH * HTTP/1.1',
1681 'HOST: 239.255.255.250:1900',
1682 'MAN: "ssdp:discover"',
1686 sock
.sendto(msg
, ("239.255.255.250", 1900))
1688 logger
.debug("Invalid ST")
1690 'M-SEARCH * HTTP/1.1',
1691 'HOST: 239.255.255.250:1900',
1692 'MAN: "ssdp:discover"',
1694 'ST; urn:schemas-wifialliance-org:device:WFADevice:1',
1696 sock
.sendto(msg
, ("239.255.255.250", 1900))
1698 logger
.debug("Invalid M-SEARCH")
1700 'M+SEARCH * HTTP/1.1',
1701 'HOST: 239.255.255.250:1900',
1702 'MAN: "ssdp:discover"',
1704 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1706 sock
.sendto(msg
, ("239.255.255.250", 1900))
1708 'M-SEARCH-* HTTP/1.1',
1709 'HOST: 239.255.255.250:1900',
1710 'MAN: "ssdp:discover"',
1712 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1714 sock
.sendto(msg
, ("239.255.255.250", 1900))
1716 logger
.debug("Invalid message format")
1717 sock
.sendto("NOTIFY * HTTP/1.1", ("239.255.255.250", 1900))
1719 'M-SEARCH * HTTP/1.1',
1720 'HOST: 239.255.255.250:1900',
1721 'MAN: "ssdp:discover"',
1723 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1725 sock
.sendto(msg
, ("239.255.255.250", 1900))
1729 raise Exception("Unexpected M-SEARCH response: " + r
)
1730 except socket
.timeout
:
1733 logger
.debug("Valid M-SEARCH")
1735 'M-SEARCH * HTTP/1.1',
1736 'HOST: 239.255.255.250:1900',
1737 'MAN: "ssdp:discover"',
1739 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1741 sock
.sendto(msg
, ("239.255.255.250", 1900))
1746 except socket
.timeout
:
1747 raise Exception("No SSDP response")
1749 def test_ap_wps_ssdp_burst(dev
, apdev
):
1750 """WPS AP and SSDP burst"""
1751 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
1752 add_ssdp_ap(apdev
[0]['ifname'], ap_uuid
)
1755 'M-SEARCH * HTTP/1.1',
1756 'HOST: 239.255.255.250:1900',
1757 'MAN: "ssdp:discover"',
1759 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1761 socket
.setdefaulttimeout(1)
1762 sock
= socket
.socket(socket
.AF_INET
, socket
.SOCK_DGRAM
, socket
.IPPROTO_UDP
)
1763 sock
.setsockopt(socket
.SOL_SOCKET
, socket
.SO_REUSEADDR
, 1)
1764 sock
.setsockopt(socket
.IPPROTO_IP
, socket
.IP_MULTICAST_TTL
, 2)
1765 sock
.bind(("127.0.0.1", 0))
1766 for i
in range(0, 25):
1767 sock
.sendto(msg
, ("239.255.255.250", 1900))
1772 if not r
.startswith("HTTP/1.1 200 OK\r\n"):
1773 raise Exception("Unexpected message: " + r
)
1775 except socket
.timeout
:
1778 raise Exception("Too few SSDP responses")
1780 sock
= socket
.socket(socket
.AF_INET
, socket
.SOCK_DGRAM
, socket
.IPPROTO_UDP
)
1781 sock
.setsockopt(socket
.SOL_SOCKET
, socket
.SO_REUSEADDR
, 1)
1782 sock
.setsockopt(socket
.IPPROTO_IP
, socket
.IP_MULTICAST_TTL
, 2)
1783 sock
.bind(("127.0.0.1", 0))
1784 for i
in range(0, 25):
1785 sock
.sendto(msg
, ("239.255.255.250", 1900))
1791 except socket
.timeout
:
1792 raise Exception("No SSDP response")
1794 def ssdp_get_location(uuid
):
1795 res
= ssdp_send_msearch("uuid:" + uuid
)
1797 for l
in res
.splitlines():
1798 if l
.lower().startswith("location:"):
1799 location
= l
.split(':', 1)[1].strip()
1801 if location
is None:
1802 raise Exception("No UPnP location found")
1805 def upnp_get_urls(location
):
1806 conn
= urllib
.urlopen(location
)
1807 tree
= ET
.parse(conn
)
1808 root
= tree
.getroot()
1809 urn
= '{urn:schemas-upnp-org:device-1-0}'
1810 service
= root
.find("./" + urn
+ "device/" + urn
+ "serviceList/" + urn
+ "service")
1812 res
['scpd_url'] = urlparse
.urljoin(location
, service
.find(urn
+ 'SCPDURL').text
)
1813 res
['control_url'] = urlparse
.urljoin(location
, service
.find(urn
+ 'controlURL').text
)
1814 res
['event_sub_url'] = urlparse
.urljoin(location
, service
.find(urn
+ 'eventSubURL').text
)
1817 def upnp_soap_action(conn
, path
, action
, include_soap_action
=True, soap_action_override
=None):
1818 soapns
= 'http://schemas.xmlsoap.org/soap/envelope/'
1819 wpsns
= 'urn:schemas-wifialliance-org:service:WFAWLANConfig:1'
1820 ET
.register_namespace('soapenv', soapns
)
1821 ET
.register_namespace('wfa', wpsns
)
1823 attrib
['{%s}encodingStyle' % soapns
] = 'http://schemas.xmlsoap.org/soap/encoding/'
1824 root
= ET
.Element("{%s}Envelope" % soapns
, attrib
=attrib
)
1825 body
= ET
.SubElement(root
, "{%s}Body" % soapns
)
1826 act
= ET
.SubElement(body
, "{%s}%s" % (wpsns
, action
))
1827 tree
= ET
.ElementTree(root
)
1828 soap
= StringIO
.StringIO()
1829 tree
.write(soap
, xml_declaration
=True, encoding
='utf-8')
1831 headers
= { "Content-type": 'text/xml; charset="utf-8"' }
1832 if include_soap_action
:
1833 headers
["SOAPAction"] = '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#%s"' % action
1834 elif soap_action_override
:
1835 headers
["SOAPAction"] = soap_action_override
1836 conn
.request("POST", path
, soap
.getvalue(), headers
)
1837 return conn
.getresponse()
1839 def test_ap_wps_upnp(dev
, apdev
):
1840 """WPS AP and UPnP operations"""
1841 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
1842 add_ssdp_ap(apdev
[0]['ifname'], ap_uuid
)
1844 location
= ssdp_get_location(ap_uuid
)
1845 urls
= upnp_get_urls(location
)
1847 conn
= urllib
.urlopen(urls
['scpd_url'])
1850 conn
= urllib
.urlopen(urlparse
.urljoin(location
, "unknown.html"))
1851 if conn
.getcode() != 404:
1852 raise Exception("Unexpected HTTP response to GET unknown URL")
1854 url
= urlparse
.urlparse(location
)
1855 conn
= httplib
.HTTPConnection(url
.netloc
)
1856 #conn.set_debuglevel(1)
1857 headers
= { "Content-type": 'text/xml; charset="utf-8"',
1858 "SOAPAction": '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#GetDeviceInfo"' }
1859 conn
.request("POST", "hello", "\r\n\r\n", headers
)
1860 resp
= conn
.getresponse()
1861 if resp
.status
!= 404:
1862 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1864 conn
.request("UNKNOWN", "hello", "\r\n\r\n", headers
)
1865 resp
= conn
.getresponse()
1866 if resp
.status
!= 501:
1867 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1869 headers
= { "Content-type": 'text/xml; charset="utf-8"',
1870 "SOAPAction": '"urn:some-unknown-action#GetDeviceInfo"' }
1871 ctrlurl
= urlparse
.urlparse(urls
['control_url'])
1872 conn
.request("POST", ctrlurl
.path
, "\r\n\r\n", headers
)
1873 resp
= conn
.getresponse()
1874 if resp
.status
!= 401:
1875 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1877 logger
.debug("GetDeviceInfo without SOAPAction header")
1878 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "GetDeviceInfo",
1879 include_soap_action
=False)
1880 if resp
.status
!= 401:
1881 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1883 logger
.debug("GetDeviceInfo with invalid SOAPAction header")
1885 "urn:schemas-wifialliance-org:service:WFAWLANConfig:1#GetDeviceInfo",
1886 '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1"',
1887 '"urn:schemas-wifialliance-org:service:WFAWLANConfig:123#GetDevice']:
1888 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "GetDeviceInfo",
1889 include_soap_action
=False,
1890 soap_action_override
=act
)
1891 if resp
.status
!= 401:
1892 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1894 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "GetDeviceInfo")
1895 if resp
.status
!= 200:
1896 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1898 if "NewDeviceInfo" not in dev
:
1899 raise Exception("Unexpected GetDeviceInfo response")
1901 logger
.debug("PutMessage without required parameters")
1902 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "PutMessage")
1903 if resp
.status
!= 600:
1904 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1906 logger
.debug("PutWLANResponse without required parameters")
1907 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "PutWLANResponse")
1908 if resp
.status
!= 600:
1909 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1911 logger
.debug("SetSelectedRegistrar from unregistered ER")
1912 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "SetSelectedRegistrar")
1913 if resp
.status
!= 501:
1914 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1916 logger
.debug("Unknown action")
1917 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "Unknown")
1918 if resp
.status
!= 401:
1919 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1921 def test_ap_wps_upnp_subscribe(dev
, apdev
):
1922 """WPS AP and UPnP event subscription"""
1923 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
1924 add_ssdp_ap(apdev
[0]['ifname'], ap_uuid
)
1926 location
= ssdp_get_location(ap_uuid
)
1927 urls
= upnp_get_urls(location
)
1928 eventurl
= urlparse
.urlparse(urls
['event_sub_url'])
1930 url
= urlparse
.urlparse(location
)
1931 conn
= httplib
.HTTPConnection(url
.netloc
)
1932 #conn.set_debuglevel(1)
1933 headers
= { "callback": '<http://127.0.0.1:12345/event>',
1934 "timeout": "Second-1234" }
1935 conn
.request("SUBSCRIBE", "hello", "\r\n\r\n", headers
)
1936 resp
= conn
.getresponse()
1937 if resp
.status
!= 412:
1938 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1940 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
1941 resp
= conn
.getresponse()
1942 if resp
.status
!= 412:
1943 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1945 headers
= { "NT": "upnp:event",
1946 "timeout": "Second-1234" }
1947 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
1948 resp
= conn
.getresponse()
1949 if resp
.status
!= 412:
1950 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1952 headers
= { "callback": '<http://127.0.0.1:12345/event>',
1953 "NT": "upnp:foobar",
1954 "timeout": "Second-1234" }
1955 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
1956 resp
= conn
.getresponse()
1957 if resp
.status
!= 400:
1958 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1960 logger
.debug("Valid subscription")
1961 headers
= { "callback": '<http://127.0.0.1:12345/event>',
1963 "timeout": "Second-1234" }
1964 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
1965 resp
= conn
.getresponse()
1966 if resp
.status
!= 200:
1967 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1968 sid
= resp
.getheader("sid")
1969 logger
.debug("Subscription SID " + sid
)
1971 logger
.debug("Invalid re-subscription")
1972 headers
= { "NT": "upnp:event",
1973 "sid": "123456734567854",
1974 "timeout": "Second-1234" }
1975 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
1976 resp
= conn
.getresponse()
1977 if resp
.status
!= 400:
1978 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1980 logger
.debug("Invalid re-subscription")
1981 headers
= { "NT": "upnp:event",
1982 "sid": "uuid:123456734567854",
1983 "timeout": "Second-1234" }
1984 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
1985 resp
= conn
.getresponse()
1986 if resp
.status
!= 400:
1987 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1989 logger
.debug("Invalid re-subscription")
1990 headers
= { "callback": '<http://127.0.0.1:12345/event>',
1993 "timeout": "Second-1234" }
1994 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
1995 resp
= conn
.getresponse()
1996 if resp
.status
!= 400:
1997 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1999 logger
.debug("SID mismatch in re-subscription")
2000 headers
= { "NT": "upnp:event",
2001 "sid": "uuid:4c2bca79-1ff4-4e43-85d4-952a2b8a51fb",
2002 "timeout": "Second-1234" }
2003 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2004 resp
= conn
.getresponse()
2005 if resp
.status
!= 412:
2006 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2008 logger
.debug("Valid re-subscription")
2009 headers
= { "NT": "upnp:event",
2011 "timeout": "Second-1234" }
2012 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2013 resp
= conn
.getresponse()
2014 if resp
.status
!= 200:
2015 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2016 sid2
= resp
.getheader("sid")
2017 logger
.debug("Subscription SID " + sid2
)
2020 raise Exception("Unexpected SID change")
2022 logger
.debug("Valid re-subscription")
2023 headers
= { "NT": "upnp:event",
2024 "sid": "uuid: \t \t" + sid
.split(':')[1],
2025 "timeout": "Second-1234" }
2026 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2027 resp
= conn
.getresponse()
2028 if resp
.status
!= 200:
2029 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2031 logger
.debug("Invalid unsubscription")
2032 headers
= { "sid": sid
}
2033 conn
.request("UNSUBSCRIBE", "/hello", "\r\n\r\n", headers
)
2034 resp
= conn
.getresponse()
2035 if resp
.status
!= 412:
2036 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2037 headers
= { "foo": "bar" }
2038 conn
.request("UNSUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2039 resp
= conn
.getresponse()
2040 if resp
.status
!= 412:
2041 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2043 logger
.debug("Valid unsubscription")
2044 headers
= { "sid": sid
}
2045 conn
.request("UNSUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2046 resp
= conn
.getresponse()
2047 if resp
.status
!= 200:
2048 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2050 logger
.debug("Unsubscription for not existing SID")
2051 headers
= { "sid": sid
}
2052 conn
.request("UNSUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2053 resp
= conn
.getresponse()
2054 if resp
.status
!= 412:
2055 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2057 logger
.debug("Invalid unsubscription")
2058 headers
= { "sid": " \t \tfoo" }
2059 conn
.request("UNSUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2060 resp
= conn
.getresponse()
2061 if resp
.status
!= 400:
2062 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2064 logger
.debug("Invalid unsubscription")
2065 headers
= { "sid": "uuid:\t \tfoo" }
2066 conn
.request("UNSUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2067 resp
= conn
.getresponse()
2068 if resp
.status
!= 400:
2069 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2071 logger
.debug("Invalid unsubscription")
2072 headers
= { "NT": "upnp:event",
2074 conn
.request("UNSUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2075 resp
= conn
.getresponse()
2076 if resp
.status
!= 400:
2077 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2078 headers
= { "callback": '<http://127.0.0.1:12345/event>',
2080 conn
.request("UNSUBSCRIBE", 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
)
2085 logger
.debug("Valid subscription with multiple callbacks")
2086 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>',
2088 "timeout": "Second-1234" }
2089 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2090 resp
= conn
.getresponse()
2091 if resp
.status
!= 200:
2092 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2093 sid
= resp
.getheader("sid")
2094 logger
.debug("Subscription SID " + sid
)
2096 def test_ap_wps_disabled(dev
, apdev
):
2097 """WPS operations while WPS is disabled"""
2098 ssid
= "test-wps-disabled"
2099 hostapd
.add_ap(apdev
[0]['ifname'], { "ssid": ssid
})
2100 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
2101 if "FAIL" not in hapd
.request("WPS_PBC"):
2102 raise Exception("WPS_PBC succeeded unexpectedly")
2103 if "FAIL" not in hapd
.request("WPS_CANCEL"):
2104 raise Exception("WPS_CANCEL succeeded unexpectedly")