1#!/usr/bin/python3.4
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.
16
17from acts import asserts
18from acts.test_decorators import test_tracker_info
19from acts.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_5G
20from acts.test_utils.wifi import wifi_test_utils as wutils
21from acts.test_utils.wifi.rtt import rtt_const as rconsts
22from acts.test_utils.wifi.rtt import rtt_test_utils as rutils
23from acts.test_utils.wifi.rtt.RttBaseTest import RttBaseTest
24
25
26class RangeSoftApTest(RttBaseTest):
27  """Test class for RTT ranging to an Android Soft AP."""
28
29  # Soft AP SSID
30  SOFT_AP_SSID = "RTT_TEST_SSID"
31
32  # Soft AP Password (irrelevant)
33  SOFT_AP_PASSWORD = "ABCDEFGH"
34
35  # Number of RTT iterations
36  NUM_ITER = 10
37
38  def __init__(self, controllers):
39    RttBaseTest.__init__(self, controllers)
40
41  #########################################################################
42
43  @test_tracker_info(uuid="578f0725-31e3-4e60-ad62-0212d93cf5b8")
44  def test_rtt_to_soft_ap(self):
45    """Set up a Soft AP on one device and try performing an RTT ranging to it
46    from another device. The attempt must fail - RTT on Soft AP must be
47    disabled."""
48    sap = self.android_devices[0]
49    sap.pretty_name = "SoftAP"
50    client = self.android_devices[1]
51    client.pretty_name = "Client"
52
53    # start Soft AP
54    wutils.start_wifi_tethering(sap, self.SOFT_AP_SSID, self.SOFT_AP_PASSWORD,
55                                band=WIFI_CONFIG_APBAND_5G, hidden=False)
56
57    try:
58      # start scanning on the client
59      wutils.start_wifi_connection_scan_and_ensure_network_found(client,
60                                                             self.SOFT_AP_SSID)
61      scans = client.droid.wifiGetScanResults()
62      scanned_softap = None
63      for scanned_ap in scans:
64        if scanned_ap[wutils.WifiEnums.SSID_KEY] == self.SOFT_AP_SSID:
65          scanned_softap = scanned_ap
66          break
67
68      asserts.assert_false(scanned_softap == None, "Soft AP not found in scan!",
69                           extras=scans)
70
71      # validate that Soft AP does not advertise 802.11mc support
72      asserts.assert_false(
73        rconsts.SCAN_RESULT_KEY_RTT_RESPONDER in scanned_softap and
74        scanned_softap[rconsts.SCAN_RESULT_KEY_RTT_RESPONDER],
75        "Soft AP advertises itself as supporting 802.11mc!",
76        extras=scanned_softap)
77
78      # falsify the SoftAP's support for IEEE 802.11 so we try a 2-sided RTT
79      scanned_softap[rconsts.SCAN_RESULT_KEY_RTT_RESPONDER] = True # falsify
80
81      # actually try ranging to the Soft AP
82      events = rutils.run_ranging(client, [scanned_softap], self.NUM_ITER, 0)
83      stats = rutils.analyze_results(events, self.rtt_reference_distance_mm,
84                                     self.rtt_reference_distance_margin_mm,
85                                     self.rtt_min_expected_rssi_dbm,
86                                     self.lci_reference, self.lcr_reference)
87
88      asserts.assert_equal(
89          stats[scanned_ap[wutils.WifiEnums.BSSID_KEY]]['num_failures'],
90          self.NUM_ITER, "Some RTT operations to Soft AP succeed!?",
91          extras=stats)
92
93      asserts.explicit_pass("SoftAP + RTT validation done", extras=events)
94    finally:
95      wutils.stop_wifi_tethering(sap)
96