lib: Make fp_dev structure opaque

This commit is contained in:
Bastien Nocera 2018-05-28 14:33:49 +02:00
parent d15282bff1
commit d83d92adf2
9 changed files with 84 additions and 71 deletions

View file

@ -542,6 +542,50 @@ API_EXPORTED int fp_dev_supports_dscv_print(struct fp_dev *dev,
0, print->driver_id, print->devtype, 0); 0, print->driver_id, print->devtype, 0);
} }
libusb_device_handle *
fpi_dev_get_usb_dev(struct fp_dev *dev)
{
return dev->udev;
}
void *
fpi_dev_get_user_data (struct fp_dev *dev)
{
return dev->priv;
}
void
fpi_dev_set_user_data (struct fp_dev *dev,
void *user_data)
{
dev->priv = user_data;
}
int
fpi_dev_get_nr_enroll_stages(struct fp_dev *dev)
{
return dev->nr_enroll_stages;
}
void
fpi_dev_set_nr_enroll_stages(struct fp_dev *dev,
int nr_enroll_stages)
{
dev->nr_enroll_stages = nr_enroll_stages;
}
struct fp_print_data *
fpi_dev_get_verify_data(struct fp_dev *dev)
{
return dev->verify_data;
}
enum fp_dev_state
fpi_dev_get_dev_state(struct fp_dev *dev)
{
return dev->state;
}
/** /**
* fp_driver_get_name: * fp_driver_get_name:
* @drv: the driver * @drv: the driver

View file

@ -140,7 +140,7 @@ static void generic_read_ignore_data(struct fpi_ssm *ssm, size_t bytes)
data = g_malloc(bytes); data = g_malloc(bytes);
dev = fpi_ssm_get_dev(ssm); dev = fpi_ssm_get_dev(ssm);
libusb_fill_bulk_transfer(transfer, dev->udev, EP_IN, data, bytes, libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(dev), EP_IN, data, bytes,
generic_ignore_data_cb, ssm, BULK_TIMEOUT); generic_ignore_data_cb, ssm, BULK_TIMEOUT);
r = libusb_submit_transfer(transfer); r = libusb_submit_transfer(transfer);

View file

@ -218,7 +218,7 @@ static void generic_read_ignore_data(struct fpi_ssm *ssm, size_t bytes)
} }
data = g_malloc(bytes); data = g_malloc(bytes);
libusb_fill_bulk_transfer(transfer, dev->udev, EP_IN, data, bytes, libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(dev), EP_IN, data, bytes,
generic_ignore_data_cb, ssm, BULK_TIMEOUT); generic_ignore_data_cb, ssm, BULK_TIMEOUT);
r = libusb_submit_transfer(transfer); r = libusb_submit_transfer(transfer);

View file

@ -406,7 +406,7 @@ static void capture_complete(struct fpi_ssm *ssm)
* completed, so we need to keep feeding it images till it's had enough. * completed, so we need to keep feeding it images till it's had enough.
* But after that it can't finalize enrollemnt until this callback exits. * But after that it can't finalize enrollemnt until this callback exits.
* That's why we schedule elan_capture instead of running it directly. */ * That's why we schedule elan_capture instead of running it directly. */
if (dev->dev->state == DEV_STATE_ENROLLING if (fpi_dev_get_dev_state(dev->dev) == DEV_STATE_ENROLLING
&& !fpi_timeout_add(10, elan_capture_async, dev)) && !fpi_timeout_add(10, elan_capture_async, dev))
fpi_imgdev_session_error(dev, -ETIME); fpi_imgdev_session_error(dev, -ETIME);

View file

@ -591,7 +591,8 @@ static void sm_write_regs(struct fpi_ssm *ssm,
data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + 1); data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + 1);
libusb_fill_control_setup(data, 0x40, 0x0c, 0, 0, 1); libusb_fill_control_setup(data, 0x40, 0x0c, 0, 0, 1);
dev = fpi_ssm_get_dev(ssm); dev = fpi_ssm_get_dev(ssm);
libusb_fill_control_transfer(wrdata->transfer, dev->udev, data, libusb_fill_control_transfer(wrdata->transfer,
fpi_dev_get_usb_dev(dev), data,
write_regs_cb, wrdata, CTRL_TIMEOUT); write_regs_cb, wrdata, CTRL_TIMEOUT);
wrdata->transfer->flags = LIBUSB_TRANSFER_SHORT_NOT_OK; wrdata->transfer->flags = LIBUSB_TRANSFER_SHORT_NOT_OK;

