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_api/chre/wifi.h" 23 #include "chre/util/dynamic_vector.h" 24 #include "chre/util/fixed_size_vector.h" 25 #include "chre/util/time.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 { 41 Invalid, 42 Active, 43 ActivePlusPassiveDfs, 44 Passive 45 }; 46 47 /** 48 * Translates a CHRE API enum wifi scan type to a WifiScanType. This funciton 49 * also performs input validation and will default to WifiScanType::Invalid if 50 * the provided value is not a valid enumeration. 51 * 52 * @param enumWifiScanType A potentially unsafe CHRE API enum wifi scan type. 53 * @return a WifiScanType given a CHRE API wifi scan type. 54 */ 55 WifiScanType getWifiScanTypeForEnum(enum chreWifiScanType enumWifiScanType); 56 57 /** 58 * An SSID can be modelled by a list of bytes. 59 */ 60 typedef FixedSizeVector<uint8_t, kMaxWifiSsidLength> WifiSsid; 61 62 /** 63 * Models a request for wifi scans. This class implements the API set forth by 64 * the RequestMultiplexer container in addition to specific functionality 65 * required for requesting wifi scans. 66 */ 67 class WifiScanRequest { 68 public: 69 /** 70 * Default constructs a wifi scan request to the minimal possible 71 * configuration. The WifiScanType is set to Invalid and the frequency and 72 * SSID lists are both cleared. 73 */ 74 WifiScanRequest(); 75 76 /** 77 * Constructs a request for wifi scan results given a scan type, maximum scan 78 * age, frequencies and SSID list as specified by the CHRE API. More details 79 * about the parameters here can be found in the CHRE API. 80 * 81 * @param wifiScanType The type of scan being requested. 82 * @param maxScanAge The maximum age of a detected wifi network to be 83 * reported. 84 * @param frequencies The list of frequencies to search for networks on. 85 * @param ssids The list of SSIDs to specifically search for. 86 */ 87 WifiScanRequest(WifiScanType wifiScanType, 88 const Nanoseconds& maxScanAge, 89 DynamicVector<uint32_t>&& frequencies, 90 DynamicVector<WifiSsid>&& ssids); 91 92 /** 93 * @return the type of this scan request. 94 */ 95 WifiScanType getScanType() const; 96 97 /** 98 * @return the maximum age of a scan result for this request. 99 */ 100 const Nanoseconds& getMaxScanAge() const; 101 102 /** 103 * @return the frequencies associated with this request. 104 */ 105 const DynamicVector<uint32_t>& getFrequencies() const; 106 107 /** 108 * @return the SSIDs associated with this request. 109 */ 110 const DynamicVector<WifiSsid>& getSsids() const; 111 112 private: 113 //! The type of request for this scan. 114 WifiScanType mScanType; 115 116 //! The maximum allowable age for a scan result. 117 Nanoseconds mMaxScanAge; 118 119 //! The list of frequencies associated with this scan request. 120 DynamicVector<uint32_t> mFrequencies; 121 122 //! The list of SSIDs associated with this scan request. 123 DynamicVector<WifiSsid> mSsids; 124 }; 125 126 } // namespace chre 127 128 #endif // CHRE_CORE_WIFI_SCAN_REQUEST_H_ 129