test_nfc_wps.py 20 KB

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