]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_ap_wps.py
ca293d430317690a0e8582b32acc8e3bb3f518f4
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(freq
="2412")
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")
96 dev
[0].request("SET wps_cred_processing 2")
97 dev
[0].request("WPS_PBC")
98 ev
= dev
[0].wait_event(["WPS-CRED-RECEIVED"], timeout
=30)
99 dev
[0].request("SET wps_cred_processing 0")
101 raise Exception("WPS cred event not seen")
103 raise Exception("WPS attributes not included in the cred event")
104 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
106 raise Exception("Association with the AP timed out")
108 dev
[1].scan(freq
="2412")
109 bss
= dev
[1].get_bss(apdev
[0]['bssid'])
110 if "[WPS-PBC]" in bss
['flags']:
111 raise Exception("WPS-PBC flag not cleared from AP1")
112 bss
= dev
[1].get_bss(apdev
[1]['bssid'])
113 if "[WPS-PBC]" in bss
['flags']:
114 raise Exception("WPS-PBC flag bit ckeared from AP2")
116 def test_ap_wps_init_2ap_pin(dev
, apdev
):
117 """Initial two-radio AP configuration with first WPS PIN Enrollee"""
119 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "1" }
120 hostapd
.add_ap(apdev
[0]['ifname'], params
)
121 hostapd
.add_ap(apdev
[1]['ifname'], params
)
122 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
123 logger
.info("WPS provisioning step")
124 pin
= dev
[0].wps_read_pin()
125 hapd
.request("WPS_PIN any " + pin
)
126 dev
[0].scan(freq
="2412")
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
)
135 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
137 raise Exception("Association with the AP timed out")
139 dev
[1].scan(freq
="2412")
140 bss
= dev
[1].get_bss(apdev
[0]['bssid'])
141 if "[WPS-AUTH]" in bss
['flags']:
142 raise Exception("WPS-AUTH flag not cleared from AP1")
143 bss
= dev
[1].get_bss(apdev
[1]['bssid'])
144 if "[WPS-AUTH]" in bss
['flags']:
145 raise Exception("WPS-AUTH flag bit ckeared from AP2")
147 def test_ap_wps_init_through_wps_config(dev
, apdev
):
148 """Initial AP configuration using wps_config command"""
149 ssid
= "test-wps-init-config"
150 hostapd
.add_ap(apdev
[0]['ifname'],
151 { "ssid": ssid
, "eap_server": "1", "wps_state": "1" })
152 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
153 if "FAIL" in hapd
.request("WPS_CONFIG " + ssid
.encode("hex") + " WPA2PSK CCMP " + "12345678".encode("hex")):
154 raise Exception("WPS_CONFIG command failed")
155 ev
= hapd
.wait_event(["WPS-NEW-AP-SETTINGS"], timeout
=5)
157 raise Exception("Timeout on WPS-NEW-AP-SETTINGS events")
158 # It takes some time for the AP to update Beacon and Probe Response frames,
159 # so wait here before requesting the scan to be started to avoid adding
160 # extra five second wait to the test due to fetching obsolete scan results.
163 dev
[0].connect(ssid
, psk
="12345678", scan_freq
="2412", proto
="WPA2",
164 pairwise
="CCMP", group
="CCMP")
166 def test_ap_wps_conf(dev
, apdev
):
167 """WPS PBC provisioning with configured AP"""
168 ssid
= "test-wps-conf"
169 hostapd
.add_ap(apdev
[0]['ifname'],
170 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
171 "wpa_passphrase": "12345678", "wpa": "2",
172 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
173 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
174 logger
.info("WPS provisioning step")
175 hapd
.request("WPS_PBC")
176 dev
[0].dump_monitor()
177 dev
[0].request("WPS_PBC")
178 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
180 raise Exception("Association with the AP timed out")
181 status
= dev
[0].get_status()
182 if status
['wpa_state'] != 'COMPLETED':
183 raise Exception("Not fully connected")
184 if status
['bssid'] != apdev
[0]['bssid']:
185 raise Exception("Unexpected BSSID")
186 if status
['ssid'] != ssid
:
187 raise Exception("Unexpected SSID")
188 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'CCMP':
189 raise Exception("Unexpected encryption configuration")
190 if status
['key_mgmt'] != 'WPA2-PSK':
191 raise Exception("Unexpected key_mgmt")
193 sta
= hapd
.get_sta(dev
[0].p2p_interface_addr())
194 if 'wpsDeviceName' not in sta
or sta
['wpsDeviceName'] != "Device A":
195 raise Exception("Device name not available in STA command")
197 def test_ap_wps_conf_5ghz(dev
, apdev
):
198 """WPS PBC provisioning with configured AP on 5 GHz band"""
200 ssid
= "test-wps-conf"
201 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
202 "wpa_passphrase": "12345678", "wpa": "2",
203 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
204 "country_code": "FI", "hw_mode": "a", "channel": "36" }
205 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
206 logger
.info("WPS provisioning step")
207 hapd
.request("WPS_PBC")
208 dev
[0].request("WPS_PBC")
209 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
211 raise Exception("Association with the AP timed out")
213 sta
= hapd
.get_sta(dev
[0].p2p_interface_addr())
214 if 'wpsDeviceName' not in sta
or sta
['wpsDeviceName'] != "Device A":
215 raise Exception("Device name not available in STA command")
217 subprocess
.call(['sudo', 'iw', 'reg', 'set', '00'])
219 def test_ap_wps_conf_chan14(dev
, apdev
):
220 """WPS PBC provisioning with configured AP on channel 14"""
222 ssid
= "test-wps-conf"
223 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
224 "wpa_passphrase": "12345678", "wpa": "2",
225 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
226 "country_code": "JP", "hw_mode": "b", "channel": "14" }
227 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
228 logger
.info("WPS provisioning step")
229 hapd
.request("WPS_PBC")
230 dev
[0].request("WPS_PBC")
231 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
233 raise Exception("Association with the AP timed out")
235 sta
= hapd
.get_sta(dev
[0].p2p_interface_addr())
236 if 'wpsDeviceName' not in sta
or sta
['wpsDeviceName'] != "Device A":
237 raise Exception("Device name not available in STA command")
239 subprocess
.call(['sudo', 'iw', 'reg', 'set', '00'])
241 def test_ap_wps_twice(dev
, apdev
):
242 """WPS provisioning with twice to change passphrase"""
243 ssid
= "test-wps-twice"
244 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
245 "wpa_passphrase": "12345678", "wpa": "2",
246 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }
247 hostapd
.add_ap(apdev
[0]['ifname'], params
)
248 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
249 logger
.info("WPS provisioning step")
250 hapd
.request("WPS_PBC")
251 dev
[0].dump_monitor()
252 dev
[0].request("WPS_PBC")
253 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
255 raise Exception("Association with the AP timed out")
256 dev
[0].request("DISCONNECT")
258 logger
.info("Restart AP with different passphrase and re-run WPS")
259 hapd_global
= hostapd
.HostapdGlobal()
260 hapd_global
.remove(apdev
[0]['ifname'])
261 params
['wpa_passphrase'] = 'another passphrase'
262 hostapd
.add_ap(apdev
[0]['ifname'], params
)
263 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
264 logger
.info("WPS provisioning step")
265 hapd
.request("WPS_PBC")
266 dev
[0].dump_monitor()
267 dev
[0].request("WPS_PBC any")
268 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
270 raise Exception("Association with the AP timed out")
271 networks
= dev
[0].list_networks()
272 if len(networks
) > 1:
273 raise Exception("Unexpected duplicated network block present")
275 def test_ap_wps_incorrect_pin(dev
, apdev
):
276 """WPS PIN provisioning with incorrect PIN"""
277 ssid
= "test-wps-incorrect-pin"
278 hostapd
.add_ap(apdev
[0]['ifname'],
279 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
280 "wpa_passphrase": "12345678", "wpa": "2",
281 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
282 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
284 logger
.info("WPS provisioning attempt 1")
285 hapd
.request("WPS_PIN any 12345670")
286 dev
[0].dump_monitor()
287 dev
[0].request("WPS_PIN any 55554444")
288 ev
= dev
[0].wait_event(["WPS-FAIL"], timeout
=30)
290 raise Exception("WPS operation timed out")
291 if "config_error=18" not in ev
:
292 raise Exception("Incorrect config_error reported")
293 if "msg=8" not in ev
:
294 raise Exception("PIN error detected on incorrect message")
295 ev
= dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
297 raise Exception("Timeout on disconnection event")
298 dev
[0].request("WPS_CANCEL")
299 # if a scan was in progress, wait for it to complete before trying WPS again
300 ev
= dev
[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
302 status
= hapd
.request("WPS_GET_STATUS")
303 if "Last WPS result: Failed" not in status
:
304 raise Exception("WPS failure result not shown correctly")
306 logger
.info("WPS provisioning attempt 2")
307 hapd
.request("WPS_PIN any 12345670")
308 dev
[0].dump_monitor()
309 dev
[0].request("WPS_PIN any 12344444")
310 ev
= dev
[0].wait_event(["WPS-FAIL"], timeout
=30)
312 raise Exception("WPS operation timed out")
313 if "config_error=18" not in ev
:
314 raise Exception("Incorrect config_error reported")
315 if "msg=10" not in ev
:
316 raise Exception("PIN error detected on incorrect message")
317 ev
= dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
319 raise Exception("Timeout on disconnection event")
321 def test_ap_wps_conf_pin(dev
, apdev
):
322 """WPS PIN provisioning with configured AP"""
323 ssid
= "test-wps-conf-pin"
324 hostapd
.add_ap(apdev
[0]['ifname'],
325 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
326 "wpa_passphrase": "12345678", "wpa": "2",
327 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
328 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
329 logger
.info("WPS provisioning step")
330 pin
= dev
[0].wps_read_pin()
331 hapd
.request("WPS_PIN any " + pin
)
332 dev
[0].dump_monitor()
333 dev
[0].request("WPS_PIN any " + pin
)
334 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
336 raise Exception("Association with the AP timed out")
337 status
= dev
[0].get_status()
338 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
339 raise Exception("Not fully connected")
340 if status
['ssid'] != ssid
:
341 raise Exception("Unexpected SSID")
342 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'CCMP':
343 raise Exception("Unexpected encryption configuration")
344 if status
['key_mgmt'] != 'WPA2-PSK':
345 raise Exception("Unexpected key_mgmt")
347 dev
[1].scan(freq
="2412")
348 bss
= dev
[1].get_bss(apdev
[0]['bssid'])
349 if "[WPS-AUTH]" in bss
['flags']:
350 raise Exception("WPS-AUTH flag not cleared")
351 logger
.info("Try to connect from another station using the same PIN")
352 dev
[1].request("WPS_PIN any " + pin
)
353 ev
= dev
[1].wait_event(["WPS-M2D","CTRL-EVENT-CONNECTED"], timeout
=30)
355 raise Exception("Operation timed out")
356 if "WPS-M2D" not in ev
:
357 raise Exception("Unexpected WPS operation started")
359 def test_ap_wps_conf_pin_2sta(dev
, apdev
):
360 """Two stations trying to use WPS PIN at the same time"""
361 ssid
= "test-wps-conf-pin2"
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")
370 hapd
.request("WPS_PIN " + dev
[0].get_status_field("uuid") + " " + pin
)
371 hapd
.request("WPS_PIN " + dev
[1].get_status_field("uuid") + " " + pin
)
372 dev
[0].dump_monitor()
373 dev
[1].dump_monitor()
374 dev
[0].request("WPS_PIN any " + pin
)
375 dev
[1].request("WPS_PIN any " + pin
)
376 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
378 raise Exception("Association with the AP timed out")
379 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
381 raise Exception("Association with the AP timed out")
383 def test_ap_wps_conf_pin_timeout(dev
, apdev
):
384 """WPS PIN provisioning with configured AP timing out PIN"""
385 ssid
= "test-wps-conf-pin"
386 hostapd
.add_ap(apdev
[0]['ifname'],
387 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
388 "wpa_passphrase": "12345678", "wpa": "2",
389 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
390 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
391 addr
= dev
[0].p2p_interface_addr()
392 pin
= dev
[0].wps_read_pin()
393 if "FAIL" not in hapd
.request("WPS_PIN "):
394 raise Exception("Unexpected success on invalid WPS_PIN")
395 hapd
.request("WPS_PIN any " + pin
+ " 1")
397 dev
[0].request("WPS_PIN any " + pin
)
398 ev
= hapd
.wait_event(["WPS-PIN-NEEDED"], timeout
=20)
400 raise Exception("WPS-PIN-NEEDED event timed out")
401 ev
= dev
[0].wait_event(["WPS-M2D"])
403 raise Exception("M2D not reported")
404 dev
[0].request("WPS_CANCEL")
406 hapd
.request("WPS_PIN any " + pin
+ " 20 " + addr
)
407 dev
[0].request("WPS_PIN any " + pin
)
408 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
410 raise Exception("Association with the AP timed out")
412 def test_ap_wps_reg_connect(dev
, apdev
):
413 """WPS registrar using AP PIN to connect"""
414 ssid
= "test-wps-reg-ap-pin"
416 hostapd
.add_ap(apdev
[0]['ifname'],
417 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
418 "wpa_passphrase": "12345678", "wpa": "2",
419 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
421 logger
.info("WPS provisioning step")
422 dev
[0].dump_monitor()
423 dev
[0].wps_reg(apdev
[0]['bssid'], appin
)
424 status
= dev
[0].get_status()
425 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
426 raise Exception("Not fully connected")
427 if status
['ssid'] != ssid
:
428 raise Exception("Unexpected SSID")
429 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'CCMP':
430 raise Exception("Unexpected encryption configuration")
431 if status
['key_mgmt'] != 'WPA2-PSK':
432 raise Exception("Unexpected key_mgmt")
434 def check_wps_reg_failure(dev
, ap
, appin
):
435 dev
.request("WPS_REG " + ap
['bssid'] + " " + appin
)
436 ev
= dev
.wait_event(["WPS-SUCCESS", "WPS-FAIL"], timeout
=15)
438 raise Exception("WPS operation timed out")
439 if "WPS-SUCCESS" in ev
:
440 raise Exception("WPS operation succeeded unexpectedly")
441 if "config_error=15" not in ev
:
442 raise Exception("WPS setup locked state was not reported correctly")
444 def test_ap_wps_random_ap_pin(dev
, apdev
):
445 """WPS registrar using random AP PIN"""
446 ssid
= "test-wps-reg-random-ap-pin"
447 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
448 hostapd
.add_ap(apdev
[0]['ifname'],
449 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
450 "wpa_passphrase": "12345678", "wpa": "2",
451 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
452 "device_name": "Wireless AP", "manufacturer": "Company",
453 "model_name": "WAP", "model_number": "123",
454 "serial_number": "12345", "device_type": "6-0050F204-1",
455 "os_version": "01020300",
456 "config_methods": "label push_button",
457 "uuid": ap_uuid
, "upnp_iface": "lo" })
458 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
459 appin
= hapd
.request("WPS_AP_PIN random")
461 raise Exception("Could not generate random AP PIN")
462 if appin
not in hapd
.request("WPS_AP_PIN get"):
463 raise Exception("Could not fetch current AP PIN")
464 logger
.info("WPS provisioning step")
465 dev
[0].wps_reg(apdev
[0]['bssid'], appin
)
467 hapd
.request("WPS_AP_PIN disable")
468 logger
.info("WPS provisioning step with AP PIN disabled")
469 check_wps_reg_failure(dev
[1], apdev
[0], appin
)
471 logger
.info("WPS provisioning step with AP PIN reset")
473 hapd
.request("WPS_AP_PIN set " + appin
)
474 dev
[1].wps_reg(apdev
[0]['bssid'], appin
)
475 dev
[0].request("REMOVE_NETWORK all")
476 dev
[1].request("REMOVE_NETWORK all")
477 dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
478 dev
[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
480 logger
.info("WPS provisioning step after AP PIN timeout")
481 hapd
.request("WPS_AP_PIN disable")
482 appin
= hapd
.request("WPS_AP_PIN random 1")
484 if "FAIL" not in hapd
.request("WPS_AP_PIN get"):
485 raise Exception("AP PIN unexpectedly still enabled")
486 check_wps_reg_failure(dev
[0], apdev
[0], appin
)
488 logger
.info("WPS provisioning step after AP PIN timeout(2)")
489 hapd
.request("WPS_AP_PIN disable")
491 hapd
.request("WPS_AP_PIN set " + appin
+ " 1")
493 if "FAIL" not in hapd
.request("WPS_AP_PIN get"):
494 raise Exception("AP PIN unexpectedly still enabled")
495 check_wps_reg_failure(dev
[1], apdev
[0], appin
)
497 def test_ap_wps_reg_config(dev
, apdev
):
498 """WPS registrar configuring an AP using AP PIN"""
499 ssid
= "test-wps-init-ap-pin"
501 hostapd
.add_ap(apdev
[0]['ifname'],
502 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
504 logger
.info("WPS configuration step")
505 dev
[0].dump_monitor()
506 new_ssid
= "wps-new-ssid"
507 new_passphrase
= "1234567890"
508 dev
[0].wps_reg(apdev
[0]['bssid'], appin
, new_ssid
, "WPA2PSK", "CCMP",
510 status
= dev
[0].get_status()
511 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
512 raise Exception("Not fully connected")
513 if status
['ssid'] != new_ssid
:
514 raise Exception("Unexpected SSID")
515 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'CCMP':
516 raise Exception("Unexpected encryption configuration")
517 if status
['key_mgmt'] != 'WPA2-PSK':
518 raise Exception("Unexpected key_mgmt")
520 logger
.info("Re-configure back to open")
521 dev
[0].request("REMOVE_NETWORK all")
522 dev
[0].request("BSS_FLUSH 0")
523 dev
[0].request("SCAN freq=2412 only_new=1")
524 ev
= dev
[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15)
526 raise Exception("Scan timed out")
527 dev
[0].dump_monitor()
528 dev
[0].wps_reg(apdev
[0]['bssid'], appin
, "wps-open", "OPEN", "NONE", "")
529 status
= dev
[0].get_status()
530 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
531 raise Exception("Not fully connected")
532 if status
['ssid'] != "wps-open":
533 raise Exception("Unexpected SSID")
534 if status
['key_mgmt'] != 'NONE':
535 raise Exception("Unexpected key_mgmt")
537 def test_ap_wps_reg_config_ext_processing(dev
, apdev
):
538 """WPS registrar configuring an AP with external config processing"""
539 ssid
= "test-wps-init-ap-pin"
541 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
542 "wps_cred_processing": "1", "ap_pin": appin
}
543 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
544 new_ssid
= "wps-new-ssid"
545 new_passphrase
= "1234567890"
546 dev
[0].wps_reg(apdev
[0]['bssid'], appin
, new_ssid
, "WPA2PSK", "CCMP",
547 new_passphrase
, no_wait
=True)
548 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=15)
550 raise Exception("WPS registrar operation timed out")
551 ev
= hapd
.wait_event(["WPS-NEW-AP-SETTINGS"], timeout
=15)
553 raise Exception("WPS configuration timed out")
555 raise Exception("AP Settings missing from event")
556 hapd
.request("SET wps_cred_processing 0")
557 if "FAIL" in hapd
.request("WPS_CONFIG " + new_ssid
.encode("hex") + " WPA2PSK CCMP " + new_passphrase
.encode("hex")):
558 raise Exception("WPS_CONFIG command failed")
559 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
561 raise Exception("Association with the AP timed out")
563 def test_ap_wps_reg_config_tkip(dev
, apdev
):
564 """WPS registrar configuring AP to use TKIP and AP upgrading to TKIP+CCMP"""
565 ssid
= "test-wps-init-ap"
567 hostapd
.add_ap(apdev
[0]['ifname'],
568 { "ssid": ssid
, "eap_server": "1", "wps_state": "1",
570 logger
.info("WPS configuration step")
571 dev
[0].request("SET wps_version_number 0x10")
572 dev
[0].dump_monitor()
573 new_ssid
= "wps-new-ssid-with-tkip"
574 new_passphrase
= "1234567890"
575 dev
[0].wps_reg(apdev
[0]['bssid'], appin
, new_ssid
, "WPAPSK", "TKIP",
577 logger
.info("Re-connect to verify WPA2 mixed mode")
578 dev
[0].request("DISCONNECT")
580 dev
[0].set_network(id, "pairwise", "CCMP")
581 dev
[0].set_network(id, "proto", "RSN")
582 dev
[0].connect_network(id)
583 status
= dev
[0].get_status()
584 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
585 raise Exception("Not fully connected")
586 if status
['ssid'] != new_ssid
:
587 raise Exception("Unexpected SSID")
588 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'TKIP':
589 raise Exception("Unexpected encryption configuration")
590 if status
['key_mgmt'] != 'WPA2-PSK':
591 raise Exception("Unexpected key_mgmt")
593 def test_ap_wps_setup_locked(dev
, apdev
):
594 """WPS registrar locking up AP setup on AP PIN failures"""
595 ssid
= "test-wps-incorrect-ap-pin"
597 hostapd
.add_ap(apdev
[0]['ifname'],
598 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
599 "wpa_passphrase": "12345678", "wpa": "2",
600 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
602 new_ssid
= "wps-new-ssid-test"
603 new_passphrase
= "1234567890"
605 ap_setup_locked
=False
606 for pin
in ["55554444", "1234", "12345678", "00000000", "11111111"]:
607 dev
[0].dump_monitor()
608 logger
.info("Try incorrect AP PIN - attempt " + pin
)
609 dev
[0].wps_reg(apdev
[0]['bssid'], pin
, new_ssid
, "WPA2PSK",
610 "CCMP", new_passphrase
, no_wait
=True)
611 ev
= dev
[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"])
613 raise Exception("Timeout on receiving WPS operation failure event")
614 if "CTRL-EVENT-CONNECTED" in ev
:
615 raise Exception("Unexpected connection")
616 if "config_error=15" in ev
:
617 logger
.info("AP Setup Locked")
619 elif "config_error=18" not in ev
:
620 raise Exception("config_error=18 not reported")
621 ev
= dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
623 raise Exception("Timeout on disconnection event")
625 if not ap_setup_locked
:
626 raise Exception("AP setup was not locked")
628 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
629 status
= hapd
.request("WPS_GET_STATUS")
630 if "Last WPS result: Failed" not in status
:
631 raise Exception("WPS failure result not shown correctly")
632 if "Peer Address: " + dev
[0].p2p_interface_addr() not in status
:
633 raise Exception("Peer address not shown correctly")
636 dev
[0].dump_monitor()
637 logger
.info("WPS provisioning step")
638 pin
= dev
[0].wps_read_pin()
639 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
640 hapd
.request("WPS_PIN any " + pin
)
641 dev
[0].request("WPS_PIN any " + pin
)
642 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=30)
644 raise Exception("WPS success was not reported")
645 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
647 raise Exception("Association with the AP timed out")
649 appin
= hapd
.request("WPS_AP_PIN random")
651 raise Exception("Could not generate random AP PIN")
652 ev
= hapd
.wait_event(["WPS-AP-SETUP-UNLOCKED"], timeout
=10)
654 raise Exception("Failed to unlock AP PIN")
656 def test_ap_wps_setup_locked_timeout(dev
, apdev
):
657 """WPS re-enabling AP PIN after timeout"""
658 ssid
= "test-wps-incorrect-ap-pin"
660 hostapd
.add_ap(apdev
[0]['ifname'],
661 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
662 "wpa_passphrase": "12345678", "wpa": "2",
663 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
665 new_ssid
= "wps-new-ssid-test"
666 new_passphrase
= "1234567890"
668 ap_setup_locked
=False
669 for pin
in ["55554444", "1234", "12345678", "00000000", "11111111"]:
670 dev
[0].dump_monitor()
671 logger
.info("Try incorrect AP PIN - attempt " + pin
)
672 dev
[0].wps_reg(apdev
[0]['bssid'], pin
, new_ssid
, "WPA2PSK",
673 "CCMP", new_passphrase
, no_wait
=True)
674 ev
= dev
[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"])
676 raise Exception("Timeout on receiving WPS operation failure event")
677 if "CTRL-EVENT-CONNECTED" in ev
:
678 raise Exception("Unexpected connection")
679 if "config_error=15" in ev
:
680 logger
.info("AP Setup Locked")
683 elif "config_error=18" not in ev
:
684 raise Exception("config_error=18 not reported")
685 ev
= dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
687 raise Exception("Timeout on disconnection event")
689 if not ap_setup_locked
:
690 raise Exception("AP setup was not locked")
691 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
692 ev
= hapd
.wait_event(["WPS-AP-SETUP-UNLOCKED"], timeout
=80)
694 raise Exception("AP PIN did not get unlocked on 60 second timeout")
696 def test_ap_wps_pbc_overlap_2ap(dev
, apdev
):
697 """WPS PBC session overlap with two active APs"""
698 hostapd
.add_ap(apdev
[0]['ifname'],
699 { "ssid": "wps1", "eap_server": "1", "wps_state": "2",
700 "wpa_passphrase": "12345678", "wpa": "2",
701 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
702 "wps_independent": "1"})
703 hostapd
.add_ap(apdev
[1]['ifname'],
704 { "ssid": "wps2", "eap_server": "1", "wps_state": "2",
705 "wpa_passphrase": "123456789", "wpa": "2",
706 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
707 "wps_independent": "1"})
708 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
709 hapd
.request("WPS_PBC")
710 hapd2
= hostapd
.Hostapd(apdev
[1]['ifname'])
711 hapd2
.request("WPS_PBC")
712 logger
.info("WPS provisioning step")
713 dev
[0].dump_monitor()
714 dev
[0].request("WPS_PBC")
715 ev
= dev
[0].wait_event(["WPS-OVERLAP-DETECTED"], timeout
=15)
717 raise Exception("PBC session overlap not detected")
719 def test_ap_wps_pbc_overlap_2sta(dev
, apdev
):
720 """WPS PBC session overlap with two active STAs"""
721 ssid
= "test-wps-pbc-overlap"
722 hostapd
.add_ap(apdev
[0]['ifname'],
723 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
724 "wpa_passphrase": "12345678", "wpa": "2",
725 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
726 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
727 logger
.info("WPS provisioning step")
728 hapd
.request("WPS_PBC")
729 dev
[0].dump_monitor()
730 dev
[1].dump_monitor()
731 dev
[0].request("WPS_PBC")
732 dev
[1].request("WPS_PBC")
733 ev
= dev
[0].wait_event(["WPS-M2D"], timeout
=15)
735 raise Exception("PBC session overlap not detected (dev0)")
736 if "config_error=12" not in ev
:
737 raise Exception("PBC session overlap not correctly reported (dev0)")
738 ev
= dev
[1].wait_event(["WPS-M2D"], timeout
=15)
740 raise Exception("PBC session overlap not detected (dev1)")
741 if "config_error=12" not in ev
:
742 raise Exception("PBC session overlap not correctly reported (dev1)")
743 hapd
.request("WPS_CANCEL")
744 ret
= hapd
.request("WPS_PBC")
745 if "FAIL" not in ret
:
746 raise Exception("PBC mode allowed to be started while PBC overlap still active")
748 def test_ap_wps_cancel(dev
, apdev
):
749 """WPS AP cancelling enabled config method"""
750 ssid
= "test-wps-ap-cancel"
751 hostapd
.add_ap(apdev
[0]['ifname'],
752 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
753 "wpa_passphrase": "12345678", "wpa": "2",
754 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
755 bssid
= apdev
[0]['bssid']
756 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
758 logger
.info("Verify PBC enable/cancel")
759 hapd
.request("WPS_PBC")
760 dev
[0].scan(freq
="2412")
761 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
762 if "[WPS-PBC]" not in bss
['flags']:
763 raise Exception("WPS-PBC flag missing")
764 if "FAIL" in hapd
.request("WPS_CANCEL"):
765 raise Exception("WPS_CANCEL failed")
766 dev
[0].scan(freq
="2412")
767 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
768 if "[WPS-PBC]" in bss
['flags']:
769 raise Exception("WPS-PBC flag not cleared")
771 logger
.info("Verify PIN enable/cancel")
772 hapd
.request("WPS_PIN any 12345670")
773 dev
[0].scan(freq
="2412")
774 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
775 if "[WPS-AUTH]" not in bss
['flags']:
776 raise Exception("WPS-AUTH flag missing")
777 if "FAIL" in hapd
.request("WPS_CANCEL"):
778 raise Exception("WPS_CANCEL failed")
779 dev
[0].scan(freq
="2412")
780 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
781 if "[WPS-AUTH]" in bss
['flags']:
782 raise Exception("WPS-AUTH flag not cleared")
784 def test_ap_wps_er_add_enrollee(dev
, apdev
):
785 """WPS ER configuring AP and adding a new enrollee using PIN"""
786 ssid
= "wps-er-add-enrollee"
788 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
789 hostapd
.add_ap(apdev
[0]['ifname'],
790 { "ssid": ssid
, "eap_server": "1", "wps_state": "1",
791 "device_name": "Wireless AP", "manufacturer": "Company",
792 "model_name": "WAP", "model_number": "123",
793 "serial_number": "12345", "device_type": "6-0050F204-1",
794 "os_version": "01020300",
795 "config_methods": "label push_button",
796 "ap_pin": ap_pin
, "uuid": ap_uuid
, "upnp_iface": "lo"})
797 logger
.info("WPS configuration step")
798 new_passphrase
= "1234567890"
799 dev
[0].dump_monitor()
800 dev
[0].wps_reg(apdev
[0]['bssid'], ap_pin
, ssid
, "WPA2PSK", "CCMP",
802 status
= dev
[0].get_status()
803 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
804 raise Exception("Not fully connected")
805 if status
['ssid'] != ssid
:
806 raise Exception("Unexpected SSID")
807 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'CCMP':
808 raise Exception("Unexpected encryption configuration")
809 if status
['key_mgmt'] != 'WPA2-PSK':
810 raise Exception("Unexpected key_mgmt")
812 logger
.info("Start ER")
813 dev
[0].request("WPS_ER_START ifname=lo")
814 ev
= dev
[0].wait_event(["WPS-ER-AP-ADD"], timeout
=15)
816 raise Exception("AP discovery timed out")
817 if ap_uuid
not in ev
:
818 raise Exception("Expected AP UUID not found")
820 logger
.info("Learn AP configuration through UPnP")
821 dev
[0].dump_monitor()
822 dev
[0].request("WPS_ER_LEARN " + ap_uuid
+ " " + ap_pin
)
823 ev
= dev
[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout
=15)
825 raise Exception("AP learn timed out")
826 if ap_uuid
not in ev
:
827 raise Exception("Expected AP UUID not in settings")
828 if "ssid=" + ssid
not in ev
:
829 raise Exception("Expected SSID not in settings")
830 if "key=" + new_passphrase
not in ev
:
831 raise Exception("Expected passphrase not in settings")
833 logger
.info("Add Enrollee using ER")
834 pin
= dev
[1].wps_read_pin()
835 dev
[0].dump_monitor()
836 dev
[0].request("WPS_ER_PIN any " + pin
+ " " + dev
[1].p2p_interface_addr())
837 dev
[1].dump_monitor()
838 dev
[1].request("WPS_PIN any " + pin
)
839 ev
= dev
[1].wait_event(["WPS-SUCCESS"], timeout
=30)
841 raise Exception("Enrollee did not report success")
842 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
844 raise Exception("Association with the AP timed out")
845 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=15)
847 raise Exception("WPS ER did not report success")
848 hwsim_utils
.test_connectivity_sta(dev
[0], dev
[1])
850 logger
.info("Add a specific Enrollee using ER")
851 pin
= dev
[2].wps_read_pin()
852 addr2
= dev
[2].p2p_interface_addr()
853 dev
[0].dump_monitor()
854 dev
[2].dump_monitor()
855 dev
[2].request("WPS_PIN any " + pin
)
856 ev
= dev
[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout
=10)
858 raise Exception("Enrollee not seen")
860 raise Exception("Unexpected Enrollee MAC address")
861 dev
[0].request("WPS_ER_PIN " + addr2
+ " " + pin
+ " " + addr2
)
862 ev
= dev
[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
864 raise Exception("Association with the AP timed out")
865 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=15)
867 raise Exception("WPS ER did not report success")
869 logger
.info("Verify registrar selection behavior")
870 dev
[0].request("WPS_ER_PIN any " + pin
+ " " + dev
[1].p2p_interface_addr())
871 dev
[1].request("DISCONNECT")
872 dev
[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
873 dev
[1].scan(freq
="2412")
874 bss
= dev
[1].get_bss(apdev
[0]['bssid'])
875 if "[WPS-AUTH]" not in bss
['flags']:
876 raise Exception("WPS-AUTH flag missing")
878 logger
.info("Stop ER")
879 dev
[0].dump_monitor()
880 dev
[0].request("WPS_ER_STOP")
881 ev
= dev
[0].wait_event(["WPS-ER-AP-REMOVE"])
883 raise Exception("WPS ER unsubscription timed out")
884 # It takes some time for the UPnP UNSUBSCRIBE command to go through, so wait
885 # a bit before verifying that the scan results have change.
888 dev
[1].scan(freq
="2412")
889 bss
= dev
[1].get_bss(apdev
[0]['bssid'])
890 if "[WPS-AUTH]" in bss
['flags']:
891 raise Exception("WPS-AUTH flag not removed")
893 def test_ap_wps_er_add_enrollee_pbc(dev
, apdev
):
894 """WPS ER connected to AP and adding a new enrollee using PBC"""
895 ssid
= "wps-er-add-enrollee-pbc"
897 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
898 hostapd
.add_ap(apdev
[0]['ifname'],
899 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
900 "wpa_passphrase": "12345678", "wpa": "2",
901 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
902 "device_name": "Wireless AP", "manufacturer": "Company",
903 "model_name": "WAP", "model_number": "123",
904 "serial_number": "12345", "device_type": "6-0050F204-1",
905 "os_version": "01020300",
906 "config_methods": "label push_button",
907 "ap_pin": ap_pin
, "uuid": ap_uuid
, "upnp_iface": "lo"})
908 logger
.info("Learn AP configuration")
909 dev
[0].dump_monitor()
910 dev
[0].wps_reg(apdev
[0]['bssid'], ap_pin
)
911 status
= dev
[0].get_status()
912 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
913 raise Exception("Not fully connected")
915 logger
.info("Start ER")
916 dev
[0].request("WPS_ER_START ifname=lo")
917 ev
= dev
[0].wait_event(["WPS-ER-AP-ADD"], timeout
=15)
919 raise Exception("AP discovery timed out")
920 if ap_uuid
not in ev
:
921 raise Exception("Expected AP UUID not found")
923 logger
.info("Use learned network configuration on ER")
924 dev
[0].request("WPS_ER_SET_CONFIG " + ap_uuid
+ " 0")
926 logger
.info("Add Enrollee using ER and PBC")
927 dev
[0].dump_monitor()
928 enrollee
= dev
[1].p2p_interface_addr()
929 dev
[1].dump_monitor()
930 dev
[1].request("WPS_PBC")
932 for i
in range(0, 2):
933 ev
= dev
[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout
=15)
935 raise Exception("Enrollee discovery timed out")
939 raise Exception("Expected Enrollee not found")
940 dev
[0].request("WPS_ER_PBC " + enrollee
)
942 ev
= dev
[1].wait_event(["WPS-SUCCESS"], timeout
=15)
944 raise Exception("Enrollee did not report success")
945 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
947 raise Exception("Association with the AP timed out")
948 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=15)
950 raise Exception("WPS ER did not report success")
951 hwsim_utils
.test_connectivity_sta(dev
[0], dev
[1])
953 # verify BSSID selection of the AP instead of UUID
954 if "FAIL" in dev
[0].request("WPS_ER_SET_CONFIG " + apdev
[0]['bssid'] + " 0"):
955 raise Exception("Could not select AP based on BSSID")
957 def test_ap_wps_er_v10_add_enrollee_pin(dev
, apdev
):
958 """WPS v1.0 ER connected to AP and adding a new enrollee using PIN"""
959 ssid
= "wps-er-add-enrollee-pbc"
961 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
962 hostapd
.add_ap(apdev
[0]['ifname'],
963 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
964 "wpa_passphrase": "12345678", "wpa": "2",
965 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
966 "device_name": "Wireless AP", "manufacturer": "Company",
967 "model_name": "WAP", "model_number": "123",
968 "serial_number": "12345", "device_type": "6-0050F204-1",
969 "os_version": "01020300",
970 "config_methods": "label push_button",
971 "ap_pin": ap_pin
, "uuid": ap_uuid
, "upnp_iface": "lo"})
972 logger
.info("Learn AP configuration")
973 dev
[0].request("SET wps_version_number 0x10")
974 dev
[0].dump_monitor()
975 dev
[0].wps_reg(apdev
[0]['bssid'], ap_pin
)
976 status
= dev
[0].get_status()
977 if status
['wpa_state'] != 'COMPLETED' or status
['bssid'] != apdev
[0]['bssid']:
978 raise Exception("Not fully connected")
980 logger
.info("Start ER")
981 dev
[0].request("WPS_ER_START ifname=lo")
982 ev
= dev
[0].wait_event(["WPS-ER-AP-ADD"], timeout
=15)
984 raise Exception("AP discovery timed out")
985 if ap_uuid
not in ev
:
986 raise Exception("Expected AP UUID not found")
988 logger
.info("Use learned network configuration on ER")
989 dev
[0].request("WPS_ER_SET_CONFIG " + ap_uuid
+ " 0")
991 logger
.info("Add Enrollee using ER and PIN")
992 enrollee
= dev
[1].p2p_interface_addr()
993 pin
= dev
[1].wps_read_pin()
994 dev
[0].dump_monitor()
995 dev
[0].request("WPS_ER_PIN any " + pin
+ " " + enrollee
)
996 dev
[1].dump_monitor()
997 dev
[1].request("WPS_PIN any " + pin
)
998 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
1000 raise Exception("Association with the AP timed out")
1001 ev
= dev
[0].wait_event(["WPS-SUCCESS"], timeout
=15)
1003 raise Exception("WPS ER did not report success")
1005 def test_ap_wps_er_config_ap(dev
, apdev
):
1006 """WPS ER configuring AP over UPnP"""
1007 ssid
= "wps-er-ap-config"
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"})
1021 logger
.info("Connect ER to the AP")
1022 dev
[0].connect(ssid
, psk
="12345678", scan_freq
="2412")
1024 logger
.info("WPS configuration step")
1025 dev
[0].request("WPS_ER_START ifname=lo")
1026 ev
= dev
[0].wait_event(["WPS-ER-AP-ADD"], timeout
=15)
1028 raise Exception("AP discovery timed out")
1029 if ap_uuid
not in ev
:
1030 raise Exception("Expected AP UUID not found")
1031 new_passphrase
= "1234567890"
1032 dev
[0].request("WPS_ER_CONFIG " + apdev
[0]['bssid'] + " " + ap_pin
+ " " +
1033 ssid
.encode("hex") + " WPA2PSK CCMP " +
1034 new_passphrase
.encode("hex"))
1035 ev
= dev
[0].wait_event(["WPS-SUCCESS"])
1037 raise Exception("WPS ER configuration operation timed out")
1038 dev
[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
1039 dev
[0].connect(ssid
, psk
="1234567890", scan_freq
="2412")
1041 def test_ap_wps_fragmentation(dev
, apdev
):
1042 """WPS with fragmentation in EAP-WSC and mixed mode WPA+WPA2"""
1043 ssid
= "test-wps-fragmentation"
1045 hostapd
.add_ap(apdev
[0]['ifname'],
1046 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1047 "wpa_passphrase": "12345678", "wpa": "3",
1048 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
1049 "wpa_pairwise": "TKIP", "ap_pin": appin
,
1050 "fragment_size": "50" })
1051 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1052 logger
.info("WPS provisioning step (PBC)")
1053 hapd
.request("WPS_PBC")
1054 dev
[0].dump_monitor()
1055 dev
[0].request("SET wps_fragment_size 50")
1056 dev
[0].request("WPS_PBC")
1057 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
1059 raise Exception("Association with the AP timed out")
1060 status
= dev
[0].get_status()
1061 if status
['wpa_state'] != 'COMPLETED':
1062 raise Exception("Not fully connected")
1063 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'TKIP':
1064 raise Exception("Unexpected encryption configuration")
1065 if status
['key_mgmt'] != 'WPA2-PSK':
1066 raise Exception("Unexpected key_mgmt")
1068 logger
.info("WPS provisioning step (PIN)")
1069 pin
= dev
[1].wps_read_pin()
1070 hapd
.request("WPS_PIN any " + pin
)
1071 dev
[1].request("SET wps_fragment_size 50")
1072 dev
[1].request("WPS_PIN any " + pin
)
1073 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
1075 raise Exception("Association with the AP timed out")
1076 status
= dev
[1].get_status()
1077 if status
['wpa_state'] != 'COMPLETED':
1078 raise Exception("Not fully connected")
1079 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'TKIP':
1080 raise Exception("Unexpected encryption configuration")
1081 if status
['key_mgmt'] != 'WPA2-PSK':
1082 raise Exception("Unexpected key_mgmt")
1084 logger
.info("WPS connection as registrar")
1085 dev
[2].request("SET wps_fragment_size 50")
1086 dev
[2].wps_reg(apdev
[0]['bssid'], appin
)
1087 status
= dev
[2].get_status()
1088 if status
['wpa_state'] != 'COMPLETED':
1089 raise Exception("Not fully connected")
1090 if status
['pairwise_cipher'] != 'CCMP' or status
['group_cipher'] != 'TKIP':
1091 raise Exception("Unexpected encryption configuration")
1092 if status
['key_mgmt'] != 'WPA2-PSK':
1093 raise Exception("Unexpected key_mgmt")
1095 def test_ap_wps_new_version_sta(dev
, apdev
):
1096 """WPS compatibility with new version number on the station"""
1097 ssid
= "test-wps-ver"
1098 hostapd
.add_ap(apdev
[0]['ifname'],
1099 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1100 "wpa_passphrase": "12345678", "wpa": "2",
1101 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
1102 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1103 logger
.info("WPS provisioning step")
1104 hapd
.request("WPS_PBC")
1105 dev
[0].dump_monitor()
1106 dev
[0].request("SET wps_version_number 0x43")
1107 dev
[0].request("SET wps_vendor_ext_m1 000137100100020001")
1108 dev
[0].request("WPS_PBC")
1109 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
1111 raise Exception("Association with the AP timed out")
1113 def test_ap_wps_new_version_ap(dev
, apdev
):
1114 """WPS compatibility with new version number on the AP"""
1115 ssid
= "test-wps-ver"
1116 hostapd
.add_ap(apdev
[0]['ifname'],
1117 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1118 "wpa_passphrase": "12345678", "wpa": "2",
1119 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
1120 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1121 logger
.info("WPS provisioning step")
1122 if "FAIL" in hapd
.request("SET wps_version_number 0x43"):
1123 raise Exception("Failed to enable test functionality")
1124 hapd
.request("WPS_PBC")
1125 dev
[0].dump_monitor()
1126 dev
[0].request("WPS_PBC")
1127 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
1128 hapd
.request("SET wps_version_number 0x20")
1130 raise Exception("Association with the AP timed out")
1132 def test_ap_wps_check_pin(dev
, apdev
):
1133 """Verify PIN checking through control interface"""
1134 hostapd
.add_ap(apdev
[0]['ifname'],
1135 { "ssid": "wps", "eap_server": "1", "wps_state": "2",
1136 "wpa_passphrase": "12345678", "wpa": "2",
1137 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
1138 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1139 for t
in [ ("12345670", "12345670"),
1140 ("12345678", "FAIL-CHECKSUM"),
1142 ("1234-5670", "12345670"),
1143 ("1234 5670", "12345670"),
1144 ("1-2.3:4 5670", "12345670") ]:
1145 res
= hapd
.request("WPS_CHECK_PIN " + t
[0]).rstrip('\n')
1146 res2
= dev
[0].request("WPS_CHECK_PIN " + t
[0]).rstrip('\n')
1148 raise Exception("Unexpected difference in WPS_CHECK_PIN responses")
1150 raise Exception("Incorrect WPS_CHECK_PIN response {} (expected {})".format(res
, t
[1]))
1152 if "FAIL" not in hapd
.request("WPS_CHECK_PIN 12345"):
1153 raise Exception("Unexpected WPS_CHECK_PIN success")
1154 if "FAIL" not in hapd
.request("WPS_CHECK_PIN 123456789"):
1155 raise Exception("Unexpected WPS_CHECK_PIN success")
1157 for i
in range(0, 10):
1158 pin
= dev
[0].request("WPS_PIN get")
1159 rpin
= dev
[0].request("WPS_CHECK_PIN " + pin
).rstrip('\n')
1161 raise Exception("Random PIN validation failed for " + pin
)
1163 def test_ap_wps_wep_config(dev
, apdev
):
1164 """WPS 2.0 AP rejecting WEP configuration"""
1165 ssid
= "test-wps-config"
1167 hostapd
.add_ap(apdev
[0]['ifname'],
1168 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1170 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1171 dev
[0].wps_reg(apdev
[0]['bssid'], appin
, "wps-new-ssid-wep", "OPEN", "WEP",
1172 "hello", no_wait
=True)
1173 ev
= hapd
.wait_event(["WPS-FAIL"], timeout
=15)
1175 raise Exception("WPS-FAIL timed out")
1176 if "reason=2" not in ev
:
1177 raise Exception("Unexpected reason code in WPS-FAIL")
1178 status
= hapd
.request("WPS_GET_STATUS")
1179 if "Last WPS result: Failed" not in status
:
1180 raise Exception("WPS failure result not shown correctly")
1181 if "Failure Reason: WEP Prohibited" not in status
:
1182 raise Exception("Failure reason not reported correctly")
1183 if "Peer Address: " + dev
[0].p2p_interface_addr() not in status
:
1184 raise Exception("Peer address not shown correctly")
1186 def test_ap_wps_wep_enroll(dev
, apdev
):
1187 """WPS 2.0 STA rejecting WEP configuration"""
1188 ssid
= "test-wps-wep"
1189 hostapd
.add_ap(apdev
[0]['ifname'],
1190 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1191 "skip_cred_build": "1", "extra_cred": "wps-wep-cred" })
1192 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1193 hapd
.request("WPS_PBC")
1194 dev
[0].request("WPS_PBC")
1195 ev
= dev
[0].wait_event(["WPS-FAIL"], timeout
=15)
1197 raise Exception("WPS-FAIL event timed out")
1198 if "msg=12" not in ev
or "reason=2 (WEP Prohibited)" not in ev
:
1199 raise Exception("Unexpected WPS-FAIL event: " + ev
)
1201 def test_ap_wps_ie_fragmentation(dev
, apdev
):
1202 """WPS AP using fragmented WPS IE"""
1203 ssid
= "test-wps-ie-fragmentation"
1204 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1205 "wpa_passphrase": "12345678", "wpa": "2",
1206 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
1207 "device_name": "1234567890abcdef1234567890abcdef",
1208 "manufacturer": "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
1209 "model_name": "1234567890abcdef1234567890abcdef",
1210 "model_number": "1234567890abcdef1234567890abcdef",
1211 "serial_number": "1234567890abcdef1234567890abcdef" }
1212 hostapd
.add_ap(apdev
[0]['ifname'], params
)
1213 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1214 hapd
.request("WPS_PBC")
1215 dev
[0].request("WPS_PBC")
1216 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
1218 raise Exception("Association with the AP timed out")
1219 bss
= dev
[0].get_bss(apdev
[0]['bssid'])
1220 if "wps_device_name" not in bss
or bss
['wps_device_name'] != "1234567890abcdef1234567890abcdef":
1222 raise Exception("Device Name not received correctly")
1223 if len(re
.findall("dd..0050f204", bss
['ie'])) != 2:
1224 raise Exception("Unexpected number of WPS IEs")
1226 def get_psk(pskfile
):
1228 with
open(pskfile
, "r") as f
:
1229 lines
= f
.read().splitlines()
1231 if l
== "# WPA PSKs":
1233 (addr
,psk
) = l
.split(' ')
1237 def test_ap_wps_per_station_psk(dev
, apdev
):
1238 """WPS PBC provisioning with per-station PSK"""
1239 addr0
= dev
[0].p2p_dev_addr()
1240 addr1
= dev
[1].p2p_dev_addr()
1241 addr2
= dev
[2].p2p_dev_addr()
1244 pskfile
= "/tmp/ap_wps_per_enrollee_psk.psk_file"
1251 with
open(pskfile
, "w") as f
:
1252 f
.write("# WPA PSKs\n")
1254 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1255 "wpa": "2", "wpa_key_mgmt": "WPA-PSK",
1256 "rsn_pairwise": "CCMP", "ap_pin": appin
,
1257 "wpa_psk_file": pskfile
}
1258 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
1260 logger
.info("First enrollee")
1261 hapd
.request("WPS_PBC")
1262 dev
[0].request("WPS_PBC")
1263 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"])
1265 raise Exception("Association with the AP timed out (1)")
1267 logger
.info("Second enrollee")
1268 hapd
.request("WPS_PBC")
1269 dev
[1].request("WPS_PBC")
1270 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"])
1272 raise Exception("Association with the AP timed out (2)")
1274 logger
.info("External registrar")
1275 dev
[2].wps_reg(apdev
[0]['bssid'], appin
)
1277 logger
.info("Verifying PSK results")
1278 psks
= get_psk(pskfile
)
1279 if addr0
not in psks
:
1280 raise Exception("No PSK recorded for sta0")
1281 if addr1
not in psks
:
1282 raise Exception("No PSK recorded for sta1")
1283 if addr2
not in psks
:
1284 raise Exception("No PSK recorded for sta2")
1285 if psks
[addr0
] == psks
[addr1
]:
1286 raise Exception("Same PSK recorded for sta0 and sta1")
1287 if psks
[addr0
] == psks
[addr2
]:
1288 raise Exception("Same PSK recorded for sta0 and sta2")
1289 if psks
[addr1
] == psks
[addr2
]:
1290 raise Exception("Same PSK recorded for sta1 and sta2")
1292 dev
[0].request("REMOVE_NETWORK all")
1293 logger
.info("Second external registrar")
1294 dev
[0].wps_reg(apdev
[0]['bssid'], appin
)
1295 psks2
= get_psk(pskfile
)
1296 if addr0
not in psks2
:
1297 raise Exception("No PSK recorded for sta0(reg)")
1298 if psks
[addr0
] == psks2
[addr0
]:
1299 raise Exception("Same PSK recorded for sta0(enrollee) and sta0(reg)")
1303 def test_ap_wps_per_station_psk_failure(dev
, apdev
):
1304 """WPS PBC provisioning with per-station PSK (file not writable)"""
1305 addr0
= dev
[0].p2p_dev_addr()
1306 addr1
= dev
[1].p2p_dev_addr()
1307 addr2
= dev
[2].p2p_dev_addr()
1310 pskfile
= "/tmp/ap_wps_per_enrollee_psk.psk_file"
1317 with
open(pskfile
, "w") as f
:
1318 f
.write("# WPA PSKs\n")
1320 params
= { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1321 "wpa": "2", "wpa_key_mgmt": "WPA-PSK",
1322 "rsn_pairwise": "CCMP", "ap_pin": appin
,
1323 "wpa_psk_file": pskfile
}
1324 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
1325 if "FAIL" in hapd
.request("SET wpa_psk_file /tmp/does/not/exists/ap_wps_per_enrollee_psk_failure.psk_file"):
1326 raise Exception("Failed to set wpa_psk_file")
1328 logger
.info("First enrollee")
1329 hapd
.request("WPS_PBC")
1330 dev
[0].request("WPS_PBC")
1331 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"])
1333 raise Exception("Association with the AP timed out (1)")
1335 logger
.info("Second enrollee")
1336 hapd
.request("WPS_PBC")
1337 dev
[1].request("WPS_PBC")
1338 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"])
1340 raise Exception("Association with the AP timed out (2)")
1342 logger
.info("External registrar")
1343 dev
[2].wps_reg(apdev
[0]['bssid'], appin
)
1345 logger
.info("Verifying PSK results")
1346 psks
= get_psk(pskfile
)
1348 raise Exception("PSK recorded unexpectedly")
1352 def test_ap_wps_pin_request_file(dev
, apdev
):
1353 """WPS PIN provisioning with configured AP"""
1355 pinfile
= "/tmp/ap_wps_pin_request_file.log"
1356 if os
.path
.exists(pinfile
):
1357 subprocess
.call(['sudo', 'rm', pinfile
])
1358 hostapd
.add_ap(apdev
[0]['ifname'],
1359 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1360 "wps_pin_requests": pinfile
,
1361 "wpa_passphrase": "12345678", "wpa": "2",
1362 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
1363 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1364 uuid
= dev
[0].get_status_field("uuid")
1365 pin
= dev
[0].wps_read_pin()
1367 dev
[0].request("WPS_PIN any " + pin
)
1368 ev
= hapd
.wait_event(["WPS-PIN-NEEDED"], timeout
=15)
1370 raise Exception("PIN needed event not shown")
1372 raise Exception("UUID mismatch")
1373 dev
[0].request("WPS_CANCEL")
1375 with
open(pinfile
, "r") as f
:
1376 lines
= f
.readlines()
1382 raise Exception("PIN request entry not in the log file")
1384 subprocess
.call(['sudo', 'rm', pinfile
])
1386 def test_ap_wps_auto_setup_with_config_file(dev
, apdev
):
1387 """WPS auto-setup with configuration file"""
1388 conffile
= "/tmp/ap_wps_auto_setup_with_config_file.conf"
1389 ifname
= apdev
[0]['ifname']
1391 with
open(conffile
, "w") as f
:
1392 f
.write("driver=nl80211\n")
1393 f
.write("hw_mode=g\n")
1394 f
.write("channel=1\n")
1395 f
.write("ieee80211n=1\n")
1396 f
.write("interface=%s\n" % ifname
)
1397 f
.write("ctrl_interface=/var/run/hostapd\n")
1398 f
.write("ssid=wps\n")
1399 f
.write("eap_server=1\n")
1400 f
.write("wps_state=1\n")
1401 hostapd
.add_bss('phy3', ifname
, conffile
)
1402 hapd
= hostapd
.Hostapd(ifname
)
1403 hapd
.request("WPS_PBC")
1404 dev
[0].request("WPS_PBC")
1405 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=30)
1407 raise Exception("Association with the AP timed out")
1408 with
open(conffile
, "r") as f
:
1409 lines
= f
.read().splitlines()
1413 [name
,value
] = l
.split('=', 1)
1415 except ValueError, e
:
1416 if "# WPS configuration" in l
:
1419 raise Exception("Unexpected configuration line: " + l
)
1420 if vals
['ieee80211n'] != '1' or vals
['wps_state'] != '2' or "WPA-PSK" not in vals
['wpa_key_mgmt']:
1421 raise Exception("Incorrect configuration: " + str(vals
))
1423 subprocess
.call(['sudo', 'rm', conffile
])
1425 def test_ap_wps_pbc_timeout(dev
, apdev
, params
):
1426 """wpa_supplicant PBC walk time [long]"""
1427 if not params
['long']:
1428 logger
.info("Skip test case with long duration due to --long not specified")
1431 hostapd
.add_ap(apdev
[0]['ifname'],
1432 { "ssid": ssid
, "eap_server": "1", "wps_state": "1" })
1433 hapd
= hostapd
.Hostapd(apdev
[0]['ifname'])
1434 logger
.info("Start WPS_PBC and wait for PBC walk time expiration")
1435 if "OK" not in dev
[0].request("WPS_PBC"):
1436 raise Exception("WPS_PBC failed")
1437 ev
= dev
[0].wait_event(["WPS-TIMEOUT"], timeout
=150)
1439 raise Exception("WPS-TIMEOUT not reported")
1441 def add_ssdp_ap(ifname
, ap_uuid
):
1444 hostapd
.add_ap(ifname
,
1445 { "ssid": ssid
, "eap_server": "1", "wps_state": "2",
1446 "wpa_passphrase": "12345678", "wpa": "2",
1447 "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
1448 "device_name": "Wireless AP", "manufacturer": "Company",
1449 "model_name": "WAP", "model_number": "123",
1450 "serial_number": "12345", "device_type": "6-0050F204-1",
1451 "os_version": "01020300",
1452 "config_methods": "label push_button",
1453 "ap_pin": ap_pin
, "uuid": ap_uuid
, "upnp_iface": "lo",
1454 "friendly_name": "WPS Access Point",
1455 "manufacturer_url": "http://www.example.com/",
1456 "model_description": "Wireless Access Point",
1457 "model_url": "http://www.example.com/model/",
1458 "upc": "123456789012" })
1460 def ssdp_send(msg
, no_recv
=False):
1461 socket
.setdefaulttimeout(1)
1462 sock
= socket
.socket(socket
.AF_INET
, socket
.SOCK_DGRAM
, socket
.IPPROTO_UDP
)
1463 sock
.setsockopt(socket
.SOL_SOCKET
, socket
.SO_REUSEADDR
, 1)
1464 sock
.setsockopt(socket
.IPPROTO_IP
, socket
.IP_MULTICAST_TTL
, 2)
1465 sock
.bind(("127.0.0.1", 0))
1466 sock
.sendto(msg
, ("239.255.255.250", 1900))
1469 return sock
.recv(1000)
1471 def ssdp_send_msearch(st
):
1473 'M-SEARCH * HTTP/1.1',
1474 'HOST: 239.255.255.250:1900',
1476 'MAN: "ssdp:discover"',
1479 return ssdp_send(msg
)
1481 def test_ap_wps_ssdp_msearch(dev
, apdev
):
1482 """WPS AP and SSDP M-SEARCH messages"""
1483 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
1484 add_ssdp_ap(apdev
[0]['ifname'], ap_uuid
)
1487 'M-SEARCH * HTTP/1.1',
1488 'Host: 239.255.255.250:1900',
1490 'Man: "ssdp:discover"',
1491 'St: urn:schemas-wifialliance-org:device:WFADevice:1',
1496 'M-SEARCH * HTTP/1.1',
1497 'host:\t239.255.255.250:1900\t\t\t\t \t\t',
1499 'man: \t \t "ssdp:discover" ',
1500 'st: urn:schemas-wifialliance-org:device:WFADevice:1\t\t',
1504 ssdp_send_msearch("ssdp:all")
1505 ssdp_send_msearch("upnp:rootdevice")
1506 ssdp_send_msearch("uuid:" + ap_uuid
)
1507 ssdp_send_msearch("urn:schemas-wifialliance-org:service:WFAWLANConfig:1")
1508 ssdp_send_msearch("urn:schemas-wifialliance-org:device:WFADevice:1");
1511 'M-SEARCH * HTTP/1.1',
1512 'HOST:\t239.255.255.250:1900',
1513 'MAN: "ssdp:discover"',
1515 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1517 ssdp_send(msg
, no_recv
=True)
1519 def test_ap_wps_ssdp_invalid_msearch(dev
, apdev
):
1520 """WPS AP and invalid SSDP M-SEARCH messages"""
1521 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
1522 add_ssdp_ap(apdev
[0]['ifname'], ap_uuid
)
1524 socket
.setdefaulttimeout(1)
1525 sock
= socket
.socket(socket
.AF_INET
, socket
.SOCK_DGRAM
, socket
.IPPROTO_UDP
)
1526 sock
.setsockopt(socket
.SOL_SOCKET
, socket
.SO_REUSEADDR
, 1)
1527 sock
.setsockopt(socket
.IPPROTO_IP
, socket
.IP_MULTICAST_TTL
, 2)
1528 sock
.bind(("127.0.0.1", 0))
1530 logger
.debug("Missing MX")
1532 'M-SEARCH * HTTP/1.1',
1533 'HOST: 239.255.255.250:1900',
1534 'MAN: "ssdp:discover"',
1535 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1537 sock
.sendto(msg
, ("239.255.255.250", 1900))
1539 logger
.debug("Negative MX")
1541 'M-SEARCH * HTTP/1.1',
1542 'HOST: 239.255.255.250:1900',
1544 'MAN: "ssdp:discover"',
1545 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1547 sock
.sendto(msg
, ("239.255.255.250", 1900))
1549 logger
.debug("Invalid MX")
1551 'M-SEARCH * HTTP/1.1',
1552 'HOST: 239.255.255.250:1900',
1554 'MAN: "ssdp:discover"',
1555 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1557 sock
.sendto(msg
, ("239.255.255.250", 1900))
1559 logger
.debug("Missing MAN")
1561 'M-SEARCH * HTTP/1.1',
1562 'HOST: 239.255.255.250:1900',
1564 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1566 sock
.sendto(msg
, ("239.255.255.250", 1900))
1568 logger
.debug("Invalid MAN")
1570 'M-SEARCH * HTTP/1.1',
1571 'HOST: 239.255.255.250:1900',
1574 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1576 sock
.sendto(msg
, ("239.255.255.250", 1900))
1578 'M-SEARCH * HTTP/1.1',
1579 'HOST: 239.255.255.250:1900',
1581 'MAN; "ssdp:discover"',
1582 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1584 sock
.sendto(msg
, ("239.255.255.250", 1900))
1586 logger
.debug("Missing HOST")
1588 'M-SEARCH * HTTP/1.1',
1589 'MAN: "ssdp:discover"',
1591 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1593 sock
.sendto(msg
, ("239.255.255.250", 1900))
1595 logger
.debug("Missing ST")
1597 'M-SEARCH * HTTP/1.1',
1598 'HOST: 239.255.255.250:1900',
1599 'MAN: "ssdp:discover"',
1602 sock
.sendto(msg
, ("239.255.255.250", 1900))
1604 logger
.debug("Mismatching ST")
1606 'M-SEARCH * HTTP/1.1',
1607 'HOST: 239.255.255.250:1900',
1608 'MAN: "ssdp:discover"',
1610 'ST: uuid:16d5f8a9-4ee4-4f5e-81f9-cc6e2f47f42d',
1612 sock
.sendto(msg
, ("239.255.255.250", 1900))
1614 'M-SEARCH * HTTP/1.1',
1615 'HOST: 239.255.255.250:1900',
1616 'MAN: "ssdp:discover"',
1620 sock
.sendto(msg
, ("239.255.255.250", 1900))
1622 'M-SEARCH * HTTP/1.1',
1623 'HOST: 239.255.255.250:1900',
1624 'MAN: "ssdp:discover"',
1628 sock
.sendto(msg
, ("239.255.255.250", 1900))
1630 logger
.debug("Invalid ST")
1632 'M-SEARCH * HTTP/1.1',
1633 'HOST: 239.255.255.250:1900',
1634 'MAN: "ssdp:discover"',
1636 'ST; urn:schemas-wifialliance-org:device:WFADevice:1',
1638 sock
.sendto(msg
, ("239.255.255.250", 1900))
1640 logger
.debug("Invalid M-SEARCH")
1642 'M+SEARCH * HTTP/1.1',
1643 'HOST: 239.255.255.250:1900',
1644 'MAN: "ssdp:discover"',
1646 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1648 sock
.sendto(msg
, ("239.255.255.250", 1900))
1650 'M-SEARCH-* HTTP/1.1',
1651 'HOST: 239.255.255.250:1900',
1652 'MAN: "ssdp:discover"',
1654 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1656 sock
.sendto(msg
, ("239.255.255.250", 1900))
1658 logger
.debug("Invalid message format")
1659 sock
.sendto("NOTIFY * HTTP/1.1", ("239.255.255.250", 1900))
1661 'M-SEARCH * HTTP/1.1',
1662 'HOST: 239.255.255.250:1900',
1663 'MAN: "ssdp:discover"',
1665 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1667 sock
.sendto(msg
, ("239.255.255.250", 1900))
1671 raise Exception("Unexpected M-SEARCH response: " + r
)
1672 except socket
.timeout
:
1675 logger
.debug("Valid M-SEARCH")
1677 'M-SEARCH * HTTP/1.1',
1678 'HOST: 239.255.255.250:1900',
1679 'MAN: "ssdp:discover"',
1681 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1683 sock
.sendto(msg
, ("239.255.255.250", 1900))
1688 except socket
.timeout
:
1689 raise Exception("No SSDP response")
1691 def test_ap_wps_ssdp_burst(dev
, apdev
):
1692 """WPS AP and SSDP burst"""
1693 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
1694 add_ssdp_ap(apdev
[0]['ifname'], ap_uuid
)
1697 'M-SEARCH * HTTP/1.1',
1698 'HOST: 239.255.255.250:1900',
1699 'MAN: "ssdp:discover"',
1701 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
1703 socket
.setdefaulttimeout(1)
1704 sock
= socket
.socket(socket
.AF_INET
, socket
.SOCK_DGRAM
, socket
.IPPROTO_UDP
)
1705 sock
.setsockopt(socket
.SOL_SOCKET
, socket
.SO_REUSEADDR
, 1)
1706 sock
.setsockopt(socket
.IPPROTO_IP
, socket
.IP_MULTICAST_TTL
, 2)
1707 sock
.bind(("127.0.0.1", 0))
1708 for i
in range(0, 25):
1709 sock
.sendto(msg
, ("239.255.255.250", 1900))
1714 if not r
.startswith("HTTP/1.1 200 OK\r\n"):
1715 raise Exception("Unexpected message: " + r
)
1717 except socket
.timeout
:
1720 raise Exception("Too few SSDP responses")
1722 sock
= socket
.socket(socket
.AF_INET
, socket
.SOCK_DGRAM
, socket
.IPPROTO_UDP
)
1723 sock
.setsockopt(socket
.SOL_SOCKET
, socket
.SO_REUSEADDR
, 1)
1724 sock
.setsockopt(socket
.IPPROTO_IP
, socket
.IP_MULTICAST_TTL
, 2)
1725 sock
.bind(("127.0.0.1", 0))
1726 for i
in range(0, 25):
1727 sock
.sendto(msg
, ("239.255.255.250", 1900))
1733 except socket
.timeout
:
1734 raise Exception("No SSDP response")
1736 def ssdp_get_location(uuid
):
1737 res
= ssdp_send_msearch("uuid:" + uuid
)
1739 for l
in res
.splitlines():
1740 if l
.lower().startswith("location:"):
1741 location
= l
.split(':', 1)[1].strip()
1743 if location
is None:
1744 raise Exception("No UPnP location found")
1747 def upnp_get_urls(location
):
1748 conn
= urllib
.urlopen(location
)
1749 tree
= ET
.parse(conn
)
1750 root
= tree
.getroot()
1751 urn
= '{urn:schemas-upnp-org:device-1-0}'
1752 service
= root
.find("./" + urn
+ "device/" + urn
+ "serviceList/" + urn
+ "service")
1754 res
['scpd_url'] = urlparse
.urljoin(location
, service
.find(urn
+ 'SCPDURL').text
)
1755 res
['control_url'] = urlparse
.urljoin(location
, service
.find(urn
+ 'controlURL').text
)
1756 res
['event_sub_url'] = urlparse
.urljoin(location
, service
.find(urn
+ 'eventSubURL').text
)
1759 def upnp_soap_action(conn
, path
, action
, include_soap_action
=True, soap_action_override
=None):
1760 soapns
= 'http://schemas.xmlsoap.org/soap/envelope/'
1761 wpsns
= 'urn:schemas-wifialliance-org:service:WFAWLANConfig:1'
1762 ET
.register_namespace('soapenv', soapns
)
1763 ET
.register_namespace('wfa', wpsns
)
1765 attrib
['{%s}encodingStyle' % soapns
] = 'http://schemas.xmlsoap.org/soap/encoding/'
1766 root
= ET
.Element("{%s}Envelope" % soapns
, attrib
=attrib
)
1767 body
= ET
.SubElement(root
, "{%s}Body" % soapns
)
1768 act
= ET
.SubElement(body
, "{%s}%s" % (wpsns
, action
))
1769 tree
= ET
.ElementTree(root
)
1770 soap
= StringIO
.StringIO()
1771 tree
.write(soap
, xml_declaration
=True, encoding
='utf-8')
1773 headers
= { "Content-type": 'text/xml; charset="utf-8"' }
1774 if include_soap_action
:
1775 headers
["SOAPAction"] = '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#%s"' % action
1776 elif soap_action_override
:
1777 headers
["SOAPAction"] = soap_action_override
1778 conn
.request("POST", path
, soap
.getvalue(), headers
)
1779 return conn
.getresponse()
1781 def test_ap_wps_upnp(dev
, apdev
):
1782 """WPS AP and UPnP operations"""
1783 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
1784 add_ssdp_ap(apdev
[0]['ifname'], ap_uuid
)
1786 location
= ssdp_get_location(ap_uuid
)
1787 urls
= upnp_get_urls(location
)
1789 conn
= urllib
.urlopen(urls
['scpd_url'])
1792 conn
= urllib
.urlopen(urlparse
.urljoin(location
, "unknown.html"))
1793 if conn
.getcode() != 404:
1794 raise Exception("Unexpected HTTP response to GET unknown URL")
1796 url
= urlparse
.urlparse(location
)
1797 conn
= httplib
.HTTPConnection(url
.netloc
)
1798 #conn.set_debuglevel(1)
1799 headers
= { "Content-type": 'text/xml; charset="utf-8"',
1800 "SOAPAction": '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#GetDeviceInfo"' }
1801 conn
.request("POST", "hello", "\r\n\r\n", headers
)
1802 resp
= conn
.getresponse()
1803 if resp
.status
!= 404:
1804 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1806 conn
.request("UNKNOWN", "hello", "\r\n\r\n", headers
)
1807 resp
= conn
.getresponse()
1808 if resp
.status
!= 501:
1809 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1811 headers
= { "Content-type": 'text/xml; charset="utf-8"',
1812 "SOAPAction": '"urn:some-unknown-action#GetDeviceInfo"' }
1813 ctrlurl
= urlparse
.urlparse(urls
['control_url'])
1814 conn
.request("POST", ctrlurl
.path
, "\r\n\r\n", headers
)
1815 resp
= conn
.getresponse()
1816 if resp
.status
!= 401:
1817 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1819 logger
.debug("GetDeviceInfo without SOAPAction header")
1820 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "GetDeviceInfo",
1821 include_soap_action
=False)
1822 if resp
.status
!= 401:
1823 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1825 logger
.debug("GetDeviceInfo with invalid SOAPAction header")
1827 "urn:schemas-wifialliance-org:service:WFAWLANConfig:1#GetDeviceInfo",
1828 '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1"',
1829 '"urn:schemas-wifialliance-org:service:WFAWLANConfig:123#GetDevice']:
1830 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "GetDeviceInfo",
1831 include_soap_action
=False,
1832 soap_action_override
=act
)
1833 if resp
.status
!= 401:
1834 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1836 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "GetDeviceInfo")
1837 if resp
.status
!= 200:
1838 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1840 if "NewDeviceInfo" not in dev
:
1841 raise Exception("Unexpected GetDeviceInfo response")
1843 logger
.debug("PutMessage without required parameters")
1844 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "PutMessage")
1845 if resp
.status
!= 600:
1846 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1848 logger
.debug("PutWLANResponse without required parameters")
1849 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "PutWLANResponse")
1850 if resp
.status
!= 600:
1851 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1853 logger
.debug("SetSelectedRegistrar from unregistered ER")
1854 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "SetSelectedRegistrar")
1855 if resp
.status
!= 501:
1856 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1858 logger
.debug("Unknown action")
1859 resp
= upnp_soap_action(conn
, ctrlurl
.path
, "Unknown")
1860 if resp
.status
!= 401:
1861 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1863 def test_ap_wps_upnp_subscribe(dev
, apdev
):
1864 """WPS AP and UPnP event subscription"""
1865 ap_uuid
= "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
1866 add_ssdp_ap(apdev
[0]['ifname'], ap_uuid
)
1868 location
= ssdp_get_location(ap_uuid
)
1869 urls
= upnp_get_urls(location
)
1870 eventurl
= urlparse
.urlparse(urls
['event_sub_url'])
1872 url
= urlparse
.urlparse(location
)
1873 conn
= httplib
.HTTPConnection(url
.netloc
)
1874 #conn.set_debuglevel(1)
1875 headers
= { "callback": '<http://127.0.0.1:12345/event>',
1876 "timeout": "Second-1234" }
1877 conn
.request("SUBSCRIBE", "hello", "\r\n\r\n", headers
)
1878 resp
= conn
.getresponse()
1879 if resp
.status
!= 412:
1880 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1882 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
1883 resp
= conn
.getresponse()
1884 if resp
.status
!= 412:
1885 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1887 headers
= { "NT": "upnp:event",
1888 "timeout": "Second-1234" }
1889 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
1890 resp
= conn
.getresponse()
1891 if resp
.status
!= 412:
1892 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1894 headers
= { "callback": '<http://127.0.0.1:12345/event>',
1895 "NT": "upnp:foobar",
1896 "timeout": "Second-1234" }
1897 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
1898 resp
= conn
.getresponse()
1899 if resp
.status
!= 400:
1900 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1902 logger
.debug("Valid subscription")
1903 headers
= { "callback": '<http://127.0.0.1:12345/event>',
1905 "timeout": "Second-1234" }
1906 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
1907 resp
= conn
.getresponse()
1908 if resp
.status
!= 200:
1909 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1910 sid
= resp
.getheader("sid")
1911 logger
.debug("Subscription SID " + sid
)
1913 logger
.debug("Invalid re-subscription")
1914 headers
= { "NT": "upnp:event",
1915 "sid": "123456734567854",
1916 "timeout": "Second-1234" }
1917 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
1918 resp
= conn
.getresponse()
1919 if resp
.status
!= 400:
1920 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1922 logger
.debug("Invalid re-subscription")
1923 headers
= { "NT": "upnp:event",
1924 "sid": "uuid:123456734567854",
1925 "timeout": "Second-1234" }
1926 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
1927 resp
= conn
.getresponse()
1928 if resp
.status
!= 400:
1929 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1931 logger
.debug("Invalid re-subscription")
1932 headers
= { "callback": '<http://127.0.0.1:12345/event>',
1935 "timeout": "Second-1234" }
1936 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
1937 resp
= conn
.getresponse()
1938 if resp
.status
!= 400:
1939 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1941 logger
.debug("SID mismatch in re-subscription")
1942 headers
= { "NT": "upnp:event",
1943 "sid": "uuid:4c2bca79-1ff4-4e43-85d4-952a2b8a51fb",
1944 "timeout": "Second-1234" }
1945 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
1946 resp
= conn
.getresponse()
1947 if resp
.status
!= 412:
1948 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1950 logger
.debug("Valid re-subscription")
1951 headers
= { "NT": "upnp:event",
1953 "timeout": "Second-1234" }
1954 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
1955 resp
= conn
.getresponse()
1956 if resp
.status
!= 200:
1957 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1958 sid2
= resp
.getheader("sid")
1959 logger
.debug("Subscription SID " + sid2
)
1962 raise Exception("Unexpected SID change")
1964 logger
.debug("Valid re-subscription")
1965 headers
= { "NT": "upnp:event",
1966 "sid": "uuid: \t \t" + sid
.split(':')[1],
1967 "timeout": "Second-1234" }
1968 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
1969 resp
= conn
.getresponse()
1970 if resp
.status
!= 200:
1971 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1973 logger
.debug("Invalid unsubscription")
1974 headers
= { "sid": sid
}
1975 conn
.request("UNSUBSCRIBE", "/hello", "\r\n\r\n", headers
)
1976 resp
= conn
.getresponse()
1977 if resp
.status
!= 412:
1978 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1979 headers
= { "foo": "bar" }
1980 conn
.request("UNSUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
1981 resp
= conn
.getresponse()
1982 if resp
.status
!= 412:
1983 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1985 logger
.debug("Valid unsubscription")
1986 headers
= { "sid": sid
}
1987 conn
.request("UNSUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
1988 resp
= conn
.getresponse()
1989 if resp
.status
!= 200:
1990 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1992 logger
.debug("Unsubscription for not existing SID")
1993 headers
= { "sid": sid
}
1994 conn
.request("UNSUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
1995 resp
= conn
.getresponse()
1996 if resp
.status
!= 412:
1997 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
1999 logger
.debug("Invalid unsubscription")
2000 headers
= { "sid": " \t \tfoo" }
2001 conn
.request("UNSUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2002 resp
= conn
.getresponse()
2003 if resp
.status
!= 400:
2004 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2006 logger
.debug("Invalid unsubscription")
2007 headers
= { "sid": "uuid:\t \tfoo" }
2008 conn
.request("UNSUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2009 resp
= conn
.getresponse()
2010 if resp
.status
!= 400:
2011 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2013 logger
.debug("Invalid unsubscription")
2014 headers
= { "NT": "upnp:event",
2016 conn
.request("UNSUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2017 resp
= conn
.getresponse()
2018 if resp
.status
!= 400:
2019 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2020 headers
= { "callback": '<http://127.0.0.1:12345/event>',
2022 conn
.request("UNSUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2023 resp
= conn
.getresponse()
2024 if resp
.status
!= 400:
2025 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2027 logger
.debug("Valid subscription with multiple callbacks")
2028 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>',
2030 "timeout": "Second-1234" }
2031 conn
.request("SUBSCRIBE", eventurl
.path
, "\r\n\r\n", headers
)
2032 resp
= conn
.getresponse()
2033 if resp
.status
!= 200:
2034 raise Exception("Unexpected HTTP response: %s" % resp
.status
)
2035 sid
= resp
.getheader("sid")
2036 logger
.debug("Subscription SID " + sid
)