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 logging 6 7import ap_spec 8import netgear_WNDR_dual_band_configurator 9 10 11class NetgearR6200APConfigurator(netgear_WNDR_dual_band_configurator. 12 NetgearDualBandAPConfigurator): 13 """Derived class to control Netgear R6200 router.""" 14 15 16 def _alert_handler(self, alert): 17 """Checks for any modal dialogs which popup to alert the user and 18 either raises a RuntimeError or ignores the alert. 19 20 @param alert: The modal dialog's contents. 21 """ 22 text = alert.text 23 if 'WPS requires SSID broadcasting in order to work' in text: 24 alert.accept() 25 else: 26 super(NetgearR6200APConfigurator, self)._alert_handler(alert) 27 28 29 def navigate_to_page(self, page_number): 30 """Navigates to the default page. 31 32 @param page_number: The page to load. 33 """ 34 super(NetgearR6200APConfigurator, self).navigate_to_page(page_number) 35 self.set_wait_time(30) 36 self.wait.until(lambda _: 37 self.driver.execute_script('return document.readyState') 38 == 'complete') 39 self.restore_default_wait_time() 40 xpath = '//select[@name="opmode"]' 41 if not self.item_in_popup_by_xpath_exist('Up to 54 Mbps', xpath): 42 raise RuntimeError('Router webpage did not load completely.') 43 44 45 def get_supported_modes(self): 46 return [{'band': ap_spec.BAND_2GHZ, 47 'modes': [ap_spec.MODE_B, ap_spec.MODE_G, ap_spec.MODE_N]}, 48 {'band': ap_spec.BAND_5GHZ, 49 'modes': [ap_spec.MODE_G, ap_spec.MODE_A, ap_spec.MODE_N]}] 50 51 52 def get_supported_bands(self): 53 return [{'band': ap_spec.BAND_2GHZ, 54 'channels': ['Auto', 1, 2, 3, 4, 5, 6, 7, 8, 9 , 10, 11]}, 55 {'band': ap_spec.BAND_5GHZ, 56 'channels': [36, 40, 44, 48, 149, 153, 157, 161]}] 57 58 59 def is_security_mode_supported(self, security_mode): 60 """Returns if the passed in security mode is supported. 61 62 @param security_mode: a security mode that is defined in APSpec 63 """ 64 return security_mode in (ap_spec.SECURITY_TYPE_DISABLED, 65 ap_spec.SECURITY_TYPE_WPA2PSK, 66 ap_spec.SECURITY_TYPE_WEP) 67 68 69 def set_channel(self, channel): 70 self.add_item_to_command_list(self._set_channel, (channel,), 1, 900) 71 72 73 def _set_channel(self, channel): 74 position = self._get_channel_popup_position(channel) 75 channel_choices = ['Auto', '01', '02', '03', '04', '05', '06', '07', 76 '08', '09', '10', '11'] 77 xpath = '//select[@name="w_channel"]' 78 if self.current_band == ap_spec.BAND_5GHZ: 79 xpath = '//select[@name="w_channel_an"]' 80 channel_choices = ['36', '40', '44', '48', '149', '153', 81 '157', '161'] 82 self.select_item_from_popup_by_xpath(channel_choices[position], 83 xpath) 84 85 86 def _set_mode(self, mode, band=None): 87 router_mode = None 88 xpath = '//select[@name="opmode"]' 89 if self.current_band == ap_spec.BAND_2GHZ: 90 if mode == ap_spec.MODE_B: 91 router_mode = 'Up to 54 Mbps' 92 elif mode == ap_spec.MODE_G: 93 router_mode = 'Up to 145 Mbps' 94 elif mode == ap_spec.MODE_N: 95 router_mode = 'Up to 300 Mbps' 96 elif self.current_band == ap_spec.BAND_5GHZ: 97 xpath = '//select[@name="opmode_an"]' 98 if mode == ap_spec.MODE_G: 99 router_mode = 'Up to 173 Mbps' 100 elif mode == ap_spec.MODE_A: 101 router_mode = 'Up to 400 Mbps' 102 elif mode == ap_spec.MODE_N: 103 router_mode = 'Up to 867 Mbps' 104 if not router_mode: 105 raise RuntimeError('You selected a mode that is not assigned ' 106 'to this router. Select either b, g or n ' 107 'for 2.4Ghz or either g, a or n for 5Ghz.') 108 self.wait_for_object_by_xpath(xpath, wait_time=10) 109 self.select_item_from_popup_by_xpath(router_mode, xpath) 110 111 112 def set_security_wep(self, key_value, authentication): 113 if self.current_band == ap_spec.BAND_5GHZ: 114 logging.debug('Cannot set WEP security for 5GHz band in Netgear ' 115 'R6200 router.') 116 return None 117 super(NetgearR6200APConfigurator, self).set_security_wep( 118 key_value, authentication) 119