test_wpas_ctrl.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #!/usr/bin/python
  2. #
  3. # wpa_supplicant control interface
  4. # Copyright (c) 2014, Qualcomm Atheros, Inc.
  5. #
  6. # This software may be distributed under the terms of the BSD license.
  7. # See README for more details.
  8. def test_wpas_ctrl_network(dev):
  9. """wpa_supplicant ctrl_iface network set/get"""
  10. id = dev[0].add_network()
  11. tests = (("key_mgmt", "WPA-PSK WPA-EAP IEEE8021X NONE WPA-NONE FT-PSK FT-EAP WPA-PSK-SHA256 WPA-EAP-SHA256"),
  12. ("pairwise", "CCMP-256 GCMP-256 CCMP GCMP TKIP"),
  13. ("group", "CCMP-256 GCMP-256 CCMP GCMP TKIP WEP104 WEP40"),
  14. ("auth_alg", "OPEN SHARED LEAP"),
  15. ("scan_freq", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"),
  16. ("freq_list", "2412 2417"),
  17. ("eap", "TLS"),
  18. ("go_p2p_dev_addr", "22:33:44:55:66:aa"),
  19. ("p2p_client_list", "22:33:44:55:66:bb 02:11:22:33:44:55"))
  20. dev[0].set_network_quoted(id, "ssid", "test")
  21. for field, value in tests:
  22. dev[0].set_network(id, field, value)
  23. res = dev[0].get_network(id, field)
  24. if res != value:
  25. raise Exception("Unexpected response for '" + field + "': '" + res + "'")
  26. q_tests = (("identity", "hello"),
  27. ("anonymous_identity", "foo@nowhere.com"))
  28. for field, value in q_tests:
  29. dev[0].set_network_quoted(id, field, value)
  30. res = dev[0].get_network(id, field)
  31. if res != '"' + value + '"':
  32. raise Exception("Unexpected quoted response for '" + field + "': '" + res + "'")
  33. get_tests = (("foo", None), ("ssid", '"test"'))
  34. for field, value in get_tests:
  35. res = dev[0].get_network(id, field)
  36. if res != value:
  37. raise Exception("Unexpected response for '" + field + "': '" + res + "'")
  38. if dev[0].get_network(id, "password"):
  39. raise Exception("Unexpected response for 'password'")
  40. dev[0].set_network_quoted(id, "password", "foo")
  41. if dev[0].get_network(id, "password") != '*':
  42. raise Exception("Unexpected response for 'password' (expected *)")
  43. dev[0].set_network(id, "password", "hash:12345678901234567890123456789012")
  44. if dev[0].get_network(id, "password") != '*':
  45. raise Exception("Unexpected response for 'password' (expected *)")
  46. dev[0].set_network(id, "password", "NULL")
  47. if dev[0].get_network(id, "password"):
  48. raise Exception("Unexpected response for 'password'")
  49. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + " password hash:12"):
  50. raise Exception("Unexpected success for invalid password hash")
  51. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + " password hash:123456789012345678x0123456789012"):
  52. raise Exception("Unexpected success for invalid password hash")
  53. dev[0].set_network(id, "identity", "414243")
  54. if dev[0].get_network(id, "identity") != '"ABC"':
  55. raise Exception("Unexpected identity hex->text response")
  56. dev[0].set_network(id, "identity", 'P"abc\ndef"')
  57. if dev[0].get_network(id, "identity") != "6162630a646566":
  58. raise Exception("Unexpected identity printf->hex response")
  59. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' identity P"foo'):
  60. raise Exception("Unexpected success for invalid identity string")
  61. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' identity 12x3'):
  62. raise Exception("Unexpected success for invalid identity string")
  63. for i in range(0, 4):
  64. if "FAIL" in dev[0].request("SET_NETWORK " + str(id) + ' wep_key' + str(i) + ' aabbccddee'):
  65. raise Exception("Unexpected wep_key set failure")
  66. if dev[0].get_network(id, "wep_key" + str(i)) != '*':
  67. raise Exception("Unexpected wep_key get failure")
  68. if "FAIL" in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'):
  69. raise Exception("Unexpected failure for psk_list string")
  70. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list 00:11:x2:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'):
  71. raise Exception("Unexpected success for invalid psk_list string")
  72. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:x2:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'):
  73. raise Exception("Unexpected success for invalid psk_list string")
  74. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55+0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'):
  75. raise Exception("Unexpected success for invalid psk_list string")
  76. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde'):
  77. raise Exception("Unexpected success for invalid psk_list string")
  78. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdex'):
  79. raise Exception("Unexpected success for invalid psk_list string")
  80. if dev[0].get_network(id, "psk_list"):
  81. raise Exception("Unexpected psk_list get response")
  82. def test_wpas_ctrl_cred(dev):
  83. """wpa_supplicant ctrl_iface cred set"""
  84. id1 = dev[0].add_cred()
  85. id = dev[0].add_cred()
  86. id2 = dev[0].add_cred()
  87. dev[0].set_cred(id, "temporary", "1")
  88. dev[0].set_cred(id, "priority", "1")
  89. dev[0].set_cred(id, "pcsc", "1")
  90. dev[0].set_cred_quoted(id, "private_key_passwd", "test")
  91. dev[0].set_cred_quoted(id, "domain_suffix_match", "test")
  92. dev[0].set_cred_quoted(id, "phase1", "test")
  93. dev[0].set_cred_quoted(id, "phase2", "test")
  94. if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " eap FOO"):
  95. raise Exception("Unexpected success on unknown EAP method")
  96. if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " username 12xa"):
  97. raise Exception("Unexpected success on invalid string")
  98. for i in ("11", "1122", "112233445566778899aabbccddeeff00"):
  99. if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " roaming_consortium " + i):
  100. raise Exception("Unexpected success on invalid roaming_consortium")
  101. dev[0].set_cred(id, "excluded_ssid", "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff")
  102. if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " excluded_ssid 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"):
  103. raise Exception("Unexpected success on invalid excluded_ssid")
  104. if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " foo 4142"):
  105. raise Exception("Unexpected success on unknown field")
  106. id3 = dev[0].add_cred()
  107. id4 = dev[0].add_cred()
  108. dev[0].remove_cred(id1)
  109. dev[0].remove_cred(id3)
  110. dev[0].remove_cred(id4)
  111. dev[0].remove_cred(id2)
  112. dev[0].remove_cred(id)
  113. if "FAIL" not in dev[0].request("REMOVE_CRED 1"):
  114. raise Exception("Unexpected success on invalid remove cred")
  115. def test_wpas_ctrl_pno(dev):
  116. """wpa_supplicant ctrl_iface pno"""
  117. if "FAIL" not in dev[0].request("SET pno 1"):
  118. raise Exception("Unexpected success in enabling PNO without enabled network blocks")
  119. id = dev[0].add_network()
  120. dev[0].set_network_quoted(id, "ssid", "test")
  121. dev[0].set_network(id, "key_mgmt", "NONE")
  122. dev[0].request("ENABLE_NETWORK " + str(id) + " no-connect")
  123. #mac80211_hwsim does not yet support PNO, so this fails
  124. if "FAIL" not in dev[0].request("SET pno 1"):
  125. raise Exception("Unexpected success in enabling PNO")
  126. if "FAIL" in dev[0].request("SET pno 0"):
  127. raise Exception("Unexpected failure in disabling PNO")
  128. def test_wpas_ctrl_get(dev):
  129. """wpa_supplicant ctrl_iface get"""
  130. if "FAIL" in dev[0].request("GET version"):
  131. raise Exception("Unexpected get failure for version")
  132. if "FAIL" in dev[0].request("GET wifi_display"):
  133. raise Exception("Unexpected get failure for wifi_display")
  134. if "FAIL" not in dev[0].request("GET foo"):
  135. raise Exception("Unexpected success on get command")
  136. def test_wpas_ctrl_preauth(dev):
  137. """wpa_supplicant ctrl_iface preauth"""
  138. if "FAIL" not in dev[0].request("PREAUTH "):
  139. raise Exception("Unexpected success on invalid PREAUTH")
  140. if "FAIL" in dev[0].request("PREAUTH 00:11:22:33:44:55"):
  141. raise Exception("Unexpected failure on PREAUTH")
  142. def test_wpas_ctrl_stkstart(dev):
  143. """wpa_supplicant ctrl_iface strkstart"""
  144. if "FAIL" not in dev[0].request("STKSTART "):
  145. raise Exception("Unexpected success on invalid STKSTART")
  146. if "FAIL" not in dev[0].request("STKSTART 00:11:22:33:44:55"):
  147. raise Exception("Unexpected success on STKSTART")
  148. def test_wpas_ctrl_tdls_discover(dev):
  149. """wpa_supplicant ctrl_iface tdls_discover"""
  150. if "FAIL" not in dev[0].request("TDLS_DISCOVER "):
  151. raise Exception("Unexpected success on invalid TDLS_DISCOVER")
  152. if "FAIL" not in dev[0].request("TDLS_DISCOVER 00:11:22:33:44:55"):
  153. raise Exception("Unexpected success on TDLS_DISCOVER")