Skip to content

Commit

Permalink
usb: Rename usb_device struct member 'dev' to more appropriate 'handle'
Browse files Browse the repository at this point in the history
  • Loading branch information
nikias committed Jun 13, 2024
1 parent 243dedf commit bc0b91c
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#define NUM_RX_LOOPS 3

struct usb_device {
libusb_device_handle *dev;
libusb_device_handle *handle;
uint8_t bus, address;
char serial[256];
int alive;
Expand Down Expand Up @@ -83,7 +83,7 @@ static int device_hotplug = 1;

static void usb_disconnect(struct usb_device *dev)
{
if(!dev->dev) {
if(!dev->handle) {
return;
}

Expand Down Expand Up @@ -114,9 +114,9 @@ static void usb_disconnect(struct usb_device *dev)

collection_free(&dev->tx_xfers);
collection_free(&dev->rx_xfers);
libusb_release_interface(dev->dev, dev->interface);
libusb_close(dev->dev);
dev->dev = NULL;
libusb_release_interface(dev->handle, dev->interface);
libusb_close(dev->handle);
dev->handle = NULL;
collection_remove(&device_list, dev);
free(dev);
}
Expand Down Expand Up @@ -177,7 +177,7 @@ int usb_send(struct usb_device *dev, const unsigned char *buf, int length)
{
int res;
struct libusb_transfer *xfer = libusb_alloc_transfer(0);
libusb_fill_bulk_transfer(xfer, dev->dev, dev->ep_out, (void*)buf, length, tx_callback, dev, 0);
libusb_fill_bulk_transfer(xfer, dev->handle, dev->ep_out, (void*)buf, length, tx_callback, dev, 0);
if((res = libusb_submit_transfer(xfer)) < 0) {
usbmuxd_log(LL_ERROR, "Failed to submit TX transfer %p len %d to device %d-%d: %s", buf, length, dev->bus, dev->address, libusb_error_name(res));
libusb_free_transfer(xfer);
Expand All @@ -189,7 +189,7 @@ int usb_send(struct usb_device *dev, const unsigned char *buf, int length)
// Send Zero Length Packet
xfer = libusb_alloc_transfer(0);
void *buffer = malloc(1);
libusb_fill_bulk_transfer(xfer, dev->dev, dev->ep_out, buffer, 0, tx_callback, dev, 0);
libusb_fill_bulk_transfer(xfer, dev->handle, dev->ep_out, buffer, 0, tx_callback, dev, 0);
if((res = libusb_submit_transfer(xfer)) < 0) {
usbmuxd_log(LL_ERROR, "Failed to submit TX ZLP transfer to device %d-%d: %s", dev->bus, dev->address, libusb_error_name(res));
libusb_free_transfer(xfer);
Expand Down Expand Up @@ -256,7 +256,7 @@ static int start_rx_loop(struct usb_device *dev)
void *buf;
struct libusb_transfer *xfer = libusb_alloc_transfer(0);
buf = malloc(USB_MRU);
libusb_fill_bulk_transfer(xfer, dev->dev, dev->ep_in, buf, USB_MRU, rx_callback, dev, 0);
libusb_fill_bulk_transfer(xfer, dev->handle, dev->ep_in, buf, USB_MRU, rx_callback, dev, 0);
if((res = libusb_submit_transfer(xfer)) != 0) {
usbmuxd_log(LL_ERROR, "Failed to submit RX transfer to device %d-%d: %s", dev->bus, dev->address, libusb_error_name(res));
libusb_free_transfer(xfer);
Expand Down Expand Up @@ -357,7 +357,7 @@ static void get_langid_callback(struct libusb_transfer *transfer)
libusb_fill_control_setup(transfer->buffer, LIBUSB_ENDPOINT_IN, LIBUSB_REQUEST_GET_DESCRIPTOR,
(uint16_t)((LIBUSB_DT_STRING << 8) | usbdev->devdesc.iSerialNumber),
langid, 1024 + LIBUSB_CONTROL_SETUP_SIZE);
libusb_fill_control_transfer(transfer, usbdev->dev, transfer->buffer, get_serial_callback, usbdev, 1000);
libusb_fill_control_transfer(transfer, usbdev->handle, transfer->buffer, get_serial_callback, usbdev, 1000);

if((res = libusb_submit_transfer(transfer)) < 0) {
usbmuxd_log(LL_ERROR, "Could not request transfer for device %d-%d: %s", usbdev->bus, usbdev->address, libusb_error_name(res));
Expand Down Expand Up @@ -595,7 +595,7 @@ static void device_complete_initialization(struct mode_context *context, struct
usbdev->address = address;
usbdev->devdesc = devdesc;
usbdev->speed = 480000000;
usbdev->dev = handle;
usbdev->handle = handle;
usbdev->alive = 1;
usbdev->wMaxPacketSize = libusb_get_max_packet_size(dev, usbdev->ep_out);
if (usbdev->wMaxPacketSize <= 0) {
Expand Down Expand Up @@ -764,7 +764,7 @@ static int usb_device_add(libusb_device* dev)
usbdev->address = address;
usbdev->devdesc = devdesc;
usbdev->speed = 0;
usbdev->dev = handle;
usbdev->handle = handle;
usbdev->alive = 1;

collection_init(&usbdev->tx_xfers);
Expand Down Expand Up @@ -854,31 +854,31 @@ int usb_discover(void)

const char *usb_get_serial(struct usb_device *dev)
{
if(!dev->dev) {
if(!dev->handle) {
return NULL;
}
return dev->serial;
}

uint32_t usb_get_location(struct usb_device *dev)
{
if(!dev->dev) {
if(!dev->handle) {
return 0;
}
return (dev->bus << 16) | dev->address;
}

uint16_t usb_get_pid(struct usb_device *dev)
{
if(!dev->dev) {
if(!dev->handle) {
return 0;
}
return dev->devdesc.idProduct;
}

uint64_t usb_get_speed(struct usb_device *dev)
{
if (!dev->dev) {
if (!dev->handle) {
return 0;
}
return dev->speed;
Expand Down

0 comments on commit bc0b91c

Please sign in to comment.