test_ap_tdls.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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(ifname):
  18. params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678")
  19. return hostapd.add_ap(ifname, 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():
  49. wt = Wlantest()
  50. wt.flush()
  51. wt.add_passphrase("12345678")
  52. wt.add_wepkey("68656c6c6f")
  53. def wlantest_tdls_packet_counters(bssid, addr0, addr1):
  54. wt = Wlantest()
  55. dl = wt.get_tdls_counter("valid_direct_link", bssid, addr0, addr1)
  56. inv_dl = wt.get_tdls_counter("invalid_direct_link", bssid, addr0, addr1)
  57. ap = wt.get_tdls_counter("valid_ap_path", bssid, addr0, addr1)
  58. inv_ap = wt.get_tdls_counter("invalid_ap_path", bssid, addr0, addr1)
  59. return [dl,inv_dl,ap,inv_ap]
  60. def tdls_check_dl(sta0, sta1, bssid, addr0, addr1):
  61. wt = Wlantest()
  62. wt.tdls_clear(bssid, addr0, addr1)
  63. hwsim_utils.test_connectivity_sta(sta0, sta1)
  64. [dl,inv_dl,ap,inv_ap] = wlantest_tdls_packet_counters(bssid, addr0, addr1)
  65. if dl == 0:
  66. raise Exception("No valid frames through direct link")
  67. if inv_dl > 0:
  68. raise Exception("Invalid frames through direct link")
  69. if ap > 0:
  70. raise Exception("Unexpected frames through AP path")
  71. if inv_ap > 0:
  72. raise Exception("Invalid frames through AP path")
  73. def tdls_check_ap(sta0, sta1, bssid, addr0, addr1):
  74. wt = Wlantest()
  75. wt.tdls_clear(bssid, addr0, addr1);
  76. hwsim_utils.test_connectivity_sta(sta0, sta1)
  77. [dl,inv_dl,ap,inv_ap] = wlantest_tdls_packet_counters(bssid, addr0, addr1)
  78. if dl > 0:
  79. raise Exception("Unexpected frames through direct link")
  80. if inv_dl > 0:
  81. raise Exception("Invalid frames through direct link")
  82. if ap == 0:
  83. raise Exception("No valid frames through AP path")
  84. if inv_ap > 0:
  85. raise Exception("Invalid frames through AP path")
  86. def check_connectivity(sta0, sta1, hapd):
  87. hwsim_utils.test_connectivity_sta(sta0, sta1)
  88. hwsim_utils.test_connectivity(sta0, hapd)
  89. hwsim_utils.test_connectivity(sta1, hapd)
  90. def setup_tdls(sta0, sta1, ap, reverse=False, expect_fail=False):
  91. logger.info("Setup TDLS")
  92. hapd = hostapd.Hostapd(ap['ifname'])
  93. check_connectivity(sta0, sta1, hapd)
  94. bssid = ap['bssid']
  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, ap, responder=False, wildcard=False):
  114. logger.info("Teardown TDLS")
  115. hapd = hostapd.Hostapd(ap['ifname'])
  116. check_connectivity(sta0, sta1, hapd)
  117. bssid = ap['bssid']
  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. def test_ap_tdls_discovery(dev, apdev):
  149. """WPA2-PSK AP and two stations using TDLS discovery"""
  150. hapd = start_ap_wpa2_psk(apdev[0]['ifname'])
  151. wlantest_setup()
  152. connect_2sta_wpa2_psk(dev, hapd)
  153. dev[0].request("TDLS_DISCOVER " + dev[1].p2p_interface_addr())
  154. time.sleep(0.2)
  155. def test_ap_wpa2_tdls(dev, apdev):
  156. """WPA2-PSK AP and two stations using TDLS"""
  157. hapd = start_ap_wpa2_psk(apdev[0]['ifname'])
  158. wlantest_setup()
  159. connect_2sta_wpa2_psk(dev, hapd)
  160. setup_tdls(dev[0], dev[1], apdev[0])
  161. teardown_tdls(dev[0], dev[1], apdev[0])
  162. setup_tdls(dev[1], dev[0], apdev[0])
  163. #teardown_tdls(dev[0], dev[1], apdev[0])
  164. def test_ap_wpa2_tdls_concurrent_init(dev, apdev):
  165. """Concurrent TDLS setup initiation"""
  166. hapd = start_ap_wpa2_psk(apdev[0]['ifname'])
  167. wlantest_setup()
  168. connect_2sta_wpa2_psk(dev, hapd)
  169. dev[0].request("SET tdls_testing 0x80")
  170. setup_tdls(dev[1], dev[0], apdev[0], reverse=True)
  171. def test_ap_wpa2_tdls_concurrent_init2(dev, apdev):
  172. """Concurrent TDLS setup initiation (reverse)"""
  173. hapd = start_ap_wpa2_psk(apdev[0]['ifname'])
  174. wlantest_setup()
  175. connect_2sta_wpa2_psk(dev, hapd)
  176. dev[1].request("SET tdls_testing 0x80")
  177. setup_tdls(dev[0], dev[1], apdev[0])
  178. def test_ap_wpa2_tdls_decline_resp(dev, apdev):
  179. """Decline TDLS Setup Response"""
  180. hapd = start_ap_wpa2_psk(apdev[0]['ifname'])
  181. wlantest_setup()
  182. connect_2sta_wpa2_psk(dev, hapd)
  183. dev[1].request("SET tdls_testing 0x200")
  184. setup_tdls(dev[1], dev[0], apdev[0], expect_fail=True)
  185. def test_ap_wpa2_tdls_long_lifetime(dev, apdev):
  186. """TDLS with long TPK lifetime"""
  187. hapd = start_ap_wpa2_psk(apdev[0]['ifname'])
  188. wlantest_setup()
  189. connect_2sta_wpa2_psk(dev, hapd)
  190. dev[1].request("SET tdls_testing 0x40")
  191. setup_tdls(dev[1], dev[0], apdev[0])
  192. def test_ap_wpa2_tdls_long_frame(dev, apdev):
  193. """TDLS with long setup/teardown frames"""
  194. hapd = start_ap_wpa2_psk(apdev[0]['ifname'])
  195. wlantest_setup()
  196. connect_2sta_wpa2_psk(dev, hapd)
  197. dev[0].request("SET tdls_testing 0x1")
  198. dev[1].request("SET tdls_testing 0x1")
  199. setup_tdls(dev[1], dev[0], apdev[0])
  200. teardown_tdls(dev[1], dev[0], apdev[0])
  201. setup_tdls(dev[0], dev[1], apdev[0])
  202. def test_ap_wpa2_tdls_reneg(dev, apdev):
  203. """Renegotiate TDLS link"""
  204. hapd = start_ap_wpa2_psk(apdev[0]['ifname'])
  205. wlantest_setup()
  206. connect_2sta_wpa2_psk(dev, hapd)
  207. setup_tdls(dev[1], dev[0], apdev[0])
  208. setup_tdls(dev[0], dev[1], apdev[0])
  209. def test_ap_wpa2_tdls_wrong_lifetime_resp(dev, apdev):
  210. """Incorrect TPK lifetime in TDLS Setup Response"""
  211. hapd = start_ap_wpa2_psk(apdev[0]['ifname'])
  212. wlantest_setup()
  213. connect_2sta_wpa2_psk(dev, hapd)
  214. dev[1].request("SET tdls_testing 0x10")
  215. setup_tdls(dev[0], dev[1], apdev[0], expect_fail=True)
  216. def test_ap_wpa2_tdls_diff_rsnie(dev, apdev):
  217. """TDLS with different RSN IEs"""
  218. hapd = start_ap_wpa2_psk(apdev[0]['ifname'])
  219. wlantest_setup()
  220. connect_2sta_wpa2_psk(dev, hapd)
  221. dev[1].request("SET tdls_testing 0x2")
  222. setup_tdls(dev[1], dev[0], apdev[0])
  223. teardown_tdls(dev[1], dev[0], apdev[0])
  224. def test_ap_wpa2_tdls_wrong_tpk_m2_mic(dev, apdev):
  225. """Incorrect MIC in TDLS Setup Response"""
  226. hapd = start_ap_wpa2_psk(apdev[0]['ifname'])
  227. wlantest_setup()
  228. connect_2sta_wpa2_psk(dev, hapd)
  229. dev[0].request("SET tdls_testing 0x800")
  230. addr0 = dev[0].p2p_interface_addr()
  231. dev[1].tdls_setup(addr0)
  232. time.sleep(1)
  233. def test_ap_wpa2_tdls_wrong_tpk_m3_mic(dev, apdev):
  234. """Incorrect MIC in TDLS Setup Confirm"""
  235. hapd = start_ap_wpa2_psk(apdev[0]['ifname'])
  236. wlantest_setup()
  237. connect_2sta_wpa2_psk(dev, hapd)
  238. dev[1].request("SET tdls_testing 0x800")
  239. addr0 = dev[0].p2p_interface_addr()
  240. dev[1].tdls_setup(addr0)
  241. time.sleep(1)
  242. def test_ap_wpa_tdls(dev, apdev):
  243. """WPA-PSK AP and two stations using TDLS"""
  244. skip_with_fips(dev[0])
  245. hapd = hostapd.add_ap(apdev[0]['ifname'],
  246. hostapd.wpa_params(ssid="test-wpa-psk",
  247. passphrase="12345678"))
  248. wlantest_setup()
  249. connect_2sta_wpa_psk(dev, hapd)
  250. setup_tdls(dev[0], dev[1], apdev[0])
  251. teardown_tdls(dev[0], dev[1], apdev[0])
  252. setup_tdls(dev[1], dev[0], apdev[0])
  253. def test_ap_wpa_mixed_tdls(dev, apdev):
  254. """WPA+WPA2-PSK AP and two stations using TDLS"""
  255. skip_with_fips(dev[0])
  256. hapd = hostapd.add_ap(apdev[0]['ifname'],
  257. hostapd.wpa_mixed_params(ssid="test-wpa-mixed-psk",
  258. passphrase="12345678"))
  259. wlantest_setup()
  260. connect_2sta_wpa_psk_mixed(dev, hapd)
  261. setup_tdls(dev[0], dev[1], apdev[0])
  262. teardown_tdls(dev[0], dev[1], apdev[0])
  263. setup_tdls(dev[1], dev[0], apdev[0])
  264. def test_ap_wep_tdls(dev, apdev):
  265. """WEP AP and two stations using TDLS"""
  266. hapd = hostapd.add_ap(apdev[0]['ifname'],
  267. { "ssid": "test-wep", "wep_key0": '"hello"' })
  268. wlantest_setup()
  269. connect_2sta_wep(dev, hapd)
  270. setup_tdls(dev[0], dev[1], apdev[0])
  271. teardown_tdls(dev[0], dev[1], apdev[0])
  272. setup_tdls(dev[1], dev[0], apdev[0])
  273. def test_ap_open_tdls(dev, apdev):
  274. """Open AP and two stations using TDLS"""
  275. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
  276. wlantest_setup()
  277. connect_2sta_open(dev, hapd)
  278. setup_tdls(dev[0], dev[1], apdev[0])
  279. teardown_tdls(dev[0], dev[1], apdev[0])
  280. setup_tdls(dev[1], dev[0], apdev[0])
  281. teardown_tdls(dev[1], dev[0], apdev[0], wildcard=True)
  282. def test_ap_wpa2_tdls_bssid_mismatch(dev, apdev):
  283. """TDLS failure due to BSSID mismatch"""
  284. try:
  285. ssid = "test-wpa2-psk"
  286. passphrase = "12345678"
  287. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  288. params['bridge'] = 'ap-br0'
  289. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  290. hostapd.add_ap(apdev[1]['ifname'], params)
  291. wlantest_setup()
  292. subprocess.call(['brctl', 'setfd', 'ap-br0', '0'])
  293. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
  294. dev[0].connect(ssid, psk=passphrase, scan_freq="2412",
  295. bssid=apdev[0]['bssid'])
  296. dev[1].connect(ssid, psk=passphrase, scan_freq="2412",
  297. bssid=apdev[1]['bssid'])
  298. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  299. hwsim_utils.test_connectivity_iface(dev[0], hapd, "ap-br0")
  300. hwsim_utils.test_connectivity_iface(dev[1], hapd, "ap-br0")
  301. addr0 = dev[0].p2p_interface_addr()
  302. dev[1].tdls_setup(addr0)
  303. time.sleep(1)
  304. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  305. finally:
  306. subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'])
  307. subprocess.call(['brctl', 'delbr', 'ap-br0'])
  308. def test_ap_wpa2_tdls_responder_teardown(dev, apdev):
  309. """TDLS teardown from responder with WPA2-PSK AP"""
  310. hapd = start_ap_wpa2_psk(apdev[0]['ifname'])
  311. wlantest_setup()
  312. connect_2sta_wpa2_psk(dev, hapd)
  313. setup_tdls(dev[0], dev[1], apdev[0])
  314. teardown_tdls(dev[0], dev[1], apdev[0], responder=True)
  315. def test_ap_open_tdls_vht(dev, apdev):
  316. """Open AP and two stations using TDLS"""
  317. params = { "ssid": "test-open",
  318. "country_code": "DE",
  319. "hw_mode": "a",
  320. "channel": "36",
  321. "ieee80211n": "1",
  322. "ieee80211ac": "1",
  323. "ht_capab": "",
  324. "vht_capab": "",
  325. "vht_oper_chwidth": "0",
  326. "vht_oper_centr_freq_seg0_idx": "0" }
  327. try:
  328. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  329. wlantest_setup()
  330. connect_2sta_open(dev, hapd, scan_freq="5180")
  331. setup_tdls(dev[0], dev[1], apdev[0])
  332. teardown_tdls(dev[0], dev[1], apdev[0])
  333. setup_tdls(dev[1], dev[0], apdev[0])
  334. teardown_tdls(dev[1], dev[0], apdev[0], 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]['ifname'], params)
  358. wlantest_setup()
  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], apdev[0])
  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]['ifname'], params)
  401. wlantest_setup()
  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], apdev[0])
  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]['ifname'], 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()
  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], apdev[0])
  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]['ifname'], { "ssid": "test-open" })
  489. connect_2sta_open(dev, hapd)
  490. setup_tdls(dev[0], dev[1], apdev[0])
  491. if "OK" not in dev[0].request("TDLS_CHAN_SWITCH " + dev[1].own_addr() + " 81 2462"):
  492. raise Exception("Failed to enable TDLS channel switching")
  493. if "OK" not in dev[0].request("TDLS_CANCEL_CHAN_SWITCH " + dev[1].own_addr()):
  494. raise Exception("Could not disable TDLS channel switching")
  495. if "FAIL" not in dev[0].request("TDLS_CANCEL_CHAN_SWITCH " + dev[1].own_addr()):
  496. raise Exception("TDLS_CANCEL_CHAN_SWITCH accepted even though channel switching was already disabled")
  497. def test_ap_tdls_link_status(dev, apdev):
  498. """Check TDLS link status between two stations"""
  499. hapd = start_ap_wpa2_psk(apdev[0]['ifname'])
  500. wlantest_setup()
  501. connect_2sta_wpa2_psk(dev, hapd)
  502. check_tdls_link(dev[0], dev[1], connected=False)
  503. setup_tdls(dev[0], dev[1], apdev[0])
  504. check_tdls_link(dev[0], dev[1], connected=True)
  505. teardown_tdls(dev[0], dev[1], apdev[0])
  506. check_tdls_link(dev[0], dev[1], connected=False)
  507. if "FAIL" not in dev[0].request("TDLS_LINK_STATUS foo"):
  508. raise Exception("Unexpected TDLS_LINK_STATUS response for invalid argument")