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 logging, re | 5 import logging, re |
6 | 6 |
| 7 def isBSDRouter(router): |
| 8 router_uname = router.run('uname').stdout |
| 9 return re.search('BSD', router_uname) |
| 10 |
| 11 def find_ifnet(host, pattern): |
| 12 list = host.run("ifconfig -l").stdout |
| 13 for ifnet in list.split(): |
| 14 status = host.run("ifconfig %s" % ifnet).stdout |
| 15 m = re.search(pattern, status) |
| 16 if m: |
| 17 return ifnet |
| 18 return None |
| 19 |
7 class NotImplemented(Exception): | 20 class NotImplemented(Exception): |
8 def __init__(self, what): | 21 def __init__(self, what): |
9 self.what = what | 22 self.what = what |
10 def __str__(self): | 23 def __str__(self): |
11 return repr("Test method '%s' not implemented" % self.what) | 24 return repr("Test method '%s' not implemented" % self.what) |
12 | 25 |
13 | 26 |
14 class BSDRouter(object): | 27 class BSDRouter(object): |
15 """ | 28 """ |
16 BSD-style WiFi Router support for WiFiTest class. | 29 BSD-style WiFi Router support for WiFiTest class. |
17 | 30 |
18 This class implements test methods/steps that communicate with a | 31 This class implements test methods/steps that communicate with a |
19 router implemented with FreeBSD 8.0 and later. The router must | 32 router implemented with FreeBSD 8.0 and later. The router must |
20 be pre-configured to enable ssh access and have a net80211-based | 33 be pre-configured to enable ssh access and have a net80211-based |
21 wireless device. We also assume hostapd is present for handling | 34 wireless device. We also assume hostapd is present for handling |
22 authenticator duties and any necessary modules are pre-loaded | 35 authenticator duties and any necessary modules are pre-loaded |
23 (e.g. wlan_ccmp, wlan_tkip, wlan_wep, wlan_xauth). | 36 (e.g. wlan_ccmp, wlan_tkip, wlan_wep, wlan_xauth). |
24 """ | 37 """ |
25 | 38 |
26 | 39 |
27 def __init__(self, host, params, defssid): | 40 def __init__(self, host, params, defssid): |
28 self.router = host | 41 self.router = host |
29 # TODO(sleffler) default to 1st available wireless nic | 42 # default to 1st available wireless nic |
30 self.phydev = params['phydev'] | 43 if "phydev" not in params: |
31 # TODO(sleffler) default to 1st available wired nic | 44 self.phydev = find_ifnet(host, ".*media:.IEEE.802.11.*") |
32 self.wiredif = params['wiredev'] | 45 if self.phydev is None: |
| 46 raise Exception("No wireless NIC found") |
| 47 else: |
| 48 self.phydev = params['phydev'] |
| 49 # default to 1st available wired nic |
| 50 if "wiredev" not in params: |
| 51 self.wiredif = find_ifnet(host, ".*media:.Ethernet.*") |
| 52 if self.wiredif is None: |
| 53 raise Exception("No wired NIC found") |
| 54 else: |
| 55 self.wiredif = params['wiredev'] |
33 self.defssid = defssid; | 56 self.defssid = defssid; |
34 self.wlanif = None | 57 self.wlanif = None |
35 self.bridgeif = None | 58 self.bridgeif = None |
36 | 59 |
37 self.hostapd_keys = ("wpa", "wpa_passphrase", "wpa_key_mgmt", | 60 self.hostapd_keys = ("wpa", "wpa_passphrase", "wpa_key_mgmt", |
38 "wpa_pairwise", "wpa_group_rekey", "wpa_strict_rekey", | 61 "wpa_pairwise", "wpa_group_rekey", "wpa_strict_rekey", |
39 "wpa_gmk_rekey", "wpa_ptk_rekey", | 62 "wpa_gmk_rekey", "wpa_ptk_rekey", |
40 "rsn_pairwise", | 63 "rsn_pairwise", |
41 "rsn_preauth", "rsh_preauth_interfaces", | 64 "rsn_preauth", "rsh_preauth_interfaces", |
42 "peerkey") | 65 "peerkey") |
43 self.hostapd_conf = None | 66 self.hostapd_conf = None |
44 | 67 |
45 # clear any previous state; this is a hack | 68 # clear any previous state; this is a hack |
46 self.router.run("ifconfig wlan0 destroy >/dev/null 2>&1", | 69 self.router.run("ifconfig wlan0 destroy >/dev/null 2>&1", |
47 ignore_status=True) | 70 ignore_status=True) |
48 self.router.run("ifconfig bridge0 destroy >/dev/null 2>&1", | 71 self.router.run("ifconfig bridge0 destroy >/dev/null 2>&1", |
49 ignore_status=True) | 72 ignore_status=True) |
50 self.router.run("killall hostapd >/dev/null 2>&1", ignore_status=True) | 73 self.router.run("killall hostapd >/dev/null 2>&1", ignore_status=True) |
51 | 74 |
52 | |
53 def create(self, params): | 75 def create(self, params): |
54 """ Create a wifi device of the specified type """ | 76 """ Create a wifi device of the specified type """ |
55 | 77 |
56 phydev = params.get('phydev', self.phydev) | 78 phydev = params.get('phydev', self.phydev) |
57 result = self.router.run("ifconfig wlan create wlandev %s" \ | 79 result = self.router.run("ifconfig wlan create wlandev %s" \ |
58 " wlanmode %s" % (phydev, params['type'])) | 80 " wlanmode %s" % (phydev, params['type'])) |
59 self.wlanif = result.stdout[:-1] | 81 self.wlanif = result.stdout[:-1] |
60 | 82 |
61 # NB: can't create+addm together 'cuz of ifconfig bug | 83 # NB: can't create+addm together 'cuz of ifconfig bug |
62 result = self.router.run("ifconfig bridge create") | 84 result = self.router.run("ifconfig bridge create") |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 raise NotImplemented("check_client_event_countermeasures") | 209 raise NotImplemented("check_client_event_countermeasures") |
188 | 210 |
189 | 211 |
190 def router_force_mic_error(self, params): | 212 def router_force_mic_error(self, params): |
191 """ | 213 """ |
192 Force a Michael MIC error on the next packet. Note this requires | 214 Force a Michael MIC error on the next packet. Note this requires |
193 a driver that uses software crypto and a kernel with the support | 215 a driver that uses software crypto and a kernel with the support |
194 to fire oneshot MIC errors (first appeared in FreeBSD 8.1). | 216 to fire oneshot MIC errors (first appeared in FreeBSD 8.1). |
195 """ | 217 """ |
196 raise NotImplemented("force_mic_error") | 218 raise NotImplemented("force_mic_error") |
OLD | NEW |