unsigned long session_id)
{
size_t priv_size = usbi_backend.device_priv_size;
- struct libusb_device *dev = calloc(1, sizeof(*dev) + priv_size);
+ struct libusb_device *dev = calloc(1, PTR_ALIGN(sizeof(*dev)) + priv_size);
int r;
if (!dev)
if (!usbi_backend.wrap_sys_device)
return LIBUSB_ERROR_NOT_SUPPORTED;
- _dev_handle = malloc(sizeof(*_dev_handle) + priv_size);
+ _dev_handle = calloc(1, PTR_ALIGN(sizeof(*_dev_handle)) + priv_size);
if (!_dev_handle)
return LIBUSB_ERROR_NO_MEM;
return LIBUSB_ERROR_OTHER;
}
- _dev_handle->dev = NULL;
- _dev_handle->auto_detach_kernel_driver = 0;
- _dev_handle->claimed_interfaces = 0;
- memset(&_dev_handle->os_priv, 0, priv_size);
-
r = usbi_backend.wrap_sys_device(ctx, _dev_handle, sys_dev);
if (r < 0) {
usbi_dbg("wrap_sys_device %p returns %d", (void *)sys_dev, r);
return LIBUSB_ERROR_NO_DEVICE;
}
- _dev_handle = malloc(sizeof(*_dev_handle) + priv_size);
+ _dev_handle = calloc(1, PTR_ALIGN(sizeof(*_dev_handle)) + priv_size);
if (!_dev_handle)
return LIBUSB_ERROR_NO_MEM;
}
_dev_handle->dev = libusb_ref_device(dev);
- _dev_handle->auto_detach_kernel_driver = 0;
- _dev_handle->claimed_interfaces = 0;
- memset(&_dev_handle->os_priv, 0, priv_size);
r = usbi_backend.open(_dev_handle);
if (r < 0) {
return 0;
}
- ctx = calloc(1, sizeof(*ctx) + priv_size);
+ ctx = calloc(1, PTR_ALIGN(sizeof(*ctx)) + priv_size);
if (!ctx) {
r = LIBUSB_ERROR_NO_MEM;
goto err_unlock;
itransfer = (struct usbi_transfer *)(ptr + priv_size);
itransfer->num_iso_packets = iso_packets;
- itransfer->os_priv = ptr;
+ itransfer->priv = ptr;
usbi_mutex_init(&itransfer->lock);
transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
usbi_dbg("transfer %p", transfer);
priv_size = PTR_ALIGN(usbi_backend.transfer_priv_size);
ptr = (unsigned char *)itransfer - priv_size;
- assert(ptr == itransfer->os_priv);
+ assert(ptr == itransfer->priv);
free(ptr);
}
#define PTR_ALIGN(v) \
(((v) + (sizeof(void *) - 1)) & ~(sizeof(void *) - 1))
-/* Attribute to ensure that a structure member is aligned to a natural
- * pointer alignment. Used for os_priv member. */
-#if defined(_MSC_VER)
-#if defined(_WIN64)
-#define PTR_ALIGNED __declspec(align(8))
-#else
-#define PTR_ALIGNED __declspec(align(4))
-#endif
-#elif defined(__GNUC__) && (__GNUC__ >= 3)
-#define PTR_ALIGNED __attribute__((aligned(sizeof(void *))))
-#else
-#define PTR_ALIGNED
-#endif
-
/* Internal abstraction for poll */
#if defined(POLL_POSIX)
#include "os/poll_posix.h"
#endif
struct list_head list;
-
- PTR_ALIGNED unsigned char os_priv[ZERO_SIZED_ARRAY];
};
extern struct libusb_context *usbi_default_context;
struct libusb_device_descriptor device_descriptor;
int attached;
-
- PTR_ALIGNED unsigned char os_priv[ZERO_SIZED_ARRAY];
};
struct libusb_device_handle {
struct list_head list;
struct libusb_device *dev;
int auto_detach_kernel_driver;
-
- PTR_ALIGNED unsigned char os_priv[ZERO_SIZED_ARRAY];
};
enum {
* always take the flying_transfers_lock first */
usbi_mutex_t lock;
- void *os_priv;
+ void *priv;
struct libusb_transfer libusb_transfer;
};
#define LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer) \
container_of(transfer, struct usbi_transfer, libusb_transfer)
-static inline void *usbi_transfer_get_os_priv(struct usbi_transfer *itransfer)
-{
- return itransfer->os_priv;
-}
-
/* All standard descriptors have these 2 fields in common */
struct usb_descriptor_header {
uint8_t bLength;
int usbi_add_pollfd(struct libusb_context *ctx, int fd, short events);
void usbi_remove_pollfd(struct libusb_context *ctx, int fd);
+/* accessor functions for structure private data */
+
+static inline void *usbi_get_context_priv(struct libusb_context *ctx)
+{
+ return (unsigned char *)ctx + PTR_ALIGN(sizeof(*ctx));
+}
+
+static inline void *usbi_get_device_priv(struct libusb_device *dev)
+{
+ return (unsigned char *)dev + PTR_ALIGN(sizeof(*dev));
+}
+
+static inline void *usbi_get_device_handle_priv(struct libusb_device_handle *dev_handle)
+{
+ return (unsigned char *)dev_handle + PTR_ALIGN(sizeof(*dev_handle));
+}
+
+static inline void *usbi_get_transfer_priv(struct usbi_transfer *itransfer)
+{
+ return itransfer->priv;
+}
+
/* device discovery */
/* we traverse usbfs without knowing how many devices we are going to find.
int (*clock_gettime)(int clkid, struct timespec *tp);
/* Number of bytes to reserve for per-context private backend data.
- * This private data area is accessible through the "os_priv" field of
- * struct libusb_context. */
+ * This private data area is accessible by calling
+ * usbi_get_context_priv() on the libusb_context instance.
+ */
size_t context_priv_size;
/* Number of bytes to reserve for per-device private backend data.
- * This private data area is accessible through the "os_priv" field of
- * struct libusb_device. */
+ * This private data area is accessible by calling
+ * usbi_get_device_priv() on the libusb_device instance.
+ */
size_t device_priv_size;
/* Number of bytes to reserve for per-handle private backend data.
- * This private data area is accessible through the "os_priv" field of
- * struct libusb_device_handle. */
+ * This private data area is accessible by calling
+ * usbi_get_device_handle_priv() on the libusb_device_handle instance.
+ */
size_t device_handle_priv_size;
/* Number of bytes to reserve for per-transfer private backend data.
* This private data area is accessible by calling
- * usbi_transfer_get_os_priv() on the appropriate usbi_transfer instance.
+ * usbi_get_transfer_priv() on the usbi_transfer instance.
*/
size_t transfer_priv_size;
};
static struct list_head darwin_cached_devices = {&darwin_cached_devices, &darwin_cached_devices};
static const char *darwin_device_class = kIOUSBDeviceClassName;
-#define DARWIN_CACHED_DEVICE(a) ((struct darwin_cached_device *) (((struct darwin_device_priv *)((a)->os_priv))->dev))
+#define DARWIN_CACHED_DEVICE(a) (((struct darwin_device_priv *)usbi_get_device_priv((a)))->dev)
/* async event thread */
static pthread_t libusb_darwin_at;
}
static int ep_to_pipeRef(struct libusb_device_handle *dev_handle, uint8_t ep, uint8_t *pipep, uint8_t *ifcp, struct darwin_interface **interface_out) {
- struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
+ struct darwin_device_handle_priv *priv = usbi_get_device_handle_priv(dev_handle);
/* current interface */
struct darwin_interface *cInterface;
return LIBUSB_ERROR_NO_MEM;
}
- priv = (struct darwin_device_priv *)dev->os_priv;
+ priv = usbi_get_device_priv(dev);
priv->dev = cached_device;
darwin_ref_cached_device (priv->dev);
assert(cached_device->address <= UINT8_MAX);
dev->device_address = (uint8_t)cached_device->address;
} else {
- priv = (struct darwin_device_priv *)dev->os_priv;
+ priv = usbi_get_device_priv(dev);
}
if (cached_device->parent_session > 0) {
}
static int darwin_open (struct libusb_device_handle *dev_handle) {
- struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
+ struct darwin_device_handle_priv *priv = usbi_get_device_handle_priv(dev_handle);
struct darwin_cached_device *dpriv = DARWIN_CACHED_DEVICE(dev_handle->dev);
IOReturn kresult;
}
static void darwin_close (struct libusb_device_handle *dev_handle) {
- struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
+ struct darwin_device_handle_priv *priv = usbi_get_device_handle_priv(dev_handle);
struct darwin_cached_device *dpriv = DARWIN_CACHED_DEVICE(dev_handle->dev);
IOReturn kresult;
int i;
}
static enum libusb_error get_endpoints (struct libusb_device_handle *dev_handle, int iface) {
- struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
+ struct darwin_device_handle_priv *priv = usbi_get_device_handle_priv(dev_handle);
/* current interface */
struct darwin_interface *cInterface = &priv->interfaces[iface];
static int darwin_claim_interface(struct libusb_device_handle *dev_handle, int iface) {
struct darwin_cached_device *dpriv = DARWIN_CACHED_DEVICE(dev_handle->dev);
- struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
+ struct darwin_device_handle_priv *priv = usbi_get_device_handle_priv(dev_handle);
io_service_t usbInterface = IO_OBJECT_NULL;
IOReturn kresult;
enum libusb_error ret;
}
static int darwin_release_interface(struct libusb_device_handle *dev_handle, int iface) {
- struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
+ struct darwin_device_handle_priv *priv = usbi_get_device_handle_priv(dev_handle);
IOReturn kresult;
/* current interface */
}
static int darwin_set_interface_altsetting(struct libusb_device_handle *dev_handle, int iface, int altsetting) {
- struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
+ struct darwin_device_handle_priv *priv = usbi_get_device_handle_priv(dev_handle);
IOReturn kresult;
enum libusb_error ret;
static int darwin_restore_state (struct libusb_device_handle *dev_handle, int8_t active_config,
unsigned long claimed_interfaces) {
struct darwin_cached_device *dpriv = DARWIN_CACHED_DEVICE(dev_handle->dev);
- struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
+ struct darwin_device_handle_priv *priv = usbi_get_device_handle_priv(dev_handle);
int open_count = dpriv->open_count;
int ret;
}
static void darwin_destroy_device(struct libusb_device *dev) {
- struct darwin_device_priv *dpriv = (struct darwin_device_priv *) dev->os_priv;
+ struct darwin_device_priv *dpriv = usbi_get_device_priv(dev);
if (dpriv->dev) {
/* need to hold the lock in case this is the last reference to the device */
static int submit_iso_transfer(struct usbi_transfer *itransfer) {
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct darwin_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
+ struct darwin_transfer_priv *tpriv = usbi_get_transfer_priv(itransfer);
IOReturn kresult;
uint8_t direction, number, interval, pipeRef, transferType;
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct libusb_control_setup *setup = (struct libusb_control_setup *) transfer->buffer;
struct darwin_cached_device *dpriv = DARWIN_CACHED_DEVICE(transfer->dev_handle->dev);
- struct darwin_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
+ struct darwin_transfer_priv *tpriv = usbi_get_transfer_priv(itransfer);
IOReturn kresult;
static void darwin_async_io_callback (void *refcon, IOReturn result, void *arg0) {
struct usbi_transfer *itransfer = (struct usbi_transfer *)refcon;
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct darwin_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
+ struct darwin_transfer_priv *tpriv = usbi_get_transfer_priv(itransfer);
usbi_dbg ("an async io operation has completed");
static int darwin_handle_transfer_completion (struct usbi_transfer *itransfer) {
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct darwin_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
+ struct darwin_transfer_priv *tpriv = usbi_get_transfer_priv(itransfer);
bool isIsoc = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS == transfer->type;
bool isBulk = LIBUSB_TRANSFER_TYPE_BULK == transfer->type;
bool isControl = LIBUSB_TRANSFER_TYPE_CONTROL == transfer->type;
usbi_dbg("device allocation failed");
continue;
}
- *((USBDevice **)dev->os_priv) = fDevice;
+ *((USBDevice **)usbi_get_device_priv(dev)) = fDevice;
// Calculate pseudo-device-address
int addr, tmp;
USBDeviceHandle::SubmitTransfer(struct usbi_transfer *itransfer)
{
USBTransfer *transfer = new USBTransfer(itransfer, fUSBDevice);
- *((USBTransfer **)usbi_transfer_get_os_priv(itransfer)) = transfer;
+ *((USBTransfer **)usbi_get_transfer_priv(itransfer)) = transfer;
BAutolock locker(fTransfersLock);
fTransfers.AddItem(transfer);
release_sem(fTransfersSem);
static int
haiku_open(struct libusb_device_handle *dev_handle)
{
- USBDevice *dev = *((USBDevice **)dev_handle->dev->os_priv);
+ USBDevice *dev = *((USBDevice **)usbi_get_device_priv(dev_handle->dev));
USBDeviceHandle *handle = new(std::nothrow) USBDeviceHandle(dev);
if (handle == NULL)
return LIBUSB_ERROR_NO_MEM;
delete handle;
return LIBUSB_ERROR_NO_DEVICE;
}
- *((USBDeviceHandle **)dev_handle->os_priv) = handle;
+ *((USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle)) = handle;
return LIBUSB_SUCCESS;
}
static void
haiku_close(struct libusb_device_handle *dev_handle)
{
- USBDeviceHandle *handle = *((USBDeviceHandle **)dev_handle->os_priv);
+ USBDeviceHandle **pHandle = (USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle);
+ USBDeviceHandle *handle = *pHandle;
if (handle == NULL)
return;
delete handle;
- *((USBDeviceHandle **)dev_handle->os_priv) = NULL;
+ *pHandle = NULL;
}
static int
haiku_get_device_descriptor(struct libusb_device *device, unsigned char *buffer, int *host_endian)
{
- USBDevice *dev = *((USBDevice **)device->os_priv);
+ USBDevice *dev = *((USBDevice **)usbi_get_device_priv(device));
memcpy(buffer, dev->Descriptor(), DEVICE_DESC_LENGTH);
*host_endian = 0;
return LIBUSB_SUCCESS;
static int
haiku_get_active_config_descriptor(struct libusb_device *device, unsigned char *buffer, size_t len, int *host_endian)
{
- USBDevice *dev = *((USBDevice **)device->os_priv);
+ USBDevice *dev = *((USBDevice **)usbi_get_device_priv(device));
return haiku_get_config_descriptor(device, dev->ActiveConfigurationIndex(), buffer, len, host_endian);
}
static int
haiku_get_config_descriptor(struct libusb_device *device, uint8_t config_index, unsigned char *buffer, size_t len, int *host_endian)
{
- USBDevice *dev = *((USBDevice **)device->os_priv);
+ USBDevice *dev = *((USBDevice **)usbi_get_device_priv(device));
const usb_configuration_descriptor *config = dev->ConfigurationDescriptor(config_index);
if (config == NULL) {
usbi_err(DEVICE_CTX(device), "failed getting configuration descriptor");
static int
haiku_set_configuration(struct libusb_device_handle *dev_handle, int config)
{
- USBDeviceHandle *handle= *((USBDeviceHandle **)dev_handle->os_priv);
+ USBDeviceHandle *handle= *((USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle));
return handle->SetConfiguration(config);
}
static int
haiku_claim_interface(struct libusb_device_handle *dev_handle, int interface_number)
{
- USBDeviceHandle *handle = *((USBDeviceHandle **)dev_handle->os_priv);
+ USBDeviceHandle *handle = *((USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle));
return handle->ClaimInterface(interface_number);
}
static int
haiku_set_altsetting(struct libusb_device_handle *dev_handle, int interface_number, int altsetting)
{
- USBDeviceHandle *handle = *((USBDeviceHandle **)dev_handle->os_priv);
+ USBDeviceHandle *handle = *((USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle));
return handle->SetAltSetting(interface_number, altsetting);
}
static int
haiku_clear_halt(struct libusb_device_handle *dev_handle, unsigned char endpoint)
{
- USBDeviceHandle *handle = *((USBDeviceHandle **)dev_handle->os_priv);
+ USBDeviceHandle *handle = *((USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle));
return handle->ClearHalt(endpoint);
}
static int
haiku_release_interface(struct libusb_device_handle *dev_handle, int interface_number)
{
- USBDeviceHandle *handle = *((USBDeviceHandle **)dev_handle->os_priv);
+ USBDeviceHandle *handle = *((USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle));
haiku_set_altsetting(dev_handle,interface_number, 0);
return handle->ReleaseInterface(interface_number);
}
haiku_submit_transfer(struct usbi_transfer *itransfer)
{
struct libusb_transfer *fLibusbTransfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- USBDeviceHandle *fDeviceHandle = *((USBDeviceHandle **)fLibusbTransfer->dev_handle->os_priv);
+ USBDeviceHandle *fDeviceHandle = *((USBDeviceHandle **)usbi_get_device_handle_priv(fLibusbTransfer->dev_handle));
return fDeviceHandle->SubmitTransfer(itransfer);
}
haiku_cancel_transfer(struct usbi_transfer *itransfer)
{
struct libusb_transfer *fLibusbTransfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- USBDeviceHandle *fDeviceHandle = *((USBDeviceHandle **)fLibusbTransfer->dev_handle->os_priv);
- return fDeviceHandle->CancelTransfer(*((USBTransfer **)usbi_transfer_get_os_priv(itransfer)));
+ USBDeviceHandle *fDeviceHandle = *((USBDeviceHandle **)usbi_get_device_handle_priv(fLibusbTransfer->dev_handle));
+ return fDeviceHandle->CancelTransfer(*((USBTransfer **)usbi_get_transfer_priv(itransfer)));
}
static int
haiku_handle_transfer_completion(struct usbi_transfer *itransfer)
{
- USBTransfer *transfer = *((USBTransfer **)usbi_transfer_get_os_priv(itransfer));
+ USBTransfer **pTransfer = (USBTransfer **)usbi_get_transfer_priv(itransfer);
+ USBTransfer *transfer = *pTransfer;
usbi_mutex_lock(&itransfer->lock);
if (transfer->IsCancelled()) {
delete transfer;
- *((USBTransfer **)usbi_transfer_get_os_priv(itransfer)) = NULL;
+ *pTransfer = NULL;
usbi_mutex_unlock(&itransfer->lock);
if (itransfer->transferred < 0)
itransfer->transferred = 0;
itransfer->transferred = 0;
}
delete transfer;
- *((USBTransfer **)usbi_transfer_get_os_priv(itransfer)) = NULL;
+ *pTransfer = NULL;
usbi_mutex_unlock(&itransfer->lock);
return usbi_handle_transfer_completion(itransfer, status);
}
return LIBUSB_ERROR_IO;
}
-static struct linux_device_priv *_device_priv(struct libusb_device *dev)
-{
- return (struct linux_device_priv *)dev->os_priv;
-}
-
-static struct linux_device_handle_priv *_device_handle_priv(
- struct libusb_device_handle *handle)
-{
- return (struct linux_device_handle_priv *)handle->os_priv;
-}
-
/* check dirent for a /dev/usbdev%d.%d name
* optionally return bus/device on success */
static int is_usbdev_entry(const char *name, uint8_t *bus_p, uint8_t *dev_p)
static int op_get_device_descriptor(struct libusb_device *dev,
unsigned char *buffer, int *host_endian)
{
- struct linux_device_priv *priv = _device_priv(dev);
+ struct linux_device_priv *priv = usbi_get_device_priv(dev);
*host_endian = priv->sysfs_dir != NULL;
memcpy(buffer, priv->descriptors, DEVICE_DESC_LENGTH);
/* read the bConfigurationValue for a device */
static int sysfs_get_active_config(struct libusb_device *dev, int *config)
{
- struct linux_device_priv *priv = _device_priv(dev);
+ struct linux_device_priv *priv = usbi_get_device_priv(dev);
int ret;
ret = read_sysfs_attr(DEVICE_CTX(dev), priv->sysfs_dir, "bConfigurationValue",
unsigned char *buffer, int size)
{
struct libusb_context *ctx = DEVICE_CTX(dev);
- struct linux_device_priv *priv = _device_priv(dev);
+ struct linux_device_priv *priv = usbi_get_device_priv(dev);
struct libusb_config_descriptor config;
if (size == 0)
static int op_get_config_descriptor_by_value(struct libusb_device *dev,
uint8_t value, unsigned char **buffer, int *host_endian)
{
- struct linux_device_priv *priv = _device_priv(dev);
+ struct linux_device_priv *priv = usbi_get_device_priv(dev);
unsigned char *descriptors = priv->descriptors;
int size = priv->descriptors_len;
struct libusb_config_descriptor *config;
static int op_get_active_config_descriptor(struct libusb_device *dev,
unsigned char *buffer, size_t len, int *host_endian)
{
- struct linux_device_priv *priv = _device_priv(dev);
+ struct linux_device_priv *priv = usbi_get_device_priv(dev);
int r, config;
unsigned char *config_desc;
static int op_get_config_descriptor(struct libusb_device *dev,
uint8_t config_index, unsigned char *buffer, size_t len, int *host_endian)
{
- struct linux_device_priv *priv = _device_priv(dev);
+ struct linux_device_priv *priv = usbi_get_device_priv(dev);
unsigned char *descriptors = priv->descriptors;
int i, r, size = priv->descriptors_len;
/* send a control message to retrieve active configuration */
static int usbfs_get_active_config(struct libusb_device *dev, int fd)
{
- struct linux_device_priv *priv = _device_priv(dev);
+ struct linux_device_priv *priv = usbi_get_device_priv(dev);
unsigned char active_config = 0;
int r;
static int initialize_device(struct libusb_device *dev, uint8_t busnum,
uint8_t devaddr, const char *sysfs_dir, int wrapped_fd)
{
- struct linux_device_priv *priv = _device_priv(dev);
+ struct linux_device_priv *priv = usbi_get_device_priv(dev);
struct libusb_context *ctx = DEVICE_CTX(dev);
int descriptors_size = 0;
int fd, speed;
/* find the parent in the context */
usbi_mutex_lock(&ctx->usb_devs_lock);
list_for_each_entry(it, &ctx->usb_devs, list, struct libusb_device) {
- struct linux_device_priv *priv = _device_priv(it);
+ struct linux_device_priv *priv = usbi_get_device_priv(it);
if (priv->sysfs_dir) {
if (!strcmp(priv->sysfs_dir, parent_sysfs_dir)) {
static int initialize_handle(struct libusb_device_handle *handle, int fd)
{
- struct linux_device_handle_priv *hpriv = _device_handle_priv(handle);
+ struct linux_device_handle_priv *hpriv = usbi_get_device_handle_priv(handle);
int r;
hpriv->fd = fd;
static int op_wrap_sys_device(struct libusb_context *ctx,
struct libusb_device_handle *handle, intptr_t sys_dev)
{
- struct linux_device_handle_priv *hpriv = _device_handle_priv(handle);
+ struct linux_device_handle_priv *hpriv = usbi_get_device_handle_priv(handle);
int fd = (int)sys_dev;
uint8_t busnum, devaddr;
struct usbfs_connectinfo ci;
static void op_close(struct libusb_device_handle *dev_handle)
{
- struct linux_device_handle_priv *hpriv = _device_handle_priv(dev_handle);
+ struct linux_device_handle_priv *hpriv = usbi_get_device_handle_priv(dev_handle);
/* fd may have already been removed by POLLERR condition in op_handle_events() */
if (!hpriv->fd_removed)
static int op_get_configuration(struct libusb_device_handle *handle,
int *config)
{
- struct linux_device_priv *priv = _device_priv(handle->dev);
+ struct linux_device_priv *priv = usbi_get_device_priv(handle->dev);
int r;
if (priv->sysfs_dir) {
r = sysfs_get_active_config(handle->dev, config);
} else {
- r = usbfs_get_active_config(handle->dev, _device_handle_priv(handle)->fd);
+ struct linux_device_handle_priv *hpriv = usbi_get_device_handle_priv(handle);
+
+ r = usbfs_get_active_config(handle->dev, hpriv->fd);
if (r == LIBUSB_SUCCESS)
*config = priv->active_config;
}
static int op_set_configuration(struct libusb_device_handle *handle, int config)
{
- struct linux_device_priv *priv = _device_priv(handle->dev);
- int fd = _device_handle_priv(handle)->fd;
+ struct linux_device_priv *priv = usbi_get_device_priv(handle->dev);
+ struct linux_device_handle_priv *hpriv = usbi_get_device_handle_priv(handle);
+ int fd = hpriv->fd;
int r = ioctl(fd, IOCTL_USBFS_SETCONFIGURATION, &config);
if (r < 0) {
static int claim_interface(struct libusb_device_handle *handle, int iface)
{
- int fd = _device_handle_priv(handle)->fd;
+ struct linux_device_handle_priv *hpriv = usbi_get_device_handle_priv(handle);
+ int fd = hpriv->fd;
int r = ioctl(fd, IOCTL_USBFS_CLAIMINTERFACE, &iface);
if (r < 0) {
static int release_interface(struct libusb_device_handle *handle, int iface)
{
- int fd = _device_handle_priv(handle)->fd;
+ struct linux_device_handle_priv *hpriv = usbi_get_device_handle_priv(handle);
+ int fd = hpriv->fd;
int r = ioctl(fd, IOCTL_USBFS_RELEASEINTERFACE, &iface);
if (r < 0) {
static int op_set_interface(struct libusb_device_handle *handle, int iface,
int altsetting)
{
- int fd = _device_handle_priv(handle)->fd;
+ struct linux_device_handle_priv *hpriv = usbi_get_device_handle_priv(handle);
+ int fd = hpriv->fd;
struct usbfs_setinterface setintf;
int r;
static int op_clear_halt(struct libusb_device_handle *handle,
unsigned char endpoint)
{
- int fd = _device_handle_priv(handle)->fd;
+ struct linux_device_handle_priv *hpriv = usbi_get_device_handle_priv(handle);
+ int fd = hpriv->fd;
unsigned int _endpoint = endpoint;
int r = ioctl(fd, IOCTL_USBFS_CLEAR_HALT, &_endpoint);
static int op_reset_device(struct libusb_device_handle *handle)
{
- int fd = _device_handle_priv(handle)->fd;
+ struct linux_device_handle_priv *hpriv = usbi_get_device_handle_priv(handle);
+ int fd = hpriv->fd;
int i, r, ret = 0;
/* Doing a device reset will cause the usbfs driver to get unbound
static int do_streams_ioctl(struct libusb_device_handle *handle, long req,
uint32_t num_streams, unsigned char *endpoints, int num_endpoints)
{
- int r, fd = _device_handle_priv(handle)->fd;
+ struct linux_device_handle_priv *hpriv = usbi_get_device_handle_priv(handle);
+ int r, fd = hpriv->fd;
struct usbfs_streams *streams;
if (num_endpoints > 30) /* Max 15 in + 15 out eps */
static unsigned char *op_dev_mem_alloc(struct libusb_device_handle *handle,
size_t len)
{
- struct linux_device_handle_priv *hpriv = _device_handle_priv(handle);
+ struct linux_device_handle_priv *hpriv = usbi_get_device_handle_priv(handle);
unsigned char *buffer;
buffer = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, hpriv->fd, 0);
static int op_kernel_driver_active(struct libusb_device_handle *handle,
int interface)
{
- int fd = _device_handle_priv(handle)->fd;
+ struct linux_device_handle_priv *hpriv = usbi_get_device_handle_priv(handle);
+ int fd = hpriv->fd;
struct usbfs_getdriver getdrv;
int r;
static int op_detach_kernel_driver(struct libusb_device_handle *handle,
int interface)
{
- int fd = _device_handle_priv(handle)->fd;
+ struct linux_device_handle_priv *hpriv = usbi_get_device_handle_priv(handle);
+ int fd = hpriv->fd;
struct usbfs_ioctl command;
struct usbfs_getdriver getdrv;
int r;
static int op_attach_kernel_driver(struct libusb_device_handle *handle,
int interface)
{
- int fd = _device_handle_priv(handle)->fd;
+ struct linux_device_handle_priv *hpriv = usbi_get_device_handle_priv(handle);
+ int fd = hpriv->fd;
struct usbfs_ioctl command;
int r;
static int detach_kernel_driver_and_claim(struct libusb_device_handle *handle,
int interface)
{
+ struct linux_device_handle_priv *hpriv = usbi_get_device_handle_priv(handle);
struct usbfs_disconnect_claim dc;
- int r, fd = _device_handle_priv(handle)->fd;
+ int r, fd = hpriv->fd;
dc.interface = interface;
strcpy(dc.driver, "usbfs");
static void op_destroy_device(struct libusb_device *dev)
{
- struct linux_device_priv *priv = _device_priv(dev);
+ struct linux_device_priv *priv = usbi_get_device_priv(dev);
free(priv->descriptors);
free(priv->sysfs_dir);
{
struct libusb_transfer *transfer =
USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct linux_transfer_priv *tpriv =
- usbi_transfer_get_os_priv(itransfer);
- struct linux_device_handle_priv *dpriv =
- _device_handle_priv(transfer->dev_handle);
+ struct linux_transfer_priv *tpriv = usbi_get_transfer_priv(itransfer);
+ struct linux_device_handle_priv *hpriv =
+ usbi_get_device_handle_priv(transfer->dev_handle);
int i, ret = 0;
struct usbfs_urb *urb;
else
urb = &tpriv->urbs[i];
- if (ioctl(dpriv->fd, IOCTL_USBFS_DISCARDURB, urb) == 0)
+ if (ioctl(hpriv->fd, IOCTL_USBFS_DISCARDURB, urb) == 0)
continue;
if (errno == EINVAL) {
{
struct libusb_transfer *transfer =
USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct linux_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
- struct linux_device_handle_priv *dpriv =
- _device_handle_priv(transfer->dev_handle);
+ struct linux_transfer_priv *tpriv = usbi_get_transfer_priv(itransfer);
+ struct linux_device_handle_priv *hpriv =
+ usbi_get_device_handle_priv(transfer->dev_handle);
struct usbfs_urb *urbs;
int is_out = IS_XFEROUT(transfer);
int bulk_buffer_len, use_bulk_continuation;
* short split-transfers to work reliable USBFS_CAP_BULK_CONTINUATION
* is needed, but this is not always available.
*/
- if (dpriv->caps & USBFS_CAP_BULK_SCATTER_GATHER) {
+ if (hpriv->caps & USBFS_CAP_BULK_SCATTER_GATHER) {
/* Good! Just submit everything in one go */
bulk_buffer_len = transfer->length ? transfer->length : 1;
use_bulk_continuation = 0;
- } else if (dpriv->caps & USBFS_CAP_BULK_CONTINUATION) {
+ } else if (hpriv->caps & USBFS_CAP_BULK_CONTINUATION) {
/* Split the transfers and use bulk-continuation to
avoid issues with short-transfers */
bulk_buffer_len = MAX_BULK_BUFFER_LENGTH;
use_bulk_continuation = 1;
- } else if (dpriv->caps & USBFS_CAP_NO_PACKET_SIZE_LIM) {
+ } else if (hpriv->caps & USBFS_CAP_NO_PACKET_SIZE_LIM) {
/* Don't split, assume the kernel can alloc the buffer
(otherwise the submit will fail with -ENOMEM) */
bulk_buffer_len = transfer->length ? transfer->length : 1;
(transfer->flags & LIBUSB_TRANSFER_ADD_ZERO_PACKET))
urb->flags |= USBFS_URB_ZERO_PACKET;
- r = ioctl(dpriv->fd, IOCTL_USBFS_SUBMITURB, urb);
+ r = ioctl(hpriv->fd, IOCTL_USBFS_SUBMITURB, urb);
if (r == 0)
continue;
{
struct libusb_transfer *transfer =
USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct linux_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
- struct linux_device_handle_priv *dpriv =
- _device_handle_priv(transfer->dev_handle);
+ struct linux_transfer_priv *tpriv = usbi_get_transfer_priv(itransfer);
+ struct linux_device_handle_priv *hpriv =
+ usbi_get_device_handle_priv(transfer->dev_handle);
struct usbfs_urb **urbs;
int num_packets = transfer->num_iso_packets;
int num_packets_remaining;
/* submit URBs */
for (i = 0; i < num_urbs; i++) {
- int r = ioctl(dpriv->fd, IOCTL_USBFS_SUBMITURB, urbs[i]);
+ int r = ioctl(hpriv->fd, IOCTL_USBFS_SUBMITURB, urbs[i]);
if (r == 0)
continue;
static int submit_control_transfer(struct usbi_transfer *itransfer)
{
- struct linux_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
+ struct linux_transfer_priv *tpriv = usbi_get_transfer_priv(itransfer);
struct libusb_transfer *transfer =
USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct linux_device_handle_priv *dpriv =
- _device_handle_priv(transfer->dev_handle);
+ struct linux_device_handle_priv *hpriv =
+ usbi_get_device_handle_priv(transfer->dev_handle);
struct usbfs_urb *urb;
int r;
urb->buffer = transfer->buffer;
urb->buffer_length = transfer->length;
- r = ioctl(dpriv->fd, IOCTL_USBFS_SUBMITURB, urb);
+ r = ioctl(hpriv->fd, IOCTL_USBFS_SUBMITURB, urb);
if (r < 0) {
free(urb);
tpriv->urbs = NULL;
static int op_cancel_transfer(struct usbi_transfer *itransfer)
{
- struct linux_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
+ struct linux_transfer_priv *tpriv = usbi_get_transfer_priv(itransfer);
struct libusb_transfer *transfer =
USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
int r;
{
struct libusb_transfer *transfer =
USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct linux_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
+ struct linux_transfer_priv *tpriv = usbi_get_transfer_priv(itransfer);
switch (transfer->type) {
case LIBUSB_TRANSFER_TYPE_CONTROL:
static int handle_bulk_completion(struct usbi_transfer *itransfer,
struct usbfs_urb *urb)
{
- struct linux_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
+ struct linux_transfer_priv *tpriv = usbi_get_transfer_priv(itransfer);
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
int urb_idx = urb - tpriv->urbs;
{
struct libusb_transfer *transfer =
USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct linux_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
+ struct linux_transfer_priv *tpriv = usbi_get_transfer_priv(itransfer);
int num_urbs = tpriv->num_urbs;
int urb_idx = 0;
int i;
static int handle_control_completion(struct usbi_transfer *itransfer,
struct usbfs_urb *urb)
{
- struct linux_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
+ struct linux_transfer_priv *tpriv = usbi_get_transfer_priv(itransfer);
int status;
usbi_mutex_lock(&itransfer->lock);
static int reap_for_handle(struct libusb_device_handle *handle)
{
- struct linux_device_handle_priv *hpriv = _device_handle_priv(handle);
+ struct linux_device_handle_priv *hpriv = usbi_get_device_handle_priv(handle);
int r;
struct usbfs_urb *urb = NULL;
struct usbi_transfer *itransfer;
num_ready--;
list_for_each_entry(handle, &ctx->open_devs, list, struct libusb_device_handle) {
- hpriv = _device_handle_priv(handle);
+ hpriv = usbi_get_device_handle_priv(handle);
if (hpriv->fd == pollfd->fd)
break;
}
dev->device_address = di.udi_addr;
dev->speed = di.udi_speed;
- dpriv = (struct device_priv *)dev->os_priv;
+ dpriv = usbi_get_device_priv(dev);
strlcpy(dpriv->devnode, devnode, sizeof(devnode));
dpriv->fd = -1;
int
netbsd_open(struct libusb_device_handle *handle)
{
- struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
- struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
+ struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
+ struct handle_priv *hpriv = usbi_get_device_handle_priv(handle);
int i;
dpriv->fd = open(dpriv->devnode, O_RDWR);
void
netbsd_close(struct libusb_device_handle *handle)
{
- struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
+ struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
usbi_dbg("close: fd %d", dpriv->fd);
netbsd_get_device_descriptor(struct libusb_device *dev, unsigned char *buf,
int *host_endian)
{
- struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
+ struct device_priv *dpriv = usbi_get_device_priv(dev);
usbi_dbg(" ");
netbsd_get_active_config_descriptor(struct libusb_device *dev,
unsigned char *buf, size_t len, int *host_endian)
{
- struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
+ struct device_priv *dpriv = usbi_get_device_priv(dev);
usb_config_descriptor_t *ucd;
ucd = (usb_config_descriptor_t *) dpriv->cdesc;
netbsd_get_config_descriptor(struct libusb_device *dev, uint8_t idx,
unsigned char *buf, size_t len, int *host_endian)
{
- struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
+ struct device_priv *dpriv = usbi_get_device_priv(dev);
struct usb_full_desc ufd;
int fd, err;
int
netbsd_get_configuration(struct libusb_device_handle *handle, int *config)
{
- struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
+ struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
usbi_dbg(" ");
int
netbsd_set_configuration(struct libusb_device_handle *handle, int config)
{
- struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
+ struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
usbi_dbg("configuration %d", config);
int
netbsd_claim_interface(struct libusb_device_handle *handle, int iface)
{
- struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
+ struct handle_priv *hpriv = usbi_get_device_handle_priv(handle);
int i;
for (i = 0; i < USB_MAX_ENDPOINTS; i++)
int
netbsd_release_interface(struct libusb_device_handle *handle, int iface)
{
- struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
+ struct handle_priv *hpriv = usbi_get_device_handle_priv(handle);
int i;
for (i = 0; i < USB_MAX_ENDPOINTS; i++)
netbsd_set_interface_altsetting(struct libusb_device_handle *handle, int iface,
int altsetting)
{
- struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
+ struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
struct usb_alt_interface intf;
usbi_dbg("iface %d, setting %d", iface, altsetting);
int
netbsd_clear_halt(struct libusb_device_handle *handle, unsigned char endpoint)
{
- struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
+ struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
struct usb_ctl_request req;
usbi_dbg(" ");
void
netbsd_destroy_device(struct libusb_device *dev)
{
- struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
+ struct device_priv *dpriv = usbi_get_device_priv(dev);
usbi_dbg(" ");
usbi_dbg(" ");
transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- hpriv = (struct handle_priv *)transfer->dev_handle->os_priv;
+ hpriv = usbi_get_device_handle_priv(transfer->dev_handle);
switch (transfer->type) {
case LIBUSB_TRANSFER_TYPE_CONTROL:
int
_cache_active_config_descriptor(struct libusb_device *dev, int fd)
{
- struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
+ struct device_priv *dpriv = usbi_get_device_priv(dev);
struct usb_config_desc ucd;
struct usb_full_desc ufd;
unsigned char* buf;
struct usb_ctl_request req;
transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- dpriv = (struct device_priv *)transfer->dev_handle->dev->os_priv;
+ dpriv = usbi_get_device_priv(transfer->dev_handle->dev);
setup = (struct libusb_control_setup *)transfer->buffer;
usbi_dbg("type %d request %d value %d index %d length %d timeout %d",
int fd, endpt;
mode_t mode;
- hpriv = (struct handle_priv *)transfer->dev_handle->os_priv;
- dpriv = (struct device_priv *)transfer->dev_handle->dev->os_priv;
+ hpriv = usbi_get_device_handle_priv(transfer->dev_handle);
+ dpriv = usbi_get_device_priv(transfer->dev_handle->dev);
endpt = UE_GET_ADDR(transfer->endpoint);
mode = IS_XFERIN(transfer) ? O_RDONLY : O_WRONLY;
dev->device_address = di.udi_addr;
dev->speed = di.udi_speed;
- dpriv = (struct device_priv *)dev->os_priv;
+ dpriv = usbi_get_device_priv(dev);
dpriv->fd = -1;
dpriv->cdesc = NULL;
dpriv->devname = udevname;
int
obsd_open(struct libusb_device_handle *handle)
{
- struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
+ struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
char devnode[16];
if (dpriv->devname) {
void
obsd_close(struct libusb_device_handle *handle)
{
- struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
+ struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
if (dpriv->devname) {
usbi_dbg("close: fd %d", dpriv->fd);
obsd_get_device_descriptor(struct libusb_device *dev, unsigned char *buf,
int *host_endian)
{
- struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
+ struct device_priv *dpriv = usbi_get_device_priv(dev);
usbi_dbg(" ");
obsd_get_active_config_descriptor(struct libusb_device *dev,
unsigned char *buf, size_t len, int *host_endian)
{
- struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
+ struct device_priv *dpriv = usbi_get_device_priv(dev);
usb_config_descriptor_t *ucd = (usb_config_descriptor_t *)dpriv->cdesc;
len = MIN(len, UGETW(ucd->wTotalLength));
int
obsd_get_configuration(struct libusb_device_handle *handle, int *config)
{
- struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
+ struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
usb_config_descriptor_t *ucd = (usb_config_descriptor_t *)dpriv->cdesc;
*config = ucd->bConfigurationValue;
int
obsd_set_configuration(struct libusb_device_handle *handle, int config)
{
- struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
+ struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
if (dpriv->devname == NULL)
return (LIBUSB_ERROR_NOT_SUPPORTED);
int
obsd_claim_interface(struct libusb_device_handle *handle, int iface)
{
- struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
+ struct handle_priv *hpriv = usbi_get_device_handle_priv(handle);
int i;
for (i = 0; i < USB_MAX_ENDPOINTS; i++)
int
obsd_release_interface(struct libusb_device_handle *handle, int iface)
{
- struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
+ struct handle_priv *hpriv = usbi_get_device_handle_priv(handle);
int i;
for (i = 0; i < USB_MAX_ENDPOINTS; i++)
obsd_set_interface_altsetting(struct libusb_device_handle *handle, int iface,
int altsetting)
{
- struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
+ struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
struct usb_alt_interface intf;
if (dpriv->devname == NULL)
void
obsd_destroy_device(struct libusb_device *dev)
{
- struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
+ struct device_priv *dpriv = usbi_get_device_priv(dev);
usbi_dbg(" ");
usbi_dbg(" ");
transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- hpriv = (struct handle_priv *)transfer->dev_handle->os_priv;
+ hpriv = usbi_get_device_handle_priv(transfer->dev_handle);
switch (transfer->type) {
case LIBUSB_TRANSFER_TYPE_CONTROL:
int
_cache_active_config_descriptor(struct libusb_device *dev)
{
- struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
+ struct device_priv *dpriv = usbi_get_device_priv(dev);
struct usb_device_cdesc udc;
struct usb_device_fdesc udf;
unsigned char* buf;
struct usb_ctl_request req;
transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- dpriv = (struct device_priv *)transfer->dev_handle->dev->os_priv;
+ dpriv = usbi_get_device_priv(transfer->dev_handle->dev);
setup = (struct libusb_control_setup *)transfer->buffer;
usbi_dbg("type %x request %x value %x index %d length %d timeout %d",
int fd, endpt;
mode_t mode;
- hpriv = (struct handle_priv *)transfer->dev_handle->os_priv;
- dpriv = (struct device_priv *)transfer->dev_handle->dev->os_priv;
+ hpriv = usbi_get_device_handle_priv(transfer->dev_handle);
+ dpriv = usbi_get_device_priv(transfer->dev_handle->dev);
endpt = UE_GET_ADDR(transfer->endpoint);
mode = IS_XFERIN(transfer) ? O_RDONLY : O_WRONLY;
int fd, nr = 1;
transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- dpriv = (struct device_priv *)transfer->dev_handle->dev->os_priv;
+ dpriv = usbi_get_device_priv(transfer->dev_handle->dev);
if (dpriv->devname == NULL)
return (LIBUSB_ERROR_NOT_SUPPORTED);
sunos_dev_priv_t *dpriv;
devctl_ap_state_t devctl_ap_state;
- dpriv = (sunos_dev_priv_t *)dev->os_priv;
+ dpriv = usbi_get_device_priv(dev);
phypath = dpriv->phypath;
end = strrchr(phypath, '/');
sunos_kernel_driver_active(struct libusb_device_handle *dev, int interface)
{
sunos_dev_priv_t *dpriv;
- dpriv = (sunos_dev_priv_t *)dev->dev->os_priv;
+ dpriv = usbi_get_device_priv(dev->dev);
usbi_dbg("%s", dpriv->ugenpath);
sunos_dev_priv_t *dpriv;
int r;
- dpriv = (sunos_dev_priv_t *)dev_handle->dev->os_priv;
+ dpriv = usbi_get_device_priv(dev_handle->dev);
snprintf(path_arg, sizeof(path_arg), "\'\"%s\"\'", dpriv->phypath);
usbi_dbg("%s", path_arg);
return (LIBUSB_ERROR_IO);
}
- return sunos_usb_open_ep0((sunos_dev_handle_priv_t *)dev_handle->os_priv, dpriv);
+ return sunos_usb_open_ep0(usbi_get_device_handle_priv(dev_handle), dpriv);
}
static int
/* we open the dev in detach driver, so we need close it first. */
sunos_close(dev_handle);
- dpriv = (sunos_dev_priv_t *)dev_handle->dev->os_priv;
+ dpriv = usbi_get_device_priv(dev_handle->dev);
snprintf(path_arg, sizeof(path_arg), "\'\"%s\"\'", dpriv->phypath);
usbi_dbg("%s", path_arg);
char *phypath;
uint8_t *rdata;
struct libusb_device_descriptor *descr;
- sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)dev->os_priv;
+ sunos_dev_priv_t *dpriv = usbi_get_device_priv(dev);
char match_str[PATH_MAX];
/* Device descriptors */
usbi_dbg("can't alloc device");
continue;
}
- devpriv = (sunos_dev_priv_t *)dev->os_priv;
+ devpriv = usbi_get_device_priv(dev);
dev->bus_number = bus_number;
if (sunos_fill_in_dev_info(dn, dev) != LIBUSB_SUCCESS) {
return (DI_WALK_TERMINATE);
}
} else {
- devpriv = (sunos_dev_priv_t *)dev->os_priv;
+ devpriv = usbi_get_device_priv(dev);
usbi_dbg("Dev %s exists", devpriv->ugenpath);
}
sunos_dev_handle_priv_t *hpriv;
usbi_dbg("open ep 0x%02x", ep_addr);
- hpriv = (sunos_dev_handle_priv_t *)hdl->os_priv;
+ hpriv = usbi_get_device_handle_priv(hdl);
ep_index = sunos_usb_ep_index(ep_addr);
/* ep already opened */
if ((hpriv->eps[ep_index].datafd > 0) &&
int i;
int ret;
- hpriv = (sunos_dev_handle_priv_t *)handle->os_priv;
- dpriv = (sunos_dev_priv_t *)handle->dev->os_priv;
+ hpriv = usbi_get_device_handle_priv(handle);
+ dpriv = usbi_get_device_priv(handle->dev);
hpriv->dpriv = dpriv;
/* set all file descriptors to "closed" */
return;
}
- hpriv = (sunos_dev_handle_priv_t *)handle->os_priv;
+ hpriv = usbi_get_device_handle_priv(handle);
if (!hpriv) {
return;
}
- dpriv = (sunos_dev_priv_t *)handle->dev->os_priv;
+ dpriv = usbi_get_device_priv(handle->dev);
if (!dpriv) {
return;
}
sunos_get_device_descriptor(struct libusb_device *dev, uint8_t *buf,
int *host_endian)
{
- sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)dev->os_priv;
+ sunos_dev_priv_t *dpriv = usbi_get_device_priv(dev);
memcpy(buf, &dpriv->dev_descr, LIBUSB_DT_DEVICE_SIZE);
*host_endian = 0;
sunos_get_active_config_descriptor(struct libusb_device *dev,
uint8_t *buf, size_t len, int *host_endian)
{
- sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)dev->os_priv;
+ sunos_dev_priv_t *dpriv = usbi_get_device_priv(dev);
struct libusb_config_descriptor *cfg;
int proplen;
di_node_t node;
int
sunos_get_configuration(struct libusb_device_handle *handle, int *config)
{
- sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)handle->dev->os_priv;
+ sunos_dev_priv_t *dpriv = usbi_get_device_priv(handle->dev);
*config = dpriv->cfgvalue;
int
sunos_set_configuration(struct libusb_device_handle *handle, int config)
{
- sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)handle->dev->os_priv;
+ sunos_dev_priv_t *dpriv = usbi_get_device_priv(handle->dev);
sunos_dev_handle_priv_t *hpriv;
usbi_dbg("bConfigurationValue %d", config);
- hpriv = (sunos_dev_handle_priv_t *)handle->os_priv;
+ hpriv = usbi_get_device_handle_priv(handle);
if (dpriv->ugenpath == NULL)
return (LIBUSB_ERROR_NOT_SUPPORTED);
int
sunos_release_interface(struct libusb_device_handle *handle, int iface)
{
- sunos_dev_handle_priv_t *hpriv =
- (sunos_dev_handle_priv_t *)handle->os_priv;
+ sunos_dev_handle_priv_t *hpriv = usbi_get_device_handle_priv(handle);
usbi_dbg("iface %d", iface);
if (iface < 0) {
sunos_set_interface_altsetting(struct libusb_device_handle *handle, int iface,
int altsetting)
{
- sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)handle->dev->os_priv;
- sunos_dev_handle_priv_t *hpriv =
- (sunos_dev_handle_priv_t *)handle->os_priv;
+ sunos_dev_priv_t *dpriv = usbi_get_device_priv(handle->dev);
+ sunos_dev_handle_priv_t *hpriv = usbi_get_device_handle_priv(handle);
usbi_dbg("iface %d, setting %d", iface, altsetting);
/* libusb can forcibly interrupt transfer in do_close() */
if (dev_handle != NULL) {
- hpriv = (sunos_dev_handle_priv_t *)dev_handle->os_priv;
+ hpriv = usbi_get_device_handle_priv(dev_handle);
ep = sunos_usb_ep_index(xfer->endpoint);
ret = aio_error(aiocb);
usbi_dbg(" ");
- tpriv = usbi_transfer_get_os_priv(LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer));
- hpriv = (sunos_dev_handle_priv_t *)transfer->dev_handle->os_priv;
+ tpriv = usbi_get_transfer_priv(LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer));
+ hpriv = usbi_get_device_handle_priv(transfer->dev_handle);
ep = sunos_usb_ep_index(transfer->endpoint);
tpriv->transfer = transfer;
uint16_t wLength;
uint8_t *data = transfer->buffer;
- hpriv = (sunos_dev_handle_priv_t *)hdl->os_priv;
+ hpriv = usbi_get_device_handle_priv(hdl);
wLength = transfer->length - LIBUSB_CONTROL_SETUP_SIZE;
if (hpriv->eps[0].datafd == -1) {
void
sunos_destroy_device(struct libusb_device *dev)
{
- sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)dev->os_priv;
+ sunos_dev_priv_t *dpriv = usbi_get_device_priv(dev);
usbi_dbg("destroy everyting");
free(dpriv->raw_cfgdescr);
free(dpriv->ugenpath);
uint8_t ep;
int ret;
- tpriv = usbi_transfer_get_os_priv(itransfer);
+ tpriv = usbi_get_transfer_priv(itransfer);
aiocb = &tpriv->aiocb;
transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- hpriv = (sunos_dev_handle_priv_t *)transfer->dev_handle->os_priv;
+ hpriv = usbi_get_device_handle_priv(transfer->dev_handle);
ep = sunos_usb_ep_index(transfer->endpoint);
ret = aio_cancel(hpriv->eps[ep].datafd, aiocb);
}
#endif
-static inline struct windows_context_priv *_context_priv(struct libusb_context *ctx)
-{
- return (struct windows_context_priv *)ctx->os_priv;
-}
-
/* Hash table functions - modified From glibc 2.3.2:
[Aho,Sethi,Ullman] Compilers: Principles, Techniques and Tools, 1986
[Knuth] The Art of Computer Programming, part 3 (6.4) */
static void windows_transfer_callback(const struct windows_backend *backend,
struct usbi_transfer *itransfer, DWORD error, DWORD bytes_transferred)
{
- struct windows_transfer_priv *transfer_priv = get_transfer_priv(itransfer);
+ struct windows_transfer_priv *transfer_priv = usbi_get_transfer_priv(itransfer);
enum libusb_transfer_status status, istatus;
usbi_dbg("handling I/O completion with errcode %lu, length %lu",
static int windows_init(struct libusb_context *ctx)
{
- struct windows_context_priv *priv = _context_priv(ctx);
+ struct windows_context_priv *priv = usbi_get_context_priv(ctx);
char mutex_name[11 + 8 + 1]; // strlen("libusb_init") + (32-bit hex PID) + '\0'
HANDLE mutex;
int r = LIBUSB_ERROR_OTHER;
static int windows_set_option(struct libusb_context *ctx, enum libusb_option option, va_list ap)
{
- struct windows_context_priv *priv = _context_priv(ctx);
+ struct windows_context_priv *priv = usbi_get_context_priv(ctx);
UNUSED(ap);
static int windows_get_device_list(struct libusb_context *ctx, struct discovered_devs **discdevs)
{
- struct windows_context_priv *priv = _context_priv(ctx);
+ struct windows_context_priv *priv = usbi_get_context_priv(ctx);
return priv->backend->get_device_list(ctx, discdevs);
}
static int windows_open(struct libusb_device_handle *dev_handle)
{
- struct windows_context_priv *priv = _context_priv(HANDLE_CTX(dev_handle));
+ struct windows_context_priv *priv = usbi_get_context_priv(HANDLE_CTX(dev_handle));
return priv->backend->open(dev_handle);
}
static void windows_close(struct libusb_device_handle *dev_handle)
{
- struct windows_context_priv *priv = _context_priv(HANDLE_CTX(dev_handle));
+ struct windows_context_priv *priv = usbi_get_context_priv(HANDLE_CTX(dev_handle));
priv->backend->close(dev_handle);
}
static int windows_get_device_descriptor(struct libusb_device *dev,
unsigned char *buffer, int *host_endian)
{
- struct windows_context_priv *priv = _context_priv(DEVICE_CTX(dev));
+ struct windows_context_priv *priv = usbi_get_context_priv(DEVICE_CTX(dev));
*host_endian = 0;
return priv->backend->get_device_descriptor(dev, buffer);
}
static int windows_get_active_config_descriptor(struct libusb_device *dev,
unsigned char *buffer, size_t len, int *host_endian)
{
- struct windows_context_priv *priv = _context_priv(DEVICE_CTX(dev));
+ struct windows_context_priv *priv = usbi_get_context_priv(DEVICE_CTX(dev));
*host_endian = 0;
return priv->backend->get_active_config_descriptor(dev, buffer, len);
}
static int windows_get_config_descriptor(struct libusb_device *dev,
uint8_t config_index, unsigned char *buffer, size_t len, int *host_endian)
{
- struct windows_context_priv *priv = _context_priv(DEVICE_CTX(dev));
+ struct windows_context_priv *priv = usbi_get_context_priv(DEVICE_CTX(dev));
*host_endian = 0;
return priv->backend->get_config_descriptor(dev, config_index, buffer, len);
}
static int windows_get_config_descriptor_by_value(struct libusb_device *dev,
uint8_t bConfigurationValue, unsigned char **buffer, int *host_endian)
{
- struct windows_context_priv *priv = _context_priv(DEVICE_CTX(dev));
+ struct windows_context_priv *priv = usbi_get_context_priv(DEVICE_CTX(dev));
*host_endian = 0;
return priv->backend->get_config_descriptor_by_value(dev, bConfigurationValue, buffer);
}
static int windows_get_configuration(struct libusb_device_handle *dev_handle, int *config)
{
- struct windows_context_priv *priv = _context_priv(HANDLE_CTX(dev_handle));
+ struct windows_context_priv *priv = usbi_get_context_priv(HANDLE_CTX(dev_handle));
return priv->backend->get_configuration(dev_handle, config);
}
static int windows_set_configuration(struct libusb_device_handle *dev_handle, int config)
{
- struct windows_context_priv *priv = _context_priv(HANDLE_CTX(dev_handle));
+ struct windows_context_priv *priv = usbi_get_context_priv(HANDLE_CTX(dev_handle));
return priv->backend->set_configuration(dev_handle, config);
}
static int windows_claim_interface(struct libusb_device_handle *dev_handle, int interface_number)
{
- struct windows_context_priv *priv = _context_priv(HANDLE_CTX(dev_handle));
+ struct windows_context_priv *priv = usbi_get_context_priv(HANDLE_CTX(dev_handle));
return priv->backend->claim_interface(dev_handle, interface_number);
}
static int windows_release_interface(struct libusb_device_handle *dev_handle, int interface_number)
{
- struct windows_context_priv *priv = _context_priv(HANDLE_CTX(dev_handle));
+ struct windows_context_priv *priv = usbi_get_context_priv(HANDLE_CTX(dev_handle));
return priv->backend->release_interface(dev_handle, interface_number);
}
static int windows_set_interface_altsetting(struct libusb_device_handle *dev_handle,
int interface_number, int altsetting)
{
- struct windows_context_priv *priv = _context_priv(HANDLE_CTX(dev_handle));
+ struct windows_context_priv *priv = usbi_get_context_priv(HANDLE_CTX(dev_handle));
return priv->backend->set_interface_altsetting(dev_handle, interface_number, altsetting);
}
static int windows_clear_halt(struct libusb_device_handle *dev_handle, unsigned char endpoint)
{
- struct windows_context_priv *priv = _context_priv(HANDLE_CTX(dev_handle));
+ struct windows_context_priv *priv = usbi_get_context_priv(HANDLE_CTX(dev_handle));
return priv->backend->clear_halt(dev_handle, endpoint);
}
static int windows_reset_device(struct libusb_device_handle *dev_handle)
{
- struct windows_context_priv *priv = _context_priv(HANDLE_CTX(dev_handle));
+ struct windows_context_priv *priv = usbi_get_context_priv(HANDLE_CTX(dev_handle));
return priv->backend->reset_device(dev_handle);
}
static void windows_destroy_device(struct libusb_device *dev)
{
- struct windows_context_priv *priv = _context_priv(DEVICE_CTX(dev));
+ struct windows_context_priv *priv = usbi_get_context_priv(DEVICE_CTX(dev));
priv->backend->destroy_device(dev);
}
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct libusb_context *ctx = TRANSFER_CTX(transfer);
- struct windows_context_priv *priv = _context_priv(ctx);
- struct windows_transfer_priv *transfer_priv = get_transfer_priv(itransfer);
+ struct windows_context_priv *priv = usbi_get_context_priv(ctx);
+ struct windows_transfer_priv *transfer_priv = usbi_get_transfer_priv(itransfer);
short events;
int r;
static int windows_cancel_transfer(struct usbi_transfer *itransfer)
{
- struct windows_context_priv *priv = _context_priv(ITRANSFER_CTX(itransfer));
- struct windows_transfer_priv *transfer_priv = get_transfer_priv(itransfer);
+ struct windows_context_priv *priv = usbi_get_context_priv(ITRANSFER_CTX(itransfer));
+ struct windows_transfer_priv *transfer_priv = usbi_get_transfer_priv(itransfer);
// Try CancelIoEx() on the transfer
// If that fails, fall back to the backend's cancel_transfer()
static int windows_handle_events(struct libusb_context *ctx, struct pollfd *fds, usbi_nfds_t nfds, int num_ready)
{
- struct windows_context_priv *priv = _context_priv(ctx);
+ struct windows_context_priv *priv = usbi_get_context_priv(ctx);
struct usbi_transfer *itransfer;
struct windows_transfer_priv *transfer_priv;
DWORD result, bytes_transferred;
transfer_priv = NULL;
usbi_mutex_lock(&ctx->flying_transfers_lock);
list_for_each_entry(itransfer, &ctx->flying_transfers, list, struct usbi_transfer) {
- transfer_priv = get_transfer_priv(itransfer);
+ transfer_priv = usbi_get_transfer_priv(itransfer);
if (transfer_priv->pollable_fd.fd == fds[i].fd)
break;
transfer_priv = NULL;
};
};
-static inline struct windows_transfer_priv *get_transfer_priv(struct usbi_transfer *itransfer)
-{
- return (struct windows_transfer_priv *)usbi_transfer_get_os_priv(itransfer);
-}
-
static inline OVERLAPPED *get_transfer_priv_overlapped(struct usbi_transfer *itransfer)
{
- struct windows_transfer_priv *transfer_priv = get_transfer_priv(itransfer);
+ struct windows_transfer_priv *transfer_priv = usbi_get_transfer_priv(itransfer);
return transfer_priv->pollable_fd.overlapped;
}
static inline void set_transfer_priv_handle(struct usbi_transfer *itransfer, HANDLE handle)
{
- struct windows_transfer_priv *transfer_priv = get_transfer_priv(itransfer);
+ struct windows_transfer_priv *transfer_priv = usbi_get_transfer_priv(itransfer);
transfer_priv->handle = handle;
}
static inline struct usbdk_transfer_priv *get_usbdk_transfer_priv(struct usbi_transfer *itransfer)
{
- struct windows_transfer_priv *transfer_priv = get_transfer_priv(itransfer);
+ struct windows_transfer_priv *transfer_priv = usbi_get_transfer_priv(itransfer);
return &transfer_priv->usbdk_priv;
}
static inline struct winusb_transfer_priv *get_winusb_transfer_priv(struct usbi_transfer *itransfer)
{
- struct windows_transfer_priv *transfer_priv = get_transfer_priv(itransfer);
+ struct windows_transfer_priv *transfer_priv = usbi_get_transfer_priv(itransfer);
return &transfer_priv->winusb_priv;
}
#define STATUS_REQUEST_CANCELED ((NTSTATUS)0xC0000703L)
#endif
-static inline struct usbdk_device_priv *_usbdk_device_priv(struct libusb_device *dev)
-{
- return (struct usbdk_device_priv *)dev->os_priv;
-}
-
static struct {
HMODULE module;
return LIBUSB_SUCCESS;
}
-static void usbdk_release_config_descriptors(struct usbdk_device_priv *p, uint8_t count)
+static void usbdk_release_config_descriptors(struct usbdk_device_priv *priv, uint8_t count)
{
uint8_t i;
for (i = 0; i < count; i++)
- usbdk_helper.ReleaseConfigurationDescriptor(p->config_descriptors[i]);
+ usbdk_helper.ReleaseConfigurationDescriptor(priv->config_descriptors[i]);
- free(p->config_descriptors);
- p->config_descriptors = NULL;
+ free(priv->config_descriptors);
+ priv->config_descriptors = NULL;
}
static int usbdk_cache_config_descriptors(struct libusb_context *ctx,
- struct usbdk_device_priv *p, PUSB_DK_DEVICE_INFO info)
+ struct usbdk_device_priv *priv, PUSB_DK_DEVICE_INFO info)
{
uint8_t i;
USB_DK_CONFIG_DESCRIPTOR_REQUEST Request;
Request.ID = info->ID;
- p->config_descriptors = calloc(info->DeviceDescriptor.bNumConfigurations, sizeof(PUSB_CONFIGURATION_DESCRIPTOR));
- if (p->config_descriptors == NULL) {
+ priv->config_descriptors = calloc(info->DeviceDescriptor.bNumConfigurations, sizeof(PUSB_CONFIGURATION_DESCRIPTOR));
+ if (priv->config_descriptors == NULL) {
usbi_err(ctx, "failed to allocate configuration descriptors holder");
return LIBUSB_ERROR_NO_MEM;
}
ULONG Length;
Request.Index = i;
- if (!usbdk_helper.GetConfigurationDescriptor(&Request, &p->config_descriptors[i], &Length)) {
+ if (!usbdk_helper.GetConfigurationDescriptor(&Request, &priv->config_descriptors[i], &Length)) {
usbi_err(ctx, "failed to retrieve configuration descriptors");
- usbdk_release_config_descriptors(p, i);
+ usbdk_release_config_descriptors(priv, i);
return LIBUSB_ERROR_OTHER;
}
}
static inline int usbdk_device_priv_init(struct libusb_context *ctx, struct libusb_device *dev, PUSB_DK_DEVICE_INFO info)
{
- struct usbdk_device_priv *p = _usbdk_device_priv(dev);
+ struct usbdk_device_priv *priv = usbi_get_device_priv(dev);
- p->info = *info;
- p->active_configuration = 0;
+ priv->info = *info;
+ priv->active_configuration = 0;
- return usbdk_cache_config_descriptors(ctx, p, info);
+ return usbdk_cache_config_descriptors(ctx, priv, info);
}
static void usbdk_device_init(libusb_device *dev, PUSB_DK_DEVICE_INFO info)
static int usbdk_get_device_descriptor(struct libusb_device *dev, unsigned char *buffer)
{
- struct usbdk_device_priv *priv = _usbdk_device_priv(dev);
+ struct usbdk_device_priv *priv = usbi_get_device_priv(dev);
memcpy(buffer, &priv->info.DeviceDescriptor, DEVICE_DESC_LENGTH);
static int usbdk_get_config_descriptor(struct libusb_device *dev, uint8_t config_index, unsigned char *buffer, size_t len)
{
- struct usbdk_device_priv *priv = _usbdk_device_priv(dev);
+ struct usbdk_device_priv *priv = usbi_get_device_priv(dev);
PUSB_CONFIGURATION_DESCRIPTOR config_header;
size_t size;
static int usbdk_get_config_descriptor_by_value(struct libusb_device *dev, uint8_t bConfigurationValue,
unsigned char **buffer)
{
- struct usbdk_device_priv *priv = _usbdk_device_priv(dev);
+ struct usbdk_device_priv *priv = usbi_get_device_priv(dev);
PUSB_CONFIGURATION_DESCRIPTOR config_header;
uint8_t index;
static int usbdk_get_active_config_descriptor(struct libusb_device *dev, unsigned char *buffer, size_t len)
{
- return usbdk_get_config_descriptor(dev, _usbdk_device_priv(dev)->active_configuration,
- buffer, len);
+ struct usbdk_device_priv *priv = usbi_get_device_priv(dev);
+
+ return usbdk_get_config_descriptor(dev, priv->active_configuration, buffer, len);
}
static int usbdk_open(struct libusb_device_handle *dev_handle)
{
- struct usbdk_device_priv *priv = _usbdk_device_priv(dev_handle->dev);
+ struct usbdk_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
priv->redirector_handle = usbdk_helper.StartRedirect(&priv->info.ID);
if (priv->redirector_handle == INVALID_HANDLE_VALUE) {
static void usbdk_close(struct libusb_device_handle *dev_handle)
{
- struct usbdk_device_priv *priv = _usbdk_device_priv(dev_handle->dev);
+ struct usbdk_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
if (!usbdk_helper.StopRedirect(priv->redirector_handle))
usbi_err(HANDLE_CTX(dev_handle), "Redirector shutdown failed");
static int usbdk_get_configuration(struct libusb_device_handle *dev_handle, int *config)
{
- *config = _usbdk_device_priv(dev_handle->dev)->active_configuration;
+ struct usbdk_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
+
+ *config = priv->active_configuration;
return LIBUSB_SUCCESS;
}
static int usbdk_set_interface_altsetting(struct libusb_device_handle *dev_handle, int iface, int altsetting)
{
- struct usbdk_device_priv *priv = _usbdk_device_priv(dev_handle->dev);
+ struct usbdk_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
if (!usbdk_helper.SetAltsetting(priv->redirector_handle, iface, altsetting)) {
usbi_err(HANDLE_CTX(dev_handle), "SetAltsetting failed: %s", windows_error_str(0));
static int usbdk_clear_halt(struct libusb_device_handle *dev_handle, unsigned char endpoint)
{
- struct usbdk_device_priv *priv = _usbdk_device_priv(dev_handle->dev);
+ struct usbdk_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
if (!usbdk_helper.ResetPipe(priv->redirector_handle, endpoint)) {
usbi_err(HANDLE_CTX(dev_handle), "ResetPipe failed: %s", windows_error_str(0));
static int usbdk_reset_device(struct libusb_device_handle *dev_handle)
{
- struct usbdk_device_priv *priv = _usbdk_device_priv(dev_handle->dev);
+ struct usbdk_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
if (!usbdk_helper.ResetDevice(priv->redirector_handle)) {
usbi_err(HANDLE_CTX(dev_handle), "ResetDevice failed: %s", windows_error_str(0));
static void usbdk_destroy_device(struct libusb_device *dev)
{
- struct usbdk_device_priv* p = _usbdk_device_priv(dev);
+ struct usbdk_device_priv *priv = usbi_get_device_priv(dev);
- if (p->config_descriptors != NULL)
- usbdk_release_config_descriptors(p, p->info.DeviceDescriptor.bNumConfigurations);
+ if (priv->config_descriptors != NULL)
+ usbdk_release_config_descriptors(priv, priv->info.DeviceDescriptor.bNumConfigurations);
}
static void usbdk_clear_transfer_priv(struct usbi_transfer *itransfer)
static int usbdk_do_control_transfer(struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct usbdk_device_priv *priv = _usbdk_device_priv(transfer->dev_handle->dev);
+ struct usbdk_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
struct usbdk_transfer_priv *transfer_priv = get_usbdk_transfer_priv(itransfer);
OVERLAPPED *overlapped = get_transfer_priv_overlapped(itransfer);
TransferResult transResult;
static int usbdk_do_bulk_transfer(struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct usbdk_device_priv *priv = _usbdk_device_priv(transfer->dev_handle->dev);
+ struct usbdk_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
struct usbdk_transfer_priv *transfer_priv = get_usbdk_transfer_priv(itransfer);
OVERLAPPED *overlapped = get_transfer_priv_overlapped(itransfer);
TransferResult transferRes;
static int usbdk_do_iso_transfer(struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct usbdk_device_priv *priv = _usbdk_device_priv(transfer->dev_handle->dev);
+ struct usbdk_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
struct usbdk_transfer_priv *transfer_priv = get_usbdk_transfer_priv(itransfer);
OVERLAPPED *overlapped = get_transfer_priv_overlapped(itransfer);
TransferResult transferRes;
*/
static int windows_assign_endpoints(struct libusb_device_handle *dev_handle, int iface, int altsetting)
{
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
struct libusb_config_descriptor *conf_desc;
const struct libusb_interface_descriptor *if_desc;
int i, r;
*/
static int auto_claim(struct libusb_transfer *transfer, int *interface_number, int api_type)
{
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(
- transfer->dev_handle);
- struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv =
+ usbi_get_device_handle_priv(transfer->dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
int current_interface = *interface_number;
int r = LIBUSB_SUCCESS;
struct winusb_transfer_priv *transfer_priv = get_winusb_transfer_priv(itransfer);
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
libusb_device_handle *dev_handle = transfer->dev_handle;
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(dev_handle);
int r;
usbi_mutex_lock(&autoclaim_lock);
static void cache_config_descriptors(struct libusb_device *dev, HANDLE hub_handle)
{
struct libusb_context *ctx = DEVICE_CTX(dev);
- struct winusb_device_priv *priv = _device_priv(dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev);
DWORD size, ret_size;
uint8_t i;
{
struct libusb_context *ctx;
struct libusb_device *tmp_dev;
- struct winusb_device_priv *priv, *parent_priv;
+ struct winusb_device_priv *priv, *parent_priv, *tmp_priv;
USB_NODE_CONNECTION_INFORMATION_EX conn_info;
USB_NODE_CONNECTION_INFORMATION_EX_V2 conn_info_v2;
HANDLE hub_handle;
int r;
int ginfotimeout;
- priv = _device_priv(dev);
+ priv = usbi_get_device_priv(dev);
// If the device is already initialized, we can stop here
if (priv->initialized)
if (parent_dev != NULL) { // Not a HCD root hub
ctx = DEVICE_CTX(dev);
- parent_priv = _device_priv(parent_dev);
+ parent_priv = usbi_get_device_priv(parent_dev);
if (parent_priv->apib->id != USB_API_HUB) {
usbi_warn(ctx, "parent for device '%s' is not a hub", priv->dev_id);
return LIBUSB_ERROR_NOT_FOUND;
tmp_dev = get_ancestor(ctx, devinst, &devinst);
if (tmp_dev->bus_number != 0) {
bus_number = tmp_dev->bus_number;
- depth += _device_priv(tmp_dev)->depth;
+ tmp_priv = usbi_get_device_priv(tmp_dev);
+ depth += tmp_priv->depth;
}
libusb_unref_device(tmp_dev);
}
if (dev->bus_number == 0) {
// Only do this once
usbi_dbg("assigning HCD '%s' bus number %u", dev_id, bus_number);
- priv = _device_priv(dev);
+ priv = usbi_get_device_priv(dev);
dev->bus_number = bus_number;
dev->num_configurations = 1;
priv->dev_descriptor.bLength = LIBUSB_DT_DEVICE_SIZE;
static int set_composite_interface(struct libusb_context *ctx, struct libusb_device *dev,
char *dev_interface_path, char *device_id, int api, int sub_api)
{
- struct winusb_device_priv *priv = _device_priv(dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev);
int interface_number;
const char *mi_str;
static int set_hid_interface(struct libusb_context *ctx, struct libusb_device *dev,
char *dev_interface_path)
{
- struct winusb_device_priv *priv = _device_priv(dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev);
uint8_t i;
if (priv->hid == NULL) {
// Root hubs will not have a parent
dev = usbi_get_device_by_session_id(ctx, (unsigned long)dev_info_data.DevInst);
if (dev != NULL) {
- priv = _device_priv(dev);
+ priv = usbi_get_device_priv(dev);
if (priv->root_hub)
goto track_unref;
libusb_unref_device(dev);
continue;
}
- parent_priv = _device_priv(parent_dev);
+ parent_priv = usbi_get_device_priv(parent_dev);
// virtual USB devices are also listed during GEN - don't process these yet
if ((pass == GEN_PASS) && (parent_priv->apib->id != USB_API_HUB)) {
libusb_unref_device(parent_dev);
} else {
usbi_dbg("found existing device for session [%lX]", session_id);
- priv = _device_priv(dev);
+ priv = usbi_get_device_priv(dev);
if (strcmp(priv->dev_id, dev_id) != 0) {
usbi_dbg("device instance ID for session [%lX] changed", session_id);
usbi_disconnect_device(dev);
static int winusb_get_device_descriptor(struct libusb_device *dev, unsigned char *buffer)
{
- struct winusb_device_priv *priv = _device_priv(dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev);
memcpy(buffer, &priv->dev_descriptor, DEVICE_DESC_LENGTH);
return LIBUSB_SUCCESS;
static int winusb_get_config_descriptor(struct libusb_device *dev, uint8_t config_index, unsigned char *buffer, size_t len)
{
- struct winusb_device_priv *priv = _device_priv(dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev);
PUSB_CONFIGURATION_DESCRIPTOR config_header;
size_t size;
static int winusb_get_config_descriptor_by_value(struct libusb_device *dev, uint8_t bConfigurationValue,
unsigned char **buffer)
{
- struct winusb_device_priv *priv = _device_priv(dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev);
PUSB_CONFIGURATION_DESCRIPTOR config_header;
uint8_t index;
*/
static int winusb_get_active_config_descriptor(struct libusb_device *dev, unsigned char *buffer, size_t len)
{
- struct winusb_device_priv *priv = _device_priv(dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev);
unsigned char *config_desc;
int r;
static int winusb_open(struct libusb_device_handle *dev_handle)
{
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
CHECK_SUPPORTED_API(priv->apib, open);
static void winusb_close(struct libusb_device_handle *dev_handle)
{
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
if (priv->apib->close)
priv->apib->close(SUB_API_NOTSET, dev_handle);
static int winusb_get_configuration(struct libusb_device_handle *dev_handle, int *config)
{
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
if (priv->active_config == 0) {
*config = 0;
*/
static int winusb_set_configuration(struct libusb_device_handle *dev_handle, int config)
{
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
int r = LIBUSB_SUCCESS;
if (config >= USB_MAXCONFIG)
static int winusb_claim_interface(struct libusb_device_handle *dev_handle, int iface)
{
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
int r;
CHECK_SUPPORTED_API(priv->apib, claim_interface);
static int winusb_set_interface_altsetting(struct libusb_device_handle *dev_handle, int iface, int altsetting)
{
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
int r;
CHECK_SUPPORTED_API(priv->apib, set_interface_altsetting);
static int winusb_release_interface(struct libusb_device_handle *dev_handle, int iface)
{
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
CHECK_SUPPORTED_API(priv->apib, release_interface);
static int winusb_clear_halt(struct libusb_device_handle *dev_handle, unsigned char endpoint)
{
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
CHECK_SUPPORTED_API(priv->apib, clear_halt);
static int winusb_reset_device(struct libusb_device_handle *dev_handle)
{
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
CHECK_SUPPORTED_API(priv->apib, reset_device);
{
struct winusb_transfer_priv *transfer_priv = get_winusb_transfer_priv(itransfer);
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
int sub_api = priv->sub_api;
safe_free(transfer_priv->hid_buffer);
static int winusb_submit_transfer(struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
int (*transfer_fn)(int, struct usbi_transfer *);
switch (transfer->type) {
static int winusb_cancel_transfer(struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
CHECK_SUPPORTED_API(priv->apib, cancel_transfer);
static enum libusb_transfer_status winusb_copy_transfer_data(struct usbi_transfer *itransfer, DWORD length)
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
if (priv->apib->copy_transfer_data == NULL) {
usbi_err(TRANSFER_CTX(transfer), "program assertion failed - no function to copy transfer data");
// composite_open(), with interfaces belonging to different APIs
static int winusbx_open(int sub_api, struct libusb_device_handle *dev_handle)
{
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(dev_handle);
HANDLE file_handle;
int i;
static void winusbx_close(int sub_api, struct libusb_device_handle *dev_handle)
{
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
HANDLE handle;
int i;
static int winusbx_configure_endpoints(int sub_api, struct libusb_device_handle *dev_handle, int iface)
{
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
HANDLE winusb_handle = handle_priv->interface_handle[iface].api_handle;
UCHAR policy;
ULONG timeout = 0;
static int winusbx_claim_interface(int sub_api, struct libusb_device_handle *dev_handle, int iface)
{
struct libusb_context *ctx = HANDLE_CTX(dev_handle);
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
bool is_using_usbccgp = (priv->apib->id == USB_API_COMPOSITE);
SP_DEVICE_INTERFACE_DETAIL_DATA_A *dev_interface_details = NULL;
HDEVINFO dev_info = INVALID_HANDLE_VALUE;
static int winusbx_release_interface(int sub_api, struct libusb_device_handle *dev_handle, int iface)
{
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
HANDLE winusb_handle;
CHECK_WINUSBX_AVAILABLE(sub_api);
*/
static int get_valid_interface(struct libusb_device_handle *dev_handle, int api_id)
{
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
int i;
if ((api_id < USB_API_WINUSBX) || (api_id > USB_API_HID)) {
*/
static int check_valid_interface(struct libusb_device_handle *dev_handle, unsigned short interface, int api_id)
{
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
if (interface >= USB_MAXINTERFACES)
return -1;
static int winusbx_submit_control_transfer(int sub_api, struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
struct winusb_transfer_priv *transfer_priv = get_winusb_transfer_priv(itransfer);
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(transfer->dev_handle);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(transfer->dev_handle);
PWINUSB_SETUP_PACKET setup = (PWINUSB_SETUP_PACKET)transfer->buffer;
ULONG size;
HANDLE winusb_handle;
static int winusbx_set_interface_altsetting(int sub_api, struct libusb_device_handle *dev_handle, int iface, int altsetting)
{
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
HANDLE winusb_handle;
CHECK_WINUSBX_AVAILABLE(sub_api);
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct winusb_transfer_priv *transfer_priv = get_winusb_transfer_priv(itransfer);
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(transfer->dev_handle);
- struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(transfer->dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
HANDLE winusb_handle;
OVERLAPPED *overlapped;
BOOL ret;
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct winusb_transfer_priv *transfer_priv = get_winusb_transfer_priv(itransfer);
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(transfer->dev_handle);
- struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(transfer->dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
HANDLE winusb_handle;
OVERLAPPED *overlapped;
BOOL ret;
static int winusbx_clear_halt(int sub_api, struct libusb_device_handle *dev_handle, unsigned char endpoint)
{
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
HANDLE winusb_handle;
int current_interface;
static int winusbx_cancel_transfer(int sub_api, struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(transfer->dev_handle);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(transfer->dev_handle);
struct winusb_transfer_priv *transfer_priv = get_winusb_transfer_priv(itransfer);
- struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
int current_interface = transfer_priv->interface_number;
HANDLE handle;
// TODO: (post hotplug): see if we can force eject the device and redetect it (reuse hotplug?)
static int winusbx_reset_device(int sub_api, struct libusb_device_handle *dev_handle)
{
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
HANDLE winusb_handle;
int i, j;
static int _hid_get_descriptor(struct libusb_device *dev, HANDLE hid_handle, int recipient,
int type, int _index, void *data, size_t *size)
{
- struct winusb_device_priv *priv = _device_priv(dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev);
UNUSED(recipient);
switch (type) {
// composite_open(), with interfaces belonging to different APIs
static int hid_open(int sub_api, struct libusb_device_handle *dev_handle)
{
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(dev_handle);
HIDD_ATTRIBUTES hid_attributes;
PHIDP_PREPARSED_DATA preparsed_data = NULL;
HIDP_CAPS capabilities;
static void hid_close(int sub_api, struct libusb_device_handle *dev_handle)
{
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(dev_handle);
HANDLE file_handle;
int i;
static int hid_claim_interface(int sub_api, struct libusb_device_handle *dev_handle, int iface)
{
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
UNUSED(sub_api);
CHECK_HID_AVAILABLE;
static int hid_release_interface(int sub_api, struct libusb_device_handle *dev_handle, int iface)
{
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
UNUSED(sub_api);
CHECK_HID_AVAILABLE;
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct winusb_transfer_priv *transfer_priv = get_winusb_transfer_priv(itransfer);
struct libusb_device_handle *dev_handle = transfer->dev_handle;
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
- struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
WINUSB_SETUP_PACKET *setup = (WINUSB_SETUP_PACKET *)transfer->buffer;
HANDLE hid_handle;
OVERLAPPED *overlapped;
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct winusb_transfer_priv *transfer_priv = get_winusb_transfer_priv(itransfer);
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(transfer->dev_handle);
- struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(transfer->dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
HANDLE hid_handle;
OVERLAPPED *overlapped;
bool direction_in;
static int hid_reset_device(int sub_api, struct libusb_device_handle *dev_handle)
{
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(dev_handle);
HANDLE hid_handle;
int current_interface;
static int hid_clear_halt(int sub_api, struct libusb_device_handle *dev_handle, unsigned char endpoint)
{
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
HANDLE hid_handle;
int current_interface;
*/
static int composite_open(int sub_api, struct libusb_device_handle *dev_handle)
{
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
int i, r = LIBUSB_ERROR_NOT_FOUND;
// SUB_API_MAX + 1 as the SUB_API_MAX pos is used to indicate availability of HID
bool available[SUB_API_MAX + 1];
static void composite_close(int sub_api, struct libusb_device_handle *dev_handle)
{
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
int i;
// SUB_API_MAX + 1 as the SUB_API_MAX pos is used to indicate availability of HID
bool available[SUB_API_MAX + 1];
static int composite_claim_interface(int sub_api, struct libusb_device_handle *dev_handle, int iface)
{
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
UNUSED(sub_api);
CHECK_SUPPORTED_API(priv->usb_interface[iface].apib, claim_interface);
static int composite_set_interface_altsetting(int sub_api, struct libusb_device_handle *dev_handle, int iface, int altsetting)
{
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
UNUSED(sub_api);
CHECK_SUPPORTED_API(priv->usb_interface[iface].apib, set_interface_altsetting);
static int composite_release_interface(int sub_api, struct libusb_device_handle *dev_handle, int iface)
{
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
UNUSED(sub_api);
CHECK_SUPPORTED_API(priv->usb_interface[iface].apib, release_interface);
static int composite_submit_control_transfer(int sub_api, struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
struct libusb_config_descriptor *conf_desc;
WINUSB_SETUP_PACKET *setup = (WINUSB_SETUP_PACKET *)transfer->buffer;
int iface, pass, r;
static int composite_submit_bulk_transfer(int sub_api, struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(transfer->dev_handle);
- struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(transfer->dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
int current_interface;
UNUSED(sub_api);
static int composite_submit_iso_transfer(int sub_api, struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(transfer->dev_handle);
- struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(transfer->dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
int current_interface;
UNUSED(sub_api);
static int composite_clear_halt(int sub_api, struct libusb_device_handle *dev_handle, unsigned char endpoint)
{
- struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(dev_handle);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
int current_interface;
UNUSED(sub_api);
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct winusb_transfer_priv *transfer_priv = get_winusb_transfer_priv(itransfer);
- struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
int current_interface = transfer_priv->interface_number;
UNUSED(sub_api);
static int composite_reset_device(int sub_api, struct libusb_device_handle *dev_handle)
{
- struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
int i, r;
bool available[SUB_API_MAX];
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct winusb_transfer_priv *transfer_priv = get_winusb_transfer_priv(itransfer);
- struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(transfer->dev_handle->dev);
int current_interface = transfer_priv->interface_number;
UNUSED(sub_api);
uint8_t string_index[3]; // man, prod, ser
};
-static inline struct winusb_device_priv *_device_priv(struct libusb_device *dev)
-{
- return (struct winusb_device_priv *)dev->os_priv;
-}
-
static inline struct winusb_device_priv *winusb_device_priv_init(struct libusb_device *dev)
{
- struct winusb_device_priv *p = _device_priv(dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev);
int i;
- p->apib = &usb_api_backend[USB_API_UNSUPPORTED];
- p->sub_api = SUB_API_NOTSET;
+ priv->apib = &usb_api_backend[USB_API_UNSUPPORTED];
+ priv->sub_api = SUB_API_NOTSET;
for (i = 0; i < USB_MAXINTERFACES; i++) {
- p->usb_interface[i].apib = &usb_api_backend[USB_API_UNSUPPORTED];
- p->usb_interface[i].sub_api = SUB_API_NOTSET;
+ priv->usb_interface[i].apib = &usb_api_backend[USB_API_UNSUPPORTED];
+ priv->usb_interface[i].sub_api = SUB_API_NOTSET;
}
- return p;
+ return priv;
}
static inline void winusb_device_priv_release(struct libusb_device *dev)
{
- struct winusb_device_priv *p = _device_priv(dev);
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev);
int i;
- free(p->dev_id);
- free(p->path);
- if ((dev->num_configurations > 0) && (p->config_descriptor != NULL)) {
+ free(priv->dev_id);
+ free(priv->path);
+ if ((dev->num_configurations > 0) && (priv->config_descriptor != NULL)) {
for (i = 0; i < dev->num_configurations; i++) {
- if (p->config_descriptor[i] == NULL)
+ if (priv->config_descriptor[i] == NULL)
continue;
- free((UCHAR *)p->config_descriptor[i] - USB_DESCRIPTOR_REQUEST_SIZE);
+ free((UCHAR *)priv->config_descriptor[i] - USB_DESCRIPTOR_REQUEST_SIZE);
}
}
- free(p->config_descriptor);
- free(p->hid);
+ free(priv->config_descriptor);
+ free(priv->hid);
for (i = 0; i < USB_MAXINTERFACES; i++) {
- free(p->usb_interface[i].path);
- free(p->usb_interface[i].endpoint);
+ free(priv->usb_interface[i].path);
+ free(priv->usb_interface[i].endpoint);
}
}
-static inline struct winusb_device_handle_priv *_device_handle_priv(
- struct libusb_device_handle *handle)
-{
- return (struct winusb_device_handle_priv *)handle->os_priv;
-}
-
// used to match a device driver (including filter drivers) against a supported API
struct driver_lookup {
char list[MAX_KEY_LENGTH + 1]; // REG_MULTI_SZ list of services (driver) names
-#define LIBUSB_NANO 11459
+#define LIBUSB_NANO 11460