const UsbHidDescriptor * usbHidDescriptor (UsbDevice *device) { const UsbDescriptor *descriptor = NULL; while (usbNextDescriptor(device, &descriptor)) if (descriptor->endpoint.bDescriptorType == UsbDescriptorType_HID) return &descriptor->hid; logMessage(LOG_WARNING, "USB: HID descriptor not found"); errno = ENOENT; return NULL; }
static const UsbInterfaceDescriptor * usbFindCommunicationInterface (UsbDevice *device) { const UsbDescriptor *descriptor = NULL; while (usbNextDescriptor(device, &descriptor)) { if (descriptor->header.bDescriptorType == UsbDescriptorType_Interface) { if (descriptor->interface.bInterfaceClass == 0X02) { return &descriptor->interface; } } } logMessage(LOG_WARNING, "USB: communication interface descriptor not found"); errno = ENOENT; return NULL; }
unsigned int usbAlternativeCount ( UsbDevice *device, unsigned char interface ) { unsigned int count = 0; const UsbDescriptor *descriptor = NULL; while (usbNextDescriptor(device, &descriptor)) { if (descriptor->interface.bDescriptorType == UsbDescriptorType_Interface) if (descriptor->interface.bInterfaceNumber == interface) count += 1; } return count; }
const UsbEndpointDescriptor * usbEndpointDescriptor ( UsbDevice *device, unsigned char endpointAddress ) { const UsbDescriptor *descriptor = NULL; while (usbNextDescriptor(device, &descriptor)) { if (descriptor->endpoint.bDescriptorType == UsbDescriptorType_Endpoint) if (descriptor->endpoint.bEndpointAddress == endpointAddress) return &descriptor->endpoint; } logMessage(LOG_WARNING, "USB: endpoint descriptor not found: %02X", endpointAddress); errno = ENOENT; return NULL; }
const UsbInterfaceDescriptor * usbInterfaceDescriptor ( UsbDevice *device, unsigned char interface, unsigned char alternative ) { const UsbDescriptor *descriptor = NULL; while (usbNextDescriptor(device, &descriptor)) { if (descriptor->interface.bDescriptorType == UsbDescriptorType_Interface) if (descriptor->interface.bInterfaceNumber == interface) if (descriptor->interface.bAlternateSetting == alternative) return &descriptor->interface; } logMessage(LOG_WARNING, "USB: interface descriptor not found: %d.%d", interface, alternative); errno = ENOENT; return NULL; }
static const UsbEndpointDescriptor * usbFindInterruptInputEndpoint (UsbDevice *device, const UsbInterfaceDescriptor *interface) { const UsbDescriptor *descriptor = (const UsbDescriptor *)interface; while (usbNextDescriptor(device, &descriptor)) { if (descriptor->header.bDescriptorType == UsbDescriptorType_Interface) break; if (descriptor->header.bDescriptorType == UsbDescriptorType_Endpoint) { if (USB_ENDPOINT_DIRECTION(&descriptor->endpoint) == UsbEndpointDirection_Input) { if (USB_ENDPOINT_TRANSFER(&descriptor->endpoint) == UsbEndpointTransfer_Interrupt) { return &descriptor->endpoint; } } } } logMessage(LOG_WARNING, "USB: interrupt input endpoint descriptor not found"); errno = ENOENT; return NULL; }