test_ap_tdls.py 21 KB

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