ssize_t usbWriteEndpoint ( UsbDevice *device, unsigned char endpointNumber, const void *buffer, size_t length, int timeout ) { UsbEndpoint *endpoint; if ((endpoint = usbGetOutputEndpoint(device, endpointNumber))) { UsbEndpointExtension *eptx = endpoint->extension; ssize_t count; doWrite: if ((count = write(eptx->data, buffer, length)) == -1) { if (errno == EINTR) goto doWrite; logSystemError("USB endpoint write"); } else if (count != length) { logMessage(LOG_ERR, "USB truncated endpoint write: %d < %d", count, length); errno = EIO; } else { return count; } } return -1; }
ssize_t usbWriteEndpoint ( UsbDevice *device, unsigned char endpointNumber, const void *buffer, size_t length, int timeout ) { UsbDeviceExtension *devx = device->extension; if (usbGetHandle(devx)) { const UsbEndpoint *endpoint; if ((endpoint = usbGetOutputEndpoint(device, endpointNumber))) { const UsbEndpointDescriptor *descriptor = endpoint->descriptor; UsbEndpointTransfer transfer = USB_ENDPOINT_TRANSFER(descriptor); int actual_length; int result; switch (transfer) { case UsbEndpointTransfer_Bulk: result = libusb_bulk_transfer(devx->handle, descriptor->bEndpointAddress, (void *)buffer, length, &actual_length, timeout); break; case UsbEndpointTransfer_Interrupt: result = libusb_interrupt_transfer(devx->handle, descriptor->bEndpointAddress, (void *)buffer, length, &actual_length, timeout); break; default: logMessage(LOG_ERR, "USB endpoint output transfer not supported: 0X%02X", transfer); result = LIBUSB_ERROR_NOT_SUPPORTED; break; } if (result == LIBUSB_SUCCESS) return actual_length; usbSetErrno(result, NULL); } } logSystemError("USB endpoint write"); return -1; }
ssize_t usbWriteEndpoint ( UsbDevice *device, unsigned char endpointNumber, const void *buffer, size_t length, int timeout ) { UsbDeviceExtension *devx = device->extension; UsbEndpoint *endpoint; if ((endpoint = usbGetOutputEndpoint(device, endpointNumber))) { const UsbEndpointDescriptor *descriptor = endpoint->descriptor; UsbEndpointTransfer transfer = USB_ENDPOINT_TRANSFER(descriptor); int result = -1; usbLogEndpointData(endpoint, "output", buffer, length); switch (transfer) { case UsbEndpointTransfer_Bulk: result = usb_bulk_write(devx->handle, descriptor->bEndpointAddress, (char *)buffer, length, timeout); break; case UsbEndpointTransfer_Interrupt: result = usb_interrupt_write(devx->handle, descriptor->bEndpointAddress, (char *)buffer, length, timeout); break; default: logMessage(LOG_ERR, "USB endpoint output transfer not supported: 0X%02X", transfer); result = -ENOSYS; break; } if (result >= 0) return result; errno = -result; } logSystemError("USB endpoint write"); return -1; }
ssize_t usbWriteEndpoint ( UsbDevice *device, unsigned char endpointNumber, const void *buffer, size_t length, int timeout ) { UsbEndpoint *endpoint; if ((endpoint = usbGetOutputEndpoint(device, endpointNumber))) { UsbEndpointTransfer transfer = USB_ENDPOINT_TRANSFER(endpoint->descriptor); switch (transfer) { case UsbEndpointTransfer_Interrupt: case UsbEndpointTransfer_Bulk: return usbBulkTransfer(endpoint, (void *)buffer, length, timeout); /* case UsbEndpointTransfer_Interrupt: { struct usbdevfs_urb *urb = usbInterruptTransfer(endpoint, (void *)buffer, length, timeout); if (urb) { ssize_t count = urb->actual_length; free(urb); return count; } break; } */ default: logMessage(LOG_ERR, "USB output transfer not supported: %d", transfer); errno = ENOSYS; break; } } return -1; }