1#!/usr/bin/env python3 2# 3# Copyright 2020 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17from acts.controllers.fuchsia_lib.base_lib import BaseLib 18 19 20class FuchsiaWlanApPolicyLib(BaseLib): 21 def __init__(self, addr, tc, client_id): 22 self.address = addr 23 self.test_counter = tc 24 self.client_id = client_id 25 26 def wlanStartAccessPoint(self, target_ssid, security_type, target_pwd, 27 connectivity_mode, operating_band): 28 """ Start an Access Point. 29 Args: 30 target_ssid: the network to attempt a connection to 31 security_type: the security protocol of the network. Possible inputs: 32 "none", "wep", "wpa", "wpa2", "wpa3" 33 target_pwd: (optional) credential being saved with the network. No password 34 is equivalent to empty string. 35 connectivity_mode: the connectivity mode to use. Possible inputs: 36 "local_only", "unrestricted" 37 operating_band: The operating band to use. Possible inputs: 38 "any", "only_2_4_ghz", "only_5_ghz" 39 40 Returns: 41 boolean indicating if the action was successful 42 """ 43 44 test_cmd = "wlan_ap_policy.start_access_point" 45 test_id = self.build_id(self.test_counter) 46 self.test_counter += 1 47 48 test_args = { 49 "target_ssid": target_ssid, 50 "security_type": security_type.lower(), 51 "target_pwd": target_pwd, 52 "connectivity_mode": connectivity_mode, 53 "operating_band": operating_band, 54 } 55 56 return self.send_command(test_id, test_cmd, test_args) 57 58 def wlanStopAccessPoint(self, target_ssid, security_type, target_pwd=""): 59 """ Stops an active Access Point. 60 Args: 61 target_ssid: the network to attempt a connection to 62 security_type: the security protocol of the network 63 target_pwd: (optional) credential being saved with the network. No password 64 is equivalent to empty string. 65 66 Returns: 67 boolean indicating if the action was successful 68 """ 69 70 test_cmd = "wlan_ap_policy.stop_access_point" 71 test_id = self.build_id(self.test_counter) 72 self.test_counter += 1 73 74 test_args = { 75 "target_ssid": target_ssid, 76 "security_type": security_type.lower(), 77 "target_pwd": target_pwd 78 } 79 80 return self.send_command(test_id, test_cmd, test_args) 81 82 def wlanStopAllAccessPoint(self): 83 """ Stops all Access Points 84 85 Returns: 86 boolean indicating if the actions were successful 87 """ 88 89 test_cmd = "wlan_ap_policy.stop_all_access_points" 90 test_id = self.build_id(self.test_counter) 91 self.test_counter += 1 92 93 test_args = {} 94 95 return self.send_command(test_id, test_cmd, test_args) 96 97 def wlanSetNewListener(self): 98 """ Sets the update listener stream of the facade to a new stream so that updates will be 99 reset. Intended to be used between tests so that the behaviour of updates in a test is 100 independent from previous tests. 101 """ 102 test_cmd = "wlan_ap_policy.set_new_update_listener" 103 test_id = self.build_id(self.test_counter) 104 self.test_counter += 1 105 106 return self.send_command(test_id, test_cmd, {}) 107 108 def wlanGetUpdate(self, timeout=30): 109 """ Gets a list of AP state updates. This call will return with an update immediately the 110 first time the update listener is initialized by setting a new listener or by creating 111 a client controller before setting a new listener. Subsequent calls will hang until 112 there is an update. 113 Returns: 114 A list of AP state updated. If there is no error, the result is a list with a 115 structure that matches the FIDL AccessPointState struct given for updates. 116 """ 117 test_cmd = "wlan_ap_policy.get_update" 118 test_id = self.build_id(self.test_counter) 119 self.test_counter += 1 120 121 return self.send_command(test_id, 122 test_cmd, {}, 123 response_timeout=timeout) 124