test_ap_wps.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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_er_add_enrollee(dev, apdev):
  333. """WPS ER configuring AP and adding a new enrollee using PIN"""
  334. ssid = "wps-er-add-enrollee"
  335. ap_pin = "12345670"
  336. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  337. hostapd.add_ap(apdev[0]['ifname'],
  338. { "ssid": ssid, "eap_server": "1", "wps_state": "1",
  339. "device_name": "Wireless AP", "manufacturer": "Company",
  340. "model_name": "WAP", "model_number": "123",
  341. "serial_number": "12345", "device_type": "6-0050F204-1",
  342. "os_version": "01020300",
  343. "config_methods": "label push_button",
  344. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
  345. logger.info("WPS configuration step")
  346. new_passphrase = "1234567890"
  347. dev[0].dump_monitor()
  348. dev[0].request("SET ignore_old_scan_res 1")
  349. dev[0].wps_reg(apdev[0]['bssid'], ap_pin, ssid, "WPA2PSK", "CCMP",
  350. new_passphrase)
  351. status = dev[0].get_status()
  352. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  353. raise Exception("Not fully connected")
  354. if status['ssid'] != ssid:
  355. raise Exception("Unexpected SSID")
  356. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  357. raise Exception("Unexpected encryption configuration")
  358. if status['key_mgmt'] != 'WPA2-PSK':
  359. raise Exception("Unexpected key_mgmt")
  360. logger.info("Start ER")
  361. dev[0].request("WPS_ER_START ifname=lo")
  362. ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
  363. if ev is None:
  364. raise Exception("AP discovery timed out")
  365. if ap_uuid not in ev:
  366. raise Exception("Expected AP UUID not found")
  367. logger.info("Learn AP configuration through UPnP")
  368. dev[0].dump_monitor()
  369. dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin)
  370. ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15)
  371. if ev is None:
  372. raise Exception("AP learn timed out")
  373. if ap_uuid not in ev:
  374. raise Exception("Expected AP UUID not in settings")
  375. if "ssid=" + ssid not in ev:
  376. raise Exception("Expected SSID not in settings")
  377. if "key=" + new_passphrase not in ev:
  378. raise Exception("Expected passphrase not in settings")
  379. logger.info("Add Enrollee using ER")
  380. pin = dev[1].wps_read_pin()
  381. dev[0].dump_monitor()
  382. dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr())
  383. dev[1].request("SET ignore_old_scan_res 1")
  384. dev[1].dump_monitor()
  385. dev[1].request("WPS_PIN any " + pin)
  386. ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=30)
  387. if ev is None:
  388. raise Exception("Enrollee did not report success")
  389. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  390. if ev is None:
  391. raise Exception("Association with the AP timed out")
  392. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
  393. if ev is None:
  394. raise Exception("WPS ER did not report success")
  395. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  396. def test_ap_wps_er_add_enrollee_pbc(dev, apdev):
  397. """WPS ER connected to AP and adding a new enrollee using PBC"""
  398. ssid = "wps-er-add-enrollee-pbc"
  399. ap_pin = "12345670"
  400. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  401. hostapd.add_ap(apdev[0]['ifname'],
  402. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  403. "wpa_passphrase": "12345678", "wpa": "2",
  404. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  405. "device_name": "Wireless AP", "manufacturer": "Company",
  406. "model_name": "WAP", "model_number": "123",
  407. "serial_number": "12345", "device_type": "6-0050F204-1",
  408. "os_version": "01020300",
  409. "config_methods": "label push_button",
  410. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
  411. logger.info("Learn AP configuration")
  412. dev[0].dump_monitor()
  413. dev[0].request("SET ignore_old_scan_res 1")
  414. dev[0].wps_reg(apdev[0]['bssid'], ap_pin)
  415. status = dev[0].get_status()
  416. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  417. raise Exception("Not fully connected")
  418. logger.info("Start ER")
  419. dev[0].request("WPS_ER_START ifname=lo")
  420. ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
  421. if ev is None:
  422. raise Exception("AP discovery timed out")
  423. if ap_uuid not in ev:
  424. raise Exception("Expected AP UUID not found")
  425. logger.info("Use learned network configuration on ER")
  426. dev[0].request("WPS_ER_SET_CONFIG " + ap_uuid + " 0")
  427. logger.info("Add Enrollee using ER and PBC")
  428. dev[0].dump_monitor()
  429. enrollee = dev[1].p2p_interface_addr()
  430. dev[1].request("SET ignore_old_scan_res 1")
  431. dev[1].dump_monitor()
  432. dev[1].request("WPS_PBC")
  433. ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=15)
  434. if ev is None:
  435. raise Exception("Enrollee discovery timed out")
  436. if enrollee not in ev:
  437. raise Exception("Expected Enrollee not found")
  438. dev[0].request("WPS_ER_PBC " + enrollee)
  439. ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=15)
  440. if ev is None:
  441. raise Exception("Enrollee did not report success")
  442. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  443. if ev is None:
  444. raise Exception("Association with the AP timed out")
  445. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
  446. if ev is None:
  447. raise Exception("WPS ER did not report success")
  448. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  449. # verify BSSID selection of the AP instead of UUID
  450. if "FAIL" in dev[0].request("WPS_ER_SET_CONFIG " + apdev[0]['bssid'] + " 0"):
  451. raise Exception("Could not select AP based on BSSID")
  452. def test_ap_wps_fragmentation(dev, apdev):
  453. """WPS with fragmentation in EAP-WSC and mixed mode WPA+WPA2"""
  454. ssid = "test-wps-fragmentation"
  455. hostapd.add_ap(apdev[0]['ifname'],
  456. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  457. "wpa_passphrase": "12345678", "wpa": "3",
  458. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  459. "wpa_pairwise": "TKIP",
  460. "fragment_size": "50" })
  461. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  462. logger.info("WPS provisioning step")
  463. hapd.request("WPS_PBC")
  464. dev[0].request("SET ignore_old_scan_res 1")
  465. dev[0].dump_monitor()
  466. dev[0].request("SET wps_fragment_size 50")
  467. dev[0].request("WPS_PBC")
  468. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  469. if ev is None:
  470. raise Exception("Association with the AP timed out")
  471. status = dev[0].get_status()
  472. if status['wpa_state'] != 'COMPLETED':
  473. raise Exception("Not fully connected")
  474. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP':
  475. raise Exception("Unexpected encryption configuration")
  476. if status['key_mgmt'] != 'WPA2-PSK':
  477. raise Exception("Unexpected key_mgmt")
  478. def test_ap_wps_new_version_sta(dev, apdev):
  479. """WPS compatibility with new version number on the station"""
  480. ssid = "test-wps-ver"
  481. hostapd.add_ap(apdev[0]['ifname'],
  482. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  483. "wpa_passphrase": "12345678", "wpa": "2",
  484. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
  485. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  486. logger.info("WPS provisioning step")
  487. hapd.request("WPS_PBC")
  488. dev[0].request("SET ignore_old_scan_res 1")
  489. dev[0].dump_monitor()
  490. dev[0].request("SET wps_version_number 0x43")
  491. dev[0].request("WPS_PBC")
  492. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  493. if ev is None:
  494. raise Exception("Association with the AP timed out")
  495. def test_ap_wps_new_version_ap(dev, apdev):
  496. """WPS compatibility with new version number on the AP"""
  497. ssid = "test-wps-ver"
  498. hostapd.add_ap(apdev[0]['ifname'],
  499. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  500. "wpa_passphrase": "12345678", "wpa": "2",
  501. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
  502. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  503. logger.info("WPS provisioning step")
  504. if "FAIL" in hapd.request("SET wps_version_number 0x43"):
  505. raise Exception("Failed to enable test functionality")
  506. hapd.request("WPS_PBC")
  507. dev[0].request("SET ignore_old_scan_res 1")
  508. dev[0].dump_monitor()
  509. dev[0].request("WPS_PBC")
  510. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  511. hapd.request("SET wps_version_number 0x20")
  512. if ev is None:
  513. raise Exception("Association with the AP timed out")