1570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish# Copyright (c) 2012 The Chromium Authors. All rights reserved. 2570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish# Use of this source code is governed by a BSD-style license that can be 3570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish# found in the LICENSE file. 4570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 5a67a9d879d47df5863de79df1bba3dfbf3fe5cdfBimal"""Class to control the AsusAP router.""" 6a67a9d879d47df5863de79df1bba3dfbf3fe5cdfBimal 7570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambishimport logging 87e87f4e698f250376692c87f460bb7f3273616f5Kris Rambishfrom selenium.common.exceptions import TimeoutException 9570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 1094c3721324b55d312dc3087068ac4da454ef6c25Jason Abeleimport dynamic_ap_configurator 11d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambishimport ap_spec 12570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 13570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 1494c3721324b55d312dc3087068ac4da454ef6c25Jason Abeleclass AsusAPConfigurator( 1594c3721324b55d312dc3087068ac4da454ef6c25Jason Abele dynamic_ap_configurator.DynamicAPConfigurator): 160d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal """Base class for Asus RT-N56U router.""" 17570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 1810b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 19570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def _set_authentication(self, authentication, wait_for_xpath=None): 20570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish """Sets the authentication method in the popup. 21570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 22570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish Args: 23570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish authentication: The authentication method to select. 24570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish wait_for_path: An item to wait for before returning. 25570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish """ 26570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish auth = '//select[@name="rt_auth_mode"]' 27d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish if self.current_band == ap_spec.BAND_5GHZ: 28570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish auth = '//select[@name="wl_auth_mode"]' 29570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish self.select_item_from_popup_by_xpath(authentication, auth, 30570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish wait_for_xpath, alert_handler=self._invalid_security_handler) 31570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 3210b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 33570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def _invalid_security_handler(self, alert): 34570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish text = alert.text 35570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish # This tweaks encryption but is more of a warning, so we can dismiss. 3610b36041348a787280247cc0c379f64428b2aa32Deepak Gopal if text.find('will change WEP or TKIP encryption to AES') != -1: 37570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish alert.accept() 3825f27816ccd001b87db184f354df8e38fc72a55cViral Modi else: 39570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish raise RuntimeError('You have entered an invalid configuration: ' 40570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish '%s' % text) 41570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 4210b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 43570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def get_number_of_pages(self): 44570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish return 2 45570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 4610b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 47570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def get_supported_bands(self): 48d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish return [{'band': ap_spec.BAND_2GHZ, 49570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 'channels': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]}, 50d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish {'band': ap_spec.BAND_5GHZ, 51570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 'channels': [36, 40, 44, 48, 149, 153, 157, 161]}] 52570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 5310b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 54570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def get_supported_modes(self): 55d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish return [{'band': ap_spec.BAND_2GHZ, 56d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish 'modes': [ap_spec.MODE_B, ap_spec.MODE_N, ap_spec.MODE_B | 57d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish ap_spec.MODE_G, ap_spec.MODE_B]}, 58d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish {'band': ap_spec.BAND_5GHZ, 59d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish 'modes': [ap_spec.MODE_N, ap_spec.MODE_A]}] 60570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 6110b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 62570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def is_security_mode_supported(self, security_mode): 63506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish """ 64506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish Returns if a given security_type is supported. 65506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish 66506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish @param security_mode: one security modes defined in the APSpec 67506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish 68506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish @return True if the security mode is supported; False otherwise. 69506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish 70506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish """ 71d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish return security_mode in (ap_spec.SECURITY_TYPE_DISABLED, 72d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish ap_spec.SECURITY_TYPE_WPAPSK, 73ada34e33a27786604af7007600d99fbf2e4fc7f6bmahadev ap_spec.SECURITY_TYPE_WPA2PSK, 74d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish ap_spec.SECURITY_TYPE_WEP) 75570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 7610b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 77570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def navigate_to_page(self, page_number): 78506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish """ 79506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish Navigates to the page corresponding to the given page number. 80506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish 81506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish This method performs the translation between a page number and a url to 82506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish load. This is used internally by apply_settings. 83506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish 84506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish @param page_number: page number of the page to load 85506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish 86506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish """ 87570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish # The page is determined by what band we are using. We ignore the input. 88570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish admin_url = self.admin_interface_url 89d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish if self.current_band == ap_spec.BAND_2GHZ: 900d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal self.get_url('%s/Advanced_Wireless2g_Content.asp' % admin_url, 910d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal page_title='2.4G') 92d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish elif self.current_band == ap_spec.BAND_5GHZ: 937dece17f74e1d37617d1716aee2a7bc28363e488Kris Rambish self.get_url('%s/Advanced_Wireless_Content.asp' % admin_url, 940d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal page_title='5G') 95570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish else: 96570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish raise RuntimeError('Invalid page number passed. Number of pages ' 97570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish '%d, page value sent was %d' % 98570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish (self.get_number_of_pages(), page_number)) 99570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 10010b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 101570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def save_page(self, page_number): 102506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish """ 103506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish Saves the given page. 104506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish 105506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish @param page_number: Page number of the page to save. 106506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish 107506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish """ 108570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish button = self.driver.find_element_by_id('applyButton') 109570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish button.click() 110570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish menu_id = 'menu_body' # id of the table with the main content 111570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish try: 112570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish self.wait_for_object_by_id(menu_id) 1137e87f4e698f250376692c87f460bb7f3273616f5Kris Rambish except TimeoutException, e: 11410b36041348a787280247cc0c379f64428b2aa32Deepak Gopal raise RuntimeError('Unable to find the object by id: %s\n ' 11510b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 'WebDriver exception: %s' % (menu_id, str(e))) 116570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish self.navigate_to_page(page_number) 117570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 11810b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 119570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def set_mode(self, mode, band=None): 1208238fdcf89535456a0be158a4f267611ae8b152aKris Rambish # To avoid the modal dialog 1218238fdcf89535456a0be158a4f267611ae8b152aKris Rambish self.add_item_to_command_list(self._set_security_disabled, (), 1, 799) 1228238fdcf89535456a0be158a4f267611ae8b152aKris Rambish self.add_item_to_command_list(self._set_mode, (mode, band), 1, 800) 123570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 12410b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 125570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def _set_mode(self, mode, band=None): 126570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish xpath = '//select[@name="rt_gmode"]' 127570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish # Create the mode to popup item mapping 128d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish mode_mapping = {ap_spec.MODE_B: 'b Only', ap_spec.MODE_G: 'g Only', 129d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish ap_spec.MODE_B | ap_spec.MODE_G: 'b/g Only', 130d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish ap_spec.MODE_N: 'n Only', ap_spec.MODE_A: 'a Only'} 131570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish mode_name = '' 132d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish if self.current_band == ap_spec.BAND_5GHZ or band == ap_spec.BAND_5GHZ: 133570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish xpath = '//select[@name="wl_gmode"]' 134570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish if mode in mode_mapping.keys(): 135570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish mode_name = mode_mapping[mode] 136d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish if ((mode & ap_spec.MODE_A) and 137d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish (self.current_band == ap_spec.BAND_2GHZ)): 138570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish # a mode only in 5Ghz 139a67a9d879d47df5863de79df1bba3dfbf3fe5cdfBimal logging.debug('Mode \'a\' is not available for 2.4Ghz band.') 140570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish return 141d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish elif ((mode & (ap_spec.MODE_B | ap_spec.MODE_G) == 142d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish (ap_spec.MODE_B | ap_spec.MODE_G)) or 143d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish (mode & ap_spec.MODE_B == ap_spec.MODE_B) or 144d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish (mode & ap_spec.MODE_G == ap_spec.MODE_G)) and \ 145d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish (self.current_band != ap_spec.BAND_2GHZ): 146570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish # b/g, b, g mode only in 2.4Ghz 147a67a9d879d47df5863de79df1bba3dfbf3fe5cdfBimal logging.debug('Mode \'%s\' is not available for 5Ghz band.', 1480d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal mode_name) 149570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish return 150570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish else: 151570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish raise RuntimeError('The mode selected \'%s\' is not supported by ' 152b02e1744df2907cc4c0e7167cd8a52c43a73b155Jason Abele 'router %s.' % mode_name, self.name) 153570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish self.select_item_from_popup_by_xpath(mode_name, xpath, 154570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish alert_handler=self._invalid_security_handler) 155570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 15610b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 157570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def set_radio(self, enabled): 158570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish # We cannot turn off radio on ASUS. 159570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish return None 160570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 16110b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 162570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def set_ssid(self, ssid): 163570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish self.add_item_to_command_list(self._set_ssid, (ssid,), 1, 900) 164570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 16510b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 166570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def _set_ssid(self, ssid): 167570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish xpath = '//input[@maxlength="32" and @name="rt_ssid"]' 168d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish if self.current_band == ap_spec.BAND_5GHZ: 169570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish xpath = '//input[@maxlength="32" and @name="wl_ssid"]' 170570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish self.set_content_of_text_field_by_xpath(ssid, xpath) 171506a99d582456eff2f6d5e534cbf00a62990e97dKris Rambish self._ssid = ssid 172570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 17310b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 174570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def set_channel(self, channel): 175570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish self.add_item_to_command_list(self._set_channel, (channel,), 1, 900) 176570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 17710b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 178570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def _set_channel(self, channel): 1799ec33ea72bac74c968ce2dac57d68882ac33ca34Kris Rambish position = self._get_channel_popup_position(channel) 18067f68cd77168e628273c93a40b4c72b40245532bDeepak Gopal channel_choices = range(1, 12) 181570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish xpath = '//select[@name="rt_channel"]' 182d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish if self.current_band == ap_spec.BAND_5GHZ: 183570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish xpath = '//select[@name="wl_channel"]' 184570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish channel_choices = ['36', '40', '44', '48', '149', '153', 185570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish '157', '161'] 1869ec33ea72bac74c968ce2dac57d68882ac33ca34Kris Rambish self.select_item_from_popup_by_xpath(str(channel_choices[position]), 187570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish xpath) 188570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 18910b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 190570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def set_band(self, band): 191d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish if band == ap_spec.BAND_2GHZ: 192d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish self.current_band = ap_spec.BAND_2GHZ 193d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish elif band == ap_spec.BAND_5GHZ: 194d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish self.current_band = ap_spec.BAND_5GHZ 195570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish else: 196570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish raise RuntimeError('Invalid band sent %s' % band) 197570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 198570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 199570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def set_security_disabled(self): 200570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish self.add_item_to_command_list(self._set_security_disabled, (), 1, 1000) 201570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 20210b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 203570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def _set_security_disabled(self): 204570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish popup = '//select[@name="rt_wep_x"]' 205d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish if self.current_band == ap_spec.BAND_5GHZ: 206570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish popup = '//select[@name="wl_wep_x"]' 2077dece17f74e1d37617d1716aee2a7bc28363e488Kris Rambish self._set_authentication('Open System', wait_for_xpath=popup) 2080d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal self.select_item_from_popup_by_xpath('None', popup) 209570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 21010b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 211570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def set_security_wep(self, key_value, authentication): 212570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish self.add_item_to_command_list(self._set_security_wep, 213570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish (key_value, authentication), 1, 1000) 214570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 21510b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 216570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def _set_security_wep(self, key_value, authentication): 217570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish popup = '//select[@name="rt_wep_x"]' 218570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish text_field = '//input[@name="rt_phrase_x"]' 219d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish if self.current_band == ap_spec.BAND_5GHZ: 220570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish popup = '//select[@name="wl_wep_x"]' 221570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish text_field = '//input[@name="wl_phrase_x"]' 2220d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal self._set_authentication('Open System', wait_for_xpath=popup) 2230d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal self.select_item_from_popup_by_xpath('WEP-64bits', popup, 2240d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal wait_for_xpath=text_field, 2250d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal alert_handler= 2260d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal self._invalid_security_handler) 2270d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal self.set_content_of_text_field_by_xpath(key_value, text_field, 2280d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal abort_check=True) 229570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 23010b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 231ada34e33a27786604af7007600d99fbf2e4fc7f6bmahadev def set_security_wpapsk(self, security, shared_key, update_interval=1800): 232570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish # Asus does not support TKIP (wpapsk) encryption in 'n' mode. 233570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish # So we will use AES (wpa2psk) to avoid conflicts and modal dialogs. 2340d1264acafb16ee523d17e7eabe2b049be04e20aDeepak Gopal self.add_item_to_command_list(self._set_security_wpapsk, 235ada34e33a27786604af7007600d99fbf2e4fc7f6bmahadev (security, shared_key, update_interval), 236ada34e33a27786604af7007600d99fbf2e4fc7f6bmahadev 1, 900) 237570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 23810b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 239ada34e33a27786604af7007600d99fbf2e4fc7f6bmahadev def _set_security_wpapsk(self, security, shared_key, update_interval): 240570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish key_field = '//input[@name="rt_wpa_psk"]' 241570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish interval_field = '//input[@name="rt_wpa_gtk_rekey"]' 242d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish if self.current_band == ap_spec.BAND_5GHZ: 243570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish key_field = '//input[@name="wl_wpa_psk"]' 244570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish interval_field = '//input[@name="wl_wpa_gtk_rekey"]' 245ada34e33a27786604af7007600d99fbf2e4fc7f6bmahadev if security == ap_spec.SECURITY_TYPE_WPAPSK: 246ada34e33a27786604af7007600d99fbf2e4fc7f6bmahadev self._set_authentication('WPA-Personal', 247ada34e33a27786604af7007600d99fbf2e4fc7f6bmahadev wait_for_xpath=key_field) 248ada34e33a27786604af7007600d99fbf2e4fc7f6bmahadev else: 249ada34e33a27786604af7007600d99fbf2e4fc7f6bmahadev self._set_authentication('WPA2-Personal', 250ada34e33a27786604af7007600d99fbf2e4fc7f6bmahadev wait_for_xpath=key_field) 251570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish self.set_content_of_text_field_by_xpath(shared_key, key_field) 252570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish self.set_content_of_text_field_by_xpath(str(update_interval), 253570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish interval_field) 254570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 25510b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 256570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def set_visibility(self, visible=True): 257570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish self.add_item_to_command_list(self._set_visibility,(visible,), 1, 900) 258570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish 25910b36041348a787280247cc0c379f64428b2aa32Deepak Gopal 260570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish def _set_visibility(self, visible=True): 261570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish # value=0 is visible; value=1 is invisible 262570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish value = 0 if visible else 1 263570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish xpath = '//input[@name="rt_closed" and @value="%s"]' % value 264d751a4f5e86c0e5f8a984d7fe21a4f74c7caa761Kris Rambish if self.current_band == ap_spec.BAND_5GHZ: 265570972d932ee7b75ae1e48a8bbb34134067ccc36Kris Rambish xpath = '//input[@name="wl_closed" and @value="%s"]' % value 2667dece17f74e1d37617d1716aee2a7bc28363e488Kris Rambish self.click_button_by_xpath(xpath, 2677dece17f74e1d37617d1716aee2a7bc28363e488Kris Rambish alert_handler=self._invalid_security_handler) 268