• 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 <unistd.h>
17 #include <stdio.h>
18 #include <sys/time.h>
19 #include "hdf_base.h"
20 #include "hdf_log.h"
21 #include "securec.h"
22 #include "hdf_device_desc.h"
23 #include "osal_atomic.h"
24 
25 #define HDF_LOG_TAG     USB_PNP_SAMPLE_TEST
26 #define STR_LEN         1024
27 
UsbPnpSampleTestWriteLog(char * string)28 static void UsbPnpSampleTestWriteLog(char *string)
29 {
30     char str[STR_LEN];
31     FILE *fp = NULL;
32     struct timeval time;
33 
34     gettimeofday(&time, NULL);
35 
36     fp = fopen("/data/usbhost_pnp_xts", "a+");
37     if (!fp) {
38         HDF_LOGE("%s: fopen failed", __func__);
39         return;
40     }
41 
42     (void)snprintf_s(str, STR_LEN, STR_LEN - 1, "[XTSCHECK] %d.%06d, %s\n",
43         time.tv_sec, time.tv_usec, string);
44 
45     (void)fwrite(str, strlen(str), 1, fp);
46     (void)fclose(fp);
47 }
48 
UsbPnpSampleTestServiceDispatch(struct HdfDeviceIoClient * client,int32_t cmdId,struct HdfSBuf * data,struct HdfSBuf * reply)49 static int32_t UsbPnpSampleTestServiceDispatch(struct HdfDeviceIoClient *client, int32_t cmdId,
50     struct HdfSBuf *data, struct HdfSBuf *reply)
51 {
52     HDF_LOGI("%s: %d", __func__, __LINE__);
53     return HDF_SUCCESS;
54 }
55 
UsbPnpSampleTestDriverBind(struct HdfDeviceObject * deviceObject)56 int32_t UsbPnpSampleTestDriverBind(struct HdfDeviceObject *deviceObject)
57 {
58     HDF_LOGI("%s: %d enter", __func__, __LINE__);
59     static struct IDeviceIoService testService = {
60         .Dispatch = UsbPnpSampleTestServiceDispatch,
61         .Open = NULL,
62         .Release = NULL,
63     };
64     deviceObject->service = &testService;
65     HDF_LOGI("%s: %d done", __func__, __LINE__);
66     return HDF_SUCCESS;
67 }
68 
UsbPnpSampleTestDriverInit(struct HdfDeviceObject * deviceObject)69 int32_t UsbPnpSampleTestDriverInit(struct HdfDeviceObject *deviceObject)
70 {
71     HDF_LOGI("%s: %d", __func__, __LINE__);
72 
73     UsbPnpSampleTestWriteLog("usb pnp sample device driver was loaded successfully");
74 
75     return HDF_SUCCESS;
76 }
77 
UsbPnpSampleTestDriverRelease(struct HdfDeviceObject * deviceObject)78 void UsbPnpSampleTestDriverRelease(struct HdfDeviceObject *deviceObject)
79 {
80     HDF_LOGI("%s: %d", __func__, __LINE__);
81 
82     (void)deviceObject;
83 
84     UsbPnpSampleTestWriteLog("usb pnp sample device driver was unloaded successfully");
85 
86     return;
87 }
88 
89 struct HdfDriverEntry g_usbPnpSampleDriverEntry = {
90     .moduleVersion = 1,
91     .moduleName    = "usb_pnp_sample_driver",
92     .Bind          = UsbPnpSampleTestDriverBind,
93     .Init          = UsbPnpSampleTestDriverInit,
94     .Release       = UsbPnpSampleTestDriverRelease,
95 };
96 
97 HDF_INIT(g_usbPnpSampleDriverEntry);
98