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 5 6import ap_spec 7import linksyse2500_ap_configurator 8 9 10class LinksysWRT610NAPConfigurator(linksyse2500_ap_configurator. 11 Linksyse2500APConfigurator): 12 """Base class for objects to configure Linksys wrt610 and E3000 AP's 13 using webdriver.""" 14 15 16 def is_security_mode_supported(self, security_mode): 17 """Returns if the passed in security mode is supported. 18 19 @param security_mode: one of the supported security methods defined 20 in APSpec. 21 22 @returns True is suppported; False otherwise. 23 """ 24 return security_mode in (ap_spec.SECURITY_TYPE_DISABLED, 25 ap_spec.SECURITY_TYPE_WPAPSK, 26 ap_spec.SECURITY_TYPE_WPA2PSK, 27 ap_spec.SECURITY_TYPE_WEP) 28 29 30 def _set_mode(self, mode, band=None): 31 mode_mapping = {ap_spec.MODE_B: 'Wireless-B Only', 32 ap_spec.MODE_G: 'Wireless-G Only', 33 ap_spec.MODE_B | ap_spec.MODE_G: 'Wireless-B/G Only', 34 ap_spec.MODE_N: 'Wireless-N Only', 35 ap_spec.MODE_A: 'Wireless-A Only', 36 ap_spec.MODE_M: 'Mixed'} 37 xpath = '//select[@name="wl0_net_mode"]' 38 if self.current_band == ap_spec.BAND_5GHZ: 39 xpath = '//select[@name="wl1_net_mode"]' 40 mode_name = '' 41 if mode in mode_mapping.keys(): 42 mode_name = mode_mapping[mode] 43 else: 44 raise RuntimeError('The mode selected %d is not supported by router' 45 ' %s.', hex(mode), self.name) 46 self.select_item_from_popup_by_xpath(mode_name, xpath, 47 alert_handler=self._alert_handler) 48 49 50 def _set_ssid(self, ssid): 51 xpath = '//input[@name="wl0_ssid"]' 52 if self.current_band == ap_spec.BAND_5GHZ: 53 xpath = '//input[@name="wl1_ssid"]' 54 self.set_content_of_text_field_by_xpath(ssid, xpath) 55 self._ssid = ssid 56 57 58 def _set_channel(self, channel): 59 position = self._get_channel_popup_position(channel) 60 channel_choices = ['Auto', 61 '1 - 2.412GHZ', '2 - 2.417GHZ', '3 - 2.422GHZ', 62 '4 - 2.427GHZ', '5 - 2.432GHZ', '6 - 2.437GHZ', 63 '7 - 2.442GHZ', '8 - 2.447GHZ', '9 - 2.452GHZ', 64 '10 - 2.457GHZ', '11 - 2.462GHZ'] 65 xpath = '//select[@name="_wl0_channel"]' 66 if self.current_band == ap_spec.BAND_5GHZ: 67 xpath = '//select[@name="_wl1_channel"]' 68 channel_choices = ['Auto (DFS)', 69 '36 - 5.180GHz', '40 - 5.200GHz', 70 '44 - 5.220GHz', '48 - 5.240GHz', 71 '149 - 5.745GHz', '153 - 5.765GHz', 72 '157 - 5.785GHz', '161 - 5.805GHz'] 73 self.select_item_from_popup_by_xpath(channel_choices[position], xpath, 74 alert_handler=self._alert_handler) 75 76 77 def _set_visibility(self, visible=True): 78 button = 'wl0_closed' 79 if self.current_band == ap_spec.BAND_5GHZ: 80 button = 'wl1_closed' 81 int_value = 0 if visible else 1 82 xpath = ('//input[@value="%d" and @name="%s"]' % (int_value, button)) 83 self.click_button_by_xpath(xpath, alert_handler=self._alert_handler) 84