1 /*
2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3 *
4 * HDF is dual licensed: you can use it either under the terms of
5 * the GPL, or the BSD license, at your option.
6 * See the LICENSE file in the root of this repository for complete details.
7 */
8
9 #include "can/can_service.h"
10 #include "can/can_core.h"
11 #include "hdf_device_desc.h"
12 #include "osal_mem.h"
13 #include "platform_core.h"
14
15 #define HDF_LOG_TAG can_service
16
CanServiceDispatch(struct HdfDeviceIoClient * client,int cmd,struct HdfSBuf * data,struct HdfSBuf * reply)17 static int32_t CanServiceDispatch(
18 struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
19 {
20 struct CanCntlr *cntlr = NULL;
21 (void)data;
22 (void)reply;
23
24 if (client == NULL || client->device == NULL) {
25 HDF_LOGE("CanServiceDispatch: invalid client object!");
26 return HDF_ERR_INVALID_OBJECT;
27 }
28
29 cntlr = CanCntlrFromHdfDev(client->device);
30 if (cntlr == NULL) {
31 HDF_LOGE("CanServiceDispatch: no controller binded!");
32 return HDF_ERR_INVALID_OBJECT;
33 }
34
35 HDF_LOGD("CanServiceDispatch: cntlr number=%d, cmd = %d", cntlr->number, cmd);
36 return HDF_SUCCESS;
37 }
38
CanServiceBind(struct HdfDeviceObject * device)39 int32_t CanServiceBind(struct HdfDeviceObject *device)
40 {
41 struct IDeviceIoService *service = NULL;
42
43 if (device == NULL) {
44 HDF_LOGE("CanServiceBind: device is null!");
45 return HDF_ERR_INVALID_OBJECT;
46 }
47
48 service = (struct IDeviceIoService *)OsalMemCalloc(sizeof(*service));
49 if (service == NULL) {
50 HDF_LOGE("CanServiceBind: memcalloc service fail!");
51 return HDF_ERR_MALLOC_FAIL;
52 }
53
54 service->Dispatch = CanServiceDispatch;
55 device->service = service;
56 return HDF_SUCCESS;
57 }
58
CanServiceRelease(struct HdfDeviceObject * device)59 void CanServiceRelease(struct HdfDeviceObject *device)
60 {
61 if (device != NULL && device->service != NULL) {
62 OsalMemFree(device->service);
63 }
64 }
65