return -1;
snprintf(path, PATH_MAX, "%s/%s", busdir, devnum);
- fp_dbg("%s", path);
+ usbi_dbg("%s", path);
fd = open(path, O_RDWR);
if (!fd) {
- fp_dbg("open '%s' failed, ret=%d errno=%d", path, fd, errno);
+ usbi_dbg("open '%s' failed, ret=%d errno=%d", path, fd, errno);
r = -1;
goto err;
}
r = read(fd, raw_desc, DEVICE_DESC_LENGTH);
if (r < 0) {
- fp_err("read failed ret=%d errno=%d", r, errno);
+ usbi_err("read failed ret=%d errno=%d", r, errno);
goto err;
}
/* FIXME: short read handling? */
/* Now try to fetch the rest of the descriptors */
if (dev->desc.bNumConfigurations > USB_MAXCONFIG) {
- fp_err("too many configurations");
+ usbi_err("too many configurations");
r = -1;
goto err;
}
if (dev->desc.bNumConfigurations < 1) {
- fp_dbg("no configurations?");
+ usbi_dbg("no configurations?");
r = -1;
goto err;
}
/* Get the first 8 bytes to figure out what the total length is */
r = read(fd, buffer, sizeof(buffer));
if (r < sizeof(buffer)) {
- fp_err("short descriptor read (%d/%d)", r, sizeof(buffer));
+ usbi_err("short descriptor read (%d/%d)", r, sizeof(buffer));
goto err;
}
tmp = config.wTotalLength - 8;
r = read(fd, bigbuffer + 8, tmp);
if (r < tmp) {
- fp_err("short descriptor read (%d/%d)", r, tmp);
+ usbi_err("short descriptor read (%d/%d)", r, tmp);
free(bigbuffer);
goto err;
}
r = usbi_parse_configuration(&dev->config[i], bigbuffer);
if (r > 0)
- fp_warn("descriptor data still left\n");
+ usbi_warn("descriptor data still left\n");
free(bigbuffer);
}
if (!dev->nodepath)
goto err;
- fp_dbg("found device %04x:%04x", dev->desc.idVendor, dev->desc.idProduct);
+ usbi_dbg("found device %04x:%04x", dev->desc.idVendor, dev->desc.idProduct);
list_add(&dev->list, &usb_devs);
r = 0;
struct dirent *entry;
snprintf(dirpath, PATH_MAX, "%s/%s", USBFS_PATH, busnum);
- fp_dbg("%s", dirpath);
+ usbi_dbg("%s", dirpath);
dir = opendir(dirpath);
if (!dir) {
- fp_err("opendir '%s' failed, errno=%d", dirpath, errno);
+ usbi_err("opendir '%s' failed, errno=%d", dirpath, errno);
return -1;
}
{
DIR *buses;
struct dirent *entry;
- fp_dbg("");
+ usbi_dbg("");
buses = opendir(USBFS_PATH);
if (!buses) {
- fp_err("opendir buses failed errno=%d", errno);
+ usbi_err("opendir buses failed errno=%d", errno);
return -1;
}
{
struct libusb_dev_handle *devh;
int fd;
- fp_dbg("open %04x:%04x", dev->desc.idVendor, dev->desc.idProduct);
+ usbi_dbg("open %04x:%04x", dev->desc.idVendor, dev->desc.idProduct);
fd = open(dev->nodepath, O_RDWR);
if (!fd) {
- fp_err("open failed, code %d errno %d", fd, errno);
+ usbi_err("open failed, code %d errno %d", fd, errno);
return NULL;
}
{
if (!devh)
return;
- fp_dbg("");
+ usbi_dbg("");
list_del(&devh->list);
do_close(devh);
int iface)
{
int r;
- fp_dbg("interface %d", iface);
+ usbi_dbg("interface %d", iface);
r = ioctl(dev->fd, IOCTL_USB_CLAIMINTF, &iface);
if (r < 0)
- fp_err("claim interface failed, error %d", r);
+ usbi_err("claim interface failed, error %d", r);
return r;
}
int iface)
{
int r;
- fp_dbg("interface %d", iface);
+ usbi_dbg("interface %d", iface);
r = ioctl(dev->fd, IOCTL_USB_RELEASEINTF, &iface);
if (r < 0)
- fp_err("release interface failed, error %d", r);
+ usbi_err("release interface failed, error %d", r);
return r;
}
API_EXPORTED int libusb_init(int signum)
{
/* FIXME: find correct usb node path */
- fp_dbg("");
+ usbi_dbg("");
list_init(&usb_devs);
list_init(&open_devs);
return usbi_io_init(signum);
API_EXPORTED void libusb_exit(void)
{
struct libusb_dev_handle *devh;
- fp_dbg("");
+ usbi_dbg("");
if (!list_empty(&open_devs)) {
- fp_dbg("naughty app left some devices open!\n");
+ usbi_dbg("naughty app left some devices open!\n");
list_for_each_entry(devh, &open_devs, list)
do_close(devh);
}
/* Everything should be fine being passed into here, but we sanity */
/* check JIC */
if (header.bLength > size) {
- fp_err("ran out of descriptors parsing");
+ usbi_err("ran out of descriptors parsing");
return -1;
}
if (header.bDescriptorType != LIBUSB_DT_ENDPOINT) {
- fp_err("unexpected descriptor %x (expected %x)",
+ usbi_err("unexpected descriptor %x (expected %x)",
header.bDescriptorType, LIBUSB_DT_ENDPOINT);
return parsed;
}
usbi_parse_descriptor(buffer, "bb", &header);
if (header.bLength < 2) {
- fp_err("invalid descriptor length %d", header.bLength);
+ usbi_err("invalid descriptor length %d", header.bLength);
return -1;
}
(header.bDescriptorType == LIBUSB_DT_DEVICE))
break;
- fp_dbg("skipping descriptor %x", header.bDescriptorType);
+ usbi_dbg("skipping descriptor %x", header.bDescriptorType);
buffer += header.bLength;
size -= header.bLength;
parsed += header.bLength;
while (size >= DESC_HEADER_LENGTH) {
usbi_parse_descriptor(buffer, "bb", &header);
if (header.bLength < 2) {
- fp_err("invalid descriptor of length %d", header.bLength);
+ usbi_err("invalid descriptor of length %d", header.bLength);
return -1;
}
return parsed;
if (ifp->bNumEndpoints > USB_MAXENDPOINTS) {
- fp_err("too many endpoints (%d)", ifp->bNumEndpoints);
+ usbi_err("too many endpoints (%d)", ifp->bNumEndpoints);
/* FIXME will leak memory */
return -1;
}
usbi_parse_descriptor(buffer, "bb", &header);
if (header.bLength > size) {
- fp_err("ran out of descriptors parsing");
+ usbi_err("ran out of descriptors parsing");
/* FIXME will leak memory */
return -1;
}
size = config->wTotalLength;
if (config->bNumInterfaces > USB_MAXINTERFACES) {
- fp_err("too many interfaces (%d)", config->bNumInterfaces);
+ usbi_err("too many interfaces (%d)", config->bNumInterfaces);
return -1;
}
if ((header.bLength > size) ||
(header.bLength < DESC_HEADER_LENGTH)) {
- fp_err("invalid descriptor length of %d", header.bLength);
+ usbi_err("invalid descriptor length of %d", header.bLength);
return -1;
}
(header.bDescriptorType == LIBUSB_DT_DEVICE))
break;
- fp_dbg("skipping descriptor 0x%x\n", header.bDescriptorType);
+ usbi_dbg("skipping descriptor 0x%x\n", header.bDescriptorType);
buffer += header.bLength;
size -= header.bLength;
}
static int sigfd;
static int signum;
-/* this is a list of in-flight fp_urb_handles, sorted by timeout expiration.
+/* this is a list of in-flight rb_handles, sorted by timeout expiration.
* URBs to timeout the soonest are placed at the beginning of the list, URBs
* that will time out later are placed after, and urbs with infinite timeout
* are always placed at the very end. */
sigset_t sigset;
if (_signum == 0)
_signum = SIGRTMIN;
- fp_dbg("signal %d", _signum);
+ usbi_dbg("signal %d", _signum);
sigemptyset(&sigset);
sigaddset(&sigset, _signum);
sigfd = signalfd(-1, &sigset, 0);
if (sigfd < 0) {
- fp_err("signalfd failed, code=%d errno=%d", sigfd, errno);
+ usbi_err("signalfd failed, code=%d errno=%d", sigfd, errno);
return sigfd;
}
- fp_dbg("got signalfd %d", sigfd);
+ usbi_dbg("got signalfd %d", sigfd);
signum = _signum;
sigemptyset(&sigset);
r = clock_gettime(CLOCK_MONOTONIC, ¤t_time);
if (r < 0) {
- fp_err("failed to read monotonic clock, errno=%d", errno);
+ usbi_err("failed to read monotonic clock, errno=%d", errno);
return r;
}
r = timer_create(CLOCK_MONOTONIC, &sigevt, &urbh->timer);
if (r < 0) {
- fp_err("failed to create monotonic timer");
+ usbi_err("failed to create monotonic timer");
return r;
}
r = timer_settime(&urbh->timer, TIMER_ABSTIME, &itspec, NULL);
if (r < 0) {
- fp_err("failed to arm monotonic timer");
+ usbi_err("failed to arm monotonic timer");
return r;
}
* rather than: submit, reap, submit, reap, submit, reap
* this will improve performance and fix bugs concerning behaviour when
* the user submits two similar multiple-urb requests */
- fp_dbg("transferring %d from %d bytes", urb->buffer_length,
+ usbi_dbg("transferring %d from %d bytes", urb->buffer_length,
to_be_transferred);
r = ioctl(devh->fd, IOCTL_USB_SUBMITURB, &urbh->urb);
if (r < 0) {
- fp_err("submiturb failed error %d errno=%d", r, errno);
+ usbi_err("submiturb failed error %d errno=%d", r, errno);
return r;
}
return NULL;
}
- fp_dbg("RQT=%02x RQ=%02x VAL=%04x IDX=%04x length=%d",
+ usbi_dbg("RQT=%02x RQ=%02x VAL=%04x IDX=%04x length=%d",
transfer->requesttype, transfer->request, transfer->value,
transfer->index, transfer->length);
struct libusb_urb_handle *urbh = malloc(sizeof(*urbh));
int r;
- fp_dbg("length %d timeout %d", transfer->length, timeout);
+ usbi_dbg("length %d timeout %d", transfer->length, timeout);
if (!urbh)
return NULL;
struct libusb_urb_handle *urbh)
{
int r;
- fp_dbg("");
+ usbi_dbg("");
r = ioctl(devh->fd, IOCTL_USB_DISCARDURB, &urbh->urb);
if (r < 0)
- fp_err("cancel urb failed error %d", r);
+ usbi_err("cancel urb failed error %d", r);
return r;
}
struct libusb_urb_handle *urbh)
{
int r;
- fp_dbg("");
+ usbi_dbg("");
r = ioctl(devh->fd, IOCTL_USB_DISCARDURB, &urbh->urb);
if (r < 0) {
- fp_err("cancel urb failed error %d", r);
+ usbi_err("cancel urb failed error %d", r);
return r;
}
}
int handle_transfer_completion(struct libusb_dev_handle *devh,
- struct libusb_urb_handle *urbh, enum fp_urb_cb_status status)
+ struct libusb_urb_handle *urbh, enum libusb_urb_cb_status status)
{
struct usb_urb *urb = &urbh->urb;
*/
if (urbh->flags & LIBUSB_URBH_SYNC_CANCELLED) {
urbh->flags &= ~LIBUSB_URBH_SYNC_CANCELLED;
- fp_dbg("detected sync. cancel");
+ usbi_dbg("detected sync. cancel");
return handle_transfer_completion(devh, urbh, FP_URB_SILENT_COMPLETION);
}
/* if the URB was cancelled due to timeout, report timeout to the user */
if (urbh->flags & LIBUSB_URBH_TIMED_OUT) {
- fp_dbg("detected timeout cancellation");
+ usbi_dbg("detected timeout cancellation");
return handle_transfer_completion(devh, urbh, FP_URB_TIMEOUT);
}
if (r == -1 && errno == EAGAIN)
return r;
if (r < 0) {
- fp_err("reap failed error %d errno=%d", r, errno);
+ usbi_err("reap failed error %d errno=%d", r, errno);
return r;
}
urbh = container_of(urb, struct libusb_urb_handle, urb);
- fp_dbg("urb type=%d status=%d transferred=%d", urb->type, urb->status,
+ usbi_dbg("urb type=%d status=%d transferred=%d", urb->type, urb->status,
urb->actual_length);
list_del(&urbh->list);
return handle_transfer_cancellation(devh, urbh);
/* FIXME: research what other status codes may exist */
if (urb->status != 0)
- fp_warn("unrecognised urb status %d", urb->status);
+ usbi_warn("unrecognised urb status %d", urb->status);
/* determine how much data was asked for */
trf_requested = MIN(urbh->transfer_len - urbh->transferred,
/* if we were provided less data than requested, then our transfer is
* done */
if (urb->actual_length < trf_requested) {
- fp_dbg("less data than requested (%d/%d) --> all done",
+ usbi_dbg("less data than requested (%d/%d) --> all done",
urb->actual_length, trf_requested);
return handle_transfer_completion(devh, urbh, FP_URB_COMPLETED);
}
/* if we've transferred all data, we're done */
if (urbh->transferred == urbh->transfer_len) {
- fp_dbg("transfer complete --> all done");
+ usbi_dbg("transfer complete --> all done");
return handle_transfer_completion(devh, urbh, FP_URB_COMPLETED);
}
/* otherwise, we have more data to transfer */
- fp_dbg("more data to transfer...");
+ usbi_dbg("more data to transfer...");
memset(urb, 0, sizeof(*urb));
return submit_urb(devh, urbh);
}
urbh->flags |= LIBUSB_URBH_TIMED_OUT;
r = libusb_urb_handle_cancel(urbh->devh, urbh);
if (r < 0)
- fp_warn("async cancel failed %d errno=%d", r, errno);
+ usbi_warn("async cancel failed %d errno=%d", r, errno);
}
static int handle_timeouts(void)
struct signalfd_siginfo siginfo;
r = read(sigfd, &siginfo, sizeof(siginfo));
if (r < 0) {
- fp_err("sigfd read failed %d %d", r, errno);
+ usbi_err("sigfd read failed %d %d", r, errno);
return r;
}
if ((unsigned int) r < sizeof(siginfo)) {
- fp_err("sigfd short read (%d/%d)", r, sizeof(siginfo));
+ usbi_err("sigfd short read (%d/%d)", r, sizeof(siginfo));
return -1;
}
return 0;
if (r == -1 && errno == EINTR)
return 0;
if (r < 0) {
- fp_err("select failed %d err=%d\n", r, errno);
+ usbi_err("select failed %d err=%d\n", r, errno);
return r;
}
}
struct sync_ctrl_handle {
- enum fp_urb_cb_status status;
+ enum libusb_urb_cb_status status;
unsigned char *data;
int actual_length;
};
static void ctrl_transfer_cb(struct libusb_dev_handle *devh,
- struct libusb_urb_handle *urbh, enum fp_urb_cb_status status,
+ struct libusb_urb_handle *urbh, enum libusb_urb_cb_status status,
struct libusb_ctrl_setup *setup, unsigned char *data, int actual_length,
void *user_data)
{
struct sync_ctrl_handle *ctrlh = (struct sync_ctrl_handle *) user_data;
- fp_dbg("actual_length=%d", actual_length);
+ usbi_dbg("actual_length=%d", actual_length);
if (status == FP_URB_COMPLETED) {
/* copy results into user-defined buffer */
case FP_URB_TIMEOUT:
return -ETIMEDOUT;
default:
- fp_warn("unrecognised status code %d", ctrlh.status);
+ usbi_warn("unrecognised status code %d", ctrlh.status);
return -1;
}
}
struct sync_bulk_handle {
- enum fp_urb_cb_status status;
+ enum libusb_urb_cb_status status;
int actual_length;
};
static void bulk_transfer_cb(struct libusb_dev_handle *devh,
- struct libusb_urb_handle *urbh, enum fp_urb_cb_status status,
+ struct libusb_urb_handle *urbh, enum libusb_urb_cb_status status,
unsigned char endpoint, int rqlength, unsigned char *data,
int actual_length, void *user_data)
{
struct sync_bulk_handle *bulkh = (struct sync_bulk_handle *) user_data;
- fp_dbg("");
+ usbi_dbg("");
bulkh->status = status;
bulkh->actual_length = actual_length;
/* caller frees urbh */
case FP_URB_TIMEOUT:
return -ETIMEDOUT;
default:
- fp_warn("unrecognised status code %d", bulkh.status);
+ usbi_warn("unrecognised status code %d", bulkh.status);
return -1;
}
}