test_ap_wps.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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. def test_ap_wps_reg_connect(dev, apdev):
  163. """WPS registrar using AP PIN to connect"""
  164. ssid = "test-wps-reg-ap-pin"
  165. appin = "12345670"
  166. hostapd.add_ap(apdev[0]['ifname'],
  167. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  168. "wpa_passphrase": "12345678", "wpa": "2",
  169. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  170. "ap_pin": appin})
  171. logger.info("WPS provisioning step")
  172. dev[0].request("SET ignore_old_scan_res 1")
  173. dev[0].dump_monitor()
  174. dev[0].wps_reg(apdev[0]['bssid'], appin)
  175. status = dev[0].get_status()
  176. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  177. raise Exception("Not fully connected")
  178. if status['ssid'] != ssid:
  179. raise Exception("Unexpected SSID")
  180. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  181. raise Exception("Unexpected encryption configuration")
  182. if status['key_mgmt'] != 'WPA2-PSK':
  183. raise Exception("Unexpected key_mgmt")
  184. def test_ap_wps_reg_config(dev, apdev):
  185. """WPS registrar configuring and AP using AP PIN"""
  186. ssid = "test-wps-init-ap-pin"
  187. appin = "12345670"
  188. hostapd.add_ap(apdev[0]['ifname'],
  189. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  190. "ap_pin": appin})
  191. logger.info("WPS configuration step")
  192. dev[0].request("SET ignore_old_scan_res 1")
  193. dev[0].dump_monitor()
  194. new_ssid = "wps-new-ssid"
  195. new_passphrase = "1234567890"
  196. dev[0].wps_reg(apdev[0]['bssid'], appin, new_ssid, "WPA2PSK", "CCMP",
  197. new_passphrase)
  198. status = dev[0].get_status()
  199. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  200. raise Exception("Not fully connected")
  201. if status['ssid'] != new_ssid:
  202. raise Exception("Unexpected SSID")
  203. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  204. raise Exception("Unexpected encryption configuration")
  205. if status['key_mgmt'] != 'WPA2-PSK':
  206. raise Exception("Unexpected key_mgmt")
  207. def test_ap_wps_setup_locked(dev, apdev):
  208. """WPS registrar locking up AP setup on AP PIN failures"""
  209. ssid = "test-wps-incorrect-ap-pin"
  210. appin = "12345670"
  211. hostapd.add_ap(apdev[0]['ifname'],
  212. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  213. "wpa_passphrase": "12345678", "wpa": "2",
  214. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  215. "ap_pin": appin})
  216. dev[0].request("SET ignore_old_scan_res 1")
  217. new_ssid = "wps-new-ssid-test"
  218. new_passphrase = "1234567890"
  219. ap_setup_locked=False
  220. for pin in ["55554444", "1234", "12345678", "00000000", "11111111"]:
  221. dev[0].dump_monitor()
  222. logger.info("Try incorrect AP PIN - attempt " + pin)
  223. dev[0].wps_reg(apdev[0]['bssid'], pin, new_ssid, "WPA2PSK",
  224. "CCMP", new_passphrase, no_wait=True)
  225. ev = dev[0].wait_event(["WPS-FAIL", "CTRL-EVENT-CONNECTED"])
  226. if ev is None:
  227. raise Exception("Timeout on receiving WPS operation failure event")
  228. if "CTRL-EVENT-CONNECTED" in ev:
  229. raise Exception("Unexpected connection")
  230. if "config_error=15" in ev:
  231. logger.info("AP Setup Locked")
  232. ap_setup_locked=True
  233. elif "config_error=18" not in ev:
  234. raise Exception("config_error=18 not reported")
  235. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"])
  236. if ev is None:
  237. raise Exception("Timeout on disconnection event")
  238. time.sleep(0.1)
  239. if not ap_setup_locked:
  240. raise Exception("AP setup was not locked")
  241. time.sleep(0.5)
  242. dev[0].dump_monitor()
  243. logger.info("WPS provisioning step")
  244. pin = dev[0].wps_read_pin()
  245. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  246. hapd.request("WPS_PIN any " + pin)
  247. dev[0].request("WPS_PIN any " + pin)
  248. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=30)
  249. if ev is None:
  250. raise Exception("WPS success was not reported")
  251. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  252. if ev is None:
  253. raise Exception("Association with the AP timed out")
  254. def test_ap_wps_pbc_overlap_2ap(dev, apdev):
  255. """WPS PBC session overlap with two active APs"""
  256. hostapd.add_ap(apdev[0]['ifname'],
  257. { "ssid": "wps1", "eap_server": "1", "wps_state": "2",
  258. "wpa_passphrase": "12345678", "wpa": "2",
  259. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  260. "wps_independent": "1"})
  261. hostapd.add_ap(apdev[1]['ifname'],
  262. { "ssid": "wps2", "eap_server": "1", "wps_state": "2",
  263. "wpa_passphrase": "123456789", "wpa": "2",
  264. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  265. "wps_independent": "1"})
  266. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  267. hapd.request("WPS_PBC")
  268. hapd2 = hostapd.Hostapd(apdev[1]['ifname'])
  269. hapd2.request("WPS_PBC")
  270. logger.info("WPS provisioning step")
  271. dev[0].dump_monitor()
  272. dev[0].request("WPS_PBC")
  273. ev = dev[0].wait_event(["WPS-OVERLAP-DETECTED"], timeout=15)
  274. if ev is None:
  275. raise Exception("PBC session overlap not detected")
  276. def test_ap_wps_pbc_overlap_2sta(dev, apdev):
  277. """WPS PBC session overlap with two active STAs"""
  278. ssid = "test-wps-pbc-overlap"
  279. hostapd.add_ap(apdev[0]['ifname'],
  280. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  281. "wpa_passphrase": "12345678", "wpa": "2",
  282. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  283. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  284. logger.info("WPS provisioning step")
  285. hapd.request("WPS_PBC")
  286. dev[0].request("SET ignore_old_scan_res 1")
  287. dev[1].request("SET ignore_old_scan_res 1")
  288. dev[0].dump_monitor()
  289. dev[1].dump_monitor()
  290. dev[0].request("WPS_PBC")
  291. dev[1].request("WPS_PBC")
  292. ev = dev[0].wait_event(["WPS-M2D"], timeout=15)
  293. if ev is None:
  294. raise Exception("PBC session overlap not detected (dev0)")
  295. if "config_error=12" not in ev:
  296. raise Exception("PBC session overlap not correctly reported (dev0)")
  297. ev = dev[1].wait_event(["WPS-M2D"], timeout=15)
  298. if ev is None:
  299. raise Exception("PBC session overlap not detected (dev1)")
  300. if "config_error=12" not in ev:
  301. raise Exception("PBC session overlap not correctly reported (dev1)")
  302. def test_ap_wps_er_add_enrollee(dev, apdev):
  303. """WPS ER configuring AP and adding a new enrollee using PIN"""
  304. ssid = "wps-er-add-enrollee"
  305. ap_pin = "12345670"
  306. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  307. hostapd.add_ap(apdev[0]['ifname'],
  308. { "ssid": ssid, "eap_server": "1", "wps_state": "1",
  309. "device_name": "Wireless AP", "manufacturer": "Company",
  310. "model_name": "WAP", "model_number": "123",
  311. "serial_number": "12345", "device_type": "6-0050F204-1",
  312. "os_version": "01020300",
  313. "config_methods": "label push_button",
  314. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
  315. logger.info("WPS configuration step")
  316. new_passphrase = "1234567890"
  317. dev[0].dump_monitor()
  318. dev[0].request("SET ignore_old_scan_res 1")
  319. dev[0].wps_reg(apdev[0]['bssid'], ap_pin, ssid, "WPA2PSK", "CCMP",
  320. new_passphrase)
  321. status = dev[0].get_status()
  322. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  323. raise Exception("Not fully connected")
  324. if status['ssid'] != ssid:
  325. raise Exception("Unexpected SSID")
  326. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  327. raise Exception("Unexpected encryption configuration")
  328. if status['key_mgmt'] != 'WPA2-PSK':
  329. raise Exception("Unexpected key_mgmt")
  330. logger.info("Start ER")
  331. dev[0].request("WPS_ER_START ifname=lo")
  332. ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
  333. if ev is None:
  334. raise Exception("AP discovery timed out")
  335. if ap_uuid not in ev:
  336. raise Exception("Expected AP UUID not found")
  337. logger.info("Learn AP configuration through UPnP")
  338. dev[0].dump_monitor()
  339. dev[0].request("WPS_ER_LEARN " + ap_uuid + " " + ap_pin)
  340. ev = dev[0].wait_event(["WPS-ER-AP-SETTINGS"], timeout=15)
  341. if ev is None:
  342. raise Exception("AP learn timed out")
  343. if ap_uuid not in ev:
  344. raise Exception("Expected AP UUID not in settings")
  345. if "ssid=" + ssid not in ev:
  346. raise Exception("Expected SSID not in settings")
  347. if "key=" + new_passphrase not in ev:
  348. raise Exception("Expected passphrase not in settings")
  349. logger.info("Add Enrollee using ER")
  350. pin = dev[1].wps_read_pin()
  351. dev[0].dump_monitor()
  352. dev[0].request("WPS_ER_PIN any " + pin + " " + dev[1].p2p_interface_addr())
  353. dev[1].request("SET ignore_old_scan_res 1")
  354. dev[1].dump_monitor()
  355. dev[1].request("WPS_PIN any " + pin)
  356. ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=30)
  357. if ev is None:
  358. raise Exception("Enrollee did not report success")
  359. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  360. if ev is None:
  361. raise Exception("Association with the AP timed out")
  362. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
  363. if ev is None:
  364. raise Exception("WPS ER did not report success")
  365. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  366. def test_ap_wps_er_add_enrollee_pbc(dev, apdev):
  367. """WPS ER connected to AP and adding a new enrollee using PBC"""
  368. ssid = "wps-er-add-enrollee-pbc"
  369. ap_pin = "12345670"
  370. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  371. hostapd.add_ap(apdev[0]['ifname'],
  372. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  373. "wpa_passphrase": "12345678", "wpa": "2",
  374. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  375. "device_name": "Wireless AP", "manufacturer": "Company",
  376. "model_name": "WAP", "model_number": "123",
  377. "serial_number": "12345", "device_type": "6-0050F204-1",
  378. "os_version": "01020300",
  379. "config_methods": "label push_button",
  380. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
  381. logger.info("Learn AP configuration")
  382. dev[0].dump_monitor()
  383. dev[0].request("SET ignore_old_scan_res 1")
  384. dev[0].wps_reg(apdev[0]['bssid'], ap_pin)
  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. logger.info("Start ER")
  389. dev[0].request("WPS_ER_START ifname=lo")
  390. ev = dev[0].wait_event(["WPS-ER-AP-ADD"], timeout=15)
  391. if ev is None:
  392. raise Exception("AP discovery timed out")
  393. if ap_uuid not in ev:
  394. raise Exception("Expected AP UUID not found")
  395. logger.info("Use learned network configuration on ER")
  396. dev[0].request("WPS_ER_SET_CONFIG " + ap_uuid + " 0")
  397. logger.info("Add Enrollee using ER and PBC")
  398. dev[0].dump_monitor()
  399. enrollee = dev[1].p2p_interface_addr()
  400. dev[1].request("SET ignore_old_scan_res 1")
  401. dev[1].dump_monitor()
  402. dev[1].request("WPS_PBC")
  403. ev = dev[0].wait_event(["WPS-ER-ENROLLEE-ADD"], timeout=15)
  404. if ev is None:
  405. raise Exception("Enrollee discovery timed out")
  406. if enrollee not in ev:
  407. raise Exception("Expected Enrollee not found")
  408. dev[0].request("WPS_ER_PBC " + enrollee)
  409. ev = dev[1].wait_event(["WPS-SUCCESS"], timeout=15)
  410. if ev is None:
  411. raise Exception("Enrollee did not report success")
  412. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  413. if ev is None:
  414. raise Exception("Association with the AP timed out")
  415. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
  416. if ev is None:
  417. raise Exception("WPS ER did not report success")
  418. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  419. def test_ap_wps_fragmentation(dev, apdev):
  420. """WPS with fragmentation in EAP-WSC and mixed mode WPA+WPA2"""
  421. ssid = "test-wps-fragmentation"
  422. hostapd.add_ap(apdev[0]['ifname'],
  423. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  424. "wpa_passphrase": "12345678", "wpa": "3",
  425. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  426. "wpa_pairwise": "TKIP",
  427. "fragment_size": "50" })
  428. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  429. logger.info("WPS provisioning step")
  430. hapd.request("WPS_PBC")
  431. dev[0].request("SET ignore_old_scan_res 1")
  432. dev[0].dump_monitor()
  433. dev[0].request("SET wps_fragment_size 50")
  434. dev[0].request("WPS_PBC")
  435. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  436. if ev is None:
  437. raise Exception("Association with the AP timed out")
  438. status = dev[0].get_status()
  439. if status['wpa_state'] != 'COMPLETED':
  440. raise Exception("Not fully connected")
  441. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'TKIP':
  442. raise Exception("Unexpected encryption configuration")
  443. if status['key_mgmt'] != 'WPA2-PSK':
  444. raise Exception("Unexpected key_mgmt")
  445. def test_ap_wps_new_version_sta(dev, apdev):
  446. """WPS compatibility with new version number on the station"""
  447. ssid = "test-wps-ver"
  448. hostapd.add_ap(apdev[0]['ifname'],
  449. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  450. "wpa_passphrase": "12345678", "wpa": "2",
  451. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
  452. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  453. logger.info("WPS provisioning step")
  454. hapd.request("WPS_PBC")
  455. dev[0].request("SET ignore_old_scan_res 1")
  456. dev[0].dump_monitor()
  457. dev[0].request("SET wps_version_number 0x43")
  458. dev[0].request("WPS_PBC")
  459. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  460. if ev is None:
  461. raise Exception("Association with the AP timed out")
  462. def test_ap_wps_new_version_ap(dev, apdev):
  463. """WPS compatibility with new version number on the AP"""
  464. ssid = "test-wps-ver"
  465. hostapd.add_ap(apdev[0]['ifname'],
  466. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  467. "wpa_passphrase": "12345678", "wpa": "2",
  468. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
  469. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  470. logger.info("WPS provisioning step")
  471. if "FAIL" in hapd.request("SET wps_version_number 0x43"):
  472. raise Exception("Failed to enable test functionality")
  473. hapd.request("WPS_PBC")
  474. dev[0].request("SET ignore_old_scan_res 1")
  475. dev[0].dump_monitor()
  476. dev[0].request("WPS_PBC")
  477. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  478. hapd.request("SET wps_version_number 0x20")
  479. if ev is None:
  480. raise Exception("Association with the AP timed out")