test_ap_wps.py 33 KB

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