• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "device_resource_if.h"
10 #include "hdf_base.h"
11 #include "hdf_device_desc.h"
12 #include "hdf_log.h"
13 #include "pin_test.h"
14 #include "securec.h"
15 #include "string.h"
16 
17 #define HDF_LOG_TAG pin_driver_test_c
18 
19 static struct PinTestConfig g_config;
20 
PinTestDispatch(struct HdfDeviceIoClient * client,int cmd,struct HdfSBuf * data,struct HdfSBuf * reply)21 static int32_t PinTestDispatch(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
22 {
23     (void)client;
24     (void)data;
25     if (cmd == 0) {
26         if (reply == NULL) {
27             HDF_LOGE("PinTestDispatch: reply is null!");
28             return HDF_ERR_INVALID_PARAM;
29         }
30         if (!HdfSbufWriteBuffer(reply, &g_config, sizeof(g_config))) {
31             HDF_LOGE("PinTestDispatch: write config fail!");
32             return HDF_ERR_IO;
33         }
34     } else {
35         HDF_LOGE("PinTestDispatch: cmd %d is not support!", cmd);
36         return HDF_ERR_NOT_SUPPORT;
37     }
38 
39     return HDF_SUCCESS;
40 }
PinTestReadConfig(struct PinTestConfig * config,const struct DeviceResourceNode * node)41 static int32_t PinTestReadConfig(struct PinTestConfig *config, const struct DeviceResourceNode *node)
42 {
43     int32_t ret;
44     const char *funcName = NULL;
45     struct DeviceResourceIface *drsOps = NULL;
46 
47     drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
48     if (drsOps == NULL || drsOps->GetUint32 == NULL || drsOps->GetString == NULL) {
49         HDF_LOGE("PinTestReadConfig: invalid drs ops!");
50         return HDF_FAILURE;
51     }
52     ret = drsOps->GetString(node, "pinName", &config->pinName, 0);
53     if (ret != HDF_SUCCESS) {
54         HDF_LOGE("PinTestReadConfig: read pinName fail!");
55         return ret;
56     }
57 
58     ret = drsOps->GetUint32(node, "strengthNum", &config->strengthNum, 0);
59     if (ret != HDF_SUCCESS) {
60         HDF_LOGE("PinTestReadConfig: read StrengthNum fail!");
61         return ret;
62     }
63 
64     ret = drsOps->GetUint32(node, "PullTypeNum", &config->PullTypeNum, 0);
65     if (ret != HDF_SUCCESS) {
66         HDF_LOGE("PinTestReadConfig: read PullTypeNum fail!");
67         return ret;
68     }
69 
70     ret = drsOps->GetString(node, "funcName", &funcName, 0);
71     if (ret != HDF_SUCCESS) {
72         HDF_LOGE("PinTestReadConfig: read funcName fail!");
73         return ret;
74     }
75     if (strcpy_s(config->funcNameBuf, NAME_SIZE_MAX, funcName) != EOK) {
76         HDF_LOGE("PinTestReadConfig: copy funcNameBuf fail!");
77         return HDF_FAILURE;
78     }
79 
80     if (strcpy_s(config->pinNameBuf, NAME_SIZE_MAX, config->pinName) != EOK) {
81         HDF_LOGE("PinTestReadConfig: copy pinNameBuf fail!");
82         return HDF_FAILURE;
83     }
84     return HDF_SUCCESS;
85 }
86 
PinTestBind(struct HdfDeviceObject * device)87 static int32_t PinTestBind(struct HdfDeviceObject *device)
88 {
89     int32_t ret;
90     static struct IDeviceIoService service;
91 
92     if (device == NULL || device->property == NULL) {
93         HDF_LOGE("PinTestBind: device or config is null!");
94         return HDF_ERR_IO;
95     }
96     ret = PinTestReadConfig(&g_config, device->property);
97     if (ret != HDF_SUCCESS) {
98         HDF_LOGE("PinTestBind: read config fail!");
99         return ret;
100     }
101     service.Dispatch = PinTestDispatch;
102     device->service = &service;
103     return HDF_SUCCESS;
104 }
105 
PinTestInit(struct HdfDeviceObject * device)106 static int32_t PinTestInit(struct HdfDeviceObject *device)
107 {
108     (void)device;
109     return HDF_SUCCESS;
110 }
111 
PinTestRelease(struct HdfDeviceObject * device)112 static void PinTestRelease(struct HdfDeviceObject *device)
113 {
114     if (device != NULL) {
115         device->service = NULL;
116     }
117     HDF_LOGI("PinTestRelease: done!");
118     return;
119 }
120 
121 struct HdfDriverEntry g_pinTestEntry = {
122     .moduleVersion = 1,
123     .Bind = PinTestBind,
124     .Init = PinTestInit,
125     .Release = PinTestRelease,
126     .moduleName = "PLATFORM_PIN_TEST",
127 };
128 HDF_INIT(g_pinTestEntry);