upektc_img: Port upektc_img and back in
Note that this port currently conflicts with with the upeksonly driver as the revision check is non-functional right now.
This commit is contained in:
parent
dac489b7f6
commit
f119c273fd
2 changed files with 263 additions and 262 deletions
|
@ -21,14 +21,13 @@
|
|||
|
||||
#include "drivers_api.h"
|
||||
#include "upek_proto.h"
|
||||
#include "aeslib.h"
|
||||
#include "upektc_img.h"
|
||||
|
||||
static void start_capture(struct fp_img_dev *dev);
|
||||
static void start_deactivation(struct fp_img_dev *dev);
|
||||
static void start_capture(FpImageDevice *dev);
|
||||
static void start_deactivation(FpImageDevice *dev);
|
||||
|
||||
#define EP_IN (1 | LIBUSB_ENDPOINT_IN)
|
||||
#define EP_OUT (2 | LIBUSB_ENDPOINT_OUT)
|
||||
#define EP_IN (1 | FPI_USB_ENDPOINT_IN)
|
||||
#define EP_OUT (2 | FPI_USB_ENDPOINT_OUT)
|
||||
#define CTRL_TIMEOUT 4000
|
||||
#define BULK_TIMEOUT 4000
|
||||
|
||||
|
@ -40,15 +39,20 @@ static void start_deactivation(struct fp_img_dev *dev);
|
|||
#define MAX_RESPONSE_SIZE 2052
|
||||
#define SHORT_RESPONSE_SIZE 64
|
||||
|
||||
struct upektc_img_dev {
|
||||
struct _FpiDeviceUpektcImg {
|
||||
FpImageDevice parent;
|
||||
|
||||
unsigned char cmd[MAX_CMD_SIZE];
|
||||
unsigned char response[MAX_RESPONSE_SIZE];
|
||||
unsigned char image_bits[IMAGE_SIZE * 2];
|
||||
unsigned char *image_bits;
|
||||
unsigned char seq;
|
||||
size_t image_size;
|
||||
size_t response_rest;
|
||||
gboolean deactivating;
|
||||
};
|
||||
G_DECLARE_FINAL_TYPE(FpiDeviceUpektcImg, fpi_device_upektc_img, FPI,
|
||||
DEVICE_UPEKTC_IMG, FpImageDevice);
|
||||
G_DEFINE_TYPE(FpiDeviceUpektcImg, fpi_device_upektc_img, FP_TYPE_IMAGE_DEVICE);
|
||||
|
||||
/****** HELPERS ******/
|
||||
|
||||
|
@ -72,58 +76,48 @@ static void upektc_img_cmd_update_crc(unsigned char *cmd_buf, size_t size)
|
|||
}
|
||||
|
||||
static void
|
||||
upektc_img_submit_req(fpi_ssm *ssm,
|
||||
struct fp_img_dev *dev,
|
||||
upektc_img_submit_req(FpiSsm *ssm,
|
||||
FpImageDevice *dev,
|
||||
const unsigned char *buf,
|
||||
size_t buf_size,
|
||||
unsigned char seq,
|
||||
libusb_transfer_cb_fn cb)
|
||||
FpiUsbTransferCallback cb)
|
||||
{
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
int r;
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG(dev);
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new(FP_DEVICE(dev));
|
||||
|
||||
BUG_ON(buf_size > MAX_CMD_SIZE);
|
||||
|
||||
transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER;
|
||||
memcpy(self->cmd, buf, buf_size);
|
||||
upektc_img_cmd_fix_seq(self->cmd, seq);
|
||||
upektc_img_cmd_update_crc(self->cmd, buf_size);
|
||||
|
||||
memcpy(upekdev->cmd, buf, buf_size);
|
||||
upektc_img_cmd_fix_seq(upekdev->cmd, seq);
|
||||
upektc_img_cmd_update_crc(upekdev->cmd, buf_size);
|
||||
|
||||
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_OUT, upekdev->cmd, buf_size,
|
||||
cb, ssm, BULK_TIMEOUT);
|
||||
|
||||
r = libusb_submit_transfer(transfer);
|
||||
if (r < 0) {
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, r);
|
||||
}
|
||||
fpi_usb_transfer_fill_bulk_full(transfer, EP_OUT, self->cmd, buf_size,
|
||||
NULL);
|
||||
transfer->ssm = ssm;
|
||||
transfer->short_is_error = TRUE;
|
||||
fpi_usb_transfer_submit(transfer, BULK_TIMEOUT, NULL, cb, NULL);
|
||||
fpi_usb_transfer_unref(transfer);
|
||||
}
|
||||
|
||||
static void
|
||||
upektc_img_read_data(fpi_ssm *ssm,
|
||||
struct fp_img_dev *dev,
|
||||
upektc_img_read_data(FpiSsm *ssm,
|
||||
FpImageDevice *dev,
|
||||
size_t buf_size,
|
||||
size_t buf_offset,
|
||||
libusb_transfer_cb_fn cb)
|
||||
FpiUsbTransferCallback cb)
|
||||
{
|
||||
struct libusb_transfer *transfer = fpi_usb_alloc();
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
int r;
|
||||
FpiUsbTransfer *transfer = fpi_usb_transfer_new(FP_DEVICE(dev));
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG(dev);
|
||||
|
||||
BUG_ON(buf_size > MAX_RESPONSE_SIZE);
|
||||
BUG_ON(buf_offset + buf_size > MAX_RESPONSE_SIZE);
|
||||
|
||||
transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER;
|
||||
|
||||
libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(FP_DEV(dev)), EP_IN, upekdev->response + buf_offset, buf_size,
|
||||
cb, ssm, BULK_TIMEOUT);
|
||||
|
||||
r = libusb_submit_transfer(transfer);
|
||||
if (r < 0) {
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, r);
|
||||
}
|
||||
fpi_usb_transfer_fill_bulk_full(transfer, EP_IN,
|
||||
self->response + buf_offset, buf_size,
|
||||
NULL);
|
||||
transfer->ssm = ssm;
|
||||
fpi_usb_transfer_submit(transfer, BULK_TIMEOUT, NULL, cb, NULL);
|
||||
fpi_usb_transfer_unref(transfer);
|
||||
}
|
||||
|
||||
/****** CAPTURE ******/
|
||||
|
@ -139,21 +133,19 @@ enum capture_states {
|
|||
CAPTURE_NUM_STATES,
|
||||
};
|
||||
|
||||
static void capture_reqs_cb(struct libusb_transfer *transfer)
|
||||
static void capture_reqs_cb(FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
{
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
|
||||
if ((transfer->status != LIBUSB_TRANSFER_COMPLETED) ||
|
||||
(transfer->length != transfer->actual_length)) {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
if (error) {
|
||||
fpi_ssm_mark_failed(transfer->ssm, error);
|
||||
return;
|
||||
}
|
||||
switch (fpi_ssm_get_cur_state(ssm)) {
|
||||
switch (fpi_ssm_get_cur_state(transfer->ssm)) {
|
||||
case CAPTURE_ACK_00_28_TERM:
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_READ_DATA_TERM);
|
||||
fpi_ssm_jump_to_state(transfer->ssm, CAPTURE_READ_DATA_TERM);
|
||||
break;
|
||||
default:
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_READ_DATA);
|
||||
fpi_ssm_jump_to_state(transfer->ssm, CAPTURE_READ_DATA);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -176,53 +168,54 @@ static int upektc_img_process_image_frame(unsigned char *image_buf, unsigned cha
|
|||
return len;
|
||||
}
|
||||
|
||||
static void capture_read_data_cb(struct libusb_transfer *transfer)
|
||||
static void capture_read_data_cb(FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
{
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
struct fp_img_dev *dev = fpi_ssm_get_user_data(ssm);
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
unsigned char *data = upekdev->response;
|
||||
struct fp_img *img;
|
||||
FpImageDevice *dev = FP_IMAGE_DEVICE(device);
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG(dev);
|
||||
unsigned char *data = self->response;
|
||||
FpImage *img;
|
||||
size_t response_size;
|
||||
|
||||
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
||||
fp_dbg("request is not completed, %d", transfer->status);
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
if (error) {
|
||||
fp_dbg("request is not completed, %s", error->message);
|
||||
fpi_ssm_mark_failed(transfer->ssm, error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (upekdev->deactivating) {
|
||||
if (self->deactivating) {
|
||||
fp_dbg("Deactivate requested\n");
|
||||
fpi_ssm_mark_completed(ssm);
|
||||
fpi_ssm_mark_completed(transfer->ssm);
|
||||
return;
|
||||
}
|
||||
|
||||
fp_dbg("request completed, len: %.4x", transfer->actual_length);
|
||||
fp_dbg("request completed, len: %.4x", (gint)transfer->actual_length);
|
||||
if (transfer->actual_length == 0) {
|
||||
fpi_ssm_jump_to_state(ssm, fpi_ssm_get_cur_state(ssm));
|
||||
fpi_ssm_jump_to_state(transfer->ssm,
|
||||
fpi_ssm_get_cur_state(transfer->ssm));
|
||||
return;
|
||||
}
|
||||
|
||||
if (fpi_ssm_get_cur_state(ssm) == CAPTURE_READ_DATA_TERM) {
|
||||
if (fpi_ssm_get_cur_state(transfer->ssm) == CAPTURE_READ_DATA_TERM) {
|
||||
fp_dbg("Terminating SSM\n");
|
||||
fpi_ssm_mark_completed(ssm);
|
||||
fpi_ssm_mark_completed(transfer->ssm);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!upekdev->response_rest) {
|
||||
if (!self->response_rest) {
|
||||
response_size = ((data[5] & 0x0f) << 8) + data[6];
|
||||
response_size += 9; /* 7 bytes for header, 2 for CRC */
|
||||
if (response_size > transfer->actual_length) {
|
||||
fp_dbg("response_size is %lu, actual_length is %d\n",
|
||||
response_size, transfer->actual_length);
|
||||
response_size, (gint)transfer->actual_length);
|
||||
fp_dbg("Waiting for rest of transfer");
|
||||
BUG_ON(upekdev->response_rest);
|
||||
upekdev->response_rest = response_size - transfer->actual_length;
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_READ_DATA);
|
||||
BUG_ON(self->response_rest);
|
||||
self->response_rest = response_size - transfer->actual_length;
|
||||
fpi_ssm_jump_to_state(transfer->ssm, CAPTURE_READ_DATA);
|
||||
return;
|
||||
}
|
||||
}
|
||||
upekdev->response_rest = 0;
|
||||
self->response_rest = 0;
|
||||
|
||||
switch (data[4]) {
|
||||
case 0x00:
|
||||
|
@ -233,88 +226,103 @@ static void capture_read_data_cb(struct libusb_transfer *transfer)
|
|||
switch (data[18]) {
|
||||
case 0x0c:
|
||||
/* no finger */
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_ACK_00_28);
|
||||
fpi_ssm_jump_to_state(transfer->ssm,
|
||||
CAPTURE_ACK_00_28);
|
||||
break;
|
||||
case 0x00:
|
||||
/* finger is present! */
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_ACK_00_28);
|
||||
fpi_ssm_jump_to_state(transfer->ssm,
|
||||
CAPTURE_ACK_00_28);
|
||||
break;
|
||||
case 0x1e:
|
||||
/* short scan */
|
||||
fp_err("short scan, aborting\n");
|
||||
fpi_imgdev_abort_scan(dev, FP_VERIFY_RETRY_TOO_SHORT);
|
||||
fpi_imgdev_report_finger_status(dev, FALSE);
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_ACK_00_28_TERM);
|
||||
fpi_image_device_retry_scan(dev,
|
||||
FP_DEVICE_RETRY_TOO_SHORT);
|
||||
fpi_image_device_report_finger_status(dev,
|
||||
FALSE);
|
||||
fpi_ssm_jump_to_state(transfer->ssm,
|
||||
CAPTURE_ACK_00_28_TERM);
|
||||
break;
|
||||
case 0x1d:
|
||||
/* too much horisontal movement */
|
||||
fp_err("too much horisontal movement, aborting\n");
|
||||
fpi_imgdev_abort_scan(dev, FP_VERIFY_RETRY_CENTER_FINGER);
|
||||
fpi_imgdev_report_finger_status(dev, FALSE);
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_ACK_00_28_TERM);
|
||||
fpi_image_device_retry_scan(dev,
|
||||
FP_DEVICE_RETRY_CENTER_FINGER);
|
||||
fpi_image_device_report_finger_status(dev,
|
||||
FALSE);
|
||||
fpi_ssm_jump_to_state(transfer->ssm,
|
||||
CAPTURE_ACK_00_28_TERM);
|
||||
break;
|
||||
default:
|
||||
/* some error happened, cancel scan */
|
||||
fp_err("something bad happened, stop scan\n");
|
||||
fpi_imgdev_abort_scan(dev, FP_VERIFY_RETRY);
|
||||
fpi_imgdev_report_finger_status(dev, FALSE);
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_ACK_00_28_TERM);
|
||||
fpi_image_device_retry_scan(dev,
|
||||
FP_DEVICE_RETRY);
|
||||
fpi_image_device_report_finger_status(dev,
|
||||
FALSE);
|
||||
fpi_ssm_jump_to_state(transfer->ssm,
|
||||
CAPTURE_ACK_00_28_TERM);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
/* Image frame with additional info */
|
||||
case 0x2c:
|
||||
fpi_imgdev_report_finger_status(dev, TRUE);
|
||||
fpi_image_device_report_finger_status(dev,
|
||||
TRUE);
|
||||
/* Plain image frame */
|
||||
case 0x24:
|
||||
upekdev->image_size +=
|
||||
upektc_img_process_image_frame(upekdev->image_bits + upekdev->image_size,
|
||||
data);
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_ACK_FRAME);
|
||||
self->image_size +=
|
||||
upektc_img_process_image_frame(self->image_bits + self->image_size,
|
||||
data);
|
||||
fpi_ssm_jump_to_state(transfer->ssm,
|
||||
CAPTURE_ACK_FRAME);
|
||||
break;
|
||||
/* Last image frame */
|
||||
case 0x20:
|
||||
upekdev->image_size +=
|
||||
upektc_img_process_image_frame(upekdev->image_bits + upekdev->image_size,
|
||||
data);
|
||||
BUG_ON(upekdev->image_size != IMAGE_SIZE);
|
||||
fp_dbg("Image size is %lu\n", upekdev->image_size);
|
||||
img = fpi_img_new(IMAGE_SIZE);
|
||||
img->flags = FP_IMG_PARTIAL;
|
||||
memcpy(img->data, upekdev->image_bits, IMAGE_SIZE);
|
||||
fpi_imgdev_image_captured(dev, img);
|
||||
fpi_imgdev_report_finger_status(dev, FALSE);
|
||||
fpi_ssm_mark_completed(ssm);
|
||||
self->image_size +=
|
||||
upektc_img_process_image_frame(self->image_bits + self->image_size,
|
||||
data);
|
||||
BUG_ON(self->image_size != IMAGE_SIZE);
|
||||
fp_dbg("Image size is %lu\n",
|
||||
self->image_size);
|
||||
img = fp_image_new(IMAGE_WIDTH, IMAGE_HEIGHT);
|
||||
memcpy(img->data, self->image_bits,
|
||||
IMAGE_SIZE);
|
||||
fpi_image_device_image_captured(dev, img);
|
||||
fpi_image_device_report_finger_status(dev,
|
||||
FALSE);
|
||||
fpi_ssm_mark_completed(transfer->ssm);
|
||||
break;
|
||||
default:
|
||||
fp_err("Unknown response!\n");
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
fpi_ssm_mark_failed(transfer->ssm, fpi_device_error_new (FP_DEVICE_ERROR_GENERAL));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 0x08:
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_ACK_08);
|
||||
fpi_ssm_jump_to_state(transfer->ssm, CAPTURE_ACK_08);
|
||||
break;
|
||||
default:
|
||||
fp_err("Not handled response!\n");
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
fpi_ssm_mark_failed(transfer->ssm, fpi_device_error_new (FP_DEVICE_ERROR_GENERAL));
|
||||
}
|
||||
}
|
||||
|
||||
static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
static void capture_run_state(FpiSsm *ssm, FpDevice *_dev, void *user_data)
|
||||
{
|
||||
struct fp_img_dev *dev = user_data;
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(_dev);
|
||||
FpImageDevice *dev = user_data;
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG(_dev);
|
||||
|
||||
switch (fpi_ssm_get_cur_state(ssm)) {
|
||||
case CAPTURE_INIT_CAPTURE:
|
||||
upektc_img_submit_req(ssm, dev, upek2020_init_capture, sizeof(upek2020_init_capture),
|
||||
upekdev->seq, capture_reqs_cb);
|
||||
upekdev->seq++;
|
||||
self->seq, capture_reqs_cb);
|
||||
self->seq++;
|
||||
break;
|
||||
case CAPTURE_READ_DATA:
|
||||
case CAPTURE_READ_DATA_TERM:
|
||||
if (!upekdev->response_rest)
|
||||
if (!self->response_rest)
|
||||
upektc_img_read_data(ssm, dev, SHORT_RESPONSE_SIZE, 0, capture_read_data_cb);
|
||||
else
|
||||
upektc_img_read_data(ssm, dev, MAX_RESPONSE_SIZE - SHORT_RESPONSE_SIZE,
|
||||
|
@ -323,8 +331,8 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data
|
|||
case CAPTURE_ACK_00_28:
|
||||
case CAPTURE_ACK_00_28_TERM:
|
||||
upektc_img_submit_req(ssm, dev, upek2020_ack_00_28, sizeof(upek2020_ack_00_28),
|
||||
upekdev->seq, capture_reqs_cb);
|
||||
upekdev->seq++;
|
||||
self->seq, capture_reqs_cb);
|
||||
self->seq++;
|
||||
break;
|
||||
case CAPTURE_ACK_08:
|
||||
upektc_img_submit_req(ssm, dev, upek2020_ack_08, sizeof(upek2020_ack_08),
|
||||
|
@ -332,37 +340,38 @@ static void capture_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data
|
|||
break;
|
||||
case CAPTURE_ACK_FRAME:
|
||||
upektc_img_submit_req(ssm, dev, upek2020_ack_frame, sizeof(upek2020_ack_frame),
|
||||
upekdev->seq, capture_reqs_cb);
|
||||
upekdev->seq++;
|
||||
self->seq, capture_reqs_cb);
|
||||
self->seq++;
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
static void capture_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
static void capture_sm_complete(FpiSsm *ssm, FpDevice *_dev, void *user_data, GError *error_arg)
|
||||
{
|
||||
struct fp_img_dev *dev = user_data;
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(_dev);
|
||||
int err = fpi_ssm_get_error(ssm);
|
||||
FpImageDevice *dev = user_data;
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG(_dev);
|
||||
g_autoptr(GError) error = error_arg;
|
||||
|
||||
fp_dbg("Capture completed, %d", err);
|
||||
fpi_ssm_free(ssm);
|
||||
|
||||
if (upekdev->deactivating)
|
||||
/* Note: We assume that the error is a cancellation in the deactivation case */
|
||||
if (self->deactivating)
|
||||
start_deactivation(dev);
|
||||
else if (err)
|
||||
fpi_imgdev_session_error(dev, err);
|
||||
else if (error)
|
||||
fpi_image_device_session_error (dev, g_steal_pointer (&error));
|
||||
else
|
||||
start_capture(dev);
|
||||
}
|
||||
|
||||
static void start_capture(struct fp_img_dev *dev)
|
||||
static void start_capture(FpImageDevice *dev)
|
||||
{
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
fpi_ssm *ssm;
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG(dev);
|
||||
FpiSsm *ssm;
|
||||
|
||||
upekdev->image_size = 0;
|
||||
self->image_size = 0;
|
||||
|
||||
ssm = fpi_ssm_new(FP_DEV(dev), capture_run_state, CAPTURE_NUM_STATES, dev);
|
||||
ssm = fpi_ssm_new(FP_DEVICE(dev), capture_run_state,
|
||||
CAPTURE_NUM_STATES, dev);
|
||||
fpi_ssm_start(ssm, capture_sm_complete);
|
||||
}
|
||||
|
||||
|
@ -374,40 +383,38 @@ enum deactivate_states {
|
|||
DEACTIVATE_NUM_STATES,
|
||||
};
|
||||
|
||||
static void deactivate_reqs_cb(struct libusb_transfer *transfer)
|
||||
static void deactivate_reqs_cb(FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
{
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
|
||||
if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) &&
|
||||
(transfer->length == transfer->actual_length)) {
|
||||
fpi_ssm_jump_to_state(ssm, CAPTURE_READ_DATA);
|
||||
if (!error) {
|
||||
fpi_ssm_jump_to_state(transfer->ssm, CAPTURE_READ_DATA);
|
||||
} else {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
fpi_ssm_mark_failed(transfer->ssm, error);
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: process response properly */
|
||||
static void deactivate_read_data_cb(struct libusb_transfer *transfer)
|
||||
static void deactivate_read_data_cb(FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
{
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
|
||||
if (transfer->status == LIBUSB_TRANSFER_COMPLETED) {
|
||||
fpi_ssm_mark_completed(ssm);
|
||||
if (!error) {
|
||||
fpi_ssm_mark_completed(transfer->ssm);
|
||||
} else {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
fpi_ssm_mark_failed(transfer->ssm, error);
|
||||
}
|
||||
}
|
||||
|
||||
static void deactivate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
static void deactivate_run_state(FpiSsm *ssm, FpDevice *_dev,
|
||||
void *user_data)
|
||||
{
|
||||
struct fp_img_dev *dev = user_data;
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(_dev);
|
||||
FpImageDevice *dev = user_data;
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG(_dev);
|
||||
|
||||
switch (fpi_ssm_get_cur_state(ssm)) {
|
||||
case DEACTIVATE_DEINIT:
|
||||
upektc_img_submit_req(ssm, dev, upek2020_deinit, sizeof(upek2020_deinit),
|
||||
upekdev->seq, deactivate_reqs_cb);
|
||||
upekdev->seq++;
|
||||
self->seq, deactivate_reqs_cb);
|
||||
self->seq++;
|
||||
break;
|
||||
case DEACTIVATE_READ_DEINIT_DATA:
|
||||
upektc_img_read_data(ssm, dev, SHORT_RESPONSE_SIZE, 0, deactivate_read_data_cb);
|
||||
|
@ -415,32 +422,28 @@ static void deactivate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_d
|
|||
};
|
||||
}
|
||||
|
||||
static void deactivate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
static void deactivate_sm_complete(FpiSsm *ssm, FpDevice *_dev,
|
||||
void *user_data, GError *error)
|
||||
{
|
||||
struct fp_img_dev *dev = user_data;
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(_dev);
|
||||
int err = fpi_ssm_get_error(ssm);
|
||||
FpImageDevice *dev = user_data;
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG(_dev);
|
||||
|
||||
fp_dbg("Deactivate completed");
|
||||
fpi_ssm_free(ssm);
|
||||
|
||||
if (err) {
|
||||
fpi_imgdev_session_error(dev, err);
|
||||
return;
|
||||
}
|
||||
|
||||
upekdev->deactivating = FALSE;
|
||||
fpi_imgdev_deactivate_complete(dev);
|
||||
self->deactivating = FALSE;
|
||||
fpi_image_device_deactivate_complete(dev, error);
|
||||
}
|
||||
|
||||
static void start_deactivation(struct fp_img_dev *dev)
|
||||
static void start_deactivation(FpImageDevice *dev)
|
||||
{
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
fpi_ssm *ssm;
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG(dev);
|
||||
FpiSsm *ssm;
|
||||
|
||||
upekdev->image_size = 0;
|
||||
self->image_size = 0;
|
||||
|
||||
ssm = fpi_ssm_new(FP_DEV(dev), deactivate_run_state, DEACTIVATE_NUM_STATES, dev);
|
||||
ssm = fpi_ssm_new(FP_DEVICE(dev), deactivate_run_state,
|
||||
DEACTIVATE_NUM_STATES, dev);
|
||||
fpi_ssm_start(ssm, deactivate_sm_complete);
|
||||
}
|
||||
|
||||
|
@ -460,69 +463,59 @@ enum activate_states {
|
|||
ACTIVATE_NUM_STATES,
|
||||
};
|
||||
|
||||
static void init_reqs_ctrl_cb(struct libusb_transfer *transfer)
|
||||
static void init_reqs_ctrl_cb(FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
{
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
|
||||
if (transfer->status == LIBUSB_TRANSFER_COMPLETED) {
|
||||
fpi_ssm_next_state(ssm);
|
||||
if (!error) {
|
||||
fpi_ssm_next_state(transfer->ssm);
|
||||
} else {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
fpi_ssm_mark_failed(transfer->ssm, error);
|
||||
}
|
||||
}
|
||||
|
||||
static void init_reqs_cb(struct libusb_transfer *transfer)
|
||||
static void init_reqs_cb(FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
{
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
|
||||
if ((transfer->status == LIBUSB_TRANSFER_COMPLETED) &&
|
||||
(transfer->length == transfer->actual_length)) {
|
||||
fpi_ssm_next_state(ssm);
|
||||
if (!error) {
|
||||
fpi_ssm_next_state(transfer->ssm);
|
||||
} else {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
fpi_ssm_mark_failed(transfer->ssm, error);
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: process response properly */
|
||||
static void init_read_data_cb(struct libusb_transfer *transfer)
|
||||
static void init_read_data_cb(FpiUsbTransfer *transfer, FpDevice *device,
|
||||
gpointer user_data, GError *error)
|
||||
{
|
||||
fpi_ssm *ssm = transfer->user_data;
|
||||
|
||||
if (transfer->status == LIBUSB_TRANSFER_COMPLETED) {
|
||||
fpi_ssm_next_state(ssm);
|
||||
if (!error) {
|
||||
fpi_ssm_next_state(transfer->ssm);
|
||||
} else {
|
||||
fpi_ssm_mark_failed(ssm, -EIO);
|
||||
fpi_ssm_mark_failed(transfer->ssm, error);
|
||||
}
|
||||
}
|
||||
|
||||
static void activate_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *user_data)
|
||||
static void activate_run_state(FpiSsm *ssm, FpDevice *dev, void *user_data)
|
||||
{
|
||||
struct libusb_transfer *transfer;
|
||||
struct fp_img_dev *idev = user_data;
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(dev);
|
||||
int r;
|
||||
FpiUsbTransfer *transfer;
|
||||
FpImageDevice *idev = user_data;
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG(dev);
|
||||
|
||||
switch (fpi_ssm_get_cur_state(ssm)) {
|
||||
case ACTIVATE_CONTROL_REQ_1:
|
||||
case ACTIVATE_CONTROL_REQ_2:
|
||||
{
|
||||
unsigned char *data;
|
||||
transfer = fpi_usb_transfer_new(dev);
|
||||
|
||||
transfer = fpi_usb_alloc();
|
||||
transfer->flags |= LIBUSB_TRANSFER_FREE_BUFFER |
|
||||
LIBUSB_TRANSFER_FREE_TRANSFER;
|
||||
|
||||
data = g_malloc0(LIBUSB_CONTROL_SETUP_SIZE + 1);
|
||||
libusb_fill_control_setup(data,
|
||||
LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, 0x0c, 0x100, 0x0400, 1);
|
||||
libusb_fill_control_transfer(transfer, fpi_dev_get_usb_dev(dev), data,
|
||||
init_reqs_ctrl_cb, ssm, CTRL_TIMEOUT);
|
||||
r = libusb_submit_transfer(transfer);
|
||||
if (r < 0) {
|
||||
g_free(data);
|
||||
libusb_free_transfer(transfer);
|
||||
fpi_ssm_mark_failed(ssm, r);
|
||||
}
|
||||
fpi_usb_transfer_fill_control(transfer,
|
||||
G_USB_DEVICE_DIRECTION_HOST_TO_DEVICE,
|
||||
G_USB_DEVICE_REQUEST_TYPE_VENDOR,
|
||||
G_USB_DEVICE_RECIPIENT_DEVICE,
|
||||
0x0c, 0x100, 0x0400, 1);
|
||||
transfer->buffer[0] = '\0';
|
||||
transfer->ssm = ssm;
|
||||
fpi_usb_transfer_submit(transfer, CTRL_TIMEOUT, NULL,
|
||||
init_reqs_ctrl_cb, NULL);
|
||||
fpi_usb_transfer_unref(transfer);
|
||||
}
|
||||
break;
|
||||
case ACTIVATE_INIT_1:
|
||||
|
@ -539,9 +532,9 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *user_data
|
|||
break;
|
||||
case ACTIVATE_INIT_4:
|
||||
upektc_img_submit_req(ssm, idev, upek2020_init_4, sizeof(upek2020_init_4),
|
||||
upekdev->seq, init_reqs_cb);
|
||||
self->seq, init_reqs_cb);
|
||||
/* Seq should be updated after 4th init */
|
||||
upekdev->seq++;
|
||||
self->seq++;
|
||||
break;
|
||||
case ACTIVATE_READ_CTRL_RESP_1:
|
||||
case ACTIVATE_READ_CTRL_RESP_2:
|
||||
|
@ -554,94 +547,102 @@ static void activate_run_state(fpi_ssm *ssm, struct fp_dev *dev, void *user_data
|
|||
}
|
||||
}
|
||||
|
||||
static void activate_sm_complete(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data)
|
||||
static void activate_sm_complete(FpiSsm *ssm, FpDevice *_dev,
|
||||
void *user_data, GError *error)
|
||||
{
|
||||
struct fp_img_dev *dev = user_data;
|
||||
int err = fpi_ssm_get_error(ssm);
|
||||
FpImageDevice *dev = user_data;
|
||||
|
||||
fpi_ssm_free(ssm);
|
||||
fp_dbg("%s status %d", __func__, err);
|
||||
fpi_imgdev_activate_complete(dev, err);
|
||||
fpi_image_device_activate_complete(dev, error);
|
||||
|
||||
if (!err)
|
||||
if (!error)
|
||||
start_capture(dev);
|
||||
}
|
||||
|
||||
static int dev_activate(struct fp_img_dev *dev)
|
||||
static void dev_activate(FpImageDevice *dev)
|
||||
{
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
fpi_ssm *ssm = fpi_ssm_new(FP_DEV(dev), activate_run_state,
|
||||
ACTIVATE_NUM_STATES, dev);
|
||||
upekdev->seq = 0;
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG(dev);
|
||||
FpiSsm *ssm = fpi_ssm_new(FP_DEVICE(dev), activate_run_state,
|
||||
ACTIVATE_NUM_STATES, dev);
|
||||
self->seq = 0;
|
||||
fpi_ssm_start(ssm, activate_sm_complete);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dev_deactivate(struct fp_img_dev *dev)
|
||||
static void dev_deactivate(FpImageDevice *dev)
|
||||
{
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG(dev);
|
||||
|
||||
upekdev->deactivating = TRUE;
|
||||
self->deactivating = TRUE;
|
||||
}
|
||||
|
||||
static int dev_init(struct fp_img_dev *dev, unsigned long driver_data)
|
||||
static void dev_init(FpImageDevice *dev)
|
||||
{
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG(dev);
|
||||
GError *error = NULL;
|
||||
/* TODO check that device has endpoints we're using */
|
||||
int r;
|
||||
struct upektc_img_dev *upekdev;
|
||||
|
||||
r = libusb_claim_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0);
|
||||
if (r < 0) {
|
||||
fp_err("could not claim interface 0: %s", libusb_error_name(r));
|
||||
return r;
|
||||
if (!g_usb_device_claim_interface(fpi_device_get_usb_device(FP_DEVICE(dev)), 0, 0, &error)) {
|
||||
fpi_image_device_open_complete(dev, error);
|
||||
return;
|
||||
}
|
||||
|
||||
upekdev = g_malloc0(sizeof(struct upektc_img_dev));
|
||||
fp_dev_set_instance_data(FP_DEV(dev), upekdev);
|
||||
fpi_imgdev_open_complete(dev, 0);
|
||||
return 0;
|
||||
self->image_bits = g_malloc0 (IMAGE_SIZE * 2);
|
||||
fpi_image_device_open_complete(dev, NULL);
|
||||
}
|
||||
|
||||
static void dev_deinit(struct fp_img_dev *dev)
|
||||
static void dev_deinit(FpImageDevice *dev)
|
||||
{
|
||||
struct upektc_img_dev *upekdev = FP_INSTANCE_DATA(FP_DEV(dev));
|
||||
g_free(upekdev);
|
||||
libusb_release_interface(fpi_dev_get_usb_dev(FP_DEV(dev)), 0);
|
||||
fpi_imgdev_close_complete(dev);
|
||||
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG(dev);
|
||||
GError *error = NULL;
|
||||
|
||||
g_clear_pointer (&self->image_bits, g_free);
|
||||
g_usb_device_release_interface(fpi_device_get_usb_device(FP_DEVICE(dev)),
|
||||
0, 0, &error);
|
||||
fpi_image_device_close_complete(dev, error);
|
||||
}
|
||||
|
||||
static int discover(struct libusb_device_descriptor *dsc, uint32_t *devtype)
|
||||
static int
|
||||
discover(GUsbDevice *usb_device)
|
||||
{
|
||||
if (dsc->idProduct == 0x2020 && dsc->bcdDevice == 1)
|
||||
return 1;
|
||||
if (dsc->idProduct == 0x2016 && dsc->bcdDevice == 2)
|
||||
return 1;
|
||||
gint16 pid = g_usb_device_get_pid (usb_device);
|
||||
gint16 bcd = g_usb_device_get_release (usb_device);
|
||||
|
||||
if (pid == 0x2020 && bcd == 1)
|
||||
return 100;
|
||||
if (pid == 0x2016 && bcd == 2)
|
||||
return 100;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct usb_id id_table[] = {
|
||||
{ .vendor = 0x147e, .product = 0x2016 },
|
||||
{ .vendor = 0x147e, .product = 0x2020 },
|
||||
{ 0, 0, 0, },
|
||||
};
|
||||
|
||||
struct fp_img_driver upektc_img_driver = {
|
||||
.driver = {
|
||||
.id = UPEKTC_IMG_ID,
|
||||
.name = FP_COMPONENT,
|
||||
.full_name = "Upek TouchChip Fingerprint Coprocessor",
|
||||
.id_table = id_table,
|
||||
.scan_type = FP_SCAN_TYPE_SWIPE,
|
||||
.discover = discover,
|
||||
static const FpIdEntry id_table [ ] = {
|
||||
{ .vid = 0x147e, .pid = 0x2016,
|
||||
},
|
||||
.flags = 0,
|
||||
.img_height = IMAGE_HEIGHT,
|
||||
.img_width = IMAGE_WIDTH,
|
||||
.bz3_threshold = 20,
|
||||
|
||||
.open = dev_init,
|
||||
.close = dev_deinit,
|
||||
.activate = dev_activate,
|
||||
.deactivate = dev_deactivate,
|
||||
{ .vid = 0x147e, .pid = 0x2020,
|
||||
},
|
||||
{ .vid = 0, .pid = 0, .driver_data = 0 },
|
||||
};
|
||||
|
||||
static void fpi_device_upektc_img_init(FpiDeviceUpektcImg *self) {
|
||||
}
|
||||
static void fpi_device_upektc_img_class_init(FpiDeviceUpektcImgClass *klass) {
|
||||
FpDeviceClass *dev_class = FP_DEVICE_CLASS(klass);
|
||||
FpImageDeviceClass *img_class = FP_IMAGE_DEVICE_CLASS(klass);
|
||||
|
||||
dev_class->id = "upektc_img";
|
||||
dev_class->full_name = "Upek TouchChip Fingerprint Coprocessor";
|
||||
dev_class->type = FP_DEVICE_TYPE_USB;
|
||||
dev_class->id_table = id_table;
|
||||
dev_class->scan_type = FP_SCAN_TYPE_SWIPE;
|
||||
dev_class->usb_discover = discover;
|
||||
|
||||
img_class->img_open = dev_init;
|
||||
img_class->img_close = dev_deinit;
|
||||
img_class->activate = dev_activate;
|
||||
img_class->deactivate = dev_deactivate;
|
||||
|
||||
img_class->bz3_threshold = 20;
|
||||
|
||||
img_class->img_width = IMAGE_WIDTH;
|
||||
img_class->img_height = IMAGE_HEIGHT;
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ mathlib_dep = cc.find_library('m', required: false)
|
|||
drivers = get_option('drivers').split(',')
|
||||
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 = [ ]
|
||||
default_drivers = [ 'upektc_img' ]
|
||||
|
||||
all_drivers = default_drivers + virtual_drivers
|
||||
|
||||
|
|
Loading…
Reference in a new issue