• 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 
38     (void)snprintf_s(str, STR_LEN, STR_LEN - 1, "[XTSCHECK] %d.%06d, %s\n",
39         time.tv_sec, time.tv_usec, string);
40 
41     (void)fwrite(str, strlen(str), 1, fp);
42     (void)fclose(fp);
43 }
44 
UsbPnpSampleTestServiceDispatch(struct HdfDeviceIoClient * client,int cmdId,struct HdfSBuf * data,struct HdfSBuf * reply)45 static int32_t UsbPnpSampleTestServiceDispatch(struct HdfDeviceIoClient *client, int cmdId,
46     struct HdfSBuf *data, struct HdfSBuf *reply)
47 {
48     HDF_LOGI("%s: %d", __func__, __LINE__);
49     return HDF_SUCCESS;
50 }
51 
UsbPnpSampleTestDriverBind(struct HdfDeviceObject * deviceObject)52 int UsbPnpSampleTestDriverBind(struct HdfDeviceObject *deviceObject)
53 {
54     HDF_LOGI("%s: %d enter", __func__, __LINE__);
55     static struct IDeviceIoService testService = {
56         .Dispatch = UsbPnpSampleTestServiceDispatch,
57         .Open = NULL,
58         .Release = NULL,
59     };
60     deviceObject->service = &testService;
61     HDF_LOGI("%s: %d done", __func__, __LINE__);
62     return HDF_SUCCESS;
63 }
64 
UsbPnpSampleTestDriverInit(struct HdfDeviceObject * deviceObject)65 int UsbPnpSampleTestDriverInit(struct HdfDeviceObject *deviceObject)
66 {
67     HDF_LOGI("%s: %d", __func__, __LINE__);
68 
69     UsbPnpSampleTestWriteLog("usb pnp sample device driver was loaded successfully");
70 
71     return HDF_SUCCESS;
72 }
73 
UsbPnpSampleTestDriverRelease(struct HdfDeviceObject * deviceObject)74 void UsbPnpSampleTestDriverRelease(struct HdfDeviceObject *deviceObject)
75 {
76     HDF_LOGI("%s: %d", __func__, __LINE__);
77 
78     (void)deviceObject;
79 
80     UsbPnpSampleTestWriteLog("usb pnp sample device driver was unloaded successfully");
81 
82     return;
83 }
84 
85 struct HdfDriverEntry g_usbPnpSampleDriverEntry = {
86     .moduleVersion = 1,
87     .moduleName    = "usb_pnp_sample_driver",
88     .Bind          = UsbPnpSampleTestDriverBind,
89     .Init          = UsbPnpSampleTestDriverInit,
90     .Release       = UsbPnpSampleTestDriverRelease,
91 };
92 
93 HDF_INIT(g_usbPnpSampleDriverEntry);
94