blob: 54b7ef063d03ff89373776124ee086082a357d1d [file] [log] [blame]
Sam Leffler6969d1d2010-03-15 16:07:11 -07001# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Paul Stewart310928c2010-09-07 11:54:11 -07005import logging, re, time
Paul Stewartc9628b32010-08-11 13:03:51 -07006from autotest_lib.client.common_lib import error
Paul Stewart2ee7fdf2011-05-19 16:29:23 -07007from autotest_lib.server import site_linux_system
Sam Leffler19bb0a72010-04-12 08:51:08 -07008
9def isLinuxRouter(router):
10 router_uname = router.run('uname').stdout
11 return re.search('Linux', router_uname)
12
Paul Stewart2ee7fdf2011-05-19 16:29:23 -070013class LinuxRouter(site_linux_system.LinuxSystem):
Sam Leffler6969d1d2010-03-15 16:07:11 -070014 """
15 Linux/mac80211-style WiFi Router support for WiFiTest class.
16
17 This class implements test methods/steps that communicate with a
18 router implemented with Linux/mac80211. The router must
19 be pre-configured to enable ssh access and have a mac80211-based
20 wireless device. We also assume hostapd 0.7.x and iw are present
21 and any necessary modules are pre-loaded.
22 """
23
24
25 def __init__(self, host, params, defssid):
Paul Stewart2ee7fdf2011-05-19 16:29:23 -070026 site_linux_system.LinuxSystem.__init__(self, host, params, "router")
mukesh agrawalfe0e85b2011-08-09 14:24:15 -070027 self._remove_interfaces()
Paul Stewart2ee7fdf2011-05-19 16:29:23 -070028
mukesh agrawalfe0e85b2011-08-09 14:24:15 -070029 self.cmd_hostapd = params.get("cmd_hostapd", "/usr/sbin/hostapd")
30 self.cmd_hostapd_cli = \
31 params.get("cmd_hostapd_cli", "/usr/sbin/hostapd_cli")
32 self.dhcpd_conf = "/tmp/dhcpd.conf"
33 self.dhcpd_leases = "/tmp/dhcpd.leases"
Nebojsa Sabovic138ff912010-04-06 15:47:42 -070034
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -070035 # Router host.
Sam Leffler6969d1d2010-03-15 16:07:11 -070036 self.router = host
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -070037
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -070038 # hostapd configuration persists throughout the test, subsequent
39 # 'config' commands only modify it.
Paul Stewart7cb1f062010-06-10 15:46:20 -070040 self.defssid = defssid
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -070041 self.hostapd = {
42 'configured': False,
Nebojsa Sabovic60ae1462010-05-07 16:14:45 -070043 'file': "/tmp/hostapd-test.conf",
Paul Stewartf854d2e2011-05-04 13:19:18 -070044 'log': "/tmp/hostapd-test.log",
45 'log_count': 0,
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -070046 'driver': "nl80211",
47 'conf': {
48 'ssid': defssid,
Paul Stewartaa52e8c2011-05-24 08:46:23 -070049 'hw_mode': 'g',
mukesh agrawal05c455a2011-10-12 13:40:27 -070050 'ctrl_interface': '/tmp/hostapd-test.control',
51 'logger_syslog': '-1',
52 'logger_syslog_level': '0'
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -070053 }
54 }
Paul Stewartc2b3de82011-03-03 14:45:31 -080055 self.station = {
56 'configured': False,
57 'conf': {
58 'ssid': defssid,
Paul Stewartf05d7fd2011-04-06 16:19:37 -070059 },
Paul Stewartc2b3de82011-03-03 14:45:31 -080060 }
mukesh agrawalfe0e85b2011-08-09 14:24:15 -070061 self.default_interface = None
62 self.local_servers = []
63 self.force_local_server = "force_local_server" in params
64 self.dhcp_low = 1
65 self.dhcp_high = 128
Paul Stewartf05d7fd2011-04-06 16:19:37 -070066
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -070067 # Kill hostapd if already running.
Thieu Le7b23a542012-01-27 15:54:48 -080068 self.kill_hostapd()
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -070069
Nebojsa Sabovicbc245c62010-04-28 16:58:50 -070070 # Place us in the US by default
71 self.router.run("%s reg set US" % self.cmd_iw)
Sam Leffler6969d1d2010-03-15 16:07:11 -070072
Paul Stewartf05d7fd2011-04-06 16:19:37 -070073
Sam Leffler6969d1d2010-03-15 16:07:11 -070074 def create(self, params):
75 """ Create a wifi device of the specified type """
76 #
77 # AP mode is handled entirely by hostapd so we only
78 # have to setup others (mapping the bsd type to what
79 # iw wants)
80 #
81 # map from bsd types to iw types
Paul Stewartc2b3de82011-03-03 14:45:31 -080082 self.apmode = params['type'] in ("ap", "hostap")
83 if not self.apmode:
84 self.station['type'] = params['type']
Paul Stewart2ee7fdf2011-05-19 16:29:23 -070085 self.phytype = {
Sam Leffler6969d1d2010-03-15 16:07:11 -070086 "sta" : "managed",
87 "monitor" : "monitor",
88 "adhoc" : "adhoc",
89 "ibss" : "ibss",
Nebojsa Sabovic138ff912010-04-06 15:47:42 -070090 "ap" : "managed", # NB: handled by hostapd
91 "hostap" : "managed", # NB: handled by hostapd
Sam Leffler6969d1d2010-03-15 16:07:11 -070092 "mesh" : "mesh",
93 "wds" : "wds",
94 }[params['type']]
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -070095
Sam Leffler6969d1d2010-03-15 16:07:11 -070096
97 def destroy(self, params):
98 """ Destroy a previously created device """
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -070099 # For linux, this is the same as deconfig.
100 self.deconfig(params)
101
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700102 def has_local_server(self):
103 return bool(self.local_servers)
Sam Leffler6969d1d2010-03-15 16:07:11 -0700104
Paul Stewart9e3ff0b2011-08-17 20:35:19 -0700105 def cleanup(self, params):
106 """ Clean up any resources in use """
107 # For linux, this is a no-op
108 pass
109
Thieu Le7b23a542012-01-27 15:54:48 -0800110 def kill_hostapd(self):
111 """
112 Kills the hostapd process. Makes sure hostapd exits before
113 continuing since it sets the interface back to station mode in its
114 cleanup path. If we start another instance of hostapd before the
115 previous instance exits, the interface station mode will overwrite the
116 ap mode.
117 """
118 self.router.run("pkill hostapd >/dev/null 2>&1 && "
119 "while pgrep hostapd &> /dev/null; do sleep 1; done",
120 timeout=30,
121 ignore_status=True)
122
Paul Stewartc2b3de82011-03-03 14:45:31 -0800123 def hostap_config(self, params):
Sam Leffler6969d1d2010-03-15 16:07:11 -0700124 """ Configure the AP per test requirements """
125
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700126 # keep parameter modifications local-only
127 orig_params = params
128 params = params.copy()
129
Paul Stewart45338d22010-10-21 10:57:02 -0700130 multi_interface = 'multi_interface' in params
131 if multi_interface:
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700132 # remove non-hostapd config item from params
Paul Stewart45338d22010-10-21 10:57:02 -0700133 params.pop('multi_interface')
Paul Stewartc2b3de82011-03-03 14:45:31 -0800134 elif self.hostapd['configured'] or self.station['configured']:
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700135 self.deconfig({})
136
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700137 local_server = params.pop('local_server', False)
138
Paul Stewartc2b3de82011-03-03 14:45:31 -0800139 # Construct the hostapd.conf file and start hostapd.
140 conf = self.hostapd['conf']
Sam Lefflerbf5af622011-10-21 12:11:17 -0700141 # default RTS and frag threshold to ``off''
142 conf['rts_threshold'] = '2347'
143 conf['fragm_threshold'] = '2346'
144
Paul Stewartc2b3de82011-03-03 14:45:31 -0800145 tx_power_params = {}
146 htcaps = set()
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700147
Paul Stewartc2b3de82011-03-03 14:45:31 -0800148 conf['driver'] = params.get('hostapd_driver',
149 self.hostapd['driver'])
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700150
Paul Stewartc2b3de82011-03-03 14:45:31 -0800151 for k, v in params.iteritems():
152 if k == 'ssid':
153 conf['ssid'] = v
154 elif k == 'ssid_suffix':
155 conf['ssid'] = self.defssid + v
156 elif k == 'channel':
157 freq = int(v)
Paul Stewart2ee7fdf2011-05-19 16:29:23 -0700158 self.hostapd['frequency'] = freq
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700159
Paul Stewartc2b3de82011-03-03 14:45:31 -0800160 # 2.4GHz
161 if freq <= 2484:
162 # Make sure hw_mode is set
163 if conf.get('hw_mode') == 'a':
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700164 conf['hw_mode'] = 'g'
Paul Stewartc2b3de82011-03-03 14:45:31 -0800165
166 # Freq = 5 * chan + 2407, except channel 14
167 if freq == 2484:
168 conf['channel'] = 14
169 else:
170 conf['channel'] = (freq - 2407) / 5
171 # 5GHz
Sam Leffler6969d1d2010-03-15 16:07:11 -0700172 else:
Paul Stewartc2b3de82011-03-03 14:45:31 -0800173 # Make sure hw_mode is set
174 conf['hw_mode'] = 'a'
175 # Freq = 5 * chan + 4000
176 if freq < 5000:
177 conf['channel'] = (freq - 4000) / 5
178 # Freq = 5 * chan + 5000
179 else:
180 conf['channel'] = (freq - 5000) / 5
Sam Leffler6969d1d2010-03-15 16:07:11 -0700181
Paul Stewartc2b3de82011-03-03 14:45:31 -0800182 elif k == 'country':
183 conf['country_code'] = v
184 elif k == 'dotd':
185 conf['ieee80211d'] = 1
186 elif k == '-dotd':
187 conf['ieee80211d'] = 0
188 elif k == 'mode':
189 if v == '11a':
190 conf['hw_mode'] = 'a'
191 elif v == '11g':
192 conf['hw_mode'] = 'g'
193 elif v == '11b':
194 conf['hw_mode'] = 'b'
195 elif v == '11n':
196 conf['ieee80211n'] = 1
197 elif k == 'bintval':
198 conf['beacon_int'] = v
199 elif k == 'dtimperiod':
200 conf['dtim_period'] = v
201 elif k == 'rtsthreshold':
202 conf['rts_threshold'] = v
203 elif k == 'fragthreshold':
204 conf['fragm_threshold'] = v
205 elif k == 'shortpreamble':
206 conf['preamble'] = 1
207 elif k == 'authmode':
208 if v == "open":
209 conf['auth_algs'] = 1
210 elif v == "shared":
211 conf['auth_algs'] = 2
212 elif k == 'hidessid':
213 conf['ignore_broadcast_ssid'] = 1
214 elif k == 'wme':
215 conf['wmm_enabled'] = 1
216 elif k == '-wme':
217 conf['wmm_enabled'] = 0
218 elif k == 'deftxkey':
219 conf['wep_default_key'] = v
220 elif k == 'ht20':
221 htcaps.add('') # NB: ensure 802.11n setup below
222 conf['wmm_enabled'] = 1
223 elif k == 'ht40':
224 htcaps.add('[HT40-]')
225 htcaps.add('[HT40+]')
226 conf['wmm_enabled'] = 1
Paul Stewartc1df8d62011-04-07 14:28:15 -0700227 elif k in ('ht40+', 'ht40-'):
228 htcaps.add('[%s]' % k.upper())
229 conf['wmm_enabled'] = 1
Paul Stewartc2b3de82011-03-03 14:45:31 -0800230 elif k == 'shortgi':
231 htcaps.add('[SHORT-GI-20]')
232 htcaps.add('[SHORT-GI-40]')
233 elif k == 'pureg':
234 pass # TODO(sleffler) need hostapd support
235 elif k == 'puren':
236 pass # TODO(sleffler) need hostapd support
237 elif k == 'protmode':
238 pass # TODO(sleffler) need hostapd support
239 elif k == 'ht':
240 htcaps.add('') # NB: ensure 802.11n setup below
241 elif k == 'htprotmode':
242 pass # TODO(sleffler) need hostapd support
243 elif k == 'rifs':
244 pass # TODO(sleffler) need hostapd support
245 elif k == 'wepmode':
246 pass # NB: meaningless for hostapd; ignore
247 elif k == '-ampdu':
248 pass # TODO(sleffler) need hostapd support
249 elif k == 'txpower':
250 tx_power_params['power'] = v
Nebojsa Sabovic60ae1462010-05-07 16:14:45 -0700251 else:
Paul Stewartc2b3de82011-03-03 14:45:31 -0800252 conf[k] = v
Nebojsa Sabovic60ae1462010-05-07 16:14:45 -0700253
Paul Stewartc2b3de82011-03-03 14:45:31 -0800254 # Aggregate ht_capab.
255 if htcaps:
256 conf['ieee80211n'] = 1
257 conf['ht_capab'] = ''.join(htcaps)
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700258
Paul Stewartc2b3de82011-03-03 14:45:31 -0800259 # Figure out the correct interface.
Paul Stewart2ee7fdf2011-05-19 16:29:23 -0700260 conf['interface'] = self._get_wlanif(self.hostapd['frequency'],
261 self.phytype,
262 mode=conf.get('hw_mode', 'b'))
Paul Stewart9877fe42010-12-10 08:28:21 -0800263
Paul Stewartc2b3de82011-03-03 14:45:31 -0800264 # Generate hostapd.conf.
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700265 self._pre_config_hook(conf)
Paul Stewartc2b3de82011-03-03 14:45:31 -0800266 self.router.run("cat <<EOF >%s\n%s\nEOF\n" %
267 (self.hostapd['file'], '\n'.join(
268 "%s=%s" % kv for kv in conf.iteritems())))
269
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700270 self._pre_start_hook(orig_params)
Paul Stewartc2b3de82011-03-03 14:45:31 -0800271
272 # Run hostapd.
273 logging.info("Starting hostapd...")
Thieu Le7b23a542012-01-27 15:54:48 -0800274 self.router.run("%s -dd %s &> %s &" %
Paul Stewartf854d2e2011-05-04 13:19:18 -0700275 (self.cmd_hostapd, self.hostapd['file'], self.hostapd['log']))
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700276
Paul Stewartc2b3de82011-03-03 14:45:31 -0800277 if not multi_interface:
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700278 self.default_interface = conf['interface']
Paul Stewart1ae854b2011-02-08 15:10:14 -0800279
Paul Stewartc2b3de82011-03-03 14:45:31 -0800280 # Configure transmit power
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700281 tx_power_params['interface'] = conf['interface']
Paul Stewartc2b3de82011-03-03 14:45:31 -0800282 self.set_txpower(tx_power_params)
Nebojsa Sabovic138ff912010-04-06 15:47:42 -0700283
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700284 if self.force_local_server or local_server is not False:
285 self.start_local_server(conf['interface'])
Sam Leffler6969d1d2010-03-15 16:07:11 -0700286
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700287 self._post_start_hook(orig_params)
288
289 logging.info("AP configured.")
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700290 self.hostapd['configured'] = True
Sam Leffler6969d1d2010-03-15 16:07:11 -0700291
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700292 @staticmethod
293 def ip_addr(netblock, idx):
Paul Stewartf05d7fd2011-04-06 16:19:37 -0700294 """
295 Simple IPv4 calculator. Takes host address in "IP/bits" notation
296 and returns netmask, broadcast address as well as integer offsets
297 into the address range.
298 """
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700299 addr_str,bits = netblock.split('/')
Paul Stewartf05d7fd2011-04-06 16:19:37 -0700300 addr = map(int, addr_str.split('.'))
301 mask_bits = (-1 << (32-int(bits))) & 0xffffffff
302 mask = [(mask_bits >> s) & 0xff for s in range(24, -1, -8)]
Paul Stewart5977da92011-06-01 19:14:08 -0700303 if idx == 'local':
304 return addr_str
305 elif idx == 'netmask':
Paul Stewartf05d7fd2011-04-06 16:19:37 -0700306 return '.'.join(map(str, mask))
307 elif idx == 'broadcast':
308 offset = [m ^ 0xff for m in mask]
309 else:
310 offset = [(idx >> s) & 0xff for s in range(24, -1, -8)]
311 return '.'.join(map(str, [(a & m) + o
312 for a, m, o in zip(addr, mask, offset)]))
313
314
Paul Stewartc2b3de82011-03-03 14:45:31 -0800315 def station_config(self, params):
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700316 # keep parameter modifications local-only
317 orig_params = params
318 params = params.copy()
319
320 if 'multi_interface' in params:
321 raise NotImplementedError("station with multi_interface")
322
323 if self.station['type'] != 'ibss':
324 raise NotImplementedError("non-ibss station")
325
326 if self.station['configured'] or self.hostapd['configured']:
Paul Stewartc2b3de82011-03-03 14:45:31 -0800327 self.deconfig({})
328
Paul Stewartf05d7fd2011-04-06 16:19:37 -0700329 local_server = params.pop('local_server', False)
Paul Stewart2ee7fdf2011-05-19 16:29:23 -0700330 mode = None
Paul Stewartc2b3de82011-03-03 14:45:31 -0800331 conf = self.station['conf']
332 for k, v in params.iteritems():
333 if k == 'ssid_suffix':
334 conf['ssid'] = self.defssid + v
335 elif k == 'channel':
336 freq = int(v)
337 if freq > 2484:
Paul Stewart2ee7fdf2011-05-19 16:29:23 -0700338 mode = 'a'
Paul Stewartc2b3de82011-03-03 14:45:31 -0800339 elif k == 'mode':
340 if v == '11a':
Paul Stewart2ee7fdf2011-05-19 16:29:23 -0700341 mode = 'a'
Paul Stewartc2b3de82011-03-03 14:45:31 -0800342 else:
343 conf[k] = v
344
Paul Stewart2ee7fdf2011-05-19 16:29:23 -0700345 interface = self._get_wlanif(freq, self.phytype, mode)
346
Paul Stewartc2b3de82011-03-03 14:45:31 -0800347 # Run interface configuration commands
348 for k, v in conf.iteritems():
349 if k != 'ssid':
350 self.router.run("%s dev %s set %s %s" %
351 (self.cmd_iw, interface, k, v))
352
353 # Connect the station
354 self.router.run("%s link set %s up" % (self.cmd_ip, interface))
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700355 self.router.run("%s dev %s ibss join %s %d" %
356 (self.cmd_iw, interface, conf['ssid'], freq))
Paul Stewartc2b3de82011-03-03 14:45:31 -0800357
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700358 if self.force_local_server or local_server is not False:
359 self.start_local_server(interface)
Paul Stewartc2b3de82011-03-03 14:45:31 -0800360
361 self.station['configured'] = True
362 self.station['interface'] = interface
363
364
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700365 def start_local_server(self, interface):
366 logging.info("Starting up local server...")
367
368 if len(self.local_servers) >= 256:
369 raise error.TestFail('Exhausted available local servers')
370
371 netblock = '%d.%d.%d.%d/24' % \
372 (192, 168, len(self.local_servers), 254)
373
374 params = {}
375 params['netblock'] = netblock
376 params['subnet'] = self.ip_addr(netblock, 0)
377 params['netmask'] = self.ip_addr(netblock, 'netmask')
378 params['dhcp_range'] = ' '.join(
379 (self.ip_addr(netblock, self.dhcp_low),
380 self.ip_addr(netblock, self.dhcp_high)))
mukesh agrawal05c455a2011-10-12 13:40:27 -0700381 params['interface'] = interface
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700382
383 params['ip_params'] = ("%s broadcast %s dev %s" %
384 (netblock,
385 self.ip_addr(netblock, 'broadcast'),
386 interface))
387 self.local_servers.append(params)
388
389 self.router.run("%s addr flush %s" %
390 (self.cmd_ip, interface))
391 self.router.run("%s addr add %s" %
392 (self.cmd_ip, params['ip_params']))
393 self.router.run("%s link set %s up" %
394 (self.cmd_ip, interface))
mukesh agrawal05c455a2011-10-12 13:40:27 -0700395 self.start_dhcp_server()
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700396
mukesh agrawal05c455a2011-10-12 13:40:27 -0700397 def start_dhcp_server(self):
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700398 dhcp_conf = '\n'.join(map(
399 lambda server_conf: \
400 "subnet %(subnet)s netmask %(netmask)s {\n" \
401 " range %(dhcp_range)s;\n" \
402 "}" % server_conf,
403 self.local_servers))
404 self.router.run("cat <<EOF >%s\n%s\nEOF\n" %
405 (self.dhcpd_conf,
406 '\n'.join(('ddns-update-style none;', dhcp_conf))))
407 self.router.run("touch %s" % self.dhcpd_leases)
408
409 self.router.run("pkill dhcpd >/dev/null 2>&1", ignore_status=True)
410 self.router.run("%s -q -cf %s -lf %s" %
411 (self.cmd_dhcpd, self.dhcpd_conf, self.dhcpd_leases))
412
413
Paul Stewartc2b3de82011-03-03 14:45:31 -0800414 def config(self, params):
415 if self.apmode:
416 self.hostap_config(params)
417 else:
418 self.station_config(params)
419
420
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700421 def get_wifi_ip(self, ap_num):
422 if self.local_servers:
423 return self.ip_addr(self.local_servers[ap_num]['netblock'],
424 'local')
425 else:
426 raise error.TestFail("No IP address assigned")
Paul Stewart5977da92011-06-01 19:14:08 -0700427
428
Sam Leffler6969d1d2010-03-15 16:07:11 -0700429 def deconfig(self, params):
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700430 """ De-configure the AP (will also bring wlan down) """
Sam Leffler6969d1d2010-03-15 16:07:11 -0700431
Paul Stewartc2b3de82011-03-03 14:45:31 -0800432 if not self.hostapd['configured'] and not self.station['configured']:
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700433 return
Sam Leffler6969d1d2010-03-15 16:07:11 -0700434
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700435 # Taking down hostapd takes wlan0 and mon.wlan0 down.
Paul Stewartc2b3de82011-03-03 14:45:31 -0800436 if self.hostapd['configured']:
Paul Stewart64cc4292011-06-01 10:59:36 -0700437 if 'silent' in params:
438 # Deconfigure without notifying DUT. Remove the monitor
439 # interface hostapd uses to send beacon and DEAUTH packets
440 self._remove_interfaces()
441
Thieu Le7b23a542012-01-27 15:54:48 -0800442 self.kill_hostapd()
Paul Stewartc2b3de82011-03-03 14:45:31 -0800443# self.router.run("rm -f %s" % self.hostapd['file'])
Paul Stewartf854d2e2011-05-04 13:19:18 -0700444 self.router.get_file(self.hostapd['log'],
445 'debug/hostapd_router_%d.log' %
446 self.hostapd['log_count'])
447 self.hostapd['log_count'] += 1
Paul Stewartc2b3de82011-03-03 14:45:31 -0800448 if self.station['configured']:
449 if self.station['type'] == 'ibss':
450 self.router.run("%s dev %s ibss leave" %
451 (self.cmd_iw, self.station['interface']))
452 else:
453 self.router.run("%s dev %s disconnect" %
454 (self.cmd_iw, self.station['interface']))
455 self.router.run("%s link set %s down" % (self.cmd_ip,
456 self.station['interface']))
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700457
458 if self.local_servers:
459 self.router.run("pkill dhcpd >/dev/null 2>&1",
460 ignore_status=True)
461 for server in self.local_servers:
Paul Stewartf05d7fd2011-04-06 16:19:37 -0700462 self.router.run("%s addr del %s" %
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700463 (self.cmd_ip, server['ip_params']))
464 self.local_servers = []
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700465
466 self.hostapd['configured'] = False
Paul Stewartc2b3de82011-03-03 14:45:31 -0800467 self.station['configured'] = False
Paul Stewart7cb1f062010-06-10 15:46:20 -0700468
469
470 def get_ssid(self):
471 return self.hostapd['conf']['ssid']
Paul Stewart98022e22010-10-22 10:33:14 -0700472
473
474 def set_txpower(self, params):
475 self.router.run("%s dev %s set txpower %s" %
476 (self.cmd_iw, params.get('interface',
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700477 self.default_interface),
Paul Stewart98022e22010-10-22 10:33:14 -0700478 params.get('power', 'auto')))
Paul Stewartaa52e8c2011-05-24 08:46:23 -0700479
480
481 def deauth(self, params):
482 self.router.run('%s -p%s deauthenticate %s' %
483 (self.cmd_hostapd_cli,
484 self.hostapd['conf']['ctrl_interface'],
485 params['client']))
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700486
487
488 def _pre_config_hook(self, config):
489 """
490 Hook for subclasses. Run after gathering configuration parameters,
491 but before writing parameters to config file.
492 """
493 pass
494
495
496 def _pre_start_hook(self, params):
497 """
498 Hook for subclasses. Run after generating hostapd config file, but
499 before starting hostapd.
500 """
501 pass
502
503
504 def _post_start_hook(self, params):
505 """Hook for subclasses. Run after starting hostapd."""
506 pass