test_nfc_wps.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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. def test_nfc_wps_handover_init(dev, apdev):
  136. """Connect to WPS AP with NFC connection handover and move to configured state"""
  137. dev[0].request("SET ignore_old_scan_res 1")
  138. ssid = "test-wps-nfc-handover-init"
  139. hostapd.add_ap(apdev[0]['ifname'],
  140. { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
  141. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  142. logger.info("NFC connection handover")
  143. req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  144. if "FAIL" in req:
  145. raise Exception("Failed to generate NFC connection handover request")
  146. sel = hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
  147. if "FAIL" in sel:
  148. raise Exception("Failed to generate NFC connection handover select")
  149. res = hapd.request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  150. if "FAIL" in res:
  151. raise Exception("Failed to report NFC connection handover to to hostapd")
  152. dev[0].dump_monitor()
  153. res = dev[0].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  154. if "FAIL" in res:
  155. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  156. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  157. if ev is None:
  158. raise Exception("Association with the AP timed out")
  159. check_wpa2_connection(dev[0], apdev[0], ssid, mixed=True)
  160. def test_nfc_wps_handover(dev, apdev):
  161. """Connect to WPS AP with NFC connection handover"""
  162. ssid = "test-wps-nfc-handover"
  163. params = ap_wps_params(ssid)
  164. hostapd.add_ap(apdev[0]['ifname'], params)
  165. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  166. logger.info("NFC connection handover")
  167. req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  168. if "FAIL" in req:
  169. raise Exception("Failed to generate NFC connection handover request")
  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. res = hapd.request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  174. if "FAIL" in res:
  175. raise Exception("Failed to report NFC connection handover to to hostapd")
  176. dev[0].dump_monitor()
  177. res = dev[0].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  178. if "FAIL" in res:
  179. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  180. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  181. if ev is None:
  182. raise Exception("Association with the AP timed out")
  183. check_wpa2_connection(dev[0], apdev[0], ssid)
  184. def test_nfc_wps_handover_with_pw_token_set(dev, apdev):
  185. """Connect to WPS AP with NFC connection handover (wps_nfc_* set)"""
  186. ssid = "test-wps-nfc-handover2"
  187. params = ap_wps_params(ssid)
  188. hostapd.add_ap(apdev[0]['ifname'], params)
  189. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  190. # enable a password token (which won't be used in this test case)
  191. pw = hapd.request("WPS_NFC_TOKEN NDEF").rstrip()
  192. if "FAIL" in pw:
  193. raise Exception("Failed to generate password token")
  194. res = hapd.request("WPS_NFC_TOKEN enable")
  195. if "FAIL" in pw:
  196. raise Exception("Failed to enable AP password token")
  197. logger.info("NFC connection handover")
  198. req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  199. if "FAIL" in req:
  200. raise Exception("Failed to generate NFC connection handover request")
  201. sel = hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
  202. if "FAIL" in sel:
  203. raise Exception("Failed to generate NFC connection handover select")
  204. res = hapd.request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  205. if "FAIL" in res:
  206. raise Exception("Failed to report NFC connection handover to to hostapd")
  207. dev[0].dump_monitor()
  208. res = dev[0].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  209. if "FAIL" in res:
  210. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  211. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  212. if ev is None:
  213. raise Exception("Association with the AP timed out")
  214. check_wpa2_connection(dev[0], apdev[0], ssid)
  215. def test_nfc_wps_handover_pk_hash_mismatch_sta(dev, apdev):
  216. """WPS NFC connection handover with invalid pkhash from station (negative)"""
  217. ssid = "wps-nfc-handover-pkhash-sta"
  218. if "FAIL" in dev[0].request("SET wps_corrupt_pkhash 1"):
  219. raise Exception("Could not enable wps_corrupt_pkhash")
  220. params = ap_wps_params(ssid)
  221. hostapd.add_ap(apdev[0]['ifname'], params)
  222. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  223. logger.info("NFC connection handover")
  224. req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  225. if "FAIL" in req:
  226. raise Exception("Failed to generate NFC connection handover request")
  227. sel = hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
  228. if "FAIL" in sel:
  229. raise Exception("Failed to generate NFC connection handover select")
  230. res = hapd.request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  231. if "FAIL" in res:
  232. raise Exception("Failed to report NFC connection handover to to hostapd")
  233. dev[0].dump_monitor()
  234. res = dev[0].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  235. if "FAIL" in res:
  236. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  237. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", "WPS-FAIL"], timeout=15)
  238. if ev is None:
  239. raise Exception("Timed out")
  240. if "WPS-FAIL" not in ev:
  241. raise Exception("Public key hash mismatch not detected")
  242. def test_nfc_wps_handover_pk_hash_mismatch_ap(dev, apdev):
  243. """WPS NFC connection handover with invalid pkhash from AP (negative)"""
  244. ssid = "wps-nfc-handover-pkhash-ap"
  245. params = ap_wps_params(ssid)
  246. hostapd.add_ap(apdev[0]['ifname'], params)
  247. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  248. if "FAIL" in hapd.request("SET wps_corrupt_pkhash 1"):
  249. raise Exception("Could not enable wps_corrupt_pkhash")
  250. logger.info("NFC connection handover")
  251. req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  252. if "FAIL" in req:
  253. raise Exception("Failed to generate NFC connection handover request")
  254. sel = hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
  255. if "FAIL" in sel:
  256. raise Exception("Failed to generate NFC connection handover select")
  257. res = hapd.request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  258. if "FAIL" in res:
  259. raise Exception("Failed to report NFC connection handover to to hostapd")
  260. dev[0].dump_monitor()
  261. res = dev[0].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  262. if "FAIL" in res:
  263. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  264. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", "WPS-FAIL"], timeout=15)
  265. if ev is None:
  266. raise Exception("Timed out")
  267. if "WPS-FAIL" not in ev:
  268. raise Exception("Public key hash mismatch not detected")
  269. def start_ap_er(er, ap, ssid):
  270. ap_pin = "12345670"
  271. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  272. hostapd.add_ap(ap['ifname'],
  273. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  274. "wpa_passphrase": "12345678", "wpa": "2",
  275. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  276. "device_name": "Wireless AP", "manufacturer": "Company",
  277. "model_name": "WAP", "model_number": "123",
  278. "serial_number": "12345", "device_type": "6-0050F204-1",
  279. "os_version": "01020300",
  280. "config_methods": "label push_button",
  281. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
  282. logger.info("Learn AP configuration")
  283. er.dump_monitor()
  284. er.request("SET ignore_old_scan_res 1")
  285. er.wps_reg(ap['bssid'], ap_pin)
  286. logger.info("Start ER")
  287. er.request("WPS_ER_STOP")
  288. time.sleep(1)
  289. er.request("WPS_ER_START ifname=lo")
  290. ev = er.wait_event(["WPS-ER-AP-ADD"], timeout=15)
  291. if ev is None:
  292. raise Exception("AP discovery timed out")
  293. if ap_uuid not in ev:
  294. raise Exception("Expected AP UUID not found")
  295. logger.info("Use learned network configuration on ER")
  296. er.request("WPS_ER_SET_CONFIG " + ap_uuid + " 0")
  297. def test_nfc_wps_er_pw_token(dev, apdev):
  298. """WPS NFC password token from Enrollee to ER"""
  299. ssid = "wps-nfc-er-pw-token"
  300. start_ap_er(dev[0], apdev[0], ssid)
  301. logger.info("WPS provisioning step using password token from station")
  302. dev[1].request("SET ignore_old_scan_res 1")
  303. pw = dev[1].request("WPS_NFC_TOKEN NDEF").rstrip()
  304. if "FAIL" in pw:
  305. raise Exception("Failed to generate password token")
  306. res = dev[0].request("WPS_NFC_TAG_READ " + pw)
  307. if "FAIL" in res:
  308. raise Exception("Failed to provide NFC tag contents to WPS ER")
  309. dev[0].dump_monitor()
  310. res = dev[1].request("WPS_NFC")
  311. if "FAIL" in res:
  312. raise Exception("Failed to start Enrollee using NFC password token")
  313. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
  314. if ev is None:
  315. raise Exception("WPS ER did not report success")
  316. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  317. if ev is None:
  318. raise Exception("Association with the AP timed out")
  319. check_wpa2_connection(dev[1], apdev[0], ssid)
  320. def test_nfc_wps_er_config_token(dev, apdev):
  321. """WPS NFC configuration token from ER to Enrollee"""
  322. ssid = "wps-nfc-er-config-token"
  323. start_ap_er(dev[0], apdev[0], ssid)
  324. logger.info("WPS provisioning step using configuration token from ER")
  325. conf = dev[0].request("WPS_ER_NFC_CONFIG_TOKEN NDEF " + apdev[0]['bssid']).rstrip()
  326. if "FAIL" in conf:
  327. raise Exception("Failed to generate configugration token")
  328. dev[1].request("SET ignore_old_scan_res 1")
  329. res = dev[1].request("WPS_NFC_TAG_READ " + conf)
  330. if "FAIL" in res:
  331. raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
  332. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  333. if ev is None:
  334. raise Exception("Association with the AP timed out")
  335. check_wpa2_connection(dev[1], apdev[0], ssid)
  336. def test_nfc_wps_er_handover(dev, apdev):
  337. """WPS NFC connection handover between Enrollee and ER"""
  338. ssid = "wps-nfc-er-handover"
  339. start_ap_er(dev[0], apdev[0], ssid)
  340. logger.info("WPS provisioning step using connection handover")
  341. req = dev[1].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  342. if "FAIL" in req:
  343. raise Exception("Failed to generate NFC connection handover request")
  344. sel = dev[0].request("NFC_GET_HANDOVER_SEL NDEF WPS-CR " + apdev[0]['bssid']).rstrip()
  345. if "FAIL" in sel:
  346. raise Exception("Failed to generate NFC connection handover select")
  347. res = dev[0].request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  348. if "FAIL" in res:
  349. raise Exception("Failed to report NFC connection handover to to hostapd")
  350. dev[1].dump_monitor()
  351. res = dev[1].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  352. if "FAIL" in res:
  353. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  354. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  355. if ev is None:
  356. raise Exception("Association with the AP timed out")
  357. check_wpa2_connection(dev[1], apdev[0], ssid)
  358. def test_nfc_wps_er_handover_pk_hash_mismatch_sta(dev, apdev):
  359. """WPS NFC connection handover with invalid pkhash from station to ER (negative)"""
  360. ssid = "wps-nfc-er-handover-pkhash-sta"
  361. start_ap_er(dev[0], apdev[0], ssid)
  362. logger.info("WPS provisioning step using connection handover")
  363. if "FAIL" in dev[1].request("SET wps_corrupt_pkhash 1"):
  364. raise Exception("Could not enable wps_corrupt_pkhash")
  365. dev[1].request("SET ignore_old_scan_res 1")
  366. req = dev[1].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  367. if "FAIL" in req:
  368. raise Exception("Failed to generate NFC connection handover request")
  369. sel = dev[0].request("NFC_GET_HANDOVER_SEL NDEF WPS-CR " + apdev[0]['bssid']).rstrip()
  370. if "FAIL" in sel:
  371. raise Exception("Failed to generate NFC connection handover select")
  372. res = dev[0].request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  373. if "FAIL" in res:
  374. raise Exception("Failed to report NFC connection handover to to hostapd")
  375. dev[1].dump_monitor()
  376. res = dev[1].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  377. if "FAIL" in res:
  378. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  379. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED", "WPS-FAIL"], timeout=15)
  380. if ev is None:
  381. raise Exception("Timed out")
  382. if "WPS-FAIL" not in ev:
  383. raise Exception("Public key hash mismatch not detected")
  384. def test_nfc_wps_er_handover_pk_hash_mismatch_er(dev, apdev):
  385. """WPS NFC connection handover with invalid pkhash from ER to station (negative)"""
  386. ssid = "wps-nfc-er-handover-pkhash-er"
  387. start_ap_er(dev[0], apdev[0], ssid)
  388. logger.info("WPS provisioning step using connection handover")
  389. if "FAIL" in dev[0].request("SET wps_corrupt_pkhash 1"):
  390. raise Exception("Could not enable wps_corrupt_pkhash")
  391. dev[1].request("SET ignore_old_scan_res 1")
  392. req = dev[1].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  393. if "FAIL" in req:
  394. raise Exception("Failed to generate NFC connection handover request")
  395. sel = dev[0].request("NFC_GET_HANDOVER_SEL NDEF WPS-CR " + apdev[0]['bssid']).rstrip()
  396. if "FAIL" in sel:
  397. raise Exception("Failed to generate NFC connection handover select")
  398. res = dev[0].request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  399. if "FAIL" in res:
  400. raise Exception("Failed to report NFC connection handover to to hostapd")
  401. dev[1].dump_monitor()
  402. res = dev[1].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  403. if "FAIL" in res:
  404. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  405. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED", "WPS-FAIL"], timeout=15)
  406. if ev is None:
  407. raise Exception("Timed out")
  408. if "WPS-FAIL" not in ev:
  409. raise Exception("Public key hash mismatch not detected")