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_1/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
WlanInterfaceRegisterHid2dCallback(Hid2dCallbackFunc func,const char * ifName)89 int32_t WlanInterfaceRegisterHid2dCallback(Hid2dCallbackFunc func, const char *ifName)
90 {
91 int ret;
92
93 if (func == NULL || ifName == NULL) {
94 HDF_LOGE("%{public}s input parameter invalid!", __func__);
95 return HDF_ERR_INVALID_PARAM;
96 }
97 if (g_wifi == NULL) {
98 HDF_LOGE("%{public}s g_wifi is NULL!", __func__);
99 return HDF_FAILURE;
100 }
101 ret = g_wifi->registerHid2dCallback(func, ifName);
102 if (ret != HDF_SUCCESS) {
103 HDF_LOGE("%{public}s: Register hid2d callback failed!, error code: %{public}d", __func__, ret);
104 }
105 return ret;
106 }
107
WlanInterfaceUnregisterHid2dCallback(Hid2dCallbackFunc func,const char * ifName)108 int32_t WlanInterfaceUnregisterHid2dCallback(Hid2dCallbackFunc func, const char *ifName)
109 {
110 int ret;
111
112 if (func == NULL || ifName == NULL) {
113 HDF_LOGE("%{public}s input parameter invalid!", __func__);
114 return HDF_ERR_INVALID_PARAM;
115 }
116 if (g_wifi == NULL) {
117 HDF_LOGE("%{public}s g_wifi is NULL!", __func__);
118 return HDF_FAILURE;
119 }
120 ret = g_wifi->unregisterHid2dCallback(func, ifName);
121 if (ret != HDF_SUCCESS) {
122 HDF_LOGE("%{public}s: Unregister hid2d callback failed!, error code: %{public}d", __func__, ret);
123 }
124 return ret;
125 }
126
WlanExtendInterfaceWifiConstruct(void)127 int32_t WlanExtendInterfaceWifiConstruct(void)
128 {
129 int32_t ret;
130 ret = WifiConstruct(&g_wifi);
131 if (ret != HDF_SUCCESS) {
132 HDF_LOGE("%{public}s construct WiFi failed! error code: %{public}d", __func__, ret);
133 }
134 return ret;
135 }
136
WlanExtendInterfaceWifiDestruct(void)137 int32_t WlanExtendInterfaceWifiDestruct(void)
138 {
139 int32_t ret;
140 ret = WifiDestruct(&g_wifi);
141 if (ret != HDF_SUCCESS) {
142 HDF_LOGE("%{public}s destruct WiFi failed! error code: %{public}d", __func__, ret);
143 }
144 return ret;
145 }
146