test_ap_wps.py 37 KB

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