• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3#   Copyright 2018 - 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.
16from acts import logger
17from acts.controllers.fuchsia_lib.base_lib import BaseLib
18
19COMMAND_SCAN = "wlan.scan"
20COMMAND_SCAN_FOR_BSS_INFO = "wlan.scan_for_bss_info"
21COMMAND_CONNECT = "wlan.connect"
22COMMAND_DISCONNECT = "wlan.disconnect"
23COMMAND_STATUS = "wlan.status"
24COMMAND_GET_IFACE_ID_LIST = "wlan.get_iface_id_list"
25COMMAND_GET_PHY_ID_LIST = "wlan.get_phy_id_list"
26COMMAND_DESTROY_IFACE = "wlan.destroy_iface"
27COMMAND_GET_COUNTRY = "wlan_phy.get_country"
28COMMAND_QUERY_IFACE = "wlan.query_iface"
29
30
31class FuchsiaWlanLib(BaseLib):
32    def __init__(self, addr, tc, client_id):
33        self.address = addr
34        self.test_counter = tc
35        self.client_id = client_id
36        self.log = logger.create_tagged_trace_logger(str(addr))
37
38    def wlanStartScan(self):
39        """ Starts a wlan scan
40
41        Returns:
42            scan results
43        """
44        test_cmd = COMMAND_SCAN
45        test_id = self.build_id(self.test_counter)
46        self.test_counter += 1
47
48        return self.send_command(test_id, test_cmd, {})
49
50    def wlanScanForBSSInfo(self):
51        """ Scans and returns BSS info
52
53        Returns:
54            A dict mapping each seen SSID to a list of BSS Description IE
55            blocks, one for each BSS observed in the network
56        """
57        test_cmd = COMMAND_SCAN_FOR_BSS_INFO
58        test_id = self.build_id(self.test_counter)
59        self.test_counter += 1
60
61        return self.send_command(test_id, test_cmd, {})
62
63    def wlanConnectToNetwork(self,
64                             target_ssid,
65                             target_bss_desc,
66                             target_pwd=None):
67        """ Triggers a network connection
68        Args:
69            target_ssid: the network to attempt a connection to
70            target_pwd: (optional) password for the target network
71
72        Returns:
73            boolean indicating if the connection was successful
74        """
75        test_cmd = COMMAND_CONNECT
76        test_args = {
77            "target_ssid": target_ssid,
78            "target_pwd": target_pwd,
79            "target_bss_desc": target_bss_desc
80        }
81        test_id = self.build_id(self.test_counter)
82        self.test_counter += 1
83
84        return self.send_command(test_id, test_cmd, test_args)
85
86    def wlanDisconnect(self):
87        """ Disconnect any current wifi connections"""
88        test_cmd = COMMAND_DISCONNECT
89        test_id = self.build_id(self.test_counter)
90        self.test_counter += 1
91
92        return self.send_command(test_id, test_cmd, {})
93
94    def wlanDestroyIface(self, iface_id):
95        """ Destroy WLAN interface by ID.
96        Args:
97            iface_id: the interface id.
98
99        Returns:
100            Dictionary, service id if success, error if error.
101        """
102        test_cmd = COMMAND_DESTROY_IFACE
103        test_args = {"identifier": iface_id}
104        test_id = self.build_id(self.test_counter)
105        self.test_counter += 1
106
107        return self.send_command(test_id, test_cmd, test_args)
108
109    def wlanGetIfaceIdList(self):
110        """ Get a list if wlan interface IDs.
111
112        Returns:
113            Dictionary, service id if success, error if error.
114        """
115        test_cmd = COMMAND_GET_IFACE_ID_LIST
116        test_id = self.build_id(self.test_counter)
117        self.test_counter += 1
118
119        return self.send_command(test_id, test_cmd, {})
120
121    def wlanPhyIdList(self):
122        """ Get a list if wlan phy IDs.
123
124        Returns:
125            List of IDs if success, error if error.
126        """
127        test_cmd = COMMAND_GET_PHY_ID_LIST
128        test_id = self.build_id(self.test_counter)
129        self.test_counter += 1
130
131        return self.send_command(test_id, test_cmd, {})
132
133    def wlanStatus(self):
134        """ Request connection status
135
136        Returns:
137            Client state summary containing WlanClientState and
138            status of various networks connections
139        """
140        test_cmd = COMMAND_STATUS
141        test_id = self.build_id(self.test_counter)
142        self.test_counter += 1
143
144        return self.send_command(test_id, test_cmd, {})
145
146    def wlanGetCountry(self, phy_id):
147        """ Reads the currently configured country for `phy_id`.
148
149        Args:
150            phy_id: unsigned 16-bit integer.
151
152        Returns:
153            Dictionary, String if success, error if error.
154        """
155        test_cmd = COMMAND_GET_COUNTRY
156        test_args = {"phy_id": phy_id}
157        test_id = self.build_id(self.test_counter)
158        self.test_counter += 1
159
160        return self.send_command(test_id, test_cmd, test_args)
161
162    def wlanQueryInterface(self, iface_id):
163        """ Retrieves interface info for given wlan iface id.
164
165        Args:
166            iface_id: unsigned 16-bit int, the wlan interface id.
167
168        Returns:
169            Dictionary, containing interface id, role, phy_id, phy_assigned_id
170            and mac addr.
171        """
172        test_cmd = COMMAND_QUERY_IFACE
173        test_args = {'iface_id': iface_id}
174        test_id = self.build_id(self.test_counter)
175        self.test_counter += 1
176
177        return self.send_command(test_id, test_cmd, test_args)
178