Loading...
Searching...
No Matches
usbfs.h
Go to the documentation of this file.
129 return access(USBFS_SYSFS_ROOT, R_OK | X_OK) == 0 && access(USBFS_DEVICE_ROOT, R_OK | X_OK) == 0;
169 if (length < 0 || (size_t)length >= sizeof(device->name) || name[0] < '1' || name[0] > '9') return false;
199/** @return 1 with a device, 0 at the end, or a negative error. Vanishing devices are skipped. */
256static inline int usbfs_active_config(const struct usbfs_device *device, uint8_t *buffer, size_t capacity,
280 return result ? result : usbfs_select_config(buffer, used, (unsigned)value, config, config_length);
339 usbfs_read_number(device->name, "idProduct", 16, 0xffff, &product) && product == device->product;
355 return errno == ENOENT || errno == ENODEV || errno == ENXIO ? USBFS_ERROR_NO_DEVICE : USBFS_ERROR_IO;
358 if (fstat(fd, &status) != 0 || !S_ISCHR(status.st_mode) || major(status.st_rdev) != USBFS_DEVICE_MAJOR ||
359 minor(status.st_rdev) != (device->bus - 1) * 128 + device->address - 1 || !usbfs_same_device(device)) {
384static inline int usbfs_interface_ioctl(struct usbfs_handle *handle, unsigned long request, void *argument)
403 return interface < 0 ? USBFS_ERROR_INVALID_PARAM : usbfs_interface_ioctl(handle, USBDEVFS_CLAIMINTERFACE, &number);
414 return interface < 0 ? USBFS_ERROR_INVALID_PARAM : usbfs_interface_ioctl(handle, USBDEVFS_RELEASEINTERFACE, &number);
444static inline int usbfs_control_transfer(struct usbfs_handle *handle, uint8_t request_type, uint8_t request,
464/** @brief Clear a halted endpoint of a claimed interface; data toggles are reset by the kernel. */
494static inline int usbfs_bulk_urb(struct usbfs_handle *handle, unsigned char endpoint, unsigned char *data,
517 if (error != EAGAIN) return usbfs_drop(handle, error == ENODEV ? USBFS_ERROR_NO_DEVICE : USBFS_ERROR_IO);
527 if (discarded) return usbfs_drop(handle, cancelled ? USBFS_ERROR_INTERRUPTED : USBFS_ERROR_TIMEOUT);
543 return cancelled ? USBFS_ERROR_INTERRUPTED : discarded ? USBFS_ERROR_TIMEOUT : USBFS_ERROR_INTERRUPTED;
563static inline int usbfs_bulk_transfer(struct usbfs_handle *handle, unsigned char endpoint, unsigned char *data,
572 int limit = handle->capabilities & USBDEVFS_CAP_NO_PACKET_SIZE_LIM ? INT_MAX : USBFS_LEGACY_TRANSFER;
574 return usbfs_bulk_urb(handle, endpoint, data, length < limit ? length : limit, transferred, deadline);
static bool transfer(const struct lwir_state_io *io, uint64_t deadline, bool input, uint16_t address, uint8_t *data, unsigned length, struct lwir_state_value *value)
Perform one deadline-bounded mailbox transfer and classify failure.
Definition lwir_state.c:102
One enumerated USB device; a value copy, valid after enumeration ends.
Definition usbfs.h:73
Definition usbfs.h:92
Definition usbfs.h:81
Definition usbfs.h:86
static bool usbfs_parse_name(const char *name, struct usbfs_device *device)
Parse "BUS-PORT[.PORT...]"; rejects root hubs and interface entries.
Definition usbfs.h:166
static int usbfs_bulk_urb(struct usbfs_handle *handle, unsigned char endpoint, unsigned char *data, int length, int *actual, uint64_t deadline)
Submit one bulk URB and wait until it is reaped or deadline passes.
Definition usbfs.h:494
static bool usbfs_next_interface(const uint8_t *config, size_t length, size_t *offset, struct usbfs_interface *interface)
Return the next complete interface/alternate setting in a configuration.
Definition usbfs.h:293
static int usbfs_select_config(const uint8_t *descriptors, size_t length, unsigned value, const uint8_t **config, size_t *config_length)
Locate configuration value in raw sysfs descriptors.
Definition usbfs.h:236
static int usbfs_clear_halt(struct usbfs_handle *handle, unsigned char endpoint)
Clear a halted endpoint of a claimed interface; data toggles are reset by the kernel.
Definition usbfs.h:465
static bool usbfs_available(void)
True when sysfs device listing and usbfs nodes are reachable.
Definition usbfs.h:127
static int usbfs_interface_ioctl(struct usbfs_handle *handle, unsigned long request, void *argument)
Run a synchronous interface ioctl and translate its result.
Definition usbfs.h:384
static const char * usbfs_error_name(int error)
Get the diagnostic name of a usbfs result.
Definition usbfs.h:107
static int usbfs_release_interface(struct usbfs_handle *handle, int interface)
Release the numbered interface on an open device.
Definition usbfs.h:411
static int usbfs_bulk_transfer(struct usbfs_handle *handle, unsigned char endpoint, unsigned char *data, int length, int *transferred, unsigned timeout)
Synchronous bulk transfer with libusb_bulk_transfer() semantics.
Definition usbfs.h:563
static int usbfs_drop(struct usbfs_handle *handle, int result)
Abandon the fd; closing it is the only way the kernel guarantees the URB is gone.
Definition usbfs.h:482
static int usbfs_active_config(const struct usbfs_device *device, uint8_t *buffer, size_t capacity, const uint8_t **config, size_t *config_length)
Read the active configuration into buffer; config points inside it.
Definition usbfs.h:256
static void usbfs_devices_close(struct usbfs_devices *devices)
Release the sysfs enumeration stream.
Definition usbfs.h:225
static int usbfs_devices_open(struct usbfs_devices *devices)
Start a streaming sysfs enumeration.
Definition usbfs.h:192
static int usbfs_control_transfer(struct usbfs_handle *handle, uint8_t request_type, uint8_t request, uint16_t value, uint16_t index, unsigned char *data, uint16_t length, unsigned timeout)
Synchronous control transfer on endpoint zero.
Definition usbfs.h:444
static int usbfs_open(const struct usbfs_device *device, struct usbfs_handle *handle)
Open the device node, rejecting a node now owned by a different device.
Definition usbfs.h:343
static bool usbfs_read_number(const char *device, const char *attribute, int base, unsigned long maximum, unsigned long *value)
Read one bounded unsigned numeric sysfs attribute.
Definition usbfs.h:141
static bool usbfs_same_device(const struct usbfs_device *device)
Compare a previously discovered USB identity with current sysfs.
Definition usbfs.h:333
static uint64_t usbfs_now_ms(void)
Read the clock used for bulk transfer deadlines.
Definition usbfs.h:474
static int usbfs_set_alternate(struct usbfs_handle *handle, int interface, int alternate)
Select an alternate setting for an interface.
Definition usbfs.h:423
static int usbfs_devices_next(struct usbfs_devices *devices, struct usbfs_device *device)
Definition usbfs.h:200
static int usbfs_claim_interface(struct usbfs_handle *handle, int interface)
Claim without detaching another owner; EBUSY is reported to the caller.
Definition usbfs.h:400
static void usbfs_close(struct usbfs_handle *handle)
Close the node; the kernel releases claimed interfaces and kills pending URBs.
Definition usbfs.h:371