vfs5011: Port driver and add it back into build

There is still a warning where a USB transfer should be cancelled but it
not at this point.
This commit is contained in:
Benjamin Berg 2019-07-04 17:40:06 +02:00
parent f119c273fd
commit 0169fe8cf6
3 changed files with 283 additions and 332 deletions

View file

@ -18,6 +18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#define FP_COMPONENT "vfs5011"
#include "drivers_api.h" #include "drivers_api.h"
#include "vfs5011_proto.h" #include "vfs5011_proto.h"
@ -65,166 +67,119 @@ struct usb_action {
struct usbexchange_data { struct usbexchange_data {
int stepcount; int stepcount;
struct fp_img_dev *device; FpImageDevice *device;
struct usb_action *actions; struct usb_action *actions;
void *receive_buf; void *receive_buf;
int timeout; int timeout;
}; };
static void start_scan(struct fp_img_dev *dev); static void start_scan(FpImageDevice *dev);
static void async_send_cb(struct libusb_transfer *transfer) static void async_send_cb(FpiUsbTransfer *transfer, FpDevice *device,
gpointer user_data, GError *error)
{ {
fpi_ssm *ssm = transfer->user_data; struct usbexchange_data *data = fpi_ssm_get_user_data(transfer->ssm);
struct usbexchange_data *data = fpi_ssm_get_user_data(ssm);
struct usb_action *action; struct usb_action *action;
if (fpi_ssm_get_cur_state(ssm) >= data->stepcount) { g_assert(!(fpi_ssm_get_cur_state(transfer->ssm) >= data->stepcount));
fp_err("Radiation detected!");
fpi_imgdev_session_error(data->device, -EINVAL);
fpi_ssm_mark_failed(ssm, -EINVAL);
goto out;
}
action = &data->actions[fpi_ssm_get_cur_state(ssm)]; action = &data->actions[fpi_ssm_get_cur_state(transfer->ssm)];
if (action->type != ACTION_SEND) { g_assert(!(action->type != ACTION_SEND));
fp_err("Radiation detected!");
fpi_imgdev_session_error(data->device, -EINVAL);
fpi_ssm_mark_failed(ssm, -EINVAL);
goto out;
}
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { if (error) {
/* Transfer not completed, return IO error */ /* Transfer not completed, return IO error */
fp_err("transfer not completed, status = %d", transfer->status); fpi_ssm_mark_failed(transfer->ssm, error);
fpi_imgdev_session_error(data->device, -EIO); return;
fpi_ssm_mark_failed(ssm, -EIO);
goto out;
}
if (transfer->length != transfer->actual_length) {
/* Data sended mismatch with expected, return protocol error */
fp_err("length mismatch, got %d, expected %d",
transfer->actual_length, transfer->length);
fpi_imgdev_session_error(data->device, -EIO);
fpi_ssm_mark_failed(ssm, -EIO);
goto out;
} }
/* success */ /* success */
fpi_ssm_next_state(ssm); fpi_ssm_next_state(transfer->ssm);
out:
libusb_free_transfer(transfer);
} }
static void async_recv_cb(struct libusb_transfer *transfer) static void async_recv_cb(FpiUsbTransfer *transfer, FpDevice *device,
gpointer user_data, GError *error)
{ {
fpi_ssm *ssm = transfer->user_data; struct usbexchange_data *data = fpi_ssm_get_user_data(transfer->ssm);
struct usbexchange_data *data = fpi_ssm_get_user_data(ssm);
struct usb_action *action; struct usb_action *action;
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { if (error) {
/* Transfer not completed, return IO error */ /* Transfer not completed, return IO error */
fp_err("transfer not completed, status = %d", transfer->status); fpi_ssm_mark_failed(transfer->ssm, error);
fpi_imgdev_session_error(data->device, -EIO); return;
fpi_ssm_mark_failed(ssm, -EIO);
goto out;
} }
if (fpi_ssm_get_cur_state(ssm) >= data->stepcount) { g_assert(!(fpi_ssm_get_cur_state(transfer->ssm) >= data->stepcount));
fp_err("Radiation detected!");
fpi_imgdev_session_error(data->device, -EINVAL);
fpi_ssm_mark_failed(ssm, -EINVAL);
goto out;
}
action = &data->actions[fpi_ssm_get_cur_state(ssm)]; action = &data->actions[fpi_ssm_get_cur_state(transfer->ssm)];
if (action->type != ACTION_RECEIVE) { g_assert(!(action->type != ACTION_RECEIVE));
fp_err("Radiation detected!");
fpi_imgdev_session_error(data->device, -EINVAL);
fpi_ssm_mark_failed(ssm, -EINVAL);
goto out;
}
if (action->data != NULL) { if (action->data != NULL) {
if (transfer->actual_length != action->correct_reply_size) { if (transfer->actual_length != action->correct_reply_size) {
fp_err("Got %d bytes instead of %d", fp_err("Got %d bytes instead of %d",
transfer->actual_length, (gint)transfer->actual_length,
action->correct_reply_size); action->correct_reply_size);
fpi_imgdev_session_error(data->device, -EIO); fpi_ssm_mark_failed(transfer->ssm, fpi_device_error_new (FP_DEVICE_ERROR_GENERAL));
fpi_ssm_mark_failed(ssm, -EIO); return;
goto out;
} }
if (memcmp(transfer->buffer, action->data, if (memcmp(transfer->buffer, action->data,
action->correct_reply_size) != 0) { action->correct_reply_size) != 0) {
fp_dbg("Wrong reply:"); fp_dbg("Wrong reply:");
fpi_imgdev_session_error(data->device, -EIO); fpi_ssm_mark_failed(transfer->ssm, fpi_device_error_new (FP_DEVICE_ERROR_GENERAL));
fpi_ssm_mark_failed(ssm, -EIO); return;
goto out;
} }
} else } else
fp_dbg("Got %d bytes out of %d", transfer->actual_length, fp_dbg("Got %d bytes out of %d",
transfer->length); (gint)transfer->actual_length,
(gint)transfer->length);
fpi_ssm_next_state(ssm); fpi_ssm_next_state(transfer->ssm);
out:
libusb_free_transfer(transfer);
} }
static void usbexchange_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) static void usbexchange_loop(FpiSsm *ssm, FpDevice *_dev, void *user_data)
{ {
struct usbexchange_data *data = user_data; struct usbexchange_data *data = user_data;
if (fpi_ssm_get_cur_state(ssm) >= data->stepcount) {
fp_err("Bug detected: state %d out of range, only %d steps",
fpi_ssm_get_cur_state(ssm), data->stepcount);
fpi_imgdev_session_error(data->device, -EINVAL);
fpi_ssm_mark_failed(ssm, -EINVAL);
return;
}
struct usb_action *action = &data->actions[fpi_ssm_get_cur_state(ssm)]; struct usb_action *action = &data->actions[fpi_ssm_get_cur_state(ssm)];
struct libusb_transfer *transfer; FpiUsbTransfer *transfer;
int ret = -EINVAL;
g_assert (fpi_ssm_get_cur_state(ssm) < data->stepcount);
switch (action->type) { switch (action->type) {
case ACTION_SEND: case ACTION_SEND:
fp_dbg("Sending %s", action->name); fp_dbg("Sending %s", action->name);
transfer = fpi_usb_alloc(); transfer = fpi_usb_transfer_new(_dev);
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(data->device)), fpi_usb_transfer_fill_bulk_full(transfer, action->endpoint,
action->endpoint, action->data, action->data, action->size,
action->size, async_send_cb, ssm, NULL);
data->timeout); transfer->ssm = ssm;
ret = libusb_submit_transfer(transfer); transfer->short_is_error = TRUE;
fpi_usb_transfer_submit(transfer, data->timeout, NULL,
async_send_cb, NULL);
fpi_usb_transfer_unref(transfer);
break; break;
case ACTION_RECEIVE: case ACTION_RECEIVE:
fp_dbg("Receiving %d bytes", action->size); fp_dbg("Receiving %d bytes", action->size);
transfer = fpi_usb_alloc(); transfer = fpi_usb_transfer_new(_dev);
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(data->device)), fpi_usb_transfer_fill_bulk_full(transfer, action->endpoint,
action->endpoint, data->receive_buf, data->receive_buf,
action->size, async_recv_cb, ssm, action->size, NULL);
data->timeout); transfer->ssm = ssm;
ret = libusb_submit_transfer(transfer); fpi_usb_transfer_submit(transfer, data->timeout, NULL,
async_recv_cb, NULL);
fpi_usb_transfer_unref(transfer);
break; break;
default: default:
fp_err("Bug detected: invalid action %d", action->type); fp_err("Bug detected: invalid action %d", action->type);
fpi_imgdev_session_error(data->device, -EINVAL); fpi_ssm_mark_failed(ssm, fpi_device_error_new (FP_DEVICE_ERROR_GENERAL));
fpi_ssm_mark_failed(ssm, -EINVAL);
return; return;
} }
if (ret != 0) {
fp_err("USB transfer error: %s", strerror(ret));
fpi_imgdev_session_error(data->device, ret);
fpi_ssm_mark_failed(ssm, ret);
}
} }
static void usb_exchange_async(fpi_ssm *ssm, static void usb_exchange_async(FpiSsm *ssm,
struct usbexchange_data *data) struct usbexchange_data *data)
{ {
fpi_ssm *subsm = fpi_ssm_new(FP_DEV(data->device), FpiSsm *subsm = fpi_ssm_new(FP_DEVICE(data->device),
usbexchange_loop, usbexchange_loop,
data->stepcount, data->stepcount,
data); data);
@ -283,7 +238,9 @@ static struct fpi_line_asmbl_ctx assembling_ctx = {
.get_pixel = vfs5011_get_pixel, .get_pixel = vfs5011_get_pixel,
}; };
struct vfs5011_data { struct _FpDeviceVfs5011 {
FpImageDevice parent;
unsigned char *total_buffer; unsigned char *total_buffer;
unsigned char *capture_buffer; unsigned char *capture_buffer;
unsigned char *row_buffer; unsigned char *row_buffer;
@ -295,9 +252,12 @@ struct vfs5011_data {
gboolean loop_running; gboolean loop_running;
gboolean deactivating; gboolean deactivating;
struct usbexchange_data init_sequence; struct usbexchange_data init_sequence;
struct libusb_transfer *flying_transfer;
}; };
G_DECLARE_FINAL_TYPE(FpDeviceVfs5011, fpi_device_vfs5011, FPI, DEVICE_VFS5011,
FpImageDevice);
G_DEFINE_TYPE(FpDeviceVfs5011, fpi_device_vfs5011, FP_TYPE_IMAGE_DEVICE);
enum { enum {
DEV_ACTIVATE_REQUEST_FPRINT, DEV_ACTIVATE_REQUEST_FPRINT,
DEV_ACTIVATE_INIT_COMPLETE, DEV_ACTIVATE_INIT_COMPLETE,
@ -312,22 +272,22 @@ enum {
DEV_OPEN_NUM_STATES DEV_OPEN_NUM_STATES
}; };
static void capture_init(struct vfs5011_data *data, int max_captured, static void capture_init(FpDeviceVfs5011 *self, int max_captured,
int max_recorded) int max_recorded)
{ {
fp_dbg("capture_init"); fp_dbg("capture_init");
data->lastline = NULL; self->lastline = NULL;
data->lines_captured = 0; self->lines_captured = 0;
data->lines_recorded = 0; self->lines_recorded = 0;
data->empty_lines = 0; self->empty_lines = 0;
data->lines_total = 0; self->lines_total = 0;
data->lines_total_allocated = 0; self->lines_total_allocated = 0;
data->total_buffer = NULL; self->total_buffer = NULL;
data->max_lines_captured = max_captured; self->max_lines_captured = max_captured;
data->max_lines_recorded = max_recorded; self->max_lines_recorded = max_recorded;
} }
static int process_chunk(struct vfs5011_data *data, int transferred) static int process_chunk(FpDeviceVfs5011 *self, int transferred)
{ {
enum { enum {
DEVIATION_THRESHOLD = 15*15, DEVIATION_THRESHOLD = 15*15,
@ -340,42 +300,42 @@ static int process_chunk(struct vfs5011_data *data, int transferred)
int i; int i;
for (i = 0; i < lines_captured; i++) { for (i = 0; i < lines_captured; i++) {
unsigned char *linebuf = data->capture_buffer unsigned char *linebuf = self->capture_buffer
+ i * VFS5011_LINE_SIZE; + i * VFS5011_LINE_SIZE;
if (fpi_std_sq_dev(linebuf + 8, VFS5011_IMAGE_WIDTH) if (fpi_std_sq_dev(linebuf + 8, VFS5011_IMAGE_WIDTH)
< DEVIATION_THRESHOLD) { < DEVIATION_THRESHOLD) {
if (data->lines_captured == 0) if (self->lines_captured == 0)
continue; continue;
else else
data->empty_lines++; self->empty_lines++;
} else } else
data->empty_lines = 0; self->empty_lines = 0;
if (data->empty_lines >= STOP_CHECK_LINES) { if (self->empty_lines >= STOP_CHECK_LINES) {
fp_dbg("process_chunk: got %d empty lines, finishing", fp_dbg("process_chunk: got %d empty lines, finishing",
data->empty_lines); self->empty_lines);
return 1; return 1;
} }
data->lines_captured++; self->lines_captured++;
if (data->lines_captured > data->max_lines_captured) { if (self->lines_captured > self->max_lines_captured) {
fp_dbg("process_chunk: captured %d lines, finishing", fp_dbg("process_chunk: captured %d lines, finishing",
data->lines_captured); self->lines_captured);
return 1; return 1;
} }
if ((data->lastline == NULL) if ((self->lastline == NULL)
|| (fpi_mean_sq_diff_norm( || (fpi_mean_sq_diff_norm(self->lastline + 8,
data->lastline + 8, linebuf + 8,
linebuf + 8, VFS5011_IMAGE_WIDTH) >= DIFFERENCE_THRESHOLD)) {
VFS5011_IMAGE_WIDTH) >= DIFFERENCE_THRESHOLD)) { self->lastline = g_malloc(VFS5011_LINE_SIZE);
data->lastline = g_malloc(VFS5011_LINE_SIZE); self->rows = g_slist_prepend(self->rows,
data->rows = g_slist_prepend(data->rows, data->lastline); self->lastline);
memmove(data->lastline, linebuf, VFS5011_LINE_SIZE); memmove(self->lastline, linebuf, VFS5011_LINE_SIZE);
data->lines_recorded++; self->lines_recorded++;
if (data->lines_recorded >= data->max_lines_recorded) { if (self->lines_recorded >= self->max_lines_recorded) {
fp_dbg("process_chunk: recorded %d lines, finishing", fp_dbg("process_chunk: recorded %d lines, finishing",
data->lines_recorded); self->lines_recorded);
return 1; return 1;
} }
} }
@ -384,80 +344,88 @@ static int process_chunk(struct vfs5011_data *data, int transferred)
} }
static void static void
submit_image(fpi_ssm *ssm, submit_image(FpiSsm *ssm,
struct vfs5011_data *data, FpDeviceVfs5011 *self,
struct fp_img_dev *dev) FpImageDevice *dev)
{ {
struct fp_img *img; FpImage *img;
if (data->lines_recorded == 0) { if (self->lines_recorded == 0) {
/* == FP_ENROLL_RETRY_TOO_SHORT */ /* == FP_ENROLL_RETRY_TOO_SHORT */
fpi_imgdev_session_error(dev, FP_VERIFY_RETRY_TOO_SHORT); fpi_image_device_retry_scan (dev, FP_DEVICE_RETRY_TOO_SHORT);
return; return;
} }
g_assert (data->rows != NULL); g_assert (self->rows != NULL);
data->rows = g_slist_reverse(data->rows); self->rows = g_slist_reverse(self->rows);
img = fpi_assemble_lines(&assembling_ctx, data->rows, data->lines_recorded); img = fpi_assemble_lines(&assembling_ctx, self->rows,
self->lines_recorded);
g_slist_free_full(data->rows, g_free); g_slist_free_full(self->rows, g_free);
data->rows = NULL; self->rows = NULL;
fp_dbg("Image captured, committing"); fp_dbg("Image captured, committing");
fpi_imgdev_image_captured(dev, img); fpi_image_device_image_captured(dev, img);
} }
static void chunk_capture_callback(struct libusb_transfer *transfer) static void chunk_capture_callback(FpiUsbTransfer *transfer, FpDevice *device,
gpointer user_data, GError *error)
{ {
fpi_ssm *ssm = (fpi_ssm *)transfer->user_data; FpImageDevice *dev = FP_IMAGE_DEVICE(device);
struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm); FpDeviceVfs5011 *self;
struct vfs5011_data *data;
data = FP_INSTANCE_DATA(FP_DEV(dev)); self = FPI_DEVICE_VFS5011(dev);
if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) || if (!error ||
(transfer->status == LIBUSB_TRANSFER_TIMED_OUT)) { g_error_matches(error, G_USB_DEVICE_ERROR, G_USB_DEVICE_ERROR_TIMED_OUT)) {
if (error)
g_error_free(error);
if (transfer->actual_length > 0) if (transfer->actual_length > 0)
fpi_imgdev_report_finger_status(dev, TRUE); fpi_image_device_report_finger_status(dev, TRUE);
if (process_chunk(data, transfer->actual_length)) if (process_chunk(self, transfer->actual_length))
fpi_ssm_jump_to_state(ssm, DEV_ACTIVATE_DATA_COMPLETE); fpi_ssm_jump_to_state(transfer->ssm,
DEV_ACTIVATE_DATA_COMPLETE);
else else
fpi_ssm_jump_to_state(ssm, DEV_ACTIVATE_READ_DATA); fpi_ssm_jump_to_state(transfer->ssm,
DEV_ACTIVATE_READ_DATA);
} else { } else {
if (!data->deactivating) { if (!self->deactivating) {
fp_err("Failed to capture data"); fp_err("Failed to capture data");
fpi_ssm_mark_failed(ssm, -1); fpi_ssm_mark_failed(transfer->ssm, error);
} else { } else {
fpi_ssm_mark_completed(ssm); g_error_free (error);
fpi_ssm_mark_completed(transfer->ssm);
} }
} }
libusb_free_transfer(transfer);
data->flying_transfer = NULL;
} }
static int capture_chunk_async(struct vfs5011_data *data, static void capture_chunk_async(FpDeviceVfs5011 *self,
libusb_device_handle *handle, int nline, GUsbDevice *handle, int nline,
int timeout, fpi_ssm *ssm) int timeout, FpiSsm *ssm)
{ {
FpiUsbTransfer *transfer;
fp_dbg("capture_chunk_async: capture %d lines, already have %d", fp_dbg("capture_chunk_async: capture %d lines, already have %d",
nline, data->lines_recorded); nline, self->lines_recorded);
enum { enum {
DEVIATION_THRESHOLD = 15*15, DEVIATION_THRESHOLD = 15*15,
DIFFERENCE_THRESHOLD = 600, DIFFERENCE_THRESHOLD = 600,
STOP_CHECK_LINES = 50 STOP_CHECK_LINES = 50
}; };
data->flying_transfer = fpi_usb_alloc(); transfer = fpi_usb_transfer_new(FP_DEVICE(self));
libusb_fill_bulk_transfer(data->flying_transfer, handle, VFS5011_IN_ENDPOINT_DATA, fpi_usb_transfer_fill_bulk_full(transfer,
data->capture_buffer, VFS5011_IN_ENDPOINT_DATA,
nline * VFS5011_LINE_SIZE, self->capture_buffer,
chunk_capture_callback, ssm, timeout); nline * VFS5011_LINE_SIZE, NULL);
return libusb_submit_transfer(data->flying_transfer); transfer->ssm = ssm;
fpi_usb_transfer_submit(transfer, timeout, fpi_device_get_cancellable (FP_DEVICE (self)),
chunk_capture_callback, NULL);
fpi_usb_transfer_unref(transfer);
} }
/* /*
@ -648,20 +616,18 @@ struct usb_action vfs5011_initiate_capture[] = {
/* ====================== lifprint interface ======================= */ /* ====================== lifprint interface ======================= */
static void activate_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) static void activate_loop(FpiSsm *ssm, FpDevice *_dev, void *user_data)
{ {
enum {READ_TIMEOUT = 0}; enum {READ_TIMEOUT = 0};
struct fp_img_dev *dev = user_data; FpImageDevice *dev = user_data;
struct vfs5011_data *data; FpDeviceVfs5011 *self;
int r;
fpi_timeout *timeout;
data = FP_INSTANCE_DATA(_dev); self = FPI_DEVICE_VFS5011(_dev);
fp_dbg("main_loop: state %d", fpi_ssm_get_cur_state(ssm)); fp_dbg("main_loop: state %d", fpi_ssm_get_cur_state(ssm));
if (data->deactivating) { if (self->deactivating) {
fp_dbg("deactivating, marking completed"); fp_dbg("deactivating, marking completed");
fpi_ssm_mark_completed(ssm); fpi_ssm_mark_completed(ssm);
return; return;
@ -669,239 +635,224 @@ static void activate_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
switch (fpi_ssm_get_cur_state(ssm)) { switch (fpi_ssm_get_cur_state(ssm)) {
case DEV_ACTIVATE_REQUEST_FPRINT: case DEV_ACTIVATE_REQUEST_FPRINT:
data->init_sequence.stepcount = self->init_sequence.stepcount =
G_N_ELEMENTS(vfs5011_initiate_capture); G_N_ELEMENTS(vfs5011_initiate_capture);
data->init_sequence.actions = vfs5011_initiate_capture; self->init_sequence.actions = vfs5011_initiate_capture;
data->init_sequence.device = dev; self->init_sequence.device = dev;
if (data->init_sequence.receive_buf == NULL) if (self->init_sequence.receive_buf == NULL)
data->init_sequence.receive_buf = self->init_sequence.receive_buf =
g_malloc0(VFS5011_RECEIVE_BUF_SIZE); g_malloc0(VFS5011_RECEIVE_BUF_SIZE);
data->init_sequence.timeout = 1000; self->init_sequence.timeout = 1000;
usb_exchange_async(ssm, &data->init_sequence); usb_exchange_async(ssm, &self->init_sequence);
break; break;
case DEV_ACTIVATE_INIT_COMPLETE: case DEV_ACTIVATE_INIT_COMPLETE:
if (data->init_sequence.receive_buf != NULL) if (self->init_sequence.receive_buf != NULL)
g_free(data->init_sequence.receive_buf); g_free(self->init_sequence.receive_buf);
data->init_sequence.receive_buf = NULL; self->init_sequence.receive_buf = NULL;
capture_init(data, MAX_CAPTURE_LINES, MAXLINES); capture_init(self, MAX_CAPTURE_LINES, MAXLINES);
fpi_imgdev_activate_complete(dev, 0); fpi_image_device_activate_complete(dev, NULL);
fpi_ssm_next_state(ssm); fpi_ssm_next_state(ssm);
break; break;
case DEV_ACTIVATE_READ_DATA: case DEV_ACTIVATE_READ_DATA:
r = capture_chunk_async(data, fpi_dev_get_usb_dev(FP_DEV(dev)), CAPTURE_LINES, capture_chunk_async(self,
READ_TIMEOUT, ssm); fpi_device_get_usb_device(FP_DEVICE(dev)),
if (r != 0) { CAPTURE_LINES,
fp_err("Failed to capture data"); READ_TIMEOUT, ssm);
fpi_imgdev_session_error(dev, r);
fpi_ssm_mark_failed(ssm, r);
}
break; break;
case DEV_ACTIVATE_DATA_COMPLETE: case DEV_ACTIVATE_DATA_COMPLETE:
timeout = fpi_timeout_add(1, fpi_ssm_next_state_timeout_cb, _dev, ssm); fpi_device_add_timeout(_dev, 1,
fpi_ssm_next_state_timeout_cb,
ssm);
if (timeout == NULL) {
/* Failed to add timeout */
fp_err("failed to add timeout");
fpi_imgdev_session_error(dev, -1);
fpi_ssm_mark_failed(ssm, -1);
}
break; break;
case DEV_ACTIVATE_PREPARE_NEXT_CAPTURE: case DEV_ACTIVATE_PREPARE_NEXT_CAPTURE:
data->init_sequence.stepcount = self->init_sequence.stepcount =
G_N_ELEMENTS(vfs5011_initiate_capture); G_N_ELEMENTS(vfs5011_initiate_capture);
data->init_sequence.actions = vfs5011_initiate_capture; self->init_sequence.actions = vfs5011_initiate_capture;
data->init_sequence.device = dev; self->init_sequence.device = dev;
if (data->init_sequence.receive_buf == NULL) if (self->init_sequence.receive_buf == NULL)
data->init_sequence.receive_buf = self->init_sequence.receive_buf =
g_malloc0(VFS5011_RECEIVE_BUF_SIZE); g_malloc0(VFS5011_RECEIVE_BUF_SIZE);
data->init_sequence.timeout = VFS5011_DEFAULT_WAIT_TIMEOUT; self->init_sequence.timeout = VFS5011_DEFAULT_WAIT_TIMEOUT;
usb_exchange_async(ssm, &data->init_sequence); usb_exchange_async(ssm, &self->init_sequence);
break; break;
} }
} }
static void activate_loop_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) static void activate_loop_complete(FpiSsm *ssm, FpDevice *_dev,
void *user_data, GError *error)
{ {
struct fp_img_dev *dev = user_data; FpImageDevice *dev = user_data;
struct vfs5011_data *data; FpDeviceVfs5011 *self;
int r = fpi_ssm_get_error(ssm);
data = FP_INSTANCE_DATA(_dev); self = FPI_DEVICE_VFS5011(_dev);
fp_dbg("finishing"); fp_dbg("finishing");
if (data->init_sequence.receive_buf != NULL) if (self->init_sequence.receive_buf != NULL)
g_free(data->init_sequence.receive_buf); g_free(self->init_sequence.receive_buf);
data->init_sequence.receive_buf = NULL; self->init_sequence.receive_buf = NULL;
if (!data->deactivating && !r) { if (!self->deactivating && !error) {
submit_image(ssm, data, dev); submit_image(ssm, self, dev);
fpi_imgdev_report_finger_status(dev, FALSE); fpi_image_device_report_finger_status(dev, FALSE);
} }
fpi_ssm_free(ssm); fpi_ssm_free(ssm);
data->loop_running = FALSE; self->loop_running = FALSE;
if (data->deactivating) { if (self->deactivating) {
fpi_imgdev_deactivate_complete(dev); fpi_image_device_deactivate_complete(dev, error);
} else if (r) { } else if (error) {
fpi_imgdev_session_error(dev, r); fpi_image_device_session_error(dev, error);
} else { } else {
start_scan(dev); start_scan(dev);
} }
} }
static void open_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) static void open_loop(FpiSsm *ssm, FpDevice *_dev, void *user_data)
{ {
struct fp_img_dev *dev = user_data; FpImageDevice *dev = user_data;
struct vfs5011_data *data; FpDeviceVfs5011 *self;
data = FP_INSTANCE_DATA(_dev); self = FPI_DEVICE_VFS5011(_dev);
switch (fpi_ssm_get_cur_state(ssm)) { switch (fpi_ssm_get_cur_state(ssm)) {
case DEV_OPEN_START: case DEV_OPEN_START:
data->init_sequence.stepcount = self->init_sequence.stepcount =
G_N_ELEMENTS(vfs5011_initialization); G_N_ELEMENTS(vfs5011_initialization);
data->init_sequence.actions = vfs5011_initialization; self->init_sequence.actions = vfs5011_initialization;
data->init_sequence.device = dev; self->init_sequence.device = dev;
data->init_sequence.receive_buf = self->init_sequence.receive_buf =
g_malloc0(VFS5011_RECEIVE_BUF_SIZE); g_malloc0(VFS5011_RECEIVE_BUF_SIZE);
data->init_sequence.timeout = VFS5011_DEFAULT_WAIT_TIMEOUT; self->init_sequence.timeout = VFS5011_DEFAULT_WAIT_TIMEOUT;
usb_exchange_async(ssm, &data->init_sequence); usb_exchange_async(ssm, &self->init_sequence);
break; break;
}; };
} }
static void open_loop_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) static void open_loop_complete(FpiSsm *ssm, FpDevice *_dev, void *user_data,
GError *error)
{ {
struct fp_img_dev *dev = user_data; FpImageDevice *dev = user_data;
struct vfs5011_data *data; FpDeviceVfs5011 *self;
data = FP_INSTANCE_DATA(_dev); self = FPI_DEVICE_VFS5011(_dev);
g_free(data->init_sequence.receive_buf); g_free(self->init_sequence.receive_buf);
data->init_sequence.receive_buf = NULL; self->init_sequence.receive_buf = NULL;
fpi_imgdev_open_complete(dev, 0); fpi_image_device_open_complete(dev, error);
fpi_ssm_free(ssm); fpi_ssm_free(ssm);
} }
static int dev_open(struct fp_img_dev *dev, unsigned long driver_data) static void dev_open(FpImageDevice *dev)
{ {
FpiSsm *ssm;
GError *error = NULL;
FpDeviceVfs5011 *self;
struct vfs5011_data *data; self = FPI_DEVICE_VFS5011(dev);
int r; self->capture_buffer =
data = (struct vfs5011_data *)g_malloc0(sizeof(*data));
data->capture_buffer =
(unsigned char *)g_malloc0(CAPTURE_LINES * VFS5011_LINE_SIZE); (unsigned char *)g_malloc0(CAPTURE_LINES * VFS5011_LINE_SIZE);
fp_dev_set_instance_data(FP_DEV(dev), data);
r = libusb_reset_device(fpi_dev_get_usb_dev(FP_DEV(dev))); if (!g_usb_device_claim_interface(fpi_device_get_usb_device(FP_DEVICE(dev)), 0, 0, &error)) {
if (r != 0) { fpi_image_device_open_complete(dev, error);
fp_err("Failed to reset the device"); return;
return r;
} }
r = libusb_claim_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); ssm = fpi_ssm_new(FP_DEVICE(dev), open_loop, DEV_OPEN_NUM_STATES, dev);
if (r != 0) {
fp_err("Failed to claim interface: %s", libusb_error_name(r));
return r;
}
fpi_ssm *ssm;
ssm = fpi_ssm_new(FP_DEV(dev), open_loop, DEV_OPEN_NUM_STATES, dev);
fpi_ssm_start(ssm, open_loop_complete); fpi_ssm_start(ssm, open_loop_complete);
return 0;
} }
static void dev_close(struct fp_img_dev *dev) static void dev_close(FpImageDevice *dev)
{ {
libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0); GError *error = NULL;
struct vfs5011_data *data; FpDeviceVfs5011 *self = FPI_DEVICE_VFS5011(dev);;
data = FP_INSTANCE_DATA(FP_DEV(dev));
if (data != NULL) { g_usb_device_release_interface(fpi_device_get_usb_device(FP_DEVICE(dev)),
g_free(data->capture_buffer); 0, 0, &error);
g_slist_free_full(data->rows, g_free);
g_free(data); g_free(self->capture_buffer);
} g_slist_free_full(self->rows, g_free);
fpi_imgdev_close_complete(dev);
fpi_image_device_close_complete(dev, error);
} }
static void start_scan(struct fp_img_dev *dev) static void start_scan(FpImageDevice *dev)
{ {
struct vfs5011_data *data; FpDeviceVfs5011 *self;
fpi_ssm *ssm; FpiSsm *ssm;
data = FP_INSTANCE_DATA(FP_DEV(dev)); self = FPI_DEVICE_VFS5011(dev);
data->loop_running = TRUE; self->loop_running = TRUE;
fp_dbg("creating ssm"); fp_dbg("creating ssm");
ssm = fpi_ssm_new(FP_DEV(dev), activate_loop, DEV_ACTIVATE_NUM_STATES, dev); ssm = fpi_ssm_new(FP_DEVICE(dev), activate_loop,
DEV_ACTIVATE_NUM_STATES, dev);
fp_dbg("starting ssm"); fp_dbg("starting ssm");
fpi_ssm_start(ssm, activate_loop_complete); fpi_ssm_start(ssm, activate_loop_complete);
fp_dbg("ssm done, getting out"); fp_dbg("ssm done, getting out");
} }
static int dev_activate(struct fp_img_dev *dev) static void dev_activate(FpImageDevice *dev)
{ {
struct vfs5011_data *data; FpDeviceVfs5011 *self;
data = FP_INSTANCE_DATA(FP_DEV(dev)); self = FPI_DEVICE_VFS5011(dev);
fp_dbg("device initialized"); fp_dbg("device initialized");
data->deactivating = FALSE; self->deactivating = FALSE;
start_scan(dev); start_scan(dev);
return 0;
} }
static void dev_deactivate(struct fp_img_dev *dev) static void dev_deactivate(FpImageDevice *dev)
{ {
int r; FpDeviceVfs5011 *self;
struct vfs5011_data *data;
data = FP_INSTANCE_DATA(FP_DEV(dev)); self = FPI_DEVICE_VFS5011(dev);
if (data->loop_running) { if (self->loop_running) {
data->deactivating = TRUE; self->deactivating = TRUE;
if (data->flying_transfer) {
r = libusb_cancel_transfer(data->flying_transfer);
if (r < 0)
fp_dbg("cancel failed error %d", r);
}
} else } else
fpi_imgdev_deactivate_complete(dev); fpi_image_device_deactivate_complete(dev, NULL);
} }
static const struct usb_id id_table[] = { static const FpIdEntry id_table [ ] = {
{ .vendor = 0x138a, .product = 0x0010 /* Validity device from some Toshiba laptops */ }, { /* Validity device from some Toshiba laptops */ .vid = 0x138a, .pid = 0x0010,
{ .vendor = 0x138a, .product = 0x0011 /* vfs5011 */ },
{ .vendor = 0x138a, .product = 0x0015 /* Validity device from Lenovo Preferred Pro USB Fingerprint Keyboard KUF1256 */ },
{ .vendor = 0x138a, .product = 0x0017 /* Validity device from Lenovo T440 laptops */ },
{ .vendor = 0x138a, .product = 0x0018 /* one more Validity device */ },
{ 0, 0, 0, },
};
struct fp_img_driver vfs5011_driver = {
.driver = {
.id = VFS5011_ID,
.name = "vfs5011",
.full_name = "Validity VFS5011",
.id_table = id_table,
.scan_type = FP_SCAN_TYPE_SWIPE,
}, },
{ /* vfs5011 */ .vid = 0x138a, .pid = 0x0011,
.flags = 0, },
.img_width = VFS5011_IMAGE_WIDTH, { /* Validity device from Lenovo Preferred Pro USB Fingerprint Keyboard KUF1256 */ .vid = 0x138a, .pid = 0x0015,
.img_height = -1, },
.bz3_threshold = 20, { /* Validity device from Lenovo T440 laptops */ .vid = 0x138a, .pid = 0x0017,
},
.open = dev_open, { /* one more Validity device */ .vid = 0x138a, .pid = 0x0018,
.close = dev_close, },
.activate = dev_activate, { .vid = 0, .pid = 0, .driver_data = 0 },
.deactivate = dev_deactivate,
}; };
static void fpi_device_vfs5011_init(FpDeviceVfs5011 *self) {
}
static void fpi_device_vfs5011_class_init(FpDeviceVfs5011Class *klass) {
FpDeviceClass *dev_class = FP_DEVICE_CLASS(klass);
FpImageDeviceClass *img_class = FP_IMAGE_DEVICE_CLASS(klass);
dev_class->id = "vfs5011";
dev_class->full_name = "Validity VFS5011";
dev_class->type = FP_DEVICE_TYPE_USB;
dev_class->id_table = id_table;
dev_class->scan_type = FP_SCAN_TYPE_SWIPE;
img_class->img_open = dev_open;
img_class->img_close = dev_close;
img_class->activate = dev_activate;
img_class->deactivate = dev_deactivate;
img_class->bz3_threshold = 20;
img_class->img_width = VFS5011_IMAGE_WIDTH;
img_class->img_height = -1;
}

