test_ap_tdls.py 21 KB

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