Mercurial > hg > ucis.core
annotate USBLib/Internal/Windows/UsbApi.cs @ 111:df53bdd49507 default tip
Merge
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Fri, 07 Nov 2014 18:37:39 +0100 |
parents | e811297f5aa4 |
children |
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 HubCharacteristics : byte { | |
31 GangedPowerSwitching = 0x00, | |
32 IndividualPotPowerSwitching = 0x01, | |
33 } | |
34 | |
35 enum USB_CONNECTION_STATUS : int { | |
36 NoDeviceConnected, | |
37 DeviceConnected, | |
38 DeviceFailedEnumeration, | |
39 DeviceGeneralFailure, | |
40 DeviceCausedOvercurrent, | |
41 DeviceNotEnoughPower, | |
42 DeviceNotEnoughBandwidth, | |
43 DeviceHubNestedTooDeeply, | |
44 DeviceInLegacyHub | |
45 } | |
46 | |
47 enum USB_DEVICE_SPEED : byte { | |
48 UsbLowSpeed = 0, | |
49 UsbFullSpeed, | |
50 UsbHighSpeed | |
51 } | |
52 | |
53 [Flags] | |
54 enum DeviceInterfaceDataFlags : uint { | |
55 Unknown = 0x00000000, | |
56 Active = 0x00000001, | |
57 Default = 0x00000002, | |
58 Removed = 0x00000004 | |
59 } | |
60 | |
61 [Flags] | |
62 enum HubPortStatus : short { | |
63 Connection = 0x0001, | |
64 Enabled = 0x0002, | |
65 Suspend = 0x0004, | |
66 OverCurrent = 0x0008, | |
67 BeingReset = 0x0010, | |
68 Power = 0x0100, | |
69 LowSpeed = 0x0200, | |
70 HighSpeed = 0x0400, | |
71 TestMode = 0x0800, | |
72 Indicator = 0x1000, | |
73 } | |
74 | |
75 enum HubStatus : byte { | |
76 LocalPowerStatus = 1, | |
77 OverCurrentIndicator = 2, | |
78 LocalPowerStatusChange = 1, | |
79 OverCurrentIndicatorChange = 2 | |
80 } | |
81 | |
82 enum PortIndicatorSlectors : byte { | |
83 IndicatorAutomatic = 0, | |
84 IndicatorAmber, | |
85 IndicatorGreen, | |
86 IndicatorOff | |
87 } | |
88 | |
89 enum PowerSwitching : byte { | |
90 SupportsGangPower = 0, | |
91 SupportsIndividualPortPower = 1, | |
92 SetPowerOff = 0, | |
93 SetPowerOn = 1 | |
94 } | |
95 | |
96 [StructLayout(LayoutKind.Sequential)] | |
97 struct SP_CLASSINSTALL_HEADER { | |
98 public int cbSize; | |
99 public int InstallFunction; //DI_FUNCTION InstallFunction; | |
100 } | |
101 | |
102 [StructLayout(LayoutKind.Sequential)] | |
103 struct SP_PROPCHANGE_PARAMS { | |
104 public SP_CLASSINSTALL_HEADER ClassInstallHeader; | |
105 public int StateChange; | |
106 public int Scope; | |
107 public int HwProfile; | |
108 } | |
109 | |
63
309c705d7460
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
62
diff
changeset
|
110 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] |
21 | 111 struct USB_HCD_DRIVERKEY_NAME { |
63
309c705d7460
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
62
diff
changeset
|
112 public UInt32 ActualLength; |
21 | 113 [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
|
114 public String DriverKeyName; |
21 | 115 } |
116 | |
63
309c705d7460
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
62
diff
changeset
|
117 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] |
21 | 118 struct USB_ROOT_HUB_NAME { |
63
309c705d7460
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
62
diff
changeset
|
119 public UInt32 ActualLength; |
21 | 120 [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
|
121 public String RootHubName; |
21 | 122 } |
123 | |
124 [StructLayout(LayoutKind.Sequential, Pack = 1)] | |
125 struct USB_HUB_DESCRIPTOR { | |
126 public byte bDescriptorLength; | |
62
edc41c861d96
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
58
diff
changeset
|
127 public UsbDescriptorType bDescriptorType; |
21 | 128 public byte bNumberOfPorts; |
129 public ushort wHubCharacteristics; | |
130 public byte bPowerOnToPowerGood; | |
131 public byte bHubControlCurrent; | |
132 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] | |
133 public byte[] bRemoveAndPowerMask; //UCHAR bRemoveAndPowerMask[64]; | |
134 } | |
135 | |
136 [StructLayout(LayoutKind.Sequential)] | |
137 struct USB_HUB_INFORMATION { | |
138 public USB_HUB_DESCRIPTOR HubDescriptor; | |
139 public bool HubIsBusPowered; | |
140 } | |
141 | |
142 [StructLayout(LayoutKind.Sequential)] | |
143 struct USB_NODE_INFORMATION { | |
63
309c705d7460
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
62
diff
changeset
|
144 public int NodeType; |
309c705d7460
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
62
diff
changeset
|
145 public USB_HUB_INFORMATION HubInformation; |
21 | 146 } |
147 | |
148 [StructLayout(LayoutKind.Sequential, Pack = 1)] | |
149 struct USB_NODE_CONNECTION_INFORMATION_EX { | |
150 public uint ConnectionIndex; | |
62
edc41c861d96
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
58
diff
changeset
|
151 public UsbDeviceDescriptor DeviceDescriptor; |
21 | 152 public byte CurrentConfigurationValue; |
153 public USB_DEVICE_SPEED Speed; | |
154 public byte DeviceIsHub; //BOOLEAN DeviceIsHub; | |
155 public ushort DeviceAddress; | |
156 public uint NumberOfOpenPipes; | |
157 public USB_CONNECTION_STATUS ConnectionStatus; | |
158 //public IntPtr PipeList; //USB_PIPE_INFO PipeList[0]; | |
159 //[MarshalAs(UnmanagedType.ByValArray, SizeConst=100)] | |
160 //Byte[] PipeList; | |
161 } | |
162 | |
163 [StructLayout(LayoutKind.Sequential)] | |
164 struct HID_DESCRIPTOR_DESC_LIST { | |
165 public byte bReportType; | |
166 public short wReportLength; | |
167 } | |
168 | |
169 [StructLayout(LayoutKind.Sequential, Pack = 1)] | |
170 struct HID_DESCRIPTOR { | |
171 public byte bLength; | |
62
edc41c861d96
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
58
diff
changeset
|
172 public UsbDescriptorType bDescriptorType; |
21 | 173 public ushort bcdHID; |
174 public byte bCountry; | |
175 public byte bNumDescriptors; | |
176 public HID_DESCRIPTOR_DESC_LIST hid_desclist; //DescriptorList [1]; | |
177 } | |
178 | |
62
edc41c861d96
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
58
diff
changeset
|
179 [StructLayout(LayoutKind.Sequential, Pack = 8)] |
21 | 180 struct USB_DESCRIPTOR_REQUEST { |
181 public uint ConnectionIndex; | |
62
edc41c861d96
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
58
diff
changeset
|
182 public UsbSetupPacket SetupPacket; |
21 | 183 //public byte[] Data; //UCHAR Data[0]; |
184 } | |
185 | |
58
fd63c453ff65
Improved Windows USB enumeration classes
Ivo Smits <Ivo@UCIS.nl>
parents:
21
diff
changeset
|
186 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] |
21 | 187 struct USB_NODE_CONNECTION_NAME { |
188 public uint ConnectionIndex; | |
189 public uint ActualLength; | |
190 [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
|
191 public string NodeName; |
21 | 192 } |
193 | |
58
fd63c453ff65
Improved Windows USB enumeration classes
Ivo Smits <Ivo@UCIS.nl>
parents:
21
diff
changeset
|
194 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] |
21 | 195 struct USB_NODE_CONNECTION_DRIVERKEY_NAME { |
196 public uint ConnectionIndex; | |
197 public uint ActualLength; | |
198 [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
|
199 public string DriverKeyName; |
21 | 200 } |
201 | |
202 [StructLayout(LayoutKind.Sequential)] | |
203 struct STORAGE_DEVICE_NUMBER { | |
204 public int DeviceType; //DEVICE_TYPE DeviceType; | |
205 public uint DeviceNumber; | |
206 public uint PartitionNumber; | |
207 } | |
62
edc41c861d96
Updates and cleanup in Windows USB enumeration code
Ivo Smits <Ivo@UCIS.nl>
parents:
58
diff
changeset
|
208 } |