test_wpas_ctrl.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. # wpa_supplicant control interface
  2. # Copyright (c) 2014, Qualcomm Atheros, Inc.
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import hostapd
  7. def test_wpas_ctrl_network(dev):
  8. """wpa_supplicant ctrl_iface network set/get"""
  9. id = dev[0].add_network()
  10. tests = (("key_mgmt", "WPA-PSK WPA-EAP IEEE8021X NONE WPA-NONE FT-PSK FT-EAP WPA-PSK-SHA256 WPA-EAP-SHA256"),
  11. ("pairwise", "CCMP-256 GCMP-256 CCMP GCMP TKIP"),
  12. ("group", "CCMP-256 GCMP-256 CCMP GCMP TKIP WEP104 WEP40"),
  13. ("auth_alg", "OPEN SHARED LEAP"),
  14. ("scan_freq", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"),
  15. ("freq_list", "2412 2417"),
  16. ("scan_ssid", "1"),
  17. ("bssid", "00:11:22:33:44:55"),
  18. ("proto", "WPA RSN OSEN"),
  19. ("eap", "TLS"),
  20. ("go_p2p_dev_addr", "22:33:44:55:66:aa"),
  21. ("p2p_client_list", "22:33:44:55:66:bb 02:11:22:33:44:55"))
  22. dev[0].set_network_quoted(id, "ssid", "test")
  23. for field, value in tests:
  24. dev[0].set_network(id, field, value)
  25. res = dev[0].get_network(id, field)
  26. if res != value:
  27. raise Exception("Unexpected response for '" + field + "': '" + res + "'")
  28. q_tests = (("identity", "hello"),
  29. ("anonymous_identity", "foo@nowhere.com"))
  30. for field, value in q_tests:
  31. dev[0].set_network_quoted(id, field, value)
  32. res = dev[0].get_network(id, field)
  33. if res != '"' + value + '"':
  34. raise Exception("Unexpected quoted response for '" + field + "': '" + res + "'")
  35. get_tests = (("foo", None), ("ssid", '"test"'))
  36. for field, value in get_tests:
  37. res = dev[0].get_network(id, field)
  38. if res != value:
  39. raise Exception("Unexpected response for '" + field + "': '" + res + "'")
  40. if dev[0].get_network(id, "password"):
  41. raise Exception("Unexpected response for 'password'")
  42. dev[0].set_network_quoted(id, "password", "foo")
  43. if dev[0].get_network(id, "password") != '*':
  44. raise Exception("Unexpected response for 'password' (expected *)")
  45. dev[0].set_network(id, "password", "hash:12345678901234567890123456789012")
  46. if dev[0].get_network(id, "password") != '*':
  47. raise Exception("Unexpected response for 'password' (expected *)")
  48. dev[0].set_network(id, "password", "NULL")
  49. if dev[0].get_network(id, "password"):
  50. raise Exception("Unexpected response for 'password'")
  51. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + " password hash:12"):
  52. raise Exception("Unexpected success for invalid password hash")
  53. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + " password hash:123456789012345678x0123456789012"):
  54. raise Exception("Unexpected success for invalid password hash")
  55. dev[0].set_network(id, "identity", "414243")
  56. if dev[0].get_network(id, "identity") != '"ABC"':
  57. raise Exception("Unexpected identity hex->text response")
  58. dev[0].set_network(id, "identity", 'P"abc\ndef"')
  59. if dev[0].get_network(id, "identity") != "6162630a646566":
  60. raise Exception("Unexpected identity printf->hex response")
  61. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' identity P"foo'):
  62. raise Exception("Unexpected success for invalid identity string")
  63. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' identity 12x3'):
  64. raise Exception("Unexpected success for invalid identity string")
  65. for i in range(0, 4):
  66. if "FAIL" in dev[0].request("SET_NETWORK " + str(id) + ' wep_key' + str(i) + ' aabbccddee'):
  67. raise Exception("Unexpected wep_key set failure")
  68. if dev[0].get_network(id, "wep_key" + str(i)) != '*':
  69. raise Exception("Unexpected wep_key get failure")
  70. if "FAIL" in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'):
  71. raise Exception("Unexpected failure for psk_list string")
  72. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list 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:x2: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+0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'):
  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-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde'):
  79. raise Exception("Unexpected success for invalid psk_list string")
  80. if "FAIL" not in dev[0].request("SET_NETWORK " + str(id) + ' psk_list P2P-00:11:22:33:44:55-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdex'):
  81. raise Exception("Unexpected success for invalid psk_list string")
  82. if dev[0].get_network(id, "psk_list"):
  83. raise Exception("Unexpected psk_list get response")
  84. if dev[0].list_networks()[0]['ssid'] != "test":
  85. raise Exception("Unexpected ssid in LIST_NETWORKS")
  86. dev[0].set_network(id, "ssid", "NULL")
  87. if dev[0].list_networks()[0]['ssid'] != "":
  88. raise Exception("Unexpected ssid in LIST_NETWORKS after clearing it")
  89. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' ssid "0123456789abcdef0123456789abcdef0"'):
  90. raise Exception("Too long SSID accepted")
  91. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' scan_ssid qwerty'):
  92. raise Exception("Invalid integer accepted")
  93. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' scan_ssid 2'):
  94. raise Exception("Too large integer accepted")
  95. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' psk 12345678'):
  96. raise Exception("Invalid PSK accepted")
  97. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' psk "1234567"'):
  98. raise Exception("Too short PSK accepted")
  99. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' psk "1234567890123456789012345678901234567890123456789012345678901234"'):
  100. raise Exception("Too long PSK accepted")
  101. dev[0].set_network_quoted(id, "psk", "123456768");
  102. dev[0].set_network_quoted(id, "psk", "123456789012345678901234567890123456789012345678901234567890123");
  103. if dev[0].get_network(id, "psk") != '*':
  104. raise Exception("Unexpected psk read result");
  105. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' eap UNKNOWN'):
  106. raise Exception("Unknown EAP method accepted")
  107. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' password "foo'):
  108. raise Exception("Invalid password accepted")
  109. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' wep_key0 "foo'):
  110. raise Exception("Invalid WEP key accepted")
  111. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' wep_key0 "12345678901234567"'):
  112. raise Exception("Too long WEP key accepted")
  113. # too short WEP key is ignored
  114. dev[0].set_network_quoted(id, "wep_key0", "1234")
  115. dev[0].set_network_quoted(id, "wep_key1", "12345")
  116. dev[0].set_network_quoted(id, "wep_key2", "1234567890123")
  117. dev[0].set_network_quoted(id, "wep_key3", "1234567890123456")
  118. dev[0].set_network(id, "go_p2p_dev_addr", "any")
  119. if dev[0].get_network(id, "go_p2p_dev_addr") is not None:
  120. raise Exception("Unexpected go_p2p_dev_addr value")
  121. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' go_p2p_dev_addr 00:11:22:33:44'):
  122. raise Exception("Invalid go_p2p_dev_addr accepted")
  123. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' p2p_client_list 00:11:22:33:44'):
  124. raise Exception("Invalid p2p_client_list accepted")
  125. if "FAIL" in dev[0].request('SET_NETWORK ' + str(id) + ' p2p_client_list 00:11:22:33:44:55 00:1'):
  126. raise Exception("p2p_client_list truncation workaround failed")
  127. if dev[0].get_network(id, "p2p_client_list") != "00:11:22:33:44:55":
  128. raise Exception("p2p_client_list truncation workaround did not work")
  129. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' auth_alg '):
  130. raise Exception("Empty auth_alg accepted")
  131. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' auth_alg FOO'):
  132. raise Exception("Invalid auth_alg accepted")
  133. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' proto '):
  134. raise Exception("Empty proto accepted")
  135. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' proto FOO'):
  136. raise Exception("Invalid proto accepted")
  137. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' pairwise '):
  138. raise Exception("Empty pairwise accepted")
  139. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' pairwise FOO'):
  140. raise Exception("Invalid pairwise accepted")
  141. if "FAIL" not in dev[0].request('SET_NETWORK ' + str(id) + ' pairwise WEP40'):
  142. raise Exception("Invalid pairwise accepted")
  143. def add_cred(dev):
  144. id = dev.add_cred()
  145. ev = dev.wait_event(["CRED-ADDED"])
  146. if ev is None:
  147. raise Exception("Missing CRED-ADDED event")
  148. if " " + str(id) not in ev:
  149. raise Exception("CRED-ADDED event without matching id")
  150. return id
  151. def set_cred(dev, id, field, value):
  152. dev.set_cred(id, field, value)
  153. ev = dev.wait_event(["CRED-MODIFIED"])
  154. if ev is None:
  155. raise Exception("Missing CRED-MODIFIED event")
  156. if " " + str(id) + " " not in ev:
  157. raise Exception("CRED-MODIFIED event without matching id")
  158. if field not in ev:
  159. raise Exception("CRED-MODIFIED event without matching field")
  160. def set_cred_quoted(dev, id, field, value):
  161. dev.set_cred_quoted(id, field, value)
  162. ev = dev.wait_event(["CRED-MODIFIED"])
  163. if ev is None:
  164. raise Exception("Missing CRED-MODIFIED event")
  165. if " " + str(id) + " " not in ev:
  166. raise Exception("CRED-MODIFIED event without matching id")
  167. if field not in ev:
  168. raise Exception("CRED-MODIFIED event without matching field")
  169. def remove_cred(dev, id):
  170. dev.remove_cred(id)
  171. ev = dev.wait_event(["CRED-REMOVED"])
  172. if ev is None:
  173. raise Exception("Missing CRED-REMOVED event")
  174. if " " + str(id) not in ev:
  175. raise Exception("CRED-REMOVED event without matching id")
  176. def test_wpas_ctrl_cred(dev):
  177. """wpa_supplicant ctrl_iface cred set"""
  178. id1 = add_cred(dev[0])
  179. id = add_cred(dev[0])
  180. id2 = add_cred(dev[0])
  181. set_cred(dev[0], id, "temporary", "1")
  182. set_cred(dev[0], id, "priority", "1")
  183. set_cred(dev[0], id, "pcsc", "1")
  184. set_cred_quoted(dev[0], id, "private_key_passwd", "test")
  185. set_cred_quoted(dev[0], id, "domain_suffix_match", "test")
  186. set_cred_quoted(dev[0], id, "phase1", "test")
  187. set_cred_quoted(dev[0], id, "phase2", "test")
  188. if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " eap FOO"):
  189. raise Exception("Unexpected success on unknown EAP method")
  190. if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " username 12xa"):
  191. raise Exception("Unexpected success on invalid string")
  192. for i in ("11", "1122", "112233445566778899aabbccddeeff00"):
  193. if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " roaming_consortium " + i):
  194. raise Exception("Unexpected success on invalid roaming_consortium")
  195. dev[0].set_cred(id, "excluded_ssid", "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff")
  196. if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " excluded_ssid 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"):
  197. raise Exception("Unexpected success on invalid excluded_ssid")
  198. if "FAIL" not in dev[0].request("SET_CRED " + str(id) + " foo 4142"):
  199. raise Exception("Unexpected success on unknown field")
  200. id3 = add_cred(dev[0])
  201. id4 = add_cred(dev[0])
  202. remove_cred(dev[0], id1)
  203. remove_cred(dev[0], id3)
  204. remove_cred(dev[0], id4)
  205. remove_cred(dev[0], id2)
  206. remove_cred(dev[0], id)
  207. if "FAIL" not in dev[0].request("REMOVE_CRED 1"):
  208. raise Exception("Unexpected success on invalid remove cred")
  209. id = add_cred(dev[0])
  210. values = [ ("temporary", "1", False),
  211. ("temporary", "0", False),
  212. ("pcsc", "1", False),
  213. ("realm", "example.com", True),
  214. ("username", "user@example.com", True),
  215. ("password", "foo", True, "*"),
  216. ("ca_cert", "ca.pem", True),
  217. ("client_cert", "user.pem", True),
  218. ("private_key", "key.pem", True),
  219. ("private_key_passwd", "foo", True, "*"),
  220. ("imsi", "310026-000000000", True),
  221. ("milenage", "foo", True, "*"),
  222. ("domain_suffix_match", "example.com", True),
  223. ("domain", "example.com", True),
  224. ("domain", "example.org", True, "example.com\nexample.org"),
  225. ("roaming_consortium", "0123456789", False),
  226. ("required_roaming_consortium", "456789", False),
  227. ("eap", "TTLS", False),
  228. ("phase1", "foo=bar1", True),
  229. ("phase2", "foo=bar2", True),
  230. ("excluded_ssid", "test", True),
  231. ("excluded_ssid", "foo", True, "test\nfoo"),
  232. ("roaming_partner", "example.com,0,4,*", True),
  233. ("roaming_partner", "example.org,1,2,US", True,
  234. "example.com,0,4,*\nexample.org,1,2,US"),
  235. ("update_identifier", "4", False),
  236. ("provisioning_sp", "sp.example.com", True),
  237. ("sp_priority", "7", False),
  238. ("min_dl_bandwidth_home", "100", False),
  239. ("min_ul_bandwidth_home", "101", False),
  240. ("min_dl_bandwidth_roaming", "102", False),
  241. ("min_ul_bandwidth_roaming", "103", False),
  242. ("max_bss_load", "57", False),
  243. ("req_conn_capab", "6:22,80,443", False),
  244. ("req_conn_capab", "17:500", False, "6:22,80,443\n17:500"),
  245. ("req_conn_capab", "50", False, "6:22,80,443\n17:500\n50"),
  246. ("ocsp", "1", False) ]
  247. for v in values:
  248. if v[2]:
  249. set_cred_quoted(dev[0], id, v[0], v[1])
  250. else:
  251. set_cred(dev[0], id, v[0], v[1])
  252. val = dev[0].get_cred(id, v[0])
  253. if len(v) == 4:
  254. expect = v[3]
  255. else:
  256. expect = v[1]
  257. if val != expect:
  258. raise Exception("Unexpected GET_CRED value for {}: {} != {}".format(v[0], val, expect))
  259. remove_cred(dev[0], id)
  260. def test_wpas_ctrl_pno(dev):
  261. """wpa_supplicant ctrl_iface pno"""
  262. if "FAIL" not in dev[0].request("SET pno 1"):
  263. raise Exception("Unexpected success in enabling PNO without enabled network blocks")
  264. id = dev[0].add_network()
  265. dev[0].set_network_quoted(id, "ssid", "test")
  266. dev[0].set_network(id, "key_mgmt", "NONE")
  267. dev[0].request("ENABLE_NETWORK " + str(id) + " no-connect")
  268. #mac80211_hwsim does not yet support PNO, so this fails
  269. if "FAIL" not in dev[0].request("SET pno 1"):
  270. raise Exception("Unexpected success in enabling PNO")
  271. if "FAIL" not in dev[0].request("SET pno 1 freq=2000-3000,5180"):
  272. raise Exception("Unexpected success in enabling PNO")
  273. if "FAIL" not in dev[0].request("SET pno 1 freq=0-6000"):
  274. raise Exception("Unexpected success in enabling PNO")
  275. if "FAIL" in dev[0].request("SET pno 0"):
  276. raise Exception("Unexpected failure in disabling PNO")
  277. def test_wpas_ctrl_get(dev):
  278. """wpa_supplicant ctrl_iface get"""
  279. if "FAIL" in dev[0].request("GET version"):
  280. raise Exception("Unexpected get failure for version")
  281. if "FAIL" in dev[0].request("GET wifi_display"):
  282. raise Exception("Unexpected get failure for wifi_display")
  283. if "FAIL" not in dev[0].request("GET foo"):
  284. raise Exception("Unexpected success on get command")
  285. def test_wpas_ctrl_preauth(dev):
  286. """wpa_supplicant ctrl_iface preauth"""
  287. if "FAIL" not in dev[0].request("PREAUTH "):
  288. raise Exception("Unexpected success on invalid PREAUTH")
  289. if "FAIL" in dev[0].request("PREAUTH 00:11:22:33:44:55"):
  290. raise Exception("Unexpected failure on PREAUTH")
  291. def test_wpas_ctrl_stkstart(dev):
  292. """wpa_supplicant ctrl_iface strkstart"""
  293. if "FAIL" not in dev[0].request("STKSTART "):
  294. raise Exception("Unexpected success on invalid STKSTART")
  295. if "FAIL" not in dev[0].request("STKSTART 00:11:22:33:44:55"):
  296. raise Exception("Unexpected success on STKSTART")
  297. def test_wpas_ctrl_tdls_discover(dev):
  298. """wpa_supplicant ctrl_iface tdls_discover"""
  299. if "FAIL" not in dev[0].request("TDLS_DISCOVER "):
  300. raise Exception("Unexpected success on invalid TDLS_DISCOVER")
  301. if "FAIL" not in dev[0].request("TDLS_DISCOVER 00:11:22:33:44:55"):
  302. raise Exception("Unexpected success on TDLS_DISCOVER")
  303. def test_wpas_ctrl_config_parser(dev):
  304. """wpa_supplicant ctrl_iface SET config parser"""
  305. if "FAIL" not in dev[0].request("SET pbc_in_m1 qwerty"):
  306. raise Exception("Non-number accepted as integer")
  307. if "FAIL" not in dev[0].request("SET eapol_version 0"):
  308. raise Exception("Out-of-range value accepted")
  309. if "FAIL" not in dev[0].request("SET eapol_version 10"):
  310. raise Exception("Out-of-range value accepted")
  311. if "FAIL" not in dev[0].request("SET serial_number 0123456789abcdef0123456789abcdef0"):
  312. raise Exception("Too long string accepted")
  313. def test_wpas_ctrl_mib(dev):
  314. """wpa_supplicant ctrl_iface MIB"""
  315. mib = dev[0].get_mib()
  316. if "dot11RSNAOptionImplemented" not in mib:
  317. raise Exception("Missing MIB entry")
  318. if mib["dot11RSNAOptionImplemented"] != "TRUE":
  319. raise Exception("Unexpected dot11RSNAOptionImplemented value")
  320. def test_wpas_ctrl_set_wps_params(dev):
  321. """wpa_supplicant ctrl_iface SET config_methods"""
  322. ts = [ "config_methods label virtual_display virtual_push_button keypad",
  323. "device_type 1-0050F204-1",
  324. "os_version 01020300",
  325. "uuid 12345678-9abc-def0-1234-56789abcdef0" ]
  326. for t in ts:
  327. if "OK" not in dev[2].request("SET " + t):
  328. raise Exception("SET failed for: " + t)
  329. def test_wpas_ctrl_level(dev):
  330. """wpa_supplicant ctrl_iface LEVEL"""
  331. try:
  332. if "FAIL" not in dev[2].request("LEVEL 3"):
  333. raise Exception("Unexpected LEVEL success")
  334. if "OK" not in dev[2].mon.request("LEVEL 2"):
  335. raise Exception("Unexpected LEVEL failure")
  336. dev[2].request("SCAN freq=2412")
  337. ev = dev[2].wait_event(["State:"], timeout=5)
  338. if ev is None:
  339. raise Exception("No debug message received")
  340. dev[2].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=5)
  341. finally:
  342. dev[2].mon.request("LEVEL 3")
  343. def test_wpas_ctrl_bssid_filter(dev, apdev):
  344. """wpa_supplicant bssid_filter"""
  345. try:
  346. if "OK" not in dev[2].request("SET bssid_filter " + apdev[0]['bssid']):
  347. raise Exception("Failed to set bssid_filter")
  348. params = { "ssid": "test" }
  349. hostapd.add_ap(apdev[0]['ifname'], params)
  350. hostapd.add_ap(apdev[1]['ifname'], params)
  351. dev[2].scan(freq="2412")
  352. bss = dev[2].get_bss(apdev[0]['bssid'])
  353. if len(bss) == 0:
  354. raise Exception("Missing BSS data")
  355. bss = dev[2].get_bss(apdev[1]['bssid'])
  356. if len(bss) != 0:
  357. raise Exception("Unexpected BSS data")
  358. dev[2].request("SET bssid_filter ")
  359. dev[2].scan(freq="2412")
  360. bss = dev[2].get_bss(apdev[0]['bssid'])
  361. if len(bss) == 0:
  362. raise Exception("Missing BSS data")
  363. bss = dev[2].get_bss(apdev[1]['bssid'])
  364. if len(bss) == 0:
  365. raise Exception("Missing BSS data(2)")
  366. finally:
  367. dev[2].request("SET bssid_filter ")
  368. def test_wpas_ctrl_disallow_aps(dev, apdev):
  369. """wpa_supplicant ctrl_iface disallow_aps"""
  370. params = { "ssid": "test" }
  371. hostapd.add_ap(apdev[0]['ifname'], params)
  372. if "FAIL" not in dev[0].request("SET disallow_aps bssid "):
  373. raise Exception("Unexpected success on invalid disallow_aps")
  374. if "FAIL" not in dev[0].request("SET disallow_aps bssid 00:11:22:33:44"):
  375. raise Exception("Unexpected success on invalid disallow_aps")
  376. if "FAIL" not in dev[0].request("SET disallow_aps ssid 0"):
  377. raise Exception("Unexpected success on invalid disallow_aps")
  378. if "FAIL" not in dev[0].request("SET disallow_aps ssid 4q"):
  379. raise Exception("Unexpected success on invalid disallow_aps")
  380. if "FAIL" not in dev[0].request("SET disallow_aps ssid 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f00"):
  381. raise Exception("Unexpected success on invalid disallow_aps")
  382. if "FAIL" not in dev[0].request("SET disallow_aps foo 112233445566"):
  383. raise Exception("Unexpected success on invalid disallow_aps")
  384. dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
  385. hostapd.add_ap(apdev[1]['ifname'], params)
  386. dev[0].dump_monitor()
  387. if "OK" not in dev[0].request("SET disallow_aps bssid " + apdev[0]['bssid']):
  388. raise Exception("Failed to set disallow_aps")
  389. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  390. if ev is None:
  391. raise Exception("Reassociation timed out")
  392. if apdev[1]['bssid'] not in ev:
  393. raise Exception("Unexpected BSSID")
  394. dev[0].dump_monitor()
  395. if "OK" not in dev[0].request("SET disallow_aps ssid " + "test".encode("hex")):
  396. raise Exception("Failed to set disallow_aps")
  397. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5)
  398. if ev is None:
  399. raise Exception("Disconnection not seen")
  400. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  401. if ev is not None:
  402. raise Exception("Unexpected reassociation")
  403. def test_wpas_ctrl_blob(dev):
  404. """wpa_supplicant ctrl_iface SET blob"""
  405. if "FAIL" not in dev[0].request("SET blob foo"):
  406. raise Exception("Unexpected SET success")
  407. if "FAIL" not in dev[0].request("SET blob foo 0"):
  408. raise Exception("Unexpected SET success")
  409. if "FAIL" not in dev[0].request("SET blob foo 0q"):
  410. raise Exception("Unexpected SET success")
  411. if "OK" not in dev[0].request("SET blob foo 00"):
  412. raise Exception("Unexpected SET failure")
  413. if "OK" not in dev[0].request("SET blob foo 0011"):
  414. raise Exception("Unexpected SET failure")
  415. def test_wpas_ctrl_set_uapsd(dev):
  416. """wpa_supplicant ctrl_iface SET uapsd"""
  417. if "FAIL" not in dev[0].request("SET uapsd foo"):
  418. raise Exception("Unexpected SET success")
  419. if "FAIL" not in dev[0].request("SET uapsd 0,0,0"):
  420. raise Exception("Unexpected SET success")
  421. if "FAIL" not in dev[0].request("SET uapsd 0,0"):
  422. raise Exception("Unexpected SET success")
  423. if "FAIL" not in dev[0].request("SET uapsd 0"):
  424. raise Exception("Unexpected SET success")
  425. if "OK" not in dev[0].request("SET uapsd 0,0,0,0;0"):
  426. raise Exception("Unexpected SET failure")
  427. if "OK" not in dev[0].request("SET uapsd disable"):
  428. raise Exception("Unexpected SET failure")
  429. def test_wpas_ctrl_get_capability(dev):
  430. """wpa_supplicant ctrl_iface GET_CAPABILITY"""
  431. res = dev[0].get_capability("eap")
  432. if "TTLS" not in res:
  433. raise Exception("Unexpected GET_CAPABILITY eap response: " + str(res))
  434. res = dev[0].get_capability("pairwise")
  435. if "CCMP" not in res:
  436. raise Exception("Unexpected GET_CAPABILITY pairwise response: " + str(res))
  437. res = dev[0].get_capability("group")
  438. if "CCMP" not in res:
  439. raise Exception("Unexpected GET_CAPABILITY group response: " + str(res))
  440. res = dev[0].get_capability("key_mgmt")
  441. if "WPA-PSK" not in res or "WPA-EAP" not in res:
  442. raise Exception("Unexpected GET_CAPABILITY key_mgmt response: " + str(res))
  443. res = dev[0].get_capability("proto")
  444. if "WPA" not in res or "RSN" not in res:
  445. raise Exception("Unexpected GET_CAPABILITY proto response: " + str(res))
  446. res = dev[0].get_capability("auth_alg")
  447. if "OPEN" not in res or "SHARED" not in res:
  448. raise Exception("Unexpected GET_CAPABILITY auth_alg response: " + str(res))
  449. res = dev[0].get_capability("modes")
  450. if "IBSS" not in res or "AP" not in res:
  451. raise Exception("Unexpected GET_CAPABILITY modes response: " + str(res))
  452. res = dev[0].get_capability("channels")
  453. if "8" not in res or "36" not in res:
  454. raise Exception("Unexpected GET_CAPABILITY channels response: " + str(res))
  455. res = dev[0].get_capability("freq")
  456. if "2457" not in res or "5180" not in res:
  457. raise Exception("Unexpected GET_CAPABILITY freq response: " + str(res))
  458. res = dev[0].get_capability("tdls")
  459. if "EXTERNAL" not in res[0]:
  460. raise Exception("Unexpected GET_CAPABILITY tdls response: " + str(res))
  461. if dev[0].get_capability("foo") is not None:
  462. raise Exception("Unexpected GET_CAPABILITY foo response: " + str(res))