-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathusb_enumer.h
93 lines (84 loc) · 3.43 KB
/
usb_enumer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once
#include "tinyxml\tinyxml.h"
/*
typedef struct _STRING_DESCRIPTOR_NODE
{
struct _STRING_DESCRIPTOR_NODE *Next;
UCHAR DescriptorIndex;
USHORT LanguageID;
USB_STRING_DESCRIPTOR StringDescriptor[1];
} StringDescriptorNode, *PStringDescriptorNode;
*/
struct UsbDevicePnpStrings
{
CString sDeviceInstanceId;
CString sDeviceDesc;
CString sHardwareId;
CString sService;
CString sDeviceClass;
};
typedef enum _TREEICON
{
ComputerIcon,
HubIcon,
NoDeviceIcon,
GoodDeviceIcon,
BadDeviceIcon,
GoodSsDeviceIcon,
NoSsDeviceIcon
} TREEICON;
class CUsbEnumer
{
private:
TiXmlDocument* m_pXmlDoc;
public:
CUsbEnumer();
void EnumAllUsbDevices();
TiXmlDocument* GetEnumResult() const;
void ClearEnumResult();
private:
/**
* 枚举分为4块:
* 首先枚举所有的usb host controller,对应_EnumHostControllers()函数
* 对某个具体的usb host controller进行枚举,对应_EnumHostController()函数.
* 枚举usb host controller时,其实是对其hub口进行枚举,对应_EnumHub()函数
* 枚举hub上的各个port,对应函数_EnumHubPorts()
*
* 一台计算机上有多个usb host controller.
* 一个usb host controller上有一个root hub.
* 一个root hub上拓展出若干个port口.
* 一个port口上,可能插了hub,也可能插了具体设备(如手机),也可能什么都没插.
*/
VOID _EnumHostControllers(TiXmlElement* pXmlConputer);
VOID _EnumHostController(HANDLE hHCDev, HDEVINFO deviceInfo, PSP_DEVINFO_DATA deviceInfoData, TiXmlElement* pXmlHostController);
VOID _EnumHub(const CString& sHubName, TiXmlElement* pXmlFather);
VOID _EnumHubPorts(HANDLE hHubDevice, ULONG NumPorts, TiXmlElement* pXmlFather);
private:
PUSB_DESCRIPTOR_REQUEST _GetConfigDescriptor(HANDLE hHubDevice, ULONG ConnectionIndex, UCHAR DescriptorIndex);
BOOL IsAdbDevice(const CString& sFatherHubName, int nPortNum);
PUSB_COMMON_DESCRIPTOR _GetNextDescriptor(
_In_reads_bytes_(TotalLength) PUSB_COMMON_DESCRIPTOR FirstDescriptor,
_In_ ULONG TotalLength,
_In_ PUSB_COMMON_DESCRIPTOR StartDescriptor,
_In_ long DescriptorType
);
PUSB_COMMON_DESCRIPTOR _NextDescriptor(_In_ PUSB_COMMON_DESCRIPTOR Descriptor);
void _MyReadUsbDescriptorRequest(PUSB_DESCRIPTOR_REQUEST pRequest, BOOL& bFindInterface0xff42);
void _ParsepUsbDescriptorRequest( PUSB_DESCRIPTOR_REQUEST pRequest, TiXmlElement* pXmlFather);
private:
// 如:"\\?\pci#ven_8086&dev_1e26&subsys_05771028&rev_04#3&11583659&1&e8#{3abf6f2d-71c4-462a-8a92-1e6861e6af27}"
CString _GetDevPath( HDEVINFO hDevInfo, SP_DEVICE_INTERFACE_DATA stDeviceInterfaceData );
CString _GetRootHubName(HANDLE hHostController);
CString _GetExternalHubName(HANDLE Hub, ULONG ConnectionIndex);
CString _GetHCDDriverKeyName(HANDLE hHCDev);
CString _GetDriverKeyName(HANDLE Hub, ULONG ConnectionIndex); // 如:"{36fc9e60-c465-11cf-8056-444553540000}\0006"
CString _GetDeviceProperty(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, DWORD Property);
BOOL _DriverNameToDeviceProperties(const CString& sDrvKeyName, UsbDevicePnpStrings& stPnpStrings);
void _GetConnInfo(
ULONG ulConnectionIndex,
HANDLE hHubDevice,
PUSB_NODE_CONNECTION_INFORMATION_EX* ppConnInfoEx,
PUSB_NODE_CONNECTION_INFORMATION_EX_V2* ppConnInfoExV2
);
HDEVINFO _DriverNameToDeviceInst(const CString& sDrvKeyName, SP_DEVINFO_DATA& stDevInfoData);
};