test_ap_wps.py 42 KB

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