1 # Python class for controlling wlantest
2 # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
13 logger = logging.getLogger()
17 if os.path.isfile('../../wlantest/wlantest_cli'):
18 self.wlantest_cli = '../../wlantest/wlantest_cli'
20 self.wlantest_cli = 'wlantest_cli'
23 res = subprocess.check_output([self.wlantest_cli, "flush"])
25 raise Exception("wlantest_cli flush failed")
28 res = subprocess.check_output([self.wlantest_cli, "relog"])
30 raise Exception("wlantest_cli relog failed")
32 def add_passphrase(self, passphrase):
33 res = subprocess.check_output([self.wlantest_cli, "add_passphrase",
36 raise Exception("wlantest_cli add_passphrase failed")
38 def add_wepkey(self, key):
39 res = subprocess.check_output([self.wlantest_cli, "add_wepkey", key])
41 raise Exception("wlantest_cli add_key failed")
43 def info_bss(self, field, bssid):
44 res = subprocess.check_output([self.wlantest_cli, "info_bss",
47 raise Exception("Could not get BSS info from wlantest for " + bssid)
50 def get_bss_counter(self, field, bssid):
52 res = subprocess.check_output([self.wlantest_cli, "get_bss_counter",
60 def clear_bss_counters(self, bssid):
61 subprocess.call([self.wlantest_cli, "clear_bss_counters", bssid],
62 stdout=open('/dev/null', 'w'));
64 def info_sta(self, field, bssid, addr):
65 res = subprocess.check_output([self.wlantest_cli, "info_sta",
68 raise Exception("Could not get STA info from wlantest for " + addr)
71 def get_sta_counter(self, field, bssid, addr):
72 res = subprocess.check_output([self.wlantest_cli, "get_sta_counter",
75 raise Exception("wlantest_cli command failed")
78 def clear_sta_counters(self, bssid, addr):
79 res = subprocess.check_output([self.wlantest_cli, "clear_sta_counters",
82 raise Exception("wlantest_cli command failed")
84 def tdls_clear(self, bssid, addr1, addr2):
85 res = subprocess.check_output([self.wlantest_cli, "clear_tdls_counters",
86 bssid, addr1, addr2]);
88 def get_tdls_counter(self, field, bssid, addr1, addr2):
89 res = subprocess.check_output([self.wlantest_cli, "get_tdls_counter",
90 field, bssid, addr1, addr2]);
92 raise Exception("wlantest_cli command failed")
95 def require_ap_pmf_mandatory(self, bssid):
96 res = self.info_bss("rsn_capab", bssid)
98 raise Exception("AP did not require PMF")
100 raise Exception("AP did not enable PMF")
101 res = self.info_bss("key_mgmt", bssid)
102 if "PSK-SHA256" not in res:
103 raise Exception("AP did not enable SHA256-based AKM for PMF")
105 def require_ap_pmf_optional(self, bssid):
106 res = self.info_bss("rsn_capab", bssid)
108 raise Exception("AP required PMF")
109 if "MFPC" not in res:
110 raise Exception("AP did not enable PMF")
112 def require_ap_no_pmf(self, bssid):
113 res = self.info_bss("rsn_capab", bssid)
115 raise Exception("AP required PMF")
117 raise Exception("AP enabled PMF")
119 def require_sta_pmf_mandatory(self, bssid, addr):
120 res = self.info_sta("rsn_capab", bssid, addr)
121 if "MFPR" not in res:
122 raise Exception("STA did not require PMF")
123 if "MFPC" not in res:
124 raise Exception("STA did not enable PMF")
126 def require_sta_pmf(self, bssid, addr):
127 res = self.info_sta("rsn_capab", bssid, addr)
128 if "MFPC" not in res:
129 raise Exception("STA did not enable PMF")
131 def require_sta_no_pmf(self, bssid, addr):
132 res = self.info_sta("rsn_capab", bssid, addr)
134 raise Exception("STA enabled PMF")
136 def require_sta_key_mgmt(self, bssid, addr, key_mgmt):
137 res = self.info_sta("key_mgmt", bssid, addr)
138 if key_mgmt not in res:
139 raise Exception("Unexpected STA key_mgmt")
141 def get_tx_tid(self, bssid, addr, tid):
142 res = subprocess.check_output([self.wlantest_cli, "get_tx_tid",
143 bssid, addr, str(tid)]);
145 raise Exception("wlantest_cli command failed")
148 def get_rx_tid(self, bssid, addr, tid):
149 res = subprocess.check_output([self.wlantest_cli, "get_rx_tid",
150 bssid, addr, str(tid)]);
152 raise Exception("wlantest_cli command failed")
155 def get_tid_counters(self, bssid, addr):
158 for tid in range(0, 17):
159 tx[tid] = self.get_tx_tid(bssid, addr, tid)
160 rx[tid] = self.get_rx_tid(bssid, addr, tid)