1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef OHOS_SCAN_COMMON_H 16 #define OHOS_SCAN_COMMON_H 17 18 #include <functional> 19 #include <string> 20 #include <vector> 21 #include "wifi_scan_msg.h" 22 #include "wifi_internal_msg.h" 23 24 namespace OHOS { 25 namespace Wifi { 26 #define FRIEND_GTEST(test_typename) friend class test_typename##Test 27 static const int MIN_SYSTEM_SCAN_INTERVAL = 20; 28 static const int MAX_SYSTEM_SCAN_INTERVAL = 160; 29 static const int MAX_SCAN_CONFIG_STORE_INDEX = 10000; 30 static const int SECOND_TO_MILLI_SECOND = 1000; 31 32 /* Scan Parameter Configuration */ 33 struct ScanConfig { 34 std::vector<std::string> hiddenNetworkSsid; /* Hidden network can be detected */ 35 /* only after users manually add them */ 36 ScanBandType scanBand; /* A frequency segment */ 37 std::vector<int> scanFreqs; /* 38 * Only APs with specified frequencies are 39 * scanned. If this parameter is not set,all 40 * frequencies's ap are scanned 41 */ 42 int backScanPeriod; /* Scan interval for background scan */ 43 bool fullScanFlag; /* Flag indicating whether the request is full scan */ 44 ScanType scanType; /* Flag indicating whether the request is an external scan */ 45 bool scanningWithParamFlag; /* Flag Indicating whether scanning with parameter */ 46 std::string ssid; /* The network name */ 47 std::string bssid; /* The address of the access point */ 48 int scanStyle; /* Type of scan to perform */ 49 ScanConfigScanConfig50 ScanConfig() 51 { 52 scanBand = SCAN_BAND_UNSPECIFIED; 53 backScanPeriod = 0; 54 fullScanFlag = false; 55 scanType = ScanType::SCAN_TYPE_SYSTEMTIMER; 56 scanningWithParamFlag = false; 57 scanStyle = 0xFF; 58 } 59 }; 60 61 /* Parameters used by the scan service */ 62 struct InterScanConfig { 63 std::vector<std::string> hiddenNetworkSsid; /* Hidden network can be detected */ 64 /* only after users manually add them */ 65 std::vector<int> scanFreqs; /* 66 * Only AP with specified frequencies are scanned. 67 * If this parameter is not set,all frequencies's 68 * ap are scanned 69 */ 70 bool fullScanFlag; /* Flag of scan without specifying parameters */ 71 int backScanPeriod; /* Scan interval for background scan */ 72 int bssidsNumPerScan; /* Maximum number of records contained in each scan */ 73 int maxScansCache; /* Maximum number of cached scans */ 74 int maxBackScanPeriod; /* Maximum background scan interval */ 75 int scanStyle; /* Type of scan to perform */ 76 InterScanConfigInterScanConfig77 InterScanConfig() 78 { 79 fullScanFlag = false; 80 backScanPeriod = 0; 81 bssidsNumPerScan = 0; 82 maxScansCache = 0; 83 maxBackScanPeriod = 0; 84 scanStyle = 0xFF; 85 } 86 }; 87 88 /* Saved parameters, which are filtered after the scanning result is received */ 89 struct StoreScanConfig { 90 std::string ssid; /* Specifies the SSID in parameter scanning. */ 91 std::string bssid; /* Specifies the BSSID carried in parameter scanning. */ 92 std::vector<int> scanFreqs; /* Only APs with specified frequencies are scanned. */ 93 int64_t scanTime; /* Scan Start Time */ 94 bool fullScanFlag; /* Flag of scan without specifying parameters */ 95 ScanType scanType; /* Flag indicating whether the request is an external scan. */ 96 bool scanningWithParamFlag; /* Flag Indicating whether scanning with parameter */ StoreScanConfigStoreScanConfig97 StoreScanConfig() 98 { 99 scanTime = 0; 100 fullScanFlag = false; 101 scanType = ScanType::SCAN_TYPE_SYSTEMTIMER; 102 scanningWithParamFlag = false; 103 } 104 }; 105 106 /* PNO Scanning Parameter Configuration */ 107 struct PnoScanConfig { 108 int scanInterval; /* PNO scanning interval */ 109 int minRssi2Dot4Ghz; /* Minimum 2.4 GHz network signal strength */ 110 int minRssi5Ghz; /* Minimum 5 GHz network signal strength */ 111 std::vector<std::string> hiddenNetworkSsid; /* Hidden network name */ 112 std::vector<std::string> savedNetworkSsid; /* Saved network name */ 113 std::vector<int> freqs; /* Scan at a specified frequency */ 114 PnoScanConfigPnoScanConfig115 PnoScanConfig() 116 { 117 scanInterval = 0; 118 minRssi2Dot4Ghz = 0; 119 minRssi5Ghz = 0; 120 } 121 }; 122 123 /* Scan command */ 124 enum ScanCommond { 125 CMD_SCAN_PREPARE = 0, /* Preparations and driver loading */ 126 CMD_START_COMMON_SCAN = 1, /* Start a common scan */ 127 CMD_STOP_COMMON_SCAN = 2, /* Stopping a common scan */ 128 CMD_START_PNO_SCAN = 3, /* Start PNO scanning */ 129 CMD_STOP_PNO_SCAN = 4, /* Stop PNO Scanning */ 130 CMD_RESTART_PNO_SCAN = 5, /* Restart PNO Scanning */ 131 CMD_SCAN_FINISH = 6, /* Stop PNO scanning and uninstall the driver */ 132 CMD_DISABLE_SCAN = 7, 133 }; 134 135 /* Monitored scanning events */ 136 enum ScanEventType { 137 HARDWARE_LOAD_EVENT = 20, /* The hardware is successfully loaded */ 138 SCAN_RESULT_EVENT = 21, /* The common scan is successful. The scan result can be obtained */ 139 PNO_SCAN_RESULT_EVENT = 22, /* The PNO scanning result can be obtained */ 140 SCAN_FAILED_EVENT = 23, /* Common scan failure */ 141 HARDWARE_UNLOAD_EVENT = 24, /* Hardware uninstalled successfully */ 142 SCAN_UPDATE_COUNTRY_CODE = 25, 143 }; 144 145 /* Internal event */ 146 enum ScanInnerEventType { 147 WAIT_SCAN_RESULT_TIMER = 100, /* Scan result waiting timer */ 148 WAIT_PNO_SCAN_RESULT_TIMER = 101, /* PNO scan result waiting timer */ 149 SOFTWARE_PNO_SCAN_TIMER = 102, /* PNO software scanning timer */ 150 151 /* ---------------------------Used for ScanServices ------------------- */ 152 SYSTEM_SCAN_TIMER = 200, /* Automatic scanning */ 153 DISCONNECTED_SCAN_TIMER = 201, /* Automatic scanning in disconnected state */ 154 RESTART_PNO_SCAN_TIMER = 202, /* Restart after PNO scanning fails */ 155 RESTART_SYSTEM_SCAN_TIMER = 203, 156 SCAN_INNER_EVENT_INVALID /* Invalid value */ 157 }; 158 159 /* State machine status reporting */ 160 enum ScanStatus { 161 SCAN_STARTED_STATUS = 0, /* Started successfully */ 162 SCAN_FINISHED_STATUS = 1, /* End processing completed */ 163 COMMON_SCAN_SUCCESS = 2, /* Notify the scan result after the common scan is complete */ 164 COMMON_SCAN_FAILED = 3, /* Common scan failure */ 165 PNO_SCAN_INFO = 4, /* The PNO scan is complete and the scanning result is notified */ 166 PNO_SCAN_FAILED = 5, /* Failed to start the PNO scanning */ 167 SCAN_INNER_EVENT = 6, /* Report internal events */ 168 SCAN_STATUS_INVALID /* Invalid value */ 169 }; 170 171 struct ScanStatusReport { 172 ScanStatus status; /* status code */ 173 std::vector<int> requestIndexList; /* 174 * Request index list, 175 * which is used for common scanning of reported events. 176 */ 177 std::vector<InterScanInfo> scanInfoList; /* 178 * Scan result, 179 * which is used for reporting 180 * common and PNO scan results. 181 */ 182 ScanInnerEventType innerEvent; /* Internal event, which is used by timer events. */ 183 ScanStatusReportScanStatusReport184 ScanStatusReport() 185 { 186 status = SCAN_STATUS_INVALID; 187 innerEvent = SCAN_INNER_EVENT_INVALID; 188 } 189 }; 190 191 using ScanStatusReportHandler = std::function<void(ScanStatusReport &scanStatusReport)>; 192 using ScanInfoHandler = std::function<void(std::vector<InterScanInfo> &scanInfoList)>; 193 using PnoScanInfoHandler = std::function<void(std::vector<InterScanInfo> &pnoScanInfoList)>; 194 } // namespace Wifi 195 } // namespace OHOS 196 #endif