bmahadev | 8e94981 | 2013-09-18 13:59:41 -0700 | [diff] [blame] | 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 | import os |
bmahadev | 8e94981 | 2013-09-18 13:59:41 -0700 | [diff] [blame] | 6 | import ap_spec |
| 7 | import trendnet692gr_ap_configurator |
bmahadev | b34ca6f | 2014-06-27 17:52:27 -0700 | [diff] [blame] | 8 | import time |
bmahadev | 8e94981 | 2013-09-18 13:59:41 -0700 | [diff] [blame] | 9 | |
| 10 | |
| 11 | class Trendnet812druAPConfigurator(trendnet692gr_ap_configurator. |
| 12 | Trendnet692grAPConfigurator): |
| 13 | """Derived class to control the Trendnet TEW-812DRU.""" |
| 14 | |
| 15 | |
| 16 | def _alert_handler(self, alert): |
| 17 | """ |
| 18 | Checks for any modal dialogs which popup to alert the user and |
| 19 | either raises a RuntimeError or ignores the alert. |
| 20 | |
| 21 | @param alert: The modal dialog's contents. |
| 22 | """ |
| 23 | text = alert.text |
| 24 | if 'WPS in Open security' in text: |
| 25 | alert.accept() |
| 26 | else: |
| 27 | raise RuntimeError('An unexpected alert was thrown: %s' % text) |
| 28 | |
| 29 | |
| 30 | def get_supported_modes(self): |
| 31 | return [{'band': ap_spec.BAND_2GHZ, 'modes': [ap_spec.MODE_N]}, |
| 32 | {'band': ap_spec.BAND_5GHZ, 'modes': [ap_spec.MODE_N]}] |
| 33 | |
| 34 | |
| 35 | def is_security_mode_supported(self, security_mode): |
Kris Rambish | 506a99d | 2013-10-08 19:19:13 -0700 | [diff] [blame] | 36 | """ |
| 37 | Returns if a given security_type is supported. |
| 38 | |
| 39 | @param security_mode: one security modes defined in the APSpec |
| 40 | |
| 41 | @return True if the security mode is supported; False otherwise. |
| 42 | |
| 43 | """ |
bmahadev | 8e94981 | 2013-09-18 13:59:41 -0700 | [diff] [blame] | 44 | return security_mode in (ap_spec.SECURITY_TYPE_DISABLED, |
bmahadev | ada34e3 | 2013-11-06 15:28:45 -0800 | [diff] [blame] | 45 | ap_spec.SECURITY_TYPE_WEP, |
bmahadev | 8e94981 | 2013-09-18 13:59:41 -0700 | [diff] [blame] | 46 | ap_spec.SECURITY_TYPE_WPAPSK, |
| 47 | ap_spec.SECURITY_TYPE_WPA2PSK) |
| 48 | |
| 49 | |
| 50 | def navigate_to_page(self, page_number): |
| 51 | """Navigates to the given page. |
| 52 | |
| 53 | @param page_number: the page to navigate to. |
| 54 | """ |
| 55 | # All settings are on the same page, so we always open the config page |
| 56 | if self.current_band == ap_spec.BAND_2GHZ: |
| 57 | if page_number == 1: |
| 58 | page_url = os.path.join(self.admin_interface_url , |
| 59 | 'wireless/basic.asp?wl_unit=0') |
| 60 | elif page_number == 2: |
| 61 | page_url = os.path.join(self.admin_interface_url , |
| 62 | 'wireless/security.asp?wl_unit=0') |
| 63 | else: |
| 64 | raise RuntimeError('Invalid page number passed. Number of pages' |
| 65 | '%d, page value sent was %d' % |
| 66 | (self.get_number_of_pages(), page_number)) |
| 67 | elif self.current_band == ap_spec.BAND_5GHZ: |
| 68 | if page_number == 1: |
| 69 | page_url = os.path.join(self.admin_interface_url , |
| 70 | 'wireless/basic.asp?wl_unit=1') |
| 71 | elif page_number == 2: |
| 72 | page_url = os.path.join(self.admin_interface_url , |
| 73 | 'wireless/security.asp?wl_unit=1') |
| 74 | else: |
| 75 | raise RuntimeError('Invalid page number passed. Number of pages' |
| 76 | '%d, page value sent was %d' % |
| 77 | (self.get_number_of_pages(), page_number)) |
| 78 | else: |
| 79 | raise RuntimeError('Incorrect band band = %s' % self.current_band) |
| 80 | self.get_url(page_url, page_title='TEW-812DRU') |
| 81 | |
| 82 | |
| 83 | def _set_ssid(self, ssid): |
| 84 | xpath = '//input[@maxlength="32" and @name="wl_ssid"]' |
| 85 | self.set_content_of_text_field_by_xpath(ssid, xpath, abort_check=True) |
Kris Rambish | 506a99d | 2013-10-08 19:19:13 -0700 | [diff] [blame] | 86 | self._ssid = ssid |
bmahadev | 8e94981 | 2013-09-18 13:59:41 -0700 | [diff] [blame] | 87 | |
| 88 | |
| 89 | def _set_mode(self, mode, band=None): |
| 90 | # Different bands are not supported so we ignore. |
| 91 | # Create the mode to popup item mapping |
bmahadev | b34ca6f | 2014-06-27 17:52:27 -0700 | [diff] [blame] | 92 | mode_mapping = {ap_spec.MODE_N: 'Auto'} |
bmahadev | 8e94981 | 2013-09-18 13:59:41 -0700 | [diff] [blame] | 93 | mode_name = '' |
| 94 | if mode in mode_mapping.keys(): |
| 95 | mode_name = mode_mapping[mode] |
| 96 | else: |
| 97 | raise RuntimeError('The mode selected %s is not supported by router' |
| 98 | ' %s.', ap_spec.mode_string_for_mode(mode), |
Jason Abele | b02e174 | 2013-11-20 13:14:43 -0800 | [diff] [blame] | 99 | self.name) |
bmahadev | b34ca6f | 2014-06-27 17:52:27 -0700 | [diff] [blame] | 100 | xpath = '//select[@name="wl_nmode"]' |
| 101 | while self.number_of_items_in_popup_by_xpath(xpath) < 2: |
| 102 | time.sleep(0.25) |
| 103 | self.select_item_from_popup_by_xpath(mode_name, xpath) |
bmahadev | 8e94981 | 2013-09-18 13:59:41 -0700 | [diff] [blame] | 104 | |
| 105 | |
| 106 | def set_radio(self, enabled=True): |
| 107 | self.add_item_to_command_list(self._set_radio, (enabled, ), 1, 200) |
| 108 | |
| 109 | |
| 110 | def _set_radio(self, enabled=True): |
| 111 | xpath = '//select[@name="wl_bss_enabled"]' |
| 112 | if enabled: |
| 113 | self.select_item_from_popup_by_xpath('On', xpath) |
| 114 | else: |
| 115 | self.select_item_from_popup_by_xpath('Off', xpath) |
| 116 | |
| 117 | |
| 118 | def _set_visibility(self, visible=True): |
| 119 | xpath = '//select[@name="wl_closed"]' |
| 120 | if visible: |
| 121 | self.select_item_from_popup_by_xpath('Enabled', xpath) |
| 122 | else: |
| 123 | self.select_item_from_popup_by_xpath('Disabled', xpath) |
| 124 | |
| 125 | |
| 126 | def _set_channel(self, channel): |
| 127 | position = self._get_channel_popup_position(channel) |
| 128 | xpath = '//select[@name="wl_chanspec"]' |
| 129 | channel_choices_2GHZ = ['Auto', '1', '2', '3', '4', '5', '6', '7', '8', |
| 130 | '9', '10', '11'] |
| 131 | channel_choices_5GHZ = ['Auto', '36', '40', '44', '48', '149', '153', |
| 132 | '157', '161'] |
| 133 | if self.current_band == ap_spec.BAND_2GHZ: |
| 134 | self.select_item_from_popup_by_xpath(channel_choices_2GHZ[position], |
| 135 | xpath) |
| 136 | else: |
| 137 | self.select_item_from_popup_by_xpath(channel_choices_5GHZ[position], |
| 138 | xpath) |
| 139 | |
| 140 | |
bmahadev | ada34e3 | 2013-11-06 15:28:45 -0800 | [diff] [blame] | 141 | def _set_security_wpapsk(self, security, shared_key, update_interval=1800): |
bmahadev | 8e94981 | 2013-09-18 13:59:41 -0700 | [diff] [blame] | 142 | self.wait_for_object_by_id('security_mode') |
bmahadev | ada34e3 | 2013-11-06 15:28:45 -0800 | [diff] [blame] | 143 | if security == ap_spec.SECURITY_TYPE_WPAPSK: |
| 144 | wpa_item = 'WPA-PSK' |
| 145 | else: |
| 146 | wpa_item = 'WPA2-PSK' |
| 147 | self.select_item_from_popup_by_id(wpa_item, 'security_mode', |
bmahadev | 8e94981 | 2013-09-18 13:59:41 -0700 | [diff] [blame] | 148 | wait_for_xpath='id("wpaPassphrase")') |
| 149 | self.set_content_of_text_field_by_id(shared_key, 'wpaPassphrase') |
| 150 | self.set_content_of_text_field_by_id(update_interval, |
| 151 | 'rotationInterval') |