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 16 #ifndef OHOS_WIFI_SAVEDDEVICEAPPRAISAL_H 17 #define OHOS_WIFI_SAVEDDEVICEAPPRAISAL_H 18 19 #include "wifi_log.h" 20 #include "sta_device_appraisal.h" 21 #include "wifi_internal_msg.h" 22 23 namespace OHOS { 24 namespace Wifi { 25 class StaSavedDeviceAppraisal : public StaDeviceAppraisal { 26 FRIEND_GTEST(StaSavedDeviceAppraisal); 27 public: 28 StaSavedDeviceAppraisal(bool supportFmRoamingFlag, int instId = 0); 29 ~StaSavedDeviceAppraisal() override; 30 /** 31 * @Description Evaluate the Saved device from the scanning result and 32 return the Wi-Fi configuration of the selected device. 33 * 34 * @param scanInfos - Scan details list constructed based on the scan result(in) 35 * @param Info - Current device(in) 36 * @param electedDevice - elected device(out) 37 * @Return: Configuration of the selected device; Null if no devices are available in this category 38 */ 39 ErrCode DeviceAppraisals( 40 WifiDeviceConfig &electedDevice, std::vector<InterScanInfo> &scanInfos, WifiLinkedInfo &info) override; 41 42 private: 43 static const int MAX_SIGNAL_BAR_NUM = 5; 44 int signalScorePerLevel; 45 int signalBaseScore; 46 int sameBssidScore; 47 int sameDeviceScore; 48 int frequency5GHzScore; 49 int userSelectedDeviceScore; 50 int safetyDeviceScore; 51 int normalDeviceScore; 52 bool firmwareRoamFlag; 53 int m_instId; 54 55 /** 56 * @Description Scoring mechanism. 57 * 58 * @param scanInfo - Scan Information.(in) 59 * @param device - Saved device.(in) 60 * @param info - Connection information.(in) 61 * @param score - score points.(out) 62 * @param flip - flip the score when failed cout > MAX_RETRY_COUNT 63 */ 64 void AppraiseDeviceQuality(int &score, InterScanInfo &scanInfo, WifiDeviceConfig &device, 65 WifiLinkedInfo &info, bool flip); 66 /** 67 * @Description Signal strength converted to grids. 68 * 69 * @param rssi - Signal strength(in) 70 * @param signalBars - Max Bars(in) 71 * @Return: signal Bars 72 */ 73 74 bool WhetherSkipDevice(WifiDeviceConfig &device); 75 int CalculateSignalBars(int rssi, int signalBars); 76 /** 77 * @Description Whether the device is a 5G device. 78 * 79 * @param frequency(in) 80 * @Return success: true; failed: false 81 */ 82 bool Whether5GDevice(int frequency); 83 /** 84 * @Description check select higher priority wifi. 85 * 86 * @param score(int) 87 * @param lastScore(int) 88 * @param rssi(int) 89 * @param selectedRssi(int) 90 * @Return success: true; failed: false 91 */ 92 bool CheckHigherPriority(int score, int lastScore, int rssi, int selectedRssi); 93 }; 94 } // namespace Wifi 95 } // namespace OHOS 96 #endif