public override Endpoint GetEndpoint(uint index) { var udev = udev_new(); var udevEnumerator = udev_enumerate_new(udev); if (udevEnumerator == null) { throw new UdevException("Failed to create udev enumerator."); } udev_enumerate_add_match_subsystem(udevEnumerator, "hidraw"); udev_enumerate_scan_devices(udevEnumerator); List <string> endpointPaths = new List <string>(); for (var entry = udev_enumerate_get_list_entry(udevEnumerator); entry != null; entry = udev_list_entry_get_next(entry)) { var sysPath = udev_list_entry_get_name(entry); udev_device *hidEndpoint = udev_device_new_from_syspath(udev, sysPath); udev_device *parentDevice = udev_device_get_parent_with_subsystem_devtype(hidEndpoint, "usb", "usb_device"); var parentDevname = udev_device_get_property_value(parentDevice, "DEVNAME"); if (parentDevname == devname) { endpointPaths.Add(sysPath); } } throw new NotImplementedException(); }
public override Endpoint GetEndpoint(uint index) { var udev = udev_new(); var udevEnumerator = udev_enumerate_new(udev); if (udevEnumerator == null) { throw new UdevException("Failed to create udev enumerator."); } udev_enumerate_add_match_subsystem(udevEnumerator, "hidraw"); udev_enumerate_scan_devices(udevEnumerator); List <string> endpointPaths = new List <string>(); for (var entry = udev_enumerate_get_list_entry(udevEnumerator); entry != null; entry = udev_list_entry_get_next(entry)) { var sysPath = udev_list_entry_get_name(entry); udev_device *hidEndpoint = udev_device_new_from_syspath(udev, sysPath); udev_device *parentDevice = udev_device_get_parent_with_subsystem_devtype(hidEndpoint, "usb", "usb_device"); var parentDevname = udev_device_get_property_value(parentDevice, "DEVNAME"); if (parentDevname == devname) { endpointPaths.Add(sysPath); } } fixed(byte *endpointDescriptors = otherDescriptors) { var descriptorPtr = (EndpointDescriptor *)endpointDescriptors; int currentIndex = 0; while (currentIndex < otherDescriptors.Length) { EndpointDescriptor descriptor = *descriptorPtr; if (descriptor.bDescriptorType.HasFlag(DescriptorType.Endpoint)) { int endpointNum = descriptor.bEndpointAddress & 0x0f; bool endpointDirection = (descriptor.bEndpointAddress & (1 << 7)) != 0; if (endpointNum == index) { return(new LinuxDeviceEndpoint(descriptor, endpointPaths[(int)index])); } } currentIndex += descriptor.bLength; descriptorPtr = (EndpointDescriptor *)(endpointDescriptors + currentIndex); } } throw new Exception($"Requested endpoint {index} doesn't exist or is not available."); }
internal unsafe LinuxDevice(udev_device *udevDevice, string devPath, DeviceDescriptor descriptor, byte[] otherDescriptors = null) { InternalFilePath = devPath; this.descriptor = descriptor; this.otherDescriptors = otherDescriptors; SetValues(descriptor); var busnum = udev_device_get_sysattr_value(udevDevice, "busnum"); var devnum = udev_device_get_sysattr_value(udevDevice, "devnum"); this.devname = $"/dev/bus/usb/{int.Parse(busnum):D3}/{int.Parse(devnum):D3}"; this.Manufacturer = udev_device_get_sysattr_value(udevDevice, "manufacturer"); this.ProductName = udev_device_get_sysattr_value(udevDevice, "product"); this.SerialNumber = udev_device_get_property_value(udevDevice, "serial"); }
public static extern string udev_device_get_devpath(udev_device *udev_device);
public static extern udev_device *udev_device_get_parent(udev_device *udev_device);
public static extern udev_device *udev_device_get_parent_with_subsystem_devtype( udev_device *udev_device, [MarshalAs(UnmanagedType.LPStr)] string subsystem, [MarshalAs(UnmanagedType.LPStr)] string devtype );
public static extern udev_device *udev_device_unref(udev_device *udev_device);
public static extern udev *udev_device_get_udev(udev_device *udev_device);
public static extern udev_list_entry *udev_device_get_tags_list_entry(udev_device *udev_device);
public static extern int udev_device_has_tag( udev_device *udev_device, [MarshalAs(UnmanagedType.LPStr)] string tag );
public static extern int udev_device_get_is_initialized(udev_device *udev_device);
public static extern string udev_device_get_devnode(udev_device *udev_device);
public static extern string udev_device_get_action(udev_device *udev_device);
public static extern ulong udev_device_get_seqnum(udev_device *udev_device);
public static extern string udev_device_get_driver(udev_device *udev_device);
public static extern string udev_device_get_property_value( udev_device *udev_device, [MarshalAs(UnmanagedType.LPStr)] string key );
public static extern udev_list_entry *udev_device_get_sysattr_list_entry(udev_device *udev_device);
public static extern string udev_device_get_subsystem(udev_device *udev_device);
public static extern int udev_device_set_sysattr_value( udev_device *udev_device, [MarshalAs(UnmanagedType.LPStr)] string sysattr, [MarshalAs(UnmanagedType.LPStr)] string value );
public static extern ulong udev_device_get_usec_since_initialized(udev_device *udev_device);
public static extern udev_list_entry *udev_device_get_properties_list_entry(udev_device *udev_device);
public static extern string udev_device_get_sysattr_value( udev_device *udev_device, [MarshalAs(UnmanagedType.LPStr)] string sysattr );
public static extern string udev_device_get_sysnum(udev_device *udev_device);