test_ap_wps.py 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791
  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. raise Exception("Device Name not received correctly")
  1009. if len(re.findall("dd..0050f204", bss['ie'])) != 2:
  1010. raise Exception("Unexpected number of WPS IEs")
  1011. def get_psk(pskfile):
  1012. psks = {}
  1013. with open(pskfile, "r") as f:
  1014. lines = f.read().splitlines()
  1015. for l in lines:
  1016. if l == "# WPA PSKs":
  1017. continue
  1018. (addr,psk) = l.split(' ')
  1019. psks[addr] = psk
  1020. return psks
  1021. def test_ap_wps_per_station_psk(dev, apdev):
  1022. """WPS PBC provisioning with per-station PSK"""
  1023. addr0 = dev[0].p2p_dev_addr()
  1024. addr1 = dev[1].p2p_dev_addr()
  1025. addr2 = dev[2].p2p_dev_addr()
  1026. ssid = "wps"
  1027. appin = "12345670"
  1028. pskfile = "/tmp/ap_wps_per_enrollee_psk.psk_file"
  1029. try:
  1030. os.remove(pskfile)
  1031. except:
  1032. pass
  1033. try:
  1034. with open(pskfile, "w") as f:
  1035. f.write("# WPA PSKs\n")
  1036. params = { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  1037. "wpa": "2", "wpa_key_mgmt": "WPA-PSK",
  1038. "rsn_pairwise": "CCMP", "ap_pin": appin,
  1039. "wpa_psk_file": pskfile }
  1040. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  1041. logger.info("First enrollee")
  1042. hapd.request("WPS_PBC")
  1043. dev[0].request("WPS_PBC")
  1044. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"])
  1045. if ev is None:
  1046. raise Exception("Association with the AP timed out (1)")
  1047. logger.info("Second enrollee")
  1048. hapd.request("WPS_PBC")
  1049. dev[1].request("WPS_PBC")
  1050. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"])
  1051. if ev is None:
  1052. raise Exception("Association with the AP timed out (2)")
  1053. logger.info("External registrar")
  1054. dev[2].wps_reg(apdev[0]['bssid'], appin)
  1055. logger.info("Verifying PSK results")
  1056. psks = get_psk(pskfile)
  1057. if addr0 not in psks:
  1058. raise Exception("No PSK recorded for sta0")
  1059. if addr1 not in psks:
  1060. raise Exception("No PSK recorded for sta1")
  1061. if addr2 not in psks:
  1062. raise Exception("No PSK recorded for sta2")
  1063. if psks[addr0] == psks[addr1]:
  1064. raise Exception("Same PSK recorded for sta0 and sta1")
  1065. if psks[addr0] == psks[addr2]:
  1066. raise Exception("Same PSK recorded for sta0 and sta2")
  1067. if psks[addr1] == psks[addr2]:
  1068. raise Exception("Same PSK recorded for sta1 and sta2")
  1069. dev[0].request("REMOVE_NETWORK all")
  1070. logger.info("Second external registrar")
  1071. dev[0].wps_reg(apdev[0]['bssid'], appin)
  1072. psks2 = get_psk(pskfile)
  1073. if addr0 not in psks2:
  1074. raise Exception("No PSK recorded for sta0(reg)")
  1075. if psks[addr0] == psks2[addr0]:
  1076. raise Exception("Same PSK recorded for sta0(enrollee) and sta0(reg)")
  1077. finally:
  1078. os.remove(pskfile)
  1079. def test_ap_wps_pin_request_file(dev, apdev):
  1080. """WPS PIN provisioning with configured AP"""
  1081. ssid = "wps"
  1082. pinfile = "/tmp/ap_wps_pin_request_file.log"
  1083. if os.path.exists(pinfile):
  1084. subprocess.call(['sudo', 'rm', pinfile])
  1085. hostapd.add_ap(apdev[0]['ifname'],
  1086. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  1087. "wps_pin_requests": pinfile,
  1088. "wpa_passphrase": "12345678", "wpa": "2",
  1089. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  1090. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  1091. uuid = dev[0].get_status_field("uuid")
  1092. pin = dev[0].wps_read_pin()
  1093. try:
  1094. dev[0].request("WPS_PIN any " + pin)
  1095. ev = hapd.wait_event(["WPS-PIN-NEEDED"], timeout=15)
  1096. if ev is None:
  1097. raise Exception("PIN needed event not shown")
  1098. if uuid not in ev:
  1099. raise Exception("UUID mismatch")
  1100. dev[0].request("WPS_CANCEL")
  1101. success = False
  1102. with open(pinfile, "r") as f:
  1103. lines = f.readlines()
  1104. for l in lines:
  1105. if uuid in l:
  1106. success = True
  1107. break
  1108. if not success:
  1109. raise Exception("PIN request entry not in the log file")
  1110. finally:
  1111. subprocess.call(['sudo', 'rm', pinfile])
  1112. def add_ssdp_ap(ifname, ap_uuid):
  1113. ssid = "wps-ssdp"
  1114. ap_pin = "12345670"
  1115. hostapd.add_ap(ifname,
  1116. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  1117. "wpa_passphrase": "12345678", "wpa": "2",
  1118. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  1119. "device_name": "Wireless AP", "manufacturer": "Company",
  1120. "model_name": "WAP", "model_number": "123",
  1121. "serial_number": "12345", "device_type": "6-0050F204-1",
  1122. "os_version": "01020300",
  1123. "config_methods": "label push_button",
  1124. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo",
  1125. "friendly_name": "WPS Access Point",
  1126. "manufacturer_url": "http://www.example.com/",
  1127. "model_description": "Wireless Access Point",
  1128. "model_url": "http://www.example.com/model/",
  1129. "upc": "123456789012" })
  1130. def ssdp_send(msg, no_recv=False):
  1131. socket.setdefaulttimeout(1)
  1132. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
  1133. sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  1134. sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
  1135. sock.bind(("127.0.0.1", 0))
  1136. sock.sendto(msg, ("239.255.255.250", 1900))
  1137. if no_recv:
  1138. return None
  1139. return sock.recv(1000)
  1140. def ssdp_send_msearch(st):
  1141. msg = '\r\n'.join([
  1142. 'M-SEARCH * HTTP/1.1',
  1143. 'HOST: 239.255.255.250:1900',
  1144. 'MX: 1',
  1145. 'MAN: "ssdp:discover"',
  1146. 'ST: ' + st,
  1147. '', ''])
  1148. return ssdp_send(msg)
  1149. def test_ap_wps_ssdp_msearch(dev, apdev):
  1150. """WPS AP and SSDP M-SEARCH messages"""
  1151. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  1152. add_ssdp_ap(apdev[0]['ifname'], ap_uuid)
  1153. msg = '\r\n'.join([
  1154. 'M-SEARCH * HTTP/1.1',
  1155. 'Host: 239.255.255.250:1900',
  1156. 'Mx: 1',
  1157. 'Man: "ssdp:discover"',
  1158. 'St: urn:schemas-wifialliance-org:device:WFADevice:1',
  1159. '', ''])
  1160. ssdp_send(msg)
  1161. msg = '\r\n'.join([
  1162. 'M-SEARCH * HTTP/1.1',
  1163. 'host:\t239.255.255.250:1900\t\t\t\t \t\t',
  1164. 'mx: \t1\t\t ',
  1165. 'man: \t \t "ssdp:discover" ',
  1166. 'st: urn:schemas-wifialliance-org:device:WFADevice:1\t\t',
  1167. '', ''])
  1168. ssdp_send(msg)
  1169. ssdp_send_msearch("ssdp:all")
  1170. ssdp_send_msearch("upnp:rootdevice")
  1171. ssdp_send_msearch("uuid:" + ap_uuid)
  1172. ssdp_send_msearch("urn:schemas-wifialliance-org:service:WFAWLANConfig:1")
  1173. ssdp_send_msearch("urn:schemas-wifialliance-org:device:WFADevice:1");
  1174. msg = '\r\n'.join([
  1175. 'M-SEARCH * HTTP/1.1',
  1176. 'HOST:\t239.255.255.250:1900',
  1177. 'MAN: "ssdp:discover"',
  1178. 'MX: 130',
  1179. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1180. '', ''])
  1181. ssdp_send(msg, no_recv=True)
  1182. def test_ap_wps_ssdp_invalid_msearch(dev, apdev):
  1183. """WPS AP and invalid SSDP M-SEARCH messages"""
  1184. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  1185. add_ssdp_ap(apdev[0]['ifname'], ap_uuid)
  1186. socket.setdefaulttimeout(1)
  1187. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
  1188. sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  1189. sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
  1190. sock.bind(("127.0.0.1", 0))
  1191. logger.debug("Missing MX")
  1192. msg = '\r\n'.join([
  1193. 'M-SEARCH * HTTP/1.1',
  1194. 'HOST: 239.255.255.250:1900',
  1195. 'MAN: "ssdp:discover"',
  1196. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1197. '', ''])
  1198. sock.sendto(msg, ("239.255.255.250", 1900))
  1199. logger.debug("Negative MX")
  1200. msg = '\r\n'.join([
  1201. 'M-SEARCH * HTTP/1.1',
  1202. 'HOST: 239.255.255.250:1900',
  1203. 'MX: -1',
  1204. 'MAN: "ssdp:discover"',
  1205. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1206. '', ''])
  1207. sock.sendto(msg, ("239.255.255.250", 1900))
  1208. logger.debug("Invalid MX")
  1209. msg = '\r\n'.join([
  1210. 'M-SEARCH * HTTP/1.1',
  1211. 'HOST: 239.255.255.250:1900',
  1212. 'MX; 1',
  1213. 'MAN: "ssdp:discover"',
  1214. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1215. '', ''])
  1216. sock.sendto(msg, ("239.255.255.250", 1900))
  1217. logger.debug("Missing MAN")
  1218. msg = '\r\n'.join([
  1219. 'M-SEARCH * HTTP/1.1',
  1220. 'HOST: 239.255.255.250:1900',
  1221. 'MX: 1',
  1222. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1223. '', ''])
  1224. sock.sendto(msg, ("239.255.255.250", 1900))
  1225. logger.debug("Invalid MAN")
  1226. msg = '\r\n'.join([
  1227. 'M-SEARCH * HTTP/1.1',
  1228. 'HOST: 239.255.255.250:1900',
  1229. 'MX: 1',
  1230. 'MAN: foo',
  1231. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1232. '', ''])
  1233. sock.sendto(msg, ("239.255.255.250", 1900))
  1234. msg = '\r\n'.join([
  1235. 'M-SEARCH * HTTP/1.1',
  1236. 'HOST: 239.255.255.250:1900',
  1237. 'MX: 1',
  1238. 'MAN; "ssdp:discover"',
  1239. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1240. '', ''])
  1241. sock.sendto(msg, ("239.255.255.250", 1900))
  1242. logger.debug("Missing HOST")
  1243. msg = '\r\n'.join([
  1244. 'M-SEARCH * HTTP/1.1',
  1245. 'MAN: "ssdp:discover"',
  1246. 'MX: 1',
  1247. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1248. '', ''])
  1249. sock.sendto(msg, ("239.255.255.250", 1900))
  1250. logger.debug("Missing ST")
  1251. msg = '\r\n'.join([
  1252. 'M-SEARCH * HTTP/1.1',
  1253. 'HOST: 239.255.255.250:1900',
  1254. 'MAN: "ssdp:discover"',
  1255. 'MX: 1',
  1256. '', ''])
  1257. sock.sendto(msg, ("239.255.255.250", 1900))
  1258. logger.debug("Mismatching ST")
  1259. msg = '\r\n'.join([
  1260. 'M-SEARCH * HTTP/1.1',
  1261. 'HOST: 239.255.255.250:1900',
  1262. 'MAN: "ssdp:discover"',
  1263. 'MX: 1',
  1264. 'ST: uuid:16d5f8a9-4ee4-4f5e-81f9-cc6e2f47f42d',
  1265. '', ''])
  1266. sock.sendto(msg, ("239.255.255.250", 1900))
  1267. msg = '\r\n'.join([
  1268. 'M-SEARCH * HTTP/1.1',
  1269. 'HOST: 239.255.255.250:1900',
  1270. 'MAN: "ssdp:discover"',
  1271. 'MX: 1',
  1272. 'ST: foo:bar',
  1273. '', ''])
  1274. sock.sendto(msg, ("239.255.255.250", 1900))
  1275. msg = '\r\n'.join([
  1276. 'M-SEARCH * HTTP/1.1',
  1277. 'HOST: 239.255.255.250:1900',
  1278. 'MAN: "ssdp:discover"',
  1279. 'MX: 1',
  1280. 'ST: foobar',
  1281. '', ''])
  1282. sock.sendto(msg, ("239.255.255.250", 1900))
  1283. logger.debug("Invalid ST")
  1284. msg = '\r\n'.join([
  1285. 'M-SEARCH * HTTP/1.1',
  1286. 'HOST: 239.255.255.250:1900',
  1287. 'MAN: "ssdp:discover"',
  1288. 'MX: 1',
  1289. 'ST; urn:schemas-wifialliance-org:device:WFADevice:1',
  1290. '', ''])
  1291. sock.sendto(msg, ("239.255.255.250", 1900))
  1292. logger.debug("Invalid M-SEARCH")
  1293. msg = '\r\n'.join([
  1294. 'M+SEARCH * HTTP/1.1',
  1295. 'HOST: 239.255.255.250:1900',
  1296. 'MAN: "ssdp:discover"',
  1297. 'MX: 1',
  1298. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1299. '', ''])
  1300. sock.sendto(msg, ("239.255.255.250", 1900))
  1301. msg = '\r\n'.join([
  1302. 'M-SEARCH-* HTTP/1.1',
  1303. 'HOST: 239.255.255.250:1900',
  1304. 'MAN: "ssdp:discover"',
  1305. 'MX: 1',
  1306. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1307. '', ''])
  1308. sock.sendto(msg, ("239.255.255.250", 1900))
  1309. logger.debug("Invalid message format")
  1310. sock.sendto("NOTIFY * HTTP/1.1", ("239.255.255.250", 1900))
  1311. msg = '\r'.join([
  1312. 'M-SEARCH * HTTP/1.1',
  1313. 'HOST: 239.255.255.250:1900',
  1314. 'MAN: "ssdp:discover"',
  1315. 'MX: 1',
  1316. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1317. '', ''])
  1318. sock.sendto(msg, ("239.255.255.250", 1900))
  1319. try:
  1320. r = sock.recv(1000)
  1321. raise Exception("Unexpected M-SEARCH response: " + r)
  1322. except socket.timeout:
  1323. pass
  1324. logger.debug("Valid M-SEARCH")
  1325. msg = '\r\n'.join([
  1326. 'M-SEARCH * HTTP/1.1',
  1327. 'HOST: 239.255.255.250:1900',
  1328. 'MAN: "ssdp:discover"',
  1329. 'MX: 1',
  1330. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1331. '', ''])
  1332. sock.sendto(msg, ("239.255.255.250", 1900))
  1333. try:
  1334. r = sock.recv(1000)
  1335. pass
  1336. except socket.timeout:
  1337. raise Exception("No SSDP response")
  1338. def test_ap_wps_ssdp_burst(dev, apdev):
  1339. """WPS AP and SSDP burst"""
  1340. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  1341. add_ssdp_ap(apdev[0]['ifname'], ap_uuid)
  1342. msg = '\r\n'.join([
  1343. 'M-SEARCH * HTTP/1.1',
  1344. 'HOST: 239.255.255.250:1900',
  1345. 'MAN: "ssdp:discover"',
  1346. 'MX: 1',
  1347. 'ST: urn:schemas-wifialliance-org:device:WFADevice:1',
  1348. '', ''])
  1349. socket.setdefaulttimeout(1)
  1350. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
  1351. sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  1352. sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
  1353. sock.bind(("127.0.0.1", 0))
  1354. for i in range(0, 25):
  1355. sock.sendto(msg, ("239.255.255.250", 1900))
  1356. resp = 0
  1357. while True:
  1358. try:
  1359. r = sock.recv(1000)
  1360. if not r.startswith("HTTP/1.1 200 OK\r\n"):
  1361. raise Exception("Unexpected message: " + r)
  1362. resp += 1
  1363. except socket.timeout:
  1364. break
  1365. if resp < 20:
  1366. raise Exception("Too few SSDP responses")
  1367. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
  1368. sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  1369. sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
  1370. sock.bind(("127.0.0.1", 0))
  1371. for i in range(0, 25):
  1372. sock.sendto(msg, ("239.255.255.250", 1900))
  1373. while True:
  1374. try:
  1375. r = sock.recv(1000)
  1376. if ap_uuid in r:
  1377. break
  1378. except socket.timeout:
  1379. raise Exception("No SSDP response")
  1380. def ssdp_get_location(uuid):
  1381. res = ssdp_send_msearch("uuid:" + uuid)
  1382. location = None
  1383. for l in res.splitlines():
  1384. if l.lower().startswith("location:"):
  1385. location = l.split(':', 1)[1].strip()
  1386. break
  1387. if location is None:
  1388. raise Exception("No UPnP location found")
  1389. return location
  1390. def upnp_get_urls(location):
  1391. conn = urllib.urlopen(location)
  1392. tree = ET.parse(conn)
  1393. root = tree.getroot()
  1394. urn = '{urn:schemas-upnp-org:device-1-0}'
  1395. service = root.find("./" + urn + "device/" + urn + "serviceList/" + urn + "service")
  1396. res = {}
  1397. res['scpd_url'] = urlparse.urljoin(location, service.find(urn + 'SCPDURL').text)
  1398. res['control_url'] = urlparse.urljoin(location, service.find(urn + 'controlURL').text)
  1399. res['event_sub_url'] = urlparse.urljoin(location, service.find(urn + 'eventSubURL').text)
  1400. return res
  1401. def upnp_soap_action(conn, path, action, include_soap_action=True, soap_action_override=None):
  1402. soapns = 'http://schemas.xmlsoap.org/soap/envelope/'
  1403. wpsns = 'urn:schemas-wifialliance-org:service:WFAWLANConfig:1'
  1404. ET.register_namespace('soapenv', soapns)
  1405. ET.register_namespace('wfa', wpsns)
  1406. attrib = {}
  1407. attrib['{%s}encodingStyle' % soapns] = 'http://schemas.xmlsoap.org/soap/encoding/'
  1408. root = ET.Element("{%s}Envelope" % soapns, attrib=attrib)
  1409. body = ET.SubElement(root, "{%s}Body" % soapns)
  1410. act = ET.SubElement(body, "{%s}%s" % (wpsns, action))
  1411. tree = ET.ElementTree(root)
  1412. soap = StringIO.StringIO()
  1413. tree.write(soap, xml_declaration=True, encoding='utf-8')
  1414. headers = { "Content-type": 'text/xml; charset="utf-8"' }
  1415. if include_soap_action:
  1416. headers["SOAPAction"] = '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#%s"' % action
  1417. elif soap_action_override:
  1418. headers["SOAPAction"] = soap_action_override
  1419. conn.request("POST", path, soap.getvalue(), headers)
  1420. return conn.getresponse()
  1421. def test_ap_wps_upnp(dev, apdev):
  1422. """WPS AP and UPnP operations"""
  1423. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  1424. add_ssdp_ap(apdev[0]['ifname'], ap_uuid)
  1425. location = ssdp_get_location(ap_uuid)
  1426. urls = upnp_get_urls(location)
  1427. conn = urllib.urlopen(urls['scpd_url'])
  1428. scpd = conn.read()
  1429. conn = urllib.urlopen(urlparse.urljoin(location, "unknown.html"))
  1430. if conn.getcode() != 404:
  1431. raise Exception("Unexpected HTTP response to GET unknown URL")
  1432. url = urlparse.urlparse(location)
  1433. conn = httplib.HTTPConnection(url.netloc)
  1434. #conn.set_debuglevel(1)
  1435. headers = { "Content-type": 'text/xml; charset="utf-8"',
  1436. "SOAPAction": '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#GetDeviceInfo"' }
  1437. conn.request("POST", "hello", "\r\n\r\n", headers)
  1438. resp = conn.getresponse()
  1439. if resp.status != 404:
  1440. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1441. conn.request("UNKNOWN", "hello", "\r\n\r\n", headers)
  1442. resp = conn.getresponse()
  1443. if resp.status != 501:
  1444. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1445. headers = { "Content-type": 'text/xml; charset="utf-8"',
  1446. "SOAPAction": '"urn:some-unknown-action#GetDeviceInfo"' }
  1447. ctrlurl = urlparse.urlparse(urls['control_url'])
  1448. conn.request("POST", ctrlurl.path, "\r\n\r\n", headers)
  1449. resp = conn.getresponse()
  1450. if resp.status != 401:
  1451. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1452. logger.debug("GetDeviceInfo without SOAPAction header")
  1453. resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo",
  1454. include_soap_action=False)
  1455. if resp.status != 401:
  1456. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1457. logger.debug("GetDeviceInfo with invalid SOAPAction header")
  1458. for act in [ "foo",
  1459. "urn:schemas-wifialliance-org:service:WFAWLANConfig:1#GetDeviceInfo",
  1460. '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1"',
  1461. '"urn:schemas-wifialliance-org:service:WFAWLANConfig:123#GetDevice']:
  1462. resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo",
  1463. include_soap_action=False,
  1464. soap_action_override=act)
  1465. if resp.status != 401:
  1466. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1467. resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo")
  1468. if resp.status != 200:
  1469. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1470. dev = resp.read()
  1471. if "NewDeviceInfo" not in dev:
  1472. raise Exception("Unexpected GetDeviceInfo response")
  1473. logger.debug("PutMessage without required parameters")
  1474. resp = upnp_soap_action(conn, ctrlurl.path, "PutMessage")
  1475. if resp.status != 600:
  1476. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1477. logger.debug("PutWLANResponse without required parameters")
  1478. resp = upnp_soap_action(conn, ctrlurl.path, "PutWLANResponse")
  1479. if resp.status != 600:
  1480. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1481. logger.debug("SetSelectedRegistrar from unregistered ER")
  1482. resp = upnp_soap_action(conn, ctrlurl.path, "SetSelectedRegistrar")
  1483. if resp.status != 501:
  1484. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1485. logger.debug("Unknown action")
  1486. resp = upnp_soap_action(conn, ctrlurl.path, "Unknown")
  1487. if resp.status != 401:
  1488. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1489. def test_ap_wps_upnp_subscribe(dev, apdev):
  1490. """WPS AP and UPnP event subscription"""
  1491. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  1492. add_ssdp_ap(apdev[0]['ifname'], ap_uuid)
  1493. location = ssdp_get_location(ap_uuid)
  1494. urls = upnp_get_urls(location)
  1495. eventurl = urlparse.urlparse(urls['event_sub_url'])
  1496. url = urlparse.urlparse(location)
  1497. conn = httplib.HTTPConnection(url.netloc)
  1498. #conn.set_debuglevel(1)
  1499. headers = { "callback": '<http://127.0.0.1:12345/event>',
  1500. "timeout": "Second-1234" }
  1501. conn.request("SUBSCRIBE", "hello", "\r\n\r\n", headers)
  1502. resp = conn.getresponse()
  1503. if resp.status != 412:
  1504. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1505. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1506. resp = conn.getresponse()
  1507. if resp.status != 412:
  1508. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1509. headers = { "NT": "upnp:event",
  1510. "timeout": "Second-1234" }
  1511. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1512. resp = conn.getresponse()
  1513. if resp.status != 412:
  1514. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1515. headers = { "callback": '<http://127.0.0.1:12345/event>',
  1516. "NT": "upnp:foobar",
  1517. "timeout": "Second-1234" }
  1518. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1519. resp = conn.getresponse()
  1520. if resp.status != 400:
  1521. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1522. logger.debug("Valid subscription")
  1523. headers = { "callback": '<http://127.0.0.1:12345/event>',
  1524. "NT": "upnp:event",
  1525. "timeout": "Second-1234" }
  1526. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1527. resp = conn.getresponse()
  1528. if resp.status != 200:
  1529. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1530. sid = resp.getheader("sid")
  1531. logger.debug("Subscription SID " + sid)
  1532. logger.debug("Invalid re-subscription")
  1533. headers = { "NT": "upnp:event",
  1534. "sid": "123456734567854",
  1535. "timeout": "Second-1234" }
  1536. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1537. resp = conn.getresponse()
  1538. if resp.status != 400:
  1539. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1540. logger.debug("Invalid re-subscription")
  1541. headers = { "NT": "upnp:event",
  1542. "sid": "uuid:123456734567854",
  1543. "timeout": "Second-1234" }
  1544. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1545. resp = conn.getresponse()
  1546. if resp.status != 400:
  1547. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1548. logger.debug("Invalid re-subscription")
  1549. headers = { "callback": '<http://127.0.0.1:12345/event>',
  1550. "NT": "upnp:event",
  1551. "sid": sid,
  1552. "timeout": "Second-1234" }
  1553. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1554. resp = conn.getresponse()
  1555. if resp.status != 400:
  1556. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1557. logger.debug("SID mismatch in re-subscription")
  1558. headers = { "NT": "upnp:event",
  1559. "sid": "uuid:4c2bca79-1ff4-4e43-85d4-952a2b8a51fb",
  1560. "timeout": "Second-1234" }
  1561. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1562. resp = conn.getresponse()
  1563. if resp.status != 412:
  1564. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1565. logger.debug("Valid re-subscription")
  1566. headers = { "NT": "upnp:event",
  1567. "sid": sid,
  1568. "timeout": "Second-1234" }
  1569. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1570. resp = conn.getresponse()
  1571. if resp.status != 200:
  1572. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1573. sid2 = resp.getheader("sid")
  1574. logger.debug("Subscription SID " + sid2)
  1575. if sid != sid2:
  1576. raise Exception("Unexpected SID change")
  1577. logger.debug("Valid re-subscription")
  1578. headers = { "NT": "upnp:event",
  1579. "sid": "uuid: \t \t" + sid.split(':')[1],
  1580. "timeout": "Second-1234" }
  1581. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1582. resp = conn.getresponse()
  1583. if resp.status != 200:
  1584. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1585. logger.debug("Invalid unsubscription")
  1586. headers = { "sid": sid }
  1587. conn.request("UNSUBSCRIBE", "/hello", "\r\n\r\n", headers)
  1588. resp = conn.getresponse()
  1589. if resp.status != 412:
  1590. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1591. headers = { "foo": "bar" }
  1592. conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1593. resp = conn.getresponse()
  1594. if resp.status != 412:
  1595. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1596. logger.debug("Valid unsubscription")
  1597. headers = { "sid": sid }
  1598. conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1599. resp = conn.getresponse()
  1600. if resp.status != 200:
  1601. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1602. logger.debug("Unsubscription for not existing SID")
  1603. headers = { "sid": sid }
  1604. conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1605. resp = conn.getresponse()
  1606. if resp.status != 412:
  1607. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1608. logger.debug("Invalid unsubscription")
  1609. headers = { "sid": " \t \tfoo" }
  1610. conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1611. resp = conn.getresponse()
  1612. if resp.status != 400:
  1613. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1614. logger.debug("Invalid unsubscription")
  1615. headers = { "sid": "uuid:\t \tfoo" }
  1616. conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1617. resp = conn.getresponse()
  1618. if resp.status != 400:
  1619. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1620. logger.debug("Invalid unsubscription")
  1621. headers = { "NT": "upnp:event",
  1622. "sid": sid }
  1623. conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1624. resp = conn.getresponse()
  1625. if resp.status != 400:
  1626. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1627. headers = { "callback": '<http://127.0.0.1:12345/event>',
  1628. "sid": sid }
  1629. conn.request("UNSUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1630. resp = conn.getresponse()
  1631. if resp.status != 400:
  1632. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1633. logger.debug("Valid subscription with multiple callbacks")
  1634. 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>',
  1635. "NT": "upnp:event",
  1636. "timeout": "Second-1234" }
  1637. conn.request("SUBSCRIBE", eventurl.path, "\r\n\r\n", headers)
  1638. resp = conn.getresponse()
  1639. if resp.status != 200:
  1640. raise Exception("Unexpected HTTP response: %s" % resp.status)
  1641. sid = resp.getheader("sid")
  1642. logger.debug("Subscription SID " + sid)