test_ap_wps.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #!/usr/bin/python
  2. #
  3. # WPS 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(__name__)
  12. import hwsim_utils
  13. import hostapd
  14. def test_ap_wps_init(dev, apdev):
  15. """Initial AP configuration with first WPS Enrollee"""
  16. ssid = "test-wps"
  17. hostapd.add_ap(apdev[0]['ifname'],
  18. { "ssid": ssid, "eap_server": "1", "wps_state": "1" })
  19. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  20. logger.info("WPS provisioning step")
  21. hapd.request("WPS_PBC")
  22. dev[0].dump_monitor()
  23. dev[0].request("WPS_PBC")
  24. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  25. if ev is None:
  26. raise Exception("Association with the AP timed out")
  27. status = dev[0].get_status()
  28. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  29. raise Exception("Not fully connected")
  30. if status['ssid'] != ssid:
  31. raise Exception("Unexpected SSID")
  32. if status['pairwise_cipher'] != 'CCMP':
  33. raise Exception("Unexpected encryption configuration")
  34. if status['key_mgmt'] != 'WPA2-PSK':
  35. raise Exception("Unexpected key_mgmt")
  36. def test_ap_wps_conf(dev, apdev):
  37. """WPS PBC provisioning with configured AP"""
  38. ssid = "test-wps-conf"
  39. hostapd.add_ap(apdev[0]['ifname'],
  40. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  41. "wpa_passphrase": "12345678", "wpa": "2",
  42. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  43. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  44. logger.info("WPS provisioning step")
  45. hapd.request("WPS_PBC")
  46. dev[0].dump_monitor()
  47. dev[0].request("WPS_PBC")
  48. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  49. if ev is None:
  50. raise Exception("Association with the AP timed out")
  51. status = dev[0].get_status()
  52. if status['wpa_state'] != 'COMPLETED':
  53. raise Exception("Not fully connected")
  54. if status['bssid'] != apdev[0]['bssid']:
  55. raise Exception("Unexpected BSSID")
  56. if status['ssid'] != ssid:
  57. raise Exception("Unexpected SSID")
  58. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  59. raise Exception("Unexpected encryption configuration")
  60. if status['key_mgmt'] != 'WPA2-PSK':
  61. raise Exception("Unexpected key_mgmt")
  62. def test_ap_wps_conf_pin(dev, apdev):
  63. """WPS PIN provisioning with configured AP"""
  64. ssid = "test-wps-conf-pin"
  65. hostapd.add_ap(apdev[0]['ifname'],
  66. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  67. "wpa_passphrase": "12345678", "wpa": "2",
  68. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  69. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  70. logger.info("WPS provisioning step")
  71. pin = dev[0].wps_read_pin()
  72. hapd.request("WPS_PIN any " + pin)
  73. dev[0].dump_monitor()
  74. dev[0].request("WPS_PIN any " + pin)
  75. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  76. if ev is None:
  77. raise Exception("Association with the AP timed out")
  78. status = dev[0].get_status()
  79. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  80. raise Exception("Not fully connected")
  81. if status['ssid'] != ssid:
  82. raise Exception("Unexpected SSID")
  83. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  84. raise Exception("Unexpected encryption configuration")
  85. if status['key_mgmt'] != 'WPA2-PSK':
  86. raise Exception("Unexpected key_mgmt")
  87. def test_ap_wps_reg_connect(dev, apdev):
  88. """WPS registrar using AP PIN to connect"""
  89. ssid = "test-wps-conf-ap-pin"
  90. appin = "12345670"
  91. hostapd.add_ap(apdev[0]['ifname'],
  92. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  93. "wpa_passphrase": "12345678", "wpa": "2",
  94. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  95. "ap_pin": appin})
  96. logger.info("WPS provisioning step")
  97. dev[0].request("BSS_FLUSH")
  98. dev[0].dump_monitor()
  99. dev[0].request("WPS_REG " + apdev[0]['bssid'] + " " + appin)
  100. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  101. if ev is None:
  102. raise Exception("Association with the AP timed out")
  103. status = dev[0].get_status()
  104. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  105. raise Exception("Not fully connected")
  106. if status['ssid'] != ssid:
  107. raise Exception("Unexpected SSID")
  108. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  109. raise Exception("Unexpected encryption configuration")
  110. if status['key_mgmt'] != 'WPA2-PSK':
  111. raise Exception("Unexpected key_mgmt")
  112. def test_ap_wps_reg_config(dev, apdev):
  113. """WPS registrar configuring and AP using AP PIN"""
  114. ssid = "test-wps-init-ap-pin"
  115. appin = "12345670"
  116. hostapd.add_ap(apdev[0]['ifname'],
  117. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  118. "ap_pin": appin})
  119. logger.info("WPS configuration step")
  120. dev[0].request("BSS_FLUSH")
  121. dev[0].dump_monitor()
  122. new_ssid = "wps-new-ssid"
  123. new_passphrase = "1234567890"
  124. dev[0].request("WPS_REG " + apdev[0]['bssid'] + " " + appin + " " + new_ssid.encode("hex") + " WPA2PSK CCMP " + new_passphrase.encode("hex"))
  125. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  126. if ev is None:
  127. raise Exception("Association with the AP timed out")
  128. status = dev[0].get_status()
  129. if status['wpa_state'] != 'COMPLETED' or status['bssid'] != apdev[0]['bssid']:
  130. raise Exception("Not fully connected")
  131. if status['ssid'] != new_ssid:
  132. raise Exception("Unexpected SSID")
  133. if status['pairwise_cipher'] != 'CCMP' or status['group_cipher'] != 'CCMP':
  134. raise Exception("Unexpected encryption configuration")
  135. if status['key_mgmt'] != 'WPA2-PSK':
  136. raise Exception("Unexpected key_mgmt")
  137. def test_ap_wps_pbc_overlap_2ap(dev, apdev):
  138. """WPS PBC session overlap with two active APs"""
  139. hostapd.add_ap(apdev[0]['ifname'],
  140. { "ssid": "wps1", "eap_server": "1", "wps_state": "2",
  141. "wpa_passphrase": "12345678", "wpa": "2",
  142. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  143. "wps_independent": "1"})
  144. hostapd.add_ap(apdev[1]['ifname'],
  145. { "ssid": "wps2", "eap_server": "1", "wps_state": "2",
  146. "wpa_passphrase": "123456789", "wpa": "2",
  147. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
  148. "wps_independent": "1"})
  149. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  150. hapd.request("WPS_PBC")
  151. hapd2 = hostapd.Hostapd(apdev[1]['ifname'])
  152. hapd2.request("WPS_PBC")
  153. logger.info("WPS provisioning step")
  154. dev[0].dump_monitor()
  155. dev[0].request("WPS_PBC")
  156. ev = dev[0].wait_event(["WPS-OVERLAP-DETECTED"], timeout=15)
  157. if ev is None:
  158. raise Exception("PBC session overlap not detected")
  159. def test_ap_wps_pbc_overlap_2sta(dev, apdev):
  160. """WPS PBC session overlap with two active STAs"""
  161. ssid = "test-wps-pbc-overlap"
  162. hostapd.add_ap(apdev[0]['ifname'],
  163. { "ssid": ssid, "eap_server": "1", "wps_state": "2",
  164. "wpa_passphrase": "12345678", "wpa": "2",
  165. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP"})
  166. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  167. logger.info("WPS provisioning step")
  168. hapd.request("WPS_PBC")
  169. dev[0].request("BSS_FLUSH")
  170. dev[1].request("BSS_FLUSH")
  171. dev[0].dump_monitor()
  172. dev[1].dump_monitor()
  173. dev[0].request("WPS_PBC")
  174. dev[1].request("WPS_PBC")
  175. ev = dev[0].wait_event(["WPS-M2D"], timeout=15)
  176. if ev is None:
  177. raise Exception("PBC session overlap not detected (dev0)")
  178. if "config_error=12" not in ev:
  179. raise Exception("PBC session overlap not correctly reported (dev0)")
  180. ev = dev[1].wait_event(["WPS-M2D"], timeout=15)
  181. if ev is None:
  182. raise Exception("PBC session overlap not detected (dev1)")
  183. if "config_error=12" not in ev:
  184. raise Exception("PBC session overlap not correctly reported (dev1)")