test_ap_wps.py 42 KB

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