• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this list of
8  *    conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  *    of conditions and the following disclaimer in the documentation and/or other materials
12  *    provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15  *    to endorse or promote products derived from this software without specific prior written
16  *    permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "usb_pnp_manager.h"
32 #include "hdf_base.h"
33 #include "hdf_device_desc.h"
34 #include "hdf_io_service_if.h"
35 #include "hdf_log.h"
36 #include "usb_ddk_pnp_loader.h"
37 
38 #define HDF_LOG_TAG usb_pnp_manager
39 
UsbPnpManagerWriteModuleName(struct HdfSBuf * sbuf,const char * moduleName)40 bool UsbPnpManagerWriteModuleName(struct HdfSBuf *sbuf, const char *moduleName)
41 {
42     return HdfSbufWriteString(sbuf, moduleName);
43 }
44 
UsbPnpManagerDispatch(struct HdfDeviceIoClient * client,int32_t cmd,struct HdfSBuf * data,struct HdfSBuf * reply)45 static int32_t UsbPnpManagerDispatch(struct HdfDeviceIoClient *client, int32_t cmd,
46     struct HdfSBuf *data, struct HdfSBuf *reply)
47 {
48     if (client == NULL) {
49         HDF_LOGE("%s:%d client is NULL, cmd = %d", __func__, __LINE__, cmd);
50         return HDF_FAILURE;
51     }
52 
53     HDF_LOGI("%s:%d received cmd = %d", __func__, __LINE__, cmd);
54 
55     return UsbDdkPnpLoaderEventReceived((void *)client->device, cmd, data);
56 }
57 
UsbPnpManagerBind(struct HdfDeviceObject * device)58 static int32_t UsbPnpManagerBind(struct HdfDeviceObject *device)
59 {
60     static struct IDeviceIoService pnpLoaderService = {
61         .Dispatch = UsbPnpManagerDispatch,
62     };
63 
64     dprintf("%s:%d enter!\n", __func__, __LINE__);
65 
66     if (device == NULL) {
67         dprintf("%s: device is NULL!\n", __func__);
68         return HDF_ERR_INVALID_OBJECT;
69     }
70 
71     device->service = &pnpLoaderService;
72     dprintf("%s:%d bind success\n", __func__, __LINE__);
73 
74     return HDF_SUCCESS;
75 }
76 
UsbPnpManagerInit(struct HdfDeviceObject * device)77 static int32_t UsbPnpManagerInit(struct HdfDeviceObject *device)
78 {
79     int32_t ret;
80 
81     dprintf("%s:%d enter!\n", __func__, __LINE__);
82 
83     if (device == NULL) {
84         dprintf("%s: device is NULL\n", __func__);
85         return HDF_ERR_INVALID_OBJECT;
86     }
87 
88     ret = UsbDdkPnpLoaderEventHandle();
89     if (ret != HDF_SUCCESS) {
90         dprintf("%s:%d UsbPnpLoaderEventHandle error\n", __func__, __LINE__);
91         return ret;
92     }
93 
94     dprintf("%s:%d Init success\n", __func__, __LINE__);
95 
96     return ret;
97 }
98 
UsbPnpManagerRelease(struct HdfDeviceObject * device)99 static void UsbPnpManagerRelease(struct HdfDeviceObject *device)
100 {
101     if (device == NULL) {
102         dprintf("%s: device is null\n", __func__);
103         return;
104     }
105 
106     dprintf("%s:%d release success\n", __func__, __LINE__);
107 
108     return;
109 }
110 
111 struct HdfDriverEntry g_usbPnpManagerEntry = {
112     .moduleVersion = 1,
113     .Bind = UsbPnpManagerBind,
114     .Init = UsbPnpManagerInit,
115     .Release = UsbPnpManagerRelease,
116     .moduleName = "HDF_USB_PNP_MANAGER",
117 };
118 
119 HDF_INIT(g_usbPnpManagerEntry);
120 
121