test_ap_wps.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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. def test_ap_wps_reg_connect(dev, apdev):
  163. """WPS registrar using AP PIN to connect"""
  164. ssid = "test-wps-reg-ap-pin"
  165. appin = "12345670"
  166. hostapd.add_ap(apdev[0]['ifname'],
  167. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  168. "wpa_passphrase": "12345678", "wpa": "2",
  169. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  170. "ap_pin": appin})
  171. logger.info("WPS provisioning step")
  172. dev[0].request("SET ignore_old_scan_res 1")
  173. dev[0].dump_monitor()
  174. dev[0].wps_reg(apdev[0]['bssid'], appin)
  175. status = dev[0].get_status()
  176. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  177. raise Exception("Not fully connected")
  178. if status['ssid'] != ssid:
  179. raise Exception("Unexpected SSID")
  180. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  181. raise Exception("Unexpected encryption configuration")
  182. if status['key_mgmt'] != 'WPA2-PSK':
  183. raise Exception("Unexpected key_mgmt")
  184. def test_ap_wps_reg_config(dev, apdev):
  185. """WPS registrar configuring and AP using AP PIN"""
  186. ssid = "test-wps-init-ap-pin"
  187. appin = "12345670"
  188. hostapd.add_ap(apdev[0]['ifname'],
  189. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  190. "ap_pin": appin})
  191. logger.info("WPS configuration step")
  192. dev[0].request("SET ignore_old_scan_res 1")
  193. dev[0].dump_monitor()
  194. new_ssid = "wps-new-ssid"
  195. new_passphrase = "1234567890"
  196. dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPA2PSK", "CCMP",
  197. new_passphrase)
  198. status = dev[0].get_status()
  199. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  200. raise Exception("Not fully connected")
  201. if status['ssid'] != new_ssid:
  202. raise Exception("Unexpected SSID")
  203. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  204. raise Exception("Unexpected encryption configuration")
  205. if status['key_mgmt'] != 'WPA2-PSK':
  206. raise Exception("Unexpected key_mgmt")
  207. def test_ap_wps_reg_config_tkip(dev, apdev):
  208. """WPS registrar configuring AP to use TKIP and AP upgrading to TKIP+CCMP"""
  209. ssid = "test-wps-init-ap"
  210. appin = "12345670"
  211. hostapd.add_ap(apdev[0]['ifname'],
  212. { "ssid": ssid, "eap_server": "1", "wps_state": "1",
  213. "ap_pin": appin})
  214. logger.info("WPS configuration step")
  215. dev[0].request("SET ignore_old_scan_res 1")
  216. dev[0].request("SET wps_version_number 0x10")
  217. dev[0].dump_monitor()
  218. new_ssid = "wps-new-ssid-with-tkip"
  219. new_passphrase = "1234567890"
  220. dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPAPSK", "TKIP",
  221. new_passphrase)
  222. logger.info("Re-connect to verify WPA2 mixed mode")
  223. dev[0].request("DISCONNECT")
  224. id = 0
  225. dev[0].set_network(id, "pairwise", "CCMP")
  226. dev[0].set_network(id, "proto", "RSN")
  227. dev[0].connect_network(id)
  228. status = dev[0].get_status()
  229. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  230. raise Exception("Not fully connected")
  231. if status['ssid'] != new_ssid:
  232. raise Exception("Unexpected SSID")
  233. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP':
  234. raise Exception("Unexpected encryption configuration")
  235. if status['key_mgmt'] != 'WPA2-PSK':
  236. raise Exception("Unexpected key_mgmt")
  237. def test_ap_wps_setup_locked(dev, apdev):
  238. """WPS registrar locking up AP setup on AP PIN failures"""
  239. ssid = "test-wps-incorrect-ap-pin"
  240. appin = "12345670"
  241. hostapd.add_ap(apdev[0]['ifname'],
  242. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  243. "wpa_passphrase": "12345678", "wpa": "2",
  244. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  245. "ap_pin": appin})
  246. dev[0].request("SET ignore_old_scan_res 1")
  247. new_ssid = "wps-new-ssid-test"
  248. new_passphrase = "1234567890"
  249. ap_setup_locked=False
  250. for pin in ["55554444", "1234", "12345678", "00000000", "11111111"]:
  251. dev[0].dump_monitor()
  252. logger.info("Try incorrect AP PIN - attempt " + pin)
  253. dev[0].wps_reg(apdev[0]['bssid'], pin, new_ssid, "WPA2PSK",
  254. "CCMP", new_passphrase, no_wait=True)
  255. ev = dev[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"])
  256. if ev is None:
  257. raise Exception("Timeout on receiving WPS operation failure event")
  258. if "CTRL-EVENT-CONNECTED" in ev:
  259. raise Exception("Unexpected connection")
  260. if "config_error=15" in ev:
  261. logger.info("AP Setup Locked")
  262. ap_setup_locked=True
  263. elif "config_error=18" not in ev:
  264. raise Exception("config_error=18 not reported")
  265. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
  266. if ev is None:
  267. raise Exception("Timeout on disconnection event")
  268. time.sleep(0.1)
  269. if not ap_setup_locked:
  270. raise Exception("AP setup was not locked")
  271. time.sleep(0.5)
  272. dev[0].dump_monitor()
  273. logger.info("WPS provisioning step")
  274. pin = dev[0].wps_read_pin()
  275. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  276. hapd.request("WPS_PIN any " + pin)
  277. dev[0].request("WPS_PIN any " + pin)
  278. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=30)
  279. if ev is None:
  280. raise Exception("WPS success was not reported")
  281. ev = dev[0].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_pbc_overlap_2ap(dev, apdev):
  285. """WPS PBC session overlap with two active APs"""
  286. hostapd.add_ap(apdev[0]['ifname'],
  287. { "ssid": "wps1", "eap_server": "1", "wps_state": "2",
  288. "wpa_passphrase": "12345678", "wpa": "2",
  289. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  290. "wps_independent": "1"})
  291. hostapd.add_ap(apdev[1]['ifname'],
  292. { "ssid": "wps2", "eap_server": "1", "wps_state": "2",
  293. "wpa_passphrase": "123456789", "wpa": "2",
  294. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  295. "wps_independent": "1"})
  296. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  297. hapd.request("WPS_PBC")
  298. hapd2 = hostapd.Hostapd(apdev[1]['ifname'])
  299. hapd2.request("WPS_PBC")
  300. logger.info("WPS provisioning step")
  301. dev[0].dump_monitor()
  302. dev[0].request("WPS_PBC")
  303. ev = dev[0].wait_event(["WPS-OVERLAP-DETECTED"], timeout=15)
  304. if ev is None:
  305. raise Exception("PBC session overlap not detected")
  306. def test_ap_wps_pbc_overlap_2sta(dev, apdev):
  307. """WPS PBC session overlap with two active STAs"""
  308. ssid = "test-wps-pbc-overlap"
  309. hostapd.add_ap(apdev[0]['ifname'],
  310. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  311. "wpa_passphrase": "12345678", "wpa": "2",
  312. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  313. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  314. logger.info("WPS provisioning step")
  315. hapd.request("WPS_PBC")
  316. dev[0].request("SET ignore_old_scan_res 1")
  317. dev[1].request("SET ignore_old_scan_res 1")
  318. dev[0].dump_monitor()
  319. dev[1].dump_monitor()
  320. dev[0].request("WPS_PBC")
  321. dev[1].request("WPS_PBC")
  322. ev = dev[0].wait_event(["WPS-M2D"], timeout=15)
  323. if ev is None:
  324. raise Exception("PBC session overlap not detected (dev0)")
  325. if "config_error=12" not in ev:
  326. raise Exception("PBC session overlap not correctly reported (dev0)")
  327. ev = dev[1].wait_event(["WPS-M2D"], timeout=15)
  328. if ev is None:
  329. raise Exception("PBC session overlap not detected (dev1)")
  330. if "config_error=12" not in ev:
  331. raise Exception("PBC session overlap not correctly reported (dev1)")
  332. def test_ap_wps_cancel(dev, apdev):
  333. """WPS AP cancelling enabled config method"""
  334. ssid = "test-wps-ap-cancel"
  335. hostapd.add_ap(apdev[0]['ifname'],
  336. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  337. "wpa_passphrase": "12345678", "wpa": "2",
  338. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
  339. bssid = apdev[0]['bssid']
  340. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  341. logger.info("Verify PBC enable/cancel")
  342. hapd.request("WPS_PBC")
  343. dev[0].request("SET ignore_old_scan_res 1")
  344. dev[0].scan(freq="2412")
  345. bss = dev[0].get_bss(apdev[0]['bssid'])
  346. if "[WPS-PBC]" not in bss['flags']:
  347. raise Exception("WPS-PBC flag missing")
  348. if "FAIL" in hapd.request("WPS_CANCEL"):
  349. raise Exception("WPS_CANCEL failed")
  350. dev[0].scan(freq="2412")
  351. bss = dev[0].get_bss(apdev[0]['bssid'])
  352. if "[WPS-PBC]" in bss['flags']:
  353. raise Exception("WPS-PBC flag not cleared")
  354. logger.info("Verify PIN enable/cancel")
  355. hapd.request("WPS_PIN any 12345670")
  356. dev[0].scan(freq="2412")
  357. bss = dev[0].get_bss(apdev[0]['bssid'])
  358. if "[WPS-AUTH]" not in bss['flags']:
  359. raise Exception("WPS-AUTH 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-AUTH]" in bss['flags']:
  365. raise Exception("WPS-AUTH flag not cleared")
  366. def test_ap_wps_er_add_enrollee(dev, apdev):
  367. """WPS ER configuring AP and adding a new enrollee using PIN"""
  368. ssid = "wps-er-add-enrollee"
  369. ap_pin = "12345670"
  370. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  371. hostapd.add_ap(apdev[0]['ifname'],
  372. { "ssid": ssid, "eap_server": "1", "wps_state": "1",
  373. "device_name": "Wireless AP", "manufacturer": "Company",
  374. "model_name": "WAP", "model_number": "123",
  375. "serial_number": "12345", "device_type": "6-0050F204-1",
  376. "os_version": "01020300",
  377. "config_methods": "label push_button",
  378. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
  379. logger.info("WPS configuration step")
  380. new_passphrase = "1234567890"
  381. dev[0].dump_monitor()
  382. dev[0].request("SET ignore_old_scan_res 1")
  383. dev[0].wps_reg(apdev[0]['bssid'], ap_pin, ssid, "WPA2PSK", "CCMP",
  384. new_passphrase)
  385. status = dev[0].get_status()
  386. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  387. raise Exception("Not fully connected")
  388. if status['ssid'] != ssid:
  389. raise Exception("Unexpected SSID")
  390. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  391. raise Exception("Unexpected encryption configuration")
  392. if status['key_mgmt'] != 'WPA2-PSK':
  393. raise Exception("Unexpected key_mgmt")
  394. logger.info("Start ER")
  395. dev[0].request("WPS_ER_START ifname=lo")
  396. ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
  397. if ev is None:
  398. raise Exception("AP discovery timed out")
  399. if ap_uuid not in ev:
  400. raise Exception("Expected AP UUID not found")
  401. logger.info("Learn AP configuration through UPnP")
  402. dev[0].dump_monitor()
  403. dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin)
  404. ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15)
  405. if ev is None:
  406. raise Exception("AP learn timed out")
  407. if ap_uuid not in ev:
  408. raise Exception("Expected AP UUID not in settings")
  409. if "ssid=" + ssid not in ev:
  410. raise Exception("Expected SSID not in settings")
  411. if "key=" + new_passphrase not in ev:
  412. raise Exception("Expected passphrase not in settings")
  413. logger.info("Add Enrollee using ER")
  414. pin = dev[1].wps_read_pin()
  415. dev[0].dump_monitor()
  416. dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr())
  417. dev[1].request("SET ignore_old_scan_res 1")
  418. dev[1].dump_monitor()
  419. dev[1].request("WPS_PIN any " + pin)
  420. ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=30)
  421. if ev is None:
  422. raise Exception("Enrollee did not report success")
  423. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  424. if ev is None:
  425. raise Exception("Association with the AP timed out")
  426. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
  427. if ev is None:
  428. raise Exception("WPS ER did not report success")
  429. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  430. logger.info("Verify registrar selection behavior")
  431. dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr())
  432. dev[1].request("DISCONNECT")
  433. dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
  434. dev[1].scan(freq="2412")
  435. bss = dev[1].get_bss(apdev[0]['bssid'])
  436. if "[WPS-AUTH]" not in bss['flags']:
  437. raise Exception("WPS-AUTH flag missing")
  438. logger.info("Stop ER")
  439. dev[0].dump_monitor()
  440. dev[0].request("WPS_ER_STOP")
  441. ev = dev[0].wait_event(["WPS-ER-AP-REMOVE"])
  442. if ev is None:
  443. raise Exception("WPS ER unsubscription timed out")
  444. dev[1].scan(freq="2412")
  445. bss = dev[1].get_bss(apdev[0]['bssid'])
  446. if "[WPS-AUTH]" in bss['flags']:
  447. raise Exception("WPS-AUTH flag not removed")
  448. def test_ap_wps_er_add_enrollee_pbc(dev, apdev):
  449. """WPS ER connected to AP and adding a new enrollee using PBC"""
  450. ssid = "wps-er-add-enrollee-pbc"
  451. ap_pin = "12345670"
  452. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  453. hostapd.add_ap(apdev[0]['ifname'],
  454. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  455. "wpa_passphrase": "12345678", "wpa": "2",
  456. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  457. "device_name": "Wireless AP", "manufacturer": "Company",
  458. "model_name": "WAP", "model_number": "123",
  459. "serial_number": "12345", "device_type": "6-0050F204-1",
  460. "os_version": "01020300",
  461. "config_methods": "label push_button",
  462. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
  463. logger.info("Learn AP configuration")
  464. dev[0].dump_monitor()
  465. dev[0].request("SET ignore_old_scan_res 1")
  466. dev[0].wps_reg(apdev[0]['bssid'], ap_pin)
  467. status = dev[0].get_status()
  468. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  469. raise Exception("Not fully connected")
  470. logger.info("Start ER")
  471. dev[0].request("WPS_ER_START ifname=lo")
  472. ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
  473. if ev is None:
  474. raise Exception("AP discovery timed out")
  475. if ap_uuid not in ev:
  476. raise Exception("Expected AP UUID not found")
  477. logger.info("Use learned network configuration on ER")
  478. dev[0].request("WPS_ER_SET_CONFIG " + ap_uuid + " 0")
  479. logger.info("Add Enrollee using ER and PBC")
  480. dev[0].dump_monitor()
  481. enrollee = dev[1].p2p_interface_addr()
  482. dev[1].request("SET ignore_old_scan_res 1")
  483. dev[1].dump_monitor()
  484. dev[1].request("WPS_PBC")
  485. ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=15)
  486. if ev is None:
  487. raise Exception("Enrollee discovery timed out")
  488. if enrollee not in ev:
  489. raise Exception("Expected Enrollee not found")
  490. dev[0].request("WPS_ER_PBC " + enrollee)
  491. ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=15)
  492. if ev is None:
  493. raise Exception("Enrollee did not report success")
  494. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  495. if ev is None:
  496. raise Exception("Association with the AP timed out")
  497. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
  498. if ev is None:
  499. raise Exception("WPS ER did not report success")
  500. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  501. # verify BSSID selection of the AP instead of UUID
  502. if "FAIL" in dev[0].request("WPS_ER_SET_CONFIG " + apdev[0]['bssid'] + " 0"):
  503. raise Exception("Could not select AP based on BSSID")
  504. def test_ap_wps_er_config_ap(dev, apdev):
  505. """WPS ER configuring AP over UPnP"""
  506. ssid = "wps-er-ap-config"
  507. ap_pin = "12345670"
  508. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  509. hostapd.add_ap(apdev[0]['ifname'],
  510. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  511. "wpa_passphrase": "12345678", "wpa": "2",
  512. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  513. "device_name": "Wireless AP", "manufacturer": "Company",
  514. "model_name": "WAP", "model_number": "123",
  515. "serial_number": "12345", "device_type": "6-0050F204-1",
  516. "os_version": "01020300",
  517. "config_methods": "label push_button",
  518. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
  519. logger.info("Connect ER to the AP")
  520. dev[0].connect(ssid, psk="12345678", scan_freq="2412")
  521. logger.info("WPS configuration step")
  522. dev[0].request("WPS_ER_START ifname=lo")
  523. ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
  524. if ev is None:
  525. raise Exception("AP discovery timed out")
  526. if ap_uuid not in ev:
  527. raise Exception("Expected AP UUID not found")
  528. new_passphrase = "1234567890"
  529. dev[0].request("WPS_ER_CONFIG " + apdev[0]['bssid'] + " " + ap_pin + " " +
  530. ssid.encode("hex") + " WPA2PSK CCMP " +
  531. new_passphrase.encode("hex"))
  532. ev = dev[0].wait_event(["WPS-SUCCESS"])
  533. if ev is None:
  534. raise Exception("WPS ER configuration operation timed out")
  535. dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"])
  536. dev[0].connect(ssid, psk="1234567890", scan_freq="2412")
  537. def test_ap_wps_fragmentation(dev, apdev):
  538. """WPS with fragmentation in EAP-WSC and mixed mode WPA+WPA2"""
  539. ssid = "test-wps-fragmentation"
  540. hostapd.add_ap(apdev[0]['ifname'],
  541. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  542. "wpa_passphrase": "12345678", "wpa": "3",
  543. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  544. "wpa_pairwise": "TKIP",
  545. "fragment_size": "50" })
  546. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  547. logger.info("WPS provisioning step")
  548. hapd.request("WPS_PBC")
  549. dev[0].request("SET ignore_old_scan_res 1")
  550. dev[0].dump_monitor()
  551. dev[0].request("SET wps_fragment_size 50")
  552. dev[0].request("WPS_PBC")
  553. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  554. if ev is None:
  555. raise Exception("Association with the AP timed out")
  556. status = dev[0].get_status()
  557. if status['wpa_state'] != 'COMPLETED':
  558. raise Exception("Not fully connected")
  559. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP':
  560. raise Exception("Unexpected encryption configuration")
  561. if status['key_mgmt'] != 'WPA2-PSK':
  562. raise Exception("Unexpected key_mgmt")
  563. def test_ap_wps_new_version_sta(dev, apdev):
  564. """WPS compatibility with new version number on the station"""
  565. ssid = "test-wps-ver"
  566. hostapd.add_ap(apdev[0]['ifname'],
  567. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  568. "wpa_passphrase": "12345678", "wpa": "2",
  569. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
  570. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  571. logger.info("WPS provisioning step")
  572. hapd.request("WPS_PBC")
  573. dev[0].request("SET ignore_old_scan_res 1")
  574. dev[0].dump_monitor()
  575. dev[0].request("SET wps_version_number 0x43")
  576. dev[0].request("WPS_PBC")
  577. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  578. if ev is None:
  579. raise Exception("Association with the AP timed out")
  580. def test_ap_wps_new_version_ap(dev, apdev):
  581. """WPS compatibility with new version number on the AP"""
  582. ssid = "test-wps-ver"
  583. hostapd.add_ap(apdev[0]['ifname'],
  584. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  585. "wpa_passphrase": "12345678", "wpa": "2",
  586. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
  587. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  588. logger.info("WPS provisioning step")
  589. if "FAIL" in hapd.request("SET wps_version_number 0x43"):
  590. raise Exception("Failed to enable test functionality")
  591. hapd.request("WPS_PBC")
  592. dev[0].request("SET ignore_old_scan_res 1")
  593. dev[0].dump_monitor()
  594. dev[0].request("WPS_PBC")
  595. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  596. hapd.request("SET wps_version_number 0x20")
  597. if ev is None:
  598. raise Exception("Association with the AP timed out")