1 /*
2 * Copyright (c) 2021 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 #include "hdf_device_object.h"
17 #include "wlan_hdi_service_stub.h"
18 #include <sys/stat.h>
19 #include <sys/ioctl.h>
20 #include <osal_mem.h>
21 #include <fcntl.h>
22
WlanHdiServiceDispatch(struct HdfDeviceIoClient * client,int cmdId,struct HdfSBuf * data,struct HdfSBuf * reply)23 static int32_t WlanHdiServiceDispatch(struct HdfDeviceIoClient *client, int cmdId,
24 struct HdfSBuf *data, struct HdfSBuf *reply)
25 {
26 return WlanHdiServiceOnRemoteRequest(client, cmdId, data, reply);
27 }
28
HdfWlanHdiDriverRelease(struct HdfDeviceObject * deviceObject)29 void HdfWlanHdiDriverRelease(struct HdfDeviceObject *deviceObject)
30 {
31 struct HdfWlanRemoteNode *pos = NULL;
32 struct HdfWlanRemoteNode *tmp = NULL;
33 struct HdfWlanStubData *stubData = HdfStubDriver();
34 if (stubData == NULL) {
35 HDF_LOGE("%s: stubData is NUll!", __func__);
36 return;
37 }
38
39 DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &stubData->remoteListHead, struct HdfWlanRemoteNode, node) {
40 DListRemove(&(pos->node));
41 OsalMemFree(pos);
42 }
43 OsalMutexDestroy(&stubData->mutex);
44 struct IDeviceIoService *testService = deviceObject->service;
45 OsalMemFree(testService);
46 }
47
HdfWlanHdiDriverBind(struct HdfDeviceObject * deviceObject)48 int HdfWlanHdiDriverBind(struct HdfDeviceObject *deviceObject)
49 {
50 struct IDeviceIoService *ioService = (struct IDeviceIoService *)OsalMemAlloc(sizeof(struct IDeviceIoService));
51 if (ioService == NULL) {
52 HDF_LOGE("%s: OsalMemAlloc IDeviceIoService failed!", __func__);
53 return HDF_FAILURE;
54 }
55 ioService->Dispatch = WlanHdiServiceDispatch;
56 ioService->Open = NULL;
57 ioService->Release = NULL;
58 int ret = HdfDeviceObjectSetInterfaceDesc(deviceObject, "HDI.WLAN.V1_0");
59 if (ret != HDF_SUCCESS) {
60 HDF_LOGE("failed to set interface desc");
61 return ret;
62 }
63 deviceObject->service = ioService;
64 return HDF_SUCCESS;
65 }
66
HdfWlanRegisterInit(void)67 int32_t HdfWlanRegisterInit (void)
68 {
69 int32_t ret;
70
71 struct HdfWlanStubData *stubData = HdfStubDriver();
72 DListHeadInit(&stubData->remoteListHead);
73 ret = OsalMutexInit(&stubData->mutex);
74 if (ret != HDF_SUCCESS) {
75 HDF_LOGE("%s: Mutex init failed, error code: %d", __func__, ret);
76 return HDF_FAILURE;
77 }
78 return HDF_SUCCESS;
79 }
80
HdfWlanHdiDriverInit(struct HdfDeviceObject * deviceObject)81 int HdfWlanHdiDriverInit(struct HdfDeviceObject *deviceObject)
82 {
83 (void)deviceObject;
84
85 int32_t ret = HdfWlanRegisterInit();
86 if (ret != HDF_SUCCESS) {
87 HDF_LOGE("%{public}s: register init failed, error code: %d", __func__, ret);
88 return HDF_FAILURE;
89 }
90 return HDF_SUCCESS;
91 }
92
93 struct HdfDriverEntry g_wlanHdiDriverEntry = {
94 .moduleVersion = 1,
95 .moduleName = "wlan_device",
96 .Bind = HdfWlanHdiDriverBind,
97 .Init = HdfWlanHdiDriverInit,
98 .Release = HdfWlanHdiDriverRelease,
99 };
100
101 HDF_INIT(g_wlanHdiDriverEntry);