1# Copyright (c) 2014 The Chromium 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
5import ap_spec
6import linksys_ap_configurator
7
8
9class LinksysWRT54GS2APConfigurator(
10        linksys_ap_configurator.LinksysAPConfigurator):
11    """Derived class to control Linksys WRT54GS2 router."""
12
13    def get_supported_modes(self):
14        return [{'band': ap_spec.BAND_2GHZ,
15                 'modes': [ap_spec.MODE_B, ap_spec.MODE_G, ap_spec.MODE_M]}]
16
17
18    def _set_mode(self, mode):
19        mode_mapping = {ap_spec.MODE_B: 'B-Only', ap_spec.MODE_G: 'G-Only',
20                        ap_spec.MODE_M: 'Mixed', 'Disabled' : 'Disabled'}
21        mode_name = None
22        if mode in self.get_supported_modes()[0]['modes']:
23            mode_name = mode_mapping.get(mode)
24        else:
25            mode_name = mode
26        if not mode_name:
27            raise RuntimeError('The mode selected %d is not supported by router'
28                               ' %s.', hex(mode), self.name)
29        xpath = ('//select[@name="wl_net_mode"]')
30        self.select_item_from_popup_by_xpath(mode_name, xpath)
31