blob: fe8696c15cf0fbeec037ec150332d62334c066b5 [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.
68 self.router.run("pkill hostapd >/dev/null 2>&1", ignore_status=True)
69
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
Paul Stewartc2b3de82011-03-03 14:45:31 -0800110 def hostap_config(self, params):
Sam Leffler6969d1d2010-03-15 16:07:11 -0700111 """ Configure the AP per test requirements """
112
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700113 # keep parameter modifications local-only
114 orig_params = params
115 params = params.copy()
116
Paul Stewart45338d22010-10-21 10:57:02 -0700117 multi_interface = 'multi_interface' in params
118 if multi_interface:
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700119 # remove non-hostapd config item from params
Paul Stewart45338d22010-10-21 10:57:02 -0700120 params.pop('multi_interface')
Paul Stewartc2b3de82011-03-03 14:45:31 -0800121 elif self.hostapd['configured'] or self.station['configured']:
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700122 self.deconfig({})
123
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700124 local_server = params.pop('local_server', False)
125
Paul Stewartc2b3de82011-03-03 14:45:31 -0800126 # Construct the hostapd.conf file and start hostapd.
127 conf = self.hostapd['conf']
128 tx_power_params = {}
129 htcaps = set()
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700130
Paul Stewartc2b3de82011-03-03 14:45:31 -0800131 conf['driver'] = params.get('hostapd_driver',
132 self.hostapd['driver'])
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700133
Paul Stewartc2b3de82011-03-03 14:45:31 -0800134 for k, v in params.iteritems():
135 if k == 'ssid':
136 conf['ssid'] = v
137 elif k == 'ssid_suffix':
138 conf['ssid'] = self.defssid + v
139 elif k == 'channel':
140 freq = int(v)
Paul Stewart2ee7fdf2011-05-19 16:29:23 -0700141 self.hostapd['frequency'] = freq
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700142
Paul Stewartc2b3de82011-03-03 14:45:31 -0800143 # 2.4GHz
144 if freq <= 2484:
145 # Make sure hw_mode is set
146 if conf.get('hw_mode') == 'a':
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700147 conf['hw_mode'] = 'g'
Paul Stewartc2b3de82011-03-03 14:45:31 -0800148
149 # Freq = 5 * chan + 2407, except channel 14
150 if freq == 2484:
151 conf['channel'] = 14
152 else:
153 conf['channel'] = (freq - 2407) / 5
154 # 5GHz
Sam Leffler6969d1d2010-03-15 16:07:11 -0700155 else:
Paul Stewartc2b3de82011-03-03 14:45:31 -0800156 # Make sure hw_mode is set
157 conf['hw_mode'] = 'a'
158 # Freq = 5 * chan + 4000
159 if freq < 5000:
160 conf['channel'] = (freq - 4000) / 5
161 # Freq = 5 * chan + 5000
162 else:
163 conf['channel'] = (freq - 5000) / 5
Sam Leffler6969d1d2010-03-15 16:07:11 -0700164
Paul Stewartc2b3de82011-03-03 14:45:31 -0800165 elif k == 'country':
166 conf['country_code'] = v
167 elif k == 'dotd':
168 conf['ieee80211d'] = 1
169 elif k == '-dotd':
170 conf['ieee80211d'] = 0
171 elif k == 'mode':
172 if v == '11a':
173 conf['hw_mode'] = 'a'
174 elif v == '11g':
175 conf['hw_mode'] = 'g'
176 elif v == '11b':
177 conf['hw_mode'] = 'b'
178 elif v == '11n':
179 conf['ieee80211n'] = 1
180 elif k == 'bintval':
181 conf['beacon_int'] = v
182 elif k == 'dtimperiod':
183 conf['dtim_period'] = v
184 elif k == 'rtsthreshold':
185 conf['rts_threshold'] = v
186 elif k == 'fragthreshold':
187 conf['fragm_threshold'] = v
188 elif k == 'shortpreamble':
189 conf['preamble'] = 1
190 elif k == 'authmode':
191 if v == "open":
192 conf['auth_algs'] = 1
193 elif v == "shared":
194 conf['auth_algs'] = 2
195 elif k == 'hidessid':
196 conf['ignore_broadcast_ssid'] = 1
197 elif k == 'wme':
198 conf['wmm_enabled'] = 1
199 elif k == '-wme':
200 conf['wmm_enabled'] = 0
201 elif k == 'deftxkey':
202 conf['wep_default_key'] = v
203 elif k == 'ht20':
204 htcaps.add('') # NB: ensure 802.11n setup below
205 conf['wmm_enabled'] = 1
206 elif k == 'ht40':
207 htcaps.add('[HT40-]')
208 htcaps.add('[HT40+]')
209 conf['wmm_enabled'] = 1
Paul Stewartc1df8d62011-04-07 14:28:15 -0700210 elif k in ('ht40+', 'ht40-'):
211 htcaps.add('[%s]' % k.upper())
212 conf['wmm_enabled'] = 1
Paul Stewartc2b3de82011-03-03 14:45:31 -0800213 elif k == 'shortgi':
214 htcaps.add('[SHORT-GI-20]')
215 htcaps.add('[SHORT-GI-40]')
216 elif k == 'pureg':
217 pass # TODO(sleffler) need hostapd support
218 elif k == 'puren':
219 pass # TODO(sleffler) need hostapd support
220 elif k == 'protmode':
221 pass # TODO(sleffler) need hostapd support
222 elif k == 'ht':
223 htcaps.add('') # NB: ensure 802.11n setup below
224 elif k == 'htprotmode':
225 pass # TODO(sleffler) need hostapd support
226 elif k == 'rifs':
227 pass # TODO(sleffler) need hostapd support
228 elif k == 'wepmode':
229 pass # NB: meaningless for hostapd; ignore
230 elif k == '-ampdu':
231 pass # TODO(sleffler) need hostapd support
232 elif k == 'txpower':
233 tx_power_params['power'] = v
Nebojsa Sabovic60ae1462010-05-07 16:14:45 -0700234 else:
Paul Stewartc2b3de82011-03-03 14:45:31 -0800235 conf[k] = v
Nebojsa Sabovic60ae1462010-05-07 16:14:45 -0700236
Paul Stewartc2b3de82011-03-03 14:45:31 -0800237 # Aggregate ht_capab.
238 if htcaps:
239 conf['ieee80211n'] = 1
240 conf['ht_capab'] = ''.join(htcaps)
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700241
Paul Stewartc2b3de82011-03-03 14:45:31 -0800242 # Figure out the correct interface.
Paul Stewart2ee7fdf2011-05-19 16:29:23 -0700243 conf['interface'] = self._get_wlanif(self.hostapd['frequency'],
244 self.phytype,
245 mode=conf.get('hw_mode', 'b'))
Paul Stewart9877fe42010-12-10 08:28:21 -0800246
Paul Stewartc2b3de82011-03-03 14:45:31 -0800247 # Generate hostapd.conf.
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700248 self._pre_config_hook(conf)
Paul Stewartc2b3de82011-03-03 14:45:31 -0800249 self.router.run("cat <<EOF >%s\n%s\nEOF\n" %
250 (self.hostapd['file'], '\n'.join(
251 "%s=%s" % kv for kv in conf.iteritems())))
252
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700253 self._pre_start_hook(orig_params)
Paul Stewartc2b3de82011-03-03 14:45:31 -0800254
255 # Run hostapd.
256 logging.info("Starting hostapd...")
Paul Stewartf854d2e2011-05-04 13:19:18 -0700257 self.router.run("%s -dd %s > %s &" %
258 (self.cmd_hostapd, self.hostapd['file'], self.hostapd['log']))
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700259
Paul Stewartc2b3de82011-03-03 14:45:31 -0800260 if not multi_interface:
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700261 self.default_interface = conf['interface']
Paul Stewart1ae854b2011-02-08 15:10:14 -0800262
Paul Stewartc2b3de82011-03-03 14:45:31 -0800263 # Configure transmit power
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700264 tx_power_params['interface'] = conf['interface']
Paul Stewartc2b3de82011-03-03 14:45:31 -0800265 self.set_txpower(tx_power_params)
Nebojsa Sabovic138ff912010-04-06 15:47:42 -0700266
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700267 if self.force_local_server or local_server is not False:
268 self.start_local_server(conf['interface'])
Sam Leffler6969d1d2010-03-15 16:07:11 -0700269
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700270 self._post_start_hook(orig_params)
271
272 logging.info("AP configured.")
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700273 self.hostapd['configured'] = True
Sam Leffler6969d1d2010-03-15 16:07:11 -0700274
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700275 @staticmethod
276 def ip_addr(netblock, idx):
Paul Stewartf05d7fd2011-04-06 16:19:37 -0700277 """
278 Simple IPv4 calculator. Takes host address in "IP/bits" notation
279 and returns netmask, broadcast address as well as integer offsets
280 into the address range.
281 """
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700282 addr_str,bits = netblock.split('/')
Paul Stewartf05d7fd2011-04-06 16:19:37 -0700283 addr = map(int, addr_str.split('.'))
284 mask_bits = (-1 << (32-int(bits))) & 0xffffffff
285 mask = [(mask_bits >> s) & 0xff for s in range(24, -1, -8)]
Paul Stewart5977da92011-06-01 19:14:08 -0700286 if idx == 'local':
287 return addr_str
288 elif idx == 'netmask':
Paul Stewartf05d7fd2011-04-06 16:19:37 -0700289 return '.'.join(map(str, mask))
290 elif idx == 'broadcast':
291 offset = [m ^ 0xff for m in mask]
292 else:
293 offset = [(idx >> s) & 0xff for s in range(24, -1, -8)]
294 return '.'.join(map(str, [(a & m) + o
295 for a, m, o in zip(addr, mask, offset)]))
296
297
Paul Stewartc2b3de82011-03-03 14:45:31 -0800298 def station_config(self, params):
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700299 # keep parameter modifications local-only
300 orig_params = params
301 params = params.copy()
302
303 if 'multi_interface' in params:
304 raise NotImplementedError("station with multi_interface")
305
306 if self.station['type'] != 'ibss':
307 raise NotImplementedError("non-ibss station")
308
309 if self.station['configured'] or self.hostapd['configured']:
Paul Stewartc2b3de82011-03-03 14:45:31 -0800310 self.deconfig({})
311
Paul Stewartf05d7fd2011-04-06 16:19:37 -0700312 local_server = params.pop('local_server', False)
Paul Stewart2ee7fdf2011-05-19 16:29:23 -0700313 mode = None
Paul Stewartc2b3de82011-03-03 14:45:31 -0800314 conf = self.station['conf']
315 for k, v in params.iteritems():
316 if k == 'ssid_suffix':
317 conf['ssid'] = self.defssid + v
318 elif k == 'channel':
319 freq = int(v)
320 if freq > 2484:
Paul Stewart2ee7fdf2011-05-19 16:29:23 -0700321 mode = 'a'
Paul Stewartc2b3de82011-03-03 14:45:31 -0800322 elif k == 'mode':
323 if v == '11a':
Paul Stewart2ee7fdf2011-05-19 16:29:23 -0700324 mode = 'a'
Paul Stewartc2b3de82011-03-03 14:45:31 -0800325 else:
326 conf[k] = v
327
Paul Stewart2ee7fdf2011-05-19 16:29:23 -0700328 interface = self._get_wlanif(freq, self.phytype, mode)
329
Paul Stewartc2b3de82011-03-03 14:45:31 -0800330 # Run interface configuration commands
331 for k, v in conf.iteritems():
332 if k != 'ssid':
333 self.router.run("%s dev %s set %s %s" %
334 (self.cmd_iw, interface, k, v))
335
336 # Connect the station
337 self.router.run("%s link set %s up" % (self.cmd_ip, interface))
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700338 self.router.run("%s dev %s ibss join %s %d" %
339 (self.cmd_iw, interface, conf['ssid'], freq))
Paul Stewartc2b3de82011-03-03 14:45:31 -0800340
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700341 if self.force_local_server or local_server is not False:
342 self.start_local_server(interface)
Paul Stewartc2b3de82011-03-03 14:45:31 -0800343
344 self.station['configured'] = True
345 self.station['interface'] = interface
346
347
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700348 def start_local_server(self, interface):
349 logging.info("Starting up local server...")
350
351 if len(self.local_servers) >= 256:
352 raise error.TestFail('Exhausted available local servers')
353
354 netblock = '%d.%d.%d.%d/24' % \
355 (192, 168, len(self.local_servers), 254)
356
357 params = {}
358 params['netblock'] = netblock
359 params['subnet'] = self.ip_addr(netblock, 0)
360 params['netmask'] = self.ip_addr(netblock, 'netmask')
361 params['dhcp_range'] = ' '.join(
362 (self.ip_addr(netblock, self.dhcp_low),
363 self.ip_addr(netblock, self.dhcp_high)))
mukesh agrawal05c455a2011-10-12 13:40:27 -0700364 params['interface'] = interface
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700365
366 params['ip_params'] = ("%s broadcast %s dev %s" %
367 (netblock,
368 self.ip_addr(netblock, 'broadcast'),
369 interface))
370 self.local_servers.append(params)
371
372 self.router.run("%s addr flush %s" %
373 (self.cmd_ip, interface))
374 self.router.run("%s addr add %s" %
375 (self.cmd_ip, params['ip_params']))
376 self.router.run("%s link set %s up" %
377 (self.cmd_ip, interface))
mukesh agrawal05c455a2011-10-12 13:40:27 -0700378 self.start_dhcp_server()
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700379
mukesh agrawal05c455a2011-10-12 13:40:27 -0700380 def start_dhcp_server(self):
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700381 dhcp_conf = '\n'.join(map(
382 lambda server_conf: \
383 "subnet %(subnet)s netmask %(netmask)s {\n" \
384 " range %(dhcp_range)s;\n" \
385 "}" % server_conf,
386 self.local_servers))
387 self.router.run("cat <<EOF >%s\n%s\nEOF\n" %
388 (self.dhcpd_conf,
389 '\n'.join(('ddns-update-style none;', dhcp_conf))))
390 self.router.run("touch %s" % self.dhcpd_leases)
391
392 self.router.run("pkill dhcpd >/dev/null 2>&1", ignore_status=True)
393 self.router.run("%s -q -cf %s -lf %s" %
394 (self.cmd_dhcpd, self.dhcpd_conf, self.dhcpd_leases))
395
396
Paul Stewartc2b3de82011-03-03 14:45:31 -0800397 def config(self, params):
398 if self.apmode:
399 self.hostap_config(params)
400 else:
401 self.station_config(params)
402
403
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700404 def get_wifi_ip(self, ap_num):
405 if self.local_servers:
406 return self.ip_addr(self.local_servers[ap_num]['netblock'],
407 'local')
408 else:
409 raise error.TestFail("No IP address assigned")
Paul Stewart5977da92011-06-01 19:14:08 -0700410
411
Sam Leffler6969d1d2010-03-15 16:07:11 -0700412 def deconfig(self, params):
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700413 """ De-configure the AP (will also bring wlan down) """
Sam Leffler6969d1d2010-03-15 16:07:11 -0700414
Paul Stewartc2b3de82011-03-03 14:45:31 -0800415 if not self.hostapd['configured'] and not self.station['configured']:
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700416 return
Sam Leffler6969d1d2010-03-15 16:07:11 -0700417
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700418 # Taking down hostapd takes wlan0 and mon.wlan0 down.
Paul Stewartc2b3de82011-03-03 14:45:31 -0800419 if self.hostapd['configured']:
Paul Stewart64cc4292011-06-01 10:59:36 -0700420 if 'silent' in params:
421 # Deconfigure without notifying DUT. Remove the monitor
422 # interface hostapd uses to send beacon and DEAUTH packets
423 self._remove_interfaces()
424
Paul Stewartc2b3de82011-03-03 14:45:31 -0800425 self.router.run("pkill hostapd >/dev/null 2>&1", ignore_status=True)
426# self.router.run("rm -f %s" % self.hostapd['file'])
Paul Stewartf854d2e2011-05-04 13:19:18 -0700427 self.router.get_file(self.hostapd['log'],
428 'debug/hostapd_router_%d.log' %
429 self.hostapd['log_count'])
430 self.hostapd['log_count'] += 1
Paul Stewartc2b3de82011-03-03 14:45:31 -0800431 if self.station['configured']:
432 if self.station['type'] == 'ibss':
433 self.router.run("%s dev %s ibss leave" %
434 (self.cmd_iw, self.station['interface']))
435 else:
436 self.router.run("%s dev %s disconnect" %
437 (self.cmd_iw, self.station['interface']))
438 self.router.run("%s link set %s down" % (self.cmd_ip,
439 self.station['interface']))
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700440
441 if self.local_servers:
442 self.router.run("pkill dhcpd >/dev/null 2>&1",
443 ignore_status=True)
444 for server in self.local_servers:
Paul Stewartf05d7fd2011-04-06 16:19:37 -0700445 self.router.run("%s addr del %s" %
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700446 (self.cmd_ip, server['ip_params']))
447 self.local_servers = []
Nebojsa Sabovic4cc2ce92010-04-21 15:08:01 -0700448
449 self.hostapd['configured'] = False
Paul Stewartc2b3de82011-03-03 14:45:31 -0800450 self.station['configured'] = False
Paul Stewart7cb1f062010-06-10 15:46:20 -0700451
452
453 def get_ssid(self):
454 return self.hostapd['conf']['ssid']
Paul Stewart98022e22010-10-22 10:33:14 -0700455
456
457 def set_txpower(self, params):
458 self.router.run("%s dev %s set txpower %s" %
459 (self.cmd_iw, params.get('interface',
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700460 self.default_interface),
Paul Stewart98022e22010-10-22 10:33:14 -0700461 params.get('power', 'auto')))
Paul Stewartaa52e8c2011-05-24 08:46:23 -0700462
463
464 def deauth(self, params):
465 self.router.run('%s -p%s deauthenticate %s' %
466 (self.cmd_hostapd_cli,
467 self.hostapd['conf']['ctrl_interface'],
468 params['client']))
mukesh agrawalfe0e85b2011-08-09 14:24:15 -0700469
470
471 def _pre_config_hook(self, config):
472 """
473 Hook for subclasses. Run after gathering configuration parameters,
474 but before writing parameters to config file.
475 """
476 pass
477
478
479 def _pre_start_hook(self, params):
480 """
481 Hook for subclasses. Run after generating hostapd config file, but
482 before starting hostapd.
483 """
484 pass
485
486
487 def _post_start_hook(self, params):
488 """Hook for subclasses. Run after starting hostapd."""
489 pass