test_ap_wps.py 35 KB

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