test_ap_params.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. # Test various AP mode parameters
  2. # Copyright (c) 2014, Qualcomm Atheros, Inc.
  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 logging
  8. logger = logging.getLogger()
  9. import os
  10. import subprocess
  11. import hwsim_utils
  12. import hostapd
  13. from tshark import run_tshark
  14. from utils import alloc_fail, HwsimSkip
  15. @remote_compatible
  16. def test_ap_fragmentation_rts_set_high(dev, apdev):
  17. """WPA2-PSK AP with fragmentation and RTS thresholds larger than frame length"""
  18. ssid = "test-wpa2-psk"
  19. passphrase = 'qwertyuiop'
  20. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  21. params['rts_threshold'] = "1000"
  22. params['fragm_threshold'] = "2000"
  23. hapd = hostapd.add_ap(apdev[0], params)
  24. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  25. hwsim_utils.test_connectivity(dev[0], hapd)
  26. @remote_compatible
  27. def test_ap_fragmentation_open(dev, apdev):
  28. """Open AP with fragmentation threshold"""
  29. ssid = "fragmentation"
  30. params = {}
  31. params['ssid'] = ssid
  32. params['fragm_threshold'] = "1000"
  33. hapd = hostapd.add_ap(apdev[0], params)
  34. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  35. hwsim_utils.test_connectivity(dev[0], hapd)
  36. @remote_compatible
  37. def test_ap_fragmentation_wpa2(dev, apdev):
  38. """WPA2-PSK AP with fragmentation threshold"""
  39. ssid = "test-wpa2-psk"
  40. passphrase = 'qwertyuiop'
  41. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  42. params['fragm_threshold'] = "1000"
  43. hapd = hostapd.add_ap(apdev[0], params)
  44. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  45. hwsim_utils.test_connectivity(dev[0], hapd)
  46. def test_ap_vendor_elements(dev, apdev):
  47. """WPA2-PSK AP with vendor elements added"""
  48. bssid = apdev[0]['bssid']
  49. ssid = "test-wpa2-psk"
  50. passphrase = 'qwertyuiop'
  51. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  52. params['vendor_elements'] = "dd0411223301"
  53. params['assocresp_elements'] = "dd0411223302"
  54. hapd = hostapd.add_ap(apdev[0], params)
  55. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  56. bss = dev[0].get_bss(bssid)
  57. if "dd0411223301" not in bss['ie']:
  58. raise Exception("Vendor element not shown in scan results")
  59. hapd.set('vendor_elements', 'dd051122330203dd0400137400dd04001374ff')
  60. if "OK" not in hapd.request("UPDATE_BEACON"):
  61. raise Exception("UPDATE_BEACON failed")
  62. dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
  63. bss = dev[1].get_bss(bssid)
  64. if "dd0411223301" in bss['ie']:
  65. raise Exception("Old vendor element still in scan results")
  66. if "dd051122330203" not in bss['ie']:
  67. raise Exception("New vendor element not shown in scan results")
  68. def test_ap_element_parse(dev, apdev):
  69. """Information element parsing - extra coverage"""
  70. bssid = apdev[0]['bssid']
  71. ssid = "test-wpa2-psk"
  72. params = { 'ssid': ssid,
  73. 'vendor_elements': "380501020304059e009e009e009e009e009e00" }
  74. hapd = hostapd.add_ap(apdev[0], params)
  75. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  76. bss = dev[0].get_bss(bssid)
  77. if "38050102030405" not in bss['ie']:
  78. raise Exception("Timeout element not shown in scan results")
  79. @remote_compatible
  80. def test_ap_element_parse_oom(dev, apdev):
  81. """Information element parsing OOM"""
  82. bssid = apdev[0]['bssid']
  83. ssid = "test-wpa2-psk"
  84. params = { 'ssid': ssid,
  85. 'vendor_elements': "dd0d506f9a0a00000600411c440028" }
  86. hapd = hostapd.add_ap(apdev[0], params)
  87. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  88. with alloc_fail(dev[0], 1, "wpabuf_alloc;ieee802_11_vendor_ie_concat"):
  89. bss = dev[0].get_bss(bssid)
  90. logger.info(str(bss))
  91. def test_ap_country(dev, apdev):
  92. """WPA2-PSK AP setting country code and using 5 GHz band"""
  93. try:
  94. hapd = None
  95. bssid = apdev[0]['bssid']
  96. ssid = "test-wpa2-psk"
  97. passphrase = 'qwertyuiop'
  98. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  99. params['country_code'] = 'FI'
  100. params['ieee80211d'] = '1'
  101. params['hw_mode'] = 'a'
  102. params['channel'] = '36'
  103. hapd = hostapd.add_ap(apdev[0], params)
  104. dev[0].connect(ssid, psk=passphrase, scan_freq="5180")
  105. hwsim_utils.test_connectivity(dev[0], hapd)
  106. finally:
  107. dev[0].request("DISCONNECT")
  108. if hapd:
  109. hapd.request("DISABLE")
  110. hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
  111. dev[0].flush_scan_cache()
  112. def test_ap_acl_accept(dev, apdev):
  113. """MAC ACL accept list"""
  114. ssid = "acl"
  115. params = {}
  116. params['ssid'] = ssid
  117. params['accept_mac_file'] = "hostapd.macaddr"
  118. hapd = hostapd.add_ap(apdev[0], params)
  119. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  120. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  121. dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
  122. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  123. dev[0].request("REMOVE_NETWORK all")
  124. dev[1].request("REMOVE_NETWORK all")
  125. hapd.request("SET macaddr_acl 1")
  126. dev[1].dump_monitor()
  127. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  128. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  129. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  130. if ev is not None:
  131. raise Exception("Unexpected association")
  132. def test_ap_acl_deny(dev, apdev):
  133. """MAC ACL deny list"""
  134. ssid = "acl"
  135. params = {}
  136. params['ssid'] = ssid
  137. params['deny_mac_file'] = "hostapd.macaddr"
  138. hapd = hostapd.add_ap(apdev[0], params)
  139. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  140. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  141. dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
  142. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  143. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  144. if ev is not None:
  145. raise Exception("Unexpected association")
  146. @remote_compatible
  147. def test_ap_wds_sta(dev, apdev):
  148. """WPA2-PSK AP with STA using 4addr mode"""
  149. ssid = "test-wpa2-psk"
  150. passphrase = 'qwertyuiop'
  151. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  152. params['wds_sta'] = "1"
  153. params['wds_bridge'] = "wds-br0"
  154. hapd = hostapd.add_ap(apdev[0], params)
  155. try:
  156. dev[0].cmd_execute(['brctl', 'addbr', 'wds-br0'])
  157. dev[0].cmd_execute(['brctl', 'setfd', 'wds-br0', '0'])
  158. dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'wds-br0', 'up'])
  159. dev[0].cmd_execute(['iw', dev[0].ifname, 'set', '4addr', 'on'])
  160. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  161. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  162. max_tries=15)
  163. finally:
  164. dev[0].cmd_execute(['iw', dev[0].ifname, 'set', '4addr', 'off'])
  165. dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'wds-br0', 'down'])
  166. dev[0].cmd_execute(['brctl', 'delbr', 'wds-br0'])
  167. @remote_compatible
  168. def test_ap_inactivity_poll(dev, apdev):
  169. """AP using inactivity poll"""
  170. ssid = "test-wpa2-psk"
  171. passphrase = 'qwertyuiop'
  172. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  173. params['ap_max_inactivity'] = "1"
  174. hapd = hostapd.add_ap(apdev[0], params)
  175. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  176. hapd.set("ext_mgmt_frame_handling", "1")
  177. dev[0].request("DISCONNECT")
  178. ev = hapd.wait_event(["MGMT-RX"], timeout=5)
  179. if ev is None:
  180. raise Exception("MGMT RX wait timed out for Deauth")
  181. hapd.set("ext_mgmt_frame_handling", "0")
  182. ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=30)
  183. if ev is None:
  184. raise Exception("STA disconnection on inactivity was not reported")
  185. @remote_compatible
  186. def test_ap_inactivity_disconnect(dev, apdev):
  187. """AP using inactivity disconnect"""
  188. ssid = "test-wpa2-psk"
  189. passphrase = 'qwertyuiop'
  190. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  191. params['ap_max_inactivity'] = "1"
  192. params['skip_inactivity_poll'] = "1"
  193. hapd = hostapd.add_ap(apdev[0], params)
  194. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  195. hapd.set("ext_mgmt_frame_handling", "1")
  196. dev[0].request("DISCONNECT")
  197. ev = hapd.wait_event(["MGMT-RX"], timeout=5)
  198. if ev is None:
  199. raise Exception("MGMT RX wait timed out for Deauth")
  200. hapd.set("ext_mgmt_frame_handling", "0")
  201. ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=30)
  202. if ev is None:
  203. raise Exception("STA disconnection on inactivity was not reported")
  204. @remote_compatible
  205. def test_ap_basic_rates(dev, apdev):
  206. """Open AP with lots of basic rates"""
  207. ssid = "basic rates"
  208. params = {}
  209. params['ssid'] = ssid
  210. params['basic_rates'] = "10 20 55 110 60 90 120 180 240 360 480 540"
  211. hostapd.add_ap(apdev[0], params)
  212. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  213. @remote_compatible
  214. def test_ap_short_preamble(dev, apdev):
  215. """Open AP with short preamble"""
  216. ssid = "short preamble"
  217. params = {}
  218. params['ssid'] = ssid
  219. params['preamble'] = "1"
  220. hostapd.add_ap(apdev[0], params)
  221. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  222. def test_ap_spectrum_management_required(dev, apdev):
  223. """Open AP with spectrum management required"""
  224. ssid = "spectrum mgmt"
  225. params = {}
  226. params['ssid'] = ssid
  227. params["country_code"] = "JP"
  228. params["hw_mode"] = "a"
  229. params["channel"] = "36"
  230. params["ieee80211d"] = "1"
  231. params["local_pwr_constraint"] = "3"
  232. params['spectrum_mgmt_required'] = "1"
  233. try:
  234. hapd = None
  235. hapd = hostapd.add_ap(apdev[0], params)
  236. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="5180")
  237. finally:
  238. dev[0].request("DISCONNECT")
  239. if hapd:
  240. hapd.request("DISABLE")
  241. hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
  242. dev[0].flush_scan_cache()
  243. @remote_compatible
  244. def test_ap_max_listen_interval(dev, apdev):
  245. """Open AP with maximum listen interval limit"""
  246. ssid = "listen"
  247. params = {}
  248. params['ssid'] = ssid
  249. params['max_listen_interval'] = "1"
  250. hostapd.add_ap(apdev[0], params)
  251. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  252. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  253. if ev is None:
  254. raise Exception("Association rejection not reported")
  255. if "status_code=51" not in ev:
  256. raise Exception("Unexpected ASSOC-REJECT reason")
  257. @remote_compatible
  258. def test_ap_max_num_sta(dev, apdev):
  259. """Open AP with maximum STA count"""
  260. ssid = "max"
  261. params = {}
  262. params['ssid'] = ssid
  263. params['max_num_sta'] = "1"
  264. hostapd.add_ap(apdev[0], params)
  265. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  266. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  267. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  268. if ev is not None:
  269. raise Exception("Unexpected association")
  270. def test_ap_max_num_sta_no_probe_resp(dev, apdev, params):
  271. """Maximum STA count and limit on Probe Response frames"""
  272. logdir = params['logdir']
  273. dev[0].flush_scan_cache()
  274. ssid = "max"
  275. params = {}
  276. params['ssid'] = ssid
  277. params['beacon_int'] = "2000"
  278. params['max_num_sta'] = "1"
  279. params['no_probe_resp_if_max_sta'] = "1"
  280. hostapd.add_ap(apdev[0], params)
  281. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  282. dev[0].scan(freq=2412, type="ONLY")
  283. dev[0].scan(freq=2412, type="ONLY")
  284. seen = dev[0].get_bss(apdev[0]['bssid']) != None
  285. dev[1].scan(freq=2412, type="ONLY")
  286. if seen:
  287. out = run_tshark(os.path.join(logdir, "hwsim0.pcapng"),
  288. "wlan.fc.type_subtype == 5", ["wlan.da" ])
  289. if out:
  290. if dev[0].own_addr() not in out:
  291. # Discovery happened through Beacon frame reception. That's not
  292. # an error case.
  293. seen = False
  294. if dev[1].own_addr() not in out:
  295. raise Exception("No Probe Response frames to dev[1] seen")
  296. if seen:
  297. raise Exception("AP found unexpectedly")
  298. @remote_compatible
  299. def test_ap_tx_queue_params(dev, apdev):
  300. """Open AP with TX queue params set"""
  301. ssid = "tx"
  302. params = {}
  303. params['ssid'] = ssid
  304. params['tx_queue_data2_aifs'] = "4"
  305. params['tx_queue_data2_cwmin'] = "7"
  306. params['tx_queue_data2_cwmax'] = "1023"
  307. params['tx_queue_data2_burst'] = "4.2"
  308. params['tx_queue_data1_aifs'] = "4"
  309. params['tx_queue_data1_cwmin'] = "7"
  310. params['tx_queue_data1_cwmax'] = "1023"
  311. params['tx_queue_data1_burst'] = "2"
  312. hapd = hostapd.add_ap(apdev[0], params)
  313. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  314. hwsim_utils.test_connectivity(dev[0], hapd)
  315. def test_ap_beacon_rate_legacy(dev, apdev):
  316. """Open AP with Beacon frame TX rate 5.5 Mbps"""
  317. hapd = hostapd.add_ap(apdev[0], { 'ssid': 'beacon-rate' })
  318. res = hapd.get_driver_status_field('capa.flags')
  319. if (int(res, 0) & 0x0000080000000000) == 0:
  320. raise HwsimSkip("Setting Beacon frame TX rate not supported")
  321. hapd.disable()
  322. hapd.set('beacon_rate', '55')
  323. hapd.enable()
  324. dev[0].connect('beacon-rate', key_mgmt="NONE", scan_freq="2412")
  325. def test_ap_beacon_rate_legacy2(dev, apdev):
  326. """Open AP with Beacon frame TX rate 12 Mbps in VHT BSS"""
  327. hapd = hostapd.add_ap(apdev[0], { 'ssid': 'beacon-rate' })
  328. res = hapd.get_driver_status_field('capa.flags')
  329. if (int(res, 0) & 0x0000080000000000) == 0:
  330. raise HwsimSkip("Setting Beacon frame TX rate not supported")
  331. hapd.disable()
  332. hapd.set('beacon_rate', '120')
  333. hapd.set("country_code", "DE")
  334. hapd.set("hw_mode", "a")
  335. hapd.set("channel", "36")
  336. hapd.set("ieee80211n", "1")
  337. hapd.set("ieee80211ac", "1")
  338. hapd.set("ht_capab", "[HT40+]")
  339. hapd.set("vht_capab", "")
  340. hapd.set("vht_oper_chwidth", "0")
  341. hapd.set("vht_oper_centr_freq_seg0_idx", "0")
  342. try:
  343. hapd.enable()
  344. dev[0].scan_for_bss(hapd.own_addr(), freq="5180")
  345. dev[0].connect('beacon-rate', key_mgmt="NONE", scan_freq="5180")
  346. finally:
  347. dev[0].request("DISCONNECT")
  348. hapd.request("DISABLE")
  349. subprocess.call(['iw', 'reg', 'set', '00'])
  350. dev[0].flush_scan_cache()
  351. def test_ap_beacon_rate_ht(dev, apdev):
  352. """Open AP with Beacon frame TX rate HT-MCS 0"""
  353. hapd = hostapd.add_ap(apdev[0], { 'ssid': 'beacon-rate' })
  354. res = hapd.get_driver_status_field('capa.flags')
  355. if (int(res, 0) & 0x0000100000000000) == 0:
  356. raise HwsimSkip("Setting Beacon frame TX rate not supported")
  357. hapd.disable()
  358. hapd.set('beacon_rate', 'ht:0')
  359. hapd.enable()
  360. dev[0].connect('beacon-rate', key_mgmt="NONE", scan_freq="2412")
  361. def test_ap_beacon_rate_ht2(dev, apdev):
  362. """Open AP with Beacon frame TX rate HT-MCS 1 in VHT BSS"""
  363. hapd = hostapd.add_ap(apdev[0], { 'ssid': 'beacon-rate' })
  364. res = hapd.get_driver_status_field('capa.flags')
  365. if (int(res, 0) & 0x0000100000000000) == 0:
  366. raise HwsimSkip("Setting Beacon frame TX rate not supported")
  367. hapd.disable()
  368. hapd.set('beacon_rate', 'ht:1')
  369. hapd.set("country_code", "DE")
  370. hapd.set("hw_mode", "a")
  371. hapd.set("channel", "36")
  372. hapd.set("ieee80211n", "1")
  373. hapd.set("ieee80211ac", "1")
  374. hapd.set("ht_capab", "[HT40+]")
  375. hapd.set("vht_capab", "")
  376. hapd.set("vht_oper_chwidth", "0")
  377. hapd.set("vht_oper_centr_freq_seg0_idx", "0")
  378. try:
  379. hapd.enable()
  380. dev[0].scan_for_bss(hapd.own_addr(), freq="5180")
  381. dev[0].connect('beacon-rate', key_mgmt="NONE", scan_freq="5180")
  382. finally:
  383. dev[0].request("DISCONNECT")
  384. hapd.request("DISABLE")
  385. subprocess.call(['iw', 'reg', 'set', '00'])
  386. dev[0].flush_scan_cache()
  387. def test_ap_beacon_rate_vht(dev, apdev):
  388. """Open AP with Beacon frame TX rate VHT-MCS 0"""
  389. hapd = hostapd.add_ap(apdev[0], { 'ssid': 'beacon-rate' })
  390. res = hapd.get_driver_status_field('capa.flags')
  391. if (int(res, 0) & 0x0000200000000000) == 0:
  392. raise HwsimSkip("Setting Beacon frame TX rate not supported")
  393. hapd.disable()
  394. hapd.set('beacon_rate', 'vht:0')
  395. hapd.set("country_code", "DE")
  396. hapd.set("hw_mode", "a")
  397. hapd.set("channel", "36")
  398. hapd.set("ieee80211n", "1")
  399. hapd.set("ieee80211ac", "1")
  400. hapd.set("ht_capab", "[HT40+]")
  401. hapd.set("vht_capab", "")
  402. hapd.set("vht_oper_chwidth", "0")
  403. hapd.set("vht_oper_centr_freq_seg0_idx", "0")
  404. try:
  405. hapd.enable()
  406. dev[0].scan_for_bss(hapd.own_addr(), freq="5180")
  407. dev[0].connect('beacon-rate', key_mgmt="NONE", scan_freq="5180")
  408. finally:
  409. dev[0].request("DISCONNECT")
  410. hapd.request("DISABLE")
  411. subprocess.call(['iw', 'reg', 'set', '00'])
  412. dev[0].flush_scan_cache()