test_ap_tdls.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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_wpa_tdls(dev, apdev):
  244. """WPA-PSK AP and two stations using TDLS"""
  245. skip_with_fips(dev[0])
  246. hapd = hostapd.add_ap(apdev[0],
  247. hostapd.wpa_params(ssid="test-wpa-psk",
  248. passphrase="12345678"))
  249. wlantest_setup(hapd)
  250. connect_2sta_wpa_psk(dev, hapd)
  251. setup_tdls(dev[0], dev[1], hapd)
  252. teardown_tdls(dev[0], dev[1], hapd)
  253. setup_tdls(dev[1], dev[0], hapd)
  254. def test_ap_wpa_mixed_tdls(dev, apdev):
  255. """WPA+WPA2-PSK AP and two stations using TDLS"""
  256. skip_with_fips(dev[0])
  257. hapd = hostapd.add_ap(apdev[0],
  258. hostapd.wpa_mixed_params(ssid="test-wpa-mixed-psk",
  259. passphrase="12345678"))
  260. wlantest_setup(hapd)
  261. connect_2sta_wpa_psk_mixed(dev, hapd)
  262. setup_tdls(dev[0], dev[1], hapd)
  263. teardown_tdls(dev[0], dev[1], hapd)
  264. setup_tdls(dev[1], dev[0], hapd)
  265. def test_ap_wep_tdls(dev, apdev):
  266. """WEP AP and two stations using TDLS"""
  267. hapd = hostapd.add_ap(apdev[0],
  268. { "ssid": "test-wep", "wep_key0": '"hello"' })
  269. wlantest_setup(hapd)
  270. connect_2sta_wep(dev, hapd)
  271. setup_tdls(dev[0], dev[1], hapd)
  272. teardown_tdls(dev[0], dev[1], hapd)
  273. setup_tdls(dev[1], dev[0], hapd)
  274. def test_ap_open_tdls(dev, apdev):
  275. """Open AP and two stations using TDLS"""
  276. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
  277. wlantest_setup(hapd)
  278. connect_2sta_open(dev, hapd)
  279. setup_tdls(dev[0], dev[1], hapd)
  280. teardown_tdls(dev[0], dev[1], hapd)
  281. setup_tdls(dev[1], dev[0], hapd)
  282. teardown_tdls(dev[1], dev[0], hapd, wildcard=True)
  283. def test_ap_wpa2_tdls_bssid_mismatch(dev, apdev):
  284. """TDLS failure due to BSSID mismatch"""
  285. try:
  286. ssid = "test-wpa2-psk"
  287. passphrase = "12345678"
  288. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  289. params['bridge'] = 'ap-br0'
  290. hapd = hostapd.add_ap(apdev[0], params)
  291. hostapd.add_ap(apdev[1], params)
  292. wlantest_setup(hapd)
  293. subprocess.call(['brctl', 'setfd', 'ap-br0', '0'])
  294. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
  295. dev[0].connect(ssid, psk=passphrase, scan_freq="2412",
  296. bssid=apdev[0]['bssid'])
  297. dev[1].connect(ssid, psk=passphrase, scan_freq="2412",
  298. bssid=apdev[1]['bssid'])
  299. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  300. hwsim_utils.test_connectivity_iface(dev[0], hapd, "ap-br0")
  301. hwsim_utils.test_connectivity_iface(dev[1], hapd, "ap-br0")
  302. addr0 = dev[0].p2p_interface_addr()
  303. dev[1].tdls_setup(addr0)
  304. time.sleep(1)
  305. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  306. finally:
  307. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'])
  308. subprocess.call(['brctl', 'delbr', 'ap-br0'])
  309. def test_ap_wpa2_tdls_responder_teardown(dev, apdev):
  310. """TDLS teardown from responder with WPA2-PSK AP"""
  311. hapd = start_ap_wpa2_psk(apdev[0])
  312. wlantest_setup(hapd)
  313. connect_2sta_wpa2_psk(dev, hapd)
  314. setup_tdls(dev[0], dev[1], hapd)
  315. teardown_tdls(dev[0], dev[1], hapd, responder=True)
  316. def test_ap_open_tdls_vht(dev, apdev):
  317. """Open AP and two stations using TDLS"""
  318. params = { "ssid": "test-open",
  319. "country_code": "DE",
  320. "hw_mode": "a",
  321. "channel": "36",
  322. "ieee80211n": "1",
  323. "ieee80211ac": "1",
  324. "ht_capab": "",
  325. "vht_capab": "",
  326. "vht_oper_chwidth": "0",
  327. "vht_oper_centr_freq_seg0_idx": "0" }
  328. hapd = None
  329. try:
  330. hapd = hostapd.add_ap(apdev[0], params)
  331. wlantest_setup(hapd)
  332. connect_2sta_open(dev, hapd, scan_freq="5180")
  333. setup_tdls(dev[0], dev[1], hapd)
  334. teardown_tdls(dev[0], dev[1], hapd)
  335. setup_tdls(dev[1], dev[0], hapd)
  336. teardown_tdls(dev[1], dev[0], hapd, wildcard=True)
  337. finally:
  338. dev[0].request("DISCONNECT")
  339. dev[1].request("DISCONNECT")
  340. if hapd:
  341. hapd.request("DISABLE")
  342. subprocess.call(['iw', 'reg', 'set', '00'])
  343. dev[0].flush_scan_cache()
  344. dev[1].flush_scan_cache()
  345. def test_ap_open_tdls_vht80(dev, apdev):
  346. """Open AP and two stations using TDLS with VHT 80"""
  347. params = { "ssid": "test-open",
  348. "country_code": "US",
  349. "hw_mode": "a",
  350. "channel": "36",
  351. "ht_capab": "[HT40+]",
  352. "ieee80211n": "1",
  353. "ieee80211ac": "1",
  354. "vht_capab": "",
  355. "vht_oper_chwidth": "1",
  356. "vht_oper_centr_freq_seg0_idx": "42" }
  357. try:
  358. hapd = None
  359. hapd = hostapd.add_ap(apdev[0], params)
  360. wlantest_setup(hapd)
  361. connect_2sta_open(dev, hapd, scan_freq="5180")
  362. sig = dev[0].request("SIGNAL_POLL").splitlines()
  363. if "WIDTH=80 MHz" not in sig:
  364. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  365. setup_tdls(dev[0], dev[1], hapd)
  366. for i in range(10):
  367. check_connectivity(dev[0], dev[1], hapd)
  368. for i in range(2):
  369. cmd = subprocess.Popen(['iw', dev[0].ifname, 'station', 'dump'],
  370. stdout=subprocess.PIPE)
  371. res = cmd.stdout.read()
  372. cmd.stdout.close()
  373. logger.info("Station dump on dev[%d]:\n%s" % (i, res))
  374. except Exception, e:
  375. if isinstance(e, Exception) and str(e) == "AP startup failed":
  376. if not vht_supported():
  377. raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
  378. raise
  379. finally:
  380. dev[0].request("DISCONNECT")
  381. dev[1].request("DISCONNECT")
  382. if hapd:
  383. hapd.request("DISABLE")
  384. subprocess.call(['iw', 'reg', 'set', '00'])
  385. dev[0].flush_scan_cache()
  386. dev[1].flush_scan_cache()
  387. def test_ap_open_tdls_vht80plus80(dev, apdev):
  388. """Open AP and two stations using TDLS with VHT 80+80"""
  389. params = { "ssid": "test-open",
  390. "country_code": "US",
  391. "hw_mode": "a",
  392. "channel": "36",
  393. "ht_capab": "[HT40+]",
  394. "ieee80211n": "1",
  395. "ieee80211ac": "1",
  396. "vht_capab": "",
  397. "vht_oper_chwidth": "3",
  398. "vht_oper_centr_freq_seg0_idx": "42",
  399. "vht_oper_centr_freq_seg1_idx": "155" }
  400. try:
  401. hapd = None
  402. hapd = hostapd.add_ap(apdev[0], params)
  403. wlantest_setup(hapd)
  404. connect_2sta_open(dev, hapd, scan_freq="5180")
  405. sig = dev[0].request("SIGNAL_POLL").splitlines()
  406. if "FREQUENCY=5180" not in sig:
  407. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  408. if "WIDTH=80+80 MHz" not in sig:
  409. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  410. if "CENTER_FRQ1=5210" not in sig:
  411. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  412. if "CENTER_FRQ2=5775" not in sig:
  413. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  414. setup_tdls(dev[0], dev[1], hapd)
  415. for i in range(10):
  416. check_connectivity(dev[0], dev[1], hapd)
  417. for i in range(2):
  418. cmd = subprocess.Popen(['iw', dev[0].ifname, 'station', 'dump'],
  419. stdout=subprocess.PIPE)
  420. res = cmd.stdout.read()
  421. cmd.stdout.close()
  422. logger.info("Station dump on dev[%d]:\n%s" % (i, res))
  423. except Exception, e:
  424. if isinstance(e, Exception) and str(e) == "AP startup failed":
  425. if not vht_supported():
  426. raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
  427. raise
  428. finally:
  429. dev[0].request("DISCONNECT")
  430. dev[1].request("DISCONNECT")
  431. if hapd:
  432. hapd.request("DISABLE")
  433. subprocess.call(['iw', 'reg', 'set', '00'])
  434. dev[0].flush_scan_cache()
  435. dev[1].flush_scan_cache()
  436. def test_ap_open_tdls_vht160(dev, apdev):
  437. """Open AP and two stations using TDLS with VHT 160"""
  438. params = { "ssid": "test-open",
  439. "country_code": "ZA",
  440. "hw_mode": "a",
  441. "channel": "104",
  442. "ht_capab": "[HT40-]",
  443. "ieee80211n": "1",
  444. "ieee80211ac": "1",
  445. "vht_oper_chwidth": "2",
  446. "vht_oper_centr_freq_seg0_idx": "114" }
  447. try:
  448. hapd = None
  449. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  450. ev = hapd.wait_event(["AP-ENABLED"], timeout=2)
  451. if not ev:
  452. cmd = subprocess.Popen(["iw", "reg", "get"], stdout=subprocess.PIPE)
  453. reg = cmd.stdout.readlines()
  454. for r in reg:
  455. if "5490" in r and "DFS" in r:
  456. raise HwsimSkip("ZA regulatory rule did not have DFS requirement removed")
  457. raise Exception("AP setup timed out")
  458. wlantest_setup(hapd)
  459. connect_2sta_open(dev, hapd, scan_freq="5520")
  460. sig = dev[0].request("SIGNAL_POLL").splitlines()
  461. if "WIDTH=160 MHz" not in sig:
  462. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  463. setup_tdls(dev[0], dev[1], hapd)
  464. for i in range(10):
  465. check_connectivity(dev[0], dev[1], hapd)
  466. for i in range(2):
  467. cmd = subprocess.Popen(['iw', dev[0].ifname, 'station', 'dump'],
  468. stdout=subprocess.PIPE)
  469. res = cmd.stdout.read()
  470. cmd.stdout.close()
  471. logger.info("Station dump on dev[%d]:\n%s" % (i, res))
  472. except Exception, e:
  473. if isinstance(e, Exception) and str(e) == "AP startup failed":
  474. if not vht_supported():
  475. raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
  476. raise
  477. finally:
  478. dev[0].request("DISCONNECT")
  479. dev[1].request("DISCONNECT")
  480. if hapd:
  481. hapd.request("DISABLE")
  482. subprocess.call(['iw', 'reg', 'set', '00'])
  483. dev[0].flush_scan_cache()
  484. dev[1].flush_scan_cache()
  485. def test_tdls_chan_switch(dev, apdev):
  486. """Open AP and two stations using TDLS"""
  487. flags = int(dev[0].get_driver_status_field('capa.flags'), 16)
  488. if flags & 0x800000000 == 0:
  489. raise HwsimSkip("Driver does not support TDLS channel switching")
  490. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
  491. wlantest_setup(hapd)
  492. connect_2sta_open(dev, hapd)
  493. setup_tdls(dev[0], dev[1], hapd)
  494. if "OK" not in dev[0].request("TDLS_CHAN_SWITCH " + dev[1].own_addr() + " 81 2462"):
  495. raise Exception("Failed to enable TDLS channel switching")
  496. if "OK" not in dev[0].request("TDLS_CANCEL_CHAN_SWITCH " + dev[1].own_addr()):
  497. raise Exception("Could not disable TDLS channel switching")
  498. if "FAIL" not in dev[0].request("TDLS_CANCEL_CHAN_SWITCH " + dev[1].own_addr()):
  499. raise Exception("TDLS_CANCEL_CHAN_SWITCH accepted even though channel switching was already disabled")
  500. def test_ap_tdls_link_status(dev, apdev):
  501. """Check TDLS link status between two stations"""
  502. hapd = start_ap_wpa2_psk(apdev[0])
  503. wlantest_setup(hapd)
  504. connect_2sta_wpa2_psk(dev, hapd)
  505. check_tdls_link(dev[0], dev[1], connected=False)
  506. setup_tdls(dev[0], dev[1], hapd)
  507. check_tdls_link(dev[0], dev[1], connected=True)
  508. teardown_tdls(dev[0], dev[1], hapd)
  509. check_tdls_link(dev[0], dev[1], connected=False)
  510. if "FAIL" not in dev[0].request("TDLS_LINK_STATUS foo"):
  511. raise Exception("Unexpected TDLS_LINK_STATUS response for invalid argument")