mirror of
https://github.com/Cxbx-Reloaded/libusb.git
synced 2024-12-04 17:26:39 +00:00
Rename to libusb-1.0
I've taken over the libusb project, and what was previously known as fpusb will eventually be released as libusb-1.0.
This commit is contained in:
parent
f4ed0b6a3e
commit
e9364d7215
@ -1,14 +1,14 @@
|
||||
AUTOMAKE_OPTIONS = dist-bzip2
|
||||
DISTCLEANFILES = ChangeLog fpusb.pc
|
||||
DISTCLEANFILES = ChangeLog libusb-1.0.pc
|
||||
EXTRA_DIST = TODO
|
||||
SUBDIRS = libfpusb
|
||||
SUBDIRS = libusb
|
||||
|
||||
if BUILD_EXAMPLES
|
||||
SUBDIRS += examples
|
||||
endif
|
||||
|
||||
pkgconfigdir=$(libdir)/pkgconfig
|
||||
pkgconfig_DATA=fpusb.pc
|
||||
pkgconfig_DATA=libusb-1.0.pc
|
||||
|
||||
.PHONY: ChangeLog dist-up
|
||||
ChangeLog:
|
||||
|
13
README
13
README
@ -1,17 +1,14 @@
|
||||
fpusb
|
||||
=====
|
||||
libusb
|
||||
======
|
||||
|
||||
fpusb is another library for USB device access from Linux userspace.
|
||||
libusb is another library for USB device access from Linux userspace.
|
||||
It is written in C and licensed under the LGPL-2.1 (see COPYING).
|
||||
|
||||
See the homepage for more information:
|
||||
http://www.reactivated.net/fprint/wiki/Fpusb
|
||||
http://libusb.sourceforge.net
|
||||
|
||||
Use the mailing list for questions, comments, etc:
|
||||
http://www.reactivated.net/fprint/wiki/Mailing_list
|
||||
|
||||
Use the bug tracker for bugs and feature requests:
|
||||
http://www.reactivated.net/fprint/bugs/index.php?project=4&switch=1&do=index
|
||||
https://sourceforge.net/mailarchive/forum.php?forum_name=libusb-devel
|
||||
|
||||
- Daniel Drake <dsd@gentoo.org>
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
AC_INIT([fpusb], [0.0])
|
||||
AC_INIT([libusb], [0.9.0])
|
||||
AM_INIT_AUTOMAKE
|
||||
AC_CONFIG_SRCDIR([libfpusb/core.c])
|
||||
AC_CONFIG_SRCDIR([libusb/core.c])
|
||||
AM_CONFIG_HEADER([config.h])
|
||||
|
||||
AC_PREREQ([2.50])
|
||||
@ -44,6 +44,6 @@ AC_DEFINE([API_EXPORTED], [__attribute__((visibility("default")))], [Default vis
|
||||
AM_CFLAGS="-std=gnu99 -fgnu89-inline -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration -Wno-pointer-sign -Wshadow"
|
||||
AC_SUBST(AM_CFLAGS)
|
||||
|
||||
AC_CONFIG_FILES([fpusb.pc] [Makefile] [libfpusb/Makefile] [examples/Makefile])
|
||||
AC_CONFIG_FILES([libusb-1.0.pc] [Makefile] [libusb/Makefile] [examples/Makefile])
|
||||
AC_OUTPUT
|
||||
|
||||
|
@ -2,8 +2,8 @@ INCLUDES = -I$(top_srcdir)
|
||||
noinst_PROGRAMS = lsusb dpfp
|
||||
|
||||
lsusb_SOURCES = lsusb.c
|
||||
lsusb_LDADD = ../libfpusb/libfpusb.la -lfpusb
|
||||
lsusb_LDADD = ../libusb/libusb-1.0.la -lusb-1.0
|
||||
|
||||
dpfp_SOURCES = dpfp.c
|
||||
dpfp_LDADD = ../libfpusb/libfpusb.la -lfpusb
|
||||
dpfp_LDADD = ../libusb/libusb-1.0.la -lusb-1.0
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* fpusb example program to manipulate U.are.U 4000B fingerprint scanner.
|
||||
* libusb example program to manipulate U.are.U 4000B fingerprint scanner.
|
||||
* Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
|
||||
*
|
||||
* Basic image capture program only, does not consider the powerup quirks or
|
||||
@ -26,7 +26,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <libfpusb/fpusb.h>
|
||||
#include <libusb/libusb.h>
|
||||
|
||||
#define EP_INTR (1 | USB_ENDPOINT_IN)
|
||||
#define EP_DATA (2 | USB_ENDPOINT_IN)
|
||||
@ -58,34 +58,34 @@ enum {
|
||||
};
|
||||
|
||||
static int state = 0;
|
||||
static struct fpusb_dev_handle *devh = NULL;
|
||||
static struct libusb_dev_handle *devh = NULL;
|
||||
static unsigned char imgbuf[0x1b340];
|
||||
static unsigned char irqbuf[INTR_LENGTH];
|
||||
static fpusb_urb_handle *img_urbh = NULL;
|
||||
static fpusb_urb_handle *irq_urbh = NULL;
|
||||
static libusb_urb_handle *img_urbh = NULL;
|
||||
static libusb_urb_handle *irq_urbh = NULL;
|
||||
static int img_idx = 0;
|
||||
static int do_exit = 0;
|
||||
|
||||
static struct fpusb_bulk_msg imgmsg = {
|
||||
static struct libusb_bulk_msg imgmsg = {
|
||||
.endpoint = EP_DATA,
|
||||
.data = imgbuf,
|
||||
.length = sizeof(imgbuf),
|
||||
};
|
||||
|
||||
static struct fpusb_bulk_msg irqmsg = {
|
||||
static struct libusb_bulk_msg irqmsg = {
|
||||
.endpoint = EP_INTR,
|
||||
.data = irqbuf,
|
||||
.length = sizeof(irqbuf),
|
||||
};
|
||||
|
||||
static struct fpusb_dev *find_dpfp_device(void)
|
||||
static struct libusb_dev *find_dpfp_device(void)
|
||||
{
|
||||
struct fpusb_dev *dev;
|
||||
struct libusb_dev *dev;
|
||||
|
||||
fpusb_find_devices();
|
||||
libusb_find_devices();
|
||||
|
||||
for (dev = fpusb_get_devices(); dev; dev = fpusb_dev_next(dev)) {
|
||||
struct usb_dev_descriptor *desc = fpusb_dev_get_descriptor(dev);
|
||||
for (dev = libusb_get_devices(); dev; dev = libusb_dev_next(dev)) {
|
||||
struct usb_dev_descriptor *desc = libusb_dev_get_descriptor(dev);
|
||||
if (desc->idVendor == 0x05ba && desc->idProduct == 0x000a)
|
||||
return dev;
|
||||
}
|
||||
@ -96,7 +96,7 @@ static struct fpusb_dev *find_dpfp_device(void)
|
||||
static int print_f0_data(void)
|
||||
{
|
||||
unsigned char data[0x10];
|
||||
struct fpusb_ctrl_msg msg = {
|
||||
struct libusb_ctrl_msg msg = {
|
||||
.requesttype = CTRL_IN,
|
||||
.request = USB_RQ,
|
||||
.value = 0xf0,
|
||||
@ -107,7 +107,7 @@ static int print_f0_data(void)
|
||||
int r;
|
||||
unsigned int i;
|
||||
|
||||
r = fpusb_ctrl_msg(devh, &msg, 0);
|
||||
r = libusb_ctrl_msg(devh, &msg, 0);
|
||||
if (r < 0) {
|
||||
fprintf(stderr, "F0 error %d\n", r);
|
||||
return r;
|
||||
@ -126,7 +126,7 @@ static int print_f0_data(void)
|
||||
|
||||
static int get_hwstat(unsigned char *status)
|
||||
{
|
||||
struct fpusb_ctrl_msg msg = {
|
||||
struct libusb_ctrl_msg msg = {
|
||||
.requesttype = CTRL_IN,
|
||||
.request = USB_RQ,
|
||||
.value = 0x07,
|
||||
@ -136,7 +136,7 @@ static int get_hwstat(unsigned char *status)
|
||||
};
|
||||
int r;
|
||||
|
||||
r = fpusb_ctrl_msg(devh, &msg, 0);
|
||||
r = libusb_ctrl_msg(devh, &msg, 0);
|
||||
if (r < 0) {
|
||||
fprintf(stderr, "read hwstat error %d\n", r);
|
||||
return r;
|
||||
@ -153,7 +153,7 @@ static int get_hwstat(unsigned char *status)
|
||||
static int set_hwstat(unsigned char data)
|
||||
{
|
||||
int r;
|
||||
struct fpusb_ctrl_msg msg = {
|
||||
struct libusb_ctrl_msg msg = {
|
||||
.requesttype = CTRL_OUT,
|
||||
.request = USB_RQ,
|
||||
.value = 0x07,
|
||||
@ -164,7 +164,7 @@ static int set_hwstat(unsigned char data)
|
||||
|
||||
printf("set hwstat to %02x\n", data);
|
||||
|
||||
r = fpusb_ctrl_msg(devh, &msg, 0);
|
||||
r = libusb_ctrl_msg(devh, &msg, 0);
|
||||
if (r < 0) {
|
||||
fprintf(stderr, "set hwstat error %d\n", r);
|
||||
return r;
|
||||
@ -180,7 +180,7 @@ static int set_hwstat(unsigned char data)
|
||||
static int set_mode(unsigned char data)
|
||||
{
|
||||
int r;
|
||||
struct fpusb_ctrl_msg msg = {
|
||||
struct libusb_ctrl_msg msg = {
|
||||
.requesttype = CTRL_OUT,
|
||||
.request = USB_RQ,
|
||||
.value = 0x4e,
|
||||
@ -191,7 +191,7 @@ static int set_mode(unsigned char data)
|
||||
|
||||
printf("set mode %02x\n", data);
|
||||
|
||||
r = fpusb_ctrl_msg(devh, &msg, 0);
|
||||
r = libusb_ctrl_msg(devh, &msg, 0);
|
||||
if (r < 0) {
|
||||
fprintf(stderr, "set mode error %d\n", r);
|
||||
return r;
|
||||
@ -204,8 +204,8 @@ static int set_mode(unsigned char data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void cb_mode_changed(struct fpusb_dev_handle *_devh,
|
||||
struct fpusb_urb_handle *urbh, enum fp_urb_cb_status status,
|
||||
static void cb_mode_changed(struct libusb_dev_handle *_devh,
|
||||
struct libusb_urb_handle *urbh, enum fp_urb_cb_status status,
|
||||
struct usb_ctrl_setup *setup, unsigned char *data, int actual_length,
|
||||
void *user_data)
|
||||
{
|
||||
@ -221,8 +221,8 @@ static void cb_mode_changed(struct fpusb_dev_handle *_devh,
|
||||
|
||||
static int set_mode_async(unsigned char data)
|
||||
{
|
||||
fpusb_urb_handle *urbh;
|
||||
struct fpusb_ctrl_msg msg = {
|
||||
libusb_urb_handle *urbh;
|
||||
struct libusb_ctrl_msg msg = {
|
||||
.requesttype = CTRL_OUT,
|
||||
.request = USB_RQ,
|
||||
.value = 0x4e,
|
||||
@ -233,7 +233,7 @@ static int set_mode_async(unsigned char data)
|
||||
|
||||
printf("async set mode %02x\n", data);
|
||||
|
||||
urbh = fpusb_submit_ctrl_msg(devh, &msg, cb_mode_changed, NULL, 1000);
|
||||
urbh = libusb_submit_ctrl_msg(devh, &msg, cb_mode_changed, NULL, 1000);
|
||||
if (!urbh) {
|
||||
fprintf(stderr, "set mode submit error\n");
|
||||
return -1;
|
||||
@ -244,7 +244,7 @@ static int set_mode_async(unsigned char data)
|
||||
|
||||
static int do_sync_intr(unsigned char *data)
|
||||
{
|
||||
struct fpusb_bulk_msg msg = {
|
||||
struct libusb_bulk_msg msg = {
|
||||
.endpoint = EP_INTR,
|
||||
.data = data,
|
||||
.length = INTR_LENGTH,
|
||||
@ -252,7 +252,7 @@ static int do_sync_intr(unsigned char *data)
|
||||
int r;
|
||||
int transferred;
|
||||
|
||||
r = fpusb_intr_msg(devh, &msg, &transferred, 1000);
|
||||
r = libusb_intr_msg(devh, &msg, &transferred, 1000);
|
||||
if (r < 0) {
|
||||
fprintf(stderr, "intr error %d\n", r);
|
||||
return r;
|
||||
@ -335,7 +335,7 @@ static int next_state(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void cb_irq(fpusb_dev_handle *_devh, fpusb_urb_handle *urbh,
|
||||
static void cb_irq(libusb_dev_handle *_devh, libusb_urb_handle *urbh,
|
||||
enum fp_urb_cb_status status, unsigned char endpoint, int rqlength,
|
||||
unsigned char *data, int actual_length, void *user_data)
|
||||
{
|
||||
@ -374,7 +374,7 @@ static void cb_irq(fpusb_dev_handle *_devh, fpusb_urb_handle *urbh,
|
||||
do_exit = 2;
|
||||
}
|
||||
|
||||
static void cb_img(fpusb_dev_handle *_devh, fpusb_urb_handle *urbh,
|
||||
static void cb_img(libusb_dev_handle *_devh, libusb_urb_handle *urbh,
|
||||
enum fp_urb_cb_status status, unsigned char endpoint, int rqlength,
|
||||
unsigned char *data, int actual_length, void *user_data)
|
||||
{
|
||||
@ -396,15 +396,15 @@ static void cb_img(fpusb_dev_handle *_devh, fpusb_urb_handle *urbh,
|
||||
|
||||
static int submit_irq_urb(void)
|
||||
{
|
||||
fpusb_urb_handle_free(irq_urbh);
|
||||
irq_urbh = fpusb_submit_intr_msg(devh, &irqmsg, cb_irq, NULL, 0);
|
||||
libusb_urb_handle_free(irq_urbh);
|
||||
irq_urbh = libusb_submit_intr_msg(devh, &irqmsg, cb_irq, NULL, 0);
|
||||
return irq_urbh != NULL;
|
||||
}
|
||||
|
||||
static int submit_img_urb(void)
|
||||
{
|
||||
fpusb_urb_handle_free(img_urbh);
|
||||
img_urbh = fpusb_submit_bulk_msg(devh, &imgmsg, cb_img, NULL, 0);
|
||||
libusb_urb_handle_free(img_urbh);
|
||||
img_urbh = libusb_submit_bulk_msg(devh, &imgmsg, cb_img, NULL, 0);
|
||||
return img_urbh != NULL;
|
||||
}
|
||||
|
||||
@ -418,7 +418,7 @@ static int init_capture(void)
|
||||
|
||||
r = submit_img_urb();
|
||||
if (r < 0) {
|
||||
fpusb_urb_handle_cancel_sync(devh, img_urbh);
|
||||
libusb_urb_handle_cancel_sync(devh, img_urbh);
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -468,13 +468,13 @@ static void sighandler(int signum)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct fpusb_dev *dev;
|
||||
struct libusb_dev *dev;
|
||||
struct sigaction sigact;
|
||||
int r = 1;
|
||||
|
||||
r = fpusb_init(0);
|
||||
r = libusb_init(0);
|
||||
if (r < 0) {
|
||||
fprintf(stderr, "failed to initialise fpusb\n");
|
||||
fprintf(stderr, "failed to initialise libusb\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -485,14 +485,14 @@ int main(void)
|
||||
}
|
||||
printf("found device\n");
|
||||
|
||||
devh = fpusb_devh_open(dev);
|
||||
devh = libusb_devh_open(dev);
|
||||
if (!devh) {
|
||||
fprintf(stderr, "Could not open device\n");
|
||||
goto out;
|
||||
}
|
||||
printf("opened device\n");
|
||||
|
||||
r = fpusb_devh_claim_intf(devh, 0);
|
||||
r = libusb_devh_claim_intf(devh, 0);
|
||||
if (r < 0) {
|
||||
fprintf(stderr, "usb_claim_interface error %d %s\n", r, strerror(-r));
|
||||
goto out;
|
||||
@ -521,18 +521,18 @@ int main(void)
|
||||
sigaction(SIGQUIT, &sigact, NULL);
|
||||
|
||||
while (!do_exit) {
|
||||
r = fpusb_poll();
|
||||
r = libusb_poll();
|
||||
if (r < 0)
|
||||
goto out_deinit;
|
||||
}
|
||||
|
||||
printf("shutting down...\n");
|
||||
|
||||
r = fpusb_urb_handle_cancel_sync(devh, irq_urbh);
|
||||
r = libusb_urb_handle_cancel_sync(devh, irq_urbh);
|
||||
if (r < 0)
|
||||
goto out_deinit;
|
||||
|
||||
r = fpusb_urb_handle_cancel_sync(devh, img_urbh);
|
||||
r = libusb_urb_handle_cancel_sync(devh, img_urbh);
|
||||
if (r < 0)
|
||||
goto out_deinit;
|
||||
|
||||
@ -542,15 +542,15 @@ int main(void)
|
||||
r = 1;
|
||||
|
||||
out_deinit:
|
||||
fpusb_urb_handle_free(img_urbh);
|
||||
fpusb_urb_handle_free(irq_urbh);
|
||||
libusb_urb_handle_free(img_urbh);
|
||||
libusb_urb_handle_free(irq_urbh);
|
||||
set_mode(0);
|
||||
set_hwstat(0x80);
|
||||
out_release:
|
||||
fpusb_devh_release_intf(devh, 0);
|
||||
libusb_devh_release_intf(devh, 0);
|
||||
out:
|
||||
fpusb_devh_close(devh);
|
||||
fpusb_exit();
|
||||
libusb_devh_close(devh);
|
||||
libusb_exit();
|
||||
return r >= 0 ? r : -r;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* fpusb example program to list devices on the bus
|
||||
* libusb example program to list devices on the bus
|
||||
* Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -19,28 +19,28 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <libfpusb/fpusb.h>
|
||||
#include <libusb/libusb.h>
|
||||
|
||||
void print_devs(fpusb_dev *devs)
|
||||
void print_devs(libusb_dev *devs)
|
||||
{
|
||||
fpusb_dev *dev;
|
||||
libusb_dev *dev;
|
||||
|
||||
for (dev = devs; dev; dev = fpusb_dev_next(dev)) {
|
||||
struct usb_dev_descriptor *desc = fpusb_dev_get_descriptor(dev);
|
||||
for (dev = devs; dev; dev = libusb_dev_next(dev)) {
|
||||
struct usb_dev_descriptor *desc = libusb_dev_get_descriptor(dev);
|
||||
printf("%04x:%04x\n", desc->idVendor, desc->idProduct);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
fpusb_dev *devs;
|
||||
fpusb_init(0);
|
||||
fpusb_find_devices();
|
||||
devs = fpusb_get_devices();
|
||||
libusb_dev *devs;
|
||||
libusb_init(0);
|
||||
libusb_find_devices();
|
||||
devs = libusb_get_devices();
|
||||
|
||||
print_devs(devs);
|
||||
|
||||
fpusb_exit();
|
||||
libusb_exit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,7 +0,0 @@
|
||||
lib_LTLIBRARIES = libfpusb.la
|
||||
|
||||
libfpusb_la_CFLAGS = -fvisibility=hidden $(AM_CFLAGS)
|
||||
libfpusb_la_SOURCES = signalfd.h fpusbi.h usbfs.h core.c descriptor.c io.c
|
||||
libfpusb_la_LIBADD = -lrt
|
||||
|
||||
pkginclude_HEADERS = fpusb.h
|
@ -3,9 +3,9 @@ exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: fpusb
|
||||
Name: libusb-1.0
|
||||
Description: C API for USB device access from Linux userspace
|
||||
Version: @VERSION@
|
||||
Libs: -L${libdir} -lfpusb
|
||||
Cflags: -I${includedir}/fpusb
|
||||
Libs: -L${libdir} -lusb-1.0
|
||||
Cflags: -I${includedir}/libusb-1.0
|
||||
|
7
libusb/Makefile.am
Normal file
7
libusb/Makefile.am
Normal file
@ -0,0 +1,7 @@
|
||||
lib_LTLIBRARIES = libusb-1.0.la
|
||||
|
||||
libusb_1_0_la_CFLAGS = -fvisibility=hidden $(AM_CFLAGS)
|
||||
libusb_1_0_la_SOURCES = signalfd.h libusbi.h usbfs.h core.c descriptor.c io.c
|
||||
libusb_1_0_la_LIBADD = -lrt
|
||||
|
||||
pkginclude_HEADERS = libusb.h
|
@ -1,8 +1,6 @@
|
||||
/*
|
||||
* Core functions for libfpusb
|
||||
* Core functions for libusb
|
||||
* Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
|
||||
*
|
||||
* Portions based on libusb-0.1
|
||||
* Copyright (c) 2001 Johannes Erdfelt <johannes@erdfelt.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -35,8 +33,8 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "fpusb.h"
|
||||
#include "fpusbi.h"
|
||||
#include "libusb.h"
|
||||
#include "libusbi.h"
|
||||
|
||||
static struct list_head usb_devs;
|
||||
struct list_head open_devs;
|
||||
@ -45,7 +43,7 @@ static int scan_device(char *busdir, const char *devnum)
|
||||
{
|
||||
char path[PATH_MAX + 1];
|
||||
unsigned char raw_desc[DEVICE_DESC_LENGTH];
|
||||
struct fpusb_dev *dev = malloc(sizeof(*dev));
|
||||
struct libusb_dev *dev = malloc(sizeof(*dev));
|
||||
int fd = 0;
|
||||
int i;
|
||||
int r;
|
||||
@ -168,7 +166,7 @@ static int scan_busdir(const char *busnum)
|
||||
return 0;
|
||||
}
|
||||
|
||||
API_EXPORTED int fpusb_find_devices(void)
|
||||
API_EXPORTED int libusb_find_devices(void)
|
||||
{
|
||||
DIR *busses;
|
||||
struct dirent *entry;
|
||||
@ -191,36 +189,36 @@ API_EXPORTED int fpusb_find_devices(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
API_EXPORTED struct fpusb_dev *fpusb_get_devices(void)
|
||||
API_EXPORTED struct libusb_dev *libusb_get_devices(void)
|
||||
{
|
||||
if (list_empty(&usb_devs))
|
||||
return NULL;
|
||||
return list_entry(usb_devs.next, struct fpusb_dev, list);
|
||||
return list_entry(usb_devs.next, struct libusb_dev, list);
|
||||
}
|
||||
|
||||
API_EXPORTED struct fpusb_dev *fpusb_dev_next(struct fpusb_dev *dev)
|
||||
API_EXPORTED struct libusb_dev *libusb_dev_next(struct libusb_dev *dev)
|
||||
{
|
||||
struct list_head *head = &dev->list;
|
||||
if (!head || head->next == &usb_devs)
|
||||
return NULL;
|
||||
return list_entry(head->next, struct fpusb_dev, list);
|
||||
return list_entry(head->next, struct libusb_dev, list);
|
||||
}
|
||||
|
||||
API_EXPORTED struct usb_dev_descriptor *fpusb_dev_get_descriptor(
|
||||
struct fpusb_dev *dev)
|
||||
API_EXPORTED struct usb_dev_descriptor *libusb_dev_get_descriptor(
|
||||
struct libusb_dev *dev)
|
||||
{
|
||||
return &dev->desc;
|
||||
}
|
||||
|
||||
API_EXPORTED struct usb_config_descriptor *fpusb_dev_get_config(
|
||||
struct fpusb_dev *dev)
|
||||
API_EXPORTED struct usb_config_descriptor *libusb_dev_get_config(
|
||||
struct libusb_dev *dev)
|
||||
{
|
||||
return dev->config;
|
||||
}
|
||||
|
||||
API_EXPORTED struct fpusb_dev_handle *fpusb_devh_open(struct fpusb_dev *dev)
|
||||
API_EXPORTED struct libusb_dev_handle *libusb_devh_open(struct libusb_dev *dev)
|
||||
{
|
||||
struct fpusb_dev_handle *devh;
|
||||
struct libusb_dev_handle *devh;
|
||||
int fd;
|
||||
fp_dbg("open %04x:%04x", dev->desc.idVendor, dev->desc.idProduct);
|
||||
|
||||
@ -242,12 +240,12 @@ API_EXPORTED struct fpusb_dev_handle *fpusb_devh_open(struct fpusb_dev *dev)
|
||||
return devh;
|
||||
}
|
||||
|
||||
static void do_close(struct fpusb_dev_handle *devh)
|
||||
static void do_close(struct libusb_dev_handle *devh)
|
||||
{
|
||||
close(devh->fd);
|
||||
}
|
||||
|
||||
API_EXPORTED void fpusb_devh_close(struct fpusb_dev_handle *devh)
|
||||
API_EXPORTED void libusb_devh_close(struct libusb_dev_handle *devh)
|
||||
{
|
||||
if (!devh)
|
||||
return;
|
||||
@ -258,12 +256,12 @@ API_EXPORTED void fpusb_devh_close(struct fpusb_dev_handle *devh)
|
||||
free(devh);
|
||||
}
|
||||
|
||||
API_EXPORTED struct fpusb_dev *fpusb_devh_get_dev(struct fpusb_dev_handle *devh)
|
||||
API_EXPORTED struct libusb_dev *libusb_devh_get_dev(struct libusb_dev_handle *devh)
|
||||
{
|
||||
return devh->dev;
|
||||
}
|
||||
|
||||
API_EXPORTED int fpusb_devh_claim_intf(struct fpusb_dev_handle *dev,
|
||||
API_EXPORTED int libusb_devh_claim_intf(struct libusb_dev_handle *dev,
|
||||
int iface)
|
||||
{
|
||||
int r;
|
||||
@ -275,7 +273,7 @@ API_EXPORTED int fpusb_devh_claim_intf(struct fpusb_dev_handle *dev,
|
||||
return r;
|
||||
}
|
||||
|
||||
API_EXPORTED int fpusb_devh_release_intf(struct fpusb_dev_handle *dev,
|
||||
API_EXPORTED int libusb_devh_release_intf(struct libusb_dev_handle *dev,
|
||||
int iface)
|
||||
{
|
||||
int r;
|
||||
@ -287,7 +285,7 @@ API_EXPORTED int fpusb_devh_release_intf(struct fpusb_dev_handle *dev,
|
||||
return r;
|
||||
}
|
||||
|
||||
API_EXPORTED int fpusb_init(int signum)
|
||||
API_EXPORTED int libusb_init(int signum)
|
||||
{
|
||||
/* FIXME: find correct usb node path */
|
||||
fp_dbg("");
|
||||
@ -296,9 +294,9 @@ API_EXPORTED int fpusb_init(int signum)
|
||||
return fpi_io_init(signum);
|
||||
}
|
||||
|
||||
API_EXPORTED void fpusb_exit(void)
|
||||
API_EXPORTED void libusb_exit(void)
|
||||
{
|
||||
struct fpusb_dev_handle *devh;
|
||||
struct libusb_dev_handle *devh;
|
||||
fp_dbg("");
|
||||
if (!list_empty(&open_devs)) {
|
||||
fp_dbg("naughty app left some devices open!\n");
|
||||
@ -337,7 +335,7 @@ void fpi_log(enum fpi_log_level level, const char *function,
|
||||
break;
|
||||
}
|
||||
|
||||
fprintf(stream, "fpusb:%s [%s] ", prefix, function);
|
||||
fprintf(stream, "libusb:%s [%s] ", prefix, function);
|
||||
|
||||
va_start (args, format);
|
||||
vfprintf(stream, format, args);
|
@ -1,8 +1,6 @@
|
||||
/*
|
||||
* USB descriptor handling functions for libfpusb
|
||||
* USB descriptor handling functions for libusb
|
||||
* Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
|
||||
*
|
||||
* Portions based on libusb-0.1
|
||||
* Copyright (c) 2001 Johannes Erdfelt <johannes@erdfelt.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -23,7 +21,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "fpusbi.h"
|
||||
#include "libusbi.h"
|
||||
|
||||
#define DESC_HEADER_LENGTH 2
|
||||
#define DEVICE_DESC_LENGTH 18
|
@ -1,8 +1,6 @@
|
||||
/*
|
||||
* I/O functions for libfpusb
|
||||
* I/O functions for libusb
|
||||
* Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
|
||||
*
|
||||
* Portions based on libusb-0.1
|
||||
* Copyright (c) 2001 Johannes Erdfelt <johannes@erdfelt.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -41,7 +39,7 @@
|
||||
#include "signalfd.h"
|
||||
#endif
|
||||
|
||||
#include "fpusbi.h"
|
||||
#include "libusbi.h"
|
||||
|
||||
static int sigfd;
|
||||
static int signum;
|
||||
@ -85,7 +83,7 @@ void fpi_io_exit(void)
|
||||
close(sigfd);
|
||||
}
|
||||
|
||||
static int calculate_timeout(struct fpusb_urb_handle *urbh,
|
||||
static int calculate_timeout(struct libusb_urb_handle *urbh,
|
||||
unsigned int timeout)
|
||||
{
|
||||
int r;
|
||||
@ -133,9 +131,9 @@ static int calculate_timeout(struct fpusb_urb_handle *urbh,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void add_to_flying_list(struct fpusb_urb_handle *urbh)
|
||||
static void add_to_flying_list(struct libusb_urb_handle *urbh)
|
||||
{
|
||||
struct fpusb_urb_handle *cur;
|
||||
struct libusb_urb_handle *cur;
|
||||
struct timespec *timeout = &urbh->timeout;
|
||||
|
||||
/* if we have no other flying urbs, start the list with this one */
|
||||
@ -167,8 +165,8 @@ static void add_to_flying_list(struct fpusb_urb_handle *urbh)
|
||||
list_add_tail(&urbh->list, &flying_urbs);
|
||||
}
|
||||
|
||||
static int submit_urb(struct fpusb_dev_handle *devh,
|
||||
struct fpusb_urb_handle *urbh)
|
||||
static int submit_urb(struct libusb_dev_handle *devh,
|
||||
struct libusb_urb_handle *urbh)
|
||||
{
|
||||
int r;
|
||||
struct usb_urb *urb = &urbh->urb;
|
||||
@ -198,11 +196,11 @@ static int submit_urb(struct fpusb_dev_handle *devh,
|
||||
return 0;
|
||||
}
|
||||
|
||||
API_EXPORTED struct fpusb_urb_handle *fpusb_submit_ctrl_msg(
|
||||
struct fpusb_dev_handle *devh, struct fpusb_ctrl_msg *msg,
|
||||
fpusb_ctrl_cb_fn callback, void *user_data, unsigned int timeout)
|
||||
API_EXPORTED struct libusb_urb_handle *libusb_submit_ctrl_msg(
|
||||
struct libusb_dev_handle *devh, struct libusb_ctrl_msg *msg,
|
||||
libusb_ctrl_cb_fn callback, void *user_data, unsigned int timeout)
|
||||
{
|
||||
struct fpusb_urb_handle *urbh = malloc(sizeof(*urbh));
|
||||
struct libusb_urb_handle *urbh = malloc(sizeof(*urbh));
|
||||
struct usb_ctrl_setup *setup;
|
||||
unsigned char *urbdata;
|
||||
int urbdata_length = sizeof(struct usb_ctrl_setup) + msg->length;
|
||||
@ -253,11 +251,11 @@ API_EXPORTED struct fpusb_urb_handle *fpusb_submit_ctrl_msg(
|
||||
return urbh;
|
||||
}
|
||||
|
||||
static struct fpusb_urb_handle *submit_bulk_msg(struct fpusb_dev_handle *devh,
|
||||
struct fpusb_bulk_msg *msg, fpusb_bulk_cb_fn callback, void *user_data,
|
||||
static struct libusb_urb_handle *submit_bulk_msg(struct libusb_dev_handle *devh,
|
||||
struct libusb_bulk_msg *msg, libusb_bulk_cb_fn callback, void *user_data,
|
||||
unsigned int timeout, unsigned char urbtype)
|
||||
{
|
||||
struct fpusb_urb_handle *urbh = malloc(sizeof(*urbh));
|
||||
struct libusb_urb_handle *urbh = malloc(sizeof(*urbh));
|
||||
int r;
|
||||
|
||||
fp_dbg("length %d timeout %d", msg->length, timeout);
|
||||
@ -273,7 +271,7 @@ static struct fpusb_urb_handle *submit_bulk_msg(struct fpusb_dev_handle *devh,
|
||||
urbh->devh = devh;
|
||||
urbh->callback = callback;
|
||||
urbh->user_data = user_data;
|
||||
urbh->flags |= FPUSB_URBH_DATA_BELONGS_TO_USER;
|
||||
urbh->flags |= LIBUSB_URBH_DATA_BELONGS_TO_USER;
|
||||
urbh->endpoint = msg->endpoint;
|
||||
urbh->urb_type = urbtype;
|
||||
urbh->buffer = msg->data;
|
||||
@ -288,24 +286,24 @@ static struct fpusb_urb_handle *submit_bulk_msg(struct fpusb_dev_handle *devh,
|
||||
return urbh;
|
||||
}
|
||||
|
||||
API_EXPORTED struct fpusb_urb_handle *fpusb_submit_bulk_msg(
|
||||
struct fpusb_dev_handle *devh, struct fpusb_bulk_msg *msg,
|
||||
fpusb_bulk_cb_fn callback, void *user_data, unsigned int timeout)
|
||||
API_EXPORTED struct libusb_urb_handle *libusb_submit_bulk_msg(
|
||||
struct libusb_dev_handle *devh, struct libusb_bulk_msg *msg,
|
||||
libusb_bulk_cb_fn callback, void *user_data, unsigned int timeout)
|
||||
{
|
||||
return submit_bulk_msg(devh, msg, callback, user_data, timeout,
|
||||
USB_URB_TYPE_BULK);
|
||||
}
|
||||
|
||||
API_EXPORTED struct fpusb_urb_handle *fpusb_submit_intr_msg(
|
||||
struct fpusb_dev_handle *devh, struct fpusb_bulk_msg *msg,
|
||||
fpusb_bulk_cb_fn callback, void *user_data, unsigned int timeout)
|
||||
API_EXPORTED struct libusb_urb_handle *libusb_submit_intr_msg(
|
||||
struct libusb_dev_handle *devh, struct libusb_bulk_msg *msg,
|
||||
libusb_bulk_cb_fn callback, void *user_data, unsigned int timeout)
|
||||
{
|
||||
return submit_bulk_msg(devh, msg, callback, user_data, timeout,
|
||||
USB_URB_TYPE_INTERRUPT);
|
||||
}
|
||||
|
||||
API_EXPORTED int fpusb_urb_handle_cancel(struct fpusb_dev_handle *devh,
|
||||
struct fpusb_urb_handle *urbh)
|
||||
API_EXPORTED int libusb_urb_handle_cancel(struct libusb_dev_handle *devh,
|
||||
struct libusb_urb_handle *urbh)
|
||||
{
|
||||
int r;
|
||||
fp_dbg("");
|
||||
@ -315,8 +313,8 @@ API_EXPORTED int fpusb_urb_handle_cancel(struct fpusb_dev_handle *devh,
|
||||
return r;
|
||||
}
|
||||
|
||||
API_EXPORTED int fpusb_urb_handle_cancel_sync(struct fpusb_dev_handle *devh,
|
||||
struct fpusb_urb_handle *urbh)
|
||||
API_EXPORTED int libusb_urb_handle_cancel_sync(struct libusb_dev_handle *devh,
|
||||
struct libusb_urb_handle *urbh)
|
||||
{
|
||||
int r;
|
||||
fp_dbg("");
|
||||
@ -326,9 +324,9 @@ API_EXPORTED int fpusb_urb_handle_cancel_sync(struct fpusb_dev_handle *devh,
|
||||
return r;
|
||||
}
|
||||
|
||||
urbh->flags |= FPUSB_URBH_SYNC_CANCELLED;
|
||||
while (urbh->flags & FPUSB_URBH_SYNC_CANCELLED) {
|
||||
r = fpusb_poll();
|
||||
urbh->flags |= LIBUSB_URBH_SYNC_CANCELLED;
|
||||
while (urbh->flags & LIBUSB_URBH_SYNC_CANCELLED) {
|
||||
r = libusb_poll();
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -336,8 +334,8 @@ API_EXPORTED int fpusb_urb_handle_cancel_sync(struct fpusb_dev_handle *devh,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_transfer_completion(struct fpusb_dev_handle *devh,
|
||||
struct fpusb_urb_handle *urbh, enum fp_urb_cb_status status)
|
||||
int handle_transfer_completion(struct libusb_dev_handle *devh,
|
||||
struct libusb_urb_handle *urbh, enum fp_urb_cb_status status)
|
||||
{
|
||||
struct usb_urb *urb = &urbh->urb;
|
||||
|
||||
@ -348,14 +346,14 @@ int handle_transfer_completion(struct fpusb_dev_handle *devh,
|
||||
return 0;
|
||||
|
||||
if (urb->type == USB_URB_TYPE_CONTROL) {
|
||||
fpusb_ctrl_cb_fn callback = urbh->callback;
|
||||
libusb_ctrl_cb_fn callback = urbh->callback;
|
||||
if (callback)
|
||||
callback(devh, urbh, status, urb->buffer,
|
||||
urb->buffer + sizeof(struct usb_ctrl_setup), urbh->transferred,
|
||||
urbh->user_data);
|
||||
} else if (urb->type == USB_URB_TYPE_BULK ||
|
||||
urb->type == USB_URB_TYPE_INTERRUPT) {
|
||||
fpusb_bulk_cb_fn callback = urbh->callback;
|
||||
libusb_bulk_cb_fn callback = urbh->callback;
|
||||
if (callback)
|
||||
callback(devh, urbh, status, urbh->endpoint, urbh->transfer_len,
|
||||
urbh->buffer, urbh->transferred, urbh->user_data);
|
||||
@ -363,21 +361,21 @@ int handle_transfer_completion(struct fpusb_dev_handle *devh,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int handle_transfer_cancellation(struct fpusb_dev_handle *devh,
|
||||
struct fpusb_urb_handle *urbh)
|
||||
static int handle_transfer_cancellation(struct libusb_dev_handle *devh,
|
||||
struct libusb_urb_handle *urbh)
|
||||
{
|
||||
/* if the URB is being cancelled synchronously, raise cancellation
|
||||
* completion event by unsetting flag, and ensure that user callback does
|
||||
* not get called.
|
||||
*/
|
||||
if (urbh->flags & FPUSB_URBH_SYNC_CANCELLED) {
|
||||
urbh->flags &= ~FPUSB_URBH_SYNC_CANCELLED;
|
||||
if (urbh->flags & LIBUSB_URBH_SYNC_CANCELLED) {
|
||||
urbh->flags &= ~LIBUSB_URBH_SYNC_CANCELLED;
|
||||
fp_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 & FPUSB_URBH_TIMED_OUT) {
|
||||
if (urbh->flags & LIBUSB_URBH_TIMED_OUT) {
|
||||
fp_dbg("detected timeout cancellation");
|
||||
return handle_transfer_completion(devh, urbh, FP_URB_TIMEOUT);
|
||||
}
|
||||
@ -386,11 +384,11 @@ static int handle_transfer_cancellation(struct fpusb_dev_handle *devh,
|
||||
return handle_transfer_completion(devh, urbh, FP_URB_CANCELLED);
|
||||
}
|
||||
|
||||
static int reap_for_devh(struct fpusb_dev_handle *devh)
|
||||
static int reap_for_devh(struct libusb_dev_handle *devh)
|
||||
{
|
||||
int r;
|
||||
struct usb_urb *urb;
|
||||
struct fpusb_urb_handle *urbh;
|
||||
struct libusb_urb_handle *urbh;
|
||||
int trf_requested;
|
||||
|
||||
r = ioctl(devh->fd, IOCTL_USB_REAPURBNDELAY, &urb);
|
||||
@ -401,7 +399,7 @@ static int reap_for_devh(struct fpusb_dev_handle *devh)
|
||||
return r;
|
||||
}
|
||||
|
||||
urbh = container_of(urb, struct fpusb_urb_handle, urb);
|
||||
urbh = container_of(urb, struct libusb_urb_handle, urb);
|
||||
|
||||
fp_dbg("urb type=%d status=%d transferred=%d", urb->type, urb->status,
|
||||
urb->actual_length);
|
||||
@ -439,7 +437,7 @@ static int reap_for_devh(struct fpusb_dev_handle *devh)
|
||||
return submit_urb(devh, urbh);
|
||||
}
|
||||
|
||||
static void handle_timeout(struct fpusb_urb_handle *urbh)
|
||||
static void handle_timeout(struct libusb_urb_handle *urbh)
|
||||
{
|
||||
/* handling timeouts is tricky, as we may race with the kernel: we may
|
||||
* detect a timeout racing with the condition that the urb has actually
|
||||
@ -449,8 +447,8 @@ static void handle_timeout(struct fpusb_urb_handle *urbh)
|
||||
int r;
|
||||
|
||||
|
||||
urbh->flags |= FPUSB_URBH_TIMED_OUT;
|
||||
r = fpusb_urb_handle_cancel(urbh->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);
|
||||
}
|
||||
@ -458,7 +456,7 @@ static void handle_timeout(struct fpusb_urb_handle *urbh)
|
||||
static int handle_timeouts(void)
|
||||
{
|
||||
struct timespec systime;
|
||||
struct fpusb_urb_handle *urbh;
|
||||
struct libusb_urb_handle *urbh;
|
||||
int r;
|
||||
|
||||
if (list_empty(&flying_urbs))
|
||||
@ -493,7 +491,7 @@ static int handle_timeouts(void)
|
||||
|
||||
static int reap(void)
|
||||
{
|
||||
struct fpusb_dev_handle *devh;
|
||||
struct libusb_dev_handle *devh;
|
||||
int r;
|
||||
|
||||
list_for_each_entry(devh, &open_devs, list) {
|
||||
@ -548,12 +546,12 @@ static int poll_io(struct timeval *tv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
API_EXPORTED int fpusb_poll_timeout(struct timeval *tv)
|
||||
API_EXPORTED int libusb_poll_timeout(struct timeval *tv)
|
||||
{
|
||||
return poll_io(tv);
|
||||
}
|
||||
|
||||
API_EXPORTED int fpusb_poll(void)
|
||||
API_EXPORTED int libusb_poll(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 0;
|
||||
@ -567,8 +565,8 @@ struct sync_ctrl_handle {
|
||||
int actual_length;
|
||||
};
|
||||
|
||||
static void ctrl_msg_cb(struct fpusb_dev_handle *devh,
|
||||
struct fpusb_urb_handle *urbh, enum fp_urb_cb_status status,
|
||||
static void ctrl_msg_cb(struct libusb_dev_handle *devh,
|
||||
struct libusb_urb_handle *urbh, enum fp_urb_cb_status status,
|
||||
struct usb_ctrl_setup *setup, unsigned char *data, int actual_length,
|
||||
void *user_data)
|
||||
{
|
||||
@ -586,29 +584,29 @@ static void ctrl_msg_cb(struct fpusb_dev_handle *devh,
|
||||
/* caller frees urbh */
|
||||
}
|
||||
|
||||
API_EXPORTED int fpusb_ctrl_msg(struct fpusb_dev_handle *devh,
|
||||
struct fpusb_ctrl_msg *msg, unsigned int timeout)
|
||||
API_EXPORTED int libusb_ctrl_msg(struct libusb_dev_handle *devh,
|
||||
struct libusb_ctrl_msg *msg, unsigned int timeout)
|
||||
{
|
||||
struct fpusb_urb_handle *urbh;
|
||||
struct libusb_urb_handle *urbh;
|
||||
struct sync_ctrl_handle ctrlh;
|
||||
|
||||
memset(&ctrlh, 0, sizeof(ctrlh));
|
||||
ctrlh.data = msg->data;
|
||||
|
||||
urbh = fpusb_submit_ctrl_msg(devh, msg, ctrl_msg_cb, &ctrlh, timeout);
|
||||
urbh = libusb_submit_ctrl_msg(devh, msg, ctrl_msg_cb, &ctrlh, timeout);
|
||||
if (!urbh)
|
||||
return -1;
|
||||
|
||||
while (!ctrlh.status) {
|
||||
int r = fpusb_poll();
|
||||
int r = libusb_poll();
|
||||
if (r < 0) {
|
||||
fpusb_urb_handle_cancel_sync(devh, urbh);
|
||||
fpusb_urb_handle_free(urbh);
|
||||
libusb_urb_handle_cancel_sync(devh, urbh);
|
||||
libusb_urb_handle_free(urbh);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
fpusb_urb_handle_free(urbh);
|
||||
libusb_urb_handle_free(urbh);
|
||||
switch (ctrlh.status) {
|
||||
case FP_URB_COMPLETED:
|
||||
return ctrlh.actual_length;
|
||||
@ -625,8 +623,8 @@ struct sync_bulk_handle {
|
||||
int actual_length;
|
||||
};
|
||||
|
||||
static void bulk_msg_cb(struct fpusb_dev_handle *devh,
|
||||
struct fpusb_urb_handle *urbh, enum fp_urb_cb_status status,
|
||||
static void bulk_msg_cb(struct libusb_dev_handle *devh,
|
||||
struct libusb_urb_handle *urbh, enum fp_urb_cb_status status,
|
||||
unsigned char endpoint, int rqlength, unsigned char *data,
|
||||
int actual_length, void *user_data)
|
||||
{
|
||||
@ -637,11 +635,11 @@ static void bulk_msg_cb(struct fpusb_dev_handle *devh,
|
||||
/* caller frees urbh */
|
||||
}
|
||||
|
||||
static int do_sync_bulk_msg(struct fpusb_dev_handle *devh,
|
||||
struct fpusb_bulk_msg *msg, int *transferred, unsigned int timeout,
|
||||
static int do_sync_bulk_msg(struct libusb_dev_handle *devh,
|
||||
struct libusb_bulk_msg *msg, int *transferred, unsigned int timeout,
|
||||
unsigned char urbtype)
|
||||
{
|
||||
struct fpusb_urb_handle *urbh;
|
||||
struct libusb_urb_handle *urbh;
|
||||
struct sync_bulk_handle bulkh;
|
||||
|
||||
memset(&bulkh, 0, sizeof(bulkh));
|
||||
@ -651,16 +649,16 @@ static int do_sync_bulk_msg(struct fpusb_dev_handle *devh,
|
||||
return -1;
|
||||
|
||||
while (!bulkh.status) {
|
||||
int r = fpusb_poll();
|
||||
int r = libusb_poll();
|
||||
if (r < 0) {
|
||||
fpusb_urb_handle_cancel_sync(devh, urbh);
|
||||
fpusb_urb_handle_free(urbh);
|
||||
libusb_urb_handle_cancel_sync(devh, urbh);
|
||||
libusb_urb_handle_free(urbh);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
*transferred = bulkh.actual_length;
|
||||
fpusb_urb_handle_free(urbh);
|
||||
libusb_urb_handle_free(urbh);
|
||||
|
||||
switch (bulkh.status) {
|
||||
case FP_URB_COMPLETED:
|
||||
@ -673,31 +671,31 @@ static int do_sync_bulk_msg(struct fpusb_dev_handle *devh,
|
||||
}
|
||||
}
|
||||
|
||||
API_EXPORTED int fpusb_intr_msg(struct fpusb_dev_handle *devh,
|
||||
struct fpusb_bulk_msg *msg, int *transferred, unsigned int timeout)
|
||||
API_EXPORTED int libusb_intr_msg(struct libusb_dev_handle *devh,
|
||||
struct libusb_bulk_msg *msg, int *transferred, unsigned int timeout)
|
||||
{
|
||||
return do_sync_bulk_msg(devh, msg, transferred, timeout,
|
||||
USB_URB_TYPE_INTERRUPT);
|
||||
}
|
||||
|
||||
API_EXPORTED int fpusb_bulk_msg(struct fpusb_dev_handle *devh,
|
||||
struct fpusb_bulk_msg *msg, int *transferred, unsigned int timeout)
|
||||
API_EXPORTED int libusb_bulk_msg(struct libusb_dev_handle *devh,
|
||||
struct libusb_bulk_msg *msg, int *transferred, unsigned int timeout)
|
||||
{
|
||||
return do_sync_bulk_msg(devh, msg, transferred, timeout,
|
||||
USB_URB_TYPE_BULK);
|
||||
}
|
||||
|
||||
API_EXPORTED void fpusb_urb_handle_free(struct fpusb_urb_handle *urbh)
|
||||
API_EXPORTED void libusb_urb_handle_free(struct libusb_urb_handle *urbh)
|
||||
{
|
||||
if (!urbh)
|
||||
return;
|
||||
|
||||
if (!(urbh->flags & FPUSB_URBH_DATA_BELONGS_TO_USER))
|
||||
if (!(urbh->flags & LIBUSB_URBH_DATA_BELONGS_TO_USER))
|
||||
free(urbh->urb.buffer);
|
||||
free(urbh);
|
||||
}
|
||||
|
||||
API_EXPORTED int fpusb_get_pollfd(void)
|
||||
API_EXPORTED int libusb_get_pollfd(void)
|
||||
{
|
||||
return sigfd;
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
/*
|
||||
* Public libfpusb header file
|
||||
* Public libusb header file
|
||||
* Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
|
||||
*
|
||||
* Portions based on libusb-0.1
|
||||
* Copyright (c) 2001 Johannes Erdfelt <johannes@erdfelt.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -20,8 +18,8 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef __FPUSB_H__
|
||||
#define __FPUSB_H__
|
||||
#ifndef __LIBUSB_H__
|
||||
#define __LIBUSB_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
@ -175,16 +173,16 @@ struct usb_ctrl_setup {
|
||||
uint16_t wLength;
|
||||
} __attribute__((packed));
|
||||
|
||||
/* fpusb */
|
||||
/* libusb */
|
||||
|
||||
struct fpusb_dev;
|
||||
typedef struct fpusb_dev fpusb_dev;
|
||||
struct libusb_dev;
|
||||
typedef struct libusb_dev libusb_dev;
|
||||
|
||||
struct fpusb_dev_handle;
|
||||
typedef struct fpusb_dev_handle fpusb_dev_handle;
|
||||
struct libusb_dev_handle;
|
||||
typedef struct libusb_dev_handle libusb_dev_handle;
|
||||
|
||||
struct fpusb_urb_handle;
|
||||
typedef struct fpusb_urb_handle fpusb_urb_handle;
|
||||
struct libusb_urb_handle;
|
||||
typedef struct libusb_urb_handle libusb_urb_handle;
|
||||
|
||||
enum fp_urb_cb_status {
|
||||
FP_URB_SILENT_COMPLETION = 0,
|
||||
@ -193,7 +191,7 @@ enum fp_urb_cb_status {
|
||||
FP_URB_CANCELLED,
|
||||
};
|
||||
|
||||
struct fpusb_ctrl_msg {
|
||||
struct libusb_ctrl_msg {
|
||||
uint8_t requesttype;
|
||||
uint8_t request;
|
||||
uint16_t value;
|
||||
@ -202,63 +200,63 @@ struct fpusb_ctrl_msg {
|
||||
unsigned char *data;
|
||||
};
|
||||
|
||||
typedef void (*fpusb_ctrl_cb_fn)(fpusb_dev_handle *devh, fpusb_urb_handle *urbh,
|
||||
typedef void (*libusb_ctrl_cb_fn)(libusb_dev_handle *devh, libusb_urb_handle *urbh,
|
||||
enum fp_urb_cb_status status, struct usb_ctrl_setup *setup,
|
||||
unsigned char *data, int actual_length, void *user_data);
|
||||
|
||||
struct fpusb_bulk_msg {
|
||||
struct libusb_bulk_msg {
|
||||
unsigned char endpoint;
|
||||
unsigned char *data;
|
||||
int length;
|
||||
};
|
||||
|
||||
typedef void (*fpusb_bulk_cb_fn)(fpusb_dev_handle *devh, fpusb_urb_handle *urbh,
|
||||
typedef void (*libusb_bulk_cb_fn)(libusb_dev_handle *devh, libusb_urb_handle *urbh,
|
||||
enum fp_urb_cb_status status, unsigned char endpoint,
|
||||
int rqlength, unsigned char *data, int actual_length, void *user_data);
|
||||
|
||||
int fpusb_init(int signum);
|
||||
void fpusb_exit(void);
|
||||
int libusb_init(int signum);
|
||||
void libusb_exit(void);
|
||||
|
||||
int fpusb_find_devices(void);
|
||||
fpusb_dev *fpusb_get_devices(void);
|
||||
struct usb_dev_descriptor *fpusb_dev_get_descriptor(fpusb_dev *dev);
|
||||
struct usb_config_descriptor *fpusb_dev_get_config(fpusb_dev *dev);
|
||||
fpusb_dev *fpusb_dev_next(fpusb_dev *dev);
|
||||
int libusb_find_devices(void);
|
||||
libusb_dev *libusb_get_devices(void);
|
||||
struct usb_dev_descriptor *libusb_dev_get_descriptor(libusb_dev *dev);
|
||||
struct usb_config_descriptor *libusb_dev_get_config(libusb_dev *dev);
|
||||
libusb_dev *libusb_dev_next(libusb_dev *dev);
|
||||
|
||||
fpusb_dev_handle *fpusb_devh_open(fpusb_dev *dev);
|
||||
void fpusb_devh_close(fpusb_dev_handle *devh);
|
||||
struct fpusb_dev *fpusb_devh_get_dev(fpusb_dev_handle *devh);
|
||||
int fpusb_devh_claim_intf(fpusb_dev_handle *dev, int iface);
|
||||
int fpusb_devh_release_intf(fpusb_dev_handle *dev, int iface);
|
||||
libusb_dev_handle *libusb_devh_open(libusb_dev *dev);
|
||||
void libusb_devh_close(libusb_dev_handle *devh);
|
||||
struct libusb_dev *libusb_devh_get_dev(libusb_dev_handle *devh);
|
||||
int libusb_devh_claim_intf(libusb_dev_handle *dev, int iface);
|
||||
int libusb_devh_release_intf(libusb_dev_handle *dev, int iface);
|
||||
|
||||
/* async I/O */
|
||||
|
||||
fpusb_urb_handle *fpusb_submit_ctrl_msg(fpusb_dev_handle *devh,
|
||||
struct fpusb_ctrl_msg *msg, fpusb_ctrl_cb_fn callback, void *user_data,
|
||||
libusb_urb_handle *libusb_submit_ctrl_msg(libusb_dev_handle *devh,
|
||||
struct libusb_ctrl_msg *msg, libusb_ctrl_cb_fn callback, void *user_data,
|
||||
unsigned int timeout);
|
||||
fpusb_urb_handle *fpusb_submit_bulk_msg(fpusb_dev_handle *devh,
|
||||
struct fpusb_bulk_msg *msg, fpusb_bulk_cb_fn callback, void *user_data,
|
||||
libusb_urb_handle *libusb_submit_bulk_msg(libusb_dev_handle *devh,
|
||||
struct libusb_bulk_msg *msg, libusb_bulk_cb_fn callback, void *user_data,
|
||||
unsigned int timeout);
|
||||
fpusb_urb_handle *fpusb_submit_intr_msg(fpusb_dev_handle *devh,
|
||||
struct fpusb_bulk_msg *msg, fpusb_bulk_cb_fn callback, void *user_data,
|
||||
libusb_urb_handle *libusb_submit_intr_msg(libusb_dev_handle *devh,
|
||||
struct libusb_bulk_msg *msg, libusb_bulk_cb_fn callback, void *user_data,
|
||||
unsigned int timeout);
|
||||
|
||||
int fpusb_urb_handle_cancel(fpusb_dev_handle *devh, fpusb_urb_handle *urbh);
|
||||
int fpusb_urb_handle_cancel_sync(fpusb_dev_handle *devh,
|
||||
fpusb_urb_handle *urbh);
|
||||
void fpusb_urb_handle_free(fpusb_urb_handle *urbh);
|
||||
int libusb_urb_handle_cancel(libusb_dev_handle *devh, libusb_urb_handle *urbh);
|
||||
int libusb_urb_handle_cancel_sync(libusb_dev_handle *devh,
|
||||
libusb_urb_handle *urbh);
|
||||
void libusb_urb_handle_free(libusb_urb_handle *urbh);
|
||||
|
||||
int fpusb_poll_timeout(struct timeval *tv);
|
||||
int fpusb_poll(void);
|
||||
int fpusb_get_pollfd(void);
|
||||
int libusb_poll_timeout(struct timeval *tv);
|
||||
int libusb_poll(void);
|
||||
int libusb_get_pollfd(void);
|
||||
|
||||
/* sync I/O */
|
||||
|
||||
int fpusb_ctrl_msg(fpusb_dev_handle *devh, struct fpusb_ctrl_msg *msg,
|
||||
int libusb_ctrl_msg(libusb_dev_handle *devh, struct libusb_ctrl_msg *msg,
|
||||
unsigned int timeout);
|
||||
int fpusb_bulk_msg(fpusb_dev_handle *devh, struct fpusb_bulk_msg *msg,
|
||||
int libusb_bulk_msg(libusb_dev_handle *devh, struct libusb_bulk_msg *msg,
|
||||
int *transferred, unsigned int timeout);
|
||||
int fpusb_intr_msg(fpusb_dev_handle *devh, struct fpusb_bulk_msg *msg,
|
||||
int libusb_intr_msg(libusb_dev_handle *devh, struct libusb_bulk_msg *msg,
|
||||
int *transferred, unsigned int timeout);
|
||||
|
||||
#endif
|
@ -1,8 +1,6 @@
|
||||
/*
|
||||
* Internal header for libfpusb
|
||||
* Internal header for libusb
|
||||
* Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
|
||||
*
|
||||
* Portions based on libusb-0.1
|
||||
* Copyright (c) 2001 Johannes Erdfelt <johannes@erdfelt.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -20,8 +18,8 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef __FPUSBI_H__
|
||||
#define __FPUSBI_H__
|
||||
#ifndef __LIBUSBI_H__
|
||||
#define __LIBUSBI_H__
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@ -30,7 +28,7 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <fpusb.h>
|
||||
#include <libusb.h>
|
||||
#include <usbfs.h>
|
||||
|
||||
#define USBFS_PATH "/dev/bus/usb"
|
||||
@ -145,30 +143,30 @@ void fpi_log(enum fpi_log_level, const char *function, const char *format, ...);
|
||||
#define fp_warn(fmt...) _fpi_log(LOG_LEVEL_WARNING, fmt)
|
||||
#define fp_err(fmt...) _fpi_log(LOG_LEVEL_ERROR, fmt)
|
||||
|
||||
struct fpusb_dev {
|
||||
struct libusb_dev {
|
||||
struct list_head list;
|
||||
char *nodepath;
|
||||
struct usb_dev_descriptor desc;
|
||||
struct usb_config_descriptor *config;
|
||||
};
|
||||
|
||||
struct fpusb_dev_handle {
|
||||
struct libusb_dev_handle {
|
||||
struct list_head list;
|
||||
struct fpusb_dev *dev;
|
||||
struct libusb_dev *dev;
|
||||
int fd;
|
||||
};
|
||||
|
||||
enum fpusb_urb_type {
|
||||
FPUSB_URB_CONTROL,
|
||||
FPUSB_URB_BULK,
|
||||
enum libusb_urb_type {
|
||||
LIBUSB_URB_CONTROL,
|
||||
LIBUSB_URB_BULK,
|
||||
};
|
||||
|
||||
#define FPUSB_URBH_DATA_BELONGS_TO_USER (1<<0)
|
||||
#define FPUSB_URBH_SYNC_CANCELLED (1<<1)
|
||||
#define FPUSB_URBH_TIMED_OUT (1<<2)
|
||||
#define LIBUSB_URBH_DATA_BELONGS_TO_USER (1<<0)
|
||||
#define LIBUSB_URBH_SYNC_CANCELLED (1<<1)
|
||||
#define LIBUSB_URBH_TIMED_OUT (1<<2)
|
||||
|
||||
struct fpusb_urb_handle {
|
||||
struct fpusb_dev_handle *devh;
|
||||
struct libusb_urb_handle {
|
||||
struct libusb_dev_handle *devh;
|
||||
struct usb_urb urb;
|
||||
struct list_head list;
|
||||
struct timespec timeout;
|
@ -20,8 +20,8 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef __FPUSB_SIGNALFD_H__
|
||||
#define __FPUSB_SIGNALFD_H__
|
||||
#ifndef __LIBUSB_SIGNALFD_H__
|
||||
#define __LIBUSB_SIGNALFD_H__
|
||||
|
||||
/* FIXME: in future, remove this and unconditionally use glibc directly when
|
||||
* glibc-2.8 is widespread */
|
@ -1,8 +1,6 @@
|
||||
/*
|
||||
* usbfs header structures
|
||||
* Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
|
||||
*
|
||||
* Portions based on libusb-0.1
|
||||
* Copyright (c) 2001 Johannes Erdfelt <johannes@erdfelt.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -20,8 +18,8 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef __FPUSB_USBFS_H__
|
||||
#define __FPUSB_USBFS_H__
|
||||
#ifndef __LIBUSB_USBFS_H__
|
||||
#define __LIBUSB_USBFS_H__
|
||||
|
||||
struct usb_ctrltransfer {
|
||||
/* keep in sync with usbdevice_fs.h:usbdevfs_ctrltransfer */
|
Loading…
Reference in New Issue
Block a user