Commit bf7093d6 authored by Daniel Drake's avatar Daniel Drake

Port to libusb-0.9.0 (synchronous I/O)

Straightforward port to libusb-0.9.0 sync I/O functions, to give libusb-1.0
a bit of a test drive and to create a reference point for later.
parent 6f456f39
......@@ -17,7 +17,7 @@ AC_SUBST(lt_major)
AC_SUBST(lt_revision)
AC_SUBST(lt_age)
PKG_CHECK_MODULES(LIBUSB, "libusb")
PKG_CHECK_MODULES(LIBUSB, [libusb-1.0 = 0.9.0])
AC_SUBST(LIBUSB_CFLAGS)
AC_SUBST(LIBUSB_LIBS)
......
......@@ -21,6 +21,7 @@
#include <errno.h>
#include <libusb.h>
#include <glib.h>
#include "fp_internal.h"
......@@ -29,8 +30,8 @@
#define MAX_REGWRITES_PER_REQUEST 16
#define BULK_TIMEOUT 4000
#define EP_IN (1 | USB_ENDPOINT_IN)
#define EP_OUT (2 | USB_ENDPOINT_OUT)
#define EP_IN (1 | LIBUSB_ENDPOINT_IN)
#define EP_OUT (2 | LIBUSB_ENDPOINT_OUT)
static int do_write_regv(struct fp_img_dev *dev,
const struct aes_regwrite *regs, unsigned int num)
......@@ -40,18 +41,24 @@ static int do_write_regv(struct fp_img_dev *dev,
unsigned int i;
size_t offset = 0;
int r;
int transferred;
struct libusb_bulk_transfer msg = {
.endpoint = EP_OUT,
.data = data,
.length = alloc_size,
};
for (i = 0; i < num; i++) {
data[offset++] = regs[i].reg;
data[offset++] = regs[i].value;
}
r = usb_bulk_write(dev->udev, EP_OUT, data, alloc_size, BULK_TIMEOUT);
r = libusb_bulk_transfer(dev->udev, &msg, &transferred, BULK_TIMEOUT);
g_free(data);
if (r < 0) {
fp_err("bulk write error %d", r);
return r;
} else if ((unsigned int) r < alloc_size) {
} else if ((unsigned int) transferred < alloc_size) {
fp_err("unexpected short write %d/%d", r, alloc_size);
return -EIO;
}
......
......@@ -22,7 +22,7 @@
#include <stdio.h>
#include <glib.h>
#include <usb.h>
#include <libusb.h>
#include "fp_internal.h"
......@@ -351,18 +351,18 @@ static void register_drivers(void)
}
}
static struct fp_driver *find_supporting_driver(struct usb_device *udev,
static struct fp_driver *find_supporting_driver(libusb_dev *udev,
const struct usb_id **usb_id)
{
GSList *elem = registered_drivers;
struct libusb_dev_descriptor *dsc = libusb_dev_get_descriptor(udev);
do {
struct fp_driver *drv = elem->data;
const struct usb_id *id;
for (id = drv->id_table; id->vendor; id++)
if (udev->descriptor.idVendor == id->vendor &&
udev->descriptor.idProduct == id->product) {
if (dsc->idVendor == id->vendor && dsc->idProduct == id->product) {
fp_dbg("driver %s supports USB device %04x:%04x",
drv->name, id->vendor, id->product);
*usb_id = id;
......@@ -372,7 +372,7 @@ static struct fp_driver *find_supporting_driver(struct usb_device *udev,
return NULL;
}
static struct fp_dscv_dev *discover_dev(struct usb_device *udev)
static struct fp_dscv_dev *discover_dev(libusb_dev *udev)
{
const struct usb_id *usb_id;
struct fp_driver *drv = find_supporting_driver(udev, &usb_id);
......@@ -408,23 +408,20 @@ API_EXPORTED struct fp_dscv_dev **fp_discover_devs(void)
{
GSList *tmplist = NULL;
struct fp_dscv_dev **list;
struct usb_device *udev;
struct usb_bus *bus;
struct libusb_dev *udev;
int dscv_count = 0;
if (registered_drivers == NULL)
return NULL;
usb_find_busses();
usb_find_devices();
libusb_find_devices();
/* Check each device against each driver, temporarily storing successfully
* discovered devices in a GSList.
*
* Quite inefficient but excusable as we'll only be dealing with small
* sets of drivers against small sets of USB devices */
for (bus = usb_get_busses(); bus; bus = bus->next)
for (udev = bus->devices; udev; udev = udev->next) {
for (udev = libusb_get_devices(); udev; udev = libusb_dev_next(udev)) {
struct fp_dscv_dev *ddev = discover_dev(udev);
if (!ddev)
continue;
......@@ -581,7 +578,7 @@ API_EXPORTED struct fp_dev *fp_dev_open(struct fp_dscv_dev *ddev)
struct fp_driver *drv = ddev->drv;
int r;
usb_dev_handle *udevh = usb_open(ddev->udev);
libusb_dev_handle *udevh = libusb_open(ddev->udev);
if (!udevh) {
fp_err("usb_open failed");
return NULL;
......@@ -596,7 +593,7 @@ API_EXPORTED struct fp_dev *fp_dev_open(struct fp_dscv_dev *ddev)
r = drv->init(dev, ddev->driver_data);
if (r) {
fp_err("device initialisation failed, driver=%s", drv->name);
usb_close(udevh);
libusb_close(udevh);
g_free(dev);
return NULL;
}
......@@ -612,7 +609,7 @@ static void do_close(struct fp_dev *dev)
{
if (dev->drv->exit)
dev->drv->exit(dev);
usb_close(dev->udev);
libusb_close(dev->udev);
g_free(dev);
}
......@@ -1119,8 +1116,13 @@ API_EXPORTED int fp_identify_finger_img(struct fp_dev *dev,
*/
API_EXPORTED int fp_init(void)
{
int r;
fp_dbg("");
usb_init();
r = libusb_init();
if (r < 0)
return r;
register_drivers();
return 0;
}
......@@ -1147,5 +1149,6 @@ API_EXPORTED void fp_exit(void)
fpi_data_exit();
g_slist_free(registered_drivers);
registered_drivers = NULL;
libusb_exit();
}
......@@ -19,6 +19,7 @@
#include <config.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
......
......@@ -27,14 +27,14 @@
#include <errno.h>
#include <string.h>
#include <usb.h>
#include <libusb.h>
#include <aeslib.h>
#include <fp_internal.h>
/* FIXME these need checking */
#define EP_IN (1 | USB_ENDPOINT_IN)
#define EP_OUT (2 | USB_ENDPOINT_OUT)
#define EP_IN (1 | LIBUSB_ENDPOINT_IN)
#define EP_OUT (2 | LIBUSB_ENDPOINT_OUT)
#define BULK_TIMEOUT 4000
......@@ -63,13 +63,19 @@
static int read_data(struct fp_img_dev *dev, unsigned char *data, size_t len)
{
int r;
int transferred;
struct libusb_bulk_transfer msg = {
.endpoint = EP_IN,
.data = data,
.length = len,
};
fp_dbg("len=%zd", len);
r = usb_bulk_read(dev->udev, EP_IN, data, len, BULK_TIMEOUT);
r = libusb_bulk_transfer(dev->udev, &msg, &transferred, BULK_TIMEOUT);
if (r < 0) {
fp_err("bulk read error %d", r);
return r;
} else if (r < (int) len) {
} else if (transferred < len) {
fp_err("unexpected short read %d/%zd", r, len);
return -EIO;
}
......@@ -88,7 +94,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data)
{
int r;
r = usb_claim_interface(dev->udev, 0);
r = libusb_claim_interface(dev->udev, 0);
if (r < 0) {
fp_err("could not claim interface 0");
return r;
......@@ -107,7 +113,7 @@ static int do_exit(struct fp_img_dev *dev)
static void dev_exit(struct fp_img_dev *dev)
{
do_exit(dev);
usb_release_interface(dev->udev, 0);
libusb_release_interface(dev->udev, 0);
}
static const struct aes_regwrite finger_det_reqs[] = {
......
......@@ -26,15 +26,15 @@
#include <errno.h>
#include <string.h>
#include <usb.h>
#include <libusb.h>
#include <aeslib.h>
#include <fp_internal.h>
#include "aes2501.h"
/* FIXME these need checking */
#define EP_IN (1 | USB_ENDPOINT_IN)
#define EP_OUT (2 | USB_ENDPOINT_OUT)
#define EP_IN (1 | LIBUSB_ENDPOINT_IN)
#define EP_OUT (2 | LIBUSB_ENDPOINT_OUT)
#define BULK_TIMEOUT 4000
......@@ -60,13 +60,19 @@
static int read_data(struct fp_img_dev *dev, unsigned char *data, size_t len)
{
int r;
int transferred;
struct libusb_bulk_transfer msg = {
.endpoint = EP_IN,
.data = data,
.length = len,
};
fp_dbg("len=%zd", len);
r = usb_bulk_read(dev->udev, EP_IN, data, len, BULK_TIMEOUT);
r = libusb_bulk_transfer(dev->udev, &msg, &transferred, BULK_TIMEOUT);
if (r < 0) {
fp_err("bulk read error %d", r);
return r;
} else if (r < len) {
} else if (transferred < len) {
fp_err("unexpected short read %d/%zd", r, len);
return -EIO;
}
......@@ -232,7 +238,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data)
{
int r;
r = usb_claim_interface(dev->udev, 0);
r = libusb_claim_interface(dev->udev, 0);
if (r < 0) {
fp_err("could not claim interface 0");
return r;
......@@ -245,7 +251,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data)
static void dev_exit(struct fp_img_dev *dev)
{
usb_release_interface(dev->udev, 0);
libusb_release_interface(dev->udev, 0);
}
static const struct aes_regwrite finger_det_reqs[] = {
......
......@@ -22,14 +22,14 @@
#include <errno.h>
#include <glib.h>
#include <usb.h>
#include <libusb.h>
#include <aeslib.h>
#include <fp_internal.h>
#define CTRL_TIMEOUT 1000
#define EP_IN (1 | USB_ENDPOINT_IN)
#define EP_OUT (2 | USB_ENDPOINT_OUT)
#define EP_IN (1 | LIBUSB_ENDPOINT_IN)
#define EP_OUT (2 | LIBUSB_ENDPOINT_OUT)
#define DATA_BUFLEN 0x1259
#define NR_SUBARRAYS 6
#define SUBARRAY_LEN 768
......@@ -114,9 +114,14 @@ static int capture(struct fp_img_dev *dev, gboolean unconditional,
{
int i;
int r;
int transferred;
struct fp_img *img;
unsigned char *data;
unsigned char *ptr;
struct libusb_bulk_transfer msg = {
.endpoint = EP_IN,
.length = DATA_BUFLEN,
};
r = aes_write_regv(dev, init_reqs, G_N_ELEMENTS(init_reqs));
if (r < 0)
......@@ -125,18 +130,19 @@ static int capture(struct fp_img_dev *dev, gboolean unconditional,
img = fpi_img_new_for_imgdev(dev);
data = g_malloc(DATA_BUFLEN);
ptr = data;
msg.data = data;
/* See the timeout explanation in the uru4000 driver for the reasoning
* behind this silly loop. */
retry:
r = usb_bulk_read(dev->udev, EP_IN, data, DATA_BUFLEN, 1000);
r = libusb_bulk_transfer(dev->udev, &msg, &transferred, 1000);
if (r == -ETIMEDOUT)
goto retry;
if (r < 0) {
fp_err("data read failed, error %d", r);
goto err;
} else if (r < DATA_BUFLEN) {
} else if (transferred < DATA_BUFLEN) {
fp_err("short data read (%d)", r);
r = -EIO;
goto err;
......@@ -163,7 +169,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data)
{
int r;
r = usb_claim_interface(dev->udev, 0);
r = libusb_claim_interface(dev->udev, 0);
if (r < 0) {
fp_err("could not claim interface 0");
return r;
......@@ -174,7 +180,7 @@ static int dev_init(struct fp_img_dev *dev, unsigned long driver_data)
static void dev_exit(struct fp_img_dev *dev)
{
usb_release_interface(dev->udev, 0);
libusb_release_interface(dev->udev, 0);
}
static const struct usb_id id_table[] = {
......
......@@ -21,7 +21,7 @@
#include <string.h>
#include <unistd.h>
#include <usb.h>
#include <libusb.h>
#define FP_COMPONENT "fdu2000"
#include <fp_internal.h>
......@@ -53,9 +53,9 @@ memmem(const gpointer haystack, size_t haystack_len, const gpointer needle, size
}
#endif /* HAVE_MEMMEM */
#define EP_IMAGE ( 0x02 | USB_ENDPOINT_IN )
#define EP_REPLY ( 0x01 | USB_ENDPOINT_IN )
#define EP_CMD ( 0x01 | USB_ENDPOINT_OUT )
#define EP_IMAGE ( 0x02 | LIBUSB_ENDPOINT_IN )
#define EP_REPLY ( 0x01 | LIBUSB_ENDPOINT_IN )
#define EP_CMD ( 0x01 | LIBUSB_ENDPOINT_OUT )
#define BULK_TIMEOUT 200
/* fdu_req[] index */
......@@ -112,15 +112,26 @@ static const struct fdu2000_req {
* Write a command and verify reponse
*/
static gint
bulk_write_safe(usb_dev_handle *dev, req_index rIndex) {
bulk_write_safe(libusb_dev_handle *dev, req_index rIndex) {
gchar reponse[ACK_LEN];
gint r;
gchar *cmd = (gchar *)fdu_req[rIndex].cmd;
gchar *ack = (gchar *)fdu_req[rIndex].ack;
gint ack_len = fdu_req[rIndex].ack_len;
r = usb_bulk_write(dev, EP_CMD, cmd, sizeof(cmd), BULK_TIMEOUT);
struct libusb_bulk_transfer wrmsg = {
.endpoint = EP_CMD,
.data = cmd,
.length = sizeof(cmd),
};
struct libusb_bulk_transfer readmsg = {
.endpoint = EP_REPLY,
.data = reponse,
.length = sizeof(reponse),
};
int trf;
r = libusb_bulk_transfer(dev, &wrmsg, &trf, BULK_TIMEOUT);
if (r < 0)
return r;
......@@ -128,8 +139,7 @@ bulk_write_safe(usb_dev_handle *dev, req_index rIndex) {
return 0;
/* Check reply from FP */
r = usb_bulk_read (dev, EP_REPLY,
reponse, sizeof(reponse), BULK_TIMEOUT);
r = libusb_bulk_transfer(dev, &readmsg, &trf, BULK_TIMEOUT);
if (r < 0)
return r;
......@@ -149,15 +159,19 @@ capture(struct fp_img_dev *dev, gboolean unconditional,
#define RAW_IMAGE_SIZE (RAW_IMAGE_WIDTH * RAW_IMAGE_HEIGTH)
struct fp_img *img = NULL;
guint bytes, r;
int bytes, r;
const gchar SOF[] = { 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x0c, 0x07 }; // Start of frame
const gchar SOL[] = { 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x0b, 0x06 }; // Start of line + { L L } (L: Line num) (8 nibbles)
gchar *buffer;
gchar *buffer = g_malloc0(RAW_IMAGE_SIZE * 6);
gchar *image;
gchar *p;
guint offset;
struct libusb_bulk_transfer msg = {
.endpoint = EP_IMAGE,
.data = buffer,
.length = RAW_IMAGE_SIZE * 6,
};
buffer = g_malloc0(RAW_IMAGE_SIZE * 6);
image = g_malloc0(RAW_IMAGE_SIZE);
if ((r = bulk_write_safe(dev->udev, LED_ON))) {
......@@ -178,12 +192,8 @@ read:
/* Now we are ready to read from dev */
bytes = usb_bulk_read(dev->udev,
EP_IMAGE,
buffer, RAW_IMAGE_SIZE * 6,
BULK_TIMEOUT * 10);
if (bytes < 1)
r = libusb_bulk_transfer(dev->udev, &msg, &bytes, BULK_TIMEOUT * 10);
if (r < 0 || bytes < 1)
goto read;
/*
......@@ -249,17 +259,17 @@ static
gint dev_init(struct fp_img_dev *dev, unsigned long driver_data)
{
gint r;
if ( (r = usb_set_configuration(dev->udev, 1)) < 0 )
goto out;
//if ( (r = usb_set_configuration(dev->udev, 1)) < 0 )
// goto out;
if ( (r = usb_claim_interface(dev->udev, 0)) < 0 )
if ( (r = libusb_claim_interface(dev->udev, 0)) < 0 )
goto out;
if ( (r = usb_set_altinterface(dev->udev, 1)) < 0 )
goto out;
//if ( (r = usb_set_altinterface(dev->udev, 1)) < 0 )
// goto out;
if ( (r = usb_clear_halt(dev->udev, EP_CMD)) < 0 )
goto out;
//if ( (r = usb_clear_halt(dev->udev, EP_CMD)) < 0 )
// goto out;
/* Make sure sensor mode is not capture_{ready|read} */
if ((r = bulk_write_safe(dev->udev, CAPTURE_END))) {
......@@ -276,7 +286,6 @@ gint dev_init(struct fp_img_dev *dev, unsigned long driver_data)
out:
fp_err("could not init dev");
fp_err(usb_strerror());
return r;
}
......@@ -286,7 +295,7 @@ void dev_exit(struct fp_img_dev *dev)
if (bulk_write_safe(dev->udev, CAPTURE_END))
fp_err("Command: CAPTURE_END");
usb_release_interface(dev->udev, 0);
libusb_release_interface(dev->udev, 0);
}
static const struct usb_id id_table[] = {
......
......@@ -23,7 +23,7 @@
#include <string.h>
#include <glib.h>
#include <usb.h>
#include <libusb.h>
#include <fp_internal.h>
......@@ -70,9 +70,20 @@ static const unsigned char anInitCommand[ 0x40 ] = {
static sint32 askScanner( struct fp_img_dev *dev, const unsigned char *pnRawString, sint32 nLen, sint8 *pnBuffer ) {
sint8 anBuf[ 65535 ];
sint32 nRet;
int transferred;
struct libusb_bulk_transfer msg1 = {
.endpoint = 3,
.data = pnRawString,
.length = 0x40,
};
struct libusb_bulk_transfer msg2 = {
.endpoint = 0x82,
.data = anBuf,
.length = nLen,
};
nRet = usb_bulk_write( dev -> udev, 0x00000003, pnRawString, 0x40, 1003 );
if ( nRet != 0x40 ) {
nRet = libusb_bulk_transfer(dev->udev, &msg1, &transferred, 1003);
if (transferred != 0x40) {
return -1;
}
......@@ -80,10 +91,10 @@ static sint32 askScanner( struct fp_img_dev *dev, const unsigned char *pnRawStri
return 0;
}
nRet = usb_bulk_read( dev -> udev, 0x00000082, anBuf, nLen, 1003 );
if ( ( nRet == nLen ) && ( pnBuffer != NULL ) ) {
nRet = libusb_bulk_transfer(dev->udev, &msg2, &transferred, 1003);
if ( ( transferred == nLen ) && ( pnBuffer != NULL ) ) {
memcpy( pnBuffer, anBuf, nLen );
return nRet;
return transferred;
}
return nRet;
......@@ -114,7 +125,7 @@ static sint32 ValidScan( sint8 *pnImage ) {
* \return error code
*/
static sint32 SetupSensor( struct fp_img_dev *dev ) {
usb_claim_interface( dev -> udev, 0 );
libusb_claim_interface(dev->udev, 0);
/* setup sensor */
if ( askScanner( dev, "\x03\x00\x00\x00\x02\xfe\x00\x01\xc0\xbd\xf0\xff\xff\xff\xff\xff\x00\xf0\xfd\x7f\x00\x60\xfd\x7f\x14\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\xcc\xf8\x2f\x01\x09\x48\xe7\x77\xf0\xfa\x2f\x01\x09\x48\xe7\x77\xe0\x3a\xe6\x77", 0x00, NULL ) < 0 ) {
......@@ -365,7 +376,7 @@ static int capture( struct fp_img_dev *dev, gboolean unconditional, struct fp_im
static int dev_init( struct fp_img_dev *dev, unsigned long driver_data ) {
int nResult;
nResult = usb_claim_interface( dev -> udev, 0 );
nResult = libusb_claim_interface(dev->udev, 0);
if ( nResult < 0 ) {
fp_err( "could not claim interface 0" );
return nResult;
......@@ -377,7 +388,7 @@ static int dev_init( struct fp_img_dev *dev, unsigned long driver_data ) {
}
static void dev_exit( struct fp_img_dev *dev ) {
usb_release_interface( dev -> udev, 0 );
libusb_release_interface(dev->udev, 0);
}
static const struct usb_id id_table[] = {
......
......@@ -31,12 +31,12 @@
#include <string.h>
#include <glib.h>
#include <usb.h>
#include <libusb.h>
#include <fp_internal.h>
#define EP_IN (1 | USB_ENDPOINT_IN)
#define EP_OUT (2 | USB_ENDPOINT_OUT)
#define EP_IN (1 | LIBUSB_ENDPOINT_IN)
#define EP_OUT (2 | LIBUSB_ENDPOINT_OUT)
#define TIMEOUT 5000
struct upekts_dev {
......@@ -131,6 +131,7 @@ static int send_cmd(struct fp_dev *dev, unsigned char seq_a,
unsigned char seq_b, unsigned char *data, uint16_t len)
{
int r;
int transferred;
uint16_t crc;
/* 9 bytes extra for: 4 byte 'Ciao', 1 byte A, 1 byte B | lenHI,
......@@ -138,6 +139,11 @@ static int send_cmd(struct fp_dev *dev, unsigned char seq_a,
size_t urblen = len + 9;
unsigned char *buf;
struct libusb_bulk_transfer msg = {
.endpoint = EP_OUT,
.length = urblen,
};
if (!data && len > 0) {
fp_err("len>0 but no data?");
return -EINVAL;
......@@ -161,12 +167,13 @@ static int send_cmd(struct fp_dev *dev, unsigned char seq_a,
buf[urblen - 2] = crc >> 8;
buf[urblen - 1] = crc & 0xff;
r = usb_bulk_write(dev->udev, EP_OUT, buf, urblen, TIMEOUT);
msg.data = buf;
r = libusb_bulk_transfer(dev->udev, &msg, &transferred, TIMEOUT);
g_free(buf);
if (r < 0) {
fp_err("cmd write failed, code %d", r);
return r;
} else if ((unsigned int) r < urblen) {
} else if ((unsigned int) transferred < urblen) {
fp_err("cmd write too short (%d/%d)", r, urblen);
return -EIO;
}
......@@ -217,12 +224,19 @@ static unsigned char *__read_msg(struct fp_dev *dev, size_t *data_len)
uint16_t computed_crc, msg_crc;
uint16_t len;
int r;
int transferred;
struct libusb_bulk_transfer msg = {
.endpoint = EP_IN,
.data = buf,
.length = buf_size,
};
r = usb_bulk_read(dev->udev, EP_IN, buf, buf_size, TIMEOUT);
r = libusb_bulk_transfer(dev->udev, &msg, &transferred, TIMEOUT);
if (r < 0) {
fp_err("msg read failed, code %d", r);
goto err;
} else if (r < 9) {
} else if (transferred < 9) {
fp_err("msg read too short (%d/%d)", r, buf_size);
goto err;
}
......@@ -247,14 +261,19 @@ static unsigned char *__read_msg(struct fp_dev *dev, size_t *data_len)
* to read the remainder. This is handled below. */
if (len > MAX_DATA_IN_READ_BUF) {
int needed = len - MAX_DATA_IN_READ_BUF;
struct libusb_bulk_transfer extend_msg = {
.endpoint = EP_IN,
.length = needed,
};
fp_dbg("didn't fit in buffer, need to extend by %d bytes", needed);
buf = g_realloc((gpointer) buf, MSG_READ_BUF_SIZE + needed);
r = usb_bulk_read(dev->udev, EP_IN, buf + MSG_READ_BUF_SIZE, needed,
TIMEOUT);
extend_msg.data = buf + MSG_READ_BUF_SIZE;
r = libusb_bulk_transfer(dev->udev, &extend_msg, &transferred, TIMEOUT);
if (r < 0) {
fp_err("extended msg read failed, code %d", r);
goto err;
} else if (r < needed) {
} else if (transferred < needed) {
fp_err("extended msg short read (%d/%d)", r, needed);
goto err;
}
......@@ -427,8 +446,16 @@ static int do_init(struct fp_dev *dev)
uint8_t seq;
int r;
r = usb_control_msg(dev->udev, USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0x0c, 0x100, 0x400, &dummy, sizeof(dummy), TIMEOUT);
struct libusb_control_transfer msg = {
.requesttype = LIBUSB_TYPE_VENDOR | LIBUSB_RECIP_DEVICE,
.request = 0x0c,
.value = 0x0100,
.index = 0x0400,
.length = sizeof(dummy),
.data = &dummy,
};
r = libusb_control_transfer(dev->udev, &msg, TIMEOUT);
if (r < 0) {
fp_dbg("control write failed\n");
return r;
......@@ -528,7 +555,7 @@ static int dev_init(struct fp_dev *dev, unsigned long driver_data)
struct upekts_dev *upekdev = NULL;
int r;
r = usb_claim_interface(dev->udev, 0);
r = libusb_claim_interface(dev->udev, 0);
if (r < 0)
return r;
......@@ -542,7 +569,7 @@ static int dev_init(struct fp_dev *dev, unsigned long driver_data)
static void dev_exit(struct fp_dev *dev)
{
usb_release_interface(dev->udev, 0);
libusb_release_interface(dev->udev, 0);
g_free(dev->priv);
}
......
......@@ -24,15 +24,15 @@
#include <unistd.h>
#include <openssl/aes.h>
#include <usb.h>
#include <libusb.h>
#include <fp_internal.h>
#define EP_INTR (1 | USB_ENDPOINT_IN)
#define EP_DATA (2 | USB_ENDPOINT_IN)
#define EP_INTR (1 | LIBUSB_ENDPOINT_IN)
#define EP_DATA (2 | LIBUSB_ENDPOINT_IN)
#define USB_RQ 0x04
#define CTRL_IN (USB_TYPE_VENDOR | USB_ENDPOINT_IN)
#define CTRL_OUT (USB_TYPE_VENDOR | USB_ENDPOINT_OUT)
#define CTRL_IN (LIBUSB_TYPE_VENDOR | LIBUSB_ENDPOINT_IN)
#define CTRL_OUT (LIBUSB_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT)
#define CTRL_TIMEOUT 5000
#define BULK_TIMEOUT 5000
#define DATABLK1_RQLEN 0x10000
......@@ -156,8 +156,16 @@ static int get_hwstat(struct fp_img_dev *dev, unsigned char *data)
/* The windows driver uses a request of 0x0c here. We use 0x04 to be
* consistent with every other command we know about. */
r = usb_control_msg(dev->udev, CTRL_IN, USB_RQ, REG_HWSTAT, 0,
data, 1, CTRL_TIMEOUT);
struct libusb_control_transfer msg = {
.requesttype = CTRL_IN,
.request = USB_RQ,
.value = REG_HWSTAT,
.index = 0,
.length = 1,
.data = data,
};
r = libusb_control_transfer(dev->udev, &msg, CTRL_TIMEOUT);
if (r < 0) {
fp_err("error %d", r);
return r;
......@@ -173,10 +181,17 @@ static int get_hwstat(struct fp_img_dev *dev, unsigned char *data)