test_ap_wps.py 36 KB

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