test_ap_wps.py 34 KB

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