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