test_ap_wps.py 31 KB

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