• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2012 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 linksyse_single_band_configurator
7
8
9class Linksyse2100APConfigurator(linksyse_single_band_configurator.
10                                 LinksyseSingleBandAPConfigurator):
11    """Derived class to control Linksys E2100 router."""
12
13
14    def _set_mode(self, mode, band=None):
15        mode_mapping = {ap_spec.MODE_M:'Mixed',
16                        ap_spec.MODE_B | ap_spec.MODE_G:'BG-Mixed',
17                        ap_spec.MODE_G:'Wireless-G Only',
18                        ap_spec.MODE_B:'Wireless-B Only',
19                        ap_spec.MODE_N:'Wireless-N Only',
20                        'Disabled':'Disabled'}
21        mode_name = mode_mapping.get(mode)
22        if not mode_name:
23            raise RuntimeError('The mode %d not supported by router %s. ',
24                               hex(mode), self.name)
25        xpath = '//select[@name="wl_net_mode"]'
26        self.select_item_from_popup_by_xpath(mode_name, xpath,
27                                             alert_handler=self._sec_alert)
28
29
30    def _set_ssid(self, ssid):
31        xpath = '//input[@name="wl_ssid"]'
32        self.set_content_of_text_field_by_xpath(ssid, xpath, abort_check=False)
33        self._ssid = ssid
34
35
36    def _set_channel(self, channel):
37        position = self._get_channel_popup_position(channel)
38        xpath = '//select[@name="wl_schannel"]'
39        channels = ['Auto',
40                    '1 - 2.412GHZ', '2 - 2.417GHZ', '3 - 2.422GHZ',
41                    '4 - 2.427GHZ', '5 - 2.432GHZ', '6 - 2.437GHZ',
42                    '7 - 2.442GHZ', '8 - 2.447GHZ', '9 - 2.452GHZ',
43                    '10 - 2.457GHZ', '11 - 2.462GHZ']
44        self.select_item_from_popup_by_xpath(channels[position], xpath)
45
46
47    def _set_ch_width(self, channel_wid):
48        channel_width_choice = ['Auto', 'Standard - 20MHz Channel']
49        xpath = '//select[@name="_wl_nbw"]'
50        self.select_item_from_popup_by_xpath(channel_width_choice[channel_wid],
51                                             xpath)
52
53
54    def _set_security_disabled(self):
55        xpath = '//select[@name="security_mode2"]'
56        self.select_item_from_popup_by_xpath('Disabled', xpath)
57
58
59    def _set_security_wep(self, key_value, authentication):
60        # WEP and WPA-Personal are not supported for Wireless-N only mode
61        # and Mixed mode.
62        # WEP and WPA-Personal do not show up in the list, no alert is thrown.
63        popup = '//select[@name="security_mode2"]'
64        self.select_item_from_popup_by_xpath('WEP', popup,
65                                             alert_handler=self._sec_alert)
66        text = '//input[@name="wl_passphrase"]'
67        self.set_content_of_text_field_by_xpath(key_value, text,
68                                                abort_check=True)
69        xpath = '//input[@value="Generate"]'
70        self.click_button_by_xpath(xpath, alert_handler=self._sec_alert)
71
72
73    def _set_security_wpapsk(self, security, shared_key, update_interval=None):
74        popup = '//select[@name="security_mode2"]'
75        self.wait_for_object_by_xpath(popup)
76        if security == ap_spec.SECURITY_TYPE_WPAPSK:
77            wpa_item = 'WPA Personal'
78        else:
79            wpa_item = 'WPA2 Personal'
80        self.select_item_from_popup_by_xpath(wpa_item, popup,
81                                             alert_handler=self._sec_alert)
82        text = '//input[@name="wl_wpa_psk"]'
83        self.set_content_of_text_field_by_xpath(shared_key, text,
84                                                abort_check=True)
85
86
87    def is_update_interval_supported(self):
88        """
89        Returns True if setting the PSK refresh interval is supported.
90
91        @return True is supported; False otherwise
92        """
93        return False
94
95
96    def _set_visibility(self, visible=True):
97        int_value = 0 if visible else 1
98        xpath = ('//input[@value="%d" and @name="wl_closed"]' % int_value)
99        self.click_button_by_xpath(xpath, alert_handler=self._sec_alert)
100