1 /* 2 * Copyright (C) 2021-2023 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 WIFI_COUNTRY_CODE_POLICY_FACTORY_H 17 #define WIFI_COUNTRY_CODE_POLICY_FACTORY_H 18 19 #include <bitset> 20 #include <list> 21 #include <string> 22 #include <mutex> 23 #include "wifi_errcode.h" 24 #include "wifi_scan_msg.h" 25 #include "wifi_country_code_define.h" 26 #include "wifi_scan_msg.h" 27 #include "wifi_library_utils.h" 28 29 namespace OHOS { 30 namespace Wifi { 31 class WifiCountryCodePolicy { 32 public: 33 /** 34 * @Description WifiCountryCodePolicy constructor 35 * 36 * @param wifiCountryCodePolicyConf wifi country code policy config 37 */ 38 explicit WifiCountryCodePolicy(std::bitset<WIFI_COUNTRY_CODE_POLICE_DEF_LEN> wifiCountryCodePolicyConf); 39 /** 40 * @Description WifiCountryCodePolicy destructor 41 */ 42 ~WifiCountryCodePolicy() = default; 43 44 /** 45 * @Description calculate wifi countryCode 46 * 47 * @return wifiCountryCode - country code 48 */ 49 ErrCode CalculateWifiCountryCode(std::string &wifiCountryCode); 50 51 /** 52 * @Description handle scan result action 53 */ 54 void HandleScanResultAction(); 55 private: 56 void CreatePolicy(std::bitset<WIFI_COUNTRY_CODE_POLICE_DEF_LEN> wifiCountryCodePolicyConf); 57 ErrCode GetWifiCountryCodeByFactory(std::string &wifiCountryCode); 58 ErrCode GetWifiCountryCodeByMcc(std::string &wifiCountryCode); 59 ErrCode StatisticCountryCodeFromScanResult(std::string &wifiCountryCode); 60 ErrCode FindLargestCountCountryCode(std::string &wifiCountryCode); 61 ErrCode ParseCountryCodeElement(const std::vector<WifiInfoElem> &infoElems, std::string &wifiCountryCode); 62 ErrCode HandleWifiNetworkStateChangeAction(int connectionStatus); 63 ErrCode GetWifiCountryCodeByRegion(std::string &wifiCountryCode); 64 ErrCode GetWifiCountryCodeByAP(std::string &wifiCountryCode); 65 ErrCode GetWifiCountryCodeByScanResult(std::string &wifiCountryCode); 66 ErrCode GetWifiCountryCodeByDefaultZZ(std::string &wifiCountryCode); 67 ErrCode GetWifiCountryCodeByCache(std::string &wifiCountryCode); 68 ErrCode GetWifiCountryCodeByDefaultRegion(std::string &wifiCountryCode); 69 ErrCode GetWifiCountryCodeByDefault(std::string &wifiCountryCode); 70 bool IsContainBssid(const std::vector<std::string> &bssidList, const std::string &bssid); 71 72 std::mutex countryCodeFromScanResult; 73 std::vector<std::vector<std::string>> m_allBssidVector; 74 std::map<std::string, std::string> m_bssidAndCountryCodeMap; 75 std::string m_wifiCountryCodeFromScanResults; 76 std::list<std::function<ErrCode(std::string&)>> m_policyList; 77 }; 78 79 class WifiCountryCodeIntlUtils { 80 public: WifiCountryCodeIntlUtils()81 WifiCountryCodeIntlUtils() : wifiLibraryUtils_("libwifi_ext_lib.z.so", libHandle_, false) {} 82 ~WifiCountryCodeIntlUtils() = default; 83 std::string GetSystemRegion(); 84 private: 85 static void* libHandle_; 86 WifiLibraryUtils wifiLibraryUtils_; 87 }; 88 } 89 } 90 #endif