public override Configuration GetConfiguration() { var setup = new usbfs_ctrltransfer { bRequestType = (byte)(RequestType.USB_DIR_IN | RequestType.USB_TYPE_STANDARD | RequestType.USB_RECIP_DEVICE), bRequest = (byte)Request.GET_CONFIGURATION, wLength = 1 }; byte buf = 0; setup.data = &buf; setup = ControlRequest(devname, setup); byte currentConfiguration = ((byte *)setup.data)[0]; fixed(byte *configDescriptors = otherDescriptors) { var descriptorPtr = (ConfigurationDescriptor *)configDescriptors; ushort currentIndex = 0; for (int i = 0; i < ConfigurationCount; i++) { var descriptor = *descriptorPtr; if (descriptor.bDescriptorType.HasFlag(DescriptorType.Configuration)) { if (descriptor.bConfigurationValue == currentConfiguration) { var start = currentIndex + sizeof(ConfigurationDescriptor); var end = currentIndex + descriptor.wTotalLength - sizeof(ConfigurationDescriptor) - 1; return(new LinuxDeviceConfiguration(descriptor, devname, otherDescriptors[start..end]));
public override Interface GetInterface() { var setup = new usbfs_ctrltransfer { bRequestType = (byte)(RequestType.USB_DIR_IN | RequestType.USB_RECIP_DEVICE | RequestType.USB_TYPE_STANDARD), bRequest = (byte)Request.GET_INTERFACE, wLength = 1 }; byte buf = 0; setup.data = &buf; setup = ControlRequest(devname, setup); byte currentInterface = ((byte *)setup.data)[0]; fixed(byte *interfaceDescriptors = otherDescriptors) { var descriptorPtr = (InterfaceDescriptor *)interfaceDescriptors; for (int i = 0; i < InterfaceCount; i++) { var descriptor = *descriptorPtr; if (descriptor.bInterfaceNumber == currentInterface) { var start = i * sizeof(InterfaceDescriptor); var end = start + sizeof(InterfaceDescriptor); return(new LinuxDeviceInterface(descriptor, devname, otherDescriptors[start..end]));
public static usbfs_ctrltransfer ControlRequest(string devname, usbfs_ctrltransfer setup) { var fd = open(devname, oflag.NONBLOCK | oflag.RDWR); if (fd == -1 || ioctl(fd, USBDEVFS_CONTROL, ref setup) == -1) { throw CreateNativeException(fd); } close(fd); return(setup); }
public override bool SetConfiguration(ushort index) { var setup = new usbfs_ctrltransfer { bRequestType = (byte)(RequestType.USB_DIR_IN | RequestType.USB_TYPE_STANDARD | RequestType.USB_RECIP_DEVICE), bRequest = (byte)Request.SET_CONFIGURATION, wValue = index }; ControlRequest(devname, setup); return(true); }
public override bool SetInterface(ushort index) { var setup = new usbfs_ctrltransfer { bRequestType = (byte)(RequestType.USB_DIR_IN | RequestType.USB_RECIP_DEVICE | RequestType.USB_TYPE_STANDARD), bRequest = (byte)Request.SET_INTERFACE, wValue = index }; ControlRequest(devname, setup); return(true); }
public override string GetIndexedString(byte index) { var setup = new usbfs_ctrltransfer { bRequestType = (byte)(RequestType.USB_DIR_IN | RequestType.USB_TYPE_STANDARD | RequestType.USB_RECIP_DEVICE), bRequest = (byte)Request.GET_DESCRIPTOR, wValue = string_index(0), wIndex = 0, wLength = 255 }; fixed(char *strbuf = new char[256]) { setup.data = strbuf; var fd = open(devname, oflag.NONBLOCK | oflag.RDWR); if (fd == -1 || ioctl(fd, USBDEVFS_CONTROL, ref setup) == -1) { throw CreateNativeException(); } setup.wIndex = (ushort)(strbuf[2] | strbuf[3] << 8); setup.wValue = string_index(index); for (int i = 0; i < 256; i++) { ((byte *)setup.data)[i] = 0; } ioctl(fd, USBDEVFS_CONTROL, ref setup); close(fd); var sb = new StringBuilder(); var retBuf = (char *)setup.data; for (int i = 1; i < 255; i++) { var c = retBuf[i]; if (c == 0) { break; } sb.Append(c); } return(sb.ToString()); } }
public override Interface GetInterface() { var setup = new usbfs_ctrltransfer { bRequestType = (byte)(RequestType.USB_DIR_IN | RequestType.USB_RECIP_DEVICE | RequestType.USB_TYPE_STANDARD), bRequest = (byte)Request.GET_INTERFACE, wValue = 0, wIndex = 0, wLength = 1 }; byte buf = 0; setup.data = &buf; var fd = open(devname, oflag.NONBLOCK | oflag.RDWR); if (fd != -1) { ioctl(fd, USBDEVFS_CONTROL, ref setup); close(fd); } else { throw CreateNativeException(); } byte currentInterface = ((byte *)setup.data)[0]; fixed(byte *interfaceDescriptors = otherDescriptors) { var descriptorPtr = (InterfaceDescriptor *)interfaceDescriptors; int currentIndex = 0; while (currentIndex < otherDescriptors.Length) { var descriptor = *descriptorPtr; if (descriptor.bDescriptorType.HasFlag(DescriptorType.Interface)) { if (descriptor.bInterfaceNumber == currentInterface) { var end = currentIndex + sizeof(InterfaceDescriptor); return(new LinuxDeviceInterface(descriptor, devname, otherDescriptors[currentIndex..^ 0]));
public static extern int ioctl(int filedes, UIntPtr request, ref usbfs_ctrltransfer value);
public static extern int ioctl(int filedes, UIntPtr command, ref usbfs_ctrltransfer value);