1 /*
2 * Copyright (c) 2022 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 return HDF_ERR_INVALID_OBJECT;
45 }
46
47 service = (struct IDeviceIoService *)OsalMemCalloc(sizeof(*service));
48 if (service == NULL) {
49 HDF_LOGE("CanServiceBind: alloc service failed!");
50 return HDF_ERR_MALLOC_FAIL;
51 }
52
53 service->Dispatch = CanServiceDispatch;
54 device->service = service;
55 return HDF_SUCCESS;
56 }
57
CanServiceRelease(struct HdfDeviceObject * device)58 void CanServiceRelease(struct HdfDeviceObject *device)
59 {
60 if (device != NULL && device->service != NULL) {
61 OsalMemFree(device->service);
62 }
63 }
64