test_ap_tdls.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. # TDLS tests
  2. # Copyright (c) 2013-2014, 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. from remotehost import remote_compatible
  7. import time
  8. import logging
  9. logger = logging.getLogger()
  10. import subprocess
  11. import hwsim_utils
  12. from hostapd import HostapdGlobal
  13. from hostapd import Hostapd
  14. import hostapd
  15. from utils import HwsimSkip, skip_with_fips
  16. from wlantest import Wlantest
  17. from test_ap_vht import vht_supported
  18. def start_ap_wpa2_psk(ap):
  19. params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678")
  20. return hostapd.add_ap(ap, params)
  21. def connectivity(dev, hapd):
  22. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  23. hwsim_utils.test_connectivity(dev[0], hapd)
  24. hwsim_utils.test_connectivity(dev[1], hapd)
  25. def connect_2sta(dev, ssid, hapd):
  26. dev[0].connect(ssid, psk="12345678", scan_freq="2412")
  27. dev[1].connect(ssid, psk="12345678", scan_freq="2412")
  28. connectivity(dev, hapd)
  29. def connect_2sta_wpa2_psk(dev, hapd):
  30. connect_2sta(dev, "test-wpa2-psk", hapd)
  31. def connect_2sta_wpa_psk(dev, hapd):
  32. connect_2sta(dev, "test-wpa-psk", hapd)
  33. def connect_2sta_wpa_psk_mixed(dev, hapd):
  34. dev[0].connect("test-wpa-mixed-psk", psk="12345678", proto="WPA",
  35. scan_freq="2412")
  36. dev[1].connect("test-wpa-mixed-psk", psk="12345678", proto="WPA2",
  37. scan_freq="2412")
  38. connectivity(dev, hapd)
  39. def connect_2sta_wep(dev, hapd):
  40. dev[0].connect("test-wep", key_mgmt="NONE", wep_key0='"hello"',
  41. scan_freq="2412")
  42. dev[1].connect("test-wep", key_mgmt="NONE", wep_key0='"hello"',
  43. scan_freq="2412")
  44. connectivity(dev, hapd)
  45. def connect_2sta_open(dev, hapd, scan_freq="2412"):
  46. dev[0].connect("test-open", key_mgmt="NONE", scan_freq=scan_freq)
  47. dev[1].connect("test-open", key_mgmt="NONE", scan_freq=scan_freq)
  48. connectivity(dev, hapd)
  49. def wlantest_setup(hapd):
  50. Wlantest.setup(hapd)
  51. wt = Wlantest()
  52. wt.flush()
  53. wt.add_passphrase("12345678")
  54. wt.add_wepkey("68656c6c6f")
  55. def wlantest_tdls_packet_counters(bssid, addr0, addr1):
  56. wt = Wlantest()
  57. dl = wt.get_tdls_counter("valid_direct_link", bssid, addr0, addr1)
  58. inv_dl = wt.get_tdls_counter("invalid_direct_link", bssid, addr0, addr1)
  59. ap = wt.get_tdls_counter("valid_ap_path", bssid, addr0, addr1)
  60. inv_ap = wt.get_tdls_counter("invalid_ap_path", bssid, addr0, addr1)
  61. return [dl,inv_dl,ap,inv_ap]
  62. def tdls_check_dl(sta0, sta1, bssid, addr0, addr1):
  63. wt = Wlantest()
  64. wt.tdls_clear(bssid, addr0, addr1)
  65. hwsim_utils.test_connectivity_sta(sta0, sta1)
  66. [dl,inv_dl,ap,inv_ap] = wlantest_tdls_packet_counters(bssid, addr0, addr1)
  67. if dl == 0:
  68. raise Exception("No valid frames through direct link")
  69. if inv_dl > 0:
  70. raise Exception("Invalid frames through direct link")
  71. if ap > 0:
  72. raise Exception("Unexpected frames through AP path")
  73. if inv_ap > 0:
  74. raise Exception("Invalid frames through AP path")
  75. def tdls_check_ap(sta0, sta1, bssid, addr0, addr1):
  76. wt = Wlantest()
  77. wt.tdls_clear(bssid, addr0, addr1)
  78. hwsim_utils.test_connectivity_sta(sta0, sta1)
  79. [dl,inv_dl,ap,inv_ap] = wlantest_tdls_packet_counters(bssid, addr0, addr1)
  80. if dl > 0:
  81. raise Exception("Unexpected frames through direct link")
  82. if inv_dl > 0:
  83. raise Exception("Invalid frames through direct link")
  84. if ap == 0:
  85. raise Exception("No valid frames through AP path")
  86. if inv_ap > 0:
  87. raise Exception("Invalid frames through AP path")
  88. def check_connectivity(sta0, sta1, hapd):
  89. hwsim_utils.test_connectivity_sta(sta0, sta1)
  90. hwsim_utils.test_connectivity(sta0, hapd)
  91. hwsim_utils.test_connectivity(sta1, hapd)
  92. def setup_tdls(sta0, sta1, hapd, reverse=False, expect_fail=False):
  93. logger.info("Setup TDLS")
  94. check_connectivity(sta0, sta1, hapd)
  95. bssid = hapd.own_addr()
  96. addr0 = sta0.p2p_interface_addr()
  97. addr1 = sta1.p2p_interface_addr()
  98. wt = Wlantest()
  99. wt.tdls_clear(bssid, addr0, addr1)
  100. wt.tdls_clear(bssid, addr1, addr0)
  101. sta0.tdls_setup(addr1)
  102. time.sleep(1)
  103. if expect_fail:
  104. tdls_check_ap(sta0, sta1, bssid, addr0, addr1)
  105. return
  106. if reverse:
  107. addr1 = sta0.p2p_interface_addr()
  108. addr0 = sta1.p2p_interface_addr()
  109. conf = wt.get_tdls_counter("setup_conf_ok", bssid, addr0, addr1)
  110. if conf == 0:
  111. raise Exception("No TDLS Setup Confirm (success) seen")
  112. tdls_check_dl(sta0, sta1, bssid, addr0, addr1)
  113. check_connectivity(sta0, sta1, hapd)
  114. def teardown_tdls(sta0, sta1, hapd, responder=False, wildcard=False):
  115. logger.info("Teardown TDLS")
  116. check_connectivity(sta0, sta1, hapd)
  117. bssid = hapd.own_addr()
  118. addr0 = sta0.p2p_interface_addr()
  119. addr1 = sta1.p2p_interface_addr()
  120. if responder:
  121. sta1.tdls_teardown(addr0)
  122. elif wildcard:
  123. sta0.tdls_teardown("*")
  124. else:
  125. sta0.tdls_teardown(addr1)
  126. time.sleep(1)
  127. wt = Wlantest()
  128. teardown = wt.get_tdls_counter("teardown", bssid, addr0, addr1)
  129. if teardown == 0:
  130. raise Exception("No TDLS Setup Teardown seen")
  131. tdls_check_ap(sta0, sta1, bssid, addr0, addr1)
  132. check_connectivity(sta0, sta1, hapd)
  133. def check_tdls_link(sta0, sta1, connected=True):
  134. addr0 = sta0.own_addr()
  135. addr1 = sta1.own_addr()
  136. status0 = sta0.tdls_link_status(addr1).rstrip()
  137. status1 = sta1.tdls_link_status(addr0).rstrip()
  138. logger.info("%s: %s" % (sta0.ifname, status0))
  139. logger.info("%s: %s" % (sta1.ifname, status1))
  140. if status0 != status1:
  141. raise Exception("TDLS link status differs between stations")
  142. if "status: connected" in status0:
  143. if not connected:
  144. raise Exception("Expected TDLS link status NOT to be connected")
  145. else:
  146. if connected:
  147. raise Exception("Expected TDLS link status to be connected")
  148. @remote_compatible
  149. def test_ap_tdls_discovery(dev, apdev):
  150. """WPA2-PSK AP and two stations using TDLS discovery"""
  151. hapd = start_ap_wpa2_psk(apdev[0])
  152. wlantest_setup(hapd)
  153. connect_2sta_wpa2_psk(dev, hapd)
  154. dev[0].request("TDLS_DISCOVER " + dev[1].p2p_interface_addr())
  155. time.sleep(0.2)
  156. def test_ap_wpa2_tdls(dev, apdev):
  157. """WPA2-PSK AP and two stations using TDLS"""
  158. hapd = start_ap_wpa2_psk(apdev[0])
  159. wlantest_setup(hapd)
  160. connect_2sta_wpa2_psk(dev, hapd)
  161. setup_tdls(dev[0], dev[1], hapd)
  162. teardown_tdls(dev[0], dev[1], hapd)
  163. setup_tdls(dev[1], dev[0], hapd)
  164. #teardown_tdls(dev[0], dev[1], hapd)
  165. def test_ap_wpa2_tdls_concurrent_init(dev, apdev):
  166. """Concurrent TDLS setup initiation"""
  167. hapd = start_ap_wpa2_psk(apdev[0])
  168. wlantest_setup(hapd)
  169. connect_2sta_wpa2_psk(dev, hapd)
  170. dev[0].request("SET tdls_testing 0x80")
  171. setup_tdls(dev[1], dev[0], hapd, reverse=True)
  172. def test_ap_wpa2_tdls_concurrent_init2(dev, apdev):
  173. """Concurrent TDLS setup initiation (reverse)"""
  174. hapd = start_ap_wpa2_psk(apdev[0])
  175. wlantest_setup(hapd)
  176. connect_2sta_wpa2_psk(dev, hapd)
  177. dev[1].request("SET tdls_testing 0x80")
  178. setup_tdls(dev[0], dev[1], hapd)
  179. def test_ap_wpa2_tdls_decline_resp(dev, apdev):
  180. """Decline TDLS Setup Response"""
  181. hapd = start_ap_wpa2_psk(apdev[0])
  182. wlantest_setup(hapd)
  183. connect_2sta_wpa2_psk(dev, hapd)
  184. dev[1].request("SET tdls_testing 0x200")
  185. setup_tdls(dev[1], dev[0], hapd, expect_fail=True)
  186. def test_ap_wpa2_tdls_long_lifetime(dev, apdev):
  187. """TDLS with long TPK lifetime"""
  188. hapd = start_ap_wpa2_psk(apdev[0])
  189. wlantest_setup(hapd)
  190. connect_2sta_wpa2_psk(dev, hapd)
  191. dev[1].request("SET tdls_testing 0x40")
  192. setup_tdls(dev[1], dev[0], hapd)
  193. def test_ap_wpa2_tdls_long_frame(dev, apdev):
  194. """TDLS with long setup/teardown frames"""
  195. hapd = start_ap_wpa2_psk(apdev[0])
  196. wlantest_setup(hapd)
  197. connect_2sta_wpa2_psk(dev, hapd)
  198. dev[0].request("SET tdls_testing 0x1")
  199. dev[1].request("SET tdls_testing 0x1")
  200. setup_tdls(dev[1], dev[0], hapd)
  201. teardown_tdls(dev[1], dev[0], hapd)
  202. setup_tdls(dev[0], dev[1], hapd)
  203. def test_ap_wpa2_tdls_reneg(dev, apdev):
  204. """Renegotiate TDLS link"""
  205. hapd = start_ap_wpa2_psk(apdev[0])
  206. wlantest_setup(hapd)
  207. connect_2sta_wpa2_psk(dev, hapd)
  208. setup_tdls(dev[1], dev[0], hapd)
  209. setup_tdls(dev[0], dev[1], hapd)
  210. def test_ap_wpa2_tdls_wrong_lifetime_resp(dev, apdev):
  211. """Incorrect TPK lifetime in TDLS Setup Response"""
  212. hapd = start_ap_wpa2_psk(apdev[0])
  213. wlantest_setup(hapd)
  214. connect_2sta_wpa2_psk(dev, hapd)
  215. dev[1].request("SET tdls_testing 0x10")
  216. setup_tdls(dev[0], dev[1], hapd, expect_fail=True)
  217. def test_ap_wpa2_tdls_diff_rsnie(dev, apdev):
  218. """TDLS with different RSN IEs"""
  219. hapd = start_ap_wpa2_psk(apdev[0])
  220. wlantest_setup(hapd)
  221. connect_2sta_wpa2_psk(dev, hapd)
  222. dev[1].request("SET tdls_testing 0x2")
  223. setup_tdls(dev[1], dev[0], hapd)
  224. teardown_tdls(dev[1], dev[0], hapd)
  225. def test_ap_wpa2_tdls_wrong_tpk_m2_mic(dev, apdev):
  226. """Incorrect MIC in TDLS Setup Response"""
  227. hapd = start_ap_wpa2_psk(apdev[0])
  228. wlantest_setup(hapd)
  229. connect_2sta_wpa2_psk(dev, hapd)
  230. dev[0].request("SET tdls_testing 0x800")
  231. addr0 = dev[0].p2p_interface_addr()
  232. dev[1].tdls_setup(addr0)
  233. time.sleep(1)
  234. def test_ap_wpa2_tdls_wrong_tpk_m3_mic(dev, apdev):
  235. """Incorrect MIC in TDLS Setup Confirm"""
  236. hapd = start_ap_wpa2_psk(apdev[0])
  237. wlantest_setup(hapd)
  238. connect_2sta_wpa2_psk(dev, hapd)
  239. dev[1].request("SET tdls_testing 0x800")
  240. addr0 = dev[0].p2p_interface_addr()
  241. dev[1].tdls_setup(addr0)
  242. time.sleep(1)
  243. def test_ap_wpa2_tdls_double_tpk_m2(dev, apdev):
  244. """Double TPK M2 during TDLS setup initiation"""
  245. hapd = start_ap_wpa2_psk(apdev[0])
  246. wlantest_setup(hapd)
  247. connect_2sta_wpa2_psk(dev, hapd)
  248. dev[0].request("SET tdls_testing 0x1000")
  249. setup_tdls(dev[1], dev[0], hapd)
  250. def test_ap_wpa_tdls(dev, apdev):
  251. """WPA-PSK AP and two stations using TDLS"""
  252. skip_with_fips(dev[0])
  253. hapd = hostapd.add_ap(apdev[0],
  254. hostapd.wpa_params(ssid="test-wpa-psk",
  255. passphrase="12345678"))
  256. wlantest_setup(hapd)
  257. connect_2sta_wpa_psk(dev, hapd)
  258. setup_tdls(dev[0], dev[1], hapd)
  259. teardown_tdls(dev[0], dev[1], hapd)
  260. setup_tdls(dev[1], dev[0], hapd)
  261. def test_ap_wpa_mixed_tdls(dev, apdev):
  262. """WPA+WPA2-PSK AP and two stations using TDLS"""
  263. skip_with_fips(dev[0])
  264. hapd = hostapd.add_ap(apdev[0],
  265. hostapd.wpa_mixed_params(ssid="test-wpa-mixed-psk",
  266. passphrase="12345678"))
  267. wlantest_setup(hapd)
  268. connect_2sta_wpa_psk_mixed(dev, hapd)
  269. setup_tdls(dev[0], dev[1], hapd)
  270. teardown_tdls(dev[0], dev[1], hapd)
  271. setup_tdls(dev[1], dev[0], hapd)
  272. def test_ap_wep_tdls(dev, apdev):
  273. """WEP AP and two stations using TDLS"""
  274. hapd = hostapd.add_ap(apdev[0],
  275. { "ssid": "test-wep", "wep_key0": '"hello"' })
  276. wlantest_setup(hapd)
  277. connect_2sta_wep(dev, hapd)
  278. setup_tdls(dev[0], dev[1], hapd)
  279. teardown_tdls(dev[0], dev[1], hapd)
  280. setup_tdls(dev[1], dev[0], hapd)
  281. def test_ap_open_tdls(dev, apdev):
  282. """Open AP and two stations using TDLS"""
  283. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
  284. wlantest_setup(hapd)
  285. connect_2sta_open(dev, hapd)
  286. setup_tdls(dev[0], dev[1], hapd)
  287. teardown_tdls(dev[0], dev[1], hapd)
  288. setup_tdls(dev[1], dev[0], hapd)
  289. teardown_tdls(dev[1], dev[0], hapd, wildcard=True)
  290. def test_ap_wpa2_tdls_bssid_mismatch(dev, apdev):
  291. """TDLS failure due to BSSID mismatch"""
  292. try:
  293. ssid = "test-wpa2-psk"
  294. passphrase = "12345678"
  295. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  296. params['bridge'] = 'ap-br0'
  297. hapd = hostapd.add_ap(apdev[0], params)
  298. hostapd.add_ap(apdev[1], params)
  299. wlantest_setup(hapd)
  300. subprocess.call(['brctl', 'setfd', 'ap-br0', '0'])
  301. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
  302. dev[0].connect(ssid, psk=passphrase, scan_freq="2412",
  303. bssid=apdev[0]['bssid'])
  304. dev[1].connect(ssid, psk=passphrase, scan_freq="2412",
  305. bssid=apdev[1]['bssid'])
  306. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  307. hwsim_utils.test_connectivity_iface(dev[0], hapd, "ap-br0")
  308. hwsim_utils.test_connectivity_iface(dev[1], hapd, "ap-br0")
  309. addr0 = dev[0].p2p_interface_addr()
  310. dev[1].tdls_setup(addr0)
  311. time.sleep(1)
  312. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  313. finally:
  314. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'])
  315. subprocess.call(['brctl', 'delbr', 'ap-br0'])
  316. def test_ap_wpa2_tdls_responder_teardown(dev, apdev):
  317. """TDLS teardown from responder with WPA2-PSK AP"""
  318. hapd = start_ap_wpa2_psk(apdev[0])
  319. wlantest_setup(hapd)
  320. connect_2sta_wpa2_psk(dev, hapd)
  321. setup_tdls(dev[0], dev[1], hapd)
  322. teardown_tdls(dev[0], dev[1], hapd, responder=True)
  323. def test_ap_open_tdls_vht(dev, apdev):
  324. """Open AP and two stations using TDLS"""
  325. params = { "ssid": "test-open",
  326. "country_code": "DE",
  327. "hw_mode": "a",
  328. "channel": "36",
  329. "ieee80211n": "1",
  330. "ieee80211ac": "1",
  331. "ht_capab": "",
  332. "vht_capab": "",
  333. "vht_oper_chwidth": "0",
  334. "vht_oper_centr_freq_seg0_idx": "0" }
  335. hapd = None
  336. try:
  337. hapd = hostapd.add_ap(apdev[0], params)
  338. wlantest_setup(hapd)
  339. connect_2sta_open(dev, hapd, scan_freq="5180")
  340. setup_tdls(dev[0], dev[1], hapd)
  341. teardown_tdls(dev[0], dev[1], hapd)
  342. setup_tdls(dev[1], dev[0], hapd)
  343. teardown_tdls(dev[1], dev[0], hapd, wildcard=True)
  344. finally:
  345. dev[0].request("DISCONNECT")
  346. dev[1].request("DISCONNECT")
  347. if hapd:
  348. hapd.request("DISABLE")
  349. subprocess.call(['iw', 'reg', 'set', '00'])
  350. dev[0].flush_scan_cache()
  351. dev[1].flush_scan_cache()
  352. def test_ap_open_tdls_vht80(dev, apdev):
  353. """Open AP and two stations using TDLS with VHT 80"""
  354. params = { "ssid": "test-open",
  355. "country_code": "US",
  356. "hw_mode": "a",
  357. "channel": "36",
  358. "ht_capab": "[HT40+]",
  359. "ieee80211n": "1",
  360. "ieee80211ac": "1",
  361. "vht_capab": "",
  362. "vht_oper_chwidth": "1",
  363. "vht_oper_centr_freq_seg0_idx": "42" }
  364. try:
  365. hapd = None
  366. hapd = hostapd.add_ap(apdev[0], params)
  367. wlantest_setup(hapd)
  368. connect_2sta_open(dev, hapd, scan_freq="5180")
  369. sig = dev[0].request("SIGNAL_POLL").splitlines()
  370. if "WIDTH=80 MHz" not in sig:
  371. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  372. setup_tdls(dev[0], dev[1], hapd)
  373. for i in range(10):
  374. check_connectivity(dev[0], dev[1], hapd)
  375. for i in range(2):
  376. cmd = subprocess.Popen(['iw', dev[0].ifname, 'station', 'dump'],
  377. stdout=subprocess.PIPE)
  378. res = cmd.stdout.read()
  379. cmd.stdout.close()
  380. logger.info("Station dump on dev[%d]:\n%s" % (i, res))
  381. except Exception, e:
  382. if isinstance(e, Exception) and str(e) == "AP startup failed":
  383. if not vht_supported():
  384. raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
  385. raise
  386. finally:
  387. dev[0].request("DISCONNECT")
  388. dev[1].request("DISCONNECT")
  389. if hapd:
  390. hapd.request("DISABLE")
  391. subprocess.call(['iw', 'reg', 'set', '00'])
  392. dev[0].flush_scan_cache()
  393. dev[1].flush_scan_cache()
  394. def test_ap_open_tdls_vht80plus80(dev, apdev):
  395. """Open AP and two stations using TDLS with VHT 80+80"""
  396. params = { "ssid": "test-open",
  397. "country_code": "US",
  398. "hw_mode": "a",
  399. "channel": "36",
  400. "ht_capab": "[HT40+]",
  401. "ieee80211n": "1",
  402. "ieee80211ac": "1",
  403. "vht_capab": "",
  404. "vht_oper_chwidth": "3",
  405. "vht_oper_centr_freq_seg0_idx": "42",
  406. "vht_oper_centr_freq_seg1_idx": "155" }
  407. try:
  408. hapd = None
  409. hapd = hostapd.add_ap(apdev[0], params)
  410. wlantest_setup(hapd)
  411. connect_2sta_open(dev, hapd, scan_freq="5180")
  412. sig = dev[0].request("SIGNAL_POLL").splitlines()
  413. if "FREQUENCY=5180" not in sig:
  414. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  415. if "WIDTH=80+80 MHz" not in sig:
  416. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  417. if "CENTER_FRQ1=5210" not in sig:
  418. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  419. if "CENTER_FRQ2=5775" not in sig:
  420. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  421. setup_tdls(dev[0], dev[1], hapd)
  422. for i in range(10):
  423. check_connectivity(dev[0], dev[1], hapd)
  424. for i in range(2):
  425. cmd = subprocess.Popen(['iw', dev[0].ifname, 'station', 'dump'],
  426. stdout=subprocess.PIPE)
  427. res = cmd.stdout.read()
  428. cmd.stdout.close()
  429. logger.info("Station dump on dev[%d]:\n%s" % (i, res))
  430. except Exception, e:
  431. if isinstance(e, Exception) and str(e) == "AP startup failed":
  432. if not vht_supported():
  433. raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
  434. raise
  435. finally:
  436. dev[0].request("DISCONNECT")
  437. dev[1].request("DISCONNECT")
  438. if hapd:
  439. hapd.request("DISABLE")
  440. subprocess.call(['iw', 'reg', 'set', '00'])
  441. dev[0].flush_scan_cache()
  442. dev[1].flush_scan_cache()
  443. def test_ap_open_tdls_vht160(dev, apdev):
  444. """Open AP and two stations using TDLS with VHT 160"""
  445. params = { "ssid": "test-open",
  446. "country_code": "ZA",
  447. "hw_mode": "a",
  448. "channel": "104",
  449. "ht_capab": "[HT40-]",
  450. "ieee80211n": "1",
  451. "ieee80211ac": "1",
  452. "vht_oper_chwidth": "2",
  453. "vht_oper_centr_freq_seg0_idx": "114" }
  454. try:
  455. hapd = None
  456. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  457. ev = hapd.wait_event(["AP-ENABLED"], timeout=2)
  458. if not ev:
  459. cmd = subprocess.Popen(["iw", "reg", "get"], stdout=subprocess.PIPE)
  460. reg = cmd.stdout.readlines()
  461. for r in reg:
  462. if "5490" in r and "DFS" in r:
  463. raise HwsimSkip("ZA regulatory rule did not have DFS requirement removed")
  464. raise Exception("AP setup timed out")
  465. wlantest_setup(hapd)
  466. connect_2sta_open(dev, hapd, scan_freq="5520")
  467. sig = dev[0].request("SIGNAL_POLL").splitlines()
  468. if "WIDTH=160 MHz" not in sig:
  469. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  470. setup_tdls(dev[0], dev[1], hapd)
  471. for i in range(10):
  472. check_connectivity(dev[0], dev[1], hapd)
  473. for i in range(2):
  474. cmd = subprocess.Popen(['iw', dev[0].ifname, 'station', 'dump'],
  475. stdout=subprocess.PIPE)
  476. res = cmd.stdout.read()
  477. cmd.stdout.close()
  478. logger.info("Station dump on dev[%d]:\n%s" % (i, res))
  479. except Exception, e:
  480. if isinstance(e, Exception) and str(e) == "AP startup failed":
  481. if not vht_supported():
  482. raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
  483. raise
  484. finally:
  485. dev[0].request("DISCONNECT")
  486. dev[1].request("DISCONNECT")
  487. if hapd:
  488. hapd.request("DISABLE")
  489. subprocess.call(['iw', 'reg', 'set', '00'])
  490. dev[0].flush_scan_cache()
  491. dev[1].flush_scan_cache()
  492. def test_tdls_chan_switch(dev, apdev):
  493. """Open AP and two stations using TDLS"""
  494. flags = int(dev[0].get_driver_status_field('capa.flags'), 16)
  495. if flags & 0x800000000 == 0:
  496. raise HwsimSkip("Driver does not support TDLS channel switching")
  497. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
  498. wlantest_setup(hapd)
  499. connect_2sta_open(dev, hapd)
  500. setup_tdls(dev[0], dev[1], hapd)
  501. if "OK" not in dev[0].request("TDLS_CHAN_SWITCH " + dev[1].own_addr() + " 81 2462"):
  502. raise Exception("Failed to enable TDLS channel switching")
  503. if "OK" not in dev[0].request("TDLS_CANCEL_CHAN_SWITCH " + dev[1].own_addr()):
  504. raise Exception("Could not disable TDLS channel switching")
  505. if "FAIL" not in dev[0].request("TDLS_CANCEL_CHAN_SWITCH " + dev[1].own_addr()):
  506. raise Exception("TDLS_CANCEL_CHAN_SWITCH accepted even though channel switching was already disabled")
  507. if "FAIL" not in dev[0].request("TDLS_CHAN_SWITCH foo 81 2462"):
  508. raise Exception("Invalid TDLS channel switching command accepted")
  509. def test_ap_tdls_link_status(dev, apdev):
  510. """Check TDLS link status between two stations"""
  511. hapd = start_ap_wpa2_psk(apdev[0])
  512. wlantest_setup(hapd)
  513. connect_2sta_wpa2_psk(dev, hapd)
  514. check_tdls_link(dev[0], dev[1], connected=False)
  515. setup_tdls(dev[0], dev[1], hapd)
  516. check_tdls_link(dev[0], dev[1], connected=True)
  517. teardown_tdls(dev[0], dev[1], hapd)
  518. check_tdls_link(dev[0], dev[1], connected=False)
  519. if "FAIL" not in dev[0].request("TDLS_LINK_STATUS foo"):
  520. raise Exception("Unexpected TDLS_LINK_STATUS response for invalid argument")
  521. def test_ap_tdls_prohibit(dev, apdev):
  522. """Open AP and TDLS prohibited"""
  523. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open",
  524. "tdls_prohibit": "1" })
  525. connect_2sta_open(dev, hapd)
  526. if "FAIL" not in dev[0].request("TDLS_SETUP " + dev[1].own_addr()):
  527. raise Exception("TDLS_SETUP accepted unexpectedly")
  528. def test_ap_tdls_chan_switch_prohibit(dev, apdev):
  529. """Open AP and TDLS channel switch prohibited"""
  530. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open",
  531. "tdls_prohibit_chan_switch": "1" })
  532. wlantest_setup(hapd)
  533. connect_2sta_open(dev, hapd)
  534. setup_tdls(dev[0], dev[1], hapd)
  535. def test_ap_open_tdls_external_control(dev, apdev):
  536. """TDLS and tdls_external_control"""
  537. try:
  538. _test_ap_open_tdls_external_control(dev, apdev)
  539. finally:
  540. dev[0].set("tdls_external_control", "0")
  541. def _test_ap_open_tdls_external_control(dev, apdev):
  542. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
  543. dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412")
  544. dev[1].connect("test-open", key_mgmt="NONE", scan_freq="2412")
  545. addr0 = dev[0].own_addr()
  546. addr1 = dev[1].own_addr()
  547. dev[0].set("tdls_external_control", "1")
  548. if "FAIL" in dev[0].request("TDLS_SETUP " + addr1):
  549. # tdls_external_control not supported; try without it
  550. dev[0].set("tdls_external_control", "0")
  551. if "FAIL" in dev[0].request("TDLS_SETUP " + addr1):
  552. raise Exception("TDLS_SETUP failed")
  553. connected = False
  554. for i in range(50):
  555. res0 = dev[0].request("TDLS_LINK_STATUS " + addr1)
  556. res1 = dev[1].request("TDLS_LINK_STATUS " + addr0)
  557. if "TDLS link status: connected" in res0 and "TDLS link status: connected" in res1:
  558. connected = True
  559. break
  560. time.sleep(0.1)
  561. if not connected:
  562. raise Exception("TDLS setup did not complete")
  563. dev[0].set("tdls_external_control", "1")
  564. if "FAIL" in dev[0].request("TDLS_TEARDOWN " + addr1):
  565. # tdls_external_control not supported; try without it
  566. dev[0].set("tdls_external_control", "0")
  567. if "FAIL" in dev[0].request("TDLS_TEARDOWN " + addr1):
  568. raise Exception("TDLS_TEARDOWN failed")
  569. for i in range(50):
  570. res0 = dev[0].request("TDLS_LINK_STATUS " + addr1)
  571. res1 = dev[1].request("TDLS_LINK_STATUS " + addr0)
  572. if "TDLS link status: connected" not in res0 and "TDLS link status: connected" not in res1:
  573. connected = False
  574. break
  575. time.sleep(0.1)
  576. if connected:
  577. raise Exception("TDLS teardown did not complete")