• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CHRE_CORE_WIFI_SCAN_REQUEST_H_
18 #define CHRE_CORE_WIFI_SCAN_REQUEST_H_
19 
20 #include <cstddef>
21 
22 #include "chre/util/dynamic_vector.h"
23 #include "chre/util/fixed_size_vector.h"
24 #include "chre/util/time.h"
25 #include "chre_api/chre/wifi.h"
26 
27 namespace chre {
28 
29 /**
30  * The maximum length for a Wifi SSID. This value is taken from 802.11 7.3.2.1
31  * and can also be found in the CHRE API wifi.h.
32  */
33 constexpr size_t kMaxWifiSsidLength = 32;
34 
35 /**
36  * This WifiScanType is designed to wrap constants provided by the CHRE API to
37  * improve type-safety. In addition, an invalid wifi scan type is added for
38  * handling an app that is not requesting wifi scans.
39  */
40 enum class WifiScanType { Invalid, Active, ActivePlusPassiveDfs, Passive };
41 
42 /**
43  * Translates a CHRE API enum wifi scan type to a WifiScanType. This funciton
44  * also performs input validation and will default to WifiScanType::Invalid if
45  * the provided value is not a valid enumeration.
46  *
47  * @param enumWifiScanType A potentially unsafe CHRE API enum wifi scan type.
48  * @return a WifiScanType given a CHRE API wifi scan type.
49  */
50 WifiScanType getWifiScanTypeForEnum(enum chreWifiScanType enumWifiScanType);
51 
52 /**
53  * An SSID can be modelled by a list of bytes.
54  */
55 typedef FixedSizeVector<uint8_t, kMaxWifiSsidLength> WifiSsid;
56 
57 /**
58  * Models a request for wifi scans. This class implements the API set forth by
59  * the RequestMultiplexer container in addition to specific functionality
60  * required for requesting wifi scans.
61  */
62 class WifiScanRequest {
63  public:
64   /**
65    * Default constructs a wifi scan request to the minimal possible
66    * configuration. The WifiScanType is set to Invalid and the frequency and
67    * SSID lists are both cleared.
68    */
69   WifiScanRequest();
70 
71   /**
72    * Constructs a request for wifi scan results given a scan type, maximum scan
73    * age, frequencies and SSID list as specified by the CHRE API. More details
74    * about the parameters here can be found in the CHRE API.
75    *
76    * @param wifiScanType The type of scan being requested.
77    * @param maxScanAge The maximum age of a detected wifi network to be
78    *        reported.
79    * @param frequencies The list of frequencies to search for networks on.
80    * @param ssids The list of SSIDs to specifically search for.
81    */
82   WifiScanRequest(WifiScanType wifiScanType, const Nanoseconds &maxScanAge,
83                   DynamicVector<uint32_t> &&frequencies,
84                   DynamicVector<WifiSsid> &&ssids);
85 
86   /**
87    * @return the type of this scan request.
88    */
89   WifiScanType getScanType() const;
90 
91   /**
92    * @return the maximum age of a scan result for this request.
93    */
94   const Nanoseconds &getMaxScanAge() const;
95 
96   /**
97    * @return the frequencies associated with this request.
98    */
99   const DynamicVector<uint32_t> &getFrequencies() const;
100 
101   /**
102    * @return the SSIDs associated with this request.
103    */
104   const DynamicVector<WifiSsid> &getSsids() const;
105 
106  private:
107   //! The type of request for this scan.
108   WifiScanType mScanType;
109 
110   //! The maximum allowable age for a scan result.
111   Nanoseconds mMaxScanAge;
112 
113   //! The list of frequencies associated with this scan request.
114   DynamicVector<uint32_t> mFrequencies;
115 
116   //! The list of SSIDs associated with this scan request.
117   DynamicVector<WifiSsid> mSsids;
118 };
119 
120 }  // namespace chre
121 
122 #endif  // CHRE_CORE_WIFI_SCAN_REQUEST_H_
123