test_ap_params.py 9.8 KB

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