test_ap_wps.py 29 KB

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