View file

@ -7,10 +7,10 @@
enum { enum {
VFS5011_DEFAULT_WAIT_TIMEOUT = 3000, VFS5011_DEFAULT_WAIT_TIMEOUT = 3000,
VFS5011_OUT_ENDPOINT = 1 | LIBUSB_ENDPOINT_OUT, VFS5011_OUT_ENDPOINT = 1 | FPI_USB_ENDPOINT_OUT,
VFS5011_IN_ENDPOINT_CTRL = 1 | LIBUSB_ENDPOINT_IN, VFS5011_IN_ENDPOINT_CTRL = 1 | FPI_USB_ENDPOINT_IN,
VFS5011_IN_ENDPOINT_DATA = 2 | LIBUSB_ENDPOINT_IN, VFS5011_IN_ENDPOINT_DATA = 2 | FPI_USB_ENDPOINT_IN,
VFS5011_IN_ENDPOINT_CTRL2 = 3 | LIBUSB_ENDPOINT_IN, VFS5011_IN_ENDPOINT_CTRL2 = 3 | FPI_USB_ENDPOINT_IN,
}; };
enum { enum {

View file

@ -51,7 +51,7 @@ mathlib_dep = cc.find_library('m', required: false)
drivers = get_option('drivers').split(',') drivers = get_option('drivers').split(',')
virtual_drivers = [ 'virtual_image' ] virtual_drivers = [ 'virtual_image' ]
#default_drivers = [ 'upekts', 'upektc', 'upeksonly', 'vcom5s', 'uru4000', 'aes1610', 'aes1660', 'aes2501', 'aes2550', 'aes2660', 'aes3500', 'aes4000', 'vfs101', 'vfs301', 'vfs5011', 'upektc_img', 'etes603', 'vfs0050', 'elan' ] #default_drivers = [ 'upekts', 'upektc', 'upeksonly', 'vcom5s', 'uru4000', 'aes1610', 'aes1660', 'aes2501', 'aes2550', 'aes2660', 'aes3500', 'aes4000', 'vfs101', 'vfs301', 'vfs5011', 'upektc_img', 'etes603', 'vfs0050', 'elan' ]
default_drivers = [ 'upektc_img' ] default_drivers = [ 'upektc_img', 'vfs5011' ]
all_drivers = default_drivers + virtual_drivers all_drivers = default_drivers + virtual_drivers