test_nfc_wps.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. # WPS+NFC tests
  2. # Copyright (c) 2013, 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 hwsim_utils
  11. import hostapd
  12. def check_wpa2_connection(sta, ap, ssid, mixed=False):
  13. status = sta.get_status()
  14. if status['wpa_state'] != 'COMPLETED':
  15. raise Exception("Not fully connected")
  16. if status['bssid'] != ap['bssid']:
  17. raise Exception("Unexpected BSSID")
  18. if status['ssid'] != ssid:
  19. raise Exception("Unexpected SSID")
  20. if status['pairwise_cipher'] != 'CCMP':
  21. raise Exception("Unexpected encryption configuration")
  22. if status['group_cipher'] != 'CCMP' and not mixed:
  23. raise Exception("Unexpected encryption configuration")
  24. if status['key_mgmt'] != 'WPA2-PSK':
  25. raise Exception("Unexpected key_mgmt")
  26. hwsim_utils.test_connectivity(sta.ifname, ap['ifname'])
  27. def ap_wps_params(ssid):
  28. return { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  29. "wpa_passphrase": "12345678", "wpa": "2",
  30. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"}
  31. def test_nfc_wps_password_token_sta(dev, apdev):
  32. """NFC tag with password token on the station/Enrollee"""
  33. ssid = "test-wps-nfc-pw-token-conf"
  34. params = ap_wps_params(ssid)
  35. hostapd.add_ap(apdev[0]['ifname'], params)
  36. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  37. logger.info("WPS provisioning step using password token from station")
  38. pw = dev[0].request("WPS_NFC_TOKEN NDEF").rstrip()
  39. if "FAIL" in pw:
  40. raise Exception("Failed to generate password token")
  41. res = hapd.request("WPS_NFC_TAG_READ " + pw)
  42. if "FAIL" in res:
  43. raise Exception("Failed to provide NFC tag contents to hostapd")
  44. dev[0].dump_monitor()
  45. res = dev[0].request("WPS_NFC")
  46. if "FAIL" in res:
  47. raise Exception("Failed to start Enrollee using NFC password token")
  48. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  49. if ev is None:
  50. raise Exception("Association with the AP timed out")
  51. check_wpa2_connection(dev[0], apdev[0], ssid)
  52. def test_nfc_wps_config_token(dev, apdev):
  53. """NFC tag with configuration token from AP"""
  54. ssid = "test-wps-nfc-conf-token"
  55. params = ap_wps_params(ssid)
  56. hostapd.add_ap(apdev[0]['ifname'], params)
  57. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  58. logger.info("NFC configuration token from AP to station")
  59. conf = hapd.request("WPS_NFC_CONFIG_TOKEN NDEF").rstrip()
  60. if "FAIL" in conf:
  61. raise Exception("Failed to generate configuration token")
  62. dev[0].dump_monitor()
  63. res = dev[0].request("WPS_NFC_TAG_READ " + conf)
  64. if "FAIL" in res:
  65. raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
  66. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  67. if ev is None:
  68. raise Exception("Association with the AP timed out")
  69. check_wpa2_connection(dev[0], apdev[0], ssid)
  70. def test_nfc_wps_config_token_init(dev, apdev):
  71. """NFC tag with configuration token from AP with auto configuration"""
  72. ssid = "test-wps-nfc-conf-token-init"
  73. hostapd.add_ap(apdev[0]['ifname'],
  74. { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
  75. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  76. logger.info("NFC configuration token from AP to station")
  77. conf = hapd.request("WPS_NFC_CONFIG_TOKEN NDEF").rstrip()
  78. if "FAIL" in conf:
  79. raise Exception("Failed to generate configuration token")
  80. dev[0].dump_monitor()
  81. res = dev[0].request("WPS_NFC_TAG_READ " + conf)
  82. if "FAIL" in res:
  83. raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
  84. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  85. if ev is None:
  86. raise Exception("Association with the AP timed out")
  87. check_wpa2_connection(dev[0], apdev[0], ssid, mixed=True)
  88. def test_nfc_wps_password_token_sta_init(dev, apdev):
  89. """Initial AP configuration with first WPS NFC Enrollee"""
  90. ssid = "test-wps-nfc-pw-token-init"
  91. hostapd.add_ap(apdev[0]['ifname'],
  92. { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
  93. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  94. logger.info("WPS provisioning step using password token from station")
  95. pw = dev[0].request("WPS_NFC_TOKEN NDEF").rstrip()
  96. if "FAIL" in pw:
  97. raise Exception("Failed to generate password token")
  98. res = hapd.request("WPS_NFC_TAG_READ " + pw)
  99. if "FAIL" in res:
  100. raise Exception("Failed to provide NFC tag contents to hostapd")
  101. dev[0].dump_monitor()
  102. res = dev[0].request("WPS_NFC")
  103. if "FAIL" in res:
  104. raise Exception("Failed to start Enrollee using NFC password token")
  105. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  106. if ev is None:
  107. raise Exception("Association with the AP timed out")
  108. check_wpa2_connection(dev[0], apdev[0], ssid, mixed=True)
  109. def test_nfc_wps_password_token_ap(dev, apdev):
  110. """WPS registrar configuring an AP using AP password token"""
  111. ssid = "test-wps-nfc-pw-token-init"
  112. hostapd.add_ap(apdev[0]['ifname'],
  113. { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
  114. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  115. logger.info("WPS configuration step")
  116. pw = hapd.request("WPS_NFC_TOKEN NDEF").rstrip()
  117. if "FAIL" in pw:
  118. raise Exception("Failed to generate password token")
  119. res = hapd.request("WPS_NFC_TOKEN enable")
  120. if "FAIL" in pw:
  121. raise Exception("Failed to enable AP password token")
  122. res = dev[0].request("WPS_NFC_TAG_READ " + pw)
  123. if "FAIL" in res:
  124. raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
  125. dev[0].dump_monitor()
  126. new_ssid = "test-wps-nfc-pw-token-new-ssid"
  127. new_passphrase = "1234567890"
  128. res = dev[0].request("WPS_REG " + apdev[0]['bssid'] + " nfc-pw " + new_ssid.encode("hex") + " WPA2PSK CCMP " + new_passphrase.encode("hex"))
  129. if "FAIL" in res:
  130. raise Exception("Failed to start Registrar using NFC password token")
  131. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  132. if ev is None:
  133. raise Exception("Association with the AP timed out")
  134. check_wpa2_connection(dev[0], apdev[0], new_ssid, mixed=True)
  135. if "FAIL" in hapd.request("WPS_NFC_TOKEN disable"):
  136. raise Exception("Failed to disable AP password token")
  137. if "FAIL" in hapd.request("WPS_NFC_TOKEN WPS"):
  138. raise Exception("Unexpected WPS_NFC_TOKEN WPS failure")
  139. def test_nfc_wps_handover_init(dev, apdev):
  140. """Connect to WPS AP with NFC connection handover and move to configured state"""
  141. dev[0].request("SET ignore_old_scan_res 1")
  142. ssid = "test-wps-nfc-handover-init"
  143. hostapd.add_ap(apdev[0]['ifname'],
  144. { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
  145. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  146. logger.info("NFC connection handover")
  147. req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  148. if "FAIL" in req:
  149. raise Exception("Failed to generate NFC connection handover request")
  150. sel = hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
  151. if "FAIL" in sel:
  152. raise Exception("Failed to generate NFC connection handover select")
  153. res = hapd.request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  154. if "FAIL" in res:
  155. raise Exception("Failed to report NFC connection handover to to hostapd")
  156. dev[0].dump_monitor()
  157. res = dev[0].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  158. if "FAIL" in res:
  159. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  160. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  161. if ev is None:
  162. raise Exception("Association with the AP timed out")
  163. check_wpa2_connection(dev[0], apdev[0], ssid, mixed=True)
  164. def test_nfc_wps_handover_errors(dev, apdev):
  165. """WPS AP NFC handover report error cases"""
  166. ssid = "test-wps-nfc-handover"
  167. hostapd.add_ap(apdev[0]['ifname'],
  168. { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
  169. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  170. sel = hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
  171. if "FAIL" in sel:
  172. raise Exception("Failed to generate NFC connection handover select")
  173. if "FAIL" not in hapd.request("NFC_REPORT_HANDOVER "):
  174. raise Exception("Unexpected handover report success")
  175. if "FAIL" not in hapd.request("NFC_REPORT_HANDOVER RESP"):
  176. raise Exception("Unexpected handover report success")
  177. if "FAIL" not in hapd.request("NFC_REPORT_HANDOVER RESP WPS"):
  178. raise Exception("Unexpected handover report success")
  179. if "FAIL" not in hapd.request("NFC_REPORT_HANDOVER RESP WPS 001122"):
  180. raise Exception("Unexpected handover report success")
  181. if "FAIL" not in hapd.request("NFC_REPORT_HANDOVER RESP WPS 001122 00"):
  182. raise Exception("Unexpected handover report success")
  183. if "FAIL" not in hapd.request("NFC_REPORT_HANDOVER RESP WPS 0 00"):
  184. raise Exception("Unexpected handover report success")
  185. if "FAIL" not in hapd.request("NFC_REPORT_HANDOVER RESP WPS 001122 0"):
  186. raise Exception("Unexpected handover report success")
  187. if "FAIL" not in hapd.request("NFC_REPORT_HANDOVER RESP WPS 00q122 001122"):
  188. raise Exception("Unexpected handover report success")
  189. if "FAIL" not in hapd.request("NFC_REPORT_HANDOVER RESP WPS 001122 001q22"):
  190. raise Exception("Unexpected handover report success")
  191. if "FAIL" not in hapd.request("NFC_REPORT_HANDOVER RESP FOO 001122 00"):
  192. raise Exception("Unexpected handover report success")
  193. def test_nfc_wps_handover(dev, apdev):
  194. """Connect to WPS AP with NFC connection handover"""
  195. ssid = "test-wps-nfc-handover"
  196. params = ap_wps_params(ssid)
  197. hostapd.add_ap(apdev[0]['ifname'], params)
  198. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  199. logger.info("NFC connection handover")
  200. req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  201. if "FAIL" in req:
  202. raise Exception("Failed to generate NFC connection handover request")
  203. sel = hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
  204. if "FAIL" in sel:
  205. raise Exception("Failed to generate NFC connection handover select")
  206. res = hapd.request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  207. if "FAIL" in res:
  208. raise Exception("Failed to report NFC connection handover to to hostapd")
  209. dev[0].dump_monitor()
  210. res = dev[0].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  211. if "FAIL" in res:
  212. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  213. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  214. if ev is None:
  215. raise Exception("Association with the AP timed out")
  216. check_wpa2_connection(dev[0], apdev[0], ssid)
  217. def test_nfc_wps_handover_with_pw_token_set(dev, apdev):
  218. """Connect to WPS AP with NFC connection handover (wps_nfc_* set)"""
  219. ssid = "test-wps-nfc-handover2"
  220. params = ap_wps_params(ssid)
  221. hostapd.add_ap(apdev[0]['ifname'], params)
  222. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  223. # enable a password token (which won't be used in this test case)
  224. pw = hapd.request("WPS_NFC_TOKEN NDEF").rstrip()
  225. if "FAIL" in pw:
  226. raise Exception("Failed to generate password token")
  227. res = hapd.request("WPS_NFC_TOKEN enable")
  228. if "FAIL" in pw:
  229. raise Exception("Failed to enable AP password token")
  230. logger.info("NFC connection handover")
  231. req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  232. if "FAIL" in req:
  233. raise Exception("Failed to generate NFC connection handover request")
  234. sel = hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
  235. if "FAIL" in sel:
  236. raise Exception("Failed to generate NFC connection handover select")
  237. res = hapd.request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  238. if "FAIL" in res:
  239. raise Exception("Failed to report NFC connection handover to to hostapd")
  240. dev[0].dump_monitor()
  241. res = dev[0].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  242. if "FAIL" in res:
  243. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  244. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  245. if ev is None:
  246. raise Exception("Association with the AP timed out")
  247. check_wpa2_connection(dev[0], apdev[0], ssid)
  248. def test_nfc_wps_handover_pk_hash_mismatch_sta(dev, apdev):
  249. """WPS NFC connection handover with invalid pkhash from station (negative)"""
  250. ssid = "wps-nfc-handover-pkhash-sta"
  251. if "FAIL" in dev[0].request("SET wps_corrupt_pkhash 1"):
  252. raise Exception("Could not enable wps_corrupt_pkhash")
  253. params = ap_wps_params(ssid)
  254. hostapd.add_ap(apdev[0]['ifname'], params)
  255. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  256. logger.info("NFC connection handover")
  257. req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  258. if "FAIL" in req:
  259. raise Exception("Failed to generate NFC connection handover request")
  260. sel = hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
  261. if "FAIL" in sel:
  262. raise Exception("Failed to generate NFC connection handover select")
  263. res = hapd.request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  264. if "FAIL" in res:
  265. raise Exception("Failed to report NFC connection handover to to hostapd")
  266. dev[0].dump_monitor()
  267. res = dev[0].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  268. if "FAIL" in res:
  269. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  270. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", "WPS-FAIL"], timeout=15)
  271. if ev is None:
  272. raise Exception("Timed out")
  273. if "WPS-FAIL" not in ev:
  274. raise Exception("Public key hash mismatch not detected")
  275. def test_nfc_wps_handover_pk_hash_mismatch_ap(dev, apdev):
  276. """WPS NFC connection handover with invalid pkhash from AP (negative)"""
  277. ssid = "wps-nfc-handover-pkhash-ap"
  278. params = ap_wps_params(ssid)
  279. hostapd.add_ap(apdev[0]['ifname'], params)
  280. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  281. if "FAIL" in hapd.request("SET wps_corrupt_pkhash 1"):
  282. raise Exception("Could not enable wps_corrupt_pkhash")
  283. logger.info("NFC connection handover")
  284. req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  285. if "FAIL" in req:
  286. raise Exception("Failed to generate NFC connection handover request")
  287. sel = hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
  288. if "FAIL" in sel:
  289. raise Exception("Failed to generate NFC connection handover select")
  290. res = hapd.request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  291. if "FAIL" in res:
  292. raise Exception("Failed to report NFC connection handover to to hostapd")
  293. dev[0].dump_monitor()
  294. res = dev[0].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  295. if "FAIL" in res:
  296. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  297. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", "WPS-FAIL"], timeout=15)
  298. if ev is None:
  299. raise Exception("Timed out")
  300. if "WPS-FAIL" not in ev:
  301. raise Exception("Public key hash mismatch not detected")
  302. def start_ap_er(er, ap, ssid):
  303. ap_pin = "12345670"
  304. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  305. hostapd.add_ap(ap['ifname'],
  306. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  307. "wpa_passphrase": "12345678", "wpa": "2",
  308. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  309. "device_name": "Wireless AP", "manufacturer": "Company",
  310. "model_name": "WAP", "model_number": "123",
  311. "serial_number": "12345", "device_type": "6-0050F204-1",
  312. "os_version": "01020300",
  313. "config_methods": "label push_button",
  314. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
  315. logger.info("Learn AP configuration")
  316. er.dump_monitor()
  317. er.request("SET ignore_old_scan_res 1")
  318. er.wps_reg(ap['bssid'], ap_pin)
  319. logger.info("Start ER")
  320. er.request("WPS_ER_STOP")
  321. time.sleep(1)
  322. er.request("WPS_ER_START ifname=lo")
  323. ev = er.wait_event(["WPS-ER-AP-ADD"], timeout=15)
  324. if ev is None:
  325. raise Exception("AP discovery timed out")
  326. if ap_uuid not in ev:
  327. raise Exception("Expected AP UUID not found")
  328. logger.info("Use learned network configuration on ER")
  329. er.request("WPS_ER_SET_CONFIG " + ap_uuid + " 0")
  330. def test_nfc_wps_er_pw_token(dev, apdev):
  331. """WPS NFC password token from Enrollee to ER"""
  332. ssid = "wps-nfc-er-pw-token"
  333. start_ap_er(dev[0], apdev[0], ssid)
  334. logger.info("WPS provisioning step using password token from station")
  335. dev[1].request("SET ignore_old_scan_res 1")
  336. pw = dev[1].request("WPS_NFC_TOKEN NDEF").rstrip()
  337. if "FAIL" in pw:
  338. raise Exception("Failed to generate password token")
  339. res = dev[0].request("WPS_NFC_TAG_READ " + pw)
  340. if "FAIL" in res:
  341. raise Exception("Failed to provide NFC tag contents to WPS ER")
  342. dev[0].dump_monitor()
  343. res = dev[1].request("WPS_NFC")
  344. if "FAIL" in res:
  345. raise Exception("Failed to start Enrollee using NFC password token")
  346. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
  347. if ev is None:
  348. raise Exception("WPS ER did not report success")
  349. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  350. if ev is None:
  351. raise Exception("Association with the AP timed out")
  352. check_wpa2_connection(dev[1], apdev[0], ssid)
  353. def test_nfc_wps_er_config_token(dev, apdev):
  354. """WPS NFC configuration token from ER to Enrollee"""
  355. ssid = "wps-nfc-er-config-token"
  356. start_ap_er(dev[0], apdev[0], ssid)
  357. logger.info("WPS provisioning step using configuration token from ER")
  358. conf = dev[0].request("WPS_ER_NFC_CONFIG_TOKEN NDEF " + apdev[0]['bssid']).rstrip()
  359. if "FAIL" in conf:
  360. raise Exception("Failed to generate configugration token")
  361. dev[1].request("SET ignore_old_scan_res 1")
  362. res = dev[1].request("WPS_NFC_TAG_READ " + conf)
  363. if "FAIL" in res:
  364. raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
  365. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  366. if ev is None:
  367. raise Exception("Association with the AP timed out")
  368. check_wpa2_connection(dev[1], apdev[0], ssid)
  369. def test_nfc_wps_er_handover(dev, apdev):
  370. """WPS NFC connection handover between Enrollee and ER"""
  371. ssid = "wps-nfc-er-handover"
  372. start_ap_er(dev[0], apdev[0], ssid)
  373. logger.info("WPS provisioning step using connection handover")
  374. req = dev[1].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  375. if "FAIL" in req:
  376. raise Exception("Failed to generate NFC connection handover request")
  377. sel = dev[0].request("NFC_GET_HANDOVER_SEL NDEF WPS-CR " + apdev[0]['bssid']).rstrip()
  378. if "FAIL" in sel:
  379. raise Exception("Failed to generate NFC connection handover select")
  380. res = dev[0].request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  381. if "FAIL" in res:
  382. raise Exception("Failed to report NFC connection handover to to hostapd")
  383. dev[1].dump_monitor()
  384. res = dev[1].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  385. if "FAIL" in res:
  386. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  387. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  388. if ev is None:
  389. raise Exception("Association with the AP timed out")
  390. check_wpa2_connection(dev[1], apdev[0], ssid)
  391. def test_nfc_wps_er_handover_pk_hash_mismatch_sta(dev, apdev):
  392. """WPS NFC connection handover with invalid pkhash from station to ER (negative)"""
  393. ssid = "wps-nfc-er-handover-pkhash-sta"
  394. start_ap_er(dev[0], apdev[0], ssid)
  395. logger.info("WPS provisioning step using connection handover")
  396. if "FAIL" in dev[1].request("SET wps_corrupt_pkhash 1"):
  397. raise Exception("Could not enable wps_corrupt_pkhash")
  398. dev[1].request("SET ignore_old_scan_res 1")
  399. req = dev[1].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  400. if "FAIL" in req:
  401. raise Exception("Failed to generate NFC connection handover request")
  402. sel = dev[0].request("NFC_GET_HANDOVER_SEL NDEF WPS-CR " + apdev[0]['bssid']).rstrip()
  403. if "FAIL" in sel:
  404. raise Exception("Failed to generate NFC connection handover select")
  405. res = dev[0].request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  406. if "FAIL" in res:
  407. raise Exception("Failed to report NFC connection handover to to hostapd")
  408. dev[1].dump_monitor()
  409. res = dev[1].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  410. if "FAIL" in res:
  411. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  412. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED", "WPS-FAIL"], timeout=15)
  413. if ev is None:
  414. raise Exception("Timed out")
  415. if "WPS-FAIL" not in ev:
  416. raise Exception("Public key hash mismatch not detected")
  417. def test_nfc_wps_er_handover_pk_hash_mismatch_er(dev, apdev):
  418. """WPS NFC connection handover with invalid pkhash from ER to station (negative)"""
  419. ssid = "wps-nfc-er-handover-pkhash-er"
  420. start_ap_er(dev[0], apdev[0], ssid)
  421. logger.info("WPS provisioning step using connection handover")
  422. if "FAIL" in dev[0].request("SET wps_corrupt_pkhash 1"):
  423. raise Exception("Could not enable wps_corrupt_pkhash")
  424. dev[1].request("SET ignore_old_scan_res 1")
  425. req = dev[1].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  426. if "FAIL" in req:
  427. raise Exception("Failed to generate NFC connection handover request")
  428. sel = dev[0].request("NFC_GET_HANDOVER_SEL NDEF WPS-CR " + apdev[0]['bssid']).rstrip()
  429. if "FAIL" in sel:
  430. raise Exception("Failed to generate NFC connection handover select")
  431. res = dev[0].request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  432. if "FAIL" in res:
  433. raise Exception("Failed to report NFC connection handover to to hostapd")
  434. dev[1].dump_monitor()
  435. res = dev[1].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  436. if "FAIL" in res:
  437. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  438. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED", "WPS-FAIL"], timeout=15)
  439. if ev is None:
  440. raise Exception("Timed out")
  441. if "WPS-FAIL" not in ev:
  442. raise Exception("Public key hash mismatch not detected")