1 /*
2  * Copyright (C) 2021-2022 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 HDI_WPA_INTERFACE_SUPPORT
17 #include "wifi_chip_hal_interface.h"
18 #include <mutex>
19 #include "wifi_log.h"
20 
21 #undef LOG_TAG
22 #define LOG_TAG "WifiChipHalInterface"
23 
24 namespace OHOS {
25 namespace Wifi {
GetInstance(void)26 WifiChipHalInterface &WifiChipHalInterface::GetInstance(void)
27 {
28     static WifiChipHalInterface inst;
29     static int initFlag = 0;
30     static std::mutex initMutex;
31     if (initFlag == 0) {
32         std::unique_lock<std::mutex> lock(initMutex);
33         if (initFlag == 0) {
34             if (inst.InitIdlClient()) {
35                 initFlag = 1;
36             }
37         }
38     }
39     return inst;
40 }
41 
GetWifiChipObject(int id,IWifiChip & chip)42 WifiErrorNo WifiChipHalInterface::GetWifiChipObject(int id, IWifiChip &chip)
43 {
44     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
45     return mIdlClient->GetWifiChipObject(id, chip);
46 }
47 
GetChipIds(std::vector<int> & ids)48 WifiErrorNo WifiChipHalInterface::GetChipIds(std::vector<int> &ids)
49 {
50     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
51     return mIdlClient->GetChipIds(ids);
52 }
53 
GetUsedChipId(int & id)54 WifiErrorNo WifiChipHalInterface::GetUsedChipId(int &id)
55 {
56     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
57     return mIdlClient->GetUsedChipId(id);
58 }
59 
GetChipCapabilities(int & capabilities)60 WifiErrorNo WifiChipHalInterface::GetChipCapabilities(int &capabilities)
61 {
62     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
63     return mIdlClient->GetChipCapabilities(capabilities);
64 }
65 
GetSupportedModes(std::vector<int> & modes)66 WifiErrorNo WifiChipHalInterface::GetSupportedModes(std::vector<int> &modes)
67 {
68     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
69     return mIdlClient->GetSupportedModes(modes);
70 }
71 
ConfigRunModes(int mode)72 WifiErrorNo WifiChipHalInterface::ConfigRunModes(int mode)
73 {
74     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
75     return mIdlClient->ConfigRunModes(mode);
76 }
77 
GetCurrentMode(int & mode)78 WifiErrorNo WifiChipHalInterface::GetCurrentMode(int &mode)
79 {
80     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
81     return mIdlClient->GetCurrentMode(mode);
82 }
83 
RegisterChipEventCallback(WifiChipEventCallback & callback)84 WifiErrorNo WifiChipHalInterface::RegisterChipEventCallback(WifiChipEventCallback &callback)
85 {
86     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
87     return mIdlClient->RegisterChipEventCallback(callback);
88 }
89 
RequestFirmwareDebugInfo(std::string & debugInfo)90 WifiErrorNo WifiChipHalInterface::RequestFirmwareDebugInfo(std::string &debugInfo)
91 {
92     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
93     return mIdlClient->RequestFirmwareDebugInfo(debugInfo);
94 }
95 
IsSupportDbdc(bool & isSupport) const96 WifiErrorNo WifiChipHalInterface::IsSupportDbdc(bool &isSupport) const
97 {
98     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
99     return mIdlClient->ReqIsSupportDbdc(isSupport);
100 }
101 
IsSupportCsa(bool & isSupport) const102 WifiErrorNo WifiChipHalInterface::IsSupportCsa(bool &isSupport) const
103 {
104     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
105     return mIdlClient->ReqIsSupportCsa(isSupport);
106 }
107 
IsSupportRadarDetect(bool & isSupport) const108 WifiErrorNo WifiChipHalInterface::IsSupportRadarDetect(bool &isSupport) const
109 {
110     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
111     return mIdlClient->ReqIsSupportRadarDetect(isSupport);
112 }
113 
IsSupportDfsChannel(bool & isSupport) const114 WifiErrorNo WifiChipHalInterface::IsSupportDfsChannel(bool &isSupport) const
115 {
116     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
117     return mIdlClient->ReqIsSupportDfsChannel(isSupport);
118 }
119 
IsSupportIndoorChannel(bool & isSupport) const120 WifiErrorNo WifiChipHalInterface::IsSupportIndoorChannel(bool &isSupport) const
121 {
122     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
123     return mIdlClient->ReqIsSupportIndoorChannel(isSupport);
124 }
125 }  // namespace Wifi
126 }  // namespace OHOS
127 #endif