예제 #1
0
        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();
        }
예제 #2
0
        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.");
        }
예제 #3
0
        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");
        }
예제 #4
0
 public static extern string udev_device_get_devpath(udev_device *udev_device);
예제 #5
0
 public static extern udev_device *udev_device_get_parent(udev_device *udev_device);
예제 #6
0
 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
     );
예제 #7
0
 public static extern udev_device *udev_device_unref(udev_device *udev_device);
예제 #8
0
 public static extern udev *udev_device_get_udev(udev_device *udev_device);
예제 #9
0
 public static extern udev_list_entry *udev_device_get_tags_list_entry(udev_device *udev_device);
예제 #10
0
 public static extern int udev_device_has_tag(
     udev_device *udev_device,
     [MarshalAs(UnmanagedType.LPStr)] string tag
     );
예제 #11
0
 public static extern int udev_device_get_is_initialized(udev_device *udev_device);
예제 #12
0
 public static extern string udev_device_get_devnode(udev_device *udev_device);
예제 #13
0
 public static extern string udev_device_get_action(udev_device *udev_device);
예제 #14
0
 public static extern ulong udev_device_get_seqnum(udev_device *udev_device);
예제 #15
0
 public static extern string udev_device_get_driver(udev_device *udev_device);
예제 #16
0
 public static extern string udev_device_get_property_value(
     udev_device *udev_device,
     [MarshalAs(UnmanagedType.LPStr)] string key
     );
예제 #17
0
 public static extern udev_list_entry *udev_device_get_sysattr_list_entry(udev_device *udev_device);
예제 #18
0
 public static extern string udev_device_get_subsystem(udev_device *udev_device);
예제 #19
0
 public static extern int udev_device_set_sysattr_value(
     udev_device *udev_device,
     [MarshalAs(UnmanagedType.LPStr)] string sysattr,
     [MarshalAs(UnmanagedType.LPStr)] string value
     );
예제 #20
0
 public static extern ulong udev_device_get_usec_since_initialized(udev_device *udev_device);
예제 #21
0
 public static extern udev_list_entry *udev_device_get_properties_list_entry(udev_device *udev_device);
예제 #22
0
 public static extern string udev_device_get_sysattr_value(
     udev_device *udev_device,
     [MarshalAs(UnmanagedType.LPStr)] string sysattr
     );
예제 #23
0
 public static extern string udev_device_get_sysnum(udev_device *udev_device);