test_ap_wps.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. #!/usr/bin/python
  2. #
  3. # WPS tests
  4. # Copyright (c) 2013, 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 hwsim_utils
  13. import hostapd
  14. def test_ap_wps_init(dev, apdev):
  15. """Initial AP configuration with first WPS Enrollee"""
  16. ssid = "test-wps"
  17. hostapd.add_ap(apdev[0]['ifname'],
  18. { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
  19. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  20. logger.info("WPS provisioning step")
  21. hapd.request("WPS_PBC")
  22. dev[0].request("SET ignore_old_scan_res 1")
  23. dev[0].dump_monitor()
  24. dev[0].request("WPS_PBC")
  25. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  26. if ev is None:
  27. raise Exception("Association with the AP timed out")
  28. status = dev[0].get_status()
  29. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  30. raise Exception("Not fully connected")
  31. if status['ssid'] != ssid:
  32. raise Exception("Unexpected SSID")
  33. if status['pairwise_cipher'] != 'CCMP':
  34. raise Exception("Unexpected encryption configuration")
  35. if status['key_mgmt'] != 'WPA2-PSK':
  36. raise Exception("Unexpected key_mgmt")
  37. def test_ap_wps_conf(dev, apdev):
  38. """WPS PBC provisioning with configured AP"""
  39. ssid = "test-wps-conf"
  40. hostapd.add_ap(apdev[0]['ifname'],
  41. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  42. "wpa_passphrase": "12345678", "wpa": "2",
  43. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  44. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  45. logger.info("WPS provisioning step")
  46. hapd.request("WPS_PBC")
  47. dev[0].dump_monitor()
  48. dev[0].request("WPS_PBC")
  49. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  50. if ev is None:
  51. raise Exception("Association with the AP timed out")
  52. status = dev[0].get_status()
  53. if status['wpa_state'] != 'COMPLETED':
  54. raise Exception("Not fully connected")
  55. if status['bssid'] != apdev[0]['bssid']:
  56. raise Exception("Unexpected BSSID")
  57. if status['ssid'] != ssid:
  58. raise Exception("Unexpected SSID")
  59. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  60. raise Exception("Unexpected encryption configuration")
  61. if status['key_mgmt'] != 'WPA2-PSK':
  62. raise Exception("Unexpected key_mgmt")
  63. def test_ap_wps_twice(dev, apdev):
  64. """WPS provisioning with twice to change passphrase"""
  65. ssid = "test-wps-twice"
  66. params = { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  67. "wpa_passphrase": "12345678", "wpa": "2",
  68. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" }
  69. hostapd.add_ap(apdev[0]['ifname'], params)
  70. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  71. logger.info("WPS provisioning step")
  72. hapd.request("WPS_PBC")
  73. dev[0].request("SET ignore_old_scan_res 1")
  74. dev[0].dump_monitor()
  75. dev[0].request("WPS_PBC")
  76. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  77. if ev is None:
  78. raise Exception("Association with the AP timed out")
  79. dev[0].request("DISCONNECT")
  80. logger.info("Restart AP with different passphrase and re-run WPS")
  81. hapd_global = hostapd.HostapdGlobal()
  82. hapd_global.remove(apdev[0]['ifname'])
  83. params['wpa_passphrase'] = 'another passphrase'
  84. hostapd.add_ap(apdev[0]['ifname'], params)
  85. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  86. logger.info("WPS provisioning step")
  87. hapd.request("WPS_PBC")
  88. dev[0].dump_monitor()
  89. dev[0].request("WPS_PBC")
  90. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  91. if ev is None:
  92. raise Exception("Association with the AP timed out")
  93. networks = dev[0].list_networks()
  94. if len(networks) > 1:
  95. raise Exception("Unexpected duplicated network block present")
  96. def test_ap_wps_incorrect_pin(dev, apdev):
  97. """WPS PIN provisioning with incorrect PIN"""
  98. ssid = "test-wps-incorrect-pin"
  99. hostapd.add_ap(apdev[0]['ifname'],
  100. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  101. "wpa_passphrase": "12345678", "wpa": "2",
  102. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  103. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  104. logger.info("WPS provisioning attempt 1")
  105. hapd.request("WPS_PIN any 12345670")
  106. dev[0].request("SET ignore_old_scan_res 1")
  107. dev[0].dump_monitor()
  108. dev[0].request("WPS_PIN any 55554444")
  109. ev = dev[0].wait_event(["WPS-FAIL"], timeout=30)
  110. if ev is None:
  111. raise Exception("WPS operation timed out")
  112. if "config_error=18" not in ev:
  113. raise Exception("Incorrect config_error reported")
  114. if "msg=8" not in ev:
  115. raise Exception("PIN error detected on incorrect message")
  116. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
  117. if ev is None:
  118. raise Exception("Timeout on disconnection event")
  119. dev[0].request("WPS_CANCEL")
  120. # if a scan was in progress, wait for it to complete before trying WPS again
  121. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
  122. logger.info("WPS provisioning attempt 2")
  123. hapd.request("WPS_PIN any 12345670")
  124. dev[0].dump_monitor()
  125. dev[0].request("WPS_PIN any 12344444")
  126. ev = dev[0].wait_event(["WPS-FAIL"], timeout=30)
  127. if ev is None:
  128. raise Exception("WPS operation timed out")
  129. if "config_error=18" not in ev:
  130. raise Exception("Incorrect config_error reported")
  131. if "msg=10" not in ev:
  132. raise Exception("PIN error detected on incorrect message")
  133. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
  134. if ev is None:
  135. raise Exception("Timeout on disconnection event")
  136. def test_ap_wps_conf_pin(dev, apdev):
  137. """WPS PIN provisioning with configured AP"""
  138. ssid = "test-wps-conf-pin"
  139. hostapd.add_ap(apdev[0]['ifname'],
  140. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  141. "wpa_passphrase": "12345678", "wpa": "2",
  142. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  143. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  144. logger.info("WPS provisioning step")
  145. pin = dev[0].wps_read_pin()
  146. hapd.request("WPS_PIN any " + pin)
  147. dev[0].request("SET ignore_old_scan_res 1")
  148. dev[0].dump_monitor()
  149. dev[0].request("WPS_PIN any " + pin)
  150. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  151. if ev is None:
  152. raise Exception("Association with the AP timed out")
  153. status = dev[0].get_status()
  154. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  155. raise Exception("Not fully connected")
  156. if status['ssid'] != ssid:
  157. raise Exception("Unexpected SSID")
  158. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  159. raise Exception("Unexpected encryption configuration")
  160. if status['key_mgmt'] != 'WPA2-PSK':
  161. raise Exception("Unexpected key_mgmt")
  162. dev[1].request("SET ignore_old_scan_res 1")
  163. dev[1].scan(freq="2412")
  164. bss = dev[1].get_bss(apdev[0]['bssid'])
  165. if "[WPS-AUTH]" in bss['flags']:
  166. raise Exception("WPS-AUTH flag not cleared")
  167. logger.info("Try to connect from another station using the same PIN")
  168. dev[1].request("WPS_PIN any " + pin)
  169. ev = dev[1].wait_event(["WPS-M2D","CTRL-EVENT-CONNECTED"], timeout=30)
  170. if ev is None:
  171. raise Exception("Operation timed out")
  172. if "WPS-M2D" not in ev:
  173. raise Exception("Unexpected WPS operation started")
  174. def test_ap_wps_reg_connect(dev, apdev):
  175. """WPS registrar using AP PIN to connect"""
  176. ssid = "test-wps-reg-ap-pin"
  177. appin = "12345670"
  178. hostapd.add_ap(apdev[0]['ifname'],
  179. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  180. "wpa_passphrase": "12345678", "wpa": "2",
  181. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  182. "ap_pin": appin})
  183. logger.info("WPS provisioning step")
  184. dev[0].request("SET ignore_old_scan_res 1")
  185. dev[0].dump_monitor()
  186. dev[0].wps_reg(apdev[0]['bssid'], appin)
  187. status = dev[0].get_status()
  188. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  189. raise Exception("Not fully connected")
  190. if status['ssid'] != ssid:
  191. raise Exception("Unexpected SSID")
  192. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  193. raise Exception("Unexpected encryption configuration")
  194. if status['key_mgmt'] != 'WPA2-PSK':
  195. raise Exception("Unexpected key_mgmt")
  196. def test_ap_wps_reg_config(dev, apdev):
  197. """WPS registrar configuring and AP using AP PIN"""
  198. ssid = "test-wps-init-ap-pin"
  199. appin = "12345670"
  200. hostapd.add_ap(apdev[0]['ifname'],
  201. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  202. "ap_pin": appin})
  203. logger.info("WPS configuration step")
  204. dev[0].request("SET ignore_old_scan_res 1")
  205. dev[0].dump_monitor()
  206. new_ssid = "wps-new-ssid"
  207. new_passphrase = "1234567890"
  208. dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPA2PSK", "CCMP",
  209. new_passphrase)
  210. status = dev[0].get_status()
  211. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  212. raise Exception("Not fully connected")
  213. if status['ssid'] != new_ssid:
  214. raise Exception("Unexpected SSID")
  215. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  216. raise Exception("Unexpected encryption configuration")
  217. if status['key_mgmt'] != 'WPA2-PSK':
  218. raise Exception("Unexpected key_mgmt")
  219. def test_ap_wps_reg_config_tkip(dev, apdev):
  220. """WPS registrar configuring AP to use TKIP and AP upgrading to TKIP+CCMP"""
  221. ssid = "test-wps-init-ap"
  222. appin = "12345670"
  223. hostapd.add_ap(apdev[0]['ifname'],
  224. { "ssid": ssid, "eap_server": "1", "wps_state": "1",
  225. "ap_pin": appin})
  226. logger.info("WPS configuration step")
  227. dev[0].request("SET ignore_old_scan_res 1")
  228. dev[0].request("SET wps_version_number 0x10")
  229. dev[0].dump_monitor()
  230. new_ssid = "wps-new-ssid-with-tkip"
  231. new_passphrase = "1234567890"
  232. dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPAPSK", "TKIP",
  233. new_passphrase)
  234. logger.info("Re-connect to verify WPA2 mixed mode")
  235. dev[0].request("DISCONNECT")
  236. id = 0
  237. dev[0].set_network(id, "pairwise", "CCMP")
  238. dev[0].set_network(id, "proto", "RSN")
  239. dev[0].connect_network(id)
  240. status = dev[0].get_status()
  241. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  242. raise Exception("Not fully connected")
  243. if status['ssid'] != new_ssid:
  244. raise Exception("Unexpected SSID")
  245. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP':
  246. raise Exception("Unexpected encryption configuration")
  247. if status['key_mgmt'] != 'WPA2-PSK':
  248. raise Exception("Unexpected key_mgmt")
  249. def test_ap_wps_setup_locked(dev, apdev):
  250. """WPS registrar locking up AP setup on AP PIN failures"""
  251. ssid = "test-wps-incorrect-ap-pin"
  252. appin = "12345670"
  253. hostapd.add_ap(apdev[0]['ifname'],
  254. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  255. "wpa_passphrase": "12345678", "wpa": "2",
  256. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  257. "ap_pin": appin})
  258. dev[0].request("SET ignore_old_scan_res 1")
  259. new_ssid = "wps-new-ssid-test"
  260. new_passphrase = "1234567890"
  261. ap_setup_locked=False
  262. for pin in ["55554444", "1234", "12345678", "00000000", "11111111"]:
  263. dev[0].dump_monitor()
  264. logger.info("Try incorrect AP PIN - attempt " + pin)
  265. dev[0].wps_reg(apdev[0]['bssid'], pin, new_ssid, "WPA2PSK",
  266. "CCMP", new_passphrase, no_wait=True)
  267. ev = dev[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"])
  268. if ev is None:
  269. raise Exception("Timeout on receiving WPS operation failure event")
  270. if "CTRL-EVENT-CONNECTED" in ev:
  271. raise Exception("Unexpected connection")
  272. if "config_error=15" in ev:
  273. logger.info("AP Setup Locked")
  274. ap_setup_locked=True
  275. elif "config_error=18" not in ev:
  276. raise Exception("config_error=18 not reported")
  277. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
  278. if ev is None:
  279. raise Exception("Timeout on disconnection event")
  280. time.sleep(0.1)
  281. if not ap_setup_locked:
  282. raise Exception("AP setup was not locked")
  283. time.sleep(0.5)
  284. dev[0].dump_monitor()
  285. logger.info("WPS provisioning step")
  286. pin = dev[0].wps_read_pin()
  287. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  288. hapd.request("WPS_PIN any " + pin)
  289. dev[0].request("WPS_PIN any " + pin)
  290. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=30)
  291. if ev is None:
  292. raise Exception("WPS success was not reported")
  293. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  294. if ev is None:
  295. raise Exception("Association with the AP timed out")
  296. def test_ap_wps_pbc_overlap_2ap(dev, apdev):
  297. """WPS PBC session overlap with two active APs"""
  298. hostapd.add_ap(apdev[0]['ifname'],
  299. { "ssid": "wps1", "eap_server": "1", "wps_state": "2",
  300. "wpa_passphrase": "12345678", "wpa": "2",
  301. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  302. "wps_independent": "1"})
  303. hostapd.add_ap(apdev[1]['ifname'],
  304. { "ssid": "wps2", "eap_server": "1", "wps_state": "2",
  305. "wpa_passphrase": "123456789", "wpa": "2",
  306. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  307. "wps_independent": "1"})
  308. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  309. hapd.request("WPS_PBC")
  310. hapd2 = hostapd.Hostapd(apdev[1]['ifname'])
  311. hapd2.request("WPS_PBC")
  312. logger.info("WPS provisioning step")
  313. dev[0].dump_monitor()
  314. dev[0].request("WPS_PBC")
  315. ev = dev[0].wait_event(["WPS-OVERLAP-DETECTED"], timeout=15)
  316. if ev is None:
  317. raise Exception("PBC session overlap not detected")
  318. def test_ap_wps_pbc_overlap_2sta(dev, apdev):
  319. """WPS PBC session overlap with two active STAs"""
  320. ssid = "test-wps-pbc-overlap"
  321. hostapd.add_ap(apdev[0]['ifname'],
  322. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  323. "wpa_passphrase": "12345678", "wpa": "2",
  324. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  325. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  326. logger.info("WPS provisioning step")
  327. hapd.request("WPS_PBC")
  328. dev[0].request("SET ignore_old_scan_res 1")
  329. dev[1].request("SET ignore_old_scan_res 1")
  330. dev[0].dump_monitor()
  331. dev[1].dump_monitor()
  332. dev[0].request("WPS_PBC")
  333. dev[1].request("WPS_PBC")
  334. ev = dev[0].wait_event(["WPS-M2D"], timeout=15)
  335. if ev is None:
  336. raise Exception("PBC session overlap not detected (dev0)")
  337. if "config_error=12" not in ev:
  338. raise Exception("PBC session overlap not correctly reported (dev0)")
  339. ev = dev[1].wait_event(["WPS-M2D"], timeout=15)
  340. if ev is None:
  341. raise Exception("PBC session overlap not detected (dev1)")
  342. if "config_error=12" not in ev:
  343. raise Exception("PBC session overlap not correctly reported (dev1)")
  344. def test_ap_wps_cancel(dev, apdev):
  345. """WPS AP cancelling enabled config method"""
  346. ssid = "test-wps-ap-cancel"
  347. hostapd.add_ap(apdev[0]['ifname'],
  348. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  349. "wpa_passphrase": "12345678", "wpa": "2",
  350. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
  351. bssid = apdev[0]['bssid']
  352. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  353. logger.info("Verify PBC enable/cancel")
  354. hapd.request("WPS_PBC")
  355. dev[0].request("SET ignore_old_scan_res 1")
  356. dev[0].scan(freq="2412")
  357. bss = dev[0].get_bss(apdev[0]['bssid'])
  358. if "[WPS-PBC]" not in bss['flags']:
  359. raise Exception("WPS-PBC flag missing")
  360. if "FAIL" in hapd.request("WPS_CANCEL"):
  361. raise Exception("WPS_CANCEL failed")
  362. dev[0].scan(freq="2412")
  363. bss = dev[0].get_bss(apdev[0]['bssid'])
  364. if "[WPS-PBC]" in bss['flags']:
  365. raise Exception("WPS-PBC flag not cleared")
  366. logger.info("Verify PIN enable/cancel")
  367. hapd.request("WPS_PIN any 12345670")
  368. dev[0].scan(freq="2412")
  369. bss = dev[0].get_bss(apdev[0]['bssid'])
  370. if "[WPS-AUTH]" not in bss['flags']:
  371. raise Exception("WPS-AUTH flag missing")
  372. if "FAIL" in hapd.request("WPS_CANCEL"):
  373. raise Exception("WPS_CANCEL failed")
  374. dev[0].scan(freq="2412")
  375. bss = dev[0].get_bss(apdev[0]['bssid'])
  376. if "[WPS-AUTH]" in bss['flags']:
  377. raise Exception("WPS-AUTH flag not cleared")
  378. def test_ap_wps_er_add_enrollee(dev, apdev):
  379. """WPS ER configuring AP and adding a new enrollee using PIN"""
  380. ssid = "wps-er-add-enrollee"
  381. ap_pin = "12345670"
  382. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  383. hostapd.add_ap(apdev[0]['ifname'],
  384. { "ssid": ssid, "eap_server": "1", "wps_state": "1",
  385. "device_name": "Wireless AP", "manufacturer": "Company",
  386. "model_name": "WAP", "model_number": "123",
  387. "serial_number": "12345", "device_type": "6-0050F204-1",
  388. "os_version": "01020300",
  389. "config_methods": "label push_button",
  390. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
  391. logger.info("WPS configuration step")
  392. new_passphrase = "1234567890"
  393. dev[0].dump_monitor()
  394. dev[0].request("SET ignore_old_scan_res 1")
  395. dev[0].wps_reg(apdev[0]['bssid'], ap_pin, ssid, "WPA2PSK", "CCMP",
  396. new_passphrase)
  397. status = dev[0].get_status()
  398. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  399. raise Exception("Not fully connected")
  400. if status['ssid'] != ssid:
  401. raise Exception("Unexpected SSID")
  402. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  403. raise Exception("Unexpected encryption configuration")
  404. if status['key_mgmt'] != 'WPA2-PSK':
  405. raise Exception("Unexpected key_mgmt")
  406. logger.info("Start ER")
  407. dev[0].request("WPS_ER_START ifname=lo")
  408. ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
  409. if ev is None:
  410. raise Exception("AP discovery timed out")
  411. if ap_uuid not in ev:
  412. raise Exception("Expected AP UUID not found")
  413. logger.info("Learn AP configuration through UPnP")
  414. dev[0].dump_monitor()
  415. dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin)
  416. ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15)
  417. if ev is None:
  418. raise Exception("AP learn timed out")
  419. if ap_uuid not in ev:
  420. raise Exception("Expected AP UUID not in settings")
  421. if "ssid=" + ssid not in ev:
  422. raise Exception("Expected SSID not in settings")
  423. if "key=" + new_passphrase not in ev:
  424. raise Exception("Expected passphrase not in settings")
  425. logger.info("Add Enrollee using ER")
  426. pin = dev[1].wps_read_pin()
  427. dev[0].dump_monitor()
  428. dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr())
  429. dev[1].request("SET ignore_old_scan_res 1")
  430. dev[1].dump_monitor()
  431. dev[1].request("WPS_PIN any " + pin)
  432. ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=30)
  433. if ev is None:
  434. raise Exception("Enrollee did not report success")
  435. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  436. if ev is None:
  437. raise Exception("Association with the AP timed out")
  438. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
  439. if ev is None:
  440. raise Exception("WPS ER did not report success")
  441. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  442. logger.info("Verify registrar selection behavior")
  443. dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr())
  444. dev[1].request("DISCONNECT")
  445. dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
  446. dev[1].scan(freq="2412")
  447. bss = dev[1].get_bss(apdev[0]['bssid'])
  448. if "[WPS-AUTH]" not in bss['flags']:
  449. raise Exception("WPS-AUTH flag missing")
  450. logger.info("Stop ER")
  451. dev[0].dump_monitor()
  452. dev[0].request("WPS_ER_STOP")
  453. ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"])
  454. if ev is None:
  455. raise Exception("WPS ER unsubscription timed out")
  456. dev[1].scan(freq="2412")
  457. bss = dev[1].get_bss(apdev[0]['bssid'])
  458. if "[WPS-AUTH]" in bss['flags']:
  459. raise Exception("WPS-AUTH flag not removed")
  460. def test_ap_wps_er_add_enrollee_pbc(dev, apdev):
  461. """WPS ER connected to AP and adding a new enrollee using PBC"""
  462. ssid = "wps-er-add-enrollee-pbc"
  463. ap_pin = "12345670"
  464. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  465. hostapd.add_ap(apdev[0]['ifname'],
  466. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  467. "wpa_passphrase": "12345678", "wpa": "2",
  468. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  469. "device_name": "Wireless AP", "manufacturer": "Company",
  470. "model_name": "WAP", "model_number": "123",
  471. "serial_number": "12345", "device_type": "6-0050F204-1",
  472. "os_version": "01020300",
  473. "config_methods": "label push_button",
  474. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
  475. logger.info("Learn AP configuration")
  476. dev[0].dump_monitor()
  477. dev[0].request("SET ignore_old_scan_res 1")
  478. dev[0].wps_reg(apdev[0]['bssid'], ap_pin)
  479. status = dev[0].get_status()
  480. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  481. raise Exception("Not fully connected")
  482. logger.info("Start ER")
  483. dev[0].request("WPS_ER_START ifname=lo")
  484. ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
  485. if ev is None:
  486. raise Exception("AP discovery timed out")
  487. if ap_uuid not in ev:
  488. raise Exception("Expected AP UUID not found")
  489. logger.info("Use learned network configuration on ER")
  490. dev[0].request("WPS_ER_SET_CONFIG " + ap_uuid + " 0")
  491. logger.info("Add Enrollee using ER and PBC")
  492. dev[0].dump_monitor()
  493. enrollee = dev[1].p2p_interface_addr()
  494. dev[1].request("SET ignore_old_scan_res 1")
  495. dev[1].dump_monitor()
  496. dev[1].request("WPS_PBC")
  497. ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=15)
  498. if ev is None:
  499. raise Exception("Enrollee discovery timed out")
  500. if enrollee not in ev:
  501. raise Exception("Expected Enrollee not found")
  502. dev[0].request("WPS_ER_PBC " + enrollee)
  503. ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=15)
  504. if ev is None:
  505. raise Exception("Enrollee did not report success")
  506. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  507. if ev is None:
  508. raise Exception("Association with the AP timed out")
  509. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
  510. if ev is None:
  511. raise Exception("WPS ER did not report success")
  512. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  513. # verify BSSID selection of the AP instead of UUID
  514. if "FAIL" in dev[0].request("WPS_ER_SET_CONFIG " + apdev[0]['bssid'] + " 0"):
  515. raise Exception("Could not select AP based on BSSID")
  516. def test_ap_wps_er_config_ap(dev, apdev):
  517. """WPS ER configuring AP over UPnP"""
  518. ssid = "wps-er-ap-config"
  519. ap_pin = "12345670"
  520. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  521. hostapd.add_ap(apdev[0]['ifname'],
  522. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  523. "wpa_passphrase": "12345678", "wpa": "2",
  524. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  525. "device_name": "Wireless AP", "manufacturer": "Company",
  526. "model_name": "WAP", "model_number": "123",
  527. "serial_number": "12345", "device_type": "6-0050F204-1",
  528. "os_version": "01020300",
  529. "config_methods": "label push_button",
  530. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
  531. logger.info("Connect ER to the AP")
  532. dev[0].connect(ssid, psk="12345678", scan_freq="2412")
  533. logger.info("WPS configuration step")
  534. dev[0].request("WPS_ER_START ifname=lo")
  535. ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
  536. if ev is None:
  537. raise Exception("AP discovery timed out")
  538. if ap_uuid not in ev:
  539. raise Exception("Expected AP UUID not found")
  540. new_passphrase = "1234567890"
  541. dev[0].request("WPS_ER_CONFIG " + apdev[0]['bssid'] + " " + ap_pin + " " +
  542. ssid.encode("hex") + " WPA2PSK CCMP " +
  543. new_passphrase.encode("hex"))
  544. ev = dev[0].wait_event(["WPS-SUCCESS"])
  545. if ev is None:
  546. raise Exception("WPS ER configuration operation timed out")
  547. dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
  548. dev[0].connect(ssid, psk="1234567890", scan_freq="2412")
  549. def test_ap_wps_fragmentation(dev, apdev):
  550. """WPS with fragmentation in EAP-WSC and mixed mode WPA+WPA2"""
  551. ssid = "test-wps-fragmentation"
  552. hostapd.add_ap(apdev[0]['ifname'],
  553. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  554. "wpa_passphrase": "12345678", "wpa": "3",
  555. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  556. "wpa_pairwise": "TKIP",
  557. "fragment_size": "50" })
  558. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  559. logger.info("WPS provisioning step")
  560. hapd.request("WPS_PBC")
  561. dev[0].request("SET ignore_old_scan_res 1")
  562. dev[0].dump_monitor()
  563. dev[0].request("SET wps_fragment_size 50")
  564. dev[0].request("WPS_PBC")
  565. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  566. if ev is None:
  567. raise Exception("Association with the AP timed out")
  568. status = dev[0].get_status()
  569. if status['wpa_state'] != 'COMPLETED':
  570. raise Exception("Not fully connected")
  571. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP':
  572. raise Exception("Unexpected encryption configuration")
  573. if status['key_mgmt'] != 'WPA2-PSK':
  574. raise Exception("Unexpected key_mgmt")
  575. def test_ap_wps_new_version_sta(dev, apdev):
  576. """WPS compatibility with new version number on the station"""
  577. ssid = "test-wps-ver"
  578. hostapd.add_ap(apdev[0]['ifname'],
  579. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  580. "wpa_passphrase": "12345678", "wpa": "2",
  581. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
  582. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  583. logger.info("WPS provisioning step")
  584. hapd.request("WPS_PBC")
  585. dev[0].request("SET ignore_old_scan_res 1")
  586. dev[0].dump_monitor()
  587. dev[0].request("SET wps_version_number 0x43")
  588. dev[0].request("WPS_PBC")
  589. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  590. if ev is None:
  591. raise Exception("Association with the AP timed out")
  592. def test_ap_wps_new_version_ap(dev, apdev):
  593. """WPS compatibility with new version number on the AP"""
  594. ssid = "test-wps-ver"
  595. hostapd.add_ap(apdev[0]['ifname'],
  596. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  597. "wpa_passphrase": "12345678", "wpa": "2",
  598. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
  599. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  600. logger.info("WPS provisioning step")
  601. if "FAIL" in hapd.request("SET wps_version_number 0x43"):
  602. raise Exception("Failed to enable test functionality")
  603. hapd.request("WPS_PBC")
  604. dev[0].request("SET ignore_old_scan_res 1")
  605. dev[0].dump_monitor()
  606. dev[0].request("WPS_PBC")
  607. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  608. hapd.request("SET wps_version_number 0x20")
  609. if ev is None:
  610. raise Exception("Association with the AP timed out")