test_ap_wps.py 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792
  1. # WPS tests
  2. # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi>
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import os
  7. import time
  8. import subprocess
  9. import logging
  10. logger = logging.getLogger()
  11. import re
  12. import socket
  13. import httplib
  14. import urlparse
  15. import urllib
  16. import xml.etree.ElementTree as ET
  17. import StringIO
  18. import hwsim_utils
  19. import hostapd
  20. def test_ap_wps_init(dev, apdev):
  21. """Initial AP configuration with first WPS Enrollee"""
  22. ssid = "test-wps"
  23. hostapd.add_ap(apdev[0]['ifname'],
  24. { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
  25. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  26. logger.info("WPS provisioning step")
  27. hapd.request("WPS_PBC")
  28. if "PBC Status: Active" not in hapd.request("WPS_GET_STATUS"):
  29. raise Exception("PBC status not shown correctly")
  30. dev[0].dump_monitor()
  31. dev[0].request("WPS_PBC")
  32. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  33. if ev is None:
  34. raise Exception("Association with the AP timed out")
  35. status = dev[0].get_status()
  36. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  37. raise Exception("Not fully connected")
  38. if status['ssid'] != ssid:
  39. raise Exception("Unexpected SSID")
  40. if status['pairwise_cipher'] != 'CCMP':
  41. raise Exception("Unexpected encryption configuration")
  42. if status['key_mgmt'] != 'WPA2-PSK':
  43. raise Exception("Unexpected key_mgmt")
  44. status = hapd.request("WPS_GET_STATUS")
  45. if "PBC Status: Disabled" not in status:
  46. raise Exception("PBC status not shown correctly")
  47. if "Last WPS result: Success" not in status:
  48. raise Exception("Last WPS result not shown correctly")
  49. if "Peer Address: " + dev[0].p2p_interface_addr() not in status:
  50. raise Exception("Peer address not shown correctly")
  51. conf = hapd.request("GET_CONFIG")
  52. if "wps_state=configured" not in conf:
  53. raise Exception("AP not in WPS configured state")
  54. if "rsn_pairwise_cipher=CCMP TKIP" not in conf:
  55. raise Exception("Unexpected rsn_pairwise_cipher")
  56. if "wpa_pairwise_cipher=CCMP TKIP" not in conf:
  57. raise Exception("Unexpected wpa_pairwise_cipher")
  58. if "group_cipher=TKIP" not in conf:
  59. raise Exception("Unexpected group_cipher")
  60. def test_ap_wps_init_2ap_pbc(dev, apdev):
  61. """Initial two-radio AP configuration with first WPS PBC Enrollee"""
  62. ssid = "test-wps"
  63. params = { "ssid": ssid, "eap_server": "1", "wps_state": "1" }
  64. hostapd.add_ap(apdev[0]['ifname'], params)
  65. hostapd.add_ap(apdev[1]['ifname'], params)
  66. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  67. logger.info("WPS provisioning step")
  68. hapd.request("WPS_PBC")
  69. dev[0].scan(freq="2412")
  70. bss = dev[0].get_bss(apdev[0]['bssid'])
  71. if "[WPS-PBC]" not in bss['flags']:
  72. raise Exception("WPS-PBC flag missing from AP1")
  73. bss = dev[0].get_bss(apdev[1]['bssid'])
  74. if "[WPS-PBC]" not in bss['flags']:
  75. raise Exception("WPS-PBC flag missing from AP2")
  76. dev[0].dump_monitor()
  77. dev[0].request("WPS_PBC")
  78. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  79. if ev is None:
  80. raise Exception("Association with the AP timed out")
  81. dev[1].scan(freq="2412")
  82. bss = dev[1].get_bss(apdev[0]['bssid'])
  83. if "[WPS-PBC]" in bss['flags']:
  84. raise Exception("WPS-PBC flag not cleared from AP1")
  85. bss = dev[1].get_bss(apdev[1]['bssid'])
  86. if "[WPS-PBC]" in bss['flags']:
  87. raise Exception("WPS-PBC flag bit ckeared from AP2")
  88. def test_ap_wps_init_2ap_pin(dev, apdev):
  89. """Initial two-radio AP configuration with first WPS PIN Enrollee"""
  90. ssid = "test-wps"
  91. params = { "ssid": ssid, "eap_server": "1", "wps_state": "1" }
  92. hostapd.add_ap(apdev[0]['ifname'], params)
  93. hostapd.add_ap(apdev[1]['ifname'], params)
  94. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  95. logger.info("WPS provisioning step")
  96. pin = dev[0].wps_read_pin()
  97. hapd.request("WPS_PIN any " + pin)
  98. dev[0].scan(freq="2412")
  99. bss = dev[0].get_bss(apdev[0]['bssid'])
  100. if "[WPS-AUTH]" not in bss['flags']:
  101. raise Exception("WPS-AUTH flag missing from AP1")
  102. bss = dev[0].get_bss(apdev[1]['bssid'])
  103. if "[WPS-AUTH]" not in bss['flags']:
  104. raise Exception("WPS-AUTH flag missing from AP2")
  105. dev[0].dump_monitor()
  106. dev[0].request("WPS_PIN any " + pin)
  107. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  108. if ev is None:
  109. raise Exception("Association with the AP timed out")
  110. dev[1].scan(freq="2412")
  111. bss = dev[1].get_bss(apdev[0]['bssid'])
  112. if "[WPS-AUTH]" in bss['flags']:
  113. raise Exception("WPS-AUTH flag not cleared from AP1")
  114. bss = dev[1].get_bss(apdev[1]['bssid'])
  115. if "[WPS-AUTH]" in bss['flags']:
  116. raise Exception("WPS-AUTH flag bit ckeared from AP2")
  117. def test_ap_wps_init_through_wps_config(dev, apdev):
  118. """Initial AP configuration using wps_config command"""
  119. ssid = "test-wps-init-config"
  120. hostapd.add_ap(apdev[0]['ifname'],
  121. { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
  122. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  123. if "FAIL" in hapd.request("WPS_CONFIG " + ssid.encode("hex") + " WPA2PSK CCMP " + "12345678".encode("hex")):
  124. raise Exception("WPS_CONFIG command failed")
  125. ev = hapd.wait_event(["WPS-NEW-AP-SETTINGS"], timeout=5)
  126. if ev is None:
  127. raise Exception("Timeout on WPS-NEW-AP-SETTINGS events")
  128. # It takes some time for the AP to update Beacon and Probe Response frames,
  129. # so wait here before requesting the scan to be started to avoid adding
  130. # extra five second wait to the test due to fetching obsolete scan results.
  131. hapd.ping()
  132. time.sleep(0.2)
  133. dev[0].connect(ssid, psk="12345678", scan_freq="2412", proto="WPA2",
  134. pairwise="CCMP", group="CCMP")
  135. def test_ap_wps_conf(dev, apdev):
  136. """WPS PBC provisioning with configured AP"""
  137. ssid = "test-wps-conf"
  138. hostapd.add_ap(apdev[0]['ifname'],
  139. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  140. "wpa_passphrase": "12345678", "wpa": "2",
  141. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  142. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  143. logger.info("WPS provisioning step")
  144. hapd.request("WPS_PBC")
  145. dev[0].dump_monitor()
  146. dev[0].request("WPS_PBC")
  147. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  148. if ev is None:
  149. raise Exception("Association with the AP timed out")
  150. status = dev[0].get_status()
  151. if status['wpa_state'] != 'COMPLETED':
  152. raise Exception("Not fully connected")
  153. if status['bssid'] != apdev[0]['bssid']:
  154. raise Exception("Unexpected BSSID")
  155. if status['ssid'] != ssid:
  156. raise Exception("Unexpected SSID")
  157. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  158. raise Exception("Unexpected encryption configuration")
  159. if status['key_mgmt'] != 'WPA2-PSK':
  160. raise Exception("Unexpected key_mgmt")
  161. sta = hapd.get_sta(dev[0].p2p_interface_addr())
  162. if 'wpsDeviceName' not in sta or sta['wpsDeviceName'] != "Device A":
  163. raise Exception("Device name not available in STA command")
  164. def test_ap_wps_twice(dev, apdev):
  165. """WPS provisioning with twice to change passphrase"""
  166. ssid = "test-wps-twice"
  167. params = { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  168. "wpa_passphrase": "12345678", "wpa": "2",
  169. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }
  170. hostapd.add_ap(apdev[0]['ifname'], params)
  171. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  172. logger.info("WPS provisioning step")
  173. hapd.request("WPS_PBC")
  174. dev[0].dump_monitor()
  175. dev[0].request("WPS_PBC")
  176. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  177. if ev is None:
  178. raise Exception("Association with the AP timed out")
  179. dev[0].request("DISCONNECT")
  180. logger.info("Restart AP with different passphrase and re-run WPS")
  181. hapd_global = hostapd.HostapdGlobal()
  182. hapd_global.remove(apdev[0]['ifname'])
  183. params['wpa_passphrase'] = 'another passphrase'
  184. hostapd.add_ap(apdev[0]['ifname'], params)
  185. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  186. logger.info("WPS provisioning step")
  187. hapd.request("WPS_PBC")
  188. dev[0].dump_monitor()
  189. dev[0].request("WPS_PBC")
  190. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  191. if ev is None:
  192. raise Exception("Association with the AP timed out")
  193. networks = dev[0].list_networks()
  194. if len(networks) > 1:
  195. raise Exception("Unexpected duplicated network block present")
  196. def test_ap_wps_incorrect_pin(dev, apdev):
  197. """WPS PIN provisioning with incorrect PIN"""
  198. ssid = "test-wps-incorrect-pin"
  199. hostapd.add_ap(apdev[0]['ifname'],
  200. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  201. "wpa_passphrase": "12345678", "wpa": "2",
  202. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  203. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  204. logger.info("WPS provisioning attempt 1")
  205. hapd.request("WPS_PIN any 12345670")
  206. dev[0].dump_monitor()
  207. dev[0].request("WPS_PIN any 55554444")
  208. ev = dev[0].wait_event(["WPS-FAIL"], timeout=30)
  209. if ev is None:
  210. raise Exception("WPS operation timed out")
  211. if "config_error=18" not in ev:
  212. raise Exception("Incorrect config_error reported")
  213. if "msg=8" not in ev:
  214. raise Exception("PIN error detected on incorrect message")
  215. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
  216. if ev is None:
  217. raise Exception("Timeout on disconnection event")
  218. dev[0].request("WPS_CANCEL")
  219. # if a scan was in progress, wait for it to complete before trying WPS again
  220. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
  221. status = hapd.request("WPS_GET_STATUS")
  222. if "Last WPS result: Failed" not in status:
  223. raise Exception("WPS failure result not shown correctly")
  224. logger.info("WPS provisioning attempt 2")
  225. hapd.request("WPS_PIN any 12345670")
  226. dev[0].dump_monitor()
  227. dev[0].request("WPS_PIN any 12344444")
  228. ev = dev[0].wait_event(["WPS-FAIL"], timeout=30)
  229. if ev is None:
  230. raise Exception("WPS operation timed out")
  231. if "config_error=18" not in ev:
  232. raise Exception("Incorrect config_error reported")
  233. if "msg=10" not in ev:
  234. raise Exception("PIN error detected on incorrect message")
  235. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
  236. if ev is None:
  237. raise Exception("Timeout on disconnection event")
  238. def test_ap_wps_conf_pin(dev, apdev):
  239. """WPS PIN provisioning with configured AP"""
  240. ssid = "test-wps-conf-pin"
  241. hostapd.add_ap(apdev[0]['ifname'],
  242. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  243. "wpa_passphrase": "12345678", "wpa": "2",
  244. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  245. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  246. logger.info("WPS provisioning step")
  247. pin = dev[0].wps_read_pin()
  248. hapd.request("WPS_PIN any " + pin)
  249. dev[0].dump_monitor()
  250. dev[0].request("WPS_PIN any " + pin)
  251. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  252. if ev is None:
  253. raise Exception("Association with the AP timed out")
  254. status = dev[0].get_status()
  255. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  256. raise Exception("Not fully connected")
  257. if status['ssid'] != ssid:
  258. raise Exception("Unexpected SSID")
  259. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  260. raise Exception("Unexpected encryption configuration")
  261. if status['key_mgmt'] != 'WPA2-PSK':
  262. raise Exception("Unexpected key_mgmt")
  263. dev[1].scan(freq="2412")
  264. bss = dev[1].get_bss(apdev[0]['bssid'])
  265. if "[WPS-AUTH]" in bss['flags']:
  266. raise Exception("WPS-AUTH flag not cleared")
  267. logger.info("Try to connect from another station using the same PIN")
  268. dev[1].request("WPS_PIN any " + pin)
  269. ev = dev[1].wait_event(["WPS-M2D","CTRL-EVENT-CONNECTED"], timeout=30)
  270. if ev is None:
  271. raise Exception("Operation timed out")
  272. if "WPS-M2D" not in ev:
  273. raise Exception("Unexpected WPS operation started")
  274. def test_ap_wps_conf_pin_2sta(dev, apdev):
  275. """Two stations trying to use WPS PIN at the same time"""
  276. ssid = "test-wps-conf-pin2"
  277. hostapd.add_ap(apdev[0]['ifname'],
  278. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  279. "wpa_passphrase": "12345678", "wpa": "2",
  280. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  281. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  282. logger.info("WPS provisioning step")
  283. pin = "12345670"
  284. pin2 = "55554444"
  285. hapd.request("WPS_PIN " + dev[0].get_status_field("uuid") + " " + pin)
  286. hapd.request("WPS_PIN " + dev[1].get_status_field("uuid") + " " + pin)
  287. dev[0].dump_monitor()
  288. dev[1].dump_monitor()
  289. dev[0].request("WPS_PIN any " + pin)
  290. dev[1].request("WPS_PIN any " + pin)
  291. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  292. if ev is None:
  293. raise Exception("Association with the AP timed out")
  294. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  295. if ev is None:
  296. raise Exception("Association with the AP timed out")
  297. def test_ap_wps_conf_pin_timeout(dev, apdev):
  298. """WPS PIN provisioning with configured AP timing out PIN"""
  299. ssid = "test-wps-conf-pin"
  300. hostapd.add_ap(apdev[0]['ifname'],
  301. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  302. "wpa_passphrase": "12345678", "wpa": "2",
  303. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  304. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  305. addr = dev[0].p2p_interface_addr()
  306. pin = dev[0].wps_read_pin()
  307. if "FAIL" not in hapd.request("WPS_PIN "):
  308. raise Exception("Unexpected success on invalid WPS_PIN")
  309. hapd.request("WPS_PIN any " + pin + " 1")
  310. time.sleep(1.1)
  311. dev[0].request("WPS_PIN any " + pin)
  312. ev = hapd.wait_event(["WPS-PIN-NEEDED"], timeout=20)
  313. if ev is None:
  314. raise Exception("WPS-PIN-NEEDED event timed out")
  315. ev = dev[0].wait_event(["WPS-M2D"])
  316. if ev is None:
  317. raise Exception("M2D not reported")
  318. dev[0].request("WPS_CANCEL")
  319. hapd.request("WPS_PIN any " + pin + " 20 " + addr)
  320. dev[0].request("WPS_PIN any " + pin)
  321. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  322. if ev is None:
  323. raise Exception("Association with the AP timed out")
  324. def test_ap_wps_reg_connect(dev, apdev):
  325. """WPS registrar using AP PIN to connect"""
  326. ssid = "test-wps-reg-ap-pin"
  327. appin = "12345670"
  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. "ap_pin": appin})
  333. logger.info("WPS provisioning step")
  334. dev[0].dump_monitor()
  335. dev[0].wps_reg(apdev[0]['bssid'], appin)
  336. status = dev[0].get_status()
  337. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  338. raise Exception("Not fully connected")
  339. if status['ssid'] != ssid:
  340. raise Exception("Unexpected SSID")
  341. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  342. raise Exception("Unexpected encryption configuration")
  343. if status['key_mgmt'] != 'WPA2-PSK':
  344. raise Exception("Unexpected key_mgmt")
  345. def check_wps_reg_failure(dev, ap, appin):
  346. dev.request("WPS_REG " + ap['bssid'] + " " + appin)
  347. ev = dev.wait_event(["WPS-SUCCESS", "WPS-FAIL"], timeout=15)
  348. if ev is None:
  349. raise Exception("WPS operation timed out")
  350. if "WPS-SUCCESS" in ev:
  351. raise Exception("WPS operation succeeded unexpectedly")
  352. if "config_error=15" not in ev:
  353. raise Exception("WPS setup locked state was not reported correctly")
  354. def test_ap_wps_random_ap_pin(dev, apdev):
  355. """WPS registrar using random AP PIN"""
  356. ssid = "test-wps-reg-random-ap-pin"
  357. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  358. hostapd.add_ap(apdev[0]['ifname'],
  359. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  360. "wpa_passphrase": "12345678", "wpa": "2",
  361. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  362. "device_name": "Wireless AP", "manufacturer": "Company",
  363. "model_name": "WAP", "model_number": "123",
  364. "serial_number": "12345", "device_type": "6-0050F204-1",
  365. "os_version": "01020300",
  366. "config_methods": "label push_button",
  367. "uuid": ap_uuid, "upnp_iface": "lo" })
  368. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  369. appin = hapd.request("WPS_AP_PIN random")
  370. if "FAIL" in appin:
  371. raise Exception("Could not generate random AP PIN")
  372. if appin not in hapd.request("WPS_AP_PIN get"):
  373. raise Exception("Could not fetch current AP PIN")
  374. logger.info("WPS provisioning step")
  375. dev[0].wps_reg(apdev[0]['bssid'], appin)
  376. hapd.request("WPS_AP_PIN disable")
  377. logger.info("WPS provisioning step with AP PIN disabled")
  378. check_wps_reg_failure(dev[1], apdev[0], appin)
  379. logger.info("WPS provisioning step with AP PIN reset")
  380. appin = "12345670"
  381. hapd.request("WPS_AP_PIN set " + appin)
  382. dev[1].wps_reg(apdev[0]['bssid'], appin)
  383. dev[0].request("REMOVE_NETWORK all")
  384. dev[1].request("REMOVE_NETWORK all")
  385. dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
  386. dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
  387. logger.info("WPS provisioning step after AP PIN timeout")
  388. hapd.request("WPS_AP_PIN disable")
  389. appin = hapd.request("WPS_AP_PIN random 1")
  390. time.sleep(1.1)
  391. if "FAIL" not in hapd.request("WPS_AP_PIN get"):
  392. raise Exception("AP PIN unexpectedly still enabled")
  393. check_wps_reg_failure(dev[0], apdev[0], appin)
  394. logger.info("WPS provisioning step after AP PIN timeout(2)")
  395. hapd.request("WPS_AP_PIN disable")
  396. appin = "12345670"
  397. hapd.request("WPS_AP_PIN set " + appin + " 1")
  398. time.sleep(1.1)
  399. if "FAIL" not in hapd.request("WPS_AP_PIN get"):
  400. raise Exception("AP PIN unexpectedly still enabled")
  401. check_wps_reg_failure(dev[1], apdev[0], appin)
  402. def test_ap_wps_reg_config(dev, apdev):
  403. """WPS registrar configuring an AP using AP PIN"""
  404. ssid = "test-wps-init-ap-pin"
  405. appin = "12345670"
  406. hostapd.add_ap(apdev[0]['ifname'],
  407. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  408. "ap_pin": appin})
  409. logger.info("WPS configuration step")
  410. dev[0].dump_monitor()
  411. new_ssid = "wps-new-ssid"
  412. new_passphrase = "1234567890"
  413. dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPA2PSK", "CCMP",
  414. new_passphrase)
  415. status = dev[0].get_status()
  416. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  417. raise Exception("Not fully connected")
  418. if status['ssid'] != new_ssid:
  419. raise Exception("Unexpected SSID")
  420. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  421. raise Exception("Unexpected encryption configuration")
  422. if status['key_mgmt'] != 'WPA2-PSK':
  423. raise Exception("Unexpected key_mgmt")
  424. logger.info("Re-configure back to open")
  425. dev[0].request("REMOVE_NETWORK all")
  426. dev[0].request("BSS_FLUSH 0")
  427. dev[0].request("SCAN freq=2412 only_new=1")
  428. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15)
  429. if ev is None:
  430. raise Exception("Scan timed out")
  431. dev[0].dump_monitor()
  432. dev[0].wps_reg(apdev[0]['bssid'], appin, "wps-open", "OPEN", "NONE", "")
  433. status = dev[0].get_status()
  434. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  435. raise Exception("Not fully connected")
  436. if status['ssid'] != "wps-open":
  437. raise Exception("Unexpected SSID")
  438. if status['key_mgmt'] != 'NONE':
  439. raise Exception("Unexpected key_mgmt")
  440. def test_ap_wps_reg_config_ext_processing(dev, apdev):
  441. """WPS registrar configuring an AP with external config processing"""
  442. ssid = "test-wps-init-ap-pin"
  443. appin = "12345670"
  444. params = { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  445. "wps_cred_processing": "1", "ap_pin": appin}
  446. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  447. new_ssid = "wps-new-ssid"
  448. new_passphrase = "1234567890"
  449. dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPA2PSK", "CCMP",
  450. new_passphrase, no_wait=True)
  451. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
  452. if ev is None:
  453. raise Exception("WPS registrar operation timed out")
  454. ev = hapd.wait_event(["WPS-NEW-AP-SETTINGS"], timeout=15)
  455. if ev is None:
  456. raise Exception("WPS configuration timed out")
  457. if "1026" not in ev:
  458. raise Exception("AP Settings missing from event")
  459. hapd.request("SET wps_cred_processing 0")
  460. if "FAIL" in hapd.request("WPS_CONFIG " + new_ssid.encode("hex") + " WPA2PSK CCMP " + new_passphrase.encode("hex")):
  461. raise Exception("WPS_CONFIG command failed")
  462. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  463. if ev is None:
  464. raise Exception("Association with the AP timed out")
  465. def test_ap_wps_reg_config_tkip(dev, apdev):
  466. """WPS registrar configuring AP to use TKIP and AP upgrading to TKIP+CCMP"""
  467. ssid = "test-wps-init-ap"
  468. appin = "12345670"
  469. hostapd.add_ap(apdev[0]['ifname'],
  470. { "ssid": ssid, "eap_server": "1", "wps_state": "1",
  471. "ap_pin": appin})
  472. logger.info("WPS configuration step")
  473. dev[0].request("SET wps_version_number 0x10")
  474. dev[0].dump_monitor()
  475. new_ssid = "wps-new-ssid-with-tkip"
  476. new_passphrase = "1234567890"
  477. dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPAPSK", "TKIP",
  478. new_passphrase)
  479. logger.info("Re-connect to verify WPA2 mixed mode")
  480. dev[0].request("DISCONNECT")
  481. id = 0
  482. dev[0].set_network(id, "pairwise", "CCMP")
  483. dev[0].set_network(id, "proto", "RSN")
  484. dev[0].connect_network(id)
  485. status = dev[0].get_status()
  486. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  487. raise Exception("Not fully connected")
  488. if status['ssid'] != new_ssid:
  489. raise Exception("Unexpected SSID")
  490. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP':
  491. raise Exception("Unexpected encryption configuration")
  492. if status['key_mgmt'] != 'WPA2-PSK':
  493. raise Exception("Unexpected key_mgmt")
  494. def test_ap_wps_setup_locked(dev, apdev):
  495. """WPS registrar locking up AP setup on AP PIN failures"""
  496. ssid = "test-wps-incorrect-ap-pin"
  497. appin = "12345670"
  498. hostapd.add_ap(apdev[0]['ifname'],
  499. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  500. "wpa_passphrase": "12345678", "wpa": "2",
  501. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  502. "ap_pin": appin})
  503. new_ssid = "wps-new-ssid-test"
  504. new_passphrase = "1234567890"
  505. ap_setup_locked=False
  506. for pin in ["55554444", "1234", "12345678", "00000000", "11111111"]:
  507. dev[0].dump_monitor()
  508. logger.info("Try incorrect AP PIN - attempt " + pin)
  509. dev[0].wps_reg(apdev[0]['bssid'], pin, new_ssid, "WPA2PSK",
  510. "CCMP", new_passphrase, no_wait=True)
  511. ev = dev[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"])
  512. if ev is None:
  513. raise Exception("Timeout on receiving WPS operation failure event")
  514. if "CTRL-EVENT-CONNECTED" in ev:
  515. raise Exception("Unexpected connection")
  516. if "config_error=15" in ev:
  517. logger.info("AP Setup Locked")
  518. ap_setup_locked=True
  519. elif "config_error=18" not in ev:
  520. raise Exception("config_error=18 not reported")
  521. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
  522. if ev is None:
  523. raise Exception("Timeout on disconnection event")
  524. time.sleep(0.1)
  525. if not ap_setup_locked:
  526. raise Exception("AP setup was not locked")
  527. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  528. status = hapd.request("WPS_GET_STATUS")
  529. if "Last WPS result: Failed" not in status:
  530. raise Exception("WPS failure result not shown correctly")
  531. if "Peer Address: " + dev[0].p2p_interface_addr() not in status:
  532. raise Exception("Peer address not shown correctly")
  533. time.sleep(0.5)
  534. dev[0].dump_monitor()
  535. logger.info("WPS provisioning step")
  536. pin = dev[0].wps_read_pin()
  537. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  538. hapd.request("WPS_PIN any " + pin)
  539. dev[0].request("WPS_PIN any " + pin)
  540. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=30)
  541. if ev is None:
  542. raise Exception("WPS success was not reported")
  543. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  544. if ev is None:
  545. raise Exception("Association with the AP timed out")
  546. appin = hapd.request("WPS_AP_PIN random")
  547. if "FAIL" in appin:
  548. raise Exception("Could not generate random AP PIN")
  549. ev = hapd.wait_event(["WPS-AP-SETUP-UNLOCKED"], timeout=10)
  550. if ev is None:
  551. raise Exception("Failed to unlock AP PIN")
  552. def test_ap_wps_pbc_overlap_2ap(dev, apdev):
  553. """WPS PBC session overlap with two active APs"""
  554. hostapd.add_ap(apdev[0]['ifname'],
  555. { "ssid": "wps1", "eap_server": "1", "wps_state": "2",
  556. "wpa_passphrase": "12345678", "wpa": "2",
  557. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  558. "wps_independent": "1"})
  559. hostapd.add_ap(apdev[1]['ifname'],
  560. { "ssid": "wps2", "eap_server": "1", "wps_state": "2",
  561. "wpa_passphrase": "123456789", "wpa": "2",
  562. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  563. "wps_independent": "1"})
  564. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  565. hapd.request("WPS_PBC")
  566. hapd2 = hostapd.Hostapd(apdev[1]['ifname'])
  567. hapd2.request("WPS_PBC")
  568. logger.info("WPS provisioning step")
  569. dev[0].dump_monitor()
  570. dev[0].request("WPS_PBC")
  571. ev = dev[0].wait_event(["WPS-OVERLAP-DETECTED"], timeout=15)
  572. if ev is None:
  573. raise Exception("PBC session overlap not detected")
  574. def test_ap_wps_pbc_overlap_2sta(dev, apdev):
  575. """WPS PBC session overlap with two active STAs"""
  576. ssid = "test-wps-pbc-overlap"
  577. hostapd.add_ap(apdev[0]['ifname'],
  578. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  579. "wpa_passphrase": "12345678", "wpa": "2",
  580. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  581. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  582. logger.info("WPS provisioning step")
  583. hapd.request("WPS_PBC")
  584. dev[0].dump_monitor()
  585. dev[1].dump_monitor()
  586. dev[0].request("WPS_PBC")
  587. dev[1].request("WPS_PBC")
  588. ev = dev[0].wait_event(["WPS-M2D"], timeout=15)
  589. if ev is None:
  590. raise Exception("PBC session overlap not detected (dev0)")
  591. if "config_error=12" not in ev:
  592. raise Exception("PBC session overlap not correctly reported (dev0)")
  593. ev = dev[1].wait_event(["WPS-M2D"], timeout=15)
  594. if ev is None:
  595. raise Exception("PBC session overlap not detected (dev1)")
  596. if "config_error=12" not in ev:
  597. raise Exception("PBC session overlap not correctly reported (dev1)")
  598. hapd.request("WPS_CANCEL")
  599. ret = hapd.request("WPS_PBC")
  600. if "FAIL" not in ret:
  601. raise Exception("PBC mode allowed to be started while PBC overlap still active")
  602. def test_ap_wps_cancel(dev, apdev):
  603. """WPS AP cancelling enabled config method"""
  604. ssid = "test-wps-ap-cancel"
  605. hostapd.add_ap(apdev[0]['ifname'],
  606. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  607. "wpa_passphrase": "12345678", "wpa": "2",
  608. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
  609. bssid = apdev[0]['bssid']
  610. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  611. logger.info("Verify PBC enable/cancel")
  612. hapd.request("WPS_PBC")
  613. dev[0].scan(freq="2412")
  614. bss = dev[0].get_bss(apdev[0]['bssid'])
  615. if "[WPS-PBC]" not in bss['flags']:
  616. raise Exception("WPS-PBC flag missing")
  617. if "FAIL" in hapd.request("WPS_CANCEL"):
  618. raise Exception("WPS_CANCEL failed")
  619. dev[0].scan(freq="2412")
  620. bss = dev[0].get_bss(apdev[0]['bssid'])
  621. if "[WPS-PBC]" in bss['flags']:
  622. raise Exception("WPS-PBC flag not cleared")
  623. logger.info("Verify PIN enable/cancel")
  624. hapd.request("WPS_PIN any 12345670")
  625. dev[0].scan(freq="2412")
  626. bss = dev[0].get_bss(apdev[0]['bssid'])
  627. if "[WPS-AUTH]" not in bss['flags']:
  628. raise Exception("WPS-AUTH flag missing")
  629. if "FAIL" in hapd.request("WPS_CANCEL"):
  630. raise Exception("WPS_CANCEL failed")
  631. dev[0].scan(freq="2412")
  632. bss = dev[0].get_bss(apdev[0]['bssid'])
  633. if "[WPS-AUTH]" in bss['flags']:
  634. raise Exception("WPS-AUTH flag not cleared")
  635. def test_ap_wps_er_add_enrollee(dev, apdev):
  636. """WPS ER configuring AP and adding a new enrollee using PIN"""
  637. ssid = "wps-er-add-enrollee"
  638. ap_pin = "12345670"
  639. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  640. hostapd.add_ap(apdev[0]['ifname'],
  641. { "ssid": ssid, "eap_server": "1", "wps_state": "1",
  642. "device_name": "Wireless AP", "manufacturer": "Company",
  643. "model_name": "WAP", "model_number": "123",
  644. "serial_number": "12345", "device_type": "6-0050F204-1",
  645. "os_version": "01020300",
  646. "config_methods": "label push_button",
  647. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
  648. logger.info("WPS configuration step")
  649. new_passphrase = "1234567890"
  650. dev[0].dump_monitor()
  651. dev[0].wps_reg(apdev[0]['bssid'], ap_pin, ssid, "WPA2PSK", "CCMP",
  652. new_passphrase)
  653. status = dev[0].get_status()
  654. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  655. raise Exception("Not fully connected")
  656. if status['ssid'] != ssid:
  657. raise Exception("Unexpected SSID")
  658. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  659. raise Exception("Unexpected encryption configuration")
  660. if status['key_mgmt'] != 'WPA2-PSK':
  661. raise Exception("Unexpected key_mgmt")
  662. logger.info("Start ER")
  663. dev[0].request("WPS_ER_START ifname=lo")
  664. ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
  665. if ev is None:
  666. raise Exception("AP discovery timed out")
  667. if ap_uuid not in ev:
  668. raise Exception("Expected AP UUID not found")
  669. logger.info("Learn AP configuration through UPnP")
  670. dev[0].dump_monitor()
  671. dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin)
  672. ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15)
  673. if ev is None:
  674. raise Exception("AP learn timed out")
  675. if ap_uuid not in ev:
  676. raise Exception("Expected AP UUID not in settings")
  677. if "ssid=" + ssid not in ev:
  678. raise Exception("Expected SSID not in settings")
  679. if "key=" + new_passphrase not in ev:
  680. raise Exception("Expected passphrase not in settings")
  681. logger.info("Add Enrollee using ER")
  682. pin = dev[1].wps_read_pin()
  683. dev[0].dump_monitor()
  684. dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr())
  685. dev[1].dump_monitor()
  686. dev[1].request("WPS_PIN any " + pin)
  687. ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=30)
  688. if ev is None:
  689. raise Exception("Enrollee did not report success")
  690. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  691. if ev is None:
  692. raise Exception("Association with the AP timed out")
  693. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
  694. if ev is None:
  695. raise Exception("WPS ER did not report success")
  696. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  697. logger.info("Add a specific Enrollee using ER")
  698. pin = dev[2].wps_read_pin()
  699. addr2 = dev[2].p2p_interface_addr()
  700. dev[0].dump_monitor()
  701. dev[2].dump_monitor()
  702. dev[2].request("WPS_PIN any " + pin)
  703. ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=10)
  704. if ev is None:
  705. raise Exception("Enrollee not seen")
  706. if addr2 not in ev:
  707. raise Exception("Unexpected Enrollee MAC address")
  708. dev[0].request("WPS_ER_PIN " + addr2 + " " + pin + " " + addr2)
  709. ev = dev[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  710. if ev is None:
  711. raise Exception("Association with the AP timed out")
  712. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
  713. if ev is None:
  714. raise Exception("WPS ER did not report success")
  715. logger.info("Verify registrar selection behavior")
  716. dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr())
  717. dev[1].request("DISCONNECT")
  718. dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
  719. dev[1].scan(freq="2412")
  720. bss = dev[1].get_bss(apdev[0]['bssid'])
  721. if "[WPS-AUTH]" not in bss['flags']:
  722. raise Exception("WPS-AUTH flag missing")
  723. logger.info("Stop ER")
  724. dev[0].dump_monitor()
  725. dev[0].request("WPS_ER_STOP")
  726. ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"])
  727. if ev is None:
  728. raise Exception("WPS ER unsubscription timed out")
  729. # It takes some time for the UPnP UNSUBSCRIBE command to go through, so wait
  730. # a bit before verifying that the scan results have change.
  731. time.sleep(0.2)
  732. dev[1].scan(freq="2412")
  733. bss = dev[1].get_bss(apdev[0]['bssid'])
  734. if "[WPS-AUTH]" in bss['flags']:
  735. raise Exception("WPS-AUTH flag not removed")
  736. def test_ap_wps_er_add_enrollee_pbc(dev, apdev):
  737. """WPS ER connected to AP and adding a new enrollee using PBC"""
  738. ssid = "wps-er-add-enrollee-pbc"
  739. ap_pin = "12345670"
  740. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  741. hostapd.add_ap(apdev[0]['ifname'],
  742. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  743. "wpa_passphrase": "12345678", "wpa": "2",
  744. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  745. "device_name": "Wireless AP", "manufacturer": "Company",
  746. "model_name": "WAP", "model_number": "123",
  747. "serial_number": "12345", "device_type": "6-0050F204-1",
  748. "os_version": "01020300",
  749. "config_methods": "label push_button",
  750. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
  751. logger.info("Learn AP configuration")
  752. dev[0].dump_monitor()
  753. dev[0].wps_reg(apdev[0]['bssid'], ap_pin)
  754. status = dev[0].get_status()
  755. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  756. raise Exception("Not fully connected")
  757. logger.info("Start ER")
  758. dev[0].request("WPS_ER_START ifname=lo")
  759. ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
  760. if ev is None:
  761. raise Exception("AP discovery timed out")
  762. if ap_uuid not in ev:
  763. raise Exception("Expected AP UUID not found")
  764. logger.info("Use learned network configuration on ER")
  765. dev[0].request("WPS_ER_SET_CONFIG " + ap_uuid + " 0")
  766. logger.info("Add Enrollee using ER and PBC")
  767. dev[0].dump_monitor()
  768. enrollee = dev[1].p2p_interface_addr()
  769. dev[1].dump_monitor()
  770. dev[1].request("WPS_PBC")
  771. for i in range(0, 2):
  772. ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=15)
  773. if ev is None:
  774. raise Exception("Enrollee discovery timed out")
  775. if enrollee in ev:
  776. break
  777. if i == 1:
  778. raise Exception("Expected Enrollee not found")
  779. dev[0].request("WPS_ER_PBC " + enrollee)
  780. ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=15)
  781. if ev is None:
  782. raise Exception("Enrollee did not report success")
  783. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  784. if ev is None:
  785. raise Exception("Association with the AP timed out")
  786. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
  787. if ev is None:
  788. raise Exception("WPS ER did not report success")
  789. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  790. # verify BSSID selection of the AP instead of UUID
  791. if "FAIL" in dev[0].request("WPS_ER_SET_CONFIG " + apdev[0]['bssid'] + " 0"):
  792. raise Exception("Could not select AP based on BSSID")
  793. def test_ap_wps_er_v10_add_enrollee_pin(dev, apdev):
  794. """WPS v1.0 ER connected to AP and adding a new enrollee using PIN"""
  795. ssid = "wps-er-add-enrollee-pbc"
  796. ap_pin = "12345670"
  797. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  798. hostapd.add_ap(apdev[0]['ifname'],
  799. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  800. "wpa_passphrase": "12345678", "wpa": "2",
  801. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  802. "device_name": "Wireless AP", "manufacturer": "Company",
  803. "model_name": "WAP", "model_number": "123",
  804. "serial_number": "12345", "device_type": "6-0050F204-1",
  805. "os_version": "01020300",
  806. "config_methods": "label push_button",
  807. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
  808. logger.info("Learn AP configuration")
  809. dev[0].request("SET wps_version_number 0x10")
  810. dev[0].dump_monitor()
  811. dev[0].wps_reg(apdev[0]['bssid'], ap_pin)
  812. status = dev[0].get_status()
  813. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  814. raise Exception("Not fully connected")
  815. logger.info("Start ER")
  816. dev[0].request("WPS_ER_START ifname=lo")
  817. ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
  818. if ev is None:
  819. raise Exception("AP discovery timed out")
  820. if ap_uuid not in ev:
  821. raise Exception("Expected AP UUID not found")
  822. logger.info("Use learned network configuration on ER")
  823. dev[0].request("WPS_ER_SET_CONFIG " + ap_uuid + " 0")
  824. logger.info("Add Enrollee using ER and PIN")
  825. enrollee = dev[1].p2p_interface_addr()
  826. pin = dev[1].wps_read_pin()
  827. dev[0].dump_monitor()
  828. dev[0].request("WPS_ER_PIN any " + pin + " " + enrollee)
  829. dev[1].dump_monitor()
  830. dev[1].request("WPS_PIN any " + pin)
  831. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  832. if ev is None:
  833. raise Exception("Association with the AP timed out")
  834. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
  835. if ev is None:
  836. raise Exception("WPS ER did not report success")
  837. def test_ap_wps_er_config_ap(dev, apdev):
  838. """WPS ER configuring AP over UPnP"""
  839. ssid = "wps-er-ap-config"
  840. ap_pin = "12345670"
  841. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  842. hostapd.add_ap(apdev[0]['ifname'],
  843. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  844. "wpa_passphrase": "12345678", "wpa": "2",
  845. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  846. "device_name": "Wireless AP", "manufacturer": "Company",
  847. "model_name": "WAP", "model_number": "123",
  848. "serial_number": "12345", "device_type": "6-0050F204-1",
  849. "os_version": "01020300",
  850. "config_methods": "label push_button",
  851. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
  852. logger.info("Connect ER to the AP")
  853. dev[0].connect(ssid, psk="12345678", scan_freq="2412")
  854. logger.info("WPS configuration step")
  855. dev[0].request("WPS_ER_START ifname=lo")
  856. ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
  857. if ev is None:
  858. raise Exception("AP discovery timed out")
  859. if ap_uuid not in ev:
  860. raise Exception("Expected AP UUID not found")
  861. new_passphrase = "1234567890"
  862. dev[0].request("WPS_ER_CONFIG " + apdev[0]['bssid'] + " " + ap_pin + " " +
  863. ssid.encode("hex") + " WPA2PSK CCMP " +
  864. new_passphrase.encode("hex"))
  865. ev = dev[0].wait_event(["WPS-SUCCESS"])
  866. if ev is None:
  867. raise Exception("WPS ER configuration operation timed out")
  868. dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
  869. dev[0].connect(ssid, psk="1234567890", scan_freq="2412")
  870. def test_ap_wps_fragmentation(dev, apdev):
  871. """WPS with fragmentation in EAP-WSC and mixed mode WPA+WPA2"""
  872. ssid = "test-wps-fragmentation"
  873. hostapd.add_ap(apdev[0]['ifname'],
  874. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  875. "wpa_passphrase": "12345678", "wpa": "3",
  876. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  877. "wpa_pairwise": "TKIP",
  878. "fragment_size": "50" })
  879. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  880. logger.info("WPS provisioning step")
  881. hapd.request("WPS_PBC")
  882. dev[0].dump_monitor()
  883. dev[0].request("SET wps_fragment_size 50")
  884. dev[0].request("WPS_PBC")
  885. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  886. if ev is None:
  887. raise Exception("Association with the AP timed out")
  888. status = dev[0].get_status()
  889. if status['wpa_state'] != 'COMPLETED':
  890. raise Exception("Not fully connected")
  891. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP':
  892. raise Exception("Unexpected encryption configuration")
  893. if status['key_mgmt'] != 'WPA2-PSK':
  894. raise Exception("Unexpected key_mgmt")
  895. def test_ap_wps_new_version_sta(dev, apdev):
  896. """WPS compatibility with new version number on the station"""
  897. ssid = "test-wps-ver"
  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. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  903. logger.info("WPS provisioning step")
  904. hapd.request("WPS_PBC")
  905. dev[0].dump_monitor()
  906. dev[0].request("SET wps_version_number 0x43")
  907. dev[0].request("SET wps_vendor_ext_m1 000137100100020001")
  908. dev[0].request("WPS_PBC")
  909. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  910. if ev is None:
  911. raise Exception("Association with the AP timed out")
  912. def test_ap_wps_new_version_ap(dev, apdev):
  913. """WPS compatibility with new version number on the AP"""
  914. ssid = "test-wps-ver"
  915. hostapd.add_ap(apdev[0]['ifname'],
  916. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  917. "wpa_passphrase": "12345678", "wpa": "2",
  918. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
  919. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  920. logger.info("WPS provisioning step")
  921. if "FAIL" in hapd.request("SET wps_version_number 0x43"):
  922. raise Exception("Failed to enable test functionality")
  923. hapd.request("WPS_PBC")
  924. dev[0].dump_monitor()
  925. dev[0].request("WPS_PBC")
  926. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  927. hapd.request("SET wps_version_number 0x20")
  928. if ev is None:
  929. raise Exception("Association with the AP timed out")
  930. def test_ap_wps_check_pin(dev, apdev):
  931. """Verify PIN checking through control interface"""
  932. hostapd.add_ap(apdev[0]['ifname'],
  933. { "ssid": "wps", "eap_server": "1", "wps_state": "2",
  934. "wpa_passphrase": "12345678", "wpa": "2",
  935. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
  936. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  937. for t in [ ("12345670", "12345670"),
  938. ("12345678", "FAIL-CHECKSUM"),
  939. ("1234-5670", "12345670"),
  940. ("1234 5670", "12345670"),
  941. ("1-2.3:4 5670", "12345670") ]:
  942. res = hapd.request("WPS_CHECK_PIN " + t[0]).rstrip('\n')
  943. res2 = dev[0].request("WPS_CHECK_PIN " + t[0]).rstrip('\n')
  944. if res != res2:
  945. raise Exception("Unexpected difference in WPS_CHECK_PIN responses")
  946. if res != t[1]:
  947. raise Exception("Incorrect WPS_CHECK_PIN response {} (expected {})".format(res, t[1]))
  948. if "FAIL" not in hapd.request("WPS_CHECK_PIN 12345"):
  949. raise Exception("Unexpected WPS_CHECK_PIN success")
  950. if "FAIL" not in hapd.request("WPS_CHECK_PIN 123456789"):
  951. raise Exception("Unexpected WPS_CHECK_PIN success")
  952. def test_ap_wps_wep_config(dev, apdev):
  953. """WPS 2.0 AP rejecting WEP configuration"""
  954. ssid = "test-wps-config"
  955. appin = "12345670"
  956. hostapd.add_ap(apdev[0]['ifname'],
  957. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  958. "ap_pin": appin})
  959. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  960. dev[0].wps_reg(apdev[0]['bssid'], appin, "wps-new-ssid-wep", "OPEN", "WEP",
  961. "hello", no_wait=True)
  962. ev = hapd.wait_event(["WPS-FAIL"], timeout=15)
  963. if ev is None:
  964. raise Exception("WPS-FAIL timed out")
  965. if "reason=2" not in ev:
  966. raise Exception("Unexpected reason code in WPS-FAIL")
  967. status = hapd.request("WPS_GET_STATUS")
  968. if "Last WPS result: Failed" not in status:
  969. raise Exception("WPS failure result not shown correctly")
  970. if "Failure Reason: WEP Prohibited" not in status:
  971. raise Exception("Failure reason not reported correctly")
  972. if "Peer Address: " + dev[0].p2p_interface_addr() not in status:
  973. raise Exception("Peer address not shown correctly")
  974. def test_ap_wps_wep_enroll(dev, apdev):
  975. """WPS 2.0 STA rejecting WEP configuration"""
  976. ssid = "test-wps-wep"
  977. hostapd.add_ap(apdev[0]['ifname'],
  978. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  979. "skip_cred_build": "1", "extra_cred": "wps-wep-cred" })
  980. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  981. hapd.request("WPS_PBC")
  982. dev[0].request("WPS_PBC")
  983. ev = dev[0].wait_event(["WPS-FAIL"], timeout=15)
  984. if ev is None:
  985. raise Exception("WPS-FAIL event timed out")
  986. if "msg=12" not in ev or "reason=2 (WEP Prohibited)" not in ev:
  987. raise Exception("Unexpected WPS-FAIL event: " + ev)
  988. def test_ap_wps_ie_fragmentation(dev, apdev):
  989. """WPS AP using fragmented WPS IE"""
  990. ssid = "test-wps-ie-fragmentation"
  991. params = { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  992. "wpa_passphrase": "12345678", "wpa": "2",
  993. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  994. "device_name": "1234567890abcdef1234567890abcdef",
  995. "manufacturer": "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
  996. "model_name": "1234567890abcdef1234567890abcdef",
  997. "model_number": "1234567890abcdef1234567890abcdef",
  998. "serial_number": "1234567890abcdef1234567890abcdef" }
  999. hostapd.add_ap(apdev[0]['ifname'], params)
  1000. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  1001. hapd.request("WPS_PBC")
  1002. dev[0].request("WPS_PBC")
  1003. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  1004. if ev is None:
  1005. raise Exception("Association with the AP timed out")
  1006. bss = dev[0].get_bss(apdev[0]['bssid'])
  1007. if "wps_device_name" not in bss or bss['wps_device_name'] != "1234567890abcdef1234567890abcdef":
  1008. logger.info(bss)
  1009. raise Exception("Device Name not received correctly")
  1010. if len(re.findall("dd..0050f204", bss['ie'])) != 2:
  1011. raise Exception("Unexpected number of WPS IEs")
  1012. def get_psk(pskfile):
  1013. psks = {}
  1014. with open(pskfile, "r") as f:
  1015. lines = f.read().splitlines()
  1016. for l in lines:
  1017. if l == "# WPA PSKs":
  1018. continue
  1019. (addr,psk) = l.split(' ')
  1020. psks[addr] = psk
  1021. return psks
  1022. def test_ap_wps_per_station_psk(dev, apdev):
  1023. """WPS PBC provisioning with per-station PSK"""
  1024. addr0 = dev[0].p2p_dev_addr()
  1025. addr1 = dev[1].p2p_dev_addr()
  1026. addr2 = dev[2].p2p_dev_addr()
  1027. ssid = "wps"
  1028. appin = "12345670"
  1029. pskfile = "/tmp/ap_wps_per_enrollee_psk.psk_file"
  1030. try:
  1031. os.remove(pskfile)
  1032. except:
  1033. pass
  1034. try:
  1035. with open(pskfile, "w") as f:
  1036. f.write("# WPA PSKs\n")
  1037. params = { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  1038. "wpa": "2", "wpa_key_mgmt": "WPA-PSK",
  1039. "rsn_pairwise": "CCMP", "ap_pin": appin,
  1040. "wpa_psk_file": pskfile }
  1041. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1042. logger.info("First enrollee")
  1043. hapd.request("WPS_PBC")
  1044. dev[0].request("WPS_PBC")
  1045. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"])
  1046. if ev is None:
  1047. raise Exception("Association with the AP timed out (1)")
  1048. logger.info("Second enrollee")
  1049. hapd.request("WPS_PBC")
  1050. dev[1].request("WPS_PBC")
  1051. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"])
  1052. if ev is None:
  1053. raise Exception("Association with the AP timed out (2)")
  1054. logger.info("External registrar")
  1055. dev[2].wps_reg(apdev[0]['bssid'], appin)
  1056. logger.info("Verifying PSK results")
  1057. psks = get_psk(pskfile)
  1058. if addr0 not in psks:
  1059. raise Exception("No PSK recorded for sta0")
  1060. if addr1 not in psks:
  1061. raise Exception("No PSK recorded for sta1")
  1062. if addr2 not in psks:
  1063. raise Exception("No PSK recorded for sta2")
  1064. if psks[addr0] == psks[addr1]:
  1065. raise Exception("Same PSK recorded for sta0 and sta1")
  1066. if psks[addr0] == psks[addr2]:
  1067. raise Exception("Same PSK recorded for sta0 and sta2")
  1068. if psks[addr1] == psks[addr2]:
  1069. raise Exception("Same PSK recorded for sta1 and sta2")
  1070. dev[0].request("REMOVE_NETWORK all")
  1071. logger.info("Second external registrar")
  1072. dev[0].wps_reg(apdev[0]['bssid'], appin)
  1073. psks2 = get_psk(pskfile)
  1074. if addr0 not in psks2:
  1075. raise Exception("No PSK recorded for sta0(reg)")
  1076. if psks[addr0] == psks2[addr0]:
  1077. raise Exception("Same PSK recorded for sta0(enrollee) and sta0(reg)")
  1078. finally:
  1079. os.remove(pskfile)
  1080. def test_ap_wps_pin_request_file(dev, apdev):
  1081. """WPS PIN provisioning with configured AP"""
  1082. ssid = "wps"
  1083. pinfile = "/tmp/ap_wps_pin_request_file.log"
  1084. if os.path.exists(pinfile):
  1085. subprocess.call(['sudo', 'rm', pinfile])
  1086. hostapd.add_ap(apdev[0]['ifname'],
  1087. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  1088. "wps_pin_requests": pinfile,
  1089. "wpa_passphrase": "12345678", "wpa": "2",
  1090. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  1091. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  1092. uuid = dev[0].get_status_field("uuid")
  1093. pin = dev[0].wps_read_pin()
  1094. try:
  1095. dev[0].request("WPS_PIN any " + pin)
  1096. ev = hapd.wait_event(["WPS-PIN-NEEDED"], timeout=15)
  1097. if ev is None:
  1098. raise Exception("PIN needed event not shown")
  1099. if uuid not in ev:
  1100. raise Exception("UUID mismatch")
  1101. dev[0].request("WPS_CANCEL")
  1102. success = False
  1103. with open(pinfile, "r") as f:
  1104. lines = f.readlines()
  1105. for l in lines:
  1106. if uuid in l:
  1107. success = True
  1108. break
  1109. if not success:
  1110. raise Exception("PIN request entry not in the log file")
  1111. finally:
  1112. subprocess.call(['sudo', 'rm', pinfile])
  1113. def add_ssdp_ap(ifname, ap_uuid):
  1114. ssid = "wps-ssdp"
  1115. ap_pin = "12345670"
  1116. hostapd.add_ap(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. "device_name": "Wireless AP", "manufacturer": "Company",
  1121. "model_name": "WAP", "model_number": "123",
  1122. "serial_number": "12345", "device_type": "6-0050F204-1",
  1123. "os_version": "01020300",
  1124. "config_methods": "label push_button",
  1125. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo",
  1126. "friendly_name": "WPS Access Point",
  1127. "manufacturer_url": "http://www.example.com/",
  1128. "model_description": "Wireless Access Point",
  1129. "model_url": "http://www.example.com/model/",
  1130. "upc": "123456789012" })
  1131. def ssdp_send(msg, no_recv=False):
  1132. socket.setdefaulttimeout(1)
  1133. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
  1134. sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  1135. sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
  1136. sock.bind(("127.0.0.1", 0))
  1137. sock.sendto(msg, ("239.255.255.250", 1900))
  1138. if no_recv:
  1139. return None
  1140. return sock.recv(1000)
  1141. def ssdp_send_msearch(st):
  1142. msg = '\r\n'.join([
  1143. 'M-SEARCH * HTTP/1.1',
  1144. 'HOST: 239.255.255.250:1900',
  1145. 'MX: 1',
  1146. 'MAN: "ssdp:discover"',
  1147. 'ST: ' + st,
  1148. '', ''])
  1149. return ssdp_send(msg)
  1150. def test_ap_wps_ssdp_msearch(dev, apdev):
  1151. """WPS AP and SSDP M-SEARCH messages"""
  1152. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  1153. add_ssdp_ap(apdev[0]['ifname'], ap_uuid)
  1154. msg = '\r\n'.join([
  1155. 'M-SEARCH * HTTP/1.1',
  1156. 'Host: 239.255.255.250:1900',
  1157. 'Mx: 1',
  1158. 'Man: "ssdp:discover"',
  1159. 'St: urn:schemas-wifialliance-org:device:WFADevice:1',
  1160. '', ''])
  1161. ssdp_send(msg)
  1162. msg = '\r\n'.join([
  1163. 'M-SEARCH * HTTP/1.1',
  1164. 'host:\t239.255.255.250:1900\t\t\t\t \t\t',
  1165. 'mx: \t1\t\t ',
  1166. 'man: \t \t "ssdp:discover" ',
  1167. 'st: urn:schemas-wifialliance-org:device:WFADevice:1\t\t',
  1168. '', ''])
  1169. ssdp_send(msg)
  1170. ssdp_send_msearch("ssdp:all")
  1171. ssdp_send_msearch("upnp:rootdevice")
  1172. ssdp_send_msearch("uuid:" + ap_uuid)
  1173. ssdp_send_msearch("urn:schemas-wifialliance-org:service:WFAWLANConfig:1")
  1174. ssdp_send_msearch("urn:schemas-wifialliance-org:device:WFADevice:1");
  1175. msg = '\r\n'.join([
  1176. 'M-SEARCH * HTTP/1.1',
  1177. 'HOST:\t239.255.255.250:1900',
  1178. 'MAN: "ssdp:discover"',
  1179. 'MX: 130',
  1180. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1181. '', ''])
  1182. ssdp_send(msg, no_recv=True)
  1183. def test_ap_wps_ssdp_invalid_msearch(dev, apdev):
  1184. """WPS AP and invalid SSDP M-SEARCH messages"""
  1185. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  1186. add_ssdp_ap(apdev[0]['ifname'], ap_uuid)
  1187. socket.setdefaulttimeout(1)
  1188. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
  1189. sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  1190. sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
  1191. sock.bind(("127.0.0.1", 0))
  1192. logger.debug("Missing MX")
  1193. msg = '\r\n'.join([
  1194. 'M-SEARCH * HTTP/1.1',
  1195. 'HOST: 239.255.255.250:1900',
  1196. 'MAN: "ssdp:discover"',
  1197. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1198. '', ''])
  1199. sock.sendto(msg, ("239.255.255.250", 1900))
  1200. logger.debug("Negative MX")
  1201. msg = '\r\n'.join([
  1202. 'M-SEARCH * HTTP/1.1',
  1203. 'HOST: 239.255.255.250:1900',
  1204. 'MX: -1',
  1205. 'MAN: "ssdp:discover"',
  1206. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1207. '', ''])
  1208. sock.sendto(msg, ("239.255.255.250", 1900))
  1209. logger.debug("Invalid MX")
  1210. msg = '\r\n'.join([
  1211. 'M-SEARCH * HTTP/1.1',
  1212. 'HOST: 239.255.255.250:1900',
  1213. 'MX; 1',
  1214. 'MAN: "ssdp:discover"',
  1215. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1216. '', ''])
  1217. sock.sendto(msg, ("239.255.255.250", 1900))
  1218. logger.debug("Missing MAN")
  1219. msg = '\r\n'.join([
  1220. 'M-SEARCH * HTTP/1.1',
  1221. 'HOST: 239.255.255.250:1900',
  1222. 'MX: 1',
  1223. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1224. '', ''])
  1225. sock.sendto(msg, ("239.255.255.250", 1900))
  1226. logger.debug("Invalid MAN")
  1227. msg = '\r\n'.join([
  1228. 'M-SEARCH * HTTP/1.1',
  1229. 'HOST: 239.255.255.250:1900',
  1230. 'MX: 1',
  1231. 'MAN: foo',
  1232. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1233. '', ''])
  1234. sock.sendto(msg, ("239.255.255.250", 1900))
  1235. msg = '\r\n'.join([
  1236. 'M-SEARCH * HTTP/1.1',
  1237. 'HOST: 239.255.255.250:1900',
  1238. 'MX: 1',
  1239. 'MAN; "ssdp:discover"',
  1240. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1241. '', ''])
  1242. sock.sendto(msg, ("239.255.255.250", 1900))
  1243. logger.debug("Missing HOST")
  1244. msg = '\r\n'.join([
  1245. 'M-SEARCH * HTTP/1.1',
  1246. 'MAN: "ssdp:discover"',
  1247. 'MX: 1',
  1248. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1249. '', ''])
  1250. sock.sendto(msg, ("239.255.255.250", 1900))
  1251. logger.debug("Missing ST")
  1252. msg = '\r\n'.join([
  1253. 'M-SEARCH * HTTP/1.1',
  1254. 'HOST: 239.255.255.250:1900',
  1255. 'MAN: "ssdp:discover"',
  1256. 'MX: 1',
  1257. '', ''])
  1258. sock.sendto(msg, ("239.255.255.250", 1900))
  1259. logger.debug("Mismatching ST")
  1260. msg = '\r\n'.join([
  1261. 'M-SEARCH * HTTP/1.1',
  1262. 'HOST: 239.255.255.250:1900',
  1263. 'MAN: "ssdp:discover"',
  1264. 'MX: 1',
  1265. 'ST: uuid:16d5f8a9-4ee4-4f5e-81f9-cc6e2f47f42d',
  1266. '', ''])
  1267. sock.sendto(msg, ("239.255.255.250", 1900))
  1268. msg = '\r\n'.join([
  1269. 'M-SEARCH * HTTP/1.1',
  1270. 'HOST: 239.255.255.250:1900',
  1271. 'MAN: "ssdp:discover"',
  1272. 'MX: 1',
  1273. 'ST: foo:bar',
  1274. '', ''])
  1275. sock.sendto(msg, ("239.255.255.250", 1900))
  1276. msg = '\r\n'.join([
  1277. 'M-SEARCH * HTTP/1.1',
  1278. 'HOST: 239.255.255.250:1900',
  1279. 'MAN: "ssdp:discover"',
  1280. 'MX: 1',
  1281. 'ST: foobar',
  1282. '', ''])
  1283. sock.sendto(msg, ("239.255.255.250", 1900))
  1284. logger.debug("Invalid ST")
  1285. msg = '\r\n'.join([
  1286. 'M-SEARCH * HTTP/1.1',
  1287. 'HOST: 239.255.255.250:1900',
  1288. 'MAN: "ssdp:discover"',
  1289. 'MX: 1',
  1290. 'ST; urn:schemas-wifialliance-org:device:WFADevice:1',
  1291. '', ''])
  1292. sock.sendto(msg, ("239.255.255.250", 1900))
  1293. logger.debug("Invalid M-SEARCH")
  1294. msg = '\r\n'.join([
  1295. 'M+SEARCH * HTTP/1.1',
  1296. 'HOST: 239.255.255.250:1900',
  1297. 'MAN: "ssdp:discover"',
  1298. 'MX: 1',
  1299. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1300. '', ''])
  1301. sock.sendto(msg, ("239.255.255.250", 1900))
  1302. msg = '\r\n'.join([
  1303. 'M-SEARCH-* HTTP/1.1',
  1304. 'HOST: 239.255.255.250:1900',
  1305. 'MAN: "ssdp:discover"',
  1306. 'MX: 1',
  1307. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1308. '', ''])
  1309. sock.sendto(msg, ("239.255.255.250", 1900))
  1310. logger.debug("Invalid message format")
  1311. sock.sendto("NOTIFY * HTTP/1.1", ("239.255.255.250", 1900))
  1312. msg = '\r'.join([
  1313. 'M-SEARCH * HTTP/1.1',
  1314. 'HOST: 239.255.255.250:1900',
  1315. 'MAN: "ssdp:discover"',
  1316. 'MX: 1',
  1317. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1318. '', ''])
  1319. sock.sendto(msg, ("239.255.255.250", 1900))
  1320. try:
  1321. r = sock.recv(1000)
  1322. raise Exception("Unexpected M-SEARCH response: " + r)
  1323. except socket.timeout:
  1324. pass
  1325. logger.debug("Valid M-SEARCH")
  1326. msg = '\r\n'.join([
  1327. 'M-SEARCH * HTTP/1.1',
  1328. 'HOST: 239.255.255.250:1900',
  1329. 'MAN: "ssdp:discover"',
  1330. 'MX: 1',
  1331. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1332. '', ''])
  1333. sock.sendto(msg, ("239.255.255.250", 1900))
  1334. try:
  1335. r = sock.recv(1000)
  1336. pass
  1337. except socket.timeout:
  1338. raise Exception("No SSDP response")
  1339. def test_ap_wps_ssdp_burst(dev, apdev):
  1340. """WPS AP and SSDP burst"""
  1341. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  1342. add_ssdp_ap(apdev[0]['ifname'], ap_uuid)
  1343. msg = '\r\n'.join([
  1344. 'M-SEARCH * HTTP/1.1',
  1345. 'HOST: 239.255.255.250:1900',
  1346. 'MAN: "ssdp:discover"',
  1347. 'MX: 1',
  1348. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1349. '', ''])
  1350. socket.setdefaulttimeout(1)
  1351. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
  1352. sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  1353. sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
  1354. sock.bind(("127.0.0.1", 0))
  1355. for i in range(0, 25):
  1356. sock.sendto(msg, ("239.255.255.250", 1900))
  1357. resp = 0
  1358. while True:
  1359. try:
  1360. r = sock.recv(1000)
  1361. if not r.startswith("HTTP/1.1 200 OK\r\n"):
  1362. raise Exception("Unexpected message: " + r)
  1363. resp += 1
  1364. except socket.timeout:
  1365. break
  1366. if resp < 20:
  1367. raise Exception("Too few SSDP responses")
  1368. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
  1369. sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  1370. sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
  1371. sock.bind(("127.0.0.1", 0))
  1372. for i in range(0, 25):
  1373. sock.sendto(msg, ("239.255.255.250", 1900))
  1374. while True:
  1375. try:
  1376. r = sock.recv(1000)
  1377. if ap_uuid in r:
  1378. break
  1379. except socket.timeout:
  1380. raise Exception("No SSDP response")
  1381. def ssdp_get_location(uuid):
  1382. res = ssdp_send_msearch("uuid:" + uuid)
  1383. location = None
  1384. for l in res.splitlines():
  1385. if l.lower().startswith("location:"):
  1386. location = l.split(':', 1)[1].strip()
  1387. break
  1388. if location is None:
  1389. raise Exception("No UPnP location found")
  1390. return location
  1391. def upnp_get_urls(location):
  1392. conn = urllib.urlopen(location)
  1393. tree = ET.parse(conn)
  1394. root = tree.getroot()
  1395. urn = '{urn:schemas-upnp-org:device-1-0}'
  1396. service = root.find("./" + urn + "device/" + urn + "serviceList/" + urn + "service")
  1397. res = {}
  1398. res['scpd_url'] = urlparse.urljoin(location, service.find(urn + 'SCPDURL').text)
  1399. res['control_url'] = urlparse.urljoin(location, service.find(urn + 'controlURL').text)
  1400. res['event_sub_url'] = urlparse.urljoin(location, service.find(urn + 'eventSubURL').text)
  1401. return res
  1402. def upnp_soap_action(conn, path, action, include_soap_action=True, soap_action_override=None):
  1403. soapns = 'http://schemas.xmlsoap.org/soap/envelope/'
  1404. wpsns = 'urn:schemas-wifialliance-org:service:WFAWLANConfig:1'
  1405. ET.register_namespace('soapenv', soapns)
  1406. ET.register_namespace('wfa', wpsns)
  1407. attrib = {}
  1408. attrib['{%s}encodingStyle' % soapns] = 'http://schemas.xmlsoap.org/soap/encoding/'
  1409. root = ET.Element("{%s}Envelope" % soapns, attrib=attrib)
  1410. body = ET.SubElement(root, "{%s}Body" % soapns)
  1411. act = ET.SubElement(body, "{%s}%s" % (wpsns, action))
  1412. tree = ET.ElementTree(root)
  1413. soap = StringIO.StringIO()
  1414. tree.write(soap, xml_declaration=True, encoding='utf-8')
  1415. headers = { "Content-type": 'text/xml; charset="utf-8"' }
  1416. if include_soap_action:
  1417. headers["SOAPAction"] = '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#%s"' % action
  1418. elif soap_action_override:
  1419. headers["SOAPAction"] = soap_action_override
  1420. conn.request("POST", path, soap.getvalue(), headers)
  1421. return conn.getresponse()
  1422. def test_ap_wps_upnp(dev, apdev):
  1423. """WPS AP and UPnP operations"""
  1424. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  1425. add_ssdp_ap(apdev[0]['ifname'], ap_uuid)
  1426. location = ssdp_get_location(ap_uuid)
  1427. urls = upnp_get_urls(location)
  1428. conn = urllib.urlopen(urls['scpd_url'])
  1429. scpd = conn.read()
  1430. conn = urllib.urlopen(urlparse.urljoin(location, "unknown.html"))
  1431. if conn.getcode() != 404:
  1432. raise Exception("Unexpected HTTP response to GET unknown URL")
  1433. url = urlparse.urlparse(location)
  1434. conn = httplib.HTTPConnection(url.netloc)
  1435. #conn.set_debuglevel(1)
  1436. headers = { "Content-type": 'text/xml; charset="utf-8"',
  1437. "SOAPAction": '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#GetDeviceInfo"' }
  1438. conn.request("POST", "hello", "\r\n\r\n", headers)
  1439. resp = conn.getresponse()
  1440. if resp.status != 404:
  1441. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1442. conn.request("UNKNOWN", "hello", "\r\n\r\n", headers)
  1443. resp = conn.getresponse()
  1444. if resp.status != 501:
  1445. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1446. headers = { "Content-type": 'text/xml; charset="utf-8"',
  1447. "SOAPAction": '"urn:some-unknown-action#GetDeviceInfo"' }
  1448. ctrlurl = urlparse.urlparse(urls['control_url'])
  1449. conn.request("POST", ctrlurl.path, "\r\n\r\n", headers)
  1450. resp = conn.getresponse()
  1451. if resp.status != 401:
  1452. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1453. logger.debug("GetDeviceInfo without SOAPAction header")
  1454. resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo",
  1455. include_soap_action=False)
  1456. if resp.status != 401:
  1457. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1458. logger.debug("GetDeviceInfo with invalid SOAPAction header")
  1459. for act in [ "foo",
  1460. "urn:schemas-wifialliance-org:service:WFAWLANConfig:1#GetDeviceInfo",
  1461. '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1"',
  1462. '"urn:schemas-wifialliance-org:service:WFAWLANConfig:123#GetDevice']:
  1463. resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo",
  1464. include_soap_action=False,
  1465. soap_action_override=act)
  1466. if resp.status != 401:
  1467. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1468. resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo")
  1469. if resp.status != 200:
  1470. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1471. dev = resp.read()
  1472. if "NewDeviceInfo" not in dev:
  1473. raise Exception("Unexpected GetDeviceInfo response")
  1474. logger.debug("PutMessage without required parameters")
  1475. resp = upnp_soap_action(conn, ctrlurl.path, "PutMessage")
  1476. if resp.status != 600:
  1477. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1478. logger.debug("PutWLANResponse without required parameters")
  1479. resp = upnp_soap_action(conn, ctrlurl.path, "PutWLANResponse")
  1480. if resp.status != 600:
  1481. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1482. logger.debug("SetSelectedRegistrar from unregistered ER")
  1483. resp = upnp_soap_action(conn, ctrlurl.path, "SetSelectedRegistrar")
  1484. if resp.status != 501:
  1485. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1486. logger.debug("Unknown action")
  1487. resp = upnp_soap_action(conn, ctrlurl.path, "Unknown")
  1488. if resp.status != 401:
  1489. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1490. def test_ap_wps_upnp_subscribe(dev, apdev):
  1491. """WPS AP and UPnP event subscription"""
  1492. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  1493. add_ssdp_ap(apdev[0]['ifname'], ap_uuid)
  1494. location = ssdp_get_location(ap_uuid)
  1495. urls = upnp_get_urls(location)
  1496. eventurl = urlparse.urlparse(urls['event_sub_url'])
  1497. url = urlparse.urlparse(location)
  1498. conn = httplib.HTTPConnection(url.netloc)
  1499. #conn.set_debuglevel(1)
  1500. headers = { "callback": '<http://127.0.0.1:12345/event>',
  1501. "timeout": "Second-1234" }
  1502. conn.request("SUBSCRIBE", "hello", "\r\n\r\n", headers)
  1503. resp = conn.getresponse()
  1504. if resp.status != 412:
  1505. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1506. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1507. resp = conn.getresponse()
  1508. if resp.status != 412:
  1509. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1510. headers = { "NT": "upnp:event",
  1511. "timeout": "Second-1234" }
  1512. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1513. resp = conn.getresponse()
  1514. if resp.status != 412:
  1515. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1516. headers = { "callback": '<http://127.0.0.1:12345/event>',
  1517. "NT": "upnp:foobar",
  1518. "timeout": "Second-1234" }
  1519. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1520. resp = conn.getresponse()
  1521. if resp.status != 400:
  1522. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1523. logger.debug("Valid subscription")
  1524. headers = { "callback": '<http://127.0.0.1:12345/event>',
  1525. "NT": "upnp:event",
  1526. "timeout": "Second-1234" }
  1527. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1528. resp = conn.getresponse()
  1529. if resp.status != 200:
  1530. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1531. sid = resp.getheader("sid")
  1532. logger.debug("Subscription SID " + sid)
  1533. logger.debug("Invalid re-subscription")
  1534. headers = { "NT": "upnp:event",
  1535. "sid": "123456734567854",
  1536. "timeout": "Second-1234" }
  1537. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1538. resp = conn.getresponse()
  1539. if resp.status != 400:
  1540. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1541. logger.debug("Invalid re-subscription")
  1542. headers = { "NT": "upnp:event",
  1543. "sid": "uuid:123456734567854",
  1544. "timeout": "Second-1234" }
  1545. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1546. resp = conn.getresponse()
  1547. if resp.status != 400:
  1548. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1549. logger.debug("Invalid re-subscription")
  1550. headers = { "callback": '<http://127.0.0.1:12345/event>',
  1551. "NT": "upnp:event",
  1552. "sid": sid,
  1553. "timeout": "Second-1234" }
  1554. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1555. resp = conn.getresponse()
  1556. if resp.status != 400:
  1557. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1558. logger.debug("SID mismatch in re-subscription")
  1559. headers = { "NT": "upnp:event",
  1560. "sid": "uuid:4c2bca79-1ff4-4e43-85d4-952a2b8a51fb",
  1561. "timeout": "Second-1234" }
  1562. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1563. resp = conn.getresponse()
  1564. if resp.status != 412:
  1565. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1566. logger.debug("Valid re-subscription")
  1567. headers = { "NT": "upnp:event",
  1568. "sid": sid,
  1569. "timeout": "Second-1234" }
  1570. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1571. resp = conn.getresponse()
  1572. if resp.status != 200:
  1573. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1574. sid2 = resp.getheader("sid")
  1575. logger.debug("Subscription SID " + sid2)
  1576. if sid != sid2:
  1577. raise Exception("Unexpected SID change")
  1578. logger.debug("Valid re-subscription")
  1579. headers = { "NT": "upnp:event",
  1580. "sid": "uuid: \t \t" + sid.split(':')[1],
  1581. "timeout": "Second-1234" }
  1582. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1583. resp = conn.getresponse()
  1584. if resp.status != 200:
  1585. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1586. logger.debug("Invalid unsubscription")
  1587. headers = { "sid": sid }
  1588. conn.request("UNSUBSCRIBE", "/hello", "\r\n\r\n", headers)
  1589. resp = conn.getresponse()
  1590. if resp.status != 412:
  1591. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1592. headers = { "foo": "bar" }
  1593. conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1594. resp = conn.getresponse()
  1595. if resp.status != 412:
  1596. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1597. logger.debug("Valid unsubscription")
  1598. headers = { "sid": sid }
  1599. conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1600. resp = conn.getresponse()
  1601. if resp.status != 200:
  1602. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1603. logger.debug("Unsubscription for not existing SID")
  1604. headers = { "sid": sid }
  1605. conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1606. resp = conn.getresponse()
  1607. if resp.status != 412:
  1608. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1609. logger.debug("Invalid unsubscription")
  1610. headers = { "sid": " \t \tfoo" }
  1611. conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1612. resp = conn.getresponse()
  1613. if resp.status != 400:
  1614. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1615. logger.debug("Invalid unsubscription")
  1616. headers = { "sid": "uuid:\t \tfoo" }
  1617. conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1618. resp = conn.getresponse()
  1619. if resp.status != 400:
  1620. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1621. logger.debug("Invalid unsubscription")
  1622. headers = { "NT": "upnp:event",
  1623. "sid": sid }
  1624. conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1625. resp = conn.getresponse()
  1626. if resp.status != 400:
  1627. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1628. headers = { "callback": '<http://127.0.0.1:12345/event>',
  1629. "sid": sid }
  1630. conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1631. resp = conn.getresponse()
  1632. if resp.status != 400:
  1633. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1634. logger.debug("Valid subscription with multiple callbacks")
  1635. 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>',
  1636. "NT": "upnp:event",
  1637. "timeout": "Second-1234" }
  1638. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1639. resp = conn.getresponse()
  1640. if resp.status != 200:
  1641. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1642. sid = resp.getheader("sid")
  1643. logger.debug("Subscription SID " + sid)