test_ap_wps.py 93 KB

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