public static unsafe UsbInterfaceInfo FromUsbInterfaceDescriptor(LibUsb.UsbDevice device, InterfaceDescriptor descriptor) { Debug.Assert(descriptor.DescriptorType == (int)DescriptorType.Interface, "A config descriptor was expected"); UsbInterfaceInfo value = new UsbInterfaceInfo(); value.AlternateSetting = descriptor.AlternateSetting; var endpoints = (EndpointDescriptor *)descriptor.Endpoint; for (int i = 0; i < descriptor.NumEndpoints; i++) { if (endpoints[i].DescriptorType != 0) { value.endpoints.Add(UsbEndpointInfo.FromUsbEndpointDescriptor(endpoints[i])); } } value.RawDescriptors = new byte[descriptor.ExtraLength]; if (descriptor.ExtraLength > 0) { Span <byte> extra = new Span <byte>(descriptor.Extra, descriptor.ExtraLength); extra.CopyTo(value.RawDescriptors); } value.Interface = device.GetStringDescriptor(descriptor.Interface, failSilently: true); value.Class = (ClassCode)descriptor.InterfaceClass; value.Number = descriptor.InterfaceNumber; value.Protocol = descriptor.InterfaceProtocol; value.SubClass = descriptor.InterfaceSubClass; return(value); }
public static unsafe UsbEndpointInfo FromUsbEndpointDescriptor(EndpointDescriptor descriptor) { Debug.Assert(descriptor.DescriptorType == (int)DescriptorType.Endpoint, "An endpoint descriptor was expected"); var value = new UsbEndpointInfo(); value.Attributes = descriptor.Attributes; value.EndpointAddress = descriptor.EndpointAddress; value.RawDescriptors = new byte[descriptor.ExtraLength]; if (descriptor.ExtraLength > 0) { Span <byte> extra = new Span <byte>(descriptor.Extra, descriptor.ExtraLength); extra.CopyTo(value.RawDescriptors); } value.Interval = descriptor.Interval; value.MaxPacketSize = descriptor.MaxPacketSize; value.Refresh = descriptor.Refresh; value.SyncAddress = descriptor.SynchAddress; return(value); }
/// <summary> /// Looks up endpoint/interface information in a configuration. /// </summary> /// <param name="currentConfigInfo">The config to seach.</param> /// <param name="endpointAddress">The endpoint address to look for.</param> /// <param name="usbInterfaceInfo">On success, the <see cref="UsbInterfaceInfo"/> class for this endpoint.</param> /// <param name="usbEndpointInfo">On success, the <see cref="UsbEndpointInfo"/> class for this endpoint.</param> /// <returns>True of the endpoint was found, otherwise false.</returns> public static bool LookupEndpointInfo(UsbConfigInfo currentConfigInfo, byte endpointAddress, out UsbInterfaceInfo usbInterfaceInfo, out UsbEndpointInfo usbEndpointInfo) { bool found = false; usbInterfaceInfo = null; usbEndpointInfo = null; foreach (UsbInterfaceInfo interfaceInfo in currentConfigInfo.InterfaceInfoList) { foreach (UsbEndpointInfo endpointInfo in interfaceInfo.EndpointInfoList) { if ((endpointAddress & UsbConstants.ENDPOINT_NUMBER_MASK) == 0) { // find first read/write endpoint if ((endpointAddress & UsbConstants.ENDPOINT_DIR_MASK) == 0 && (endpointInfo.Descriptor.EndpointID & UsbConstants.ENDPOINT_DIR_MASK) == 0) { // first write endpoint found = true; } if ((endpointAddress & UsbConstants.ENDPOINT_DIR_MASK) != 0 && (endpointInfo.Descriptor.EndpointID & UsbConstants.ENDPOINT_DIR_MASK) != 0) { // first read endpoint found = true; } } else if (endpointInfo.Descriptor.EndpointID == endpointAddress) { found = true; } if (found) { usbInterfaceInfo = interfaceInfo; usbEndpointInfo = endpointInfo; return true; } } } return false; }
private static void FillEndpointInfo(TreeNode tvEndpoints, UsbEndpointInfo i) { if (i.Descriptor != null) { TreeNode tvEpDesc = tvEndpoints.Nodes.Add(string.Format("Endpoint (ID: 0x{0:X4}) Descriptor [Length: {1}]", i.Descriptor.EndpointID, i.Descriptor.Length)); tvEpDesc.Nodes.Add(string.Format("{0}: {1} (0x{2:X2})", "DescriptorType", i.Descriptor.DescriptorType, (int)i.Descriptor.DescriptorType)); tvEpDesc.Nodes.Add(string.Format("{0}: {1}", "Attributes", i.Descriptor.Attributes)); tvEpDesc.Nodes.Add(string.Format("{0}: {1}", "MaxPacketSize", i.Descriptor.MaxPacketSize)); tvEpDesc.Nodes.Add(string.Format("{0}: {1}", "Interval", i.Descriptor.Interval)); tvEpDesc.Nodes.Add(string.Format("{0}: {1}", "Refresh", i.Descriptor.Refresh)); tvEpDesc.Nodes.Add(string.Format("{0}: 0x{1:X2}", "SynchAddress", i.Descriptor.SynchAddress)); } if (i.CustomDescriptors != null) { TreeNode tvEpDesc = tvEndpoints.Nodes.Add(string.Format("EP Custom Descriptor [Length: {0}]", i.CustomDescriptors.Count)); FillCustomDescriptor(i.CustomDescriptors, tvEpDesc); } }
/// <summary> /// Looks up endpoint/interface information in a configuration. /// </summary> /// <param name="currentConfigInfo">The config to seach.</param> /// <param name="endpointAddress">The endpoint address to look for.</param> /// <param name="usbInterfaceInfo">On success, the <see cref="UsbInterfaceInfo"/> class for this endpoint.</param> /// <param name="usbEndpointInfo">On success, the <see cref="UsbEndpointInfo"/> class for this endpoint.</param> /// <returns>True of the endpoint was found, otherwise false.</returns> public static bool LookupEndpointInfo(UsbConfigInfo currentConfigInfo, byte endpointAddress, out UsbInterfaceInfo usbInterfaceInfo, out UsbEndpointInfo usbEndpointInfo) { return LookupEndpointInfo(currentConfigInfo, -1, endpointAddress, out usbInterfaceInfo, out usbEndpointInfo); }