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 #ifndef LITEOS_USB_PNP_NOTIFY_H
32 #define LITEOS_USB_PNP_NOTIFY_H
33 
34 #include "hdf_base.h"
35 #include "hdf_dlist.h"
36 #include "hdf_usb_pnp_manage.h"
37 #include "osal_mutex.h"
38 
39 #ifdef __cplusplus
40 #if __cplusplus
41 extern "C" {
42 #endif
43 #endif /* __cplusplus */
44 
45 #define USB_PNP_LOADER_SERVICE_NAME         "hdf_usb_pnp_manager_service"
46 
47 #define USB_PNP_INTERFACE_MSLEEP_TIME       (200)
48 #define USB_PNP_NOTIFY_MSLEEP_TIME          (10)
49 #define USB_PNP_NOTIFY_REPORT_STACK_SIZE    (10000)
50 
51 #ifndef INT32_MAX
52 #define INT32_MAX 0x7fffffff
53 #endif
54 
55 typedef enum {
56     USB_INFO_NORMAL_TYPE,
57     USB_INFO_ID_TYPE,
58     USB_INFO_DEVICE_ADDRESS_TYPE,
59 } UsbInfoQueryParaType;
60 
61 typedef enum {
62     USB_PNP_DEVICE_INIT_STATUS,
63     USB_PNP_DEVICE_ADD_STATUS,
64     USB_PNP_DEVICE_REMOVE_STATUS,
65     USB_PNP_DEVICE_INTERFACE_STATUS,
66 } UsbPnpDeviceStatus;
67 
68 typedef enum {
69     USB_PNP_DEVICE_ADDRESS_TYPE,
70     USB_PNP_DEVICE_VENDOR_PRODUCT_TYPE,
71 } UsbPnpDeviceParaType;
72 
73 struct UsbPnpDeviceInfo {
74     int32_t id;
75     struct OsalMutex lock;
76     UsbPnpDeviceStatus status;
77     struct DListHead list;
78     bool interfaceRemoveStatus[USB_PNP_INFO_MAX_INTERFACES];
79     struct UsbPnpNotifyMatchInfoTable info;
80 };
81 
82 struct UsbInfoQueryPara {
83     UsbInfoQueryParaType type;
84     union {
85         int32_t id;
86         uint64_t usbDevAddr;
87         struct {
88             int32_t devNum;
89             int32_t busNum;
90         };
91     };
92 };
93 
94 union UsbPnpDeviceInfoData {
95     struct usb_device *usbDev;
96     struct UsbPnpAddRemoveInfo *infoData;
97 };
98 
99 struct UsbPnpNotifyDeviceList {
100     struct usb_device *device;
101     struct DListHead deviceList;
102 };
103 
104 struct UsbGetDevicePara {
105     UsbPnpDeviceParaType type;
106     union {
107         struct {
108             uint8_t busNum;
109             uint8_t devNum;
110         };
111         struct {
112             uint16_t vendorId;
113             uint16_t productId;
114         };
115     };
116 };
117 
118 void UsbPnpNotifyDevice(const char *type, struct usb_device *udev);
119 struct usb_device *UsbPnpNotifyGetUsbDevice(struct UsbGetDevicePara paraData);
120 
121 #ifdef __cplusplus
122 #if __cplusplus
123 }
124 #endif
125 #endif /* __cplusplus */
126 
127 #endif /* LITEOS_USB_PNP_NOTIFY_H */
128