test_ap_wps.py 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  1. #!/usr/bin/python
  2. #
  3. # WPS tests
  4. # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi>
  5. #
  6. # This software may be distributed under the terms of the BSD license.
  7. # See README for more details.
  8. import time
  9. import subprocess
  10. import logging
  11. logger = logging.getLogger()
  12. import re
  13. import hwsim_utils
  14. import hostapd
  15. def test_ap_wps_init(dev, apdev):
  16. """Initial AP configuration with first WPS Enrollee"""
  17. ssid = "test-wps"
  18. hostapd.add_ap(apdev[0]['ifname'],
  19. { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
  20. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  21. logger.info("WPS provisioning step")
  22. hapd.request("WPS_PBC")
  23. if "PBC Status: Active" not in hapd.request("WPS_GET_STATUS"):
  24. raise Exception("PBC status not shown correctly")
  25. dev[0].dump_monitor()
  26. dev[0].request("WPS_PBC")
  27. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  28. if ev is None:
  29. raise Exception("Association with the AP timed out")
  30. status = dev[0].get_status()
  31. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  32. raise Exception("Not fully connected")
  33. if status['ssid'] != ssid:
  34. raise Exception("Unexpected SSID")
  35. if status['pairwise_cipher'] != 'CCMP':
  36. raise Exception("Unexpected encryption configuration")
  37. if status['key_mgmt'] != 'WPA2-PSK':
  38. raise Exception("Unexpected key_mgmt")
  39. status = hapd.request("WPS_GET_STATUS")
  40. if "PBC Status: Disabled" not in status:
  41. raise Exception("PBC status not shown correctly")
  42. if "Last WPS result: Success" not in status:
  43. raise Exception("Last WPS result not shown correctly")
  44. if "Peer Address: " + dev[0].p2p_interface_addr() not in status:
  45. raise Exception("Peer address not shown correctly")
  46. conf = hapd.request("GET_CONFIG")
  47. if "wps_state=configured" not in conf:
  48. raise Exception("AP not in WPS configured state")
  49. if "rsn_pairwise_cipher=CCMP TKIP" not in conf:
  50. raise Exception("Unexpected rsn_pairwise_cipher")
  51. if "wpa_pairwise_cipher=CCMP TKIP" not in conf:
  52. raise Exception("Unexpected wpa_pairwise_cipher")
  53. if "group_cipher=TKIP" not in conf:
  54. raise Exception("Unexpected group_cipher")
  55. def test_ap_wps_init_2ap_pbc(dev, apdev):
  56. """Initial two-radio AP configuration with first WPS PBC Enrollee"""
  57. ssid = "test-wps"
  58. params = { "ssid": ssid, "eap_server": "1", "wps_state": "1" }
  59. hostapd.add_ap(apdev[0]['ifname'], params)
  60. hostapd.add_ap(apdev[1]['ifname'], params)
  61. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  62. logger.info("WPS provisioning step")
  63. hapd.request("WPS_PBC")
  64. dev[0].scan(freq="2412")
  65. bss = dev[0].get_bss(apdev[0]['bssid'])
  66. if "[WPS-PBC]" not in bss['flags']:
  67. raise Exception("WPS-PBC flag missing from AP1")
  68. bss = dev[0].get_bss(apdev[1]['bssid'])
  69. if "[WPS-PBC]" not in bss['flags']:
  70. raise Exception("WPS-PBC flag missing from AP2")
  71. dev[0].dump_monitor()
  72. dev[0].request("WPS_PBC")
  73. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  74. if ev is None:
  75. raise Exception("Association with the AP timed out")
  76. dev[1].scan(freq="2412")
  77. bss = dev[1].get_bss(apdev[0]['bssid'])
  78. if "[WPS-PBC]" in bss['flags']:
  79. raise Exception("WPS-PBC flag not cleared from AP1")
  80. bss = dev[1].get_bss(apdev[1]['bssid'])
  81. if "[WPS-PBC]" in bss['flags']:
  82. raise Exception("WPS-PBC flag bit ckeared from AP2")
  83. def test_ap_wps_init_2ap_pin(dev, apdev):
  84. """Initial two-radio AP configuration with first WPS PIN Enrollee"""
  85. ssid = "test-wps"
  86. params = { "ssid": ssid, "eap_server": "1", "wps_state": "1" }
  87. hostapd.add_ap(apdev[0]['ifname'], params)
  88. hostapd.add_ap(apdev[1]['ifname'], params)
  89. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  90. logger.info("WPS provisioning step")
  91. pin = dev[0].wps_read_pin()
  92. hapd.request("WPS_PIN any " + pin)
  93. dev[0].scan(freq="2412")
  94. bss = dev[0].get_bss(apdev[0]['bssid'])
  95. if "[WPS-AUTH]" not in bss['flags']:
  96. raise Exception("WPS-AUTH flag missing from AP1")
  97. bss = dev[0].get_bss(apdev[1]['bssid'])
  98. if "[WPS-AUTH]" not in bss['flags']:
  99. raise Exception("WPS-AUTH flag missing from AP2")
  100. dev[0].dump_monitor()
  101. dev[0].request("WPS_PIN any " + pin)
  102. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  103. if ev is None:
  104. raise Exception("Association with the AP timed out")
  105. dev[1].scan(freq="2412")
  106. bss = dev[1].get_bss(apdev[0]['bssid'])
  107. if "[WPS-AUTH]" in bss['flags']:
  108. raise Exception("WPS-AUTH flag not cleared from AP1")
  109. bss = dev[1].get_bss(apdev[1]['bssid'])
  110. if "[WPS-AUTH]" in bss['flags']:
  111. raise Exception("WPS-AUTH flag bit ckeared from AP2")
  112. def test_ap_wps_init_through_wps_config(dev, apdev):
  113. """Initial AP configuration using wps_config command"""
  114. ssid = "test-wps-init-config"
  115. hostapd.add_ap(apdev[0]['ifname'],
  116. { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
  117. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  118. if "FAIL" in hapd.request("WPS_CONFIG " + ssid.encode("hex") + " WPA2PSK CCMP " + "12345678".encode("hex")):
  119. raise Exception("WPS_CONFIG command failed")
  120. dev[0].connect(ssid, psk="12345678", scan_freq="2412", proto="WPA2",
  121. pairwise="CCMP", group="CCMP")
  122. def test_ap_wps_conf(dev, apdev):
  123. """WPS PBC provisioning with configured AP"""
  124. ssid = "test-wps-conf"
  125. hostapd.add_ap(apdev[0]['ifname'],
  126. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  127. "wpa_passphrase": "12345678", "wpa": "2",
  128. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  129. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  130. logger.info("WPS provisioning step")
  131. hapd.request("WPS_PBC")
  132. dev[0].dump_monitor()
  133. dev[0].request("WPS_PBC")
  134. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  135. if ev is None:
  136. raise Exception("Association with the AP timed out")
  137. status = dev[0].get_status()
  138. if status['wpa_state'] != 'COMPLETED':
  139. raise Exception("Not fully connected")
  140. if status['bssid'] != apdev[0]['bssid']:
  141. raise Exception("Unexpected BSSID")
  142. if status['ssid'] != ssid:
  143. raise Exception("Unexpected SSID")
  144. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  145. raise Exception("Unexpected encryption configuration")
  146. if status['key_mgmt'] != 'WPA2-PSK':
  147. raise Exception("Unexpected key_mgmt")
  148. sta = hapd.get_sta(dev[0].p2p_interface_addr())
  149. if 'wpsDeviceName' not in sta or sta['wpsDeviceName'] != "Device A":
  150. raise Exception("Device name not available in STA command")
  151. def test_ap_wps_twice(dev, apdev):
  152. """WPS provisioning with twice to change passphrase"""
  153. ssid = "test-wps-twice"
  154. params = { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  155. "wpa_passphrase": "12345678", "wpa": "2",
  156. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }
  157. hostapd.add_ap(apdev[0]['ifname'], params)
  158. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  159. logger.info("WPS provisioning step")
  160. hapd.request("WPS_PBC")
  161. dev[0].dump_monitor()
  162. dev[0].request("WPS_PBC")
  163. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  164. if ev is None:
  165. raise Exception("Association with the AP timed out")
  166. dev[0].request("DISCONNECT")
  167. logger.info("Restart AP with different passphrase and re-run WPS")
  168. hapd_global = hostapd.HostapdGlobal()
  169. hapd_global.remove(apdev[0]['ifname'])
  170. params['wpa_passphrase'] = 'another passphrase'
  171. hostapd.add_ap(apdev[0]['ifname'], params)
  172. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  173. logger.info("WPS provisioning step")
  174. hapd.request("WPS_PBC")
  175. dev[0].dump_monitor()
  176. dev[0].request("WPS_PBC")
  177. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  178. if ev is None:
  179. raise Exception("Association with the AP timed out")
  180. networks = dev[0].list_networks()
  181. if len(networks) > 1:
  182. raise Exception("Unexpected duplicated network block present")
  183. def test_ap_wps_incorrect_pin(dev, apdev):
  184. """WPS PIN provisioning with incorrect PIN"""
  185. ssid = "test-wps-incorrect-pin"
  186. hostapd.add_ap(apdev[0]['ifname'],
  187. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  188. "wpa_passphrase": "12345678", "wpa": "2",
  189. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  190. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  191. logger.info("WPS provisioning attempt 1")
  192. hapd.request("WPS_PIN any 12345670")
  193. dev[0].dump_monitor()
  194. dev[0].request("WPS_PIN any 55554444")
  195. ev = dev[0].wait_event(["WPS-FAIL"], timeout=30)
  196. if ev is None:
  197. raise Exception("WPS operation timed out")
  198. if "config_error=18" not in ev:
  199. raise Exception("Incorrect config_error reported")
  200. if "msg=8" not in ev:
  201. raise Exception("PIN error detected on incorrect message")
  202. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
  203. if ev is None:
  204. raise Exception("Timeout on disconnection event")
  205. dev[0].request("WPS_CANCEL")
  206. # if a scan was in progress, wait for it to complete before trying WPS again
  207. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
  208. status = hapd.request("WPS_GET_STATUS")
  209. if "Last WPS result: Failed" not in status:
  210. raise Exception("WPS failure result not shown correctly")
  211. logger.info("WPS provisioning attempt 2")
  212. hapd.request("WPS_PIN any 12345670")
  213. dev[0].dump_monitor()
  214. dev[0].request("WPS_PIN any 12344444")
  215. ev = dev[0].wait_event(["WPS-FAIL"], timeout=30)
  216. if ev is None:
  217. raise Exception("WPS operation timed out")
  218. if "config_error=18" not in ev:
  219. raise Exception("Incorrect config_error reported")
  220. if "msg=10" not in ev:
  221. raise Exception("PIN error detected on incorrect message")
  222. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
  223. if ev is None:
  224. raise Exception("Timeout on disconnection event")
  225. def test_ap_wps_conf_pin(dev, apdev):
  226. """WPS PIN provisioning with configured AP"""
  227. ssid = "test-wps-conf-pin"
  228. hostapd.add_ap(apdev[0]['ifname'],
  229. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  230. "wpa_passphrase": "12345678", "wpa": "2",
  231. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  232. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  233. logger.info("WPS provisioning step")
  234. pin = dev[0].wps_read_pin()
  235. hapd.request("WPS_PIN any " + pin)
  236. dev[0].dump_monitor()
  237. dev[0].request("WPS_PIN any " + pin)
  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. status = dev[0].get_status()
  242. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  243. raise Exception("Not fully connected")
  244. if status['ssid'] != ssid:
  245. raise Exception("Unexpected SSID")
  246. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  247. raise Exception("Unexpected encryption configuration")
  248. if status['key_mgmt'] != 'WPA2-PSK':
  249. raise Exception("Unexpected key_mgmt")
  250. dev[1].scan(freq="2412")
  251. bss = dev[1].get_bss(apdev[0]['bssid'])
  252. if "[WPS-AUTH]" in bss['flags']:
  253. raise Exception("WPS-AUTH flag not cleared")
  254. logger.info("Try to connect from another station using the same PIN")
  255. dev[1].request("WPS_PIN any " + pin)
  256. ev = dev[1].wait_event(["WPS-M2D","CTRL-EVENT-CONNECTED"], timeout=30)
  257. if ev is None:
  258. raise Exception("Operation timed out")
  259. if "WPS-M2D" not in ev:
  260. raise Exception("Unexpected WPS operation started")
  261. def test_ap_wps_conf_pin_2sta(dev, apdev):
  262. """Two stations trying to use WPS PIN at the same time"""
  263. ssid = "test-wps-conf-pin2"
  264. hostapd.add_ap(apdev[0]['ifname'],
  265. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  266. "wpa_passphrase": "12345678", "wpa": "2",
  267. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  268. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  269. logger.info("WPS provisioning step")
  270. pin = "12345670"
  271. pin2 = "55554444"
  272. hapd.request("WPS_PIN " + dev[0].get_status_field("uuid") + " " + pin)
  273. hapd.request("WPS_PIN " + dev[1].get_status_field("uuid") + " " + pin)
  274. dev[0].dump_monitor()
  275. dev[1].dump_monitor()
  276. dev[0].request("WPS_PIN any " + pin)
  277. dev[1].request("WPS_PIN any " + pin)
  278. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  279. if ev is None:
  280. raise Exception("Association with the AP timed out")
  281. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  282. if ev is None:
  283. raise Exception("Association with the AP timed out")
  284. def test_ap_wps_reg_connect(dev, apdev):
  285. """WPS registrar using AP PIN to connect"""
  286. ssid = "test-wps-reg-ap-pin"
  287. appin = "12345670"
  288. hostapd.add_ap(apdev[0]['ifname'],
  289. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  290. "wpa_passphrase": "12345678", "wpa": "2",
  291. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  292. "ap_pin": appin})
  293. logger.info("WPS provisioning step")
  294. dev[0].dump_monitor()
  295. dev[0].wps_reg(apdev[0]['bssid'], appin)
  296. status = dev[0].get_status()
  297. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  298. raise Exception("Not fully connected")
  299. if status['ssid'] != ssid:
  300. raise Exception("Unexpected SSID")
  301. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  302. raise Exception("Unexpected encryption configuration")
  303. if status['key_mgmt'] != 'WPA2-PSK':
  304. raise Exception("Unexpected key_mgmt")
  305. def check_wps_reg_failure(dev, ap, appin):
  306. dev.request("WPS_REG " + ap['bssid'] + " " + appin)
  307. ev = dev.wait_event(["WPS-SUCCESS", "WPS-FAIL"], timeout=15)
  308. if ev is None:
  309. raise Exception("WPS operation timed out")
  310. if "WPS-SUCCESS" in ev:
  311. raise Exception("WPS operation succeeded unexpectedly")
  312. if "config_error=15" not in ev:
  313. raise Exception("WPS setup locked state was not reported correctly")
  314. def test_ap_wps_random_ap_pin(dev, apdev):
  315. """WPS registrar using random AP PIN"""
  316. ssid = "test-wps-reg-random-ap-pin"
  317. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  318. hostapd.add_ap(apdev[0]['ifname'],
  319. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  320. "wpa_passphrase": "12345678", "wpa": "2",
  321. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  322. "device_name": "Wireless AP", "manufacturer": "Company",
  323. "model_name": "WAP", "model_number": "123",
  324. "serial_number": "12345", "device_type": "6-0050F204-1",
  325. "os_version": "01020300",
  326. "config_methods": "label push_button",
  327. "uuid": ap_uuid, "upnp_iface": "lo" })
  328. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  329. appin = hapd.request("WPS_AP_PIN random")
  330. if "FAIL" in appin:
  331. raise Exception("Could not generate random AP PIN")
  332. if appin not in hapd.request("WPS_AP_PIN get"):
  333. raise Exception("Could not fetch current AP PIN")
  334. logger.info("WPS provisioning step")
  335. dev[0].wps_reg(apdev[0]['bssid'], appin)
  336. hapd.request("WPS_AP_PIN disable")
  337. logger.info("WPS provisioning step with AP PIN disabled")
  338. check_wps_reg_failure(dev[1], apdev[0], appin)
  339. logger.info("WPS provisioning step with AP PIN reset")
  340. appin = "12345670"
  341. hapd.request("WPS_AP_PIN set " + appin)
  342. dev[1].wps_reg(apdev[0]['bssid'], appin)
  343. dev[0].request("REMOVE_NETWORK all")
  344. dev[1].request("REMOVE_NETWORK all")
  345. dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
  346. dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
  347. logger.info("WPS provisioning step after AP PIN timeout")
  348. hapd.request("WPS_AP_PIN disable")
  349. appin = hapd.request("WPS_AP_PIN random 1")
  350. time.sleep(1.1)
  351. if "FAIL" not in hapd.request("WPS_AP_PIN get"):
  352. raise Exception("AP PIN unexpectedly still enabled")
  353. check_wps_reg_failure(dev[0], apdev[0], appin)
  354. logger.info("WPS provisioning step after AP PIN timeout(2)")
  355. hapd.request("WPS_AP_PIN disable")
  356. appin = "12345670"
  357. hapd.request("WPS_AP_PIN set " + appin + " 1")
  358. time.sleep(1.1)
  359. if "FAIL" not in hapd.request("WPS_AP_PIN get"):
  360. raise Exception("AP PIN unexpectedly still enabled")
  361. check_wps_reg_failure(dev[1], apdev[0], appin)
  362. def test_ap_wps_reg_config(dev, apdev):
  363. """WPS registrar configuring and AP using AP PIN"""
  364. ssid = "test-wps-init-ap-pin"
  365. appin = "12345670"
  366. hostapd.add_ap(apdev[0]['ifname'],
  367. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  368. "ap_pin": appin})
  369. logger.info("WPS configuration step")
  370. dev[0].dump_monitor()
  371. new_ssid = "wps-new-ssid"
  372. new_passphrase = "1234567890"
  373. dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPA2PSK", "CCMP",
  374. new_passphrase)
  375. status = dev[0].get_status()
  376. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  377. raise Exception("Not fully connected")
  378. if status['ssid'] != new_ssid:
  379. raise Exception("Unexpected SSID")
  380. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  381. raise Exception("Unexpected encryption configuration")
  382. if status['key_mgmt'] != 'WPA2-PSK':
  383. raise Exception("Unexpected key_mgmt")
  384. def test_ap_wps_reg_config_tkip(dev, apdev):
  385. """WPS registrar configuring AP to use TKIP and AP upgrading to TKIP+CCMP"""
  386. ssid = "test-wps-init-ap"
  387. appin = "12345670"
  388. hostapd.add_ap(apdev[0]['ifname'],
  389. { "ssid": ssid, "eap_server": "1", "wps_state": "1",
  390. "ap_pin": appin})
  391. logger.info("WPS configuration step")
  392. dev[0].request("SET wps_version_number 0x10")
  393. dev[0].dump_monitor()
  394. new_ssid = "wps-new-ssid-with-tkip"
  395. new_passphrase = "1234567890"
  396. dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPAPSK", "TKIP",
  397. new_passphrase)
  398. logger.info("Re-connect to verify WPA2 mixed mode")
  399. dev[0].request("DISCONNECT")
  400. id = 0
  401. dev[0].set_network(id, "pairwise", "CCMP")
  402. dev[0].set_network(id, "proto", "RSN")
  403. dev[0].connect_network(id)
  404. status = dev[0].get_status()
  405. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  406. raise Exception("Not fully connected")
  407. if status['ssid'] != new_ssid:
  408. raise Exception("Unexpected SSID")
  409. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP':
  410. raise Exception("Unexpected encryption configuration")
  411. if status['key_mgmt'] != 'WPA2-PSK':
  412. raise Exception("Unexpected key_mgmt")
  413. def test_ap_wps_setup_locked(dev, apdev):
  414. """WPS registrar locking up AP setup on AP PIN failures"""
  415. ssid = "test-wps-incorrect-ap-pin"
  416. appin = "12345670"
  417. hostapd.add_ap(apdev[0]['ifname'],
  418. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  419. "wpa_passphrase": "12345678", "wpa": "2",
  420. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  421. "ap_pin": appin})
  422. new_ssid = "wps-new-ssid-test"
  423. new_passphrase = "1234567890"
  424. ap_setup_locked=False
  425. for pin in ["55554444", "1234", "12345678", "00000000", "11111111"]:
  426. dev[0].dump_monitor()
  427. logger.info("Try incorrect AP PIN - attempt " + pin)
  428. dev[0].wps_reg(apdev[0]['bssid'], pin, new_ssid, "WPA2PSK",
  429. "CCMP", new_passphrase, no_wait=True)
  430. ev = dev[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"])
  431. if ev is None:
  432. raise Exception("Timeout on receiving WPS operation failure event")
  433. if "CTRL-EVENT-CONNECTED" in ev:
  434. raise Exception("Unexpected connection")
  435. if "config_error=15" in ev:
  436. logger.info("AP Setup Locked")
  437. ap_setup_locked=True
  438. elif "config_error=18" not in ev:
  439. raise Exception("config_error=18 not reported")
  440. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
  441. if ev is None:
  442. raise Exception("Timeout on disconnection event")
  443. time.sleep(0.1)
  444. if not ap_setup_locked:
  445. raise Exception("AP setup was not locked")
  446. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  447. status = hapd.request("WPS_GET_STATUS")
  448. if "Last WPS result: Failed" not in status:
  449. raise Exception("WPS failure result not shown correctly")
  450. if "Peer Address: " + dev[0].p2p_interface_addr() not in status:
  451. raise Exception("Peer address not shown correctly")
  452. time.sleep(0.5)
  453. dev[0].dump_monitor()
  454. logger.info("WPS provisioning step")
  455. pin = dev[0].wps_read_pin()
  456. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  457. hapd.request("WPS_PIN any " + pin)
  458. dev[0].request("WPS_PIN any " + pin)
  459. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=30)
  460. if ev is None:
  461. raise Exception("WPS success was not reported")
  462. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  463. if ev is None:
  464. raise Exception("Association with the AP timed out")
  465. def test_ap_wps_pbc_overlap_2ap(dev, apdev):
  466. """WPS PBC session overlap with two active APs"""
  467. hostapd.add_ap(apdev[0]['ifname'],
  468. { "ssid": "wps1", "eap_server": "1", "wps_state": "2",
  469. "wpa_passphrase": "12345678", "wpa": "2",
  470. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  471. "wps_independent": "1"})
  472. hostapd.add_ap(apdev[1]['ifname'],
  473. { "ssid": "wps2", "eap_server": "1", "wps_state": "2",
  474. "wpa_passphrase": "123456789", "wpa": "2",
  475. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  476. "wps_independent": "1"})
  477. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  478. hapd.request("WPS_PBC")
  479. hapd2 = hostapd.Hostapd(apdev[1]['ifname'])
  480. hapd2.request("WPS_PBC")
  481. logger.info("WPS provisioning step")
  482. dev[0].dump_monitor()
  483. dev[0].request("WPS_PBC")
  484. ev = dev[0].wait_event(["WPS-OVERLAP-DETECTED"], timeout=15)
  485. if ev is None:
  486. raise Exception("PBC session overlap not detected")
  487. def test_ap_wps_pbc_overlap_2sta(dev, apdev):
  488. """WPS PBC session overlap with two active STAs"""
  489. ssid = "test-wps-pbc-overlap"
  490. hostapd.add_ap(apdev[0]['ifname'],
  491. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  492. "wpa_passphrase": "12345678", "wpa": "2",
  493. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  494. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  495. logger.info("WPS provisioning step")
  496. hapd.request("WPS_PBC")
  497. dev[0].dump_monitor()
  498. dev[1].dump_monitor()
  499. dev[0].request("WPS_PBC")
  500. dev[1].request("WPS_PBC")
  501. ev = dev[0].wait_event(["WPS-M2D"], timeout=15)
  502. if ev is None:
  503. raise Exception("PBC session overlap not detected (dev0)")
  504. if "config_error=12" not in ev:
  505. raise Exception("PBC session overlap not correctly reported (dev0)")
  506. ev = dev[1].wait_event(["WPS-M2D"], timeout=15)
  507. if ev is None:
  508. raise Exception("PBC session overlap not detected (dev1)")
  509. if "config_error=12" not in ev:
  510. raise Exception("PBC session overlap not correctly reported (dev1)")
  511. def test_ap_wps_cancel(dev, apdev):
  512. """WPS AP cancelling enabled config method"""
  513. ssid = "test-wps-ap-cancel"
  514. hostapd.add_ap(apdev[0]['ifname'],
  515. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  516. "wpa_passphrase": "12345678", "wpa": "2",
  517. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
  518. bssid = apdev[0]['bssid']
  519. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  520. logger.info("Verify PBC enable/cancel")
  521. hapd.request("WPS_PBC")
  522. dev[0].scan(freq="2412")
  523. bss = dev[0].get_bss(apdev[0]['bssid'])
  524. if "[WPS-PBC]" not in bss['flags']:
  525. raise Exception("WPS-PBC flag missing")
  526. if "FAIL" in hapd.request("WPS_CANCEL"):
  527. raise Exception("WPS_CANCEL failed")
  528. dev[0].scan(freq="2412")
  529. bss = dev[0].get_bss(apdev[0]['bssid'])
  530. if "[WPS-PBC]" in bss['flags']:
  531. raise Exception("WPS-PBC flag not cleared")
  532. logger.info("Verify PIN enable/cancel")
  533. hapd.request("WPS_PIN any 12345670")
  534. dev[0].scan(freq="2412")
  535. bss = dev[0].get_bss(apdev[0]['bssid'])
  536. if "[WPS-AUTH]" not in bss['flags']:
  537. raise Exception("WPS-AUTH flag missing")
  538. if "FAIL" in hapd.request("WPS_CANCEL"):
  539. raise Exception("WPS_CANCEL failed")
  540. dev[0].scan(freq="2412")
  541. bss = dev[0].get_bss(apdev[0]['bssid'])
  542. if "[WPS-AUTH]" in bss['flags']:
  543. raise Exception("WPS-AUTH flag not cleared")
  544. def test_ap_wps_er_add_enrollee(dev, apdev):
  545. """WPS ER configuring AP and adding a new enrollee using PIN"""
  546. ssid = "wps-er-add-enrollee"
  547. ap_pin = "12345670"
  548. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  549. hostapd.add_ap(apdev[0]['ifname'],
  550. { "ssid": ssid, "eap_server": "1", "wps_state": "1",
  551. "device_name": "Wireless AP", "manufacturer": "Company",
  552. "model_name": "WAP", "model_number": "123",
  553. "serial_number": "12345", "device_type": "6-0050F204-1",
  554. "os_version": "01020300",
  555. "config_methods": "label push_button",
  556. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
  557. logger.info("WPS configuration step")
  558. new_passphrase = "1234567890"
  559. dev[0].dump_monitor()
  560. dev[0].wps_reg(apdev[0]['bssid'], ap_pin, ssid, "WPA2PSK", "CCMP",
  561. new_passphrase)
  562. status = dev[0].get_status()
  563. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  564. raise Exception("Not fully connected")
  565. if status['ssid'] != ssid:
  566. raise Exception("Unexpected SSID")
  567. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  568. raise Exception("Unexpected encryption configuration")
  569. if status['key_mgmt'] != 'WPA2-PSK':
  570. raise Exception("Unexpected key_mgmt")
  571. logger.info("Start ER")
  572. dev[0].request("WPS_ER_START ifname=lo")
  573. ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
  574. if ev is None:
  575. raise Exception("AP discovery timed out")
  576. if ap_uuid not in ev:
  577. raise Exception("Expected AP UUID not found")
  578. logger.info("Learn AP configuration through UPnP")
  579. dev[0].dump_monitor()
  580. dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin)
  581. ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15)
  582. if ev is None:
  583. raise Exception("AP learn timed out")
  584. if ap_uuid not in ev:
  585. raise Exception("Expected AP UUID not in settings")
  586. if "ssid=" + ssid not in ev:
  587. raise Exception("Expected SSID not in settings")
  588. if "key=" + new_passphrase not in ev:
  589. raise Exception("Expected passphrase not in settings")
  590. logger.info("Add Enrollee using ER")
  591. pin = dev[1].wps_read_pin()
  592. dev[0].dump_monitor()
  593. dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr())
  594. dev[1].dump_monitor()
  595. dev[1].request("WPS_PIN any " + pin)
  596. ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=30)
  597. if ev is None:
  598. raise Exception("Enrollee did not report success")
  599. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  600. if ev is None:
  601. raise Exception("Association with the AP timed out")
  602. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
  603. if ev is None:
  604. raise Exception("WPS ER did not report success")
  605. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  606. logger.info("Verify registrar selection behavior")
  607. dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr())
  608. dev[1].request("DISCONNECT")
  609. dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
  610. dev[1].scan(freq="2412")
  611. bss = dev[1].get_bss(apdev[0]['bssid'])
  612. if "[WPS-AUTH]" not in bss['flags']:
  613. raise Exception("WPS-AUTH flag missing")
  614. logger.info("Stop ER")
  615. dev[0].dump_monitor()
  616. dev[0].request("WPS_ER_STOP")
  617. ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"])
  618. if ev is None:
  619. raise Exception("WPS ER unsubscription timed out")
  620. # It takes some time for the UPnP UNSUBSCRIBE command to go through, so wait
  621. # a bit before verifying that the scan results have change.
  622. time.sleep(0.2)
  623. dev[1].scan(freq="2412")
  624. bss = dev[1].get_bss(apdev[0]['bssid'])
  625. if "[WPS-AUTH]" in bss['flags']:
  626. raise Exception("WPS-AUTH flag not removed")
  627. def test_ap_wps_er_add_enrollee_pbc(dev, apdev):
  628. """WPS ER connected to AP and adding a new enrollee using PBC"""
  629. ssid = "wps-er-add-enrollee-pbc"
  630. ap_pin = "12345670"
  631. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  632. hostapd.add_ap(apdev[0]['ifname'],
  633. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  634. "wpa_passphrase": "12345678", "wpa": "2",
  635. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  636. "device_name": "Wireless AP", "manufacturer": "Company",
  637. "model_name": "WAP", "model_number": "123",
  638. "serial_number": "12345", "device_type": "6-0050F204-1",
  639. "os_version": "01020300",
  640. "config_methods": "label push_button",
  641. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
  642. logger.info("Learn AP configuration")
  643. dev[0].dump_monitor()
  644. dev[0].wps_reg(apdev[0]['bssid'], ap_pin)
  645. status = dev[0].get_status()
  646. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  647. raise Exception("Not fully connected")
  648. logger.info("Start ER")
  649. dev[0].request("WPS_ER_START ifname=lo")
  650. ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
  651. if ev is None:
  652. raise Exception("AP discovery timed out")
  653. if ap_uuid not in ev:
  654. raise Exception("Expected AP UUID not found")
  655. logger.info("Use learned network configuration on ER")
  656. dev[0].request("WPS_ER_SET_CONFIG " + ap_uuid + " 0")
  657. logger.info("Add Enrollee using ER and PBC")
  658. dev[0].dump_monitor()
  659. enrollee = dev[1].p2p_interface_addr()
  660. dev[1].dump_monitor()
  661. dev[1].request("WPS_PBC")
  662. for i in range(0, 2):
  663. ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=15)
  664. if ev is None:
  665. raise Exception("Enrollee discovery timed out")
  666. if enrollee in ev:
  667. break
  668. if i == 1:
  669. raise Exception("Expected Enrollee not found")
  670. dev[0].request("WPS_ER_PBC " + enrollee)
  671. ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=15)
  672. if ev is None:
  673. raise Exception("Enrollee did not report success")
  674. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  675. if ev is None:
  676. raise Exception("Association with the AP timed out")
  677. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
  678. if ev is None:
  679. raise Exception("WPS ER did not report success")
  680. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  681. # verify BSSID selection of the AP instead of UUID
  682. if "FAIL" in dev[0].request("WPS_ER_SET_CONFIG " + apdev[0]['bssid'] + " 0"):
  683. raise Exception("Could not select AP based on BSSID")
  684. def test_ap_wps_er_config_ap(dev, apdev):
  685. """WPS ER configuring AP over UPnP"""
  686. ssid = "wps-er-ap-config"
  687. ap_pin = "12345670"
  688. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  689. hostapd.add_ap(apdev[0]['ifname'],
  690. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  691. "wpa_passphrase": "12345678", "wpa": "2",
  692. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  693. "device_name": "Wireless AP", "manufacturer": "Company",
  694. "model_name": "WAP", "model_number": "123",
  695. "serial_number": "12345", "device_type": "6-0050F204-1",
  696. "os_version": "01020300",
  697. "config_methods": "label push_button",
  698. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
  699. logger.info("Connect ER to the AP")
  700. dev[0].connect(ssid, psk="12345678", scan_freq="2412")
  701. logger.info("WPS configuration step")
  702. dev[0].request("WPS_ER_START ifname=lo")
  703. ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
  704. if ev is None:
  705. raise Exception("AP discovery timed out")
  706. if ap_uuid not in ev:
  707. raise Exception("Expected AP UUID not found")
  708. new_passphrase = "1234567890"
  709. dev[0].request("WPS_ER_CONFIG " + apdev[0]['bssid'] + " " + ap_pin + " " +
  710. ssid.encode("hex") + " WPA2PSK CCMP " +
  711. new_passphrase.encode("hex"))
  712. ev = dev[0].wait_event(["WPS-SUCCESS"])
  713. if ev is None:
  714. raise Exception("WPS ER configuration operation timed out")
  715. dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
  716. dev[0].connect(ssid, psk="1234567890", scan_freq="2412")
  717. def test_ap_wps_fragmentation(dev, apdev):
  718. """WPS with fragmentation in EAP-WSC and mixed mode WPA+WPA2"""
  719. ssid = "test-wps-fragmentation"
  720. hostapd.add_ap(apdev[0]['ifname'],
  721. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  722. "wpa_passphrase": "12345678", "wpa": "3",
  723. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  724. "wpa_pairwise": "TKIP",
  725. "fragment_size": "50" })
  726. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  727. logger.info("WPS provisioning step")
  728. hapd.request("WPS_PBC")
  729. dev[0].dump_monitor()
  730. dev[0].request("SET wps_fragment_size 50")
  731. dev[0].request("WPS_PBC")
  732. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  733. if ev is None:
  734. raise Exception("Association with the AP timed out")
  735. status = dev[0].get_status()
  736. if status['wpa_state'] != 'COMPLETED':
  737. raise Exception("Not fully connected")
  738. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP':
  739. raise Exception("Unexpected encryption configuration")
  740. if status['key_mgmt'] != 'WPA2-PSK':
  741. raise Exception("Unexpected key_mgmt")
  742. def test_ap_wps_new_version_sta(dev, apdev):
  743. """WPS compatibility with new version number on the station"""
  744. ssid = "test-wps-ver"
  745. hostapd.add_ap(apdev[0]['ifname'],
  746. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  747. "wpa_passphrase": "12345678", "wpa": "2",
  748. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
  749. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  750. logger.info("WPS provisioning step")
  751. hapd.request("WPS_PBC")
  752. dev[0].dump_monitor()
  753. dev[0].request("SET wps_version_number 0x43")
  754. dev[0].request("SET wps_vendor_ext_m1 000137100100020001")
  755. dev[0].request("WPS_PBC")
  756. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  757. if ev is None:
  758. raise Exception("Association with the AP timed out")
  759. def test_ap_wps_new_version_ap(dev, apdev):
  760. """WPS compatibility with new version number on the AP"""
  761. ssid = "test-wps-ver"
  762. hostapd.add_ap(apdev[0]['ifname'],
  763. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  764. "wpa_passphrase": "12345678", "wpa": "2",
  765. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
  766. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  767. logger.info("WPS provisioning step")
  768. if "FAIL" in hapd.request("SET wps_version_number 0x43"):
  769. raise Exception("Failed to enable test functionality")
  770. hapd.request("WPS_PBC")
  771. dev[0].dump_monitor()
  772. dev[0].request("WPS_PBC")
  773. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  774. hapd.request("SET wps_version_number 0x20")
  775. if ev is None:
  776. raise Exception("Association with the AP timed out")
  777. def test_ap_wps_check_pin(dev, apdev):
  778. """Verify PIN checking through control interface"""
  779. hostapd.add_ap(apdev[0]['ifname'],
  780. { "ssid": "wps", "eap_server": "1", "wps_state": "2",
  781. "wpa_passphrase": "12345678", "wpa": "2",
  782. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
  783. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  784. for t in [ ("12345670", "12345670"),
  785. ("12345678", "FAIL-CHECKSUM"),
  786. ("1234-5670", "12345670"),
  787. ("1234 5670", "12345670"),
  788. ("1-2.3:4 5670", "12345670") ]:
  789. res = hapd.request("WPS_CHECK_PIN " + t[0]).rstrip('\n')
  790. res2 = dev[0].request("WPS_CHECK_PIN " + t[0]).rstrip('\n')
  791. if res != res2:
  792. raise Exception("Unexpected difference in WPS_CHECK_PIN responses")
  793. if res != t[1]:
  794. raise Exception("Incorrect WPS_CHECK_PIN response {} (expected {})".format(res, t[1]))
  795. def test_ap_wps_wep_config(dev, apdev):
  796. """WPS 2.0 AP rejecting WEP configuration"""
  797. ssid = "test-wps-config"
  798. appin = "12345670"
  799. hostapd.add_ap(apdev[0]['ifname'],
  800. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  801. "ap_pin": appin})
  802. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  803. dev[0].wps_reg(apdev[0]['bssid'], appin, "wps-new-ssid-wep", "OPEN", "WEP",
  804. "hello", no_wait=True)
  805. ev = hapd.wait_event(["WPS-FAIL"], timeout=15)
  806. if ev is None:
  807. raise Exception("WPS-FAIL timed out")
  808. if "reason=2" not in ev:
  809. raise Exception("Unexpected reason code in WPS-FAIL")
  810. status = hapd.request("WPS_GET_STATUS")
  811. if "Last WPS result: Failed" not in status:
  812. raise Exception("WPS failure result not shown correctly")
  813. if "Failure Reason: WEP Prohibited" not in status:
  814. raise Exception("Failure reason not reported correctly")
  815. if "Peer Address: " + dev[0].p2p_interface_addr() not in status:
  816. raise Exception("Peer address not shown correctly")
  817. def test_ap_wps_ie_fragmentation(dev, apdev):
  818. """WPS AP using fragmented WPS IE"""
  819. ssid = "test-wps-ie-fragmentation"
  820. params = { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  821. "wpa_passphrase": "12345678", "wpa": "2",
  822. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  823. "device_name": "1234567890abcdef1234567890abcdef",
  824. "manufacturer": "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
  825. "model_name": "1234567890abcdef1234567890abcdef",
  826. "model_number": "1234567890abcdef1234567890abcdef",
  827. "serial_number": "1234567890abcdef1234567890abcdef" }
  828. hostapd.add_ap(apdev[0]['ifname'], params)
  829. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  830. hapd.request("WPS_PBC")
  831. dev[0].request("WPS_PBC")
  832. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  833. if ev is None:
  834. raise Exception("Association with the AP timed out")
  835. bss = dev[0].get_bss(apdev[0]['bssid'])
  836. if "wps_device_name" not in bss or bss['wps_device_name'] != "1234567890abcdef1234567890abcdef":
  837. raise Exception("Device Name not received correctly")
  838. if len(re.findall("dd..0050f204", bss['ie'])) != 2:
  839. raise Exception("Unexpected number of WPS IEs")