test_ap_params.py 12 KB

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