test_ap_params.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. import logging
  7. logger = logging.getLogger()
  8. import os
  9. import subprocess
  10. import hwsim_utils
  11. import hostapd
  12. from tshark import run_tshark
  13. from utils import alloc_fail
  14. def test_ap_fragmentation_rts_set_high(dev, apdev):
  15. """WPA2-PSK AP with fragmentation and RTS thresholds larger than frame length"""
  16. ssid = "test-wpa2-psk"
  17. passphrase = 'qwertyuiop'
  18. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  19. params['rts_threshold'] = "1000"
  20. params['fragm_threshold'] = "2000"
  21. hapd = hostapd.add_ap(apdev[0], params)
  22. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  23. hwsim_utils.test_connectivity(dev[0], hapd)
  24. def test_ap_fragmentation_open(dev, apdev):
  25. """Open AP with fragmentation threshold"""
  26. ssid = "fragmentation"
  27. params = {}
  28. params['ssid'] = ssid
  29. params['fragm_threshold'] = "1000"
  30. hapd = hostapd.add_ap(apdev[0], params)
  31. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  32. hwsim_utils.test_connectivity(dev[0], hapd)
  33. def test_ap_fragmentation_wpa2(dev, apdev):
  34. """WPA2-PSK AP with fragmentation threshold"""
  35. ssid = "test-wpa2-psk"
  36. passphrase = 'qwertyuiop'
  37. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  38. params['fragm_threshold'] = "1000"
  39. hapd = hostapd.add_ap(apdev[0], params)
  40. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  41. hwsim_utils.test_connectivity(dev[0], hapd)
  42. def test_ap_vendor_elements(dev, apdev):
  43. """WPA2-PSK AP with vendor elements added"""
  44. bssid = apdev[0]['bssid']
  45. ssid = "test-wpa2-psk"
  46. passphrase = 'qwertyuiop'
  47. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  48. params['vendor_elements'] = "dd0411223301"
  49. params['assocresp_elements'] = "dd0411223302"
  50. hapd = hostapd.add_ap(apdev[0], params)
  51. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  52. bss = dev[0].get_bss(bssid)
  53. if "dd0411223301" not in bss['ie']:
  54. raise Exception("Vendor element not shown in scan results")
  55. hapd.set('vendor_elements', 'dd051122330203dd0400137400dd04001374ff')
  56. if "OK" not in hapd.request("UPDATE_BEACON"):
  57. raise Exception("UPDATE_BEACON failed")
  58. dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
  59. bss = dev[1].get_bss(bssid)
  60. if "dd0411223301" in bss['ie']:
  61. raise Exception("Old vendor element still in scan results")
  62. if "dd051122330203" not in bss['ie']:
  63. raise Exception("New vendor element not shown in scan results")
  64. def test_ap_element_parse(dev, apdev):
  65. """Information element parsing - extra coverage"""
  66. bssid = apdev[0]['bssid']
  67. ssid = "test-wpa2-psk"
  68. params = { 'ssid': ssid,
  69. 'vendor_elements': "380501020304059e009e009e009e009e009e00" }
  70. hapd = hostapd.add_ap(apdev[0], params)
  71. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  72. bss = dev[0].get_bss(bssid)
  73. if "38050102030405" not in bss['ie']:
  74. raise Exception("Timeout element not shown in scan results")
  75. def test_ap_element_parse_oom(dev, apdev):
  76. """Information element parsing OOM"""
  77. bssid = apdev[0]['bssid']
  78. ssid = "test-wpa2-psk"
  79. params = { 'ssid': ssid,
  80. 'vendor_elements': "dd0d506f9a0a00000600411c440028" }
  81. hapd = hostapd.add_ap(apdev[0], params)
  82. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  83. with alloc_fail(dev[0], 1, "wpabuf_alloc;ieee802_11_vendor_ie_concat"):
  84. bss = dev[0].get_bss(bssid)
  85. logger.info(str(bss))
  86. def test_ap_country(dev, apdev):
  87. """WPA2-PSK AP setting country code and using 5 GHz band"""
  88. try:
  89. hapd = None
  90. bssid = apdev[0]['bssid']
  91. ssid = "test-wpa2-psk"
  92. passphrase = 'qwertyuiop'
  93. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  94. params['country_code'] = 'FI'
  95. params['ieee80211d'] = '1'
  96. params['hw_mode'] = 'a'
  97. params['channel'] = '36'
  98. hapd = hostapd.add_ap(apdev[0], params)
  99. dev[0].connect(ssid, psk=passphrase, scan_freq="5180")
  100. hwsim_utils.test_connectivity(dev[0], hapd)
  101. finally:
  102. dev[0].request("DISCONNECT")
  103. if hapd:
  104. hapd.request("DISABLE")
  105. subprocess.call(['iw', 'reg', 'set', '00'])
  106. dev[0].flush_scan_cache()
  107. def test_ap_acl_accept(dev, apdev):
  108. """MAC ACL accept list"""
  109. ssid = "acl"
  110. params = {}
  111. params['ssid'] = ssid
  112. params['accept_mac_file'] = "hostapd.macaddr"
  113. hapd = hostapd.add_ap(apdev[0], params)
  114. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  115. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  116. dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
  117. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  118. dev[0].request("REMOVE_NETWORK all")
  119. dev[1].request("REMOVE_NETWORK all")
  120. hapd.request("SET macaddr_acl 1")
  121. dev[1].dump_monitor()
  122. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  123. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  124. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  125. if ev is not None:
  126. raise Exception("Unexpected association")
  127. def test_ap_acl_deny(dev, apdev):
  128. """MAC ACL deny list"""
  129. ssid = "acl"
  130. params = {}
  131. params['ssid'] = ssid
  132. params['deny_mac_file'] = "hostapd.macaddr"
  133. hapd = hostapd.add_ap(apdev[0], params)
  134. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  135. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  136. dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
  137. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  138. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  139. if ev is not None:
  140. raise Exception("Unexpected association")
  141. def test_ap_wds_sta(dev, apdev):
  142. """WPA2-PSK AP with STA using 4addr mode"""
  143. ssid = "test-wpa2-psk"
  144. passphrase = 'qwertyuiop'
  145. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  146. params['wds_sta'] = "1"
  147. params['wds_bridge'] = "wds-br0"
  148. hapd = hostapd.add_ap(apdev[0], params)
  149. try:
  150. subprocess.call(['brctl', 'addbr', 'wds-br0'])
  151. subprocess.call(['brctl', 'setfd', 'wds-br0', '0'])
  152. subprocess.call(['ip', 'link', 'set', 'dev', 'wds-br0', 'up'])
  153. subprocess.call(['iw', dev[0].ifname, 'set', '4addr', 'on'])
  154. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  155. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  156. max_tries=15)
  157. finally:
  158. subprocess.call(['iw', dev[0].ifname, 'set', '4addr', 'off'])
  159. subprocess.call(['ip', 'link', 'set', 'dev', 'wds-br0', 'down'])
  160. subprocess.call(['brctl', 'delbr', 'wds-br0'])
  161. def test_ap_inactivity_poll(dev, apdev):
  162. """AP using inactivity poll"""
  163. ssid = "test-wpa2-psk"
  164. passphrase = 'qwertyuiop'
  165. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  166. params['ap_max_inactivity'] = "1"
  167. hapd = hostapd.add_ap(apdev[0], params)
  168. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  169. hapd.set("ext_mgmt_frame_handling", "1")
  170. dev[0].request("DISCONNECT")
  171. ev = hapd.wait_event(["MGMT-RX"], timeout=5)
  172. if ev is None:
  173. raise Exception("MGMT RX wait timed out for Deauth")
  174. hapd.set("ext_mgmt_frame_handling", "0")
  175. ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=30)
  176. if ev is None:
  177. raise Exception("STA disconnection on inactivity was not reported")
  178. def test_ap_inactivity_disconnect(dev, apdev):
  179. """AP using inactivity disconnect"""
  180. ssid = "test-wpa2-psk"
  181. passphrase = 'qwertyuiop'
  182. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  183. params['ap_max_inactivity'] = "1"
  184. params['skip_inactivity_poll'] = "1"
  185. hapd = hostapd.add_ap(apdev[0], params)
  186. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  187. hapd.set("ext_mgmt_frame_handling", "1")
  188. dev[0].request("DISCONNECT")
  189. ev = hapd.wait_event(["MGMT-RX"], timeout=5)
  190. if ev is None:
  191. raise Exception("MGMT RX wait timed out for Deauth")
  192. hapd.set("ext_mgmt_frame_handling", "0")
  193. ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=30)
  194. if ev is None:
  195. raise Exception("STA disconnection on inactivity was not reported")
  196. def test_ap_basic_rates(dev, apdev):
  197. """Open AP with lots of basic rates"""
  198. ssid = "basic rates"
  199. params = {}
  200. params['ssid'] = ssid
  201. params['basic_rates'] = "10 20 55 110 60 90 120 180 240 360 480 540"
  202. hostapd.add_ap(apdev[0], params)
  203. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  204. def test_ap_short_preamble(dev, apdev):
  205. """Open AP with short preamble"""
  206. ssid = "short preamble"
  207. params = {}
  208. params['ssid'] = ssid
  209. params['preamble'] = "1"
  210. hostapd.add_ap(apdev[0], params)
  211. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  212. def test_ap_spectrum_management_required(dev, apdev):
  213. """Open AP with spectrum management required"""
  214. ssid = "spectrum mgmt"
  215. params = {}
  216. params['ssid'] = ssid
  217. params["country_code"] = "JP"
  218. params["hw_mode"] = "a"
  219. params["channel"] = "36"
  220. params["ieee80211d"] = "1"
  221. params["local_pwr_constraint"] = "3"
  222. params['spectrum_mgmt_required'] = "1"
  223. try:
  224. hapd = None
  225. hapd = hostapd.add_ap(apdev[0], params)
  226. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="5180")
  227. finally:
  228. dev[0].request("DISCONNECT")
  229. if hapd:
  230. hapd.request("DISABLE")
  231. subprocess.call(['iw', 'reg', 'set', '00'])
  232. dev[0].flush_scan_cache()
  233. def test_ap_max_listen_interval(dev, apdev):
  234. """Open AP with maximum listen interval limit"""
  235. ssid = "listen"
  236. params = {}
  237. params['ssid'] = ssid
  238. params['max_listen_interval'] = "1"
  239. hostapd.add_ap(apdev[0], params)
  240. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  241. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  242. if ev is None:
  243. raise Exception("Association rejection not reported")
  244. if "status_code=51" not in ev:
  245. raise Exception("Unexpected ASSOC-REJECT reason")
  246. def test_ap_max_num_sta(dev, apdev):
  247. """Open AP with maximum STA count"""
  248. ssid = "max"
  249. params = {}
  250. params['ssid'] = ssid
  251. params['max_num_sta'] = "1"
  252. hostapd.add_ap(apdev[0], params)
  253. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  254. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  255. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  256. if ev is not None:
  257. raise Exception("Unexpected association")
  258. def test_ap_max_num_sta_no_probe_resp(dev, apdev, params):
  259. """Maximum STA count and limit on Probe Response frames"""
  260. logdir = params['logdir']
  261. dev[0].flush_scan_cache()
  262. ssid = "max"
  263. params = {}
  264. params['ssid'] = ssid
  265. params['beacon_int'] = "2000"
  266. params['max_num_sta'] = "1"
  267. params['no_probe_resp_if_max_sta'] = "1"
  268. hostapd.add_ap(apdev[0], params)
  269. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  270. dev[0].scan(freq=2412, type="ONLY")
  271. dev[0].scan(freq=2412, type="ONLY")
  272. seen = dev[0].get_bss(apdev[0]['bssid']) != None
  273. dev[1].scan(freq=2412, type="ONLY")
  274. if seen:
  275. out = run_tshark(os.path.join(logdir, "hwsim0.pcapng"),
  276. "wlan.fc.type_subtype == 5", ["wlan.da" ])
  277. if out:
  278. if dev[0].own_addr() not in out:
  279. # Discovery happened through Beacon frame reception. That's not
  280. # an error case.
  281. seen = False
  282. if dev[1].own_addr() not in out:
  283. raise Exception("No Probe Response frames to dev[1] seen")
  284. if seen:
  285. raise Exception("AP found unexpectedly")
  286. def test_ap_tx_queue_params(dev, apdev):
  287. """Open AP with TX queue params set"""
  288. ssid = "tx"
  289. params = {}
  290. params['ssid'] = ssid
  291. params['tx_queue_data2_aifs'] = "4"
  292. params['tx_queue_data2_cwmin'] = "7"
  293. params['tx_queue_data2_cwmax'] = "1023"
  294. params['tx_queue_data2_burst'] = "4.2"
  295. params['tx_queue_data1_aifs'] = "4"
  296. params['tx_queue_data1_cwmin'] = "7"
  297. params['tx_queue_data1_cwmax'] = "1023"
  298. params['tx_queue_data1_burst'] = "2"
  299. hapd = hostapd.add_ap(apdev[0], params)
  300. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  301. hwsim_utils.test_connectivity(dev[0], hapd)