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 #include "wifi_hal_chip_interface.h"
16 #include <stdlib.h>
17 #include <string.h>
18 #include "securec.h"
19 #include "wifi_log.h"
20 #include "wifi_hal_adapter.h"
21 #undef LOG_TAG
22 #define LOG_TAG "WifiHalChipInterface"
23 
GetWifiChip(uint8_t id,WifiChip * chip)24 WifiErrorNo GetWifiChip(uint8_t id, WifiChip *chip)
25 {
26     LOGD("GetWifiChip() id: %{public}u", id);
27     if (chip != NULL) {
28         chip->chip = 0; /* fixed compile error, -Werror,-Wunused-parameter */
29     }
30     return WIFI_HAL_SUCCESS;
31 }
32 
GetWifiChipIds(uint8_t * ids,int32_t * size)33 WifiErrorNo GetWifiChipIds(uint8_t *ids, int32_t *size)
34 {
35     LOGD("GetWifiChipIds()");
36     if (ids != NULL && size != NULL) {
37         LOGD("input size %{public}d", *size);
38     }
39     return WIFI_HAL_SUCCESS;
40 }
41 
GetChipId(int32_t * id)42 WifiErrorNo GetChipId(int32_t *id)
43 {
44     LOGD("GetChipId()");
45     if (id != NULL) {
46         *id = 0; /* fixed compile error, -Werror,-Wunused-parameter */
47     }
48     return WIFI_HAL_SUCCESS;
49 }
50 
CreateIface(int32_t type,WifiIface * iface)51 WifiErrorNo CreateIface(int32_t type, WifiIface *iface)
52 {
53     LOGD("CreateIface() type: %{public}d", type);
54     if (iface == NULL) {
55         return WIFI_HAL_FAILED;
56     }
57     const int bufferSize = 8;
58     char name[bufferSize];
59     (void)memset_s(name, bufferSize, 0, bufferSize);
60     if (strcpy_s(iface->name, sizeof(iface->name), name) != EOK) {
61         return WIFI_HAL_FAILED;
62     }
63 
64     iface->type = type;
65     return WIFI_HAL_SUCCESS;
66 }
67 
GetIface(const char * ifname,WifiIface * iface)68 WifiErrorNo GetIface(const char *ifname, WifiIface *iface)
69 {
70     if (ifname == NULL || iface == NULL) {
71         return WIFI_HAL_FAILED;
72     }
73     LOGD("GetIface() ifname: %{public}s", ifname);
74     /* Currently not supported */
75     return WIFI_HAL_SUCCESS;
76 }
77 
GetIfaceNames(int32_t type,char * ifaces,int32_t size)78 WifiErrorNo GetIfaceNames(int32_t type, char *ifaces, int32_t size)
79 {
80     LOGD("GetIfaceNames() type: %{public}d size: %{public}d", type, size);
81     if (ifaces != NULL) {
82         ifaces[0] = '\0'; /* fixed compile error, -Werror,-Wunused-parameter */
83     }
84     return WIFI_HAL_SUCCESS;
85 }
86 
RemoveIface(const char * ifname)87 WifiErrorNo RemoveIface(const char *ifname)
88 {
89     if (ifname == NULL) {
90         return WIFI_HAL_FAILED;
91     }
92     LOGD("RemoveIface() ifname:%{public}s", ifname);
93     return WIFI_HAL_SUCCESS;
94 }
95 
GetCapabilities(uint32_t * capabilities)96 WifiErrorNo GetCapabilities(uint32_t *capabilities)
97 {
98     LOGD("GetCapabilities()");
99     if (capabilities != NULL) {
100         *capabilities = 0; /* fixed compile error, -Werror,-Wunused-parameter */
101     }
102     return WIFI_HAL_SUCCESS;
103 }
104 
GetSupportedComboModes(int32_t * modes,int32_t * size)105 WifiErrorNo GetSupportedComboModes(int32_t *modes, int32_t *size)
106 {
107     LOGD("GetSupportedComboModes()");
108     if (modes == NULL || size == NULL) {
109         return WIFI_HAL_FAILED;
110     }
111     return WIFI_HAL_NOT_SUPPORT;
112 }
113 
ConfigComboModes(int32_t mode)114 WifiErrorNo ConfigComboModes(int32_t mode)
115 {
116     LOGD("ConfigComboModes() mode: %{public}d", mode);
117     WifiHalVendorInterface *pInterface = GetWifiHalVendorInterface();
118     if (pInterface == NULL) {
119         return WIFI_HAL_GET_VENDOR_HAL_FAILED;
120     }
121     HalVendorError err = pInterface->func.wifiConfigComboModes(mode);
122     return ConvertErrorCode(err);
123 }
124 
GetComboModes(int32_t * id)125 WifiErrorNo GetComboModes(int32_t *id)
126 {
127     LOGD("GetComboModes()");
128     if (id == NULL) {
129         return WIFI_HAL_FAILED;
130     }
131     WifiHalVendorInterface *pInterface = GetWifiHalVendorInterface();
132     if (pInterface == NULL) {
133         return WIFI_HAL_GET_VENDOR_HAL_FAILED;
134     }
135     HalVendorError err = pInterface->func.wifiGetComboModes(id);
136     return ConvertErrorCode(err);
137 }
138 
RequestFirmwareDebugDump(unsigned char * bytes,int32_t * size)139 WifiErrorNo RequestFirmwareDebugDump(unsigned char *bytes, int32_t *size)
140 {
141     LOGD("RequestFirmwareDebugDump()");
142     if (bytes == NULL || size == NULL) {
143         return WIFI_HAL_FAILED;
144     }
145     WifiHalVendorInterface *pInterface = GetWifiHalVendorInterface();
146     if (pInterface == NULL) {
147         return WIFI_HAL_GET_VENDOR_HAL_FAILED;
148     }
149     HalVendorError err = pInterface->func.wifiRequestFirmwareDebugDump(bytes, size);
150     return ConvertErrorCode(err);
151 }
152 
GetIsChipSupportDbdc(int * support)153 WifiErrorNo GetIsChipSupportDbdc(int *support)
154 {
155     LOGD("GetIsChipSupportDbdc");
156     if (support == NULL) {
157         return WIFI_HAL_FAILED;
158     }
159     *support = WIFI_HAL_TRUE;
160     return WIFI_HAL_SUCCESS;
161 }
162 
GetIsChipSupportCsa(int * support)163 WifiErrorNo GetIsChipSupportCsa(int *support)
164 {
165     LOGD("GetIsChipSupportCsa");
166     if (support == NULL) {
167         return WIFI_HAL_FAILED;
168     }
169     *support = WIFI_HAL_FALSE;
170     return WIFI_HAL_SUCCESS;
171 }
172 
GetIsChipSupportRadarDetect(int * support)173 WifiErrorNo GetIsChipSupportRadarDetect(int *support)
174 {
175     LOGD("GetIsChipSupportRadarDetect");
176     if (support == NULL) {
177         return WIFI_HAL_FAILED;
178     }
179     *support = WIFI_HAL_TRUE;
180     return WIFI_HAL_SUCCESS;
181 }
182 
GetIsChipSupportDfsChannel(int * support)183 WifiErrorNo GetIsChipSupportDfsChannel(int *support)
184 {
185     LOGD("GetIsChipSupportDfsChannel");
186     if (support == NULL) {
187         return WIFI_HAL_FAILED;
188     }
189     *support = WIFI_HAL_TRUE;
190     return WIFI_HAL_SUCCESS;
191 }
192 
GetIsChipSupportIndoorChannel(int * support)193 WifiErrorNo GetIsChipSupportIndoorChannel(int *support)
194 {
195     LOGD("GetIsChipSupportIndoorChannel");
196     if (support == NULL) {
197         return WIFI_HAL_FAILED;
198     }
199     *support = WIFI_HAL_TRUE;
200     return WIFI_HAL_SUCCESS;
201 }
202