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, time | 5 import logging, re, time |
6 from autotest_lib.client.common_lib import error | 6 from autotest_lib.client.common_lib import error |
7 from autotest_lib.server import site_eap_tls | |
8 | 7 |
9 def isLinuxRouter(router): | 8 def isLinuxRouter(router): |
10 router_uname = router.run('uname').stdout | 9 router_uname = router.run('uname').stdout |
11 return re.search('Linux', router_uname) | 10 return re.search('Linux', router_uname) |
12 | 11 |
13 class LinuxRouter(object): | 12 class LinuxRouter(object): |
14 """ | 13 """ |
15 Linux/mac80211-style WiFi Router support for WiFiTest class. | 14 Linux/mac80211-style WiFi Router support for WiFiTest class. |
16 | 15 |
17 This class implements test methods/steps that communicate with a | 16 This class implements test methods/steps that communicate with a |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 self.router.run("%s phy %s interface add %s type %s" % | 138 self.router.run("%s phy %s interface add %s type %s" % |
140 (self.cmd_iw, self.phydev5, self.wlanif5, phytype)) | 139 (self.cmd_iw, self.phydev5, self.wlanif5, phytype)) |
141 | 140 |
142 | 141 |
143 def destroy(self, params): | 142 def destroy(self, params): |
144 """ Destroy a previously created device """ | 143 """ Destroy a previously created device """ |
145 # For linux, this is the same as deconfig. | 144 # For linux, this is the same as deconfig. |
146 self.deconfig(params) | 145 self.deconfig(params) |
147 | 146 |
148 | 147 |
| 148 def insert_file(self, host, filename, contents): |
| 149 """ |
| 150 If config files are too big, the "host.run()" never returns. |
| 151 As a workaround, break the file up into lines and append the |
| 152 file piece by piece |
| 153 """ |
| 154 host.run('rm -f %s >/dev/null 2>&1' % filename, ignore_status=True) |
| 155 content_lines = contents.splitlines() |
| 156 while content_lines: |
| 157 buflist = [] |
| 158 buflen = 0 |
| 159 while content_lines and buflen + len(content_lines[0]) < 200: |
| 160 line = content_lines.pop(0) |
| 161 buflen += len(line) + 1 |
| 162 buflist.append(line) |
| 163 |
| 164 if not buflist: |
| 165 raise error.TestFail('Cert profile: line too long: %s' % |
| 166 content_lines[0]) |
| 167 host.run('cat <<EOF >>%s\n%s\nEOF\n' % |
| 168 (filename, '\n'.join(buflist))) |
149 | 169 |
150 def config(self, params): | 170 def config(self, params): |
151 """ Configure the AP per test requirements """ | 171 """ Configure the AP per test requirements """ |
152 | 172 |
153 multi_interface = 'multi_interface' in params | 173 multi_interface = 'multi_interface' in params |
154 if multi_interface: | 174 if multi_interface: |
155 params.pop('multi_interface') | 175 params.pop('multi_interface') |
156 elif self.hostapd['configured']: | 176 elif self.hostapd['configured']: |
157 self.deconfig({}) | 177 self.deconfig({}) |
158 | 178 |
159 if self.apmode: | 179 if self.apmode: |
160 # Construct the hostapd.conf file and start hostapd. | 180 # Construct the hostapd.conf file and start hostapd. |
161 conf = self.hostapd['conf'] | 181 conf = self.hostapd['conf'] |
162 htcaps = set() | 182 htcaps = set() |
163 | 183 |
164 conf['driver'] = params.get('hostapd_driver', | 184 conf['driver'] = params.get('hostapd_driver', |
165 self.hostapd['driver']) | 185 self.hostapd['driver']) |
166 | 186 |
167 for k, v in params.iteritems(): | 187 for k, v in params.iteritems(): |
168 if k == 'ssid': | 188 # For some parameters, the hostapd.conf value is a filename; |
| 189 # here, we create a file to contain the actual value and then |
| 190 # put the filename in hostapd.conf. |
| 191 if k.endswith('_file') or k in ['ca_cert', |
| 192 'server_cert', |
| 193 'private_key', |
| 194 'radius_server_clients', |
| 195 'wps_pin_requests', |
| 196 'ap_settings']: |
| 197 filename = "/tmp/hostap_%s" % k |
| 198 self.insert_file(self.router, filename, v) |
| 199 conf[k] = filename |
| 200 elif k == 'ssid': |
169 conf['ssid'] = v | 201 conf['ssid'] = v |
170 elif k == 'ssid_suffix': | 202 elif k == 'ssid_suffix': |
171 conf['ssid'] = self.defssid + v | 203 conf['ssid'] = self.defssid + v |
172 elif k == 'channel': | 204 elif k == 'channel': |
173 freq = int(v) | 205 freq = int(v) |
174 | 206 |
175 # 2.4GHz | 207 # 2.4GHz |
176 if freq <= 2484: | 208 if freq <= 2484: |
177 # Make sure hw_mode is set | 209 # Make sure hw_mode is set |
178 if conf.get('hw_mode') == 'a': | 210 if conf.get('hw_mode') == 'a': |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 elif k == 'ht': | 283 elif k == 'ht': |
252 htcaps.add('') # NB: ensure 802.11n setup below | 284 htcaps.add('') # NB: ensure 802.11n setup below |
253 elif k == 'htprotmode': | 285 elif k == 'htprotmode': |
254 pass # TODO(sleffler) need hostapd support | 286 pass # TODO(sleffler) need hostapd support |
255 elif k == 'rifs': | 287 elif k == 'rifs': |
256 pass # TODO(sleffler) need hostapd support | 288 pass # TODO(sleffler) need hostapd support |
257 elif k == 'wepmode': | 289 elif k == 'wepmode': |
258 pass # NB: meaningless for hostapd; ignore | 290 pass # NB: meaningless for hostapd; ignore |
259 elif k == '-ampdu': | 291 elif k == '-ampdu': |
260 pass # TODO(sleffler) need hostapd support | 292 pass # TODO(sleffler) need hostapd support |
261 elif k == 'eap-tls': | 293 elif k == 'eap': |
262 conf.update(site_eap_tls.router_config(self.router, v)) | 294 conf.update(site_eap.router_config(self.router, v)) |
263 else: | 295 else: |
264 conf[k] = v | 296 conf[k] = v |
265 | 297 |
266 # Aggregate ht_capab. | 298 # Aggregate ht_capab. |
267 if htcaps: | 299 if htcaps: |
268 conf['ieee80211n'] = 1 | 300 conf['ieee80211n'] = 1 |
269 conf['ht_capab'] = ''.join(htcaps) | 301 conf['ht_capab'] = ''.join(htcaps) |
270 | 302 |
271 # Figure out the correct interface. | 303 # Figure out the correct interface. |
272 if conf.get('hw_mode', 'b') == 'a': | 304 if conf.get('hw_mode', 'b') == 'a': |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 | 376 |
345 def get_ssid(self): | 377 def get_ssid(self): |
346 return self.hostapd['conf']['ssid'] | 378 return self.hostapd['conf']['ssid'] |
347 | 379 |
348 | 380 |
349 def set_txpower(self, params): | 381 def set_txpower(self, params): |
350 self.router.run("%s dev %s set txpower %s" % | 382 self.router.run("%s dev %s set txpower %s" % |
351 (self.cmd_iw, params.get('interface', | 383 (self.cmd_iw, params.get('interface', |
352 self.hostapd['interface']), | 384 self.hostapd['interface']), |
353 params.get('power', 'auto'))) | 385 params.get('power', 'auto'))) |
OLD | NEW |