1 /*
2  * Copyright (C) 2024 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 INCLUDE_WIFI_CHANNEL_HELPER_H
17 #define INCLUDE_WIFI_CHANNEL_HELPER_H
18 
19 #include "wifi_errcode.h"
20 #include "wifi_internal_msg.h"
21 
22 namespace OHOS {
23 namespace Wifi {
24 using ChannelsTable = std::map<BandType, std::vector<int32_t>>;
25 const std::map <BandType, std::vector<int32_t>> DEFAULT_VALID_CHANNEL = {{
26     BandType::BAND_2GHZ, { 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472 }}};
27 class WifiChannelHelper {
28 public:
29     static WifiChannelHelper &GetInstance();
30 
31     int GetValidBands(std::vector<BandType> &bands);
32 
33     int SetValidChannels(const ChannelsTable &channelsInfo);
34 
35     int GetValidChannels(ChannelsTable &channelsInfo);
36 
37     void UpdateValidChannels(std::string ifaceName, int instId = 0);
38 
39     bool GetAvailableScanFreqs(ScanBandType band, std::vector<int32_t>& freqs);
40 
41     bool IsFreqDbac(int freqA, int freqB);
42 
43     bool IsChannelDbac(int channelA, int channelB);
44 
45     void TransformFrequencyIntoChannel(const std::vector<int> &freqVector, std::vector<int> &chanVector);
46 
47     int TransformFrequencyIntoChannel(int freq);
48 
49     int TransformChannelToFrequency(int channel);
50 
51     BandType TransformFreqToBand(int freq);
52 
53     BandType TransformChannelToBand(int channel);
54 
55     bool IsValid5GHz(int freq);
56 
57     bool IsValid24GHz(int freq);
58 
59     bool IsValid24GChannel(int channel);
60 
61     bool IsValid5GChannel(int channel);
62 
63 private:
64     WifiChannelHelper();
65     void UpdateValidFreqs();
66     ChannelsTable mValidChannels {DEFAULT_VALID_CHANNEL};
67     std::mutex mMutex;
68     std::map<ScanBandType, std::vector<int>> mValidFreqs;
69 };
70 
71 }  // namespace Wifi
72 }  // namespace OHOS
73 #endif
74