Commit 4e884807 authored by Daniel Drake's avatar Daniel Drake

Update for libusb API rework

parent 81a5d6d9
......@@ -46,22 +46,19 @@ static void continue_write_regv(struct write_regv_data *wdata);
/* libusb bulk callback for regv write completion transfer. continues the
* transaction */
static void write_regv_trf_complete(libusb_dev_handle *devh,
libusb_urb_handle *urbh, enum libusb_urb_cb_status status,
unsigned char endpoint, int rqlength, unsigned char *data,
int actual_length, void *user_data)
static void write_regv_trf_complete(struct libusb_transfer *transfer)
{
struct write_regv_data *wdata = user_data;
struct write_regv_data *wdata = transfer->user_data;
g_free(data);
libusb_urb_handle_free(urbh);
if (status != FP_URB_COMPLETED)
if (transfer->status != LIBUSB_TRANSFER_COMPLETED)
wdata->callback(wdata->imgdev, -EIO, wdata->user_data);
else if (rqlength != actual_length)
else if (transfer->length != transfer->actual_length)
wdata->callback(wdata->imgdev, -EPROTO, wdata->user_data);
else
continue_write_regv(wdata);
g_free(transfer->buffer);
libusb_free_transfer(transfer);
}
/* write from wdata->offset to upper_bound (inclusive) of wdata->regs */
......@@ -73,12 +70,13 @@ static int do_write_regv(struct write_regv_data *wdata, int upper_bound)
unsigned char *data = g_malloc(alloc_size);
unsigned int i;
size_t data_offset = 0;
struct libusb_urb_handle *urbh;
struct libusb_bulk_transfer msg = {
.endpoint = EP_OUT,
.data = data,
.length = alloc_size,
};
struct libusb_transfer *transfer = libusb_alloc_transfer();
int r;
if (!transfer) {
g_free(data);
return -ENOMEM;
}
for (i = offset; i < offset + num; i++) {
const struct aes_regwrite *regwrite = &wdata->regs[i];
......@@ -86,14 +84,15 @@ static int do_write_regv(struct write_regv_data *wdata, int upper_bound)
data[data_offset++] = regwrite->value;
}
urbh = libusb_async_bulk_transfer(wdata->imgdev->udev, &msg,
write_regv_trf_complete, wdata, BULK_TIMEOUT);
if (!urbh) {
libusb_fill_bulk_transfer(transfer, wdata->imgdev->udev, EP_OUT, data,
alloc_size, write_regv_trf_complete, wdata, BULK_TIMEOUT);
r = libusb_submit_transfer(transfer);
if (r < 0) {
g_free(data);
return -EIO;
libusb_free_transfer(transfer);
}
return 0;
return r;
}
/* write the next batch of registers to be written, or if there are no more,
......
......@@ -41,7 +41,7 @@ API_EXPORTED int fp_async_dev_open(struct fp_dscv_dev *ddev, fp_dev_open_cb cb,
{
struct fp_driver *drv = ddev->drv;
struct fp_dev *dev;
libusb_dev_handle *udevh;
libusb_device_handle *udevh;
int r;
fp_dbg("");
......
......@@ -352,11 +352,11 @@ static void register_drivers(void)
}
}
static struct fp_driver *find_supporting_driver(libusb_dev *udev,
static struct fp_driver *find_supporting_driver(libusb_device *udev,
const struct usb_id **usb_id)
{
GSList *elem = registered_drivers;
struct libusb_dev_descriptor *dsc = libusb_dev_get_descriptor(udev);
struct libusb_device_descriptor *dsc = libusb_get_device_descriptor(udev);
do {
struct fp_driver *drv = elem->data;
......@@ -373,7 +373,7 @@ static struct fp_driver *find_supporting_driver(libusb_dev *udev,
return NULL;
}
static struct fp_dscv_dev *discover_dev(libusb_dev *udev)
static struct fp_dscv_dev *discover_dev(libusb_device *udev)
{
const struct usb_id *usb_id;
struct fp_driver *drv = find_supporting_driver(udev, &usb_id);
......@@ -409,33 +409,40 @@ API_EXPORTED struct fp_dscv_dev **fp_discover_devs(void)
{
GSList *tmplist = NULL;
struct fp_dscv_dev **list;
struct libusb_dev *udev;
libusb_device *udev;
libusb_device **devs;
int dscv_count = 0;
int r;
int i = 0;
if (registered_drivers == NULL)
return NULL;
libusb_find_devices();
r = libusb_get_device_list(&devs);
if (r < 0) {
fp_err("couldn't enumerate USB devices, error %d", r);
return NULL;
}
/* 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 (udev = libusb_get_devices(); udev; udev = libusb_dev_next(udev)) {
struct fp_dscv_dev *ddev = discover_dev(udev);
if (!ddev)
continue;
tmplist = g_slist_prepend(tmplist, (gpointer) ddev);
dscv_count++;
}
while ((udev = devs[i++]) != NULL) {
struct fp_dscv_dev *ddev = discover_dev(udev);
if (!ddev)
continue;
tmplist = g_slist_prepend(tmplist, (gpointer) ddev);
dscv_count++;
}
/* Convert our temporary GSList into a standard NULL-terminated pointer
* array. */
list = g_malloc(sizeof(*list) * (dscv_count + 1));
if (dscv_count > 0) {
GSList *elem = tmplist;
int i = 0;
i = 0;
do {
list[i++] = elem->data;
} while ((elem = g_slist_next(elem)));
......
......@@ -79,48 +79,53 @@ struct aes2501_read_regs {
void *user_data;
};
static void read_regs_data_cb(libusb_dev_handle *devh, libusb_urb_handle *urbh,
enum libusb_urb_cb_status status, unsigned char endpoint, int rqlength,
unsigned char *data, int actual_length, void *user_data)
static void read_regs_data_cb(struct libusb_transfer *transfer)
{
struct aes2501_read_regs *rdata = user_data;
struct aes2501_read_regs *rdata = transfer->user_data;
unsigned char *retdata = NULL;
int r;
if (status != FP_URB_COMPLETED) {
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
r = -EIO;
} else if (rqlength != actual_length) {
} else if (transfer->length != transfer->actual_length) {
r = -EPROTO;
} else {
r = 0;
retdata = data;
retdata = transfer->buffer;
}
rdata->callback(rdata->dev, r, retdata, rdata->user_data);
libusb_urb_handle_free(urbh);
g_free(data);
g_free(rdata);
g_free(transfer->buffer);
libusb_free_transfer(transfer);
}
static void read_regs_rq_cb(struct fp_img_dev *dev, int result, void *user_data)
{
struct aes2501_read_regs *rdata = user_data;
struct libusb_urb_handle *urbh;
struct libusb_bulk_transfer trf = {
.endpoint = EP_IN,
.length = 126,
};
struct libusb_transfer *transfer;
unsigned char *data;
int r;
g_free(rdata->regwrite);
if (result != 0)
goto err;
trf.data = g_malloc(trf.length);
urbh = libusb_async_bulk_transfer(dev->udev, &trf, read_regs_data_cb,
rdata, BULK_TIMEOUT);
if (!urbh) {
g_free(trf.data);
result = EIO;
transfer = libusb_alloc_transfer();
if (!transfer) {
result = -ENOMEM;
goto err;
}
data = g_malloc(126);
libusb_fill_bulk_transfer(transfer, dev->udev, EP_IN, data, 126,
read_regs_data_cb, rdata, BULK_TIMEOUT);
r = libusb_submit_transfer(transfer);
if (r < 0) {
g_free(data);
libusb_free_transfer(transfer);
result = -EIO;
goto err;
}
......@@ -179,40 +184,43 @@ static void generic_write_regv_cb(struct fp_img_dev *dev, int result,
}
/* check that read succeeded but ignore all data */
static void generic_ignore_data_cb(libusb_dev_handle *devh,
libusb_urb_handle *urbh, enum libusb_urb_cb_status status,
unsigned char endpoint, int rqlength, unsigned char *data,
int actual_length, void *user_data)
static void generic_ignore_data_cb(struct libusb_transfer *transfer)
{
struct fpi_ssm *ssm = user_data;
libusb_urb_handle_free(urbh);
g_free(data);
struct fpi_ssm *ssm = transfer->user_data;
if (status != FP_URB_COMPLETED)
if (transfer->status != LIBUSB_TRANSFER_COMPLETED)
fpi_ssm_mark_aborted(ssm, -EIO);
else if (rqlength != actual_length)
else if (transfer->length != transfer->actual_length)
fpi_ssm_mark_aborted(ssm, -EPROTO);
else
fpi_ssm_next_state(ssm);
g_free(transfer->buffer);
libusb_free_transfer(transfer);
}
/* read the specified number of bytes from the IN endpoint but throw them
* away, then increment the SSM */
static void generic_read_ignore_data(struct fpi_ssm *ssm, size_t bytes)
{
struct libusb_urb_handle *urbh;
struct libusb_bulk_transfer trf = {
.endpoint = EP_IN,
.data = g_malloc(bytes),
.length = bytes,
};
struct libusb_transfer *transfer = libusb_alloc_transfer();
unsigned char *data;
int r;
if (!transfer) {
fpi_ssm_mark_aborted(ssm, -ENOMEM);
return;
}
urbh = libusb_async_bulk_transfer(ssm->dev->udev, &trf,
data = g_malloc(bytes);
libusb_fill_bulk_transfer(transfer, ssm->dev->udev, EP_IN, data, bytes,
generic_ignore_data_cb, ssm, BULK_TIMEOUT);
if (!urbh) {
g_free(trf.data);
fpi_ssm_mark_aborted(ssm, -EIO);
r = libusb_submit_transfer(transfer);
if (r < 0) {
g_free(data);
libusb_free_transfer(transfer);
fpi_ssm_mark_aborted(ssm, r);
}
}
......@@ -382,19 +390,17 @@ static const struct aes_regwrite finger_det_reqs[] = {
static void start_finger_detection(struct fp_img_dev *dev);
static void finger_det_data_cb(libusb_dev_handle *devh, libusb_urb_handle *urbh,
enum libusb_urb_cb_status status, unsigned char endpoint,
int rqlength, unsigned char *data, int actual_length, void *user_data)
static void finger_det_data_cb(struct libusb_transfer *transfer)
{
struct fp_img_dev *dev = user_data;
struct fp_img_dev *dev = transfer->user_data;
unsigned char *data = transfer->buffer;
int i;
int sum = 0;
libusb_urb_handle_free(urbh);
if (status != FP_URB_COMPLETED) {
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
fpi_imgdev_session_error(dev, -EIO);
goto out;
} else if (rqlength != actual_length) {
} else if (transfer->length != transfer->actual_length) {
fpi_imgdev_session_error(dev, -EPROTO);
goto out;
}
......@@ -413,28 +419,36 @@ static void finger_det_data_cb(libusb_dev_handle *devh, libusb_urb_handle *urbh,
out:
g_free(data);
libusb_free_transfer(transfer);
}
static void finger_det_reqs_cb(struct fp_img_dev *dev, int result,
void *user_data)
{
struct libusb_urb_handle *urbh;
struct libusb_bulk_transfer trf = {
.endpoint = EP_IN,
.length = 20,
};
struct libusb_transfer *transfer;
unsigned char *data;
int r;
if (result) {
fpi_imgdev_session_error(dev, result);
return;
}
trf.data = g_malloc(trf.length);
urbh = libusb_async_bulk_transfer(dev->udev, &trf, finger_det_data_cb,
dev, BULK_TIMEOUT);
if (!urbh) {
g_free(trf.data);
fpi_imgdev_session_error(dev, -EIO);
transfer = libusb_alloc_transfer();
if (!transfer) {
fpi_imgdev_session_error(dev, -ENOMEM);
return;
}
data = g_malloc(20);
libusb_fill_bulk_transfer(transfer, dev->udev, EP_IN, data, 20,
finger_det_data_cb, dev, BULK_TIMEOUT);
r = libusb_submit_transfer(transfer);
if (r < 0) {
g_free(data);
libusb_free_transfer(transfer);
fpi_imgdev_session_error(dev, r);
}
}
......@@ -527,23 +541,20 @@ enum capture_states {
CAPTURE_NUM_STATES,
};
static void capture_read_strip_cb(libusb_dev_handle *devh,
libusb_urb_handle *urbh, enum libusb_urb_cb_status status,
unsigned char endpoint, int rqlength, unsigned char *data,
int actual_length, void *user_data)
static void capture_read_strip_cb(struct libusb_transfer *transfer)
{
unsigned char *stripdata;
struct fpi_ssm *ssm = user_data;
struct fpi_ssm *ssm = transfer->user_data;
struct fp_img_dev *dev = ssm->priv;
struct aes2501_dev *aesdev = dev->priv;
unsigned char *data = transfer->buffer;
int sum;
int threshold;
libusb_urb_handle_free(urbh);
if (status != FP_URB_COMPLETED) {
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
fpi_ssm_mark_aborted(ssm, -EIO);
goto out;
} else if (rqlength != actual_length) {
} else if (transfer->length != transfer->actual_length) {
fpi_ssm_mark_aborted(ssm, -EPROTO);
goto out;
}
......@@ -587,12 +598,14 @@ static void capture_read_strip_cb(libusb_dev_handle *devh,
out:
g_free(data);
libusb_free_transfer(transfer);
}
static void capture_run_state(struct fpi_ssm *ssm)
{
struct fp_img_dev *dev = ssm->priv;
struct aes2501_dev *aesdev = dev->priv;
int r;
switch (ssm->cur_state) {
case CAPTURE_WRITE_REQS_1:
......@@ -617,17 +630,23 @@ static void capture_run_state(struct fpi_ssm *ssm)
generic_write_regv_cb, ssm);
break;
case CAPTURE_READ_STRIP: ;
struct libusb_urb_handle *urbh;
struct libusb_bulk_transfer trf = {
.endpoint = EP_IN,
.data = g_malloc(1705),
.length = 1705,
};
urbh = libusb_async_bulk_transfer(dev->udev, &trf,
struct libusb_transfer *transfer = libusb_alloc_transfer();
unsigned char *data;
if (!transfer) {
fpi_ssm_mark_aborted(ssm, -ENOMEM);
break;
}
data = g_malloc(1705);
libusb_fill_bulk_transfer(transfer, dev->udev, EP_IN, data, 1705,
capture_read_strip_cb, ssm, BULK_TIMEOUT);
if (!urbh) {
g_free(trf.data);
fpi_ssm_mark_aborted(ssm, -EIO);
r = libusb_submit_transfer(transfer);
if (r < 0) {
g_free(data);
libusb_free_transfer(transfer);
fpi_ssm_mark_aborted(ssm, r);
}
break;
};
......
......@@ -35,7 +35,7 @@
#define SUBARRAY_LEN 768
struct aes4k_dev {
libusb_urb_handle *img_trf;
struct libusb_transfer *img_trf;
};
static const struct aes_regwrite init_reqs[] = {
......@@ -115,22 +115,20 @@ static const struct aes_regwrite init_reqs[] = {
static void do_capture(struct fp_img_dev *dev);
static void img_cb(libusb_dev_handle *devh, libusb_urb_handle *urbh,
enum libusb_urb_cb_status status, unsigned char endpoint,
int rqlength, unsigned char *data, int actual_length, void *user_data)
static void img_cb(struct libusb_transfer *transfer)
{
struct fp_img_dev *dev = user_data;
struct fp_img_dev *dev = transfer->user_data;
struct aes4k_dev *aesdev = dev->priv;
unsigned char *ptr = data;
unsigned char *ptr = transfer->buffer;
struct fp_img *img;
int i;
if (status == FP_URB_CANCELLED) {
if (transfer->status == LIBUSB_TRANSFER_CANCELLED) {
goto err;
} else if (status != FP_URB_COMPLETED) {
} else if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
fpi_imgdev_session_error(dev, -EIO);
goto err;
} else if (rqlength != actual_length) {
} else if (transfer->length != transfer->actual_length) {
fpi_imgdev_session_error(dev, -EPROTO);
goto err;
}
......@@ -155,25 +153,33 @@ static void img_cb(libusb_dev_handle *devh, libusb_urb_handle *urbh,
do_capture(dev);
err:
g_free(data);
g_free(transfer->buffer);
aesdev->img_trf = NULL;
libusb_urb_handle_free(urbh);
libusb_free_transfer(transfer);
}
static void do_capture(struct fp_img_dev *dev)
{
struct aes4k_dev *aesdev = dev->priv;
struct libusb_bulk_transfer trf = {
.endpoint = EP_IN,
.length = DATA_BUFLEN,
.data = g_malloc(DATA_BUFLEN),
};
aesdev->img_trf = libusb_async_bulk_transfer(dev->udev, &trf, img_cb, dev,
0);
unsigned char *data;
int r;
aesdev->img_trf = libusb_alloc_transfer();
if (!aesdev->img_trf) {
g_free(trf.data);
fpi_imgdev_session_error(dev, -EIO);
return;
}
data = g_malloc(DATA_BUFLEN);
libusb_fill_bulk_transfer(aesdev->img_trf, dev->udev, EP_IN, data,
DATA_BUFLEN, img_cb, dev, 0);
r = libusb_submit_transfer(aesdev->img_trf);
if (r < 0) {
g_free(data);
libusb_free_transfer(aesdev->img_trf);
aesdev->img_trf = NULL;
fpi_imgdev_session_error(dev, r);
}
}
......@@ -198,7 +204,7 @@ static void dev_deactivate(struct fp_img_dev *dev)
* from deactivation, otherwise app may legally exit before we've
* cleaned up */
if (aesdev->img_trf)
libusb_urb_handle_cancel(dev->udev, aesdev->img_trf);
libusb_cancel_transfer(aesdev->img_trf);
fpi_imgdev_deactivate_complete(dev);
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -93,7 +93,7 @@ enum fp_dev_state {
struct fp_dev {
struct fp_driver *drv;
libusb_dev_handle *udev;
libusb_device_handle *udev;
uint32_t devtype;
void *priv;
......@@ -161,7 +161,7 @@ enum fp_imgdev_verify_state {
struct fp_img_dev {
struct fp_dev *dev;
libusb_dev_handle *udev;
libusb_device_handle *udev;
enum fp_imgdev_action action;
int action_state;
......@@ -249,7 +249,7 @@ void fpi_img_driver_setup(struct fp_img_driver *idriver);
container_of((drv), struct fp_img_driver, driver)
struct fp_dscv_dev {
libusb_dev *udev;
struct libusb_device *udev;
struct fp_driver *drv;
unsigned long driver_data;
uint32_t devtype;
......
......@@ -180,7 +180,7 @@ API_EXPORTED int fp_enroll_finger_img(struct fp_dev *dev,
int stage = dev->__enroll_stage;
gboolean final = FALSE;
gboolean stopped = FALSE;
struct sync_enroll_data *edata;
struct sync_enroll_data *edata = NULL;
int r;
fp_dbg("");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment