1# Copyright (c) 2013 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
5
6import ap_spec
7import belkinF9K_ap_configurator
8
9
10class BelkinF7DAPConfigurator(
11        belkinF9K_ap_configurator.BelkinF9KAPConfigurator):
12    """Class to configure Belkin F7D1301 v1 (01A) router."""
13
14    def __init__(self, ap_config):
15        super(BelkinF7DAPConfigurator, self).__init__(ap_config)
16        self._dhcp_delay = 0
17
18
19    def set_mode(self, mode):
20        self.add_item_to_command_list(self._set_mode, (mode,), 1, 900)
21
22
23    def _set_mode(self, mode):
24        mode_mapping = {ap_spec.MODE_G: '802.11g',
25                        ap_spec.MODE_N: '1x1 802.11n',
26                        ap_spec.MODE_B | ap_spec.MODE_G | ap_spec.MODE_N:
27                        '802.11b & 802.11g & 1x1 802.11n'}
28        mode_name = mode_mapping.get(mode)
29        if not mode_name:
30            raise RuntimeError('The mode %d not supported by router %s. ',
31                               hex(mode), self.name)
32        xpath = '//select[@name="wbr"]'
33        self.select_item_from_popup_by_xpath(mode_name, xpath,
34                                             wait_for_xpath=None,
35                                             alert_handler=self._security_alert)
36
37
38    def _set_security_wpapsk(self, security, shared_key, update_interval=None):
39        key_field = '//input[@name="wpa_key_pass"]'
40        psk = '//select[@name="authentication"]'
41        self.select_item_from_popup_by_xpath('WPA/WPA2-Personal (PSK)',
42                                             self.security_popup,
43                                             wait_for_xpath=key_field,
44                                             alert_handler=self._security_alert)
45        auth_type = 'WPA2-PSK'
46        if security == ap_spec.SECURITY_TYPE_WPAPSK:
47            auth_type = 'WPA-PSK'
48        self.select_item_from_popup_by_xpath(auth_type, psk,
49                                             alert_handler=self._security_alert)
50        self.set_content_of_text_field_by_xpath(shared_key, key_field,
51                                                abort_check=False)
52