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