68a4f0163f9f7c2a7726c3a9400e4d20dd2bbb15
[mech_eap.git] / tests / hwsim / test_ap_track.py
1 # Test cases for hostapd tracking unconnected stations
2 # Copyright (c) 2015, Jouni Malinen <j@w1.fi>
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 import time
11
12 import hostapd
13 from wpasupplicant import WpaSupplicant
14
15 def test_ap_track_sta(dev, apdev):
16     """Dualband AP tracking unconnected stations"""
17     try:
18         _test_ap_track_sta(dev, apdev)
19     finally:
20         subprocess.call(['iw', 'reg', 'set', '00'])
21
22 def _test_ap_track_sta(dev, apdev):
23     params = { "ssid": "track",
24                "country_code": "US",
25                "hw_mode": "g",
26                "channel": "6",
27                "track_sta_max_num": "2" }
28     hapd = hostapd.add_ap(apdev[0]['ifname'], params)
29     bssid = apdev[0]['bssid']
30
31     params = { "ssid": "track",
32                "country_code": "US",
33                "hw_mode": "a",
34                "channel": "40",
35                "track_sta_max_num": "100",
36                "track_sta_max_age": "1" }
37     hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
38     bssid2 = apdev[1]['bssid']
39
40     for i in range(2):
41         dev[0].scan_for_bss(bssid, freq=2437, force_scan=True)
42         dev[0].scan_for_bss(bssid2, freq=5200, force_scan=True)
43         dev[1].scan_for_bss(bssid, freq=2437, force_scan=True)
44         dev[2].scan_for_bss(bssid2, freq=5200, force_scan=True)
45
46     addr0 = dev[0].own_addr()
47     addr1 = dev[1].own_addr()
48     addr2 = dev[2].own_addr()
49
50     track = hapd.request("TRACK_STA_LIST")
51     if addr0 not in track or addr1 not in track:
52         raise Exception("Station missing from 2.4 GHz tracking")
53     if addr2 in track:
54         raise Exception("Unexpected station included in 2.4 GHz tracking")
55     
56     track = hapd2.request("TRACK_STA_LIST")
57     if addr0 not in track or addr2 not in track:
58         raise Exception("Station missing from 5 GHz tracking")
59     if addr1 in track:
60         raise Exception("Unexpected station included in 5 GHz tracking")
61
62     # Test expiration
63     time.sleep(1.1)
64     track = hapd.request("TRACK_STA_LIST")
65     if addr0 not in track or addr1 not in track:
66         raise Exception("Station missing from 2.4 GHz tracking (expiration)")
67     track = hapd2.request("TRACK_STA_LIST")
68     if addr0 in track or addr2 in track:
69         raise Exception("Station not expired from 5 GHz tracking")
70
71     # Test maximum list length
72     dev[0].scan_for_bss(bssid, freq=2437, force_scan=True)
73     dev[1].scan_for_bss(bssid, freq=2437, force_scan=True)
74     dev[2].scan_for_bss(bssid, freq=2437, force_scan=True)
75     track = hapd.request("TRACK_STA_LIST")
76     if len(track.splitlines()) != 2:
77         raise Exception("Unexpected number of entries: %d" % len(track.splitlines()))
78     if addr1 not in track or addr2 not in track:
79         raise Exception("Station missing from 2.4 GHz tracking (max limit)")