Mercurial > hg > ucis.core
annotate USBLib/Internal/Windows/UsbApi.cs @ 63:309c705d7460
Updates and cleanup in Windows USB enumeration code
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Sun, 13 Oct 2013 18:43:45 +0200 |
parents | edc41c861d96 |
children | e811297f5aa4 |
rev | line source |
---|---|
21 | 1 using System; |
2 using System.Runtime.InteropServices; | |
62
edc41c861d96
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
58
diff
changeset
|
3 using UCIS.USBLib.Communication; |
edc41c861d96
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
58
diff
changeset
|
4 using UCIS.USBLib.Communication.WinUsb; |
edc41c861d96
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
58
diff
changeset
|
5 using UCIS.USBLib.Descriptor; |
21 | 6 |
7 namespace UCIS.USBLib.Internal.Windows { | |
8 class UsbApi { | |
9 public const int IOCTL_GET_HCD_DRIVERKEY_NAME = 0x220424; | |
10 public const int IOCTL_USB_GET_ROOT_HUB_NAME = 0x220408; | |
11 public const int IOCTL_USB_GET_NODE_INFORMATION = 0x220408; | |
12 public const int IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX = 0x220448; | |
13 public const int IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION = 0x220410; | |
14 public const int IOCTL_USB_GET_NODE_CONNECTION_NAME = 0x220414; | |
15 public const int IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME = 0x220420; | |
16 public const int IOCTL_STORAGE_GET_DEVICE_NUMBER = 0x2D1080; | |
17 | |
18 public const string GUID_DEVINTERFACE_USB_HOST_CONTROLLER = "{3ABF6F2D-71C4-462A-8A92-1E6861E6AF27}"; | |
19 public const string GUID_DEVINTERFACE_USB_HUB = "{F18A0E88-C30C-11D0-8815-00A0C906BED8}"; | |
20 public const string GUID_DEVINTERFACE_USB_DEVICE = "{A5DCBF10-6530-11D2-901F-00C04FB951ED}"; | |
21 | |
22 public const int MAX_BUFFER_SIZE = 2048; | |
23 public const int DIF_PROPERTYCHANGE = 0x00000012; | |
24 public const int DICS_FLAG_GLOBAL = 0x00000001; | |
25 | |
26 public const int DICS_ENABLE = 0x00000001; | |
27 public const int DICS_DISABLE = 0x00000002; | |
28 } | |
29 | |
30 enum UsbDeviceClass : byte { | |
31 UnspecifiedDevice = 0x00, | |
32 AudioInterface = 0x01, | |
33 CommunicationsAndCDCControlBoth = 0x02, | |
34 HIDInterface = 0x03, | |
35 PhysicalInterfaceDevice = 0x5, | |
36 ImageInterface = 0x06, | |
37 PrinterInterface = 0x07, | |
38 MassStorageInterface = 0x08, | |
39 HubDevice = 0x09, | |
40 CDCDataInterface = 0x0A, | |
41 SmartCardInterface = 0x0B, | |
42 ContentSecurityInterface = 0x0D, | |
43 VidioInterface = 0x0E, | |
44 PersonalHeathcareInterface = 0x0F, | |
45 DiagnosticDeviceBoth = 0xDC, | |
46 WirelessControllerInterface = 0xE0, | |
47 MiscellaneousBoth = 0xEF, | |
48 ApplicationSpecificInterface = 0xFE, | |
49 VendorSpecificBoth = 0xFF | |
50 } | |
51 | |
52 enum HubCharacteristics : byte { | |
53 GangedPowerSwitching = 0x00, | |
54 IndividualPotPowerSwitching = 0x01, | |
55 } | |
56 | |
57 enum USB_CONNECTION_STATUS : int { | |
58 NoDeviceConnected, | |
59 DeviceConnected, | |
60 DeviceFailedEnumeration, | |
61 DeviceGeneralFailure, | |
62 DeviceCausedOvercurrent, | |
63 DeviceNotEnoughPower, | |
64 DeviceNotEnoughBandwidth, | |
65 DeviceHubNestedTooDeeply, | |
66 DeviceInLegacyHub | |
67 } | |
68 | |
69 enum USB_DEVICE_SPEED : byte { | |
70 UsbLowSpeed = 0, | |
71 UsbFullSpeed, | |
72 UsbHighSpeed | |
73 } | |
74 | |
75 [Flags] | |
76 enum DeviceInterfaceDataFlags : uint { | |
77 Unknown = 0x00000000, | |
78 Active = 0x00000001, | |
79 Default = 0x00000002, | |
80 Removed = 0x00000004 | |
81 } | |
82 | |
83 [Flags] | |
84 enum HubPortStatus : short { | |
85 Connection = 0x0001, | |
86 Enabled = 0x0002, | |
87 Suspend = 0x0004, | |
88 OverCurrent = 0x0008, | |
89 BeingReset = 0x0010, | |
90 Power = 0x0100, | |
91 LowSpeed = 0x0200, | |
92 HighSpeed = 0x0400, | |
93 TestMode = 0x0800, | |
94 Indicator = 0x1000, | |
95 } | |
96 | |
97 enum HubStatus : byte { | |
98 LocalPowerStatus = 1, | |
99 OverCurrentIndicator = 2, | |
100 LocalPowerStatusChange = 1, | |
101 OverCurrentIndicatorChange = 2 | |
102 } | |
103 | |
104 enum PortIndicatorSlectors : byte { | |
105 IndicatorAutomatic = 0, | |
106 IndicatorAmber, | |
107 IndicatorGreen, | |
108 IndicatorOff | |
109 } | |
110 | |
111 enum PowerSwitching : byte { | |
112 SupportsGangPower = 0, | |
113 SupportsIndividualPortPower = 1, | |
114 SetPowerOff = 0, | |
115 SetPowerOn = 1 | |
116 } | |
117 | |
118 [StructLayout(LayoutKind.Sequential)] | |
119 struct SP_CLASSINSTALL_HEADER { | |
120 public int cbSize; | |
121 public int InstallFunction; //DI_FUNCTION InstallFunction; | |
122 } | |
123 | |
124 [StructLayout(LayoutKind.Sequential)] | |
125 struct SP_PROPCHANGE_PARAMS { | |
126 public SP_CLASSINSTALL_HEADER ClassInstallHeader; | |
127 public int StateChange; | |
128 public int Scope; | |
129 public int HwProfile; | |
130 } | |
131 | |
63
309c705d7460
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
62
diff
changeset
|
132 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] |
21 | 133 struct USB_HCD_DRIVERKEY_NAME { |
63
309c705d7460
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
62
diff
changeset
|
134 public UInt32 ActualLength; |
21 | 135 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = UsbApi.MAX_BUFFER_SIZE)] |
63
309c705d7460
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
62
diff
changeset
|
136 public String DriverKeyName; |
21 | 137 } |
138 | |
63
309c705d7460
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
62
diff
changeset
|
139 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] |
21 | 140 struct USB_ROOT_HUB_NAME { |
63
309c705d7460
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
62
diff
changeset
|
141 public UInt32 ActualLength; |
21 | 142 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = UsbApi.MAX_BUFFER_SIZE)] |
63
309c705d7460
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
62
diff
changeset
|
143 public String RootHubName; |
21 | 144 } |
145 | |
146 [StructLayout(LayoutKind.Sequential, Pack = 1)] | |
147 struct USB_HUB_DESCRIPTOR { | |
148 public byte bDescriptorLength; | |
62
edc41c861d96
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
58
diff
changeset
|
149 public UsbDescriptorType bDescriptorType; |
21 | 150 public byte bNumberOfPorts; |
151 public ushort wHubCharacteristics; | |
152 public byte bPowerOnToPowerGood; | |
153 public byte bHubControlCurrent; | |
154 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] | |
155 public byte[] bRemoveAndPowerMask; //UCHAR bRemoveAndPowerMask[64]; | |
156 } | |
157 | |
158 [StructLayout(LayoutKind.Sequential)] | |
159 struct USB_HUB_INFORMATION { | |
160 public USB_HUB_DESCRIPTOR HubDescriptor; | |
161 public bool HubIsBusPowered; | |
162 } | |
163 | |
164 [StructLayout(LayoutKind.Sequential)] | |
165 struct USB_NODE_INFORMATION { | |
63
309c705d7460
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
62
diff
changeset
|
166 public int NodeType; |
309c705d7460
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
62
diff
changeset
|
167 public USB_HUB_INFORMATION HubInformation; |
21 | 168 } |
169 | |
170 [StructLayout(LayoutKind.Sequential, Pack = 1)] | |
171 struct USB_NODE_CONNECTION_INFORMATION_EX { | |
172 public uint ConnectionIndex; | |
62
edc41c861d96
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
58
diff
changeset
|
173 public UsbDeviceDescriptor DeviceDescriptor; |
21 | 174 public byte CurrentConfigurationValue; |
175 public USB_DEVICE_SPEED Speed; | |
176 public byte DeviceIsHub; //BOOLEAN DeviceIsHub; | |
177 public ushort DeviceAddress; | |
178 public uint NumberOfOpenPipes; | |
179 public USB_CONNECTION_STATUS ConnectionStatus; | |
180 //public IntPtr PipeList; //USB_PIPE_INFO PipeList[0]; | |
181 //[MarshalAs(UnmanagedType.ByValArray, SizeConst=100)] | |
182 //Byte[] PipeList; | |
183 } | |
184 | |
185 [StructLayout(LayoutKind.Sequential)] | |
186 struct HID_DESCRIPTOR_DESC_LIST { | |
187 public byte bReportType; | |
188 public short wReportLength; | |
189 } | |
190 | |
191 [StructLayout(LayoutKind.Sequential, Pack = 1)] | |
192 struct HID_DESCRIPTOR { | |
193 public byte bLength; | |
62
edc41c861d96
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
58
diff
changeset
|
194 public UsbDescriptorType bDescriptorType; |
21 | 195 public ushort bcdHID; |
196 public byte bCountry; | |
197 public byte bNumDescriptors; | |
198 public HID_DESCRIPTOR_DESC_LIST hid_desclist; //DescriptorList [1]; | |
199 } | |
200 | |
62
edc41c861d96
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
58
diff
changeset
|
201 [StructLayout(LayoutKind.Sequential, Pack = 8)] |
21 | 202 struct USB_DESCRIPTOR_REQUEST { |
203 public uint ConnectionIndex; | |
62
edc41c861d96
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
58
diff
changeset
|
204 public UsbSetupPacket SetupPacket; |
21 | 205 //public byte[] Data; //UCHAR Data[0]; |
206 } | |
207 | |
58
fd63c453ff65
Improved Windows USB enumeration classes
Ivo Smits <Ivo@UCIS.nl>
parents:
21
diff
changeset
|
208 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] |
21 | 209 struct USB_NODE_CONNECTION_NAME { |
210 public uint ConnectionIndex; | |
211 public uint ActualLength; | |
212 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = UsbApi.MAX_BUFFER_SIZE)] | |
63
309c705d7460
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
62
diff
changeset
|
213 public string NodeName; |
21 | 214 } |
215 | |
58
fd63c453ff65
Improved Windows USB enumeration classes
Ivo Smits <Ivo@UCIS.nl>
parents:
21
diff
changeset
|
216 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] |
21 | 217 struct USB_NODE_CONNECTION_DRIVERKEY_NAME { |
218 public uint ConnectionIndex; | |
219 public uint ActualLength; | |
220 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = UsbApi.MAX_BUFFER_SIZE)] | |
63
309c705d7460
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
62
diff
changeset
|
221 public string DriverKeyName; |
21 | 222 } |
223 | |
224 [StructLayout(LayoutKind.Sequential)] | |
225 struct STORAGE_DEVICE_NUMBER { | |
226 public int DeviceType; //DEVICE_TYPE DeviceType; | |
227 public uint DeviceNumber; | |
228 public uint PartitionNumber; | |
229 } | |
62
edc41c861d96
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
58
diff
changeset
|
230 } |