| OLD | NEW |
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import re | 5 import logging, re |
| 6 | 6 |
| 7 def isLinuxRouter(router): | 7 def isLinuxRouter(router): |
| 8 router_uname = router.run('uname').stdout | 8 router_uname = router.run('uname').stdout |
| 9 return re.search('Linux', router_uname) | 9 return re.search('Linux', router_uname) |
| 10 | 10 |
| 11 class LinuxRouter(object): | 11 class LinuxRouter(object): |
| 12 """ | 12 """ |
| 13 Linux/mac80211-style WiFi Router support for WiFiTest class. | 13 Linux/mac80211-style WiFi Router support for WiFiTest class. |
| 14 | 14 |
| 15 This class implements test methods/steps that communicate with a | 15 This class implements test methods/steps that communicate with a |
| (...skipping 10 matching lines...) Expand all Loading... |
| 26 self.cmd_ip = "/usr/sbin/ip" | 26 self.cmd_ip = "/usr/sbin/ip" |
| 27 self.cmd_brctl = "/usr/sbin/brctl" | 27 self.cmd_brctl = "/usr/sbin/brctl" |
| 28 self.cmd_hostapd = "/usr/sbin/hostapd" | 28 self.cmd_hostapd = "/usr/sbin/hostapd" |
| 29 | 29 |
| 30 # Router host. | 30 # Router host. |
| 31 self.router = host | 31 self.router = host |
| 32 | 32 |
| 33 # Network interfaces. | 33 # Network interfaces. |
| 34 self.bridgeif = params.get('bridgedev', "br-lan") | 34 self.bridgeif = params.get('bridgedev', "br-lan") |
| 35 self.wiredif = params.get('wiredev', "eth1") | 35 self.wiredif = params.get('wiredev', "eth1") |
| 36 self.wlanif = "wlan0" | 36 self.wlanif2 = "wlan2" |
| 37 self.wlanif5 = "wlan5" |
| 37 | 38 |
| 38 # Default to 1st available wireless phy. | 39 # Default to 1st available wireless phy. |
| 39 if "phydev" not in params: | 40 if "phydev2" not in params: |
| 40 output = self.router.run("%s list" % self.cmd_iw).stdout | 41 output = self.router.run("%s list" % self.cmd_iw).stdout |
| 41 test = re.compile("Wiphy (.*)") | 42 test = re.compile("Wiphy (.*)") |
| 42 for line in output.splitlines(): | 43 for line in output.splitlines(): |
| 43 m = test.match(line) | 44 m = test.match(line) |
| 44 if m: | 45 if m: |
| 45 self.phydev = m.group(1) | 46 self.phydev2 = m.group(1) |
| 47 self.phydev5 = self.phydev2 |
| 46 break | 48 break |
| 47 else: | 49 else: |
| 48 raise error.TestFail("No Wireless NIC detected on the device") | 50 raise error.TestFail("No Wireless NIC detected on the device") |
| 49 else: | 51 else: |
| 50 self.phydev = params['phydev'] | 52 self.phydev2 = params['phydev2'] |
| 53 self.phydev5 = params.get('phydev5', self.phydev2) |
| 51 | 54 |
| 52 | 55 |
| 53 # hostapd configuration persists throughout the test, subsequent | 56 # hostapd configuration persists throughout the test, subsequent |
| 54 # 'config' commands only modify it. | 57 # 'config' commands only modify it. |
| 55 self.hostapd = { | 58 self.hostapd = { |
| 56 'configured': False, | 59 'configured': False, |
| 57 'file': "/tmp/%s.conf" % self.phydev, | 60 'file': "/tmp/hostapd-test.conf", |
| 58 'driver': "nl80211", | 61 'driver': "nl80211", |
| 59 'conf': { | 62 'conf': { |
| 60 'ssid': defssid, | 63 'ssid': defssid, |
| 61 'interface': self.wlanif, | |
| 62 'bridge': self.bridgeif, | 64 'bridge': self.bridgeif, |
| 63 'hw_mode': 'g' | 65 'hw_mode': 'g' |
| 64 } | 66 } |
| 65 } | 67 } |
| 66 | 68 |
| 67 # Kill hostapd if already running. | 69 # Kill hostapd if already running. |
| 68 self.router.run("pkill hostapd >/dev/null 2>&1", ignore_status=True) | 70 self.router.run("pkill hostapd >/dev/null 2>&1", ignore_status=True) |
| 69 | 71 |
| 70 # Remove all bridges. | 72 # Remove all bridges. |
| 71 output = self.router.run("%s show" % self.cmd_brctl).stdout | 73 output = self.router.run("%s show" % self.cmd_brctl).stdout |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 phytype = { | 105 phytype = { |
| 104 "sta" : "managed", | 106 "sta" : "managed", |
| 105 "monitor" : "monitor", | 107 "monitor" : "monitor", |
| 106 "adhoc" : "adhoc", | 108 "adhoc" : "adhoc", |
| 107 "ibss" : "ibss", | 109 "ibss" : "ibss", |
| 108 "ap" : "managed", # NB: handled by hostapd | 110 "ap" : "managed", # NB: handled by hostapd |
| 109 "hostap" : "managed", # NB: handled by hostapd | 111 "hostap" : "managed", # NB: handled by hostapd |
| 110 "mesh" : "mesh", | 112 "mesh" : "mesh", |
| 111 "wds" : "wds", | 113 "wds" : "wds", |
| 112 }[params['type']] | 114 }[params['type']] |
| 113 phydev = params.get('phydev', self.phydev) | 115 |
| 114 self.router.run("%s phy %s interface add %s type %s" % | 116 self.router.run("%s phy %s interface add %s type %s" % |
| 115 (self.cmd_iw, phydev, self.wlanif, phytype)) | 117 (self.cmd_iw, self.phydev2, self.wlanif2, phytype)) |
| 116 | 118 self.router.run("%s phy %s interface add %s type %s" % |
| 119 (self.cmd_iw, self.phydev5, self.wlanif5, phytype)) |
| 117 | 120 |
| 118 | 121 |
| 119 def destroy(self, params): | 122 def destroy(self, params): |
| 120 """ Destroy a previously created device """ | 123 """ Destroy a previously created device """ |
| 121 # For linux, this is the same as deconfig. | 124 # For linux, this is the same as deconfig. |
| 122 self.deconfig(params) | 125 self.deconfig(params) |
| 123 | 126 |
| 124 | 127 |
| 125 | 128 |
| 126 def config(self, params): | 129 def config(self, params): |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 elif k == '-ampdu': | 233 elif k == '-ampdu': |
| 231 pass # TODO(sleffler) need hostapd support | 234 pass # TODO(sleffler) need hostapd support |
| 232 else: | 235 else: |
| 233 conf[k] = v | 236 conf[k] = v |
| 234 | 237 |
| 235 # Aggregate ht_capab. | 238 # Aggregate ht_capab. |
| 236 if htcaps: | 239 if htcaps: |
| 237 conf['ieee80211n'] = 1 | 240 conf['ieee80211n'] = 1 |
| 238 conf['ht_capab'] = ''.join(htcaps) | 241 conf['ht_capab'] = ''.join(htcaps) |
| 239 | 242 |
| 243 # Figure out the correct interface. |
| 244 if conf.get('hw_mode', 'b') == 'a': |
| 245 conf['interface'] = self.wlanif5 |
| 246 else: |
| 247 conf['interface'] = self.wlanif2 |
| 248 |
| 240 # Generate hostapd.conf. | 249 # Generate hostapd.conf. |
| 241 self.router.run("cat <<EOF >%s\n%s\nEOF\n" % | 250 self.router.run("cat <<EOF >%s\n%s\nEOF\n" % |
| 242 (self.hostapd['file'], '\n'.join( | 251 (self.hostapd['file'], '\n'.join( |
| 243 "%s=%s" % kv for kv in conf.iteritems()))) | 252 "%s=%s" % kv for kv in conf.iteritems()))) |
| 244 | 253 |
| 245 # Run hostapd. | 254 # Run hostapd. |
| 255 logging.info("Starting hostapd...") |
| 246 self.router.run("%s -B %s" % | 256 self.router.run("%s -B %s" % |
| 247 (self.cmd_hostapd, self.hostapd['file'])) | 257 (self.cmd_hostapd, self.hostapd['file'])) |
| 248 | 258 |
| 259 |
| 249 # Set up the bridge. | 260 # Set up the bridge. |
| 261 logging.info("Setting up the bridge...") |
| 250 self.router.run("%s setfd %s %d" % | 262 self.router.run("%s setfd %s %d" % |
| 251 (self.cmd_brctl, self.bridgeif, 0)) | 263 (self.cmd_brctl, self.bridgeif, 0)) |
| 252 self.router.run("%s addif %s %s" % | 264 self.router.run("%s addif %s %s" % |
| 253 (self.cmd_brctl, self.bridgeif, self.wiredif)) | 265 (self.cmd_brctl, self.bridgeif, self.wiredif)) |
| 254 self.router.run("%s link set %s up" % | 266 self.router.run("%s link set %s up" % |
| 255 (self.cmd_ip, self.wiredif)) | 267 (self.cmd_ip, self.wiredif)) |
| 256 self.router.run("%s link set %s up" % | 268 self.router.run("%s link set %s up" % |
| 257 (self.cmd_ip, self.bridgeif)) | 269 (self.cmd_ip, self.bridgeif)) |
| 258 | 270 |
| 271 logging.info("AP configured.") |
| 272 |
| 259 # else: | 273 # else: |
| 260 # # use iw to manually configure interface | 274 # # use iw to manually configure interface |
| 261 | 275 |
| 262 self.hostapd['configured'] = True | 276 self.hostapd['configured'] = True |
| 263 | 277 |
| 264 | 278 |
| 265 def deconfig(self, params): | 279 def deconfig(self, params): |
| 266 """ De-configure the AP (will also bring wlan and the bridge down) """ | 280 """ De-configure the AP (will also bring wlan and the bridge down) """ |
| 267 | 281 |
| 268 if not self.hostapd['configured']: | 282 if not self.hostapd['configured']: |
| 269 return | 283 return |
| 270 | 284 |
| 271 # Taking down hostapd takes wlan0 and mon.wlan0 down. | 285 # Taking down hostapd takes wlan0 and mon.wlan0 down. |
| 272 self.router.run("pkill hostapd >/dev/null 2>&1", ignore_status=True) | 286 self.router.run("pkill hostapd >/dev/null 2>&1", ignore_status=True) |
| 273 # self.router.run("rm -f %s" % self.hostapd['file']) | 287 # self.router.run("rm -f %s" % self.hostapd['file']) |
| 274 | 288 |
| 275 # Tear down the bridge. | 289 # Tear down the bridge. |
| 276 self.router.run("%s link set %s down" % (self.cmd_ip, self.bridgeif), | 290 self.router.run("%s link set %s down" % (self.cmd_ip, self.bridgeif), |
| 277 ignore_status=True) | 291 ignore_status=True) |
| 278 self.router.run("%s delbr %s" % (self.cmd_brctl, self.bridgeif), | 292 self.router.run("%s delbr %s" % (self.cmd_brctl, self.bridgeif), |
| 279 ignore_status=True) | 293 ignore_status=True) |
| 280 | 294 |
| 281 self.hostapd['configured'] = False | 295 self.hostapd['configured'] = False |
| OLD | NEW |