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