1 /*
2 * Copyright (c) 2022-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 <osal_time.h>
19 #include <osal_mem.h>
20 #include "v1_3/iwlan_interface.h"
21 #include "wifi_hal.h"
22 #include "wlan_common_cmd.h"
23
24 static struct IWiFi *g_wifi = NULL;
25
WlanInterfaceStartChannelMeas(struct IWlanInterface * self,const char * ifName,const struct MeasChannelParam * measChannelParam)26 int32_t WlanInterfaceStartChannelMeas(struct IWlanInterface *self, const char *ifName,
27 const struct MeasChannelParam *measChannelParam)
28 {
29 int32_t ret;
30
31 (void)self;
32 if (ifName == NULL || measChannelParam == NULL) {
33 HDF_LOGE("%{public}s input parameter invalid!", __func__);
34 return HDF_ERR_INVALID_PARAM;
35 }
36 if (g_wifi == NULL) {
37 HDF_LOGE("%{public}s g_wifi is NULL!", __func__);
38 return HDF_FAILURE;
39 }
40 ret = g_wifi->startChannelMeas(ifName, (const struct MeasParam *)measChannelParam);
41 if (ret != HDF_SUCCESS) {
42 HDF_LOGE("%{public}s: start channel meas failed!, error code: %{public}d", __func__, ret);
43 }
44 return ret;
45 }
46
WlanInterfaceGetChannelMeasResult(struct IWlanInterface * self,const char * ifName,struct MeasChannelResult * measChannelResult)47 int32_t WlanInterfaceGetChannelMeasResult(struct IWlanInterface *self, const char *ifName,
48 struct MeasChannelResult *measChannelResult)
49 {
50 int32_t ret;
51
52 (void)self;
53 if (ifName == NULL || measChannelResult == NULL) {
54 HDF_LOGE("%{public}s input parameter invalid!", __func__);
55 return HDF_ERR_INVALID_PARAM;
56 }
57 if (g_wifi == NULL) {
58 HDF_LOGE("%{public}s g_wifi is NULL!", __func__);
59 return HDF_FAILURE;
60 }
61 ret = g_wifi->getChannelMeasResult(ifName, (struct MeasResult *)measChannelResult);
62 if (ret != HDF_SUCCESS) {
63 HDF_LOGE("%{public}s: get channel meas result failed!, error code: %{public}d", __func__, ret);
64 }
65 return ret;
66 }
67
WlanInterfaceWifiSendCmdIoctl(struct IWlanInterface * self,const char * ifName,int32_t cmdId,const int8_t * paramBuf,uint32_t paramBufLen)68 int32_t WlanInterfaceWifiSendCmdIoctl(struct IWlanInterface *self, const char *ifName, int32_t cmdId,
69 const int8_t *paramBuf, uint32_t paramBufLen)
70 {
71 int32_t ret;
72
73 (void)self;
74 if (ifName == NULL || paramBuf == NULL) {
75 HDF_LOGE("%{public}s input parameter invalid!", __func__);
76 return HDF_ERR_INVALID_PARAM;
77 }
78 if (g_wifi == NULL) {
79 HDF_LOGE("%{public}s g_wifi is NULL!", __func__);
80 return HDF_FAILURE;
81 }
82 ret = g_wifi->sendCmdIoctl(ifName, cmdId, paramBuf, paramBufLen);
83 if (ret != HDF_SUCCESS) {
84 HDF_LOGE("%{public}s: send ioctl command failed!, error code: %{public}d", __func__, ret);
85 }
86 return ret;
87 }
88
WlanInterfaceGetCoexChannelList(struct IWlanInterface * self,const char * ifName,uint8_t * paramBuf,uint32_t * paramBufLen)89 int32_t WlanInterfaceGetCoexChannelList(struct IWlanInterface *self, const char *ifName,
90 uint8_t *paramBuf, uint32_t *paramBufLen)
91 {
92 HDF_LOGI("%{public}s enter WlanInterfaceGetCoexChannelList", __func__);
93 (void)self;
94 if (ifName == NULL || paramBuf == NULL) {
95 HDF_LOGE("%{public}s input parameter invalid!", __func__);
96 return HDF_ERR_INVALID_PARAM;
97 }
98 return HDF_ERR_NOT_SUPPORT;
99 }
100
WlanInterfaceRegisterHid2dCallback(Hid2dCallbackFunc func,const char * ifName)101 int32_t WlanInterfaceRegisterHid2dCallback(Hid2dCallbackFunc func, const char *ifName)
102 {
103 int ret;
104
105 if (func == NULL || ifName == NULL) {
106 HDF_LOGE("%{public}s input parameter invalid!", __func__);
107 return HDF_ERR_INVALID_PARAM;
108 }
109 if (g_wifi == NULL) {
110 HDF_LOGE("%{public}s g_wifi is NULL!", __func__);
111 return HDF_FAILURE;
112 }
113 ret = g_wifi->registerHid2dCallback(func, ifName);
114 if (ret != HDF_SUCCESS) {
115 HDF_LOGE("%{public}s: Register hid2d callback failed!, error code: %{public}d", __func__, ret);
116 }
117 return ret;
118 }
119
WlanInterfaceUnregisterHid2dCallback(Hid2dCallbackFunc func,const char * ifName)120 int32_t WlanInterfaceUnregisterHid2dCallback(Hid2dCallbackFunc func, const char *ifName)
121 {
122 int ret;
123
124 if (func == NULL || ifName == NULL) {
125 HDF_LOGE("%{public}s input parameter invalid!", __func__);
126 return HDF_ERR_INVALID_PARAM;
127 }
128 if (g_wifi == NULL) {
129 HDF_LOGE("%{public}s g_wifi is NULL!", __func__);
130 return HDF_FAILURE;
131 }
132 ret = g_wifi->unregisterHid2dCallback(func, ifName);
133 if (ret != HDF_SUCCESS) {
134 HDF_LOGE("%{public}s: Unregister hid2d callback failed!, error code: %{public}d", __func__, ret);
135 }
136 return ret;
137 }
138
WlanExtendInterfaceWifiConstruct(void)139 int32_t WlanExtendInterfaceWifiConstruct(void)
140 {
141 int32_t ret;
142 ret = WifiConstruct(&g_wifi);
143 if (ret != HDF_SUCCESS) {
144 HDF_LOGE("%{public}s construct WiFi failed! error code: %{public}d", __func__, ret);
145 }
146 return ret;
147 }
148
WlanExtendInterfaceWifiDestruct(void)149 int32_t WlanExtendInterfaceWifiDestruct(void)
150 {
151 int32_t ret;
152 ret = WifiDestruct(&g_wifi);
153 if (ret != HDF_SUCCESS) {
154 HDF_LOGE("%{public}s destruct WiFi failed! error code: %{public}d", __func__, ret);
155 }
156 return ret;
157 }
158