• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include <securec.h>
16 #include <hdf_base.h>
17 #include <hdf_log.h>
18 #include <hdf_load_vdi.h>
19 #include <osal_time.h>
20 #include <osal_mem.h>
21 #include "v1_2/iwlan_interface.h"
22 #include "wifi_hal.h"
23 #include "wlan_common_cmd.h"
24 #include "wlan_extend_cmd_vdi.h"
25 
26 #define VDI_VERSION_ONE 1
27 
28 struct WlanExtendInterfaceVdi *g_wlanExtendVdiImpl = NULL;
29 struct HdfVdiObject *g_vdi = NULL;
30 
CloseVdi(void)31 static void CloseVdi(void)
32 {
33     if (g_vdi != NULL) {
34         HdfCloseVdi(g_vdi);
35         g_vdi = NULL;
36     }
37 }
38 
InitWlanExtendVdiImpl()39 static int32_t InitWlanExtendVdiImpl()
40 {
41     uint32_t version = 0;
42     g_vdi = HdfLoadVdi(WLAN_EXTEND_VDI_LIBNAME);
43     if (g_vdi == NULL || g_vdi->vdiBase == NULL) {
44         HDF_LOGE("%{public}s: load wlan extend vdi failed", __func__);
45         return HDF_FAILURE;
46     }
47 
48     version = HdfGetVdiVersion(g_vdi);
49     if (version != VDI_VERSION_ONE) {
50         HDF_LOGE("%{public}s: get wlan extend vdi version failed", __func__);
51         CloseVdi();
52         return HDF_FAILURE;
53     }
54 
55     struct VdiWrapperWlanExtend *vdiWrapperWlanExtend = NULL;
56     vdiWrapperWlanExtend = (struct VdiWrapperWlanExtend *)(g_vdi->vdiBase);
57     g_wlanExtendVdiImpl = vdiWrapperWlanExtend->wlanExtendModule;
58     if (g_wlanExtendVdiImpl == NULL) {
59         HDF_LOGE("%{public}s: get vibrator impl failed", __func__);
60         CloseVdi();
61         return HDF_FAILURE;
62     }
63 
64     return HDF_SUCCESS;
65 }
66 
WlanInterfaceStartChannelMeas(struct IWlanInterface * self,const char * ifName,const struct MeasChannelParam * measChannelParam)67 int32_t WlanInterfaceStartChannelMeas(struct IWlanInterface *self, const char *ifName,
68     const struct MeasChannelParam *measChannelParam)
69 {
70     int32_t ret;
71 
72     (void)self;
73     if (ifName == NULL || measChannelParam == NULL) {
74         HDF_LOGE("%{public}s input parameter invalid!", __func__);
75         return HDF_ERR_INVALID_PARAM;
76     }
77     if (g_wlanExtendVdiImpl == NULL) {
78         HDF_LOGE("%{public}s g_wlanExtendVdiImpl is NULL!", __func__);
79         return HDF_FAILURE;
80     }
81     ret = g_wlanExtendVdiImpl->startChannelMeas(self, ifName, measChannelParam);
82     if (ret != HDF_SUCCESS) {
83         HDF_LOGE("%{public}s: start channel meas failed!, error code: %{public}d", __func__, ret);
84     }
85     return ret;
86 }
87 
WlanInterfaceGetChannelMeasResult(struct IWlanInterface * self,const char * ifName,struct MeasChannelResult * measChannelResult)88 int32_t WlanInterfaceGetChannelMeasResult(struct IWlanInterface *self, const char *ifName,
89     struct MeasChannelResult *measChannelResult)
90 {
91     int32_t ret;
92 
93     (void)self;
94     if (ifName == NULL || measChannelResult == NULL) {
95         HDF_LOGE("%{public}s input parameter invalid!", __func__);
96         return HDF_ERR_INVALID_PARAM;
97     }
98     if (g_wlanExtendVdiImpl == NULL) {
99         HDF_LOGE("%{public}s g_wlanExtendVdiImplis NULL!", __func__);
100         return HDF_FAILURE;
101     }
102     ret = g_wlanExtendVdiImpl->getChannelMeasResult(self, ifName, measChannelResult);
103     if (ret != HDF_SUCCESS) {
104         HDF_LOGE("%{public}s: get channel meas result failed!, error code: %{public}d", __func__, ret);
105     }
106     return ret;
107 }
108 
WlanInterfaceWifiSendCmdIoctl(struct IWlanInterface * self,const char * ifName,int32_t cmdId,const int8_t * paramBuf,uint32_t paramBufLen)109 int32_t WlanInterfaceWifiSendCmdIoctl(struct IWlanInterface *self, const char *ifName, int32_t cmdId,
110     const int8_t *paramBuf, uint32_t paramBufLen)
111 {
112     int32_t ret;
113 
114     (void)self;
115     if (ifName == NULL || paramBuf == NULL) {
116         HDF_LOGE("%{public}s input parameter invalid!", __func__);
117         return HDF_ERR_INVALID_PARAM;
118     }
119     if (g_wlanExtendVdiImpl == NULL) {
120         HDF_LOGE("%{public}s g_wlanExtendVdiImpl is NULL!", __func__);
121         return HDF_FAILURE;
122     }
123     ret = g_wlanExtendVdiImpl->sendCmdIoctl(self, ifName, cmdId, paramBuf, paramBufLen);
124     if (ret != HDF_SUCCESS) {
125         HDF_LOGE("%{public}s: send ioctl command failed!, error code: %{public}d", __func__, ret);
126     }
127     return ret;
128 }
129 
WlanInterfaceRegisterHid2dCallback(Hid2dCallbackFunc func,const char * ifName)130 int32_t WlanInterfaceRegisterHid2dCallback(Hid2dCallbackFunc func, const char *ifName)
131 {
132     int ret;
133 
134     if (func == NULL || ifName == NULL) {
135         HDF_LOGE("%{public}s input parameter invalid!", __func__);
136         return HDF_ERR_INVALID_PARAM;
137     }
138     if (g_wlanExtendVdiImpl == NULL) {
139         HDF_LOGE("%{public}s g_wlanExtendVdiImpl is NULL!", __func__);
140         return HDF_FAILURE;
141     }
142     ret = g_wlanExtendVdiImpl->registerHid2dCallback(func, ifName);
143     if (ret != HDF_SUCCESS) {
144         HDF_LOGE("%{public}s: Register hid2d callback failed!, error code: %{public}d", __func__, ret);
145     }
146     return ret;
147 }
148 
WlanInterfaceUnregisterHid2dCallback(Hid2dCallbackFunc func,const char * ifName)149 int32_t WlanInterfaceUnregisterHid2dCallback(Hid2dCallbackFunc func, const char *ifName)
150 {
151     int ret;
152 
153     if (func == NULL || ifName == NULL) {
154         HDF_LOGE("%{public}s input parameter invalid!", __func__);
155         return HDF_ERR_INVALID_PARAM;
156     }
157     if (g_wlanExtendVdiImpl == NULL) {
158         HDF_LOGE("%{public}s g_wlanExtendVdiImpl is NULL!", __func__);
159         return HDF_FAILURE;
160     }
161     ret = g_wlanExtendVdiImpl->unregisterHid2dCallback(func, ifName);
162     if (ret != HDF_SUCCESS) {
163         HDF_LOGE("%{public}s: Unregister hid2d callback failed!, error code: %{public}d", __func__, ret);
164     }
165     return ret;
166 }
167 
WlanExtendInterfaceWifiConstruct(void)168 int32_t WlanExtendInterfaceWifiConstruct(void)
169 {
170     if (g_wlanExtendVdiImpl != NULL) {
171         HDF_LOGI("%{public}s wlanExtendVdiImpl is not NULL!", __func__);
172         return HDF_SUCCESS;
173     }
174 
175     int32_t ret;
176     ret = InitWlanExtendVdiImpl();
177     if (ret != HDF_SUCCESS) {
178         HDF_LOGE("%{public}s construct WiFi failed! error code: %{public}d", __func__, ret);
179         return HDF_FAILURE;
180     }
181 
182     if (g_wlanExtendVdiImpl == NULL) {
183         HDF_LOGE("%{public}s wlanExtendVdiImpl init failed!", __func__);
184         CloseVdi();
185         return HDF_FAILURE;
186     }
187     ret = g_wlanExtendVdiImpl->wifiConstruct();
188     if (ret != HDF_SUCCESS) {
189         HDF_LOGE("%{public}s construct WiFi failed! error code: %{public}d", __func__, ret);
190         CloseVdi();
191     }
192     return ret;
193 }
194 
WlanExtendInterfaceWifiDestruct(void)195 int32_t WlanExtendInterfaceWifiDestruct(void)
196 {
197     if (g_wlanExtendVdiImpl == NULL) {
198         HDF_LOGI("%{public}s wlanExtendVdiImpl is NULL!", __func__);
199         return HDF_SUCCESS;
200     }
201 
202     int32_t ret;
203     ret = g_wlanExtendVdiImpl->wifiDestruct();
204     if (ret != HDF_SUCCESS) {
205         HDF_LOGE("%{public}s destruct WiFi failed! error code: %{public}d", __func__, ret);
206     }
207     CloseVdi();
208     g_wlanExtendVdiImpl = NULL;
209     return ret;
210 }
211