test_ap_wps.py 33 KB

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