test_nfc_wps.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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, hapd, 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, hapd)
  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. wps = dev[0].request("WPS_NFC_TOKEN WPS").rstrip()
  39. if "FAIL" in wps:
  40. raise Exception("Failed to generate password token (WPS only)")
  41. pw = dev[0].request("WPS_NFC_TOKEN NDEF").rstrip()
  42. if "FAIL" in pw:
  43. raise Exception("Failed to generate password token")
  44. res = hapd.request("WPS_NFC_TAG_READ " + pw)
  45. if "FAIL" in res:
  46. raise Exception("Failed to provide NFC tag contents to hostapd")
  47. dev[0].dump_monitor()
  48. res = dev[0].request("WPS_NFC")
  49. if "FAIL" in res:
  50. raise Exception("Failed to start Enrollee using NFC password token")
  51. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  52. if ev is None:
  53. raise Exception("Association with the AP timed out")
  54. check_wpa2_connection(dev[0], apdev[0], hapd, ssid)
  55. def test_nfc_wps_config_token(dev, apdev):
  56. """NFC tag with configuration token from AP"""
  57. ssid = "test-wps-nfc-conf-token"
  58. params = ap_wps_params(ssid)
  59. hostapd.add_ap(apdev[0]['ifname'], params)
  60. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  61. logger.info("NFC configuration token from AP to station")
  62. conf = hapd.request("WPS_NFC_CONFIG_TOKEN NDEF").rstrip()
  63. if "FAIL" in conf:
  64. raise Exception("Failed to generate configuration token")
  65. dev[0].dump_monitor()
  66. res = dev[0].request("WPS_NFC_TAG_READ " + conf)
  67. if "FAIL" in res:
  68. raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
  69. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  70. if ev is None:
  71. raise Exception("Association with the AP timed out")
  72. check_wpa2_connection(dev[0], apdev[0], hapd, ssid)
  73. def test_nfc_wps_config_token_init(dev, apdev):
  74. """NFC tag with configuration token from AP with auto configuration"""
  75. ssid = "test-wps-nfc-conf-token-init"
  76. hostapd.add_ap(apdev[0]['ifname'],
  77. { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
  78. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  79. logger.info("NFC configuration token from AP to station")
  80. conf = hapd.request("WPS_NFC_CONFIG_TOKEN NDEF").rstrip()
  81. if "FAIL" in conf:
  82. raise Exception("Failed to generate configuration token")
  83. dev[0].dump_monitor()
  84. res = dev[0].request("WPS_NFC_TAG_READ " + conf)
  85. if "FAIL" in res:
  86. raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
  87. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  88. if ev is None:
  89. raise Exception("Association with the AP timed out")
  90. check_wpa2_connection(dev[0], apdev[0], hapd, ssid, mixed=True)
  91. def test_nfc_wps_password_token_sta_init(dev, apdev):
  92. """Initial AP configuration with first WPS NFC Enrollee"""
  93. ssid = "test-wps-nfc-pw-token-init"
  94. hostapd.add_ap(apdev[0]['ifname'],
  95. { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
  96. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  97. logger.info("WPS provisioning step using password token from station")
  98. pw = dev[0].request("WPS_NFC_TOKEN NDEF").rstrip()
  99. if "FAIL" in pw:
  100. raise Exception("Failed to generate password token")
  101. res = hapd.request("WPS_NFC_TAG_READ " + pw)
  102. if "FAIL" in res:
  103. raise Exception("Failed to provide NFC tag contents to hostapd")
  104. dev[0].dump_monitor()
  105. res = dev[0].request("WPS_NFC")
  106. if "FAIL" in res:
  107. raise Exception("Failed to start Enrollee using NFC password token")
  108. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  109. if ev is None:
  110. raise Exception("Association with the AP timed out")
  111. check_wpa2_connection(dev[0], apdev[0], hapd, ssid, mixed=True)
  112. def test_nfc_wps_password_token_ap(dev, apdev):
  113. """WPS registrar configuring an AP using AP password token"""
  114. ssid = "test-wps-nfc-pw-token-init"
  115. hostapd.add_ap(apdev[0]['ifname'],
  116. { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
  117. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  118. logger.info("WPS configuration step")
  119. pw = hapd.request("WPS_NFC_TOKEN NDEF").rstrip()
  120. if "FAIL" in pw:
  121. raise Exception("Failed to generate password token")
  122. res = hapd.request("WPS_NFC_TOKEN enable")
  123. if "FAIL" in pw:
  124. raise Exception("Failed to enable AP password token")
  125. res = dev[0].request("WPS_NFC_TAG_READ " + pw)
  126. if "FAIL" in res:
  127. raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
  128. dev[0].dump_monitor()
  129. new_ssid = "test-wps-nfc-pw-token-new-ssid"
  130. new_passphrase = "1234567890"
  131. res = dev[0].request("WPS_REG " + apdev[0]['bssid'] + " nfc-pw " + new_ssid.encode("hex") + " WPA2PSK CCMP " + new_passphrase.encode("hex"))
  132. if "FAIL" in res:
  133. raise Exception("Failed to start Registrar using NFC password token")
  134. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  135. if ev is None:
  136. raise Exception("Association with the AP timed out")
  137. check_wpa2_connection(dev[0], apdev[0], hapd, new_ssid, mixed=True)
  138. if "FAIL" in hapd.request("WPS_NFC_TOKEN disable"):
  139. raise Exception("Failed to disable AP password token")
  140. if "FAIL" in hapd.request("WPS_NFC_TOKEN WPS"):
  141. raise Exception("Unexpected WPS_NFC_TOKEN WPS failure")
  142. def test_nfc_wps_handover_init(dev, apdev):
  143. """Connect to WPS AP with NFC connection handover and move to configured state"""
  144. dev[0].request("SET ignore_old_scan_res 1")
  145. ssid = "test-wps-nfc-handover-init"
  146. hostapd.add_ap(apdev[0]['ifname'],
  147. { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
  148. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  149. logger.info("NFC connection handover")
  150. req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  151. if "FAIL" in req:
  152. raise Exception("Failed to generate NFC connection handover request")
  153. sel = hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
  154. if "FAIL" in sel:
  155. raise Exception("Failed to generate NFC connection handover select")
  156. res = hapd.request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  157. if "FAIL" in res:
  158. raise Exception("Failed to report NFC connection handover to to hostapd")
  159. dev[0].dump_monitor()
  160. res = dev[0].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  161. if "FAIL" in res:
  162. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  163. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  164. if ev is None:
  165. raise Exception("Association with the AP timed out")
  166. check_wpa2_connection(dev[0], apdev[0], hapd, ssid, mixed=True)
  167. def test_nfc_wps_handover_errors(dev, apdev):
  168. """WPS AP NFC handover report error cases"""
  169. ssid = "test-wps-nfc-handover"
  170. hostapd.add_ap(apdev[0]['ifname'],
  171. { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
  172. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  173. sel = hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
  174. if "FAIL" in sel:
  175. raise Exception("Failed to generate NFC connection handover select")
  176. if "FAIL" not in hapd.request("NFC_REPORT_HANDOVER "):
  177. raise Exception("Unexpected handover report success")
  178. if "FAIL" not in hapd.request("NFC_REPORT_HANDOVER RESP"):
  179. raise Exception("Unexpected handover report success")
  180. if "FAIL" not in hapd.request("NFC_REPORT_HANDOVER RESP WPS"):
  181. raise Exception("Unexpected handover report success")
  182. if "FAIL" not in hapd.request("NFC_REPORT_HANDOVER RESP WPS 001122"):
  183. raise Exception("Unexpected handover report success")
  184. if "FAIL" not in hapd.request("NFC_REPORT_HANDOVER RESP WPS 001122 00"):
  185. raise Exception("Unexpected handover report success")
  186. if "FAIL" not in hapd.request("NFC_REPORT_HANDOVER RESP WPS 0 00"):
  187. raise Exception("Unexpected handover report success")
  188. if "FAIL" not in hapd.request("NFC_REPORT_HANDOVER RESP WPS 001122 0"):
  189. raise Exception("Unexpected handover report success")
  190. if "FAIL" not in hapd.request("NFC_REPORT_HANDOVER RESP WPS 00q122 001122"):
  191. raise Exception("Unexpected handover report success")
  192. if "FAIL" not in hapd.request("NFC_REPORT_HANDOVER RESP WPS 001122 001q22"):
  193. raise Exception("Unexpected handover report success")
  194. if "FAIL" not in hapd.request("NFC_REPORT_HANDOVER RESP FOO 001122 00"):
  195. raise Exception("Unexpected handover report success")
  196. def test_nfc_wps_handover(dev, apdev):
  197. """Connect to WPS AP with NFC connection handover"""
  198. ssid = "test-wps-nfc-handover"
  199. params = ap_wps_params(ssid)
  200. hostapd.add_ap(apdev[0]['ifname'], params)
  201. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  202. logger.info("NFC connection handover")
  203. req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  204. if "FAIL" in req:
  205. raise Exception("Failed to generate NFC connection handover request")
  206. sel = hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
  207. if "FAIL" in sel:
  208. raise Exception("Failed to generate NFC connection handover select")
  209. res = hapd.request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  210. if "FAIL" in res:
  211. raise Exception("Failed to report NFC connection handover to to hostapd")
  212. dev[0].dump_monitor()
  213. res = dev[0].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  214. if "FAIL" in res:
  215. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  216. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  217. if ev is None:
  218. raise Exception("Association with the AP timed out")
  219. check_wpa2_connection(dev[0], apdev[0], hapd, ssid)
  220. def test_nfc_wps_handover_5ghz(dev, apdev):
  221. """Connect to WPS AP with NFC connection handover on 5 GHz band"""
  222. try:
  223. ssid = "test-wps-nfc-handover"
  224. params = ap_wps_params(ssid)
  225. params["country_code"] = "FI"
  226. params["hw_mode"] = "a"
  227. params["channel"] = "36"
  228. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  229. logger.info("NFC connection handover")
  230. req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  231. if "FAIL" in req:
  232. raise Exception("Failed to generate NFC connection handover request")
  233. sel = hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
  234. if "FAIL" in sel:
  235. raise Exception("Failed to generate NFC connection handover select")
  236. res = hapd.request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  237. if "FAIL" in res:
  238. raise Exception("Failed to report NFC connection handover to to hostapd")
  239. dev[0].dump_monitor()
  240. res = dev[0].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  241. if "FAIL" in res:
  242. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  243. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
  244. if ev is None:
  245. raise Exception("Association with the AP timed out")
  246. check_wpa2_connection(dev[0], apdev[0], hapd, ssid)
  247. finally:
  248. dev[0].request("DISCONNECT")
  249. if hapd:
  250. hapd.request("DISABLE")
  251. subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
  252. dev[0].flush_scan_cache()
  253. def test_nfc_wps_handover_chan14(dev, apdev):
  254. """Connect to WPS AP with NFC connection handover on channel 14"""
  255. try:
  256. ssid = "test-wps-nfc-handover"
  257. params = ap_wps_params(ssid)
  258. params["country_code"] = "JP"
  259. params["hw_mode"] = "b"
  260. params["channel"] = "14"
  261. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  262. logger.info("NFC connection handover")
  263. req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  264. if "FAIL" in req:
  265. raise Exception("Failed to generate NFC connection handover request")
  266. sel = hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
  267. if "FAIL" in sel:
  268. raise Exception("Failed to generate NFC connection handover select")
  269. res = hapd.request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  270. if "FAIL" in res:
  271. raise Exception("Failed to report NFC connection handover to to hostapd")
  272. dev[0].dump_monitor()
  273. res = dev[0].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  274. if "FAIL" in res:
  275. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  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. check_wpa2_connection(dev[0], apdev[0], hapd, ssid)
  280. finally:
  281. dev[0].request("DISCONNECT")
  282. if hapd:
  283. hapd.request("DISABLE")
  284. subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
  285. dev[0].flush_scan_cache()
  286. def test_nfc_wps_handover_with_pw_token_set(dev, apdev):
  287. """Connect to WPS AP with NFC connection handover (wps_nfc_* set)"""
  288. ssid = "test-wps-nfc-handover2"
  289. params = ap_wps_params(ssid)
  290. hostapd.add_ap(apdev[0]['ifname'], params)
  291. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  292. # enable a password token (which won't be used in this test case)
  293. pw = hapd.request("WPS_NFC_TOKEN NDEF").rstrip()
  294. if "FAIL" in pw:
  295. raise Exception("Failed to generate password token")
  296. res = hapd.request("WPS_NFC_TOKEN enable")
  297. if "FAIL" in pw:
  298. raise Exception("Failed to enable AP password token")
  299. logger.info("NFC connection handover")
  300. req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  301. if "FAIL" in req:
  302. raise Exception("Failed to generate NFC connection handover request")
  303. sel = hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
  304. if "FAIL" in sel:
  305. raise Exception("Failed to generate NFC connection handover select")
  306. res = hapd.request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  307. if "FAIL" in res:
  308. raise Exception("Failed to report NFC connection handover to to hostapd")
  309. dev[0].dump_monitor()
  310. res = dev[0].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  311. if "FAIL" in res:
  312. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  313. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  314. if ev is None:
  315. raise Exception("Association with the AP timed out")
  316. check_wpa2_connection(dev[0], apdev[0], hapd, ssid)
  317. def test_nfc_wps_handover_pk_hash_mismatch_sta(dev, apdev):
  318. """WPS NFC connection handover with invalid pkhash from station (negative)"""
  319. ssid = "wps-nfc-handover-pkhash-sta"
  320. if "FAIL" in dev[0].request("SET wps_corrupt_pkhash 1"):
  321. raise Exception("Could not enable wps_corrupt_pkhash")
  322. params = ap_wps_params(ssid)
  323. hostapd.add_ap(apdev[0]['ifname'], params)
  324. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  325. logger.info("NFC connection handover")
  326. req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  327. if "FAIL" in req:
  328. raise Exception("Failed to generate NFC connection handover request")
  329. sel = hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
  330. if "FAIL" in sel:
  331. raise Exception("Failed to generate NFC connection handover select")
  332. res = hapd.request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  333. if "FAIL" in res:
  334. raise Exception("Failed to report NFC connection handover to to hostapd")
  335. dev[0].dump_monitor()
  336. res = dev[0].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  337. if "FAIL" in res:
  338. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  339. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", "WPS-FAIL"], timeout=15)
  340. if ev is None:
  341. raise Exception("Timed out")
  342. if "WPS-FAIL" not in ev:
  343. raise Exception("Public key hash mismatch not detected")
  344. def test_nfc_wps_handover_pk_hash_mismatch_ap(dev, apdev):
  345. """WPS NFC connection handover with invalid pkhash from AP (negative)"""
  346. ssid = "wps-nfc-handover-pkhash-ap"
  347. params = ap_wps_params(ssid)
  348. hostapd.add_ap(apdev[0]['ifname'], params)
  349. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  350. if "FAIL" in hapd.request("SET wps_corrupt_pkhash 1"):
  351. raise Exception("Could not enable wps_corrupt_pkhash")
  352. logger.info("NFC connection handover")
  353. req = dev[0].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  354. if "FAIL" in req:
  355. raise Exception("Failed to generate NFC connection handover request")
  356. sel = hapd.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR").rstrip()
  357. if "FAIL" in sel:
  358. raise Exception("Failed to generate NFC connection handover select")
  359. res = hapd.request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  360. if "FAIL" in res:
  361. raise Exception("Failed to report NFC connection handover to to hostapd")
  362. dev[0].dump_monitor()
  363. res = dev[0].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  364. if "FAIL" in res:
  365. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  366. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", "WPS-FAIL"], timeout=15)
  367. if ev is None:
  368. raise Exception("Timed out")
  369. if "WPS-FAIL" not in ev:
  370. raise Exception("Public key hash mismatch not detected")
  371. def start_ap_er(er, ap, ssid):
  372. ap_pin = "12345670"
  373. ap_uuid = "27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"
  374. hostapd.add_ap(ap['ifname'],
  375. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  376. "wpa_passphrase": "12345678", "wpa": "2",
  377. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  378. "device_name": "Wireless AP", "manufacturer": "Company",
  379. "model_name": "WAP", "model_number": "123",
  380. "serial_number": "12345", "device_type": "6-0050F204-1",
  381. "os_version": "01020300",
  382. "config_methods": "label push_button",
  383. "ap_pin": ap_pin, "uuid": ap_uuid, "upnp_iface": "lo"})
  384. logger.info("Learn AP configuration")
  385. er.dump_monitor()
  386. er.request("SET ignore_old_scan_res 1")
  387. er.wps_reg(ap['bssid'], ap_pin)
  388. logger.info("Start ER")
  389. er.request("WPS_ER_STOP")
  390. time.sleep(1)
  391. er.request("WPS_ER_START ifname=lo")
  392. ev = er.wait_event(["WPS-ER-AP-ADD"], timeout=15)
  393. if ev is None:
  394. raise Exception("AP discovery timed out")
  395. if ap_uuid not in ev:
  396. raise Exception("Expected AP UUID not found")
  397. logger.info("Use learned network configuration on ER")
  398. er.request("WPS_ER_SET_CONFIG " + ap_uuid + " 0")
  399. def test_nfc_wps_er_pw_token(dev, apdev):
  400. """WPS NFC password token from Enrollee to ER"""
  401. try:
  402. _test_nfc_wps_er_pw_token(dev, apdev)
  403. finally:
  404. dev[0].request("WPS_ER_STOP")
  405. def _test_nfc_wps_er_pw_token(dev, apdev):
  406. ssid = "wps-nfc-er-pw-token"
  407. start_ap_er(dev[0], apdev[0], ssid)
  408. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  409. logger.info("WPS provisioning step using password token from station")
  410. dev[1].request("SET ignore_old_scan_res 1")
  411. pw = dev[1].request("WPS_NFC_TOKEN NDEF").rstrip()
  412. if "FAIL" in pw:
  413. raise Exception("Failed to generate password token")
  414. res = dev[0].request("WPS_NFC_TAG_READ " + pw)
  415. if "FAIL" in res:
  416. raise Exception("Failed to provide NFC tag contents to WPS ER")
  417. dev[0].dump_monitor()
  418. res = dev[1].request("WPS_NFC")
  419. if "FAIL" in res:
  420. raise Exception("Failed to start Enrollee using NFC password token")
  421. ev = dev[0].wait_event(["WPS-SUCCESS"], timeout=15)
  422. if ev is None:
  423. raise Exception("WPS ER did not report success")
  424. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  425. if ev is None:
  426. raise Exception("Association with the AP timed out")
  427. check_wpa2_connection(dev[1], apdev[0], hapd, ssid)
  428. def test_nfc_wps_er_config_token(dev, apdev):
  429. """WPS NFC configuration token from ER to Enrollee"""
  430. try:
  431. _test_nfc_wps_er_config_token(dev, apdev)
  432. finally:
  433. dev[0].request("WPS_ER_STOP")
  434. def _test_nfc_wps_er_config_token(dev, apdev):
  435. ssid = "wps-nfc-er-config-token"
  436. start_ap_er(dev[0], apdev[0], ssid)
  437. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  438. logger.info("WPS provisioning step using configuration token from ER")
  439. wps = dev[0].request("WPS_ER_NFC_CONFIG_TOKEN WPS " + apdev[0]['bssid']).rstrip()
  440. if "FAIL" in wps:
  441. raise Exception("Failed to generate configuration token (WPS format)")
  442. conf = dev[0].request("WPS_ER_NFC_CONFIG_TOKEN NDEF " + apdev[0]['bssid']).rstrip()
  443. if "FAIL" in conf:
  444. raise Exception("Failed to generate configuration token")
  445. dev[1].request("SET ignore_old_scan_res 1")
  446. res = dev[1].request("WPS_NFC_TAG_READ " + conf)
  447. if "FAIL" in res:
  448. raise Exception("Failed to provide NFC tag contents to wpa_supplicant")
  449. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  450. if ev is None:
  451. raise Exception("Association with the AP timed out")
  452. check_wpa2_connection(dev[1], apdev[0], hapd, ssid)
  453. def test_nfc_wps_er_handover(dev, apdev):
  454. """WPS NFC connection handover between Enrollee and ER"""
  455. try:
  456. _test_nfc_wps_er_handover(dev, apdev)
  457. finally:
  458. dev[0].request("WPS_ER_STOP")
  459. def _test_nfc_wps_er_handover(dev, apdev):
  460. ssid = "wps-nfc-er-handover"
  461. start_ap_er(dev[0], apdev[0], ssid)
  462. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  463. logger.info("WPS provisioning step using connection handover")
  464. req = dev[1].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  465. if "FAIL" in req:
  466. raise Exception("Failed to generate NFC connection handover request")
  467. sel = dev[0].request("NFC_GET_HANDOVER_SEL NDEF WPS-CR " + apdev[0]['bssid']).rstrip()
  468. if "FAIL" in sel:
  469. raise Exception("Failed to generate NFC connection handover select")
  470. res = dev[0].request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  471. if "FAIL" in res:
  472. raise Exception("Failed to report NFC connection handover to to hostapd")
  473. dev[1].dump_monitor()
  474. res = dev[1].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  475. if "FAIL" in res:
  476. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  477. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  478. if ev is None:
  479. raise Exception("Association with the AP timed out")
  480. check_wpa2_connection(dev[1], apdev[0], hapd, ssid)
  481. def test_nfc_wps_er_handover_pk_hash_mismatch_sta(dev, apdev):
  482. """WPS NFC connection handover with invalid pkhash from station to ER (negative)"""
  483. try:
  484. _test_nfc_wps_er_handover_pk_hash_mismatch_sta(dev, apdev)
  485. finally:
  486. dev[0].request("WPS_ER_STOP")
  487. def _test_nfc_wps_er_handover_pk_hash_mismatch_sta(dev, apdev):
  488. ssid = "wps-nfc-er-handover-pkhash-sta"
  489. start_ap_er(dev[0], apdev[0], ssid)
  490. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  491. logger.info("WPS provisioning step using connection handover")
  492. if "FAIL" in dev[1].request("SET wps_corrupt_pkhash 1"):
  493. raise Exception("Could not enable wps_corrupt_pkhash")
  494. dev[1].request("SET ignore_old_scan_res 1")
  495. req = dev[1].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  496. if "FAIL" in req:
  497. raise Exception("Failed to generate NFC connection handover request")
  498. sel = dev[0].request("NFC_GET_HANDOVER_SEL NDEF WPS-CR " + apdev[0]['bssid']).rstrip()
  499. if "FAIL" in sel:
  500. raise Exception("Failed to generate NFC connection handover select")
  501. res = dev[0].request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  502. if "FAIL" in res:
  503. raise Exception("Failed to report NFC connection handover to to hostapd")
  504. dev[1].dump_monitor()
  505. res = dev[1].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  506. if "FAIL" in res:
  507. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  508. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED", "WPS-FAIL"], timeout=15)
  509. if ev is None:
  510. raise Exception("Timed out")
  511. if "WPS-FAIL" not in ev:
  512. raise Exception("Public key hash mismatch not detected")
  513. def test_nfc_wps_er_handover_pk_hash_mismatch_er(dev, apdev):
  514. """WPS NFC connection handover with invalid pkhash from ER to station (negative)"""
  515. try:
  516. _test_nfc_wps_er_handover_pk_hash_mismatch_er(dev, apdev)
  517. finally:
  518. dev[0].request("WPS_ER_STOP")
  519. def _test_nfc_wps_er_handover_pk_hash_mismatch_er(dev, apdev):
  520. ssid = "wps-nfc-er-handover-pkhash-er"
  521. start_ap_er(dev[0], apdev[0], ssid)
  522. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  523. logger.info("WPS provisioning step using connection handover")
  524. if "FAIL" in dev[0].request("SET wps_corrupt_pkhash 1"):
  525. raise Exception("Could not enable wps_corrupt_pkhash")
  526. dev[1].request("SET ignore_old_scan_res 1")
  527. req = dev[1].request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip()
  528. if "FAIL" in req:
  529. raise Exception("Failed to generate NFC connection handover request")
  530. sel = dev[0].request("NFC_GET_HANDOVER_SEL NDEF WPS-CR " + apdev[0]['bssid']).rstrip()
  531. if "FAIL" in sel:
  532. raise Exception("Failed to generate NFC connection handover select")
  533. res = dev[0].request("NFC_REPORT_HANDOVER RESP WPS " + req + " " + sel)
  534. if "FAIL" in res:
  535. raise Exception("Failed to report NFC connection handover to to hostapd")
  536. dev[1].dump_monitor()
  537. res = dev[1].request("NFC_REPORT_HANDOVER INIT WPS " + req + " " + sel)
  538. if "FAIL" in res:
  539. raise Exception("Failed to report NFC connection handover to to wpa_supplicant")
  540. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED", "WPS-FAIL"], timeout=15)
  541. if ev is None:
  542. raise Exception("Timed out")
  543. if "WPS-FAIL" not in ev:
  544. raise Exception("Public key hash mismatch not detected")