1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef HDF_USB_PNP_MANAGE_H
10 #define HDF_USB_PNP_MANAGE_H
11 
12 #include "hdf_base.h"
13 
14 #define USB_PNP_NOTIFY_TEST_MODE        false
15 #define USB_PNP_INFO_MAX_INTERFACES     32
16 
17 enum UsbPnpNotifyServiceCmd {
18     USB_PNP_NOTIFY_ADD_INTERFACE,
19     USB_PNP_NOTIFY_REMOVE_INTERFACE,
20     USB_PNP_NOTIFY_REPORT_INTERFACE,
21     USB_PNP_NOTIFY_ADD_DEVICE,
22     USB_PNP_NOTIFY_REMOVE_DEVICE,
23     #if USB_PNP_NOTIFY_TEST_MODE == true
24     USB_PNP_NOTIFY_ADD_TEST,
25     USB_PNP_NOTIFY_REMOVE_TEST,
26     #endif
27     USB_PNP_DRIVER_REGISTER_DEVICE,
28     USB_PNP_DRIVER_UNREGISTER_DEVICE,
29     USB_PNP_DRIVER_GETDEVICES = 20,
30     USB_PNP_DRIVER_GADGET_ADD = 30,
31     USB_PNP_DRIVER_GADGET_REMOVE,
32     USB_PNP_DRIVER_PORT_HOST = 40,
33     USB_PNP_DRIVER_PORT_DEVICE,
34     USB_PNP_DRIVER_GET_GADGET_LINK_STATUS,
35     USB_ACCESSORY_START = 50,
36     USB_ACCESSORY_STOP,
37     USB_ACCESSORY_SEND
38 };
39 
40 enum UsbPnpNotifyRemoveType {
41     USB_PNP_NOTIFY_REMOVE_BUS_DEV_NUM,
42     USB_PNP_NOTIFY_REMOVE_INTERFACE_NUM,
43 };
44 
45 enum {
46     USB_PNP_NOTIFY_MATCH_VENDOR = 0x0001,
47     USB_PNP_NOTIFY_MATCH_PRODUCT = 0x0002,
48     USB_PNP_NOTIFY_MATCH_DEV_LOW = 0x0004,
49     USB_PNP_NOTIFY_MATCH_DEV_HIGH = 0x0008,
50     USB_PNP_NOTIFY_MATCH_DEV_CLASS = 0x0010,
51     USB_PNP_NOTIFY_MATCH_DEV_SUBCLASS = 0x0020,
52     USB_PNP_NOTIFY_MATCH_DEV_PROTOCOL = 0x0040,
53     USB_PNP_NOTIFY_MATCH_INT_CLASS = 0x0080,
54     USB_PNP_NOTIFY_MATCH_INT_SUBCLASS = 0x0100,
55     USB_PNP_NOTIFY_MATCH_INT_PROTOCOL = 0x0200,
56     USB_PNP_NOTIFY_MATCH_INT_NUMBER = 0x0400,
57 };
58 
59 struct UsbPnpNotifyServiceInfo {
60     uint8_t curInterfaceNumber;
61     uint32_t length;
62 
63     int32_t devNum;
64     int32_t busNum;
65 
66     int32_t interfaceLength;
67     uint8_t interfaceNumber[USB_PNP_INFO_MAX_INTERFACES];
68 } __attribute__ ((packed));
69 
70 struct UsbPnpNotifyInterfaceInfo {
71     uint8_t interfaceClass;
72     uint8_t interfaceSubClass;
73     uint8_t interfaceProtocol;
74 
75     uint8_t interfaceNumber;
76 };
77 
78 struct UsbPnpNotifyDeviceInfo {
79     uint16_t vendorId;
80     uint16_t productId;
81 
82     uint16_t bcdDeviceLow;
83     uint16_t bcdDeviceHigh;
84 
85     uint8_t deviceClass;
86     uint8_t deviceSubClass;
87     uint8_t deviceProtocol;
88 };
89 
90 struct UsbPnpNotifyMatchInfoTable {
91     uint64_t usbDevAddr;
92     int32_t devNum;
93     int32_t busNum;
94 
95     struct UsbPnpNotifyDeviceInfo deviceInfo;
96 
97     uint8_t removeType;
98     uint8_t numInfos;
99 
100     struct UsbPnpNotifyInterfaceInfo interfaceInfo[USB_PNP_INFO_MAX_INTERFACES];
101 };
102 
103 struct UsbPnpAddRemoveInfo {
104     int32_t devNum;
105     int32_t busNum;
106     uint8_t interfaceNumber;
107     uint8_t interfaceClass;
108     uint8_t interfaceSubClass;
109     uint8_t interfaceProtocol;
110 };
111 
112 #endif /* HDF_USB_PNP_MANAGE_H */
113