Mercurial > hg > ucis.core
annotate USBLib/Descriptor/UsbDescriptor.cs @ 111:df53bdd49507 default tip
Merge
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Fri, 07 Nov 2014 18:37:39 +0100 |
parents | 94df2951d118 |
children |
rev | line source |
---|---|
21 | 1 ???using System; |
22 | 2 using System.Runtime.InteropServices; |
21 | 3 using System.Text; |
4 using UCIS.USBLib.Communication; | |
68
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
5 using UCIS.Util; |
21 | 6 |
7 namespace UCIS.USBLib.Descriptor { | |
68
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
8 public struct UsbDescriptorBlob { |
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
9 public UsbDescriptorBlob(ArraySegment<Byte> data) : this() { this.Data = data; } |
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
10 public UsbDescriptorBlob(Byte[] data) : this() { this.Data = new ArraySegment<byte>(data); } |
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
11 public UsbDescriptorBlob(Byte[] data, int offset) : this() { this.Data = new ArraySegment<byte>(data, offset, data[offset + 0]); } |
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
12 public ArraySegment<Byte> Data { get; private set; } |
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
13 public Byte Length { get { return Data.Array[Data.Offset + 0]; } } |
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
14 public UsbDescriptorType Type { get { return (UsbDescriptorType)Data.Array[Data.Offset + 1]; } } |
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
15 public Byte[] GetBytes() { return ArrayUtil.ToArray(Data); } |
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
16 public static explicit operator UsbDescriptor(UsbDescriptorBlob self) { return UsbDescriptor.FromByteArray(self.Data.Array, self.Data.Offset, self.Data.Count); } |
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
17 public static explicit operator UsbDeviceDescriptor(UsbDescriptorBlob self) { return UsbDeviceDescriptor.FromByteArray(self.Data.Array, self.Data.Offset, self.Data.Count); } |
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
18 public static explicit operator UsbConfigurationDescriptor(UsbDescriptorBlob self) { return UsbConfigurationDescriptor.FromByteArray(self.Data.Array, self.Data.Offset, self.Data.Count); } |
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
19 public static explicit operator UsbInterfaceDescriptor(UsbDescriptorBlob self) { return UsbInterfaceDescriptor.FromByteArray(self.Data.Array, self.Data.Offset, self.Data.Count); } |
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
20 public static explicit operator UsbEndpointDescriptor(UsbDescriptorBlob self) { return UsbEndpointDescriptor.FromByteArray(self.Data.Array, self.Data.Offset, self.Data.Count); } |
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
21 public static explicit operator UsbHidDescriptor(UsbDescriptorBlob self) { return UsbHidDescriptor.FromByteArray(self.Data.Array, self.Data.Offset, self.Data.Count); } |
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
22 public static explicit operator UsbHubDescriptor(UsbDescriptorBlob self) { return UsbHubDescriptor.FromByteArray(self.Data.Array, self.Data.Offset, self.Data.Count); } |
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
23 } |
21 | 24 [StructLayout(LayoutKind.Sequential, Pack = 1)] |
25 public struct UsbDescriptor { | |
26 byte bmLength; | |
27 byte bType; | |
28 public Byte Length { get { return bmLength; } } | |
29 public UsbDescriptorType Type { get { return (UsbDescriptorType)bType; } } | |
30 internal static short FromLittleEndian(short value) { | |
31 if (BitConverter.IsLittleEndian) return value; | |
32 return (short)(((value & 0xFF) << 8) | ((value >> 8) & 0xFF)); | |
33 } | |
34 public unsafe static UsbDescriptor FromByteArray(Byte[] buffer, int offset, int length) { | |
35 if (length < Marshal.SizeOf(typeof(UsbDescriptor))) throw new ArgumentOutOfRangeException("length", "The data length is smaller than the descriptor length"); | |
36 if (offset < 0 || length < 0 || offset + length > buffer.Length) throw new ArgumentOutOfRangeException("length", "The specified offset and length exceed the buffer dimensions"); | |
37 fixed (Byte* ptr = buffer) return *(UsbDescriptor*)(ptr + offset); | |
38 } | |
39 } | |
40 [StructLayout(LayoutKind.Sequential, Pack = 1)] | |
41 public struct UsbStringDescriptor { | |
42 public static String GetString(Byte[] buffer, int offset, int length) { | |
43 if (length < 2) throw new ArgumentOutOfRangeException("length", "The data length is smaller than the descriptor length"); | |
44 if (offset < 0 || length < 0 || offset + length > buffer.Length) throw new ArgumentOutOfRangeException("length", "The specified offset and length exceed the buffer dimensions"); | |
45 if (buffer[offset + 1] != (Byte)UsbDescriptorType.String) throw new InvalidOperationException("The descriptor is not a string descriptor"); | |
46 int slen = buffer[offset]; | |
47 if (slen > length) throw new InvalidOperationException("The string has been truncated"); | |
48 return Encoding.Unicode.GetString(buffer, offset + 2, slen - 2); | |
49 } | |
47
15ddb1e0e2a5
USBLib: added convenience functions to retrieve descriptors from devices
Ivo Smits <Ivo@UCIS.nl>
parents:
22
diff
changeset
|
50 public static String GetStringFromDevice(IUsbInterface device, byte index, short langId) { |
96
94df2951d118
USBLib: fix USB string descriptor retrieval
Ivo Smits <Ivo@UCIS.nl>
parents:
68
diff
changeset
|
51 Byte[] buff = new Byte[255]; |
47
15ddb1e0e2a5
USBLib: added convenience functions to retrieve descriptors from devices
Ivo Smits <Ivo@UCIS.nl>
parents:
22
diff
changeset
|
52 int len = device.GetDescriptor((Byte)UsbDescriptorType.String, index, langId, buff, 0, buff.Length); |
58
fd63c453ff65
Improved Windows USB enumeration classes
Ivo Smits <Ivo@UCIS.nl>
parents:
47
diff
changeset
|
53 if (len == 0) return null; |
47
15ddb1e0e2a5
USBLib: added convenience functions to retrieve descriptors from devices
Ivo Smits <Ivo@UCIS.nl>
parents:
22
diff
changeset
|
54 return GetString(buff, 0, len); |
15ddb1e0e2a5
USBLib: added convenience functions to retrieve descriptors from devices
Ivo Smits <Ivo@UCIS.nl>
parents:
22
diff
changeset
|
55 } |
21 | 56 } |
57 [StructLayout(LayoutKind.Sequential, Pack = 1)] | |
58 public struct UsbDeviceDescriptor { | |
59 byte bmLength; | |
60 byte bType; | |
61 short bcdUSB; | |
62 byte bDeviceClass; | |
63 byte bDeviceSubClass; | |
64 byte bDeviceProtocol; | |
65 byte bMaxControlPacketSize; | |
66 short idVendor; | |
67 short idProduct; | |
68 short bcdDevice; | |
69 byte iManufacturer; | |
70 byte iProduct; | |
71 byte iSerialNumber; | |
72 byte numConfigurations; | |
73 public Byte Length { get { return bmLength; } } | |
74 public UsbDescriptorType Type { get { return (UsbDescriptorType)bType; }} | |
75 public short USBVersion { get { return UsbDescriptor.FromLittleEndian(bcdUSB); } } | |
68
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
76 public UsbClassCode DeviceClass { get { return (UsbClassCode)bDeviceClass; } } |
21 | 77 public Byte DeviceSubClass { get { return bDeviceSubClass; } } |
78 public Byte DeviceProtocol { get { return bDeviceProtocol; } } | |
64
99ed461509fe
Fixed data type for USB vendor and product IDs
Ivo Smits <Ivo@UCIS.nl>
parents:
58
diff
changeset
|
79 public UInt16 DeviceVersion { get { return (UInt16)UsbDescriptor.FromLittleEndian(bcdDevice); } } |
21 | 80 public Byte MaxControlPacketSize { get { return bMaxControlPacketSize; } } |
64
99ed461509fe
Fixed data type for USB vendor and product IDs
Ivo Smits <Ivo@UCIS.nl>
parents:
58
diff
changeset
|
81 public UInt16 VendorID { get { return (UInt16)UsbDescriptor.FromLittleEndian(idVendor); } } |
99ed461509fe
Fixed data type for USB vendor and product IDs
Ivo Smits <Ivo@UCIS.nl>
parents:
58
diff
changeset
|
82 public UInt16 ProductID { get { return (UInt16)UsbDescriptor.FromLittleEndian(idProduct); } } |
21 | 83 public Byte ManufacturerStringID { get { return iManufacturer; } } |
84 public Byte ProductStringID { get { return iProduct; } } | |
85 public Byte SerialNumberStringID { get { return iSerialNumber; } } | |
86 public Byte NumConfigurations { get { return numConfigurations; } } | |
68
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
87 public unsafe Byte[] GetBytes() { |
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
88 Byte[] buffer = new Byte[Size]; |
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
89 fixed (Byte* ptr = buffer) *(UsbDeviceDescriptor*)ptr = this; |
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
90 return buffer; |
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
91 } |
21 | 92 public unsafe static UsbDeviceDescriptor FromByteArray(Byte[] buffer, int offset, int length) { |
93 if (length < Size) throw new ArgumentOutOfRangeException("length", "The data length is smaller than the descriptor length"); | |
94 if (offset < 0 || length < 0 || offset + length > buffer.Length) throw new ArgumentOutOfRangeException("length", "The specified offset and length exceed the buffer dimensions"); | |
95 fixed (Byte* ptr = buffer) return *(UsbDeviceDescriptor*)(ptr + offset); | |
96 } | |
47
15ddb1e0e2a5
USBLib: added convenience functions to retrieve descriptors from devices
Ivo Smits <Ivo@UCIS.nl>
parents:
22
diff
changeset
|
97 public static UsbDeviceDescriptor FromDevice(IUsbInterface device) { |
68
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
98 Byte[] buff = new Byte[Size]; |
47
15ddb1e0e2a5
USBLib: added convenience functions to retrieve descriptors from devices
Ivo Smits <Ivo@UCIS.nl>
parents:
22
diff
changeset
|
99 int len = device.GetDescriptor((Byte)UsbDescriptorType.Device, 0, 0, buff, 0, buff.Length); |
68
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
100 if (len == 0) return new UsbDeviceDescriptor(); |
47
15ddb1e0e2a5
USBLib: added convenience functions to retrieve descriptors from devices
Ivo Smits <Ivo@UCIS.nl>
parents:
22
diff
changeset
|
101 return FromByteArray(buff, 0, len); |
15ddb1e0e2a5
USBLib: added convenience functions to retrieve descriptors from devices
Ivo Smits <Ivo@UCIS.nl>
parents:
22
diff
changeset
|
102 } |
21 | 103 public static unsafe int Size { get { return sizeof(UsbDeviceDescriptor); } } |
104 } | |
105 [StructLayout(LayoutKind.Sequential, Pack = 1)] | |
106 public struct UsbConfigurationDescriptor { | |
107 byte bmLength; | |
108 byte bType; | |
109 short wTotalLength; | |
110 byte bNumInterfaces; | |
111 byte bConfigurationValue; | |
112 byte bConfigurationStringID; | |
113 byte bmAttributes; | |
114 byte bMaxPower; | |
115 public Byte Length { get { return bmLength; } } | |
116 public UsbDescriptorType Type { get { return (UsbDescriptorType)bType; } } | |
117 public short TotalLength { get { return UsbDescriptor.FromLittleEndian(wTotalLength); } } | |
118 public Byte NumInterfaces { get { return bNumInterfaces; } } | |
119 public Byte ConfigurationValue { get { return bConfigurationValue; } } | |
120 public Byte ConfigurationStringID { get { return bConfigurationStringID; } } | |
121 public Boolean SelfPowered { get { return 0 != (bmAttributes & (1 << 6)); } } | |
122 public Boolean RemoteWakeup { get { return 0 != (bmAttributes & (1 << 5)); } } | |
123 public int MaxPowerMA { get { return bMaxPower * 2; } } | |
124 public unsafe static UsbConfigurationDescriptor FromByteArray(Byte[] buffer, int offset, int length) { | |
125 if (length < Size) throw new ArgumentOutOfRangeException("length", "The data length is smaller than the descriptor length"); | |
126 if (offset < 0 || length < 0 || offset + length > buffer.Length) throw new ArgumentOutOfRangeException("length", "The specified offset and length exceed the buffer dimensions"); | |
127 fixed (Byte* ptr = buffer) return *(UsbConfigurationDescriptor*)(ptr + offset); | |
128 } | |
65
abe0d55a2201
Removed some redundant USB communication code
Ivo Smits <Ivo@UCIS.nl>
parents:
64
diff
changeset
|
129 public static UsbConfigurationDescriptor FromDevice(IUsbInterface device, Byte index) { |
abe0d55a2201
Removed some redundant USB communication code
Ivo Smits <Ivo@UCIS.nl>
parents:
64
diff
changeset
|
130 Byte[] buff = new Byte[UsbConfigurationDescriptor.Size]; |
abe0d55a2201
Removed some redundant USB communication code
Ivo Smits <Ivo@UCIS.nl>
parents:
64
diff
changeset
|
131 int len = device.GetDescriptor((Byte)UsbDescriptorType.Configuration, index, 0, buff, 0, buff.Length); |
68
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
132 if (len == 0) return new UsbConfigurationDescriptor(); |
65
abe0d55a2201
Removed some redundant USB communication code
Ivo Smits <Ivo@UCIS.nl>
parents:
64
diff
changeset
|
133 return FromByteArray(buff, 0, len); |
abe0d55a2201
Removed some redundant USB communication code
Ivo Smits <Ivo@UCIS.nl>
parents:
64
diff
changeset
|
134 } |
21 | 135 public static unsafe int Size { get { return sizeof(UsbConfigurationDescriptor); } } |
136 } | |
137 [StructLayout(LayoutKind.Sequential, Pack = 1)] | |
138 public struct UsbInterfaceDescriptor { | |
139 byte bmLength; | |
140 byte bType; | |
141 byte bInterfaceNumber; | |
142 byte bAlternateSetting; | |
143 byte bNumEndpoints; | |
144 byte bInterfaceClass; | |
145 byte bInterfaceSubClass; | |
146 byte bInterfaceProtocol; | |
147 byte bInterfaceStringID; | |
148 public Byte Length { get { return bmLength; } } | |
149 public UsbDescriptorType Type { get { return (UsbDescriptorType)bType; } } | |
150 public Byte InterfaceNumber { get { return bInterfaceNumber; } } | |
151 public Byte AlternateSetting { get { return bAlternateSetting; } } | |
152 public Byte NumEndpoints { get { return bNumEndpoints; } } | |
68
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
153 public UsbClassCode InterfaceClass { get { return (UsbClassCode)bInterfaceClass; } } |
21 | 154 public Byte InterfaceSubClass { get { return bInterfaceSubClass; } } |
155 public Byte InterfaceProtocol { get { return bInterfaceProtocol; } } | |
156 public Byte InterfaceStringID { get { return bInterfaceStringID; } } | |
157 public unsafe static UsbInterfaceDescriptor FromByteArray(Byte[] buffer, int offset, int length) { | |
158 if (length < Size) throw new ArgumentOutOfRangeException("length", "The data length is smaller than the descriptor length"); | |
159 if (offset < 0 || length < 0 || offset + length > buffer.Length) throw new ArgumentOutOfRangeException("length", "The specified offset and length exceed the buffer dimensions"); | |
160 fixed (Byte* ptr = buffer) return *(UsbInterfaceDescriptor*)(ptr + offset); | |
161 } | |
162 public static unsafe int Size { get { return sizeof(UsbInterfaceDescriptor); } } | |
163 } | |
164 [StructLayout(LayoutKind.Sequential, Pack = 1)] | |
165 public struct UsbEndpointDescriptor { | |
166 byte bmLength; | |
167 byte bType; | |
168 byte bEndpointAddress; | |
169 Byte bmAttributes; | |
170 short wMaxPacketSize; | |
171 byte bInterval; | |
172 public Byte Length { get { return bmLength; } } | |
173 public UsbDescriptorType Type { get { return (UsbDescriptorType)bType; } } | |
174 public Byte EndpointAddress { get { return bEndpointAddress; } } | |
175 public Boolean IsInput { get { return 0 != (EndpointAddress & (1 << 7)); } } | |
176 public int EndpointNumber { get { return EndpointAddress & 0xF; } } | |
177 public int TransferType { get { return bmAttributes & 3; } } | |
178 public Boolean IsControl { get { return TransferType == 0; } } | |
179 public Boolean IsIsochronous { get { return TransferType == 1; } } | |
180 public Boolean IsBulk { get { return TransferType == 2; } } | |
181 public Boolean IsInterrupt { get { return TransferType == 3; } } | |
182 public int MaxPacketSize { get { return UsbDescriptor.FromLittleEndian(wMaxPacketSize) & 0x7FF; } } | |
183 public Byte Interval { get { return bInterval; } } | |
184 public unsafe static UsbEndpointDescriptor FromByteArray(Byte[] buffer, int offset, int length) { | |
185 if (length < Size) throw new ArgumentOutOfRangeException("length", "The data length is smaller than the descriptor length"); | |
186 if (offset < 0 || length < 0 || offset + length > buffer.Length) throw new ArgumentOutOfRangeException("length", "The specified offset and length exceed the buffer dimensions"); | |
187 fixed (Byte* ptr = buffer) return *(UsbEndpointDescriptor*)(ptr + offset); | |
188 } | |
189 public static unsafe int Size { get { return sizeof(UsbEndpointDescriptor); } } | |
190 } | |
191 [StructLayout(LayoutKind.Sequential, Pack = 1)] | |
68
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
192 public struct UsbHidDescriptor { |
21 | 193 byte bmLength; |
194 byte bType; | |
195 short bcdHID; | |
196 byte bCountryCode; | |
197 byte bNumDescriptors; | |
198 byte bDescriptorType; | |
199 short wDescriptorLength; | |
200 public Byte Length { get { return bmLength; } } | |
201 public UsbDescriptorType Type { get { return (UsbDescriptorType)bType; } } | |
202 public short HIDVersion { get { return UsbDescriptor.FromLittleEndian(bcdHID); } } | |
203 public Byte CountryCode { get { return bCountryCode; } } | |
204 public Byte NumDescriptors { get { return bNumDescriptors; } } | |
205 public UsbDescriptorType DescriptorType { get { return (UsbDescriptorType)bDescriptorType; } } | |
206 public short DescriptorLength { get { return UsbDescriptor.FromLittleEndian(wDescriptorLength); } } | |
68
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
207 public unsafe static UsbHidDescriptor FromByteArray(Byte[] buffer, int offset, int length) { |
21 | 208 if (length < Size) throw new ArgumentOutOfRangeException("length", "The data length is smaller than the descriptor length"); |
209 if (offset < 0 || length < 0 || offset + length > buffer.Length) throw new ArgumentOutOfRangeException("length", "The specified offset and length exceed the buffer dimensions"); | |
68
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
210 fixed (Byte* ptr = buffer) return *(UsbHidDescriptor*)(ptr + offset); |
21 | 211 } |
68
e811297f5aa4
Updated USBLib: removed old LibUsbDotNet compatibility code and added new information helper classes
Ivo Smits <Ivo@UCIS.nl>
parents:
65
diff
changeset
|
212 public static unsafe int Size { get { return sizeof(UsbHidDescriptor); } } |
21 | 213 } |
214 [StructLayout(LayoutKind.Sequential, Pack = 1)] | |
215 public struct UsbHubDescriptor { | |
216 byte bmLength; | |
217 byte bType; | |
218 byte bNumPorts; | |
219 short wHubCharacteristics; | |
220 byte bPwrOn2PwrGood; //2ms intervals | |
221 byte bHubControllerCurrent; | |
222 public Byte Length { get { return bmLength; } } | |
223 public UsbDescriptorType Type { get { return (UsbDescriptorType)bType; } } | |
224 public Byte NumPorts { get { return bNumPorts; } } | |
225 public Boolean IsCompoundDevice { get { return 0 != (wHubCharacteristics & (1 << 2)); } } | |
226 public Byte HubControllerCurrent { get { return bHubControllerCurrent; } } | |
227 public unsafe static UsbHubDescriptor FromByteArray(Byte[] buffer, int offset, int length) { | |
228 if (length < Marshal.SizeOf(typeof(UsbHubDescriptor))) throw new ArgumentOutOfRangeException("length", "The data length is smaller than the descriptor length"); | |
229 if (offset < 0 || length < 0 || offset + length > buffer.Length) throw new ArgumentOutOfRangeException("length", "The specified offset and length exceed the buffer dimensions"); | |
230 fixed (Byte* ptr = buffer) return *(UsbHubDescriptor*)(ptr + offset); | |
231 } | |
58
fd63c453ff65
Improved Windows USB enumeration classes
Ivo Smits <Ivo@UCIS.nl>
parents:
47
diff
changeset
|
232 public static unsafe int Size { get { return sizeof(UsbHubDescriptor); } } |
21 | 233 } |
234 } |