View file

@ -568,7 +568,7 @@ static void activate_run_state(struct fpi_ssm *ssm)
data = g_malloc0(LIBUSB_CONTROL_SETUP_SIZE + 1); data = g_malloc0(LIBUSB_CONTROL_SETUP_SIZE + 1);
libusb_fill_control_setup(data, libusb_fill_control_setup(data,
LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, 0x0c, 0x100, 0x0400, 1); LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, 0x0c, 0x100, 0x0400, 1);
libusb_fill_control_transfer(transfer, dev->udev, data, libusb_fill_control_transfer(transfer, fpi_dev_get_usb_dev(dev), data,
init_reqs_ctrl_cb, ssm, CTRL_TIMEOUT); init_reqs_ctrl_cb, ssm, CTRL_TIMEOUT);
r = libusb_submit_transfer(transfer); r = libusb_submit_transfer(transfer);
if (r < 0) { if (r < 0) {

View file

@ -166,7 +166,7 @@ static struct libusb_transfer *alloc_send_cmd_transfer(struct fp_dev *dev,
buf[urblen - 2] = crc >> 8; buf[urblen - 2] = crc >> 8;
buf[urblen - 1] = crc & 0xff; buf[urblen - 1] = crc & 0xff;
libusb_fill_bulk_transfer(transfer, dev->udev, EP_OUT, buf, urblen, libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(dev), EP_OUT, buf, urblen,
callback, user_data, TIMEOUT); callback, user_data, TIMEOUT);
return transfer; return transfer;
} }
@ -178,7 +178,7 @@ static struct libusb_transfer *alloc_send_cmd28_transfer(struct fp_dev *dev,
uint16_t _innerlen = innerlen; uint16_t _innerlen = innerlen;
size_t len = innerlen + 6; size_t len = innerlen + 6;
unsigned char *buf = g_malloc0(len); unsigned char *buf = g_malloc0(len);
struct upekts_dev *upekdev = dev->priv; struct upekts_dev *upekdev = fpi_dev_get_user_data(dev);
uint8_t seq = upekdev->seq + CMD_SEQ_INCREMENT; uint8_t seq = upekdev->seq + CMD_SEQ_INCREMENT;
struct libusb_transfer *ret; struct libusb_transfer *ret;
@ -417,7 +417,7 @@ static void read_msg_cb(struct libusb_transfer *transfer)
fp_dbg("didn't fit in buffer, need to extend by %d bytes", needed); fp_dbg("didn't fit in buffer, need to extend by %d bytes", needed);
data = g_realloc((gpointer) data, MSG_READ_BUF_SIZE + needed); data = g_realloc((gpointer) data, MSG_READ_BUF_SIZE + needed);
libusb_fill_bulk_transfer(etransfer, udata->dev->udev, EP_IN, libusb_fill_bulk_transfer(etransfer, fpi_dev_get_usb_dev(udata->dev), EP_IN,
data + MSG_READ_BUF_SIZE, needed, read_msg_extend_cb, udata, data + MSG_READ_BUF_SIZE, needed, read_msg_extend_cb, udata,
TIMEOUT); TIMEOUT);
@ -456,7 +456,7 @@ static int __read_msg_async(struct read_msg_data *udata)
return -ENOMEM; return -ENOMEM;
} }
libusb_fill_bulk_transfer(transfer, udata->dev->udev, EP_IN, buf, libusb_fill_bulk_transfer(transfer, fpi_dev_get_usb_dev(udata->dev), EP_IN, buf,
MSG_READ_BUF_SIZE, read_msg_cb, udata, TIMEOUT); MSG_READ_BUF_SIZE, read_msg_cb, udata, TIMEOUT);
r = libusb_submit_transfer(transfer); r = libusb_submit_transfer(transfer);
if (r < 0) { if (r < 0) {
@ -530,7 +530,7 @@ static void initsm_read_msg_response_cb(struct fpi_ssm *ssm,
unsigned char expect_subcmd, unsigned char subcmd) unsigned char expect_subcmd, unsigned char subcmd)
{ {
struct fp_dev *dev = fpi_ssm_get_dev(ssm); struct fp_dev *dev = fpi_ssm_get_dev(ssm);
struct upekts_dev *upekdev = dev->priv; struct upekts_dev *upekdev = fpi_dev_get_user_data(dev);
if (status != READ_MSG_RESPONSE) { if (status != READ_MSG_RESPONSE) {
fp_err("expected response, got %d seq=%x in state %d", status, seq, fp_err("expected response, got %d seq=%x in state %d", status, seq,
@ -594,7 +594,7 @@ static void initsm_read_msg_cmd_cb(struct fpi_ssm *ssm,
enum read_msg_status status, uint8_t expect_seq, uint8_t seq) enum read_msg_status status, uint8_t expect_seq, uint8_t seq)
{ {
struct fp_dev *dev = fpi_ssm_get_dev(ssm); struct fp_dev *dev = fpi_ssm_get_dev(ssm);
struct upekts_dev *upekdev = dev->priv; struct upekts_dev *upekdev = fpi_dev_get_user_data(dev);
if (status == READ_MSG_ERROR) { if (status == READ_MSG_ERROR) {
fpi_ssm_mark_aborted(ssm, -1); fpi_ssm_mark_aborted(ssm, -1);
@ -693,7 +693,7 @@ static void initsm_send_msg28_handler(struct fpi_ssm *ssm,
static void initsm_run_state(struct fpi_ssm *ssm) static void initsm_run_state(struct fpi_ssm *ssm)
{ {
struct fp_dev *dev = fpi_ssm_get_dev(ssm); struct fp_dev *dev = fpi_ssm_get_dev(ssm);
struct upekts_dev *upekdev = dev->priv; struct upekts_dev *upekdev = fpi_dev_get_user_data(dev);
struct libusb_transfer *transfer; struct libusb_transfer *transfer;
int r; int r;
@ -710,7 +710,7 @@ static void initsm_run_state(struct fpi_ssm *ssm)
data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + 1); data = g_malloc(LIBUSB_CONTROL_SETUP_SIZE + 1);
libusb_fill_control_setup(data, libusb_fill_control_setup(data,
LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, 0x0c, 0x100, 0x0400, 1); LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, 0x0c, 0x100, 0x0400, 1);
libusb_fill_control_transfer(transfer, dev->udev, data, libusb_fill_control_transfer(transfer, fpi_dev_get_usb_dev(dev), data,
ctrl400_cb, ssm, TIMEOUT); ctrl400_cb, ssm, TIMEOUT);
r = libusb_submit_transfer(transfer); r = libusb_submit_transfer(transfer);
@ -805,7 +805,7 @@ static void read_msg01_cb(struct fp_dev *dev, enum read_msg_status status,
void *user_data) void *user_data)
{ {
struct fpi_ssm *ssm = user_data; struct fpi_ssm *ssm = user_data;
struct upekts_dev *upekdev = dev->priv; struct upekts_dev *upekdev = fpi_dev_get_user_data(dev);
if (status == READ_MSG_ERROR) { if (status == READ_MSG_ERROR) {
fpi_ssm_mark_aborted(ssm, -1); fpi_ssm_mark_aborted(ssm, -1);
@ -867,7 +867,7 @@ static int dev_init(struct fp_dev *dev, unsigned long driver_data)
struct upekts_dev *upekdev = NULL; struct upekts_dev *upekdev = NULL;
int r; int r;
r = libusb_claim_interface(dev->udev, 0); r = libusb_claim_interface(fpi_dev_get_usb_dev(dev), 0);
if (r < 0) { if (r < 0) {
fp_err("could not claim interface 0: %s", libusb_error_name(r)); fp_err("could not claim interface 0: %s", libusb_error_name(r));
return r; return r;
@ -875,8 +875,8 @@ static int dev_init(struct fp_dev *dev, unsigned long driver_data)
upekdev = g_malloc(sizeof(*upekdev)); upekdev = g_malloc(sizeof(*upekdev));
upekdev->seq = 0xf0; /* incremented to 0x00 before first cmd */ upekdev->seq = 0xf0; /* incremented to 0x00 before first cmd */
dev->priv = upekdev; fpi_dev_set_user_data(dev, upekdev);
dev->nr_enroll_stages = 3; fpi_dev_set_nr_enroll_stages(dev, 3);
fpi_drvcb_open_complete(dev, 0); fpi_drvcb_open_complete(dev, 0);
return 0; return 0;
@ -884,8 +884,10 @@ static int dev_init(struct fp_dev *dev, unsigned long driver_data)
static void dev_exit(struct fp_dev *dev) static void dev_exit(struct fp_dev *dev)
{ {
libusb_release_interface(dev->udev, 0); void *user_data;
g_free(dev->priv); libusb_release_interface(fpi_dev_get_usb_dev(dev), 0);
user_data = fpi_dev_get_user_data(dev);
g_free(user_data);
fpi_drvcb_close_complete(dev); fpi_drvcb_close_complete(dev);
} }
@ -936,7 +938,7 @@ static void enroll_start_sm_cb_msg28(struct fp_dev *dev,
enum read_msg_status status, uint8_t seq, unsigned char subcmd, enum read_msg_status status, uint8_t seq, unsigned char subcmd,
unsigned char *data, size_t data_len, void *user_data) unsigned char *data, size_t data_len, void *user_data)
{ {
struct upekts_dev *upekdev = dev->priv; struct upekts_dev *upekdev = fpi_dev_get_user_data(dev);
struct fpi_ssm *ssm = user_data; struct fpi_ssm *ssm = user_data;
if (status != READ_MSG_RESPONSE) { if (status != READ_MSG_RESPONSE) {
@ -999,7 +1001,7 @@ static void enroll_iterate(struct fp_dev *dev);
static void e_handle_resp00(struct fp_dev *dev, unsigned char *data, static void e_handle_resp00(struct fp_dev *dev, unsigned char *data,
size_t data_len) size_t data_len)
{ {
struct upekts_dev *upekdev = dev->priv; struct upekts_dev *upekdev = fpi_dev_get_user_data(dev);
unsigned char status; unsigned char status;
int result = 0; int result = 0;
@ -1161,7 +1163,7 @@ static void enroll_started(struct fpi_ssm *ssm)
static int enroll_start(struct fp_dev *dev) static int enroll_start(struct fp_dev *dev)
{ {
struct upekts_dev *upekdev = dev->priv; struct upekts_dev *upekdev = fpi_dev_get_user_data(dev);
/* do_init state machine first */ /* do_init state machine first */
struct fpi_ssm *ssm = fpi_ssm_new(dev, enroll_start_sm_run_state, struct fpi_ssm *ssm = fpi_ssm_new(dev, enroll_start_sm_run_state,
@ -1249,7 +1251,7 @@ static void verify_start_sm_run_state(struct fpi_ssm *ssm)
fpi_ssm_start(initsm, verify_start_sm_cb_initsm); fpi_ssm_start(initsm, verify_start_sm_cb_initsm);
break; break;
case VERIFY_INIT: ; case VERIFY_INIT: ;
struct fp_print_data *print = dev->verify_data; struct fp_print_data *print = fpi_dev_get_verify_data(dev);
struct fp_print_data_item *item = print->prints->data; struct fp_print_data_item *item = print->prints->data;
size_t data_len = sizeof(verify_hdr) + item->length; size_t data_len = sizeof(verify_hdr) + item->length;
unsigned char *data = g_malloc(data_len); unsigned char *data = g_malloc(data_len);
@ -1355,7 +1357,7 @@ static void verify_rd2800_cb(struct fp_dev *dev, enum read_msg_status msgstat,
uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len, uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len,
void *user_data) void *user_data)
{ {
struct upekts_dev *upekdev = dev->priv; struct upekts_dev *upekdev = fpi_dev_get_user_data(dev);
if (msgstat != READ_MSG_RESPONSE) { if (msgstat != READ_MSG_RESPONSE) {
fp_err("expected response, got %d seq=%x", msgstat, seq); fp_err("expected response, got %d seq=%x", msgstat, seq);
@ -1394,7 +1396,7 @@ static void verify_wr2800_cb(struct libusb_transfer *transfer)
static void verify_iterate(struct fp_dev *dev) static void verify_iterate(struct fp_dev *dev)
{ {
struct upekts_dev *upekdev = dev->priv; struct upekts_dev *upekdev = fpi_dev_get_user_data(dev);
if (upekdev->stop_verify) { if (upekdev->stop_verify) {
do_verify_stop(dev); do_verify_stop(dev);
@ -1430,7 +1432,7 @@ static void verify_iterate(struct fp_dev *dev)
static void verify_started(struct fpi_ssm *ssm) static void verify_started(struct fpi_ssm *ssm)
{ {
struct fp_dev *dev = fpi_ssm_get_dev(ssm); struct fp_dev *dev = fpi_ssm_get_dev(ssm);
struct upekts_dev *upekdev = dev->priv; struct upekts_dev *upekdev = fpi_dev_get_user_data(dev);
fpi_drvcb_verify_started(dev, fpi_ssm_get_error(ssm)); fpi_drvcb_verify_started(dev, fpi_ssm_get_error(ssm));
if (!fpi_ssm_get_error(ssm)) { if (!fpi_ssm_get_error(ssm)) {
@ -1443,7 +1445,7 @@ static void verify_started(struct fpi_ssm *ssm)
static int verify_start(struct fp_dev *dev) static int verify_start(struct fp_dev *dev)
{ {
struct upekts_dev *upekdev = dev->priv; struct upekts_dev *upekdev = fpi_dev_get_user_data(dev);
struct fpi_ssm *ssm = fpi_ssm_new(dev, verify_start_sm_run_state, struct fpi_ssm *ssm = fpi_ssm_new(dev, verify_start_sm_run_state,
VERIFY_NUM_STATES); VERIFY_NUM_STATES);
upekdev->stop_verify = FALSE; upekdev->stop_verify = FALSE;
@ -1453,7 +1455,7 @@ static int verify_start(struct fp_dev *dev)
static int verify_stop(struct fp_dev *dev, gboolean iterating) static int verify_stop(struct fp_dev *dev, gboolean iterating)
{ {
struct upekts_dev *upekdev = dev->priv; struct upekts_dev *upekdev = fpi_dev_get_user_data(dev);
if (!iterating) if (!iterating)
do_verify_stop(dev); do_verify_stop(dev);

View file

@ -647,7 +647,7 @@ static int action_completed(struct fp_img_dev *dev)
struct vfs101_dev *vdev = dev->priv; struct vfs101_dev *vdev = dev->priv;
if ((dev->action == IMG_ACTION_ENROLL) && if ((dev->action == IMG_ACTION_ENROLL) &&
(vdev->enroll_stage < dev->dev->nr_enroll_stages)) (vdev->enroll_stage < fpi_dev_get_nr_enroll_stages(dev->dev)))
/* Enroll not completed, return false */ /* Enroll not completed, return false */
return FALSE; return FALSE;

View file

@ -71,48 +71,14 @@ enum fp_dev_state {
DEV_STATE_CAPTURE_STOPPING, DEV_STATE_CAPTURE_STOPPING,
}; };
struct fp_dev { struct fp_dev;
struct fp_driver *drv; libusb_device_handle *fpi_dev_get_usb_dev(struct fp_dev *dev);
libusb_device_handle *udev; void *fpi_dev_get_user_data (struct fp_dev *dev);
uint32_t devtype; void fpi_dev_set_user_data (struct fp_dev *dev, void *user_data);
void *priv; int fpi_dev_get_nr_enroll_stages(struct fp_dev *dev);
void fpi_dev_set_nr_enroll_stages(struct fp_dev *dev, int nr_enroll_stages);
int nr_enroll_stages; struct fp_print_data *fpi_dev_get_verify_data(struct fp_dev *dev);
enum fp_dev_state fpi_dev_get_dev_state(struct fp_dev *dev);
/* read-only to drivers */
struct fp_print_data *verify_data;
/* drivers should not mess with any of the below */
enum fp_dev_state state;
int __enroll_stage;
int unconditional_capture;
/* async I/O callbacks and data */
/* FIXME: convert this to generic state operational data mechanism? */
fp_dev_open_cb open_cb;
void *open_cb_data;
fp_operation_stop_cb close_cb;
void *close_cb_data;
fp_enroll_stage_cb enroll_stage_cb;
void *enroll_stage_cb_data;
fp_operation_stop_cb enroll_stop_cb;
void *enroll_stop_cb_data;
fp_img_operation_cb verify_cb;
void *verify_cb_data;
fp_operation_stop_cb verify_stop_cb;
void *verify_stop_cb_data;
fp_identify_cb identify_cb;
void *identify_cb_data;
fp_operation_stop_cb identify_stop_cb;
void *identify_stop_cb_data;
fp_img_operation_cb capture_cb;
void *capture_cb_data;
fp_operation_stop_cb capture_stop_cb;
void *capture_stop_cb_data;
/* FIXME: better place to put this? */
struct fp_print_data **identify_gallery;
};
enum fp_imgdev_state { enum fp_imgdev_state {
IMGDEV_STATE_INACTIVE, IMGDEV_STATE_INACTIVE,