Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion libpisock/libusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>

Expand Down Expand Up @@ -137,11 +138,35 @@ USB_poll (pi_usb_data_t *data)
LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s: trying to open device %p\n",
__FILE__, dev));

{
char devpath[64];

snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%s/%s",
bus->dirname, dev->filename);
if (access(devpath, R_OK | W_OK) != 0) {
LOG((PI_DBG_DEV, PI_DBG_LVL_ERR,
"%s: unable to access %s for device 0x%04x:0x%04x (errno=%d)\n",
__FILE__, devpath, dev->descriptor.idVendor,
dev->descriptor.idProduct, errno));
data->ref = NULL;
continue;
}
}

USB_handle = usb_open(dev);

LOG((PI_DBG_DEV, PI_DBG_LVL_DEBUG, "%s: USB_handle=%p\n",
__FILE__, USB_handle));

if (!USB_handle) {
LOG((PI_DBG_DEV, PI_DBG_LVL_ERR,
"%s: unable to open device 0x%04x:0x%04x (errno=%d)\n",
__FILE__, dev->descriptor.idVendor,
dev->descriptor.idProduct, errno));
data->ref = NULL;
continue;
}

data->ref = USB_handle;

input_endpoint = output_endpoint = 0xFF;
Expand All @@ -153,7 +178,10 @@ USB_poll (pi_usb_data_t *data)
"%s: USB configure failed for familar device: 0x%04x 0x%04x. (LifeDrive issue?)\n",
__FILE__, dev->descriptor.idVendor, dev->descriptor.idProduct));

usb_close(USB_handle);
if (USB_handle)
usb_close(USB_handle);
USB_handle = NULL;
data->ref = NULL;
continue;
}

Expand Down Expand Up @@ -185,6 +213,8 @@ USB_poll (pi_usb_data_t *data)

if (USB_in_endpoint == 0xFF || USB_out_endpoint == 0xFF) {
usb_close (USB_handle);
USB_handle = NULL;
data->ref = NULL;
continue;
}

Expand Down